Commit bbd6072d authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen
Browse files

added NAS/NGAP from AMF

parent ab5955c0
......@@ -102,7 +102,7 @@ SPGW-U =
);
SPGW-C_LIST = (
{IPV4_ADDRESS="192.168.160.100" ;}
{IPV4_ADDRESS="172.55.55.101" ;}
);
};
......@@ -28,4 +28,89 @@
#ifndef FILE_3GPP_23_003_SEEN
#define FILE_3GPP_23_003_SEEN
#endif /* FILE_3GPP_23_003_SEEN */
//#include "3gpp_29.274.h"
#include <stdint.h>
typedef struct plmn_s {
uint8_t mcc_digit2:4;
uint8_t mcc_digit1:4;
uint8_t mcc_digit3:4;
uint8_t mnc_digit3:4;
uint8_t mnc_digit2:4;
uint8_t mnc_digit1:4;
} plmn_t;
#define INVALID_TAC_0000 (uint16_t)0x0000
#define INVALID_TAC_FFFE (uint16_t)0xFFFE
#define INVALID_TAC (uint32_t)0x00000000
#define INVALID_TMSI UINT32_MAX /*!< \brief The network shall not allocate a TMSI with all 32 bits equal to 1
(this is because the TMSI must be stored in the SIM, and the SIM uses 4 octets with all bits
equal to 1 to indicate that no valid TMSI is available). */
typedef uint16_t tac_t;
typedef struct tai_s {
plmn_t plmn; /*!< \brief <MCC> + <MNC> */
tac_t tac; /*!< \brief Tracking Area Code */
} tai_t;
typedef struct eci_s {
uint32_t gnb_id:20;
uint32_t cell_id:8;
uint32_t empty:4;
} ci_t;
typedef struct cgi_s {
plmn_t plmn;
ci_t cell_identity; //28 bits
} cgi_t;
typedef struct nr_tai_s /*5G ADD it*/
{
plmn_t plmn;
uint32_t tac:24;
}nr_tai_t;
typedef struct nr_cell_identity_s /*5G ADD it */
{
uint32_t gnb_id;
uint8_t cell_id:4;
}nr_cell_identity_t;
typedef struct nr_cgi_s /*5G ADD it */
{
plmn_t plmn;
nr_cell_identity_t cell_identity;
}nr_cgi_t;
typedef struct fiveG_s_tmsi_s /*5G ADD it */
{
uint16_t amf_set_id:10;
uint8_t amf_pointer:6;
uint32_t fiveG_s_tmsi; //32
}fiveG_s_tmsi_t;
typedef struct amf_set_id_s /*5G ADD it*/
{
uint16_t amf_set_id:10;
}amf_set_id_t;
typedef struct allowed_nssai /*5G ADD it*/
{
uint8_t sST;
uint32_t sD:24;
}allowed_nssai;
typedef struct allowed_nssai_s /*5G ADD it*/
{
allowed_nssai *s_nssai;
uint32_t count;
}allowed_nssai_t;
#endif
......@@ -21,6 +21,7 @@
set(ITTI_DIR ${CMAKE_CURRENT_SOURCE_DIR}/itti)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/itti)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/msg)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/nas)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
include_directories(${SRC_TOP_DIR}/../build/ext/spdlog/include)
......
......@@ -30,15 +30,85 @@
#define FILE_COMMON_DEFS_SEEN
#include <arpa/inet.h>
#include <stdint.h>
#define RETURNclear (int)2
#define RETURNerror (int)1
#define RETURNok (int)0
typedef enum {
/* Fatal errors - received message should not be processed */
TLV_MAC_MISMATCH = -14,
TLV_BUFFER_NULL = -13,
TLV_BUFFER_TOO_SHORT = -12,
TLV_PROTOCOL_NOT_SUPPORTED = -11,
TLV_WRONG_MESSAGE_TYPE = -10,
TLV_OCTET_STRING_TOO_LONG_FOR_IEI = -9,
TLV_VALUE_DOESNT_MATCH = -4,
TLV_MANDATORY_FIELD_NOT_PRESENT = -3,
TLV_UNEXPECTED_IEI = -2,
// RETURNerror = -1,
// RETURNok = 0,
TLV_ERROR_OK = RETURNok,
/* Defines error code limit below which received message should be discarded
* because it cannot be further processed */
TLV_FATAL_ERROR = TLV_VALUE_DOESNT_MATCH
} error_code_e;
//------------------------------------------------------------------------------
#define IPV4_STR_ADDR_TO_INADDR(AdDr_StR,InAdDr,MeSsAgE ) do {\
if ( inet_aton(AdDr_StR, &InAdDr ) <= 0 ) {\
throw (MeSsAgE);\
#define DECODE_U8(bUFFER, vALUE, sIZE) \
vALUE = *(uint8_t*)(bUFFER); \
sIZE += sizeof(uint8_t)
#define DECODE_U16(bUFFER, vALUE, sIZE) \
vALUE = ntohs(*(uint16_t*)(bUFFER)); \
sIZE += sizeof(uint16_t)
#define DECODE_U24(bUFFER, vALUE, sIZE) \
vALUE = ntohl(*(uint32_t*)(bUFFER)) >> 8; \
sIZE += sizeof(uint8_t) + sizeof(uint16_t)
#define DECODE_U32(bUFFER, vALUE, sIZE) \
vALUE = ntohl(*(uint32_t*)(bUFFER)); \
sIZE += sizeof(uint32_t)
#if (BYTE_ORDER == LITTLE_ENDIAN)
# define DECODE_LENGTH_U16(bUFFER, vALUE, sIZE) \
vALUE = ((*(bUFFER)) << 8) | (*((bUFFER) + 1)); \
sIZE += sizeof(uint16_t)
#else
# define DECODE_LENGTH_U16(bUFFER, vALUE, sIZE) \
vALUE = (*(bUFFER)) | (*((bUFFER) + 1) << 8); \
sIZE += sizeof(uint16_t)
#endif
#define ENCODE_U8(buffer, value, size) \
*(uint8_t*)(buffer) = value; \
size += sizeof(uint8_t)
#define ENCODE_U16(buffer, value, size) \
*(uint16_t*)(buffer) = htons(value); \
size += sizeof(uint16_t)
#define ENCODE_U24(buffer, value, size) \
*(uint32_t*)(buffer) = htonl(value); \
size += sizeof(uint8_t) + sizeof(uint16_t)
#define ENCODE_U32(buffer, value, size) \
*(uint32_t*)(buffer) = htonl(value); \
size += sizeof(uint32_t)
#define IPV4_STR_ADDR_TO_INT_NWBO(AdDr_StR,NwBo,MeSsAgE ) do {\
struct in_addr inp;\
if ( inet_aton(AdDr_StR, &inp ) < 0 ) {\
AssertFatal (0, MeSsAgE);\
} else {\
NwBo = inp.s_addr;\
}\
} while (0)
......@@ -48,6 +118,39 @@
(uint8_t)((addr & 0x00FF0000) >> 16), \
(uint8_t)((addr & 0xFF000000) >> 24)
#define HIPADDR(addr) \
(uint8_t)((addr & 0xFF000000) >> 24),\
(uint8_t)((addr & 0x00FF0000) >> 16),\
(uint8_t)((addr & 0x0000FF00) >> 8), \
(uint8_t)(addr & 0x000000FF)
#define NIP6ADDR(addr) \
ntohs((addr)->s6_addr16[0]), \
ntohs((addr)->s6_addr16[1]), \
ntohs((addr)->s6_addr16[2]), \
ntohs((addr)->s6_addr16[3]), \
ntohs((addr)->s6_addr16[4]), \
ntohs((addr)->s6_addr16[5]), \
ntohs((addr)->s6_addr16[6]), \
ntohs((addr)->s6_addr16[7])
#define IN6_ARE_ADDR_MASKED_EQUAL(a,b,m) \
(((((__const uint32_t *) (a))[0] & (((__const uint32_t *) (m))[0])) == (((__const uint32_t *) (b))[0] & (((__const uint32_t *) (m))[0]))) \
&& ((((__const uint32_t *) (a))[1] & (((__const uint32_t *) (m))[1])) == (((__const uint32_t *) (b))[1] & (((__const uint32_t *) (m))[1]))) \
&& ((((__const uint32_t *) (a))[2] & (((__const uint32_t *) (m))[2])) == (((__const uint32_t *) (b))[2] & (((__const uint32_t *) (m))[2]))) \
&& ((((__const uint32_t *) (a))[3] & (((__const uint32_t *) (m))[3])) == (((__const uint32_t *) (b))[3] & (((__const uint32_t *) (m))[3]))))
////////////
#define IPV4_STR_ADDR_TO_INADDR(AdDr_StR,InAdDr,MeSsAgE ) do {\
if ( inet_aton(AdDr_StR, &InAdDr ) <= 0 ) {\
throw (MeSsAgE);\
}\
} while (0)
#ifndef UNUSED
#define UNUSED(x) (void)(x)
#endif
......
/*
* 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 Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
*
* 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 <stdint.h>
typedef enum extended_protocol_discriminator_e {
/* Protocol discriminator identifier for 5G Session Management */
FIVEGS_SESSION_MANAGEMENT_MESSAGES = 0x2e,
/* Protocol discriminator identifier for 5G Mobility Management */
FIVEGS_MOBILITY_MANAGEMENT_MESSAGES = 0x7e,
} extended_protocol_discriminator_t;
/*
* 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 Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
*
* 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 3gpp_33.401.h
\brief
\author Lionel Gauthier
\company Eurecom
\email: lionel.gauthier@eurecom.fr
*/
#include "security_types.h"
#ifndef FILE_3GPP_33_401_SEEN
#define FILE_3GPP_33_401_SEEN
//------------------------------------------------------------------------------
// 5.1.3.2 Algorithm Identifier Values
//------------------------------------------------------------------------------
#define EEA0_ALG_ID 0b000
#define EEA1_128_ALG_ID 0b001
#define EEA2_128_ALG_ID 0b010
//------------------------------------------------------------------------------
// 5.1.4.2 Algorithm Identifier Values
//------------------------------------------------------------------------------
#define EIA0_ALG_ID 0b000
#define EIA1_128_ALG_ID 0b001
#define EIA2_128_ALG_ID 0b010
//------------------------------------------------------------------------------
// 6.1.2 Distribution of authentication data from HSS to serving network
//------------------------------------------------------------------------------
/* NOTE 2: It is recommended that the MME fetch only one EPS authentication vector at a time as the need to perform
* AKA runs has been reduced in EPS through the use of a more elaborate key hierarchy. In particular,
* service requests can be authenticated using a stored K ASME without the need to perform AKA.
* Furthermore, the sequence number management schemes in TS 33.102, Annex C [4], designed to avoid
* re-synchronisation problems caused by interleaving use of batches of authentication vectors, are only
* optional. Re-synchronisation problems in EPS can be avoided, independently of the sequence number
* management scheme, by immediately using an authentication vector retrieved from the HSS in an
* authentication procedure between UE and MME.
*/
#define MAX_EPS_AUTH_VECTORS 1
//----------------------------
typedef struct mm_ue_eps_authentication_quadruplet_s{
uint8_t rand[16];
uint8_t xres_len;
uint8_t xres[XRES_LENGTH_MAX];
uint8_t autn_len;
uint8_t autn[AUTN_LENGTH_OCTETS];
uint8_t k_asme[32];
} mm_ue_eps_authentication_quadruplet_t;
typedef struct mm_ue_eps_authentication_quintuplet_s{
uint8_t rand[16];
uint8_t xres_len;
uint8_t xres[XRES_LENGTH_MAX];
uint8_t ck[16];
uint8_t ik[16];
uint8_t autn_len;
uint8_t autn[AUTN_LENGTH_OCTETS];
} mm_ue_eps_authentication_quintuplet_t;
#endif /* FILE_3GPP_33_401_SEEN */
/*
* 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 Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
*
* 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 3gpp_36.401.h
\brief
\author Lionel Gauthier
\company Eurecom
\email: lionel.gauthier@eurecom.fr
*/
#ifndef FILE_3GPP_36_401_SEEN
#define FILE_3GPP_36_401_SEEN
//------------------------------------------------------------------------------
// 6.2 E-UTRAN Identifiers
//------------------------------------------------------------------------------
typedef uint32_t enb_ue_s1ap_id_t; /*!< \brief An eNB UE S1AP ID shall be allocated so as to uniquely identify the UE over the S1 interface within an eNB.
When an MME receives an eNB UE S1AP ID it shall store it for the duration of the UE-associated logical S1-connection for this UE.
Once known to an MME this IE is included in all UE associated S1-AP signalling.
The eNB UE S1AP ID shall be unique within the eNB logical node. */
typedef uint32_t mme_ue_s1ap_id_t; /*!< \brief A MME UE S1AP ID shall be allocated so as to uniquely identify the UE over the S1 interface within the MME.
When an eNB receives MME UE S1AP ID it shall store it for the duration of the UE-associated logical S1-connection for this UE.
Once known to an eNB this IE is included in all UE associated S1-AP signalling.
The MME UE S1AP ID shall be unique within the MME logical node.*/
#endif /* FILE_3GPP_36_401_SEEN */
#ifndef FILE_3GPP_38_401_SEEN
#define FILE_3GPP_38_401_SEEN
#include <stdint.h>
typedef uint32_t ran_ue_ngap_id_t;
typedef uint32_t gnb_ue_ngap_id_t;
typedef uint32_t amf_ue_ngap_id_t;
#endif
MESSAGE_DEF(AMF_APP_INITIAL_UE_MESSAGE , MESSAGE_PRIORITY_MED, itti_amf_app_initial_ue_message_t , amf_app_initial_ue_message)
MESSAGE_DEF(AMF_APP_NGAP_AMF_UE_ID_NOTIFICATION , MESSAGE_PRIORITY_MED, itti_amf_app_ngap_amf_ue_id_notification_t , amf_app_ngap_amf_ue_id_notification)
#include "as_message.h"
#define AMF_APP_INITIAL_UE_MESSAGE(mSGpTR) (mSGpTR)->ittiMsg.amf_app_initial_ue_message
#define AMF_APP_NGAP_AMF_UE_ID_NOTIFICATION(mSGpTR) (mSGpTR)->ittiMsg.amf_app_ngap_amf_ue_id_notification
typedef struct itti_amf_app_initial_ue_message_s {
sctp_assoc_id_t sctp_assoc_id; // key stored in AMF_APP for AMF_APP forward NAS response to NGAP
uint32_t gnb_id;
amf_ue_ngap_id_t amf_ue_ngap_id;
ran_ue_ngap_id_t ran_ue_ngap_id;
bstring nas;
nr_tai_t tai;
nr_cgi_t cgi;
as_cause_t as_cause; /* Establishment cause */
bool is_fiveG_s_tmsi_valid;
bool is_amf_set_id_valid;
bool is_allowed_nssai_valid;
fiveG_s_tmsi_t fiveG_s_tmsi;
amf_set_id_t amf_set_id;
allowed_nssai_t allowedNSSAI;
itti_ngap_initial_ue_message_t transparent;
} itti_amf_app_initial_ue_message_t;
typedef struct itti_amf_app_ngap_amf_ue_id_notification_s {
ran_ue_ngap_id_t ran_ue_ngap_id;
amf_ue_ngap_id_t amf_ue_ngap_id;
sctp_assoc_id_t sctp_assoc_id;
} itti_amf_app_ngap_amf_ue_id_notification_t;
/*
* 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 Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
*
* 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 asn1_conversions.h
\brief
\author Sebastien ROUX, Lionel Gauthier
\company Eurecom
\email: lionel.gauthier@eurecom.fr
*/
#ifndef FILE_ASN1_CONVERSIONS_SEEN
#define FILE_ASN1_CONVERSIONS_SEEN
#include "BIT_STRING.h"
#include "assertions.h"
//-----------------------begin func -------------------
/*! \fn uint8_t BIT_STRING_to_uint8(BIT_STRING_t *)
*\brief This function extract at most a 8 bits value from a BIT_STRING_t object, the exact bits number depend on the BIT_STRING_t contents.
*\param[in] pointer to the BIT_STRING_t object.
*\return the extracted value.
*/
static inline uint8_t BIT_STRING_to_uint8(BIT_STRING_t *asn) {
DevCheck ((asn->size == 1), asn->size, 0, 0);
return asn->buf[0] >> asn->bits_unused;
}
/*! \fn uint16_t BIT_STRING_to_uint16(BIT_STRING_t *)
*\brief This function extract at most a 16 bits value from a BIT_STRING_t object, the exact bits number depend on the BIT_STRING_t contents.
*\param[in] pointer to the BIT_STRING_t object.
*\return the extracted value.
*/
static inline uint16_t BIT_STRING_to_uint16(BIT_STRING_t *asn) {
uint16_t result = 0;
int index = 0;
DevCheck ((asn->size > 0) && (asn->size <= 2), asn->size, 0, 0);
switch (asn->size) {
case 2:
result |= asn->buf[index++] << (8 - asn->bits_unused);
case 1:
result |= asn->buf[index] >> asn->bits_unused;
break;
default:
break;
}
return result;
}
/*! \fn uint32_t BIT_STRING_to_uint32(BIT_STRING_t *)
*\brief This function extract at most a 32 bits value from a BIT_STRING_t object, the exact bits number depend on the BIT_STRING_t contents.
*\param[in] pointer to the BIT_STRING_t object.
*\return the extracted value.
*/
static inline uint32_t BIT_STRING_to_uint32(BIT_STRING_t *asn) {
uint32_t result = 0;
int index;
int shift;
DevCheck ((asn->size > 0) && (asn->size <= 4), asn->size, 0, 0);
shift = ((asn->size - 1) * 8) - asn->bits_unused;
for (index = 0; index < (asn->size - 1); index++) {
result |= asn->buf[index] << shift;
shift -= 8;
}
result |= asn->buf[index] >> asn->bits_unused;
return result;
}
/*! \fn uint64_t BIT_STRING_to_uint64(BIT_STRING_t *)
*\brief This function extract at most a 64 bits value from a BIT_STRING_t object, the exact bits number depend on the BIT_STRING_t contents.
*\param[in] pointer to the BIT_STRING_t object.
*\return the extracted value.
*/
static inline uint64_t BIT_STRING_to_uint64(BIT_STRING_t *asn) {
uint64_t result = 0;
int index;
int shift;
DevCheck ((asn->size > 0) && (asn->size <= 8), asn->size, 0, 0);
shift = ((asn->size - 1) * 8) - asn->bits_unused;
for (index = 0; index < (asn->size - 1); index++) {
result |= asn->buf[index] << shift;
shift -= 8;
}
result |= asn->buf[index] >> asn->bits_unused;
return result;
}
#endif /* FILE_ASN1_CONVERSIONS_SEEN */
/*
* 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 Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
*
* 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 <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <inttypes.h>
#include "backtrace.h"
#ifndef ASSERTIONS_H_
#define ASSERTIONS_H_
#define _Assert_Exit_ \
{ \
fprintf(stderr, "\nExiting execution\n"); \
display_backtrace(); \
fflush(stdout); \
fflush(stderr); \
exit(EXIT_FAILURE); \
}
#define _Assert_SegFault_ \
{ \
fprintf(stderr, "\n Will Intentionaly raise SEGFAULT to be catched by GDB!\n"); \
display_backtrace(); \
fflush(stdout); \
fflush(stderr); \
*(int*)0=0; \
exit(EXIT_FAILURE); \
}
#define _Assert_(cOND, aCTION, fORMAT, aRGS...) \
do { \
if (!(cOND)) { \