eNB_scheduler_RA.c 19.9 KB
Newer Older
knopp's avatar
 
knopp 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
/*******************************************************************************
    OpenAirInterface
    Copyright(c) 1999 - 2014 Eurecom

    OpenAirInterface is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.


    OpenAirInterface is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with OpenAirInterface.The full GNU General Public License is
   included in this distribution in the file called "COPYING". If not,
   see <http://www.gnu.org/licenses/>.

  Contact Information
  OpenAirInterface Admin: openair_admin@eurecom.fr
  OpenAirInterface Tech : openair_tech@eurecom.fr
  OpenAirInterface Dev  : openair4g-devel@eurecom.fr

  Address      : Eurecom, Compus SophiaTech 450, route des chappes, 06451 Biot, France.

gauthier's avatar
   
gauthier committed
28
 *******************************************************************************/
knopp's avatar
 
knopp committed
29

30
/*! \file eNB_scheduler_RA.c
31
 * \brief primitives used for random access
knopp's avatar
 
knopp committed
32
33
34
35
36
37
38
39
40
 * \author  Navid Nikaein and Raymond Knopp
 * \date 2010 - 2014
 * \email: navid.nikaein@eurecom.fr
 * \version 1.0
 * @ingroup _mac

 */

#include "assertions.h"
41
#include "platform_types.h"
knopp's avatar
 
knopp committed
42
43
#include "PHY/defs.h"
#include "PHY/extern.h"
gauthier's avatar
gauthier committed
44
#include "msc.h"
knopp's avatar
 
knopp committed
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

#include "SCHED/defs.h"
#include "SCHED/extern.h"

#include "LAYER2/MAC/defs.h"
#include "LAYER2/MAC/extern.h"

#include "LAYER2/MAC/proto.h"
#include "UTIL/LOG/log.h"
#include "UTIL/LOG/vcd_signal_dumper.h"
#include "UTIL/OPT/opt.h"
#include "OCG.h"
#include "OCG_extern.h"

#include "RRC/LITE/extern.h"
#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h"

//#include "LAYER2/MAC/pre_processor.c"
#include "pdcp.h"

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

69
extern inline unsigned int taus(void);
knopp's avatar
 
knopp committed
70

