asn1_msg_NB_IoT.c 80.5 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(
Matthieu Kanj's avatar
Matthieu Kanj committed
98 99 100
    rrc_eNB_carrier_data_NB_IoT_t *carrier,
    uint16_t N_RB_DL,//may not needed--> for NB_IoT only 1 PRB is used
    uint32_t frame,
101
    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
  /*
   * 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
Nick Ho's avatar
Nick Ho committed
109
   * NOTE: 6 LSB will be used for counting the 64  frames in the TTI period (640 ms) that is exactly the MIB period
110 111 112 113 114 115 116 117
   *
   * 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!!??
   */
Matthieu Kanj's avatar
Matthieu Kanj committed
118 119
//printf("Frame   %d",frame);
//printf("HFN  %d",hyper_frame);
120
  //XXX check if correct the bit assignment
Matthieu Kanj's avatar
Matthieu Kanj committed
121 122
  uint8_t sfn_MSB = (uint8_t)((frame>>2) & 0xf0);//(uint8_t)((frame>>6) & 0x0f); // all the 4 bits are set to 1
  uint8_t hsfn_LSB = (uint8_t)((hyper_frame<<6) & 0xc0);///(uint8_t)(hyper_frame & 0x03); //2 bits set to 1 (0x3 = 0011)
123
  uint16_t spare=0; //11 bits --> use uint16
Matthieu Kanj's avatar
Matthieu Kanj committed
124 125
//printf("Frame   %d",sfn_MSB);
//printf("HFN  %d",hsfn_LSB);
126

127 128 129
  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
130

131 132 133
  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;
134

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

  //decide how to set it
Matthieu Kanj's avatar
Matthieu Kanj committed
141
  mib_NB_IoT->message.schedulingInfoSIB1_r13 =10; //see TS 36.213-->tables 16.4.1.3-3 ecc...  // to make 8 repetitions
142
  mib_NB_IoT->message.systemInfoValueTag_r13= 0;
143
  mib_NB_IoT->message.ab_Enabled_r13 = 0;
144 145

  //to be decided
146
  mib_NB_IoT->message.operationModeInfo_r13.present = MasterInformationBlock_NB__operationModeInfo_r13_PR_inband_SamePCI_r13;
Matthieu Kanj's avatar
Matthieu Kanj committed
147
  mib_NB_IoT->message.operationModeInfo_r13.choice.inband_SamePCI_r13.eutra_CRS_SequenceInfo_r13 = 8;      /// TODO: take into account RB_index of NB-IoT
148

Matthieu Kanj's avatar
Matthieu Kanj committed
149 150 151
 // printf("[MIB] Intialization of frame information ,sfn_MSB %x, hsfn_LSB %x\n",
 //        (uint32_t)sfn_MSB,
//     (uint32_t)hsfn_LSB);
152 153

  enc_rval = uper_encode_to_buffer(&asn_DEF_BCCH_BCH_Message_NB,
154
                                   (void*)mib_NB_IoT,
155
                                   carrier->MIB_NB_IoT,
156 157 158 159 160 161 162 163 164
                                   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);
165

166 167 168
}

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

  asn_enc_rval_t enc_rval;

181
  PLMN_IdentityInfo_NB_r13_t PLMN_identity_info_NB_IoT;
182
  MCC_MNC_Digit_t dummy_mcc[3],dummy_mnc[3];
Nick Ho's avatar
Nick Ho committed
183 184
  SchedulingInfo_NB_r13_t schedulingInfo_NB_IoT;
  SIB_Type_NB_r13_t sib_type_NB_IoT;
185

186

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

195 196 197
  long *offset=NULL; //this parameter should be set only if we are considering in-band operating mode (samePCI or differentPCI)
  offset = CALLOC(1,sizeof(long));

198 199 200
  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
201 202 203
  
  memset(&schedulingInfo_NB_IoT,0,sizeof(SchedulingInfo_NB_r13_t));
  memset(&sib_type_NB_IoT,0,sizeof(SIB_Type_NB_r13_t));
204
  //allocation
205
  *sib1_NB_IoT = &bcch_message->message.choice.c1.choice.systemInformationBlockType1_r13;
206

