osmocore: Add utility function rsl_chan_nr_str to RSL
authorSylvain Munaut <tnt@246tNt.com>
Sun, 25 Jul 2010 10:25:17 +0000 (12:25 +0200)
committerSylvain Munaut <tnt@246tNt.com>
Sun, 25 Jul 2010 10:27:44 +0000 (12:27 +0200)
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
include/osmocore/rsl.h
src/rsl.c

index cd84057..54d6703 100644 (file)
@@ -17,6 +17,9 @@ extern const struct tlv_definition rsl_att_tlvdef;
 uint8_t rsl_enc_chan_nr(uint8_t type, uint8_t subch, uint8_t timeslot);
 /* decode channel number as per Section 9.3.1 */
 int rsl_dec_chan_nr(uint8_t chan_nr, uint8_t *type, uint8_t *subch, uint8_t *timeslot);
+/* Turns channel number into a string */
+const char *rsl_chan_nr_str(uint8_t chan_nr);
+
 
 const char *rsl_err_name(uint8_t err);
 const char *rsl_rlm_cause_name(uint8_t err);
index 7bc1712..10fba9b 100644 (file)
--- a/src/rsl.c
+++ b/src/rsl.c
@@ -183,6 +183,32 @@ int rsl_dec_chan_nr(uint8_t chan_nr, uint8_t *type, uint8_t *subch, uint8_t *tim
        return 0;
 }
 
+const char *rsl_chan_nr_str(uint8_t chan_nr)
+{
+       static char str[20];
+       int ts = chan_nr & 7;
+       uint8_t cbits = chan_nr >> 3;
+
+       if (cbits == 0x01)
+               sprintf(str, "TCH/F on TS%d", ts);
+       else if ((cbits & 0x1e) == 0x02)
+               sprintf(str, "TCH/H(%u) on TS%d", cbits & 0x01, ts);
+       else if ((cbits & 0x1c) == 0x04)
+               sprintf(str, "SDCCH/4(%u) on TS%d", cbits & 0x03, ts);
+       else if ((cbits & 0x18) == 0x08)
+               sprintf(str, "SDCCH/8(%u) on TS%d", cbits & 0x07, ts);
+       else if (cbits == 0x10)
+               sprintf(str, "BCCH on TS%d", ts);
+       else if (cbits == 0x11)
+               sprintf(str, "RACH on TS%d", ts);
+       else if (cbits == 0x12)
+               sprintf(str, "PCH/AGCH on TS%d", ts);
+       else
+               sprintf(str, "UNKNOWN on TS%d", ts);
+
+        return str;
+}
+
 static const struct value_string rsl_err_vals[] = {
        { RSL_ERR_RADIO_IF_FAIL,        "Radio Interface Failure" },
        { RSL_ERR_RADIO_LINK_FAIL,      "Radio Link Failure" },