f1ap_du_rrc_message_transfer.c 34.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */

/*! \file f1ap_du_rrc_message_transfer.c
 * \brief f1ap rrc message transfer for DU
 * \author EURECOM/NTUST
 * \date 2018
 * \version 0.1
 * \company Eurecom
 * \email: navid.nikaein@eurecom.fr, bing-kai.hong@eurecom.fr
 * \note
 * \warning
 */

#include "f1ap_common.h"
34 35
#include "f1ap_encoder.h"
#include "f1ap_decoder.h"
36
#include "f1ap_itti_messaging.h"
37

38
#include "f1ap_du_rrc_message_transfer.h"
39

40

41 42 43
#include "LTE_DL-CCCH-Message.h"
#include "LTE_DL-DCCH-Message.h"
#include "LTE_UL-DCCH-Message.h"
44

45 46 47 48
// for SRB1_logicalChannelConfig_defaultValue
#include "rrc_extern.h"
#include "common/ran_context.h"

49
#include "rrc_eNB_UE_context.h"
50

51 52 53 54
// undefine C_RNTI from
// openair1/PHY/LTE_TRANSPORT/transport_common.h which
// replaces in ie->value.choice.C_RNTI, causing
// a compile error
55

56 57 58
#undef C_RNTI 

extern f1ap_setup_req_t *f1ap_du_data;
59
extern RAN_CONTEXT_t RC;
60
extern f1ap_cudu_inst_t f1ap_du_inst[MAX_eNB];
61 62 63



64
/*  DL RRC Message Transfer */
65 66 67 68
int DU_handle_DL_RRC_MESSAGE_TRANSFER(instance_t       instance,
                                      uint32_t         assoc_id,
                                      uint32_t         stream,
                                      F1AP_F1AP_PDU_t *pdu) {
69
  LOG_D(F1AP, "DU_handle_DL_RRC_MESSAGE_TRANSFER \n");
70 71 72 73 74 75 76 77
  
  F1AP_DLRRCMessageTransfer_t    *container;
  F1AP_DLRRCMessageTransferIEs_t *ie;

  uint64_t        cu_ue_f1ap_id;
  uint64_t        du_ue_f1ap_id;
  uint64_t        srb_id;
  int             executeDuplication;
78
  sdu_size_t      rrc_dl_sdu_len;
79 80
  //uint64_t        subscriberProfileIDforRFP;
  //uint64_t        rAT_FrequencySelectionPriority;
81 82

  DevAssert(pdu != NULL);
83

84 85 86 87 88 89 90 91 92 93 94 95 96
  if (stream != 0) {
    LOG_E(F1AP, "[SCTP %d] Received F1 on stream != 0 (%d)\n",
               assoc_id, stream);
    return -1;
  }

  container = &pdu->choice.initiatingMessage->value.choice.DLRRCMessageTransfer;


  /* GNB_CU_UE_F1AP_ID */
  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_DLRRCMessageTransferIEs_t, ie, container,
                             F1AP_ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID, true);
  cu_ue_f1ap_id = ie->value.choice.GNB_CU_UE_F1AP_ID;
97
  LOG_D(F1AP, "cu_ue_f1ap_id %lu \n", cu_ue_f1ap_id);
98 99 100 101 102 103


  /* GNB_DU_UE_F1AP_ID */
  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_DLRRCMessageTransferIEs_t, ie, container,
                             F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID, true);
  du_ue_f1ap_id = ie->value.choice.GNB_DU_UE_F1AP_ID;
104 105 106
  LOG_D(F1AP, "du_ue_f1ap_id %lu associated with UE RNTI %x \n",
        du_ue_f1ap_id,
        f1ap_get_rnti_by_du_id(&f1ap_du_inst[instance], du_ue_f1ap_id)); // this should be the one transmitted via initial ul rrc message transfer
107

108
  if (f1ap_du_add_cu_ue_id(&f1ap_du_inst[instance],du_ue_f1ap_id, cu_ue_f1ap_id) < 0 ) {
109
    LOG_E(F1AP, "Failed to find the F1AP UID \n");
110 111
    //return -1;
  }
112

113 114 115 116 117 118 119 120 121 122 123 124
  /* optional */
  /* oldgNB_DU_UE_F1AP_ID */
  if (0) {
    F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_DLRRCMessageTransferIEs_t, ie, container,
                             F1AP_ProtocolIE_ID_id_oldgNB_DU_UE_F1AP_ID, true);
  }

  /* mandatory */
  /* SRBID */
  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_DLRRCMessageTransferIEs_t, ie, container,
                             F1AP_ProtocolIE_ID_id_SRBID, true);
  srb_id = ie->value.choice.SRBID;
125
  LOG_D(F1AP, "srb_id %lu \n", srb_id);
126 127 128 129 130 131 132

  /* optional */
  /* ExecuteDuplication */
  if (0) {
    F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_DLRRCMessageTransferIEs_t, ie, container,
                             F1AP_ProtocolIE_ID_id_ExecuteDuplication, true);
    executeDuplication = ie->value.choice.ExecuteDuplication;
133
    LOG_D(F1AP, "ExecuteDuplication %d \n", executeDuplication);
134 135 136 137 138 139 140 141 142
  }

  // issue in here
  /* mandatory */
  /* RRC Container */
  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_DLRRCMessageTransferIEs_t, ie, container,
                             F1AP_ProtocolIE_ID_id_RRCContainer, true);
  // BK: need check
  // create an ITTI message and copy SDU
143