207 208 209 210 211 212 213 214

  /*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);

215
  //XXX to be checked
216 217 218
  (*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;
219

220
  memset(&PLMN_identity_info_NB_IoT,0,sizeof(PLMN_IdentityInfo_NB_r13_t));
221

222 223
  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));
224

225
  asn_set_empty(&PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc->list);//.size=0;
226 227 228 229 230 231 232 233 234 235 236

  //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
237 238 239
  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]);
240

241 242
  PLMN_identity_info_NB_IoT.plmn_Identity_r13.mnc.list.size=0;
  PLMN_identity_info_NB_IoT.plmn_Identity_r13.mnc.list.count=0;
243

244

245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
#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
268 269
  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]);
270 271

  if (dummy_mnc[2] != 0xf) {
272
    ASN_SEQUENCE_ADD(&PLMN_identity_info_NB_IoT.plmn_Identity_r13.mnc.list,&dummy_mnc[2]);
273 274 275
  }

  //still set to "notReserved" as in the previous case
276
  PLMN_identity_info_NB_IoT.cellReservedForOperatorUse_r13=PLMN_IdentityInfo_NB_r13__cellReservedForOperatorUse_r13_notReserved;
277 278

  *attachWithoutPDN_Connectivity = 0;
279
  PLMN_identity_info_NB_IoT.attachWithoutPDN_Connectivity_r13 = attachWithoutPDN_Connectivity;
280

281
  ASN_SEQUENCE_ADD(&(*sib1_NB_IoT)->cellAccessRelatedInfo_r13.plmn_IdentityList_r13.list,&PLMN_identity_info_NB_IoT);
282 283

  // 16 bits = 2 byte
284
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.buf = MALLOC(2); //MALLOC works in byte
285 286 287

  //lefts as it is?
#if defined(ENABLE_ITTI)
288 289
  (*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;
290
#else
291 292
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.buf[0] = 0x00;
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.buf[1] = 0x01;
293
#endif
294 295
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.size=2;
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.bits_unused=0;
296 297

  // 28 bits --> i have to use 32 bits = 4 byte
298
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf = MALLOC(8); // why allocate 8 byte?
299
#if defined(ENABLE_ITTI)
300 301 302 303
  (*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;
304
#else
305 306 307 308
  (*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;
309
#endif
310 311
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.size=4;
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.bits_unused=4;
312 313

  //Still set to "notBarred" as in the previous case
314
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellBarred_r13=SystemInformationBlockType1_NB__cellAccessRelatedInfo_r13__cellBarred_r13_notBarred;
315 316

  //Still Set to "notAllowed" like in the previous case
317
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.intraFreqReselection_r13=SystemInformationBlockType1_NB__cellAccessRelatedInfo_r13__intraFreqReselection_r13_notAllowed;
318 319


320
  (*sib1_NB_IoT)->cellSelectionInfo_r13.q_RxLevMin_r13=-65; //which value?? TS 36.331 V14.2.1 pag. 589
Nick Ho's avatar
Nick Ho committed
321
  (*sib1_NB_IoT)->cellSelectionInfo_r13.q_QualMin_r13 =-22; //FIXME new parameter for SIB1-NB, not present in SIB1 (for cell reselection but if not used the UE should apply the default value)
322

323 324
  (*sib1_NB_IoT)->p_Max_r13 = CALLOC(1, sizeof(P_Max_t));
  *((*sib1_NB_IoT)->p_Max_r13) = 23;
325

326
  //FIXME
327
  (*sib1_NB_IoT)->freqBandIndicator_r13 =
328
#if defined(ENABLE_ITTI)
Nick Ho's avatar
Nick Ho committed
329
    configuration->eutra_band[CC_id];
330
#else
331
    5; //if not configured we use band 5 (UL: 824 MHz - 849MHz / DL: 869 MHz - 894 MHz  FDD mode)
332 333
#endif

334 335 336

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

Matthieu Kanj's avatar
SIB23  
Matthieu Kanj committed
338
  schedulingInfo_NB_IoT.si_Periodicity_r13=  SchedulingInfo_NB_r13__si_Periodicity_r13_rf64; //SchedulingInfo_NB_r13__si_Periodicity_r13_rf4096; // (to be set to 64)
339
  schedulingInfo_NB_IoT.si_RepetitionPattern_r13=  SchedulingInfo_NB_r13__si_RepetitionPattern_r13_every4thRF; //This Indicates the starting radio frames within the SI window used for SI message transmission.
Nick Ho's avatar
Nick Ho committed
340
  schedulingInfo_NB_IoT.si_TB_r13= SchedulingInfo_NB_r13__si_TB_r13_b680;//208 bits
341
  
342 343 344 345 346 347

  // 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
348
  sib_type_NB_IoT=SIB_Type_NB_r13_sibType3_NB_r13;
349

Nick Ho's avatar
Nick Ho committed
350 351
  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);
352 353

  //printf("[ASN Debug] SI P: %ld\n",(*sib1_NB_IoT)->schedulingInfoList_r13.list.array[0]->si_Periodicity_r13);
354 355 356 357 358 359

#if defined(ENABLE_ITTI)

  if (configuration->frame_type[CC_id] == TDD)
#endif
  {
360 361 362
  //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);
363 364
  }

365 366
  //FIXME which value chose for the following parameter
  *offset =1;
367
  //FIXME which value chose for the following parameter
368
  (*sib1_NB_IoT)->si_WindowLength_r13=SystemInformationBlockType1_NB__si_WindowLength_r13_ms160;
369
  (*sib1_NB_IoT)->si_RadioFrameOffset_r13=offset;
370

Nick Ho's avatar
Nick Ho committed
371 372 373
  /////optional parameters, decide to use at future
  /*
  //system value tag
374 375 376
  (*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);
Nick Ho's avatar
Nick Ho committed
377 378 379 380 381 382 383
  // downlink bitmap
  (*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;
  // CRS power offset
  *nrs_CRS_PowerOffset= 0;
  (*sib1_NB_IoT)->nrs_CRS_PowerOffset_r13 = nrs_CRS_PowerOffset;
  */
Matthieu Kanj's avatar
Matthieu Kanj committed
384
    *eutraControlRegionSize = 2;
Nick Ho's avatar
Nick Ho committed
385
   (*sib1_NB_IoT)->eutraControlRegionSize_r13 = eutraControlRegionSize;
386 387 388 389
#ifdef XER_PRINT //generate xml files
  xer_fprint(stdout, &asn_DEF_BCCH_DL_SCH_Message_NB, (void*)bcch_message);
#endif

390
  //bcch_message->message.choice.c1.choice.systemInformationBlockType1_r13 = **sib1_NB_IoT;
391 392
  enc_rval = uper_encode_to_buffer(&asn_DEF_BCCH_DL_SCH_Message_NB,
                                   (void*)bcch_message,
393
                                   carrier->SIB1_NB_IoT,
394 395
                                   100);

Nick Ho's avatar
Nick Ho committed
396
  AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n",
