asn1_msg_NB_IoT.c 70.4 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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
/* 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.0  (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 asn1_msg.c
* \brief primitives to build the asn1 messages
* \author Raymond Knopp, Navid Nikaein and Michele Paffetti
* \date 2011, 2017
* \version 1.0
* \company Eurecom
* \email: raymond.knopp@eurecom.fr, navid.nikaein@eurecom.fr, michele.paffetti@studio.unibo.it
*/

#ifdef USER_MODE
#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h> /* for atoi(3) */
#include <unistd.h> /* for getopt(3) */
#include <string.h> /* for strerror(3) */
#include <sysexits.h> /* for EX_* exit codes */
#include <errno.h>  /* for errno */
#else
#include <linux/module.h>  /* Needed by all modules */
#endif
#ifdef USER_MODE
//#include "RRC/LITE/defs.h"
//#include "COMMON/mac_rrc_primitives.h"
#include "UTIL/LOG/log.h"
#endif
#include <asn_application.h>
#include <asn_internal.h> /* for _ASN_DEFAULT_STACK_MAX */
#include <per_encoder.h>

#include "assertions.h"


//#include for NB-IoT-------------------
#include "RRCConnectionRequest-NB.h"
#include "BCCH-DL-SCH-Message-NB.h"
#include "UL-CCCH-Message-NB.h"
#include "UL-DCCH-Message-NB.h"
#include "DL-CCCH-Message-NB.h"
#include "DL-DCCH-Message-NB.h"
#include "EstablishmentCause-NB-r13.h"
#include "RRCConnectionSetup-NB.h"
#include "SRB-ToAddModList-NB-r13.h"
#include "DRB-ToAddModList-NB-r13.h"
64
#include "RRC/LITE/defs_NB_IoT.h"
65 66 67 68 69 70 71 72 73
#include "RRCConnectionSetupComplete-NB.h"
#include "RRCConnectionReconfigurationComplete-NB.h"
#include "RRCConnectionReconfiguration-NB.h"
#include "MasterInformationBlock-NB.h"
#include "SystemInformation-NB.h"
#include "SystemInformationBlockType1.h"
#include "SIB-Type-NB-r13.h"
#include "RRCConnectionResume-NB.h"
#include "RRCConnectionReestablishment-NB.h"
74
#include "PHY/defs_NB_IoT.h"
75 76
//----------------------------------------

77
//#include "PHY/defs.h"
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
#include "enb_config.h"

#if defined(ENABLE_ITTI)
# include "intertask_interface.h"
#endif

#ifndef USER_MODE
#define msg printk
#ifndef errno
int errno;
#endif
#else
# if !defined (msg)
#   define msg printf
# endif
#endif


96 97
/*do_MIB_NB_NB_IoT*/
uint8_t do_MIB_NB_IoT(
98
		rrc_eNB_carrier_data_NB_IoT_t *carrier,
99
		uint16_t N_RB_DL,//may not needed--> for NB_IoT only 1 PRB is used
100 101
		uint32_t frame,
    uint32_t hyper_frame)
102 103
{
  asn_enc_rval_t enc_rval;
104
  BCCH_BCH_Message_NB_t *mib_NB_IoT = &(carrier->mib_NB_IoT);
105

106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
  /*
   * systemFrameNumber-MSB: (TS 36.331 pag 576)
   * define the 4 MSB of the SFN (10 bits). The last significant 6 bits will be acquired implicitly by decoding the NPBCH
   * NOTE: 6 LSB will be used for counting the 64 radio frames in the TTI period (640 ms) that is exactly the MIB period
   *
   * hyperSFN-LSB:
   * indicates the 2 least significant bits of the HSFN. The remaining 8 bits are present in SIB1-NB
   * NOTE: with the 2 bits we count the 4 HSFN (is 1 SIB1-Nb modification period) while the other 6 count the number of modification periods
   *
   *
   * NOTE: in OAI never modify the SIB messages!!??
   */

  //XXX check if correct the bit assignment
  uint8_t sfn_MSB = (uint8_t)((frame>>6) & 0x0f); // all the 4 bits are set to 1
121
  uint8_t hsfn_LSB = (uint8_t)(hyper_frame & 0x3); //2 bits set to 1 (0x3 = 0011)
122 123
  uint16_t spare=0; //11 bits --> use uint16

124 125 126
  mib_NB_IoT->message.systemFrameNumber_MSB_r13.buf = &sfn_MSB;
  mib_NB_IoT->message.systemFrameNumber_MSB_r13.size = 1; //if expressed in byte
  mib_NB_IoT->message.systemFrameNumber_MSB_r13.bits_unused = 4; //is byte based (so how many bits you don't use of the 8 bits of a bite
127

128 129 130
  mib_NB_IoT->message.hyperSFN_LSB_r13.buf= &hsfn_LSB;
  mib_NB_IoT->message.hyperSFN_LSB_r13.size= 1;
  mib_NB_IoT->message.hyperSFN_LSB_r13.bits_unused = 6;
131

132
  //XXX to be set??
133
  mib_NB_IoT->message.spare.buf = (uint8_t *)&spare;
134 135
  mib_NB_IoT->message.spare.size = 2;
  mib_NB_IoT->message.spare.bits_unused = 5;
136 137

  //decide how to set it
138 139 140
  mib_NB_IoT->message.schedulingInfoSIB1_r13 =11; //see TS 36.213-->tables 16.4.1.3-3 ecc...
  mib_NB_IoT->message.systemInfoValueTag_r13= 0;
  mib_NB_IoT->message.ab_Enabled_r13 = 0;
141 142

  //to be decided
143
  mib_NB_IoT->message.operationModeInfo_r13.present = MasterInformationBlock_NB__operationModeInfo_r13_PR_inband_SamePCI_r13;
Matthieu Kanj's avatar
Matthieu Kanj committed
144
  mib_NB_IoT->message.operationModeInfo_r13.choice.inband_SamePCI_r13.eutra_CRS_SequenceInfo_r13 = 5;
145

146
  printf("[MIB] Intialization of frame information ,sfn_MSB %x, hsfn_LSB %x\n",
147 148 149 150
         (uint32_t)sfn_MSB,
		 (uint32_t)hsfn_LSB);

  enc_rval = uper_encode_to_buffer(&asn_DEF_BCCH_BCH_Message_NB,
151
                                   (void*)mib_NB_IoT,
152
                                   carrier->MIB_NB_IoT,
153 154 155 156 157 158 159 160 161
                                   100);
  AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n",
               enc_rval.failed_type->name, enc_rval.encoded);

  if (enc_rval.encoded==-1) {
    return(-1);
  }

  return((enc_rval.encoded+7)/8);
162

163 164 165
}

