diff options
author | Andreas Eversberg <jolly@eversberg.eu> | 2011-06-26 11:41:48 +0200 |
---|---|---|
committer | Sylvain Munaut <tnt@246tNt.com> | 2011-06-26 11:41:48 +0200 |
commit | 2a68c7c8cd2eca65c58c0898d0e1716e9d4c3ecd (patch) | |
tree | 4f559b3c8740fede99d36e238e29bf83dd4cf2d4 | |
parent | 620f7ab35034f78f894319e027a151568c331eea (diff) |
gsm/utils: Adding conversion of "mobile power class" to dBm
Written-by: Andreas Eversberg <jolly@eversberg.eu>
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
-rw-r--r-- | include/osmocom/gsm/gsm_utils.h | 2 | ||||
-rw-r--r-- | src/gsm/gsm_utils.c | 41 |
2 files changed, 43 insertions, 0 deletions
diff --git a/include/osmocom/gsm/gsm_utils.h b/include/osmocom/gsm/gsm_utils.h index a0ef3c4f..405dfe32 100644 --- a/include/osmocom/gsm/gsm_utils.h +++ b/include/osmocom/gsm/gsm_utils.h @@ -59,6 +59,8 @@ enum gsm_band gsm_band_parse(const char *mhz); int gsm_7bit_decode(char *decoded, const uint8_t *user_data, uint8_t length); int gsm_7bit_encode(uint8_t *result, const char *data); +unsigned int ms_class_gmsk_dbm(enum gsm_band band, int class); + int ms_pwr_ctl_lvl(enum gsm_band band, unsigned int dbm); int ms_pwr_dbm(enum gsm_band band, uint8_t lvl); diff --git a/src/gsm/gsm_utils.c b/src/gsm/gsm_utils.c index 377705d9..5da713c2 100644 --- a/src/gsm/gsm_utils.c +++ b/src/gsm/gsm_utils.c @@ -171,6 +171,47 @@ int gsm_7bit_encode(uint8_t *result, const char *data) return z; } +/* convert power class to dBm according to GSM TS 05.05 */ +unsigned int ms_class_gmsk_dbm(enum gsm_band band, int class) +{ + switch (band) { + case GSM_BAND_450: + case GSM_BAND_480: + case GSM_BAND_750: + case GSM_BAND_900: + case GSM_BAND_810: + case GSM_BAND_850: + if (class == 1) + return 43; /* 20W */ + if (class == 2) + return 39; /* 8W */ + if (class == 3) + return 37; /* 5W */ + if (class == 4) + return 33; /* 2W */ + if (class == 5) + return 29; /* 0.8W */ + break; + case GSM_BAND_1800: + if (class == 1) + return 30; /* 1W */ + if (class == 2) + return 24; /* 0.25W */ + if (class == 3) + return 36; /* 4W */ + break; + case GSM_BAND_1900: + if (class == 1) + return 30; /* 1W */ + if (class == 2) + return 24; /* 0.25W */ + if (class == 3) + return 33; /* 2W */ + break; + } + return -EINVAL; +} + /* 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) |