397 398 399 400 401 402 403 404 405
               enc_rval.failed_type->name, enc_rval.encoded);

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

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

Matthieu Kanj's avatar
SIB23  
Matthieu Kanj committed
406 407 408
/*do_SIB1_NB*/
uint8_t do_SIB1_NB_IoT_x(uint8_t Mod_id, int CC_id,
        rrc_eNB_carrier_data_NB_IoT_t *carrier,
409 410 411 412 413 414 415
        uint16_t mcc,
        uint16_t mnc,
        uint16_t tac,
        uint32_t cell_identity,
        uint16_t band,
        uint16_t mnc_digit_length,
        uint32_t frame)
Matthieu Kanj's avatar
SIB23  
Matthieu Kanj committed
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436
{
  BCCH_DL_SCH_Message_NB_t *bcch_message= &(carrier->siblock1_NB_IoT);
  SystemInformationBlockType1_NB_t **sib1_NB_IoT= &(carrier->sib1_NB_IoT);
  

  asn_enc_rval_t enc_rval;

  PLMN_IdentityInfo_NB_r13_t PLMN_identity_info_NB_IoT;
  MCC_MNC_Digit_t dummy_mcc[3],dummy_mnc[3];
  SchedulingInfo_NB_r13_t schedulingInfo_NB_IoT;
  SIB_Type_NB_r13_t sib_type_NB_IoT;


  long* attachWithoutPDN_Connectivity = NULL;
  attachWithoutPDN_Connectivity = CALLOC(1,sizeof(long));
  long *nrs_CRS_PowerOffset=NULL;
  nrs_CRS_PowerOffset = CALLOC(1, sizeof(long));
  long *eutraControlRegionSize=NULL; //this parameter should be set only if we are considering in-band operating mode (samePCI or differentPCI)
   eutraControlRegionSize = CALLOC(1,sizeof(long));
  long systemInfoValueTagSI = 0;

437 438 439
  long *offset=NULL; //this parameter should be set only if we are considering in-band operating mode (samePCI or differentPCI)
  offset = CALLOC(1,sizeof(long));

Matthieu Kanj's avatar
SIB23  
Matthieu Kanj committed
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579
  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;
  
  memset(&schedulingInfo_NB_IoT,0,sizeof(SchedulingInfo_NB_r13_t));
  memset(&sib_type_NB_IoT,0,sizeof(SIB_Type_NB_r13_t));
  //allocation
  *sib1_NB_IoT = &bcch_message->message.choice.c1.choice.systemInformationBlockType1_r13;


  /*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);

  //XXX to be checked
  (*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;

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

  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));

  asn_set_empty(&PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc->list);//.size=0;

  //left as it is???
#if defined(ENABLE_ITTI)
  dummy_mcc[0] = (mcc / 100) % 10;
  dummy_mcc[1] = (mcc / 10) % 10;
  dummy_mcc[2] = (mcc / 1) % 10;
#else
  dummy_mcc[0] = 0;
  dummy_mcc[1] = 0;
  dummy_mcc[2] = 1;
#endif
  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]);

  PLMN_identity_info_NB_IoT.plmn_Identity_r13.mnc.list.size=0;
  PLMN_identity_info_NB_IoT.plmn_Identity_r13.mnc.list.count=0;


#if defined(ENABLE_ITTI)

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

#else
  dummy_mnc[0] = 0;
  dummy_mnc[1] = 1;
  dummy_mnc[2] = 0xf;
#endif
  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]);

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

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

  *attachWithoutPDN_Connectivity = 0;
  PLMN_identity_info_NB_IoT.attachWithoutPDN_Connectivity_r13 = attachWithoutPDN_Connectivity;

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

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

  //lefts as it is?
#if defined(ENABLE_ITTI)
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.buf[0] = (tac >> 8) & 0xff;
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.buf[1] = (tac >> 0) & 0xff;
#else
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.buf[0] = 0x00;
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.buf[1] = 0x01;
#endif
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.size=2;
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.bits_unused=0;

  // 28 bits --> i have to use 32 bits = 4 byte
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf = MALLOC(8); // why allocate 8 byte? 
#if defined(ENABLE_ITTI)
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf[0] = (cell_identity >> 20) & 0xff;
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf[1] = (cell_identity >> 12) & 0xff;
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf[2] = (cell_identity >>  4) & 0xff;
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf[3] = (cell_identity <<  4) & 0xf0;
#else
  (*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;
#endif
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.size=4;
  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.bits_unused=4;

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

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


  (*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 =-22; //FIXME new parameter for SIB1-NB, not present in SIB1 (for cell reselection but if not used the UE should apply the default value)

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

  //FIXME
  (*sib1_NB_IoT)->freqBandIndicator_r13 =
#if defined(ENABLE_ITTI)
    band;
#else
    5; //if not configured we use band 5 (UL: 824 MHz - 849MHz / DL: 869 MHz - 894 MHz  FDD mode)
#endif

  // Now, follow the scheduler SIB configuration
  // There is only one sib2+sib3 common setting

  schedulingInfo_NB_IoT.si_Periodicity_r13=  SchedulingInfo_NB_r13__si_Periodicity_r13_rf64; //SchedulingInfo_NB_r13__si_Periodicity_r13_rf4096; // (to be set to 64)
580
  schedulingInfo_NB_IoT.si_RepetitionPattern_r13=  SchedulingInfo_NB_r13__si_RepetitionPattern_r13_every4thRF; //This Indicates the starting radio frames within the SI window used for SI message transmission.
Matthieu Kanj's avatar
SIB23  
Matthieu Kanj committed
581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604
  schedulingInfo_NB_IoT.si_TB_r13= SchedulingInfo_NB_r13__si_TB_r13_b680;//208 bits
  
  // 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.
    * */
  sib_type_NB_IoT=SIB_Type_NB_r13_sibType3_NB_r13;

  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);

  //printf("[ASN Debug] SI P: %ld\n",(*sib1_NB_IoT)->schedulingInfoList_r13.list.array[0]->si_Periodicity_r13);