/*do_SIB1_NB*/
166
uint8_t do_SIB1_NB_IoT(uint8_t Mod_id, int CC_id,
167
				rrc_eNB_carrier_data_NB_IoT_t *carrier,
168 169
                RrcConfigurationReq *configuration,
				uint32_t frame
170 171
               )
{
172
  BCCH_DL_SCH_Message_NB_t *bcch_message= &(carrier->siblock1_NB_IoT);
173 174
  SystemInformationBlockType1_NB_t **sib1_NB_IoT= &(carrier->sib1_NB_IoT);
  
175 176 177

  asn_enc_rval_t enc_rval;

178
  PLMN_IdentityInfo_NB_r13_t PLMN_identity_info_NB_IoT;
179
  MCC_MNC_Digit_t dummy_mcc[3],dummy_mnc[3];
Nick Ho's avatar
Nick Ho committed
180 181
  SchedulingInfo_NB_r13_t schedulingInfo_NB_IoT;
  SIB_Type_NB_r13_t sib_type_NB_IoT;
182

183

184 185 186 187
  long* attachWithoutPDN_Connectivity = NULL;
  attachWithoutPDN_Connectivity = CALLOC(1,sizeof(long));
  long *nrs_CRS_PowerOffset=NULL;
  nrs_CRS_PowerOffset = CALLOC(1, sizeof(long));
188
  long *eutraControlRegionSize=NULL; //this parameter should be set only if we are considering in-band operating mode (samePCI or differentPCI)
189 190 191 192 193 194
   eutraControlRegionSize = CALLOC(1,sizeof(long));
  long systemInfoValueTagSI = 0;

  memset(bcch_message,0,sizeof(BCCH_DL_SCH_Message_NB_t));
  bcch_message->message.present = BCCH_DL_SCH_MessageType_NB_PR_c1;
  bcch_message->message.choice.c1.present = BCCH_DL_SCH_MessageType_NB__c1_PR_systemInformationBlockType1_r13;
Nick Ho's avatar
Nick Ho committed
195 196 197
  
  memset(&schedulingInfo_NB_IoT,0,sizeof(SchedulingInfo_NB_r13_t));
  memset(&sib_type_NB_IoT,0,sizeof(SIB_Type_NB_r13_t));
198
  //allocation
199
  *sib1_NB_IoT = &bcch_message->message.choice.c1.choice.systemInformationBlockType1_r13;
200

201 202 203 204 205 206 207 208

  /*TS 36.331 v14.2.0 pag 589
   * hyperSFN-MSB
   * Indicates the 8 most significant bits of the hyper-SFN. Together with the hyper-LSB in MIB-NB the complete HSFN is build up
   */
  //FIXME see if correct
  uint8_t hyperSFN_MSB = (uint8_t) ((frame>>2)& 0xff);

209
  //XXX to be checked
210 211 212
  (*sib1_NB_IoT)->hyperSFN_MSB_r13.buf = &hyperSFN_MSB;
  (*sib1_NB_IoT)->hyperSFN_MSB_r13.size = 1;
  (*sib1_NB_IoT)->hyperSFN_MSB_r13.bits_unused = 0;
213

214
  memset(&PLMN_identity_info_NB_IoT,0,sizeof(PLMN_IdentityInfo_NB_r13_t));
215

216 217
  PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc = CALLOC(1,sizeof(*PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc));
  memset(PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc,0,sizeof(*PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc));
218

219
  asn_set_empty(&PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc->list);//.size=0;
220 221 222 223 224 225 226 227 228 229 230

  //left as it is???
#if defined(ENABLE_ITTI)
  dummy_mcc[0] = (configuration->mcc / 100) % 10;
  dummy_mcc[1] = (configuration->mcc / 10) % 10;
  dummy_mcc[2] = (configuration->mcc / 1) % 10;
#else
  dummy_mcc[0] = 0;
  dummy_mcc[1] = 0;
  dummy_mcc[2] = 1;
#endif
231 232 233
  ASN_SEQUENCE_ADD(&PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc->list,&dummy_mcc[0]);
  ASN_SEQUENCE_ADD(&PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc->list,&dummy_mcc[1]);
  ASN_SEQUENCE_ADD(&PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc->list,&dummy_mcc[2]);
234

235 236
  PLMN_identity_info_NB_IoT.plmn_Identity_r13.mnc.list.size=0;
  PLMN_identity_info_NB_IoT.plmn_Identity_r13.mnc.list.count=0;
237

238

239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
#if defined(ENABLE_ITTI)

  if (configuration->mnc >= 100) {
    dummy_mnc[0] = (configuration->mnc / 100) % 10;
    dummy_mnc[1] = (configuration->mnc / 10) % 10;
    dummy_mnc[2] = (configuration->mnc / 1) % 10;
  } else {
    if (configuration->mnc_digit_length == 2) {
      dummy_mnc[0] = (configuration->mnc / 10) % 10;
      dummy_mnc[1] = (configuration->mnc / 1) % 10;
      dummy_mnc[2] = 0xf;
    } else {
      dummy_mnc[0] = (configuration->mnc / 100) % 100;
      dummy_mnc[1] = (configuration->mnc / 10) % 10;
      dummy_mnc[2] = (configuration->mnc / 1) % 10;
    }
  }

#else
  dummy_mnc[0] = 0;
  dummy_mnc[1] = 1;
  dummy_mnc[2] = 0xf;
#endif
262 263
  ASN_SEQUENCE_ADD(&PLMN_identity_info_NB_IoT.plmn_Identity_r13.mnc.list,&dummy_mnc[0]);
  ASN_SEQUENCE_ADD(&PLMN_identity_info_NB_IoT.plmn_Identity_r13.mnc.list,&dummy_mnc[1]);
264 265

  if (dummy_mnc[2] != 0xf) {
266
    ASN_SEQUENCE_ADD(&PLMN_identity_info_NB_IoT.plmn_Identity_r13.mnc.list,&dummy_mnc[2]);
267 268 269
  }

  //still set to "notReserved" as in the previous case
270
  PLMN_identity_info_NB_IoT.cellReservedForOperatorUse_r13=PLMN_IdentityInfo_NB_r13__cellReservedForOperatorUse_r13_notReserved;
271 272

  *attachWithoutPDN_Connectivity = 0;
273
  PLMN_identity_info_NB_IoT.attachWithoutPDN_Connectivity_r13 = attachWithoutPDN_Connectivity;
274

275
  ASN_SEQUENCE_ADD(&(*sib1_NB_IoT)->cellAccessRelatedInfo_r13.plmn_IdentityList_r13.list,&PLMN_identity_info_NB_IoT);
276 277

  // 16 bits = 2 byte
278
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.buf = MALLOC(2); //MALLOC works in byte
279 280 281

  //lefts as it is?
#if defined(ENABLE_ITTI)
282 283
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.buf[0] = (configuration->tac >> 8) & 0xff;
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.buf[1] = (configuration->tac >> 0) & 0xff;
284
#else
285 286
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.buf[0] = 0x00;
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.buf[1] = 0x01;
287
#endif
288 289
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.size=2;
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.bits_unused=0;
290 291

  // 28 bits --> i have to use 32 bits = 4 byte
292
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf = MALLOC(8); // why allocate 8 byte?
293
#if defined(ENABLE_ITTI)
294 295 296 297
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf[0] = (configuration->cell_identity >> 20) & 0xff;
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf[1] = (configuration->cell_identity >> 12) & 0xff;
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf[2] = (configuration->cell_identity >>  4) & 0xff;
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf[3] = (configuration->cell_identity <<  4) & 0xf0;
298
#else
299 300 301 302
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf[0] = 0x00;
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf[1] = 0x00;
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf[2] = 0x00;
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf[3] = 0x10;
303
#endif
304 305
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.size=4;
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.bits_unused=4;
306 307

  //Still set to "notBarred" as in the previous case
308
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellBarred_r13=SystemInformationBlockType1_NB__cellAccessRelatedInfo_r13__cellBarred_r13_notBarred;
309 310

  //Still Set to "notAllowed" like in the previous case
311
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.intraFreqReselection_r13=SystemInformationBlockType1_NB__cellAccessRelatedInfo_r13__intraFreqReselection_r13_notAllowed;
312 313


314 315
  (*sib1_NB_IoT)->cellSelectionInfo_r13.q_RxLevMin_r13=-65; //which value?? TS 36.331 V14.2.1 pag. 589
  (*sib1_NB_IoT)->cellSelectionInfo_r13.q_QualMin_r13 = 0; //FIXME new parameter for SIB1-NB, not present in SIB1 (for cell reselection but if not used the UE should apply the default value)
316

317 318
  (*sib1_NB_IoT)->p_Max_r13 = CALLOC(1, sizeof(P_Max_t));
  *((*sib1_NB_IoT)->p_Max_r13) = 23;
319

320
  //FIXME
321
  (*sib1_NB_IoT)->freqBandIndicator_r13 =
322
#if defined(ENABLE_ITTI)
323
    configuration->eutra_band[CC_id];
324
#else
325
    5; //if not configured we use band 5 (UL: 824 MHz - 849MHz / DL: 869 MHz - 894 MHz  FDD mode)
326
#endif
327
    
328 329 330 331 332
    //OPTIONAL new parameters, to be used?
      /*
       * freqBandInfo_r13
       * multiBandInfoList_r13
       * nrs_CRS_PowerOffset_r13
333
       * sib1_NB_IoT->downlinkBitmap_r13.choice.subframePattern10_r13 =(is a BIT_STRING)
334 335
       */

336

337 338
   (*sib1_NB_IoT)->downlinkBitmap_r13 = CALLOC(1, sizeof(struct DL_Bitmap_NB_r13));
   ((*sib1_NB_IoT)->downlinkBitmap_r13)->present= DL_Bitmap_NB_r13_PR_NOTHING;
339

Matthieu Kanj's avatar
Matthieu Kanj committed
340
   *eutraControlRegionSize = 2;
341
   (*sib1_NB_IoT)->eutraControlRegionSize_r13 = eutraControlRegionSize;
342 343 344


   *nrs_CRS_PowerOffset= 0;
345 346 347
   (*sib1_NB_IoT)->nrs_CRS_PowerOffset_r13 = nrs_CRS_PowerOffset;


348 349


350 351
  // Now, follow the scheduler SIB configuration
  // There is only one sib2+sib3 common setting
Matthieu Kanj's avatar
Matthieu Kanj committed
352 353

  schedulingInfo_NB_IoT.si_Periodicity_r13=SchedulingInfo_NB_r13__si_Periodicity_r13_rf4096; // (to be set to 64)
Nick Ho's avatar
Nick Ho committed
354 355
  schedulingInfo_NB_IoT.si_RepetitionPattern_r13=SchedulingInfo_NB_r13__si_RepetitionPattern_r13_every2ndRF; //This Indicates the starting radio frames within the SI window used for SI message transmission.
  schedulingInfo_NB_IoT.si_TB_r13= SchedulingInfo_NB_r13__si_TB_r13_b680;//208 bits
356
  
357 358 359 360 361 362

  // This is for SIB2/3
  /*SIB3 --> There is no mapping information of SIB2 since it is always present
    *  in the first SystemInformation message
    * listed in the schedulingInfoList list.
    * */
Nick Ho's avatar
Nick Ho committed
363
  sib_type_NB_IoT=SIB_Type_NB_r13_sibType3_NB_r13;
364

Nick Ho's avatar
Nick Ho committed
365 366
  ASN_SEQUENCE_ADD(&schedulingInfo_NB_IoT.sib_MappingInfo_r13.list,&sib_type_NB_IoT);
  ASN_SEQUENCE_ADD(&(*sib1_NB_IoT)->schedulingInfoList_r13.list,&schedulingInfo_NB_IoT);
367 368

  //printf("[ASN Debug] SI P: %ld\n",(*sib1_NB_IoT)->schedulingInfoList_r13.list.array[0]->si_Periodicity_r13);
369 370 371 372 373 374

#if defined(ENABLE_ITTI)

  if (configuration->frame_type[CC_id] == TDD)
#endif
  {
375 376 377
  //FIXME in NB-IoT mandatory to be FDD --> so must give an error
    LOG_E(RRC,"[NB-IoT %d] Frame Type is TDD --> not supported by NB-IoT, exiting\n", Mod_id); //correct?
    exit(-1);
378 379
  }

380
  //FIXME which value chose for the following parameter
381 382
  (*sib1_NB_IoT)->si_WindowLength_r13=SystemInformationBlockType1_NB__si_WindowLength_r13_ms160;
  (*sib1_NB_IoT)->si_RadioFrameOffset_r13= 0;
383 384 385 386 387

  /*In Nb-IoT change/update of specific SI message can additionally be indicated by a SI message specific value tag
   * systemInfoValueTagSI (there is no SystemInfoValueTag in SIB1-NB but only in MIB-NB)
   *contained in systemInfoValueTagList_r13
   **/
388
  //FIXME correct?
389 390 391
  (*sib1_NB_IoT)->systemInfoValueTagList_r13 = CALLOC(1, sizeof(struct SystemInfoValueTagList_NB_r13));
  asn_set_empty(&(*sib1_NB_IoT)->systemInfoValueTagList_r13->list);
  ASN_SEQUENCE_ADD(&(*sib1_NB_IoT)->systemInfoValueTagList_r13->list,&systemInfoValueTagSI);
392

393 394 395
  
  // To check if the bcch message properly setting
  printf("Check value :%d, should be band number\n",bcch_message->message.choice.c1.choice.systemInformationBlockType1_r13.freqBandIndicator_r13);
396 397 398 399 400

#ifdef XER_PRINT //generate xml files
  xer_fprint(stdout, &asn_DEF_BCCH_DL_SCH_Message_NB, (void*)bcch_message);
#endif

401
  //bcch_message->message.choice.c1.choice.systemInformationBlockType1_r13 = **sib1_NB_IoT;
402 403
  enc_rval = uper_encode_to_buffer(&asn_DEF_BCCH_DL_SCH_Message_NB,
                                   (void*)bcch_message,
404
                                   carrier->SIB1_NB_IoT,
405
                                   100);
406 407 408 409
 printf("In Asn.1 SIB1\n"); 
 for(int i=0;i<32;i++)
   printf("%x ",carrier->SIB1_NB_IoT[i]);
  printf("\n");
410

411 412
  if (enc_rval.encoded > 0){ 
       LOG_F(RRC,"ASN1 message encoding failed (%s, %lu)!\n",
413
               enc_rval.failed_type->name, enc_rval.encoded);
414
  }
415 416 417


#ifdef USER_MODE
418
  LOG_D(RRC,"[NB-IoT] SystemInformationBlockType1-NB Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8);
419 420 421 422 423 424 425 426 427
#endif

  if (enc_rval.encoded==-1) {
    return(-1);
  }

  return((enc_rval.encoded+7)/8);
}

428
/*SIB23_NB_IoT*/
429
//to be clarified is it is possible to carry SIB2 and SIB3  in the same SI message for NB-IoT?
430 431 432 433
uint8_t do_SIB23_NB_IoT(uint8_t Mod_id,
                        int CC_id,
                        rrc_eNB_carrier_data_NB_IoT_t *carrier,//MP: this is already a carrier[CC_id]
                        RrcConfigurationReq *configuration ) //openair2/COMMON/rrc_messages_types.h
434 435 436 437
{
  struct SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member *sib2_NB_part;
  struct SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member *sib3_NB_part;

438
  BCCH_DL_SCH_Message_NB_t *bcch_message = &(carrier->systemInformation_NB_IoT); //is the systeminformation-->BCCH_DL_SCH_Message_NB
439 440
  SystemInformationBlockType2_NB_r13_t *sib2_NB_IoT;
  SystemInformationBlockType3_NB_r13_t *sib3_NB_IoT;
441 442

  asn_enc_rval_t enc_rval;
443
  RACH_Info_NB_r13_t rach_Info_NB_IoT;
444
  NPRACH_Parameters_NB_r13_t *nprach_parameters;
445

446
  //optional
447 448 449
  long *connEstFailOffset = NULL;
  connEstFailOffset = CALLOC(1, sizeof(long));

450 451 452
//  RSRP_ThresholdsNPRACH_InfoList_NB_r13_t *rsrp_ThresholdsPrachInfoList;
//  RSRP_Range_t rsrp_range;

453
  ACK_NACK_NumRepetitions_NB_r13_t ack_nack_repetition;
454
  struct NPUSCH_ConfigCommon_NB_r13__dmrs_Config_r13 *dmrs_config;
455
  struct DL_GapConfig_NB_r13  *dl_Gap;
456 457 458 459 460 461 462 463

  long *srs_SubframeConfig;
  srs_SubframeConfig= CALLOC(1, sizeof(long));


  if (bcch_message) {
    memset(bcch_message,0,sizeof(BCCH_DL_SCH_Message_NB_t));
  } else {
464
    LOG_E(RRC,"[NB-IoT %d] BCCH_MESSAGE_NB is null, exiting\n", Mod_id);
465 466 467
    exit(-1);
  }

468
  //before schould be allocated memory somewhere?
469 470 471 472 473 474 475 476 477
//  if (!carrier->sib2_NB_IoT) {
//    LOG_E(RRC,"[NB-IoT %d] sib2_NB_IoT is null, exiting\n", Mod_id);
//    exit(-1);
//  }
//
//  if (!carrier->sib3_NB_IoT) {
//    LOG_E(RRC,"[NB-IoT %d] sib3_NB_IoT is null, exiting\n", Mod_id);
//    exit(-1);
//  }
478 479


480
  LOG_I(RRC,"[NB-IoT %d] Configuration SIB2/3\n", Mod_id);
481 482 483 484 485 486 487 488 489

  sib2_NB_part = CALLOC(1,sizeof(struct SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member));
  sib3_NB_part = CALLOC(1,sizeof(struct SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member));
  memset(sib2_NB_part,0,sizeof(struct SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member));
  memset(sib3_NB_part,0,sizeof(struct SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member));

  sib2_NB_part->present = SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member_PR_sib2_r13;
  sib3_NB_part->present = SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member_PR_sib3_r13;

490
  //may bug if not correct allocation of memory
491 492 493 494
  carrier->sib2_NB_IoT = &sib2_NB_part->choice.sib2_r13;
  carrier->sib3_NB_IoT = &sib3_NB_part->choice.sib3_r13;
  sib2_NB_IoT = carrier->sib2_NB_IoT;
  sib3_NB_IoT = carrier->sib3_NB_IoT;
495

496 497 498 499 500
  nprach_parameters = (NPRACH_Parameters_NB_r13_t *) malloc (3*sizeof(NPRACH_Parameters_NB_r13_t));

  memset(&nprach_parameters[0],0,sizeof(NPRACH_Parameters_NB_r13_t));
  memset(&nprach_parameters[1],0,sizeof(NPRACH_Parameters_NB_r13_t));
  memset(&nprach_parameters[2],0,sizeof(NPRACH_Parameters_NB_r13_t));
501 502 503

/// SIB2-NB-----------------------------------------

504
  //Barring is manage by ab-Enabled in MIB-NB (but is not a struct as ac-BarringInfo in LTE legacy)
505

506
  //RACH Config. Common--------------------------------------------------------------
507
  sib2_NB_IoT->radioResourceConfigCommon_r13.rach_ConfigCommon_r13.preambleTransMax_CE_r13 =
508
        configuration->rach_preambleTransMax_CE_NB[CC_id];
509
  sib2_NB_IoT->radioResourceConfigCommon_r13.rach_ConfigCommon_r13.powerRampingParameters_r13.powerRampingStep =
510
  configuration->rach_powerRampingStep_NB[CC_id];
511
  sib2_NB_IoT->radioResourceConfigCommon_r13.rach_ConfigCommon_r13.powerRampingParameters_r13.preambleInitialReceivedTargetPower =
512 513
    configuration->rach_preambleInitialReceivedTargetPower_NB[CC_id];

514 515
  rach_Info_NB_IoT.ra_ResponseWindowSize_r13 = configuration->rach_raResponseWindowSize_NB[CC_id];
  rach_Info_NB_IoT.mac_ContentionResolutionTimer_r13 = configuration-> rach_macContentionResolutionTimer_NB[CC_id];
516
  //rach_infoList max size = maxNPRACH-Resources-NB-r13 = 3
517
  ASN_SEQUENCE_ADD(&sib2_NB_IoT->radioResourceConfigCommon_r13.rach_ConfigCommon_r13.rach_InfoList_r13.list,&rach_Info_NB_IoT);
518

519
  //TS 36.331 pag 614 --> if not present the value to infinity sould be used
520
  *connEstFailOffset = 0;
521 522
  
  sib2_NB_IoT->radioResourceConfigCommon_r13.rach_ConfigCommon_r13.connEstFailOffset_r13 = connEstFailOffset; /*OPTIONAL*/
523 524


525
  // BCCH-Config-NB-IoT----------------------------------------------------------------
526
  sib2_NB_IoT->radioResourceConfigCommon_r13.bcch_Config_r13.modificationPeriodCoeff_r13
527
    = configuration->bcch_modificationPeriodCoeff_NB;
528

529
  // PCCH-Config-NB-IoT-----------------------------------------------------------------
530
  sib2_NB_IoT->radioResourceConfigCommon_r13.pcch_Config_r13.defaultPagingCycle_r13
531
    = configuration->pcch_defaultPagingCycle_NB;
532 533
  sib2_NB_IoT->radioResourceConfigCommon_r13.pcch_Config_r13.nB_r13 = configuration->pcch_nB_NB[CC_id];
  sib2_NB_IoT->radioResourceConfigCommon_r13.pcch_Config_r13.npdcch_NumRepetitionPaging_r13 = configuration-> pcch_npdcch_NumRepetitionPaging_NB[CC_id];
534

535
  //NPRACH-Config-NB-IoT-----------------------------------------------------------------
536 537

  sib2_NB_IoT->radioResourceConfigCommon_r13.nprach_Config_r13.rsrp_ThresholdsPrachInfoList_r13 = NULL; 
538
  sib2_NB_IoT->radioResourceConfigCommon_r13.nprach_Config_r13.nprach_CP_Length_r13 = configuration->nprach_CP_Length[CC_id];
539
  /*OPTIONAL*/
540
//   =CALLOC(1, sizeof(struct RSRP_ThresholdsNPRACH_InfoList_NB_r13)); //fatto uguale dopo
541
//   rsrp_ThresholdsPrachInfoList = sib2_NB_IoT->radioResourceConfigCommon_r13.nprach_Config_r13.rsrp_ThresholdsPrachInfoList_r13;
542 543
//   rsrp_range = configuration->nprach_rsrp_range_NB;
//   ASN_SEQUENCE_ADD(&rsrp_ThresholdsPrachInfoList->list,rsrp_range);
544

545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560
  // According configuration to set the 3 CE level configuration setting, for the initial testing, only consider the CE 0, since there is only one set of parameters.

  nprach_parameters[0].nprach_Periodicity_r13               = configuration->nprach_Periodicity[CC_id];
  nprach_parameters[0].nprach_StartTime_r13                 = configuration->nprach_StartTime[CC_id];
  nprach_parameters[0].nprach_SubcarrierOffset_r13          = configuration->nprach_SubcarrierOffset[CC_id];
  nprach_parameters[0].nprach_NumSubcarriers_r13            = configuration->nprach_NumSubcarriers[CC_id];
  nprach_parameters[0].numRepetitionsPerPreambleAttempt_r13 = configuration->numRepetitionsPerPreambleAttempt_NB[CC_id];
  nprach_parameters[0].nprach_SubcarrierMSG3_RangeStart_r13 = configuration->nprach_SubcarrierMSG3_RangeStart[CC_id];
  nprach_parameters[0].maxNumPreambleAttemptCE_r13          = configuration->maxNumPreambleAttemptCE_NB[CC_id];
  nprach_parameters[0].npdcch_NumRepetitions_RA_r13         = configuration->npdcch_NumRepetitions_RA[CC_id];
  nprach_parameters[0].npdcch_StartSF_CSS_RA_r13            = configuration->npdcch_StartSF_CSS_RA[CC_id];
  nprach_parameters[0].npdcch_Offset_RA_r13                 = configuration->npdcch_Offset_RA[CC_id];

  nprach_parameters[1].nprach_Periodicity_r13               = configuration->nprach_Periodicity[CC_id];
  nprach_parameters[1].nprach_StartTime_r13                 = configuration->nprach_StartTime[CC_id];
  nprach_parameters[1].nprach_SubcarrierOffset_r13          = configuration->nprach_SubcarrierOffset[CC_id];
561
  nprach_parameters[1].nprach_NumSubcarriers_r13            = configuration->nprach_NumSubcarriers[CC_id];
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
  nprach_parameters[1].numRepetitionsPerPreambleAttempt_r13 = configuration->numRepetitionsPerPreambleAttempt_NB[CC_id];
  nprach_parameters[1].nprach_SubcarrierMSG3_RangeStart_r13 = configuration->nprach_SubcarrierMSG3_RangeStart[CC_id];
  nprach_parameters[1].maxNumPreambleAttemptCE_r13          = configuration->maxNumPreambleAttemptCE_NB[CC_id];
  nprach_parameters[1].npdcch_NumRepetitions_RA_r13         = configuration->npdcch_NumRepetitions_RA[CC_id];
  nprach_parameters[1].npdcch_StartSF_CSS_RA_r13            = configuration->npdcch_StartSF_CSS_RA[CC_id];
  nprach_parameters[1].npdcch_Offset_RA_r13                 = configuration->npdcch_Offset_RA[CC_id];

  nprach_parameters[2].nprach_Periodicity_r13               = configuration->nprach_Periodicity[CC_id];
  nprach_parameters[2].nprach_StartTime_r13                 = configuration->nprach_StartTime[CC_id];
  nprach_parameters[2].nprach_SubcarrierOffset_r13          = configuration->nprach_SubcarrierOffset[CC_id];
  nprach_parameters[2].nprach_NumSubcarriers_r13            = configuration->nprach_NumSubcarriers[CC_id];
  nprach_parameters[2].numRepetitionsPerPreambleAttempt_r13 = configuration->numRepetitionsPerPreambleAttempt_NB[CC_id];
  nprach_parameters[2].nprach_SubcarrierMSG3_RangeStart_r13 = configuration->nprach_SubcarrierMSG3_RangeStart[CC_id];
  nprach_parameters[2].maxNumPreambleAttemptCE_r13          = configuration->maxNumPreambleAttemptCE_NB[CC_id];
  nprach_parameters[2].npdcch_NumRepetitions_RA_r13         = configuration->npdcch_NumRepetitions_RA[CC_id];
  nprach_parameters[2].npdcch_StartSF_CSS_RA_r13            = configuration->npdcch_StartSF_CSS_RA[CC_id];
  nprach_parameters[2].npdcch_Offset_RA_r13                 = configuration->npdcch_Offset_RA[CC_id];
579

580

581 582 583 584 585
  //nprach_parameterList have a max size of 3 possible nprach configuration (see maxNPRACH_Resources_NB_r13)
  ASN_SEQUENCE_ADD(&sib2_NB_IoT->radioResourceConfigCommon_r13.nprach_Config_r13.nprach_ParametersList_r13.list,&nprach_parameters[0]);
  ASN_SEQUENCE_ADD(&sib2_NB_IoT->radioResourceConfigCommon_r13.nprach_Config_r13.nprach_ParametersList_r13.list,&nprach_parameters[1]);
  ASN_SEQUENCE_ADD(&sib2_NB_IoT->radioResourceConfigCommon_r13.nprach_Config_r13.nprach_ParametersList_r13.list,&nprach_parameters[2]);
  
586
  // NPDSCH-Config NB-IOT
587
  sib2_NB_IoT->radioResourceConfigCommon_r13.npdsch_ConfigCommon_r13.nrs_Power_r13= configuration->npdsch_nrs_Power[CC_id];
588 589


590
  //NPUSCH-Config NB-IoT----------------------------------------------------------------
591
  //list of size 3 (see maxNPRACH_Resources_NB_r13)
592
  ack_nack_repetition = configuration-> npusch_ack_nack_numRepetitions_NB[CC_id]; //is an enumerative
593
  ASN_SEQUENCE_ADD(&(sib2_NB_IoT->radioResourceConfigCommon_r13.npusch_ConfigCommon_r13.ack_NACK_NumRepetitions_Msg4_r13.list) ,&ack_nack_repetition);
594 595

  *srs_SubframeConfig = configuration->npusch_srs_SubframeConfig_NB[CC_id];
596
  sib2_NB_IoT->radioResourceConfigCommon_r13.npusch_ConfigCommon_r13.srs_SubframeConfig_r13= srs_SubframeConfig; /*OPTIONAL*/
597 598


599 600
  /*OPTIONAL*/
  dmrs_config = CALLOC(1,sizeof(struct NPUSCH_ConfigCommon_NB_r13__dmrs_Config_r13));
601 602
  dmrs_config->threeTone_CyclicShift_r13 = configuration->npusch_threeTone_CyclicShift_r13;
  dmrs_config->sixTone_CyclicShift_r13 = configuration->npusch_sixTone_CyclicShift_r13;
603 604 605 606

  /*OPTIONAL
   * -define the base sequence for a DMRS sequence in a cell with multi tone transmission (3,6,12) see TS 36.331 NPUSCH-Config-NB
   * -if not defined will be calculated based on the cellID once we configure the phy layer (rrc_mac_config_req) through the config_sib2 */
607 608 609
  dmrs_config->threeTone_BaseSequence_r13 = NULL;
  dmrs_config->sixTone_BaseSequence_r13 = NULL;
  dmrs_config->twelveTone_BaseSequence_r13 = NULL;
610

611
  sib2_NB_IoT->radioResourceConfigCommon_r13.npusch_ConfigCommon_r13.dmrs_Config_r13 = dmrs_config;
612

613 614 615 616 617 618
  //ulReferenceSignalsNPUSCH
  /*Reference Signal (RS) for UL in NB-IoT is called DRS (Demodulation Reference Signal)
   * sequence-group hopping can be enabled or disabled by means of the cell-specific parameter groupHoppingEnabled_r13
   * sequence-group hopping can be disabled for certain specific UE through the parameter groupHoppingDisabled (physicalConfigDedicated)
   * groupAssignmentNPUSCH--> is used for generate the sequence-shift pattern
   */
619 620
  sib2_NB_IoT->radioResourceConfigCommon_r13.npusch_ConfigCommon_r13.ul_ReferenceSignalsNPUSCH_r13.groupHoppingEnabled_r13= configuration->npusch_groupHoppingEnabled[CC_id];
  sib2_NB_IoT->radioResourceConfigCommon_r13.npusch_ConfigCommon_r13.ul_ReferenceSignalsNPUSCH_r13.groupAssignmentNPUSCH_r13 =configuration->npusch_groupAssignmentNPUSCH_r13[CC_id];
621 622


623
  //dl_GAP---------------------------------------------------------------------------------/*OPTIONAL*/
624 625 626 627
  dl_Gap = CALLOC(1,sizeof(struct DL_GapConfig_NB_r13));
  dl_Gap->dl_GapDurationCoeff_r13= configuration-> dl_GapDurationCoeff_NB[CC_id];
  dl_Gap->dl_GapPeriodicity_r13= configuration->dl_GapPeriodicity_NB[CC_id];
  dl_Gap->dl_GapThreshold_r13= configuration->dl_GapThreshold_NB[CC_id];
628
  sib2_NB_IoT->radioResourceConfigCommon_r13.dl_Gap_r13 = dl_Gap;
629 630


631
  // uplinkPowerControlCommon - NB-IoT------------------------------------------------------
632 633 634
  sib2_NB_IoT->radioResourceConfigCommon_r13.uplinkPowerControlCommon_r13.p0_NominalNPUSCH_r13 = configuration->npusch_p0_NominalNPUSCH[CC_id];
  sib2_NB_IoT->radioResourceConfigCommon_r13.uplinkPowerControlCommon_r13.deltaPreambleMsg3_r13 = configuration->deltaPreambleMsg3[CC_id];
  sib2_NB_IoT->radioResourceConfigCommon_r13.uplinkPowerControlCommon_r13.alpha_r13 = configuration->npusch_alpha[CC_id];
635 636
  //no deltaFlist_PUCCH and no UL cyclic prefix

637
  // UE Timers and Constants -NB-IoT--------------------------------------------------------
638 639 640 641 642 643
  sib2_NB_IoT->ue_TimersAndConstants_r13.t300_r13 = configuration-> ue_TimersAndConstants_t300_NB[CC_id];
  sib2_NB_IoT->ue_TimersAndConstants_r13.t301_r13 = configuration-> ue_TimersAndConstants_t301_NB[CC_id];
  sib2_NB_IoT->ue_TimersAndConstants_r13.t310_r13 = configuration-> ue_TimersAndConstants_t310_NB[CC_id];
  sib2_NB_IoT->ue_TimersAndConstants_r13.t311_r13 = configuration-> ue_TimersAndConstants_t311_NB[CC_id];
  sib2_NB_IoT->ue_TimersAndConstants_r13.n310_r13 = configuration-> ue_TimersAndConstants_n310_NB[CC_id];
  sib2_NB_IoT->ue_TimersAndConstants_r13.n311_r13 = configuration-> ue_TimersAndConstants_n311_NB[CC_id];
644

645
  //other SIB2-NB Parameters--------------------------------------------------------------------------------
646 647
  sib2_NB_IoT->freqInfo_r13.additionalSpectrumEmission_r13 = 1;
  sib2_NB_IoT->freqInfo_r13.ul_CarrierFreq_r13 = NULL; /*OPTIONAL*/
648

649
  sib2_NB_IoT->timeAlignmentTimerCommon_r13=TimeAlignmentTimer_infinity;//TimeAlignmentTimer_sf5120;
650 651

  /*OPTIONAL*/
652
  sib2_NB_IoT->multiBandInfoList_r13 = NULL;
653 654 655

/// SIB3-NB-------------------------------------------------------

656
  sib3_NB_IoT->cellReselectionInfoCommon_r13.q_Hyst_r13=SystemInformationBlockType3_NB_r13__cellReselectionInfoCommon_r13__q_Hyst_r13_dB4;
657
  sib3_NB_IoT->cellReselectionServingFreqInfo_r13.s_NonIntraSearch_r13=0; //or define in configuration?
658

659
  sib3_NB_IoT->intraFreqCellReselectionInfo_r13.q_RxLevMin_r13 = -70;
660
  //new
661 662
  sib3_NB_IoT->intraFreqCellReselectionInfo_r13.q_QualMin_r13 = CALLOC(1,sizeof(*sib3_NB_IoT->intraFreqCellReselectionInfo_r13.q_QualMin_r13));
  *(sib3_NB_IoT->intraFreqCellReselectionInfo_r13.q_QualMin_r13)= 10; //a caso
663

664 665 666
  sib3_NB_IoT->intraFreqCellReselectionInfo_r13.p_Max_r13 = NULL;
  sib3_NB_IoT->intraFreqCellReselectionInfo_r13.s_IntraSearchP_r13 = 31; // s_intraSearch --> s_intraSearchP!!! (they call in a different way)
  sib3_NB_IoT->intraFreqCellReselectionInfo_r13.t_Reselection_r13=1;
667 668

  //how to manage?
669 670
  sib3_NB_IoT->freqBandInfo_r13 = NULL;
  sib3_NB_IoT->multiBandInfoList_r13 = NULL;
671 672


673
///BCCH message (generate the SI message)
674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689
  bcch_message->message.present = BCCH_DL_SCH_MessageType_NB_PR_c1;
  bcch_message->message.choice.c1.present = BCCH_DL_SCH_MessageType_NB__c1_PR_systemInformation_r13;

  bcch_message->message.choice.c1.choice.systemInformation_r13.criticalExtensions.present = SystemInformation_NB__criticalExtensions_PR_systemInformation_r13;
  bcch_message->message.choice.c1.choice.systemInformation_r13.criticalExtensions.choice.systemInformation_r13.sib_TypeAndInfo_r13.list.count=0;

  ASN_SEQUENCE_ADD(&bcch_message->message.choice.c1.choice.systemInformation_r13.criticalExtensions.choice.systemInformation_r13.sib_TypeAndInfo_r13.list,
                   sib2_NB_part);
  ASN_SEQUENCE_ADD(&bcch_message->message.choice.c1.choice.systemInformation_r13.criticalExtensions.choice.systemInformation_r13.sib_TypeAndInfo_r13.list,
                   sib3_NB_part);

#ifdef XER_PRINT
  xer_fprint(stdout, &asn_DEF_BCCH_DL_SCH_Message_NB, (void*)bcch_message);
#endif
  enc_rval = uper_encode_to_buffer(&asn_DEF_BCCH_DL_SCH_Message_NB,
                                   (void*)bcch_message,
690
                                   carrier->SIB23_NB_IoT,
691
                                   900);
692 693 694 695 696 697

   printf("In Asn.1 SIB23\n"); 
 for(int i=0;i<32;i++)
   printf("%x ", carrier->SIB23_NB_IoT[i]);
  printf("\n");
  printf("(enc_rval.encoded+7)/8 = %d\n",(enc_rval.encoded+7)/8);
698 699
//  AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n",
//               enc_rval.failed_type->name, enc_rval.encoded);
700

701
//#if defined(ENABLE_ITTI).....
702 703 704


#ifdef USER_MODE
705
  LOG_D(RRC,"[NB-IoT] SystemInformation-NB Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8);
706 707 708
#endif

  if (enc_rval.encoded==-1) {
709
    msg("[RRC] ASN1 : SI-NB encoding failed for SIB23_NB_IoT\n");
710 711 712
    return(-1);
  }

713 714 715
  carrier->sib2_NB_IoT = sib2_NB_IoT;
  carrier->sib3_NB_IoT = sib3_NB_IoT;

716 717 718
  return((enc_rval.encoded+7)/8);
}

719 720
/*do_RRCConnectionSetup_NB_IoT--> the aim is to establish SRB1 and SRB1bis(implicitly)*/
uint8_t do_RRCConnectionSetup_NB_IoT(
721
  const protocol_ctxt_t*     const ctxt_pP,
722
  rrc_eNB_ue_context_NB_IoT_t*      const ue_context_pP,
723
  int                              CC_id,
724
  uint8_t*                   const buffer, //Srb0.Tx_buffer.Payload
725
  const uint8_t                    Transaction_id,
726
  const NB_IoT_DL_FRAME_PARMS* const frame_parms, // maybe not used
727 728
  SRB_ToAddModList_NB_r13_t**             SRB_configList_NB_IoT, //for both SRB1bis and SRB1
  struct PhysicalConfigDedicated_NB_r13** physicalConfigDedicated_NB_IoT
729 730 731 732 733 734 735
)

{

 asn_enc_rval_t enc_rval;
 uint8_t ecause=0;

736
 //MP:logical channel group not defined for Nb-IoT
737

738 739
 //MP: logical channel priority pag 605 (is 1 for SRB1 and for SRB1bis should be the same)
 long* prioritySRB1 = NULL;
740 741
 long* prioritySRB1bis = NULL;
 BOOLEAN_t* logicalChannelSR_Prohibit =NULL; //pag 605
742
 BOOLEAN_t* npusch_AllSymbols= NULL;
743

744 745 746
// struct SRB_ToAddMod_NB_r13* SRB1_config_NB = NULL;
// struct SRB_ToAddMod_NB_r13__rlc_Config_r13* SRB1_rlc_config_NB = NULL;
// struct SRB_ToAddMod_NB_r13__logicalChannelConfig_r13* SRB1_lchan_config_NB = NULL;
747

748 749 750
 struct SRB_ToAddMod_NB_r13* SRB1bis_config_NB_IoT = NULL;
 struct SRB_ToAddMod_NB_r13__rlc_Config_r13* SRB1bis_rlc_config_NB_IoT = NULL;
 struct SRB_ToAddMod_NB_r13__logicalChannelConfig_r13* SRB1bis_lchan_config_NB_IoT = NULL;
751 752 753

 //No UL_specific parameters for NB-IoT in LogicalChanelConfig-NB

754
 PhysicalConfigDedicated_NB_r13_t* physicalConfigDedicated2_NB_IoT = NULL;
755
 DL_CCCH_Message_NB_t dl_ccch_msg_NB_IoT;
756
 RRCConnectionSetup_NB_t* rrcConnectionSetup_NB_IoT = NULL;
757

758 759 760
 memset((void *)&dl_ccch_msg_NB_IoT,0,sizeof(DL_CCCH_Message_NB_t));
 dl_ccch_msg_NB_IoT.message.present = DL_CCCH_MessageType_NB_PR_c1;
 dl_ccch_msg_NB_IoT.message.choice.c1.present = DL_CCCH_MessageType_NB__c1_PR_rrcConnectionSetup_r13;
761
 rrcConnectionSetup_NB_IoT = &dl_ccch_msg_NB_IoT.message.choice.c1.choice.rrcConnectionSetup_r13;
762 763


764 765
 if (*SRB_configList_NB_IoT) {
   free(*SRB_configList_NB_IoT);
766
 }
767
 *SRB_configList_NB_IoT = CALLOC(1,sizeof(SRB_ToAddModList_NB_r13_t));
768

769
/// SRB1--------------------
770
 {
771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788
// SRB1_config_NB = CALLOC(1,sizeof(*SRB1_config_NB));
//
// //no srb_Identity in SRB_ToAddMod_NB
//
// SRB1_rlc_config_NB = CALLOC(1,sizeof(*SRB1_rlc_config_NB));
// SRB1_config_NB->rlc_Config_r13   = SRB1_rlc_config_NB;
//
// SRB1_rlc_config_NB->present = SRB_ToAddMod_NB_r13__rlc_Config_r13_PR_explicitValue;
// SRB1_rlc_config_NB->choice.explicitValue.present=RLC_Config_NB_r13_PR_am;//the only possible in NB_IoT
//
//// SRB1_rlc_config_NB->choice.explicitValue.choice.am.ul_AM_RLC_r13.t_PollRetransmit_r13 = enb_properties.properties[ctxt_pP->module_id]->srb1_timer_poll_retransmit_r13;
//// SRB1_rlc_config_NB->choice.explicitValue.choice.am.ul_AM_RLC_r13.maxRetxThreshold_r13 = enb_properties.properties[ctxt_pP->module_id]->srb1_max_retx_threshold_r13;
//// //(musT be disabled--> SRB1 config pag 640 specs )
//// SRB1_rlc_config_NB->choice.explicitValue.choice.am.dl_AM_RLC_r13.enableStatusReportSN_Gap_r13 =NULL;
//
//
// SRB1_rlc_config_NB->choice.explicitValue.choice.am.ul_AM_RLC_r13.t_PollRetransmit_r13 = T_PollRetransmit_NB_r13_ms25000;
// SRB1_rlc_config_NB->choice.explicitValue.choice.am.ul_AM_RLC_r13.maxRetxThreshold_r13 = UL_AM_RLC_NB_r13__maxRetxThreshold_r13_t8;
789
// //(musT be disabled--> SRB1 config pag 640 specs )
790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807
// SRB1_rlc_config_NB->choice.explicitValue.choice.am.dl_AM_RLC_r13.enableStatusReportSN_Gap_r13 = NULL;
//
// SRB1_lchan_config_NB = CALLOC(1,sizeof(*SRB1_lchan_config_NB));
// SRB1_config_NB->logicalChannelConfig_r13  = SRB1_lchan_config_NB;
//
// SRB1_lchan_config_NB->present = SRB_ToAddMod_NB_r13__logicalChannelConfig_r13_PR_explicitValue;
//
//
// prioritySRB1 = CALLOC(1, sizeof(long));
// *prioritySRB1 = 1;
// SRB1_lchan_config_NB->choice.explicitValue.priority_r13 = prioritySRB1;
//
// logicalChannelSR_Prohibit = CALLOC(1, sizeof(BOOLEAN_t));
// *logicalChannelSR_Prohibit = 1;
// //schould be set to TRUE (specs pag 641)
// SRB1_lchan_config_NB->choice.explicitValue.logicalChannelSR_Prohibit_r13 = logicalChannelSR_Prohibit;
//
// //ADD SRB1
808
// ASN_SEQUENCE_ADD(&(*SRB_configList_NB_IoT)->list,SRB1_config_NB);
809
 }
810

811
///SRB1bis (The configuration for SRB1 and SRB1bis is the same) the only difference is the logical channel identity = 3 but not set here
812

813
		 SRB1bis_config_NB_IoT = CALLOC(1,sizeof(*SRB1bis_config_NB_IoT));
814 815

		 //no srb_Identity in SRB_ToAddMod_NB
816 817
		 SRB1bis_rlc_config_NB_IoT = CALLOC(1,sizeof(*SRB1bis_rlc_config_NB_IoT));
		 SRB1bis_config_NB_IoT->rlc_Config_r13   = SRB1bis_rlc_config_NB_IoT;
818

819 820
		 SRB1bis_rlc_config_NB_IoT->present = SRB_ToAddMod_NB_r13__rlc_Config_r13_PR_explicitValue;
		 SRB1bis_rlc_config_NB_IoT->choice.explicitValue.present=RLC_Config_NB_r13_PR_am;//MP: the only possible RLC config in NB_IoT
821

822 823
		 SRB1bis_rlc_config_NB_IoT->choice.explicitValue.choice.am.ul_AM_RLC_r13.t_PollRetransmit_r13 = T_PollRetransmit_NB_r13_ms25000;
		 SRB1bis_rlc_config_NB_IoT->choice.explicitValue.choice.am.ul_AM_RLC_r13.maxRetxThreshold_r13 = UL_AM_RLC_NB_r13__maxRetxThreshold_r13_t8;
824
		 //(musT be disabled--> SRB1 config pag 640 specs )
825
		 SRB1bis_rlc_config_NB_IoT->choice.explicitValue.choice.am.dl_AM_RLC_r13.enableStatusReportSN_Gap_r13 =NULL;
826

827 828
		 SRB1bis_lchan_config_NB_IoT = CALLOC(1,sizeof(*SRB1bis_lchan_config_NB_IoT));
		 SRB1bis_config_NB_IoT->logicalChannelConfig_r13  = SRB1bis_lchan_config_NB_IoT;
829

830
		 SRB1bis_lchan_config_NB_IoT->present = SRB_ToAddMod_NB_r13__logicalChannelConfig_r13_PR_explicitValue;
831 832

		 prioritySRB1bis = CALLOC(1, sizeof(long));
833
		 *prioritySRB1bis = 1; //same as SRB1?
834
		 SRB1bis_lchan_config_NB_IoT->choice.explicitValue.priority_r13 = prioritySRB1bis;
835 836

		 logicalChannelSR_Prohibit = CALLOC(1, sizeof(BOOLEAN_t));
837
		 *logicalChannelSR_Prohibit = 1; //schould be set to TRUE (specs pag 641)
838
		 SRB1bis_lchan_config_NB_IoT->choice.explicitValue.logicalChannelSR_Prohibit_r13 = logicalChannelSR_Prohibit;
839

840
		 //ADD SRB1bis
841
		 //MP: Actually there is no way to distinguish SRB1 and SRB1bis once put in the list
842
		 //MP: SRB_ToAddModList_NB_r13_t size = 1
843
		 ASN_SEQUENCE_ADD(&(*SRB_configList_NB_IoT)->list,SRB1bis_config_NB_IoT);
844 845 846 847


 // PhysicalConfigDedicated (NPDCCH, NPUSCH, CarrierConfig, UplinkPowerControl)

848 849
 physicalConfigDedicated2_NB_IoT = CALLOC(1,sizeof(*physicalConfigDedicated2_NB_IoT));
 *physicalConfigDedicated_NB_IoT = physicalConfigDedicated2_NB_IoT;
850

851 852 853 854
 physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13= CALLOC(1, sizeof(*physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13));
 physicalConfigDedicated2_NB_IoT->npdcch_ConfigDedicated_r13 = CALLOC(1,sizeof(*physicalConfigDedicated2_NB_IoT->npdcch_ConfigDedicated_r13));
 physicalConfigDedicated2_NB_IoT->npusch_ConfigDedicated_r13 = CALLOC(1,sizeof(*physicalConfigDedicated2_NB_IoT->npusch_ConfigDedicated_r13));
 physicalConfigDedicated2_NB_IoT->uplinkPowerControlDedicated_r13 = CALLOC(1,sizeof(*physicalConfigDedicated2_NB_IoT->uplinkPowerControlDedicated_r13));
855 856 857 858 859 860 861 862 863

 //no tpc, no cqi and no pucch, no pdsch, no soundingRS, no AntennaInfo, no scheduling request config

 /*
  * NB-IoT supports the operation with either one or two antenna ports, AP0 and AP1.
  * For the latter case, Space Frequency Block Coding (SFBC) is applied.
  * Once selected, the same transmission scheme applies to NPBCH, NPDCCH, and NPDSCH.
  * */

864 865 866 867
 //FIXME: MP: CarrierConfigDedicated check the set values ----------------------------------------------

  //DL

868 869 870
 physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13->dl_CarrierConfig_r13.dl_CarrierFreq_r13.carrierFreq_r13=0;//random value set
 physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13->dl_CarrierConfig_r13.downlinkBitmapNonAnchor_r13= CALLOC(1,sizeof(struct DL_CarrierConfigDedicated_NB_r13__downlinkBitmapNonAnchor_r13));
		 physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13->dl_CarrierConfig_r13.downlinkBitmapNonAnchor_r13->present=
871 872
				 	 	 	 	 	 	 	 	 DL_CarrierConfigDedicated_NB_r13__downlinkBitmapNonAnchor_r13_PR_useNoBitmap_r13;

873 874
 physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13->dl_CarrierConfig_r13.dl_GapNonAnchor_r13 = CALLOC(1,sizeof(struct DL_CarrierConfigDedicated_NB_r13__dl_GapNonAnchor_r13));
 physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13->dl_CarrierConfig_r13.dl_GapNonAnchor_r13->present =
875 876
		  	  	  	  	  	  	  	  	  	  	  DL_CarrierConfigDedicated_NB_r13__dl_GapNonAnchor_r13_PR_useNoGap_r13;

877
 physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13->dl_CarrierConfig_r13.inbandCarrierInfo_r13= NULL;
878

879
  //UL
880
 physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13->ul_CarrierConfig_r13.ul_CarrierFreq_r13= NULL;
881 882

 // NPDCCH
883 884 885
 physicalConfigDedicated2_NB_IoT->npdcch_ConfigDedicated_r13->npdcch_NumRepetitions_r13 =0;
 physicalConfigDedicated2_NB_IoT->npdcch_ConfigDedicated_r13->npdcch_Offset_USS_r13 =0;
 physicalConfigDedicated2_NB_IoT->npdcch_ConfigDedicated_r13->npdcch_StartSF_USS_r13=0;
886

887
 // NPUSCH //(specs TS 36.331 v14.2.1 pag 643) /* OPTIONAL */
888
 physicalConfigDedicated2_NB_IoT->npusch_ConfigDedicated_r13->ack_NACK_NumRepetitions_r13= NULL;
889 890
 npusch_AllSymbols= CALLOC(1, sizeof(BOOLEAN_t));
 *npusch_AllSymbols= 1; //TRUE
891 892
 physicalConfigDedicated2_NB_IoT->npusch_ConfigDedicated_r13->npusch_AllSymbols_r13= npusch_AllSymbols; /* OPTIONAL */
 physicalConfigDedicated2_NB_IoT->npusch_ConfigDedicated_r13->groupHoppingDisabled_r13=NULL; /* OPTIONAL */
893 894

 // UplinkPowerControlDedicated
895
 physicalConfigDedicated2_NB_IoT->uplinkPowerControlDedicated_r13->p0_UE_NPUSCH_r13 = 0; // 0 dB (specs TS36.331 v14.2.1 pag 643)
896 897


898
 //Fill the rrcConnectionSetup-NB message
899 900 901
 rrcConnectionSetup_NB_IoT->rrc_TransactionIdentifier = Transaction_id; //input value
 rrcConnectionSetup_NB_IoT->criticalExtensions.present = RRCConnectionSetup_NB__criticalExtensions_PR_c1;
 rrcConnectionSetup_NB_IoT->criticalExtensions.choice.c1.present =RRCConnectionSetup_NB__criticalExtensions__c1_PR_rrcConnectionSetup_r13 ;
902
 //MP: carry only SRB1bis at the moment and phyConfigDedicated
903 904 905 906 907 908
 rrcConnectionSetup_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r13.radioResourceConfigDedicated_r13.srb_ToAddModList_r13 = *SRB_configList_NB_IoT;
 rrcConnectionSetup_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r13.radioResourceConfigDedicated_r13.drb_ToAddModList_r13 = NULL;
 rrcConnectionSetup_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r13.radioResourceConfigDedicated_r13.drb_ToReleaseList_r13 = NULL;
 rrcConnectionSetup_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r13.radioResourceConfigDedicated_r13.rlf_TimersAndConstants_r13 = NULL;
 rrcConnectionSetup_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r13.radioResourceConfigDedicated_r13.physicalConfigDedicated_r13 = physicalConfigDedicated2_NB_IoT;
 rrcConnectionSetup_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r13.radioResourceConfigDedicated_r13.mac_MainConfig_r13 = NULL;
909 910 911 912 913

#ifdef XER_PRINT
 xer_fprint(stdout, &asn_DEF_DL_CCCH_Message, (void*)&dl_ccch_msg);
#endif
 enc_rval = uper_encode_to_buffer(&asn_DEF_DL_CCCH_Message_NB,
914
                                  (void*)&dl_ccch_msg_NB_IoT,
915 916 917 918 919 920 921 922 923 924 925 926 927 928 929
                                  buffer,
                                  100);
 AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n",
              enc_rval.failed_type->name, enc_rval.encoded);


#ifdef USER_MODE
 LOG_D(RRC,"RRCConnectionSetup-NB Encoded %d bits (%d bytes), ecause %d\n",
       enc_rval.encoded,(enc_rval.encoded+7)/8,ecause);
#endif

 return((enc_rval.encoded+7)/8);
}

/*do_SecurityModeCommand - exactly the same as previous implementation*/
930
uint8_t do_SecurityModeCommand_NB_IoT(
931 932 933 934 935 936
  const protocol_ctxt_t* const ctxt_pP,
  uint8_t* const buffer,
  const uint8_t Transaction_id,
  const uint8_t cipheringAlgorithm,
  const uint8_t integrityProtAlgorithm)
{
937
  DL_DCCH_Message_NB_t dl_dcch_msg_NB_IoT;
938 939
  asn_enc_rval_t enc_rval;

940
  memset(&dl_dcch_msg_NB_IoT,0,sizeof(DL_DCCH_Message_NB_t));
941

942 943
  dl_dcch_msg_NB_IoT.message.present = DL_DCCH_MessageType_NB_PR_c1;
  dl_dcch_msg_NB_IoT.message.choice.c1.present = DL_DCCH_MessageType_NB__c1_PR_securityModeCommand_r13;
944

945 946
  dl_dcch_msg_NB_IoT.message.choice.c1.choice.securityModeCommand_r13.rrc_TransactionIdentifier = Transaction_id;
  dl_dcch_msg_NB_IoT.message.choice.c1.choice.securityModeCommand_r13.criticalExtensions.present = SecurityModeCommand__criticalExtensions_PR_c1;
947

948
  dl_dcch_msg_NB_IoT.message.choice.c1.choice.securityModeCommand_r13.criticalExtensions.choice.c1.present =
949 950 951
		  SecurityModeCommand__criticalExtensions__c1_PR_securityModeCommand_r8;

  // the two following information could be based on the mod_id
952
  dl_dcch_msg_NB_IoT.message.choice.c1.choice.securityModeCommand_r13.criticalExtensions.choice.c1.choice.securityModeCommand_r8.securityConfigSMC.securityAlgorithmConfig.cipheringAlgorithm
953 954
    = (CipheringAlgorithm_r12_t)cipheringAlgorithm; //bug solved

955
  dl_dcch_msg_NB_IoT.message.choice.c1.choice.securityModeCommand_r13.criticalExtensions.choice.c1.choice.securityModeCommand_r8.securityConfigSMC.securityAlgorithmConfig.integrityProtAlgorithm
956 957 958 959
    = (e_SecurityAlgorithmConfig__integrityProtAlgorithm)integrityProtAlgorithm;

//only changed "asn_DEF_DL_DCCH_Message_NB"
#ifdef XER_PRINT
960
  xer_fprint(stdout, &asn_DEF_DL_DCCH_Message_NB, (void*)&dl_dcch_msg_NB_IoT);
961 962
#endif
  enc_rval = uper_encode_to_buffer(&asn_DEF_DL_DCCH_Message_NB,
963
                                   (void*)&dl_dcch_msg_NB_IoT,
964 965 966 967
                                   buffer,
                                   100);
  AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n",
               enc_rval.failed_type->name, enc_rval.encoded);
968

969

970 971
//#if defined(ENABLE_ITTI)
//# if !defined(DISABLE_XER_SPRINT)....
972 973

#ifdef USER_MODE
974
  LOG_D(RRC,"[eNB %d] securityModeCommand-NB for UE %x Encoded %d bits (%d bytes)\n",
975 976 977 978 979 980 981
        ctxt_pP->module_id,
        ctxt_pP->rnti,
        enc_rval.encoded,
        (enc_rval.encoded+7)/8);
#endif

  if (enc_rval.encoded==-1) {
982
    LOG_E(RRC,"[eNB %d] ASN1 : securityModeCommand-NB encoding failed for UE %x\n",
983 984 985 986 987 988 989 990
          ctxt_pP->module_id,
          ctxt_pP->rnti);
    return(-1);
  }

  return((enc_rval.encoded+7)/8);
}