144 145 146 147 148
  //  message_p = itti_alloc_new_message (TASK_CU_F1, RRC_MAC_CCCH_DATA_IND);
  //  memset (RRC_MAC_CCCH_DATA_IND (message_p).sdu, 0, CCCH_SDU_SIZE);
  rrc_dl_sdu_len = ie->value.choice.RRCContainer.size;
  //  memcpy(RRC_MAC_CCCH_DATA_IND (message_p).sdu, ie->value.choice.RRCContainer.buf,
  //         ccch_sdu_len);
149 150 151 152 153

  //LOG_I(F1AP, "%s() RRCContainer size %lu: ", __func__, ie->value.choice.RRCContainer.size);
  //for (int i = 0;i < ie->value.choice.RRCContainer.size; i++)
  //  printf("%02x ", ie->value.choice.RRCContainer.buf[i]);
  //printf("\n");
154 155 156 157 158 159 160 161 162

  /* optional */
  /* RAT_FrequencyPriorityInformation */
  if (0) {
    F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_DLRRCMessageTransferIEs_t, ie, container,
                             F1AP_ProtocolIE_ID_id_RAT_FrequencyPriorityInformation, true);

    switch(ie->value.choice.RAT_FrequencyPriorityInformation.present) {
      case F1AP_RAT_FrequencyPriorityInformation_PR_subscriberProfileIDforRFP:
163
        //subscriberProfileIDforRFP = ie->value.choice.RAT_FrequencyPriorityInformation.choice.subscriberProfileIDforRFP;
164 165
        break;
      case F1AP_RAT_FrequencyPriorityInformation_PR_rAT_FrequencySelectionPriority:
166
        //rAT_FrequencySelectionPriority = ie->value.choice.RAT_FrequencyPriorityInformation.choice.rAT_FrequencySelectionPriority;
167
        break;
168
      default:
169
        LOG_W(F1AP, "unhandled IE RAT_FrequencyPriorityInformation.present\n");
170
        break;
171 172 173
    }
  }

174 175 176
  // decode RRC Container and act on the message type
  AssertFatal(srb_id<3,"illegal srb_id\n");

177
  protocol_ctxt_t ctxt;
178
  ctxt.rnti      = f1ap_get_rnti_by_du_id(&f1ap_du_inst[instance], du_ue_f1ap_id);
179 180 181 182
  ctxt.module_id = instance;
  ctxt.instance  = instance;
  ctxt.enb_flag  = 1;

183 184 185 186
 struct rrc_eNB_ue_context_s* ue_context_p = rrc_eNB_get_ue_context(
                                                RC.rrc[ctxt.module_id],
                                                ctxt.rnti);