/*
#if defined(ENABLE_ITTI)

  if (configuration->frame_type[CC_id] == TDD)
#endif
  {
  //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);
  }
*/
605 606
  //FIXME which value chose for the following parameter
  *offset =1;
Matthieu Kanj's avatar
SIB23  
Matthieu Kanj committed
607 608
  //FIXME which value chose for the following parameter
  (*sib1_NB_IoT)->si_WindowLength_r13=SystemInformationBlockType1_NB__si_WindowLength_r13_ms160;
609
  (*sib1_NB_IoT)->si_RadioFrameOffset_r13=offset;
Matthieu Kanj's avatar
SIB23  
Matthieu Kanj committed
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646

  /////optional parameters, decide to use at future
  /*
  //system value tag
  (*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);
  // downlink bitmap
  (*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;
  // CRS power offset
  *nrs_CRS_PowerOffset= 0;
  (*sib1_NB_IoT)->nrs_CRS_PowerOffset_r13 = nrs_CRS_PowerOffset;
  */
    *eutraControlRegionSize = 2;
   (*sib1_NB_IoT)->eutraControlRegionSize_r13 = eutraControlRegionSize;
#ifdef XER_PRINT //generate xml files
  xer_fprint(stdout, &asn_DEF_BCCH_DL_SCH_Message_NB, (void*)bcch_message);
#endif

  //bcch_message->message.choice.c1.choice.systemInformationBlockType1_r13 = **sib1_NB_IoT;
  enc_rval = uper_encode_to_buffer(&asn_DEF_BCCH_DL_SCH_Message_NB,
                                   (void*)bcch_message,
                                   carrier->SIB1_NB_IoT,
                                   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);
}


647
/*SIB23_NB_IoT*/
648
//to be clarified is it is possible to carry SIB2 and SIB3  in the same SI message for NB-IoT?
649 650 651 652
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
653 654 655 656
{
  struct SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member *sib2_NB_part;
  struct SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member *sib3_NB_part;

657
  BCCH_DL_SCH_Message_NB_t *bcch_message = &(carrier->systemInformation_NB_IoT); //is the systeminformation-->BCCH_DL_SCH_Message_NB
658 659
  SystemInformationBlockType2_NB_r13_t *sib2_NB_IoT;
  SystemInformationBlockType3_NB_r13_t *sib3_NB_IoT;
660 661

  asn_enc_rval_t enc_rval;
662
  RACH_Info_NB_r13_t rach_Info_NB_IoT;
663
  NPRACH_Parameters_NB_r13_t *nprach_parameters;
664

665
  //optional
666 667 668
  long *connEstFailOffset = NULL;
  connEstFailOffset = CALLOC(1, sizeof(long));

669 670 671
//  RSRP_ThresholdsNPRACH_InfoList_NB_r13_t *rsrp_ThresholdsPrachInfoList;
//  RSRP_Range_t rsrp_range;

672
  ACK_NACK_NumRepetitions_NB_r13_t ack_nack_repetition;
673
  struct NPUSCH_ConfigCommon_NB_r13__dmrs_Config_r13 *dmrs_config;
674
  struct DL_GapConfig_NB_r13  *dl_Gap;
675 676 677 678 679 680 681 682

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


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

687
  //before schould be allocated memory somewhere?
688 689 690 691 692 693 694 695 696
//  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);
//  }
697 698


699
  LOG_I(RRC,"[NB-IoT %d] Configuration SIB2/3\n", Mod_id);
700 701 702 703 704 705 706 707 708

  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;

709
  //may bug if not correct allocation of memory
710 711 712 713
  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;
714

715 716 717 718 719
  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));
720 721 722

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

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

725
  //RACH Config. Common--------------------------------------------------------------
726
  sib2_NB_IoT->radioResourceConfigCommon_r13.rach_ConfigCommon_r13.preambleTransMax_CE_r13 =
727
        configuration->rach_preambleTransMax_CE_NB[CC_id];
728
  sib2_NB_IoT->radioResourceConfigCommon_r13.rach_ConfigCommon_r13.powerRampingParameters_r13.powerRampingStep =
729
  configuration->rach_powerRampingStep_NB[CC_id];
730
  sib2_NB_IoT->radioResourceConfigCommon_r13.rach_ConfigCommon_r13.powerRampingParameters_r13.preambleInitialReceivedTargetPower =
731 732
    configuration->rach_preambleInitialReceivedTargetPower_NB[CC_id];

733 734
  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];
735
  //rach_infoList max size = maxNPRACH-Resources-NB-r13 = 3
736
  ASN_SEQUENCE_ADD(&sib2_NB_IoT->radioResourceConfigCommon_r13.rach_ConfigCommon_r13.rach_InfoList_r13.list,&rach_Info_NB_IoT);
737

738
  //TS 36.331 pag 614 --> if not present the value to infinity sould be used
739
  *connEstFailOffset = 0;
740 741
  
  sib2_NB_IoT->radioResourceConfigCommon_r13.rach_ConfigCommon_r13.connEstFailOffset_r13 = connEstFailOffset; /*OPTIONAL*/