991 992
/*do_UECapabilityEnquiry_NB_IoT - very similar to legacy lte*/
uint8_t do_UECapabilityEnquiry_NB_IoT(
993 994 995 996 997 998 999
  const protocol_ctxt_t* const ctxt_pP,
  uint8_t*               const buffer,
  const uint8_t                Transaction_id
)

{

1000
  DL_DCCH_Message_NB_t dl_dcch_msg_NB_IoT;
1001 1002 1003
  //no RAT type in NB-IoT
  asn_enc_rval_t enc_rval;

1004
  memset(&dl_dcch_msg_NB_IoT,0,sizeof(DL_DCCH_Message_NB_t));
1005

1006 1007
  dl_dcch_msg_NB_IoT.message.present           = DL_DCCH_MessageType_NB_PR_c1;
  dl_dcch_msg_NB_IoT.message.choice.c1.present = DL_DCCH_MessageType_NB__c1_PR_ueCapabilityEnquiry_r13;
1008

1009
  dl_dcch_msg_NB_IoT.message.choice.c1.choice.ueCapabilityEnquiry_r13.rrc_TransactionIdentifier = Transaction_id;
1010

1011 1012
  dl_dcch_msg_NB_IoT.message.choice.c1.choice.ueCapabilityEnquiry_r13.criticalExtensions.present = UECapabilityEnquiry_NB__criticalExtensions_PR_c1;
  dl_dcch_msg_NB_IoT.message.choice.c1.choice.ueCapabilityEnquiry_r13.criticalExtensions.choice.c1.present =
1013 1014 1015 1016 1017 1018
		  UECapabilityEnquiry_NB__criticalExtensions__c1_PR_ueCapabilityEnquiry_r13;

  //no ue_CapabilityRequest (list of RAT_Type)

//only changed "asn_DEF_DL_DCCH_Message_NB"
#ifdef XER_PRINT
1019
  xer_fprint(stdout, &asn_DEF_DL_DCCH_Message_NB, (void*)&dl_dcch_msg_NB_IoT);
1020 1021
#endif
  enc_rval = uper_encode_to_buffer(&asn_DEF_DL_DCCH_Message_NB,
1022
                                   (void*)&dl_dcch_msg_NB_IoT,
1023 1024 1025 1026 1027
                                   buffer,
                                   100);
  AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n",
               enc_rval.failed_type->name, enc_rval.encoded);

