From c0919d85333ebca0ce3efa14347a33e6c3231222 Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Mon, 21 Oct 2024 17:40:05 +0200 Subject: [PATCH 01/35] Cleanup long time commented out lines in CMakeLists.txt --- CMakeLists.txt | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e6147ce3fb..211af664fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -873,9 +873,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 @@ -936,13 +933,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 ) @@ -1233,7 +1226,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 @@ -1248,7 +1240,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 @@ -2306,10 +2297,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 From 21df50b31ebb813ba26d7330af274c1a875c5daf Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Tue, 24 Sep 2024 11:13:49 +0200 Subject: [PATCH 02/35] Cleanup unused imsi member in gNB_RRC_UE_s --- openair2/RRC/NR/nr_rrc_defs.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/openair2/RRC/NR/nr_rrc_defs.h b/openair2/RRC/NR/nr_rrc_defs.h index b33b2c158c..6b5cf979e0 100644 --- a/openair2/RRC/NR/nr_rrc_defs.h +++ b/openair2/RRC/NR/nr_rrc_defs.h @@ -203,8 +203,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; From f87388099d93bc58f9a07618421ce59643a6ba77 Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Tue, 12 Nov 2024 23:33:40 +0100 Subject: [PATCH 03/35] Replace type Byte_t used in NAS directly with uint8_t * the goal is to simplify the code --- openair2/COMMON/as_message.h | 6 +- openair2/COMMON/commonDef.h | 77 +++++++++++-------- openair2/RRC/LTE/defs_NB_IoT.h | 2 +- openair2/RRC/LTE/rrc_defs.h | 2 +- openair3/NAS/COMMON/API/NETWORK/as_message.c | 22 +++--- openair3/NAS/NR_UE/nr_nas_msg.c | 16 ++-- openair3/NAS/TEST/AS_SIMULATOR/as_process.c | 8 +- openair3/NAS/TEST/NETWORK/network_simulator.c | 18 ++--- openair3/NAS/UE/API/USIM/usim_api.h | 37 +++++---- openair3/NAS/UE/EMM/SAP/emm_as.c | 4 +- openair3/NAS/UE/EMM/SAP/emm_asDef.h | 2 +- openair3/NAS/UE/EMM/emmData.h | 12 +-- openair3/NAS/UE/nas_itti_messaging.c | 15 +++- openair3/NAS/UE/nas_itti_messaging.h | 12 ++- openair3/NAS/UE/nas_proc.c | 12 +-- openair3/NAS/UE/nas_proc.h | 6 +- 16 files changed, 140 insertions(+), 111 deletions(-) diff --git a/openair2/COMMON/as_message.h b/openair2/COMMON/as_message.h index e4061f5c3d..10e2de5f19 100644 --- a/openair2/COMMON/as_message.h +++ b/openair2/COMMON/as_message.h @@ -167,7 +167,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 */ @@ -216,7 +216,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 { @@ -230,7 +230,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 d180c47c87..fd6f3410ff 100644 --- a/openair2/RRC/LTE/rrc_defs.h +++ b/openair2/RRC/LTE/rrc_defs.h @@ -812,7 +812,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/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/NR_UE/nr_nas_msg.c b/openair3/NAS/NR_UE/nr_nas_msg.c index 5e9ce65194..f198077f69 100644 --- a/openair3/NAS/NR_UE/nr_nas_msg.c +++ b/openair3/NAS/NR_UE/nr_nas_msg.c @@ -558,7 +558,7 @@ void generateRegistrationRequest(as_nas_info_t *initialNasMsg, nr_ue_nas_t *nas) 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); @@ -603,7 +603,7 @@ void generateServiceRequest(as_nas_info_t *initialNasMsg, nr_ue_nas_t *nas) size += fill_fgstmsi(&mm_msg->service_request.fiveg_s_tmsi, nas->guti); /* message encoding */ - initialNasMsg->nas_data = (Byte_t *)malloc(size * sizeof(Byte_t)); + initialNasMsg->nas_data = malloc_or_fail(size * sizeof(*initialNasMsg->nas_data)); if (security_protected) { // security protected encoding int security_header_len = nas_protected_security_header_encode((char *)(initialNasMsg->nas_data), &(nas_msg.header), size); @@ -668,7 +668,7 @@ void generateIdentityResponse(as_nas_info_t *initialNasMsg, uint8_t identitytype } // 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); } @@ -704,7 +704,7 @@ static void generateAuthenticationResp(nr_ue_nas_t *nas, as_nas_info_t *initialN mm_msg->fgs_auth_response.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); // Free res value after encode @@ -756,7 +756,7 @@ static void generateSecurityModeComplete(nr_ue_nas_t *nas, as_nas_info_t *initia 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); @@ -884,7 +884,7 @@ static void generateRegistrationComplete(nr_ue_nas_t *nas, } // 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) */ @@ -981,7 +981,7 @@ static void generateDeregistrationRequest(nr_ue_nas_t *nas, as_nas_info_t *initi size += fill_guti(&dereg_req->fgsmobileidentity, nas->guti); // encode the message - initialNasMsg->nas_data = calloc(size, sizeof(Byte_t)); + initialNasMsg->nas_data = calloc_or_fail(size, sizeof(*initialNasMsg->nas_data)); int security_header_len = nas_protected_security_header_encode((char *)(initialNasMsg->nas_data), &nas_msg.header, size); initialNasMsg->length = @@ -1089,7 +1089,7 @@ static void generatePduSessionEstablishRequest(nr_ue_nas_t *nas, as_nas_info_t * size += (1 + 1 + dnnSize + 1); // encode the message - initialNasMsg->nas_data = (Byte_t *)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); initialNasMsg->length = diff --git a/openair3/NAS/TEST/AS_SIMULATOR/as_process.c b/openair3/NAS/TEST/AS_SIMULATOR/as_process.c index 20b7a7ce35..a80a3355b9 100644 --- a/openair3/NAS/TEST/AS_SIMULATOR/as_process.c +++ b/openair3/NAS/TEST/AS_SIMULATOR/as_process.c @@ -173,7 +173,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, @@ -250,7 +250,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); @@ -360,7 +360,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, @@ -426,7 +426,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); 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/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/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 e7707a8ccd..88cdc40a7b 100644 --- a/openair3/NAS/UE/nas_itti_messaging.c +++ b/openair3/NAS/UE/nas_itti_messaging.c @@ -96,14 +96,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; @@ -111,7 +113,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 79b70394f0..a82a628519 100644 --- a/openair3/NAS/UE/nas_itti_messaging.h +++ b/openair3/NAS/UE/nas_itti_messaging.h @@ -47,11 +47,17 @@ int nas_itti_protected_msg( # if defined(NAS_BUILT_IN_UE) -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__*/ From 45da0c8a81d8f63a2d1ae91ab4a6c68a87429a77 Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Thu, 28 Nov 2024 09:55:49 +0100 Subject: [PATCH 04/35] Cleanup long time commented out code in openair3/NAS/TEST/AS_SIMULATOR/as_process.c --- openair3/NAS/TEST/AS_SIMULATOR/as_process.c | 789 -------------------- 1 file changed, 789 deletions(-) diff --git a/openair3/NAS/TEST/AS_SIMULATOR/as_process.c b/openair3/NAS/TEST/AS_SIMULATOR/as_process.c index a80a3355b9..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), @@ -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'); @@ -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, @@ -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); @@ -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] -*/ From ccff518b2caa67c12fdec8071fbfd559863ca2c0 Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Tue, 1 Oct 2024 13:08:29 +0200 Subject: [PATCH 05/35] Add include for memcpy to TLVEncoder.h --- openair3/NAS/COMMON/UTIL/TLVEncoder.h | 1 + 1 file changed, 1 insertion(+) 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 { \ From 047b4eea8b57b592438fc84c4853d39748c48562 Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Mon, 11 Nov 2024 14:58:30 +0100 Subject: [PATCH 06/35] Refactor PDU Session Establish Accept IEI * use NAS macro to define enums and text description --- .../ESM/MSG/PduSessionEstablishmentAccept.h | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/openair3/NAS/COMMON/ESM/MSG/PduSessionEstablishmentAccept.h b/openair3/NAS/COMMON/ESM/MSG/PduSessionEstablishmentAccept.h index c283079998..23c55cf170 100644 --- a/openair3/NAS/COMMON/ESM/MSG/PduSessionEstablishmentAccept.h +++ b/openair3/NAS/COMMON/ESM/MSG/PduSessionEstablishmentAccept.h @@ -23,19 +23,25 @@ #define PDU_SESSION_ESTABLISHMENT_ACCEPT_H_ #include +#include "NR_NAS_defs.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*/ From dbd2d8574e03331c703a18436d4ff896430e9ebb Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Mon, 11 Nov 2024 14:59:06 +0100 Subject: [PATCH 07/35] Use PDU Session Establish Accept IEI text definition * replace multiple log lines with one --- .../COMMON/ESM/MSG/PduSessionEstablishmentAccept.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/openair3/NAS/COMMON/ESM/MSG/PduSessionEstablishmentAccept.c b/openair3/NAS/COMMON/ESM/MSG/PduSessionEstablishmentAccept.c index aa19cae2e4..ab5ce76598 100644 --- a/openair3/NAS/COMMON/ESM/MSG/PduSessionEstablishmentAccept.c +++ b/openair3/NAS/COMMON/ESM/MSG/PduSessionEstablishmentAccept.c @@ -116,14 +116,13 @@ void capture_pdu_session_establishment_accept_msg(uint8_t *buffer, uint32_t msg_ /* 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 */ - 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 */ @@ -171,52 +170,44 @@ void capture_pdu_session_establishment_accept_msg(uint8_t *buffer, uint32_t msg_ 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]; @@ -232,7 +223,6 @@ void capture_pdu_session_establishment_accept_msg(uint8_t *buffer, uint32_t msg_ } default: - LOG_T(NAS, "PDU SESSION ESTABLISHMENT ACCEPT - Not known IE\n"); curPtr = buffer + msg_length; // we force stop processing break; } From 8215aa60bad5c4bc99224cd0c1cb1e493d8a4210 Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Fri, 20 Sep 2024 16:22:06 +0200 Subject: [PATCH 08/35] Explicit protocol_discriminator size in fgs_nas_message_security_header_t * size of fgs_nas_message_security_header_t is platform-depending while protocol_discriminator must be 1 byte * fgs_protocol_discriminator_t stays as enum type --- openair3/NAS/NR_UE/nr_nas_msg.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openair3/NAS/NR_UE/nr_nas_msg.h b/openair3/NAS/NR_UE/nr_nas_msg.h index 0e324052ad..cb4ec6a594 100644 --- a/openair3/NAS/NR_UE/nr_nas_msg.h +++ b/openair3/NAS/NR_UE/nr_nas_msg.h @@ -101,7 +101,7 @@ typedef struct { /* Structure of security protected header */ typedef struct { - fgs_protocol_discriminator_t protocol_discriminator; + uint8_t protocol_discriminator; uint8_t security_header_type; uint32_t message_authentication_code; uint8_t sequence_number; From 0fd0a4fcae6607a61cf34b61dd6fa4257f41780a Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Mon, 30 Sep 2024 16:34:04 +0200 Subject: [PATCH 09/35] NAS: Minor comments and logs --- .../COMMON/ESM/MSG/PduSessionEstablishmentAccept.c | 8 ++++++++ .../COMMON/ESM/MSG/PduSessionEstablishmentAccept.h | 11 +++++++---- openair3/NAS/NR_UE/nr_nas_msg.h | 1 + 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/openair3/NAS/COMMON/ESM/MSG/PduSessionEstablishmentAccept.c b/openair3/NAS/COMMON/ESM/MSG/PduSessionEstablishmentAccept.c index ab5ce76598..87994f383f 100644 --- a/openair3/NAS/COMMON/ESM/MSG/PduSessionEstablishmentAccept.c +++ b/openair3/NAS/COMMON/ESM/MSG/PduSessionEstablishmentAccept.c @@ -56,12 +56,17 @@ static int capture_ipv6_addr(const uint8_t *addr, char *ip, size_t len) addr[7]); } +/** + * @brief PDU session establishment accept (8.3.2 of 3GPP TS 24.501) + * network to UE + */ 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; + // Security protected NAS header (7 bytes) sec_nas_hdr.epd = *curPtr++; sec_nas_hdr.sht = *curPtr++; uint32_t tmp; @@ -69,6 +74,7 @@ void capture_pdu_session_establishment_accept_msg(uint8_t *buffer, uint32_t msg_ sec_nas_hdr.mac = htonl(tmp); curPtr += sizeof(sec_nas_hdr.mac); sec_nas_hdr.sqn = *curPtr++; + // Security protected plain NAS message sec_nas_msg.epd = *curPtr++; sec_nas_msg.sht = *curPtr++; sec_nas_msg.msg_type = *curPtr++; @@ -144,6 +150,8 @@ void capture_pdu_session_establishment_accept_msg(uint8_t *buffer, uint32_t msg_ capture_ipv4_addr(&addr[0], ip, sizeof(ip)); tun_config(1, ip, NULL, "oaitun_ue"); setup_ue_ipv4_route(1, ip, "oaitun_ue"); + LOG_I(NAS, "Received PDU Session Establishment Accept, UE IP: %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++; diff --git a/openair3/NAS/COMMON/ESM/MSG/PduSessionEstablishmentAccept.h b/openair3/NAS/COMMON/ESM/MSG/PduSessionEstablishmentAccept.h index 23c55cf170..8576418e21 100644 --- a/openair3/NAS/COMMON/ESM/MSG/PduSessionEstablishmentAccept.h +++ b/openair3/NAS/COMMON/ESM/MSG/PduSessionEstablishmentAccept.h @@ -120,10 +120,13 @@ typedef struct session_ambr_s { /* 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 */ diff --git a/openair3/NAS/NR_UE/nr_nas_msg.h b/openair3/NAS/NR_UE/nr_nas_msg.h index cb4ec6a594..7d6730a297 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 */ From c0583be24e77a8a55d48cf30ee73e2b5ed10e527 Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Tue, 12 Nov 2024 13:27:29 +0100 Subject: [PATCH 10/35] Migrated NAS 5GS (5GMM & 5GSM) to NR folders and refactor CMakeLists.txt files This commit is introducing the following macro changes: (1) Migrate NAS 5GS lib files to a new 5GS subfolder in NR_UE and organize NAS 5GS lib messages into 5GMM and 5GSM subfolders. A nested CMake structure was implemented and CMakeLists.txt were added whenever necessary. This is effectively separating 5GS libraries from LTE libraries. (2) In order to simplify the separation of 5GS libs from LTE libs, remaining dependencies from NAS LTE (e.g. nas_ue_task.c, ue-idx-standalone) were removed in the process (3) ExtendedProtocolDiscriminator.c/.h and SpareHalfOctet.c/.h were deleted and affected types were replaced with simple integer types (4) Cleanup: unused definitions and libs (e.g. LIB_5GNAS_GNB) were removed (5) Update doc/Doxyfile (6) clang-formatted the migrated files in the process (7) Update includes of headers in affected files --- CMakeLists.txt | 74 +--------- doc/Doxyfile | 36 +---- executables/nr-uesoftmodem.h | 1 - openair3/CMakeLists.txt | 3 +- openair3/NAS/CMakeLists.txt | 2 + openair3/NAS/COMMON/CMakeLists.txt | 2 +- openair3/NAS/COMMON/EMM/MSG/CMakeLists.txt | 10 -- openair3/NAS/COMMON/IES/CMakeLists.txt | 11 +- .../IES/ExtendedProtocolDiscriminator.c | 50 ------- .../IES/ExtendedProtocolDiscriminator.h | 48 ------ openair3/NAS/COMMON/IES/SpareHalfOctet.c | 50 ------- openair3/NAS/COMMON/IES/SpareHalfOctet.h | 51 ------- openair3/NAS/COMMON/UTIL/CMakeLists.txt | 6 + .../NAS/NR_UE/5GS/5GMM/IES/CMakeLists.txt | 9 ++ .../5GS/5GMM}/IES/FGCNasMessageContainer.c | 10 +- .../5GS/5GMM}/IES/FGCNasMessageContainer.h | 1 - .../5GS/5GMM}/IES/FGMMCapability.c | 16 +- .../5GS/5GMM}/IES/FGMMCapability.h | 4 - .../5GS/5GMM}/IES/FGSDeregistrationType.h | 0 .../5GS/5GMM}/IES/FGSMobileIdentity.c | 75 ++++------ .../5GS/5GMM}/IES/FGSMobileIdentity.h | 138 +++++++++--------- .../5GS/5GMM}/IES/FGSRegistrationResult.c | 10 +- .../5GS/5GMM}/IES/FGSRegistrationResult.h | 14 +- .../5GS/5GMM}/IES/FGSRegistrationType.c | 5 +- .../5GS/5GMM}/IES/FGSRegistrationType.h | 5 +- .../5GS/5GMM}/IES/NrUESecurityCapability.c | 33 ++--- .../5GS/5GMM}/IES/NrUESecurityCapability.h | 3 - .../5GS/5GMM}/IES/SORTransparentContainer.c | 19 +-- .../5GS/5GMM}/IES/SORTransparentContainer.h | 1 - .../NAS/NR_UE/5GS/5GMM/MSG/CMakeLists.txt | 13 ++ .../5GS/5GMM}/MSG/FGSAuthenticationResponse.c | 11 +- .../5GS/5GMM}/MSG/FGSAuthenticationResponse.h | 16 +- .../FGSDeregistrationRequestUEOriginating.c | 10 +- .../FGSDeregistrationRequestUEOriginating.h | 16 +- .../5GS/5GMM}/MSG/FGSIdentityResponse.c | 16 +- .../5GS/5GMM}/MSG/FGSIdentityResponse.h | 19 +-- .../5GMM}/MSG/FGSNASSecurityModeComplete.c | 41 +++--- .../5GMM}/MSG/FGSNASSecurityModeComplete.h | 24 ++- .../5GS/5GMM}/MSG/FGSUplinkNasTransport.c | 69 ++++----- .../5GS/5GMM}/MSG/FGSUplinkNasTransport.h | 42 +++--- .../5GS/5GMM}/MSG/RegistrationAccept.c | 7 +- .../5GS/5GMM}/MSG/RegistrationAccept.h | 14 +- .../5GS/5GMM}/MSG/RegistrationComplete.c | 18 +-- .../5GS/5GMM}/MSG/RegistrationComplete.h | 20 +-- .../5GS/5GMM}/MSG/RegistrationRequest.c | 43 +++--- .../5GS/5GMM}/MSG/RegistrationRequest.h | 80 +++++----- .../5GS/5GMM}/MSG/fgs_service_request.c | 0 .../5GS/5GMM}/MSG/fgs_service_request.h | 3 - .../NAS/NR_UE/5GS/5GSM/MSG/CMakeLists.txt | 3 + .../5GSM}/MSG/PduSessionEstablishRequest.c | 14 +- .../5GSM}/MSG/PduSessionEstablishRequest.h | 27 ++-- .../5GSM}/MSG/PduSessionEstablishmentAccept.c | 19 +-- .../5GSM}/MSG/PduSessionEstablishmentAccept.h | 80 +++++----- openair3/NAS/NR_UE/5GS/CMakeLists.txt | 7 + .../EMM => NR_UE/5GS}/tests/CMakeLists.txt | 5 +- .../EMM => NR_UE/5GS}/tests/nas_lib_test.c | 0 openair3/NAS/NR_UE/CMakeLists.txt | 19 +++ openair3/NAS/NR_UE/nr_nas_msg.c | 2 +- openair3/NAS/NR_UE/nr_nas_msg.h | 2 +- openair3/NAS/UE/API/CMakeLists.txt | 1 + openair3/NAS/UE/API/USIM/CMakeLists.txt | 9 ++ openair3/NAS/UE/CMakeLists.txt | 1 + openair3/UICC/CMakeLists.txt | 2 + 63 files changed, 475 insertions(+), 865 deletions(-) delete mode 100644 openair3/NAS/COMMON/EMM/MSG/CMakeLists.txt delete mode 100644 openair3/NAS/COMMON/IES/ExtendedProtocolDiscriminator.c delete mode 100644 openair3/NAS/COMMON/IES/ExtendedProtocolDiscriminator.h delete mode 100644 openair3/NAS/COMMON/IES/SpareHalfOctet.c delete mode 100644 openair3/NAS/COMMON/IES/SpareHalfOctet.h create mode 100644 openair3/NAS/COMMON/UTIL/CMakeLists.txt create mode 100644 openair3/NAS/NR_UE/5GS/5GMM/IES/CMakeLists.txt rename openair3/NAS/{COMMON => NR_UE/5GS/5GMM}/IES/FGCNasMessageContainer.c (92%) rename openair3/NAS/{COMMON => NR_UE/5GS/5GMM}/IES/FGCNasMessageContainer.h (99%) rename openair3/NAS/{COMMON => NR_UE/5GS/5GMM}/IES/FGMMCapability.c (90%) rename openair3/NAS/{COMMON => NR_UE/5GS/5GMM}/IES/FGMMCapability.h (99%) rename openair3/NAS/{COMMON => NR_UE/5GS/5GMM}/IES/FGSDeregistrationType.h (100%) rename openair3/NAS/{COMMON => NR_UE/5GS/5GMM}/IES/FGSMobileIdentity.c (81%) rename openair3/NAS/{COMMON => NR_UE/5GS/5GMM}/IES/FGSMobileIdentity.h (64%) rename openair3/NAS/{COMMON => NR_UE/5GS/5GMM}/IES/FGSRegistrationResult.c (93%) rename openair3/NAS/{COMMON => NR_UE/5GS/5GMM}/IES/FGSRegistrationResult.h (93%) rename openair3/NAS/{COMMON => NR_UE/5GS/5GMM}/IES/FGSRegistrationType.c (94%) rename openair3/NAS/{COMMON => NR_UE/5GS/5GMM}/IES/FGSRegistrationType.h (98%) rename openair3/NAS/{COMMON => NR_UE/5GS/5GMM}/IES/NrUESecurityCapability.c (76%) rename openair3/NAS/{COMMON => NR_UE/5GS/5GMM}/IES/NrUESecurityCapability.h (99%) rename openair3/NAS/{COMMON => NR_UE/5GS/5GMM}/IES/SORTransparentContainer.c (84%) rename openair3/NAS/{COMMON => NR_UE/5GS/5GMM}/IES/SORTransparentContainer.h (99%) create mode 100644 openair3/NAS/NR_UE/5GS/5GMM/MSG/CMakeLists.txt rename openair3/NAS/{COMMON/EMM => NR_UE/5GS/5GMM}/MSG/FGSAuthenticationResponse.c (79%) rename openair3/NAS/{COMMON/EMM => NR_UE/5GS/5GMM}/MSG/FGSAuthenticationResponse.h (81%) rename openair3/NAS/{COMMON/EMM => NR_UE/5GS/5GMM}/MSG/FGSDeregistrationRequestUEOriginating.c (89%) rename openair3/NAS/{COMMON/EMM => NR_UE/5GS/5GMM}/MSG/FGSDeregistrationRequestUEOriginating.h (91%) rename openair3/NAS/{COMMON/EMM => NR_UE/5GS/5GMM}/MSG/FGSIdentityResponse.c (83%) rename openair3/NAS/{COMMON/EMM => NR_UE/5GS/5GMM}/MSG/FGSIdentityResponse.h (81%) rename openair3/NAS/{COMMON/EMM => NR_UE/5GS/5GMM}/MSG/FGSNASSecurityModeComplete.c (70%) rename openair3/NAS/{COMMON/EMM => NR_UE/5GS/5GMM}/MSG/FGSNASSecurityModeComplete.h (79%) rename openair3/NAS/{COMMON/EMM => NR_UE/5GS/5GMM}/MSG/FGSUplinkNasTransport.c (71%) rename openair3/NAS/{COMMON/EMM => NR_UE/5GS/5GMM}/MSG/FGSUplinkNasTransport.h (69%) rename openair3/NAS/{COMMON/EMM => NR_UE/5GS/5GMM}/MSG/RegistrationAccept.c (94%) rename openair3/NAS/{COMMON/EMM => NR_UE/5GS/5GMM}/MSG/RegistrationAccept.h (84%) rename openair3/NAS/{COMMON/EMM => NR_UE/5GS/5GMM}/MSG/RegistrationComplete.c (78%) rename openair3/NAS/{COMMON/EMM => NR_UE/5GS/5GMM}/MSG/RegistrationComplete.h (81%) rename openair3/NAS/{COMMON/EMM => NR_UE/5GS/5GMM}/MSG/RegistrationRequest.c (78%) rename openair3/NAS/{COMMON/EMM => NR_UE/5GS/5GMM}/MSG/RegistrationRequest.h (57%) rename openair3/NAS/{COMMON/EMM => NR_UE/5GS/5GMM}/MSG/fgs_service_request.c (100%) rename openair3/NAS/{COMMON/EMM => NR_UE/5GS/5GMM}/MSG/fgs_service_request.h (95%) create mode 100644 openair3/NAS/NR_UE/5GS/5GSM/MSG/CMakeLists.txt rename openair3/NAS/{COMMON/ESM => NR_UE/5GS/5GSM}/MSG/PduSessionEstablishRequest.c (95%) rename openair3/NAS/{COMMON/ESM => NR_UE/5GS/5GSM}/MSG/PduSessionEstablishRequest.h (75%) rename openair3/NAS/{COMMON/ESM => NR_UE/5GS/5GSM}/MSG/PduSessionEstablishmentAccept.c (93%) rename openair3/NAS/{COMMON/ESM => NR_UE/5GS/5GSM}/MSG/PduSessionEstablishmentAccept.h (74%) create mode 100644 openair3/NAS/NR_UE/5GS/CMakeLists.txt rename openair3/NAS/{COMMON/EMM => NR_UE/5GS}/tests/CMakeLists.txt (74%) rename openair3/NAS/{COMMON/EMM => NR_UE/5GS}/tests/nas_lib_test.c (100%) create mode 100644 openair3/NAS/NR_UE/CMakeLists.txt create mode 100644 openair3/NAS/UE/API/CMakeLists.txt create mode 100644 openair3/NAS/UE/API/USIM/CMakeLists.txt create mode 100644 openair3/NAS/UE/CMakeLists.txt create mode 100644 openair3/UICC/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 211af664fd..9e2763671d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1477,6 +1477,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 @@ -1521,6 +1522,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 @@ -1560,10 +1562,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 @@ -1752,61 +1750,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 @@ -1846,15 +1789,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 @@ -2075,7 +2009,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 ) @@ -2084,11 +2017,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) add_dependencies( nr-uesoftmodem ldpc_orig ldpc_optim ldpc_optim8seg ldpc ) diff --git a/doc/Doxyfile b/doc/Doxyfile index 564c43bb3f..096c0882ff 100644 --- a/doc/Doxyfile +++ b/doc/Doxyfile @@ -1134,7 +1134,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 \ @@ -1275,12 +1275,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 \ @@ -1290,7 +1288,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 \ @@ -1302,17 +1299,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 \ @@ -1322,13 +1316,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 \ @@ -1354,7 +1349,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 \ @@ -1368,7 +1362,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 \ @@ -1392,12 +1385,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 \ @@ -1407,18 +1398,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 \ @@ -1433,12 +1421,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 \ @@ -1448,12 +1434,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 \ @@ -1467,13 +1451,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 \ @@ -1481,7 +1462,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 \ @@ -1497,16 +1477,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 \ @@ -1519,14 +1496,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 \ @@ -1581,7 +1556,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 40ff2075a5..c689e6531d 100644 --- a/executables/nr-uesoftmodem.h +++ b/executables/nr-uesoftmodem.h @@ -47,7 +47,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/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/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/IES/CMakeLists.txt b/openair3/NAS/COMMON/IES/CMakeLists.txt index 99df08e7b0..bf80586fbc 100644 --- a/openair3/NAS/COMMON/IES/CMakeLists.txt +++ b/openair3/NAS/COMMON/IES/CMakeLists.txt @@ -1,9 +1,8 @@ -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 PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} ) 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/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/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/NR_UE/5GS/5GMM/IES/CMakeLists.txt b/openair3/NAS/NR_UE/5GS/5GMM/IES/CMakeLists.txt new file mode 100644 index 0000000000..0915eed19c --- /dev/null +++ b/openair3/NAS/NR_UE/5GS/5GMM/IES/CMakeLists.txt @@ -0,0 +1,9 @@ +add_library(fgs_5gmm_ies_lib OBJECT + FGSMobileIdentity.c + FGSRegistrationType.c + FGSRegistrationResult.c + FGMMCapability.c + NrUESecurityCapability.c + FGCNasMessageContainer.c + SORTransparentContainer.c +) diff --git a/openair3/NAS/COMMON/IES/FGCNasMessageContainer.c b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGCNasMessageContainer.c similarity index 92% rename from openair3/NAS/COMMON/IES/FGCNasMessageContainer.c rename to openair3/NAS/NR_UE/5GS/5GMM/IES/FGCNasMessageContainer.c index 4e8de951a5..9c317c59d5 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,7 +51,9 @@ 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; @@ -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 99% rename from openair3/NAS/COMMON/IES/FGCNasMessageContainer.h rename to openair3/NAS/NR_UE/5GS/5GMM/IES/FGCNasMessageContainer.h index 19a1679b7e..5e9c8aac12 100644 --- a/openair3/NAS/COMMON/IES/FGCNasMessageContainer.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGCNasMessageContainer.h @@ -51,4 +51,3 @@ int decode_fgc_nas_message_container(FGCNasMessageContainer *nasmessagecontainer 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 90% rename from openair3/NAS/COMMON/IES/FGMMCapability.c rename to openair3/NAS/NR_UE/5GS/5GMM/IES/FGMMCapability.c index ce156e63bf..3a275ced7f 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 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 99% rename from openair3/NAS/COMMON/IES/FGMMCapability.h rename to openair3/NAS/NR_UE/5GS/5GMM/IES/FGMMCapability.h index d427896338..a28ba2ff3b 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); #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 81% rename from openair3/NAS/COMMON/IES/FGSMobileIdentity.c rename to openair3/NAS/NR_UE/5GS/5GMM/IES/FGSMobileIdentity.c index f70dfc66ed..6407448279 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 @@ -115,8 +114,7 @@ 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); + decoded_rc = decode_guti_5gs_mobile_identity(&fgsmobileidentity->guti, buffer + decoded); } else { AssertFatal(false, "Mobile Identity encoding of type %d not implemented\n", typeofidentity); } @@ -146,18 +144,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 +163,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 +187,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 +212,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 >> 3; + 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) { 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 +245,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) { 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,15 +269,15 @@ 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'); + 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; } @@ -310,17 +292,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 64% rename from openair3/NAS/COMMON/IES/FGSMobileIdentity.h rename to openair3/NAS/NR_UE/5GS/5GMM/IES/FGSMobileIdentity.h index e4747461e9..a66b74dc51 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,6 +146,7 @@ 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); @@ -157,4 +156,3 @@ int encode_stmsi_5gs_mobile_identity(uint8_t *buffer, Stmsi5GSMobileIdentity_t * 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 93% rename from openair3/NAS/COMMON/IES/FGSRegistrationResult.c rename to openair3/NAS/NR_UE/5GS/5GMM/IES/FGSRegistrationResult.c index e580b14409..88eb1b810b 100644 --- a/openair3/NAS/COMMON/IES/FGSRegistrationResult.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSRegistrationResult.c @@ -32,19 +32,17 @@ #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; } @@ -53,10 +51,8 @@ uint16_t encode_fgs_registration_result(FGSRegistrationResult *fgsregistrationre 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 93% rename from openair3/NAS/COMMON/IES/FGSRegistrationResult.h rename to openair3/NAS/NR_UE/5GS/5GMM/IES/FGSRegistrationResult.h index 0a2dedc2e5..b792dad13c 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); 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 94% rename from openair3/NAS/COMMON/IES/FGSRegistrationType.c rename to openair3/NAS/NR_UE/5GS/5GMM/IES/FGSRegistrationType.c index 7f1c3ae667..d50d7bc852 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" @@ -56,10 +55,8 @@ int encode_5gs_registration_type(FGSRegistrationType *fgsregistrationtype) 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 98% rename from openair3/NAS/COMMON/IES/FGSRegistrationType.h rename to openair3/NAS/NR_UE/5GS/5GMM/IES/FGSRegistrationType.h index a548d45d93..4298a33504 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 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 76% rename from openair3/NAS/COMMON/IES/NrUESecurityCapability.c rename to openair3/NAS/NR_UE/5GS/5GMM/IES/NrUESecurityCapability.c index 6c0ff7e7c7..d069b50a39 100644 --- a/openair3/NAS/COMMON/IES/NrUESecurityCapability.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/IES/NrUESecurityCapability.c @@ -27,37 +27,32 @@ * \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 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 99% rename from openair3/NAS/COMMON/IES/NrUESecurityCapability.h rename to openair3/NAS/NR_UE/5GS/5GMM/IES/NrUESecurityCapability.h index 10aa0cf0ea..b772feeba7 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,6 @@ typedef struct { uint8_t EIA; } NrUESecurityCapability; - int encode_nrue_security_capability(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 84% rename from openair3/NAS/COMMON/IES/SORTransparentContainer.c rename to openair3/NAS/NR_UE/5GS/5GMM/IES/SORTransparentContainer.c index 3ab2a14c3d..3bbcb89f92 100644 --- a/openair3/NAS/COMMON/IES/SORTransparentContainer.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/IES/SORTransparentContainer.c @@ -47,14 +47,15 @@ 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); @@ -67,7 +68,7 @@ int encode_sor_transparent_container(SORTransparentContainer *sortransparentcont 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 +77,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 +102,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 99% rename from openair3/NAS/COMMON/IES/SORTransparentContainer.h rename to openair3/NAS/NR_UE/5GS/5GMM/IES/SORTransparentContainer.h index 587419b1f9..652710c0b3 100644 --- a/openair3/NAS/COMMON/IES/SORTransparentContainer.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/IES/SORTransparentContainer.h @@ -42,4 +42,3 @@ int decode_sor_transparent_container(SORTransparentContainer *sortransparentcont 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..fab8d6b6ff --- /dev/null +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/CMakeLists.txt @@ -0,0 +1,13 @@ +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_include_directories(fgs_5gmm_lib PUBLIC . ../IES) diff --git a/openair3/NAS/COMMON/EMM/MSG/FGSAuthenticationResponse.c b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSAuthenticationResponse.c similarity index 79% rename from openair3/NAS/COMMON/EMM/MSG/FGSAuthenticationResponse.c rename to openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSAuthenticationResponse.c index 5e1ff25151..d93f03aed5 100644 --- a/openair3/NAS/COMMON/EMM/MSG/FGSAuthenticationResponse.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSAuthenticationResponse.c @@ -37,20 +37,19 @@ #include "FGSAuthenticationResponse.h" - int encode_fgs_authentication_response(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 81% rename from openair3/NAS/COMMON/EMM/MSG/FGSAuthenticationResponse.h rename to openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSAuthenticationResponse.h index 0acee3382f..d67e43bb7b 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,13 @@ typedef struct fgs_authentication_response_msg_tag { /* Mandatory fields */ - ExtendedProtocolDiscriminator protocoldiscriminator; - SecurityHeaderType securityheadertype:4; - SpareHalfOctet sparehalfoctet:4; - MessageType messagetype; - AuthenticationResponseParameter authenticationresponseparameter; + uint8_t protocoldiscriminator; + SecurityHeaderType securityheadertype: 4; + uint8_t sparehalfoctet: 4; + MessageType messagetype; + AuthenticationResponseParameter authenticationresponseparameter; } fgs_authentication_response_msg; int encode_fgs_authentication_response(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 89% rename from openair3/NAS/COMMON/EMM/MSG/FGSDeregistrationRequestUEOriginating.c rename to openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSDeregistrationRequestUEOriginating.c index af8dfd8c20..b5fdc5591a 100644 --- a/openair3/NAS/COMMON/EMM/MSG/FGSDeregistrationRequestUEOriginating.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSDeregistrationRequestUEOriginating.c @@ -27,13 +27,9 @@ * \version 0.1 */ -#include -#include -#include -#include - #include "FGSDeregistrationRequestUEOriginating.h" #include "NR_NAS_defs.h" +#include int encode_fgs_deregistration_request_ue_originating(fgs_deregistration_request_ue_originating_msg *drr, uint8_t *buffer, @@ -41,9 +37,7 @@ int encode_fgs_deregistration_request_ue_originating(fgs_deregistration_request_ { int encoded = 0; FGSDeregistrationType *dt = &drr->deregistrationtype; - *(buffer + encoded) = ((dt->switchoff & 0x1) << 7) - | ((dt->reregistration_required & 0x1) << 6) - | ((dt->access_type & 0x3) << 4); + *(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 91% rename from openair3/NAS/COMMON/EMM/MSG/FGSDeregistrationRequestUEOriginating.h rename to openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSDeregistrationRequestUEOriginating.h index 2bccd8a5bd..566c00c11c 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,9 +38,9 @@ typedef struct fgs_deregistration_request_ue_originating_msg_tag { /* Mandatory fields */ - ExtendedProtocolDiscriminator protocoldiscriminator; + uint8_t protocoldiscriminator; SecurityHeaderType securityheadertype: 4; - SpareHalfOctet sparehalfoctet: 4; + uint8_t sparehalfoctet: 4; MessageType messagetype; FGSDeregistrationType deregistrationtype; NasKeySetIdentifier naskeysetidentifier; @@ -57,4 +52,3 @@ int encode_fgs_deregistration_request_ue_originating(fgs_deregistration_request_ 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 83% rename from openair3/NAS/COMMON/EMM/MSG/FGSIdentityResponse.c rename to openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSIdentityResponse.c index 4f8f6dd321..573d1022d5 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 - -#include "nas_log.h" - #include "FGSIdentityResponse.h" - +#include int encode_identiy_response(fgs_identiy_response_msg *fgs_identity_reps, uint8_t *buffer, 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 81% rename from openair3/NAS/COMMON/EMM/MSG/FGSIdentityResponse.h rename to openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSIdentityResponse.h index 431293e03e..519e49410e 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_ @@ -50,16 +45,14 @@ typedef struct fgs_identiy_response_msg_tag { /* Mandatory fields */ - ExtendedProtocolDiscriminator protocoldiscriminator; - SecurityHeaderType securityheadertype:4; - SpareHalfOctet sparehalfoctet:4; - MessageType messagetype; - FGSMobileIdentity fgsmobileidentity; + uint8_t protocoldiscriminator; + SecurityHeaderType securityheadertype: 4; + uint8_t sparehalfoctet: 4; + MessageType messagetype; + FGSMobileIdentity fgsmobileidentity; } fgs_identiy_response_msg; int encode_identiy_response(fgs_identiy_response_msg *fgs_identity_reps, uint8_t *buffer, 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 70% rename from openair3/NAS/COMMON/EMM/MSG/FGSNASSecurityModeComplete.c rename to openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSNASSecurityModeComplete.c index e0be56145f..369f3a3e2d 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 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 79% rename from openair3/NAS/COMMON/EMM/MSG/FGSNASSecurityModeComplete.h rename to openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSNASSecurityModeComplete.h index 702dca3dc5..36ec4ed2b2 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,15 @@ */ 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 */ + uint8_t protocoldiscriminator; + SecurityHeaderType securityheadertype: 4; + uint8_t sparehalfoctet: 4; + MessageType messagetype; + 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); #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 71% rename from openair3/NAS/COMMON/EMM/MSG/FGSUplinkNasTransport.c rename to openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSUplinkNasTransport.c index 741ec095c3..26d2e9ad61 100644 --- a/openair3/NAS/COMMON/EMM/MSG/FGSUplinkNasTransport.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSUplinkNasTransport.c @@ -28,13 +28,10 @@ \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) @@ -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 { @@ -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 { @@ -112,41 +108,40 @@ int encode_dnn(OctetString *dnn, uint8_t iei, uint8_t *buffer) int encode_fgs_uplink_nas_transport(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 69% rename from openair3/NAS/COMMON/EMM/MSG/FGSUplinkNasTransport.h rename to openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSUplinkNasTransport.h index 5fabcea173..6c045d7d48 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,29 @@ * 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 */ + uint8_t protocoldiscriminator; + SecurityHeaderType securityheadertype: 4; + uint8_t sparehalfoctet: 4; + MessageType messagetype; + 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); #endif /* ! defined(FGS_UPLINK_NAS_TRANSPORT_H_) */ - - diff --git a/openair3/NAS/COMMON/EMM/MSG/RegistrationAccept.c b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationAccept.c similarity index 94% rename from openair3/NAS/COMMON/EMM/MSG/RegistrationAccept.c rename to openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationAccept.c index d7c5c5d719..b110ca75a3 100644 --- a/openair3/NAS/COMMON/EMM/MSG/RegistrationAccept.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationAccept.c @@ -33,7 +33,6 @@ #include #include - #include "TLVEncoder.h" #include "TLVDecoder.h" #include "RegistrationAccept.h" @@ -45,7 +44,9 @@ int decode_registration_accept(registration_accept_msg *registration_accept, con int decoded_result = 0; /* Decoding mandatory fields */ - if ((decoded_result = decode_fgs_registration_result(®istration_accept->fgsregistrationresult, 0, *(buffer + decoded), len - decoded)) < 0) + if ((decoded_result = + decode_fgs_registration_result(®istration_accept->fgsregistrationresult, 0, *(buffer + decoded), len - decoded)) + < 0) return decoded_result; decoded += decoded_result; @@ -70,7 +71,6 @@ int encode_registration_accept(registration_accept_msg *registration_accept, uin LOG_FUNC_IN; - *(buffer + encoded) = encode_fgs_registration_result(®istration_accept->fgsregistrationresult); encoded = encoded + 2; @@ -84,4 +84,3 @@ int encode_registration_accept(registration_accept_msg *registration_accept, uin // 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 84% rename from openair3/NAS/COMMON/EMM/MSG/RegistrationAccept.h rename to openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationAccept.h index 30c434c662..61c987db4b 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" @@ -52,11 +49,11 @@ typedef struct registration_accept_msg_tag { /* Mandatory fields */ - ExtendedProtocolDiscriminator protocoldiscriminator; - SecurityHeaderType securityheadertype:4; - SpareHalfOctet sparehalfoctet:4; - MessageType messagetype; - FGSRegistrationResult fgsregistrationresult; + uint8_t protocoldiscriminator; + SecurityHeaderType securityheadertype: 4; + uint8_t sparehalfoctet: 4; + MessageType messagetype; + FGSRegistrationResult fgsregistrationresult; /* Optional fields */ FGSMobileIdentity *guti; @@ -67,4 +64,3 @@ int decode_registration_accept(registration_accept_msg *registrationaccept, cons int encode_registration_accept(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 78% rename from openair3/NAS/COMMON/EMM/MSG/RegistrationComplete.c rename to openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationComplete.c index 668e665351..5c1bf38bd8 100644 --- a/openair3/NAS/COMMON/EMM/MSG/RegistrationComplete.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationComplete.c @@ -19,15 +19,8 @@ * 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) @@ -36,7 +29,9 @@ int decode_registration_complete(registration_complete_msg *registration_complet 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(®istration_complete->sortransparentcontainer, 0, buffer + decoded, len - decoded)) + < 0) return decoded_result; else decoded += decoded_result; @@ -50,12 +45,11 @@ int encode_registration_complete(registration_complete_msg *registration_complet int encode_result = 0; 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(®istration_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 81% rename from openair3/NAS/COMMON/EMM/MSG/RegistrationComplete.h rename to openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationComplete.h index 0fbf2abde1..b49cc28dd4 100644 --- a/openair3/NAS/COMMON/EMM/MSG/RegistrationComplete.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationComplete.h @@ -28,35 +28,27 @@ \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; + uint8_t protocoldiscriminator; + SecurityHeaderType securityheadertype: 4; + uint8_t sparehalfoctet: 4; + MessageType messagetype; /* Optional fields */ - SORTransparentContainer sortransparentcontainer; + SORTransparentContainer sortransparentcontainer; } registration_complete_msg; - 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); #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 78% rename from openair3/NAS/COMMON/EMM/MSG/RegistrationRequest.c rename to openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationRequest.c index cf18e46ca2..e2278c8988 100644 --- a/openair3/NAS/COMMON/EMM/MSG/RegistrationRequest.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationRequest.c @@ -27,15 +27,11 @@ * \version 0.1 */ -#include -#include -#include -#include - -#include "nas_log.h" - #include "RegistrationRequest.h" #include "NR_NAS_defs.h" +#include +#include "T.h" +#include "nas_log.h" int decode_registration_request(registration_request_msg *registration_request, uint8_t *buffer, uint32_t len) { @@ -43,12 +39,12 @@ int decode_registration_request(registration_request_msg *registration_request, 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,13 +56,12 @@ 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; @@ -81,9 +76,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 +86,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 +99,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 57% rename from openair3/NAS/COMMON/EMM/MSG/RegistrationRequest.h rename to openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationRequest.h index ce534bfff9..3ae943a5f1 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,18 +98,18 @@ 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; + uint8_t protocoldiscriminator; + SecurityHeaderType securityheadertype: 4; + uint8_t sparehalfoctet: 4; + MessageType messagetype; + 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); @@ -122,4 +117,3 @@ int decode_registration_request(registration_request_msg *registrationrequest, u int encode_registration_request(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 100% rename from openair3/NAS/COMMON/EMM/MSG/fgs_service_request.c rename to openair3/NAS/NR_UE/5GS/5GMM/MSG/fgs_service_request.c 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 95% 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..79c7c00c62 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_ 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..cea7b5c552 --- /dev/null +++ b/openair3/NAS/NR_UE/5GS/5GSM/MSG/CMakeLists.txt @@ -0,0 +1,3 @@ +add_library(fgs_5gsm_lib OBJECT PduSessionEstablishRequest.c + PduSessionEstablishmentAccept.c) +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/COMMON/ESM/MSG/PduSessionEstablishmentAccept.c b/openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishmentAccept.c similarity index 93% rename from openair3/NAS/COMMON/ESM/MSG/PduSessionEstablishmentAccept.c rename to openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishmentAccept.c index 87994f383f..77c2a1d921 100644 --- a/openair3/NAS/COMMON/ESM/MSG/PduSessionEstablishmentAccept.c +++ b/openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishmentAccept.c @@ -20,11 +20,10 @@ */ #include +#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) { @@ -66,7 +65,6 @@ void capture_pdu_session_establishment_accept_msg(uint8_t *buffer, uint32_t msg_ security_protected_plain_nas_5gs_msg_t sec_nas_msg; pdu_session_establishment_accept_msg_t psea_msg; uint8_t *curPtr = buffer; - // Security protected NAS header (7 bytes) sec_nas_hdr.epd = *curPtr++; sec_nas_hdr.sht = *curPtr++; uint32_t tmp; @@ -74,7 +72,6 @@ void capture_pdu_session_establishment_accept_msg(uint8_t *buffer, uint32_t msg_ sec_nas_hdr.mac = htonl(tmp); curPtr += sizeof(sec_nas_hdr.mac); sec_nas_hdr.sqn = *curPtr++; - // Security protected plain NAS message sec_nas_msg.epd = *curPtr++; sec_nas_msg.sht = *curPtr++; sec_nas_msg.msg_type = *curPtr++; @@ -99,12 +96,11 @@ void capture_pdu_session_establishment_accept_msg(uint8_t *buffer, uint32_t msg_ qos_rule.dqr = (*(curPtr)&0x10) >> 4; qos_rule.nb_pf = *curPtr++ & 0x0F; - if(qos_rule.nb_pf) { + 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) { + 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++; @@ -150,8 +146,7 @@ void capture_pdu_session_establishment_accept_msg(uint8_t *buffer, uint32_t msg_ capture_ipv4_addr(&addr[0], ip, sizeof(ip)); tun_config(1, ip, NULL, "oaitun_ue"); setup_ue_ipv4_route(1, ip, "oaitun_ue"); - LOG_I(NAS, "Received PDU Session Establishment Accept, UE IP: %u.%u.%u.%u\n", - addr[0], addr[1], addr[2], addr[3]); + LOG_I(NAS, "Received PDU Session Establishment Accept, UE IP: %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++; @@ -219,8 +214,7 @@ void capture_pdu_session_establishment_accept_msg(uint8_t *buffer, uint32_t msg_ 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) { + 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 @@ -236,6 +230,5 @@ void capture_pdu_session_establishment_accept_msg(uint8_t *buffer, uint32_t msg_ } } - set_qfi_pduid(qos_rule.qfi, psea_msg.pdu_id); return; } diff --git a/openair3/NAS/COMMON/ESM/MSG/PduSessionEstablishmentAccept.h b/openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishmentAccept.h similarity index 74% rename from openair3/NAS/COMMON/ESM/MSG/PduSessionEstablishmentAccept.h rename to openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishmentAccept.h index 8576418e21..a85d5c4aec 100644 --- a/openair3/NAS/COMMON/ESM/MSG/PduSessionEstablishmentAccept.h +++ b/openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishmentAccept.h @@ -45,15 +45,16 @@ 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 */ @@ -62,13 +63,14 @@ typedef enum { FOREACH_IEI(TO_ENUM) } pduSessionEstablishment_IEI_t; #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. @@ -80,12 +82,12 @@ typedef enum { FOREACH_IEI(TO_ENUM) } pduSessionEstablishment_IEI_t; 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 { @@ -96,26 +98,26 @@ 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 */ + 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_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 */ +} 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 */ @@ -131,7 +133,7 @@ typedef struct pdu_address_s { } 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 */ @@ -145,28 +147,28 @@ typedef struct qos_fd_s { 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 */ + 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 */ + 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_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 */ + 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 { diff --git a/openair3/NAS/NR_UE/5GS/CMakeLists.txt b/openair3/NAS/NR_UE/5GS/CMakeLists.txt new file mode 100644 index 0000000000..4c0810b5f6 --- /dev/null +++ b/openair3/NAS/NR_UE/5GS/CMakeLists.txt @@ -0,0 +1,7 @@ +add_subdirectory(5GMM/MSG) +add_subdirectory(5GMM/IES) +add_subdirectory(5GSM/MSG) + +if(ENABLE_TESTS) + add_subdirectory(tests) +endif() 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..90502078ac --- /dev/null +++ b/openair3/NAS/NR_UE/CMakeLists.txt @@ -0,0 +1,19 @@ +add_subdirectory(5GS) + +add_library(nr_nas STATIC + nr_nas_msg.c + ../COMMON/nr_common.c +) + +target_link_libraries(nr_nas PUBLIC asn1_lte_rrc_hdrs asn1_nr_rrc_hdrs) +target_link_libraries(nr_nas PUBLIC + fgs_5gmm_lib + fgs_5gsm_lib + fgs_5gmm_ies_lib + nas_common_ies_lib + nas_utils +) + +target_include_directories(nr_nas PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} +) diff --git a/openair3/NAS/NR_UE/nr_nas_msg.c b/openair3/NAS/NR_UE/nr_nas_msg.c index f198077f69..d944589f22 100644 --- a/openair3/NAS/NR_UE/nr_nas_msg.c +++ b/openair3/NAS/NR_UE/nr_nas_msg.c @@ -36,6 +36,7 @@ #include "TLVDecoder.h" #include "TLVEncoder.h" #include "nr_nas_msg.h" +#include "NR_NAS_defs.h" #include "aka_functions.h" #include "secu_defs.h" #include "kdf.h" @@ -46,7 +47,6 @@ #include "FGSDeregistrationRequestUEOriginating.h" #include "intertask_interface.h" #include "common/utils/tun_if.h" -#include #include "openair2/SDAP/nr_sdap/nr_sdap.h" #include "openair3/SECU/nas_stream_eia2.h" #include "openair3/UTILS/conversions.h" diff --git a/openair3/NAS/NR_UE/nr_nas_msg.h b/openair3/NAS/NR_UE/nr_nas_msg.h index 7d6730a297..6ceb3edd23 100644 --- a/openair3/NAS/NR_UE/nr_nas_msg.h +++ b/openair3/NAS/NR_UE/nr_nas_msg.h @@ -37,7 +37,7 @@ #include "FGSNASSecurityModeComplete.h" #include "FGSDeregistrationRequestUEOriginating.h" #include "RegistrationComplete.h" -#include "EMM/MSG/fgs_service_request.h" +#include "fgs_service_request.h" #include "as_message.h" #include "FGSUplinkNasTransport.h" #include 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/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/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 .) From 03a4d8efb8939de4e6736e36c8a64a91f6bd8c13 Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Thu, 30 Jan 2025 14:26:57 +0100 Subject: [PATCH 11/35] Refactor NAS 5GS (5GMM & 5GSM) structs definitions and their use Every NAS 5GS message can have 3 different headers: (1) security protected (2) 5GMM plain (3) 5GS plain; According to 3GPP TS 24.501: > 4.2 Coordination between the protocols for 5GS mobility management and 5GS session management > A 5GS session management (5GSM) message is piggybacked in specific 5GS mobility management (5GMM) transport > messages. To this purpose, the 5GSM messages can be transmitted in an information element in the 5GMM transport > messages. A PDU Session Establishment accept is a 5GSM message and as such it is contained in a 5GMM transport message. The code in capture_pdu_session_establishment_accept_msg is reflecting this. The message is thus expected to have: (1) Security protected 5GMM header (2) Plain 5GMM message (3) 5GSM Payload Container (4) Plain 5GSM message. 5.4.5 of 3GPP TS 24.501: also says: > The type of the payload is identified by the Payload container type IE and includes one of the following: a) a single 5GSM message; Thus, a 5GSM is not the only possible payload of a NAS transport message. This commit is focusing on the refactoring of the structs definitions and adaptation of the CMakeLists. Based on the above: * Move NR_NAS_defs.h to 5GS subfolder in NR_UE * Move NAS FGS structs and definitions to NR_NAS_defs.h * Rename mm_msg_header_t to fgmm_msg_header_t * Remove duplicated NAS struct definitions (1) kept fgs_nas_message_security_header_t over security_protected_nas_5gs_msg_t (2) Kept fgsm_msg_header_t over fgs_sm_nas_msg_header_t * Remove unused definitions, structs, functions in the process --- openair3/NAS/COMMON/nr_common.c | 2 +- .../NAS/NR_UE/5GS/5GMM/MSG/CMakeLists.txt | 2 +- .../NAS/NR_UE/5GS/5GSM/MSG/CMakeLists.txt | 2 +- .../5GSM/MSG/PduSessionEstablishmentAccept.c | 38 ++-- .../5GSM/MSG/PduSessionEstablishmentAccept.h | 20 +- .../NAS/{COMMON => NR_UE/5GS}/NR_NAS_defs.h | 208 ++++-------------- openair3/NAS/NR_UE/CMakeLists.txt | 1 + openair3/NAS/NR_UE/nr_nas_msg.c | 16 +- openair3/NAS/NR_UE/nr_nas_msg.h | 33 +-- 9 files changed, 81 insertions(+), 241 deletions(-) rename openair3/NAS/{COMMON => NR_UE/5GS}/NR_NAS_defs.h (67%) diff --git a/openair3/NAS/COMMON/nr_common.c b/openair3/NAS/COMMON/nr_common.c index 6c935df4f1..5f0beb3a66 100644 --- a/openair3/NAS/COMMON/nr_common.c +++ b/openair3/NAS/COMMON/nr_common.c @@ -22,7 +22,7 @@ */ #include -#include +#include "openair3/NAS/NR_UE/5GS/NR_NAS_defs.h" #include #include diff --git a/openair3/NAS/NR_UE/5GS/5GMM/MSG/CMakeLists.txt b/openair3/NAS/NR_UE/5GS/5GMM/MSG/CMakeLists.txt index fab8d6b6ff..766106ee77 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/MSG/CMakeLists.txt +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/CMakeLists.txt @@ -10,4 +10,4 @@ add_library(fgs_5gmm_lib OBJECT FGSDeregistrationRequestUEOriginating.c ) -target_include_directories(fgs_5gmm_lib PUBLIC . ../IES) +target_include_directories(fgs_5gmm_lib PUBLIC . ../IES ../../) diff --git a/openair3/NAS/NR_UE/5GS/5GSM/MSG/CMakeLists.txt b/openair3/NAS/NR_UE/5GS/5GSM/MSG/CMakeLists.txt index cea7b5c552..41498581c9 100644 --- a/openair3/NAS/NR_UE/5GS/5GSM/MSG/CMakeLists.txt +++ b/openair3/NAS/NR_UE/5GS/5GSM/MSG/CMakeLists.txt @@ -1,3 +1,3 @@ add_library(fgs_5gsm_lib OBJECT PduSessionEstablishRequest.c PduSessionEstablishmentAccept.c) -target_include_directories(fgs_5gsm_lib PUBLIC .) +target_include_directories(fgs_5gsm_lib PUBLIC . ../../) diff --git a/openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishmentAccept.c b/openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishmentAccept.c index 77c2a1d921..e00b7209af 100644 --- a/openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishmentAccept.c +++ b/openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishmentAccept.c @@ -61,28 +61,32 @@ static int capture_ipv6_addr(const uint8_t *addr, char *ip, size_t len) */ 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; + fgs_nas_message_security_header_t sec_nas_hdr; pdu_session_establishment_accept_msg_t psea_msg; uint8_t *curPtr = buffer; - sec_nas_hdr.epd = *curPtr++; - sec_nas_hdr.sht = *curPtr++; + // Security protected NAS header (7 bytes) + sec_nas_hdr.protocol_discriminator = *curPtr++; + sec_nas_hdr.security_header_type = *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); + sec_nas_hdr.message_authentication_code = htonl(tmp); + curPtr += sizeof(sec_nas_hdr.message_authentication_code); + sec_nas_hdr.sequence_number = *curPtr++; + // Security protected plain NAS message + fgmm_msg_header_t header; + header.ex_protocol_discriminator = *curPtr++; + header.security_header_type = *curPtr++; + header.message_type = *curPtr++; + // Payload container type and spare (1 octet) + curPtr++; + // Payload container length + curPtr += sizeof(getShort(curPtr)); /* Mandatory Presence IEs */ - psea_msg.epd = *curPtr++; - psea_msg.pdu_id = *curPtr++; - psea_msg.pti = *curPtr++; - psea_msg.msg_type = *curPtr++; + fgsm_msg_header_t *sm_header = &psea_msg.header; + sm_header->ex_protocol_discriminator = *curPtr++; + sm_header->pdu_session_id = *curPtr++; + sm_header->pti = *curPtr++; + sm_header->message_type = *curPtr++; psea_msg.pdu_type = *curPtr & 0x0f; psea_msg.ssc_mode = (*curPtr++ & 0xf0) >> 4; psea_msg.qos_rules.length = getShort(curPtr); diff --git a/openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishmentAccept.h b/openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishmentAccept.h index a85d5c4aec..37dea829b0 100644 --- a/openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishmentAccept.h +++ b/openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishmentAccept.h @@ -147,10 +147,7 @@ typedef struct qos_fd_s { 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 */ + fgsm_msg_header_t header; uint8_t pdu_type; /* PDU Session Type */ uint8_t ssc_mode; /* SSC mode */ auth_qos_rule_t qos_rules; /* Authorized QoS rules */ @@ -163,21 +160,6 @@ typedef struct pdu_session_establishment_accept_msg_s { qos_fd_t qos_fd_ie; /* QoS flow descriptions */ } 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); #endif diff --git a/openair3/NAS/COMMON/NR_NAS_defs.h b/openair3/NAS/NR_UE/5GS/NR_NAS_defs.h similarity index 67% rename from openair3/NAS/COMMON/NR_NAS_defs.h rename to openair3/NAS/NR_UE/5GS/NR_NAS_defs.h index f5510e5392..4451bfe615 100644 --- a/openair3/NAS/COMMON/NR_NAS_defs.h +++ b/openair3/NAS/NR_UE/5GS/NR_NAS_defs.h @@ -9,8 +9,6 @@ * * 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. @@ -20,23 +18,12 @@ * 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 -*/ +#include +#include "openair3/UICC/usim_interface.h" /* Map task id to printable name. */ typedef struct { @@ -44,24 +31,9 @@ typedef struct { 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) \ @@ -130,17 +102,6 @@ typedef enum { 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 )\ @@ -187,7 +148,6 @@ typedef enum { 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[] = { @@ -249,138 +209,58 @@ typedef enum { 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 +// IEIs (Information Element Identifier) #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; +/** + * 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 { - Extendedprotocoldiscriminator_t epd:8; - Security_header_t sh:8; - SGSmobilitymanagementmessages_t mt:8; -} SGScommonHeader_t; + // 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; +/// 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 { - Extendedprotocoldiscriminator_t epd:8; - Security_header_t sh:8; - SGSmobilitymanagementmessages_t mt:8; - identitytype_t it:8; -} Identityrequest_t; + uint8_t ex_protocol_discriminator; + uint8_t security_header_type; + uint8_t message_type; +} fgmm_msg_header_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; +/// 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 { - uicc_t *uicc; -} nr_user_nas_t; + // 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; -#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 +#endif // NR_NAS_DEFS_H diff --git a/openair3/NAS/NR_UE/CMakeLists.txt b/openair3/NAS/NR_UE/CMakeLists.txt index 90502078ac..83d5a2191a 100644 --- a/openair3/NAS/NR_UE/CMakeLists.txt +++ b/openair3/NAS/NR_UE/CMakeLists.txt @@ -16,4 +16,5 @@ target_link_libraries(nr_nas PUBLIC target_include_directories(nr_nas PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/5GS ) diff --git a/openair3/NAS/NR_UE/nr_nas_msg.c b/openair3/NAS/NR_UE/nr_nas_msg.c index d944589f22..a8aecf8912 100644 --- a/openair3/NAS/NR_UE/nr_nas_msg.c +++ b/openair3/NAS/NR_UE/nr_nas_msg.c @@ -150,12 +150,12 @@ static int nas_protected_security_header_encode(char *buffer, const fgs_nas_mess LOG_FUNC_RETURN(size); } -static int _nas_mm_msg_encode_header(const mm_msg_header_t *header, uint8_t *buffer, uint32_t len) +static 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(mm_msg_header_t)) { + if (len < sizeof(fgmm_msg_header_t)) { return (TLV_ENCODE_BUFFER_TOO_SHORT); } @@ -510,7 +510,7 @@ 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); + int size = sizeof(fgmm_msg_header_t); fgs_nas_message_t nas_msg = {0}; MM_msg *mm_msg; @@ -590,7 +590,7 @@ void generateServiceRequest(as_nas_info_t *initialNasMsg, nr_ue_nas_t *nas) 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); + size += sizeof(mm_msg->header); // Fill Service Request // Service Type @@ -645,7 +645,7 @@ void generateServiceRequest(as_nas_info_t *initialNasMsg, nr_ue_nas_t *nas) void generateIdentityResponse(as_nas_info_t *initialNasMsg, uint8_t identitytype, uicc_t *uicc) { - int size = sizeof(mm_msg_header_t); + int size = sizeof(fgmm_msg_header_t); fgs_nas_message_t nas_msg; memset(&nas_msg, 0, sizeof(fgs_nas_message_t)); MM_msg *mm_msg; @@ -681,7 +681,7 @@ 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); + int size = sizeof(fgmm_msg_header_t); fgs_nas_message_t nas_msg; memset(&nas_msg, 0, sizeof(fgs_nas_message_t)); MM_msg *mm_msg; @@ -721,7 +721,7 @@ 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); + int size = sizeof(fgmm_msg_header_t); fgs_nas_message_t nas_msg; memset(&nas_msg, 0, sizeof(fgs_nas_message_t)); @@ -964,7 +964,7 @@ static void generateDeregistrationRequest(nr_ue_nas_t *nas, as_nas_info_t *initi 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); + 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; diff --git a/openair3/NAS/NR_UE/nr_nas_msg.h b/openair3/NAS/NR_UE/nr_nas_msg.h index 6ceb3edd23..263e30e7a1 100644 --- a/openair3/NAS/NR_UE/nr_nas_msg.h +++ b/openair3/NAS/NR_UE/nr_nas_msg.h @@ -42,6 +42,7 @@ #include "FGSUplinkNasTransport.h" #include #include "secu_defs.h" +#include "NR_NAS_defs.h" #define INITIAL_REGISTRATION 0b001 @@ -94,22 +95,8 @@ typedef enum fgs_protocol_discriminator_e { 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 { - uint8_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; + fgmm_msg_header_t header; registration_request_msg registration_request; fgs_service_request_msg_t service_request; fgs_identiy_response_msg fgs_identity_response; @@ -137,7 +124,7 @@ typedef union { typedef struct { union { - mm_msg_header_t plain_nas_msg_header; + fgmm_msg_header_t plain_nas_msg_header; struct security_protected_nas_msg_header_s { uint8_t ex_protocol_discriminator; uint8_t security_header_type; @@ -148,20 +135,6 @@ typedef struct { } 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); From fb85ba7da38cad60caa477be1a07f99265f25343 Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Thu, 30 Jan 2025 14:29:16 +0100 Subject: [PATCH 12/35] Remove NAS/COMMON/nr_common.c and move servingNetworkName to nr_nas_msg.c * the only function used from nr_common.c is servingNetworkName which is used in nr_nas_msg.c, so it was moved to the latter file and its scope was reduced --- openair3/NAS/COMMON/nr_common.c | 72 ------------------------------- openair3/NAS/NR_UE/CMakeLists.txt | 5 +-- openair3/NAS/NR_UE/nr_nas_msg.c | 15 +++++++ 3 files changed, 16 insertions(+), 76 deletions(-) delete mode 100644 openair3/NAS/COMMON/nr_common.c diff --git a/openair3/NAS/COMMON/nr_common.c b/openair3/NAS/COMMON/nr_common.c deleted file mode 100644 index 5f0beb3a66..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 "openair3/NAS/NR_UE/5GS/NR_NAS_defs.h" -#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/CMakeLists.txt b/openair3/NAS/NR_UE/CMakeLists.txt index 83d5a2191a..8054d1cdd2 100644 --- a/openair3/NAS/NR_UE/CMakeLists.txt +++ b/openair3/NAS/NR_UE/CMakeLists.txt @@ -1,9 +1,6 @@ add_subdirectory(5GS) -add_library(nr_nas STATIC - nr_nas_msg.c - ../COMMON/nr_common.c -) +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 diff --git a/openair3/NAS/NR_UE/nr_nas_msg.c b/openair3/NAS/NR_UE/nr_nas_msg.c index a8aecf8912..dbf86c6222 100644 --- a/openair3/NAS/NR_UE/nr_nas_msg.c +++ b/openair3/NAS/NR_UE/nr_nas_msg.c @@ -65,6 +65,21 @@ typedef enum { NAS_SECURITY_BAD_INPUT } security_state_t; +static 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); +} + security_state_t nas_security_rx_process(nr_ue_nas_t *nas, uint8_t *pdu_buffer, int pdu_length) { if (nas->security_container == NULL) From 27ed2373004085f039547a9ae196f23678c53f4b Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Tue, 1 Oct 2024 14:47:25 +0200 Subject: [PATCH 13/35] Refactor NAS 5GS message type definitions * move defines to openair3/NAS/NR_UE/nr_nas_msg.h as they are only used in nr_nas_msg.c * made naming of all message types consistent, using the same prefix for all --- .../5GSM/MSG/PduSessionEstablishmentAccept.c | 1 + openair3/NAS/NR_UE/5GS/NR_NAS_defs.h | 105 +++++++++--------- openair3/NAS/NR_UE/nr_nas_msg.c | 16 +-- 3 files changed, 64 insertions(+), 58 deletions(-) diff --git a/openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishmentAccept.c b/openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishmentAccept.c index e00b7209af..6a7c1f7211 100644 --- a/openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishmentAccept.c +++ b/openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishmentAccept.c @@ -24,6 +24,7 @@ #include "PduSessionEstablishmentAccept.h" #include "common/utils/LOG/log.h" #include "common/utils/tun_if.h" +#include "NR_NAS_defs.h" static uint16_t getShort(uint8_t *input) { diff --git a/openair3/NAS/NR_UE/5GS/NR_NAS_defs.h b/openair3/NAS/NR_UE/5GS/NR_NAS_defs.h index 4451bfe615..35b9793863 100644 --- a/openair3/NAS/NR_UE/5GS/NR_NAS_defs.h +++ b/openair3/NAS/NR_UE/5GS/NR_NAS_defs.h @@ -34,55 +34,60 @@ typedef struct { #define TO_TEXT(LabEl, nUmID) {nUmID, #LabEl}, #define TO_ENUM(LabEl, nUmID ) LabEl = nUmID, -#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) +/* 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) @@ -91,7 +96,7 @@ static const text_info_t message_text_info[] = { //! Tasks id of each task typedef enum { FOREACH_TYPE(TO_ENUM) -} SGSmobilitymanagementmessages_t; +} fgs_nas_msg_t; // TS 24.501 typedef enum { diff --git a/openair3/NAS/NR_UE/nr_nas_msg.c b/openair3/NAS/NR_UE/nr_nas_msg.c index dbf86c6222..101546f038 100644 --- a/openair3/NAS/NR_UE/nr_nas_msg.c +++ b/openair3/NAS/NR_UE/nr_nas_msg.c @@ -268,7 +268,7 @@ int mm_msg_encode(MM_msg *mm_msg, uint8_t *buffer, uint32_t len) len -= header_result; switch (msg_type) { - case REGISTRATION_REQUEST: + case FGS_REGISTRATION_REQUEST: encode_result = encode_registration_request(&mm_msg->registration_request, buffer, len); break; case FGS_IDENTITY_RESPONSE: @@ -533,14 +533,14 @@ void generateRegistrationRequest(as_nas_info_t *initialNasMsg, nr_ue_nas_t *nas) // 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; + mm_msg->header.message_type = FGS_REGISTRATION_REQUEST; // 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; + mm_msg->registration_request.messagetype = FGS_REGISTRATION_REQUEST; size += 1; mm_msg->registration_request.fgsregistrationtype = INITIAL_REGISTRATION; mm_msg->registration_request.naskeysetidentifier.naskeysetidentifier = 1; @@ -891,7 +891,7 @@ static void generateRegistrationComplete(nr_ue_nas_t *nas, 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; + sp_msg->plain.mm_msg.registration_complete.messagetype = FGS_REGISTRATION_COMPLETE; length += 1; if (sortransparentcontainer) { @@ -1426,7 +1426,7 @@ void *nas_nrue(void *args_p) 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); @@ -1494,7 +1494,7 @@ void *nas_nrue(void *args_p) /* 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; } @@ -1519,7 +1519,7 @@ 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: @@ -1531,7 +1531,7 @@ void *nas_nrue(void *args_p) 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; From ddad26effe3ef89788902919db4d59c5e5e58ee0 Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Mon, 11 Nov 2024 16:50:00 +0100 Subject: [PATCH 14/35] Refactor includes in nr_nas_msg (.c/.h) --- openair3/NAS/NR_UE/nr_nas_msg.c | 41 ++++++++++++++++++++++----------- openair3/NAS/NR_UE/nr_nas_msg.h | 15 ++++++++---- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/openair3/NAS/NR_UE/nr_nas_msg.c b/openair3/NAS/NR_UE/nr_nas_msg.c index 101546f038..06b5736399 100644 --- a/openair3/NAS/NR_UE/nr_nas_msg.c +++ b/openair3/NAS/NR_UE/nr_nas_msg.c @@ -29,27 +29,40 @@ * 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 #include "NR_NAS_defs.h" -#include "aka_functions.h" -#include "secu_defs.h" -#include "kdf.h" -#include "key_nas_deriver.h" +#include +#include +#include +#include +#include "AuthenticationResponseParameter.h" +#include "FGCNasMessageContainer.h" +#include "FGSDeregistrationRequestUEOriginating.h" +#include "FGSDeregistrationType.h" +#include "LOG/log.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 "T.h" +#include "TLVEncoder.h" +#include "aka_functions.h" +#include "assertions.h" +#include "common/utils/ds/byte_array.h" #include "common/utils/tun_if.h" -#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" #define MAX_NAS_UE 4 diff --git a/openair3/NAS/NR_UE/nr_nas_msg.h b/openair3/NAS/NR_UE/nr_nas_msg.h index 263e30e7a1..eb76ddcd51 100644 --- a/openair3/NAS/NR_UE/nr_nas_msg.h +++ b/openair3/NAS/NR_UE/nr_nas_msg.h @@ -31,16 +31,21 @@ #ifndef __NR_NAS_MSG_SIM_H__ #define __NR_NAS_MSG_SIM_H__ -#include "RegistrationRequest.h" -#include "FGSIdentityResponse.h" +#include +#include +#include +#include #include "FGSAuthenticationResponse.h" -#include "FGSNASSecurityModeComplete.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" #include "as_message.h" -#include "FGSUplinkNasTransport.h" -#include +#include "NR_NAS_defs.h" #include "secu_defs.h" #include "NR_NAS_defs.h" From f73579ea418a13f2ac8d92feca4ac07c01505085 Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Tue, 24 Sep 2024 14:11:43 +0200 Subject: [PATCH 15/35] Limit scope of NAS functions (static) --- openair3/NAS/NR_UE/nr_nas_msg.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openair3/NAS/NR_UE/nr_nas_msg.c b/openair3/NAS/NR_UE/nr_nas_msg.c index 06b5736399..673bbfbb3d 100644 --- a/openair3/NAS/NR_UE/nr_nas_msg.c +++ b/openair3/NAS/NR_UE/nr_nas_msg.c @@ -93,7 +93,7 @@ static void servingNetworkName(uint8_t *msg, char *imsiStr, int nmc_size) memcpy(msg + 13, imsiStr, 3); } -security_state_t nas_security_rx_process(nr_ue_nas_t *nas, uint8_t *pdu_buffer, int pdu_length) +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; @@ -438,7 +438,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 @@ -473,7 +473,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]; From 2d755988516ec6ee8daf758c32d54818deca0ae7 Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Wed, 11 Dec 2024 10:12:29 +0100 Subject: [PATCH 16/35] Initial separation of enc/dec functions from handlers/callbacks * move enc/dec definitions to NR_NAS_defs.h and add new lib file nr_fgs_nas_lib.c both used by nr_nas_msg.c * move utility macros to fgs_nas_utils.h: this can be used in all the 5GMM, 5GSM lib files * use nr_nas_msg.c for handlers/callbacks only, it should call the enc/dec functions in nr_fgs_nas_lib and in the 5GMM, 5GSM libs * 5GMM, 5GSM libs should only do the enc/dec of the NAS message contents --- openair3/NAS/COMMON/IES/CMakeLists.txt | 4 +- .../NAS/NR_UE/5GS/5GMM/IES/CMakeLists.txt | 4 + .../NAS/NR_UE/5GS/5GMM/MSG/CMakeLists.txt | 4 +- .../FGSDeregistrationRequestUEOriginating.c | 3 +- .../NR_UE/5GS/5GMM/MSG/RegistrationRequest.c | 3 +- .../NR_UE/5GS/5GMM/MSG/fgs_service_request.c | 2 +- .../NAS/NR_UE/5GS/5GSM/MSG/CMakeLists.txt | 9 +- .../5GSM/MSG/PduSessionEstablishmentAccept.h | 3 +- openair3/NAS/NR_UE/5GS/CMakeLists.txt | 10 ++ openair3/NAS/NR_UE/5GS/NR_NAS_defs.h | 77 ++++++++-- openair3/NAS/NR_UE/5GS/fgs_nas_lib.c | 134 ++++++++++++++++++ openair3/NAS/NR_UE/5GS/fgs_nas_utils.h | 36 +++++ openair3/NAS/NR_UE/CMakeLists.txt | 6 +- openair3/NAS/NR_UE/nr_nas_msg.c | 118 +-------------- openair3/NAS/NR_UE/nr_nas_msg.h | 57 -------- 15 files changed, 274 insertions(+), 196 deletions(-) create mode 100644 openair3/NAS/NR_UE/5GS/fgs_nas_lib.c create mode 100644 openair3/NAS/NR_UE/5GS/fgs_nas_utils.h diff --git a/openair3/NAS/COMMON/IES/CMakeLists.txt b/openair3/NAS/COMMON/IES/CMakeLists.txt index bf80586fbc..67cc9d782a 100644 --- a/openair3/NAS/COMMON/IES/CMakeLists.txt +++ b/openair3/NAS/COMMON/IES/CMakeLists.txt @@ -3,6 +3,4 @@ add_library(nas_common_ies_lib OBJECT NasKeySetIdentifier.c ) -target_include_directories(nas_common_ies_lib PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR} -) +target_include_directories(nas_common_ies_lib PUBLIC .) diff --git a/openair3/NAS/NR_UE/5GS/5GMM/IES/CMakeLists.txt b/openair3/NAS/NR_UE/5GS/5GMM/IES/CMakeLists.txt index 0915eed19c..24ed3022a6 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/IES/CMakeLists.txt +++ b/openair3/NAS/NR_UE/5GS/5GMM/IES/CMakeLists.txt @@ -7,3 +7,7 @@ add_library(fgs_5gmm_ies_lib OBJECT FGCNasMessageContainer.c SORTransparentContainer.c ) + +target_link_libraries(fgs_5gmm_ies_lib PUBLIC + nas_common_ies_lib +) diff --git a/openair3/NAS/NR_UE/5GS/5GMM/MSG/CMakeLists.txt b/openair3/NAS/NR_UE/5GS/5GMM/MSG/CMakeLists.txt index 766106ee77..be84772da6 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/MSG/CMakeLists.txt +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/CMakeLists.txt @@ -10,4 +10,6 @@ add_library(fgs_5gmm_lib OBJECT FGSDeregistrationRequestUEOriginating.c ) -target_include_directories(fgs_5gmm_lib PUBLIC . ../IES ../../) +target_link_libraries(fgs_5gmm_lib PUBLIC fgs_5gmm_ies_lib) + +target_include_directories(fgs_5gmm_lib PRIVATE ../IES/ ../../) diff --git a/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSDeregistrationRequestUEOriginating.c b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSDeregistrationRequestUEOriginating.c index b5fdc5591a..6e1c0f102e 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSDeregistrationRequestUEOriginating.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSDeregistrationRequestUEOriginating.c @@ -28,9 +28,10 @@ */ #include "FGSDeregistrationRequestUEOriginating.h" -#include "NR_NAS_defs.h" #include +#define IEI_NULL 0x00 + int encode_fgs_deregistration_request_ue_originating(fgs_deregistration_request_ue_originating_msg *drr, uint8_t *buffer, uint32_t len) diff --git a/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationRequest.c b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationRequest.c index e2278c8988..dd08e61dba 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationRequest.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationRequest.c @@ -28,11 +28,12 @@ */ #include "RegistrationRequest.h" -#include "NR_NAS_defs.h" #include #include "T.h" #include "nas_log.h" +#define IEI_NULL 0x00 + int decode_registration_request(registration_request_msg *registration_request, uint8_t *buffer, uint32_t len) { uint32_t decoded = 0; diff --git a/openair3/NAS/NR_UE/5GS/5GMM/MSG/fgs_service_request.c b/openair3/NAS/NR_UE/5GS/5GMM/MSG/fgs_service_request.c index 85e67498a5..fa31e1e297 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/MSG/fgs_service_request.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/fgs_service_request.c @@ -30,10 +30,10 @@ #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) diff --git a/openair3/NAS/NR_UE/5GS/5GSM/MSG/CMakeLists.txt b/openair3/NAS/NR_UE/5GS/5GSM/MSG/CMakeLists.txt index 41498581c9..ca115451b3 100644 --- a/openair3/NAS/NR_UE/5GS/5GSM/MSG/CMakeLists.txt +++ b/openair3/NAS/NR_UE/5GS/5GSM/MSG/CMakeLists.txt @@ -1,3 +1,10 @@ add_library(fgs_5gsm_lib OBJECT PduSessionEstablishRequest.c PduSessionEstablishmentAccept.c) -target_include_directories(fgs_5gsm_lib PUBLIC . ../../) + +target_link_libraries(fgs_5gsm_lib PUBLIC nas_common_ies_lib) + +target_include_directories(fgs_5gsm_lib PUBLIC . + ../../5GMM/MSG # NOTE: to be removed in a later commit + ../../5GMM/IES # NOTE: to be removed in a later commit + ../../ +) diff --git a/openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishmentAccept.h b/openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishmentAccept.h index 37dea829b0..69c9cde844 100644 --- a/openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishmentAccept.h +++ b/openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishmentAccept.h @@ -23,7 +23,8 @@ #define PDU_SESSION_ESTABLISHMENT_ACCEPT_H_ #include -#include "NR_NAS_defs.h" +#include "fgs_nas_utils.h" +#include "NR_NAS_defs.h" // TEMP: to be removed in later commit /* PDU Session Establish Accept Optional IE Identifiers - TS 24.501 Table 8.3.2.1.1 */ diff --git a/openair3/NAS/NR_UE/5GS/CMakeLists.txt b/openair3/NAS/NR_UE/5GS/CMakeLists.txt index 4c0810b5f6..e04abb02db 100644 --- a/openair3/NAS/NR_UE/5GS/CMakeLists.txt +++ b/openair3/NAS/NR_UE/5GS/CMakeLists.txt @@ -5,3 +5,13 @@ 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 index 35b9793863..fd4fa2e1a8 100644 --- a/openair3/NAS/NR_UE/5GS/NR_NAS_defs.h +++ b/openair3/NAS/NR_UE/5GS/NR_NAS_defs.h @@ -24,15 +24,16 @@ #include #include "openair3/UICC/usim_interface.h" - -/* 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, +#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) @@ -220,9 +221,6 @@ typedef enum { FOREACH_CAUSE_SECU(TO_ENUM) } cause_secu_id_t; -// IEIs (Information Element Identifier) -#define IEI_NULL 0x00 - /** * Security protected 5GS NAS message header (9.1.1 of 3GPP TS 24.501) * either 5GMM or 5GSM @@ -239,6 +237,15 @@ typedef struct { 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 /** @@ -251,6 +258,46 @@ typedef struct { uint8_t message_type; } fgmm_msg_header_t; +/// 5GS legacy defs + +typedef union { + fgmm_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 { + fgmm_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; + /// 5GSM - 5GS session management /** @@ -268,4 +315,10 @@ typedef struct { uint8_t message_type; } fgsm_msg_header_t; +/// Function prototypes + +int mm_msg_encode(const MM_msg *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); + #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..8585e4ef70 --- /dev/null +++ b/openair3/NAS/NR_UE/5GS/fgs_nas_lib.c @@ -0,0 +1,134 @@ +/* + * 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 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, + "Failed to encode 5GMM message header" + "(%d)", + header_result); + LOG_FUNC_RETURN(header_result); + } + + buffer += header_result; + len -= header_result; + + switch (msg_type) { + case FGS_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, " 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, + " 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); +} + +int nas_protected_security_header_encode(uint8_t *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); +} 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..74f4d2ed7f --- /dev/null +++ b/openair3/NAS/NR_UE/5GS/fgs_nas_utils.h @@ -0,0 +1,36 @@ +/* + * 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 + +/* 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, + +#endif // FGS_NAS_UTILS_H diff --git a/openair3/NAS/NR_UE/CMakeLists.txt b/openair3/NAS/NR_UE/CMakeLists.txt index 8054d1cdd2..5e7d5da428 100644 --- a/openair3/NAS/NR_UE/CMakeLists.txt +++ b/openair3/NAS/NR_UE/CMakeLists.txt @@ -4,6 +4,7 @@ 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 @@ -11,7 +12,4 @@ target_link_libraries(nr_nas PUBLIC nas_utils ) -target_include_directories(nr_nas PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/5GS -) +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 673bbfbb3d..33fabe8df0 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 @@ -40,7 +40,6 @@ #include "FGCNasMessageContainer.h" #include "FGSDeregistrationRequestUEOriginating.h" #include "FGSDeregistrationType.h" -#include "LOG/log.h" #include "NasKeySetIdentifier.h" #include "NrUESecurityCapability.h" #include "OctetString.h" @@ -158,50 +157,6 @@ static security_state_t nas_security_rx_process(nr_ue_nas_t *nas, uint8_t *pdu_b 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 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, "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; @@ -259,71 +214,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 FGS_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}; @@ -786,7 +676,7 @@ static void generateSecurityModeComplete(nr_ue_nas_t *nas, as_nas_info_t *initia // encode the message 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, &nas_msg.header, size); initialNasMsg->length = security_header_len @@ -1010,7 +900,7 @@ static void generateDeregistrationRequest(nr_ue_nas_t *nas, as_nas_info_t *initi // encode the message initialNasMsg->nas_data = calloc_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, &nas_msg.header, size); initialNasMsg->length = security_header_len @@ -1118,7 +1008,7 @@ static void generatePduSessionEstablishRequest(nr_ue_nas_t *nas, as_nas_info_t * // encode the message 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, &nas_msg.header, size); initialNasMsg->length = security_header_len diff --git a/openair3/NAS/NR_UE/nr_nas_msg.h b/openair3/NAS/NR_UE/nr_nas_msg.h index eb76ddcd51..d024a92c9c 100644 --- a/openair3/NAS/NR_UE/nr_nas_msg.h +++ b/openair3/NAS/NR_UE/nr_nas_msg.h @@ -35,15 +35,6 @@ #include #include #include -#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" #include "as_message.h" #include "NR_NAS_defs.h" #include "secu_defs.h" @@ -92,54 +83,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 union { - fgmm_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 { - fgmm_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; - 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); From 8a844efa49ccaf6fa8e2b5203978a5131dc80066 Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Wed, 11 Dec 2024 12:47:43 +0100 Subject: [PATCH 17/35] Fix typo and rename NAS identity response --- openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSIdentityResponse.c | 2 +- openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSIdentityResponse.h | 7 +++---- openair3/NAS/NR_UE/5GS/NR_NAS_defs.h | 2 +- openair3/NAS/NR_UE/5GS/fgs_nas_lib.c | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSIdentityResponse.c b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSIdentityResponse.c index 573d1022d5..f65279c355 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSIdentityResponse.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSIdentityResponse.c @@ -31,7 +31,7 @@ #include "FGSIdentityResponse.h" #include -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; diff --git a/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSIdentityResponse.h b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSIdentityResponse.h index 519e49410e..74cc6879a6 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSIdentityResponse.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSIdentityResponse.h @@ -43,16 +43,15 @@ * Direction: UE to AMF */ -typedef struct fgs_identiy_response_msg_tag { +typedef struct fgmm_identity_response_msg_s { /* Mandatory fields */ uint8_t protocoldiscriminator; SecurityHeaderType securityheadertype: 4; uint8_t sparehalfoctet: 4; MessageType messagetype; 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/NR_UE/5GS/NR_NAS_defs.h b/openair3/NAS/NR_UE/5GS/NR_NAS_defs.h index fd4fa2e1a8..206cdab279 100644 --- a/openair3/NAS/NR_UE/5GS/NR_NAS_defs.h +++ b/openair3/NAS/NR_UE/5GS/NR_NAS_defs.h @@ -264,7 +264,7 @@ typedef union { fgmm_msg_header_t header; registration_request_msg registration_request; fgs_service_request_msg_t service_request; - fgs_identiy_response_msg fgs_identity_response; + 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; diff --git a/openair3/NAS/NR_UE/5GS/fgs_nas_lib.c b/openair3/NAS/NR_UE/5GS/fgs_nas_lib.c index 8585e4ef70..75f045846d 100644 --- a/openair3/NAS/NR_UE/5GS/fgs_nas_lib.c +++ b/openair3/NAS/NR_UE/5GS/fgs_nas_lib.c @@ -74,7 +74,7 @@ int mm_msg_encode(const MM_msg *mm_msg, uint8_t *buffer, uint32_t len) 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); + encode_result = encode_fgmm_identity_response(buffer, &mm_msg->fgs_identity_response, len); break; case FGS_AUTHENTICATION_RESPONSE: encode_result = encode_fgs_authentication_response(&mm_msg->fgs_auth_response, buffer, len); From 7810516596f3a9f6013a78365199978c2b61dad1 Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Mon, 18 Nov 2024 15:33:41 +0100 Subject: [PATCH 18/35] Add equality check and error macro to NAS --- openair3/NAS/NR_UE/5GS/fgs_nas_utils.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/openair3/NAS/NR_UE/5GS/fgs_nas_utils.h b/openair3/NAS/NR_UE/5GS/fgs_nas_utils.h index 74f4d2ed7f..3082bc7daa 100644 --- a/openair3/NAS/NR_UE/5GS/fgs_nas_utils.h +++ b/openair3/NAS/NR_UE/5GS/fgs_nas_utils.h @@ -24,6 +24,24 @@ #include +#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; From 08e3f2f0df82ce9a5fbddb5957285317439c8518 Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Wed, 13 Nov 2024 09:52:21 +0100 Subject: [PATCH 19/35] Refactor generateRegistrationComplete * replace encoding code with proper functions from the lib * remove unnecessary header members in struct definition this commit removes last enc/dec code in nr_nas_msg.c --- .../NR_UE/5GS/5GMM/MSG/RegistrationComplete.c | 5 +- .../NR_UE/5GS/5GMM/MSG/RegistrationComplete.h | 8 +-- openair3/NAS/NR_UE/nr_nas_msg.c | 50 +++++++------------ 3 files changed, 24 insertions(+), 39 deletions(-) diff --git a/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationComplete.c b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationComplete.c index 5c1bf38bd8..702b3ab600 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationComplete.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationComplete.c @@ -44,8 +44,11 @@ int encode_registration_complete(registration_complete_msg *registration_complet 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)) + encode_sor_transparent_container(registration_complete->sortransparentcontainer, 0, buffer + encoded, len - encoded)) < 0) // Return in case of error return encode_result; else diff --git a/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationComplete.h b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationComplete.h index b49cc28dd4..e97c8d262d 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationComplete.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationComplete.h @@ -37,14 +37,8 @@ #define REGISTRATION_COMPLETE_H_ typedef struct registration_complete_msg_tag { - /* Mandatory fields */ - uint8_t protocoldiscriminator; - SecurityHeaderType securityheadertype: 4; - uint8_t sparehalfoctet: 4; - MessageType messagetype; - /* Optional fields */ - SORTransparentContainer sortransparentcontainer; + SORTransparentContainer *sortransparentcontainer; } registration_complete_msg; int decode_registration_complete(registration_complete_msg *registrationcomplete, uint8_t *buffer, uint32_t len); diff --git a/openair3/NAS/NR_UE/nr_nas_msg.c b/openair3/NAS/NR_UE/nr_nas_msg.c index 33fabe8df0..6109f69234 100644 --- a/openair3/NAS/NR_UE/nr_nas_msg.c +++ b/openair3/NAS/NR_UE/nr_nas_msg.c @@ -48,7 +48,6 @@ #include "RegistrationAccept.h" #include "SORTransparentContainer.h" #include "T.h" -#include "TLVEncoder.h" #include "aka_functions.h" #include "assertions.h" #include "common/utils/ds/byte_array.h" @@ -775,7 +774,6 @@ static void generateRegistrationComplete(nr_ue_nas_t *nas, SORTransparentContainer *sortransparentcontainer) { int length = 0; - int size = 0; fgs_nas_message_t nas_msg; nas_stream_cipher_t stream_cipher; uint8_t mac[4]; @@ -783,52 +781,42 @@ static void generateRegistrationComplete(nr_ue_nas_t *nas, fgs_nas_message_security_protected_t *sp_msg; sp_msg = &nas_msg.security_protected; - // set header + // set security protected 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; length = 7; - sp_msg->plain.mm_msg.registration_complete.protocoldiscriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; + // set plain 5GMM header + sp_msg->plain.mm_msg.header.ex_protocol_discriminator = 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; + sp_msg->plain.mm_msg.header.security_header_type = PLAIN_5GS_MSG; length += 1; - sp_msg->plain.mm_msg.registration_complete.messagetype = FGS_REGISTRATION_COMPLETE; + sp_msg->plain.mm_msg.header.message_type = FGS_REGISTRATION_COMPLETE; length += 1; if (sortransparentcontainer) { + sp_msg->plain.mm_msg.registration_complete.sortransparentcontainer = sortransparentcontainer; length += sortransparentcontainer->sortransparentcontainercontents.length; } // encode the message 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_msg->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_msg->plain.mm_msg.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(&sp_msg->plain.mm_msg.registration_complete, initialNasMsg->nas_data + encoded, length - encoded); /* ciphering */ uint8_t buf[initialNasMsg->length - 7]; From 9719f5e574f6d20e9267db994d7a8b93c8dd364d Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Wed, 13 Nov 2024 10:18:09 +0100 Subject: [PATCH 20/35] Add const attribute to NAS enc/dec functions --- .../IES/AuthenticationResponseParameter.c | 5 ++++- .../IES/AuthenticationResponseParameter.h | 5 ++++- openair3/NAS/COMMON/IES/NasKeySetIdentifier.c | 2 +- openair3/NAS/COMMON/IES/NasKeySetIdentifier.h | 2 +- openair3/NAS/COMMON/UTIL/OctetString.c | 5 ++--- openair3/NAS/COMMON/UTIL/OctetString.h | 4 ++-- .../5GS/5GMM/IES/FGCNasMessageContainer.c | 2 +- .../5GS/5GMM/IES/FGCNasMessageContainer.h | 2 +- .../NAS/NR_UE/5GS/5GMM/IES/FGMMCapability.c | 2 +- .../NAS/NR_UE/5GS/5GMM/IES/FGMMCapability.h | 2 +- .../NAS/NR_UE/5GS/5GMM/IES/FGSMobileIdentity.c | 18 +++++++++--------- .../NAS/NR_UE/5GS/5GMM/IES/FGSMobileIdentity.h | 4 ++-- .../NR_UE/5GS/5GMM/IES/FGSRegistrationResult.c | 2 +- .../NR_UE/5GS/5GMM/IES/FGSRegistrationResult.h | 2 +- .../NR_UE/5GS/5GMM/IES/FGSRegistrationType.c | 2 +- .../NR_UE/5GS/5GMM/IES/FGSRegistrationType.h | 2 +- .../5GS/5GMM/IES/NrUESecurityCapability.c | 5 ++++- .../5GS/5GMM/IES/NrUESecurityCapability.h | 5 ++++- .../5GS/5GMM/IES/SORTransparentContainer.c | 10 ++++++++-- .../5GS/5GMM/IES/SORTransparentContainer.h | 10 ++++++++-- .../5GS/5GMM/MSG/FGSAuthenticationResponse.c | 4 +++- .../5GS/5GMM/MSG/FGSAuthenticationResponse.h | 4 +++- .../FGSDeregistrationRequestUEOriginating.c | 4 ++-- .../FGSDeregistrationRequestUEOriginating.h | 2 +- .../5GS/5GMM/MSG/FGSNASSecurityModeComplete.c | 2 +- .../5GS/5GMM/MSG/FGSNASSecurityModeComplete.h | 2 +- .../NR_UE/5GS/5GMM/MSG/FGSUplinkNasTransport.c | 8 ++++---- .../NR_UE/5GS/5GMM/MSG/FGSUplinkNasTransport.h | 2 +- .../NR_UE/5GS/5GMM/MSG/RegistrationAccept.c | 2 +- .../NR_UE/5GS/5GMM/MSG/RegistrationAccept.h | 2 +- .../NR_UE/5GS/5GMM/MSG/RegistrationComplete.c | 6 +++--- .../NR_UE/5GS/5GMM/MSG/RegistrationComplete.h | 4 ++-- .../NR_UE/5GS/5GMM/MSG/RegistrationRequest.c | 4 ++-- .../NR_UE/5GS/5GMM/MSG/RegistrationRequest.h | 4 ++-- .../NR_UE/5GS/5GMM/MSG/fgs_service_request.c | 2 +- .../NR_UE/5GS/5GMM/MSG/fgs_service_request.h | 2 +- 36 files changed, 86 insertions(+), 59 deletions(-) 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/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/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/NR_UE/5GS/5GMM/IES/FGCNasMessageContainer.c b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGCNasMessageContainer.c index 9c317c59d5..d06521c88c 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/IES/FGCNasMessageContainer.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGCNasMessageContainer.c @@ -60,7 +60,7 @@ int decode_fgc_nas_message_container(FGCNasMessageContainer *nasmessagecontainer 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; diff --git a/openair3/NAS/NR_UE/5GS/5GMM/IES/FGCNasMessageContainer.h b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGCNasMessageContainer.h index 5e9c8aac12..a81c1add67 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/IES/FGCNasMessageContainer.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGCNasMessageContainer.h @@ -44,7 +44,7 @@ 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); diff --git a/openair3/NAS/NR_UE/5GS/5GMM/IES/FGMMCapability.c b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGMMCapability.c index 3a275ced7f..c053070518 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/IES/FGMMCapability.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGMMCapability.c @@ -35,7 +35,7 @@ #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) { diff --git a/openair3/NAS/NR_UE/5GS/5GMM/IES/FGMMCapability.h b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGMMCapability.h index a28ba2ff3b..b125935f9d 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/IES/FGMMCapability.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGMMCapability.h @@ -42,6 +42,6 @@ typedef struct { 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/NR_UE/5GS/5GMM/IES/FGSMobileIdentity.c b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSMobileIdentity.c index 6407448279..7e1489ac81 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSMobileIdentity.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSMobileIdentity.c @@ -41,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) @@ -126,7 +126,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) @@ -222,7 +222,7 @@ static int decode_guti_5gs_mobile_identity(Guti5GSMobileIdentity_t *guti, const 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; @@ -245,7 +245,7 @@ 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); @@ -269,7 +269,7 @@ static int encode_suci_5gs_mobile_identity(Suci5GSMobileIdentity_t *suci, uint8_ *(buffer + encoded) = suci->homenetworkpki; encoded++; - char *ptr = suci->schemeoutput; + const char *ptr = suci->schemeoutput; while (ptr < suci->schemeoutput + strlen(suci->schemeoutput)) { buffer[encoded] = ((*(ptr + 1) - '0') << 4) | (*(ptr) - '0'); encoded++; @@ -281,7 +281,7 @@ static int encode_suci_5gs_mobile_identity(Suci5GSMobileIdentity_t *suci, uint8_ 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); diff --git a/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSMobileIdentity.h b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSMobileIdentity.h index a66b74dc51..b7e66019cc 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSMobileIdentity.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSMobileIdentity.h @@ -148,11 +148,11 @@ typedef union FGSMobileIdentity_tag { } 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/NR_UE/5GS/5GMM/IES/FGSRegistrationResult.c b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSRegistrationResult.c index 88eb1b810b..739cee7973 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSRegistrationResult.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSRegistrationResult.c @@ -46,7 +46,7 @@ int decode_fgs_registration_result(FGSRegistrationResult *fgsregistrationresult, 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; diff --git a/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSRegistrationResult.h b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSRegistrationResult.h index b792dad13c..04f45417b8 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSRegistrationResult.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSRegistrationResult.h @@ -48,7 +48,7 @@ typedef struct { 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); diff --git a/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSRegistrationType.c b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSRegistrationType.c index d50d7bc852..81825f585a 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSRegistrationType.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSRegistrationType.c @@ -49,7 +49,7 @@ 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; diff --git a/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSRegistrationType.h b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSRegistrationType.h index 4298a33504..ea42ac160e 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSRegistrationType.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSRegistrationType.h @@ -47,7 +47,7 @@ typedef uint8_t FGSRegistrationType; #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); diff --git a/openair3/NAS/NR_UE/5GS/5GMM/IES/NrUESecurityCapability.c b/openair3/NAS/NR_UE/5GS/5GMM/IES/NrUESecurityCapability.c index d069b50a39..5d2d7cc040 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/IES/NrUESecurityCapability.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/IES/NrUESecurityCapability.c @@ -35,7 +35,10 @@ #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) { diff --git a/openair3/NAS/NR_UE/5GS/5GMM/IES/NrUESecurityCapability.h b/openair3/NAS/NR_UE/5GS/5GMM/IES/NrUESecurityCapability.h index b772feeba7..a8ee4391b3 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/IES/NrUESecurityCapability.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/IES/NrUESecurityCapability.h @@ -45,6 +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/NR_UE/5GS/5GMM/IES/SORTransparentContainer.c b/openair3/NAS/NR_UE/5GS/5GMM/IES/SORTransparentContainer.c index 3bbcb89f92..9a6af8517c 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/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; @@ -61,7 +64,10 @@ int decode_sor_transparent_container(SORTransparentContainer *sortransparentcont 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; diff --git a/openair3/NAS/NR_UE/5GS/5GMM/IES/SORTransparentContainer.h b/openair3/NAS/NR_UE/5GS/5GMM/IES/SORTransparentContainer.h index 652710c0b3..7ed4e039ef 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/IES/SORTransparentContainer.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/IES/SORTransparentContainer.h @@ -35,9 +35,15 @@ 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); diff --git a/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSAuthenticationResponse.c b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSAuthenticationResponse.c index d93f03aed5..319026f9ef 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSAuthenticationResponse.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSAuthenticationResponse.c @@ -37,7 +37,9 @@ #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; diff --git a/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSAuthenticationResponse.h b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSAuthenticationResponse.h index d67e43bb7b..6f5427531b 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSAuthenticationResponse.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSAuthenticationResponse.h @@ -57,6 +57,8 @@ typedef struct fgs_authentication_response_msg_tag { 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/NR_UE/5GS/5GMM/MSG/FGSDeregistrationRequestUEOriginating.c b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSDeregistrationRequestUEOriginating.c index 6e1c0f102e..dbe1a548fb 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSDeregistrationRequestUEOriginating.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSDeregistrationRequestUEOriginating.c @@ -32,12 +32,12 @@ #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; + const FGSDeregistrationType *dt = &drr->deregistrationtype; *(buffer + encoded) = ((dt->switchoff & 0x1) << 7) | ((dt->reregistration_required & 0x1) << 6) | ((dt->access_type & 0x3) << 4); int encode_result; diff --git a/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSDeregistrationRequestUEOriginating.h b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSDeregistrationRequestUEOriginating.h index 566c00c11c..3c3bf3114f 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSDeregistrationRequestUEOriginating.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSDeregistrationRequestUEOriginating.h @@ -47,7 +47,7 @@ typedef struct fgs_deregistration_request_ue_originating_msg_tag { 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); diff --git a/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSNASSecurityModeComplete.c b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSNASSecurityModeComplete.c index 369f3a3e2d..f24dc50749 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSNASSecurityModeComplete.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSNASSecurityModeComplete.c @@ -33,7 +33,7 @@ #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; diff --git a/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSNASSecurityModeComplete.h b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSNASSecurityModeComplete.h index 36ec4ed2b2..01f6cc15d4 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSNASSecurityModeComplete.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSNASSecurityModeComplete.h @@ -54,6 +54,6 @@ typedef struct fgs_security_mode_complete_msg_tag { 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/NR_UE/5GS/5GMM/MSG/FGSUplinkNasTransport.c b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSUplinkNasTransport.c index 26d2e9ad61..6b1b748146 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSUplinkNasTransport.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSUplinkNasTransport.c @@ -34,7 +34,7 @@ #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; @@ -62,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; @@ -84,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; @@ -106,7 +106,7 @@ 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; diff --git a/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSUplinkNasTransport.h b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSUplinkNasTransport.h index 6c045d7d48..06ade93896 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSUplinkNasTransport.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSUplinkNasTransport.h @@ -66,6 +66,6 @@ typedef struct fgs_uplink_nas_transport_msg_tag { 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 index b110ca75a3..bca9dff06a 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationAccept.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationAccept.c @@ -65,7 +65,7 @@ int decode_registration_accept(registration_accept_msg *registration_accept, con return decoded; } -int encode_registration_accept(registration_accept_msg *registration_accept, uint8_t *buffer, uint32_t len) +int encode_registration_accept(const registration_accept_msg *registration_accept, uint8_t *buffer, uint32_t len) { int encoded = 0; diff --git a/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationAccept.h b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationAccept.h index 61c987db4b..d48a8f21d4 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationAccept.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationAccept.h @@ -61,6 +61,6 @@ typedef struct registration_accept_msg_tag { 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/NR_UE/5GS/5GMM/MSG/RegistrationComplete.c b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationComplete.c index 702b3ab600..0ce14cdcd8 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationComplete.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationComplete.c @@ -23,14 +23,14 @@ #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)) + decode_sor_transparent_container(registration_complete->sortransparentcontainer, 0, buffer + decoded, len - decoded)) < 0) return decoded_result; else @@ -39,7 +39,7 @@ 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; diff --git a/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationComplete.h b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationComplete.h index e97c8d262d..1c2141243a 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationComplete.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationComplete.h @@ -41,8 +41,8 @@ typedef struct registration_complete_msg_tag { SORTransparentContainer *sortransparentcontainer; } registration_complete_msg; -int decode_registration_complete(registration_complete_msg *registrationcomplete, uint8_t *buffer, uint32_t len); +int decode_registration_complete(registration_complete_msg *registrationcomplete, const 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/NR_UE/5GS/5GMM/MSG/RegistrationRequest.c b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationRequest.c index dd08e61dba..8f6fea900e 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationRequest.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationRequest.c @@ -34,7 +34,7 @@ #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; @@ -68,7 +68,7 @@ int decode_registration_request(registration_request_msg *registration_request, 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; diff --git a/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationRequest.h b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationRequest.h index 3ae943a5f1..9112fa6795 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationRequest.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationRequest.h @@ -112,8 +112,8 @@ typedef struct registration_request_msg_tag { 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/NR_UE/5GS/5GMM/MSG/fgs_service_request.c b/openair3/NAS/NR_UE/5GS/5GMM/MSG/fgs_service_request.c index fa31e1e297..4603db55c5 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/MSG/fgs_service_request.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/fgs_service_request.c @@ -38,7 +38,7 @@ /** * @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/NR_UE/5GS/5GMM/MSG/fgs_service_request.h b/openair3/NAS/NR_UE/5GS/5GMM/MSG/fgs_service_request.h index 79c7c00c62..82a721d52a 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/MSG/fgs_service_request.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/fgs_service_request.h @@ -53,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_) */ From 63d7f26cfd1d5992697b0c2b7244fb85830efd48 Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Wed, 13 Nov 2024 10:03:27 +0100 Subject: [PATCH 21/35] Refactor NAS 5GMM messages structs definitions as per legacy code, the NAS functions in nr_nas_msg.c were encoding the header in the plain header contained in MM_msg (e.g. plain -> mm_msg -> header in fgs_nas_message_t). The same header was encoded in the mobility management message contained in the same struct (e.g. plain -> mm_msg -> registration_request -> protocoldiscriminator). As this was more complicated than necessary, the goal of this commit is to simplify the code and improve readability. Namely: * Refactor MM_msg into fgmm_nas_message_plain_t to contain (1) 5GMM Header (2) 5GMM Payload union * Use fgmm_nas_message_plain_t and fgmm_nas_msg_security_protected_t in the 5GMM NAS procedures * Remove NAS header IEs from 5GMM messages structs and use the header in fgs_nas_message_plain_t. This reduce also the repetitions of header members in each of the 5GMM messages structs. * Rename struct to distinguish between 5GMM and 5GSM * Remove fgs_nas_message_t and nas_msg_header_t, use directly basic 5GS struct definitions, simplify the code * The callbacks in nr_nas_msg.c are now doing (1) encode header with the common NAS lib (2) encode contents with the 5GMM libs * improve code readibility in the process --- .../5GS/5GMM/MSG/FGSAuthenticationResponse.h | 4 - .../FGSDeregistrationRequestUEOriginating.h | 4 - .../NR_UE/5GS/5GMM/MSG/FGSIdentityResponse.h | 4 - .../5GS/5GMM/MSG/FGSNASSecurityModeComplete.h | 4 - .../5GS/5GMM/MSG/FGSUplinkNasTransport.h | 4 - .../NR_UE/5GS/5GMM/MSG/RegistrationAccept.h | 5 - .../NR_UE/5GS/5GMM/MSG/RegistrationRequest.h | 5 - openair3/NAS/NR_UE/5GS/NR_NAS_defs.h | 57 +-- openair3/NAS/NR_UE/5GS/fgs_nas_lib.c | 26 +- openair3/NAS/NR_UE/nr_nas_msg.c | 340 ++++++++---------- 10 files changed, 191 insertions(+), 262 deletions(-) diff --git a/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSAuthenticationResponse.h b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSAuthenticationResponse.h index 6f5427531b..6c0f0eaa64 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSAuthenticationResponse.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSAuthenticationResponse.h @@ -50,10 +50,6 @@ typedef struct fgs_authentication_response_msg_tag { /* Mandatory fields */ - uint8_t protocoldiscriminator; - SecurityHeaderType securityheadertype: 4; - uint8_t sparehalfoctet: 4; - MessageType messagetype; AuthenticationResponseParameter authenticationresponseparameter; } fgs_authentication_response_msg; diff --git a/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSDeregistrationRequestUEOriginating.h b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSDeregistrationRequestUEOriginating.h index 3c3bf3114f..6374b55895 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSDeregistrationRequestUEOriginating.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSDeregistrationRequestUEOriginating.h @@ -38,10 +38,6 @@ typedef struct fgs_deregistration_request_ue_originating_msg_tag { /* Mandatory fields */ - uint8_t protocoldiscriminator; - SecurityHeaderType securityheadertype: 4; - uint8_t sparehalfoctet: 4; - MessageType messagetype; FGSDeregistrationType deregistrationtype; NasKeySetIdentifier naskeysetidentifier; FGSMobileIdentity fgsmobileidentity; diff --git a/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSIdentityResponse.h b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSIdentityResponse.h index 74cc6879a6..667cb80c59 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSIdentityResponse.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSIdentityResponse.h @@ -45,10 +45,6 @@ typedef struct fgmm_identity_response_msg_s { /* Mandatory fields */ - uint8_t protocoldiscriminator; - SecurityHeaderType securityheadertype: 4; - uint8_t sparehalfoctet: 4; - MessageType messagetype; FGSMobileIdentity fgsmobileidentity; } fgmm_identity_response_msg; diff --git a/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSNASSecurityModeComplete.h b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSNASSecurityModeComplete.h index 01f6cc15d4..4c379dadee 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSNASSecurityModeComplete.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSNASSecurityModeComplete.h @@ -46,10 +46,6 @@ typedef struct fgs_security_mode_complete_msg_tag { /* Mandatory fields */ - uint8_t protocoldiscriminator; - SecurityHeaderType securityheadertype: 4; - uint8_t sparehalfoctet: 4; - MessageType messagetype; FGSMobileIdentity fgsmobileidentity; FGCNasMessageContainer fgsnasmessagecontainer; } fgs_security_mode_complete_msg; diff --git a/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSUplinkNasTransport.h b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSUplinkNasTransport.h index 06ade93896..7b828a1ed3 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSUplinkNasTransport.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/FGSUplinkNasTransport.h @@ -53,10 +53,6 @@ typedef struct FGSPayloadContainer_tag { typedef struct fgs_uplink_nas_transport_msg_tag { /* Mandatory fields */ - uint8_t protocoldiscriminator; - SecurityHeaderType securityheadertype: 4; - uint8_t sparehalfoctet: 4; - MessageType messagetype; PayloadContainerType payloadcontainertype; FGSPayloadContainer fgspayloadcontainer; /* Optional fields */ diff --git a/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationAccept.h b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationAccept.h index d48a8f21d4..91b024a7d8 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationAccept.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationAccept.h @@ -49,12 +49,7 @@ typedef struct registration_accept_msg_tag { /* Mandatory fields */ - uint8_t protocoldiscriminator; - SecurityHeaderType securityheadertype: 4; - uint8_t sparehalfoctet: 4; - MessageType messagetype; FGSRegistrationResult fgsregistrationresult; - /* Optional fields */ FGSMobileIdentity *guti; } registration_accept_msg; diff --git a/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationRequest.h b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationRequest.h index 9112fa6795..686b0bc148 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationRequest.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationRequest.h @@ -98,14 +98,9 @@ typedef enum registration_request_iei_tag { typedef struct registration_request_msg_tag { /* Mandatory fields */ - uint8_t protocoldiscriminator; - SecurityHeaderType securityheadertype: 4; - uint8_t sparehalfoctet: 4; - MessageType messagetype; FGSRegistrationType fgsregistrationtype; NasKeySetIdentifier naskeysetidentifier; FGSMobileIdentity fgsmobileidentity; - /* Optional fields */ uint32_t presencemask; FGMMCapability fgmmcapability; diff --git a/openair3/NAS/NR_UE/5GS/NR_NAS_defs.h b/openair3/NAS/NR_UE/5GS/NR_NAS_defs.h index 206cdab279..548909e2b3 100644 --- a/openair3/NAS/NR_UE/5GS/NR_NAS_defs.h +++ b/openair3/NAS/NR_UE/5GS/NR_NAS_defs.h @@ -258,45 +258,26 @@ typedef struct { uint8_t message_type; } fgmm_msg_header_t; -/// 5GS legacy defs - -typedef union { +/* Plain 5GMM NAS message (5GS) */ +typedef struct { fgmm_msg_header_t header; - 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; - -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 { - fgmm_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; + 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 @@ -317,7 +298,7 @@ typedef struct { /// Function prototypes -int mm_msg_encode(const MM_msg *mm_msg, uint8_t *buffer, uint32_t len); +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); diff --git a/openair3/NAS/NR_UE/5GS/fgs_nas_lib.c b/openair3/NAS/NR_UE/5GS/fgs_nas_lib.c index 75f045846d..b077476b31 100644 --- a/openair3/NAS/NR_UE/5GS/fgs_nas_lib.c +++ b/openair3/NAS/NR_UE/5GS/fgs_nas_lib.c @@ -48,15 +48,15 @@ int _nas_mm_msg_encode_header(const fgmm_msg_header_t *header, uint8_t *buffer, return (size); } -int mm_msg_encode(const MM_msg *mm_msg, uint8_t *buffer, uint32_t len) +int mm_msg_encode(const fgmm_nas_message_plain_t *p, uint8_t *buffer, uint32_t len) { LOG_FUNC_IN; int header_result; int encode_result; - uint8_t msg_type = mm_msg->header.message_type; + uint8_t msg_type = p->header.message_type; - /* First encode the EMM message header */ - header_result = _nas_mm_msg_encode_header(&mm_msg->header, buffer, len); + /* First encode the 5GMM message header */ + header_result = _nas_mm_msg_encode_header(&p->header, buffer, len); if (header_result < 0) { LOG_TRACE(ERROR, @@ -71,29 +71,29 @@ int mm_msg_encode(const MM_msg *mm_msg, uint8_t *buffer, uint32_t len) switch (msg_type) { case FGS_REGISTRATION_REQUEST: - encode_result = encode_registration_request(&mm_msg->registration_request, buffer, len); + encode_result = encode_registration_request(&p->mm_msg.registration_request, buffer, len); break; case FGS_IDENTITY_RESPONSE: - encode_result = encode_fgmm_identity_response(buffer, &mm_msg->fgs_identity_response, len); + encode_result = encode_fgmm_identity_response(buffer, &p->mm_msg.fgs_identity_response, len); break; case FGS_AUTHENTICATION_RESPONSE: - encode_result = encode_fgs_authentication_response(&mm_msg->fgs_auth_response, buffer, len); + encode_result = encode_fgs_authentication_response(&p->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); + encode_result = encode_fgs_security_mode_complete(&p->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); + encode_result = encode_fgs_uplink_nas_transport(&p->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); + encode_fgs_deregistration_request_ue_originating(&p->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); + encode_result = encode_fgs_service_request(buffer, &p->mm_msg.service_request, len); break; default: - LOG_TRACE(ERROR, " Unexpected message type: 0x%x", mm_msg->header.message_type); + LOG_TRACE(ERROR, " Unexpected message type: 0x%x", p->header.message_type); encode_result = TLV_ENCODE_WRONG_MESSAGE_TYPE; break; /* TODO: Handle not standard layer 3 messages: SERVICE_REQUEST */ @@ -103,7 +103,7 @@ int mm_msg_encode(const MM_msg *mm_msg, uint8_t *buffer, uint32_t len) LOG_TRACE(ERROR, " Failed to encode L3 EMM message 0x%x " "(%d)", - mm_msg->header.message_type, + p->header.message_type, encode_result); } diff --git a/openair3/NAS/NR_UE/nr_nas_msg.c b/openair3/NAS/NR_UE/nr_nas_msg.c index 6109f69234..bd848e9c55 100644 --- a/openair3/NAS/NR_UE/nr_nas_msg.c +++ b/openair3/NAS/NR_UE/nr_nas_msg.c @@ -47,6 +47,7 @@ #include "PduSessionEstablishmentAccept.h" #include "RegistrationAccept.h" #include "SORTransparentContainer.h" +#include "FGSIdentityResponse.h" #include "T.h" #include "aka_functions.h" #include "assertions.h" @@ -428,29 +429,24 @@ 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(fgmm_msg_header_t); - fgs_nas_message_t nas_msg = {0}; - MM_msg *mm_msg; + 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_REGISTRATION_REQUEST; + // Plain 5GMM header + fgmm_msg_header_t *mm_header = &plain.header; + mm_header->ex_protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; + mm_header->security_header_type = PLAIN_5GS_MSG; + mm_header->message_type = FGS_REGISTRATION_REQUEST; + size += 3; - // 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 = FGS_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 @@ -465,20 +461,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(*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; } @@ -486,47 +482,52 @@ 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; + fgmm_nas_message_plain_t plain = {0}; + fgs_service_request_msg_t *mm_msg; + fgmm_nas_msg_security_protected_t sp = {0}; + fgmm_msg_header_t *mm_header; 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; + 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(fgs_nas_message_security_header_t); - mm_msg = &nas_msg.security_protected.plain.mm_msg; + mm_msg = &sp.plain.mm_msg.service_request; + // Plain 5GMM header + mm_header = &sp.plain.header; } else { // Set Mobility Management plain message header - mm_msg = &nas_msg.plain.mm_msg; + mm_msg = &plain.mm_msg.service_request; + // Plain 5GMM header + mm_header = &plain.header; } - // 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); + mm_header->ex_protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; + mm_header->security_header_type = PLAIN_5GS_MSG; + mm_header->message_type = FGS_SERVICE_REQUEST; + size += sizeof(*mm_header); // Fill 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 = malloc_or_fail(size * sizeof(*initialNasMsg->nas_data)); if (security_protected) { // 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; @@ -555,7 +556,7 @@ void generateServiceRequest(as_nas_info_t *initialNasMsg, nr_ue_nas_t *nas) initialNasMsg->nas_data[2 + i] = mac[i]; } else { // plain encoding - initialNasMsg->length = mm_msg_encode(mm_msg, (uint8_t *)(initialNasMsg->nas_data), size); + initialNasMsg->length = mm_msg_encode(&plain, (uint8_t *)(initialNasMsg->nas_data), size); LOG_I(NAS, "PLAIN_5GS_MSG initial NAS message: Service Request with length %d \n", initialNasMsg->length); } } @@ -563,31 +564,25 @@ void generateServiceRequest(as_nas_info_t *initialNasMsg, nr_ue_nas_t *nas) void generateIdentityResponse(as_nas_info_t *initialNasMsg, uint8_t identitytype, uicc_t *uicc) { int size = sizeof(fgmm_msg_header_t); - fgs_nas_message_t nas_msg; - memset(&nas_msg, 0, sizeof(fgs_nas_message_t)); - MM_msg *mm_msg; + 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 + fgmm_msg_header_t *mm_header = &plain.header; + mm_header->ex_protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; + mm_header->security_header_type = PLAIN_5GS_MSG; + mm_header->message_type = FGS_IDENTITY_RESPONSE; + size += 3; // 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_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) @@ -599,31 +594,23 @@ static void generateAuthenticationResp(nr_ue_nas_t *nas, as_nas_info_t *initialN memcpy(res.value, nas->security.res, 16); int size = sizeof(fgmm_msg_header_t); - fgs_nas_message_t nas_msg; - memset(&nas_msg, 0, sizeof(fgs_nas_message_t)); - MM_msg *mm_msg; + 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 + fgmm_msg_header_t *mm_header = &plain.header; + mm_header->ex_protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; + mm_header->security_header_type = PLAIN_5GS_MSG; + mm_header->message_type = FGS_AUTHENTICATION_RESPONSE; + size += 3; // 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_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); } @@ -639,37 +626,32 @@ 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(fgmm_msg_header_t); - fgs_nas_message_t nas_msg; - memset(&nas_msg, 0, sizeof(fgs_nas_message_t)); - - MM_msg *mm_msg; + fgmm_nas_msg_security_protected_t nas_msg = {0}; nas_stream_cipher_t stream_cipher; uint8_t mac[4]; // 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 + fgmm_msg_header_t *mm_header = &plain->header; + mm_header->ex_protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; + mm_header->security_header_type = PLAIN_5GS_MSG; + mm_header->message_type = FGS_SECURITY_MODE_COMPLETE; + size += 3; - // 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 @@ -679,7 +661,7 @@ static void generateSecurityModeComplete(nr_ue_nas_t *nas, as_nas_info_t *initia 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]; @@ -774,29 +756,26 @@ static void generateRegistrationComplete(nr_ue_nas_t *nas, SORTransparentContainer *sortransparentcontainer) { int length = 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; + fgmm_nas_msg_security_protected_t sp = {0}; - sp_msg = &nas_msg.security_protected; // set security protected 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; + 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; // set plain 5GMM header - sp_msg->plain.mm_msg.header.ex_protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; - length += 1; - sp_msg->plain.mm_msg.header.security_header_type = PLAIN_5GS_MSG; - length += 1; - sp_msg->plain.mm_msg.header.message_type = FGS_REGISTRATION_COMPLETE; - length += 1; + fgmm_msg_header_t *mm_header = &sp.plain.header; + mm_header->ex_protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; + mm_header->security_header_type = PLAIN_5GS_MSG; + mm_header->message_type = FGS_REGISTRATION_COMPLETE; + length += 3; + registration_complete_msg *mm_msg = &sp.plain.mm_msg.registration_complete; if (sortransparentcontainer) { - sp_msg->plain.mm_msg.registration_complete.sortransparentcontainer = sortransparentcontainer; + mm_msg->sortransparentcontainer = sortransparentcontainer; length += sortransparentcontainer->sortransparentcontainercontents.length; } @@ -804,19 +783,19 @@ static void generateRegistrationComplete(nr_ue_nas_t *nas, initialNasMsg->nas_data = malloc_or_fail(length * sizeof(*initialNasMsg->nas_data)); initialNasMsg->length = length; // encode security protected header - int encoded = nas_protected_security_header_encode(initialNasMsg->nas_data, &sp_msg->header, length); + 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_msg->plain.mm_msg.header, initialNasMsg->nas_data + encoded, length - encoded); + encoded = _nas_mm_msg_encode_header(mm_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(&sp_msg->plain.mm_msg.registration_complete, initialNasMsg->nas_data + encoded, length - encoded); + encode_registration_complete(mm_msg, initialNasMsg->nas_data + encoded, length - encoded); /* ciphering */ uint8_t buf[initialNasMsg->length - 7]; @@ -863,36 +842,37 @@ 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(sp_msg->header); + 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 + fgmm_msg_header_t *mm_header = &sp_msg.plain.header; + mm_header->ex_protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; + mm_header->security_header_type = INTEGRITY_PROTECTED_AND_CIPHERED_WITH_NEW_SECU_CTX; + mm_header->message_type = FGS_DEREGISTRATION_REQUEST_UE_ORIGINATING; + size += 3; + + // 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_or_fail(size, sizeof(*initialNasMsg->nas_data)); - int security_header_len = nas_protected_security_header_encode(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(&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; @@ -929,7 +909,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; @@ -943,69 +922,68 @@ 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; + + // 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 + fgmm_msg_header_t *mm_header = &plain->header; + mm_header->ex_protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; + mm_header->security_header_type = PLAIN_5GS_MSG; + mm_header->message_type = FGS_UPLINK_NAS_TRANSPORT; + size += 3; - // 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 = malloc_or_fail(size * sizeof(*initialNasMsg->nas_data)); - int security_header_len = nas_protected_security_header_encode(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(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]; @@ -1153,7 +1131,7 @@ static void get_allowed_nssai(nr_nas_msg_snssai_t nssai[8], const uint8_t *pdu_b 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) { + if (((fgs_nas_message_security_header_t *)(pdu_buffer))->security_header_type > 0) { pdu_buffer += SECURITY_PROTECTED_5GS_NAS_MESSAGE_HEADER_LENGTH; } From 2c5309f0f81ee817f54c364404f5d1b807fcc681 Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Wed, 11 Dec 2024 14:51:48 +0100 Subject: [PATCH 22/35] Add function to fill fgmm_msg_header_t type headers --- openair3/NAS/NR_UE/nr_nas_msg.c | 71 +++++++++++++-------------------- 1 file changed, 28 insertions(+), 43 deletions(-) diff --git a/openair3/NAS/NR_UE/nr_nas_msg.c b/openair3/NAS/NR_UE/nr_nas_msg.c index bd848e9c55..8449a80ab2 100644 --- a/openair3/NAS/NR_UE/nr_nas_msg.c +++ b/openair3/NAS/NR_UE/nr_nas_msg.c @@ -77,6 +77,15 @@ typedef enum { NAS_SECURITY_BAD_INPUT } security_state_t; +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 nmc_size) { // SNN-network-identifier in TS 24.501 @@ -432,11 +441,8 @@ void generateRegistrationRequest(as_nas_info_t *initialNasMsg, nr_ue_nas_t *nas) fgmm_nas_message_plain_t plain = {0}; // Plain 5GMM header - fgmm_msg_header_t *mm_header = &plain.header; - mm_header->ex_protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; - mm_header->security_header_type = PLAIN_5GS_MSG; - mm_header->message_type = FGS_REGISTRATION_REQUEST; - size += 3; + plain.header = set_mm_header(FGS_REGISTRATION_REQUEST, PLAIN_5GS_MSG); + size += sizeof(plain.header); // Plain 5GMM msg registration_request_msg *mm_msg = &plain.mm_msg.registration_request; @@ -488,7 +494,7 @@ void generateServiceRequest(as_nas_info_t *initialNasMsg, nr_ue_nas_t *nas) fgmm_nas_message_plain_t plain = {0}; fgs_service_request_msg_t *mm_msg; fgmm_nas_msg_security_protected_t sp = {0}; - fgmm_msg_header_t *mm_header; + fgmm_msg_header_t mm_header = set_mm_header(FGS_SERVICE_REQUEST, PLAIN_5GS_MSG); if (security_protected) { /* Set security protected 5GS NAS message header (see 9.1.1 of 3GPP TS 24.501) */ @@ -498,17 +504,14 @@ void generateServiceRequest(as_nas_info_t *initialNasMsg, nr_ue_nas_t *nas) size += sizeof(fgs_nas_message_security_header_t); mm_msg = &sp.plain.mm_msg.service_request; // Plain 5GMM header - mm_header = &sp.plain.header; + sp.plain.header = mm_header; } else { // Set Mobility Management plain message header mm_msg = &plain.mm_msg.service_request; // Plain 5GMM header - mm_header = &plain.header; + plain.header = mm_header; } - mm_header->ex_protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; - mm_header->security_header_type = PLAIN_5GS_MSG; - mm_header->message_type = FGS_SERVICE_REQUEST; - size += sizeof(*mm_header); + size += sizeof(mm_header); // Fill Service Request // Service Type @@ -567,11 +570,8 @@ void generateIdentityResponse(as_nas_info_t *initialNasMsg, uint8_t identitytype fgmm_nas_message_plain_t plain = {0}; // Plain 5GMM header - fgmm_msg_header_t *mm_header = &plain.header; - mm_header->ex_protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; - mm_header->security_header_type = PLAIN_5GS_MSG; - mm_header->message_type = FGS_IDENTITY_RESPONSE; - size += 3; + plain.header = set_mm_header(FGS_IDENTITY_RESPONSE, PLAIN_5GS_MSG); + size += sizeof(plain.header); // set identity response fgmm_identity_response_msg *mm_msg = &plain.mm_msg.fgs_identity_response; @@ -597,11 +597,8 @@ static void generateAuthenticationResp(nr_ue_nas_t *nas, as_nas_info_t *initialN fgmm_nas_message_plain_t plain = {0}; // Plain 5GMM header - fgmm_msg_header_t *mm_header = &plain.header; - mm_header->ex_protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; - mm_header->security_header_type = PLAIN_5GS_MSG; - mm_header->message_type = FGS_AUTHENTICATION_RESPONSE; - size += 3; + plain.header = set_mm_header(FGS_AUTHENTICATION_RESPONSE, PLAIN_5GS_MSG); + size += sizeof(plain.header); // set response parameter fgs_authentication_response_msg *mm_msg = &plain.mm_msg.fgs_auth_response; @@ -640,11 +637,8 @@ static void generateSecurityModeComplete(nr_ue_nas_t *nas, as_nas_info_t *initia fgmm_nas_message_plain_t *plain = &nas_msg.plain; // Plain 5GMM header - fgmm_msg_header_t *mm_header = &plain->header; - mm_header->ex_protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; - mm_header->security_header_type = PLAIN_5GS_MSG; - mm_header->message_type = FGS_SECURITY_MODE_COMPLETE; - size += 3; + plain->header = set_mm_header(FGS_SECURITY_MODE_COMPLETE, PLAIN_5GS_MSG); + size += sizeof(plain->header); // Plain 5GMM payload fgs_security_mode_complete_msg *mm_msg = &plain->mm_msg.fgs_security_mode_complete; @@ -767,11 +761,8 @@ static void generateRegistrationComplete(nr_ue_nas_t *nas, sp.header.sequence_number = nas->security.nas_count_ul & 0xff; length = 7; // set plain 5GMM header - fgmm_msg_header_t *mm_header = &sp.plain.header; - mm_header->ex_protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; - mm_header->security_header_type = PLAIN_5GS_MSG; - mm_header->message_type = FGS_REGISTRATION_COMPLETE; - length += 3; + 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) { @@ -789,7 +780,7 @@ static void generateRegistrationComplete(nr_ue_nas_t *nas, return; } // encode 5GMM plain header - encoded = _nas_mm_msg_encode_header(mm_header, initialNasMsg->nas_data + encoded, length - encoded); + 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; @@ -851,11 +842,8 @@ static void generateDeregistrationRequest(nr_ue_nas_t *nas, as_nas_info_t *initi int size = sizeof(sp_msg.header); // Plain 5GMM header - fgmm_msg_header_t *mm_header = &sp_msg.plain.header; - mm_header->ex_protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; - mm_header->security_header_type = INTEGRITY_PROTECTED_AND_CIPHERED_WITH_NEW_SECU_CTX; - mm_header->message_type = FGS_DEREGISTRATION_REQUEST_UE_ORIGINATING; - size += 3; + 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; @@ -938,11 +926,8 @@ static void generatePduSessionEstablishRequest(nr_ue_nas_t *nas, as_nas_info_t * fgmm_nas_message_plain_t *plain = &sp_msg.plain; // Plain 5GMM header - fgmm_msg_header_t *mm_header = &plain->header; - mm_header->ex_protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; - mm_header->security_header_type = PLAIN_5GS_MSG; - mm_header->message_type = FGS_UPLINK_NAS_TRANSPORT; - size += 3; + plain->header = set_mm_header(FGS_UPLINK_NAS_TRANSPORT, PLAIN_5GS_MSG); + size += sizeof(plain->header); fgs_uplink_nas_transport_msg *mm_msg = &plain->mm_msg.uplink_nas_transport; mm_msg->payloadcontainertype.iei = 0; From b07ddb1e5747ea7e0b9cc0001e3b9310203fbf3d Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Wed, 11 Dec 2024 15:08:32 +0100 Subject: [PATCH 23/35] Refactor generateServiceRequest * simplified code, reduced conditional statements, reduced number of pointers --- openair3/NAS/NR_UE/nr_nas_msg.c | 50 ++++++++++++++++----------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/openair3/NAS/NR_UE/nr_nas_msg.c b/openair3/NAS/NR_UE/nr_nas_msg.c index 8449a80ab2..204c3733ec 100644 --- a/openair3/NAS/NR_UE/nr_nas_msg.c +++ b/openair3/NAS/NR_UE/nr_nas_msg.c @@ -491,29 +491,13 @@ void generateServiceRequest(as_nas_info_t *initialNasMsg, nr_ue_nas_t *nas) // NAS is security protected if has valid security contexts bool security_protected = nas->security_container->ciphering_context && nas->security_container->integrity_context; + + // Set 5GMM plain header fgmm_nas_message_plain_t plain = {0}; - fgs_service_request_msg_t *mm_msg; - fgmm_nas_msg_security_protected_t sp = {0}; - fgmm_msg_header_t mm_header = set_mm_header(FGS_SERVICE_REQUEST, PLAIN_5GS_MSG); - - if (security_protected) { - /* 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(fgs_nas_message_security_header_t); - mm_msg = &sp.plain.mm_msg.service_request; - // Plain 5GMM header - sp.plain.header = mm_header; - } else { - // Set Mobility Management plain message header - mm_msg = &plain.mm_msg.service_request; - // Plain 5GMM header - plain.header = mm_header; - } - size += sizeof(mm_header); - - // Fill Service Request + 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->serviceType = SERVICE_TYPE_DATA; // NAS key set identifier @@ -523,9 +507,21 @@ void generateServiceRequest(as_nas_info_t *initialNasMsg, nr_ue_nas_t *nas) // 5G-S-TMSI size += fill_fgstmsi(&mm_msg->fiveg_s_tmsi, nas->guti); - /* message encoding */ - initialNasMsg->nas_data = malloc_or_fail(size * sizeof(*initialNasMsg->nas_data)); 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(initialNasMsg->nas_data, &sp.header, size); initialNasMsg->length = @@ -554,12 +550,14 @@ 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(&plain, (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); } } From 2e651ed21c6c24533303d4533c1872b64b8cd3c6 Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Wed, 13 Nov 2024 12:06:26 +0100 Subject: [PATCH 24/35] Add NAS 5GS header decoding functions --- openair3/NAS/NR_UE/5GS/NR_NAS_defs.h | 3 ++ openair3/NAS/NR_UE/5GS/fgs_nas_lib.c | 54 ++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/openair3/NAS/NR_UE/5GS/NR_NAS_defs.h b/openair3/NAS/NR_UE/5GS/NR_NAS_defs.h index 548909e2b3..bbff5069e2 100644 --- a/openair3/NAS/NR_UE/5GS/NR_NAS_defs.h +++ b/openair3/NAS/NR_UE/5GS/NR_NAS_defs.h @@ -301,5 +301,8 @@ typedef struct { 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 index b077476b31..723306b6bc 100644 --- a/openair3/NAS/NR_UE/5GS/fgs_nas_lib.c +++ b/openair3/NAS/NR_UE/5GS/fgs_nas_lib.c @@ -132,3 +132,57 @@ int nas_protected_security_header_encode(uint8_t *buffer, const fgs_nas_message_ LOG_FUNC_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; +} From 384659ed54bfeb79a692b306910402a8d307e318 Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Wed, 11 Dec 2024 12:50:54 +0100 Subject: [PATCH 25/35] Refactor capture_pdu_session_establishment_accept_msg * the goal of this commit is to refactor capture_pdu_session_establishment_accept_msg into a decoding function * PduSessionEstablishmentAccept.c is in the 5GSM library and shall only do encoding operations * handling of PDU Session Establishment accept message is done in nr_nas_msg.c * adopted new NAS decoding functions in the process * improved QoS rules decoding * convert getShort into a macro and add to NAS utils --- .../NAS/NR_UE/5GS/5GSM/MSG/CMakeLists.txt | 6 +- .../5GSM/MSG/PduSessionEstablishmentAccept.c | 202 ++++++++---------- .../5GSM/MSG/PduSessionEstablishmentAccept.h | 57 +++-- openair3/NAS/NR_UE/5GS/fgs_nas_utils.h | 8 + openair3/NAS/NR_UE/nr_nas_msg.c | 123 ++++++++++- 5 files changed, 254 insertions(+), 142 deletions(-) diff --git a/openair3/NAS/NR_UE/5GS/5GSM/MSG/CMakeLists.txt b/openair3/NAS/NR_UE/5GS/5GSM/MSG/CMakeLists.txt index ca115451b3..1630a48222 100644 --- a/openair3/NAS/NR_UE/5GS/5GSM/MSG/CMakeLists.txt +++ b/openair3/NAS/NR_UE/5GS/5GSM/MSG/CMakeLists.txt @@ -3,8 +3,4 @@ add_library(fgs_5gsm_lib OBJECT PduSessionEstablishRequest.c target_link_libraries(fgs_5gsm_lib PUBLIC nas_common_ies_lib) -target_include_directories(fgs_5gsm_lib PUBLIC . - ../../5GMM/MSG # NOTE: to be removed in a later commit - ../../5GMM/IES # NOTE: to be removed in a later commit - ../../ -) +target_include_directories(fgs_5gsm_lib PUBLIC . ../../) diff --git a/openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishmentAccept.c b/openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishmentAccept.c index 6a7c1f7211..50b66845c6 100644 --- a/openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishmentAccept.c +++ b/openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishmentAccept.c @@ -24,101 +24,83 @@ #include "PduSessionEstablishmentAccept.h" #include "common/utils/LOG/log.h" #include "common/utils/tun_if.h" -#include "NR_NAS_defs.h" +#include "fgs_nas_utils.h" -static uint16_t getShort(uint8_t *input) +/** + * @brief Returns the size of the single QoS rule IE + */ +static uint8_t get_len_qos_rule(qos_rule_t *rule) { - uint16_t tmp16; - memcpy(&tmp16, input, sizeof(tmp16)); - return htons(tmp16); + return rule->length + sizeof(rule->id) + sizeof(rule->length); } -static int capture_ipv4_addr(const uint8_t *addr, char *ip, size_t len) +/** + * @brief Decode QoS Rule (9.11.4.13 of 3GPP TS 24.501) + */ +static qos_rule_t decode_qos_rule(uint8_t *buf) { - 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]); + 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 */ -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) { - fgs_nas_message_security_header_t sec_nas_hdr; - pdu_session_establishment_accept_msg_t psea_msg; uint8_t *curPtr = buffer; - // Security protected NAS header (7 bytes) - sec_nas_hdr.protocol_discriminator = *curPtr++; - sec_nas_hdr.security_header_type = *curPtr++; - uint32_t tmp; - memcpy(&tmp, buffer, sizeof(tmp)); - sec_nas_hdr.message_authentication_code = htonl(tmp); - curPtr += sizeof(sec_nas_hdr.message_authentication_code); - sec_nas_hdr.sequence_number = *curPtr++; - // Security protected plain NAS message - fgmm_msg_header_t header; - header.ex_protocol_discriminator = *curPtr++; - header.security_header_type = *curPtr++; - header.message_type = *curPtr++; - // Payload container type and spare (1 octet) - curPtr++; - // Payload container length - curPtr += sizeof(getShort(curPtr)); - /* Mandatory Presence IEs */ - fgsm_msg_header_t *sm_header = &psea_msg.header; - sm_header->ex_protocol_discriminator = *curPtr++; - sm_header->pdu_session_id = *curPtr++; - sm_header->pti = *curPtr++; - sm_header->message_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; - } + /* 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 - qos_rule.prcd = *curPtr++; - qos_rule.qfi = *curPtr++; - psea_msg.sess_ambr.length = *curPtr++; - curPtr += psea_msg.sess_ambr.length; /* Ommit the Seassion-AMBR */ + uint8_t *resPtr = curPtr; /* Optional Presence IEs */ while (curPtr < buffer + msg_length) { @@ -130,11 +112,11 @@ void capture_pdu_session_establishment_accept_msg(uint8_t *buffer, uint32_t msg_ break; case IEI_PDU_ADDRESS: - psea_msg.pdu_addr_ie.pdu_length = *curPtr++; + psea_msg->pdu_addr_ie.pdu_length = *curPtr++; /* Octet 3 */ // PDU type (3 bits) - psea_msg.pdu_addr_ie.pdu_type = *curPtr & 0x07; + 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) @@ -143,37 +125,29 @@ void capture_pdu_session_establishment_accept_msg(uint8_t *buffer, uint32_t msg_ /* 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) { + 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"); - LOG_I(NAS, "Received PDU Session Establishment Accept, UE IP: %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) { + 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++; - 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) { + 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++; - 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"); + 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; + 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; @@ -192,48 +166,50 @@ void capture_pdu_session_establishment_accept_msg(uint8_t *buffer, uint32_t msg_ break; case IEI_MAPPED_EPS: { - uint16_t mapped_eps_length = getShort(curPtr); + 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 = getShort(curPtr); + uint16_t eap_length = 0; + GET_SHORT(curPtr, eap_length); curPtr += (eap_length + sizeof(eap_length)); break; } case IEI_AUTH_QOS_DESC: { - psea_msg.qos_fd_ie.length = getShort(curPtr); - curPtr += (psea_msg.qos_fd_ie.length + sizeof(psea_msg.qos_fd_ie.length)); + 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: { - psea_msg.ext_pp_ie.length = getShort(curPtr); - curPtr += (psea_msg.ext_pp_ie.length + sizeof(psea_msg.ext_pp_ie.length)); + 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++; + 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); + 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; + return resPtr - buffer; } diff --git a/openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishmentAccept.h b/openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishmentAccept.h index 69c9cde844..80694814b4 100644 --- a/openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishmentAccept.h +++ b/openair3/NAS/NR_UE/5GS/5GSM/MSG/PduSessionEstablishmentAccept.h @@ -23,8 +23,8 @@ #define PDU_SESSION_ESTABLISHMENT_ACCEPT_H_ #include +#include #include "fgs_nas_utils.h" -#include "NR_NAS_defs.h" // TEMP: to be removed in later commit /* PDU Session Establish Accept Optional IE Identifiers - TS 24.501 Table 8.3.2.1.1 */ @@ -79,6 +79,8 @@ typedef enum { FOREACH_IEI(TO_ENUM) } pduSessionEstablishment_IEI_t; #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 { @@ -99,17 +101,26 @@ 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 */ + // 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 { @@ -147,20 +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 */ - fgsm_msg_header_t header; - 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 */ -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/fgs_nas_utils.h b/openair3/NAS/NR_UE/5GS/fgs_nas_utils.h index 3082bc7daa..09754e9903 100644 --- a/openair3/NAS/NR_UE/5GS/fgs_nas_utils.h +++ b/openair3/NAS/NR_UE/5GS/fgs_nas_utils.h @@ -23,6 +23,8 @@ #define FGS_NAS_UTILS_H #include +#include +#include // For memcpy #define PRINT_NAS_ERROR(...) fprintf(stderr, ##__VA_ARGS__) @@ -51,4 +53,10 @@ typedef struct { #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/NR_UE/nr_nas_msg.c b/openair3/NAS/NR_UE/nr_nas_msg.c index 204c3733ec..bfb3b73ea6 100644 --- a/openair3/NAS/NR_UE/nr_nas_msg.c +++ b/openair3/NAS/NR_UE/nr_nas_msg.c @@ -62,6 +62,8 @@ #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 @@ -815,6 +817,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 */ @@ -823,7 +940,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); } @@ -1281,7 +1398,7 @@ void *nas_nrue(void *args_p) 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) @@ -1378,7 +1495,7 @@ void *nas_nrue(void *args_p) 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"); From 8b32e95d6a9c4276ff9bce5779b9fd5339666604 Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Tue, 13 Aug 2024 23:37:56 +0200 Subject: [PATCH 26/35] Define security header and security state enums and strings with available macros * also, add security type NAS_SECURITY_NEW_SECURITY_CONTEXT --- openair3/NAS/NR_UE/5GS/NR_NAS_defs.h | 17 ++++++++++------- openair3/NAS/NR_UE/nr_nas_msg.c | 20 ++++++++++++-------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/openair3/NAS/NR_UE/5GS/NR_NAS_defs.h b/openair3/NAS/NR_UE/5GS/NR_NAS_defs.h index bbff5069e2..babda98aaa 100644 --- a/openair3/NAS/NR_UE/5GS/NR_NAS_defs.h +++ b/openair3/NAS/NR_UE/5GS/NR_NAS_defs.h @@ -100,13 +100,16 @@ typedef enum { } fgs_nas_msg_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; +#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) \ diff --git a/openair3/NAS/NR_UE/nr_nas_msg.c b/openair3/NAS/NR_UE/nr_nas_msg.c index bfb3b73ea6..bb2572eee6 100644 --- a/openair3/NAS/NR_UE/nr_nas_msg.c +++ b/openair3/NAS/NR_UE/nr_nas_msg.c @@ -71,13 +71,17 @@ extern uint16_t NB_UE_INST; 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) + +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) { @@ -1389,7 +1393,7 @@ 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; } From 611c055464eba6b22128dc626b4c09fd385e5988 Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Wed, 14 Aug 2024 11:18:29 +0200 Subject: [PATCH 27/35] Refactor nas_security_rx_process * use defines whenever possible * introduce a switch to handle security type. Currently only integrity protected and ciphered is handled, however the idea of the switch is to make the code ready for the future when different security types will be handled and different actions should be taken based on that. * define NAS_INTEGRITY_SIZE --- openair3/NAS/NR_UE/nr_nas_msg.c | 40 +++++++++++++++++++++------------ openair3/NAS/NR_UE/nr_nas_msg.h | 1 + 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/openair3/NAS/NR_UE/nr_nas_msg.c b/openair3/NAS/NR_UE/nr_nas_msg.c index bb2572eee6..667fb2e19b 100644 --- a/openair3/NAS/NR_UE/nr_nas_msg.c +++ b/openair3/NAS/NR_UE/nr_nas_msg.c @@ -111,18 +111,29 @@ static security_state_t nas_security_rx_process(nr_ue_nas_t *nas, uint8_t *pdu_b { 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) { @@ -139,33 +150,34 @@ static security_state_t nas_security_rx_process(nr_ue_nas_t *nas, uint8_t *pdu_b } /* 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++; diff --git a/openair3/NAS/NR_UE/nr_nas_msg.h b/openair3/NAS/NR_UE/nr_nas_msg.h index d024a92c9c..7863b6f7df 100644 --- a/openair3/NAS/NR_UE/nr_nas_msg.h +++ b/openair3/NAS/NR_UE/nr_nas_msg.h @@ -46,6 +46,7 @@ #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 From c37c5ad7ae5d8be74c79bd79199450555327547a Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Mon, 18 Nov 2024 16:05:49 +0100 Subject: [PATCH 28/35] Use macro NAS_INTEGRITY_SIZE in NAS --- openair3/NAS/NR_UE/nr_nas_msg.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/openair3/NAS/NR_UE/nr_nas_msg.c b/openair3/NAS/NR_UE/nr_nas_msg.c index 667fb2e19b..129e06e70f 100644 --- a/openair3/NAS/NR_UE/nr_nas_msg.c +++ b/openair3/NAS/NR_UE/nr_nas_msg.c @@ -641,7 +641,7 @@ static void generateSecurityModeComplete(nr_ue_nas_t *nas, as_nas_info_t *initia 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 fgs_nas_message_security_header_t *sp = &nas_msg.header; sp->protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; @@ -767,7 +767,7 @@ static void generateRegistrationComplete(nr_ue_nas_t *nas, { int length = 0; nas_stream_cipher_t stream_cipher; - uint8_t mac[4]; + uint8_t mac[NAS_INTEGRITY_SIZE]; fgmm_nas_msg_security_protected_t sp = {0}; // set security protected header @@ -1016,7 +1016,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]); @@ -1042,7 +1042,7 @@ static void generatePduSessionEstablishRequest(nr_ue_nas_t *nas, as_nas_info_t * encode_pdu_session_establishment_request(&pdu_session_establish, req_buffer); nas_stream_cipher_t stream_cipher; - uint8_t mac[4]; + uint8_t mac[NAS_INTEGRITY_SIZE]; // 5GMM security protected message fgmm_nas_msg_security_protected_t sp_msg = {0}; From 3e27e53f5267b68f12318d3bbdc2df2136a5550b Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Thu, 28 Nov 2024 11:31:35 +0100 Subject: [PATCH 29/35] Handle size in nas_protected_security_header_encode --- openair3/NAS/NR_UE/5GS/fgs_nas_lib.c | 9 ++++++--- openair3/NAS/NR_UE/nr_nas_msg.c | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/openair3/NAS/NR_UE/5GS/fgs_nas_lib.c b/openair3/NAS/NR_UE/5GS/fgs_nas_lib.c index 723306b6bc..f27380739c 100644 --- a/openair3/NAS/NR_UE/5GS/fgs_nas_lib.c +++ b/openair3/NAS/NR_UE/5GS/fgs_nas_lib.c @@ -115,10 +115,13 @@ int mm_msg_encode(const fgmm_nas_message_plain_t *p, uint8_t *buffer, uint32_t l int nas_protected_security_header_encode(uint8_t *buffer, const fgs_nas_message_security_header_t *header, int length) { - LOG_FUNC_IN; - 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); @@ -130,7 +133,7 @@ int nas_protected_security_header_encode(uint8_t *buffer, const fgs_nas_message_ /* Encode the sequence number */ ENCODE_U8(buffer + size, header->sequence_number, size); - LOG_FUNC_RETURN(size); + return size; } /** diff --git a/openair3/NAS/NR_UE/nr_nas_msg.c b/openair3/NAS/NR_UE/nr_nas_msg.c index 129e06e70f..658ac1fab3 100644 --- a/openair3/NAS/NR_UE/nr_nas_msg.c +++ b/openair3/NAS/NR_UE/nr_nas_msg.c @@ -667,7 +667,7 @@ static void generateSecurityModeComplete(nr_ue_nas_t *nas, as_nas_info_t *initia // encode the message initialNasMsg->nas_data = malloc_or_fail(size * sizeof(*initialNasMsg->nas_data)); - int security_header_len = nas_protected_security_header_encode(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 From 97521d21e54b21388002106610c153d5b1725e37 Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Mon, 18 Nov 2024 15:33:59 +0100 Subject: [PATCH 30/35] Refactor mm_msg_encode --- openair3/NAS/NR_UE/5GS/fgs_nas_lib.c | 50 +++++++++++----------------- 1 file changed, 19 insertions(+), 31 deletions(-) diff --git a/openair3/NAS/NR_UE/5GS/fgs_nas_lib.c b/openair3/NAS/NR_UE/5GS/fgs_nas_lib.c index f27380739c..16d84f3ad8 100644 --- a/openair3/NAS/NR_UE/5GS/fgs_nas_lib.c +++ b/openair3/NAS/NR_UE/5GS/fgs_nas_lib.c @@ -50,67 +50,55 @@ int _nas_mm_msg_encode_header(const fgmm_msg_header_t *header, uint8_t *buffer, int mm_msg_encode(const fgmm_nas_message_plain_t *p, uint8_t *buffer, uint32_t len) { - LOG_FUNC_IN; - int header_result; - int encode_result; uint8_t msg_type = p->header.message_type; - + int enc_msg = 0; /* First encode the 5GMM message header */ - header_result = _nas_mm_msg_encode_header(&p->header, buffer, len); + int enc_header = _nas_mm_msg_encode_header(&p->header, buffer, len); - if (header_result < 0) { - LOG_TRACE(ERROR, - "Failed to encode 5GMM message header" - "(%d)", - header_result); - LOG_FUNC_RETURN(header_result); + if (enc_header < 0) { + PRINT_NAS_ERROR("Failed to encode 5GMM message header\n"); + return enc_header; } - buffer += header_result; - len -= header_result; + buffer += enc_header; + len -= enc_header; switch (msg_type) { case FGS_REGISTRATION_REQUEST: - encode_result = encode_registration_request(&p->mm_msg.registration_request, buffer, len); + enc_msg = encode_registration_request(&p->mm_msg.registration_request, buffer, len); break; case FGS_IDENTITY_RESPONSE: - encode_result = encode_fgmm_identity_response(buffer, &p->mm_msg.fgs_identity_response, len); + enc_msg = encode_fgmm_identity_response(buffer, &p->mm_msg.fgs_identity_response, len); break; case FGS_AUTHENTICATION_RESPONSE: - encode_result = encode_fgs_authentication_response(&p->mm_msg.fgs_auth_response, buffer, len); + enc_msg = encode_fgs_authentication_response(&p->mm_msg.fgs_auth_response, buffer, len); break; case FGS_SECURITY_MODE_COMPLETE: - encode_result = encode_fgs_security_mode_complete(&p->mm_msg.fgs_security_mode_complete, buffer, len); + enc_msg = encode_fgs_security_mode_complete(&p->mm_msg.fgs_security_mode_complete, buffer, len); break; case FGS_UPLINK_NAS_TRANSPORT: - encode_result = encode_fgs_uplink_nas_transport(&p->mm_msg.uplink_nas_transport, buffer, len); + enc_msg = encode_fgs_uplink_nas_transport(&p->mm_msg.uplink_nas_transport, buffer, len); break; case FGS_DEREGISTRATION_REQUEST_UE_ORIGINATING: - encode_result = + enc_msg = encode_fgs_deregistration_request_ue_originating(&p->mm_msg.fgs_deregistration_request_ue_originating, buffer, len); break; case FGS_SERVICE_REQUEST: - encode_result = encode_fgs_service_request(buffer, &p->mm_msg.service_request, len); + 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); - encode_result = TLV_ENCODE_WRONG_MESSAGE_TYPE; + enc_msg = TLV_ENCODE_WRONG_MESSAGE_TYPE; break; /* TODO: Handle not standard layer 3 messages: SERVICE_REQUEST */ } - if (encode_result < 0) { - LOG_TRACE(ERROR, - " Failed to encode L3 EMM message 0x%x " - "(%d)", - p->header.message_type, - encode_result); + if (enc_msg < 0) { + PRINT_NAS_ERROR("Failed to encode 5GMM message\n"); + return enc_msg; } - if (encode_result < 0) - LOG_FUNC_RETURN(encode_result); - - LOG_FUNC_RETURN(header_result + encode_result); + return enc_header + enc_msg; } int nas_protected_security_header_encode(uint8_t *buffer, const fgs_nas_message_security_header_t *header, int length) From 918fcd2b6dc37f316857e522d6266df758a82181 Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Wed, 26 Jun 2024 18:52:26 +0200 Subject: [PATCH 31/35] Bugfix: 6 bits AMF set ID in decode_guti_5gs_mobile_identity * the last 6 bits of the GUTI represent the AMF Pointer * the AMF Set ID is 10 bits long * the Registration Accept message received from the network contains the GUTI which, when properly decoded, will be used in any possible following Registration Request --- openair3/NAS/NR_UE/5GS/5GMM/IES/FGSMobileIdentity.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSMobileIdentity.c b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSMobileIdentity.c index 7e1489ac81..ddd6ba6bc9 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSMobileIdentity.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSMobileIdentity.c @@ -215,7 +215,7 @@ static int decode_guti_5gs_mobile_identity(Guti5GSMobileIdentity_t *guti, const guti->amfregionid = *(buffer + decoded); decoded++; IES_DECODE_U16(buffer, decoded, temp); - guti->amfsetid = temp >> 3; + guti->amfsetid = (temp >> 6) & 0x3FF; guti->amfpointer = temp & 0x3f; IES_DECODE_U32(buffer, decoded, guti->tmsi); From 8260b2283c1e592adf729e83dc6cadc202b4c299 Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Tue, 24 Sep 2024 14:12:17 +0200 Subject: [PATCH 32/35] Do get_msg_type only once in nas_nrue --- openair3/NAS/NR_UE/nr_nas_msg.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/openair3/NAS/NR_UE/nr_nas_msg.c b/openair3/NAS/NR_UE/nr_nas_msg.c index 658ac1fab3..3a5dee3e72 100644 --- a/openair3/NAS/NR_UE/nr_nas_msg.c +++ b/openair3/NAS/NR_UE/nr_nas_msg.c @@ -1474,11 +1474,11 @@ 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_UE_ORIGINATING is accepted */ if (msg_type == FGS_DEREGISTRATION_ACCEPT_UE_ORIGINATING) security_state = NAS_SECURITY_INTEGRITY_PASSED; @@ -1489,8 +1489,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); From e842ca263106bd65a47d9c6b205ae7a47aee023c Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Wed, 23 Oct 2024 18:59:56 +0200 Subject: [PATCH 33/35] Move assert up in decode_5gs_mobile_identity --- openair3/NAS/NR_UE/5GS/5GMM/IES/FGSMobileIdentity.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSMobileIdentity.c b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSMobileIdentity.c index ddd6ba6bc9..883c5ba98d 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSMobileIdentity.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/IES/FGSMobileIdentity.c @@ -113,11 +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) { + 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); - } else { - AssertFatal(false, "Mobile Identity encoding of type %d not implemented\n", typeofidentity); - } if (decoded_rc < 0) { return decoded_rc; From d6e2bf165193808f90f703c21b49fbc420434e74 Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Mon, 18 Nov 2024 18:26:02 +0100 Subject: [PATCH 34/35] Refactor registration accept decoding previously we had decodeRegistrationAccept acting as a handler and calling decode_registration_accept to do the decoding. However the logic was mixed between the two functions, the naming was confusing and the code was hard understand. The goal of this commit is to simplify the code, improve readability and maintainability, while adapting the relevant function to the new OAI NAS libs structure. To this purpose: * move enc/dec logic to NAS lib openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationAccept.c - the logic of parse_allowed_nssai, get_allowed_nssai has been moved to decode_registration_accept and decode_nssai_ie * add decode_nssai_ie and use it for both Allowed/Configured NSSAIs list (IE handling was added) * do processing in the handler handle_registration_accept * simplify the code by removing nested calls * improve handling of PDU length Currently only Registration Result, 5GS Mobile Identity, Allowed/Configured NSSAI are decoded. The other optional IEIs are skipped (only the length is processed). --- .../NR_UE/5GS/5GMM/MSG/RegistrationAccept.c | 115 ++++++++++-- .../NR_UE/5GS/5GMM/MSG/RegistrationAccept.h | 12 ++ openair3/NAS/NR_UE/nr_nas_msg.c | 177 +++++------------- openair3/NAS/NR_UE/nr_nas_msg.h | 8 - 4 files changed, 157 insertions(+), 155 deletions(-) diff --git a/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationAccept.c b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationAccept.c index bca9dff06a..d92244a15f 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationAccept.c +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationAccept.c @@ -32,37 +32,116 @@ #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) { - uint32_t decoded = 0; - int decoded_result = 0; + int dec = 0; + const uint8_t *end = buffer + len; /* Decoding mandatory fields */ - if ((decoded_result = - decode_fgs_registration_result(®istration_accept->fgsregistrationresult, 0, *(buffer + decoded), len - decoded)) - < 0) - return decoded_result; + if ((dec = decode_fgs_registration_result(®istration_accept->fgsregistrationresult, 0, *buffer, len)) < 0) + return dec; + buffer += dec; - decoded += decoded_result; - - if (decoded < len && buffer[decoded] == 0x77) { - registration_accept->guti = calloc(1, sizeof(*registration_accept->guti)); - if (!registration_accept->guti) + 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; - int mi_dec = decode_5gs_mobile_identity(registration_accept->guti, 0x77, buffer + decoded, len - decoded); - if (mi_dec < 0) - return -1; - decoded += mi_dec; + } + buffer += dec; } - // todo ,Decoding optional fields - return decoded; + // 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) diff --git a/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationAccept.h b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationAccept.h index 91b024a7d8..6abf1e70ca 100644 --- a/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationAccept.h +++ b/openair3/NAS/NR_UE/5GS/5GMM/MSG/RegistrationAccept.h @@ -40,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,6 +60,10 @@ typedef struct registration_accept_msg_tag { 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); diff --git a/openair3/NAS/NR_UE/nr_nas_msg.c b/openair3/NAS/NR_UE/nr_nas_msg.c index 3a5dee3e72..3901da3441 100644 --- a/openair3/NAS/NR_UE/nr_nas_msg.c +++ b/openair3/NAS/NR_UE/nr_nas_msg.c @@ -69,7 +69,6 @@ extern uint16_t NB_UE_INST; static nr_ue_nas_t nr_ue_nas[MAX_NAS_UE] = {0}; -static nr_nas_msg_snssai_t nas_allowed_nssai[8]; #define FOREACH_STATE(TYPE_DEF) \ TYPE_DEF(NAS_SECURITY_NO_SECURITY_CONTEXT, 0) \ @@ -737,30 +736,6 @@ 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) @@ -1185,109 +1160,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 (((fgs_nas_message_security_header_t *)(pdu_buffer))->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); } @@ -1308,11 +1187,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); @@ -1320,11 +1240,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); } } diff --git a/openair3/NAS/NR_UE/nr_nas_msg.h b/openair3/NAS/NR_UE/nr_nas_msg.h index 7863b6f7df..b4a97a36d7 100644 --- a/openair3/NAS/NR_UE/nr_nas_msg.h +++ b/openair3/NAS/NR_UE/nr_nas_msg.h @@ -51,14 +51,6 @@ /* 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]; From 529b142d758c49ce1aa2570609c797dced2343ae Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Thu, 5 Dec 2024 14:18:29 +0100 Subject: [PATCH 35/35] Refactor servingNetworkName --- openair3/NAS/NR_UE/nr_nas_msg.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/openair3/NAS/NR_UE/nr_nas_msg.c b/openair3/NAS/NR_UE/nr_nas_msg.c index 3901da3441..2100089d35 100644 --- a/openair3/NAS/NR_UE/nr_nas_msg.c +++ b/openair3/NAS/NR_UE/nr_nas_msg.c @@ -91,19 +91,26 @@ static fgmm_msg_header_t set_mm_header(fgs_nas_msg_t type, Security_header_t sec return mm_header; } -static void servingNetworkName(uint8_t *msg, char *imsiStr, int nmc_size) +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. - 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); + // 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]); + } - memcpy(msg + 13, imsiStr, 3); + // 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)