187
  if (srb_id == 0) {
188
    LTE_DL_CCCH_Message_t* dl_ccch_msg=NULL;
189 190
    asn_dec_rval_t dec_rval;
    dec_rval = uper_decode(NULL,
191
         &asn_DEF_LTE_DL_CCCH_Message,
192 193 194
         (void**)&dl_ccch_msg,
         ie->value.choice.RRCContainer.buf,
         rrc_dl_sdu_len,0,0);
195
    AssertFatal(dec_rval.code == RC_OK, "could not decode F1AP message\n");
196
    switch (dl_ccch_msg->message.choice.c1.present) {
197

198
      case LTE_DL_CCCH_MessageType__c1_PR_NOTHING:
199
        LOG_I(F1AP, "Received PR_NOTHING on DL-CCCH-Message\n");
200 201
        break;

202
      case LTE_DL_CCCH_MessageType__c1_PR_rrcConnectionReestablishment:
203 204
        LOG_I(F1AP,
              "Logical Channel DL-CCCH (SRB0), Received RRCConnectionReestablishment\n");
205 206
        break;

207
      case LTE_DL_CCCH_MessageType__c1_PR_rrcConnectionReestablishmentReject:
208 209
        LOG_I(F1AP,
              "Logical Channel DL-CCCH (SRB0), Received RRCConnectionReestablishmentReject\n");
210 211
        break;

212
      case LTE_DL_CCCH_MessageType__c1_PR_rrcConnectionReject:
213 214
        LOG_I(F1AP,
              "Logical Channel DL-CCCH (SRB0), Received RRCConnectionReject \n");
215 216
        break;

217
      case LTE_DL_CCCH_MessageType__c1_PR_rrcConnectionSetup:
218
      {
219 220 221 222
        LOG_I(F1AP,
              "Logical Channel DL-CCCH (SRB0), Received RRCConnectionSetup DU_ID %lx/RNTI %x\n",
              du_ue_f1ap_id,
              f1ap_get_rnti_by_du_id(&f1ap_du_inst[instance], du_ue_f1ap_id));
223 224
          // Get configuration

225
        LTE_RRCConnectionSetup_t* rrcConnectionSetup = &dl_ccch_msg->message.choice.c1.choice.rrcConnectionSetup;
226
        AssertFatal(rrcConnectionSetup!=NULL,"rrcConnectionSetup is null\n");
227
        LTE_RadioResourceConfigDedicated_t* radioResourceConfigDedicated = &rrcConnectionSetup->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r8.radioResourceConfigDedicated;
228 229

        // get SRB logical channel information
230 231
        LTE_SRB_ToAddModList_t *SRB_configList;
        LTE_SRB_ToAddMod_t *SRB1_config;
Robert Schmidt's avatar
Robert Schmidt committed
232
        LTE_LogicalChannelConfig_t *SRB1_logicalChannelConfig = NULL;
233 234 235 236 237 238 239 240 241
        SRB_configList                 = radioResourceConfigDedicated->srb_ToAddModList;

        AssertFatal(SRB_configList!=NULL,"SRB_configList is null\n");
        for (int cnt = 0; cnt < (SRB_configList)->list.count; cnt++) {
          if ((SRB_configList)->list.array[cnt]->srb_Identity == 1) {
            SRB1_config = (SRB_configList)->list.array[cnt];

            if (SRB1_config->logicalChannelConfig) {
              if (SRB1_config->logicalChannelConfig->present ==
242
                LTE_SRB_ToAddMod__logicalChannelConfig_PR_explicitValue) {
243 244 245 246 247 248 249 250 251 252 253
                SRB1_logicalChannelConfig = &SRB1_config->logicalChannelConfig->choice.explicitValue;
              } else {
                SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
              }
            } else {
              SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
            }
          }
        } // for
        rrc_rlc_config_asn1_req(&ctxt,
          SRB_configList,
254 255 256 257
          (LTE_DRB_ToAddModList_t*) NULL,
          (LTE_DRB_ToReleaseList_t*) NULL
#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
          , (LTE_PMCH_InfoList_r9_t *) NULL,
258
          0,0
259
#   endif
260 261 262
          );

      // This should be somewhere in the f1ap_cudu_ue_inst_t
263
      /*int macrlc_instance = 0; 
264

265
      rnti_t rnti = f1ap_get_rnti_by_du_id(&f1ap_du_inst[0], du_ue_f1ap_id);
266
      struct rrc_eNB_ue_context_s *ue_context_p = rrc_eNB_get_ue_context(RC.rrc[macrlc_instance],rnti);
267
      */  
268 269 270 271 272
      eNB_RRC_UE_t *ue_p = &ue_context_p->ue_context; 
      AssertFatal(ue_p->Srb0.Active == 1,"SRB0 is not active\n");

      memcpy((void*)ue_p->Srb0.Tx_buffer.Payload,
             (void*)ie->value.choice.RRCContainer.buf,
273
             rrc_dl_sdu_len); // ie->value.choice.RRCContainer.size
274 275 276

      ue_p->Srb0.Tx_buffer.payload_size = rrc_dl_sdu_len;

Robert Schmidt's avatar
Robert Schmidt committed
277 278 279 280
      LTE_MAC_MainConfig_t    *mac_MainConfig  = NULL;
      if (radioResourceConfigDedicated->mac_MainConfig)
        mac_MainConfig = &radioResourceConfigDedicated->mac_MainConfig->choice.explicitValue;

281
      rrc_mac_config_req_eNB(
282
          ctxt.module_id,
283 284
          0, //primaryCC_id,
          0,0,0,0,0,
285
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
286
          0,
287
#endif
288
          ctxt.rnti,
289 290 291 292
          (LTE_BCCH_BCH_Message_t *) NULL,
          (LTE_RadioResourceConfigCommonSIB_t *) NULL,
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
          (LTE_RadioResourceConfigCommonSIB_t *) NULL,
293
#endif
294
          radioResourceConfigDedicated->physicalConfigDedicated,
295 296
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
          (LTE_SCellToAddMod_r10_t *)NULL,
297
          //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
298
#endif
299
          (LTE_MeasObjectToAddMod_t **) NULL,
Robert Schmidt's avatar
Robert Schmidt committed
300
          mac_MainConfig,
301 302 303
          1,
          SRB1_logicalChannelConfig,
          NULL, // measGapConfig,
304
          (LTE_TDD_Config_t *) NULL,
305
          NULL,
306 307 308 309
          (LTE_SchedulingInfoList_t *) NULL,
          0, NULL, NULL, (LTE_MBSFN_SubframeConfigList_t *) NULL
#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
          , 0, (LTE_MBSFN_AreaInfoList_r9_t *) NULL, (LTE_PMCH_InfoList_r9_t *) NULL
310
#endif
311
#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
312
          ,
313
          (LTE_SystemInformationBlockType1_v1310_IEs_t *)NULL
314
#endif
315 316 317
          );
          break;
      } // case
318

319 320 321 322 323
      default:
        AssertFatal(1==0,
        "Unknown message\n");
        break;
    }// switch case
324
    return(0);
325 326
  } else if (srb_id == 1) { 

327
    LTE_DL_DCCH_Message_t* dl_dcch_msg=NULL;
328 329
    asn_dec_rval_t dec_rval;
    dec_rval = uper_decode(NULL,
330
         &asn_DEF_LTE_DL_DCCH_Message,
331
         (void**)&dl_dcch_msg,
332
         &ie->value.choice.RRCContainer.buf[1], // buf[0] includes the pdcp header
333
         rrc_dl_sdu_len,0,0);
334 335
    
    if ((dec_rval.code != RC_OK) && (dec_rval.consumed == 0)) 
336
      LOG_E(F1AP," Failed to decode DL-DCCH (%zu bytes)\n",dec_rval.consumed);
337
    else
338 339
      LOG_D(F1AP, "Received message: present %d and c1 present %d\n",
            dl_dcch_msg->message.present, dl_dcch_msg->message.choice.c1.present);
340

341
    if (dl_dcch_msg->message.present == LTE_DL_DCCH_MessageType_PR_c1) {
342 343 344
     
      switch (dl_dcch_msg->message.choice.c1.present) {
	
345
      case LTE_DL_DCCH_MessageType__c1_PR_NOTHING:
346
        LOG_I(F1AP, "Received PR_NOTHING on DL-DCCH-Message\n");
347
        return 0;
348
      case LTE_DL_DCCH_MessageType__c1_PR_dlInformationTransfer:
349
        LOG_I(F1AP,"Received NAS DL Information Transfer\n");
350
        break;	
351
      case LTE_DL_DCCH_MessageType__c1_PR_csfbParametersResponseCDMA2000:
352
        LOG_I(F1AP,"Received NAS sfbParametersResponseCDMA2000\n");
353
        break;  
354
      case LTE_DL_DCCH_MessageType__c1_PR_handoverFromEUTRAPreparationRequest:
355
        LOG_I(F1AP,"Received NAS andoverFromEUTRAPreparationRequest\n");
356
        break;  
357
      case LTE_DL_DCCH_MessageType__c1_PR_mobilityFromEUTRACommand:
358
        LOG_I(F1AP,"Received NAS mobilityFromEUTRACommand\n");
359
        break;
360
      case LTE_DL_DCCH_MessageType__c1_PR_rrcConnectionReconfiguration:
361
	     // handle RRCConnectionReconfiguration
362 363 364 365
        LOG_I(F1AP,
              "Logical Channel DL-DCCH (SRB1), Received RRCConnectionReconfiguration DU_ID %lx/RNTI %x\n",
              du_ue_f1ap_id,
              f1ap_get_rnti_by_du_id(&f1ap_du_inst[instance], du_ue_f1ap_id));
366
	
367
        LTE_RRCConnectionReconfiguration_t* rrcConnectionReconfiguration = &dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration;
368

369
        if (rrcConnectionReconfiguration->criticalExtensions.present == LTE_RRCConnectionReconfiguration__criticalExtensions_PR_c1) {
370
	        if (rrcConnectionReconfiguration->criticalExtensions.choice.c1.present ==
371 372
	         LTE_RRCConnectionReconfiguration__criticalExtensions__c1_PR_rrcConnectionReconfiguration_r8) {
	          LTE_RRCConnectionReconfiguration_r8_IEs_t* rrcConnectionReconfiguration_r8 =
373
	          &rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8;
374
	    
375
            if (rrcConnectionReconfiguration_r8->mobilityControlInfo) {
376
	            LOG_I(F1AP, "Mobility Control Information is present\n");
377 378 379
	            AssertFatal(1==0,"Can't handle this yet in DU\n");
	          }
	          if (rrcConnectionReconfiguration_r8->measConfig != NULL) {
380
	            LOG_I(F1AP, "Measurement Configuration is present\n");
381
	          } 
382
	    
383
      	    if (rrcConnectionReconfiguration_r8->radioResourceConfigDedicated) {
384
              LOG_I(F1AP, "Radio Resource Configuration is present\n");
385
      	      uint8_t DRB2LCHAN[8];
386 387
              long drb_id;
              int i;
388 389 390
              LTE_DRB_ToAddModList_t  *DRB_configList  = rrcConnectionReconfiguration_r8->radioResourceConfigDedicated->drb_ToAddModList;
              LTE_SRB_ToAddModList_t  *SRB_configList  = rrcConnectionReconfiguration_r8->radioResourceConfigDedicated->srb_ToAddModList;
              LTE_DRB_ToReleaseList_t *DRB_ReleaseList = rrcConnectionReconfiguration_r8->radioResourceConfigDedicated->drb_ToReleaseList;
Robert Schmidt's avatar
Robert Schmidt committed
391 392 393
              LTE_MAC_MainConfig_t    *mac_MainConfig  = NULL;
              if (rrcConnectionReconfiguration_r8->radioResourceConfigDedicated->mac_MainConfig)
                mac_MainConfig = &rrcConnectionReconfiguration_r8->radioResourceConfigDedicated->mac_MainConfig->choice.explicitValue;
394
              LTE_MeasGapConfig_t     *measGapConfig   = NULL;
Robert Schmidt's avatar
Robert Schmidt committed
395
              struct LTE_PhysicalConfigDedicated* physicalConfigDedicated = rrcConnectionReconfiguration_r8->radioResourceConfigDedicated->physicalConfigDedicated;
396 397 398 399 400
              rrc_rlc_config_asn1_req(
                &ctxt,
                SRB_configList, // NULL,  //LG-RK 14/05/2014 SRB_configList,
                DRB_configList,
                DRB_ReleaseList
401 402
      #if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
                , (LTE_PMCH_InfoList_r9_t *) NULL
403 404 405 406 407 408 409 410 411 412 413 414
                , 0, 0
      #endif
                );

              if (SRB_configList != NULL) {
                for (i = 0; (i < SRB_configList->list.count) && (i < 3); i++) {
                  if (SRB_configList->list.array[i]->srb_Identity == 1 ){
                    ue_context_p->ue_context.Srb1.Active=1;
                  }
                  else if (SRB_configList->list.array[i]->srb_Identity == 2 )  {
                    ue_context_p->ue_context.Srb2.Active=1;
                    ue_context_p->ue_context.Srb2.Srb_info.Srb_id=2;
415
                    LOG_I(F1AP, "[DU %d] SRB2 is now active\n",ctxt.module_id);
416
                  } else {
417
                    LOG_W(F1AP, "[DU %d] invalide SRB identity %ld\n",ctxt.module_id,
418 419 420 421 422 423 424 425 426
                   SRB_configList->list.array[i]->srb_Identity);
                  }
                }
              }

              if (DRB_configList != NULL) {
                for (i = 0; i < DRB_configList->list.count; i++) {  // num max DRB (11-3-8)
                  if (DRB_configList->list.array[i]) {
                    drb_id = (int)DRB_configList->list.array[i]->drb_Identity;
427 428 429 430 431 432
                    LOG_I(F1AP,
                          "[DU %d] Logical Channel UL-DCCH, Received RRCConnectionReconfiguration for UE rnti %x, reconfiguring DRB %d/LCID %d\n",
                          ctxt.module_id,
                          ctxt.rnti,
                          (int)DRB_configList->list.array[i]->drb_Identity,
                          (int)*DRB_configList->list.array[i]->logicalChannelIdentity);
433 434 435 436 437 438 439 440 441 442 443

                  if (ue_context_p->ue_context.DRB_active[drb_id] == 0) {
                    ue_context_p->ue_context.DRB_active[drb_id] = 1;

                    if (DRB_configList->list.array[i]->logicalChannelIdentity) {
                      DRB2LCHAN[i] = (uint8_t) * DRB_configList->list.array[i]->logicalChannelIdentity;
                    }

                    rrc_mac_config_req_eNB(
                      ctxt.module_id,
                      0,0,0,0,0,0,
444
        #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
445 446 447
                   0,
        #endif
                   ue_context_p->ue_context.rnti,
448 449 450 451
                   (LTE_BCCH_BCH_Message_t *) NULL,
                   (LTE_RadioResourceConfigCommonSIB_t *) NULL,
        #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                   (LTE_RadioResourceConfigCommonSIB_t *) NULL,
452 453
        #endif
                   physicalConfigDedicated,
454 455
        #if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
                   (LTE_SCellToAddMod_r10_t *)NULL,
456 457
                   //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
        #endif
458
                   (LTE_MeasObjectToAddMod_t **) NULL,
459 460 461 462
                   mac_MainConfig,
                   DRB2LCHAN[i],
                   DRB_configList->list.array[i]->logicalChannelConfig,
                   measGapConfig,
463
                   (LTE_TDD_Config_t *) NULL,
464
                   NULL,
465 466 467 468
                   (LTE_SchedulingInfoList_t *) NULL,
                   0, NULL, NULL, (LTE_MBSFN_SubframeConfigList_t *) NULL
        #if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
                   , 0, (LTE_MBSFN_AreaInfoList_r9_t *) NULL, (LTE_PMCH_InfoList_r9_t *) NULL
469
        #endif
470
        #if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
471
                   ,
472
                   (LTE_SystemInformationBlockType1_v1310_IEs_t *)NULL
473 474 475 476 477 478 479 480 481 482 483 484
        #endif
                   );
                  }

                } else {        // remove LCHAN from MAC/PHY
                  AssertFatal(1==0,"Can't handle this yet in DU\n");  
                } 
        	     }
        	   }
           }
         }
       }
485
	    break;
486
      case LTE_DL_DCCH_MessageType__c1_PR_rrcConnectionRelease:
487
  	    // handle RRCConnectionRelease
488
        LOG_I(F1AP, "Received RRCConnectionRelease\n");
489
  	    break;
490
      case LTE_DL_DCCH_MessageType__c1_PR_securityModeCommand:
491
        LOG_I(F1AP, "Received securityModeCommand\n");
492
          break; 
493
      case LTE_DL_DCCH_MessageType__c1_PR_ueCapabilityEnquiry:
494
        LOG_I(F1AP, "Received ueCapabilityEnquiry\n");
495
          break;
496 497 498 499
      case LTE_DL_DCCH_MessageType__c1_PR_counterCheck:
  #if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
      case LTE_DL_DCCH_MessageType__c1_PR_loggedMeasurementConfiguration_r10:
      case LTE_DL_DCCH_MessageType__c1_PR_rnReconfiguration_r10:
500
  #endif
501 502 503 504 505
      case LTE_DL_DCCH_MessageType__c1_PR_spare1:
      case LTE_DL_DCCH_MessageType__c1_PR_spare2:
      case LTE_DL_DCCH_MessageType__c1_PR_spare3:
  #if (LTE_RRC_VERSION < MAKE_VERSION(14, 0, 0))
      case LTE_DL_DCCH_MessageType__c1_PR_spare4:
506 507
  #endif
  	    break;
508
      case LTE_DL_DCCH_MessageType__c1_PR_ueInformationRequest_r9:
509
        LOG_I(F1AP, "Received ueInformationRequest_r9\n");
510
        break;
511
      case LTE_DL_DCCH_MessageType__c1_PR_rrcConnectionResume_r13:
512
        LOG_I(F1AP, "Received rrcConnectionResume_r13\n");
513 514
	   } 
	 }	
515 516 517 518 519
  }
  else if (srb_id == 2) {
    
  }

