blob: 65fef53ad321b3018a9f369d6f2519a3c6d80234 [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>
Max969fb2e2018-12-10 11:01:10 +010025#include <osmocom/core/logging.h>
26#include <osmocom/core/application.h>
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +010027
28#include <stdio.h>
29#include <stdlib.h>
Philipp Maier22401432017-03-24 17:59:26 +010030#include <sys/socket.h>
31#include <netinet/in.h>
32#include <arpa/inet.h>
Neels Hofmeyr74663d92018-03-23 01:46:42 +010033#include <errno.h>
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +010034
Philipp Maier4f4905f2018-11-30 13:36:12 +010035#define EXPECT_ENCODED(hexstr) do { \
36 const char *enc_str = msgb_hexdump(msg); \
37 printf("%s: encoded: %s(rc = %u)\n", __func__, enc_str, rc_enc); \
38 OSMO_ASSERT(strcmp(enc_str, hexstr " ") == 0); \
39 OSMO_ASSERT(rc_enc == msg->len); \
40 } while(0)
41
Vadim Yanitskiycf6ee642018-12-20 05:23:00 +070042#define VERIFY(msg, data, data_len) do { \
43 if (!msgb_eq_l3_data_print(msg, data, data_len)) \
44 abort(); \
45 } while(0)
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +010046
Philipp Maierfa896ab2017-03-27 16:55:32 +020047/* Setup a fake codec list for testing */
48static void setup_codec_list(struct gsm0808_speech_codec_list *scl)
49{
50 memset(scl, 0, sizeof(*scl));
51
52 scl->codec[0].pi = true;
53 scl->codec[0].tf = true;
Philipp Maierbb839662017-06-01 17:11:19 +020054 scl->codec[0].type = GSM0808_SCT_FR3;
Philipp Maierfa896ab2017-03-27 16:55:32 +020055 scl->codec[0].cfg = 0xcdef;
56
57 scl->codec[1].fi = true;
58 scl->codec[1].pt = true;
Philipp Maierbb839662017-06-01 17:11:19 +020059 scl->codec[1].type = GSM0808_SCT_FR2;
Philipp Maierfa896ab2017-03-27 16:55:32 +020060
61 scl->codec[2].fi = true;
62 scl->codec[2].tf = true;
Philipp Maierbb839662017-06-01 17:11:19 +020063 scl->codec[2].type = GSM0808_SCT_CSD;
64 scl->codec[2].cfg = 0xc0;
Philipp Maierfa896ab2017-03-27 16:55:32 +020065
66 scl->len = 3;
67}
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +010068
Philipp Maier4f4905f2018-11-30 13:36:12 +010069void test_gsm0808_enc_cause(void)
70{
71 /* NOTE: This must be tested early because many of the following tests
72 * rely on the generation of a proper cause code. */
73
74 uint8_t rc_enc;
75 struct msgb *msg;
76
77 /* Test with a single byte cause code */
78 msg = msgb_alloc(1024, "output buffer");
79 rc_enc = gsm0808_enc_cause(msg, 0x41);
80 EXPECT_ENCODED("04 01 41");
81 msgb_free(msg);
82
83 /* Test with an extended (two byte) cause code */
84 msg = msgb_alloc(1024, "output buffer");
85 rc_enc = gsm0808_enc_cause(msg, 0x8041);
86 EXPECT_ENCODED("04 02 80 41");
87 msgb_free(msg);
88}
89
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +010090static void test_create_layer3(void)
91{
92 static const uint8_t res[] = {
93 0x00, 0x0e, 0x57, 0x05, 0x08, 0x00, 0x77, 0x62,
94 0x83, 0x33, 0x66, 0x44, 0x88, 0x17, 0x01, 0x23 };
95 struct msgb *msg, *in_msg;
Neels Hofmeyr178bf7a2018-04-20 12:23:45 +020096 struct osmo_cell_global_id cgi = {
97 .lai = {
98 .plmn = {
99 .mcc = 0x2244,
100 .mnc = 0x1122,
101 },
102 .lac = 0x3366,
103 },
104 .cell_identity = 0x4488,
105 };
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100106 printf("Testing creating Layer3\n");
107
108 in_msg = msgb_alloc_headroom(512, 128, "foo");
109 in_msg->l3h = in_msg->data;
110 msgb_v_put(in_msg, 0x23);
111
Neels Hofmeyr178bf7a2018-04-20 12:23:45 +0200112 msg = gsm0808_create_layer3_2(in_msg, &cgi, NULL);
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100113 VERIFY(msg, res, ARRAY_SIZE(res));
114 msgb_free(msg);
115 msgb_free(in_msg);
116}
117
Philipp Maierfa896ab2017-03-27 16:55:32 +0200118static void test_create_layer3_aoip()
119{
120 static const uint8_t res[] = {
121 0x00, 0x17, 0x57, 0x05, 0x08, 0x00, 0x77, 0x62,
122 0x83, 0x33, 0x66, 0x44, 0x88, 0x17, 0x01, 0x23,
Philipp Maierbb839662017-06-01 17:11:19 +0200123 GSM0808_IE_SPEECH_CODEC_LIST, 0x07, GSM0808_SCT_FR3 | 0x50,
Philipp Maier7e27b142018-03-22 17:26:46 +0100124 0xef, 0xcd, GSM0808_SCT_FR2 | 0xa0, 0x9f,
Philipp Maierbb839662017-06-01 17:11:19 +0200125 GSM0808_SCT_CSD | 0x90, 0xc0
Philipp Maierfa896ab2017-03-27 16:55:32 +0200126 };
Maxfa3b4822018-11-05 14:59:54 +0100127 struct osmo_cell_global_id cgi = {
128 .lai = {
129 .plmn = {
130 .mcc = 0x2244,
131 .mnc = 0x1122,
132 },
133 .lac = 0x3366,
134 },
135 .cell_identity = 0x4488,
136 };
Philipp Maierfa896ab2017-03-27 16:55:32 +0200137 struct msgb *msg, *in_msg;
138 struct gsm0808_speech_codec_list sc_list;
139 printf("Testing creating Layer3 (AoIP)\n");
140
141 setup_codec_list(&sc_list);
142
143 in_msg = msgb_alloc_headroom(512, 128, "foo");
144 in_msg->l3h = in_msg->data;
145 msgb_v_put(in_msg, 0x23);
146
Maxfa3b4822018-11-05 14:59:54 +0100147 msg = gsm0808_create_layer3_2(in_msg, &cgi, &sc_list);
148
Philipp Maierfa896ab2017-03-27 16:55:32 +0200149 VERIFY(msg, res, ARRAY_SIZE(res));
150
151 msgb_free(msg);
152 msgb_free(in_msg);
153}
154
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100155static void test_create_reset()
156{
157 static const uint8_t res[] = { 0x00, 0x04, 0x30, 0x04, 0x01, 0x20 };
158 struct msgb *msg;
159
160 printf("Testing creating Reset\n");
161 msg = gsm0808_create_reset();
162 VERIFY(msg, res, ARRAY_SIZE(res));
163 msgb_free(msg);
164}
165
Philipp Maier15596e22017-04-05 17:55:27 +0200166static void test_create_reset_ack()
167{
168 static const uint8_t res[] = { 0x00, 0x01, 0x31 };
169 struct msgb *msg;
170
171 printf("Testing creating Reset Ack\n");
172 msg = gsm0808_create_reset_ack();
173 VERIFY(msg, res, ARRAY_SIZE(res));
174 msgb_free(msg);
175}
176
177
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100178static void test_create_clear_command()
179{
180 static const uint8_t res[] = { 0x20, 0x04, 0x01, 0x23 };
181 struct msgb *msg;
182
183 printf("Testing creating Clear Command\n");
184 msg = gsm0808_create_clear_command(0x23);
185 VERIFY(msg, res, ARRAY_SIZE(res));
186 msgb_free(msg);
187}
188
Harald Weltecf665fc2019-02-18 13:45:36 +0100189static void test_create_clear_command2()
190{
191 static const uint8_t res[] = { 0x00, 0x04, 0x20, 0x04, 0x01, 0x23 };
192 struct msgb *msg;
193
194 printf("Testing creating Clear Command 2\n");
195 msg = gsm0808_create_clear_command2(0x23, false);
196 VERIFY(msg, res, ARRAY_SIZE(res));
197 msgb_free(msg);
198}
199
200static void test_create_clear_command2_csfb()
201{
202 static const uint8_t res[] = { 0x00, 0x05, 0x20, 0x04, 0x01, 0x23, 0x8F };
203 struct msgb *msg;
204
205 printf("Testing creating Clear Command 2 (CSFB)\n");
206 msg = gsm0808_create_clear_command2(0x23, true);
207 VERIFY(msg, res, ARRAY_SIZE(res));
208 msgb_free(msg);
209}
210
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100211static void test_create_clear_complete()
212{
213 static const uint8_t res[] = { 0x00, 0x01, 0x21 };
214 struct msgb *msg;
215
216 printf("Testing creating Clear Complete\n");
217 msg = gsm0808_create_clear_complete();
218 VERIFY(msg, res, ARRAY_SIZE(res));
219 msgb_free(msg);
220}
221
Philipp Maierb478dd32017-03-29 15:50:05 +0200222static void test_create_cipher()
223{
224 static const uint8_t res[] =
225 { 0x00, 0x0c, 0x53, 0x0a, 0x09, 0x03, 0xaa,
226 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x23, 0x42 };
227 static const uint8_t res2[] =
228 { 0x00, 0x0e, 0x53, 0x0a, 0x09, 0x03, 0xaa,
229 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x23, 0x42,
230 GSM0808_IE_CIPHER_RESPONSE_MODE, 0x01 };
231 struct msgb *msg;
232 struct gsm0808_encrypt_info ei;
233 uint8_t include_imeisv;
234
235 memset(&ei, 0, sizeof(ei));
236 ei.perm_algo[0] = GSM0808_ALG_ID_A5_0;
237 ei.perm_algo[1] = GSM0808_ALG_ID_A5_1;
238 ei.perm_algo_len = 2;
239 ei.key[0] = 0xaa;
240 ei.key[1] = 0xbb;
241 ei.key[2] = 0xcc;
242 ei.key[3] = 0xdd;
243 ei.key[4] = 0xee;
244 ei.key[5] = 0xff;
245 ei.key[6] = 0x23;
246 ei.key[7] = 0x42;
247 ei.key_len = 8;
248 include_imeisv = 1;
249
250 printf("Testing creating Chipher Mode Command\n");
251 msg = gsm0808_create_cipher(&ei, NULL);
252 OSMO_ASSERT(msg);
253 VERIFY(msg, res, ARRAY_SIZE(res));
254 msgb_free(msg);
255
256 msg = gsm0808_create_cipher(&ei, &include_imeisv);
257 OSMO_ASSERT(msg);
258 VERIFY(msg, res2, ARRAY_SIZE(res2));
259 msgb_free(msg);
260}
261
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100262static void test_create_cipher_complete()
263{
264 static const uint8_t res1[] = {
265 0x00, 0x08, 0x55, 0x20, 0x03, 0x23, 0x42, 0x21, 0x2c, 0x04 };
266 static const uint8_t res2[] = { 0x00, 0x03, 0x55, 0x2c, 0x04};
267 struct msgb *l3, *msg;
268
269 printf("Testing creating Cipher Complete\n");
270 l3 = msgb_alloc_headroom(512, 128, "l3h");
271 l3->l3h = l3->data;
272 msgb_v_put(l3, 0x23);
273 msgb_v_put(l3, 0x42);
274 msgb_v_put(l3, 0x21);
275
276 /* with l3 data */
277 msg = gsm0808_create_cipher_complete(l3, 4);
278 VERIFY(msg, res1, ARRAY_SIZE(res1));
279 msgb_free(msg);
280
281 /* with l3 data but short */
282 l3->len -= 1;
283 l3->tail -= 1;
284 msg = gsm0808_create_cipher_complete(l3, 4);
285 VERIFY(msg, res2, ARRAY_SIZE(res2));
286 msgb_free(msg);
287
288 /* without l3 data */
289 msg = gsm0808_create_cipher_complete(NULL, 4);
290 VERIFY(msg, res2, ARRAY_SIZE(res2));
291 msgb_free(msg);
292
293
294 msgb_free(l3);
295}
296
Maxed651d22018-11-07 15:25:05 +0100297static inline void parse_cipher_reject(struct msgb *msg, uint8_t exp)
298{
299 struct tlv_parsed tp;
300 int rc;
301
302 /* skip header and message type so we can parse Cause IE directly */
303 msg->l2h = msgb_data(msg) + sizeof(struct bssmap_header) + 1;
304
305 rc = osmo_bssap_tlv_parse(&tp, msg->l2h, msgb_l2len(msg));
306 if (rc < 0)
307 printf("FIXME: failed (%d) to parse created message %s\n", rc, msgb_hexdump(msg));
308
309 rc = gsm0808_get_cipher_reject_cause(&tp);
310 if (rc < 0)
311 printf("FIXME: failed (%s) to extract Cause from created message %s\n",
312 strerror(-rc), msgb_hexdump(msg));
313
314 if (exp != (enum gsm0808_cause)rc)
315 printf("FIXME: wrong Cause %d != %u (" OSMO_BIN_SPEC ") extracted from created message %s\n",
316 rc, exp, OSMO_BIT_PRINT(exp), msgb_hexdump(msg));
317}
318
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100319static void test_create_cipher_reject()
320{
Harald Welte62e40852017-12-17 20:50:34 +0100321 static const uint8_t res[] = { 0x00, 0x04, 0x59, 0x04, 0x01, 0x23 };
Maxed651d22018-11-07 15:25:05 +0100322 enum gsm0808_cause cause = GSM0808_CAUSE_CCCH_OVERLOAD;
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100323 struct msgb *msg;
324
325 printf("Testing creating Cipher Reject\n");
Maxed651d22018-11-07 15:25:05 +0100326 msg = gsm0808_create_cipher_reject(cause);
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100327 VERIFY(msg, res, ARRAY_SIZE(res));
Maxed651d22018-11-07 15:25:05 +0100328
329 parse_cipher_reject(msg, cause);
330
331 msgb_free(msg);
332}
333
334static void test_create_cipher_reject_ext()
335{
336 static const uint8_t res[] = { 0x00, 0x05, 0x59, 0x04, 0x02, 0xd0, 0xFA };
337 uint8_t cause = 0xFA;
338 struct msgb *msg;
339
340 printf("Testing creating Cipher Reject (extended)\n");
341 msg = gsm0808_create_cipher_reject_ext(GSM0808_CAUSE_CLASS_INVAL, cause);
342 VERIFY(msg, res, ARRAY_SIZE(res));
343
344 parse_cipher_reject(msg, cause);
345
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100346 msgb_free(msg);
347}
348
349static void test_create_cm_u()
350{
Harald Welte07b625d2012-01-23 10:02:58 +0100351 static const uint8_t res[] = {
352 0x00, 0x07, 0x54, 0x12, 0x01, 0x23, 0x13, 0x01, 0x42 };
353 static const uint8_t res2o[] = {
354 0x00, 0x04, 0x54, 0x12, 0x01, 0x23 };
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100355 struct msgb *msg;
Harald Welte07b625d2012-01-23 10:02:58 +0100356 const uint8_t cm2 = 0x23;
357 const uint8_t cm3 = 0x42;
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100358
359 printf("Testing creating CM U\n");
Harald Welte07b625d2012-01-23 10:02:58 +0100360 msg = gsm0808_create_classmark_update(&cm2, 1, &cm3, 1);
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100361 VERIFY(msg, res, ARRAY_SIZE(res));
Harald Welte07b625d2012-01-23 10:02:58 +0100362
Neels Hofmeyr9a938ae2017-11-16 17:34:07 +0100363 msgb_free(msg);
364
Harald Welte07b625d2012-01-23 10:02:58 +0100365 msg = gsm0808_create_classmark_update(&cm2, 1, NULL, 0);
366 VERIFY(msg, res2o, ARRAY_SIZE(res2o));
367
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100368 msgb_free(msg);
369}
370
371static void test_create_sapi_reject()
372{
373 static const uint8_t res[] = { 0x00, 0x03, 0x25, 0x03, 0x25 };
374 struct msgb *msg;
375
376 printf("Testing creating SAPI Reject\n");
377 msg = gsm0808_create_sapi_reject(3);
378 VERIFY(msg, res, ARRAY_SIZE(res));
379 msgb_free(msg);
380}
381
Philipp Maierc6144a22017-03-29 17:53:43 +0200382static void test_create_ass()
383{
384 static const uint8_t res1[] =
385 { 0x00, 0x0a, 0x01, 0x0b, 0x04, 0x01, 0x0b, 0xa1, 0x25, 0x01, 0x00,
386 0x04 };
387 static const uint8_t res2[] =
388 { 0x00, 0x20, 0x01, 0x0b, 0x04, 0x01, 0x0b, 0xa1, 0x25, 0x01, 0x00,
389 0x04, GSM0808_IE_AOIP_TRASP_ADDR, 0x06, 0xc0, 0xa8, 0x64, 0x17,
Philipp Maierbb839662017-06-01 17:11:19 +0200390 0x04, 0xd2, GSM0808_IE_SPEECH_CODEC_LIST, 0x07,
Philipp Maier7e27b142018-03-22 17:26:46 +0100391 GSM0808_SCT_FR3 | 0x50, 0xef, 0xcd, GSM0808_SCT_FR2 | 0xa0, 0x9f,
Philipp Maierbb839662017-06-01 17:11:19 +0200392 GSM0808_SCT_CSD | 0x90, 0xc0, GSM0808_IE_CALL_ID, 0xaa, 0xbb,
393 0xcc, 0xdd };
Philipp Maierc6144a22017-03-29 17:53:43 +0200394
395 struct msgb *msg;
396 struct gsm0808_channel_type ct;
397 uint16_t cic = 0004;
398 struct sockaddr_storage ss;
399 struct sockaddr_in sin;
400 struct gsm0808_speech_codec_list sc_list;
401 uint32_t call_id = 0xAABBCCDD;
402
403 memset(&ct, 0, sizeof(ct));
404 ct.ch_indctr = GSM0808_CHAN_SPEECH;
405 ct.ch_rate_type = GSM0808_SPEECH_HALF_PREF;
406 ct.perm_spch[0] = GSM0808_PERM_FR3;
407 ct.perm_spch[1] = GSM0808_PERM_HR3;
408 ct.perm_spch_len = 2;
409
410 memset(&sin, 0, sizeof(sin));
411 sin.sin_family = AF_INET;
412 sin.sin_port = htons(1234);
413 inet_aton("192.168.100.23", &sin.sin_addr);
414
415 memset(&ss, 0, sizeof(ss));
416 memcpy(&ss, &sin, sizeof(sin));
417
418 setup_codec_list(&sc_list);
419
420 printf("Testing creating Assignment Request\n");
421 msg = gsm0808_create_ass(&ct, &cic, NULL, NULL, NULL);
422 OSMO_ASSERT(msg);
423 VERIFY(msg, res1, ARRAY_SIZE(res1));
424 msgb_free(msg);
425
426 msg = gsm0808_create_ass(&ct, &cic, &ss, &sc_list, &call_id);
427 OSMO_ASSERT(msg);
428 VERIFY(msg, res2, ARRAY_SIZE(res2));
429 msgb_free(msg);
430}
431
Max52074322018-11-30 10:44:07 +0100432static void test_create_ass2()
433{
434 static const uint8_t res[] = {
435 BSSAP_MSG_BSS_MANAGEMENT,
436 0x45,
437 BSS_MAP_MSG_ASSIGMENT_RQST,
438 GSM0808_IE_CHANNEL_TYPE,
439 0x04, 0x01, 0x0b, 0x91, 0x15, 0x01, 0x00, 0x04,
440 GSM0808_IE_AOIP_TRASP_ADDR,
441 0x06,
442 0xac, 0x0c, 0x65, 0x0d, /* IPv4 */
443 0x02, 0x9a,
444 GSM0808_IE_SPEECH_CODEC_LIST,
445 0x07,
446 GSM0808_SCT_FR3 | 0x50,
447 0xef, 0xcd,
448 GSM0808_SCT_FR2 | 0xa0,
449 0x9f,
450 GSM0808_SCT_CSD | 0x90,
451 0xc0,
452 GSM0808_IE_CALL_ID,
453 0xde, 0xad, 0xfa, 0xce, /* CallID */
454 0x83, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, /* Kc */
455 GSM0808_IE_GLOBAL_CALL_REF, 0x0d, /* GCR, length */
456 0x03, 0x44, 0x44, 0x44, /* GCR, Net ID */
457 0x02, 0xfe, 0xed, /* GCR, Node ID */
458 0x05, 0x41, 0x41, 0x41, 0x41, 0x41, /* GCR, Call ref. ID */
459 GSM0808_IE_LCLS_CONFIG, GSM0808_LCLS_CFG_BOTH_WAY,
460 GSM0808_IE_LCLS_CONN_STATUS_CTRL, GSM0808_LCLS_CSC_CONNECT,
461 GSM0808_IE_LCLS_CORR_NOT_NEEDED,
462 };
463 struct msgb *msg;
464 struct gsm0808_channel_type ct;
465 uint16_t cic = 4;
466 struct sockaddr_storage ss;
467 struct sockaddr_in sin;
468 struct gsm0808_speech_codec_list sc_list;
469 uint32_t call_id = 0xDEADFACE;
Max52074322018-11-30 10:44:07 +0100470 uint8_t Kc[16];
471 struct osmo_lcls lcls = {
472 .config = GSM0808_LCLS_CFG_BOTH_WAY,
473 .control = GSM0808_LCLS_CSC_CONNECT,
Max3b901252019-01-15 14:15:11 +0100474 .gcr = { .net_len = 3, .node = 0xFEED },
475 .gcr_available = true,
Max52074322018-11-30 10:44:07 +0100476 .corr_needed = false
477 };
478
Max3b901252019-01-15 14:15:11 +0100479 memset(lcls.gcr.cr, 'A', 5);
480 memset(lcls.gcr.net, 'D', lcls.gcr.net_len);
Max52074322018-11-30 10:44:07 +0100481 memset(Kc, 'E', 16);
482
483 memset(&ct, 0, sizeof(ct));
484 ct.ch_indctr = GSM0808_CHAN_SPEECH;
485 ct.ch_rate_type = GSM0808_SPEECH_HALF_PREF;
486 ct.perm_spch[0] = GSM0808_PERM_FR2;
487 ct.perm_spch[1] = GSM0808_PERM_HR2;
488 ct.perm_spch_len = 2;
489
490 memset(&sin, 0, sizeof(sin));
491 sin.sin_family = AF_INET;
492 sin.sin_port = htons(666);
493 inet_aton("172.12.101.13", &sin.sin_addr); /* IPv4 */
494
495 memset(&ss, 0, sizeof(ss));
496 memcpy(&ss, &sin, sizeof(sin));
497
498 setup_codec_list(&sc_list);
499
500 printf("Testing creating Assignment Request with Kc and LCLS\n");
501
502 msg = gsm0808_create_ass2(&ct, &cic, &ss, &sc_list, &call_id, Kc, &lcls);
503 if (!msgb_eq_l3_data_print(msg, res, ARRAY_SIZE(res)))
504 abort();
505
506 msgb_free(msg);
507}
508
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100509static void test_create_ass_compl()
510{
511 static const uint8_t res1[] = {
512 0x00, 0x09, 0x02, 0x15, 0x23, 0x21, 0x42, 0x2c,
513 0x11, 0x40, 0x22 };
514 static const uint8_t res2[] = {
515 0x00, 0x07, 0x02, 0x15, 0x23, 0x21, 0x42, 0x2c, 0x11};
516 struct msgb *msg;
517
518 printf("Testing creating Assignment Complete\n");
519 msg = gsm0808_create_assignment_completed(0x23, 0x42, 0x11, 0x22);
520 VERIFY(msg, res1, ARRAY_SIZE(res1));
521 msgb_free(msg);
522
523 msg = gsm0808_create_assignment_completed(0x23, 0x42, 0x11, 0);
524 VERIFY(msg, res2, ARRAY_SIZE(res2));
525 msgb_free(msg);
526}
527
Philipp Maierfa896ab2017-03-27 16:55:32 +0200528static void test_create_ass_compl_aoip()
529{
530 struct sockaddr_storage ss;
531 struct sockaddr_in sin;
532 struct gsm0808_speech_codec sc;
533 struct gsm0808_speech_codec_list sc_list;
534 static const uint8_t res[] =
Max414c8f52019-01-08 14:44:24 +0100535 { 0x00, 0x1f, 0x02, 0x15, 0x23, 0x21, 0x42, 0x2c, 0x11, 0x40, 0x22,
Philipp Maierfa896ab2017-03-27 16:55:32 +0200536 GSM0808_IE_AOIP_TRASP_ADDR, 0x06, 0xc0, 0xa8, 0x64, 0x17, 0x04,
Philipp Maierbb839662017-06-01 17:11:19 +0200537 0xd2, GSM0808_IE_SPEECH_CODEC, 0x01, GSM0808_SCT_HR1 | 0x90,
Philipp Maier7e27b142018-03-22 17:26:46 +0100538 GSM0808_IE_SPEECH_CODEC_LIST, 0x07, GSM0808_SCT_FR3 | 0x50, 0xef,
Max414c8f52019-01-08 14:44:24 +0100539 0xcd, GSM0808_SCT_FR2 | 0xa0, 0x9f, GSM0808_SCT_CSD | 0x90, 0xc0,
540 GSM0808_IE_LCLS_BSS_STATUS, GSM0808_LCLS_STS_LOCALLY_SWITCHED };
Philipp Maierfa896ab2017-03-27 16:55:32 +0200541 struct msgb *msg;
542
543 memset(&sin, 0, sizeof(sin));
544 sin.sin_family = AF_INET;
545 sin.sin_port = htons(1234);
546 inet_aton("192.168.100.23", &sin.sin_addr);
547
548 memset(&ss, 0, sizeof(ss));
549 memcpy(&ss, &sin, sizeof(sin));
550
551 memset(&sc, 0, sizeof(sc));
552 sc.fi = true;
553 sc.tf = true;
Philipp Maierbb839662017-06-01 17:11:19 +0200554 sc.type = GSM0808_SCT_HR1;
Philipp Maierfa896ab2017-03-27 16:55:32 +0200555
556 setup_codec_list(&sc_list);
557
558 printf("Testing creating Assignment Complete (AoIP)\n");
Max414c8f52019-01-08 14:44:24 +0100559 msg = gsm0808_create_ass_compl2(0x23, 0x42, 0x11, 0x22,
560 &ss, &sc, &sc_list, GSM0808_LCLS_STS_LOCALLY_SWITCHED);
Philipp Maierfa896ab2017-03-27 16:55:32 +0200561 VERIFY(msg, res, ARRAY_SIZE(res));
562 msgb_free(msg);
563}
564
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100565static void test_create_ass_fail()
566{
567 static const uint8_t res1[] = { 0x00, 0x04, 0x03, 0x04, 0x01, 0x23 };
568 static const uint8_t res2[] = {
569 0x00, 0x06, 0x03, 0x04, 0x01, 0x23, 0x15, 0x02};
570 uint8_t rr_res = 2;
571 struct msgb *msg;
572
573 printf("Testing creating Assignment Failure\n");
574 msg = gsm0808_create_assignment_failure(0x23, NULL);
575 VERIFY(msg, res1, ARRAY_SIZE(res1));
576 msgb_free(msg);
577
578 msg = gsm0808_create_assignment_failure(0x23, &rr_res);
579 VERIFY(msg, res2, ARRAY_SIZE(res2));
580 msgb_free(msg);
581}
582
Philipp Maierfa896ab2017-03-27 16:55:32 +0200583static void test_create_ass_fail_aoip()
584{
585 static const uint8_t res1[] =
586 { 0x00, 0x0d, 0x03, 0x04, 0x01, 0x23, GSM0808_IE_SPEECH_CODEC_LIST,
Philipp Maier7e27b142018-03-22 17:26:46 +0100587 0x07, GSM0808_SCT_FR3 | 0x50, 0xef, 0xcd, GSM0808_SCT_FR2 | 0xa0,
Philipp Maierbb839662017-06-01 17:11:19 +0200588 0x9f, GSM0808_SCT_CSD | 0x90, 0xc0 };
Philipp Maierfa896ab2017-03-27 16:55:32 +0200589 static const uint8_t res2[] =
590 { 0x00, 0x0f, 0x03, 0x04, 0x01, 0x23, 0x15, 0x02,
Philipp Maier7e27b142018-03-22 17:26:46 +0100591 GSM0808_IE_SPEECH_CODEC_LIST, 0x07, GSM0808_SCT_FR3 | 0x50, 0xef,
592 0xcd, GSM0808_SCT_FR2 | 0xa0, 0x9f, GSM0808_SCT_CSD | 0x90, 0xc0 };
Philipp Maierfa896ab2017-03-27 16:55:32 +0200593 uint8_t rr_res = 2;
594 struct msgb *msg;
595 struct gsm0808_speech_codec_list sc_list;
596
597 setup_codec_list(&sc_list);
598
599 printf("Testing creating Assignment Failure (AoIP)\n");
600 msg = gsm0808_create_ass_fail(0x23, NULL, &sc_list);
601 VERIFY(msg, res1, ARRAY_SIZE(res1));
602 msgb_free(msg);
603
604 msg = gsm0808_create_ass_fail(0x23, &rr_res, &sc_list);
605 VERIFY(msg, res2, ARRAY_SIZE(res2));
606 msgb_free(msg);
607}
608
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100609static void test_create_clear_rqst()
610{
611 static const uint8_t res[] = { 0x00, 0x04, 0x22, 0x04, 0x01, 0x23 };
612 struct msgb *msg;
613
614 printf("Testing creating Clear Request\n");
615 msg = gsm0808_create_clear_rqst(0x23);
616 VERIFY(msg, res, ARRAY_SIZE(res));
617 msgb_free(msg);
618}
619
Philipp Maier3d48ec02017-03-29 17:37:55 +0200620static void test_create_paging()
621{
622 static const uint8_t res[] =
623 { 0x00, 0x10, 0x52, 0x08, 0x08, 0x09, 0x10, 0x10, 0x00, 0x00, 0x00,
624 0x21, 0x43, 0x1a, 0x03, 0x05, 0x23, 0x42 };
625 static const uint8_t res2[] =
626 { 0x00, 0x16, 0x52, 0x08, 0x08, 0x09, 0x10, 0x10, 0x00, 0x00, 0x00,
627 0x21, 0x43, GSM0808_IE_TMSI, 0x04, 0x12, 0x34, 0x56, 0x78, 0x1a,
628 0x03, 0x05, 0x23, 0x42 };
629 static const uint8_t res3[] =
630 { 0x00, 0x18, 0x52, 0x08, 0x08, 0x09, 0x10, 0x10, 0x00, 0x00, 0x00,
631 0x21, 0x43, GSM0808_IE_TMSI, 0x04, 0x12, 0x34, 0x56, 0x78, 0x1a,
632 0x03, 0x05, 0x23, 0x42, GSM0808_IE_CHANNEL_NEEDED,
633 RSL_CHANNEED_TCH_ForH };
634
635 struct msgb *msg;
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100636 struct gsm0808_cell_id_list2 cil;
Philipp Maier3d48ec02017-03-29 17:37:55 +0200637 uint32_t tmsi = 0x12345678;
638 uint8_t chan_needed = RSL_CHANNEED_TCH_ForH;
639
640 char imsi[] = "001010000001234";
641
642 cil.id_discr = CELL_IDENT_LAC;
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100643 cil.id_list[0].lac = 0x2342;
Philipp Maier3d48ec02017-03-29 17:37:55 +0200644 cil.id_list_len = 1;
645
646 printf("Testing creating Paging Request\n");
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100647 msg = gsm0808_create_paging2(imsi, NULL, &cil, NULL);
Philipp Maier3d48ec02017-03-29 17:37:55 +0200648 VERIFY(msg, res, ARRAY_SIZE(res));
649 msgb_free(msg);
650
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100651 msg = gsm0808_create_paging2(imsi, &tmsi, &cil, NULL);
Philipp Maier3d48ec02017-03-29 17:37:55 +0200652 VERIFY(msg, res2, ARRAY_SIZE(res2));
653 msgb_free(msg);
654
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100655 msg = gsm0808_create_paging2(imsi, &tmsi, &cil, &chan_needed);
Philipp Maier3d48ec02017-03-29 17:37:55 +0200656 VERIFY(msg, res3, ARRAY_SIZE(res3));
657 msgb_free(msg);
658}
659
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100660static void test_create_dtap()
661{
662 static const uint8_t res[] = { 0x01, 0x03, 0x02, 0x23, 0x42 };
663 struct msgb *msg, *l3;
664
665 printf("Testing creating DTAP\n");
666 l3 = msgb_alloc_headroom(512, 128, "test");
667 l3->l3h = l3->data;
668 msgb_v_put(l3, 0x23);
669 msgb_v_put(l3, 0x42);
670
671 msg = gsm0808_create_dtap(l3, 0x3);
672 VERIFY(msg, res, ARRAY_SIZE(res));
673 msgb_free(msg);
674 msgb_free(l3);
675}
676
677static void test_prepend_dtap()
678{
679 static const uint8_t res[] = { 0x01, 0x03, 0x02, 0x23, 0x42 };
680 struct msgb *in_msg;
681
682 printf("Testing prepend DTAP\n");
683
684 in_msg = msgb_alloc_headroom(512, 128, "test");
685 msgb_v_put(in_msg, 0x23);
686 msgb_v_put(in_msg, 0x42);
687
688 gsm0808_prepend_dtap_header(in_msg, 0x3);
689 in_msg->l3h = in_msg->data;
690 VERIFY(in_msg, res, ARRAY_SIZE(res));
691 msgb_free(in_msg);
692}
693
Max47022152018-12-19 18:51:00 +0100694static void test_enc_dec_lcls()
Max969fb2e2018-12-10 11:01:10 +0100695{
696 static const uint8_t res[] = {
697 GSM0808_IE_GLOBAL_CALL_REF,
698 0x0d, /* GCR length */
699 0x03, /* .net_len */
700 0xf1, 0xf2, 0xf3, /* .net */
701 0x02, /* .node length */
702 0xde, 0xad, /* .node */
703 0x05, /* length of Call. Ref. */
704 0x41, 0x42, 0x43, 0x44, 0x45 /* .cr - Call. Ref. */
705 };
706 uint8_t len;
707 struct msgb *msg;
Max969fb2e2018-12-10 11:01:10 +0100708 int rc;
709 struct tlv_parsed tp;
Max3b901252019-01-15 14:15:11 +0100710 struct osmo_lcls *lcls_out, lcls_in = {
711 .gcr = {
712 .net_len = 3,
713 .net = { 0xf1, 0xf2, 0xf3 },
714 .node = 0xDEAD,
715 .cr = { 0x41, 0x42, 0x43, 0x44, 0x45 },
716 },
717 .gcr_available = true,
Max47022152018-12-19 18:51:00 +0100718 .config = GSM0808_LCLS_CFG_NA,
719 .control = GSM0808_LCLS_CSC_NA,
720 .corr_needed = true,
721 };
722
723 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "LCLS IE");
Max969fb2e2018-12-10 11:01:10 +0100724 if (!msg)
725 return;
726
Max3b901252019-01-15 14:15:11 +0100727 lcls_out = talloc_zero(msg, struct osmo_lcls);
728 if (!lcls_out)
729 return;
730
Max47022152018-12-19 18:51:00 +0100731 len = gsm0808_enc_lcls(msg, &lcls_in);
Max969fb2e2018-12-10 11:01:10 +0100732 printf("Testing Global Call Reference IE encoder...\n\t%d bytes added: %s\n",
733 len, len == ARRAY_SIZE(res) ? "OK" : "FAIL");
734
735 if (!msgb_eq_data_print(msg, res, ARRAY_SIZE(res)))
736 abort();
737
738 rc = osmo_bssap_tlv_parse(&tp, msgb_data(msg), msgb_length(msg));
739 if (rc < 0) {
740 printf("parsing failed: %s [%s]\n", strerror(-rc), msgb_hexdump(msg));
741 abort();
742 }
743
Max3b901252019-01-15 14:15:11 +0100744 rc = gsm0808_dec_lcls(lcls_out, &tp);
Max969fb2e2018-12-10 11:01:10 +0100745 if (rc < 0) {
746 printf("decoding failed: %s [%s]\n", strerror(-rc), msgb_hexdump(msg));
747 abort();
748 }
749
Max3b901252019-01-15 14:15:11 +0100750 if (lcls_out->config != lcls_in.config) {
Max4fd64e52019-01-14 19:27:44 +0100751 printf("LCLS Config parsed wrong: %s != %s\n",
Max3b901252019-01-15 14:15:11 +0100752 gsm0808_lcls_config_name(lcls_out->config), gsm0808_lcls_config_name(lcls_in.config));
Max4fd64e52019-01-14 19:27:44 +0100753 abort();
754 }
755
Max3b901252019-01-15 14:15:11 +0100756 if (lcls_out->control != lcls_in.control) {
Max4fd64e52019-01-14 19:27:44 +0100757 printf("LCLS Control parsed wrong: %s != %s\n",
Max3b901252019-01-15 14:15:11 +0100758 gsm0808_lcls_control_name(lcls_out->control), gsm0808_lcls_control_name(lcls_in.control));
Max4fd64e52019-01-14 19:27:44 +0100759 abort();
760 }
761
Max3b901252019-01-15 14:15:11 +0100762 if (!osmo_gcr_eq(&lcls_out->gcr, &lcls_in.gcr)) {
Max1bec3902019-01-14 19:31:42 +0100763 printf("GCR parsed wrong.\n");
764 abort();
765 }
Max969fb2e2018-12-10 11:01:10 +0100766
767 printf("\tdecoded %d bytes: %s\n", rc, rc == len ? "OK" : "FAIL");
768 msgb_free(msg);
769}
770
Philipp Maier22401432017-03-24 17:59:26 +0100771static void test_enc_dec_aoip_trasp_addr_v4()
772{
773 struct sockaddr_storage enc_addr;
774 struct sockaddr_storage dec_addr;
775 struct sockaddr_in enc_addr_in;
776 struct msgb *msg;
777 uint8_t rc_enc;
778 int rc_dec;
779
780 memset(&enc_addr_in, 0, sizeof(enc_addr_in));
781 enc_addr_in.sin_family = AF_INET;
782 enc_addr_in.sin_port = htons(1234);
783 inet_aton("255.0.255.255", &enc_addr_in.sin_addr);
784
785 memset(&enc_addr, 0, sizeof(enc_addr));
786 memcpy(&enc_addr, &enc_addr_in, sizeof(enc_addr_in));
787
788 msg = msgb_alloc(1024, "output buffer");
789 rc_enc = gsm0808_enc_aoip_trasp_addr(msg, &enc_addr);
790 OSMO_ASSERT(rc_enc == 8);
791 rc_dec =
792 gsm0808_dec_aoip_trasp_addr(&dec_addr, msg->data + 2, msg->len - 2);
793 OSMO_ASSERT(rc_dec == 6);
794 OSMO_ASSERT(memcmp(&enc_addr, &dec_addr, sizeof(enc_addr)) == 0);
795
796 msgb_free(msg);
797}
798
799static void test_enc_dec_aoip_trasp_addr_v6()
800{
801 struct sockaddr_storage enc_addr;
802 struct sockaddr_storage dec_addr;
803 struct sockaddr_in6 enc_addr_in;
804 struct msgb *msg;
805 uint8_t rc_enc;
806 int rc_dec;
807
808 memset(&enc_addr_in, 0, sizeof(enc_addr_in));
809 enc_addr_in.sin6_family = AF_INET6;
810 enc_addr_in.sin6_port = htons(4567);
811 inet_pton(AF_INET6, "2001:0db8:85a3:08d3:1319:8a2e:0370:7344",
812 &enc_addr_in.sin6_addr);
813
814 memset(&enc_addr, 0, sizeof(enc_addr));
815 memcpy(&enc_addr, &enc_addr_in, sizeof(enc_addr_in));
816
817 msg = msgb_alloc(1024, "output buffer");
818 rc_enc = gsm0808_enc_aoip_trasp_addr(msg, &enc_addr);
819 OSMO_ASSERT(rc_enc == 20);
820 rc_dec =
821 gsm0808_dec_aoip_trasp_addr(&dec_addr, msg->data + 2, msg->len - 2);
822 OSMO_ASSERT(rc_dec == 18);
823 OSMO_ASSERT(memcmp(&enc_addr, &dec_addr, sizeof(enc_addr)) == 0);
824
825 msgb_free(msg);
826}
827
Philipp Maier6f725d62017-03-24 18:03:17 +0100828static void test_gsm0808_enc_dec_speech_codec()
829{
Neels Hofmeyr9a4286b2018-04-20 12:27:52 +0200830 struct gsm0808_speech_codec enc_sc = {
831 .pi = true,
832 .tf = true,
833 .type = GSM0808_SCT_FR2,
834 };
835 struct gsm0808_speech_codec dec_sc = {};
Philipp Maier6f725d62017-03-24 18:03:17 +0100836 struct msgb *msg;
837 uint8_t rc_enc;
838 int rc_dec;
839
Philipp Maier6f725d62017-03-24 18:03:17 +0100840 msg = msgb_alloc(1024, "output buffer");
841 rc_enc = gsm0808_enc_speech_codec(msg, &enc_sc);
842 OSMO_ASSERT(rc_enc == 3);
843
844 rc_dec = gsm0808_dec_speech_codec(&dec_sc, msg->data + 2, msg->len - 2);
845 OSMO_ASSERT(rc_dec == 1);
846
847 OSMO_ASSERT(memcmp(&enc_sc, &dec_sc, sizeof(enc_sc)) == 0);
848
849 msgb_free(msg);
850}
851
852
Philipp Maierbb839662017-06-01 17:11:19 +0200853static void test_gsm0808_enc_dec_speech_codec_with_cfg()
854{
Neels Hofmeyrc62c9342018-04-15 23:31:47 +0200855 struct gsm0808_speech_codec enc_sc = {
856 .pi = true,
857 .tf = true,
858 .type = GSM0808_SCT_FR3,
859 .cfg = 0xabcd,
860 };
861 struct gsm0808_speech_codec dec_sc = {};
Philipp Maierbb839662017-06-01 17:11:19 +0200862 struct msgb *msg;
863 uint8_t rc_enc;
864 int rc_dec;
865
Philipp Maierbb839662017-06-01 17:11:19 +0200866 msg = msgb_alloc(1024, "output buffer");
867 rc_enc = gsm0808_enc_speech_codec(msg, &enc_sc);
868 OSMO_ASSERT(rc_enc == 5);
869
870 rc_dec = gsm0808_dec_speech_codec(&dec_sc, msg->data + 2, msg->len - 2);
871 OSMO_ASSERT(rc_dec == 3);
872
873 OSMO_ASSERT(memcmp(&enc_sc, &dec_sc, sizeof(enc_sc)) == 0);
874
875 msgb_free(msg);
876}
877
Philipp Maier6f725d62017-03-24 18:03:17 +0100878static void test_gsm0808_enc_dec_speech_codec_ext_with_cfg()
879{
Neels Hofmeyr9a4286b2018-04-20 12:27:52 +0200880 struct gsm0808_speech_codec enc_sc = {
881 .pi = true,
882 .tf = true,
883 .type = GSM0808_SCT_CSD,
884 .cfg = 0xc0,
885 };
886 struct gsm0808_speech_codec dec_sc = {};
Philipp Maier6f725d62017-03-24 18:03:17 +0100887 struct msgb *msg;
888 uint8_t rc_enc;
889 int rc_dec;
890
Philipp Maier6f725d62017-03-24 18:03:17 +0100891 msg = msgb_alloc(1024, "output buffer");
892 rc_enc = gsm0808_enc_speech_codec(msg, &enc_sc);
Philipp Maierbb839662017-06-01 17:11:19 +0200893 OSMO_ASSERT(rc_enc == 5);
Philipp Maier6f725d62017-03-24 18:03:17 +0100894
895 rc_dec = gsm0808_dec_speech_codec(&dec_sc, msg->data + 2, msg->len - 2);
Philipp Maierbb839662017-06-01 17:11:19 +0200896 OSMO_ASSERT(rc_dec == 3);
Philipp Maier6f725d62017-03-24 18:03:17 +0100897
898 OSMO_ASSERT(memcmp(&enc_sc, &dec_sc, sizeof(enc_sc)) == 0);
899
900 msgb_free(msg);
901}
902
903static void test_gsm0808_enc_dec_speech_codec_list()
904{
Neels Hofmeyr9a4286b2018-04-20 12:27:52 +0200905 struct gsm0808_speech_codec_list enc_scl = {
906 .codec = {
907 {
908 .pi = true,
909 .tf = true,
910 .type = GSM0808_SCT_FR3,
911 .cfg = 0xcdef,
912 },
913
914 {
915 .fi = true,
916 .pt = true,
917 .type = GSM0808_SCT_FR2,
918 },
919
920 {
921 .fi = true,
922 .tf = true,
923 .type = GSM0808_SCT_CSD,
924 .cfg = 0xc0,
925 },
926 },
927 .len = 3,
928 };
929 struct gsm0808_speech_codec_list dec_scl = {};
Philipp Maier6f725d62017-03-24 18:03:17 +0100930 struct msgb *msg;
931 uint8_t rc_enc;
932 int rc_dec;
933
Philipp Maier6f725d62017-03-24 18:03:17 +0100934 msg = msgb_alloc(1024, "output buffer");
935 rc_enc = gsm0808_enc_speech_codec_list(msg, &enc_scl);
936 OSMO_ASSERT(rc_enc == 9);
937
938 rc_dec = gsm0808_dec_speech_codec_list(&dec_scl, msg->data + 2, msg->len - 2);
939 OSMO_ASSERT(rc_dec == 7);
940
941 OSMO_ASSERT(memcmp(&enc_scl, &dec_scl, sizeof(enc_scl)) == 0);
942
943 msgb_free(msg);
944}
945
Philipp Maierf6c369f2018-10-16 15:24:47 +0200946static void test_gsm0808_enc_dec_empty_speech_codec_list()
947{
948 struct gsm0808_speech_codec_list enc_scl = {
949 .len = 0,
950 };
951 struct gsm0808_speech_codec_list dec_scl = {};
952 struct msgb *msg;
953 uint8_t rc_enc;
954 int rc_dec;
955
956 msg = msgb_alloc(1024, "output buffer");
957 rc_enc = gsm0808_enc_speech_codec_list(msg, &enc_scl);
958 OSMO_ASSERT(rc_enc == 2);
959
960 rc_dec = gsm0808_dec_speech_codec_list(&dec_scl, msg->data + 2, msg->len - 2);
961 OSMO_ASSERT(rc_dec == 0);
962
963 OSMO_ASSERT(memcmp(&enc_scl, &dec_scl, sizeof(enc_scl)) == 0);
964
965 msgb_free(msg);
966}
967
Philipp Maiere0c65302017-03-28 17:05:40 +0200968static void test_gsm0808_enc_dec_channel_type()
969{
Neels Hofmeyr9a4286b2018-04-20 12:27:52 +0200970 struct gsm0808_channel_type enc_ct = {
971 .ch_indctr = GSM0808_CHAN_SPEECH,
972 .ch_rate_type = GSM0808_SPEECH_HALF_PREF,
973 .perm_spch = { GSM0808_PERM_FR3, GSM0808_PERM_HR3 },
974 .perm_spch_len = 2,
975 };
976 struct gsm0808_channel_type dec_ct = {};
Philipp Maiere0c65302017-03-28 17:05:40 +0200977 struct msgb *msg;
978 uint8_t ct_enc_expected[] = { GSM0808_IE_CHANNEL_TYPE,
979 0x04, 0x01, 0x0b, 0xa1, 0x25
980 };
981 uint8_t rc_enc;
982 int rc_dec;
983
Philipp Maiere0c65302017-03-28 17:05:40 +0200984 msg = msgb_alloc(1024, "output buffer");
985 rc_enc = gsm0808_enc_channel_type(msg, &enc_ct);
986 OSMO_ASSERT(rc_enc == 6);
987 OSMO_ASSERT(memcmp(ct_enc_expected, msg->data, msg->len) == 0);
988
989 rc_dec = gsm0808_dec_channel_type(&dec_ct, msg->data + 2, msg->len - 2);
990 OSMO_ASSERT(rc_dec == 4);
991 OSMO_ASSERT(memcmp(&enc_ct, &dec_ct, sizeof(enc_ct)) == 0);
992
993 msgb_free(msg);
994}
995
Philipp Maier14e76b92017-03-28 18:36:52 +0200996static void test_gsm0808_enc_dec_encrypt_info()
997{
Neels Hofmeyr9a4286b2018-04-20 12:27:52 +0200998 struct gsm0808_encrypt_info enc_ei = {
999 .perm_algo = { GSM0808_ALG_ID_A5_0, GSM0808_ALG_ID_A5_1 },
1000 .perm_algo_len = 2,
1001 .key = { 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x23, 0x42, },
1002 .key_len = 8,
1003 };
1004 struct gsm0808_encrypt_info dec_ei = {};
Philipp Maier14e76b92017-03-28 18:36:52 +02001005 struct msgb *msg;
1006 uint8_t ei_enc_expected[] =
1007 { GSM0808_IE_ENCRYPTION_INFORMATION, 0x09, 0x03, 0xaa, 0xbb,
1008 0xcc, 0xdd, 0xee, 0xff, 0x23, 0x42
1009 };
1010 uint8_t rc_enc;
1011 int rc_dec;
1012
Philipp Maier14e76b92017-03-28 18:36:52 +02001013 msg = msgb_alloc(1024, "output buffer");
1014 rc_enc = gsm0808_enc_encrypt_info(msg, &enc_ei);
1015 OSMO_ASSERT(rc_enc == 11);
1016 OSMO_ASSERT(memcmp(ei_enc_expected, msg->data, msg->len) == 0);
1017
1018 rc_dec = gsm0808_dec_encrypt_info(&dec_ei, msg->data + 2, msg->len - 2);
1019 OSMO_ASSERT(rc_dec == 9);
1020
1021 OSMO_ASSERT(memcmp(&enc_ei, &dec_ei, sizeof(enc_ei)) == 0);
1022
1023 msgb_free(msg);
1024}
1025
Philipp Maier783047e2017-03-29 11:35:50 +02001026static void test_gsm0808_enc_dec_cell_id_list_lac()
1027{
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001028 struct gsm0808_cell_id_list2 enc_cil;
1029 struct gsm0808_cell_id_list2 dec_cil;
Philipp Maier783047e2017-03-29 11:35:50 +02001030 struct msgb *msg;
1031 uint8_t rc_enc;
1032 int rc_dec;
1033
1034 memset(&enc_cil, 0, sizeof(enc_cil));
1035 enc_cil.id_discr = CELL_IDENT_LAC;
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001036 enc_cil.id_list[0].lac = 0x0124;
Neels Hofmeyrdb2fa4e2018-04-13 04:11:20 +02001037 enc_cil.id_list[1].lac = 0xABCD;
1038 enc_cil.id_list[2].lac = 0x5678;
Philipp Maier783047e2017-03-29 11:35:50 +02001039 enc_cil.id_list_len = 3;
1040
1041 msg = msgb_alloc(1024, "output buffer");
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001042 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
Neels Hofmeyrdb2fa4e2018-04-13 04:11:20 +02001043 EXPECT_ENCODED("1a 07 05 01 24 ab cd 56 78");
Philipp Maier783047e2017-03-29 11:35:50 +02001044
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001045 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
Philipp Maier783047e2017-03-29 11:35:50 +02001046 OSMO_ASSERT(rc_dec == 7);
1047
1048 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
1049
1050 msgb_free(msg);
1051}
1052
1053static void test_gsm0808_enc_dec_cell_id_list_single_lac()
1054{
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001055 struct gsm0808_cell_id_list2 enc_cil;
1056 struct gsm0808_cell_id_list2 dec_cil;
Philipp Maier783047e2017-03-29 11:35:50 +02001057 struct msgb *msg;
1058 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x03,
1059 0x05, 0x23, 0x42
1060 };
1061 uint8_t rc_enc;
1062 int rc_dec;
1063
1064 memset(&enc_cil, 0, sizeof(enc_cil));
1065 enc_cil.id_discr = CELL_IDENT_LAC;
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001066 enc_cil.id_list[0].lac = 0x2342;
Philipp Maier783047e2017-03-29 11:35:50 +02001067 enc_cil.id_list_len = 1;
1068
1069 msg = msgb_alloc(1024, "output buffer");
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001070 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
Philipp Maier783047e2017-03-29 11:35:50 +02001071 OSMO_ASSERT(rc_enc == 5);
1072 OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0);
1073
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001074 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
Philipp Maier783047e2017-03-29 11:35:50 +02001075 OSMO_ASSERT(rc_dec == 3);
1076
1077 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
1078
1079 msgb_free(msg);
1080}
1081
Stefan Sperlinge1a86742018-03-15 18:05:02 +01001082static void test_gsm0808_enc_dec_cell_id_list_multi_lac()
1083{
1084 struct gsm0808_cell_id_list2 enc_cil;
1085 struct gsm0808_cell_id_list2 dec_cil;
1086 struct msgb *msg;
1087 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x0b, 0x05,
1088 0x23, 0x42,
1089 0x24, 0x43,
1090 0x25, 0x44,
1091 0x26, 0x45,
1092 0x27, 0x46
1093 };
1094 uint8_t rc_enc;
1095 int rc_dec;
1096
1097 memset(&enc_cil, 0, sizeof(enc_cil));
1098 enc_cil.id_discr = CELL_IDENT_LAC;
1099 enc_cil.id_list[0].lac = 0x2342;
1100 enc_cil.id_list[1].lac = 0x2443;
1101 enc_cil.id_list[2].lac = 0x2544;
1102 enc_cil.id_list[3].lac = 0x2645;
1103 enc_cil.id_list[4].lac = 0x2746;
1104 enc_cil.id_list_len = 5;
1105
1106 msg = msgb_alloc(1024, "output buffer");
1107 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
1108 OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected));
1109 OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0);
1110
1111 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
1112 OSMO_ASSERT(rc_dec == msg->len - 2);
1113 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
1114
1115 msgb_free(msg);
1116}
1117
Philipp Maier783047e2017-03-29 11:35:50 +02001118static void test_gsm0808_enc_dec_cell_id_list_bss()
1119{
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001120 struct gsm0808_cell_id_list2 enc_cil;
1121 struct gsm0808_cell_id_list2 dec_cil;
Philipp Maier783047e2017-03-29 11:35:50 +02001122 struct msgb *msg;
1123 uint8_t rc_enc;
1124 int rc_dec;
1125
1126 memset(&enc_cil, 0, sizeof(enc_cil));
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001127 enc_cil.id_discr = CELL_IDENT_BSS;
Philipp Maier783047e2017-03-29 11:35:50 +02001128
1129 msg = msgb_alloc(1024, "output buffer");
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001130 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
Philipp Maier783047e2017-03-29 11:35:50 +02001131 OSMO_ASSERT(rc_enc == 3);
1132
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001133 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
Philipp Maier783047e2017-03-29 11:35:50 +02001134 OSMO_ASSERT(rc_dec == 1);
1135
1136 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
1137
1138 msgb_free(msg);
1139}
1140
Stefan Sperling23381452018-03-15 19:38:15 +01001141static void test_gsm0808_enc_dec_cell_id_list_multi_lai_and_lac()
1142{
1143 struct gsm0808_cell_id_list2 enc_cil;
1144 struct gsm0808_cell_id_list2 dec_cil;
1145 struct osmo_location_area_id id;
1146 struct msgb *msg;
1147 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x10, 0x04,
1148 0x92, 0x61, 0x54, 0x23, 0x42,
1149 0x92, 0x72, 0x54, 0x24, 0x43,
1150 0x92, 0x83, 0x54, 0x25, 0x44
1151 };
1152 uint8_t rc_enc;
1153 int rc_dec, i;
1154
1155 memset(&enc_cil, 0, sizeof(enc_cil));
1156 enc_cil.id_discr = CELL_IDENT_LAI_AND_LAC;
1157
1158 id.plmn.mcc = 0x123;
1159 osmo_mnc_from_str("456", &id.plmn.mnc, &id.plmn.mnc_3_digits);
1160 id.lac = 0x2342;
1161 memcpy(&enc_cil.id_list[0].lai_and_lac, &id, sizeof(id));
1162
1163 id.plmn.mcc = 0x124;
1164 osmo_mnc_from_str("457", &id.plmn.mnc, &id.plmn.mnc_3_digits);
1165 id.lac = 0x2443;
1166 memcpy(&enc_cil.id_list[1].lai_and_lac, &id, sizeof(id));
1167
1168 id.plmn.mcc = 0x125;
1169 osmo_mnc_from_str("458", &id.plmn.mnc, &id.plmn.mnc_3_digits);
1170 id.lac = 0x2544;
1171 memcpy(&enc_cil.id_list[2].lai_and_lac, &id, sizeof(id));
1172
1173 enc_cil.id_list_len = 3;
1174
1175 msg = msgb_alloc(1024, "output buffer");
1176 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
1177 OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected));
1178 OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0);
1179
1180 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
1181 OSMO_ASSERT(rc_dec == msg->len - 2);
1182
1183 OSMO_ASSERT(dec_cil.id_list_len == 3);
1184 /* Check MAXLEN elements to ensure everything has been initialized. */
1185 for (i = 0; i < GSM0808_CELL_ID_LIST2_MAXLEN; i++) {
1186 struct osmo_location_area_id *enc_id;
1187 struct osmo_location_area_id *dec_id;
1188 enc_id = &enc_cil.id_list[i].lai_and_lac;
1189 dec_id = &dec_cil.id_list[i].lai_and_lac;
1190 OSMO_ASSERT(osmo_plmn_cmp(&enc_id->plmn, &dec_id->plmn) == 0);
1191 OSMO_ASSERT(enc_id->lac == dec_id->lac);
1192 }
1193
1194 msgb_free(msg);
1195}
1196
Stefan Sperling9c62fc62018-03-16 10:23:34 +01001197static void test_gsm0808_enc_dec_cell_id_list_multi_ci()
1198{
1199 struct gsm0808_cell_id_list2 enc_cil;
1200 struct gsm0808_cell_id_list2 dec_cil;
1201 struct msgb *msg;
1202 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x09, 0x02,
1203 0x00, 0x01,
1204 0x00, 0x02,
1205 0x00, 0x77,
1206 0x01, 0xff,
1207 };
1208 uint8_t rc_enc;
1209 int rc_dec;
1210
1211 memset(&enc_cil, 0, sizeof(enc_cil));
1212 enc_cil.id_discr = CELL_IDENT_CI;
1213 enc_cil.id_list[0].ci = 1;
1214 enc_cil.id_list[1].ci = 2;
1215 enc_cil.id_list[2].ci = 119;
1216 enc_cil.id_list[3].ci = 511;
1217 enc_cil.id_list_len = 4;
1218
1219 msg = msgb_alloc(1024, "output buffer");
1220 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
1221 OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected));
1222 OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0);
1223
1224 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
1225 OSMO_ASSERT(rc_dec == msg->len - 2);
1226 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
1227
1228 msgb_free(msg);
1229}
1230
Stefan Sperlinged4327c2018-03-16 11:02:59 +01001231static void test_gsm0808_enc_dec_cell_id_list_multi_lac_and_ci()
1232{
1233 struct gsm0808_cell_id_list2 enc_cil;
1234 struct gsm0808_cell_id_list2 dec_cil;
1235 struct msgb *msg;
1236 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x15, 0x01,
1237 0x23, 0x42, 0x00, 0x01,
1238 0x24, 0x43, 0x00, 0x02,
1239 0x25, 0x44, 0x00, 0x77,
1240 0x26, 0x45, 0x01, 0xff,
1241 0x27, 0x46, 0x02, 0xfe,
1242 };
1243 uint8_t rc_enc;
1244 int rc_dec;
1245
1246 memset(&enc_cil, 0, sizeof(enc_cil));
1247 enc_cil.id_discr = CELL_IDENT_LAC_AND_CI;
1248 enc_cil.id_list[0].lac_and_ci.lac = 0x2342;
1249 enc_cil.id_list[0].lac_and_ci.ci = 1;
1250 enc_cil.id_list[1].lac_and_ci.lac = 0x2443;
1251 enc_cil.id_list[1].lac_and_ci.ci = 2;
1252 enc_cil.id_list[2].lac_and_ci.lac = 0x2544;
1253 enc_cil.id_list[2].lac_and_ci.ci = 119;
1254 enc_cil.id_list[3].lac_and_ci.lac = 0x2645;
1255 enc_cil.id_list[3].lac_and_ci.ci = 511;
1256 enc_cil.id_list[4].lac_and_ci.lac = 0x2746;
1257 enc_cil.id_list[4].lac_and_ci.ci = 766;
1258 enc_cil.id_list_len = 5;
1259
1260 msg = msgb_alloc(1024, "output buffer");
1261 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
1262 OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected));
1263 OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0);
1264
1265 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
1266 OSMO_ASSERT(rc_dec == msg->len - 2);
1267 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
1268
1269 msgb_free(msg);
1270}
1271
Stefan Sperling483f3862018-03-16 12:21:26 +01001272static void test_gsm0808_enc_dec_cell_id_list_multi_global()
1273{
1274 struct gsm0808_cell_id_list2 enc_cil;
1275 struct gsm0808_cell_id_list2 dec_cil;
1276 struct msgb *msg;
1277 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x16, 0x00,
Neels Hofmeyr473485c2018-03-23 02:04:18 +01001278 0x21, 0x63, 0x54, 0x23, 0x42, 0x00, 0x1,
Neels Hofmeyrc44fc232018-03-23 02:15:12 +01001279 0x21, 0xf4, 0x75, 0x24, 0x43, 0x00, 0x2,
Neels Hofmeyr8b8cd932018-03-23 01:47:37 +01001280 0x21, 0x75, 0x00, 0x25, 0x44, 0x00, 0x77
Stefan Sperling483f3862018-03-16 12:21:26 +01001281 };
Stefan Sperling483f3862018-03-16 12:21:26 +01001282 uint8_t rc_enc;
1283 int rc_dec, i;
1284
Neels Hofmeyrc1991df2018-03-23 02:00:00 +01001285 enc_cil = (struct gsm0808_cell_id_list2){
1286 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1287 .id_list_len = 3,
1288 .id_list = {
1289 {
1290 .global = {
Neels Hofmeyr473485c2018-03-23 02:04:18 +01001291 .lai = { .plmn = { .mcc = 123, .mnc = 456 },
Neels Hofmeyrc1991df2018-03-23 02:00:00 +01001292 .lac = 0x2342 },
1293 .cell_identity = 1,
1294 }
1295 },
1296 {
1297 .global = {
Neels Hofmeyrc44fc232018-03-23 02:15:12 +01001298 .lai = { .plmn = { .mcc = 124, .mnc = 57 },
Neels Hofmeyrc1991df2018-03-23 02:00:00 +01001299 .lac = 0x2443 },
1300 .cell_identity = 2,
1301 }
1302 },
1303 {
1304 .global = {
Neels Hofmeyrc44fc232018-03-23 02:15:12 +01001305 .lai = { .plmn = { .mcc = 125, .mnc = 7,
1306 .mnc_3_digits = true },
Neels Hofmeyrc1991df2018-03-23 02:00:00 +01001307 .lac = 0x2544 },
1308 .cell_identity = 119,
1309 }
1310 },
1311 }
1312 };
Stefan Sperling483f3862018-03-16 12:21:26 +01001313
1314 msg = msgb_alloc(1024, "output buffer");
1315 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
1316 OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected));
Neels Hofmeyrc1991df2018-03-23 02:00:00 +01001317 if (memcmp(cil_enc_expected, msg->data, msg->len)) {
1318 printf(" got: %s\n", osmo_hexdump(msg->data, msg->len));
1319 printf("expect: %s\n", osmo_hexdump(cil_enc_expected, sizeof(cil_enc_expected)));
1320 OSMO_ASSERT(false);
1321 }
Stefan Sperling483f3862018-03-16 12:21:26 +01001322
1323 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
1324 OSMO_ASSERT(rc_dec == msg->len - 2);
1325
1326 /* Check MAXLEN elements to ensure everything has been initialized. */
1327 for (i = 0; i < GSM0808_CELL_ID_LIST2_MAXLEN; i++) {
1328 struct osmo_cell_global_id *enc_id;
1329 struct osmo_cell_global_id *dec_id;
1330 enc_id = &enc_cil.id_list[i].global;
1331 dec_id = &dec_cil.id_list[i].global;
1332 OSMO_ASSERT(osmo_plmn_cmp(&enc_id->lai.plmn, &dec_id->lai.plmn) == 0);
1333 OSMO_ASSERT(enc_id->lai.lac == dec_id->lai.lac);
1334 OSMO_ASSERT(enc_id->cell_identity == dec_id->cell_identity);
1335 }
1336
1337 msgb_free(msg);
1338}
1339
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001340static void print_cil(const struct gsm0808_cell_id_list2 *cil)
1341{
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001342 printf(" cell_id_list == %s\n", gsm0808_cell_id_list_name(cil));
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001343}
1344
1345void test_cell_id_list_add() {
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001346 size_t zu;
1347
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001348 const struct gsm0808_cell_id_list2 cgi1 = {
1349 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1350 .id_list_len = 1,
1351 .id_list = {
1352 {
1353 .global = {
1354 .lai = {
1355 .plmn = { .mcc = 1, .mnc = 2, .mnc_3_digits = false },
1356 .lac = 3,
1357 },
1358 .cell_identity = 4,
1359 }
1360 },
1361 },
1362 };
1363
1364 const struct gsm0808_cell_id_list2 cgi2 = {
1365 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1366 .id_list_len = 2,
1367 .id_list = {
1368 {
1369 .global = {
1370 .lai = {
1371 .plmn = { .mcc = 1, .mnc = 2, .mnc_3_digits = true },
1372 .lac = 3,
1373 },
1374 .cell_identity = 4,
1375 }
1376 },
1377 {
1378 .global = {
1379 .lai = {
1380 .plmn = { .mcc = 5, .mnc = 6, .mnc_3_digits = true },
1381 .lac = 7,
1382 },
1383 .cell_identity = 8,
1384 }
1385 },
1386 },
1387 };
1388
1389 const struct gsm0808_cell_id_list2 cgi2a = {
1390 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1391 .id_list_len = 2,
1392 .id_list = {
1393 {
1394 .global = cgi2.id_list[0].global
1395 },
1396 {
1397 .global = {
1398 .lai = {
1399 .plmn = { .mcc = 9, .mnc = 10, .mnc_3_digits = true },
1400 .lac = 11,
1401 },
1402 .cell_identity = 12,
1403 }
1404 },
1405 },
1406 };
1407
1408 const struct gsm0808_cell_id_list2 cgi3 = {
1409 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1410 .id_list_len = 2,
1411 .id_list = {
1412 {
1413 .global = {
1414 .lai = {
1415 .plmn = { .mcc = 13, .mnc = 14, .mnc_3_digits = true },
1416 .lac = 15,
1417 },
1418 .cell_identity = 16,
1419 }
1420 },
1421 {
1422 .global = {
1423 .lai = {
1424 .plmn = { .mcc = 16, .mnc = 17, .mnc_3_digits = true },
1425 .lac = 18,
1426 },
1427 .cell_identity = 19,
1428 }
1429 },
1430 },
1431 };
1432
1433
1434 const struct gsm0808_cell_id_list2 lac1 = {
1435 .id_discr = CELL_IDENT_LAC,
1436 .id_list_len = 1,
1437 .id_list = {
1438 {
1439 .lac = 123
1440 },
1441 },
1442 };
1443
1444 const struct gsm0808_cell_id_list2 lac2 = {
1445 .id_discr = CELL_IDENT_LAC,
1446 .id_list_len = 2,
1447 .id_list = {
1448 {
1449 .lac = 456
1450 },
1451 {
1452 .lac = 789
1453 },
1454 },
1455 };
1456
1457 struct gsm0808_cell_id_list2 cil = {};
1458
1459 printf("------- %s\n", __func__);
1460
1461 print_cil(&cil);
1462
1463#define ADD_QUIET(other_cil, expect_rc) do { \
1464 int rc = gsm0808_cell_id_list_add(&cil, &other_cil); \
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001465 printf("gsm0808_cell_id_list_add(&cil, &" #other_cil ") --> rc = %d\n", rc); \
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001466 OSMO_ASSERT(rc == expect_rc); \
1467 } while(0)
1468
1469#define ADD(other_cil, expect_rc) ADD_QUIET(other_cil, expect_rc); print_cil(&cil)
1470
1471 ADD(lac1, 1);
1472 ADD(lac1, 0);
1473 ADD(lac2, 2);
1474 ADD(lac2, 0);
1475 ADD(cil, 0);
1476 ADD(cgi1, -EINVAL);
1477
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001478 printf("* can't add to BSS list\n");
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001479 cil.id_list_len = 0;
1480 cil.id_discr = CELL_IDENT_BSS;
1481 print_cil(&cil);
1482 ADD(lac1, -EINVAL);
1483
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001484 printf("* other types (including NO_CELL) take on new type iff empty\n");
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001485 cil.id_list_len = 0;
1486 cil.id_discr = CELL_IDENT_NO_CELL;
1487 print_cil(&cil);
1488 ADD(cgi1, 1);
1489 ADD(cgi1, 0);
1490 ADD(cgi2, 2);
1491 ADD(cgi2, 0);
1492
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001493 printf("* test gsm0808_cell_id_list_name_buf()'s return val\n");
1494 zu = strlen(gsm0808_cell_id_list_name(&cil));
1495 printf(" strlen(gsm0808_cell_id_list_name(cil)) == %zu\n", zu);
1496 zu ++;
1497 while (1) {
1498 char buf[128] = "?";
1499 int rc;
1500 OSMO_ASSERT(zu < sizeof(buf));
1501 buf[zu] = '#';
1502 rc = gsm0808_cell_id_list_name_buf(buf, zu, &cil);
1503 printf(" gsm0808_cell_id_list_name_buf(buf, %zu, cil)) == %d \"%s\"\n",
1504 zu, rc, buf);
1505 OSMO_ASSERT(buf[zu] == '#');
1506 if (!zu)
1507 break;
1508 zu /= 2;
1509 }
1510
1511 printf("* list-full behavior\n");
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001512 cil.id_list_len = GSM0808_CELL_ID_LIST2_MAXLEN - 1;
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001513 printf("cil.id_list_len = %u\n", cil.id_list_len);
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001514 ADD_QUIET(cgi2a, 1);
1515 printf("cil.id_list_len = %u\n", cil.id_list_len);
1516
1517 cil.id_list_len = GSM0808_CELL_ID_LIST2_MAXLEN - 1;
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001518 printf("cil.id_list_len = %u\n", cil.id_list_len);
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001519 ADD_QUIET(cgi3, -ENOSPC);
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001520 printf("cil.id_list_len = %u\n", cil.id_list_len);
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001521 ADD_QUIET(cgi2a, -ENOSPC);
1522 printf("cil.id_list_len = %u\n", cil.id_list_len);
1523
1524 printf("------- %s done\n", __func__);
1525}
1526
Neels Hofmeyr250e7f72018-04-13 03:30:14 +02001527static void test_gsm0808_enc_dec_cell_id_lac()
1528{
1529 struct gsm0808_cell_id enc_ci = {
1530 .id_discr = CELL_IDENT_LAC,
1531 .id.lac = 0x0124,
1532 };
1533 struct gsm0808_cell_id dec_ci;
1534 struct msgb *msg;
1535 uint8_t rc_enc;
1536 int rc_dec;
1537
1538 memset(&dec_ci, 0xa5, sizeof(dec_ci));
1539
1540 msg = msgb_alloc(1024, "output buffer");
1541 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1542 EXPECT_ENCODED("05 03 05 01 24");
1543
1544 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1545 OSMO_ASSERT(rc_dec == 3);
1546
1547 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr
1548 && enc_ci.id.lac == dec_ci.id.lac);
1549
1550 msgb_free(msg);
1551}
1552
1553static void test_gsm0808_enc_dec_cell_id_bss()
1554{
1555 struct gsm0808_cell_id enc_ci = {
1556 .id_discr = CELL_IDENT_BSS,
1557 };
1558 struct gsm0808_cell_id dec_ci;
1559 struct msgb *msg;
1560 uint8_t rc_enc;
1561 int rc_dec;
1562
1563 msg = msgb_alloc(1024, "output buffer");
1564 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1565 EXPECT_ENCODED("05 01 06");
1566
1567 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1568 OSMO_ASSERT(rc_dec == 1);
1569
1570 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr);
1571
1572 msgb_free(msg);
1573}
1574
1575static void test_gsm0808_enc_dec_cell_id_no_cell()
1576{
1577 struct gsm0808_cell_id enc_ci = {
1578 .id_discr = CELL_IDENT_NO_CELL,
1579 };
1580 struct gsm0808_cell_id dec_ci;
1581 struct msgb *msg;
1582 uint8_t rc_enc;
1583 int rc_dec;
1584
1585 msg = msgb_alloc(1024, "output buffer");
1586 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1587 EXPECT_ENCODED("05 01 03");
1588
1589 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1590 OSMO_ASSERT(rc_dec == 1);
1591
1592 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr);
1593
1594 msgb_free(msg);
1595}
1596
1597static void test_gsm0808_enc_dec_cell_id_lai_and_lac()
1598{
1599 struct gsm0808_cell_id enc_ci = {
1600 .id_discr = CELL_IDENT_LAI_AND_LAC,
1601 .id.lai_and_lac = {
1602 .plmn = {
1603 .mcc = 123,
1604 .mnc = 456,
1605 },
1606 .lac = 0x2342,
1607 },
1608 };
1609 struct gsm0808_cell_id dec_ci;
1610 struct msgb *msg;
1611 uint8_t rc_enc;
1612 int rc_dec;
1613
1614 msg = msgb_alloc(1024, "output buffer");
1615 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1616 EXPECT_ENCODED("05 06 04 21 63 54 23 42");
1617
1618 memset(&dec_ci, 0xa5, sizeof(dec_ci));
1619 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1620 OSMO_ASSERT(rc_dec == msg->len - 2);
1621
1622 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr
1623 && osmo_plmn_cmp(&enc_ci.id.lai_and_lac.plmn, &dec_ci.id.lai_and_lac.plmn) == 0
1624 && enc_ci.id.lai_and_lac.lac == dec_ci.id.lai_and_lac.lac);
1625 msgb_free(msg);
1626}
1627
1628static void test_gsm0808_enc_dec_cell_id_ci()
1629{
1630 struct gsm0808_cell_id enc_ci = {
1631 .id_discr = CELL_IDENT_CI,
1632 .id.ci = 0x423,
1633 };
1634 struct gsm0808_cell_id dec_ci;
1635 struct msgb *msg;
1636 uint8_t rc_enc;
1637 int rc_dec;
1638
1639 msg = msgb_alloc(1024, "output buffer");
1640 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1641 EXPECT_ENCODED("05 03 02 04 23");
1642
1643 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1644 OSMO_ASSERT(rc_dec == msg->len - 2);
1645 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr
1646 && enc_ci.id.ci == dec_ci.id.ci);
1647
1648 msgb_free(msg);
1649}
1650
1651static void test_gsm0808_enc_dec_cell_id_lac_and_ci()
1652{
1653 struct gsm0808_cell_id enc_ci = {
1654 .id_discr = CELL_IDENT_LAC_AND_CI,
1655 .id.lac_and_ci = {
1656 .lac = 0x423,
1657 .ci = 0x235,
1658 },
1659 };
1660 struct gsm0808_cell_id dec_ci;
1661 struct msgb *msg;
1662 uint8_t rc_enc;
1663 int rc_dec;
1664
1665 msg = msgb_alloc(1024, "output buffer");
1666 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1667 EXPECT_ENCODED("05 05 01 04 23 02 35");
1668
1669 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1670 OSMO_ASSERT(rc_dec == msg->len - 2);
1671 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr
1672 && enc_ci.id.lac_and_ci.lac == dec_ci.id.lac_and_ci.lac
1673 && enc_ci.id.lac_and_ci.ci == dec_ci.id.lac_and_ci.ci);
1674
1675 msgb_free(msg);
1676}
1677
1678static void test_gsm0808_enc_dec_cell_id_global()
1679{
1680 struct gsm0808_cell_id enc_ci = {
1681 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1682 .id.global = {
1683 .lai = {
1684 .plmn = { .mcc = 123, .mnc = 456 },
1685 .lac = 0x2342
1686 },
1687 .cell_identity = 0x423,
1688 }
1689 };
1690 struct gsm0808_cell_id dec_ci;
1691 struct msgb *msg;
1692 uint8_t rc_enc;
1693 int rc_dec;
1694
1695 msg = msgb_alloc(1024, "output buffer");
1696 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1697 EXPECT_ENCODED("05 08 00 21 63 54 23 42 04 23");
1698
1699 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1700 OSMO_ASSERT(rc_dec == msg->len - 2);
1701
1702 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr
1703 && osmo_plmn_cmp(&enc_ci.id.global.lai.plmn,
1704 &dec_ci.id.global.lai.plmn) == 0
1705 && enc_ci.id.global.lai.lac == dec_ci.id.global.lai.lac
1706 && enc_ci.id.global.cell_identity == dec_ci.id.global.cell_identity);
1707 msgb_free(msg);
1708}
1709
Philipp Maier5f2eb152018-09-19 13:40:21 +02001710static void test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(struct gsm48_multi_rate_conf *cfg)
1711{
1712 uint16_t s15_s0;
1713
1714 printf("Input:\n");
1715 printf(" m4_75= %u smod= %u\n", cfg->m4_75, cfg->smod);
1716 printf(" m5_15= %u spare= %u\n", cfg->m5_15, cfg->spare);
1717 printf(" m5_90= %u icmi= %u\n", cfg->m5_90, cfg->icmi);
1718 printf(" m6_70= %u nscb= %u\n", cfg->m6_70, cfg->nscb);
1719 printf(" m7_40= %u ver= %u\n", cfg->m7_40, cfg->ver);
1720 printf(" m7_95= %u\n", cfg->m7_95);
1721 printf(" m10_2= %u\n", cfg->m10_2);
1722 printf(" m12_2= %u\n", cfg->m12_2);
1723
1724 s15_s0 = gsm0808_sc_cfg_from_gsm48_mr_cfg(cfg, true);
1725 printf("Result (fr):\n");
1726 printf(" S15-S0 = %04x = 0b" OSMO_BIN_SPEC OSMO_BIN_SPEC "\n", s15_s0,
1727 OSMO_BIN_PRINT(s15_s0 >> 8), OSMO_BIN_PRINT(s15_s0));
1728
1729 s15_s0 = gsm0808_sc_cfg_from_gsm48_mr_cfg(cfg, false);
1730 printf("Result (hr):\n");
1731 printf(" S15-S0 = %04x = 0b" OSMO_BIN_SPEC OSMO_BIN_SPEC "\n", s15_s0,
1732 OSMO_BIN_PRINT(s15_s0 >> 8), OSMO_BIN_PRINT(s15_s0));
1733
1734 printf("\n");
1735}
1736
1737static void test_gsm0808_sc_cfg_from_gsm48_mr_cfg(void)
1738{
1739 struct gsm48_multi_rate_conf cfg;
1740
1741 printf("Testing gsm0808_sc_cfg_from_gsm48_mr_cfg():\n");
1742
1743 memset(&cfg, 0, sizeof(cfg));
1744
1745 cfg.m4_75 = 0;
1746 cfg.m5_15 = 0;
1747 cfg.m5_90 = 0;
1748 cfg.m6_70 = 0;
1749 cfg.m7_40 = 0;
1750 cfg.m7_95 = 0;
1751 cfg.m10_2 = 0;
1752 cfg.m12_2 = 0;
1753 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1754
1755 cfg.m4_75 = 1;
1756 cfg.m5_15 = 0;
1757 cfg.m5_90 = 0;
1758 cfg.m6_70 = 0;
1759 cfg.m7_40 = 0;
1760 cfg.m7_95 = 0;
1761 cfg.m10_2 = 0;
1762 cfg.m12_2 = 0;
1763 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1764
1765 cfg.m4_75 = 0;
1766 cfg.m5_15 = 1;
1767 cfg.m5_90 = 0;
1768 cfg.m6_70 = 0;
1769 cfg.m7_40 = 0;
1770 cfg.m7_95 = 0;
1771 cfg.m10_2 = 0;
1772 cfg.m12_2 = 0;
1773 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1774
1775 cfg.m4_75 = 0;
1776 cfg.m5_15 = 0;
1777 cfg.m5_90 = 1;
1778 cfg.m6_70 = 0;
1779 cfg.m7_40 = 0;
1780 cfg.m7_95 = 0;
1781 cfg.m10_2 = 0;
1782 cfg.m12_2 = 0;
1783 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1784
1785 cfg.m4_75 = 0;
1786 cfg.m5_15 = 0;
1787 cfg.m5_90 = 0;
1788 cfg.m6_70 = 1;
1789 cfg.m7_40 = 0;
1790 cfg.m7_95 = 0;
1791 cfg.m10_2 = 0;
1792 cfg.m12_2 = 0;
1793 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1794
1795 cfg.m4_75 = 0;
1796 cfg.m5_15 = 0;
1797 cfg.m5_90 = 0;
1798 cfg.m6_70 = 0;
1799 cfg.m7_40 = 1;
1800 cfg.m7_95 = 0;
1801 cfg.m10_2 = 0;
1802 cfg.m12_2 = 0;
1803 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1804
1805 cfg.m4_75 = 0;
1806 cfg.m5_15 = 0;
1807 cfg.m5_90 = 0;
1808 cfg.m6_70 = 0;
1809 cfg.m7_40 = 0;
1810 cfg.m7_95 = 1;
1811 cfg.m10_2 = 0;
1812 cfg.m12_2 = 0;
1813 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1814
1815 cfg.m4_75 = 0;
1816 cfg.m5_15 = 0;
1817 cfg.m5_90 = 0;
1818 cfg.m6_70 = 0;
1819 cfg.m7_40 = 0;
1820 cfg.m7_95 = 0;
1821 cfg.m10_2 = 1;
1822 cfg.m12_2 = 0;
1823 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1824
1825 cfg.m4_75 = 0;
1826 cfg.m5_15 = 0;
1827 cfg.m5_90 = 0;
1828 cfg.m6_70 = 0;
1829 cfg.m7_40 = 0;
1830 cfg.m7_95 = 0;
1831 cfg.m10_2 = 0;
1832 cfg.m12_2 = 1;
1833 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1834
1835 cfg.m4_75 = 1;
1836 cfg.m5_15 = 1;
1837 cfg.m5_90 = 1;
1838 cfg.m6_70 = 1;
1839 cfg.m7_40 = 0;
1840 cfg.m7_95 = 0;
1841 cfg.m10_2 = 0;
1842 cfg.m12_2 = 0;
1843 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1844
1845 cfg.m4_75 = 0;
1846 cfg.m5_15 = 0;
1847 cfg.m5_90 = 0;
1848 cfg.m6_70 = 0;
1849 cfg.m7_40 = 1;
1850 cfg.m7_95 = 1;
1851 cfg.m10_2 = 1;
1852 cfg.m12_2 = 1;
1853 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1854
1855 cfg.m4_75 = 0;
1856 cfg.m5_15 = 0;
1857 cfg.m5_90 = 1;
1858 cfg.m6_70 = 1;
1859 cfg.m7_40 = 0;
1860 cfg.m7_95 = 0;
1861 cfg.m10_2 = 1;
1862 cfg.m12_2 = 1;
1863 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1864
1865 cfg.m4_75 = 1;
1866 cfg.m5_15 = 1;
1867 cfg.m5_90 = 0;
1868 cfg.m6_70 = 0;
1869 cfg.m7_40 = 1;
1870 cfg.m7_95 = 1;
1871 cfg.m10_2 = 0;
1872 cfg.m12_2 = 0;
1873 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1874
1875 cfg.m4_75 = 0;
1876 cfg.m5_15 = 1;
1877 cfg.m5_90 = 0;
1878 cfg.m6_70 = 1;
1879 cfg.m7_40 = 0;
1880 cfg.m7_95 = 1;
1881 cfg.m10_2 = 0;
1882 cfg.m12_2 = 1;
1883 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1884
1885 cfg.m4_75 = 1;
1886 cfg.m5_15 = 0;
1887 cfg.m5_90 = 1;
1888 cfg.m6_70 = 0;
1889 cfg.m7_40 = 1;
1890 cfg.m7_95 = 0;
1891 cfg.m10_2 = 1;
1892 cfg.m12_2 = 0;
1893 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1894
1895 cfg.m4_75 = 1;
1896 cfg.m5_15 = 1;
1897 cfg.m5_90 = 1;
1898 cfg.m6_70 = 1;
1899 cfg.m7_40 = 1;
1900 cfg.m7_95 = 1;
1901 cfg.m10_2 = 1;
1902 cfg.m12_2 = 1;
1903 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1904}
1905
Philipp Maier8515d032018-09-25 15:57:49 +02001906static void test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single(uint16_t s15_s0)
1907{
1908 struct gsm48_multi_rate_conf cfg;
1909
1910 printf("Input:\n");
1911 printf(" S15-S0 = %04x = 0b" OSMO_BIN_SPEC OSMO_BIN_SPEC "\n", s15_s0,
1912 OSMO_BIN_PRINT(s15_s0 >> 8), OSMO_BIN_PRINT(s15_s0));
1913
1914 gsm48_mr_cfg_from_gsm0808_sc_cfg(&cfg, s15_s0);
1915
1916 printf("Output:\n");
1917 printf(" m4_75= %u smod= %u\n", cfg.m4_75, cfg.smod);
1918 printf(" m5_15= %u spare= %u\n", cfg.m5_15, cfg.spare);
1919 printf(" m5_90= %u icmi= %u\n", cfg.m5_90, cfg.icmi);
1920 printf(" m6_70= %u nscb= %u\n", cfg.m6_70, cfg.nscb);
1921 printf(" m7_40= %u ver= %u\n", cfg.m7_40, cfg.ver);
1922 printf(" m7_95= %u\n", cfg.m7_95);
1923 printf(" m10_2= %u\n", cfg.m10_2);
1924 printf(" m12_2= %u\n", cfg.m12_2);
1925
1926 printf("\n");
1927}
1928
1929void test_gsm48_mr_cfg_from_gsm0808_sc_cfg()
1930{
1931 printf("Testing gsm48_mr_cfg_from_gsm0808_sc_cfg():\n");
1932
1933 /* Only one codec per setting */
1934 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1935 (GSM0808_SC_CFG_DEFAULT_AMR_4_75);
1936 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1937 (GSM0808_SC_CFG_DEFAULT_AMR_5_15);
1938 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1939 (GSM0808_SC_CFG_DEFAULT_AMR_5_90);
1940 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1941 (GSM0808_SC_CFG_DEFAULT_AMR_6_70);
1942 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1943 (GSM0808_SC_CFG_DEFAULT_AMR_7_40);
1944 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1945 (GSM0808_SC_CFG_DEFAULT_AMR_7_95);
1946 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1947 (GSM0808_SC_CFG_DEFAULT_AMR_10_2);
1948 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1949 (GSM0808_SC_CFG_DEFAULT_AMR_12_2);
1950
1951 /* Combinations */
1952 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1953 (GSM0808_SC_CFG_DEFAULT_AMR_4_75 | GSM0808_SC_CFG_DEFAULT_AMR_6_70 |
1954 GSM0808_SC_CFG_DEFAULT_AMR_10_2);
1955 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1956 (GSM0808_SC_CFG_DEFAULT_AMR_10_2 | GSM0808_SC_CFG_DEFAULT_AMR_12_2 |
1957 GSM0808_SC_CFG_DEFAULT_AMR_7_40);
1958 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1959 (GSM0808_SC_CFG_DEFAULT_AMR_7_95 | GSM0808_SC_CFG_DEFAULT_AMR_12_2);
1960}
1961
Neels Hofmeyrd01ef752018-09-21 15:57:26 +02001962struct test_cell_id_matching_data {
1963 struct gsm0808_cell_id id;
1964 struct gsm0808_cell_id match_id;
1965 bool expect_match;
1966 bool expect_exact_match;
1967};
1968
1969#define lac_23 { .id_discr = CELL_IDENT_LAC, .id.lac = 23, }
1970#define lac_42 { .id_discr = CELL_IDENT_LAC, .id.lac = 42, }
1971#define ci_5 { .id_discr = CELL_IDENT_CI, .id.ci = 5, }
1972#define ci_6 { .id_discr = CELL_IDENT_CI, .id.ci = 6, }
1973#define lac_ci_23_5 { \
1974 .id_discr = CELL_IDENT_LAC_AND_CI, \
1975 .id.lac_and_ci = { .lac = 23, .ci = 5, }, \
1976 }
1977#define lac_ci_42_6 { \
1978 .id_discr = CELL_IDENT_LAC_AND_CI, \
1979 .id.lac_and_ci = { .lac = 42, .ci = 6, }, \
1980 }
1981#define lai_23_042_23 { \
1982 .id_discr = CELL_IDENT_LAI_AND_LAC, \
1983 .id.lai_and_lac = { .plmn = { .mcc = 23, .mnc = 42, .mnc_3_digits = true }, .lac = 23, }, \
1984 }
1985#define lai_23_042_42 { \
1986 .id_discr = CELL_IDENT_LAI_AND_LAC, \
1987 .id.lai_and_lac = { .plmn = { .mcc = 23, .mnc = 42, .mnc_3_digits = true }, .lac = 42, }, \
1988 }
1989#define lai_23_99_23 { \
1990 .id_discr = CELL_IDENT_LAI_AND_LAC, \
1991 .id.lai_and_lac = { .plmn = { .mcc = 23, .mnc = 99, .mnc_3_digits = false }, .lac = 23, }, \
1992 }
1993#define lai_23_42_23 { \
1994 .id_discr = CELL_IDENT_LAI_AND_LAC, \
1995 .id.lai_and_lac = { .plmn = { .mcc = 23, .mnc = 42, .mnc_3_digits = false }, .lac = 23, }, \
1996 }
1997#define cgi_23_042_23_5 { \
1998 .id_discr = CELL_IDENT_WHOLE_GLOBAL, \
1999 .id.global = { \
2000 .lai = { .plmn = { .mcc = 23, .mnc = 42, .mnc_3_digits = true }, .lac = 23, }, \
2001 .cell_identity = 5, \
2002 }, \
2003 }
2004#define cgi_23_042_42_6 { \
2005 .id_discr = CELL_IDENT_WHOLE_GLOBAL, \
2006 .id.global = { \
2007 .lai = { .plmn = { .mcc = 23, .mnc = 42, .mnc_3_digits = true }, .lac = 42, }, \
2008 .cell_identity = 6, \
2009 }, \
2010 }
2011#define cgi_23_99_23_5 { \
2012 .id_discr = CELL_IDENT_WHOLE_GLOBAL, \
2013 .id.global = { \
2014 .lai = { .plmn = { .mcc = 23, .mnc = 99, .mnc_3_digits = false }, .lac = 23, }, \
2015 .cell_identity = 5, \
2016 }, \
2017 }
2018
2019
2020static const struct test_cell_id_matching_data test_cell_id_matching_tests[] = {
2021 { .id = lac_23, .match_id = lac_23, .expect_match = true, .expect_exact_match = true },
2022 { .id = lac_23, .match_id = lac_42, .expect_match = false, .expect_exact_match = false },
2023 { .id = lac_23, .match_id = ci_5, .expect_match = true, .expect_exact_match = false },
2024 { .id = lac_23, .match_id = ci_6, .expect_match = true, .expect_exact_match = false },
2025 { .id = lac_23, .match_id = lac_ci_23_5, .expect_match = true, .expect_exact_match = false },
2026 { .id = lac_23, .match_id = lac_ci_42_6, .expect_match = false, .expect_exact_match = false },
2027 { .id = lac_23, .match_id = lai_23_042_23, .expect_match = true, .expect_exact_match = false },
2028 { .id = lac_23, .match_id = lai_23_042_42, .expect_match = false, .expect_exact_match = false },
2029 { .id = lac_23, .match_id = lai_23_99_23, .expect_match = true, .expect_exact_match = false },
2030 { .id = lac_23, .match_id = lai_23_42_23, .expect_match = true, .expect_exact_match = false },
2031 { .id = lac_23, .match_id = cgi_23_042_23_5, .expect_match = true, .expect_exact_match = false },
2032 { .id = lac_23, .match_id = cgi_23_042_42_6, .expect_match = false, .expect_exact_match = false },
2033 { .id = lac_23, .match_id = cgi_23_99_23_5, .expect_match = true, .expect_exact_match = false },
2034 { .id = ci_5, .match_id = lac_23, .expect_match = true, .expect_exact_match = false },
2035 { .id = ci_5, .match_id = lac_42, .expect_match = true, .expect_exact_match = false },
2036 { .id = ci_5, .match_id = ci_5, .expect_match = true, .expect_exact_match = true },
2037 { .id = ci_5, .match_id = ci_6, .expect_match = false, .expect_exact_match = false },
2038 { .id = ci_5, .match_id = lac_ci_23_5, .expect_match = true, .expect_exact_match = false },
2039 { .id = ci_5, .match_id = lac_ci_42_6, .expect_match = false, .expect_exact_match = false },
2040 { .id = ci_5, .match_id = lai_23_042_23, .expect_match = true, .expect_exact_match = false },
2041 { .id = ci_5, .match_id = lai_23_042_42, .expect_match = true, .expect_exact_match = false },
2042 { .id = ci_5, .match_id = lai_23_99_23, .expect_match = true, .expect_exact_match = false },
2043 { .id = ci_5, .match_id = lai_23_42_23, .expect_match = true, .expect_exact_match = false },
2044 { .id = ci_5, .match_id = cgi_23_042_23_5, .expect_match = true, .expect_exact_match = false },
2045 { .id = ci_5, .match_id = cgi_23_042_42_6, .expect_match = false, .expect_exact_match = false },
2046 { .id = ci_5, .match_id = cgi_23_99_23_5, .expect_match = true, .expect_exact_match = false },
2047 { .id = lac_ci_23_5, .match_id = lac_23, .expect_match = true, .expect_exact_match = false },
2048 { .id = lac_ci_23_5, .match_id = lac_42, .expect_match = false, .expect_exact_match = false },
2049 { .id = lac_ci_23_5, .match_id = ci_5, .expect_match = true, .expect_exact_match = false },
2050 { .id = lac_ci_23_5, .match_id = ci_6, .expect_match = false, .expect_exact_match = false },
2051 { .id = lac_ci_23_5, .match_id = lac_ci_23_5, .expect_match = true, .expect_exact_match = true },
2052 { .id = lac_ci_23_5, .match_id = lac_ci_42_6, .expect_match = false, .expect_exact_match = false },
2053 { .id = lac_ci_23_5, .match_id = lai_23_042_23, .expect_match = true, .expect_exact_match = false },
2054 { .id = lac_ci_23_5, .match_id = lai_23_042_42, .expect_match = false, .expect_exact_match = false },
2055 { .id = lac_ci_23_5, .match_id = lai_23_99_23, .expect_match = true, .expect_exact_match = false },
2056 { .id = lac_ci_23_5, .match_id = lai_23_42_23, .expect_match = true, .expect_exact_match = false },
2057 { .id = lac_ci_23_5, .match_id = cgi_23_042_23_5, .expect_match = true, .expect_exact_match = false },
2058 { .id = lac_ci_23_5, .match_id = cgi_23_042_42_6, .expect_match = false, .expect_exact_match = false },
2059 { .id = lac_ci_23_5, .match_id = cgi_23_99_23_5, .expect_match = true, .expect_exact_match = false },
2060 { .id = lai_23_042_23, .match_id = lac_23, .expect_match = true, .expect_exact_match = false },
2061 { .id = lai_23_042_23, .match_id = lac_42, .expect_match = false, .expect_exact_match = false },
2062 { .id = lai_23_042_23, .match_id = ci_5, .expect_match = true, .expect_exact_match = false },
2063 { .id = lai_23_042_23, .match_id = ci_6, .expect_match = true, .expect_exact_match = false },
2064 { .id = lai_23_042_23, .match_id = lac_ci_23_5, .expect_match = true, .expect_exact_match = false },
2065 { .id = lai_23_042_23, .match_id = lac_ci_42_6, .expect_match = false, .expect_exact_match = false },
2066 { .id = lai_23_042_23, .match_id = lai_23_042_23, .expect_match = true, .expect_exact_match = true },
2067 { .id = lai_23_042_23, .match_id = lai_23_042_42, .expect_match = false, .expect_exact_match = false },
2068 { .id = lai_23_042_23, .match_id = lai_23_99_23, .expect_match = false, .expect_exact_match = false },
2069 { .id = lai_23_042_23, .match_id = lai_23_42_23, .expect_match = false, .expect_exact_match = false },
2070 { .id = lai_23_042_23, .match_id = cgi_23_042_23_5, .expect_match = true, .expect_exact_match = false },
2071 { .id = lai_23_042_23, .match_id = cgi_23_042_42_6, .expect_match = false, .expect_exact_match = false },
2072 { .id = lai_23_042_23, .match_id = cgi_23_99_23_5, .expect_match = false, .expect_exact_match = false },
2073 { .id = cgi_23_042_23_5, .match_id = lac_23, .expect_match = true, .expect_exact_match = false },
2074 { .id = cgi_23_042_23_5, .match_id = lac_42, .expect_match = false, .expect_exact_match = false },
2075 { .id = cgi_23_042_23_5, .match_id = ci_5, .expect_match = true, .expect_exact_match = false },
2076 { .id = cgi_23_042_23_5, .match_id = ci_6, .expect_match = false, .expect_exact_match = false },
2077 { .id = cgi_23_042_23_5, .match_id = lac_ci_23_5, .expect_match = true, .expect_exact_match = false },
2078 { .id = cgi_23_042_23_5, .match_id = lac_ci_42_6, .expect_match = false, .expect_exact_match = false },
2079 { .id = cgi_23_042_23_5, .match_id = lai_23_042_23, .expect_match = true, .expect_exact_match = false },
2080 { .id = cgi_23_042_23_5, .match_id = lai_23_042_42, .expect_match = false, .expect_exact_match = false },
2081 { .id = cgi_23_042_23_5, .match_id = lai_23_99_23, .expect_match = false, .expect_exact_match = false },
2082 { .id = cgi_23_042_23_5, .match_id = lai_23_42_23, .expect_match = false, .expect_exact_match = false },
2083 { .id = cgi_23_042_23_5, .match_id = cgi_23_042_23_5, .expect_match = true, .expect_exact_match = true },
2084 { .id = cgi_23_042_23_5, .match_id = cgi_23_042_42_6, .expect_match = false, .expect_exact_match = false },
2085 { .id = cgi_23_042_23_5, .match_id = cgi_23_99_23_5, .expect_match = false, .expect_exact_match = false },
2086};
2087
2088static void test_cell_id_matching()
2089{
2090 int i;
2091 bool ok = true;
2092 printf("\n%s\n", __func__);
2093
2094 for (i = 0; i < ARRAY_SIZE(test_cell_id_matching_tests); i++) {
2095 const struct test_cell_id_matching_data *d = &test_cell_id_matching_tests[i];
2096 int exact_match;
2097
2098 for (exact_match = 0; exact_match < 2; exact_match++) {
2099 bool result;
2100 bool expect_result = exact_match ? d->expect_exact_match : d->expect_match;
2101
2102 result = gsm0808_cell_ids_match(&d->id, &d->match_id, (bool)exact_match);
2103
2104 printf("[%d] %s %s %s%s\n",
2105 i,
2106 gsm0808_cell_id_name(&d->id),
2107 gsm0808_cell_id_name2(&d->match_id),
2108 result ? "MATCH" : "don't match",
2109 exact_match ? " exactly" : "");
2110 if (result != expect_result) {
2111 printf(" ERROR: expected %s\n", d->expect_match ? "MATCH" : "no match");
2112 ok = false;
2113 }
2114 }
2115 }
2116
2117 OSMO_ASSERT(ok);
2118}
2119
2120static bool test_cell_id_list_matching_discrs(bool test_match,
2121 enum CELL_IDENT id_discr,
2122 enum CELL_IDENT list_discr)
2123{
2124 int i, j;
2125 const struct gsm0808_cell_id *id = NULL;
2126 struct gsm0808_cell_id_list2 list = {};
2127 int match_idx = -1;
2128 int result;
2129
2130 for (i = 0; i < ARRAY_SIZE(test_cell_id_matching_tests); i++) {
2131 const struct test_cell_id_matching_data *d = &test_cell_id_matching_tests[i];
2132 if (id_discr != d->id.id_discr)
2133 continue;
2134 id = &d->id;
2135 break;
2136 }
2137
2138 if (!id) {
2139 printf("Did not find any entry for %s\n", gsm0808_cell_id_discr_name(id_discr));
2140 return true;
2141 }
2142
2143 /* Collect those entries with exactly this id on the left, of type list_discr on the right.
2144 * Collect the mismatches first, for more interesting match indexes in the results. */
2145 for (j = 0; j < 2; j++) {
2146 bool collect_matches = (bool)j;
2147
2148 /* If we want to have a mismatching list, don't add any entries that match. */
2149 if (!test_match && collect_matches)
2150 continue;
2151
2152 for (i = 0; i < ARRAY_SIZE(test_cell_id_matching_tests); i++) {
2153 const struct test_cell_id_matching_data *d = &test_cell_id_matching_tests[i];
2154 struct gsm0808_cell_id_list2 add;
2155
2156 /* Ignore those with a different d->id */
2157 if (!gsm0808_cell_ids_match(&d->id, id, true))
2158 continue;
2159
2160 /* Ignore those with a different d->match_id discr */
2161 if (d->match_id.id_discr != list_discr)
2162 continue;
2163
2164 if (collect_matches != d->expect_match)
2165 continue;
2166
2167 if (match_idx < 0 && d->expect_match) {
2168 match_idx = list.id_list_len;
2169 }
2170
2171 gsm0808_cell_id_to_list(&add, &d->match_id);
2172 gsm0808_cell_id_list_add(&list, &add);
2173 }
2174 }
2175
2176 if (!list.id_list_len) {
2177 printf("%s vs. %s: No match_id entries to test %s\n",
2178 gsm0808_cell_id_name(id),
2179 gsm0808_cell_id_discr_name(list_discr),
2180 test_match ? "MATCH" : "mismatch");
2181 return true;
2182 }
2183
2184 result = gsm0808_cell_id_matches_list(id, &list, 0, false);
2185
2186 printf("%s and %s: ",
2187 gsm0808_cell_id_name(id),
2188 gsm0808_cell_id_list_name(&list));
2189 if (result >= 0)
2190 printf("MATCH at [%d]\n", result);
2191 else
2192 printf("mismatch\n");
2193
2194 if (test_match
2195 && (result < 0 || result != match_idx)) {
2196 printf(" ERROR: expected MATCH at %d\n", match_idx);
2197 return false;
2198 }
2199
2200 if (!test_match && result >= 0) {
2201 printf(" ERROR: expected mismatch\n");
2202 return false;
2203 }
2204
2205 return true;
2206}
2207
2208static void test_cell_id_list_matching(bool test_match)
2209{
2210 int i, j;
2211 bool ok = true;
2212
2213 const enum CELL_IDENT discrs[] = {
2214 CELL_IDENT_LAC, CELL_IDENT_CI, CELL_IDENT_LAC_AND_CI, CELL_IDENT_LAI_AND_LAC,
2215 CELL_IDENT_WHOLE_GLOBAL,
2216 };
2217
2218 printf("\n%s(%s)\n", __func__, test_match ? "test match" : "test mismatch");
2219
2220 /* Autogenerate Cell ID lists from above dataset, which should match / not match. */
2221 for (i = 0; i < ARRAY_SIZE(discrs); i++) {
2222 for (j = 0; j < ARRAY_SIZE(discrs); j++)
2223 if (!test_cell_id_list_matching_discrs(test_match,
2224 discrs[i], discrs[j]))
2225 ok = false;
2226 }
2227
2228 OSMO_ASSERT(ok);
2229}
2230
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002231int main(int argc, char **argv)
2232{
Max969fb2e2018-12-10 11:01:10 +01002233 void *ctx = talloc_named_const(NULL, 0, "gsm0808 test");
2234 msgb_talloc_ctx_init(ctx, 0);
2235 osmo_init_logging2(ctx, NULL);
2236
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002237 printf("Testing generation of GSM0808 messages\n");
Philipp Maier4f4905f2018-11-30 13:36:12 +01002238 test_gsm0808_enc_cause();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002239 test_create_layer3();
Philipp Maierfa896ab2017-03-27 16:55:32 +02002240 test_create_layer3_aoip();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002241 test_create_reset();
Philipp Maier15596e22017-04-05 17:55:27 +02002242 test_create_reset_ack();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002243 test_create_clear_command();
Harald Weltecf665fc2019-02-18 13:45:36 +01002244 test_create_clear_command2();
2245 test_create_clear_command2_csfb();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002246 test_create_clear_complete();
Philipp Maierb478dd32017-03-29 15:50:05 +02002247 test_create_cipher();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002248 test_create_cipher_complete();
2249 test_create_cipher_reject();
Maxed651d22018-11-07 15:25:05 +01002250 test_create_cipher_reject_ext();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002251 test_create_cm_u();
2252 test_create_sapi_reject();
Philipp Maierc6144a22017-03-29 17:53:43 +02002253 test_create_ass();
Max52074322018-11-30 10:44:07 +01002254 test_create_ass2();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002255 test_create_ass_compl();
Philipp Maierfa896ab2017-03-27 16:55:32 +02002256 test_create_ass_compl_aoip();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002257 test_create_ass_fail();
Philipp Maierfa896ab2017-03-27 16:55:32 +02002258 test_create_ass_fail_aoip();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002259 test_create_clear_rqst();
Philipp Maier3d48ec02017-03-29 17:37:55 +02002260 test_create_paging();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002261 test_create_dtap();
2262 test_prepend_dtap();
Max969fb2e2018-12-10 11:01:10 +01002263
Max47022152018-12-19 18:51:00 +01002264 test_enc_dec_lcls();
Max969fb2e2018-12-10 11:01:10 +01002265
Philipp Maier22401432017-03-24 17:59:26 +01002266 test_enc_dec_aoip_trasp_addr_v4();
2267 test_enc_dec_aoip_trasp_addr_v6();
Philipp Maier6f725d62017-03-24 18:03:17 +01002268 test_gsm0808_enc_dec_speech_codec();
Philipp Maier6f725d62017-03-24 18:03:17 +01002269 test_gsm0808_enc_dec_speech_codec_ext_with_cfg();
Philipp Maierbb839662017-06-01 17:11:19 +02002270 test_gsm0808_enc_dec_speech_codec_with_cfg();
Philipp Maier6f725d62017-03-24 18:03:17 +01002271 test_gsm0808_enc_dec_speech_codec_list();
Philipp Maierf6c369f2018-10-16 15:24:47 +02002272 test_gsm0808_enc_dec_empty_speech_codec_list();
Philipp Maiere0c65302017-03-28 17:05:40 +02002273 test_gsm0808_enc_dec_channel_type();
Philipp Maier14e76b92017-03-28 18:36:52 +02002274 test_gsm0808_enc_dec_encrypt_info();
Neels Hofmeyr250e7f72018-04-13 03:30:14 +02002275
Philipp Maier783047e2017-03-29 11:35:50 +02002276 test_gsm0808_enc_dec_cell_id_list_lac();
2277 test_gsm0808_enc_dec_cell_id_list_single_lac();
Stefan Sperlinge1a86742018-03-15 18:05:02 +01002278 test_gsm0808_enc_dec_cell_id_list_multi_lac();
Philipp Maier783047e2017-03-29 11:35:50 +02002279 test_gsm0808_enc_dec_cell_id_list_bss();
Stefan Sperling23381452018-03-15 19:38:15 +01002280 test_gsm0808_enc_dec_cell_id_list_multi_lai_and_lac();
Stefan Sperling9c62fc62018-03-16 10:23:34 +01002281 test_gsm0808_enc_dec_cell_id_list_multi_ci();
Stefan Sperlinged4327c2018-03-16 11:02:59 +01002282 test_gsm0808_enc_dec_cell_id_list_multi_lac_and_ci();
Stefan Sperling483f3862018-03-16 12:21:26 +01002283 test_gsm0808_enc_dec_cell_id_list_multi_global();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002284
Neels Hofmeyr74663d92018-03-23 01:46:42 +01002285 test_cell_id_list_add();
2286
Neels Hofmeyr250e7f72018-04-13 03:30:14 +02002287 test_gsm0808_enc_dec_cell_id_lac();
2288 test_gsm0808_enc_dec_cell_id_bss();
2289 test_gsm0808_enc_dec_cell_id_no_cell();
2290 test_gsm0808_enc_dec_cell_id_lai_and_lac();
2291 test_gsm0808_enc_dec_cell_id_ci();
2292 test_gsm0808_enc_dec_cell_id_lac_and_ci();
2293 test_gsm0808_enc_dec_cell_id_global();
2294
Philipp Maier5f2eb152018-09-19 13:40:21 +02002295 test_gsm0808_sc_cfg_from_gsm48_mr_cfg();
Philipp Maier8515d032018-09-25 15:57:49 +02002296 test_gsm48_mr_cfg_from_gsm0808_sc_cfg();
Philipp Maier5f2eb152018-09-19 13:40:21 +02002297
Neels Hofmeyrd01ef752018-09-21 15:57:26 +02002298 test_cell_id_matching();
2299 test_cell_id_list_matching(true);
2300 test_cell_id_list_matching(false);
2301
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002302 printf("Done\n");
2303 return EXIT_SUCCESS;
2304}