1
/* Copied from gprs_bssgp_pcu.cpp
3
* Copyright (C) 2012 Ivan Klyuchnikov
4
* Copyright (C) 2012 Andreas Eversberg <jolly@eversberg.eu>
5
* Copyright (C) 2013 by Holger Hans Peter Freyther
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License
9
* as published by the Free Software Foundation; either version 2
10
* of the License, or (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
#include <gprs_rlcmac.h>
27
#include <gprs_debug.h>
28
#include <gprs_bssgp_pcu.h>
31
#include <pcu_utils.h>
34
#include <osmocom/core/msgb.h>
35
#include <osmocom/core/talloc.h>
36
#include <osmocom/core/stats.h>
42
extern void *tall_pcu_ctx;
44
static void tbf_timer_cb(void *_tbf);
46
const struct value_string gprs_rlcmac_tbf_dl_ass_state_names[] = {
47
OSMO_VALUE_STRING(GPRS_RLCMAC_DL_ASS_NONE),
48
OSMO_VALUE_STRING(GPRS_RLCMAC_DL_ASS_SEND_ASS),
49
OSMO_VALUE_STRING(GPRS_RLCMAC_DL_ASS_WAIT_ACK),
53
const struct value_string gprs_rlcmac_tbf_ul_ass_state_names[] = {
54
OSMO_VALUE_STRING(GPRS_RLCMAC_UL_ASS_NONE),
55
OSMO_VALUE_STRING(GPRS_RLCMAC_UL_ASS_SEND_ASS),
56
OSMO_VALUE_STRING(GPRS_RLCMAC_UL_ASS_SEND_ASS_REJ),
57
OSMO_VALUE_STRING(GPRS_RLCMAC_UL_ASS_WAIT_ACK),
61
static const struct rate_ctr_desc tbf_ctr_description[] = {
62
{ "rlc.nacked", "RLC Nacked " },
65
static const struct rate_ctr_desc tbf_dl_gprs_ctr_description[] = {
66
{ "gprs.downlink.cs1", "CS1 " },
67
{ "gprs.downlink.cs2", "CS2 " },
68
{ "gprs.downlink.cs3", "CS3 " },
69
{ "gprs.downlink.cs4", "CS4 " },
72
static const struct rate_ctr_desc tbf_dl_egprs_ctr_description[] = {
73
{ "egprs.downlink.mcs1", "MCS1 " },
74
{ "egprs.downlink.mcs2", "MCS2 " },
75
{ "egprs.downlink.mcs3", "MCS3 " },
76
{ "egprs.downlink.mcs4", "MCS4 " },
77
{ "egprs.downlink.mcs5", "MCS5 " },
78
{ "egprs.downlink.mcs6", "MCS6 " },
79
{ "egprs.downlink.mcs7", "MCS7 " },
80
{ "egprs.downlink.mcs8", "MCS8 " },
81
{ "egprs.downlink.mcs9", "MCS9 " },
84
static const struct rate_ctr_desc tbf_ul_gprs_ctr_description[] = {
85
{ "gprs.uplink.cs1", "CS1 " },
86
{ "gprs.uplink.cs2", "CS2 " },
87
{ "gprs.uplink.cs3", "CS3 " },
88
{ "gprs.uplink.cs4", "CS4 " },
91
static const struct rate_ctr_desc tbf_ul_egprs_ctr_description[] = {
92
{ "egprs.uplink.mcs1", "MCS1 " },
93
{ "egprs.uplink.mcs2", "MCS2 " },
94
{ "egprs.uplink.mcs3", "MCS3 " },
95
{ "egprs.uplink.mcs4", "MCS4 " },
96
{ "egprs.uplink.mcs5", "MCS5 " },
97
{ "egprs.uplink.mcs6", "MCS6 " },
98
{ "egprs.uplink.mcs7", "MCS7 " },
99
{ "egprs.uplink.mcs8", "MCS8 " },
100
{ "egprs.uplink.mcs9", "MCS9 " },
103
static const struct rate_ctr_group_desc tbf_ctrg_desc = {
106
OSMO_STATS_CLASS_SUBSCRIBER,
107
ARRAY_SIZE(tbf_ctr_description),
111
static const struct rate_ctr_group_desc tbf_dl_gprs_ctrg_desc = {
114
OSMO_STATS_CLASS_SUBSCRIBER,
115
ARRAY_SIZE(tbf_dl_gprs_ctr_description),
116
tbf_dl_gprs_ctr_description,
119
static const struct rate_ctr_group_desc tbf_dl_egprs_ctrg_desc = {
122
OSMO_STATS_CLASS_SUBSCRIBER,
123
ARRAY_SIZE(tbf_dl_egprs_ctr_description),
124
tbf_dl_egprs_ctr_description,
127
static const struct rate_ctr_group_desc tbf_ul_gprs_ctrg_desc = {
130
OSMO_STATS_CLASS_SUBSCRIBER,
131
ARRAY_SIZE(tbf_ul_gprs_ctr_description),
132
tbf_ul_gprs_ctr_description,
135
static const struct rate_ctr_group_desc tbf_ul_egprs_ctrg_desc = {
138
OSMO_STATS_CLASS_SUBSCRIBER,
139
ARRAY_SIZE(tbf_ul_egprs_ctr_description),
140
tbf_ul_egprs_ctr_description,
143
gprs_rlcmac_tbf::Meas::Meas() :
147
timerclear(&rssi_tv);
150
gprs_rlcmac_tbf::gprs_rlcmac_tbf(BTS *bts_, gprs_rlcmac_tbf_direction dir) :
157
dl_ass_state(GPRS_RLCMAC_DL_ASS_NONE),
158
ul_ass_state(GPRS_RLCMAC_UL_ASS_NONE),
159
ul_ack_state(GPRS_RLCMAC_UL_ACK_NONE),
160
poll_state(GPRS_RLCMAC_POLL_NONE),
168
state(GPRS_RLCMAC_NULL),
170
upgrade_to_multislot(0),
176
m_ta(GSM48_TA_INVALID),
180
m_egprs_enabled(false)
182
/* The classes of these members do not have proper constructors yet.
183
* Just set them to 0 like talloc_zero did */
184
memset(&pdch, 0, sizeof(pdch));
185
memset(&timer, 0, sizeof(timer));
186
memset(&m_rlc, 0, sizeof(m_rlc));
187
memset(&gsm_timer, 0, sizeof(gsm_timer));
191
m_name_buf[0] = '\0';
194
gprs_rlcmac_bts *gprs_rlcmac_tbf::bts_data() const
196
return bts->bts_data();
199
uint32_t gprs_rlcmac_tbf::tlli() const
201
return m_ms ? m_ms->tlli() : 0;
204
const char *gprs_rlcmac_tbf::imsi() const
206
static const char nullc = 0;
207
return m_ms ? m_ms->imsi() : &nullc;
210
void gprs_rlcmac_tbf::assign_imsi(const char *imsi_)
214
if (!imsi_ || !m_ms) {
215
LOGP(DRLCMAC, LOGL_ERROR,
216
"%s failed to assign IMSI: missing IMSI or MS object\n",
221
if (strcmp(imsi_, imsi()) == 0)
224
/* really change the IMSI */
226
old_ms = bts->ms_store().get_ms(0, 0, imsi_);
228
/* We cannot find m_ms by IMSI since we know that it has a
230
OSMO_ASSERT(old_ms != m_ms);
232
LOGP(DRLCMAC, LOGL_INFO,
233
"%s the IMSI '%s' was already assigned to another "
234
"MS object: TLLI = 0x%08x, that IMSI will be removed\n",
235
name(), imsi_, old_ms->tlli());
237
merge_and_clear_ms(old_ms);
240
m_ms->set_imsi(imsi_);
243
uint8_t gprs_rlcmac_tbf::ta() const
245
return m_ms ? m_ms->ta() : m_ta;
248
void gprs_rlcmac_tbf::set_ta(uint8_t ta)
253
if (gsm48_ta_is_valid(ta))
257
uint8_t gprs_rlcmac_tbf::ms_class() const
259
return m_ms ? m_ms->ms_class() : m_ms_class;
262
void gprs_rlcmac_tbf::set_ms_class(uint8_t ms_class_)
265
ms()->set_ms_class(ms_class_);
267
m_ms_class = ms_class_;
270
GprsCodingScheme gprs_rlcmac_tbf::current_cs() const
273
if (direction == GPRS_RLCMAC_UL_TBF)
274
cs = m_ms ? m_ms->current_cs_ul() : GprsCodingScheme();
276
cs = m_ms ? m_ms->current_cs_dl() : GprsCodingScheme();
281
gprs_llc_queue *gprs_rlcmac_tbf::llc_queue()
283
return m_ms ? m_ms->llc_queue() : NULL;
286
const gprs_llc_queue *gprs_rlcmac_tbf::llc_queue() const
288
return m_ms ? m_ms->llc_queue() : NULL;
291
int gprs_rlcmac_tbf::llc_queue_size() const
293
/* m_ms->llc_queue() never returns NULL: GprsMs::m_llc_queue is a
294
* member instance. */
295
return m_ms ? m_ms->llc_queue()->size() : 0;
298
void gprs_rlcmac_tbf::set_ms(GprsMs *ms)
304
/* Save the TA locally. This will also be called, if the MS
305
* object detaches itself from the TBF, for instance if
306
* attach_tbf() is called */
309
m_ms->detach_tbf(this);
315
m_ms->attach_tbf(this);
318
void gprs_rlcmac_tbf::merge_and_clear_ms(GprsMs *old_ms)
323
GprsMs::Guard guard_old(old_ms);
325
/* Clean up the old MS object */
326
/* TODO: Use timer? */
327
if (old_ms->ul_tbf() && old_ms->ul_tbf()->T == 0) {
328
if (old_ms->ul_tbf() == this) {
329
LOGP(DRLCMAC, LOGL_ERROR,
330
"%s is referred by the old MS "
331
"and will not be deleted\n",
335
tbf_free(old_ms->ul_tbf());
338
if (old_ms->dl_tbf() && old_ms->dl_tbf()->T == 0) {
339
if (old_ms->dl_tbf() == this) {
340
LOGP(DRLCMAC, LOGL_ERROR,
341
"%s is referred by the old MS "
342
"and will not be deleted\n",
346
tbf_free(old_ms->dl_tbf());
350
ms()->merge_old_ms(old_ms);
353
void gprs_rlcmac_tbf::update_ms(uint32_t tlli, enum gprs_rlcmac_tbf_direction dir)
361
/* TODO: When the TLLI does not match the ms, check if there is another
362
* MS object that belongs to that TLLI and if yes make sure one of them
363
* gets deleted. This is the same problem that can arise with
364
* assign_imsi() so there should be a unified solution */
365
if (!ms()->check_tlli(tlli)) {
368
old_ms = bts->ms_store().get_ms(tlli, 0, NULL);
370
merge_and_clear_ms(old_ms);
373
if (dir == GPRS_RLCMAC_UL_TBF)
374
ms()->set_tlli(tlli);
376
ms()->confirm_tlli(tlli);
379
gprs_rlcmac_ul_tbf *tbf_alloc_ul(struct gprs_rlcmac_bts *bts,
380
int8_t use_trx, uint8_t ms_class, uint8_t egprs_ms_class,
381
uint32_t tlli, uint8_t ta, GprsMs *ms)
383
struct gprs_rlcmac_ul_tbf *tbf;
385
/* FIXME: Copy and paste with tbf_new_dl_assignment */
386
/* create new TBF, use same TRX as DL TBF */
387
/* use multislot class of downlink TBF */
388
tbf = tbf_alloc_ul_tbf(bts, ms, use_trx, ms_class, egprs_ms_class, 0);
390
LOGP(DRLCMAC, LOGL_NOTICE, "No PDCH resource\n");
391
/* FIXME: send reject */
394
tbf->m_contention_resolution_done = 1;
395
tbf->set_state(GPRS_RLCMAC_ASSIGN);
396
tbf->state_flags |= (1 << GPRS_RLCMAC_FLAG_PACCH);
397
tbf_timer_start(tbf, 3169, bts->t3169, 0);
398
tbf->update_ms(tlli, GPRS_RLCMAC_UL_TBF);
399
OSMO_ASSERT(tbf->ms());
401
tbf->ms()->set_ta(ta);
406
static void tbf_unlink_pdch(struct gprs_rlcmac_tbf *tbf)
410
for (ts = 0; ts < 8; ts++) {
414
tbf->pdch[ts]->detach_tbf(tbf);
415
tbf->pdch[ts] = NULL;
419
void tbf_free(struct gprs_rlcmac_tbf *tbf)
421
/* update counters */
422
if (tbf->direction == GPRS_RLCMAC_UL_TBF) {
423
gprs_rlcmac_ul_tbf *ul_tbf = as_ul_tbf(tbf);
424
tbf->bts->tbf_ul_freed();
425
if (tbf->state_is(GPRS_RLCMAC_FLOW))
426
tbf->bts->tbf_ul_aborted();
427
rate_ctr_group_free(ul_tbf->m_ul_egprs_ctrs);
428
rate_ctr_group_free(ul_tbf->m_ul_gprs_ctrs);
430
gprs_rlcmac_dl_tbf *dl_tbf = as_dl_tbf(tbf);
431
if (tbf->is_egprs_enabled()) {
432
rate_ctr_group_free(dl_tbf->m_dl_egprs_ctrs);
434
rate_ctr_group_free(dl_tbf->m_dl_gprs_ctrs);
436
tbf->bts->tbf_dl_freed();
437
if (tbf->state_is(GPRS_RLCMAC_FLOW))
438
tbf->bts->tbf_dl_aborted();
441
/* Give final measurement report */
442
gprs_rlcmac_rssi_rep(tbf);
443
if (tbf->direction == GPRS_RLCMAC_DL_TBF) {
444
gprs_rlcmac_dl_tbf *dl_tbf = as_dl_tbf(tbf);
450
LOGP(DRLCMAC, LOGL_INFO, "%s free\n", tbf_name(tbf));
451
if (tbf->ul_ass_state != GPRS_RLCMAC_UL_ASS_NONE)
452
LOGP(DRLCMAC, LOGL_ERROR, "%s Software error: Pending uplink "
453
"assignment in state %s. This may not happen, because the "
454
"assignment message never gets transmitted. Please "
455
"be sure not to free in this state. PLEASE FIX!\n",
457
get_value_string(gprs_rlcmac_tbf_ul_ass_state_names,
459
if (tbf->dl_ass_state != GPRS_RLCMAC_DL_ASS_NONE)
460
LOGP(DRLCMAC, LOGL_ERROR, "%s Software error: Pending downlink "
461
"assignment in state %s. This may not happen, because the "
462
"assignment message never gets transmitted. Please "
463
"be sure not to free in this state. PLEASE FIX!\n",
465
get_value_string(gprs_rlcmac_tbf_dl_ass_state_names,
468
/* TODO: Could/Should generate bssgp_tx_llc_discarded */
469
tbf_unlink_pdch(tbf);
470
llist_del(&tbf->list());
475
rate_ctr_group_free(tbf->m_ctrs);
477
LOGP(DRLCMAC, LOGL_DEBUG, "********** TBF ends here **********\n");
481
int gprs_rlcmac_tbf::update()
483
struct gprs_rlcmac_bts *bts_data = bts->bts_data();
486
LOGP(DRLCMAC, LOGL_DEBUG, "********** TBF update **********\n");
488
if (direction != GPRS_RLCMAC_DL_TBF)
491
tbf_unlink_pdch(this);
492
rc = bts_data->alloc_algorithm(bts_data, ms(), this,
493
bts_data->alloc_algorithm_curst, 0, -1);
496
LOGP(DRLCMAC, LOGL_ERROR, "No resource after update???\n");
500
if (is_egprs_enabled()) {
501
gprs_rlcmac_dl_tbf *dl_tbf = as_dl_tbf(this);
503
dl_tbf->egprs_calc_window_size();
509
int tbf_assign_control_ts(struct gprs_rlcmac_tbf *tbf)
511
if (tbf->control_ts == 0xff)
512
LOGP(DRLCMAC, LOGL_INFO, "- Setting Control TS %d\n",
513
tbf->first_common_ts);
514
else if (tbf->control_ts != tbf->first_common_ts)
515
LOGP(DRLCMAC, LOGL_INFO, "- Changing Control TS %d\n",
516
tbf->first_common_ts);
517
tbf->control_ts = tbf->first_common_ts;
522
const char *gprs_rlcmac_tbf::tbf_state_name[] = {
531
void tbf_timer_start(struct gprs_rlcmac_tbf *tbf, unsigned int T,
532
unsigned int seconds, unsigned int microseconds)
534
if (!osmo_timer_pending(&tbf->timer))
535
LOGP(DRLCMAC, LOGL_DEBUG, "%s starting timer %u.\n",
538
LOGP(DRLCMAC, LOGL_DEBUG, "%s restarting timer %u "
539
"while old timer %u pending \n",
540
tbf_name(tbf), T, tbf->T);
545
/* Tunning timers can be safely re-scheduled. */
546
tbf->timer.data = tbf;
547
tbf->timer.cb = &tbf_timer_cb;
549
osmo_timer_schedule(&tbf->timer, seconds, microseconds);
552
void gprs_rlcmac_tbf::stop_t3191()
557
void gprs_rlcmac_tbf::stop_timer()
559
if (osmo_timer_pending(&timer)) {
560
LOGP(DRLCMAC, LOGL_DEBUG, "%s stopping timer %u.\n",
562
osmo_timer_del(&timer);
566
int gprs_rlcmac_tbf::check_polling(uint32_t fn, uint8_t ts,
567
uint32_t *poll_fn_, unsigned int *rrbp_)
569
uint32_t new_poll_fn = next_fn(fn, 13);
571
if (!is_control_ts(ts)) {
572
LOGP(DRLCMAC, LOGL_DEBUG, "Polling cannot be "
573
"scheduled in this TS %d (first control TS %d)\n",
577
if (poll_state != GPRS_RLCMAC_POLL_NONE) {
578
LOGP(DRLCMAC, LOGL_DEBUG,
579
"Polling is already scheduled for %s\n",
583
if (bts->sba()->find(trx->trx_no, ts, next_fn(fn, 13))) {
584
LOGP(DRLCMAC, LOGL_DEBUG, "%s: Polling is already scheduled "
585
"for single block allocation at FN %d TS %d ...\n",
586
name(), new_poll_fn, ts);
590
*poll_fn_ = new_poll_fn;
596
void gprs_rlcmac_tbf::set_polling(uint32_t new_poll_fn, uint8_t ts, enum gprs_rlcmac_tbf_poll_type t)
598
const char *chan = "UNKNOWN";
600
if (state_flags & (1 << (GPRS_RLCMAC_FLAG_CCCH)))
603
if (state_flags & (1 << (GPRS_RLCMAC_FLAG_PACCH)))
606
if ((state_flags & (1 << (GPRS_RLCMAC_FLAG_PACCH))) && (state_flags & (1 << (GPRS_RLCMAC_FLAG_CCCH))))
607
LOGP(DRLCMACDL, LOGL_ERROR,
608
"%s Attempt to schedule polling on %s (FN=%d, TS=%d) with both CCCH and PACCH flags set - FIXME!\n",
609
name(), chan, poll_fn, poll_ts);
611
/* schedule polling */
612
poll_state = GPRS_RLCMAC_POLL_SCHED;
613
poll_fn = new_poll_fn;
617
case GPRS_RLCMAC_POLL_UL_ASS:
618
ul_ass_state = GPRS_RLCMAC_UL_ASS_WAIT_ACK;
620
LOGP(DRLCMACDL, LOGL_INFO, "%s Scheduled UL Assignment polling on %s (FN=%d, TS=%d)\n",
621
name(), chan, poll_fn, poll_ts);
623
case GPRS_RLCMAC_POLL_DL_ASS:
624
dl_ass_state = GPRS_RLCMAC_DL_ASS_WAIT_ACK;
626
LOGP(DRLCMACDL, LOGL_INFO, "%s Scheduled DL Assignment polling on %s (FN=%d, TS=%d)\n",
627
name(), chan, poll_fn, poll_ts);
629
case GPRS_RLCMAC_POLL_UL_ACK:
630
ul_ack_state = GPRS_RLCMAC_UL_ACK_WAIT_ACK;
632
LOGP(DRLCMACUL, LOGL_DEBUG, "%s Scheduled UL Acknowledgement polling on %s (FN=%d, TS=%d)\n",
633
name(), chan, poll_fn, poll_ts);
635
case GPRS_RLCMAC_POLL_DL_ACK:
636
LOGP(DRLCMACDL, LOGL_DEBUG, "%s Scheduled DL Acknowledgement polling on %s (FN=%d, TS=%d)\n",
637
name(), chan, poll_fn, poll_ts);
642
void gprs_rlcmac_tbf::poll_timeout()
644
gprs_rlcmac_ul_tbf *ul_tbf = as_ul_tbf(this);
646
LOGP(DRLCMAC, LOGL_NOTICE, "%s poll timeout for FN=%d, TS=%d (curr FN %d)\n",
647
tbf_name(this), poll_fn, poll_ts, bts->current_frame_number());
649
poll_state = GPRS_RLCMAC_POLL_NONE;
651
if (ul_tbf && ul_tbf->handle_ctrl_ack()) {
652
if (!ul_tbf->ctrl_ack_to_toggle()) {
653
LOGP(DRLCMAC, LOGL_NOTICE, "- Timeout for polling PACKET CONTROL ACK for PACKET UPLINK ACK\n");
656
bts->rlc_ack_timedout();
657
bts->pkt_ul_ack_nack_poll_timedout();
658
if (state_is(GPRS_RLCMAC_FINISHED)) {
660
if (ul_tbf->m_n3103 == ul_tbf->bts->bts_data()->n3103) {
661
LOGP(DRLCMAC, LOGL_NOTICE,
662
"- N3103 exceeded\n");
663
bts->pkt_ul_ack_nack_poll_failed();
664
ul_tbf->set_state(GPRS_RLCMAC_RELEASING);
665
tbf_timer_start(ul_tbf, 3169, ul_tbf->bts->bts_data()->t3169, 0);
668
/* reschedule UL ack */
669
ul_tbf->ul_ack_state = GPRS_RLCMAC_UL_ACK_SEND_ACK;
672
} else if (ul_ass_state == GPRS_RLCMAC_UL_ASS_WAIT_ACK) {
673
if (!(state_flags & (1 << GPRS_RLCMAC_FLAG_TO_UL_ASS))) {
674
LOGP(DRLCMAC, LOGL_NOTICE, "- Timeout for polling "
675
"PACKET CONTROL ACK for PACKET UPLINK "
678
state_flags |= (1 << GPRS_RLCMAC_FLAG_TO_UL_ASS);
680
ul_ass_state = GPRS_RLCMAC_UL_ASS_NONE;
682
bts->rlc_ass_timedout();
683
bts->pua_poll_timedout();
684
if (n3105 == bts_data()->n3105) {
685
LOGP(DRLCMAC, LOGL_NOTICE, "- N3105 exceeded\n");
686
set_state(GPRS_RLCMAC_RELEASING);
687
tbf_timer_start(this, 3195, bts_data()->t3195, 0);
688
bts->rlc_ass_failed();
689
bts->pua_poll_failed();
692
/* reschedule UL assignment */
693
ul_ass_state = GPRS_RLCMAC_UL_ASS_SEND_ASS;
694
} else if (dl_ass_state == GPRS_RLCMAC_DL_ASS_WAIT_ACK) {
695
if (!(state_flags & (1 << GPRS_RLCMAC_FLAG_TO_DL_ASS))) {
696
LOGP(DRLCMAC, LOGL_NOTICE, "- Timeout for polling "
697
"PACKET CONTROL ACK for PACKET DOWNLINK "
700
state_flags |= (1 << GPRS_RLCMAC_FLAG_TO_DL_ASS);
702
dl_ass_state = GPRS_RLCMAC_DL_ASS_NONE;
704
bts->rlc_ass_timedout();
705
bts->pda_poll_timedout();
706
if (n3105 == bts->bts_data()->n3105) {
707
LOGP(DRLCMAC, LOGL_NOTICE, "- N3105 exceeded\n");
708
set_state(GPRS_RLCMAC_RELEASING);
709
tbf_timer_start(this, 3195, bts_data()->t3195, 0);
710
bts->rlc_ass_failed();
711
bts->pda_poll_failed();
714
/* reschedule DL assignment */
715
dl_ass_state = GPRS_RLCMAC_DL_ASS_SEND_ASS;
716
} else if (direction == GPRS_RLCMAC_DL_TBF) {
717
gprs_rlcmac_dl_tbf *dl_tbf = as_dl_tbf(this);
719
if (!(dl_tbf->state_flags & (1 << GPRS_RLCMAC_FLAG_TO_DL_ACK))) {
720
LOGP(DRLCMAC, LOGL_NOTICE, "- Timeout for polling "
721
"PACKET DOWNLINK ACK.\n");
722
dl_tbf->rlcmac_diag();
723
dl_tbf->state_flags |= (1 << GPRS_RLCMAC_FLAG_TO_DL_ACK);
726
if (dl_tbf->state_is(GPRS_RLCMAC_RELEASING))
727
bts->rlc_rel_timedout();
729
bts->rlc_ack_timedout();
730
bts->pkt_dl_ack_nack_poll_timedout();
732
if (dl_tbf->n3105 == dl_tbf->bts->bts_data()->n3105) {
733
LOGP(DRLCMAC, LOGL_NOTICE, "- N3105 exceeded\n");
734
dl_tbf->set_state(GPRS_RLCMAC_RELEASING);
735
tbf_timer_start(dl_tbf, 3195, dl_tbf->bts_data()->t3195, 0);
736
bts->pkt_dl_ack_nack_poll_failed();
737
bts->rlc_ack_failed();
740
/* resend IMM.ASS on CCCH on timeout */
741
if ((dl_tbf->state_flags & (1 << GPRS_RLCMAC_FLAG_CCCH))
742
&& !(dl_tbf->state_flags & (1 << GPRS_RLCMAC_FLAG_DL_ACK))) {
743
LOGP(DRLCMAC, LOGL_DEBUG, "Re-send dowlink assignment "
744
"for %s on PCH (IMSI=%s)\n",
747
/* send immediate assignment */
748
dl_tbf->bts->snd_dl_ass(dl_tbf, 0, imsi());
749
dl_tbf->m_wait_confirm = 1;
752
LOGP(DRLCMAC, LOGL_ERROR, "- Poll Timeout, but no event!\n");
755
static int setup_tbf(struct gprs_rlcmac_tbf *tbf,
756
GprsMs *ms, int8_t use_trx,
757
uint8_t ms_class, uint8_t egprs_ms_class, uint8_t single_slot)
760
struct gprs_rlcmac_bts *bts;
764
bts = tbf->bts->bts_data();
766
if (ms->mode() == GprsCodingScheme::EGPRS)
767
ms_class = egprs_ms_class;
769
tbf->m_created_ts = time(NULL);
770
tbf->set_ms_class(ms_class);
771
/* select algorithm */
772
rc = bts->alloc_algorithm(bts, ms, tbf, bts->alloc_algorithm_curst,
773
single_slot, use_trx);
778
/* assign control ts */
779
rc = tbf_assign_control_ts(tbf);
786
gettimeofday(&tbf->meas.rssi_tv, NULL);
790
LOGP(DRLCMAC, LOGL_INFO,
791
"Allocated %s: trx = %d, ul_slots = %02x, dl_slots = %02x\n",
792
tbf->name(), tbf->trx->trx_no, tbf->ul_slots(), tbf->dl_slots());
794
tbf->m_ctrs = rate_ctr_group_alloc(tbf, &tbf_ctrg_desc, 0);
796
LOGP(DRLCMAC, LOGL_ERROR, "Couldn't allocate TBF counters\n");
803
gprs_rlcmac_ul_tbf::gprs_rlcmac_ul_tbf(BTS *bts_) :
804
gprs_rlcmac_tbf(bts_, GPRS_RLCMAC_UL_TBF),
807
m_contention_resolution_done(0),
809
m_ul_gprs_ctrs(NULL),
810
m_ul_egprs_ctrs(NULL)
812
memset(&m_usf, 0, sizeof(m_usf));
815
static int ul_tbf_dtor(struct gprs_rlcmac_ul_tbf *tbf)
817
tbf->~gprs_rlcmac_ul_tbf();
821
static void setup_egprs_mode(gprs_rlcmac_bts *bts, GprsMs *ms)
823
if (GprsCodingScheme::getEgprsByNum(bts->max_mcs_ul).isEgprsGmsk() &&
824
GprsCodingScheme::getEgprsByNum(bts->max_mcs_dl).isEgprsGmsk() &&
825
ms->mode() != GprsCodingScheme::EGPRS)
827
ms->set_mode(GprsCodingScheme::EGPRS_GMSK);
829
ms->set_mode(GprsCodingScheme::EGPRS);
833
struct gprs_rlcmac_ul_tbf *tbf_alloc_ul_tbf(struct gprs_rlcmac_bts *bts,
834
GprsMs *ms, int8_t use_trx,
835
uint8_t ms_class, uint8_t egprs_ms_class, uint8_t single_slot)
837
struct gprs_rlcmac_ul_tbf *tbf;
840
if (egprs_ms_class == 0 && bts->egprs_enabled) {
841
LOGP(DRLCMAC, LOGL_NOTICE,
842
"Not accepting non-EGPRS phone in EGPRS-only mode\n");
843
bts->bts->tbf_failed_egprs_only();
847
LOGP(DRLCMAC, LOGL_DEBUG, "********** TBF starts here **********\n");
848
LOGP(DRLCMAC, LOGL_INFO, "Allocating %s TBF: MS_CLASS=%d/%d\n",
849
"UL", ms_class, egprs_ms_class);
851
tbf = talloc(tall_pcu_ctx, struct gprs_rlcmac_ul_tbf);
856
talloc_set_destructor(tbf, ul_tbf_dtor);
857
new (tbf) gprs_rlcmac_ul_tbf(bts->bts);
860
ms = bts->bts->ms_alloc(ms_class, egprs_ms_class);
862
if (egprs_ms_class > 0 && bts->egprs_enabled) {
864
tbf->m_window.set_sns(RLC_EGPRS_SNS);
865
setup_egprs_mode(bts, ms);
866
LOGP(DRLCMAC, LOGL_INFO, "Enabled EGPRS for %s, mode %s\n",
867
tbf->name(), GprsCodingScheme::modeName(ms->mode()));
870
rc = setup_tbf(tbf, ms, use_trx, ms_class, egprs_ms_class, single_slot);
872
if (tbf->is_egprs_enabled())
873
tbf->egprs_calc_ulwindow_size();
881
tbf->m_ul_egprs_ctrs = rate_ctr_group_alloc(tbf, &tbf_ul_egprs_ctrg_desc, 0);
882
tbf->m_ul_gprs_ctrs = rate_ctr_group_alloc(tbf, &tbf_ul_gprs_ctrg_desc, 0);
883
if (!tbf->m_ul_egprs_ctrs || !tbf->m_ul_gprs_ctrs) {
884
LOGP(DRLCMAC, LOGL_ERROR, "Couldn't allocate TBF UL counters\n");
889
llist_add(&tbf->list(), &bts->bts->ul_tbfs());
890
tbf->bts->tbf_ul_created();
895
gprs_rlcmac_dl_tbf::BandWidth::BandWidth() :
901
timerclear(&dl_bw_tv);
902
timerclear(&dl_loss_tv);
905
gprs_rlcmac_dl_tbf::gprs_rlcmac_dl_tbf(BTS *bts_) :
906
gprs_rlcmac_tbf(bts_, GPRS_RLCMAC_DL_TBF),
909
m_dl_ack_requested(false),
910
m_last_dl_poll_fn(0),
911
m_last_dl_drained_fn(0),
912
m_dl_gprs_ctrs(NULL),
913
m_dl_egprs_ctrs(NULL)
915
memset(&m_llc_timer, 0, sizeof(m_llc_timer));
918
static int dl_tbf_dtor(struct gprs_rlcmac_dl_tbf *tbf)
920
tbf->~gprs_rlcmac_dl_tbf();
924
struct gprs_rlcmac_dl_tbf *tbf_alloc_dl_tbf(struct gprs_rlcmac_bts *bts,
925
GprsMs *ms, int8_t use_trx,
926
uint8_t ms_class, uint8_t egprs_ms_class, uint8_t single_slot)
928
struct gprs_rlcmac_dl_tbf *tbf;
931
if (egprs_ms_class == 0 && bts->egprs_enabled) {
933
LOGP(DRLCMAC, LOGL_NOTICE,
934
"Not accepting non-EGPRS phone in EGPRS-only mode\n");
935
bts->bts->tbf_failed_egprs_only();
941
LOGP(DRLCMAC, LOGL_DEBUG, "********** TBF starts here **********\n");
942
LOGP(DRLCMAC, LOGL_INFO, "Allocating %s TBF: MS_CLASS=%d/%d\n",
943
"DL", ms_class, egprs_ms_class);
945
tbf = talloc(tall_pcu_ctx, struct gprs_rlcmac_dl_tbf);
950
talloc_set_destructor(tbf, dl_tbf_dtor);
951
new (tbf) gprs_rlcmac_dl_tbf(bts->bts);
954
ms = bts->bts->ms_alloc(ms_class, egprs_ms_class);
956
if (egprs_ms_class > 0 && bts->egprs_enabled) {
958
tbf->m_window.set_sns(RLC_EGPRS_SNS);
959
setup_egprs_mode(bts, ms);
960
LOGP(DRLCMAC, LOGL_INFO, "Enabled EGPRS for %s, mode %s\n",
961
tbf->name(), GprsCodingScheme::modeName(ms->mode()));
964
rc = setup_tbf(tbf, ms, use_trx, ms_class, 0, single_slot);
971
if (tbf->is_egprs_enabled()) {
972
tbf->egprs_calc_window_size();
973
tbf->m_dl_egprs_ctrs = rate_ctr_group_alloc(tbf, &tbf_dl_egprs_ctrg_desc, 0);
974
if (!tbf->m_dl_egprs_ctrs) {
975
LOGP(DRLCMAC, LOGL_ERROR, "Couldn't allocate EGPRS DL counters\n");
980
tbf->m_dl_gprs_ctrs = rate_ctr_group_alloc(tbf, &tbf_dl_gprs_ctrg_desc, 0);
981
if (!tbf->m_dl_gprs_ctrs) {
982
LOGP(DRLCMAC, LOGL_ERROR, "Couldn't allocate GPRS DL counters\n");
988
llist_add(&tbf->list(), &bts->bts->dl_tbfs());
989
tbf->bts->tbf_dl_created();
991
tbf->m_last_dl_poll_fn = -1;
992
tbf->m_last_dl_drained_fn = -1;
994
gettimeofday(&tbf->m_bw.dl_bw_tv, NULL);
995
gettimeofday(&tbf->m_bw.dl_loss_tv, NULL);
1000
static void tbf_timer_cb(void *_tbf)
1002
struct gprs_rlcmac_tbf *tbf = (struct gprs_rlcmac_tbf *)_tbf;
1003
tbf->handle_timeout();
1006
void gprs_rlcmac_tbf::handle_timeout()
1008
LOGP(DRLCMAC, LOGL_DEBUG, "%s timer %u expired.\n",
1014
case 0: /* assignment */
1015
if ((state_flags & (1 << GPRS_RLCMAC_FLAG_PACCH))) {
1016
if (state_is(GPRS_RLCMAC_ASSIGN)) {
1017
LOGP(DRLCMAC, LOGL_NOTICE, "%s releasing due to "
1018
"PACCH assignment timeout.\n", tbf_name(this));
1022
LOGP(DRLCMAC, LOGL_ERROR, "Error: %s is not "
1023
"in assign state\n", tbf_name(this));
1025
if ((state_flags & (1 << GPRS_RLCMAC_FLAG_CCCH))) {
1026
gprs_rlcmac_dl_tbf *dl_tbf = as_dl_tbf(this);
1027
dl_tbf->m_wait_confirm = 0;
1028
if (dl_tbf->state_is(GPRS_RLCMAC_ASSIGN)) {
1029
tbf_assign_control_ts(dl_tbf);
1031
if (!dl_tbf->upgrade_to_multislot) {
1032
/* change state to FLOW, so scheduler
1033
* will start transmission */
1034
dl_tbf->set_state(GPRS_RLCMAC_FLOW);
1038
/* This tbf can be upgraded to use multiple DL
1039
* timeslots and now that there is already one
1040
* slot assigned send another DL assignment via
1044
dl_tbf->state_flags &= GPRS_RLCMAC_FLAG_TO_MASK;
1048
dl_tbf->trigger_ass(dl_tbf);
1050
LOGP(DRLCMAC, LOGL_NOTICE, "%s Continue flow after "
1051
"IMM.ASS confirm\n", tbf_name(dl_tbf));
1057
LOGP(DRLCMAC, LOGL_NOTICE, "%s T%d timeout during "
1058
"transsmission\n", tbf_name(this), T);
1062
LOGP(DRLCMAC, LOGL_DEBUG,
1063
"%s will be freed due to timeout\n", tbf_name(this));
1069
LOGP(DRLCMAC, LOGL_ERROR,
1070
"%s timer expired in unknown mode: %u\n", tbf_name(this), T);
1074
int gprs_rlcmac_tbf::rlcmac_diag()
1076
if ((state_flags & (1 << GPRS_RLCMAC_FLAG_CCCH)))
1077
LOGP(DRLCMAC, LOGL_NOTICE, "- Assignment was on CCCH\n");
1078
if ((state_flags & (1 << GPRS_RLCMAC_FLAG_PACCH)))
1079
LOGP(DRLCMAC, LOGL_NOTICE, "- Assignment was on PACCH\n");
1080
if ((state_flags & (1 << GPRS_RLCMAC_FLAG_UL_DATA)))
1081
LOGP(DRLCMAC, LOGL_NOTICE, "- Uplink data was received\n");
1082
else if (direction == GPRS_RLCMAC_UL_TBF)
1083
LOGP(DRLCMAC, LOGL_NOTICE, "- No uplink data received yet\n");
1084
if ((state_flags & (1 << GPRS_RLCMAC_FLAG_DL_ACK)))
1085
LOGP(DRLCMAC, LOGL_NOTICE, "- Downlink ACK was received\n");
1086
else if (direction == GPRS_RLCMAC_DL_TBF)
1087
LOGP(DRLCMAC, LOGL_NOTICE, "- No downlink ACK received yet\n");
1092
struct msgb *gprs_rlcmac_tbf::create_dl_ass(uint32_t fn, uint8_t ts)
1095
struct gprs_rlcmac_dl_tbf *new_dl_tbf = NULL;
1096
int poll_ass_dl = 1;
1097
unsigned int rrbp = 0;
1098
uint32_t new_poll_fn = 0;
1100
bool old_tfi_is_valid = is_tfi_assigned();
1102
if (direction == GPRS_RLCMAC_DL_TBF && !is_control_ts(ts)) {
1103
LOGP(DRLCMAC, LOGL_NOTICE, "Cannot poll for downlink "
1104
"assigment, because MS cannot reply. (TS=%d, "
1105
"first common TS=%d)\n", ts,
1110
if (poll_state == GPRS_RLCMAC_POLL_SCHED &&
1111
ul_ass_state == GPRS_RLCMAC_UL_ASS_WAIT_ACK)
1113
LOGP(DRLCMACUL, LOGL_DEBUG, "Polling is already "
1114
"scheduled for %s, so we must wait for the uplink "
1115
"assignment...\n", tbf_name(this));
1118
rc = check_polling(fn, ts, &new_poll_fn, &rrbp);
1123
/* on uplink TBF we get the downlink TBF to be assigned. */
1124
if (direction == GPRS_RLCMAC_UL_TBF) {
1125
gprs_rlcmac_ul_tbf *ul_tbf = as_ul_tbf(this);
1127
/* be sure to check first, if contention resolution is done,
1128
* otherwise we cannot send the assignment yet */
1129
if (!ul_tbf->m_contention_resolution_done) {
1130
LOGP(DRLCMAC, LOGL_DEBUG, "Cannot assign DL TBF now, "
1131
"because contention resolution is not "
1138
new_dl_tbf = ms()->dl_tbf();
1141
LOGP(DRLCMACDL, LOGL_ERROR, "We have a schedule for downlink "
1142
"assignment at %s, but there is no downlink "
1143
"TBF\n", tbf_name(this));
1144
dl_ass_state = GPRS_RLCMAC_DL_ASS_NONE;
1148
if (new_dl_tbf == as_dl_tbf(this))
1149
LOGP(DRLCMAC, LOGL_DEBUG,
1150
"New and old TBF are the same %s\n", name());
1152
if (old_tfi_is_valid && !new_dl_tbf->is_tlli_valid()) {
1153
LOGP(DRLCMACDL, LOGL_ERROR,
1154
"The old TFI is not assigned and there is no "
1155
"TLLI. Old TBF %s, new TBF %s\n",
1156
name(), new_dl_tbf->name());
1157
dl_ass_state = GPRS_RLCMAC_DL_ASS_NONE;
1161
new_dl_tbf->was_releasing = was_releasing;
1162
msg = msgb_alloc(23, "rlcmac_dl_ass");
1165
bitvec *ass_vec = bitvec_alloc(23, tall_pcu_ctx);
1170
bitvec_unhex(ass_vec,
1171
"2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b");
1172
LOGP(DRLCMAC, LOGL_INFO, "%s start Packet Downlink Assignment (PACCH)\n", tbf_name(new_dl_tbf));
1173
RlcMacDownlink_t * mac_control_block = (RlcMacDownlink_t *)talloc_zero(tall_pcu_ctx, RlcMacDownlink_t);
1174
Encoding::write_packet_downlink_assignment(mac_control_block,
1175
old_tfi_is_valid, m_tfi, (direction == GPRS_RLCMAC_DL_TBF),
1176
new_dl_tbf, poll_ass_dl, rrbp,
1177
bts_data()->alpha, bts_data()->gamma, -1, 0,
1178
is_egprs_enabled());
1179
LOGP(DRLCMAC, LOGL_DEBUG, "+++++++++++++++++++++++++ TX : Packet Downlink Assignment +++++++++++++++++++++++++\n");
1180
encode_gsm_rlcmac_downlink(ass_vec, mac_control_block);
1181
LOGPC(DCSN1, LOGL_NOTICE, "\n");
1182
LOGP(DRLCMAC, LOGL_DEBUG, "------------------------- TX : Packet Downlink Assignment -------------------------\n");
1183
bts->pkt_dl_assignemnt();
1184
bitvec_pack(ass_vec, msgb_put(msg, 23));
1185
bitvec_free(ass_vec);
1186
talloc_free(mac_control_block);
1189
set_polling(new_poll_fn, ts, GPRS_RLCMAC_POLL_DL_ASS);
1191
dl_ass_state = GPRS_RLCMAC_DL_ASS_NONE;
1192
new_dl_tbf->set_state(GPRS_RLCMAC_FLOW);
1193
tbf_assign_control_ts(new_dl_tbf);
1194
/* stop pending assignment timer */
1195
new_dl_tbf->stop_timer();
1202
struct msgb *gprs_rlcmac_tbf::create_packet_access_reject()
1206
msg = msgb_alloc(23, "rlcmac_ul_ass_rej");
1208
bitvec *packet_access_rej = bitvec_alloc(23, tall_pcu_ctx);
1210
bitvec_unhex(packet_access_rej,
1211
"2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b");
1213
Encoding::write_packet_access_reject(
1214
packet_access_rej, tlli());
1216
bts->pkt_access_reject();
1218
bitvec_pack(packet_access_rej, msgb_put(msg, 23));
1220
bitvec_free(packet_access_rej);
1221
ul_ass_state = GPRS_RLCMAC_UL_ASS_NONE;
1223
/* Start Tmr only if it is UL TBF */
1224
if (direction == GPRS_RLCMAC_UL_TBF)
1225
tbf_timer_start(this, 0, Treject_pacch);
1231
struct msgb *gprs_rlcmac_tbf::create_ul_ass(uint32_t fn, uint8_t ts)
1234
struct gprs_rlcmac_ul_tbf *new_tbf = NULL;
1237
uint32_t new_poll_fn;
1239
if (poll_state == GPRS_RLCMAC_POLL_SCHED &&
1240
ul_ass_state == GPRS_RLCMAC_UL_ASS_WAIT_ACK) {
1241
LOGP(DRLCMACUL, LOGL_DEBUG, "Polling is already "
1242
"scheduled for %s, so we must wait for the uplink "
1243
"assignment...\n", tbf_name(this));
1247
rc = check_polling(fn, ts, &new_poll_fn, &rrbp);
1252
new_tbf = ms()->ul_tbf();
1254
LOGP(DRLCMACUL, LOGL_ERROR, "We have a schedule for uplink "
1255
"assignment at downlink %s, but there is no uplink "
1256
"TBF\n", tbf_name(this));
1257
ul_ass_state = GPRS_RLCMAC_UL_ASS_NONE;
1261
msg = msgb_alloc(23, "rlcmac_ul_ass");
1264
LOGP(DRLCMAC, LOGL_INFO, "%ss start Packet Uplink Assignment (PACCH)\n", tbf_name(new_tbf));
1265
bitvec *ass_vec = bitvec_alloc(23, tall_pcu_ctx);
1270
bitvec_unhex(ass_vec,
1271
"2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b");
1272
Encoding::write_packet_uplink_assignment(bts_data(), ass_vec, m_tfi,
1273
(direction == GPRS_RLCMAC_DL_TBF), tlli(),
1274
is_tlli_valid(), new_tbf, 1, rrbp, bts_data()->alpha,
1275
bts_data()->gamma, -1, is_egprs_enabled());
1276
bitvec_pack(ass_vec, msgb_put(msg, 23));
1277
RlcMacDownlink_t * mac_control_block = (RlcMacDownlink_t *)talloc_zero(tall_pcu_ctx, RlcMacDownlink_t);
1278
LOGP(DRLCMAC, LOGL_DEBUG, "+++++++++++++++++++++++++ TX : Packet Uplink Assignment +++++++++++++++++++++++++\n");
1279
decode_gsm_rlcmac_downlink(ass_vec, mac_control_block);
1280
LOGPC(DCSN1, LOGL_NOTICE, "\n");
1281
LOGP(DRLCMAC, LOGL_DEBUG, "------------------------- TX : Packet Uplink Assignment -------------------------\n");
1282
bts->pkt_ul_assignment();
1283
bitvec_free(ass_vec);
1284
talloc_free(mac_control_block);
1286
set_polling(new_poll_fn, ts, GPRS_RLCMAC_POLL_UL_ASS);
1291
void gprs_rlcmac_tbf::free_all(struct gprs_rlcmac_trx *trx)
1293
for (uint8_t ts = 0; ts < 8; ts++)
1294
free_all(&trx->pdch[ts]);
1297
void gprs_rlcmac_tbf::free_all(struct gprs_rlcmac_pdch *pdch)
1299
for (uint8_t tfi = 0; tfi < 32; tfi++) {
1300
struct gprs_rlcmac_tbf *tbf;
1302
tbf = pdch->ul_tbf_by_tfi(tfi);
1305
tbf = pdch->dl_tbf_by_tfi(tfi);
1311
int gprs_rlcmac_tbf::establish_dl_tbf_on_pacch()
1313
struct gprs_rlcmac_dl_tbf *new_tbf = NULL;
1317
new_tbf = tbf_alloc_dl_tbf(bts->bts_data(), ms(),
1318
this->trx->trx_no, ms_class(),
1319
ms() ? ms()->egprs_ms_class() : 0, 0);
1322
LOGP(DRLCMAC, LOGL_NOTICE, "No PDCH resource\n");
1326
LOGP(DRLCMAC, LOGL_DEBUG, "%s Trigger downlink assignment on PACCH\n",
1328
new_tbf->trigger_ass(this);
1333
int gprs_rlcmac_tbf::set_tlli_from_ul(uint32_t new_tlli)
1335
struct gprs_rlcmac_tbf *dl_tbf = NULL;
1336
struct gprs_rlcmac_tbf *ul_tbf = NULL;
1339
OSMO_ASSERT(direction == GPRS_RLCMAC_UL_TBF);
1341
old_ms = bts->ms_by_tlli(new_tlli);
1342
/* Keep the old MS object for the update_ms() */
1343
GprsMs::Guard guard(old_ms);
1345
/* Get them before calling set_ms() */
1346
dl_tbf = old_ms->dl_tbf();
1347
ul_tbf = old_ms->ul_tbf();
1353
if (dl_tbf && dl_tbf->ms() != ms()) {
1354
LOGP(DRLCMACUL, LOGL_NOTICE, "Got RACH from "
1355
"TLLI=0x%08x while %s still exists. "
1356
"Killing pending DL TBF\n", new_tlli,
1361
if (ul_tbf && ul_tbf->ms() != ms()) {
1362
LOGP(DRLCMACUL, LOGL_NOTICE, "Got RACH from "
1363
"TLLI=0x%08x while %s still exists. "
1364
"Killing pending UL TBF\n", new_tlli,
1370
/* The TLLI has been taken from an UL message */
1371
update_ms(new_tlli, GPRS_RLCMAC_UL_TBF);
1373
#if 0 /* REMOVEME ??? */
1374
if (ms()->need_dl_tbf())
1375
establish_dl_tbf_on_pacch();
1380
const char *tbf_name(gprs_rlcmac_tbf *tbf)
1382
return tbf ? tbf->name() : "(no TBF)";
1385
const char *gprs_rlcmac_tbf::name() const
1387
snprintf(m_name_buf, sizeof(m_name_buf) - 1,
1388
"TBF(TFI=%d TLLI=0x%08x DIR=%s STATE=%s%s)",
1390
direction == GPRS_RLCMAC_UL_TBF ? "UL" : "DL",
1392
is_egprs_enabled() ? " EGPRS" : ""
1394
m_name_buf[sizeof(m_name_buf) - 1] = '\0';
1398
void gprs_rlcmac_tbf::rotate_in_list()
1401
if (direction == GPRS_RLCMAC_UL_TBF)
1402
llist_add(&list(), &bts->ul_tbfs());
1404
llist_add(&list(), &bts->dl_tbfs());
1407
uint8_t gprs_rlcmac_tbf::tsc() const
1409
return trx->pdch[first_ts].tsc;
1412
uint8_t gprs_rlcmac_tbf::dl_slots() const
1417
if (direction == GPRS_RLCMAC_UL_TBF)
1420
for (i = 0; i < ARRAY_SIZE(pdch); i += 1)
1427
uint8_t gprs_rlcmac_tbf::ul_slots() const
1432
if (direction == GPRS_RLCMAC_DL_TBF) {
1434
slots |= 1 << control_ts;
1435
if (first_common_ts < 8)
1436
slots |= 1 << first_common_ts;
1441
for (i = 0; i < ARRAY_SIZE(pdch); i += 1)
1448
bool gprs_rlcmac_tbf::is_control_ts(uint8_t ts) const
1450
return ts == control_ts;
1453
struct gprs_rlcmac_ul_tbf *handle_tbf_reject(struct gprs_rlcmac_bts *bts,
1454
GprsMs *ms, uint32_t tlli, uint8_t trx_no, uint8_t ts)
1456
struct gprs_rlcmac_ul_tbf *ul_tbf = NULL;
1457
struct gprs_rlcmac_trx *trx = &bts->trx[trx_no];
1459
ul_tbf = talloc(tall_pcu_ctx, struct gprs_rlcmac_ul_tbf);
1463
talloc_set_destructor(ul_tbf, ul_tbf_dtor);
1464
new (ul_tbf) gprs_rlcmac_ul_tbf(bts->bts);
1466
ms = bts->bts->ms_alloc(0, 0);
1470
llist_add(&ul_tbf->list(), &bts->bts->ul_tbfs());
1471
ul_tbf->bts->tbf_ul_created();
1472
ul_tbf->set_state(GPRS_RLCMAC_ASSIGN);
1473
ul_tbf->state_flags |= (1 << GPRS_RLCMAC_FLAG_PACCH);
1476
ul_tbf->update_ms(tlli, GPRS_RLCMAC_UL_TBF);
1477
ul_tbf->ul_ass_state = GPRS_RLCMAC_UL_ASS_SEND_ASS_REJ;
1478
ul_tbf->control_ts = ts;
1480
ul_tbf->m_ctrs = rate_ctr_group_alloc(ul_tbf, &tbf_ctrg_desc, 0);
1481
ul_tbf->m_ul_egprs_ctrs = rate_ctr_group_alloc(ul_tbf,
1482
&tbf_ul_egprs_ctrg_desc, 0);
1483
ul_tbf->m_ul_gprs_ctrs = rate_ctr_group_alloc(ul_tbf,
1484
&tbf_ul_gprs_ctrg_desc, 0);
1485
if (!ul_tbf->m_ctrs || !ul_tbf->m_ul_egprs_ctrs || !ul_tbf->m_ul_gprs_ctrs) {
1486
LOGP(DRLCMAC, LOGL_ERROR, "Cound not allocate TBF UL rate counters\n");
1487
talloc_free(ul_tbf);