diff options
author | Pau Espin Pedrol <pespin@sysmocom.de> | 2018-11-16 12:59:46 +0100 |
---|---|---|
committer | Pau Espin Pedrol <pespin@sysmocom.de> | 2018-11-20 16:56:28 +0000 |
commit | c8772517d9dc32da7c5e8741155e4ab638c2d01e (patch) | |
tree | 8d33db38323a32f51dc1b81a79151ddd2d92d626 /src/gsm/gsm_utils.c | |
parent | 738782467f70e13b1c6667aceb6747c2f3755f61 (diff) |
gsm: Deprecate buggy gsm_arfcn2band API and introduce gsm_arfcn2band_rc
ARFCNs are values in well defined ranges. Until this patch, ARFCNs not
belonging to any band were blindly assigned to DCS1800 by
gsm_arfcn2band, causing unnoticed bugs and misconfigurations in
osmo-bsc.
Previous API gsm_arfcn2band cannot accomodate this kind of check easily,
so let's deprecate it to tell people to use a new API gsm_arfcn2band_rc
which performs this kind of checks and allows callers to log failures,
misconfigurations, etc.
At the same time, modify implementation of gsm_arfcn2band to abort if an
invalid ARFCN is passed, this way users of this API can notice they are
passing wrong data to it that most probably will produce unexpected
results.
Related: OS#3063
Change-Id: I780d452dcebce385469e32ef2fd844df6033393a
Diffstat (limited to 'src/gsm/gsm_utils.c')
-rw-r--r-- | src/gsm/gsm_utils.c | 71 |
1 files changed, 48 insertions, 23 deletions
diff --git a/src/gsm/gsm_utils.c b/src/gsm/gsm_utils.c index 7e6c7947..8b4b5586 100644 --- a/src/gsm/gsm_utils.c +++ b/src/gsm/gsm_utils.c @@ -706,36 +706,61 @@ enum gsm_band gsm_band_parse(const char* mhz) } } -/*! Resolve GSM band from ARFCN +/*! Resolve GSM band from ARFCN. * In Osmocom, we use the highest bit of the \a arfcn to indicate PCS * \param[in] arfcn Osmocom ARFCN, highest bit determines PCS mode - * \returns GSM Band */ -enum gsm_band gsm_arfcn2band(uint16_t arfcn) + * \param[out] band GSM Band containing \arfcn if arfcn is valid, undetermined otherwise + * \returns 0 if arfcn is valid and \a band was set, negative on error */ +int gsm_arfcn2band_rc(uint16_t arfcn, enum gsm_band *band) { int is_pcs = arfcn & ARFCN_PCS; arfcn &= ~ARFCN_FLAG_MASK; - if (is_pcs) - return GSM_BAND_1900; - else if (arfcn <= 124) - return GSM_BAND_900; - else if (arfcn >= 955 && arfcn <= 1023) - return GSM_BAND_900; - else if (arfcn >= 128 && arfcn <= 251) - return GSM_BAND_850; - else if (arfcn >= 512 && arfcn <= 885) - return GSM_BAND_1800; - else if (arfcn >= 259 && arfcn <= 293) - return GSM_BAND_450; - else if (arfcn >= 306 && arfcn <= 340) - return GSM_BAND_480; - else if (arfcn >= 350 && arfcn <= 425) - return GSM_BAND_810; - else if (arfcn >= 438 && arfcn <= 511) - return GSM_BAND_750; - else - return GSM_BAND_1800; + if (is_pcs) { + *band = GSM_BAND_1900; + return 0; + } else if (arfcn <= 124) { + *band = GSM_BAND_900; + return 0; + } else if (arfcn >= 955 && arfcn <= 1023) { + *band = GSM_BAND_900; + return 0; + } else if (arfcn >= 128 && arfcn <= 251) { + *band = GSM_BAND_850; + return 0; + } else if (arfcn >= 512 && arfcn <= 885) { + *band = GSM_BAND_1800; + return 0; + } else if (arfcn >= 259 && arfcn <= 293) { + *band = GSM_BAND_450; + return 0; + } else if (arfcn >= 306 && arfcn <= 340) { + *band = GSM_BAND_480; + return 0; + } else if (arfcn >= 350 && arfcn <= 425) { + *band = GSM_BAND_810; + return 0; + } else if (arfcn >= 438 && arfcn <= 511) { + *band = GSM_BAND_750; + return 0; + } + return -1; +} + +/*! Resolve GSM band from ARFCN, aborts process on invalid ARFCN. + * In Osmocom, we use the highest bit of the \a arfcn to indicate PCS. + * DEPRECATED: Use gsm_arfcn2band_rc instead. + * \param[in] arfcn Osmocom ARFCN, highest bit determines PCS mode + * \returns GSM Band if ARFCN is valid (part of any valid band), aborts otherwise */ +enum gsm_band gsm_arfcn2band(uint16_t arfcn) +{ + enum gsm_band band; + if (gsm_arfcn2band_rc(arfcn, &band) == 0) + return band; + + osmo_panic("%s:%d Invalid arfcn %" PRIu16 " passed to gsm_arfcn2band\n", + __FILE__, __LINE__, arfcn); } struct gsm_freq_range { |