This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Vadim Yanitskiy gerrit-no-reply at lists.osmocom.org
Review at https://gerrit.osmocom.org/199
gsm48.c: move to hex tmsi representation
Because we should save the backward compatibility with
other projects that use this library, there is one new
gsm48_mid_to_string() method which is similar to the
gsm48_mi_to_string() but uses the '0x%08x' format string
to convert TMSI.
Also there is one more gsm48_tmsi_from_string() method
that was moved here from OpenBSC/gsm_subscriber.h.
Change-Id: I9d05209e546d8692360860839fa0720fb7349385
---
M include/osmocom/gsm/gsm48.h
M src/gsm/gsm48.c
2 files changed, 58 insertions(+), 4 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/99/199/1
diff --git a/include/osmocom/gsm/gsm48.h b/include/osmocom/gsm/gsm48.h
index d6e58c2..3b6a80b 100644
--- a/include/osmocom/gsm/gsm48.h
+++ b/include/osmocom/gsm/gsm48.h
@@ -29,10 +29,12 @@
int gsm48_generate_mid_from_tmsi(uint8_t *buf, uint32_t tmsi);
int gsm48_generate_mid_from_imsi(uint8_t *buf, const char *imsi);
-/* Convert Mobile Identity (10.5.1.4) to string */
+/* Mobile Identity (10.5.1.4) related methods */
+const char *gsm48_mi_type_name(uint8_t mi);
int gsm48_mi_to_string(char *string, const int str_len,
const uint8_t *mi, const int mi_len);
-const char *gsm48_mi_type_name(uint8_t mi);
+int gsm48_mid_to_string(char *string, const int str_len,
+ const uint8_t *mi, const int mi_len);
/* Parse Routeing Area Identifier */
void gsm48_parse_ra(struct gprs_ra_id *raid, const uint8_t *buf);
diff --git a/src/gsm/gsm48.c b/src/gsm/gsm48.c
index 8a46f76..0399aac 100644
--- a/src/gsm/gsm48.c
+++ b/src/gsm/gsm48.c
@@ -443,7 +443,10 @@
return 2 + buf[1];
}
-/* Convert Mobile Identity (10.5.1.4) to string */
+/* Convert Mobile Identity (10.5.1.4) to string.
+ * Now it is outdated method because we are moving to
+ * hexadecimal TMSI representation, so we should use
+ * the gsm48_mid_to_string() instead of this one. */
int gsm48_mi_to_string(char *string, const int str_len, const uint8_t *mi,
const int mi_len)
{
@@ -470,7 +473,7 @@
case GSM_MI_TYPE_IMEISV:
*str_cur++ = osmo_bcd2char(mi[0] >> 4);
- for (i = 1; i < mi_len; i++) {
+ for (i = 1; i < mi_len; i++) {
if (str_cur + 2 >= string + str_len)
return str_cur - string;
*str_cur++ = osmo_bcd2char(mi[i] & 0xf);
@@ -487,6 +490,55 @@
return str_cur - string;
}
+int gsm48_mid_to_string(char *string, const int str_len, const uint8_t *mi,
+ const int mi_len)
+{
+ int i;
+ uint8_t mi_type;
+ char *str_cur = string;
+ uint32_t tmsi;
+
+ mi_type = mi[0] & GSM_MI_TYPE_MASK;
+
+ switch (mi_type) {
+ case GSM_MI_TYPE_NONE:
+ break;
+ case GSM_MI_TYPE_TMSI:
+ if (mi_len == GSM48_TMSI_LEN && mi[0] == (0xf0 | GSM_MI_TYPE_TMSI)) {
+ memcpy(&tmsi, &mi[1], 4);
+ tmsi = ntohl(tmsi);
+ return snprintf(string, str_len, "0x%08x", tmsi);
+ }
+ break;
+ case GSM_MI_TYPE_IMSI:
+ case GSM_MI_TYPE_IMEI:
+ case GSM_MI_TYPE_IMEISV:
+ *str_cur++ = osmo_bcd2char(mi[0] >> 4);
+
+ for (i = 1; i < mi_len; i++) {
+ if (str_cur + 2 >= string + str_len)
+ return str_cur - string;
+ *str_cur++ = osmo_bcd2char(mi[i] & 0xf);
+ /* skip last nibble in last input byte when GSM_EVEN */
+ if( (i != mi_len-1) || (mi[0] & GSM_MI_ODD))
+ *str_cur++ = osmo_bcd2char(mi[i] >> 4);
+ }
+ break;
+ default:
+ break;
+ }
+ *str_cur++ = '\0';
+
+ return str_cur - string;
+}
+
+uint32_t gsm48_tmsi_from_string(char *mi_string)
+{
+ /* It is not required to cut the '0x' because
+ * the strtoul() can handle it automatically */
+ return strtoul(mi_string, NULL, 16);
+}
+
void gsm48_parse_ra(struct gprs_ra_id *raid, const uint8_t *buf)
{
raid->mcc = (buf[0] & 0xf) * 100;
--
To view, visit https://gerrit.osmocom.org/199
To unsubscribe, visit https://gerrit.osmocom.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I9d05209e546d8692360860839fa0720fb7349385
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Vadim Yanitskiy <axilirator at gmail.com>