pespin has submitted this change. ( 
https://gerrit.osmocom.org/c/libosmocore/+/15923 )

Change subject: gsm_04_08.h: Introduce API osmo_gsm48_rfpowercap2powerclass()
......................................................................

gsm_04_08.h: Introduce API osmo_gsm48_rfpowercap2powerclass()

Related: OS#4244
Change-Id: I32e9cc1c2397b44f0d48db2acdf782a821365b63
---
M TODO-RELEASE
M include/osmocom/gsm/protocol/gsm_04_08.h
M src/gsm/gsm48.c
M src/gsm/libosmogsm.map
M tests/gsm0408/gsm0408_test.c
5 files changed, 49 insertions(+), 1 deletion(-)

Approvals:
  laforge: Looks good to me, approved
  neels: Looks good to me, but someone else must approve
  fixeria: Looks good to me, but someone else must approve
  Jenkins Builder: Verified



diff --git a/TODO-RELEASE b/TODO-RELEASE
index 547b5a9..9af92c1 100644
--- a/TODO-RELEASE
+++ b/TODO-RELEASE
@@ -9,3 +9,4 @@
 #library       what                    description / commit summary line
 core           osmo_tdef_get()         change val_if_not_present arg from 
unsigned long to long to allow passing -1
 core           struct osmo_tdef        fields min_val,max_val added, ABI break 
(arrays of structs used in programs)
+gsm            API added               osmo_gsm48_rfpowercap2powerclass()
diff --git a/include/osmocom/gsm/protocol/gsm_04_08.h 
b/include/osmocom/gsm/protocol/gsm_04_08.h
index 6a6c7f3..b5317d5 100644
--- a/include/osmocom/gsm/protocol/gsm_04_08.h
+++ b/include/osmocom/gsm/protocol/gsm_04_08.h
@@ -10,6 +10,7 @@
 #include <osmocom/core/endian.h>

 struct gsm_lchan;
+enum gsm_band;

 /* Chapter 10.5.1.5 */
 struct gsm48_classmark1 {
@@ -73,7 +74,7 @@
 char *osmo_gsm48_classmark_a5_name_buf(char *buf, size_t buf_len, const struct 
osmo_gsm48_classmark *cm);
 char *osmo_gsm48_classmark_a5_name_c(const void *ctx, const struct 
osmo_gsm48_classmark *cm);
 void osmo_gsm48_classmark_update(struct osmo_gsm48_classmark *dst, const 
struct osmo_gsm48_classmark *src);
-
+int8_t osmo_gsm48_rfpowercap2powerclass(enum gsm_band band, uint8_t 
rf_power_cap);
 /* Chapter 10.5.2.1b.3 */
 #if OSMO_IS_LITTLE_ENDIAN == 1
 struct gsm48_range_1024 {
diff --git a/src/gsm/gsm48.c b/src/gsm/gsm48.c
index 2d6deb5..17b0829 100644
--- a/src/gsm/gsm48.c
+++ b/src/gsm/gsm48.c
@@ -1390,4 +1390,25 @@
        }
 }

+/*! Decode power class from Classmark1/2 RF power capability field.
+ * \param[in] rf_power_cap  The RF power capability field (3 bits).
+ * \param[in] band  the band of the arfcn from where the classmark was received
+ * \return the MS power class on success, negative on error.
+ */
+int8_t osmo_gsm48_rfpowercap2powerclass(enum gsm_band band, uint8_t 
rf_power_cap)
+{
+       switch (band)  {
+       case GSM_BAND_1800:
+       case GSM_BAND_1900:
+               if (rf_power_cap > 2)
+                       return -1;
+               return rf_power_cap + 1;
+       default:
+               if (rf_power_cap > 4)
+                       return -1;
+               return rf_power_cap + 1;
+       }
+}
+
+
 /*! @} */
diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map
index 724fe5b..a0e3b32 100644
--- a/src/gsm/libosmogsm.map
+++ b/src/gsm/libosmogsm.map
@@ -646,6 +646,7 @@
 osmo_gsm48_classmark_a5_name_buf;
 osmo_gsm48_classmark_a5_name_c;
 osmo_gsm48_classmark_update;
+osmo_gsm48_rfpowercap2powerclass;

 cbsp_msg_type_names;
 cbsp_iei_names;
diff --git a/tests/gsm0408/gsm0408_test.c b/tests/gsm0408/gsm0408_test.c
index db1d45a..2488024 100644
--- a/tests/gsm0408/gsm0408_test.c
+++ b/tests/gsm0408/gsm0408_test.c
@@ -26,6 +26,7 @@
 #include <osmocom/gsm/gsm48_ie.h>
 #include <osmocom/gsm/gsm48.h>
 #include <osmocom/gsm/gsm48_arfcn_range_encode.h>
+#include <osmocom/gsm/gsm_utils.h>
 #include <osmocom/gsm/mncc.h>
 #include <osmocom/core/backtrace.h>
 #include <osmocom/core/utils.h>
@@ -1132,6 +1133,28 @@
        VERIFY(f0, ==, 1);
 }

+static void test_power_ctrl()
+{
+       int8_t rc8;
+
+       rc8 = osmo_gsm48_rfpowercap2powerclass(GSM_BAND_850, 0x00);
+       VERIFY(rc8, ==, 1);
+       rc8 = osmo_gsm48_rfpowercap2powerclass(GSM_BAND_900, 0x02);
+       VERIFY(rc8, ==, 3);
+       rc8 = osmo_gsm48_rfpowercap2powerclass(GSM_BAND_1800, 0x02);
+       VERIFY(rc8, ==, 3);
+       rc8 = osmo_gsm48_rfpowercap2powerclass(GSM_BAND_1900, 0x02);
+       VERIFY(rc8, ==, 3);
+       rc8 = osmo_gsm48_rfpowercap2powerclass(GSM_BAND_1900, 0x04);
+       VERIFY(rc8, <, 0);
+       rc8 = osmo_gsm48_rfpowercap2powerclass(GSM_BAND_900, 0x04);
+       VERIFY(rc8, ==, 5);
+       rc8 = osmo_gsm48_rfpowercap2powerclass(GSM_BAND_900, 0x05);
+       VERIFY(rc8, <, 0);
+       rc8 = osmo_gsm48_rfpowercap2powerclass(GSM_BAND_900, 0xf2);
+       VERIFY(rc8, <, 0);
+}
+
 int main(int argc, char **argv)
 {
        test_bearer_cap();
@@ -1147,6 +1170,7 @@
        test_arfcn_filter();
        test_print_encoding();
        test_range_encoding();
+       test_power_ctrl();

        return EXIT_SUCCESS;
 }

--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/15923
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I32e9cc1c2397b44f0d48db2acdf782a821365b63
Gerrit-Change-Number: 15923
Gerrit-PatchSet: 2
Gerrit-Owner: pespin <pes...@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <axilira...@gmail.com>
Gerrit-Reviewer: laforge <lafo...@osmocom.org>
Gerrit-Reviewer: neels <nhofm...@sysmocom.de>
Gerrit-Reviewer: pespin <pes...@sysmocom.de>
Gerrit-MessageType: merged

Reply via email to