eNB_scheduler_ulsch.c 56.1 KB
Newer Older
1
2
3
4
5
/*
 * 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
Cédric Roux's avatar
Cédric Roux committed
6
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 * 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
 */
nikaeinn's avatar
nikaeinn committed
21
22
23

/*! \file eNB_scheduler_ulsch.c
 * \brief eNB procedures for the ULSCH transport channel
24
25
26
 * \author Navid Nikaein and Raymond Knopp
 * \date 2010 - 2014
 * \email: navid.nikaein@eurecom.fr
nikaeinn's avatar
nikaeinn committed
27
 * \version 1.0
28
29
30
31
 * @ingroup _mac

 */

32
33
/* indented with: indent -kr eNB_scheduler_RA.c */

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "assertions.h"
#include "PHY/defs.h"
#include "PHY/extern.h"

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

#include "LAYER2/MAC/defs.h"
#include "LAYER2/MAC/proto.h"
#include "LAYER2/MAC/extern.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)
57
#include "intertask_interface.h"
58
59
#endif

Cédric Roux's avatar
Cédric Roux committed
60
61
#include "T.h"

62
#define ENABLE_MAC_PAYLOAD_DEBUG
63
64
65
#define DEBUG_eNB_SCHEDULER 1

// This table holds the allowable PRB sizes for ULSCH transmissions
66
67
68
69
70
71
72
73
74
75
76
77
78
79
uint8_t rb_table[34] =
    { 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, 18, 20, 24, 25, 27, 30, 32,
    36, 40, 45, 48, 50, 54, 60, 64, 72, 75, 80, 81, 90, 96, 100
};

void
rx_sdu(const module_id_t enb_mod_idP,
       const int CC_idP,
       const frame_t frameP,
       const sub_frame_t subframeP,
       const rnti_t rntiP,
       uint8_t * sduP,
       const uint16_t sdu_lenP,
       const uint16_t timing_advance, const uint8_t ul_cqi)
