SIB_NB_IoT.c 18.3 KB
Newer Older
Matthieu Kanj's avatar
Matthieu Kanj committed
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
/* 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 PHY/LTE_TRANSPORT/SIB_NB_IoT.c
* \Fucntions for the generation of SIB information for NB_IoT,	 TS 36-212, V13.4.0 2017-02
* \author M. KANJ
* \date 2018
* \version 0.0
* \company bcom
* \email: matthieu.kanj@b-com.com
* \note
* \warning
*/


#include "PHY/LTE_TRANSPORT/defs_NB_IoT.h"
#include "PHY/LTE_TRANSPORT/proto_NB_IoT.h"
//#include "PHY/CODING/defs_NB_IoT.h"
//#include "PHY/LTE_REFSIG/defs_NB_IoT.h"
//#include "PHY/impl_defs_lte_NB_IoT.h"
//#include "PHY/impl_defs_top_NB_IoT.h"
#include "PHY/impl_defs_lte.h"

/////////////////////////////////////////////////////////////////////////////////////////

int generate_SIB1(NB_IoT_eNB_NDLSCH_t 		*sib1_struct,
                   int32_t 					**txdataF,
                   int16_t                  amp,
                   LTE_DL_FRAME_PARMS 	    *frame_parms,
                   uint32_t 				frame,
                   uint32_t 				subframe,
Matthieu Kanj's avatar
Matthieu Kanj committed
49
                   int                      RB_IoT_ID,
50 51
                   uint8_t                  operation_mode,
                   uint8_t                release_v13_5_0)
Matthieu Kanj's avatar
Matthieu Kanj committed
52 53 54
{
 	int done=0;
 	uint8_t *sib1_pdu  = sib1_struct->harq_process->pdu;
Matthieu Kanj's avatar
Matthieu Kanj committed
55 56 57 58 59
 	uint8_t opr_mode = 3;
 	if(operation_mode>=2)
 	{
 		opr_mode =0;
 	}
Matthieu Kanj's avatar
Matthieu Kanj committed
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
	uint8_t tmp =0;
    uint8_t rep_val = 0;
    uint8_t start_frame = get_start_frame_SIB1_NB_IoT(frame_parms, get_rep_num_SIB1_NB_IoT(sib1_struct->repetition_number_SIB1));

    switch( get_rep_num_SIB1_NB_IoT(sib1_struct->repetition_number_SIB1) )
    {
      case 4:
              rep_val = 64;
      break;

      case 8:
              rep_val = 32;
      break;
              
      case 16:
              rep_val = 16;
      break;

      default:
            printf("Error in SIB1");

    }

    uint8_t var = 0;

    if(start_frame == 1)
    {
      var =1;
    }

    if(start_frame>=16)
    {
        tmp = 1;
    }

    uint8_t born_inf = 0 + start_frame*tmp;
    uint8_t born_sup = 16 + start_frame*tmp;

    if((subframe == 4)  && (frame%2 == var) && (born_inf<= frame % rep_val) && (frame % rep_val < born_sup ))
    {
Nick Ho's avatar
Nick Ho committed
100
        LOG_D(PHY,"[%3d][%2d] Generating SIB1\n",frame,subframe);
101
    	  int G = get_G_SIB1_NB_IoT(frame_parms,operation_mode);
Matthieu Kanj's avatar
Matthieu Kanj committed
102 103 104 105 106 107

        if( frame % rep_val == var )
        {
            dlsch_encoding_NB_IoT(sib1_pdu,
                                  sib1_struct,
                                  8,             ///// number_of_subframes_required
Matthieu Kanj's avatar
Matthieu Kanj committed
108
                                  G);         //// this vallue is fixed, should take into account in future the case of stand-alone & guard-band 
Matthieu Kanj's avatar
Matthieu Kanj committed
109 110 111
        
             dlsch_scrambling_Gen_NB_IoT(frame_parms,
                                         sib1_struct,
Matthieu Kanj's avatar
Matthieu Kanj committed
112
                                         8*G,
Matthieu Kanj's avatar
Matthieu Kanj committed
113 114
                                         frame, 
                                         subframe*2,
115 116 117
                                         sib1_struct->rnti,
                                         release_v13_5_0,
                                         1);
Matthieu Kanj's avatar
Matthieu Kanj committed
118 119 120 121 122
        }

        dlsch_modulation_NB_IoT(txdataF,
                                amp,
                                frame_parms,
Matthieu Kanj's avatar
Matthieu Kanj committed
123
                                opr_mode,       // control region size for LTE , values between 0..3, (0 for stand-alone / 1, 2 or 3 for in-band)
Matthieu Kanj's avatar
Matthieu Kanj committed
124
                                sib1_struct,
Matthieu Kanj's avatar
Matthieu Kanj committed
125
                                G,              // number of bits per subframe
Matthieu Kanj's avatar
Matthieu Kanj committed
126 127 128 129
                                ((frame%16)/2),
                                4,       
                                RB_IoT_ID);
        done =1;
Matthieu Kanj's avatar
Matthieu Kanj committed
130
        frame_parms->flag_free_sf =1;
Matthieu Kanj's avatar
Matthieu Kanj committed
131 132 133 134 135 136 137 138 139 140 141 142
        
    }

 return(done);
}