520
  LOG_I(F1AP, "Received DL RRC Transfer on srb_id %ld\n", srb_id);
521 522 523 524
  rlc_op_status_t    rlc_status;
  boolean_t          ret             = TRUE;
  mem_block_t       *pdcp_pdu_p      = NULL; 
  pdcp_pdu_p = get_free_mem_block(rrc_dl_sdu_len, __func__);
525

526 527 528 529 530 531 532 533
  //LOG_I(F1AP, "PRRCContainer size %lu:", ie->value.choice.RRCContainer.size);
  //for (int i = 0; i < ie->value.choice.RRCContainer.size; i++)
  //  printf("%02x ", ie->value.choice.RRCContainer.buf[i]);

  //printf (", PDCP PDU size %d:", rrc_dl_sdu_len);
  //for (int i=0;i<rrc_dl_sdu_len;i++) printf("%2x ",pdcp_pdu_p->data[i]);
  //printf("\n");

534

535 536 537
  if (pdcp_pdu_p != NULL) {
    memset(pdcp_pdu_p->data, 0, rrc_dl_sdu_len);
    memcpy(&pdcp_pdu_p->data[0], ie->value.choice.RRCContainer.buf, rrc_dl_sdu_len);
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552
      rlc_status = rlc_data_req(&ctxt
                                , 1
                                , MBMS_FLAG_NO
                                , srb_id
                                , 0
                                , 0
                                , rrc_dl_sdu_len
                                , pdcp_pdu_p
#ifdef Rel14
                                ,NULL
                                ,NULL
#endif
                                );
      switch (rlc_status) {
        case RLC_OP_STATUS_OK:
553
          //LOG_I(F1AP, "Data sending request over RLC succeeded!\n");
554 555 556 557
          ret=TRUE;
          break;

        case RLC_OP_STATUS_BAD_PARAMETER:
558
          LOG_W(F1AP, "Data sending request over RLC failed with 'Bad Parameter' reason!\n");
559 560 561 562
          ret= FALSE;
          break;

        case RLC_OP_STATUS_INTERNAL_ERROR:
563
          LOG_W(F1AP, "Data sending request over RLC failed with 'Internal Error' reason!\n");
564 565 566 567
          ret= FALSE;
          break;

        case RLC_OP_STATUS_OUT_OF_RESSOURCES:
568
          LOG_W(F1AP, "Data sending request over RLC failed with 'Out of Resources' reason!\n");
569 570 571 572
          ret= FALSE;
          break;

        default:
573
          LOG_W(F1AP, "RLC returned an unknown status code after PDCP placed the order to send some data (Status Code:%d)\n", rlc_status);
574 575 576 577 578 579
          ret= FALSE;
          break;
      } // switch case
      return ret; 
    } // if pdcp_pdu_p
  
