Commit 9dc3f4f6 authored by Robert Schmidt's avatar Robert Schmidt

Merge remote-tracking branch 'origin/rework-ngap' into integration_2023_w11b

parents f97d002c 0b7da436
...@@ -169,7 +169,7 @@ gNBs = ...@@ -169,7 +169,7 @@ gNBs =
////////// AMF parameters: ////////// AMF parameters:
amf_ip_address = ( { ipv4 = "192.168.5.233"; amf_ip_address = ( { ipv4 = "192.168.70.132";
ipv6 = "192:168:30::17"; ipv6 = "192:168:30::17";
active = "yes"; active = "yes";
preference = "ipv4"; preference = "ipv4";
...@@ -178,11 +178,10 @@ gNBs = ...@@ -178,11 +178,10 @@ gNBs =
NETWORK_INTERFACES : NETWORK_INTERFACES :
{ {
GNB_INTERFACE_NAME_FOR_NG_AMF = "demo-oai";
GNB_INTERFACE_NAME_FOR_NG_AMF = "eth0"; GNB_IPV4_ADDRESS_FOR_NG_AMF = "192.168.70.129/24";
GNB_IPV4_ADDRESS_FOR_NG_AMF = "CI_GNB_IP_ADDR"; GNB_INTERFACE_NAME_FOR_NGU = "demo-oai";
GNB_INTERFACE_NAME_FOR_NGU = "eth0"; GNB_IPV4_ADDRESS_FOR_NGU = "192.168.70.129/24";
GNB_IPV4_ADDRESS_FOR_NGU = "CI_GNB_IP_ADDR";
GNB_PORT_FOR_S1U = 2152; # Spec 2152 GNB_PORT_FOR_S1U = 2152; # Spec 2152
}; };
} }
......
...@@ -54,4 +54,7 @@ typedef enum { CPtype = 0, UPtype } E1_t; ...@@ -54,4 +54,7 @@ typedef enum { CPtype = 0, UPtype } E1_t;
#define NODE_IS_DU(nOdE_TyPe) ((nOdE_TyPe) == ngran_eNB_DU || (nOdE_TyPe) == ngran_gNB_DU) #define NODE_IS_DU(nOdE_TyPe) ((nOdE_TyPe) == ngran_eNB_DU || (nOdE_TyPe) == ngran_gNB_DU)
#define NODE_IS_MBMS(nOdE_TyPe) ((nOdE_TyPe) == ngran_eNB_MBMS_STA) #define NODE_IS_MBMS(nOdE_TyPe) ((nOdE_TyPe) == ngran_eNB_MBMS_STA)
#define GTPV1_U_PORT_NUMBER (2152) #define GTPV1_U_PORT_NUMBER (2152)
typedef enum { non_dynamic, dynamic } fiveQI_type_t;
#define maxSRBs 4
#endif #endif
...@@ -49,7 +49,7 @@ static int get_single_ue_rnti(void) ...@@ -49,7 +49,7 @@ static int get_single_ue_rnti(void)
return -1; return -1;
// verify it exists in RRC as well // verify it exists in RRC as well
rrc_gNB_ue_context_t *rrcue = rrc_gNB_get_ue_context(RC.nrrrc[0], ue->rnti); rrc_gNB_ue_context_t *rrcue = rrc_gNB_get_ue_context_by_rnti(RC.nrrrc[0], ue->rnti);
if (!rrcue) if (!rrcue)
return -1; return -1;
...@@ -82,7 +82,7 @@ int get_reestab_count(char *buf, int debug, telnet_printfunc_t prnt) ...@@ -82,7 +82,7 @@ int get_reestab_count(char *buf, int debug, telnet_printfunc_t prnt)
ERROR_MSG_RET("RNTI needs to be [1,0xfffe]\n"); ERROR_MSG_RET("RNTI needs to be [1,0xfffe]\n");
} }
rrc_gNB_ue_context_t *ue = rrc_gNB_get_ue_context(RC.nrrrc[0], rnti); rrc_gNB_ue_context_t *ue = rrc_gNB_get_ue_context_by_rnti(RC.nrrrc[0], rnti);
if (!ue) if (!ue)
ERROR_MSG_RET("could not find UE with RNTI %04x\n", rnti); ERROR_MSG_RET("could not find UE with RNTI %04x\n", rnti);
...@@ -107,7 +107,7 @@ int trigger_reestab(char *buf, int debug, telnet_printfunc_t prnt) ...@@ -107,7 +107,7 @@ int trigger_reestab(char *buf, int debug, telnet_printfunc_t prnt)
} }
// verify it exists in RRC as well // verify it exists in RRC as well
rrc_gNB_ue_context_t *rrcue = rrc_gNB_get_ue_context(RC.nrrrc[0], rnti); rrc_gNB_ue_context_t *rrcue = rrc_gNB_get_ue_context_by_rnti(RC.nrrrc[0], rnti);
if (!rrcue) if (!rrcue)
ERROR_MSG_RET("could not find UE with RNTI %04x\n", rnti); ERROR_MSG_RET("could not find UE with RNTI %04x\n", rnti);
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#ifndef E1AP_MESSAGES_TYPES_H #ifndef E1AP_MESSAGES_TYPES_H
#define E1AP_MESSAGES_TYPES_H #define E1AP_MESSAGES_TYPES_H
#include "common/ngran_types.h"
#include "f1ap_messages_types.h" #include "f1ap_messages_types.h"
#include "ngap_messages_types.h" #include "ngap_messages_types.h"
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#ifndef NGAP_MESSAGES_TYPES_H_ #ifndef NGAP_MESSAGES_TYPES_H_
#define NGAP_MESSAGES_TYPES_H_ #define NGAP_MESSAGES_TYPES_H_
#include "common/ngran_types.h"
#include "LTE_asn_constant.h" #include "LTE_asn_constant.h"
//-------------------------------------------------------------------------------------------// //-------------------------------------------------------------------------------------------//
// Defines to access message fields. // Defines to access message fields.
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
#define NGAP_UE_CTXT_MODIFICATION_RESP(mSGpTR) (mSGpTR)->ittiMsg.ngap_ue_ctxt_modification_resp #define NGAP_UE_CTXT_MODIFICATION_RESP(mSGpTR) (mSGpTR)->ittiMsg.ngap_ue_ctxt_modification_resp
#define NGAP_UE_CTXT_MODIFICATION_FAIL(mSGpTR) (mSGpTR)->ittiMsg.ngap_ue_ctxt_modification_fail #define NGAP_UE_CTXT_MODIFICATION_FAIL(mSGpTR) (mSGpTR)->ittiMsg.ngap_ue_ctxt_modification_fail
#define NGAP_PDUSESSION_SETUP_RESP(mSGpTR) (mSGpTR)->ittiMsg.ngap_pdusession_setup_resp #define NGAP_PDUSESSION_SETUP_RESP(mSGpTR) (mSGpTR)->ittiMsg.ngap_pdusession_setup_resp
#define NGAP_PDUSESSION_SETUP_FAIL(mSGpTR) (mSGpTR)->ittiMsg.ngap_pdusession_setup_req_fail #define NGAP_PDUSESSION_SETUP_FAIL(mSGpTR) (mSGpTR)->ittiMsg.ngap_pdusession_setup_request_fail
#define NGAP_PDUSESSION_MODIFY_RESP(mSGpTR) (mSGpTR)->ittiMsg.ngap_pdusession_modify_resp #define NGAP_PDUSESSION_MODIFY_RESP(mSGpTR) (mSGpTR)->ittiMsg.ngap_pdusession_modify_resp
#define NGAP_PATH_SWITCH_REQ(mSGpTR) (mSGpTR)->ittiMsg.ngap_path_switch_req #define NGAP_PATH_SWITCH_REQ(mSGpTR) (mSGpTR)->ittiMsg.ngap_path_switch_req
#define NGAP_PATH_SWITCH_REQ_ACK(mSGpTR) (mSGpTR)->ittiMsg.ngap_path_switch_req_ack #define NGAP_PATH_SWITCH_REQ_ACK(mSGpTR) (mSGpTR)->ittiMsg.ngap_path_switch_req_ack
...@@ -194,6 +194,13 @@ typedef enum ngap_rrc_establishment_cause_e { ...@@ -194,6 +194,13 @@ typedef enum ngap_rrc_establishment_cause_e {
NGAP_RRC_CAUSE_LAST NGAP_RRC_CAUSE_LAST
} ngap_rrc_establishment_cause_t; } ngap_rrc_establishment_cause_t;
typedef struct pdusession_level_qos_parameter_s {
uint8_t qfi;
uint64_t fiveQI;
fiveQI_type_t fiveQI_type;
ngap_allocation_retention_priority_t allocation_retention_priority;
} pdusession_level_qos_parameter_t;
typedef struct ngap_guami_s { typedef struct ngap_guami_s {
uint16_t mcc; uint16_t mcc;
uint16_t mnc; uint16_t mnc;
...@@ -242,7 +249,7 @@ typedef struct ngap_nas_pdu_s { ...@@ -242,7 +249,7 @@ typedef struct ngap_nas_pdu_s {
uint8_t *buffer; uint8_t *buffer;
/* Length of the octet string */ /* Length of the octet string */
uint32_t length; uint32_t length;
} ngap_nas_pdu_t, ngap_ue_radio_cap_t; } ngap_pdu_t;
typedef struct ngap_mobility_restriction_s{ typedef struct ngap_mobility_restriction_s{
ngap_plmn_identity_t serving_plmn; ngap_plmn_identity_t serving_plmn;
...@@ -267,34 +274,14 @@ typedef struct ngap_transport_layer_addr_s { ...@@ -267,34 +274,14 @@ typedef struct ngap_transport_layer_addr_s {
uint8_t buffer[20]; // in network byte order uint8_t buffer[20]; // in network byte order
} ngap_transport_layer_addr_t; } ngap_transport_layer_addr_t;
#define TRANSPORT_LAYER_ADDR_COPY(dEST,sOURCE) \
do { \
AssertFatal(sOURCE.len <= 20); \
memcpy(dEST.buffer, sOURCE.buffer, sOURCE.len); \
dEST.length = sOURCE.length; \
} while (0)
typedef enum {
non_dynamic,
dynamic
} fiveQI_type_t;
typedef struct pdusession_level_qos_parameter_s {
uint8_t qfi;
uint64_t fiveQI;
fiveQI_type_t fiveQI_type;
ngap_allocation_retention_priority_t allocation_retention_priority;
} pdusession_level_qos_parameter_t;
typedef struct pdusession_s { typedef struct pdusession_s {
/* Unique pdusession_id for the UE. */ /* Unique pdusession_id for the UE. */
uint8_t pdusession_id; int pdusession_id;
ngap_pdu_t nas_pdu;
ngap_pdu_t pdusessionTransfer;
uint8_t nb_qos; uint8_t nb_qos;
/* Quality of service for this pdusession */ /* Quality of service for this pdusession */
pdusession_level_qos_parameter_t qos[QOSFLOW_MAX_VALUE]; pdusession_level_qos_parameter_t qos[QOSFLOW_MAX_VALUE];
/* The NAS PDU should be forwarded by the RRC layer to the NAS layer */
ngap_nas_pdu_t nas_pdu;
/* The transport layer address for the IP packets */ /* The transport layer address for the IP packets */
ngap_transport_layer_addr_t upf_addr; ngap_transport_layer_addr_t upf_addr;
/* S-GW Tunnel endpoint identifier */ /* S-GW Tunnel endpoint identifier */
...@@ -303,7 +290,6 @@ typedef struct pdusession_s { ...@@ -303,7 +290,6 @@ typedef struct pdusession_s {
uint8_t used_drbs[NGAP_MAX_DRBS_PER_UE]; uint8_t used_drbs[NGAP_MAX_DRBS_PER_UE];
} pdusession_t; } pdusession_t;
typedef enum pdusession_qosflow_mapping_ind_e{ typedef enum pdusession_qosflow_mapping_ind_e{
QOSFLOW_MAPPING_INDICATION_UL = 0, QOSFLOW_MAPPING_INDICATION_UL = 0,
QOSFLOW_MAPPING_INDICATION_DL = 1, QOSFLOW_MAPPING_INDICATION_DL = 1,
...@@ -313,7 +299,7 @@ typedef enum pdusession_qosflow_mapping_ind_e{ ...@@ -313,7 +299,7 @@ typedef enum pdusession_qosflow_mapping_ind_e{
typedef struct pdusession_associate_qosflow_s{ typedef struct pdusession_associate_qosflow_s{
uint8_t qfi; uint8_t qfi;
pdusession_qosflow_mapping_ind_t qos_flow_mapping_ind; pdusession_qosflow_mapping_ind_t qos_flow_mapping_ind;
}pdusession_associate_qosflow_t; } pdusession_associate_qosflow_t;
typedef struct pdusession_setup_s { typedef struct pdusession_setup_s {
/* Unique pdusession_id for the UE. */ /* Unique pdusession_id for the UE. */
...@@ -332,36 +318,6 @@ typedef struct pdusession_setup_s { ...@@ -332,36 +318,6 @@ typedef struct pdusession_setup_s {
pdusession_associate_qosflow_t associated_qos_flows[QOSFLOW_MAX_VALUE]; pdusession_associate_qosflow_t associated_qos_flows[QOSFLOW_MAX_VALUE];
} pdusession_setup_t; } pdusession_setup_t;
typedef struct pdusession_tobe_added_s {
/* Unique pdusession_id for the UE. */
uint8_t pdusession_id;
/* Unique drb_ID for the UE. */
uint8_t drb_ID;
/* The transport layer address for the IP packets */
ngap_transport_layer_addr_t upf_addr;
/* S-GW Tunnel endpoint identifier */
uint32_t gtp_teid;
} pdusession_tobe_added_t;
typedef struct pdusession_admitted_tobe_added_s {
/* Unique pdusession_id for the UE. */
uint8_t pdusession_id;
/* Unique drb_ID for the UE. */
uint8_t drb_ID;
/* The transport layer address for the IP packets */
ngap_transport_layer_addr_t gnb_addr;
/* S-GW Tunnel endpoint identifier */
uint32_t gtp_teid;
} pdusession_admitted_tobe_added_t;
typedef struct pdusession_tobeswitched_s { typedef struct pdusession_tobeswitched_s {
/* Unique pdusession_id for the UE. */ /* Unique pdusession_id for the UE. */
uint8_t pdusession_id; uint8_t pdusession_id;
...@@ -394,8 +350,11 @@ typedef enum ngap_Cause_e { ...@@ -394,8 +350,11 @@ typedef enum ngap_Cause_e {
NGAP_CAUSE_NAS, NGAP_CAUSE_NAS,
NGAP_CAUSE_PROTOCOL, NGAP_CAUSE_PROTOCOL,
NGAP_CAUSE_MISC, NGAP_CAUSE_MISC,
/* Extensions may appear below */ NGAP_Cause_PR_choice_ExtensionS,
//Evilish manual duplicate of asn.1 grammar
//because it is human work, whereas it can be generated by machine
//and because humans manual copy creates bugs
//and we create multiple names for the same thing, that is a source of confusion
} ngap_Cause_t; } ngap_Cause_t;
typedef enum ngap_Cause_radio_network_e { typedef enum ngap_Cause_radio_network_e {
...@@ -453,7 +412,6 @@ typedef struct pdusession_failed_s { ...@@ -453,7 +412,6 @@ typedef struct pdusession_failed_s {
/* Unique pdusession_id for the UE. */ /* Unique pdusession_id for the UE. */
uint8_t pdusession_id; uint8_t pdusession_id;
/* Cause of the failure */ /* Cause of the failure */
// cause_t cause;
ngap_Cause_t cause; ngap_Cause_t cause;
uint8_t cause_value; uint8_t cause_value;
} pdusession_failed_t; } pdusession_failed_t;
...@@ -541,7 +499,7 @@ typedef struct ngap_deregistered_gnb_ind_s { ...@@ -541,7 +499,7 @@ typedef struct ngap_deregistered_gnb_ind_s {
*/ */
typedef struct ngap_nas_first_req_s { typedef struct ngap_nas_first_req_s {
/* UE id for initial connection to NGAP */ /* UE id for initial connection to NGAP */
uint16_t ue_initial_id; uint32_t gNB_ue_ngap_id;
/* the chosen PLMN identity as index, see TS 36.331 6.2.2 RRC Connection /* the chosen PLMN identity as index, see TS 36.331 6.2.2 RRC Connection
* Setup Complete. This index here is zero-based, unlike the standard! */ * Setup Complete. This index here is zero-based, unlike the standard! */
...@@ -551,7 +509,7 @@ typedef struct ngap_nas_first_req_s { ...@@ -551,7 +509,7 @@ typedef struct ngap_nas_first_req_s {
ngap_rrc_establishment_cause_t establishment_cause; ngap_rrc_establishment_cause_t establishment_cause;
/* NAS PDU */ /* NAS PDU */
ngap_nas_pdu_t nas_pdu; ngap_pdu_t nas_pdu;
/* If this flag is set NGAP layer is expecting the GUAMI. If = 0, /* If this flag is set NGAP layer is expecting the GUAMI. If = 0,
* the temporary s-tmsi is used. * the temporary s-tmsi is used.
...@@ -562,14 +520,13 @@ typedef struct ngap_nas_first_req_s { ...@@ -562,14 +520,13 @@ typedef struct ngap_nas_first_req_s {
typedef struct ngap_uplink_nas_s { typedef struct ngap_uplink_nas_s {
/* Unique UE identifier within an gNB */ /* Unique UE identifier within an gNB */
uint32_t gNB_ue_ngap_id; uint32_t gNB_ue_ngap_id;
/* NAS pdu */ /* NAS pdu */
ngap_nas_pdu_t nas_pdu; ngap_pdu_t nas_pdu;
} ngap_uplink_nas_t; } ngap_uplink_nas_t;
typedef struct ngap_ue_cap_info_ind_s { typedef struct ngap_ue_cap_info_ind_s {
uint32_t gNB_ue_ngap_id; uint32_t gNB_ue_ngap_id;
ngap_ue_radio_cap_t ue_radio_cap; ngap_pdu_t ue_radio_cap;
} ngap_ue_cap_info_ind_t; } ngap_ue_cap_info_ind_t;
typedef struct ngap_initial_context_setup_resp_s { typedef struct ngap_initial_context_setup_resp_s {
...@@ -594,7 +551,7 @@ typedef struct ngap_initial_context_setup_fail_s { ...@@ -594,7 +551,7 @@ typedef struct ngap_initial_context_setup_fail_s {
typedef struct ngap_nas_non_delivery_ind_s { typedef struct ngap_nas_non_delivery_ind_s {
uint32_t gNB_ue_ngap_id; uint32_t gNB_ue_ngap_id;
ngap_nas_pdu_t nas_pdu; ngap_pdu_t nas_pdu;
/* TODO: add cause */ /* TODO: add cause */
} ngap_nas_non_delivery_ind_t; } ngap_nas_non_delivery_ind_t;
...@@ -621,33 +578,24 @@ typedef struct ngap_ue_ctxt_modification_resp_s { ...@@ -621,33 +578,24 @@ typedef struct ngap_ue_ctxt_modification_resp_s {
} ngap_ue_ctxt_modification_resp_t; } ngap_ue_ctxt_modification_resp_t;
typedef struct ngap_ue_release_complete_s { typedef struct ngap_ue_release_complete_s {
uint32_t gNB_ue_ngap_id; uint32_t gNB_ue_ngap_id;
} ngap_ue_release_complete_t; } ngap_ue_release_complete_t;
//-------------------------------------------------------------------------------------------// //-------------------------------------------------------------------------------------------//
// NGAP -> RRC messages // NGAP -> RRC messages
typedef struct ngap_downlink_nas_s { typedef struct ngap_downlink_nas_s {
/* UE id for initial connection to NGAP */ /* UE id for initial connection to NGAP */
uint16_t ue_initial_id;
/* Unique UE identifier within an gNB */
uint32_t gNB_ue_ngap_id; uint32_t gNB_ue_ngap_id;
/* NAS pdu */ /* NAS pdu */
ngap_nas_pdu_t nas_pdu; ngap_pdu_t nas_pdu;
} ngap_downlink_nas_t; } ngap_downlink_nas_t;
typedef struct ngap_initial_context_setup_req_s { typedef struct ngap_initial_context_setup_req_s {
/* UE id for initial connection to NGAP */ /* UE id for initial connection to NGAP */
uint16_t ue_initial_id;
/* gNB ue ngap id as initialized by NGAP layer */
uint32_t gNB_ue_ngap_id; uint32_t gNB_ue_ngap_id;
uint64_t amf_ue_ngap_id:40; uint64_t amf_ue_ngap_id;
/* UE aggregate maximum bitrate */ /* UE aggregate maximum bitrate */
ngap_ambr_t ue_ambr; ngap_ambr_t ue_ambr;
...@@ -676,7 +624,7 @@ typedef struct ngap_initial_context_setup_req_s { ...@@ -676,7 +624,7 @@ typedef struct ngap_initial_context_setup_req_s {
/* Nas Pdu */ /* Nas Pdu */
uint8_t nas_pdu_flag; uint8_t nas_pdu_flag;
ngap_nas_pdu_t nas_pdu; ngap_pdu_t nas_pdu;
} ngap_initial_context_setup_req_t; } ngap_initial_context_setup_req_t;
...@@ -702,17 +650,22 @@ typedef struct ngap_paging_ind_s { ...@@ -702,17 +650,22 @@ typedef struct ngap_paging_ind_s {
ngap_paging_priority_t paging_priority; ngap_paging_priority_t paging_priority;
} ngap_paging_ind_t; } ngap_paging_ind_t;
typedef struct {
/* Unique pdusession_id for the UE. */
int pdusession_id;
ngap_pdu_t nas_pdu;
ngap_pdu_t pdusessionTransfer;
} pdusession_setup_req_t;
typedef struct ngap_pdusession_setup_req_s { typedef struct ngap_pdusession_setup_req_s {
/* UE id for initial connection to NGAP */ /* UE id for initial connection to NGAP */
uint16_t ue_initial_id; uint32_t gNB_ue_ngap_id;
/* AMF UE id */ /* AMF UE id */
uint64_t amf_ue_ngap_id:40; uint64_t amf_ue_ngap_id;
/* gNB ue ngap id as initialized by NGAP layer */
uint32_t gNB_ue_ngap_id;
/* S-NSSAI */ /* S-NSSAI */
// Fixme: illogical, nssai is part of each pdu session
ngap_allowed_NSSAI_t allowed_nssai[8]; ngap_allowed_NSSAI_t allowed_nssai[8];
/* Number of pdusession to be setup in the list */ /* Number of pdusession to be setup in the list */
...@@ -731,7 +684,6 @@ typedef struct ngap_pdusession_setup_req_s { ...@@ -731,7 +684,6 @@ typedef struct ngap_pdusession_setup_req_s {
typedef struct ngap_pdusession_setup_resp_s { typedef struct ngap_pdusession_setup_resp_s {
uint32_t gNB_ue_ngap_id; uint32_t gNB_ue_ngap_id;
/* Number of pdusession setup-ed in the list */ /* Number of pdusession setup-ed in the list */
uint8_t nb_of_pdusessions; uint8_t nb_of_pdusessions;
/* list of pdusession setup-ed by RRC layers */ /* list of pdusession setup-ed by RRC layers */
...@@ -744,7 +696,6 @@ typedef struct ngap_pdusession_setup_resp_s { ...@@ -744,7 +696,6 @@ typedef struct ngap_pdusession_setup_resp_s {
} ngap_pdusession_setup_resp_t; } ngap_pdusession_setup_resp_t;
typedef struct ngap_path_switch_req_s { typedef struct ngap_path_switch_req_s {
uint32_t gNB_ue_ngap_id; uint32_t gNB_ue_ngap_id;
/* Number of pdusession setup-ed in the list */ /* Number of pdusession setup-ed in the list */
...@@ -754,12 +705,11 @@ typedef struct ngap_path_switch_req_s { ...@@ -754,12 +705,11 @@ typedef struct ngap_path_switch_req_s {
pdusession_setup_t pdusessions_tobeswitched[NGAP_MAX_PDUSESSION]; pdusession_setup_t pdusessions_tobeswitched[NGAP_MAX_PDUSESSION];
/* AMF UE id */ /* AMF UE id */
uint64_t amf_ue_ngap_id:40; uint64_t amf_ue_ngap_id;
ngap_guami_t ue_guami; ngap_guami_t ue_guami;
uint16_t ue_initial_id; uint16_t ue_initial_id;
/* Security algorithms */ /* Security algorithms */
ngap_security_capabilities_t security_capabilities; ngap_security_capabilities_t security_capabilities;
...@@ -773,7 +723,7 @@ typedef struct ngap_path_switch_req_ack_s { ...@@ -773,7 +723,7 @@ typedef struct ngap_path_switch_req_ack_s {
uint32_t gNB_ue_ngap_id; uint32_t gNB_ue_ngap_id;
/* AMF UE id */ /* AMF UE id */
uint64_t amf_ue_ngap_id:40; uint64_t amf_ue_ngap_id;
/* UE aggregate maximum bitrate */ /* UE aggregate maximum bitrate */
ngap_ambr_t ue_ambr; ngap_ambr_t ue_ambr;
...@@ -801,7 +751,7 @@ typedef struct ngap_pdusession_modification_ind_s { ...@@ -801,7 +751,7 @@ typedef struct ngap_pdusession_modification_ind_s {
uint32_t gNB_ue_ngap_id; uint32_t gNB_ue_ngap_id;
/* AMF UE id */ /* AMF UE id */
uint64_t amf_ue_ngap_id:40; uint64_t amf_ue_ngap_id;
/* Number of pdusession setup-ed in the list */ /* Number of pdusession setup-ed in the list */
uint8_t nb_of_pdusessions_tobemodified; uint8_t nb_of_pdusessions_tobemodified;
...@@ -830,10 +780,7 @@ typedef struct ngap_ue_release_command_s { ...@@ -830,10 +780,7 @@ typedef struct ngap_ue_release_command_s {
typedef struct pdusession_release_s { typedef struct pdusession_release_s {
/* Unique pdusession_id for the UE. */ /* Unique pdusession_id for the UE. */
uint8_t pdusession_id; uint8_t pdusession_id;
/* Octet string data */ ngap_pdu_t data;
uint8_t *transfer_buffer;
/* Length of the octet string */
uint32_t transfer_length;
} pdusession_release_t; } pdusession_release_t;
typedef struct ngap_ue_release_req_s { typedef struct ngap_ue_release_req_s {
...@@ -847,11 +794,8 @@ typedef struct ngap_ue_release_req_s { ...@@ -847,11 +794,8 @@ typedef struct ngap_ue_release_req_s {
} ngap_ue_release_req_t, ngap_ue_release_resp_t; } ngap_ue_release_req_t, ngap_ue_release_resp_t;
typedef struct ngap_pdusession_modify_req_s { typedef struct ngap_pdusession_modify_req_s {
/* UE id for initial connection to NGAP */
uint16_t ue_initial_id;
/* AMF UE id */ /* AMF UE id */
uint64_t amf_ue_ngap_id:40; uint64_t amf_ue_ngap_id;
/* gNB ue ngap id as initialized by NGAP layer */ /* gNB ue ngap id as initialized by NGAP layer */
uint32_t gNB_ue_ngap_id; uint32_t gNB_ue_ngap_id;
...@@ -879,13 +823,13 @@ typedef struct ngap_pdusession_modify_resp_s { ...@@ -879,13 +823,13 @@ typedef struct ngap_pdusession_modify_resp_s {
typedef struct ngap_pdusession_release_command_s { typedef struct ngap_pdusession_release_command_s {
/* AMF UE id */ /* AMF UE id */
uint64_t amf_ue_ngap_id:40; uint64_t amf_ue_ngap_id;
/* gNB ue ngap id as initialized by NGAP layer */ /* gNB ue ngap id as initialized by NGAP layer */
uint32_t gNB_ue_ngap_id; uint32_t gNB_ue_ngap_id;
/* The NAS PDU should be forwarded by the RRC layer to the NAS layer */ /* The NAS PDU should be forwarded by the RRC layer to the NAS layer */
ngap_nas_pdu_t nas_pdu; ngap_pdu_t nas_pdu;
/* Number of pdusession to be released in the list */ /* Number of pdusession to be released in the list */
uint8_t nb_pdusessions_torelease; uint8_t nb_pdusessions_torelease;
...@@ -897,7 +841,7 @@ typedef struct ngap_pdusession_release_command_s { ...@@ -897,7 +841,7 @@ typedef struct ngap_pdusession_release_command_s {
typedef struct ngap_pdusession_release_resp_s { typedef struct ngap_pdusession_release_resp_s {
/* AMF UE id */ /* AMF UE id */
uint64_t amf_ue_ngap_id:40; uint64_t amf_ue_ngap_id;
/* gNB ue ngap id as initialized by NGAP layer */ /* gNB ue ngap id as initialized by NGAP layer */
uint32_t gNB_ue_ngap_id; uint32_t gNB_ue_ngap_id;
......
...@@ -230,8 +230,7 @@ typedef struct protocol_ctxt_s { ...@@ -230,8 +230,7 @@ typedef struct protocol_ctxt_s {
#define ENB_INSTANCE_TO_MODULE_ID( iNSTANCE )iNSTANCE #define ENB_INSTANCE_TO_MODULE_ID( iNSTANCE )iNSTANCE
//NR //NR
#define GNB_MODULE_ID_TO_INSTANCE( mODULE_iD ) mODULE_iD #define GNB_MODULE_ID_TO_INSTANCE(mODULE_iD) mODULE_iD
#define GNB_INSTANCE_TO_MODULE_ID( iNSTANCE )iNSTANCE
#define MODULE_ID_TO_INSTANCE(mODULE_iD, iNSTANCE, eNB_fLAG) \ #define MODULE_ID_TO_INSTANCE(mODULE_iD, iNSTANCE, eNB_fLAG) \
do { \ do { \
......
...@@ -220,8 +220,8 @@ int e1ap_encode_send(E1_t type, e1ap_setup_req_t *setupReq, E1AP_E1AP_PDU_t *pdu ...@@ -220,8 +220,8 @@ int e1ap_encode_send(E1_t type, e1ap_setup_req_t *setupReq, E1AP_E1AP_PDU_t *pdu
if (encoded < 0) { if (encoded < 0) {
LOG_E(E1AP, "%s: Failed to encode E1AP message\n", func); LOG_E(E1AP, "%s: Failed to encode E1AP message\n", func);
return -1; return -1;
} else { }
MessageDef *message = itti_alloc_new_message((type==CPtype)?TASK_CUCP_E1:TASK_CUUP_E1, 0, SCTP_DATA_REQ); MessageDef *message = itti_alloc_new_message((type == CPtype) ? TASK_CUCP_E1 : TASK_CUUP_E1, 0, SCTP_DATA_REQ);
sctp_data_req_t *s = &message->ittiMsg.sctp_data_req; sctp_data_req_t *s = &message->ittiMsg.sctp_data_req;
s->assoc_id = setupReq->assoc_id; s->assoc_id = setupReq->assoc_id;
s->buffer = buffer; s->buffer = buffer;
...@@ -229,7 +229,6 @@ int e1ap_encode_send(E1_t type, e1ap_setup_req_t *setupReq, E1AP_E1AP_PDU_t *pdu ...@@ -229,7 +229,6 @@ int e1ap_encode_send(E1_t type, e1ap_setup_req_t *setupReq, E1AP_E1AP_PDU_t *pdu
s->stream = stream; s->stream = stream;
LOG_I(E1AP, "%s: Sending ITTI message to SCTP Task\n", func); LOG_I(E1AP, "%s: Sending ITTI message to SCTP Task\n", func);
itti_send_msg_to_task(TASK_SCTP, 0 /*unused by callee*/, message); itti_send_msg_to_task(TASK_SCTP, 0 /*unused by callee*/, message);
}
return encoded; return encoded;
} }
...@@ -57,7 +57,7 @@ static void cu_task_handle_sctp_association_ind(instance_t instance, sctp_new_as ...@@ -57,7 +57,7 @@ static void cu_task_handle_sctp_association_ind(instance_t instance, sctp_new_as
f1ap_cu_data->sctp_in_streams = sctp_new_association_ind->in_streams; f1ap_cu_data->sctp_in_streams = sctp_new_association_ind->in_streams;
f1ap_cu_data->sctp_out_streams = sctp_new_association_ind->out_streams; f1ap_cu_data->sctp_out_streams = sctp_new_association_ind->out_streams;
f1ap_cu_data->default_sctp_stream_id = 0; f1ap_cu_data->default_sctp_stream_id = 0;
if (RC.nrrrc[GNB_INSTANCE_TO_MODULE_ID(instance)]->node_type != ngran_gNB_CUCP) { if (RC.nrrrc[instance]->node_type != ngran_gNB_CUCP) {
getCxt(CUtype, instance)->gtpInst = cu_task_create_gtpu_instance(IPaddrs); getCxt(CUtype, instance)->gtpInst = cu_task_create_gtpu_instance(IPaddrs);
AssertFatal(getCxt(CUtype, instance)->gtpInst > 0, "Failed to create CU F1-U UDP listener"); AssertFatal(getCxt(CUtype, instance)->gtpInst > 0, "Failed to create CU F1-U UDP listener");
} else } else
......
...@@ -947,13 +947,13 @@ int CU_handle_UE_CONTEXT_RELEASE_COMPLETE(instance_t instance, ...@@ -947,13 +947,13 @@ int CU_handle_UE_CONTEXT_RELEASE_COMPLETE(instance_t instance,
protocol_ctxt_t ctxt; protocol_ctxt_t ctxt;
PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, instance, GNB_FLAG_YES, rnti, 0, 0, instance); PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, instance, GNB_FLAG_YES, rnti, 0, 0, instance);
struct rrc_gNB_ue_context_s *ue_context_p = rrc_gNB_get_ue_context(RC.nrrrc[instance], rnti); rrc_gNB_ue_context_t *ue_context_p = rrc_gNB_get_ue_context_by_rnti(RC.nrrrc[instance], rnti);
if (ue_context_p) { if (ue_context_p) {
MessageDef *msg = itti_alloc_new_message(TASK_CU_F1, 0, NGAP_UE_CONTEXT_RELEASE_COMPLETE); MessageDef *msg = itti_alloc_new_message(TASK_CU_F1, 0, NGAP_UE_CONTEXT_RELEASE_COMPLETE);
NGAP_UE_CONTEXT_RELEASE_COMPLETE(msg).gNB_ue_ngap_id = ue_context_p->ue_context.gNB_ue_ngap_id; NGAP_UE_CONTEXT_RELEASE_COMPLETE(msg).gNB_ue_ngap_id = ue_context_p->ue_context.gNB_ue_ngap_id;
itti_send_msg_to_task(TASK_NGAP, instance, msg); itti_send_msg_to_task(TASK_NGAP, instance, msg);
rrc_gNB_remove_ue_context(&ctxt, RC.nrrrc[instance], ue_context_p); rrc_gNB_remove_ue_context(RC.nrrrc[instance], ue_context_p);
} else { } else {
LOG_E(F1AP, "could not find ue_context of UE RNTI %x\n", rnti); LOG_E(F1AP, "could not find ue_context of UE RNTI %x\n", rnti);
} }
...@@ -1600,7 +1600,7 @@ int CU_handle_UE_CONTEXT_MODIFICATION_RESPONSE(instance_t instance, ...@@ -1600,7 +1600,7 @@ int CU_handle_UE_CONTEXT_MODIFICATION_RESPONSE(instance_t instance,
F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID, true); F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID, true);
f1ap_ue_context_modification_resp->gNB_DU_ue_id = ie->value.choice.GNB_DU_UE_F1AP_ID; f1ap_ue_context_modification_resp->gNB_DU_ue_id = ie->value.choice.GNB_DU_UE_F1AP_ID;
LOG_D(F1AP, "f1ap_ue_context_setup_resp->gNB_DU_ue_id is: %d \n", f1ap_ue_context_modification_resp->gNB_DU_ue_id); LOG_D(F1AP, "f1ap_ue_context_modification_resp->gNB_DU_ue_id is: %d \n", f1ap_ue_context_modification_resp->gNB_DU_ue_id);
f1ap_ue_context_modification_resp->rnti = f1ap_ue_context_modification_resp->rnti =
f1ap_get_rnti_by_du_id(CUtype, instance, f1ap_ue_context_modification_resp->gNB_DU_ue_id); f1ap_get_rnti_by_du_id(CUtype, instance, f1ap_ue_context_modification_resp->gNB_DU_ue_id);
......
...@@ -2810,10 +2810,12 @@ void nr_mac_update_timers(module_id_t module_id, ...@@ -2810,10 +2810,12 @@ void nr_mac_update_timers(module_id_t module_id,
NR_CellGroupConfig_t *cg = NULL; NR_CellGroupConfig_t *cg = NULL;
uper_decode(NULL, uper_decode(NULL,
&asn_DEF_NR_CellGroupConfig, //might be added prefix later &asn_DEF_NR_CellGroupConfig, // might be added prefix later
(void **)&cg, (void **)&cg,
(uint8_t *)UE->cg_buf, (uint8_t *)UE->cg_buf,
(UE->enc_rval.encoded+7)/8, 0, 0); (UE->enc_rval.encoded + 7) / 8,
0,
0);
UE->CellGroup = cg; UE->CellGroup = cg;
if (LOG_DEBUGFLAG(DEBUG_ASN1)) { if (LOG_DEBUGFLAG(DEBUG_ASN1)) {
...@@ -2918,13 +2920,8 @@ void send_initial_ul_rrc_message(module_id_t module_id, ...@@ -2918,13 +2920,8 @@ void send_initial_ul_rrc_message(module_id_t module_id,
sdu_len, rnti); sdu_len, rnti);
/* TODO REMOVE_DU_RRC: the RRC in the DU is a hack and should be taken out in the future */ /* TODO REMOVE_DU_RRC: the RRC in the DU is a hack and should be taken out in the future */
if (NODE_IS_DU(RC.nrrrc[module_id]->node_type)) { if (NODE_IS_DU(RC.nrrrc[module_id]->node_type))
struct rrc_gNB_ue_context_s *ue_context_p = rrc_gNB_allocate_new_UE_context(RC.nrrrc[module_id]); rrc_gNB_create_ue_context(rnti, RC.nrrrc[module_id], rnti);
ue_context_p->ue_id_rnti = rnti;
ue_context_p->ue_context.rnti = rnti;
ue_context_p->ue_context.random_ue_identity = rnti;
RB_INSERT(rrc_nr_ue_tree_s, &RC.nrrrc[module_id]->rrc_ue_head, ue_context_p);
}
const NR_ServingCellConfigCommon_t *scc = RC.nrrrc[module_id]->carrier.servingcellconfigcommon; const NR_ServingCellConfigCommon_t *scc = RC.nrrrc[module_id]->carrier.servingcellconfigcommon;
const NR_ServingCellConfig_t *sccd = RC.nrrrc[module_id]->configuration.scd; const NR_ServingCellConfig_t *sccd = RC.nrrrc[module_id]->configuration.scd;
......
...@@ -106,7 +106,7 @@ int dl_rrc_message_rrcSetup(module_id_t module_id, const f1ap_dl_rrc_message_t * ...@@ -106,7 +106,7 @@ int dl_rrc_message_rrcSetup(module_id_t module_id, const f1ap_dl_rrc_message_t *
/* TODO: drop the RRC context */ /* TODO: drop the RRC context */
gNB_RRC_INST *rrc = RC.nrrrc[module_id]; gNB_RRC_INST *rrc = RC.nrrrc[module_id];
struct rrc_gNB_ue_context_s *ue_context_p = rrc_gNB_get_ue_context(rrc, dl_rrc->rnti); rrc_gNB_ue_context_t *ue_context_p = rrc_gNB_get_ue_context_by_rnti(rrc, dl_rrc->rnti);
gNB_RRC_UE_t *ue_p = &ue_context_p->ue_context; gNB_RRC_UE_t *ue_p = &ue_context_p->ue_context;
ue_p->SRB_configList = rrcSetup_ies->radioBearerConfig.srb_ToAddModList; ue_p->SRB_configList = rrcSetup_ies->radioBearerConfig.srb_ToAddModList;
ue_p->masterCellGroup = cellGroup; ue_p->masterCellGroup = cellGroup;
......
...@@ -162,8 +162,7 @@ int8_t nr_mac_rrc_bwp_switch_req(const module_id_t module_idP, ...@@ -162,8 +162,7 @@ int8_t nr_mac_rrc_bwp_switch_req(const module_id_t module_idP,
const rnti_t rntiP, const rnti_t rntiP,
const int dl_bwp_id, const int dl_bwp_id,
const int ul_bwp_id) { const int ul_bwp_id) {
rrc_gNB_ue_context_t *ue_context_p = rrc_gNB_get_ue_context_by_rnti(RC.nrrrc[module_idP], rntiP);
struct rrc_gNB_ue_context_s *ue_context_p = rrc_gNB_get_ue_context(RC.nrrrc[module_idP], rntiP);
protocol_ctxt_t ctxt; protocol_ctxt_t ctxt;
PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, module_idP, GNB_FLAG_YES, rntiP, frameP, sub_frameP, 0); PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, module_idP, GNB_FLAG_YES, rntiP, frameP, sub_frameP, 0);
...@@ -177,10 +176,7 @@ void nr_mac_gNB_rrc_ul_failure(const module_id_t Mod_instP, ...@@ -177,10 +176,7 @@ void nr_mac_gNB_rrc_ul_failure(const module_id_t Mod_instP,
const frame_t frameP, const frame_t frameP,
const sub_frame_t subframeP, const sub_frame_t subframeP,
const rnti_t rntiP) { const rnti_t rntiP) {
struct rrc_gNB_ue_context_s *ue_context_p = NULL; rrc_gNB_ue_context_t *ue_context_p = rrc_gNB_get_ue_context_by_rnti(RC.nrrrc[Mod_instP], rntiP);
ue_context_p = rrc_gNB_get_ue_context(
RC.nrrrc[Mod_instP],
rntiP);
if (ue_context_p != NULL) { if (ue_context_p != NULL) {
LOG_D(RRC,"Frame %d, Subframe %d: UE %x UL failure, activating timer\n",frameP,subframeP,rntiP); LOG_D(RRC,"Frame %d, Subframe %d: UE %x UL failure, activating timer\n",frameP,subframeP,rntiP);
...@@ -195,8 +191,7 @@ void nr_mac_gNB_rrc_ul_failure_reset(const module_id_t Mod_instP, ...@@ -195,8 +191,7 @@ void nr_mac_gNB_rrc_ul_failure_reset(const module_id_t Mod_instP,
const frame_t frameP, const frame_t frameP,
const sub_frame_t subframeP, const sub_frame_t subframeP,
const rnti_t rntiP) { const rnti_t rntiP) {
struct rrc_gNB_ue_context_s *ue_context_p = NULL; rrc_gNB_ue_context_t *ue_context_p = rrc_gNB_get_ue_context_by_rnti(RC.nrrrc[Mod_instP], rntiP);
ue_context_p = rrc_gNB_get_ue_context(RC.nrrrc[Mod_instP], rntiP);
if (ue_context_p != NULL) { if (ue_context_p != NULL) {
LOG_W(RRC,"Frame %d, Subframe %d: UE %x UL failure reset, deactivating timer\n",frameP,subframeP,rntiP); LOG_W(RRC,"Frame %d, Subframe %d: UE %x UL failure reset, deactivating timer\n",frameP,subframeP,rntiP);
ue_context_p->ue_context.ul_failure_timer=0; ue_context_p->ue_context.ul_failure_timer=0;
......
...@@ -1298,27 +1298,24 @@ uint8_t do_NR_SecurityModeCommand( ...@@ -1298,27 +1298,24 @@ uint8_t do_NR_SecurityModeCommand(
uint8_t *const buffer, uint8_t *const buffer,
const uint8_t Transaction_id, const uint8_t Transaction_id,
const uint8_t cipheringAlgorithm, const uint8_t cipheringAlgorithm,
NR_IntegrityProtAlgorithm_t *integrityProtAlgorithm NR_IntegrityProtAlgorithm_t integrityProtAlgorithm
) )
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
{ {
NR_DL_DCCH_Message_t dl_dcch_msg; NR_DL_DCCH_Message_t dl_dcch_msg={0};
asn_enc_rval_t enc_rval; asn_enc_rval_t enc_rval;
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.present = NR_DL_DCCH_MessageType_PR_c1;
dl_dcch_msg.message.choice.c1=CALLOC(1,sizeof(struct NR_DL_DCCH_MessageType__c1)); asn1cCalloc(dl_dcch_msg.message.choice.c1, c1);
dl_dcch_msg.message.choice.c1->present = NR_DL_DCCH_MessageType__c1_PR_securityModeCommand; c1->present = NR_DL_DCCH_MessageType__c1_PR_securityModeCommand;
dl_dcch_msg.message.choice.c1->choice.securityModeCommand = CALLOC(1, sizeof(struct NR_SecurityModeCommand)); asn1cCalloc(c1->choice.securityModeCommand,scm);
dl_dcch_msg.message.choice.c1->choice.securityModeCommand->rrc_TransactionIdentifier = Transaction_id; scm->rrc_TransactionIdentifier = Transaction_id;
dl_dcch_msg.message.choice.c1->choice.securityModeCommand->criticalExtensions.present = NR_SecurityModeCommand__criticalExtensions_PR_securityModeCommand; scm->criticalExtensions.present = NR_SecurityModeCommand__criticalExtensions_PR_securityModeCommand;
dl_dcch_msg.message.choice.c1->choice.securityModeCommand->criticalExtensions.choice.securityModeCommand = asn1cCalloc(scm->criticalExtensions.choice.securityModeCommand,scmIE);
CALLOC(1, sizeof(struct NR_SecurityModeCommand_IEs));
// the two following information could be based on the mod_id // the two following information could be based on the mod_id
dl_dcch_msg.message.choice.c1->choice.securityModeCommand->criticalExtensions.choice.securityModeCommand->securityConfigSMC.securityAlgorithmConfig.cipheringAlgorithm scmIE->securityConfigSMC.securityAlgorithmConfig.cipheringAlgorithm
= (NR_CipheringAlgorithm_t)cipheringAlgorithm; = (NR_CipheringAlgorithm_t)cipheringAlgorithm;
dl_dcch_msg.message.choice.c1->choice.securityModeCommand->criticalExtensions.choice.securityModeCommand->securityConfigSMC.securityAlgorithmConfig.integrityProtAlgorithm asn1cCallocOne(scmIE->securityConfigSMC.securityAlgorithmConfig.integrityProtAlgorithm, integrityProtAlgorithm);
= integrityProtAlgorithm;
if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) { if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
xer_fprint(stdout, &asn_DEF_NR_DL_DCCH_Message, (void *)&dl_dcch_msg); xer_fprint(stdout, &asn_DEF_NR_DL_DCCH_Message, (void *)&dl_dcch_msg);
...@@ -1332,7 +1329,7 @@ uint8_t do_NR_SecurityModeCommand( ...@@ -1332,7 +1329,7 @@ uint8_t do_NR_SecurityModeCommand(
AssertFatal(enc_rval.encoded >0 , "ASN1 message encoding failed (%s, %lu)!\n", AssertFatal(enc_rval.encoded >0 , "ASN1 message encoding failed (%s, %lu)!\n",
enc_rval.failed_type->name, enc_rval.encoded); enc_rval.failed_type->name, enc_rval.encoded);
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_NR_DL_DCCH_Message,&dl_dcch_msg);
LOG_D(NR_RRC, "[gNB %d] securityModeCommand for UE %lx Encoded %zd bits (%zd bytes)\n", ctxt_pP->module_id, ctxt_pP->rntiMaybeUEid, enc_rval.encoded, (enc_rval.encoded + 7) / 8); LOG_D(NR_RRC, "[gNB %d] securityModeCommand for UE %lx Encoded %zd bits (%zd bytes)\n", ctxt_pP->module_id, ctxt_pP->rntiMaybeUEid, enc_rval.encoded, (enc_rval.encoded + 7) / 8);
// rrc_ue_process_ueCapabilityEnquiry(0,1000,&dl_dcch_msg.message.choice.c1.choice.ueCapabilityEnquiry,0); // rrc_ue_process_ueCapabilityEnquiry(0,1000,&dl_dcch_msg.message.choice.c1.choice.ueCapabilityEnquiry,0);
...@@ -1521,10 +1518,7 @@ int16_t do_RRCReconfiguration( ...@@ -1521,10 +1518,7 @@ int16_t do_RRCReconfiguration(
} }
if(cellGroupConfig!=NULL){ if(cellGroupConfig!=NULL){
update_cellGroupConfig(cellGroupConfig, update_cellGroupConfig(cellGroupConfig, ue_context_pP->ue_context.gNB_ue_ngap_id, ue_context_pP ? ue_context_pP->ue_context.UE_Capability_nr : NULL, configuration);
ue_context_pP->local_uid,
ue_context_pP ? ue_context_pP->ue_context.UE_Capability_nr : NULL,
configuration);
enc_rval = uper_encode_to_buffer(&asn_DEF_NR_CellGroupConfig, enc_rval = uper_encode_to_buffer(&asn_DEF_NR_CellGroupConfig,
NULL, NULL,
...@@ -1754,29 +1748,27 @@ do_NR_DLInformationTransfer( ...@@ -1754,29 +1748,27 @@ do_NR_DLInformationTransfer(
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
{ {
ssize_t encoded; ssize_t encoded;
NR_DL_DCCH_Message_t dl_dcch_msg; NR_DL_DCCH_Message_t dl_dcch_msg={0};
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.present = NR_DL_DCCH_MessageType_PR_c1;
dl_dcch_msg.message.choice.c1 = CALLOC(1, sizeof(struct NR_DL_DCCH_MessageType__c1)); asn1cCalloc(dl_dcch_msg.message.choice.c1, c1);
dl_dcch_msg.message.choice.c1->present = NR_DL_DCCH_MessageType__c1_PR_dlInformationTransfer; c1->present = NR_DL_DCCH_MessageType__c1_PR_dlInformationTransfer;
dl_dcch_msg.message.choice.c1->choice.dlInformationTransfer = CALLOC(1, sizeof(NR_DLInformationTransfer_t)); asn1cCalloc(c1->choice.dlInformationTransfer, infoTransfer);
dl_dcch_msg.message.choice.c1->choice.dlInformationTransfer->rrc_TransactionIdentifier = transaction_id; infoTransfer->rrc_TransactionIdentifier = transaction_id;
dl_dcch_msg.message.choice.c1->choice.dlInformationTransfer->criticalExtensions.present = infoTransfer->criticalExtensions.present =
NR_DLInformationTransfer__criticalExtensions_PR_dlInformationTransfer; NR_DLInformationTransfer__criticalExtensions_PR_dlInformationTransfer;
dl_dcch_msg.message.choice.c1->choice.dlInformationTransfer-> asn1cCalloc(infoTransfer->criticalExtensions.choice.dlInformationTransfer, dlInfoTransfer);
criticalExtensions.choice.dlInformationTransfer = CALLOC(1, sizeof(NR_DLInformationTransfer_IEs_t)); asn1cCalloc(dlInfoTransfer->dedicatedNAS_Message,msg);
dl_dcch_msg.message.choice.c1->choice.dlInformationTransfer-> // we will free the caller buffer, that is ok in the present code logic (else it will leak memory) but not natural,
criticalExtensions.choice.dlInformationTransfer->dedicatedNAS_Message = CALLOC(1, sizeof(NR_DedicatedNAS_Message_t)); // comprehensive code design
dl_dcch_msg.message.choice.c1->choice.dlInformationTransfer-> msg->buf = pdu_buffer;
criticalExtensions.choice.dlInformationTransfer->dedicatedNAS_Message->buf = pdu_buffer; msg->size = pdu_length;
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); 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, %ld)!\n", AssertFatal(encoded > 0,"ASN1 message encoding failed (%s, %ld)!\n",
"DLInformationTransfer", encoded); "DLInformationTransfer", encoded);
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_NR_DL_DCCH_Message,&dl_dcch_msg );
LOG_D(NR_RRC,"DLInformationTransfer Encoded %zd bytes\n", encoded); LOG_D(NR_RRC,"DLInformationTransfer Encoded %zd bytes\n", encoded);
//for (int i=0;i<encoded;i++) printf("%02x ",(*buffer)[i]); //for (int i=0;i<encoded;i++) printf("%02x ",(*buffer)[i]);
return encoded; return encoded;
......
...@@ -113,7 +113,7 @@ uint8_t do_NR_SecurityModeCommand( ...@@ -113,7 +113,7 @@ uint8_t do_NR_SecurityModeCommand(
uint8_t *const buffer, uint8_t *const buffer,
const uint8_t Transaction_id, const uint8_t Transaction_id,
const uint8_t cipheringAlgorithm, const uint8_t cipheringAlgorithm,
NR_IntegrityProtAlgorithm_t *integrityProtAlgorithm); NR_IntegrityProtAlgorithm_t integrityProtAlgorithm);
uint8_t do_NR_SA_UECapabilityEnquiry( const protocol_ctxt_t *const ctxt_pP, uint8_t do_NR_SA_UECapabilityEnquiry( const protocol_ctxt_t *const ctxt_pP,
uint8_t *const buffer, uint8_t *const buffer,
......
...@@ -107,18 +107,19 @@ static int drb_config_gtpu_create(const protocol_ctxt_t *const ctxt_p, ...@@ -107,18 +107,19 @@ static int drb_config_gtpu_create(const protocol_ctxt_t *const ctxt_p,
gtpv1u_gnb_create_tunnel_req_t create_tunnel_req={0}; gtpv1u_gnb_create_tunnel_req_t create_tunnel_req={0};
gtpv1u_gnb_create_tunnel_resp_t create_tunnel_resp={0}; gtpv1u_gnb_create_tunnel_resp_t create_tunnel_resp={0};
gNB_RRC_UE_t *UE = &ue_context_p->ue_context;
int i = ue_context_p->ue_context.nb_of_pdusessions - 1; LOG_W(NR_RRC, "recreate existing tunnels, while adding new ones\n");
pdu_session_param_t *pdu = ue_context_p->ue_context.pduSession + i; for (int i = 0; i < UE->nb_of_pdusessions; i++) {
create_tunnel_req.pdusession_id[0] = pdu->param.pdusession_id; rrc_pdu_session_param_t *pdu = UE->pduSession + i;
create_tunnel_req.incoming_rb_id[0] = i + 1; create_tunnel_req.pdusession_id[i] = pdu->param.pdusession_id;
create_tunnel_req.outgoing_qfi[0] = req->pduSession[i].DRBnGRanList[0].qosFlows[0].id; create_tunnel_req.incoming_rb_id[i] = i + 1;
memcpy(&create_tunnel_req.dst_addr[0].buffer, &pdu->param.upf_addr.buffer, sizeof(create_tunnel_req.dst_addr[0].buffer)); create_tunnel_req.outgoing_qfi[i] = req->pduSession[i].DRBnGRanList[0].qosFlows[0].id;
create_tunnel_req.dst_addr[0].length = pdu->param.upf_addr.length; memcpy(&create_tunnel_req.dst_addr[i].buffer, &pdu->param.upf_addr.buffer, sizeof(create_tunnel_req.dst_addr[0].buffer));
create_tunnel_req.outgoing_teid[0] = pdu->param.gtp_teid; create_tunnel_req.dst_addr[i].length = pdu->param.upf_addr.length;
create_tunnel_req.outgoing_teid[i] = pdu->param.gtp_teid;
create_tunnel_req.num_tunnels = 1; }
create_tunnel_req.ue_id = ue_context_p->ue_context.rnti; create_tunnel_req.num_tunnels = UE->nb_of_pdusessions;
create_tunnel_req.ue_id = UE->rnti;
int ret = gtpv1u_create_ngu_tunnel(getCxtE1(instance)->gtpInstN3, &create_tunnel_req, &create_tunnel_resp); int ret = gtpv1u_create_ngu_tunnel(getCxtE1(instance)->gtpInstN3, &create_tunnel_req, &create_tunnel_resp);
if (ret != 0) { if (ret != 0) {
...@@ -127,7 +128,7 @@ static int drb_config_gtpu_create(const protocol_ctxt_t *const ctxt_p, ...@@ -127,7 +128,7 @@ static int drb_config_gtpu_create(const protocol_ctxt_t *const ctxt_p,
return ret; return ret;
} }
nr_rrc_gNB_process_GTPV1U_CREATE_TUNNEL_RESP(ctxt_p, &create_tunnel_resp, i); nr_rrc_gNB_process_GTPV1U_CREATE_TUNNEL_RESP(ctxt_p, &create_tunnel_resp, 0);
uint8_t *kRRCenc = NULL; uint8_t *kRRCenc = NULL;
uint8_t *kRRCint = NULL; uint8_t *kRRCint = NULL;
...@@ -135,38 +136,26 @@ static int drb_config_gtpu_create(const protocol_ctxt_t *const ctxt_p, ...@@ -135,38 +136,26 @@ static int drb_config_gtpu_create(const protocol_ctxt_t *const ctxt_p,
uint8_t *kUPint = NULL; uint8_t *kUPint = NULL;
/* Derive the keys from kgnb */ /* Derive the keys from kgnb */
if (DRB_configList != NULL) { if (DRB_configList != NULL) {
nr_derive_key_up_enc(ue_context_p->ue_context.ciphering_algorithm, nr_derive_key_up_enc(UE->ciphering_algorithm, UE->kgnb, &kUPenc);
ue_context_p->ue_context.kgnb, nr_derive_key_up_int(UE->integrity_algorithm, UE->kgnb, &kUPint);
&kUPenc);
nr_derive_key_up_int(ue_context_p->ue_context.integrity_algorithm,
ue_context_p->ue_context.kgnb,
&kUPint);
} }
nr_derive_key_rrc_enc(ue_context_p->ue_context.ciphering_algorithm, nr_derive_key_rrc_enc(UE->ciphering_algorithm, UE->kgnb, &kRRCenc);
ue_context_p->ue_context.kgnb, nr_derive_key_rrc_int(UE->integrity_algorithm, UE->kgnb, &kRRCint);
&kRRCenc);
nr_derive_key_rrc_int(ue_context_p->ue_context.integrity_algorithm,
ue_context_p->ue_context.kgnb,
&kRRCint);
/* Refresh SRBs/DRBs */ /* Refresh SRBs/DRBs */
LOG_D(NR_RRC,"Configuring PDCP DRBs/SRBs for UE %x\n",ue_context_p->ue_context.rnti); LOG_D(NR_RRC, "Configuring PDCP DRBs/SRBs for UE %x\n", UE->rnti);
nr_pdcp_add_srbs(ctxt_p->enb_flag, ctxt_p->rntiMaybeUEid, nr_pdcp_add_srbs(ctxt_p->enb_flag, ctxt_p->rntiMaybeUEid, SRB_configList, (UE->integrity_algorithm << 4) | UE->ciphering_algorithm, kRRCenc, kRRCint);
SRB_configList,
(ue_context_p->ue_context.integrity_algorithm << 4)
| ue_context_p->ue_context.ciphering_algorithm,
kRRCenc,
kRRCint);
nr_pdcp_add_drbs(ctxt_p->enb_flag, ctxt_p->rntiMaybeUEid, 0, nr_pdcp_add_drbs(ctxt_p->enb_flag,
ctxt_p->rntiMaybeUEid,
0,
DRB_configList, DRB_configList,
(ue_context_p->ue_context.integrity_algorithm << 4) (UE->integrity_algorithm << 4) | UE->ciphering_algorithm,
| ue_context_p->ue_context.ciphering_algorithm,
kUPenc, kUPenc,
kUPint, kUPint,
get_softmodem_params()->sa ? ue_context_p->ue_context.masterCellGroup->rlc_BearerToAddModList : NULL); get_softmodem_params()->sa ? UE->masterCellGroup->rlc_BearerToAddModList : NULL);
return ret; return ret;
} }
...@@ -187,17 +176,18 @@ static NR_SRB_ToAddModList_t **generateSRB2_confList(gNB_RRC_UE_t *ue, NR_SRB_To ...@@ -187,17 +176,18 @@ static NR_SRB_ToAddModList_t **generateSRB2_confList(gNB_RRC_UE_t *ue, NR_SRB_To
return SRB_configList2; return SRB_configList2;
} }
static void cucp_cuup_bearer_context_setup_direct(e1ap_bearer_setup_req_t *const req, instance_t instance) { static void cucp_cuup_bearer_context_setup_direct(e1ap_bearer_setup_req_t *const req, instance_t instance) {
rrc_gNB_ue_context_t *ue_context_p = rrc_gNB_get_ue_context(RC.nrrrc[GNB_INSTANCE_TO_MODULE_ID(instance)], req->rnti); rrc_gNB_ue_context_t *ue_context_p = rrc_gNB_get_ue_context_by_rnti(RC.nrrrc[instance], req->rnti);
gNB_RRC_UE_t *UE = &ue_context_p->ue_context;
protocol_ctxt_t ctxt = {0}; protocol_ctxt_t ctxt = {0};
PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, 0, GNB_FLAG_YES, ue_context_p->ue_context.rnti, 0, 0, 0); PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, 0, GNB_FLAG_YES, UE->rnti, 0, 0, 0);
fill_DRB_configList(&ctxt, ue_context_p); fill_DRB_configList(&ctxt, ue_context_p);
gNB_RRC_INST *rrc = RC.nrrrc[ctxt.module_id]; gNB_RRC_INST *rrc = RC.nrrrc[ctxt.module_id];
// Fixme: xid not random, but almost! // Fixme: xid not random, but almost!
NR_SRB_ToAddModList_t **SRB_configList2 = generateSRB2_confList(&ue_context_p->ue_context, ue_context_p->ue_context.SRB_configList, ue_context_p->ue_context.pduSession[0].xid); NR_SRB_ToAddModList_t **SRB_configList2 = generateSRB2_confList(UE, UE->SRB_configList, UE->pduSession[0].xid);
// GTP tunnel for UL // GTP tunnel for UL
int ret = drb_config_gtpu_create(&ctxt, ue_context_p, req, ue_context_p->ue_context.DRB_configList, *SRB_configList2, rrc->e1_inst); int ret = drb_config_gtpu_create(&ctxt, ue_context_p, req, UE->DRB_configList, *SRB_configList2, rrc->e1_inst);
if (ret < 0) AssertFatal(false, "Unable to configure DRB or to create GTP Tunnel\n"); if (ret < 0) AssertFatal(false, "Unable to configure DRB or to create GTP Tunnel\n");
if(!NODE_IS_CU(RC.nrrrc[ctxt.module_id]->node_type)) { if(!NODE_IS_CU(RC.nrrrc[ctxt.module_id]->node_type)) {
...@@ -208,7 +198,7 @@ static void cucp_cuup_bearer_context_setup_direct(e1ap_bearer_setup_req_t *const ...@@ -208,7 +198,7 @@ static void cucp_cuup_bearer_context_setup_direct(e1ap_bearer_setup_req_t *const
in_addr_t my_addr = inet_addr(RC.nrrrc[ctxt.module_id]->eth_params_s.my_addr); in_addr_t my_addr = inet_addr(RC.nrrrc[ctxt.module_id]->eth_params_s.my_addr);
instance_t gtpInst = getCxt(CUtype, instance)->gtpInst; instance_t gtpInst = getCxt(CUtype, instance)->gtpInst;
// GTP tunnel for DL // GTP tunnel for DL
fill_e1ap_bearer_setup_resp(&resp, req, gtpInst, ue_context_p->ue_context.rnti, remote_port, my_addr); fill_e1ap_bearer_setup_resp(&resp, req, gtpInst, UE->rnti, remote_port, my_addr);
prepare_and_send_ue_context_modification_f1(ue_context_p, &resp); prepare_and_send_ue_context_modification_f1(ue_context_p, &resp);
} }
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
extern RAN_CONTEXT_t RC; extern RAN_CONTEXT_t RC;
static void cucp_cuup_bearer_context_setup_e1ap(e1ap_bearer_setup_req_t *const req, instance_t instance) { static void cucp_cuup_bearer_context_setup_e1ap(e1ap_bearer_setup_req_t *const req, instance_t instance) {
rrc_gNB_ue_context_t *ue_context_p = rrc_gNB_get_ue_context(RC.nrrrc[GNB_INSTANCE_TO_MODULE_ID(instance)], req->rnti); rrc_gNB_ue_context_t *ue_context_p = rrc_gNB_get_ue_context_by_rnti(RC.nrrrc[instance], req->rnti);
protocol_ctxt_t ctxt = {0}; protocol_ctxt_t ctxt = {0};
PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, 0, GNB_FLAG_YES, ue_context_p->ue_context.rnti, 0, 0, 0); PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, 0, GNB_FLAG_YES, ue_context_p->ue_context.rnti, 0, 0, 0);
......
...@@ -269,7 +269,7 @@ typedef struct pdu_session_param_s { ...@@ -269,7 +269,7 @@ typedef struct pdu_session_param_s {
uint8_t xid; // transaction_id uint8_t xid; // transaction_id
ngap_Cause_t cause; ngap_Cause_t cause;
uint8_t cause_value; uint8_t cause_value;
} __attribute__ ((__packed__)) pdu_session_param_t; } rrc_pdu_session_param_t;
typedef struct gNB_RRC_UE_s { typedef struct gNB_RRC_UE_s {
uint8_t primaryCC_id; uint8_t primaryCC_id;
...@@ -281,8 +281,7 @@ typedef struct gNB_RRC_UE_s { ...@@ -281,8 +281,7 @@ typedef struct gNB_RRC_UE_s {
uint8_t DRB_active[NGAP_MAX_DRBS_PER_UE]; uint8_t DRB_active[NGAP_MAX_DRBS_PER_UE];
NR_SRB_INFO SI; NR_SRB_INFO SI;
NR_SRB_INFO_TABLE_ENTRY Srb1; NR_SRB_INFO_TABLE_ENTRY Srb[maxSRBs]; // 3gpp max is 3 SRBs, number 1..3, we waste the entry 0 for code simplicity
NR_SRB_INFO_TABLE_ENTRY Srb2;
NR_MeasConfig_t *measConfig; NR_MeasConfig_t *measConfig;
NR_HANDOVER_INFO *handover_info; NR_HANDOVER_INFO *handover_info;
NR_MeasResults_t *measResults; NR_MeasResults_t *measResults;
...@@ -332,7 +331,7 @@ typedef struct gNB_RRC_UE_s { ...@@ -332,7 +331,7 @@ typedef struct gNB_RRC_UE_s {
/* Information from S1AP initial_context_setup_req */ /* Information from S1AP initial_context_setup_req */
uint32_t gNB_ue_s1ap_id :24; uint32_t gNB_ue_s1ap_id :24;
uint32_t gNB_ue_ngap_id; uint32_t gNB_ue_ngap_id;
uint64_t amf_ue_ngap_id:40; uint64_t amf_ue_ngap_id;
nr_rrc_guami_t ue_guami; nr_rrc_guami_t ue_guami;
ngap_security_capabilities_t security_capabilities; ngap_security_capabilities_t security_capabilities;
...@@ -350,11 +349,11 @@ typedef struct gNB_RRC_UE_s { ...@@ -350,11 +349,11 @@ typedef struct gNB_RRC_UE_s {
/* Number of e_rab to be modified in the list */ /* Number of e_rab to be modified in the list */
uint8_t nb_of_modify_pdusessions; uint8_t nb_of_modify_pdusessions;
uint8_t nb_of_failed_pdusessions; uint8_t nb_of_failed_pdusessions;
pdu_session_param_t modify_pdusession[NR_NB_RB_MAX]; rrc_pdu_session_param_t modify_pdusession[NR_NB_RB_MAX];
/* list of e_rab to be setup by RRC layers */ /* list of e_rab to be setup by RRC layers */
/* list of pdu session to be setup by RRC layers */ /* list of pdu session to be setup by RRC layers */
nr_e_rab_param_t e_rab[NB_RB_MAX];//[S1AP_MAX_E_RAB]; nr_e_rab_param_t e_rab[NB_RB_MAX];//[S1AP_MAX_E_RAB];
pdu_session_param_t pduSession[NGAP_MAX_PDU_SESSION]; rrc_pdu_session_param_t pduSession[NGAP_MAX_PDU_SESSION];
//release e_rabs //release e_rabs
uint8_t nb_release_of_e_rabs; uint8_t nb_release_of_e_rabs;
e_rab_failed_t e_rabs_release_failed[S1AP_MAX_E_RAB]; e_rab_failed_t e_rabs_release_failed[S1AP_MAX_E_RAB];
...@@ -396,23 +395,13 @@ typedef struct gNB_RRC_UE_s { ...@@ -396,23 +395,13 @@ typedef struct gNB_RRC_UE_s {
struct NR_PhysicalCellGroupConfig *physicalCellGroupConfig; struct NR_PhysicalCellGroupConfig *physicalCellGroupConfig;
/* Nas Pdu */ /* Nas Pdu */
uint8_t nas_pdu_flag; ngap_pdu_t nas_pdu;
ngap_nas_pdu_t nas_pdu;
} gNB_RRC_UE_t; } gNB_RRC_UE_t;
typedef struct rrc_gNB_ue_context_s { typedef struct rrc_gNB_ue_context_s {
/* Tree related data */ /* Tree related data */
RB_ENTRY(rrc_gNB_ue_context_s) entries; RB_ENTRY(rrc_gNB_ue_context_s) entries;
/* Uniquely identifies the UE between MME and eNB within the eNB.
* This id is encoded on 24bits.
*/
ue_id_t ue_id_rnti;
// another key for protocol layers but should not be used as a key for RB tree
uid_t local_uid;
/* UE id for initial connection to NGAP */ /* UE id for initial connection to NGAP */
struct gNB_RRC_UE_s ue_context; struct gNB_RRC_UE_s ue_context;
} rrc_gNB_ue_context_t; } rrc_gNB_ue_context_t;
...@@ -493,12 +482,6 @@ typedef struct gNB_RRC_INST_s { ...@@ -493,12 +482,6 @@ typedef struct gNB_RRC_INST_s {
rrc_gNB_carrier_data_t carrier; rrc_gNB_carrier_data_t carrier;
uid_allocator_t uid_allocator; uid_allocator_t uid_allocator;
RB_HEAD(rrc_nr_ue_tree_s, rrc_gNB_ue_context_s) rrc_ue_head; // ue_context tree key search by rnti RB_HEAD(rrc_nr_ue_tree_s, rrc_gNB_ue_context_s) rrc_ue_head; // ue_context tree key search by rnti
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 ;
/// NR cell id /// NR cell id
uint64_t nr_cellid; uint64_t nr_cellid;
......
...@@ -64,11 +64,11 @@ void rrc_gNB_generate_SgNBAdditionRequestAcknowledge( ...@@ -64,11 +64,11 @@ void rrc_gNB_generate_SgNBAdditionRequestAcknowledge(
rrc_gNB_ue_context_t *const ue_context_pP rrc_gNB_ue_context_t *const ue_context_pP
); );
struct rrc_gNB_ue_context_s *rrc_gNB_allocate_new_UE_context(gNB_RRC_INST *rrc_instance_pP); rrc_gNB_ue_context_t *rrc_gNB_allocate_new_UE_context(gNB_RRC_INST *rrc_instance_pP);
void rrc_parse_ue_capabilities(gNB_RRC_INST *rrc,NR_UE_CapabilityRAT_ContainerList_t *UE_CapabilityRAT_ContainerList, x2ap_ENDC_sgnb_addition_req_t *m, NR_CG_ConfigInfo_IEs_t * cg_config_info); void rrc_parse_ue_capabilities(gNB_RRC_INST *rrc,NR_UE_CapabilityRAT_ContainerList_t *UE_CapabilityRAT_ContainerList, x2ap_ENDC_sgnb_addition_req_t *m, NR_CG_ConfigInfo_IEs_t * cg_config_info);
void rrc_add_nsa_user(gNB_RRC_INST *rrc,struct rrc_gNB_ue_context_s *ue_context_p, x2ap_ENDC_sgnb_addition_req_t *m); void rrc_add_nsa_user(gNB_RRC_INST *rrc, rrc_gNB_ue_context_t *ue_context_p, x2ap_ENDC_sgnb_addition_req_t *m);
void rrc_remove_nsa_user(gNB_RRC_INST *rrc, int rnti); void rrc_remove_nsa_user(gNB_RRC_INST *rrc, int rnti);
...@@ -163,12 +163,6 @@ int nr_rrc_reconfiguration_req(rrc_gNB_ue_context_t *const ue_context_pP ...@@ -163,12 +163,6 @@ int nr_rrc_reconfiguration_req(rrc_gNB_ue_context_t *const ue_context_pP
const int dl_bwp_id, const int dl_bwp_id,
const int ul_bwp_id); const int ul_bwp_id);
int nr_rrc_gNB_decode_ccch(protocol_ctxt_t *const ctxt_pP,
const uint8_t *buffer,
int buffer_length,
const uint8_t *du_to_cu_rrc_container,
int du_to_cu_rrc_container_length);
void void
rrc_gNB_generate_dedicatedRRCReconfiguration_release( rrc_gNB_generate_dedicatedRRCReconfiguration_release(
const protocol_ctxt_t *const ctxt_pP, const protocol_ctxt_t *const ctxt_pP,
...@@ -217,9 +211,5 @@ void nr_pdcp_add_drbs(eNB_flag_t enb_flag, ...@@ -217,9 +211,5 @@ void nr_pdcp_add_drbs(eNB_flag_t enb_flag,
uint8_t *const kUPint, uint8_t *const kUPint,
struct NR_CellGroupConfig__rlc_BearerToAddModList *rlc_bearer2add_list); struct NR_CellGroupConfig__rlc_BearerToAddModList *rlc_bearer2add_list);
int rrc_gNB_generate_pcch_msg(uint32_t tmsi, int rrc_gNB_generate_pcch_msg(uint32_t tmsi, uint8_t paging_drx, instance_t instance, uint8_t CC_id);
uint8_t paging_drx,
instance_t instance,
uint8_t CC_id);
#endif #endif
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -44,26 +44,25 @@ ...@@ -44,26 +44,25 @@
extern RAN_CONTEXT_t RC; extern RAN_CONTEXT_t RC;
int int rrc_gNB_process_GTPV1U_CREATE_TUNNEL_RESP(const protocol_ctxt_t *const ctxt_pP, const gtpv1u_enb_create_tunnel_resp_t *const create_tunnel_resp_pP, uint8_t *inde_list)
rrc_gNB_process_GTPV1U_CREATE_TUNNEL_RESP( {
const protocol_ctxt_t *const ctxt_pP, if (!create_tunnel_resp_pP) {
const gtpv1u_enb_create_tunnel_resp_t *const create_tunnel_resp_pP, LOG_E(NR_RRC, "create_tunnel_resp_pP error\n");
uint8_t *inde_list return -1;
) { }
int i;
struct rrc_gNB_ue_context_s *ue_context_p = NULL;
if (create_tunnel_resp_pP) {
LOG_D(RRC, PROTOCOL_RRC_CTXT_UE_FMT" RX CREATE_TUNNEL_RESP num tunnels %u \n",
PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
create_tunnel_resp_pP->num_tunnels);
ue_context_p = rrc_gNB_get_ue_context(RC.nrrrc[ctxt_pP->module_id], ctxt_pP->rntiMaybeUEid);
for (i = 0; i < create_tunnel_resp_pP->num_tunnels; i++) { LOG_D(RRC, PROTOCOL_RRC_CTXT_UE_FMT " RX CREATE_TUNNEL_RESP num tunnels %u \n", PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP), create_tunnel_resp_pP->num_tunnels);
rrc_gNB_ue_context_t *ue_context_p = rrc_gNB_get_ue_context_by_rnti(RC.nrrrc[ctxt_pP->module_id], ctxt_pP->rntiMaybeUEid);
if (!ue_context_p) {
LOG_E(NR_RRC, "UE table error\n");
return -1;
}
for (int 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->enb_S1u_teid[i]; ue_context_p->ue_context.gnb_gtp_teid[inde_list[i]] = create_tunnel_resp_pP->enb_S1u_teid[i];
ue_context_p->ue_context.gnb_gtp_addrs[inde_list[i]] = create_tunnel_resp_pP->enb_addr; ue_context_p->ue_context.gnb_gtp_addrs[inde_list[i]] = create_tunnel_resp_pP->enb_addr;
ue_context_p->ue_context.gnb_gtp_ebi[inde_list[i]] = create_tunnel_resp_pP->eps_bearer_id[i]; ue_context_p->ue_context.gnb_gtp_ebi[inde_list[i]] = create_tunnel_resp_pP->eps_bearer_id[i];
LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" rrc_eNB_process_GTPV1U_CREATE_TUNNEL_RESP tunnel (%u, %u) bearer UE context index %u, msg index %u, id %u, gtp addr len %d \n", LOG_I(RRC,
PROTOCOL_RRC_CTXT_UE_FMT " rrc_eNB_process_GTPV1U_CREATE_TUNNEL_RESP tunnel (%u, %u) bearer UE context index %u, msg index %u, id %u, gtp addr len %d \n",
PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP), PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
create_tunnel_resp_pP->enb_S1u_teid[i], create_tunnel_resp_pP->enb_S1u_teid[i],
ue_context_p->ue_context.gnb_gtp_teid[inde_list[i]], ue_context_p->ue_context.gnb_gtp_teid[inde_list[i]],
...@@ -74,23 +73,23 @@ rrc_gNB_process_GTPV1U_CREATE_TUNNEL_RESP( ...@@ -74,23 +73,23 @@ rrc_gNB_process_GTPV1U_CREATE_TUNNEL_RESP(
} }
return 0; return 0;
} else {
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, int offset) 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, int offset)
{ {
int i; if (!create_tunnel_resp_pP) {
struct rrc_gNB_ue_context_s *ue_context_p = NULL; LOG_E(NR_RRC, "create_tunnel_resp_pP error\n");
return -1;
}
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);
LOG_D(NR_RRC, PROTOCOL_NR_RRC_CTXT_UE_FMT" RX CREATE_TUNNEL_RESP num tunnels %u \n", rrc_gNB_ue_context_t *ue_context_p = rrc_gNB_get_ue_context_by_rnti(RC.nrrrc[ctxt_pP->module_id], ctxt_pP->rntiMaybeUEid);
PROTOCOL_NR_RRC_CTXT_UE_ARGS(ctxt_pP), if (!ue_context_p) {
create_tunnel_resp_pP->num_tunnels); LOG_E(NR_RRC, "UE table error\n");
ue_context_p = rrc_gNB_get_ue_context(RC.nrrrc[ctxt_pP->module_id], ctxt_pP->rntiMaybeUEid); return -1;
}
for (i = 0; i < create_tunnel_resp_pP->num_tunnels; i++) { for (int i = 0; i < create_tunnel_resp_pP->num_tunnels; i++) {
ue_context_p->ue_context.gnb_gtp_teid[i + offset] = create_tunnel_resp_pP->gnb_NGu_teid[i]; ue_context_p->ue_context.gnb_gtp_teid[i + offset] = create_tunnel_resp_pP->gnb_NGu_teid[i];
ue_context_p->ue_context.gnb_gtp_addrs[i + offset] = create_tunnel_resp_pP->gnb_addr; ue_context_p->ue_context.gnb_gtp_addrs[i + offset] = create_tunnel_resp_pP->gnb_addr;
ue_context_p->ue_context.gnb_gtp_psi[i + offset] = create_tunnel_resp_pP->pdusession_id[i]; ue_context_p->ue_context.gnb_gtp_psi[i + offset] = create_tunnel_resp_pP->pdusession_id[i];
...@@ -105,7 +104,4 @@ int nr_rrc_gNB_process_GTPV1U_CREATE_TUNNEL_RESP(const protocol_ctxt_t *const ct ...@@ -105,7 +104,4 @@ int nr_rrc_gNB_process_GTPV1U_CREATE_TUNNEL_RESP(const protocol_ctxt_t *const ct
} }
return 0; return 0;
} else {
return -1;
}
} }
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -40,18 +40,6 @@ ...@@ -40,18 +40,6 @@
#include "NR_UL-DCCH-Message.h" #include "NR_UL-DCCH-Message.h"
#include "NGAP_CauseRadioNetwork.h" #include "NGAP_CauseRadioNetwork.h"
typedef struct rrc_ue_ngap_ids_s {
/* Tree related data */
RB_ENTRY(rrc_ue_ngap_ids_s) entries;
// keys
uint16_t ue_initial_id;
uint32_t gNB_ue_ngap_id;
// value
rnti_t ue_rnti;
} rrc_ue_ngap_ids_t;
void void
rrc_gNB_send_NGAP_NAS_FIRST_REQ( rrc_gNB_send_NGAP_NAS_FIRST_REQ(
const protocol_ctxt_t *const ctxt_pP, const protocol_ctxt_t *const ctxt_pP,
...@@ -59,12 +47,7 @@ rrc_gNB_send_NGAP_NAS_FIRST_REQ( ...@@ -59,12 +47,7 @@ rrc_gNB_send_NGAP_NAS_FIRST_REQ(
NR_RRCSetupComplete_IEs_t *rrcSetupComplete NR_RRCSetupComplete_IEs_t *rrcSetupComplete
); );
int int rrc_gNB_process_NGAP_INITIAL_CONTEXT_SETUP_REQ(MessageDef *msg_p, instance_t instance);
rrc_gNB_process_NGAP_INITIAL_CONTEXT_SETUP_REQ(
MessageDef *msg_p,
const char *msg_name,
instance_t instance
);
void void
rrc_gNB_send_NGAP_INITIAL_CONTEXT_SETUP_RESP( rrc_gNB_send_NGAP_INITIAL_CONTEXT_SETUP_RESP(
...@@ -72,20 +55,7 @@ rrc_gNB_send_NGAP_INITIAL_CONTEXT_SETUP_RESP( ...@@ -72,20 +55,7 @@ rrc_gNB_send_NGAP_INITIAL_CONTEXT_SETUP_RESP(
rrc_gNB_ue_context_t *const ue_context_pP rrc_gNB_ue_context_t *const ue_context_pP
); );
int int rrc_gNB_process_NGAP_DOWNLINK_NAS(MessageDef *msg_p, instance_t instance, mui_t *rrc_gNB_mui);
rrc_gNB_process_security(
const protocol_ctxt_t *const ctxt_pP,
rrc_gNB_ue_context_t *const ue_context_pP,
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 void
rrc_gNB_send_NGAP_UPLINK_NAS( rrc_gNB_send_NGAP_UPLINK_NAS(
...@@ -101,19 +71,9 @@ rrc_gNB_send_NGAP_PDUSESSION_SETUP_RESP( ...@@ -101,19 +71,9 @@ rrc_gNB_send_NGAP_PDUSESSION_SETUP_RESP(
uint8_t xid uint8_t xid
); );
void void rrc_gNB_process_NGAP_PDUSESSION_SETUP_REQ(MessageDef *msg_p, instance_t instance);
rrc_gNB_process_NGAP_PDUSESSION_SETUP_REQ(
MessageDef *msg_p,
const char *msg_name,
instance_t instance
);
int int rrc_gNB_process_NGAP_PDUSESSION_MODIFY_REQ(MessageDef *msg_p, instance_t instance);
rrc_gNB_process_NGAP_PDUSESSION_MODIFY_REQ(
MessageDef *msg_p,
const char *msg_name,
instance_t instance
);
int int
rrc_gNB_send_NGAP_PDUSESSION_MODIFY_RESP( rrc_gNB_send_NGAP_PDUSESSION_MODIFY_RESP(
...@@ -128,38 +88,13 @@ rrc_gNB_modify_dedicatedRRCReconfiguration( ...@@ -128,38 +88,13 @@ rrc_gNB_modify_dedicatedRRCReconfiguration(
rrc_gNB_ue_context_t *ue_context_pP rrc_gNB_ue_context_t *ue_context_pP
); );
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);
void int rrc_gNB_process_NGAP_UE_CONTEXT_RELEASE_REQ(MessageDef *msg_p, instance_t instance);
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 int rrc_gNB_process_NGAP_UE_CONTEXT_RELEASE_COMMAND(MessageDef *msg_p, instance_t instance);
rrc_gNB_process_NGAP_UE_CONTEXT_RELEASE_COMMAND(
MessageDef *msg_p,
const char *msg_name,
instance_t instance
);
void rrc_gNB_send_NGAP_UE_CONTEXT_RELEASE_COMPLETE( void rrc_gNB_send_NGAP_UE_CONTEXT_RELEASE_COMPLETE(instance_t instance, uint32_t gNB_ue_ngap_id);
instance_t instance,
uint32_t gNB_ue_ngap_id);
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 void
rrc_gNB_send_NGAP_UE_CAPABILITIES_IND( rrc_gNB_send_NGAP_UE_CAPABILITIES_IND(
...@@ -168,12 +103,7 @@ rrc_gNB_send_NGAP_UE_CAPABILITIES_IND( ...@@ -168,12 +103,7 @@ rrc_gNB_send_NGAP_UE_CAPABILITIES_IND(
NR_UL_DCCH_Message_t *const ul_dcch_msg NR_UL_DCCH_Message_t *const ul_dcch_msg
); );
int int rrc_gNB_process_NGAP_PDUSESSION_RELEASE_COMMAND(MessageDef *msg_p, instance_t instance);
rrc_gNB_process_NGAP_PDUSESSION_RELEASE_COMMAND(
MessageDef *msg_p,
const char *msg_name,
instance_t instance
);
void void
rrc_gNB_send_NGAP_PDUSESSION_RELEASE_RESPONSE( rrc_gNB_send_NGAP_PDUSESSION_RELEASE_RESPONSE(
...@@ -189,17 +119,6 @@ nr_rrc_pdcp_config_security( ...@@ -189,17 +119,6 @@ nr_rrc_pdcp_config_security(
const uint8_t send_security_mode_command const uint8_t send_security_mode_command
); );
struct rrc_gNB_ue_context_s * int rrc_gNB_process_PAGING_IND(MessageDef *msg_p, instance_t instance);
rrc_gNB_get_ue_context_from_ngap_ids(
const instance_t instanceP,
const uint16_t ue_initial_idP,
const uint32_t gNB_ue_ngap_idP
);
int
rrc_gNB_process_PAGING_IND(
MessageDef *msg_p,
const char *msg_name,
instance_t instance);
#endif #endif
...@@ -38,15 +38,14 @@ ...@@ -38,15 +38,14 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int rrc_gNB_compare_ue_rnti_id( int rrc_gNB_compare_ue_rnti_id(rrc_gNB_ue_context_t *c1_pP, rrc_gNB_ue_context_t *c2_pP)
struct rrc_gNB_ue_context_s *c1_pP, struct rrc_gNB_ue_context_s *c2_pP)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
{ {
if (c1_pP->ue_id_rnti > c2_pP->ue_id_rnti) { if (c1_pP->ue_context.gNB_ue_ngap_id > c2_pP->ue_context.gNB_ue_ngap_id) {
return 1; return 1;
} }
if (c1_pP->ue_id_rnti < c2_pP->ue_id_rnti) { if (c1_pP->ue_context.gNB_ue_ngap_id < c2_pP->ue_context.gNB_ue_ngap_id) {
return -1; return -1;
} }
...@@ -57,25 +56,17 @@ int rrc_gNB_compare_ue_rnti_id( ...@@ -57,25 +56,17 @@ int rrc_gNB_compare_ue_rnti_id(
RB_GENERATE(rrc_nr_ue_tree_s, rrc_gNB_ue_context_s, entries, RB_GENERATE(rrc_nr_ue_tree_s, rrc_gNB_ue_context_s, entries,
rrc_gNB_compare_ue_rnti_id); rrc_gNB_compare_ue_rnti_id);
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
struct rrc_gNB_ue_context_s * rrc_gNB_ue_context_t *rrc_gNB_allocate_new_ue_context(gNB_RRC_INST *rrc_instance_pP)
rrc_gNB_allocate_new_UE_context(
gNB_RRC_INST *rrc_instance_pP
)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
{ {
struct rrc_gNB_ue_context_s *new_p; rrc_gNB_ue_context_t *new_p = calloc(1, sizeof(*new_p));
new_p = (struct rrc_gNB_ue_context_s * )malloc(sizeof(struct rrc_gNB_ue_context_s));
if (new_p == NULL) { if (new_p == NULL) {
LOG_E(RRC, "Cannot allocate new ue context\n"); LOG_E(NR_RRC, "Cannot allocate new ue context\n");
return NULL; return NULL;
} }
new_p->ue_context.gNB_ue_ngap_id = uid_linear_allocator_new(&rrc_instance_pP->uid_allocator);
memset(new_p, 0, sizeof(struct rrc_gNB_ue_context_s));
new_p->local_uid = uid_linear_allocator_new(&rrc_instance_pP->uid_allocator);
for(int i = 0; i < NB_RB_MAX; i++) { for(int i = 0; i < NB_RB_MAX; i++) {
new_p->ue_context.e_rab[i].xid = -1; new_p->ue_context.e_rab[i].xid = -1;
...@@ -83,94 +74,66 @@ rrc_gNB_allocate_new_UE_context( ...@@ -83,94 +74,66 @@ rrc_gNB_allocate_new_UE_context(
new_p->ue_context.modify_e_rab[i].xid = -1; new_p->ue_context.modify_e_rab[i].xid = -1;
} }
LOG_D(NR_RRC,"Returning new UE context at %p\n",new_p); LOG_I(NR_RRC, "Returning new RRC UE context RRC ue id: %d\n", new_p->ue_context.gNB_ue_ngap_id);
return(new_p); return(new_p);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
struct rrc_gNB_ue_context_s * rrc_gNB_ue_context_t *rrc_gNB_get_ue_context(gNB_RRC_INST *rrc_instance_pP, ue_id_t ue)
rrc_gNB_get_ue_context(
gNB_RRC_INST *rrc_instance_pP,
rnti_t rntiP)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
{ {
rrc_gNB_ue_context_t temp; rrc_gNB_ue_context_t temp;
memset(&temp, 0, sizeof(struct rrc_gNB_ue_context_s));
/* gNB ue rrc id = 24 bits wide */ /* gNB ue rrc id = 24 bits wide */
temp.ue_id_rnti = rntiP; temp.ue_context.gNB_ue_ngap_id = ue;
struct rrc_gNB_ue_context_s *ue_context_p = NULL; return RB_FIND(rrc_nr_ue_tree_s, &rrc_instance_pP->rrc_ue_head, &temp);
ue_context_p = RB_FIND(rrc_nr_ue_tree_s, &rrc_instance_pP->rrc_ue_head, &temp); }
if ( ue_context_p != NULL) { rrc_gNB_ue_context_t *rrc_gNB_get_ue_context_by_rnti(gNB_RRC_INST *rrc_instance_pP, rnti_t rntiP)
return ue_context_p; {
} else { rrc_gNB_ue_context_t *ue_context_p;
RB_FOREACH(ue_context_p, rrc_nr_ue_tree_s, &(rrc_instance_pP->rrc_ue_head)) { RB_FOREACH(ue_context_p, rrc_nr_ue_tree_s, &(rrc_instance_pP->rrc_ue_head))
if (ue_context_p->ue_context.rnti == rntiP) { {
if (ue_context_p->ue_context.rnti == rntiP)
return ue_context_p; return ue_context_p;
} }
} LOG_W(NR_RRC, "search by rnti not found %04x\n", rntiP);
return NULL; return NULL;
}
} }
void rrc_gNB_free_mem_UE_context( void rrc_gNB_free_mem_ue_context(rrc_gNB_ue_context_t *const ue_context_pP)
const protocol_ctxt_t *const ctxt_pP,
struct rrc_gNB_ue_context_s *const ue_context_pP
)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
{ {
free(ue_context_pP);
LOG_T(RRC, LOG_T(NR_RRC, " Clearing UE context 0x%p (free internal structs)\n", ue_context_pP);
PROTOCOL_NR_RRC_CTXT_UE_FMT" Clearing UE context 0x%p (free internal structs)\n",
PROTOCOL_NR_RRC_CTXT_UE_ARGS(ctxt_pP),
ue_context_pP);
//ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_LTE_SCellToAddMod_r10, &ue_context_pP->ue_context.sCell_config[0]);
//ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_LTE_SCellToAddMod_r10, &ue_context_pP->ue_context.sCell_config[1]);
// empty the internal fields of the UE context here
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void rrc_gNB_remove_ue_context( void rrc_gNB_remove_ue_context(gNB_RRC_INST *rrc_instance_pP, rrc_gNB_ue_context_t *ue_context_pP)
const protocol_ctxt_t *const ctxt_pP,
gNB_RRC_INST *rrc_instance_pP,
struct rrc_gNB_ue_context_s *ue_context_pP)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
{ {
if (rrc_instance_pP == NULL) { if (rrc_instance_pP == NULL) {
LOG_E(RRC, PROTOCOL_NR_RRC_CTXT_UE_FMT" Bad RRC instance\n", LOG_E(NR_RRC, " Bad RRC instance\n");
PROTOCOL_NR_RRC_CTXT_UE_ARGS(ctxt_pP));
return; return;
} }
if (ue_context_pP == NULL) { if (ue_context_pP == NULL) {
LOG_E(RRC, PROTOCOL_NR_RRC_CTXT_UE_FMT" Trying to free a NULL UE context\n", LOG_E(NR_RRC, "Trying to free a NULL UE context\n");
PROTOCOL_NR_RRC_CTXT_UE_ARGS(ctxt_pP));
return; return;
} }
RB_REMOVE(rrc_nr_ue_tree_s, &rrc_instance_pP->rrc_ue_head, ue_context_pP); RB_REMOVE(rrc_nr_ue_tree_s, &rrc_instance_pP->rrc_ue_head, ue_context_pP);
rrc_gNB_free_mem_UE_context(ctxt_pP, ue_context_pP); uid_linear_allocator_free(&rrc_instance_pP->uid_allocator, ue_context_pP->ue_context.gNB_ue_ngap_id);
uid_linear_allocator_free(&rrc_instance_pP->uid_allocator, ue_context_pP->local_uid); rrc_gNB_free_mem_ue_context(ue_context_pP);
free(ue_context_pP); LOG_I(NR_RRC, "Removed UE context\n");
rrc_instance_pP->Nb_ue --;
LOG_I(RRC,
PROTOCOL_NR_RRC_CTXT_UE_FMT" Removed UE context\n",
PROTOCOL_NR_RRC_CTXT_UE_ARGS(ctxt_pP));
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// return the ue context if there is already an UE with ue_identityP, NULL otherwise // return the ue context if there is already an UE with ue_identityP, NULL otherwise
struct rrc_gNB_ue_context_s * rrc_gNB_ue_context_t *rrc_gNB_ue_context_random_exist(gNB_RRC_INST *rrc_instance_pP, const uint64_t ue_identityP)
rrc_gNB_ue_context_random_exist(
gNB_RRC_INST *rrc_instance_pP,
const uint64_t ue_identityP
)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
{ {
struct rrc_gNB_ue_context_s *ue_context_p = NULL; rrc_gNB_ue_context_t *ue_context_p = NULL;
RB_FOREACH(ue_context_p, rrc_nr_ue_tree_s, &rrc_instance_pP->rrc_ue_head) { RB_FOREACH(ue_context_p, rrc_nr_ue_tree_s, &rrc_instance_pP->rrc_ue_head) {
if (ue_context_p->ue_context.random_ue_identity == ue_identityP) if (ue_context_p->ue_context.random_ue_identity == ue_identityP)
return ue_context_p; return ue_context_p;
...@@ -180,63 +143,48 @@ rrc_gNB_ue_context_random_exist( ...@@ -180,63 +143,48 @@ rrc_gNB_ue_context_random_exist(
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// return the ue context if there is already an UE with the same S-TMSI, NULL otherwise // return the ue context if there is already an UE with the same S-TMSI, NULL otherwise
struct rrc_gNB_ue_context_s * rrc_gNB_ue_context_t *rrc_gNB_ue_context_5g_s_tmsi_exist(gNB_RRC_INST *rrc_instance_pP, const uint64_t s_TMSI)
rrc_gNB_ue_context_5g_s_tmsi_exist(
gNB_RRC_INST *rrc_instance_pP,
const uint64_t s_TMSI
)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
{ {
struct rrc_gNB_ue_context_s *ue_context_p = NULL; rrc_gNB_ue_context_t *ue_context_p = NULL;
RB_FOREACH(ue_context_p, rrc_nr_ue_tree_s, &rrc_instance_pP->rrc_ue_head) { RB_FOREACH(ue_context_p, rrc_nr_ue_tree_s, &rrc_instance_pP->rrc_ue_head)
LOG_I(NR_RRC,"Checking for UE 5G S-TMSI %ld: RNTI %04x\n", {
s_TMSI, ue_context_p->ue_context.rnti); LOG_I(NR_RRC, "Checking for UE 5G S-TMSI %ld: RNTI %04x\n", s_TMSI, ue_context_p->ue_context.rnti);
if (ue_context_p->ue_context.ng_5G_S_TMSI_Part1 == s_TMSI)
if (ue_context_p->ue_context.ng_5G_S_TMSI_Part1 == s_TMSI) {
return ue_context_p; return ue_context_p;
} }
}
return NULL; return NULL;
} }
void rrc_gNB_update_ue_context_rnti(rnti_t rnti, gNB_RRC_INST *rrc_instance_pP, uint32_t gNB_ue_ngap_id)
{
// rnti will need to be a fast access key, with indexing, today it is sequential search
// This function will update the index when it will be made
rrc_gNB_ue_context_t *ue_context_p = rrc_gNB_get_ue_context(rrc_instance_pP, gNB_ue_ngap_id);
if (ue_context_p)
ue_context_p->ue_context.rnti = rnti;
else
LOG_E(NR_RRC, "update rnti on a wrong UE id\n");
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// return a new ue context structure if ue_identityP, ctxt_pP->rnti not found in collection // return a new ue context structure if ue_identityP, rnti not found in collection
struct rrc_gNB_ue_context_s * rrc_gNB_ue_context_t *rrc_gNB_create_ue_context(rnti_t rnti, gNB_RRC_INST *rrc_instance_pP, const uint64_t ue_identityP)
rrc_gNB_get_next_free_ue_context(
const protocol_ctxt_t *const ctxt_pP,
gNB_RRC_INST *rrc_instance_pP,
const uint64_t ue_identityP
)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
{ {
struct rrc_gNB_ue_context_s *ue_context_p = NULL; rrc_gNB_ue_context_t *ue_context_p = rrc_gNB_get_ue_context_by_rnti(rrc_instance_pP, rnti);
ue_context_p = rrc_gNB_get_ue_context(rrc_instance_pP, ctxt_pP->rntiMaybeUEid);
if (ue_context_p == NULL) { if (ue_context_p) {
ue_context_p = rrc_gNB_allocate_new_UE_context(rrc_instance_pP); LOG_E(NR_RRC, "Cannot create new UE context, already exist rnti: %04x\n", rnti);
return ue_context_p;
}
if (ue_context_p == NULL) { ue_context_p = rrc_gNB_allocate_new_ue_context(rrc_instance_pP);
LOG_E(NR_RRC, if (ue_context_p == NULL)
PROTOCOL_NR_RRC_CTXT_UE_FMT" Cannot create new UE context, no memory\n",
PROTOCOL_NR_RRC_CTXT_UE_ARGS(ctxt_pP));
return NULL; return NULL;
}
ue_context_p->ue_id_rnti = ctxt_pP->rntiMaybeUEid; // here ue_id_rnti is just a key, may be something else ue_context_p->ue_context.rnti = rnti;
ue_context_p->ue_context.rnti = ctxt_pP->rntiMaybeUEid; // yes duplicate, 1 may be removed
ue_context_p->ue_context.random_ue_identity = ue_identityP; ue_context_p->ue_context.random_ue_identity = ue_identityP;
RB_INSERT(rrc_nr_ue_tree_s, &rrc_instance_pP->rrc_ue_head, ue_context_p); RB_INSERT(rrc_nr_ue_tree_s, &rrc_instance_pP->rrc_ue_head, ue_context_p);
LOG_D(NR_RRC, LOG_W(NR_RRC, " Created new UE context rnti: %04x, random ue id %lx, RRC ue id %u\n", rnti, ue_identityP, ue_context_p->ue_context.gNB_ue_ngap_id);
PROTOCOL_NR_RRC_CTXT_UE_FMT" Created new UE context uid %u\n",
PROTOCOL_NR_RRC_CTXT_UE_ARGS(ctxt_pP),
ue_context_p->local_uid);
return ue_context_p; return ue_context_p;
} else {
LOG_E(NR_RRC,
PROTOCOL_NR_RRC_CTXT_UE_FMT" Cannot create new UE context, already exist\n",
PROTOCOL_NR_RRC_CTXT_UE_ARGS(ctxt_pP));
return NULL;
}
return(ue_context_p);
} }
...@@ -34,52 +34,23 @@ ...@@ -34,52 +34,23 @@
#include "COMMON/platform_types.h" #include "COMMON/platform_types.h"
#include "nr_rrc_defs.h" #include "nr_rrc_defs.h"
int rrc_gNB_compare_ue_rnti_id( int rrc_gNB_compare_ue_rnti_id(rrc_gNB_ue_context_t* c1_pP, rrc_gNB_ue_context_t* c2_pP);
struct rrc_gNB_ue_context_s* c1_pP,
struct rrc_gNB_ue_context_s* c2_pP
);
RB_PROTOTYPE(rrc_nr_ue_tree_s, rrc_gNB_ue_context_s, entries, rrc_gNB_compare_ue_rnti_id); RB_PROTOTYPE(rrc_nr_ue_tree_s, rrc_gNB_ue_context_s, entries, rrc_gNB_compare_ue_rnti_id);
struct rrc_gNB_ue_context_s* rrc_gNB_ue_context_t* rrc_gNB_allocate_new_ue_context(gNB_RRC_INST* rrc_instance_pP);
rrc_gNB_allocate_new_UE_context(
gNB_RRC_INST* rrc_instance_pP
);
struct rrc_gNB_ue_context_s* rrc_gNB_ue_context_t* rrc_gNB_get_ue_context(gNB_RRC_INST* rrc_instance_pP, ue_id_t ue);
rrc_gNB_get_ue_context( rrc_gNB_ue_context_t* rrc_gNB_get_ue_context_by_rnti(gNB_RRC_INST* rrc_instance_pP, rnti_t rntiP);
gNB_RRC_INST* rrc_instance_pP,
rnti_t rntiP
);
void rrc_gNB_free_mem_UE_context( void rrc_gNB_free_mem_ue_context(rrc_gNB_ue_context_t* const ue_context_pP);
const protocol_ctxt_t *const ctxt_pP,
struct rrc_gNB_ue_context_s *const ue_context_pP
);
void rrc_gNB_remove_ue_context( void rrc_gNB_remove_ue_context(gNB_RRC_INST* rrc_instance_pP, rrc_gNB_ue_context_t* ue_context_pP);
const protocol_ctxt_t* const ctxt_pP,
gNB_RRC_INST* rrc_instance_pP,
struct rrc_gNB_ue_context_s* ue_context_pP
);
struct rrc_gNB_ue_context_s * rrc_gNB_ue_context_t* rrc_gNB_ue_context_random_exist(gNB_RRC_INST* rrc_instance_pP, const uint64_t ue_identityP);
rrc_gNB_ue_context_random_exist(
gNB_RRC_INST *rrc_instance_pP,
const uint64_t ue_identityP
);
struct rrc_gNB_ue_context_s * rrc_gNB_ue_context_t* rrc_gNB_ue_context_5g_s_tmsi_exist(gNB_RRC_INST* rrc_instance_pP, const uint64_t s_TMSI);
rrc_gNB_ue_context_5g_s_tmsi_exist( void rrc_gNB_update_ue_context_rnti(rnti_t rnti, gNB_RRC_INST* rrc_instance_pP, uint32_t gNB_ue_ngap_id);
gNB_RRC_INST *rrc_instance_pP, rrc_gNB_ue_context_t* rrc_gNB_create_ue_context(rnti_t rnti, gNB_RRC_INST* rrc_instance_pP, const uint64_t ue_identityP);
const uint64_t s_TMSI
);
struct rrc_gNB_ue_context_s *
rrc_gNB_get_next_free_ue_context(
const protocol_ctxt_t *const ctxt_pP,
gNB_RRC_INST *rrc_instance_pP,
const uint64_t ue_identityP
);
#endif #endif
...@@ -45,9 +45,8 @@ ...@@ -45,9 +45,8 @@
#include <openair2/RRC/NR/nr_rrc_proto.h> #include <openair2/RRC/NR/nr_rrc_proto.h>
#include "pdcp.h" #include "pdcp.h"
void rrc_parse_ue_capabilities(gNB_RRC_INST *rrc, NR_UE_CapabilityRAT_ContainerList_t *UE_CapabilityRAT_ContainerList, x2ap_ENDC_sgnb_addition_req_t *m, NR_CG_ConfigInfo_IEs_t *cg_config_info) { void rrc_parse_ue_capabilities(gNB_RRC_INST *rrc, NR_UE_CapabilityRAT_ContainerList_t *UE_CapabilityRAT_ContainerList, x2ap_ENDC_sgnb_addition_req_t *m, NR_CG_ConfigInfo_IEs_t *cg_config_info)
struct rrc_gNB_ue_context_s *ue_context_p = NULL; {
OCTET_STRING_t *ueCapabilityRAT_Container_nr=NULL; OCTET_STRING_t *ueCapabilityRAT_Container_nr=NULL;
OCTET_STRING_t *ueCapabilityRAT_Container_MRDC=NULL; OCTET_STRING_t *ueCapabilityRAT_Container_MRDC=NULL;
asn_dec_rval_t dec_rval; asn_dec_rval_t dec_rval;
...@@ -62,36 +61,27 @@ void rrc_parse_ue_capabilities(gNB_RRC_INST *rrc, NR_UE_CapabilityRAT_ContainerL ...@@ -62,36 +61,27 @@ void rrc_parse_ue_capabilities(gNB_RRC_INST *rrc, NR_UE_CapabilityRAT_ContainerL
} }
// decode and store capabilities // decode and store capabilities
ue_context_p = rrc_gNB_allocate_new_UE_context(rrc); rrc_gNB_ue_context_t *ue_context_p = rrc_gNB_allocate_new_ue_context(rrc);
gNB_RRC_UE_t *UE = &ue_context_p->ue_context;
if (ueCapabilityRAT_Container_nr != NULL) { if (ueCapabilityRAT_Container_nr != NULL) {
dec_rval = uper_decode(NULL, dec_rval = uper_decode(NULL, &asn_DEF_NR_UE_NR_Capability, (void **)&UE->UE_Capability_nr, ueCapabilityRAT_Container_nr->buf, ueCapabilityRAT_Container_nr->size, 0, 0);
&asn_DEF_NR_UE_NR_Capability,
(void **)&ue_context_p->ue_context.UE_Capability_nr,
ueCapabilityRAT_Container_nr->buf,
ueCapabilityRAT_Container_nr->size, 0, 0);
if ((dec_rval.code != RC_OK) && (dec_rval.consumed == 0)) { if ((dec_rval.code != RC_OK) && (dec_rval.consumed == 0)) {
LOG_E(RRC, "Failed to decode UE NR capabilities (%zu bytes) container size %lu\n", dec_rval.consumed,ueCapabilityRAT_Container_nr->size); LOG_E(RRC, "Failed to decode UE NR capabilities (%zu bytes) container size %lu\n", dec_rval.consumed,ueCapabilityRAT_Container_nr->size);
ASN_STRUCT_FREE(asn_DEF_NR_UE_NR_Capability, ASN_STRUCT_FREE(asn_DEF_NR_UE_NR_Capability, UE->UE_Capability_nr);
ue_context_p->ue_context.UE_Capability_nr); UE->UE_Capability_nr = 0;
ue_context_p->ue_context.UE_Capability_nr = 0;
AssertFatal(1==0,"exiting\n"); AssertFatal(1==0,"exiting\n");
} }
} }
if (ueCapabilityRAT_Container_MRDC != NULL) { if (ueCapabilityRAT_Container_MRDC != NULL) {
dec_rval = uper_decode(NULL, dec_rval = uper_decode(NULL, &asn_DEF_NR_UE_MRDC_Capability, (void **)&UE->UE_Capability_MRDC, ueCapabilityRAT_Container_MRDC->buf, ueCapabilityRAT_Container_MRDC->size, 0, 0);
&asn_DEF_NR_UE_MRDC_Capability,
(void **)&ue_context_p->ue_context.UE_Capability_MRDC,
ueCapabilityRAT_Container_MRDC->buf,
ueCapabilityRAT_Container_MRDC->size, 0, 0);
if ((dec_rval.code != RC_OK) && (dec_rval.consumed == 0)) { if ((dec_rval.code != RC_OK) && (dec_rval.consumed == 0)) {
LOG_E(RRC, "Failed to decode UE MRDC capabilities (%zu bytes)\n", dec_rval.consumed); LOG_E(RRC, "Failed to decode UE MRDC capabilities (%zu bytes)\n", dec_rval.consumed);
ASN_STRUCT_FREE(asn_DEF_NR_UE_MRDC_Capability, ASN_STRUCT_FREE(asn_DEF_NR_UE_MRDC_Capability, UE->UE_Capability_MRDC);
ue_context_p->ue_context.UE_Capability_MRDC); UE->UE_Capability_MRDC = 0;
ue_context_p->ue_context.UE_Capability_MRDC = 0;
AssertFatal(1==0,"exiting\n"); AssertFatal(1==0,"exiting\n");
} }
} }
...@@ -99,16 +89,16 @@ void rrc_parse_ue_capabilities(gNB_RRC_INST *rrc, NR_UE_CapabilityRAT_ContainerL ...@@ -99,16 +89,16 @@ void rrc_parse_ue_capabilities(gNB_RRC_INST *rrc, NR_UE_CapabilityRAT_ContainerL
// dump ue_capabilities // dump ue_capabilities
if ( LOG_DEBUGFLAG(DEBUG_ASN1) && ueCapabilityRAT_Container_nr != NULL ) { if ( LOG_DEBUGFLAG(DEBUG_ASN1) && ueCapabilityRAT_Container_nr != NULL ) {
xer_fprint(stdout, &asn_DEF_NR_UE_NR_Capability, ue_context_p->ue_context.UE_Capability_nr); xer_fprint(stdout, &asn_DEF_NR_UE_NR_Capability, UE->UE_Capability_nr);
} }
if ( LOG_DEBUGFLAG(DEBUG_ASN1) && ueCapabilityRAT_Container_MRDC != NULL ) { if ( LOG_DEBUGFLAG(DEBUG_ASN1) && ueCapabilityRAT_Container_MRDC != NULL ) {
xer_fprint(stdout, &asn_DEF_NR_UE_MRDC_Capability, ue_context_p->ue_context.UE_Capability_MRDC); xer_fprint(stdout, &asn_DEF_NR_UE_MRDC_Capability, UE->UE_Capability_MRDC);
} }
LOG_A(NR_RRC, "Successfully decoded UE NR capabilities (NR and MRDC)\n"); LOG_A(NR_RRC, "Successfully decoded UE NR capabilities (NR and MRDC)\n");
ue_context_p->ue_context.spCellConfig = calloc(1, sizeof(struct NR_SpCellConfig)); UE->spCellConfig = calloc(1, sizeof(struct NR_SpCellConfig));
ue_context_p->ue_context.spCellConfig->spCellConfigDedicated = rrc->carrier.servingcellconfig; UE->spCellConfig->spCellConfigDedicated = rrc->carrier.servingcellconfig;
LOG_I(NR_RRC,"Adding new NSA user (%p)\n",ue_context_p); LOG_I(NR_RRC,"Adding new NSA user (%p)\n",ue_context_p);
rrc_add_nsa_user(rrc,ue_context_p, m); rrc_add_nsa_user(rrc,ue_context_p, m);
} }
...@@ -117,7 +107,8 @@ void rrc_parse_ue_capabilities(gNB_RRC_INST *rrc, NR_UE_CapabilityRAT_ContainerL ...@@ -117,7 +107,8 @@ void rrc_parse_ue_capabilities(gNB_RRC_INST *rrc, NR_UE_CapabilityRAT_ContainerL
RB_PROTOTYPE(rrc_nr_ue_tree_s, rrc_gNB_ue_context_s, entries, RB_PROTOTYPE(rrc_nr_ue_tree_s, rrc_gNB_ue_context_s, entries,
rrc_gNB_compare_ue_rnti_id); rrc_gNB_compare_ue_rnti_id);
void rrc_add_nsa_user(gNB_RRC_INST *rrc,struct rrc_gNB_ue_context_s *ue_context_p, x2ap_ENDC_sgnb_addition_req_t *m) { void rrc_add_nsa_user(gNB_RRC_INST *rrc, rrc_gNB_ue_context_t *ue_context_p, x2ap_ENDC_sgnb_addition_req_t *m)
{
// generate nr-Config-r15 containers for LTE RRC : inside message for X2 EN-DC (CG-Config Message from 38.331) // generate nr-Config-r15 containers for LTE RRC : inside message for X2 EN-DC (CG-Config Message from 38.331)
rrc_gNB_carrier_data_t *carrier=&rrc->carrier; rrc_gNB_carrier_data_t *carrier=&rrc->carrier;
const gNB_RrcConfigurationReq *configuration = &rrc->configuration; const gNB_RrcConfigurationReq *configuration = &rrc->configuration;
...@@ -129,6 +120,7 @@ void rrc_add_nsa_user(gNB_RRC_INST *rrc,struct rrc_gNB_ue_context_s *ue_context_ ...@@ -129,6 +120,7 @@ void rrc_add_nsa_user(gNB_RRC_INST *rrc,struct rrc_gNB_ue_context_s *ue_context_
unsigned char *kUPenc = NULL; unsigned char *kUPenc = NULL;
unsigned char *kUPint = NULL; unsigned char *kUPint = NULL;
int i; int i;
gNB_RRC_UE_t *UE = &ue_context_p->ue_context;
// In case of phy-test and do-ra mode, read UE capabilities directly from file // In case of phy-test and do-ra mode, read UE capabilities directly from file
if (get_softmodem_params()->phy_test == 1 || get_softmodem_params()->do_ra == 1) { if (get_softmodem_params()->phy_test == 1 || get_softmodem_params()->do_ra == 1) {
...@@ -150,25 +142,20 @@ void rrc_add_nsa_user(gNB_RRC_INST *rrc,struct rrc_gNB_ue_context_s *ue_context_ ...@@ -150,25 +142,20 @@ void rrc_add_nsa_user(gNB_RRC_INST *rrc,struct rrc_gNB_ue_context_s *ue_context_
} }
else else
LOG_E(NR_RRC,"Could not open UE Capabilities input file. Not handling OAI UE Capabilities.\n"); LOG_E(NR_RRC,"Could not open UE Capabilities input file. Not handling OAI UE Capabilities.\n");
ue_context_p->ue_context.UE_Capability_nr = UE_Capability_nr; UE->UE_Capability_nr = UE_Capability_nr;
} }
// NR RRCReconfiguration // NR RRCReconfiguration
AssertFatal(rrc->Nb_ue < MAX_NR_RRC_UE_CONTEXTS,"cannot add another UE\n"); UE->reconfig = calloc(1, sizeof(NR_RRCReconfiguration_t));
ue_context_p->ue_context.reconfig = calloc(1,sizeof(NR_RRCReconfiguration_t)); UE->secondaryCellGroup = calloc(1, sizeof(NR_CellGroupConfig_t));
ue_context_p->ue_context.secondaryCellGroup = calloc(1,sizeof(NR_CellGroupConfig_t)); memset((void *)UE->reconfig, 0, sizeof(NR_RRCReconfiguration_t));
memset((void *)ue_context_p->ue_context.reconfig,0,sizeof(NR_RRCReconfiguration_t)); UE->reconfig->rrc_TransactionIdentifier = 0;
ue_context_p->ue_context.reconfig->rrc_TransactionIdentifier=0; UE->reconfig->criticalExtensions.present = NR_RRCReconfiguration__criticalExtensions_PR_rrcReconfiguration;
ue_context_p->ue_context.reconfig->criticalExtensions.present = NR_RRCReconfiguration__criticalExtensions_PR_rrcReconfiguration;
NR_RRCReconfiguration_IEs_t *reconfig_ies=calloc(1,sizeof(NR_RRCReconfiguration_IEs_t)); NR_RRCReconfiguration_IEs_t *reconfig_ies=calloc(1,sizeof(NR_RRCReconfiguration_IEs_t));
ue_context_p->ue_context.reconfig->criticalExtensions.choice.rrcReconfiguration = reconfig_ies; UE->reconfig->criticalExtensions.choice.rrcReconfiguration = reconfig_ies;
ue_context_p->ue_context.rb_config = calloc(1,sizeof(NR_RRCReconfiguration_t)); UE->rb_config = calloc(1, sizeof(NR_RRCReconfiguration_t));
if (get_softmodem_params()->phy_test == 1 || get_softmodem_params()->do_ra == 1 || get_softmodem_params()->sa == 1){ if (get_softmodem_params()->phy_test == 1 || get_softmodem_params()->do_ra == 1 || get_softmodem_params()->sa == 1){
fill_default_rbconfig(ue_context_p->ue_context.rb_config, fill_default_rbconfig(UE->rb_config, 10 /* EPS bearer ID */, 1 /* drb ID */, NR_CipheringAlgorithm_nea0, NR_SecurityConfig__keyToUse_master);
10 /* EPS bearer ID */,
1 /* drb ID */,
NR_CipheringAlgorithm_nea0,
NR_SecurityConfig__keyToUse_master);
} else { } else {
/* TODO: handle more than one bearer */ /* TODO: handle more than one bearer */
if (m == NULL) { if (m == NULL) {
...@@ -181,9 +168,9 @@ void rrc_add_nsa_user(gNB_RRC_INST *rrc,struct rrc_gNB_ue_context_s *ue_context_ ...@@ -181,9 +168,9 @@ void rrc_add_nsa_user(gNB_RRC_INST *rrc,struct rrc_gNB_ue_context_s *ue_context_
} }
/* store security key and security capabilities */ /* store security key and security capabilities */
memcpy(ue_context_p->ue_context.kgnb, m->kgnb, 32); memcpy(UE->kgnb, m->kgnb, 32);
ue_context_p->ue_context.security_capabilities.nRencryption_algorithms = m->security_capabilities.encryption_algorithms; UE->security_capabilities.nRencryption_algorithms = m->security_capabilities.encryption_algorithms;
ue_context_p->ue_context.security_capabilities.nRintegrity_algorithms = m->security_capabilities.integrity_algorithms; UE->security_capabilities.nRintegrity_algorithms = m->security_capabilities.integrity_algorithms;
/* Select ciphering algorithm based on gNB configuration file and /* Select ciphering algorithm based on gNB configuration file and
* UE's supported algorithms. * UE's supported algorithms.
...@@ -191,7 +178,7 @@ void rrc_add_nsa_user(gNB_RRC_INST *rrc,struct rrc_gNB_ue_context_s *ue_context_ ...@@ -191,7 +178,7 @@ void rrc_add_nsa_user(gNB_RRC_INST *rrc,struct rrc_gNB_ue_context_s *ue_context_
* The ordering of the list comes from the configuration file. * The ordering of the list comes from the configuration file.
*/ */
/* preset nea0 as fallback */ /* preset nea0 as fallback */
ue_context_p->ue_context.ciphering_algorithm = 0; UE->ciphering_algorithm = 0;
for (i = 0; i < rrc->security.ciphering_algorithms_count; i++) { for (i = 0; i < rrc->security.ciphering_algorithms_count; i++) {
int nea_mask[4] = { int nea_mask[4] = {
0, 0,
...@@ -203,13 +190,13 @@ void rrc_add_nsa_user(gNB_RRC_INST *rrc,struct rrc_gNB_ue_context_s *ue_context_ ...@@ -203,13 +190,13 @@ void rrc_add_nsa_user(gNB_RRC_INST *rrc,struct rrc_gNB_ue_context_s *ue_context_
/* nea0 already preselected */ /* nea0 already preselected */
break; break;
} }
if (ue_context_p->ue_context.security_capabilities.nRencryption_algorithms & nea_mask[rrc->security.ciphering_algorithms[i]]) { if (UE->security_capabilities.nRencryption_algorithms & nea_mask[rrc->security.ciphering_algorithms[i]]) {
ue_context_p->ue_context.ciphering_algorithm = rrc->security.ciphering_algorithms[i]; UE->ciphering_algorithm = rrc->security.ciphering_algorithms[i];
break; break;
} }
} }
LOG_I(RRC, "selecting ciphering algorithm %d\n", (int)ue_context_p->ue_context.ciphering_algorithm); LOG_I(RRC, "selecting ciphering algorithm %d\n", (int)UE->ciphering_algorithm);
/* integrity: no integrity protection for DRB in ENDC mode /* integrity: no integrity protection for DRB in ENDC mode
* as written in 38.331: "If UE is connected to E-UTRA/EPC, this field * as written in 38.331: "If UE is connected to E-UTRA/EPC, this field
...@@ -218,49 +205,46 @@ void rrc_add_nsa_user(gNB_RRC_INST *rrc,struct rrc_gNB_ue_context_s *ue_context_ ...@@ -218,49 +205,46 @@ void rrc_add_nsa_user(gNB_RRC_INST *rrc,struct rrc_gNB_ue_context_s *ue_context_
* So nothing for DRB. Plus a test with a COTS UE revealed that it * So nothing for DRB. Plus a test with a COTS UE revealed that it
* did not apply integrity on the DRB. * did not apply integrity on the DRB.
*/ */
ue_context_p->ue_context.integrity_algorithm = 0; UE->integrity_algorithm = 0;
LOG_I(RRC, "selecting integrity algorithm %d\n", ue_context_p->ue_context.integrity_algorithm); LOG_I(RRC, "selecting integrity algorithm %d\n", UE->integrity_algorithm);
/* derive UP security key */ /* derive UP security key */
nr_derive_key_up_enc(ue_context_p->ue_context.ciphering_algorithm, nr_derive_key_up_enc(UE->ciphering_algorithm, UE->kgnb, &kUPenc);
ue_context_p->ue_context.kgnb, nr_derive_key_up_int(UE->integrity_algorithm, UE->kgnb, &kUPint);
&kUPenc);
nr_derive_key_up_int(ue_context_p->ue_context.integrity_algorithm,
ue_context_p->ue_context.kgnb,
&kUPint);
e_NR_CipheringAlgorithm cipher_algo; e_NR_CipheringAlgorithm cipher_algo;
switch (ue_context_p->ue_context.ciphering_algorithm) { switch (UE->ciphering_algorithm) {
case 0: cipher_algo = NR_CipheringAlgorithm_nea0; break; case 0:
case 1: cipher_algo = NR_CipheringAlgorithm_nea1; break; cipher_algo = NR_CipheringAlgorithm_nea0;
case 2: cipher_algo = NR_CipheringAlgorithm_nea2; break; break;
case 3: cipher_algo = NR_CipheringAlgorithm_nea3; break; case 1:
default: LOG_E(RRC, "%s:%d:%s: fatal\n", __FILE__, __LINE__, __FUNCTION__); exit(1); cipher_algo = NR_CipheringAlgorithm_nea1;
break;
case 2:
cipher_algo = NR_CipheringAlgorithm_nea2;
break;
case 3:
cipher_algo = NR_CipheringAlgorithm_nea3;
break;
default:
LOG_E(RRC, "%s:%d:%s: fatal\n", __FILE__, __LINE__, __FUNCTION__);
exit(1);
} }
fill_default_rbconfig(ue_context_p->ue_context.rb_config, fill_default_rbconfig(UE->rb_config, m->e_rabs_tobeadded[0].e_rab_id, m->e_rabs_tobeadded[0].drb_ID, cipher_algo, NR_SecurityConfig__keyToUse_secondary);
m->e_rabs_tobeadded[0].e_rab_id,
m->e_rabs_tobeadded[0].drb_ID,
cipher_algo,
NR_SecurityConfig__keyToUse_secondary);
} }
NR_ServingCellConfig_t *scc = ue_context_p->ue_context.spCellConfig ? NR_ServingCellConfig_t *scc = UE->spCellConfig ? UE->spCellConfig->spCellConfigDedicated : NULL;
ue_context_p->ue_context.spCellConfig->spCellConfigDedicated : NULL; fill_default_reconfig(carrier->servingcellconfigcommon, scc, reconfig_ies, UE->secondaryCellGroup, UE->UE_Capability_nr, configuration, ue_context_p->ue_context.gNB_ue_ngap_id);
fill_default_reconfig(carrier->servingcellconfigcommon, // the UE context is not yet inserted in the RRC UE manager
scc, // rrc_gNB_update_ue_context_rnti(UE->secondaryCellGroup->spCellConfig->reconfigurationWithSync->newUE_Identity, rrc,
reconfig_ies, // UE->gNB_ue_ngap_id);
ue_context_p->ue_context.secondaryCellGroup, UE->rnti = UE->secondaryCellGroup->spCellConfig->reconfigurationWithSync->newUE_Identity;
ue_context_p->ue_context.UE_Capability_nr,
configuration,
ue_context_p->local_uid);
ue_context_p->ue_id_rnti = ue_context_p->ue_context.secondaryCellGroup->spCellConfig->reconfigurationWithSync->newUE_Identity;
NR_CG_Config_t *CG_Config = calloc(1,sizeof(*CG_Config)); NR_CG_Config_t *CG_Config = calloc(1,sizeof(*CG_Config));
memset((void *)CG_Config,0,sizeof(*CG_Config)); memset((void *)CG_Config,0,sizeof(*CG_Config));
//int CG_Config_size = generate_CG_Config(rrc,CG_Config,ue_context_p->ue_context.reconfig,ue_context_p->ue_context.rb_config); // int CG_Config_size = generate_CG_Config(rrc,CG_Config,UE->reconfig,UE->rb_config);
generate_CG_Config(rrc,CG_Config,ue_context_p->ue_context.reconfig,ue_context_p->ue_context.rb_config); generate_CG_Config(rrc, CG_Config, UE->reconfig, UE->rb_config);
if(m!=NULL) { if(m!=NULL) {
uint8_t inde_list[m->nb_e_rabs_tobeadded]; uint8_t inde_list[m->nb_e_rabs_tobeadded];
...@@ -269,14 +253,14 @@ void rrc_add_nsa_user(gNB_RRC_INST *rrc,struct rrc_gNB_ue_context_s *ue_context_ ...@@ -269,14 +253,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) { if (m->nb_e_rabs_tobeadded>0) {
for (int i=0; i<m->nb_e_rabs_tobeadded; i++) { 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 // 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->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; UE->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)); memcpy(&UE->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->nb_of_e_rabs++;
//Fill the required E-RAB specific information for the creation of the S1-U tunnel between the gNB and the SGW //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.eps_bearer_id[i] = UE->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; create_tunnel_req.sgw_S1u_teid[i] = UE->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)); memcpy(&create_tunnel_req.sgw_addr[i], &UE->e_rab[i].param.sgw_addr, sizeof(transport_layer_addr_t));
inde_list[i] = i; 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", LOG_I(RRC,"S1-U tunnel: index %d target sgw ip %d.%d.%d.%d length %d gtp teid %u\n",
i, i,
...@@ -288,10 +272,10 @@ void rrc_add_nsa_user(gNB_RRC_INST *rrc,struct rrc_gNB_ue_context_s *ue_context_ ...@@ -288,10 +272,10 @@ void rrc_add_nsa_user(gNB_RRC_INST *rrc,struct rrc_gNB_ue_context_s *ue_context_
create_tunnel_req.sgw_S1u_teid[i]); create_tunnel_req.sgw_S1u_teid[i]);
} }
create_tunnel_req.rnti = ue_context_p->ue_id_rnti; create_tunnel_req.rnti = ue_context_p->ue_context.rnti;
create_tunnel_req.num_tunnels = m->nb_e_rabs_tobeadded; create_tunnel_req.num_tunnels = m->nb_e_rabs_tobeadded;
RB_INSERT(rrc_nr_ue_tree_s, &RC.nrrrc[rrc->module_id]->rrc_ue_head, ue_context_p); RB_INSERT(rrc_nr_ue_tree_s, &RC.nrrrc[rrc->module_id]->rrc_ue_head, ue_context_p);
PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, rrc->module_id, GNB_FLAG_YES, ue_context_p->ue_id_rnti, 0, 0,rrc->module_id); PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, rrc->module_id, GNB_FLAG_YES, ue_context_p->ue_context.rnti, 0, 0, rrc->module_id);
memset(&create_tunnel_resp, 0, sizeof(create_tunnel_resp)); memset(&create_tunnel_resp, 0, sizeof(create_tunnel_resp));
if (!IS_SOFTMODEM_NOS1) { if (!IS_SOFTMODEM_NOS1) {
LOG_D(RRC, "Calling gtpv1u_create_s1u_tunnel()\n"); LOG_D(RRC, "Calling gtpv1u_create_s1u_tunnel()\n");
...@@ -307,8 +291,8 @@ void rrc_add_nsa_user(gNB_RRC_INST *rrc,struct rrc_gNB_ue_context_s *ue_context_ ...@@ -307,8 +291,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).nb_e_rabs_admitted_tobeadded = m->nb_e_rabs_tobeadded;
X2AP_ENDC_SGNB_ADDITION_REQ_ACK(msg).target_assoc_id = m->target_assoc_id; 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++) { for (int i = 0; i < UE->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; X2AP_ENDC_SGNB_ADDITION_REQ_ACK(msg).e_rabs_admitted_tobeadded[i].e_rab_id = UE->e_rab[i].param.e_rab_id;
X2AP_ENDC_SGNB_ADDITION_REQ_ACK(msg).e_rabs_admitted_tobeadded[i].gtp_teid = create_tunnel_resp.enb_S1u_teid[i]; 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)); 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 //The length field in the X2AP targetting structure is expected in bits but the create_tunnel_resp returns the address length in bytes
...@@ -334,7 +318,7 @@ void rrc_add_nsa_user(gNB_RRC_INST *rrc,struct rrc_gNB_ue_context_s *ue_context_ ...@@ -334,7 +318,7 @@ void rrc_add_nsa_user(gNB_RRC_INST *rrc,struct rrc_gNB_ue_context_s *ue_context_
LOG_W(RRC, "No E-RAB to be added received from SgNB Addition Request message \n"); LOG_W(RRC, "No E-RAB to be added received from SgNB Addition Request message \n");
X2AP_ENDC_SGNB_ADDITION_REQ_ACK(msg).MeNB_ue_x2_id = m->ue_x2_id; X2AP_ENDC_SGNB_ADDITION_REQ_ACK(msg).MeNB_ue_x2_id = m->ue_x2_id;
X2AP_ENDC_SGNB_ADDITION_REQ_ACK(msg).SgNB_ue_x2_id = ue_context_p->ue_context.secondaryCellGroup->spCellConfig->reconfigurationWithSync->newUE_Identity; X2AP_ENDC_SGNB_ADDITION_REQ_ACK(msg).SgNB_ue_x2_id = UE->secondaryCellGroup->spCellConfig->reconfigurationWithSync->newUE_Identity;
//X2AP_ENDC_SGNB_ADDITION_REQ_ACK(msg).rrc_buffer_size = CG_Config_size; //Need to verify correct value for the buffer_size //X2AP_ENDC_SGNB_ADDITION_REQ_ACK(msg).rrc_buffer_size = CG_Config_size; //Need to verify correct value for the buffer_size
// Send to X2 entity to transport to MeNB // Send to X2 entity to transport to MeNB
asn_enc_rval_t enc_rval = uper_encode_to_buffer(&asn_DEF_NR_CG_Config, asn_enc_rval_t enc_rval = uper_encode_to_buffer(&asn_DEF_NR_CG_Config,
...@@ -346,18 +330,17 @@ void rrc_add_nsa_user(gNB_RRC_INST *rrc,struct rrc_gNB_ue_context_s *ue_context_ ...@@ -346,18 +330,17 @@ void rrc_add_nsa_user(gNB_RRC_INST *rrc,struct rrc_gNB_ue_context_s *ue_context_
itti_send_msg_to_task(TASK_X2AP, ENB_MODULE_ID_TO_INSTANCE(0), msg); //Check right id instead of hardcoding itti_send_msg_to_task(TASK_X2AP, ENB_MODULE_ID_TO_INSTANCE(0), msg); //Check right id instead of hardcoding
} }
rrc->Nb_ue++;
// configure MAC and RLC // configure MAC and RLC
bool ret = false; bool ret = false;
if (get_softmodem_params()->phy_test) { if (get_softmodem_params()->phy_test) {
// phytest mode: we don't set up RA, etc // phytest mode: we don't set up RA, etc
ret = nr_mac_add_test_ue(RC.nrmac[rrc->module_id], ue_context_p->ue_id_rnti, ue_context_p->ue_context.secondaryCellGroup); ret = nr_mac_add_test_ue(RC.nrmac[rrc->module_id] , ue_context_p->ue_context.rnti, ue_context_p->ue_context.secondaryCellGroup);
} else { } else {
ret = nr_mac_prepare_ra_nsa_ue(RC.nrmac[rrc->module_id], ue_context_p->ue_id_rnti, ue_context_p->ue_context.secondaryCellGroup); ret = nr_mac_prepare_ra_nsa_ue(RC.nrmac[rrc->module_id], ue_context_p->ue_context.rnti, ue_context_p->ue_context.secondaryCellGroup);
} }
AssertFatal(ret, "cannot add NSA UE in MAC, aborting\n"); AssertFatal(ret, "cannot add NSA UE in MAC, aborting\n");
PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, rrc->module_id, GNB_FLAG_YES, ue_context_p->ue_id_rnti, 0, 0, rrc->module_id); PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, rrc->module_id, GNB_FLAG_YES, ue_context_p->ue_context.rnti, 0, 0, rrc->module_id);
if (get_softmodem_params()->do_ra) ctxt.enb_flag = 0; if (get_softmodem_params()->do_ra) ctxt.enb_flag = 0;
LOG_W(RRC, LOG_W(RRC,
"Calling RRC PDCP/RLC ASN1 request functions for protocol context %p with module_id %d, rnti %lx, frame %d, subframe %d eNB_index %d \n", "Calling RRC PDCP/RLC ASN1 request functions for protocol context %p with module_id %d, rnti %lx, frame %d, subframe %d eNB_index %d \n",
...@@ -368,20 +351,11 @@ void rrc_add_nsa_user(gNB_RRC_INST *rrc,struct rrc_gNB_ue_context_s *ue_context_ ...@@ -368,20 +351,11 @@ void rrc_add_nsa_user(gNB_RRC_INST *rrc,struct rrc_gNB_ue_context_s *ue_context_
ctxt.subframe, ctxt.subframe,
ctxt.eNB_index); ctxt.eNB_index);
nr_pdcp_add_drbs(ctxt.enb_flag, nr_pdcp_add_drbs(
ctxt.rntiMaybeUEid, ctxt.enb_flag, ctxt.rntiMaybeUEid, 0, UE->rb_config->drb_ToAddModList, (UE->integrity_algorithm << 4) | UE->ciphering_algorithm, kUPenc, kUPint, UE->secondaryCellGroup->rlc_BearerToAddModList);
0,
ue_context_p->ue_context.rb_config->drb_ToAddModList, nr_rrc_rlc_config_asn1_req(
(ue_context_p->ue_context.integrity_algorithm << 4) | ue_context_p->ue_context.ciphering_algorithm, &ctxt, get_softmodem_params()->sa ? UE->rb_config->srb_ToAddModList : NULL, UE->rb_config->drb_ToAddModList, UE->rb_config->drb_ToReleaseList, UE->secondaryCellGroup->rlc_BearerToAddModList);
kUPenc,
kUPint,
ue_context_p->ue_context.secondaryCellGroup->rlc_BearerToAddModList);
nr_rrc_rlc_config_asn1_req(&ctxt,
get_softmodem_params()->sa ? ue_context_p->ue_context.rb_config->srb_ToAddModList : NULL,
ue_context_p->ue_context.rb_config->drb_ToAddModList,
ue_context_p->ue_context.rb_config->drb_ToReleaseList,
ue_context_p->ue_context.secondaryCellGroup->rlc_BearerToAddModList);
LOG_D(RRC, "%s:%d: done RRC PDCP/RLC ASN1 request for UE rnti %lx\n", __FUNCTION__, __LINE__, ctxt.rntiMaybeUEid); LOG_D(RRC, "%s:%d: done RRC PDCP/RLC ASN1 request for UE rnti %lx\n", __FUNCTION__, __LINE__, ctxt.rntiMaybeUEid);
} }
...@@ -394,7 +368,7 @@ void rrc_remove_nsa_user(gNB_RRC_INST *rrc, int rnti) { ...@@ -394,7 +368,7 @@ void rrc_remove_nsa_user(gNB_RRC_INST *rrc, int rnti) {
LOG_D(RRC, "calling rrc_remove_nsa_user rnti %d\n", rnti); LOG_D(RRC, "calling rrc_remove_nsa_user rnti %d\n", rnti);
PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, rrc->module_id, GNB_FLAG_YES, rnti, 0, 0, rrc->module_id); PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, rrc->module_id, GNB_FLAG_YES, rnti, 0, 0, rrc->module_id);
ue_context = rrc_gNB_get_ue_context(rrc, rnti); ue_context = rrc_gNB_get_ue_context_by_rnti(rrc, rnti);
if (ue_context == NULL) { if (ue_context == NULL) {
LOG_W(RRC, "rrc_remove_nsa_user: rnti %d not found\n", rnti); LOG_W(RRC, "rrc_remove_nsa_user: rnti %d not found\n", rnti);
return; return;
...@@ -419,5 +393,5 @@ void rrc_remove_nsa_user(gNB_RRC_INST *rrc, int rnti) { ...@@ -419,5 +393,5 @@ void rrc_remove_nsa_user(gNB_RRC_INST *rrc, int rnti) {
} }
gtpv1u_delete_s1u_tunnel(rrc->module_id, &tmp); gtpv1u_delete_s1u_tunnel(rrc->module_id, &tmp);
/* remove context */ /* remove context */
rrc_gNB_remove_ue_context(&ctxt, rrc, ue_context); rrc_gNB_remove_ue_context(rrc, ue_context);
} }
...@@ -22,19 +22,30 @@ ...@@ -22,19 +22,30 @@
#include "rrc_gNB_radio_bearers.h" #include "rrc_gNB_radio_bearers.h"
#include "oai_asn1.h" #include "oai_asn1.h"
NR_DRB_ToAddMod_t *generateDRB(gNB_RRC_UE_t *ue, uint8_t drb_id, pdu_session_param_t *pduSession, bool enable_sdap, int do_drb_integrity, int do_drb_ciphering) rrc_pdu_session_param_t *find_pduSession(gNB_RRC_UE_t *ue, int id, bool create)
{ {
NR_DRB_ToAddMod_t *DRB_config = NULL; int j;
NR_SDAP_Config_t *SDAP_config = NULL; for (j = 0; j < ue->nb_of_pdusessions; j++)
if (id == ue->pduSession[j].param.pdusession_id)
break;
if (j == ue->nb_of_pdusessions && create)
ue->nb_of_pdusessions++;
else
return NULL;
AssertFatal(ue->nb_of_pdusessions < NGAP_MAX_PDU_SESSION, "");
return ue->pduSession + j;
}
DRB_config = CALLOC(1, sizeof(*DRB_config)); NR_DRB_ToAddMod_t *generateDRB(gNB_RRC_UE_t *ue, uint8_t drb_id, rrc_pdu_session_param_t *pduSession, bool enable_sdap, int do_drb_integrity, int do_drb_ciphering)
{
NR_DRB_ToAddMod_t *DRB_config = CALLOC(1, sizeof(*DRB_config));
DRB_config->drb_Identity = drb_id; DRB_config->drb_Identity = drb_id;
DRB_config->cnAssociation = CALLOC(1, sizeof(*DRB_config->cnAssociation)); asn1cCalloc(DRB_config->cnAssociation, association);
DRB_config->cnAssociation->present = NR_DRB_ToAddMod__cnAssociation_PR_sdap_Config; association->present = NR_DRB_ToAddMod__cnAssociation_PR_sdap_Config;
/* SDAP Configuration */ /* SDAP Configuration */
SDAP_config = CALLOC(1, sizeof(NR_SDAP_Config_t)); NR_SDAP_Config_t *SDAP_config = CALLOC(1, sizeof(NR_SDAP_Config_t));
SDAP_config->mappedQoS_FlowsToAdd = calloc(1, sizeof(struct NR_SDAP_Config__mappedQoS_FlowsToAdd)); asn1cCalloc(SDAP_config->mappedQoS_FlowsToAdd, sdapFlows);
SDAP_config->pdu_Session = pduSession->param.pdusession_id; SDAP_config->pdu_Session = pduSession->param.pdusession_id;
...@@ -50,53 +61,36 @@ NR_DRB_ToAddMod_t *generateDRB(gNB_RRC_UE_t *ue, uint8_t drb_id, pdu_session_par ...@@ -50,53 +61,36 @@ NR_DRB_ToAddMod_t *generateDRB(gNB_RRC_UE_t *ue, uint8_t drb_id, pdu_session_par
for (int qos_flow_index = 0; qos_flow_index < pduSession->param.nb_qos; qos_flow_index++) for (int qos_flow_index = 0; qos_flow_index < pduSession->param.nb_qos; qos_flow_index++)
{ {
NR_QFI_t *qfi = calloc(1, sizeof(NR_QFI_t)); asn1cSequenceAdd(sdapFlows->list, NR_QFI_t, qfi);
*qfi = pduSession->param.qos[qos_flow_index].qfi; *qfi = pduSession->param.qos[qos_flow_index].qfi;
asn1cSeqAdd(&SDAP_config->mappedQoS_FlowsToAdd->list, qfi);
if(pduSession->param.qos[qos_flow_index].fiveQI > 5) if(pduSession->param.qos[qos_flow_index].fiveQI > 5)
pduSession->param.used_drbs[drb_id - 1] = DRB_ACTIVE_NONGBR; pduSession->param.used_drbs[drb_id - 1] = DRB_ACTIVE_NONGBR;
else else
pduSession->param.used_drbs[drb_id - 1] = DRB_ACTIVE; pduSession->param.used_drbs[drb_id - 1] = DRB_ACTIVE;
} }
SDAP_config->mappedQoS_FlowsToRelease = NULL; association->choice.sdap_Config = SDAP_config;
DRB_config->cnAssociation->choice.sdap_Config = SDAP_config;
/* PDCP Configuration */ /* PDCP Configuration */
DRB_config->reestablishPDCP = NULL; asn1cCalloc(DRB_config->pdcp_Config, pdcpConfig);
DRB_config->recoverPDCP = NULL; asn1cCalloc(pdcpConfig->drb, drb);
DRB_config->pdcp_Config = calloc(1, sizeof(*DRB_config->pdcp_Config));
DRB_config->pdcp_Config->drb = calloc(1,sizeof(*DRB_config->pdcp_Config->drb)); asn1cCallocOne(drb->discardTimer, NR_PDCP_Config__drb__discardTimer_infinity);
DRB_config->pdcp_Config->drb->discardTimer = calloc(1, sizeof(*DRB_config->pdcp_Config->drb->discardTimer)); asn1cCallocOne(drb->pdcp_SN_SizeUL, NR_PDCP_Config__drb__pdcp_SN_SizeUL_len18bits);
*DRB_config->pdcp_Config->drb->discardTimer = NR_PDCP_Config__drb__discardTimer_infinity; asn1cCallocOne(drb->pdcp_SN_SizeDL, NR_PDCP_Config__drb__pdcp_SN_SizeDL_len18bits);
DRB_config->pdcp_Config->drb->pdcp_SN_SizeUL = calloc(1, sizeof(*DRB_config->pdcp_Config->drb->pdcp_SN_SizeUL));
*DRB_config->pdcp_Config->drb->pdcp_SN_SizeUL = NR_PDCP_Config__drb__pdcp_SN_SizeUL_len18bits; drb->headerCompression.present = NR_PDCP_Config__drb__headerCompression_PR_notUsed;
DRB_config->pdcp_Config->drb->pdcp_SN_SizeDL = calloc(1, sizeof(*DRB_config->pdcp_Config->drb->pdcp_SN_SizeDL)); drb->headerCompression.choice.notUsed = 0;
*DRB_config->pdcp_Config->drb->pdcp_SN_SizeDL = NR_PDCP_Config__drb__pdcp_SN_SizeDL_len18bits;
asn1cCallocOne(pdcpConfig->t_Reordering, NR_PDCP_Config__t_Reordering_ms100);
DRB_config->pdcp_Config->drb->headerCompression.present = NR_PDCP_Config__drb__headerCompression_PR_notUsed;
DRB_config->pdcp_Config->drb->headerCompression.choice.notUsed = 0;
DRB_config->pdcp_Config->drb->integrityProtection = NULL;
DRB_config->pdcp_Config->drb->statusReportRequired = NULL;
DRB_config->pdcp_Config->drb->outOfOrderDelivery = NULL;
DRB_config->pdcp_Config->moreThanOneRLC = NULL;
DRB_config->pdcp_Config->t_Reordering = calloc(1, sizeof(*DRB_config->pdcp_Config->t_Reordering));
*DRB_config->pdcp_Config->t_Reordering = NR_PDCP_Config__t_Reordering_ms100;
DRB_config->pdcp_Config->ext1 = NULL;
if (do_drb_integrity) { if (do_drb_integrity) {
DRB_config->pdcp_Config->drb->integrityProtection = calloc(1, sizeof(*DRB_config->pdcp_Config->drb->integrityProtection)); asn1cCallocOne(drb->integrityProtection, NR_PDCP_Config__drb__integrityProtection_enabled);
*DRB_config->pdcp_Config->drb->integrityProtection = NR_PDCP_Config__drb__integrityProtection_enabled;
} }
if (!do_drb_ciphering) { if (!do_drb_ciphering) {
DRB_config->pdcp_Config->ext1 = calloc(1, sizeof(*DRB_config->pdcp_Config->ext1)); asn1cCalloc(pdcpConfig->ext1, ext1);
DRB_config->pdcp_Config->ext1->cipheringDisabled = calloc(1, sizeof(*DRB_config->pdcp_Config->ext1->cipheringDisabled)); asn1cCallocOne(ext1->cipheringDisabled, NR_PDCP_Config__ext1__cipheringDisabled_true);
*DRB_config->pdcp_Config->ext1->cipheringDisabled = NR_PDCP_Config__ext1__cipheringDisabled_true;
} }
ue->DRB_active[drb_id-1] = DRB_ACTIVE; ue->DRB_active[drb_id-1] = DRB_ACTIVE;
...@@ -104,7 +98,7 @@ NR_DRB_ToAddMod_t *generateDRB(gNB_RRC_UE_t *ue, uint8_t drb_id, pdu_session_par ...@@ -104,7 +98,7 @@ NR_DRB_ToAddMod_t *generateDRB(gNB_RRC_UE_t *ue, uint8_t drb_id, pdu_session_par
return DRB_config; return DRB_config;
} }
uint8_t next_available_drb(gNB_RRC_UE_t *ue, pdu_session_param_t *pdusession, bool is_gbr) uint8_t next_available_drb(gNB_RRC_UE_t *ue, rrc_pdu_session_param_t *pdusession, bool is_gbr)
{ {
uint8_t drb_id; uint8_t drb_id;
......
...@@ -35,10 +35,10 @@ ...@@ -35,10 +35,10 @@
#define GBR_FLOW (1) #define GBR_FLOW (1)
#define NONGBR_FLOW (0) #define NONGBR_FLOW (0)
NR_DRB_ToAddMod_t *generateDRB(gNB_RRC_UE_t *rrc_ue, uint8_t drb_id, pdu_session_param_t *pduSession, bool enable_sdap, int do_drb_integrity, int do_drb_ciphering); NR_DRB_ToAddMod_t *generateDRB(gNB_RRC_UE_t *rrc_ue, uint8_t drb_id, rrc_pdu_session_param_t *pduSession, bool enable_sdap, int do_drb_integrity, int do_drb_ciphering);
uint8_t next_available_drb(gNB_RRC_UE_t *ue, rrc_pdu_session_param_t *pdusession, bool is_gbr);
uint8_t next_available_drb(gNB_RRC_UE_t *ue, pdu_session_param_t *pdusession, bool is_gbr);
bool drb_is_active(gNB_RRC_UE_t *ue, uint8_t drb_id); bool drb_is_active(gNB_RRC_UE_t *ue, uint8_t drb_id);
rrc_pdu_session_param_t *find_pduSession(gNB_RRC_UE_t *ue, int id, bool create);
#endif #endif
...@@ -435,15 +435,10 @@ nr_sdap_entity_t *new_nr_sdap_entity(int is_gnb, bool has_sdap_rx, bool has_sdap ...@@ -435,15 +435,10 @@ nr_sdap_entity_t *new_nr_sdap_entity(int is_gnb, bool has_sdap_rx, bool has_sdap
if(is_defaultDRB) { if(is_defaultDRB) {
sdap_entity->default_drb = drb_identity; sdap_entity->default_drb = drb_identity;
LOG_I(SDAP, "Default DRB for the created SDAP entity: %ld \n", sdap_entity->default_drb); LOG_I(SDAP, "Default DRB for the created SDAP entity: %ld \n", sdap_entity->default_drb);
LOG_D(SDAP, "RRC updating mapping rules: %d\n", mappedQFIs2AddCount);
if(mappedQFIs2AddCount) {
LOG_D(SDAP, "RRC updating mapping rules\n");
for (int i = 0; i < mappedQFIs2AddCount; i++) for (int i = 0; i < mappedQFIs2AddCount; i++)
{
sdap_entity->qfi2drb_map_update(sdap_entity, mapped_qfi_2_add[i], sdap_entity->default_drb, has_sdap_rx, has_sdap_tx); sdap_entity->qfi2drb_map_update(sdap_entity, mapped_qfi_2_add[i], sdap_entity->default_drb, has_sdap_rx, has_sdap_tx);
} }
}
}
sdap_entity->next_entity = sdap_info.sdap_entity_llist; sdap_entity->next_entity = sdap_info.sdap_entity_llist;
sdap_info.sdap_entity_llist = sdap_entity; sdap_info.sdap_entity_llist = sdap_entity;
......
...@@ -859,6 +859,7 @@ void *nas_nrue_task(void *args_p) ...@@ -859,6 +859,7 @@ void *nas_nrue_task(void *args_p)
instance = msg_p->ittiMsgHeader.originInstance; instance = msg_p->ittiMsgHeader.originInstance;
Mod_id = instance ; Mod_id = instance ;
uicc_t *uicc=checkUicc(Mod_id); uicc_t *uicc=checkUicc(Mod_id);
LOG_I(NAS, "[UE %d] Received %s\n", Mod_id, ITTI_MSG_NAME(msg_p));
if (instance == INSTANCE_DEFAULT) { if (instance == INSTANCE_DEFAULT) {
printf("%s:%d: FATAL: instance is INSTANCE_DEFAULT, should not happen.\n", printf("%s:%d: FATAL: instance is INSTANCE_DEFAULT, should not happen.\n",
...@@ -868,21 +869,24 @@ void *nas_nrue_task(void *args_p) ...@@ -868,21 +869,24 @@ void *nas_nrue_task(void *args_p)
switch (ITTI_MSG_ID(msg_p)) { switch (ITTI_MSG_ID(msg_p)) {
case INITIALIZE_MESSAGE: case INITIALIZE_MESSAGE:
LOG_I(NAS, "[UE %d] Received %s\n", Mod_id, ITTI_MSG_NAME (msg_p));
break; break;
case TERMINATE_MESSAGE: case TERMINATE_MESSAGE:
itti_exit_task (); itti_exit_task();
break; break;
case MESSAGE_TEST: case MESSAGE_TEST:
LOG_I(NAS, "[UE %d] Received %s\n", Mod_id, ITTI_MSG_NAME (msg_p));
break; break;
case NAS_CELL_SELECTION_CNF: case NAS_CELL_SELECTION_CNF:
LOG_I(NAS, "[UE %d] Received %s: errCode %u, cellID %u, tac %u\n", Mod_id, ITTI_MSG_NAME (msg_p), LOG_I(NAS,
NAS_CELL_SELECTION_CNF (msg_p).errCode, NAS_CELL_SELECTION_CNF (msg_p).cellID, NAS_CELL_SELECTION_CNF (msg_p).tac); "[UE %d] Received %s: errCode %u, cellID %u, tac %u\n",
Mod_id,
ITTI_MSG_NAME(msg_p),
NAS_CELL_SELECTION_CNF(msg_p).errCode,
NAS_CELL_SELECTION_CNF(msg_p).cellID,
NAS_CELL_SELECTION_CNF(msg_p).tac);
// as_stmsi_t s_tmsi={0, 0}; // as_stmsi_t s_tmsi={0, 0};
// as_nas_info_t nas_info; // as_nas_info_t nas_info;
// plmn_t plmnID={0, 0, 0, 0}; // plmn_t plmnID={0, 0, 0, 0};
...@@ -891,34 +895,30 @@ void *nas_nrue_task(void *args_p) ...@@ -891,34 +895,30 @@ void *nas_nrue_task(void *args_p)
break; break;
case NAS_CELL_SELECTION_IND: case NAS_CELL_SELECTION_IND:
LOG_I(NAS, "[UE %d] Received %s: cellID %u, tac %u\n", Mod_id, ITTI_MSG_NAME (msg_p), LOG_I(NAS, "[UE %d] Received %s: cellID %u, tac %u\n", Mod_id, ITTI_MSG_NAME(msg_p), NAS_CELL_SELECTION_IND(msg_p).cellID, NAS_CELL_SELECTION_IND(msg_p).tac);
NAS_CELL_SELECTION_IND (msg_p).cellID, NAS_CELL_SELECTION_IND (msg_p).tac);
/* TODO not processed by NAS currently */ /* TODO not processed by NAS currently */
break; break;
case NAS_PAGING_IND: case NAS_PAGING_IND:
LOG_I(NAS, "[UE %d] Received %s: cause %u\n", Mod_id, ITTI_MSG_NAME (msg_p), LOG_I(NAS, "[UE %d] Received %s: cause %u\n", Mod_id, ITTI_MSG_NAME(msg_p), NAS_PAGING_IND(msg_p).cause);
NAS_PAGING_IND (msg_p).cause);
/* TODO not processed by NAS currently */ /* TODO not processed by NAS currently */
break; break;
case NAS_CONN_ESTABLI_CNF: case NAS_CONN_ESTABLI_CNF: {
{ LOG_I(NAS, "[UE %d] Received %s: errCode %u, length %u\n", Mod_id, ITTI_MSG_NAME(msg_p), NAS_CONN_ESTABLI_CNF(msg_p).errCode, NAS_CONN_ESTABLI_CNF(msg_p).nasMsg.length);
LOG_I(NAS, "[UE %d] Received %s: errCode %u, length %u\n", Mod_id, ITTI_MSG_NAME (msg_p),
NAS_CONN_ESTABLI_CNF (msg_p).errCode, NAS_CONN_ESTABLI_CNF (msg_p).nasMsg.length);
pdu_buffer = NAS_CONN_ESTABLI_CNF (msg_p).nasMsg.data; pdu_buffer = NAS_CONN_ESTABLI_CNF(msg_p).nasMsg.data;
msg_type = get_msg_type(pdu_buffer, NAS_CONN_ESTABLI_CNF (msg_p).nasMsg.length); msg_type = get_msg_type(pdu_buffer, NAS_CONN_ESTABLI_CNF(msg_p).nasMsg.length);
if(msg_type == REGISTRATION_ACCEPT){ if (msg_type == REGISTRATION_ACCEPT) {
LOG_I(NAS, "[UE] Received REGISTRATION ACCEPT message\n"); LOG_I(NAS, "[UE] Received REGISTRATION ACCEPT message\n");
as_nas_info_t initialNasMsg; as_nas_info_t initialNasMsg;
memset(&initialNasMsg, 0, sizeof(as_nas_info_t)); memset(&initialNasMsg, 0, sizeof(as_nas_info_t));
generateRegistrationComplete(Mod_id,&initialNasMsg, NULL); generateRegistrationComplete(Mod_id, &initialNasMsg, NULL);
if(initialNasMsg.length > 0){ if (initialNasMsg.length > 0) {
MessageDef *message_p; MessageDef *message_p;
message_p = itti_alloc_new_message(TASK_NAS_NRUE, 0, NAS_UPLINK_DATA_REQ); message_p = itti_alloc_new_message(TASK_NAS_NRUE, 0, NAS_UPLINK_DATA_REQ);
NAS_UPLINK_DATA_REQ(message_p).UEid = Mod_id; NAS_UPLINK_DATA_REQ(message_p).UEid = Mod_id;
...@@ -931,7 +931,7 @@ void *nas_nrue_task(void *args_p) ...@@ -931,7 +931,7 @@ void *nas_nrue_task(void *args_p)
as_nas_info_t pduEstablishMsg; as_nas_info_t pduEstablishMsg;
memset(&pduEstablishMsg, 0, sizeof(as_nas_info_t)); memset(&pduEstablishMsg, 0, sizeof(as_nas_info_t));
generatePduSessionEstablishRequest(Mod_id, uicc, &pduEstablishMsg); generatePduSessionEstablishRequest(Mod_id, uicc, &pduEstablishMsg);
if(pduEstablishMsg.length > 0){ if (pduEstablishMsg.length > 0) {
MessageDef *message_p; MessageDef *message_p;
message_p = itti_alloc_new_message(TASK_NAS_NRUE, 0, NAS_UPLINK_DATA_REQ); message_p = itti_alloc_new_message(TASK_NAS_NRUE, 0, NAS_UPLINK_DATA_REQ);
NAS_UPLINK_DATA_REQ(message_p).UEid = Mod_id; NAS_UPLINK_DATA_REQ(message_p).UEid = Mod_id;
...@@ -940,8 +940,8 @@ void *nas_nrue_task(void *args_p) ...@@ -940,8 +940,8 @@ void *nas_nrue_task(void *args_p)
itti_send_msg_to_task(TASK_RRC_NRUE, instance, message_p); itti_send_msg_to_task(TASK_RRC_NRUE, instance, message_p);
LOG_I(NAS, "Send NAS_UPLINK_DATA_REQ message(PduSessionEstablishRequest)\n"); LOG_I(NAS, "Send NAS_UPLINK_DATA_REQ message(PduSessionEstablishRequest)\n");
} }
} else if(msg_type == FGS_PDU_SESSION_ESTABLISHMENT_ACC){ } else if (msg_type == FGS_PDU_SESSION_ESTABLISHMENT_ACC) {
capture_pdu_session_establishment_accept_msg(pdu_buffer, NAS_CONN_ESTABLI_CNF (msg_p).nasMsg.length); capture_pdu_session_establishment_accept_msg(pdu_buffer, NAS_CONN_ESTABLI_CNF(msg_p).nasMsg.length);
} }
break; break;
......
...@@ -113,27 +113,27 @@ extern int asn1_xer_print; ...@@ -113,27 +113,27 @@ extern int asn1_xer_print;
# define NGAP_DEBUG(x, args...) do { fprintf(stdout, "[NGAP][D]"x, ##args); } while(0) # define NGAP_DEBUG(x, args...) do { fprintf(stdout, "[NGAP][D]"x, ##args); } while(0)
#endif #endif
#define NGAP_FIND_PROTOCOLIE_BY_ID(IE_TYPE, ie, container, IE_ID, mandatory) \ #define NGAP_FIND_PROTOCOLIE_BY_ID(IE_TYPE, ie, container, IE_ID, mandatory) \
do {\ do { \
IE_TYPE **ptr; \ IE_TYPE **ptr; \
ie = NULL; \ ie = NULL; \
for (ptr = container->protocolIEs.list.array; \ for (ptr = container->protocolIEs.list.array; ptr < &container->protocolIEs.list.array[container->protocolIEs.list.count]; ptr++) { \
ptr < &container->protocolIEs.list.array[container->protocolIEs.list.count]; \ if ((*ptr)->id == IE_ID) { \
ptr++) { \
if((*ptr)->id == IE_ID) { \
ie = *ptr; \ ie = *ptr; \
break; \ break; \
} \ } \
} \ } \
if (ie == NULL ) { \ if (ie == NULL) { \
if (mandatory) {\ if (mandatory) { \
NGAP_ERROR("NGAP_FIND_PROTOCOLIE_BY_ID: %s %d: ie is NULL (searching for ie: %ld)\n",__FILE__,__LINE__, IE_ID);\ AssertFatal(NGAP, "NGAP_FIND_PROTOCOLIE_BY_ID ie is NULL (searching for ie: %ld)\n", IE_ID); \
abort();\ } else { \
}\ NGAP_INFO("NGAP_FIND_PROTOCOLIE_BY_ID ie is NULL (searching for ie: %ld)\n", IE_ID); \
else NGAP_INFO("NGAP_FIND_PROTOCOLIE_BY_ID: %s %d: ie is NULL (searching for ie: %ld)\n",__FILE__,__LINE__, IE_ID);\ } \
} \ } \
} while(0) } while (0); \
if (mandatory && !ie) \
return -1
/** \brief Function callback prototype. /** \brief Function callback prototype.
**/ **/
typedef int (*ngap_message_decoded_callback)( typedef int (*ngap_message_decoded_callback)(
......
...@@ -162,7 +162,6 @@ void ngap_gNB_handle_register_gNB(instance_t instance, ngap_register_gnb_req_t * ...@@ -162,7 +162,6 @@ void ngap_gNB_handle_register_gNB(instance_t instance, ngap_register_gnb_req_t *
} else { } else {
new_instance = calloc(1, sizeof(ngap_gNB_instance_t)); new_instance = calloc(1, sizeof(ngap_gNB_instance_t));
DevAssert(new_instance != NULL); DevAssert(new_instance != NULL);
RB_INIT(&new_instance->ngap_ue_head);
RB_INIT(&new_instance->ngap_amf_head); RB_INIT(&new_instance->ngap_amf_head);
/* Copy usefull parameters */ /* Copy usefull parameters */
new_instance->instance = instance; new_instance->instance = instance;
...@@ -276,127 +275,88 @@ void *ngap_gNB_process_itti_msg(void *notUsed) { ...@@ -276,127 +275,88 @@ void *ngap_gNB_process_itti_msg(void *notUsed) {
MessageDef *received_msg = NULL; MessageDef *received_msg = NULL;
int result; int result;
itti_receive_msg(TASK_NGAP, &received_msg); itti_receive_msg(TASK_NGAP, &received_msg);
if (received_msg) {
instance_t instance = ITTI_MSG_DESTINATION_INSTANCE(received_msg);
LOG_D(RRC, "Received message %s\n", ITTI_MSG_NAME(received_msg));
switch (ITTI_MSG_ID(received_msg)) { switch (ITTI_MSG_ID(received_msg)) {
case TERMINATE_MESSAGE: case TERMINATE_MESSAGE:
NGAP_WARN(" *** Exiting NGAP thread\n"); NGAP_WARN(" *** Exiting NGAP thread\n");
itti_exit_task(); itti_exit_task();
break; break;
case NGAP_REGISTER_GNB_REQ: { case NGAP_REGISTER_GNB_REQ:
/* Register a new gNB. /* Register a new gNB.
* in Virtual mode gNBs will be distinguished using the mod_id/ * in Virtual mode gNBs will be distinguished using the mod_id/
* Each gNB has to send an NGAP_REGISTER_GNB message with its * Each gNB has to send an NGAP_REGISTER_GNB message with its
* own parameters. * own parameters.
*/ */
ngap_gNB_handle_register_gNB(ITTI_MSG_DESTINATION_INSTANCE(received_msg), ngap_gNB_handle_register_gNB(instance, &NGAP_REGISTER_GNB_REQ(received_msg));
&NGAP_REGISTER_GNB_REQ(received_msg));
}
break; break;
case SCTP_NEW_ASSOCIATION_RESP: { case SCTP_NEW_ASSOCIATION_RESP:
ngap_gNB_handle_sctp_association_resp(ITTI_MSG_DESTINATION_INSTANCE(received_msg), ngap_gNB_handle_sctp_association_resp(instance, &received_msg->ittiMsg.sctp_new_association_resp);
&received_msg->ittiMsg.sctp_new_association_resp);
}
break; break;
case SCTP_DATA_IND: { case SCTP_DATA_IND:
ngap_gNB_handle_sctp_data_ind(&received_msg->ittiMsg.sctp_data_ind); ngap_gNB_handle_sctp_data_ind(&received_msg->ittiMsg.sctp_data_ind);
}
break; break;
case NGAP_NAS_FIRST_REQ: { case NGAP_NAS_FIRST_REQ:
ngap_gNB_handle_nas_first_req(ITTI_MSG_DESTINATION_INSTANCE(received_msg), ngap_gNB_handle_nas_first_req(instance, &NGAP_NAS_FIRST_REQ(received_msg));
&NGAP_NAS_FIRST_REQ(received_msg));
}
break; break;
case NGAP_UPLINK_NAS: { case NGAP_UPLINK_NAS:
ngap_gNB_nas_uplink(ITTI_MSG_DESTINATION_INSTANCE(received_msg), ngap_gNB_nas_uplink(instance, &NGAP_UPLINK_NAS(received_msg));
&NGAP_UPLINK_NAS(received_msg));
}
break; break;
case NGAP_UE_CAPABILITIES_IND: { case NGAP_UE_CAPABILITIES_IND:
ngap_gNB_ue_capabilities(ITTI_MSG_DESTINATION_INSTANCE(received_msg), ngap_gNB_ue_capabilities(instance, &NGAP_UE_CAPABILITIES_IND(received_msg));
&NGAP_UE_CAPABILITIES_IND(received_msg));
}
break; break;
case NGAP_INITIAL_CONTEXT_SETUP_RESP: { case NGAP_INITIAL_CONTEXT_SETUP_RESP:
ngap_gNB_initial_ctxt_resp(ITTI_MSG_DESTINATION_INSTANCE(received_msg), ngap_gNB_initial_ctxt_resp(instance, &NGAP_INITIAL_CONTEXT_SETUP_RESP(received_msg));
&NGAP_INITIAL_CONTEXT_SETUP_RESP(received_msg));
}
break; break;
case NGAP_PDUSESSION_SETUP_RESP: { case NGAP_PDUSESSION_SETUP_RESP:
ngap_gNB_pdusession_setup_resp(ITTI_MSG_DESTINATION_INSTANCE(received_msg), ngap_gNB_pdusession_setup_resp(instance, &NGAP_PDUSESSION_SETUP_RESP(received_msg));
&NGAP_PDUSESSION_SETUP_RESP(received_msg));
}
break; break;
case NGAP_PDUSESSION_MODIFY_RESP: { case NGAP_PDUSESSION_MODIFY_RESP:
ngap_gNB_pdusession_modify_resp(ITTI_MSG_DESTINATION_INSTANCE(received_msg), ngap_gNB_pdusession_modify_resp(instance, &NGAP_PDUSESSION_MODIFY_RESP(received_msg));
&NGAP_PDUSESSION_MODIFY_RESP(received_msg));
}
break; break;
case NGAP_NAS_NON_DELIVERY_IND: { case NGAP_NAS_NON_DELIVERY_IND:
ngap_gNB_nas_non_delivery_ind(ITTI_MSG_DESTINATION_INSTANCE(received_msg), ngap_gNB_nas_non_delivery_ind(instance, &NGAP_NAS_NON_DELIVERY_IND(received_msg));
&NGAP_NAS_NON_DELIVERY_IND(received_msg));
}
break; break;
case NGAP_PATH_SWITCH_REQ: { case NGAP_PATH_SWITCH_REQ:
ngap_gNB_path_switch_req(ITTI_MSG_DESTINATION_INSTANCE(received_msg), ngap_gNB_path_switch_req(instance, &NGAP_PATH_SWITCH_REQ(received_msg));
&NGAP_PATH_SWITCH_REQ(received_msg));
}
break; break;
case NGAP_PDUSESSION_MODIFICATION_IND: { case NGAP_PDUSESSION_MODIFICATION_IND:
ngap_gNB_generate_PDUSESSION_Modification_Indication(ITTI_MSG_DESTINATION_INSTANCE(received_msg), ngap_gNB_generate_PDUSESSION_Modification_Indication(instance, &NGAP_PDUSESSION_MODIFICATION_IND(received_msg));
&NGAP_PDUSESSION_MODIFICATION_IND(received_msg));
}
break; break;
case NGAP_UE_CONTEXT_RELEASE_COMPLETE: { case NGAP_UE_CONTEXT_RELEASE_COMPLETE:
ngap_ue_context_release_complete(ITTI_MSG_DESTINATION_INSTANCE(received_msg), ngap_ue_context_release_complete(instance, &NGAP_UE_CONTEXT_RELEASE_COMPLETE(received_msg));
&NGAP_UE_CONTEXT_RELEASE_COMPLETE(received_msg));
}
break; break;
case NGAP_UE_CONTEXT_RELEASE_REQ: { case NGAP_UE_CONTEXT_RELEASE_REQ:
ngap_gNB_instance_t *ngap_gNB_instance_p = NULL; // test ngap_ue_context_release_req(instance, &NGAP_UE_CONTEXT_RELEASE_REQ(received_msg));
struct ngap_gNB_ue_context_s *ue_context_p = NULL; // test
ngap_ue_context_release_req(ITTI_MSG_DESTINATION_INSTANCE(received_msg),
&NGAP_UE_CONTEXT_RELEASE_REQ(received_msg));
ngap_gNB_instance_p = ngap_gNB_get_instance(ITTI_MSG_DESTINATION_INSTANCE(received_msg)); // test
DevAssert(ngap_gNB_instance_p != NULL); // test
if ((ue_context_p = ngap_gNB_get_ue_context(ngap_gNB_instance_p,
NGAP_UE_CONTEXT_RELEASE_REQ(received_msg).gNB_ue_ngap_id)) == NULL) { // test
/* The context for this gNB ue ngap id doesn't exist in the map of gNB UEs */
NGAP_ERROR("Failed to find ue context associated with gNB ue ngap id: %u\n",
NGAP_UE_CONTEXT_RELEASE_REQ(received_msg).gNB_ue_ngap_id); // test
} // test
}
break; break;
case NGAP_PDUSESSION_RELEASE_RESPONSE: { case NGAP_PDUSESSION_RELEASE_RESPONSE:
ngap_gNB_pdusession_release_resp(ITTI_MSG_DESTINATION_INSTANCE(received_msg), ngap_gNB_pdusession_release_resp(instance, &NGAP_PDUSESSION_RELEASE_RESPONSE(received_msg));
&NGAP_PDUSESSION_RELEASE_RESPONSE(received_msg));
}
break; break;
default: default:
NGAP_ERROR("Received unhandled message: %d:%s\n", NGAP_ERROR("Received unhandled message: %d:%s\n", ITTI_MSG_ID(received_msg), ITTI_MSG_NAME(received_msg));
ITTI_MSG_ID(received_msg), ITTI_MSG_NAME(received_msg));
break; break;
} }
result = itti_free (ITTI_MSG_ORIGIN_ID(received_msg), received_msg); result = itti_free(ITTI_MSG_ORIGIN_ID(received_msg), received_msg);
AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result); AssertFatal(result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
received_msg = NULL; }
return NULL; return NULL;
} }
......
...@@ -58,9 +58,7 @@ int ngap_ue_context_release_complete(instance_t instance, ...@@ -58,9 +58,7 @@ int ngap_ue_context_release_complete(instance_t instance,
ngap_gNB_instance_t *ngap_gNB_instance_p = NULL; ngap_gNB_instance_t *ngap_gNB_instance_p = NULL;
struct ngap_gNB_ue_context_s *ue_context_p = NULL; struct ngap_gNB_ue_context_s *ue_context_p = NULL;
NGAP_NGAP_PDU_t pdu; NGAP_NGAP_PDU_t pdu = {0};
NGAP_UEContextReleaseComplete_t *out;
NGAP_UEContextReleaseComplete_IEs_t *ie;
uint8_t *buffer; uint8_t *buffer;
uint32_t length; uint32_t length;
...@@ -70,44 +68,37 @@ int ngap_ue_context_release_complete(instance_t instance, ...@@ -70,44 +68,37 @@ int ngap_ue_context_release_complete(instance_t instance,
DevAssert(ue_release_complete_p != NULL); DevAssert(ue_release_complete_p != NULL);
DevAssert(ngap_gNB_instance_p != NULL); DevAssert(ngap_gNB_instance_p != NULL);
/*RB_FOREACH(ue_context_p, ngap_ue_map, &ngap_gNB_instance_p->ngap_ue_head) { if ((ue_context_p = ngap_get_ue_context(ue_release_complete_p->gNB_ue_ngap_id)) == NULL) {
NGAP_WARN("in ngap_ue_map: UE context gNB_ue_ngap_id %u amf_ue_ngap_id %u state %u\n",
ue_context_p->gNB_ue_ngap_id, ue_context_p->amf_ue_ngap_id,
ue_context_p->ue_state);
}*/
if ((ue_context_p = ngap_gNB_get_ue_context(ngap_gNB_instance_p,
ue_release_complete_p->gNB_ue_ngap_id)) == NULL) {
/* The context for this gNB ue ngap id doesn't exist in the map of gNB UEs */ /* The context for this gNB ue ngap id doesn't exist in the map of gNB UEs */
NGAP_WARN("Failed to find ue context associated with gNB ue ngap id: %u\n", NGAP_ERROR("Failed to find ue context associated with gNB ue ngap id: %u\n", ue_release_complete_p->gNB_ue_ngap_id);
ue_release_complete_p->gNB_ue_ngap_id);
return -1; return -1;
} }
/* Prepare the NGAP message to encode */ /* Prepare the NGAP message to encode */
memset(&pdu, 0, sizeof(pdu));
pdu.present = NGAP_NGAP_PDU_PR_successfulOutcome; pdu.present = NGAP_NGAP_PDU_PR_successfulOutcome;
pdu.choice.successfulOutcome = CALLOC(1, sizeof(struct NGAP_SuccessfulOutcome)); asn1cCalloc(pdu.choice.successfulOutcome, head);
pdu.choice.successfulOutcome->procedureCode = NGAP_ProcedureCode_id_UEContextRelease; head->procedureCode = NGAP_ProcedureCode_id_UEContextRelease;
pdu.choice.successfulOutcome->criticality = NGAP_Criticality_reject; head->criticality = NGAP_Criticality_reject;
pdu.choice.successfulOutcome->value.present = NGAP_SuccessfulOutcome__value_PR_UEContextReleaseComplete; head->value.present = NGAP_SuccessfulOutcome__value_PR_UEContextReleaseComplete;
out = &pdu.choice.successfulOutcome->value.choice.UEContextReleaseComplete; NGAP_UEContextReleaseComplete_t *out = &head->value.choice.UEContextReleaseComplete;
/* mandatory */ /* mandatory */
ie = (NGAP_UEContextReleaseComplete_IEs_t *)calloc(1, sizeof(NGAP_UEContextReleaseComplete_IEs_t)); {
asn1cSequenceAdd(out->protocolIEs.list, NGAP_UEContextReleaseComplete_IEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID; ie->id = NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID;
ie->criticality = NGAP_Criticality_ignore; ie->criticality = NGAP_Criticality_ignore;
ie->value.present = NGAP_UEContextReleaseComplete_IEs__value_PR_AMF_UE_NGAP_ID; ie->value.present = NGAP_UEContextReleaseComplete_IEs__value_PR_AMF_UE_NGAP_ID;
asn_uint642INTEGER(&ie->value.choice.AMF_UE_NGAP_ID, ue_context_p->amf_ue_ngap_id); asn_uint642INTEGER(&ie->value.choice.AMF_UE_NGAP_ID, ue_context_p->amf_ue_ngap_id);
asn1cSeqAdd(&out->protocolIEs.list, ie); }
/* mandatory */ /* mandatory */
ie = (NGAP_UEContextReleaseComplete_IEs_t *)calloc(1, sizeof(NGAP_UEContextReleaseComplete_IEs_t)); {
asn1cSequenceAdd(out->protocolIEs.list, NGAP_UEContextReleaseComplete_IEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID; ie->id = NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID;
ie->criticality = NGAP_Criticality_ignore; ie->criticality = NGAP_Criticality_ignore;
ie->value.present = NGAP_UEContextReleaseComplete_IEs__value_PR_RAN_UE_NGAP_ID; ie->value.present = NGAP_UEContextReleaseComplete_IEs__value_PR_RAN_UE_NGAP_ID;
ie->value.choice.RAN_UE_NGAP_ID = ue_release_complete_p->gNB_ue_ngap_id; ie->value.choice.RAN_UE_NGAP_ID = ue_release_complete_p->gNB_ue_ngap_id;
asn1cSeqAdd(&out->protocolIEs.list, ie); }
if (ngap_gNB_encode_pdu(&pdu, &buffer, &length) < 0) { if (ngap_gNB_encode_pdu(&pdu, &buffer, &length) < 0) {
/* Encode procedure has failed... */ /* Encode procedure has failed... */
...@@ -123,35 +114,18 @@ int ngap_ue_context_release_complete(instance_t instance, ...@@ -123,35 +114,18 @@ int ngap_ue_context_release_complete(instance_t instance,
//LG ngap_gNB_itti_send_sctp_close_association(ngap_gNB_instance_p->instance, //LG ngap_gNB_itti_send_sctp_close_association(ngap_gNB_instance_p->instance,
// ue_context_p->amf_ref->assoc_id); // ue_context_p->amf_ref->assoc_id);
// release UE context // release UE context
struct ngap_gNB_ue_context_s *ue_context2_p = NULL; ngap_gNB_ue_context_t *tmp = ngap_detach_ue_context(ue_release_complete_p->gNB_ue_ngap_id);
if (tmp)
if ((ue_context2_p = RB_REMOVE(ngap_ue_map, &ngap_gNB_instance_p->ngap_ue_head, ue_context_p)) free(tmp);
!= NULL) {
NGAP_WARN("Removed UE context gNB_ue_ngap_id %u\n",
ue_context2_p->gNB_ue_ngap_id);
ngap_gNB_free_ue_context(ue_context2_p);
} else {
NGAP_WARN("Removing UE context gNB_ue_ngap_id %u: did not find context\n",
ue_context_p->gNB_ue_ngap_id);
}
/*RB_FOREACH(ue_context_p, ngap_ue_map, &ngap_gNB_instance_p->ngap_ue_head) {
NGAP_WARN("in ngap_ue_map: UE context gNB_ue_ngap_id %u amf_ue_ngap_id %u state %u\n",
ue_context_p->gNB_ue_ngap_id, ue_context_p->amf_ue_ngap_id,
ue_context_p->ue_state);
}*/
return 0; return 0;
} }
int ngap_ue_context_release_req(instance_t instance, int ngap_ue_context_release_req(instance_t instance,
ngap_ue_release_req_t *ue_release_req_p) ngap_ue_release_req_t *ue_release_req_p)
{ {
ngap_gNB_instance_t *ngap_gNB_instance_p = NULL; ngap_gNB_instance_t *ngap_gNB_instance_p = NULL;
struct ngap_gNB_ue_context_s *ue_context_p = NULL; struct ngap_gNB_ue_context_s *ue_context_p = NULL;
NGAP_NGAP_PDU_t pdu; NGAP_NGAP_PDU_t pdu = {0};
NGAP_UEContextReleaseRequest_t *out;
NGAP_UEContextReleaseRequest_IEs_t *ie;
uint8_t *buffer = NULL; uint8_t *buffer = NULL;
uint32_t length; uint32_t length;
/* Retrieve the NGAP gNB instance associated with Mod_id */ /* Retrieve the NGAP gNB instance associated with Mod_id */
...@@ -160,8 +134,7 @@ int ngap_ue_context_release_req(instance_t instance, ...@@ -160,8 +134,7 @@ int ngap_ue_context_release_req(instance_t instance,
DevAssert(ue_release_req_p != NULL); DevAssert(ue_release_req_p != NULL);
DevAssert(ngap_gNB_instance_p != NULL); DevAssert(ngap_gNB_instance_p != NULL);
if ((ue_context_p = ngap_gNB_get_ue_context(ngap_gNB_instance_p, if ((ue_context_p = ngap_get_ue_context(ue_release_req_p->gNB_ue_ngap_id)) == NULL) {
ue_release_req_p->gNB_ue_ngap_id)) == NULL) {
/* The context for this gNB ue ngap id doesn't exist in the map of gNB UEs */ /* The context for this gNB ue ngap id doesn't exist in the map of gNB UEs */
NGAP_WARN("Failed to find ue context associated with gNB ue ngap id: %u\n", NGAP_WARN("Failed to find ue context associated with gNB ue ngap id: %u\n",
ue_release_req_p->gNB_ue_ngap_id); ue_release_req_p->gNB_ue_ngap_id);
...@@ -169,33 +142,34 @@ int ngap_ue_context_release_req(instance_t instance, ...@@ -169,33 +142,34 @@ int ngap_ue_context_release_req(instance_t instance,
} }
/* Prepare the NGAP message to encode */ /* Prepare the NGAP message to encode */
memset(&pdu, 0, sizeof(pdu));
pdu.present = NGAP_NGAP_PDU_PR_initiatingMessage; pdu.present = NGAP_NGAP_PDU_PR_initiatingMessage;
pdu.choice.initiatingMessage = CALLOC(1, sizeof(struct NGAP_InitiatingMessage)); asn1cCalloc(pdu.choice.initiatingMessage, head);
pdu.choice.initiatingMessage->procedureCode = NGAP_ProcedureCode_id_UEContextReleaseRequest; head->procedureCode = NGAP_ProcedureCode_id_UEContextReleaseRequest;
pdu.choice.initiatingMessage->criticality = NGAP_Criticality_ignore; head->criticality = NGAP_Criticality_ignore;
pdu.choice.initiatingMessage->value.present = NGAP_InitiatingMessage__value_PR_UEContextReleaseRequest; head->value.present = NGAP_InitiatingMessage__value_PR_UEContextReleaseRequest;
out = &pdu.choice.initiatingMessage->value.choice.UEContextReleaseRequest; NGAP_UEContextReleaseRequest_t *out = &head->value.choice.UEContextReleaseRequest;
/* mandatory */ /* mandatory */
ie = (NGAP_UEContextReleaseRequest_IEs_t *)calloc(1, sizeof(NGAP_UEContextReleaseRequest_IEs_t)); {
asn1cSequenceAdd(out->protocolIEs.list, NGAP_UEContextReleaseRequest_IEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID; ie->id = NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID;
ie->criticality = NGAP_Criticality_reject; ie->criticality = NGAP_Criticality_reject;
ie->value.present = NGAP_UEContextReleaseRequest_IEs__value_PR_AMF_UE_NGAP_ID; ie->value.present = NGAP_UEContextReleaseRequest_IEs__value_PR_AMF_UE_NGAP_ID;
asn_uint642INTEGER(&ie->value.choice.AMF_UE_NGAP_ID, ue_context_p->amf_ue_ngap_id); asn_uint642INTEGER(&ie->value.choice.AMF_UE_NGAP_ID, ue_context_p->amf_ue_ngap_id);
asn1cSeqAdd(&out->protocolIEs.list, ie); }
/* mandatory */ /* mandatory */
ie = (NGAP_UEContextReleaseRequest_IEs_t *)calloc(1, sizeof(NGAP_UEContextReleaseRequest_IEs_t)); {
asn1cSequenceAdd(out->protocolIEs.list, NGAP_UEContextReleaseRequest_IEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID; ie->id = NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID;
ie->criticality = NGAP_Criticality_reject; ie->criticality = NGAP_Criticality_reject;
ie->value.present = NGAP_UEContextReleaseRequest_IEs__value_PR_RAN_UE_NGAP_ID; ie->value.present = NGAP_UEContextReleaseRequest_IEs__value_PR_RAN_UE_NGAP_ID;
ie->value.choice.RAN_UE_NGAP_ID = ue_release_req_p->gNB_ue_ngap_id; ie->value.choice.RAN_UE_NGAP_ID = ue_release_req_p->gNB_ue_ngap_id;
asn1cSeqAdd(&out->protocolIEs.list, ie); }
/* optional */ /* optional */
if (ue_release_req_p->nb_of_pdusessions > 0) { if (ue_release_req_p->nb_of_pdusessions > 0) {
ie = (NGAP_UEContextReleaseRequest_IEs_t *)calloc(1, sizeof(NGAP_UEContextReleaseRequest_IEs_t)); asn1cSequenceAdd(out->protocolIEs.list, NGAP_UEContextReleaseRequest_IEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_PDUSessionResourceListCxtRelReq; ie->id = NGAP_ProtocolIE_ID_id_PDUSessionResourceListCxtRelReq;
ie->criticality = NGAP_Criticality_reject; ie->criticality = NGAP_Criticality_reject;
ie->value.present = NGAP_UEContextReleaseRequest_IEs__value_PR_PDUSessionResourceListCxtRelReq; ie->value.present = NGAP_UEContextReleaseRequest_IEs__value_PR_PDUSessionResourceListCxtRelReq;
...@@ -205,51 +179,19 @@ int ngap_ue_context_release_req(instance_t instance, ...@@ -205,51 +179,19 @@ int ngap_ue_context_release_req(instance_t instance,
item->pDUSessionID = ue_release_req_p->pdusessions[i].pdusession_id; item->pDUSessionID = ue_release_req_p->pdusessions[i].pdusession_id;
asn1cSeqAdd(&ie->value.choice.PDUSessionResourceListCxtRelReq.list, item); asn1cSeqAdd(&ie->value.choice.PDUSessionResourceListCxtRelReq.list, item);
} }
asn1cSeqAdd(&out->protocolIEs.list, ie);
} }
/* mandatory */ /* mandatory */
ie = (NGAP_UEContextReleaseRequest_IEs_t *)calloc(1, sizeof(NGAP_UEContextReleaseRequest_IEs_t)); {
asn1cSequenceAdd(out->protocolIEs.list, NGAP_UEContextReleaseRequest_IEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_Cause; ie->id = NGAP_ProtocolIE_ID_id_Cause;
ie->criticality = NGAP_Criticality_ignore; ie->criticality = NGAP_Criticality_ignore;
ie->value.present = NGAP_UEContextReleaseRequest_IEs__value_PR_Cause; ie->value.present = NGAP_UEContextReleaseRequest_IEs__value_PR_Cause;
DevAssert(ue_release_req_p->cause <= NGAP_Cause_PR_choice_ExtensionS);
switch (ue_release_req_p->cause) { ie->value.choice.Cause.present = ue_release_req_p->cause;
case NGAP_Cause_PR_radioNetwork:
ie->value.choice.Cause.present = NGAP_Cause_PR_radioNetwork;
ie->value.choice.Cause.choice.radioNetwork = ue_release_req_p->cause_value;
break;
case NGAP_Cause_PR_transport:
ie->value.choice.Cause.present = NGAP_Cause_PR_transport;
ie->value.choice.Cause.choice.transport = ue_release_req_p->cause_value;
break;
case NGAP_Cause_PR_nas:
ie->value.choice.Cause.present = NGAP_Cause_PR_nas;
ie->value.choice.Cause.choice.nas = ue_release_req_p->cause_value;
break;
case NGAP_Cause_PR_protocol:
ie->value.choice.Cause.present = NGAP_Cause_PR_protocol;
ie->value.choice.Cause.choice.protocol = ue_release_req_p->cause_value;
break;
case NGAP_Cause_PR_misc:
ie->value.choice.Cause.present = NGAP_Cause_PR_misc;
ie->value.choice.Cause.choice.misc = ue_release_req_p->cause_value; ie->value.choice.Cause.choice.misc = ue_release_req_p->cause_value;
break;
case NGAP_Cause_PR_NOTHING:
default:
ie->value.choice.Cause.present = NGAP_Cause_PR_NOTHING;
break;
} }
asn1cSeqAdd(&out->protocolIEs.list, ie);
if (ngap_gNB_encode_pdu(&pdu, &buffer, &length) < 0) { if (ngap_gNB_encode_pdu(&pdu, &buffer, &length) < 0) {
/* Encode procedure has failed... */ /* Encode procedure has failed... */
NGAP_ERROR("Failed to encode UE context release complete\n"); NGAP_ERROR("Failed to encode UE context release complete\n");
......
...@@ -156,13 +156,8 @@ int ngap_gNB_decode_pdu(NGAP_NGAP_PDU_t *pdu, const uint8_t *const buffer, ...@@ -156,13 +156,8 @@ int ngap_gNB_decode_pdu(NGAP_NGAP_PDU_t *pdu, const uint8_t *const buffer,
asn_dec_rval_t dec_ret; asn_dec_rval_t dec_ret;
DevAssert(pdu != NULL); DevAssert(pdu != NULL);
DevAssert(buffer != NULL); DevAssert(buffer != NULL);
dec_ret = aper_decode(NULL, asn_codec_ctx_t st = {.max_stack_size = 100 * 1000}; // if we enable asn1c debug the stack size become large
&asn_DEF_NGAP_NGAP_PDU, dec_ret = aper_decode(&st, &asn_DEF_NGAP_NGAP_PDU, (void **)&pdu, buffer, length, 0, 0);
(void **)&pdu,
buffer,
length,
0,
0);
if (dec_ret.code != RC_OK) { if (dec_ret.code != RC_OK) {
NGAP_ERROR("Failed to decode pdu\n"); NGAP_ERROR("Failed to decode pdu\n");
......
...@@ -236,11 +236,6 @@ typedef struct ngap_gNB_instance_s { ...@@ -236,11 +236,6 @@ typedef struct ngap_gNB_instance_s {
/* Tree of NGAP AMF associations ordered by association ID */ /* Tree of NGAP AMF associations ordered by association ID */
RB_HEAD(ngap_amf_map, ngap_gNB_amf_data_s) ngap_amf_head; RB_HEAD(ngap_amf_map, ngap_gNB_amf_data_s) ngap_amf_head;
/* TODO: add a map ordered by relative AMF capacity */
/* Tree of UE ordered by gNB_ue_ngap_id's */
RB_HEAD(ngap_ue_map, ngap_gNB_ue_context_s) ngap_ue_head;
/* For virtual mode, mod_id as defined in the rest of the L1/L2 stack */ /* For virtual mode, mod_id as defined in the rest of the L1/L2 stack */
instance_t instance; instance_t instance;
......
...@@ -38,186 +38,100 @@ ...@@ -38,186 +38,100 @@
#include "ngap_common.h" #include "ngap_common.h"
#include "ngap_gNB_encoder.h" #include "ngap_gNB_encoder.h"
static inline int ngap_gNB_encode_initiating(NGAP_NGAP_PDU_t *pdu, static inline int ngap_gNB_encode_initiating(NGAP_NGAP_PDU_t *pdu, uint8_t **buffer, uint32_t *len)
uint8_t **buffer, {
uint32_t *len);
static inline int ngap_gNB_encode_successfull_outcome(NGAP_NGAP_PDU_t *pdu,
uint8_t **buffer, uint32_t *len);
static inline int ngap_gNB_encode_unsuccessfull_outcome(NGAP_NGAP_PDU_t *pdu,
uint8_t **buffer, uint32_t *len);
int ngap_gNB_encode_pdu(NGAP_NGAP_PDU_t *pdu, uint8_t **buffer, uint32_t *len) {
int ret = -1;
DevAssert(pdu != NULL); DevAssert(pdu != NULL);
DevAssert(buffer != NULL);
DevAssert(len != NULL);
switch(pdu->present) { const NGAP_ProcedureCode_t tmp[] = {NGAP_ProcedureCode_id_NGSetup,
case NGAP_NGAP_PDU_PR_initiatingMessage: NGAP_ProcedureCode_id_UplinkNASTransport,
ret = ngap_gNB_encode_initiating(pdu, buffer, len); NGAP_ProcedureCode_id_UERadioCapabilityInfoIndication,
break; NGAP_ProcedureCode_id_InitialUEMessage,
NGAP_ProcedureCode_id_NASNonDeliveryIndication,
case NGAP_NGAP_PDU_PR_successfulOutcome: NGAP_ProcedureCode_id_UEContextReleaseRequest,
ret = ngap_gNB_encode_successfull_outcome(pdu, buffer, len); NGAP_ProcedureCode_id_PathSwitchRequest,
break; NGAP_ProcedureCode_id_PDUSessionResourceModifyIndication};
int i;
case NGAP_NGAP_PDU_PR_unsuccessfulOutcome: for (i = 0; i < sizeofArray(tmp); i++)
ret = ngap_gNB_encode_unsuccessfull_outcome(pdu, buffer, len); if (pdu->choice.initiatingMessage->procedureCode == tmp[i])
break; break;
if (i == sizeofArray(tmp)) {
default: NGAP_DEBUG("Unknown procedure ID (%d) for initiating message\n", (int)pdu->choice.initiatingMessage->procedureCode);
NGAP_DEBUG("Unknown message outcome (%d) or not implemented",
(int)pdu->present);
return -1; return -1;
} }
//ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_NGAP_NGAP_PDU, pdu); asn_encode_to_new_buffer_result_t res = asn_encode_to_new_buffer(NULL, ATS_ALIGNED_CANONICAL_PER, &asn_DEF_NGAP_NGAP_PDU, pdu);
return ret; AssertFatal(res.result.encoded > 0, "failed to encode NGAP msg\n");
*buffer = res.buffer;
*len = res.result.encoded;
return 0;
} }
static inline static inline int ngap_gNB_encode_successfull_outcome(NGAP_NGAP_PDU_t *pdu, uint8_t **buffer, uint32_t *len)
int ngap_gNB_encode_initiating(NGAP_NGAP_PDU_t *pdu, {
uint8_t **buffer, uint32_t *len) {
asn_encode_to_new_buffer_result_t res = { NULL, {0, NULL, NULL} };
DevAssert(pdu != NULL); DevAssert(pdu != NULL);
const NGAP_ProcedureCode_t tmp[] = {NGAP_ProcedureCode_id_InitialContextSetup,
switch(pdu->choice.initiatingMessage->procedureCode) { NGAP_ProcedureCode_id_UEContextRelease,
case NGAP_ProcedureCode_id_NGSetup: NGAP_ProcedureCode_id_PDUSessionResourceSetup,
res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_NGAP_NGAP_PDU, pdu); NGAP_ProcedureCode_id_PDUSessionResourceModify,
free(res.buffer); NGAP_ProcedureCode_id_PDUSessionResourceRelease};
break; int i;
for (i = 0; i < sizeofArray(tmp); i++)
case NGAP_ProcedureCode_id_UplinkNASTransport: if (pdu->choice.successfulOutcome->procedureCode == tmp[i])
res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_NGAP_NGAP_PDU, pdu); break;
free(res.buffer); if (i == sizeofArray(tmp)) {
break; NGAP_WARN("Unknown procedure ID (%ld) for successfull outcome message\n", pdu->choice.successfulOutcome->procedureCode);
case NGAP_ProcedureCode_id_UERadioCapabilityInfoIndication:
res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_NGAP_NGAP_PDU, pdu);
free(res.buffer);
break;
case NGAP_ProcedureCode_id_InitialUEMessage:
res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_NGAP_NGAP_PDU, pdu);
free(res.buffer);
break;
case NGAP_ProcedureCode_id_NASNonDeliveryIndication:
res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_NGAP_NGAP_PDU, pdu);
free(res.buffer);
break;
case NGAP_ProcedureCode_id_UEContextReleaseRequest:
res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_NGAP_NGAP_PDU, pdu);
free(res.buffer);
break;
case NGAP_ProcedureCode_id_PathSwitchRequest:
res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_NGAP_NGAP_PDU, pdu);
free(res.buffer);
break;
case NGAP_ProcedureCode_id_PDUSessionResourceModifyIndication:
res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_NGAP_NGAP_PDU, pdu);
free(res.buffer);
break;
default:
NGAP_DEBUG("Unknown procedure ID (%d) for initiating message\n",
(int)pdu->choice.initiatingMessage->procedureCode);
return -1; return -1;
} }
if (asn1_xer_print) { asn_encode_to_new_buffer_result_t res = asn_encode_to_new_buffer(NULL, ATS_ALIGNED_CANONICAL_PER, &asn_DEF_NGAP_NGAP_PDU, pdu);
xer_fprint(stdout, &asn_DEF_NGAP_NGAP_PDU, (void *)pdu); AssertFatal(res.result.encoded > 0, "failed to encode NGAP msg\n");
}
memset(&res, 0, sizeof(res));
res = asn_encode_to_new_buffer(NULL, ATS_ALIGNED_CANONICAL_PER, &asn_DEF_NGAP_NGAP_PDU, pdu);
*buffer = res.buffer; *buffer = res.buffer;
*len = res.result.encoded; *len = res.result.encoded;
return 0; return 0;
} }
static inline static inline int ngap_gNB_encode_unsuccessfull_outcome(NGAP_NGAP_PDU_t *pdu, uint8_t **buffer, uint32_t *len)
int ngap_gNB_encode_successfull_outcome(NGAP_NGAP_PDU_t *pdu, {
uint8_t **buffer, uint32_t *len) {
asn_encode_to_new_buffer_result_t res = { NULL, {0, NULL, NULL} };
DevAssert(pdu != NULL); DevAssert(pdu != NULL);
switch(pdu->choice.successfulOutcome->procedureCode) { if (pdu->choice.unsuccessfulOutcome->procedureCode != NGAP_ProcedureCode_id_InitialContextSetup) {
case NGAP_ProcedureCode_id_InitialContextSetup: NGAP_DEBUG("Unknown procedure ID (%d) for unsuccessfull outcome message\n", (int)pdu->choice.unsuccessfulOutcome->procedureCode);
res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_NGAP_NGAP_PDU, pdu);
free(res.buffer);
break;
case NGAP_ProcedureCode_id_UEContextRelease:
res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_NGAP_NGAP_PDU, pdu);
free(res.buffer);
break;
case NGAP_ProcedureCode_id_PDUSessionResourceSetup:
res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_NGAP_NGAP_PDU, pdu);
free(res.buffer);
NGAP_INFO("PDUSESSIONSetup successful message\n");
break;
case NGAP_ProcedureCode_id_PDUSessionResourceModify:
res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_NGAP_NGAP_PDU, pdu);
free(res.buffer);
NGAP_INFO("PDUSESSIONModify successful message\n");
break;
case NGAP_ProcedureCode_id_PDUSessionResourceRelease:
res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_NGAP_NGAP_PDU, pdu);
free(res.buffer);
NGAP_INFO("PDUSESSION Release successful message\n");
break;
default:
NGAP_WARN("Unknown procedure ID (%d) for successfull outcome message\n",
(int)pdu->choice.successfulOutcome->procedureCode);
return -1; return -1;
} }
if (asn1_xer_print) { asn_encode_to_new_buffer_result_t res = asn_encode_to_new_buffer(NULL, ATS_ALIGNED_CANONICAL_PER, &asn_DEF_NGAP_NGAP_PDU, pdu);
xer_fprint(stdout, &asn_DEF_NGAP_NGAP_PDU, (void *)pdu); AssertFatal(res.result.encoded > 0, "failed to encode NGAP msg\n");
}
memset(&res, 0, sizeof(res));
res = asn_encode_to_new_buffer(NULL, ATS_ALIGNED_CANONICAL_PER, &asn_DEF_NGAP_NGAP_PDU, pdu);
*buffer = res.buffer; *buffer = res.buffer;
*len = res.result.encoded; *len = res.result.encoded;
return 0; return 0;
} }
static inline int ngap_gNB_encode_pdu(NGAP_NGAP_PDU_t *pdu, uint8_t **buffer, uint32_t *len)
int ngap_gNB_encode_unsuccessfull_outcome(NGAP_NGAP_PDU_t *pdu, {
uint8_t **buffer, uint32_t *len) { int ret = -1;
asn_encode_to_new_buffer_result_t res = { NULL, {0, NULL, NULL} };
DevAssert(pdu != NULL); DevAssert(pdu != NULL);
DevAssert(buffer != NULL);
DevAssert(len != NULL);
if (asn1_xer_print) {
xer_fprint(stdout, &asn_DEF_NGAP_NGAP_PDU, (void *)pdu);
}
switch (pdu->present) {
case NGAP_NGAP_PDU_PR_initiatingMessage:
ret = ngap_gNB_encode_initiating(pdu, buffer, len);
break;
switch(pdu->choice.unsuccessfulOutcome->procedureCode) { case NGAP_NGAP_PDU_PR_successfulOutcome:
case NGAP_ProcedureCode_id_InitialContextSetup: ret = ngap_gNB_encode_successfull_outcome(pdu, buffer, len);
res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_NGAP_NGAP_PDU, pdu); break;
free(res.buffer);
case NGAP_NGAP_PDU_PR_unsuccessfulOutcome:
ret = ngap_gNB_encode_unsuccessfull_outcome(pdu, buffer, len);
break; break;
default: default:
NGAP_DEBUG("Unknown procedure ID (%d) for unsuccessfull outcome message\n", NGAP_DEBUG("Unknown message outcome (%d) or not implemented", (int)pdu->present);
(int)pdu->choice.unsuccessfulOutcome->procedureCode);
return -1; return -1;
} }
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_NGAP_NGAP_PDU, pdu);
if (asn1_xer_print) { return ret;
xer_fprint(stdout, &asn_DEF_NGAP_NGAP_PDU, (void *)pdu);
}
memset(&res, 0, sizeof(res));
res = asn_encode_to_new_buffer(NULL, ATS_ALIGNED_CANONICAL_PER, &asn_DEF_NGAP_NGAP_PDU, pdu);
*buffer = res.buffer;
*len = res.result.encoded;
return 0;
} }
...@@ -48,119 +48,15 @@ ...@@ -48,119 +48,15 @@
#include "conversions.h" #include "conversions.h"
#include "NGAP_NonDynamic5QIDescriptor.h" #include "NGAP_NonDynamic5QIDescriptor.h"
static int ngap_gNB_handle_ng_setup_response(uint32_t ssoc_id, uint32_t stream, NGAP_NGAP_PDU_t *pdu); static void allocCopy(ngap_pdu_t *out, OCTET_STRING_t in)
static {
int ngap_gNB_handle_ng_setup_failure(uint32_t assoc_id, if (in.size) {
uint32_t stream, out->buffer = malloc(in.size);
NGAP_NGAP_PDU_t *pdu); memcpy(out->buffer, in.buf, in.size);
}
static out->length = in.size;
int ngap_gNB_handle_error_indication(uint32_t assoc_id, }
uint32_t stream,
NGAP_NGAP_PDU_t *pdu);
static
int ngap_gNB_handle_initial_context_request(uint32_t assoc_id,
uint32_t stream,
NGAP_NGAP_PDU_t *pdu);
static
int ngap_gNB_handle_ue_context_release_command(uint32_t assoc_id,
uint32_t stream,
NGAP_NGAP_PDU_t *pdu);
static
int ngap_gNB_handle_pdusession_setup_request(uint32_t assoc_id,
uint32_t stream,
NGAP_NGAP_PDU_t *pdu);
static
int ngap_gNB_handle_paging(uint32_t assoc_id,
uint32_t stream,
NGAP_NGAP_PDU_t *pdu);
static
int ngap_gNB_handle_pdusession_modify_request(uint32_t assoc_id,
uint32_t stream,
NGAP_NGAP_PDU_t *pdu);
static
int ngap_gNB_handle_pdusession_release_command(uint32_t assoc_id,
uint32_t stream,
NGAP_NGAP_PDU_t *pdu);
static
int ngap_gNB_handle_ng_path_switch_request_ack(uint32_t assoc_id,
uint32_t stream,
NGAP_NGAP_PDU_t *pdu);
static
int ngap_gNB_handle_ng_path_switch_request_failure(uint32_t assoc_id,
uint32_t stream,
NGAP_NGAP_PDU_t *pdu);
static
int ngap_gNB_handle_ng_ENDC_pdusession_modification_confirm(uint32_t assoc_id,
uint32_t stream,
NGAP_NGAP_PDU_t *pdu);
/* Handlers matrix. Only gNB related procedure present here */
ngap_message_decoded_callback ngap_messages_callback[][3] = {
{ 0, 0, 0 }, /* AMFConfigurationUpdate */
{ 0, 0, 0 }, /* AMFStatusIndication */
{ 0, 0, 0 }, /* CellTrafficTrace */
{ ngap_gNB_handle_deactivate_trace, 0, 0 }, /* DeactivateTrace */
{ ngap_gNB_handle_nas_downlink, 0, 0 }, /* DownlinkNASTransport */
{ 0, 0, 0 }, /* DownlinkNonUEAssociatedNRPPaTransport */
{ 0, 0, 0 }, /* DownlinkRANConfigurationTransfer */
{ 0, 0, 0 }, /* DownlinkRANStatusTransfer */
{ 0, 0, 0 }, /* DownlinkUEAssociatedNRPPaTransport */
{ ngap_gNB_handle_error_indication, 0, 0 }, /* ErrorIndication */
{ 0, 0, 0 }, /* HandoverCancel */
{ 0, 0, 0 }, /* HandoverNotification */
{ 0, 0, 0 }, /* HandoverPreparation */
{ 0, 0, 0 }, /* HandoverResourceAllocation */
{ ngap_gNB_handle_initial_context_request, 0, 0 }, /* InitialContextSetup */
{ 0, 0, 0 }, /* InitialUEMessage */
{ 0, 0, 0 }, /* LocationReportingControl */
{ 0, 0, 0 }, /* LocationReportingFailureIndication */
{ 0, 0, 0 }, /* LocationReport */
{ 0, 0, 0 }, /* NASNonDeliveryIndication */
{ 0, 0, 0 }, /* NGReset */
{ 0, ngap_gNB_handle_ng_setup_response, ngap_gNB_handle_ng_setup_failure }, /* NGSetup */
{ 0, 0, 0 }, /* OverloadStart */
{ 0, 0, 0 }, /* OverloadStop */
{ ngap_gNB_handle_paging, 0, 0 }, /* Paging */
{ 0, ngap_gNB_handle_ng_path_switch_request_ack, ngap_gNB_handle_ng_path_switch_request_failure }, /* PathSwitchRequest */
{ ngap_gNB_handle_pdusession_modify_request, 0, 0 }, /* PDUSessionResourceModify */
{ 0, ngap_gNB_handle_ng_ENDC_pdusession_modification_confirm, 0 }, /* PDUSessionResourceModifyIndication */
{ ngap_gNB_handle_pdusession_release_command, 0, 0 }, /* PDUSessionResourceRelease */
{ ngap_gNB_handle_pdusession_setup_request, 0, 0 }, /* PDUSessionResourceSetup */
{ 0, 0, 0 }, /* PDUSessionResourceNotify */
{ 0, 0, 0 }, /* PrivateMessage */
{ 0, 0, 0 }, /* PWSCancel */
{ 0, 0, 0 }, /* PWSFailureIndication */
{ 0, 0, 0 }, /* PWSRestartIndication */
{ 0, 0, 0 }, /* RANConfigurationUpdate */
{ 0, 0, 0 }, /* RerouteNASRequest */
{ 0, 0, 0 }, /* RRCInactiveTransitionReport */
{ 0, 0, 0 }, /* TraceFailureIndication */
{ ngap_gNB_handle_trace_start, 0, 0 }, /* TraceStart */
{ 0, 0, 0 }, /* UEContextModification */
{ ngap_gNB_handle_ue_context_release_command, 0, 0 }, /* UEContextRelease */
{ 0, 0, 0 }, /* UEContextReleaseRequest */
{ 0, 0, 0 }, /* UERadioCapabilityCheck */
{ 0, 0, 0 }, /* UERadioCapabilityInfoIndication */
{ 0, 0, 0 }, /* UETNLABindingRelease */
{ 0, 0, 0 }, /* UplinkNASTransport */
{ 0, 0, 0 }, /* UplinkNonUEAssociatedNRPPaTransport */
{ 0, 0, 0 }, /* UplinkRANConfigurationTransfer */
{ 0, 0, 0 }, /* UplinkRANStatusTransfer */
{ 0, 0, 0 }, /* UplinkUEAssociatedNRPPaTransport */
{ 0, 0, 0 }, /* WriteReplaceWarning */
{ 0, 0, 0 }, /* SecondaryRATDataUsageReport */
};
char *ngap_direction2String(int ngap_dir) { char *ngap_direction2String(int ngap_dir) {
static char *ngap_direction_String[] = { static char *ngap_direction_String[] = {
"", /* Nothing */ "", /* Nothing */
...@@ -209,46 +105,6 @@ void ngap_handle_ng_setup_message(ngap_gNB_amf_data_t *amf_desc_p, int sctp_shut ...@@ -209,46 +105,6 @@ void ngap_handle_ng_setup_message(ngap_gNB_amf_data_t *amf_desc_p, int sctp_shut
} }
} }
int ngap_gNB_handle_message(uint32_t assoc_id, int32_t stream,
const uint8_t *const data, const uint32_t data_length) {
NGAP_NGAP_PDU_t pdu;
int ret;
DevAssert(data != NULL);
memset(&pdu, 0, sizeof(pdu));
if (ngap_gNB_decode_pdu(&pdu, data, data_length) < 0) {
NGAP_ERROR("Failed to decode PDU\n");
return -1;
}
/* Checking procedure Code and direction of message */
if (pdu.choice.initiatingMessage->procedureCode >= sizeof(ngap_messages_callback) / (3 * sizeof(
ngap_message_decoded_callback))
|| (pdu.present > NGAP_NGAP_PDU_PR_unsuccessfulOutcome)) {
NGAP_ERROR("[SCTP %d] Either procedureCode %ld or direction %d exceed expected\n",
assoc_id, pdu.choice.initiatingMessage->procedureCode, pdu.present);
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_NGAP_NGAP_PDU, &pdu);
return -1;
}
/* No handler present.
* This can mean not implemented or no procedure for gNB (wrong direction).
*/
if (ngap_messages_callback[pdu.choice.initiatingMessage->procedureCode][pdu.present - 1] == NULL) {
NGAP_ERROR("[SCTP %d] No handler for procedureCode %ld in %s\n",
assoc_id, pdu.choice.initiatingMessage->procedureCode,
ngap_direction2String(pdu.present - 1));
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_NGAP_NGAP_PDU, &pdu);
return -1;
}
/* Calling the right handler */
ret = (*ngap_messages_callback[pdu.choice.initiatingMessage->procedureCode][pdu.present - 1])
(assoc_id, stream, &pdu);
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_NGAP_NGAP_PDU, &pdu);
return ret;
}
static static
int ngap_gNB_handle_ng_setup_failure(uint32_t assoc_id, int ngap_gNB_handle_ng_setup_failure(uint32_t assoc_id,
uint32_t stream, uint32_t stream,
...@@ -378,10 +234,8 @@ int ngap_gNB_handle_ng_setup_response(uint32_t assoc_id, ...@@ -378,10 +234,8 @@ int ngap_gNB_handle_ng_setup_response(uint32_t assoc_id,
NGAP_ProtocolIE_ID_id_AMFName, true); NGAP_ProtocolIE_ID_id_AMFName, true);
if (ie) { if (ie) {
amf_desc_p->amf_name = calloc(ie->value.choice.AMFName.size + 1, sizeof(char)); amf_desc_p->amf_name = malloc(ie->value.choice.AMFName.size + 1);
memcpy(amf_desc_p->amf_name, ie->value.choice.AMFName.buf, memcpy(amf_desc_p->amf_name, ie->value.choice.AMFName.buf, ie->value.choice.AMFName.size);
ie->value.choice.AMFName.size);
/* Convert the amf name to a printable string */
amf_desc_p->amf_name[ie->value.choice.AMFName.size] = '\0'; amf_desc_p->amf_name[ie->value.choice.AMFName.size] = '\0';
} }
...@@ -824,18 +678,12 @@ int ngap_gNB_handle_error_indication(uint32_t assoc_id, ...@@ -824,18 +678,12 @@ int ngap_gNB_handle_error_indication(uint32_t assoc_id,
return 0; return 0;
} }
static int ngap_gNB_handle_initial_context_request(uint32_t assoc_id, uint32_t stream, NGAP_NGAP_PDU_t *pdu)
static {
int ngap_gNB_handle_initial_context_request(uint32_t assoc_id,
uint32_t stream,
NGAP_NGAP_PDU_t *pdu) {
int i; int i;
ngap_gNB_amf_data_t *amf_desc_p = NULL; ngap_gNB_amf_data_t *amf_desc_p = NULL;
ngap_gNB_ue_context_t *ue_desc_p = NULL;
NGAP_InitialContextSetupRequest_t *container; NGAP_InitialContextSetupRequest_t *container;
NGAP_InitialContextSetupRequestIEs_t *ie; NGAP_InitialContextSetupRequestIEs_t *ie;
NGAP_RAN_UE_NGAP_ID_t ran_ue_ngap_id;
uint64_t amf_ue_ngap_id; uint64_t amf_ue_ngap_id;
DevAssert(pdu != NULL); DevAssert(pdu != NULL);
container = &pdu->choice.initiatingMessage->value.choice.InitialContextSetupRequest; container = &pdu->choice.initiatingMessage->value.choice.InitialContextSetupRequest;
...@@ -850,29 +698,22 @@ int ngap_gNB_handle_initial_context_request(uint32_t assoc_id, ...@@ -850,29 +698,22 @@ int ngap_gNB_handle_initial_context_request(uint32_t assoc_id,
NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_InitialContextSetupRequestIEs_t, ie, container, NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_InitialContextSetupRequestIEs_t, ie, container,
NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID, true); NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID, true);
if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
asn_INTEGER2ulong(&(ie->value.choice.AMF_UE_NGAP_ID), &amf_ue_ngap_id); asn_INTEGER2ulong(&(ie->value.choice.AMF_UE_NGAP_ID), &amf_ue_ngap_id);
} else {
return -1;
}
/* id-RAN-UE-NGAP-ID */ /* id-RAN-UE-NGAP-ID */
NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_InitialContextSetupRequestIEs_t, ie, container, NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_InitialContextSetupRequestIEs_t, ie, container,
NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID, true); NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID, true);
if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ const NGAP_RAN_UE_NGAP_ID_t ran_ue_ngap_id = ie->value.choice.RAN_UE_NGAP_ID;
ran_ue_ngap_id = ie->value.choice.RAN_UE_NGAP_ID; ngap_gNB_ue_context_t *ue_desc_p = ngap_get_ue_context(ran_ue_ngap_id);
if (!ue_desc_p) {
if ((ue_desc_p = ngap_gNB_get_ue_context(amf_desc_p->ngap_gNB_instance, NGAP_ERROR(
ran_ue_ngap_id)) == NULL) { "[SCTP %d] Received initial context setup request for non "
NGAP_ERROR("[SCTP %d] Received initial context setup request for non " "existing UE context 0x%06lx\n",
"existing UE context 0x%06lx\n", assoc_id, assoc_id,
ran_ue_ngap_id); ran_ue_ngap_id);
return -1; return -1;
} }
} else {
return -1;
}
/* Initial context request = UE-related procedure -> stream != 0 */ /* Initial context request = UE-related procedure -> stream != 0 */
//if (stream == 0) { //if (stream == 0) {
...@@ -886,8 +727,7 @@ int ngap_gNB_handle_initial_context_request(uint32_t assoc_id, ...@@ -886,8 +727,7 @@ int ngap_gNB_handle_initial_context_request(uint32_t assoc_id,
MessageDef *message_p = itti_alloc_new_message(TASK_NGAP, 0, NGAP_INITIAL_CONTEXT_SETUP_REQ); MessageDef *message_p = itti_alloc_new_message(TASK_NGAP, 0, NGAP_INITIAL_CONTEXT_SETUP_REQ);
ngap_initial_context_setup_req_t * msg=&NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p); ngap_initial_context_setup_req_t * msg=&NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p);
msg->ue_initial_id = ue_desc_p->ue_initial_id; memset(msg, 0, sizeof(*msg));
ue_desc_p->ue_initial_id = 0;
msg->gNB_ue_ngap_id = ue_desc_p->gNB_ue_ngap_id; msg->gNB_ue_ngap_id = ue_desc_p->gNB_ue_ngap_id;
msg->amf_ue_ngap_id = ue_desc_p->amf_ue_ngap_id; msg->amf_ue_ngap_id = ue_desc_p->amf_ue_ngap_id;
/* id-UEAggregateMaximumBitRate */ /* id-UEAggregateMaximumBitRate */
...@@ -908,152 +748,24 @@ int ngap_gNB_handle_initial_context_request(uint32_t assoc_id, ...@@ -908,152 +748,24 @@ int ngap_gNB_handle_initial_context_request(uint32_t assoc_id,
NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_InitialContextSetupRequestIEs_t, ie, container, NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_InitialContextSetupRequestIEs_t, ie, container,
NGAP_ProtocolIE_ID_id_GUAMI, true); NGAP_ProtocolIE_ID_id_GUAMI, true);
if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
TBCD_TO_MCC_MNC(&ie->value.choice.GUAMI.pLMNIdentity, msg->guami.mcc, TBCD_TO_MCC_MNC(&ie->value.choice.GUAMI.pLMNIdentity, msg->guami.mcc,
msg->guami.mnc, msg->guami.mnc_len); msg->guami.mnc, msg->guami.mnc_len);
OCTET_STRING_TO_INT8(&ie->value.choice.GUAMI.aMFRegionID, msg->guami.amf_region_id); OCTET_STRING_TO_INT8(&ie->value.choice.GUAMI.aMFRegionID, msg->guami.amf_region_id);
OCTET_STRING_TO_INT16(&ie->value.choice.GUAMI.aMFSetID, msg->guami.amf_set_id); OCTET_STRING_TO_INT16(&ie->value.choice.GUAMI.aMFSetID, msg->guami.amf_set_id);
OCTET_STRING_TO_INT8(&ie->value.choice.GUAMI.aMFPointer, msg->guami.amf_pointer); OCTET_STRING_TO_INT8(&ie->value.choice.GUAMI.aMFPointer, msg->guami.amf_pointer);
} else {/* ie != NULL */
return -1;
}
NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_InitialContextSetupRequestIEs_t, ie, container,
NGAP_ProtocolIE_ID_id_PDUSessionResourceSetupListCxtReq, false);
if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_InitialContextSetupRequestIEs_t, ie, container, NGAP_ProtocolIE_ID_id_PDUSessionResourceSetupListCxtReq, false);
msg->nb_of_pdusessions = if (ie != NULL) {
ie->value.choice.PDUSessionResourceSetupListCxtReq.list.count; msg->nb_of_pdusessions = ie->value.choice.PDUSessionResourceSetupListCxtReq.list.count;
for (i = 0; i < ie->value.choice.PDUSessionResourceSetupListCxtReq.list.count; i++) { for (i = 0; i < ie->value.choice.PDUSessionResourceSetupListCxtReq.list.count; i++) {
NGAP_PDUSessionResourceSetupItemCxtReq_t *item_p; NGAP_PDUSessionResourceSetupItemCxtReq_t *item_p = ie->value.choice.PDUSessionResourceSetupListCxtReq.list.array[i];
asn_dec_rval_t dec_rval;
NGAP_PDUSessionResourceSetupRequestTransfer_t *pdusessionTransfer_p = NULL;
NGAP_PDUSessionResourceSetupRequestTransferIEs_t *pdusessionTransfer_ies = NULL;
item_p = (NGAP_PDUSessionResourceSetupItemCxtReq_t *)ie->value.choice.PDUSessionResourceSetupListCxtReq.list.array[i];
msg->pdusession_param[i].pdusession_id = item_p->pDUSessionID; msg->pdusession_param[i].pdusession_id = item_p->pDUSessionID;
if (item_p->nAS_PDU != NULL) { allocCopy(&msg->pdusession_param[i].nas_pdu, *item_p->nAS_PDU);
/* Only copy NAS pdu if present */ allocCopy(&msg->pdusession_param[i].pdusessionTransfer, item_p->pDUSessionResourceSetupRequestTransfer);
msg->pdusession_param[i].nas_pdu.length = item_p->nAS_PDU->size;
msg->pdusession_param[i].nas_pdu.buffer =
malloc(sizeof(uint8_t) * item_p->nAS_PDU->size);
memcpy(msg->pdusession_param[i].nas_pdu.buffer,
item_p->nAS_PDU->buf, item_p->nAS_PDU->size);
NGAP_DEBUG("Received NAS message with the PDUSESSION setup procedure\n");
} else {
msg->pdusession_param[i].nas_pdu.length = 0;
msg->pdusession_param[i].nas_pdu.buffer = NULL;
}
dec_rval = aper_decode(NULL,
&asn_DEF_NGAP_PDUSessionResourceSetupRequestTransfer,
(void **)&pdusessionTransfer_p,
item_p->pDUSessionResourceSetupRequestTransfer.buf,
item_p->pDUSessionResourceSetupRequestTransfer.size, 0, 0);
if(dec_rval.code != RC_OK) {
NGAP_ERROR("could not decode PDUSessionResourceSetupRequestTransfer\n");
return -1;
}
for(int j=0; j< pdusessionTransfer_p->protocolIEs.list.count; j++) {
pdusessionTransfer_ies = pdusessionTransfer_p->protocolIEs.list.array[j];
switch(pdusessionTransfer_ies->id) {
/* optional PDUSessionAggregateMaximumBitRate */
case NGAP_ProtocolIE_ID_id_PDUSessionAggregateMaximumBitRate:
break;
/* mandatory UL-NGU-UP-TNLInformation */
case NGAP_ProtocolIE_ID_id_UL_NGU_UP_TNLInformation:
{
NGAP_GTPTunnel_t *gTPTunnel_p;
gTPTunnel_p = pdusessionTransfer_ies->value.choice.UPTransportLayerInformation.choice.gTPTunnel;
/* Set the transport layer address */
memcpy(msg->pdusession_param[i].upf_addr.buffer,
gTPTunnel_p->transportLayerAddress.buf, gTPTunnel_p->transportLayerAddress.size);
msg->pdusession_param[i].upf_addr.length =
gTPTunnel_p->transportLayerAddress.size * 8 - gTPTunnel_p->transportLayerAddress.bits_unused;
/* GTP tunnel endpoint ID */
OCTET_STRING_TO_INT32(&gTPTunnel_p->gTP_TEID, msg->pdusession_param[i].gtp_teid);
}
break;
/* optional AdditionalUL-NGU-UP-TNLInformation */
case NGAP_ProtocolIE_ID_id_AdditionalUL_NGU_UP_TNLInformation:
break;
/* optional DataForwardingNotPossible */
case NGAP_ProtocolIE_ID_id_DataForwardingNotPossible:
break;
/* mandatory PDUSessionType */
case NGAP_ProtocolIE_ID_id_PDUSessionType:
msg->pdusession_param[i].upf_addr.pdu_session_type = (uint8_t)pdusessionTransfer_ies->value.choice.PDUSessionType;
break;
/* optional SecurityIndication */
case NGAP_ProtocolIE_ID_id_SecurityIndication:
break;
/* optional NetworkInstance */
case NGAP_ProtocolIE_ID_id_NetworkInstance:
break;
/* mandatory QosFlowSetupRequestList */
case NGAP_ProtocolIE_ID_id_QosFlowSetupRequestList:
{
NGAP_QosFlowSetupRequestItem_t *qosFlowItem_p;
NGAP_DEBUG("QosFlowSetupRequestList.list.count %d\n", pdusessionTransfer_ies->value.choice.QosFlowSetupRequestList.list.count);
DevAssert(pdusessionTransfer_ies->value.choice.QosFlowSetupRequestList.list.count > 0);
DevAssert(pdusessionTransfer_ies->value.choice.QosFlowSetupRequestList.list.count <= NGAP_maxnoofQosFlows);
msg->pdusession_param[i].nb_qos = pdusessionTransfer_ies->value.choice.QosFlowSetupRequestList.list.count;
for(int qosIdx = 0; qosIdx < pdusessionTransfer_ies->value.choice.QosFlowSetupRequestList.list.count; qosIdx++) {
qosFlowItem_p = pdusessionTransfer_ies->value.choice.QosFlowSetupRequestList.list.array[qosIdx];
/* Set the QOS informations */
msg->pdusession_param[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){
msg->pdusession_param[i].qos[qosIdx].fiveQI =
(uint64_t)qosFlowItem_p->qosFlowLevelQosParameters.qosCharacteristics.choice.nonDynamic5QI->fiveQI;
}
}
msg->pdusession_param[i].qos[qosIdx].allocation_retention_priority.priority_level =
qosFlowItem_p->qosFlowLevelQosParameters.allocationAndRetentionPriority.priorityLevelARP;
msg->pdusession_param[i].qos[qosIdx].allocation_retention_priority.pre_emp_capability =
qosFlowItem_p->qosFlowLevelQosParameters.allocationAndRetentionPriority.pre_emptionCapability;
msg->pdusession_param[i].qos[qosIdx].allocation_retention_priority.pre_emp_vulnerability =
qosFlowItem_p->qosFlowLevelQosParameters.allocationAndRetentionPriority.pre_emptionVulnerability;
}
}
break;
/* optional CommonNetworkInstance */
case NGAP_ProtocolIE_ID_id_CommonNetworkInstance:
break;
default:
NGAP_ERROR("Not found protocolIEs id %ld\n", pdusessionTransfer_ies->id);
return -1;
}
} }
} /* for i... */
} else {/* ie != NULL */
NGAP_ERROR("Not found NGAP_ProtocolIE_ID_id_PDUSessionResourceSetupListCxtReq\n");
} }
/* id-AllowedNSSAI */ /* id-AllowedNSSAI */
...@@ -1067,25 +779,8 @@ int ngap_gNB_handle_initial_context_request(uint32_t assoc_id, ...@@ -1067,25 +779,8 @@ int ngap_gNB_handle_initial_context_request(uint32_t assoc_id,
//DevAssert(ie->value.choice.AllowedNSSAI.list.count > 0); //DevAssert(ie->value.choice.AllowedNSSAI.list.count > 0);
//DevAssert(ie->value.choice.AllowedNSSAI.list.count <= NGAP_maxnoofAllowedS_NSSAIs); //DevAssert(ie->value.choice.AllowedNSSAI.list.count <= NGAP_maxnoofAllowedS_NSSAIs);
if (ie == NULL) { AssertFatal(ie, "AllowedNSSAI not present, forging 2 NSSAI\n");
NGAP_WARN("AllowedNSSAI not present, forging 2 NSSAI\n");
msg->nb_allowed_nssais = 2;
msg->allowed_nssai[0].sST = 01;
msg->allowed_nssai[0].sD_flag = 1;
msg->allowed_nssai[0].sD[0] = 01;
msg->allowed_nssai[0].sD[1] = 02;
msg->allowed_nssai[0].sD[2] = 03;
msg->allowed_nssai[1].sST = 01;
msg->allowed_nssai[1].sD_flag = 1;
msg->allowed_nssai[1].sD[0] = 00;//11;
msg->allowed_nssai[1].sD[1] = 00;//22;
msg->allowed_nssai[1].sD[2] = 01;//33;
} else {
NGAP_INFO("AllowedNSSAI.list.count %d\n", ie->value.choice.AllowedNSSAI.list.count); NGAP_INFO("AllowedNSSAI.list.count %d\n", ie->value.choice.AllowedNSSAI.list.count);
msg->nb_allowed_nssais = ie->value.choice.AllowedNSSAI.list.count; msg->nb_allowed_nssais = ie->value.choice.AllowedNSSAI.list.count;
...@@ -1096,58 +791,36 @@ int ngap_gNB_handle_initial_context_request(uint32_t assoc_id, ...@@ -1096,58 +791,36 @@ int ngap_gNB_handle_initial_context_request(uint32_t assoc_id,
if(allow_nssai_item_p->s_NSSAI.sD != NULL) { if(allow_nssai_item_p->s_NSSAI.sD != NULL) {
msg->allowed_nssai[i].sD_flag = 1; msg->allowed_nssai[i].sD_flag = 1;
msg->allowed_nssai[i].sD[0] = allow_nssai_item_p->s_NSSAI.sD->buf[0]; memcpy(msg->allowed_nssai[i].sD, allow_nssai_item_p->s_NSSAI.sD, sizeof(msg->allowed_nssai[i].sD));
msg->allowed_nssai[i].sD[1] = allow_nssai_item_p->s_NSSAI.sD->buf[1];
msg->allowed_nssai[i].sD[2] = allow_nssai_item_p->s_NSSAI.sD->buf[2];
}
} }
} }
//} else {/* ie != NULL */
// return -1;
//}
/* id-UESecurityCapabilities */ /* id-UESecurityCapabilities */
NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_InitialContextSetupRequestIEs_t, ie, container, NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_InitialContextSetupRequestIEs_t, ie, container,
NGAP_ProtocolIE_ID_id_UESecurityCapabilities, true); NGAP_ProtocolIE_ID_id_UESecurityCapabilities, true);
if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
msg->security_capabilities.nRencryption_algorithms = msg->security_capabilities.nRencryption_algorithms =
BIT_STRING_to_uint16(&ie->value.choice.UESecurityCapabilities.nRencryptionAlgorithms); BIT_STRING_to_uint16(&ie->value.choice.UESecurityCapabilities.nRencryptionAlgorithms);
msg->security_capabilities.nRintegrity_algorithms = msg->security_capabilities.nRintegrity_algorithms =
BIT_STRING_to_uint16(&ie->value.choice.UESecurityCapabilities.nRintegrityProtectionAlgorithms); BIT_STRING_to_uint16(&ie->value.choice.UESecurityCapabilities.nRintegrityProtectionAlgorithms);
msg->security_capabilities.eUTRAencryption_algorithms = msg->security_capabilities.eUTRAencryption_algorithms =
BIT_STRING_to_uint16(&ie->value.choice.UESecurityCapabilities.eUTRAencryptionAlgorithms); BIT_STRING_to_uint16(&ie->value.choice.UESecurityCapabilities.eUTRAencryptionAlgorithms);
msg->security_capabilities.eUTRAintegrity_algorithms = msg->security_capabilities.eUTRAintegrity_algorithms = BIT_STRING_to_uint16(&ie->value.choice.UESecurityCapabilities.eUTRAintegrityProtectionAlgorithms);
BIT_STRING_to_uint16(&ie->value.choice.UESecurityCapabilities.eUTRAintegrityProtectionAlgorithms);
} else {/* ie != NULL */
return -1;
}
/* id-SecurityKey : Copy the security key */ /* id-SecurityKey : Copy the security key */
NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_InitialContextSetupRequestIEs_t, ie, container, NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_InitialContextSetupRequestIEs_t, ie, container, NGAP_ProtocolIE_ID_id_SecurityKey, true);
NGAP_ProtocolIE_ID_id_SecurityKey, true); memcpy(&msg->security_key, ie->value.choice.SecurityKey.buf, ie->value.choice.SecurityKey.size);
if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
memcpy(&msg->security_key,
ie->value.choice.SecurityKey.buf, ie->value.choice.SecurityKey.size);
} else {/* ie != NULL */
return -1;
}
/* id-MobilityRestrictionList */ /* id-MobilityRestrictionList */
NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_InitialContextSetupRequestIEs_t, ie, container, NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_InitialContextSetupRequestIEs_t, ie, container, NGAP_ProtocolIE_ID_id_MobilityRestrictionList, false);
NGAP_ProtocolIE_ID_id_MobilityRestrictionList, false);
if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
NGAP_MobilityRestrictionList_t *mobility_rest_list_p = NULL; NGAP_MobilityRestrictionList_t *mobility_rest_list_p = NULL;
mobility_rest_list_p = &ie->value.choice.MobilityRestrictionList; mobility_rest_list_p = &ie->value.choice.MobilityRestrictionList;
msg->mobility_restriction_flag = 1; msg->mobility_restriction_flag = 1;
TBCD_TO_MCC_MNC(&mobility_rest_list_p->servingPLMN, TBCD_TO_MCC_MNC(
msg->mobility_restriction.serving_plmn.mcc, &mobility_rest_list_p->servingPLMN, msg->mobility_restriction.serving_plmn.mcc, msg->mobility_restriction.serving_plmn.mnc, msg->mobility_restriction.serving_plmn.mnc_digit_length);
msg->mobility_restriction.serving_plmn.mnc,
msg->mobility_restriction.serving_plmn.mnc_digit_length);
} }
...@@ -1155,29 +828,19 @@ int ngap_gNB_handle_initial_context_request(uint32_t assoc_id, ...@@ -1155,29 +828,19 @@ int ngap_gNB_handle_initial_context_request(uint32_t assoc_id,
NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_InitialContextSetupRequestIEs_t, ie, container, NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_InitialContextSetupRequestIEs_t, ie, container,
NGAP_ProtocolIE_ID_id_NAS_PDU, false); NGAP_ProtocolIE_ID_id_NAS_PDU, false);
if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ if (ie)
if(ie->value.choice.NAS_PDU.size > 0) { allocCopy(&msg->nas_pdu, ie->value.choice.NAS_PDU);
msg->nas_pdu_flag = 1;
msg->nas_pdu.length = ie->value.choice.NAS_PDU.size;
msg->nas_pdu.buffer = malloc(sizeof(uint8_t) * ie->value.choice.NAS_PDU.size);
memcpy(msg->nas_pdu.buffer,
ie->value.choice.NAS_PDU.buf, ie->value.choice.NAS_PDU.size);
}
}
itti_send_msg_to_task(TASK_RRC_GNB, ue_desc_p->gNB_instance->instance, message_p); itti_send_msg_to_task(TASK_RRC_GNB, ue_desc_p->gNB_instance->instance, message_p);
return 0; return 0;
} }
static static
int ngap_gNB_handle_ue_context_release_command(uint32_t assoc_id, int ngap_gNB_handle_ue_context_release_command(uint32_t assoc_id,
uint32_t stream, uint32_t stream,
NGAP_NGAP_PDU_t *pdu) { NGAP_NGAP_PDU_t *pdu) {
ngap_gNB_amf_data_t *amf_desc_p = NULL; ngap_gNB_amf_data_t *amf_desc_p = NULL;
ngap_gNB_ue_context_t *ue_desc_p = NULL;
MessageDef *message_p = NULL; MessageDef *message_p = NULL;
uint64_t amf_ue_ngap_id; uint64_t amf_ue_ngap_id;
NGAP_RAN_UE_NGAP_ID_t gnb_ue_ngap_id; NGAP_RAN_UE_NGAP_ID_t gnb_ue_ngap_id;
...@@ -1195,15 +858,14 @@ int ngap_gNB_handle_ue_context_release_command(uint32_t assoc_id, ...@@ -1195,15 +858,14 @@ int ngap_gNB_handle_ue_context_release_command(uint32_t assoc_id,
NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_UEContextReleaseCommand_IEs_t, ie, container, NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_UEContextReleaseCommand_IEs_t, ie, container,
NGAP_ProtocolIE_ID_id_UE_NGAP_IDs, true); NGAP_ProtocolIE_ID_id_UE_NGAP_IDs, true);
if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
switch (ie->value.choice.UE_NGAP_IDs.present) { switch (ie->value.choice.UE_NGAP_IDs.present) {
case NGAP_UE_NGAP_IDs_PR_uE_NGAP_ID_pair: case NGAP_UE_NGAP_IDs_PR_uE_NGAP_ID_pair:
gnb_ue_ngap_id = ie->value.choice.UE_NGAP_IDs.choice.uE_NGAP_ID_pair->rAN_UE_NGAP_ID; gnb_ue_ngap_id = ie->value.choice.UE_NGAP_IDs.choice.uE_NGAP_ID_pair->rAN_UE_NGAP_ID;
asn_INTEGER2ulong(&(ie->value.choice.UE_NGAP_IDs.choice.uE_NGAP_ID_pair->aMF_UE_NGAP_ID), &amf_ue_ngap_id); asn_INTEGER2ulong(&(ie->value.choice.UE_NGAP_IDs.choice.uE_NGAP_ID_pair->aMF_UE_NGAP_ID), &amf_ue_ngap_id);
ngap_gNB_ue_context_t *ue_desc_p = ngap_get_ue_context(gnb_ue_ngap_id);
if ((ue_desc_p = ngap_gNB_get_ue_context(amf_desc_p->ngap_gNB_instance, if (!ue_desc_p) {
gnb_ue_ngap_id)) == NULL) { NGAP_ERROR(
NGAP_ERROR("[SCTP %d] Received UE context release command for non " "[SCTP %d] Received UE context release command for non "
"existing UE context 0x%06lx\n", "existing UE context 0x%06lx\n",
assoc_id, assoc_id,
gnb_ue_ngap_id); gnb_ue_ngap_id);
...@@ -1234,9 +896,6 @@ int ngap_gNB_handle_ue_context_release_command(uint32_t assoc_id, ...@@ -1234,9 +896,6 @@ int ngap_gNB_handle_ue_context_release_command(uint32_t assoc_id,
NGAP_ERROR("NGAP_UE_CONTEXT_RELEASE_COMMAND not processed, missing info elements"); NGAP_ERROR("NGAP_UE_CONTEXT_RELEASE_COMMAND not processed, missing info elements");
return -1; return -1;
} }
} else {
return -1;
}
NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_UEContextReleaseCommand_IEs_t, ie, container, NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_UEContextReleaseCommand_IEs_t, ie, container,
NGAP_ProtocolIE_ID_id_Cause, true); NGAP_ProtocolIE_ID_id_Cause, true);
...@@ -1253,7 +912,7 @@ int ngap_gNB_handle_pdusession_setup_request(uint32_t assoc_id, ...@@ -1253,7 +912,7 @@ int ngap_gNB_handle_pdusession_setup_request(uint32_t assoc_id,
uint64_t amf_ue_ngap_id; uint64_t amf_ue_ngap_id;
NGAP_RAN_UE_NGAP_ID_t ran_ue_ngap_id; NGAP_RAN_UE_NGAP_ID_t ran_ue_ngap_id;
ngap_gNB_amf_data_t *amf_desc_p = NULL; ngap_gNB_amf_data_t *amf_desc_p = NULL;
ngap_gNB_ue_context_t *ue_desc_p = NULL;
NGAP_PDUSessionResourceSetupRequest_t *container; NGAP_PDUSessionResourceSetupRequest_t *container;
NGAP_PDUSessionResourceSetupRequestIEs_t *ie; NGAP_PDUSessionResourceSetupRequestIEs_t *ie;
DevAssert(pdu != NULL); DevAssert(pdu != NULL);
...@@ -1266,40 +925,21 @@ int ngap_gNB_handle_pdusession_setup_request(uint32_t assoc_id, ...@@ -1266,40 +925,21 @@ int ngap_gNB_handle_pdusession_setup_request(uint32_t assoc_id,
} }
/* id-AMF-UE-NGAP-ID */ /* id-AMF-UE-NGAP-ID */
NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_PDUSessionResourceSetupRequestIEs_t, ie, container, NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_PDUSessionResourceSetupRequestIEs_t, ie, container, NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID, true);
NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID, true);
if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
asn_INTEGER2ulong(&(ie->value.choice.AMF_UE_NGAP_ID), &amf_ue_ngap_id); asn_INTEGER2ulong(&(ie->value.choice.AMF_UE_NGAP_ID), &amf_ue_ngap_id);
} else {
return -1;
}
/* id-gNB-UE-NGAP-ID */ /* id-gNB-UE-NGAP-ID */
NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_PDUSessionResourceSetupRequestIEs_t, ie, container, NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_PDUSessionResourceSetupRequestIEs_t, ie, container, NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID, true);
NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID, true);
if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
ran_ue_ngap_id = ie->value.choice.RAN_UE_NGAP_ID; ran_ue_ngap_id = ie->value.choice.RAN_UE_NGAP_ID;
} else {
return -1;
}
if ((ue_desc_p = ngap_gNB_get_ue_context(amf_desc_p->ngap_gNB_instance, ngap_gNB_ue_context_t *ue_desc_p = ngap_get_ue_context(ran_ue_ngap_id);
ran_ue_ngap_id)) == NULL) { if (!ue_desc_p) {
NGAP_ERROR("[SCTP %d] Received pdu session resource setup request for non " NGAP_ERROR("[SCTP %d] Received pdu session resource setup request for non "
"existing UE context 0x%06lx\n", assoc_id, "existing UE context 0x%06lx\n", assoc_id,
ran_ue_ngap_id); ran_ue_ngap_id);
return -1; return -1;
} }
/* 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;
// }
ue_desc_p->rx_stream = stream; ue_desc_p->rx_stream = stream;
if ( ue_desc_p->amf_ue_ngap_id != amf_ue_ngap_id) { if ( ue_desc_p->amf_ue_ngap_id != amf_ue_ngap_id) {
...@@ -1309,8 +949,7 @@ int ngap_gNB_handle_pdusession_setup_request(uint32_t assoc_id, ...@@ -1309,8 +949,7 @@ int ngap_gNB_handle_pdusession_setup_request(uint32_t assoc_id,
MessageDef * message_p = itti_alloc_new_message(TASK_NGAP, 0, NGAP_PDUSESSION_SETUP_REQ); MessageDef * message_p = itti_alloc_new_message(TASK_NGAP, 0, NGAP_PDUSESSION_SETUP_REQ);
ngap_pdusession_setup_req_t * msg=&NGAP_PDUSESSION_SETUP_REQ(message_p); ngap_pdusession_setup_req_t * msg=&NGAP_PDUSESSION_SETUP_REQ(message_p);
msg->ue_initial_id = ue_desc_p->ue_initial_id; memset(msg, 0, sizeof(*msg));
ue_desc_p->ue_initial_id = 0;
msg->gNB_ue_ngap_id = ue_desc_p->gNB_ue_ngap_id; msg->gNB_ue_ngap_id = ue_desc_p->gNB_ue_ngap_id;
msg->amf_ue_ngap_id = ue_desc_p->amf_ue_ngap_id; msg->amf_ue_ngap_id = ue_desc_p->amf_ue_ngap_id;
...@@ -1325,147 +964,26 @@ int ngap_gNB_handle_pdusession_setup_request(uint32_t assoc_id, ...@@ -1325,147 +964,26 @@ int ngap_gNB_handle_pdusession_setup_request(uint32_t assoc_id,
NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_PDUSessionResourceSetupRequestIEs_t, ie, container, NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_PDUSessionResourceSetupRequestIEs_t, ie, container,
NGAP_ProtocolIE_ID_id_PDUSessionResourceSetupListSUReq, true); NGAP_ProtocolIE_ID_id_PDUSessionResourceSetupListSUReq, true);
if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ msg->nb_pdusessions_tosetup = ie->value.choice.PDUSessionResourceSetupListSUReq.list.count;
msg->nb_pdusessions_tosetup =
ie->value.choice.PDUSessionResourceSetupListSUReq.list.count;
for (int i = 0; i < ie->value.choice.PDUSessionResourceSetupListSUReq.list.count; i++) { for (int i = 0; i < ie->value.choice.PDUSessionResourceSetupListSUReq.list.count; i++) {
NGAP_PDUSessionResourceSetupItemSUReq_t *item_p; NGAP_PDUSessionResourceSetupItemSUReq_t *item_p = ie->value.choice.PDUSessionResourceSetupListSUReq.list.array[i];
asn_dec_rval_t dec_rval;
NGAP_PDUSessionResourceSetupRequestTransfer_t *pdusessionTransfer_p = NULL;
NGAP_PDUSessionResourceSetupRequestTransferIEs_t *pdusessionTransfer_ies = NULL;
// PDU session ID
item_p = (NGAP_PDUSessionResourceSetupItemSUReq_t *)ie->value.choice.PDUSessionResourceSetupListSUReq.list.array[i];
msg->pdusession_setup_params[i].pdusession_id = item_p->pDUSessionID; msg->pdusession_setup_params[i].pdusession_id = item_p->pDUSessionID;
// S-NSSAI // S-NSSAI
OCTET_STRING_TO_INT8(&item_p->s_NSSAI.sST, msg->allowed_nssai[i].sST); OCTET_STRING_TO_INT8(&item_p->s_NSSAI.sST, msg->allowed_nssai[i].sST);
if(item_p->s_NSSAI.sD != NULL) { if (item_p->s_NSSAI.sD != NULL) {
msg->allowed_nssai[i].sD_flag = 1; msg->allowed_nssai[i].sD_flag = 1;
msg->allowed_nssai[i].sD[0] = item_p->s_NSSAI.sD->buf[0]; msg->allowed_nssai[i].sD[0] = item_p->s_NSSAI.sD->buf[0];
msg->allowed_nssai[i].sD[1] = item_p->s_NSSAI.sD->buf[1]; msg->allowed_nssai[i].sD[1] = item_p->s_NSSAI.sD->buf[1];
msg->allowed_nssai[i].sD[2] = item_p->s_NSSAI.sD->buf[2]; msg->allowed_nssai[i].sD[2] = item_p->s_NSSAI.sD->buf[2];
} }
// check for the NAS PDU allocCopy(&msg->pdusession_setup_params[i].nas_pdu, *item_p->pDUSessionNAS_PDU);
if (item_p->pDUSessionNAS_PDU->size > 0 ) { allocCopy(&msg->pdusession_setup_params[i].pdusessionTransfer, item_p->pDUSessionResourceSetupRequestTransfer);
msg->pdusession_setup_params[i].nas_pdu.length = item_p->pDUSessionNAS_PDU->size;
msg->pdusession_setup_params[i].nas_pdu.buffer = malloc(sizeof(uint8_t) * item_p->pDUSessionNAS_PDU->size);
memcpy(msg->pdusession_setup_params[i].nas_pdu.buffer,
item_p->pDUSessionNAS_PDU->buf, item_p->pDUSessionNAS_PDU->size);
// NGAP_INFO("received a NAS PDU with size %d (%02x.%02x)\n",msg->pdusession_setup_params[i].nas_pdu.length, item_p->nAS_PDU.buf[0], item_p->nAS_PDU.buf[1]);
} else {
msg->pdusession_setup_params[i].nas_pdu.length = 0;
msg->pdusession_setup_params[i].nas_pdu.buffer = NULL;
NGAP_WARN("NAS PDU is not provided, generate a PDUSESSION_SETUP Failure (TBD) back to AMF \n");
}
dec_rval = aper_decode(NULL,
&asn_DEF_NGAP_PDUSessionResourceSetupRequestTransfer,
(void **)&pdusessionTransfer_p,
item_p->pDUSessionResourceSetupRequestTransfer.buf,
item_p->pDUSessionResourceSetupRequestTransfer.size, 0, 0);
if(dec_rval.code != RC_OK) {
NGAP_ERROR("could not decode PDUSessionResourceSetupRequestTransfer\n");
return -1;
}
for(int j=0; j< pdusessionTransfer_p->protocolIEs.list.count; j++) {
pdusessionTransfer_ies = pdusessionTransfer_p->protocolIEs.list.array[j];
switch(pdusessionTransfer_ies->id) {
/* optional PDUSessionAggregateMaximumBitRate */
case NGAP_ProtocolIE_ID_id_PDUSessionAggregateMaximumBitRate:
break;
/* mandatory UL-NGU-UP-TNLInformation */
case NGAP_ProtocolIE_ID_id_UL_NGU_UP_TNLInformation:
{
NGAP_GTPTunnel_t *gTPTunnel_p;
gTPTunnel_p = pdusessionTransfer_ies->value.choice.UPTransportLayerInformation.choice.gTPTunnel;
/* The transport layer address for the IP packets */
OCTET_STRING_TO_INT32(&gTPTunnel_p->gTP_TEID, msg->pdusession_setup_params[i].gtp_teid);
msg->pdusession_setup_params[i].upf_addr.length =
gTPTunnel_p->transportLayerAddress.size * 8 - gTPTunnel_p->transportLayerAddress.bits_unused;
memcpy(msg->pdusession_setup_params[i].upf_addr.buffer ,
gTPTunnel_p->transportLayerAddress.buf, gTPTunnel_p->transportLayerAddress.size);
}
break;
/* optional AdditionalUL-NGU-UP-TNLInformation */
case NGAP_ProtocolIE_ID_id_AdditionalUL_NGU_UP_TNLInformation:
break;
/* optional DataForwardingNotPossible */
case NGAP_ProtocolIE_ID_id_DataForwardingNotPossible:
break;
/* mandatory PDUSessionType */
case NGAP_ProtocolIE_ID_id_PDUSessionType:
msg->pdusession_setup_params[i].upf_addr.pdu_session_type = (uint8_t)pdusessionTransfer_ies->value.choice.PDUSessionType;
break;
/* optional SecurityIndication */
case NGAP_ProtocolIE_ID_id_SecurityIndication:
break;
/* optional NetworkInstance */
case NGAP_ProtocolIE_ID_id_NetworkInstance:
break;
/* mandatory QosFlowSetupRequestList */
case NGAP_ProtocolIE_ID_id_QosFlowSetupRequestList:
{
NGAP_QosFlowSetupRequestItem_t *qosFlowItem_p;
NGAP_DEBUG("servedGUAMIs.list.count %d\n", pdusessionTransfer_ies->value.choice.QosFlowSetupRequestList.list.count);
DevAssert(pdusessionTransfer_ies->value.choice.QosFlowSetupRequestList.list.count > 0);
DevAssert(pdusessionTransfer_ies->value.choice.QosFlowSetupRequestList.list.count <= NGAP_maxnoofQosFlows);
msg->pdusession_setup_params[i].nb_qos = pdusessionTransfer_ies->value.choice.QosFlowSetupRequestList.list.count;
for(int qosIdx = 0; qosIdx < pdusessionTransfer_ies->value.choice.QosFlowSetupRequestList.list.count; qosIdx++){
qosFlowItem_p = pdusessionTransfer_ies->value.choice.QosFlowSetupRequestList.list.array[qosIdx];
/* Set the QOS informations */
msg->pdusession_setup_params[i].qos[qosIdx].qfi = (uint8_t)qosFlowItem_p->qosFlowIdentifier;
if(qosFlowItem_p->qosFlowLevelQosParameters.qosCharacteristics.present == NGAP_QosCharacteristics_PR_nonDynamic5QI){
msg->pdusession_setup_params[i].qos[qosIdx].fiveQI_type = non_dynamic;
if(qosFlowItem_p->qosFlowLevelQosParameters.qosCharacteristics.choice.nonDynamic5QI != NULL){
msg->pdusession_setup_params[i].qos[qosIdx].fiveQI =
(uint64_t)qosFlowItem_p->qosFlowLevelQosParameters.qosCharacteristics.choice.nonDynamic5QI->fiveQI;
} }
} else if (qosFlowItem_p->qosFlowLevelQosParameters.qosCharacteristics.present == NGAP_QosCharacteristics_PR_dynamic5QI)
{
msg->pdusession_setup_params[i].qos[qosIdx].fiveQI_type = dynamic;
}
msg->pdusession_setup_params[i].qos[qosIdx].allocation_retention_priority.priority_level =
qosFlowItem_p->qosFlowLevelQosParameters.allocationAndRetentionPriority.priorityLevelARP;
msg->pdusession_setup_params[i].qos[qosIdx].allocation_retention_priority.pre_emp_capability =
qosFlowItem_p->qosFlowLevelQosParameters.allocationAndRetentionPriority.pre_emptionCapability;
msg->pdusession_setup_params[i].qos[qosIdx].allocation_retention_priority.pre_emp_vulnerability =
qosFlowItem_p->qosFlowLevelQosParameters.allocationAndRetentionPriority.pre_emptionVulnerability;
}
}
break;
/* optional CommonNetworkInstance */
case NGAP_ProtocolIE_ID_id_CommonNetworkInstance:
break;
default:
NGAP_ERROR("could not found protocolIEs id %ld\n", pdusessionTransfer_ies->id);
return -1;
}
}/* for j... */
} /* for i... */
itti_send_msg_to_task(TASK_RRC_GNB, ue_desc_p->gNB_instance->instance, message_p); itti_send_msg_to_task(TASK_RRC_GNB, ue_desc_p->gNB_instance->instance, message_p);
}else {/* ie == NULL */
NGAP_ERROR("could not found NGAP_ProtocolIE_ID_id_PDUSessionResourceSetupListSUReq\n");
return -1;
}
return 0; return 0;
} }
...@@ -1507,31 +1025,26 @@ int ngap_gNB_handle_paging(uint32_t assoc_id, ...@@ -1507,31 +1025,26 @@ int ngap_gNB_handle_paging(uint32_t assoc_id,
MessageDef *message_p = itti_alloc_new_message(TASK_NGAP, 0, NGAP_PAGING_IND); MessageDef *message_p = itti_alloc_new_message(TASK_NGAP, 0, NGAP_PAGING_IND);
ngap_paging_ind_t * msg=&NGAP_PAGING_IND(message_p); ngap_paging_ind_t * msg=&NGAP_PAGING_IND(message_p);
memset(msg, 0, sizeof(*msg));
/* convert NGAP_PagingIEs_t to ngap_paging_ind_t */ /* convert NGAP_PagingIEs_t to ngap_paging_ind_t */
/* id-UEIdentityIndexValue : convert UE Identity Index value */ /* id-UEIdentityIndexValue : convert UE Identity Index value */
NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_PagingIEs_t, ie, container, NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_PagingIEs_t, ie, container, NGAP_ProtocolIE_ID_id_UEPagingIdentity, true);
NGAP_ProtocolIE_ID_id_UEPagingIdentity, true);
if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ struct NGAP_FiveG_S_TMSI *fiveG_S_TMSI = ie->value.choice.UEPagingIdentity.choice.fiveG_S_TMSI;
OCTET_STRING_TO_INT16(&ie->value.choice.UEPagingIdentity.choice.fiveG_S_TMSI->aMFSetID, msg->ue_paging_identity.s_tmsi.amf_set_id); OCTET_STRING_TO_INT16(&fiveG_S_TMSI->aMFSetID, msg->ue_paging_identity.s_tmsi.amf_set_id);
OCTET_STRING_TO_INT8(&ie->value.choice.UEPagingIdentity.choice.fiveG_S_TMSI->aMFPointer, msg->ue_paging_identity.s_tmsi.amf_pointer); OCTET_STRING_TO_INT8(&fiveG_S_TMSI->aMFPointer, msg->ue_paging_identity.s_tmsi.amf_pointer);
OCTET_STRING_TO_INT32(&ie->value.choice.UEPagingIdentity.choice.fiveG_S_TMSI->fiveG_TMSI, msg->ue_paging_identity.s_tmsi.m_tmsi); OCTET_STRING_TO_INT32(&fiveG_S_TMSI->fiveG_TMSI, msg->ue_paging_identity.s_tmsi.m_tmsi);
NGAP_DEBUG("[SCTP %d] Received Paging Identity amf_set_id %d, amf_pointer %d, m_tmsi %d\n", NGAP_DEBUG("[SCTP %d] Received Paging Identity amf_set_id %d, amf_pointer %d, m_tmsi %d\n",
assoc_id, assoc_id,
msg->ue_paging_identity.s_tmsi.amf_set_id, msg->ue_paging_identity.s_tmsi.amf_set_id,
msg->ue_paging_identity.s_tmsi.amf_pointer, msg->ue_paging_identity.s_tmsi.amf_pointer,
msg->ue_paging_identity.s_tmsi.m_tmsi); msg->ue_paging_identity.s_tmsi.m_tmsi);
} else {
return -1;
}
msg->paging_drx = NGAP_PAGING_DRX_256; msg->paging_drx = NGAP_PAGING_DRX_256;
/* id-pagingDRX */ /* id-pagingDRX */
NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_PagingIEs_t, ie, container, NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_PagingIEs_t, ie, container, NGAP_ProtocolIE_ID_id_PagingDRX, false);
NGAP_ProtocolIE_ID_id_PagingDRX, false);
/* optional */ /* optional */
if (ie) { if (ie) {
...@@ -1540,31 +1053,19 @@ int ngap_gNB_handle_paging(uint32_t assoc_id, ...@@ -1540,31 +1053,19 @@ int ngap_gNB_handle_paging(uint32_t assoc_id,
msg->paging_drx = NGAP_PAGING_DRX_256; msg->paging_drx = NGAP_PAGING_DRX_256;
} }
memset (&msg->plmn_identity[0], 0, sizeof(plmn_identity_t)*256);
memset (&msg->tac[0], 0, sizeof(int16_t)*256);
msg->tai_size = 0;
/* id-TAIList */ /* id-TAIList */
NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_PagingIEs_t, ie, container, NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_PagingIEs_t, ie, container,
NGAP_ProtocolIE_ID_id_TAIListForPaging, true); NGAP_ProtocolIE_ID_id_TAIListForPaging, true);
if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
NGAP_INFO("[SCTP %d] Received Paging taiList For Paging: count %d\n", assoc_id, ie->value.choice.TAIListForPaging.list.count); NGAP_INFO("[SCTP %d] Received Paging taiList For Paging: count %d\n", assoc_id, ie->value.choice.TAIListForPaging.list.count);
for (int i = 0; i < ie->value.choice.TAIListForPaging.list.count; i++) { for (int i = 0; i < ie->value.choice.TAIListForPaging.list.count; i++) {
NGAP_TAIListForPagingItem_t *item_p; NGAP_TAIListForPagingItem_t *item_p;
item_p = (NGAP_TAIListForPagingItem_t *)ie->value.choice.TAIListForPaging.list.array[i]; item_p = (NGAP_TAIListForPagingItem_t *)ie->value.choice.TAIListForPaging.list.array[i];
TBCD_TO_MCC_MNC(&(item_p->tAI.pLMNIdentity), msg->plmn_identity[i].mcc, TBCD_TO_MCC_MNC(&(item_p->tAI.pLMNIdentity), msg->plmn_identity[i].mcc, msg->plmn_identity[i].mnc, msg->plmn_identity[i].mnc_digit_length);
msg->plmn_identity[i].mnc,
msg->plmn_identity[i].mnc_digit_length);
OCTET_STRING_TO_INT16(&(item_p->tAI.tAC), msg->tac[i]); OCTET_STRING_TO_INT16(&(item_p->tAI.tAC), msg->tac[i]);
msg->tai_size++; msg->tai_size++;
NGAP_DEBUG("[SCTP %d] Received Paging: MCC %d, MNC %d, TAC %d\n", assoc_id, NGAP_DEBUG("[SCTP %d] Received Paging: MCC %d, MNC %d, TAC %d\n", assoc_id, msg->plmn_identity[i].mcc, msg->plmn_identity[i].mnc, msg->tac[i]);
msg->plmn_identity[i].mcc,
msg->plmn_identity[i].mnc,
msg->tac[i]);
}
} else {
return -1;
} }
//paging parameter values //paging parameter values
...@@ -1579,14 +1080,9 @@ int ngap_gNB_handle_paging(uint32_t assoc_id, ...@@ -1579,14 +1080,9 @@ int ngap_gNB_handle_paging(uint32_t assoc_id,
return 0; return 0;
} }
static static int ngap_gNB_handle_pdusession_modify_request(uint32_t assoc_id, uint32_t stream, NGAP_NGAP_PDU_t *pdu)
int ngap_gNB_handle_pdusession_modify_request(uint32_t assoc_id, {
uint32_t stream,
NGAP_NGAP_PDU_t *pdu) {
int i, nb_of_pdusessions_failed;
ngap_gNB_amf_data_t *amf_desc_p = NULL; ngap_gNB_amf_data_t *amf_desc_p = NULL;
ngap_gNB_ue_context_t *ue_desc_p = NULL;
NGAP_PDUSessionResourceModifyRequest_t *container; NGAP_PDUSessionResourceModifyRequest_t *container;
NGAP_PDUSessionResourceModifyRequestIEs_t *ie; NGAP_PDUSessionResourceModifyRequestIEs_t *ie;
NGAP_RAN_UE_NGAP_ID_t gnb_ue_ngap_id; NGAP_RAN_UE_NGAP_ID_t gnb_ue_ngap_id;
...@@ -1614,184 +1110,69 @@ int ngap_gNB_handle_pdusession_modify_request(uint32_t assoc_id, ...@@ -1614,184 +1110,69 @@ int ngap_gNB_handle_pdusession_modify_request(uint32_t assoc_id,
NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_PDUSessionResourceModifyRequestIEs_t, ie, container, NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_PDUSessionResourceModifyRequestIEs_t, ie, container,
NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID, true); NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID, true);
if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
gnb_ue_ngap_id = ie->value.choice.RAN_UE_NGAP_ID; gnb_ue_ngap_id = ie->value.choice.RAN_UE_NGAP_ID;
} else { ngap_gNB_ue_context_t *ue_desc_p = ngap_get_ue_context(gnb_ue_ngap_id);
return -1; if (!ue_desc_p) {
} NGAP_ERROR(
"[SCTP %d] Received PDUSession Resource modify request for non "
if ((ue_desc_p = ngap_gNB_get_ue_context(amf_desc_p->ngap_gNB_instance, "existing UE context 0x%08lx\n",
gnb_ue_ngap_id)) == NULL) { assoc_id,
NGAP_ERROR("[SCTP %d] Received PDUSession Resource modify request for non "
"existing UE context 0x%08lx\n", assoc_id,
gnb_ue_ngap_id); gnb_ue_ngap_id);
return -1; return -1;
} }
ue_desc_p->rx_stream = stream; ue_desc_p->rx_stream = stream;
/* id-PDUSessionResourceModifyListModReq */
NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_PDUSessionResourceModifyRequestIEs_t, ie, container, NGAP_ProtocolIE_ID_id_PDUSessionResourceModifyListModReq, true);
if (ue_desc_p->amf_ue_ngap_id != amf_ue_ngap_id) { if (ue_desc_p->amf_ue_ngap_id != amf_ue_ngap_id) {
NGAP_WARN("UE context amf_ue_ngap_id is different form that of the message (%ld != %ld)", NGAP_WARN("UE context amf_ue_ngap_id is different form that of the message (%ld != %ld)",
(uint64_t)ue_desc_p->amf_ue_ngap_id, amf_ue_ngap_id); (uint64_t)ue_desc_p->amf_ue_ngap_id, amf_ue_ngap_id);
MessageDef *message_p = itti_alloc_new_message (TASK_RRC_GNB, 0, NGAP_PDUSESSION_MODIFY_RESP); MessageDef *message_p = itti_alloc_new_message (TASK_RRC_GNB, 0, NGAP_PDUSESSION_MODIFY_RESP);
ngap_pdusession_modify_resp_t* msg=&NGAP_PDUSESSION_MODIFY_RESP(message_p); ngap_pdusession_modify_resp_t* msg=&NGAP_PDUSESSION_MODIFY_RESP(message_p);
memset(msg, 0, sizeof(*msg));
msg->gNB_ue_ngap_id = gnb_ue_ngap_id; msg->gNB_ue_ngap_id = gnb_ue_ngap_id;
NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_PDUSessionResourceModifyRequestIEs_t, ie, container, for (int nb_of_pdusessions_failed = 0; nb_of_pdusessions_failed < ie->value.choice.PDUSessionResourceModifyListModReq.list.count; nb_of_pdusessions_failed++) {
NGAP_ProtocolIE_ID_id_PDUSessionResourceModifyListModReq, true);
if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
for(nb_of_pdusessions_failed = 0; nb_of_pdusessions_failed < ie->value.choice.PDUSessionResourceModifyListModReq.list.count; nb_of_pdusessions_failed++) {
NGAP_PDUSessionResourceModifyItemModReq_t *item_p; NGAP_PDUSessionResourceModifyItemModReq_t *item_p;
item_p = (NGAP_PDUSessionResourceModifyItemModReq_t *)ie->value.choice.PDUSessionResourceModifyListModReq.list.array[nb_of_pdusessions_failed]; item_p = (NGAP_PDUSessionResourceModifyItemModReq_t *)ie->value.choice.PDUSessionResourceModifyListModReq.list.array[nb_of_pdusessions_failed];
pdusession_failed_t *tmp = &msg->pdusessions_failed[nb_of_pdusessions_failed];
msg->pdusessions_failed[nb_of_pdusessions_failed].pdusession_id = item_p->pDUSessionID; tmp->pdusession_id = item_p->pDUSessionID;
msg->pdusessions_failed[nb_of_pdusessions_failed].cause = NGAP_CAUSE_RADIO_NETWORK; tmp->cause = NGAP_CAUSE_RADIO_NETWORK;
msg->pdusessions_failed[nb_of_pdusessions_failed].cause_value = NGAP_CauseRadioNetwork_unknown_local_UE_NGAP_ID; tmp->cause_value = NGAP_CauseRadioNetwork_unknown_local_UE_NGAP_ID;
} }
} else { msg->nb_of_pdusessions_failed = ie->value.choice.PDUSessionResourceModifyListModReq.list.count;
return -1;
}
msg->nb_of_pdusessions_failed = nb_of_pdusessions_failed;
ngap_gNB_pdusession_modify_resp(amf_desc_p->ngap_gNB_instance->instance,msg); ngap_gNB_pdusession_modify_resp(amf_desc_p->ngap_gNB_instance->instance,msg);
itti_free(TASK_RRC_GNB,message_p); itti_free(TASK_RRC_GNB, message_p);
message_p = NULL;
return -1; return -1;
} }
MessageDef *message_p = itti_alloc_new_message(TASK_NGAP, 0, NGAP_PDUSESSION_MODIFY_REQ); MessageDef *message_p = itti_alloc_new_message(TASK_NGAP, 0, NGAP_PDUSESSION_MODIFY_REQ);
ngap_pdusession_modify_req_t * msg=&NGAP_PDUSESSION_MODIFY_REQ(message_p); ngap_pdusession_modify_req_t * msg=&NGAP_PDUSESSION_MODIFY_REQ(message_p);
msg->ue_initial_id = ue_desc_p->ue_initial_id; memset(msg, 0, sizeof(*msg));
msg->amf_ue_ngap_id = amf_ue_ngap_id; msg->amf_ue_ngap_id = amf_ue_ngap_id;
msg->gNB_ue_ngap_id = gnb_ue_ngap_id; msg->gNB_ue_ngap_id = gnb_ue_ngap_id;
/* id-PDUSessionResourceModifyListModReq */
NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_PDUSessionResourceModifyRequestIEs_t, ie, container,
NGAP_ProtocolIE_ID_id_PDUSessionResourceModifyListModReq, true);
if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
msg->nb_pdusessions_tomodify =
ie->value.choice.PDUSessionResourceModifyListModReq.list.count;
for (i = 0; i < ie->value.choice.PDUSessionResourceModifyListModReq.list.count; i++) { msg->nb_pdusessions_tomodify = ie->value.choice.PDUSessionResourceModifyListModReq.list.count;
NGAP_PDUSessionResourceModifyItemModReq_t *item_p;
asn_dec_rval_t dec_rval;
NGAP_PDUSessionResourceModifyRequestTransfer_t *pdusessionTransfer_p = NULL;
NGAP_PDUSessionResourceModifyRequestTransferIEs_t *pdusessionTransfer_ies = NULL;
item_p = (NGAP_PDUSessionResourceModifyItemModReq_t *)ie->value.choice.PDUSessionResourceModifyListModReq.list.array[i]; for (int i = 0; i < ie->value.choice.PDUSessionResourceModifyListModReq.list.count; i++) {
NGAP_PDUSessionResourceModifyItemModReq_t *item_p = ie->value.choice.PDUSessionResourceModifyListModReq.list.array[i];
msg->pdusession_modify_params[i].pdusession_id = item_p->pDUSessionID; msg->pdusession_modify_params[i].pdusession_id = item_p->pDUSessionID;
// check for the NAS PDU // check for the NAS PDU
if (item_p->nAS_PDU != NULL && item_p->nAS_PDU->size > 0 ) { if (item_p->nAS_PDU != NULL && item_p->nAS_PDU->size > 0) {
msg->pdusession_modify_params[i].nas_pdu.length = item_p->nAS_PDU->size; allocCopy(&msg->pdusession_modify_params[i].nas_pdu, *item_p->nAS_PDU);
msg->pdusession_modify_params[i].nas_pdu.buffer = malloc(sizeof(uint8_t) * item_p->nAS_PDU->size); allocCopy(&msg->pdusession_modify_params[i].pdusessionTransfer, item_p->pDUSessionResourceModifyRequestTransfer);
memcpy(msg->pdusession_modify_params[i].nas_pdu.buffer,
item_p->nAS_PDU->buf, item_p->nAS_PDU->size);
} else { } else {
msg->pdusession_modify_params[i].nas_pdu.length = 0; LOG_W(NGAP, "received pdu session modify with void content for UE %u, pdu session %lu\n", msg->gNB_ue_ngap_id, item_p->pDUSessionID);
msg->pdusession_modify_params[i].nas_pdu.buffer = NULL;
continue; continue;
} }
dec_rval = aper_decode(NULL,
&asn_DEF_NGAP_PDUSessionResourceModifyRequestTransfer,
(void **)&pdusessionTransfer_p,
item_p->pDUSessionResourceModifyRequestTransfer.buf,
item_p->pDUSessionResourceModifyRequestTransfer.size, 0, 0);
if(dec_rval.code != RC_OK) {
NGAP_ERROR("could not decode PDUSessionResourceModifyRequestTransfer\n");
return -1;
}
for(int j=0; j< pdusessionTransfer_p->protocolIEs.list.count; j++) {
pdusessionTransfer_ies = pdusessionTransfer_p->protocolIEs.list.array[j];
switch(pdusessionTransfer_ies->id) {
/* optional PDUSessionAggregateMaximumBitRate */
case NGAP_ProtocolIE_ID_id_PDUSessionAggregateMaximumBitRate:
// TODO
NGAP_ERROR("Cant' handle NGAP_ProtocolIE_ID_id_PDUSessionAggregateMaximumBitRate\n");
break;
/* optional UL-NGU-UP-TNLModifyList */
case NGAP_ProtocolIE_ID_id_UL_NGU_UP_TNLModifyList:
// TODO
NGAP_ERROR("Cant' handle NGAP_ProtocolIE_ID_id_UL_NGU_UP_TNLModifyList\n");
break;
/* optional NetworkInstance */
case NGAP_ProtocolIE_ID_id_NetworkInstance:
// TODO
NGAP_ERROR("Cant' handle NGAP_ProtocolIE_ID_id_NetworkInstance\n");
break;
/* optional QosFlowAddOrModifyRequestList */
case NGAP_ProtocolIE_ID_id_QosFlowAddOrModifyRequestList:
{
NGAP_QosFlowAddOrModifyRequestItem_t *qosFlowItem_p;
NGAP_DEBUG("QosFlowAddOrModifyRequestList.list.count %d\n", pdusessionTransfer_ies->value.choice.QosFlowAddOrModifyRequestList.list.count);
DevAssert(pdusessionTransfer_ies->value.choice.QosFlowAddOrModifyRequestList.list.count > 0);
DevAssert(pdusessionTransfer_ies->value.choice.QosFlowAddOrModifyRequestList.list.count <= NGAP_maxnoofQosFlows);
msg->pdusession_modify_params[i].nb_qos = pdusessionTransfer_ies->value.choice.QosFlowAddOrModifyRequestList.list.count;
for(int qosIdx = 0; qosIdx < pdusessionTransfer_ies->value.choice.QosFlowAddOrModifyRequestList.list.count; qosIdx++) {
qosFlowItem_p = pdusessionTransfer_ies->value.choice.QosFlowAddOrModifyRequestList.list.array[qosIdx];
/* Set the QOS informations */
msg->pdusession_modify_params[i].qos[qosIdx].qfi = (uint8_t)qosFlowItem_p->qosFlowIdentifier;
if(qosFlowItem_p->qosFlowLevelQosParameters) {
if (qosFlowItem_p->qosFlowLevelQosParameters->qosCharacteristics.present == NGAP_QosCharacteristics_PR_nonDynamic5QI) {
msg->pdusession_modify_params[i].qos[qosIdx].fiveQI =
qosFlowItem_p->qosFlowLevelQosParameters->qosCharacteristics.choice.nonDynamic5QI->fiveQI;
} else if (qosFlowItem_p->qosFlowLevelQosParameters->qosCharacteristics.present == NGAP_QosCharacteristics_PR_dynamic5QI) {
// TODO
} }
msg->pdusession_modify_params[i].qos[qosIdx].allocation_retention_priority.priority_level =
qosFlowItem_p->qosFlowLevelQosParameters->allocationAndRetentionPriority.priorityLevelARP;
msg->pdusession_modify_params[i].qos[qosIdx].allocation_retention_priority.pre_emp_capability =
qosFlowItem_p->qosFlowLevelQosParameters->allocationAndRetentionPriority.pre_emptionCapability;
msg->pdusession_modify_params[i].qos[qosIdx].allocation_retention_priority.pre_emp_vulnerability =
qosFlowItem_p->qosFlowLevelQosParameters->allocationAndRetentionPriority.pre_emptionVulnerability;
}
}
}
break;
/* optional QosFlowToReleaseList */
case NGAP_ProtocolIE_ID_id_QosFlowToReleaseList:
// TODO
NGAP_ERROR("Cant' handle NGAP_ProtocolIE_ID_id_QosFlowToReleaseList\n");
break;
/* optional AdditionalUL-NGU-UP-TNLInformation */
case NGAP_ProtocolIE_ID_id_AdditionalUL_NGU_UP_TNLInformation:
// TODO
NGAP_ERROR("Cant' handle NGAP_ProtocolIE_ID_id_AdditionalUL_NGU_UP_TNLInformation\n");
break;
/* optional CommonNetworkInstance */
case NGAP_ProtocolIE_ID_id_CommonNetworkInstance:
// TODO
NGAP_ERROR("Cant' handle NGAP_ProtocolIE_ID_id_CommonNetworkInstance\n");
break;
default:
NGAP_ERROR("could not found protocolIEs id %ld\n", pdusessionTransfer_ies->id);
return -1;
}
}
}
itti_send_msg_to_task(TASK_RRC_GNB, ue_desc_p->gNB_instance->instance, message_p); itti_send_msg_to_task(TASK_RRC_GNB, ue_desc_p->gNB_instance->instance, message_p);
} else { /* of if (ie != NULL)*/
return -1;
}
return 0; return 0;
} }
// handle pdu session release command and send it to rrc_end // handle pdu session release command and send it to rrc_end
static static
int ngap_gNB_handle_pdusession_release_command(uint32_t assoc_id, int ngap_gNB_handle_pdusession_release_command(uint32_t assoc_id,
...@@ -1800,7 +1181,6 @@ int ngap_gNB_handle_pdusession_release_command(uint32_t assoc_id, ...@@ -1800,7 +1181,6 @@ int ngap_gNB_handle_pdusession_release_command(uint32_t assoc_id,
int i; int i;
ngap_gNB_amf_data_t *amf_desc_p = NULL; ngap_gNB_amf_data_t *amf_desc_p = NULL;
ngap_gNB_ue_context_t *ue_desc_p = NULL;
NGAP_PDUSessionResourceReleaseCommand_t *container; NGAP_PDUSessionResourceReleaseCommand_t *container;
NGAP_PDUSessionResourceReleaseCommandIEs_t *ie; NGAP_PDUSessionResourceReleaseCommandIEs_t *ie;
NGAP_RAN_UE_NGAP_ID_t gnb_ue_ngap_id; NGAP_RAN_UE_NGAP_ID_t gnb_ue_ngap_id;
...@@ -1834,20 +1214,13 @@ int ngap_gNB_handle_pdusession_release_command(uint32_t assoc_id, ...@@ -1834,20 +1214,13 @@ int ngap_gNB_handle_pdusession_release_command(uint32_t assoc_id,
return -1; return -1;
} }
if ((ue_desc_p = ngap_gNB_get_ue_context(amf_desc_p->ngap_gNB_instance, ngap_gNB_ue_context_t *ue_desc_p = ngap_get_ue_context(gnb_ue_ngap_id);
gnb_ue_ngap_id)) == NULL) { if (!ue_desc_p) {
NGAP_ERROR("[SCTP %d] Received PDUSession Resource release command for non existing UE context 0x%08lx\n", assoc_id, NGAP_ERROR("[SCTP %d] Received PDUSession Resource release command for non existing UE context 0x%08lx\n", assoc_id,
ie->value.choice.RAN_UE_NGAP_ID); ie->value.choice.RAN_UE_NGAP_ID);
return -1; return -1;
} }
/* 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;
// }
ue_desc_p->rx_stream = stream; ue_desc_p->rx_stream = stream;
if (ue_desc_p->amf_ue_ngap_id != amf_ue_ngap_id) { if (ue_desc_p->amf_ue_ngap_id != amf_ue_ngap_id) {
...@@ -1859,6 +1232,7 @@ int ngap_gNB_handle_pdusession_release_command(uint32_t assoc_id, ...@@ -1859,6 +1232,7 @@ int ngap_gNB_handle_pdusession_release_command(uint32_t assoc_id,
assoc_id, gnb_ue_ngap_id, amf_ue_ngap_id); assoc_id, gnb_ue_ngap_id, amf_ue_ngap_id);
MessageDef * message_p = itti_alloc_new_message(TASK_NGAP, 0, NGAP_PDUSESSION_RELEASE_COMMAND); MessageDef * message_p = itti_alloc_new_message(TASK_NGAP, 0, NGAP_PDUSESSION_RELEASE_COMMAND);
ngap_pdusession_release_command_t * msg=&NGAP_PDUSESSION_RELEASE_COMMAND(message_p); ngap_pdusession_release_command_t * msg=&NGAP_PDUSESSION_RELEASE_COMMAND(message_p);
memset(msg, 0, sizeof(*msg));
msg->gNB_ue_ngap_id = gnb_ue_ngap_id; msg->gNB_ue_ngap_id = gnb_ue_ngap_id;
msg->amf_ue_ngap_id = amf_ue_ngap_id; msg->amf_ue_ngap_id = amf_ue_ngap_id;
...@@ -1866,44 +1240,20 @@ int ngap_gNB_handle_pdusession_release_command(uint32_t assoc_id, ...@@ -1866,44 +1240,20 @@ int ngap_gNB_handle_pdusession_release_command(uint32_t assoc_id,
NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_PDUSessionResourceReleaseCommandIEs_t, ie, container, NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_PDUSessionResourceReleaseCommandIEs_t, ie, container,
NGAP_ProtocolIE_ID_id_NAS_PDU, false); NGAP_ProtocolIE_ID_id_NAS_PDU, false);
if(ie && ie->value.choice.NAS_PDU.size > 0) { if (ie)
msg->nas_pdu.length = ie->value.choice.NAS_PDU.size; allocCopy(&msg->nas_pdu, ie->value.choice.NAS_PDU);
msg->nas_pdu.buffer = malloc(sizeof(uint8_t) * ie->value.choice.NAS_PDU.size);
memcpy(msg->nas_pdu.buffer,
ie->value.choice.NAS_PDU.buf,
ie->value.choice.NAS_PDU.size);
} else {
msg->nas_pdu.length = 0;
msg->nas_pdu.buffer = NULL;
}
/* id-PDUSessionResourceToReleaseListRelCmd */ /* id-PDUSessionResourceToReleaseListRelCmd */
NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_PDUSessionResourceReleaseCommandIEs_t, ie, container, NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_PDUSessionResourceReleaseCommandIEs_t, ie, container,
NGAP_ProtocolIE_ID_id_PDUSessionResourceToReleaseListRelCmd, true); NGAP_ProtocolIE_ID_id_PDUSessionResourceToReleaseListRelCmd, true);
if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
msg->nb_pdusessions_torelease = ie->value.choice.PDUSessionResourceToReleaseListRelCmd.list.count; msg->nb_pdusessions_torelease = ie->value.choice.PDUSessionResourceToReleaseListRelCmd.list.count;
for (i = 0; i < ie->value.choice.PDUSessionResourceToReleaseListRelCmd.list.count; i++) { for (i = 0; i < ie->value.choice.PDUSessionResourceToReleaseListRelCmd.list.count; i++) {
NGAP_PDUSessionResourceToReleaseItemRelCmd_t *item_p; NGAP_PDUSessionResourceToReleaseItemRelCmd_t *item_p;
item_p = (NGAP_PDUSessionResourceToReleaseItemRelCmd_t *)ie->value.choice.PDUSessionResourceToReleaseListRelCmd.list.array[i]; item_p = ie->value.choice.PDUSessionResourceToReleaseListRelCmd.list.array[i];
msg->pdusession_release_params[i].pdusession_id = item_p->pDUSessionID; msg->pdusession_release_params[i].pdusession_id = item_p->pDUSessionID;
if(item_p->pDUSessionResourceReleaseCommandTransfer.size > 0) { allocCopy(&msg->pdusession_release_params[i].data, item_p->pDUSessionResourceReleaseCommandTransfer);
msg->pdusession_release_params[i].transfer_length = item_p->pDUSessionResourceReleaseCommandTransfer.size;
msg->pdusession_release_params[i].transfer_buffer = malloc(sizeof(uint8_t) * item_p->pDUSessionResourceReleaseCommandTransfer.size);
memcpy(msg->pdusession_release_params[i].transfer_buffer,
item_p->pDUSessionResourceReleaseCommandTransfer.buf,
item_p->pDUSessionResourceReleaseCommandTransfer.size);
}else {
msg->pdusession_release_params[i].transfer_length = 0;
msg->pdusession_release_params[i].transfer_buffer = NULL;
NGAP_ERROR("[NGAP] Received pdu session release command for pDUSessionResourceReleaseCommandTransfer is NULL!\n");
}
NGAP_DEBUG("[NGAP] Received pdu session release command for pDUSessionID id %ld\n", item_p->pDUSessionID);
}
} else {
return -1;
} }
itti_send_msg_to_task(TASK_RRC_GNB, ue_desc_p->gNB_instance->instance, message_p); itti_send_msg_to_task(TASK_RRC_GNB, ue_desc_p->gNB_instance->instance, message_p);
...@@ -1937,3 +1287,94 @@ int ngap_gNB_handle_ng_ENDC_pdusession_modification_confirm(uint32_t ...@@ -1937,3 +1287,94 @@ int ngap_gNB_handle_ng_ENDC_pdusession_modification_confirm(uint32_t
return 0; return 0;
} }
/* Handlers matrix. Only gNB related procedure present here */
ngap_message_decoded_callback ngap_messages_callback[][3] = {
{0, 0, 0}, /* AMFConfigurationUpdate */
{0, 0, 0}, /* AMFStatusIndication */
{0, 0, 0}, /* CellTrafficTrace */
{ngap_gNB_handle_deactivate_trace, 0, 0}, /* DeactivateTrace */
{ngap_gNB_handle_nas_downlink, 0, 0}, /* DownlinkNASTransport */
{0, 0, 0}, /* DownlinkNonUEAssociatedNRPPaTransport */
{0, 0, 0}, /* DownlinkRANConfigurationTransfer */
{0, 0, 0}, /* DownlinkRANStatusTransfer */
{0, 0, 0}, /* DownlinkUEAssociatedNRPPaTransport */
{ngap_gNB_handle_error_indication, 0, 0}, /* ErrorIndication */
{0, 0, 0}, /* HandoverCancel */
{0, 0, 0}, /* HandoverNotification */
{0, 0, 0}, /* HandoverPreparation */
{0, 0, 0}, /* HandoverResourceAllocation */
{ngap_gNB_handle_initial_context_request, 0, 0}, /* InitialContextSetup */
{0, 0, 0}, /* InitialUEMessage */
{0, 0, 0}, /* LocationReportingControl */
{0, 0, 0}, /* LocationReportingFailureIndication */
{0, 0, 0}, /* LocationReport */
{0, 0, 0}, /* NASNonDeliveryIndication */
{0, 0, 0}, /* NGReset */
{0, ngap_gNB_handle_ng_setup_response, ngap_gNB_handle_ng_setup_failure}, /* NGSetup */
{0, 0, 0}, /* OverloadStart */
{0, 0, 0}, /* OverloadStop */
{ngap_gNB_handle_paging, 0, 0}, /* Paging */
{0, ngap_gNB_handle_ng_path_switch_request_ack, ngap_gNB_handle_ng_path_switch_request_failure}, /* PathSwitchRequest */
{ngap_gNB_handle_pdusession_modify_request, 0, 0}, /* PDUSessionResourceModify */
{0, ngap_gNB_handle_ng_ENDC_pdusession_modification_confirm, 0}, /* PDUSessionResourceModifyIndication */
{ngap_gNB_handle_pdusession_release_command, 0, 0}, /* PDUSessionResourceRelease */
{ngap_gNB_handle_pdusession_setup_request, 0, 0}, /* PDUSessionResourceSetup */
{0, 0, 0}, /* PDUSessionResourceNotify */
{0, 0, 0}, /* PrivateMessage */
{0, 0, 0}, /* PWSCancel */
{0, 0, 0}, /* PWSFailureIndication */
{0, 0, 0}, /* PWSRestartIndication */
{0, 0, 0}, /* RANConfigurationUpdate */
{0, 0, 0}, /* RerouteNASRequest */
{0, 0, 0}, /* RRCInactiveTransitionReport */
{0, 0, 0}, /* TraceFailureIndication */
{ngap_gNB_handle_trace_start, 0, 0}, /* TraceStart */
{0, 0, 0}, /* UEContextModification */
{ngap_gNB_handle_ue_context_release_command, 0, 0}, /* UEContextRelease */
{0, 0, 0}, /* UEContextReleaseRequest */
{0, 0, 0}, /* UERadioCapabilityCheck */
{0, 0, 0}, /* UERadioCapabilityInfoIndication */
{0, 0, 0}, /* UETNLABindingRelease */
{0, 0, 0}, /* UplinkNASTransport */
{0, 0, 0}, /* UplinkNonUEAssociatedNRPPaTransport */
{0, 0, 0}, /* UplinkRANConfigurationTransfer */
{0, 0, 0}, /* UplinkRANStatusTransfer */
{0, 0, 0}, /* UplinkUEAssociatedNRPPaTransport */
{0, 0, 0}, /* WriteReplaceWarning */
{0, 0, 0}, /* SecondaryRATDataUsageReport */
};
int ngap_gNB_handle_message(uint32_t assoc_id, int32_t stream, const uint8_t *const data, const uint32_t data_length)
{
NGAP_NGAP_PDU_t pdu;
int ret;
DevAssert(data != NULL);
memset(&pdu, 0, sizeof(pdu));
if (ngap_gNB_decode_pdu(&pdu, data, data_length) < 0) {
NGAP_ERROR("Failed to decode PDU\n");
return -1;
}
/* Checking procedure Code and direction of message */
if (pdu.choice.initiatingMessage->procedureCode >= sizeof(ngap_messages_callback) / (3 * sizeof(ngap_message_decoded_callback)) || (pdu.present > NGAP_NGAP_PDU_PR_unsuccessfulOutcome)) {
NGAP_ERROR("[SCTP %d] Either procedureCode %ld or direction %d exceed expected\n", assoc_id, pdu.choice.initiatingMessage->procedureCode, pdu.present);
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_NGAP_NGAP_PDU, &pdu);
return -1;
}
/* No handler present.
* This can mean not implemented or no procedure for gNB (wrong direction).
*/
if (ngap_messages_callback[pdu.choice.initiatingMessage->procedureCode][pdu.present - 1] == NULL) {
NGAP_ERROR("[SCTP %d] No handler for procedureCode %ld in %s\n", assoc_id, pdu.choice.initiatingMessage->procedureCode, ngap_direction2String(pdu.present - 1));
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_NGAP_NGAP_PDU, &pdu);
return -1;
}
/* Calling the right handler */
ret = (*ngap_messages_callback[pdu.choice.initiatingMessage->procedureCode][pdu.present - 1])(assoc_id, stream, &pdu);
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_NGAP_NGAP_PDU, &pdu);
return ret;
}
...@@ -49,11 +49,7 @@ void ngap_gNB_itti_send_sctp_data_req(instance_t instance, int32_t assoc_id, uin ...@@ -49,11 +49,7 @@ void ngap_gNB_itti_send_sctp_data_req(instance_t instance, int32_t assoc_id, uin
itti_send_msg_to_task(TASK_SCTP, instance, message_p); itti_send_msg_to_task(TASK_SCTP, instance, message_p);
} }
void ngap_gNB_itti_send_nas_downlink_ind(instance_t instance, void ngap_gNB_itti_send_nas_downlink_ind(instance_t instance, uint32_t gNB_ue_ngap_id, uint8_t *nas_pdu, uint32_t nas_pdu_length)
uint16_t ue_initial_id,
uint32_t gNB_ue_ngap_id,
uint8_t *nas_pdu,
uint32_t nas_pdu_length)
{ {
MessageDef *message_p; MessageDef *message_p;
ngap_downlink_nas_t *ngap_downlink_nas; ngap_downlink_nas_t *ngap_downlink_nas;
...@@ -62,7 +58,6 @@ void ngap_gNB_itti_send_nas_downlink_ind(instance_t instance, ...@@ -62,7 +58,6 @@ void ngap_gNB_itti_send_nas_downlink_ind(instance_t instance,
ngap_downlink_nas = &message_p->ittiMsg.ngap_downlink_nas; ngap_downlink_nas = &message_p->ittiMsg.ngap_downlink_nas;
ngap_downlink_nas->ue_initial_id = ue_initial_id;
ngap_downlink_nas->gNB_ue_ngap_id = gNB_ue_ngap_id; ngap_downlink_nas->gNB_ue_ngap_id = gNB_ue_ngap_id;
ngap_downlink_nas->nas_pdu.buffer = malloc(sizeof(uint8_t) * nas_pdu_length); ngap_downlink_nas->nas_pdu.buffer = malloc(sizeof(uint8_t) * nas_pdu_length);
memcpy(ngap_downlink_nas->nas_pdu.buffer, nas_pdu, nas_pdu_length); memcpy(ngap_downlink_nas->nas_pdu.buffer, nas_pdu, nas_pdu_length);
......
...@@ -33,11 +33,7 @@ ...@@ -33,11 +33,7 @@
void ngap_gNB_itti_send_sctp_data_req(instance_t instance, int32_t assoc_id, uint8_t *buffer, void ngap_gNB_itti_send_sctp_data_req(instance_t instance, int32_t assoc_id, uint8_t *buffer,
uint32_t buffer_length, uint16_t stream); uint32_t buffer_length, uint16_t stream);
void ngap_gNB_itti_send_nas_downlink_ind(instance_t instance, void ngap_gNB_itti_send_nas_downlink_ind(instance_t instance, uint32_t gNB_ue_ngap_id, uint8_t *nas_pdu, uint32_t nas_pdu_length);
uint16_t ue_initial_id,
uint32_t gNB_ue_ngap_id,
uint8_t *nas_pdu,
uint32_t nas_pdu_length);
void ngap_gNB_itti_send_sctp_close_association(instance_t instance, void ngap_gNB_itti_send_sctp_close_association(instance_t instance,
int32_t assoc_id); int32_t assoc_id);
......
...@@ -49,72 +49,79 @@ ...@@ -49,72 +49,79 @@
#include "ngap_gNB_nas_procedures.h" #include "ngap_gNB_nas_procedures.h"
#include "ngap_gNB_management_procedures.h" #include "ngap_gNB_management_procedures.h"
static void allocCopy(OCTET_STRING_t *out, ngap_pdu_t in)
{
if (in.length) {
out->buf = malloc(in.length);
memcpy(out->buf, in.buffer, in.length);
}
out->size = in.length;
}
static void allocAddrCopy(BIT_STRING_t *out, ngap_transport_layer_addr_t in)
{
if (in.length) {
out->buf = malloc(in.length);
memcpy(out->buf, in.buffer, in.length);
out->size = in.length;
out->bits_unused = 0;
}
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int ngap_gNB_handle_nas_first_req( int ngap_gNB_handle_nas_first_req(instance_t instance, ngap_nas_first_req_t *UEfirstReq)
instance_t instance, ngap_nas_first_req_t *ngap_nas_first_req_p)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
{ {
ngap_gNB_instance_t *instance_p = NULL; ngap_gNB_instance_t *instance_p = NULL;
struct ngap_gNB_amf_data_s *amf_desc_p = NULL; struct ngap_gNB_amf_data_s *amf_desc_p = NULL;
struct ngap_gNB_ue_context_s *ue_desc_p = NULL;
NGAP_NGAP_PDU_t pdu; NGAP_NGAP_PDU_t pdu;
NGAP_InitialUEMessage_t *out;
NGAP_InitialUEMessage_IEs_t *ie;
NGAP_UserLocationInformationNR_t *userinfo_nr_p = NULL;
uint8_t *buffer = NULL; uint8_t *buffer = NULL;
uint32_t length = 0; uint32_t length = 0;
DevAssert(ngap_nas_first_req_p != NULL); DevAssert(UEfirstReq != NULL);
/* Retrieve the NGAP gNB instance associated with Mod_id */ /* Retrieve the NGAP gNB instance associated with Mod_id */
instance_p = ngap_gNB_get_instance(instance); instance_p = ngap_gNB_get_instance(instance);
DevAssert(instance_p != NULL); DevAssert(instance_p != NULL);
memset(&pdu, 0, sizeof(pdu)); memset(&pdu, 0, sizeof(pdu));
pdu.present = NGAP_NGAP_PDU_PR_initiatingMessage; pdu.present = NGAP_NGAP_PDU_PR_initiatingMessage;
pdu.choice.initiatingMessage = (NGAP_InitiatingMessage_t *)calloc(1,sizeof(NGAP_InitiatingMessage_t)); asn1cCalloc(pdu.choice.initiatingMessage, head);
pdu.choice.initiatingMessage->procedureCode = NGAP_ProcedureCode_id_InitialUEMessage; head->procedureCode = NGAP_ProcedureCode_id_InitialUEMessage;
pdu.choice.initiatingMessage->criticality = NGAP_Criticality_ignore; head->criticality = NGAP_Criticality_ignore;
pdu.choice.initiatingMessage->value.present = NGAP_InitiatingMessage__value_PR_InitialUEMessage; head->value.present = NGAP_InitiatingMessage__value_PR_InitialUEMessage;
out = &pdu.choice.initiatingMessage->value.choice.InitialUEMessage; NGAP_InitialUEMessage_t *out = &head->value.choice.InitialUEMessage;
/* Select the AMF corresponding to the provided GUAMI. */ /* Select the AMF corresponding to the provided GUAMI. */
//TODO have not be test. it's should be test //TODO have not be test. it's should be test
if (ngap_nas_first_req_p->ue_identity.presenceMask & NGAP_UE_IDENTITIES_guami) { if (UEfirstReq->ue_identity.presenceMask & NGAP_UE_IDENTITIES_guami) {
amf_desc_p = ngap_gNB_nnsf_select_amf_by_guami( amf_desc_p = ngap_gNB_nnsf_select_amf_by_guami(instance_p, UEfirstReq->establishment_cause, UEfirstReq->ue_identity.guami);
instance_p,
ngap_nas_first_req_p->establishment_cause,
ngap_nas_first_req_p->ue_identity.guami);
if (amf_desc_p) { if (amf_desc_p) {
NGAP_INFO("[gNB %ld] Chose AMF '%s' (assoc_id %d) through GUAMI MCC %d MNC %d AMFRI %d AMFSI %d AMFPT %d\n", NGAP_INFO("[gNB %ld] Chose AMF '%s' (assoc_id %d) through GUAMI MCC %d MNC %d AMFRI %d AMFSI %d AMFPT %d\n",
instance, instance,
amf_desc_p->amf_name, amf_desc_p->amf_name,
amf_desc_p->assoc_id, amf_desc_p->assoc_id,
ngap_nas_first_req_p->ue_identity.guami.mcc, UEfirstReq->ue_identity.guami.mcc,
ngap_nas_first_req_p->ue_identity.guami.mnc, UEfirstReq->ue_identity.guami.mnc,
ngap_nas_first_req_p->ue_identity.guami.amf_region_id, UEfirstReq->ue_identity.guami.amf_region_id,
ngap_nas_first_req_p->ue_identity.guami.amf_set_id, UEfirstReq->ue_identity.guami.amf_set_id,
ngap_nas_first_req_p->ue_identity.guami.amf_pointer); UEfirstReq->ue_identity.guami.amf_pointer);
} }
} }
if (amf_desc_p == NULL) { if (amf_desc_p == NULL) {
/* Select the AMF corresponding to the provided s-TMSI. */ /* Select the AMF corresponding to the provided s-TMSI. */
//TODO have not be test. it's should be test //TODO have not be test. it's should be test
if (ngap_nas_first_req_p->ue_identity.presenceMask & NGAP_UE_IDENTITIES_FiveG_s_tmsi) { if (UEfirstReq->ue_identity.presenceMask & NGAP_UE_IDENTITIES_FiveG_s_tmsi) {
amf_desc_p = ngap_gNB_nnsf_select_amf_by_amf_setid( amf_desc_p = ngap_gNB_nnsf_select_amf_by_amf_setid(instance_p, UEfirstReq->establishment_cause, UEfirstReq->selected_plmn_identity, UEfirstReq->ue_identity.s_tmsi.amf_set_id);
instance_p,
ngap_nas_first_req_p->establishment_cause,
ngap_nas_first_req_p->selected_plmn_identity,
ngap_nas_first_req_p->ue_identity.s_tmsi.amf_set_id);
if (amf_desc_p) { if (amf_desc_p) {
NGAP_INFO("[gNB %ld] Chose AMF '%s' (assoc_id %d) through S-TMSI AMFSI %d and selected PLMN Identity index %d MCC %d MNC %d\n", NGAP_INFO("[gNB %ld] Chose AMF '%s' (assoc_id %d) through S-TMSI AMFSI %d and selected PLMN Identity index %d MCC %d MNC %d\n",
instance, instance,
amf_desc_p->amf_name, amf_desc_p->amf_name,
amf_desc_p->assoc_id, amf_desc_p->assoc_id,
ngap_nas_first_req_p->ue_identity.s_tmsi.amf_set_id, UEfirstReq->ue_identity.s_tmsi.amf_set_id,
ngap_nas_first_req_p->selected_plmn_identity, UEfirstReq->selected_plmn_identity,
instance_p->mcc[ngap_nas_first_req_p->selected_plmn_identity], instance_p->mcc[UEfirstReq->selected_plmn_identity],
instance_p->mnc[ngap_nas_first_req_p->selected_plmn_identity]); instance_p->mnc[UEfirstReq->selected_plmn_identity]);
} }
} }
} }
...@@ -123,19 +130,16 @@ int ngap_gNB_handle_nas_first_req( ...@@ -123,19 +130,16 @@ int ngap_gNB_handle_nas_first_req(
/* Select AMF based on the selected PLMN identity, received through RRC /* Select AMF based on the selected PLMN identity, received through RRC
* Connection Setup Complete */ * Connection Setup Complete */
//TODO have not be test. it's should be test //TODO have not be test. it's should be test
amf_desc_p = ngap_gNB_nnsf_select_amf_by_plmn_id( amf_desc_p = ngap_gNB_nnsf_select_amf_by_plmn_id(instance_p, UEfirstReq->establishment_cause, UEfirstReq->selected_plmn_identity);
instance_p,
ngap_nas_first_req_p->establishment_cause,
ngap_nas_first_req_p->selected_plmn_identity);
if (amf_desc_p) { if (amf_desc_p) {
NGAP_INFO("[gNB %ld] Chose AMF '%s' (assoc_id %d) through selected PLMN Identity index %d MCC %d MNC %d\n", NGAP_INFO("[gNB %ld] Chose AMF '%s' (assoc_id %d) through selected PLMN Identity index %d MCC %d MNC %d\n",
instance, instance,
amf_desc_p->amf_name, amf_desc_p->amf_name,
amf_desc_p->assoc_id, amf_desc_p->assoc_id,
ngap_nas_first_req_p->selected_plmn_identity, UEfirstReq->selected_plmn_identity,
instance_p->mcc[ngap_nas_first_req_p->selected_plmn_identity], instance_p->mcc[UEfirstReq->selected_plmn_identity],
instance_p->mnc[ngap_nas_first_req_p->selected_plmn_identity]); instance_p->mnc[UEfirstReq->selected_plmn_identity]);
} }
} }
...@@ -145,15 +149,10 @@ int ngap_gNB_handle_nas_first_req( ...@@ -145,15 +149,10 @@ int ngap_gNB_handle_nas_first_req(
* identity, selects the AMF with the highest capacity. * identity, selects the AMF with the highest capacity.
*/ */
//TODO have not be test. it's should be test //TODO have not be test. it's should be test
amf_desc_p = ngap_gNB_nnsf_select_amf( amf_desc_p = ngap_gNB_nnsf_select_amf(instance_p, UEfirstReq->establishment_cause);
instance_p,
ngap_nas_first_req_p->establishment_cause);
if (amf_desc_p) { if (amf_desc_p) {
NGAP_INFO("[gNB %ld] Chose AMF '%s' (assoc_id %d) through highest relative capacity\n", NGAP_INFO("[gNB %ld] Chose AMF '%s' (assoc_id %d) through highest relative capacity\n", instance, amf_desc_p->amf_name, amf_desc_p->assoc_id);
instance,
amf_desc_p->amf_name,
amf_desc_p->assoc_id);
} }
} }
...@@ -170,63 +169,44 @@ int ngap_gNB_handle_nas_first_req( ...@@ -170,63 +169,44 @@ int ngap_gNB_handle_nas_first_req(
/* The gNB should allocate a unique gNB UE NGAP ID for this UE. The value /* The gNB should allocate a unique gNB UE NGAP ID for this UE. The value
* will be used for the duration of the connectivity. * will be used for the duration of the connectivity.
*/ */
ue_desc_p = ngap_gNB_allocate_new_UE_context(); struct ngap_gNB_ue_context_s *ue_desc_p = calloc(1, sizeof(*ue_desc_p));
DevAssert(ue_desc_p != NULL); DevAssert(ue_desc_p != NULL);
/* Keep a reference to the selected AMF */ /* Keep a reference to the selected AMF */
ue_desc_p->amf_ref = amf_desc_p; ue_desc_p->amf_ref = amf_desc_p;
ue_desc_p->ue_initial_id = ngap_nas_first_req_p->ue_initial_id; ue_desc_p->gNB_ue_ngap_id = UEfirstReq->gNB_ue_ngap_id;
ue_desc_p->gNB_instance = instance_p; ue_desc_p->gNB_instance = instance_p;
ue_desc_p->selected_plmn_identity = ngap_nas_first_req_p->selected_plmn_identity; ue_desc_p->selected_plmn_identity = UEfirstReq->selected_plmn_identity;
do { // insert in master table
struct ngap_gNB_ue_context_s *collision_p; ngap_store_ue_context(ue_desc_p);
/* Peek a random value for the gNB_ue_ngap_id */
ue_desc_p->gNB_ue_ngap_id = (random() + random()) & 0xffffffff;
if ((collision_p = RB_INSERT(ngap_ue_map, &instance_p->ngap_ue_head, ue_desc_p))
== NULL) {
NGAP_DEBUG("Found usable gNB_ue_ngap_id: 0x%08x %u(10)\n",
ue_desc_p->gNB_ue_ngap_id,
ue_desc_p->gNB_ue_ngap_id);
/* Break the loop as the id is not already used by another UE */
break;
}
} while(1);
/* mandatory */ /* mandatory */
ie = (NGAP_InitialUEMessage_IEs_t *)calloc(1, sizeof(NGAP_InitialUEMessage_IEs_t)); {
asn1cSequenceAdd(out->protocolIEs.list, NGAP_InitialUEMessage_IEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID; ie->id = NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID;
ie->criticality = NGAP_Criticality_reject; ie->criticality = NGAP_Criticality_reject;
ie->value.present = NGAP_InitialUEMessage_IEs__value_PR_RAN_UE_NGAP_ID; ie->value.present = NGAP_InitialUEMessage_IEs__value_PR_RAN_UE_NGAP_ID;
ie->value.choice.RAN_UE_NGAP_ID = ue_desc_p->gNB_ue_ngap_id; ie->value.choice.RAN_UE_NGAP_ID = ue_desc_p->gNB_ue_ngap_id;
asn1cSeqAdd(&out->protocolIEs.list, ie); }
/* mandatory */ /* mandatory */
ie = (NGAP_InitialUEMessage_IEs_t *)calloc(1, sizeof(NGAP_InitialUEMessage_IEs_t)); {
asn1cSequenceAdd(out->protocolIEs.list, NGAP_InitialUEMessage_IEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_NAS_PDU; ie->id = NGAP_ProtocolIE_ID_id_NAS_PDU;
ie->criticality = NGAP_Criticality_reject; ie->criticality = NGAP_Criticality_reject;
ie->value.present = NGAP_InitialUEMessage_IEs__value_PR_NAS_PDU; ie->value.present = NGAP_InitialUEMessage_IEs__value_PR_NAS_PDU;
#if 1 allocCopy(&ie->value.choice.NAS_PDU, UEfirstReq->nas_pdu);
ie->value.choice.NAS_PDU.buf = ngap_nas_first_req_p->nas_pdu.buffer; }
#else
ie->value.choice.NAS_PDU.buf = malloc(ngap_nas_first_req_p->nas_pdu.length);
memcpy(ie->value.choice.NAS_PDU.buf,
ngap_nas_first_req_p->nas_pdu.buffer,
ngap_nas_first_req_p->nas_pdu.length);
#endif
ie->value.choice.NAS_PDU.size = ngap_nas_first_req_p->nas_pdu.length;
asn1cSeqAdd(&out->protocolIEs.list, ie);
/* mandatory */ /* mandatory */
ie = (NGAP_InitialUEMessage_IEs_t *)calloc(1, sizeof(NGAP_InitialUEMessage_IEs_t)); {
asn1cSequenceAdd(out->protocolIEs.list, NGAP_InitialUEMessage_IEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_UserLocationInformation; ie->id = NGAP_ProtocolIE_ID_id_UserLocationInformation;
ie->criticality = NGAP_Criticality_reject; ie->criticality = NGAP_Criticality_reject;
ie->value.present = NGAP_InitialUEMessage_IEs__value_PR_UserLocationInformation; ie->value.present = NGAP_InitialUEMessage_IEs__value_PR_UserLocationInformation;
ie->value.choice.UserLocationInformation.present = NGAP_UserLocationInformation_PR_userLocationInformationNR; ie->value.choice.UserLocationInformation.present = NGAP_UserLocationInformation_PR_userLocationInformationNR;
ie->value.choice.UserLocationInformation.choice.userLocationInformationNR = asn1cCalloc(ie->value.choice.UserLocationInformation.choice.userLocationInformationNR, userinfo_nr_p);
CALLOC(1, sizeof(*ie->value.choice.UserLocationInformation.choice.userLocationInformationNR));
userinfo_nr_p = ie->value.choice.UserLocationInformation.choice.userLocationInformationNR;
/* Set nRCellIdentity. default userLocationInformationNR */ /* Set nRCellIdentity. default userLocationInformationNR */
MACRO_GNB_ID_TO_CELL_IDENTITY(instance_p->gNB_id, MACRO_GNB_ID_TO_CELL_IDENTITY(instance_p->gNB_id,
...@@ -243,47 +223,40 @@ int ngap_gNB_handle_nas_first_req( ...@@ -243,47 +223,40 @@ int ngap_gNB_handle_nas_first_req(
instance_p->mnc[ue_desc_p->selected_plmn_identity], instance_p->mnc[ue_desc_p->selected_plmn_identity],
instance_p->mnc_digit_length[ue_desc_p->selected_plmn_identity], instance_p->mnc_digit_length[ue_desc_p->selected_plmn_identity],
&userinfo_nr_p->tAI.pLMNIdentity); &userinfo_nr_p->tAI.pLMNIdentity);
}
asn1cSeqAdd(&out->protocolIEs.list, ie);
/* Set the establishment cause according to those provided by RRC */ /* Set the establishment cause according to those provided by RRC */
DevCheck(ngap_nas_first_req_p->establishment_cause < NGAP_RRC_CAUSE_LAST, DevCheck(UEfirstReq->establishment_cause < NGAP_RRC_CAUSE_LAST, UEfirstReq->establishment_cause, NGAP_RRC_CAUSE_LAST, 0);
ngap_nas_first_req_p->establishment_cause, NGAP_RRC_CAUSE_LAST, 0);
/* mandatory */ /* mandatory */
ie = (NGAP_InitialUEMessage_IEs_t *)calloc(1, sizeof(NGAP_InitialUEMessage_IEs_t)); {
asn1cSequenceAdd(out->protocolIEs.list, NGAP_InitialUEMessage_IEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_RRCEstablishmentCause; ie->id = NGAP_ProtocolIE_ID_id_RRCEstablishmentCause;
ie->criticality = NGAP_Criticality_ignore; ie->criticality = NGAP_Criticality_ignore;
ie->value.present = NGAP_InitialUEMessage_IEs__value_PR_RRCEstablishmentCause; ie->value.present = NGAP_InitialUEMessage_IEs__value_PR_RRCEstablishmentCause;
ie->value.choice.RRCEstablishmentCause = ngap_nas_first_req_p->establishment_cause; ie->value.choice.RRCEstablishmentCause = UEfirstReq->establishment_cause;
asn1cSeqAdd(&out->protocolIEs.list, ie); }
/* optional */ /* optional */
if (ngap_nas_first_req_p->ue_identity.presenceMask & NGAP_UE_IDENTITIES_FiveG_s_tmsi) { if (UEfirstReq->ue_identity.presenceMask & NGAP_UE_IDENTITIES_FiveG_s_tmsi) {
NGAP_DEBUG("FIVEG_S_TMSI_PRESENT\n"); NGAP_DEBUG("FIVEG_S_TMSI_PRESENT\n");
ie = (NGAP_InitialUEMessage_IEs_t *)calloc(1, sizeof(NGAP_InitialUEMessage_IEs_t)); asn1cSequenceAdd(out->protocolIEs.list, NGAP_InitialUEMessage_IEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_FiveG_S_TMSI; ie->id = NGAP_ProtocolIE_ID_id_FiveG_S_TMSI;
ie->criticality = NGAP_Criticality_reject; ie->criticality = NGAP_Criticality_reject;
ie->value.present = NGAP_InitialUEMessage_IEs__value_PR_FiveG_S_TMSI; ie->value.present = NGAP_InitialUEMessage_IEs__value_PR_FiveG_S_TMSI;
AMF_SETID_TO_BIT_STRING(ngap_nas_first_req_p->ue_identity.s_tmsi.amf_set_id, AMF_SETID_TO_BIT_STRING(UEfirstReq->ue_identity.s_tmsi.amf_set_id, &ie->value.choice.FiveG_S_TMSI.aMFSetID);
&ie->value.choice.FiveG_S_TMSI.aMFSetID); AMF_SETID_TO_BIT_STRING(UEfirstReq->ue_identity.s_tmsi.amf_pointer, &ie->value.choice.FiveG_S_TMSI.aMFPointer);
AMF_SETID_TO_BIT_STRING(ngap_nas_first_req_p->ue_identity.s_tmsi.amf_pointer, M_TMSI_TO_OCTET_STRING(UEfirstReq->ue_identity.s_tmsi.m_tmsi, &ie->value.choice.FiveG_S_TMSI.fiveG_TMSI);
&ie->value.choice.FiveG_S_TMSI.aMFPointer);
M_TMSI_TO_OCTET_STRING(ngap_nas_first_req_p->ue_identity.s_tmsi.m_tmsi,
&ie->value.choice.FiveG_S_TMSI.fiveG_TMSI);
asn1cSeqAdd(&out->protocolIEs.list, ie);
} }
/* optional */ /* optional */
ie = (NGAP_InitialUEMessage_IEs_t *)calloc(1, sizeof(NGAP_InitialUEMessage_IEs_t)); {
asn1cSequenceAdd(out->protocolIEs.list, NGAP_InitialUEMessage_IEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_UEContextRequest; ie->id = NGAP_ProtocolIE_ID_id_UEContextRequest;
ie->criticality = NGAP_Criticality_ignore; ie->criticality = NGAP_Criticality_ignore;
ie->value.present = NGAP_InitialUEMessage_IEs__value_PR_UEContextRequest; ie->value.present = NGAP_InitialUEMessage_IEs__value_PR_UEContextRequest;
ie->value.choice.UEContextRequest = NGAP_UEContextRequest_requested; ie->value.choice.UEContextRequest = NGAP_UEContextRequest_requested;
asn1cSeqAdd(&out->protocolIEs.list, ie); }
if (ngap_gNB_encode_pdu(&pdu, &buffer, &length) < 0) { if (ngap_gNB_encode_pdu(&pdu, &buffer, &length) < 0) {
/* Failed to encode message */ /* Failed to encode message */
...@@ -342,9 +315,7 @@ int ngap_gNB_handle_nas_downlink(uint32_t assoc_id, ...@@ -342,9 +315,7 @@ int ngap_gNB_handle_nas_downlink(uint32_t assoc_id,
// } // }
if ((amf_desc_p = ngap_gNB_get_AMF(NULL, assoc_id, 0)) == NULL) { if ((amf_desc_p = ngap_gNB_get_AMF(NULL, assoc_id, 0)) == NULL) {
NGAP_ERROR( NGAP_ERROR("[SCTP %d] Received NAS downlink message for non existing AMF context\n", assoc_id);
"[SCTP %d] Received NAS downlink message for non existing AMF context\n",
assoc_id);
return -1; return -1;
} }
...@@ -360,8 +331,7 @@ int ngap_gNB_handle_nas_downlink(uint32_t assoc_id, ...@@ -360,8 +331,7 @@ int ngap_gNB_handle_nas_downlink(uint32_t assoc_id,
NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID, true); NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID, true);
gnb_ue_ngap_id = ie->value.choice.RAN_UE_NGAP_ID; gnb_ue_ngap_id = ie->value.choice.RAN_UE_NGAP_ID;
if ((ue_desc_p = ngap_gNB_get_ue_context(ngap_gNB_instance, if ((ue_desc_p = ngap_get_ue_context(gnb_ue_ngap_id)) == NULL) {
gnb_ue_ngap_id)) == NULL) {
NGAP_ERROR("[SCTP %d] Received NAS downlink message for non existing UE context gNB_UE_NGAP_ID: 0x%lx\n", NGAP_ERROR("[SCTP %d] Received NAS downlink message for non existing UE context gNB_UE_NGAP_ID: 0x%lx\n",
assoc_id, assoc_id,
gnb_ue_ngap_id); gnb_ue_ngap_id);
...@@ -384,11 +354,7 @@ int ngap_gNB_handle_nas_downlink(uint32_t assoc_id, ...@@ -384,11 +354,7 @@ int ngap_gNB_handle_nas_downlink(uint32_t assoc_id,
} else { } else {
/* We already have a amf ue ngap id check the received is the same */ /* We already have a amf ue ngap id check the received is the same */
if (ue_desc_p->amf_ue_ngap_id != amf_ue_ngap_id) { if (ue_desc_p->amf_ue_ngap_id != amf_ue_ngap_id) {
NGAP_ERROR("[SCTP %d] Mismatch in AMF UE NGAP ID (0x%lx != 0x%"PRIx64"\n", NGAP_ERROR("[SCTP %d] Mismatch in AMF UE NGAP ID (0x%lx != 0x%" PRIx64 "\n", assoc_id, amf_ue_ngap_id, (uint64_t)ue_desc_p->amf_ue_ngap_id);
assoc_id,
amf_ue_ngap_id,
(uint64_t)ue_desc_p->amf_ue_ngap_id
);
return -1; return -1;
} }
} }
...@@ -396,11 +362,7 @@ int ngap_gNB_handle_nas_downlink(uint32_t assoc_id, ...@@ -396,11 +362,7 @@ int ngap_gNB_handle_nas_downlink(uint32_t assoc_id,
NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_DownlinkNASTransport_IEs_t, ie, container, NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_DownlinkNASTransport_IEs_t, ie, container,
NGAP_ProtocolIE_ID_id_NAS_PDU, true); NGAP_ProtocolIE_ID_id_NAS_PDU, true);
/* Forward the NAS PDU to NR-RRC */ /* Forward the NAS PDU to NR-RRC */
ngap_gNB_itti_send_nas_downlink_ind(ngap_gNB_instance->instance, ngap_gNB_itti_send_nas_downlink_ind(ngap_gNB_instance->instance, ue_desc_p->gNB_ue_ngap_id, ie->value.choice.NAS_PDU.buf, ie->value.choice.NAS_PDU.size);
ue_desc_p->ue_initial_id,
ue_desc_p->gNB_ue_ngap_id,
ie->value.choice.NAS_PDU.buf,
ie->value.choice.NAS_PDU.size);
return 0; return 0;
} }
...@@ -412,9 +374,6 @@ int ngap_gNB_nas_uplink(instance_t instance, ngap_uplink_nas_t *ngap_uplink_nas_ ...@@ -412,9 +374,6 @@ int ngap_gNB_nas_uplink(instance_t instance, ngap_uplink_nas_t *ngap_uplink_nas_
struct ngap_gNB_ue_context_s *ue_context_p; struct ngap_gNB_ue_context_s *ue_context_p;
ngap_gNB_instance_t *ngap_gNB_instance_p; ngap_gNB_instance_t *ngap_gNB_instance_p;
NGAP_NGAP_PDU_t pdu; NGAP_NGAP_PDU_t pdu;
NGAP_UplinkNASTransport_t *out;
NGAP_UplinkNASTransport_IEs_t *ie;
NGAP_UserLocationInformationNR_t *userinfo_nr_p = NULL;
uint8_t *buffer; uint8_t *buffer;
uint32_t length; uint32_t length;
DevAssert(ngap_uplink_nas_p != NULL); DevAssert(ngap_uplink_nas_p != NULL);
...@@ -422,7 +381,7 @@ int ngap_gNB_nas_uplink(instance_t instance, ngap_uplink_nas_t *ngap_uplink_nas_ ...@@ -422,7 +381,7 @@ int ngap_gNB_nas_uplink(instance_t instance, ngap_uplink_nas_t *ngap_uplink_nas_
ngap_gNB_instance_p = ngap_gNB_get_instance(instance); ngap_gNB_instance_p = ngap_gNB_get_instance(instance);
DevAssert(ngap_gNB_instance_p != NULL); DevAssert(ngap_gNB_instance_p != NULL);
if ((ue_context_p = ngap_gNB_get_ue_context(ngap_gNB_instance_p, ngap_uplink_nas_p->gNB_ue_ngap_id)) == NULL) { if ((ue_context_p = ngap_get_ue_context(ngap_uplink_nas_p->gNB_ue_ngap_id)) == NULL) {
/* The context for this gNB ue ngap id doesn't exist in the map of gNB UEs */ /* The context for this gNB ue ngap id doesn't exist in the map of gNB UEs */
NGAP_WARN("Failed to find ue context associated with gNB ue ngap id: %08x\n", NGAP_WARN("Failed to find ue context associated with gNB ue ngap id: %08x\n",
ngap_uplink_nas_p->gNB_ue_ngap_id); ngap_uplink_nas_p->gNB_ue_ngap_id);
...@@ -432,8 +391,7 @@ int ngap_gNB_nas_uplink(instance_t instance, ngap_uplink_nas_t *ngap_uplink_nas_ ...@@ -432,8 +391,7 @@ int ngap_gNB_nas_uplink(instance_t instance, ngap_uplink_nas_t *ngap_uplink_nas_
/* Uplink NAS transport can occur either during an ngap connected state /* Uplink NAS transport can occur either during an ngap connected state
* or during initial attach (for example: NAS authentication). * or during initial attach (for example: NAS authentication).
*/ */
if (!(ue_context_p->ue_state == NGAP_UE_CONNECTED || if (!(ue_context_p->ue_state == NGAP_UE_CONNECTED || ue_context_p->ue_state == NGAP_UE_WAITING_CSR)) {
ue_context_p->ue_state == NGAP_UE_WAITING_CSR)) {
NGAP_WARN("You are attempting to send NAS data over non-connected " NGAP_WARN("You are attempting to send NAS data over non-connected "
"gNB ue ngap id: %u, current state: %d\n", "gNB ue ngap id: %u, current state: %d\n",
ngap_uplink_nas_p->gNB_ue_ngap_id, ue_context_p->ue_state); ngap_uplink_nas_p->gNB_ue_ngap_id, ue_context_p->ue_state);
...@@ -443,43 +401,46 @@ int ngap_gNB_nas_uplink(instance_t instance, ngap_uplink_nas_t *ngap_uplink_nas_ ...@@ -443,43 +401,46 @@ int ngap_gNB_nas_uplink(instance_t instance, ngap_uplink_nas_t *ngap_uplink_nas_
/* Prepare the NGAP message to encode */ /* Prepare the NGAP message to encode */
memset(&pdu, 0, sizeof(pdu)); memset(&pdu, 0, sizeof(pdu));
pdu.present = NGAP_NGAP_PDU_PR_initiatingMessage; pdu.present = NGAP_NGAP_PDU_PR_initiatingMessage;
pdu.choice.initiatingMessage = (NGAP_InitiatingMessage_t *)calloc(1,sizeof(NGAP_InitiatingMessage_t)); asn1cCalloc(pdu.choice.initiatingMessage, head);
pdu.choice.initiatingMessage->procedureCode = NGAP_ProcedureCode_id_UplinkNASTransport; head->procedureCode = NGAP_ProcedureCode_id_UplinkNASTransport;
pdu.choice.initiatingMessage->criticality = NGAP_Criticality_ignore; head->criticality = NGAP_Criticality_ignore;
pdu.choice.initiatingMessage->value.present = NGAP_InitiatingMessage__value_PR_UplinkNASTransport; head->value.present = NGAP_InitiatingMessage__value_PR_UplinkNASTransport;
out = &pdu.choice.initiatingMessage->value.choice.UplinkNASTransport; NGAP_UplinkNASTransport_t *out = &head->value.choice.UplinkNASTransport;
/* mandatory */ /* mandatory */
ie = (NGAP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(NGAP_UplinkNASTransport_IEs_t)); {
asn1cSequenceAdd(out->protocolIEs.list, NGAP_UplinkNASTransport_IEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID; ie->id = NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID;
ie->criticality = NGAP_Criticality_reject; ie->criticality = NGAP_Criticality_reject;
ie->value.present = NGAP_UplinkNASTransport_IEs__value_PR_AMF_UE_NGAP_ID; ie->value.present = NGAP_UplinkNASTransport_IEs__value_PR_AMF_UE_NGAP_ID;
//ie->value.choice.AMF_UE_NGAP_ID = ue_context_p->amf_ue_ngap_id; // ie->value.choice.AMF_UE_NGAP_ID = ue_context_p->amf_ue_ngap_id;
asn_uint642INTEGER(&ie->value.choice.AMF_UE_NGAP_ID, ue_context_p->amf_ue_ngap_id); asn_uint642INTEGER(&ie->value.choice.AMF_UE_NGAP_ID, ue_context_p->amf_ue_ngap_id);
asn1cSeqAdd(&out->protocolIEs.list, ie); }
/* mandatory */ /* mandatory */
ie = (NGAP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(NGAP_UplinkNASTransport_IEs_t)); {
asn1cSequenceAdd(out->protocolIEs.list, NGAP_UplinkNASTransport_IEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID; ie->id = NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID;
ie->criticality = NGAP_Criticality_reject; ie->criticality = NGAP_Criticality_reject;
ie->value.present = NGAP_UplinkNASTransport_IEs__value_PR_RAN_UE_NGAP_ID; ie->value.present = NGAP_UplinkNASTransport_IEs__value_PR_RAN_UE_NGAP_ID;
ie->value.choice.RAN_UE_NGAP_ID = ue_context_p->gNB_ue_ngap_id; ie->value.choice.RAN_UE_NGAP_ID = ue_context_p->gNB_ue_ngap_id;
asn1cSeqAdd(&out->protocolIEs.list, ie); }
/* mandatory */ /* mandatory */
ie = (NGAP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(NGAP_UplinkNASTransport_IEs_t)); {
asn1cSequenceAdd(out->protocolIEs.list, NGAP_UplinkNASTransport_IEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_NAS_PDU; ie->id = NGAP_ProtocolIE_ID_id_NAS_PDU;
ie->criticality = NGAP_Criticality_reject; ie->criticality = NGAP_Criticality_reject;
ie->value.present = NGAP_UplinkNASTransport_IEs__value_PR_NAS_PDU; ie->value.present = NGAP_UplinkNASTransport_IEs__value_PR_NAS_PDU;
ie->value.choice.NAS_PDU.buf = ngap_uplink_nas_p->nas_pdu.buffer; ie->value.choice.NAS_PDU.buf = ngap_uplink_nas_p->nas_pdu.buffer;
ie->value.choice.NAS_PDU.size = ngap_uplink_nas_p->nas_pdu.length; ie->value.choice.NAS_PDU.size = ngap_uplink_nas_p->nas_pdu.length;
asn1cSeqAdd(&out->protocolIEs.list, ie); }
/* mandatory */ /* mandatory */
ie = (NGAP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(NGAP_UplinkNASTransport_IEs_t)); {
asn1cSequenceAdd(out->protocolIEs.list, NGAP_UplinkNASTransport_IEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_UserLocationInformation; ie->id = NGAP_ProtocolIE_ID_id_UserLocationInformation;
ie->criticality = NGAP_Criticality_ignore; ie->criticality = NGAP_Criticality_ignore;
ie->value.present = NGAP_UplinkNASTransport_IEs__value_PR_UserLocationInformation; ie->value.present = NGAP_UplinkNASTransport_IEs__value_PR_UserLocationInformation;
ie->value.choice.UserLocationInformation.present = NGAP_UserLocationInformation_PR_userLocationInformationNR; ie->value.choice.UserLocationInformation.present = NGAP_UserLocationInformation_PR_userLocationInformationNR;
ie->value.choice.UserLocationInformation.choice.userLocationInformationNR = CALLOC(1,sizeof(struct NGAP_UserLocationInformationNR)); asn1cCalloc(ie->value.choice.UserLocationInformation.choice.userLocationInformationNR, userinfo_nr_p);
userinfo_nr_p = ie->value.choice.UserLocationInformation.choice.userLocationInformationNR;
/* Set nRCellIdentity. default userLocationInformationNR */ /* Set nRCellIdentity. default userLocationInformationNR */
MACRO_GNB_ID_TO_CELL_IDENTITY(ngap_gNB_instance_p->gNB_id, MACRO_GNB_ID_TO_CELL_IDENTITY(ngap_gNB_instance_p->gNB_id,
...@@ -496,10 +457,7 @@ int ngap_gNB_nas_uplink(instance_t instance, ngap_uplink_nas_t *ngap_uplink_nas_ ...@@ -496,10 +457,7 @@ int ngap_gNB_nas_uplink(instance_t instance, ngap_uplink_nas_t *ngap_uplink_nas_
ngap_gNB_instance_p->mnc[ue_context_p->selected_plmn_identity], ngap_gNB_instance_p->mnc[ue_context_p->selected_plmn_identity],
ngap_gNB_instance_p->mnc_digit_length[ue_context_p->selected_plmn_identity], ngap_gNB_instance_p->mnc_digit_length[ue_context_p->selected_plmn_identity],
&userinfo_nr_p->tAI.pLMNIdentity); &userinfo_nr_p->tAI.pLMNIdentity);
}
asn1cSeqAdd(&out->protocolIEs.list, ie);
if (ngap_gNB_encode_pdu(&pdu, &buffer, &length) < 0) { if (ngap_gNB_encode_pdu(&pdu, &buffer, &length) < 0) {
NGAP_ERROR("Failed to encode uplink NAS transport\n"); NGAP_ERROR("Failed to encode uplink NAS transport\n");
/* Encode procedure has failed... */ /* Encode procedure has failed... */
...@@ -523,8 +481,6 @@ int ngap_gNB_nas_non_delivery_ind(instance_t instance, ...@@ -523,8 +481,6 @@ int ngap_gNB_nas_non_delivery_ind(instance_t instance,
struct ngap_gNB_ue_context_s *ue_context_p; struct ngap_gNB_ue_context_s *ue_context_p;
ngap_gNB_instance_t *ngap_gNB_instance_p; ngap_gNB_instance_t *ngap_gNB_instance_p;
NGAP_NGAP_PDU_t pdu; NGAP_NGAP_PDU_t pdu;
NGAP_NASNonDeliveryIndication_t *out;
NGAP_NASNonDeliveryIndication_IEs_t *ie;
uint8_t *buffer; uint8_t *buffer;
uint32_t length; uint32_t length;
DevAssert(ngap_nas_non_delivery_ind != NULL); DevAssert(ngap_nas_non_delivery_ind != NULL);
...@@ -532,7 +488,7 @@ int ngap_gNB_nas_non_delivery_ind(instance_t instance, ...@@ -532,7 +488,7 @@ int ngap_gNB_nas_non_delivery_ind(instance_t instance,
ngap_gNB_instance_p = ngap_gNB_get_instance(instance); ngap_gNB_instance_p = ngap_gNB_get_instance(instance);
DevAssert(ngap_gNB_instance_p != NULL); DevAssert(ngap_gNB_instance_p != NULL);
if ((ue_context_p = ngap_gNB_get_ue_context(ngap_gNB_instance_p, ngap_nas_non_delivery_ind->gNB_ue_ngap_id)) == NULL) { if ((ue_context_p = ngap_get_ue_context(ngap_nas_non_delivery_ind->gNB_ue_ngap_id)) == NULL) {
/* The context for this gNB ue ngap id doesn't exist in the map of gNB UEs */ /* The context for this gNB ue ngap id doesn't exist in the map of gNB UEs */
NGAP_WARN("Failed to find ue context associated with gNB ue ngap id: %08x\n", NGAP_WARN("Failed to find ue context associated with gNB ue ngap id: %08x\n",
ngap_nas_non_delivery_ind->gNB_ue_ngap_id); ngap_nas_non_delivery_ind->gNB_ue_ngap_id);
...@@ -542,42 +498,46 @@ int ngap_gNB_nas_non_delivery_ind(instance_t instance, ...@@ -542,42 +498,46 @@ int ngap_gNB_nas_non_delivery_ind(instance_t instance,
/* Prepare the NGAP message to encode */ /* Prepare the NGAP message to encode */
memset(&pdu, 0, sizeof(pdu)); memset(&pdu, 0, sizeof(pdu));
pdu.present = NGAP_NGAP_PDU_PR_initiatingMessage; pdu.present = NGAP_NGAP_PDU_PR_initiatingMessage;
pdu.choice.initiatingMessage = (NGAP_InitiatingMessage_t *)calloc(1,sizeof(NGAP_InitiatingMessage_t)); asn1cCalloc(pdu.choice.initiatingMessage, head);
pdu.choice.initiatingMessage->procedureCode = NGAP_ProcedureCode_id_NASNonDeliveryIndication; head->procedureCode = NGAP_ProcedureCode_id_NASNonDeliveryIndication;
pdu.choice.initiatingMessage->criticality = NGAP_Criticality_ignore; head->criticality = NGAP_Criticality_ignore;
pdu.choice.initiatingMessage->value.present = NGAP_InitiatingMessage__value_PR_NASNonDeliveryIndication; head->value.present = NGAP_InitiatingMessage__value_PR_NASNonDeliveryIndication;
out = &pdu.choice.initiatingMessage->value.choice.NASNonDeliveryIndication; NGAP_NASNonDeliveryIndication_t *out = &head->value.choice.NASNonDeliveryIndication;
/* mandatory */ /* mandatory */
ie = (NGAP_NASNonDeliveryIndication_IEs_t *)calloc(1, sizeof(NGAP_NASNonDeliveryIndication_IEs_t)); {
asn1cSequenceAdd(out->protocolIEs.list, NGAP_NASNonDeliveryIndication_IEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID; ie->id = NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID;
ie->criticality = NGAP_Criticality_reject; ie->criticality = NGAP_Criticality_reject;
ie->value.present = NGAP_NASNonDeliveryIndication_IEs__value_PR_AMF_UE_NGAP_ID; ie->value.present = NGAP_NASNonDeliveryIndication_IEs__value_PR_AMF_UE_NGAP_ID;
asn_uint642INTEGER(&ie->value.choice.AMF_UE_NGAP_ID, ue_context_p->amf_ue_ngap_id); asn_uint642INTEGER(&ie->value.choice.AMF_UE_NGAP_ID, ue_context_p->amf_ue_ngap_id);
asn1cSeqAdd(&out->protocolIEs.list, ie); }
/* mandatory */ /* mandatory */
ie = (NGAP_NASNonDeliveryIndication_IEs_t *)calloc(1, sizeof(NGAP_NASNonDeliveryIndication_IEs_t)); {
asn1cSequenceAdd(out->protocolIEs.list, NGAP_NASNonDeliveryIndication_IEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID; ie->id = NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID;
ie->criticality = NGAP_Criticality_reject; ie->criticality = NGAP_Criticality_reject;
ie->value.present = NGAP_NASNonDeliveryIndication_IEs__value_PR_RAN_UE_NGAP_ID; ie->value.present = NGAP_NASNonDeliveryIndication_IEs__value_PR_RAN_UE_NGAP_ID;
ie->value.choice.RAN_UE_NGAP_ID = ue_context_p->gNB_ue_ngap_id; ie->value.choice.RAN_UE_NGAP_ID = ue_context_p->gNB_ue_ngap_id;
asn1cSeqAdd(&out->protocolIEs.list, ie); }
/* mandatory */ /* mandatory */
ie = (NGAP_NASNonDeliveryIndication_IEs_t *)calloc(1, sizeof(NGAP_NASNonDeliveryIndication_IEs_t)); {
asn1cSequenceAdd(out->protocolIEs.list, NGAP_NASNonDeliveryIndication_IEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_NAS_PDU; ie->id = NGAP_ProtocolIE_ID_id_NAS_PDU;
ie->criticality = NGAP_Criticality_ignore; ie->criticality = NGAP_Criticality_ignore;
ie->value.present = NGAP_NASNonDeliveryIndication_IEs__value_PR_NAS_PDU; ie->value.present = NGAP_NASNonDeliveryIndication_IEs__value_PR_NAS_PDU;
ie->value.choice.NAS_PDU.buf = ngap_nas_non_delivery_ind->nas_pdu.buffer; ie->value.choice.NAS_PDU.buf = ngap_nas_non_delivery_ind->nas_pdu.buffer;
ie->value.choice.NAS_PDU.size = ngap_nas_non_delivery_ind->nas_pdu.length; ie->value.choice.NAS_PDU.size = ngap_nas_non_delivery_ind->nas_pdu.length;
asn1cSeqAdd(&out->protocolIEs.list, ie); }
/* mandatory */ /* mandatory */
ie = (NGAP_NASNonDeliveryIndication_IEs_t *)calloc(1, sizeof(NGAP_NASNonDeliveryIndication_IEs_t)); {
asn1cSequenceAdd(out->protocolIEs.list, NGAP_NASNonDeliveryIndication_IEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_Cause; ie->id = NGAP_ProtocolIE_ID_id_Cause;
ie->criticality = NGAP_Criticality_ignore; ie->criticality = NGAP_Criticality_ignore;
/* Send a dummy cause */ /* Send a dummy cause */
ie->value.present = NGAP_NASNonDeliveryIndication_IEs__value_PR_Cause; ie->value.present = NGAP_NASNonDeliveryIndication_IEs__value_PR_Cause;
ie->value.choice.Cause.present = NGAP_Cause_PR_radioNetwork; ie->value.choice.Cause.present = NGAP_Cause_PR_radioNetwork;
ie->value.choice.Cause.choice.radioNetwork = NGAP_CauseRadioNetwork_radio_connection_with_ue_lost; ie->value.choice.Cause.choice.radioNetwork = NGAP_CauseRadioNetwork_radio_connection_with_ue_lost;
asn1cSeqAdd(&out->protocolIEs.list, ie); }
if (ngap_gNB_encode_pdu(&pdu, &buffer, &length) < 0) { if (ngap_gNB_encode_pdu(&pdu, &buffer, &length) < 0) {
NGAP_ERROR("Failed to encode NAS NON delivery indication\n"); NGAP_ERROR("Failed to encode NAS NON delivery indication\n");
...@@ -594,30 +554,23 @@ int ngap_gNB_nas_non_delivery_ind(instance_t instance, ...@@ -594,30 +554,23 @@ int ngap_gNB_nas_non_delivery_ind(instance_t instance,
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int ngap_gNB_initial_ctxt_resp( int ngap_gNB_initial_ctxt_resp(instance_t instance, ngap_initial_context_setup_resp_t *initial_ctxt_resp_p)
instance_t instance, ngap_initial_context_setup_resp_t *initial_ctxt_resp_p)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
{ {
ngap_gNB_instance_t *ngap_gNB_instance_p = NULL; ngap_gNB_instance_t *ngap_gNB_instance_p = NULL;
struct ngap_gNB_ue_context_s *ue_context_p = NULL; struct ngap_gNB_ue_context_s *ue_context_p = NULL;
NGAP_NGAP_PDU_t pdu; NGAP_NGAP_PDU_t pdu;
NGAP_InitialContextSetupResponse_t *out;
NGAP_InitialContextSetupResponseIEs_t *ie;
uint8_t *buffer = NULL; uint8_t *buffer = NULL;
uint8_t pdusessionTransfer_buffer[1000];
uint32_t length; uint32_t length;
int i; int i;
asn_encode_to_new_buffer_result_t res = { NULL, {0, NULL, NULL} };
/* Retrieve the NGAP gNB instance associated with Mod_id */ /* Retrieve the NGAP gNB instance associated with Mod_id */
ngap_gNB_instance_p = ngap_gNB_get_instance(instance); ngap_gNB_instance_p = ngap_gNB_get_instance(instance);
DevAssert(initial_ctxt_resp_p != NULL); DevAssert(initial_ctxt_resp_p != NULL);
DevAssert(ngap_gNB_instance_p != NULL); DevAssert(ngap_gNB_instance_p != NULL);
if ((ue_context_p = ngap_gNB_get_ue_context(ngap_gNB_instance_p, if ((ue_context_p = ngap_get_ue_context(initial_ctxt_resp_p->gNB_ue_ngap_id)) == NULL) {
initial_ctxt_resp_p->gNB_ue_ngap_id)) == NULL) {
/* The context for this gNB ue ngap id doesn't exist in the map of gNB UEs */ /* The context for this gNB ue ngap id doesn't exist in the map of gNB UEs */
NGAP_WARN("Failed to find ue context associated with gNB ue ngap id: 0x%08x\n", NGAP_WARN("Failed to find ue context associated with gNB ue ngap id: 0x%08x\n",
initial_ctxt_resp_p->gNB_ue_ngap_id); initial_ctxt_resp_p->gNB_ue_ngap_id);
...@@ -627,8 +580,7 @@ int ngap_gNB_initial_ctxt_resp( ...@@ -627,8 +580,7 @@ int ngap_gNB_initial_ctxt_resp(
/* Uplink NAS transport can occur either during an ngap connected state /* Uplink NAS transport can occur either during an ngap connected state
* or during initial attach (for example: NAS authentication). * or during initial attach (for example: NAS authentication).
*/ */
if (!(ue_context_p->ue_state == NGAP_UE_CONNECTED || if (!(ue_context_p->ue_state == NGAP_UE_CONNECTED || ue_context_p->ue_state == NGAP_UE_WAITING_CSR)) {
ue_context_p->ue_state == NGAP_UE_WAITING_CSR)) {
NGAP_WARN("You are attempting to send NAS data over non-connected " NGAP_WARN("You are attempting to send NAS data over non-connected "
"gNB ue ngap id: %08x, current state: %d\n", "gNB ue ngap id: %08x, current state: %d\n",
initial_ctxt_resp_p->gNB_ue_ngap_id, ue_context_p->ue_state); initial_ctxt_resp_p->gNB_ue_ngap_id, ue_context_p->ue_state);
...@@ -638,142 +590,101 @@ int ngap_gNB_initial_ctxt_resp( ...@@ -638,142 +590,101 @@ int ngap_gNB_initial_ctxt_resp(
/* Prepare the NGAP message to encode */ /* Prepare the NGAP message to encode */
memset(&pdu, 0, sizeof(pdu)); memset(&pdu, 0, sizeof(pdu));
pdu.present = NGAP_NGAP_PDU_PR_successfulOutcome; pdu.present = NGAP_NGAP_PDU_PR_successfulOutcome;
pdu.choice.successfulOutcome = (NGAP_SuccessfulOutcome_t *)calloc(1,sizeof(struct NGAP_SuccessfulOutcome)); asn1cCalloc(pdu.choice.successfulOutcome, head);
pdu.choice.successfulOutcome->procedureCode = NGAP_ProcedureCode_id_InitialContextSetup; head->procedureCode = NGAP_ProcedureCode_id_InitialContextSetup;
pdu.choice.successfulOutcome->criticality = NGAP_Criticality_reject; head->criticality = NGAP_Criticality_reject;
pdu.choice.successfulOutcome->value.present = NGAP_SuccessfulOutcome__value_PR_InitialContextSetupResponse; head->value.present = NGAP_SuccessfulOutcome__value_PR_InitialContextSetupResponse;
out = &pdu.choice.successfulOutcome->value.choice.InitialContextSetupResponse; NGAP_InitialContextSetupResponse_t *out = &head->value.choice.InitialContextSetupResponse;
/* mandatory */ /* mandatory */
ie = (NGAP_InitialContextSetupResponseIEs_t *)calloc(1, sizeof(NGAP_InitialContextSetupResponseIEs_t)); {
asn1cSequenceAdd(out->protocolIEs.list, NGAP_InitialContextSetupResponseIEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID; ie->id = NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID;
ie->criticality = NGAP_Criticality_ignore; ie->criticality = NGAP_Criticality_ignore;
ie->value.present = NGAP_InitialContextSetupResponseIEs__value_PR_AMF_UE_NGAP_ID; ie->value.present = NGAP_InitialContextSetupResponseIEs__value_PR_AMF_UE_NGAP_ID;
//ie->value.choice.AMF_UE_NGAP_ID = ue_context_p->amf_ue_ngap_id; // ie->value.choice.AMF_UE_NGAP_ID = ue_context_p->amf_ue_ngap_id;
asn_uint642INTEGER(&ie->value.choice.AMF_UE_NGAP_ID, ue_context_p->amf_ue_ngap_id); asn_uint642INTEGER(&ie->value.choice.AMF_UE_NGAP_ID, ue_context_p->amf_ue_ngap_id);
asn1cSeqAdd(&out->protocolIEs.list, ie); }
/* mandatory */ /* mandatory */
ie = (NGAP_InitialContextSetupResponseIEs_t *)calloc(1, sizeof(NGAP_InitialContextSetupResponseIEs_t)); {
asn1cSequenceAdd(out->protocolIEs.list, NGAP_InitialContextSetupResponseIEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID; ie->id = NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID;
ie->criticality = NGAP_Criticality_ignore; ie->criticality = NGAP_Criticality_ignore;
ie->value.present = NGAP_InitialContextSetupResponseIEs__value_PR_RAN_UE_NGAP_ID; ie->value.present = NGAP_InitialContextSetupResponseIEs__value_PR_RAN_UE_NGAP_ID;
ie->value.choice.RAN_UE_NGAP_ID = initial_ctxt_resp_p->gNB_ue_ngap_id; ie->value.choice.RAN_UE_NGAP_ID = initial_ctxt_resp_p->gNB_ue_ngap_id;
asn1cSeqAdd(&out->protocolIEs.list, ie); }
/* optional */ /* optional */
if (initial_ctxt_resp_p->nb_of_pdusessions){ if (initial_ctxt_resp_p->nb_of_pdusessions){
ie = (NGAP_InitialContextSetupResponseIEs_t *)calloc(1, sizeof(NGAP_InitialContextSetupResponseIEs_t)); asn1cSequenceAdd(out->protocolIEs.list, NGAP_InitialContextSetupResponseIEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_PDUSessionResourceSetupListCxtRes; ie->id = NGAP_ProtocolIE_ID_id_PDUSessionResourceSetupListCxtRes;
ie->criticality = NGAP_Criticality_ignore; ie->criticality = NGAP_Criticality_ignore;
ie->value.present = NGAP_InitialContextSetupResponseIEs__value_PR_PDUSessionResourceSetupListCxtRes; ie->value.present = NGAP_InitialContextSetupResponseIEs__value_PR_PDUSessionResourceSetupListCxtRes;
for (i = 0; i < initial_ctxt_resp_p->nb_of_pdusessions; i++) { for (i = 0; i < initial_ctxt_resp_p->nb_of_pdusessions; i++) {
NGAP_PDUSessionResourceSetupItemCxtRes_t *item; asn1cSequenceAdd(ie->value.choice.PDUSessionResourceSetupListCxtRes.list, NGAP_PDUSessionResourceSetupItemCxtRes_t, item);
NGAP_PDUSessionResourceSetupResponseTransfer_t *pdusessionTransfer_p = NULL;
/* mandatory */
item = (NGAP_PDUSessionResourceSetupItemCxtRes_t *)calloc(1, sizeof(NGAP_PDUSessionResourceSetupItemCxtRes_t));
/* pDUSessionID */ /* pDUSessionID */
item->pDUSessionID = initial_ctxt_resp_p->pdusessions[i].pdusession_id; item->pDUSessionID = initial_ctxt_resp_p->pdusessions[i].pdusession_id;
/* dLQosFlowPerTNLInformation */ /* dLQosFlowPerTNLInformation */
pdusessionTransfer_p = (NGAP_PDUSessionResourceSetupResponseTransfer_t *)calloc(1, sizeof(NGAP_PDUSessionResourceSetupResponseTransfer_t)); NGAP_PDUSessionResourceSetupResponseTransfer_t pdusessionTransfer = {0};
pdusessionTransfer_p->dLQosFlowPerTNLInformation.uPTransportLayerInformation.present = NGAP_UPTransportLayerInformation_PR_gTPTunnel; pdusessionTransfer.dLQosFlowPerTNLInformation.uPTransportLayerInformation.present = NGAP_UPTransportLayerInformation_PR_gTPTunnel;
pdusessionTransfer_p->dLQosFlowPerTNLInformation.uPTransportLayerInformation.choice.gTPTunnel = (NGAP_GTPTunnel_t *)calloc(1, sizeof(NGAP_GTPTunnel_t)); asn1cCalloc(pdusessionTransfer.dLQosFlowPerTNLInformation.uPTransportLayerInformation.choice.gTPTunnel, tmp);
struct NGAP_GTPTunnel *tmp=pdusessionTransfer_p->dLQosFlowPerTNLInformation.uPTransportLayerInformation.choice.gTPTunnel;
GTP_TEID_TO_ASN1(initial_ctxt_resp_p->pdusessions[i].gtp_teid, &tmp->gTP_TEID); GTP_TEID_TO_ASN1(initial_ctxt_resp_p->pdusessions[i].gtp_teid, &tmp->gTP_TEID);
allocAddrCopy(&tmp->transportLayerAddress, initial_ctxt_resp_p->pdusessions[i].gNB_addr);
tmp->transportLayerAddress.buf = malloc(initial_ctxt_resp_p->pdusessions[i].gNB_addr.length); NGAP_DEBUG("initial_ctxt_resp_p: pdusession ID %ld\n", item->pDUSessionID);
memcpy(tmp->transportLayerAddress.buf,
initial_ctxt_resp_p->pdusessions[i].gNB_addr.buffer,
initial_ctxt_resp_p->pdusessions[i].gNB_addr.length);
tmp->transportLayerAddress.size = initial_ctxt_resp_p->pdusessions[i].gNB_addr.length;
tmp->transportLayerAddress.bits_unused = 0;
NGAP_DEBUG("initial_ctxt_resp_p: pdusession ID %ld\n",
item->pDUSessionID);
/* associatedQosFlowList. number of 1? */ /* associatedQosFlowList. number of 1? */
for(int j=0; j < initial_ctxt_resp_p->pdusessions[i].nb_of_qos_flow; j++) { for(int j=0; j < initial_ctxt_resp_p->pdusessions[i].nb_of_qos_flow; j++) {
NGAP_AssociatedQosFlowItem_t *ass_qos_item_p; asn1cSequenceAdd(pdusessionTransfer.dLQosFlowPerTNLInformation.associatedQosFlowList.list, NGAP_AssociatedQosFlowItem_t, ass_qos_item_p);
ass_qos_item_p = (NGAP_AssociatedQosFlowItem_t *)calloc(1, sizeof(NGAP_AssociatedQosFlowItem_t));
/* qosFlowIdentifier */ /* qosFlowIdentifier */
ass_qos_item_p->qosFlowIdentifier = initial_ctxt_resp_p->pdusessions[i].associated_qos_flows[j].qfi; 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;
// }
asn1cSeqAdd(&pdusessionTransfer_p->dLQosFlowPerTNLInformation.associatedQosFlowList.list, ass_qos_item_p);
}
//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;
if (asn1_xer_print) {
xer_fprint(stdout, &asn_DEF_NGAP_PDUSessionResourceSetupResponseTransfer, pdusessionTransfer_p);
} }
memset(pdusessionTransfer_buffer, 0, 1000); void *pdusessionTransfer_buffer;
asn_enc_rval_t enc_rval = aper_encode_to_buffer(&asn_DEF_NGAP_PDUSessionResourceSetupResponseTransfer, ssize_t encoded = aper_encode_to_new_buffer(&asn_DEF_NGAP_PDUSessionResourceSetupResponseTransfer, NULL, &pdusessionTransfer, &pdusessionTransfer_buffer);
NULL, AssertFatal(encoded > 0, "ASN1 message encoding failed !\n");
pdusessionTransfer_p,
pdusessionTransfer_buffer,1000);
AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n", enc_rval.failed_type->name, enc_rval.encoded);
item->pDUSessionResourceSetupResponseTransfer.buf = pdusessionTransfer_buffer; item->pDUSessionResourceSetupResponseTransfer.buf = pdusessionTransfer_buffer;
item->pDUSessionResourceSetupResponseTransfer.size = enc_rval.encoded; item->pDUSessionResourceSetupResponseTransfer.size = encoded;
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_NGAP_PDUSessionResourceSetupResponseTransfer, pdusessionTransfer_p); ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_NGAP_PDUSessionResourceSetupResponseTransfer, &pdusessionTransfer);
asn1cSeqAdd(&ie->value.choice.PDUSessionResourceSetupListCxtRes.list, item);
} }
asn1cSeqAdd(&out->protocolIEs.list, ie);
} }
/* optional */ /* optional */
if (initial_ctxt_resp_p->nb_of_pdusessions_failed) { if (initial_ctxt_resp_p->nb_of_pdusessions_failed) {
ie = (NGAP_InitialContextSetupResponseIEs_t *)calloc(1, sizeof(NGAP_InitialContextSetupResponseIEs_t)); asn1cSequenceAdd(out->protocolIEs.list, NGAP_InitialContextSetupResponseIEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_PDUSessionResourceFailedToSetupListCxtRes; ie->id = NGAP_ProtocolIE_ID_id_PDUSessionResourceFailedToSetupListCxtRes;
ie->criticality = NGAP_Criticality_ignore; ie->criticality = NGAP_Criticality_ignore;
ie->value.present = NGAP_InitialContextSetupResponseIEs__value_PR_PDUSessionResourceFailedToSetupListCxtRes; ie->value.present = NGAP_InitialContextSetupResponseIEs__value_PR_PDUSessionResourceFailedToSetupListCxtRes;
for (i = 0; i < initial_ctxt_resp_p->nb_of_pdusessions_failed; i++) { for (i = 0; i < initial_ctxt_resp_p->nb_of_pdusessions_failed; i++) {
NGAP_PDUSessionResourceFailedToSetupItemCxtRes_t *item = calloc(1, sizeof *item); asn1cSequenceAdd(ie->value.choice.PDUSessionResourceFailedToSetupListCxtRes.list, NGAP_PDUSessionResourceFailedToSetupItemCxtRes_t, item);
NGAP_PDUSessionResourceSetupUnsuccessfulTransfer_t *pdusessionUnTransfer_p = calloc(1, sizeof *pdusessionUnTransfer_p); NGAP_PDUSessionResourceSetupUnsuccessfulTransfer_t pdusessionUnTransfer = {0};
/* pDUSessionID */ /* pDUSessionID */
item->pDUSessionID = initial_ctxt_resp_p->pdusessions_failed[i].pdusession_id; item->pDUSessionID = initial_ctxt_resp_p->pdusessions_failed[i].pdusession_id;
/* cause */ /* cause */
switch(initial_ctxt_resp_p->pdusessions_failed[i].cause) { pdusessionUnTransfer.cause.present = initial_ctxt_resp_p->pdusessions_failed[i].cause;
switch (pdusessionUnTransfer.cause.present) {
case NGAP_CAUSE_RADIO_NETWORK: case NGAP_CAUSE_RADIO_NETWORK:
pdusessionUnTransfer_p->cause.present = NGAP_Cause_PR_radioNetwork; pdusessionUnTransfer.cause.choice.radioNetwork = initial_ctxt_resp_p->pdusessions_failed[i].cause_value;
pdusessionUnTransfer_p->cause.choice.radioNetwork = initial_ctxt_resp_p->pdusessions_failed[i].cause_value;
break; break;
case NGAP_CAUSE_TRANSPORT: case NGAP_CAUSE_TRANSPORT:
pdusessionUnTransfer_p->cause.present = NGAP_Cause_PR_transport; pdusessionUnTransfer.cause.choice.transport = initial_ctxt_resp_p->pdusessions_failed[i].cause_value;
pdusessionUnTransfer_p->cause.choice.transport = initial_ctxt_resp_p->pdusessions_failed[i].cause_value;
break; break;
case NGAP_CAUSE_NAS: case NGAP_CAUSE_NAS:
pdusessionUnTransfer_p->cause.present = NGAP_Cause_PR_nas; pdusessionUnTransfer.cause.choice.nas = initial_ctxt_resp_p->pdusessions_failed[i].cause_value;
pdusessionUnTransfer_p->cause.choice.nas = initial_ctxt_resp_p->pdusessions_failed[i].cause_value;
break; break;
case NGAP_CAUSE_PROTOCOL: case NGAP_CAUSE_PROTOCOL:
pdusessionUnTransfer_p->cause.present = NGAP_Cause_PR_protocol; pdusessionUnTransfer.cause.choice.protocol = initial_ctxt_resp_p->pdusessions_failed[i].cause_value;
pdusessionUnTransfer_p->cause.choice.protocol = initial_ctxt_resp_p->pdusessions_failed[i].cause_value;
break; break;
case NGAP_CAUSE_MISC: case NGAP_CAUSE_MISC:
pdusessionUnTransfer_p->cause.present = NGAP_Cause_PR_misc; pdusessionUnTransfer.cause.choice.misc = initial_ctxt_resp_p->pdusessions_failed[i].cause_value;
pdusessionUnTransfer_p->cause.choice.misc = initial_ctxt_resp_p->pdusessions_failed[i].cause_value;
break; break;
case NGAP_CAUSE_NOTHING: case NGAP_CAUSE_NOTHING:
...@@ -782,27 +693,22 @@ int ngap_gNB_initial_ctxt_resp( ...@@ -782,27 +693,22 @@ int ngap_gNB_initial_ctxt_resp(
} }
NGAP_DEBUG("initial context setup response: failed pdusession ID %ld\n", item->pDUSessionID); NGAP_DEBUG("initial context setup response: failed pdusession ID %ld\n", item->pDUSessionID);
asn_encode_to_new_buffer_result_t res = asn_encode_to_new_buffer(NULL, ATS_ALIGNED_CANONICAL_PER, &asn_DEF_NGAP_PDUSessionResourceSetupUnsuccessfulTransfer, &pdusessionUnTransfer);
memset(&res, 0, sizeof(res)); AssertFatal(res.buffer, "ASN1 message encoding failed (%s, %lu)!\n", res.result.failed_type->name, res.result.encoded);
res = asn_encode_to_new_buffer(NULL, ATS_ALIGNED_CANONICAL_PER, &asn_DEF_NGAP_PDUSessionResourceSetupUnsuccessfulTransfer, pdusessionUnTransfer_p);
item->pDUSessionResourceSetupUnsuccessfulTransfer.buf = res.buffer; item->pDUSessionResourceSetupUnsuccessfulTransfer.buf = res.buffer;
item->pDUSessionResourceSetupUnsuccessfulTransfer.size = res.result.encoded; item->pDUSessionResourceSetupUnsuccessfulTransfer.size = res.result.encoded;
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_NGAP_PDUSessionResourceSetupUnsuccessfulTransfer, pdusessionUnTransfer_p); ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_NGAP_PDUSessionResourceSetupUnsuccessfulTransfer, &pdusessionUnTransfer);
asn1cSeqAdd(&ie->value.choice.PDUSessionResourceFailedToSetupListCxtRes.list, item);
} }
asn1cSeqAdd(&out->protocolIEs.list, ie);
} }
/* optional */ /* optional */
if (0) { if (0) {
ie = (NGAP_InitialContextSetupResponseIEs_t *)calloc(1, sizeof(NGAP_InitialContextSetupResponseIEs_t)); asn1cSequenceAdd(out->protocolIEs.list, NGAP_InitialContextSetupResponseIEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_CriticalityDiagnostics; ie->id = NGAP_ProtocolIE_ID_id_CriticalityDiagnostics;
ie->criticality = NGAP_Criticality_ignore; ie->criticality = NGAP_Criticality_ignore;
ie->value.present = NGAP_InitialContextSetupResponseIEs__value_PR_CriticalityDiagnostics; ie->value.present = NGAP_InitialContextSetupResponseIEs__value_PR_CriticalityDiagnostics;
// ie->value.choice.CriticalityDiagnostics =; // ie->value.choice.CriticalityDiagnostics =;
asn1cSeqAdd(&out->protocolIEs.list, ie);
} }
if (asn1_xer_print) { if (asn1_xer_print) {
...@@ -817,23 +723,17 @@ int ngap_gNB_initial_ctxt_resp( ...@@ -817,23 +723,17 @@ int ngap_gNB_initial_ctxt_resp(
/* UE associated signalling -> use the allocated stream */ /* UE associated signalling -> use the allocated stream */
LOG_I(NR_RRC,"Send message to sctp: NGAP_InitialContextSetupResponse\n"); LOG_I(NR_RRC,"Send message to sctp: NGAP_InitialContextSetupResponse\n");
ngap_gNB_itti_send_sctp_data_req(ngap_gNB_instance_p->instance, ngap_gNB_itti_send_sctp_data_req(ngap_gNB_instance_p->instance, ue_context_p->amf_ref->assoc_id, buffer, length, ue_context_p->tx_stream);
ue_context_p->amf_ref->assoc_id, buffer,
length, ue_context_p->tx_stream);
return 0; return 0;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int ngap_gNB_ue_capabilities(instance_t instance, int ngap_gNB_ue_capabilities(instance_t instance, ngap_ue_cap_info_ind_t *ue_cap_info_ind_p)
ngap_ue_cap_info_ind_t *ue_cap_info_ind_p)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
{ {
ngap_gNB_instance_t *ngap_gNB_instance_p; ngap_gNB_instance_t *ngap_gNB_instance_p;
struct ngap_gNB_ue_context_s *ue_context_p; struct ngap_gNB_ue_context_s *ue_context_p;
NGAP_NGAP_PDU_t pdu;
NGAP_UERadioCapabilityInfoIndication_t *out;
NGAP_UERadioCapabilityInfoIndicationIEs_t *ie;
uint8_t *buffer; uint8_t *buffer;
uint32_t length; uint32_t length;
/* Retrieve the NGAP gNB instance associated with Mod_id */ /* Retrieve the NGAP gNB instance associated with Mod_id */
...@@ -841,56 +741,57 @@ int ngap_gNB_ue_capabilities(instance_t instance, ...@@ -841,56 +741,57 @@ int ngap_gNB_ue_capabilities(instance_t instance,
DevAssert(ue_cap_info_ind_p != NULL); DevAssert(ue_cap_info_ind_p != NULL);
DevAssert(ngap_gNB_instance_p != NULL); DevAssert(ngap_gNB_instance_p != NULL);
if ((ue_context_p = ngap_gNB_get_ue_context(ngap_gNB_instance_p, if ((ue_context_p = ngap_get_ue_context(ue_cap_info_ind_p->gNB_ue_ngap_id)) == NULL) {
ue_cap_info_ind_p->gNB_ue_ngap_id)) == NULL) {
/* The context for this gNB ue ngap id doesn't exist in the map of gNB UEs */ /* The context for this gNB ue ngap id doesn't exist in the map of gNB UEs */
NGAP_WARN("Failed to find ue context associated with gNB ue ngap id: %u\n", NGAP_WARN("Failed to find ue context associated with gNB ue ngap id: %u\n", ue_cap_info_ind_p->gNB_ue_ngap_id);
ue_cap_info_ind_p->gNB_ue_ngap_id);
return -1; return -1;
} }
/* UE radio capabilities message can occur either during an ngap connected state /* UE radio capabilities message can occur either during an ngap connected state
* or during initial attach (for example: NAS authentication). * or during initial attach (for example: NAS authentication).
*/ */
if (!(ue_context_p->ue_state == NGAP_UE_CONNECTED || if (!(ue_context_p->ue_state == NGAP_UE_CONNECTED || ue_context_p->ue_state == NGAP_UE_WAITING_CSR)) {
ue_context_p->ue_state == NGAP_UE_WAITING_CSR)) { NGAP_WARN(
NGAP_WARN("You are attempting to send NAS data over non-connected " "You are attempting to send NAS data over non-connected "
"gNB ue ngap id: %u, current state: %d\n", "gNB ue ngap id: %u, current state: %d\n",
ue_cap_info_ind_p->gNB_ue_ngap_id, ue_context_p->ue_state); ue_cap_info_ind_p->gNB_ue_ngap_id,
ue_context_p->ue_state);
return -1; return -1;
} }
/* Prepare the NGAP message to encode */ /* Prepare the NGAP message to encode */
memset(&pdu, 0, sizeof(pdu)); NGAP_NGAP_PDU_t pdu = {0};
pdu.present = NGAP_NGAP_PDU_PR_initiatingMessage; pdu.present = NGAP_NGAP_PDU_PR_initiatingMessage;
pdu.choice.initiatingMessage = (NGAP_InitiatingMessage_t *)calloc(1,sizeof(NGAP_InitiatingMessage_t)); asn1cCalloc(pdu.choice.initiatingMessage, head);
pdu.choice.initiatingMessage->procedureCode = NGAP_ProcedureCode_id_UERadioCapabilityInfoIndication; head->procedureCode = NGAP_ProcedureCode_id_UERadioCapabilityInfoIndication;
pdu.choice.initiatingMessage->criticality = NGAP_Criticality_ignore; head->criticality = NGAP_Criticality_ignore;
pdu.choice.initiatingMessage->value.present = NGAP_InitiatingMessage__value_PR_UERadioCapabilityInfoIndication; head->value.present = NGAP_InitiatingMessage__value_PR_UERadioCapabilityInfoIndication;
out = &pdu.choice.initiatingMessage->value.choice.UERadioCapabilityInfoIndication; NGAP_UERadioCapabilityInfoIndication_t *out = &head->value.choice.UERadioCapabilityInfoIndication;
/* mandatory */ /* mandatory */
ie = (NGAP_UERadioCapabilityInfoIndicationIEs_t *)calloc(1, sizeof(NGAP_UERadioCapabilityInfoIndicationIEs_t)); {
asn1cSequenceAdd(out->protocolIEs.list, NGAP_UERadioCapabilityInfoIndicationIEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID; ie->id = NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID;
ie->criticality = NGAP_Criticality_reject; ie->criticality = NGAP_Criticality_reject;
ie->value.present = NGAP_UERadioCapabilityInfoIndicationIEs__value_PR_AMF_UE_NGAP_ID; ie->value.present = NGAP_UERadioCapabilityInfoIndicationIEs__value_PR_AMF_UE_NGAP_ID;
//ie->value.choice.AMF_UE_NGAP_ID = ue_context_p->amf_ue_ngap_id;
asn_uint642INTEGER(&ie->value.choice.AMF_UE_NGAP_ID, ue_context_p->amf_ue_ngap_id); asn_uint642INTEGER(&ie->value.choice.AMF_UE_NGAP_ID, ue_context_p->amf_ue_ngap_id);
asn1cSeqAdd(&out->protocolIEs.list, ie); }
/* mandatory */ /* mandatory */
ie = (NGAP_UERadioCapabilityInfoIndicationIEs_t *)calloc(1, sizeof(NGAP_UERadioCapabilityInfoIndicationIEs_t)); {
asn1cSequenceAdd(out->protocolIEs.list, NGAP_UERadioCapabilityInfoIndicationIEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID; ie->id = NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID;
ie->criticality = NGAP_Criticality_reject; ie->criticality = NGAP_Criticality_reject;
ie->value.present = NGAP_UERadioCapabilityInfoIndicationIEs__value_PR_RAN_UE_NGAP_ID; ie->value.present = NGAP_UERadioCapabilityInfoIndicationIEs__value_PR_RAN_UE_NGAP_ID;
ie->value.choice.RAN_UE_NGAP_ID = ue_cap_info_ind_p->gNB_ue_ngap_id; ie->value.choice.RAN_UE_NGAP_ID = (int64_t)ue_cap_info_ind_p->gNB_ue_ngap_id;
asn1cSeqAdd(&out->protocolIEs.list, ie); }
/* mandatory */ /* mandatory */
ie = (NGAP_UERadioCapabilityInfoIndicationIEs_t *)calloc(1, sizeof(NGAP_UERadioCapabilityInfoIndicationIEs_t)); {
asn1cSequenceAdd(out->protocolIEs.list, NGAP_UERadioCapabilityInfoIndicationIEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_UERadioCapability; ie->id = NGAP_ProtocolIE_ID_id_UERadioCapability;
ie->criticality = NGAP_Criticality_ignore; ie->criticality = NGAP_Criticality_ignore;
ie->value.present = NGAP_UERadioCapabilityInfoIndicationIEs__value_PR_UERadioCapability; ie->value.present = NGAP_UERadioCapabilityInfoIndicationIEs__value_PR_UERadioCapability;
ie->value.choice.UERadioCapability.buf = ue_cap_info_ind_p->ue_radio_cap.buffer; ie->value.choice.UERadioCapability.buf = ue_cap_info_ind_p->ue_radio_cap.buffer;
ie->value.choice.UERadioCapability.size = ue_cap_info_ind_p->ue_radio_cap.length; ie->value.choice.UERadioCapability.size = ue_cap_info_ind_p->ue_radio_cap.length;
asn1cSeqAdd(&out->protocolIEs.list, ie); }
/* optional */ /* optional */
//NGAP_UERadioCapabilityForPaging TBD //NGAP_UERadioCapabilityForPaging TBD
if (ngap_gNB_encode_pdu(&pdu, &buffer, &length) < 0) { if (ngap_gNB_encode_pdu(&pdu, &buffer, &length) < 0) {
...@@ -900,22 +801,17 @@ int ngap_gNB_ue_capabilities(instance_t instance, ...@@ -900,22 +801,17 @@ int ngap_gNB_ue_capabilities(instance_t instance,
} }
/* UE associated signalling -> use the allocated stream */ /* UE associated signalling -> use the allocated stream */
ngap_gNB_itti_send_sctp_data_req(ngap_gNB_instance_p->instance, ngap_gNB_itti_send_sctp_data_req(ngap_gNB_instance_p->instance, ue_context_p->amf_ref->assoc_id, buffer, length, ue_context_p->tx_stream);
ue_context_p->amf_ref->assoc_id, buffer,
length, ue_context_p->tx_stream);
return 0; return 0;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int ngap_gNB_pdusession_setup_resp(instance_t instance, int ngap_gNB_pdusession_setup_resp(instance_t instance, ngap_pdusession_setup_resp_t *pdusession_setup_resp_p)
ngap_pdusession_setup_resp_t *pdusession_setup_resp_p)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
{ {
ngap_gNB_instance_t *ngap_gNB_instance_p = NULL; ngap_gNB_instance_t *ngap_gNB_instance_p = NULL;
struct ngap_gNB_ue_context_s *ue_context_p = NULL; struct ngap_gNB_ue_context_s *ue_context_p = NULL;
NGAP_NGAP_PDU_t pdu; NGAP_NGAP_PDU_t pdu = {0};
NGAP_PDUSessionResourceSetupResponse_t *out;
NGAP_PDUSessionResourceSetupResponseIEs_t *ie;
uint8_t *buffer = NULL; uint8_t *buffer = NULL;
uint32_t length; uint32_t length;
...@@ -924,78 +820,67 @@ int ngap_gNB_pdusession_setup_resp(instance_t instance, ...@@ -924,78 +820,67 @@ int ngap_gNB_pdusession_setup_resp(instance_t instance,
DevAssert(pdusession_setup_resp_p != NULL); DevAssert(pdusession_setup_resp_p != NULL);
DevAssert(ngap_gNB_instance_p != NULL); DevAssert(ngap_gNB_instance_p != NULL);
if ((ue_context_p = ngap_gNB_get_ue_context(ngap_gNB_instance_p, if ((ue_context_p = ngap_get_ue_context(pdusession_setup_resp_p->gNB_ue_ngap_id)) == NULL) {
pdusession_setup_resp_p->gNB_ue_ngap_id)) == NULL) {
/* The context for this gNB ue ngap id doesn't exist in the map of gNB UEs */ /* The context for this gNB ue ngap id doesn't exist in the map of gNB UEs */
NGAP_WARN("Failed to find ue context associated with gNB ue ngap id: 0x%08x\n", NGAP_WARN("Failed to find ue context associated with gNB ue ngap id: 0x%08x\n", pdusession_setup_resp_p->gNB_ue_ngap_id);
pdusession_setup_resp_p->gNB_ue_ngap_id);
return -1; return -1;
} }
/* Uplink NAS transport can occur either during an ngap connected state /* Uplink NAS transport can occur either during an ngap connected state
* or during initial attach (for example: NAS authentication). * or during initial attach (for example: NAS authentication).
*/ */
if (!(ue_context_p->ue_state == NGAP_UE_CONNECTED || if (!(ue_context_p->ue_state == NGAP_UE_CONNECTED || ue_context_p->ue_state == NGAP_UE_WAITING_CSR)) {
ue_context_p->ue_state == NGAP_UE_WAITING_CSR)) { NGAP_WARN(
NGAP_WARN("You are attempting to send NAS data over non-connected " "You are attempting to send NAS data over non-connected "
"gNB ue ngap id: %08x, current state: %d\n", "gNB ue ngap id: %08x, current state: %d\n",
pdusession_setup_resp_p->gNB_ue_ngap_id, ue_context_p->ue_state); pdusession_setup_resp_p->gNB_ue_ngap_id,
ue_context_p->ue_state);
return -1; return -1;
} }
/* Prepare the NGAP message to encode */ /* Prepare the NGAP message to encode */
memset(&pdu, 0, sizeof(pdu));
pdu.present = NGAP_NGAP_PDU_PR_successfulOutcome; pdu.present = NGAP_NGAP_PDU_PR_successfulOutcome;
pdu.choice.successfulOutcome = calloc(1,sizeof *pdu.choice.successfulOutcome); asn1cCalloc(pdu.choice.successfulOutcome, successfulOutcome);
pdu.choice.successfulOutcome->procedureCode = NGAP_ProcedureCode_id_PDUSessionResourceSetup; successfulOutcome->procedureCode = NGAP_ProcedureCode_id_PDUSessionResourceSetup;
pdu.choice.successfulOutcome->criticality = NGAP_Criticality_reject; successfulOutcome->criticality = NGAP_Criticality_reject;
pdu.choice.successfulOutcome->value.present = NGAP_SuccessfulOutcome__value_PR_PDUSessionResourceSetupResponse; successfulOutcome->value.present = NGAP_SuccessfulOutcome__value_PR_PDUSessionResourceSetupResponse;
out = &pdu.choice.successfulOutcome->value.choice.PDUSessionResourceSetupResponse; NGAP_PDUSessionResourceSetupResponse_t *out = &successfulOutcome->value.choice.PDUSessionResourceSetupResponse;
/* mandatory */ /* mandatory */
ie = calloc(1, sizeof *ie); {
asn1cSequenceAdd(out->protocolIEs.list, NGAP_PDUSessionResourceSetupResponseIEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID; ie->id = NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID;
ie->criticality = NGAP_Criticality_ignore; ie->criticality = NGAP_Criticality_ignore;
ie->value.present = NGAP_PDUSessionResourceSetupResponseIEs__value_PR_AMF_UE_NGAP_ID; ie->value.present = NGAP_PDUSessionResourceSetupResponseIEs__value_PR_AMF_UE_NGAP_ID;
asn_uint642INTEGER(&ie->value.choice.AMF_UE_NGAP_ID, ue_context_p->amf_ue_ngap_id); asn_uint642INTEGER(&ie->value.choice.AMF_UE_NGAP_ID, ue_context_p->amf_ue_ngap_id);
asn1cSeqAdd(&out->protocolIEs.list, ie); }
/* mandatory */ /* mandatory */
ie = calloc(1, sizeof *ie ); {
asn1cSequenceAdd(out->protocolIEs.list, NGAP_PDUSessionResourceSetupResponseIEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID; ie->id = NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID;
ie->criticality = NGAP_Criticality_ignore; ie->criticality = NGAP_Criticality_ignore;
ie->value.present = NGAP_PDUSessionResourceSetupResponseIEs__value_PR_RAN_UE_NGAP_ID; ie->value.present = NGAP_PDUSessionResourceSetupResponseIEs__value_PR_RAN_UE_NGAP_ID;
ie->value.choice.RAN_UE_NGAP_ID = pdusession_setup_resp_p->gNB_ue_ngap_id; ie->value.choice.RAN_UE_NGAP_ID = pdusession_setup_resp_p->gNB_ue_ngap_id;
asn1cSeqAdd(&out->protocolIEs.list, ie); }
/* optional */ /* optional */
if (pdusession_setup_resp_p->nb_of_pdusessions > 0) { if (pdusession_setup_resp_p->nb_of_pdusessions > 0) {
ie = calloc(1, sizeof *ie ); asn1cSequenceAdd(out->protocolIEs.list, NGAP_PDUSessionResourceSetupResponseIEs_t, ie3);
ie->id = NGAP_ProtocolIE_ID_id_PDUSessionResourceSetupListSURes; ie3->id = NGAP_ProtocolIE_ID_id_PDUSessionResourceSetupListSURes;
ie->criticality = NGAP_Criticality_ignore; ie3->criticality = NGAP_Criticality_ignore;
ie->value.present = NGAP_PDUSessionResourceSetupResponseIEs__value_PR_PDUSessionResourceSetupListSURes; ie3->value.present = NGAP_PDUSessionResourceSetupResponseIEs__value_PR_PDUSessionResourceSetupListSURes;
for (int i = 0; i < pdusession_setup_resp_p->nb_of_pdusessions; i++) { for (int i = 0; i < pdusession_setup_resp_p->nb_of_pdusessions; i++) {
NGAP_PDUSessionResourceSetupItemSURes_t *item=calloc(1, sizeof *item ); pdusession_setup_t *pdusession = pdusession_setup_resp_p->pdusessions + i;
NGAP_PDUSessionResourceSetupResponseTransfer_t *pdusessionTransfer_p = calloc(1, sizeof *pdusessionTransfer_p ); asn1cSequenceAdd(ie3->value.choice.PDUSessionResourceSetupListSURes.list, NGAP_PDUSessionResourceSetupItemSURes_t, item);
/* pDUSessionID */ /* pDUSessionID */
item->pDUSessionID = pdusession_setup_resp_p->pdusessions[i].pdusession_id; item->pDUSessionID = pdusession->pdusession_id;
/* dLQosFlowPerTNLInformation */ /* dLQosFlowPerTNLInformation */
NGAP_PDUSessionResourceSetupResponseTransfer_t pdusessionTransfer = {0};
pdusessionTransfer_p->dLQosFlowPerTNLInformation.uPTransportLayerInformation.present = NGAP_UPTransportLayerInformation_PR_gTPTunnel; pdusessionTransfer.dLQosFlowPerTNLInformation.uPTransportLayerInformation.present = NGAP_UPTransportLayerInformation_PR_gTPTunnel;
pdusessionTransfer_p->dLQosFlowPerTNLInformation.uPTransportLayerInformation.choice.gTPTunnel = asn1cCalloc(pdusessionTransfer.dLQosFlowPerTNLInformation.uPTransportLayerInformation.choice.gTPTunnel, tmp);
calloc(1, sizeof(struct NGAP_GTPTunnel)); GTP_TEID_TO_ASN1(pdusession->gtp_teid, &tmp->gTP_TEID);
struct NGAP_GTPTunnel *tmp=pdusessionTransfer_p->dLQosFlowPerTNLInformation.uPTransportLayerInformation.choice.gTPTunnel; allocAddrCopy(&tmp->transportLayerAddress, pdusession->gNB_addr);
GTP_TEID_TO_ASN1(pdusession_setup_resp_p->pdusessions[i].gtp_teid, &tmp->gTP_TEID);
if (pdusession_setup_resp_p->pdusessions[i].gNB_addr.length) {
tmp->transportLayerAddress.buf = malloc(pdusession_setup_resp_p->pdusessions[i].gNB_addr.length);
memcpy(tmp->transportLayerAddress.buf,
pdusession_setup_resp_p->pdusessions[i].gNB_addr.buffer,
pdusession_setup_resp_p->pdusessions[i].gNB_addr.length);
tmp->transportLayerAddress.size = pdusession_setup_resp_p->pdusessions[i].gNB_addr.length;
tmp->transportLayerAddress.bits_unused = 0;
NGAP_DEBUG("pdusession_setup_resp_p: pdusession ID %ld, gnb_addr %d.%d.%d.%d, SIZE %ld \n", NGAP_DEBUG("pdusession_setup_resp_p: pdusession ID %ld, gnb_addr %d.%d.%d.%d, SIZE %ld \n",
item->pDUSessionID, item->pDUSessionID,
tmp->transportLayerAddress.buf[0], tmp->transportLayerAddress.buf[0],
...@@ -1003,76 +888,66 @@ int ngap_gNB_pdusession_setup_resp(instance_t instance, ...@@ -1003,76 +888,66 @@ int ngap_gNB_pdusession_setup_resp(instance_t instance,
tmp->transportLayerAddress.buf[2], tmp->transportLayerAddress.buf[2],
tmp->transportLayerAddress.buf[3], tmp->transportLayerAddress.buf[3],
tmp->transportLayerAddress.size); tmp->transportLayerAddress.size);
}
/* associatedQosFlowList. number of 1? */ /* associatedQosFlowList. number of 1? */
for(int j=0; j < pdusession_setup_resp_p->pdusessions[i].nb_of_qos_flow; j++) { for(int j=0; j < pdusession_setup_resp_p->pdusessions[i].nb_of_qos_flow; j++) {
NGAP_AssociatedQosFlowItem_t *ass_qos_item_p = calloc(1, sizeof *ass_qos_item_p); asn1cSequenceAdd(pdusessionTransfer.dLQosFlowPerTNLInformation.associatedQosFlowList.list, NGAP_AssociatedQosFlowItem_t, ass_qos_item_p);
/* qosFlowIdentifier */ /* qosFlowIdentifier */
ass_qos_item_p->qosFlowIdentifier = pdusession_setup_resp_p->pdusessions[i].associated_qos_flows[j].qfi; ass_qos_item_p->qosFlowIdentifier = pdusession_setup_resp_p->pdusessions[i].associated_qos_flows[j].qfi;
/* qosFlowMappingIndication */ /* qosFlowMappingIndication */
//if(pdusession_setup_resp_p->pdusessions[i].associated_qos_flows[j].qos_flow_mapping_ind != QOSFLOW_MAPPING_INDICATION_NON) { // 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 = 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; // *ass_qos_item_p->qosFlowMappingIndication = pdusession_setup_resp_p->pdusessions[i].associated_qos_flows[j].qos_flow_mapping_ind;
//} // }
asn1cSeqAdd(&pdusessionTransfer_p->dLQosFlowPerTNLInformation.associatedQosFlowList.list, ass_qos_item_p);
} }
asn_encode_to_new_buffer_result_t res = asn_encode_to_new_buffer(NULL, ATS_ALIGNED_CANONICAL_PER, asn_encode_to_new_buffer_result_t res = asn_encode_to_new_buffer(NULL, ATS_ALIGNED_CANONICAL_PER, &asn_DEF_NGAP_PDUSessionResourceSetupResponseTransfer, &pdusessionTransfer);
&asn_DEF_NGAP_PDUSessionResourceSetupResponseTransfer, pdusessionTransfer_p);
AssertFatal (res.buffer, "ASN1 message encoding failed (%s, %lu)!\n", res.result.failed_type->name, res.result.encoded); AssertFatal (res.buffer, "ASN1 message encoding failed (%s, %lu)!\n", res.result.failed_type->name, res.result.encoded);
item->pDUSessionResourceSetupResponseTransfer.buf = res.buffer; item->pDUSessionResourceSetupResponseTransfer.buf = res.buffer;
item->pDUSessionResourceSetupResponseTransfer.size = res.result.encoded; 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);
asn1cSeqAdd(&ie->value.choice.PDUSessionResourceSetupListSURes.list, item);
} }
asn1cSeqAdd(&out->protocolIEs.list, ie);
} }
/* optional */ /* optional */
if (pdusession_setup_resp_p->nb_of_pdusessions_failed > 0) { if (pdusession_setup_resp_p->nb_of_pdusessions_failed > 0) {
ie = calloc(1, sizeof *ie); asn1cSequenceAdd(out->protocolIEs.list, NGAP_PDUSessionResourceSetupResponseIEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_PDUSessionResourceFailedToSetupListSURes; ie->id = NGAP_ProtocolIE_ID_id_PDUSessionResourceFailedToSetupListSURes;
ie->criticality = NGAP_Criticality_ignore; ie->criticality = NGAP_Criticality_ignore;
ie->value.present = NGAP_PDUSessionResourceSetupResponseIEs__value_PR_PDUSessionResourceFailedToSetupListSURes; ie->value.present = NGAP_PDUSessionResourceSetupResponseIEs__value_PR_PDUSessionResourceFailedToSetupListSURes;
for (int i = 0; i < pdusession_setup_resp_p->nb_of_pdusessions_failed; i++) { for (int i = 0; i < pdusession_setup_resp_p->nb_of_pdusessions_failed; i++) {
LOG_W(NGAP,"add a failed session\n"); LOG_W(NGAP,"add a failed session\n");
NGAP_PDUSessionResourceFailedToSetupItemSURes_t *item=calloc(1, sizeof *item); pdusession_failed_t *pdusession_failed = pdusession_setup_resp_p->pdusessions_failed + i;
NGAP_PDUSessionResourceSetupUnsuccessfulTransfer_t *pdusessionUnTransfer_p = calloc(1, sizeof *pdusessionUnTransfer_p); asn1cSequenceAdd(ie->value.choice.PDUSessionResourceFailedToSetupListSURes.list, NGAP_PDUSessionResourceFailedToSetupItemSURes_t, item);
NGAP_PDUSessionResourceSetupUnsuccessfulTransfer_t pdusessionUnTransfer_p = {0};
/* pDUSessionID */ /* pDUSessionID */
item->pDUSessionID = pdusession_setup_resp_p->pdusessions_failed[i].pdusession_id; item->pDUSessionID = pdusession_failed->pdusession_id;
/* cause */ /* cause */
switch(pdusession_setup_resp_p->pdusessions_failed[i].cause) { pdusessionUnTransfer_p.cause.present = pdusession_failed->cause;
switch (pdusessionUnTransfer_p.cause.present) {
case NGAP_CAUSE_RADIO_NETWORK: case NGAP_CAUSE_RADIO_NETWORK:
pdusessionUnTransfer_p->cause.present = NGAP_Cause_PR_radioNetwork; pdusessionUnTransfer_p.cause.choice.radioNetwork = pdusession_failed->cause_value;
pdusessionUnTransfer_p->cause.choice.radioNetwork = pdusession_setup_resp_p->pdusessions_failed[i].cause_value;
break; break;
case NGAP_CAUSE_TRANSPORT: case NGAP_CAUSE_TRANSPORT:
pdusessionUnTransfer_p->cause.present = NGAP_Cause_PR_transport; pdusessionUnTransfer_p.cause.choice.transport = pdusession_failed->cause_value;
pdusessionUnTransfer_p->cause.choice.transport = pdusession_setup_resp_p->pdusessions_failed[i].cause_value;
break; break;
case NGAP_CAUSE_NAS: case NGAP_CAUSE_NAS:
pdusessionUnTransfer_p->cause.present = NGAP_Cause_PR_nas; pdusessionUnTransfer_p.cause.choice.nas = pdusession_failed->cause_value;
pdusessionUnTransfer_p->cause.choice.nas = pdusession_setup_resp_p->pdusessions_failed[i].cause_value;
break; break;
case NGAP_CAUSE_PROTOCOL: case NGAP_CAUSE_PROTOCOL:
pdusessionUnTransfer_p->cause.present = NGAP_Cause_PR_protocol; pdusessionUnTransfer_p.cause.choice.protocol = pdusession_failed->cause_value;
pdusessionUnTransfer_p->cause.choice.protocol = pdusession_setup_resp_p->pdusessions_failed[i].cause_value;
break; break;
case NGAP_CAUSE_MISC: case NGAP_CAUSE_MISC:
pdusessionUnTransfer_p->cause.present = NGAP_Cause_PR_misc; pdusessionUnTransfer_p.cause.choice.misc = pdusession_failed->cause_value;
pdusessionUnTransfer_p->cause.choice.misc = pdusession_setup_resp_p->pdusessions_failed[i].cause_value;
break; break;
case NGAP_CAUSE_NOTHING: case NGAP_CAUSE_NOTHING:
...@@ -1082,31 +957,23 @@ int ngap_gNB_pdusession_setup_resp(instance_t instance, ...@@ -1082,31 +957,23 @@ int ngap_gNB_pdusession_setup_resp(instance_t instance,
NGAP_DEBUG("pdusession setup response: failed pdusession ID %ld\n", item->pDUSessionID); NGAP_DEBUG("pdusession setup response: failed pdusession ID %ld\n", item->pDUSessionID);
asn_encode_to_new_buffer_result_t res = asn_encode_to_new_buffer_result_t res = asn_encode_to_new_buffer(NULL, ATS_ALIGNED_CANONICAL_PER, &asn_DEF_NGAP_PDUSessionResourceSetupUnsuccessfulTransfer, &pdusessionUnTransfer_p);
asn_encode_to_new_buffer(NULL, ATS_ALIGNED_CANONICAL_PER,
&asn_DEF_NGAP_PDUSessionResourceSetupUnsuccessfulTransfer, pdusessionUnTransfer_p);
item->pDUSessionResourceSetupUnsuccessfulTransfer.buf = res.buffer; item->pDUSessionResourceSetupUnsuccessfulTransfer.buf = res.buffer;
item->pDUSessionResourceSetupUnsuccessfulTransfer.size = res.result.encoded; item->pDUSessionResourceSetupUnsuccessfulTransfer.size = res.result.encoded;
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_NGAP_PDUSessionResourceSetupUnsuccessfulTransfer, pdusessionUnTransfer_p); ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_NGAP_PDUSessionResourceSetupUnsuccessfulTransfer, &pdusessionUnTransfer_p);
asn1cSeqAdd(&ie->value.choice.PDUSessionResourceFailedToSetupListSURes.list, item);
} }
asn1cSeqAdd(&out->protocolIEs.list, ie);
} }
/* optional */ /* optional */
if (0) { if (0) {
ie = calloc(1, sizeof *ie); asn1cSequenceAdd(out->protocolIEs.list, NGAP_PDUSessionResourceSetupResponseIEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_CriticalityDiagnostics; ie->id = NGAP_ProtocolIE_ID_id_CriticalityDiagnostics;
ie->criticality = NGAP_Criticality_ignore; ie->criticality = NGAP_Criticality_ignore;
ie->value.present = NGAP_PDUSessionResourceSetupResponseIEs__value_PR_CriticalityDiagnostics; ie->value.present = NGAP_PDUSessionResourceSetupResponseIEs__value_PR_CriticalityDiagnostics;
// ie->value.choice.CriticalityDiagnostics = ; // ie->value.choice.CriticalityDiagnostics = ;
asn1cSeqAdd(&out->protocolIEs.list, ie);
} }
if (ngap_gNB_encode_pdu(&pdu, &buffer, &length) < 0) { if (ngap_gNB_encode_pdu(&pdu, &buffer, &length) < 0) {
NGAP_ERROR("Failed to encode uplink transport\n"); NGAP_ERROR("Failed to encode uplink transport\n");
/* Encode procedure has failed... */ /* Encode procedure has failed... */
...@@ -1114,100 +981,90 @@ int ngap_gNB_pdusession_setup_resp(instance_t instance, ...@@ -1114,100 +981,90 @@ int ngap_gNB_pdusession_setup_resp(instance_t instance,
} }
/* UE associated signalling -> use the allocated stream */ /* UE associated signalling -> use the allocated stream */
ngap_gNB_itti_send_sctp_data_req(ngap_gNB_instance_p->instance, ngap_gNB_itti_send_sctp_data_req(ngap_gNB_instance_p->instance, ue_context_p->amf_ref->assoc_id, buffer, length, ue_context_p->tx_stream);
ue_context_p->amf_ref->assoc_id, buffer,
length, ue_context_p->tx_stream);
return 0; return 0;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int ngap_gNB_pdusession_modify_resp(instance_t instance, int ngap_gNB_pdusession_modify_resp(instance_t instance, ngap_pdusession_modify_resp_t *pdusession_modify_resp_p)
ngap_pdusession_modify_resp_t *pdusession_modify_resp_p)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
{ {
ngap_gNB_instance_t *ngap_gNB_instance_p = NULL; ngap_gNB_instance_t *ngap_gNB_instance_p = NULL;
struct ngap_gNB_ue_context_s *ue_context_p = NULL; struct ngap_gNB_ue_context_s *ue_context_p = NULL;
NGAP_NGAP_PDU_t pdu; NGAP_NGAP_PDU_t pdu;
NGAP_PDUSessionResourceModifyResponse_t *out;
NGAP_PDUSessionResourceModifyResponseIEs_t *ie;
uint8_t *buffer = NULL; uint8_t *buffer = NULL;
uint32_t length; uint32_t length;
int i;
asn_encode_to_new_buffer_result_t res = { NULL, {0, NULL, NULL} };
/* Retrieve the NGAP gNB instance associated with Mod_id */ /* Retrieve the NGAP gNB instance associated with Mod_id */
ngap_gNB_instance_p = ngap_gNB_get_instance(instance); ngap_gNB_instance_p = ngap_gNB_get_instance(instance);
DevAssert(pdusession_modify_resp_p != NULL); DevAssert(pdusession_modify_resp_p != NULL);
DevAssert(ngap_gNB_instance_p != NULL); DevAssert(ngap_gNB_instance_p != NULL);
if ((ue_context_p = ngap_gNB_get_ue_context(ngap_gNB_instance_p, if ((ue_context_p = ngap_get_ue_context(pdusession_modify_resp_p->gNB_ue_ngap_id)) == NULL) {
pdusession_modify_resp_p->gNB_ue_ngap_id)) == NULL) {
/* The context for this gNB ue ngap id doesn't exist in the map of gNB UEs */ /* The context for this gNB ue ngap id doesn't exist in the map of gNB UEs */
NGAP_WARN("Failed to find ue context associated with gNB ue ngap id: 0x%08x\n", NGAP_WARN("Failed to find ue context associated with gNB ue ngap id: 0x%08x\n", pdusession_modify_resp_p->gNB_ue_ngap_id);
pdusession_modify_resp_p->gNB_ue_ngap_id);
return -1; return -1;
} }
/* Uplink NAS transport can occur either during an ngap connected state /* Uplink NAS transport can occur either during an ngap connected state
* or during initial attach (for example: NAS authentication). * or during initial attach (for example: NAS authentication).
*/ */
if (!(ue_context_p->ue_state == NGAP_UE_CONNECTED || if (!(ue_context_p->ue_state == NGAP_UE_CONNECTED || ue_context_p->ue_state == NGAP_UE_WAITING_CSR)) {
ue_context_p->ue_state == NGAP_UE_WAITING_CSR)) { NGAP_WARN(
NGAP_WARN("You are attempting to send NAS data over non-connected " "You are attempting to send NAS data over non-connected "
"gNB ue ngap id: %08x, current state: %d\n", "gNB ue ngap id: %08x, current state: %d\n",
pdusession_modify_resp_p->gNB_ue_ngap_id, ue_context_p->ue_state); pdusession_modify_resp_p->gNB_ue_ngap_id,
ue_context_p->ue_state);
return -1; return -1;
} }
/* Prepare the NGAP message to encode */ /* Prepare the NGAP message to encode */
memset(&pdu, 0, sizeof(pdu)); memset(&pdu, 0, sizeof(pdu));
pdu.present = NGAP_NGAP_PDU_PR_successfulOutcome; pdu.present = NGAP_NGAP_PDU_PR_successfulOutcome;
pdu.choice.successfulOutcome = (NGAP_SuccessfulOutcome_t *)calloc(1,sizeof(struct NGAP_SuccessfulOutcome)); asn1cCalloc(pdu.choice.successfulOutcome, head);
pdu.choice.successfulOutcome->procedureCode = NGAP_ProcedureCode_id_PDUSessionResourceModify; head->procedureCode = NGAP_ProcedureCode_id_PDUSessionResourceModify;
pdu.choice.successfulOutcome->criticality = NGAP_Criticality_reject; head->criticality = NGAP_Criticality_reject;
pdu.choice.successfulOutcome->value.present = NGAP_SuccessfulOutcome__value_PR_PDUSessionResourceModifyResponse; head->value.present = NGAP_SuccessfulOutcome__value_PR_PDUSessionResourceModifyResponse;
out = &pdu.choice.successfulOutcome->value.choice.PDUSessionResourceModifyResponse; NGAP_PDUSessionResourceModifyResponse_t *out = &head->value.choice.PDUSessionResourceModifyResponse;
/* mandatory */ /* mandatory */
{
asn1cSequenceAdd(out->protocolIEs.list, NGAP_PDUSessionResourceModifyResponseIEs_t, ie);
ie = (NGAP_PDUSessionResourceModifyResponseIEs_t *)calloc(1, sizeof(NGAP_PDUSessionResourceModifyResponseIEs_t)); ie = (NGAP_PDUSessionResourceModifyResponseIEs_t *)calloc(1, sizeof(NGAP_PDUSessionResourceModifyResponseIEs_t));
ie->id = NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID; ie->id = NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID;
ie->criticality = NGAP_Criticality_ignore; ie->criticality = NGAP_Criticality_ignore;
ie->value.present = NGAP_PDUSessionResourceModifyResponseIEs__value_PR_AMF_UE_NGAP_ID; ie->value.present = NGAP_PDUSessionResourceModifyResponseIEs__value_PR_AMF_UE_NGAP_ID;
asn_uint642INTEGER(&ie->value.choice.AMF_UE_NGAP_ID, ue_context_p->amf_ue_ngap_id); asn_uint642INTEGER(&ie->value.choice.AMF_UE_NGAP_ID, ue_context_p->amf_ue_ngap_id);
asn1cSeqAdd(&out->protocolIEs.list, ie); asn1cSeqAdd(&out->protocolIEs.list, ie);
}
/* mandatory */ /* mandatory */
ie = (NGAP_PDUSessionResourceModifyResponseIEs_t *)calloc(1, sizeof(NGAP_PDUSessionResourceModifyResponseIEs_t)); {
asn1cSequenceAdd(out->protocolIEs.list, NGAP_PDUSessionResourceModifyResponseIEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID; ie->id = NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID;
ie->criticality = NGAP_Criticality_ignore; ie->criticality = NGAP_Criticality_ignore;
ie->value.present = NGAP_PDUSessionResourceModifyResponseIEs__value_PR_RAN_UE_NGAP_ID; ie->value.present = NGAP_PDUSessionResourceModifyResponseIEs__value_PR_RAN_UE_NGAP_ID;
ie->value.choice.RAN_UE_NGAP_ID = pdusession_modify_resp_p->gNB_ue_ngap_id; ie->value.choice.RAN_UE_NGAP_ID = pdusession_modify_resp_p->gNB_ue_ngap_id;
asn1cSeqAdd(&out->protocolIEs.list, ie); }
/* PDUSessionResourceModifyListModRes optional */ /* PDUSessionResourceModifyListModRes optional */
if (pdusession_modify_resp_p->nb_of_pdusessions > 0) { if (pdusession_modify_resp_p->nb_of_pdusessions > 0) {
ie = (NGAP_PDUSessionResourceModifyResponseIEs_t *)calloc(1, sizeof(NGAP_PDUSessionResourceModifyResponseIEs_t)); asn1cSequenceAdd(out->protocolIEs.list, NGAP_PDUSessionResourceModifyResponseIEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_PDUSessionResourceModifyListModRes; ie->id = NGAP_ProtocolIE_ID_id_PDUSessionResourceModifyListModRes;
ie->criticality = NGAP_Criticality_ignore; ie->criticality = NGAP_Criticality_ignore;
ie->value.present = NGAP_PDUSessionResourceModifyResponseIEs__value_PR_PDUSessionResourceModifyListModRes; ie->value.present = NGAP_PDUSessionResourceModifyResponseIEs__value_PR_PDUSessionResourceModifyListModRes;
for (i = 0; i < pdusession_modify_resp_p->nb_of_pdusessions; i++) { for (int i = 0; i < pdusession_modify_resp_p->nb_of_pdusessions; i++) {
NGAP_PDUSessionResourceModifyItemModRes_t *item; asn1cSequenceAdd(ie->value.choice.PDUSessionResourceModifyListModRes.list, NGAP_PDUSessionResourceModifyItemModRes_t, item);
NGAP_PDUSessionResourceModifyResponseTransfer_t *transfer_p = NULL;
item = (NGAP_PDUSessionResourceModifyItemModRes_t *)calloc(1, sizeof(NGAP_PDUSessionResourceModifyItemModRes_t));
item->pDUSessionID = pdusession_modify_resp_p->pdusessions[i].pdusession_id; item->pDUSessionID = pdusession_modify_resp_p->pdusessions[i].pdusession_id;
transfer_p = (NGAP_PDUSessionResourceModifyResponseTransfer_t *)calloc(1, sizeof(NGAP_PDUSessionResourceModifyResponseTransfer_t)); NGAP_PDUSessionResourceModifyResponseTransfer_t transfer = {0};
transfer_p->qosFlowAddOrModifyResponseList = (NGAP_QosFlowAddOrModifyResponseList_t *)calloc(1, sizeof(NGAP_QosFlowAddOrModifyResponseList_t)); asn1cCalloc(transfer.qosFlowAddOrModifyResponseList, tmp);
uint8_t qos_flow_index; for (int qos_flow_index = 0; qos_flow_index < pdusession_modify_resp_p->pdusessions[i].nb_of_qos_flow; qos_flow_index++) {
for (qos_flow_index = 0; qos_flow_index < pdusession_modify_resp_p->pdusessions[i].nb_of_qos_flow; qos_flow_index++) { asn1cSequenceAdd(tmp->list, NGAP_QosFlowAddOrModifyResponseItem_t, qos);
NGAP_QosFlowAddOrModifyResponseItem_t *qosFlowAddOrModifyResponseItem_p = calloc(1, sizeof(NGAP_QosFlowAddOrModifyResponseItem_t)); qos->qosFlowIdentifier = pdusession_modify_resp_p->pdusessions[i].qos[qos_flow_index].qfi;
qosFlowAddOrModifyResponseItem_p->qosFlowIdentifier =
pdusession_modify_resp_p->pdusessions[i].qos[qos_flow_index].qfi;
asn1cSeqAdd(&transfer_p->qosFlowAddOrModifyResponseList->list, qosFlowAddOrModifyResponseItem_p);
} }
asn_encode_to_new_buffer_result_t res = {0};
memset(&res, 0, sizeof(res)); NGAP_PDUSessionResourceModifyResponseTransfer_t *transfer_p = NULL;
res = asn_encode_to_new_buffer(NULL, ATS_ALIGNED_CANONICAL_PER, &asn_DEF_NGAP_PDUSessionResourceModifyResponseTransfer, transfer_p); res = asn_encode_to_new_buffer(NULL, ATS_ALIGNED_CANONICAL_PER, &asn_DEF_NGAP_PDUSessionResourceModifyResponseTransfer, transfer_p);
item->pDUSessionResourceModifyResponseTransfer.buf = res.buffer; item->pDUSessionResourceModifyResponseTransfer.buf = res.buffer;
item->pDUSessionResourceModifyResponseTransfer.size = res.result.encoded; item->pDUSessionResourceModifyResponseTransfer.size = res.result.encoded;
...@@ -1215,52 +1072,42 @@ int ngap_gNB_pdusession_modify_resp(instance_t instance, ...@@ -1215,52 +1072,42 @@ int ngap_gNB_pdusession_modify_resp(instance_t instance,
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_NGAP_PDUSessionResourceModifyResponseTransfer, transfer_p); ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_NGAP_PDUSessionResourceModifyResponseTransfer, transfer_p);
NGAP_DEBUG("pdusession_modify_resp: modified pdusession ID %ld\n", item->pDUSessionID); NGAP_DEBUG("pdusession_modify_resp: modified pdusession ID %ld\n", item->pDUSessionID);
asn1cSeqAdd(&ie->value.choice.PDUSessionResourceModifyListModRes.list, item);
} }
asn1cSeqAdd(&out->protocolIEs.list, ie);
} }
/* optional */ /* optional */
if (pdusession_modify_resp_p->nb_of_pdusessions_failed > 0) { if (pdusession_modify_resp_p->nb_of_pdusessions_failed > 0) {
ie = (NGAP_PDUSessionResourceModifyResponseIEs_t *)calloc(1, sizeof(NGAP_PDUSessionResourceModifyResponseIEs_t)); asn1cSequenceAdd(out->protocolIEs.list, NGAP_PDUSessionResourceModifyResponseIEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_PDUSessionResourceFailedToModifyListModRes; ie->id = NGAP_ProtocolIE_ID_id_PDUSessionResourceFailedToModifyListModRes;
ie->criticality = NGAP_Criticality_ignore; ie->criticality = NGAP_Criticality_ignore;
ie->value.present = NGAP_PDUSessionResourceModifyResponseIEs__value_PR_PDUSessionResourceFailedToModifyListModRes; ie->value.present = NGAP_PDUSessionResourceModifyResponseIEs__value_PR_PDUSessionResourceFailedToModifyListModRes;
for (i = 0; i < pdusession_modify_resp_p->nb_of_pdusessions_failed; i++) { for (int i = 0; i < pdusession_modify_resp_p->nb_of_pdusessions_failed; i++) {
NGAP_PDUSessionResourceFailedToModifyItemModRes_t *item; asn1cSequenceAdd(ie->value.choice.PDUSessionResourceFailedToModifyListModRes.list, NGAP_PDUSessionResourceFailedToModifyItemModRes_t, item);
NGAP_PDUSessionResourceModifyUnsuccessfulTransfer_t *pdusessionTransfer_p = NULL;
item = (NGAP_PDUSessionResourceFailedToModifyItemModRes_t *)calloc(1, sizeof(NGAP_PDUSessionResourceFailedToModifyItemModRes_t));
item->pDUSessionID = pdusession_modify_resp_p->pdusessions_failed[i].pdusession_id; item->pDUSessionID = pdusession_modify_resp_p->pdusessions_failed[i].pdusession_id;
pdusessionTransfer_p = (NGAP_PDUSessionResourceModifyUnsuccessfulTransfer_t *)calloc(1, sizeof(NGAP_PDUSessionResourceModifyUnsuccessfulTransfer_t)); NGAP_PDUSessionResourceModifyUnsuccessfulTransfer_t pdusessionTransfer = {0};
pdusessionTransfer.cause.present = pdusession_modify_resp_p->pdusessions_failed[i].cause;
switch(pdusession_modify_resp_p->pdusessions_failed[i].cause) { switch (pdusessionTransfer.cause.present) {
case NGAP_CAUSE_RADIO_NETWORK: case NGAP_CAUSE_RADIO_NETWORK:
pdusessionTransfer_p->cause.present = NGAP_Cause_PR_radioNetwork; pdusessionTransfer.cause.choice.radioNetwork = pdusession_modify_resp_p->pdusessions_failed[i].cause_value;
pdusessionTransfer_p->cause.choice.radioNetwork = pdusession_modify_resp_p->pdusessions_failed[i].cause_value;
break; break;
case NGAP_CAUSE_TRANSPORT: case NGAP_CAUSE_TRANSPORT:
pdusessionTransfer_p->cause.present = NGAP_Cause_PR_transport; pdusessionTransfer.cause.choice.transport = pdusession_modify_resp_p->pdusessions_failed[i].cause_value;
pdusessionTransfer_p->cause.choice.transport = pdusession_modify_resp_p->pdusessions_failed[i].cause_value;
break; break;
case NGAP_CAUSE_NAS: case NGAP_CAUSE_NAS:
pdusessionTransfer_p->cause.present = NGAP_Cause_PR_nas; pdusessionTransfer.cause.choice.nas = pdusession_modify_resp_p->pdusessions_failed[i].cause_value;
pdusessionTransfer_p->cause.choice.nas = pdusession_modify_resp_p->pdusessions_failed[i].cause_value;
break; break;
case NGAP_CAUSE_PROTOCOL: case NGAP_CAUSE_PROTOCOL:
pdusessionTransfer_p->cause.present = NGAP_Cause_PR_protocol; pdusessionTransfer.cause.choice.protocol = pdusession_modify_resp_p->pdusessions_failed[i].cause_value;
pdusessionTransfer_p->cause.choice.protocol = pdusession_modify_resp_p->pdusessions_failed[i].cause_value;
break; break;
case NGAP_CAUSE_MISC: case NGAP_CAUSE_MISC:
pdusessionTransfer_p->cause.present = NGAP_Cause_PR_misc; pdusessionTransfer.cause.choice.misc = pdusession_modify_resp_p->pdusessions_failed[i].cause_value;
pdusessionTransfer_p->cause.choice.misc = pdusession_modify_resp_p->pdusessions_failed[i].cause_value;
break; break;
case NGAP_CAUSE_NOTHING: case NGAP_CAUSE_NOTHING:
...@@ -1268,33 +1115,27 @@ int ngap_gNB_pdusession_modify_resp(instance_t instance, ...@@ -1268,33 +1115,27 @@ int ngap_gNB_pdusession_modify_resp(instance_t instance,
break; break;
} }
memset(&res, 0, sizeof(res)); asn_encode_to_new_buffer_result_t res = {0};
res = asn_encode_to_new_buffer(NULL, ATS_ALIGNED_CANONICAL_PER, &asn_DEF_NGAP_PDUSessionResourceModifyUnsuccessfulTransfer, pdusessionTransfer_p); NGAP_PDUSessionResourceModifyUnsuccessfulTransfer_t *pdusessionTransfer_p = NULL;
res = asn_encode_to_new_buffer(NULL, ATS_ALIGNED_CANONICAL_PER, &asn_DEF_NGAP_PDUSessionResourceModifyUnsuccessfulTransfer, &pdusessionTransfer);
item->pDUSessionResourceModifyUnsuccessfulTransfer.buf = res.buffer; item->pDUSessionResourceModifyUnsuccessfulTransfer.buf = res.buffer;
item->pDUSessionResourceModifyUnsuccessfulTransfer.size = res.result.encoded; item->pDUSessionResourceModifyUnsuccessfulTransfer.size = res.result.encoded;
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_NGAP_PDUSessionResourceModifyUnsuccessfulTransfer, pdusessionTransfer_p); ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_NGAP_PDUSessionResourceModifyUnsuccessfulTransfer, pdusessionTransfer_p);
NGAP_DEBUG("pdusession_modify_resp: failed pdusession ID %ld\n", item->pDUSessionID); NGAP_DEBUG("pdusession_modify_resp: failed pdusession ID %ld\n", item->pDUSessionID);
asn1cSeqAdd(&ie->value.choice.PDUSessionResourceFailedToModifyListModRes.list, item);
} }
asn1cSeqAdd(&out->protocolIEs.list, ie);
} }
/* optional */ /* optional */
if (0) { if (0) {
ie = (NGAP_PDUSessionResourceModifyResponseIEs_t *)calloc(1, sizeof(NGAP_PDUSessionResourceModifyResponseIEs_t)); asn1cSequenceAdd(out->protocolIEs.list, NGAP_PDUSessionResourceModifyResponseIEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_CriticalityDiagnostics; ie->id = NGAP_ProtocolIE_ID_id_CriticalityDiagnostics;
ie->criticality = NGAP_Criticality_ignore; ie->criticality = NGAP_Criticality_ignore;
ie->value.present = NGAP_PDUSessionResourceModifyResponseIEs__value_PR_CriticalityDiagnostics; ie->value.present = NGAP_PDUSessionResourceModifyResponseIEs__value_PR_CriticalityDiagnostics;
// ie->value.choice.CriticalityDiagnostics = ; // ie->value.choice.CriticalityDiagnostics = ;
asn1cSeqAdd(&out->protocolIEs.list, ie);
} }
fprintf(stderr, "start encode\n");
if (ngap_gNB_encode_pdu(&pdu, &buffer, &length) < 0) { if (ngap_gNB_encode_pdu(&pdu, &buffer, &length) < 0) {
NGAP_ERROR("Failed to encode uplink transport\n"); NGAP_ERROR("Failed to encode uplink transport\n");
/* Encode procedure has failed... */ /* Encode procedure has failed... */
...@@ -1302,22 +1143,17 @@ int ngap_gNB_pdusession_modify_resp(instance_t instance, ...@@ -1302,22 +1143,17 @@ int ngap_gNB_pdusession_modify_resp(instance_t instance,
} }
/* UE associated signalling -> use the allocated stream */ /* UE associated signalling -> use the allocated stream */
ngap_gNB_itti_send_sctp_data_req(ngap_gNB_instance_p->instance, ngap_gNB_itti_send_sctp_data_req(ngap_gNB_instance_p->instance, ue_context_p->amf_ref->assoc_id, buffer, length, ue_context_p->tx_stream);
ue_context_p->amf_ref->assoc_id, buffer,
length, ue_context_p->tx_stream);
return 0; return 0;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int ngap_gNB_pdusession_release_resp(instance_t instance, int ngap_gNB_pdusession_release_resp(instance_t instance, ngap_pdusession_release_resp_t *pdusession_release_resp_p)
ngap_pdusession_release_resp_t *pdusession_release_resp_p)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
{ {
ngap_gNB_instance_t *ngap_gNB_instance_p = NULL; ngap_gNB_instance_t *ngap_gNB_instance_p = NULL;
struct ngap_gNB_ue_context_s *ue_context_p = NULL; struct ngap_gNB_ue_context_s *ue_context_p = NULL;
NGAP_NGAP_PDU_t pdu; NGAP_NGAP_PDU_t pdu;
NGAP_PDUSessionResourceReleaseResponse_t *out;
NGAP_PDUSessionResourceReleaseResponseIEs_t *ie;
uint8_t *buffer = NULL; uint8_t *buffer = NULL;
uint32_t length; uint32_t length;
int i; int i;
...@@ -1326,68 +1162,52 @@ int ngap_gNB_pdusession_release_resp(instance_t instance, ...@@ -1326,68 +1162,52 @@ int ngap_gNB_pdusession_release_resp(instance_t instance,
DevAssert(pdusession_release_resp_p != NULL); DevAssert(pdusession_release_resp_p != NULL);
DevAssert(ngap_gNB_instance_p != NULL); DevAssert(ngap_gNB_instance_p != NULL);
if ((ue_context_p = ngap_gNB_get_ue_context(ngap_gNB_instance_p, if ((ue_context_p = ngap_get_ue_context(pdusession_release_resp_p->gNB_ue_ngap_id)) == NULL) {
pdusession_release_resp_p->gNB_ue_ngap_id)) == NULL) {
/* The context for this gNB ue ngap id doesn't exist in the map of gNB UEs */ /* The context for this gNB ue ngap id doesn't exist in the map of gNB UEs */
NGAP_WARN("Failed to find ue context associated with gNB ue ngap id: 0x%08x\n", NGAP_WARN("Failed to find ue context associated with gNB ue ngap id: 0x%08x\n", pdusession_release_resp_p->gNB_ue_ngap_id);
pdusession_release_resp_p->gNB_ue_ngap_id);
return -1; return -1;
} }
/* Prepare the NGAP message to encode */ /* Prepare the NGAP message to encode */
memset(&pdu, 0, sizeof(pdu)); memset(&pdu, 0, sizeof(pdu));
pdu.present = NGAP_NGAP_PDU_PR_successfulOutcome; pdu.present = NGAP_NGAP_PDU_PR_successfulOutcome;
pdu.choice.successfulOutcome = (NGAP_SuccessfulOutcome_t *)calloc(1,sizeof(struct NGAP_SuccessfulOutcome)); asn1cCalloc(pdu.choice.successfulOutcome, head);
pdu.choice.successfulOutcome->procedureCode = NGAP_ProcedureCode_id_PDUSessionResourceRelease; head->procedureCode = NGAP_ProcedureCode_id_PDUSessionResourceRelease;
pdu.choice.successfulOutcome->criticality = NGAP_Criticality_reject; head->criticality = NGAP_Criticality_reject;
pdu.choice.successfulOutcome->value.present = NGAP_SuccessfulOutcome__value_PR_PDUSessionResourceReleaseResponse; head->value.present = NGAP_SuccessfulOutcome__value_PR_PDUSessionResourceReleaseResponse;
out = &pdu.choice.successfulOutcome->value.choice.PDUSessionResourceReleaseResponse; NGAP_PDUSessionResourceReleaseResponse_t *out = &head->value.choice.PDUSessionResourceReleaseResponse;
/* mandatory */ /* mandatory */
ie = (NGAP_PDUSessionResourceReleaseResponseIEs_t *)calloc(1, sizeof(NGAP_PDUSessionResourceReleaseResponseIEs_t)); {
asn1cSequenceAdd(out->protocolIEs.list, NGAP_PDUSessionResourceReleaseResponseIEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID; ie->id = NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID;
ie->criticality = NGAP_Criticality_ignore; ie->criticality = NGAP_Criticality_ignore;
ie->value.present = NGAP_PDUSessionResourceReleaseResponseIEs__value_PR_AMF_UE_NGAP_ID; ie->value.present = NGAP_PDUSessionResourceReleaseResponseIEs__value_PR_AMF_UE_NGAP_ID;
asn_uint642INTEGER(&ie->value.choice.AMF_UE_NGAP_ID, ue_context_p->amf_ue_ngap_id); asn_uint642INTEGER(&ie->value.choice.AMF_UE_NGAP_ID, ue_context_p->amf_ue_ngap_id);
asn1cSeqAdd(&out->protocolIEs.list, ie); }
/* mandatory */ /* mandatory */
ie = (NGAP_PDUSessionResourceReleaseResponseIEs_t *)calloc(1, sizeof(NGAP_PDUSessionResourceReleaseResponseIEs_t)); {
asn1cSequenceAdd(out->protocolIEs.list, NGAP_PDUSessionResourceReleaseResponseIEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID; ie->id = NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID;
ie->criticality = NGAP_Criticality_ignore; ie->criticality = NGAP_Criticality_ignore;
ie->value.present = NGAP_PDUSessionResourceReleaseResponseIEs__value_PR_RAN_UE_NGAP_ID; ie->value.present = NGAP_PDUSessionResourceReleaseResponseIEs__value_PR_RAN_UE_NGAP_ID;
ie->value.choice.RAN_UE_NGAP_ID = pdusession_release_resp_p->gNB_ue_ngap_id; ie->value.choice.RAN_UE_NGAP_ID = pdusession_release_resp_p->gNB_ue_ngap_id;
asn1cSeqAdd(&out->protocolIEs.list, ie); }
/* optional */ /* optional */
if (pdusession_release_resp_p->nb_of_pdusessions_released > 0) { if (pdusession_release_resp_p->nb_of_pdusessions_released > 0) {
ie = (NGAP_PDUSessionResourceReleaseResponseIEs_t *)calloc(1, sizeof(NGAP_PDUSessionResourceReleaseResponseIEs_t)); asn1cSequenceAdd(out->protocolIEs.list, NGAP_PDUSessionResourceReleaseResponseIEs_t, ie);
ie->id = NGAP_ProtocolIE_ID_id_PDUSessionResourceReleasedListRelRes; ie->id = NGAP_ProtocolIE_ID_id_PDUSessionResourceReleasedListRelRes;
ie->criticality = NGAP_Criticality_ignore; ie->criticality = NGAP_Criticality_ignore;
ie->value.present = NGAP_PDUSessionResourceReleaseResponseIEs__value_PR_PDUSessionResourceReleasedListRelRes; ie->value.present = NGAP_PDUSessionResourceReleaseResponseIEs__value_PR_PDUSessionResourceReleasedListRelRes;
for (i = 0; i < pdusession_release_resp_p->nb_of_pdusessions_released; i++) { for (i = 0; i < pdusession_release_resp_p->nb_of_pdusessions_released; i++) {
NGAP_PDUSessionResourceReleasedItemRelRes_t *item; asn1cSequenceAdd(ie->value.choice.PDUSessionResourceReleasedListRelRes.list, NGAP_PDUSessionResourceReleasedItemRelRes_t, item);
item = (NGAP_PDUSessionResourceReleasedItemRelRes_t *)calloc(1, sizeof(NGAP_PDUSessionResourceReleasedItemRelRes_t));
item->pDUSessionID = pdusession_release_resp_p->pdusession_release[i].pdusession_id; item->pDUSessionID = pdusession_release_resp_p->pdusession_release[i].pdusession_id;
if(pdusession_release_resp_p->pdusession_release[i].transfer_length > 0){ allocCopy(&item->pDUSessionResourceReleaseResponseTransfer, pdusession_release_resp_p->pdusession_release[i].data);
item->pDUSessionResourceReleaseResponseTransfer.size = pdusession_release_resp_p->pdusession_release[i].transfer_length;
item->pDUSessionResourceReleaseResponseTransfer.buf = malloc(sizeof(uint8_t) * pdusession_release_resp_p->pdusession_release[i].transfer_length);
memcpy(item->pDUSessionResourceReleaseResponseTransfer.buf,
pdusession_release_resp_p->pdusession_release[i].transfer_buffer,
pdusession_release_resp_p->pdusession_release[i].transfer_length);
}else {
item->pDUSessionResourceReleaseResponseTransfer.size = 0;
item->pDUSessionResourceReleaseResponseTransfer.buf = NULL;
NGAP_DEBUG("pdusession_release_resp: transfer_buffer is NULL!\n");
}
NGAP_DEBUG("pdusession_release_resp: pdusession ID %ld\n", item->pDUSessionID); NGAP_DEBUG("pdusession_release_resp: pdusession ID %ld\n", item->pDUSessionID);
asn1cSeqAdd(&ie->value.choice.PDUSessionResourceReleasedListRelRes.list, item);
} }
asn1cSeqAdd(&out->protocolIEs.list, ie);
} }
if (ngap_gNB_encode_pdu(&pdu, &buffer, &length) < 0) { if (ngap_gNB_encode_pdu(&pdu, &buffer, &length) < 0) {
NGAP_ERROR("Failed to encode release response\n"); NGAP_ERROR("Failed to encode release response\n");
/* Encode procedure has failed... */ /* Encode procedure has failed... */
...@@ -1395,17 +1215,17 @@ int ngap_gNB_pdusession_release_resp(instance_t instance, ...@@ -1395,17 +1215,17 @@ int ngap_gNB_pdusession_release_resp(instance_t instance,
} }
/* UE associated signalling -> use the allocated stream */ /* UE associated signalling -> use the allocated stream */
ngap_gNB_itti_send_sctp_data_req(ngap_gNB_instance_p->instance, ngap_gNB_itti_send_sctp_data_req(ngap_gNB_instance_p->instance, ue_context_p->amf_ref->assoc_id, buffer, length, ue_context_p->tx_stream);
ue_context_p->amf_ref->assoc_id, buffer,
length, ue_context_p->tx_stream);
NGAP_INFO("pdusession_release_response sended gNB_UE_NGAP_ID %u amf_ue_ngap_id %lu nb_of_pdusessions_released %d nb_of_pdusessions_failed %d\n", NGAP_INFO("pdusession_release_response sended gNB_UE_NGAP_ID %u amf_ue_ngap_id %lu nb_of_pdusessions_released %d nb_of_pdusessions_failed %d\n",
pdusession_release_resp_p->gNB_ue_ngap_id, (uint64_t)ue_context_p->amf_ue_ngap_id,pdusession_release_resp_p->nb_of_pdusessions_released,pdusession_release_resp_p->nb_of_pdusessions_failed); pdusession_release_resp_p->gNB_ue_ngap_id,
(uint64_t)ue_context_p->amf_ue_ngap_id,
pdusession_release_resp_p->nb_of_pdusessions_released,
pdusession_release_resp_p->nb_of_pdusessions_failed);
return 0; return 0;
} }
int ngap_gNB_path_switch_req(instance_t instance, int ngap_gNB_path_switch_req(instance_t instance, ngap_path_switch_req_t *path_switch_req_p)
ngap_path_switch_req_t *path_switch_req_p)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
{ {
//TODO //TODO
...@@ -1413,13 +1233,9 @@ int ngap_gNB_path_switch_req(instance_t instance, ...@@ -1413,13 +1233,9 @@ int ngap_gNB_path_switch_req(instance_t instance,
return 0; return 0;
} }
int ngap_gNB_generate_PDUSESSION_Modification_Indication( int ngap_gNB_generate_PDUSESSION_Modification_Indication(instance_t instance, ngap_pdusession_modification_ind_t *pdusession_modification_ind)
instance_t instance,
ngap_pdusession_modification_ind_t *pdusession_modification_ind)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
{ {
//TODO //TODO
return 0; return 0;
} }
...@@ -30,23 +30,10 @@ ...@@ -30,23 +30,10 @@
#ifndef NGAP_GNB_TRACE_H_ #ifndef NGAP_GNB_TRACE_H_
#define NGAP_GNB_TRACE_H_ #define NGAP_GNB_TRACE_H_
// int ngap_gNB_generate_trace_failure(sctp_data_t *sctp_data_p,
// int32_t stream,
// uint32_t gNB_ue_ngap_id,
// uint32_t amf_ue_ngap_id,
// E_UTRAN_Trace_ID_t *trace_id,
// Cause_t *cause_p);
// int ngap_gNB_handle_trace_start(gNB_amf_desc_t *gNB_desc_p,
// sctp_queue_item_t *packet_p,
// struct ngap_message_s *message_p);
int ngap_gNB_handle_trace_start(uint32_t assoc_id, int ngap_gNB_handle_trace_start(uint32_t assoc_id,
uint32_t stream, uint32_t stream,
NGAP_NGAP_PDU_t *pdu); NGAP_NGAP_PDU_t *pdu);
// int ngap_gNB_handle_deactivate_trace(gNB_amf_desc_t *gNB_desc_p,
// sctp_queue_item_t *packet_p,
// struct ngap_message_s *message_p);
int ngap_gNB_handle_deactivate_trace(uint32_t assoc_id, int ngap_gNB_handle_deactivate_trace(uint32_t assoc_id,
uint32_t stream, uint32_t stream,
NGAP_NGAP_PDU_t *pdu); NGAP_NGAP_PDU_t *pdu);
......
...@@ -40,8 +40,15 @@ ...@@ -40,8 +40,15 @@
#include "ngap_gNB_defs.h" #include "ngap_gNB_defs.h"
#include "ngap_gNB_ue_context.h" #include "ngap_gNB_ue_context.h"
int ngap_gNB_compare_gNB_ue_ngap_id( /* Tree of UE ordered by gNB_ue_ngap_id's
struct ngap_gNB_ue_context_s *p1, struct ngap_gNB_ue_context_s *p2) * NO INSTANCE, the 32 bits id is large enough to handle all UEs, regardless the cell, gNB, ...
*/
static RB_HEAD(ngap_ue_map, ngap_gNB_ue_context_s) ngap_ue_head = RB_INITIALIZER(&ngap_ue_head);
/* Generate the tree management functions prototypes */
RB_PROTOTYPE(ngap_ue_map, ngap_gNB_ue_context_s, entries, ngap_gNB_compare_gNB_ue_ngap_id);
static int ngap_gNB_compare_gNB_ue_ngap_id(struct ngap_gNB_ue_context_s *p1, struct ngap_gNB_ue_context_s *p2)
{ {
if (p1->gNB_ue_ngap_id > p2->gNB_ue_ngap_id) { if (p1->gNB_ue_ngap_id > p2->gNB_ue_ngap_id) {
return 1; return 1;
...@@ -58,46 +65,26 @@ int ngap_gNB_compare_gNB_ue_ngap_id( ...@@ -58,46 +65,26 @@ int ngap_gNB_compare_gNB_ue_ngap_id(
RB_GENERATE(ngap_ue_map, ngap_gNB_ue_context_s, entries, RB_GENERATE(ngap_ue_map, ngap_gNB_ue_context_s, entries,
ngap_gNB_compare_gNB_ue_ngap_id); ngap_gNB_compare_gNB_ue_ngap_id);
struct ngap_gNB_ue_context_s *ngap_gNB_allocate_new_UE_context(void) void ngap_store_ue_context(struct ngap_gNB_ue_context_s *ue_desc_p)
{ {
struct ngap_gNB_ue_context_s *new_p; if (RB_INSERT(ngap_ue_map, &ngap_ue_head, ue_desc_p))
LOG_E(NGAP, "Bug in UE uniq number allocation %u, we try to add a existing UE\n", ue_desc_p->gNB_ue_ngap_id);
new_p = malloc(sizeof(struct ngap_gNB_ue_context_s)); return;
if (new_p == NULL) {
NGAP_ERROR("Cannot allocate new ue context\n");
return NULL;
}
memset(new_p, 0, sizeof(struct ngap_gNB_ue_context_s));
return new_p;
} }
struct ngap_gNB_ue_context_s *ngap_gNB_get_ue_context( struct ngap_gNB_ue_context_s *ngap_get_ue_context(uint32_t gNB_ue_ngap_id)
ngap_gNB_instance_t *instance_p,
uint32_t gNB_ue_ngap_id)
{ {
ngap_gNB_ue_context_t temp; ngap_gNB_ue_context_t temp = {.gNB_ue_ngap_id = gNB_ue_ngap_id};
return RB_FIND(ngap_ue_map, &ngap_ue_head, &temp);
memset(&temp, 0, sizeof(struct ngap_gNB_ue_context_s));
/* 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);
} }
void ngap_gNB_free_ue_context(struct ngap_gNB_ue_context_s *ue_context_p) struct ngap_gNB_ue_context_s *ngap_detach_ue_context(uint32_t gNB_ue_ngap_id)
{ {
if (ue_context_p == NULL) { struct ngap_gNB_ue_context_s *tmp = ngap_get_ue_context(gNB_ue_ngap_id);
NGAP_ERROR("Trying to free a NULL context\n"); if (tmp == NULL) {
return; NGAP_ERROR("Trying to free a NULL UE context, %u\n", gNB_ue_ngap_id);
return NULL;
} }
RB_REMOVE(ngap_ue_map, &ngap_ue_head, tmp);
/* TODO: check that context is currently not in the tree of known return tmp;
* contexts.
*/
free(ue_context_p);
} }
...@@ -37,7 +37,6 @@ ...@@ -37,7 +37,6 @@
// Forward declarations // Forward declarations
struct ngap_gNB_amf_data_s; struct ngap_gNB_amf_data_s;
struct ngap_ue_map;
struct gNB_amf_desc_s; struct gNB_amf_desc_s;
typedef enum { typedef enum {
...@@ -59,11 +58,7 @@ typedef struct ngap_gNB_ue_context_s { ...@@ -59,11 +58,7 @@ typedef struct ngap_gNB_ue_context_s {
*/ */
uint32_t gNB_ue_ngap_id; uint32_t gNB_ue_ngap_id;
/* UE id for initial connection to NGAP */ uint64_t amf_ue_ngap_id;
uint16_t ue_initial_id;
/* Uniquely identifies the UE within AMF. Encoded on 32 bits. */
uint64_t amf_ue_ngap_id:40;
/* Stream used for this particular UE */ /* Stream used for this particular UE */
int32_t tx_stream; int32_t tx_stream;
...@@ -84,20 +79,9 @@ typedef struct ngap_gNB_ue_context_s { ...@@ -84,20 +79,9 @@ typedef struct ngap_gNB_ue_context_s {
ngap_gNB_instance_t *gNB_instance; ngap_gNB_instance_t *gNB_instance;
} ngap_gNB_ue_context_t; } ngap_gNB_ue_context_t;
int ngap_gNB_compare_gNB_ue_ngap_id( void ngap_store_ue_context(ngap_gNB_ue_context_t *ue_desc_p);
struct ngap_gNB_ue_context_s *p1, struct ngap_gNB_ue_context_s *p2);
/* Generate the tree management functions prototypes */
RB_PROTOTYPE(ngap_ue_map, ngap_gNB_ue_context_s, entries,
ngap_gNB_compare_gNB_ue_ngap_id);
struct ngap_gNB_ue_context_s *ngap_gNB_allocate_new_UE_context(void);
struct ngap_gNB_ue_context_s *ngap_gNB_get_ue_context(
ngap_gNB_instance_t *instance_p,
uint32_t gNB_ue_ngap_id);
void ngap_gNB_free_ue_context(struct ngap_gNB_ue_context_s *ue_context_p);
ngap_gNB_ue_context_t *ngap_get_ue_context(uint32_t gNB_ue_ngap_id);
ngap_gNB_ue_context_t *ngap_detach_ue_context(uint32_t gNB_ue_ngap_id);
#endif /* NGAP_GNB_UE_CONTEXT_H_ */ #endif /* NGAP_GNB_UE_CONTEXT_H_ */
...@@ -650,7 +650,7 @@ static void sctp_send_data(sctp_data_req_t *sctp_data_req_p) ...@@ -650,7 +650,7 @@ static void sctp_send_data(sctp_data_req_t *sctp_data_req_p)
/* TODO: notify upper layer */ /* TODO: notify upper layer */
return; return;
} }
free(sctp_data_req_p->buffer); // assuming it has been malloced
SCTP_DEBUG("Successfully sent %u bytes on stream %d for assoc_id %u\n", SCTP_DEBUG("Successfully sent %u bytes on stream %d for assoc_id %u\n",
sctp_data_req_p->buffer_length, sctp_data_req_p->stream, sctp_data_req_p->buffer_length, sctp_data_req_p->stream,
sctp_cnx->assoc_id); sctp_cnx->assoc_id);
......
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