lynxis lazus has uploaded this change for review. ( 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, 34 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/64/38764/1
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..a0df49c 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 = (1 << 31) | (1 << 30); + + 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..51fe599 100644 --- a/tests/gprs/gprs_test.c +++ b/tests/gprs/gprs_test.c @@ -110,6 +110,16 @@ } }
+static void test_ptmsi_tlli() +{ + OSMO_ASSERT(gprs_tlli2tmsi(0xc0010203) == 0x00010203); + OSMO_ASSERT(gprs_tlli2tmsi(0x80010203) == 0x00010203); + OSMO_ASSERT(gprs_tlli2tmsi(0xf0010203) == 0xffffffff); + + OSMO_ASSERT(gprs_tmsi2tlli(0x00010203, TLLI_LOCAL) == 0xc0010203); + OSMO_ASSERT(gprs_tmsi2tlli(0x00010203, TLLI_FOREIGN) == 0x80010203); +} + const struct log_info_cat default_categories[] = { };
@@ -124,6 +134,7 @@ osmo_init_logging2(ctx, &info);
test_gsm_03_03_apn(); + test_ptmsi_tlli();
printf("Done.\n"); return EXIT_SUCCESS;