summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/osmocom/gsm/gsm_utils.h2
-rw-r--r--src/gsm/gsm_utils.c41
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)