SIB_NB_IoT.c 17.1 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 50
                   int                      RB_IoT_ID,
                   uint8_t                  operation_mode)
Matthieu Kanj's avatar
Matthieu Kanj committed
51 52 53
{
 	int done=0;
 	uint8_t *sib1_pdu  = sib1_struct->harq_process->pdu;
Matthieu Kanj's avatar
Matthieu Kanj committed
54 55 56 57 58
 	uint8_t opr_mode = 3;
 	if(operation_mode>=2)
 	{
 		opr_mode =0;
 	}
Matthieu Kanj's avatar
Matthieu Kanj committed
59 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
	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
99
        LOG_D(PHY,"[%3d][%2d] Generating SIB1\n",frame,subframe);
Matthieu Kanj's avatar
Matthieu Kanj committed
100
    	int G = get_G_SIB1_NB_IoT(frame_parms,operation_mode);
Matthieu Kanj's avatar
Matthieu Kanj committed
101 102 103 104 105 106

        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
107
                                  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
108 109 110
        
             dlsch_scrambling_Gen_NB_IoT(frame_parms,
                                         sib1_struct,
Matthieu Kanj's avatar
Matthieu Kanj committed
111
                                         8*G,
Matthieu Kanj's avatar
Matthieu Kanj committed
112 113 114 115 116 117 118 119
                                         frame, 
                                         subframe*2,
                                         sib1_struct->rnti);
        }

        dlsch_modulation_NB_IoT(txdataF,
                                amp,
                                frame_parms,
Matthieu Kanj's avatar
Matthieu Kanj committed
120
                                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
121
                                sib1_struct,
Matthieu Kanj's avatar
Matthieu Kanj committed
122
                                G,              // number of bits per subframe
Matthieu Kanj's avatar
Matthieu Kanj committed
123 124 125 126
                                ((frame%16)/2),
                                4,       
                                RB_IoT_ID);
        done =1;
Matthieu Kanj's avatar
Matthieu Kanj committed
127
        frame_parms->flag_free_sf =1;
Matthieu Kanj's avatar
Matthieu Kanj committed
128 129 130 131 132 133 134 135 136 137 138 139
        
    }

 return(done);
}


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

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

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

Matthieu Kanj's avatar
Matthieu Kanj committed
154 155
    	uint8_t *SIB23_pdu  = SIB23->harq_process->pdu;
	 	uint32_t rep =  SIB23->resource_assignment;
Matthieu Kanj's avatar
Matthieu Kanj committed
156
	 	uint8_t eutra_control_region = 3;
Matthieu Kanj's avatar
Matthieu Kanj committed
157 158 159 160

	    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
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
    	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,
                                         SIB23->rnti);
        }

        dlsch_modulation_NB_IoT(txdataF,
                                amp,
                                frame_parms,
Matthieu Kanj's avatar
Matthieu Kanj committed
182
                                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
183 184 185 186 187 188 189 190
                                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
191 192
        
        frame_parms->flag_free_sf =1;
Matthieu Kanj's avatar
Matthieu Kanj committed
193 194 195 196

        if(SIB23->counter_repetition_number == 0)
        {
        	SIB23->active = 0;
Matthieu Kanj's avatar
Matthieu Kanj committed
197
        	
Matthieu Kanj's avatar
Matthieu Kanj committed
198
        }
Matthieu Kanj's avatar
Matthieu Kanj committed
199
        done =1;
Matthieu Kanj's avatar
Matthieu Kanj committed
200 201 202 203
    }

 return(done);

Matthieu Kanj's avatar
Matthieu Kanj committed
204
}
Matthieu Kanj's avatar
Matthieu Kanj committed
205

Matthieu Kanj's avatar
Matthieu Kanj committed
206 207
////////////////////////////////////////////////////////////////////////

Matthieu Kanj's avatar
Matthieu Kanj committed
208 209 210 211 212 213 214 215 216 217 218