580 581
  return 0;
  
582 583
}

584 585
int DU_send_UL_RRC_MESSAGE_TRANSFER(instance_t instance, const f1ap_ul_rrc_message_t *msg) {
  const rnti_t rnti = msg->rnti;
586

587 588 589 590
  F1AP_F1AP_PDU_t                pdu;
  F1AP_ULRRCMessageTransfer_t    *out;
  F1AP_ULRRCMessageTransferIEs_t *ie;

591 592
  uint8_t *buffer = NULL;
  uint32_t len;
593

594

595
  LOG_I(F1AP, "[DU %d] %s: size %d UE RNTI %x in SRB %d\n",
596
        instance, __func__, msg->rrc_container_length, rnti, msg->srb_id);
597

598 599 600 601 602
  //LOG_I(F1AP, "%s() RRCContainer size %d: ", __func__, msg->rrc_container_length);
  //for (int i = 0;i < msg->rrc_container_length; i++)
  //  printf("%02x ", msg->rrc_container[i]);
  //printf("\n");

603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618
  /* Create */
  /* 0. Message Type */
  memset(&pdu, 0, sizeof(pdu));
  pdu.present = F1AP_F1AP_PDU_PR_initiatingMessage;
  pdu.choice.initiatingMessage = (F1AP_InitiatingMessage_t *)calloc(1, sizeof(F1AP_InitiatingMessage_t));
  pdu.choice.initiatingMessage->procedureCode = F1AP_ProcedureCode_id_ULRRCMessageTransfer;
  pdu.choice.initiatingMessage->criticality   = F1AP_Criticality_ignore;
  pdu.choice.initiatingMessage->value.present = F1AP_InitiatingMessage__value_PR_ULRRCMessageTransfer;
  out = &pdu.choice.initiatingMessage->value.choice.ULRRCMessageTransfer;
  
  /* mandatory */
  /* c1. GNB_CU_UE_F1AP_ID */
  ie = (F1AP_ULRRCMessageTransferIEs_t *)calloc(1, sizeof(F1AP_ULRRCMessageTransferIEs_t));
  ie->id                             = F1AP_ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
  ie->criticality                    = F1AP_Criticality_reject;
  ie->value.present                  = F1AP_ULRRCMessageTransferIEs__value_PR_GNB_CU_UE_F1AP_ID;
619

620
  ie->value.choice.GNB_CU_UE_F1AP_ID = f1ap_get_cu_ue_f1ap_id(&f1ap_du_inst[instance], rnti);
621

622 623 624 625 626 627 628 629
  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);

  /* mandatory */
  /* c2. GNB_DU_UE_F1AP_ID */
  ie = (F1AP_ULRRCMessageTransferIEs_t *)calloc(1, sizeof(F1AP_ULRRCMessageTransferIEs_t));
  ie->id                             = F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
  ie->criticality                    = F1AP_Criticality_reject;
  ie->value.present                  = F1AP_ULRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
