Commit 8dc01636 authored by Chenyu's avatar Chenyu

nos1 ping is ok and initianluemessage with 4gnas

parent e6acfaca
......@@ -47,6 +47,7 @@
#include "NwGtpv1uMsg.h"
#include "NwGtpv1uPrivate.h"
#include "gtpv1u_eNB_defs.h"
#include "gtpv1u_gNB_defs.h"
#include "PHY/defs_L1_NB_IoT.h"
#include "RRC/LTE/defs_NB_IoT.h"
......@@ -109,6 +110,8 @@ typedef struct {
struct gNB_MAC_INST_s **nrmac;
/// GTPu descriptor
gtpv1u_data_t *gtpv1u_data_g;
/// NR GTPu descriptor
nr_gtpv1u_data_t *nr_gtpv1u_data_g;
/// RU descriptors. These describe what each radio unit is supposed to do and contain the necessary functions for fronthaul interfaces
struct RU_t_s **ru;
/// Mask to indicate fronthaul setup status of RU (hard-limit to 64 RUs)
......
......@@ -54,6 +54,7 @@ typedef enum {
MSC_S1AP_ENB,
MSC_NGAP_GNB,
MSC_GTPU_ENB,
MSC_GTPU_GNB,
MSC_GTPU_SGW,
MSC_S1AP_MME,
MSC_NGAP_AMF,
......
......@@ -30,3 +30,4 @@ MESSAGE_DEF(GTPV1U_ENB_DATA_FORWARDING_IND, MESSAGE_PRIORITY_MED, gtpv1u_enb_dat
MESSAGE_DEF(GTPV1U_ENB_END_MARKER_REQ, MESSAGE_PRIORITY_MED, gtpv1u_enb_end_marker_req_t, Gtpv1uEndMarkerReq)
MESSAGE_DEF(GTPV1U_ENB_END_MARKER_IND, MESSAGE_PRIORITY_MED, gtpv1u_enb_end_marker_ind_t, Gtpv1uEndMarkerInd)
MESSAGE_DEF(GTPV1U_ENB_S1_REQ, MESSAGE_PRIORITY_MED, Gtpv1uS1Req, gtpv1uS1Req)
MESSAGE_DEF(GTPV1U_GNB_NG_REQ, MESSAGE_PRIORITY_MED, Gtpv1uNGReq, gtpv1uNGReq)
......@@ -26,6 +26,7 @@
#define GTPV1U_MAX_BEARERS_PER_UE max_val_LTE_DRB_Identity
#define NR_GTPV1U_MAX_BEARERS_PER_UE max_val_NR_DRB_Identity
#define GTPV1U_ENB_UPDATE_TUNNEL_REQ(mSGpTR) (mSGpTR)->ittiMsg.Gtpv1uUpdateTunnelReq
#define GTPV1U_ENB_UPDATE_TUNNEL_RESP(mSGpTR) (mSGpTR)->ittiMsg.Gtpv1uUpdateTunnelResp
......@@ -39,6 +40,7 @@
#define GTPV1U_ENB_END_MARKER_IND(mSGpTR) (mSGpTR)->ittiMsg.Gtpv1uEndMarkerInd
#define GTPV1U_ENB_S1_REQ(mSGpTR) (mSGpTR)->ittiMsg.gtpv1uS1Req
#define GTPV1U_GNB_NG_REQ(mSGpTR) (mSGpTR)->ittiMsg.gtpv1uNGReq
#define GTPV1U_ALL_TUNNELS_TEID (teid_t)0xFFFFFFFF
......@@ -172,4 +174,25 @@ typedef struct {
tcp_udp_port_t enb_port_for_S1u_S12_S4_up;
} Gtpv1uS1Req;
typedef struct {
in_addr_t gnb_ip_address_for_NGu_up;
tcp_udp_port_t gnb_port_for_NGu_up;
} Gtpv1uNGReq;
typedef struct gtpv1u_gnb_create_tunnel_req_s {
rnti_t rnti;
int num_tunnels;
teid_t upf_NGu_teid[NR_GTPV1U_MAX_BEARERS_PER_UE]; ///< Tunnel Endpoint Identifier
pdusessionid_t pdusession_id[NR_GTPV1U_MAX_BEARERS_PER_UE];
transport_layer_addr_t upf_addr[NR_GTPV1U_MAX_BEARERS_PER_UE];
} gtpv1u_gnb_create_tunnel_req_t;
typedef struct gtpv1u_gnb_create_tunnel_resp_s {
uint8_t status; ///< Status of S1U endpoint creation (Failed = 0xFF or Success = 0x0)
rnti_t rnti;
int num_tunnels;
teid_t gnb_NGu_teid[NR_GTPV1U_MAX_BEARERS_PER_UE]; ///< Tunnel Endpoint Identifier
pdusessionid_t pdusession_id[NR_GTPV1U_MAX_BEARERS_PER_UE];
transport_layer_addr_t gnb_addr;
} gtpv1u_gnb_create_tunnel_resp_t;
#endif /* GTPV1_U_MESSAGES_TYPES_H_ */
......@@ -263,8 +263,8 @@ typedef struct ngap_transport_layer_addr_s {
} while (0)
typedef struct pdusession_level_qos_parameter_s {
uint8_t qci;
uint8_t qfi;
uint64_t fiveQI;
ngap_allocation_retention_priority_t allocation_retention_priority;
} pdusession_level_qos_parameter_t;
......@@ -291,7 +291,7 @@ typedef enum pdusession_qosflow_mapping_ind_e{
}pdusession_qosflow_mapping_ind_t;
typedef struct pdusession_associate_qosflow_s{
uint8_t qci;
uint8_t qfi;
pdusession_qosflow_mapping_ind_t qos_flow_mapping_ind;
}pdusession_associate_qosflow_t;
......@@ -738,10 +738,19 @@ typedef struct ngap_ue_release_command_s {
//-------------------------------------------------------------------------------------------//
// NGAP <-- RRC messages
typedef struct pdusession_release_s {
/* Unique pdusession_id for the UE. */
uint8_t pdusession_id;
} pdusession_release_t;
typedef struct ngap_ue_release_req_s {
uint32_t gNB_ue_ngap_id;
ngap_Cause_t cause;
long cause_value;
uint32_t gNB_ue_ngap_id;
/* Number of pdusession resource in the list */
uint8_t nb_of_pdusessions;
/* list of pdusession resource by RRC layers */
pdusession_release_t pdusessions[NGAP_MAX_PDUSESSION];
ngap_Cause_t cause;
long cause_value;
} ngap_ue_release_req_t, ngap_ue_release_resp_t;
typedef struct ngap_pdusession_modify_req_s {
......@@ -775,11 +784,6 @@ typedef struct ngap_pdusession_modify_resp_s {
pdusession_failed_t pdusessions_failed[NGAP_MAX_PDUSESSION];
} ngap_pdusession_modify_resp_t;
typedef struct pdusession_release_s {
/* Unique pdusession_id for the UE. */
uint8_t pdusession_id;
} pdusession_release_t;
typedef struct ngap_pdusession_release_command_s {
/* AMF UE id */
uint64_t amf_ue_ngap_id:40;
......
......@@ -29,6 +29,7 @@
***************************************************************************/
#include "LTE_asn_constant.h"
#include "NR_asn_constant.h"
#ifndef __PLATFORM_CONSTANTS_H__
# define __PLATFORM_CONSTANTS_H__
......@@ -103,6 +104,7 @@
#define DEFAULT_RAB_ID 1
#define NB_RB_MAX (LTE_maxDRB + 3) /* was 11, now 14, maxDRB comes from asn1_constants.h, + 3 because of 3 SRB, one invisible id 0, then id 1 and 2 */
#define NR_NB_RB_MAX (NR_maxDRB + 3)
#define NB_RB_MBMS_MAX (LTE_maxSessionPerPMCH*LTE_maxServiceCount)
......
......@@ -222,7 +222,7 @@ typedef enum config_action_e {
//-----------------------------------------------------------------------------
typedef uint32_t teid_t; // tunnel endpoint identifier
typedef uint8_t ebi_t; // eps bearer id
typedef uint8_t pdusessionid_t;
//-----------------------------------------------------------------------------
......
......@@ -386,6 +386,7 @@ typedef struct s1ap_register_enb_req_s {
uint8_t nb_mme;
/* List of MME to connect to */
net_ip_address_t mme_ip_address[S1AP_MAX_NB_MME_IP_ADDRESS];
uint16_t mme_port[S1AP_MAX_NB_MME_IP_ADDRESS];
uint8_t broadcast_plmn_num[S1AP_MAX_NB_MME_IP_ADDRESS];
uint8_t broadcast_plmn_index[S1AP_MAX_NB_MME_IP_ADDRESS][PLMN_LIST_MAX_SIZE];
......
......@@ -68,6 +68,7 @@
#include "NR_SDAP-Config.h"
#include "NR_RRCReconfigurationComplete.h"
#include "NR_RRCReconfigurationComplete-IEs.h"
#include "NR_DLInformationTransfer.h"
#if defined(NR_Rel16)
#include "NR_SCS-SpecificCarrier.h"
#include "NR_TDD-UL-DL-ConfigCommon.h"
......@@ -918,8 +919,8 @@ uint8_t do_NR_SA_UECapabilityEnquiry( const protocol_ctxt_t *const ctxt_pP,
}
uint8_t do_NR_RRCConnectionRelease(uint8_t *buffer,
uint8_t Transaction_id) {
uint8_t do_NR_RRCRelease(uint8_t *buffer,
uint8_t Transaction_id) {
asn_enc_rval_t enc_rval;
NR_DL_DCCH_Message_t dl_dcch_msg;
NR_RRCRelease_t *rrcConnectionRelease;
......@@ -927,12 +928,19 @@ uint8_t do_NR_RRCConnectionRelease(uint8_t *buffer,
dl_dcch_msg.message.present = NR_DL_DCCH_MessageType_PR_c1;
dl_dcch_msg.message.choice.c1=CALLOC(1,sizeof(struct NR_DL_DCCH_MessageType__c1));
dl_dcch_msg.message.choice.c1->present = NR_DL_DCCH_MessageType__c1_PR_rrcRelease;
dl_dcch_msg.message.choice.c1->choice.rrcRelease = CALLOC(1, sizeof(struct NR_RRCRelease));
dl_dcch_msg.message.choice.c1->choice.rrcRelease = CALLOC(1, sizeof(NR_RRCRelease_t));
rrcConnectionRelease = dl_dcch_msg.message.choice.c1->choice.rrcRelease;
// RRCConnectionRelease
rrcConnectionRelease->rrc_TransactionIdentifier = Transaction_id;
rrcConnectionRelease->criticalExtensions.present = NR_RRCRelease__criticalExtensions_PR_rrcRelease;
rrcConnectionRelease->criticalExtensions.choice.rrcRelease = NULL;
rrcConnectionRelease->criticalExtensions.choice.rrcRelease = CALLOC(1, sizeof(NR_RRCRelease_IEs_t));
rrcConnectionRelease->criticalExtensions.choice.rrcRelease->deprioritisationReq =
CALLOC(1, sizeof(struct NR_RRCRelease_IEs__deprioritisationReq));
rrcConnectionRelease->criticalExtensions.choice.rrcRelease->deprioritisationReq->deprioritisationType =
NR_RRCRelease_IEs__deprioritisationReq__deprioritisationType_nr;
rrcConnectionRelease->criticalExtensions.choice.rrcRelease->deprioritisationReq->deprioritisationTimer =
NR_RRCRelease_IEs__deprioritisationReq__deprioritisationTimer_min10;
enc_rval = uper_encode_to_buffer(&asn_DEF_NR_DL_DCCH_Message,
NULL,
(void *)&dl_dcch_msg,
......@@ -1260,3 +1268,64 @@ int do_DLInformationTransfer_NR (void * p) {
return 0;
}
//------------------------------------------------------------------------------
uint8_t
do_NR_DLInformationTransfer(
uint8_t Mod_id,
uint8_t **buffer,
uint8_t transaction_id,
uint32_t pdu_length,
uint8_t *pdu_buffer
)
//------------------------------------------------------------------------------
{
ssize_t encoded;
NR_DL_DCCH_Message_t dl_dcch_msg;
memset(&dl_dcch_msg, 0, sizeof(NR_DL_DCCH_Message_t));
dl_dcch_msg.message.present = NR_DL_DCCH_MessageType_PR_c1;
dl_dcch_msg.message.choice.c1 = CALLOC(1, sizeof(struct NR_DL_DCCH_MessageType__c1));
dl_dcch_msg.message.choice.c1->present = NR_DL_DCCH_MessageType__c1_PR_dlInformationTransfer;
dl_dcch_msg.message.choice.c1->choice.dlInformationTransfer = CALLOC(1, sizeof(NR_DLInformationTransfer_t));
dl_dcch_msg.message.choice.c1->choice.dlInformationTransfer->rrc_TransactionIdentifier = transaction_id;
dl_dcch_msg.message.choice.c1->choice.dlInformationTransfer->criticalExtensions.present =
NR_DLInformationTransfer__criticalExtensions_PR_dlInformationTransfer;
dl_dcch_msg.message.choice.c1->choice.dlInformationTransfer->
criticalExtensions.choice.dlInformationTransfer = CALLOC(1, sizeof(NR_DLInformationTransfer_IEs_t));
dl_dcch_msg.message.choice.c1->choice.dlInformationTransfer->
criticalExtensions.choice.dlInformationTransfer->dedicatedNAS_Message = CALLOC(1, sizeof(NR_DedicatedNAS_Message_t));
dl_dcch_msg.message.choice.c1->choice.dlInformationTransfer->
criticalExtensions.choice.dlInformationTransfer->dedicatedNAS_Message->buf = pdu_buffer;
dl_dcch_msg.message.choice.c1->choice.dlInformationTransfer->
criticalExtensions.choice.dlInformationTransfer->dedicatedNAS_Message->size = pdu_length;
encoded = uper_encode_to_new_buffer (&asn_DEF_NR_DL_DCCH_Message, NULL, (void *) &dl_dcch_msg, (void **)buffer);
AssertFatal(encoded > 0,"ASN1 message encoding failed (%s, %lu)!\n",
"DLInformationTransfer", encoded);
LOG_D(NR_RRC,"DLInformationTransfer Encoded %zd bytes\n", encoded);
return encoded;
}
uint8_t do_NR_ULInformationTransfer(uint8_t **buffer, uint32_t pdu_length, uint8_t *pdu_buffer) {
ssize_t encoded;
NR_UL_DCCH_Message_t ul_dcch_msg;
memset(&ul_dcch_msg, 0, sizeof(NR_UL_DCCH_Message_t));
ul_dcch_msg.message.present = NR_UL_DCCH_MessageType_PR_c1;
ul_dcch_msg.message.choice.c1 = CALLOC(1,sizeof(struct NR_UL_DCCH_MessageType__c1));
ul_dcch_msg.message.choice.c1->present = NR_UL_DCCH_MessageType__c1_PR_ulInformationTransfer;
ul_dcch_msg.message.choice.c1->choice.ulInformationTransfer = CALLOC(1,sizeof(struct NR_ULInformationTransfer));
ul_dcch_msg.message.choice.c1->choice.ulInformationTransfer->criticalExtensions.present = NR_ULInformationTransfer__criticalExtensions_PR_ulInformationTransfer;
ul_dcch_msg.message.choice.c1->choice.ulInformationTransfer->criticalExtensions.choice.ulInformationTransfer = CALLOC(1,sizeof(struct NR_ULInformationTransfer_IEs));
struct NR_ULInformationTransfer_IEs *ulInformationTransfer = ul_dcch_msg.message.choice.c1->choice.ulInformationTransfer->criticalExtensions.choice.ulInformationTransfer;
ulInformationTransfer->dedicatedNAS_Message = CALLOC(1,sizeof(NR_DedicatedNAS_Message_t));
ulInformationTransfer->dedicatedNAS_Message->buf = pdu_buffer;
ulInformationTransfer->dedicatedNAS_Message->size = pdu_length;
ulInformationTransfer->lateNonCriticalExtension = NULL;
encoded = uper_encode_to_new_buffer (&asn_DEF_NR_UL_DCCH_Message, NULL, (void *) &ul_dcch_msg, (void **) buffer);
AssertFatal(encoded > 0,"ASN1 message encoding failed (%s, %lu)!\n",
"ULInformationTransfer",encoded);
LOG_D(NR_RRC,"ULInformationTransfer Encoded %zd bytes\n",encoded);
return encoded;
}
......@@ -257,6 +257,21 @@ typedef struct nr_rrc_guami_s {
uint8_t amf_pointer;
} nr_rrc_guami_t;
typedef enum pdu_session_satus_e {
PDU_SESSION_STATUS_NEW,
PDU_SESSION_STATUS_DONE,
PDU_SESSION_STATUS_ESTABLISHED,
PDU_SESSION_STATUS_FAILED,
} pdu_session_status_t;
typedef struct pdu_session_param_s {
pdusession_t param;
uint8_t status;
uint8_t xid; // transaction_id
ngap_Cause_t cause;
uint8_t cause_value;
} __attribute__ ((__packed__)) pdu_session_param_t;
typedef struct gNB_RRC_UE_s {
uint8_t primaryCC_id;
LTE_SCellToAddMod_r10_t sCell_config[2];
......@@ -325,12 +340,16 @@ typedef struct gNB_RRC_UE_s {
uint8_t setup_e_rabs;
/* Number of e_rab to be setup in the list */
uint8_t nb_of_e_rabs;
/* Total number of pdu session already setup in the list */
uint8_t setup_pdu_sessions;
/* Number of pdu session to be setup in the list */
uint8_t nb_of_pdusessions;
/* Number of e_rab to be modified in the list */
uint8_t nb_of_modify_e_rabs;
uint8_t nb_of_failed_e_rabs;
e_rab_param_t modify_e_rab[NB_RB_MAX];//[S1AP_MAX_E_RAB];
/* list of e_rab to be setup by RRC layers */
e_rab_param_t e_rab[NB_RB_MAX];//[S1AP_MAX_E_RAB];
pdu_session_param_t pdusession[NR_NB_RB_MAX];//[NGAP_MAX_PDU_SESSION];
//release e_rabs
uint8_t nb_release_of_e_rabs;
e_rab_failed_t e_rabs_release_failed[S1AP_MAX_E_RAB];
......@@ -338,12 +357,15 @@ typedef struct gNB_RRC_UE_s {
uint32_t gnb_gtp_teid[S1AP_MAX_E_RAB];
transport_layer_addr_t gnb_gtp_addrs[S1AP_MAX_E_RAB];
rb_id_t gnb_gtp_ebi[S1AP_MAX_E_RAB];
rb_id_t gnb_gtp_psi[S1AP_MAX_E_RAB];
uint32_t ul_failure_timer;
uint32_t ue_release_timer;
uint32_t ue_release_timer_thres;
uint32_t ue_release_timer_s1;
uint32_t ue_release_timer_thres_s1;
uint32_t ue_release_timer_ng;
uint32_t ue_release_timer_thres_ng;
uint32_t ue_release_timer_rrc;
uint32_t ue_release_timer_thres_rrc;
uint32_t ue_reestablishment_timer;
......@@ -424,6 +446,8 @@ typedef struct gNB_RRC_INST_s {
int Nb_ue;
hash_table_t *initial_id2_s1ap_ids; // key is content is rrc_ue_s1ap_ids_t
hash_table_t *s1ap_id2_s1ap_ids ; // key is content is rrc_ue_s1ap_ids_t
hash_table_t *initial_id2_ngap_ids;
hash_table_t *ngap_id2_ngap_ids ;
// other PLMN parameters
/// Mobile country code
......@@ -444,7 +468,6 @@ typedef struct gNB_RRC_INST_s {
} gNB_RRC_INST;
#include "nr_rrc_proto.h" //should be put here otherwise compilation error
#endif
......
......@@ -295,6 +295,8 @@ char openair_rrc_gNB_configuration(const module_id_t gnb_mod_idP, gNB_RrcConfigu
RB_INIT(&rrc->rrc_ue_head);
rrc->initial_id2_s1ap_ids = hashtable_create (NUMBER_OF_UE_MAX * 2, NULL, NULL);
rrc->s1ap_id2_s1ap_ids = hashtable_create (NUMBER_OF_UE_MAX * 2, NULL, NULL);
rrc->initial_id2_ngap_ids = hashtable_create (NUMBER_OF_UE_MAX * 2, NULL, NULL);
rrc->ngap_id2_ngap_ids = hashtable_create (NUMBER_OF_UE_MAX * 2, NULL, NULL);
rrc->carrier.servingcellconfigcommon = configuration->scc;
rrc->carrier.ssb_SubcarrierOffset = configuration->ssb_SubcarrierOffset;
rrc->carrier.pdsch_AntennaPorts = configuration->pdsch_AntennaPorts;
......@@ -1105,6 +1107,34 @@ rrc_gNB_decode_dcch(
ue_context_p->ue_context.ue_release_timer = 0;
break;
case NR_UL_DCCH_MessageType__c1_PR_ulInformationTransfer:
LOG_I(NR_RRC,"Recived RRC GNB UL Information Transfer \n");
if(!ue_context_p) {
LOG_I(NR_RRC, "Processing ulInformationTransfer UE %x, ue_context_p is NULL\n", ctxt_pP->rnti);
break;
}
LOG_D(NR_RRC,"[MSG] RRC UL Information Transfer \n");
LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)Rx_sdu,sdu_sizeP,
"[MSG] RRC UL Information Transfer \n");
MSC_LOG_RX_MESSAGE(
MSC_RRC_GNB,
MSC_RRC_UE,
Rx_sdu,
sdu_sizeP,
MSC_AS_TIME_FMT" ulInformationTransfer UE %x size %u",
MSC_AS_TIME_ARGS(ctxt_pP),
ue_context_p->ue_context.rnti,
sdu_sizeP);
if (AMF_MODE_ENABLED == 1) {
rrc_gNB_send_NGAP_UPLINK_NAS(ctxt_pP,
ue_context_p,
ul_dcch_msg);
}
break;
case NR_UL_DCCH_MessageType__c1_PR_securityModeComplete:
// to avoid segmentation fault
if(!ue_context_p) {
......@@ -1130,6 +1160,31 @@ rrc_gNB_decode_dcch(
rrc_gNB_generate_UECapabilityEnquiry(ctxt_pP, ue_context_p);
//rrc_gNB_generate_defaultRRCReconfiguration(ctxt_pP, ue_context_p);
break;
case NR_UL_DCCH_MessageType__c1_PR_securityModeFailure:
LOG_DUMPMSG(NR_RRC,DEBUG_RRC,(char *)Rx_sdu,sdu_sizeP,
"[MSG] NR RRC Security Mode Failure\n");
MSC_LOG_RX_MESSAGE(
MSC_RRC_GNB,
MSC_RRC_UE,
Rx_sdu,
sdu_sizeP,
MSC_AS_TIME_FMT" securityModeFailure UE %x size %u",
MSC_AS_TIME_ARGS(ctxt_pP),
ue_context_p->ue_context.rnti,
sdu_sizeP);
LOG_W(NR_RRC,
PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
"(securityModeFailure) ---> RRC_gNB\n",
PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
DCCH,
sdu_sizeP);
if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
xer_fprint(stdout, &asn_DEF_NR_UL_DCCH_Message, (void *)ul_dcch_msg);
}
rrc_gNB_generate_UECapabilityEnquiry(ctxt_pP, ue_context_p);
break;
case NR_UL_DCCH_MessageType__c1_PR_ueCapabilityInformation:
if(!ue_context_p) {
......@@ -1235,10 +1290,14 @@ rrc_gNB_decode_dcch(
if(eutra_index == -1)
break;
}
rrc_gNB_generate_defaultRRCReconfiguration(ctxt_pP, ue_context_p);
break;
}
if (AMF_MODE_ENABLED == 1) {
rrc_gNB_send_NGAP_UE_CAPABILITIES_IND(ctxt_pP,
ue_context_p,
ul_dcch_msg);
}
rrc_gNB_generate_defaultRRCReconfiguration(ctxt_pP, ue_context_p);
break;
default:
break;
......@@ -1356,6 +1415,14 @@ void *rrc_gnb_task(void *args_p) {
NR_RRC_DCCH_DATA_IND(msg_p).sdu_size);
break;
case NGAP_DOWNLINK_NAS:
rrc_gNB_process_NGAP_DOWNLINK_NAS(msg_p, msg_name_p, instance, &rrc_gNB_mui);
break;
case NGAP_PDUSESSION_SETUP_REQ:
rrc_gNB_process_NGAP_PDUSESSION_SETUP_REQ(msg_p, msg_name_p, instance);
break;
/*
#if defined(ENABLE_USE_MME)
......@@ -1444,6 +1511,14 @@ void *rrc_gnb_task(void *args_p) {
/* nothing to do? */
break;
case NGAP_UE_CONTEXT_RELEASE_REQ:
rrc_gNB_process_NGAP_UE_CONTEXT_RELEASE_REQ(msg_p, msg_name_p, instance);
break;
case NGAP_UE_CONTEXT_RELEASE_COMMAND:
rrc_gNB_process_NGAP_UE_CONTEXT_RELEASE_COMMAND(msg_p, msg_name_p, instance);
break;
default:
LOG_E(NR_RRC, "[gNB %d] Received unexpected message %s\n", instance, msg_name_p);
break;
......@@ -1582,9 +1657,9 @@ rrc_gNB_generate_UECapabilityEnquiry(
* If received, UE should switch to RRC_IDLE mode.
*/
void
rrc_gNB_generate_RRCConnectionRelease(
rrc_gNB_generate_RRCRelease(
const protocol_ctxt_t *const ctxt_pP,
rrc_gNB_ue_context_t *const ue_context_pP
rrc_gNB_ue_context_t *const ue_context_pP
)
//-----------------------------------------------------------------------------
{
......@@ -1593,16 +1668,16 @@ rrc_gNB_generate_RRCConnectionRelease(
memset(buffer, 0, RRC_BUF_SIZE);
size = do_NR_RRCConnectionRelease(buffer,rrc_gNB_get_next_transaction_identifier(ctxt_pP->module_id));
size = do_NR_RRCRelease(buffer,rrc_gNB_get_next_transaction_identifier(ctxt_pP->module_id));
ue_context_pP->ue_context.ue_reestablishment_timer = 0;
ue_context_pP->ue_context.ue_release_timer = 0;
LOG_I(NR_RRC,
PROTOCOL_RRC_CTXT_UE_FMT" Logical Channel DL-DCCH, Generate RRCConnectionRelease (bytes %d)\n",
PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
PROTOCOL_NR_RRC_CTXT_UE_FMT" Logical Channel DL-DCCH, Generate RRCRelease (bytes %d)\n",
PROTOCOL_NR_RRC_CTXT_UE_ARGS(ctxt_pP),
size);
LOG_D(NR_RRC,
PROTOCOL_RRC_CTXT_UE_FMT" --- PDCP_DATA_REQ/%d Bytes (rrcConnectionRelease MUI %d) --->[PDCP][RB %u]\n",
PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
PROTOCOL_NR_RRC_CTXT_UE_FMT" --- PDCP_DATA_REQ/%d Bytes (rrcRelease MUI %d) --->[PDCP][RB %u]\n",
PROTOCOL_NR_RRC_CTXT_UE_ARGS(ctxt_pP),
size,
rrc_gNB_mui,
DCCH);
......@@ -1611,14 +1686,25 @@ rrc_gNB_generate_RRCConnectionRelease(
MSC_RRC_UE,
buffer,
size,
MSC_AS_TIME_FMT" LTE_RRCConnectionRelease UE %x MUI %d size %u",
MSC_AS_TIME_FMT" NR_RRCRelease UE %x MUI %d size %u",
MSC_AS_TIME_ARGS(ctxt_pP),
ue_context_pP->ue_context.rnti,
rrc_gNB_mui,
size);
#ifdef ITTI_SIM
MessageDef *message_p;
uint8_t *message_buffer;
message_buffer = itti_malloc (TASK_RRC_GNB, TASK_RRC_UE_SIM, size);
memcpy (message_buffer, buffer, size);
message_p = itti_alloc_new_message (TASK_RRC_GNB, GNB_RRC_DCCH_DATA_IND);
GNB_RRC_DCCH_DATA_IND (message_p).rbid = DCCH;
GNB_RRC_DCCH_DATA_IND (message_p).sdu = message_buffer;
GNB_RRC_DCCH_DATA_IND (message_p).size = size;
itti_send_msg_to_task (TASK_RRC_UE_SIM, ctxt_pP->instance, message_p);
#else
if (NODE_IS_CU(RC.rrc[ctxt_pP->module_id]->node_type)) {
MessageDef *m = itti_alloc_new_message(TASK_RRC_ENB, F1AP_UE_CONTEXT_RELEASE_CMD);
MessageDef *m = itti_alloc_new_message(TASK_RRC_GNB, F1AP_UE_CONTEXT_RELEASE_CMD);
F1AP_UE_CONTEXT_RELEASE_CMD(m).rnti = ctxt_pP->rnti;
F1AP_UE_CONTEXT_RELEASE_CMD(m).cause = F1AP_CAUSE_RADIO_NETWORK;
F1AP_UE_CONTEXT_RELEASE_CMD(m).cause_value = 10; // 10 = F1AP_CauseRadioNetwork_normal_release
......@@ -1634,6 +1720,7 @@ rrc_gNB_generate_RRCConnectionRelease(
buffer,
PDCP_TRANSMISSION_MODE_CONTROL);
}
#endif
}
void nr_rrc_trigger(protocol_ctxt_t *ctxt, int CC_id, int frame, int subframe)
{
......
......@@ -92,3 +92,52 @@ rrc_gNB_process_GTPV1U_CREATE_TUNNEL_RESP(
return -1;
}
}
int
nr_rrc_gNB_process_GTPV1U_CREATE_TUNNEL_RESP(
const protocol_ctxt_t *const ctxt_pP,
const gtpv1u_gnb_create_tunnel_resp_t *const create_tunnel_resp_pP,
uint8_t *inde_list
) {
rnti_t rnti;
int i;
struct rrc_gNB_ue_context_s *ue_context_p = NULL;
if (create_tunnel_resp_pP) {
LOG_D(NR_RRC, PROTOCOL_NR_RRC_CTXT_UE_FMT" RX CREATE_TUNNEL_RESP num tunnels %u \n",
PROTOCOL_NR_RRC_CTXT_UE_ARGS(ctxt_pP),
create_tunnel_resp_pP->num_tunnels);
rnti = create_tunnel_resp_pP->rnti;
ue_context_p = rrc_gNB_get_ue_context(
RC.nrrrc[ctxt_pP->module_id],
ctxt_pP->rnti);
for (i = 0; i < create_tunnel_resp_pP->num_tunnels; i++) {
ue_context_p->ue_context.gnb_gtp_teid[inde_list[i]] = create_tunnel_resp_pP->gnb_NGu_teid[i];
ue_context_p->ue_context.gnb_gtp_addrs[inde_list[i]] = create_tunnel_resp_pP->gnb_addr;
ue_context_p->ue_context.gnb_gtp_psi[inde_list[i]] = create_tunnel_resp_pP->pdusession_id[i];
LOG_I(NR_RRC, PROTOCOL_NR_RRC_CTXT_UE_FMT" nr_rrc_gNB_process_GTPV1U_CREATE_TUNNEL_RESP tunnel (%u, %u) bearer UE context index %u, msg index %u, id %u, gtp addr len %d \n",
PROTOCOL_NR_RRC_CTXT_UE_ARGS(ctxt_pP),
create_tunnel_resp_pP->gnb_NGu_teid[i],
ue_context_p->ue_context.gnb_gtp_teid[inde_list[i]],
inde_list[i],
i,
create_tunnel_resp_pP->pdusession_id[i],
create_tunnel_resp_pP->gnb_addr.length);
}
MSC_LOG_RX_MESSAGE(
MSC_RRC_GNB,
MSC_GTPU_GNB,
NULL,0,
MSC_AS_TIME_FMT" CREATE_TUNNEL_RESP RNTI %"PRIx16" ntuns %u psid %u enb-s1u teid %u",
0,0,rnti,
create_tunnel_resp_pP->num_tunnels,
ue_context_p->ue_context.gnb_gtp_psi[0],
ue_context_p->ue_context.gnb_gtp_teid[0]);
(void)rnti; /* avoid gcc warning "set but not used" */
return 0;
} else {
return -1;
}
}
......@@ -37,3 +37,12 @@ rrc_gNB_process_GTPV1U_CREATE_TUNNEL_RESP(
const gtpv1u_enb_create_tunnel_resp_t *const create_tunnel_resp_pP,
uint8_t *inde_list
);
int
nr_rrc_gNB_process_GTPV1U_CREATE_TUNNEL_RESP(
const protocol_ctxt_t *const ctxt_pP,
const gtpv1u_gnb_create_tunnel_resp_t *const create_tunnel_resp_pP,
uint8_t *inde_list
);
#endif
......@@ -43,17 +43,38 @@
#include "msc.h"
#include "gtpv1u_eNB_task.h"
#include "gtpv1u_gNB_task.h"
#include "RRC/LTE/rrc_eNB_GTPV1U.h"
#include "RRC/NR/rrc_gNB_GTPV1U.h"
#include "S1AP_NAS-PDU.h"
#include "executables/softmodem-common.h"
#include "UTIL/OSA/osa_defs.h"
#include "ngap_gNB_defs.h"
#include "ngap_gNB_ue_context.h"
#include "ngap_gNB_management_procedures.h"
#include "NR_ULInformationTransfer.h"
#include "RRC/NR/MESSAGES/asn1_msg.h"
#include "NR_UERadioAccessCapabilityInformation.h"
#include "NR_UE-CapabilityRAT-ContainerList.h"
extern RAN_CONTEXT_t RC;
/* Value to indicate an invalid UE initial id */
static const uint16_t UE_INITIAL_ID_INVALID = 0;
/* Masks for NGAP Encryption algorithms, NEA0 is always supported (not coded) */
static const uint16_t NGAP_ENCRYPTION_NEA1_MASK = 0x8000;
static const uint16_t NGAP_ENCRYPTION_NEA2_MASK = 0x4000;
static const uint16_t NGAP_ENCRYPTION_NEA3_MASK = 0x2000;
/* Masks for NGAP Integrity algorithms, NIA0 is always supported (not coded) */
static const uint16_t NGAP_INTEGRITY_NIA1_MASK = 0x8000;
static const uint16_t NGAP_INTEGRITY_NIA2_MASK = 0x4000;
static const uint16_t NGAP_INTEGRITY_NIA3_MASK = 0x2000;
#define INTEGRITY_ALGORITHM_NONE NR_IntegrityProtAlgorithm_nia0
/*! \fn uint16_t get_next_ue_initial_id(uint8_t mod_id)
*\brief provide an UE initial ID for NGAP initial communication.
*\param mod_id Instance ID of gNB.
......@@ -90,9 +111,132 @@ rrc_gNB_NGAP_get_ue_ids(
)
//------------------------------------------------------------------------------
{
rrc_ue_ngap_ids_t *result = NULL;
rrc_ue_ngap_ids_t *result = NULL;
rrc_ue_ngap_ids_t *result2 = NULL;
/*****************************/
instance_t instance = 0;
ngap_gNB_instance_t *ngap_gNB_instance_p = NULL;
ngap_gNB_ue_context_t *ue_desc_p = NULL;
rrc_gNB_ue_context_t *ue_context_p = NULL;
/*****************************/
hashtable_rc_t h_rc;
if (ue_initial_id != UE_INITIAL_ID_INVALID) {
h_rc = hashtable_get(rrc_instance_pP->initial_id2_ngap_ids, (hash_key_t)ue_initial_id, (void **)&result);
if (h_rc == HASH_TABLE_OK) {
if (gNB_ue_ngap_idP > 0) {
h_rc = hashtable_get(rrc_instance_pP->ngap_id2_ngap_ids, (hash_key_t)gNB_ue_ngap_idP, (void **)&result2);
if (h_rc != HASH_TABLE_OK) { // this case is equivalent to associate gNB_ue_ngap_idP and ue_initial_id
result2 = malloc(sizeof(*result2));
if (NULL != result2) {
*result2 = *result;
result2->gNB_ue_ngap_id = gNB_ue_ngap_idP;
result->gNB_ue_ngap_id = gNB_ue_ngap_idP;
h_rc = hashtable_insert(rrc_instance_pP->ngap_id2_ngap_ids, (hash_key_t)gNB_ue_ngap_idP, result2);
if (h_rc != HASH_TABLE_OK) {
LOG_E(NGAP, "[gNB %ld] Error while hashtable_insert in ngap_id2_ngap_ids gNB_ue_ngap_idP %"PRIu32"\n",
rrc_instance_pP - RC.nrrrc[0],
gNB_ue_ngap_idP);
}
}
} else { // here we should check that the association was done correctly
if ((result->ue_initial_id != result2->ue_initial_id) || (result->gNB_ue_ngap_id != result2->gNB_ue_ngap_id)) {
LOG_E(NGAP, "[gNB %ld] Error while hashtable_get, two rrc_ue_ngap_ids_t that should be equal, are not:\n \
ue_initial_id 1 = %"PRIu16",\n \
ue_initial_id 2 = %"PRIu16",\n \
gNB_ue_ngap_idP 1 = %"PRIu32",\n \
gNB_ue_ngap_idP 2 = %"PRIu32"\n",
rrc_instance_pP - RC.nrrrc[0],
result->ue_initial_id,
result2->ue_initial_id,
result->gNB_ue_ngap_id,
result2->gNB_ue_ngap_id);
// Still return *result
}
}
} // end if if (gNB_ue_ngap_idP > 0)
} else { // end if (h_rc == HASH_TABLE_OK)
LOG_E(NGAP, "[gNB %ld] In hashtable_get, couldn't find in initial_id2_ngap_ids ue_initial_id %"PRIu16"\n",
rrc_instance_pP - RC.nrrrc[0],
ue_initial_id);
return NULL;
/*
* At the moment this is written, this case shouldn't (cannot) happen and is equivalent to an error.
* One could try to find the struct instance based on ngap_id2_ngap_ids and gNB_ue_ngap_idP (if > 0),
* but this behavior is not expected at the moment.
*/
} // end else (h_rc != HASH_TABLE_OK)
} else { // end if (ue_initial_id != UE_INITIAL_ID_INVALID)
if (gNB_ue_ngap_idP > 0) {
h_rc = hashtable_get(rrc_instance_pP->ngap_id2_ngap_ids, (hash_key_t)gNB_ue_ngap_idP, (void **)&result);
if (h_rc != HASH_TABLE_OK) {
/*
* This case is uncommon, but can happen when:
* -> if the first NAS message was a Detach Request (non exhaustiv), the UE RRC context exist
* but is not associated with gNB_ue_ngap_id
* -> ... (?)
*/
LOG_E(NGAP, "[gNB %ld] In hashtable_get, couldn't find in ngap_id2_ngap_ids gNB_ue_ngap_idP %"PRIu32", trying to find it through NGAP context\n",
rrc_instance_pP - RC.nrrrc[0],
gNB_ue_ngap_idP);
instance = GNB_MODULE_ID_TO_INSTANCE(rrc_instance_pP - RC.nrrrc[0]); // get gNB instance
ngap_gNB_instance_p = ngap_gNB_get_instance(instance); // get ngap_gNB_instance
if (ngap_gNB_instance_p != NULL) {
ue_desc_p = ngap_gNB_get_ue_context(ngap_gNB_instance_p, gNB_ue_ngap_idP); // get s1ap_eNB_ue_context
} else {
LOG_E(NGAP, "[gNB instance %d] Couldn't find the gNB NGAP context\n",
instance);
return NULL;
}
if (ue_desc_p != NULL) {
struct ngap_gNB_ue_context_s *ngap_ue_context_p = NULL;
if ((ngap_ue_context_p = RB_REMOVE(ngap_ue_map, &ngap_gNB_instance_p->ngap_ue_head, ue_desc_p)) != NULL) {
LOG_E(NR_RRC, "Removed UE context gNB_ue_ngap_id %u\n", ngap_ue_context_p->gNB_ue_ngap_id);
ngap_gNB_free_ue_context(ngap_ue_context_p);
} else {
LOG_E(NR_RRC, "Removing UE context gNB_ue_ngap_id %u: did not find context\n",ue_desc_p->gNB_ue_ngap_id);
}
return NULL; //skip the operation below to avoid loop
result = rrc_gNB_NGAP_get_ue_ids(rrc_instance_pP, ue_desc_p->ue_initial_id, gNB_ue_ngap_idP);
if (ue_desc_p->ue_initial_id != UE_INITIAL_ID_INVALID) {
result = rrc_gNB_NGAP_get_ue_ids(rrc_instance_pP, ue_desc_p->ue_initial_id, gNB_ue_ngap_idP);
/* TODO */
if (result != NULL) {
ue_context_p = rrc_gNB_get_ue_context(RC.nrrrc[GNB_INSTANCE_TO_MODULE_ID(instance)], result->ue_rnti);
if ((ue_context_p != NULL) && (ue_context_p->ue_context.gNB_ue_ngap_id == 0)) {
ue_context_p->ue_context.gNB_ue_ngap_id = gNB_ue_ngap_idP;
} else {
LOG_E(NR_RRC, "[gNB %ld] Incoherence between RRC context and NGAP context (%d != %d) for UE RNTI %d or UE RRC context doesn't exist\n",
rrc_instance_pP - RC.nrrrc[0],
(ue_context_p==NULL)?99999:ue_context_p->ue_context.gNB_ue_ngap_id,
gNB_ue_ngap_idP,
result->ue_rnti);
}
}
} else {
LOG_E(NGAP, "[gNB %ld] NGAP context found but ue_initial_id is invalid (0)\n", rrc_instance_pP - RC.nrrrc[0]);
return NULL;
}
} else {
LOG_E(NGAP, "[gNB %ld] In hashtable_get, couldn't find in ngap_id2_ngap_ids gNB_ue_ngap_idP %"PRIu32", because ue_initial_id is invalid in NGAP context\n",
rrc_instance_pP - RC.nrrrc[0],
gNB_ue_ngap_idP);
return NULL;
}
} // end if (h_rc != HASH_TABLE_OK)
} // end if (gNB_ue_ngap_idP > 0)
} // end else (ue_initial_id == UE_INITIAL_ID_INVALID)
return result;
}
......@@ -116,6 +260,35 @@ rrc_gNB_get_ue_context_from_ngap_ids(
return NULL;
}
/*! \fn void process_gNB_security_key (const protocol_ctxt_t* const ctxt_pP, eNB_RRC_UE_t * const ue_context_pP, uint8_t *security_key)
*\brief save security key.
*\param ctxt_pP Running context.
*\param ue_context_pP UE context.
*\param security_key_pP The security key received from NGAP.
*/
//------------------------------------------------------------------------------
void process_gNB_security_key (
const protocol_ctxt_t *const ctxt_pP,
rrc_gNB_ue_context_t *const ue_context_pP,
uint8_t *security_key_pP
)
//------------------------------------------------------------------------------
{
char ascii_buffer[65];
uint8_t i;
/* Saves the security key */
memcpy (ue_context_pP->ue_context.kgnb, security_key_pP, SECURITY_KEY_LENGTH);
memset (ue_context_pP->ue_context.nh, 0, SECURITY_KEY_LENGTH);
ue_context_pP->ue_context.nh_ncc = -1;
for (i = 0; i < 32; i++) {
sprintf(&ascii_buffer[2 * i], "%02X", ue_context_pP->ue_context.kgnb[i]);
}
ascii_buffer[2 * i] = '\0';
LOG_I(NR_RRC, "[gNB %d][UE %x] Saved security key %s\n", ctxt_pP->module_id, ue_context_pP->ue_context.rnti, ascii_buffer);
}
//------------------------------------------------------------------------------
void
nr_rrc_pdcp_config_security(
......@@ -136,19 +309,19 @@ nr_rrc_pdcp_config_security(
hash_key_t key;
#ifndef PHYSIM
/* Derive the keys from kgnb */
if (SRB_configList != NULL) {
derive_key_up_enc(ue_context_pP->ue_context.ciphering_algorithm,
ue_context_pP->ue_context.kgnb,
&kUPenc);
}
/* Derive the keys from kgnb */
if (SRB_configList != NULL) {
nr_derive_key_up_enc(ue_context_pP->ue_context.ciphering_algorithm,
ue_context_pP->ue_context.kgnb,
&kUPenc);
}
derive_key_rrc_enc(ue_context_pP->ue_context.ciphering_algorithm,
ue_context_pP->ue_context.kgnb,
&kRRCenc);
derive_key_rrc_int(ue_context_pP->ue_context.integrity_algorithm,
ue_context_pP->ue_context.kgnb,
&kRRCint);
nr_derive_key_rrc_enc(ue_context_pP->ue_context.ciphering_algorithm,
ue_context_pP->ue_context.kgnb,
&kRRCenc);
nr_derive_key_rrc_int(ue_context_pP->ue_context.integrity_algorithm,
ue_context_pP->ue_context.kgnb,
&kRRCint);
#endif
if (!IS_SOFTMODEM_IQPLAYER) {
SET_LOG_DUMP(DEBUG_SECURITY) ;
......@@ -200,109 +373,110 @@ rrc_gNB_send_NGAP_NAS_FIRST_REQ(
)
//------------------------------------------------------------------------------
{
// gNB_RRC_INST *rrc = RC.nrrrc[ctxt_pP->module_id];
MessageDef *message_p = NULL;
rrc_ue_ngap_ids_t *rrc_ue_ngap_ids_p = NULL;
// hashtable_rc_t h_rc;
message_p = itti_alloc_new_message(TASK_RRC_GNB, NGAP_NAS_FIRST_REQ);
memset(&message_p->ittiMsg.ngap_nas_first_req, 0, sizeof(ngap_nas_first_req_t));
ue_context_pP->ue_context.ue_initial_id = get_next_ue_initial_id(ctxt_pP->module_id);
NGAP_NAS_FIRST_REQ(message_p).ue_initial_id = ue_context_pP->ue_context.ue_initial_id;
rrc_ue_ngap_ids_p = malloc(sizeof(rrc_ue_ngap_ids_t));
rrc_ue_ngap_ids_p->ue_initial_id = ue_context_pP->ue_context.ue_initial_id;
rrc_ue_ngap_ids_p->gNB_ue_ngap_id = UE_INITIAL_ID_INVALID;
rrc_ue_ngap_ids_p->ue_rnti = ctxt_pP->rnti;
// h_rc = hashtable_insert(RC.nrrrc[ctxt_pP->module_id]->initial_id2_s1ap_ids,
// (hash_key_t)ue_context_pP->ue_context.ue_initial_id,
// rrc_ue_s1ap_ids_p);
// if (h_rc != HASH_TABLE_OK) {
// LOG_E(S1AP, "[eNB %d] Error while hashtable_insert in initial_id2_s1ap_ids ue_initial_id %u\n",
// ctxt_pP->module_id,
// ue_context_pP->ue_context.ue_initial_id);
// }
/* Assume that cause is coded in the same way in RRC and NGap, just check that the value is in NGap range */
AssertFatal(ue_context_pP->ue_context.establishment_cause < NGAP_RRC_CAUSE_LAST,
"Establishment cause invalid (%jd/%d) for gNB %d!",
ue_context_pP->ue_context.establishment_cause,
NGAP_RRC_CAUSE_LAST,
ctxt_pP->module_id);
NGAP_NAS_FIRST_REQ(message_p).establishment_cause = ue_context_pP->ue_context.establishment_cause;
/* Forward NAS message */
NGAP_NAS_FIRST_REQ(message_p).nas_pdu.buffer = rrcSetupComplete->dedicatedNAS_Message.buf;
NGAP_NAS_FIRST_REQ(message_p).nas_pdu.length = rrcSetupComplete->dedicatedNAS_Message.size;
// extract_imsi(NGAP_NAS_FIRST_REQ (message_p).nas_pdu.buffer,
// NGAP_NAS_FIRST_REQ (message_p).nas_pdu.length,
// ue_context_pP);
/* Fill UE identities with available information */
NGAP_NAS_FIRST_REQ(message_p).ue_identity.presenceMask = NGAP_UE_IDENTITIES_NONE;
/* Fill s-TMSI */
NGAP_NAS_FIRST_REQ(message_p).ue_identity.s_tmsi.amf_set_id = ue_context_pP->ue_context.Initialue_identity_5g_s_TMSI.amf_set_id;
NGAP_NAS_FIRST_REQ(message_p).ue_identity.s_tmsi.amf_pointer = ue_context_pP->ue_context.Initialue_identity_5g_s_TMSI.amf_pointer;
NGAP_NAS_FIRST_REQ(message_p).ue_identity.s_tmsi.m_tmsi = ue_context_pP->ue_context.Initialue_identity_5g_s_TMSI.fiveg_tmsi;
/* selected_plmn_identity: IE is 1-based, convert to 0-based (C array) */
int selected_plmn_identity = rrcSetupComplete->selectedPLMN_Identity - 1;
NGAP_NAS_FIRST_REQ(message_p).selected_plmn_identity = selected_plmn_identity;
if (rrcSetupComplete->registeredAMF != NULL) {
NR_RegisteredAMF_t *r_amf = rrcSetupComplete->registeredAMF;
NGAP_NAS_FIRST_REQ(message_p).ue_identity.presenceMask |= NGAP_UE_IDENTITIES_guami;
if (r_amf->plmn_Identity != NULL) {
if ((r_amf->plmn_Identity->mcc != NULL) && (r_amf->plmn_Identity->mcc->list.count > 0)) {
/* Use first indicated PLMN MCC if it is defined */
NGAP_NAS_FIRST_REQ(message_p).ue_identity.guami.mcc = *r_amf->plmn_Identity->mcc->list.array[selected_plmn_identity];
LOG_I(NGAP, "[gNB %d] Build NGAP_NAS_FIRST_REQ adding in s_TMSI: GUMMEI MCC %u ue %x\n",
ctxt_pP->module_id,
NGAP_NAS_FIRST_REQ (message_p).ue_identity.guami.mcc,
ue_context_pP->ue_context.rnti);
}
// gNB_RRC_INST *rrc = RC.nrrrc[ctxt_pP->module_id];
MessageDef *message_p = NULL;
rrc_ue_ngap_ids_t *rrc_ue_ngap_ids_p = NULL;
hashtable_rc_t h_rc;
message_p = itti_alloc_new_message(TASK_RRC_GNB, NGAP_NAS_FIRST_REQ);
memset(&message_p->ittiMsg.ngap_nas_first_req, 0, sizeof(ngap_nas_first_req_t));
ue_context_pP->ue_context.ue_initial_id = get_next_ue_initial_id(ctxt_pP->module_id);
NGAP_NAS_FIRST_REQ(message_p).ue_initial_id = ue_context_pP->ue_context.ue_initial_id;
rrc_ue_ngap_ids_p = malloc(sizeof(rrc_ue_ngap_ids_t));
rrc_ue_ngap_ids_p->ue_initial_id = ue_context_pP->ue_context.ue_initial_id;
rrc_ue_ngap_ids_p->gNB_ue_ngap_id = UE_INITIAL_ID_INVALID;
rrc_ue_ngap_ids_p->ue_rnti = ctxt_pP->rnti;
if (r_amf->plmn_Identity->mnc.list.count > 0) {
/* Use first indicated PLMN MNC if it is defined */
NGAP_NAS_FIRST_REQ(message_p).ue_identity.guami.mnc = *r_amf->plmn_Identity->mnc.list.array[selected_plmn_identity];
LOG_I(NGAP, "[gNB %d] Build NGAP_NAS_FIRST_REQ adding in s_TMSI: GUMMEI MNC %u ue %x\n",
h_rc = hashtable_insert(RC.nrrrc[ctxt_pP->module_id]->initial_id2_ngap_ids,
(hash_key_t)ue_context_pP->ue_context.ue_initial_id,
rrc_ue_ngap_ids_p);
if (h_rc != HASH_TABLE_OK) {
LOG_E(NGAP, "[gNB %d] Error while hashtable_insert in initial_id2_ngap_ids ue_initial_id %u\n",
ctxt_pP->module_id,
NGAP_NAS_FIRST_REQ (message_p).ue_identity.guami.mnc,
ue_context_pP->ue_context.rnti);
}
} else {
/* TODO */
ue_context_pP->ue_context.ue_initial_id);
}
/* Assume that cause is coded in the same way in RRC and NGap, just check that the value is in NGap range */
AssertFatal(ue_context_pP->ue_context.establishment_cause < NGAP_RRC_CAUSE_LAST,
"Establishment cause invalid (%jd/%d) for gNB %d!",
ue_context_pP->ue_context.establishment_cause,
NGAP_RRC_CAUSE_LAST,
ctxt_pP->module_id);
NGAP_NAS_FIRST_REQ(message_p).establishment_cause = ue_context_pP->ue_context.establishment_cause;
/* Forward NAS message */
NGAP_NAS_FIRST_REQ(message_p).nas_pdu.buffer = rrcSetupComplete->dedicatedNAS_Message.buf;
NGAP_NAS_FIRST_REQ(message_p).nas_pdu.length = rrcSetupComplete->dedicatedNAS_Message.size;
// extract_imsi(NGAP_NAS_FIRST_REQ (message_p).nas_pdu.buffer,
// NGAP_NAS_FIRST_REQ (message_p).nas_pdu.length,
// ue_context_pP);
/* Fill UE identities with available information */
NGAP_NAS_FIRST_REQ(message_p).ue_identity.presenceMask = NGAP_UE_IDENTITIES_NONE;
/* Fill s-TMSI */
NGAP_NAS_FIRST_REQ(message_p).ue_identity.s_tmsi.amf_set_id = ue_context_pP->ue_context.Initialue_identity_5g_s_TMSI.amf_set_id;
NGAP_NAS_FIRST_REQ(message_p).ue_identity.s_tmsi.amf_pointer = ue_context_pP->ue_context.Initialue_identity_5g_s_TMSI.amf_pointer;
NGAP_NAS_FIRST_REQ(message_p).ue_identity.s_tmsi.m_tmsi = ue_context_pP->ue_context.Initialue_identity_5g_s_TMSI.fiveg_tmsi;
/* selected_plmn_identity: IE is 1-based, convert to 0-based (C array) */
int selected_plmn_identity = rrcSetupComplete->selectedPLMN_Identity - 1;
NGAP_NAS_FIRST_REQ(message_p).selected_plmn_identity = selected_plmn_identity;
if (rrcSetupComplete->registeredAMF != NULL) {
NR_RegisteredAMF_t *r_amf = rrcSetupComplete->registeredAMF;
NGAP_NAS_FIRST_REQ(message_p).ue_identity.presenceMask |= NGAP_UE_IDENTITIES_guami;
if (r_amf->plmn_Identity != NULL) {
if ((r_amf->plmn_Identity->mcc != NULL) && (r_amf->plmn_Identity->mcc->list.count > 0)) {
/* Use first indicated PLMN MCC if it is defined */
NGAP_NAS_FIRST_REQ(message_p).ue_identity.guami.mcc = *r_amf->plmn_Identity->mcc->list.array[selected_plmn_identity];
LOG_I(NGAP, "[gNB %d] Build NGAP_NAS_FIRST_REQ adding in s_TMSI: GUMMEI MCC %u ue %x\n",
ctxt_pP->module_id,
NGAP_NAS_FIRST_REQ (message_p).ue_identity.guami.mcc,
ue_context_pP->ue_context.rnti);
}
if (r_amf->plmn_Identity->mnc.list.count > 0) {
/* Use first indicated PLMN MNC if it is defined */
NGAP_NAS_FIRST_REQ(message_p).ue_identity.guami.mnc = *r_amf->plmn_Identity->mnc.list.array[selected_plmn_identity];
LOG_I(NGAP, "[gNB %d] Build NGAP_NAS_FIRST_REQ adding in s_TMSI: GUMMEI MNC %u ue %x\n",
ctxt_pP->module_id,
NGAP_NAS_FIRST_REQ (message_p).ue_identity.guami.mnc,
ue_context_pP->ue_context.rnti);
}
} else {
/* TODO */
}
/* amf_Identifier */
uint32_t amf_Id = BIT_STRING_to_uint32(&r_amf->amf_Identifier);
NGAP_NAS_FIRST_REQ(message_p).ue_identity.guami.amf_region_id = amf_Id >> 16;
NGAP_NAS_FIRST_REQ(message_p).ue_identity.guami.amf_set_id = ue_context_pP->ue_context.Initialue_identity_5g_s_TMSI.amf_set_id;
NGAP_NAS_FIRST_REQ(message_p).ue_identity.guami.amf_pointer = ue_context_pP->ue_context.Initialue_identity_5g_s_TMSI.amf_pointer;
ue_context_pP->ue_context.ue_guami.mcc = NGAP_NAS_FIRST_REQ(message_p).ue_identity.guami.mcc;
ue_context_pP->ue_context.ue_guami.mnc = NGAP_NAS_FIRST_REQ(message_p).ue_identity.guami.mnc;
ue_context_pP->ue_context.ue_guami.mnc_len = NGAP_NAS_FIRST_REQ(message_p).ue_identity.guami.mnc_len;
ue_context_pP->ue_context.ue_guami.amf_region_id = NGAP_NAS_FIRST_REQ(message_p).ue_identity.guami.amf_region_id;
ue_context_pP->ue_context.ue_guami.amf_set_id = NGAP_NAS_FIRST_REQ(message_p).ue_identity.guami.amf_set_id;
ue_context_pP->ue_context.ue_guami.amf_pointer = NGAP_NAS_FIRST_REQ(message_p).ue_identity.guami.amf_pointer;
MSC_LOG_TX_MESSAGE(MSC_NGAP_GNB,
MSC_NGAP_AMF,
(const char *)&message_p->ittiMsg.ngap_nas_first_req,
sizeof(ngap_nas_first_req_t),
MSC_AS_TIME_FMT" NGAP_NAS_FIRST_REQ gNB %u UE %x",
MSC_AS_TIME_ARGS(ctxt_pP),
ctxt_pP->module_id,
ctxt_pP->rnti);
LOG_I(NGAP, "[gNB %d] Build NGAP_NAS_FIRST_REQ adding in s_TMSI: GUAMI amf_set_id %u amf_region_id %u ue %x\n",
ctxt_pP->module_id,
NGAP_NAS_FIRST_REQ (message_p).ue_identity.guami.amf_set_id,
NGAP_NAS_FIRST_REQ (message_p).ue_identity.guami.amf_region_id,
ue_context_pP->ue_context.rnti);
}
/* amf_Identifier */
uint32_t amf_Id = BIT_STRING_to_uint32(&r_amf->amf_Identifier);
NGAP_NAS_FIRST_REQ(message_p).ue_identity.guami.amf_region_id = amf_Id >> 16;
NGAP_NAS_FIRST_REQ(message_p).ue_identity.guami.amf_set_id = ue_context_pP->ue_context.Initialue_identity_5g_s_TMSI.amf_set_id;
NGAP_NAS_FIRST_REQ(message_p).ue_identity.guami.amf_pointer = ue_context_pP->ue_context.Initialue_identity_5g_s_TMSI.amf_pointer;
ue_context_pP->ue_context.ue_guami.mcc = NGAP_NAS_FIRST_REQ(message_p).ue_identity.guami.mcc;
ue_context_pP->ue_context.ue_guami.mnc = NGAP_NAS_FIRST_REQ(message_p).ue_identity.guami.mnc;
ue_context_pP->ue_context.ue_guami.mnc_len = NGAP_NAS_FIRST_REQ(message_p).ue_identity.guami.mnc_len;
ue_context_pP->ue_context.ue_guami.amf_region_id = NGAP_NAS_FIRST_REQ(message_p).ue_identity.guami.amf_region_id;
ue_context_pP->ue_context.ue_guami.amf_set_id = NGAP_NAS_FIRST_REQ(message_p).ue_identity.guami.amf_set_id;
ue_context_pP->ue_context.ue_guami.amf_pointer = NGAP_NAS_FIRST_REQ(message_p).ue_identity.guami.amf_pointer;
MSC_LOG_TX_MESSAGE(MSC_NGAP_GNB,
MSC_NGAP_AMF,
(const char *)&message_p->ittiMsg.ngap_nas_first_req,
sizeof(ngap_nas_first_req_t),
MSC_AS_TIME_FMT" NGAP_NAS_FIRST_REQ gNB %u UE %x",
MSC_AS_TIME_ARGS(ctxt_pP),
ctxt_pP->module_id,
ctxt_pP->rnti);
LOG_I(NGAP, "[gNB %d] Build NGAP_NAS_FIRST_REQ adding in s_TMSI: GUAMI amf_set_id %u amf_region_id %u ue %x\n",
ctxt_pP->module_id,
NGAP_NAS_FIRST_REQ (message_p).ue_identity.guami.amf_set_id,
NGAP_NAS_FIRST_REQ (message_p).ue_identity.guami.amf_region_id,
ue_context_pP->ue_context.rnti);
}
itti_send_msg_to_task (TASK_NGAP, ctxt_pP->instance, message_p);
}
......@@ -316,60 +490,84 @@ rrc_gNB_process_NGAP_INITIAL_CONTEXT_SETUP_REQ(
)
//------------------------------------------------------------------------------
{
uint16_t ue_initial_id;
uint32_t gNB_ue_ngap_id;
rrc_gNB_ue_context_t *ue_context_p = NULL;
protocol_ctxt_t ctxt;
uint16_t ue_initial_id;
uint32_t gNB_ue_ngap_id;
rrc_gNB_ue_context_t *ue_context_p = NULL;
protocol_ctxt_t ctxt;
uint8_t pdu_sessions_done = 0;
ue_initial_id = NGAP_INITIAL_CONTEXT_SETUP_REQ(msg_p).ue_initial_id;
gNB_ue_ngap_id = NGAP_INITIAL_CONTEXT_SETUP_REQ(msg_p).gNB_ue_ngap_id;
ue_initial_id = NGAP_INITIAL_CONTEXT_SETUP_REQ(msg_p).ue_initial_id;
gNB_ue_ngap_id = NGAP_INITIAL_CONTEXT_SETUP_REQ(msg_p).gNB_ue_ngap_id;
ue_context_p = rrc_gNB_get_ue_context_from_ngap_ids(instance, ue_initial_id, gNB_ue_ngap_id);
LOG_I(NR_RRC, "[gNB %d] Received %s: ue_initial_id %d, gNB_ue_ngap_id %d \n",
instance, msg_name, ue_initial_id, gNB_ue_ngap_id);
ue_context_p = rrc_gNB_get_ue_context_from_ngap_ids(instance, ue_initial_id, gNB_ue_ngap_id);
LOG_I(NR_RRC, "[gNB %d] Received %s: ue_initial_id %d, gNB_ue_ngap_id %d \n",
instance, msg_name, ue_initial_id, gNB_ue_ngap_id);
if (ue_context_p == NULL) {
/* Can not associate this message to an UE index, send a failure to NGAP and discard it! */
MessageDef *msg_fail_p = NULL;
LOG_W(NR_RRC, "[gNB %d] In NGAP_INITIAL_CONTEXT_SETUP_REQ: unknown UE from S1AP ids (%d, %d)\n", instance, ue_initial_id, gNB_ue_ngap_id);
msg_fail_p = itti_alloc_new_message (TASK_RRC_GNB, NGAP_INITIAL_CONTEXT_SETUP_FAIL);
NGAP_INITIAL_CONTEXT_SETUP_FAIL (msg_fail_p).gNB_ue_ngap_id = gNB_ue_ngap_id;
// TODO add failure cause when defined!
itti_send_msg_to_task (TASK_NGAP, instance, msg_fail_p);
return (-1);
} else {
PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, instance, GNB_FLAG_YES, ue_context_p->ue_context.rnti, 0, 0);
ue_context_p->ue_context.gNB_ue_ngap_id = NGAP_INITIAL_CONTEXT_SETUP_REQ (msg_p).gNB_ue_ngap_id;
ue_context_p->ue_context.amf_ue_ngap_id = NGAP_INITIAL_CONTEXT_SETUP_REQ (msg_p).amf_ue_ngap_id;
/* NAS PDU */
if (ue_context_p->ue_context.nas_pdu_flag == 1) {
ue_context_p->ue_context.nas_pdu.length = NGAP_INITIAL_CONTEXT_SETUP_REQ(msg_p).nas_pdu.length;
ue_context_p->ue_context.nas_pdu.buffer = NGAP_INITIAL_CONTEXT_SETUP_REQ(msg_p).nas_pdu.buffer;
}
if (ue_context_p == NULL) {
/* Can not associate this message to an UE index, send a failure to NGAP and discard it! */
MessageDef *msg_fail_p = NULL;
LOG_W(NR_RRC, "[gNB %d] In NGAP_INITIAL_CONTEXT_SETUP_REQ: unknown UE from NGAP ids (%d, %d)\n", instance, ue_initial_id, gNB_ue_ngap_id);
msg_fail_p = itti_alloc_new_message (TASK_RRC_GNB, NGAP_INITIAL_CONTEXT_SETUP_FAIL);
NGAP_INITIAL_CONTEXT_SETUP_FAIL (msg_fail_p).gNB_ue_ngap_id = gNB_ue_ngap_id;
// TODO add failure cause when defined!
itti_send_msg_to_task (TASK_NGAP, instance, msg_fail_p);
return (-1);
} else {
PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, instance, GNB_FLAG_YES, ue_context_p->ue_context.rnti, 0, 0);
ue_context_p->ue_context.gNB_ue_ngap_id = NGAP_INITIAL_CONTEXT_SETUP_REQ (msg_p).gNB_ue_ngap_id;
ue_context_p->ue_context.amf_ue_ngap_id = NGAP_INITIAL_CONTEXT_SETUP_REQ (msg_p).amf_ue_ngap_id;
ue_context_p->ue_context.nas_pdu_flag = NGAP_INITIAL_CONTEXT_SETUP_REQ (msg_p).nas_pdu_flag;
/* TODO security */
rrc_gNB_process_security(&ctxt, ue_context_p, &(NGAP_INITIAL_CONTEXT_SETUP_REQ(msg_p).security_capabilities));
if (NGAP_INITIAL_CONTEXT_SETUP_REQ(msg_p).nb_of_pdusessions != 0) {
ue_context_p->ue_context.nb_of_pdusessions = NGAP_INITIAL_CONTEXT_SETUP_REQ(msg_p).nb_of_pdusessions;
for (int i = 0; i < NR_NB_RB_MAX - 3; i++) {
if(ue_context_p->ue_context.pdusession[i].status >= PDU_SESSION_STATUS_DONE)
continue;
ue_context_p->ue_context.pdusession[i].status = PDU_SESSION_STATUS_NEW;
ue_context_p->ue_context.pdusession[i].param = NGAP_INITIAL_CONTEXT_SETUP_REQ (msg_p).pdusession_param[pdu_sessions_done];
pdu_sessions_done++;
uint8_t send_security_mode_command = TRUE;
// TODO establish PDU SESSION
nr_rrc_pdcp_config_security(
&ctxt,
ue_context_p,
send_security_mode_command);
if(pdu_sessions_done >= NGAP_INITIAL_CONTEXT_SETUP_REQ(msg_p).nb_of_pdusessions) {
break;
}
}
}
if (send_security_mode_command) {
rrc_gNB_generate_SecurityModeCommand (&ctxt, ue_context_p);
send_security_mode_command = FALSE;
/* NAS PDU */
ue_context_p->ue_context.nas_pdu_flag = NGAP_INITIAL_CONTEXT_SETUP_REQ(msg_p).nas_pdu_flag;
if (ue_context_p->ue_context.nas_pdu_flag == 1) {
ue_context_p->ue_context.nas_pdu.length = NGAP_INITIAL_CONTEXT_SETUP_REQ(msg_p).nas_pdu.length;
ue_context_p->ue_context.nas_pdu.buffer = NGAP_INITIAL_CONTEXT_SETUP_REQ(msg_p).nas_pdu.buffer;
}
/* security */
rrc_gNB_process_security(&ctxt, ue_context_p, &(NGAP_INITIAL_CONTEXT_SETUP_REQ(msg_p).security_capabilities));
process_gNB_security_key (
&ctxt,
ue_context_p,
NGAP_INITIAL_CONTEXT_SETUP_REQ(msg_p).security_key);
uint8_t send_security_mode_command = TRUE;
nr_rrc_pdcp_config_security(
&ctxt,
ue_context_p,
send_security_mode_command);
} else {
/* rrc_gNB_generate_UECapabilityEnquiry */
rrc_gNB_generate_UECapabilityEnquiry(&ctxt, ue_context_p);
}
if (send_security_mode_command) {
rrc_gNB_generate_SecurityModeCommand (&ctxt, ue_context_p);
send_security_mode_command = FALSE;
nr_rrc_pdcp_config_security(
&ctxt,
ue_context_p,
send_security_mode_command);
} else {
/* rrc_gNB_generate_UECapabilityEnquiry */
rrc_gNB_generate_UECapabilityEnquiry(&ctxt, ue_context_p);
}
// in case, send the S1SP initial context response if it is not sent with the attach complete message
if (ue_context_p->ue_context.Status == NR_RRC_RECONFIGURED) {
......@@ -390,25 +588,25 @@ rrc_gNB_send_NGAP_INITIAL_CONTEXT_SETUP_RESP(
//------------------------------------------------------------------------------
{
MessageDef *msg_p = NULL;
int e_rab;
int pdusession;
int e_rabs_done = 0;
int e_rabs_failed = 0;
msg_p = itti_alloc_new_message (TASK_RRC_ENB, NGAP_INITIAL_CONTEXT_SETUP_RESP);
NGAP_INITIAL_CONTEXT_SETUP_RESP (msg_p).gNB_ue_ngap_id = ue_context_pP->ue_context.gNB_ue_ngap_id;
for (e_rab = 0; e_rab < ue_context_pP->ue_context.nb_of_e_rabs; e_rab++) {
if (ue_context_pP->ue_context.e_rab[e_rab].status == E_RAB_STATUS_DONE) {
for (pdusession = 0; pdusession < ue_context_pP->ue_context.nb_of_pdusessions; pdusession++) {
if (ue_context_pP->ue_context.pdusession[pdusession].status == E_RAB_STATUS_DONE) {
e_rabs_done++;
NGAP_INITIAL_CONTEXT_SETUP_RESP (msg_p).pdusessions[e_rab].pdusession_id = ue_context_pP->ue_context.e_rab[e_rab].param.e_rab_id;
NGAP_INITIAL_CONTEXT_SETUP_RESP (msg_p).pdusessions[pdusession].pdusession_id = ue_context_pP->ue_context.pdusession[pdusession].param.pdusession_id;
// TODO add other information from S1-U when it will be integrated
NGAP_INITIAL_CONTEXT_SETUP_RESP (msg_p).pdusessions[e_rab].gtp_teid = ue_context_pP->ue_context.gnb_gtp_teid[e_rab];
memcpy(NGAP_INITIAL_CONTEXT_SETUP_RESP (msg_p).pdusessions[e_rab].gNB_addr.buffer , ue_context_pP->ue_context.gnb_gtp_addrs[e_rab].buffer, 20);
NGAP_INITIAL_CONTEXT_SETUP_RESP (msg_p).pdusessions[e_rab].gNB_addr.length = 4;
ue_context_pP->ue_context.e_rab[e_rab].status = E_RAB_STATUS_ESTABLISHED;
NGAP_INITIAL_CONTEXT_SETUP_RESP (msg_p).pdusessions[pdusession].gtp_teid = ue_context_pP->ue_context.gnb_gtp_teid[pdusession];
memcpy(NGAP_INITIAL_CONTEXT_SETUP_RESP (msg_p).pdusessions[pdusession].gNB_addr.buffer , ue_context_pP->ue_context.gnb_gtp_addrs[pdusession].buffer, 20);
NGAP_INITIAL_CONTEXT_SETUP_RESP (msg_p).pdusessions[pdusession].gNB_addr.length = 4;
ue_context_pP->ue_context.pdusession[pdusession].status = E_RAB_STATUS_ESTABLISHED;
} else {
e_rabs_failed++;
ue_context_pP->ue_context.e_rab[e_rab].status = E_RAB_STATUS_FAILED;
NGAP_INITIAL_CONTEXT_SETUP_RESP (msg_p).pdusessions_failed[e_rab].pdusession_id = ue_context_pP->ue_context.e_rab[e_rab].param.e_rab_id;
ue_context_pP->ue_context.pdusession[pdusession].status = E_RAB_STATUS_FAILED;
NGAP_INITIAL_CONTEXT_SETUP_RESP (msg_p).pdusessions_failed[pdusession].pdusession_id = ue_context_pP->ue_context.pdusession[pdusession].param.pdusession_id;
// TODO add cause when it will be integrated
}
}
......@@ -429,13 +627,34 @@ rrc_gNB_send_NGAP_INITIAL_CONTEXT_SETUP_RESP(
}
static NR_CipheringAlgorithm_t rrc_gNB_select_ciphering(uint16_t algorithms) {
//#warning "Forced return NR_CipheringAlgorithm_nea0, to be deleted in future"
if (algorithms & NGAP_ENCRYPTION_NEA3_MASK) {
return NR_CipheringAlgorithm_nea3;
}
if (algorithms & NGAP_ENCRYPTION_NEA2_MASK) {
return NR_CipheringAlgorithm_nea2;
}
if (algorithms & NGAP_ENCRYPTION_NEA1_MASK) {
return NR_CipheringAlgorithm_nea1;
}
return NR_CipheringAlgorithm_nea0;
}
static e_NR_IntegrityProtAlgorithm rrc_gNB_select_integrity(uint16_t algorithms) {
if (algorithms & NGAP_INTEGRITY_NIA3_MASK) {
return NR_IntegrityProtAlgorithm_nia3;
}
if (algorithms & NGAP_INTEGRITY_NIA2_MASK) {
return NR_IntegrityProtAlgorithm_nia2;
}
if (algorithms & NGAP_INTEGRITY_NIA1_MASK) {
return NR_IntegrityProtAlgorithm_nia1;
}
// to be continue
return NR_IntegrityProtAlgorithm_nia0;
}
......@@ -452,7 +671,7 @@ rrc_gNB_process_security(
ue_context_pP->ue_context.security_capabilities = *security_capabilities_pP;
// translation
LOG_D(NR_RRC,
"[eNB %d] NAS security_capabilities.encryption_algorithms %u AS ciphering_algorithm %lu NAS security_capabilities.integrity_algorithms %u AS integrity_algorithm %u\n",
"[gNB %d] NAS security_capabilities.encryption_algorithms %u AS ciphering_algorithm %lu NAS security_capabilities.integrity_algorithms %u AS integrity_algorithm %u\n",
ctxt_pP->module_id,
ue_context_pP->ue_context.security_capabilities.nRencryption_algorithms,
(unsigned long)ue_context_pP->ue_context.ciphering_algorithm,
......@@ -473,7 +692,7 @@ rrc_gNB_process_security(
changed = TRUE;
}
LOG_I (NR_RRC, "[eNB %d][UE %x] Selected security algorithms (%p): %lx, %x, %s\n",
LOG_I (NR_RRC, "[gNB %d][UE %x] Selected security algorithms (%p): %lx, %x, %s\n",
ctxt_pP->module_id,
ue_context_pP->ue_context.rnti,
security_capabilities_pP,
......@@ -482,3 +701,532 @@ rrc_gNB_process_security(
changed ? "changed" : "same");
return changed;
}
//------------------------------------------------------------------------------
int
rrc_gNB_process_NGAP_DOWNLINK_NAS(
MessageDef *msg_p,
const char *msg_name,
instance_t instance,
mui_t *rrc_gNB_mui
)
//------------------------------------------------------------------------------
{
uint16_t ue_initial_id;
uint32_t gNB_ue_ngap_id;
uint32_t length;
uint8_t *buffer;
struct rrc_gNB_ue_context_s *ue_context_p = NULL;
protocol_ctxt_t ctxt;
memset(&ctxt, 0, sizeof(protocol_ctxt_t));
ue_initial_id = NGAP_DOWNLINK_NAS (msg_p).ue_initial_id;
gNB_ue_ngap_id = NGAP_DOWNLINK_NAS (msg_p).gNB_ue_ngap_id;
ue_context_p = rrc_gNB_get_ue_context_from_ngap_ids(instance, ue_initial_id, gNB_ue_ngap_id);
LOG_I(NR_RRC, "[gNB %d] Received %s: ue_initial_id %d, gNB_ue_ngap_id %d\n",
instance,
msg_name,
ue_initial_id,
gNB_ue_ngap_id);
if (ue_context_p == NULL) {
MSC_LOG_RX_MESSAGE(
MSC_RRC_GNB,
MSC_NGAP_GNB,
NULL,
0,
MSC_AS_TIME_FMT" DOWNLINK-NAS UE initial id %u gNB_ue_ngap_id %u",
0,0,//MSC_AS_TIME_ARGS(ctxt_pP),
ue_initial_id,
gNB_ue_ngap_id);
/* Can not associate this message to an UE index, send a failure to NGAP and discard it! */
MessageDef *msg_fail_p;
LOG_W(NR_RRC, "[gNB %d] In NGAP_DOWNLINK_NAS: unknown UE from NGAP ids (%d, %d)\n", instance, ue_initial_id, gNB_ue_ngap_id);
msg_fail_p = itti_alloc_new_message (TASK_RRC_GNB, NGAP_NAS_NON_DELIVERY_IND);
NGAP_NAS_NON_DELIVERY_IND (msg_fail_p).gNB_ue_ngap_id = gNB_ue_ngap_id;
NGAP_NAS_NON_DELIVERY_IND (msg_fail_p).nas_pdu.length = NGAP_DOWNLINK_NAS (msg_p).nas_pdu.length;
NGAP_NAS_NON_DELIVERY_IND (msg_fail_p).nas_pdu.buffer = NGAP_DOWNLINK_NAS (msg_p).nas_pdu.buffer;
// TODO add failure cause when defined!
MSC_LOG_TX_MESSAGE(
MSC_RRC_ENB,
MSC_NGAP_GNB,
(const char *)NULL,
0,
MSC_AS_TIME_FMT" NGAP_NAS_NON_DELIVERY_IND UE initial id %u gNB_ue_ngap_id %u (ue ctxt !found)",
0,0,//MSC_AS_TIME_ARGS(ctxt_pP),
ue_initial_id,
gNB_ue_ngap_id);
itti_send_msg_to_task (TASK_NGAP, instance, msg_fail_p);
return (-1);
} else {
PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, instance, GNB_FLAG_YES, ue_context_p->ue_context.rnti, 0, 0);
/* Is it the first income from NGAP ? */
if (ue_context_p->ue_context.gNB_ue_ngap_id == 0) {
ue_context_p->ue_context.gNB_ue_ngap_id = NGAP_DOWNLINK_NAS (msg_p).gNB_ue_ngap_id;
}
MSC_LOG_RX_MESSAGE(
MSC_RRC_GNB,
MSC_NGAP_GNB,
(const char *)NULL,
0,
MSC_AS_TIME_FMT" DOWNLINK-NAS UE initial id %u gNB_ue_ngap_id %u",
0,0,//MSC_AS_TIME_ARGS(ctxt_pP),
ue_initial_id,
NGAP_DOWNLINK_NAS (msg_p).gNB_ue_ngap_id);
/* Create message for PDCP (DLInformationTransfer_t) */
length = do_NR_DLInformationTransfer (
instance,
&buffer,
rrc_gNB_get_next_transaction_identifier (instance),
NGAP_DOWNLINK_NAS (msg_p).nas_pdu.length,
NGAP_DOWNLINK_NAS (msg_p).nas_pdu.buffer);
LOG_DUMPMSG(NR_RRC, DEBUG_RRC, buffer, length, "[MSG] RRC DL Information Transfer\n");
/*
* switch UL or DL NAS message without RRC piggybacked to SRB2 if active.
*/
#ifdef ITTI_SIM
MessageDef *message_p;
uint8_t *message_buffer;
message_buffer = itti_malloc (TASK_RRC_GNB_SIM, TASK_RRC_UE_SIM, length);
memcpy (message_buffer, buffer, length);
message_p = itti_alloc_new_message (TASK_RRC_GNB_SIM, GNB_RRC_DCCH_DATA_IND);
GNB_RRC_DCCH_DATA_IND (message_p).rbid = DCCH;
GNB_RRC_DCCH_DATA_IND (message_p).sdu = message_buffer;
GNB_RRC_DCCH_DATA_IND (message_p).size = length;
itti_send_msg_to_task (TASK_RRC_UE_SIM, instance, message_p);
LOG_I(NR_RRC, "Send DL NAS message \n");
#else
/* Transfer data to PDCP */
nr_rrc_data_req (
&ctxt,
ue_context_p->ue_context.Srb2.Srb_info.Srb_id,
(*rrc_gNB_mui)++,
SDU_CONFIRM_NO,
length,
buffer,
PDCP_TRANSMISSION_MODE_CONTROL);
#endif
return (0);
}
}
//------------------------------------------------------------------------------
void
rrc_gNB_send_NGAP_UPLINK_NAS(
const protocol_ctxt_t *const ctxt_pP,
rrc_gNB_ue_context_t *const ue_context_pP,
NR_UL_DCCH_Message_t *const ul_dcch_msg
)
//------------------------------------------------------------------------------
{
uint32_t pdu_length;
uint8_t *pdu_buffer;
MessageDef *msg_p;
NR_ULInformationTransfer_t *ulInformationTransfer = ul_dcch_msg->message.choice.c1->choice.ulInformationTransfer;
if (ulInformationTransfer->criticalExtensions.present == NR_ULInformationTransfer__criticalExtensions_PR_ulInformationTransfer) {
pdu_length = ulInformationTransfer->criticalExtensions.choice.ulInformationTransfer->dedicatedNAS_Message->size;
pdu_buffer = ulInformationTransfer->criticalExtensions.choice.ulInformationTransfer->dedicatedNAS_Message->buf;
msg_p = itti_alloc_new_message (TASK_RRC_GNB, NGAP_UPLINK_NAS);
NGAP_UPLINK_NAS (msg_p).gNB_ue_ngap_id = ue_context_pP->ue_context.gNB_ue_ngap_id;
NGAP_UPLINK_NAS (msg_p).nas_pdu.length = pdu_length;
NGAP_UPLINK_NAS (msg_p).nas_pdu.buffer = pdu_buffer;
// extract_imsi(NGAP_UPLINK_NAS (msg_p).nas_pdu.buffer,
// NGAP_UPLINK_NAS (msg_p).nas_pdu.length,
// ue_context_pP);
itti_send_msg_to_task (TASK_NGAP, ctxt_pP->instance, msg_p);
LOG_I(NR_RRC,"Send RRC GNB UL Information Transfer \n");
}
}
//------------------------------------------------------------------------------
void
rrc_gNB_send_NGAP_PDUSESSION_SETUP_RESP(
const protocol_ctxt_t *const ctxt_pP,
rrc_gNB_ue_context_t *const ue_context_pP,
uint8_t xid
)
//------------------------------------------------------------------------------
{
MessageDef *msg_p;
int pdu_sessions_done = 0;
int pdu_sessions_failed = 0;
int pdusession;
int qos_flow_index;
msg_p = itti_alloc_new_message (TASK_RRC_GNB, NGAP_PDUSESSION_SETUP_RESP);
NGAP_PDUSESSION_SETUP_RESP(msg_p).gNB_ue_ngap_id = ue_context_pP->ue_context.gNB_ue_ngap_id;
for (pdusession = 0; pdusession < ue_context_pP->ue_context.setup_pdu_sessions; pdusession++) {
// if (xid == ue_context_pP->ue_context.pdusession[pdusession].xid) {
if (ue_context_pP->ue_context.pdusession[pdusession].status == PDU_SESSION_STATUS_DONE) {
NGAP_PDUSESSION_SETUP_RESP(msg_p).pdusessions[pdusession].pdusession_id = ue_context_pP->ue_context.pdusession[pdusession].param.pdusession_id;
// NGAP_PDUSESSION_SETUP_RESP(msg_p).pdusessions[pdusession].pdusession_id = 1;
NGAP_PDUSESSION_SETUP_RESP(msg_p).pdusessions[pdusession].nb_of_qos_flow = ue_context_pP->ue_context.pdusession[pdusession].param.nb_qos;
NGAP_PDUSESSION_SETUP_RESP(msg_p).pdusessions[pdusession].gtp_teid = ue_context_pP->ue_context.gnb_gtp_teid[pdusession];
NGAP_PDUSESSION_SETUP_RESP(msg_p).pdusessions[pdusession].gNB_addr.pdu_session_type = PDUSessionType_ipv4;
NGAP_PDUSESSION_SETUP_RESP(msg_p).pdusessions[pdusession].gNB_addr.length = ue_context_pP->ue_context.gnb_gtp_addrs[pdusession].length;
memcpy(NGAP_PDUSESSION_SETUP_RESP(msg_p).pdusessions[pdusession].gNB_addr.buffer,
ue_context_pP->ue_context.gnb_gtp_addrs[pdusession].buffer, sizeof(uint8_t)*20);
for (qos_flow_index = 0; qos_flow_index < NGAP_PDUSESSION_SETUP_RESP(msg_p).pdusessions[pdusession].nb_of_qos_flow; qos_flow_index++) {
NGAP_PDUSESSION_SETUP_RESP(msg_p).pdusessions[pdusession].associated_qos_flows[qos_flow_index].qfi =
ue_context_pP->ue_context.pdusession[pdusession].param.qos[qos_flow_index].qfi;
NGAP_PDUSESSION_SETUP_RESP(msg_p).pdusessions[pdusession].associated_qos_flows[qos_flow_index].qos_flow_mapping_ind = QOSFLOW_MAPPING_INDICATION_DL;
}
ue_context_pP->ue_context.pdusession[pdusession].status = PDU_SESSION_STATUS_ESTABLISHED;
LOG_I (NR_RRC,"gnb_gtp_addr (msg index %d, pdu_sessions index %d, status %d, xid %d): nb_of_pdusessions %d, pdusession_id %d, teid: %u, addr: %d.%d.%d.%d \n ",
pdu_sessions_done, pdusession, ue_context_pP->ue_context.pdusession[pdusession].status, xid,
ue_context_pP->ue_context.nb_of_pdusessions,
NGAP_PDUSESSION_SETUP_RESP (msg_p).pdusessions[pdu_sessions_done].pdusession_id,
NGAP_PDUSESSION_SETUP_RESP (msg_p).pdusessions[pdu_sessions_done].gtp_teid,
NGAP_PDUSESSION_SETUP_RESP (msg_p).pdusessions[pdu_sessions_done].gNB_addr.buffer[0],
NGAP_PDUSESSION_SETUP_RESP (msg_p).pdusessions[pdu_sessions_done].gNB_addr.buffer[1],
NGAP_PDUSESSION_SETUP_RESP (msg_p).pdusessions[pdu_sessions_done].gNB_addr.buffer[2],
NGAP_PDUSESSION_SETUP_RESP (msg_p).pdusessions[pdu_sessions_done].gNB_addr.buffer[3]);
pdu_sessions_done++;
} else if ((ue_context_pP->ue_context.pdusession[pdusession].status == PDU_SESSION_STATUS_NEW) ||
(ue_context_pP->ue_context.pdusession[pdusession].status == PDU_SESSION_STATUS_ESTABLISHED)) {
LOG_D (NR_RRC,"PDU-SESSION is NEW or already ESTABLISHED\n");
} else { /* to be improved */
ue_context_pP->ue_context.pdusession[pdusession].status = PDU_SESSION_STATUS_FAILED;
NGAP_PDUSESSION_SETUP_RESP (msg_p).pdusessions_failed[pdu_sessions_failed].pdusession_id = ue_context_pP->ue_context.pdusession[pdusession].param.pdusession_id;
pdu_sessions_failed++;
// TODO add cause when it will be integrated
}
NGAP_PDUSESSION_SETUP_RESP(msg_p).nb_of_pdusessions = pdu_sessions_done;
NGAP_PDUSESSION_SETUP_RESP(msg_p).nb_of_pdusessions_failed = pdu_sessions_failed;
// } else {
// LOG_D(NR_RRC,"xid does not corresponds (context pdu_sessions index %d, status %d, xid %d/%d) \n ",
// pdusession, ue_context_pP->ue_context.pdusession[pdusession].status, xid, ue_context_pP->ue_context.pdusession[pdusession].xid);
// }
}
if ((pdu_sessions_done > 0) ) {
LOG_I(NR_RRC,"NGAP_PDUSESSION_SETUP_RESP: sending the message: nb_of_pdusessions %d, total pdu_sessions %d, index %d\n",
ue_context_pP->ue_context.nb_of_pdusessions, ue_context_pP->ue_context.setup_pdu_sessions, pdusession);
MSC_LOG_TX_MESSAGE(
MSC_RRC_GNB,
MSC_NGAP_GNB,
(const char *)&NGAP_PDUSESSION_SETUP_RESP (msg_p),
sizeof(ngap_pdusession_setup_resp_t),
MSC_AS_TIME_FMT" PDUSESSION_SETUP_RESP UE %X gNB_ue_ngap_id %u pdu_sessions:%u succ %u fail",
MSC_AS_TIME_ARGS(ctxt_pP),
ue_context_pP->ue_id_rnti,
NGAP_PDUSESSION_SETUP_RESP (msg_p).gNB_ue_ngap_id,
pdu_sessions_done, pdu_sessions_failed);
itti_send_msg_to_task (TASK_NGAP, ctxt_pP->instance, msg_p);
}
for(int i = 0; i < NB_RB_MAX; i++) {
ue_context_pP->ue_context.pdusession[i].xid = -1;
}
return;
}
//------------------------------------------------------------------------------
int
rrc_gNB_process_NGAP_PDUSESSION_SETUP_REQ(
MessageDef *msg_p,
const char *msg_name,
instance_t instance
)
//------------------------------------------------------------------------------
{
uint16_t ue_initial_id;
uint32_t gNB_ue_ngap_id;
rrc_gNB_ue_context_t *ue_context_p = NULL;
protocol_ctxt_t ctxt;
gtpv1u_gnb_create_tunnel_req_t create_tunnel_req;
gtpv1u_gnb_create_tunnel_resp_t create_tunnel_resp;
uint8_t pdu_sessions_done;
uint8_t inde_list[NR_NB_RB_MAX - 3]= {0};
int ret = 0;
ue_initial_id = NGAP_PDUSESSION_SETUP_REQ(msg_p).ue_initial_id;
gNB_ue_ngap_id = NGAP_PDUSESSION_SETUP_REQ(msg_p).gNB_ue_ngap_id;
ue_context_p = rrc_gNB_get_ue_context_from_ngap_ids(instance, ue_initial_id, gNB_ue_ngap_id);
LOG_I(NR_RRC, "[gNB %d] Received %s: ue_initial_id %d, gNB_ue_ngap_id %d \n",
instance, msg_name, ue_initial_id, gNB_ue_ngap_id);
if (ue_context_p == NULL) {
MessageDef *msg_fail_p = NULL;
LOG_W(NR_RRC, "[gNB %d] In NGAP_PDUSESSION_SETUP_REQ: unknown UE from NGAP ids (%d, %d)\n", instance, ue_initial_id, gNB_ue_ngap_id);
msg_fail_p = itti_alloc_new_message(TASK_RRC_GNB, NGAP_PDUSESSION_SETUP_REQUEST_FAIL);
NGAP_PDUSESSION_SETUP_REQ(msg_fail_p).gNB_ue_ngap_id = gNB_ue_ngap_id;
// TODO add failure cause when defined!
itti_send_msg_to_task (TASK_NGAP, instance, msg_fail_p);
return (-1);
} else {
memset(&create_tunnel_req, 0, sizeof(gtpv1u_gnb_create_tunnel_req_t));
uint8_t nb_pdusessions_tosetup = NGAP_PDUSESSION_SETUP_REQ(msg_p).nb_pdusessions_tosetup;
pdu_sessions_done = 0;
PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, instance, GNB_FLAG_YES, ue_context_p->ue_context.rnti, 0, 0);
for (int i = 0; i < NR_NB_RB_MAX - 3; i++) {
if(ue_context_p->ue_context.pdusession[i].status >= PDU_SESSION_STATUS_DONE)
continue;
ue_context_p->ue_context.pdusession[i].status = PDU_SESSION_STATUS_NEW;
ue_context_p->ue_context.pdusession[i].param = NGAP_PDUSESSION_SETUP_REQ(msg_p).pdusession_setup_params[pdu_sessions_done];
create_tunnel_req.pdusession_id[pdu_sessions_done] = NGAP_PDUSESSION_SETUP_REQ(msg_p).pdusession_setup_params[pdu_sessions_done].pdusession_id;
create_tunnel_req.upf_NGu_teid[pdu_sessions_done] = NGAP_PDUSESSION_SETUP_REQ(msg_p).pdusession_setup_params[pdu_sessions_done].gtp_teid;
memcpy(create_tunnel_req.upf_addr[pdu_sessions_done].buffer,
NGAP_PDUSESSION_SETUP_REQ(msg_p).pdusession_setup_params[i].upf_addr.buffer,
sizeof(uint8_t)*20);
create_tunnel_req.upf_addr[pdu_sessions_done].length = NGAP_PDUSESSION_SETUP_REQ(msg_p).pdusession_setup_params[i].upf_addr.length;
LOG_I(NR_RRC,"NGAP PDUSESSION SETUP REQ: local index %d teid %u, pdusession id %d \n",
i,
create_tunnel_req.upf_NGu_teid[i],
create_tunnel_req.pdusession_id[i]);
inde_list[pdu_sessions_done] = i;
pdu_sessions_done++;
if(pdu_sessions_done >= nb_pdusessions_tosetup) {
break;
}
}
ue_context_p->ue_context.nb_of_pdusessions = NGAP_PDUSESSION_SETUP_REQ(msg_p).nb_pdusessions_tosetup;
ue_context_p->ue_context.gNB_ue_ngap_id = NGAP_PDUSESSION_SETUP_REQ(msg_p).gNB_ue_ngap_id;
ue_context_p->ue_context.amf_ue_ngap_id = NGAP_PDUSESSION_SETUP_REQ(msg_p).amf_ue_ngap_id;
create_tunnel_req.rnti = ue_context_p->ue_context.rnti;
create_tunnel_req.num_tunnels = pdu_sessions_done;
ret = gtpv1u_create_ngu_tunnel(
instance,
&create_tunnel_req,
&create_tunnel_resp);
if (ret != 0) {
LOG_E(NR_RRC,"rrc_gNB_process_NGAP_PDUSESSION_SETUP_REQ : gtpv1u_create_ngu_tunnel failed,start to release UE %x\n",ue_context_p->ue_context.rnti);
ue_context_p->ue_context.ue_release_timer_ng = 1;
ue_context_p->ue_context.ue_release_timer_thres_ng = 100;
ue_context_p->ue_context.ue_release_timer = 0;
ue_context_p->ue_context.ue_reestablishment_timer = 0;
ue_context_p->ue_context.ul_failure_timer = 20000; // set ul_failure to 20000 for triggering rrc_eNB_send_S1AP_UE_CONTEXT_RELEASE_REQ
// rrc_gNB_free_UE(ctxt.module_id,ue_context_p);
ue_context_p->ue_context.ul_failure_timer = 0;
return (0);
}
nr_rrc_gNB_process_GTPV1U_CREATE_TUNNEL_RESP(
&ctxt,
&create_tunnel_resp,
&inde_list[0]);
ue_context_p->ue_context.setup_pdu_sessions += nb_pdusessions_tosetup;
// TEST
ue_context_p->ue_context.pdusession[0].status = PDU_SESSION_STATUS_DONE;
rrc_gNB_send_NGAP_PDUSESSION_SETUP_RESP(&ctxt, ue_context_p, 0);
return(0);
}
}
void
rrc_gNB_send_NGAP_UE_CONTEXT_RELEASE_REQ(
const module_id_t gnb_mod_idP,
const rrc_gNB_ue_context_t *const ue_context_pP,
const ngap_Cause_t causeP,
const long cause_valueP)
//------------------------------------------------------------------------------
{
if (ue_context_pP == NULL) {
LOG_E(RRC, "[gNB] In NGAP_UE_CONTEXT_RELEASE_REQ: invalid UE\n");
} else {
MSC_LOG_TX_MESSAGE(MSC_RRC_GNB,
MSC_NGAP_GNB,
NULL,
0,
"0 NGAP_UE_CONTEXT_RELEASE_REQ gNB_ue_ngap_id 0x%06"PRIX32" ",
ue_context_pP->ue_context.gNB_ue_ngap_id);
MessageDef *msg_context_release_req_p = NULL;
msg_context_release_req_p = itti_alloc_new_message(TASK_RRC_GNB, NGAP_UE_CONTEXT_RELEASE_REQ);
NGAP_UE_CONTEXT_RELEASE_REQ(msg_context_release_req_p).gNB_ue_ngap_id = ue_context_pP->ue_context.gNB_ue_ngap_id;
NGAP_UE_CONTEXT_RELEASE_REQ(msg_context_release_req_p).cause = causeP;
NGAP_UE_CONTEXT_RELEASE_REQ(msg_context_release_req_p).cause_value = cause_valueP;
NGAP_UE_CONTEXT_RELEASE_REQ(msg_context_release_req_p).nb_of_pdusessions = ue_context_pP->ue_context.setup_pdu_sessions;
for (int pdusession = 0; pdusession < ue_context_pP->ue_context.setup_pdu_sessions; pdusession++) {
NGAP_UE_CONTEXT_RELEASE_REQ(msg_context_release_req_p).pdusessions[pdusession].pdusession_id = ue_context_pP->ue_context.pdusession[pdusession].param.pdusession_id;
}
itti_send_msg_to_task(TASK_NGAP, GNB_MODULE_ID_TO_INSTANCE(gnb_mod_idP), msg_context_release_req_p);
}
}
/*------------------------------------------------------------------------------*/
int
rrc_gNB_process_NGAP_UE_CONTEXT_RELEASE_REQ (
MessageDef *msg_p,
const char *msg_name,
instance_t instance)
{
uint32_t gNB_ue_ngap_id;
struct rrc_gNB_ue_context_s *ue_context_p = NULL;
gNB_ue_ngap_id = NGAP_UE_CONTEXT_RELEASE_REQ(msg_p).gNB_ue_ngap_id;
ue_context_p = rrc_gNB_get_ue_context_from_ngap_ids(instance, UE_INITIAL_ID_INVALID, gNB_ue_ngap_id);
if (ue_context_p == NULL) {
/* Can not associate this message to an UE index, send a failure to ngAP and discard it! */
MessageDef *msg_fail_p;
LOG_W(RRC, "[gNB %d] In NGAP_UE_CONTEXT_RELEASE_REQ: unknown UE from gNB_ue_ngap_id (%d)\n",
instance,
gNB_ue_ngap_id);
msg_fail_p = itti_alloc_new_message(TASK_RRC_GNB, NGAP_UE_CONTEXT_RELEASE_RESP); /* TODO change message ID. */
NGAP_UE_CONTEXT_RELEASE_RESP(msg_fail_p).gNB_ue_ngap_id = gNB_ue_ngap_id;
// TODO add failure cause when defined!
itti_send_msg_to_task(TASK_NGAP, instance, msg_fail_p);
return (-1);
} else {
/* TODO release context. */
/* Send the response */
{
MessageDef *msg_resp_p;
msg_resp_p = itti_alloc_new_message(TASK_RRC_GNB, NGAP_UE_CONTEXT_RELEASE_RESP);
NGAP_UE_CONTEXT_RELEASE_RESP(msg_resp_p).gNB_ue_ngap_id = gNB_ue_ngap_id;
itti_send_msg_to_task(TASK_NGAP, instance, msg_resp_p);
}
return (0);
}
}
//-----------------------------------------------------------------------------
/*
* Process the NG command NGAP_UE_CONTEXT_RELEASE_COMMAND, sent by AMF.
* The gNB should remove all pdu session, NG context, and other context of the UE.
*/
int
rrc_gNB_process_NGAP_UE_CONTEXT_RELEASE_COMMAND(
MessageDef *msg_p,
const char *msg_name,
instance_t instance) {
//-----------------------------------------------------------------------------
uint32_t gNB_ue_ngap_id = 0;
protocol_ctxt_t ctxt;
struct rrc_gNB_ue_context_s *ue_context_p = NULL;
struct rrc_ue_ngap_ids_s *rrc_ue_ngap_ids = NULL;
gNB_ue_ngap_id = NGAP_UE_CONTEXT_RELEASE_COMMAND(msg_p).gNB_ue_ngap_id;
ue_context_p = rrc_gNB_get_ue_context_from_ngap_ids(instance, UE_INITIAL_ID_INVALID, gNB_ue_ngap_id);
if (ue_context_p == NULL) {
/* Can not associate this message to an UE index */
MessageDef *msg_complete_p = NULL;
LOG_W(RRC, "[gNB %d] In NGAP_UE_CONTEXT_RELEASE_COMMAND: unknown UE from gNB_ue_ngap_id (%d)\n",
instance,
gNB_ue_ngap_id);
MSC_LOG_EVENT(MSC_RRC_GNB, "0 NGAP_UE_CONTEXT_RELEASE_COMPLETE gNB_ue_ngap_id 0x%06"PRIX32" context not found",
gNB_ue_ngap_id);
MSC_LOG_TX_MESSAGE(MSC_RRC_GNB,
MSC_NGAP_GNB,
NULL,
0,
"0 NGAP_UE_CONTEXT_RELEASE_COMPLETE gNB_ue_ngap_id 0x%06"PRIX32" ",
gNB_ue_ngap_id);
msg_complete_p = itti_alloc_new_message(TASK_RRC_GNB, NGAP_UE_CONTEXT_RELEASE_COMPLETE);
NGAP_UE_CONTEXT_RELEASE_COMPLETE(msg_complete_p).gNB_ue_ngap_id = gNB_ue_ngap_id;
itti_send_msg_to_task(TASK_NGAP, instance, msg_complete_p);
rrc_ue_ngap_ids = rrc_gNB_NGAP_get_ue_ids(RC.nrrrc[instance], UE_INITIAL_ID_INVALID, gNB_ue_ngap_id);
if (rrc_ue_ngap_ids != NULL) {
rrc_gNB_NGAP_remove_ue_ids(RC.nrrrc[instance], rrc_ue_ngap_ids);
}
return -1;
} else {
ue_context_p->ue_context.ue_release_timer_ng = 0;
PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, instance, GNB_FLAG_YES, ue_context_p->ue_context.rnti, 0, 0);
rrc_gNB_generate_RRCRelease(&ctxt, ue_context_p);
return 0;
}
}
//------------------------------------------------------------------------------
/*
* Remove UE ids (ue_initial_id and ng_id) from hashtables.
*/
void
rrc_gNB_NGAP_remove_ue_ids(
gNB_RRC_INST *const rrc_instance_pP,
struct rrc_ue_ngap_ids_s *const ue_ids_pP
)
//------------------------------------------------------------------------------
{
hashtable_rc_t h_rc;
if (rrc_instance_pP == NULL) {
LOG_E(NR_RRC, "Bad NR RRC instance\n");
return;
}
if (ue_ids_pP == NULL) {
LOG_E(NR_RRC, "Trying to free a NULL NGAP UE IDs\n");
return;
}
const uint16_t ue_initial_id = ue_ids_pP->ue_initial_id;
const uint32_t gNB_ue_ngap_id = ue_ids_pP->gNB_ue_ngap_id;
if (gNB_ue_ngap_id > 0) {
h_rc = hashtable_remove(rrc_instance_pP->ngap_id2_ngap_ids, (hash_key_t)gNB_ue_ngap_id);
if (h_rc != HASH_TABLE_OK) {
LOG_W(NR_RRC, "NGAP Did not find entry in hashtable ngap_id2_ngap_ids for gNB_ue_ngap_id %u\n", gNB_ue_ngap_id);
} else {
LOG_W(NR_RRC, "NGAP removed entry in hashtable ngap_id2_ngap_ids for gNB_ue_ngap_id %u\n", gNB_ue_ngap_id);
}
}
if (ue_initial_id != UE_INITIAL_ID_INVALID) {
h_rc = hashtable_remove(rrc_instance_pP->initial_id2_ngap_ids, (hash_key_t)ue_initial_id);
if (h_rc != HASH_TABLE_OK) {
LOG_W(NR_RRC, "NGAP Did not find entry in hashtable initial_id2_ngap_ids for ue_initial_id %u\n", ue_initial_id);
} else {
LOG_W(NR_RRC, "NGAP removed entry in hashtable initial_id2_ngap_ids for ue_initial_id %u\n", ue_initial_id);
}
}
}
void
rrc_gNB_send_NGAP_UE_CAPABILITIES_IND(
const protocol_ctxt_t *const ctxt_pP,
rrc_gNB_ue_context_t *const ue_context_pP,
NR_UL_DCCH_Message_t *const ul_dcch_msg
)
//------------------------------------------------------------------------------
{
NR_UE_CapabilityRAT_ContainerList_t *ueCapabilityRATContainerList = ul_dcch_msg->message.choice.c1->choice.ueCapabilityInformation->criticalExtensions.choice.ueCapabilityInformation->ue_CapabilityRAT_ContainerList;
/* 4096 is arbitrary, should be big enough */
unsigned char buf[4096];
unsigned char *buf2;
NR_UERadioAccessCapabilityInformation_t rac;
if (ueCapabilityRATContainerList->list.count == 0) {
LOG_W(RRC, "[gNB %d][UE %x] bad UE capabilities\n", ctxt_pP->module_id, ue_context_pP->ue_context.rnti);
}
asn_enc_rval_t ret = uper_encode_to_buffer(&asn_DEF_NR_UE_CapabilityRAT_ContainerList, NULL, ueCapabilityRATContainerList, buf, 4096);
if (ret.encoded == -1) abort();
memset(&rac, 0, sizeof(NR_UERadioAccessCapabilityInformation_t));
rac.criticalExtensions.present = NR_UERadioAccessCapabilityInformation__criticalExtensions_PR_c1;
rac.criticalExtensions.choice.c1 = calloc(1,sizeof(*rac.criticalExtensions.choice.c1));
rac.criticalExtensions.choice.c1->present = NR_UERadioAccessCapabilityInformation__criticalExtensions__c1_PR_ueRadioAccessCapabilityInformation;
rac.criticalExtensions.choice.c1->choice.ueRadioAccessCapabilityInformation = calloc(1,sizeof(NR_UERadioAccessCapabilityInformation_IEs_t));
rac.criticalExtensions.choice.c1->choice.ueRadioAccessCapabilityInformation->ue_RadioAccessCapabilityInfo.buf = buf;
rac.criticalExtensions.choice.c1->choice.ueRadioAccessCapabilityInformation->ue_RadioAccessCapabilityInfo.size = (ret.encoded+7)/8;
rac.criticalExtensions.choice.c1->choice.ueRadioAccessCapabilityInformation->nonCriticalExtension = NULL;
/* 8192 is arbitrary, should be big enough */
buf2 = malloc16(8192);
if (buf2 == NULL) abort();
ret = uper_encode_to_buffer(&asn_DEF_NR_UERadioAccessCapabilityInformation, NULL, &rac, buf2, 8192);
if (ret.encoded == -1) abort();
MessageDef *msg_p;
msg_p = itti_alloc_new_message (TASK_RRC_GNB, NGAP_UE_CAPABILITIES_IND);
NGAP_UE_CAPABILITIES_IND (msg_p).gNB_ue_ngap_id = ue_context_pP->ue_context.gNB_ue_ngap_id;
NGAP_UE_CAPABILITIES_IND (msg_p).ue_radio_cap.length = (ret.encoded+7)/8;
NGAP_UE_CAPABILITIES_IND (msg_p).ue_radio_cap.buffer = buf2;
itti_send_msg_to_task (TASK_NGAP, ctxt_pP->instance, msg_p);
LOG_I(NR_RRC,"Send message to ngap: NGAP_UE_CAPABILITIES_IND\n");
}
......@@ -37,6 +37,7 @@
#include "NR_RRCSetupComplete-IEs.h"
#include "NR_RegisteredAMF.h"
#include "NR_UL-DCCH-Message.h"
typedef struct rrc_ue_ngap_ids_s {
/* Tree related data */
......@@ -77,4 +78,68 @@ rrc_gNB_process_security(
ngap_security_capabilities_t *security_capabilities_pP
);
int
rrc_gNB_process_NGAP_DOWNLINK_NAS(
MessageDef *msg_p,
const char *msg_name,
instance_t instance,
mui_t *rrc_gNB_mui
);
void
rrc_gNB_send_NGAP_UPLINK_NAS(
const protocol_ctxt_t *const ctxt_pP,
rrc_gNB_ue_context_t *const ue_context_pP,
NR_UL_DCCH_Message_t *const ul_dcch_msg
);
void
rrc_gNB_send_NGAP_PDUSESSION_SETUP_RESP(
const protocol_ctxt_t *const ctxt_pP,
rrc_gNB_ue_context_t *const ue_context_pP,
uint8_t xid
);
int
rrc_gNB_process_NGAP_PDUSESSION_SETUP_REQ(
MessageDef *msg_p,
const char *msg_name,
instance_t instance
);
void
rrc_gNB_send_NGAP_UE_CONTEXT_RELEASE_REQ(
const module_id_t gnb_mod_idP,
const rrc_gNB_ue_context_t *const ue_context_pP,
const ngap_Cause_t causeP,
const long cause_valueP
);
int
rrc_gNB_process_NGAP_UE_CONTEXT_RELEASE_REQ (
MessageDef *msg_p,
const char *msg_name,
instance_t instance
);
int
rrc_gNB_process_NGAP_UE_CONTEXT_RELEASE_COMMAND(
MessageDef *msg_p,
const char *msg_name,
instance_t instance
);
void
rrc_gNB_NGAP_remove_ue_ids(
gNB_RRC_INST *const rrc_instance_pP,
struct rrc_ue_ngap_ids_s *const ue_ids_pP
);
void
rrc_gNB_send_NGAP_UE_CAPABILITIES_IND(
const protocol_ctxt_t *const ctxt_pP,
rrc_gNB_ue_context_t *const ue_context_pP,
NR_UL_DCCH_Message_t *const ul_dcch_msg
);
#endif
......@@ -134,7 +134,7 @@ rrc_gNB_allocate_new_UE_context(
new_p->local_uid = nr_uid_linear_allocator_new(rrc_instance_pP);
for(int i = 0; i < NB_RB_MAX; i++) {
new_p->ue_context.e_rab[i].xid = -1;
new_p->ue_context.pdusession[i].xid = -1;
new_p->ue_context.modify_e_rab[i].xid = -1;
}
......
......@@ -184,14 +184,14 @@ void rrc_add_nsa_user(gNB_RRC_INST *rrc,struct rrc_gNB_ue_context_s *ue_context_
if (m->nb_e_rabs_tobeadded>0) {
for (int i=0; i<m->nb_e_rabs_tobeadded; i++) {
// Add the new E-RABs at the corresponding rrc ue context of the gNB
ue_context_p->ue_context.e_rab[i].param.e_rab_id = m->e_rabs_tobeadded[i].e_rab_id;
ue_context_p->ue_context.e_rab[i].param.gtp_teid = m->e_rabs_tobeadded[i].gtp_teid;
memcpy(&ue_context_p->ue_context.e_rab[i].param.sgw_addr, &m->e_rabs_tobeadded[i].sgw_addr, sizeof(transport_layer_addr_t));
ue_context_p->ue_context.nb_of_e_rabs++;
ue_context_p->ue_context.pdusession[i].param.pdusession_id = m->e_rabs_tobeadded[i].e_rab_id;
ue_context_p->ue_context.pdusession[i].param.gtp_teid = m->e_rabs_tobeadded[i].gtp_teid;
memcpy(&ue_context_p->ue_context.pdusession[i].param.upf_addr, &m->e_rabs_tobeadded[i].sgw_addr, sizeof(transport_layer_addr_t));
ue_context_p->ue_context.nb_of_pdusessions++;
//Fill the required E-RAB specific information for the creation of the S1-U tunnel between the gNB and the SGW
create_tunnel_req.eps_bearer_id[i] = ue_context_p->ue_context.e_rab[i].param.e_rab_id;
create_tunnel_req.sgw_S1u_teid[i] = ue_context_p->ue_context.e_rab[i].param.gtp_teid;
memcpy(&create_tunnel_req.sgw_addr[i], &ue_context_p->ue_context.e_rab[i].param.sgw_addr, sizeof(transport_layer_addr_t));
create_tunnel_req.eps_bearer_id[i] = ue_context_p->ue_context.pdusession[i].param.pdusession_id;
create_tunnel_req.sgw_S1u_teid[i] = ue_context_p->ue_context.pdusession[i].param.gtp_teid;
memcpy(&create_tunnel_req.sgw_addr[i], &ue_context_p->ue_context.pdusession[i].param.upf_addr, sizeof(transport_layer_addr_t));
inde_list[i] = i;
LOG_I(RRC,"S1-U tunnel: index %d target sgw ip %d.%d.%d.%d length %d gtp teid %u\n",
i,
......@@ -218,8 +218,8 @@ void rrc_add_nsa_user(gNB_RRC_INST *rrc,struct rrc_gNB_ue_context_s *ue_context_
X2AP_ENDC_SGNB_ADDITION_REQ_ACK(msg).nb_e_rabs_admitted_tobeadded = m->nb_e_rabs_tobeadded;
X2AP_ENDC_SGNB_ADDITION_REQ_ACK(msg).target_assoc_id = m->target_assoc_id;
for(int i=0; i<ue_context_p->ue_context.nb_of_e_rabs; i++) {
X2AP_ENDC_SGNB_ADDITION_REQ_ACK(msg).e_rabs_admitted_tobeadded[i].e_rab_id = ue_context_p->ue_context.e_rab[i].param.e_rab_id;
for(int i=0; i<ue_context_p->ue_context.nb_of_pdusessions; i++) {
X2AP_ENDC_SGNB_ADDITION_REQ_ACK(msg).e_rabs_admitted_tobeadded[i].e_rab_id = ue_context_p->ue_context.pdusession[i].param.pdusession_id;
X2AP_ENDC_SGNB_ADDITION_REQ_ACK(msg).e_rabs_admitted_tobeadded[i].gtp_teid = create_tunnel_resp.enb_S1u_teid[i];
memcpy(&X2AP_ENDC_SGNB_ADDITION_REQ_ACK(msg).e_rabs_admitted_tobeadded[i].gnb_addr, &create_tunnel_resp.enb_addr, sizeof(transport_layer_addr_t));
//The length field in the X2AP targetting structure is expected in bits but the create_tunnel_resp returns the address length in bytes
......
......@@ -995,7 +995,7 @@ int nr_decode_SI( const protocol_ctxt_t *const ctxt_pP, const uint8_t gNB_index
if (NR_UE_rrc_inst[ctxt_pP->module_id].Info[gNB_index].SIcnt == sib1->si_SchedulingInfo->schedulingInfoList.list.count)
nr_rrc_set_sub_state( ctxt_pP->module_id, RRC_SUB_STATE_IDLE_SIB_COMPLETE );
LOG_I(RRC,"SIStatus %x, SIcnt %d/%d\n",
LOG_I(NR_RRC,"SIStatus %x, SIcnt %d/%d\n",
NR_UE_rrc_inst[ctxt_pP->module_id].Info[gNB_index].SIStatus,
NR_UE_rrc_inst[ctxt_pP->module_id].Info[gNB_index].SIcnt,
sib1->si_SchedulingInfo->schedulingInfoList.list.count);
......@@ -1162,7 +1162,7 @@ int nr_decode_SIB1( const protocol_ctxt_t *const ctxt_pP, const uint8_t gNB_inde
) {
/* PLMN match, send a confirmation to NAS */
MessageDef *msg_p;
msg_p = itti_alloc_new_message(TASK_RRC_UE, NAS_CELL_SELECTION_CNF);
msg_p = itti_alloc_new_message(TASK_RRC_NRUE, NAS_CELL_SELECTION_CNF);
NAS_CELL_SELECTION_CNF (msg_p).errCode = AS_SUCCESS;
NAS_CELL_SELECTION_CNF (msg_p).cellID = BIT_STRING_to_uint32(&sib1->cellAccessRelatedInfo.plmn_IdentityList.list.array[0]->cellIdentity);
NAS_CELL_SELECTION_CNF (msg_p).tac = BIT_STRING_to_uint16(sib1->cellAccessRelatedInfo.plmn_IdentityList.list.array[0]->trackingAreaCode);
......@@ -1180,7 +1180,7 @@ int nr_decode_SIB1( const protocol_ctxt_t *const ctxt_pP, const uint8_t gNB_inde
if (cell_valid == 0) {
/* Cell can not be used, ask PHY to try the next one */
MessageDef *msg_p;
msg_p = itti_alloc_new_message(TASK_RRC_UE, PHY_FIND_NEXT_CELL_REQ);
msg_p = itti_alloc_new_message(TASK_RRC_NRUE, PHY_FIND_NEXT_CELL_REQ);
itti_send_msg_to_task(TASK_PHY_UE, ctxt_pP->instance, msg_p);
LOG_E(RRC,
"Synched with a cell, but PLMN doesn't match our SIM "
......@@ -1602,34 +1602,29 @@ nr_rrc_ue_process_securityModeCommand(
securityMode = NR_CipheringAlgorithm_spare1;
break;
}
NR_UE_rrc_inst[ctxt_pP->module_id].cipheringAlgorithm =
securityModeCommand->criticalExtensions.choice.securityModeCommand->securityConfigSMC.securityAlgorithmConfig.cipheringAlgorithm;
if (securityModeCommand->criticalExtensions.choice.securityModeCommand->securityConfigSMC.securityAlgorithmConfig.integrityProtAlgorithm != NULL)
{
switch (*securityModeCommand->criticalExtensions.choice.securityModeCommand->securityConfigSMC.securityAlgorithmConfig.integrityProtAlgorithm) {
case NR_IntegrityProtAlgorithm_nia1:
LOG_I(NR_RRC,"[UE %d] Integrity protection algorithm is set to nia1\n",ctxt_pP->module_id);
securityMode |= 1 << 5;
break;
case NR_IntegrityProtAlgorithm_nia2:
LOG_I(NR_RRC,"[UE %d] Integrity protection algorithm is set to nia2\n",ctxt_pP->module_id);
securityMode |= 1 << 6;
break;
switch (*securityModeCommand->criticalExtensions.choice.securityModeCommand->securityConfigSMC.securityAlgorithmConfig.integrityProtAlgorithm) {
case NR_IntegrityProtAlgorithm_nia1:
LOG_I(NR_RRC,"[UE %d] Integrity protection algorithm is set to nia1\n",ctxt_pP->module_id);
securityMode |= 1 << 5;
break;
default:
LOG_I(NR_RRC,"[UE %d] Integrity protection algorithm is set to none\n",ctxt_pP->module_id);
securityMode |= 0x70 ;
break;
}
NR_UE_rrc_inst[ctxt_pP->module_id].integrityProtAlgorithm =
*securityModeCommand->criticalExtensions.choice.securityModeCommand->securityConfigSMC.securityAlgorithmConfig.integrityProtAlgorithm;
case NR_IntegrityProtAlgorithm_nia2:
LOG_I(NR_RRC,"[UE %d] Integrity protection algorithm is set to nia2\n",ctxt_pP->module_id);
securityMode |= 1 << 6;
break;
default:
LOG_I(NR_RRC,"[UE %d] Integrity protection algorithm is set to none\n",ctxt_pP->module_id);
securityMode |= 0x70 ;
break;
}
LOG_D(NR_RRC,"[UE %d] security mode is %x \n",ctxt_pP->module_id, securityMode);
NR_UE_rrc_inst[ctxt_pP->module_id].cipheringAlgorithm =
securityModeCommand->criticalExtensions.choice.securityModeCommand->securityConfigSMC.securityAlgorithmConfig.cipheringAlgorithm;
NR_UE_rrc_inst[ctxt_pP->module_id].integrityProtAlgorithm =
*securityModeCommand->criticalExtensions.choice.securityModeCommand->securityConfigSMC.securityAlgorithmConfig.integrityProtAlgorithm;
memset((void *)&ul_dcch_msg,0,sizeof(NR_UL_DCCH_Message_t));
//memset((void *)&SecurityModeCommand,0,sizeof(SecurityModeCommand_t));
ul_dcch_msg.message.present = NR_UL_DCCH_MessageType_PR_c1;
......@@ -1792,11 +1787,11 @@ void rrc_ue_generate_RRCSetupRequest( const protocol_ctxt_t *const ctxt_pP, cons
#ifdef ITTI_SIM
MessageDef *message_p;
uint8_t *message_buffer;
message_buffer = itti_malloc (TASK_RRC_UE_SIM,TASK_RRC_GNB_SIM,
message_buffer = itti_malloc (TASK_RRC_NRUE,TASK_RRC_GNB_SIM,
NR_UE_rrc_inst[ctxt_pP->module_id].Srb0[gNB_index].Tx_buffer.payload_size);
memcpy (message_buffer, (uint8_t*)NR_UE_rrc_inst[ctxt_pP->module_id].Srb0[gNB_index].Tx_buffer.Payload,
NR_UE_rrc_inst[ctxt_pP->module_id].Srb0[gNB_index].Tx_buffer.payload_size);
message_p = itti_alloc_new_message (TASK_RRC_UE_SIM, UE_RRC_CCCH_DATA_IND);
message_p = itti_alloc_new_message (TASK_RRC_NRUE, UE_RRC_CCCH_DATA_IND);
GNB_RRC_CCCH_DATA_IND (message_p).sdu = message_buffer;
GNB_RRC_CCCH_DATA_IND (message_p).size = NR_UE_rrc_inst[ctxt_pP->module_id].Srb0[gNB_index].Tx_buffer.payload_size;
itti_send_msg_to_task (TASK_RRC_GNB_SIM, ctxt_pP->instance, message_p);
......@@ -1952,7 +1947,7 @@ nr_rrc_ue_process_measConfig(
(char *)measConfig->reportConfigToAddModList->list.array[i],
sizeof(NR_ReportConfigToAddMod_t));
} else {
LOG_D(RRC,"Adding Report Configuration %ld %p \n", ind-1, measConfig->reportConfigToAddModList->list.array[i]);
LOG_D(NR_RRC,"Adding Report Configuration %ld %p \n", ind-1, measConfig->reportConfigToAddModList->list.array[i]);
if (reportConfig->reportConfig.present == NR_ReportConfigToAddMod__reportConfig_PR_reportConfigNR) {
NR_UE_rrc_inst[ctxt_pP->module_id].ReportConfig[gNB_index][ind-1] = measConfig->reportConfigToAddModList->list.array[i];
}
......@@ -1985,7 +1980,7 @@ nr_rrc_ue_process_measConfig(
if (measConfig->quantityConfig != NULL) {
if (NR_UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[gNB_index]) {
LOG_D(RRC,"Modifying Quantity Configuration \n");
LOG_D(NR_RRC,"Modifying Quantity Configuration \n");
memcpy((char *)NR_UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[gNB_index],
(char *)measConfig->quantityConfig,
sizeof(NR_QuantityConfig_t));
......@@ -2199,22 +2194,45 @@ rrc_ue_process_rrcReconfiguration(
// nr_sa_rrc_ue_process_radioBearerConfig(ctxt_pP, gNB_index, ie->radioBearerConfig);
}
/* Check if there is dedicated NAS information to forward to NAS */
if (ie->nonCriticalExtension->dedicatedNAS_MessageList != NULL) {
int list_count;
uint32_t pdu_length;
uint8_t *pdu_buffer;
MessageDef *msg_p;
for (list_count = 0; list_count < ie->nonCriticalExtension->dedicatedNAS_MessageList->list.count; list_count++) {
pdu_length = ie->nonCriticalExtension->dedicatedNAS_MessageList->list.array[list_count]->size;
pdu_buffer = ie->nonCriticalExtension->dedicatedNAS_MessageList->list.array[list_count]->buf;
msg_p = itti_alloc_new_message(TASK_RRC_UE, NAS_CONN_ESTABLI_CNF);
NAS_CONN_ESTABLI_CNF(msg_p).errCode = AS_SUCCESS;
NAS_CONN_ESTABLI_CNF(msg_p).nasMsg.length = pdu_length;
NAS_CONN_ESTABLI_CNF(msg_p).nasMsg.data = pdu_buffer;
itti_send_msg_to_task(TASK_NAS_UE, ctxt_pP->instance, msg_p);
}
/* Check if there is dedicated NAS information to forward to NAS */
if (ie->nonCriticalExtension->dedicatedNAS_MessageList != NULL) {
int list_count;
uint32_t pdu_length;
uint8_t *pdu_buffer;
MessageDef *msg_p;
for (list_count = 0; list_count < ie->nonCriticalExtension->dedicatedNAS_MessageList->list.count; list_count++) {
pdu_length = ie->nonCriticalExtension->dedicatedNAS_MessageList->list.array[list_count]->size;
pdu_buffer = ie->nonCriticalExtension->dedicatedNAS_MessageList->list.array[list_count]->buf;
#ifdef ITTI_SIM
uint8_t msg_type = 0;
if((pdu_buffer + 1) != NULL){
if (*(pdu_buffer + 1) > 0 ) {
if(pdu_buffer + 9){
msg_type = *(pdu_buffer + 9);
} else {
LOG_W(NR_RRC, "[UE] Received invalid downlink message\n");
return;
}
} else {
if(pdu_buffer + 2){
msg_type = *(pdu_buffer + 2);
} else {
LOG_W(NR_RRC, "[UE] Received invalid downlink message\n");
return;
}
}
}
if(msg_type == REGISTRATION_ACCEPT){
LOG_I(NR_RRC, "[UE] Received REGISTRATION ACCEPT message\n");
}
#endif
msg_p = itti_alloc_new_message(TASK_RRC_NRUE, NAS_CONN_ESTABLI_CNF);
NAS_CONN_ESTABLI_CNF(msg_p).errCode = AS_SUCCESS;
NAS_CONN_ESTABLI_CNF(msg_p).nasMsg.length = pdu_length;
NAS_CONN_ESTABLI_CNF(msg_p).nasMsg.data = pdu_buffer;
itti_send_msg_to_task(TASK_NAS_UE, ctxt_pP->instance, msg_p);
}
free (ie->nonCriticalExtension->dedicatedNAS_MessageList);
}
......@@ -2239,10 +2257,10 @@ void nr_rrc_ue_generate_RRCReconfigurationComplete( const protocol_ctxt_t *const
#ifdef ITTI_SIM
MessageDef *message_p;
uint8_t *message_buffer;
message_buffer = itti_malloc (TASK_RRC_UE_SIM,TASK_RRC_GNB_SIM,size);
message_buffer = itti_malloc (TASK_RRC_NRUE,TASK_RRC_GNB_SIM,size);
memcpy (message_buffer, buffer, size);
message_p = itti_alloc_new_message (TASK_RRC_UE_SIM, UE_RRC_DCCH_DATA_IND);
message_p = itti_alloc_new_message (TASK_RRC_NRUE, UE_RRC_DCCH_DATA_IND);
UE_RRC_DCCH_DATA_IND (message_p).rbid = DCCH;
UE_RRC_DCCH_DATA_IND (message_p).sdu = message_buffer;
UE_RRC_DCCH_DATA_IND (message_p).size = size;
......@@ -2301,66 +2319,163 @@ nr_rrc_ue_decode_dcch(
xer_fprint(stdout, &asn_DEF_NR_DL_DCCH_Message,(void *)dl_dcch_msg);
// }
if (dl_dcch_msg->message.present == NR_DL_DCCH_MessageType_PR_c1) {
switch (dl_dcch_msg->message.choice.c1->present) {
case NR_DL_DCCH_MessageType__c1_PR_NOTHING:
LOG_I(NR_RRC, "Received PR_NOTHING on DL-DCCH-Message\n");
break;
case NR_DL_DCCH_MessageType__c1_PR_rrcReconfiguration:
rrc_ue_process_rrcReconfiguration(ctxt_pP,
dl_dcch_msg->message.choice.c1->choice.rrcReconfiguration,
gNB_indexP);
nr_rrc_ue_generate_RRCReconfigurationComplete(ctxt_pP,
gNB_indexP,
dl_dcch_msg->message.choice.c1->choice.rrcReconfiguration->rrc_TransactionIdentifier);
break;
case NR_DL_DCCH_MessageType__c1_PR_rrcResume:
case NR_DL_DCCH_MessageType__c1_PR_rrcRelease:
msg_p = itti_alloc_new_message(TASK_RRC_UE, NAS_CONN_RELEASE_IND);
if((dl_dcch_msg->message.choice.c1->choice.rrcRelease->criticalExtensions.present == NR_RRCRelease__criticalExtensions_PR_rrcRelease) &&
(dl_dcch_msg->message.choice.c1->present == NR_DL_DCCH_MessageType__c1_PR_rrcRelease)){
dl_dcch_msg->message.choice.c1->choice.rrcRelease->criticalExtensions.choice.rrcRelease->deprioritisationReq->deprioritisationTimer =
NR_RRCRelease_IEs__deprioritisationReq__deprioritisationTimer_min5;
dl_dcch_msg->message.choice.c1->choice.rrcRelease->criticalExtensions.choice.rrcRelease->deprioritisationReq->deprioritisationType =
NR_RRCRelease_IEs__deprioritisationReq__deprioritisationType_frequency;
}
itti_send_msg_to_task(TASK_NAS_UE, ctxt_pP->instance, msg_p);
break;
case NR_DL_DCCH_MessageType__c1_PR_ueCapabilityEnquiry:
LOG_I(RRC, "[UE %d] Received Capability Enquiry (gNB %d)\n",
ctxt_pP->module_id,gNB_indexP);
nr_rrc_ue_process_ueCapabilityEnquiry(
ctxt_pP,
dl_dcch_msg->message.choice.c1->choice.ueCapabilityEnquiry,
gNB_indexP);
break;
case NR_DL_DCCH_MessageType__c1_PR_rrcReestablishment:
case NR_DL_DCCH_MessageType__c1_PR_dlInformationTransfer:
case NR_DL_DCCH_MessageType__c1_PR_mobilityFromNRCommand:
case NR_DL_DCCH_MessageType__c1_PR_dlDedicatedMessageSegment_r16:
case NR_DL_DCCH_MessageType__c1_PR_ueInformationRequest_r16:
case NR_DL_DCCH_MessageType__c1_PR_dlInformationTransferMRDC_r16:
case NR_DL_DCCH_MessageType__c1_PR_loggedMeasurementConfiguration_r16:
case NR_DL_DCCH_MessageType__c1_PR_spare3:
case NR_DL_DCCH_MessageType__c1_PR_spare2:
case NR_DL_DCCH_MessageType__c1_PR_spare1:
case NR_DL_DCCH_MessageType__c1_PR_counterCheck:
break;
case NR_DL_DCCH_MessageType__c1_PR_securityModeCommand:
LOG_I(RRC, "[UE %d] Received securityModeCommand (gNB %d)\n",
ctxt_pP->module_id, gNB_indexP);
nr_rrc_ue_process_securityModeCommand(
ctxt_pP,
dl_dcch_msg->message.choice.c1->choice.securityModeCommand,
gNB_indexP);
if (dl_dcch_msg->message.present == NR_DL_DCCH_MessageType_PR_c1) {
switch (dl_dcch_msg->message.choice.c1->present) {
case NR_DL_DCCH_MessageType__c1_PR_NOTHING:
LOG_I(NR_RRC, "Received PR_NOTHING on DL-DCCH-Message\n");
break;
case NR_DL_DCCH_MessageType__c1_PR_rrcReconfiguration:
{
rrc_ue_process_rrcReconfiguration(ctxt_pP,
dl_dcch_msg->message.choice.c1->choice.rrcReconfiguration,
gNB_indexP);
nr_rrc_ue_generate_RRCReconfigurationComplete(ctxt_pP,
gNB_indexP,
dl_dcch_msg->message.choice.c1->choice.rrcReconfiguration->rrc_TransactionIdentifier);
#ifdef ITTI_SIM
as_nas_info_t initialNasMsg;
memset(&initialNasMsg, 0, sizeof(as_nas_info_t));
generateRegistrationComplete(&initialNasMsg, NULL);
if(initialNasMsg.length > 0){
MessageDef *message_p;
message_p = itti_alloc_new_message(TASK_RRC_NRUE, NAS_UPLINK_DATA_REQ);
NAS_UPLINK_DATA_REQ(message_p).UEid = ctxt_pP->module_id;
NAS_UPLINK_DATA_REQ(message_p).nasMsg.data = (uint8_t *)initialNasMsg.data;
NAS_UPLINK_DATA_REQ(message_p).nasMsg.length = initialNasMsg.length;
itti_send_msg_to_task(TASK_RRC_NRUE, ctxt_pP->instance, message_p);
LOG_I(NR_RRC, " Send NAS_UPLINK_DATA_REQ message(RegistrationComplete)\n");
}
as_nas_info_t pduEstablishMsg;
memset(&pduEstablishMsg, 0, sizeof(as_nas_info_t));
generatePduSessionEstablishRequest(&pduEstablishMsg);
if(initialNasMsg.length > 0){
MessageDef *message_p;
message_p = itti_alloc_new_message(TASK_RRC_NRUE, NAS_UPLINK_DATA_REQ);
NAS_UPLINK_DATA_REQ(message_p).UEid = ctxt_pP->module_id;
NAS_UPLINK_DATA_REQ(message_p).nasMsg.data = (uint8_t *)pduEstablishMsg.data;
NAS_UPLINK_DATA_REQ(message_p).nasMsg.length = pduEstablishMsg.length;
itti_send_msg_to_task(TASK_RRC_NRUE, ctxt_pP->instance, message_p);
LOG_I(NR_RRC, " Send NAS_UPLINK_DATA_REQ message(PduSessionEstablishRequest)\n");
}
#endif
}
break;
case NR_DL_DCCH_MessageType__c1_PR_rrcResume:
case NR_DL_DCCH_MessageType__c1_PR_rrcRelease:
LOG_I(NR_RRC, "[UE %d] Received RRC Release (gNB %d)\n",
ctxt_pP->module_id, gNB_indexP);
msg_p = itti_alloc_new_message(TASK_RRC_NRUE, NAS_CONN_RELEASE_IND);
if((dl_dcch_msg->message.choice.c1->choice.rrcRelease->criticalExtensions.present == NR_RRCRelease__criticalExtensions_PR_rrcRelease) &&
(dl_dcch_msg->message.choice.c1->present == NR_DL_DCCH_MessageType__c1_PR_rrcRelease)){
dl_dcch_msg->message.choice.c1->choice.rrcRelease->criticalExtensions.choice.rrcRelease->deprioritisationReq->deprioritisationTimer =
NR_RRCRelease_IEs__deprioritisationReq__deprioritisationTimer_min5;
dl_dcch_msg->message.choice.c1->choice.rrcRelease->criticalExtensions.choice.rrcRelease->deprioritisationReq->deprioritisationType =
NR_RRCRelease_IEs__deprioritisationReq__deprioritisationType_frequency;
}
itti_send_msg_to_task(TASK_NAS_UE, ctxt_pP->instance, msg_p);
break;
case NR_DL_DCCH_MessageType__c1_PR_ueCapabilityEnquiry:
LOG_I(NR_RRC, "[UE %d] Received Capability Enquiry (gNB %d)\n",
ctxt_pP->module_id,gNB_indexP);
nr_rrc_ue_process_ueCapabilityEnquiry(
ctxt_pP,
dl_dcch_msg->message.choice.c1->choice.ueCapabilityEnquiry,
gNB_indexP);
break;
case NR_DL_DCCH_MessageType__c1_PR_rrcReestablishment:
break;
case NR_DL_DCCH_MessageType__c1_PR_dlInformationTransfer:
{
NR_DLInformationTransfer_t *dlInformationTransfer = dl_dcch_msg->message.choice.c1->choice.dlInformationTransfer;
if (dlInformationTransfer->criticalExtensions.present
== NR_DLInformationTransfer__criticalExtensions_PR_dlInformationTransfer) {
/* This message hold a dedicated info NAS payload, forward it to NAS */
NR_DedicatedNAS_Message_t *dedicatedNAS_Message =
dlInformationTransfer->criticalExtensions.choice.dlInformationTransfer->dedicatedNAS_Message;
uint32_t pdu_length;
uint8_t *pdu_buffer;
pdu_length = dedicatedNAS_Message->size;
pdu_buffer = dedicatedNAS_Message->buf;
#ifdef ITTI_SIM
LOG_I(NR_RRC, "[UE %d] Received %s: UEid %u, length %u , buffer %p\n", ctxt_pP->module_id, messages_info[NAS_DOWNLINK_DATA_IND].name,
ctxt_pP->module_id, pdu_length, pdu_buffer);
as_nas_info_t initialNasMsg;
uint8_t msg_type = 0;
memset(&initialNasMsg, 0, sizeof(as_nas_info_t));
if((pdu_buffer + 1) != NULL){
if (*(pdu_buffer + 1) > 0 ) {
msg_type = *(pdu_buffer + 9);
} else {
msg_type = *(pdu_buffer + 2);
}
}
if((pdu_buffer + 2) == NULL){
LOG_W(NR_RRC, "[UE] Received invalid downlink message\n");
return 0;
}
switch(msg_type){
case FGS_IDENTITY_REQUEST:
generateIdentityResponse(&initialNasMsg,*(pdu_buffer+3));
break;
case FGS_AUTHENTICATION_REQUEST:
generateAuthenticationResp(&initialNasMsg, pdu_buffer);
break;
case FGS_SECURITY_MODE_COMMAND:
generateSecurityModeComplete(&initialNasMsg);
break;
default:
LOG_W(NR_RRC,"unknow message type %d\n",msg_type);
break;
}
if(initialNasMsg.length > 0){
MessageDef *message_p;
message_p = itti_alloc_new_message(TASK_RRC_NRUE, NAS_UPLINK_DATA_REQ);
NAS_UPLINK_DATA_REQ(message_p).UEid = ctxt_pP->module_id;
NAS_UPLINK_DATA_REQ(message_p).nasMsg.data = (uint8_t *)initialNasMsg.data;
NAS_UPLINK_DATA_REQ(message_p).nasMsg.length = initialNasMsg.length;
itti_send_msg_to_task(TASK_RRC_NRUE, ctxt_pP->instance, message_p);
LOG_I(NR_RRC, " Send NAS_UPLINK_DATA_REQ message\n");
}
#else
MessageDef *msg_p;
msg_p = itti_alloc_new_message(TASK_RRC_NRUE, NAS_DOWNLINK_DATA_IND);
NAS_DOWNLINK_DATA_IND(msg_p).UEid = ctxt_pP->module_id; // TODO set the UEid to something else ?
NAS_DOWNLINK_DATA_IND(msg_p).nasMsg.length = pdu_length;
NAS_DOWNLINK_DATA_IND(msg_p).nasMsg.data = pdu_buffer;
itti_send_msg_to_task(TASK_NAS_UE, ctxt_pP->instance, msg_p);
#endif
}
}
break;
break;
case NR_DL_DCCH_MessageType__c1_PR_mobilityFromNRCommand:
case NR_DL_DCCH_MessageType__c1_PR_dlDedicatedMessageSegment_r16:
case NR_DL_DCCH_MessageType__c1_PR_ueInformationRequest_r16:
case NR_DL_DCCH_MessageType__c1_PR_dlInformationTransferMRDC_r16:
case NR_DL_DCCH_MessageType__c1_PR_loggedMeasurementConfiguration_r16:
case NR_DL_DCCH_MessageType__c1_PR_spare3:
case NR_DL_DCCH_MessageType__c1_PR_spare2:
case NR_DL_DCCH_MessageType__c1_PR_spare1:
case NR_DL_DCCH_MessageType__c1_PR_counterCheck:
break;
case NR_DL_DCCH_MessageType__c1_PR_securityModeCommand:
LOG_I(NR_RRC, "[UE %d] Received securityModeCommand (gNB %d)\n",
ctxt_pP->module_id, gNB_indexP);
nr_rrc_ue_process_securityModeCommand(
ctxt_pP,
dl_dcch_msg->message.choice.c1->choice.securityModeCommand,
gNB_indexP);
break;
}
}
}
return 0;
}
......@@ -2441,6 +2556,50 @@ void *rrc_nrue_task( void *args_p ) {
NR_RRC_DCCH_DATA_IND (msg_p).gNB_index);
break;
case NAS_UPLINK_DATA_REQ: {
uint32_t length;
uint8_t *buffer;
LOG_I(NR_RRC, "[UE %d] Received %s: UEid %d\n", ue_mod_id, ITTI_MSG_NAME (msg_p), NAS_UPLINK_DATA_REQ (msg_p).UEid);
/* Create message for PDCP (ULInformationTransfer_t) */
length = do_NR_ULInformationTransfer(&buffer, NAS_UPLINK_DATA_REQ (msg_p).nasMsg.length, NAS_UPLINK_DATA_REQ (msg_p).nasMsg.data);
/* Transfer data to PDCP */
PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_id, GNB_FLAG_NO, NR_UE_rrc_inst[ue_mod_id].Info[0].rnti, 0, 0,0);
#ifdef ITTI_SIM
MessageDef *message_p;
uint8_t *message_buffer;
message_buffer = itti_malloc (TASK_RRC_NRUE,TASK_RRC_GNB_SIM,length);
memcpy (message_buffer, buffer, length);
message_p = itti_alloc_new_message (TASK_RRC_NRUE, UE_RRC_DCCH_DATA_IND);
if(NR_UE_rrc_inst[ue_mod_id].SRB2_config[0] == NULL)
UE_RRC_DCCH_DATA_IND (message_p).rbid = DCCH;
else
UE_RRC_DCCH_DATA_IND (message_p).rbid = DCCH1;
UE_RRC_DCCH_DATA_IND (message_p).sdu = message_buffer;
UE_RRC_DCCH_DATA_IND (message_p).size = length;
itti_send_msg_to_task (TASK_RRC_GNB_SIM, ctxt.instance, message_p);
#else
// check if SRB2 is created, if yes request data_req on DCCH1 (SRB2)
if(NR_UE_rrc_inst[ue_mod_id].SRB2_config[0] == NULL) {
rrc_data_req_ue (&ctxt,
DCCH,
nr_rrc_mui++,
SDU_CONFIRM_NO,
length, buffer,
PDCP_TRANSMISSION_MODE_CONTROL);
} else {
rrc_data_req_ue (&ctxt,
DCCH1,
nr_rrc_mui++,
SDU_CONFIRM_NO,
length, buffer,
PDCP_TRANSMISSION_MODE_CONTROL);
}
#endif
break;
}
default:
LOG_E(NR_RRC, "[UE %d] Received unexpected message %s\n", ue_mod_id, ITTI_MSG_NAME (msg_p));
break;
......@@ -2487,7 +2646,7 @@ nr_rrc_ue_process_ueCapabilityEnquiry(
NR_UE_CapabilityRAT_Container_t ue_CapabilityRAT_Container;
uint8_t buffer[200];
int i;
LOG_I(RRC,"[UE %d] Frame %d: Receiving from SRB1 (DL-DCCH), Processing UECapabilityEnquiry (gNB %d)\n",
LOG_I(NR_RRC,"[UE %d] Frame %d: Receiving from SRB1 (DL-DCCH), Processing UECapabilityEnquiry (gNB %d)\n",
ctxt_pP->module_id,
ctxt_pP->frame,
gNB_index);
......
......@@ -55,6 +55,8 @@ typedef enum {
int derive_key(algorithm_type_dist_t nas_alg_type, uint8_t nas_enc_alg_id,
const uint8_t key[32], uint8_t **out);
int nr_derive_key(algorithm_type_dist_t alg_type, uint8_t alg_id,
const uint8_t key[32], uint8_t **out);
//#define derive_key_nas_enc(aLGiD, kEY, kNAS) derive_key(NAS_ENC_ALG, aLGiD, kEY, kNAS)
......@@ -72,6 +74,19 @@ int derive_key(algorithm_type_dist_t nas_alg_type, uint8_t nas_enc_alg_id,
#define derive_key_up_int(aLGiD, kEY, kNAS) \
derive_key(UP_INT_ALG, aLGiD, kEY, kNAS)
// 5G SA
#define nr_derive_key_rrc_enc(aLGiD, kEY, kRRC) \
nr_derive_key(RRC_ENC_ALG, aLGiD, kEY, kRRC)
#define nr_derive_key_rrc_int(aLGiD, kEY, kRRC) \
nr_derive_key(RRC_INT_ALG, aLGiD, kEY, kRRC)
#define nr_derive_key_up_enc(aLGiD, kEY, kUP) \
nr_derive_key(UP_ENC_ALG, aLGiD, kEY, kUP)
#define nr_derive_key_up_int(aLGiD, kEY, kUP) \
nr_derive_key(UP_INT_ALG, aLGiD, kEY, kUP)
typedef struct {
uint8_t *key;
uint32_t key_length;
......
......@@ -36,6 +36,8 @@
#define FC_ALG_KEY_DER (0x15)
#define FC_KASME_TO_CK (0x16)
#define NR_FC_ALG_KEY_DER (0x69)
#ifndef hton_int32
# define hton_int32(x) \
(((x & 0x000000FF) << 24) | ((x & 0x0000FF00) << 8) | \
......
......@@ -97,6 +97,34 @@ int derive_key(algorithm_type_dist_t alg_type, uint8_t alg_id,
return 0;
}
int nr_derive_key(algorithm_type_dist_t alg_type, uint8_t alg_id,
const uint8_t key[32], uint8_t **out)
{
uint8_t string[7];
/* FC */
string[0] = NR_FC_ALG_KEY_DER;
/* P0 = algorithm type distinguisher */
string[1] = (uint8_t)(alg_type & 0xFF);
/* L0 = length(P0) = 1 */
string[2] = 0x00;
string[3] = 0x01;
/* P1 */
string[4] = alg_id;
/* L1 = length(P1) = 1 */
string[5] = 0x00;
string[6] = 0x01;
kdf(string, 7, key, 32, out, 32);
return 0;
}
/*
int derive_keNB(const uint8_t key[32], const uint32_t nas_count, uint8_t **keNB)
{
......
......@@ -38,6 +38,7 @@
#include "NwGtpv1uPrivate.h"
#include "NwLog.h"
#include "gtpv1u_eNB_defs.h"
#include "gtpv1u_gNB_defs.h"
#include "gtpv1_u_messages_types.h"
#include "udp_eNB_task.h"
#include "common/utils/LOG/log.h"
......@@ -45,7 +46,7 @@
#include "COMMON/platform_constants.h"
#include "common/utils/LOG/vcd_signal_dumper.h"
#include "common/ran_context.h"
#include "gtpv1u_eNB_defs.h"
//#include "gtpv1u_eNB_defs.h"
#include "gtpv1u_eNB_task.h"
#include "gtpv1u_gNB_task.h"
#include "rrc_eNB_GTPV1U.h"
......@@ -184,7 +185,7 @@ NwGtpv1uRcT gtpv1u_gNB_process_stack_req(
ctxt.module_id=0;
ctxt.rnti=0x1234;
ctxt.eNB_index=0;
result = pdcp_data_req(
&ctxt,
SRB_FLAG_NO,
......@@ -318,4 +319,343 @@ void *gtpv1u_gNB_task(void *args) {
return NULL;
}
int nr_gtpv1u_gNB_init(void) {
NwGtpv1uRcT rc = NW_GTPV1U_FAILURE;
NwGtpv1uUlpEntityT ulp;
NwGtpv1uUdpEntityT udp;
NwGtpv1uLogMgrEntityT log;
NwGtpv1uTimerMgrEntityT tmr;
// enb_properties_p = enb_config_get()->properties[0];
RC.nr_gtpv1u_data_g = (nr_gtpv1u_data_t *)calloc(sizeof(nr_gtpv1u_data_t),1);
LOG_I(GTPU, "Initializing GTPU stack %p\n",&RC.nr_gtpv1u_data_g);
/* Initialize UE hashtable */
RC.nr_gtpv1u_data_g->ue_mapping = hashtable_create (32, NULL, NULL);
AssertFatal(RC.nr_gtpv1u_data_g->ue_mapping != NULL, " ERROR Initializing TASK_GTPV1_U task interface: in hashtable_create returned %p\n", RC.gtpv1u_data_g->ue_mapping);
RC.nr_gtpv1u_data_g->teid_mapping = hashtable_create (256, NULL, NULL);
AssertFatal(RC.nr_gtpv1u_data_g->teid_mapping != NULL, " ERROR Initializing TASK_GTPV1_U task interface: in hashtable_create\n");
// RC.gtpv1u_data_g.enb_ip_address_for_S1u_S12_S4_up = enb_properties_p->enb_ipv4_address_for_S1U;
//gtpv1u_data_g.udp_data;
RC.nr_gtpv1u_data_g->seq_num = 0;
RC.nr_gtpv1u_data_g->restart_counter = 0;
/* Initializing GTPv1-U stack */
if ((rc = nwGtpv1uInitialize(&RC.nr_gtpv1u_data_g->gtpv1u_stack, GTPU_STACK_ENB)) != NW_GTPV1U_OK) {
LOG_E(GTPU, "Failed to setup nwGtpv1u stack %x\n", rc);
return -1;
}
if ((rc = nwGtpv1uSetLogLevel(RC.nr_gtpv1u_data_g->gtpv1u_stack,
NW_LOG_LEVEL_DEBG)) != NW_GTPV1U_OK) {
LOG_E(GTPU, "Failed to setup loglevel for stack %x\n", rc);
return -1;
}
/* Set the ULP API callback. Called once message have been processed by the
* nw-gtpv1u stack.
*/
ulp.ulpReqCallback = gtpv1u_gNB_process_stack_req;
memset((void *)&(ulp.hUlp), 0, sizeof(NwGtpv1uUlpHandleT));
if ((rc = nwGtpv1uSetUlpEntity(RC.nr_gtpv1u_data_g->gtpv1u_stack, &ulp)) != NW_GTPV1U_OK) {
LOG_E(GTPU, "nwGtpv1uSetUlpEntity: %x", rc);
return -1;
}
/* nw-gtpv1u stack requires an udp callback to send data over UDP.
* We provide a wrapper to UDP task.
*/
udp.udpDataReqCallback = gtpv1u_eNB_send_udp_msg;
memset((void *)&(udp.hUdp), 0, sizeof(NwGtpv1uUdpHandleT));
if ((rc = nwGtpv1uSetUdpEntity(RC.nr_gtpv1u_data_g->gtpv1u_stack, &udp)) != NW_GTPV1U_OK) {
LOG_E(GTPU, "nwGtpv1uSetUdpEntity: %x", rc);
return -1;
}
log.logReqCallback = gtpv1u_eNB_log_request;
memset((void *)&(log.logMgrHandle), 0, sizeof(NwGtpv1uLogMgrHandleT));
if ((rc = nwGtpv1uSetLogMgrEntity(RC.nr_gtpv1u_data_g->gtpv1u_stack, &log)) != NW_GTPV1U_OK) {
LOG_E(GTPU, "nwGtpv1uSetLogMgrEntity: %x", rc);
return -1;
}
/* Timer interface is more complicated as both wrappers doesn't send a message
* to the timer task but call the timer API functions start/stop timer.
*/
tmr.tmrMgrHandle = 0;
tmr.tmrStartCallback = gtpv1u_start_timer_wrapper;
tmr.tmrStopCallback = gtpv1u_stop_timer_wrapper;
if ((rc = nwGtpv1uSetTimerMgrEntity(RC.nr_gtpv1u_data_g->gtpv1u_stack, &tmr)) != NW_GTPV1U_OK) {
LOG_E(GTPU, "nwGtpv1uSetTimerMgrEntity: %x", rc);
return -1;
}
#if defined(GTP_DUMP_SOCKET) && GTP_DUMP_SOCKET > 0
if ((ret = gtpv1u_eNB_create_dump_socket()) < 0) {
return -1;
}
#endif
LOG_D(GTPU, "Initializing GTPV1U interface for eNB: DONE\n");
return 0;
}
//-----------------------------------------------------------------------------
int
gtpv1u_create_ngu_tunnel(
const instance_t instanceP,
const gtpv1u_gnb_create_tunnel_req_t *const create_tunnel_req_pP,
gtpv1u_gnb_create_tunnel_resp_t *const create_tunnel_resp_pP)
{
/* Create a new nw-gtpv1-u stack req using API */
NwGtpv1uUlpApiT stack_req;
NwGtpv1uRcT rc = NW_GTPV1U_FAILURE;
/* Local tunnel end-point identifier */
teid_t ngu_teid = 0;
nr_gtpv1u_teid_data_t *gtpv1u_teid_data_p = NULL;
nr_gtpv1u_ue_data_t *gtpv1u_ue_data_p = NULL;
//MessageDef *message_p = NULL;
hashtable_rc_t hash_rc = HASH_TABLE_KEY_NOT_EXISTS;
int i;
pdusessionid_t pdusession_id = 0;
// int ipv4_addr = 0;
int ip_offset = 0;
in_addr_t in_addr;
int addrs_length_in_bytes= 0;
int loop_counter = 0;
int ret = 0;
MSC_LOG_RX_MESSAGE(
MSC_GTPU_GNB,
MSC_RRC_GNB,
NULL,0,
MSC_AS_TIME_FMT" CREATE_TUNNEL_REQ RNTI %"PRIx16" inst %u ntuns %u psid %u upf-ngu teid %u",
0,0,create_tunnel_req_pP->rnti, instanceP,
create_tunnel_req_pP->num_tunnels, create_tunnel_req_pP->pdusession_id[0],
create_tunnel_req_pP->upf_NGu_teid[0]);
create_tunnel_resp_pP->rnti = create_tunnel_req_pP->rnti;
create_tunnel_resp_pP->status = 0;
create_tunnel_resp_pP->num_tunnels = 0;
for (i = 0; i < create_tunnel_req_pP->num_tunnels; i++) {
ip_offset = 0;
loop_counter = 0;
pdusession_id = create_tunnel_req_pP->pdusession_id[i];
LOG_D(GTPU, "Rx GTPV1U_GNB_CREATE_TUNNEL_REQ ue rnti %x pdu session id %u\n",
create_tunnel_req_pP->rnti, pdusession_id);
memset(&stack_req, 0, sizeof(NwGtpv1uUlpApiT));
stack_req.apiType = NW_GTPV1U_ULP_API_CREATE_TUNNEL_ENDPOINT;
do {
ngu_teid = gtpv1u_new_teid();
LOG_D(GTPU, "gtpv1u_create_ngu_tunnel() 0x%x %u(dec)\n", ngu_teid, ngu_teid);
stack_req.apiInfo.createTunnelEndPointInfo.teid = ngu_teid;
stack_req.apiInfo.createTunnelEndPointInfo.hUlpSession = 0;
stack_req.apiInfo.createTunnelEndPointInfo.hStackSession = 0;
rc = nwGtpv1uProcessUlpReq(RC.nr_gtpv1u_data_g->gtpv1u_stack, &stack_req);
LOG_D(GTPU, ".\n");
loop_counter++;
} while (rc != NW_GTPV1U_OK && loop_counter < 10);
if ( rc != NW_GTPV1U_OK && loop_counter == 10 ) {
LOG_E(GTPU,"NwGtpv1uCreateTunnelEndPoint failed 10 times,start next loop\n");
ret = -1;
continue;
}
//-----------------------
// PDCP->GTPV1U mapping
//-----------------------
hash_rc = hashtable_get(RC.nr_gtpv1u_data_g->ue_mapping, create_tunnel_req_pP->rnti, (void **)&gtpv1u_ue_data_p);
if ((hash_rc == HASH_TABLE_KEY_NOT_EXISTS) || (hash_rc == HASH_TABLE_OK)) {
if (hash_rc == HASH_TABLE_KEY_NOT_EXISTS) {
gtpv1u_ue_data_p = calloc (1, sizeof(gtpv1u_ue_data_t));
hash_rc = hashtable_insert(RC.nr_gtpv1u_data_g->ue_mapping, create_tunnel_req_pP->rnti, gtpv1u_ue_data_p);
AssertFatal(hash_rc == HASH_TABLE_OK, "Error inserting ue_mapping in GTPV1U hashtable");
}
gtpv1u_ue_data_p->ue_id = create_tunnel_req_pP->rnti;
gtpv1u_ue_data_p->instance_id = 0; // TO DO
memcpy(&create_tunnel_resp_pP->gnb_addr.buffer,
&RC.nr_gtpv1u_data_g->gnb_ip_address_for_NGu_up,
sizeof (in_addr_t));
LOG_I(GTPU,"Configured GTPu address : %x\n",RC.nr_gtpv1u_data_g->gnb_ip_address_for_NGu_up);
create_tunnel_resp_pP->gnb_addr.length = sizeof (in_addr_t);
addrs_length_in_bytes = create_tunnel_req_pP->upf_addr[i].length / 8;
AssertFatal((addrs_length_in_bytes == 4) ||
(addrs_length_in_bytes == 16) ||
(addrs_length_in_bytes == 20),
"Bad transport layer address length %d (bits) %d (bytes)",
create_tunnel_req_pP->upf_addr[i].length, addrs_length_in_bytes);
if ((addrs_length_in_bytes == 4) ||
(addrs_length_in_bytes == 20)) {
in_addr = *((in_addr_t *)create_tunnel_req_pP->upf_addr[i].buffer);
ip_offset = 4;
gtpv1u_ue_data_p->bearers[pdusession_id - GTPV1U_BEARER_OFFSET].upf_ip_addr = in_addr;
}
if ((addrs_length_in_bytes == 16) ||
(addrs_length_in_bytes == 20)) {
memcpy(gtpv1u_ue_data_p->bearers[pdusession_id - GTPV1U_BEARER_OFFSET].upf_ip6_addr.s6_addr,
&create_tunnel_req_pP->upf_addr[i].buffer[ip_offset],
16);
}
gtpv1u_ue_data_p->bearers[pdusession_id - GTPV1U_BEARER_OFFSET].state = BEARER_IN_CONFIG;
gtpv1u_ue_data_p->bearers[pdusession_id - GTPV1U_BEARER_OFFSET].teid_gNB = ngu_teid;
gtpv1u_ue_data_p->bearers[pdusession_id - GTPV1U_BEARER_OFFSET].teid_gNB_stack_session = stack_req.apiInfo.createTunnelEndPointInfo.hStackSession;
gtpv1u_ue_data_p->bearers[pdusession_id - GTPV1U_BEARER_OFFSET].teid_upf = create_tunnel_req_pP->upf_NGu_teid[i];
gtpv1u_ue_data_p->num_bearers++;
create_tunnel_resp_pP->gnb_NGu_teid[i] = ngu_teid;
LOG_I(GTPU,"Copied to create_tunnel_resp tunnel: index %d target gNB ip %d.%d.%d.%d length %d gtp teid %u\n",
i,
create_tunnel_resp_pP->gnb_addr.buffer[0],
create_tunnel_resp_pP->gnb_addr.buffer[1],
create_tunnel_resp_pP->gnb_addr.buffer[2],
create_tunnel_resp_pP->gnb_addr.buffer[3],
create_tunnel_resp_pP->gnb_addr.length,
create_tunnel_resp_pP->gnb_NGu_teid[i]);
} else {
create_tunnel_resp_pP->gnb_NGu_teid[i] = 0;
create_tunnel_resp_pP->status = 0xFF;
}
create_tunnel_resp_pP->pdusession_id[i] = pdusession_id;
create_tunnel_resp_pP->num_tunnels += 1;
//-----------------------
// GTPV1U->PDCP mapping
//-----------------------
hash_rc = hashtable_get(RC.nr_gtpv1u_data_g->teid_mapping, ngu_teid, (void **)&gtpv1u_teid_data_p);
if (hash_rc == HASH_TABLE_KEY_NOT_EXISTS) {
gtpv1u_teid_data_p = calloc (1, sizeof(nr_gtpv1u_teid_data_t));
gtpv1u_teid_data_p->gnb_id = 0; // TO DO
gtpv1u_teid_data_p->ue_id = create_tunnel_req_pP->rnti;
gtpv1u_teid_data_p->pdu_session_id = pdusession_id;
hash_rc = hashtable_insert(RC.nr_gtpv1u_data_g->teid_mapping, ngu_teid, gtpv1u_teid_data_p);
AssertFatal(hash_rc == HASH_TABLE_OK, "Error inserting teid mapping in GTPV1U hashtable");
} else {
create_tunnel_resp_pP->gnb_NGu_teid[i] = 0;
create_tunnel_resp_pP->status = 0xFF;
}
}
MSC_LOG_TX_MESSAGE(
MSC_GTPU_GNB,
MSC_RRC_GNB,
NULL,0,
"0 GTPV1U_GNB_CREATE_TUNNEL_RESP rnti %x teid %x",
create_tunnel_resp_pP->rnti,
ngu_teid);
LOG_D(GTPU, "Tx GTPV1U_GNB_CREATE_TUNNEL_RESP ue rnti %x status %d\n",
create_tunnel_req_pP->rnti,
create_tunnel_resp_pP->status);
//return 0;
return ret;
}
//-----------------------------------------------------------------------------
static int gtpv1u_gNB_send_init_udp(const Gtpv1uNGReq *req) {
// Create and alloc new message
MessageDef *message_p;
struct in_addr addr= {0};
message_p = itti_alloc_new_message(TASK_GTPV1_U, UDP_INIT);
if (message_p == NULL) {
return -1;
}
UDP_INIT(message_p).port = req->gnb_port_for_NGu_up;
addr.s_addr = req->gnb_ip_address_for_NGu_up;
UDP_INIT(message_p).address = inet_ntoa(addr);
LOG_I(GTPU, "Tx UDP_INIT IP addr %s (%x)\n", UDP_INIT(message_p).address,UDP_INIT(message_p).port);
MSC_LOG_EVENT(
MSC_GTPU_ENB,
"0 UDP bind %s:%u",
UDP_INIT(message_p).address,
UDP_INIT(message_p).port);
return itti_send_msg_to_task(TASK_UDP, INSTANCE_DEFAULT, message_p);
}
static int gtpv1u_ng_req(
const instance_t instanceP,
const Gtpv1uNGReq *const req) {
memcpy(&RC.nr_gtpv1u_data_g->gnb_ip_address_for_NGu_up,
&req->gnb_ip_address_for_NGu_up,
sizeof (req->gnb_ip_address_for_NGu_up));
gtpv1u_gNB_send_init_udp(req);
return 0;
}
//-----------------------------------------------------------------------------
void *gtpv1u_gNB_process_itti_msg(void *notUsed) {
/* Trying to fetch a message from the message queue.
* If the queue is empty, this function will block till a
* message is sent to the task.
*/
instance_t instance;
MessageDef *received_message_p = NULL;
int rc = 0;
itti_receive_msg(TASK_GTPV1_U, &received_message_p);
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_GTPV1U_ENB_TASK, VCD_FUNCTION_IN);
DevAssert(received_message_p != NULL);
instance = ITTI_MSG_INSTANCE(received_message_p);
switch (ITTI_MSG_ID(received_message_p)) {
case GTPV1U_GNB_NG_REQ:
gtpv1u_ng_req(instance, &received_message_p->ittiMsg.gtpv1uNGReq);
break;
case TERMINATE_MESSAGE: {
if (RC.nr_gtpv1u_data_g->ue_mapping != NULL) {
hashtable_destroy (&(RC.nr_gtpv1u_data_g->ue_mapping));
}
if (RC.nr_gtpv1u_data_g->teid_mapping != NULL) {
hashtable_destroy (&(RC.nr_gtpv1u_data_g->teid_mapping));
}
LOG_W(GTPU, " *** Exiting GTPU thread\n");
itti_exit_task();
}
break;
case TIMER_HAS_EXPIRED:
nwGtpv1uProcessTimeout(&received_message_p->ittiMsg.timer_has_expired.arg);
break;
default: {
LOG_E(GTPU, "Unkwnon message ID %d:%s\n",
ITTI_MSG_ID(received_message_p),
ITTI_MSG_NAME(received_message_p));
}
break;
}
rc = itti_free(ITTI_MSG_ORIGIN_ID(received_message_p), received_message_p);
AssertFatal(rc == EXIT_SUCCESS, "Failed to free memory (%d)!\n", rc);
received_message_p = NULL;
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_GTPV1U_ENB_TASK, VCD_FUNCTION_OUT);
return NULL;
}
void *nr_gtpv1u_gNB_task(void *args) {
int rc = 0;
rc = nr_gtpv1u_gNB_init();
AssertFatal(rc == 0, "gtpv1u_gNB_init Failed");
itti_mark_task_ready(TASK_GTPV1_U);
MSC_START_USE();
while(1) {
(void) gtpv1u_gNB_process_itti_msg (NULL);
}
return NULL;
}
/*
* 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 gtpv1u_gNB_defs.h
* \brief
* \author Yoshio INOUE, Masayuki HARADA
* \date 2020
* \version 0.1
* \email: yoshio.inoue@fujitsu.com,masayuki.harada@fujitsu.com
* (yoshio.inoue%40fujitsu.com%2cmasayuki.harada%40fujitsu.com)
*/
#include "hashtable.h"
#include "NR_asn_constant.h"
#ifndef GTPV1U_GNB_DEFS_H_
#define GTPV1U_GNB_DEFS_H_
#include "NwGtpv1u.h"
#define GTPV1U_UDP_PORT (2152)
#define NR_GTPV1U_MAX_BEARERS_ID (max_val_NR_DRB_Identity - 3)
#define GTPV1U_SOURCE_GNB (0)
#define GTPV1U_TARGET_GNB (1)
#define GTPV1U_MSG_FROM_SOURCE_GNB (0)
#define GTPV1U_MSG_FROM_UPF (1)
typedef struct nr_gtpv1u_teid_data_s {
/* UE identifier for oaisim stack */
module_id_t gnb_id;
rnti_t ue_id;
pdusessionid_t pdu_session_id;
} nr_gtpv1u_teid_data_t;
typedef struct nr_gtpv1u_bearer_s {
/* TEID used in dl and ul */
teid_t teid_gNB; ///< gNB TEID
uintptr_t teid_gNB_stack_session; ///< gNB TEID
teid_t teid_upf; ///< Remote TEID
in_addr_t upf_ip_addr;
struct in6_addr upf_ip6_addr;
teid_t teid_tgNB;
in_addr_t tgnb_ip_addr; ///< target gNB ipv4
struct in6_addr tgnb_ip6_addr; ///< target gNB ipv6
tcp_udp_port_t port;
//NwGtpv1uStackSessionHandleT stack_session;
bearer_state_t state;
} nr_gtpv1u_bearer_t;
typedef struct nr_gtpv1u_ue_data_s {
/* UE identifier for oaisim stack */
rnti_t ue_id;
/* Unique identifier used between PDCP and GTP-U to distinguish UEs */
uint32_t instance_id;
int num_bearers;
/* Bearer related data.
* Note that the first LCID available for data is 3 and we fixed the maximum
* number of e-rab per UE to be (32 [id range]), max RB is 11. The real rb id will 3 + rab_id (3..32).
*/
nr_gtpv1u_bearer_t bearers[NR_GTPV1U_MAX_BEARERS_ID];
//RB_ENTRY(gtpv1u_ue_data_s) gtpv1u_ue_node;
} nr_gtpv1u_ue_data_t;
typedef struct nr_gtpv1u_data_s {
/* nwgtpv1u stack internal data */
NwGtpv1uStackHandleT gtpv1u_stack;
/* RB tree of UEs */
hash_table_t *ue_mapping; // PDCP->GTPV1U
hash_table_t *teid_mapping; // GTPV1U -> PDCP
//RB_HEAD(gtpv1u_ue_map, gtpv1u_ue_data_s) gtpv1u_ue_map_head;
/* Local IP address to use */
in_addr_t gnb_ip_address_for_NGu_up;
/* UDP internal data */
//udp_data_t udp_data;
uint16_t seq_num;
uint8_t restart_counter;
#ifdef GTPU_IN_KERNEL
char *interface_name;
int interface_index;
struct iovec *malloc_ring;
void *sock_mmap_ring[16];
int sock_desc[16]; // indexed by marking
#endif
} nr_gtpv1u_data_t;
#endif /* GTPV1U_GNB_DEFS_H_ */
......@@ -32,6 +32,13 @@ int gtpv1u_gNB_init(void);
void *gtpv1u_gNB_task(void *args);
void *nr_gtpv1u_gNB_task(void *args);
int
gtpv1u_create_ngu_tunnel(
const instance_t instanceP,
const gtpv1u_gnb_create_tunnel_req_t * const create_tunnel_req_pP,
gtpv1u_gnb_create_tunnel_resp_t * const create_tunnel_resp_pP);
#endif /* GTPV1U_GNB_TASK_H_ */
......@@ -95,6 +95,7 @@ static void ngap_gNB_register_amf(ngap_gNB_instance_t *instance_p,
MessageDef *message_p = NULL;
sctp_new_association_req_t *sctp_new_association_req_p = NULL;
ngap_gNB_amf_data_t *ngap_amf_data_p = NULL;
struct ngap_gNB_amf_data_s *amf = NULL;
DevAssert(instance_p != NULL);
DevAssert(amf_ip_address != NULL);
message_p = itti_alloc_new_message(TASK_NGAP, SCTP_NEW_ASSOCIATION_REQ);
......@@ -110,29 +111,50 @@ static void ngap_gNB_register_amf(ngap_gNB_instance_t *instance_p,
local_ip_addr,
sizeof(*local_ip_addr));
NGAP_INFO("[gNB %d] check the amf registration state\n",instance_p->instance);
/* Create new AMF descriptor */
ngap_amf_data_p = calloc(1, sizeof(*ngap_amf_data_p));
DevAssert(ngap_amf_data_p != NULL);
ngap_amf_data_p->cnx_id = ngap_gNB_fetch_add_global_cnx_id();
sctp_new_association_req_p->ulp_cnx_id = ngap_amf_data_p->cnx_id;
ngap_amf_data_p->assoc_id = -1;
ngap_amf_data_p->broadcast_plmn_num = broadcast_plmn_num;
memcpy(&ngap_amf_data_p->amf_s1_ip,
amf_ip_address,
sizeof(*amf_ip_address));
for (int i = 0; i < broadcast_plmn_num; ++i)
ngap_amf_data_p->broadcast_plmn_index[i] = broadcast_plmn_index[i];
ngap_amf_data_p->ngap_gNB_instance = instance_p;
STAILQ_INIT(&ngap_amf_data_p->served_guami);
/* Insert the new descriptor in list of known AMF
* but not yet associated.
*/
RB_INSERT(ngap_amf_map, &instance_p->ngap_amf_head, ngap_amf_data_p);
ngap_amf_data_p->state = NGAP_GNB_STATE_WAITING;
instance_p->ngap_amf_nb ++;
instance_p->ngap_amf_pending_nb ++;
amf = NULL;
if ( amf == NULL ) {
/* Create new AMF descriptor */
ngap_amf_data_p = calloc(1, sizeof(*ngap_amf_data_p));
DevAssert(ngap_amf_data_p != NULL);
ngap_amf_data_p->cnx_id = ngap_gNB_fetch_add_global_cnx_id();
sctp_new_association_req_p->ulp_cnx_id = ngap_amf_data_p->cnx_id;
ngap_amf_data_p->assoc_id = -1;
ngap_amf_data_p->broadcast_plmn_num = broadcast_plmn_num;
memcpy(&ngap_amf_data_p->amf_s1_ip,
amf_ip_address,
sizeof(*amf_ip_address));
for (int i = 0; i < broadcast_plmn_num; ++i)
ngap_amf_data_p->broadcast_plmn_index[i] = broadcast_plmn_index[i];
ngap_amf_data_p->ngap_gNB_instance = instance_p;
STAILQ_INIT(&ngap_amf_data_p->served_guami);
/* Insert the new descriptor in list of known AMF
* but not yet associated.
*/
RB_INSERT(ngap_amf_map, &instance_p->ngap_amf_head, ngap_amf_data_p);
ngap_amf_data_p->state = NGAP_GNB_STATE_WAITING;
instance_p->ngap_amf_nb ++;
instance_p->ngap_amf_pending_nb ++;
} else if (amf->state == NGAP_GNB_STATE_WAITING) {
instance_p->ngap_amf_pending_nb ++;
sctp_new_association_req_p->ulp_cnx_id = amf->cnx_id;
NGAP_INFO("[gNB %d] AMF already registered, retrive the data (state %d, cnx %d, amf_nb %d, amf_pending_nb %d)\n",
instance_p->instance,
amf->state, amf->cnx_id,
instance_p->ngap_amf_nb, instance_p->ngap_amf_pending_nb);
/*ngap_amf_data_p->cnx_id = amf->cnx_id;
sctp_new_association_req_p->ulp_cnx_id = amf->cnx_id;
ngap_amf_data_p->assoc_id = -1;
ngap_amf_data_p->ngap_gNB_instance = instance_p;
*/
} else {
NGAP_WARN("[gNB %d] AMF already registered but not in the waiting state, retrive the data (state %d, cnx %d, amf_nb %d, amf_pending_nb %d)\n",
instance_p->instance,
amf->state, amf->cnx_id,
instance_p->ngap_amf_nb, instance_p->ngap_amf_pending_nb);
}
itti_send_msg_to_task(TASK_SCTP, instance_p->instance, message_p);
}
......
......@@ -49,6 +49,7 @@
#include "ngap_gNB_nas_procedures.h"
#include "ngap_gNB_management_procedures.h"
#include "ngap_gNB_context_management_procedures.h"
#include "NGAP_PDUSessionResourceItemCxtRelReq.h"
#include "msc.h"
......@@ -203,6 +204,21 @@ int ngap_ue_context_release_req(instance_t instance,
ie->value.choice.RAN_UE_NGAP_ID = ue_release_req_p->gNB_ue_ngap_id;
ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
/* optional */
if (ue_release_req_p->nb_of_pdusessions > 0) {
ie = (NGAP_UEContextReleaseRequest_IEs_t *)calloc(1, sizeof(NGAP_UEContextReleaseRequest_IEs_t));
ie->id = NGAP_ProtocolIE_ID_id_PDUSessionResourceListCxtRelReq;
ie->criticality = NGAP_Criticality_reject;
ie->value.present = NGAP_UEContextReleaseRequest_IEs__value_PR_PDUSessionResourceListCxtRelReq;
for (int i = 0; i < ue_release_req_p->nb_of_pdusessions; i++) {
NGAP_PDUSessionResourceItemCxtRelReq_t *item;
item = (NGAP_PDUSessionResourceItemCxtRelReq_t *)calloc(1,sizeof(NGAP_PDUSessionResourceItemCxtRelReq_t));
item->pDUSessionID = ue_release_req_p->pdusessions[i].pdusession_id;
ASN_SEQUENCE_ADD(&ie->value.choice.PDUSessionResourceListCxtRelReq.list, item);
}
ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
}
/* mandatory */
ie = (NGAP_UEContextReleaseRequest_IEs_t *)calloc(1, sizeof(NGAP_UEContextReleaseRequest_IEs_t));
ie->id = NGAP_ProtocolIE_ID_id_Cause;
......
......@@ -49,6 +49,7 @@
#include "assertions.h"
#include "conversions.h"
#include "msc.h"
#include "NGAP_NonDynamic5QIDescriptor.h"
static
int ngap_gNB_handle_ng_setup_response(uint32_t assoc_id,
......@@ -882,11 +883,11 @@ int ngap_gNB_handle_initial_context_request(uint32_t assoc_id,
}
/* Initial context request = UE-related procedure -> stream != 0 */
if (stream == 0) {
NGAP_ERROR("[SCTP %d] Received UE-related procedure on stream (%d)\n",
assoc_id, stream);
return -1;
}
//if (stream == 0) {
// NGAP_ERROR("[SCTP %d] Received UE-related procedure on stream (%d)\n",
// assoc_id, stream);
// return -1;
//}
ue_desc_p->rx_stream = stream;
ue_desc_p->amf_ue_ngap_id = amf_ue_ngap_id;
......@@ -955,7 +956,7 @@ int ngap_gNB_handle_initial_context_request(uint32_t assoc_id,
}
dec_rval = uper_decode(NULL,
dec_rval = aper_decode(NULL,
&asn_DEF_NGAP_PDUSessionResourceSetupRequestTransfer,
(void **)&pdusessionTransfer_p,
item_p->pDUSessionResourceSetupRequestTransfer.buf,
......@@ -1028,7 +1029,7 @@ int ngap_gNB_handle_initial_context_request(uint32_t assoc_id,
qosFlowItem_p = pdusessionTransfer_ies->value.choice.QosFlowSetupRequestList.list.array[qosIdx];
/* Set the QOS informations */
NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).pdusession_param[i].qos[qosIdx].qci = (uint8_t)qosFlowItem_p->qosFlowIdentifier;
NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).pdusession_param[i].qos[qosIdx].qfi = (uint8_t)qosFlowItem_p->qosFlowIdentifier;
NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).pdusession_param[i].qos[qosIdx].allocation_retention_priority.priority_level =
qosFlowItem_p->qosFlowLevelQosParameters.allocationAndRetentionPriority.priorityLevelARP;
......@@ -1289,11 +1290,11 @@ int ngap_gNB_handle_pdusession_setup_request(uint32_t assoc_id,
}
/* Initial context request = UE-related procedure -> stream != 0 */
if (stream == 0) {
NGAP_ERROR("[SCTP %d] Received UE-related procedure on stream (%d)\n",
assoc_id, stream);
return -1;
}
// if (stream == 0) {
// NGAP_ERROR("[SCTP %d] Received UE-related procedure on stream (%d)\n",
// assoc_id, stream);
// return -1;
// }
ue_desc_p->rx_stream = stream;
......@@ -1338,7 +1339,7 @@ int ngap_gNB_handle_pdusession_setup_request(uint32_t assoc_id,
NGAP_WARN("NAS PDU is not provided, generate a PDUSESSION_SETUP Failure (TBD) back to AMF \n");
}
dec_rval = uper_decode(NULL,
dec_rval = aper_decode(NULL,
&asn_DEF_NGAP_PDUSessionResourceSetupRequestTransfer,
(void **)&pdusessionTransfer_p,
item_p->pDUSessionResourceSetupRequestTransfer.buf,
......@@ -1407,8 +1408,13 @@ int ngap_gNB_handle_pdusession_setup_request(uint32_t assoc_id,
qosFlowItem_p = pdusessionTransfer_ies->value.choice.QosFlowSetupRequestList.list.array[qosIdx];
/* Set the QOS informations */
NGAP_PDUSESSION_SETUP_REQ(message_p).pdusession_setup_params[i].qos[qosIdx].qci = (uint8_t)qosFlowItem_p->qosFlowIdentifier;
NGAP_PDUSESSION_SETUP_REQ(message_p).pdusession_setup_params[i].qos[qosIdx].qfi = (uint8_t)qosFlowItem_p->qosFlowIdentifier;
if(qosFlowItem_p->qosFlowLevelQosParameters.qosCharacteristics.present == NGAP_QosCharacteristics_PR_nonDynamic5QI){
if(qosFlowItem_p->qosFlowLevelQosParameters.qosCharacteristics.choice.nonDynamic5QI != NULL){
NGAP_PDUSESSION_SETUP_REQ(message_p).pdusession_setup_params[i].qos[qosIdx].fiveQI =
(uint64_t)qosFlowItem_p->qosFlowLevelQosParameters.qosCharacteristics.choice.nonDynamic5QI->fiveQI;
}
}
NGAP_PDUSESSION_SETUP_REQ(message_p).pdusession_setup_params[i].qos[qosIdx].allocation_retention_priority.priority_level =
qosFlowItem_p->qosFlowLevelQosParameters.allocationAndRetentionPriority.priorityLevelARP;
NGAP_PDUSESSION_SETUP_REQ(message_p).pdusession_setup_params[i].qos[qosIdx].allocation_retention_priority.pre_emp_capability =
......@@ -1668,7 +1674,7 @@ int ngap_gNB_handle_pdusession_modify_request(uint32_t assoc_id,
continue;
}
dec_rval = uper_decode(NULL,
dec_rval = aper_decode(NULL,
&asn_DEF_NGAP_PDUSessionResourceModifyRequestTransfer,
(void **)&pdusessionTransfer_p,
item_p->pDUSessionResourceModifyRequestTransfer.buf,
......@@ -1709,7 +1715,7 @@ int ngap_gNB_handle_pdusession_modify_request(uint32_t assoc_id,
qosFlowItem_p = pdusessionTransfer_ies->value.choice.QosFlowAddOrModifyRequestList.list.array[qosIdx];
/* Set the QOS informations */
NGAP_PDUSESSION_MODIFY_REQ(message_p).pdusession_modify_params[i].qos[qosIdx].qci = (uint8_t)qosFlowItem_p->qosFlowIdentifier;
NGAP_PDUSESSION_MODIFY_REQ(message_p).pdusession_modify_params[i].qos[qosIdx].qfi = (uint8_t)qosFlowItem_p->qosFlowIdentifier;
if(qosFlowItem_p->qosFlowLevelQosParameters) {
NGAP_PDUSESSION_MODIFY_REQ(message_p).pdusession_modify_params[i].qos[qosIdx].allocation_retention_priority.priority_level =
qosFlowItem_p->qosFlowLevelQosParameters->allocationAndRetentionPriority.priorityLevelARP;
......
......@@ -344,11 +344,11 @@ int ngap_gNB_handle_nas_downlink(uint32_t assoc_id,
DevAssert(pdu != NULL);
/* UE-related procedure -> stream != 0 */
if (stream == 0) {
NGAP_ERROR("[SCTP %d] Received UE-related procedure on stream == 0\n",
assoc_id);
return -1;
}
// if (stream == 0) {
// NGAP_ERROR("[SCTP %d] Received UE-related procedure on stream == 0\n",
// assoc_id);
// return -1;
// }
if ((amf_desc_p = ngap_gNB_get_AMF(NULL, assoc_id, 0)) == NULL) {
NGAP_ERROR(
......@@ -469,6 +469,7 @@ int ngap_gNB_nas_uplink(instance_t instance, ngap_uplink_nas_t *ngap_uplink_nas_
/* Prepare the NGAP message to encode */
memset(&pdu, 0, sizeof(pdu));
pdu.present = NGAP_NGAP_PDU_PR_initiatingMessage;
pdu.choice.initiatingMessage = (NGAP_InitiatingMessage_t *)calloc(1,sizeof(NGAP_InitiatingMessage_t));
pdu.choice.initiatingMessage->procedureCode = NGAP_ProcedureCode_id_UplinkNASTransport;
pdu.choice.initiatingMessage->criticality = NGAP_Criticality_ignore;
pdu.choice.initiatingMessage->value.present = NGAP_InitiatingMessage__value_PR_UplinkNASTransport;
......@@ -503,6 +504,7 @@ int ngap_gNB_nas_uplink(instance_t instance, ngap_uplink_nas_t *ngap_uplink_nas_
ie->value.present = NGAP_UplinkNASTransport_IEs__value_PR_UserLocationInformation;
ie->value.choice.UserLocationInformation.present = NGAP_UserLocationInformation_PR_userLocationInformationNR;
ie->value.choice.UserLocationInformation.choice.userLocationInformationNR = CALLOC(1,sizeof(struct NGAP_UserLocationInformationNR));
userinfo_nr_p = ie->value.choice.UserLocationInformation.choice.userLocationInformationNR;
/* Set nRCellIdentity. default userLocationInformationNR */
......@@ -579,6 +581,7 @@ int ngap_gNB_nas_non_delivery_ind(instance_t instance,
/* Prepare the NGAP message to encode */
memset(&pdu, 0, sizeof(pdu));
pdu.present = NGAP_NGAP_PDU_PR_initiatingMessage;
pdu.choice.initiatingMessage = (NGAP_InitiatingMessage_t *)calloc(1,sizeof(NGAP_InitiatingMessage_t));
pdu.choice.initiatingMessage->procedureCode = NGAP_ProcedureCode_id_NASNonDeliveryIndication;
pdu.choice.initiatingMessage->criticality = NGAP_Criticality_ignore;
pdu.choice.initiatingMessage->value.present = NGAP_InitiatingMessage__value_PR_NASNonDeliveryIndication;
......@@ -685,6 +688,7 @@ int ngap_gNB_initial_ctxt_resp(
/* Prepare the NGAP message to encode */
memset(&pdu, 0, sizeof(pdu));
pdu.present = NGAP_NGAP_PDU_PR_successfulOutcome;
pdu.choice.successfulOutcome = (NGAP_SuccessfulOutcome_t *)calloc(1,sizeof(struct NGAP_SuccessfulOutcome));
pdu.choice.successfulOutcome->procedureCode = NGAP_ProcedureCode_id_InitialContextSetup;
pdu.choice.successfulOutcome->criticality = NGAP_Criticality_reject;
pdu.choice.successfulOutcome->value.present = NGAP_SuccessfulOutcome__value_PR_InitialContextSetupResponse;
......@@ -710,67 +714,68 @@ int ngap_gNB_initial_ctxt_resp(
ie->criticality = NGAP_Criticality_ignore;
ie->value.present = NGAP_InitialContextSetupResponseIEs__value_PR_PDUSessionResourceSetupListCxtRes;
for (i = 0; i < initial_ctxt_resp_p->nb_of_pdusessions; i++) {
NGAP_PDUSessionResourceSetupItemCxtRes_t *item;
NGAP_PDUSessionResourceSetupResponseTransfer_t *pdusessionTransfer_p = NULL;
/* mandatory */
item = (NGAP_PDUSessionResourceSetupItemCxtRes_t *)calloc(1, sizeof(NGAP_PDUSessionResourceSetupItemCxtRes_t));
if (initial_ctxt_resp_p->nb_of_pdusessions){
for (i = 0; i < initial_ctxt_resp_p->nb_of_pdusessions; i++) {
NGAP_PDUSessionResourceSetupItemCxtRes_t *item;
NGAP_PDUSessionResourceSetupResponseTransfer_t *pdusessionTransfer_p = NULL;
/* pDUSessionID */
item->pDUSessionID = initial_ctxt_resp_p->pdusessions[i].pdusession_id;
/* mandatory */
item = (NGAP_PDUSessionResourceSetupItemCxtRes_t *)calloc(1, sizeof(NGAP_PDUSessionResourceSetupItemCxtRes_t));
/* dLQosFlowPerTNLInformation */
pdusessionTransfer_p = (NGAP_PDUSessionResourceSetupResponseTransfer_t *)calloc(1, sizeof(NGAP_PDUSessionResourceSetupResponseTransfer_t));
/* pDUSessionID */
item->pDUSessionID = initial_ctxt_resp_p->pdusessions[i].pdusession_id;
/* dLQosFlowPerTNLInformation */
pdusessionTransfer_p = (NGAP_PDUSessionResourceSetupResponseTransfer_t *)calloc(1, sizeof(NGAP_PDUSessionResourceSetupResponseTransfer_t));
pdusessionTransfer_p->dLQosFlowPerTNLInformation.uPTransportLayerInformation.present = NGAP_UPTransportLayerInformation_PR_gTPTunnel;
pdusessionTransfer_p->dLQosFlowPerTNLInformation.uPTransportLayerInformation.present = NGAP_UPTransportLayerInformation_PR_gTPTunnel;
GTP_TEID_TO_ASN1(initial_ctxt_resp_p->pdusessions[i].gtp_teid, &pdusessionTransfer_p->dLQosFlowPerTNLInformation.uPTransportLayerInformation.choice.gTPTunnel->gTP_TEID);
pdusessionTransfer_p->dLQosFlowPerTNLInformation.uPTransportLayerInformation.choice.gTPTunnel->transportLayerAddress.buf = malloc(initial_ctxt_resp_p->pdusessions[i].gNB_addr.length);
memcpy(pdusessionTransfer_p->dLQosFlowPerTNLInformation.uPTransportLayerInformation.choice.gTPTunnel->transportLayerAddress.buf,
initial_ctxt_resp_p->pdusessions[i].gNB_addr.buffer,
initial_ctxt_resp_p->pdusessions[i].gNB_addr.length);
pdusessionTransfer_p->dLQosFlowPerTNLInformation.uPTransportLayerInformation.choice.gTPTunnel->transportLayerAddress.size = initial_ctxt_resp_p->pdusessions[i].gNB_addr.length;
pdusessionTransfer_p->dLQosFlowPerTNLInformation.uPTransportLayerInformation.choice.gTPTunnel->transportLayerAddress.bits_unused = 0;
NGAP_DEBUG("initial_ctxt_resp_p: pdusession ID %ld, gnb_addr %d.%d.%d.%d, SIZE %ld \n",
item->pDUSessionID,
pdusessionTransfer_p->dLQosFlowPerTNLInformation.uPTransportLayerInformation.choice.gTPTunnel->transportLayerAddress.buf[0],
pdusessionTransfer_p->dLQosFlowPerTNLInformation.uPTransportLayerInformation.choice.gTPTunnel->transportLayerAddress.buf[1],
pdusessionTransfer_p->dLQosFlowPerTNLInformation.uPTransportLayerInformation.choice.gTPTunnel->transportLayerAddress.buf[2],
pdusessionTransfer_p->dLQosFlowPerTNLInformation.uPTransportLayerInformation.choice.gTPTunnel->transportLayerAddress.buf[3],
pdusessionTransfer_p->dLQosFlowPerTNLInformation.uPTransportLayerInformation.choice.gTPTunnel->transportLayerAddress.size);
/* associatedQosFlowList. number of 1? */
for(int j=0; j < initial_ctxt_resp_p->pdusessions[i].nb_of_qos_flow; j++) {
NGAP_AssociatedQosFlowItem_t *ass_qos_item_p;
ass_qos_item_p = (NGAP_AssociatedQosFlowItem_t *)calloc(1, sizeof(NGAP_AssociatedQosFlowItem_t));
/* qosFlowIdentifier */
ass_qos_item_p->qosFlowIdentifier = initial_ctxt_resp_p->pdusessions[i].associated_qos_flows[j].qci;
/* qosFlowMappingIndication */
if(initial_ctxt_resp_p->pdusessions[i].associated_qos_flows[j].qos_flow_mapping_ind != QOSFLOW_MAPPING_INDICATION_NON) {
ass_qos_item_p->qosFlowMappingIndication = malloc(sizeof(*ass_qos_item_p->qosFlowMappingIndication));
*ass_qos_item_p->qosFlowMappingIndication = initial_ctxt_resp_p->pdusessions[i].associated_qos_flows[j].qos_flow_mapping_ind;
GTP_TEID_TO_ASN1(initial_ctxt_resp_p->pdusessions[i].gtp_teid, &pdusessionTransfer_p->dLQosFlowPerTNLInformation.uPTransportLayerInformation.choice.gTPTunnel->gTP_TEID);
pdusessionTransfer_p->dLQosFlowPerTNLInformation.uPTransportLayerInformation.choice.gTPTunnel->transportLayerAddress.buf = malloc(initial_ctxt_resp_p->pdusessions[i].gNB_addr.length);
memcpy(pdusessionTransfer_p->dLQosFlowPerTNLInformation.uPTransportLayerInformation.choice.gTPTunnel->transportLayerAddress.buf,
initial_ctxt_resp_p->pdusessions[i].gNB_addr.buffer,
initial_ctxt_resp_p->pdusessions[i].gNB_addr.length);
pdusessionTransfer_p->dLQosFlowPerTNLInformation.uPTransportLayerInformation.choice.gTPTunnel->transportLayerAddress.size = initial_ctxt_resp_p->pdusessions[i].gNB_addr.length;
pdusessionTransfer_p->dLQosFlowPerTNLInformation.uPTransportLayerInformation.choice.gTPTunnel->transportLayerAddress.bits_unused = 0;
NGAP_DEBUG("initial_ctxt_resp_p: pdusession ID %ld, gnb_addr %d.%d.%d.%d, SIZE %ld \n",
item->pDUSessionID,
pdusessionTransfer_p->dLQosFlowPerTNLInformation.uPTransportLayerInformation.choice.gTPTunnel->transportLayerAddress.buf[0],
pdusessionTransfer_p->dLQosFlowPerTNLInformation.uPTransportLayerInformation.choice.gTPTunnel->transportLayerAddress.buf[1],
pdusessionTransfer_p->dLQosFlowPerTNLInformation.uPTransportLayerInformation.choice.gTPTunnel->transportLayerAddress.buf[2],
pdusessionTransfer_p->dLQosFlowPerTNLInformation.uPTransportLayerInformation.choice.gTPTunnel->transportLayerAddress.buf[3],
pdusessionTransfer_p->dLQosFlowPerTNLInformation.uPTransportLayerInformation.choice.gTPTunnel->transportLayerAddress.size);
/* associatedQosFlowList. number of 1? */
for(int j=0; j < initial_ctxt_resp_p->pdusessions[i].nb_of_qos_flow; j++) {
NGAP_AssociatedQosFlowItem_t *ass_qos_item_p;
ass_qos_item_p = (NGAP_AssociatedQosFlowItem_t *)calloc(1, sizeof(NGAP_AssociatedQosFlowItem_t));
/* qosFlowIdentifier */
ass_qos_item_p->qosFlowIdentifier = initial_ctxt_resp_p->pdusessions[i].associated_qos_flows[j].qfi;
/* qosFlowMappingIndication */
if(initial_ctxt_resp_p->pdusessions[i].associated_qos_flows[j].qos_flow_mapping_ind != QOSFLOW_MAPPING_INDICATION_NON) {
ass_qos_item_p->qosFlowMappingIndication = malloc(sizeof(*ass_qos_item_p->qosFlowMappingIndication));
*ass_qos_item_p->qosFlowMappingIndication = initial_ctxt_resp_p->pdusessions[i].associated_qos_flows[j].qos_flow_mapping_ind;
}
ASN_SEQUENCE_ADD(&pdusessionTransfer_p->dLQosFlowPerTNLInformation.associatedQosFlowList.list, ass_qos_item_p);
}
ASN_SEQUENCE_ADD(&pdusessionTransfer_p->dLQosFlowPerTNLInformation.associatedQosFlowList.list, ass_qos_item_p);
}
memset(&res, 0, sizeof(res));
res = asn_encode_to_new_buffer(NULL, ATS_ALIGNED_CANONICAL_PER, &asn_DEF_NGAP_PDUSessionResourceSetupResponseTransfer, pdusessionTransfer_p);
item->pDUSessionResourceSetupResponseTransfer.buf = res.buffer;
item->pDUSessionResourceSetupResponseTransfer.size = res.result.encoded;
memset(&res, 0, sizeof(res));
res = asn_encode_to_new_buffer(NULL, ATS_ALIGNED_CANONICAL_PER, &asn_DEF_NGAP_PDUSessionResourceSetupResponseTransfer, pdusessionTransfer_p);
item->pDUSessionResourceSetupResponseTransfer.buf = res.buffer;
item->pDUSessionResourceSetupResponseTransfer.size = res.result.encoded;
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_NGAP_PDUSessionResourceSetupResponseTransfer, pdusessionTransfer_p);
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_NGAP_PDUSessionResourceSetupResponseTransfer, pdusessionTransfer_p);
ASN_SEQUENCE_ADD(&ie->value.choice.PDUSessionResourceSetupListCxtRes.list, item);
}
ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
ASN_SEQUENCE_ADD(&ie->value.choice.PDUSessionResourceSetupListCxtRes.list, item);
}
ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
}
/* optional */
if (initial_ctxt_resp_p->nb_of_pdusessions_failed) {
ie = (NGAP_InitialContextSetupResponseIEs_t *)calloc(1, sizeof(NGAP_InitialContextSetupResponseIEs_t));
......@@ -903,6 +908,7 @@ int ngap_gNB_ue_capabilities(instance_t instance,
/* Prepare the NGAP message to encode */
memset(&pdu, 0, sizeof(pdu));
pdu.present = NGAP_NGAP_PDU_PR_initiatingMessage;
pdu.choice.initiatingMessage = (NGAP_InitiatingMessage_t *)calloc(1,sizeof(NGAP_InitiatingMessage_t));
pdu.choice.initiatingMessage->procedureCode = NGAP_ProcedureCode_id_UERadioCapabilityInfoIndication;
pdu.choice.initiatingMessage->criticality = NGAP_Criticality_ignore;
pdu.choice.initiatingMessage->value.present = NGAP_InitiatingMessage__value_PR_UERadioCapabilityInfoIndication;
......@@ -996,6 +1002,7 @@ int ngap_gNB_pdusession_setup_resp(instance_t instance,
/* Prepare the NGAP message to encode */
memset(&pdu, 0, sizeof(pdu));
pdu.present = NGAP_NGAP_PDU_PR_successfulOutcome;
pdu.choice.successfulOutcome = (NGAP_SuccessfulOutcome_t *)calloc(1,sizeof(struct NGAP_SuccessfulOutcome));
pdu.choice.successfulOutcome->procedureCode = NGAP_ProcedureCode_id_PDUSessionResourceSetup;
pdu.choice.successfulOutcome->criticality = NGAP_Criticality_reject;
pdu.choice.successfulOutcome->value.present = NGAP_SuccessfulOutcome__value_PR_PDUSessionResourceSetupResponse;
......@@ -1036,6 +1043,8 @@ int ngap_gNB_pdusession_setup_resp(instance_t instance,
pdusessionTransfer_p = (NGAP_PDUSessionResourceSetupResponseTransfer_t *)calloc(1, sizeof(NGAP_PDUSessionResourceSetupResponseTransfer_t));
pdusessionTransfer_p->dLQosFlowPerTNLInformation.uPTransportLayerInformation.present = NGAP_UPTransportLayerInformation_PR_gTPTunnel;
pdusessionTransfer_p->dLQosFlowPerTNLInformation.uPTransportLayerInformation.choice.gTPTunnel =
calloc(1, sizeof(struct NGAP_GTPTunnel));
GTP_TEID_TO_ASN1(pdusession_setup_resp_p->pdusessions[i].gtp_teid, &pdusessionTransfer_p->dLQosFlowPerTNLInformation.uPTransportLayerInformation.choice.gTPTunnel->gTP_TEID);
......@@ -1061,20 +1070,28 @@ int ngap_gNB_pdusession_setup_resp(instance_t instance,
ass_qos_item_p = (NGAP_AssociatedQosFlowItem_t *)calloc(1, sizeof(NGAP_AssociatedQosFlowItem_t));
/* qosFlowIdentifier */
ass_qos_item_p->qosFlowIdentifier = pdusession_setup_resp_p->pdusessions[i].associated_qos_flows[j].qci;
ass_qos_item_p->qosFlowIdentifier = pdusession_setup_resp_p->pdusessions[i].associated_qos_flows[j].qfi;
/* qosFlowMappingIndication */
if(pdusession_setup_resp_p->pdusessions[i].associated_qos_flows[j].qos_flow_mapping_ind != QOSFLOW_MAPPING_INDICATION_NON) {
ass_qos_item_p->qosFlowMappingIndication = malloc(sizeof(*ass_qos_item_p->qosFlowMappingIndication));
*ass_qos_item_p->qosFlowMappingIndication = pdusession_setup_resp_p->pdusessions[i].associated_qos_flows[j].qos_flow_mapping_ind;
}
//if(pdusession_setup_resp_p->pdusessions[i].associated_qos_flows[j].qos_flow_mapping_ind != QOSFLOW_MAPPING_INDICATION_NON) {
// ass_qos_item_p->qosFlowMappingIndication = malloc(sizeof(*ass_qos_item_p->qosFlowMappingIndication));
// *ass_qos_item_p->qosFlowMappingIndication = pdusession_setup_resp_p->pdusessions[i].associated_qos_flows[j].qos_flow_mapping_ind;
//}
ASN_SEQUENCE_ADD(&pdusessionTransfer_p->dLQosFlowPerTNLInformation.associatedQosFlowList.list, ass_qos_item_p);
}
memset(&res, 0, sizeof(res));
res = asn_encode_to_new_buffer(NULL, ATS_ALIGNED_CANONICAL_PER, &asn_DEF_NGAP_PDUSessionResourceSetupResponseTransfer, pdusessionTransfer_p);
item->pDUSessionResourceSetupResponseTransfer.buf = res.buffer;
item->pDUSessionResourceSetupResponseTransfer.size = res.result.encoded;
// res = asn_encode_to_new_buffer(NULL, ATS_ALIGNED_CANONICAL_PER, &asn_DEF_NGAP_PDUSessionResourceSetupResponseTransfer, pdusessionTransfer_p);
// item->pDUSessionResourceSetupResponseTransfer.buf = res.buffer;
// item->pDUSessionResourceSetupResponseTransfer.size = res.result.encoded;
uint8_t buffer[100];
asn_enc_rval_t enc_rval = aper_encode_to_buffer(&asn_DEF_NGAP_PDUSessionResourceSetupResponseTransfer,
NULL,
pdusessionTransfer_p,
buffer,100);
AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n", enc_rval.failed_type->name, enc_rval.encoded);
item->pDUSessionResourceSetupResponseTransfer.buf = buffer;
item->pDUSessionResourceSetupResponseTransfer.size = enc_rval.encoded;
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_NGAP_PDUSessionResourceSetupResponseTransfer, pdusessionTransfer_p);
......@@ -1218,6 +1235,7 @@ int ngap_gNB_pdusession_modify_resp(instance_t instance,
/* Prepare the NGAP message to encode */
memset(&pdu, 0, sizeof(pdu));
pdu.present = NGAP_NGAP_PDU_PR_successfulOutcome;
pdu.choice.successfulOutcome = (NGAP_SuccessfulOutcome_t *)calloc(1,sizeof(struct NGAP_SuccessfulOutcome));
pdu.choice.successfulOutcome->procedureCode = NGAP_ProcedureCode_id_PDUSessionResourceModify;
pdu.choice.successfulOutcome->criticality = NGAP_Criticality_reject;
pdu.choice.successfulOutcome->value.present = NGAP_SuccessfulOutcome__value_PR_PDUSessionResourceModifyResponse;
......@@ -1378,6 +1396,7 @@ int ngap_gNB_pdusession_release_resp(instance_t instance,
/* Prepare the NGAP message to encode */
memset(&pdu, 0, sizeof(pdu));
pdu.present = NGAP_NGAP_PDU_PR_successfulOutcome;
pdu.choice.successfulOutcome = (NGAP_SuccessfulOutcome_t *)calloc(1,sizeof(struct NGAP_SuccessfulOutcome));
pdu.choice.successfulOutcome->procedureCode = NGAP_ProcedureCode_id_PDUSessionResourceRelease;
pdu.choice.successfulOutcome->criticality = NGAP_Criticality_reject;
pdu.choice.successfulOutcome->value.present = NGAP_SuccessfulOutcome__value_PR_PDUSessionResourceReleaseResponse;
......
......@@ -82,8 +82,8 @@ struct ngap_gNB_ue_context_s *ngap_gNB_get_ue_context(
memset(&temp, 0, sizeof(struct ngap_gNB_ue_context_s));
/* gNB ue ngap id = 24 bits wide */
temp.gNB_ue_ngap_id = gNB_ue_ngap_id & 0x00FFFFFF;
/* gNB ue ngap id = 32 bits wide */
temp.gNB_ue_ngap_id = gNB_ue_ngap_id & 0xFFFFFFFF;
return RB_FIND(ngap_ue_map, &instance_p->ngap_ue_head, &temp);
}
......
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