742 743


744
  // BCCH-Config-NB-IoT----------------------------------------------------------------
745
  sib2_NB_IoT->radioResourceConfigCommon_r13.bcch_Config_r13.modificationPeriodCoeff_r13
Nick Ho's avatar
Nick Ho committed
746
    = configuration->bcch_modificationPeriodCoeff_NB[CC_id];
747

748
  // PCCH-Config-NB-IoT-----------------------------------------------------------------
749
  sib2_NB_IoT->radioResourceConfigCommon_r13.pcch_Config_r13.defaultPagingCycle_r13
Nick Ho's avatar
Nick Ho committed
750
    = configuration->pcch_defaultPagingCycle_NB[CC_id];
751 752
  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];
753

754
  //NPRACH-Config-NB-IoT-----------------------------------------------------------------
755 756

  sib2_NB_IoT->radioResourceConfigCommon_r13.nprach_Config_r13.rsrp_ThresholdsPrachInfoList_r13 = NULL; 
757
  sib2_NB_IoT->radioResourceConfigCommon_r13.nprach_Config_r13.nprach_CP_Length_r13 = configuration->nprach_CP_Length[CC_id];
758
  /*OPTIONAL*/
759
//   =CALLOC(1, sizeof(struct RSRP_ThresholdsNPRACH_InfoList_NB_r13)); //fatto uguale dopo
760
//   rsrp_ThresholdsPrachInfoList = sib2_NB_IoT->radioResourceConfigCommon_r13.nprach_Config_r13.rsrp_ThresholdsPrachInfoList_r13;
761 762
//   rsrp_range = configuration->nprach_rsrp_range_NB;
//   ASN_SEQUENCE_ADD(&rsrp_ThresholdsPrachInfoList->list,rsrp_range);
763

764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779
  // 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];
Nick Ho's avatar
Nick Ho committed
780
  nprach_parameters[1].nprach_NumSubcarriers_r13            = configuration->nprach_NumSubcarriers[CC_id];
781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797
  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];
798

799

800 801 802 803 804
  //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]);
  
805
  // NPDSCH-Config NB-IOT
806
  sib2_NB_IoT->radioResourceConfigCommon_r13.npdsch_ConfigCommon_r13.nrs_Power_r13= configuration->npdsch_nrs_Power[CC_id];
807 808


809
  //NPUSCH-Config NB-IoT----------------------------------------------------------------
810
  //list of size 3 (see maxNPRACH_Resources_NB_r13)
811
  ack_nack_repetition = configuration-> npusch_ack_nack_numRepetitions_NB[CC_id]; //is an enumerative
812
  ASN_SEQUENCE_ADD(&(sib2_NB_IoT->radioResourceConfigCommon_r13.npusch_ConfigCommon_r13.ack_NACK_NumRepetitions_Msg4_r13.list) ,&ack_nack_repetition);
813 814

  *srs_SubframeConfig = configuration->npusch_srs_SubframeConfig_NB[CC_id];
815
  sib2_NB_IoT->radioResourceConfigCommon_r13.npusch_ConfigCommon_r13.srs_SubframeConfig_r13= srs_SubframeConfig; /*OPTIONAL*/
816 817


818 819
  /*OPTIONAL*/
  dmrs_config = CALLOC(1,sizeof(struct NPUSCH_ConfigCommon_NB_r13__dmrs_Config_r13));
Nick Ho's avatar
Nick Ho committed
820 821
  dmrs_config->threeTone_CyclicShift_r13 = configuration->npusch_threeTone_CyclicShift_r13[CC_id];
  dmrs_config->sixTone_CyclicShift_r13 = configuration->npusch_sixTone_CyclicShift_r13[CC_id];
822 823 824 825

  /*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 */
826 827 828
  dmrs_config->threeTone_BaseSequence_r13 = NULL;
  dmrs_config->sixTone_BaseSequence_r13 = NULL;
  dmrs_config->twelveTone_BaseSequence_r13 = NULL;
829

830
  sib2_NB_IoT->radioResourceConfigCommon_r13.npusch_ConfigCommon_r13.dmrs_Config_r13 = dmrs_config;
831

832 833 834 835 836 837
  //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
   */
838 839
  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];
840 841


842
  //dl_GAP---------------------------------------------------------------------------------/*OPTIONAL*/
843 844 845 846
  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];
847
  sib2_NB_IoT->radioResourceConfigCommon_r13.dl_Gap_r13 = dl_Gap;
848 849


850
  // uplinkPowerControlCommon - NB-IoT------------------------------------------------------
851 852 853
  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];
854 855
  //no deltaFlist_PUCCH and no UL cyclic prefix

856
  // UE Timers and Constants -NB-IoT--------------------------------------------------------
857 858 859 860 861 862
  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];
863

864
  //other SIB2-NB Parameters--------------------------------------------------------------------------------
865 866
  sib2_NB_IoT->freqInfo_r13.additionalSpectrumEmission_r13 = 1;
  sib2_NB_IoT->freqInfo_r13.ul_CarrierFreq_r13 = NULL; /*OPTIONAL*/
867

868
  sib2_NB_IoT->timeAlignmentTimerCommon_r13=TimeAlignmentTimer_infinity;//TimeAlignmentTimer_sf5120;
869 870

  /*OPTIONAL*/
871
  sib2_NB_IoT->multiBandInfoList_r13 = NULL;
872 873 874

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

875
  sib3_NB_IoT->cellReselectionInfoCommon_r13.q_Hyst_r13=SystemInformationBlockType3_NB_r13__cellReselectionInfoCommon_r13__q_Hyst_r13_dB4;