630
  ie->value.choice.GNB_DU_UE_F1AP_ID = f1ap_get_du_ue_f1ap_id(&f1ap_du_inst[instance], rnti);
631 632 633 634 635 636 637 638
  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);

  /* mandatory */
  /* c3. SRBID */
  ie = (F1AP_ULRRCMessageTransferIEs_t *)calloc(1, sizeof(F1AP_ULRRCMessageTransferIEs_t));
  ie->id                            = F1AP_ProtocolIE_ID_id_SRBID;
  ie->criticality                   = F1AP_Criticality_reject;
  ie->value.present                 = F1AP_ULRRCMessageTransferIEs__value_PR_SRBID;
639
  ie->value.choice.SRBID            = msg->srb_id;
640 641 642 643 644 645 646 647 648
  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);

  // issue in here
  /* mandatory */
  /* c4. RRCContainer */
  ie = (F1AP_ULRRCMessageTransferIEs_t *)calloc(1, sizeof(F1AP_ULRRCMessageTransferIEs_t));
  ie->id                            = F1AP_ProtocolIE_ID_id_RRCContainer;
  ie->criticality                   = F1AP_Criticality_reject;
  ie->value.present                 = F1AP_ULRRCMessageTransferIEs__value_PR_RRCContainer;
649 650 651
  OCTET_STRING_fromBuf(&ie->value.choice.RRCContainer,
                       (const char *) msg->rrc_container,
                       msg->rrc_container_length);
