From 35b263240f12b7d3b1c62c26b91fa555935c5703 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Mon, 31 Jul 2017 19:36:52 +0200 Subject: Add osmo_gprs_{ul,dl}_block_size_{bits,bytes} functions Those functions can be used to look up the size of (E)GPRS blocks. Change-Id: I05ff75ef7dfae639886bbd09fe35f03a8af9d988 --- src/gsm/gprs_rlc.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/gsm/libosmogsm.map | 6 ++++ 2 files changed, 96 insertions(+) (limited to 'src') diff --git a/src/gsm/gprs_rlc.c b/src/gsm/gprs_rlc.c index b213b269..d2c05b70 100644 --- a/src/gsm/gprs_rlc.c +++ b/src/gsm/gprs_rlc.c @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -109,3 +110,92 @@ int egprs_get_cps(struct egprs_cps *cps, uint8_t type, uint8_t bits) return 0; } + +struct gprs_cs_desc { + struct { + uint8_t bytes; + uint8_t bits; + } uplink, downlink; +}; + +const struct gprs_cs_desc gprs_cs_desc[_NUM_OSMO_GPRS_CS] = { + [OSMO_GPRS_CS1] = { {23, 0}, {23, 0} }, + [OSMO_GPRS_CS2] = { {33, 7}, {33, 7} }, + [OSMO_GPRS_CS3] = { {39, 3}, {39, 3} }, + [OSMO_GPRS_CS4] = { {53, 7}, {53, 7} }, + + [OSMO_GPRS_MCS1] = { {26, 1}, {26, 1} }, + [OSMO_GPRS_MCS2] = { {32, 1}, {32, 1} }, + [OSMO_GPRS_MCS3] = { {41, 1}, {41, 1} }, + [OSMO_GPRS_MCS4] = { {48, 1}, {48, 1} }, + + [OSMO_GPRS_MCS5] = { {60, 7}, {59, 6} }, + [OSMO_GPRS_MCS6] = { {78, 7}, {77, 6} }, + [OSMO_GPRS_MCS7] = { {118, 2}, {117, 4} }, + [OSMO_GPRS_MCS8] = { {142, 2}, {141, 4} }, + [OSMO_GPRS_MCS9] = { {154, 2}, {153, 4} }, +}; + +/*! Return size of (E)GPRS uplink block for given coding scheme in bits */ +int osmo_gprs_ul_block_size_bits(enum osmo_gprs_cs cs) +{ + if (cs >= ARRAY_SIZE(gprs_cs_desc)) + return -EINVAL; + return gprs_cs_desc[cs].uplink.bytes * 8 + gprs_cs_desc[cs].uplink.bits; +} + +/*! Return size of (E)GPRS downlink block for given coding scheme in bits */ +int osmo_gprs_dl_block_size_bits(enum osmo_gprs_cs cs) +{ + if (cs >= ARRAY_SIZE(gprs_cs_desc)) + return -EINVAL; + return gprs_cs_desc[cs].downlink.bytes * 8 + gprs_cs_desc[cs].downlink.bits; +} + +/*! Return size of (E)GPRS uplink block for given coding scheme in bytes */ +int osmo_gprs_ul_block_size_bytes(enum osmo_gprs_cs cs) +{ + int rc; + if (cs >= ARRAY_SIZE(gprs_cs_desc)) + return -EINVAL; + rc = gprs_cs_desc[cs].uplink.bytes; + if (gprs_cs_desc[cs].uplink.bits) + rc++; + return rc; +} + +/*! Return size of (E)GPRS downlink block for given coding scheme in bytes */ +int osmo_gprs_dl_block_size_bytes(enum osmo_gprs_cs cs) +{ + int rc; + if (cs >= ARRAY_SIZE(gprs_cs_desc)) + return -EINVAL; + rc = gprs_cs_desc[cs].downlink.bytes; + if (gprs_cs_desc[cs].downlink.bits) + rc++; + return rc; +} + +/*! Return coding scheme for given (E)GPRS uplink block size */ +enum osmo_gprs_cs osmo_gprs_ul_cs_by_block_bytes(uint8_t block_size) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(gprs_cs_desc); i++) { + if (block_size == osmo_gprs_ul_block_size_bytes(i)) + return i; + } + return OSMO_GPRS_CS_NONE; +} + +/*! Return coding scheme for given (E)GPRS downlink block size */ +enum osmo_gprs_cs osmo_gprs_dl_cs_by_block_bytes(uint8_t block_size) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(gprs_cs_desc); i++) { + if (block_size == osmo_gprs_dl_block_size_bytes(i)) + return i; + } + return OSMO_GPRS_CS_NONE; +} diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map index 714cb25f..066f4107 100644 --- a/src/gsm/libosmogsm.map +++ b/src/gsm/libosmogsm.map @@ -65,6 +65,12 @@ gprs_ms_net_cap_gea_supported; gprs_msgt_gmm_names; egprs_get_cps; +osmo_gprs_ul_block_size_bits; +osmo_gprs_dl_block_size_bits; +osmo_gprs_ul_block_size_bytes; +osmo_gprs_dl_block_size_bytes; +osmo_gprs_ul_cs_by_block_bytes; +osmo_gprs_dl_cs_by_block_bytes; gsm48_gmm_cause_names; gsm48_gsm_cause_names; -- cgit v1.2.3