2012-03-05 15:24:57 +00:00
|
|
|
/* gprs_rlcmac.cpp
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Ivan Klyuchnikov
|
2012-06-27 13:52:04 +00:00
|
|
|
* Copyright (C) 2012 Andreas Eversberg <jolly@eversberg.eu>
|
2012-03-05 15:24:57 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gprs_bssgp_pcu.h>
|
|
|
|
#include <pcu_l1_if.h>
|
|
|
|
#include <gprs_rlcmac.h>
|
|
|
|
|
2012-07-13 12:46:03 +00:00
|
|
|
LLIST_HEAD(gprs_rlcmac_ul_tbfs);
|
|
|
|
LLIST_HEAD(gprs_rlcmac_dl_tbfs);
|
2012-03-05 15:24:57 +00:00
|
|
|
void *rlcmac_tall_ctx;
|
|
|
|
|
2012-07-13 12:46:03 +00:00
|
|
|
/* FIXME: spread ressources over multiple TRX. Also add option to use same
|
|
|
|
* TRX in case of existing TBF for TLLI in the other direction. */
|
|
|
|
/* search for free TFI and return TFI, TRX and first TS */
|
|
|
|
int tfi_alloc(enum gprs_rlcmac_tbf_direction dir, uint8_t *_trx, uint8_t *_ts,
|
|
|
|
uint8_t use_trx, uint8_t first_ts)
|
2012-03-05 15:24:57 +00:00
|
|
|
{
|
2012-06-27 13:52:04 +00:00
|
|
|
struct gprs_rlcmac_bts *bts = gprs_rlcmac_bts;
|
|
|
|
struct gprs_rlcmac_pdch *pdch;
|
2012-07-13 12:46:03 +00:00
|
|
|
struct gprs_rlcmac_tbf **tbfp;
|
|
|
|
uint8_t trx_from, trx_to, trx, ts, tfi;
|
|
|
|
|
|
|
|
if (use_trx >= 0 && use_trx < 8)
|
|
|
|
trx_from = trx_to = use_trx;
|
|
|
|
else {
|
|
|
|
trx_from = 0;
|
|
|
|
trx_to = 7;
|
|
|
|
}
|
|
|
|
if (first_ts < 0 || first_ts >= 8)
|
|
|
|
first_ts = 0;
|
2012-03-05 15:24:57 +00:00
|
|
|
|
2012-07-13 12:46:03 +00:00
|
|
|
/* on TRX find first enabled TS */
|
|
|
|
for (trx = trx_from; trx <= trx_to; trx++) {
|
|
|
|
for (ts = first_ts; ts < 8; ts++) {
|
2012-06-27 13:52:04 +00:00
|
|
|
pdch = &bts->trx[trx].pdch[ts];
|
|
|
|
if (!pdch->enable)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ts < 8)
|
|
|
|
break;
|
|
|
|
}
|
2012-07-13 12:46:03 +00:00
|
|
|
if (trx > trx_to) {
|
2012-06-27 13:52:04 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_NOTICE, "No PDCH available.\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LOGP(DRLCMAC, LOGL_DEBUG, "Searching for first unallocated TFI: "
|
2012-07-13 12:46:03 +00:00
|
|
|
"TRX=%d first TS=%d\n", trx, ts);
|
|
|
|
if (dir == GPRS_RLCMAC_UL_TBF)
|
|
|
|
tbfp = pdch->ul_tbf;
|
|
|
|
else
|
|
|
|
tbfp = pdch->dl_tbf;
|
2012-06-27 13:52:04 +00:00
|
|
|
for (tfi = 0; tfi < 32; tfi++) {
|
2012-07-13 12:46:03 +00:00
|
|
|
if (!tbfp[tfi])
|
2012-06-27 13:52:04 +00:00
|
|
|
break;
|
2012-03-05 15:24:57 +00:00
|
|
|
}
|
|
|
|
|
2012-06-27 13:52:04 +00:00
|
|
|
if (tfi < 32) {
|
|
|
|
LOGP(DRLCMAC, LOGL_DEBUG, " Found TFI=%d.\n", tfi);
|
|
|
|
*_trx = trx;
|
|
|
|
*_ts = ts;
|
|
|
|
return tfi;
|
|
|
|
}
|
|
|
|
LOGP(DRLCMAC, LOGL_NOTICE, "No TFI available.\n");
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-07-13 12:46:03 +00:00
|
|
|
static inline int8_t find_free_usf(struct gprs_rlcmac_pdch *pdch, uint8_t ts)
|
2012-06-27 13:52:04 +00:00
|
|
|
{
|
|
|
|
struct gprs_rlcmac_tbf *tbf;
|
|
|
|
uint8_t usf_map = 0;
|
|
|
|
uint8_t tfi, usf;
|
|
|
|
|
|
|
|
/* make map of used USF */
|
|
|
|
for (tfi = 0; tfi < 32; tfi++) {
|
2012-07-13 12:46:03 +00:00
|
|
|
tbf = pdch->ul_tbf[tfi];
|
2012-06-27 13:52:04 +00:00
|
|
|
if (!tbf)
|
|
|
|
continue;
|
2012-07-13 12:46:03 +00:00
|
|
|
usf_map |= (1 << tbf->dir.ul.usf[ts]);
|
2012-06-27 13:52:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* look for USF, don't use USF=7 */
|
|
|
|
for (usf = 0; usf < 7; usf++) {
|
2012-07-13 12:46:03 +00:00
|
|
|
if (!(usf_map & (1 << usf)))
|
2012-06-27 13:52:04 +00:00
|
|
|
return usf;
|
2012-03-05 15:24:57 +00:00
|
|
|
}
|
2012-06-27 13:52:04 +00:00
|
|
|
|
2012-03-05 15:24:57 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* lookup TBF Entity (by TFI) */
|
2012-07-13 12:46:03 +00:00
|
|
|
struct gprs_rlcmac_tbf *tbf_by_tfi(uint8_t tfi, uint8_t trx, uint8_t ts,
|
|
|
|
enum gprs_rlcmac_tbf_direction dir)
|
2012-03-05 15:24:57 +00:00
|
|
|
{
|
|
|
|
struct gprs_rlcmac_tbf *tbf;
|
2012-07-13 12:46:03 +00:00
|
|
|
struct gprs_rlcmac_bts *bts = gprs_rlcmac_bts;
|
|
|
|
|
|
|
|
if (tfi >= 32 || trx >= 8 || ts >= 8)
|
|
|
|
return NULL;
|
2012-03-05 15:24:57 +00:00
|
|
|
|
2012-07-13 12:46:03 +00:00
|
|
|
if (dir == GPRS_RLCMAC_UL_TBF)
|
|
|
|
tbf = bts->trx[trx].pdch[ts].ul_tbf[tfi];
|
|
|
|
else
|
|
|
|
tbf = bts->trx[trx].pdch[ts].dl_tbf[tfi];
|
|
|
|
if (!tbf)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (tbf->state != GPRS_RLCMAC_RELEASING)
|
2012-03-05 15:24:57 +00:00
|
|
|
return tbf;
|
2012-07-13 12:46:03 +00:00
|
|
|
|
2012-03-05 15:24:57 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-07-03 11:36:03 +00:00
|
|
|
/* search for active downlink or uplink tbf */
|
2012-07-13 12:46:03 +00:00
|
|
|
struct gprs_rlcmac_tbf *tbf_by_tlli(uint32_t tlli,
|
|
|
|
enum gprs_rlcmac_tbf_direction dir)
|
2012-03-05 15:24:57 +00:00
|
|
|
{
|
|
|
|
struct gprs_rlcmac_tbf *tbf;
|
2012-07-13 12:46:03 +00:00
|
|
|
if (dir == GPRS_RLCMAC_UL_TBF) {
|
|
|
|
llist_for_each_entry(tbf, &gprs_rlcmac_ul_tbfs, list) {
|
|
|
|
if (tbf->state != GPRS_RLCMAC_RELEASING
|
|
|
|
&& tbf->tlli == tlli)
|
|
|
|
return tbf;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
llist_for_each_entry(tbf, &gprs_rlcmac_dl_tbfs, list) {
|
|
|
|
if (tbf->state != GPRS_RLCMAC_RELEASING
|
|
|
|
&& tbf->tlli == tlli)
|
|
|
|
return tbf;
|
|
|
|
}
|
2012-03-05 15:24:57 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-07-13 12:46:03 +00:00
|
|
|
struct gprs_rlcmac_tbf *tbf_by_poll_fn(uint32_t fn, uint8_t trx, uint8_t ts)
|
2012-06-17 04:30:06 +00:00
|
|
|
{
|
2012-03-05 15:24:57 +00:00
|
|
|
struct gprs_rlcmac_tbf *tbf;
|
2012-07-13 12:46:03 +00:00
|
|
|
|
|
|
|
/* only one TBF can poll on specific TS/FN, because scheduler can only
|
|
|
|
* schedule one downlink control block (with polling) at a FN per TS */
|
2012-07-15 04:25:37 +00:00
|
|
|
llist_for_each_entry(tbf, &gprs_rlcmac_ul_tbfs, list) {
|
|
|
|
if (tbf->state != GPRS_RLCMAC_RELEASING
|
2012-07-13 12:46:03 +00:00
|
|
|
&& tbf->poll_state == GPRS_RLCMAC_POLL_SCHED
|
2012-07-15 04:25:37 +00:00
|
|
|
&& tbf->poll_fn == fn && tbf->trx == trx
|
|
|
|
&& tbf->control_ts == ts)
|
2012-07-13 12:46:03 +00:00
|
|
|
return tbf;
|
2012-07-15 04:25:37 +00:00
|
|
|
}
|
|
|
|
llist_for_each_entry(tbf, &gprs_rlcmac_dl_tbfs, list) {
|
|
|
|
if (tbf->state != GPRS_RLCMAC_RELEASING
|
2012-07-03 11:36:03 +00:00
|
|
|
&& tbf->poll_state == GPRS_RLCMAC_POLL_SCHED
|
2012-07-15 04:25:37 +00:00
|
|
|
&& tbf->poll_fn == fn && tbf->trx == trx
|
|
|
|
&& tbf->control_ts == ts)
|
2012-06-17 04:30:06 +00:00
|
|
|
return tbf;
|
|
|
|
}
|
2012-03-05 15:24:57 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-07-15 04:25:37 +00:00
|
|
|
struct gprs_rlcmac_tbf *tbf_alloc(struct gprs_rlcmac_tbf *old_tbf,
|
|
|
|
enum gprs_rlcmac_tbf_direction dir, uint8_t tfi, uint8_t trx,
|
|
|
|
uint8_t first_ts, uint8_t ms_class, uint8_t single_slot)
|
2012-03-05 15:24:57 +00:00
|
|
|
{
|
2012-06-27 13:52:04 +00:00
|
|
|
struct gprs_rlcmac_bts *bts = gprs_rlcmac_bts;
|
2012-03-05 15:24:57 +00:00
|
|
|
struct gprs_rlcmac_tbf *tbf;
|
2012-07-13 12:50:57 +00:00
|
|
|
int rc;
|
2012-06-17 04:30:06 +00:00
|
|
|
|
2012-07-06 09:04:57 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_DEBUG, "********** TBF starts here **********\n");
|
2012-07-13 12:50:57 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_INFO, "Allocating %s TBF: TFI=%d TRX=%d "
|
|
|
|
"MS_CLASS=%d\n", (dir == GPRS_RLCMAC_UL_TBF) ? "UL" : "DL",
|
|
|
|
tfi, trx, ms_class);
|
2012-06-17 04:30:06 +00:00
|
|
|
|
2012-07-13 12:46:03 +00:00
|
|
|
if (trx >= 8 || first_ts >= 8 || tfi >= 32)
|
2012-06-27 13:52:04 +00:00
|
|
|
return NULL;
|
2012-06-17 04:30:06 +00:00
|
|
|
|
2012-03-05 15:24:57 +00:00
|
|
|
tbf = talloc_zero(rlcmac_tall_ctx, struct gprs_rlcmac_tbf);
|
|
|
|
if (!tbf)
|
|
|
|
return NULL;
|
2012-06-17 04:30:06 +00:00
|
|
|
|
2012-07-13 12:46:03 +00:00
|
|
|
tbf->direction = dir;
|
2012-03-05 15:24:57 +00:00
|
|
|
tbf->tfi = tfi;
|
2012-06-23 08:33:16 +00:00
|
|
|
tbf->trx = trx;
|
2012-06-27 13:52:04 +00:00
|
|
|
tbf->arfcn = bts->trx[trx].arfcn;
|
2012-07-13 12:50:57 +00:00
|
|
|
tbf->first_ts = first_ts;
|
|
|
|
tbf->ms_class = ms_class;
|
|
|
|
tbf->ws = 64;
|
|
|
|
tbf->sns = 128;
|
2012-07-15 04:25:37 +00:00
|
|
|
/* select algorithm A in case we don't have multislot class info */
|
|
|
|
if (single_slot || ms_class == 0)
|
|
|
|
rc = alloc_algorithm_a(old_tbf, tbf,
|
|
|
|
bts->alloc_algorithm_curst);
|
2012-07-13 12:50:57 +00:00
|
|
|
else
|
2012-07-15 04:25:37 +00:00
|
|
|
rc = bts->alloc_algorithm(old_tbf, tbf,
|
|
|
|
bts->alloc_algorithm_curst);
|
|
|
|
/* if no ressource */
|
|
|
|
if (rc < 0) {
|
|
|
|
talloc_free(tbf);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/* assign control ts */
|
|
|
|
tbf->control_ts = 0xff;
|
|
|
|
rc = tbf_assign_control_ts(tbf);
|
2012-07-13 12:50:57 +00:00
|
|
|
/* if no ressource */
|
|
|
|
if (rc < 0) {
|
|
|
|
talloc_free(tbf);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
INIT_LLIST_HEAD(&tbf->llc_queue);
|
|
|
|
if (dir == GPRS_RLCMAC_UL_TBF)
|
|
|
|
llist_add(&tbf->list, &gprs_rlcmac_ul_tbfs);
|
|
|
|
else
|
|
|
|
llist_add(&tbf->list, &gprs_rlcmac_dl_tbfs);
|
|
|
|
|
|
|
|
return tbf;
|
|
|
|
}
|
|
|
|
|
2012-07-15 04:25:37 +00:00
|
|
|
/* Slot Allocation: Algorithm A
|
|
|
|
*
|
|
|
|
* Assign single slot for uplink and downlink
|
|
|
|
*/
|
|
|
|
int alloc_algorithm_a(struct gprs_rlcmac_tbf *old_tbf,
|
|
|
|
struct gprs_rlcmac_tbf *tbf, uint32_t cust)
|
2012-07-13 12:50:57 +00:00
|
|
|
{
|
|
|
|
struct gprs_rlcmac_bts *bts = gprs_rlcmac_bts;
|
|
|
|
struct gprs_rlcmac_pdch *pdch;
|
|
|
|
uint8_t ts = tbf->first_ts;
|
|
|
|
int8_t usf; /* must be signed */
|
|
|
|
|
2012-07-15 04:25:37 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_DEBUG, "Slot Allocation (Algorithm A) for class "
|
|
|
|
"%d\n", tbf->ms_class);
|
|
|
|
|
2012-07-13 12:50:57 +00:00
|
|
|
pdch = &bts->trx[tbf->trx].pdch[ts];
|
|
|
|
if (!pdch->enable) {
|
|
|
|
LOGP(DRLCMAC, LOGL_ERROR, "TS=%d not enabled.", ts);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
tbf->tsc = pdch->tsc;
|
|
|
|
if (tbf->direction == GPRS_RLCMAC_UL_TBF) {
|
|
|
|
/* if TFI is free on TS */
|
|
|
|
if (!pdch->ul_tbf[tbf->tfi]) {
|
|
|
|
/* if USF available */
|
|
|
|
usf = find_free_usf(pdch, ts);
|
|
|
|
if (usf >= 0) {
|
2012-07-15 04:25:37 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_DEBUG, "- Assign uplink "
|
2012-07-13 12:50:57 +00:00
|
|
|
"TS=%d USF=%d\n", ts, usf);
|
|
|
|
pdch->ul_tbf[tbf->tfi] = tbf;
|
2012-07-13 12:46:03 +00:00
|
|
|
tbf->pdch[ts] = pdch;
|
2012-07-13 12:50:57 +00:00
|
|
|
} else {
|
2012-07-15 04:25:37 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_NOTICE, "- Failed "
|
|
|
|
"allocating TS=%d, no USF available\n",
|
|
|
|
ts);
|
2012-07-13 12:50:57 +00:00
|
|
|
return -EBUSY;
|
2012-07-13 12:46:03 +00:00
|
|
|
}
|
2012-07-13 12:50:57 +00:00
|
|
|
} else {
|
2012-07-15 04:25:37 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_NOTICE, "- Failed allocating "
|
2012-07-13 12:50:57 +00:00
|
|
|
"TS=%d, TFI is not available\n", ts);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* if TFI is free on TS */
|
|
|
|
if (!pdch->dl_tbf[tbf->tfi]) {
|
2012-07-15 04:25:37 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_DEBUG, "- Assign downlink TS=%d\n",
|
2012-07-13 12:50:57 +00:00
|
|
|
ts);
|
|
|
|
pdch->dl_tbf[tbf->tfi] = tbf;
|
|
|
|
tbf->pdch[ts] = pdch;
|
|
|
|
} else {
|
2012-07-15 04:25:37 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_NOTICE, "- Failed allocating "
|
2012-07-13 12:50:57 +00:00
|
|
|
"TS=%d, TFI is not available\n", ts);
|
|
|
|
return -EBUSY;
|
2012-07-13 12:46:03 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-15 04:25:37 +00:00
|
|
|
/* the only one TS is the common TS */
|
|
|
|
tbf->first_common_ts = ts;
|
2012-07-13 12:46:03 +00:00
|
|
|
|
2012-07-13 12:50:57 +00:00
|
|
|
return 0;
|
2012-03-05 15:24:57 +00:00
|
|
|
}
|
|
|
|
|
2012-07-15 04:25:37 +00:00
|
|
|
static void tbf_unlink_pdch(struct gprs_rlcmac_tbf *tbf)
|
2012-06-17 04:30:06 +00:00
|
|
|
{
|
2012-06-27 13:52:04 +00:00
|
|
|
struct gprs_rlcmac_pdch *pdch;
|
2012-07-13 12:46:03 +00:00
|
|
|
int ts;
|
2012-06-17 04:30:06 +00:00
|
|
|
|
2012-07-15 04:25:37 +00:00
|
|
|
if (tbf->direction == GPRS_RLCMAC_UL_TBF) {
|
|
|
|
for (ts = 0; ts < 8; ts++) {
|
|
|
|
pdch = tbf->pdch[ts];
|
|
|
|
if (pdch)
|
|
|
|
pdch->ul_tbf[tbf->tfi] = NULL;
|
|
|
|
tbf->pdch[ts] = NULL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (ts = 0; ts < 8; ts++) {
|
|
|
|
pdch = tbf->pdch[ts];
|
|
|
|
if (pdch)
|
|
|
|
pdch->dl_tbf[tbf->tfi] = NULL;
|
|
|
|
tbf->pdch[ts] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tbf_free(struct gprs_rlcmac_tbf *tbf)
|
|
|
|
{
|
|
|
|
struct msgb *msg;
|
|
|
|
|
2012-07-13 12:46:03 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_INFO, "Free %s TBF=%d with TLLI=0x%08x.\n",
|
|
|
|
(tbf->direction == GPRS_RLCMAC_UL_TBF) ? "UL" : "DL", tbf->tfi,
|
2012-07-03 11:36:03 +00:00
|
|
|
tbf->tlli);
|
2012-07-13 12:46:03 +00:00
|
|
|
if (tbf->ul_ass_state != GPRS_RLCMAC_UL_ASS_NONE)
|
|
|
|
LOGP(DRLCMAC, LOGL_ERROR, "Software error: Pending uplink "
|
|
|
|
"assignment. This may not happen, because the "
|
|
|
|
"assignment message never gets transmitted. Please "
|
|
|
|
"be shure not to free in this state. PLEASE FIX!\n");
|
|
|
|
if (tbf->dl_ass_state != GPRS_RLCMAC_DL_ASS_NONE)
|
|
|
|
LOGP(DRLCMAC, LOGL_ERROR, "Software error: Pending downlink "
|
|
|
|
"assignment. This may not happen, because the "
|
|
|
|
"assignment message never gets transmitted. Please "
|
|
|
|
"be shure not to free in this state. PLEASE FIX!\n");
|
2012-06-27 13:52:04 +00:00
|
|
|
tbf_timer_stop(tbf);
|
2012-07-03 11:36:03 +00:00
|
|
|
while ((msg = msgb_dequeue(&tbf->llc_queue)))
|
|
|
|
msgb_free(msg);
|
2012-07-15 04:25:37 +00:00
|
|
|
tbf_unlink_pdch(tbf);
|
2012-03-05 15:24:57 +00:00
|
|
|
llist_del(&tbf->list);
|
2012-07-06 09:04:57 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_DEBUG, "********** TBF ends here **********\n");
|
2012-03-05 15:24:57 +00:00
|
|
|
talloc_free(tbf);
|
2012-06-17 04:30:06 +00:00
|
|
|
}
|
|
|
|
|
2012-07-15 04:25:37 +00:00
|
|
|
int tbf_update(struct gprs_rlcmac_tbf *tbf)
|
|
|
|
{
|
|
|
|
struct gprs_rlcmac_bts *bts = gprs_rlcmac_bts;
|
|
|
|
struct gprs_rlcmac_tbf *ul_tbf = NULL;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
LOGP(DRLCMAC, LOGL_DEBUG, "********** TBF update **********\n");
|
|
|
|
|
|
|
|
if (tbf->direction != GPRS_RLCMAC_DL_TBF)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (!tbf->ms_class) {
|
|
|
|
LOGP(DRLCMAC, LOGL_DEBUG, "- Cannot update, no class\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tbf->tlli_valid)
|
|
|
|
ul_tbf = tbf_by_tlli(tbf->tlli, GPRS_RLCMAC_UL_TBF);
|
|
|
|
|
|
|
|
tbf_unlink_pdch(tbf);
|
|
|
|
rc = bts->alloc_algorithm(ul_tbf, tbf, bts->alloc_algorithm_curst);
|
|
|
|
/* if no ressource */
|
|
|
|
if (rc < 0) {
|
|
|
|
LOGP(DRLCMAC, LOGL_ERROR, "No ressource after update???\n");
|
|
|
|
return -rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int tbf_assign_control_ts(struct gprs_rlcmac_tbf *tbf)
|
|
|
|
{
|
|
|
|
if (tbf->control_ts == 0xff)
|
|
|
|
LOGP(DRLCMAC, LOGL_DEBUG, "- Setting Control TS %d\n",
|
|
|
|
tbf->control_ts);
|
|
|
|
else if (tbf->control_ts != tbf->first_common_ts)
|
|
|
|
LOGP(DRLCMAC, LOGL_DEBUG, "- Changing Control TS %d\n",
|
|
|
|
tbf->control_ts);
|
|
|
|
tbf->control_ts = tbf->first_common_ts;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-03 11:36:03 +00:00
|
|
|
const char *tbf_state_name[] = {
|
|
|
|
"NULL",
|
|
|
|
"ASSIGN",
|
|
|
|
"FLOW",
|
|
|
|
"FINISHED",
|
|
|
|
"WAIT RELEASE",
|
|
|
|
"RELEASING",
|
|
|
|
};
|
2012-06-17 04:30:06 +00:00
|
|
|
|
2012-07-03 11:36:03 +00:00
|
|
|
void tbf_new_state(struct gprs_rlcmac_tbf *tbf,
|
|
|
|
enum gprs_rlcmac_tbf_state state)
|
2012-06-17 04:30:06 +00:00
|
|
|
{
|
2012-07-13 12:46:03 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_DEBUG, "%s TBF=%d changes state from %s to %s\n",
|
|
|
|
(tbf->direction == GPRS_RLCMAC_UL_TBF) ? "UL" : "DL", tbf->tfi,
|
|
|
|
tbf_state_name[tbf->state], tbf_state_name[state]);
|
2012-07-03 11:36:03 +00:00
|
|
|
tbf->state = state;
|
2012-06-17 04:30:06 +00:00
|
|
|
}
|
2012-04-12 11:22:06 +00:00
|
|
|
|
2012-06-27 13:52:04 +00:00
|
|
|
void tbf_timer_start(struct gprs_rlcmac_tbf *tbf, unsigned int T,
|
2012-07-03 11:36:03 +00:00
|
|
|
unsigned int seconds, unsigned int microseconds)
|
2012-04-12 11:22:06 +00:00
|
|
|
{
|
2012-06-27 13:52:04 +00:00
|
|
|
if (!osmo_timer_pending(&tbf->timer))
|
2012-07-13 12:46:03 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_DEBUG, "Starting %s TBF=%d timer %u.\n",
|
|
|
|
(tbf->direction == GPRS_RLCMAC_UL_TBF) ? "UL" : "DL",
|
2012-07-03 11:36:03 +00:00
|
|
|
tbf->tfi, T);
|
2012-06-27 13:52:04 +00:00
|
|
|
else
|
2012-07-13 12:46:03 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_DEBUG, "Restarting %s TBF=%d timer %u "
|
|
|
|
"while old timer %u pending \n",
|
|
|
|
(tbf->direction == GPRS_RLCMAC_UL_TBF) ? "UL" : "DL",
|
|
|
|
tbf->tfi, T, tbf->T);
|
2012-04-12 11:22:06 +00:00
|
|
|
|
|
|
|
tbf->T = T;
|
|
|
|
tbf->num_T_exp = 0;
|
|
|
|
|
2012-06-27 13:52:04 +00:00
|
|
|
/* Tunning timers can be safely re-scheduled. */
|
2012-04-12 11:22:06 +00:00
|
|
|
tbf->timer.data = tbf;
|
|
|
|
tbf->timer.cb = &tbf_timer_cb;
|
|
|
|
|
2012-07-03 11:36:03 +00:00
|
|
|
osmo_timer_schedule(&tbf->timer, seconds, microseconds);
|
2012-04-12 11:22:06 +00:00
|
|
|
}
|
|
|
|
|
2012-06-27 13:52:04 +00:00
|
|
|
void tbf_timer_stop(struct gprs_rlcmac_tbf *tbf)
|
|
|
|
{
|
|
|
|
if (osmo_timer_pending(&tbf->timer)) {
|
2012-07-13 12:46:03 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_DEBUG, "Stopping %s TBF=%d timer %u.\n",
|
|
|
|
(tbf->direction == GPRS_RLCMAC_UL_TBF) ? "UL" : "DL",
|
2012-07-03 11:36:03 +00:00
|
|
|
tbf->tfi, tbf->T);
|
2012-06-27 13:52:04 +00:00
|
|
|
osmo_timer_del(&tbf->timer);
|
|
|
|
}
|
|
|
|
}
|
2012-04-12 11:22:06 +00:00
|
|
|
|
2012-07-03 11:36:03 +00:00
|
|
|
#if 0
|
2012-04-12 11:22:06 +00:00
|
|
|
static void tbf_gsm_timer_cb(void *_tbf)
|
|
|
|
{
|
|
|
|
struct gprs_rlcmac_tbf *tbf = (struct gprs_rlcmac_tbf *)_tbf;
|
|
|
|
|
|
|
|
tbf->num_fT_exp++;
|
|
|
|
|
|
|
|
switch (tbf->fT) {
|
|
|
|
case 0:
|
2012-07-12 10:49:15 +00:00
|
|
|
hier alles berdenken
|
2012-04-12 11:22:06 +00:00
|
|
|
// This is timer for delay RLC/MAC data sending after Downlink Immediate Assignment on CCCH.
|
|
|
|
gprs_rlcmac_segment_llc_pdu(tbf);
|
2012-05-24 18:25:06 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_NOTICE, "TBF: [DOWNLINK] END TFI: %u TLLI: 0x%08x \n", tbf->tfi, tbf->tlli);
|
2012-05-24 19:12:59 +00:00
|
|
|
tbf_free(tbf);
|
2012-04-12 11:22:06 +00:00
|
|
|
break;
|
|
|
|
default:
|
2012-06-15 05:31:29 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_NOTICE, "Timer expired in unknown mode: %u \n", tbf->fT);
|
2012-04-12 11:22:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tbf_gsm_timer_start(struct gprs_rlcmac_tbf *tbf, unsigned int fT,
|
|
|
|
int frames)
|
|
|
|
{
|
|
|
|
if (osmo_gsm_timer_pending(&tbf->gsm_timer))
|
2012-06-15 05:31:29 +00:00
|
|
|
LOGP(DRLCMAC, LOGL_NOTICE, "Starting TBF timer %u while old timer %u pending \n", fT, tbf->fT);
|
2012-04-12 11:22:06 +00:00
|
|
|
tbf->fT = fT;
|
|
|
|
tbf->num_fT_exp = 0;
|
|
|
|
|
|
|
|
/* FIXME: we should do this only once ? */
|
|
|
|
tbf->gsm_timer.data = tbf;
|
|
|
|
tbf->gsm_timer.cb = &tbf_gsm_timer_cb;
|
|
|
|
|
|
|
|
osmo_gsm_timer_schedule(&tbf->gsm_timer, frames);
|
|
|
|
}
|
|
|
|
|
2012-07-03 11:36:03 +00:00
|
|
|
eine stop-funktion, auch im tbf_free aufrufen
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 0
|
2012-06-27 13:52:04 +00:00
|
|
|
void gprs_rlcmac_enqueue_block(bitvec *block, int len)
|
2012-06-23 08:33:16 +00:00
|
|
|
{
|
|
|
|
struct msgb *msg = msgb_alloc(len, "rlcmac_dl");
|
|
|
|
bitvec_pack(block, msgb_put(msg, len));
|
|
|
|
msgb_enqueue(&block_queue, msg);
|
|
|
|
}
|
2012-07-03 11:36:03 +00:00
|
|
|
#endif
|
2012-06-23 08:33:16 +00:00
|
|
|
|
2012-07-03 11:36:03 +00:00
|
|
|
/* received RLC/MAC block from L1 */
|
2012-07-13 12:46:03 +00:00
|
|
|
int gprs_rlcmac_rcv_block(uint8_t trx, uint8_t ts, uint8_t *data, uint8_t len,
|
|
|
|
uint32_t fn)
|
2012-03-05 15:24:57 +00:00
|
|
|
{
|
2012-07-03 11:36:03 +00:00
|
|
|
unsigned payload = data[0] >> 6;
|
|
|
|
bitvec *block;
|
|
|
|
int rc = 0;
|
2012-03-05 15:24:57 +00:00
|
|
|
|
2012-07-03 11:36:03 +00:00
|
|
|
switch (payload) {
|
|
|
|
case GPRS_RLCMAC_DATA_BLOCK:
|
2012-07-13 12:46:03 +00:00
|
|
|
rc = gprs_rlcmac_rcv_data_block_acknowledged(trx, ts, data,
|
|
|
|
len);
|
2012-07-03 11:36:03 +00:00
|
|
|
break;
|
|
|
|
case GPRS_RLCMAC_CONTROL_BLOCK:
|
|
|
|
block = bitvec_alloc(len);
|
|
|
|
if (!block)
|
|
|
|
return -ENOMEM;
|
|
|
|
bitvec_unpack(block, data);
|
2012-07-13 12:46:03 +00:00
|
|
|
rc = gprs_rlcmac_rcv_control_block(block, trx, ts, fn);
|
2012-07-03 11:36:03 +00:00
|
|
|
bitvec_free(block);
|
|
|
|
break;
|
|
|
|
case GPRS_RLCMAC_CONTROL_BLOCK_OPT:
|
|
|
|
LOGP(DRLCMAC, LOGL_NOTICE, "GPRS_RLCMAC_CONTROL_BLOCK_OPT block payload is not supported.\n");
|
|
|
|
default:
|
|
|
|
LOGP(DRLCMAC, LOGL_NOTICE, "Unknown RLCMAC block payload.\n");
|
|
|
|
rc = -EINVAL;
|
2012-06-27 14:41:04 +00:00
|
|
|
}
|
2012-03-05 15:24:57 +00:00
|
|
|
|
2012-07-03 11:36:03 +00:00
|
|
|
return rc;
|
2012-03-05 15:24:57 +00:00
|
|
|
}
|
|
|
|
|
2012-04-17 18:00:31 +00:00
|
|
|
// GSM 04.08 9.1.18 Immediate assignment
|
2012-07-03 11:36:03 +00:00
|
|
|
int write_immediate_assignment(bitvec * dest, uint8_t downlink, uint8_t ra,
|
|
|
|
uint32_t fn, uint8_t ta, uint16_t arfcn, uint8_t ts, uint8_t tsc,
|
|
|
|
uint8_t tfi, uint8_t usf, uint32_t tlli,
|
|
|
|
uint8_t polling, uint32_t poll_fn)
|
2012-04-17 18:00:31 +00:00
|
|
|
{
|
|
|
|
unsigned wp = 0;
|
2012-07-05 05:38:49 +00:00
|
|
|
uint8_t plen;
|
2012-04-17 18:00:31 +00:00
|
|
|
|
2012-04-30 14:00:36 +00:00
|
|
|
bitvec_write_field(dest, wp,0x0,4); // Skip Indicator
|
|
|
|
bitvec_write_field(dest, wp,0x6,4); // Protocol Discriminator
|
|
|
|
bitvec_write_field(dest, wp,0x3F,8); // Immediate Assignment Message Type
|
2012-04-17 18:00:31 +00:00
|
|
|
|
|
|
|
// 10.5.2.25b Dedicated mode or TBF
|
2012-04-30 14:00:36 +00:00
|
|
|
bitvec_write_field(dest, wp,0x0,1); // spare
|
|
|
|
bitvec_write_field(dest, wp,0x0,1); // TMA : Two-message assignment: No meaning
|
|
|
|
bitvec_write_field(dest, wp,downlink,1); // Downlink : Downlink assignment to mobile in packet idle mode
|
|
|
|
bitvec_write_field(dest, wp,0x1,1); // T/D : TBF or dedicated mode: this message assigns a Temporary Block Flow (TBF).
|
2012-04-17 18:00:31 +00:00
|
|
|
|
2012-04-30 14:00:36 +00:00
|
|
|
bitvec_write_field(dest, wp,0x0,4); // Page Mode
|
2012-04-17 18:00:31 +00:00
|
|
|
|
|
|
|
// GSM 04.08 10.5.2.25a Packet Channel Description
|
2012-04-30 14:00:36 +00:00
|
|
|
bitvec_write_field(dest, wp,0x1,5); // Channel type
|
2012-06-23 08:33:16 +00:00
|
|
|
bitvec_write_field(dest, wp,ts,3); // TN
|
|
|
|
bitvec_write_field(dest, wp,tsc,3); // TSC
|
2012-04-30 14:00:36 +00:00
|
|
|
bitvec_write_field(dest, wp,0x0,3); // non-hopping RF channel configuraion
|
2012-06-23 08:33:16 +00:00
|
|
|
bitvec_write_field(dest, wp,arfcn,10); // ARFCN
|
2012-04-17 18:00:31 +00:00
|
|
|
|
|
|
|
//10.5.2.30 Request Reference
|
2012-04-30 14:00:36 +00:00
|
|
|
bitvec_write_field(dest, wp,ra,8); // RA
|
|
|
|
bitvec_write_field(dest, wp,(fn / (26 * 51)) % 32,5); // T1'
|
|
|
|
bitvec_write_field(dest, wp,fn % 51,6); // T3
|
|
|
|
bitvec_write_field(dest, wp,fn % 26,5); // T2
|
2012-04-17 18:00:31 +00:00
|
|
|
|
|
|
|
// 10.5.2.40 Timing Advance
|
2012-04-30 14:00:36 +00:00
|
|
|
bitvec_write_field(dest, wp,0x0,2); // spare
|
|
|
|
bitvec_write_field(dest, wp,ta,6); // Timing Advance value
|
2012-04-17 18:00:31 +00:00
|
|
|
|
|
|
|
// No mobile allocation in non-hopping systems.
|
|
|
|
// A zero-length LV. Just write L=0.
|
2012-04-30 14:00:36 +00:00
|
|
|
bitvec_write_field(dest, wp,0,8);
|
2012-04-17 18:00:31 +00:00
|
|
|
|
2012-07-05 05:38:49 +00:00
|
|
|
if ((wp % 8)) {
|
|
|
|
LOGP(DRLCMACUL, LOGL_ERROR, "Length of IMM.ASS without rest "
|
|
|
|
"octets is not multiple of 8 bits, PLEASE FIX!\n");
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
plen = wp / 8;
|
|
|
|
|
2012-04-17 18:00:31 +00:00
|
|
|
if (downlink)
|
|
|
|
{
|
|
|
|
// GSM 04.08 10.5.2.16 IA Rest Octets
|
2012-04-30 14:00:36 +00:00
|
|
|
bitvec_write_field(dest, wp, 3, 2); // "HH"
|
|
|
|
bitvec_write_field(dest, wp, 1, 2); // "01" Packet Downlink Assignment
|
|
|
|
bitvec_write_field(dest, wp,tlli,32); // TLLI
|
|
|
|
bitvec_write_field(dest, wp,0x1,1); // switch TFI : on
|
|
|
|
bitvec_write_field(dest, wp,tfi,5); // TFI
|
|
|
|
bitvec_write_field(dest, wp,0x0,1); // RLC acknowledged mode
|
2012-07-03 11:36:03 +00:00
|
|
|
bitvec_write_field(dest, wp,0x0,1); // ALPHA = not present
|
2012-04-30 14:00:36 +00:00
|
|
|
bitvec_write_field(dest, wp,0x0,5); // GAMMA power control parameter
|
2012-07-03 11:36:03 +00:00
|
|
|
bitvec_write_field(dest, wp,polling,1); // Polling Bit
|
|
|
|
bitvec_write_field(dest, wp,!polling,1); // TA_VALID ???
|
2012-04-30 14:00:36 +00:00
|
|
|
bitvec_write_field(dest, wp,0x1,1); // switch TIMING_ADVANCE_INDEX = on
|
|
|
|
bitvec_write_field(dest, wp,0x0,4); // TIMING_ADVANCE_INDEX
|
2012-07-03 11:36:03 +00:00
|
|
|
if (polling) {
|
|
|
|
bitvec_write_field(dest, wp,0x1,1); // TBF Starting TIME present
|
|
|
|
bitvec_write_field(dest, wp,(poll_fn / (26 * 51)) % 32,5); // T1'
|
|
|
|
bitvec_write_field(dest, wp,poll_fn % 51,6); // T3
|
|
|
|
bitvec_write_field(dest, wp,poll_fn % 26,5); // T2
|
|
|
|
} else {
|
|
|
|
bitvec_write_field(dest, wp,0x0,1); // TBF Starting TIME present
|
|
|
|
}
|
2012-04-30 14:00:36 +00:00
|
|
|
bitvec_write_field(dest, wp,0x0,1); // P0 not present
|
2012-07-03 11:36:03 +00:00
|
|
|
// bitvec_write_field(dest, wp,0x1,1); // P0 not present
|
|
|
|
// bitvec_write_field(dest, wp,0xb,4);
|
2012-04-17 18:00:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-07-06 06:13:59 +00:00
|
|
|
struct gprs_rlcmac_bts *bts = gprs_rlcmac_bts;
|
2012-04-17 18:00:31 +00:00
|
|
|
// GMS 04.08 10.5.2.37b 10.5.2.16
|
2012-04-30 14:00:36 +00:00
|
|
|
bitvec_write_field(dest, wp, 3, 2); // "HH"
|
|
|
|
bitvec_write_field(dest, wp, 0, 2); // "0" Packet Uplink Assignment
|
|
|
|
bitvec_write_field(dest, wp, 1, 1); // Block Allocation : Not Single Block Allocation
|
|
|
|
bitvec_write_field(dest, wp, tfi, 5); // TFI_ASSIGNMENT Temporary Flow Identity
|
|
|
|
bitvec_write_field(dest, wp, 0, 1); // POLLING
|
|
|
|
bitvec_write_field(dest, wp, 0, 1); // ALLOCATION_TYPE: dynamic
|
2012-06-27 13:52:04 +00:00
|
|
|
bitvec_write_field(dest, wp, usf, 3); // USF
|
2012-06-24 09:46:49 +00:00
|
|
|
bitvec_write_field(dest, wp, 0, 1); // USF_GRANULARITY
|
2012-04-30 14:00:36 +00:00
|
|
|
bitvec_write_field(dest, wp, 0 , 1); // "0" power control: Not Present
|
2012-07-06 06:13:59 +00:00
|
|
|
bitvec_write_field(dest, wp, bts->initial_cs-1, 2); // CHANNEL_CODING_COMMAND
|
|
|
|
bitvec_write_field(dest, wp, 1, 1); // TLLI_BLOCK_CHANNEL_CODING
|
2012-04-30 14:00:36 +00:00
|
|
|
bitvec_write_field(dest, wp, 1 , 1); // "1" Alpha : Present
|
|
|
|
bitvec_write_field(dest, wp, 0, 4); // Alpha
|
|
|
|
bitvec_write_field(dest, wp, 0, 5); // Gamma
|
|
|
|
bitvec_write_field(dest, wp, 0, 1); // TIMING_ADVANCE_INDEX_FLAG
|
|
|
|
bitvec_write_field(dest, wp, 0, 1); // TBF_STARTING_TIME_FLAG
|
2012-04-17 18:00:31 +00:00
|
|
|
}
|
|
|
|
|
2012-07-05 05:38:49 +00:00
|
|
|
return plen;
|
2012-04-17 18:00:31 +00:00
|
|
|
}
|
|
|
|
|
2012-07-03 11:36:03 +00:00
|
|
|
/* generate uplink assignment */
|
|
|
|
void write_packet_uplink_assignment(bitvec * dest, uint8_t old_tfi,
|
2012-07-13 12:46:03 +00:00
|
|
|
uint8_t old_downlink, uint32_t tlli, uint8_t use_tlli,
|
|
|
|
struct gprs_rlcmac_tbf *tbf, uint8_t poll)
|
2012-06-29 18:53:15 +00:00
|
|
|
{
|
2012-07-03 11:36:03 +00:00
|
|
|
// TODO We should use our implementation of encode RLC/MAC Control messages.
|
2012-07-06 06:13:59 +00:00
|
|
|
struct gprs_rlcmac_bts *bts = gprs_rlcmac_bts;
|
2012-06-29 18:53:15 +00:00
|
|
|
unsigned wp = 0;
|
2012-07-13 12:46:03 +00:00
|
|
|
uint8_t ts;
|
2012-03-05 15:24:57 +00:00
|
|
|
|
2012-07-03 11:36:03 +00:00
|
|
|
bitvec_write_field(dest, wp,0x1,2); // Payload Type
|
|
|
|
bitvec_write_field(dest, wp,0x0,2); // Uplink block with TDMA framenumber (N+13)
|
|
|
|
bitvec_write_field(dest, wp,poll,1); // Suppl/Polling Bit
|
|
|
|
bitvec_write_field(dest, wp,0x0,3); // Uplink state flag
|
|
|
|
bitvec_write_field(dest, wp,0xa,6); // MESSAGE TYPE
|
2012-03-05 15:24:57 +00:00
|
|
|
|
2012-07-03 11:36:03 +00:00
|
|
|
bitvec_write_field(dest, wp,0x0,2); // Page Mode
|
2012-03-05 15:24:57 +00:00
|
|
|
|
2012-07-03 11:36:03 +00:00
|
|
|
bitvec_write_field(dest, wp,0x0,1); // switch PERSIST_LEVEL: off
|
|
|
|
if (use_tlli) {
|
|
|
|
bitvec_write_field(dest, wp,0x2,2); // switch TLLI : on
|
|
|
|
bitvec_write_field(dest, wp,tlli,32); // TLLI
|
|
|
|
} else {
|
|
|
|
bitvec_write_field(dest, wp,0x0,1); // switch TFI : on
|
|
|
|
bitvec_write_field(dest, wp,old_downlink,1); // 0=UPLINK TFI, 1=DL TFI
|
|
|
|
bitvec_write_field(dest, wp,old_tfi,5); // TFI
|
2012-03-05 15:24:57 +00:00
|
|
|
}
|
2012-06-27 14:41:04 +00:00
|
|
|
|
2012-07-03 11:36:03 +00:00
|
|
|
bitvec_write_field(dest, wp,0x0,1); // Message escape
|
2012-07-13 12:46:03 +00:00
|
|
|
bitvec_write_field(dest, wp,bts->initial_cs-1, 2); // CHANNEL_CODING_COMMAND
|
2012-07-06 06:13:59 +00:00
|
|
|
bitvec_write_field(dest, wp,0x1,1); // TLLI_BLOCK_CHANNEL_CODING
|
2012-03-05 15:24:57 +00:00
|
|
|
|
2012-07-03 11:36:03 +00:00
|
|
|
bitvec_write_field(dest, wp,0x1,1); // switch TIMING_ADVANCE_VALUE = on
|
2012-07-13 12:46:03 +00:00
|
|
|
bitvec_write_field(dest, wp,tbf->ta,6); // TIMING_ADVANCE_VALUE
|
2012-07-03 11:36:03 +00:00
|
|
|
bitvec_write_field(dest, wp,0x0,1); // switch TIMING_ADVANCE_INDEX = off
|
2012-03-05 15:24:57 +00:00
|
|
|
|
2012-07-03 11:36:03 +00:00
|
|
|
#if 1
|
|
|
|
bitvec_write_field(dest, wp,0x1,1); // Frequency Parameters information elements = present
|
2012-07-13 12:46:03 +00:00
|
|
|
bitvec_write_field(dest, wp,tbf->tsc,3); // Training Sequence Code (TSC)
|
2012-07-03 11:36:03 +00:00
|
|
|
bitvec_write_field(dest, wp,0x0,2); // ARFCN = present
|
2012-07-13 12:46:03 +00:00
|
|
|
bitvec_write_field(dest, wp,tbf->arfcn,10); // ARFCN
|
2012-07-03 11:36:03 +00:00
|
|
|
#else
|
|
|
|
bitvec_write_field(dest, wp,0x0,1); // Frequency Parameters = off
|
|
|
|
#endif
|
2012-06-05 12:56:27 +00:00
|
|
|
|
2012-07-03 11:36:03 +00:00
|
|
|
bitvec_write_field(dest, wp,0x1,2); // Dynamic Allocation
|
2012-06-05 12:56:27 +00:00
|
|
|
|
2012-07-03 11:36:03 +00:00
|
|
|
bitvec_write_field(dest, wp,0x0,1); // Extended Dynamic Allocation = off
|
|
|
|
bitvec_write_field(dest, wp,0x0,1); // P0 = off
|
2012-06-05 12:56:27 +00:00
|
|
|
|
2012-07-03 11:36:03 +00:00
|
|
|
bitvec_write_field(dest, wp,0x0,1); // USF_GRANULARITY
|
|
|
|
bitvec_write_field(dest, wp,0x1,1); // switch TFI : on
|
2012-07-13 12:46:03 +00:00
|
|
|
bitvec_write_field(dest, wp,tbf->tfi,5);// TFI
|
2012-03-05 15:24:57 +00:00
|
|
|
|
2012-07-03 11:36:03 +00:00
|
|
|
bitvec_write_field(dest, wp,0x0,1); //
|
|
|
|
bitvec_write_field(dest, wp,0x0,1); // TBF Starting Time = off
|
|
|
|
bitvec_write_field(dest, wp,0x0,1); // Timeslot Allocation
|
2012-06-17 04:30:06 +00:00
|
|
|
|
2012-07-13 12:46:03 +00:00
|
|
|
for (ts = 0; ts < 8; ts++) {
|
|
|
|
if (tbf->pdch[ts]) {
|
2012-07-03 11:36:03 +00:00
|
|
|
bitvec_write_field(dest, wp,0x1,1); // USF_TN(i): on
|
2012-07-13 12:46:03 +00:00
|
|
|
bitvec_write_field(dest, wp,tbf->dir.ul.usf[ts],3); // USF_TN(i)
|
2012-07-03 11:36:03 +00:00
|
|
|
} else
|
|
|
|
bitvec_write_field(dest, wp,0x0,1); // USF_TN(i): off
|
2012-03-05 15:24:57 +00:00
|
|
|
}
|
2012-07-03 11:36:03 +00:00
|
|
|
// bitvec_write_field(dest, wp,0x0,1); // Measurement Mapping struct not present
|
2012-03-05 15:24:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-03 11:36:03 +00:00
|
|
|
/* generate downlink assignment */
|
2012-07-12 10:49:15 +00:00
|
|
|
void write_packet_downlink_assignment(RlcMacDownlink_t * block, uint8_t old_tfi,
|
2012-07-13 12:46:03 +00:00
|
|
|
uint8_t old_downlink, struct gprs_rlcmac_tbf *tbf, uint8_t poll)
|
2012-06-23 08:33:16 +00:00
|
|
|
{
|
2012-07-12 10:49:15 +00:00
|
|
|
// Packet downlink assignment TS 44.060 11.2.7
|
2012-06-23 08:33:16 +00:00
|
|
|
|
2012-07-13 12:46:03 +00:00
|
|
|
uint8_t tn;
|
2012-06-23 08:33:16 +00:00
|
|
|
|
2012-07-12 10:49:15 +00:00
|
|
|
block->PAYLOAD_TYPE = 0x1; // RLC/MAC control block that does not include the optional octets of the RLC/MAC control header
|
|
|
|
block->RRBP = 0x0; // N+13
|
|
|
|
block->SP = poll; // RRBP field is valid
|
|
|
|
block->USF = 0x0; // Uplink state flag
|
2012-06-23 08:33:16 +00:00
|
|
|
|
2012-07-12 10:49:15 +00:00
|
|
|
block->u.Packet_Downlink_Assignment.MESSAGE_TYPE = 0x2; // Packet Downlink Assignment
|
|
|
|
block->u.Packet_Downlink_Assignment.PAGE_MODE = 0x0; // Normal Paging
|
2012-06-23 08:33:16 +00:00
|
|
|
|
2012-07-12 10:49:15 +00:00
|
|
|
block->u.Packet_Downlink_Assignment.Exist_PERSISTENCE_LEVEL = 0x0; // PERSISTENCE_LEVEL: off
|
2012-06-23 08:33:16 +00:00
|
|
|
|
2012-07-12 10:49:15 +00:00
|
|
|
block->u.Packet_Downlink_Assignment.ID.UnionType = 0x0; // TFI = on
|
|
|
|
block->u.Packet_Downlink_Assignment.ID.u.Global_TFI.UnionType = old_downlink; // 0=UPLINK TFI, 1=DL TFI
|
|
|
|
block->u.Packet_Downlink_Assignment.ID.u.Global_TFI.u.UPLINK_TFI = old_tfi; // TFI
|
2012-04-17 18:00:31 +00:00
|
|
|
|
2012-07-12 10:49:15 +00:00
|
|
|
block->u.Packet_Downlink_Assignment.MAC_MODE = 0x0; // Dynamic Allocation
|
|
|
|
block->u.Packet_Downlink_Assignment.RLC_MODE = 0x0; // RLC acknowledged mode
|
|
|
|
block->u.Packet_Downlink_Assignment.CONTROL_ACK = old_downlink; // NW establishes no new DL TBF for the MS with running timer T3192
|
2012-07-13 12:46:03 +00:00
|
|
|
block->u.Packet_Downlink_Assignment.TIMESLOT_ALLOCATION = 0; // timeslot(s)
|
|
|
|
for (tn = 0; tn < 8; tn++) {
|
|
|
|
if (tbf->pdch[tn])
|
|
|
|
block->u.Packet_Downlink_Assignment.TIMESLOT_ALLOCATION |= 0x80 >> tn; // timeslot(s)
|
|
|
|
}
|
2012-04-17 18:00:31 +00:00
|
|
|
|
2012-07-12 10:49:15 +00:00
|
|
|
block->u.Packet_Downlink_Assignment.Packet_Timing_Advance.Exist_TIMING_ADVANCE_VALUE = 0x1; // TIMING_ADVANCE_VALUE = on
|
2012-07-13 12:46:03 +00:00
|
|
|
block->u.Packet_Downlink_Assignment.Packet_Timing_Advance.TIMING_ADVANCE_VALUE = tbf->ta; // TIMING_ADVANCE_VALUE
|
2012-07-12 10:49:15 +00:00
|
|
|
block->u.Packet_Downlink_Assignment.Packet_Timing_Advance.Exist_IndexAndtimeSlot = 0x0; // TIMING_ADVANCE_INDEX = off
|
2012-06-17 04:30:06 +00:00
|
|
|
|
2012-07-12 10:49:15 +00:00
|
|
|
block->u.Packet_Downlink_Assignment.Exist_P0_and_BTS_PWR_CTRL_MODE = 0x0; // POWER CONTROL = off
|
2012-06-17 04:30:06 +00:00
|
|
|
|
2012-07-12 10:49:15 +00:00
|
|
|
block->u.Packet_Downlink_Assignment.Exist_Frequency_Parameters = 0x1; // Frequency Parameters = on
|
2012-07-13 12:46:03 +00:00
|
|
|
block->u.Packet_Downlink_Assignment.Frequency_Parameters.TSC = tbf->tsc; // Training Sequence Code (TSC)
|
2012-07-12 10:49:15 +00:00
|
|
|
block->u.Packet_Downlink_Assignment.Frequency_Parameters.UnionType = 0x0; // ARFCN = on
|
2012-07-13 12:46:03 +00:00
|
|
|
block->u.Packet_Downlink_Assignment.Frequency_Parameters.u.ARFCN = tbf->arfcn; // ARFCN
|
2012-03-05 15:24:57 +00:00
|
|
|
|
2012-07-12 10:49:15 +00:00
|
|
|
block->u.Packet_Downlink_Assignment.Exist_DOWNLINK_TFI_ASSIGNMENT = 0x1; // DOWNLINK TFI ASSIGNMENT = on
|
2012-07-13 12:46:03 +00:00
|
|
|
block->u.Packet_Downlink_Assignment.DOWNLINK_TFI_ASSIGNMENT = tbf->tfi; // TFI
|
2012-06-06 21:12:29 +00:00
|
|
|
|
2012-07-12 10:49:15 +00:00
|
|
|
block->u.Packet_Downlink_Assignment.Exist_Power_Control_Parameters = 0x1; // Power Control Parameters = on
|
|
|
|
block->u.Packet_Downlink_Assignment.Power_Control_Parameters.ALPHA = 0x0; // ALPHA
|
2012-03-05 15:24:57 +00:00
|
|
|
|
2012-07-13 12:46:03 +00:00
|
|
|
for (tn = 0; tn < 8; tn++)
|
2012-06-06 21:12:29 +00:00
|
|
|
{
|
2012-07-13 12:46:03 +00:00
|
|
|
if (tbf->pdch[tn])
|
2012-03-05 15:24:57 +00:00
|
|
|
{
|
2012-07-13 12:46:03 +00:00
|
|
|
block->u.Packet_Downlink_Assignment.Power_Control_Parameters.Slot[tn].Exist = 0x1; // Slot[i] = on
|
|
|
|
block->u.Packet_Downlink_Assignment.Power_Control_Parameters.Slot[tn].GAMMA_TN = 0x0; // GAMMA_TN
|
2012-07-12 10:49:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-07-13 12:46:03 +00:00
|
|
|
block->u.Packet_Downlink_Assignment.Power_Control_Parameters.Slot[tn].Exist = 0x0; // Slot[i] = off
|
2012-03-05 15:24:57 +00:00
|
|
|
}
|
2012-07-12 10:49:15 +00:00
|
|
|
}
|
2012-06-06 21:12:29 +00:00
|
|
|
|
2012-07-12 10:49:15 +00:00
|
|
|
block->u.Packet_Downlink_Assignment.Exist_TBF_Starting_Time = 0x0; // TBF Starting TIME = off
|
|
|
|
block->u.Packet_Downlink_Assignment.Exist_Measurement_Mapping = 0x0; // Measurement_Mapping = off
|
|
|
|
block->u.Packet_Downlink_Assignment.Exist_AdditionsR99 = 0x0; // AdditionsR99 = off
|
2012-03-05 15:24:57 +00:00
|
|
|
}
|
2012-06-06 21:12:29 +00:00
|
|
|
|
2012-07-03 11:36:03 +00:00
|
|
|
/* generate uplink ack */
|
2012-07-12 10:49:15 +00:00
|
|
|
void write_packet_uplink_ack(RlcMacDownlink_t * block, struct gprs_rlcmac_tbf *tbf,
|
2012-07-03 11:36:03 +00:00
|
|
|
uint8_t final)
|
2012-03-05 15:24:57 +00:00
|
|
|
{
|
2012-07-12 10:49:15 +00:00
|
|
|
// Packet Uplink Ack/Nack TS 44.060 11.2.28
|
2012-06-06 21:12:29 +00:00
|
|
|
|
2012-07-03 11:36:03 +00:00
|
|
|
char show_v_n[65];
|
2012-06-06 21:12:29 +00:00
|
|
|
|
2012-07-12 10:49:15 +00:00
|
|
|
uint8_t rbb = 0;
|
2012-07-03 11:36:03 +00:00
|
|
|
uint16_t i, bbn;
|
|
|
|
uint16_t mod_sns_half = (tbf->sns >> 1) - 1;
|
|
|
|
char bit;
|
2012-03-05 15:24:57 +00:00
|
|
|
|
2012-07-03 11:36:03 +00:00
|
|
|
LOGP(DRLCMACUL, LOGL_DEBUG, "Sending Ack/Nack for TBF=%d "
|
|
|
|
"(final=%d)\n", tbf->tfi, final);
|
2012-06-06 21:12:29 +00:00
|
|
|
|
2012-07-12 10:49:15 +00:00
|
|
|
block->PAYLOAD_TYPE = 0x1; // RLC/MAC control block that does not include the optional octets of the RLC/MAC control header
|
|
|
|
block->RRBP = 0x0; // N+13
|
|
|
|
block->SP = final; // RRBP field is valid, if it is final ack
|
|
|
|
block->USF = 0x0; // Uplink state flag
|
2012-07-03 11:36:03 +00:00
|
|
|
|
2012-07-12 10:49:15 +00:00
|
|
|
block->u.Packet_Uplink_Ack_Nack.MESSAGE_TYPE = 0x9; // Packet Downlink Assignment
|
|
|
|
block->u.Packet_Uplink_Ack_Nack.PAGE_MODE = 0x0; // Normal Paging
|
|
|
|
block->u.Packet_Uplink_Ack_Nack.UPLINK_TFI = tbf->tfi; // Uplink TFI
|
2012-06-23 08:33:16 +00:00
|
|
|
|
2012-07-12 10:49:15 +00:00
|
|
|
block->u.Packet_Uplink_Ack_Nack.UnionType = 0x0; // PU_AckNack_GPRS = on
|
|
|
|
block->u.Packet_Uplink_Ack_Nack.u.PU_AckNack_GPRS_Struct.CHANNEL_CODING_COMMAND = 0x0; // CS1
|
|
|
|
block->u.Packet_Uplink_Ack_Nack.u.PU_AckNack_GPRS_Struct.Ack_Nack_Description.FINAL_ACK_INDICATION = final; // FINAL ACK INDICATION
|
|
|
|
block->u.Packet_Uplink_Ack_Nack.u.PU_AckNack_GPRS_Struct.Ack_Nack_Description.STARTING_SEQUENCE_NUMBER = tbf->dir.ul.v_r; // STARTING_SEQUENCE_NUMBER
|
2012-07-03 11:36:03 +00:00
|
|
|
// RECEIVE_BLOCK_BITMAP
|
|
|
|
for (i = 0, bbn = (tbf->dir.ul.v_r - 64) & mod_sns_half; i < 64;
|
|
|
|
i++, bbn = (bbn + 1) & mod_sns_half) {
|
|
|
|
bit = tbf->dir.ul.v_n[bbn];
|
|
|
|
if (bit == 0)
|
|
|
|
bit = ' ';
|
|
|
|
show_v_n[i] = bit;
|
2012-07-12 10:49:15 +00:00
|
|
|
if (bit == 'R')
|
|
|
|
rbb = (rbb << 1)|1;
|
|
|
|
else
|
|
|
|
rbb = (rbb << 1);
|
|
|
|
if((i%8) == 7)
|
2012-03-05 15:24:57 +00:00
|
|
|
{
|
2012-07-12 10:49:15 +00:00
|
|
|
block->u.Packet_Uplink_Ack_Nack.u.PU_AckNack_GPRS_Struct.Ack_Nack_Description.RECEIVED_BLOCK_BITMAP[i/8] = rbb;
|
|
|
|
rbb = 0;
|
2012-03-05 15:24:57 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-03 11:36:03 +00:00
|
|
|
show_v_n[64] = '\0';
|
|
|
|
LOGP(DRLCMACUL, LOGL_DEBUG, "- V(N): \"%s\" R=Received "
|
|
|
|
"N=Not-Received\n", show_v_n);
|
2012-06-23 08:33:16 +00:00
|
|
|
|
2012-07-12 10:49:15 +00:00
|
|
|
block->u.Packet_Uplink_Ack_Nack.u.PU_AckNack_GPRS_Struct.UnionType = 0x0; // Fixed Allocation Dummy = on
|
|
|
|
block->u.Packet_Uplink_Ack_Nack.u.PU_AckNack_GPRS_Struct.u.FixedAllocationDummy = 0x0; // Fixed Allocation Dummy
|
|
|
|
block->u.Packet_Uplink_Ack_Nack.u.PU_AckNack_GPRS_Struct.Exist_AdditionsR99 = 0x0; // AdditionsR99 = off
|
|
|
|
|
|
|
|
block->u.Packet_Uplink_Ack_Nack.u.PU_AckNack_GPRS_Struct.Common_Uplink_Ack_Nack_Data.Exist_CONTENTION_RESOLUTION_TLLI = 0x1;
|
|
|
|
block->u.Packet_Uplink_Ack_Nack.u.PU_AckNack_GPRS_Struct.Common_Uplink_Ack_Nack_Data.CONTENTION_RESOLUTION_TLLI = tbf->tlli;
|
|
|
|
block->u.Packet_Uplink_Ack_Nack.u.PU_AckNack_GPRS_Struct.Common_Uplink_Ack_Nack_Data.Exist_Packet_Timing_Advance = 0x0;
|
|
|
|
block->u.Packet_Uplink_Ack_Nack.u.PU_AckNack_GPRS_Struct.Common_Uplink_Ack_Nack_Data.Exist_Extension_Bits = 0x0;
|
|
|
|
block->u.Packet_Uplink_Ack_Nack.u.PU_AckNack_GPRS_Struct.Common_Uplink_Ack_Nack_Data.Exist_Power_Control_Parameters = 0x0;
|
2012-03-05 15:24:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Send Uplink unit-data to SGSN. */
|
2012-07-06 07:28:15 +00:00
|
|
|
int gprs_rlcmac_tx_ul_ud(gprs_rlcmac_tbf *tbf)
|
2012-03-05 15:24:57 +00:00
|
|
|
{
|
|
|
|
const uint8_t qos_profile = QOS_PROFILE;
|
|
|
|
struct msgb *llc_pdu;
|
2012-06-27 13:52:04 +00:00
|
|
|
unsigned msg_len = NS_HDR_LEN + BSSGP_HDR_LEN + tbf->llc_index;
|
2012-03-05 15:24:57 +00:00
|
|
|
|
2012-07-13 12:46:03 +00:00
|
|
|
LOGP(DBSSGP, LOGL_INFO, "LLC [PCU -> SGSN] TFI: %u TLLI: 0x%08x len=%d\n", tbf->tfi, tbf->tlli, tbf->llc_index);
|
2012-07-06 07:28:15 +00:00
|
|
|
if (!bctx) {
|
|
|
|
LOGP(DBSSGP, LOGL_ERROR, "No bctx\n");
|
|
|
|
return -EIO;
|
|
|
|
}
|
2012-03-18 11:04:48 +00:00
|
|
|
|
2012-03-05 15:24:57 +00:00
|
|
|
llc_pdu = msgb_alloc_headroom(msg_len, msg_len,"llc_pdu");
|
2012-06-27 13:52:04 +00:00
|
|
|
msgb_tvlv_push(llc_pdu, BSSGP_IE_LLC_PDU, sizeof(uint8_t)*tbf->llc_index, tbf->llc_frame);
|
2012-03-05 15:24:57 +00:00
|
|
|
bssgp_tx_ul_ud(bctx, tbf->tlli, &qos_profile, llc_pdu);
|
2012-05-24 19:12:59 +00:00
|
|
|
|
2012-07-06 07:28:15 +00:00
|
|
|
return 0;
|
2012-06-29 18:53:15 +00:00
|
|
|
}
|