652 653
  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);

654 655
  if (msg->srb_id == 1 || msg->srb_id == 2) {
    struct rrc_eNB_ue_context_s* ue_context_p = rrc_eNB_get_ue_context(RC.rrc[instance], rnti);
656 657

   
658
    LTE_UL_DCCH_Message_t* ul_dcch_msg=NULL;
659 660
    asn_dec_rval_t dec_rval;
    dec_rval = uper_decode(NULL,
661
         &asn_DEF_LTE_UL_DCCH_Message,
662 663
         (void**)&ul_dcch_msg,
         &ie->value.choice.RRCContainer.buf[1], // buf[0] includes the pdcp header
664
         msg->rrc_container_length, 0, 0);
665 666
    
    if ((dec_rval.code != RC_OK) && (dec_rval.consumed == 0)) 
667
      LOG_E(F1AP, " Failed to decode UL-DCCH (%zu bytes)\n",dec_rval.consumed);
668
    else
669 670
      LOG_I(F1AP, "Received message: present %d and c1 present %d\n",
            ul_dcch_msg->message.present, ul_dcch_msg->message.choice.c1.present);
671

672
    if (ul_dcch_msg->message.present == LTE_UL_DCCH_MessageType_PR_c1) {
673 674

      switch (ul_dcch_msg->message.choice.c1.present) {
675
      case LTE_UL_DCCH_MessageType__c1_PR_NOTHING:   /* No components present */
676 677
        break;

678
      case LTE_UL_DCCH_MessageType__c1_PR_csfbParametersRequestCDMA2000:
679 680
        break;

681
      case LTE_UL_DCCH_MessageType__c1_PR_measurementReport:
682 683
        break;

684
      case LTE_UL_DCCH_MessageType__c1_PR_rrcConnectionReconfigurationComplete:
685 686
        break;

687
      case LTE_UL_DCCH_MessageType__c1_PR_rrcConnectionReestablishmentComplete:
688 689
        break;

690
      case LTE_UL_DCCH_MessageType__c1_PR_rrcConnectionSetupComplete:
691
        LOG_I(F1AP, "[MSG] RRC UL rrcConnectionSetupComplete \n");
692
       if(!ue_context_p){
693
          LOG_E(F1AP, "Did not find the UE context associated with UE RNTOI %x, ue_context_p is NULL\n", rnti);
694
        }else {
695
          LOG_I(F1AP, "Processing RRCConnectionSetupComplete UE %x\n", rnti);
696 697 698 699
          ue_context_p->ue_context.Status = RRC_CONNECTED;
        }

        break;
700
      case LTE_UL_DCCH_MessageType__c1_PR_securityModeComplete:
701
        LOG_I(F1AP, "[MSG] RRC securityModeComplete \n");
702 703
        break;

704
      case LTE_UL_DCCH_MessageType__c1_PR_securityModeFailure:
705 706
        break;

707
      case LTE_UL_DCCH_MessageType__c1_PR_ueCapabilityInformation:
708
        LOG_I(F1AP, "[MSG] RRC ueCapabilityInformation \n");
709 710
        break;

711
      case LTE_UL_DCCH_MessageType__c1_PR_ulHandoverPreparationTransfer:
712 713
        break;

714
      case LTE_UL_DCCH_MessageType__c1_PR_ulInformationTransfer:
715
        LOG_I(F1AP,"[MSG] RRC UL Information Transfer \n");
716 717
        break;

718
      case LTE_UL_DCCH_MessageType__c1_PR_counterCheckResponse:
719 720
        break;

721
#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
722

723
      case LTE_UL_DCCH_MessageType__c1_PR_ueInformationResponse_r9:
724
        break;
725
      case LTE_UL_DCCH_MessageType__c1_PR_proximityIndication_r9:
726 727 728
       break;
#endif

729 730
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
      case LTE_UL_DCCH_MessageType__c1_PR_rnReconfigurationComplete_r10:
731 732
        break;

733
      case LTE_UL_DCCH_MessageType__c1_PR_mbmsCountingResponse_r10:
734 735
       break;

736
      case LTE_UL_DCCH_MessageType__c1_PR_interFreqRSTDMeasurementIndication_r10:
737 738 739 740 741 742
       break;
#endif

      }
    }
  }
743 744
    /* encode */
  if (f1ap_encode_pdu(&pdu, &buffer, &len) < 0) {
745
    LOG_E(F1AP, "Failed to encode F1 setup request\n");
746
    return -1;
747 748
  }

749
  du_f1ap_itti_send_sctp_data_req(instance, f1ap_du_data->assoc_id, buffer, len, f1ap_du_data->default_sctp_stream_id);
750
  return 0;
751 752
}

753