876
  sib3_NB_IoT->cellReselectionServingFreqInfo_r13.s_NonIntraSearch_r13=0; //or define in configuration?
877

878
  sib3_NB_IoT->intraFreqCellReselectionInfo_r13.q_RxLevMin_r13 = -70;
879
  //new
880
  sib3_NB_IoT->intraFreqCellReselectionInfo_r13.q_QualMin_r13 = CALLOC(1,sizeof(*sib3_NB_IoT->intraFreqCellReselectionInfo_r13.q_QualMin_r13));
Nick Ho's avatar
Nick Ho committed
881
  *(sib3_NB_IoT->intraFreqCellReselectionInfo_r13.q_QualMin_r13)= -22; //a caso
882

883 884 885
  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;
886 887

  //how to manage?
888 889
  sib3_NB_IoT->freqBandInfo_r13 = NULL;
  sib3_NB_IoT->multiBandInfoList_r13 = NULL;
890 891


892
///BCCH message (generate the SI message)
893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908
  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,
909
                                   carrier->SIB23_NB_IoT,
910
                                   900);
911 912 913 914 915 916

   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);
917 918
//  AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n",
//               enc_rval.failed_type->name, enc_rval.encoded);
919

920
//#if defined(ENABLE_ITTI).....
921 922 923


