diff --git a/CMakeLists.txt b/CMakeLists.txt index 69199f599e..8a55506b59 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -780,9 +780,6 @@ add_library(dfts MODULE ${OPENAIR1_DIR}/PHY/TOOLS/oai_dfts.c ${OPENAIR1_DIR}/PHY set(PHY_SRC_COMMON ${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/dci_tools_common.c ${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/lte_mcs.c -# ${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/slss.c -# ${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/sldch.c -# ${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/slsch.c ${OPENAIR1_DIR}/PHY/LTE_UE_TRANSPORT/get_pmi.c ${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/group_hopping.c ${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/phich_common.c @@ -841,13 +838,9 @@ set(PHY_SRC ${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/pcfich.c ${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/pucch.c ${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/pmch.c -# ${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/ulsch_demodulation.c ${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/ulsch_decoding.c ${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/rar_tools.c ${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/uci_tools.c -# ${OPENAIR1_DIR}/PHY/LTE_ESTIMATION/freq_equalization.c -# ${OPENAIR1_DIR}/PHY/LTE_ESTIMATION/lte_adjust_sync_eNB.c -# ${OPENAIR1_DIR}/PHY/LTE_ESTIMATION/lte_ul_channel_estimation.c ${OPENAIR1_DIR}/PHY/LTE_ESTIMATION/lte_eNB_measurements.c ${OPENAIR1_DIR}/PHY/INIT/lte_init.c ) @@ -1114,7 +1107,6 @@ set(L2_SRC ${PDCP_DIR}/pdcp_util.c ${PDCP_DIR}/pdcp_security.c ${OPENAIR2_DIR}/LAYER2/openair2_proc.c -# ${RRC_DIR}/rrc_UE.c ${RRC_DIR}/rrc_eNB.c ${RRC_DIR}/rrc_eNB_endc.c ${RRC_DIR}/rrc_eNB_S1AP.c @@ -1129,7 +1121,6 @@ set(L2_SRC set(L2_RRC_SRC ${OPENAIR2_DIR}/LAYER2/openair2_proc.c - # ${RRC_DIR}/rrc_UE.c ${RRC_DIR}/rrc_eNB.c ${RRC_DIR}/rrc_eNB_endc.c ${RRC_DIR}/rrc_eNB_S1AP.c @@ -1368,6 +1359,7 @@ target_link_libraries(L2_UE PRIVATE asn1_lte_rrc_hdrs) add_library( NR_L2_UE ${NR_L2_SRC_UE} ${MAC_NR_SRC_UE} ) target_link_libraries(NR_L2_UE PRIVATE f1ap nr_rlc) target_link_libraries(NR_L2_UE PRIVATE asn1_nr_rrc_hdrs asn1_lte_rrc_hdrs nr_common nr_ue_power_procedures nr_ue_ra_procedures) +target_link_libraries(NR_L2_UE PRIVATE nr_nas) add_library(MAC_NR_COMMON ${OPENAIR2_DIR}/LAYER2/NR_MAC_COMMON/nr_mac_common.c @@ -1412,6 +1404,7 @@ add_library(SCTP_CLIENT ${SCTP_SRC}) target_link_libraries(SCTP_CLIENT PRIVATE asn1_nr_rrc_hdrs asn1_lte_rrc_hdrs) set(NAS_SRC ${OPENAIR3_DIR}/NAS/) + set(libnas_api_OBJS ${NAS_SRC}COMMON/API/NETWORK/as_message.c ${NAS_SRC}COMMON/API/NETWORK/nas_message.c @@ -1451,10 +1444,6 @@ set(libnas_emm_msg_OBJS ${NAS_SRC}COMMON/EMM/MSG/UplinkNasTransport.c ) -set(libnas_fgs_msg_OBJS - ${NAS_SRC}COMMON/EMM/MSG/fgs_service_request.c -) - set(libnas_esm_msg_OBJS ${NAS_SRC}COMMON/ESM/MSG/ActivateDedicatedEpsBearerContextAccept.c ${NAS_SRC}COMMON/ESM/MSG/ActivateDedicatedEpsBearerContextReject.c @@ -1643,61 +1632,6 @@ set(libnas_ue_esm_sap_OBJS ${NAS_SRC}UE/ESM/SAP/esm_sap.c ) -set(libnrnas_emm_msg_OBJS - ${NAS_SRC}COMMON/EMM/MSG/RegistrationRequest.c - ${NAS_SRC}COMMON/EMM/MSG/RegistrationAccept.c - ${NAS_SRC}COMMON/EMM/MSG/FGSIdentityResponse.c - ${NAS_SRC}COMMON/EMM/MSG/FGSAuthenticationResponse.c - ${NAS_SRC}COMMON/EMM/MSG/FGSNASSecurityModeComplete.c - ${NAS_SRC}COMMON/EMM/MSG/RegistrationComplete.c - ${NAS_SRC}COMMON/EMM/MSG/FGSUplinkNasTransport.c - ${NAS_SRC}COMMON/ESM/MSG/PduSessionEstablishRequest.c - ${NAS_SRC}COMMON/ESM/MSG/PduSessionEstablishmentAccept.c - ${NAS_SRC}COMMON/EMM/MSG/FGSDeregistrationRequestUEOriginating.c - ) - -set(libnrnas_ies_OBJS - ${NAS_SRC}COMMON/IES/ExtendedProtocolDiscriminator.c - ${NAS_SRC}COMMON/IES/FGSMobileIdentity.c - ${NAS_SRC}COMMON/IES/FGSRegistrationType.c - ${NAS_SRC}COMMON/IES/SpareHalfOctet.c - ${NAS_SRC}COMMON/IES/FGSRegistrationResult.c - ${NAS_SRC}COMMON/IES/FGMMCapability.c - ${NAS_SRC}COMMON/IES/NrUESecurityCapability.c - ${NAS_SRC}COMMON/IES/FGCNasMessageContainer.c - ${NAS_SRC}COMMON/IES/SORTransparentContainer.c - ) - -add_library(LIB_NAS_SIMUE - ${NAS_SRC}UE/nas_itti_messaging.c - ${NAS_SRC}UE/nas_network.c - ${NAS_SRC}UE/nas_parser.c - ${NAS_SRC}UE/nas_proc.c - ${NAS_SRC}UE/nas_user.c - ${NAS_SRC}NR_UE/nr_nas_msg.c - ${libnas_api_OBJS} - ${libnas_ue_api_OBJS} - ${libnas_emm_msg_OBJS} - ${libnas_fgs_msg_OBJS} - ${libnas_esm_msg_OBJS} - ${libnas_ies_OBJS} - ${libnas_utils_OBJS} - ${libnas_ue_emm_OBJS} - ${libnas_ue_emm_sap_OBJS} - ${libnas_ue_esm_OBJS} - ${libnas_ue_esm_sap_OBJS} - ${libnrnas_emm_msg_OBJS} - ${libnrnas_ies_OBJS} - $ - ) -target_include_directories(LIB_NAS_SIMUE PRIVATE ${OPENAIR_DIR}/common/utils/ds/) -target_link_libraries(LIB_NAS_SIMUE PRIVATE lte_rrc) - - - -set(NAS_SIM_LIB LIB_NAS_SIMUE) -target_link_libraries(LIB_NAS_SIMUE PRIVATE asn1_nr_rrc_hdrs asn1_lte_rrc_hdrs) - add_library(LIB_NAS_UE ${NAS_SRC}UE/nas_itti_messaging.c ${NAS_SRC}UE/nas_network.c @@ -1737,15 +1671,6 @@ set (NBIOT_SOURCES ) add_library(NB_IoT MODULE ${NBIOT_SOURCES} ) -add_library(LIB_5GNAS_GNB - ${NAS_SRC}/COMMON/nr_common.c - ${OPENAIR3_DIR}//UICC/usim_interface.c - ) - -target_include_directories(LIB_5GNAS_GNB PRIVATE ${OPENAIR_DIR}/common/utils/ds/) -target_link_libraries(LIB_5GNAS_GNB PRIVATE SECURITY) -target_link_libraries(LIB_5GNAS_GNB PRIVATE asn1_nr_rrc_hdrs asn1_lte_rrc_hdrs) - # Simulation library ########################## set (SIMUSRC @@ -1963,7 +1888,6 @@ add_executable(nr-uesoftmodem ${OPENAIR_DIR}/radio/COMMON/common_lib.c ${OPENAIR_DIR}/radio/COMMON/record_player.c ${OPENAIR2_DIR}/LAYER2/NR_MAC_COMMON/nr_mac_common.c - ${OPENAIR3_DIR}/NAS/UE/nas_ue_task.c ${OPENAIR1_DIR}/PHY/TOOLS/phy_scope_interface.c ) @@ -1972,11 +1896,12 @@ target_link_libraries(nr-uesoftmodem PRIVATE nr_rrc SECURITY UTIL HASHTABLE SCHED_RU_LIB SCHED_NR_UE_LIB PHY_COMMON PHY_NR_COMMON PHY_NR_UE NR_L2_UE L2_UE_LTE_NR MAC_NR_COMMON NFAPI_LIB NFAPI_PNF_LIB NFAPI_USER_LIB MISC_NFAPI_NR_LIB - ITTI LIB_5GNAS_GNB LIB_NAS_SIMUE ${NAS_SIM_LIB} SIMU shlib_loader + ITTI SIMU shlib_loader -Wl,--end-group z dl) target_link_libraries(nr-uesoftmodem PRIVATE pthread m CONFIG_LIB rt nr_ue_phy_meas) target_link_libraries(nr-uesoftmodem PRIVATE ${T_LIB}) +target_link_libraries(nr-uesoftmodem PRIVATE nr_nas lib_uicc usim_lib) target_link_libraries(nr-uesoftmodem PRIVATE asn1_nr_rrc_hdrs asn1_lte_rrc_hdrs) # force the generation of ASN.1 so that we don't need to wait during the build @@ -2169,10 +2094,6 @@ foreach(myExe s1ap ) endforeach(myExe) -# to be added -#../targets/TEST/PDCP/test_pdcp.c -#../targets/TEST/PDCP/with_rlc/test_pdcp_rlc.c - #ensure that the T header files are generated before targets depending on them if (${T_TRACER}) foreach(i diff --git a/doc/Doxyfile b/doc/Doxyfile index 22273aaf71..59a984e79f 100644 --- a/doc/Doxyfile +++ b/doc/Doxyfile @@ -1133,7 +1133,7 @@ INPUT = \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/UICC/usim_interface.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/ocp-gtpu/gtp_itf.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/NR_UE/nr_nas_msg.h \ -@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/NR_UE/nr_nas_msgc \ +@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/NR_UE/nr_nas_msg.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/UE/nas_itti_messaging.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/UE/user_defs.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/UE/EMM/emm_proc.h \ @@ -1274,12 +1274,10 @@ INPUT = \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/emm_msg.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/AttachReject.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/SecurityModeReject.h \ -@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/FGSDeregistrationRequestUEOriginating.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/UplinkNasTransport.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/AuthenticationFailure.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/AuthenticationResponse.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/AttachComplete.h \ -@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/FGSNASSecurityModeComplete.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/ExtendedServiceRequest.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/GutiReallocationComplete.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/DownlinkNasTransport.h \ @@ -1289,7 +1287,6 @@ INPUT = \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/AttachReject.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/AttachAccept.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/ServiceReject.h \ -@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/FGSIdentityResponse.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/AttachComplete.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/AttachRequest.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/AuthenticationRequest.c \ @@ -1301,17 +1298,14 @@ INPUT = \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/AttachAccept.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/IdentityResponse.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/GutiReallocationComplete.h \ -@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/RegistrationComplete.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/ServiceRequest.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/RegistrationAccept.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/IdentityRequest.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/RegistrationRequest.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/DetachAccept.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/AttachRequest.c \ -@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/FGSIdentityResponse.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/EmmStatus.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/AuthenticationFailure.h \ -@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/FGSAuthenticationResponse.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/AuthenticationReject.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/TrackingAreaUpdateAccept.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/TrackingAreaUpdateRequest.h \ @@ -1321,13 +1315,14 @@ INPUT = \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/FGSNASSecurityModeComplete.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/IdentityResponse.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/RegistrationComplete.c \ -@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/FGSDeregistrationRequestUEOriginating.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/emm_cause.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/EmmInformation.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/IdentityRequest.h \ -@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/FGSUplinkNasTransport.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/GutiReallocationCommand.h \ -@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/EMM/MSG/RegistrationRequest.h \ +@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/NR_UE/5GS/5GMM/MSG \ +@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/NR_UE/5GS/5GMM/IES \ +@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/NR_UE/5GS/5GSM \ +@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/NR_UE/5GS/5GSM/MSG \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/UTIL/parser.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/UTIL/device.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/UTIL/device.c \ @@ -1353,7 +1348,6 @@ INPUT = \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/AuthenticationParameterRand.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/UeRadioCapabilityInformationUpdateNeeded.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/ProtocolDiscriminator.h \ -@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/ExtendedProtocolDiscriminator.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/CsfbResponse.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/EsmCause.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/ProcedureTransactionIdentity.h \ @@ -1367,7 +1361,6 @@ INPUT = \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/LlcServiceAccessPointIdentifier.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/ProtocolConfigurationOptions.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/TransactionIdentifier.h \ -@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/ExtendedProtocolDiscriminator.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/GutiType.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/SupportedCodecList.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/MobileStationClassmark3.c \ @@ -1391,12 +1384,10 @@ INPUT = \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/UeSecurityCapability.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/ApnAggregateMaximumBitRate.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/ImeisvRequest.c \ -@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/SpareHalfOctet.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/PdnType.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/ShortMac.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/MobileStationClassmark3.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/TrafficFlowTemplate.h \ -@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/SORTransparentContainer.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/NasPagingIdentity.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/NasMessageContainer.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/Cli.h \ @@ -1406,18 +1397,15 @@ INPUT = \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/DetachType.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/EmergencyNumberList.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/EsmMessageContainer.c \ -@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/FGSRegistrationResult.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/GprsTimer.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/TmsiStatus.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/VoiceDomainPreferenceAndUeUsageSetting.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/IdentityType2.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/EpsQualityOfService.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/LocationAreaIdentification.h \ -@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/FGCNasMessageContainer.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/TrackingAreaIdentityList.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/MsNetworkCapability.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/ShortMac.c \ -@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/FGSRegistrationResult.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/AuthenticationFailureParameter.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/TrackingAreaIdentity.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/EmmCause.h \ @@ -1432,12 +1420,10 @@ INPUT = \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/AuthenticationParameterAutn.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/PdnAddress.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/EsmInformationTransferFlag.c \ -@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/SpareHalfOctet.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/KsiAndSequenceNumber.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/LocationAreaIdentification.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/QualityOfService.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/ProcedureTransactionIdentity.c \ -@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/NrUESecurityCapability.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/ProtocolConfigurationOptions.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/SsCode.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/EpsQualityOfService.h \ @@ -1447,12 +1433,10 @@ INPUT = \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/EpsMobileIdentity.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/MobileIdentity.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/SsCode.h \ -@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/FGSRegistrationType.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/TrackingAreaIdentity.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/EpsBearerIdentity.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/NasMessageContainer.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/DetachType.h \ -@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/FGMMCapability.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/TmsiStatus.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/MobileStationClassmark2.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/MessageType.c \ @@ -1466,13 +1450,10 @@ INPUT = \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/AdditionalUpdateType.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/NasRequestType.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/EpsBearerContextStatus.h \ -@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/FGSMobileIdentity.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/LcsClientIdentity.h \ -@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/FGSMobileIdentity.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/ServiceType.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/PagingIdentity.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/UeNetworkCapability.c \ -@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/NrUESecurityCapability.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/AuthenticationParameterAutn.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/PdnAddress.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/EpsUpdateType.h \ @@ -1480,7 +1461,6 @@ INPUT = \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/PTmsiSignature.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/PacketFlowIdentifier.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/UeRadioCapabilityInformationUpdateNeeded.h \ -@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/FGCNasMessageContainer.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/PTmsiSignature.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/EpsMobileIdentity.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/GutiType.h \ @@ -1496,16 +1476,13 @@ INPUT = \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/NasKeySetIdentifier.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/EpsAttachResult.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/AccessPointName.h \ -@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/FGMMCapability.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/AdditionalUpdateResult.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/EpsAttachType.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/UeNetworkCapability.h \ -@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/FGSDeregistrationType.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/EsmMessageContainer.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/SecurityHeaderType.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/EsmCause.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/NasSecurityAlgorithms.c \ -@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/SORTransparentContainer.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/LinkedEpsBearerIdentity.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/AdditionalUpdateType.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/MsNetworkFeatureSupport.c \ @@ -1518,14 +1495,12 @@ INPUT = \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/EpsBearerIdentity.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/EsmInformationTransferFlag.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/TimeZoneAndTime.c \ -@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/FGSRegistrationType.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/EpsUpdateResult.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/EpsUpdateType.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/AuthenticationResponseParameter.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/NetworkName.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/LinkedEpsBearerIdentity.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/SupportedCodecList.c \ -@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/NR_NAS_defs.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/milenage.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/ESM/MSG/EsmStatus.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/ESM/MSG/ModifyEpsBearerContextReject.h \ @@ -1580,7 +1555,6 @@ INPUT = \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/ESM/MSG/EsmInformationResponse.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/ESM/MSG/ActivateDefaultEpsBearerContextAccept.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/userDef.h \ -@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/nr_common.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair3/UTILS/conversions.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair2/X2AP/x2ap_eNB_encoder.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair2/X2AP/x2ap_eNB_management_procedures.c \ diff --git a/executables/nr-uesoftmodem.h b/executables/nr-uesoftmodem.h index c323ff18b4..90e32d651b 100644 --- a/executables/nr-uesoftmodem.h +++ b/executables/nr-uesoftmodem.h @@ -43,7 +43,6 @@ {"uecap_file", CONFIG_HLP_UECAP_FILE, 0, .strptr=&nrUE_params.uecap_file, .defstrval="./uecap_ports1.xml", TYPE_STRING, 0}, \ {"reconfig-file", CONFIG_HLP_RE_CFG_FILE, 0, .strptr=&nrUE_params.reconfig_file, .defstrval="./reconfig.raw", TYPE_STRING, 0}, \ {"rbconfig-file", CONFIG_HLP_RB_CFG_FILE, 0, .strptr=&nrUE_params.rbconfig_file, .defstrval="./rbconfig.raw", TYPE_STRING, 0}, \ - {"ue-idx-standalone", NULL, 0, .u16ptr=&ue_idx_standalone, .defuintval=0xFFFF, TYPE_UINT16, 0}, \ {"ue-rxgain", CONFIG_HLP_UERXG, 0, .dblptr=&nrUE_params.rx_gain, .defdblval=110, TYPE_DOUBLE, 0}, \ {"ue-rxgain-off", CONFIG_HLP_UERXGOFF, 0, .dblptr=&nrUE_params.rx_gain_off, .defdblval=0, TYPE_DOUBLE, 0}, \ {"ue-txgain", CONFIG_HLP_UETXG, 0, .dblptr=&nrUE_params.tx_gain, .defdblval=0, TYPE_DOUBLE, 0}, \ diff --git a/openair2/COMMON/as_message.h b/openair2/COMMON/as_message.h index cdf6792151..5a29d6881b 100644 --- a/openair2/COMMON/as_message.h +++ b/openair2/COMMON/as_message.h @@ -166,7 +166,7 @@ typedef struct as_stmsi_s { /* Dedicated NAS information */ typedef struct as_nas_info_s { uint32_t length; /* Length of the NAS information data */ - Byte_t* nas_data; /* Dedicated NAS information data container */ + uint8_t* nas_data; /* Dedicated NAS information data container */ } as_nas_info_t; /* Radio Access Bearer identity */ @@ -215,7 +215,7 @@ typedef struct broadcast_info_ind_s { * NAS request AS to refresh its KeNB key */ typedef struct kenb_refresh_req_s { - Byte_t kenb[32]; + uint8_t kenb[32]; } kenb_refresh_req_t; typedef struct nsa_oai_tun_nsa_s { @@ -229,7 +229,7 @@ typedef struct nsa_oai_tun_nsa_s { */ typedef struct cell_info_req_s { plmn_t plmnID; /* Selected PLMN identity */ - Byte_t rat; /* Bitmap - set of radio access technologies */ + uint8_t rat; /* Bitmap - set of radio access technologies */ } cell_info_req_t; /* diff --git a/openair2/COMMON/commonDef.h b/openair2/COMMON/commonDef.h index f5a24494a7..cff6b011fc 100644 --- a/openair2/COMMON/commonDef.h +++ b/openair2/COMMON/commonDef.h @@ -43,7 +43,6 @@ Description Contains global common definitions #include #include #include "common/platform_constants.h" -typedef uint8_t Byte_t; /* 8 bit unsigned integer */ /* ----------------------------------------------------------------------------- @@ -62,30 +61,30 @@ typedef uint8_t AcT_t; /* Access Technology */ * International Mobile Subscriber Identity */ typedef struct { - Byte_t length; + uint8_t length; union { struct { - Byte_t digit2:4; - Byte_t digit1:4; - Byte_t digit4:4; - Byte_t digit3:4; - Byte_t digit6:4; - Byte_t digit5:4; - Byte_t digit8:4; - Byte_t digit7:4; - Byte_t digit10:4; - Byte_t digit9:4; - Byte_t digit12:4; - Byte_t digit11:4; - Byte_t digit14:4; - Byte_t digit13:4; + uint8_t digit2: 4; + uint8_t digit1: 4; + uint8_t digit4: 4; + uint8_t digit3: 4; + uint8_t digit6: 4; + uint8_t digit5: 4; + uint8_t digit8: 4; + uint8_t digit7: 4; + uint8_t digit10: 4; + uint8_t digit9: 4; + uint8_t digit12: 4; + uint8_t digit11: 4; + uint8_t digit14: 4; + uint8_t digit13: 4; #define EVEN_PARITY 0 #define ODD_PARITY 1 - Byte_t parity:4; - Byte_t digit15:4; + uint8_t parity: 4; + uint8_t digit15: 4; } num; #define IMSI_SIZE 8 - Byte_t value[IMSI_SIZE]; + uint8_t value[IMSI_SIZE]; } u; } imsi_t; @@ -119,7 +118,7 @@ typedef struct { * Mobile subscriber dialing number */ typedef struct { - Byte_t ext:1; + uint8_t ext: 1; /* Type Of Number */ #define MSISDN_TON_UNKNOWKN 0b000 #define MSISDN_TON_INTERNATIONAL 0b001 @@ -128,7 +127,7 @@ typedef struct { #define MSISDN_TON_SUBCRIBER 0b100 #define MSISDN_TON_ABBREVIATED 0b110 #define MSISDN_TON_RESERVED 0b111 - Byte_t ton:3; + uint8_t ton: 3; /* Numbering Plan Identification */ #define MSISDN_NPI_UNKNOWN 0b0000 #define MSISDN_NPI_ISDN_TELEPHONY 0b0001 @@ -140,11 +139,11 @@ typedef struct { #define MSISDN_NPI_ISDN_MOBILE 0b0111 #define MSISDN_NPI_PRIVATE 0b1110 #define MSISDN_NPI_RESERVED 0b1111 - Byte_t npi:4; + uint8_t npi: 4; /* Dialing Number */ struct { - Byte_t lsb:4; - Byte_t msb:4; + uint8_t lsb: 4; + uint8_t msb: 4; #define MSISDN_DIGIT_SIZE 10 } digit[MSISDN_DIGIT_SIZE]; } msisdn_t; @@ -159,12 +158,12 @@ typedef imsi_t imei_t; * PLMN = BCD encoding (Mobile Country Code + Mobile Network Code) */ typedef struct { - Byte_t MCCdigit2:4; - Byte_t MCCdigit1:4; - Byte_t MNCdigit3:4; - Byte_t MCCdigit3:4; - Byte_t MNCdigit2:4; - Byte_t MNCdigit1:4; + uint8_t MCCdigit2: 4; + uint8_t MCCdigit1: 4; + uint8_t MNCdigit3: 4; + uint8_t MCCdigit3: 4; + uint8_t MNCdigit2: 4; + uint8_t MNCdigit1: 4; } plmn_t; /* @@ -256,17 +255,29 @@ typedef struct { /* * A list of PLMNs */ -#define PLMN_LIST_T(SIZE) struct {Byte_t n_plmns; plmn_t plmn[SIZE];} +#define PLMN_LIST_T(SIZE) \ + struct { \ + uint8_t n_plmns; \ + plmn_t plmn[SIZE]; \ + } /* * A list of TACs */ -#define TAC_LIST_T(SIZE) struct {Byte_t n_tacs; TAC_t tac[SIZE];} +#define TAC_LIST_T(SIZE) \ + struct { \ + uint8_t n_tacs; \ + TAC_t tac[SIZE]; \ + } /* * A list of TAIs */ -#define TAI_LIST_T(SIZE) struct {Byte_t n_tais; tai_t tai[SIZE];} +#define TAI_LIST_T(SIZE) \ + struct { \ + uint8_t n_tais; \ + tai_t tai[SIZE]; \ + } typedef enum eps_protocol_discriminator_e { /* Protocol discriminator identifier for EPS Mobility Management */ diff --git a/openair2/RRC/LTE/defs_NB_IoT.h b/openair2/RRC/LTE/defs_NB_IoT.h index 4cce4650d7..51835cc181 100644 --- a/openair2/RRC/LTE/defs_NB_IoT.h +++ b/openair2/RRC/LTE/defs_NB_IoT.h @@ -461,7 +461,7 @@ typedef struct UE_RRC_INST_NB_IoT_s { Rrc_State_NB_IoT_t RrcState; Rrc_Sub_State_NB_IoT_t RrcSubState; plmn_t plmnID; - Byte_t rat; + uint8_t rat; as_nas_info_t initialNasMsg; OAI_UECapability_NB_IoT_t *UECap; uint8_t *UECapability; diff --git a/openair2/RRC/LTE/rrc_defs.h b/openair2/RRC/LTE/rrc_defs.h index 959abc11f9..70897c16b7 100644 --- a/openair2/RRC/LTE/rrc_defs.h +++ b/openair2/RRC/LTE/rrc_defs.h @@ -801,7 +801,7 @@ typedef struct UE_RRC_INST_s { Rrc_State_t RrcState; Rrc_Sub_State_t RrcSubState; plmn_t plmnID; - Byte_t rat; + uint8_t rat; uint8_t selected_plmn_identity; as_nas_info_t initialNasMsg; OAI_UECapability_t *UECap; diff --git a/openair2/RRC/NR/nr_rrc_defs.h b/openair2/RRC/NR/nr_rrc_defs.h index 953f723853..7ed9bf322e 100644 --- a/openair2/RRC/NR/nr_rrc_defs.h +++ b/openair2/RRC/NR/nr_rrc_defs.h @@ -202,8 +202,6 @@ typedef struct gNB_RRC_UE_s { NR_CellGroupConfig_t *masterCellGroup; NR_RadioBearerConfig_t *rb_config; - ImsiMobileIdentity_t imsi; - /* KgNB as derived from KASME received from EPC */ uint8_t kgnb[32]; int8_t kgnb_ncc; diff --git a/openair3/CMakeLists.txt b/openair3/CMakeLists.txt index f638abbaaa..55f9fe91d6 100644 --- a/openair3/CMakeLists.txt +++ b/openair3/CMakeLists.txt @@ -1,6 +1,7 @@ add_subdirectory(LPP) add_subdirectory(M3AP) add_subdirectory(S1AP) +add_subdirectory(NAS) add_subdirectory(NGAP) add_subdirectory(NRPPA) -add_subdirectory(NAS) +add_subdirectory(UICC) diff --git a/openair3/NAS/CMakeLists.txt b/openair3/NAS/CMakeLists.txt index 50cbedd280..50bfe97bc3 100644 --- a/openair3/NAS/CMakeLists.txt +++ b/openair3/NAS/CMakeLists.txt @@ -1 +1,3 @@ add_subdirectory(COMMON) +add_subdirectory(NR_UE) +add_subdirectory(UE) diff --git a/openair3/NAS/COMMON/API/NETWORK/as_message.c b/openair3/NAS/COMMON/API/NETWORK/as_message.c index e1db277bcc..23d7097db3 100644 --- a/openair3/NAS/COMMON/API/NETWORK/as_message.c +++ b/openair3/NAS/COMMON/API/NETWORK/as_message.c @@ -192,7 +192,7 @@ int as_message_encode(char* buffer, as_message_t* msg, int length) int bytes = sizeof(msg->msgID); as_nas_info_t nas_msg; - Byte_t *dataptr=NULL; + uint8_t* dataptr = NULL; uint32_t len=0; memset(&nas_msg, 0, sizeof(as_nas_info_t)); @@ -230,30 +230,30 @@ int as_message_encode(char* buffer, as_message_t* msg, int length) case AS_NAS_ESTABLISH_REQ: /* NAS signalling connection establish request */ - bytes += sizeof(nas_establish_req_t) - sizeof(Byte_t*); + bytes += sizeof(nas_establish_req_t) - sizeof(uint8_t*); nas_msg = msg->msg.nas_establish_req.initialNasMsg; break; case AS_NAS_ESTABLISH_IND: /* NAS signalling connection establish indication */ - bytes += sizeof(nas_establish_ind_t) - sizeof(Byte_t*); + bytes += sizeof(nas_establish_ind_t) - sizeof(uint8_t*); nas_msg = msg->msg.nas_establish_ind.initialNasMsg; - dataptr = (Byte_t*)&(msg->msg.nas_establish_ind.initialNasMsg.nas_data); + dataptr = (uint8_t*)&(msg->msg.nas_establish_ind.initialNasMsg.nas_data); len=msg->msg.nas_establish_ind.initialNasMsg.length; break; case AS_NAS_ESTABLISH_RSP: /* NAS signalling connection establish response */ - bytes += sizeof(nas_establish_rsp_t) - sizeof(Byte_t*); + bytes += sizeof(nas_establish_rsp_t) - sizeof(uint8_t*); nas_msg = msg->msg.nas_establish_rsp.nasMsg; break; case AS_NAS_ESTABLISH_CNF: /* NAS signalling connection establish confirm */ - bytes += sizeof(nas_establish_cnf_t) - sizeof(Byte_t*); + bytes += sizeof(nas_establish_cnf_t) - sizeof(uint8_t*); nas_msg = msg->msg.nas_establish_cnf.nasMsg; - dataptr = (Byte_t*)&(msg->msg.nas_establish_cnf.nasMsg.nas_data); + dataptr = (uint8_t*)&(msg->msg.nas_establish_cnf.nasMsg.nas_data); len=msg->msg.nas_establish_ind.initialNasMsg.length; break; @@ -269,7 +269,7 @@ int as_message_encode(char* buffer, as_message_t* msg, int length) case AS_UL_INFO_TRANSFER_REQ: /* Uplink L3 data transfer request */ - bytes += sizeof(ul_info_transfer_req_t) - sizeof(Byte_t*); + bytes += sizeof(ul_info_transfer_req_t) - sizeof(uint8_t*); nas_msg = msg->msg.ul_info_transfer_req.nasMsg; break; @@ -280,13 +280,13 @@ int as_message_encode(char* buffer, as_message_t* msg, int length) case AS_UL_INFO_TRANSFER_IND: /* Uplink L3 data transfer indication */ - bytes += sizeof(ul_info_transfer_ind_t) - sizeof(Byte_t*); + bytes += sizeof(ul_info_transfer_ind_t) - sizeof(uint8_t*); nas_msg = msg->msg.ul_info_transfer_ind.nasMsg; break; case AS_DL_INFO_TRANSFER_REQ: /* Downlink L3 data transfer */ - bytes += sizeof(dl_info_transfer_req_t) - sizeof(Byte_t*); + bytes += sizeof(dl_info_transfer_req_t) - sizeof(uint8_t*); nas_msg = msg->msg.dl_info_transfer_req.nasMsg; break; @@ -297,7 +297,7 @@ int as_message_encode(char* buffer, as_message_t* msg, int length) case AS_DL_INFO_TRANSFER_IND: /* Downlink L3 data transfer indication */ - bytes += sizeof(dl_info_transfer_ind_t) - sizeof(Byte_t*); + bytes += sizeof(dl_info_transfer_ind_t) - sizeof(uint8_t*); nas_msg = msg->msg.dl_info_transfer_ind.nasMsg; break; diff --git a/openair3/NAS/COMMON/CMakeLists.txt b/openair3/NAS/COMMON/CMakeLists.txt index 21de73f92f..820b03f2b8 100644 --- a/openair3/NAS/COMMON/CMakeLists.txt +++ b/openair3/NAS/COMMON/CMakeLists.txt @@ -1,2 +1,2 @@ add_subdirectory(IES) -add_subdirectory(EMM) +add_subdirectory(UTIL) diff --git a/openair3/NAS/COMMON/EMM/MSG/CMakeLists.txt b/openair3/NAS/COMMON/EMM/MSG/CMakeLists.txt deleted file mode 100644 index fed78e453d..0000000000 --- a/openair3/NAS/COMMON/EMM/MSG/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -add_library(fgs_lib OBJECT - fgs_service_request.c -) - -target_link_libraries(fgs_lib PUBLIC fgs_ies_lib) - -target_include_directories(fgs_lib PUBLIC - ${CMAKE_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR} -) diff --git a/openair3/NAS/COMMON/EMM/MSG/RegistrationAccept.c b/openair3/NAS/COMMON/EMM/MSG/RegistrationAccept.c deleted file mode 100644 index d7c5c5d719..0000000000 --- a/openair3/NAS/COMMON/EMM/MSG/RegistrationAccept.c +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under - * the OAI Public License, Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -/*! \file RegistrationAccept.c - -\brief 5GS registration accept procedures -\author Yoshio INOUE, Masayuki HARADA -\email: yoshio.inoue@fujitsu.com,masayuki.harada@fujitsu.com -\date 2020 -\version 0.1 -*/ - -#include -#include -#include -#include - - -#include "TLVEncoder.h" -#include "TLVDecoder.h" -#include "RegistrationAccept.h" -#include "assertions.h" - -int decode_registration_accept(registration_accept_msg *registration_accept, const uint8_t *buffer, uint32_t len) -{ - uint32_t decoded = 0; - int decoded_result = 0; - - /* Decoding mandatory fields */ - if ((decoded_result = decode_fgs_registration_result(®istration_accept->fgsregistrationresult, 0, *(buffer + decoded), len - decoded)) < 0) - return decoded_result; - - decoded += decoded_result; - - if (decoded < len && buffer[decoded] == 0x77) { - registration_accept->guti = calloc(1, sizeof(*registration_accept->guti)); - if (!registration_accept->guti) - return -1; - int mi_dec = decode_5gs_mobile_identity(registration_accept->guti, 0x77, buffer + decoded, len - decoded); - if (mi_dec < 0) - return -1; - decoded += mi_dec; - } - - // todo ,Decoding optional fields - return decoded; -} - -int encode_registration_accept(registration_accept_msg *registration_accept, uint8_t *buffer, uint32_t len) -{ - int encoded = 0; - - LOG_FUNC_IN; - - - *(buffer + encoded) = encode_fgs_registration_result(®istration_accept->fgsregistrationresult); - encoded = encoded + 2; - - if (registration_accept->guti) { - int mi_enc = encode_5gs_mobile_identity(registration_accept->guti, 0x77, buffer + encoded, len - encoded); - if (mi_enc < 0) - return mi_enc; - encoded += mi_enc; - } - - // todo ,Encoding optional fields - LOG_FUNC_RETURN(encoded); -} - diff --git a/openair3/NAS/COMMON/ESM/MSG/PduSessionEstablishmentAccept.c b/openair3/NAS/COMMON/ESM/MSG/PduSessionEstablishmentAccept.c deleted file mode 100644 index aa19cae2e4..0000000000 --- a/openair3/NAS/COMMON/ESM/MSG/PduSessionEstablishmentAccept.c +++ /dev/null @@ -1,243 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under - * the OAI Public License, Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -#include -#include "PduSessionEstablishmentAccept.h" -#include "common/utils/LOG/log.h" -#include "nr_nas_msg.h" -#include "common/utils/tun_if.h" -#include "openair2/SDAP/nr_sdap/nr_sdap.h" - -static uint16_t getShort(uint8_t *input) -{ - uint16_t tmp16; - memcpy(&tmp16, input, sizeof(tmp16)); - return htons(tmp16); -} - -static int capture_ipv4_addr(const uint8_t *addr, char *ip, size_t len) -{ - return snprintf(ip, len, "%d.%d.%d.%d", addr[0], addr[1], addr[2], addr[3]); -} - -static int capture_ipv6_addr(const uint8_t *addr, char *ip, size_t len) -{ - // 24.501 Sec 9.11.4.10: "an interface identifier for the IPv6 link local - // address": link local starts with fe80::, and only the last 64bits are - // given (middle is zero) - return snprintf(ip, - len, - "fe80::%02x%02x:%02x%02x:%02x%02x:%02x%02x", - addr[0], - addr[1], - addr[2], - addr[3], - addr[4], - addr[5], - addr[6], - addr[7]); -} - -void capture_pdu_session_establishment_accept_msg(uint8_t *buffer, uint32_t msg_length) -{ - security_protected_nas_5gs_msg_t sec_nas_hdr; - security_protected_plain_nas_5gs_msg_t sec_nas_msg; - pdu_session_establishment_accept_msg_t psea_msg; - uint8_t *curPtr = buffer; - sec_nas_hdr.epd = *curPtr++; - sec_nas_hdr.sht = *curPtr++; - uint32_t tmp; - memcpy(&tmp, buffer, sizeof(tmp)); - sec_nas_hdr.mac = htonl(tmp); - curPtr += sizeof(sec_nas_hdr.mac); - sec_nas_hdr.sqn = *curPtr++; - sec_nas_msg.epd = *curPtr++; - sec_nas_msg.sht = *curPtr++; - sec_nas_msg.msg_type = *curPtr++; - sec_nas_msg.payload_type = *curPtr++; - sec_nas_msg.payload_len = getShort(curPtr); - curPtr += sizeof(sec_nas_msg.payload_len); - /* Mandatory Presence IEs */ - psea_msg.epd = *curPtr++; - psea_msg.pdu_id = *curPtr++; - psea_msg.pti = *curPtr++; - psea_msg.msg_type = *curPtr++; - psea_msg.pdu_type = *curPtr & 0x0f; - psea_msg.ssc_mode = (*curPtr++ & 0xf0) >> 4; - psea_msg.qos_rules.length = getShort(curPtr); - curPtr += sizeof(psea_msg.qos_rules.length); - /* Supports the capture of only one QoS Rule, it should be changed for multiple QoS Rules */ - qos_rule_t qos_rule; - qos_rule.id = *curPtr++; - qos_rule.length = getShort(curPtr); - curPtr += sizeof(qos_rule.length); - qos_rule.oc = (*(curPtr)&0xE0) >> 5; - qos_rule.dqr = (*(curPtr)&0x10) >> 4; - qos_rule.nb_pf = *curPtr++ & 0x0F; - - if(qos_rule.nb_pf) { - packet_filter_t pf; - - if(qos_rule.oc == ROC_CREATE_NEW_QOS_RULE || - qos_rule.oc == ROC_MODIFY_QOS_RULE_ADD_PF || - qos_rule.oc == ROC_MODIFY_QOS_RULE_REPLACE_PF) { - pf.pf_type.type_1.pf_dir = (*curPtr & 0x30) >> 4; - pf.pf_type.type_1.pf_id = *curPtr++ & 0x0F; - pf.pf_type.type_1.length = *curPtr++; - curPtr += (qos_rule.nb_pf * pf.pf_type.type_1.length); /* Ommit the Packet filter List */ - } else if (qos_rule.oc == ROC_MODIFY_QOS_RULE_DELETE_PF) { - curPtr += qos_rule.nb_pf; - } - } - - qos_rule.prcd = *curPtr++; - qos_rule.qfi = *curPtr++; - psea_msg.sess_ambr.length = *curPtr++; - curPtr += psea_msg.sess_ambr.length; /* Ommit the Seassion-AMBR */ - - /* Optional Presence IEs */ - while (curPtr < buffer + msg_length) { - uint8_t psea_iei = *curPtr++; - switch (psea_iei) { - case IEI_5GSM_CAUSE: /* Ommited */ - LOG_T(NAS, "PDU SESSION ESTABLISHMENT ACCEPT - Received 5GSM Cause IEI\n"); - curPtr++; - break; - - case IEI_PDU_ADDRESS: - LOG_T(NAS, "PDU SESSION ESTABLISHMENT ACCEPT - Received PDU Address IE\n"); - psea_msg.pdu_addr_ie.pdu_length = *curPtr++; - - /* Octet 3 */ - // PDU type (3 bits) - psea_msg.pdu_addr_ie.pdu_type = *curPtr & 0x07; - // SMF's IPv6 link local address (1 bit) - uint8_t si6lla = (*curPtr >> 3) & 0x01; - if (si6lla) - LOG_E(NAS, "SMF's IPv6 link local address is not handled\n"); - curPtr++; - - /* Octet 4 to n */ - // PDU address information - uint8_t *addr = psea_msg.pdu_addr_ie.pdu_addr_oct; - if (psea_msg.pdu_addr_ie.pdu_type == PDU_SESSION_TYPE_IPV4) { - for (int i = 0; i < IPv4_ADDRESS_LENGTH; ++i) - addr[i] = *curPtr++; - char ip[20]; - capture_ipv4_addr(&addr[0], ip, sizeof(ip)); - tun_config(1, ip, NULL, "oaitun_ue"); - setup_ue_ipv4_route(1, ip, "oaitun_ue"); - } else if (psea_msg.pdu_addr_ie.pdu_type == PDU_SESSION_TYPE_IPV6) { - for (int i = 0; i < IPv6_INTERFACE_ID_LENGTH; ++i) - addr[i] = *curPtr++; - char ipv6[40]; - capture_ipv6_addr(addr, ipv6, sizeof(ipv6)); - tun_config(1, NULL, ipv6, "oaitun_ue"); - } else if (psea_msg.pdu_addr_ie.pdu_type == PDU_SESSION_TYPE_IPV4V6) { - // 24.501 Sec 9.11.4.10: "If the PDU session type value indicates - // IPv4v6, the PDU address information in octet 4 to octet 11 - // contains an interface identifier for the IPv6 link local address - // and in octet 12 to octet 15 contains an IPv4 address." - for (int i = 0; i < IPv4_ADDRESS_LENGTH + IPv6_INTERFACE_ID_LENGTH; ++i) - addr[i] = *curPtr++; - char ipv6[40]; - capture_ipv6_addr(addr, ipv6, sizeof(ipv6)); - char ipv4[20]; - capture_ipv4_addr(&addr[IPv6_INTERFACE_ID_LENGTH], ipv4, sizeof(ipv4)); - tun_config(1, ipv4, ipv6, "oaitun_ue"); - setup_ue_ipv4_route(1, ipv4, "oaitun_ue"); - } else { - LOG_E(NAS, "unknown/unhandled PDU session establishment accept PDU type %d\n", psea_msg.pdu_addr_ie.pdu_type); - curPtr += psea_msg.pdu_addr_ie.pdu_length; - } - break; - - case IEI_RQ_TIMER_VALUE: /* Ommited */ - LOG_T(NAS, "PDU SESSION ESTABLISHMENT ACCEPT - Received RQ timer value IE\n"); - curPtr++; /* TS 24.008 10.5.7.3 */ - break; - - case IEI_SNSSAI: { - LOG_T(NAS, "PDU SESSION ESTABLISHMENT ACCEPT - Received S-NSSAI IE\n"); - uint8_t snssai_length = *curPtr; - curPtr += (snssai_length + sizeof(snssai_length)); - break; - } - - case IEI_ALWAYSON_PDU: /* Ommited */ - LOG_T(NAS, "PDU SESSION ESTABLISHMENT ACCEPT - Received Always-on PDU Session indication IE\n"); - curPtr++; - break; - - case IEI_MAPPED_EPS: { - LOG_T(NAS, "PDU SESSION ESTABLISHMENT ACCEPT - Received Mapped EPS bearer context IE\n"); - uint16_t mapped_eps_length = getShort(curPtr); - curPtr += mapped_eps_length; - break; - } - - case IEI_EAP_MSG: { - LOG_T(NAS, "PDU SESSION ESTABLISHMENT ACCEPT - Received EAP message IE\n"); - uint16_t eap_length = getShort(curPtr); - curPtr += (eap_length + sizeof(eap_length)); - break; - } - - case IEI_AUTH_QOS_DESC: { - LOG_T(NAS, "PDU SESSION ESTABLISHMENT ACCEPT - Received Authorized QoS flow descriptions IE\n"); - psea_msg.qos_fd_ie.length = getShort(curPtr); - curPtr += (psea_msg.qos_fd_ie.length + sizeof(psea_msg.qos_fd_ie.length)); - break; - } - - case IEI_EXT_CONF_OPT: { - LOG_T(NAS, "PDU SESSION ESTABLISHMENT ACCEPT - Received Extended protocol configuration options IE\n"); - psea_msg.ext_pp_ie.length = getShort(curPtr); - curPtr += (psea_msg.ext_pp_ie.length + sizeof(psea_msg.ext_pp_ie.length)); - break; - } - - case IEI_DNN: { - LOG_T(NAS, "PDU SESSION ESTABLISHMENT ACCEPT - Received DNN IE\n"); - psea_msg.dnn_ie.dnn_length = *curPtr++; - char apn[APN_MAX_LEN]; - - if(psea_msg.dnn_ie.dnn_length <= APN_MAX_LEN && - psea_msg.dnn_ie.dnn_length >= APN_MIN_LEN) { - memcpy(apn, curPtr, psea_msg.dnn_ie.dnn_length); - LOG_T(NAS, "PDU SESSION ESTABLISHMENT ACCEPT - APN: %s\n", apn); - } else - LOG_E(NAS, "PDU SESSION ESTABLISHMENT ACCEPT - DNN IE has invalid length\n"); - - curPtr = buffer + msg_length; // we force stop processing - break; - } - - default: - LOG_T(NAS, "PDU SESSION ESTABLISHMENT ACCEPT - Not known IE\n"); - curPtr = buffer + msg_length; // we force stop processing - break; - } - } - - set_qfi_pduid(qos_rule.qfi, psea_msg.pdu_id); - return; -} diff --git a/openair3/NAS/COMMON/IES/AuthenticationResponseParameter.c b/openair3/NAS/COMMON/IES/AuthenticationResponseParameter.c index 3ac3e60a3d..85bcaeb1b2 100644 --- a/openair3/NAS/COMMON/IES/AuthenticationResponseParameter.c +++ b/openair3/NAS/COMMON/IES/AuthenticationResponseParameter.c @@ -53,7 +53,10 @@ int decode_authentication_response_parameter(AuthenticationResponseParameter *au #endif return decoded; } -int encode_authentication_response_parameter(AuthenticationResponseParameter *authenticationresponseparameter, uint8_t iei, uint8_t *buffer, uint32_t len) +int encode_authentication_response_parameter(const AuthenticationResponseParameter *authenticationresponseparameter, + uint8_t iei, + uint8_t *buffer, + uint32_t len) { uint8_t *lenPtr; uint32_t encoded = 0; diff --git a/openair3/NAS/COMMON/IES/AuthenticationResponseParameter.h b/openair3/NAS/COMMON/IES/AuthenticationResponseParameter.h index 4e3dd33d5b..75a2dd9a2d 100644 --- a/openair3/NAS/COMMON/IES/AuthenticationResponseParameter.h +++ b/openair3/NAS/COMMON/IES/AuthenticationResponseParameter.h @@ -35,7 +35,10 @@ typedef struct AuthenticationResponseParameter_tag { OctetString res; } AuthenticationResponseParameter; -int encode_authentication_response_parameter(AuthenticationResponseParameter *authenticationresponseparameter, uint8_t iei, uint8_t *buffer, uint32_t len); +int encode_authentication_response_parameter(const AuthenticationResponseParameter *authenticationresponseparameter, + uint8_t iei, + uint8_t *buffer, + uint32_t len); int decode_authentication_response_parameter(AuthenticationResponseParameter *authenticationresponseparameter, uint8_t iei, uint8_t *buffer, uint32_t len); diff --git a/openair3/NAS/COMMON/IES/CMakeLists.txt b/openair3/NAS/COMMON/IES/CMakeLists.txt index 99df08e7b0..67cc9d782a 100644 --- a/openair3/NAS/COMMON/IES/CMakeLists.txt +++ b/openair3/NAS/COMMON/IES/CMakeLists.txt @@ -1,9 +1,6 @@ -add_library(fgs_ies_lib OBJECT - NasKeySetIdentifier.c - FGSMobileIdentity.c +add_library(nas_common_ies_lib OBJECT + AuthenticationResponseParameter.c + NasKeySetIdentifier.c ) -target_include_directories(fgs_ies_lib PUBLIC - ${CMAKE_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR} -) +target_include_directories(nas_common_ies_lib PUBLIC .) diff --git a/openair3/NAS/COMMON/IES/ExtendedProtocolDiscriminator.c b/openair3/NAS/COMMON/IES/ExtendedProtocolDiscriminator.c deleted file mode 100644 index e3b4bd021a..0000000000 --- a/openair3/NAS/COMMON/IES/ExtendedProtocolDiscriminator.c +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under - * the OAI Public License, Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - - -/*! \file ExtendedProtocolDiscriminator.c - -\brief Extended protocol discriminator for registration request procedures -\author Yoshio INOUE, Masayuki HARADA -\email: yoshio.inoue@fujitsu.com,masayuki.harada@fujitsu.com -\date 2020 -\version 0.1 -*/ - -#include -#include -#include - - -#include "TLVEncoder.h" -#include "TLVDecoder.h" -#include "ExtendedProtocolDiscriminator.h" - -int encode_ex_protocol_discriminator(ExtendedProtocolDiscriminator *exprotocoldiscriminator, uint8_t iei, uint8_t *buffer, uint32_t len) -{ - return 0; -} - -int decode_ex_protocol_discriminator(ExtendedProtocolDiscriminator *exprotocoldiscriminator, uint8_t iei, uint8_t *buffer, uint32_t len) -{ - return 0; -} - diff --git a/openair3/NAS/COMMON/IES/ExtendedProtocolDiscriminator.h b/openair3/NAS/COMMON/IES/ExtendedProtocolDiscriminator.h deleted file mode 100644 index 3bf1f6ec8f..0000000000 --- a/openair3/NAS/COMMON/IES/ExtendedProtocolDiscriminator.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under - * the OAI Public License, Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - - -/*! \file ExtendedProtocolDiscriminator.h - -\brief Extended protocol discriminator for registration request procedures -\author Yoshio INOUE, Masayuki HARADA -\email: yoshio.inoue@fujitsu.com,masayuki.harada@fujitsu.com -\date 2020 -\version 0.1 -*/ - -#include -#include -#include - -#include "OctetString.h" - -#ifndef EXTENDED_PROTOCOL_DISCRIMINATOR_H_ -#define EXTENDED_PROTOCOL_DISCRIMINATOR_H_ - -typedef uint8_t ExtendedProtocolDiscriminator; - -int encode_ex_protocol_discriminator(ExtendedProtocolDiscriminator *exprotocoldiscriminator, uint8_t iei, uint8_t *buffer, uint32_t len); - -int decode_ex_protocol_discriminator(ExtendedProtocolDiscriminator *exprotocoldiscriminator, uint8_t iei, uint8_t *buffer, uint32_t len); - -#endif /* EXTENDED PROTOCOL DISCRIMINATOR_H_ */ - diff --git a/openair3/NAS/COMMON/IES/NasKeySetIdentifier.c b/openair3/NAS/COMMON/IES/NasKeySetIdentifier.c index 82fe69d79e..368e66911b 100644 --- a/openair3/NAS/COMMON/IES/NasKeySetIdentifier.c +++ b/openair3/NAS/COMMON/IES/NasKeySetIdentifier.c @@ -50,7 +50,7 @@ int decode_nas_key_set_identifier(NasKeySetIdentifier *naskeysetidentifier, uint /** * @brief Encode the NAS key set identifier in one byte */ -uint8_t encode_nas_key_set_identifier(NasKeySetIdentifier *naskeysetidentifier, uint8_t iei) +uint8_t encode_nas_key_set_identifier(const NasKeySetIdentifier *naskeysetidentifier, uint8_t iei) { #if defined (NAS_DEBUG) dump_nas_key_set_identifier_xml(naskeysetidentifier, iei); diff --git a/openair3/NAS/COMMON/IES/NasKeySetIdentifier.h b/openair3/NAS/COMMON/IES/NasKeySetIdentifier.h index 5f6b445fc4..bdc1506cb2 100644 --- a/openair3/NAS/COMMON/IES/NasKeySetIdentifier.h +++ b/openair3/NAS/COMMON/IES/NasKeySetIdentifier.h @@ -39,7 +39,7 @@ typedef struct NasKeySetIdentifier_tag { uint8_t naskeysetidentifier:3; } NasKeySetIdentifier; -uint8_t encode_nas_key_set_identifier(NasKeySetIdentifier *naskeysetidentifier, uint8_t iei); +uint8_t encode_nas_key_set_identifier(const NasKeySetIdentifier *naskeysetidentifier, uint8_t iei); void dump_nas_key_set_identifier_xml(NasKeySetIdentifier *naskeysetidentifier, uint8_t iei); diff --git a/openair3/NAS/COMMON/IES/SpareHalfOctet.c b/openair3/NAS/COMMON/IES/SpareHalfOctet.c deleted file mode 100644 index 60c45e07c2..0000000000 --- a/openair3/NAS/COMMON/IES/SpareHalfOctet.c +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under - * the OAI Public License, Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - - -/*! \file SpareHalfOctet.c - -\brief registration request procedures for gNB -\author Yoshio INOUE, Masayuki HARADA -\email: yoshio.inoue@fujitsu.com,masayuki.harada@fujitsu.com -\date 2020 -\version 0.1 -*/ - -#include -#include -#include - - -#include "TLVEncoder.h" -#include "TLVDecoder.h" -#include "SpareHalfOctet.h" - -int decode_spare_half_octet(SpareHalfOctet *sparehalfoctet, uint8_t iei, uint8_t *buffer, uint32_t len) -{ - return 0; -} - -int encode_spare_half_octet(SpareHalfOctet *sparehalfoctet, uint8_t iei, uint8_t *buffer, uint32_t len) -{ - return 0; -} - diff --git a/openair3/NAS/COMMON/IES/SpareHalfOctet.h b/openair3/NAS/COMMON/IES/SpareHalfOctet.h deleted file mode 100644 index fbf410d4f8..0000000000 --- a/openair3/NAS/COMMON/IES/SpareHalfOctet.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under - * the OAI Public License, Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - - -/*! \file SpareHalfOctet.h - -\brief registration request procedures for gNB -\author Yoshio INOUE, Masayuki HARADA -\email: yoshio.inoue@fujitsu.com,masayuki.harada@fujitsu.com -\date 2020 -\version 0.1 -*/ - -#include -#include -#include - -#include "OctetString.h" - -#ifndef SPARE_HALF_OCTET_H_ -#define SPARE_HALF_OCTET_H_ - -#define SPARE_HALF_OCTET_MINIMUM_LENGTH 1 -#define SPARE_HALF_OCTET_MAXIMUM_LENGTH 1 - -typedef uint8_t SpareHalfOctet; - -int encode_spare_half_octet(SpareHalfOctet *sparehalfoctet, uint8_t iei, uint8_t *buffer, uint32_t len); - -int decode_spare_half_octet(SpareHalfOctet *sparehalfoctet, uint8_t iei, uint8_t *buffer, uint32_t len); - -#endif /* SPARE HALF OCTET_H_ */ - diff --git a/openair3/NAS/COMMON/NR_NAS_defs.h b/openair3/NAS/COMMON/NR_NAS_defs.h deleted file mode 100644 index f5510e5392..0000000000 --- a/openair3/NAS/COMMON/NR_NAS_defs.h +++ /dev/null @@ -1,386 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under - * the OAI Public License, Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.openairinterface.org/?page_id=698 - * - * Author and copyright: Laurent Thomas, open-cells.com - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ -#ifndef NR_NAS_DEFS_H -#define NR_NAS_DEFS_H - -#include -#include - -/* TS 24.007 possible L3 formats: - TableĀ 11.1: Formats of information elements - Format Meaning IEI present LI present Value part present - T Type only yes no no - V Value only no no yes - TV Type and Value yes no yes - LV Length and Value no yes yes - TLV Type, Length and Value yes yes yes - LV-E Length and Value no yes yes - TLV-E Type, Length and Value yes yes yes -*/ - -/* Map task id to printable name. */ -typedef struct { - int id; - char text[256]; -} text_info_t; - -static inline const char * idToText(const text_info_t* table, int size, int id) { - for(int i=0; i TS 24.007 -typedef enum { - SGSsessionmanagementmessages=0x2e, //LTEbox: 0xC0 ??? - SGSmobilitymanagementmessages=0x7e, -} Extendedprotocoldiscriminator_t; - -#define FOREACH_TYPE(TYPE_DEF) \ - TYPE_DEF(REGISTRATION_REQUEST, 0x41) \ - TYPE_DEF(REGISTRATION_ACCEPT, 0x42) \ - TYPE_DEF(REGISTRATION_COMPLETE, 0x43) \ - TYPE_DEF(REGISTRATION_REJECT, 0x44) \ - TYPE_DEF(FGS_DEREGISTRATION_REQUEST_UE_ORIGINATING, 0x45) \ - TYPE_DEF(FGS_DEREGISTRATION_ACCEPT_UE_ORIGINATING, 0x46) \ - TYPE_DEF(DeregistrationrequestUEterminated, 0x47) \ - TYPE_DEF(DeregistrationacceptUEterminated, 0x48) \ - TYPE_DEF(FGS_SERVICE_REQUEST, 0x4c) \ - TYPE_DEF(FGS_SERVICE_REJECT, 0x4d) \ - TYPE_DEF(FGS_SERVICE_ACCEPT, 0x4e) \ - TYPE_DEF(Controlplaneservicerequest, 0x4f) \ - TYPE_DEF(Networkslicespecificauthenticationcommand, 0x50) \ - TYPE_DEF(Networkslicespecificauthenticationcomplete, 0x51) \ - TYPE_DEF(Networkslicespecificauthenticationresult, 0x52) \ - TYPE_DEF(Configurationupdatecommand, 0x54) \ - TYPE_DEF(Configurationupdatecomplete, 0x55) \ - TYPE_DEF(FGS_AUTHENTICATION_REQUEST, 0x56) \ - TYPE_DEF(FGS_AUTHENTICATION_RESPONSE, 0x57) \ - TYPE_DEF(Authenticationreject, 0x58) \ - TYPE_DEF(Authenticationfailure, 0x59) \ - TYPE_DEF(Authenticationresult, 0x5a) \ - TYPE_DEF(FGS_IDENTITY_REQUEST, 0x5b) \ - TYPE_DEF(FGS_IDENTITY_RESPONSE, 0x5c) \ - TYPE_DEF(FGS_SECURITY_MODE_COMMAND, 0x5d) \ - TYPE_DEF(FGS_SECURITY_MODE_COMPLETE, 0x5e) \ - TYPE_DEF(Securitymodereject, 0x5f) \ - TYPE_DEF(SGMMstatus, 0x64) \ - TYPE_DEF(Notification, 0x65) \ - TYPE_DEF(Notificationresponse, 0x66) \ - TYPE_DEF(FGS_UPLINK_NAS_TRANSPORT, 0x67) \ - TYPE_DEF(FGS_DOWNLINK_NAS_TRANSPORT, 0x68) \ - TYPE_DEF(FGS_PDU_SESSION_ESTABLISHMENT_REQ, 0xc1) \ - TYPE_DEF(FGS_PDU_SESSION_ESTABLISHMENT_ACC, 0xc2) \ - TYPE_DEF(FGS_PDU_SESSION_ESTABLISHMENT_REJ, 0xc3) \ - TYPE_DEF(PDUsessionauthenticationcommand, 0xc5) \ - TYPE_DEF(PDUsessionauthenticationcomplete, 0xc6) \ - TYPE_DEF(PDUsessionauthenticationresult, 0xc7) \ - TYPE_DEF(PDUsessionmodificationrequest, 0xc9) \ - TYPE_DEF(PDUsessionmodificationreject, 0xca) \ - TYPE_DEF(PDUsessionmodificationcommand, 0xcb) \ - TYPE_DEF(PDUsessionmodificationcomplete, 0xcc) \ - TYPE_DEF(PDUsessionmodificationcommandreject, 0xcd) \ - TYPE_DEF(PDUsessionreleaserequest, 0xd1) \ - TYPE_DEF(PDUsessionreleasereject, 0xd2) \ - TYPE_DEF(PDUsessionreleasecommand, 0xd3) \ - TYPE_DEF(PDUsessionreleasecomplete, 0xd4) \ - TYPE_DEF(SGSMstatus, 0xd6) - -static const text_info_t message_text_info[] = { - FOREACH_TYPE(TO_TEXT) -}; - -//! Tasks id of each task -typedef enum { - FOREACH_TYPE(TO_ENUM) -} SGSmobilitymanagementmessages_t; - -// TS 24.501 -typedef enum { - PLAIN_5GS_MSG = 0, - INTEGRITY_PROTECTED = 1, - INTEGRITY_PROTECTED_AND_CIPHERED = 2, - INTEGRITY_PROTECTED_WITH_NEW_SECU_CTX = 3, - INTEGRITY_PROTECTED_AND_CIPHERED_WITH_NEW_SECU_CTX = 4, -} Security_header_t; - -typedef enum { - SUCI=1, - SGGUTI, - IMEI, - SGSTMSI, - IMEISV, - MACaddress, - EUI64, -} identitytype_t; - - -// table 9.11.3.2.1 -#define FOREACH_CAUSE(CAUSE_DEF) \ - CAUSE_DEF(Illegal_UE,0x3 )\ - CAUSE_DEF(PEI_not_accepted,0x5 )\ - CAUSE_DEF(Illegal_ME,0x6 )\ - CAUSE_DEF(SGS_services_not_allowed,0x7 )\ - CAUSE_DEF(UE_identity_cannot_be_derived_by_the_network,0x9 )\ - CAUSE_DEF(Implicitly_de_registered,0x0a )\ - CAUSE_DEF(PLMN_not_allowed,0x0b )\ - CAUSE_DEF(Tracking_area_not_allowed,0x0c )\ - CAUSE_DEF(Roaming_not_allowed_in_this_tracking_area,0x0d )\ - CAUSE_DEF(No_suitable_cells_in_tracking_area,0x0f )\ - CAUSE_DEF(MAC_failure,0x14 )\ - CAUSE_DEF(Synch_failure,0x15 )\ - CAUSE_DEF(Congestion,0x16 )\ - CAUSE_DEF(UE_security_capabilities_mismatch,0x17 )\ - CAUSE_DEF(Security_mode_rejected_unspecified,0x18 )\ - CAUSE_DEF(Non_5G_authentication_unacceptable,0x1a )\ - CAUSE_DEF(N1_mode_not_allowed,0x1b )\ - CAUSE_DEF(Restricted_service_area,0x1c )\ - CAUSE_DEF(Redirection_to_EPC_required,0x1f )\ - CAUSE_DEF(LADN_not_available,0x2b )\ - CAUSE_DEF(No_network_slices_available,0x3e )\ - CAUSE_DEF(Maximum_number_of_PDU_sessions_reached,0x41 )\ - CAUSE_DEF(Insufficient_resources_for_specific_slice_and_DNN,0x43 )\ - CAUSE_DEF(Insufficient_resources_for_specific_slice,0x45 )\ - CAUSE_DEF(ngKSI_already_in_use,0x47 )\ - CAUSE_DEF(Non_3GPP_access_to_5GCN_not_allowed,0x48 )\ - CAUSE_DEF(Serving_network_not_authorized,0x49 )\ - CAUSE_DEF(Temporarily_not_authorized_for_this_SNPN,0x4A )\ - CAUSE_DEF(Permanently_not_authorized_for_this_SNPN,0x4b )\ - CAUSE_DEF(Not_authorized_for_this_CAG_or_authorized_for_CAG_cells_only,0x4c )\ - CAUSE_DEF(Wireline_access_area_not_allowed,0x4d )\ - CAUSE_DEF(Payload_was_not_forwarded,0x5a )\ - CAUSE_DEF(DNN_not_supported_or_not_subscribed_in_the_slice,0x5b )\ - CAUSE_DEF(Insufficient_user_plane_resources_for_the_PDU_session,0x5c )\ - CAUSE_DEF(Semantically_incorrect_message,0x5f )\ - CAUSE_DEF(Invalid_mandatory_information,0x60 )\ - CAUSE_DEF(Message_type_non_existent_or_not_implemented,0x61 )\ - CAUSE_DEF(Message_type_not_compatible_with_the_protocol_state,0x62 )\ - CAUSE_DEF(Information_element_non_existent_or_not_implemented,0x63 )\ - CAUSE_DEF(Conditional_IE_error,0x64 )\ - CAUSE_DEF(Message_not_compatible_with_the_protocol_state,0x65 )\ - CAUSE_DEF(Protocol_error_unspecified,0x67 ) - -/* Map task id to printable name. */ - -#define CAUSE_TEXT(LabEl, nUmID) {nUmID, #LabEl}, - -static const text_info_t cause_text_info[] = { - FOREACH_CAUSE(TO_TEXT) -}; - -#define CAUSE_ENUM(LabEl, nUmID ) LabEl = nUmID, -//! Tasks id of each task -typedef enum { - FOREACH_CAUSE(TO_ENUM) -} cause_id_t; - -//_table_9.11.4.2.1:_5GSM_cause_information_element -#define FOREACH_CAUSE_SECU(CAUSE_SECU_DEF) \ - CAUSE_SECU_DEF(Security_Operator_determined_barring,0x08 )\ - CAUSE_SECU_DEF(Security_Insufficient_resources,0x1a )\ - CAUSE_SECU_DEF(Security_Missing_or_unknown_DNN,0x1b )\ - CAUSE_SECU_DEF(Security_Unknown_PDU_session_type,0x1c )\ - CAUSE_SECU_DEF(Security_User_authentication_or_authorization_failed,0x1d )\ - CAUSE_SECU_DEF(Security_Request_rejected_unspecified,0x1f )\ - CAUSE_SECU_DEF(Security_Service_option_not_supported,0x20 )\ - CAUSE_SECU_DEF(Security_Requested_service_option_not_subscribed,0x21 )\ - CAUSE_SECU_DEF(Security_Service_option_temporarily_out_of_order,0x22 )\ - CAUSE_SECU_DEF(Security_PTI_already_in_use,0x23 )\ - CAUSE_SECU_DEF(Security_Regular_deactivation,0x24 )\ - CAUSE_SECU_DEF(Security_Network_failure,0x26 )\ - CAUSE_SECU_DEF(Security_Reactivation_requested,0x27 )\ - CAUSE_SECU_DEF(Security_Semantic_error_in_the_TFT_operation,0x29 )\ - CAUSE_SECU_DEF(Security_Syntactical_error_in_the_TFT_operation,0x2a )\ - CAUSE_SECU_DEF(Security_Invalid_PDU_session_identity,0x2b )\ - CAUSE_SECU_DEF(Security_Semantic_errors_in_packet_filter,0x2c )\ - CAUSE_SECU_DEF(Security_Syntactical_error_in_packet_filter,0x2d )\ - CAUSE_SECU_DEF(Security_Out_of_LADN_service_area,0x2e )\ - CAUSE_SECU_DEF(Security_PTI_mismatch,0x2f )\ - CAUSE_SECU_DEF(Security_PDU_session_type_IPv4_only_allowed,0x32 )\ - CAUSE_SECU_DEF(Security_PDU_session_type_IPv6_only_allowed,0x33 )\ - CAUSE_SECU_DEF(Security_PDU_session_does_not_exist,0x36 )\ - CAUSE_SECU_DEF(Security_PDU_session_type_IPv4v6_only_allowed,0x39 )\ - CAUSE_SECU_DEF(Security_PDU_session_type_Unstructured_only_allowed,0x3a )\ - CAUSE_SECU_DEF(Security_PDU_session_type_Ethernet_only_allowed,0x3d )\ - CAUSE_SECU_DEF(Security_Insufficient_resources_for_specific_slice_and_DNN,0x43 )\ - CAUSE_SECU_DEF(Security_Not_supported_SSC_mode,0x44 )\ - CAUSE_SECU_DEF(Security_Insufficient_resources_for_specific_slice,0x45 )\ - CAUSE_SECU_DEF(Security_Missing_or_unknown_DNN_in_a_slice,0x46 )\ - CAUSE_SECU_DEF(Security_Invalid_PTI_value,0x51 )\ - CAUSE_SECU_DEF(Security_Maximum_data_rate_per_UE_for_user_plane_integrity_protection_is_too_low,0x52 )\ - CAUSE_SECU_DEF(Security_Semantic_error_in_the_QoS_operation,0x53 )\ - CAUSE_SECU_DEF(Security_Syntactical_error_in_the_QoS_operation,0x54 )\ - CAUSE_SECU_DEF(Security_Invalid_mapped_EPS_bearer_identity,0x55 )\ - CAUSE_SECU_DEF(Security_Semantically_incorrect_message,0x5f )\ - CAUSE_SECU_DEF(Security_Invalid_mandatory_information,0x60 )\ - CAUSE_SECU_DEF(Security_Message_type_non_existent_or_not_implemented,0x61 )\ - CAUSE_SECU_DEF(Security_Message_type_not_compatible_with_the_protocol_state,0x62 )\ - CAUSE_SECU_DEF(Security_Information_element_non_existent_or_not_implemented,0x63 )\ - CAUSE_SECU_DEF(Security_Conditional_IE_error,0x64 )\ - CAUSE_SECU_DEF(Security_Message_not_compatible_with_the_protocol_state,0x65 )\ - CAUSE_SECU_DEF(Security_Protocol_error_unspecified,0x6f ) - -static const text_info_t cause_secu_text_info[] = { - FOREACH_CAUSE_SECU(TO_TEXT) -}; - -//! Tasks id of each task -typedef enum { - FOREACH_CAUSE_SECU(TO_ENUM) -} cause_secu_id_t; - -// IEI (information element identifier) are spread in each message definition -#define IEI_NULL 0x00 -#define IEI_RAND 0x21 -#define IEI_AUTN 0x20 -#define IEI_EAP 0x78 -#define IEI_AuthenticationResponse 0x2d - -//TS 24.501 sub layer states for UE -// for network side, only 5GMMderegistered, 5GMMderegistered_initiated, 5GMMregistered, 5GMMservice_request_initiated are valid -typedef enum { - SGMMnull, - SGMMderegistered, - SGMMderegistered_initiated, - SGMMregistered, - SGMMregistered_initiated, - SGMMservice_request_initiated, -} SGMM_UE_states; - -typedef struct { - Extendedprotocoldiscriminator_t epd:8; - Security_header_t sh:8; - SGSmobilitymanagementmessages_t mt:8; -} SGScommonHeader_t; - -typedef struct { - Extendedprotocoldiscriminator_t epd:8; - Security_header_t sh:8; - SGSmobilitymanagementmessages_t mt:8; - identitytype_t it:8; -} Identityrequest_t; - -// the message continues with the identity value, depending on identity type, see TS 14.501, 9.11.3.4 -typedef struct __attribute__((packed)) { - Extendedprotocoldiscriminator_t epd:8; - Security_header_t sh:8; - SGSmobilitymanagementmessages_t mt:8; - uint16_t len; -} -Identityresponse_t; - -typedef struct __attribute__((packed)) { - Identityresponse_t common; - identitytype_t mi:8; - unsigned int supiFormat:4; - unsigned int identityType:4; - unsigned int mcc1:4; - unsigned int mcc2:4; - unsigned int mcc3:4; - unsigned int mnc3:4; - unsigned int mnc1:4; - unsigned int mnc2:4; - unsigned int routing1:4; - unsigned int routing2:4; - unsigned int routing3:4; - unsigned int routing4:4; - unsigned int protectScheme:4; - unsigned int spare:4; - uint8_t hplmnId; -} -IdentityresponseIMSI_t; - -typedef struct __attribute__((packed)) { - Extendedprotocoldiscriminator_t epd:8; - Security_header_t sh:8; - SGSmobilitymanagementmessages_t mt:8; - unsigned int ngKSI:4; - unsigned int spare:4; - unsigned int ABBALen:8; - unsigned int ABBA:16; - uint8_t ieiRAND; - uint8_t RAND[16]; - uint8_t ieiAUTN; - uint8_t AUTNlen; - uint8_t AUTN[16]; -} -authenticationrequestHeader_t; - -typedef struct __attribute__((packed)) { - Extendedprotocoldiscriminator_t epd:8; - Security_header_t sh:8; - SGSmobilitymanagementmessages_t mt:8; - uint8_t iei; - uint8_t RESlen; - uint8_t RES[16]; -} authenticationresponse_t; - -//AUTHENTICATION RESULT - -typedef struct __attribute__((packed)) { - Extendedprotocoldiscriminator_t epd:8; - Security_header_t sh:8; - SGSmobilitymanagementmessages_t mt:8; - - unsigned int selectedNASsecurityalgorithms; - unsigned int ngKSI:4; //ngKSI NAS key set identifier 9.11.3.32 - unsigned int spare:4; - // LV 3-9 bytes Replayed UE security capabilities UE security capability 9.11.3.54 - - /* optional - TV (E-, 1 byte) Oprional IMEISV request IMEISV request 9.11.3.28 - TV (57, 2 bytes ) Selected EPS NAS security algorithms EPS NAS security algorithms 9.11.3.25 - TLV (36, 3 bytes) Additional 5G security information Additional 5G security information 9.11.3.12 - TLV-E (78,, 7-1503 bytes) EAP message EAP message 9.11.2.2 - TLV (38, 4-n)ABBA ABBA 9.11.3.10 - TLV (19, 4-7) Replayed S1 UE security capabilities S1 UE security capability 9.11.3.48A - */ - -} securityModeCommand_t; - -typedef struct __attribute__((packed)) { - Extendedprotocoldiscriminator_t epd: 8; - Security_header_t sh: 8; - SGSmobilitymanagementmessages_t mt: 8; -} deregistrationRequestUEOriginating_t; - -typedef struct { - uicc_t *uicc; -} nr_user_nas_t; - -#define STATIC_ASSERT(test_for_true) _Static_assert((test_for_true), "(" #test_for_true ") failed") -#define myCalloc(var, type) type * var=(type*)calloc(sizeof(type),1); -#define arrayCpy(tO, FroM) STATIC_ASSERT(sizeof(tO) == sizeof(FroM)) ; memcpy(tO, FroM, sizeof(tO)) -int resToresStar(uint8_t *msg, const uicc_t* uicc); - -int identityResponse(void **msg, nr_user_nas_t *UE); -int authenticationResponse(void **msg, nr_user_nas_t *UE); -void servingNetworkName(uint8_t *msg, char * imsiStr, int nmc_size); - -#endif diff --git a/openair3/NAS/COMMON/UTIL/CMakeLists.txt b/openair3/NAS/COMMON/UTIL/CMakeLists.txt new file mode 100644 index 0000000000..dc29dff207 --- /dev/null +++ b/openair3/NAS/COMMON/UTIL/CMakeLists.txt @@ -0,0 +1,6 @@ +add_library(nas_utils OBJECT + TLVDecoder.c + OctetString.c +) + +target_include_directories(nas_utils PRIVATE .) diff --git a/openair3/NAS/COMMON/UTIL/OctetString.c b/openair3/NAS/COMMON/UTIL/OctetString.c index 2f1b7b2c32..4afa522664 100644 --- a/openair3/NAS/COMMON/UTIL/OctetString.c +++ b/openair3/NAS/COMMON/UTIL/OctetString.c @@ -55,8 +55,7 @@ void free_octet_string(OctetString *octetstring) } } - -int encode_octet_string(OctetString *octetstring, uint8_t *buffer, uint32_t buflen) +int encode_octet_string(const OctetString *octetstring, uint8_t *buffer, uint32_t buflen) { if (octetstring != NULL) { if ((octetstring->value != NULL) && (octetstring->length > 0)) { @@ -71,7 +70,7 @@ int encode_octet_string(OctetString *octetstring, uint8_t *buffer, uint32_t bufl } } -int decode_octet_string(OctetString *octetstring, uint16_t pdulen, uint8_t *buffer, uint32_t buflen) +int decode_octet_string(OctetString *octetstring, uint16_t pdulen, const uint8_t *buffer, uint32_t buflen) { if (buflen < pdulen) return -1; diff --git a/openair3/NAS/COMMON/UTIL/OctetString.h b/openair3/NAS/COMMON/UTIL/OctetString.h index 2223b67ece..fcfe6d46b4 100644 --- a/openair3/NAS/COMMON/UTIL/OctetString.h +++ b/openair3/NAS/COMMON/UTIL/OctetString.h @@ -58,9 +58,9 @@ OctetString* dup_octet_string(OctetString*octetstring); void free_octet_string(OctetString *octetstring); -int encode_octet_string(OctetString *octetstring, uint8_t *buffer, uint32_t len); +int encode_octet_string(const OctetString *octetstring, uint8_t *buffer, uint32_t len); -int decode_octet_string(OctetString *octetstring, uint16_t pdulen, uint8_t *buffer, uint32_t buflen); +int decode_octet_string(OctetString *octetstring, uint16_t pdulen, const uint8_t *buffer, uint32_t buflen); char* dump_octet_string_xml(const OctetString * const octetstring); diff --git a/openair3/NAS/COMMON/UTIL/TLVEncoder.h b/openair3/NAS/COMMON/UTIL/TLVEncoder.h index a400d9e388..3b5fcfda3c 100644 --- a/openair3/NAS/COMMON/UTIL/TLVEncoder.h +++ b/openair3/NAS/COMMON/UTIL/TLVEncoder.h @@ -23,6 +23,7 @@ #define TLV_ENCODER_H_ #include // htonl, htons +#include // memcpy #define ENCODE_U8(buffer, value, size) \ do { \ diff --git a/openair3/NAS/COMMON/nr_common.c b/openair3/NAS/COMMON/nr_common.c deleted file mode 100644 index 6c935df4f1..0000000000 --- a/openair3/NAS/COMMON/nr_common.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under - * the OAI Public License, Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.openairinterface.org/?page_id=698 - * - * Author and copyright: Laurent Thomas, open-cells.com - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -#include -#include -#include -#include - -void servingNetworkName(uint8_t *msg, char * imsiStr, int nmc_size) { - //SNN-network-identifier in TS 24.501 - // TS 24.501: If the MNC of the serving PLMN has two digits, then a zero is added at the beginning. - const char *format="5G:mnc000.mcc000.3gppnetwork.org"; - memcpy(msg,format, strlen(format)); - - if (nmc_size == 2) - memcpy(msg+7, imsiStr+3, 2); - else - memcpy(msg+6, imsiStr+3, 3); - - memcpy(msg+13, imsiStr, 3); -} - -int resToresStar(uint8_t *msg, const uicc_t* uicc) { - // TS 33.220 annex B.2 => FC=0x6B in TS 33.501 annex A.4 - //input S to KDF - uint8_t S[128]= {0}; - S[0]=0x6B; - uint8_t *ptr=S+1; - servingNetworkName(ptr, uicc->imsiStr, uicc->nmc_size); - *(uint16_t *)(ptr+strlen((char *)ptr))=htons(strlen((char *)ptr)); - ptr+=strlen((char *)ptr)+sizeof(uint16_t); - // add rand - memcpy(ptr, uicc->rand, sizeof(uicc->rand) ) ; - *(uint16_t *)(ptr+sizeof(uicc->rand))=htons(sizeof(uicc->rand)); - ptr+=sizeof(uicc->rand)+sizeof(uint16_t); - // add res - memcpy(ptr, uicc->milenage_res, sizeof(uicc->milenage_res) ) ; - *(uint16_t *)(ptr+sizeof(uicc->milenage_res))=htons(sizeof(uicc->milenage_res)); - ptr+=sizeof(uicc->milenage_res)+sizeof(uint16_t); - // S is done - uint8_t ckik[sizeof(uicc->ck) +sizeof(uicc->ik)]; - memcpy(ckik, uicc->ck, sizeof(uicc->ck)); - memcpy(ckik+sizeof(uicc->ck),uicc->ik, sizeof(uicc->ik)); - uint8_t out[32] = {0}; - assert(ptr-S == 32); - //kdf(S, ptr-S, ckik, 32, out, sizeof(out)); - byte_array_t data = {.buf = ckik, .len = 32}; - kdf(S, data, 32, out); - - memcpy(msg, out+16, 16); - return 16; -} diff --git a/openair3/NAS/NR_UE/5GS/5GMM/IES/CMakeLists.txt b/openair3/NAS/NR_UE/5GS/5GMM/IES/CMakeLists.txt new file mode 100644 index 0000000000..24ed3022a6 --- /dev/null +++ b/openair3/NAS/NR_UE/5GS/5GMM/IES/CMakeLists.txt @@ -0,0 +1,13 @@ +add_library(fgs_5gmm_ies_lib OBJECT + FGSMobileIdentity.c + FGSRegistrationType.c + FGSRegistrationResult.c + FGMMCapability.c + NrUESecurityCapability.c + FGCNasMessageContainer.c + SORTransparentContainer.c +) + +target_link_libraries(fgs_5gmm_ies_lib PUBLIC + nas_common_ies_lib +) diff --git a/openair3/NAS/COMMON/IES/FGCNasMessageContainer.c b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGCNasMessageContainer.c similarity index 88% rename from openair3/NAS/COMMON/IES/FGCNasMessageContainer.c rename to openair3/NAS/NR_UE/5GS/5GMM/IES/FGCNasMessageContainer.c index 4e8de951a5..d06521c88c 100644 --- a/openair3/NAS/COMMON/IES/FGCNasMessageContainer.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGCNasMessageContainer.c @@ -32,7 +32,6 @@ #include #include - #include "TLVEncoder.h" #include "TLVDecoder.h" #include "FGCNasMessageContainer.h" @@ -52,14 +51,16 @@ int decode_fgc_nas_message_container(FGCNasMessageContainer *nasmessagecontainer decoded += 2; CHECK_LENGTH_DECODER(len - decoded, ielen); - if ((decode_result = decode_octet_string(&nasmessagecontainer->nasmessagecontainercontents, ielen, buffer + decoded, len - decoded)) < 0) + if ((decode_result = + decode_octet_string(&nasmessagecontainer->nasmessagecontainercontents, ielen, buffer + decoded, len - decoded)) + < 0) return decode_result; else decoded += decode_result; return decoded; } -int encode_fgc_nas_message_container(FGCNasMessageContainer *nasmessagecontainer, uint8_t iei, uint8_t *buffer, uint32_t len) +int encode_fgc_nas_message_container(const FGCNasMessageContainer *nasmessagecontainer, uint8_t iei, uint8_t *buffer, uint32_t len) { uint32_t encoded = 0; int encode_result; @@ -73,7 +74,8 @@ int encode_fgc_nas_message_container(FGCNasMessageContainer *nasmessagecontainer encoded += 2; - if ((encode_result = encode_octet_string(&nasmessagecontainer->nasmessagecontainercontents, buffer + encoded, len - encoded)) < 0) { + if ((encode_result = encode_octet_string(&nasmessagecontainer->nasmessagecontainercontents, buffer + encoded, len - encoded)) + < 0) { return encode_result; } else { uint16_t tmp = htons(encoded + encode_result - 3); @@ -95,5 +97,3 @@ void dump_fgc_nas_message_container_xml(FGCNasMessageContainer *nasmessagecontai printf("%s", dump_octet_string_xml(&nasmessagecontainer->nasmessagecontainercontents)); printf("\n"); } - - diff --git a/openair3/NAS/COMMON/IES/FGCNasMessageContainer.h b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGCNasMessageContainer.h similarity index 93% rename from openair3/NAS/COMMON/IES/FGCNasMessageContainer.h rename to openair3/NAS/NR_UE/5GS/5GMM/IES/FGCNasMessageContainer.h index 19a1679b7e..a81c1add67 100644 --- a/openair3/NAS/COMMON/IES/FGCNasMessageContainer.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGCNasMessageContainer.h @@ -44,11 +44,10 @@ typedef struct FGCNasMessageContainer_tag { OctetString nasmessagecontainercontents; } FGCNasMessageContainer; -int encode_fgc_nas_message_container(FGCNasMessageContainer *nasmessagecontainer, uint8_t iei, uint8_t *buffer, uint32_t len); +int encode_fgc_nas_message_container(const FGCNasMessageContainer *nasmessagecontainer, uint8_t iei, uint8_t *buffer, uint32_t len); int decode_fgc_nas_message_container(FGCNasMessageContainer *nasmessagecontainer, uint8_t iei, uint8_t *buffer, uint32_t len); void dump_fgc_nas_message_container_xml(FGCNasMessageContainer *nasmessagecontainer, uint8_t iei); #endif /* FGC NAS MESSAGE CONTAINER_H_ */ - diff --git a/openair3/NAS/COMMON/IES/FGMMCapability.c b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGMMCapability.c similarity index 84% rename from openair3/NAS/COMMON/IES/FGMMCapability.c rename to openair3/NAS/NR_UE/5GS/5GMM/IES/FGMMCapability.c index ce156e63bf..c053070518 100644 --- a/openair3/NAS/COMMON/IES/FGMMCapability.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGMMCapability.c @@ -31,24 +31,20 @@ #include #include - #include "TLVEncoder.h" #include "TLVDecoder.h" #include "FGMMCapability.h" - - -int encode_5gmm_capability(FGMMCapability *fgmmcapability, uint8_t iei, uint8_t *buffer, uint32_t len) +int encode_5gmm_capability(const FGMMCapability *fgmmcapability, uint8_t iei, uint8_t *buffer, uint32_t len) { int encoded = 0; - if(iei){ + if (iei) { *buffer = fgmmcapability->iei; - encoded++; - *(buffer+encoded) = fgmmcapability->length; - encoded++; - *(buffer+encoded) = fgmmcapability->value; - encoded++; + encoded++; + *(buffer + encoded) = fgmmcapability->length; + encoded++; + *(buffer + encoded) = fgmmcapability->value; + encoded++; } return encoded; } - diff --git a/openair3/NAS/COMMON/IES/FGMMCapability.h b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGMMCapability.h similarity index 93% rename from openair3/NAS/COMMON/IES/FGMMCapability.h rename to openair3/NAS/NR_UE/5GS/5GMM/IES/FGMMCapability.h index d427896338..b125935f9d 100644 --- a/openair3/NAS/COMMON/IES/FGMMCapability.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGMMCapability.h @@ -27,7 +27,6 @@ * \version 0.1 */ - #include #include #include @@ -37,15 +36,12 @@ #ifndef FGMM_CAPABILITY_H_ #define FGMM_CAPABILITY_H_ - typedef struct { uint8_t iei; uint8_t length; uint8_t value; } FGMMCapability; - -int encode_5gmm_capability(FGMMCapability *fgmmcapability, uint8_t iei, uint8_t *buffer, uint32_t len); +int encode_5gmm_capability(const FGMMCapability *fgmmcapability, uint8_t iei, uint8_t *buffer, uint32_t len); #endif /* FGMM_CAPABILITY_H_ */ - diff --git a/openair3/NAS/COMMON/IES/FGSDeregistrationType.h b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSDeregistrationType.h similarity index 100% rename from openair3/NAS/COMMON/IES/FGSDeregistrationType.h rename to openair3/NAS/NR_UE/5GS/5GMM/IES/FGSDeregistrationType.h diff --git a/openair3/NAS/COMMON/IES/FGSMobileIdentity.c b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSMobileIdentity.c similarity index 72% rename from openair3/NAS/COMMON/IES/FGSMobileIdentity.c rename to openair3/NAS/NR_UE/5GS/5GMM/IES/FGSMobileIdentity.c index f70dfc66ed..883c5ba98d 100644 --- a/openair3/NAS/COMMON/IES/FGSMobileIdentity.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSMobileIdentity.c @@ -27,7 +27,6 @@ * \version 0.1 */ - #include #include #include @@ -42,11 +41,11 @@ static int decode_guti_5gs_mobile_identity(Guti5GSMobileIdentity_t *guti, const uint8_t *buffer); -static int encode_guti_5gs_mobile_identity(Guti5GSMobileIdentity_t *guti, uint8_t *buffer); -static int encode_suci_5gs_mobile_identity(Suci5GSMobileIdentity_t *suci, uint8_t *buffer); -static int encode_imeisv_5gs_mobile_identity(Imeisv5GSMobileIdentity_t *imeisv, uint8_t *buffer); +static int encode_guti_5gs_mobile_identity(const Guti5GSMobileIdentity_t *guti, uint8_t *buffer); +static int encode_suci_5gs_mobile_identity(const Suci5GSMobileIdentity_t *suci, uint8_t *buffer); +static int encode_imeisv_5gs_mobile_identity(const Imeisv5GSMobileIdentity_t *imeisv, uint8_t *buffer); -int encode_stmsi_5gs_mobile_identity(uint8_t *buffer, Stmsi5GSMobileIdentity_t *stmsi, uint32_t len) +int encode_stmsi_5gs_mobile_identity(uint8_t *buffer, const Stmsi5GSMobileIdentity_t *stmsi, uint32_t len) { // Return if buffer is shorter than min length if (len < LEN_5G_FGS_TMSI_IE) @@ -114,12 +113,9 @@ int decode_5gs_mobile_identity(FGSMobileIdentity *fgsmobileidentity, uint8_t iei uint8_t typeofidentity = *(buffer + decoded) & 0x7; - if (typeofidentity == FGS_MOBILE_IDENTITY_5G_GUTI) { - decoded_rc = decode_guti_5gs_mobile_identity(&fgsmobileidentity->guti, - buffer + decoded); - } else { - AssertFatal(false, "Mobile Identity encoding of type %d not implemented\n", typeofidentity); - } + AssertFatal(typeofidentity == FGS_MOBILE_IDENTITY_5G_GUTI, "Mobile Identity encoding of type %d not implemented\n", typeofidentity); + if (typeofidentity == FGS_MOBILE_IDENTITY_5G_GUTI) + decoded_rc = decode_guti_5gs_mobile_identity(&fgsmobileidentity->guti, buffer + decoded); if (decoded_rc < 0) { return decoded_rc; @@ -128,7 +124,7 @@ int decode_5gs_mobile_identity(FGSMobileIdentity *fgsmobileidentity, uint8_t iei return (decoded + decoded_rc); } -int encode_5gs_mobile_identity(FGSMobileIdentity *fgsmobileidentity, uint8_t iei, uint8_t *buffer, uint32_t len) +int encode_5gs_mobile_identity(const FGSMobileIdentity *fgsmobileidentity, uint8_t iei, uint8_t *buffer, uint32_t len) { // Return if buffer is shorter than min length if (len < MIN_LEN_FGS_MOBILE_ID_IE) @@ -146,18 +142,15 @@ int encode_5gs_mobile_identity(FGSMobileIdentity *fgsmobileidentity, uint8_t iei len -= encoded; if (fgsmobileidentity->guti.typeofidentity == FGS_MOBILE_IDENTITY_5G_GUTI) { - encoded_rc = encode_guti_5gs_mobile_identity(&fgsmobileidentity->guti, - buffer + encoded); + encoded_rc = encode_guti_5gs_mobile_identity(&fgsmobileidentity->guti, buffer + encoded); } if (fgsmobileidentity->suci.typeofidentity == FGS_MOBILE_IDENTITY_SUCI) { - encoded_rc = encode_suci_5gs_mobile_identity(&fgsmobileidentity->suci, - buffer + encoded); + encoded_rc = encode_suci_5gs_mobile_identity(&fgsmobileidentity->suci, buffer + encoded); } if (fgsmobileidentity->imeisv.typeofidentity == FGS_MOBILE_IDENTITY_IMEISV) { - encoded_rc = encode_imeisv_5gs_mobile_identity(&fgsmobileidentity->imeisv, - buffer + encoded); + encoded_rc = encode_imeisv_5gs_mobile_identity(&fgsmobileidentity->imeisv, buffer + encoded); } if (fgsmobileidentity->stmsi.typeofidentity == FGS_MOBILE_IDENTITY_5GS_TMSI) { @@ -168,7 +161,7 @@ int encode_5gs_mobile_identity(FGSMobileIdentity *fgsmobileidentity, uint8_t iei return encoded_rc; } - if(iei > 0){ + if (iei > 0) { uint16_t tmp = htons(encoded + encoded_rc - 3); memcpy(buffer + 1, &tmp, sizeof(tmp)); } else { @@ -192,7 +185,6 @@ static int decode_guti_5gs_mobile_identity(Guti5GSMobileIdentity_t *guti, const return (TLV_ENCODE_VALUE_DOESNT_MATCH); } - guti->oddeven = (*(buffer + decoded) >> 3) & 0x1; /* @@ -218,33 +210,27 @@ static int decode_guti_5gs_mobile_identity(Guti5GSMobileIdentity_t *guti, const guti->mncdigit1 = *(buffer + decoded) & 0xf; decoded++; - - guti->amfregionid = *(buffer+decoded); + guti->amfregionid = *(buffer + decoded); decoded++; IES_DECODE_U16(buffer, decoded, temp); - guti->amfsetid = temp>>3; - guti->amfpointer = temp&0x3f; + guti->amfsetid = (temp >> 6) & 0x3FF; + guti->amfpointer = temp & 0x3f; IES_DECODE_U32(buffer, decoded, guti->tmsi); return decoded; } - -static int encode_guti_5gs_mobile_identity(Guti5GSMobileIdentity_t *guti, uint8_t *buffer) +static int encode_guti_5gs_mobile_identity(const Guti5GSMobileIdentity_t *guti, uint8_t *buffer) { uint32_t encoded = 0; uint16_t temp; - *(buffer + encoded) = 0xf0 | ((guti->oddeven & 0x1) << 3) | - (guti->typeofidentity & 0x7); + *(buffer + encoded) = 0xf0 | ((guti->oddeven & 0x1) << 3) | (guti->typeofidentity & 0x7); encoded++; - *(buffer + encoded) = 0x00 | ((guti->mccdigit2 & 0xf) << 4) | - (guti->mccdigit1 & 0xf); + *(buffer + encoded) = 0x00 | ((guti->mccdigit2 & 0xf) << 4) | (guti->mccdigit1 & 0xf); encoded++; - *(buffer + encoded) = 0x00 | ((guti->mncdigit3 & 0xf) << 4) | - (guti->mccdigit3 & 0xf); + *(buffer + encoded) = 0x00 | ((guti->mncdigit3 & 0xf) << 4) | (guti->mccdigit3 & 0xf); encoded++; - *(buffer + encoded) = 0x00 | ((guti->mncdigit2 & 0xf) << 4) | - (guti->mncdigit1 & 0xf); + *(buffer + encoded) = 0x00 | ((guti->mncdigit2 & 0xf) << 4) | (guti->mncdigit1 & 0xf); encoded++; *(buffer + encoded) = guti->amfregionid; @@ -257,28 +243,22 @@ static int encode_guti_5gs_mobile_identity(Guti5GSMobileIdentity_t *guti, uint8_ return encoded; } - -static int encode_suci_5gs_mobile_identity(Suci5GSMobileIdentity_t *suci, uint8_t *buffer) +static int encode_suci_5gs_mobile_identity(const Suci5GSMobileIdentity_t *suci, uint8_t *buffer) { uint32_t encoded = 0; *(buffer + encoded) = (suci->supiformat << 4) | (suci->typeofidentity); encoded++; - *(buffer + encoded) = ((suci->mccdigit2 & 0xf) << 4) | - (suci->mccdigit1 & 0xf); + *(buffer + encoded) = ((suci->mccdigit2 & 0xf) << 4) | (suci->mccdigit1 & 0xf); encoded++; - *(buffer + encoded) = ((suci->mncdigit3 & 0xf) << 4) | - (suci->mccdigit3 & 0xf); + *(buffer + encoded) = ((suci->mncdigit3 & 0xf) << 4) | (suci->mccdigit3 & 0xf); encoded++; - *(buffer + encoded) = ((suci->mncdigit2 & 0xf) << 4) | - (suci->mncdigit1 & 0xf); + *(buffer + encoded) = ((suci->mncdigit2 & 0xf) << 4) | (suci->mncdigit1 & 0xf); encoded++; - *(buffer + encoded) = ((suci->routingindicatordigit2 & 0xf) << 4) | - (suci->routingindicatordigit1 & 0xf); + *(buffer + encoded) = ((suci->routingindicatordigit2 & 0xf) << 4) | (suci->routingindicatordigit1 & 0xf); encoded++; - *(buffer + encoded) = ((suci->routingindicatordigit4 & 0xf) << 4) | - (suci->routingindicatordigit3 & 0xf); + *(buffer + encoded) = ((suci->routingindicatordigit4 & 0xf) << 4) | (suci->routingindicatordigit3 & 0xf); encoded++; *(buffer + encoded) = 0x00 | (suci->protectionschemeId & 0xf); @@ -287,19 +267,19 @@ static int encode_suci_5gs_mobile_identity(Suci5GSMobileIdentity_t *suci, uint8_ *(buffer + encoded) = suci->homenetworkpki; encoded++; - char *ptr=suci->schemeoutput; - while ( ptr < suci->schemeoutput+strlen(suci->schemeoutput) ) { - buffer[encoded]=((*(ptr+1)-'0')<<4) | (*(ptr) -'0'); + const char *ptr = suci->schemeoutput; + while (ptr < suci->schemeoutput + strlen(suci->schemeoutput)) { + buffer[encoded] = ((*(ptr + 1) - '0') << 4) | (*(ptr) - '0'); encoded++; - ptr+=2; + ptr += 2; } - if (strlen(suci->schemeoutput)%2 == 1) - buffer[encoded++]=((*(ptr-1)-'0')) | 0xF0; + if (strlen(suci->schemeoutput) % 2 == 1) + buffer[encoded++] = ((*(ptr - 1) - '0')) | 0xF0; return encoded; } -static int encode_imeisv_5gs_mobile_identity(Imeisv5GSMobileIdentity_t *imeisv, uint8_t *buffer) +static int encode_imeisv_5gs_mobile_identity(const Imeisv5GSMobileIdentity_t *imeisv, uint8_t *buffer) { uint32_t encoded = 0; *(buffer + encoded) = 0x00 | (imeisv->digittac01 << 4) | (imeisv->oddeven << 3) | (imeisv->typeofidentity); @@ -310,17 +290,16 @@ static int encode_imeisv_5gs_mobile_identity(Imeisv5GSMobileIdentity_t *imeisv, encoded++; *(buffer + encoded) = 0x00 | (imeisv->digittac07 << 4) | (imeisv->digittac06); encoded++; - *(buffer + encoded) = 0x00 | (imeisv->digit09 << 4) | (imeisv->digittac08); + *(buffer + encoded) = 0x00 | (imeisv->digit09 << 4) | (imeisv->digittac08); encoded++; - *(buffer + encoded) = 0x00 | (imeisv->digit11 << 4) | (imeisv->digit10); + *(buffer + encoded) = 0x00 | (imeisv->digit11 << 4) | (imeisv->digit10); encoded++; - *(buffer + encoded) = 0x00 | (imeisv->digit13 << 4) | (imeisv->digit12); + *(buffer + encoded) = 0x00 | (imeisv->digit13 << 4) | (imeisv->digit12); encoded++; - *(buffer + encoded) = 0x00 | (imeisv->digitsv1 << 4) | (imeisv->digit14); + *(buffer + encoded) = 0x00 | (imeisv->digitsv1 << 4) | (imeisv->digit14); encoded++; - *(buffer + encoded) = 0x00 | (imeisv->spare << 4) | (imeisv->digitsv2); + *(buffer + encoded) = 0x00 | (imeisv->spare << 4) | (imeisv->digitsv2); encoded++; return encoded; } - diff --git a/openair3/NAS/COMMON/IES/FGSMobileIdentity.h b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSMobileIdentity.h similarity index 60% rename from openair3/NAS/COMMON/IES/FGSMobileIdentity.h rename to openair3/NAS/NR_UE/5GS/5GMM/IES/FGSMobileIdentity.h index e4747461e9..b7e66019cc 100644 --- a/openair3/NAS/COMMON/IES/FGSMobileIdentity.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSMobileIdentity.h @@ -27,7 +27,6 @@ * \version 0.1 */ - #include #include #include @@ -41,97 +40,96 @@ #define DIGIT1 0xF typedef struct { - uint8_t spare:5; - uint8_t typeofidentity:3; + uint8_t spare: 5; + uint8_t typeofidentity: 3; } NoIdentity5GSMobileIdentity_t; typedef struct { - uint8_t spare1:1; - uint8_t supiformat:3; - uint8_t spare2:1; - uint8_t typeofidentity:3; - uint8_t mccdigit2:4; - uint8_t mccdigit1:4; - uint8_t mncdigit3:4; - uint8_t mccdigit3:4; - uint8_t mncdigit2:4; - uint8_t mncdigit1:4; - uint8_t routingindicatordigit2:4; - uint8_t routingindicatordigit1:4; - uint8_t routingindicatordigit4:4; - uint8_t routingindicatordigit3:4; - uint8_t spare3:1; - uint8_t spare4:1; - uint8_t spare5:1; - uint8_t spare6:1; - uint8_t protectionschemeId:4; - uint8_t homenetworkpki; + uint8_t spare1: 1; + uint8_t supiformat: 3; + uint8_t spare2: 1; + uint8_t typeofidentity: 3; + uint8_t mccdigit2: 4; + uint8_t mccdigit1: 4; + uint8_t mncdigit3: 4; + uint8_t mccdigit3: 4; + uint8_t mncdigit2: 4; + uint8_t mncdigit1: 4; + uint8_t routingindicatordigit2: 4; + uint8_t routingindicatordigit1: 4; + uint8_t routingindicatordigit4: 4; + uint8_t routingindicatordigit3: 4; + uint8_t spare3: 1; + uint8_t spare4: 1; + uint8_t spare5: 1; + uint8_t spare6: 1; + uint8_t protectionschemeId: 4; + uint8_t homenetworkpki; char schemeoutput[32]; } Suci5GSMobileIdentity_t; typedef struct { - uint8_t spare:4; - uint8_t oddeven:1; - uint8_t typeofidentity:3; - uint8_t mccdigit2:4; - uint8_t mccdigit1:4; - uint8_t mncdigit3:4; - uint8_t mccdigit3:4; - uint8_t mncdigit2:4; - uint8_t mncdigit1:4; - uint8_t amfregionid; - uint16_t amfsetid:10; - uint16_t amfpointer:6; + uint8_t spare: 4; + uint8_t oddeven: 1; + uint8_t typeofidentity: 3; + uint8_t mccdigit2: 4; + uint8_t mccdigit1: 4; + uint8_t mncdigit3: 4; + uint8_t mccdigit3: 4; + uint8_t mncdigit2: 4; + uint8_t mncdigit1: 4; + uint8_t amfregionid; + uint16_t amfsetid: 10; + uint16_t amfpointer: 6; uint32_t tmsi; } Guti5GSMobileIdentity_t; - typedef struct { - uint8_t digit1:4; - uint8_t oddeven:1; - uint8_t typeofidentity:3; - uint8_t digitp1:4; - uint8_t digitp:4; + uint8_t digit1: 4; + uint8_t oddeven: 1; + uint8_t typeofidentity: 3; + uint8_t digitp1: 4; + uint8_t digitp: 4; } Imei5GSMobileIdentity_t; typedef struct { - uint8_t digittac01:4; - uint8_t oddeven:1; - uint8_t typeofidentity:3; - uint8_t digittac02:4; - uint8_t digittac03:4; - uint8_t digittac04:4; - uint8_t digittac05:4; - uint8_t digittac06:4; - uint8_t digittac07:4; - uint8_t digittac08:4; - uint8_t digit09:4; - uint8_t digit10:4; - uint8_t digit11:4; - uint8_t digit12:4; - uint8_t digit13:4; - uint8_t digit14:4; - uint8_t digitsv1:4; - uint8_t digitsv2:4; - uint8_t spare:4; + uint8_t digittac01: 4; + uint8_t oddeven: 1; + uint8_t typeofidentity: 3; + uint8_t digittac02: 4; + uint8_t digittac03: 4; + uint8_t digittac04: 4; + uint8_t digittac05: 4; + uint8_t digittac06: 4; + uint8_t digittac07: 4; + uint8_t digittac08: 4; + uint8_t digit09: 4; + uint8_t digit10: 4; + uint8_t digit11: 4; + uint8_t digit12: 4; + uint8_t digit13: 4; + uint8_t digit14: 4; + uint8_t digitsv1: 4; + uint8_t digitsv2: 4; + uint8_t spare: 4; } Imeisv5GSMobileIdentity_t; - typedef struct { - uint8_t digit1:4; - uint8_t spare:1; - uint8_t typeofidentity:3; - uint16_t amfsetid:10; - uint16_t amfpointer:6; + uint8_t digit1: 4; + uint8_t spare: 1; + uint8_t typeofidentity: 3; + uint16_t amfsetid: 10; + uint16_t amfpointer: 6; uint32_t tmsi; } Stmsi5GSMobileIdentity_t; typedef struct { - uint8_t spare:5; - uint8_t typeofidentity:3; - uint8_t macaddr; + uint8_t spare: 5; + uint8_t typeofidentity: 3; + uint8_t macaddr; } Macaddr5GSMobileIdentity_t; +// clang-format off typedef union FGSMobileIdentity_tag { #define FGS_MOBILE_IDENTITY_NOIDENTITY 0b000 #define FGS_MOBILE_IDENTITY_SUCI 0b001 @@ -148,13 +146,13 @@ typedef union FGSMobileIdentity_tag { Imeisv5GSMobileIdentity_t imeisv; Macaddr5GSMobileIdentity_t macaddress; } FGSMobileIdentity; +// clang-format on -int encode_5gs_mobile_identity(FGSMobileIdentity *fgsmobileidentity, uint8_t iei, uint8_t *buffer, uint32_t len); +int encode_5gs_mobile_identity(const FGSMobileIdentity *fgsmobileidentity, uint8_t iei, uint8_t *buffer, uint32_t len); int decode_5gs_mobile_identity(FGSMobileIdentity *fgsmobileidentity, uint8_t iei, const uint8_t *buffer, uint32_t len); -int encode_stmsi_5gs_mobile_identity(uint8_t *buffer, Stmsi5GSMobileIdentity_t *stmsi, uint32_t len); +int encode_stmsi_5gs_mobile_identity(uint8_t *buffer, const Stmsi5GSMobileIdentity_t *stmsi, uint32_t len); int decode_stmsi_5gs_mobile_identity(Stmsi5GSMobileIdentity_t *stmsi, const uint8_t *buffer, uint32_t len); #endif /* FGS MOBILE IDENTITY_H_ */ - diff --git a/openair3/NAS/COMMON/IES/FGSRegistrationResult.c b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSRegistrationResult.c similarity index 89% rename from openair3/NAS/COMMON/IES/FGSRegistrationResult.c rename to openair3/NAS/NR_UE/5GS/5GMM/IES/FGSRegistrationResult.c index e580b14409..739cee7973 100644 --- a/openair3/NAS/COMMON/IES/FGSRegistrationResult.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSRegistrationResult.c @@ -32,31 +32,27 @@ #include #include - #include "TLVEncoder.h" #include "TLVDecoder.h" #include "FGSRegistrationResult.h" - int decode_fgs_registration_result(FGSRegistrationResult *fgsregistrationresult, uint8_t iei, uint16_t value, uint32_t len) { int decoded = 0; uint16_t *buffer = &value; fgsregistrationresult->registrationresult = *buffer & 0x7; fgsregistrationresult->smsallowed = *buffer & 0x8; - decoded = decoded+2; + decoded = decoded + 2; return decoded; } -uint16_t encode_fgs_registration_result(FGSRegistrationResult *fgsregistrationresult) +uint16_t encode_fgs_registration_result(const FGSRegistrationResult *fgsregistrationresult) { uint16_t bufferReturn; uint16_t *buffer = &bufferReturn; uint8_t encoded = 0; - *(buffer + encoded) = 0x00 | (fgsregistrationresult->smsallowed & 0x8) | - (fgsregistrationresult->registrationresult & 0x7); - encoded= encoded+2; + *(buffer + encoded) = 0x00 | (fgsregistrationresult->smsallowed & 0x8) | (fgsregistrationresult->registrationresult & 0x7); + encoded = encoded + 2; return bufferReturn; } - diff --git a/openair3/NAS/COMMON/IES/FGSRegistrationResult.h b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSRegistrationResult.h similarity index 89% rename from openair3/NAS/COMMON/IES/FGSRegistrationResult.h rename to openair3/NAS/NR_UE/5GS/5GMM/IES/FGSRegistrationResult.h index 0a2dedc2e5..04f45417b8 100644 --- a/openair3/NAS/COMMON/IES/FGSRegistrationResult.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSRegistrationResult.h @@ -34,8 +34,6 @@ #include "OctetString.h" - - #ifndef FGS_REGISTRATION_RESULT_H_ #define FGS_REGISTRATION_RESULT_H_ #define FGS_REGISTRATION_RESULT_3GPP 0b001 @@ -43,17 +41,15 @@ #define FGS_REGISTRATION_RESULT_3GPP_AND_NON_3GPP 0b011 typedef struct { - uint8_t iei; - uint8_t resultlength; - uint8_t spare:4; - uint8_t smsallowed:1; - uint8_t registrationresult:3; + uint8_t iei; + uint8_t resultlength; + uint8_t spare: 4; + uint8_t smsallowed: 1; + uint8_t registrationresult: 3; } FGSRegistrationResult; - -uint16_t encode_fgs_registration_result(FGSRegistrationResult *fgsregistrationresult); +uint16_t encode_fgs_registration_result(const FGSRegistrationResult *fgsregistrationresult); int decode_fgs_registration_result(FGSRegistrationResult *fgsregistrationresult, uint8_t iei, uint16_t value, uint32_t len); #endif /* FGS REGISTRATION RESULT_H_*/ - diff --git a/openair3/NAS/COMMON/IES/FGSRegistrationType.c b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSRegistrationType.c similarity index 91% rename from openair3/NAS/COMMON/IES/FGSRegistrationType.c rename to openair3/NAS/NR_UE/5GS/5GMM/IES/FGSRegistrationType.c index 7f1c3ae667..81825f585a 100644 --- a/openair3/NAS/COMMON/IES/FGSRegistrationType.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSRegistrationType.c @@ -31,7 +31,6 @@ #include #include - #include "TLVEncoder.h" #include "TLVDecoder.h" #include "FGSRegistrationType.h" @@ -50,16 +49,14 @@ int decode_5gs_registration_type(FGSRegistrationType *fgsregistrationtype, uint8 return decoded; } -int encode_5gs_registration_type(FGSRegistrationType *fgsregistrationtype) +int encode_5gs_registration_type(const FGSRegistrationType *fgsregistrationtype) { uint8_t bufferReturn; uint8_t *buffer = &bufferReturn; uint8_t encoded = 0; uint8_t iei = 0; - *(buffer + encoded) = 0x00 | (iei & 0xf0) | 0x8| - (*fgsregistrationtype & 0x7); + *(buffer + encoded) = 0x00 | (iei & 0xf0) | 0x8 | (*fgsregistrationtype & 0x7); encoded++; return bufferReturn; } - diff --git a/openair3/NAS/COMMON/IES/FGSRegistrationType.h b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSRegistrationType.h similarity index 94% rename from openair3/NAS/COMMON/IES/FGSRegistrationType.h rename to openair3/NAS/NR_UE/5GS/5GMM/IES/FGSRegistrationType.h index a548d45d93..ea42ac160e 100644 --- a/openair3/NAS/COMMON/IES/FGSRegistrationType.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSRegistrationType.h @@ -40,16 +40,15 @@ typedef uint8_t FGSRegistrationType; - +// clang-format off #define INITIAL_REGISTRATION 0b001 #define MOBILITY_REGISTRATION_UPDATING 0b010 #define PERIODIC_REGISTRATION_UPDATING 0b011 #define EMERGENCY_REGISTRATION 0b100 +// clang-format on -int encode_5gs_registration_type(FGSRegistrationType *fgsregistrationtype); +int encode_5gs_registration_type(const FGSRegistrationType *fgsregistrationtype); int decode_5gs_registration_type(FGSRegistrationType *fgsregistrationtype, uint8_t iei, uint8_t value, uint32_t len); - #endif /* FGS_REGISTRATION_TYPE_H_*/ - diff --git a/openair3/NAS/COMMON/IES/NrUESecurityCapability.c b/openair3/NAS/NR_UE/5GS/5GMM/IES/NrUESecurityCapability.c similarity index 67% rename from openair3/NAS/COMMON/IES/NrUESecurityCapability.c rename to openair3/NAS/NR_UE/5GS/5GMM/IES/NrUESecurityCapability.c index 6c0ff7e7c7..5d2d7cc040 100644 --- a/openair3/NAS/COMMON/IES/NrUESecurityCapability.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/IES/NrUESecurityCapability.c @@ -27,37 +27,35 @@ * \version 0.1 */ - #include #include #include - #include "TLVEncoder.h" #include "TLVDecoder.h" #include "NrUESecurityCapability.h" - - -int encode_nrue_security_capability(NrUESecurityCapability *nruesecuritycapability, uint8_t iei, uint8_t *buffer, uint32_t len) +int encode_nrue_security_capability(const NrUESecurityCapability *nruesecuritycapability, + uint8_t iei, + uint8_t *buffer, + uint32_t len) { int encoded = 0; - if(iei){ + if (iei) { *buffer = nruesecuritycapability->iei; - encoded++; - *(buffer+encoded) = nruesecuritycapability->length; - encoded++; - *(buffer+encoded) = nruesecuritycapability->fg_EA; - encoded++; - *(buffer+encoded) = nruesecuritycapability->fg_IA; - encoded++; - *(buffer+encoded) = nruesecuritycapability->EEA; - encoded++; - *(buffer+encoded) = nruesecuritycapability->EIA; - encoded++; - if((nruesecuritycapability->length - 4) > 0) - encoded = encoded + nruesecuritycapability->length - 4; + encoded++; + *(buffer + encoded) = nruesecuritycapability->length; + encoded++; + *(buffer + encoded) = nruesecuritycapability->fg_EA; + encoded++; + *(buffer + encoded) = nruesecuritycapability->fg_IA; + encoded++; + *(buffer + encoded) = nruesecuritycapability->EEA; + encoded++; + *(buffer + encoded) = nruesecuritycapability->EIA; + encoded++; + if ((nruesecuritycapability->length - 4) > 0) + encoded = encoded + nruesecuritycapability->length - 4; } return encoded; } - diff --git a/openair3/NAS/COMMON/IES/NrUESecurityCapability.h b/openair3/NAS/NR_UE/5GS/5GMM/IES/NrUESecurityCapability.h similarity index 87% rename from openair3/NAS/COMMON/IES/NrUESecurityCapability.h rename to openair3/NAS/NR_UE/5GS/5GMM/IES/NrUESecurityCapability.h index 10aa0cf0ea..a8ee4391b3 100644 --- a/openair3/NAS/COMMON/IES/NrUESecurityCapability.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/IES/NrUESecurityCapability.h @@ -36,7 +36,6 @@ #ifndef NRUE_SECURITY_CAPABILITY_H_ #define NRUE_SECURITY_CAPABILITY_H_ - typedef struct { uint8_t iei; uint8_t length; @@ -46,8 +45,9 @@ typedef struct { uint8_t EIA; } NrUESecurityCapability; - -int encode_nrue_security_capability(NrUESecurityCapability *nruesecuritycapability, uint8_t iei, uint8_t *buffer, uint32_t len); +int encode_nrue_security_capability(const NrUESecurityCapability *nruesecuritycapability, + uint8_t iei, + uint8_t *buffer, + uint32_t len); #endif /* NRUE_SECURITY_CAPABILITY_H_ */ - diff --git a/openair3/NAS/COMMON/IES/SORTransparentContainer.c b/openair3/NAS/NR_UE/5GS/5GMM/IES/SORTransparentContainer.c similarity index 75% rename from openair3/NAS/COMMON/IES/SORTransparentContainer.c rename to openair3/NAS/NR_UE/5GS/5GMM/IES/SORTransparentContainer.c index 3ab2a14c3d..9a6af8517c 100644 --- a/openair3/NAS/COMMON/IES/SORTransparentContainer.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/IES/SORTransparentContainer.c @@ -30,7 +30,10 @@ //#define NAS_DEBUG 1 -int decode_sor_transparent_container(SORTransparentContainer *sortransparentcontainer, uint8_t iei, uint8_t *buffer, uint32_t len) +int decode_sor_transparent_container(SORTransparentContainer *sortransparentcontainer, + uint8_t iei, + const uint8_t *buffer, + uint32_t len) { int decoded = 0; int decode_result; @@ -47,27 +50,31 @@ int decode_sor_transparent_container(SORTransparentContainer *sortransparentcont CHECK_LENGTH_DECODER(len - decoded, ielen); - - if ((decode_result = decode_octet_string(&sortransparentcontainer->sortransparentcontainercontents, ielen, buffer + decoded, len - decoded)) < 0) { + if ((decode_result = + decode_octet_string(&sortransparentcontainer->sortransparentcontainercontents, ielen, buffer + decoded, len - decoded)) + < 0) { LOG_FUNC_RETURN(decode_result); } else { decoded += decode_result; } -#if defined (NAS_DEBUG) +#if defined(NAS_DEBUG) dump_sor_transparent_container_xml(sortransparentcontainer, iei); #endif LOG_FUNC_RETURN(decoded); } -int encode_sor_transparent_container(SORTransparentContainer *sortransparentcontainer, uint8_t iei, uint8_t *buffer, uint32_t len) +int encode_sor_transparent_container(const SORTransparentContainer *sortransparentcontainer, + uint8_t iei, + uint8_t *buffer, + uint32_t len) { uint8_t *lenPtr; uint32_t encoded = 0; int32_t encode_result; /* Checking IEI and pointer */ CHECK_PDU_POINTER_AND_LENGTH_ENCODER(buffer, SOR_TRANSPARENT_CONTAINER_MINIMUM_LENGTH, len); -#if defined (NAS_DEBUG) +#if defined(NAS_DEBUG) dump_sor_transparent_container_xml(sortransparentcontainer, iei); #endif @@ -76,11 +83,12 @@ int encode_sor_transparent_container(SORTransparentContainer *sortransparentcont encoded++; } - lenPtr = (buffer + encoded); + lenPtr = (buffer + encoded); - //encoded += 2; - //if ((encode_result = encode_octet_string(&sortransparentcontainer->sortransparentcontainercontents, buffer + sizeof(uint16_t), len - sizeof(uint16_t))) < 0) - if ((encode_result = encode_octet_string(&sortransparentcontainer->sortransparentcontainercontents, lenPtr + sizeof(uint16_t), len - sizeof(uint16_t))) < 0) + if ((encode_result = encode_octet_string(&sortransparentcontainer->sortransparentcontainercontents, + lenPtr + sizeof(uint16_t), + len - sizeof(uint16_t))) + < 0) return encode_result; else encoded += encode_result; @@ -100,4 +108,3 @@ void dump_sor_transparent_container_xml(SORTransparentContainer *sortransparentc printf("%s", dump_octet_string_xml(&sortransparentcontainer->sortransparentcontainercontents)); printf("\n"); } - diff --git a/openair3/NAS/COMMON/IES/SORTransparentContainer.h b/openair3/NAS/NR_UE/5GS/5GMM/IES/SORTransparentContainer.h similarity index 79% rename from openair3/NAS/COMMON/IES/SORTransparentContainer.h rename to openair3/NAS/NR_UE/5GS/5GMM/IES/SORTransparentContainer.h index 587419b1f9..7ed4e039ef 100644 --- a/openair3/NAS/COMMON/IES/SORTransparentContainer.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/IES/SORTransparentContainer.h @@ -35,11 +35,16 @@ typedef struct SORTransparentContainer_tag { OctetString sortransparentcontainercontents; } SORTransparentContainer; -int encode_sor_transparent_container(SORTransparentContainer *sortransparentcontainer, uint8_t iei, uint8_t *buffer, uint32_t len); +int encode_sor_transparent_container(const SORTransparentContainer *sortransparentcontainer, + uint8_t iei, + uint8_t *buffer, + uint32_t len); -int decode_sor_transparent_container(SORTransparentContainer *sortransparentcontainer, uint8_t iei, uint8_t *buffer, uint32_t len); +int decode_sor_transparent_container(SORTransparentContainer *sortransparentcontainer, + uint8_t iei, + const uint8_t *buffer, + uint32_t len); void dump_sor_transparent_container_xml(SORTransparentContainer *sortransparentcontainer, uint8_t iei); #endif /* ESM MESSAGE CONTAINER_H_ */ - diff --git a/openair3/NAS/NR_UE/5GS/5GMM/MSG/CMakeLists.txt b/openair3/NAS/NR_UE/5GS/5GMM/MSG/CMakeLists.txt new file mode 100644 index 0000000000..be84772da6 --- /dev/null +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/CMakeLists.txt @@ -0,0 +1,15 @@ +add_library(fgs_5gmm_lib OBJECT + fgs_service_request.c + RegistrationRequest.c + RegistrationAccept.c + FGSIdentityResponse.c + FGSAuthenticationResponse.c + FGSNASSecurityModeComplete.c + RegistrationComplete.c + FGSUplinkNasTransport.c + FGSDeregistrationRequestUEOriginating.c +) + +target_link_libraries(fgs_5gmm_lib PUBLIC fgs_5gmm_ies_lib) + +target_include_directories(fgs_5gmm_lib PRIVATE ../IES/ ../../) diff --git a/openair3/NAS/COMMON/EMM/MSG/FGSAuthenticationResponse.c b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSAuthenticationResponse.c similarity index 70% rename from openair3/NAS/COMMON/EMM/MSG/FGSAuthenticationResponse.c rename to openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSAuthenticationResponse.c index 5e1ff25151..319026f9ef 100644 --- a/openair3/NAS/COMMON/EMM/MSG/FGSAuthenticationResponse.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSAuthenticationResponse.c @@ -37,20 +37,21 @@ #include "FGSAuthenticationResponse.h" - -int encode_fgs_authentication_response(fgs_authentication_response_msg *authentication_response, uint8_t *buffer, uint32_t len) +int encode_fgs_authentication_response(const fgs_authentication_response_msg *authentication_response, + uint8_t *buffer, + uint32_t len) { int encoded = 0; int encode_result = 0; - - if ((encode_result = - encode_authentication_response_parameter(&authentication_response->authenticationresponseparameter, - AUTHENTICATION_RESPONSE_PARAMETER_IEI, buffer + encoded, len - encoded)) < 0) //Return in case of error + if ((encode_result = encode_authentication_response_parameter(&authentication_response->authenticationresponseparameter, + AUTHENTICATION_RESPONSE_PARAMETER_IEI, + buffer + encoded, + len - encoded)) + < 0) // Return in case of error return encode_result; else encoded += encode_result; return encoded; } - diff --git a/openair3/NAS/COMMON/EMM/MSG/FGSAuthenticationResponse.h b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSAuthenticationResponse.h similarity index 76% rename from openair3/NAS/COMMON/EMM/MSG/FGSAuthenticationResponse.h rename to openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSAuthenticationResponse.h index 0acee3382f..6c0f0eaa64 100644 --- a/openair3/NAS/COMMON/EMM/MSG/FGSAuthenticationResponse.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSAuthenticationResponse.h @@ -32,16 +32,14 @@ #include #include -#include "ExtendedProtocolDiscriminator.h" #include "SecurityHeaderType.h" -#include "SpareHalfOctet.h" #include "MessageType.h" #include "AuthenticationResponseParameter.h" #ifndef FGS_AUTHENTICATION_RESPONSE_H_ #define FGS_AUTHENTICATION_RESPONSE_H_ -#define AUTHENTICATION_RESPONSE_PARAMETER_IEI 0x2d +#define AUTHENTICATION_RESPONSE_PARAMETER_IEI 0x2d /* * Message name: Identity response @@ -52,15 +50,11 @@ typedef struct fgs_authentication_response_msg_tag { /* Mandatory fields */ - ExtendedProtocolDiscriminator protocoldiscriminator; - SecurityHeaderType securityheadertype:4; - SpareHalfOctet sparehalfoctet:4; - MessageType messagetype; - AuthenticationResponseParameter authenticationresponseparameter; + AuthenticationResponseParameter authenticationresponseparameter; } fgs_authentication_response_msg; -int encode_fgs_authentication_response(fgs_authentication_response_msg *authentication_response, uint8_t *buffer, uint32_t len); +int encode_fgs_authentication_response(const fgs_authentication_response_msg *authentication_response, + uint8_t *buffer, + uint32_t len); #endif /* ! defined(FGS_AUTHENTICATION_RESPONSE_H_) */ - - diff --git a/openair3/NAS/COMMON/EMM/MSG/FGSDeregistrationRequestUEOriginating.c b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSDeregistrationRequestUEOriginating.c similarity index 81% rename from openair3/NAS/COMMON/EMM/MSG/FGSDeregistrationRequestUEOriginating.c rename to openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSDeregistrationRequestUEOriginating.c index af8dfd8c20..dbe1a548fb 100644 --- a/openair3/NAS/COMMON/EMM/MSG/FGSDeregistrationRequestUEOriginating.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSDeregistrationRequestUEOriginating.c @@ -27,23 +27,18 @@ * \version 0.1 */ -#include -#include -#include +#include "FGSDeregistrationRequestUEOriginating.h" #include -#include "FGSDeregistrationRequestUEOriginating.h" -#include "NR_NAS_defs.h" +#define IEI_NULL 0x00 -int encode_fgs_deregistration_request_ue_originating(fgs_deregistration_request_ue_originating_msg *drr, +int encode_fgs_deregistration_request_ue_originating(const fgs_deregistration_request_ue_originating_msg *drr, uint8_t *buffer, uint32_t len) { int encoded = 0; - FGSDeregistrationType *dt = &drr->deregistrationtype; - *(buffer + encoded) = ((dt->switchoff & 0x1) << 7) - | ((dt->reregistration_required & 0x1) << 6) - | ((dt->access_type & 0x3) << 4); + const FGSDeregistrationType *dt = &drr->deregistrationtype; + *(buffer + encoded) = ((dt->switchoff & 0x1) << 7) | ((dt->reregistration_required & 0x1) << 6) | ((dt->access_type & 0x3) << 4); int encode_result; if ((encode_result = encode_nas_key_set_identifier(&drr->naskeysetidentifier, IEI_NULL)) < 0) diff --git a/openair3/NAS/COMMON/EMM/MSG/FGSDeregistrationRequestUEOriginating.h b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSDeregistrationRequestUEOriginating.h similarity index 83% rename from openair3/NAS/COMMON/EMM/MSG/FGSDeregistrationRequestUEOriginating.h rename to openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSDeregistrationRequestUEOriginating.h index 2bccd8a5bd..6374b55895 100644 --- a/openair3/NAS/COMMON/EMM/MSG/FGSDeregistrationRequestUEOriginating.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSDeregistrationRequestUEOriginating.h @@ -22,17 +22,12 @@ #ifndef FGS_DEREGISTRATION_REQUEST_UE_ORIGINATING_H_ #define FGS_DEREGISTRATION_REQUEST_UE_ORIGINATING_H_ -#include -#include #include - -#include "ExtendedProtocolDiscriminator.h" -#include "SecurityHeaderType.h" -#include "SpareHalfOctet.h" -#include "MessageType.h" #include "FGSDeregistrationType.h" -#include "NasKeySetIdentifier.h" #include "FGSMobileIdentity.h" +#include "MessageType.h" +#include "NasKeySetIdentifier.h" +#include "SecurityHeaderType.h" /* * Message name: De-registration request (UE originating de-registration) @@ -43,18 +38,13 @@ typedef struct fgs_deregistration_request_ue_originating_msg_tag { /* Mandatory fields */ - ExtendedProtocolDiscriminator protocoldiscriminator; - SecurityHeaderType securityheadertype: 4; - SpareHalfOctet sparehalfoctet: 4; - MessageType messagetype; FGSDeregistrationType deregistrationtype; NasKeySetIdentifier naskeysetidentifier; FGSMobileIdentity fgsmobileidentity; } fgs_deregistration_request_ue_originating_msg; -int encode_fgs_deregistration_request_ue_originating(fgs_deregistration_request_ue_originating_msg *registrationrequest, +int encode_fgs_deregistration_request_ue_originating(const fgs_deregistration_request_ue_originating_msg *registrationrequest, uint8_t *buffer, uint32_t len); #endif /* ! defined(REGISTRATION_REQUEST_H_) */ - diff --git a/openair3/NAS/COMMON/EMM/MSG/FGSIdentityResponse.c b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSIdentityResponse.c similarity index 78% rename from openair3/NAS/COMMON/EMM/MSG/FGSIdentityResponse.c rename to openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSIdentityResponse.c index 4f8f6dd321..f65279c355 100644 --- a/openair3/NAS/COMMON/EMM/MSG/FGSIdentityResponse.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSIdentityResponse.c @@ -28,29 +28,19 @@ \version 0.1 */ -#include -#include -#include +#include "FGSIdentityResponse.h" #include -#include "nas_log.h" - -#include "FGSIdentityResponse.h" - - -int encode_identiy_response(fgs_identiy_response_msg *fgs_identity_reps, uint8_t *buffer, uint32_t len) +int encode_fgmm_identity_response(uint8_t *buffer, const fgmm_identity_response_msg *fgs_identity_reps, uint32_t len) { int encoded = 0; int encode_result = 0; - if ((encode_result = - encode_5gs_mobile_identity(&fgs_identity_reps->fgsmobileidentity, 0, buffer + - encoded, len - encoded)) < 0) //Return in case of error + if ((encode_result = encode_5gs_mobile_identity(&fgs_identity_reps->fgsmobileidentity, 0, buffer + encoded, len - encoded)) + < 0) // Return in case of error return encode_result; else encoded += encode_result; return encoded; } - - diff --git a/openair3/NAS/COMMON/EMM/MSG/FGSIdentityResponse.h b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSIdentityResponse.h similarity index 74% rename from openair3/NAS/COMMON/EMM/MSG/FGSIdentityResponse.h rename to openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSIdentityResponse.h index 431293e03e..667cb80c59 100644 --- a/openair3/NAS/COMMON/EMM/MSG/FGSIdentityResponse.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSIdentityResponse.h @@ -28,15 +28,10 @@ \version 0.1 */ -#include -#include #include - -#include "ExtendedProtocolDiscriminator.h" -#include "SecurityHeaderType.h" -#include "SpareHalfOctet.h" #include "FGSMobileIdentity.h" #include "MessageType.h" +#include "SecurityHeaderType.h" #ifndef FGS_IDENTITY_RESPONSE_H_ #define FGS_IDENTITY_RESPONSE_H_ @@ -48,18 +43,11 @@ * Direction: UE to AMF */ -typedef struct fgs_identiy_response_msg_tag { +typedef struct fgmm_identity_response_msg_s { /* Mandatory fields */ - ExtendedProtocolDiscriminator protocoldiscriminator; - SecurityHeaderType securityheadertype:4; - SpareHalfOctet sparehalfoctet:4; - MessageType messagetype; - FGSMobileIdentity fgsmobileidentity; + FGSMobileIdentity fgsmobileidentity; +} fgmm_identity_response_msg; -} fgs_identiy_response_msg; - -int encode_identiy_response(fgs_identiy_response_msg *fgs_identity_reps, uint8_t *buffer, uint32_t len); +int encode_fgmm_identity_response(uint8_t *buffer, const fgmm_identity_response_msg *fgs_identity_reps, uint32_t len); #endif /* ! defined(FGS_IDENTITY_RESPONSE_H_) */ - - diff --git a/openair3/NAS/COMMON/EMM/MSG/FGSNASSecurityModeComplete.c b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSNASSecurityModeComplete.c similarity index 65% rename from openair3/NAS/COMMON/EMM/MSG/FGSNASSecurityModeComplete.c rename to openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSNASSecurityModeComplete.c index e0be56145f..f24dc50749 100644 --- a/openair3/NAS/COMMON/EMM/MSG/FGSNASSecurityModeComplete.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSNASSecurityModeComplete.c @@ -28,39 +28,32 @@ \version 0.1 */ -#include -#include -#include -#include - -#include "nas_log.h" - #include "FGSNASSecurityModeComplete.h" -#include "FGSMobileIdentity.h" +#include #include "FGCNasMessageContainer.h" +#include "FGSMobileIdentity.h" -int encode_fgs_security_mode_complete(fgs_security_mode_complete_msg *fgs_security_mode_comp, uint8_t *buffer, uint32_t len) +int encode_fgs_security_mode_complete(const fgs_security_mode_complete_msg *fgs_security_mode_comp, uint8_t *buffer, uint32_t len) { - int encoded = 0; - int encode_result = 0; + int encoded = 0; + int encode_result = 0; - if ((encode_result = - encode_5gs_mobile_identity(&fgs_security_mode_comp->fgsmobileidentity, 0x77, buffer + - encoded, len - encoded)) < 0) { //Return in case of error + if ((encode_result = + encode_5gs_mobile_identity(&fgs_security_mode_comp->fgsmobileidentity, 0x77, buffer + encoded, len - encoded)) + < 0) { // Return in case of error + return encode_result; + } else { + encoded += encode_result; + if ((encode_result = encode_fgc_nas_message_container(&fgs_security_mode_comp->fgsnasmessagecontainer, + 0x71, + buffer + encoded, + len - encoded)) + < 0) { return encode_result; } else { encoded += encode_result; - if ((encode_result = - encode_fgc_nas_message_container(&fgs_security_mode_comp->fgsnasmessagecontainer, 0x71, buffer + - encoded, len - encoded)) < 0) { - return encode_result; - } else { - encoded += encode_result; - } } + } - return encoded; + return encoded; } - - - diff --git a/openair3/NAS/COMMON/EMM/MSG/FGSNASSecurityModeComplete.h b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSNASSecurityModeComplete.h similarity index 74% rename from openair3/NAS/COMMON/EMM/MSG/FGSNASSecurityModeComplete.h rename to openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSNASSecurityModeComplete.h index 702dca3dc5..4c379dadee 100644 --- a/openair3/NAS/COMMON/EMM/MSG/FGSNASSecurityModeComplete.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSNASSecurityModeComplete.h @@ -28,16 +28,11 @@ \version 0.1 */ -#include -#include #include - -#include "ExtendedProtocolDiscriminator.h" -#include "SecurityHeaderType.h" -#include "SpareHalfOctet.h" +#include "FGCNasMessageContainer.h" #include "FGSMobileIdentity.h" #include "MessageType.h" -#include "FGCNasMessageContainer.h" +#include "SecurityHeaderType.h" #ifndef FGS_NAS_SECURITY_MODE_COMPLETE_H_ #define FGS_NAS_SECURITY_MODE_COMPLETE_H_ @@ -50,16 +45,11 @@ */ typedef struct fgs_security_mode_complete_msg_tag { - /* Mandatory fields */ - ExtendedProtocolDiscriminator protocoldiscriminator; - SecurityHeaderType securityheadertype:4; - SpareHalfOctet sparehalfoctet:4; - MessageType messagetype; - FGSMobileIdentity fgsmobileidentity; - FGCNasMessageContainer fgsnasmessagecontainer; + /* Mandatory fields */ + FGSMobileIdentity fgsmobileidentity; + FGCNasMessageContainer fgsnasmessagecontainer; } fgs_security_mode_complete_msg; -int encode_fgs_security_mode_complete(fgs_security_mode_complete_msg *fgs_security_mode_comp, uint8_t *buffer, uint32_t len); +int encode_fgs_security_mode_complete(const fgs_security_mode_complete_msg *fgs_security_mode_comp, uint8_t *buffer, uint32_t len); #endif /* ! defined(FGS_NAS_SECURITY_MODE_COMPLETE_H_) */ - diff --git a/openair3/NAS/COMMON/EMM/MSG/FGSUplinkNasTransport.c b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSUplinkNasTransport.c similarity index 62% rename from openair3/NAS/COMMON/EMM/MSG/FGSUplinkNasTransport.c rename to openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSUplinkNasTransport.c index 741ec095c3..6b1b748146 100644 --- a/openair3/NAS/COMMON/EMM/MSG/FGSUplinkNasTransport.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSUplinkNasTransport.c @@ -28,16 +28,13 @@ \version 0.1 */ -#include -#include -#include -#include -#include - #include "FGSUplinkNasTransport.h" +#include +#include +#include #include "TLVEncoder.h" -int encode_fgs_payload_container(FGSPayloadContainer *paycontainer, uint8_t iei, uint8_t *buffer, uint32_t len) +static int encode_fgs_payload_container(const FGSPayloadContainer *paycontainer, uint8_t iei, uint8_t *buffer, uint32_t len) { uint32_t encoded = 0; int encode_result; @@ -54,7 +51,7 @@ int encode_fgs_payload_container(FGSPayloadContainer *paycontainer, uint8_t iei, } else { encoded += encode_result; } - if(iei > 0){ + if (iei > 0) { uint16_t tmp = htons(encoded - 3); memcpy(buffer + 1, &tmp, sizeof(tmp)); } else { @@ -65,7 +62,7 @@ int encode_fgs_payload_container(FGSPayloadContainer *paycontainer, uint8_t iei, return encoded; } -int encode_nssai(OctetString *nssai, uint8_t iei, uint8_t *buffer) +static int encode_nssai(const OctetString *nssai, uint8_t iei, uint8_t *buffer) { uint32_t encoded = 0; int encode_result; @@ -78,7 +75,6 @@ int encode_nssai(OctetString *nssai, uint8_t iei, uint8_t *buffer) *(buffer + encoded) = nssai->length; encoded++; - if ((encode_result = encode_octet_string(nssai, buffer + encoded, nssai->length)) < 0) { return encode_result; } else { @@ -88,7 +84,7 @@ int encode_nssai(OctetString *nssai, uint8_t iei, uint8_t *buffer) return encoded; } -int encode_dnn(OctetString *dnn, uint8_t iei, uint8_t *buffer) +static int encode_dnn(const OctetString *dnn, uint8_t iei, uint8_t *buffer) { uint32_t encoded = 0; int encode_result; @@ -110,43 +106,42 @@ int encode_dnn(OctetString *dnn, uint8_t iei, uint8_t *buffer) return encoded; } -int encode_fgs_uplink_nas_transport(fgs_uplink_nas_transport_msg *fgs_up_nas_transport, uint8_t *buffer, uint32_t len) +int encode_fgs_uplink_nas_transport(const fgs_uplink_nas_transport_msg *fgs_up_nas_transport, uint8_t *buffer, uint32_t len) { - int encoded = 0; - int encode_result = 0; + int encoded = 0; + int encode_result = 0; - *(buffer + encoded) = (fgs_up_nas_transport->payloadcontainertype.iei << 4) | (fgs_up_nas_transport->payloadcontainertype.type &0xf); - encoded++; + *(buffer + encoded) = + (fgs_up_nas_transport->payloadcontainertype.iei << 4) | (fgs_up_nas_transport->payloadcontainertype.type & 0xf); + encoded++; - if ((encode_result = encode_fgs_payload_container(&fgs_up_nas_transport->fgspayloadcontainer, - 0, buffer +encoded, len - encoded)) < 0) { - return encode_result; - } else { - encoded += encode_result; - } + if ((encode_result = encode_fgs_payload_container(&fgs_up_nas_transport->fgspayloadcontainer, 0, buffer + encoded, len - encoded)) + < 0) { + return encode_result; + } else { + encoded += encode_result; + } - *(buffer + encoded) = 0x12; - encoded++; + *(buffer + encoded) = 0x12; + encoded++; - IES_ENCODE_U8(buffer, encoded, fgs_up_nas_transport->pdusessionid); + IES_ENCODE_U8(buffer, encoded, fgs_up_nas_transport->pdusessionid); - // set request type - *(buffer + encoded) = (0x8<<4)|(fgs_up_nas_transport->requesttype &0x7); - encoded++; + // set request type + *(buffer + encoded) = (0x8 << 4) | (fgs_up_nas_transport->requesttype & 0x7); + encoded++; - if ((encode_result = encode_nssai(&fgs_up_nas_transport->snssai, 0x22, buffer +encoded)) < 0) { - return encode_result; - } else { - encoded += encode_result; - } + if ((encode_result = encode_nssai(&fgs_up_nas_transport->snssai, 0x22, buffer + encoded)) < 0) { + return encode_result; + } else { + encoded += encode_result; + } - if ((encode_result = encode_dnn(&fgs_up_nas_transport->dnn, 0x25, buffer +encoded)) < 0) { - return encode_result; - } else { - encoded += encode_result; - } + if ((encode_result = encode_dnn(&fgs_up_nas_transport->dnn, 0x25, buffer + encoded)) < 0) { + return encode_result; + } else { + encoded += encode_result; + } - return encoded; + return encoded; } - - diff --git a/openair3/NAS/COMMON/EMM/MSG/FGSUplinkNasTransport.h b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSUplinkNasTransport.h similarity index 65% rename from openair3/NAS/COMMON/EMM/MSG/FGSUplinkNasTransport.h rename to openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSUplinkNasTransport.h index 5fabcea173..7b828a1ed3 100644 --- a/openair3/NAS/COMMON/EMM/MSG/FGSUplinkNasTransport.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSUplinkNasTransport.h @@ -28,14 +28,10 @@ \version 0.1 */ -#include -#include #include - -#include "ExtendedProtocolDiscriminator.h" -#include "SecurityHeaderType.h" -#include "SpareHalfOctet.h" #include "MessageType.h" +#include "OctetString.h" +#include "SecurityHeaderType.h" #ifndef FGS_UPLINK_NAS_TRANSPORT_H_ #define FGS_UPLINK_NAS_TRANSPORT_H_ @@ -47,31 +43,25 @@ * Direction: UE to network */ -typedef struct PayloadContainerType_tag{ - uint8_t iei:4; - uint8_t type:4; -}PayloadContainerType; +typedef struct PayloadContainerType_tag { + uint8_t iei: 4; + uint8_t type: 4; +} PayloadContainerType; typedef struct FGSPayloadContainer_tag { OctetString payloadcontainercontents; } FGSPayloadContainer; typedef struct fgs_uplink_nas_transport_msg_tag { - /* Mandatory fields */ - ExtendedProtocolDiscriminator protocoldiscriminator; - SecurityHeaderType securityheadertype:4; - SpareHalfOctet sparehalfoctet:4; - MessageType messagetype; - PayloadContainerType payloadcontainertype; - FGSPayloadContainer fgspayloadcontainer; - /* Optional fields */ - uint16_t pdusessionid; - uint8_t requesttype; - OctetString snssai; - OctetString dnn; + /* Mandatory fields */ + PayloadContainerType payloadcontainertype; + FGSPayloadContainer fgspayloadcontainer; + /* Optional fields */ + uint16_t pdusessionid; + uint8_t requesttype; + OctetString snssai; + OctetString dnn; } fgs_uplink_nas_transport_msg; -int encode_fgs_uplink_nas_transport(fgs_uplink_nas_transport_msg *fgs_security_mode_comp, uint8_t *buffer, uint32_t len); +int encode_fgs_uplink_nas_transport(const fgs_uplink_nas_transport_msg *fgs_security_mode_comp, uint8_t *buffer, uint32_t len); #endif /* ! defined(FGS_UPLINK_NAS_TRANSPORT_H_) */ - - diff --git a/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationAccept.c b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationAccept.c new file mode 100644 index 0000000000..d92244a15f --- /dev/null +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationAccept.c @@ -0,0 +1,165 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +/*! \file RegistrationAccept.c + +\brief 5GS registration accept procedures +\author Yoshio INOUE, Masayuki HARADA +\email: yoshio.inoue@fujitsu.com,masayuki.harada@fujitsu.com +\date 2020 +\version 0.1 +*/ + +#include +#include +#include +#include +#include "conversions.h" +#include "TLVEncoder.h" +#include "TLVDecoder.h" +#include "RegistrationAccept.h" +#include "assertions.h" +#include "fgs_nas_utils.h" + +#define IEI_5G_GUTI 0x77 + +/** + * @brief Allowed NSSAI from Registration Accept according to 3GPP TS 24.501 Table 8.2.7.1.1 + */ +static int decode_nssai_ie(nr_nas_msg_snssai_t *nssai, const uint8_t *buf) +{ + const int length = *buf; // Length of S-NSSAI IE contents (list of S-NSSAIs) + const uint32_t decoded = length + 1; // Length IE (1 octet) + buf++; + int nssai_cnt = 0; + const uint8_t *end = buf + length; + while (buf < end) { + nr_nas_msg_snssai_t *item = nssai + nssai_cnt; + item->sd = 0xffffff; + const int item_len = *buf++; // Length of S-NSSAI IE item + switch (item_len) { + case 1: + item->sst = *buf++; + nssai_cnt++; + break; + + case 2: + item->sst = *buf++; + item->hplmn_sst = *buf++; + nssai_cnt++; + break; + + case 4: + item->sst = *buf++; + item->sd = 0xffffff & ntoh_int24_buf(buf); + buf += 3; + nssai_cnt++; + break; + + case 5: + item->sst = *buf++; + item->sd = 0xffffff & ntoh_int24_buf(buf); + buf += 3; + item->hplmn_sst = *buf++; + nssai_cnt++; + break; + + case 8: + item->sst = *buf++; + item->sd = 0xffffff & ntoh_int24_buf(buf); + buf += 3; + item->hplmn_sst = *buf++; + item->hplmn_sd = 0xffffff & ntoh_int24_buf(buf); + buf += 3; + nssai_cnt++; + break; + + default: + PRINT_NAS_ERROR("Unknown length in Allowed S-NSSAI list item\n"); + break; + } + } + return decoded; +} + +int decode_registration_accept(registration_accept_msg *registration_accept, const uint8_t *buffer, uint32_t len) +{ + int dec = 0; + const uint8_t *end = buffer + len; + + /* Decoding mandatory fields */ + if ((dec = decode_fgs_registration_result(®istration_accept->fgsregistrationresult, 0, *buffer, len)) < 0) + return dec; + buffer += dec; + + if (buffer < end && *buffer == IEI_5G_GUTI) { + registration_accept->guti = calloc_or_fail(1, sizeof(*registration_accept->guti)); + if ((dec = decode_5gs_mobile_identity(registration_accept->guti, IEI_5G_GUTI, buffer, end - buffer)) < 0) { + PRINT_NAS_ERROR("Failed to decode 5GS Mobile Identity in Registration Accept\n"); + return -1; + } + buffer += dec; + } + + // Allowed NSSAI (O) + /* Optional Presence IEs */ + while (buffer < end) { + const int iei = *buffer++; + switch (iei) { + + case 0x15: // allowed NSSAI + dec = decode_nssai_ie(registration_accept->nas_allowed_nssai, buffer); + buffer += dec; + break; + + case 0x31: // configured NSSAI + dec = decode_nssai_ie(registration_accept->config_nssai, buffer); + buffer += dec; + break; + + default: + dec = *buffer++; // content length + 1 byte (Length IE) + buffer += dec; + break; + } + } + return len; +} + +int encode_registration_accept(const registration_accept_msg *registration_accept, uint8_t *buffer, uint32_t len) +{ + int encoded = 0; + + LOG_FUNC_IN; + + *(buffer + encoded) = encode_fgs_registration_result(®istration_accept->fgsregistrationresult); + encoded = encoded + 2; + + if (registration_accept->guti) { + int mi_enc = encode_5gs_mobile_identity(registration_accept->guti, 0x77, buffer + encoded, len - encoded); + if (mi_enc < 0) + return mi_enc; + encoded += mi_enc; + } + + // todo ,Encoding optional fields + LOG_FUNC_RETURN(encoded); +} diff --git a/openair3/NAS/COMMON/EMM/MSG/RegistrationAccept.h b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationAccept.h similarity index 80% rename from openair3/NAS/COMMON/EMM/MSG/RegistrationAccept.h rename to openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationAccept.h index 30c434c662..6abf1e70ca 100644 --- a/openair3/NAS/COMMON/EMM/MSG/RegistrationAccept.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationAccept.h @@ -32,10 +32,7 @@ #include #include - -#include "ExtendedProtocolDiscriminator.h" #include "SecurityHeaderType.h" -#include "SpareHalfOctet.h" #include "MessageType.h" #include "FGSRegistrationResult.h" #include "FGSMobileIdentity.h" @@ -43,6 +40,14 @@ #ifndef REGISTRATION_ACCEPT_H_ #define REGISTRATION_ACCEPT_H_ +// 9.11.3.37 of 3GPP TS 24.501 +typedef struct { + int sst; + int hplmn_sst; + int sd; + int hplmn_sd; +} nr_nas_msg_snssai_t; + /* * Message name: Registration accept * Description: The REGISTRATION ACCEPT message is sent by the AMF to the UE. See table 8.2.7.1.1. @@ -52,19 +57,17 @@ typedef struct registration_accept_msg_tag { /* Mandatory fields */ - ExtendedProtocolDiscriminator protocoldiscriminator; - SecurityHeaderType securityheadertype:4; - SpareHalfOctet sparehalfoctet:4; - MessageType messagetype; - FGSRegistrationResult fgsregistrationresult; - + FGSRegistrationResult fgsregistrationresult; /* Optional fields */ FGSMobileIdentity *guti; + // Allowed NSSAI (O) + nr_nas_msg_snssai_t nas_allowed_nssai[8]; + // Configured NSSAI (O) + nr_nas_msg_snssai_t config_nssai[8]; } registration_accept_msg; int decode_registration_accept(registration_accept_msg *registrationaccept, const uint8_t *buffer, uint32_t len); -int encode_registration_accept(registration_accept_msg *registrationaccept, uint8_t *buffer, uint32_t len); +int encode_registration_accept(const registration_accept_msg *registrationaccept, uint8_t *buffer, uint32_t len); #endif /* ! defined(REGISTRATION_ACCEPT_H_) */ - diff --git a/openair3/NAS/COMMON/EMM/MSG/RegistrationComplete.c b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationComplete.c similarity index 71% rename from openair3/NAS/COMMON/EMM/MSG/RegistrationComplete.c rename to openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationComplete.c index 668e665351..0ce14cdcd8 100644 --- a/openair3/NAS/COMMON/EMM/MSG/RegistrationComplete.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationComplete.c @@ -19,24 +19,19 @@ * contact@openairinterface.org */ -#include -#include -#include -#include - - -#include "TLVEncoder.h" -#include "TLVDecoder.h" #include "RegistrationComplete.h" +#include #include "SORTransparentContainer.h" -int decode_registration_complete(registration_complete_msg *registration_complete, uint8_t *buffer, uint32_t len) +int decode_registration_complete(registration_complete_msg *registration_complete, const uint8_t *buffer, uint32_t len) { uint32_t decoded = 0; int decoded_result = 0; /* Decoding mandatory fields */ - if ((decoded_result = decode_sor_transparent_container(®istration_complete->sortransparentcontainer, 0, buffer + decoded, len - decoded)) < 0) + if ((decoded_result = + decode_sor_transparent_container(registration_complete->sortransparentcontainer, 0, buffer + decoded, len - decoded)) + < 0) return decoded_result; else decoded += decoded_result; @@ -44,18 +39,20 @@ int decode_registration_complete(registration_complete_msg *registration_complet return decoded; } -int encode_registration_complete(registration_complete_msg *registration_complete, uint8_t *buffer, uint32_t len) +int encode_registration_complete(const registration_complete_msg *registration_complete, uint8_t *buffer, uint32_t len) { int encoded = 0; int encode_result = 0; + if (!registration_complete->sortransparentcontainer) + return encoded; + if ((encode_result = - encode_sor_transparent_container(®istration_complete->sortransparentcontainer, 0, - buffer + encoded, len - encoded)) < 0) //Return in case of error + encode_sor_transparent_container(registration_complete->sortransparentcontainer, 0, buffer + encoded, len - encoded)) + < 0) // Return in case of error return encode_result; else encoded += encode_result; return encoded; } - diff --git a/openair3/NAS/COMMON/EMM/MSG/RegistrationComplete.h b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationComplete.h similarity index 72% rename from openair3/NAS/COMMON/EMM/MSG/RegistrationComplete.h rename to openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationComplete.h index 0fbf2abde1..1c2141243a 100644 --- a/openair3/NAS/COMMON/EMM/MSG/RegistrationComplete.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationComplete.h @@ -28,35 +28,21 @@ \version 0.1 */ -#include -#include #include - -#include "ExtendedProtocolDiscriminator.h" -#include "SecurityHeaderType.h" -#include "SpareHalfOctet.h" #include "MessageType.h" #include "SORTransparentContainer.h" +#include "SecurityHeaderType.h" #ifndef REGISTRATION_COMPLETE_H_ #define REGISTRATION_COMPLETE_H_ - typedef struct registration_complete_msg_tag { - /* Mandatory fields */ - ExtendedProtocolDiscriminator protocoldiscriminator; - SecurityHeaderType securityheadertype:4; - SpareHalfOctet sparehalfoctet:4; - MessageType messagetype; - /* Optional fields */ - SORTransparentContainer sortransparentcontainer; + SORTransparentContainer *sortransparentcontainer; } registration_complete_msg; +int decode_registration_complete(registration_complete_msg *registrationcomplete, const uint8_t *buffer, uint32_t len); -int decode_registration_complete(registration_complete_msg *registrationcomplete, uint8_t *buffer, uint32_t len); - -int encode_registration_complete(registration_complete_msg *registrationcomplete, uint8_t *buffer, uint32_t len); +int encode_registration_complete(const registration_complete_msg *registrationcomplete, uint8_t *buffer, uint32_t len); #endif /* ! defined(REGISTRATION_COMPLETE_H_) */ - diff --git a/openair3/NAS/COMMON/EMM/MSG/RegistrationRequest.c b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationRequest.c similarity index 73% rename from openair3/NAS/COMMON/EMM/MSG/RegistrationRequest.c rename to openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationRequest.c index cf18e46ca2..8f6fea900e 100644 --- a/openair3/NAS/COMMON/EMM/MSG/RegistrationRequest.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationRequest.c @@ -27,28 +27,25 @@ * \version 0.1 */ -#include -#include -#include +#include "RegistrationRequest.h" #include - +#include "T.h" #include "nas_log.h" -#include "RegistrationRequest.h" -#include "NR_NAS_defs.h" +#define IEI_NULL 0x00 -int decode_registration_request(registration_request_msg *registration_request, uint8_t *buffer, uint32_t len) +int decode_registration_request(registration_request_msg *registration_request, const uint8_t *buffer, uint32_t len) { uint32_t decoded = 0; int decoded_result = 0; LOG_FUNC_IN; - LOG_TRACE(INFO, "EMM - registration_request len = %d", - len); + LOG_TRACE(INFO, "5GMM: Registration Request len = %d", len); /* Decoding mandatory fields */ - if ((decoded_result = decode_5gs_registration_type(®istration_request->fgsregistrationtype, 0, *(buffer + decoded) & 0x0f, len - decoded)) < 0) { - // return decoded_result; + if ((decoded_result = + decode_5gs_registration_type(®istration_request->fgsregistrationtype, 0, *(buffer + decoded) & 0x0f, len - decoded)) + < 0) { LOG_FUNC_RETURN(decoded_result); } @@ -60,19 +57,18 @@ int decode_registration_request(registration_request_msg *registration_request, decoded++; - if ((decoded_result = decode_5gs_mobile_identity(®istration_request->fgsmobileidentity, 0, buffer + decoded, len - decoded)) < 0) { - // return decoded_result; + if ((decoded_result = decode_5gs_mobile_identity(®istration_request->fgsmobileidentity, 0, buffer + decoded, len - decoded)) + < 0) { LOG_FUNC_RETURN(decoded_result); } else decoded += decoded_result; - // TODO, Decoding optional fields return decoded; } -int encode_registration_request(registration_request_msg *registration_request, uint8_t *buffer, uint32_t len) +int encode_registration_request(const registration_request_msg *registration_request, uint8_t *buffer, uint32_t len) { int encoded = 0; int encode_result = 0; @@ -81,9 +77,9 @@ int encode_registration_request(registration_request_msg *registration_request, | (encode_5gs_registration_type(®istration_request->fgsregistrationtype) & 0x0f); encoded++; - if ((encode_result = - encode_5gs_mobile_identity(®istration_request->fgsmobileidentity, 0, buffer + - encoded, len - encoded)) < 0) //Return in case of error + if ((encode_result = encode_5gs_mobile_identity(®istration_request->fgsmobileidentity, 0, buffer + encoded, len - encoded)) + < 0) + // Return in case of error return encode_result; else encoded += encode_result; @@ -91,8 +87,10 @@ int encode_registration_request(registration_request_msg *registration_request, if ((registration_request->presencemask & REGISTRATION_REQUEST_5GMM_CAPABILITY_PRESENT) == REGISTRATION_REQUEST_5GMM_CAPABILITY_PRESENT) { if ((encode_result = encode_5gmm_capability(®istration_request->fgmmcapability, - REGISTRATION_REQUEST_5GMM_CAPABILITY_IEI, buffer + encoded, len - - encoded)) < 0) + REGISTRATION_REQUEST_5GMM_CAPABILITY_IEI, + buffer + encoded, + len - encoded)) + < 0) // Return in case of error return encode_result; else @@ -102,16 +100,16 @@ int encode_registration_request(registration_request_msg *registration_request, if ((registration_request->presencemask & REGISTRATION_REQUEST_UE_SECURITY_CAPABILITY_PRESENT) == REGISTRATION_REQUEST_UE_SECURITY_CAPABILITY_PRESENT) { if ((encode_result = encode_nrue_security_capability(®istration_request->nruesecuritycapability, - REGISTRATION_REQUEST_UE_SECURITY_CAPABILITY_IEI, buffer + encoded, len - - encoded)) < 0) + REGISTRATION_REQUEST_UE_SECURITY_CAPABILITY_IEI, + buffer + encoded, + len - encoded)) + < 0) // Return in case of error return encode_result; else encoded += encode_result; } - // TODO, Encoding optional fields return encoded; } - diff --git a/openair3/NAS/COMMON/EMM/MSG/RegistrationRequest.h b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationRequest.h similarity index 54% rename from openair3/NAS/COMMON/EMM/MSG/RegistrationRequest.h rename to openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationRequest.h index ce534bfff9..686b0bc148 100644 --- a/openair3/NAS/COMMON/EMM/MSG/RegistrationRequest.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationRequest.h @@ -27,25 +27,19 @@ * \version 0.1 */ - -#include -#include #include - -#include "ExtendedProtocolDiscriminator.h" -#include "SecurityHeaderType.h" -#include "SpareHalfOctet.h" +#include "FGMMCapability.h" #include "FGSMobileIdentity.h" -#include "NasKeySetIdentifier.h" #include "FGSRegistrationType.h" #include "MessageType.h" -#include "FGMMCapability.h" +#include "NasKeySetIdentifier.h" #include "NrUESecurityCapability.h" +#include "SecurityHeaderType.h" #ifndef REGISTRATION_REQUEST_H_ #define REGISTRATION_REQUEST_H_ - +// clang-format off # define REGISTRATION_REQUEST_NON_CURRENT_NATIVE_NAS_KEYSET_PRESENT (1<<0) # define REGISTRATION_REQUEST_5GMM_CAPABILITY_PRESENT (1<<1) # define REGISTRATION_REQUEST_UE_SECURITY_CAPABILITY_PRESENT (1<<2) @@ -70,29 +64,30 @@ # define REGISTRATION_REQUEST_EPS_BEARER_CONTEXT_STATUS_PRESENT (1<<21) typedef enum registration_request_iei_tag { - REGISTRATION_REQUEST_NON_CURRENT_NATIVE_NAS_KEYSET_IEI = 0xC0, /* 0xC- = 192- */ - REGISTRATION_REQUEST_5GMM_CAPABILITY_IEI = 0x10, /* 0x10 = 16 */ - REGISTRATION_REQUEST_UE_SECURITY_CAPABILITY_IEI = 0x2E, /* 0x2E = 46 */ - REGISTRATION_REQUEST_REQUESTED_NSSAI_IEI = 0x2F, /* 0x2F = 47 */ - REGISTRATION_REQUEST_LAST_VISITED_REGISTERED_TAI_IEI = 0x52, /* 0x52 = 82 */ - REGISTRATION_REQUEST_S1_UE_NETWORK_CAPABILITY_IEI = 0x17, /* 0x17 = 23 */ - REGISTRATION_REQUEST_UPLINK_DATA_STATUS_IEI = 0x40, /* 0x40 = 64 */ - REGISTRATION_REQUEST_PDU_SESSION_STATUS_IEI = 0x50, /* 0x50 = 80 */ - REGISTRATION_REQUEST_MICO_INDICATION_IEI = 0xB0, /* 0xB- = 176- */ - REGISTRATION_REQUEST_UE_STATUS_IEI = 0x2B, /* 0x2B = 43 */ - REGISTRATION_REQUEST_ADDITIONAL_GUTI_IEI = 0x77, /* 0x77 = 119 */ - REGISTRATION_REQUEST_ALLOWED_PDU_SESSION_STATUS_IEI = 0x25, /* 0x25 = 37 */ - REGISTRATION_REQUEST_UE_USAGE_SETTING_IEI = 0x18, /* 0x18 = 24 */ - REGISTRATION_REQUEST_REQUESTED_DRX_PARAMETERS_IEI = 0x51, /* 0x51 = 81 */ - REGISTRATION_REQUEST_EPS_NAS_MESSAGE_CONTAINER_IEI = 0x70, /* 0x70 = 112 */ - REGISTRATION_REQUEST_LADN_INDICATION_IEI = 0x74, /* 0x74 = 116 */ - REGISTRATION_REQUEST_PAYLOAD_CONTAINER_TYPE_IEI = 0x80, /* 0x80 = 128 */ - REGISTRATION_REQUEST_PAYLOAD_CONTAINER_IEI = 0x7B, /* 0x7B = 123 */ - REGISTRATION_REQUEST_NETWORK_SLICING_INDICATION_IEI = 0x90, /* 0x90 = 144 */ - REGISTRATION_REQUEST_5GS_UPDATE_TYPE_IEI = 0x53, /* 0x53 = 83 */ - REGISTRATION_REQUEST_NAS_MESSAGE_CONTAINER_IEI = 0x71, /* 0x71 = 113 */ - REGISTRATION_REQUEST_EPS_BEARER_CONTEXT_STATUS_IEI = 0x60 /* 0x60 = 96 */ + REGISTRATION_REQUEST_NON_CURRENT_NATIVE_NAS_KEYSET_IEI = 0xC0, /* 0xC- = 192- */ + REGISTRATION_REQUEST_5GMM_CAPABILITY_IEI = 0x10, /* 0x10 = 16 */ + REGISTRATION_REQUEST_UE_SECURITY_CAPABILITY_IEI = 0x2E, /* 0x2E = 46 */ + REGISTRATION_REQUEST_REQUESTED_NSSAI_IEI = 0x2F, /* 0x2F = 47 */ + REGISTRATION_REQUEST_LAST_VISITED_REGISTERED_TAI_IEI = 0x52, /* 0x52 = 82 */ + REGISTRATION_REQUEST_S1_UE_NETWORK_CAPABILITY_IEI = 0x17, /* 0x17 = 23 */ + REGISTRATION_REQUEST_UPLINK_DATA_STATUS_IEI = 0x40, /* 0x40 = 64 */ + REGISTRATION_REQUEST_PDU_SESSION_STATUS_IEI = 0x50, /* 0x50 = 80 */ + REGISTRATION_REQUEST_MICO_INDICATION_IEI = 0xB0, /* 0xB- = 176- */ + REGISTRATION_REQUEST_UE_STATUS_IEI = 0x2B, /* 0x2B = 43 */ + REGISTRATION_REQUEST_ADDITIONAL_GUTI_IEI = 0x77, /* 0x77 = 119 */ + REGISTRATION_REQUEST_ALLOWED_PDU_SESSION_STATUS_IEI = 0x25, /* 0x25 = 37 */ + REGISTRATION_REQUEST_UE_USAGE_SETTING_IEI = 0x18, /* 0x18 = 24 */ + REGISTRATION_REQUEST_REQUESTED_DRX_PARAMETERS_IEI = 0x51, /* 0x51 = 81 */ + REGISTRATION_REQUEST_EPS_NAS_MESSAGE_CONTAINER_IEI = 0x70, /* 0x70 = 112 */ + REGISTRATION_REQUEST_LADN_INDICATION_IEI = 0x74, /* 0x74 = 116 */ + REGISTRATION_REQUEST_PAYLOAD_CONTAINER_TYPE_IEI = 0x80, /* 0x80 = 128 */ + REGISTRATION_REQUEST_PAYLOAD_CONTAINER_IEI = 0x7B, /* 0x7B = 123 */ + REGISTRATION_REQUEST_NETWORK_SLICING_INDICATION_IEI = 0x90, /* 0x90 = 144 */ + REGISTRATION_REQUEST_5GS_UPDATE_TYPE_IEI = 0x53, /* 0x53 = 83 */ + REGISTRATION_REQUEST_NAS_MESSAGE_CONTAINER_IEI = 0x71, /* 0x71 = 113 */ + REGISTRATION_REQUEST_EPS_BEARER_CONTEXT_STATUS_IEI = 0x60 /* 0x60 = 96 */ } registration_request_iei; +// clang-format on /* * Message name: Registration request @@ -103,23 +98,17 @@ typedef enum registration_request_iei_tag { typedef struct registration_request_msg_tag { /* Mandatory fields */ - ExtendedProtocolDiscriminator protocoldiscriminator; - SecurityHeaderType securityheadertype:4; - SpareHalfOctet sparehalfoctet:4; - MessageType messagetype; - FGSRegistrationType fgsregistrationtype; - NasKeySetIdentifier naskeysetidentifier; - FGSMobileIdentity fgsmobileidentity; - + FGSRegistrationType fgsregistrationtype; + NasKeySetIdentifier naskeysetidentifier; + FGSMobileIdentity fgsmobileidentity; /* Optional fields */ - uint32_t presencemask; - FGMMCapability fgmmcapability; - NrUESecurityCapability nruesecuritycapability; + uint32_t presencemask; + FGMMCapability fgmmcapability; + NrUESecurityCapability nruesecuritycapability; } registration_request_msg; -int decode_registration_request(registration_request_msg *registrationrequest, uint8_t *buffer, uint32_t len); +int decode_registration_request(registration_request_msg *registrationrequest, const uint8_t *buffer, uint32_t len); -int encode_registration_request(registration_request_msg *registrationrequest, uint8_t *buffer, uint32_t len); +int encode_registration_request(const registration_request_msg *registrationrequest, uint8_t *buffer, uint32_t len); #endif /* ! defined(REGISTRATION_REQUEST_H_) */ - diff --git a/openair3/NAS/COMMON/EMM/MSG/fgs_service_request.c b/openair3/NAS/NR_UE/5GS/5GMM/MSG/fgs_service_request.c similarity index 95% rename from openair3/NAS/COMMON/EMM/MSG/fgs_service_request.c rename to openair3/NAS/NR_UE/5GS/5GMM/MSG/fgs_service_request.c index 85e67498a5..4603db55c5 100644 --- a/openair3/NAS/COMMON/EMM/MSG/fgs_service_request.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/fgs_service_request.c @@ -30,15 +30,15 @@ #include "FGSMobileIdentity.h" #include "NasKeySetIdentifier.h" #include "ServiceType.h" -#include "NR_NAS_defs.h" #define LEN_FGS_MOBILE_ID_CONTENTS_SIZE 2 // octets #define MIN_LEN_FGS_SERVICE_REQUEST 10 // octets +#define IEI_NULL 0x00 /** * @brief Encode 5GMM NAS Service Request message (8.2.16 of 3GPP TS 24.501) */ -int encode_fgs_service_request(uint8_t *buffer, fgs_service_request_msg_t *service_request, uint32_t len) +int encode_fgs_service_request(uint8_t *buffer, const fgs_service_request_msg_t *service_request, uint32_t len) { // Return if buffer is shorter than min length if (len < MIN_LEN_FGS_SERVICE_REQUEST) diff --git a/openair3/NAS/COMMON/EMM/MSG/fgs_service_request.h b/openair3/NAS/NR_UE/5GS/5GMM/MSG/fgs_service_request.h similarity index 91% rename from openair3/NAS/COMMON/EMM/MSG/fgs_service_request.h rename to openair3/NAS/NR_UE/5GS/5GMM/MSG/fgs_service_request.h index eecd1ee34a..82a721d52a 100644 --- a/openair3/NAS/COMMON/EMM/MSG/fgs_service_request.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/fgs_service_request.h @@ -27,11 +27,8 @@ #include "SecurityHeaderType.h" #include "NasKeySetIdentifier.h" #include "ServiceType.h" -#include "ExtendedProtocolDiscriminator.h" #include "FGCNasMessageContainer.h" -//#include "PDUSessionStatus.h" #include "MessageType.h" -#include "SpareHalfOctet.h" #include "FGSMobileIdentity.h" #ifndef FGS_SERVICE_REQUEST_H_ @@ -56,7 +53,7 @@ typedef struct { FGCNasMessageContainer *fgsnasmessagecontainer; } fgs_service_request_msg_t; -int encode_fgs_service_request(uint8_t *buffer, fgs_service_request_msg_t *servicerequest, uint32_t len); +int encode_fgs_service_request(uint8_t *buffer, const fgs_service_request_msg_t *servicerequest, uint32_t len); int decode_fgs_service_request(fgs_service_request_msg_t *sr, const uint8_t *buffer, uint32_t len); #endif /* ! defined(FGS_SERVICE_REQUEST_H_) */ diff --git a/openair3/NAS/NR_UE/5GS/5GSM/MSG/CMakeLists.txt b/openair3/NAS/NR_UE/5GS/5GSM/MSG/CMakeLists.txt new file mode 100644 index 0000000000..1630a48222 --- /dev/null +++ b/openair3/NAS/NR_UE/5GS/5GSM/MSG/CMakeLists.txt @@ -0,0 +1,6 @@ +add_library(fgs_5gsm_lib OBJECT PduSessionEstablishRequest.c + PduSessionEstablishmentAccept.c) + +target_link_libraries(fgs_5gsm_lib PUBLIC nas_common_ies_lib) + +target_include_directories(fgs_5gsm_lib PUBLIC . ../../) diff --git a/openair3/NAS/COMMON/ESM/MSG/PduSessionEstablishRequest.c b/openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishRequest.c similarity index 95% rename from openair3/NAS/COMMON/ESM/MSG/PduSessionEstablishRequest.c rename to openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishRequest.c index 1c9198b720..6c4592e2e2 100644 --- a/openair3/NAS/COMMON/ESM/MSG/PduSessionEstablishRequest.c +++ b/openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishRequest.c @@ -28,22 +28,14 @@ \version 0.1 */ -#include -#include -#include -#include - - -#include "TLVEncoder.h" -#include "TLVDecoder.h" #include "PduSessionEstablishRequest.h" - +#include +#include "TLVEncoder.h" int encode_pdu_session_establishment_request(pdu_session_establishment_request_msg *pdusessionestablishrequest, uint8_t *buffer) { int encoded = 0; - *(buffer + encoded) = pdusessionestablishrequest->protocoldiscriminator; encoded++; *(buffer + encoded) = pdusessionestablishrequest->pdusessionid; @@ -59,5 +51,3 @@ int encode_pdu_session_establishment_request(pdu_session_establishment_request_m return encoded; } - - diff --git a/openair3/NAS/COMMON/ESM/MSG/PduSessionEstablishRequest.h b/openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishRequest.h similarity index 75% rename from openair3/NAS/COMMON/ESM/MSG/PduSessionEstablishRequest.h rename to openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishRequest.h index e2742ebc38..3d61491968 100644 --- a/openair3/NAS/COMMON/ESM/MSG/PduSessionEstablishRequest.h +++ b/openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishRequest.h @@ -31,35 +31,28 @@ #include #include #include - -#include "ExtendedProtocolDiscriminator.h" #include "MessageType.h" #ifndef PDU_SESSION_ESTABLISHMENT_REQUEST_H_ #define PDU_SESSION_ESTABLISHMENT_REQUEST_H_ - /* * Message name: pdu session establishment request - * Description: The PDU SESSION ESTABLISHMENT REQUEST message is sent by the UE to the SMF to initiate establishment of a PDU session. See table 8.3.1.1.1. - * Significance: dual - * Direction: UE to network + * Description: The PDU SESSION ESTABLISHMENT REQUEST message is sent by the UE to the SMF to initiate establishment of a PDU + * session. See table 8.3.1.1.1. Significance: dual Direction: UE to network */ typedef struct pdu_session_establishment_request_msg_tag { - /* Mandatory fields */ - ExtendedProtocolDiscriminator protocoldiscriminator; - uint8_t pdusessionid; - uint8_t pti; - MessageType pdusessionestblishmsgtype; - uint16_t maxdatarate; - uint8_t pdusessiontype; - /* Optional fields */ + /* Mandatory fields */ + uint8_t protocoldiscriminator; + uint8_t pdusessionid; + uint8_t pti; + MessageType pdusessionestblishmsgtype; + uint16_t maxdatarate; + uint8_t pdusessiontype; + /* Optional fields */ } pdu_session_establishment_request_msg; - int encode_pdu_session_establishment_request(pdu_session_establishment_request_msg *pdusessionestablishrequest, uint8_t *buffer); #endif /* ! defined(PDU_SESSION_ESTABLISHMENT_REQUEST_H_) */ - - diff --git a/openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishmentAccept.c b/openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishmentAccept.c new file mode 100644 index 0000000000..50b66845c6 --- /dev/null +++ b/openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishmentAccept.c @@ -0,0 +1,215 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +#include +#include +#include "PduSessionEstablishmentAccept.h" +#include "common/utils/LOG/log.h" +#include "common/utils/tun_if.h" +#include "fgs_nas_utils.h" + +/** + * @brief Returns the size of the single QoS rule IE + */ +static uint8_t get_len_qos_rule(qos_rule_t *rule) +{ + return rule->length + sizeof(rule->id) + sizeof(rule->length); +} + +/** + * @brief Decode QoS Rule (9.11.4.13 of 3GPP TS 24.501) + */ +static qos_rule_t decode_qos_rule(uint8_t *buf) +{ + qos_rule_t qos_rule = {0}; + // octet 4 + qos_rule.id = *buf++; + // octet 5 - 6 + GET_SHORT(buf, qos_rule.length); + buf += sizeof(qos_rule.length); + // octet 7 + qos_rule.oc = (*(buf)&0xE0) >> 5; + qos_rule.dqr = (*(buf)&0x10) >> 4; + qos_rule.nb_pf = *buf++ & 0x0F; + // octet 8 - m + for (int i = 0; i < qos_rule.nb_pf; i++) { + packet_filter_t pf; + if (qos_rule.oc == ROC_CREATE_NEW_QOS_RULE || qos_rule.oc == ROC_MODIFY_QOS_RULE_ADD_PF + || qos_rule.oc == ROC_MODIFY_QOS_RULE_REPLACE_PF) { + pf.pf_type.type_1.pf_dir = (*buf & 0x30) >> 4; + pf.pf_type.type_1.pf_id = *buf++ & 0x0F; + pf.pf_type.type_1.length = *buf++; + buf += pf.pf_type.type_1.length; // skip PF content + } else if (qos_rule.oc == ROC_MODIFY_QOS_RULE_DELETE_PF) { + pf.pf_type.type_2.pf_id = *buf++; + } + } + // octet m + 1 + qos_rule.precendence = *buf++; + // octet m + 2 + qos_rule.qfi = *buf++ & 0x3F; + return qos_rule; +} + +/** + * @brief PDU session establishment accept (8.3.2 of 3GPP TS 24.501) + * network to UE + */ +int decode_pdu_session_establishment_accept_msg(pdu_session_establishment_accept_msg_t *psea_msg, uint8_t *buffer, uint32_t msg_length) +{ + uint8_t *curPtr = buffer; + + /* Mandatory PDU Session Establishment Accept IEs */ + // PDU Session Type (half octet) + psea_msg->pdu_type = *curPtr & 0x0f; + // SSC Mode (half octet) + psea_msg->ssc_mode = (*curPtr++ & 0xf0) >> 4; + // Authorized QoS Rules + auth_qos_rule_t *qos_rules = &psea_msg->qos_rules; + // Length of the rule IEs (2 octets) + GET_SHORT(curPtr, qos_rules->length); + curPtr += sizeof(qos_rules->length); + /* Decode rule IEs as long as the total length + of all IEs (qos_rules->length) is not reached */ + uint16_t rules_tot_len = 0; + while (rules_tot_len < qos_rules->length) + { + qos_rules->rule[0] = decode_qos_rule(curPtr); + rules_tot_len += get_len_qos_rule(&qos_rules->rule[0]); + curPtr += rules_tot_len; + } + // Session-AMBR (M) + psea_msg->sess_ambr.length = *curPtr++; + curPtr += psea_msg->sess_ambr.length; // skip content + + uint8_t *resPtr = curPtr; + + /* Optional Presence IEs */ + while (curPtr < buffer + msg_length) { + uint8_t psea_iei = *curPtr++; + LOG_T(NAS, "PDU SESSION ESTABLISHMENT ACCEPT - Received %s IEI\n", iei_text_desc[psea_iei].text); + switch (psea_iei) { + case IEI_5GSM_CAUSE: /* Ommited */ + curPtr++; + break; + + case IEI_PDU_ADDRESS: + psea_msg->pdu_addr_ie.pdu_length = *curPtr++; + + /* Octet 3 */ + // PDU type (3 bits) + psea_msg->pdu_addr_ie.pdu_type = *curPtr & 0x07; + // SMF's IPv6 link local address (1 bit) + uint8_t si6lla = (*curPtr >> 3) & 0x01; + if (si6lla) + LOG_E(NAS, "SMF's IPv6 link local address is not handled\n"); + curPtr++; + + /* Octet 4 to n */ + // PDU address information + uint8_t *addr = psea_msg->pdu_addr_ie.pdu_addr_oct; + if (psea_msg->pdu_addr_ie.pdu_type == PDU_SESSION_TYPE_IPV4) { + for (int i = 0; i < IPv4_ADDRESS_LENGTH; ++i) + addr[i] = *curPtr++; + LOG_I(NAS, "Received PDU Session Establishment Accept, UE IPv4: %u.%u.%u.%u\n", addr[0], addr[1], addr[2], addr[3]); + } else if (psea_msg->pdu_addr_ie.pdu_type == PDU_SESSION_TYPE_IPV6) { + for (int i = 0; i < IPv6_INTERFACE_ID_LENGTH; ++i) + addr[i] = *curPtr++; + LOG_I(NAS, "Received PDU Session Establishment Accept, UE IPv6: %u.%u.%u.%u.%u.%u.%u.%u\n", + addr[0], addr[1], addr[2], addr[3], addr[4], addr[5], addr[6], addr[7]); + } else if (psea_msg->pdu_addr_ie.pdu_type == PDU_SESSION_TYPE_IPV4V6) { + // 24.501 Sec 9.11.4.10: "If the PDU session type value indicates + // IPv4v6, the PDU address information in octet 4 to octet 11 + // contains an interface identifier for the IPv6 link local address + // and in octet 12 to octet 15 contains an IPv4 address." + for (int i = 0; i < IPv4_ADDRESS_LENGTH + IPv6_INTERFACE_ID_LENGTH; ++i) + addr[i] = *curPtr++; + LOG_I(NAS, "Received PDU Session Establishment Accept, UE IPv4v6: %u.%u.%u.%u/%u.%u.%u.%u.%u.%u.%u.%u\n", + addr[0], addr[1], addr[2], addr[3], + addr[4], addr[5], addr[6], addr[7], addr[8], addr[9], addr[10], addr[11]); + } else { + LOG_E(NAS, "unknown/unhandled PDU session establishment accept PDU type %d\n", psea_msg->pdu_addr_ie.pdu_type); + curPtr += psea_msg->pdu_addr_ie.pdu_length; + } + break; + + case IEI_RQ_TIMER_VALUE: /* Ommited */ + curPtr++; /* TS 24.008 10.5.7.3 */ + break; + + case IEI_SNSSAI: { + uint8_t snssai_length = *curPtr; + curPtr += (snssai_length + sizeof(snssai_length)); + break; + } + + case IEI_ALWAYSON_PDU: /* Ommited */ + curPtr++; + break; + + case IEI_MAPPED_EPS: { + uint16_t mapped_eps_length = 0; + GET_SHORT(curPtr, mapped_eps_length); + curPtr += mapped_eps_length; + break; + } + + case IEI_EAP_MSG: { + uint16_t eap_length = 0; + GET_SHORT(curPtr, eap_length); + curPtr += (eap_length + sizeof(eap_length)); + break; + } + + case IEI_AUTH_QOS_DESC: { + GET_SHORT(curPtr, psea_msg->qos_fd_ie.length); + curPtr += (psea_msg->qos_fd_ie.length + sizeof(psea_msg->qos_fd_ie.length)); + break; + } + + case IEI_EXT_CONF_OPT: { + GET_SHORT(curPtr, psea_msg->ext_pp_ie.length); + curPtr += (psea_msg->ext_pp_ie.length + sizeof(psea_msg->ext_pp_ie.length)); + break; + } + + case IEI_DNN: { + psea_msg->dnn_ie.dnn_length = *curPtr++; + char apn[APN_MAX_LEN]; + + if (psea_msg->dnn_ie.dnn_length <= APN_MAX_LEN && psea_msg->dnn_ie.dnn_length >= APN_MIN_LEN) { + memcpy(apn, curPtr, psea_msg->dnn_ie.dnn_length); + LOG_T(NAS, "PDU SESSION ESTABLISHMENT ACCEPT - APN: %s\n", apn); + } else + LOG_E(NAS, "PDU SESSION ESTABLISHMENT ACCEPT - DNN IE has invalid length\n"); + resPtr = curPtr; + curPtr = buffer + msg_length; // we force stop processing + break; + } + + default: + PRINT_NAS_ERROR("Unknown IEI %d\n", psea_iei); + curPtr = buffer + msg_length; // we force stop processing + break; + } + } + return resPtr - buffer; +} diff --git a/openair3/NAS/COMMON/ESM/MSG/PduSessionEstablishmentAccept.h b/openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishmentAccept.h similarity index 54% rename from openair3/NAS/COMMON/ESM/MSG/PduSessionEstablishmentAccept.h rename to openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishmentAccept.h index c283079998..80694814b4 100644 --- a/openair3/NAS/COMMON/ESM/MSG/PduSessionEstablishmentAccept.h +++ b/openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishmentAccept.h @@ -23,31 +23,39 @@ #define PDU_SESSION_ESTABLISHMENT_ACCEPT_H_ #include +#include +#include "fgs_nas_utils.h" /* PDU Session Establish Accept Optional IE Identifiers - TS 24.501 Table 8.3.2.1.1 */ -#define IEI_5GSM_CAUSE 0x59 /* 5GSM cause 9.11.4.2 */ -#define IEI_PDU_ADDRESS 0x29 /* PDU address 9.11.4.10 */ -#define IEI_RQ_TIMER_VALUE 0x56 /* GPRS timer 9.11.2.3 */ -#define IEI_SNSSAI 0x22 /* S-NSSAI 9.11.2.8 */ -#define IEI_ALWAYSON_PDU 0x80 /* Always-on PDU session indication 9.11.4.3 */ -#define IEI_MAPPED_EPS 0x75 /* Mapped EPS bearer contexts 9.11.4.8 */ -#define IEI_EAP_MSG 0x78 /* EAP message 9.11.2.2 */ -#define IEI_AUTH_QOS_DESC 0x79 /* QoS flow descriptions 9.11.4.12 */ -#define IEI_EXT_CONF_OPT 0x7b /* Extended protocol configuration options 9.11.4.6 */ -#define IEI_DNN 0x25 /* DNN 9.11.2.1B */ +#define FOREACH_IEI(IEI_DEF) \ + IEI_DEF(IEI_5GSM_CAUSE, 0x59) /* 5GSM cause 9.11.4.2 */ \ + IEI_DEF(IEI_PDU_ADDRESS, 0x29) /* PDU address 9.11.4.10 */ \ + IEI_DEF(IEI_RQ_TIMER_VALUE, 0x56) /* GPRS timer 9.11.2.3 */ \ + IEI_DEF(IEI_SNSSAI, 0x22) /* S-NSSAI 9.11.2.8 */ \ + IEI_DEF(IEI_ALWAYSON_PDU, 0x80) /* Always-on PDU session indication 9.11.4.3 */ \ + IEI_DEF(IEI_MAPPED_EPS, 0x75) /* Mapped EPS bearer contexts 9.11.4.8 */ \ + IEI_DEF(IEI_EAP_MSG, 0x78) /* EAP message 9.11.2.2 */ \ + IEI_DEF(IEI_AUTH_QOS_DESC, 0x79) /* QoS flow descriptions 9.11.4.12 */ \ + IEI_DEF(IEI_EXT_CONF_OPT, 0x7b) /* Extended protocol configuration options 9.11.4.6 */ \ + IEI_DEF(IEI_DNN, 0x25) /* DNN 9.11.2.1B */ + +static const text_info_t iei_text_desc[] = {FOREACH_IEI(TO_TEXT)}; + +typedef enum { FOREACH_IEI(TO_ENUM) } pduSessionEstablishment_IEI_t; /* PDU Session type value - TS 24.501 Table 9.11.4.10.1*/ -#define PDU_SESSION_TYPE_IPV4 0b001 -#define PDU_SESSION_TYPE_IPV6 0b010 +#define PDU_SESSION_TYPE_IPV4 0b001 +#define PDU_SESSION_TYPE_IPV6 0b010 #define PDU_SESSION_TYPE_IPV4V6 0b011 -#define IPv4_ADDRESS_LENGTH 4 // length of the IPv4 address associated with a PDU session +#define IPv4_ADDRESS_LENGTH 4 // length of the IPv4 address associated with a PDU session #define IPv6_INTERFACE_ID_LENGTH 8 // interface identifier for the IPv6 link local address #define SMF_IPv6_LLA_LENGTH 16 /* Rule operation codes - TS 24.501 Table 9.11.4.13.1 */ +// clang-format off #define ROC_RESERVED_0 0b000 /* Reserved */ #define ROC_CREATE_NEW_QOS_RULE 0b001 /* Create new QoS rule */ #define ROC_DELETE_QOS_RULE 0b010 /* Delete existing QoS rule */ @@ -56,13 +64,14 @@ #define ROC_MODIFY_QOS_RULE_DELETE_PF 0b101 /* Modify existing QoS rule and delete packet filters */ #define ROC_MODIFY_QOS_RULE_WITHOUT_PF 0b110 /* Modify existing QoS rule without modifying packet filters */ #define ROC_RESERVED_1 0b111 /* Reserved */ +// clang-format on -/* DNN - APN +/* DNN - APN * TS 23.003 9.1 * The APN is composed of two parts, the APN Network Identifier (9.1.1) & The APN Operator Identifier (9.1.2). - * + * * The DNN information element has a length in the range of 3 to 102 octets. - * The Header is consisted of two octets, the DNN IEI and the Length of the DNN contents fields, each is 1 octet. + * The Header is consisted of two octets, the DNN IEI and the Length of the DNN contents fields, each is 1 octet. * The DNN value payload starts from the 3rd octet. * The accumulated max length of APN payload is 100 octets. * The min length of the APN payload is 1 octet. @@ -70,16 +79,18 @@ #define APN_MAX_LEN 100 #define APN_MIN_LEN 1 +#define MAX_NUM_QOS_RULES 64 + /* Mandatory Presence IE - TS 24.501 Table 8.3.2.1.1 */ typedef struct packet_filter_create_qos_rule_s { uint8_t pf_dir; /* Packet filter direction */ - uint8_t pf_id; /* Packet filter identifier */ + uint8_t pf_id; /* Packet filter identifier */ uint8_t length; /* Length of packet filter contents */ } packet_filter_type1_t; /* TS 24.501 Figure 9.11.4.13.3 */ typedef struct packet_filter_modify_qos_rule_s { - uint8_t pf_id; /* Packet filter identifier */ + uint8_t pf_id; /* Packet filter identifier */ } packet_filter_type2_t; /* TS 24.501 Figure 9.11.4.13.4 */ typedef struct packet_filter_s { @@ -90,39 +101,51 @@ typedef struct packet_filter_s { } packet_filter_t; typedef struct qos_rule_s { - uint8_t id; /* QoS rule identifier */ - uint16_t length; /* Length of QoS Rule */ - uint8_t oc; /* Rule operation code (3bits) */ - uint8_t dqr; /* DQR bit (1 bit) */ - uint8_t nb_pf; /* Number of packet filters (4 bits) */ - uint8_t prcd; /* QoS rule precedence */ - uint8_t qfi; /* QoS Flow Identifier */ + // QoS rule identifier + uint8_t id; + // Length of QoS Rule + uint16_t length; + // Rule operation code + uint8_t oc; + // Default QoS Rule + bool dqr; + // Number of packet filters + uint8_t nb_pf; + // QoS rule precedence + uint8_t precendence; + // QoS Flow Identifier + uint8_t qfi; } qos_rule_t; typedef struct auth_qos_rules_s { - uint16_t length; /* Length of QoS rules IE */ -} auth_qos_rule_t; /* QoS Rule as defined in 24.501 Figure 9.11.4.13.2 */ + uint16_t length; /* Length of QoS rules IE */ + // QoS rules (M) + qos_rule_t rule[MAX_NUM_QOS_RULES]; +} auth_qos_rule_t; /* QoS Rule as defined in 24.501 Figure 9.11.4.13.2 */ typedef struct session_ambr_s { - uint8_t length; /* Length of Session-AMBR contents */ - uint8_t unit_dl; /* Unit for Session-AMBR for downlink */ + uint8_t length; /* Length of Session-AMBR contents */ + uint8_t unit_dl; /* Unit for Session-AMBR for downlink */ uint16_t sess_dl; /* Session-AMBR for downlink */ - uint8_t unit_ul; /* Unit for Session-AMBR for uplink */ + uint8_t unit_ul; /* Unit for Session-AMBR for uplink */ uint16_t sess_ul; /* Session-AMBR for uplink */ -} session_ambr_t; /* TS 24.501 Figure 9.11.4.14.1 */ +} session_ambr_t; /* TS 24.501 Figure 9.11.4.14.1 */ /* Optional Presence IE - TS 24.501 Table 8.3.2.1.1 */ typedef struct pdu_address_s { - uint8_t pdu_iei; /* PDU Address IEI (0x29) */ - uint8_t pdu_length; /* Length of PDU address contents */ - uint8_t pdu_type; /* PDU session type value */ - /// PDU address information (depending on type, up to 12 bytes) + // PDU address IEI (0x29) (octet 1) + uint8_t pdu_iei; + // Length of PDU address contents (octet 2) + uint8_t pdu_length; + // PDU session type value (9.11.4.11 of TS 24.501) + uint8_t pdu_type; + // PDU address IE (depending on type, up to 12 bytes) uint8_t pdu_addr_oct[IPv4_ADDRESS_LENGTH + IPv6_INTERFACE_ID_LENGTH]; } pdu_address_t; /* TS 24.501 9.11.4.10 */ typedef struct dnn_s { - uint8_t dnn_iei; /* DNN IEI (0x25) */ + uint8_t dnn_iei; /* DNN IEI (0x25) */ uint8_t dnn_length; /* Length of DNN contents */ } dnn_t; /* TS 24.501 9.11.2.1A */ @@ -135,38 +158,24 @@ typedef struct qos_fd_s { } qos_fd_t; /* TS 24.501 9.11.4.12 - Ommited, only length is processed*/ typedef struct pdu_session_establishment_accept_msg_s { - /* Mandatory presence */ - uint8_t epd; /* Extended Protocol Discriminator */ - uint8_t pdu_id; /* PDU Session ID */ - uint8_t pti; /* Procedure Transaction Identity */ - uint8_t msg_type; /* Message Type */ - uint8_t pdu_type; /* PDU Session Type */ - uint8_t ssc_mode; /* SSC mode */ - auth_qos_rule_t qos_rules; /* Authorized QoS rules */ - session_ambr_t sess_ambr; /* Session-AMBR */ - - /* Optional presence */ - dnn_t dnn_ie; /* Data Network Name */ - pdu_address_t pdu_addr_ie; /* PDU Address */ - ext_pP_t ext_pp_ie; /* Extended Protocol Configuration Options */ - qos_fd_t qos_fd_ie; /* QoS flow descriptions */ + // PDU Session Type (M) + uint8_t pdu_type; + // Selected SSC Mode (M) + uint8_t ssc_mode; + // Authorized QoS rules (M) + auth_qos_rule_t qos_rules; + // Session-AMBR (M) + session_ambr_t sess_ambr; + // Data Network Name (O) + dnn_t dnn_ie; + // PDU Address (O) + pdu_address_t pdu_addr_ie; + // Extended Protocol Configuration Options (O) + ext_pP_t ext_pp_ie; + // QoS flow descriptions (O) + qos_fd_t qos_fd_ie; } pdu_session_establishment_accept_msg_t; /* 24.501 Table 8.3.2.1.1 */ -typedef struct security_protected_plain_nas_5gs_msg_s { - uint8_t epd; /* Extended Protocol Discriminator */ - uint8_t sht; /* Security Header Type */ - uint8_t msg_type; /* Message Type */ - uint8_t payload_type; /* Payload Container Type */ - uint16_t payload_len; /* Payload Container Length */ -} security_protected_plain_nas_5gs_msg_t; - -typedef struct security_protected_nas_5gs_msg_s { - uint8_t epd; /* Extended Protocol Discriminator */ - uint8_t sht; /* Security Header Type */ - uint32_t mac; /* Message Authentication Code */ - uint8_t sqn; /* Sequence Number */ -} security_protected_nas_5gs_msg_t; /* 24.501 Figure 9.1.1.2 */ - -void capture_pdu_session_establishment_accept_msg(uint8_t *buffer, uint32_t msg_length); +int decode_pdu_session_establishment_accept_msg(pdu_session_establishment_accept_msg_t *psea_msg, uint8_t *buffer, uint32_t msg_length); #endif diff --git a/openair3/NAS/NR_UE/5GS/CMakeLists.txt b/openair3/NAS/NR_UE/5GS/CMakeLists.txt new file mode 100644 index 0000000000..e04abb02db --- /dev/null +++ b/openair3/NAS/NR_UE/5GS/CMakeLists.txt @@ -0,0 +1,17 @@ +add_subdirectory(5GMM/MSG) +add_subdirectory(5GMM/IES) +add_subdirectory(5GSM/MSG) + +if(ENABLE_TESTS) + add_subdirectory(tests) +endif() +add_library(fgs_lib fgs_nas_lib.c) + +target_link_libraries(fgs_lib PUBLIC + fgs_5gmm_lib + fgs_5gsm_lib + fgs_5gmm_ies_lib + nas_common_ies_lib +) + +target_include_directories(fgs_lib PUBLIC . 5GMM/MSG 5GMM/IES) diff --git a/openair3/NAS/NR_UE/5GS/NR_NAS_defs.h b/openair3/NAS/NR_UE/5GS/NR_NAS_defs.h new file mode 100644 index 0000000000..babda98aaa --- /dev/null +++ b/openair3/NAS/NR_UE/5GS/NR_NAS_defs.h @@ -0,0 +1,311 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +#ifndef NR_NAS_DEFS_H +#define NR_NAS_DEFS_H + +#include +#include "openair3/UICC/usim_interface.h" +#include "fgs_nas_utils.h" +#include "FGSAuthenticationResponse.h" +#include "FGSDeregistrationRequestUEOriginating.h" +#include "FGSIdentityResponse.h" +#include "FGSMobileIdentity.h" +#include "FGSNASSecurityModeComplete.h" +#include "FGSUplinkNasTransport.h" +#include "RegistrationComplete.h" +#include "RegistrationRequest.h" +#include "fgs_service_request.h" + +/* Message types defintions for: + (a) 5GS Mobility Management (5GMM) (IDs 0x41 - 0x68) + Table 9.7.1 of 3GPP TS 24.501 + (b) 5GS Session Management (5GSM) (IDs 0xc1 - 0xd6) + Table 9.7.2 of 3GPP TS 24.501 */ +#define FOREACH_TYPE(TYPE_DEF) \ + TYPE_DEF(FGS_REGISTRATION_REQUEST, 0x41) \ + TYPE_DEF(FGS_REGISTRATION_ACCEPT, 0x42) \ + TYPE_DEF(FGS_REGISTRATION_COMPLETE, 0x43) \ + TYPE_DEF(FGS_REGISTRATION_REJECT, 0x44) \ + TYPE_DEF(FGS_DEREGISTRATION_REQUEST_UE_ORIGINATING, 0x45) \ + TYPE_DEF(FGS_DEREGISTRATION_ACCEPT_UE_ORIGINATING, 0x46) \ + TYPE_DEF(FGS_DEREGISTRATION_REQUEST_UE_TERMINATED, 0x47) \ + TYPE_DEF(FGS_DEREGISTRATION_ACCEPT_UE_TERMINATED, 0x48) \ + TYPE_DEF(FGS_SERVICE_REQUEST, 0x4c) \ + TYPE_DEF(FGS_SERVICE_REJECT, 0x4d) \ + TYPE_DEF(FGS_SERVICE_ACCEPT, 0x4e) \ + TYPE_DEF(FGS_CONTROL_PLANE_SERVICE_REQUEST, 0x4f) \ + TYPE_DEF(FGS_NSS_AUTHENTICATION_COMMAND, 0x50) \ + TYPE_DEF(FGS_NSS_AUTHENTICATION_COMPLETE, 0x51) \ + TYPE_DEF(FGS_NSS_AUTHENTICATION_RESULT, 0x52) \ + TYPE_DEF(FGS_CONFIGURATION_UPDATE_COMMAND, 0x54) \ + TYPE_DEF(FGS_CONFIGURATION_UPDATE_COMPLETE, 0x55) \ + TYPE_DEF(FGS_AUTHENTICATION_REQUEST, 0x56) \ + TYPE_DEF(FGS_AUTHENTICATION_RESPONSE, 0x57) \ + TYPE_DEF(FGS_AUTHENTICATION_REJECT, 0x58) \ + TYPE_DEF(FGS_AUTHENTICATION_FAILURE, 0x59) \ + TYPE_DEF(FGS_AUTHENTICATION_RESULT, 0x5a) \ + TYPE_DEF(FGS_IDENTITY_REQUEST, 0x5b) \ + TYPE_DEF(FGS_IDENTITY_RESPONSE, 0x5c) \ + TYPE_DEF(FGS_SECURITY_MODE_COMMAND, 0x5d) \ + TYPE_DEF(FGS_SECURITY_MODE_COMPLETE, 0x5e) \ + TYPE_DEF(FGS_SECURITY_MODE_REJECT, 0x5f) \ + TYPE_DEF(FGS_5GMM_STATUS, 0x64) \ + TYPE_DEF(FGS_NOTIFICATION, 0x65) \ + TYPE_DEF(FGS_NOTIFICATION_RESPONSE, 0x66) \ + TYPE_DEF(FGS_UPLINK_NAS_TRANSPORT, 0x67) \ + TYPE_DEF(FGS_DOWNLINK_NAS_TRANSPORT, 0x68) \ + TYPE_DEF(FGS_PDU_SESSION_ESTABLISHMENT_REQ, 0xc1) \ + TYPE_DEF(FGS_PDU_SESSION_ESTABLISHMENT_ACC, 0xc2) \ + TYPE_DEF(FGS_PDU_SESSION_ESTABLISHMENT_REJ, 0xc3) \ + TYPE_DEF(FGS_PDU_SESSION_AUTH_COMMAND, 0xc5) \ + TYPE_DEF(FGS_PDU_SESSION_AUTH_COMPLETE, 0xc6) \ + TYPE_DEF(FGS_PDU_SESSION_AUTH_RESULT, 0xc7) \ + TYPE_DEF(FGS_PDU_SESSION_MODIFICATION_REQ, 0xc9) \ + TYPE_DEF(FGS_PDU_SESSION_MODIFICATION_REJ, 0xca) \ + TYPE_DEF(FGS_PDU_SESSION_MODIFICATION_COMMAND, 0xcb) \ + TYPE_DEF(FGS_PDU_SESSION_MODIFICATION_COMPLETE, 0xcc) \ + TYPE_DEF(FGS_PDU_SESSION_MODIFICATION_COMMAND_REJ, 0xcd) \ + TYPE_DEF(FGS_PDU_SESSION_RELEASE_REQ, 0xd1) \ + TYPE_DEF(FGS_PDU_SESSION_RELEASE_REJ, 0xd2) \ + TYPE_DEF(FGS_PDU_SESSION_RELEASE_COMMAND, 0xd3) \ + TYPE_DEF(FGS_PDU_SESSION_RELEASE_COMPLETE, 0xd4) \ + TYPE_DEF(FGS_5GSM_STATUS, 0xd6) + +static const text_info_t message_text_info[] = { + FOREACH_TYPE(TO_TEXT) +}; + +//! Tasks id of each task +typedef enum { + FOREACH_TYPE(TO_ENUM) +} fgs_nas_msg_t; + +// TS 24.501 +#define FOREACH_HEADER(TYPE_DEF) \ + TYPE_DEF(PLAIN_5GS_MSG, 0) \ + TYPE_DEF(INTEGRITY_PROTECTED, 1) \ + TYPE_DEF(INTEGRITY_PROTECTED_AND_CIPHERED, 2) \ + TYPE_DEF(INTEGRITY_PROTECTED_WITH_NEW_SECU_CTX, 3) \ + TYPE_DEF(INTEGRITY_PROTECTED_AND_CIPHERED_WITH_NEW_SECU_CTX, 4) + +typedef enum { FOREACH_HEADER(TO_ENUM) } Security_header_t; + +static const text_info_t security_header_type_s[] = {FOREACH_HEADER(TO_TEXT)}; + +// table 9.11.3.2.1 +#define FOREACH_CAUSE(CAUSE_DEF) \ + CAUSE_DEF(Illegal_UE,0x3 )\ + CAUSE_DEF(PEI_not_accepted,0x5 )\ + CAUSE_DEF(Illegal_ME,0x6 )\ + CAUSE_DEF(SGS_services_not_allowed,0x7 )\ + CAUSE_DEF(UE_identity_cannot_be_derived_by_the_network,0x9 )\ + CAUSE_DEF(Implicitly_de_registered,0x0a )\ + CAUSE_DEF(PLMN_not_allowed,0x0b )\ + CAUSE_DEF(Tracking_area_not_allowed,0x0c )\ + CAUSE_DEF(Roaming_not_allowed_in_this_tracking_area,0x0d )\ + CAUSE_DEF(No_suitable_cells_in_tracking_area,0x0f )\ + CAUSE_DEF(MAC_failure,0x14 )\ + CAUSE_DEF(Synch_failure,0x15 )\ + CAUSE_DEF(Congestion,0x16 )\ + CAUSE_DEF(UE_security_capabilities_mismatch,0x17 )\ + CAUSE_DEF(Security_mode_rejected_unspecified,0x18 )\ + CAUSE_DEF(Non_5G_authentication_unacceptable,0x1a )\ + CAUSE_DEF(N1_mode_not_allowed,0x1b )\ + CAUSE_DEF(Restricted_service_area,0x1c )\ + CAUSE_DEF(Redirection_to_EPC_required,0x1f )\ + CAUSE_DEF(LADN_not_available,0x2b )\ + CAUSE_DEF(No_network_slices_available,0x3e )\ + CAUSE_DEF(Maximum_number_of_PDU_sessions_reached,0x41 )\ + CAUSE_DEF(Insufficient_resources_for_specific_slice_and_DNN,0x43 )\ + CAUSE_DEF(Insufficient_resources_for_specific_slice,0x45 )\ + CAUSE_DEF(ngKSI_already_in_use,0x47 )\ + CAUSE_DEF(Non_3GPP_access_to_5GCN_not_allowed,0x48 )\ + CAUSE_DEF(Serving_network_not_authorized,0x49 )\ + CAUSE_DEF(Temporarily_not_authorized_for_this_SNPN,0x4A )\ + CAUSE_DEF(Permanently_not_authorized_for_this_SNPN,0x4b )\ + CAUSE_DEF(Not_authorized_for_this_CAG_or_authorized_for_CAG_cells_only,0x4c )\ + CAUSE_DEF(Wireline_access_area_not_allowed,0x4d )\ + CAUSE_DEF(Payload_was_not_forwarded,0x5a )\ + CAUSE_DEF(DNN_not_supported_or_not_subscribed_in_the_slice,0x5b )\ + CAUSE_DEF(Insufficient_user_plane_resources_for_the_PDU_session,0x5c )\ + CAUSE_DEF(Semantically_incorrect_message,0x5f )\ + CAUSE_DEF(Invalid_mandatory_information,0x60 )\ + CAUSE_DEF(Message_type_non_existent_or_not_implemented,0x61 )\ + CAUSE_DEF(Message_type_not_compatible_with_the_protocol_state,0x62 )\ + CAUSE_DEF(Information_element_non_existent_or_not_implemented,0x63 )\ + CAUSE_DEF(Conditional_IE_error,0x64 )\ + CAUSE_DEF(Message_not_compatible_with_the_protocol_state,0x65 )\ + CAUSE_DEF(Protocol_error_unspecified,0x67 ) + +/* Map task id to printable name. */ +#define CAUSE_TEXT(LabEl, nUmID) {nUmID, #LabEl}, + +static const text_info_t cause_text_info[] = { + FOREACH_CAUSE(TO_TEXT) +}; + +#define CAUSE_ENUM(LabEl, nUmID ) LabEl = nUmID, +//! Tasks id of each task +typedef enum { + FOREACH_CAUSE(TO_ENUM) +} cause_id_t; + +//_table_9.11.4.2.1:_5GSM_cause_information_element +#define FOREACH_CAUSE_SECU(CAUSE_SECU_DEF) \ + CAUSE_SECU_DEF(Security_Operator_determined_barring,0x08 )\ + CAUSE_SECU_DEF(Security_Insufficient_resources,0x1a )\ + CAUSE_SECU_DEF(Security_Missing_or_unknown_DNN,0x1b )\ + CAUSE_SECU_DEF(Security_Unknown_PDU_session_type,0x1c )\ + CAUSE_SECU_DEF(Security_User_authentication_or_authorization_failed,0x1d )\ + CAUSE_SECU_DEF(Security_Request_rejected_unspecified,0x1f )\ + CAUSE_SECU_DEF(Security_Service_option_not_supported,0x20 )\ + CAUSE_SECU_DEF(Security_Requested_service_option_not_subscribed,0x21 )\ + CAUSE_SECU_DEF(Security_Service_option_temporarily_out_of_order,0x22 )\ + CAUSE_SECU_DEF(Security_PTI_already_in_use,0x23 )\ + CAUSE_SECU_DEF(Security_Regular_deactivation,0x24 )\ + CAUSE_SECU_DEF(Security_Network_failure,0x26 )\ + CAUSE_SECU_DEF(Security_Reactivation_requested,0x27 )\ + CAUSE_SECU_DEF(Security_Semantic_error_in_the_TFT_operation,0x29 )\ + CAUSE_SECU_DEF(Security_Syntactical_error_in_the_TFT_operation,0x2a )\ + CAUSE_SECU_DEF(Security_Invalid_PDU_session_identity,0x2b )\ + CAUSE_SECU_DEF(Security_Semantic_errors_in_packet_filter,0x2c )\ + CAUSE_SECU_DEF(Security_Syntactical_error_in_packet_filter,0x2d )\ + CAUSE_SECU_DEF(Security_Out_of_LADN_service_area,0x2e )\ + CAUSE_SECU_DEF(Security_PTI_mismatch,0x2f )\ + CAUSE_SECU_DEF(Security_PDU_session_type_IPv4_only_allowed,0x32 )\ + CAUSE_SECU_DEF(Security_PDU_session_type_IPv6_only_allowed,0x33 )\ + CAUSE_SECU_DEF(Security_PDU_session_does_not_exist,0x36 )\ + CAUSE_SECU_DEF(Security_PDU_session_type_IPv4v6_only_allowed,0x39 )\ + CAUSE_SECU_DEF(Security_PDU_session_type_Unstructured_only_allowed,0x3a )\ + CAUSE_SECU_DEF(Security_PDU_session_type_Ethernet_only_allowed,0x3d )\ + CAUSE_SECU_DEF(Security_Insufficient_resources_for_specific_slice_and_DNN,0x43 )\ + CAUSE_SECU_DEF(Security_Not_supported_SSC_mode,0x44 )\ + CAUSE_SECU_DEF(Security_Insufficient_resources_for_specific_slice,0x45 )\ + CAUSE_SECU_DEF(Security_Missing_or_unknown_DNN_in_a_slice,0x46 )\ + CAUSE_SECU_DEF(Security_Invalid_PTI_value,0x51 )\ + CAUSE_SECU_DEF(Security_Maximum_data_rate_per_UE_for_user_plane_integrity_protection_is_too_low,0x52 )\ + CAUSE_SECU_DEF(Security_Semantic_error_in_the_QoS_operation,0x53 )\ + CAUSE_SECU_DEF(Security_Syntactical_error_in_the_QoS_operation,0x54 )\ + CAUSE_SECU_DEF(Security_Invalid_mapped_EPS_bearer_identity,0x55 )\ + CAUSE_SECU_DEF(Security_Semantically_incorrect_message,0x5f )\ + CAUSE_SECU_DEF(Security_Invalid_mandatory_information,0x60 )\ + CAUSE_SECU_DEF(Security_Message_type_non_existent_or_not_implemented,0x61 )\ + CAUSE_SECU_DEF(Security_Message_type_not_compatible_with_the_protocol_state,0x62 )\ + CAUSE_SECU_DEF(Security_Information_element_non_existent_or_not_implemented,0x63 )\ + CAUSE_SECU_DEF(Security_Conditional_IE_error,0x64 )\ + CAUSE_SECU_DEF(Security_Message_not_compatible_with_the_protocol_state,0x65 )\ + CAUSE_SECU_DEF(Security_Protocol_error_unspecified,0x6f ) + +static const text_info_t cause_secu_text_info[] = { + FOREACH_CAUSE_SECU(TO_TEXT) +}; + +//! Tasks id of each task +typedef enum { + FOREACH_CAUSE_SECU(TO_ENUM) +} cause_secu_id_t; + +/** + * Security protected 5GS NAS message header (9.1.1 of 3GPP TS 24.501) + * either 5GMM or 5GSM + * Standard L3 message header (11.2.3.1 of 3GPP TS 24.007) + */ +typedef struct { + // Extended Protocol Discriminator + uint8_t protocol_discriminator; + // Security Header Type + uint8_t security_header_type; + // Message Authentication Code + uint32_t message_authentication_code; + // Sequence Number + uint8_t sequence_number; +} __attribute__((packed)) fgs_nas_message_security_header_t; + +/// 5GS Protocol Discriminator identifiers + +typedef enum fgs_protocol_discriminator_e { + // 5GS Mobility Management + FGS_MOBILITY_MANAGEMENT_MESSAGE = 0x7E, + // 5GS Session Management + FGS_SESSION_MANAGEMENT_MESSAGE = 0x2E, +} fgs_protocol_discriminator_t; + +/// 5GMM - 5GS mobility management + +/** + * Header of a plain 5GMM NAS message (5GS) + * Standard L3 message header (11.2.3.1 of 3GPP TS 24.007) + */ +typedef struct { + uint8_t ex_protocol_discriminator; + uint8_t security_header_type; + uint8_t message_type; +} fgmm_msg_header_t; + +/* Plain 5GMM NAS message (5GS) */ +typedef struct { + fgmm_msg_header_t header; + union { + registration_request_msg registration_request; + fgs_service_request_msg_t service_request; + fgmm_identity_response_msg fgs_identity_response; + fgs_authentication_response_msg fgs_auth_response; + fgs_deregistration_request_ue_originating_msg fgs_deregistration_request_ue_originating; + fgs_security_mode_complete_msg fgs_security_mode_complete; + registration_complete_msg registration_complete; + fgs_uplink_nas_transport_msg uplink_nas_transport; + } mm_msg; /* 5GS Mobility Management messages */ +} fgmm_nas_message_plain_t; + +/* Security protected 5GMM NAS message (5GS) */ +typedef struct { + fgs_nas_message_security_header_t header; + fgmm_nas_message_plain_t plain; +} fgmm_nas_msg_security_protected_t; + +/// 5GSM - 5GS session management + +/** + * Header of a plain 5GSM NAS message (5GS) + * Standard L3 message header (11.2.3.1 of 3GPP TS 24.007) + */ +typedef struct { + // Extended protocol discriminator + uint8_t ex_protocol_discriminator; + // PDU session identity + uint8_t pdu_session_id; + // Procedure transaction identity + uint8_t pti; + // Message type + uint8_t message_type; +} fgsm_msg_header_t; + +/// Function prototypes + +int mm_msg_encode(const fgmm_nas_message_plain_t *mm_msg, uint8_t *buffer, uint32_t len); +int nas_protected_security_header_encode(uint8_t *buffer, const fgs_nas_message_security_header_t *header, int length); +int _nas_mm_msg_encode_header(const fgmm_msg_header_t *header, uint8_t *buffer, uint32_t len); +uint8_t decode_5gmm_msg_header(fgmm_msg_header_t *mm_header, const uint8_t *buffer, uint32_t len); +uint8_t decode_5gsm_msg_header(fgsm_msg_header_t *sm_header, const uint8_t *buffer, uint32_t len); +int decode_5gs_security_protected_header(fgs_nas_message_security_header_t *header, const uint8_t *buf, uint32_t len); + +#endif // NR_NAS_DEFS_H diff --git a/openair3/NAS/NR_UE/5GS/fgs_nas_lib.c b/openair3/NAS/NR_UE/5GS/fgs_nas_lib.c new file mode 100644 index 0000000000..16d84f3ad8 --- /dev/null +++ b/openair3/NAS/NR_UE/5GS/fgs_nas_lib.c @@ -0,0 +1,179 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +#include "NR_NAS_defs.h" +#include "nas_log.h" +#include "TLVEncoder.h" +#include "fgs_nas_utils.h" + +int _nas_mm_msg_encode_header(const fgmm_msg_header_t *header, uint8_t *buffer, uint32_t len) +{ + int size = 0; + + /* Check the buffer length */ + if (len < sizeof(fgmm_msg_header_t)) { + return (TLV_ENCODE_BUFFER_TOO_SHORT); + } + + /* Check the protocol discriminator */ + if (header->ex_protocol_discriminator != FGS_MOBILITY_MANAGEMENT_MESSAGE) { + LOG_TRACE(ERROR, "Unexpected extened protocol discriminator: 0x%x", header->ex_protocol_discriminator); + return (TLV_ENCODE_PROTOCOL_NOT_SUPPORTED); + } + + /* Encode the extendedprotocol discriminator */ + ENCODE_U8(buffer + size, header->ex_protocol_discriminator, size); + /* Encode the security header type */ + ENCODE_U8(buffer + size, (header->security_header_type & 0xf), size); + /* Encode the message type */ + ENCODE_U8(buffer + size, header->message_type, size); + return (size); +} + +int mm_msg_encode(const fgmm_nas_message_plain_t *p, uint8_t *buffer, uint32_t len) +{ + uint8_t msg_type = p->header.message_type; + int enc_msg = 0; + /* First encode the 5GMM message header */ + int enc_header = _nas_mm_msg_encode_header(&p->header, buffer, len); + + if (enc_header < 0) { + PRINT_NAS_ERROR("Failed to encode 5GMM message header\n"); + return enc_header; + } + + buffer += enc_header; + len -= enc_header; + + switch (msg_type) { + case FGS_REGISTRATION_REQUEST: + enc_msg = encode_registration_request(&p->mm_msg.registration_request, buffer, len); + break; + case FGS_IDENTITY_RESPONSE: + enc_msg = encode_fgmm_identity_response(buffer, &p->mm_msg.fgs_identity_response, len); + break; + case FGS_AUTHENTICATION_RESPONSE: + enc_msg = encode_fgs_authentication_response(&p->mm_msg.fgs_auth_response, buffer, len); + break; + case FGS_SECURITY_MODE_COMPLETE: + enc_msg = encode_fgs_security_mode_complete(&p->mm_msg.fgs_security_mode_complete, buffer, len); + break; + case FGS_UPLINK_NAS_TRANSPORT: + enc_msg = encode_fgs_uplink_nas_transport(&p->mm_msg.uplink_nas_transport, buffer, len); + break; + case FGS_DEREGISTRATION_REQUEST_UE_ORIGINATING: + enc_msg = + encode_fgs_deregistration_request_ue_originating(&p->mm_msg.fgs_deregistration_request_ue_originating, buffer, len); + break; + case FGS_SERVICE_REQUEST: + enc_msg = encode_fgs_service_request(buffer, &p->mm_msg.service_request, len); + break; + default: + LOG_TRACE(ERROR, " Unexpected message type: 0x%x", p->header.message_type); + enc_msg = TLV_ENCODE_WRONG_MESSAGE_TYPE; + break; + /* TODO: Handle not standard layer 3 messages: SERVICE_REQUEST */ + } + + if (enc_msg < 0) { + PRINT_NAS_ERROR("Failed to encode 5GMM message\n"); + return enc_msg; + } + + return enc_header + enc_msg; +} + +int nas_protected_security_header_encode(uint8_t *buffer, const fgs_nas_message_security_header_t *header, int length) +{ + int size = 0; + + if (length < sizeof(fgs_nas_message_security_header_t)) { + PRINT_NAS_ERROR("Could not encode the NAS security header\n"); + return -1; + } + + /* Encode the protocol discriminator) */ + ENCODE_U8(buffer, header->protocol_discriminator, size); + + /* Encode the security header type */ + ENCODE_U8(buffer + size, (header->security_header_type & 0xf), size); + + /* Encode the message authentication code */ + ENCODE_U32(buffer + size, header->message_authentication_code, size); + /* Encode the sequence number */ + ENCODE_U8(buffer + size, header->sequence_number, size); + + return size; +} + +/** + * @brief Decode plain 5GMM header from buffer and return fgmm_msg_header_t instance + */ +uint8_t decode_5gmm_msg_header(fgmm_msg_header_t *mm_header, const uint8_t *buffer, uint32_t len) +{ + if (len < sizeof(fgmm_msg_header_t)) { + PRINT_NAS_ERROR("Failed to decode plain 5GMM header: buffer length too short\n"); + return -1; + } + mm_header->ex_protocol_discriminator = *buffer++; + mm_header->security_header_type = *buffer++; + mm_header->message_type = *buffer++; + return sizeof(*mm_header); +} + +/** + * @brief Decode plain 5GSM header from buffer and return fgsm_msg_header_t instance + */ +uint8_t decode_5gsm_msg_header(fgsm_msg_header_t *sm_header, const uint8_t *buffer, uint32_t len) +{ + if (len < sizeof(fgsm_msg_header_t)) { + PRINT_NAS_ERROR("Failed to decode plain 5GSM header: buffer length too short\n"); + return -1; + } + sm_header->ex_protocol_discriminator = *buffer++; + sm_header->pdu_session_id = *buffer++; + sm_header->pti = *buffer++; + sm_header->message_type = *buffer++; + return sizeof(*sm_header); +} + +/** + * @brief Decode security protected 5GS header from buffer and return fgs_nas_message_security_header_t instance + */ +int decode_5gs_security_protected_header(fgs_nas_message_security_header_t *header, const uint8_t *buf, uint32_t len) +{ + int decoded = 0; + if (len < sizeof(fgs_nas_message_security_header_t)) { + PRINT_NAS_ERROR("Failed to decode security protected 5GS header: buffer length too short\n"); + return -1; + } + header->protocol_discriminator = *buf++; + decoded++; + header->security_header_type = *buf++; + decoded++; + uint32_t tmp; + memcpy(&tmp, buf, sizeof(tmp)); + decoded += sizeof(tmp); + header->message_authentication_code = htonl(tmp); + header->sequence_number = *buf++; + decoded++; + return decoded; +} diff --git a/openair3/NAS/NR_UE/5GS/fgs_nas_utils.h b/openair3/NAS/NR_UE/5GS/fgs_nas_utils.h new file mode 100644 index 0000000000..09754e9903 --- /dev/null +++ b/openair3/NAS/NR_UE/5GS/fgs_nas_utils.h @@ -0,0 +1,62 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +#ifndef FGS_NAS_UTILS_H +#define FGS_NAS_UTILS_H + +#include +#include +#include // For memcpy + +#define PRINT_NAS_ERROR(...) fprintf(stderr, ##__VA_ARGS__) + +#define _NAS_EQ_CHECK_GENERIC(condition, fmt, ...) \ + do { \ + if (!(condition)) { \ + PRINT_NAS_ERROR("NAS Equality Check failure: %s:%d: Condition '%s' failed: " fmt " != " fmt "\n", \ + __FILE__, \ + __LINE__, \ + #condition, \ + ##__VA_ARGS__); \ + return false; \ + } \ + } while (0) + +#define _NAS_EQ_CHECK_LONG(A, B) _NAS_EQ_CHECK_GENERIC(A == B, "%ld", A, B); +#define _NAS_EQ_CHECK_INT(A, B) _NAS_EQ_CHECK_GENERIC(A == B, "%d", A, B); +#define _NAS_EQ_CHECK_STR(A, B) _NAS_EQ_CHECK_GENERIC(strcmp(A, B) == 0, "'%s'", A, B); + +/* Map task id to printable name. */ +typedef struct { + int id; + char text[256]; +} text_info_t; + +#define TO_TEXT(LabEl, nUmID) {nUmID, #LabEl}, +#define TO_ENUM(LabEl, nUmID ) LabEl = nUmID, + +#define GET_SHORT(input, size) ({ \ + uint16_t tmp16; \ + memcpy(&tmp16, (input), sizeof(tmp16)); \ + size += htons(tmp16); \ +}) + +#endif // FGS_NAS_UTILS_H diff --git a/openair3/NAS/COMMON/EMM/tests/CMakeLists.txt b/openair3/NAS/NR_UE/5GS/tests/CMakeLists.txt similarity index 74% rename from openair3/NAS/COMMON/EMM/tests/CMakeLists.txt rename to openair3/NAS/NR_UE/5GS/tests/CMakeLists.txt index 3f960c5562..a72a47700f 100644 --- a/openair3/NAS/COMMON/EMM/tests/CMakeLists.txt +++ b/openair3/NAS/NR_UE/5GS/tests/CMakeLists.txt @@ -5,9 +5,10 @@ add_executable(nas_lib_test nas_lib_test.c) add_dependencies(tests nas_lib_test) add_test(NAME nas_lib_test COMMAND nas_lib_test) -target_link_libraries(nas_lib_test PRIVATE fgs_lib fgs_ies_lib) +target_link_libraries(nas_lib_test PRIVATE + nr_nas +) target_include_directories(nas_lib_test PRIVATE - ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ) diff --git a/openair3/NAS/COMMON/EMM/tests/nas_lib_test.c b/openair3/NAS/NR_UE/5GS/tests/nas_lib_test.c similarity index 100% rename from openair3/NAS/COMMON/EMM/tests/nas_lib_test.c rename to openair3/NAS/NR_UE/5GS/tests/nas_lib_test.c diff --git a/openair3/NAS/NR_UE/CMakeLists.txt b/openair3/NAS/NR_UE/CMakeLists.txt new file mode 100644 index 0000000000..5e7d5da428 --- /dev/null +++ b/openair3/NAS/NR_UE/CMakeLists.txt @@ -0,0 +1,15 @@ +add_subdirectory(5GS) + +add_library(nr_nas STATIC nr_nas_msg.c) + +target_link_libraries(nr_nas PUBLIC asn1_lte_rrc_hdrs asn1_nr_rrc_hdrs) +target_link_libraries(nr_nas PUBLIC + fgs_lib + fgs_5gmm_lib + fgs_5gsm_lib + fgs_5gmm_ies_lib + nas_common_ies_lib + nas_utils +) + +target_include_directories(nr_nas PUBLIC . 5GS/) diff --git a/openair3/NAS/NR_UE/nr_nas_msg.c b/openair3/NAS/NR_UE/nr_nas_msg.c index f05a173960..d7a1c42bf3 100644 --- a/openair3/NAS/NR_UE/nr_nas_msg.c +++ b/openair3/NAS/NR_UE/nr_nas_msg.c @@ -20,7 +20,7 @@ */ /*! \file nr_nas_msg.c - * \brief simulator for nr nas message + * \brief Definitions of handlers and callbacks for NR NAS UE task * \author Yoshio INOUE, Masayuki HARADA * \email yoshio.inoue@fujitsu.com,masayuki.harada@fujitsu.com * \date 2020 @@ -29,57 +29,116 @@ * 2023.01.27 Vladimir Dorovskikh 16 digits IMEISV */ -#include // memset -#include // malloc, free - -#include "nas_log.h" -#include "TLVDecoder.h" -#include "TLVEncoder.h" #include "nr_nas_msg.h" -#include "aka_functions.h" -#include "secu_defs.h" -#include "kdf.h" -#include "key_nas_deriver.h" +#include +#include "NR_NAS_defs.h" +#include +#include +#include +#include +#include "AuthenticationResponseParameter.h" +#include "FGCNasMessageContainer.h" +#include "FGSDeregistrationRequestUEOriginating.h" +#include "FGSDeregistrationType.h" +#include "NasKeySetIdentifier.h" +#include "NrUESecurityCapability.h" +#include "OctetString.h" #include "PduSessionEstablishRequest.h" #include "PduSessionEstablishmentAccept.h" #include "RegistrationAccept.h" -#include "FGSDeregistrationRequestUEOriginating.h" -#include "intertask_interface.h" +#include "SORTransparentContainer.h" +#include "FGSIdentityResponse.h" +#include "T.h" +#include "aka_functions.h" +#include "assertions.h" +#include "common/utils/ds/byte_array.h" #include "common/utils/tun_if.h" -#include -#include "openair2/SDAP/nr_sdap/nr_sdap.h" -#include "openair3/SECU/nas_stream_eia2.h" +#include "commonDef.h" +#include "intertask_interface.h" +#include "kdf.h" +#include "key_nas_deriver.h" +#include "nas_log.h" +#include "openair3/UICC/usim_interface.h" #include "openair3/UTILS/conversions.h" +#include "secu_defs.h" +#include "utils.h" +#include "openair2/SDAP/nr_sdap/nr_sdap.h" +#include "fgs_nas_utils.h" #define MAX_NAS_UE 4 static nr_ue_nas_t nr_ue_nas[MAX_NAS_UE] = {0}; -static nr_nas_msg_snssai_t nas_allowed_nssai[8]; -typedef enum { - NAS_SECURITY_NO_SECURITY_CONTEXT, - NAS_SECURITY_UNPROTECTED, - NAS_SECURITY_INTEGRITY_FAILED, - NAS_SECURITY_INTEGRITY_PASSED, - NAS_SECURITY_BAD_INPUT -} security_state_t; +#define FOREACH_STATE(TYPE_DEF) \ + TYPE_DEF(NAS_SECURITY_NO_SECURITY_CONTEXT, 0) \ + TYPE_DEF(NAS_SECURITY_NEW_SECURITY_CONTEXT, 1) \ + TYPE_DEF(NAS_SECURITY_UNPROTECTED, 2) \ + TYPE_DEF(NAS_SECURITY_INTEGRITY_FAILED, 3) \ + TYPE_DEF(NAS_SECURITY_INTEGRITY_PASSED, 4) \ + TYPE_DEF(NAS_SECURITY_BAD_INPUT, 5) -security_state_t nas_security_rx_process(nr_ue_nas_t *nas, uint8_t *pdu_buffer, int pdu_length) +typedef enum { FOREACH_STATE(TO_ENUM) } security_state_t; + +static const text_info_t security_state_info[] = {FOREACH_STATE(TO_TEXT)}; + +static fgmm_msg_header_t set_mm_header(fgs_nas_msg_t type, Security_header_t security) +{ + fgmm_msg_header_t mm_header = {0}; + mm_header.ex_protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; + mm_header.security_header_type = security; + mm_header.message_type = type; + return mm_header; +} + +static void servingNetworkName(uint8_t *msg, char *imsiStr, int mnc_size) +{ + // SNN-network-identifier in TS 24.501 + // TS 24.501: If the MNC of the serving PLMN has two digits, then a zero is added at the beginning. + + // MNC + char mnc[4]; + if (mnc_size == 2) { + snprintf(mnc, sizeof(mnc), "0%c%c", imsiStr[3], imsiStr[4]); + } else { + snprintf(mnc, sizeof(mnc), "%c%c%c", imsiStr[3], imsiStr[4], imsiStr[5]); + } + + // MCC + char mcc[4]; + snprintf(mcc, sizeof(mcc), "%c%c%c", imsiStr[0], imsiStr[1], imsiStr[2]); + + int size = 64; + + snprintf((char *)msg, size, "5G:mnc%3s.mcc%3s.3gppnetwork.org", mnc, mcc); +} + +static security_state_t nas_security_rx_process(nr_ue_nas_t *nas, uint8_t *pdu_buffer, int pdu_length) { if (nas->security_container == NULL) return NAS_SECURITY_NO_SECURITY_CONTEXT; - if (pdu_buffer[1] == 0) - return NAS_SECURITY_UNPROTECTED; /* header is 7 bytes, require at least one byte of payload */ if (pdu_length < 8) return NAS_SECURITY_BAD_INPUT; - /* only accept "integrity protected and ciphered" messages */ - if (pdu_buffer[1] != 2) { - LOG_E(NAS, "todo: unhandled security type %d\n", pdu_buffer[2]); - return NAS_SECURITY_BAD_INPUT; + + switch (pdu_buffer[1]) { + case PLAIN_5GS_MSG: + return NAS_SECURITY_UNPROTECTED; + break; + case INTEGRITY_PROTECTED: + case INTEGRITY_PROTECTED_WITH_NEW_SECU_CTX: + case INTEGRITY_PROTECTED_AND_CIPHERED_WITH_NEW_SECU_CTX: + /* only accept "integrity protected and ciphered" messages */ + if (pdu_buffer[6] == 0) + LOG_E(NAS, "Received nas_count_dl = %d\n", pdu_buffer[6]); + LOG_E(NAS, "todo: unhandled security type %s (pdu_buffer[1] = %d)\n", security_header_type_s[pdu_buffer[1]].text, pdu_buffer[1]); + return NAS_SECURITY_BAD_INPUT; + break; + default: + break; } /* synchronize NAS SQN, based on 24.501 4.4.3.1 */ + // Sequence number int nas_sqn = pdu_buffer[6]; int target_sqn = nas->security.nas_count_dl & 0xff; if (nas_sqn != target_sqn) { @@ -96,83 +155,40 @@ security_state_t nas_security_rx_process(nr_ue_nas_t *nas, uint8_t *pdu_buffer, } /* check integrity */ - uint8_t computed_mac[4]; + uint8_t computed_mac[NAS_INTEGRITY_SIZE]; nas_stream_cipher_t stream_cipher; stream_cipher.context = nas->security_container->integrity_context; stream_cipher.count = nas->security.nas_count_dl; stream_cipher.bearer = 1; /* todo: don't hardcode */ stream_cipher.direction = 1; - stream_cipher.message = pdu_buffer + 6; + stream_cipher.message = pdu_buffer + SECURITY_PROTECTED_5GS_NAS_MESSAGE_HEADER_LENGTH - 1; /* length in bits */ - stream_cipher.blength = (pdu_length - 6) << 3; + stream_cipher.blength = (pdu_length - SECURITY_PROTECTED_5GS_NAS_MESSAGE_HEADER_LENGTH + 1) << 3; stream_compute_integrity(nas->security_container->integrity_algorithm, &stream_cipher, computed_mac); uint8_t *received_mac = pdu_buffer + 2; - if (memcmp(received_mac, computed_mac, 4) != 0) + if (memcmp(received_mac, computed_mac, NAS_INTEGRITY_SIZE) != 0) return NAS_SECURITY_INTEGRITY_FAILED; /* decipher */ - uint8_t buf[pdu_length - 7]; + uint8_t payload_len = pdu_length - SECURITY_PROTECTED_5GS_NAS_MESSAGE_HEADER_LENGTH; + uint8_t buf[payload_len]; stream_cipher.context = nas->security_container->ciphering_context; stream_cipher.count = nas->security.nas_count_dl; stream_cipher.bearer = 1; /* todo: don't hardcode */ stream_cipher.direction = 1; - stream_cipher.message = pdu_buffer + 7; + stream_cipher.message = pdu_buffer + SECURITY_PROTECTED_5GS_NAS_MESSAGE_HEADER_LENGTH; /* length in bits */ - stream_cipher.blength = (pdu_length - 7) << 3; + stream_cipher.blength = (payload_len) << 3; stream_compute_encrypt(nas->security_container->ciphering_algorithm, &stream_cipher, buf); - memcpy(pdu_buffer + 7, buf, pdu_length - 7); + memcpy(pdu_buffer + SECURITY_PROTECTED_5GS_NAS_MESSAGE_HEADER_LENGTH, buf, payload_len); nas->security.nas_count_dl++; return NAS_SECURITY_INTEGRITY_PASSED; } -static int nas_protected_security_header_encode(char *buffer, const fgs_nas_message_security_header_t *header, int length) -{ - LOG_FUNC_IN; - - int size = 0; - - /* Encode the protocol discriminator) */ - ENCODE_U8(buffer, header->protocol_discriminator, size); - - /* Encode the security header type */ - ENCODE_U8(buffer + size, (header->security_header_type & 0xf), size); - - /* Encode the message authentication code */ - ENCODE_U32(buffer + size, header->message_authentication_code, size); - /* Encode the sequence number */ - ENCODE_U8(buffer + size, header->sequence_number, size); - - LOG_FUNC_RETURN(size); -} - -static int _nas_mm_msg_encode_header(const mm_msg_header_t *header, uint8_t *buffer, uint32_t len) -{ - int size = 0; - - /* Check the buffer length */ - if (len < sizeof(mm_msg_header_t)) { - return (TLV_ENCODE_BUFFER_TOO_SHORT); - } - - /* Check the protocol discriminator */ - if (header->ex_protocol_discriminator != FGS_MOBILITY_MANAGEMENT_MESSAGE) { - LOG_TRACE(ERROR, "ESM-MSG - Unexpected extened protocol discriminator: 0x%x", header->ex_protocol_discriminator); - return (TLV_ENCODE_PROTOCOL_NOT_SUPPORTED); - } - - /* Encode the extendedprotocol discriminator */ - ENCODE_U8(buffer + size, header->ex_protocol_discriminator, size); - /* Encode the security header type */ - ENCODE_U8(buffer + size, (header->security_header_type & 0xf), size); - /* Encode the message type */ - ENCODE_U8(buffer + size, header->message_type, size); - return (size); -} - static int fill_suci(FGSMobileIdentity *mi, const uicc_t *uicc) { mi->suci.typeofidentity = FGS_MOBILE_IDENTITY_SUCI; @@ -230,71 +246,6 @@ static int fill_imeisv(FGSMobileIdentity *mi, const uicc_t *uicc) return 19; } -int mm_msg_encode(MM_msg *mm_msg, uint8_t *buffer, uint32_t len) -{ - LOG_FUNC_IN; - int header_result; - int encode_result; - uint8_t msg_type = mm_msg->header.message_type; - - /* First encode the EMM message header */ - header_result = _nas_mm_msg_encode_header(&mm_msg->header, buffer, len); - - if (header_result < 0) { - LOG_TRACE(ERROR, - "EMM-MSG - Failed to encode EMM message header " - "(%d)", - header_result); - LOG_FUNC_RETURN(header_result); - } - - buffer += header_result; - len -= header_result; - - switch (msg_type) { - case REGISTRATION_REQUEST: - encode_result = encode_registration_request(&mm_msg->registration_request, buffer, len); - break; - case FGS_IDENTITY_RESPONSE: - encode_result = encode_identiy_response(&mm_msg->fgs_identity_response, buffer, len); - break; - case FGS_AUTHENTICATION_RESPONSE: - encode_result = encode_fgs_authentication_response(&mm_msg->fgs_auth_response, buffer, len); - break; - case FGS_SECURITY_MODE_COMPLETE: - encode_result = encode_fgs_security_mode_complete(&mm_msg->fgs_security_mode_complete, buffer, len); - break; - case FGS_UPLINK_NAS_TRANSPORT: - encode_result = encode_fgs_uplink_nas_transport(&mm_msg->uplink_nas_transport, buffer, len); - break; - case FGS_DEREGISTRATION_REQUEST_UE_ORIGINATING: - encode_result = - encode_fgs_deregistration_request_ue_originating(&mm_msg->fgs_deregistration_request_ue_originating, buffer, len); - break; - case FGS_SERVICE_REQUEST: - encode_result = encode_fgs_service_request(buffer, &mm_msg->service_request, len); - break; - default: - LOG_TRACE(ERROR, "EMM-MSG - Unexpected message type: 0x%x", mm_msg->header.message_type); - encode_result = TLV_ENCODE_WRONG_MESSAGE_TYPE; - break; - /* TODO: Handle not standard layer 3 messages: SERVICE_REQUEST */ - } - - if (encode_result < 0) { - LOG_TRACE(ERROR, - "EMM-MSG - Failed to encode L3 EMM message 0x%x " - "(%d)", - mm_msg->header.message_type, - encode_result); - } - - if (encode_result < 0) - LOG_FUNC_RETURN(encode_result); - - LOG_FUNC_RETURN(header_result + encode_result); -} - void transferRES(uint8_t ck[16], uint8_t ik[16], uint8_t *input, uint8_t rand[16], uint8_t *output, uicc_t *uicc) { uint8_t S[100] = {0}; @@ -409,7 +360,7 @@ void derive_knas(algorithm_type_dist_t nas_alg_type, uint8_t nas_alg_id, uint8_t memcpy(knas, out + 16, 16); } -void derive_kgnb(uint8_t kamf[32], uint32_t count, uint8_t *kgnb) +static void derive_kgnb(uint8_t kamf[32], uint32_t count, uint8_t *kgnb) { /* Compute the KDF input parameter * S = FC(0x6E) || UL NAS Count || 0x00 0x04 || 0x01 || 0x00 0x01 @@ -444,7 +395,7 @@ void derive_kgnb(uint8_t kamf[32], uint32_t count, uint8_t *kgnb) printf("\n"); } -void derive_ue_keys(uint8_t *buf, nr_ue_nas_t *nas) +static void derive_ue_keys(uint8_t *buf, nr_ue_nas_t *nas) { uint8_t ak[6]; uint8_t sqn[6]; @@ -509,30 +460,22 @@ nr_ue_nas_t *get_ue_nas_info(module_id_t module_id) void generateRegistrationRequest(as_nas_info_t *initialNasMsg, nr_ue_nas_t *nas) { - int size = sizeof(mm_msg_header_t); - fgs_nas_message_t nas_msg = {0}; - MM_msg *mm_msg; + int size = sizeof(fgmm_msg_header_t); + fgmm_nas_message_plain_t plain = {0}; - mm_msg = &nas_msg.plain.mm_msg; - // set header - mm_msg->header.ex_protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; - mm_msg->header.security_header_type = PLAIN_5GS_MSG; - mm_msg->header.message_type = REGISTRATION_REQUEST; + // Plain 5GMM header + plain.header = set_mm_header(FGS_REGISTRATION_REQUEST, PLAIN_5GS_MSG); + size += sizeof(plain.header); - // set registration request - mm_msg->registration_request.protocoldiscriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; - size += 1; - mm_msg->registration_request.securityheadertype = PLAIN_5GS_MSG; - size += 1; - mm_msg->registration_request.messagetype = REGISTRATION_REQUEST; - size += 1; - mm_msg->registration_request.fgsregistrationtype = INITIAL_REGISTRATION; - mm_msg->registration_request.naskeysetidentifier.naskeysetidentifier = 1; + // Plain 5GMM msg + registration_request_msg *mm_msg = &plain.mm_msg.registration_request; + mm_msg->fgsregistrationtype = INITIAL_REGISTRATION; + mm_msg->naskeysetidentifier.naskeysetidentifier = 1; size += 1; if (nas->guti) { - size += fill_guti(&mm_msg->registration_request.fgsmobileidentity, nas->guti); + size += fill_guti(&mm_msg->fgsmobileidentity, nas->guti); } else { - size += fill_suci(&mm_msg->registration_request.fgsmobileidentity, nas->uicc); + size += fill_suci(&mm_msg->fgsmobileidentity, nas->uicc); } #if 0 @@ -547,20 +490,20 @@ void generateRegistrationRequest(as_nas_info_t *initialNasMsg, nr_ue_nas_t *nas) size += 3; #endif - mm_msg->registration_request.presencemask |= REGISTRATION_REQUEST_UE_SECURITY_CAPABILITY_PRESENT; - mm_msg->registration_request.nruesecuritycapability.iei = REGISTRATION_REQUEST_UE_SECURITY_CAPABILITY_IEI; - mm_msg->registration_request.nruesecuritycapability.length = 8; - mm_msg->registration_request.nruesecuritycapability.fg_EA = 0xe0; - mm_msg->registration_request.nruesecuritycapability.fg_IA = 0x60; - mm_msg->registration_request.nruesecuritycapability.EEA = 0; - mm_msg->registration_request.nruesecuritycapability.EIA = 0; + mm_msg->presencemask |= REGISTRATION_REQUEST_UE_SECURITY_CAPABILITY_PRESENT; + mm_msg->nruesecuritycapability.iei = REGISTRATION_REQUEST_UE_SECURITY_CAPABILITY_IEI; + mm_msg->nruesecuritycapability.length = 8; + mm_msg->nruesecuritycapability.fg_EA = 0xe0; + mm_msg->nruesecuritycapability.fg_IA = 0x60; + mm_msg->nruesecuritycapability.EEA = 0; + mm_msg->nruesecuritycapability.EIA = 0; size += 10; // encode the message - initialNasMsg->nas_data = malloc16_clear(size * sizeof(Byte_t)); + initialNasMsg->nas_data = malloc16_clear(size * sizeof(*initialNasMsg->nas_data)); nas->registration_request_buf = initialNasMsg->nas_data; - initialNasMsg->length = mm_msg_encode(mm_msg, initialNasMsg->nas_data, size); + initialNasMsg->length = mm_msg_encode(&plain, initialNasMsg->nas_data, size); nas->registration_request_len = initialNasMsg->length; } @@ -568,47 +511,45 @@ void generateServiceRequest(as_nas_info_t *initialNasMsg, nr_ue_nas_t *nas) { LOG_I(NAS, "Generate initial NAS message: Service Request\n"); int size = 0; - fgs_nas_message_t nas_msg = {0}; - memset(&nas_msg, 0, sizeof(nas_msg)); + // NAS is security protected if has valid security contexts bool security_protected = nas->security_container->ciphering_context && nas->security_container->integrity_context; - MM_msg *mm_msg; - if (security_protected) { - /* Set security protected 5GS NAS message header (see 9.1.1 of 3GPP TS 24.501) */ - nas_msg.header.protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; - nas_msg.header.security_header_type = INTEGRITY_PROTECTED; - nas_msg.header.sequence_number = nas->security.nas_count_ul & 0xff; - size += sizeof(fgs_nas_message_security_header_t); - mm_msg = &nas_msg.security_protected.plain.mm_msg; - } else { - // Set Mobility Management plain message header - mm_msg = &nas_msg.plain.mm_msg; - } - // Fill MM plain message header - mm_msg->header.ex_protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; - mm_msg->header.security_header_type = PLAIN_5GS_MSG; - mm_msg->header.message_type = FGS_SERVICE_REQUEST; - size += sizeof(mm_msg_header_t); - - // Fill Service Request + // Set 5GMM plain header + fgmm_nas_message_plain_t plain = {0}; + plain.header = set_mm_header(FGS_SERVICE_REQUEST, PLAIN_5GS_MSG); + size += sizeof(plain.header); + // Set plain FGMM Service Request + fgs_service_request_msg_t *mm_msg = &plain.mm_msg.service_request; // Service Type - mm_msg->service_request.serviceType = SERVICE_TYPE_DATA; + mm_msg->serviceType = SERVICE_TYPE_DATA; // NAS key set identifier - mm_msg->service_request.naskeysetidentifier.naskeysetidentifier = NAS_KEY_SET_IDENTIFIER_NOT_AVAILABLE; - mm_msg->service_request.naskeysetidentifier.tsc = NAS_KEY_SET_IDENTIFIER_NATIVE; + mm_msg->naskeysetidentifier.naskeysetidentifier = NAS_KEY_SET_IDENTIFIER_NOT_AVAILABLE; + mm_msg->naskeysetidentifier.tsc = NAS_KEY_SET_IDENTIFIER_NATIVE; size += 1; // 5G-S-TMSI - size += fill_fgstmsi(&mm_msg->service_request.fiveg_s_tmsi, nas->guti); + size += fill_fgstmsi(&mm_msg->fiveg_s_tmsi, nas->guti); - /* message encoding */ - initialNasMsg->nas_data = (Byte_t *)malloc(size * sizeof(Byte_t)); if (security_protected) { + fgmm_nas_msg_security_protected_t sp = {0}; + + // Set security protected 5GS NAS message header (see 9.1.1 of 3GPP TS 24.501) + sp.header.protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; + sp.header.security_header_type = INTEGRITY_PROTECTED; + sp.header.sequence_number = nas->security.nas_count_ul & 0xff; + size += sizeof(sp.header); + + // Payload: plain message + sp.plain = plain; + + // Allocate NAS message for encoding + initialNasMsg->nas_data = malloc_or_fail(size * sizeof(*initialNasMsg->nas_data)); + // security protected encoding - int security_header_len = nas_protected_security_header_encode((char *)(initialNasMsg->nas_data), &(nas_msg.header), size); + int security_header_len = nas_protected_security_header_encode(initialNasMsg->nas_data, &sp.header, size); initialNasMsg->length = security_header_len - + mm_msg_encode(mm_msg, (uint8_t *)(initialNasMsg->nas_data + security_header_len), size - security_header_len); + + mm_msg_encode(&sp.plain, (uint8_t *)(initialNasMsg->nas_data + security_header_len), size - security_header_len); /* ciphering */ uint8_t buf[initialNasMsg->length - 7]; nas_stream_cipher_t stream_cipher; @@ -632,44 +573,37 @@ void generateServiceRequest(as_nas_info_t *initialNasMsg, nr_ue_nas_t *nas) /* length in bits */ stream_cipher.blength = (initialNasMsg->length - 6) << 3; stream_compute_integrity(nas->security_container->integrity_algorithm, &stream_cipher, mac); - printf("Integrity protected initial NAS message: mac = %x %x %x %x \n", mac[0], mac[1], mac[2], mac[3]); + LOG_D(NAS, "Integrity protected initial NAS message: mac = %x %x %x %x \n", mac[0], mac[1], mac[2], mac[3]); for (int i = 0; i < 4; i++) initialNasMsg->nas_data[2 + i] = mac[i]; } else { // plain encoding - initialNasMsg->length = mm_msg_encode(mm_msg, (uint8_t *)(initialNasMsg->nas_data), size); + // Allocate NAS message for encoding + initialNasMsg->nas_data = malloc_or_fail(size * sizeof(*initialNasMsg->nas_data)); + initialNasMsg->length = mm_msg_encode(&plain, initialNasMsg->nas_data, size); LOG_I(NAS, "PLAIN_5GS_MSG initial NAS message: Service Request with length %d \n", initialNasMsg->length); } } void generateIdentityResponse(as_nas_info_t *initialNasMsg, uint8_t identitytype, uicc_t *uicc) { - int size = sizeof(mm_msg_header_t); - fgs_nas_message_t nas_msg; - memset(&nas_msg, 0, sizeof(fgs_nas_message_t)); - MM_msg *mm_msg; + int size = sizeof(fgmm_msg_header_t); + fgmm_nas_message_plain_t plain = {0}; - mm_msg = &nas_msg.plain.mm_msg; - // set header - mm_msg->header.ex_protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; - mm_msg->header.security_header_type = PLAIN_5GS_MSG; - mm_msg->header.message_type = FGS_IDENTITY_RESPONSE; + // Plain 5GMM header + plain.header = set_mm_header(FGS_IDENTITY_RESPONSE, PLAIN_5GS_MSG); + size += sizeof(plain.header); // set identity response - mm_msg->fgs_identity_response.protocoldiscriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; - size += 1; - mm_msg->fgs_identity_response.securityheadertype = PLAIN_5GS_MSG; - size += 1; - mm_msg->fgs_identity_response.messagetype = FGS_IDENTITY_RESPONSE; - size += 1; + fgmm_identity_response_msg *mm_msg = &plain.mm_msg.fgs_identity_response; if (identitytype == FGS_MOBILE_IDENTITY_SUCI) { - size += fill_suci(&mm_msg->fgs_identity_response.fgsmobileidentity, uicc); + size += fill_suci(&mm_msg->fgsmobileidentity, uicc); } // encode the message - initialNasMsg->nas_data = malloc(size * sizeof(Byte_t)); + initialNasMsg->nas_data = malloc_or_fail(size * sizeof(*initialNasMsg->nas_data)); - initialNasMsg->length = mm_msg_encode(mm_msg, initialNasMsg->nas_data, size); + initialNasMsg->length = mm_msg_encode(&plain, initialNasMsg->nas_data, size); } static void generateAuthenticationResp(nr_ue_nas_t *nas, as_nas_info_t *initialNasMsg, uint8_t *buf) @@ -680,32 +614,21 @@ static void generateAuthenticationResp(nr_ue_nas_t *nas, as_nas_info_t *initialN res.value = calloc(1, 16); memcpy(res.value, nas->security.res, 16); - int size = sizeof(mm_msg_header_t); - fgs_nas_message_t nas_msg; - memset(&nas_msg, 0, sizeof(fgs_nas_message_t)); - MM_msg *mm_msg; + int size = sizeof(fgmm_msg_header_t); + fgmm_nas_message_plain_t plain = {0}; - mm_msg = &nas_msg.plain.mm_msg; - // set header - mm_msg->header.ex_protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; - mm_msg->header.security_header_type = PLAIN_5GS_MSG; - mm_msg->header.message_type = FGS_AUTHENTICATION_RESPONSE; - - // set authentication response - mm_msg->fgs_identity_response.protocoldiscriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; - size += 1; - mm_msg->fgs_identity_response.securityheadertype = PLAIN_5GS_MSG; - size += 1; - mm_msg->fgs_identity_response.messagetype = FGS_AUTHENTICATION_RESPONSE; - size += 1; + // Plain 5GMM header + plain.header = set_mm_header(FGS_AUTHENTICATION_RESPONSE, PLAIN_5GS_MSG); + size += sizeof(plain.header); // set response parameter - mm_msg->fgs_auth_response.authenticationresponseparameter.res = res; + fgs_authentication_response_msg *mm_msg = &plain.mm_msg.fgs_auth_response; + mm_msg->authenticationresponseparameter.res = res; size += 18; // encode the message - initialNasMsg->nas_data = malloc(size * sizeof(Byte_t)); + initialNasMsg->nas_data = malloc_or_fail(size * sizeof(*initialNasMsg->nas_data)); - initialNasMsg->length = mm_msg_encode(mm_msg, initialNasMsg->nas_data, size); + initialNasMsg->length = mm_msg_encode(&plain, initialNasMsg->nas_data, size); // Free res value after encode free(res.value); } @@ -720,48 +643,40 @@ int nas_itti_kgnb_refresh_req(instance_t instance, const uint8_t kgnb[32]) static void generateSecurityModeComplete(nr_ue_nas_t *nas, as_nas_info_t *initialNasMsg) { - int size = sizeof(mm_msg_header_t); - fgs_nas_message_t nas_msg; - memset(&nas_msg, 0, sizeof(fgs_nas_message_t)); - - MM_msg *mm_msg; + int size = sizeof(fgmm_msg_header_t); + fgmm_nas_msg_security_protected_t nas_msg = {0}; nas_stream_cipher_t stream_cipher; - uint8_t mac[4]; + uint8_t mac[NAS_INTEGRITY_SIZE]; // set security protected header - nas_msg.header.protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; - nas_msg.header.security_header_type = INTEGRITY_PROTECTED_AND_CIPHERED_WITH_NEW_SECU_CTX; - nas_msg.header.sequence_number = nas->security.nas_count_ul & 0xff; + fgs_nas_message_security_header_t *sp = &nas_msg.header; + sp->protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; + sp->security_header_type = INTEGRITY_PROTECTED_AND_CIPHERED_WITH_NEW_SECU_CTX; + sp->sequence_number = nas->security.nas_count_ul & 0xff; size += 7; - mm_msg = &nas_msg.security_protected.plain.mm_msg; + // Plain 5GMM Security Mode Complete msg + fgmm_nas_message_plain_t *plain = &nas_msg.plain; - // set header - mm_msg->header.ex_protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; - mm_msg->header.security_header_type = PLAIN_5GS_MSG; - mm_msg->header.message_type = FGS_SECURITY_MODE_COMPLETE; + // Plain 5GMM header + plain->header = set_mm_header(FGS_SECURITY_MODE_COMPLETE, PLAIN_5GS_MSG); + size += sizeof(plain->header); - // set security mode complete - mm_msg->fgs_security_mode_complete.protocoldiscriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; - size += 1; - mm_msg->fgs_security_mode_complete.securityheadertype = PLAIN_5GS_MSG; - size += 1; - mm_msg->fgs_security_mode_complete.messagetype = FGS_SECURITY_MODE_COMPLETE; - size += 1; + // Plain 5GMM payload + fgs_security_mode_complete_msg *mm_msg = &plain->mm_msg.fgs_security_mode_complete; + size += fill_imeisv(&mm_msg->fgsmobileidentity, nas->uicc); - size += fill_imeisv(&mm_msg->fgs_security_mode_complete.fgsmobileidentity, nas->uicc); - - mm_msg->fgs_security_mode_complete.fgsnasmessagecontainer.nasmessagecontainercontents.value = nas->registration_request_buf; - mm_msg->fgs_security_mode_complete.fgsnasmessagecontainer.nasmessagecontainercontents.length = nas->registration_request_len; + mm_msg->fgsnasmessagecontainer.nasmessagecontainercontents.value = nas->registration_request_buf; + mm_msg->fgsnasmessagecontainer.nasmessagecontainercontents.length = nas->registration_request_len; size += (nas->registration_request_len + 2); // encode the message - initialNasMsg->nas_data = malloc(size * sizeof(Byte_t)); + initialNasMsg->nas_data = malloc_or_fail(size * sizeof(*initialNasMsg->nas_data)); - int security_header_len = nas_protected_security_header_encode((char *)(initialNasMsg->nas_data), &(nas_msg.header), size); + int security_header_len = nas_protected_security_header_encode(initialNasMsg->nas_data, sp, size); initialNasMsg->length = security_header_len - + mm_msg_encode(mm_msg, (uint8_t *)(initialNasMsg->nas_data + security_header_len), size - security_header_len); + + mm_msg_encode(plain, (uint8_t *)(initialNasMsg->nas_data + security_header_len), size - security_header_len); /* ciphering */ uint8_t buf[initialNasMsg->length - 7]; @@ -827,89 +742,48 @@ static void handle_security_mode_command(nr_ue_nas_t *nas, as_nas_info_t *initia generateSecurityModeComplete(nas, initialNasMsg); } -static void decodeRegistrationAccept(const uint8_t *buf, int len, nr_ue_nas_t *nas) -{ - registration_accept_msg reg_acc = {0}; - /* it seems there is no 5G corresponding emm_msg_decode() function, so here - * we just jump to the right decision */ - buf += 7; /* skip security header */ - buf += 2; /* skip prot discriminator, security header, half octet */ - AssertFatal(*buf == 0x42, "this is not a NAS Registration Accept\n"); - buf++; - int decoded = decode_registration_accept(®_acc, buf, len); - AssertFatal(decoded > 0, "could not decode registration accept\n"); - if (reg_acc.guti) { - AssertFatal(reg_acc.guti->guti.typeofidentity == FGS_MOBILE_IDENTITY_5G_GUTI, - "registration accept 5GS Mobile Identity is not GUTI, but %d\n", - reg_acc.guti->guti.typeofidentity); - nas->guti = malloc(sizeof(*nas->guti)); - AssertFatal(nas->guti, "out of memory\n"); - *nas->guti = reg_acc.guti->guti; - free(reg_acc.guti); /* no proper memory management for NAS decoded messages */ - } else { - LOG_W(NAS, "no GUTI in registration accept\n"); - } -} - static void generateRegistrationComplete(nr_ue_nas_t *nas, as_nas_info_t *initialNasMsg, SORTransparentContainer *sortransparentcontainer) { int length = 0; - int size = 0; - fgs_nas_message_t nas_msg; nas_stream_cipher_t stream_cipher; - uint8_t mac[4]; - memset(&nas_msg, 0, sizeof(fgs_nas_message_t)); - fgs_nas_message_security_protected_t *sp_msg; + uint8_t mac[NAS_INTEGRITY_SIZE]; + fgmm_nas_msg_security_protected_t sp = {0}; - sp_msg = &nas_msg.security_protected; - // set header - sp_msg->header.protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; - sp_msg->header.security_header_type = INTEGRITY_PROTECTED_AND_CIPHERED; - sp_msg->header.message_authentication_code = 0; - sp_msg->header.sequence_number = nas->security.nas_count_ul & 0xff; + // set security protected header + sp.header.protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; + sp.header.security_header_type = INTEGRITY_PROTECTED_AND_CIPHERED; + sp.header.message_authentication_code = 0; + sp.header.sequence_number = nas->security.nas_count_ul & 0xff; length = 7; - sp_msg->plain.mm_msg.registration_complete.protocoldiscriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; - length += 1; - sp_msg->plain.mm_msg.registration_complete.securityheadertype = PLAIN_5GS_MSG; - sp_msg->plain.mm_msg.registration_complete.sparehalfoctet = 0; - length += 1; - sp_msg->plain.mm_msg.registration_complete.messagetype = REGISTRATION_COMPLETE; - length += 1; + // set plain 5GMM header + sp.plain.header = set_mm_header(FGS_REGISTRATION_COMPLETE, PLAIN_5GS_MSG); + length += sizeof(sp.plain.header); + registration_complete_msg *mm_msg = &sp.plain.mm_msg.registration_complete; if (sortransparentcontainer) { + mm_msg->sortransparentcontainer = sortransparentcontainer; length += sortransparentcontainer->sortransparentcontainercontents.length; } // encode the message - initialNasMsg->nas_data = malloc(length * sizeof(Byte_t)); + initialNasMsg->nas_data = malloc_or_fail(length * sizeof(*initialNasMsg->nas_data)); initialNasMsg->length = length; - - /* Encode the first octet of the header (extended protocol discriminator) */ - ENCODE_U8(initialNasMsg->nas_data + size, sp_msg->header.protocol_discriminator, size); - - /* Encode the security header type */ - ENCODE_U8(initialNasMsg->nas_data + size, sp_msg->header.security_header_type, size); - - /* Encode the message authentication code */ - ENCODE_U32(initialNasMsg->nas_data + size, sp_msg->header.message_authentication_code, size); - - /* Encode the sequence number */ - ENCODE_U8(initialNasMsg->nas_data + size, sp_msg->header.sequence_number, size); - - /* Encode the extended protocol discriminator */ - ENCODE_U8(initialNasMsg->nas_data + size, sp_msg->plain.mm_msg.registration_complete.protocoldiscriminator, size); - - /* Encode the security header type */ - ENCODE_U8(initialNasMsg->nas_data + size, sp_msg->plain.mm_msg.registration_complete.securityheadertype, size); - - /* Encode the message type */ - ENCODE_U8(initialNasMsg->nas_data + size, sp_msg->plain.mm_msg.registration_complete.messagetype, size); - - if (sortransparentcontainer) { - encode_registration_complete(&sp_msg->plain.mm_msg.registration_complete, initialNasMsg->nas_data + size, length - size); + // encode security protected header + int encoded = nas_protected_security_header_encode(initialNasMsg->nas_data, &sp.header, length); + if (encoded < 0) { + LOG_E(NAS, "generateRegistrationComplete: failed to encode security protected header\n"); + return; } + // encode 5GMM plain header + encoded = _nas_mm_msg_encode_header(&sp.plain.header, initialNasMsg->nas_data + encoded, length - encoded); + if (encoded < 0) { + LOG_E(NAS, "generateRegistrationComplete: failed to encode 5GMM plain header\n"); + return; + } + + encode_registration_complete(mm_msg, initialNasMsg->nas_data + encoded, length - encoded); /* ciphering */ uint8_t buf[initialNasMsg->length - 7]; @@ -940,6 +814,121 @@ static void generateRegistrationComplete(nr_ue_nas_t *nas, } } +/** + * @brief Capture IPv4 PDU Session Address + */ +static int capture_ipv4_addr(const uint8_t *addr, char *ip, size_t len) +{ + return snprintf(ip, len, "%d.%d.%d.%d", addr[0], addr[1], addr[2], addr[3]); +} + +/** + * @brief Capture IPv6 PDU Session Address + */ +static int capture_ipv6_addr(const uint8_t *addr, char *ip, size_t len) +{ + // 24.501 Sec 9.11.4.10: "an interface identifier for the IPv6 link local + // address": link local starts with fe80::, and only the last 64bits are + // given (middle is zero) + return snprintf(ip, + len, + "fe80::%02x%02x:%02x%02x:%02x%02x:%02x%02x", + addr[0], + addr[1], + addr[2], + addr[3], + addr[4], + addr[5], + addr[6], + addr[7]); +} + +/** + * @brief Process PDU Session Address in PDU Session Establishment Accept message + * and configure the tun interface + */ +static void process_pdu_session_addr(pdu_session_establishment_accept_msg_t *msg) +{ + uint8_t *addr = msg->pdu_addr_ie.pdu_addr_oct; + + switch (msg->pdu_addr_ie.pdu_type) { + case PDU_SESSION_TYPE_IPV4: { + char ip[20]; + capture_ipv4_addr(&addr[0], ip, sizeof(ip)); + tun_config(1, ip, NULL, "oaitun_ue"); + setup_ue_ipv4_route(1, ip, "oaitun_ue"); + } break; + + case PDU_SESSION_TYPE_IPV6: { + char ipv6[40]; + capture_ipv6_addr(addr, ipv6, sizeof(ipv6)); + tun_config(1, NULL, ipv6, "oaitun_ue"); + } break; + + case PDU_SESSION_TYPE_IPV4V6: { + char ipv6[40]; + capture_ipv6_addr(addr, ipv6, sizeof(ipv6)); + char ipv4[20]; + capture_ipv4_addr(&addr[IPv6_INTERFACE_ID_LENGTH], ipv4, sizeof(ipv4)); + tun_config(1, ipv4, ipv6, "oaitun_ue"); + setup_ue_ipv4_route(1, ipv4, "oaitun_ue"); + } break; + + default: + LOG_E(NAS, "Unknown PDU Session Address type %d\n", msg->pdu_addr_ie.pdu_type); + break; + } +} + +/** + * @brief Handle PDU Session Establishment Accept and process decoded message + */ +static void handle_pdu_session_accept(uint8_t *pdu_buffer, uint32_t msg_length) +{ + pdu_session_establishment_accept_msg_t msg = {0}; + int size = 0; + int decoded = 0; + + // Security protected NAS header (7 bytes) + fgs_nas_message_security_header_t sec_nas_hdr = {0}; + if ((decoded = decode_5gs_security_protected_header(&sec_nas_hdr, pdu_buffer, msg_length)) < 0) { + LOG_E(NAS, "decode_5gs_security_protected_header failure in PDU Session Establishment Accept decoding\n"); + return; + } + size += decoded; + + // decode plain 5GMM message header + fgmm_msg_header_t mm_header = {0}; + if ((decoded = decode_5gmm_msg_header(&mm_header, pdu_buffer + size, msg_length - size)) < 0) { + LOG_E(NAS, "decode_5gmm_msg_header failure in PDU Session Establishment Accept decoding\n"); + return; + } + size += decoded; + + /* Process container (5GSM message) */ + // Payload container type and spare (1 octet) + size++; + // Payload container length + uint16_t iei_len = 0; + GET_SHORT(pdu_buffer + size, iei_len); + size += sizeof(iei_len); + // decode plain 5GSM message header + fgsm_msg_header_t sm_header = {0}; + if ((decoded = decode_5gsm_msg_header(&sm_header, pdu_buffer + size, msg_length - size)) < 0) { + LOG_E(NAS, "decode_5gsm_msg_header failure in PDU Session Establishment Accept decoding\n"); + return; + } + size += decoded; + + // decode PDU Session Establishment Accept + if (!decode_pdu_session_establishment_accept_msg(&msg, pdu_buffer + size, msg_length)) + LOG_E(NAS, "decode_pdu_session_establishment_accept_msg failure\n"); + + // process PDU Session + process_pdu_session_addr(&msg); + set_qfi_pduid(msg.qos_rules.rule->qfi, sm_header.pdu_session_id); +} + /** * @brief Handle DL NAS Transport and process piggybacked 5GSM messages */ @@ -948,7 +937,7 @@ static void handleDownlinkNASTransport(uint8_t *pdu_buffer, uint32_t msg_length) uint8_t msg_type = *(pdu_buffer + 16); if (msg_type == FGS_PDU_SESSION_ESTABLISHMENT_ACC) { LOG_A(NAS, "Received PDU Session Establishment Accept in DL NAS Transport\n"); - capture_pdu_session_establishment_accept_msg(pdu_buffer, msg_length); + handle_pdu_session_accept(pdu_buffer, msg_length); } else { LOG_E(NAS, "Received unexpected message in DLinformationTransfer %d\n", msg_type); } @@ -956,36 +945,34 @@ static void handleDownlinkNASTransport(uint8_t *pdu_buffer, uint32_t msg_length) static void generateDeregistrationRequest(nr_ue_nas_t *nas, as_nas_info_t *initialNasMsg, const nas_deregistration_req_t *req) { - fgs_nas_message_t nas_msg = {0}; - fgs_nas_message_security_protected_t *sp_msg; - sp_msg = &nas_msg.security_protected; - sp_msg->header.protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; - sp_msg->header.security_header_type = INTEGRITY_PROTECTED_AND_CIPHERED; - sp_msg->header.message_authentication_code = 0; - sp_msg->header.sequence_number = nas->security.nas_count_ul & 0xff; - int size = sizeof(fgs_nas_message_security_header_t); + fgmm_nas_msg_security_protected_t sp_msg = {0}; + fgs_nas_message_security_header_t *sp_header = &sp_msg.header; + sp_header->protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; + sp_header->security_header_type = INTEGRITY_PROTECTED_AND_CIPHERED; + sp_header->message_authentication_code = 0; + sp_header->sequence_number = nas->security.nas_count_ul & 0xff; + int size = sizeof(sp_msg.header); - fgs_deregistration_request_ue_originating_msg *dereg_req = &sp_msg->plain.mm_msg.fgs_deregistration_request_ue_originating; - dereg_req->protocoldiscriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; + // Plain 5GMM header + sp_msg.plain.header = set_mm_header(FGS_DEREGISTRATION_REQUEST_UE_ORIGINATING, INTEGRITY_PROTECTED_AND_CIPHERED_WITH_NEW_SECU_CTX); + size += sizeof(sp_msg.plain.header); + + // Plain 5GMM + fgs_deregistration_request_ue_originating_msg *mm_msg = &sp_msg.plain.mm_msg.fgs_deregistration_request_ue_originating; + mm_msg->deregistrationtype.switchoff = NORMAL_DEREGISTRATION; + mm_msg->deregistrationtype.reregistration_required = REREGISTRATION_NOT_REQUIRED; + mm_msg->deregistrationtype.access_type = TGPP_ACCESS; + mm_msg->naskeysetidentifier.naskeysetidentifier = 1; size += 1; - dereg_req->securityheadertype = INTEGRITY_PROTECTED_AND_CIPHERED_WITH_NEW_SECU_CTX; - size += 1; - dereg_req->messagetype = FGS_DEREGISTRATION_REQUEST_UE_ORIGINATING; - size += 1; - dereg_req->deregistrationtype.switchoff = NORMAL_DEREGISTRATION; - dereg_req->deregistrationtype.reregistration_required = REREGISTRATION_NOT_REQUIRED; - dereg_req->deregistrationtype.access_type = TGPP_ACCESS; - dereg_req->naskeysetidentifier.naskeysetidentifier = 1; - size += 1; - size += fill_guti(&dereg_req->fgsmobileidentity, nas->guti); + size += fill_guti(&mm_msg->fgsmobileidentity, nas->guti); // encode the message - initialNasMsg->nas_data = calloc(size, sizeof(Byte_t)); - int security_header_len = nas_protected_security_header_encode((char *)(initialNasMsg->nas_data), &nas_msg.header, size); + initialNasMsg->nas_data = calloc_or_fail(size, sizeof(*initialNasMsg->nas_data)); + int security_header_len = nas_protected_security_header_encode(initialNasMsg->nas_data, sp_header, size); initialNasMsg->length = security_header_len - + mm_msg_encode(&sp_msg->plain.mm_msg, (uint8_t *)(initialNasMsg->nas_data + security_header_len), size - security_header_len); + + mm_msg_encode(&sp_msg.plain, (uint8_t *)(initialNasMsg->nas_data + security_header_len), size - security_header_len); nas_stream_cipher_t stream_cipher; @@ -1010,7 +997,7 @@ static void generateDeregistrationRequest(nr_ue_nas_t *nas, as_nas_info_t *initi stream_cipher.message = (unsigned char *)(initialNasMsg->nas_data + 6); /* length in bits */ stream_cipher.blength = (initialNasMsg->length - 6) << 3; - uint8_t mac[4]; + uint8_t mac[NAS_INTEGRITY_SIZE]; stream_compute_integrity(nas->security_container->integrity_algorithm, &stream_cipher, mac); printf("mac %x %x %x %x \n", mac[0], mac[1], mac[2], mac[3]); @@ -1022,7 +1009,6 @@ static void generateDeregistrationRequest(nr_ue_nas_t *nas, as_nas_info_t *initi static void generatePduSessionEstablishRequest(nr_ue_nas_t *nas, as_nas_info_t *initialNasMsg, nas_pdu_session_req_t *pdu_req) { int size = 0; - fgs_nas_message_t nas_msg = {0}; // setup pdu session establishment request uint16_t req_length = 7; @@ -1036,69 +1022,65 @@ static void generatePduSessionEstablishRequest(nr_ue_nas_t *nas, as_nas_info_t * pdu_session_establish.pdusessiontype = pdu_req->pdusession_type; encode_pdu_session_establishment_request(&pdu_session_establish, req_buffer); - MM_msg *mm_msg; nas_stream_cipher_t stream_cipher; - uint8_t mac[4]; - nas_msg.header.protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; - nas_msg.header.security_header_type = INTEGRITY_PROTECTED_AND_CIPHERED; - nas_msg.header.sequence_number = nas->security.nas_count_ul & 0xff; + uint8_t mac[NAS_INTEGRITY_SIZE]; + + // 5GMM security protected message + fgmm_nas_msg_security_protected_t sp_msg = {0}; + // 5GMM security protected message header + fgs_nas_message_security_header_t *sp_header = &sp_msg.header; + sp_header->protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; + sp_header->security_header_type = INTEGRITY_PROTECTED_AND_CIPHERED; + sp_header->sequence_number = nas->security.nas_count_ul & 0xff; size += 7; - mm_msg = &nas_msg.security_protected.plain.mm_msg; + fgmm_nas_message_plain_t *plain = &sp_msg.plain; - // set header - mm_msg->header.ex_protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; - mm_msg->header.security_header_type = PLAIN_5GS_MSG; - mm_msg->header.message_type = FGS_UPLINK_NAS_TRANSPORT; + // Plain 5GMM header + plain->header = set_mm_header(FGS_UPLINK_NAS_TRANSPORT, PLAIN_5GS_MSG); + size += sizeof(plain->header); - // set uplink nas transport - mm_msg->uplink_nas_transport.protocoldiscriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; + fgs_uplink_nas_transport_msg *mm_msg = &plain->mm_msg.uplink_nas_transport; + mm_msg->payloadcontainertype.iei = 0; + mm_msg->payloadcontainertype.type = 1; size += 1; - mm_msg->uplink_nas_transport.securityheadertype = PLAIN_5GS_MSG; - size += 1; - mm_msg->uplink_nas_transport.messagetype = FGS_UPLINK_NAS_TRANSPORT; - size += 1; - - mm_msg->uplink_nas_transport.payloadcontainertype.iei = 0; - mm_msg->uplink_nas_transport.payloadcontainertype.type = 1; - size += 1; - mm_msg->uplink_nas_transport.fgspayloadcontainer.payloadcontainercontents.length = req_length; - mm_msg->uplink_nas_transport.fgspayloadcontainer.payloadcontainercontents.value = req_buffer; + mm_msg->fgspayloadcontainer.payloadcontainercontents.length = req_length; + mm_msg->fgspayloadcontainer.payloadcontainercontents.value = req_buffer; size += (2 + req_length); - mm_msg->uplink_nas_transport.pdusessionid = pdu_req->pdusession_id; - mm_msg->uplink_nas_transport.requesttype = 1; + mm_msg->pdusessionid = pdu_req->pdusession_id; + mm_msg->requesttype = 1; size += 3; const bool has_nssai_sd = pdu_req->sd != 0xffffff; // 0xffffff means "no SD", TS 23.003 const size_t nssai_len = has_nssai_sd ? 4 : 1; - mm_msg->uplink_nas_transport.snssai.length = nssai_len; + mm_msg->snssai.length = nssai_len; // Fixme: it seems there are a lot of memory errors in this: this value was on the stack, // but pushed in a itti message to another thread // this kind of error seems in many places in 5G NAS - mm_msg->uplink_nas_transport.snssai.value = calloc(1, nssai_len); - mm_msg->uplink_nas_transport.snssai.value[0] = pdu_req->sst; + mm_msg->snssai.value = calloc(1, nssai_len); + mm_msg->snssai.value[0] = pdu_req->sst; if (has_nssai_sd) - INT24_TO_BUFFER(pdu_req->sd, &mm_msg->uplink_nas_transport.snssai.value[1]); + INT24_TO_BUFFER(pdu_req->sd, &mm_msg->snssai.value[1]); size += 1 + 1 + nssai_len; int dnnSize = strlen(nas->uicc->dnnStr); - mm_msg->uplink_nas_transport.dnn.value = calloc(1, dnnSize + 1); - mm_msg->uplink_nas_transport.dnn.length = dnnSize + 1; - mm_msg->uplink_nas_transport.dnn.value[0] = dnnSize; - memcpy(mm_msg->uplink_nas_transport.dnn.value + 1, nas->uicc->dnnStr, dnnSize); + mm_msg->dnn.value = calloc(1, dnnSize + 1); + mm_msg->dnn.length = dnnSize + 1; + mm_msg->dnn.value[0] = dnnSize; + memcpy(mm_msg->dnn.value + 1, nas->uicc->dnnStr, dnnSize); size += (1 + 1 + dnnSize + 1); // encode the message - initialNasMsg->nas_data = (Byte_t *)malloc(size * sizeof(Byte_t)); - int security_header_len = nas_protected_security_header_encode((char *)(initialNasMsg->nas_data), &(nas_msg.header), size); + initialNasMsg->nas_data = malloc_or_fail(size * sizeof(*initialNasMsg->nas_data)); + int security_header_len = nas_protected_security_header_encode(initialNasMsg->nas_data, sp_header, size); initialNasMsg->length = security_header_len - + mm_msg_encode(mm_msg, (uint8_t *)(initialNasMsg->nas_data + security_header_len), size - security_header_len); + + mm_msg_encode(plain, (uint8_t *)(initialNasMsg->nas_data + security_header_len), size - security_header_len); // Free allocated memory after encode free(req_buffer); - free(mm_msg->uplink_nas_transport.dnn.value); - free(mm_msg->uplink_nas_transport.snssai.value); + free(mm_msg->dnn.value); + free(mm_msg->snssai.value); /* ciphering */ uint8_t buf[initialNasMsg->length - 7]; @@ -1184,109 +1166,13 @@ static void send_nas_detach_req(nr_ue_nas_t *nas, bool wait_release) itti_send_msg_to_task(TASK_RRC_NRUE, nas->UE_id, msg); } -static void parse_allowed_nssai(nr_nas_msg_snssai_t nssaiList[8], const uint8_t *buf, const uint32_t len) -{ - int nssai_cnt = 0; - const uint8_t *end = buf + len; - while (buf < end) { - const int length = *buf++; - nr_nas_msg_snssai_t *nssai = nssaiList + nssai_cnt; - nssai->sd = 0xffffff; - - switch (length) { - case 1: - nssai->sst = *buf++; - nssai_cnt++; - break; - - case 2: - nssai->sst = *buf++; - nssai->hplmn_sst = *buf++; - nssai_cnt++; - break; - - case 4: - nssai->sst = *buf++; - nssai->sd = 0xffffff & ntoh_int24_buf(buf); - buf += 3; - nssai_cnt++; - break; - - case 5: - nssai->sst = *buf++; - nssai->sd = 0xffffff & ntoh_int24_buf(buf); - buf += 3; - nssai->hplmn_sst = *buf++; - nssai_cnt++; - break; - - case 8: - nssai->sst = *buf++; - nssai->sd = 0xffffff & ntoh_int24_buf(buf); - buf += 3; - nssai->hplmn_sst = *buf++; - nssai->hplmn_sd = 0xffffff & ntoh_int24_buf(buf); - buf += 3; - nssai_cnt++; - break; - - default: - LOG_E(NAS, "UE received unknown length in an allowed S-NSSAI\n"); - break; - } - } -} - -/* Extract Allowed NSSAI from Regestration Accept according to - 3GPP TS 24.501 Table 8.2.7.1.1 -*/ -static void get_allowed_nssai(nr_nas_msg_snssai_t nssai[8], const uint8_t *pdu_buffer, const uint32_t pdu_length) -{ - if ((pdu_buffer == NULL) || (pdu_length <= 0)) - return; - - const uint8_t *end = pdu_buffer + pdu_length; - if (((nas_msg_header_t *)(pdu_buffer))->choice.security_protected_nas_msg_header_t.security_header_type > 0) { - pdu_buffer += SECURITY_PROTECTED_5GS_NAS_MESSAGE_HEADER_LENGTH; - } - - pdu_buffer += 1 + 1 + 1 + 2; // Mandatory fields offset - /* optional fields */ - while (pdu_buffer < end) { - const int type = *pdu_buffer++; - int length = 0; - switch (type) { - case 0x77: // 5GS mobile identity - pdu_buffer += ntoh_int16_buf(pdu_buffer) + sizeof(uint16_t); - break; - - case 0x4A: // PLMN list - case 0x54: // 5GS tracking area identity - pdu_buffer += *pdu_buffer + 1; // offset length + 1 byte which contains the length - break; - - case 0x15: // allowed NSSAI - length = *pdu_buffer++; - parse_allowed_nssai(nssai, pdu_buffer, length); - pdu_buffer += length; - break; - - default: - LOG_W(NAS, "This NAS IEI (0x%2.2x) is not handled when extracting list of allowed NSSAI\n", type); - length = *pdu_buffer++; - pdu_buffer += length; - break; - } - } -} - -static void request_default_pdusession(nr_ue_nas_t *nas, int nssai_idx) +static void request_default_pdusession(nr_ue_nas_t *nas) { MessageDef *message_p = itti_alloc_new_message(TASK_NAS_NRUE, nas->UE_id, NAS_PDU_SESSION_REQ); NAS_PDU_SESSION_REQ(message_p).pdusession_id = 10; /* first or default pdu session */ NAS_PDU_SESSION_REQ(message_p).pdusession_type = 0x91; // 0x91 = IPv4, 0x92 = IPv6, 0x93 = IPv4v6 - NAS_PDU_SESSION_REQ(message_p).sst = nas_allowed_nssai[nssai_idx].sst; - NAS_PDU_SESSION_REQ(message_p).sd = nas_allowed_nssai[nssai_idx].sd; + NAS_PDU_SESSION_REQ(message_p).sst = nas->uicc->nssai_sst; + NAS_PDU_SESSION_REQ(message_p).sd = nas->uicc->nssai_sd; itti_send_msg_to_task(TASK_NAS_NRUE, nas->UE_id, message_p); } @@ -1307,11 +1193,52 @@ void *nas_nrue_task(void *args_p) } } +static void process_guti(Guti5GSMobileIdentity_t *guti, nr_ue_nas_t *nas) +{ + AssertFatal(guti->typeofidentity == FGS_MOBILE_IDENTITY_5G_GUTI, + "registration accept 5GS Mobile Identity is not GUTI, but %d\n", + guti->typeofidentity); + nas->guti = malloc_or_fail(sizeof(*nas->guti)); + *nas->guti = *guti; +} + static void handle_registration_accept(nr_ue_nas_t *nas, const uint8_t *pdu_buffer, uint32_t msg_length) { LOG_I(NAS, "[UE] Received REGISTRATION ACCEPT message\n"); - decodeRegistrationAccept(pdu_buffer, msg_length, nas); - get_allowed_nssai(nas_allowed_nssai, pdu_buffer, msg_length); + registration_accept_msg msg = {0}; + fgs_nas_message_security_header_t sp_header = {0}; + const uint8_t *end = pdu_buffer + msg_length; + // security protected header + int decoded = decode_5gs_security_protected_header(&sp_header, pdu_buffer, msg_length); + if (!decoded) { + LOG_E(NAS, "NAS Registration Accept: failed to decode security protected header\n"); + return; + } + pdu_buffer += decoded; + // plain header + fgmm_msg_header_t mm_header = {0}; + if ((decoded = decode_5gmm_msg_header(&mm_header, pdu_buffer, end - pdu_buffer)) < 0) { + LOG_E(NAS, "Failed to decode NAS Registration Accept\n"); + return; + } + if (mm_header.message_type != FGS_REGISTRATION_ACCEPT) { + LOG_E(NAS, "Failed to process NAS Registration Accept: wrong message type\n"); + return; + } + pdu_buffer += decoded; + // plain payload + if ((decoded = decode_registration_accept(&msg, pdu_buffer, end - pdu_buffer)) < 0) { + LOG_E(NAS, "Failed to decode NAS Registration Accept\n"); + return; + } + pdu_buffer += decoded; + // process GUTI + if (msg.guti) { + process_guti(&msg.guti->guti, nas); + free(msg.guti); + } else { + LOG_W(NAS, "no GUTI in registration accept\n"); + } as_nas_info_t initialNasMsg = {0}; generateRegistrationComplete(nas, &initialNasMsg, NULL); @@ -1319,11 +1246,10 @@ static void handle_registration_accept(nr_ue_nas_t *nas, const uint8_t *pdu_buff send_nas_uplink_data_req(nas, &initialNasMsg); LOG_I(NAS, "Send NAS_UPLINK_DATA_REQ message(RegistrationComplete)\n"); } - const int nssai_idx = get_user_nssai_idx(nas_allowed_nssai, nas); - if (nssai_idx < 0) { + if (get_user_nssai_idx(msg.nas_allowed_nssai, nas) < 0) { LOG_E(NAS, "NSSAI parameters not match with allowed NSSAI. Couldn't request PDU session.\n"); } else { - request_default_pdusession(nas, nssai_idx); + request_default_pdusession(nas); } } @@ -1404,16 +1330,16 @@ void *nas_nrue(void *args_p) security_state_t security_state = nas_security_rx_process(nas, pdu_buffer, pdu_length); if (security_state != NAS_SECURITY_INTEGRITY_PASSED && security_state != NAS_SECURITY_NO_SECURITY_CONTEXT) { - LOG_E(NAS, "NAS integrity failed, discard incoming message\n"); + LOG_E(NAS, "NAS integrity failed, discard incoming message: security state is %s\n", security_state_info[security_state].text); break; } int msg_type = get_msg_type(pdu_buffer, pdu_length); - if (msg_type == REGISTRATION_ACCEPT) { + if (msg_type == FGS_REGISTRATION_ACCEPT) { handle_registration_accept(nas, pdu_buffer, pdu_length); } else if (msg_type == FGS_PDU_SESSION_ESTABLISHMENT_ACC) { - capture_pdu_session_establishment_accept_msg(pdu_buffer, pdu_length); + handle_pdu_session_accept(pdu_buffer, pdu_length); } // Free NAS buffer memory after use (coming from RRC) @@ -1473,12 +1399,12 @@ void *nas_nrue(void *args_p) uint8_t *pdu_buffer = NAS_DOWNLINK_DATA_IND(msg_p).nasMsg.nas_data; int pdu_length = NAS_DOWNLINK_DATA_IND(msg_p).nasMsg.length; + int msg_type = get_msg_type(pdu_buffer, pdu_length); security_state_t security_state = nas_security_rx_process(nas, pdu_buffer, pdu_length); /* special cases accepted without protection */ if (security_state == NAS_SECURITY_UNPROTECTED) { - int msg_type = get_msg_type(pdu_buffer, pdu_length); - /* for the moment, only FGS_DEREGISTRATION_ACCEPT is accepted */ + /* for the moment, only FGS_DEREGISTRATION_ACCEPT_UE_ORIGINATING is accepted */ if (msg_type == FGS_DEREGISTRATION_ACCEPT_UE_ORIGINATING) security_state = NAS_SECURITY_INTEGRITY_PASSED; } @@ -1488,8 +1414,6 @@ void *nas_nrue(void *args_p) break; } - int msg_type = get_msg_type(pdu_buffer, pdu_length); - switch (msg_type) { case FGS_IDENTITY_REQUEST: generateIdentityResponse(&initialNasMsg, *(pdu_buffer + 3), nas->uicc); @@ -1503,19 +1427,19 @@ void *nas_nrue(void *args_p) case FGS_DOWNLINK_NAS_TRANSPORT: handleDownlinkNASTransport(pdu_buffer, pdu_length); break; - case REGISTRATION_ACCEPT: + case FGS_REGISTRATION_ACCEPT: handle_registration_accept(nas, pdu_buffer, pdu_length); break; case FGS_DEREGISTRATION_ACCEPT_UE_ORIGINATING: LOG_I(NAS, "received deregistration accept\n"); break; case FGS_PDU_SESSION_ESTABLISHMENT_ACC: - capture_pdu_session_establishment_accept_msg(pdu_buffer, pdu_length); + handle_pdu_session_accept(pdu_buffer, pdu_length); break; case FGS_PDU_SESSION_ESTABLISHMENT_REJ: LOG_E(NAS, "Received PDU Session Establishment reject\n"); break; - case REGISTRATION_REJECT: + case FGS_REGISTRATION_REJECT: LOG_E(NAS, "Received Registration reject cause: %s\n", cause_text_info[pdu_buffer[17]].text); exit(1); break; diff --git a/openair3/NAS/NR_UE/nr_nas_msg.h b/openair3/NAS/NR_UE/nr_nas_msg.h index 0e324052ad..b4a97a36d7 100644 --- a/openair3/NAS/NR_UE/nr_nas_msg.h +++ b/openair3/NAS/NR_UE/nr_nas_msg.h @@ -23,6 +23,7 @@ * \brief simulator for nr nas message * \author Yoshio INOUE, Masayuki HARADA * \email yoshio.inoue@fujitsu.com,masayuki.harada@fujitsu.com + * \protocol 5GS (5GMM and 5GSM) * \date 2020 * \version 0.1 */ @@ -30,17 +31,14 @@ #ifndef __NR_NAS_MSG_SIM_H__ #define __NR_NAS_MSG_SIM_H__ -#include "RegistrationRequest.h" -#include "FGSIdentityResponse.h" -#include "FGSAuthenticationResponse.h" -#include "FGSNASSecurityModeComplete.h" -#include "FGSDeregistrationRequestUEOriginating.h" -#include "RegistrationComplete.h" -#include "EMM/MSG/fgs_service_request.h" -#include "as_message.h" -#include "FGSUplinkNasTransport.h" +#include #include +#include +#include +#include "as_message.h" +#include "NR_NAS_defs.h" #include "secu_defs.h" +#include "NR_NAS_defs.h" #define INITIAL_REGISTRATION 0b001 @@ -48,18 +46,11 @@ #define SECURITY_PROTECTED_5GS_NAS_MESSAGE_HEADER_LENGTH 7 #define PAYLOAD_CONTAINER_LENGTH_MIN 3 #define PAYLOAD_CONTAINER_LENGTH_MAX 65537 +#define NAS_INTEGRITY_SIZE 4 /* 3GPP TS 24.501: 9.11.3.50 Service type */ #define SERVICE_TYPE_DATA 0x1 -/* List of allowed NSSAI from NAS messaging. */ -typedef struct { - int sst; - int hplmn_sst; - int sd; - int hplmn_sd; -} nr_nas_msg_snssai_t; - /* Security Key for SA UE */ typedef struct { uint8_t kausf[32]; @@ -85,82 +76,6 @@ typedef struct { instance_t UE_id; } nr_ue_nas_t; -typedef enum fgs_protocol_discriminator_e { - /* Protocol discriminator identifier for 5GS Mobility Management */ - FGS_MOBILITY_MANAGEMENT_MESSAGE = 0x7E, - - /* Protocol discriminator identifier for 5GS Session Management */ - FGS_SESSION_MANAGEMENT_MESSAGE = 0x2E, -} fgs_protocol_discriminator_t; - -typedef struct { - uint8_t ex_protocol_discriminator; - uint8_t security_header_type; - uint8_t message_type; -} mm_msg_header_t; - -/* Structure of security protected header */ -typedef struct { - fgs_protocol_discriminator_t protocol_discriminator; - uint8_t security_header_type; - uint32_t message_authentication_code; - uint8_t sequence_number; -} fgs_nas_message_security_header_t; - -typedef union { - mm_msg_header_t header; - registration_request_msg registration_request; - fgs_service_request_msg_t service_request; - fgs_identiy_response_msg fgs_identity_response; - fgs_authentication_response_msg fgs_auth_response; - fgs_deregistration_request_ue_originating_msg fgs_deregistration_request_ue_originating; - fgs_security_mode_complete_msg fgs_security_mode_complete; - registration_complete_msg registration_complete; - fgs_uplink_nas_transport_msg uplink_nas_transport; -} MM_msg; - -typedef struct { - MM_msg mm_msg; /* 5GS Mobility Management messages */ -} fgs_nas_message_plain_t; - -typedef struct { - fgs_nas_message_security_header_t header; - fgs_nas_message_plain_t plain; -} fgs_nas_message_security_protected_t; - -typedef union { - fgs_nas_message_security_header_t header; - fgs_nas_message_security_protected_t security_protected; - fgs_nas_message_plain_t plain; -} fgs_nas_message_t; - -typedef struct { - union { - mm_msg_header_t plain_nas_msg_header; - struct security_protected_nas_msg_header_s { - uint8_t ex_protocol_discriminator; - uint8_t security_header_type; - uint16_t message_authentication_code1; - uint16_t message_authentication_code2; - uint8_t sequence_number; - } security_protected_nas_msg_header_t; - } choice; -} nas_msg_header_t; - -typedef struct { - uint8_t ex_protocol_discriminator; - uint8_t pdu_session_id; - uint8_t PTI; - uint8_t message_type; -} fgs_sm_nas_msg_header_t; - -typedef struct { - mm_msg_header_t plain_nas_msg_header; - uint8_t payload_container_type; - uint16_t payload_container_length; - fgs_sm_nas_msg_header_t sm_nas_msg_header; -} dl_nas_transport_t; - nr_ue_nas_t *get_ue_nas_info(module_id_t module_id); void generateRegistrationRequest(as_nas_info_t *initialNasMsg, nr_ue_nas_t *nas); void generateServiceRequest(as_nas_info_t *initialNasMsg, nr_ue_nas_t *nas); diff --git a/openair3/NAS/TEST/AS_SIMULATOR/as_process.c b/openair3/NAS/TEST/AS_SIMULATOR/as_process.c index 20b7a7ce35..740c67b1e0 100644 --- a/openair3/NAS/TEST/AS_SIMULATOR/as_process.c +++ b/openair3/NAS/TEST/AS_SIMULATOR/as_process.c @@ -137,11 +137,6 @@ int process_nas_establish_req(int msg_id, const nas_establish_req_t* req, printf("INFO\t: %s - Process NAS signalling connection establishment " "request\n", __FUNCTION__); - // Attach_Request.Pdn_Connectivity_Request.ebi = 5 - //req->initialNasMsg.data[23] = 0x52; // MME DEBUG (Reject Attachment) - // Attach_Request.Pdn_Connectivity_Request.messagetype = WRONG_MESSAGE_TYPE - //req->initialNasMsg.data[25] = 0xc4; // MME DEBUG (Send ESM status) - snprintf(_mscgen_buffer, MSCGEN_BUFFER_SIZE, "cause = %s, type = %s, tmsi = {MMEcode = %d, m_tmsi = %u}%c", rrcCause(req->cause), rrcType(req->type), @@ -173,7 +168,7 @@ int process_nas_establish_req(int msg_id, const nas_establish_req_t* req, ind->tac = DEFAULT_TAC; if (req->initialNasMsg.length > 0) { - ind->initialNasMsg.data = (Byte_t*)malloc(req->initialNasMsg.length); + ind->initialNasMsg.data = malloc(req->initialNasMsg.length); if (ind->initialNasMsg.data) { memcpy(ind->initialNasMsg.data, req->initialNasMsg.data, @@ -212,15 +207,6 @@ int process_ul_info_transfer_req(int msg_id, const ul_info_transfer_req_t* req, printf("INFO\t: %s - Process uplink data transfer request\n", __FUNCTION__); - // Attach_Complete.Activate_Default_EPS_Bearer_Context_Accept.ebi = UNASSIGNED - //if (req->nasMsg.data[7] == 0x43) { - // req->nasMsg.data[10] = 0x02; // MME DEBUG (Send ESM status) - //} - // Deactivate_EPS_Bearer_Context_Accept.ebi = UNASSIGNED - //if (req->nasMsg.data[8] == 0xCE) { - // req->nasMsg.data[6] = 0x02; // MME DEBUG (Discard ESM message) - //} - snprintf(_mscgen_buffer, MSCGEN_BUFFER_SIZE, "tmsi = {MMEcode = %d, m_tmsi = %u}%c", req->s_tmsi.MMEcode, req->s_tmsi.m_tmsi, '\0'); @@ -250,7 +236,7 @@ int process_ul_info_transfer_req(int msg_id, const ul_info_transfer_req_t* req, ind->UEid = 1; // Valid UEid starts at index 1 if (req->nasMsg.length > 0) { - ind->nasMsg.data = (Byte_t*)malloc(req->nasMsg.length); + ind->nasMsg.data = malloc(req->nasMsg.length); if (ind->nasMsg.data) { memcpy(ind->nasMsg.data, req->nasMsg.data, req->nasMsg.length); @@ -258,26 +244,9 @@ int process_ul_info_transfer_req(int msg_id, const ul_info_transfer_req_t* req, } } - // Identity-Response.messagetype = WRONG_MESSAGE_TYPE - //if (ind->nasMsg.data[1] == 0x56) { - // ind->nasMsg.data[1] = 0x47; // MME DEBUG (Send EMM status) - //} - // Authentication-Response.messagetype = WRONG_MESSAGE_TYPE - //if (ind->nasMsg.data[1] == 0x53) { - // ind->nasMsg.data[1] = 0x47; // MME DEBUG (Send EMM status) - //} - // Security-Mode-Complete.messagetype = WRONG_MESSAGE_TYPE - //if (ind->nasMsg.data[7] == 0x5e) { - // ind->nasMsg.data[7] = 0x47; // MME DEBUG (Send EMM status) - //} - /* Setup uplink information confirmation message */ cnf->UEid = 0; cnf->errCode = AS_SUCCESS; - // Transmission failure of Attach Complete message - //if (req->nasMsg.data[7] == 0x43) { - // cnf->errCode = AS_FAILURE; // UE DEBUG - //} printf("[%s][%s][--- Uplink Information Indication " "(0x%.4x), UEid = %u\\n%s --->][%s]\n", getTime(), @@ -324,14 +293,6 @@ int process_nas_establish_rsp(int msg_id, const nas_establish_rsp_t* rsp, printf("INFO\t: %s - Process NAS signalling connection establishment " "response\n", __FUNCTION__); - // Attach_Accept - //if (rsp->nasMsg.data[7] == 0x42) { - // Activate_Default_EPS_Bearer_Context_Request.ebi = UNASSIGNED - //rsp->nasMsg.data[19] = 0x02; // UE DEBUG (Send ESM status) - // Activate_Default_EPS_Bearer_Context_Request.messagetype = WRONG_MESSAGE_TYPE - //rsp->nasMsg.data[21] = 0xc4; // MME DEBUG (Send ESM status) - //} - printf("[%s][%s][--- NAS Signalling Connection Establishment " "Response (0x%.4x)\\nerrCode = %s, UEid = %u --->][%s]\n", getTime(), _mme_id, msg_id, @@ -360,7 +321,7 @@ int process_nas_establish_rsp(int msg_id, const nas_establish_rsp_t* rsp, cnf->errCode = rsp->errCode; if (rsp->nasMsg.length > 0) { - cnf->nasMsg.data = (Byte_t*)malloc(rsp->nasMsg.length); + cnf->nasMsg.data = malloc(rsp->nasMsg.length); if (cnf->nasMsg.data) { memcpy(cnf->nasMsg.data, rsp->nasMsg.data, @@ -392,15 +353,6 @@ int process_dl_info_transfer_req(int msg_id, const dl_info_transfer_req_t* req, printf("INFO\t: %s - Process downlink data transfer request\n", __FUNCTION__); - // Activate_default_EPS_Bearer_Context_Request.ebi = 6 (already active) - //if (req->nasMsg.data[8] == 0xC1) { - // req->nasMsg.data[6] = 0x52; // UE DEBUG (Accept with same ebi) - //} - // Deactivate_EPS_Bearer_Context_Request.ebi = UNASSIGNED - //if (req->nasMsg.data[8] == 0xCD) { - // req->nasMsg.data[6] = 0x02; // UE DEBUG - //} - printf("[%s][%s][--- Downlink Information Request " "(0x%.4x), UEid = %u --->][%s]\n", getTime(), _mme_id, msg_id, req->UEid, _as_id); @@ -426,7 +378,7 @@ int process_dl_info_transfer_req(int msg_id, const dl_info_transfer_req_t* req, /* Setup downlink information indication message */ if (req->nasMsg.length > 0) { - ind->nasMsg.data = (Byte_t*)malloc(req->nasMsg.length); + ind->nasMsg.data = malloc(req->nasMsg.length); if (ind->nasMsg.data) { memcpy(ind->nasMsg.data, req->nasMsg.data, req->nasMsg.length); @@ -524,744 +476,3 @@ static int _process_dump(char* buffer, int len, const char* msg, int size) buffer[index] = '\0'; return (index); } - -/* - 04 01 04 10 00 00 0f 00 00 00 01 00 00 00 20 8f - 10 00 22 00 00 00 07 41 71 0b f6 02 f8 01 01 02 - 0f 00 00 00 01 05 80 80 00 00 00 00 04 02 01 d0 - 31 52 02 f8 01 00 01 e0 -*/ -/* - U16 msgID = [04 01] - AS_NAS_ESTABLISH_REQ - U8 cause = [04] - NET_ESTABLISH_CAUSE_MO_SIGNAL - U8 type = [10] - NET_ESTABLISH_TYPE_ORIGINATING_SIGNAL - as_stmsi_t s_tmsi - U8 MMEcode = [0f] - U32 m_tmsi = [00 00 00 01] - plmn_t plmnID = [20 8f 10] - Byte_t MCCdigit2:4 = [0] - Byte_t MCCdigit1:4 = [2] - Byte_t MNCdigit3:4 = [f] - Byte_t MCCdigit3:4 = [8] - Byte_t MNCdigit2:4 = [0] - Byte_t MNCdigit1:4 = [1] - - U32 Length = [22 00 00 00] (34 octets) - U8* initialNasMsg = [07 41 71 0b f6 02 f8 01 01 02 0f 00 00 00 01 05] - [80 80 00 00 00 00 04 02 01 d0 31 52 02 f8 01 00] - [01 e0] - - U8:4 Security header type = [0] - Not protected - U8:4 Protocol discriminator = [7] - EMM message - U8 EMM message identifier = [41] - Attach Request - - U8:4 NAS KSI = [7] - No key available - U8:4 Attach Type = [1] - EPS Mobile Identity = [0b f6 02 f8 01 01 02 0f 00 00 00 01] - Length = [0b] (11 bytes) - U8:4 = 1111 = [f] - U8:1 oddeven = 0 - U8:3 typeofidentity = 110 = [6] - GUTI - U8:4 mccdigit2 = [0] - U8:4 mccdigit1 = [2] - U8:4 mncdigit3 = [f] - U8:4 mccdigit3 = [8] - U8:4 mncdigit2 = [0] - U8:4 mncdigit1 = [1] - U16 mmegroupid = [01 02] - U8 mmecode = [0f] - U32 mtmsi = [00 00 00 01] - UE network capability = [05 80 80 00 00 00] - Length = [05] (5 bytes) - U8 eea = [80] - EEA0 - U8 eia = [80] - EIA0 - U8 uea = [00] - U8:1 ucs2 = 0 - U8:7 uia = 0000000 = [00] - U8:3 spare = 000 - U8:1 csfb = 0 - U8:1 lpp = 0 - U8:1 lcs = 0 - U8:1 srvcc = 0 - U8:1 nf = 0 = [00] - - ESM message container = [00 04 02 01 d0 31] - Length = [00 04] (4 bytes) - ESM message = [02 01 d0 31] - U8:4 EPS bearer identity = [0] - Not assigned - U8:4 Protocol discriminator = [2] - ESM message - U8 Procedure Transaction Identity = [01] - U8 ESM message identifier = [d0] - PDN Connectivity Request - U8:4 Pdn type = [3] - IPv4v6 - U8:4 Request type = [1] - Initial request - - Last TAI = [52 02 f8 01 00 01] - PLMN = 20810, TAC = 00 01 - Old GUTI type = [e0] - Native GUTI -*/ - -/* - 07 04 00 00 00 00 03 00 00 00 07 44 03 -*/ -/* - U16 msgID = [07 04] - AS_DL_INFO_TRANSFER_IND - U32 UEid = [00 00 00 00] - - U32 Length = [03 00 00 00] (3 octets) - U8* NasMsg = [07 44 03] - - U8:4 Security header type = [0] - Not protected - U8:4 Protocol discriminator = [7] - EMM message - U8 EMM message identifier = [44] - Attach Reject - - U8 EMM cause code = [03] - EMM_CAUSE_ILLEGAL_UE -*/ - -/* - 07 04 00 00 00 00 10 00 00 00 27 ab ab ab ab 00 - 07 44 13 78 00 04 02 01 d1 1f -*/ -/* - U16 msgID = [07 04] - AS_DL_INFO_TRANSFER_IND - U32 UEid = [00 00 00 00] - - U32 Length = [10 00 00 00] (16 octets) - U8* NasMsg = [27 ab ab ab ab 00 07 44 13 78 00 04 02 01 d1 1f] - - U8:4 Security header type = [2] - Integrity protected and cyphered - U8:4 Protocol discriminator = [7] - EMM message - U32 Message authentication code = [ab ab ab ab] - U8 Sequence number = [00] - 0 - - NAS message = [07 44 13 78 00 04 02 d1 1f] - U8:4 Security header type = [0] - Not protected - U8:4 Protocol discriminator = [7] - EMM message - U8 EMM message identifier = [44] - Attach Reject - - U8 EMM cause code = [13] - #19 ESM failure - - ESM message container = [00 04 02 01 d1 1f] - U16 Length = [00 04] (4 octets) - U8* EsmMsg = [02 01 d1 1f] - U8:4 EPS bearer identity = [0] - Not assigned - U8:4 Protocol discriminator = [2] - ESM message - U8 Procedure Transaction Identity = [01] - U8 ESM message identifier = [d1] - PDN Connectivity Reject - - U8 ESM cause code = [1f] - REQUEST_REJECTED_UNSPECIFIED -*/ - -/* - 04 08 01 00 00 00 46 00 00 00 27 ab ab ab ab 00 - 07 42 01 e0 06 24 02 f8 01 00 01 00 26 52 01 c1 - 05 03 48 87 40 78 0e 77 77 77 2e 65 75 72 65 63 - 6f 6d 2e 66 72 0d 03 c0 a8 02 3c 02 21 70 ff c0 - a8 02 3c 50 0b f6 02 f8 01 01 02 0f 00 00 00 01 -*/ -/* - U16 msgID = [04 08] - AS_NAS_ESTABLISH_CNF - U8 errCode = [01] - SUCCESS - - U32 Length = [00 00 00 46] (70 octets) - U8* NasMsg = [27 ab ab ab ab 00 07 42 01 e0 06 24 02 f8 01 00] - [01 00 26 52 01 c1 05 03 48 87 40 78 0e 77 77 77] - [2e 65 75 72 65 63 6f 6d 2e 66 72 0d 03 c0 a8 02] - [3c 02 21 70 ff c0 a8 02 3c 50 0b f6 02 f8 01 01] - [02 0f 00 00 00 01] - - U8:4 Security header type = [2] - Integrity protected and cyphered - U8:4 Protocol discriminator = [7] - EMM message - U32 Message authentication code = [ab ab ab ab] - U8 Sequence number = [00] - 0 - - NAS message = [07 42 01 e0 06 24 02 f8 01 00 01 00 26 52 01 c1] - [05 03 48 87 40 78 0e 77 77 77 2e 65 75 72 65 63] - [6f 6d 2e 66 72 0d 03 c0 a8 02 3c 02 21 70 ff c0] - [a8 02 3c 50 0b f6 02 f8 01 01 02 0f 00 00 00 01] - U8:4 Security header type = [0] - Not protected - U8:4 Protocol discriminator = [7] - EMM message - U8 EMM message identifier = [42] - Attach Accept - - U8:4 Spare = [0] - U8:4 EPS attach result = [1] - EPS - U8:3 T3412 unit = 111 - Deactivated - U8:5 T3412 value = 00000 - - TAI list = [06 24 02 f8 01 00 01] - Length = [06] - U8:1 spare = 0 - U8:2 Type of list = 01 - list of TACs belonging to one PLMN, - with consecutive TAC values - U8:5 Number of elements = 0 0100 - 4 consecutive TACs - TAI = [02 f8 01 00 01] - PLMN = 20810, TAC = 00 01 - - ESM message container = [00 26 52 01 c1 05 03 48 87 40 78 0e 77 77 77 2e] - [65 75 72 65 63 6f 6d 2e 66 72 0d 03 c0 a8 02 3c] - [02 21 70 ff c0 a8 02 3c] - U16 Length = [00 26] (38 octets) - U8:4 EPS bearer identity = [5] - ebi = 5 - U8:4 Protocol discriminator = [2] - ESM message - U8 Procedure Transaction Identity = [01] - U8 ESM message identifier = [c1] - Activate Default EPS Bearer Context Request - - EPS Qos = [05 03 48 87 40 78] - Length = [05] - 5 octets - QCI = [03] - 3 - Maximum bit rate for uplink = [48] - 128K - Maximum bit rate for downlink = [87] - 1024K - Guaranteed bit rate for uplink = [40] - 64K - Guaranteed bit rate for downlink = [78] - 512K - - Access point name = [0e 77 77 77 2e 65 75 72 65 63 6f 6d 2e 66 72] - Length = [0e] - 14 octets - APN = "www.eurecom.fr" - - PDN address = [0d 03 c0 a8 02 3c 02 21 70 ff c0 a8 02 3c] - Length = [0d] - 13 octets - U8:5 Spare = 00000 - 0 - U8:3 Pdn type = 011 - IPv4v6 - PDN address information = [c0 a8 02 3c 02 21 70 ff c0 a8 02 3c] -*/ - -/* - 06 01 00 00 00 00 0f 00 00 00 01 00 00 00 0d 00 - 00 00 27 ab ab ab ab 00 07 43 00 03 52 00 c2 -*/ -/* - U16 msgID = [06 01] - AS_UL_INFO_TRANSFER_REQ - U32 UEid = [00 00 00 00] - as_stmsi_t s_tmsi - U8 MMEcode = [0f] - U32 m_tmsi = [00 00 00 01] - - U32 Length = [00 00 00 0d] (13 octets) - U8* NasMsg = [27 ab ab ab ab 00 07 43 00 03 52 00 c2] - - U8:4 Security header type = [2] - Integrity protected and ciphered - U8:4 Protocol discriminator = [7] - EMM message - U32 Message authentication code = [ab ab ab ab] - U8 Sequence number = [00] - Uplink counter value - - NAS message = [07 43 00 03 52 00 c2] - U8:4 Security header type = [0] - Not protected - U8:4 Protocol discriminator = [7] - EMM message - U8 EMM message identifier = [43] - Attach Complete - - ESM message container = [00 03 52 00 c2] - Length = [00 03] (3 bytes) - ESM message = [52 00 c2] - U8:4 EPS bearer identity = [5] - ebi = 5 - U8:4 Protocol discriminator = [2] - ESM message - U8 Procedure Transaction Identity = [00] - unassigned - U8 ESM message identifier = [c2] - Activate Default EPS Bearer Context Accept -*/ - -/* - 07 04 00 00 00 00 03 00 00 00 07 55 10 -*/ -/* - U16 msgID = [07 04] - AS_DL_INFO_TRANSFER_IND - U32 UEid = [00 00 00 00] - - U32 Length = [03 00 00 00] (3 octets) - U8* NasMsg = [07 55 10] - - U8:4 Security header type = [0] - Not protected - U8:4 Protocol discriminator = [7] - EMM message - U8 EMM message identifier = [55] - Identity Request - - U8:4 Identity type = [1] - IMSI - U8:4 spare = [0] -*/ - -/* - 06 01 00 00 00 00 0f 00 00 00 01 00 00 00 0b 00 - 00 00 07 56 08 21 80 01 0f 00 10 32 f4 -*/ -/* - U16 msgID = [06 01] - AS_UL_INFO_TRANSFER_REQ - U32 UEid = [00 00 00 00] - as_stmsi_t s_tmsi - U8 MMEcode = [0f] - U32 m_tmsi = [00 00 00 01] - - U32 Length = [00 00 00 0b] (11 octets) - U8* NasMsg = [07 56 08 21 80 01 0f 00 10 32 f4] - U8:4 Security header type = [0] - Not protected - U8:4 Protocol discriminator = [7] - EMM message - U8 EMM message identifier = [56] - Identity Response - - Mobile identity = [08 21 80 01 0f 00 10 32 f4] - Length = [08] - 8 octets - U8:4 Identity digit 1 = [2] - 2 - U8:1 odd/even indicator = [0] - even number of identity digits - U8:3 Type of identity = [001] - IMSI - U8:4 Identity digit 3 = [8] - 8 - U8:4 Identity digit 2 = [0] - 0 - U8:4 Identity digit 5 = [0] - 0 - U8:4 Identity digit 4 = [1] - 1 - U8:4 Identity digit 7 = [0] - 0 - U8:4 Identity digit 6 = [f] - f - U8:4 Identity digit 9 = [0] - 0 - U8:4 Identity digit 8 = [0] - 0 - U8:4 Identity digit 11 = [1] - 1 - U8:4 Identity digit 10 = [0] - 0 - U8:4 Identity digit 13 = [3] - 3 - U8:4 Identity digit 12 = [2] - 2 - U8:4 Identity digit 15 = [f] - f - U8:4 Identity digit 16 = [4] - 4 - -IMSI = 20810f00001234f (2081000001234) -*/ - -/* - 07 04 00 00 00 00 24 00 00 00 07 52 00 00 00 00 - 00 00 00 00 00 00 00 00 00 01 02 03 04 10 00 00 - 00 00 00 00 80 05 04 03 02 00 00 00 00 00 -*/ -/* - U16 msgID = [07 04] - AS_DL_INFO_TRANSFER_IND - U32 UEid = [00 00 00 00] - - U32 Length = [24 00 00 00] (36 octets) - U8* NasMsg = [07 52 00 00 00 00 00 00 00 00 00 00 00 00 00 01] - [02 03 04 10 00 00 00 00 00 00 80 05 04 03 02 00] - [00 00 00 00] - - U8:4 Security header type = [0] - Not protected - U8:4 Protocol discriminator = [7] - EMM message - U8 EMM message identifier = [52] - Authentication Request - - U8:4 NAS key set identifier = [0] - 000 - U8:4 spare = [0] - RAND = [00 00 00 00 00 00 00 00 00 00 00 00 01 02 03 04] - AUTHN Length = [10] - 16 octets - AUTHN = [00 00 00 00 00 00 80 05 04 03 02 00 00 00 00 00] -*/ - -/* - 06 01 00 00 00 00 0f 00 00 00 01 00 00 00 13 00 - 00 00 07 53 10 67 70 3a 31 f2 2a 2d 51 00 00 00 - 00 00 00 00 00 -*/ -/* - U16 msgID = [06 01] - AS_UL_INFO_TRANSFER_REQ - U32 UEid = [00 00 00 00] - as_stmsi_t s_tmsi - U8 MMEcode = [0f] - U32 m_tmsi = [00 00 00 01] - - U32 Length = [00 00 00 13] (19 octets) - U8* NasMsg = [07 53 10 67 70 3a 31 f2 2a 2d 51 00 00 00 00 00 00 00 00] - U8:4 Security header type = [0] - Not protected - U8:4 Protocol discriminator = [7] - EMM message - U8 EMM message identifier = [53] - Authentication Response - - RES Length = [10] - 16 octets - RES = [67 70 3a 31 f2 2a 2d 51 00 00 00 00 00 00 00 00] -*/ - -/* - 07 04 00 00 00 00 10 00 00 00 37 ab ab ab ab 00 - 07 5d 00 00 05 80 80 00 00 00 -*/ -/* - U16 msgID = [07 04] - AS_DL_INFO_TRANSFER_IND - U32 UEid = [00 00 00 00] - - U32 Length = [10 00 00 00] (16 octets) - U8* NasMsg = [37 ab ab ab ab 00 07 5d 00 00 05 80 80 00 00 00] - - U8:4 Security header type = [3] - Integrity protected with - new EPS security context - U8:4 Protocol discriminator = [7] - EMM message - U32 Message authentication code = [ab ab ab ab] - U8 Sequence number = [00] - 0 - - NAS message = [07 5d 00 00 05 80 80 00 00 00] - U8:4 Security header type = [0] - Not protected - U8:4 Protocol discriminator = [7] - EMM message - U8 EMM message identifier = [5d] - Security Mode Command - - U8 Selected NAS security algorithms = [00] - U8:4 Spare half octet = [0] - U8:4 NAS key set identifier = [0] - Replayed UE security capabilities = [05 80 80 00 00 00] - U8 EEA = [80] - EEA0 - U8 EIA = [80] - EIA0 - U8 UEA = [00] - U8 UIA = [00] - U8 GEA = [00] -*/ - -/* - 06 01 00 00 00 00 0f 00 00 00 01 00 00 00 08 00 - 00 00 47 ab ab ab ab 00 07 5e -*/ -/* - U16 msgID = [06 01] - AS_UL_INFO_TRANSFER_REQ - U32 UEid = [00 00 00 00] - as_stmsi_t s_tmsi - U8 MMEcode = [0f] - U32 m_tmsi = [00 00 00 01] - - U32 Length = [00 00 00 08] (8 octets) - U8* NasMsg = [47 ab ab ab ab 00 07 5e] - - U8:4 Security header type = [4] - Integrity protected and ciphered with - new EPS security context - U8:4 Protocol discriminator = [7] - EMM message - U32 Message authentication code = [ab ab ab ab] - U8 Sequence number = [00] - Uplink counter value - - NAS message = [07 5e] - U8:4 Security header type = [0] - Not protected - U8:4 Protocol discriminator = [7] - EMM message - U8 EMM message identifier = [5e] - Security Mode Complete -*/ - -/* - 06 01 00 00 00 00 0f 00 00 00 01 00 00 00 09 00 - 00 00 27 ab ab ab ab 00 07 5f 18 -*/ -/* - U16 msgID = [06 01] - AS_UL_INFO_TRANSFER_REQ - U32 UEid = [00 00 00 00] - as_stmsi_t s_tmsi - U8 MMEcode = [0f] - U32 m_tmsi = [00 00 00 01] - - U32 Length = [00 00 00 09] (9 octets) - U8* NasMsg = [27 ab ab ab ab 00 07 5f 18] - - U8:4 Security header type = [2] - Integrity protected and ciphered - U8:4 Protocol discriminator = [7] - EMM message - U32 Message authentication code = [ab ab ab ab] - U8 Sequence number = [00] - Uplink counter value - - NAS message = [07 5f 18] - U8:4 Security header type = [0] - Not protected - U8:4 Protocol discriminator = [7] - EMM message - U8 EMM message identifier = [5f] - Security Mode Reject - - U8 EMM cause code = [18] - EMM_CAUSE_SECURITY_MODE_REJECTED -*/ - -/* - 07 01 00 00 00 00 00 00 00 00 00 00 00 00 04 00 - 00 00 52 00 e8 6f -*/ -/* - U16 msgID = [07 01] - AS_DL_INFO_TRANSFER_REQ - U32 UEid = [00 00 00 00] - as_stmsi_t s_tmsi - U8 MMEcode = [00] - !!! - U32 m_tmsi = [00 00 00 00] - !!! - - U32 Length = [00 00 00 04] (4 octets) - NAS message = [52 00 e8 6f] - - U8:4 EPS bearer identity = [5] - ebi = 5 - U8:4 Protocol discriminator = [2] - ESM message - U8 Procedure Transaction Identity = [00] - unassigned - U8 ESM message identifier = [e8] - ESM Status - - U8 ESM cause code = [6f] - #111 PROTOCOL_ERROR -*/ - -/* - 06 01 00 00 00 00 12 00 00 00 01 00 00 00 0a 00 - 00 00 27 ab ab ab ab 00 02 01 e8 2b -*/ -/* - U16 msgID = [06 01] - AS_UL_INFO_TRANSFER_REQ - U32 UEid = [00 00 00 00] - as_stmsi_t s_tmsi - U8 MMEcode = [12] - U32 m_tmsi = [00 00 00 01] - - U32 Length = [00 00 00 0a] (10 octets) - U8* NasMsg = [27 ab ab ab ab 00 02 01 e8 2b] - - U8:4 Security header type = [2] - Integrity protected and ciphered - U8:4 Protocol discriminator = [7] - EMM message - U32 Message authentication code = [ab ab ab ab] - U8 Sequence number = [00] - Uplink counter value - - NAS message = [02 01 e8 2b] - U8:4 EPS bearer identity = [0] - Not assigned - U8:4 Protocol discriminator = [2] - ESM message - U8 Procedure Transaction Identity = [01] - U8 ESM message identifier = [e8] - ESM Status - - U8 ESM cause code = [2b] - #43 INVALID_EPS_BEARER_IDENTITY -*/ - -/* - 06 01 00 00 00 00 12 00 00 00 01 00 00 00 0a 00 - 00 00 27 ab ab ab ab 00 02 03 d2 06 -*/ -/* - U16 msgID = [06 01] - AS_UL_INFO_TRANSFER_REQ - U32 UEid = [00 00 00 00] - as_stmsi_t s_tmsi - U8 MMEcode = [12] - U32 m_tmsi = [00 00 00 01] - - U32 Length = [00 00 00 0a] (10 octets) - U8* NasMsg = [27 ab ab ab ab 00 02 03 d2 06] - - U8:4 Security header type = [2] - Integrity protected and ciphered - U8:4 Protocol discriminator = [7] - EMM message - U32 Message authentication code = [ab ab ab ab] - U8 Sequence number = [00] - Uplink counter value - - NAS message = [02 03 d2 06] - U8:4 EPS bearer identity = [0] - Not assigned - U8:4 Protocol discriminator = [2] - ESM message - U8 Procedure Transaction Identity = [03] - U8 ESM message identifier = [d2] - PDN Disconnect Request - - U8:4 Spare half octet = [0] - U8:4 Linked EPS bearer identity = [6] - ebi = 6 -*/ - -/* - 06 08 00 00 00 00 01 00 00 00 -*/ -/* - U16 msgID = [06 08] - AS_UL_INFO_TRANSFER_CNF - U32 UEid = [00 00 00 00] - U8 errCode = [01] - SUCCESS -*/ - -/* - 06 01 00 00 00 00 12 00 00 00 01 00 00 00 09 00 - 00 00 27 ab ab ab ab 00 82 00 ce -*/ -/* - U16 msgID = [06 01] - AS_UL_INFO_TRANSFER_REQ - U32 UEid = [00 00 00 00] - as_stmsi_t s_tmsi - U8 MMEcode = [12] - U32 m_tmsi = [00 00 00 01] - - U32 Length = [00 00 00 09] (9 octets) - U8* NasMsg = [27 ab ab ab ab 00 82 00 ce] - - U8:4 Security header type = [2] - Integrity protected and ciphered - U8:4 Protocol discriminator = [7] - EMM message - U32 Message authentication code = [ab ab ab ab] - U8 Sequence number = [00] - Uplink counter value - - NAS message = [82 00 ce] - U8:4 EPS bearer identity = [8] - 8 - U8:4 Protocol discriminator = [2] - ESM message - U8 Procedure Transaction Identity = [00] - U8 ESM message identifier = [ce] - Deactivate EPS Bearer Context Accept -*/ - -/* - 07 01 01 00 00 00 00 00 00 00 00 00 00 00 0a 00 - 00 00 27 ab ab ab ab 00 62 02 cd 24 -*/ -/* - U16 msgID = [07 01] - AS_DL_INFO_TRANSFER_REQ - U32 UEid = [01 00 00 00] - as_stmsi_t s_tmsi - U8 MMEcode = [00] - U32 m_tmsi = [00 00 00 00] - - U32 Length = [00 00 00 0a] (10 octets) - NAS message = [27 ab ab ab ab 00 62 02 cd 24] - - U8:4 Security header type = [2] - Integrity protected and ciphered - U8:4 Protocol discriminator = [7] - EMM message - U32 Message authentication code = [ab ab ab ab] - U8 Sequence number = [00] - Uplink counter value - - NAS message = [62 02 cd 24] - U8:4 EPS bearer identity = [6] - ebi = 6 - U8:4 Protocol discriminator = [2] - ESM message - U8 Procedure Transaction Identity = [02] - U8 ESM message identifier = [cd] - Deactivate EPS Bearer Context Request - - U8 ESM cause code = [24] - #36 REGULAR_DEACTIVATION -*/ - -/* - 04 08 01 00 00 00 00 00 00 00 -*/ -/* - U16 msgID = [04 08] - AS_NAS_ESTABLISH_CNF - U8 errCode = [01] - SUCCESS - U32 Length = [00 00 00 00] (0 octets) -*/ - - -/* - 07 01 01 00 00 00 00 00 00 00 00 00 00 00 0e 00 - 00 00 27 ab ab ab ab 00 72 00 c5 06 01 02 01 00 -*/ -/* - U16 msgID = [07 01] - AS_DL_INFO_TRANSFER_REQ - U32 UEid = [01 00 00 00] - as_stmsi_t s_tmsi - U8 MMEcode = [00] - U32 m_tmsi = [00 00 00 00] - - U32 Length = [00 00 00 0e] (14 octets) - NAS message = [27 ab ab ab ab 00 72 00 c5 06 01 02 01 00] - - U8:4 Security header type = [2] - Integrity protected and ciphered - U8:4 Protocol discriminator = [7] - EMM message - U32 Message authentication code = [ab ab ab ab] - U8 Sequence number = [00] - Uplink counter value - - NAS message = [72 00 c5 06 00 00 00 00] - U8:4 EPS bearer identity = [7] - ebi = 7 - U8:4 Protocol discriminator = [2] - ESM message - U8 Procedure Transaction Identity - Unassigned - U8 ESM message identifier = [c5] - Activate dedicated EPS Bearer Context Request - - U8:4 Spare half octet = [0] - U8:4 Linked EPS bearer identity = [6] - U8 QoS length = [01] - U8 QCI = [02] - U8 TFT length = [01] - U8 TFT = [00] -*/ - -/* - 07 04 00 00 00 00 36 00 00 00 27 ab ab ab ab 00 - 72 00 c5 06 01 02 29 22 11 02 11 10 c0 a8 0c 01 - ff ff ff 00 30 11 40 27 11 50 2e e1 22 03 11 10 - c0 a8 0c 01 ff ff ff 00 30 11 40 27 12 50 2e e2 -*/ -/* - U16 msgID = [07 04] - AS_DL_INFO_TRANSFER_IND - U32 UEid = [00 00 00 00] - - U32 Length = [36 00 00 00] (54 octets) - U8* NasMsg = [27 ab ab ab ab 00 72 00 c5 06 01 02 29 22 11 02] - [11 10 c0 a8 0c 01 ff ff ff 00 30 11 40 27 11 50] - [2e e1 22 03 11 10 c0 a8 0c 01 ff ff ff 00 30 11] - [40 27 12 50 2e e2] - - U8:4 Security header type = [2] - Integrity protected and ciphered - U8:4 Protocol discriminator = [7] - EMM message - U32 Message authentication code = [ab ab ab ab] - U8 Sequence number = [00] - 0 - - NAS message = [72 00 c5 06 01 02 29 22 11 02 11 10 c0 a8 0c 01] - [ff ff ff 00 30 11 40 27 11 50 2e e1 22 03 11 10] - [c0 a8 0c 01 ff ff ff 00 30 11 40 27 12 50 2e e2] - U8:4 EPS bearer identity = [7] - ebi = 7 - U8:4 Protocol discriminator = [2] - ESM message - U8 Procedure Transaction Identity - Unassigned - U8 ESM message identifier = [c5] - Activate dedicated EPS Bearer Context Request - - U8:4 Spare half octet = [0] - U8:4 Linked EPS bearer identity = [6] - U8 QoS length = [01] - 1 octet - U8 QCI = [02] - U8 TFT length = [29] - 41 octets - U8 TFT = [22 11 02 11 10 c0 a8 0c 01 ff ff ff 00 30 11 40] - [27 11 50 2e e1 22 03 11 10 c0 a8 0c 01 ff ff ff] - [00 30 11 40 27 12 50 2e e2] -*/ - -/* - 06 01 00 00 00 00 12 00 00 00 01 00 00 00 0a 00 - 00 00 27 ab ab ab ab 00 72 00 c7 2d -*/ -/* - U16 msgID = [06 01] - AS_UL_INFO_TRANSFER_REQ - U32 UEid = [00 00 00 00] - as_stmsi_t s_tmsi - U8 MMEcode = [12] - U32 m_tmsi = [00 00 00 01] - - U32 Length = [00 00 00 0a] (10 octets) - U8* NasMsg = [27 ab ab ab ab 00 72 00 c7 2d] - - U8:4 Security header type = [2] - Integrity protected and ciphered - U8:4 Protocol discriminator = [7] - EMM message - U32 Message authentication code = [ab ab ab ab] - U8 Sequence number = [00] - Uplink counter value - - NAS message = [72 00 c7 2d] - U8:4 EPS bearer identity = [7] - 7 - U8:4 Protocol discriminator = [2] - ESM message - U8 Procedure Transaction Identity = [00] - U8 ESM message identifier = [c7] - Activate Dedicated EPS Bearer Context - Reject - - U8 ESM cause code = [2d] - SYNTACTICAL_ERROR_IN_PACKET_FILTER -*/ - -/* - 06 01 00 00 00 00 12 00 00 00 01 00 00 00 09 00 - 00 00 27 ab ab ab ab 00 72 00 c6 -*/ -/* - U16 msgID = [06 01] - AS_UL_INFO_TRANSFER_REQ - U32 UEid = [00 00 00 00] - as_stmsi_t s_tmsi - U8 MMEcode = [12] - U32 m_tmsi = [00 00 00 01] - - U32 Length = [00 00 00 09] (9 octets) - U8* NasMsg = [27 ab ab ab ab 00 72 00 c6] - - U8:4 Security header type = [2] - Integrity protected and ciphered - U8:4 Protocol discriminator = [7] - EMM message - U32 Message authentication code = [ab ab ab ab] - U8 Sequence number = [00] - Uplink counter value - - NAS message = [72 00 c6] - U8:4 EPS bearer identity = [7] - 7 - U8:4 Protocol discriminator = [2] - ESM message - U8 Procedure Transaction Identity = [00] - U8 ESM message identifier = [c6] - Activate Dedicated EPS Bearer Context - Accept -*/ - -/* - 06 01 00 00 00 00 12 00 00 00 01 00 00 00 15 00 - 00 00 27 ab ab ab ab 00 07 45 01 0b f6 02 f8 01 - 01 02 12 00 00 00 01 -*/ -/* - U16 msgID = [06 01] - AS_UL_INFO_TRANSFER_REQ - U32 UEid = [00 00 00 00] - as_stmsi_t s_tmsi - U8 MMEcode = [12] - U32 m_tmsi = [00 00 00 01] - - U32 Length = [00 00 00 15] (21 octets) - U8* NasMsg = [27 ab ab ab ab 00 07 45 01 0b f6 02 f8 01 01 02] - [12 00 00 00 01] - - U8:4 Security header type = [2] - Integrity protected and ciphered - U8:4 Protocol discriminator = [7] - EMM message - U32 Message authentication code = [ab ab ab ab] - U8 Sequence number = [00] - Uplink counter value - - NAS message = [07 45 01 0b f6 02 f8 01 01 02 12 00 00 00 01] - U8:4 Security header type = [0] - Not protected - U8:4 Protocol discriminator = [7] - EMM message - U8 EMM message identifier = [45] - Detach Request - - U8:4 NAS key set identifier = [0] - Native 0 - U8:4 Detach type = [1] - EPS Detach - - Mobile identity = [0b f6 02 f8 01 01 02 12 00 00 00 01] - Length = [0b] - 11 octets - U8:4 = 1111 = [f] - U8:1 odd/even indicator = [0] - even number of identity digits - U8:3 Type of identity = [110] - GUTI - plmn = [02 f8 01] - 20810 - U16 mmegroupid = [01 02] - U8 mmecode = [12] - U32 mtmsi = [00 00 00 01] -*/ diff --git a/openair3/NAS/TEST/NETWORK/network_simulator.c b/openair3/NAS/TEST/NETWORK/network_simulator.c index 492a709463..a09c0a0a69 100644 --- a/openair3/NAS/TEST/NETWORK/network_simulator.c +++ b/openair3/NAS/TEST/NETWORK/network_simulator.c @@ -228,7 +228,7 @@ static int _process_activate_default_eps_bearer_context_accept(const activate_de static int _process_activate_default_eps_bearer_context_reject(const activate_default_eps_bearer_context_reject_msg* msg); static int _process_deactivate_eps_bearer_context_accept(const deactivate_eps_bearer_context_accept_msg* msg); -static void _dump_buffer(const Byte_t* buffer, size_t len) +static void _dump_buffer(const uint8_t* buffer, size_t len) { for (int i = 0; i < len; i++) { if ( (i%16) == 0 ) printf("\n\t"); @@ -538,7 +538,7 @@ static int _process_establish_req(const nas_establish_req_t* req, if (bytes > 0) { /* Setup signalling connection establishment confirm message */ rsp->errCode = AS_SUCCESS; - rsp->nasMsg.data = (Byte_t*)malloc(bytes * sizeof(Byte_t)); + rsp->nasMsg.data = malloc(bytes * sizeof(uint8_t)); if (rsp->nasMsg.data) { rsp->nasMsg.length = bytes; @@ -618,7 +618,7 @@ static int _process_ul_info_transfer_req(const ul_info_transfer_req_t* req, return (AS_UL_INFO_TRANSFER_CNF); } else if (bytes > 0) { /* Some data has to be sent back to the UE */ - ind->nasMsg.data = (Byte_t*)malloc(bytes * sizeof(Byte_t)); + ind->nasMsg.data = malloc(bytes * sizeof(uint8_t)); if (ind->nasMsg.data) { ind->nasMsg.length = bytes; @@ -1258,12 +1258,12 @@ static int _assign_pdn_address(int ue_pdn_type, int is_initial, int* pdn_type, O U8 cause = [04] - NET_ESTABLISH_CAUSE_MO_SIGNAL U8 type = [10] - NET_ESTABLISH_TYPE_ORIGINATING_SIGNAL plmn_t plmnID = [20 8f 10] - Byte_t MCCdigit2:4 = [0] - Byte_t MCCdigit1:4 = [2] - Byte_t MNCdigit3:4 = [f] - Byte_t MCCdigit3:4 = [8] - Byte_t MNCdigit2:4 = [0] - Byte_t MNCdigit1:4 = [1] + uint8_t MCCdigit2:4 = [0] + uint8_t MCCdigit1:4 = [2] + uint8_t MNCdigit3:4 = [f] + uint8_t MCCdigit3:4 = [8] + uint8_t MNCdigit2:4 = [0] + uint8_t MNCdigit1:4 = [1] as_stmsi_t s_tmsi U8 MMEcode = [0f] U32 m_tmsi = [00 00 00 01] diff --git a/openair3/NAS/UE/API/CMakeLists.txt b/openair3/NAS/UE/API/CMakeLists.txt new file mode 100644 index 0000000000..0810099d9e --- /dev/null +++ b/openair3/NAS/UE/API/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(USIM) diff --git a/openair3/NAS/UE/API/USIM/CMakeLists.txt b/openair3/NAS/UE/API/USIM/CMakeLists.txt new file mode 100644 index 0000000000..90a9cb40fe --- /dev/null +++ b/openair3/NAS/UE/API/USIM/CMakeLists.txt @@ -0,0 +1,9 @@ +add_library(usim_lib OBJECT + ${OPENAIR_DIR}/common/utils/mem/memory.c + aka_functions.c + usim_api.c +) + +target_include_directories(usim_lib PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} +) diff --git a/openair3/NAS/UE/API/USIM/usim_api.h b/openair3/NAS/UE/API/USIM/usim_api.h index f332b5ffc8..e1b379c050 100644 --- a/openair3/NAS/UE/API/USIM/usim_api.h +++ b/openair3/NAS/UE/API/USIM/usim_api.h @@ -73,7 +73,12 @@ Description Implements the API used by the NAS layer to read/write * USIM TLV parameter structure * ---------------------------- */ -#define USIM_TLV_T(SIZE) struct {uint8_t type; uint8_t length; Byte_t value[SIZE];} +#define USIM_TLV_T(SIZE) \ + struct { \ + uint8_t type; \ + uint8_t length; \ + uint8_t value[SIZE]; \ + } /* * Non Access Stratum Configuration @@ -116,13 +121,13 @@ typedef struct { #define USIM_KSI_MIN 0b000 #define USIM_KSI_MAX 0b110 #define USIM_KSI_NOT_AVAILABLE 0b111 - Byte_t ksi; + uint8_t ksi; /* Cyphering key */ #define USIM_CK_SIZE 16 - Byte_t ck[USIM_CK_SIZE]; + uint8_t ck[USIM_CK_SIZE]; /* Integrity key */ #define USIM_IK_SIZE 16 - Byte_t ik[USIM_IK_SIZE]; + uint8_t ik[USIM_IK_SIZE]; uint8_t usim_api_k[USIM_API_K_SIZE]; uint8_t opc[16]; } usim_keys_t; @@ -195,10 +200,10 @@ typedef struct { * ---------------------------- */ typedef struct { - Byte_t length; /* Length of BCD number/SSC contents */ + uint8_t length; /* Length of BCD number/SSC contents */ msisdn_t number; /* Mobile subscriber dialing number */ - Byte_t conf1_record_id; /* Configuration1 Record Identifier */ - Byte_t ext1_record_id; /* Extension1 Record Identifier */ + uint8_t conf1_record_id; /* Configuration1 Record Identifier */ + uint8_t ext1_record_id; /* Extension1 Record Identifier */ } usim_msisdn_t; /* @@ -251,12 +256,12 @@ typedef struct { typedef struct { uint32_t tmsi; /* Temporary Mobile Subscriber Identity */ lai_t lai; /* Location Area Identity */ - Byte_t reserved; /* Reserved for future use */ + uint8_t reserved; /* Reserved for future use */ #define USIM_LOCI_UPDATED 0x00 #define USIM_LOCI_NOT_UPDATED 0x01 #define USIM_LOCI_PLMN_NOT_ALLOWED 0x02 #define USIM_LOCI_LA_NOT_ALLOWED 0x03 - Byte_t status; /* Location update status */ + uint8_t status; /* Location update status */ } usim_loci_t; /* @@ -265,13 +270,13 @@ typedef struct { */ typedef struct { uint32_t p_tmsi; /* Packet Temporary Mobile Subscriber Identity */ - Byte_t signature[3]; /* P-TMSI signature value */ + uint8_t signature[3]; /* P-TMSI signature value */ RAI_t rai; /* Routing Area Identity */ #define USIM_PSLOCI_UPDATED 0x00 #define USIM_PSLOCI_NOT_UPDATED 0x01 #define USIM_PSLOCI_PLMN_NOT_ALLOWED 0x02 #define USIM_PSLOCI_LA_NOT_ALLOWED 0x03 - Byte_t status; /* Routing Area update status */ + uint8_t status; /* Routing Area update status */ } usim_psloci_t; /* @@ -284,7 +289,7 @@ typedef struct { #define USIM_EPSLOCI_UPDATED 0x00 #define USIM_EPSLOCI_NOT_UPDATED 0x01 #define USIM_EPSLOCI_ROAMING_NOT_ALLOWED 0x02 - Byte_t status; /* EPS update status */ + uint8_t status; /* EPS update status */ } usim_epsloci_t; /* @@ -308,11 +313,11 @@ typedef struct { #define USIM_TYPE_APPROVAL_SPECIFIC_MODE 0x81U #define USIM_MAINTENANCE_MODE 0x02U #define USIM_CELL_TEST_MODE 0x04U - Byte_t UE_Operation_Mode; /* Mode of operation for the UE */ + uint8_t UE_Operation_Mode; /* Mode of operation for the UE */ uint16_t Additional_Info; /* Additional information depending on * the UE operation mode */ - Byte_t MNC_Length; /* Number of digits used for extracting - * the MNC from the IMSI */ + uint8_t MNC_Length; /* Number of digits used for extracting + * the MNC from the IMSI */ } usim_ad_t; /* @@ -328,7 +333,7 @@ typedef struct { */ imsi_t imsi; /* International Mobile Subscriber Identity */ usim_keys_t keys; /* Ciphering and Integrity Keys */ - Byte_t hpplmn; /* Higher Priority PLMN search period */ + uint8_t hpplmn; /* Higher Priority PLMN search period */ #define USIM_FPLMN_MAX 4 plmn_t fplmn[USIM_FPLMN_MAX]; /* List of Forbidden PLMNs */ usim_loci_t loci; /* Location Information */ diff --git a/openair3/NAS/UE/CMakeLists.txt b/openair3/NAS/UE/CMakeLists.txt new file mode 100644 index 0000000000..01e40a3c9e --- /dev/null +++ b/openair3/NAS/UE/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(API) diff --git a/openair3/NAS/UE/EMM/SAP/emm_as.c b/openair3/NAS/UE/EMM/SAP/emm_as.c index 1c7ba03f70..32353fa969 100644 --- a/openair3/NAS/UE/EMM/SAP/emm_as.c +++ b/openair3/NAS/UE/EMM/SAP/emm_as.c @@ -837,7 +837,7 @@ _emm_as_encode( } /* Allocate memory to the NAS information container */ - info->nas_data = malloc(length * sizeof(Byte_t)); + info->nas_data = malloc(length * sizeof(uint8_t)); if (info->nas_data != NULL) { /* Encode the NAS message */ @@ -889,7 +889,7 @@ _emm_as_encrypt( } /* Allocate memory to the NAS information container */ - info->nas_data = malloc(length * sizeof(Byte_t)); + info->nas_data = malloc(length * sizeof(uint8_t)); if (info->nas_data != NULL) { /* Encrypt the NAS information message */ diff --git a/openair3/NAS/UE/EMM/SAP/emm_asDef.h b/openair3/NAS/UE/EMM/SAP/emm_asDef.h index 4f6182a2c9..531b3e5a69 100644 --- a/openair3/NAS/UE/EMM/SAP/emm_asDef.h +++ b/openair3/NAS/UE/EMM/SAP/emm_asDef.h @@ -229,7 +229,7 @@ typedef struct emm_as_cell_info_s { #define EMM_AS_PLMN_LIST_SIZE 6 PLMN_LIST_T(EMM_AS_PLMN_LIST_SIZE) plmnIDs; /* List of identifiers of available PLMNs */ - Byte_t rat; /* Bitmap of Radio Access Technologies */ + uint8_t rat; /* Bitmap of Radio Access Technologies */ tac_t tac; /* Tracking Area Code */ ci_t cellID; /* cell identity */ } emm_as_cell_info_t; diff --git a/openair3/NAS/UE/EMM/emmData.h b/openair3/NAS/UE/EMM/emmData.h index d90820edf9..37f407fec4 100644 --- a/openair3/NAS/UE/EMM/emmData.h +++ b/openair3/NAS/UE/EMM/emmData.h @@ -345,12 +345,12 @@ typedef struct emm_data_s { * ---------------------------- * see "Non Access Stratum Configuration" in USIM API header file */ - Byte_t NAS_SignallingPriority; - Byte_t NMO_I_Behaviour; - Byte_t AttachWithImsi; - Byte_t MinimumPeriodicSearchTimer; - Byte_t ExtendedAccessBarring; - Byte_t Timer_T3245_Behaviour; + uint8_t NAS_SignallingPriority; + uint8_t NMO_I_Behaviour; + uint8_t AttachWithImsi; + uint8_t MinimumPeriodicSearchTimer; + uint8_t ExtendedAccessBarring; + uint8_t Timer_T3245_Behaviour; /* * EMM data stored in the UE's memory diff --git a/openair3/NAS/UE/nas_itti_messaging.c b/openair3/NAS/UE/nas_itti_messaging.c index 6f64413b70..9a83314352 100644 --- a/openair3/NAS/UE/nas_itti_messaging.c +++ b/openair3/NAS/UE/nas_itti_messaging.c @@ -95,14 +95,16 @@ int nas_itti_protected_msg(const char *buffer, const nas_message_t *msg, const i } #endif -int nas_itti_kenb_refresh_req(const Byte_t kenb[32], int user_id) { +int nas_itti_kenb_refresh_req(const uint8_t kenb[32], int user_id) +{ MessageDef *message_p; message_p = itti_alloc_new_message(TASK_NAS_UE, 0, NAS_KENB_REFRESH_REQ); memcpy(NAS_KENB_REFRESH_REQ(message_p).kenb, kenb, sizeof(NAS_KENB_REFRESH_REQ(message_p).kenb)); return itti_send_msg_to_task(TASK_RRC_UE, NB_eNB_INST + user_id, message_p); } -int nas_itti_cell_info_req(const plmn_t plmnID, const Byte_t rat, int user_id) { +int nas_itti_cell_info_req(const plmn_t plmnID, const uint8_t rat, int user_id) +{ MessageDef *message_p; message_p = itti_alloc_new_message(TASK_NAS_UE, 0, NAS_CELL_SELECTION_REQ); NAS_CELL_SELECTION_REQ(message_p).plmnID = plmnID; @@ -110,7 +112,14 @@ int nas_itti_cell_info_req(const plmn_t plmnID, const Byte_t rat, int user_id) { return itti_send_msg_to_task(TASK_RRC_UE, NB_eNB_INST + user_id, message_p); } -int nas_itti_nas_establish_req(as_cause_t cause, as_call_type_t type, as_stmsi_t s_tmsi, plmn_t plmnID, Byte_t *data, uint32_t length, int user_id) { +int nas_itti_nas_establish_req(as_cause_t cause, + as_call_type_t type, + as_stmsi_t s_tmsi, + plmn_t plmnID, + uint8_t *data, + uint32_t length, + int user_id) +{ MessageDef *message_p; message_p = itti_alloc_new_message(TASK_NAS_UE, 0, NAS_CONN_ESTABLI_REQ); NAS_CONN_ESTABLI_REQ(message_p).cause = cause; diff --git a/openair3/NAS/UE/nas_itti_messaging.h b/openair3/NAS/UE/nas_itti_messaging.h index 7fdda32960..96cf1df60a 100644 --- a/openair3/NAS/UE/nas_itti_messaging.h +++ b/openair3/NAS/UE/nas_itti_messaging.h @@ -38,11 +38,17 @@ int nas_itti_plain_msg( int nas_itti_protected_msg(const char *buffer, const nas_message_t *msg, const int lengthP, const int instance); -int nas_itti_kenb_refresh_req(const Byte_t kenb[32], int user_id); +int nas_itti_kenb_refresh_req(const uint8_t kenb[32], int user_id); -int nas_itti_cell_info_req(const plmn_t plmnID, const Byte_t rat, int user_id); +int nas_itti_cell_info_req(const plmn_t plmnID, const uint8_t rat, int user_id); -int nas_itti_nas_establish_req(as_cause_t cause, as_call_type_t type, as_stmsi_t s_tmsi, plmn_t plmnID, Byte_t *data_pP, uint32_t lengthP, int user_id); +int nas_itti_nas_establish_req(as_cause_t cause, + as_call_type_t type, + as_stmsi_t s_tmsi, + plmn_t plmnID, + uint8_t *data_pP, + uint32_t lengthP, + int user_id); int nas_itti_ul_data_req(const uint32_t ue_idP, void *const data_pP, const uint32_t lengthP, int user_id); diff --git a/openair3/NAS/UE/nas_proc.c b/openair3/NAS/UE/nas_proc.c index 65b531342a..3fdef5ce73 100644 --- a/openair3/NAS/UE/nas_proc.c +++ b/openair3/NAS/UE/nas_proc.c @@ -311,11 +311,11 @@ int nas_proc_get_msisdn(nas_user_t *user, char *msisdn_str, int *ton_npi) if (msisdn != NULL) { union { struct { - Byte_t ext:1; - Byte_t ton:3; - Byte_t npi:4; + uint8_t ext: 1; + uint8_t ton: 3; + uint8_t npi: 4; } ext_ton_npi; - Byte_t type; + uint8_t type; } converter; converter.ext_ton_npi.ext = msisdn->ext; converter.ext_ton_npi.ton = msisdn->ton; @@ -1058,7 +1058,7 @@ int nas_proc_cell_info(nas_user_t *user, int found, tac_t tac, ci_t ci, AcT_t Ac ** Others: None ** ** ** ***************************************************************************/ -int nas_proc_establish_cnf(nas_user_t *user, const Byte_t *data, uint32_t len) +int nas_proc_establish_cnf(nas_user_t *user, const uint8_t *data, uint32_t len) { LOG_FUNC_IN; @@ -1236,7 +1236,7 @@ int nas_proc_ul_transfer_rej(nas_user_t *user) ** Others: None ** ** ** ***************************************************************************/ -int nas_proc_dl_transfer_ind(nas_user_t *user, const Byte_t *data, uint32_t len) +int nas_proc_dl_transfer_ind(nas_user_t *user, const uint8_t *data, uint32_t len) { LOG_FUNC_IN; diff --git a/openair3/NAS/UE/nas_proc.h b/openair3/NAS/UE/nas_proc.h index 1f8a88d46d..ec2a2ce2d6 100644 --- a/openair3/NAS/UE/nas_proc.h +++ b/openair3/NAS/UE/nas_proc.h @@ -113,15 +113,13 @@ int nas_proc_activate_pdn(nas_user_t *user, int cid); */ int nas_proc_cell_info(nas_user_t *user, int found, tac_t tac, ci_t ci, AcT_t AcT, uint8_t rsrq, uint8_t rsrp); -int nas_proc_establish_cnf(nas_user_t *user, const Byte_t *data, uint32_t len); +int nas_proc_establish_cnf(nas_user_t *user, const uint8_t *data, uint32_t len); int nas_proc_establish_rej(nas_user_t *user); int nas_proc_release_ind(nas_user_t *user, int cause); int nas_proc_ul_transfer_cnf(nas_user_t *user); int nas_proc_ul_transfer_rej(nas_user_t *user); -int nas_proc_dl_transfer_ind(nas_user_t *user, const Byte_t *data, uint32_t len); - - +int nas_proc_dl_transfer_ind(nas_user_t *user, const uint8_t *data, uint32_t len); #endif /* __NAS_PROC_H__*/ diff --git a/openair3/UICC/CMakeLists.txt b/openair3/UICC/CMakeLists.txt new file mode 100644 index 0000000000..0570c7238f --- /dev/null +++ b/openair3/UICC/CMakeLists.txt @@ -0,0 +1,2 @@ +add_library(lib_uicc OBJECT usim_interface.c) +target_include_directories(lib_uicc PRIVATE .)