aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src/libbsc/abis_rsl.c
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2016-07-23 17:38:22 +0200
committerNeels Hofmeyr <neels@hofmeyr.de>2016-07-25 17:35:47 +0200
commit745857277cd24fadcd27d54aaa402bd82090cc86 (patch)
treed96de2120f17dd4950694afde73a272534cd68bd /openbsc/src/libbsc/abis_rsl.c
parent34b8b5b29b72e245cc159ed4b035f6377988b762 (diff)
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
Diffstat (limited to 'openbsc/src/libbsc/abis_rsl.c')
-rw-r--r--openbsc/src/libbsc/abis_rsl.c52
1 files changed, 10 insertions, 42 deletions
diff --git a/openbsc/src/libbsc/abis_rsl.c b/openbsc/src/libbsc/abis_rsl.c
index 0a2c114f4..baefd54f6 100644
--- a/openbsc/src/libbsc/abis_rsl.c
+++ b/openbsc/src/libbsc/abis_rsl.c
@@ -106,53 +106,21 @@ static inline void init_dchan_hdr(struct abis_rsl_dchan_hdr *dh,
dh->ie_chan = RSL_IE_CHAN_NR;
}
-/* determine logical channel based on TRX and channel number IE */
-struct gsm_lchan *lchan_lookup(struct gsm_bts_trx *trx, uint8_t chan_nr)
+/* call rsl_lchan_lookup and set the log context */
+static struct gsm_lchan *lchan_lookup(struct gsm_bts_trx *trx, uint8_t chan_nr)
{
- struct gsm_lchan *lchan;
- 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];
-
- 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)
- 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 {
+ int rc;
+ struct gsm_lchan *lchan = rsl_lchan_lookup(trx, chan_nr, &rc);
+
+ if (!lchan) {
LOGP(DRSL, LOGL_ERROR, "unknown chan_nr=0x%02x\n", chan_nr);
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);
if (lchan->conn)
log_set_context(BSC_CTX_SUBSCR, lchan->conn->subscr);