#ifdef USER_MODE
924
  LOG_D(RRC,"[NB-IoT] SystemInformation-NB Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8);
925 926 927
#endif

  if (enc_rval.encoded==-1) {
928
    msg("[RRC] ASN1 : SI-NB encoding failed for SIB23_NB_IoT\n");
929 930 931
    return(-1);
  }

932 933 934
  carrier->sib2_NB_IoT = sib2_NB_IoT;
  carrier->sib3_NB_IoT = sib3_NB_IoT;

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

Nick Ho's avatar
Nick Ho committed
938
/*do_RRCConnectionSetup_NB_IoT--> the aim is to establish SRB1 and SRB1bis(implicitly), based on configuration setting up Msg 4*/
939
uint8_t do_RRCConnectionSetup_NB_IoT(
940
  rrc_eNB_ue_context_NB_IoT_t*      const ue_context_pP,
941
  int                              CC_id,
942
  uint8_t*                   const buffer, //Srb0.Tx_buffer.Payload
943
  const uint8_t                    Transaction_id,
944
  SRB_ToAddModList_NB_r13_t**             SRB_configList_NB_IoT, //for both SRB1bis and SRB1
Nick Ho's avatar
Nick Ho committed
945
  struct PhysicalConfigDedicated_NB_r13** physicalConfigDedicated_NB_IoT)
946
{
Nick Ho's avatar
Nick Ho committed
947 948
  asn_enc_rval_t enc_rval;
  uint8_t ecause=0;
949

Nick Ho's avatar
Nick Ho committed
950 951 952 953 954
  long* prioritySRB1 = NULL;
  long* prioritySRB1bis = NULL;
  BOOLEAN_t* logicalChannelSR_Prohibit = NULL; //pag 605
  BOOLEAN_t* npusch_AllSymbols = NULL;
  long* npusch_repetitions = NULL;
955
  long* group_hopping_disabled = NULL;
Nick Ho's avatar
Nick Ho committed
956
  long* srpro = NULL;
957

Nick Ho's avatar
Nick Ho committed
958
  // At the first moment of MSG4 testing we set NULL to those optional
959

Nick Ho's avatar
Nick Ho committed
960 961 962
  struct SRB_ToAddMod_NB_r13* SRB1_config_NB_IoT = NULL;
  struct SRB_ToAddMod_NB_r13__rlc_Config_r13* SRB1_rlc_config_NB_IoT = NULL;
  struct SRB_ToAddMod_NB_r13__logicalChannelConfig_r13* SRB1_lchan_config_NB_IoT = NULL;
963

Nick Ho's avatar
Nick Ho committed
964 965 966
  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;
967

Nick Ho's avatar
Nick Ho committed
968 969 970
  PhysicalConfigDedicated_NB_r13_t* physicalConfigDedicated2_NB_IoT = NULL;
  DL_CCCH_Message_NB_t dl_ccch_msg_NB_IoT;
  RRCConnectionSetup_NB_t* rrcConnectionSetup_NB_IoT = NULL;
971

Nick Ho's avatar
Nick Ho committed
972 973 974 975
  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;
  rrcConnectionSetup_NB_IoT = &dl_ccch_msg_NB_IoT.message.choice.c1.choice.rrcConnectionSetup_r13;
976 977


Nick Ho's avatar
Nick Ho committed
978 979
  if (*SRB_configList_NB_IoT)
  {
980
   free(*SRB_configList_NB_IoT);
Nick Ho's avatar
Nick Ho committed
981 982
  }
  *SRB_configList_NB_IoT = CALLOC(1,sizeof(SRB_ToAddModList_NB_r13_t));
983

Nick Ho's avatar
Nick Ho committed
984
#if 0
985

Nick Ho's avatar
Nick Ho committed
986 987 988 989
  // SRB1--------------------
  SRB1_config_NB_IoT = CALLOC(1,sizeof(*SRB1_config_NB_IoT));
  SRB1_rlc_config_NB_IoT = CALLOC(1,sizeof(*SRB1_rlc_config_NB_IoT));
  SRB1_config_NB_IoT->rlc_Config_r13   = SRB1_rlc_config_NB_IoT;
990

Nick Ho's avatar
Nick Ho committed
991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016
  SRB1_rlc_config_NB_IoT->present = SRB_ToAddMod_NB_r13__rlc_Config_r13_PR_explicitValue;
  SRB1_rlc_config_NB_IoT->choice.explicitValue.present=RLC_Config_NB_r13_PR_am;//the only possible in NB_IoT
  
  // apply the SRB1 configuration from configuration files
  SRB1_rlc_config_NB_IoT->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_IoT->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_IoT->choice.explicitValue.choice.am.dl_AM_RLC_r13.enableStatusReportSN_Gap_r13 =NULL;
  SRB1_rlc_config_NB_IoT->choice.explicitValue.choice.am.ul_AM_RLC_r13.t_PollRetransmit_r13 = T_PollRetransmit_NB_r13_ms25000;
  SRB1_rlc_config_NB_IoT->choice.explicitValue.choice.am.ul_AM_RLC_r13.maxRetxThreshold_r13 = UL_AM_RLC_NB_r13__maxRetxThreshold_r13_t8;
  // musT be disabled--> SRB1 config pag 640 specs
  SRB1_rlc_config_NB_IoT->choice.explicitValue.choice.am.dl_AM_RLC_r13.enableStatusReportSN_Gap_r13 = NULL;

  SRB1_lchan_config_NB_IoT = CALLOC(1,sizeof(*SRB1_lchan_config_NB_IoT));
  SRB1_config_NB_IoT->logicalChannelConfig_r13  = SRB1_lchan_config_NB_IoT;
  SRB1_lchan_config_NB_IoT->present = SRB_ToAddMod_NB_r13__logicalChannelConfig_r13_PR_explicitValue;

  // logical channel priority pag 605 (is 1 for SRB1 and for SRB1bis should be the same)
  prioritySRB1 = CALLOC(1, sizeof(long));
  *prioritySRB1 = 1;
  SRB1_lchan_config_NB_IoT->choice.explicitValue.priority_r13 = prioritySRB1;
  
  logicalChannelSR_Prohibit = CALLOC(1, sizeof(BOOLEAN_t));
  *logicalChannelSR_Prohibit = 1;
  // should be set to TRUE (specs pag 641)
  SRB1_lchan_config_NB_IoT->choice.explicitValue.logicalChannelSR_Prohibit_r13 = logicalChannelSR_Prohibit;
1017

Nick Ho's avatar
Nick Ho committed
1018 1019
  // ADD SRB1
  ASN_SEQUENCE_ADD(&(*SRB_configList_NB_IoT)->list,SRB1_config_NB);
1020

Nick Ho's avatar
Nick Ho committed
1021
#endif
1022

Nick Ho's avatar
Nick Ho committed
1023
#if 1
1024

Nick Ho's avatar
Nick Ho committed
1025 1026 1027 1028
  // SRB1bis (The configuration for SRB1 and SRB1bis is the same) the only difference is the logical channel identity = 3 but not set here
	SRB1bis_config_NB_IoT = CALLOC(1,sizeof(*SRB1bis_config_NB_IoT));
	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;
1029

Nick Ho's avatar
Nick Ho committed
1030 1031
	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
1032

Nick Ho's avatar
Nick Ho committed
1033
  // Set from ourself not configuration files
1034
	SRB1bis_rlc_config_NB_IoT->choice.explicitValue.choice.am.ul_AM_RLC_r13.t_PollRetransmit_r13 = T_PollRetransmit_NB_r13_ms250;
Nick Ho's avatar
Nick Ho committed
1035 1036 1037
	SRB1bis_rlc_config_NB_IoT->choice.explicitValue.choice.am.ul_AM_RLC_r13.maxRetxThreshold_r13 = UL_AM_RLC_NB_r13__maxRetxThreshold_r13_t8;
	//musT be disabled--> SRB1 config pag 640 specs 
	SRB1bis_rlc_config_NB_IoT->choice.explicitValue.choice.am.dl_AM_RLC_r13.enableStatusReportSN_Gap_r13 =NULL;
1038

Nick Ho's avatar
Nick Ho committed
1039 1040
	SRB1bis_lchan_config_NB_IoT = CALLOC(1,sizeof(*SRB1bis_lchan_config_NB_IoT));
	SRB1bis_config_NB_IoT->logicalChannelConfig_r13  = SRB1bis_lchan_config_NB_IoT;
Nick Ho's avatar
Nick Ho committed
1041
  //SRB1bis_lchan_config_NB_IoT->present = SRB_ToAddMod_NB_r13__logicalChannelConfig_r13_PR_explicitValue;
1042
  SRB1bis_lchan_config_NB_IoT->present = SRB_ToAddMod_NB_r13__logicalChannelConfig_r13_PR_defaultValue;
Nick Ho's avatar
Nick Ho committed
1043 1044 1045 1046 1047
/*
  srpro = CALLOC(1,sizeof(long));
  *srpro = 3;
  SRB1bis_lchan_config_NB_IoT->choice.explicitValue.priority_r13 = srpro;
*/
1048 1049 1050
	//prioritySRB1bis = CALLOC(1, sizeof(long));
	//*prioritySRB1bis = 1; //same as SRB1?
	//SRB1bis_lchan_config_NB_IoT->choice.explicitValue.priority_r13 = prioritySRB1bis;
1051

1052 1053 1054
	//logicalChannelSR_Prohibit = CALLOC(1, sizeof(BOOLEAN_t));
	//*logicalChannelSR_Prohibit = 1; //should be set to TRUE (specs pag 641)
	//SRB1bis_lchan_config_NB_IoT->choice.defaultValue = 0;
1055

Nick Ho's avatar
Nick Ho committed
1056 1057 1058
	//ADD SRB1bis
	//MP: SRB_ToAddModList_NB_r13_t size = 1
	ASN_SEQUENCE_ADD(&(*SRB_configList_NB_IoT)->list,SRB1bis_config_NB_IoT);
1059

Nick Ho's avatar
Nick Ho committed
1060
#endif
1061

Nick Ho's avatar
Nick Ho committed
1062 1063 1064 1065 1066 1067 1068 1069
  // start PHY dedicate config
  physicalConfigDedicated2_NB_IoT = CALLOC(1,sizeof(*physicalConfigDedicated2_NB_IoT));
  *physicalConfigDedicated_NB_IoT = physicalConfigDedicated2_NB_IoT;

  physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13=NULL;
  //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));
1070 1071
  //physicalConfigDedicated2_NB_IoT->uplinkPowerControlDedicated_r13 = NULL;
  physicalConfigDedicated2_NB_IoT->uplinkPowerControlDedicated_r13 = CALLOC(1,sizeof(*physicalConfigDedicated2_NB_IoT->uplinkPowerControlDedicated_r13));
Nick Ho's avatar
Nick Ho committed
1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082

#if 0  
  // Carrier config dedicated set to NULL at this moment
  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=DL_CarrierConfigDedicated_NB_r13__downlinkBitmapNonAnchor_r13_PR_useNoBitmap_r13;
  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 = DL_CarrierConfigDedicated_NB_r13__dl_GapNonAnchor_r13_PR_useNoGap_r13;
  physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13->dl_CarrierConfig_r13.inbandCarrierInfo_r13= NULL;
  physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13->ul_CarrierConfig_r13.ul_CarrierFreq_r13= NULL;
#endif
1083 1084

 // NPDCCH
1085 1086 1087
 physicalConfigDedicated2_NB_IoT->npdcch_ConfigDedicated_r13->npdcch_NumRepetitions_r13 =NPDCCH_ConfigDedicated_NB_r13__npdcch_NumRepetitions_r13_r4;
 physicalConfigDedicated2_NB_IoT->npdcch_ConfigDedicated_r13->npdcch_Offset_USS_r13 =NPDCCH_ConfigDedicated_NB_r13__npdcch_Offset_USS_r13_oneFourth;
 physicalConfigDedicated2_NB_IoT->npdcch_ConfigDedicated_r13->npdcch_StartSF_USS_r13=NPDCCH_ConfigDedicated_NB_r13__npdcch_StartSF_USS_r13_v2;
1088

Nick Ho's avatar
Nick Ho committed
1089 1090
 // NPUSCH
 npusch_repetitions = CALLOC(1, sizeof(long));
1091 1092
 *npusch_repetitions = ACK_NACK_NumRepetitions_NB_r13_r8;
 physicalConfigDedicated2_NB_IoT->npusch_ConfigDedicated_r13->ack_NACK_NumRepetitions_r13= npusch_repetitions;
1093 1094
 npusch_AllSymbols= CALLOC(1, sizeof(BOOLEAN_t));
 *npusch_AllSymbols= 1; //TRUE
1095 1096 1097 1098
 physicalConfigDedicated2_NB_IoT->npusch_ConfigDedicated_r13->npusch_AllSymbols_r13= npusch_AllSymbols;
 group_hopping_disabled = CALLOC(1,sizeof(long));
 *group_hopping_disabled= NPUSCH_ConfigDedicated_NB_r13__groupHoppingDisabled_r13_true;
 physicalConfigDedicated2_NB_IoT->npusch_ConfigDedicated_r13->groupHoppingDisabled_r13=group_hopping_disabled;
1099 1100

 // UplinkPowerControlDedicated
1101
 physicalConfigDedicated2_NB_IoT->uplinkPowerControlDedicated_r13->p0_UE_NPUSCH_r13 = 0;
1102

1103
 //Fill the rrcConnectionSetup-NB message
1104 1105 1106
 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 ;
Nick Ho's avatar
Nick Ho committed
1107
 // carry only the phyiscal dedicate configuration
1108 1109 1110 1111 1112 1113
 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;
1114 1115 1116 1117 1118

#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,
1119
                                  (void*)&dl_ccch_msg_NB_IoT,
1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134
                                  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*/
1135
uint8_t do_SecurityModeCommand_NB_IoT(
1136 1137 1138 1139 1140 1141
  const protocol_ctxt_t* const ctxt_pP,
  uint8_t* const buffer,
  const uint8_t Transaction_id,
  const uint8_t cipheringAlgorithm,
  const uint8_t integrityProtAlgorithm)
{
1142
  DL_DCCH_Message_NB_t dl_dcch_msg_NB_IoT;
1143 1144
  asn_enc_rval_t enc_rval;

1145
  memset(&dl_dcch_msg_NB_IoT,0,sizeof(DL_DCCH_Message_NB_t));
1146

1147 1148
  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;
1149

1150 1151
  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;
1152

1153
  dl_dcch_msg_NB_IoT.message.choice.c1.choice.securityModeCommand_r13.criticalExtensions.choice.c1.present =
1154 1155 1156
		  SecurityModeCommand__criticalExtensions__c1_PR_securityModeCommand_r8;

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

1160
  dl_dcch_msg_NB_IoT.message.choice.c1.choice.securityModeCommand_r13.criticalExtensions.choice.c1.choice.securityModeCommand_r8.securityConfigSMC.securityAlgorithmConfig.integrityProtAlgorithm
1161 1162 1163 1164
    = (