Fix various problems in 4G NAS handling
- rename as_nas_info_t member data to nas_data to have a uniq name to trace between complex malloc/free of this pointer - fix, maybe not perfect, these pais od malloc/free - remove typedef name changes across transmission of these as_nas_info_t over itti, as name changing makes it even more confusing - remove globals that are likely possible races - in as_message_decode() fix memcpy size, it is hard to understand the initial idea, likely the author beleives a struct of struct makes a intermediate pointer - in network_api.c remove globals (static but used globally) - remove casts that are there to hide gcc warnings on probable unaligned access - remain a weird mix of packed/unpacked versions of the same typedef, but gcc is happy
This commit is contained in:
@@ -167,7 +167,7 @@ typedef struct as_stmsi_s {
|
||||
/* Dedicated NAS information */
|
||||
typedef struct as_nas_info_s {
|
||||
uint32_t length; /* Length of the NAS information data */
|
||||
Byte_t* data; /* Dedicated NAS information data container */
|
||||
Byte_t* nas_data; /* Dedicated NAS information data container */
|
||||
} as_nas_info_t;
|
||||
|
||||
/* Radio Access Bearer identity */
|
||||
|
||||
@@ -57,26 +57,26 @@ MESSAGE_DEF(RRC_CONFIGURATION_REQ, MESSAGE_PRIORITY_MED, RrcConfigura
|
||||
MESSAGE_DEF(NBIOTRRC_CONFIGURATION_REQ, MESSAGE_PRIORITY_MED, NbIoTRrcConfigurationReq, nbiotrrc_configuration_req)
|
||||
|
||||
// UE: NAS -> RRC messages
|
||||
MESSAGE_DEF(NAS_KENB_REFRESH_REQ, MESSAGE_PRIORITY_MED, NasKenbRefreshReq, nas_kenb_refresh_req)
|
||||
MESSAGE_DEF(NAS_CELL_SELECTION_REQ, MESSAGE_PRIORITY_MED, NasCellSelectionReq, nas_cell_selection_req)
|
||||
MESSAGE_DEF(NAS_CONN_ESTABLI_REQ, MESSAGE_PRIORITY_MED, NasConnEstabliReq, nas_conn_establi_req)
|
||||
MESSAGE_DEF(NAS_UPLINK_DATA_REQ, MESSAGE_PRIORITY_MED, NasUlDataReq, nas_ul_data_req)
|
||||
MESSAGE_DEF(NAS_DETACH_REQ, MESSAGE_PRIORITY_MED, NasDetachReq, nas_detach_req)
|
||||
MESSAGE_DEF(NAS_DEREGISTRATION_REQ, MESSAGE_PRIORITY_MED, NasDeregistrationReq, nas_deregistration_req)
|
||||
MESSAGE_DEF(NAS_KENB_REFRESH_REQ, MESSAGE_PRIORITY_MED, kenb_refresh_req_t, nas_kenb_refresh_req)
|
||||
MESSAGE_DEF(NAS_CELL_SELECTION_REQ, MESSAGE_PRIORITY_MED, cell_info_req_t, nas_cell_selection_req)
|
||||
MESSAGE_DEF(NAS_CONN_ESTABLI_REQ, MESSAGE_PRIORITY_MED, nas_establish_req_t, nas_conn_establi_req)
|
||||
MESSAGE_DEF(NAS_UPLINK_DATA_REQ, MESSAGE_PRIORITY_MED, ul_info_transfer_req_t, nas_ul_data_req)
|
||||
MESSAGE_DEF(NAS_DETACH_REQ, MESSAGE_PRIORITY_MED, nas_detach_req_t, nas_detach_req)
|
||||
MESSAGE_DEF(NAS_DEREGISTRATION_REQ, MESSAGE_PRIORITY_MED, nas_deregistration_req_t, nas_deregistration_req)
|
||||
|
||||
MESSAGE_DEF(NAS_RAB_ESTABLI_RSP, MESSAGE_PRIORITY_MED, NasRabEstRsp, nas_rab_est_rsp)
|
||||
MESSAGE_DEF(NAS_RAB_ESTABLI_RSP, MESSAGE_PRIORITY_MED, rab_establish_rsp_t, nas_rab_est_rsp)
|
||||
|
||||
MESSAGE_DEF(NAS_OAI_TUN_NSA, MESSAGE_PRIORITY_MED, NasOaiTunNsa, nas_oai_tun_nsa)
|
||||
MESSAGE_DEF(NAS_OAI_TUN_NSA, MESSAGE_PRIORITY_MED, nas_oai_tun_nsa_t, nas_oai_tun_nsa)
|
||||
|
||||
// UE: RRC -> NAS messages
|
||||
MESSAGE_DEF(NAS_CELL_SELECTION_CNF, MESSAGE_PRIORITY_MED, NasCellSelectionCnf, nas_cell_selection_cnf)
|
||||
MESSAGE_DEF(NAS_CELL_SELECTION_IND, MESSAGE_PRIORITY_MED, NasCellSelectionInd, nas_cell_selection_ind)
|
||||
MESSAGE_DEF(NAS_PAGING_IND, MESSAGE_PRIORITY_MED, NasPagingInd, nas_paging_ind)
|
||||
MESSAGE_DEF(NAS_CONN_ESTABLI_CNF, MESSAGE_PRIORITY_MED, NasConnEstabCnf, nas_conn_establi_cnf)
|
||||
MESSAGE_DEF(NAS_CONN_RELEASE_IND, MESSAGE_PRIORITY_MED, NasConnReleaseInd, nas_conn_release_ind)
|
||||
MESSAGE_DEF(NAS_CELL_SELECTION_CNF, MESSAGE_PRIORITY_MED, cell_info_cnf_t, nas_cell_selection_cnf)
|
||||
MESSAGE_DEF(NAS_CELL_SELECTION_IND, MESSAGE_PRIORITY_MED, cell_info_ind_t, nas_cell_selection_ind)
|
||||
MESSAGE_DEF(NAS_PAGING_IND, MESSAGE_PRIORITY_MED, paging_ind_t, nas_paging_ind)
|
||||
MESSAGE_DEF(NAS_CONN_ESTABLI_CNF, MESSAGE_PRIORITY_MED, nas_establish_cnf_t, nas_conn_establi_cnf)
|
||||
MESSAGE_DEF(NAS_CONN_RELEASE_IND, MESSAGE_PRIORITY_MED, nas_release_ind_t, nas_conn_release_ind)
|
||||
MESSAGE_DEF(NR_NAS_CONN_RELEASE_IND, MESSAGE_PRIORITY_MED, NRNasConnReleaseInd, nr_nas_conn_release_ind)
|
||||
MESSAGE_DEF(NAS_UPLINK_DATA_CNF, MESSAGE_PRIORITY_MED, NasUlDataCnf, nas_ul_data_cnf)
|
||||
MESSAGE_DEF(NAS_DOWNLINK_DATA_IND, MESSAGE_PRIORITY_MED, NasDlDataInd, nas_dl_data_ind)
|
||||
MESSAGE_DEF(NAS_UPLINK_DATA_CNF, MESSAGE_PRIORITY_MED, ul_info_transfer_cnf_t, nas_ul_data_cnf)
|
||||
MESSAGE_DEF(NAS_DOWNLINK_DATA_IND, MESSAGE_PRIORITY_MED, dl_info_transfer_ind_t, nas_dl_data_ind)
|
||||
|
||||
// xNB: realtime -> RRC messages
|
||||
MESSAGE_DEF(RRC_SUBFRAME_PROCESS, MESSAGE_PRIORITY_MED, RrcSubframeProcess, rrc_subframe_process)
|
||||
|
||||
@@ -422,28 +422,7 @@ typedef struct NRDuDlReq_s {
|
||||
rnti_t rnti;
|
||||
uint8_t *buf;
|
||||
uint64_t srb_id;
|
||||
} NRDuDlReq_t;
|
||||
|
||||
// UE: NAS -> RRC messages
|
||||
typedef kenb_refresh_req_t NasKenbRefreshReq;
|
||||
typedef cell_info_req_t NasCellSelectionReq;
|
||||
typedef nas_establish_req_t NasConnEstabliReq;
|
||||
typedef ul_info_transfer_req_t NasUlDataReq;
|
||||
typedef nas_deregistration_req_t NasDeregistrationReq;
|
||||
typedef nas_detach_req_t NasDetachReq;
|
||||
|
||||
typedef rab_establish_rsp_t NasRabEstRsp;
|
||||
|
||||
typedef nas_oai_tun_nsa_t NasOaiTunNsa;
|
||||
|
||||
// UE: RRC -> NAS messages
|
||||
typedef cell_info_cnf_t NasCellSelectionCnf;
|
||||
typedef cell_info_ind_t NasCellSelectionInd;
|
||||
typedef paging_ind_t NasPagingInd;
|
||||
typedef nas_establish_cnf_t NasConnEstabCnf;
|
||||
typedef nas_release_ind_t NasConnReleaseInd;
|
||||
typedef ul_info_transfer_cnf_t NasUlDataCnf;
|
||||
typedef dl_info_transfer_ind_t NasDlDataInd;
|
||||
} NRDuDlReq_t;
|
||||
|
||||
// eNB: realtime -> RRC messages
|
||||
typedef struct rrc_subframe_process_s {
|
||||
|
||||
+32
-30
@@ -536,18 +536,18 @@ rrc_t310_expiration(
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
static void rrc_ue_generate_RRCConnectionSetupComplete(
|
||||
const protocol_ctxt_t *const ctxt_pP,
|
||||
const uint8_t eNB_index,
|
||||
const uint8_t Transaction_id,
|
||||
uint8_t sel_plmn_id) {
|
||||
static void rrc_ue_generate_RRCConnectionSetupComplete(const protocol_ctxt_t *const ctxt_pP,
|
||||
const uint8_t eNB_index,
|
||||
const uint8_t Transaction_id,
|
||||
uint8_t sel_plmn_id)
|
||||
{
|
||||
uint8_t buffer[100];
|
||||
uint8_t size;
|
||||
const char *nas_msg;
|
||||
int nas_msg_length;
|
||||
|
||||
if (EPC_MODE_ENABLED) {
|
||||
nas_msg = (char *) UE_rrc_inst[ctxt_pP->module_id].initialNasMsg.data;
|
||||
nas_msg = (char *)UE_rrc_inst[ctxt_pP->module_id].initialNasMsg.nas_data;
|
||||
nas_msg_length = UE_rrc_inst[ctxt_pP->module_id].initialNasMsg.length;
|
||||
} else {
|
||||
nas_msg = nas_attach_req_imsi;
|
||||
@@ -1904,14 +1904,13 @@ static bool is_nr_r15_config_present(LTE_RRCConnectionReconfiguration_r8_IEs_t *
|
||||
#undef NCE
|
||||
#undef chk
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void
|
||||
rrc_ue_process_rrcConnectionReconfiguration(
|
||||
const protocol_ctxt_t *const ctxt_pP,
|
||||
LTE_RRCConnectionReconfiguration_t *rrcConnectionReconfiguration,
|
||||
uint8_t eNB_index
|
||||
)
|
||||
/** \brief process the received rrcConnectionReconfiguration message at UE
|
||||
\param ctxt_pP Running context
|
||||
\param *rrcConnectionReconfiguration pointer to the sturcture
|
||||
\param eNB_index Index of corresponding eNB/CH*/
|
||||
static void rrc_ue_process_rrcConnectionReconfiguration(const protocol_ctxt_t *const ctxt_pP,
|
||||
LTE_RRCConnectionReconfiguration_t *rrcConnectionReconfiguration,
|
||||
uint8_t eNB_index)
|
||||
//-----------------------------------------------------------------------------
|
||||
{
|
||||
LOG_I(RRC,"[UE %d] Frame %d: Receiving from SRB1 (DL-DCCH), Processing RRCConnectionReconfiguration (eNB %d)\n",
|
||||
@@ -2035,7 +2034,7 @@ rrc_ue_process_rrcConnectionReconfiguration(
|
||||
msg_p = itti_alloc_new_message(TASK_RRC_UE, 0, NAS_CONN_ESTABLI_CNF);
|
||||
NAS_CONN_ESTABLI_CNF(msg_p).errCode = AS_SUCCESS;
|
||||
NAS_CONN_ESTABLI_CNF(msg_p).nasMsg.length = pdu_length;
|
||||
NAS_CONN_ESTABLI_CNF(msg_p).nasMsg.data = pdu_buffer;
|
||||
NAS_CONN_ESTABLI_CNF(msg_p).nasMsg.nas_data = pdu_buffer;
|
||||
itti_send_msg_to_task(TASK_NAS_UE, ctxt_pP->instance, msg_p);
|
||||
}
|
||||
LOG_D(RRC, "Sent NAS_CONN_ESTABLI_CNF to NAS layer via itti!\n");
|
||||
@@ -2185,14 +2184,17 @@ rrc_detach_from_eNB(
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void
|
||||
rrc_ue_decode_dcch(
|
||||
const protocol_ctxt_t *const ctxt_pP,
|
||||
const rb_id_t Srb_id,
|
||||
const uint8_t *const Buffer,
|
||||
const uint32_t Buffer_size,
|
||||
const uint8_t eNB_indexP
|
||||
)
|
||||
/** \brief Decodes a DL-DCCH message and invokes appropriate routine to handle the message
|
||||
\param ctxt_pP Running context
|
||||
\param Srb_id Index of Srb (1,2)
|
||||
\param Buffer Pointer to received SDU
|
||||
\param Buffer_size
|
||||
\param eNB_indexP Index of corresponding eNB/CH*/
|
||||
static void rrc_ue_decode_dcch(const protocol_ctxt_t *const ctxt_pP,
|
||||
const rb_id_t Srb_id,
|
||||
const uint8_t *const Buffer,
|
||||
const uint32_t Buffer_size,
|
||||
const uint8_t eNB_indexP)
|
||||
//-----------------------------------------------------------------------------
|
||||
{
|
||||
//DL_DCCH_Message_t dldcchmsg;
|
||||
@@ -2247,15 +2249,14 @@ rrc_ue_decode_dcch(
|
||||
/* This message hold a dedicated info NAS payload, forward it to NAS */
|
||||
struct LTE_DLInformationTransfer_r8_IEs__dedicatedInfoType *dedicatedInfoType =
|
||||
&dlInformationTransfer->criticalExtensions.choice.c1.choice.dlInformationTransfer_r8.dedicatedInfoType;
|
||||
uint32_t pdu_length;
|
||||
uint8_t *pdu_buffer;
|
||||
MessageDef *msg_p;
|
||||
pdu_length = dedicatedInfoType->choice.dedicatedInfoNAS.size;
|
||||
pdu_buffer = dedicatedInfoType->choice.dedicatedInfoNAS.buf;
|
||||
uint32_t pdu_length = dedicatedInfoType->choice.dedicatedInfoNAS.size;
|
||||
uint8_t *pdu_buffer = malloc(pdu_length);
|
||||
memcpy(pdu_buffer, dedicatedInfoType->choice.dedicatedInfoNAS.buf, pdu_length);
|
||||
msg_p = itti_alloc_new_message(TASK_RRC_UE, 0, NAS_DOWNLINK_DATA_IND);
|
||||
NAS_DOWNLINK_DATA_IND(msg_p).UEid = ctxt_pP->module_id; // TODO set the UEid to something else ?
|
||||
NAS_DOWNLINK_DATA_IND(msg_p).nasMsg.length = pdu_length;
|
||||
NAS_DOWNLINK_DATA_IND(msg_p).nasMsg.data = pdu_buffer;
|
||||
NAS_DOWNLINK_DATA_IND(msg_p).nasMsg.nas_data = pdu_buffer;
|
||||
itti_send_msg_to_task(TASK_NAS_UE, ctxt_pP->instance, msg_p);
|
||||
}
|
||||
|
||||
@@ -2918,7 +2919,7 @@ int decode_BCCH_DLSCH_Message(
|
||||
}
|
||||
|
||||
if (rrc_get_sub_state(ctxt_pP->module_id) == RRC_SUB_STATE_IDLE_SIB_COMPLETE) {
|
||||
if ( (UE_rrc_inst[ctxt_pP->module_id].initialNasMsg.data != NULL) || (!EPC_MODE_ENABLED)) {
|
||||
if ((UE_rrc_inst[ctxt_pP->module_id].initialNasMsg.nas_data != NULL) || (!EPC_MODE_ENABLED)) {
|
||||
rrc_ue_generate_RRCConnectionRequest(ctxt_pP, 0);
|
||||
rrc_set_sub_state( ctxt_pP->module_id, RRC_SUB_STATE_IDLE_CONNECTING );
|
||||
}
|
||||
@@ -5173,7 +5174,8 @@ void *rrc_ue_task( void *args_p ) {
|
||||
uint8_t *buffer;
|
||||
LOG_D(RRC, "[UE %d] Received %s: UEid %d\n", ue_mod_id, ITTI_MSG_NAME (msg_p), NAS_UPLINK_DATA_REQ (msg_p).UEid);
|
||||
/* Create message for PDCP (ULInformationTransfer_t) */
|
||||
length = do_ULInformationTransfer(&buffer, NAS_UPLINK_DATA_REQ (msg_p).nasMsg.length, NAS_UPLINK_DATA_REQ (msg_p).nasMsg.data);
|
||||
length =
|
||||
do_ULInformationTransfer(&buffer, NAS_UPLINK_DATA_REQ(msg_p).nasMsg.length, NAS_UPLINK_DATA_REQ(msg_p).nasMsg.nas_data);
|
||||
/* Transfer data to PDCP */
|
||||
PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_id, ENB_FLAG_NO, UE_rrc_inst[ue_mod_id].Info[0].rnti, 0, 0,0);
|
||||
|
||||
|
||||
@@ -93,21 +93,6 @@ rrc_rx_tx_ue(
|
||||
\param eNB_index Index of corresponding eNB/CH*/
|
||||
int rrc_ue_decode_ccch( const protocol_ctxt_t *const ctxt_pP, const SRB_INFO *const Srb_info, const uint8_t eNB_index );
|
||||
|
||||
/** \brief Decodes a DL-DCCH message and invokes appropriate routine to handle the message
|
||||
\param ctxt_pP Running context
|
||||
\param Srb_id Index of Srb (1,2)
|
||||
\param Buffer Pointer to received SDU
|
||||
\param Buffer_size
|
||||
\param eNB_indexP Index of corresponding eNB/CH*/
|
||||
void
|
||||
rrc_ue_decode_dcch(
|
||||
const protocol_ctxt_t *const ctxt_pP,
|
||||
const rb_id_t Srb_id,
|
||||
const uint8_t *const Buffer,
|
||||
const uint32_t Buffer_size,
|
||||
const uint8_t eNB_indexP
|
||||
);
|
||||
|
||||
int decode_SL_Discovery_Message(
|
||||
const protocol_ctxt_t *const ctxt_pP,
|
||||
const uint8_t eNB_index,
|
||||
@@ -123,17 +108,6 @@ rrc_ue_generate_RRCConnectionRequest(
|
||||
const uint8_t eNB_index
|
||||
);
|
||||
|
||||
/** \brief process the received rrcConnectionReconfiguration message at UE
|
||||
\param ctxt_pP Running context
|
||||
\param *rrcConnectionReconfiguration pointer to the sturcture
|
||||
\param eNB_index Index of corresponding eNB/CH*/
|
||||
void
|
||||
rrc_ue_process_rrcConnectionReconfiguration(
|
||||
const protocol_ctxt_t *const ctxt_pP,
|
||||
LTE_RRCConnectionReconfiguration_t *rrcConnectionReconfiguration,
|
||||
uint8_t eNB_index
|
||||
);
|
||||
|
||||
/** \brief Establish SRB1 based on configuration in SRB_ToAddMod structure. Configures RLC/PDCP accordingly
|
||||
\param module_idP Instance ID of UE
|
||||
\param frameP Frame index
|
||||
|
||||
@@ -189,10 +189,10 @@ static void nr_rrc_ue_process_rrcReconfiguration(NR_UE_RRC_INST_t *rrc,
|
||||
struct NR_RRCReconfiguration_v1530_IEs__dedicatedNAS_MessageList *tmp = ext->dedicatedNAS_MessageList;
|
||||
for (int i = 0; i < tmp->list.count; i++) {
|
||||
MessageDef *ittiMsg = itti_alloc_new_message(TASK_RRC_NRUE, rrc->ue_id, NAS_CONN_ESTABLI_CNF);
|
||||
NasConnEstabCnf *msg = &NAS_CONN_ESTABLI_CNF(ittiMsg);
|
||||
nas_establish_cnf_t *msg = &NAS_CONN_ESTABLI_CNF(ittiMsg);
|
||||
msg->errCode = AS_SUCCESS;
|
||||
msg->nasMsg.length = tmp->list.array[i]->size;
|
||||
msg->nasMsg.data = tmp->list.array[i]->buf;
|
||||
msg->nasMsg.nas_data = tmp->list.array[i]->buf;
|
||||
itti_send_msg_to_task(TASK_NAS_NRUE, rrc->ue_id, ittiMsg);
|
||||
}
|
||||
tmp->list.count = 0; // to prevent the automatic free by ASN1_FREE
|
||||
@@ -998,7 +998,7 @@ static void rrc_ue_generate_RRCSetupComplete(const NR_UE_RRC_INST_t *rrc, const
|
||||
as_nas_info_t initialNasMsg;
|
||||
nr_ue_nas_t *nas = get_ue_nas_info(rrc->ue_id);
|
||||
generateRegistrationRequest(&initialNasMsg, nas);
|
||||
nas_msg = (char*)initialNasMsg.data;
|
||||
nas_msg = (char *)initialNasMsg.nas_data;
|
||||
nas_msg_length = initialNasMsg.length;
|
||||
} else {
|
||||
nas_msg = nr_nas_attach_req_imsi_dummy_NSA_case;
|
||||
@@ -1751,10 +1751,11 @@ static int nr_rrc_ue_decode_dcch(NR_UE_RRC_INST_t *rrc,
|
||||
dlInformationTransfer->criticalExtensions.choice.dlInformationTransfer->dedicatedNAS_Message;
|
||||
|
||||
MessageDef *ittiMsg = itti_alloc_new_message(TASK_RRC_NRUE, rrc->ue_id, NAS_DOWNLINK_DATA_IND);
|
||||
NasDlDataInd *msg = &NAS_DOWNLINK_DATA_IND(ittiMsg);
|
||||
dl_info_transfer_ind_t *msg = &NAS_DOWNLINK_DATA_IND(ittiMsg);
|
||||
msg->UEid = rrc->ue_id;
|
||||
msg->nasMsg.length = dedicatedNAS_Message->size;
|
||||
msg->nasMsg.data = dedicatedNAS_Message->buf;
|
||||
msg->nasMsg.nas_data = malloc(msg->nasMsg.length);
|
||||
memcpy(msg->nasMsg.nas_data, dedicatedNAS_Message->buf, msg->nasMsg.length);
|
||||
itti_send_msg_to_task(TASK_NAS_NRUE, rrc->ue_id, ittiMsg);
|
||||
dedicatedNAS_Message->buf = NULL; // to keep the buffer, up to NAS to free it
|
||||
}
|
||||
@@ -1907,15 +1908,15 @@ void *rrc_nrue(void *notUsed)
|
||||
case NAS_UPLINK_DATA_REQ: {
|
||||
uint32_t length;
|
||||
uint8_t *buffer = NULL;
|
||||
NasUlDataReq *req = &NAS_UPLINK_DATA_REQ(msg_p);
|
||||
ul_info_transfer_req_t *req = &NAS_UPLINK_DATA_REQ(msg_p);
|
||||
/* Create message for PDCP (ULInformationTransfer_t) */
|
||||
length = do_NR_ULInformationTransfer(&buffer, req->nasMsg.length, req->nasMsg.data);
|
||||
length = do_NR_ULInformationTransfer(&buffer, req->nasMsg.length, req->nasMsg.nas_data);
|
||||
/* Transfer data to PDCP */
|
||||
// check if SRB2 is created, if yes request data_req on SRB2
|
||||
// error: the remote gNB is hardcoded here
|
||||
rb_id_t srb_id = rrc->Srb[2] == RB_ESTABLISHED ? 2 : 1;
|
||||
nr_pdcp_data_req_srb(rrc->ue_id, srb_id, 0, length, buffer, deliver_pdu_srb_rlc, NULL);
|
||||
free(req->nasMsg.data);
|
||||
free(req->nasMsg.nas_data);
|
||||
free(buffer);
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user