aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bts.cpp9
-rw-r--r--src/bts.h3
-rw-r--r--src/gprs_rlcmac.h6
-rw-r--r--src/gprs_rlcmac_ts_alloc.cpp43
-rw-r--r--src/tbf.cpp48
-rw-r--r--src/tbf.h5
-rw-r--r--src/tbf_dl.cpp17
7 files changed, 71 insertions, 60 deletions
diff --git a/src/bts.cpp b/src/bts.cpp
index bd1e025e..712954ea 100644
--- a/src/bts.cpp
+++ b/src/bts.cpp
@@ -392,7 +392,6 @@ int BTS::rcv_rach(uint8_t ra, uint32_t Fn, int16_t qta)
{
struct gprs_rlcmac_ul_tbf *tbf = NULL;
uint8_t trx_no, ts_no = 0;
- int8_t tfi; /* must be signed */
uint8_t sb = 0;
uint32_t sb_fn = 0;
int rc;
@@ -429,14 +428,8 @@ int BTS::rcv_rach(uint8_t ra, uint32_t Fn, int16_t qta)
} else {
// Create new TBF
#warning "Copy and pate with other routines.."
- tfi = tfi_find_free(GPRS_RLCMAC_UL_TBF, &trx_no, -1);
- if (tfi < 0) {
- LOGP(DRLCMAC, LOGL_NOTICE, "No PDCH resource\n");
- /* FIXME: send reject */
- return -EBUSY;
- }
/* set class to 0, since we don't know the multislot class yet */
- tbf = tbf_alloc_ul_tbf(&m_bts, NULL, tfi, trx_no, 0, 1);
+ tbf = tbf_alloc_ul_tbf(&m_bts, NULL, -1, 0, 1);
if (!tbf) {
LOGP(DRLCMAC, LOGL_NOTICE, "No PDCH resource\n");
/* FIXME: send reject */
diff --git a/src/bts.h b/src/bts.h
index b0e88f59..8784f4d5 100644
--- a/src/bts.h
+++ b/src/bts.h
@@ -162,7 +162,8 @@ struct gprs_rlcmac_bts {
struct gprs_rlcmac_trx trx[8];
int (*alloc_algorithm)(struct gprs_rlcmac_bts *bts,
struct GprsMs *ms,
- struct gprs_rlcmac_tbf *tbf, uint32_t cust, uint8_t single);
+ struct gprs_rlcmac_tbf *tbf, uint32_t cust, uint8_t single,
+ int use_tbf);
uint32_t alloc_algorithm_curst; /* options to customize algorithm */
uint8_t force_two_phase;
uint8_t alpha, gamma;
diff --git a/src/gprs_rlcmac.h b/src/gprs_rlcmac.h
index dab3338f..3fc95e69 100644
--- a/src/gprs_rlcmac.h
+++ b/src/gprs_rlcmac.h
@@ -97,11 +97,13 @@ extern "C" {
#endif
int alloc_algorithm_a(struct gprs_rlcmac_bts *bts,
struct GprsMs *ms,
- struct gprs_rlcmac_tbf *tbf, uint32_t cust, uint8_t single);
+ struct gprs_rlcmac_tbf *tbf, uint32_t cust, uint8_t single,
+ int use_trx);
int alloc_algorithm_b(struct gprs_rlcmac_bts *bts,
struct GprsMs *ms,
- struct gprs_rlcmac_tbf *tbf, uint32_t cust, uint8_t single);
+ struct gprs_rlcmac_tbf *tbf, uint32_t cust, uint8_t single,
+ int use_trx);
#ifdef __cplusplus
}
#endif
diff --git a/src/gprs_rlcmac_ts_alloc.cpp b/src/gprs_rlcmac_ts_alloc.cpp
index ec228d1a..33814365 100644
--- a/src/gprs_rlcmac_ts_alloc.cpp
+++ b/src/gprs_rlcmac_ts_alloc.cpp
@@ -277,6 +277,24 @@ static void assign_dlink_tbf(
attach_tbf_to_pdch(pdch, tbf);
}
+static int tfi_find_free(BTS *bts, GprsMs *ms, enum gprs_rlcmac_tbf_direction dir,
+ int use_trx, int *trx_no_)
+{
+ int tfi;
+ uint8_t trx_no;
+
+ if (use_trx == -1 && ms->current_trx())
+ use_trx = ms->current_trx()->trx_no;
+
+ tfi = bts->tfi_find_free(dir, &trx_no, use_trx);
+ if (tfi < 0)
+ return -EBUSY;
+
+ if (trx_no_)
+ *trx_no_ = trx_no;
+
+ return tfi;
+}
/* Slot Allocation: Algorithm A
*
@@ -284,11 +302,14 @@ static void assign_dlink_tbf(
*/
int alloc_algorithm_a(struct gprs_rlcmac_bts *bts,
GprsMs *ms,
- struct gprs_rlcmac_tbf *tbf, uint32_t cust, uint8_t single)
+ struct gprs_rlcmac_tbf *tbf, uint32_t cust, uint8_t single,
+ int use_trx)
{
struct gprs_rlcmac_pdch *pdch;
int ts = -1;
uint8_t ul_slots, dl_slots;
+ int trx_no;
+ int rc;
int usf = -1;
int mask = 0xff;
const char *mask_reason = NULL;
@@ -296,6 +317,14 @@ int alloc_algorithm_a(struct gprs_rlcmac_bts *bts,
LOGP(DRLCMAC, LOGL_DEBUG, "Slot Allocation (Algorithm A) for class "
"%d\n", tbf->ms_class());
+ rc = tfi_find_free(bts->bts, ms, tbf->direction, use_trx, &trx_no);
+ if (rc < 0) {
+ LOGP(DRLCMAC, LOGL_NOTICE, "- Failed to allocate a TFI\n");
+ return rc;
+ }
+ tbf->m_tfi = rc;
+ tbf->trx = &bts->trx[trx_no];
+
dl_slots = ms->reserved_dl_slots();
ul_slots = ms->reserved_ul_slots();
@@ -348,7 +377,6 @@ int alloc_algorithm_a(struct gprs_rlcmac_bts *bts,
ms->set_reserved_slots(tbf->trx, 1 << ts, 1 << ts);
tbf->upgrade_to_multislot = 0;
-
return 0;
}
@@ -669,7 +697,7 @@ static int find_multi_slots(struct gprs_rlcmac_bts *bts,
*/
int alloc_algorithm_b(struct gprs_rlcmac_bts *bts,
GprsMs *ms,
- struct gprs_rlcmac_tbf *tbf, uint32_t cust, uint8_t single)
+ struct gprs_rlcmac_tbf *tbf, uint32_t cust, uint8_t single, int use_trx)
{
uint8_t dl_slots = 0;
uint8_t ul_slots = 0;
@@ -679,6 +707,15 @@ int alloc_algorithm_b(struct gprs_rlcmac_bts *bts,
char slot_info[9] = {0};
int ts;
int rc;
+ int trx_no;
+
+ rc = tfi_find_free(bts->bts, ms, tbf->direction, use_trx, &trx_no);
+ if (rc < 0) {
+ LOGP(DRLCMAC, LOGL_NOTICE, "- Failed to allocate a TFI\n");
+ return rc;
+ }
+ tbf->m_tfi = rc;
+ tbf->trx = &bts->trx[trx_no];
if (!ms) {
LOGP(DRLCMAC, LOGL_ERROR, "MS not set\n");
diff --git a/src/tbf.cpp b/src/tbf.cpp
index 4a8fd337..70483e35 100644
--- a/src/tbf.cpp
+++ b/src/tbf.cpp
@@ -174,20 +174,12 @@ gprs_rlcmac_ul_tbf *tbf_alloc_ul(struct gprs_rlcmac_bts *bts,
int8_t use_trx, uint8_t ms_class,
uint32_t tlli, uint8_t ta, GprsMs *ms)
{
- uint8_t trx;
struct gprs_rlcmac_ul_tbf *tbf;
- int8_t tfi; /* must be signed */
#warning "Copy and paste with tbf_new_dl_assignment"
/* create new TBF, use same TRX as DL TBF */
- tfi = bts->bts->tfi_find_free(GPRS_RLCMAC_UL_TBF, &trx, use_trx);
- if (tfi < 0) {
- LOGP(DRLCMAC, LOGL_NOTICE, "No PDCH resource\n");
- /* FIXME: send reject */
- return NULL;
- }
/* use multislot class of downlink TBF */
- tbf = tbf_alloc_ul_tbf(bts, ms, tfi, trx, ms_class, 0);
+ tbf = tbf_alloc_ul_tbf(bts, ms, use_trx, ms_class, 0);
if (!tbf) {
LOGP(DRLCMAC, LOGL_NOTICE, "No PDCH resource\n");
/* FIXME: send reject */
@@ -274,7 +266,8 @@ int gprs_rlcmac_tbf::update()
return -EINVAL;
tbf_unlink_pdch(this);
- rc = bts_data->alloc_algorithm(bts_data, ms(), this, bts_data->alloc_algorithm_curst, 0);
+ rc = bts_data->alloc_algorithm(bts_data, ms(), this,
+ bts_data->alloc_algorithm_curst, 0, -1);
/* if no resource */
if (rc < 0) {
LOGP(DRLCMAC, LOGL_ERROR, "No resource after update???\n");
@@ -445,14 +438,11 @@ void gprs_rlcmac_tbf::poll_timeout()
}
static int setup_tbf(struct gprs_rlcmac_tbf *tbf, struct gprs_rlcmac_bts *bts,
- GprsMs *ms, uint8_t tfi, uint8_t trx,
+ GprsMs *ms, int8_t use_trx,
uint8_t ms_class, uint8_t single_slot)
{
int rc;
- if (trx >= 8 || tfi >= 32)
- return -1;
-
if (!tbf)
return -1;
@@ -461,12 +451,10 @@ static int setup_tbf(struct gprs_rlcmac_tbf *tbf, struct gprs_rlcmac_bts *bts,
tbf->m_created_ts = time(NULL);
tbf->bts = bts->bts;
- tbf->m_tfi = tfi;
- tbf->trx = &bts->trx[trx];
tbf->set_ms_class(ms_class);
/* select algorithm */
rc = bts->alloc_algorithm(bts, ms, tbf, bts->alloc_algorithm_curst,
- single_slot);
+ single_slot, use_trx);
/* if no resource */
if (rc < 0) {
return -1;
@@ -485,23 +473,24 @@ static int setup_tbf(struct gprs_rlcmac_tbf *tbf, struct gprs_rlcmac_bts *bts,
tbf->m_llc.init();
tbf->set_ms(ms);
+ LOGP(DRLCMAC, LOGL_INFO,
+ "Allocated %s: trx = %d, ul_slots = %02x, dl_slots = %02x\n",
+ tbf->name(), tbf->trx->trx_no, tbf->ul_slots(), tbf->dl_slots());
+
return 0;
}
struct gprs_rlcmac_ul_tbf *tbf_alloc_ul_tbf(struct gprs_rlcmac_bts *bts,
- GprsMs *ms, uint8_t tfi, uint8_t trx,
+ GprsMs *ms, int8_t use_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;
+ LOGP(DRLCMAC, LOGL_INFO, "Allocating %s TBF: MS_CLASS=%d\n",
+ "UL", ms_class);
tbf = talloc_zero(tall_pcu_ctx, struct gprs_rlcmac_ul_tbf);
@@ -513,7 +502,7 @@ struct gprs_rlcmac_ul_tbf *tbf_alloc_ul_tbf(struct gprs_rlcmac_bts *bts,
if (!ms)
ms = bts->bts->ms_alloc(ms_class);
- rc = setup_tbf(tbf, bts, ms, tfi, trx, ms_class, single_slot);
+ rc = setup_tbf(tbf, bts, ms, use_trx, ms_class, single_slot);
/* if no resource */
if (rc < 0) {
talloc_free(tbf);
@@ -527,18 +516,15 @@ struct gprs_rlcmac_ul_tbf *tbf_alloc_ul_tbf(struct gprs_rlcmac_bts *bts,
}
struct gprs_rlcmac_dl_tbf *tbf_alloc_dl_tbf(struct gprs_rlcmac_bts *bts,
- GprsMs *ms, uint8_t tfi, uint8_t trx,
+ GprsMs *ms, int8_t use_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;
+ LOGP(DRLCMAC, LOGL_INFO, "Allocating %s TBF: MS_CLASS=%d\n",
+ "DL", ms_class);
tbf = talloc_zero(tall_pcu_ctx, struct gprs_rlcmac_dl_tbf);
@@ -550,7 +536,7 @@ struct gprs_rlcmac_dl_tbf *tbf_alloc_dl_tbf(struct gprs_rlcmac_bts *bts,
if (!ms)
ms = bts->bts->ms_alloc(ms_class);
- rc = setup_tbf(tbf, bts, ms, tfi, trx, ms_class, single_slot);
+ rc = setup_tbf(tbf, bts, ms, use_trx, ms_class, single_slot);
/* if no resource */
if (rc < 0) {
talloc_free(tbf);
diff --git a/src/tbf.h b/src/tbf.h
index 7f1dd765..5c198d3e 100644
--- a/src/tbf.h
+++ b/src/tbf.h
@@ -245,12 +245,11 @@ struct gprs_rlcmac_ul_tbf *tbf_alloc_ul(struct gprs_rlcmac_bts *bts,
uint32_t tlli, uint8_t ta, GprsMs *ms);
struct gprs_rlcmac_ul_tbf *tbf_alloc_ul_tbf(struct gprs_rlcmac_bts *bts,
- GprsMs *ms,
- uint8_t tfi, uint8_t trx,
+ GprsMs *ms, int8_t use_trx,
uint8_t ms_class, uint8_t single_slot);
struct gprs_rlcmac_dl_tbf *tbf_alloc_dl_tbf(struct gprs_rlcmac_bts *bts,
- GprsMs *ms, uint8_t tfi, uint8_t trx,
+ GprsMs *ms, int8_t use_trx,
uint8_t ms_class, uint8_t single_slot);
void tbf_free(struct gprs_rlcmac_tbf *tbf);
diff --git a/src/tbf_dl.cpp b/src/tbf_dl.cpp
index cf03d331..cdd02bae 100644
--- a/src/tbf_dl.cpp
+++ b/src/tbf_dl.cpp
@@ -139,12 +139,11 @@ static int tbf_new_dl_assignment(struct gprs_rlcmac_bts *bts,
const uint8_t ms_class,
struct gprs_rlcmac_dl_tbf **tbf)
{
- uint8_t trx, ss;
+ uint8_t ss;
int8_t use_trx;
uint16_t ta = 0;
struct gprs_rlcmac_ul_tbf *ul_tbf = NULL, *old_ul_tbf;
struct gprs_rlcmac_dl_tbf *dl_tbf = NULL;
- int8_t tfi; /* must be signed */
GprsMs *ms;
/* check for uplink data, so we copy our informations */
@@ -170,10 +169,8 @@ static int tbf_new_dl_assignment(struct gprs_rlcmac_bts *bts,
// Create new TBF (any TRX)
#warning "Copy and paste with alloc_ul_tbf"
- tfi = bts->bts->tfi_find_free(GPRS_RLCMAC_DL_TBF, &trx, use_trx);
- if (tfi >= 0)
- /* set number of downlink slots according to multislot class */
- dl_tbf = tbf_alloc_dl_tbf(bts, ms, tfi, trx, ms_class, ss);
+ /* set number of downlink slots according to multislot class */
+ dl_tbf = tbf_alloc_dl_tbf(bts, ms, use_trx, ms_class, ss);
if (!dl_tbf) {
LOGP(DRLCMAC, LOGL_NOTICE, "No PDCH resource\n");
@@ -842,16 +839,12 @@ int gprs_rlcmac_dl_tbf::rcvd_dl_ack(uint8_t final_ack, uint8_t ssn, uint8_t *rbb
void gprs_rlcmac_dl_tbf::reuse_tbf()
{
- uint8_t trx;
struct gprs_rlcmac_dl_tbf *new_tbf = NULL;
- int8_t tfi; /* must be signed */
bts->tbf_reused();
- tfi = bts->tfi_find_free(GPRS_RLCMAC_DL_TBF, &trx, this->trx->trx_no);
- if (tfi >= 0)
- new_tbf = tbf_alloc_dl_tbf(bts->bts_data(), ms(), tfi, trx,
- ms_class(), 0);
+ new_tbf = tbf_alloc_dl_tbf(bts->bts_data(), ms(),
+ this->trx->trx_no, ms_class(), 0);
if (!new_tbf) {
LOGP(DRLCMAC, LOGL_NOTICE, "No PDCH resource\n");