summaryrefslogtreecommitdiffstats
path: root/openbsc/tests/gsm0408/gsm0408_test.c
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2009-08-20 08:41:24 +0200
committerHolger Hans Peter Freyther <zecke@selfish.org>2009-08-20 13:59:14 +0200
commit5d0e56f722ce77ed29226c85e93dd09c9184f97e (patch)
tree51a3767c861603d1e317053ec5687cced1c86e21 /openbsc/tests/gsm0408/gsm0408_test.c
parentd1862d7cf98b984407d8533ac68b0ae85cfbf9c7 (diff)
[gsm48] Introduce a gsm48_generate_mid_from_imsi method
Prefix generate_mid_from_tmsi with a gsm48_, create a new method to binary encode the imsi. Add a unit test for parsing and decoding. The implementation can parse the data it generated and the last octet seems to be filled with the end mark.
Diffstat (limited to 'openbsc/tests/gsm0408/gsm0408_test.c')
-rw-r--r--openbsc/tests/gsm0408/gsm0408_test.c40
1 files changed, 38 insertions, 2 deletions
diff --git a/openbsc/tests/gsm0408/gsm0408_test.c b/openbsc/tests/gsm0408/gsm0408_test.c
index c99766a72..bbf812965 100644
--- a/openbsc/tests/gsm0408/gsm0408_test.c
+++ b/openbsc/tests/gsm0408/gsm0408_test.c
@@ -24,13 +24,20 @@
#include <stdlib.h>
#include <openbsc/gsm_04_08.h>
+#include <openbsc/gsm_subscriber.h>
+#include <openbsc/debug.h>
#define COMPARE(result, op, value) \
if (!((result) op (value))) {\
fprintf(stderr, "Compare failed. Was %x should be %x in %s:%d\n",result, value, __FILE__, __LINE__); \
exit(-1); \
}
-
+
+#define COMPARE_STR(result, value) \
+ if (strcmp(result, value) != 0) { \
+ fprintf(stderr, "Compare failed. Was %s should be %s in %s:%d\n",result, value, __FILE__, __LINE__); \
+ exit(-1); \
+ }
/*
* Test Location Area Identifier formatting. Table 10.5.3 of 04.08
@@ -58,9 +65,38 @@ static void test_location_area_identifier(void)
COMPARE(lai48.lac, ==, htons(0x000f));
}
+static void test_mi_functionality(void)
+{
+ const char *imsi_odd = "987654321098763";
+ const char *imsi_even = "9876543210987654";
+ const u_int32_t tmsi = 0xfabeacd0;
+ u_int8_t mi[128];
+ unsigned int mi_len;
+ char mi_parsed[GSM48_MI_SIZE];
+
+ printf("Testing parsing and generating TMSI/IMSI\n");
+
+ /* tmsi code */
+ mi_len = gsm48_generate_mid_from_tmsi(mi, tmsi);
+ gsm48_mi_to_string(mi_parsed, sizeof(mi_parsed), mi + 2, mi_len - 2);
+ COMPARE((u_int32_t)strtoul(mi_parsed, NULL, 10), ==, tmsi);
+
+ /* imsi code */
+ mi_len = gsm48_generate_mid_from_imsi(mi, imsi_odd);
+ gsm48_mi_to_string(mi_parsed, sizeof(mi_parsed), mi + 2, mi_len -2);
+ printf("hex: %s\n", hexdump(mi, mi_len));
+ COMPARE_STR(mi_parsed, imsi_odd);
+
+ mi_len = gsm48_generate_mid_from_imsi(mi, imsi_even);
+ gsm48_mi_to_string(mi_parsed, sizeof(mi_parsed), mi + 2, mi_len -2);
+ printf("hex: %s\n", hexdump(mi, mi_len));
+ COMPARE_STR(mi_parsed, imsi_even);
+}
+
int main(int argc, char** argv)
{
- test_location_area_identifier();
+ test_location_area_identifier();
+ test_mi_functionality();
}