1028 1029
//#if defined(ENABLE_ITTI)
//# if !defined(DISABLE_XER_SPRINT)....
1030 1031

#ifdef USER_MODE
1032
  LOG_D(RRC,"[eNB %d] UECapabilityEnquiry-NB for UE %x Encoded %d bits (%d bytes)\n",
1033 1034 1035 1036 1037 1038 1039
        ctxt_pP->module_id,
        ctxt_pP->rnti,
        enc_rval.encoded,
        (enc_rval.encoded+7)/8);
#endif

  if (enc_rval.encoded==-1) {
1040
    LOG_E(RRC,"[eNB %d] ASN1 : UECapabilityEnquiry-NB encoding failed for UE %x\n",
1041 1042 1043 1044 1045 1046 1047 1048
          ctxt_pP->module_id,
          ctxt_pP->rnti);
    return(-1);
  }

  return((enc_rval.encoded+7)/8);
}

1049
/*do_RRCConnectionReconfiguration_NB_IoT-->may convey information for resource configuration
1050 1051
 * (including RBs, MAC main configuration and physical channel configuration)
 * including any associated dedicated NAS information.*/
1052
uint16_t do_RRCConnectionReconfiguration_NB_IoT(
1053 1054 1055
  const protocol_ctxt_t*        const ctxt_pP,
    uint8_t                            *buffer,
    uint8_t                             Transaction_id,
1056
    SRB_ToAddModList_NB_r13_t          *SRB1_list_NB, //SRB_ConfigList2 (default)--> only SRB1
1057 1058 1059
    DRB_ToAddModList_NB_r13_t          *DRB_list_NB_IoT, //DRB_ConfigList (default)
    DRB_ToReleaseList_NB_r13_t         *DRB_list2_NB_IoT, //is NULL when passed
    struct PhysicalConfigDedicated_NB_r13     *physicalConfigDedicated_NB_IoT,
1060
	MAC_MainConfig_NB_r13_t                   *mac_MainConfig_NB_IoT,
1061
  struct RRCConnectionReconfiguration_NB_r13_IEs__dedicatedInfoNASList_r13* dedicatedInfoNASList_NB_IoT)