//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////

143 144 145
int generate_SIB23(NB_IoT_eNB_NDLSCH_t 	  *SIB23,
	                 int32_t 				        **txdataF,
	                 int16_t                amp,
Matthieu Kanj's avatar
Matthieu Kanj committed
146
	                 LTE_DL_FRAME_PARMS 	  *frame_parms,
147 148 149 150
	                 uint32_t 			        frame,
	                 uint32_t 			        subframe,
	                 int                    RB_IoT_ID,
                   uint8_t                release_v13_5_0)
Matthieu Kanj's avatar
Matthieu Kanj committed
151
{
Matthieu Kanj's avatar
Matthieu Kanj committed
152 153 154 155
    int done=0;

    if( SIB23->active == 1 )
    {
156 157
        //LOG_I(PHY,"[Frame: %d][Subframe: %d]sent SIB23\n",frame,subframe);

Matthieu Kanj's avatar
Matthieu Kanj committed
158
    	uint8_t *SIB23_pdu  = SIB23->harq_process->pdu;
159 160
	 	  uint32_t rep =  SIB23->resource_assignment;
	 	  uint8_t eutra_control_region = 3;
Matthieu Kanj's avatar
Matthieu Kanj committed
161 162 163 164

	    uint32_t counter_rep    =  SIB23->counter_repetition_number;
	    uint32_t pointer_to_sf  =  SIB23->pointer_to_subframe;             /// to identify wich encoded subframe to transmit 

Matthieu Kanj's avatar
Matthieu Kanj committed
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
    	int G = get_G_NB_IoT(frame_parms);
    	uint8_t Nsf = SIB23->resource_assignment;   //value 2 or 8

        if(counter_rep == rep)
        {
            dlsch_encoding_NB_IoT(SIB23_pdu,
                                  SIB23,
                                  Nsf,             ///// number_of_subframes_required
                                  G);              //// this vallue is fixed, should take into account in future the case of stand-alone & guard-band 
        
             dlsch_scrambling_Gen_NB_IoT(frame_parms,
                                         SIB23,
                                         Nsf*G,
                                         frame, 
                                         subframe*2,
180 181 182
                                         SIB23->rnti,
                                         release_v13_5_0,
                                         1);
Matthieu Kanj's avatar
Matthieu Kanj committed
183 184 185 186 187
        }

        dlsch_modulation_NB_IoT(txdataF,
                                amp,
                                frame_parms,
Matthieu Kanj's avatar
Matthieu Kanj committed
188
                                eutra_control_region,     //should be replace by start_symbole   // control region size for LTE , values between 0..3, (0 for stand-alone / 1, 2 or 3 for in-band)
Matthieu Kanj's avatar
Matthieu Kanj committed
189 190 191 192 193 194 195 196
                                SIB23,
                                G,                  // number of bits per subframe
                                pointer_to_sf,
                                subframe,       
                                RB_IoT_ID);

        SIB23->counter_repetition_number--;
        SIB23->pointer_to_subframe++;
Matthieu Kanj's avatar
Matthieu Kanj committed
197 198
        
        frame_parms->flag_free_sf =1;
Matthieu Kanj's avatar
Matthieu Kanj committed
199 200 201 202

        if(SIB23->counter_repetition_number == 0)
        {
        	SIB23->active = 0;
Matthieu Kanj's avatar
Matthieu Kanj committed
203
        	
Matthieu Kanj's avatar
Matthieu Kanj committed
204
        }
Matthieu Kanj's avatar
Matthieu Kanj committed
205
        done =1;
Matthieu Kanj's avatar
Matthieu Kanj committed
206 207 208 209
    }

 return(done);

Matthieu Kanj's avatar
Matthieu Kanj committed
210
}
Matthieu Kanj's avatar
Matthieu Kanj committed
211

