move ms_pwr utility function to gsm_utils.c
also, they should both take the gsm_band parameter, not a BTS
diff --git a/openbsc/src/abis_rsl.c b/openbsc/src/abis_rsl.c
index f5a0f6d..9080a6b 100644
--- a/openbsc/src/abis_rsl.c
+++ b/openbsc/src/abis_rsl.c
@@ -30,6 +30,7 @@
#include <openbsc/gsm_data.h>
#include <openbsc/gsm_04_08.h>
+#include <openbsc/gsm_utils.h>
#include <openbsc/abis_rsl.h>
#include <openbsc/chan_alloc.h>
#include <openbsc/bsc_rll.h>
@@ -431,78 +432,6 @@
return abis_rsl_sendmsg(msg);
}
-/* determine power control level for given dBm value, as indicated
- * by the tables in chapter 4.1.1 of GSM TS 05.05 */
-static int ms_pwr_ctl_lvl(struct gsm_bts *bts, unsigned int dbm)
-{
- switch (bts->band) {
- case GSM_BAND_400:
- case GSM_BAND_900:
- case GSM_BAND_850:
- if (dbm >= 39)
- return 0;
- else if (dbm < 5)
- return 19;
- else
- return 2 + ((39 - dbm) / 2);
- break;
- case GSM_BAND_1800:
- if (dbm >= 36)
- return 29;
- else if (dbm >= 34)
- return 30;
- else if (dbm >= 32)
- return 31;
- else
- return (30 - dbm) / 2;
- break;
- case GSM_BAND_1900:
- if (dbm >= 33)
- return 30;
- else if (dbm >= 32)
- return 31;
- else
- return (30 - dbm) / 2;
- break;
- }
- return -EINVAL;
-}
-
-static int ms_pwr_dbm(enum gsm_band band, u_int8_t lvl)
-{
- lvl &= 0x1f;
-
- switch (band) {
- case GSM_BAND_400:
- case GSM_BAND_900:
- case GSM_BAND_850:
- if (lvl < 2)
- return 39;
- else if (lvl < 20)
- return 39 - ((lvl - 2) * 2) ;
- else
- return 5;
- break;
- case GSM_BAND_1800:
- if (lvl < 16)
- return 30 - (lvl * 2);
- else if (lvl < 29)
- return 0;
- else
- return 36 - ((lvl - 29) * 2);
- break;
- case GSM_BAND_1900:
- if (lvl < 16)
- return 30 - (lvl * 2);
- else if (lvl < 30)
- return -EINVAL;
- else
- return 33 - (lvl - 30);
- break;
- }
- return -EINVAL;
-}
-
int rsl_chan_ms_power_ctrl(struct gsm_lchan *lchan, unsigned int fpc, int dbm)
{
struct abis_rsl_dchan_hdr *dh;
@@ -510,7 +439,7 @@
u_int8_t chan_nr = lchan2chan_nr(lchan);
int ctl_lvl;
- ctl_lvl = ms_pwr_ctl_lvl(lchan->ts->trx->bts, dbm);
+ ctl_lvl = ms_pwr_ctl_lvl(lchan->ts->trx->bts->band, dbm);
if (ctl_lvl < 0)
return ctl_lvl;
@@ -1130,7 +1059,7 @@
arfcn = lchan->ts->trx->arfcn;
subch = lchan->nr;
- lchan->ms_power = ms_pwr_ctl_lvl(bts, 20 /* dBm == 100mW */);
+ lchan->ms_power = ms_pwr_ctl_lvl(bts->band, 20 /* dBm == 100mW */);
lchan->bs_power = 0x0f; /* 30dB reduction */
lchan->rsl_cmode = RSL_CMOD_SPD_SIGN;
rsl_chan_activate_lchan(lchan, 0x00, rqd_ta);
diff --git a/openbsc/src/bsc_hack.c b/openbsc/src/bsc_hack.c
index 02ec1ab..0f0f4c8 100644
--- a/openbsc/src/bsc_hack.c
+++ b/openbsc/src/bsc_hack.c
@@ -37,6 +37,7 @@
#include <openbsc/db.h>
#include <openbsc/timer.h>
#include <openbsc/gsm_data.h>
+#include <openbsc/gsm_utils.h>
#include <openbsc/gsm_04_08.h>
#include <openbsc/select.h>
#include <openbsc/abis_rsl.h>
@@ -982,7 +983,7 @@
/* patch MS max power for CCH */
type_4->cell_sel_par.ms_txpwr_max_ccch =
- ms_pwr_ctl_lvl(bts, 20 /* dBm == 100mW */);
+ ms_pwr_ctl_lvl(bts->band, 20 /* dBm == 100mW */);
}
diff --git a/openbsc/src/gsm_utils.c b/openbsc/src/gsm_utils.c
index 0c25b28..185918e 100644
--- a/openbsc/src/gsm_utils.c
+++ b/openbsc/src/gsm_utils.c
@@ -21,9 +21,11 @@
*
*/
+#include <openbsc/gsm_data.h>
#include <openbsc/gsm_utils.h>
#include <stdlib.h>
#include <string.h>
+#include <errno.h>
/* GSM 03.38 6.2.1 Charachter packing */
int gsm_7bit_decode(char *text, const u_int8_t *user_data, u_int8_t length)
@@ -71,3 +73,77 @@
return out_length;
}
+
+/* determine power control level for given dBm value, as indicated
+ * by the tables in chapter 4.1.1 of GSM TS 05.05 */
+int ms_pwr_ctl_lvl(enum gsm_band band, unsigned int dbm)
+{
+ switch (band) {
+ case GSM_BAND_400:
+ case GSM_BAND_900:
+ case GSM_BAND_850:
+ if (dbm >= 39)
+ return 0;
+ else if (dbm < 5)
+ return 19;
+ else
+ return 2 + ((39 - dbm) / 2);
+ break;
+ case GSM_BAND_1800:
+ if (dbm >= 36)
+ return 29;
+ else if (dbm >= 34)
+ return 30;
+ else if (dbm >= 32)
+ return 31;
+ else
+ return (30 - dbm) / 2;
+ break;
+ case GSM_BAND_1900:
+ if (dbm >= 33)
+ return 30;
+ else if (dbm >= 32)
+ return 31;
+ else
+ return (30 - dbm) / 2;
+ break;
+ }
+ return -EINVAL;
+}
+
+int ms_pwr_dbm(enum gsm_band band, u_int8_t lvl)
+{
+ lvl &= 0x1f;
+
+ switch (band) {
+ case GSM_BAND_400:
+ case GSM_BAND_900:
+ case GSM_BAND_850:
+ if (lvl < 2)
+ return 39;
+ else if (lvl < 20)
+ return 39 - ((lvl - 2) * 2) ;
+ else
+ return 5;
+ break;
+ case GSM_BAND_1800:
+ if (lvl < 16)
+ return 30 - (lvl * 2);
+ else if (lvl < 29)
+ return 0;
+ else
+ return 36 - ((lvl - 29) * 2);
+ break;
+ case GSM_BAND_1900:
+ if (lvl < 16)
+ return 30 - (lvl * 2);
+ else if (lvl < 30)
+ return -EINVAL;
+ else
+ return 33 - (lvl - 30);
+ break;
+ }
+ return -EINVAL;
+}
+
+