Commit 70a052a6 authored by Xue Song's avatar Xue Song

add NAS up/downlink

parent 97b8a7d6
......@@ -68,6 +68,7 @@
#include "NR_SDAP-Config.h"
#include "NR_RRCReconfigurationComplete.h"
#include "NR_RRCReconfigurationComplete-IEs.h"
#include "NR_DLInformationTransfer.h"
#if defined(NR_Rel16)
#include "NR_SCS-SpecificCarrier.h"
#include "NR_TDD-UL-DL-ConfigCommon.h"
......@@ -1270,3 +1271,64 @@ enc_rval = uper_encode_to_buffer(&asn_DEF_NR_UL_DCCH_Message,
return((enc_rval.encoded+7)/8);
}
//------------------------------------------------------------------------------
uint8_t
do_NR_DLInformationTransfer(
uint8_t Mod_id,
uint8_t **buffer,
uint8_t transaction_id,
uint32_t pdu_length,
uint8_t *pdu_buffer
)
//------------------------------------------------------------------------------
{
ssize_t encoded;
NR_DL_DCCH_Message_t dl_dcch_msg;
memset(&dl_dcch_msg, 0, sizeof(NR_DL_DCCH_Message_t));
dl_dcch_msg.message.present = NR_DL_DCCH_MessageType_PR_c1;
dl_dcch_msg.message.choice.c1 = CALLOC(1, sizeof(struct NR_DL_DCCH_MessageType__c1));
dl_dcch_msg.message.choice.c1->present = NR_DL_DCCH_MessageType__c1_PR_dlInformationTransfer;
dl_dcch_msg.message.choice.c1->choice.dlInformationTransfer = CALLOC(1, sizeof(NR_DLInformationTransfer_t));
dl_dcch_msg.message.choice.c1->choice.dlInformationTransfer->rrc_TransactionIdentifier = transaction_id;
dl_dcch_msg.message.choice.c1->choice.dlInformationTransfer->criticalExtensions.present =
NR_DLInformationTransfer__criticalExtensions_PR_dlInformationTransfer;
dl_dcch_msg.message.choice.c1->choice.dlInformationTransfer->
criticalExtensions.choice.dlInformationTransfer = CALLOC(1, sizeof(NR_DLInformationTransfer_IEs_t));
dl_dcch_msg.message.choice.c1->choice.dlInformationTransfer->
criticalExtensions.choice.dlInformationTransfer->dedicatedNAS_Message = CALLOC(1, sizeof(NR_DedicatedNAS_Message_t));
dl_dcch_msg.message.choice.c1->choice.dlInformationTransfer->
criticalExtensions.choice.dlInformationTransfer->dedicatedNAS_Message->buf = pdu_buffer;
dl_dcch_msg.message.choice.c1->choice.dlInformationTransfer->
criticalExtensions.choice.dlInformationTransfer->dedicatedNAS_Message->size = pdu_length;
encoded = uper_encode_to_new_buffer (&asn_DEF_NR_DL_DCCH_Message, NULL, (void *) &dl_dcch_msg, (void **)buffer);
AssertFatal(encoded > 0,"ASN1 message encoding failed (%s, %lu)!\n",
"DLInformationTransfer", encoded);
LOG_D(NR_RRC,"DLInformationTransfer Encoded %zd bytes\n", encoded);
return encoded;
}
uint8_t do_NR_ULInformationTransfer(uint8_t **buffer, uint32_t pdu_length, uint8_t *pdu_buffer) {
ssize_t encoded;
NR_UL_DCCH_Message_t ul_dcch_msg;
memset(&ul_dcch_msg, 0, sizeof(NR_UL_DCCH_Message_t));
ul_dcch_msg.message.present = NR_UL_DCCH_MessageType_PR_c1;
ul_dcch_msg.message.choice.c1 = CALLOC(1,sizeof(struct NR_UL_DCCH_MessageType__c1));
ul_dcch_msg.message.choice.c1->present = NR_UL_DCCH_MessageType__c1_PR_ulInformationTransfer;
ul_dcch_msg.message.choice.c1->choice.ulInformationTransfer = CALLOC(1,sizeof(struct NR_ULInformationTransfer));
ul_dcch_msg.message.choice.c1->choice.ulInformationTransfer->criticalExtensions.present = NR_ULInformationTransfer__criticalExtensions_PR_ulInformationTransfer;
ul_dcch_msg.message.choice.c1->choice.ulInformationTransfer->criticalExtensions.choice.ulInformationTransfer = CALLOC(1,sizeof(struct NR_ULInformationTransfer_IEs));
struct NR_ULInformationTransfer_IEs *ulInformationTransfer = ul_dcch_msg.message.choice.c1->choice.ulInformationTransfer->criticalExtensions.choice.ulInformationTransfer;
ulInformationTransfer->dedicatedNAS_Message = CALLOC(1,sizeof(NR_DedicatedNAS_Message_t));
ulInformationTransfer->dedicatedNAS_Message->buf = pdu_buffer;
ulInformationTransfer->dedicatedNAS_Message->size = pdu_length;
ulInformationTransfer->lateNonCriticalExtension = NULL;
encoded = uper_encode_to_new_buffer (&asn_DEF_NR_UL_DCCH_Message, NULL, (void *) &ul_dcch_msg, (void **) buffer);
AssertFatal(encoded > 0,"ASN1 message encoding failed (%s, %lu)!\n",
"ULInformationTransfer",encoded);
LOG_D(NR_RRC,"ULInformationTransfer Encoded %zd bytes\n",encoded);
return encoded;
}
......@@ -126,3 +126,16 @@ uint8_t do_NR_RRCReconfigurationComplete(
uint8_t *buffer,
const uint8_t Transaction_id
);
uint8_t
do_NR_DLInformationTransfer(
uint8_t Mod_id,
uint8_t **buffer,
uint8_t transaction_id,
uint32_t pdu_length,
uint8_t *pdu_buffer
);
uint8_t do_NR_ULInformationTransfer(uint8_t **buffer,
uint32_t pdu_length,
uint8_t *pdu_buffer);
\ No newline at end of file
......@@ -1309,6 +1309,10 @@ void *rrc_gnb_task(void *args_p) {
break;
case NGAP_DOWNLINK_NAS:
rrc_gNB_process_NGAP_DOWNLINK_NAS(msg_p, msg_name_p, instance, &rrc_gNB_mui);
break;
/*
#if defined(ENABLE_USE_MME)
......
......@@ -330,7 +330,7 @@ rrc_gNB_process_NGAP_INITIAL_CONTEXT_SETUP_REQ(
if (ue_context_p == NULL) {
/* Can not associate this message to an UE index, send a failure to NGAP and discard it! */
MessageDef *msg_fail_p = NULL;
LOG_W(NR_RRC, "[gNB %d] In NGAP_INITIAL_CONTEXT_SETUP_REQ: unknown UE from S1AP ids (%d, %d)\n", instance, ue_initial_id, gNB_ue_ngap_id);
LOG_W(NR_RRC, "[gNB %d] In NGAP_INITIAL_CONTEXT_SETUP_REQ: unknown UE from NGAP ids (%d, %d)\n", instance, ue_initial_id, gNB_ue_ngap_id);
msg_fail_p = itti_alloc_new_message (TASK_RRC_GNB, NGAP_INITIAL_CONTEXT_SETUP_FAIL);
NGAP_INITIAL_CONTEXT_SETUP_FAIL (msg_fail_p).gNB_ue_ngap_id = gNB_ue_ngap_id;
// TODO add failure cause when defined!
......@@ -481,3 +481,112 @@ rrc_gNB_process_security(
changed ? "changed" : "same");
return changed;
}
//------------------------------------------------------------------------------
int
rrc_gNB_process_NGAP_DOWNLINK_NAS(
MessageDef *msg_p,
const char *msg_name,
instance_t instance,
mui_t *rrc_gNB_mui
)
//------------------------------------------------------------------------------
{
uint16_t ue_initial_id;
uint32_t gNB_ue_ngap_id;
uint32_t length;
uint8_t *buffer;
struct rrc_gNB_ue_context_s *ue_context_p = NULL;
protocol_ctxt_t ctxt;
memset(&ctxt, 0, sizeof(protocol_ctxt_t));
ue_initial_id = NGAP_DOWNLINK_NAS (msg_p).ue_initial_id;
gNB_ue_ngap_id = NGAP_DOWNLINK_NAS (msg_p).gNB_ue_ngap_id;
ue_context_p = rrc_gNB_get_ue_context_from_ngap_ids(instance, ue_initial_id, gNB_ue_ngap_id);
LOG_I(NR_RRC, "[gNB %d] Received %s: ue_initial_id %d, gNB_ue_ngap_id %d\n",
instance,
msg_name,
ue_initial_id,
gNB_ue_ngap_id);
if (ue_context_p == NULL) {
MSC_LOG_RX_MESSAGE(
MSC_RRC_GNB,
MSC_NGAP_GNB,
NULL,
0,
MSC_AS_TIME_FMT" DOWNLINK-NAS UE initial id %u gNB_ue_ngap_id %u",
0,0,//MSC_AS_TIME_ARGS(ctxt_pP),
ue_initial_id,
gNB_ue_ngap_id);
/* Can not associate this message to an UE index, send a failure to NGAP and discard it! */
MessageDef *msg_fail_p;
LOG_W(NR_RRC, "[gNB %d] In NGAP_DOWNLINK_NAS: unknown UE from NGAP ids (%d, %d)\n", instance, ue_initial_id, gNB_ue_ngap_id);
msg_fail_p = itti_alloc_new_message (TASK_RRC_GNB, NGAP_NAS_NON_DELIVERY_IND);
NGAP_NAS_NON_DELIVERY_IND (msg_fail_p).gNB_ue_ngap_id = gNB_ue_ngap_id;
NGAP_NAS_NON_DELIVERY_IND (msg_fail_p).nas_pdu.length = NGAP_DOWNLINK_NAS (msg_p).nas_pdu.length;
NGAP_NAS_NON_DELIVERY_IND (msg_fail_p).nas_pdu.buffer = NGAP_DOWNLINK_NAS (msg_p).nas_pdu.buffer;
// TODO add failure cause when defined!
MSC_LOG_TX_MESSAGE(
MSC_RRC_ENB,
MSC_NGAP_GNB,
(const char *)NULL,
0,
MSC_AS_TIME_FMT" NGAP_NAS_NON_DELIVERY_IND UE initial id %u gNB_ue_ngap_id %u (ue ctxt !found)",
0,0,//MSC_AS_TIME_ARGS(ctxt_pP),
ue_initial_id,
gNB_ue_ngap_id);
itti_send_msg_to_task (TASK_NGAP, instance, msg_fail_p);
return (-1);
} else {
PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, instance, GNB_FLAG_YES, ue_context_p->ue_context.rnti, 0, 0);
/* Is it the first income from NGAP ? */
if (ue_context_p->ue_context.gNB_ue_ngap_id == 0) {
ue_context_p->ue_context.gNB_ue_ngap_id = NGAP_DOWNLINK_NAS (msg_p).gNB_ue_ngap_id;
}
MSC_LOG_RX_MESSAGE(
MSC_RRC_GNB,
MSC_NGAP_GNB,
(const char *)NULL,
0,
MSC_AS_TIME_FMT" DOWNLINK-NAS UE initial id %u gNB_ue_ngap_id %u",
0,0,//MSC_AS_TIME_ARGS(ctxt_pP),
ue_initial_id,
NGAP_DOWNLINK_NAS (msg_p).gNB_ue_ngap_id);
/* Create message for PDCP (DLInformationTransfer_t) */
length = do_NR_DLInformationTransfer (
instance,
&buffer,
rrc_gNB_get_next_transaction_identifier (instance),
NGAP_DOWNLINK_NAS (msg_p).nas_pdu.length,
NGAP_DOWNLINK_NAS (msg_p).nas_pdu.buffer);
LOG_DUMPMSG(NR_RRC, DEBUG_RRC, buffer, length, "[MSG] RRC DL Information Transfer\n");
/*
* switch UL or DL NAS message without RRC piggybacked to SRB2 if active.
*/
#ifdef ITTI_SIM
MessageDef *message_p;
uint8_t *message_buffer;
message_buffer = itti_malloc (TASK_RRC_GNB_SIM, TASK_RRC_UE_SIM, length);
memcpy (message_buffer, buffer, length);
message_p = itti_alloc_new_message (TASK_RRC_GNB_SIM, GNB_RRC_DCCH_DATA_IND);
GNB_RRC_DCCH_DATA_IND (message_p).rbid = DCCH;
GNB_RRC_DCCH_DATA_IND (message_p).sdu = message_buffer;
GNB_RRC_DCCH_DATA_IND (message_p).size = length;
itti_send_msg_to_task (TASK_RRC_UE_SIM, instance, message_p);
LOG_I(NR_RRC, "Send DL NAS message \n");
#else
/* Transfer data to PDCP */
nr_rrc_data_req (
&ctxt,
ue_context_p->ue_context.Srb2.Srb_info.Srb_id,
(*rrc_gNB_mui)++,
SDU_CONFIRM_NO,
length,
buffer,
PDCP_TRANSMISSION_MODE_CONTROL);
#endif
return (0);
}
}
......@@ -77,4 +77,12 @@ rrc_gNB_process_security(
ngap_security_capabilities_t *security_capabilities_pP
);
int
rrc_gNB_process_NGAP_DOWNLINK_NAS(
MessageDef *msg_p,
const char *msg_name,
instance_t instance,
mui_t *rrc_gNB_mui
);
#endif
......@@ -999,7 +999,7 @@ int nr_decode_SI( const protocol_ctxt_t *const ctxt_pP, const uint8_t gNB_index
if (NR_UE_rrc_inst[ctxt_pP->module_id].Info[gNB_index].SIcnt == sib1->si_SchedulingInfo->schedulingInfoList.list.count)
nr_rrc_set_sub_state( ctxt_pP->module_id, RRC_SUB_STATE_IDLE_SIB_COMPLETE );
LOG_I(RRC,"SIStatus %x, SIcnt %d/%d\n",
LOG_I(NR_RRC,"SIStatus %x, SIcnt %d/%d\n",
NR_UE_rrc_inst[ctxt_pP->module_id].Info[gNB_index].SIStatus,
NR_UE_rrc_inst[ctxt_pP->module_id].Info[gNB_index].SIcnt,
sib1->si_SchedulingInfo->schedulingInfoList.list.count);
......@@ -1941,7 +1941,7 @@ nr_rrc_ue_process_measConfig(
(char *)measConfig->reportConfigToAddModList->list.array[i],
sizeof(NR_ReportConfigToAddMod_t));
} else {
LOG_D(RRC,"Adding Report Configuration %ld %p \n", ind-1, measConfig->reportConfigToAddModList->list.array[i]);
LOG_D(NR_RRC,"Adding Report Configuration %ld %p \n", ind-1, measConfig->reportConfigToAddModList->list.array[i]);
if (reportConfig->reportConfig.present == NR_ReportConfigToAddMod__reportConfig_PR_reportConfigNR) {
NR_UE_rrc_inst[ctxt_pP->module_id].ReportConfig[gNB_index][ind-1] = measConfig->reportConfigToAddModList->list.array[i];
}
......@@ -1974,7 +1974,7 @@ nr_rrc_ue_process_measConfig(
if (measConfig->quantityConfig != NULL) {
if (NR_UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[gNB_index]) {
LOG_D(RRC,"Modifying Quantity Configuration \n");
LOG_D(NR_RRC,"Modifying Quantity Configuration \n");
memcpy((char *)NR_UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[gNB_index],
(char *)measConfig->quantityConfig,
sizeof(NR_QuantityConfig_t));
......@@ -2324,7 +2324,7 @@ nr_rrc_ue_decode_dcch(
itti_send_msg_to_task(TASK_NAS_UE, ctxt_pP->instance, msg_p);
break;
case NR_DL_DCCH_MessageType__c1_PR_ueCapabilityEnquiry:
LOG_I(RRC, "[UE %d] Received Capability Enquiry (gNB %d)\n",
LOG_I(NR_RRC, "[UE %d] Received Capability Enquiry (gNB %d)\n",
ctxt_pP->module_id,gNB_indexP);
nr_rrc_ue_process_ueCapabilityEnquiry(
ctxt_pP,
......@@ -2332,7 +2332,36 @@ nr_rrc_ue_decode_dcch(
gNB_indexP);
break;
case NR_DL_DCCH_MessageType__c1_PR_rrcReestablishment:
break;
case NR_DL_DCCH_MessageType__c1_PR_dlInformationTransfer:
{
NR_DLInformationTransfer_t *dlInformationTransfer = dl_dcch_msg->message.choice.c1->choice.dlInformationTransfer;
if (dlInformationTransfer->criticalExtensions.present
== NR_DLInformationTransfer__criticalExtensions_PR_dlInformationTransfer) {
/* This message hold a dedicated info NAS payload, forward it to NAS */
NR_DedicatedNAS_Message_t *dedicatedNAS_Message =
dlInformationTransfer->criticalExtensions.choice.dlInformationTransfer->dedicatedNAS_Message;
uint32_t pdu_length;
uint8_t *pdu_buffer;
pdu_length = dedicatedNAS_Message->size;
pdu_buffer = dedicatedNAS_Message->buf;
#ifdef ITTI_SIM
LOG_I(NR_RRC, "[UE %d] Received %s: UEid %u, length %u , buffer %p\n", ctxt_pP->module_id, messages_info[NAS_DOWNLINK_DATA_IND].name,
ctxt_pP->module_id, pdu_length, pdu_buffer);
//nas_proc_dl_transfer_ind (user, pdu_buffer, pdu_length);
#else
MessageDef *msg_p;
msg_p = itti_alloc_new_message(TASK_RRC_UE, NAS_DOWNLINK_DATA_IND);
NAS_DOWNLINK_DATA_IND(msg_p).UEid = ctxt_pP->module_id; // TODO set the UEid to something else ?
NAS_DOWNLINK_DATA_IND(msg_p).nasMsg.length = pdu_length;
NAS_DOWNLINK_DATA_IND(msg_p).nasMsg.data = pdu_buffer;
itti_send_msg_to_task(TASK_NAS_UE, ctxt_pP->instance, msg_p);
#endif
}
}
break;
case NR_DL_DCCH_MessageType__c1_PR_mobilityFromNRCommand:
case NR_DL_DCCH_MessageType__c1_PR_dlDedicatedMessageSegment_r16:
case NR_DL_DCCH_MessageType__c1_PR_ueInformationRequest_r16:
......@@ -2344,12 +2373,12 @@ nr_rrc_ue_decode_dcch(
case NR_DL_DCCH_MessageType__c1_PR_counterCheck:
break;
case NR_DL_DCCH_MessageType__c1_PR_securityModeCommand:
LOG_I(RRC, "[UE %d] Received securityModeCommand (gNB %d)\n",
ctxt_pP->module_id, gNB_indexP);
nr_rrc_ue_process_securityModeCommand(
ctxt_pP,
dl_dcch_msg->message.choice.c1->choice.securityModeCommand,
gNB_indexP);
LOG_I(NR_RRC, "[UE %d] Received securityModeCommand (gNB %d)\n",
ctxt_pP->module_id, gNB_indexP);
nr_rrc_ue_process_securityModeCommand(
ctxt_pP,
dl_dcch_msg->message.choice.c1->choice.securityModeCommand,
gNB_indexP);
break;
}
......@@ -2434,6 +2463,50 @@ void *rrc_nrue_task( void *args_p ) {
NR_RRC_DCCH_DATA_IND (msg_p).gNB_index);
break;
case NAS_UPLINK_DATA_REQ: {
uint32_t length;
uint8_t *buffer;
LOG_D(NR_RRC, "[UE %d] Received %s: UEid %d\n", ue_mod_id, ITTI_MSG_NAME (msg_p), NAS_UPLINK_DATA_REQ (msg_p).UEid);
/* Create message for PDCP (ULInformationTransfer_t) */
length = do_NR_ULInformationTransfer(&buffer, NAS_UPLINK_DATA_REQ (msg_p).nasMsg.length, NAS_UPLINK_DATA_REQ (msg_p).nasMsg.data);
/* Transfer data to PDCP */
PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_id, GNB_FLAG_NO, NR_UE_rrc_inst[ue_mod_id].Info[0].rnti, 0, 0,0);
#ifdef ITTI_SIM
MessageDef *message_p;
uint8_t *message_buffer;
message_buffer = itti_malloc (TASK_RRC_UE_SIM,TASK_RRC_GNB_SIM,length);
memcpy (message_buffer, buffer, length);
message_p = itti_alloc_new_message (TASK_RRC_UE_SIM, UE_RRC_DCCH_DATA_IND);
if(NR_UE_rrc_inst[ue_mod_id].SRB2_config[0] == NULL)
UE_RRC_DCCH_DATA_IND (message_p).rbid = DCCH;
else
UE_RRC_DCCH_DATA_IND (message_p).rbid = DCCH1;
UE_RRC_DCCH_DATA_IND (message_p).sdu = message_buffer;
UE_RRC_DCCH_DATA_IND (message_p).size = length;
itti_send_msg_to_task (TASK_RRC_GNB_SIM, ctxt.instance, message_p);
#else
// check if SRB2 is created, if yes request data_req on DCCH1 (SRB2)
if(NR_UE_rrc_inst[ue_mod_id].SRB2_config[0] == NULL) {
rrc_data_req_ue (&ctxt,
DCCH,
nr_rrc_mui++,
SDU_CONFIRM_NO,
length, buffer,
PDCP_TRANSMISSION_MODE_CONTROL);
} else {
rrc_data_req_ue (&ctxt,
DCCH1,
nr_rrc_mui++,
SDU_CONFIRM_NO,
length, buffer,
PDCP_TRANSMISSION_MODE_CONTROL);
}
#endif
break;
}
default:
LOG_E(NR_RRC, "[UE %d] Received unexpected message %s\n", ue_mod_id, ITTI_MSG_NAME (msg_p));
break;
......@@ -2480,7 +2553,7 @@ nr_rrc_ue_process_ueCapabilityEnquiry(
NR_UE_CapabilityRAT_Container_t ue_CapabilityRAT_Container;
uint8_t buffer[200];
int i;
LOG_I(RRC,"[UE %d] Frame %d: Receiving from SRB1 (DL-DCCH), Processing UECapabilityEnquiry (gNB %d)\n",
LOG_I(NR_RRC,"[UE %d] Frame %d: Receiving from SRB1 (DL-DCCH), Processing UECapabilityEnquiry (gNB %d)\n",
ctxt_pP->module_id,
ctxt_pP->frame,
gNB_index);
......
......@@ -340,11 +340,11 @@ int ngap_gNB_handle_nas_downlink(uint32_t assoc_id,
DevAssert(pdu != NULL);
/* UE-related procedure -> stream != 0 */
if (stream == 0) {
NGAP_ERROR("[SCTP %d] Received UE-related procedure on stream == 0\n",
assoc_id);
return -1;
}
// if (stream == 0) {
// NGAP_ERROR("[SCTP %d] Received UE-related procedure on stream == 0\n",
// assoc_id);
// return -1;
// }
if ((amf_desc_p = ngap_gNB_get_AMF(NULL, assoc_id, 0)) == NULL) {
NGAP_ERROR(
......
......@@ -82,8 +82,8 @@ struct ngap_gNB_ue_context_s *ngap_gNB_get_ue_context(
memset(&temp, 0, sizeof(struct ngap_gNB_ue_context_s));
/* gNB ue ngap id = 24 bits wide */
temp.gNB_ue_ngap_id = gNB_ue_ngap_id & 0x00FFFFFF;
/* gNB ue ngap id = 32 bits wide */
temp.gNB_ue_ngap_id = gNB_ue_ngap_id & 0xFFFFFFFF;
return RB_FIND(ngap_ue_map, &instance_p->ngap_ue_head, &temp);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment