code dup: join [rsl_]lchan_lookup() from libbsc and osmo-bts
lchan_lookup in abis_rsl.c and rsl_lchan_lookup() from osmo-bts rsl.c are the same code, except for the log context, which is only set in abis_rsl.c. Factor out the common code to rsl_lchan_lookup() in gsm_data_shared.c. Openbsc and osmo-bts each define their own DRSL log constant, so add an int *rc return code argument and keep the logging part in abis_rsl.c's thin lchan_lookup() wrapper. Incidentally, this also removes code dup for logging. To avoid duplicate symbols, the rsl_lchan_lookup() implementation needs to be removed from osmo-bts, so older osmo-bts git revisions will not build with this. Change-Id: Ie89bc5bb9110a0e539d37991dedac6f913211b48
This commit is contained in:
parent
34b8b5b29b
commit
745857277c
|
@ -844,5 +844,7 @@ static inline uint8_t gsm_ts_tsc(const struct gsm_bts_trx_ts *ts)
|
||||||
return ts->trx->bts->bsic & 7;
|
return ts->trx->bts->bsic & 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct gsm_lchan *rsl_lchan_lookup(struct gsm_bts_trx *trx, uint8_t chan_nr,
|
||||||
|
int *rc);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -106,53 +106,21 @@ static inline void init_dchan_hdr(struct abis_rsl_dchan_hdr *dh,
|
||||||
dh->ie_chan = RSL_IE_CHAN_NR;
|
dh->ie_chan = RSL_IE_CHAN_NR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* determine logical channel based on TRX and channel number IE */
|
/* call rsl_lchan_lookup and set the log context */
|
||||||
struct gsm_lchan *lchan_lookup(struct gsm_bts_trx *trx, uint8_t chan_nr)
|
static struct gsm_lchan *lchan_lookup(struct gsm_bts_trx *trx, uint8_t chan_nr)
|
||||||
{
|
{
|
||||||
struct gsm_lchan *lchan;
|
int rc;
|
||||||
uint8_t ts_nr = chan_nr & 0x07;
|
struct gsm_lchan *lchan = rsl_lchan_lookup(trx, chan_nr, &rc);
|
||||||
uint8_t cbits = chan_nr >> 3;
|
|
||||||
uint8_t lch_idx;
|
|
||||||
struct gsm_bts_trx_ts *ts = &trx->ts[ts_nr];
|
|
||||||
|
|
||||||
if (cbits == 0x01) {
|
if (!lchan) {
|
||||||
lch_idx = 0; /* TCH/F */
|
|
||||||
if (ts->pchan != GSM_PCHAN_TCH_F &&
|
|
||||||
ts->pchan != GSM_PCHAN_PDCH &&
|
|
||||||
ts->pchan != GSM_PCHAN_TCH_F_PDCH)
|
|
||||||
LOGP(DRSL, LOGL_ERROR, "chan_nr=0x%02x but pchan=%u\n",
|
|
||||||
chan_nr, ts->pchan);
|
|
||||||
} else if ((cbits & 0x1e) == 0x02) {
|
|
||||||
lch_idx = cbits & 0x1; /* TCH/H */
|
|
||||||
if (ts->pchan != GSM_PCHAN_TCH_H)
|
|
||||||
LOGP(DRSL, LOGL_ERROR, "chan_nr=0x%02x but pchan=%u\n",
|
|
||||||
chan_nr, ts->pchan);
|
|
||||||
} else if ((cbits & 0x1c) == 0x04) {
|
|
||||||
lch_idx = cbits & 0x3; /* SDCCH/4 */
|
|
||||||
if (ts->pchan != GSM_PCHAN_CCCH_SDCCH4 &&
|
|
||||||
ts->pchan != GSM_PCHAN_CCCH_SDCCH4_CBCH)
|
|
||||||
LOGP(DRSL, LOGL_ERROR, "chan_nr=0x%02x but pchan=%u\n",
|
|
||||||
chan_nr, ts->pchan);
|
|
||||||
} else if ((cbits & 0x18) == 0x08) {
|
|
||||||
lch_idx = cbits & 0x7; /* SDCCH/8 */
|
|
||||||
if (ts->pchan != GSM_PCHAN_SDCCH8_SACCH8C &&
|
|
||||||
ts->pchan != GSM_PCHAN_SDCCH8_SACCH8C_CBCH)
|
|
||||||
LOGP(DRSL, LOGL_ERROR, "chan_nr=0x%02x but pchan=%u\n",
|
|
||||||
chan_nr, ts->pchan);
|
|
||||||
} else if (cbits == 0x10 || cbits == 0x11 || cbits == 0x12) {
|
|
||||||
lch_idx = 0;
|
|
||||||
if (ts->pchan != GSM_PCHAN_CCCH &&
|
|
||||||
ts->pchan != GSM_PCHAN_CCCH_SDCCH4 &&
|
|
||||||
ts->pchan != GSM_PCHAN_CCCH_SDCCH4_CBCH)
|
|
||||||
LOGP(DRSL, LOGL_ERROR, "chan_nr=0x%02x but pchan=%u\n",
|
|
||||||
chan_nr, ts->pchan);
|
|
||||||
/* FIXME: we should not return first sdcch4 !!! */
|
|
||||||
} else {
|
|
||||||
LOGP(DRSL, LOGL_ERROR, "unknown chan_nr=0x%02x\n", chan_nr);
|
LOGP(DRSL, LOGL_ERROR, "unknown chan_nr=0x%02x\n", chan_nr);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
lchan = &ts->lchan[lch_idx];
|
if (rc < 0)
|
||||||
|
LOGP(DRSL, LOGL_ERROR, "%s mismatching chan_nr=0x%02x\n",
|
||||||
|
gsm_ts_and_pchan_name(lchan->ts), chan_nr);
|
||||||
|
|
||||||
log_set_context(BSC_CTX_LCHAN, lchan);
|
log_set_context(BSC_CTX_LCHAN, lchan);
|
||||||
if (lchan->conn)
|
if (lchan->conn)
|
||||||
log_set_context(BSC_CTX_SUBSCR, lchan->conn->subscr);
|
log_set_context(BSC_CTX_SUBSCR, lchan->conn->subscr);
|
||||||
|
|
|
@ -612,3 +612,52 @@ struct gsm_lchan *gsm_bts_get_cbch(struct gsm_bts *bts)
|
||||||
|
|
||||||
return lchan;
|
return lchan;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* determine logical channel based on TRX and channel number IE */
|
||||||
|
struct gsm_lchan *rsl_lchan_lookup(struct gsm_bts_trx *trx, uint8_t chan_nr,
|
||||||
|
int *rc)
|
||||||
|
{
|
||||||
|
uint8_t ts_nr = chan_nr & 0x07;
|
||||||
|
uint8_t cbits = chan_nr >> 3;
|
||||||
|
uint8_t lch_idx;
|
||||||
|
struct gsm_bts_trx_ts *ts = &trx->ts[ts_nr];
|
||||||
|
bool ok = true;
|
||||||
|
|
||||||
|
if (rc)
|
||||||
|
*rc = -EINVAL;
|
||||||
|
|
||||||
|
if (cbits == 0x01) {
|
||||||
|
lch_idx = 0; /* TCH/F */
|
||||||
|
if (ts->pchan != GSM_PCHAN_TCH_F &&
|
||||||
|
ts->pchan != GSM_PCHAN_PDCH &&
|
||||||
|
ts->pchan != GSM_PCHAN_TCH_F_PDCH)
|
||||||
|
ok = false;
|
||||||
|
} else if ((cbits & 0x1e) == 0x02) {
|
||||||
|
lch_idx = cbits & 0x1; /* TCH/H */
|
||||||
|
if (ts->pchan != GSM_PCHAN_TCH_H)
|
||||||
|
ok = false;
|
||||||
|
} else if ((cbits & 0x1c) == 0x04) {
|
||||||
|
lch_idx = cbits & 0x3; /* SDCCH/4 */
|
||||||
|
if (ts->pchan != GSM_PCHAN_CCCH_SDCCH4 &&
|
||||||
|
ts->pchan != GSM_PCHAN_CCCH_SDCCH4_CBCH)
|
||||||
|
ok = false;
|
||||||
|
} else if ((cbits & 0x18) == 0x08) {
|
||||||
|
lch_idx = cbits & 0x7; /* SDCCH/8 */
|
||||||
|
if (ts->pchan != GSM_PCHAN_SDCCH8_SACCH8C &&
|
||||||
|
ts->pchan != GSM_PCHAN_SDCCH8_SACCH8C_CBCH)
|
||||||
|
ok = false;
|
||||||
|
} else if (cbits == 0x10 || cbits == 0x11 || cbits == 0x12) {
|
||||||
|
lch_idx = 0;
|
||||||
|
if (ts->pchan != GSM_PCHAN_CCCH &&
|
||||||
|
ts->pchan != GSM_PCHAN_CCCH_SDCCH4 &&
|
||||||
|
ts->pchan != GSM_PCHAN_CCCH_SDCCH4_CBCH)
|
||||||
|
ok = false;
|
||||||
|
/* FIXME: we should not return first sdcch4 !!! */
|
||||||
|
} else
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (rc && ok)
|
||||||
|
*rc = 0;
|
||||||
|
|
||||||
|
return &ts->lchan[lch_idx];
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue