diff --git a/executables/nr-uesoftmodem.c b/executables/nr-uesoftmodem.c index d3d8090be5d6ce40b5824c1f194e43ed45d15201..6d8ce1f15e7a82abc8673410be4e7053707aed77 100644 --- a/executables/nr-uesoftmodem.c +++ b/executables/nr-uesoftmodem.c @@ -550,7 +550,7 @@ int main( int argc, char **argv ) { // Sleep a while before checking all parameters have been used // Some are used directly in external threads, asynchronously - sleep(20); + sleep(200); config_check_unknown_cmdlineopt(CONFIG_CHECKALLSECTIONS); while(true) diff --git a/openair2/COMMON/ngap_messages_types.h b/openair2/COMMON/ngap_messages_types.h index 0f60b7abac945b96a736ccf67bb08885f100aa14..87426eff98416de4c9e568fcbd39026d34517b80 100644 --- a/openair2/COMMON/ngap_messages_types.h +++ b/openair2/COMMON/ngap_messages_types.h @@ -350,9 +350,12 @@ typedef enum ngap_Cause_e { NGAP_CAUSE_NAS, NGAP_CAUSE_PROTOCOL, NGAP_CAUSE_MISC, - /* Extensions may appear below */ - -} ngap_Cause_t; + 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; typedef enum ngap_Cause_radio_network_e { NGAP_CAUSE_RADIO_NETWORK_UNSPECIFIED, diff --git a/openair2/COMMON/sctp_messages_types.h b/openair2/COMMON/sctp_messages_types.h index c2561c0424ed42803a9d9ae4aa0ac9f7ae131b45..594b9f06e82851b3e2f2057af88b261ec000b60b 100644 --- a/openair2/COMMON/sctp_messages_types.h +++ b/openair2/COMMON/sctp_messages_types.h @@ -119,7 +119,7 @@ typedef struct sctp_data_ind_s { /* Buffer to send over SCTP */ uint32_t buffer_length; uint8_t *buffer; - + bool freeAfterSend; /* Streams on which data will be sent/received */ uint16_t stream; } sctp_data_ind_t; diff --git a/openair2/E1AP/e1ap_common.c b/openair2/E1AP/e1ap_common.c index 2db1ecef65b7236578430f2c83efcd1d9d6f0c22..e58c4dbc8157105b305f4990ecfa3497359a2be6 100644 --- a/openair2/E1AP/e1ap_common.c +++ b/openair2/E1AP/e1ap_common.c @@ -227,6 +227,7 @@ int e1ap_encode_send(E1_t type, e1ap_setup_req_t *setupReq, E1AP_E1AP_PDU_t *pdu s->buffer = buffer; s->buffer_length = encoded; s->stream = stream; + s->freeAfterSend=true; LOG_I(E1AP, "%s: Sending ITTI message to SCTP Task\n", func); itti_send_msg_to_task(TASK_SCTP, 0 /*unused by callee*/, message); } diff --git a/openair2/F1AP/f1ap_itti_messaging.c b/openair2/F1AP/f1ap_itti_messaging.c index e45edcc3a3bfed2ca60d06a60e5bb39a7827333a..3026a9b25d898b91242b7432a9a40ed3880b19ae 100644 --- a/openair2/F1AP/f1ap_itti_messaging.c +++ b/openair2/F1AP/f1ap_itti_messaging.c @@ -32,6 +32,7 @@ void f1ap_itti_send_sctp_data_req(bool isCu, instance_t instance, uint8_t *buffe sctp_data_req->buffer = buffer; sctp_data_req->buffer_length = buffer_length; sctp_data_req->stream = stream; + sctp_data_req->freeAfterSend=true; LOG_D(F1AP, "Sending ITTI message to SCTP Task\n"); itti_send_msg_to_task(TASK_SCTP, instance, message_p); } diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c index b599aadddf3ab813994f5902e06a22cdad86d243..f36dffa85fbf03d5953b8cb4bb71618cc9b4013e 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c @@ -2799,7 +2799,13 @@ void nr_mac_update_timers(module_id_t module_id, (void **)&cg, (uint8_t *)UE->cg_buf, (UE->enc_rval.encoded+7)/8, 0, 0); - UE->CellGroup = cg; + if (UE->CellGroup) { + NR_CellGroupConfig_t *tmp=UE->CellGroup; + UE->CellGroup = cg; + ASN_STRUCT_FREE(asn_DEF_NR_CellGroupConfig,tmp); + } else + UE->CellGroup = cg; + if (LOG_DEBUGFLAG(DEBUG_ASN1)) { xer_fprint(stdout, &asn_DEF_NR_CellGroupConfig, (const void *) UE->CellGroup); diff --git a/openair2/RRC/NR/MESSAGES/asn1_msg.c b/openair2/RRC/NR/MESSAGES/asn1_msg.c index 9f846f9594e45721e96c20b52cf71ddaefd53719..3be51ca4edfd4784c822e513592c2ef2f72afce7 100644 --- a/openair2/RRC/NR/MESSAGES/asn1_msg.c +++ b/openair2/RRC/NR/MESSAGES/asn1_msg.c @@ -1298,27 +1298,24 @@ uint8_t do_NR_SecurityModeCommand( uint8_t *const buffer, const uint8_t Transaction_id, 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; - memset(&dl_dcch_msg,0,sizeof(NR_DL_DCCH_Message_t)); dl_dcch_msg.message.present = NR_DL_DCCH_MessageType_PR_c1; - dl_dcch_msg.message.choice.c1=CALLOC(1,sizeof(struct NR_DL_DCCH_MessageType__c1)); - dl_dcch_msg.message.choice.c1->present = NR_DL_DCCH_MessageType__c1_PR_securityModeCommand; - dl_dcch_msg.message.choice.c1->choice.securityModeCommand = CALLOC(1, sizeof(struct NR_SecurityModeCommand)); - dl_dcch_msg.message.choice.c1->choice.securityModeCommand->rrc_TransactionIdentifier = Transaction_id; - dl_dcch_msg.message.choice.c1->choice.securityModeCommand->criticalExtensions.present = NR_SecurityModeCommand__criticalExtensions_PR_securityModeCommand; + asn1cCalloc(dl_dcch_msg.message.choice.c1, c1); + c1->present = NR_DL_DCCH_MessageType__c1_PR_securityModeCommand; + asn1cCalloc(c1->choice.securityModeCommand,scm); + scm->rrc_TransactionIdentifier = Transaction_id; + scm->criticalExtensions.present = NR_SecurityModeCommand__criticalExtensions_PR_securityModeCommand; - dl_dcch_msg.message.choice.c1->choice.securityModeCommand->criticalExtensions.choice.securityModeCommand = - CALLOC(1, sizeof(struct NR_SecurityModeCommand_IEs)); + asn1cCalloc(scm->criticalExtensions.choice.securityModeCommand,scmIE); // 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; - dl_dcch_msg.message.choice.c1->choice.securityModeCommand->criticalExtensions.choice.securityModeCommand->securityConfigSMC.securityAlgorithmConfig.integrityProtAlgorithm - = integrityProtAlgorithm; + asn1cCallocOne(scmIE->securityConfigSMC.securityAlgorithmConfig.integrityProtAlgorithm, integrityProtAlgorithm); if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) { xer_fprint(stdout, &asn_DEF_NR_DL_DCCH_Message, (void *)&dl_dcch_msg); @@ -1332,7 +1329,7 @@ uint8_t do_NR_SecurityModeCommand( AssertFatal(enc_rval.encoded >0 , "ASN1 message encoding failed (%s, %lu)!\n", 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); // rrc_ue_process_ueCapabilityEnquiry(0,1000,&dl_dcch_msg.message.choice.c1.choice.ueCapabilityEnquiry,0); @@ -1751,29 +1748,26 @@ do_NR_DLInformationTransfer( //------------------------------------------------------------------------------ { ssize_t encoded; - NR_DL_DCCH_Message_t dl_dcch_msg; - memset(&dl_dcch_msg, 0, sizeof(NR_DL_DCCH_Message_t)); + NR_DL_DCCH_Message_t dl_dcch_msg={0}; dl_dcch_msg.message.present = NR_DL_DCCH_MessageType_PR_c1; - dl_dcch_msg.message.choice.c1 = CALLOC(1, sizeof(struct NR_DL_DCCH_MessageType__c1)); - dl_dcch_msg.message.choice.c1->present = NR_DL_DCCH_MessageType__c1_PR_dlInformationTransfer; + asn1cCalloc(dl_dcch_msg.message.choice.c1, c1); + c1->present = NR_DL_DCCH_MessageType__c1_PR_dlInformationTransfer; - dl_dcch_msg.message.choice.c1->choice.dlInformationTransfer = CALLOC(1, sizeof(NR_DLInformationTransfer_t)); - dl_dcch_msg.message.choice.c1->choice.dlInformationTransfer->rrc_TransactionIdentifier = transaction_id; - dl_dcch_msg.message.choice.c1->choice.dlInformationTransfer->criticalExtensions.present = + asn1cCalloc(c1->choice.dlInformationTransfer, infoTransfer); + infoTransfer->rrc_TransactionIdentifier = transaction_id; + infoTransfer->criticalExtensions.present = NR_DLInformationTransfer__criticalExtensions_PR_dlInformationTransfer; - dl_dcch_msg.message.choice.c1->choice.dlInformationTransfer-> - criticalExtensions.choice.dlInformationTransfer = CALLOC(1, sizeof(NR_DLInformationTransfer_IEs_t)); - dl_dcch_msg.message.choice.c1->choice.dlInformationTransfer-> - criticalExtensions.choice.dlInformationTransfer->dedicatedNAS_Message = CALLOC(1, sizeof(NR_DedicatedNAS_Message_t)); - dl_dcch_msg.message.choice.c1->choice.dlInformationTransfer-> - criticalExtensions.choice.dlInformationTransfer->dedicatedNAS_Message->buf = pdu_buffer; - dl_dcch_msg.message.choice.c1->choice.dlInformationTransfer-> - criticalExtensions.choice.dlInformationTransfer->dedicatedNAS_Message->size = pdu_length; + asn1cCalloc(infoTransfer->criticalExtensions.choice.dlInformationTransfer, dlInfoTransfer); + asn1cCalloc(dlInfoTransfer->dedicatedNAS_Message,msg); + // we will free the caller buffer + msg->buf = pdu_buffer; + msg->size = pdu_length; encoded = uper_encode_to_new_buffer (&asn_DEF_NR_DL_DCCH_Message, NULL, (void *) &dl_dcch_msg, (void **)buffer); AssertFatal(encoded > 0,"ASN1 message encoding failed (%s, %ld)!\n", "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); //for (int i=0;i<encoded;i++) printf("%02x ",(*buffer)[i]); return encoded; diff --git a/openair2/RRC/NR/MESSAGES/asn1_msg.h b/openair2/RRC/NR/MESSAGES/asn1_msg.h index 090bbb5c84cae3b678ed832060af5d2faf9e2f72..1df0920a06558173f5e9e320ac2da9c032d98aec 100644 --- a/openair2/RRC/NR/MESSAGES/asn1_msg.h +++ b/openair2/RRC/NR/MESSAGES/asn1_msg.h @@ -113,7 +113,7 @@ uint8_t do_NR_SecurityModeCommand( uint8_t *const buffer, const uint8_t Transaction_id, 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 *const buffer, diff --git a/openair2/RRC/NR/rrc_gNB.c b/openair2/RRC/NR/rrc_gNB.c index fc2cfe9e9a105ec6b74c5a51ea3ca8fc3f0c27b1..4a0e8cf9d1cd24d3ad03a2d560df868004a124c2 100644 --- a/openair2/RRC/NR/rrc_gNB.c +++ b/openair2/RRC/NR/rrc_gNB.c @@ -3868,7 +3868,7 @@ rrc_gNB_generate_SecurityModeCommand( T(T_ENB_RRC_SECURITY_MODE_COMMAND, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame), T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rntiMaybeUEid)); NR_IntegrityProtAlgorithm_t integrity_algorithm = (NR_IntegrityProtAlgorithm_t)ue_p->integrity_algorithm; - size = do_NR_SecurityModeCommand(ctxt_pP, buffer, rrc_gNB_get_next_transaction_identifier(ctxt_pP->module_id), ue_p->ciphering_algorithm, &integrity_algorithm); + size = do_NR_SecurityModeCommand(ctxt_pP, buffer, rrc_gNB_get_next_transaction_identifier(ctxt_pP->module_id), ue_p->ciphering_algorithm, integrity_algorithm); LOG_DUMPMSG(NR_RRC,DEBUG_RRC,(char *)buffer,size,"[MSG] RRC Security Mode Command\n"); LOG_I(NR_RRC, "UE %04x Logical Channel DL-DCCH, Generate SecurityModeCommand (bytes %d)\n", ue_p->rnti, size); diff --git a/openair2/RRC/NR/rrc_gNB_NGAP.c b/openair2/RRC/NR/rrc_gNB_NGAP.c index e4dc239237af6a62d63f4d856b56ac887f929bf4..f88dbc719b61632075f7bcd21b01b6fcc04718d3 100644 --- a/openair2/RRC/NR/rrc_gNB_NGAP.c +++ b/openair2/RRC/NR/rrc_gNB_NGAP.c @@ -279,6 +279,9 @@ static void fill_qos(NGAP_QosFlowSetupRequestList_t *qos, pdusession_t *session) static int decodePDUSessionResourceSetup(pdusession_t *session) { NGAP_PDUSessionResourceSetupRequestTransfer_t *pdusessionTransfer; + for (int i=0; i<session->pdusessionTransfer.length; i++) + printf("%02x:",session->pdusessionTransfer.buffer[i]); + printf("\n"); asn_codec_ctx_t st = {.max_stack_size = 100 * 1000}; asn_dec_rval_t dec_rval = aper_decode(&st, &asn_DEF_NGAP_PDUSessionResourceSetupRequestTransfer, (void **)&pdusessionTransfer, session->pdusessionTransfer.buffer, session->pdusessionTransfer.length, 0, 0); @@ -345,6 +348,8 @@ static int decodePDUSessionResourceSetup(pdusession_t *session) return -1; } } + ASN_STRUCT_FREE(asn_DEF_NGAP_PDUSessionResourceSetupRequestTransfer,pdusessionTransfer ); + return 0; } @@ -629,6 +634,7 @@ int rrc_gNB_process_NGAP_DOWNLINK_NAS(MessageDef *msg_p, instance_t instance, mu AssertFatal(srb_id > 0 && srb_id < maxSRBs, ""); /* Transfer data to PDCP */ nr_rrc_data_req(&ctxt, srb_id, (*rrc_gNB_mui)++, SDU_CONFIRM_NO, length, buffer, PDCP_TRANSMISSION_MODE_CONTROL); + free(buffer); // nr_rrc_data_req do a second malloc and copy } break; case ngran_gNB_DU: @@ -924,6 +930,7 @@ static void decodePDUSessionResourceModify(pdusession_t *param, const ngap_pdu_t return; } } + ASN_STRUCT_FREE(asn_DEF_NGAP_PDUSessionResourceModifyRequestTransfer,pdusessionTransfer ); } //------------------------------------------------------------------------------ diff --git a/openair2/X2AP/x2ap_eNB_itti_messaging.c b/openair2/X2AP/x2ap_eNB_itti_messaging.c index 26e26ba4115ce2e4ff87101a34554d907d16ece9..6468e2134e1ed0bf719926c8e71dc249e9638afe 100644 --- a/openair2/X2AP/x2ap_eNB_itti_messaging.c +++ b/openair2/X2AP/x2ap_eNB_itti_messaging.c @@ -44,6 +44,7 @@ void x2ap_eNB_itti_send_sctp_data_req(instance_t instance, int32_t assoc_id, uin sctp_data_req->buffer = buffer; sctp_data_req->buffer_length = buffer_length; sctp_data_req->stream = stream; + sctp_data_req->freeAfterSend=true; itti_send_msg_to_task(TASK_SCTP, instance, message_p); } diff --git a/openair3/NGAP/ngap_gNB_context_management_procedures.c b/openair3/NGAP/ngap_gNB_context_management_procedures.c index f82b25d39048bc4dada46350f05c8bc1b776fe4f..8d3c20d218758c89451961eb1211cdd74f7f5b95 100644 --- a/openair3/NGAP/ngap_gNB_context_management_procedures.c +++ b/openair3/NGAP/ngap_gNB_context_management_procedures.c @@ -187,7 +187,7 @@ int ngap_ue_context_release_req(instance_t instance, ie->id = NGAP_ProtocolIE_ID_id_Cause; ie->criticality = NGAP_Criticality_ignore; ie->value.present = NGAP_UEContextReleaseRequest_IEs__value_PR_Cause; - DevAssert(ue_release_req_p->cause <= NGAP_Cause_PR_choice_Extensions); + DevAssert(ue_release_req_p->cause <= NGAP_Cause_PR_choice_ExtensionS); ie->value.choice.Cause.present = ue_release_req_p->cause; ie->value.choice.Cause.choice.misc = ue_release_req_p->cause_value; } diff --git a/openair3/NGAP/ngap_gNB_itti_messaging.c b/openair3/NGAP/ngap_gNB_itti_messaging.c index bb9de4da36989ad004361197d6232b7e85a2b069..78751b693a5d16c9b04cb580abe50a5924a2a10d 100644 --- a/openair3/NGAP/ngap_gNB_itti_messaging.c +++ b/openair3/NGAP/ngap_gNB_itti_messaging.c @@ -45,6 +45,7 @@ void ngap_gNB_itti_send_sctp_data_req(instance_t instance, int32_t assoc_id, uin sctp_data_req->buffer = buffer; sctp_data_req->buffer_length = buffer_length; sctp_data_req->stream = stream; + sctp_data_req->freeAfterSend=true; itti_send_msg_to_task(TASK_SCTP, instance, message_p); } diff --git a/openair3/SCTP/sctp_eNB_task.c b/openair3/SCTP/sctp_eNB_task.c index 14128dd53e476fe26ee451d42e68ee3fa276f3bb..ef419556d7a532f376bcc71885cf8c18b7563204 100644 --- a/openair3/SCTP/sctp_eNB_task.c +++ b/openair3/SCTP/sctp_eNB_task.c @@ -650,7 +650,8 @@ static void sctp_send_data(sctp_data_req_t *sctp_data_req_p) /* TODO: notify upper layer */ return; } - + if ( sctp_data_req_p->freeAfterSend) + free(sctp_data_req_p->buffer); 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_cnx->assoc_id);