Matthieu Kanj's avatar
Matthieu Kanj committed
212 213
////////////////////////////////////////////////////////////////////////

Matthieu Kanj's avatar
Matthieu Kanj committed
214

Matthieu Kanj's avatar
Matthieu Kanj committed
215 216
int generate_NDLSCH_NB_IoT(PHY_VARS_eNB           *eNB,
                           NB_IoT_eNB_NDLSCH_t 	  *RAR,
217 218 219 220 221 222 223
		                       int32_t 				        **txdataF,
		                       int16_t                amp,
		                       LTE_DL_FRAME_PARMS 	  *frame_parms,
		                       uint32_t 			        frame,
		                       uint32_t 			        subframe,
		                       int                    RB_IoT_ID,
                           uint8_t                release_v13_5_0)
Matthieu Kanj's avatar
Matthieu Kanj committed
224 225 226
{
    int done = 0;

227
    if( RAR->active == 1 )
Matthieu Kanj's avatar
Matthieu Kanj committed
228 229
    {
    	uint8_t *RAR_pdu  = RAR->harq_process->pdu;
230 231 232 233 234 235 236 237 238 239
      
      if(RAR->active_msg2 == 1 && RAR_pdu!=NULL)
      {
          uint8_t one_byte = RAR_pdu[2]>>3;
          uint8_t subcarrier_spacing = one_byte & 0x01;
          eNB->ulsch_NB_IoT[0]->harq_process->subcarrier_spacing = subcarrier_spacing;
      }
      // make different between RAR data and NPDSCH data   // add a flag in NPDSCH to switch between RA and normal data transmission
	 	  uint32_t rep =  RAR->repetition_number;
	 	  uint8_t  eutra_control_region = 3;
Matthieu Kanj's avatar
Matthieu Kanj committed
240

Matthieu Kanj's avatar
Matthieu Kanj committed
241 242 243
	    uint32_t counter_rep    =  RAR->counter_repetition_number;
	    uint32_t counter_sf_rep =  RAR->counter_current_sf_repetition;   /// for identifiying when to trigger new scrambling
	    uint32_t pointer_to_sf  =  RAR->pointer_to_subframe;             /// to identify wich encoded subframe to transmit 
Matthieu Kanj's avatar
Matthieu Kanj committed
244

Matthieu Kanj's avatar
Matthieu Kanj committed
245
    	int     G   = get_G_NB_IoT(frame_parms);
Matthieu Kanj's avatar
Matthieu Kanj committed
246 247
    	uint8_t Nsf = RAR->number_of_subframes_for_resource_assignment;

Nick Ho's avatar
Nick Ho committed
248
        //LOG_I(PHY,"[Frame: %d][Subframe: %d]sent RAR, rep : %d, counter_rep:%d, Num_res:%d\n",frame,subframe,rep,counter_rep,Nsf);
Nick Ho's avatar
Nick Ho committed
249

250 251
      if( (counter_rep == rep) && (counter_sf_rep == 0) && (pointer_to_sf == 0) )
      {
Matthieu Kanj's avatar
Matthieu Kanj committed
252 253 254 255 256 257 258 259 260 261 262
        	
            dlsch_encoding_NB_IoT(RAR_pdu,
                                  RAR,
                                  Nsf,             ///// number_of_subframes_required
                                  G);              //// this vallue is fixed, should take into account in future the case of stand-alone & guard-band 
        
             dlsch_scrambling_Gen_NB_IoT(frame_parms,
                                         RAR,
                                         Nsf*G,
                                         frame, 
                                         subframe*2,
263 264 265 266 267 268 269 270
                                         RAR->rnti,
                                         release_v13_5_0,
                                         0);
      }

		  if( (counter_rep != rep) && (counter_sf_rep == 0) && (pointer_to_sf == 0) )
		  {
			       dlsch_scrambling_Gen_NB_IoT(frame_parms,
Matthieu Kanj's avatar
Matthieu Kanj committed
271 272 273 274
                                         RAR,
                                         Nsf*G,
                                         frame, 
                                         subframe*2,
275 276 277 278
                                         RAR->rnti,
                                         release_v13_5_0,
                                         0);
		  }
Matthieu Kanj's avatar
Matthieu Kanj committed
279 280 281 282 283 284 285 286 287

        if( rep > 4)
        {

		        RAR->counter_current_sf_repetition++;

		        dlsch_modulation_NB_IoT(txdataF,
		                                amp,
		                                frame_parms,
Matthieu Kanj's avatar
Matthieu Kanj committed
288
		                                eutra_control_region,     //should be replace by start_symbole   // control region size for LTE , values between 0..3, (0 for stand-alone / 1, 2 or 3 for in-band)
Matthieu Kanj's avatar
Matthieu Kanj committed
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
		                                RAR,
		                                G,                  // number of bits per subframe
		                                pointer_to_sf,
		                                subframe,       
		                                RB_IoT_ID);

		        if(RAR->counter_current_sf_repetition == 4)
		        {
		        	RAR->pointer_to_subframe++;
		        	RAR->counter_current_sf_repetition =0;

		        	if (Nsf == RAR->pointer_to_subframe && (RAR->counter_repetition_number > 4))
		        	{
		        		RAR->counter_repetition_number = RAR->counter_repetition_number-4;
		        		RAR->pointer_to_subframe =0;
		        		RAR->counter_current_sf_repetition =0;

		        	} else {
Matthieu Kanj's avatar
Matthieu Kanj committed
307 308 309
                        
		        		RAR->active      = 0;
                RAR->active_msg2 = 0;
Matthieu Kanj's avatar
Matthieu Kanj committed
310 311 312 313 314 315 316 317 318 319 320 321
		        		done =1;
		        	}

		        }

        } else {

        		RAR->counter_current_sf_repetition++;

		        dlsch_modulation_NB_IoT(txdataF,
		                                amp,
		                                frame_parms,
Matthieu Kanj's avatar
Matthieu Kanj committed
322
		                                eutra_control_region,     //should be replace by start_symbole   // control region size for LTE , values between 0..3, (0 for stand-alone / 1, 2 or 3 for in-band)
Matthieu Kanj's avatar
Matthieu Kanj committed
323 324 325 326 327 328 329 330 331
		                                RAR,
		                                G,                  // number of bits per subframe
		                                pointer_to_sf,
		                                subframe,       
		                                RB_IoT_ID);

		        if(RAR->counter_current_sf_repetition == rep)
		        {
		        	RAR->pointer_to_subframe++;
Matthieu Kanj's avatar
Matthieu Kanj committed
332
              RAR->counter_current_sf_repetition =0;
Matthieu Kanj's avatar
Matthieu Kanj committed
333 334 335

		        	if (Nsf == RAR->pointer_to_subframe)
		        	{
Matthieu Kanj's avatar
Matthieu Kanj committed
336 337 338
                       
		        		RAR->active      = 0;
                RAR->active_msg2 = 0;
Matthieu Kanj's avatar
Matthieu Kanj committed
339 340 341 342 343 344 345 346 347
		        		done =1;
		        	}

		        }
        }   
    }

	return(done);
}
Matthieu Kanj's avatar
Matthieu Kanj committed
348

Matthieu Kanj's avatar
Matthieu Kanj committed
349 350
/////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
Daniel's avatar
Daniel committed
351
int generate_NPDCCH_NB_IoT(NB_IoT_eNB_NPDCCH_t 	  *DCI_pdu,
Matthieu Kanj's avatar
Matthieu Kanj committed
352 353 354 355 356 357 358 359
		                   int32_t 				  **txdataF,
		                   int16_t                amp,
		                   LTE_DL_FRAME_PARMS 	  *frame_parms,
		                   uint32_t 			  frame,
		                   uint32_t 			  subframe,
		                   int                    RB_IoT_ID)
{
    int done=0;
Matthieu Kanj's avatar
Matthieu Kanj committed
360
    
Matthieu Kanj's avatar
Matthieu Kanj committed
361

Matthieu Kanj's avatar
Matthieu Kanj committed
362 363 364 365
 	for(int i=0; i<2; i++) 
    {		
    	uint8_t ncce_index = 0;   /// = DCI->ncce_index[i];
 	    uint8_t agr_level = 2;	  /// = DCI->aggregation_level[i];
Matthieu Kanj's avatar
Matthieu Kanj committed
366

367
		    if( DCI->active[i] == 1)
Matthieu Kanj's avatar
Matthieu Kanj committed
368
		    {
Nick Ho's avatar
Nick Ho committed
369
                //LOG_I(PHY,"[Frame: %d][Subframe: %d]sent DCI\n",frame,subframe);
Matthieu Kanj's avatar
Matthieu Kanj committed
370 371 372 373 374
		    	uint8_t  *DCI_pdu  = DCI->pdu[i];
			 	uint32_t rep =  DCI->dci_repetitions[i];         /// repetition number
			 	uint8_t  eutra_control_region = 3;
			 	uint8_t num_bits_of_DCI =DCI->A[i];  //DCI->dci_bits_length;    /// value to be passed through nfapi when filling the PHY structures
			    uint32_t counter_rep    =  DCI->counter_repetition_number[i];          ////// Buffer for repetitions 
Matthieu Kanj's avatar
Matthieu Kanj committed
375

Matthieu Kanj's avatar
Matthieu Kanj committed
376 377
		    	int G = get_G_NB_IoT(frame_parms);
		    	////////////  uint8_t Nsf = DCI->number_of_subframes_for_resource_assignment;
Matthieu Kanj's avatar
Matthieu Kanj committed
378

Matthieu Kanj's avatar
Matthieu Kanj committed
379 380
		        if( counter_rep == rep)
		        {
Matthieu Kanj's avatar
Matthieu Kanj committed
381

Matthieu Kanj's avatar
Matthieu Kanj committed
382 383 384 385 386 387 388 389 390 391 392 393 394 395
		            dci_encoding_NB_IoT(DCI_pdu,		     // Array of two DCI pdus, even if one DCI is to transmit , the number of DCI is indicated in dci_number
										DCI,                  ////uint8_t    *e[2],				// *e should be e[2][G]
										num_bits_of_DCI,       //////A = number of bits of the DCI
										G,
										ncce_index,
										agr_level);

		             npdcch_scrambling_NB_IoT(frame_parms,
											  DCI,			// Input data
											  G,        	// Total number of bits to transmit in one subframe(case of DCI = G)
											  subframe*2,	//XXX we pass the subframe	// Slot number (0..19)
											  ncce_index,
											  agr_level);
		        }
Matthieu Kanj's avatar
Matthieu Kanj committed
396

Matthieu Kanj's avatar
Matthieu Kanj committed
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
				if( ((counter_rep %4)== 0) && (counter_rep != rep) )
				{
					npdcch_scrambling_NB_IoT(frame_parms,
											  DCI,			// Input data
											  G,        	// Total number of bits to transmit in one subframe(case of DCI = G)
											  subframe*2,				//XXX we pass the subframe	// Slot number (0..19)
											  ncce_index,
											  agr_level);
				}

		        dci_modulation_NB_IoT(txdataF,
									  amp,
									  frame_parms,
									  eutra_control_region,      // control region size for LTE , values between 0..3, (0 for stand-alone / 1, 2 or 3 for in-band)
									  DCI,
									  0,		     // npdsch_data_subframe, // subframe index of the data table of npdsch channel (G*Nsf)  , values are between 0..Nsf  			
									  agr_level,
									  ncce_index,
									  subframe,
									  RB_IoT_ID);

				DCI->counter_repetition_number[i]--; 

		        if(DCI->counter_repetition_number[i] == 0)
		        { 	
422
                        //printf("DCI REP done\n");
Matthieu Kanj's avatar
Matthieu Kanj committed
423 424 425 426 427 428
		        		DCI->active[i] = 0;
		        		done =1;
		        }
		          
		    }
	}
Matthieu Kanj's avatar
Matthieu Kanj committed
429 430 431
	return(done);
}