int generate_NDLSCH_NB_IoT(NB_IoT_eNB_NDLSCH_t 	  *RAR,
		                   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;

219
    if( RAR->active == 1 )
Matthieu Kanj's avatar
Matthieu Kanj committed
220 221 222
    {
    	uint8_t *RAR_pdu  = RAR->harq_process->pdu;
	 	uint32_t rep =  RAR->repetition_number;
Matthieu Kanj's avatar
Matthieu Kanj committed
223
	 	uint8_t eutra_control_region = 3;
Matthieu Kanj's avatar
Matthieu Kanj committed
224

Matthieu Kanj's avatar
Matthieu Kanj committed
225 226 227
	    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
228 229 230 231

    	int G = get_G_NB_IoT(frame_parms);
    	uint8_t Nsf = RAR->number_of_subframes_for_resource_assignment;

Nick Ho's avatar
Nick Ho committed
232
        //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
233

Matthieu Kanj's avatar
Matthieu Kanj committed
234 235 236 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 262 263 264 265 266 267 268
        if( (counter_rep == rep) && (counter_sf_rep == 0) && (pointer_to_sf == 0) )
        {
        	

            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,
                                         RAR->rnti);
        }

		if( (counter_rep != rep) && (counter_sf_rep == 0) && (pointer_to_sf == 0) )
		{
			dlsch_scrambling_Gen_NB_IoT(frame_parms,
                                         RAR,
                                         Nsf*G,
                                         frame, 
                                         subframe*2,
                                         RAR->rnti);
		}

        if( rep > 4)
        {

		        RAR->counter_current_sf_repetition++;

		        dlsch_modulation_NB_IoT(txdataF,
		                                amp,
		                                frame_parms,
Matthieu Kanj's avatar
Matthieu Kanj committed
269
		                                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
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
		                                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 {
288
                        //printf("RAR done\n");
Matthieu Kanj's avatar
Matthieu Kanj committed
289 290 291 292 293 294 295 296 297 298 299 300 301
		        		RAR->active = 0;
		        		done =1;
		        	}

		        }

        } else {

        		RAR->counter_current_sf_repetition++;

		        dlsch_modulation_NB_IoT(txdataF,
		                                amp,
		                                frame_parms,
Matthieu Kanj's avatar
Matthieu Kanj committed
302
		                                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
303 304 305 306 307 308 309 310 311 312 313 314
		                                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++;

		        	if (Nsf == RAR->pointer_to_subframe)
		        	{
315
                        //printf("RAR done\n");
Matthieu Kanj's avatar
Matthieu Kanj committed
316 317 318 319 320 321 322 323 324 325
		        		RAR->active = 0;
		        		done =1;
		        	}

		        }
        }   
    }

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

Matthieu Kanj's avatar
Matthieu Kanj committed
327 328
/////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
Matthieu Kanj's avatar
Matthieu Kanj committed
329
int generate_NPDCCH_NB_IoT(NB_IoT_eNB_NPDCCH_t 	  *DCI,
Matthieu Kanj's avatar
Matthieu Kanj committed
330 331 332 333 334 335 336 337
		                   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
338
    
Matthieu Kanj's avatar
Matthieu Kanj committed
339

Matthieu Kanj's avatar
Matthieu Kanj committed
340 341 342 343
 	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
344

345
		    if( DCI->active[i] == 1)
Matthieu Kanj's avatar
Matthieu Kanj committed
346
		    {
Nick Ho's avatar
Nick Ho committed
347
                //LOG_I(PHY,"[Frame: %d][Subframe: %d]sent DCI\n",frame,subframe);
Matthieu Kanj's avatar
Matthieu Kanj committed
348 349 350 351 352
		    	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
353

Matthieu Kanj's avatar
Matthieu Kanj committed
354 355
		    	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
356

Matthieu Kanj's avatar
Matthieu Kanj committed
357 358
		        if( counter_rep == rep)
		        {
Matthieu Kanj's avatar
Matthieu Kanj committed
359

Matthieu Kanj's avatar
Matthieu Kanj committed
360 361 362 363 364 365 366 367 368 369 370 371 372 373
		            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
374

Matthieu Kanj's avatar
Matthieu Kanj committed
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399
				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)
		        { 	
400
                        //printf("DCI REP done\n");
Matthieu Kanj's avatar
Matthieu Kanj committed
401 402 403 404 405 406
		        		DCI->active[i] = 0;
		        		done =1;
		        }
		          
		    }
	}
Matthieu Kanj's avatar
Matthieu Kanj committed
407 408 409
	return(done);
}

Matthieu Kanj's avatar
Matthieu Kanj committed
410

Matthieu Kanj's avatar
Matthieu Kanj committed
411
////////////////////////////////////////////////// backup ///////////////////////////
Matthieu Kanj's avatar
Matthieu Kanj committed
412
//////////////////////////////////////////////////// SIB23 ////////////////////////////////////////////////////////////////////////
Matthieu Kanj's avatar
Matthieu Kanj committed
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 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
 /* 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);

       }
        
  }
*/