Commit e0865421 authored by Robert Schmidt's avatar Robert Schmidt

Merge remote-tracking branch 'origin/nr-ue-nas-improvements' into integration_2025_w05 (!2984)

NAS 5GS refactor

The goal of this MR is to reorganize the NR NAS code into:

- enc/dec library functions (5GS, 5GMM, 5GSM, NR_NAS_defs.h,
  nr_fgs_nas_lib.c)
- handlers and callbacks (nr_nas_msg.c)

The following changes are introduced:

1. migrate 5GS enc/dec lib (5GMM and 5GSM) to a dedicated folder
2. add a nested CMakeLists structure
3. refactor NR NAS enc/dec functions
4. refactor NR NAS messages struct definitions
5. remove most of dependency from NAS LTE
6. further refactor of PDU Session Establishment Accept processing to
   separate enc/dec from handling
7. made naming of 5GS definitions consistent whenever necessary
8. cleanup unused code
9. remove redundant struct definitions

Also:

1. fix decoding of AMF Set ID in 5G-S-TMSI UE identity
2. replace Byte_t directly with uint8_t
parents 70e70f6f 529b142d
......@@ -780,9 +780,6 @@ add_library(dfts MODULE ${OPENAIR1_DIR}/PHY/TOOLS/oai_dfts.c ${OPENAIR1_DIR}/PHY
set(PHY_SRC_COMMON
${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/dci_tools_common.c
${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/lte_mcs.c
# ${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/slss.c
# ${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/sldch.c
# ${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/slsch.c
${OPENAIR1_DIR}/PHY/LTE_UE_TRANSPORT/get_pmi.c
${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/group_hopping.c
${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/phich_common.c
......@@ -841,13 +838,9 @@ set(PHY_SRC
${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/pcfich.c
${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/pucch.c
${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/pmch.c
# ${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/ulsch_demodulation.c
${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/ulsch_decoding.c
${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/rar_tools.c
${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/uci_tools.c
# ${OPENAIR1_DIR}/PHY/LTE_ESTIMATION/freq_equalization.c
# ${OPENAIR1_DIR}/PHY/LTE_ESTIMATION/lte_adjust_sync_eNB.c
# ${OPENAIR1_DIR}/PHY/LTE_ESTIMATION/lte_ul_channel_estimation.c
${OPENAIR1_DIR}/PHY/LTE_ESTIMATION/lte_eNB_measurements.c
${OPENAIR1_DIR}/PHY/INIT/lte_init.c
)
......@@ -1114,7 +1107,6 @@ set(L2_SRC
${PDCP_DIR}/pdcp_util.c
${PDCP_DIR}/pdcp_security.c
${OPENAIR2_DIR}/LAYER2/openair2_proc.c
# ${RRC_DIR}/rrc_UE.c
${RRC_DIR}/rrc_eNB.c
${RRC_DIR}/rrc_eNB_endc.c
${RRC_DIR}/rrc_eNB_S1AP.c
......@@ -1129,7 +1121,6 @@ set(L2_SRC
set(L2_RRC_SRC
${OPENAIR2_DIR}/LAYER2/openair2_proc.c
# ${RRC_DIR}/rrc_UE.c
${RRC_DIR}/rrc_eNB.c
${RRC_DIR}/rrc_eNB_endc.c
${RRC_DIR}/rrc_eNB_S1AP.c
......@@ -1368,6 +1359,7 @@ target_link_libraries(L2_UE PRIVATE asn1_lte_rrc_hdrs)
add_library( NR_L2_UE ${NR_L2_SRC_UE} ${MAC_NR_SRC_UE} )
target_link_libraries(NR_L2_UE PRIVATE f1ap nr_rlc)
target_link_libraries(NR_L2_UE PRIVATE asn1_nr_rrc_hdrs asn1_lte_rrc_hdrs nr_common nr_ue_power_procedures nr_ue_ra_procedures)
target_link_libraries(NR_L2_UE PRIVATE nr_nas)
add_library(MAC_NR_COMMON
${OPENAIR2_DIR}/LAYER2/NR_MAC_COMMON/nr_mac_common.c
......@@ -1412,6 +1404,7 @@ add_library(SCTP_CLIENT ${SCTP_SRC})
target_link_libraries(SCTP_CLIENT PRIVATE asn1_nr_rrc_hdrs asn1_lte_rrc_hdrs)
set(NAS_SRC ${OPENAIR3_DIR}/NAS/)
set(libnas_api_OBJS
${NAS_SRC}COMMON/API/NETWORK/as_message.c
${NAS_SRC}COMMON/API/NETWORK/nas_message.c
......@@ -1451,10 +1444,6 @@ set(libnas_emm_msg_OBJS
${NAS_SRC}COMMON/EMM/MSG/UplinkNasTransport.c
)
set(libnas_fgs_msg_OBJS
${NAS_SRC}COMMON/EMM/MSG/fgs_service_request.c
)
set(libnas_esm_msg_OBJS
${NAS_SRC}COMMON/ESM/MSG/ActivateDedicatedEpsBearerContextAccept.c
${NAS_SRC}COMMON/ESM/MSG/ActivateDedicatedEpsBearerContextReject.c
......@@ -1643,61 +1632,6 @@ set(libnas_ue_esm_sap_OBJS
${NAS_SRC}UE/ESM/SAP/esm_sap.c
)
set(libnrnas_emm_msg_OBJS
${NAS_SRC}COMMON/EMM/MSG/RegistrationRequest.c
${NAS_SRC}COMMON/EMM/MSG/RegistrationAccept.c
${NAS_SRC}COMMON/EMM/MSG/FGSIdentityResponse.c
${NAS_SRC}COMMON/EMM/MSG/FGSAuthenticationResponse.c
${NAS_SRC}COMMON/EMM/MSG/FGSNASSecurityModeComplete.c
${NAS_SRC}COMMON/EMM/MSG/RegistrationComplete.c
${NAS_SRC}COMMON/EMM/MSG/FGSUplinkNasTransport.c
${NAS_SRC}COMMON/ESM/MSG/PduSessionEstablishRequest.c
${NAS_SRC}COMMON/ESM/MSG/PduSessionEstablishmentAccept.c
${NAS_SRC}COMMON/EMM/MSG/FGSDeregistrationRequestUEOriginating.c
)
set(libnrnas_ies_OBJS
${NAS_SRC}COMMON/IES/ExtendedProtocolDiscriminator.c
${NAS_SRC}COMMON/IES/FGSMobileIdentity.c
${NAS_SRC}COMMON/IES/FGSRegistrationType.c
${NAS_SRC}COMMON/IES/SpareHalfOctet.c
${NAS_SRC}COMMON/IES/FGSRegistrationResult.c
${NAS_SRC}COMMON/IES/FGMMCapability.c
${NAS_SRC}COMMON/IES/NrUESecurityCapability.c
${NAS_SRC}COMMON/IES/FGCNasMessageContainer.c
${NAS_SRC}COMMON/IES/SORTransparentContainer.c
)
add_library(LIB_NAS_SIMUE
${NAS_SRC}UE/nas_itti_messaging.c
${NAS_SRC}UE/nas_network.c
${NAS_SRC}UE/nas_parser.c
${NAS_SRC}UE/nas_proc.c
${NAS_SRC}UE/nas_user.c
${NAS_SRC}NR_UE/nr_nas_msg.c
${libnas_api_OBJS}
${libnas_ue_api_OBJS}
${libnas_emm_msg_OBJS}
${libnas_fgs_msg_OBJS}
${libnas_esm_msg_OBJS}
${libnas_ies_OBJS}
${libnas_utils_OBJS}
${libnas_ue_emm_OBJS}
${libnas_ue_emm_sap_OBJS}
${libnas_ue_esm_OBJS}
${libnas_ue_esm_sap_OBJS}
${libnrnas_emm_msg_OBJS}
${libnrnas_ies_OBJS}
$<TARGET_OBJECTS:ds>
)
target_include_directories(LIB_NAS_SIMUE PRIVATE ${OPENAIR_DIR}/common/utils/ds/)
target_link_libraries(LIB_NAS_SIMUE PRIVATE lte_rrc)
set(NAS_SIM_LIB LIB_NAS_SIMUE)
target_link_libraries(LIB_NAS_SIMUE PRIVATE asn1_nr_rrc_hdrs asn1_lte_rrc_hdrs)
add_library(LIB_NAS_UE
${NAS_SRC}UE/nas_itti_messaging.c
${NAS_SRC}UE/nas_network.c
......@@ -1737,15 +1671,6 @@ set (NBIOT_SOURCES
)
add_library(NB_IoT MODULE ${NBIOT_SOURCES} )
add_library(LIB_5GNAS_GNB
${NAS_SRC}/COMMON/nr_common.c
${OPENAIR3_DIR}//UICC/usim_interface.c
)
target_include_directories(LIB_5GNAS_GNB PRIVATE ${OPENAIR_DIR}/common/utils/ds/)
target_link_libraries(LIB_5GNAS_GNB PRIVATE SECURITY)
target_link_libraries(LIB_5GNAS_GNB PRIVATE asn1_nr_rrc_hdrs asn1_lte_rrc_hdrs)
# Simulation library
##########################
set (SIMUSRC
......@@ -1963,7 +1888,6 @@ add_executable(nr-uesoftmodem
${OPENAIR_DIR}/radio/COMMON/common_lib.c
${OPENAIR_DIR}/radio/COMMON/record_player.c
${OPENAIR2_DIR}/LAYER2/NR_MAC_COMMON/nr_mac_common.c
${OPENAIR3_DIR}/NAS/UE/nas_ue_task.c
${OPENAIR1_DIR}/PHY/TOOLS/phy_scope_interface.c
)
......@@ -1972,11 +1896,12 @@ target_link_libraries(nr-uesoftmodem PRIVATE
nr_rrc SECURITY UTIL HASHTABLE SCHED_RU_LIB SCHED_NR_UE_LIB
PHY_COMMON PHY_NR_COMMON PHY_NR_UE NR_L2_UE L2_UE_LTE_NR MAC_NR_COMMON NFAPI_LIB NFAPI_PNF_LIB
NFAPI_USER_LIB MISC_NFAPI_NR_LIB
ITTI LIB_5GNAS_GNB LIB_NAS_SIMUE ${NAS_SIM_LIB} SIMU shlib_loader
ITTI SIMU shlib_loader
-Wl,--end-group z dl)
target_link_libraries(nr-uesoftmodem PRIVATE pthread m CONFIG_LIB rt nr_ue_phy_meas)
target_link_libraries(nr-uesoftmodem PRIVATE ${T_LIB})
target_link_libraries(nr-uesoftmodem PRIVATE nr_nas lib_uicc usim_lib)
target_link_libraries(nr-uesoftmodem PRIVATE asn1_nr_rrc_hdrs asn1_lte_rrc_hdrs)
# force the generation of ASN.1 so that we don't need to wait during the build
......@@ -2169,10 +2094,6 @@ foreach(myExe s1ap
)
endforeach(myExe)
# to be added
#../targets/TEST/PDCP/test_pdcp.c
#../targets/TEST/PDCP/with_rlc/test_pdcp_rlc.c
#ensure that the T header files are generated before targets depending on them
if (${T_TRACER})
foreach(i
......
This diff is collapsed.
......@@ -43,7 +43,6 @@
{"uecap_file", CONFIG_HLP_UECAP_FILE, 0, .strptr=&nrUE_params.uecap_file, .defstrval="./uecap_ports1.xml", TYPE_STRING, 0}, \
{"reconfig-file", CONFIG_HLP_RE_CFG_FILE, 0, .strptr=&nrUE_params.reconfig_file, .defstrval="./reconfig.raw", TYPE_STRING, 0}, \
{"rbconfig-file", CONFIG_HLP_RB_CFG_FILE, 0, .strptr=&nrUE_params.rbconfig_file, .defstrval="./rbconfig.raw", TYPE_STRING, 0}, \
{"ue-idx-standalone", NULL, 0, .u16ptr=&ue_idx_standalone, .defuintval=0xFFFF, TYPE_UINT16, 0}, \
{"ue-rxgain", CONFIG_HLP_UERXG, 0, .dblptr=&nrUE_params.rx_gain, .defdblval=110, TYPE_DOUBLE, 0}, \
{"ue-rxgain-off", CONFIG_HLP_UERXGOFF, 0, .dblptr=&nrUE_params.rx_gain_off, .defdblval=0, TYPE_DOUBLE, 0}, \
{"ue-txgain", CONFIG_HLP_UETXG, 0, .dblptr=&nrUE_params.tx_gain, .defdblval=0, TYPE_DOUBLE, 0}, \
......
......@@ -166,7 +166,7 @@ typedef struct as_stmsi_s {
/* Dedicated NAS information */
typedef struct as_nas_info_s {
uint32_t length; /* Length of the NAS information data */
Byte_t* nas_data; /* Dedicated NAS information data container */
uint8_t* nas_data; /* Dedicated NAS information data container */
} as_nas_info_t;
/* Radio Access Bearer identity */
......@@ -215,7 +215,7 @@ typedef struct broadcast_info_ind_s {
* NAS request AS to refresh its KeNB key
*/
typedef struct kenb_refresh_req_s {
Byte_t kenb[32];
uint8_t kenb[32];
} kenb_refresh_req_t;
typedef struct nsa_oai_tun_nsa_s {
......@@ -229,7 +229,7 @@ typedef struct nsa_oai_tun_nsa_s {
*/
typedef struct cell_info_req_s {
plmn_t plmnID; /* Selected PLMN identity */
Byte_t rat; /* Bitmap - set of radio access technologies */
uint8_t rat; /* Bitmap - set of radio access technologies */
} cell_info_req_t;
/*
......
......@@ -43,7 +43,6 @@ Description Contains global common definitions
#include <stddef.h>
#include <stdbool.h>
#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 */
......
......@@ -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;
......
......@@ -801,7 +801,7 @@ typedef struct UE_RRC_INST_s {
Rrc_State_t RrcState;
Rrc_Sub_State_t RrcSubState;
plmn_t plmnID;
Byte_t rat;
uint8_t rat;
uint8_t selected_plmn_identity;
as_nas_info_t initialNasMsg;
OAI_UECapability_t *UECap;
......
......@@ -202,8 +202,6 @@ typedef struct gNB_RRC_UE_s {
NR_CellGroupConfig_t *masterCellGroup;
NR_RadioBearerConfig_t *rb_config;
ImsiMobileIdentity_t imsi;
/* KgNB as derived from KASME received from EPC */
uint8_t kgnb[32];
int8_t kgnb_ncc;
......
add_subdirectory(LPP)
add_subdirectory(M3AP)
add_subdirectory(S1AP)
add_subdirectory(NAS)
add_subdirectory(NGAP)
add_subdirectory(NRPPA)
add_subdirectory(NAS)
add_subdirectory(UICC)
add_subdirectory(COMMON)
add_subdirectory(NR_UE)
add_subdirectory(UE)
......@@ -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;
......
add_subdirectory(IES)
add_subdirectory(EMM)
add_subdirectory(UTIL)
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}
)
......@@ -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;
......
......@@ -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);
......
add_library(fgs_ies_lib OBJECT
NasKeySetIdentifier.c
FGSMobileIdentity.c
add_library(nas_common_ies_lib OBJECT
AuthenticationResponseParameter.c
NasKeySetIdentifier.c
)
target_include_directories(fgs_ies_lib PUBLIC
${CMAKE_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
)
target_include_directories(nas_common_ies_lib PUBLIC .)
/*
* 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 <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#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;
}
/*
* 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 <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#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_ */
......@@ -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);
......
......@@ -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);
......
/*
* 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 <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#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;
}
/*
* 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 <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#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_ */
add_library(nas_utils OBJECT
TLVDecoder.c
OctetString.c
)
target_include_directories(nas_utils PRIVATE .)
......@@ -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;
......
......@@ -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);
......
......@@ -23,6 +23,7 @@
#define TLV_ENCODER_H_
#include <arpa/inet.h> // htonl, htons
#include <string.h> // memcpy
#define ENCODE_U8(buffer, value, size) \
do { \
......
/*
* 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 <arpa/inet.h>
#include <openair3/NAS/COMMON/NR_NAS_defs.h>
#include <openair3/SECU/secu_defs.h>
#include <openair3/SECU/kdf.h>
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;
}
add_library(fgs_5gmm_ies_lib OBJECT
FGSMobileIdentity.c
FGSRegistrationType.c
FGSRegistrationResult.c
FGMMCapability.c
NrUESecurityCapability.c
FGCNasMessageContainer.c
SORTransparentContainer.c
)
target_link_libraries(fgs_5gmm_ies_lib PUBLIC
nas_common_ies_lib
)
......@@ -32,7 +32,6 @@
#include <stdlib.h>
#include <stdint.h>
#include "TLVEncoder.h"
#include "TLVDecoder.h"
#include "FGCNasMessageContainer.h"
......@@ -52,14 +51,16 @@ int decode_fgc_nas_message_container(FGCNasMessageContainer *nasmessagecontainer
decoded += 2;
CHECK_LENGTH_DECODER(len - decoded, ielen);
if ((decode_result = decode_octet_string(&nasmessagecontainer->nasmessagecontainercontents, ielen, buffer + decoded, len - decoded)) < 0)
if ((decode_result =
decode_octet_string(&nasmessagecontainer->nasmessagecontainercontents, ielen, buffer + decoded, len - decoded))
< 0)
return decode_result;
else
decoded += decode_result;
return decoded;
}
int encode_fgc_nas_message_container(FGCNasMessageContainer *nasmessagecontainer, uint8_t iei, uint8_t *buffer, uint32_t len)
int encode_fgc_nas_message_container(const FGCNasMessageContainer *nasmessagecontainer, uint8_t iei, uint8_t *buffer, uint32_t len)
{
uint32_t encoded = 0;
int encode_result;
......@@ -73,7 +74,8 @@ int encode_fgc_nas_message_container(FGCNasMessageContainer *nasmessagecontainer
encoded += 2;
if ((encode_result = encode_octet_string(&nasmessagecontainer->nasmessagecontainercontents, buffer + encoded, len - encoded)) < 0) {
if ((encode_result = encode_octet_string(&nasmessagecontainer->nasmessagecontainercontents, buffer + encoded, len - encoded))
< 0) {
return encode_result;
} else {
uint16_t tmp = htons(encoded + encode_result - 3);
......@@ -95,5 +97,3 @@ void dump_fgc_nas_message_container_xml(FGCNasMessageContainer *nasmessagecontai
printf("%s", dump_octet_string_xml(&nasmessagecontainer->nasmessagecontainercontents));
printf("</Nas Message Container>\n");
}
......@@ -44,11 +44,10 @@ typedef struct FGCNasMessageContainer_tag {
OctetString nasmessagecontainercontents;
} FGCNasMessageContainer;
int encode_fgc_nas_message_container(FGCNasMessageContainer *nasmessagecontainer, uint8_t iei, uint8_t *buffer, uint32_t len);
int encode_fgc_nas_message_container(const FGCNasMessageContainer *nasmessagecontainer, uint8_t iei, uint8_t *buffer, uint32_t len);
int decode_fgc_nas_message_container(FGCNasMessageContainer *nasmessagecontainer, uint8_t iei, uint8_t *buffer, uint32_t len);
void dump_fgc_nas_message_container_xml(FGCNasMessageContainer *nasmessagecontainer, uint8_t iei);
#endif /* FGC NAS MESSAGE CONTAINER_H_ */
......@@ -31,24 +31,20 @@
#include <stdlib.h>
#include <stdint.h>
#include "TLVEncoder.h"
#include "TLVDecoder.h"
#include "FGMMCapability.h"
int encode_5gmm_capability(FGMMCapability *fgmmcapability, uint8_t iei, uint8_t *buffer, uint32_t len)
int encode_5gmm_capability(const FGMMCapability *fgmmcapability, uint8_t iei, uint8_t *buffer, uint32_t len)
{
int encoded = 0;
if(iei){
if (iei) {
*buffer = fgmmcapability->iei;
encoded++;
*(buffer+encoded) = fgmmcapability->length;
encoded++;
*(buffer+encoded) = fgmmcapability->value;
encoded++;
encoded++;
*(buffer + encoded) = fgmmcapability->length;
encoded++;
*(buffer + encoded) = fgmmcapability->value;
encoded++;
}
return encoded;
}
......@@ -27,7 +27,6 @@
* \version 0.1
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
......@@ -37,15 +36,12 @@
#ifndef FGMM_CAPABILITY_H_
#define FGMM_CAPABILITY_H_
typedef struct {
uint8_t iei;
uint8_t length;
uint8_t value;
} FGMMCapability;
int encode_5gmm_capability(FGMMCapability *fgmmcapability, uint8_t iei, uint8_t *buffer, uint32_t len);
int encode_5gmm_capability(const FGMMCapability *fgmmcapability, uint8_t iei, uint8_t *buffer, uint32_t len);
#endif /* FGMM_CAPABILITY_H_ */
......@@ -27,7 +27,6 @@
* \version 0.1
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
......@@ -42,11 +41,11 @@
static int decode_guti_5gs_mobile_identity(Guti5GSMobileIdentity_t *guti, const uint8_t *buffer);
static int encode_guti_5gs_mobile_identity(Guti5GSMobileIdentity_t *guti, uint8_t *buffer);
static int encode_suci_5gs_mobile_identity(Suci5GSMobileIdentity_t *suci, uint8_t *buffer);
static int encode_imeisv_5gs_mobile_identity(Imeisv5GSMobileIdentity_t *imeisv, uint8_t *buffer);
static int encode_guti_5gs_mobile_identity(const Guti5GSMobileIdentity_t *guti, uint8_t *buffer);
static int encode_suci_5gs_mobile_identity(const Suci5GSMobileIdentity_t *suci, uint8_t *buffer);
static int encode_imeisv_5gs_mobile_identity(const Imeisv5GSMobileIdentity_t *imeisv, uint8_t *buffer);
int encode_stmsi_5gs_mobile_identity(uint8_t *buffer, Stmsi5GSMobileIdentity_t *stmsi, uint32_t len)
int encode_stmsi_5gs_mobile_identity(uint8_t *buffer, const Stmsi5GSMobileIdentity_t *stmsi, uint32_t len)
{
// Return if buffer is shorter than min length
if (len < LEN_5G_FGS_TMSI_IE)
......@@ -114,12 +113,9 @@ int decode_5gs_mobile_identity(FGSMobileIdentity *fgsmobileidentity, uint8_t iei
uint8_t typeofidentity = *(buffer + decoded) & 0x7;
if (typeofidentity == FGS_MOBILE_IDENTITY_5G_GUTI) {
decoded_rc = decode_guti_5gs_mobile_identity(&fgsmobileidentity->guti,
buffer + decoded);
} else {
AssertFatal(false, "Mobile Identity encoding of type %d not implemented\n", typeofidentity);
}
AssertFatal(typeofidentity == FGS_MOBILE_IDENTITY_5G_GUTI, "Mobile Identity encoding of type %d not implemented\n", typeofidentity);
if (typeofidentity == FGS_MOBILE_IDENTITY_5G_GUTI)
decoded_rc = decode_guti_5gs_mobile_identity(&fgsmobileidentity->guti, buffer + decoded);
if (decoded_rc < 0) {
return decoded_rc;
......@@ -128,7 +124,7 @@ int decode_5gs_mobile_identity(FGSMobileIdentity *fgsmobileidentity, uint8_t iei
return (decoded + decoded_rc);
}
int encode_5gs_mobile_identity(FGSMobileIdentity *fgsmobileidentity, uint8_t iei, uint8_t *buffer, uint32_t len)
int encode_5gs_mobile_identity(const FGSMobileIdentity *fgsmobileidentity, uint8_t iei, uint8_t *buffer, uint32_t len)
{
// Return if buffer is shorter than min length
if (len < MIN_LEN_FGS_MOBILE_ID_IE)
......@@ -146,18 +142,15 @@ int encode_5gs_mobile_identity(FGSMobileIdentity *fgsmobileidentity, uint8_t iei
len -= encoded;
if (fgsmobileidentity->guti.typeofidentity == FGS_MOBILE_IDENTITY_5G_GUTI) {
encoded_rc = encode_guti_5gs_mobile_identity(&fgsmobileidentity->guti,
buffer + encoded);
encoded_rc = encode_guti_5gs_mobile_identity(&fgsmobileidentity->guti, buffer + encoded);
}
if (fgsmobileidentity->suci.typeofidentity == FGS_MOBILE_IDENTITY_SUCI) {
encoded_rc = encode_suci_5gs_mobile_identity(&fgsmobileidentity->suci,
buffer + encoded);
encoded_rc = encode_suci_5gs_mobile_identity(&fgsmobileidentity->suci, buffer + encoded);
}
if (fgsmobileidentity->imeisv.typeofidentity == FGS_MOBILE_IDENTITY_IMEISV) {
encoded_rc = encode_imeisv_5gs_mobile_identity(&fgsmobileidentity->imeisv,
buffer + encoded);
encoded_rc = encode_imeisv_5gs_mobile_identity(&fgsmobileidentity->imeisv, buffer + encoded);
}
if (fgsmobileidentity->stmsi.typeofidentity == FGS_MOBILE_IDENTITY_5GS_TMSI) {
......@@ -168,7 +161,7 @@ int encode_5gs_mobile_identity(FGSMobileIdentity *fgsmobileidentity, uint8_t iei
return encoded_rc;
}
if(iei > 0){
if (iei > 0) {
uint16_t tmp = htons(encoded + encoded_rc - 3);
memcpy(buffer + 1, &tmp, sizeof(tmp));
} else {
......@@ -192,7 +185,6 @@ static int decode_guti_5gs_mobile_identity(Guti5GSMobileIdentity_t *guti, const
return (TLV_ENCODE_VALUE_DOESNT_MATCH);
}
guti->oddeven = (*(buffer + decoded) >> 3) & 0x1;
/*
......@@ -218,33 +210,27 @@ static int decode_guti_5gs_mobile_identity(Guti5GSMobileIdentity_t *guti, const
guti->mncdigit1 = *(buffer + decoded) & 0xf;
decoded++;
guti->amfregionid = *(buffer+decoded);
guti->amfregionid = *(buffer + decoded);
decoded++;
IES_DECODE_U16(buffer, decoded, temp);
guti->amfsetid = temp>>3;
guti->amfpointer = temp&0x3f;
guti->amfsetid = (temp >> 6) & 0x3FF;
guti->amfpointer = temp & 0x3f;
IES_DECODE_U32(buffer, decoded, guti->tmsi);
return decoded;
}
static int encode_guti_5gs_mobile_identity(Guti5GSMobileIdentity_t *guti, uint8_t *buffer)
static int encode_guti_5gs_mobile_identity(const Guti5GSMobileIdentity_t *guti, uint8_t *buffer)
{
uint32_t encoded = 0;
uint16_t temp;
*(buffer + encoded) = 0xf0 | ((guti->oddeven & 0x1) << 3) |
(guti->typeofidentity & 0x7);
*(buffer + encoded) = 0xf0 | ((guti->oddeven & 0x1) << 3) | (guti->typeofidentity & 0x7);
encoded++;
*(buffer + encoded) = 0x00 | ((guti->mccdigit2 & 0xf) << 4) |
(guti->mccdigit1 & 0xf);
*(buffer + encoded) = 0x00 | ((guti->mccdigit2 & 0xf) << 4) | (guti->mccdigit1 & 0xf);
encoded++;
*(buffer + encoded) = 0x00 | ((guti->mncdigit3 & 0xf) << 4) |
(guti->mccdigit3 & 0xf);
*(buffer + encoded) = 0x00 | ((guti->mncdigit3 & 0xf) << 4) | (guti->mccdigit3 & 0xf);
encoded++;
*(buffer + encoded) = 0x00 | ((guti->mncdigit2 & 0xf) << 4) |
(guti->mncdigit1 & 0xf);
*(buffer + encoded) = 0x00 | ((guti->mncdigit2 & 0xf) << 4) | (guti->mncdigit1 & 0xf);
encoded++;
*(buffer + encoded) = guti->amfregionid;
......@@ -257,28 +243,22 @@ static int encode_guti_5gs_mobile_identity(Guti5GSMobileIdentity_t *guti, uint8_
return encoded;
}
static int encode_suci_5gs_mobile_identity(Suci5GSMobileIdentity_t *suci, uint8_t *buffer)
static int encode_suci_5gs_mobile_identity(const Suci5GSMobileIdentity_t *suci, uint8_t *buffer)
{
uint32_t encoded = 0;
*(buffer + encoded) = (suci->supiformat << 4) | (suci->typeofidentity);
encoded++;
*(buffer + encoded) = ((suci->mccdigit2 & 0xf) << 4) |
(suci->mccdigit1 & 0xf);
*(buffer + encoded) = ((suci->mccdigit2 & 0xf) << 4) | (suci->mccdigit1 & 0xf);
encoded++;
*(buffer + encoded) = ((suci->mncdigit3 & 0xf) << 4) |
(suci->mccdigit3 & 0xf);
*(buffer + encoded) = ((suci->mncdigit3 & 0xf) << 4) | (suci->mccdigit3 & 0xf);
encoded++;
*(buffer + encoded) = ((suci->mncdigit2 & 0xf) << 4) |
(suci->mncdigit1 & 0xf);
*(buffer + encoded) = ((suci->mncdigit2 & 0xf) << 4) | (suci->mncdigit1 & 0xf);
encoded++;
*(buffer + encoded) = ((suci->routingindicatordigit2 & 0xf) << 4) |
(suci->routingindicatordigit1 & 0xf);
*(buffer + encoded) = ((suci->routingindicatordigit2 & 0xf) << 4) | (suci->routingindicatordigit1 & 0xf);
encoded++;
*(buffer + encoded) = ((suci->routingindicatordigit4 & 0xf) << 4) |
(suci->routingindicatordigit3 & 0xf);
*(buffer + encoded) = ((suci->routingindicatordigit4 & 0xf) << 4) | (suci->routingindicatordigit3 & 0xf);
encoded++;
*(buffer + encoded) = 0x00 | (suci->protectionschemeId & 0xf);
......@@ -287,19 +267,19 @@ static int encode_suci_5gs_mobile_identity(Suci5GSMobileIdentity_t *suci, uint8_
*(buffer + encoded) = suci->homenetworkpki;
encoded++;
char *ptr=suci->schemeoutput;
while ( ptr < suci->schemeoutput+strlen(suci->schemeoutput) ) {
buffer[encoded]=((*(ptr+1)-'0')<<4) | (*(ptr) -'0');
const char *ptr = suci->schemeoutput;
while (ptr < suci->schemeoutput + strlen(suci->schemeoutput)) {
buffer[encoded] = ((*(ptr + 1) - '0') << 4) | (*(ptr) - '0');
encoded++;
ptr+=2;
ptr += 2;
}
if (strlen(suci->schemeoutput)%2 == 1)
buffer[encoded++]=((*(ptr-1)-'0')) | 0xF0;
if (strlen(suci->schemeoutput) % 2 == 1)
buffer[encoded++] = ((*(ptr - 1) - '0')) | 0xF0;
return encoded;
}
static int encode_imeisv_5gs_mobile_identity(Imeisv5GSMobileIdentity_t *imeisv, uint8_t *buffer)
static int encode_imeisv_5gs_mobile_identity(const Imeisv5GSMobileIdentity_t *imeisv, uint8_t *buffer)
{
uint32_t encoded = 0;
*(buffer + encoded) = 0x00 | (imeisv->digittac01 << 4) | (imeisv->oddeven << 3) | (imeisv->typeofidentity);
......@@ -310,17 +290,16 @@ static int encode_imeisv_5gs_mobile_identity(Imeisv5GSMobileIdentity_t *imeisv,
encoded++;
*(buffer + encoded) = 0x00 | (imeisv->digittac07 << 4) | (imeisv->digittac06);
encoded++;
*(buffer + encoded) = 0x00 | (imeisv->digit09 << 4) | (imeisv->digittac08);
*(buffer + encoded) = 0x00 | (imeisv->digit09 << 4) | (imeisv->digittac08);
encoded++;
*(buffer + encoded) = 0x00 | (imeisv->digit11 << 4) | (imeisv->digit10);
*(buffer + encoded) = 0x00 | (imeisv->digit11 << 4) | (imeisv->digit10);
encoded++;
*(buffer + encoded) = 0x00 | (imeisv->digit13 << 4) | (imeisv->digit12);
*(buffer + encoded) = 0x00 | (imeisv->digit13 << 4) | (imeisv->digit12);
encoded++;
*(buffer + encoded) = 0x00 | (imeisv->digitsv1 << 4) | (imeisv->digit14);
*(buffer + encoded) = 0x00 | (imeisv->digitsv1 << 4) | (imeisv->digit14);
encoded++;
*(buffer + encoded) = 0x00 | (imeisv->spare << 4) | (imeisv->digitsv2);
*(buffer + encoded) = 0x00 | (imeisv->spare << 4) | (imeisv->digitsv2);
encoded++;
return encoded;
}
......@@ -27,7 +27,6 @@
* \version 0.1
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
......@@ -41,97 +40,96 @@
#define DIGIT1 0xF
typedef struct {
uint8_t spare:5;
uint8_t typeofidentity:3;
uint8_t spare: 5;
uint8_t typeofidentity: 3;
} NoIdentity5GSMobileIdentity_t;
typedef struct {
uint8_t spare1:1;
uint8_t supiformat:3;
uint8_t spare2:1;
uint8_t typeofidentity:3;
uint8_t mccdigit2:4;
uint8_t mccdigit1:4;
uint8_t mncdigit3:4;
uint8_t mccdigit3:4;
uint8_t mncdigit2:4;
uint8_t mncdigit1:4;
uint8_t routingindicatordigit2:4;
uint8_t routingindicatordigit1:4;
uint8_t routingindicatordigit4:4;
uint8_t routingindicatordigit3:4;
uint8_t spare3:1;
uint8_t spare4:1;
uint8_t spare5:1;
uint8_t spare6:1;
uint8_t protectionschemeId:4;
uint8_t homenetworkpki;
uint8_t spare1: 1;
uint8_t supiformat: 3;
uint8_t spare2: 1;
uint8_t typeofidentity: 3;
uint8_t mccdigit2: 4;
uint8_t mccdigit1: 4;
uint8_t mncdigit3: 4;
uint8_t mccdigit3: 4;
uint8_t mncdigit2: 4;
uint8_t mncdigit1: 4;
uint8_t routingindicatordigit2: 4;
uint8_t routingindicatordigit1: 4;
uint8_t routingindicatordigit4: 4;
uint8_t routingindicatordigit3: 4;
uint8_t spare3: 1;
uint8_t spare4: 1;
uint8_t spare5: 1;
uint8_t spare6: 1;
uint8_t protectionschemeId: 4;
uint8_t homenetworkpki;
char schemeoutput[32];
} Suci5GSMobileIdentity_t;
typedef struct {
uint8_t spare:4;
uint8_t oddeven:1;
uint8_t typeofidentity:3;
uint8_t mccdigit2:4;
uint8_t mccdigit1:4;
uint8_t mncdigit3:4;
uint8_t mccdigit3:4;
uint8_t mncdigit2:4;
uint8_t mncdigit1:4;
uint8_t amfregionid;
uint16_t amfsetid:10;
uint16_t amfpointer:6;
uint8_t spare: 4;
uint8_t oddeven: 1;
uint8_t typeofidentity: 3;
uint8_t mccdigit2: 4;
uint8_t mccdigit1: 4;
uint8_t mncdigit3: 4;
uint8_t mccdigit3: 4;
uint8_t mncdigit2: 4;
uint8_t mncdigit1: 4;
uint8_t amfregionid;
uint16_t amfsetid: 10;
uint16_t amfpointer: 6;
uint32_t tmsi;
} Guti5GSMobileIdentity_t;
typedef struct {
uint8_t digit1:4;
uint8_t oddeven:1;
uint8_t typeofidentity:3;
uint8_t digitp1:4;
uint8_t digitp:4;
uint8_t digit1: 4;
uint8_t oddeven: 1;
uint8_t typeofidentity: 3;
uint8_t digitp1: 4;
uint8_t digitp: 4;
} Imei5GSMobileIdentity_t;
typedef struct {
uint8_t digittac01:4;
uint8_t oddeven:1;
uint8_t typeofidentity:3;
uint8_t digittac02:4;
uint8_t digittac03:4;
uint8_t digittac04:4;
uint8_t digittac05:4;
uint8_t digittac06:4;
uint8_t digittac07:4;
uint8_t digittac08:4;
uint8_t digit09:4;
uint8_t digit10:4;
uint8_t digit11:4;
uint8_t digit12:4;
uint8_t digit13:4;
uint8_t digit14:4;
uint8_t digitsv1:4;
uint8_t digitsv2:4;
uint8_t spare:4;
uint8_t digittac01: 4;
uint8_t oddeven: 1;
uint8_t typeofidentity: 3;
uint8_t digittac02: 4;
uint8_t digittac03: 4;
uint8_t digittac04: 4;
uint8_t digittac05: 4;
uint8_t digittac06: 4;
uint8_t digittac07: 4;
uint8_t digittac08: 4;
uint8_t digit09: 4;
uint8_t digit10: 4;
uint8_t digit11: 4;
uint8_t digit12: 4;
uint8_t digit13: 4;
uint8_t digit14: 4;
uint8_t digitsv1: 4;
uint8_t digitsv2: 4;
uint8_t spare: 4;
} Imeisv5GSMobileIdentity_t;
typedef struct {
uint8_t digit1:4;
uint8_t spare:1;
uint8_t typeofidentity:3;
uint16_t amfsetid:10;
uint16_t amfpointer:6;
uint8_t digit1: 4;
uint8_t spare: 1;
uint8_t typeofidentity: 3;
uint16_t amfsetid: 10;
uint16_t amfpointer: 6;
uint32_t tmsi;
} Stmsi5GSMobileIdentity_t;
typedef struct {
uint8_t spare:5;
uint8_t typeofidentity:3;
uint8_t macaddr;
uint8_t spare: 5;
uint8_t typeofidentity: 3;
uint8_t macaddr;
} Macaddr5GSMobileIdentity_t;
// clang-format off
typedef union FGSMobileIdentity_tag {
#define FGS_MOBILE_IDENTITY_NOIDENTITY 0b000
#define FGS_MOBILE_IDENTITY_SUCI 0b001
......@@ -148,13 +146,13 @@ typedef union FGSMobileIdentity_tag {
Imeisv5GSMobileIdentity_t imeisv;
Macaddr5GSMobileIdentity_t macaddress;
} FGSMobileIdentity;
// clang-format on
int encode_5gs_mobile_identity(FGSMobileIdentity *fgsmobileidentity, uint8_t iei, uint8_t *buffer, uint32_t len);
int encode_5gs_mobile_identity(const FGSMobileIdentity *fgsmobileidentity, uint8_t iei, uint8_t *buffer, uint32_t len);
int decode_5gs_mobile_identity(FGSMobileIdentity *fgsmobileidentity, uint8_t iei, const uint8_t *buffer, uint32_t len);
int encode_stmsi_5gs_mobile_identity(uint8_t *buffer, Stmsi5GSMobileIdentity_t *stmsi, uint32_t len);
int encode_stmsi_5gs_mobile_identity(uint8_t *buffer, const Stmsi5GSMobileIdentity_t *stmsi, uint32_t len);
int decode_stmsi_5gs_mobile_identity(Stmsi5GSMobileIdentity_t *stmsi, const uint8_t *buffer, uint32_t len);
#endif /* FGS MOBILE IDENTITY_H_ */
......@@ -32,31 +32,27 @@
#include <stdlib.h>
#include <stdint.h>
#include "TLVEncoder.h"
#include "TLVDecoder.h"
#include "FGSRegistrationResult.h"
int decode_fgs_registration_result(FGSRegistrationResult *fgsregistrationresult, uint8_t iei, uint16_t value, uint32_t len)
{
int decoded = 0;
uint16_t *buffer = &value;
fgsregistrationresult->registrationresult = *buffer & 0x7;
fgsregistrationresult->smsallowed = *buffer & 0x8;
decoded = decoded+2;
decoded = decoded + 2;
return decoded;
}
uint16_t encode_fgs_registration_result(FGSRegistrationResult *fgsregistrationresult)
uint16_t encode_fgs_registration_result(const FGSRegistrationResult *fgsregistrationresult)
{
uint16_t bufferReturn;
uint16_t *buffer = &bufferReturn;
uint8_t encoded = 0;
*(buffer + encoded) = 0x00 | (fgsregistrationresult->smsallowed & 0x8) |
(fgsregistrationresult->registrationresult & 0x7);
encoded= encoded+2;
*(buffer + encoded) = 0x00 | (fgsregistrationresult->smsallowed & 0x8) | (fgsregistrationresult->registrationresult & 0x7);
encoded = encoded + 2;
return bufferReturn;
}
......@@ -34,8 +34,6 @@
#include "OctetString.h"
#ifndef FGS_REGISTRATION_RESULT_H_
#define FGS_REGISTRATION_RESULT_H_
#define FGS_REGISTRATION_RESULT_3GPP 0b001
......@@ -43,17 +41,15 @@
#define FGS_REGISTRATION_RESULT_3GPP_AND_NON_3GPP 0b011
typedef struct {
uint8_t iei;
uint8_t resultlength;
uint8_t spare:4;
uint8_t smsallowed:1;
uint8_t registrationresult:3;
uint8_t iei;
uint8_t resultlength;
uint8_t spare: 4;
uint8_t smsallowed: 1;
uint8_t registrationresult: 3;
} FGSRegistrationResult;
uint16_t encode_fgs_registration_result(FGSRegistrationResult *fgsregistrationresult);
uint16_t encode_fgs_registration_result(const FGSRegistrationResult *fgsregistrationresult);
int decode_fgs_registration_result(FGSRegistrationResult *fgsregistrationresult, uint8_t iei, uint16_t value, uint32_t len);
#endif /* FGS REGISTRATION RESULT_H_*/
......@@ -31,7 +31,6 @@
#include <stdlib.h>
#include <stdint.h>
#include "TLVEncoder.h"
#include "TLVDecoder.h"
#include "FGSRegistrationType.h"
......@@ -50,16 +49,14 @@ int decode_5gs_registration_type(FGSRegistrationType *fgsregistrationtype, uint8
return decoded;
}
int encode_5gs_registration_type(FGSRegistrationType *fgsregistrationtype)
int encode_5gs_registration_type(const FGSRegistrationType *fgsregistrationtype)
{
uint8_t bufferReturn;
uint8_t *buffer = &bufferReturn;
uint8_t encoded = 0;
uint8_t iei = 0;
*(buffer + encoded) = 0x00 | (iei & 0xf0) | 0x8|
(*fgsregistrationtype & 0x7);
*(buffer + encoded) = 0x00 | (iei & 0xf0) | 0x8 | (*fgsregistrationtype & 0x7);
encoded++;
return bufferReturn;
}
......@@ -40,16 +40,15 @@
typedef uint8_t FGSRegistrationType;
// clang-format off
#define INITIAL_REGISTRATION 0b001
#define MOBILITY_REGISTRATION_UPDATING 0b010
#define PERIODIC_REGISTRATION_UPDATING 0b011
#define EMERGENCY_REGISTRATION 0b100
// clang-format on
int encode_5gs_registration_type(FGSRegistrationType *fgsregistrationtype);
int encode_5gs_registration_type(const FGSRegistrationType *fgsregistrationtype);
int decode_5gs_registration_type(FGSRegistrationType *fgsregistrationtype, uint8_t iei, uint8_t value, uint32_t len);
#endif /* FGS_REGISTRATION_TYPE_H_*/
......@@ -27,37 +27,35 @@
* \version 0.1
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "TLVEncoder.h"
#include "TLVDecoder.h"
#include "NrUESecurityCapability.h"
int encode_nrue_security_capability(NrUESecurityCapability *nruesecuritycapability, uint8_t iei, uint8_t *buffer, uint32_t len)
int encode_nrue_security_capability(const NrUESecurityCapability *nruesecuritycapability,
uint8_t iei,
uint8_t *buffer,
uint32_t len)
{
int encoded = 0;
if(iei){
if (iei) {
*buffer = nruesecuritycapability->iei;
encoded++;
*(buffer+encoded) = nruesecuritycapability->length;
encoded++;
*(buffer+encoded) = nruesecuritycapability->fg_EA;
encoded++;
*(buffer+encoded) = nruesecuritycapability->fg_IA;
encoded++;
*(buffer+encoded) = nruesecuritycapability->EEA;
encoded++;
*(buffer+encoded) = nruesecuritycapability->EIA;
encoded++;
if((nruesecuritycapability->length - 4) > 0)
encoded = encoded + nruesecuritycapability->length - 4;
encoded++;
*(buffer + encoded) = nruesecuritycapability->length;
encoded++;
*(buffer + encoded) = nruesecuritycapability->fg_EA;
encoded++;
*(buffer + encoded) = nruesecuritycapability->fg_IA;
encoded++;
*(buffer + encoded) = nruesecuritycapability->EEA;
encoded++;
*(buffer + encoded) = nruesecuritycapability->EIA;
encoded++;
if ((nruesecuritycapability->length - 4) > 0)
encoded = encoded + nruesecuritycapability->length - 4;
}
return encoded;
}
......@@ -36,7 +36,6 @@
#ifndef NRUE_SECURITY_CAPABILITY_H_
#define NRUE_SECURITY_CAPABILITY_H_
typedef struct {
uint8_t iei;
uint8_t length;
......@@ -46,8 +45,9 @@ typedef struct {
uint8_t EIA;
} NrUESecurityCapability;
int encode_nrue_security_capability(NrUESecurityCapability *nruesecuritycapability, uint8_t iei, uint8_t *buffer, uint32_t len);
int encode_nrue_security_capability(const NrUESecurityCapability *nruesecuritycapability,
uint8_t iei,
uint8_t *buffer,
uint32_t len);
#endif /* NRUE_SECURITY_CAPABILITY_H_ */
......@@ -30,7 +30,10 @@
//#define NAS_DEBUG 1
int decode_sor_transparent_container(SORTransparentContainer *sortransparentcontainer, uint8_t iei, uint8_t *buffer, uint32_t len)
int decode_sor_transparent_container(SORTransparentContainer *sortransparentcontainer,
uint8_t iei,
const uint8_t *buffer,
uint32_t len)
{
int decoded = 0;
int decode_result;
......@@ -47,27 +50,31 @@ int decode_sor_transparent_container(SORTransparentContainer *sortransparentcont
CHECK_LENGTH_DECODER(len - decoded, ielen);
if ((decode_result = decode_octet_string(&sortransparentcontainer->sortransparentcontainercontents, ielen, buffer + decoded, len - decoded)) < 0) {
if ((decode_result =
decode_octet_string(&sortransparentcontainer->sortransparentcontainercontents, ielen, buffer + decoded, len - decoded))
< 0) {
LOG_FUNC_RETURN(decode_result);
} else {
decoded += decode_result;
}
#if defined (NAS_DEBUG)
#if defined(NAS_DEBUG)
dump_sor_transparent_container_xml(sortransparentcontainer, iei);
#endif
LOG_FUNC_RETURN(decoded);
}
int encode_sor_transparent_container(SORTransparentContainer *sortransparentcontainer, uint8_t iei, uint8_t *buffer, uint32_t len)
int encode_sor_transparent_container(const SORTransparentContainer *sortransparentcontainer,
uint8_t iei,
uint8_t *buffer,
uint32_t len)
{
uint8_t *lenPtr;
uint32_t encoded = 0;
int32_t encode_result;
/* Checking IEI and pointer */
CHECK_PDU_POINTER_AND_LENGTH_ENCODER(buffer, SOR_TRANSPARENT_CONTAINER_MINIMUM_LENGTH, len);
#if defined (NAS_DEBUG)
#if defined(NAS_DEBUG)
dump_sor_transparent_container_xml(sortransparentcontainer, iei);
#endif
......@@ -76,11 +83,12 @@ int encode_sor_transparent_container(SORTransparentContainer *sortransparentcont
encoded++;
}
lenPtr = (buffer + encoded);
lenPtr = (buffer + encoded);
//encoded += 2;
//if ((encode_result = encode_octet_string(&sortransparentcontainer->sortransparentcontainercontents, buffer + sizeof(uint16_t), len - sizeof(uint16_t))) < 0)
if ((encode_result = encode_octet_string(&sortransparentcontainer->sortransparentcontainercontents, lenPtr + sizeof(uint16_t), len - sizeof(uint16_t))) < 0)
if ((encode_result = encode_octet_string(&sortransparentcontainer->sortransparentcontainercontents,
lenPtr + sizeof(uint16_t),
len - sizeof(uint16_t)))
< 0)
return encode_result;
else
encoded += encode_result;
......@@ -100,4 +108,3 @@ void dump_sor_transparent_container_xml(SORTransparentContainer *sortransparentc
printf("%s", dump_octet_string_xml(&sortransparentcontainer->sortransparentcontainercontents));
printf("</SOR Transparent Container>\n");
}
......@@ -35,11 +35,16 @@ typedef struct SORTransparentContainer_tag {
OctetString sortransparentcontainercontents;
} SORTransparentContainer;
int encode_sor_transparent_container(SORTransparentContainer *sortransparentcontainer, uint8_t iei, uint8_t *buffer, uint32_t len);
int encode_sor_transparent_container(const SORTransparentContainer *sortransparentcontainer,
uint8_t iei,
uint8_t *buffer,
uint32_t len);
int decode_sor_transparent_container(SORTransparentContainer *sortransparentcontainer, uint8_t iei, uint8_t *buffer, uint32_t len);
int decode_sor_transparent_container(SORTransparentContainer *sortransparentcontainer,
uint8_t iei,
const uint8_t *buffer,
uint32_t len);
void dump_sor_transparent_container_xml(SORTransparentContainer *sortransparentcontainer, uint8_t iei);
#endif /* ESM MESSAGE CONTAINER_H_ */
add_library(fgs_5gmm_lib OBJECT
fgs_service_request.c
RegistrationRequest.c
RegistrationAccept.c
FGSIdentityResponse.c
FGSAuthenticationResponse.c
FGSNASSecurityModeComplete.c
RegistrationComplete.c
FGSUplinkNasTransport.c
FGSDeregistrationRequestUEOriginating.c
)
target_link_libraries(fgs_5gmm_lib PUBLIC fgs_5gmm_ies_lib)
target_include_directories(fgs_5gmm_lib PRIVATE ../IES/ ../../)
......@@ -37,20 +37,21 @@
#include "FGSAuthenticationResponse.h"
int encode_fgs_authentication_response(fgs_authentication_response_msg *authentication_response, uint8_t *buffer, uint32_t len)
int encode_fgs_authentication_response(const fgs_authentication_response_msg *authentication_response,
uint8_t *buffer,
uint32_t len)
{
int encoded = 0;
int encode_result = 0;
if ((encode_result =
encode_authentication_response_parameter(&authentication_response->authenticationresponseparameter,
AUTHENTICATION_RESPONSE_PARAMETER_IEI, buffer + encoded, len - encoded)) < 0) //Return in case of error
if ((encode_result = encode_authentication_response_parameter(&authentication_response->authenticationresponseparameter,
AUTHENTICATION_RESPONSE_PARAMETER_IEI,
buffer + encoded,
len - encoded))
< 0) // Return in case of error
return encode_result;
else
encoded += encode_result;
return encoded;
}
......@@ -32,16 +32,14 @@
#include <stdlib.h>
#include <stdint.h>
#include "ExtendedProtocolDiscriminator.h"
#include "SecurityHeaderType.h"
#include "SpareHalfOctet.h"
#include "MessageType.h"
#include "AuthenticationResponseParameter.h"
#ifndef FGS_AUTHENTICATION_RESPONSE_H_
#define FGS_AUTHENTICATION_RESPONSE_H_
#define AUTHENTICATION_RESPONSE_PARAMETER_IEI 0x2d
#define AUTHENTICATION_RESPONSE_PARAMETER_IEI 0x2d
/*
* Message name: Identity response
......@@ -52,15 +50,11 @@
typedef struct fgs_authentication_response_msg_tag {
/* Mandatory fields */
ExtendedProtocolDiscriminator protocoldiscriminator;
SecurityHeaderType securityheadertype:4;
SpareHalfOctet sparehalfoctet:4;
MessageType messagetype;
AuthenticationResponseParameter authenticationresponseparameter;
AuthenticationResponseParameter authenticationresponseparameter;
} fgs_authentication_response_msg;
int encode_fgs_authentication_response(fgs_authentication_response_msg *authentication_response, uint8_t *buffer, uint32_t len);
int encode_fgs_authentication_response(const fgs_authentication_response_msg *authentication_response,
uint8_t *buffer,
uint32_t len);
#endif /* ! defined(FGS_AUTHENTICATION_RESPONSE_H_) */
......@@ -27,23 +27,18 @@
* \version 0.1
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "FGSDeregistrationRequestUEOriginating.h"
#include <stdint.h>
#include "FGSDeregistrationRequestUEOriginating.h"
#include "NR_NAS_defs.h"
#define IEI_NULL 0x00
int encode_fgs_deregistration_request_ue_originating(fgs_deregistration_request_ue_originating_msg *drr,
int encode_fgs_deregistration_request_ue_originating(const fgs_deregistration_request_ue_originating_msg *drr,
uint8_t *buffer,
uint32_t len)
{
int encoded = 0;
FGSDeregistrationType *dt = &drr->deregistrationtype;
*(buffer + encoded) = ((dt->switchoff & 0x1) << 7)
| ((dt->reregistration_required & 0x1) << 6)
| ((dt->access_type & 0x3) << 4);
const FGSDeregistrationType *dt = &drr->deregistrationtype;
*(buffer + encoded) = ((dt->switchoff & 0x1) << 7) | ((dt->reregistration_required & 0x1) << 6) | ((dt->access_type & 0x3) << 4);
int encode_result;
if ((encode_result = encode_nas_key_set_identifier(&drr->naskeysetidentifier, IEI_NULL)) < 0)
......
......@@ -22,17 +22,12 @@
#ifndef FGS_DEREGISTRATION_REQUEST_UE_ORIGINATING_H_
#define FGS_DEREGISTRATION_REQUEST_UE_ORIGINATING_H_
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "ExtendedProtocolDiscriminator.h"
#include "SecurityHeaderType.h"
#include "SpareHalfOctet.h"
#include "MessageType.h"
#include "FGSDeregistrationType.h"
#include "NasKeySetIdentifier.h"
#include "FGSMobileIdentity.h"
#include "MessageType.h"
#include "NasKeySetIdentifier.h"
#include "SecurityHeaderType.h"
/*
* Message name: De-registration request (UE originating de-registration)
......@@ -43,18 +38,13 @@
typedef struct fgs_deregistration_request_ue_originating_msg_tag {
/* Mandatory fields */
ExtendedProtocolDiscriminator protocoldiscriminator;
SecurityHeaderType securityheadertype: 4;
SpareHalfOctet sparehalfoctet: 4;
MessageType messagetype;
FGSDeregistrationType deregistrationtype;
NasKeySetIdentifier naskeysetidentifier;
FGSMobileIdentity fgsmobileidentity;
} fgs_deregistration_request_ue_originating_msg;
int encode_fgs_deregistration_request_ue_originating(fgs_deregistration_request_ue_originating_msg *registrationrequest,
int encode_fgs_deregistration_request_ue_originating(const fgs_deregistration_request_ue_originating_msg *registrationrequest,
uint8_t *buffer,
uint32_t len);
#endif /* ! defined(REGISTRATION_REQUEST_H_) */
......@@ -28,29 +28,19 @@
\version 0.1
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "nas_log.h"
#include "FGSIdentityResponse.h"
#include <stdint.h>
int encode_identiy_response(fgs_identiy_response_msg *fgs_identity_reps, uint8_t *buffer, uint32_t len)
int encode_fgmm_identity_response(uint8_t *buffer, const fgmm_identity_response_msg *fgs_identity_reps, uint32_t len)
{
int encoded = 0;
int encode_result = 0;
if ((encode_result =
encode_5gs_mobile_identity(&fgs_identity_reps->fgsmobileidentity, 0, buffer +
encoded, len - encoded)) < 0) //Return in case of error
if ((encode_result = encode_5gs_mobile_identity(&fgs_identity_reps->fgsmobileidentity, 0, buffer + encoded, len - encoded))
< 0) // Return in case of error
return encode_result;
else
encoded += encode_result;
return encoded;
}
......@@ -28,15 +28,10 @@
\version 0.1
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "ExtendedProtocolDiscriminator.h"
#include "SecurityHeaderType.h"
#include "SpareHalfOctet.h"
#include "FGSMobileIdentity.h"
#include "MessageType.h"
#include "SecurityHeaderType.h"
#ifndef FGS_IDENTITY_RESPONSE_H_
#define FGS_IDENTITY_RESPONSE_H_
......@@ -48,18 +43,11 @@
* Direction: UE to AMF
*/
typedef struct fgs_identiy_response_msg_tag {
typedef struct fgmm_identity_response_msg_s {
/* Mandatory fields */
ExtendedProtocolDiscriminator protocoldiscriminator;
SecurityHeaderType securityheadertype:4;
SpareHalfOctet sparehalfoctet:4;
MessageType messagetype;
FGSMobileIdentity fgsmobileidentity;
FGSMobileIdentity fgsmobileidentity;
} fgmm_identity_response_msg;
} fgs_identiy_response_msg;
int encode_identiy_response(fgs_identiy_response_msg *fgs_identity_reps, uint8_t *buffer, uint32_t len);
int encode_fgmm_identity_response(uint8_t *buffer, const fgmm_identity_response_msg *fgs_identity_reps, uint32_t len);
#endif /* ! defined(FGS_IDENTITY_RESPONSE_H_) */
......@@ -28,39 +28,32 @@
\version 0.1
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "nas_log.h"
#include "FGSNASSecurityModeComplete.h"
#include "FGSMobileIdentity.h"
#include <stdint.h>
#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;
if ((encode_result =
encode_5gs_mobile_identity(&fgs_security_mode_comp->fgsmobileidentity, 0x77, buffer +
encoded, len - encoded)) < 0) { //Return in case of error
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
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;
}
......@@ -28,16 +28,11 @@
\version 0.1
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "ExtendedProtocolDiscriminator.h"
#include "SecurityHeaderType.h"
#include "SpareHalfOctet.h"
#include "FGCNasMessageContainer.h"
#include "FGSMobileIdentity.h"
#include "MessageType.h"
#include "FGCNasMessageContainer.h"
#include "SecurityHeaderType.h"
#ifndef FGS_NAS_SECURITY_MODE_COMPLETE_H_
#define FGS_NAS_SECURITY_MODE_COMPLETE_H_
......@@ -50,16 +45,11 @@
*/
typedef struct fgs_security_mode_complete_msg_tag {
/* Mandatory fields */
ExtendedProtocolDiscriminator protocoldiscriminator;
SecurityHeaderType securityheadertype:4;
SpareHalfOctet sparehalfoctet:4;
MessageType messagetype;
FGSMobileIdentity fgsmobileidentity;
FGCNasMessageContainer fgsnasmessagecontainer;
/* Mandatory fields */
FGSMobileIdentity fgsmobileidentity;
FGCNasMessageContainer fgsnasmessagecontainer;
} fgs_security_mode_complete_msg;
int encode_fgs_security_mode_complete(fgs_security_mode_complete_msg *fgs_security_mode_comp, uint8_t *buffer, uint32_t len);
int encode_fgs_security_mode_complete(const fgs_security_mode_complete_msg *fgs_security_mode_comp, uint8_t *buffer, uint32_t len);
#endif /* ! defined(FGS_NAS_SECURITY_MODE_COMPLETE_H_) */
......@@ -28,16 +28,13 @@
\version 0.1
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <arpa/inet.h>
#include "FGSUplinkNasTransport.h"
#include <netinet/in.h>
#include <stdint.h>
#include <string.h>
#include "TLVEncoder.h"
int encode_fgs_payload_container(FGSPayloadContainer *paycontainer, uint8_t iei, uint8_t *buffer, uint32_t len)
static int encode_fgs_payload_container(const FGSPayloadContainer *paycontainer, uint8_t iei, uint8_t *buffer, uint32_t len)
{
uint32_t encoded = 0;
int encode_result;
......@@ -54,7 +51,7 @@ int encode_fgs_payload_container(FGSPayloadContainer *paycontainer, uint8_t iei,
} else {
encoded += encode_result;
}
if(iei > 0){
if (iei > 0) {
uint16_t tmp = htons(encoded - 3);
memcpy(buffer + 1, &tmp, sizeof(tmp));
} else {
......@@ -65,7 +62,7 @@ int encode_fgs_payload_container(FGSPayloadContainer *paycontainer, uint8_t iei,
return encoded;
}
int encode_nssai(OctetString *nssai, uint8_t iei, uint8_t *buffer)
static int encode_nssai(const OctetString *nssai, uint8_t iei, uint8_t *buffer)
{
uint32_t encoded = 0;
int encode_result;
......@@ -78,7 +75,6 @@ int encode_nssai(OctetString *nssai, uint8_t iei, uint8_t *buffer)
*(buffer + encoded) = nssai->length;
encoded++;
if ((encode_result = encode_octet_string(nssai, buffer + encoded, nssai->length)) < 0) {
return encode_result;
} else {
......@@ -88,7 +84,7 @@ int encode_nssai(OctetString *nssai, uint8_t iei, uint8_t *buffer)
return encoded;
}
int encode_dnn(OctetString *dnn, uint8_t iei, uint8_t *buffer)
static int encode_dnn(const OctetString *dnn, uint8_t iei, uint8_t *buffer)
{
uint32_t encoded = 0;
int encode_result;
......@@ -110,43 +106,42 @@ int encode_dnn(OctetString *dnn, uint8_t iei, uint8_t *buffer)
return encoded;
}
int encode_fgs_uplink_nas_transport(fgs_uplink_nas_transport_msg *fgs_up_nas_transport, uint8_t *buffer, uint32_t len)
int encode_fgs_uplink_nas_transport(const fgs_uplink_nas_transport_msg *fgs_up_nas_transport, uint8_t *buffer, uint32_t len)
{
int encoded = 0;
int encode_result = 0;
int encoded = 0;
int encode_result = 0;
*(buffer + encoded) = (fgs_up_nas_transport->payloadcontainertype.iei << 4) | (fgs_up_nas_transport->payloadcontainertype.type &0xf);
encoded++;
*(buffer + encoded) =
(fgs_up_nas_transport->payloadcontainertype.iei << 4) | (fgs_up_nas_transport->payloadcontainertype.type & 0xf);
encoded++;
if ((encode_result = encode_fgs_payload_container(&fgs_up_nas_transport->fgspayloadcontainer,
0, buffer +encoded, len - encoded)) < 0) {
return encode_result;
} else {
encoded += encode_result;
}
if ((encode_result = encode_fgs_payload_container(&fgs_up_nas_transport->fgspayloadcontainer, 0, buffer + encoded, len - encoded))
< 0) {
return encode_result;
} else {
encoded += encode_result;
}
*(buffer + encoded) = 0x12;
encoded++;
*(buffer + encoded) = 0x12;
encoded++;
IES_ENCODE_U8(buffer, encoded, fgs_up_nas_transport->pdusessionid);
IES_ENCODE_U8(buffer, encoded, fgs_up_nas_transport->pdusessionid);
// set request type
*(buffer + encoded) = (0x8<<4)|(fgs_up_nas_transport->requesttype &0x7);
encoded++;
// set request type
*(buffer + encoded) = (0x8 << 4) | (fgs_up_nas_transport->requesttype & 0x7);
encoded++;
if ((encode_result = encode_nssai(&fgs_up_nas_transport->snssai, 0x22, buffer +encoded)) < 0) {
return encode_result;
} else {
encoded += encode_result;
}
if ((encode_result = encode_nssai(&fgs_up_nas_transport->snssai, 0x22, buffer + encoded)) < 0) {
return encode_result;
} else {
encoded += encode_result;
}
if ((encode_result = encode_dnn(&fgs_up_nas_transport->dnn, 0x25, buffer +encoded)) < 0) {
return encode_result;
} else {
encoded += encode_result;
}
if ((encode_result = encode_dnn(&fgs_up_nas_transport->dnn, 0x25, buffer + encoded)) < 0) {
return encode_result;
} else {
encoded += encode_result;
}
return encoded;
return encoded;
}
......@@ -28,14 +28,10 @@
\version 0.1
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "ExtendedProtocolDiscriminator.h"
#include "SecurityHeaderType.h"
#include "SpareHalfOctet.h"
#include "MessageType.h"
#include "OctetString.h"
#include "SecurityHeaderType.h"
#ifndef FGS_UPLINK_NAS_TRANSPORT_H_
#define FGS_UPLINK_NAS_TRANSPORT_H_
......@@ -47,31 +43,25 @@
* Direction: UE to network
*/
typedef struct PayloadContainerType_tag{
uint8_t iei:4;
uint8_t type:4;
}PayloadContainerType;
typedef struct PayloadContainerType_tag {
uint8_t iei: 4;
uint8_t type: 4;
} PayloadContainerType;
typedef struct FGSPayloadContainer_tag {
OctetString payloadcontainercontents;
} FGSPayloadContainer;
typedef struct fgs_uplink_nas_transport_msg_tag {
/* Mandatory fields */
ExtendedProtocolDiscriminator protocoldiscriminator;
SecurityHeaderType securityheadertype:4;
SpareHalfOctet sparehalfoctet:4;
MessageType messagetype;
PayloadContainerType payloadcontainertype;
FGSPayloadContainer fgspayloadcontainer;
/* Optional fields */
uint16_t pdusessionid;
uint8_t requesttype;
OctetString snssai;
OctetString dnn;
/* Mandatory fields */
PayloadContainerType payloadcontainertype;
FGSPayloadContainer fgspayloadcontainer;
/* Optional fields */
uint16_t pdusessionid;
uint8_t requesttype;
OctetString snssai;
OctetString dnn;
} fgs_uplink_nas_transport_msg;
int encode_fgs_uplink_nas_transport(fgs_uplink_nas_transport_msg *fgs_security_mode_comp, uint8_t *buffer, uint32_t len);
int encode_fgs_uplink_nas_transport(const fgs_uplink_nas_transport_msg *fgs_security_mode_comp, uint8_t *buffer, uint32_t len);
#endif /* ! defined(FGS_UPLINK_NAS_TRANSPORT_H_) */
......@@ -32,45 +32,124 @@
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#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(&registration_accept->fgsregistrationresult, 0, *(buffer + decoded), len - decoded)) < 0)
return decoded_result;
decoded += decoded_result;
if (decoded < len && buffer[decoded] == 0x77) {
registration_accept->guti = calloc(1, sizeof(*registration_accept->guti));
if (!registration_accept->guti)
return -1;
int mi_dec = decode_5gs_mobile_identity(registration_accept->guti, 0x77, buffer + decoded, len - decoded);
if (mi_dec < 0)
if ((dec = decode_fgs_registration_result(&registration_accept->fgsregistrationresult, 0, *buffer, len)) < 0)
return dec;
buffer += dec;
if (buffer < end && *buffer == IEI_5G_GUTI) {
registration_accept->guti = calloc_or_fail(1, sizeof(*registration_accept->guti));
if ((dec = decode_5gs_mobile_identity(registration_accept->guti, IEI_5G_GUTI, buffer, end - buffer)) < 0) {
PRINT_NAS_ERROR("Failed to decode 5GS Mobile Identity in Registration Accept\n");
return -1;
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(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;
LOG_FUNC_IN;
*(buffer + encoded) = encode_fgs_registration_result(&registration_accept->fgsregistrationresult);
encoded = encoded + 2;
......@@ -84,4 +163,3 @@ int encode_registration_accept(registration_accept_msg *registration_accept, uin
// todo ,Encoding optional fields
LOG_FUNC_RETURN(encoded);
}
......@@ -32,10 +32,7 @@
#include <stdlib.h>
#include <stdint.h>
#include "ExtendedProtocolDiscriminator.h"
#include "SecurityHeaderType.h"
#include "SpareHalfOctet.h"
#include "MessageType.h"
#include "FGSRegistrationResult.h"
#include "FGSMobileIdentity.h"
......@@ -43,6 +40,14 @@
#ifndef REGISTRATION_ACCEPT_H_
#define REGISTRATION_ACCEPT_H_
// 9.11.3.37 of 3GPP TS 24.501
typedef struct {
int sst;
int hplmn_sst;
int sd;
int hplmn_sd;
} nr_nas_msg_snssai_t;
/*
* Message name: Registration accept
* Description: The REGISTRATION ACCEPT message is sent by the AMF to the UE. See table 8.2.7.1.1.
......@@ -52,19 +57,17 @@
typedef struct registration_accept_msg_tag {
/* Mandatory fields */
ExtendedProtocolDiscriminator protocoldiscriminator;
SecurityHeaderType securityheadertype:4;
SpareHalfOctet sparehalfoctet:4;
MessageType messagetype;
FGSRegistrationResult fgsregistrationresult;
FGSRegistrationResult fgsregistrationresult;
/* Optional fields */
FGSMobileIdentity *guti;
// Allowed NSSAI (O)
nr_nas_msg_snssai_t nas_allowed_nssai[8];
// Configured NSSAI (O)
nr_nas_msg_snssai_t config_nssai[8];
} registration_accept_msg;
int decode_registration_accept(registration_accept_msg *registrationaccept, const uint8_t *buffer, uint32_t len);
int encode_registration_accept(registration_accept_msg *registrationaccept, uint8_t *buffer, uint32_t len);
int encode_registration_accept(const registration_accept_msg *registrationaccept, uint8_t *buffer, uint32_t len);
#endif /* ! defined(REGISTRATION_ACCEPT_H_) */
......@@ -19,24 +19,19 @@
* contact@openairinterface.org
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "TLVEncoder.h"
#include "TLVDecoder.h"
#include "RegistrationComplete.h"
#include <stdint.h>
#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(&registration_complete->sortransparentcontainer, 0, buffer + decoded, len - decoded)) < 0)
if ((decoded_result =
decode_sor_transparent_container(registration_complete->sortransparentcontainer, 0, buffer + decoded, len - decoded))
< 0)
return decoded_result;
else
decoded += decoded_result;
......@@ -44,18 +39,20 @@ int decode_registration_complete(registration_complete_msg *registration_complet
return decoded;
}
int encode_registration_complete(registration_complete_msg *registration_complete, uint8_t *buffer, uint32_t len)
int encode_registration_complete(const registration_complete_msg *registration_complete, uint8_t *buffer, uint32_t len)
{
int encoded = 0;
int encode_result = 0;
if (!registration_complete->sortransparentcontainer)
return encoded;
if ((encode_result =
encode_sor_transparent_container(&registration_complete->sortransparentcontainer, 0,
buffer + encoded, len - encoded)) < 0) //Return in case of error
encode_sor_transparent_container(registration_complete->sortransparentcontainer, 0, buffer + encoded, len - encoded))
< 0) // Return in case of error
return encode_result;
else
encoded += encode_result;
return encoded;
}
......@@ -28,35 +28,21 @@
\version 0.1
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "ExtendedProtocolDiscriminator.h"
#include "SecurityHeaderType.h"
#include "SpareHalfOctet.h"
#include "MessageType.h"
#include "SORTransparentContainer.h"
#include "SecurityHeaderType.h"
#ifndef REGISTRATION_COMPLETE_H_
#define REGISTRATION_COMPLETE_H_
typedef struct registration_complete_msg_tag {
/* Mandatory fields */
ExtendedProtocolDiscriminator protocoldiscriminator;
SecurityHeaderType securityheadertype:4;
SpareHalfOctet sparehalfoctet:4;
MessageType messagetype;
/* Optional fields */
SORTransparentContainer sortransparentcontainer;
SORTransparentContainer *sortransparentcontainer;
} registration_complete_msg;
int decode_registration_complete(registration_complete_msg *registrationcomplete, const uint8_t *buffer, uint32_t len);
int decode_registration_complete(registration_complete_msg *registrationcomplete, uint8_t *buffer, uint32_t len);
int encode_registration_complete(registration_complete_msg *registrationcomplete, uint8_t *buffer, uint32_t len);
int encode_registration_complete(const registration_complete_msg *registrationcomplete, uint8_t *buffer, uint32_t len);
#endif /* ! defined(REGISTRATION_COMPLETE_H_) */
......@@ -27,28 +27,25 @@
* \version 0.1
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "RegistrationRequest.h"
#include <stdint.h>
#include "T.h"
#include "nas_log.h"
#include "RegistrationRequest.h"
#include "NR_NAS_defs.h"
#define IEI_NULL 0x00
int decode_registration_request(registration_request_msg *registration_request, uint8_t *buffer, uint32_t len)
int decode_registration_request(registration_request_msg *registration_request, const uint8_t *buffer, uint32_t len)
{
uint32_t decoded = 0;
int decoded_result = 0;
LOG_FUNC_IN;
LOG_TRACE(INFO, "EMM - registration_request len = %d",
len);
LOG_TRACE(INFO, "5GMM: Registration Request len = %d", len);
/* Decoding mandatory fields */
if ((decoded_result = decode_5gs_registration_type(&registration_request->fgsregistrationtype, 0, *(buffer + decoded) & 0x0f, len - decoded)) < 0) {
// return decoded_result;
if ((decoded_result =
decode_5gs_registration_type(&registration_request->fgsregistrationtype, 0, *(buffer + decoded) & 0x0f, len - decoded))
< 0) {
LOG_FUNC_RETURN(decoded_result);
}
......@@ -60,19 +57,18 @@ int decode_registration_request(registration_request_msg *registration_request,
decoded++;
if ((decoded_result = decode_5gs_mobile_identity(&registration_request->fgsmobileidentity, 0, buffer + decoded, len - decoded)) < 0) {
// return decoded_result;
if ((decoded_result = decode_5gs_mobile_identity(&registration_request->fgsmobileidentity, 0, buffer + decoded, len - decoded))
< 0) {
LOG_FUNC_RETURN(decoded_result);
} else
decoded += decoded_result;
// TODO, Decoding optional fields
return decoded;
}
int encode_registration_request(registration_request_msg *registration_request, uint8_t *buffer, uint32_t len)
int encode_registration_request(const registration_request_msg *registration_request, uint8_t *buffer, uint32_t len)
{
int encoded = 0;
int encode_result = 0;
......@@ -81,9 +77,9 @@ int encode_registration_request(registration_request_msg *registration_request,
| (encode_5gs_registration_type(&registration_request->fgsregistrationtype) & 0x0f);
encoded++;
if ((encode_result =
encode_5gs_mobile_identity(&registration_request->fgsmobileidentity, 0, buffer +
encoded, len - encoded)) < 0) //Return in case of error
if ((encode_result = encode_5gs_mobile_identity(&registration_request->fgsmobileidentity, 0, buffer + encoded, len - encoded))
< 0)
// Return in case of error
return encode_result;
else
encoded += encode_result;
......@@ -91,8 +87,10 @@ int encode_registration_request(registration_request_msg *registration_request,
if ((registration_request->presencemask & REGISTRATION_REQUEST_5GMM_CAPABILITY_PRESENT)
== REGISTRATION_REQUEST_5GMM_CAPABILITY_PRESENT) {
if ((encode_result = encode_5gmm_capability(&registration_request->fgmmcapability,
REGISTRATION_REQUEST_5GMM_CAPABILITY_IEI, buffer + encoded, len -
encoded)) < 0)
REGISTRATION_REQUEST_5GMM_CAPABILITY_IEI,
buffer + encoded,
len - encoded))
< 0)
// Return in case of error
return encode_result;
else
......@@ -102,16 +100,16 @@ int encode_registration_request(registration_request_msg *registration_request,
if ((registration_request->presencemask & REGISTRATION_REQUEST_UE_SECURITY_CAPABILITY_PRESENT)
== REGISTRATION_REQUEST_UE_SECURITY_CAPABILITY_PRESENT) {
if ((encode_result = encode_nrue_security_capability(&registration_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;
}
......@@ -27,25 +27,19 @@
* \version 0.1
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "ExtendedProtocolDiscriminator.h"
#include "SecurityHeaderType.h"
#include "SpareHalfOctet.h"
#include "FGMMCapability.h"
#include "FGSMobileIdentity.h"
#include "NasKeySetIdentifier.h"
#include "FGSRegistrationType.h"
#include "MessageType.h"
#include "FGMMCapability.h"
#include "NasKeySetIdentifier.h"
#include "NrUESecurityCapability.h"
#include "SecurityHeaderType.h"
#ifndef REGISTRATION_REQUEST_H_
#define REGISTRATION_REQUEST_H_
// clang-format off
# define REGISTRATION_REQUEST_NON_CURRENT_NATIVE_NAS_KEYSET_PRESENT (1<<0)
# define REGISTRATION_REQUEST_5GMM_CAPABILITY_PRESENT (1<<1)
# define REGISTRATION_REQUEST_UE_SECURITY_CAPABILITY_PRESENT (1<<2)
......@@ -70,29 +64,30 @@
# define REGISTRATION_REQUEST_EPS_BEARER_CONTEXT_STATUS_PRESENT (1<<21)
typedef enum registration_request_iei_tag {
REGISTRATION_REQUEST_NON_CURRENT_NATIVE_NAS_KEYSET_IEI = 0xC0, /* 0xC- = 192- */
REGISTRATION_REQUEST_5GMM_CAPABILITY_IEI = 0x10, /* 0x10 = 16 */
REGISTRATION_REQUEST_UE_SECURITY_CAPABILITY_IEI = 0x2E, /* 0x2E = 46 */
REGISTRATION_REQUEST_REQUESTED_NSSAI_IEI = 0x2F, /* 0x2F = 47 */
REGISTRATION_REQUEST_LAST_VISITED_REGISTERED_TAI_IEI = 0x52, /* 0x52 = 82 */
REGISTRATION_REQUEST_S1_UE_NETWORK_CAPABILITY_IEI = 0x17, /* 0x17 = 23 */
REGISTRATION_REQUEST_UPLINK_DATA_STATUS_IEI = 0x40, /* 0x40 = 64 */
REGISTRATION_REQUEST_PDU_SESSION_STATUS_IEI = 0x50, /* 0x50 = 80 */
REGISTRATION_REQUEST_MICO_INDICATION_IEI = 0xB0, /* 0xB- = 176- */
REGISTRATION_REQUEST_UE_STATUS_IEI = 0x2B, /* 0x2B = 43 */
REGISTRATION_REQUEST_ADDITIONAL_GUTI_IEI = 0x77, /* 0x77 = 119 */
REGISTRATION_REQUEST_ALLOWED_PDU_SESSION_STATUS_IEI = 0x25, /* 0x25 = 37 */
REGISTRATION_REQUEST_UE_USAGE_SETTING_IEI = 0x18, /* 0x18 = 24 */
REGISTRATION_REQUEST_REQUESTED_DRX_PARAMETERS_IEI = 0x51, /* 0x51 = 81 */
REGISTRATION_REQUEST_EPS_NAS_MESSAGE_CONTAINER_IEI = 0x70, /* 0x70 = 112 */
REGISTRATION_REQUEST_LADN_INDICATION_IEI = 0x74, /* 0x74 = 116 */
REGISTRATION_REQUEST_PAYLOAD_CONTAINER_TYPE_IEI = 0x80, /* 0x80 = 128 */
REGISTRATION_REQUEST_PAYLOAD_CONTAINER_IEI = 0x7B, /* 0x7B = 123 */
REGISTRATION_REQUEST_NETWORK_SLICING_INDICATION_IEI = 0x90, /* 0x90 = 144 */
REGISTRATION_REQUEST_5GS_UPDATE_TYPE_IEI = 0x53, /* 0x53 = 83 */
REGISTRATION_REQUEST_NAS_MESSAGE_CONTAINER_IEI = 0x71, /* 0x71 = 113 */
REGISTRATION_REQUEST_EPS_BEARER_CONTEXT_STATUS_IEI = 0x60 /* 0x60 = 96 */
REGISTRATION_REQUEST_NON_CURRENT_NATIVE_NAS_KEYSET_IEI = 0xC0, /* 0xC- = 192- */
REGISTRATION_REQUEST_5GMM_CAPABILITY_IEI = 0x10, /* 0x10 = 16 */
REGISTRATION_REQUEST_UE_SECURITY_CAPABILITY_IEI = 0x2E, /* 0x2E = 46 */
REGISTRATION_REQUEST_REQUESTED_NSSAI_IEI = 0x2F, /* 0x2F = 47 */
REGISTRATION_REQUEST_LAST_VISITED_REGISTERED_TAI_IEI = 0x52, /* 0x52 = 82 */
REGISTRATION_REQUEST_S1_UE_NETWORK_CAPABILITY_IEI = 0x17, /* 0x17 = 23 */
REGISTRATION_REQUEST_UPLINK_DATA_STATUS_IEI = 0x40, /* 0x40 = 64 */
REGISTRATION_REQUEST_PDU_SESSION_STATUS_IEI = 0x50, /* 0x50 = 80 */
REGISTRATION_REQUEST_MICO_INDICATION_IEI = 0xB0, /* 0xB- = 176- */
REGISTRATION_REQUEST_UE_STATUS_IEI = 0x2B, /* 0x2B = 43 */
REGISTRATION_REQUEST_ADDITIONAL_GUTI_IEI = 0x77, /* 0x77 = 119 */
REGISTRATION_REQUEST_ALLOWED_PDU_SESSION_STATUS_IEI = 0x25, /* 0x25 = 37 */
REGISTRATION_REQUEST_UE_USAGE_SETTING_IEI = 0x18, /* 0x18 = 24 */
REGISTRATION_REQUEST_REQUESTED_DRX_PARAMETERS_IEI = 0x51, /* 0x51 = 81 */
REGISTRATION_REQUEST_EPS_NAS_MESSAGE_CONTAINER_IEI = 0x70, /* 0x70 = 112 */
REGISTRATION_REQUEST_LADN_INDICATION_IEI = 0x74, /* 0x74 = 116 */
REGISTRATION_REQUEST_PAYLOAD_CONTAINER_TYPE_IEI = 0x80, /* 0x80 = 128 */
REGISTRATION_REQUEST_PAYLOAD_CONTAINER_IEI = 0x7B, /* 0x7B = 123 */
REGISTRATION_REQUEST_NETWORK_SLICING_INDICATION_IEI = 0x90, /* 0x90 = 144 */
REGISTRATION_REQUEST_5GS_UPDATE_TYPE_IEI = 0x53, /* 0x53 = 83 */
REGISTRATION_REQUEST_NAS_MESSAGE_CONTAINER_IEI = 0x71, /* 0x71 = 113 */
REGISTRATION_REQUEST_EPS_BEARER_CONTEXT_STATUS_IEI = 0x60 /* 0x60 = 96 */
} registration_request_iei;
// clang-format on
/*
* Message name: Registration request
......@@ -103,23 +98,17 @@ typedef enum registration_request_iei_tag {
typedef struct registration_request_msg_tag {
/* Mandatory fields */
ExtendedProtocolDiscriminator protocoldiscriminator;
SecurityHeaderType securityheadertype:4;
SpareHalfOctet sparehalfoctet:4;
MessageType messagetype;
FGSRegistrationType fgsregistrationtype;
NasKeySetIdentifier naskeysetidentifier;
FGSMobileIdentity fgsmobileidentity;
FGSRegistrationType fgsregistrationtype;
NasKeySetIdentifier naskeysetidentifier;
FGSMobileIdentity fgsmobileidentity;
/* Optional fields */
uint32_t presencemask;
FGMMCapability fgmmcapability;
NrUESecurityCapability nruesecuritycapability;
uint32_t presencemask;
FGMMCapability fgmmcapability;
NrUESecurityCapability nruesecuritycapability;
} registration_request_msg;
int decode_registration_request(registration_request_msg *registrationrequest, uint8_t *buffer, uint32_t len);
int decode_registration_request(registration_request_msg *registrationrequest, const uint8_t *buffer, uint32_t len);
int encode_registration_request(registration_request_msg *registrationrequest, uint8_t *buffer, uint32_t len);
int encode_registration_request(const registration_request_msg *registrationrequest, uint8_t *buffer, uint32_t len);
#endif /* ! defined(REGISTRATION_REQUEST_H_) */
......@@ -30,15 +30,15 @@
#include "FGSMobileIdentity.h"
#include "NasKeySetIdentifier.h"
#include "ServiceType.h"
#include "NR_NAS_defs.h"
#define LEN_FGS_MOBILE_ID_CONTENTS_SIZE 2 // octets
#define MIN_LEN_FGS_SERVICE_REQUEST 10 // octets
#define IEI_NULL 0x00
/**
* @brief Encode 5GMM NAS Service Request message (8.2.16 of 3GPP TS 24.501)
*/
int encode_fgs_service_request(uint8_t *buffer, fgs_service_request_msg_t *service_request, uint32_t len)
int encode_fgs_service_request(uint8_t *buffer, const fgs_service_request_msg_t *service_request, uint32_t len)
{
// Return if buffer is shorter than min length
if (len < MIN_LEN_FGS_SERVICE_REQUEST)
......
......@@ -27,11 +27,8 @@
#include "SecurityHeaderType.h"
#include "NasKeySetIdentifier.h"
#include "ServiceType.h"
#include "ExtendedProtocolDiscriminator.h"
#include "FGCNasMessageContainer.h"
//#include "PDUSessionStatus.h"
#include "MessageType.h"
#include "SpareHalfOctet.h"
#include "FGSMobileIdentity.h"
#ifndef FGS_SERVICE_REQUEST_H_
......@@ -56,7 +53,7 @@ typedef struct {
FGCNasMessageContainer *fgsnasmessagecontainer;
} fgs_service_request_msg_t;
int encode_fgs_service_request(uint8_t *buffer, fgs_service_request_msg_t *servicerequest, uint32_t len);
int encode_fgs_service_request(uint8_t *buffer, const fgs_service_request_msg_t *servicerequest, uint32_t len);
int decode_fgs_service_request(fgs_service_request_msg_t *sr, const uint8_t *buffer, uint32_t len);
#endif /* ! defined(FGS_SERVICE_REQUEST_H_) */
add_library(fgs_5gsm_lib OBJECT PduSessionEstablishRequest.c
PduSessionEstablishmentAccept.c)
target_link_libraries(fgs_5gsm_lib PUBLIC nas_common_ies_lib)
target_include_directories(fgs_5gsm_lib PUBLIC . ../../)
......@@ -28,22 +28,14 @@
\version 0.1
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "PduSessionEstablishRequest.h"
#include <stdint.h>
#include "TLVEncoder.h"
#include "TLVDecoder.h"
#include "PduSessionEstablishRequest.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;
}
......@@ -31,35 +31,28 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#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_) */
......@@ -23,31 +23,39 @@
#define PDU_SESSION_ESTABLISHMENT_ACCEPT_H_
#include <stdint.h>
#include <stdbool.h>
#include "fgs_nas_utils.h"
/* PDU Session Establish Accept Optional IE Identifiers - TS 24.501 Table 8.3.2.1.1 */
#define IEI_5GSM_CAUSE 0x59 /* 5GSM cause 9.11.4.2 */
#define IEI_PDU_ADDRESS 0x29 /* PDU address 9.11.4.10 */
#define IEI_RQ_TIMER_VALUE 0x56 /* GPRS timer 9.11.2.3 */
#define IEI_SNSSAI 0x22 /* S-NSSAI 9.11.2.8 */
#define IEI_ALWAYSON_PDU 0x80 /* Always-on PDU session indication 9.11.4.3 */
#define IEI_MAPPED_EPS 0x75 /* Mapped EPS bearer contexts 9.11.4.8 */
#define IEI_EAP_MSG 0x78 /* EAP message 9.11.2.2 */
#define IEI_AUTH_QOS_DESC 0x79 /* QoS flow descriptions 9.11.4.12 */
#define IEI_EXT_CONF_OPT 0x7b /* Extended protocol configuration options 9.11.4.6 */
#define IEI_DNN 0x25 /* DNN 9.11.2.1B */
#define FOREACH_IEI(IEI_DEF) \
IEI_DEF(IEI_5GSM_CAUSE, 0x59) /* 5GSM cause 9.11.4.2 */ \
IEI_DEF(IEI_PDU_ADDRESS, 0x29) /* PDU address 9.11.4.10 */ \
IEI_DEF(IEI_RQ_TIMER_VALUE, 0x56) /* GPRS timer 9.11.2.3 */ \
IEI_DEF(IEI_SNSSAI, 0x22) /* S-NSSAI 9.11.2.8 */ \
IEI_DEF(IEI_ALWAYSON_PDU, 0x80) /* Always-on PDU session indication 9.11.4.3 */ \
IEI_DEF(IEI_MAPPED_EPS, 0x75) /* Mapped EPS bearer contexts 9.11.4.8 */ \
IEI_DEF(IEI_EAP_MSG, 0x78) /* EAP message 9.11.2.2 */ \
IEI_DEF(IEI_AUTH_QOS_DESC, 0x79) /* QoS flow descriptions 9.11.4.12 */ \
IEI_DEF(IEI_EXT_CONF_OPT, 0x7b) /* Extended protocol configuration options 9.11.4.6 */ \
IEI_DEF(IEI_DNN, 0x25) /* DNN 9.11.2.1B */
static const text_info_t iei_text_desc[] = {FOREACH_IEI(TO_TEXT)};
typedef enum { FOREACH_IEI(TO_ENUM) } pduSessionEstablishment_IEI_t;
/* PDU Session type value - TS 24.501 Table 9.11.4.10.1*/
#define PDU_SESSION_TYPE_IPV4 0b001
#define PDU_SESSION_TYPE_IPV6 0b010
#define PDU_SESSION_TYPE_IPV4 0b001
#define PDU_SESSION_TYPE_IPV6 0b010
#define PDU_SESSION_TYPE_IPV4V6 0b011
#define IPv4_ADDRESS_LENGTH 4 // length of the IPv4 address associated with a PDU session
#define IPv4_ADDRESS_LENGTH 4 // length of the IPv4 address associated with a PDU session
#define IPv6_INTERFACE_ID_LENGTH 8 // interface identifier for the IPv6 link local address
#define SMF_IPv6_LLA_LENGTH 16
/* Rule operation codes - TS 24.501 Table 9.11.4.13.1 */
// clang-format off
#define ROC_RESERVED_0 0b000 /* Reserved */
#define ROC_CREATE_NEW_QOS_RULE 0b001 /* Create new QoS rule */
#define ROC_DELETE_QOS_RULE 0b010 /* Delete existing QoS rule */
......@@ -56,13 +64,14 @@
#define ROC_MODIFY_QOS_RULE_DELETE_PF 0b101 /* Modify existing QoS rule and delete packet filters */
#define ROC_MODIFY_QOS_RULE_WITHOUT_PF 0b110 /* Modify existing QoS rule without modifying packet filters */
#define ROC_RESERVED_1 0b111 /* Reserved */
// clang-format on
/* DNN - APN
/* DNN - APN
* TS 23.003 9.1
* The APN is composed of two parts, the APN Network Identifier (9.1.1) & The APN Operator Identifier (9.1.2).
*
*
* The DNN information element has a length in the range of 3 to 102 octets.
* The Header is consisted of two octets, the DNN IEI and the Length of the DNN contents fields, each is 1 octet.
* The Header is consisted of two octets, the DNN IEI and the Length of the DNN contents fields, each is 1 octet.
* The DNN value payload starts from the 3rd octet.
* The accumulated max length of APN payload is 100 octets.
* The min length of the APN payload is 1 octet.
......@@ -70,16 +79,18 @@
#define APN_MAX_LEN 100
#define APN_MIN_LEN 1
#define MAX_NUM_QOS_RULES 64
/* Mandatory Presence IE - TS 24.501 Table 8.3.2.1.1 */
typedef struct packet_filter_create_qos_rule_s {
uint8_t pf_dir; /* Packet filter direction */
uint8_t pf_id; /* Packet filter identifier */
uint8_t pf_id; /* Packet filter identifier */
uint8_t length; /* Length of packet filter contents */
} packet_filter_type1_t; /* TS 24.501 Figure 9.11.4.13.3 */
typedef struct packet_filter_modify_qos_rule_s {
uint8_t pf_id; /* Packet filter identifier */
uint8_t pf_id; /* Packet filter identifier */
} packet_filter_type2_t; /* TS 24.501 Figure 9.11.4.13.4 */
typedef struct packet_filter_s {
......@@ -90,39 +101,51 @@ typedef struct packet_filter_s {
} packet_filter_t;
typedef struct qos_rule_s {
uint8_t id; /* QoS rule identifier */
uint16_t length; /* Length of QoS Rule */
uint8_t oc; /* Rule operation code (3bits) */
uint8_t dqr; /* DQR bit (1 bit) */
uint8_t nb_pf; /* Number of packet filters (4 bits) */
uint8_t prcd; /* QoS rule precedence */
uint8_t qfi; /* QoS Flow Identifier */
// QoS rule identifier
uint8_t id;
// Length of QoS Rule
uint16_t length;
// Rule operation code
uint8_t oc;
// Default QoS Rule
bool dqr;
// Number of packet filters
uint8_t nb_pf;
// QoS rule precedence
uint8_t precendence;
// QoS Flow Identifier
uint8_t qfi;
} qos_rule_t;
typedef struct auth_qos_rules_s {
uint16_t length; /* Length of QoS rules IE */
} auth_qos_rule_t; /* QoS Rule as defined in 24.501 Figure 9.11.4.13.2 */
uint16_t length; /* Length of QoS rules IE */
// QoS rules (M)
qos_rule_t rule[MAX_NUM_QOS_RULES];
} auth_qos_rule_t; /* QoS Rule as defined in 24.501 Figure 9.11.4.13.2 */
typedef struct session_ambr_s {
uint8_t length; /* Length of Session-AMBR contents */
uint8_t unit_dl; /* Unit for Session-AMBR for downlink */
uint8_t length; /* Length of Session-AMBR contents */
uint8_t unit_dl; /* Unit for Session-AMBR for downlink */
uint16_t sess_dl; /* Session-AMBR for downlink */
uint8_t unit_ul; /* Unit for Session-AMBR for uplink */
uint8_t unit_ul; /* Unit for Session-AMBR for uplink */
uint16_t sess_ul; /* Session-AMBR for uplink */
} session_ambr_t; /* TS 24.501 Figure 9.11.4.14.1 */
} session_ambr_t; /* TS 24.501 Figure 9.11.4.14.1 */
/* Optional Presence IE - TS 24.501 Table 8.3.2.1.1 */
typedef struct pdu_address_s {
uint8_t pdu_iei; /* PDU Address IEI (0x29) */
uint8_t pdu_length; /* Length of PDU address contents */
uint8_t pdu_type; /* PDU session type value */
/// PDU address information (depending on type, up to 12 bytes)
// PDU address IEI (0x29) (octet 1)
uint8_t pdu_iei;
// Length of PDU address contents (octet 2)
uint8_t pdu_length;
// PDU session type value (9.11.4.11 of TS 24.501)
uint8_t pdu_type;
// PDU address IE (depending on type, up to 12 bytes)
uint8_t pdu_addr_oct[IPv4_ADDRESS_LENGTH + IPv6_INTERFACE_ID_LENGTH];
} pdu_address_t; /* TS 24.501 9.11.4.10 */
typedef struct dnn_s {
uint8_t dnn_iei; /* DNN IEI (0x25) */
uint8_t dnn_iei; /* DNN IEI (0x25) */
uint8_t dnn_length; /* Length of DNN contents */
} dnn_t; /* TS 24.501 9.11.2.1A */
......@@ -135,38 +158,24 @@ typedef struct qos_fd_s {
} qos_fd_t; /* TS 24.501 9.11.4.12 - Ommited, only length is processed*/
typedef struct pdu_session_establishment_accept_msg_s {
/* Mandatory presence */
uint8_t epd; /* Extended Protocol Discriminator */
uint8_t pdu_id; /* PDU Session ID */
uint8_t pti; /* Procedure Transaction Identity */
uint8_t msg_type; /* Message Type */
uint8_t pdu_type; /* PDU Session Type */
uint8_t ssc_mode; /* SSC mode */
auth_qos_rule_t qos_rules; /* Authorized QoS rules */
session_ambr_t sess_ambr; /* Session-AMBR */
/* Optional presence */
dnn_t dnn_ie; /* Data Network Name */
pdu_address_t pdu_addr_ie; /* PDU Address */
ext_pP_t ext_pp_ie; /* Extended Protocol Configuration Options */
qos_fd_t qos_fd_ie; /* QoS flow descriptions */
// PDU Session Type (M)
uint8_t pdu_type;
// Selected SSC Mode (M)
uint8_t ssc_mode;
// Authorized QoS rules (M)
auth_qos_rule_t qos_rules;
// Session-AMBR (M)
session_ambr_t sess_ambr;
// Data Network Name (O)
dnn_t dnn_ie;
// PDU Address (O)
pdu_address_t pdu_addr_ie;
// Extended Protocol Configuration Options (O)
ext_pP_t ext_pp_ie;
// QoS flow descriptions (O)
qos_fd_t qos_fd_ie;
} pdu_session_establishment_accept_msg_t; /* 24.501 Table 8.3.2.1.1 */
typedef struct security_protected_plain_nas_5gs_msg_s {
uint8_t epd; /* Extended Protocol Discriminator */
uint8_t sht; /* Security Header Type */
uint8_t msg_type; /* Message Type */
uint8_t payload_type; /* Payload Container Type */
uint16_t payload_len; /* Payload Container Length */
} security_protected_plain_nas_5gs_msg_t;
typedef struct security_protected_nas_5gs_msg_s {
uint8_t epd; /* Extended Protocol Discriminator */
uint8_t sht; /* Security Header Type */
uint32_t mac; /* Message Authentication Code */
uint8_t sqn; /* Sequence Number */
} security_protected_nas_5gs_msg_t; /* 24.501 Figure 9.1.1.2 */
void capture_pdu_session_establishment_accept_msg(uint8_t *buffer, uint32_t msg_length);
int decode_pdu_session_establishment_accept_msg(pdu_session_establishment_accept_msg_t *psea_msg, uint8_t *buffer, uint32_t msg_length);
#endif
add_subdirectory(5GMM/MSG)
add_subdirectory(5GMM/IES)
add_subdirectory(5GSM/MSG)
if(ENABLE_TESTS)
add_subdirectory(tests)
endif()
add_library(fgs_lib fgs_nas_lib.c)
target_link_libraries(fgs_lib PUBLIC
fgs_5gmm_lib
fgs_5gsm_lib
fgs_5gmm_ies_lib
nas_common_ies_lib
)
target_include_directories(fgs_lib PUBLIC . 5GMM/MSG 5GMM/IES)
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#include "NR_NAS_defs.h"
#include "nas_log.h"
#include "TLVEncoder.h"
#include "fgs_nas_utils.h"
int _nas_mm_msg_encode_header(const fgmm_msg_header_t *header, uint8_t *buffer, uint32_t len)
{
int size = 0;
/* Check the buffer length */
if (len < sizeof(fgmm_msg_header_t)) {
return (TLV_ENCODE_BUFFER_TOO_SHORT);
}
/* Check the protocol discriminator */
if (header->ex_protocol_discriminator != FGS_MOBILITY_MANAGEMENT_MESSAGE) {
LOG_TRACE(ERROR, "Unexpected extened protocol discriminator: 0x%x", header->ex_protocol_discriminator);
return (TLV_ENCODE_PROTOCOL_NOT_SUPPORTED);
}
/* Encode the extendedprotocol discriminator */
ENCODE_U8(buffer + size, header->ex_protocol_discriminator, size);
/* Encode the security header type */
ENCODE_U8(buffer + size, (header->security_header_type & 0xf), size);
/* Encode the message type */
ENCODE_U8(buffer + size, header->message_type, size);
return (size);
}
int mm_msg_encode(const fgmm_nas_message_plain_t *p, uint8_t *buffer, uint32_t len)
{
uint8_t msg_type = p->header.message_type;
int enc_msg = 0;
/* First encode the 5GMM message header */
int enc_header = _nas_mm_msg_encode_header(&p->header, buffer, len);
if (enc_header < 0) {
PRINT_NAS_ERROR("Failed to encode 5GMM message header\n");
return enc_header;
}
buffer += enc_header;
len -= enc_header;
switch (msg_type) {
case FGS_REGISTRATION_REQUEST:
enc_msg = encode_registration_request(&p->mm_msg.registration_request, buffer, len);
break;
case FGS_IDENTITY_RESPONSE:
enc_msg = encode_fgmm_identity_response(buffer, &p->mm_msg.fgs_identity_response, len);
break;
case FGS_AUTHENTICATION_RESPONSE:
enc_msg = encode_fgs_authentication_response(&p->mm_msg.fgs_auth_response, buffer, len);
break;
case FGS_SECURITY_MODE_COMPLETE:
enc_msg = encode_fgs_security_mode_complete(&p->mm_msg.fgs_security_mode_complete, buffer, len);
break;
case FGS_UPLINK_NAS_TRANSPORT:
enc_msg = encode_fgs_uplink_nas_transport(&p->mm_msg.uplink_nas_transport, buffer, len);
break;
case FGS_DEREGISTRATION_REQUEST_UE_ORIGINATING:
enc_msg =
encode_fgs_deregistration_request_ue_originating(&p->mm_msg.fgs_deregistration_request_ue_originating, buffer, len);
break;
case FGS_SERVICE_REQUEST:
enc_msg = encode_fgs_service_request(buffer, &p->mm_msg.service_request, len);
break;
default:
LOG_TRACE(ERROR, " Unexpected message type: 0x%x", p->header.message_type);
enc_msg = TLV_ENCODE_WRONG_MESSAGE_TYPE;
break;
/* TODO: Handle not standard layer 3 messages: SERVICE_REQUEST */
}
if (enc_msg < 0) {
PRINT_NAS_ERROR("Failed to encode 5GMM message\n");
return enc_msg;
}
return enc_header + enc_msg;
}
int nas_protected_security_header_encode(uint8_t *buffer, const fgs_nas_message_security_header_t *header, int length)
{
int size = 0;
if (length < sizeof(fgs_nas_message_security_header_t)) {
PRINT_NAS_ERROR("Could not encode the NAS security header\n");
return -1;
}
/* Encode the protocol discriminator) */
ENCODE_U8(buffer, header->protocol_discriminator, size);
/* Encode the security header type */
ENCODE_U8(buffer + size, (header->security_header_type & 0xf), size);
/* Encode the message authentication code */
ENCODE_U32(buffer + size, header->message_authentication_code, size);
/* Encode the sequence number */
ENCODE_U8(buffer + size, header->sequence_number, size);
return size;
}
/**
* @brief Decode plain 5GMM header from buffer and return fgmm_msg_header_t instance
*/
uint8_t decode_5gmm_msg_header(fgmm_msg_header_t *mm_header, const uint8_t *buffer, uint32_t len)
{
if (len < sizeof(fgmm_msg_header_t)) {
PRINT_NAS_ERROR("Failed to decode plain 5GMM header: buffer length too short\n");
return -1;
}
mm_header->ex_protocol_discriminator = *buffer++;
mm_header->security_header_type = *buffer++;
mm_header->message_type = *buffer++;
return sizeof(*mm_header);
}
/**
* @brief Decode plain 5GSM header from buffer and return fgsm_msg_header_t instance
*/
uint8_t decode_5gsm_msg_header(fgsm_msg_header_t *sm_header, const uint8_t *buffer, uint32_t len)
{
if (len < sizeof(fgsm_msg_header_t)) {
PRINT_NAS_ERROR("Failed to decode plain 5GSM header: buffer length too short\n");
return -1;
}
sm_header->ex_protocol_discriminator = *buffer++;
sm_header->pdu_session_id = *buffer++;
sm_header->pti = *buffer++;
sm_header->message_type = *buffer++;
return sizeof(*sm_header);
}
/**
* @brief Decode security protected 5GS header from buffer and return fgs_nas_message_security_header_t instance
*/
int decode_5gs_security_protected_header(fgs_nas_message_security_header_t *header, const uint8_t *buf, uint32_t len)
{
int decoded = 0;
if (len < sizeof(fgs_nas_message_security_header_t)) {
PRINT_NAS_ERROR("Failed to decode security protected 5GS header: buffer length too short\n");
return -1;
}
header->protocol_discriminator = *buf++;
decoded++;
header->security_header_type = *buf++;
decoded++;
uint32_t tmp;
memcpy(&tmp, buf, sizeof(tmp));
decoded += sizeof(tmp);
header->message_authentication_code = htonl(tmp);
header->sequence_number = *buf++;
decoded++;
return decoded;
}
/*
* 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 <stdint.h>
#include <arpa/inet.h>
#include <string.h> // For memcpy
#define PRINT_NAS_ERROR(...) fprintf(stderr, ##__VA_ARGS__)
#define _NAS_EQ_CHECK_GENERIC(condition, fmt, ...) \
do { \
if (!(condition)) { \
PRINT_NAS_ERROR("NAS Equality Check failure: %s:%d: Condition '%s' failed: " fmt " != " fmt "\n", \
__FILE__, \
__LINE__, \
#condition, \
##__VA_ARGS__); \
return false; \
} \
} while (0)
#define _NAS_EQ_CHECK_LONG(A, B) _NAS_EQ_CHECK_GENERIC(A == B, "%ld", A, B);
#define _NAS_EQ_CHECK_INT(A, B) _NAS_EQ_CHECK_GENERIC(A == B, "%d", A, B);
#define _NAS_EQ_CHECK_STR(A, B) _NAS_EQ_CHECK_GENERIC(strcmp(A, B) == 0, "'%s'", A, B);
/* Map task id to printable name. */
typedef struct {
int id;
char text[256];
} text_info_t;
#define TO_TEXT(LabEl, nUmID) {nUmID, #LabEl},
#define TO_ENUM(LabEl, nUmID ) LabEl = nUmID,
#define GET_SHORT(input, size) ({ \
uint16_t tmp16; \
memcpy(&tmp16, (input), sizeof(tmp16)); \
size += htons(tmp16); \
})
#endif // FGS_NAS_UTILS_H
......@@ -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}
)
add_subdirectory(5GS)
add_library(nr_nas STATIC nr_nas_msg.c)
target_link_libraries(nr_nas PUBLIC asn1_lte_rrc_hdrs asn1_nr_rrc_hdrs)
target_link_libraries(nr_nas PUBLIC
fgs_lib
fgs_5gmm_lib
fgs_5gsm_lib
fgs_5gmm_ies_lib
nas_common_ies_lib
nas_utils
)
target_include_directories(nr_nas PUBLIC . 5GS/)
This diff is collapsed.
......@@ -23,6 +23,7 @@
* \brief simulator for nr nas message
* \author Yoshio INOUE, Masayuki HARADA
* \email yoshio.inoue@fujitsu.com,masayuki.harada@fujitsu.com
* \protocol 5GS (5GMM and 5GSM)
* \date 2020
* \version 0.1
*/
......@@ -30,17 +31,14 @@
#ifndef __NR_NAS_MSG_SIM_H__
#define __NR_NAS_MSG_SIM_H__
#include "RegistrationRequest.h"
#include "FGSIdentityResponse.h"
#include "FGSAuthenticationResponse.h"
#include "FGSNASSecurityModeComplete.h"
#include "FGSDeregistrationRequestUEOriginating.h"
#include "RegistrationComplete.h"
#include "EMM/MSG/fgs_service_request.h"
#include "as_message.h"
#include "FGSUplinkNasTransport.h"
#include <common/utils/assertions.h>
#include <openair3/UICC/usim_interface.h>
#include <stdbool.h>
#include <stdint.h>
#include "as_message.h"
#include "NR_NAS_defs.h"
#include "secu_defs.h"
#include "NR_NAS_defs.h"
#define INITIAL_REGISTRATION 0b001
......@@ -48,18 +46,11 @@
#define SECURITY_PROTECTED_5GS_NAS_MESSAGE_HEADER_LENGTH 7
#define PAYLOAD_CONTAINER_LENGTH_MIN 3
#define PAYLOAD_CONTAINER_LENGTH_MAX 65537
#define NAS_INTEGRITY_SIZE 4
/* 3GPP TS 24.501: 9.11.3.50 Service type */
#define SERVICE_TYPE_DATA 0x1
/* List of allowed NSSAI from NAS messaging. */
typedef struct {
int sst;
int hplmn_sst;
int sd;
int hplmn_sd;
} nr_nas_msg_snssai_t;
/* Security Key for SA UE */
typedef struct {
uint8_t kausf[32];
......@@ -85,82 +76,6 @@ typedef struct {
instance_t UE_id;
} nr_ue_nas_t;
typedef enum fgs_protocol_discriminator_e {
/* Protocol discriminator identifier for 5GS Mobility Management */
FGS_MOBILITY_MANAGEMENT_MESSAGE = 0x7E,
/* Protocol discriminator identifier for 5GS Session Management */
FGS_SESSION_MANAGEMENT_MESSAGE = 0x2E,
} fgs_protocol_discriminator_t;
typedef struct {
uint8_t ex_protocol_discriminator;
uint8_t security_header_type;
uint8_t message_type;
} mm_msg_header_t;
/* Structure of security protected header */
typedef struct {
fgs_protocol_discriminator_t protocol_discriminator;
uint8_t security_header_type;
uint32_t message_authentication_code;
uint8_t sequence_number;
} fgs_nas_message_security_header_t;
typedef union {
mm_msg_header_t header;
registration_request_msg registration_request;
fgs_service_request_msg_t service_request;
fgs_identiy_response_msg fgs_identity_response;
fgs_authentication_response_msg fgs_auth_response;
fgs_deregistration_request_ue_originating_msg fgs_deregistration_request_ue_originating;
fgs_security_mode_complete_msg fgs_security_mode_complete;
registration_complete_msg registration_complete;
fgs_uplink_nas_transport_msg uplink_nas_transport;
} MM_msg;
typedef struct {
MM_msg mm_msg; /* 5GS Mobility Management messages */
} fgs_nas_message_plain_t;
typedef struct {
fgs_nas_message_security_header_t header;
fgs_nas_message_plain_t plain;
} fgs_nas_message_security_protected_t;
typedef union {
fgs_nas_message_security_header_t header;
fgs_nas_message_security_protected_t security_protected;
fgs_nas_message_plain_t plain;
} fgs_nas_message_t;
typedef struct {
union {
mm_msg_header_t plain_nas_msg_header;
struct security_protected_nas_msg_header_s {
uint8_t ex_protocol_discriminator;
uint8_t security_header_type;
uint16_t message_authentication_code1;
uint16_t message_authentication_code2;
uint8_t sequence_number;
} security_protected_nas_msg_header_t;
} choice;
} nas_msg_header_t;
typedef struct {
uint8_t ex_protocol_discriminator;
uint8_t pdu_session_id;
uint8_t PTI;
uint8_t message_type;
} fgs_sm_nas_msg_header_t;
typedef struct {
mm_msg_header_t plain_nas_msg_header;
uint8_t payload_container_type;
uint16_t payload_container_length;
fgs_sm_nas_msg_header_t sm_nas_msg_header;
} dl_nas_transport_t;
nr_ue_nas_t *get_ue_nas_info(module_id_t module_id);
void generateRegistrationRequest(as_nas_info_t *initialNasMsg, nr_ue_nas_t *nas);
void generateServiceRequest(as_nas_info_t *initialNasMsg, nr_ue_nas_t *nas);
......
This diff is collapsed.
......@@ -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]
......
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}
)
......@@ -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 */
......
......@@ -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 */
......
......@@ -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;
......
......@@ -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
......
......@@ -95,14 +95,16 @@ int nas_itti_protected_msg(const char *buffer, const nas_message_t *msg, const i
}
#endif
int nas_itti_kenb_refresh_req(const Byte_t kenb[32], int user_id) {
int nas_itti_kenb_refresh_req(const uint8_t kenb[32], int user_id)
{
MessageDef *message_p;
message_p = itti_alloc_new_message(TASK_NAS_UE, 0, NAS_KENB_REFRESH_REQ);
memcpy(NAS_KENB_REFRESH_REQ(message_p).kenb, kenb, sizeof(NAS_KENB_REFRESH_REQ(message_p).kenb));
return itti_send_msg_to_task(TASK_RRC_UE, NB_eNB_INST + user_id, message_p);
}
int nas_itti_cell_info_req(const plmn_t plmnID, const Byte_t rat, int user_id) {
int nas_itti_cell_info_req(const plmn_t plmnID, const uint8_t rat, int user_id)
{
MessageDef *message_p;
message_p = itti_alloc_new_message(TASK_NAS_UE, 0, NAS_CELL_SELECTION_REQ);
NAS_CELL_SELECTION_REQ(message_p).plmnID = plmnID;
......@@ -110,7 +112,14 @@ int nas_itti_cell_info_req(const plmn_t plmnID, const Byte_t rat, int user_id) {
return itti_send_msg_to_task(TASK_RRC_UE, NB_eNB_INST + user_id, message_p);
}
int nas_itti_nas_establish_req(as_cause_t cause, as_call_type_t type, as_stmsi_t s_tmsi, plmn_t plmnID, Byte_t *data, uint32_t length, int user_id) {
int nas_itti_nas_establish_req(as_cause_t cause,
as_call_type_t type,
as_stmsi_t s_tmsi,
plmn_t plmnID,
uint8_t *data,
uint32_t length,
int user_id)
{
MessageDef *message_p;
message_p = itti_alloc_new_message(TASK_NAS_UE, 0, NAS_CONN_ESTABLI_REQ);
NAS_CONN_ESTABLI_REQ(message_p).cause = cause;
......
......@@ -38,11 +38,17 @@ int nas_itti_plain_msg(
int nas_itti_protected_msg(const char *buffer, const nas_message_t *msg, const int lengthP, const int instance);
int nas_itti_kenb_refresh_req(const Byte_t kenb[32], int user_id);
int nas_itti_kenb_refresh_req(const uint8_t kenb[32], int user_id);
int nas_itti_cell_info_req(const plmn_t plmnID, const Byte_t rat, int user_id);
int nas_itti_cell_info_req(const plmn_t plmnID, const uint8_t rat, int user_id);
int nas_itti_nas_establish_req(as_cause_t cause, as_call_type_t type, as_stmsi_t s_tmsi, plmn_t plmnID, Byte_t *data_pP, uint32_t lengthP, int user_id);
int nas_itti_nas_establish_req(as_cause_t cause,
as_call_type_t type,
as_stmsi_t s_tmsi,
plmn_t plmnID,
uint8_t *data_pP,
uint32_t lengthP,
int user_id);
int nas_itti_ul_data_req(const uint32_t ue_idP, void *const data_pP, const uint32_t lengthP, int user_id);
......
......@@ -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;
......
......@@ -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__*/
add_library(lib_uicc OBJECT usim_interface.c)
target_include_directories(lib_uicc PRIVATE .)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment