lynxis lazus has submitted this change. ( 
https://gerrit.osmocom.org/c/libosmocore/+/38764?usp=email )

Change subject: gsm_utils: add gprs_tlli2tmsi()
......................................................................

gsm_utils: add gprs_tlli2tmsi()

A converter function which converts from a TLLI into a TMSI.

Change-Id: I9d3464922c89383099a5f3cdd1458c0ecc28ee18
---
M include/osmocom/gsm/gsm_utils.h
M src/gsm/gsm_utils.c
M src/gsm/libosmogsm.map
M tests/gprs/gprs_test.c
4 files changed, 35 insertions(+), 0 deletions(-)

Approvals:
  daniel: Looks good to me, approved
  Jenkins Builder: Verified
  pespin: Looks good to me, but someone else must approve




diff --git a/include/osmocom/gsm/gsm_utils.h b/include/osmocom/gsm/gsm_utils.h
index b250c59..72bd131 100644
--- a/include/osmocom/gsm/gsm_utils.h
+++ b/include/osmocom/gsm/gsm_utils.h
@@ -211,6 +211,7 @@
 int gprs_tlli_type(uint32_t tlli);

 uint32_t gprs_tmsi2tlli(uint32_t p_tmsi, enum gprs_tlli_type type);
+uint32_t gprs_tlli2tmsi(uint32_t tlli);

 /* Osmocom internal, not part of any gsm spec */
 enum gsm_phys_chan_config {
diff --git a/src/gsm/gsm_utils.c b/src/gsm/gsm_utils.c
index bb40339..64fbd63 100644
--- a/src/gsm/gsm_utils.c
+++ b/src/gsm/gsm_utils.c
@@ -1019,6 +1019,27 @@
        return TLLI_RESERVED;
 }

+/*! Determine P-TMSI from foreign and local TLLIs
+ *
+ *  \param[in] tlli P-TMSI
+ *  \param[in] type TLLI Type we want to derive from \a p_tmsi
+ *  \returns P-TMSI or 0xffffffff on error. */
+uint32_t gprs_tlli2tmsi(uint32_t tlli)
+{
+       uint32_t ptmsi = 0xc0000000;
+
+       switch (gprs_tlli_type(tlli)) {
+       case TLLI_LOCAL:
+       case TLLI_FOREIGN:
+               break;
+       default:
+               return 0xffffffff;
+       }
+
+       ptmsi |= tlli;
+       return ptmsi;
+}
+
 /*! Determine TLLI from P-TMSI
  *  \param[in] p_tmsi P-TMSI
  *  \param[in] type TLLI Type we want to derive from \a p_tmsi
diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map
index 8d17ce3..7c78347 100644
--- a/src/gsm/libosmogsm.map
+++ b/src/gsm/libosmogsm.map
@@ -73,6 +73,7 @@
 gprs_cipher_key_length;
 gprs_tlli_type;
 gprs_tmsi2tlli;
+gprs_tlli2tmsi;
 gprs_ms_net_cap_gea_supported;
 gprs_msgt_gmm_names;

diff --git a/tests/gprs/gprs_test.c b/tests/gprs/gprs_test.c
index 70e3009..a98728c 100644
--- a/tests/gprs/gprs_test.c
+++ b/tests/gprs/gprs_test.c
@@ -7,6 +7,7 @@
 #include <osmocom/core/utils.h>
 #include <osmocom/core/logging.h>
 #include <osmocom/gsm/apn.h>
+#include <osmocom/gsm/gsm_utils.h>

 static void apn_round_trip(const uint8_t *input, size_t len, const char 
*wanted_output)
 {
@@ -110,6 +111,16 @@
        }
 }

+static void test_ptmsi_tlli(void)
+{
+       OSMO_ASSERT(gprs_tlli2tmsi(0xc0010203) == 0xc0010203);
+       OSMO_ASSERT(gprs_tlli2tmsi(0x80010203) == 0xc0010203);
+       OSMO_ASSERT(gprs_tlli2tmsi(0x00010203) == 0xffffffff);
+
+       OSMO_ASSERT(gprs_tmsi2tlli(0xc0010203, TLLI_LOCAL) == 0xc0010203);
+       OSMO_ASSERT(gprs_tmsi2tlli(0xc0010203, TLLI_FOREIGN) == 0x80010203);
+}
+
 const struct log_info_cat default_categories[] = {
 };

@@ -124,6 +135,7 @@
        osmo_init_logging2(ctx, &info);

        test_gsm_03_03_apn();
+       test_ptmsi_tlli();

        printf("Done.\n");
        return EXIT_SUCCESS;

--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/38764?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I9d3464922c89383099a5f3cdd1458c0ecc28ee18
Gerrit-Change-Number: 38764
Gerrit-PatchSet: 5
Gerrit-Owner: lynxis lazus <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <[email protected]>
Gerrit-Reviewer: lynxis lazus <[email protected]>
Gerrit-Reviewer: pespin <[email protected]>
Gerrit-CC: laforge <[email protected]>

Reply via email to