2013-08-24 16:31:27 +00:00
|
|
|
/* Copied from gprs_bssgp_pcu.cpp
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Ivan Klyuchnikov
|
2013-08-24 19:26:42 +00:00
|
|
|
* Copyright (C) 2012 Andreas Eversberg <jolly@eversberg.eu>
|
2013-08-24 16:31:27 +00:00
|
|
|
* Copyright (C) 2013 by Holger Hans Peter Freyther
|
|
|
|
*
|
|
|
|
* This program 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 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2013-10-17 15:01:54 +00:00
|
|
|
#include <bts.h>
|
2013-08-24 16:31:27 +00:00
|
|
|
#include <tbf.h>
|
2013-10-26 15:32:04 +00:00
|
|
|
#include <rlc.h>
|
2013-10-26 18:45:35 +00:00
|
|
|
#include <encoding.h>
|
2013-08-24 16:31:27 +00:00
|
|
|
#include <gprs_rlcmac.h>
|
|
|
|
#include <gprs_debug.h>
|
2013-10-26 19:38:30 +00:00
|
|
|
#include <gprs_bssgp_pcu.h>
|
2013-11-06 18:16:43 +00:00
|
|
|
#include <decoding.h>
|
2013-08-24 16:31:27 +00:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include <osmocom/core/msgb.h>
|
2013-10-16 15:55:57 +00:00
|
|
|
#include <osmocom/core/talloc.h>
|
2013-08-24 16:31:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2013-10-16 16:09:19 +00:00
|
|
|
extern void *tall_pcu_ctx;
|
|
|
|
|
2013-10-26 15:56:15 +00:00
|
|
|
static void tbf_timer_cb(void *_tbf);
|
|
|
|
|
2014-08-08 10:14:12 +00:00
|
|
|
gprs_rlcmac_bts *gprs_rlcmac_tbf::bts_data() const
|
2013-10-26 18:12:59 +00:00
|
|
|
{
|
|
|
|
return bts->bts_data();
|
|
|
|
}
|
|
|
|
|
2013-10-27 19:57:35 +00:00
|
|
|
void gprs_rlcmac_tbf::assign_imsi(const char *imsi)
|
2013-08-24 18:51:06 +00:00
|
|
|
{
|
2013-10-27 19:57:35 +00:00
|
|
|
strncpy(m_imsi, imsi, sizeof(m_imsi));
|
|
|
|
m_imsi[sizeof(m_imsi) - 1] = '\0';
|
2013-08-24 18:51:06 +00:00
|
|
|
}
|
|
|
|
|
2014-07-10 15:44:07 +00:00
|
|
|
gprs_rlcmac_ul_tbf *tbf_alloc_ul(struct gprs_rlcmac_bts *bts,
|
2013-08-24 19:26:42 +00:00
|
|
|
int8_t use_trx, uint8_t ms_class,
|
|
|
|
uint32_t tlli, uint8_t ta, struct gprs_rlcmac_tbf *dl_tbf)
|
|
|
|
{
|
|
|
|
uint8_t trx;
|
2014-07-10 15:44:07 +00:00
|
|
|
struct gprs_rlcmac_ul_tbf *tbf;
|
2013-11-11 15:22:39 +00:00
|
|
|
int8_t tfi; /* must be signed */
|
2013-08-24 19:26:42 +00:00
|
|
|
|
|
|
|
#warning "Copy and paste with tbf_new_dl_assignment"
|
2013-12-25 18:15:57 +00:00
|
|
|
/* create new TBF, use same TRX as DL TBF */
|
2013-10-26 17:17:58 +00:00
|
|
|
tfi = bts->bts->tfi_find_free(GPRS_RLCMAC_UL_TBF, &trx, use_trx);
|
2013-08-24 19:26:42 +00:00
|
|
|
if (tfi < 0) {
|
2013-10-27 09:38:31 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_NOTICE, "No PDCH resource\n");
|
2013-08-24 19:26:42 +00:00
|
|
|
/* FIXME: send reject */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/* use multislot class of downlink TBF */
|
2014-07-16 16:54:10 +00:00
|
|
|
tbf = tbf_alloc_ul_tbf(bts, dl_tbf, tfi, trx, ms_class, 0);
|
2013-08-24 19:26:42 +00:00
|
|
|
if (!tbf) {
|
2013-10-27 09:38:31 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_NOTICE, "No PDCH resource\n");
|
2013-08-24 19:26:42 +00:00
|
|
|
/* FIXME: send reject */
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-10-27 16:01:14 +00:00
|
|
|
tbf->m_tlli = tlli;
|
|
|
|
tbf->m_tlli_valid = 1; /* no contention resolution */
|
2014-08-07 13:49:21 +00:00
|
|
|
tbf->m_contention_resolution_done = 1;
|
2013-08-24 19:26:42 +00:00
|
|
|
tbf->ta = ta; /* use current TA */
|
2014-08-08 09:43:53 +00:00
|
|
|
tbf->set_state(GPRS_RLCMAC_ASSIGN);
|
2013-08-24 19:26:42 +00:00
|
|
|
tbf->state_flags |= (1 << GPRS_RLCMAC_FLAG_PACCH);
|
|
|
|
tbf_timer_start(tbf, 3169, bts->t3169, 0);
|
|
|
|
|
|
|
|
return tbf;
|
|
|
|
}
|
2013-10-16 15:53:23 +00:00
|
|
|
|
2013-10-16 15:55:57 +00:00
|
|
|
static void tbf_unlink_pdch(struct gprs_rlcmac_tbf *tbf)
|
|
|
|
{
|
|
|
|
int ts;
|
|
|
|
|
|
|
|
if (tbf->direction == GPRS_RLCMAC_UL_TBF) {
|
2013-10-27 19:31:47 +00:00
|
|
|
tbf->trx->ul_tbf[tbf->tfi()] = NULL;
|
2014-05-30 18:21:30 +00:00
|
|
|
for (ts = 0; ts < 8; ts++)
|
2013-10-16 15:55:57 +00:00
|
|
|
tbf->pdch[ts] = NULL;
|
|
|
|
} else {
|
2013-10-27 19:31:47 +00:00
|
|
|
tbf->trx->dl_tbf[tbf->tfi()] = NULL;
|
2014-05-30 18:21:30 +00:00
|
|
|
for (ts = 0; ts < 8; ts++)
|
2013-10-16 15:55:57 +00:00
|
|
|
tbf->pdch[ts] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tbf_free(struct gprs_rlcmac_tbf *tbf)
|
|
|
|
{
|
|
|
|
/* Give final measurement report */
|
|
|
|
gprs_rlcmac_rssi_rep(tbf);
|
2014-08-08 09:21:04 +00:00
|
|
|
if (tbf->direction == GPRS_RLCMAC_DL_TBF) {
|
|
|
|
gprs_rlcmac_dl_tbf *dl_tbf = static_cast<gprs_rlcmac_dl_tbf *>(tbf);
|
|
|
|
gprs_rlcmac_lost_rep(dl_tbf);
|
|
|
|
}
|
2013-10-16 15:55:57 +00:00
|
|
|
|
2013-10-27 15:39:36 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_INFO, "%s free\n", tbf_name(tbf));
|
2013-10-16 15:55:57 +00:00
|
|
|
if (tbf->ul_ass_state != GPRS_RLCMAC_UL_ASS_NONE)
|
2013-10-27 15:39:36 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_ERROR, "%s Software error: Pending uplink "
|
2013-10-16 15:55:57 +00:00
|
|
|
"assignment. This may not happen, because the "
|
|
|
|
"assignment message never gets transmitted. Please "
|
2013-10-27 15:39:36 +00:00
|
|
|
"be sure not to free in this state. PLEASE FIX!\n",
|
|
|
|
tbf_name(tbf));
|
2013-10-16 15:55:57 +00:00
|
|
|
if (tbf->dl_ass_state != GPRS_RLCMAC_DL_ASS_NONE)
|
2013-10-27 15:39:36 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_ERROR, "%s Software error: Pending downlink "
|
2013-10-16 15:55:57 +00:00
|
|
|
"assignment. This may not happen, because the "
|
|
|
|
"assignment message never gets transmitted. Please "
|
2013-10-27 15:39:36 +00:00
|
|
|
"be sure not to free in this state. PLEASE FIX!\n",
|
|
|
|
tbf_name(tbf));
|
2013-10-26 16:01:35 +00:00
|
|
|
tbf->stop_timer();
|
2013-10-26 16:31:51 +00:00
|
|
|
#warning "TODO: Could/Should generate bssgp_tx_llc_discarded"
|
2013-11-06 19:39:45 +00:00
|
|
|
tbf->m_llc.clear(tbf->bts);
|
2013-10-16 15:55:57 +00:00
|
|
|
tbf_unlink_pdch(tbf);
|
2014-07-30 11:25:19 +00:00
|
|
|
llist_del(&tbf->list.list);
|
2013-10-27 08:50:15 +00:00
|
|
|
|
|
|
|
if (tbf->direction == GPRS_RLCMAC_UL_TBF)
|
|
|
|
tbf->bts->tbf_ul_freed();
|
|
|
|
else
|
|
|
|
tbf->bts->tbf_dl_freed();
|
|
|
|
|
2013-10-16 15:55:57 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_DEBUG, "********** TBF ends here **********\n");
|
|
|
|
talloc_free(tbf);
|
|
|
|
}
|
|
|
|
|
2013-10-26 15:49:36 +00:00
|
|
|
int gprs_rlcmac_tbf::update()
|
2013-10-16 15:55:57 +00:00
|
|
|
{
|
|
|
|
struct gprs_rlcmac_tbf *ul_tbf = NULL;
|
2013-10-26 15:49:36 +00:00
|
|
|
struct gprs_rlcmac_bts *bts_data = bts->bts_data();
|
2013-10-16 15:55:57 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
LOGP(DRLCMAC, LOGL_DEBUG, "********** TBF update **********\n");
|
|
|
|
|
2013-10-26 15:49:36 +00:00
|
|
|
if (direction != GPRS_RLCMAC_DL_TBF)
|
2013-10-16 15:55:57 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
2014-07-02 15:58:14 +00:00
|
|
|
ul_tbf = bts->ul_tbf_by_tlli(m_tlli);
|
2013-10-16 15:55:57 +00:00
|
|
|
|
2013-10-26 15:49:36 +00:00
|
|
|
tbf_unlink_pdch(this);
|
|
|
|
rc = bts_data->alloc_algorithm(bts_data, ul_tbf, this, bts_data->alloc_algorithm_curst, 0);
|
2013-10-27 09:38:31 +00:00
|
|
|
/* if no resource */
|
2013-10-16 15:55:57 +00:00
|
|
|
if (rc < 0) {
|
2013-10-27 09:38:31 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_ERROR, "No resource after update???\n");
|
2013-10-16 15:55:57 +00:00
|
|
|
return -rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int tbf_assign_control_ts(struct gprs_rlcmac_tbf *tbf)
|
|
|
|
{
|
|
|
|
if (tbf->control_ts == 0xff)
|
|
|
|
LOGP(DRLCMAC, LOGL_INFO, "- Setting Control TS %d\n",
|
|
|
|
tbf->first_common_ts);
|
|
|
|
else if (tbf->control_ts != tbf->first_common_ts)
|
|
|
|
LOGP(DRLCMAC, LOGL_INFO, "- Changing Control TS %d\n",
|
|
|
|
tbf->first_common_ts);
|
|
|
|
tbf->control_ts = tbf->first_common_ts;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-08 09:43:53 +00:00
|
|
|
const char *gprs_rlcmac_tbf::tbf_state_name[] = {
|
2013-10-16 15:55:57 +00:00
|
|
|
"NULL",
|
|
|
|
"ASSIGN",
|
|
|
|
"FLOW",
|
|
|
|
"FINISHED",
|
|
|
|
"WAIT RELEASE",
|
|
|
|
"RELEASING",
|
|
|
|
};
|
|
|
|
|
|
|
|
void tbf_timer_start(struct gprs_rlcmac_tbf *tbf, unsigned int T,
|
|
|
|
unsigned int seconds, unsigned int microseconds)
|
|
|
|
{
|
|
|
|
if (!osmo_timer_pending(&tbf->timer))
|
2013-10-27 15:39:36 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_DEBUG, "%s starting timer %u.\n",
|
|
|
|
tbf_name(tbf), T);
|
2013-10-16 15:55:57 +00:00
|
|
|
else
|
2013-10-27 15:39:36 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_DEBUG, "%s restarting timer %u "
|
2013-10-16 15:55:57 +00:00
|
|
|
"while old timer %u pending \n",
|
2013-10-27 15:39:36 +00:00
|
|
|
tbf_name(tbf), T, tbf->T);
|
2013-10-16 15:55:57 +00:00
|
|
|
|
|
|
|
tbf->T = T;
|
|
|
|
tbf->num_T_exp = 0;
|
|
|
|
|
|
|
|
/* Tunning timers can be safely re-scheduled. */
|
|
|
|
tbf->timer.data = tbf;
|
|
|
|
tbf->timer.cb = &tbf_timer_cb;
|
|
|
|
|
|
|
|
osmo_timer_schedule(&tbf->timer, seconds, microseconds);
|
|
|
|
}
|
|
|
|
|
2013-10-26 16:01:35 +00:00
|
|
|
void gprs_rlcmac_tbf::stop_t3191()
|
2013-10-16 15:55:57 +00:00
|
|
|
{
|
2013-10-26 16:01:35 +00:00
|
|
|
return stop_timer();
|
|
|
|
}
|
|
|
|
|
|
|
|
void gprs_rlcmac_tbf::stop_timer()
|
|
|
|
{
|
|
|
|
if (osmo_timer_pending(&timer)) {
|
2013-10-27 15:39:36 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_DEBUG, "%s stopping timer %u.\n",
|
|
|
|
tbf_name(this), T);
|
2013-10-26 16:01:35 +00:00
|
|
|
osmo_timer_del(&timer);
|
2013-10-16 15:55:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-26 18:12:59 +00:00
|
|
|
void gprs_rlcmac_tbf::poll_timeout()
|
|
|
|
{
|
2013-10-27 15:39:36 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_NOTICE, "%s poll timeout\n",
|
|
|
|
tbf_name(this));
|
2013-10-26 18:12:59 +00:00
|
|
|
|
|
|
|
poll_state = GPRS_RLCMAC_POLL_NONE;
|
|
|
|
|
|
|
|
if (ul_ack_state == GPRS_RLCMAC_UL_ACK_WAIT_ACK) {
|
|
|
|
if (!(state_flags & (1 << GPRS_RLCMAC_FLAG_TO_UL_ACK))) {
|
|
|
|
LOGP(DRLCMAC, LOGL_NOTICE, "- Timeout for polling "
|
|
|
|
"PACKET CONTROL ACK for PACKET UPLINK ACK\n");
|
|
|
|
rlcmac_diag();
|
|
|
|
state_flags |= (1 << GPRS_RLCMAC_FLAG_TO_UL_ACK);
|
|
|
|
}
|
|
|
|
ul_ack_state = GPRS_RLCMAC_UL_ACK_NONE;
|
|
|
|
if (state_is(GPRS_RLCMAC_FINISHED)) {
|
2014-08-07 11:03:35 +00:00
|
|
|
gprs_rlcmac_ul_tbf *ul_tbf = static_cast<gprs_rlcmac_ul_tbf *>(this);
|
2014-08-07 13:49:21 +00:00
|
|
|
ul_tbf->m_n3103++;
|
|
|
|
if (ul_tbf->m_n3103 == ul_tbf->bts->bts_data()->n3103) {
|
2013-10-26 18:12:59 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_NOTICE,
|
|
|
|
"- N3103 exceeded\n");
|
2014-08-08 09:43:53 +00:00
|
|
|
ul_tbf->set_state(GPRS_RLCMAC_RELEASING);
|
2014-08-07 11:03:35 +00:00
|
|
|
tbf_timer_start(ul_tbf, 3169, ul_tbf->bts->bts_data()->t3169, 0);
|
2013-10-26 18:12:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* reschedule UL ack */
|
2014-08-07 11:03:35 +00:00
|
|
|
ul_tbf->ul_ack_state = GPRS_RLCMAC_UL_ACK_SEND_ACK;
|
2013-10-26 18:12:59 +00:00
|
|
|
}
|
|
|
|
} else if (ul_ass_state == GPRS_RLCMAC_UL_ASS_WAIT_ACK) {
|
|
|
|
if (!(state_flags & (1 << GPRS_RLCMAC_FLAG_TO_UL_ASS))) {
|
|
|
|
LOGP(DRLCMAC, LOGL_NOTICE, "- Timeout for polling "
|
|
|
|
"PACKET CONTROL ACK for PACKET UPLINK "
|
|
|
|
"ASSIGNMENT.\n");
|
|
|
|
rlcmac_diag();
|
|
|
|
state_flags |= (1 << GPRS_RLCMAC_FLAG_TO_UL_ASS);
|
|
|
|
}
|
|
|
|
ul_ass_state = GPRS_RLCMAC_UL_ASS_NONE;
|
|
|
|
n3105++;
|
|
|
|
if (n3105 == bts_data()->n3105) {
|
|
|
|
LOGP(DRLCMAC, LOGL_NOTICE, "- N3105 exceeded\n");
|
2014-08-08 09:43:53 +00:00
|
|
|
set_state(GPRS_RLCMAC_RELEASING);
|
2013-10-26 18:12:59 +00:00
|
|
|
tbf_timer_start(this, 3195, bts_data()->t3195, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* reschedule UL assignment */
|
|
|
|
ul_ass_state = GPRS_RLCMAC_UL_ASS_SEND_ASS;
|
|
|
|
} else if (dl_ass_state == GPRS_RLCMAC_DL_ASS_WAIT_ACK) {
|
|
|
|
if (!(state_flags & (1 << GPRS_RLCMAC_FLAG_TO_DL_ASS))) {
|
|
|
|
LOGP(DRLCMAC, LOGL_NOTICE, "- Timeout for polling "
|
|
|
|
"PACKET CONTROL ACK for PACKET DOWNLINK "
|
|
|
|
"ASSIGNMENT.\n");
|
|
|
|
rlcmac_diag();
|
|
|
|
state_flags |= (1 << GPRS_RLCMAC_FLAG_TO_DL_ASS);
|
|
|
|
}
|
|
|
|
dl_ass_state = GPRS_RLCMAC_DL_ASS_NONE;
|
|
|
|
n3105++;
|
|
|
|
if (n3105 == bts->bts_data()->n3105) {
|
|
|
|
LOGP(DRLCMAC, LOGL_NOTICE, "- N3105 exceeded\n");
|
2014-08-08 09:43:53 +00:00
|
|
|
set_state(GPRS_RLCMAC_RELEASING);
|
2013-10-26 18:12:59 +00:00
|
|
|
tbf_timer_start(this, 3195, bts_data()->t3195, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* reschedule DL assignment */
|
|
|
|
dl_ass_state = GPRS_RLCMAC_DL_ASS_SEND_ASS;
|
|
|
|
} else if (direction == GPRS_RLCMAC_DL_TBF) {
|
2014-08-07 11:03:35 +00:00
|
|
|
gprs_rlcmac_dl_tbf *dl_tbf = static_cast<gprs_rlcmac_dl_tbf *>(this);
|
|
|
|
|
|
|
|
if (!(dl_tbf->state_flags & (1 << GPRS_RLCMAC_FLAG_TO_DL_ACK))) {
|
2013-10-26 18:12:59 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_NOTICE, "- Timeout for polling "
|
|
|
|
"PACKET DOWNLINK ACK.\n");
|
2014-08-07 11:03:35 +00:00
|
|
|
dl_tbf->rlcmac_diag();
|
|
|
|
dl_tbf->state_flags |= (1 << GPRS_RLCMAC_FLAG_TO_DL_ACK);
|
2013-10-26 18:12:59 +00:00
|
|
|
}
|
2014-08-07 11:03:35 +00:00
|
|
|
dl_tbf->n3105++;
|
|
|
|
if (dl_tbf->n3105 == dl_tbf->bts->bts_data()->n3105) {
|
2013-10-26 18:12:59 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_NOTICE, "- N3105 exceeded\n");
|
2014-08-08 09:43:53 +00:00
|
|
|
dl_tbf->set_state(GPRS_RLCMAC_RELEASING);
|
2014-08-07 11:03:35 +00:00
|
|
|
tbf_timer_start(dl_tbf, 3195, dl_tbf->bts_data()->t3195, 0);
|
2013-10-26 18:12:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* resend IMM.ASS on CCCH on timeout */
|
2014-08-07 11:03:35 +00:00
|
|
|
if ((dl_tbf->state_flags & (1 << GPRS_RLCMAC_FLAG_CCCH))
|
|
|
|
&& !(dl_tbf->state_flags & (1 << GPRS_RLCMAC_FLAG_DL_ACK))) {
|
2013-10-26 18:12:59 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_DEBUG, "Re-send dowlink assignment "
|
2013-10-27 19:31:47 +00:00
|
|
|
"for %s on PCH (IMSI=%s)\n",
|
2014-08-07 11:03:35 +00:00
|
|
|
tbf_name(dl_tbf),
|
2013-10-27 19:57:35 +00:00
|
|
|
m_imsi);
|
2013-10-26 18:12:59 +00:00
|
|
|
/* send immediate assignment */
|
2014-08-07 11:03:35 +00:00
|
|
|
dl_tbf->bts->snd_dl_ass(dl_tbf, 0, m_imsi);
|
2014-08-07 13:49:21 +00:00
|
|
|
dl_tbf->m_wait_confirm = 1;
|
2013-10-26 18:12:59 +00:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
LOGP(DRLCMAC, LOGL_ERROR, "- Poll Timeout, but no event!\n");
|
|
|
|
}
|
|
|
|
|
2014-07-16 16:54:10 +00:00
|
|
|
static int setup_tbf(struct gprs_rlcmac_tbf *tbf, struct gprs_rlcmac_bts *bts,
|
|
|
|
struct gprs_rlcmac_tbf *old_tbf, uint8_t tfi, uint8_t trx,
|
2013-10-16 16:09:19 +00:00
|
|
|
uint8_t ms_class, uint8_t single_slot)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (trx >= 8 || tfi >= 32)
|
2014-07-16 16:54:10 +00:00
|
|
|
return -1;
|
2014-07-10 15:44:06 +00:00
|
|
|
|
2013-10-16 16:09:19 +00:00
|
|
|
if (!tbf)
|
2014-07-16 16:54:10 +00:00
|
|
|
return -1;
|
2013-10-16 16:09:19 +00:00
|
|
|
|
2014-07-30 11:25:19 +00:00
|
|
|
/* Back pointer for PODS llist compatibility */
|
|
|
|
tbf->list.back = tbf;
|
|
|
|
|
2014-01-16 09:07:20 +00:00
|
|
|
tbf->m_created_ts = time(NULL);
|
2013-10-19 19:24:34 +00:00
|
|
|
tbf->bts = bts->bts;
|
2013-10-27 19:31:47 +00:00
|
|
|
tbf->m_tfi = tfi;
|
2013-09-29 05:50:50 +00:00
|
|
|
tbf->trx = &bts->trx[trx];
|
2013-10-16 16:09:19 +00:00
|
|
|
tbf->ms_class = ms_class;
|
|
|
|
/* select algorithm */
|
|
|
|
rc = bts->alloc_algorithm(bts, old_tbf, tbf, bts->alloc_algorithm_curst,
|
|
|
|
single_slot);
|
2013-10-27 09:38:31 +00:00
|
|
|
/* if no resource */
|
2013-10-16 16:09:19 +00:00
|
|
|
if (rc < 0) {
|
2014-07-16 16:54:10 +00:00
|
|
|
return -1;
|
2013-10-16 16:09:19 +00:00
|
|
|
}
|
|
|
|
/* assign control ts */
|
|
|
|
tbf->control_ts = 0xff;
|
|
|
|
rc = tbf_assign_control_ts(tbf);
|
2013-10-27 09:38:31 +00:00
|
|
|
/* if no resource */
|
2013-10-16 16:09:19 +00:00
|
|
|
if (rc < 0) {
|
2014-07-16 16:54:10 +00:00
|
|
|
return -1;
|
2013-10-16 16:09:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* set timestamp */
|
|
|
|
gettimeofday(&tbf->meas.rssi_tv, NULL);
|
|
|
|
|
2013-11-06 19:39:45 +00:00
|
|
|
tbf->m_llc.init();
|
2014-07-16 16:54:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct gprs_rlcmac_ul_tbf *tbf_alloc_ul_tbf(struct gprs_rlcmac_bts *bts,
|
|
|
|
struct gprs_rlcmac_tbf *old_tbf, uint8_t tfi, uint8_t trx,
|
|
|
|
uint8_t ms_class, uint8_t single_slot)
|
|
|
|
{
|
|
|
|
struct gprs_rlcmac_ul_tbf *tbf;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
LOGP(DRLCMAC, LOGL_DEBUG, "********** TBF starts here **********\n");
|
|
|
|
LOGP(DRLCMAC, LOGL_INFO, "Allocating %s TBF: TFI=%d TRX=%d "
|
|
|
|
"MS_CLASS=%d\n", "UL", tfi, trx, ms_class);
|
|
|
|
|
|
|
|
if (trx >= 8 || tfi >= 32)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
tbf = talloc_zero(tall_pcu_ctx, struct gprs_rlcmac_ul_tbf);
|
|
|
|
|
|
|
|
if (!tbf)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
tbf->direction = GPRS_RLCMAC_UL_TBF;
|
|
|
|
rc = setup_tbf(tbf, bts, old_tbf, tfi, trx, ms_class, single_slot);
|
|
|
|
/* if no resource */
|
|
|
|
if (rc < 0) {
|
|
|
|
talloc_free(tbf);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-07-30 11:25:19 +00:00
|
|
|
llist_add(&tbf->list.list, &bts->ul_tbfs);
|
2014-07-16 16:54:10 +00:00
|
|
|
tbf->bts->tbf_ul_created();
|
|
|
|
|
|
|
|
return tbf;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct gprs_rlcmac_dl_tbf *tbf_alloc_dl_tbf(struct gprs_rlcmac_bts *bts,
|
|
|
|
struct gprs_rlcmac_tbf *old_tbf, uint8_t tfi, uint8_t trx,
|
|
|
|
uint8_t ms_class, uint8_t single_slot)
|
|
|
|
{
|
|
|
|
struct gprs_rlcmac_dl_tbf *tbf;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
LOGP(DRLCMAC, LOGL_DEBUG, "********** TBF starts here **********\n");
|
|
|
|
LOGP(DRLCMAC, LOGL_INFO, "Allocating %s TBF: TFI=%d TRX=%d "
|
|
|
|
"MS_CLASS=%d\n", "DL", tfi, trx, ms_class);
|
|
|
|
|
|
|
|
if (trx >= 8 || tfi >= 32)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
tbf = talloc_zero(tall_pcu_ctx, struct gprs_rlcmac_dl_tbf);
|
|
|
|
|
|
|
|
if (!tbf)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
tbf->direction = GPRS_RLCMAC_DL_TBF;
|
|
|
|
rc = setup_tbf(tbf, bts, old_tbf, tfi, trx, ms_class, single_slot);
|
|
|
|
/* if no resource */
|
|
|
|
if (rc < 0) {
|
|
|
|
talloc_free(tbf);
|
|
|
|
return NULL;
|
2013-10-27 08:50:15 +00:00
|
|
|
}
|
2013-10-16 16:09:19 +00:00
|
|
|
|
2014-07-30 11:25:19 +00:00
|
|
|
llist_add(&tbf->list.list, &bts->dl_tbfs);
|
2014-07-16 16:54:10 +00:00
|
|
|
tbf->bts->tbf_dl_created();
|
|
|
|
|
2014-08-08 09:21:04 +00:00
|
|
|
gettimeofday(&tbf->m_bw.dl_bw_tv, NULL);
|
|
|
|
gettimeofday(&tbf->m_bw.dl_loss_tv, NULL);
|
|
|
|
|
2013-10-16 16:09:19 +00:00
|
|
|
return tbf;
|
|
|
|
}
|
|
|
|
|
2013-10-26 15:56:15 +00:00
|
|
|
static void tbf_timer_cb(void *_tbf)
|
2013-10-16 16:09:19 +00:00
|
|
|
{
|
|
|
|
struct gprs_rlcmac_tbf *tbf = (struct gprs_rlcmac_tbf *)_tbf;
|
2013-10-26 15:56:15 +00:00
|
|
|
tbf->handle_timeout();
|
|
|
|
}
|
2013-10-16 16:09:19 +00:00
|
|
|
|
2013-10-26 15:56:15 +00:00
|
|
|
void gprs_rlcmac_tbf::handle_timeout()
|
|
|
|
{
|
2013-10-27 15:39:36 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_DEBUG, "%s timer %u expired.\n",
|
|
|
|
tbf_name(this), T);
|
2013-10-16 16:09:19 +00:00
|
|
|
|
2013-10-26 15:56:15 +00:00
|
|
|
num_T_exp++;
|
2013-10-16 16:09:19 +00:00
|
|
|
|
2013-10-26 15:56:15 +00:00
|
|
|
switch (T) {
|
2013-10-16 16:09:19 +00:00
|
|
|
case 0: /* assignment */
|
2013-10-26 15:56:15 +00:00
|
|
|
if ((state_flags & (1 << GPRS_RLCMAC_FLAG_PACCH))) {
|
|
|
|
if (state_is(GPRS_RLCMAC_ASSIGN)) {
|
2013-10-27 15:39:36 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_NOTICE, "%s releasing due to "
|
|
|
|
"PACCH assignment timeout.\n", tbf_name(this));
|
2013-10-26 15:56:15 +00:00
|
|
|
tbf_free(this);
|
2014-01-16 09:09:42 +00:00
|
|
|
return;
|
2013-10-16 16:09:19 +00:00
|
|
|
} else
|
2013-10-27 15:39:36 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_ERROR, "Error: %s is not "
|
|
|
|
"in assign state\n", tbf_name(this));
|
2013-10-16 16:09:19 +00:00
|
|
|
}
|
2013-10-26 15:56:15 +00:00
|
|
|
if ((state_flags & (1 << GPRS_RLCMAC_FLAG_CCCH))) {
|
2014-08-07 10:39:26 +00:00
|
|
|
gprs_rlcmac_dl_tbf *dl_tbf = static_cast<gprs_rlcmac_dl_tbf *>(this);
|
2014-08-07 13:49:21 +00:00
|
|
|
dl_tbf->m_wait_confirm = 0;
|
2014-08-07 10:39:26 +00:00
|
|
|
if (dl_tbf->state_is(GPRS_RLCMAC_ASSIGN)) {
|
|
|
|
tbf_assign_control_ts(dl_tbf);
|
2014-05-30 15:58:01 +00:00
|
|
|
|
2014-08-07 10:39:26 +00:00
|
|
|
if (!dl_tbf->upgrade_to_multislot) {
|
2014-05-30 15:58:01 +00:00
|
|
|
/* change state to FLOW, so scheduler
|
|
|
|
* will start transmission */
|
2014-08-08 09:43:53 +00:00
|
|
|
dl_tbf->set_state(GPRS_RLCMAC_FLOW);
|
2014-05-30 15:58:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This tbf can be upgraded to use multiple DL
|
|
|
|
* timeslots and now that there is already one
|
|
|
|
* slot assigned send another DL assignment via
|
|
|
|
* PDCH. */
|
|
|
|
|
|
|
|
/* keep to flags */
|
2014-08-07 10:39:26 +00:00
|
|
|
dl_tbf->state_flags &= GPRS_RLCMAC_FLAG_TO_MASK;
|
|
|
|
dl_tbf->state_flags &= ~(1 << GPRS_RLCMAC_FLAG_CCCH);
|
2014-05-30 15:58:01 +00:00
|
|
|
|
2014-08-07 10:39:26 +00:00
|
|
|
dl_tbf->update();
|
2014-05-30 15:58:01 +00:00
|
|
|
|
2014-08-07 10:39:26 +00:00
|
|
|
dl_tbf->bts->trigger_dl_ass(dl_tbf, dl_tbf, NULL);
|
2013-10-16 16:09:19 +00:00
|
|
|
} else
|
2013-10-27 15:39:36 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_NOTICE, "%s Continue flow after "
|
2014-08-07 10:39:26 +00:00
|
|
|
"IMM.ASS confirm\n", tbf_name(dl_tbf));
|
2013-10-16 16:09:19 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3169:
|
|
|
|
case 3191:
|
|
|
|
case 3195:
|
2013-10-27 15:39:36 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_NOTICE, "%s T%d timeout during "
|
|
|
|
"transsmission\n", tbf_name(this), T);
|
2013-10-26 15:56:15 +00:00
|
|
|
rlcmac_diag();
|
2013-10-16 16:09:19 +00:00
|
|
|
/* fall through */
|
|
|
|
case 3193:
|
2013-10-27 11:42:58 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_DEBUG,
|
2013-10-27 15:39:36 +00:00
|
|
|
"%s will be freed due to timeout\n", tbf_name(this));
|
2013-10-16 16:09:19 +00:00
|
|
|
/* free TBF */
|
2013-10-26 15:56:15 +00:00
|
|
|
tbf_free(this);
|
2014-01-16 09:09:42 +00:00
|
|
|
return;
|
2013-10-16 16:09:19 +00:00
|
|
|
break;
|
|
|
|
default:
|
2013-10-27 11:42:58 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_ERROR,
|
2013-10-27 15:39:36 +00:00
|
|
|
"%s timer expired in unknown mode: %u\n", tbf_name(this), T);
|
2013-10-16 16:09:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int gprs_rlcmac_tbf::rlcmac_diag()
|
|
|
|
{
|
|
|
|
if ((state_flags & (1 << GPRS_RLCMAC_FLAG_CCCH)))
|
|
|
|
LOGP(DRLCMAC, LOGL_NOTICE, "- Assignment was on CCCH\n");
|
|
|
|
if ((state_flags & (1 << GPRS_RLCMAC_FLAG_PACCH)))
|
|
|
|
LOGP(DRLCMAC, LOGL_NOTICE, "- Assignment was on PACCH\n");
|
|
|
|
if ((state_flags & (1 << GPRS_RLCMAC_FLAG_UL_DATA)))
|
|
|
|
LOGP(DRLCMAC, LOGL_NOTICE, "- Uplink data was received\n");
|
|
|
|
else if (direction == GPRS_RLCMAC_UL_TBF)
|
|
|
|
LOGP(DRLCMAC, LOGL_NOTICE, "- No uplink data received yet\n");
|
|
|
|
if ((state_flags & (1 << GPRS_RLCMAC_FLAG_DL_ACK)))
|
|
|
|
LOGP(DRLCMAC, LOGL_NOTICE, "- Downlink ACK was received\n");
|
|
|
|
else if (direction == GPRS_RLCMAC_DL_TBF)
|
|
|
|
LOGP(DRLCMAC, LOGL_NOTICE, "- No downlink ACK received yet\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-10-26 18:45:35 +00:00
|
|
|
struct msgb *gprs_rlcmac_tbf::create_dl_ass(uint32_t fn)
|
|
|
|
{
|
|
|
|
struct msgb *msg;
|
2014-08-07 12:48:20 +00:00
|
|
|
struct gprs_rlcmac_dl_tbf *new_dl_tbf;
|
2013-11-24 21:52:10 +00:00
|
|
|
int poll_ass_dl = 1;
|
2013-10-26 18:45:35 +00:00
|
|
|
|
2013-11-24 21:52:10 +00:00
|
|
|
if (direction == GPRS_RLCMAC_DL_TBF && control_ts != first_common_ts) {
|
2013-10-26 18:45:35 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_NOTICE, "Cannot poll for downlink "
|
|
|
|
"assigment, because MS cannot reply. (control TS=%d, "
|
|
|
|
"first common TS=%d)\n", control_ts,
|
|
|
|
first_common_ts);
|
|
|
|
poll_ass_dl = 0;
|
|
|
|
}
|
|
|
|
if (poll_ass_dl) {
|
|
|
|
if (poll_state != GPRS_RLCMAC_POLL_NONE) {
|
|
|
|
LOGP(DRLCMAC, LOGL_DEBUG, "Polling is already sheduled "
|
2013-10-27 19:31:47 +00:00
|
|
|
"for %s, so we must wait for downlink "
|
|
|
|
"assignment...\n", tbf_name(this));
|
2013-10-26 18:45:35 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2013-10-27 12:44:37 +00:00
|
|
|
if (bts->sba()->find(trx->trx_no, control_ts, (fn + 13) % 2715648)) {
|
2013-10-26 18:45:35 +00:00
|
|
|
LOGP(DRLCMACUL, LOGL_DEBUG, "Polling is already "
|
|
|
|
"scheduled for single block allocation...\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* on uplink TBF we get the downlink TBF to be assigned. */
|
|
|
|
if (direction == GPRS_RLCMAC_UL_TBF) {
|
2014-08-07 12:48:20 +00:00
|
|
|
gprs_rlcmac_ul_tbf *ul_tbf = static_cast<gprs_rlcmac_ul_tbf *>(this);
|
|
|
|
|
2013-10-26 18:45:35 +00:00
|
|
|
/* be sure to check first, if contention resolution is done,
|
|
|
|
* otherwise we cannot send the assignment yet */
|
2014-08-07 13:49:21 +00:00
|
|
|
if (!ul_tbf->m_contention_resolution_done) {
|
2013-10-26 18:45:35 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_DEBUG, "Cannot assign DL TBF now, "
|
|
|
|
"because contention resolution is not "
|
|
|
|
"finished.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#warning "THIS should probably go over the IMSI too"
|
2014-08-07 12:48:20 +00:00
|
|
|
new_dl_tbf = ul_tbf->bts->dl_tbf_by_tlli(m_tlli);
|
2013-10-26 18:45:35 +00:00
|
|
|
} else
|
2014-08-07 12:48:20 +00:00
|
|
|
new_dl_tbf = static_cast<gprs_rlcmac_dl_tbf *>(this);
|
|
|
|
if (!new_dl_tbf) {
|
2013-10-26 18:45:35 +00:00
|
|
|
LOGP(DRLCMACDL, LOGL_ERROR, "We have a schedule for downlink "
|
2013-10-27 19:31:47 +00:00
|
|
|
"assignment at uplink %s, but there is no downlink "
|
|
|
|
"TBF\n", tbf_name(this));
|
2013-10-26 18:45:35 +00:00
|
|
|
dl_ass_state = GPRS_RLCMAC_DL_ASS_NONE;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
msg = msgb_alloc(23, "rlcmac_dl_ass");
|
|
|
|
if (!msg)
|
|
|
|
return NULL;
|
|
|
|
bitvec *ass_vec = bitvec_alloc(23);
|
|
|
|
if (!ass_vec) {
|
|
|
|
msgb_free(msg);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
bitvec_unhex(ass_vec,
|
|
|
|
"2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b");
|
2014-08-07 12:48:20 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_INFO, "%s start Packet Downlink Assignment (PACCH)\n", tbf_name(new_dl_tbf));
|
2013-10-26 18:45:35 +00:00
|
|
|
RlcMacDownlink_t * mac_control_block = (RlcMacDownlink_t *)talloc_zero(tall_pcu_ctx, RlcMacDownlink_t);
|
2013-10-27 19:31:47 +00:00
|
|
|
Encoding::write_packet_downlink_assignment(mac_control_block, m_tfi,
|
2014-08-07 12:48:20 +00:00
|
|
|
(direction == GPRS_RLCMAC_DL_TBF), new_dl_tbf,
|
2013-10-26 18:45:35 +00:00
|
|
|
poll_ass_dl, bts_data()->alpha, bts_data()->gamma, -1, 0);
|
|
|
|
LOGP(DRLCMAC, LOGL_DEBUG, "+++++++++++++++++++++++++ TX : Packet Downlink Assignment +++++++++++++++++++++++++\n");
|
|
|
|
encode_gsm_rlcmac_downlink(ass_vec, mac_control_block);
|
|
|
|
LOGPC(DCSN1, LOGL_NOTICE, "\n");
|
|
|
|
LOGP(DRLCMAC, LOGL_DEBUG, "------------------------- TX : Packet Downlink Assignment -------------------------\n");
|
|
|
|
bitvec_pack(ass_vec, msgb_put(msg, 23));
|
|
|
|
bitvec_free(ass_vec);
|
|
|
|
talloc_free(mac_control_block);
|
|
|
|
|
|
|
|
if (poll_ass_dl) {
|
|
|
|
poll_state = GPRS_RLCMAC_POLL_SCHED;
|
|
|
|
poll_fn = (fn + 13) % 2715648;
|
|
|
|
dl_ass_state = GPRS_RLCMAC_DL_ASS_WAIT_ACK;
|
|
|
|
} else {
|
|
|
|
dl_ass_state = GPRS_RLCMAC_DL_ASS_NONE;
|
2014-08-08 09:43:53 +00:00
|
|
|
new_dl_tbf->set_state(GPRS_RLCMAC_FLOW);
|
2014-08-07 12:48:20 +00:00
|
|
|
tbf_assign_control_ts(new_dl_tbf);
|
2013-10-26 18:45:35 +00:00
|
|
|
/* stop pending assignment timer */
|
2014-08-07 12:48:20 +00:00
|
|
|
new_dl_tbf->stop_timer();
|
2013-10-26 18:45:35 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
2013-10-26 19:20:51 +00:00
|
|
|
struct msgb *gprs_rlcmac_tbf::create_ul_ass(uint32_t fn)
|
|
|
|
{
|
|
|
|
struct msgb *msg;
|
2014-08-07 12:54:11 +00:00
|
|
|
struct gprs_rlcmac_ul_tbf *new_tbf;
|
2013-10-26 19:20:51 +00:00
|
|
|
|
|
|
|
if (poll_state != GPRS_RLCMAC_POLL_NONE) {
|
|
|
|
LOGP(DRLCMACUL, LOGL_DEBUG, "Polling is already "
|
2013-10-27 19:31:47 +00:00
|
|
|
"sheduled for %s, so we must wait for uplink "
|
|
|
|
"assignment...\n", tbf_name(this));
|
2013-10-26 19:20:51 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2013-10-27 12:44:37 +00:00
|
|
|
if (bts->sba()->find(trx->trx_no, control_ts, (fn + 13) % 2715648)) {
|
2013-10-26 19:20:51 +00:00
|
|
|
LOGP(DRLCMACUL, LOGL_DEBUG, "Polling is already scheduled for "
|
|
|
|
"single block allocation...\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* on down TBF we get the uplink TBF to be assigned. */
|
|
|
|
#warning "Probably want to find by IMSI too"
|
|
|
|
if (direction == GPRS_RLCMAC_DL_TBF)
|
2014-07-02 15:58:14 +00:00
|
|
|
new_tbf = bts->ul_tbf_by_tlli(m_tlli);
|
2013-10-26 19:20:51 +00:00
|
|
|
else
|
2014-08-07 12:54:11 +00:00
|
|
|
new_tbf = static_cast<gprs_rlcmac_ul_tbf *>(this);
|
2013-10-26 19:20:51 +00:00
|
|
|
|
|
|
|
if (!new_tbf) {
|
|
|
|
LOGP(DRLCMACUL, LOGL_ERROR, "We have a schedule for uplink "
|
2013-10-27 19:31:47 +00:00
|
|
|
"assignment at downlink %s, but there is no uplink "
|
|
|
|
"TBF\n", tbf_name(this));
|
2013-10-26 19:20:51 +00:00
|
|
|
ul_ass_state = GPRS_RLCMAC_UL_ASS_NONE;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
msg = msgb_alloc(23, "rlcmac_ul_ass");
|
|
|
|
if (!msg)
|
|
|
|
return NULL;
|
2013-10-27 16:01:14 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_INFO, "%ss start Packet Uplink Assignment (PACCH)\n", tbf_name(new_tbf));
|
2013-10-26 19:20:51 +00:00
|
|
|
bitvec *ass_vec = bitvec_alloc(23);
|
|
|
|
if (!ass_vec) {
|
|
|
|
msgb_free(msg);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
bitvec_unhex(ass_vec,
|
|
|
|
"2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b");
|
2013-10-27 19:31:47 +00:00
|
|
|
Encoding::write_packet_uplink_assignment(bts_data(), ass_vec, m_tfi,
|
2013-10-27 16:01:14 +00:00
|
|
|
(direction == GPRS_RLCMAC_DL_TBF), m_tlli,
|
2013-11-24 21:52:10 +00:00
|
|
|
m_tlli_valid, new_tbf, 1, bts_data()->alpha,
|
2013-10-26 19:20:51 +00:00
|
|
|
bts_data()->gamma, -1);
|
|
|
|
bitvec_pack(ass_vec, msgb_put(msg, 23));
|
|
|
|
RlcMacDownlink_t * mac_control_block = (RlcMacDownlink_t *)talloc_zero(tall_pcu_ctx, RlcMacDownlink_t);
|
|
|
|
LOGP(DRLCMAC, LOGL_DEBUG, "+++++++++++++++++++++++++ TX : Packet Uplink Assignment +++++++++++++++++++++++++\n");
|
|
|
|
decode_gsm_rlcmac_downlink(ass_vec, mac_control_block);
|
|
|
|
LOGPC(DCSN1, LOGL_NOTICE, "\n");
|
|
|
|
LOGP(DRLCMAC, LOGL_DEBUG, "------------------------- TX : Packet Uplink Assignment -------------------------\n");
|
|
|
|
bitvec_free(ass_vec);
|
|
|
|
talloc_free(mac_control_block);
|
|
|
|
|
|
|
|
poll_state = GPRS_RLCMAC_POLL_SCHED;
|
|
|
|
poll_fn = (fn + 13) % 2715648;
|
|
|
|
ul_ass_state = GPRS_RLCMAC_UL_ASS_WAIT_ACK;
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
2013-10-16 15:53:23 +00:00
|
|
|
void gprs_rlcmac_tbf::free_all(struct gprs_rlcmac_trx *trx)
|
|
|
|
{
|
|
|
|
for (uint8_t tfi = 0; tfi < 32; tfi++) {
|
|
|
|
struct gprs_rlcmac_tbf *tbf;
|
|
|
|
|
|
|
|
tbf = trx->ul_tbf[tfi];
|
|
|
|
if (tbf)
|
|
|
|
tbf_free(tbf);
|
|
|
|
tbf = trx->dl_tbf[tfi];
|
|
|
|
if (tbf)
|
|
|
|
tbf_free(tbf);
|
|
|
|
}
|
|
|
|
}
|
2013-10-16 15:58:46 +00:00
|
|
|
|
|
|
|
void gprs_rlcmac_tbf::free_all(struct gprs_rlcmac_pdch *pdch)
|
|
|
|
{
|
|
|
|
for (uint8_t tfi = 0; tfi < 32; tfi++) {
|
|
|
|
struct gprs_rlcmac_tbf *tbf;
|
|
|
|
|
2014-05-30 18:21:30 +00:00
|
|
|
tbf = pdch->ul_tbf_by_tfi(tfi);
|
2013-10-16 15:58:46 +00:00
|
|
|
if (tbf)
|
|
|
|
tbf_free(tbf);
|
2014-05-30 18:21:30 +00:00
|
|
|
tbf = pdch->dl_tbf_by_tfi(tfi);
|
2013-10-16 15:58:46 +00:00
|
|
|
if (tbf)
|
|
|
|
tbf_free(tbf);
|
|
|
|
}
|
|
|
|
}
|
2013-10-27 15:39:36 +00:00
|
|
|
|
2013-10-27 16:01:14 +00:00
|
|
|
void gprs_rlcmac_tbf::tlli_mark_valid()
|
|
|
|
{
|
|
|
|
m_tlli_valid = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gprs_rlcmac_tbf::update_tlli(uint32_t tlli)
|
|
|
|
{
|
|
|
|
if (tlli == m_tlli)
|
|
|
|
return;
|
|
|
|
|
2013-10-30 13:50:17 +00:00
|
|
|
bool changedUl = false;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* During a Routing Area Update (due the assignment of a new
|
|
|
|
* P-TMSI) the tlli can change. We notice this when receiving
|
|
|
|
* a PACKET CONTROL ACK.
|
|
|
|
* When we get a TLLI change on the DL we will look if there
|
|
|
|
* is a UL TBF and change the tlli there as well.
|
|
|
|
*
|
|
|
|
* TODO: There could be multiple DL and UL TBFs and we should
|
|
|
|
* have a proper way to link all the related TBFs so we can do
|
|
|
|
* a group update.
|
|
|
|
*/
|
|
|
|
if (m_tlli_valid && direction == GPRS_RLCMAC_DL_TBF) {
|
|
|
|
gprs_rlcmac_tbf *ul_tbf;
|
2014-07-02 15:58:14 +00:00
|
|
|
ul_tbf = bts->ul_tbf_by_tlli(m_tlli);
|
2013-10-30 13:50:17 +00:00
|
|
|
|
|
|
|
if (ul_tbf) {
|
|
|
|
ul_tbf->m_tlli = tlli;
|
|
|
|
changedUl = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-30 18:50:49 +00:00
|
|
|
/* update the timing advance for the new tlli */
|
|
|
|
bts->timing_advance()->update(m_tlli, tlli, ta);
|
|
|
|
|
2013-10-30 13:50:17 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_NOTICE,
|
|
|
|
"%s changing tlli from TLLI=0x%08x TLLI=0x%08x ul_changed=%d\n",
|
|
|
|
tbf_name(this), m_tlli, tlli, changedUl);
|
2013-10-27 16:01:14 +00:00
|
|
|
m_tlli = tlli;
|
|
|
|
}
|
|
|
|
|
2013-11-25 22:05:26 +00:00
|
|
|
int gprs_rlcmac_tbf::extract_tlli(const uint8_t *data, const size_t len)
|
|
|
|
{
|
|
|
|
struct gprs_rlcmac_tbf *dl_tbf, *ul_tbf;
|
|
|
|
struct rlc_ul_header *rh = (struct rlc_ul_header *)data;
|
|
|
|
uint32_t new_tlli;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* no TLLI yet */
|
|
|
|
if (!rh->ti) {
|
|
|
|
LOGP(DRLCMACUL, LOGL_NOTICE, "UL DATA TFI=%d without "
|
|
|
|
"TLLI, but no TLLI received yet\n", rh->tfi);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
rc = Decoding::tlli_from_ul_data(data, len, &new_tlli);
|
|
|
|
if (rc) {
|
|
|
|
bts->decode_error();
|
|
|
|
LOGP(DRLCMACUL, LOGL_NOTICE, "Failed to decode TLLI "
|
|
|
|
"of UL DATA TFI=%d.\n", rh->tfi);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
update_tlli(new_tlli);
|
|
|
|
LOGP(DRLCMACUL, LOGL_INFO, "Decoded premier TLLI=0x%08x of "
|
|
|
|
"UL DATA TFI=%d.\n", tlli(), rh->tfi);
|
2014-07-02 15:58:14 +00:00
|
|
|
if ((dl_tbf = bts->dl_tbf_by_tlli(tlli()))) {
|
2013-11-25 22:05:26 +00:00
|
|
|
LOGP(DRLCMACUL, LOGL_NOTICE, "Got RACH from "
|
|
|
|
"TLLI=0x%08x while %s still exists. "
|
|
|
|
"Killing pending DL TBF\n", tlli(),
|
|
|
|
tbf_name(dl_tbf));
|
|
|
|
tbf_free(dl_tbf);
|
2014-01-16 09:09:42 +00:00
|
|
|
dl_tbf = NULL;
|
2013-11-25 22:05:26 +00:00
|
|
|
}
|
2014-07-02 15:58:14 +00:00
|
|
|
/* ul_tbf_by_tlli will not find your TLLI, because it is not
|
2013-11-25 22:05:26 +00:00
|
|
|
* yet marked valid */
|
2014-07-02 15:58:14 +00:00
|
|
|
if ((ul_tbf = bts->ul_tbf_by_tlli(tlli()))) {
|
2013-11-25 22:05:26 +00:00
|
|
|
LOGP(DRLCMACUL, LOGL_NOTICE, "Got RACH from "
|
|
|
|
"TLLI=0x%08x while %s still exists. "
|
|
|
|
"Killing pending UL TBF\n", tlli(),
|
|
|
|
tbf_name(ul_tbf));
|
|
|
|
tbf_free(ul_tbf);
|
2014-01-16 09:09:42 +00:00
|
|
|
ul_tbf = NULL;
|
2013-11-25 22:05:26 +00:00
|
|
|
}
|
|
|
|
/* mark TLLI valid now */
|
|
|
|
tlli_mark_valid();
|
|
|
|
/* store current timing advance */
|
|
|
|
bts->timing_advance()->remember(tlli(), ta);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-10-27 15:39:36 +00:00
|
|
|
const char *tbf_name(gprs_rlcmac_tbf *tbf)
|
|
|
|
{
|
|
|
|
static char buf[40];
|
|
|
|
snprintf(buf, sizeof(buf), "TBF(TFI=%d TLLI=0x%08x DIR=%s)",
|
2013-10-27 19:31:47 +00:00
|
|
|
tbf->m_tfi, tbf->m_tlli,
|
2013-10-27 15:39:36 +00:00
|
|
|
tbf->direction == GPRS_RLCMAC_UL_TBF ? "UL" : "DL");
|
|
|
|
buf[sizeof(buf) - 1] = '\0';
|
|
|
|
return buf;
|
|
|
|
}
|
2013-11-06 19:39:45 +00:00
|
|
|
|
2013-11-26 12:08:12 +00:00
|
|
|
void gprs_rlcmac_tbf::rotate_in_list()
|
|
|
|
{
|
2014-07-30 11:25:19 +00:00
|
|
|
llist_del(&list.list);
|
2013-11-26 12:08:12 +00:00
|
|
|
if (direction == GPRS_RLCMAC_UL_TBF)
|
2014-07-30 11:25:19 +00:00
|
|
|
llist_add(&list.list, &bts->bts_data()->ul_tbfs);
|
2013-11-26 12:08:12 +00:00
|
|
|
else
|
2014-07-30 11:25:19 +00:00
|
|
|
llist_add(&list.list, &bts->bts_data()->dl_tbfs);
|
2013-11-26 12:08:12 +00:00
|
|
|
}
|
2013-12-25 19:22:35 +00:00
|
|
|
|
|
|
|
uint8_t gprs_rlcmac_tbf::tsc() const
|
|
|
|
{
|
|
|
|
return trx->pdch[first_ts].tsc;
|
|
|
|
}
|
2014-01-15 16:06:19 +00:00
|
|
|
|
|
|
|
void tbf_print_vty_info(struct vty *vty, llist_head *ltbf)
|
|
|
|
{
|
2014-07-30 11:25:19 +00:00
|
|
|
gprs_rlcmac_tbf *tbf = llist_pods_entry(ltbf, gprs_rlcmac_tbf);
|
2014-01-15 16:06:19 +00:00
|
|
|
|
2014-01-15 16:06:51 +00:00
|
|
|
vty_out(vty, "TBF: TFI=%d TLLI=0x%08x (%s) DIR=%s IMSI=%s%s", tbf->tfi(),
|
2014-01-15 16:06:19 +00:00
|
|
|
tbf->tlli(), tbf->is_tlli_valid() ? "valid" : "invalid",
|
|
|
|
tbf->direction == GPRS_RLCMAC_UL_TBF ? "UL" : "DL",
|
|
|
|
tbf->imsi(), VTY_NEWLINE);
|
2014-01-15 16:40:28 +00:00
|
|
|
vty_out(vty, " created=%lu state=%08x 1st_TS=%d 1st_cTS=%d ctrl_TS=%d "
|
2014-01-15 16:06:19 +00:00
|
|
|
"MS_CLASS=%d%s",
|
2014-01-16 09:07:20 +00:00
|
|
|
tbf->created_ts(), tbf->state_flags, tbf->first_ts,
|
2014-01-15 16:40:28 +00:00
|
|
|
tbf->first_common_ts, tbf->control_ts, tbf->ms_class,
|
|
|
|
VTY_NEWLINE);
|
2014-01-15 16:06:19 +00:00
|
|
|
vty_out(vty, " TS_alloc=");
|
|
|
|
for (int i = 0; i < 8; i++) {
|
|
|
|
if (tbf->pdch[i])
|
|
|
|
vty_out(vty, "%d ", i);
|
|
|
|
}
|
2014-01-15 16:06:51 +00:00
|
|
|
vty_out(vty, " CS=%d%s%s", tbf->cs, VTY_NEWLINE, VTY_NEWLINE);
|
2014-01-15 16:06:19 +00:00
|
|
|
}
|