1062 1063 1064 1065 1066 1067

{

 //check on DRB_list if contains more than 2 DRB?

  asn_enc_rval_t enc_rval;
1068
  DL_DCCH_Message_NB_t dl_dcch_msg_NB_IoT;
1069 1070 1071
  RRCConnectionReconfiguration_NB_t *rrcConnectionReconfiguration_NB;


1072
  memset(&dl_dcch_msg_NB_IoT,0,sizeof(DL_DCCH_Message_NB_t));
1073

1074 1075 1076
  dl_dcch_msg_NB_IoT.message.present           = DL_DCCH_MessageType_NB_PR_c1;
  dl_dcch_msg_NB_IoT.message.choice.c1.present = DL_DCCH_MessageType_NB__c1_PR_rrcConnectionReconfiguration_r13;
  rrcConnectionReconfiguration_NB          = &dl_dcch_msg_NB_IoT.message.choice.c1.choice.rrcConnectionReconfiguration_r13;
1077 1078 1079 1080 1081 1082 1083 1084 1085

  // RRCConnectionReconfiguration
  rrcConnectionReconfiguration_NB->rrc_TransactionIdentifier = Transaction_id;
  rrcConnectionReconfiguration_NB->criticalExtensions.present = RRCConnectionReconfiguration_NB__criticalExtensions_PR_c1;
  rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.present =RRCConnectionReconfiguration_NB__criticalExtensions__c1_PR_rrcConnectionReconfiguration_r13 ;

  //RAdioResourceconfigDedicated
  rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13 =
		  CALLOC(1,sizeof(*rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13));
1086
  rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->srb_ToAddModList_r13 = SRB1_list_NB; //only SRB1
1087 1088 1089
  rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->drb_ToAddModList_r13 = DRB_list_NB_IoT;
  rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->drb_ToReleaseList_r13 = DRB_list2_NB_IoT; //NULL
  rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->physicalConfigDedicated_r13 = physicalConfigDedicated_NB_IoT;
1090
  //FIXME may not used now
1091 1092
  //rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->rlf_TimersAndConstants_r13

1093
  if (mac_MainConfig_NB_IoT!=NULL) {
1094 1095 1096 1097 1098 1099
    rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->mac_MainConfig_r13 =
    		CALLOC(1, sizeof(*rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->mac_MainConfig_r13));
    rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->mac_MainConfig_r13->present
      =RadioResourceConfigDedicated_NB_r13__mac_MainConfig_r13_PR_explicitValue_r13;
   //why memcopy only this one?
    memcpy(&rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->mac_MainConfig_r13->choice.explicitValue_r13,
1100
           mac_MainConfig_NB_IoT, sizeof(*mac_MainConfig_NB_IoT));
1101 1102 1103 1104 1105

  } else {
	  rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->mac_MainConfig_r13=NULL;
  }

1106
  //no measConfig, measIDlist
1107 1108
  //no mobilityControlInfo

1109
  rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.dedicatedInfoNASList_r13 = dedicatedInfoNASList_NB_IoT;
1110
  //mainly used for cell-reselection/handover purposes??
1111 1112 1113
  rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.fullConfig_r13 = NULL;

  enc_rval = uper_encode_to_buffer(&asn_DEF_DL_DCCH_Message_NB,
1114
                                   (void*)&dl_dcch_msg_NB_IoT,
1115 1116 1117 1118 1119 1120 1121
                                   buffer,
                                   RRC_BUF_SIZE);
  AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %l)!\n",
               enc_rval.failed_type->name, enc_rval.encoded);

  //changed only asn_DEF_DL_DCCH_Message_NB
#ifdef XER_PRINT
1122
  xer_fprint(stdout,&asn_DEF_DL_DCCH_Message_NB,(void*)&dl_dcch_msg_NB_IoT);
1123 1124
#endif

1125 1126
//#if defined(ENABLE_ITTI)
//# if !defined(DISABLE_XER_SPRINT)...
1127 1128 1129 1130 1131 1132 1133 1134


  LOG_I(RRC,"RRCConnectionReconfiguration-NB Encoded %d bits (%d bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8);

  return((enc_rval.encoded+7)/8);
}

/*do_RRCConnectionReestablishmentReject - exactly the same as legacy LTE*/
1135
uint8_t do_RRCConnectionReestablishmentReject_NB_IoT(
1136 1137 1138 1139 1140 1141
    uint8_t                    Mod_id,
    uint8_t*                   const buffer)
{

  asn_enc_rval_t enc_rval;

1142
  DL_CCCH_Message_NB_t dl_ccch_msg_NB_IoT;
1143 1144
  RRCConnectionReestablishmentReject_t *rrcConnectionReestablishmentReject;

1145 1146 1147 1148
  memset((void *)&dl_ccch_msg_NB_IoT,0,sizeof(DL_CCCH_Message_NB_t));
  dl_ccch_msg_NB_IoT.message.present = DL_CCCH_MessageType_NB_PR_c1;
  dl_ccch_msg_NB_IoT.message.choice.c1.present = DL_CCCH_MessageType_NB__c1_PR_rrcConnectionReestablishmentReject_r13;
  rrcConnectionReestablishmentReject    = &dl_ccch_msg_NB_IoT.message.choice.c1.choice.rrcConnectionReestablishmentReject_r13;
1149

1150
  // RRCConnectionReestablishmentReject //exactly the same as LTE
1151 1152 1153 1154
  rrcConnectionReestablishmentReject->criticalExtensions.present = RRCConnectionReestablishmentReject__criticalExtensions_PR_rrcConnectionReestablishmentReject_r8;

  //Only change in "asn_DEF_DL_CCCH_Message_NB"
#ifdef XER_PRINT
1155
  xer_fprint(stdout, &asn_DEF_DL_CCCH_Message_NB, (void*)&dl_ccch_msg_NB_IoT);
1156 1157
#endif
  enc_rval = uper_encode_to_buffer(&asn_DEF_DL_CCCH_Message_NB,
1158
                                   (void*)&dl_ccch_msg_NB_IoT,
1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170
                                   buffer,
                                   100);
  AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n",
               enc_rval.failed_type->name, enc_rval.encoded);

  //Only change in "asn_DEF_DL_CCCH_Message_NB"
