blob: bbf812965cab60e7db0ad72c29c3b297550a7e76 [file] [log] [blame]
Holger Freytheraa0fb362008-12-28 21:55:40 +00001/* simple test for the gsm0408 formatting functions */
2/*
3 * (C) 2008 by Holger Hans Peter Freyther <zecke@selfish.org>
4 * All Rights Reserved
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 */
21
22#include <assert.h>
23#include <stdio.h>
24#include <stdlib.h>
25
26#include <openbsc/gsm_04_08.h>
Holger Hans Peter Freyther5d0e56f2009-08-20 08:41:24 +020027#include <openbsc/gsm_subscriber.h>
28#include <openbsc/debug.h>
Holger Freytheraa0fb362008-12-28 21:55:40 +000029
30#define COMPARE(result, op, value) \
31 if (!((result) op (value))) {\
32 fprintf(stderr, "Compare failed. Was %x should be %x in %s:%d\n",result, value, __FILE__, __LINE__); \
33 exit(-1); \
34 }
Holger Hans Peter Freyther5d0e56f2009-08-20 08:41:24 +020035
36#define COMPARE_STR(result, value) \
37 if (strcmp(result, value) != 0) { \
38 fprintf(stderr, "Compare failed. Was %s should be %s in %s:%d\n",result, value, __FILE__, __LINE__); \
39 exit(-1); \
40 }
Holger Freytheraa0fb362008-12-28 21:55:40 +000041
42/*
43 * Test Location Area Identifier formatting. Table 10.5.3 of 04.08
44 */
45static void test_location_area_identifier(void)
46{
47 struct gsm48_loc_area_id lai48;
48
49 printf("Testing test location area identifier\n");
50
51 /*
52 * Test the default/test setup. Coming from
53 * bsc_hack.c dumps
54 */
55 gsm0408_generate_lai(&lai48, 1, 1, 1);
56 COMPARE(lai48.digits[0], ==, 0x00);
57 COMPARE(lai48.digits[1], ==, 0xF1);
58 COMPARE(lai48.digits[2], ==, 0x10);
59 COMPARE(lai48.lac, ==, htons(0x0001));
60
61 gsm0408_generate_lai(&lai48, 602, 1, 15);
62 COMPARE(lai48.digits[0], ==, 0x06);
63 COMPARE(lai48.digits[1], ==, 0xF2);
64 COMPARE(lai48.digits[2], ==, 0x10);
65 COMPARE(lai48.lac, ==, htons(0x000f));
66}
67
Holger Hans Peter Freyther5d0e56f2009-08-20 08:41:24 +020068static void test_mi_functionality(void)
69{
70 const char *imsi_odd = "987654321098763";
71 const char *imsi_even = "9876543210987654";
72 const u_int32_t tmsi = 0xfabeacd0;
73 u_int8_t mi[128];
74 unsigned int mi_len;
75 char mi_parsed[GSM48_MI_SIZE];
76
77 printf("Testing parsing and generating TMSI/IMSI\n");
78
79 /* tmsi code */
80 mi_len = gsm48_generate_mid_from_tmsi(mi, tmsi);
81 gsm48_mi_to_string(mi_parsed, sizeof(mi_parsed), mi + 2, mi_len - 2);
82 COMPARE((u_int32_t)strtoul(mi_parsed, NULL, 10), ==, tmsi);
83
84 /* imsi code */
85 mi_len = gsm48_generate_mid_from_imsi(mi, imsi_odd);
86 gsm48_mi_to_string(mi_parsed, sizeof(mi_parsed), mi + 2, mi_len -2);
87 printf("hex: %s\n", hexdump(mi, mi_len));
88 COMPARE_STR(mi_parsed, imsi_odd);
89
90 mi_len = gsm48_generate_mid_from_imsi(mi, imsi_even);
91 gsm48_mi_to_string(mi_parsed, sizeof(mi_parsed), mi + 2, mi_len -2);
92 printf("hex: %s\n", hexdump(mi, mi_len));
93 COMPARE_STR(mi_parsed, imsi_even);
94}
95
Holger Freytheraa0fb362008-12-28 21:55:40 +000096int main(int argc, char** argv)
97{
Holger Hans Peter Freyther5d0e56f2009-08-20 08:41:24 +020098 test_location_area_identifier();
99 test_mi_functionality();
Holger Freytheraa0fb362008-12-28 21:55:40 +0000100}
101
102
103
104/*
105 * Stubs to compile and link
106 */
Holger Freyther3281f6e2009-02-20 18:33:00 +0000107void input_event(void) {}
108void nm_state_event(void) {}