encoding: Redesign Encoding::write_immediate_assignment API

The EGPRS support will need more information to encode the IMMEDIATE
ASSIGMENT. Instead of adding more parameters pass a pointer to the
TBF unless an SBA shall be done (indicated by tbf == NULL). All
values that can be derived from the TBF and are not needed for an SBA
are removed from the parameter list.

Return a negative value on error.

Sponsored-by: On-Waves ehf
This commit is contained in:
Jacob Erlbeck 2016-02-01 16:13:38 +01:00
parent 18831c3ca9
commit 2647a337a8
4 changed files with 62 additions and 42 deletions

View File

@ -466,8 +466,7 @@ int BTS::rcv_rach(uint8_t ra, uint32_t Fn, int16_t qta)
uint8_t sb = 0;
uint32_t sb_fn = 0;
int rc;
uint8_t plen;
uint8_t tfi = 0;
int plen;
uint8_t usf = 7;
uint8_t tsc;
uint16_t ta;
@ -528,7 +527,6 @@ int BTS::rcv_rach(uint8_t ra, uint32_t Fn, int16_t qta)
"Assignment Uplink (AGCH)\n", tbf_name(tbf));
trx_no = tbf->trx->trx_no;
ts_no = tbf->first_ts;
tfi = tbf->tfi();
usf = tbf->m_usf[ts_no];
tsc = tbf->tsc();
}
@ -538,14 +536,17 @@ int BTS::rcv_rach(uint8_t ra, uint32_t Fn, int16_t qta)
LOGP(DRLCMAC, LOGL_DEBUG,
" - TRX=%d (%d) TS=%d TA=%d TSC=%d TFI=%d USF=%d\n",
trx_no, m_bts.trx[trx_no].arfcn, ts_no, ta, tsc, tfi, usf);
trx_no, m_bts.trx[trx_no].arfcn, ts_no, ta, tsc,
tbf ? tbf->tfi() : -1, usf);
plen = Encoding::write_immediate_assignment(
&m_bts, immediate_assignment, 0, ra, Fn, ta,
m_bts.trx[trx_no].arfcn, ts_no, tsc, tfi, usf, 0, 0, sb_fn, sb,
tbf, immediate_assignment, 0, ra, Fn, ta,
m_bts.trx[trx_no].arfcn, ts_no, tsc, usf, 0, sb_fn,
m_bts.alpha, m_bts.gamma, -1);
pcu_l1if_tx_agch(immediate_assignment, plen);
if (plen >= 0)
pcu_l1if_tx_agch(immediate_assignment, plen);
bitvec_free(immediate_assignment);
return 0;
@ -598,11 +599,12 @@ void BTS::snd_dl_ass(gprs_rlcmac_tbf *tbf, uint8_t poll, const char *imsi)
LOGP(DRLCMAC, LOGL_DEBUG, " - TRX=%d (%d) TS=%d TA=%d pollFN=%d\n",
tbf->trx->trx_no, tbf->trx->arfcn,
ts, tbf->ta(), poll ? tbf->poll_fn : -1);
plen = Encoding::write_immediate_assignment(&m_bts, immediate_assignment, 1, 125,
plen = Encoding::write_immediate_assignment(tbf, immediate_assignment, 1, 125,
(tbf->pdch[ts]->last_rts_fn + 21216) % 2715648, tbf->ta(),
tbf->trx->arfcn, ts, tbf->tsc(), tbf->tfi(), 7, tbf->tlli(), poll,
tbf->poll_fn, 0, m_bts.alpha, m_bts.gamma, -1);
pcu_l1if_tx_pch(immediate_assignment, plen, imsi);
tbf->trx->arfcn, ts, tbf->tsc(), 7, poll,
tbf->poll_fn, m_bts.alpha, m_bts.gamma, -1);
if (plen >= 0)
pcu_l1if_tx_pch(immediate_assignment, plen, imsi);
bitvec_free(immediate_assignment);
}

View File