#if defined(ENABLE_ITTI)
# if !defined(DISABLE_XER_SPRINT)
  {
    char        message_string[20000];
    size_t      message_string_size;

1171
    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_DL_CCCH_Message_NB, (void *) &dl_ccch_msg_NB_IoT)) > 0) {
1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191
      MessageDef *msg_p;

      msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB, RRC_DL_CCCH, message_string_size + sizeof (IttiMsgText));
      msg_p->ittiMsg.rrc_dl_ccch.size = message_string_size;
      memcpy(&msg_p->ittiMsg.rrc_dl_ccch.text, message_string, message_string_size);

      itti_send_msg_to_task(TASK_UNKNOWN, Mod_id, msg_p);
    }
  }
# endif
#endif

#ifdef USER_MODE
  LOG_D(RRC,"RRCConnectionReestablishmentReject Encoded %d bits (%d bytes)\n",
        enc_rval.encoded,(enc_rval.encoded+7)/8);
#endif

  return((enc_rval.encoded+7)/8);
}

1192 1193
/*do_RRCConnectionReject_NB_IoT*/
uint8_t do_RRCConnectionReject_NB_IoT(
1194 1195 1196 1197 1198 1199 1200
    uint8_t                    Mod_id,
    uint8_t*                   const buffer)

{

  asn_enc_rval_t enc_rval;

1201 1202
  DL_CCCH_Message_NB_t          dl_ccch_msg_NB_IoT;
  RRCConnectionReject_NB_t      *rrcConnectionReject_NB_IoT;
1203

1204 1205 1206 1207
  memset((void *)&dl_ccch_msg_NB_IoT,0,sizeof(DL_CCCH_Message_NB_t));
  dl_ccch_msg_NB_IoT.message.present           = DL_CCCH_MessageType_NB_PR_c1;
  dl_ccch_msg_NB_IoT.message.choice.c1.present = DL_CCCH_MessageType_NB__c1_PR_rrcConnectionReject_r13;
  rrcConnectionReject_NB_IoT = &dl_ccch_msg_NB_IoT.message.choice.c1.choice.rrcConnectionReject_r13;
1208

1209 1210 1211
  // RRCConnectionReject-NB_IoT
  rrcConnectionReject_NB_IoT->criticalExtensions.present = RRCConnectionReject_NB__criticalExtensions_PR_c1;
  rrcConnectionReject_NB_IoT->criticalExtensions.choice.c1.present = RRCConnectionReject_NB__criticalExtensions__c1_PR_rrcConnectionReject_r13;
1212
  /* let's put an extended wait time of 1s for the moment */
1213
  rrcConnectionReject_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReject_r13.extendedWaitTime_r13 = 1;
1214 1215
  //new-use of suspend indication
  //If present, this field indicates that the UE should remain suspended and not release its stored context.
1216
  rrcConnectionReject_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReject_r13.rrc_SuspendIndication_r13=
1217
		  CALLOC(1, sizeof(long));
1218
  *(rrcConnectionReject_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReject_r13.rrc_SuspendIndication_r13)=
1219 1220 1221 1222 1223 1224 1225
		  RRCConnectionReject_NB_r13_IEs__rrc_SuspendIndication_r13_true;

  //Only Modified "asn_DEF_DL_CCCH_Message_NB"
#ifdef XER_PRINT
  xer_fprint(stdout, &asn_DEF_DL_CCCH_Message_NB, (void*)&dl_ccch_msg);
#endif
  enc_rval = uper_encode_to_buffer(&asn_DEF_DL_CCCH_Message_NB,
1226
                                   (void*)&dl_ccch_msg_NB_IoT,
1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237
                                   buffer,
                                   100);
  AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %ld)!\n",
               enc_rval.failed_type->name, enc_rval.encoded);

#if defined(ENABLE_ITTI)
# if !defined(DISABLE_XER_SPRINT)
  {
    char        message_string[20000];
    size_t      message_string_size;

1238
    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_DL_CCCH_Message_NB, (void *) &dl_ccch_msg_NB_IoT)) > 0) {
1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263
      MessageDef *msg_p;

      msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB, RRC_DL_CCCH, message_string_size + sizeof (IttiMsgText));
      msg_p->ittiMsg.rrc_dl_ccch.size = message_string_size;
      memcpy(&msg_p->ittiMsg.rrc_dl_ccch.text, message_string, message_string_size);

      itti_send_msg_to_task(TASK_UNKNOWN, Mod_id, msg_p);
    }
  }
# endif
#endif

#ifdef USER_MODE
  LOG_D(RRC,"RRCConnectionReject-NB Encoded %d bits (%d bytes)\n",
        enc_rval.encoded,(enc_rval.encoded+7)/8);
#endif

  return((enc_rval.encoded+7)/8);
}


//no do_MBSFNAreaConfig(..) in NB-IoT
//no do_MeasurementReport(..) in NB-IoT

/*do_DLInformationTransfer_NB*/
1264
uint8_t do_DLInformationTransfer_NB_IoT(
1265 1266 1267 1268 1269 1270 1271 1272 1273
		uint8_t Mod_id,
		uint8_t **buffer,
		uint8_t transaction_id,
		uint32_t pdu_length,
		uint8_t *pdu_buffer)

