blob: e111fe6786ab5027bb030e3dc32ff28617030256 [file] [log] [blame]
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01001/*
2 * (C) 2012 by Holger Hans Peter Freyther
3 * All Rights Reserved
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 */
20
21#include <osmocom/gsm/gsm0808.h>
Philipp Maier22401432017-03-24 17:59:26 +010022#include <osmocom/gsm/gsm0808_utils.h>
23#include <osmocom/gsm/protocol/gsm_08_08.h>
Philipp Maier3d48ec02017-03-29 17:37:55 +020024#include <osmocom/gsm/protocol/gsm_08_58.h>
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +010025
26#include <stdio.h>
27#include <stdlib.h>
Philipp Maier22401432017-03-24 17:59:26 +010028#include <sys/socket.h>
29#include <netinet/in.h>
30#include <arpa/inet.h>
Neels Hofmeyr74663d92018-03-23 01:46:42 +010031#include <errno.h>
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +010032
33#define VERIFY(msg, data, len) \
34 if (msgb_l3len(msg) != len) { \
35 printf("%s:%d Length don't match: %d vs. %d. %s\n", \
Holger Hans Peter Freytherfdb46672015-11-09 16:32:43 +000036 __func__, __LINE__, msgb_l3len(msg), (int) len, \
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +010037 osmo_hexdump(msg->l3h, msgb_l3len(msg))); \
38 abort(); \
39 } else if (memcmp(msg->l3h, data, len) != 0) { \
40 printf("%s:%d didn't match: got: %s\n", \
41 __func__, __LINE__, \
42 osmo_hexdump(msg->l3h, msgb_l3len(msg))); \
43 abort(); \
44 }
45
Philipp Maierfa896ab2017-03-27 16:55:32 +020046/* Setup a fake codec list for testing */
47static void setup_codec_list(struct gsm0808_speech_codec_list *scl)
48{
49 memset(scl, 0, sizeof(*scl));
50
51 scl->codec[0].pi = true;
52 scl->codec[0].tf = true;
Philipp Maierbb839662017-06-01 17:11:19 +020053 scl->codec[0].type = GSM0808_SCT_FR3;
Philipp Maierfa896ab2017-03-27 16:55:32 +020054 scl->codec[0].cfg = 0xcdef;
55
56 scl->codec[1].fi = true;
57 scl->codec[1].pt = true;
Philipp Maierbb839662017-06-01 17:11:19 +020058 scl->codec[1].type = GSM0808_SCT_FR2;
Philipp Maierfa896ab2017-03-27 16:55:32 +020059
60 scl->codec[2].fi = true;
61 scl->codec[2].tf = true;
Philipp Maierbb839662017-06-01 17:11:19 +020062 scl->codec[2].type = GSM0808_SCT_CSD;
63 scl->codec[2].cfg = 0xc0;
Philipp Maierfa896ab2017-03-27 16:55:32 +020064
65 scl->len = 3;
66}
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +010067
68static void test_create_layer3(void)
69{
70 static const uint8_t res[] = {
71 0x00, 0x0e, 0x57, 0x05, 0x08, 0x00, 0x77, 0x62,
72 0x83, 0x33, 0x66, 0x44, 0x88, 0x17, 0x01, 0x23 };
73 struct msgb *msg, *in_msg;
74 printf("Testing creating Layer3\n");
75
76 in_msg = msgb_alloc_headroom(512, 128, "foo");
77 in_msg->l3h = in_msg->data;
78 msgb_v_put(in_msg, 0x23);
79
80 msg = gsm0808_create_layer3(in_msg, 0x1122, 0x2244, 0x3366, 0x4488);
81 VERIFY(msg, res, ARRAY_SIZE(res));
82 msgb_free(msg);
83 msgb_free(in_msg);
84}
85
Philipp Maierfa896ab2017-03-27 16:55:32 +020086static void test_create_layer3_aoip()
87{
88 static const uint8_t res[] = {
89 0x00, 0x17, 0x57, 0x05, 0x08, 0x00, 0x77, 0x62,
90 0x83, 0x33, 0x66, 0x44, 0x88, 0x17, 0x01, 0x23,
Philipp Maierbb839662017-06-01 17:11:19 +020091 GSM0808_IE_SPEECH_CODEC_LIST, 0x07, GSM0808_SCT_FR3 | 0x50,
Philipp Maier7e27b142018-03-22 17:26:46 +010092 0xef, 0xcd, GSM0808_SCT_FR2 | 0xa0, 0x9f,
Philipp Maierbb839662017-06-01 17:11:19 +020093 GSM0808_SCT_CSD | 0x90, 0xc0
Philipp Maierfa896ab2017-03-27 16:55:32 +020094 };
95
96 struct msgb *msg, *in_msg;
97 struct gsm0808_speech_codec_list sc_list;
98 printf("Testing creating Layer3 (AoIP)\n");
99
100 setup_codec_list(&sc_list);
101
102 in_msg = msgb_alloc_headroom(512, 128, "foo");
103 in_msg->l3h = in_msg->data;
104 msgb_v_put(in_msg, 0x23);
105
106 msg =
107 gsm0808_create_layer3_aoip(in_msg, 0x1122, 0x2244, 0x3366, 0x4488,
108 &sc_list);
109 VERIFY(msg, res, ARRAY_SIZE(res));
110
111 msgb_free(msg);
112 msgb_free(in_msg);
113}
114
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100115static void test_create_reset()
116{
117 static const uint8_t res[] = { 0x00, 0x04, 0x30, 0x04, 0x01, 0x20 };
118 struct msgb *msg;
119
120 printf("Testing creating Reset\n");
121 msg = gsm0808_create_reset();
122 VERIFY(msg, res, ARRAY_SIZE(res));
123 msgb_free(msg);
124}
125
Philipp Maier15596e22017-04-05 17:55:27 +0200126static void test_create_reset_ack()
127{
128 static const uint8_t res[] = { 0x00, 0x01, 0x31 };
129 struct msgb *msg;
130
131 printf("Testing creating Reset Ack\n");
132 msg = gsm0808_create_reset_ack();
133 VERIFY(msg, res, ARRAY_SIZE(res));
134 msgb_free(msg);
135}
136
137
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100138static void test_create_clear_command()
139{
140 static const uint8_t res[] = { 0x20, 0x04, 0x01, 0x23 };
141 struct msgb *msg;
142
143 printf("Testing creating Clear Command\n");
144 msg = gsm0808_create_clear_command(0x23);
145 VERIFY(msg, res, ARRAY_SIZE(res));
146 msgb_free(msg);
147}
148
149static void test_create_clear_complete()
150{
151 static const uint8_t res[] = { 0x00, 0x01, 0x21 };
152 struct msgb *msg;
153
154 printf("Testing creating Clear Complete\n");
155 msg = gsm0808_create_clear_complete();
156 VERIFY(msg, res, ARRAY_SIZE(res));
157 msgb_free(msg);
158}
159
Philipp Maierb478dd32017-03-29 15:50:05 +0200160static void test_create_cipher()
161{
162 static const uint8_t res[] =
163 { 0x00, 0x0c, 0x53, 0x0a, 0x09, 0x03, 0xaa,
164 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x23, 0x42 };
165 static const uint8_t res2[] =
166 { 0x00, 0x0e, 0x53, 0x0a, 0x09, 0x03, 0xaa,
167 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x23, 0x42,
168 GSM0808_IE_CIPHER_RESPONSE_MODE, 0x01 };
169 struct msgb *msg;
170 struct gsm0808_encrypt_info ei;
171 uint8_t include_imeisv;
172
173 memset(&ei, 0, sizeof(ei));
174 ei.perm_algo[0] = GSM0808_ALG_ID_A5_0;
175 ei.perm_algo[1] = GSM0808_ALG_ID_A5_1;
176 ei.perm_algo_len = 2;
177 ei.key[0] = 0xaa;
178 ei.key[1] = 0xbb;
179 ei.key[2] = 0xcc;
180 ei.key[3] = 0xdd;
181 ei.key[4] = 0xee;
182 ei.key[5] = 0xff;
183 ei.key[6] = 0x23;
184 ei.key[7] = 0x42;
185 ei.key_len = 8;
186 include_imeisv = 1;
187
188 printf("Testing creating Chipher Mode Command\n");
189 msg = gsm0808_create_cipher(&ei, NULL);
190 OSMO_ASSERT(msg);
191 VERIFY(msg, res, ARRAY_SIZE(res));
192 msgb_free(msg);
193
194 msg = gsm0808_create_cipher(&ei, &include_imeisv);
195 OSMO_ASSERT(msg);
196 VERIFY(msg, res2, ARRAY_SIZE(res2));
197 msgb_free(msg);
198}
199
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100200static void test_create_cipher_complete()
201{
202 static const uint8_t res1[] = {
203 0x00, 0x08, 0x55, 0x20, 0x03, 0x23, 0x42, 0x21, 0x2c, 0x04 };
204 static const uint8_t res2[] = { 0x00, 0x03, 0x55, 0x2c, 0x04};
205 struct msgb *l3, *msg;
206
207 printf("Testing creating Cipher Complete\n");
208 l3 = msgb_alloc_headroom(512, 128, "l3h");
209 l3->l3h = l3->data;
210 msgb_v_put(l3, 0x23);
211 msgb_v_put(l3, 0x42);
212 msgb_v_put(l3, 0x21);
213
214 /* with l3 data */
215 msg = gsm0808_create_cipher_complete(l3, 4);
216 VERIFY(msg, res1, ARRAY_SIZE(res1));
217 msgb_free(msg);
218
219 /* with l3 data but short */
220 l3->len -= 1;
221 l3->tail -= 1;
222 msg = gsm0808_create_cipher_complete(l3, 4);
223 VERIFY(msg, res2, ARRAY_SIZE(res2));
224 msgb_free(msg);
225
226 /* without l3 data */
227 msg = gsm0808_create_cipher_complete(NULL, 4);
228 VERIFY(msg, res2, ARRAY_SIZE(res2));
229 msgb_free(msg);
230
231
232 msgb_free(l3);
233}
234
235static void test_create_cipher_reject()
236{
Harald Welte62e40852017-12-17 20:50:34 +0100237 static const uint8_t res[] = { 0x00, 0x04, 0x59, 0x04, 0x01, 0x23 };
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100238 struct msgb *msg;
239
240 printf("Testing creating Cipher Reject\n");
241 msg = gsm0808_create_cipher_reject(0x23);
242 VERIFY(msg, res, ARRAY_SIZE(res));
243 msgb_free(msg);
244}
245
246static void test_create_cm_u()
247{
Harald Welte07b625d2012-01-23 10:02:58 +0100248 static const uint8_t res[] = {
249 0x00, 0x07, 0x54, 0x12, 0x01, 0x23, 0x13, 0x01, 0x42 };
250 static const uint8_t res2o[] = {
251 0x00, 0x04, 0x54, 0x12, 0x01, 0x23 };
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100252 struct msgb *msg;
Harald Welte07b625d2012-01-23 10:02:58 +0100253 const uint8_t cm2 = 0x23;
254 const uint8_t cm3 = 0x42;
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100255
256 printf("Testing creating CM U\n");
Harald Welte07b625d2012-01-23 10:02:58 +0100257 msg = gsm0808_create_classmark_update(&cm2, 1, &cm3, 1);
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100258 VERIFY(msg, res, ARRAY_SIZE(res));
Harald Welte07b625d2012-01-23 10:02:58 +0100259
Neels Hofmeyr9a938ae2017-11-16 17:34:07 +0100260 msgb_free(msg);
261
Harald Welte07b625d2012-01-23 10:02:58 +0100262 msg = gsm0808_create_classmark_update(&cm2, 1, NULL, 0);
263 VERIFY(msg, res2o, ARRAY_SIZE(res2o));
264
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100265 msgb_free(msg);
266}
267
268static void test_create_sapi_reject()
269{
270 static const uint8_t res[] = { 0x00, 0x03, 0x25, 0x03, 0x25 };
271 struct msgb *msg;
272
273 printf("Testing creating SAPI Reject\n");
274 msg = gsm0808_create_sapi_reject(3);
275 VERIFY(msg, res, ARRAY_SIZE(res));
276 msgb_free(msg);
277}
278
Philipp Maierc6144a22017-03-29 17:53:43 +0200279static void test_create_ass()
280{
281 static const uint8_t res1[] =
282 { 0x00, 0x0a, 0x01, 0x0b, 0x04, 0x01, 0x0b, 0xa1, 0x25, 0x01, 0x00,
283 0x04 };
284 static const uint8_t res2[] =
285 { 0x00, 0x20, 0x01, 0x0b, 0x04, 0x01, 0x0b, 0xa1, 0x25, 0x01, 0x00,
286 0x04, GSM0808_IE_AOIP_TRASP_ADDR, 0x06, 0xc0, 0xa8, 0x64, 0x17,
Philipp Maierbb839662017-06-01 17:11:19 +0200287 0x04, 0xd2, GSM0808_IE_SPEECH_CODEC_LIST, 0x07,
Philipp Maier7e27b142018-03-22 17:26:46 +0100288 GSM0808_SCT_FR3 | 0x50, 0xef, 0xcd, GSM0808_SCT_FR2 | 0xa0, 0x9f,
Philipp Maierbb839662017-06-01 17:11:19 +0200289 GSM0808_SCT_CSD | 0x90, 0xc0, GSM0808_IE_CALL_ID, 0xaa, 0xbb,
290 0xcc, 0xdd };
Philipp Maierc6144a22017-03-29 17:53:43 +0200291
292 struct msgb *msg;
293 struct gsm0808_channel_type ct;
294 uint16_t cic = 0004;
295 struct sockaddr_storage ss;
296 struct sockaddr_in sin;
297 struct gsm0808_speech_codec_list sc_list;
298 uint32_t call_id = 0xAABBCCDD;
299
300 memset(&ct, 0, sizeof(ct));
301 ct.ch_indctr = GSM0808_CHAN_SPEECH;
302 ct.ch_rate_type = GSM0808_SPEECH_HALF_PREF;
303 ct.perm_spch[0] = GSM0808_PERM_FR3;
304 ct.perm_spch[1] = GSM0808_PERM_HR3;
305 ct.perm_spch_len = 2;
306
307 memset(&sin, 0, sizeof(sin));
308 sin.sin_family = AF_INET;
309 sin.sin_port = htons(1234);
310 inet_aton("192.168.100.23", &sin.sin_addr);
311
312 memset(&ss, 0, sizeof(ss));
313 memcpy(&ss, &sin, sizeof(sin));
314
315 setup_codec_list(&sc_list);
316
317 printf("Testing creating Assignment Request\n");
318 msg = gsm0808_create_ass(&ct, &cic, NULL, NULL, NULL);
319 OSMO_ASSERT(msg);
320 VERIFY(msg, res1, ARRAY_SIZE(res1));
321 msgb_free(msg);
322
323 msg = gsm0808_create_ass(&ct, &cic, &ss, &sc_list, &call_id);
324 OSMO_ASSERT(msg);
325 VERIFY(msg, res2, ARRAY_SIZE(res2));
326 msgb_free(msg);
327}
328
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100329static void test_create_ass_compl()
330{
331 static const uint8_t res1[] = {
332 0x00, 0x09, 0x02, 0x15, 0x23, 0x21, 0x42, 0x2c,
333 0x11, 0x40, 0x22 };
334 static const uint8_t res2[] = {
335 0x00, 0x07, 0x02, 0x15, 0x23, 0x21, 0x42, 0x2c, 0x11};
336 struct msgb *msg;
337
338 printf("Testing creating Assignment Complete\n");
339 msg = gsm0808_create_assignment_completed(0x23, 0x42, 0x11, 0x22);
340 VERIFY(msg, res1, ARRAY_SIZE(res1));
341 msgb_free(msg);
342
343 msg = gsm0808_create_assignment_completed(0x23, 0x42, 0x11, 0);
344 VERIFY(msg, res2, ARRAY_SIZE(res2));
345 msgb_free(msg);
346}
347
Philipp Maierfa896ab2017-03-27 16:55:32 +0200348static void test_create_ass_compl_aoip()
349{
350 struct sockaddr_storage ss;
351 struct sockaddr_in sin;
352 struct gsm0808_speech_codec sc;
353 struct gsm0808_speech_codec_list sc_list;
354 static const uint8_t res[] =
355 { 0x00, 0x1d, 0x02, 0x15, 0x23, 0x21, 0x42, 0x2c, 0x11, 0x40, 0x22,
356 GSM0808_IE_AOIP_TRASP_ADDR, 0x06, 0xc0, 0xa8, 0x64, 0x17, 0x04,
Philipp Maierbb839662017-06-01 17:11:19 +0200357 0xd2, GSM0808_IE_SPEECH_CODEC, 0x01, GSM0808_SCT_HR1 | 0x90,
Philipp Maier7e27b142018-03-22 17:26:46 +0100358 GSM0808_IE_SPEECH_CODEC_LIST, 0x07, GSM0808_SCT_FR3 | 0x50, 0xef,
359 0xcd, GSM0808_SCT_FR2 | 0xa0, 0x9f, GSM0808_SCT_CSD | 0x90, 0xc0 };
Philipp Maierfa896ab2017-03-27 16:55:32 +0200360 struct msgb *msg;
361
362 memset(&sin, 0, sizeof(sin));
363 sin.sin_family = AF_INET;
364 sin.sin_port = htons(1234);
365 inet_aton("192.168.100.23", &sin.sin_addr);
366
367 memset(&ss, 0, sizeof(ss));
368 memcpy(&ss, &sin, sizeof(sin));
369
370 memset(&sc, 0, sizeof(sc));
371 sc.fi = true;
372 sc.tf = true;
Philipp Maierbb839662017-06-01 17:11:19 +0200373 sc.type = GSM0808_SCT_HR1;
Philipp Maierfa896ab2017-03-27 16:55:32 +0200374
375 setup_codec_list(&sc_list);
376
377 printf("Testing creating Assignment Complete (AoIP)\n");
378 msg = gsm0808_create_ass_compl(0x23, 0x42, 0x11, 0x22,
379 &ss, &sc, &sc_list);
380 VERIFY(msg, res, ARRAY_SIZE(res));
381 msgb_free(msg);
382}
383
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100384static void test_create_ass_fail()
385{
386 static const uint8_t res1[] = { 0x00, 0x04, 0x03, 0x04, 0x01, 0x23 };
387 static const uint8_t res2[] = {
388 0x00, 0x06, 0x03, 0x04, 0x01, 0x23, 0x15, 0x02};
389 uint8_t rr_res = 2;
390 struct msgb *msg;
391
392 printf("Testing creating Assignment Failure\n");
393 msg = gsm0808_create_assignment_failure(0x23, NULL);
394 VERIFY(msg, res1, ARRAY_SIZE(res1));
395 msgb_free(msg);
396
397 msg = gsm0808_create_assignment_failure(0x23, &rr_res);
398 VERIFY(msg, res2, ARRAY_SIZE(res2));
399 msgb_free(msg);
400}
401
Philipp Maierfa896ab2017-03-27 16:55:32 +0200402static void test_create_ass_fail_aoip()
403{
404 static const uint8_t res1[] =
405 { 0x00, 0x0d, 0x03, 0x04, 0x01, 0x23, GSM0808_IE_SPEECH_CODEC_LIST,
Philipp Maier7e27b142018-03-22 17:26:46 +0100406 0x07, GSM0808_SCT_FR3 | 0x50, 0xef, 0xcd, GSM0808_SCT_FR2 | 0xa0,
Philipp Maierbb839662017-06-01 17:11:19 +0200407 0x9f, GSM0808_SCT_CSD | 0x90, 0xc0 };
Philipp Maierfa896ab2017-03-27 16:55:32 +0200408 static const uint8_t res2[] =
409 { 0x00, 0x0f, 0x03, 0x04, 0x01, 0x23, 0x15, 0x02,
Philipp Maier7e27b142018-03-22 17:26:46 +0100410 GSM0808_IE_SPEECH_CODEC_LIST, 0x07, GSM0808_SCT_FR3 | 0x50, 0xef,
411 0xcd, GSM0808_SCT_FR2 | 0xa0, 0x9f, GSM0808_SCT_CSD | 0x90, 0xc0 };
Philipp Maierfa896ab2017-03-27 16:55:32 +0200412 uint8_t rr_res = 2;
413 struct msgb *msg;
414 struct gsm0808_speech_codec_list sc_list;
415
416 setup_codec_list(&sc_list);
417
418 printf("Testing creating Assignment Failure (AoIP)\n");
419 msg = gsm0808_create_ass_fail(0x23, NULL, &sc_list);
420 VERIFY(msg, res1, ARRAY_SIZE(res1));
421 msgb_free(msg);
422
423 msg = gsm0808_create_ass_fail(0x23, &rr_res, &sc_list);
424 VERIFY(msg, res2, ARRAY_SIZE(res2));
425 msgb_free(msg);
426}
427
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100428static void test_create_clear_rqst()
429{
430 static const uint8_t res[] = { 0x00, 0x04, 0x22, 0x04, 0x01, 0x23 };
431 struct msgb *msg;
432
433 printf("Testing creating Clear Request\n");
434 msg = gsm0808_create_clear_rqst(0x23);
435 VERIFY(msg, res, ARRAY_SIZE(res));
436 msgb_free(msg);
437}
438
Philipp Maier3d48ec02017-03-29 17:37:55 +0200439static void test_create_paging()
440{
441 static const uint8_t res[] =
442 { 0x00, 0x10, 0x52, 0x08, 0x08, 0x09, 0x10, 0x10, 0x00, 0x00, 0x00,
443 0x21, 0x43, 0x1a, 0x03, 0x05, 0x23, 0x42 };
444 static const uint8_t res2[] =
445 { 0x00, 0x16, 0x52, 0x08, 0x08, 0x09, 0x10, 0x10, 0x00, 0x00, 0x00,
446 0x21, 0x43, GSM0808_IE_TMSI, 0x04, 0x12, 0x34, 0x56, 0x78, 0x1a,
447 0x03, 0x05, 0x23, 0x42 };
448 static const uint8_t res3[] =
449 { 0x00, 0x18, 0x52, 0x08, 0x08, 0x09, 0x10, 0x10, 0x00, 0x00, 0x00,
450 0x21, 0x43, GSM0808_IE_TMSI, 0x04, 0x12, 0x34, 0x56, 0x78, 0x1a,
451 0x03, 0x05, 0x23, 0x42, GSM0808_IE_CHANNEL_NEEDED,
452 RSL_CHANNEED_TCH_ForH };
453
454 struct msgb *msg;
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100455 struct gsm0808_cell_id_list2 cil;
Philipp Maier3d48ec02017-03-29 17:37:55 +0200456 uint32_t tmsi = 0x12345678;
457 uint8_t chan_needed = RSL_CHANNEED_TCH_ForH;
458
459 char imsi[] = "001010000001234";
460
461 cil.id_discr = CELL_IDENT_LAC;
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100462 cil.id_list[0].lac = 0x2342;
Philipp Maier3d48ec02017-03-29 17:37:55 +0200463 cil.id_list_len = 1;
464
465 printf("Testing creating Paging Request\n");
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100466 msg = gsm0808_create_paging2(imsi, NULL, &cil, NULL);
Philipp Maier3d48ec02017-03-29 17:37:55 +0200467 VERIFY(msg, res, ARRAY_SIZE(res));
468 msgb_free(msg);
469
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100470 msg = gsm0808_create_paging2(imsi, &tmsi, &cil, NULL);
Philipp Maier3d48ec02017-03-29 17:37:55 +0200471 VERIFY(msg, res2, ARRAY_SIZE(res2));
472 msgb_free(msg);
473
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100474 msg = gsm0808_create_paging2(imsi, &tmsi, &cil, &chan_needed);
Philipp Maier3d48ec02017-03-29 17:37:55 +0200475 VERIFY(msg, res3, ARRAY_SIZE(res3));
476 msgb_free(msg);
477}
478
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100479static void test_create_dtap()
480{
481 static const uint8_t res[] = { 0x01, 0x03, 0x02, 0x23, 0x42 };
482 struct msgb *msg, *l3;
483
484 printf("Testing creating DTAP\n");
485 l3 = msgb_alloc_headroom(512, 128, "test");
486 l3->l3h = l3->data;
487 msgb_v_put(l3, 0x23);
488 msgb_v_put(l3, 0x42);
489
490 msg = gsm0808_create_dtap(l3, 0x3);
491 VERIFY(msg, res, ARRAY_SIZE(res));
492 msgb_free(msg);
493 msgb_free(l3);
494}
495
496static void test_prepend_dtap()
497{
498 static const uint8_t res[] = { 0x01, 0x03, 0x02, 0x23, 0x42 };
499 struct msgb *in_msg;
500
501 printf("Testing prepend DTAP\n");
502
503 in_msg = msgb_alloc_headroom(512, 128, "test");
504 msgb_v_put(in_msg, 0x23);
505 msgb_v_put(in_msg, 0x42);
506
507 gsm0808_prepend_dtap_header(in_msg, 0x3);
508 in_msg->l3h = in_msg->data;
509 VERIFY(in_msg, res, ARRAY_SIZE(res));
510 msgb_free(in_msg);
511}
512
Philipp Maier22401432017-03-24 17:59:26 +0100513static void test_enc_dec_aoip_trasp_addr_v4()
514{
515 struct sockaddr_storage enc_addr;
516 struct sockaddr_storage dec_addr;
517 struct sockaddr_in enc_addr_in;
518 struct msgb *msg;
519 uint8_t rc_enc;
520 int rc_dec;
521
522 memset(&enc_addr_in, 0, sizeof(enc_addr_in));
523 enc_addr_in.sin_family = AF_INET;
524 enc_addr_in.sin_port = htons(1234);
525 inet_aton("255.0.255.255", &enc_addr_in.sin_addr);
526
527 memset(&enc_addr, 0, sizeof(enc_addr));
528 memcpy(&enc_addr, &enc_addr_in, sizeof(enc_addr_in));
529
530 msg = msgb_alloc(1024, "output buffer");
531 rc_enc = gsm0808_enc_aoip_trasp_addr(msg, &enc_addr);
532 OSMO_ASSERT(rc_enc == 8);
533 rc_dec =
534 gsm0808_dec_aoip_trasp_addr(&dec_addr, msg->data + 2, msg->len - 2);
535 OSMO_ASSERT(rc_dec == 6);
536 OSMO_ASSERT(memcmp(&enc_addr, &dec_addr, sizeof(enc_addr)) == 0);
537
538 msgb_free(msg);
539}
540
541static void test_enc_dec_aoip_trasp_addr_v6()
542{
543 struct sockaddr_storage enc_addr;
544 struct sockaddr_storage dec_addr;
545 struct sockaddr_in6 enc_addr_in;
546 struct msgb *msg;
547 uint8_t rc_enc;
548 int rc_dec;
549
550 memset(&enc_addr_in, 0, sizeof(enc_addr_in));
551 enc_addr_in.sin6_family = AF_INET6;
552 enc_addr_in.sin6_port = htons(4567);
553 inet_pton(AF_INET6, "2001:0db8:85a3:08d3:1319:8a2e:0370:7344",
554 &enc_addr_in.sin6_addr);
555
556 memset(&enc_addr, 0, sizeof(enc_addr));
557 memcpy(&enc_addr, &enc_addr_in, sizeof(enc_addr_in));
558
559 msg = msgb_alloc(1024, "output buffer");
560 rc_enc = gsm0808_enc_aoip_trasp_addr(msg, &enc_addr);
561 OSMO_ASSERT(rc_enc == 20);
562 rc_dec =
563 gsm0808_dec_aoip_trasp_addr(&dec_addr, msg->data + 2, msg->len - 2);
564 OSMO_ASSERT(rc_dec == 18);
565 OSMO_ASSERT(memcmp(&enc_addr, &dec_addr, sizeof(enc_addr)) == 0);
566
567 msgb_free(msg);
568}
569
Philipp Maier6f725d62017-03-24 18:03:17 +0100570static void test_gsm0808_enc_dec_speech_codec()
571{
Neels Hofmeyr9a4286b2018-04-20 12:27:52 +0200572 struct gsm0808_speech_codec enc_sc = {
573 .pi = true,
574 .tf = true,
575 .type = GSM0808_SCT_FR2,
576 };
577 struct gsm0808_speech_codec dec_sc = {};
Philipp Maier6f725d62017-03-24 18:03:17 +0100578 struct msgb *msg;
579 uint8_t rc_enc;
580 int rc_dec;
581
Philipp Maier6f725d62017-03-24 18:03:17 +0100582 msg = msgb_alloc(1024, "output buffer");
583 rc_enc = gsm0808_enc_speech_codec(msg, &enc_sc);
584 OSMO_ASSERT(rc_enc == 3);
585
586 rc_dec = gsm0808_dec_speech_codec(&dec_sc, msg->data + 2, msg->len - 2);
587 OSMO_ASSERT(rc_dec == 1);
588
589 OSMO_ASSERT(memcmp(&enc_sc, &dec_sc, sizeof(enc_sc)) == 0);
590
591 msgb_free(msg);
592}
593
594
Philipp Maierbb839662017-06-01 17:11:19 +0200595static void test_gsm0808_enc_dec_speech_codec_with_cfg()
596{
Neels Hofmeyrc62c9342018-04-15 23:31:47 +0200597 struct gsm0808_speech_codec enc_sc = {
598 .pi = true,
599 .tf = true,
600 .type = GSM0808_SCT_FR3,
601 .cfg = 0xabcd,
602 };
603 struct gsm0808_speech_codec dec_sc = {};
Philipp Maierbb839662017-06-01 17:11:19 +0200604 struct msgb *msg;
605 uint8_t rc_enc;
606 int rc_dec;
607
Philipp Maierbb839662017-06-01 17:11:19 +0200608 msg = msgb_alloc(1024, "output buffer");
609 rc_enc = gsm0808_enc_speech_codec(msg, &enc_sc);
610 OSMO_ASSERT(rc_enc == 5);
611
612 rc_dec = gsm0808_dec_speech_codec(&dec_sc, msg->data + 2, msg->len - 2);
613 OSMO_ASSERT(rc_dec == 3);
614
615 OSMO_ASSERT(memcmp(&enc_sc, &dec_sc, sizeof(enc_sc)) == 0);
616
617 msgb_free(msg);
618}
619
Philipp Maier6f725d62017-03-24 18:03:17 +0100620static void test_gsm0808_enc_dec_speech_codec_ext_with_cfg()
621{
Neels Hofmeyr9a4286b2018-04-20 12:27:52 +0200622 struct gsm0808_speech_codec enc_sc = {
623 .pi = true,
624 .tf = true,
625 .type = GSM0808_SCT_CSD,
626 .cfg = 0xc0,
627 };
628 struct gsm0808_speech_codec dec_sc = {};
Philipp Maier6f725d62017-03-24 18:03:17 +0100629 struct msgb *msg;
630 uint8_t rc_enc;
631 int rc_dec;
632
Philipp Maier6f725d62017-03-24 18:03:17 +0100633 msg = msgb_alloc(1024, "output buffer");
634 rc_enc = gsm0808_enc_speech_codec(msg, &enc_sc);
Philipp Maierbb839662017-06-01 17:11:19 +0200635 OSMO_ASSERT(rc_enc == 5);
Philipp Maier6f725d62017-03-24 18:03:17 +0100636
637 rc_dec = gsm0808_dec_speech_codec(&dec_sc, msg->data + 2, msg->len - 2);
Philipp Maierbb839662017-06-01 17:11:19 +0200638 OSMO_ASSERT(rc_dec == 3);
Philipp Maier6f725d62017-03-24 18:03:17 +0100639
640 OSMO_ASSERT(memcmp(&enc_sc, &dec_sc, sizeof(enc_sc)) == 0);
641
642 msgb_free(msg);
643}
644
645static void test_gsm0808_enc_dec_speech_codec_list()
646{
Neels Hofmeyr9a4286b2018-04-20 12:27:52 +0200647 struct gsm0808_speech_codec_list enc_scl = {
648 .codec = {
649 {
650 .pi = true,
651 .tf = true,
652 .type = GSM0808_SCT_FR3,
653 .cfg = 0xcdef,
654 },
655
656 {
657 .fi = true,
658 .pt = true,
659 .type = GSM0808_SCT_FR2,
660 },
661
662 {
663 .fi = true,
664 .tf = true,
665 .type = GSM0808_SCT_CSD,
666 .cfg = 0xc0,
667 },
668 },
669 .len = 3,
670 };
671 struct gsm0808_speech_codec_list dec_scl = {};
Philipp Maier6f725d62017-03-24 18:03:17 +0100672 struct msgb *msg;
673 uint8_t rc_enc;
674 int rc_dec;
675
Philipp Maier6f725d62017-03-24 18:03:17 +0100676 msg = msgb_alloc(1024, "output buffer");
677 rc_enc = gsm0808_enc_speech_codec_list(msg, &enc_scl);
678 OSMO_ASSERT(rc_enc == 9);
679
680 rc_dec = gsm0808_dec_speech_codec_list(&dec_scl, msg->data + 2, msg->len - 2);
681 OSMO_ASSERT(rc_dec == 7);
682
683 OSMO_ASSERT(memcmp(&enc_scl, &dec_scl, sizeof(enc_scl)) == 0);
684
685 msgb_free(msg);
686}
687
Philipp Maiere0c65302017-03-28 17:05:40 +0200688static void test_gsm0808_enc_dec_channel_type()
689{
Neels Hofmeyr9a4286b2018-04-20 12:27:52 +0200690 struct gsm0808_channel_type enc_ct = {
691 .ch_indctr = GSM0808_CHAN_SPEECH,
692 .ch_rate_type = GSM0808_SPEECH_HALF_PREF,
693 .perm_spch = { GSM0808_PERM_FR3, GSM0808_PERM_HR3 },
694 .perm_spch_len = 2,
695 };
696 struct gsm0808_channel_type dec_ct = {};
Philipp Maiere0c65302017-03-28 17:05:40 +0200697 struct msgb *msg;
698 uint8_t ct_enc_expected[] = { GSM0808_IE_CHANNEL_TYPE,
699 0x04, 0x01, 0x0b, 0xa1, 0x25
700 };
701 uint8_t rc_enc;
702 int rc_dec;
703
Philipp Maiere0c65302017-03-28 17:05:40 +0200704 msg = msgb_alloc(1024, "output buffer");
705 rc_enc = gsm0808_enc_channel_type(msg, &enc_ct);
706 OSMO_ASSERT(rc_enc == 6);
707 OSMO_ASSERT(memcmp(ct_enc_expected, msg->data, msg->len) == 0);
708
709 rc_dec = gsm0808_dec_channel_type(&dec_ct, msg->data + 2, msg->len - 2);
710 OSMO_ASSERT(rc_dec == 4);
711 OSMO_ASSERT(memcmp(&enc_ct, &dec_ct, sizeof(enc_ct)) == 0);
712
713 msgb_free(msg);
714}
715
Philipp Maier14e76b92017-03-28 18:36:52 +0200716static void test_gsm0808_enc_dec_encrypt_info()
717{
Neels Hofmeyr9a4286b2018-04-20 12:27:52 +0200718 struct gsm0808_encrypt_info enc_ei = {
719 .perm_algo = { GSM0808_ALG_ID_A5_0, GSM0808_ALG_ID_A5_1 },
720 .perm_algo_len = 2,
721 .key = { 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x23, 0x42, },
722 .key_len = 8,
723 };
724 struct gsm0808_encrypt_info dec_ei = {};
Philipp Maier14e76b92017-03-28 18:36:52 +0200725 struct msgb *msg;
726 uint8_t ei_enc_expected[] =
727 { GSM0808_IE_ENCRYPTION_INFORMATION, 0x09, 0x03, 0xaa, 0xbb,
728 0xcc, 0xdd, 0xee, 0xff, 0x23, 0x42
729 };
730 uint8_t rc_enc;
731 int rc_dec;
732
Philipp Maier14e76b92017-03-28 18:36:52 +0200733 msg = msgb_alloc(1024, "output buffer");
734 rc_enc = gsm0808_enc_encrypt_info(msg, &enc_ei);
735 OSMO_ASSERT(rc_enc == 11);
736 OSMO_ASSERT(memcmp(ei_enc_expected, msg->data, msg->len) == 0);
737
738 rc_dec = gsm0808_dec_encrypt_info(&dec_ei, msg->data + 2, msg->len - 2);
739 OSMO_ASSERT(rc_dec == 9);
740
741 OSMO_ASSERT(memcmp(&enc_ei, &dec_ei, sizeof(enc_ei)) == 0);
742
743 msgb_free(msg);
744}
745
Neels Hofmeyr066473f2018-04-13 04:10:58 +0200746#define EXPECT_ENCODED(hexstr) do { \
747 const char *enc_str = msgb_hexdump(msg); \
748 printf("%s: encoded: %s(rc = %u)\n", __func__, enc_str, rc_enc); \
749 OSMO_ASSERT(strcmp(enc_str, hexstr " ") == 0); \
750 OSMO_ASSERT(rc_enc == msg->len); \
751 } while(0)
752
Philipp Maier783047e2017-03-29 11:35:50 +0200753static void test_gsm0808_enc_dec_cell_id_list_lac()
754{
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100755 struct gsm0808_cell_id_list2 enc_cil;
756 struct gsm0808_cell_id_list2 dec_cil;
Philipp Maier783047e2017-03-29 11:35:50 +0200757 struct msgb *msg;
758 uint8_t rc_enc;
759 int rc_dec;
760
761 memset(&enc_cil, 0, sizeof(enc_cil));
762 enc_cil.id_discr = CELL_IDENT_LAC;
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100763 enc_cil.id_list[0].lac = 0x0124;
Neels Hofmeyrdb2fa4e2018-04-13 04:11:20 +0200764 enc_cil.id_list[1].lac = 0xABCD;
765 enc_cil.id_list[2].lac = 0x5678;
Philipp Maier783047e2017-03-29 11:35:50 +0200766 enc_cil.id_list_len = 3;
767
768 msg = msgb_alloc(1024, "output buffer");
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100769 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
Neels Hofmeyrdb2fa4e2018-04-13 04:11:20 +0200770 EXPECT_ENCODED("1a 07 05 01 24 ab cd 56 78");
Philipp Maier783047e2017-03-29 11:35:50 +0200771
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100772 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
Philipp Maier783047e2017-03-29 11:35:50 +0200773 OSMO_ASSERT(rc_dec == 7);
774
775 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
776
777 msgb_free(msg);
778}
779
780static void test_gsm0808_enc_dec_cell_id_list_single_lac()
781{
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100782 struct gsm0808_cell_id_list2 enc_cil;
783 struct gsm0808_cell_id_list2 dec_cil;
Philipp Maier783047e2017-03-29 11:35:50 +0200784 struct msgb *msg;
785 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x03,
786 0x05, 0x23, 0x42
787 };
788 uint8_t rc_enc;
789 int rc_dec;
790
791 memset(&enc_cil, 0, sizeof(enc_cil));
792 enc_cil.id_discr = CELL_IDENT_LAC;
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100793 enc_cil.id_list[0].lac = 0x2342;
Philipp Maier783047e2017-03-29 11:35:50 +0200794 enc_cil.id_list_len = 1;
795
796 msg = msgb_alloc(1024, "output buffer");
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100797 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
Philipp Maier783047e2017-03-29 11:35:50 +0200798 OSMO_ASSERT(rc_enc == 5);
799 OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0);
800
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100801 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
Philipp Maier783047e2017-03-29 11:35:50 +0200802 OSMO_ASSERT(rc_dec == 3);
803
804 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
805
806 msgb_free(msg);
807}
808
Stefan Sperlinge1a86742018-03-15 18:05:02 +0100809static void test_gsm0808_enc_dec_cell_id_list_multi_lac()
810{
811 struct gsm0808_cell_id_list2 enc_cil;
812 struct gsm0808_cell_id_list2 dec_cil;
813 struct msgb *msg;
814 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x0b, 0x05,
815 0x23, 0x42,
816 0x24, 0x43,
817 0x25, 0x44,
818 0x26, 0x45,
819 0x27, 0x46
820 };
821 uint8_t rc_enc;
822 int rc_dec;
823
824 memset(&enc_cil, 0, sizeof(enc_cil));
825 enc_cil.id_discr = CELL_IDENT_LAC;
826 enc_cil.id_list[0].lac = 0x2342;
827 enc_cil.id_list[1].lac = 0x2443;
828 enc_cil.id_list[2].lac = 0x2544;
829 enc_cil.id_list[3].lac = 0x2645;
830 enc_cil.id_list[4].lac = 0x2746;
831 enc_cil.id_list_len = 5;
832
833 msg = msgb_alloc(1024, "output buffer");
834 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
835 OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected));
836 OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0);
837
838 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
839 OSMO_ASSERT(rc_dec == msg->len - 2);
840 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
841
842 msgb_free(msg);
843}
844
Philipp Maier783047e2017-03-29 11:35:50 +0200845static void test_gsm0808_enc_dec_cell_id_list_bss()
846{
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100847 struct gsm0808_cell_id_list2 enc_cil;
848 struct gsm0808_cell_id_list2 dec_cil;
Philipp Maier783047e2017-03-29 11:35:50 +0200849 struct msgb *msg;
850 uint8_t rc_enc;
851 int rc_dec;
852
853 memset(&enc_cil, 0, sizeof(enc_cil));
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100854 enc_cil.id_discr = CELL_IDENT_BSS;
Philipp Maier783047e2017-03-29 11:35:50 +0200855
856 msg = msgb_alloc(1024, "output buffer");
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100857 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
Philipp Maier783047e2017-03-29 11:35:50 +0200858 OSMO_ASSERT(rc_enc == 3);
859
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100860 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
Philipp Maier783047e2017-03-29 11:35:50 +0200861 OSMO_ASSERT(rc_dec == 1);
862
863 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
864
865 msgb_free(msg);
866}
867
Stefan Sperling23381452018-03-15 19:38:15 +0100868static void test_gsm0808_enc_dec_cell_id_list_multi_lai_and_lac()
869{
870 struct gsm0808_cell_id_list2 enc_cil;
871 struct gsm0808_cell_id_list2 dec_cil;
872 struct osmo_location_area_id id;
873 struct msgb *msg;
874 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x10, 0x04,
875 0x92, 0x61, 0x54, 0x23, 0x42,
876 0x92, 0x72, 0x54, 0x24, 0x43,
877 0x92, 0x83, 0x54, 0x25, 0x44
878 };
879 uint8_t rc_enc;
880 int rc_dec, i;
881
882 memset(&enc_cil, 0, sizeof(enc_cil));
883 enc_cil.id_discr = CELL_IDENT_LAI_AND_LAC;
884
885 id.plmn.mcc = 0x123;
886 osmo_mnc_from_str("456", &id.plmn.mnc, &id.plmn.mnc_3_digits);
887 id.lac = 0x2342;
888 memcpy(&enc_cil.id_list[0].lai_and_lac, &id, sizeof(id));
889
890 id.plmn.mcc = 0x124;
891 osmo_mnc_from_str("457", &id.plmn.mnc, &id.plmn.mnc_3_digits);
892 id.lac = 0x2443;
893 memcpy(&enc_cil.id_list[1].lai_and_lac, &id, sizeof(id));
894
895 id.plmn.mcc = 0x125;
896 osmo_mnc_from_str("458", &id.plmn.mnc, &id.plmn.mnc_3_digits);
897 id.lac = 0x2544;
898 memcpy(&enc_cil.id_list[2].lai_and_lac, &id, sizeof(id));
899
900 enc_cil.id_list_len = 3;
901
902 msg = msgb_alloc(1024, "output buffer");
903 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
904 OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected));
905 OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0);
906
907 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
908 OSMO_ASSERT(rc_dec == msg->len - 2);
909
910 OSMO_ASSERT(dec_cil.id_list_len == 3);
911 /* Check MAXLEN elements to ensure everything has been initialized. */
912 for (i = 0; i < GSM0808_CELL_ID_LIST2_MAXLEN; i++) {
913 struct osmo_location_area_id *enc_id;
914 struct osmo_location_area_id *dec_id;
915 enc_id = &enc_cil.id_list[i].lai_and_lac;
916 dec_id = &dec_cil.id_list[i].lai_and_lac;
917 OSMO_ASSERT(osmo_plmn_cmp(&enc_id->plmn, &dec_id->plmn) == 0);
918 OSMO_ASSERT(enc_id->lac == dec_id->lac);
919 }
920
921 msgb_free(msg);
922}
923
Stefan Sperling9c62fc62018-03-16 10:23:34 +0100924static void test_gsm0808_enc_dec_cell_id_list_multi_ci()
925{
926 struct gsm0808_cell_id_list2 enc_cil;
927 struct gsm0808_cell_id_list2 dec_cil;
928 struct msgb *msg;
929 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x09, 0x02,
930 0x00, 0x01,
931 0x00, 0x02,
932 0x00, 0x77,
933 0x01, 0xff,
934 };
935 uint8_t rc_enc;
936 int rc_dec;
937
938 memset(&enc_cil, 0, sizeof(enc_cil));
939 enc_cil.id_discr = CELL_IDENT_CI;
940 enc_cil.id_list[0].ci = 1;
941 enc_cil.id_list[1].ci = 2;
942 enc_cil.id_list[2].ci = 119;
943 enc_cil.id_list[3].ci = 511;
944 enc_cil.id_list_len = 4;
945
946 msg = msgb_alloc(1024, "output buffer");
947 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
948 OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected));
949 OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0);
950
951 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
952 OSMO_ASSERT(rc_dec == msg->len - 2);
953 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
954
955 msgb_free(msg);
956}
957
Stefan Sperlinged4327c2018-03-16 11:02:59 +0100958static void test_gsm0808_enc_dec_cell_id_list_multi_lac_and_ci()
959{
960 struct gsm0808_cell_id_list2 enc_cil;
961 struct gsm0808_cell_id_list2 dec_cil;
962 struct msgb *msg;
963 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x15, 0x01,
964 0x23, 0x42, 0x00, 0x01,
965 0x24, 0x43, 0x00, 0x02,
966 0x25, 0x44, 0x00, 0x77,
967 0x26, 0x45, 0x01, 0xff,
968 0x27, 0x46, 0x02, 0xfe,
969 };
970 uint8_t rc_enc;
971 int rc_dec;
972
973 memset(&enc_cil, 0, sizeof(enc_cil));
974 enc_cil.id_discr = CELL_IDENT_LAC_AND_CI;
975 enc_cil.id_list[0].lac_and_ci.lac = 0x2342;
976 enc_cil.id_list[0].lac_and_ci.ci = 1;
977 enc_cil.id_list[1].lac_and_ci.lac = 0x2443;
978 enc_cil.id_list[1].lac_and_ci.ci = 2;
979 enc_cil.id_list[2].lac_and_ci.lac = 0x2544;
980 enc_cil.id_list[2].lac_and_ci.ci = 119;
981 enc_cil.id_list[3].lac_and_ci.lac = 0x2645;
982 enc_cil.id_list[3].lac_and_ci.ci = 511;
983 enc_cil.id_list[4].lac_and_ci.lac = 0x2746;
984 enc_cil.id_list[4].lac_and_ci.ci = 766;
985 enc_cil.id_list_len = 5;
986
987 msg = msgb_alloc(1024, "output buffer");
988 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
989 OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected));
990 OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0);
991
992 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
993 OSMO_ASSERT(rc_dec == msg->len - 2);
994 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
995
996 msgb_free(msg);
997}
998
Stefan Sperling483f3862018-03-16 12:21:26 +0100999static void test_gsm0808_enc_dec_cell_id_list_multi_global()
1000{
1001 struct gsm0808_cell_id_list2 enc_cil;
1002 struct gsm0808_cell_id_list2 dec_cil;
1003 struct msgb *msg;
1004 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x16, 0x00,
Neels Hofmeyr473485c2018-03-23 02:04:18 +01001005 0x21, 0x63, 0x54, 0x23, 0x42, 0x00, 0x1,
Neels Hofmeyrc44fc232018-03-23 02:15:12 +01001006 0x21, 0xf4, 0x75, 0x24, 0x43, 0x00, 0x2,
Neels Hofmeyr8b8cd932018-03-23 01:47:37 +01001007 0x21, 0x75, 0x00, 0x25, 0x44, 0x00, 0x77
Stefan Sperling483f3862018-03-16 12:21:26 +01001008 };
Stefan Sperling483f3862018-03-16 12:21:26 +01001009 uint8_t rc_enc;
1010 int rc_dec, i;
1011
Neels Hofmeyrc1991df2018-03-23 02:00:00 +01001012 enc_cil = (struct gsm0808_cell_id_list2){
1013 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1014 .id_list_len = 3,
1015 .id_list = {
1016 {
1017 .global = {
Neels Hofmeyr473485c2018-03-23 02:04:18 +01001018 .lai = { .plmn = { .mcc = 123, .mnc = 456 },
Neels Hofmeyrc1991df2018-03-23 02:00:00 +01001019 .lac = 0x2342 },
1020 .cell_identity = 1,
1021 }
1022 },
1023 {
1024 .global = {
Neels Hofmeyrc44fc232018-03-23 02:15:12 +01001025 .lai = { .plmn = { .mcc = 124, .mnc = 57 },
Neels Hofmeyrc1991df2018-03-23 02:00:00 +01001026 .lac = 0x2443 },
1027 .cell_identity = 2,
1028 }
1029 },
1030 {
1031 .global = {
Neels Hofmeyrc44fc232018-03-23 02:15:12 +01001032 .lai = { .plmn = { .mcc = 125, .mnc = 7,
1033 .mnc_3_digits = true },
Neels Hofmeyrc1991df2018-03-23 02:00:00 +01001034 .lac = 0x2544 },
1035 .cell_identity = 119,
1036 }
1037 },
1038 }
1039 };
Stefan Sperling483f3862018-03-16 12:21:26 +01001040
1041 msg = msgb_alloc(1024, "output buffer");
1042 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
1043 OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected));
Neels Hofmeyrc1991df2018-03-23 02:00:00 +01001044 if (memcmp(cil_enc_expected, msg->data, msg->len)) {
1045 printf(" got: %s\n", osmo_hexdump(msg->data, msg->len));
1046 printf("expect: %s\n", osmo_hexdump(cil_enc_expected, sizeof(cil_enc_expected)));
1047 OSMO_ASSERT(false);
1048 }
Stefan Sperling483f3862018-03-16 12:21:26 +01001049
1050 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
1051 OSMO_ASSERT(rc_dec == msg->len - 2);
1052
1053 /* Check MAXLEN elements to ensure everything has been initialized. */
1054 for (i = 0; i < GSM0808_CELL_ID_LIST2_MAXLEN; i++) {
1055 struct osmo_cell_global_id *enc_id;
1056 struct osmo_cell_global_id *dec_id;
1057 enc_id = &enc_cil.id_list[i].global;
1058 dec_id = &dec_cil.id_list[i].global;
1059 OSMO_ASSERT(osmo_plmn_cmp(&enc_id->lai.plmn, &dec_id->lai.plmn) == 0);
1060 OSMO_ASSERT(enc_id->lai.lac == dec_id->lai.lac);
1061 OSMO_ASSERT(enc_id->cell_identity == dec_id->cell_identity);
1062 }
1063
1064 msgb_free(msg);
1065}
1066
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001067static void print_cil(const struct gsm0808_cell_id_list2 *cil)
1068{
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001069 printf(" cell_id_list == %s\n", gsm0808_cell_id_list_name(cil));
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001070}
1071
1072void test_cell_id_list_add() {
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001073 size_t zu;
1074
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001075 const struct gsm0808_cell_id_list2 cgi1 = {
1076 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1077 .id_list_len = 1,
1078 .id_list = {
1079 {
1080 .global = {
1081 .lai = {
1082 .plmn = { .mcc = 1, .mnc = 2, .mnc_3_digits = false },
1083 .lac = 3,
1084 },
1085 .cell_identity = 4,
1086 }
1087 },
1088 },
1089 };
1090
1091 const struct gsm0808_cell_id_list2 cgi2 = {
1092 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1093 .id_list_len = 2,
1094 .id_list = {
1095 {
1096 .global = {
1097 .lai = {
1098 .plmn = { .mcc = 1, .mnc = 2, .mnc_3_digits = true },
1099 .lac = 3,
1100 },
1101 .cell_identity = 4,
1102 }
1103 },
1104 {
1105 .global = {
1106 .lai = {
1107 .plmn = { .mcc = 5, .mnc = 6, .mnc_3_digits = true },
1108 .lac = 7,
1109 },
1110 .cell_identity = 8,
1111 }
1112 },
1113 },
1114 };
1115
1116 const struct gsm0808_cell_id_list2 cgi2a = {
1117 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1118 .id_list_len = 2,
1119 .id_list = {
1120 {
1121 .global = cgi2.id_list[0].global
1122 },
1123 {
1124 .global = {
1125 .lai = {
1126 .plmn = { .mcc = 9, .mnc = 10, .mnc_3_digits = true },
1127 .lac = 11,
1128 },
1129 .cell_identity = 12,
1130 }
1131 },
1132 },
1133 };
1134
1135 const struct gsm0808_cell_id_list2 cgi3 = {
1136 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1137 .id_list_len = 2,
1138 .id_list = {
1139 {
1140 .global = {
1141 .lai = {
1142 .plmn = { .mcc = 13, .mnc = 14, .mnc_3_digits = true },
1143 .lac = 15,
1144 },
1145 .cell_identity = 16,
1146 }
1147 },
1148 {
1149 .global = {
1150 .lai = {
1151 .plmn = { .mcc = 16, .mnc = 17, .mnc_3_digits = true },
1152 .lac = 18,
1153 },
1154 .cell_identity = 19,
1155 }
1156 },
1157 },
1158 };
1159
1160
1161 const struct gsm0808_cell_id_list2 lac1 = {
1162 .id_discr = CELL_IDENT_LAC,
1163 .id_list_len = 1,
1164 .id_list = {
1165 {
1166 .lac = 123
1167 },
1168 },
1169 };
1170
1171 const struct gsm0808_cell_id_list2 lac2 = {
1172 .id_discr = CELL_IDENT_LAC,
1173 .id_list_len = 2,
1174 .id_list = {
1175 {
1176 .lac = 456
1177 },
1178 {
1179 .lac = 789
1180 },
1181 },
1182 };
1183
1184 struct gsm0808_cell_id_list2 cil = {};
1185
1186 printf("------- %s\n", __func__);
1187
1188 print_cil(&cil);
1189
1190#define ADD_QUIET(other_cil, expect_rc) do { \
1191 int rc = gsm0808_cell_id_list_add(&cil, &other_cil); \
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001192 printf("gsm0808_cell_id_list_add(&cil, &" #other_cil ") --> rc = %d\n", rc); \
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001193 OSMO_ASSERT(rc == expect_rc); \
1194 } while(0)
1195
1196#define ADD(other_cil, expect_rc) ADD_QUIET(other_cil, expect_rc); print_cil(&cil)
1197
1198 ADD(lac1, 1);
1199 ADD(lac1, 0);
1200 ADD(lac2, 2);
1201 ADD(lac2, 0);
1202 ADD(cil, 0);
1203 ADD(cgi1, -EINVAL);
1204
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001205 printf("* can't add to BSS list\n");
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001206 cil.id_list_len = 0;
1207 cil.id_discr = CELL_IDENT_BSS;
1208 print_cil(&cil);
1209 ADD(lac1, -EINVAL);
1210
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001211 printf("* other types (including NO_CELL) take on new type iff empty\n");
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001212 cil.id_list_len = 0;
1213 cil.id_discr = CELL_IDENT_NO_CELL;
1214 print_cil(&cil);
1215 ADD(cgi1, 1);
1216 ADD(cgi1, 0);
1217 ADD(cgi2, 2);
1218 ADD(cgi2, 0);
1219
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001220 printf("* test gsm0808_cell_id_list_name_buf()'s return val\n");
1221 zu = strlen(gsm0808_cell_id_list_name(&cil));
1222 printf(" strlen(gsm0808_cell_id_list_name(cil)) == %zu\n", zu);
1223 zu ++;
1224 while (1) {
1225 char buf[128] = "?";
1226 int rc;
1227 OSMO_ASSERT(zu < sizeof(buf));
1228 buf[zu] = '#';
1229 rc = gsm0808_cell_id_list_name_buf(buf, zu, &cil);
1230 printf(" gsm0808_cell_id_list_name_buf(buf, %zu, cil)) == %d \"%s\"\n",
1231 zu, rc, buf);
1232 OSMO_ASSERT(buf[zu] == '#');
1233 if (!zu)
1234 break;
1235 zu /= 2;
1236 }
1237
1238 printf("* list-full behavior\n");
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001239 cil.id_list_len = GSM0808_CELL_ID_LIST2_MAXLEN - 1;
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001240 printf("cil.id_list_len = %u\n", cil.id_list_len);
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001241 ADD_QUIET(cgi2a, 1);
1242 printf("cil.id_list_len = %u\n", cil.id_list_len);
1243
1244 cil.id_list_len = GSM0808_CELL_ID_LIST2_MAXLEN - 1;
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001245 printf("cil.id_list_len = %u\n", cil.id_list_len);
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001246 ADD_QUIET(cgi3, -ENOSPC);
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001247 printf("cil.id_list_len = %u\n", cil.id_list_len);
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001248 ADD_QUIET(cgi2a, -ENOSPC);
1249 printf("cil.id_list_len = %u\n", cil.id_list_len);
1250
1251 printf("------- %s done\n", __func__);
1252}
1253
Neels Hofmeyr250e7f72018-04-13 03:30:14 +02001254static void test_gsm0808_enc_dec_cell_id_lac()
1255{
1256 struct gsm0808_cell_id enc_ci = {
1257 .id_discr = CELL_IDENT_LAC,
1258 .id.lac = 0x0124,
1259 };
1260 struct gsm0808_cell_id dec_ci;
1261 struct msgb *msg;
1262 uint8_t rc_enc;
1263 int rc_dec;
1264
1265 memset(&dec_ci, 0xa5, sizeof(dec_ci));
1266
1267 msg = msgb_alloc(1024, "output buffer");
1268 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1269 EXPECT_ENCODED("05 03 05 01 24");
1270
1271 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1272 OSMO_ASSERT(rc_dec == 3);
1273
1274 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr
1275 && enc_ci.id.lac == dec_ci.id.lac);
1276
1277 msgb_free(msg);
1278}
1279
1280static void test_gsm0808_enc_dec_cell_id_bss()
1281{
1282 struct gsm0808_cell_id enc_ci = {
1283 .id_discr = CELL_IDENT_BSS,
1284 };
1285 struct gsm0808_cell_id dec_ci;
1286 struct msgb *msg;
1287 uint8_t rc_enc;
1288 int rc_dec;
1289
1290 msg = msgb_alloc(1024, "output buffer");
1291 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1292 EXPECT_ENCODED("05 01 06");
1293
1294 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1295 OSMO_ASSERT(rc_dec == 1);
1296
1297 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr);
1298
1299 msgb_free(msg);
1300}
1301
1302static void test_gsm0808_enc_dec_cell_id_no_cell()
1303{
1304 struct gsm0808_cell_id enc_ci = {
1305 .id_discr = CELL_IDENT_NO_CELL,
1306 };
1307 struct gsm0808_cell_id dec_ci;
1308 struct msgb *msg;
1309 uint8_t rc_enc;
1310 int rc_dec;
1311
1312 msg = msgb_alloc(1024, "output buffer");
1313 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1314 EXPECT_ENCODED("05 01 03");
1315
1316 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1317 OSMO_ASSERT(rc_dec == 1);
1318
1319 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr);
1320
1321 msgb_free(msg);
1322}
1323
1324static void test_gsm0808_enc_dec_cell_id_lai_and_lac()
1325{
1326 struct gsm0808_cell_id enc_ci = {
1327 .id_discr = CELL_IDENT_LAI_AND_LAC,
1328 .id.lai_and_lac = {
1329 .plmn = {
1330 .mcc = 123,
1331 .mnc = 456,
1332 },
1333 .lac = 0x2342,
1334 },
1335 };
1336 struct gsm0808_cell_id dec_ci;
1337 struct msgb *msg;
1338 uint8_t rc_enc;
1339 int rc_dec;
1340
1341 msg = msgb_alloc(1024, "output buffer");
1342 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1343 EXPECT_ENCODED("05 06 04 21 63 54 23 42");
1344
1345 memset(&dec_ci, 0xa5, sizeof(dec_ci));
1346 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1347 OSMO_ASSERT(rc_dec == msg->len - 2);
1348
1349 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr
1350 && osmo_plmn_cmp(&enc_ci.id.lai_and_lac.plmn, &dec_ci.id.lai_and_lac.plmn) == 0
1351 && enc_ci.id.lai_and_lac.lac == dec_ci.id.lai_and_lac.lac);
1352 msgb_free(msg);
1353}
1354
1355static void test_gsm0808_enc_dec_cell_id_ci()
1356{
1357 struct gsm0808_cell_id enc_ci = {
1358 .id_discr = CELL_IDENT_CI,
1359 .id.ci = 0x423,
1360 };
1361 struct gsm0808_cell_id dec_ci;
1362 struct msgb *msg;
1363 uint8_t rc_enc;
1364 int rc_dec;
1365
1366 msg = msgb_alloc(1024, "output buffer");
1367 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1368 EXPECT_ENCODED("05 03 02 04 23");
1369
1370 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1371 OSMO_ASSERT(rc_dec == msg->len - 2);
1372 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr
1373 && enc_ci.id.ci == dec_ci.id.ci);
1374
1375 msgb_free(msg);
1376}
1377
1378static void test_gsm0808_enc_dec_cell_id_lac_and_ci()
1379{
1380 struct gsm0808_cell_id enc_ci = {
1381 .id_discr = CELL_IDENT_LAC_AND_CI,
1382 .id.lac_and_ci = {
1383 .lac = 0x423,
1384 .ci = 0x235,
1385 },
1386 };
1387 struct gsm0808_cell_id dec_ci;
1388 struct msgb *msg;
1389 uint8_t rc_enc;
1390 int rc_dec;
1391
1392 msg = msgb_alloc(1024, "output buffer");
1393 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1394 EXPECT_ENCODED("05 05 01 04 23 02 35");
1395
1396 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1397 OSMO_ASSERT(rc_dec == msg->len - 2);
1398 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr
1399 && enc_ci.id.lac_and_ci.lac == dec_ci.id.lac_and_ci.lac
1400 && enc_ci.id.lac_and_ci.ci == dec_ci.id.lac_and_ci.ci);
1401
1402 msgb_free(msg);
1403}
1404
1405static void test_gsm0808_enc_dec_cell_id_global()
1406{
1407 struct gsm0808_cell_id enc_ci = {
1408 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1409 .id.global = {
1410 .lai = {
1411 .plmn = { .mcc = 123, .mnc = 456 },
1412 .lac = 0x2342
1413 },
1414 .cell_identity = 0x423,
1415 }
1416 };
1417 struct gsm0808_cell_id dec_ci;
1418 struct msgb *msg;
1419 uint8_t rc_enc;
1420 int rc_dec;
1421
1422 msg = msgb_alloc(1024, "output buffer");
1423 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1424 EXPECT_ENCODED("05 08 00 21 63 54 23 42 04 23");
1425
1426 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1427 OSMO_ASSERT(rc_dec == msg->len - 2);
1428
1429 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr
1430 && osmo_plmn_cmp(&enc_ci.id.global.lai.plmn,
1431 &dec_ci.id.global.lai.plmn) == 0
1432 && enc_ci.id.global.lai.lac == dec_ci.id.global.lai.lac
1433 && enc_ci.id.global.cell_identity == dec_ci.id.global.cell_identity);
1434 msgb_free(msg);
1435}
1436
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01001437int main(int argc, char **argv)
1438{
1439 printf("Testing generation of GSM0808 messages\n");
1440 test_create_layer3();
Philipp Maierfa896ab2017-03-27 16:55:32 +02001441 test_create_layer3_aoip();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01001442 test_create_reset();
Philipp Maier15596e22017-04-05 17:55:27 +02001443 test_create_reset_ack();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01001444 test_create_clear_command();
1445 test_create_clear_complete();
Philipp Maierb478dd32017-03-29 15:50:05 +02001446 test_create_cipher();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01001447 test_create_cipher_complete();
1448 test_create_cipher_reject();
1449 test_create_cm_u();
1450 test_create_sapi_reject();
Philipp Maierc6144a22017-03-29 17:53:43 +02001451 test_create_ass();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01001452 test_create_ass_compl();
Philipp Maierfa896ab2017-03-27 16:55:32 +02001453 test_create_ass_compl_aoip();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01001454 test_create_ass_fail();
Philipp Maierfa896ab2017-03-27 16:55:32 +02001455 test_create_ass_fail_aoip();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01001456 test_create_clear_rqst();
Philipp Maier3d48ec02017-03-29 17:37:55 +02001457 test_create_paging();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01001458 test_create_dtap();
1459 test_prepend_dtap();
Philipp Maier22401432017-03-24 17:59:26 +01001460 test_enc_dec_aoip_trasp_addr_v4();
1461 test_enc_dec_aoip_trasp_addr_v6();
Philipp Maier6f725d62017-03-24 18:03:17 +01001462 test_gsm0808_enc_dec_speech_codec();
Philipp Maier6f725d62017-03-24 18:03:17 +01001463 test_gsm0808_enc_dec_speech_codec_ext_with_cfg();
Philipp Maierbb839662017-06-01 17:11:19 +02001464 test_gsm0808_enc_dec_speech_codec_with_cfg();
Philipp Maier6f725d62017-03-24 18:03:17 +01001465 test_gsm0808_enc_dec_speech_codec_list();
Philipp Maiere0c65302017-03-28 17:05:40 +02001466 test_gsm0808_enc_dec_channel_type();
Philipp Maier14e76b92017-03-28 18:36:52 +02001467 test_gsm0808_enc_dec_encrypt_info();
Neels Hofmeyr250e7f72018-04-13 03:30:14 +02001468
Philipp Maier783047e2017-03-29 11:35:50 +02001469 test_gsm0808_enc_dec_cell_id_list_lac();
1470 test_gsm0808_enc_dec_cell_id_list_single_lac();
Stefan Sperlinge1a86742018-03-15 18:05:02 +01001471 test_gsm0808_enc_dec_cell_id_list_multi_lac();
Philipp Maier783047e2017-03-29 11:35:50 +02001472 test_gsm0808_enc_dec_cell_id_list_bss();
Stefan Sperling23381452018-03-15 19:38:15 +01001473 test_gsm0808_enc_dec_cell_id_list_multi_lai_and_lac();
Stefan Sperling9c62fc62018-03-16 10:23:34 +01001474 test_gsm0808_enc_dec_cell_id_list_multi_ci();
Stefan Sperlinged4327c2018-03-16 11:02:59 +01001475 test_gsm0808_enc_dec_cell_id_list_multi_lac_and_ci();
Stefan Sperling483f3862018-03-16 12:21:26 +01001476 test_gsm0808_enc_dec_cell_id_list_multi_global();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01001477
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001478 test_cell_id_list_add();
1479
Neels Hofmeyr250e7f72018-04-13 03:30:14 +02001480 test_gsm0808_enc_dec_cell_id_lac();
1481 test_gsm0808_enc_dec_cell_id_bss();
1482 test_gsm0808_enc_dec_cell_id_no_cell();
1483 test_gsm0808_enc_dec_cell_id_lai_and_lac();
1484 test_gsm0808_enc_dec_cell_id_ci();
1485 test_gsm0808_enc_dec_cell_id_lac_and_ci();
1486 test_gsm0808_enc_dec_cell_id_global();
1487
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01001488 printf("Done\n");
1489 return EXIT_SUCCESS;
1490}