71
72
void schedule_RA(module_id_t module_idP,frame_t frameP, sub_frame_t subframeP,unsigned char Msg3_subframe,unsigned int *nprb,unsigned int *nCCE)
{
knopp's avatar
 
knopp committed
73

74
75
  int CC_id;
  eNB_MAC_INST *eNB = &eNB_mac_inst[module_idP];
gauthier's avatar
   
gauthier committed
76
77


78
79
80
81
82
83
84
  RA_TEMPLATE *RA_template;
  unsigned char i;//,harq_pid,round;
  int16_t rrc_sdu_length;
  unsigned char lcid,offset;
  module_id_t UE_id= UE_INDEX_INVALID;
  unsigned short TBsize = -1;
  unsigned short msg4_padding,msg4_post_padding,msg4_header;
gauthier's avatar
   
gauthier committed
85

86
  start_meas(&eNB->schedule_ra);
gauthier's avatar
   
gauthier committed
87

88
  for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
gauthier's avatar
   
gauthier committed
89

90
    RA_template = (RA_TEMPLATE *)&eNB->common_channels[CC_id].RA_template[0];
gauthier's avatar
   
gauthier committed
91

92
    for (i=0; i<NB_RA_PROC_MAX; i++) {
gauthier's avatar
   
gauthier committed
93

94
      if (RA_template[i].RA_active == TRUE) {
gauthier's avatar
   
gauthier committed
95

96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
        LOG_D(MAC,"[eNB %d][RAPROC] RA %d is active (generate RAR %d, generate_Msg4 %d, wait_ack_Msg4 %d, rnti %x)\n",
              module_idP,i,RA_template[i].generate_rar,RA_template[i].generate_Msg4,RA_template[i].wait_ack_Msg4, RA_template[i].rnti);

        if (RA_template[i].generate_rar == 1) {
          nprb[CC_id]= nprb[CC_id] + 3;
          nCCE[CC_id] = nCCE[CC_id] + 4;
          RA_template[i].Msg3_subframe=Msg3_subframe;
        } else if (RA_template[i].generate_Msg4 == 1) {

          // check for Msg4 Message
          UE_id = find_UE_id(module_idP,RA_template[i].rnti);

          if (Is_rrc_registered == 1) {

            // Get RRCConnectionSetup for Piggyback
            rrc_sdu_length = mac_rrc_data_req(module_idP,
                                              frameP,
113
114
                                              CCCH,
                                              1, // 1 transport block
115
                                              &eNB->common_channels[CC_id].CCCH_pdu.payload[0],
116
                                              ENB_FLAG_YES,
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
                                              module_idP,
                                              0); // not used in this case

            if (rrc_sdu_length == -1) {
              mac_xface->macphy_exit("[MAC][eNB Scheduler] CCCH not allocated\n");
              return; // not reached
            } else {
              //msg("[MAC][eNB %d] Frame %d, subframeP %d: got %d bytes from RRC\n",module_idP,frameP, subframeP,rrc_sdu_length);
            }
          }

          LOG_D(MAC,"[eNB %d][RAPROC] Frame %d, subframeP %d: UE_id %d, Is_rrc_registered %d, rrc_sdu_length %d\n",
                module_idP,frameP, subframeP,UE_id, Is_rrc_registered,rrc_sdu_length);

          if (rrc_sdu_length>0) {
            LOG_I(MAC,"[eNB %d][RAPROC] Frame %d, subframeP %d: Generating Msg4 with RRC Piggyback (RA proc %d, RNTI %x)\n",
                  module_idP,frameP, subframeP,i,RA_template[i].rnti);

            //msg("[MAC][eNB %d][RAPROC] Frame %d, subframeP %d: Received %d bytes for Msg4: \n",module_idP,frameP,subframeP,rrc_sdu_length);
            //    for (j=0;j<rrc_sdu_length;j++)
            //      msg("%x ",(unsigned char)eNB_mac_inst[module_idP][CC_id].CCCH_pdu.payload[j]);
            //    msg("\n");
            //    msg("[MAC][eNB] Frame %d, subframeP %d: Generated DLSCH (Msg4) DCI, format 1A, for UE %d\n",frameP, subframeP,UE_id);
            // Schedule Reflection of Connection request



            // Compute MCS for 3 PRB
            msg4_header = 1+6+1;  // CR header, CR CE, SDU header

            if (mac_xface->lte_frame_parms->frame_type == TDD) {

              switch (mac_xface->lte_frame_parms->N_RB_DL) {
              case 6:
                ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->ndi=1;

                if ((rrc_sdu_length+msg4_header) <= 22) {
                  ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=4;
                  TBsize = 22;
                } else if ((rrc_sdu_length+msg4_header) <= 28) {
                  ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=5;
                  TBsize = 28;
                } else if ((rrc_sdu_length+msg4_header) <= 32) {
                  ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=6;
                  TBsize = 32;
                } else if ((rrc_sdu_length+msg4_header) <= 41) {
                  ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=7;
                  TBsize = 41;
                } else if ((rrc_sdu_length+msg4_header) <= 49) {
                  ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=8;
                  TBsize = 49;
                } else if ((rrc_sdu_length+msg4_header) <= 57) {
                  ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=9;
                  TBsize = 57;
gauthier's avatar
   
gauthier committed
171
                }
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300

                break;

              case 25:

                ((DCI1A_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->ndi=1;

                if ((rrc_sdu_length+msg4_header) <= 22) {
                  ((DCI1A_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=4;
                  TBsize = 22;
                } else if ((rrc_sdu_length+msg4_header) <= 28) {
                  ((DCI1A_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=5;
                  TBsize = 28;
                } else if ((rrc_sdu_length+msg4_header) <= 32) {
                  ((DCI1A_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=6;
                  TBsize = 32;
                } else if ((rrc_sdu_length+msg4_header) <= 41) {
                  ((DCI1A_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=7;
                  TBsize = 41;
                } else if ((rrc_sdu_length+msg4_header) <= 49) {
                  ((DCI1A_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=8;
                  TBsize = 49;
                } else if ((rrc_sdu_length+msg4_header) <= 57) {
                  ((DCI1A_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=9;
                  TBsize = 57;
                }

                break;

              case 50:

                ((DCI1A_10MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->ndi=1;

                if ((rrc_sdu_length+msg4_header) <= 22) {
                  ((DCI1A_10MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=4;
                  TBsize = 22;
                } else if ((rrc_sdu_length+msg4_header) <= 28) {
                  ((DCI1A_10MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=5;
                  TBsize = 28;
                } else if ((rrc_sdu_length+msg4_header) <= 32) {
                  ((DCI1A_10MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=6;
                  TBsize = 32;
                } else if ((rrc_sdu_length+msg4_header) <= 41) {
                  ((DCI1A_10MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=7;
                  TBsize = 41;
                } else if ((rrc_sdu_length+msg4_header) <= 49) {
                  ((DCI1A_10MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=8;
                  TBsize = 49;
                } else if ((rrc_sdu_length+msg4_header) <= 57) {
                  ((DCI1A_10MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=9;
                  TBsize = 57;
                }

                break;

              case 100:

                ((DCI1A_20MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->ndi=1;

                if ((rrc_sdu_length+msg4_header) <= 22) {
                  ((DCI1A_20MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=4;
                  TBsize = 22;
                } else if ((rrc_sdu_length+msg4_header) <= 28) {
                  ((DCI1A_20MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=5;
                  TBsize = 28;
                } else if ((rrc_sdu_length+msg4_header) <= 32) {
                  ((DCI1A_20MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=6;
                  TBsize = 32;
                } else if ((rrc_sdu_length+msg4_header) <= 41) {
                  ((DCI1A_20MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=7;
                  TBsize = 41;
                } else if ((rrc_sdu_length+msg4_header) <= 49) {
                  ((DCI1A_20MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=8;
                  TBsize = 49;
                } else if ((rrc_sdu_length+msg4_header) <= 57) {
                  ((DCI1A_20MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=9;
                  TBsize = 57;
                }

                break;
              }
            } else { // FDD DCI
              switch (mac_xface->lte_frame_parms->N_RB_DL) {
              case 6:
                ((DCI1A_1_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->ndi=1;

                if ((rrc_sdu_length+msg4_header) <= 22) {
                  ((DCI1A_1_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=4;
                  TBsize = 22;
                } else if ((rrc_sdu_length+msg4_header) <= 28) {
                  ((DCI1A_1_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=5;
                  TBsize = 28;
                } else if ((rrc_sdu_length+msg4_header) <= 32) {
                  ((DCI1A_1_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=6;
                  TBsize = 32;
                } else if ((rrc_sdu_length+msg4_header) <= 41) {
                  ((DCI1A_1_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=7;
                  TBsize = 41;
                } else if ((rrc_sdu_length+msg4_header) <= 49) {
                  ((DCI1A_1_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=8;
                  TBsize = 49;
                } else if ((rrc_sdu_length+msg4_header) <= 57) {
                  ((DCI1A_1_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=9;
                  TBsize = 57;
                }

                break;

              case 25:
                ((DCI1A_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->ndi=1;

                if ((rrc_sdu_length+msg4_header) <= 22) {
                  ((DCI1A_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=4;
                  TBsize = 22;
                } else if ((rrc_sdu_length+msg4_header) <= 28) {
                  ((DCI1A_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=5;
                  TBsize = 28;
                } else if ((rrc_sdu_length+msg4_header) <= 32) {
                  ((DCI1A_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=6;
                  TBsize = 32;
                } else if ((rrc_sdu_length+msg4_header) <= 41) {
                  ((DCI1A_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=7;
                  TBsize = 41;
                } else if ((rrc_sdu_length+msg4_header) <= 49) {
                  ((DCI1A_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=8;
                  TBsize = 49;
                } else if ((rrc_sdu_length+msg4_header) <= 57) {
                  ((DCI1A_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=9;
                  TBsize = 57;
gauthier's avatar
   
gauthier committed
301
                }
knopp's avatar
 
knopp committed
302

303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
                break;

              case 50:
                ((DCI1A_10MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->ndi=1;

                if ((rrc_sdu_length+msg4_header) <= 22) {
                  ((DCI1A_10MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=4;
                  TBsize = 22;
                } else if ((rrc_sdu_length+msg4_header) <= 28) {
                  ((DCI1A_10MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=5;
                  TBsize = 28;
                } else if ((rrc_sdu_length+msg4_header) <= 32) {
                  ((DCI1A_10MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=6;
                  TBsize = 32;
                } else if ((rrc_sdu_length+msg4_header) <= 41) {
                  ((DCI1A_10MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=7;
                  TBsize = 41;
                } else if ((rrc_sdu_length+msg4_header) <= 49) {
                  ((DCI1A_10MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=8;
                  TBsize = 49;
                } else if ((rrc_sdu_length+msg4_header) <= 57) {
                  ((DCI1A_10MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=9;
                  TBsize = 57;
                }
knopp's avatar
 
knopp committed
327

328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
                break;

              case 100:
                ((DCI1A_20MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->ndi=1;

                if ((rrc_sdu_length+msg4_header) <= 22) {
                  ((DCI1A_20MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=4;
                  TBsize = 22;
                } else if ((rrc_sdu_length+msg4_header) <= 28) {
                  ((DCI1A_20MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=5;
                  TBsize = 28;
                } else if ((rrc_sdu_length+msg4_header) <= 32) {
                  ((DCI1A_20MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=6;
                  TBsize = 32;
                } else if ((rrc_sdu_length+msg4_header) <= 41) {
                  ((DCI1A_20MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=7;
                  TBsize = 41;
                } else if ((rrc_sdu_length+msg4_header) <= 49) {
                  ((DCI1A_20MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=8;
                  TBsize = 49;
                } else if ((rrc_sdu_length+msg4_header) <= 57) {
                  ((DCI1A_20MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=9;
                  TBsize = 57;
                }
                break;
              }
            }
gauthier's avatar
   
gauthier committed
355
356

            RA_template[i].generate_Msg4=0;
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
            RA_template[i].generate_Msg4_dci=1;
            RA_template[i].wait_ack_Msg4=1;
            RA_template[i].RA_active = FALSE;
            lcid=0;

            if ((TBsize - rrc_sdu_length - msg4_header) <= 2) {
              msg4_padding = TBsize - rrc_sdu_length - msg4_header;
              msg4_post_padding = 0;
            } else {
              msg4_padding = 0;
              msg4_post_padding = TBsize - rrc_sdu_length - msg4_header -1;
            }

            LOG_I(MAC,"[eNB %d][RAPROC] Frame %d subframeP %d Msg4 : TBS %d, sdu_len %d, msg4_header %d, msg4_padding %d, msg4_post_padding %d\n",
                  module_idP,frameP,subframeP,TBsize,rrc_sdu_length,msg4_header,msg4_padding,msg4_post_padding);
            DevAssert( UE_id != UE_INDEX_INVALID ); // FIXME not sure how to gracefully return
            offset = generate_dlsch_header((unsigned char*)eNB->UE_list.DLSCH_pdu[CC_id][0][(unsigned char)UE_id].payload[0],
                                           1,                           //num_sdus
                                           (unsigned short*)&rrc_sdu_length,             //
                                           &lcid,                       // sdu_lcid
                                           255,                         // no drx
                                           0,                           // no timing advance
                                           RA_template[i].cont_res_id,  // contention res id
                                           msg4_padding,                // no padding
                                           msg4_post_padding);

            memcpy((void*)&eNB->UE_list.DLSCH_pdu[CC_id][0][(unsigned char)UE_id].payload[0][(unsigned char)offset],
                   &eNB->common_channels[CC_id].CCCH_pdu.payload[0],
                   rrc_sdu_length);

387
388
389
390
391
392
393
394
	    if (opt_enabled==1){
	      trace_pdu(1, (uint8_t *)eNB->UE_list.DLSCH_pdu[CC_id][0][(unsigned char)UE_id].payload[0],
			rrc_sdu_length, UE_id, 3, UE_RNTI(module_idP, UE_id),
			eNB->subframe,0,0);
	      LOG_D(OPT,"[eNB %d][DLSCH] Frame %d trace pdu for rnti %x with size %d\n",
		    module_idP, frameP, UE_RNTI(module_idP,UE_id), rrc_sdu_length);
	    }

395
396
397
398
399
            nprb[CC_id]= nprb[CC_id] + 3;
            nCCE[CC_id] = nCCE[CC_id] + 4;
          }

          //try here
gauthier's avatar
   
gauthier committed
400
        }
401
402
403
404
405
406
407
408
409
410
411
412
413
414

        /*
        else if (eNB_mac_inst[module_idP][CC_id].RA_template[i].wait_ack_Msg4==1) {
        // check HARQ status and retransmit if necessary
        LOG_I(MAC,"[eNB %d][RAPROC] Frame %d, subframeP %d: Checking if Msg4 was acknowledged :\n",module_idP,frameP,subframeP);
        // Get candidate harq_pid from PHY
        mac_xface->get_ue_active_harq_pid(module_idP,eNB_mac_inst[module_idP][CC_id].RA_template[i].rnti,subframeP,&harq_pid,&round,0);
        if (round>0) {
         *nprb= (*nprb) + 3;
         *nCCE = (*nCCE) + 4;
        }
        }
         */
      }
knopp's avatar
 
knopp committed
415
    }
416
  }
knopp's avatar
 
knopp committed
417

418
419
  stop_meas(&eNB->schedule_ra);
}
gauthier's avatar
   
gauthier committed
420

421
422
void initiate_ra_proc(module_id_t module_idP, int CC_id,frame_t frameP, uint16_t preamble_index,int16_t timing_offset,uint8_t sect_id,sub_frame_t subframeP,
                      uint8_t f_id)
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
{

  uint8_t i;
  RA_TEMPLATE *RA_template = (RA_TEMPLATE *)&eNB_mac_inst[module_idP].common_channels[CC_id].RA_template[0];

  LOG_I(MAC,"[eNB %d][RAPROC] Frame %d Initiating RA procedure for preamble index %d\n",module_idP,frameP,preamble_index);

  for (i=0; i<NB_RA_PROC_MAX; i++) {
    if (RA_template[i].RA_active==FALSE) {
      RA_template[i].RA_active=TRUE;
      RA_template[i].generate_rar=1;
      RA_template[i].generate_Msg4=0;
      RA_template[i].wait_ack_Msg4=0;
      RA_template[i].timing_offset=timing_offset;
      // Put in random rnti (to be replaced with proper procedure!!)
      RA_template[i].rnti = taus();
      RA_template[i].RA_rnti = 1+subframeP+(10*f_id);
      RA_template[i].preamble_index = preamble_index;
      LOG_D(MAC,"[eNB %d][RAPROC] Frame %d Activating RAR generation for process %d, rnti %x, RA_active %d\n",
            module_idP,frameP,i,RA_template[i].rnti,
            RA_template[i].RA_active);

      return;
    }
  }
}
gauthier's avatar
   
gauthier committed
449

450
451
452
453
454
void cancel_ra_proc(module_id_t module_idP, int CC_id, frame_t frameP, rnti_t rnti)
{
  unsigned char i;
  RA_TEMPLATE *RA_template = (RA_TEMPLATE *)&eNB_mac_inst[module_idP].common_channels[CC_id].RA_template[0];

gauthier's avatar
gauthier committed
455
  MSC_LOG_EVENT(MSC_PHY_ENB, "RA Cancelling procedure ue %"PRIx16" ", rnti);
456
457
458
459
460
461
462
463
464
465
466
  LOG_I(MAC,"[eNB %d][RAPROC] Frame %d Cancelling RA procedure for UE rnti %x\n",module_idP,frameP,rnti);

  for (i=0; i<NB_RA_PROC_MAX; i++) {
    if (rnti == RA_template[i].rnti) {
      RA_template[i].RA_active=FALSE;
      RA_template[i].generate_rar=0;
      RA_template[i].generate_Msg4=0;
      RA_template[i].wait_ack_Msg4=0;
      RA_template[i].timing_offset=0;
      RA_template[i].RRC_timer=20;
      RA_template[i].rnti = 0;
knopp's avatar
 
knopp committed
467
    }
468
  }
knopp's avatar
 
knopp committed
469
470
}