aboutsummaryrefslogtreecommitdiffstats
path: root/gtp/gtp.c
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2017-08-12 19:29:16 +0200
committerHarald Welte <laforge@gnumonks.org>2017-08-12 22:53:54 +0200
commitb10ee08c2ff4df8acc053d2ad9a2cba04e757061 (patch)
tree289b828c702e623f7dc71a462b5e0479d16374d7 /gtp/gtp.c
parent23eea1d132120198745dcca32728906d5f05dc5f (diff)
Properly format IMSI before using it in trap
For some reason Max' commits introducing the CTRL/trap interface about one year ago didn't convert the IMSI to its actual textual representation before usign it in the CTRL interface. Let's clean that up by properly interpreting the IMSI. Change-Id: I8b20d2e47a29de266d93a7ddd5e6877f7e346a63
Diffstat (limited to 'gtp/gtp.c')
-rw-r--r--gtp/gtp.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/gtp/gtp.c b/gtp/gtp.c
index 801664d..4aa6eb1 100644
--- a/gtp/gtp.c
+++ b/gtp/gtp.c
@@ -3244,3 +3244,31 @@ int in_addr2gsna(struct ul16_t *gsna, struct in_addr *src)
memcpy(gsna->v, src, gsna->l);
return 0;
}
+
+/* TS 29.060 has yet again a different encoding for IMSIs than
+ * what we have in other places, so we cannot use the gsm48
+ * decoding functions. Also, libgtp uses an uint64_t in
+ * _network byte order_ to contain BCD digits ?!? */
+const char *imsi_gtp2str(const uint64_t *imsi)
+{
+ static char buf[sizeof(*imsi)+1];
+ const uint8_t *imsi8 = (const uint8_t *) imsi;
+ unsigned int i, j = 0;
+
+ for (i = 0; i < sizeof(*imsi); i++) {
+ uint8_t nibble;
+
+ nibble = imsi8[i] & 0xf;
+ if (nibble == 0xf)
+ break;
+ buf[j++] = osmo_bcd2char(nibble);
+
+ nibble = imsi8[i] >> 4;
+ if (nibble == 0xf)
+ break;
+ buf[j++] = osmo_bcd2char(nibble);
+ }
+
+ buf[j++] = '\0';
+ return buf;
+}