diff options
Diffstat (limited to 'src/bts.cpp')
-rw-r--r-- | src/bts.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/bts.cpp b/src/bts.cpp index cbe6303..cc53f25 100644 --- a/src/bts.cpp +++ b/src/bts.cpp @@ -236,6 +236,61 @@ gprs_rlcmac_tbf *BTS::tbf_by_tfi(uint8_t tfi, uint8_t trx, return NULL; } +/* FIXME: spread resources 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 */ +int BTS::tfi_find_free(enum gprs_rlcmac_tbf_direction dir, + uint8_t *_trx, int8_t use_trx) +{ + struct gprs_rlcmac_pdch *pdch; + 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; + } + + /* on TRX find first enabled TS */ + for (trx = trx_from; trx <= trx_to; trx++) { + for (ts = 0; ts < 8; ts++) { + pdch = &m_bts.trx[trx].pdch[ts]; + if (!pdch->is_enabled()) + continue; + break; + } + if (ts < 8) + break; + } + if (trx > trx_to) { + LOGP(DRLCMAC, LOGL_NOTICE, "No PDCH available.\n"); + return -EINVAL; + } + + + LOGP(DRLCMAC, LOGL_DEBUG, "Searching for first unallocated TFI: " + "TRX=%d first TS=%d\n", trx, ts); + if (dir == GPRS_RLCMAC_UL_TBF) + tbfp = m_bts.trx[trx].ul_tbf; + else + tbfp = m_bts.trx[trx].dl_tbf; + for (tfi = 0; tfi < 32; tfi++) { + if (!tbfp[tfi]) + break; + } + + if (tfi < 32) { + LOGP(DRLCMAC, LOGL_DEBUG, " Found TFI=%d.\n", tfi); + *_trx = trx; + return tfi; + } + LOGP(DRLCMAC, LOGL_NOTICE, "No TFI available.\n"); + + return -1; +} + /* * PDCH code below. TODO: move to a separate file |