{
  ssize_t encoded;

1274
  DL_DCCH_Message_NB_t dl_dcch_msg_NB_IoT;
1275

1276
  memset(&dl_dcch_msg_NB_IoT, 0, sizeof(DL_DCCH_Message_NB_t));
1277

1278 1279 1280 1281 1282 1283 1284
  dl_dcch_msg_NB_IoT.message.present           = DL_DCCH_MessageType_NB_PR_c1;
  dl_dcch_msg_NB_IoT.message.choice.c1.present = DL_DCCH_MessageType_NB__c1_PR_dlInformationTransfer_r13;
  dl_dcch_msg_NB_IoT.message.choice.c1.choice.dlInformationTransfer_r13.rrc_TransactionIdentifier = transaction_id;
  dl_dcch_msg_NB_IoT.message.choice.c1.choice.dlInformationTransfer_r13.criticalExtensions.present = DLInformationTransfer_NB__criticalExtensions_PR_c1;
  dl_dcch_msg_NB_IoT.message.choice.c1.choice.dlInformationTransfer_r13.criticalExtensions.choice.c1.present = DLInformationTransfer_NB__criticalExtensions__c1_PR_dlInformationTransfer_r13;
  dl_dcch_msg_NB_IoT.message.choice.c1.choice.dlInformationTransfer_r13.criticalExtensions.choice.c1.choice.dlInformationTransfer_r13.dedicatedInfoNAS_r13.size = pdu_length;
  dl_dcch_msg_NB_IoT.message.choice.c1.choice.dlInformationTransfer_r13.criticalExtensions.choice.c1.choice.dlInformationTransfer_r13.dedicatedInfoNAS_r13.buf = pdu_buffer;
1285

1286
  encoded = uper_encode_to_new_buffer (&asn_DEF_DL_DCCH_Message_NB, NULL, (void*) &dl_dcch_msg_NB_IoT, (void **) buffer);
1287 1288 1289 1290 1291 1292 1293 1294

  //only change in "asn_DEF_DL_DCCH_Message_NB"
#if defined(ENABLE_ITTI)
# if !defined(DISABLE_XER_SPRINT)
  {
    char        message_string[10000];
    size_t      message_string_size;

1295
    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_DL_DCCH_Message_NB, (void *)&dl_dcch_msg_NB_IoT)) > 0) {
1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315
      MessageDef *msg_p;

      msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB, RRC_DL_DCCH, message_string_size + sizeof (IttiMsgText));
      msg_p->ittiMsg.rrc_dl_dcch.size = message_string_size;
      memcpy(&msg_p->ittiMsg.rrc_dl_dcch.text, message_string, message_string_size);

      itti_send_msg_to_task(TASK_UNKNOWN, Mod_id, msg_p);
    }
  }
# endif
#endif

  return encoded;
}

/*do_ULInformationTransfer*/
//for the moment is not needed (UE-SIDE)

/*OAI_UECapability_t *fill_ue_capability*/

1316
/*do_RRCConnectionReestablishment_NB-->used to re-establish SRB1*/ //which parameter to use?
1317
uint8_t do_RRCConnectionReestablishment_NB_IoT(
1318 1319 1320
		uint8_t Mod_id,
		uint8_t* const buffer,
		const uint8_t     Transaction_id,
1321
		const NB_IoT_DL_FRAME_PARMS* const frame_parms, //to be changed
1322
		SRB_ToAddModList_NB_r13_t*      SRB_list_NB_IoT) //should contain SRB1 already configured?
1323 1324 1325
{

	asn_enc_rval_t enc_rval;
1326
	DL_CCCH_Message_NB_t dl_ccch_msg_NB_IoT;
1327
	RRCConnectionReestablishment_NB_t* rrcConnectionReestablishment_NB_IoT;
1328

1329
	memset(&dl_ccch_msg_NB_IoT, 0, sizeof(DL_CCCH_Message_NB_t));
1330

1331 1332
	dl_ccch_msg_NB_IoT.message.present = DL_CCCH_MessageType_NB_PR_c1;
	dl_ccch_msg_NB_IoT.message.choice.c1.present = DL_CCCH_MessageType_NB__c1_PR_rrcConnectionReestablishment_r13;
1333
	rrcConnectionReestablishment_NB_IoT = &dl_ccch_msg_NB_IoT.message.choice.c1.choice.rrcConnectionReestablishment_r13;
1334 1335

	//rrcConnectionReestablishment_NB
1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347
	rrcConnectionReestablishment_NB_IoT->rrc_TransactionIdentifier = Transaction_id;
	rrcConnectionReestablishment_NB_IoT->criticalExtensions.present = RRCConnectionReestablishment_NB__criticalExtensions_PR_c1;
	rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.present = RRCConnectionReestablishment_NB__criticalExtensions__c1_PR_rrcConnectionReestablishment_r13;

	rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r13.radioResourceConfigDedicated_r13.srb_ToAddModList_r13 = SRB_list_NB_IoT;
	rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r13.radioResourceConfigDedicated_r13.drb_ToAddModList_r13 = NULL;
	rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r13.radioResourceConfigDedicated_r13.drb_ToReleaseList_r13 = NULL;
	rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r13.radioResourceConfigDedicated_r13.rlf_TimersAndConstants_r13= NULL;
	rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r13.radioResourceConfigDedicated_r13.mac_MainConfig_r13= NULL;
	rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r13.radioResourceConfigDedicated_r13.physicalConfigDedicated_r13 = NULL;

	rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r13.nextHopChainingCount_r13=0;
1348 1349

	enc_rval = uper_encode_to_buffer(&asn_DEF_DL_CCCH_Message_NB,
1350
	                                   (void*)&dl_ccch_msg_NB_IoT,
1351 1352 1353 1354 1355 1356 1357
	                                   buffer,
	                                   RRC_BUF_SIZE);

	 AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %l)!\n",
	               enc_rval.failed_type->name, enc_rval.encoded);

#ifdef XER_PRINT
1358
  xer_fprint(stdout,&asn_DEF_DL_CCCH_Message_NB,(void*)&dl_ccch_msg_NB_IoT);
1359 1360 1361 1362 1363 1364 1365 1366
#endif

#if defined(ENABLE_ITTI)
# if !defined(DISABLE_XER_SPRINT)
  {
    char        message_string[30000];
    size_t      message_string_size;

1367
    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_DL_CCCH_Message_NB, (void *) &dl_ccch_msg_NB_IoT)) > 0) {
1368 1369 1370 1371 1372 1373
      MessageDef *msg_p;

      msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB, RRC_DL_CCCH, message_string_size + sizeof (IttiMsgText));
      msg_p->ittiMsg.rrc_dl_ccch.size = message_string_size;
      memcpy(&msg_p->ittiMsg.rrc_dl_ccch.text, message_string, message_string_size);

1374
      itti_send_msg_to_task(TASK_UNKNOWN, Mod_id, msg_p);
1375 1376 1377 1378 1379 1380 1381 1382 1383
    }
  }
# endif
#endif

  LOG_I(RRC,"RRCConnectionReestablishment-NB Encoded %d bits (%d bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8);

}

1384
/*do_RRCConnectionRelease_NB--> is used to command the release of an RRC connection*/
1385
uint8_t do_RRCConnectionRelease_NB_IoT(
1386 1387
  uint8_t                             Mod_id,
  uint8_t                            *buffer,
1388
 const uint8_t                             Transaction_id)
1389 1390 1391 1392
{

  asn_enc_rval_t enc_rval;

1393 1394
  DL_DCCH_Message_NB_t dl_dcch_msg_NB_IoT;
  RRCConnectionRelease_NB_t *rrcConnectionRelease_NB_IoT;
1395 1396


1397
  memset(&dl_dcch_msg_NB_IoT,0,sizeof(DL_DCCH_Message_NB_t));
1398

1399 1400 1401
  dl_dcch_msg_NB_IoT.message.present           = DL_DCCH_MessageType_NB_PR_c1;
  dl_dcch_msg_NB_IoT.message.choice.c1.present = DL_DCCH_MessageType_NB__c1_PR_rrcConnectionRelease_r13;
  rrcConnectionRelease_NB_IoT                  = &dl_dcch_msg_NB_IoT.message.choice.c1.choice.rrcConnectionRelease_r13;
1402 1403

  // RRCConnectionRelease
1404 1405 1406
  rrcConnectionRelease_NB_IoT->rrc_TransactionIdentifier = Transaction_id;
  rrcConnectionRelease_NB_IoT->criticalExtensions.present = RRCConnectionRelease_NB__criticalExtensions_PR_c1;
  rrcConnectionRelease_NB_IoT->criticalExtensions.choice.c1.present =RRCConnectionRelease_NB__criticalExtensions__c1_PR_rrcConnectionRelease_r13 ;
1407

1408 1409 1410
  rrcConnectionRelease_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionRelease_r13.releaseCause_r13 = ReleaseCause_NB_r13_other;
  rrcConnectionRelease_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionRelease_r13.redirectedCarrierInfo_r13 = NULL;
  rrcConnectionRelease_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionRelease_r13.extendedWaitTime_r13 = NULL;
1411 1412

  //Why allocate memory for non critical extension?
1413 1414
  rrcConnectionRelease_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionRelease_r13.nonCriticalExtension=CALLOC(1,
      sizeof(*rrcConnectionRelease_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionRelease_r13.nonCriticalExtension));
1415 1416

  enc_rval = uper_encode_to_buffer(&asn_DEF_DL_DCCH_Message_NB,
1417
                                   (void*)&dl_dcch_msg_NB_IoT,
1418 1419 1420 1421 1422 1423
                                   buffer,
                                   RRC_BUF_SIZE);//check

  return((enc_rval.encoded+7)/8);
}

1424 1425 1426

// -----??????--------------------
#ifndef USER_MODE
1427
int init_module_NB_IoT(void)
1428 1429 1430 1431 1432 1433 1434 1435
{
  printk("Init asn1_msg_nb_iot module\n");

  // A non 0 return means init_module failed; module can't be loaded.
  return 0;
}


1436
void cleanup_module_NB_IoT(void)
1437 1438 1439 1440
{
  printk("Stopping asn1_msg_nb_iot module\n");
}

1441 1442 1443 1444 1445 1446 1447 1448
EXPORT_SYMBOL(do_SIB1_NB_IoT);
EXPORT_SYMBOL(do_SIB23_NB_IoT);
EXPORT_SYMBOL(do_RRCConnectionRequest_NB_IoT);
EXPORT_SYMBOL(do_RRCConnectionSetupComplete_NB_IoT);
EXPORT_SYMBOL(do_RRCConnectionReconfigurationComplete_NB_IoT);
EXPORT_SYMBOL(do_RRCConnectionSetup_NB_IoT);
EXPORT_SYMBOL(do_RRCConnectionReestablishmentReject_NB_IoT);
EXPORT_SYMBOL(do_RRCConnectionReconfiguration_NB_IoT);
1449 1450
EXPORT_SYMBOL(asn_DEF_UL_DCCH_Message_NB);
EXPORT_SYMBOL(asn_DEF_UL_CCCH_Message_NB);
1451
EXPORT_SYMBOL(asn_DEF_SystemInformation_NB_IoT);
1452
EXPORT_SYMBOL(asn_DEF_DL_DCCH_Message_NB);
1453
EXPORT_SYMBOL(asn_DEF_SystemInformationBlockType1_NB_IoT);
1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464
EXPORT_SYMBOL(asn_DEF_DL_CCCH_Message_NB);
EXPORT_SYMBOL(uper_decode_complete);
EXPORT_SYMBOL(uper_decode);
EXPORT_SYMBOL(transmission_mode_rrc);
#endif

//----------------------------------