@ -28,17 +28,23 @@
#include <errno.h>
#include <string.h>
static void write_ia_rest_downlink(
static int write_ia_rest_downlink(
gprs_rlcmac_dl_tbf *tbf,
bitvec * dest, unsigned& wp,
uint8_t tfi, uint32_t tlli, uint8_t polling,
uint32_t fn, uint8_t alpha, uint8_t gamma, int8_t ta_idx)
uint8_t polling, uint32_t fn,
uint8_t alpha, uint8_t gamma, int8_t ta_idx)
{
if (!tbf) {
LOGP(DRLCMACDL, LOGL_ERROR,
"Cannot encode DL IMMEDIATE ASSIGNMENT without TBF\n");
return -EINVAL;
}
// GSM 04.08 10.5.2.16 IA Rest Octets
bitvec_write_field_lh(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,tbf->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,tbf->tfi(),5); // TFI
bitvec_write_field(dest, wp,0x0,1); // RLC acknowledged mode
if (alpha) {
bitvec_write_field(dest, wp,0x1,1); // ALPHA = present
@ -66,17 +72,20 @@ static void write_ia_rest_downlink(
bitvec_write_field(dest, wp,0x0,1); // P0 not present
// bitvec_write_field(dest, wp,0x1,1); // P0 not present
// bitvec_write_field(dest, wp,0xb,4);
return 0;
}
static void write_ia_rest_uplink(
struct gprs_rlcmac_bts *bts, bitvec * dest, unsigned& wp,
uint8_t tfi, uint8_t usf, uint32_t fn, uint8_t single_block,
static int write_ia_rest_uplink(
gprs_rlcmac_ul_tbf *tbf,
bitvec * dest, unsigned& wp,
uint8_t usf, uint32_t fn,
uint8_t alpha, uint8_t gamma, int8_t ta_idx)
{
// GMS 04.08 10.5.2.37b 10.5.2.16
bitvec_write_field_lh(dest, wp, 3, 2); // "HH"
bitvec_write_field(dest, wp, 0, 2); // "0" Packet Uplink Assignment
if (single_block) {
if (tbf == NULL) {
bitvec_write_field(dest, wp, 0, 1); // Block Allocation : Single Block Allocation
if (alpha) {
bitvec_write_field(dest, wp,0x1,1); // ALPHA = present
@ -96,13 +105,13 @@ static void write_ia_rest_uplink(
bitvec_write_field(dest, wp,fn % 26,5); // T2
} else {
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, tbf->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
bitvec_write_field(dest, wp, usf, 3); // USF
bitvec_write_field(dest, wp, 0, 1); // USF_GRANULARITY
bitvec_write_field(dest, wp, 0, 1); // "0" power control: Not Present
bitvec_write_field(dest, wp, bts->initial_cs_ul-1, 2); // CHANNEL_CODING_COMMAND
bitvec_write_field(dest, wp, tbf->current_cs().to_num()-1, 2); // CHANNEL_CODING_COMMAND
bitvec_write_field(dest, wp, 1, 1); // TLLI_BLOCK_CHANNEL_CODING
if (alpha) {
bitvec_write_field(dest, wp,0x1,1); // ALPHA = present
@ -114,6 +123,7 @@ static void write_ia_rest_uplink(
bitvec_write_field(dest, wp, 0, 1); // switch TIMING_ADVANCE_INDEX = off
bitvec_write_field(dest, wp, 0, 1); // TBF_STARTING_TIME_FLAG
}
return 0;
}
/*
@ -121,15 +131,15 @@ static void write_ia_rest_uplink(
* see GSM 04.08, 9.1.18 and GSM 44.018, 9.1.18 + 10.5.2.16
*/
int Encoding::write_immediate_assignment(
struct gprs_rlcmac_bts *bts,
struct gprs_rlcmac_tbf *tbf,
bitvec * dest, uint8_t downlink, uint8_t ra,
uint32_t ref_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 fn, uint8_t single_block, uint8_t alpha,
uint8_t usf, uint8_t polling, uint32_t fn, uint8_t alpha,
uint8_t gamma, int8_t ta_idx)
{
unsigned wp = 0;
uint8_t plen;
int plen;
int rc;
bitvec_write_field(dest, wp,0x0,4); // Skip Indicator
bitvec_write_field(dest, wp,0x6,4); // Protocol Discriminator
@ -172,14 +182,22 @@ int Encoding::write_immediate_assignment(
plen = wp / 8;
if (downlink)
write_ia_rest_downlink(dest, wp,
tfi, tlli, polling, fn,
rc = write_ia_rest_downlink(as_dl_tbf(tbf), dest, wp,
polling, fn,
alpha, gamma, ta_idx);
else
write_ia_rest_uplink(bts, dest, wp,
tfi, usf, fn, single_block,
rc = write_ia_rest_uplink(as_ul_tbf(tbf), dest, wp,
usf, fn,
alpha, gamma, ta_idx);
if (rc < 0) {
LOGP(DRLCMAC, LOGL_ERROR,
"Failed to create IMMEDIATE ASSIGMENT (%s) for %s\n",
downlink ? "downlink" : "uplink",
tbf ? tbf->name() : "single block allocation");
return rc;
}
return plen;
}

View File

@ -39,11 +39,11 @@ struct gprs_rlc_data_block_info;
class Encoding {
public:
static int write_immediate_assignment(
struct gprs_rlcmac_bts *bts,
bitvec * dest, uint8_t downlink, uint8_t ra,
uint32_t ref_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 fn, uint8_t single_block, uint8_t alpha, uint8_t gamma,
struct gprs_rlcmac_tbf *tbf,
bitvec * dest, uint8_t downlink, uint8_t ra,
uint32_t ref_fn, uint8_t ta, uint16_t arfcn, uint8_t ts,
uint8_t tsc, uint8_t usf, uint8_t polling,
uint32_t fn, uint8_t alpha, uint8_t gamma,
int8_t ta_idx);
static void write_packet_uplink_assignment(

View File

@ -1522,7 +1522,7 @@ MS requests UL TBF on RACH, so we provide one:
MS requests single block allocation
RX: [PCU <- BTS] RACH qbit-ta=31 ra=0x73, Fn=2654167 (17,25,9), SBFn=2654270
TX: Immediate Assignment Uplink (AGCH)
- TRX=0 (0) TS=7 TA=7 TSC=0 TFI=0 USF=7
- TRX=0 (0) TS=7 TA=7 TSC=0 TFI=-1 USF=7
Sending data request: trx=0 ts=0 sapi=2 arfcn=0 fn=0 block=0 data=2d 06 3f 10 0f 00 00 73 8b 29 07 00 c0 0c 5a 43 2b 2b 2b 2b 2b 2b 2b
Searching for first unallocated TFI: TRX=0
Found TFI=0.
@ -1607,7 +1607,7 @@ MS requests UL TBF on RACH, so we provide one:
MS requests single block allocation
RX: [PCU <- BTS] RACH qbit-ta=31 ra=0x73, Fn=2654167 (17,25,9), SBFn=2654270
TX: Immediate Assignment Uplink (AGCH)
- TRX=0 (0) TS=7 TA=7 TSC=0 TFI=0 USF=7
- TRX=0 (0) TS=7 TA=7 TSC=0 TFI=-1 USF=7
Sending data request: trx=0 ts=0 sapi=2 arfcn=0 fn=0 block=0 data=2d 06 3f 10 0f 00 00 73 8b 29 07 00 c0 0c 5a 43 2b 2b 2b 2b 2b 2b 2b
Searching for first unallocated TFI: TRX=0
Found TFI=0.
@ -1737,7 +1737,7 @@ MS requests UL TBF on RACH, so we provide one:
MS requests single block allocation
RX: [PCU <- BTS] RACH qbit-ta=31 ra=0x73, Fn=2654232 (17,39,22), SBFn=2654335
TX: Immediate Assignment Uplink (AGCH)
- TRX=0 (0) TS=7 TA=7 TSC=0 TFI=0 USF=7
- TRX=0 (0) TS=7 TA=7 TSC=0 TFI=-1 USF=7
Sending data request: trx=0 ts=0 sapi=2 arfcn=0 fn=0 block=0 data=2d 06 3f 10 0f 00 00 73 8c f6 07 00 c0 0c 68 ab 2b 2b 2b 2b 2b 2b 2b
Searching for first unallocated TFI: TRX=0
Found TFI=1.
@ -1813,7 +1813,7 @@ MS requests UL TBF on RACH, so we provide one:
MS requests single block allocation
RX: [PCU <- BTS] RACH qbit-ta=31 ra=0x73, Fn=2654167 (17,25,9), SBFn=2654270
TX: Immediate Assignment Uplink (AGCH)
- TRX=0 (0) TS=7 TA=7 TSC=0 TFI=0 USF=7
- TRX=0 (0) TS=7 TA=7 TSC=0 TFI=-1 USF=7
Sending data request: trx=0 ts=0 sapi=2 arfcn=0 fn=0 block=0 data=2d 06 3f 10 0f 00 00 73 8b 29 07 00 c0 0c 5a 43 2b 2b 2b 2b 2b 2b 2b
Searching for first unallocated TFI: TRX=0
Found TFI=0.
@ -1906,7 +1906,7 @@ MS requests UL TBF on RACH, so we provide one:
MS requests single block allocation
RX: [PCU <- BTS] RACH qbit-ta=31 ra=0x73, Fn=2654224 (17,31,14), SBFn=2654327
TX: Immediate Assignment Uplink (AGCH)
- TRX=0 (0) TS=7 TA=7 TSC=0 TFI=0 USF=7
- TRX=0 (0) TS=7 TA=7 TSC=0 TFI=-1 USF=7
Sending data request: trx=0 ts=0 sapi=2 arfcn=0 fn=0 block=0 data=2d 06 3f 10 0f 00 00 73 8b ee 07 00 c0 0c 60 6b 2b 2b 2b 2b 2b 2b 2b
Searching for first unallocated TFI: TRX=0
Found TFI=0.
@ -1990,7 +1990,7 @@ MS requests UL TBF on RACH, so we provide one:
MS requests single block allocation
RX: [PCU <- BTS] RACH qbit-ta=31 ra=0x73, Fn=2654167 (17,25,9), SBFn=2654270
TX: Immediate Assignment Uplink (AGCH)
- TRX=0 (0) TS=7 TA=7 TSC=0 TFI=0 USF=7
- TRX=0 (0) TS=7 TA=7 TSC=0 TFI=-1 USF=7
Sending data request: trx=0 ts=0 sapi=2 arfcn=0 fn=0 block=0 data=2d 06 3f 10 0f 00 00 73 8b 29 07 00 c0 0c 5a 43 2b 2b 2b 2b 2b 2b 2b
Searching for first unallocated TFI: TRX=0
Found TFI=0.
@ -2144,7 +2144,7 @@ MS requests UL TBF on RACH, so we provide one:
MS requests single block allocation
RX: [PCU <- BTS] RACH qbit-ta=31 ra=0x73, Fn=2654167 (17,25,9), SBFn=2654270
TX: Immediate Assignment Uplink (AGCH)
- TRX=0 (0) TS=7 TA=7 TSC=0 TFI=0 USF=7
- TRX=0 (0) TS=7 TA=7 TSC=0 TFI=-1 USF=7
Sending data request: trx=0 ts=0 sapi=2 arfcn=0 fn=0 block=0 data=2d 06 3f 10 0f 00 00 73 8b 29 07 00 c0 0c 5a 43 2b 2b 2b 2b 2b 2b 2b
Searching for first unallocated TFI: TRX=0
Found TFI=0.