Cédric Roux's avatar
Cédric Roux committed
80
{
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
    int current_rnti = rntiP;
    unsigned char rx_ces[MAX_NUM_CE], num_ce, num_sdu, i, *payload_ptr;
    unsigned char rx_lcids[NB_RB_MAX];
    unsigned short rx_lengths[NB_RB_MAX];
    int UE_id = find_UE_id(enb_mod_idP, current_rnti);
    int RA_id;
    int ii, j;
    eNB_MAC_INST *mac = RC.mac[enb_mod_idP];
    int harq_pid =
	subframe2harqpid(&mac->common_channels[CC_idP], frameP, subframeP);

    UE_list_t *UE_list = &mac->UE_list;
    int crnti_rx = 0;
    int old_buffer_info;
    RA_t *ra =
	(RA_t *) & RC.mac[enb_mod_idP]->common_channels[CC_idP].ra[0];
    int first_rb = 0;

    start_meas(&mac->rx_ulsch_sdu);

    if ((UE_id > NUMBER_OF_UE_MAX) || (UE_id == -1))
	for (ii = 0; ii < NB_RB_MAX; ii++) {
	    rx_lengths[ii] = 0;
	}

    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME
	(VCD_SIGNAL_DUMPER_FUNCTIONS_RX_SDU, 1);
    if (opt_enabled == 1) {
	trace_pdu(0, sduP, sdu_lenP, 0, 3, current_rnti, frameP, subframeP,
		  0, 0);
	LOG_D(OPT, "[eNB %d][ULSCH] Frame %d  rnti %x  with size %d\n",
	      enb_mod_idP, frameP, current_rnti, sdu_lenP);
Florian Kaltenberger's avatar
Florian Kaltenberger committed
113
    }
114

115
116
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
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
    if (UE_id != -1) {
	LOG_D(MAC,
	      "[eNB %d][PUSCH %d] CC_id %d Received ULSCH sdu round %d from PHY (rnti %x, UE_id %d) ul_cqi %d\n",
	      enb_mod_idP, harq_pid, CC_idP,
	      UE_list->UE_sched_ctrl[UE_id].round_UL[CC_idP][harq_pid],
	      current_rnti, UE_id, ul_cqi);

	AssertFatal(UE_list->UE_sched_ctrl[UE_id].
		    round_UL[CC_idP][harq_pid] < 8, "round >= 8\n");
	if (sduP != NULL) {
	    UE_list->UE_sched_ctrl[UE_id].ul_inactivity_timer = 0;
	    UE_list->UE_sched_ctrl[UE_id].ul_failure_timer = 0;
	    UE_list->UE_sched_ctrl[UE_id].ul_scheduled &=
		(~(1 << harq_pid));
	    /* Update with smoothing: 3/4 of old value and 1/4 of new.
	     * This is the logic that was done in the function
	     * lte_est_timing_advance_pusch, maybe it's not necessary?
	     * maybe it's even not correct at all?
	     */
	    UE_list->UE_sched_ctrl[UE_id].ta_update =
		(UE_list->UE_sched_ctrl[UE_id].ta_update * 3 +
		 timing_advance) / 4;
	    UE_list->UE_sched_ctrl[UE_id].pusch_snr[CC_idP] = ul_cqi;
	    UE_list->UE_sched_ctrl[UE_id].ul_consecutive_errors = 0;
	    first_rb =
		UE_list->UE_template[CC_idP][UE_id].first_rb_ul[harq_pid];

	    if (UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync > 0) {
		UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync = 0;
		mac_eNB_rrc_ul_in_sync(enb_mod_idP, CC_idP, frameP,
				       subframeP, UE_RNTI(enb_mod_idP,
							  UE_id));
	    }
	} else {		// we've got an error
	    LOG_D(MAC,
		  "[eNB %d][PUSCH %d] CC_id %d ULSCH in error in round %d, ul_cqi %d\n",
		  enb_mod_idP, harq_pid, CC_idP,
		  UE_list->UE_sched_ctrl[UE_id].round_UL[CC_idP][harq_pid],
		  ul_cqi);

	    //      AssertFatal(1==0,"ulsch in error\n");
	    if (UE_list->UE_sched_ctrl[UE_id].round_UL[CC_idP][harq_pid] ==
		3) {
		UE_list->UE_sched_ctrl[UE_id].ul_scheduled &=
		    (~(1 << harq_pid));
		UE_list->UE_sched_ctrl[UE_id].round_UL[CC_idP][harq_pid] =
		    0;
		if (UE_list->UE_sched_ctrl[UE_id].
		    ul_consecutive_errors++ == 10)
		    UE_list->UE_sched_ctrl[UE_id].ul_failure_timer = 1;
	    } else
		UE_list->UE_sched_ctrl[UE_id].round_UL[CC_idP][harq_pid]++;
	    return;

	}
    } else if ((RA_id = find_RA_id(enb_mod_idP, CC_idP, current_rnti)) != -1) {	// Check if this is an RA process for the rnti
	AssertFatal(mac->common_channels[CC_idP].
		    radioResourceConfigCommon->rach_ConfigCommon.
		    maxHARQ_Msg3Tx > 1,
		    "maxHARQ %d should be greater than 1\n",
		    (int) mac->common_channels[CC_idP].
		    radioResourceConfigCommon->rach_ConfigCommon.
		    maxHARQ_Msg3Tx);

	LOG_D(MAC,
	      "[eNB %d][PUSCH %d] CC_id %d Received ULSCH sdu round %d from PHY (rnti %x, RA_id %d) ul_cqi %d\n",
	      enb_mod_idP, harq_pid, CC_idP, ra[RA_id].msg3_round,
	      current_rnti, RA_id, ul_cqi);

	first_rb = ra->msg3_first_rb;

	if (sduP == NULL) {	// we've got an error on Msg3
	    LOG_D(MAC,
		  "[eNB %d] CC_id %d, RA %d ULSCH in error in round %d/%d\n",
		  enb_mod_idP, CC_idP, RA_id,
		  ra[RA_id].msg3_round,
		  (int) mac->common_channels[CC_idP].
		  radioResourceConfigCommon->rach_ConfigCommon.
		  maxHARQ_Msg3Tx);
	    if (ra[RA_id].msg3_round ==
		mac->common_channels[CC_idP].radioResourceConfigCommon->
		rach_ConfigCommon.maxHARQ_Msg3Tx - 1) {
		cancel_ra_proc(enb_mod_idP, CC_idP, frameP, current_rnti);
	    }

	    else {
		first_rb =
		    UE_list->UE_template[CC_idP][UE_id].
		    first_rb_ul[harq_pid];
		ra[RA_id].msg3_round++;
		// prepare handling of retransmission
		ra[RA_id].Msg3_frame +=
		    ((ra[RA_id].Msg3_subframe > 1) ? 1 : 0);
		ra[RA_id].Msg3_subframe =
		    (ra[RA_id].Msg3_subframe + 8) % 10;
		add_msg3(enb_mod_idP, CC_idP, &ra[RA_id], frameP,
			 subframeP);
	    }
	    return;
	}
    } else {
	LOG_W(MAC,
	      "Cannot find UE or RA corresponding to ULSCH rnti %x, dropping it\n",
	      current_rnti);
	return;
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
    payload_ptr =
	parse_ulsch_header(sduP, &num_ce, &num_sdu, rx_ces, rx_lcids,
			   rx_lengths, sdu_lenP);

    T(T_ENB_MAC_UE_UL_PDU, T_INT(enb_mod_idP), T_INT(CC_idP),
      T_INT(current_rnti), T_INT(frameP), T_INT(subframeP),
      T_INT(harq_pid), T_INT(sdu_lenP), T_INT(num_ce), T_INT(num_sdu));
    T(T_ENB_MAC_UE_UL_PDU_WITH_DATA, T_INT(enb_mod_idP), T_INT(CC_idP),
      T_INT(current_rnti), T_INT(frameP), T_INT(subframeP),
      T_INT(harq_pid), T_INT(sdu_lenP), T_INT(num_ce), T_INT(num_sdu),
      T_BUFFER(sduP, sdu_lenP));

    mac->eNB_stats[CC_idP].ulsch_bytes_rx = sdu_lenP;
    mac->eNB_stats[CC_idP].total_ulsch_bytes_rx += sdu_lenP;
    mac->eNB_stats[CC_idP].total_ulsch_pdus_rx += 1;

    UE_list->UE_sched_ctrl[UE_id].round_UL[CC_idP][harq_pid] = 0;

    // control element
    for (i = 0; i < num_ce; i++) {

	T(T_ENB_MAC_UE_UL_CE, T_INT(enb_mod_idP), T_INT(CC_idP),
	  T_INT(current_rnti), T_INT(frameP), T_INT(subframeP),
	  T_INT(rx_ces[i]));

	switch (rx_ces[i]) {	// implement and process BSR + CRNTI +
	case POWER_HEADROOM:
	    if (UE_id != -1) {
		UE_list->UE_template[CC_idP][UE_id].phr_info =
		    (payload_ptr[0] & 0x3f) - PHR_MAPPING_OFFSET;
		LOG_D(MAC,
		      "[eNB %d] CC_id %d MAC CE_LCID %d : Received PHR PH = %d (db)\n",
		      enb_mod_idP, CC_idP, rx_ces[i],
		      UE_list->UE_template[CC_idP][UE_id].phr_info);
		UE_list->UE_template[CC_idP][UE_id].phr_info_configured =
		    1;
		UE_list->UE_sched_ctrl[UE_id].phr_received = 1;
	    }
	    payload_ptr += sizeof(POWER_HEADROOM_CMD);
	    break;

	case CRNTI:
	    {
		int old_rnti =
		    (((uint16_t) payload_ptr[0]) << 8) + payload_ptr[1];
		int old_UE_id = find_UE_id(enb_mod_idP, old_rnti);
		LOG_D(MAC,
		      "[eNB %d] Frame %d, Subframe %d CC_id %d MAC CE_LCID %d (ce %d/%d): CRNTI %x (UE_id %d) in Msg3\n",
		      enb_mod_idP, frameP, subframeP, CC_idP, rx_ces[i], i,
		      num_ce, old_rnti, old_UE_id);
271
272
273
		/* receiving CRNTI means that the current rnti has to go away */
		cancel_ra_proc(enb_mod_idP, CC_idP, frameP,
			       current_rnti);
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
301
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
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
355
356
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
387
388
389
390
391
392
393
394
395
396
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
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
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
		if (old_UE_id != -1) {
		    /* TODO: if the UE did random access (followed by a MAC uplink with
		     * CRNTI) because none of its scheduling request was granted, then
		     * according to 36.321 5.4.4 the UE's MAC will notify RRC to release
		     * PUCCH/SRS. According to 36.331 5.3.13 the UE will then apply
		     * default configuration for CQI reporting and scheduling requests,
		     * which basically means that the CQI requests won't work anymore and
		     * that the UE won't do any scheduling request anymore as long as the
		     * eNB doesn't reconfigure the UE.
		     * We have to take care of this. As the code is, nothing is done and
		     * the UE state in the eNB is wrong.
		     */
		    UE_id = old_UE_id;
		    UE_list->UE_sched_ctrl[UE_id].ul_inactivity_timer = 0;
		    UE_list->UE_sched_ctrl[UE_id].ul_failure_timer = 0;
		    if (UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync > 0) {
			UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync = 0;
			mac_eNB_rrc_ul_in_sync(enb_mod_idP, CC_idP, frameP,
					       subframeP, old_rnti);
		    }
		    current_rnti = old_rnti;
		}
		crnti_rx = 1;
		payload_ptr += 2;
		break;
	    }

	case TRUNCATED_BSR:
	case SHORT_BSR:
	    {
		uint8_t lcgid;
		lcgid = (payload_ptr[0] >> 6);

		LOG_D(MAC,
		      "[eNB %d] CC_id %d MAC CE_LCID %d : Received short BSR LCGID = %u bsr = %d\n",
		      enb_mod_idP, CC_idP, rx_ces[i], lcgid,
		      payload_ptr[0] & 0x3f);

		if (crnti_rx == 1)
		    LOG_D(MAC,
			  "[eNB %d] CC_id %d MAC CE_LCID %d : Received short BSR LCGID = %u bsr = %d\n",
			  enb_mod_idP, CC_idP, rx_ces[i], lcgid,
			  payload_ptr[0] & 0x3f);
		if (UE_id != -1) {

		    UE_list->UE_template[CC_idP][UE_id].bsr_info[lcgid] =
			(payload_ptr[0] & 0x3f);

		    // update buffer info

		    UE_list->UE_template[CC_idP][UE_id].
			ul_buffer_info[lcgid] =
			BSR_TABLE[UE_list->UE_template[CC_idP][UE_id].
				  bsr_info[lcgid]];

		    UE_list->UE_template[CC_idP][UE_id].ul_total_buffer =
			UE_list->UE_template[CC_idP][UE_id].
			ul_buffer_info[lcgid];

		    RC.eNB[enb_mod_idP][CC_idP]->
			pusch_stats_bsr[UE_id][(frameP * 10) + subframeP]
			= (payload_ptr[0] & 0x3f);
		    if (UE_id == UE_list->head)
			VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME
			    (VCD_SIGNAL_DUMPER_VARIABLES_UE0_BSR,
			     RC.eNB[enb_mod_idP][CC_idP]->pusch_stats_bsr
			     [UE_id][(frameP * 10) + subframeP]);
		    if (UE_list->UE_template[CC_idP][UE_id].
			ul_buffer_creation_time[lcgid]
			== 0) {
			UE_list->UE_template[CC_idP]
			    [UE_id].ul_buffer_creation_time[lcgid] =
			    frameP;
		    }
		    if (mac_eNB_get_rrc_status
			(enb_mod_idP,
			 UE_RNTI(enb_mod_idP, UE_id)) < RRC_CONNECTED)
			LOG_D(MAC,
			      "[eNB %d] CC_id %d MAC CE_LCID %d : ul_total_buffer = %d (lcg increment %d)\n",
			      enb_mod_idP, CC_idP, rx_ces[i],
			      UE_list->UE_template[CC_idP][UE_id].
			      ul_total_buffer,
			      UE_list->UE_template[CC_idP][UE_id].
			      ul_buffer_info[lcgid]);
		} else {

		}
		payload_ptr += 1;	//sizeof(SHORT_BSR); // fixme
	    }
	    break;

	case LONG_BSR:
	    if (UE_id != -1) {
		UE_list->UE_template[CC_idP][UE_id].bsr_info[LCGID0] =
		    ((payload_ptr[0] & 0xFC) >> 2);
		UE_list->UE_template[CC_idP][UE_id].bsr_info[LCGID1] =
		    ((payload_ptr[0] & 0x03) << 4) |
		    ((payload_ptr[1] & 0xF0) >> 4);
		UE_list->UE_template[CC_idP][UE_id].bsr_info[LCGID2] =
		    ((payload_ptr[1] & 0x0F) << 2) |
		    ((payload_ptr[2] & 0xC0) >> 6);
		UE_list->UE_template[CC_idP][UE_id].bsr_info[LCGID3] =
		    (payload_ptr[2] & 0x3F);

		// update buffer info
		old_buffer_info =
		    UE_list->UE_template[CC_idP][UE_id].
		    ul_buffer_info[LCGID0];
		UE_list->UE_template[CC_idP][UE_id].
		    ul_buffer_info[LCGID0] =
		    BSR_TABLE[UE_list->UE_template[CC_idP][UE_id].
			      bsr_info[LCGID0]];

		UE_list->UE_template[CC_idP][UE_id].ul_total_buffer +=
		    UE_list->UE_template[CC_idP][UE_id].
		    ul_buffer_info[LCGID0];
		if (UE_list->UE_template[CC_idP][UE_id].ul_total_buffer >=
		    old_buffer_info)
		    UE_list->UE_template[CC_idP][UE_id].ul_total_buffer -=
			old_buffer_info;
		else
		    UE_list->UE_template[CC_idP][UE_id].ul_total_buffer =
			0;

		old_buffer_info =
		    UE_list->UE_template[CC_idP][UE_id].
		    ul_buffer_info[LCGID1];
		UE_list->UE_template[CC_idP][UE_id].
		    ul_buffer_info[LCGID1] =
		    BSR_TABLE[UE_list->UE_template[CC_idP][UE_id].
			      bsr_info[LCGID1]];
		UE_list->UE_template[CC_idP][UE_id].ul_total_buffer +=
		    UE_list->UE_template[CC_idP][UE_id].
		    ul_buffer_info[LCGID1];
		if (UE_list->UE_template[CC_idP][UE_id].ul_total_buffer >=
		    old_buffer_info)
		    UE_list->UE_template[CC_idP][UE_id].ul_total_buffer -=
			old_buffer_info;
		else
		    UE_list->UE_template[CC_idP][UE_id].ul_total_buffer =
			0;

		old_buffer_info =
		    UE_list->UE_template[CC_idP][UE_id].
		    ul_buffer_info[LCGID2];
		UE_list->UE_template[CC_idP][UE_id].
		    ul_buffer_info[LCGID2] =
		    BSR_TABLE[UE_list->UE_template[CC_idP][UE_id].
			      bsr_info[LCGID2]];
		UE_list->UE_template[CC_idP][UE_id].ul_total_buffer +=
		    UE_list->UE_template[CC_idP][UE_id].
		    ul_buffer_info[LCGID2];
		if (UE_list->UE_template[CC_idP][UE_id].ul_total_buffer >=
		    old_buffer_info)
		    UE_list->UE_template[CC_idP][UE_id].ul_total_buffer -=
			old_buffer_info;
		else
		    UE_list->UE_template[CC_idP][UE_id].ul_total_buffer =
			0;

		old_buffer_info =
		    UE_list->UE_template[CC_idP][UE_id].
		    ul_buffer_info[LCGID3];
		UE_list->UE_template[CC_idP][UE_id].
		    ul_buffer_info[LCGID3] =
		    BSR_TABLE[UE_list->UE_template[CC_idP][UE_id].
			      bsr_info[LCGID3]];
		UE_list->UE_template[CC_idP][UE_id].ul_total_buffer +=
		    UE_list->UE_template[CC_idP][UE_id].
		    ul_buffer_info[LCGID3];
		if (UE_list->UE_template[CC_idP][UE_id].ul_total_buffer >=
		    old_buffer_info)
		    UE_list->UE_template[CC_idP][UE_id].ul_total_buffer -=
			old_buffer_info;
		else
		    UE_list->UE_template[CC_idP][UE_id].ul_total_buffer =
			0;

		LOG_D(MAC,
		      "[eNB %d] CC_id %d MAC CE_LCID %d: Received long BSR LCGID0 = %u LCGID1 = "
		      "%u LCGID2 = %u LCGID3 = %u\n", enb_mod_idP, CC_idP,
		      rx_ces[i],
		      UE_list->UE_template[CC_idP][UE_id].bsr_info[LCGID0],
		      UE_list->UE_template[CC_idP][UE_id].bsr_info[LCGID1],
		      UE_list->UE_template[CC_idP][UE_id].bsr_info[LCGID2],
		      UE_list->UE_template[CC_idP][UE_id].
		      bsr_info[LCGID3]);
		if (crnti_rx == 1)
		    LOG_D(MAC,
			  "[eNB %d] CC_id %d MAC CE_LCID %d: Received long BSR LCGID0 = %u LCGID1 = "
			  "%u LCGID2 = %u LCGID3 = %u\n", enb_mod_idP,
			  CC_idP, rx_ces[i],
			  UE_list->UE_template[CC_idP][UE_id].
			  bsr_info[LCGID0],
			  UE_list->UE_template[CC_idP][UE_id].
			  bsr_info[LCGID1],
			  UE_list->UE_template[CC_idP][UE_id].
			  bsr_info[LCGID2],
			  UE_list->UE_template[CC_idP][UE_id].
			  bsr_info[LCGID3]);

		if (UE_list->UE_template[CC_idP][UE_id].bsr_info[LCGID0] ==
		    0) {
		    UE_list->UE_template[CC_idP][UE_id].
			ul_buffer_creation_time[LCGID0] = 0;
		} else if (UE_list->UE_template[CC_idP]
			   [UE_id].ul_buffer_creation_time[LCGID0] == 0) {
		    UE_list->UE_template[CC_idP][UE_id].
			ul_buffer_creation_time[LCGID0] = frameP;
		}

		if (UE_list->UE_template[CC_idP][UE_id].bsr_info[LCGID1] ==
		    0) {
		    UE_list->UE_template[CC_idP][UE_id].
			ul_buffer_creation_time[LCGID1] = 0;
		} else if (UE_list->UE_template[CC_idP]
			   [UE_id].ul_buffer_creation_time[LCGID1] == 0) {
		    UE_list->UE_template[CC_idP][UE_id].
			ul_buffer_creation_time[LCGID1] = frameP;
		}

		if (UE_list->UE_template[CC_idP][UE_id].bsr_info[LCGID2] ==
		    0) {
		    UE_list->UE_template[CC_idP][UE_id].
			ul_buffer_creation_time[LCGID2] = 0;
		} else if (UE_list->UE_template[CC_idP]
			   [UE_id].ul_buffer_creation_time[LCGID2] == 0) {
		    UE_list->UE_template[CC_idP][UE_id].
			ul_buffer_creation_time[LCGID2] = frameP;
		}

		if (UE_list->UE_template[CC_idP][UE_id].bsr_info[LCGID3] ==
		    0) {
		    UE_list->UE_template[CC_idP][UE_id].
			ul_buffer_creation_time[LCGID3] = 0;
		} else if (UE_list->UE_template[CC_idP]
			   [UE_id].ul_buffer_creation_time[LCGID3] == 0) {
		    UE_list->UE_template[CC_idP][UE_id].
			ul_buffer_creation_time[LCGID3] = frameP;

		}
	    }

	    payload_ptr += 3;	////sizeof(LONG_BSR);
	    break;

	default:
	    LOG_E(MAC,
		  "[eNB %d] CC_id %d Received unknown MAC header (0x%02x)\n",
		  enb_mod_idP, CC_idP, rx_ces[i]);
	    break;
	}
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
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
    for (i = 0; i < num_sdu; i++) {
	LOG_D(MAC, "SDU Number %d MAC Subheader SDU_LCID %d, length %d\n",
	      i, rx_lcids[i], rx_lengths[i]);

	T(T_ENB_MAC_UE_UL_SDU, T_INT(enb_mod_idP), T_INT(CC_idP),
	  T_INT(current_rnti), T_INT(frameP), T_INT(subframeP),
	  T_INT(rx_lcids[i]), T_INT(rx_lengths[i]));
	T(T_ENB_MAC_UE_UL_SDU_WITH_DATA, T_INT(enb_mod_idP), T_INT(CC_idP),
	  T_INT(current_rnti), T_INT(frameP), T_INT(subframeP),
	  T_INT(rx_lcids[i]), T_INT(rx_lengths[i]), T_BUFFER(payload_ptr,
							     rx_lengths
							     [i]));

	switch (rx_lcids[i]) {
	case CCCH:
	    if (rx_lengths[i] > CCCH_PAYLOAD_SIZE_MAX) {
		LOG_E(MAC,
		      "[eNB %d/%d] frame %d received CCCH of size %d (too big, maximum allowed is %d, sdu_len %d), dropping packet\n",
		      enb_mod_idP, CC_idP, frameP, rx_lengths[i],
		      CCCH_PAYLOAD_SIZE_MAX, sdu_lenP);
		break;
	    }
	    LOG_D(MAC,
		  "[eNB %d][RAPROC] CC_id %d Frame %d, Received CCCH:  %x.%x.%x.%x.%x.%x, Terminating RA procedure for UE rnti %x\n",
		  enb_mod_idP, CC_idP, frameP, payload_ptr[0],
		  payload_ptr[1], payload_ptr[2], payload_ptr[3],
		  payload_ptr[4], payload_ptr[5], current_rnti);
	    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME
		(VCD_SIGNAL_DUMPER_FUNCTIONS_TERMINATE_RA_PROC, 1);
	    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME
		(VCD_SIGNAL_DUMPER_FUNCTIONS_TERMINATE_RA_PROC, 0);
	    for (ii = 0; ii < NB_RA_PROC_MAX; ii++) {
		RA_t *ra = &mac->common_channels[CC_idP].ra[ii];

		LOG_D(MAC,
		      "[mac %d][RAPROC] CC_id %d Checking proc %d : rnti (%x, %x), state %d\n",
		      enb_mod_idP, CC_idP, ii, ra->rnti,
		      current_rnti, ra->state);

		if ((ra->rnti == current_rnti) && (ra->state != IDLE)) {

		    //payload_ptr = parse_ulsch_header(msg3,&num_ce,&num_sdu,rx_ces,rx_lcids,rx_lengths,msg3_len);

		    if (UE_id < 0) {
			memcpy(&ra->cont_res_id[0], payload_ptr, 6);
			LOG_D(MAC,
			      "[eNB %d][RAPROC] CC_id %d Frame %d CCCH: Received Msg3: length %d, offset %ld\n",
			      enb_mod_idP, CC_idP, frameP, rx_lengths[i],
			      payload_ptr - sduP);

			if ((UE_id =
			     add_new_ue(enb_mod_idP, CC_idP,
					mac->common_channels[CC_idP].
					ra[ii].rnti, harq_pid
#ifdef Rel14
					,
					mac->common_channels[CC_idP].
					ra[ii].rach_resource_type
#endif
			     )) == -1) {
			    AssertFatal(1 == 0,
					"[MAC][eNB] Max user count reached\n");
			    // kill RA procedure
			} else
			    LOG_D(MAC,
				  "[eNB %d][RAPROC] CC_id %d Frame %d Added user with rnti %x => UE %d\n",
				  enb_mod_idP, CC_idP, frameP, ra->rnti,
				  UE_id);
		    } else {
			LOG_D(MAC,
			      "[eNB %d][RAPROC] CC_id %d Frame %d CCCH: Received Msg3 from already registered UE %d: length %d, offset %ld\n",
			      enb_mod_idP, CC_idP, frameP, UE_id,
			      rx_lengths[i], payload_ptr - sduP);
			// kill RA procedure
		    }

		    mac_rrc_data_ind(enb_mod_idP,
				     CC_idP,
				     frameP, subframeP,
				     current_rnti,
				     CCCH,
				     (uint8_t *) payload_ptr,
				     rx_lengths[i],
				     ENB_FLAG_YES, enb_mod_idP, 0);


		    if (num_ce > 0) {	// handle msg3 which is not RRCConnectionRequest
			//  process_ra_message(msg3,num_ce,rx_lcids,rx_ces);
		    }
		    // prepare transmission of Msg4
		    ra->state = MSG4;



		    // Program Msg4 PDCCH+DLSCH/MPDCCH transmission 4 subframes from now, // Check if this is ok for BL/CE, or if the rule is different
		    ra->Msg4_frame = frameP + ((subframeP > 5) ? 1 : 0);
		    ra->Msg4_subframe = (subframeP + 4) % 10;

		}		// if process is active
	    }			// loop on RA processes

	    break;

	case DCCH:
	case DCCH1:
	    //      if(eNB_mac_inst[module_idP][CC_idP].Dcch_lchan[UE_id].Active==1){
Cédric Roux's avatar
Cédric Roux committed
634

gauthier's avatar
   
gauthier committed
635

knopp's avatar
   
knopp committed
636
#if defined(ENABLE_MAC_PAYLOAD_DEBUG)
637
638
639
640
641
642
	    LOG_T(MAC, "offset: %d\n",
		  (unsigned char) ((unsigned char *) payload_ptr - sduP));
	    for (j = 0; j < 32; j++) {
		LOG_T(MAC, "%x ", payload_ptr[j]);
	    }
	    LOG_T(MAC, "\n");
knopp's avatar
   
knopp committed
643
#endif
gauthier's avatar
   
gauthier committed
644

645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
	    if (UE_id != -1) {
		// adjust buffer occupancy of the correponding logical channel group
		if (UE_list->UE_template[CC_idP][UE_id].
		    ul_buffer_info[UE_list->UE_template[CC_idP]
				   [UE_id].lcgidmap[rx_lcids[i]]] >=
		    rx_lengths[i])
		    UE_list->UE_template[CC_idP][UE_id].
			ul_buffer_info[UE_list->UE_template[CC_idP]
				       [UE_id].lcgidmap[rx_lcids[i]]] -=
			rx_lengths[i];
		else
		    UE_list->UE_template[CC_idP][UE_id].
			ul_buffer_info[UE_list->UE_template[CC_idP]
				       [UE_id].lcgidmap[rx_lcids[i]]] = 0;

		LOG_D(MAC,
		      "[eNB %d] CC_id %d Frame %d : ULSCH -> UL-DCCH, received %d bytes form UE %d on LCID %d \n",
		      enb_mod_idP, CC_idP, frameP, rx_lengths[i], UE_id,
		      rx_lcids[i]);

		mac_rlc_data_ind(enb_mod_idP, current_rnti, enb_mod_idP, frameP, ENB_FLAG_YES, MBMS_FLAG_NO, rx_lcids[i], (char *) payload_ptr, rx_lengths[i], 1, NULL);	//(unsigned int*)crc_status);
		UE_list->eNB_UE_stats[CC_idP][UE_id].
		    num_pdu_rx[rx_lcids[i]] += 1;
		UE_list->eNB_UE_stats[CC_idP][UE_id].
		    num_bytes_rx[rx_lcids[i]]
		    += rx_lengths[i];


	    }

	    /* UE_id != -1 */
	    // }
	    break;

	    // all the DRBS
	case DTCH:
	default:
gauthier's avatar
   
gauthier committed
682

knopp's avatar
   
knopp committed
683
#if defined(ENABLE_MAC_PAYLOAD_DEBUG)
684
685
686
687
688
689
	    LOG_T(MAC, "offset: %d\n",
		  (unsigned char) ((unsigned char *) payload_ptr - sduP));
	    for (j = 0; j < 32; j++) {
		LOG_T(MAC, "%x ", payload_ptr[j]);
	    }
	    LOG_T(MAC, "\n");
690
#endif
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
	    if (rx_lcids[i] < NB_RB_MAX) {
		LOG_D(MAC,
		      "[eNB %d] CC_id %d Frame %d : ULSCH -> UL-DTCH, received %d bytes from UE %d for lcid %d\n",
		      enb_mod_idP, CC_idP, frameP, rx_lengths[i], UE_id,
		      rx_lcids[i]);

		if (UE_id != -1) {
		    // adjust buffer occupancy of the correponding logical channel group
		    LOG_D(MAC,
			  "[eNB %d] CC_id %d Frame %d : ULSCH -> UL-DTCH, received %d bytes from UE %d for lcid %d, removing from LCGID %ld, %d\n",
			  enb_mod_idP, CC_idP, frameP, rx_lengths[i],
			  UE_id, rx_lcids[i],
			  UE_list->UE_template[CC_idP][UE_id].
			  lcgidmap[rx_lcids[i]],
			  UE_list->UE_template[CC_idP][UE_id].
			  ul_buffer_info[UE_list->UE_template[CC_idP]
					 [UE_id].lcgidmap[rx_lcids[i]]]);

		    if (UE_list->UE_template[CC_idP][UE_id].
			ul_buffer_info[UE_list->UE_template[CC_idP]
				       [UE_id].lcgidmap[rx_lcids[i]]]
			>= rx_lengths[i])
			UE_list->UE_template[CC_idP][UE_id].
			    ul_buffer_info[UE_list->UE_template[CC_idP]
					   [UE_id].lcgidmap[rx_lcids[i]]]
			    -= rx_lengths[i];
		    else
			UE_list->UE_template[CC_idP][UE_id].ul_buffer_info
			    [UE_list->UE_template[CC_idP][UE_id].lcgidmap
			     [rx_lcids[i]]] = 0;
		    if ((rx_lengths[i] < SCH_PAYLOAD_SIZE_MAX)
			&& (rx_lengths[i] > 0)) {	// MAX SIZE OF transport block
			mac_rlc_data_ind(enb_mod_idP, current_rnti, enb_mod_idP, frameP, ENB_FLAG_YES, MBMS_FLAG_NO, rx_lcids[i], (char *) payload_ptr, rx_lengths[i], 1, NULL);	//(unsigned int*)crc_status);

			UE_list->eNB_UE_stats[CC_idP][UE_id].
			    num_pdu_rx[rx_lcids[i]] += 1;
			UE_list->eNB_UE_stats[CC_idP][UE_id].
			    num_bytes_rx[rx_lcids[i]] += rx_lengths[i];
		    } else {	/* rx_length[i] */
			UE_list->eNB_UE_stats[CC_idP][UE_id].
			    num_errors_rx += 1;
			LOG_E(MAC,
			      "[eNB %d] CC_id %d Frame %d : Max size of transport block reached LCID %d from UE %d ",
			      enb_mod_idP, CC_idP, frameP, rx_lcids[i],
			      UE_id);
		    }
		} else {	/*(UE_id != -1 */
		    LOG_E(MAC,
			  "[eNB %d] CC_id %d Frame %d : received unsupported or unknown LCID %d from UE %d ",
			  enb_mod_idP, CC_idP, frameP, rx_lcids[i], UE_id);
		}
	    }

	    break;
	}

	payload_ptr += rx_lengths[i];
knopp's avatar
   
knopp committed
748
    }
Cédric Roux's avatar
Cédric Roux committed
749

750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
    // Program ACK for PHICH
    LOG_D(MAC,
	  "Programming PHICH ACK for rnti %x harq_pid %d (first_rb %d)\n",
	  current_rnti, harq_pid, first_rb);
    nfapi_hi_dci0_request_body_t *hi_dci0_req =
	&mac->HI_DCI0_req[CC_idP].hi_dci0_request_body;
    nfapi_hi_dci0_request_pdu_t *hi_dci0_pdu =
	&hi_dci0_req->hi_dci0_pdu_list[hi_dci0_req->number_of_dci +
				       hi_dci0_req->number_of_hi];
    memset((void *) hi_dci0_pdu, 0, sizeof(nfapi_hi_dci0_request_pdu_t));
    hi_dci0_pdu->pdu_type = NFAPI_HI_DCI0_HI_PDU_TYPE;
    hi_dci0_pdu->pdu_size = 2 + sizeof(nfapi_hi_dci0_hi_pdu);
    hi_dci0_pdu->hi_pdu.hi_pdu_rel8.resource_block_start = first_rb;
    hi_dci0_pdu->hi_pdu.hi_pdu_rel8.cyclic_shift_2_for_drms = 0;
    hi_dci0_pdu->hi_pdu.hi_pdu_rel8.hi_value = 1;
    hi_dci0_req->number_of_hi++;

    /* NN--> FK: we could either check the payload, or use a phy helper to detect a false msg3 */
    if ((num_sdu == 0) && (num_ce == 0)) {
	if (UE_id != -1)
	    UE_list->eNB_UE_stats[CC_idP][UE_id].total_num_errors_rx += 1;
	/*
	   if (msg3_flagP != NULL) {
	   if( *msg3_flagP == 1 ) {
	   LOG_N(MAC,"[eNB %d] CC_id %d frame %d : false msg3 detection: signal phy to canceling RA and remove the UE\n", enb_mod_idP, CC_idP, frameP);
	   *msg3_flagP=0;
	   }
	   } */
    } else {
	if (UE_id != -1) {
	    UE_list->eNB_UE_stats[CC_idP][UE_id].pdu_bytes_rx = sdu_lenP;
	    UE_list->eNB_UE_stats[CC_idP][UE_id].total_pdu_bytes_rx +=
		sdu_lenP;
	    UE_list->eNB_UE_stats[CC_idP][UE_id].total_num_pdus_rx += 1;
	}
roux's avatar
roux committed
785
    }
786

787
788
789
    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME
	(VCD_SIGNAL_DUMPER_FUNCTIONS_RX_SDU, 0);
    stop_meas(&mac->rx_ulsch_sdu);
knopp's avatar
   
knopp committed
790
791
}

792
793
uint32_t bytes_to_bsr_index(int32_t nbytes)
{
794
    uint32_t i = 0;
795

796
797
798
    if (nbytes < 0) {
	return (0);
    }
799

800
801
802
    while ((i < BSR_TABLE_SIZE) && (BSR_TABLE[i] <= nbytes)) {
	i++;
    }
803

804
    return (i - 1);
805
806
}

807
808
809
void
add_ue_ulsch_info(module_id_t module_idP, int CC_id, int UE_id,
		  sub_frame_t subframeP, UE_ULSCH_STATUS status)
810
{
811
812
813
814
    eNB_ulsch_info[module_idP][CC_id][UE_id].rnti =
	UE_RNTI(module_idP, UE_id);
    eNB_ulsch_info[module_idP][CC_id][UE_id].subframe = subframeP;
    eNB_ulsch_info[module_idP][CC_id][UE_id].status = status;
815

816
    eNB_ulsch_info[module_idP][CC_id][UE_id].serving_num++;
817
818
819
}

unsigned char *parse_ulsch_header(unsigned char *mac_header,
820
821
822
823
824
825
				  unsigned char *num_ce,
				  unsigned char *num_sdu,
				  unsigned char *rx_ces,
				  unsigned char *rx_lcids,
				  unsigned short *rx_lengths,
				  unsigned short tb_length)
826
{
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
    unsigned char not_done = 1, num_ces = 0, num_sdus =
	0, lcid, num_sdu_cnt;
    unsigned char *mac_header_ptr = mac_header;
    unsigned short length, ce_len = 0;

    while (not_done == 1) {

	if (((SCH_SUBHEADER_FIXED *) mac_header_ptr)->E == 0) {
	    not_done = 0;
	}

	lcid = ((SCH_SUBHEADER_FIXED *) mac_header_ptr)->LCID;

	if (lcid < EXTENDED_POWER_HEADROOM) {
	    if (not_done == 0) {	// last MAC SDU, length is implicit
		mac_header_ptr++;
		length =
		    tb_length - (mac_header_ptr - mac_header) - ce_len;

		for (num_sdu_cnt = 0; num_sdu_cnt < num_sdus;
		     num_sdu_cnt++) {
		    length -= rx_lengths[num_sdu_cnt];
		}
	    } else {
		if (((SCH_SUBHEADER_SHORT *) mac_header_ptr)->F == 0) {
		    length = ((SCH_SUBHEADER_SHORT *) mac_header_ptr)->L;
		    mac_header_ptr += 2;	//sizeof(SCH_SUBHEADER_SHORT);
		} else {	// F = 1
		    length =
			((((SCH_SUBHEADER_LONG *) mac_header_ptr)->L_MSB &
			  0x7f) << 8) | (((SCH_SUBHEADER_LONG *)
					  mac_header_ptr)->L_LSB & 0xff);
		    mac_header_ptr += 3;	//sizeof(SCH_SUBHEADER_LONG);
		}
	    }

	    LOG_D(MAC,
		  "[eNB] sdu %d lcid %d tb_length %d length %d (offset now %ld)\n",
		  num_sdus, lcid, tb_length, length,
		  mac_header_ptr - mac_header);
	    rx_lcids[num_sdus] = lcid;
	    rx_lengths[num_sdus] = length;
	    num_sdus++;
	} else {		// This is a control element subheader POWER_HEADROOM, BSR and CRNTI
	    if (lcid == SHORT_PADDING) {
		mac_header_ptr++;
	    } else {
		rx_ces[num_ces] = lcid;
		num_ces++;
		mac_header_ptr++;

		if (lcid == LONG_BSR) {
		    ce_len += 3;
		} else if (lcid == CRNTI) {
		    ce_len += 2;
		} else if ((lcid == POWER_HEADROOM)
			   || (lcid == TRUNCATED_BSR)
			   || (lcid == SHORT_BSR)) {
		    ce_len++;
		} else {
		    LOG_E(MAC, "unknown CE %d \n", lcid);
		    AssertFatal(1 == 0, "unknown CE");
		}
	    }
	}
knopp's avatar
   
knopp committed
892
    }
893

894
895
    *num_ce = num_ces;
    *num_sdu = num_sdus;
896

897
    return (mac_header_ptr);
898
899
}

900
901
902
903
904
/* This function is called by PHY layer when it schedules some
 * uplink for a random access message 3.
 * The MAC scheduler has to skip the RBs used by this message 3
 * (done below in schedule_ulsch).
 */
905
906
907
908
909
910
void
set_msg3_subframe(module_id_t Mod_id,
		  int CC_id,
		  int frame,
		  int subframe, int rnti, int Msg3_frame,
		  int Msg3_subframe)
911
{
912
913
914
915
916
917
918
919
920
    eNB_MAC_INST *mac = RC.mac[Mod_id];
    int i;
    for (i = 0; i < NB_RA_PROC_MAX; i++) {
	if (mac->common_channels[CC_id].ra[i].state != IDLE &&
	    mac->common_channels[CC_id].ra[i].rnti == rnti) {
	    mac->common_channels[CC_id].ra[i].Msg3_subframe =
		Msg3_subframe;
	    break;
	}
921
922
    }
}
923

924

925
926
927
void
schedule_ulsch(module_id_t module_idP, frame_t frameP,
	       sub_frame_t subframeP)
Cédric Roux's avatar
Cédric Roux committed
928
{
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
    uint16_t first_rb[MAX_NUM_CCs], i;
    int CC_id;
    eNB_MAC_INST *mac = RC.mac[module_idP];
    COMMON_channels_t *cc;

    start_meas(&mac->schedule_ulsch);

    int sched_subframe = (subframeP + 4) % 10;

    cc = &mac->common_channels[0];
    int tdd_sfa;
    // for TDD: check subframes where we have to act and return if nothing should be done now
    if (cc->tdd_Config) {
	tdd_sfa = cc->tdd_Config->subframeAssignment;
	switch (subframeP) {
	case 0:
	    if ((tdd_sfa == 0) || (tdd_sfa == 3) || (tdd_sfa == 6))
		sched_subframe = 4;
	    else
		return;
	    break;
	case 1:
	    if ((tdd_sfa == 0) || (tdd_sfa == 1))
		sched_subframe = 7;
	    else if (tdd_sfa == 6)
		sched_subframe = 8;
	    break;
	default:
	    return;

	case 2:		// Don't schedule UL in subframe 2 for TDD
	    return;
	case 3:
	    if (tdd_sfa == 2)
		sched_subframe = 7;
	    else
		return;
	    break;
	case 4:
	    if (tdd_sfa == 1)
		sched_subframe = 8;
	    else
		return;
	    break;
	case 5:
	    if (tdd_sfa == 0)
		sched_subframe = 9;
	    else if (tdd_sfa == 6)
		sched_subframe = 3;
	    else
		return;
	    break;
	case 6:
	    if (tdd_sfa == 1)
		sched_subframe = 2;
	    else if (tdd_sfa == 6)
		sched_subframe = 3;
	    else
		return;
	    break;
	case 7:
	    return;
	case 8:
	    if ((tdd_sfa >= 2) || (tdd_sfa <= 5))
		sched_subframe = 2;
	    else
		return;
	    break;
	case 9:
	    if ((tdd_sfa == 1) || (tdd_sfa == 3) || (tdd_sfa == 4))
		sched_subframe = 3;
	    else if (tdd_sfa == 6)
For faster browsing, not all history is shown. View entire blame