754
/*  UL RRC Message Transfer */
755 756 757 758
int DU_send_INITIAL_UL_RRC_MESSAGE_TRANSFER(module_id_t     module_idP,
                                            int             CC_idP,
                                            int             UE_id,
                                            rnti_t          rntiP,
759
                                            const uint8_t   *sduP,
760
                                            sdu_size_t      sdu_lenP) {
761 762 763 764 765 766
  F1AP_F1AP_PDU_t                       pdu;
  F1AP_InitialULRRCMessageTransfer_t    *out;
  F1AP_InitialULRRCMessageTransferIEs_t *ie;

  uint8_t  *buffer;
  uint32_t  len;
767
  int f1ap_uid = f1ap_add_ue (&f1ap_du_inst[module_idP], module_idP, CC_idP,UE_id, rntiP);
768 769

  if (f1ap_uid  < 0 ) {
770
    LOG_E(F1AP, "Failed to add UE \n");
771 772
    return -1;
  }
773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790

  /* Create */
  /* 0. Message Type */
  memset(&pdu, 0, sizeof(pdu));
  pdu.present = F1AP_F1AP_PDU_PR_initiatingMessage;
  pdu.choice.initiatingMessage = (F1AP_InitiatingMessage_t *)calloc(1, sizeof(F1AP_InitiatingMessage_t));
  pdu.choice.initiatingMessage->procedureCode = F1AP_ProcedureCode_id_InitialULRRCMessageTransfer;
  pdu.choice.initiatingMessage->criticality   = F1AP_Criticality_ignore;
  pdu.choice.initiatingMessage->value.present = F1AP_InitiatingMessage__value_PR_InitialULRRCMessageTransfer;
  out = &pdu.choice.initiatingMessage->value.choice.InitialULRRCMessageTransfer;
  

  /* mandatory */
  /* c1. GNB_DU_UE_F1AP_ID */
  ie = (F1AP_InitialULRRCMessageTransferIEs_t *)calloc(1, sizeof(F1AP_InitialULRRCMessageTransferIEs_t));
  ie->id                             = F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
  ie->criticality                    = F1AP_Criticality_reject;
  ie->value.present                  = F1AP_InitialULRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
791
  ie->value.choice.GNB_DU_UE_F1AP_ID = f1ap_du_inst[module_idP].f1ap_ue[f1ap_uid].du_ue_f1ap_id;
792 793 794 795 796 797 798 799 800 801 802 803
  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);

  /* mandatory */
  /* c2. NRCGI */
  ie = (F1AP_InitialULRRCMessageTransferIEs_t *)calloc(1, sizeof(F1AP_InitialULRRCMessageTransferIEs_t));
  ie->id                             = F1AP_ProtocolIE_ID_id_NRCGI;
  ie->criticality                    = F1AP_Criticality_reject;
  ie->value.present                  = F1AP_InitialULRRCMessageTransferIEs__value_PR_NRCGI;

  F1AP_NRCGI_t nRCGI;
  MCC_MNC_TO_PLMNID(f1ap_du_data->mcc[0], f1ap_du_data->mnc[0], f1ap_du_data->mnc_digit_length[0],
                                         &nRCGI.pLMN_Identity);
804
  NR_CELL_ID_TO_BIT_STRING(f1ap_du_data->nr_cellid[0], &nRCGI.nRCellIdentity);
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823
  ie->value.choice.NRCGI = nRCGI;

  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);

  /* mandatory */
  /* c3. C_RNTI */  // 16
  ie = (F1AP_InitialULRRCMessageTransferIEs_t *)calloc(1, sizeof(F1AP_InitialULRRCMessageTransferIEs_t));
  ie->id                             = F1AP_ProtocolIE_ID_id_C_RNTI;
  ie->criticality                    = F1AP_Criticality_reject;
  ie->value.present                  = F1AP_InitialULRRCMessageTransferIEs__value_PR_C_RNTI;
  C_RNTI_TO_BIT_STRING(rntiP, &ie->value.choice.C_RNTI);
  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);

  /* mandatory */
  /* c4. RRCContainer */
  ie = (F1AP_InitialULRRCMessageTransferIEs_t *)calloc(1, sizeof(F1AP_InitialULRRCMessageTransferIEs_t));
  ie->id                            = F1AP_ProtocolIE_ID_id_RRCContainer;
  ie->criticality                   = F1AP_Criticality_reject;
  ie->value.present                 = F1AP_InitialULRRCMessageTransferIEs__value_PR_RRCContainer;
Robert Schmidt's avatar
Robert Schmidt committed
824
  OCTET_STRING_fromBuf(&ie->value.choice.RRCContainer, (const char *)sduP, sdu_lenP);
825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840
  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);

  /* optional */
  /* c5. DUtoCURRCContainer */
  if (0) {
    ie = (F1AP_InitialULRRCMessageTransferIEs_t *)calloc(1, sizeof(F1AP_InitialULRRCMessageTransferIEs_t));
    ie->id                             = F1AP_ProtocolIE_ID_id_DUtoCURRCContainer;
    ie->criticality                    = F1AP_Criticality_reject;
    ie->value.present                  = F1AP_InitialULRRCMessageTransferIEs__value_PR_DUtoCURRCContainer;
    OCTET_STRING_fromBuf(&ie->value.choice.DUtoCURRCContainer, "dummy_val",
                       strlen("dummy_val"));
    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
  }

    /* encode */
  if (f1ap_encode_pdu(&pdu, &buffer, &len) < 0) {
841
    LOG_E(F1AP, "Failed to encode F1 setup request\n");
842
    return -1;
843 844
  }

845

846 847 848 849 850 851
  struct rrc_eNB_ue_context_s* ue_context_p = rrc_eNB_allocate_new_UE_context(RC.rrc[module_idP]);
  ue_context_p->ue_id_rnti                    = rntiP; 
  ue_context_p->ue_context.rnti               = rntiP;
  ue_context_p->ue_context.random_ue_identity = rntiP;
  ue_context_p->ue_context.Srb0.Active        = 1;
  RB_INSERT(rrc_ue_tree_s, &RC.rrc[module_idP]->rrc_ue_head, ue_context_p);
852 853
  du_f1ap_itti_send_sctp_data_req(module_idP, f1ap_du_data->assoc_id, buffer, len,  f1ap_du_data->default_sctp_stream_id);

854
  return 0;
855
}
856
    
857 858 859

void init_f1ap_du_ue_inst (void) {

860
   memset(f1ap_du_inst, 0, sizeof(f1ap_du_inst));
861 862 863
}