Matthieu Kanj's avatar
Matthieu Kanj committed
432

Matthieu Kanj's avatar
Matthieu Kanj committed
433
////////////////////////////////////////////////// backup ///////////////////////////
Matthieu Kanj's avatar
Matthieu Kanj committed
434
//////////////////////////////////////////////////// SIB23 ////////////////////////////////////////////////////////////////////////
Matthieu Kanj's avatar
Matthieu Kanj committed
435 436 437 438 439 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
 /* if( (subframe >0) && (subframe !=5) && (With_NSSS == 0) && (frame%2==1) && (frame%64<16) )   ////if((subframe != 0)  && (subframe != 4) && (subframe != 9) ) 
  {
        

        if( subframe == 1 )
        {
            dlsch_encoding_NB_IoT(sib23_pdu,
                                  sib23,
                                  8,                      ///// number_of_subframes_required
                                  236);                   //////////// G*2
        
            dlsch_scrambling_Gen_NB_IoT(fp,                    // is called only in subframe 4
                                         sib23,
                                         1888,            //////   total_bits
                                         frame,
                                         subframe*2,
                                         eNB->ndlsch_SIB23->rnti);
        }

        if( subframe < 5 )
        {

        dlsch_modulation_NB_IoT(txdataF,
                                AMP,
                                fp,
                                3,                          // control region size for LTE , values between 0..3, (0 for stand-alone / 1, 2 or 3 for in-band)
                                sib23,
                                236,                       // number of bits per subframe
                                (subframe-1),   ///npdsch_data_subframe, data per subframe//subframe index of the data table of npdsch channel (G*Nsf) ((frame%32)/2),values are between 0..Nsf        
                                subframe,
                                RB_IoT_ID);
       } else {

         dlsch_modulation_NB_IoT(txdataF,
                                AMP,
                                fp,
                                3,                          // control region size for LTE , values between 0..3, (0 for stand-alone / 1, 2 or 3 for in-band)
                                sib23,
                                236,                       // number of bits per subframe
                                (subframe-2),///npdsch_data_subframe, data per subframe//subframe index of the data table of npdsch channel (G*Nsf) ((frame%32)/2),values are between 0..Nsf        
                                subframe,
                                RB_IoT_ID);

       }
        
  }
*/