blob: af90d00c4080ab68ec11e1492bc419153da07d68 [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)) {
Max5ec0cf52019-01-15 16:37:09 +0100763 printf("GCR parsed wrong:\n\t%s\n\t%s\n", osmo_gcr_dump(lcls_out), osmo_gcr_dump(&lcls_in));
Max1bec3902019-01-14 19:31:42 +0100764 abort();
765 }
Max969fb2e2018-12-10 11:01:10 +0100766
Max5ec0cf52019-01-15 16:37:09 +0100767 printf("\tdecoded %d bytes: %s:\n%s\n", rc, rc == len ? "OK" : "FAIL", osmo_lcls_dump(lcls_out));
768 printf("\t%s\n", osmo_gcr_dump(lcls_out));
Max969fb2e2018-12-10 11:01:10 +0100769 msgb_free(msg);
770}
771
Philipp Maier22401432017-03-24 17:59:26 +0100772static void test_enc_dec_aoip_trasp_addr_v4()
773{
774 struct sockaddr_storage enc_addr;
775 struct sockaddr_storage dec_addr;
776 struct sockaddr_in enc_addr_in;
777 struct msgb *msg;
778 uint8_t rc_enc;
779 int rc_dec;
780
781 memset(&enc_addr_in, 0, sizeof(enc_addr_in));
782 enc_addr_in.sin_family = AF_INET;
783 enc_addr_in.sin_port = htons(1234);
784 inet_aton("255.0.255.255", &enc_addr_in.sin_addr);
785
786 memset(&enc_addr, 0, sizeof(enc_addr));
787 memcpy(&enc_addr, &enc_addr_in, sizeof(enc_addr_in));
788
789 msg = msgb_alloc(1024, "output buffer");
790 rc_enc = gsm0808_enc_aoip_trasp_addr(msg, &enc_addr);
791 OSMO_ASSERT(rc_enc == 8);
792 rc_dec =
793 gsm0808_dec_aoip_trasp_addr(&dec_addr, msg->data + 2, msg->len - 2);
794 OSMO_ASSERT(rc_dec == 6);
795 OSMO_ASSERT(memcmp(&enc_addr, &dec_addr, sizeof(enc_addr)) == 0);
796
797 msgb_free(msg);
798}
799
800static void test_enc_dec_aoip_trasp_addr_v6()
801{
802 struct sockaddr_storage enc_addr;
803 struct sockaddr_storage dec_addr;
804 struct sockaddr_in6 enc_addr_in;
805 struct msgb *msg;
806 uint8_t rc_enc;
807 int rc_dec;
808
809 memset(&enc_addr_in, 0, sizeof(enc_addr_in));
810 enc_addr_in.sin6_family = AF_INET6;
811 enc_addr_in.sin6_port = htons(4567);
812 inet_pton(AF_INET6, "2001:0db8:85a3:08d3:1319:8a2e:0370:7344",
813 &enc_addr_in.sin6_addr);
814
815 memset(&enc_addr, 0, sizeof(enc_addr));
816 memcpy(&enc_addr, &enc_addr_in, sizeof(enc_addr_in));
817
818 msg = msgb_alloc(1024, "output buffer");
819 rc_enc = gsm0808_enc_aoip_trasp_addr(msg, &enc_addr);
820 OSMO_ASSERT(rc_enc == 20);
821 rc_dec =
822 gsm0808_dec_aoip_trasp_addr(&dec_addr, msg->data + 2, msg->len - 2);
823 OSMO_ASSERT(rc_dec == 18);
824 OSMO_ASSERT(memcmp(&enc_addr, &dec_addr, sizeof(enc_addr)) == 0);
825
826 msgb_free(msg);
827}
828
Philipp Maier6f725d62017-03-24 18:03:17 +0100829static void test_gsm0808_enc_dec_speech_codec()
830{
Neels Hofmeyr9a4286b2018-04-20 12:27:52 +0200831 struct gsm0808_speech_codec enc_sc = {
832 .pi = true,
833 .tf = true,
834 .type = GSM0808_SCT_FR2,
835 };
836 struct gsm0808_speech_codec dec_sc = {};
Philipp Maier6f725d62017-03-24 18:03:17 +0100837 struct msgb *msg;
838 uint8_t rc_enc;
839 int rc_dec;
840
Philipp Maier6f725d62017-03-24 18:03:17 +0100841 msg = msgb_alloc(1024, "output buffer");
842 rc_enc = gsm0808_enc_speech_codec(msg, &enc_sc);
843 OSMO_ASSERT(rc_enc == 3);
844
845 rc_dec = gsm0808_dec_speech_codec(&dec_sc, msg->data + 2, msg->len - 2);
846 OSMO_ASSERT(rc_dec == 1);
847
848 OSMO_ASSERT(memcmp(&enc_sc, &dec_sc, sizeof(enc_sc)) == 0);
849
850 msgb_free(msg);
851}
852
853
Philipp Maierbb839662017-06-01 17:11:19 +0200854static void test_gsm0808_enc_dec_speech_codec_with_cfg()
855{
Neels Hofmeyrc62c9342018-04-15 23:31:47 +0200856 struct gsm0808_speech_codec enc_sc = {
857 .pi = true,
858 .tf = true,
859 .type = GSM0808_SCT_FR3,
860 .cfg = 0xabcd,
861 };
862 struct gsm0808_speech_codec dec_sc = {};
Philipp Maierbb839662017-06-01 17:11:19 +0200863 struct msgb *msg;
864 uint8_t rc_enc;
865 int rc_dec;
866
Philipp Maierbb839662017-06-01 17:11:19 +0200867 msg = msgb_alloc(1024, "output buffer");
868 rc_enc = gsm0808_enc_speech_codec(msg, &enc_sc);
869 OSMO_ASSERT(rc_enc == 5);
870
871 rc_dec = gsm0808_dec_speech_codec(&dec_sc, msg->data + 2, msg->len - 2);
872 OSMO_ASSERT(rc_dec == 3);
873
874 OSMO_ASSERT(memcmp(&enc_sc, &dec_sc, sizeof(enc_sc)) == 0);
875
876 msgb_free(msg);
877}
878
Philipp Maier6f725d62017-03-24 18:03:17 +0100879static void test_gsm0808_enc_dec_speech_codec_ext_with_cfg()
880{
Neels Hofmeyr9a4286b2018-04-20 12:27:52 +0200881 struct gsm0808_speech_codec enc_sc = {
882 .pi = true,
883 .tf = true,
884 .type = GSM0808_SCT_CSD,
885 .cfg = 0xc0,
886 };
887 struct gsm0808_speech_codec dec_sc = {};
Philipp Maier6f725d62017-03-24 18:03:17 +0100888 struct msgb *msg;
889 uint8_t rc_enc;
890 int rc_dec;
891
Philipp Maier6f725d62017-03-24 18:03:17 +0100892 msg = msgb_alloc(1024, "output buffer");
893 rc_enc = gsm0808_enc_speech_codec(msg, &enc_sc);
Philipp Maierbb839662017-06-01 17:11:19 +0200894 OSMO_ASSERT(rc_enc == 5);
Philipp Maier6f725d62017-03-24 18:03:17 +0100895
896 rc_dec = gsm0808_dec_speech_codec(&dec_sc, msg->data + 2, msg->len - 2);
Philipp Maierbb839662017-06-01 17:11:19 +0200897 OSMO_ASSERT(rc_dec == 3);
Philipp Maier6f725d62017-03-24 18:03:17 +0100898
899 OSMO_ASSERT(memcmp(&enc_sc, &dec_sc, sizeof(enc_sc)) == 0);
900
901 msgb_free(msg);
902}
903
904static void test_gsm0808_enc_dec_speech_codec_list()
905{
Neels Hofmeyr9a4286b2018-04-20 12:27:52 +0200906 struct gsm0808_speech_codec_list enc_scl = {
907 .codec = {
908 {
909 .pi = true,
910 .tf = true,
911 .type = GSM0808_SCT_FR3,
912 .cfg = 0xcdef,
913 },
914
915 {
916 .fi = true,
917 .pt = true,
918 .type = GSM0808_SCT_FR2,
919 },
920
921 {
922 .fi = true,
923 .tf = true,
924 .type = GSM0808_SCT_CSD,
925 .cfg = 0xc0,
926 },
927 },
928 .len = 3,
929 };
930 struct gsm0808_speech_codec_list dec_scl = {};
Philipp Maier6f725d62017-03-24 18:03:17 +0100931 struct msgb *msg;
932 uint8_t rc_enc;
933 int rc_dec;
934
Philipp Maier6f725d62017-03-24 18:03:17 +0100935 msg = msgb_alloc(1024, "output buffer");
936 rc_enc = gsm0808_enc_speech_codec_list(msg, &enc_scl);
937 OSMO_ASSERT(rc_enc == 9);
938
939 rc_dec = gsm0808_dec_speech_codec_list(&dec_scl, msg->data + 2, msg->len - 2);
940 OSMO_ASSERT(rc_dec == 7);
941
942 OSMO_ASSERT(memcmp(&enc_scl, &dec_scl, sizeof(enc_scl)) == 0);
943
944 msgb_free(msg);
945}
946
Philipp Maierf6c369f2018-10-16 15:24:47 +0200947static void test_gsm0808_enc_dec_empty_speech_codec_list()
948{
949 struct gsm0808_speech_codec_list enc_scl = {
950 .len = 0,
951 };
952 struct gsm0808_speech_codec_list dec_scl = {};
953 struct msgb *msg;
954 uint8_t rc_enc;
955 int rc_dec;
956
957 msg = msgb_alloc(1024, "output buffer");
958 rc_enc = gsm0808_enc_speech_codec_list(msg, &enc_scl);
959 OSMO_ASSERT(rc_enc == 2);
960
961 rc_dec = gsm0808_dec_speech_codec_list(&dec_scl, msg->data + 2, msg->len - 2);
962 OSMO_ASSERT(rc_dec == 0);
963
964 OSMO_ASSERT(memcmp(&enc_scl, &dec_scl, sizeof(enc_scl)) == 0);
965
966 msgb_free(msg);
967}
968
Philipp Maiere0c65302017-03-28 17:05:40 +0200969static void test_gsm0808_enc_dec_channel_type()
970{
Neels Hofmeyr9a4286b2018-04-20 12:27:52 +0200971 struct gsm0808_channel_type enc_ct = {
972 .ch_indctr = GSM0808_CHAN_SPEECH,
973 .ch_rate_type = GSM0808_SPEECH_HALF_PREF,
974 .perm_spch = { GSM0808_PERM_FR3, GSM0808_PERM_HR3 },
975 .perm_spch_len = 2,
976 };
977 struct gsm0808_channel_type dec_ct = {};
Philipp Maiere0c65302017-03-28 17:05:40 +0200978 struct msgb *msg;
979 uint8_t ct_enc_expected[] = { GSM0808_IE_CHANNEL_TYPE,
980 0x04, 0x01, 0x0b, 0xa1, 0x25
981 };
982 uint8_t rc_enc;
983 int rc_dec;
984
Philipp Maiere0c65302017-03-28 17:05:40 +0200985 msg = msgb_alloc(1024, "output buffer");
986 rc_enc = gsm0808_enc_channel_type(msg, &enc_ct);
987 OSMO_ASSERT(rc_enc == 6);
988 OSMO_ASSERT(memcmp(ct_enc_expected, msg->data, msg->len) == 0);
989
990 rc_dec = gsm0808_dec_channel_type(&dec_ct, msg->data + 2, msg->len - 2);
991 OSMO_ASSERT(rc_dec == 4);
992 OSMO_ASSERT(memcmp(&enc_ct, &dec_ct, sizeof(enc_ct)) == 0);
993
994 msgb_free(msg);
995}
996
Philipp Maier14e76b92017-03-28 18:36:52 +0200997static void test_gsm0808_enc_dec_encrypt_info()
998{
Neels Hofmeyr9a4286b2018-04-20 12:27:52 +0200999 struct gsm0808_encrypt_info enc_ei = {
1000 .perm_algo = { GSM0808_ALG_ID_A5_0, GSM0808_ALG_ID_A5_1 },
1001 .perm_algo_len = 2,
1002 .key = { 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x23, 0x42, },
1003 .key_len = 8,
1004 };
1005 struct gsm0808_encrypt_info dec_ei = {};
Philipp Maier14e76b92017-03-28 18:36:52 +02001006 struct msgb *msg;
1007 uint8_t ei_enc_expected[] =
1008 { GSM0808_IE_ENCRYPTION_INFORMATION, 0x09, 0x03, 0xaa, 0xbb,
1009 0xcc, 0xdd, 0xee, 0xff, 0x23, 0x42
1010 };
1011 uint8_t rc_enc;
1012 int rc_dec;
1013
Philipp Maier14e76b92017-03-28 18:36:52 +02001014 msg = msgb_alloc(1024, "output buffer");
1015 rc_enc = gsm0808_enc_encrypt_info(msg, &enc_ei);
1016 OSMO_ASSERT(rc_enc == 11);
1017 OSMO_ASSERT(memcmp(ei_enc_expected, msg->data, msg->len) == 0);
1018
1019 rc_dec = gsm0808_dec_encrypt_info(&dec_ei, msg->data + 2, msg->len - 2);
1020 OSMO_ASSERT(rc_dec == 9);
1021
1022 OSMO_ASSERT(memcmp(&enc_ei, &dec_ei, sizeof(enc_ei)) == 0);
1023
1024 msgb_free(msg);
1025}
1026
Philipp Maier783047e2017-03-29 11:35:50 +02001027static void test_gsm0808_enc_dec_cell_id_list_lac()
1028{
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001029 struct gsm0808_cell_id_list2 enc_cil;
1030 struct gsm0808_cell_id_list2 dec_cil;
Philipp Maier783047e2017-03-29 11:35:50 +02001031 struct msgb *msg;
1032 uint8_t rc_enc;
1033 int rc_dec;
1034
1035 memset(&enc_cil, 0, sizeof(enc_cil));
1036 enc_cil.id_discr = CELL_IDENT_LAC;
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001037 enc_cil.id_list[0].lac = 0x0124;
Neels Hofmeyrdb2fa4e2018-04-13 04:11:20 +02001038 enc_cil.id_list[1].lac = 0xABCD;
1039 enc_cil.id_list[2].lac = 0x5678;
Philipp Maier783047e2017-03-29 11:35:50 +02001040 enc_cil.id_list_len = 3;
1041
1042 msg = msgb_alloc(1024, "output buffer");
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001043 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
Neels Hofmeyrdb2fa4e2018-04-13 04:11:20 +02001044 EXPECT_ENCODED("1a 07 05 01 24 ab cd 56 78");
Philipp Maier783047e2017-03-29 11:35:50 +02001045
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001046 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
Philipp Maier783047e2017-03-29 11:35:50 +02001047 OSMO_ASSERT(rc_dec == 7);
1048
1049 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
1050
1051 msgb_free(msg);
1052}
1053
1054static void test_gsm0808_enc_dec_cell_id_list_single_lac()
1055{
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001056 struct gsm0808_cell_id_list2 enc_cil;
1057 struct gsm0808_cell_id_list2 dec_cil;
Philipp Maier783047e2017-03-29 11:35:50 +02001058 struct msgb *msg;
1059 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x03,
1060 0x05, 0x23, 0x42
1061 };
1062 uint8_t rc_enc;
1063 int rc_dec;
1064
1065 memset(&enc_cil, 0, sizeof(enc_cil));
1066 enc_cil.id_discr = CELL_IDENT_LAC;
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001067 enc_cil.id_list[0].lac = 0x2342;
Philipp Maier783047e2017-03-29 11:35:50 +02001068 enc_cil.id_list_len = 1;
1069
1070 msg = msgb_alloc(1024, "output buffer");
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001071 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
Philipp Maier783047e2017-03-29 11:35:50 +02001072 OSMO_ASSERT(rc_enc == 5);
1073 OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0);
1074
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001075 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
Philipp Maier783047e2017-03-29 11:35:50 +02001076 OSMO_ASSERT(rc_dec == 3);
1077
1078 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
1079
1080 msgb_free(msg);
1081}
1082
Stefan Sperlinge1a86742018-03-15 18:05:02 +01001083static void test_gsm0808_enc_dec_cell_id_list_multi_lac()
1084{
1085 struct gsm0808_cell_id_list2 enc_cil;
1086 struct gsm0808_cell_id_list2 dec_cil;
1087 struct msgb *msg;
1088 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x0b, 0x05,
1089 0x23, 0x42,
1090 0x24, 0x43,
1091 0x25, 0x44,
1092 0x26, 0x45,
1093 0x27, 0x46
1094 };
1095 uint8_t rc_enc;
1096 int rc_dec;
1097
1098 memset(&enc_cil, 0, sizeof(enc_cil));
1099 enc_cil.id_discr = CELL_IDENT_LAC;
1100 enc_cil.id_list[0].lac = 0x2342;
1101 enc_cil.id_list[1].lac = 0x2443;
1102 enc_cil.id_list[2].lac = 0x2544;
1103 enc_cil.id_list[3].lac = 0x2645;
1104 enc_cil.id_list[4].lac = 0x2746;
1105 enc_cil.id_list_len = 5;
1106
1107 msg = msgb_alloc(1024, "output buffer");
1108 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
1109 OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected));
1110 OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0);
1111
1112 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
1113 OSMO_ASSERT(rc_dec == msg->len - 2);
1114 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
1115
1116 msgb_free(msg);
1117}
1118
Philipp Maier783047e2017-03-29 11:35:50 +02001119static void test_gsm0808_enc_dec_cell_id_list_bss()
1120{
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001121 struct gsm0808_cell_id_list2 enc_cil;
1122 struct gsm0808_cell_id_list2 dec_cil;
Philipp Maier783047e2017-03-29 11:35:50 +02001123 struct msgb *msg;
1124 uint8_t rc_enc;
1125 int rc_dec;
1126
1127 memset(&enc_cil, 0, sizeof(enc_cil));
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001128 enc_cil.id_discr = CELL_IDENT_BSS;
Philipp Maier783047e2017-03-29 11:35:50 +02001129
1130 msg = msgb_alloc(1024, "output buffer");
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001131 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
Philipp Maier783047e2017-03-29 11:35:50 +02001132 OSMO_ASSERT(rc_enc == 3);
1133
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001134 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
Philipp Maier783047e2017-03-29 11:35:50 +02001135 OSMO_ASSERT(rc_dec == 1);
1136
1137 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
1138
1139 msgb_free(msg);
1140}
1141
Stefan Sperling23381452018-03-15 19:38:15 +01001142static void test_gsm0808_enc_dec_cell_id_list_multi_lai_and_lac()
1143{
1144 struct gsm0808_cell_id_list2 enc_cil;
1145 struct gsm0808_cell_id_list2 dec_cil;
1146 struct osmo_location_area_id id;
1147 struct msgb *msg;
1148 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x10, 0x04,
1149 0x92, 0x61, 0x54, 0x23, 0x42,
1150 0x92, 0x72, 0x54, 0x24, 0x43,
1151 0x92, 0x83, 0x54, 0x25, 0x44
1152 };
1153 uint8_t rc_enc;
1154 int rc_dec, i;
1155
1156 memset(&enc_cil, 0, sizeof(enc_cil));
1157 enc_cil.id_discr = CELL_IDENT_LAI_AND_LAC;
1158
1159 id.plmn.mcc = 0x123;
1160 osmo_mnc_from_str("456", &id.plmn.mnc, &id.plmn.mnc_3_digits);
1161 id.lac = 0x2342;
1162 memcpy(&enc_cil.id_list[0].lai_and_lac, &id, sizeof(id));
1163
1164 id.plmn.mcc = 0x124;
1165 osmo_mnc_from_str("457", &id.plmn.mnc, &id.plmn.mnc_3_digits);
1166 id.lac = 0x2443;
1167 memcpy(&enc_cil.id_list[1].lai_and_lac, &id, sizeof(id));
1168
1169 id.plmn.mcc = 0x125;
1170 osmo_mnc_from_str("458", &id.plmn.mnc, &id.plmn.mnc_3_digits);
1171 id.lac = 0x2544;
1172 memcpy(&enc_cil.id_list[2].lai_and_lac, &id, sizeof(id));
1173
1174 enc_cil.id_list_len = 3;
1175
1176 msg = msgb_alloc(1024, "output buffer");
1177 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
1178 OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected));
1179 OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0);
1180
1181 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
1182 OSMO_ASSERT(rc_dec == msg->len - 2);
1183
1184 OSMO_ASSERT(dec_cil.id_list_len == 3);
1185 /* Check MAXLEN elements to ensure everything has been initialized. */
1186 for (i = 0; i < GSM0808_CELL_ID_LIST2_MAXLEN; i++) {
1187 struct osmo_location_area_id *enc_id;
1188 struct osmo_location_area_id *dec_id;
1189 enc_id = &enc_cil.id_list[i].lai_and_lac;
1190 dec_id = &dec_cil.id_list[i].lai_and_lac;
1191 OSMO_ASSERT(osmo_plmn_cmp(&enc_id->plmn, &dec_id->plmn) == 0);
1192 OSMO_ASSERT(enc_id->lac == dec_id->lac);
1193 }
1194
1195 msgb_free(msg);
1196}
1197
Stefan Sperling9c62fc62018-03-16 10:23:34 +01001198static void test_gsm0808_enc_dec_cell_id_list_multi_ci()
1199{
1200 struct gsm0808_cell_id_list2 enc_cil;
1201 struct gsm0808_cell_id_list2 dec_cil;
1202 struct msgb *msg;
1203 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x09, 0x02,
1204 0x00, 0x01,
1205 0x00, 0x02,
1206 0x00, 0x77,
1207 0x01, 0xff,
1208 };
1209 uint8_t rc_enc;
1210 int rc_dec;
1211
1212 memset(&enc_cil, 0, sizeof(enc_cil));
1213 enc_cil.id_discr = CELL_IDENT_CI;
1214 enc_cil.id_list[0].ci = 1;
1215 enc_cil.id_list[1].ci = 2;
1216 enc_cil.id_list[2].ci = 119;
1217 enc_cil.id_list[3].ci = 511;
1218 enc_cil.id_list_len = 4;
1219
1220 msg = msgb_alloc(1024, "output buffer");
1221 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
1222 OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected));
1223 OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0);
1224
1225 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
1226 OSMO_ASSERT(rc_dec == msg->len - 2);
1227 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
1228
1229 msgb_free(msg);
1230}
1231
Stefan Sperlinged4327c2018-03-16 11:02:59 +01001232static void test_gsm0808_enc_dec_cell_id_list_multi_lac_and_ci()
1233{
1234 struct gsm0808_cell_id_list2 enc_cil;
1235 struct gsm0808_cell_id_list2 dec_cil;
1236 struct msgb *msg;
1237 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x15, 0x01,
1238 0x23, 0x42, 0x00, 0x01,
1239 0x24, 0x43, 0x00, 0x02,
1240 0x25, 0x44, 0x00, 0x77,
1241 0x26, 0x45, 0x01, 0xff,
1242 0x27, 0x46, 0x02, 0xfe,
1243 };
1244 uint8_t rc_enc;
1245 int rc_dec;
1246
1247 memset(&enc_cil, 0, sizeof(enc_cil));
1248 enc_cil.id_discr = CELL_IDENT_LAC_AND_CI;
1249 enc_cil.id_list[0].lac_and_ci.lac = 0x2342;
1250 enc_cil.id_list[0].lac_and_ci.ci = 1;
1251 enc_cil.id_list[1].lac_and_ci.lac = 0x2443;
1252 enc_cil.id_list[1].lac_and_ci.ci = 2;
1253 enc_cil.id_list[2].lac_and_ci.lac = 0x2544;
1254 enc_cil.id_list[2].lac_and_ci.ci = 119;
1255 enc_cil.id_list[3].lac_and_ci.lac = 0x2645;
1256 enc_cil.id_list[3].lac_and_ci.ci = 511;
1257 enc_cil.id_list[4].lac_and_ci.lac = 0x2746;
1258 enc_cil.id_list[4].lac_and_ci.ci = 766;
1259 enc_cil.id_list_len = 5;
1260
1261 msg = msgb_alloc(1024, "output buffer");
1262 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
1263 OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected));
1264 OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0);
1265
1266 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
1267 OSMO_ASSERT(rc_dec == msg->len - 2);
1268 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
1269
1270 msgb_free(msg);
1271}
1272
Stefan Sperling483f3862018-03-16 12:21:26 +01001273static void test_gsm0808_enc_dec_cell_id_list_multi_global()
1274{
1275 struct gsm0808_cell_id_list2 enc_cil;
1276 struct gsm0808_cell_id_list2 dec_cil;
1277 struct msgb *msg;
1278 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x16, 0x00,
Neels Hofmeyr473485c2018-03-23 02:04:18 +01001279 0x21, 0x63, 0x54, 0x23, 0x42, 0x00, 0x1,
Neels Hofmeyrc44fc232018-03-23 02:15:12 +01001280 0x21, 0xf4, 0x75, 0x24, 0x43, 0x00, 0x2,
Neels Hofmeyr8b8cd932018-03-23 01:47:37 +01001281 0x21, 0x75, 0x00, 0x25, 0x44, 0x00, 0x77
Stefan Sperling483f3862018-03-16 12:21:26 +01001282 };
Stefan Sperling483f3862018-03-16 12:21:26 +01001283 uint8_t rc_enc;
1284 int rc_dec, i;
1285
Neels Hofmeyrc1991df2018-03-23 02:00:00 +01001286 enc_cil = (struct gsm0808_cell_id_list2){
1287 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1288 .id_list_len = 3,
1289 .id_list = {
1290 {
1291 .global = {
Neels Hofmeyr473485c2018-03-23 02:04:18 +01001292 .lai = { .plmn = { .mcc = 123, .mnc = 456 },
Neels Hofmeyrc1991df2018-03-23 02:00:00 +01001293 .lac = 0x2342 },
1294 .cell_identity = 1,
1295 }
1296 },
1297 {
1298 .global = {
Neels Hofmeyrc44fc232018-03-23 02:15:12 +01001299 .lai = { .plmn = { .mcc = 124, .mnc = 57 },
Neels Hofmeyrc1991df2018-03-23 02:00:00 +01001300 .lac = 0x2443 },
1301 .cell_identity = 2,
1302 }
1303 },
1304 {
1305 .global = {
Neels Hofmeyrc44fc232018-03-23 02:15:12 +01001306 .lai = { .plmn = { .mcc = 125, .mnc = 7,
1307 .mnc_3_digits = true },
Neels Hofmeyrc1991df2018-03-23 02:00:00 +01001308 .lac = 0x2544 },
1309 .cell_identity = 119,
1310 }
1311 },
1312 }
1313 };
Stefan Sperling483f3862018-03-16 12:21:26 +01001314
1315 msg = msgb_alloc(1024, "output buffer");
1316 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
1317 OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected));
Neels Hofmeyrc1991df2018-03-23 02:00:00 +01001318 if (memcmp(cil_enc_expected, msg->data, msg->len)) {
1319 printf(" got: %s\n", osmo_hexdump(msg->data, msg->len));
1320 printf("expect: %s\n", osmo_hexdump(cil_enc_expected, sizeof(cil_enc_expected)));
1321 OSMO_ASSERT(false);
1322 }
Stefan Sperling483f3862018-03-16 12:21:26 +01001323
1324 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
1325 OSMO_ASSERT(rc_dec == msg->len - 2);
1326
1327 /* Check MAXLEN elements to ensure everything has been initialized. */
1328 for (i = 0; i < GSM0808_CELL_ID_LIST2_MAXLEN; i++) {
1329 struct osmo_cell_global_id *enc_id;
1330 struct osmo_cell_global_id *dec_id;
1331 enc_id = &enc_cil.id_list[i].global;
1332 dec_id = &dec_cil.id_list[i].global;
1333 OSMO_ASSERT(osmo_plmn_cmp(&enc_id->lai.plmn, &dec_id->lai.plmn) == 0);
1334 OSMO_ASSERT(enc_id->lai.lac == dec_id->lai.lac);
1335 OSMO_ASSERT(enc_id->cell_identity == dec_id->cell_identity);
1336 }
1337
1338 msgb_free(msg);
1339}
1340
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001341static void print_cil(const struct gsm0808_cell_id_list2 *cil)
1342{
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001343 printf(" cell_id_list == %s\n", gsm0808_cell_id_list_name(cil));
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001344}
1345
1346void test_cell_id_list_add() {
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001347 size_t zu;
1348
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001349 const struct gsm0808_cell_id_list2 cgi1 = {
1350 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1351 .id_list_len = 1,
1352 .id_list = {
1353 {
1354 .global = {
1355 .lai = {
1356 .plmn = { .mcc = 1, .mnc = 2, .mnc_3_digits = false },
1357 .lac = 3,
1358 },
1359 .cell_identity = 4,
1360 }
1361 },
1362 },
1363 };
1364
1365 const struct gsm0808_cell_id_list2 cgi2 = {
1366 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1367 .id_list_len = 2,
1368 .id_list = {
1369 {
1370 .global = {
1371 .lai = {
1372 .plmn = { .mcc = 1, .mnc = 2, .mnc_3_digits = true },
1373 .lac = 3,
1374 },
1375 .cell_identity = 4,
1376 }
1377 },
1378 {
1379 .global = {
1380 .lai = {
1381 .plmn = { .mcc = 5, .mnc = 6, .mnc_3_digits = true },
1382 .lac = 7,
1383 },
1384 .cell_identity = 8,
1385 }
1386 },
1387 },
1388 };
1389
1390 const struct gsm0808_cell_id_list2 cgi2a = {
1391 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1392 .id_list_len = 2,
1393 .id_list = {
1394 {
1395 .global = cgi2.id_list[0].global
1396 },
1397 {
1398 .global = {
1399 .lai = {
1400 .plmn = { .mcc = 9, .mnc = 10, .mnc_3_digits = true },
1401 .lac = 11,
1402 },
1403 .cell_identity = 12,
1404 }
1405 },
1406 },
1407 };
1408
1409 const struct gsm0808_cell_id_list2 cgi3 = {
1410 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1411 .id_list_len = 2,
1412 .id_list = {
1413 {
1414 .global = {
1415 .lai = {
1416 .plmn = { .mcc = 13, .mnc = 14, .mnc_3_digits = true },
1417 .lac = 15,
1418 },
1419 .cell_identity = 16,
1420 }
1421 },
1422 {
1423 .global = {
1424 .lai = {
1425 .plmn = { .mcc = 16, .mnc = 17, .mnc_3_digits = true },
1426 .lac = 18,
1427 },
1428 .cell_identity = 19,
1429 }
1430 },
1431 },
1432 };
1433
1434
1435 const struct gsm0808_cell_id_list2 lac1 = {
1436 .id_discr = CELL_IDENT_LAC,
1437 .id_list_len = 1,
1438 .id_list = {
1439 {
1440 .lac = 123
1441 },
1442 },
1443 };
1444
1445 const struct gsm0808_cell_id_list2 lac2 = {
1446 .id_discr = CELL_IDENT_LAC,
1447 .id_list_len = 2,
1448 .id_list = {
1449 {
1450 .lac = 456
1451 },
1452 {
1453 .lac = 789
1454 },
1455 },
1456 };
1457
1458 struct gsm0808_cell_id_list2 cil = {};
1459
1460 printf("------- %s\n", __func__);
1461
1462 print_cil(&cil);
1463
1464#define ADD_QUIET(other_cil, expect_rc) do { \
1465 int rc = gsm0808_cell_id_list_add(&cil, &other_cil); \
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001466 printf("gsm0808_cell_id_list_add(&cil, &" #other_cil ") --> rc = %d\n", rc); \
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001467 OSMO_ASSERT(rc == expect_rc); \
1468 } while(0)
1469
1470#define ADD(other_cil, expect_rc) ADD_QUIET(other_cil, expect_rc); print_cil(&cil)
1471
1472 ADD(lac1, 1);
1473 ADD(lac1, 0);
1474 ADD(lac2, 2);
1475 ADD(lac2, 0);
1476 ADD(cil, 0);
1477 ADD(cgi1, -EINVAL);
1478
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001479 printf("* can't add to BSS list\n");
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001480 cil.id_list_len = 0;
1481 cil.id_discr = CELL_IDENT_BSS;
1482 print_cil(&cil);
1483 ADD(lac1, -EINVAL);
1484
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001485 printf("* other types (including NO_CELL) take on new type iff empty\n");
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001486 cil.id_list_len = 0;
1487 cil.id_discr = CELL_IDENT_NO_CELL;
1488 print_cil(&cil);
1489 ADD(cgi1, 1);
1490 ADD(cgi1, 0);
1491 ADD(cgi2, 2);
1492 ADD(cgi2, 0);
1493
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001494 printf("* test gsm0808_cell_id_list_name_buf()'s return val\n");
1495 zu = strlen(gsm0808_cell_id_list_name(&cil));
1496 printf(" strlen(gsm0808_cell_id_list_name(cil)) == %zu\n", zu);
1497 zu ++;
1498 while (1) {
1499 char buf[128] = "?";
1500 int rc;
1501 OSMO_ASSERT(zu < sizeof(buf));
1502 buf[zu] = '#';
1503 rc = gsm0808_cell_id_list_name_buf(buf, zu, &cil);
1504 printf(" gsm0808_cell_id_list_name_buf(buf, %zu, cil)) == %d \"%s\"\n",
1505 zu, rc, buf);
1506 OSMO_ASSERT(buf[zu] == '#');
1507 if (!zu)
1508 break;
1509 zu /= 2;
1510 }
1511
1512 printf("* list-full behavior\n");
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001513 cil.id_list_len = GSM0808_CELL_ID_LIST2_MAXLEN - 1;
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001514 printf("cil.id_list_len = %u\n", cil.id_list_len);
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001515 ADD_QUIET(cgi2a, 1);
1516 printf("cil.id_list_len = %u\n", cil.id_list_len);
1517
1518 cil.id_list_len = GSM0808_CELL_ID_LIST2_MAXLEN - 1;
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001519 printf("cil.id_list_len = %u\n", cil.id_list_len);
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001520 ADD_QUIET(cgi3, -ENOSPC);
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001521 printf("cil.id_list_len = %u\n", cil.id_list_len);
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001522 ADD_QUIET(cgi2a, -ENOSPC);
1523 printf("cil.id_list_len = %u\n", cil.id_list_len);
1524
1525 printf("------- %s done\n", __func__);
1526}
1527
Neels Hofmeyr250e7f72018-04-13 03:30:14 +02001528static void test_gsm0808_enc_dec_cell_id_lac()
1529{
1530 struct gsm0808_cell_id enc_ci = {
1531 .id_discr = CELL_IDENT_LAC,
1532 .id.lac = 0x0124,
1533 };
1534 struct gsm0808_cell_id dec_ci;
1535 struct msgb *msg;
1536 uint8_t rc_enc;
1537 int rc_dec;
1538
1539 memset(&dec_ci, 0xa5, sizeof(dec_ci));
1540
1541 msg = msgb_alloc(1024, "output buffer");
1542 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1543 EXPECT_ENCODED("05 03 05 01 24");
1544
1545 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1546 OSMO_ASSERT(rc_dec == 3);
1547
1548 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr
1549 && enc_ci.id.lac == dec_ci.id.lac);
1550
1551 msgb_free(msg);
1552}
1553
1554static void test_gsm0808_enc_dec_cell_id_bss()
1555{
1556 struct gsm0808_cell_id enc_ci = {
1557 .id_discr = CELL_IDENT_BSS,
1558 };
1559 struct gsm0808_cell_id dec_ci;
1560 struct msgb *msg;
1561 uint8_t rc_enc;
1562 int rc_dec;
1563
1564 msg = msgb_alloc(1024, "output buffer");
1565 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1566 EXPECT_ENCODED("05 01 06");
1567
1568 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1569 OSMO_ASSERT(rc_dec == 1);
1570
1571 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr);
1572
1573 msgb_free(msg);
1574}
1575
1576static void test_gsm0808_enc_dec_cell_id_no_cell()
1577{
1578 struct gsm0808_cell_id enc_ci = {
1579 .id_discr = CELL_IDENT_NO_CELL,
1580 };
1581 struct gsm0808_cell_id dec_ci;
1582 struct msgb *msg;
1583 uint8_t rc_enc;
1584 int rc_dec;
1585
1586 msg = msgb_alloc(1024, "output buffer");
1587 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1588 EXPECT_ENCODED("05 01 03");
1589
1590 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1591 OSMO_ASSERT(rc_dec == 1);
1592
1593 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr);
1594
1595 msgb_free(msg);
1596}
1597
1598static void test_gsm0808_enc_dec_cell_id_lai_and_lac()
1599{
1600 struct gsm0808_cell_id enc_ci = {
1601 .id_discr = CELL_IDENT_LAI_AND_LAC,
1602 .id.lai_and_lac = {
1603 .plmn = {
1604 .mcc = 123,
1605 .mnc = 456,
1606 },
1607 .lac = 0x2342,
1608 },
1609 };
1610 struct gsm0808_cell_id dec_ci;
1611 struct msgb *msg;
1612 uint8_t rc_enc;
1613 int rc_dec;
1614
1615 msg = msgb_alloc(1024, "output buffer");
1616 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1617 EXPECT_ENCODED("05 06 04 21 63 54 23 42");
1618
1619 memset(&dec_ci, 0xa5, sizeof(dec_ci));
1620 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1621 OSMO_ASSERT(rc_dec == msg->len - 2);
1622
1623 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr
1624 && osmo_plmn_cmp(&enc_ci.id.lai_and_lac.plmn, &dec_ci.id.lai_and_lac.plmn) == 0
1625 && enc_ci.id.lai_and_lac.lac == dec_ci.id.lai_and_lac.lac);
1626 msgb_free(msg);
1627}
1628
1629static void test_gsm0808_enc_dec_cell_id_ci()
1630{
1631 struct gsm0808_cell_id enc_ci = {
1632 .id_discr = CELL_IDENT_CI,
1633 .id.ci = 0x423,
1634 };
1635 struct gsm0808_cell_id dec_ci;
1636 struct msgb *msg;
1637 uint8_t rc_enc;
1638 int rc_dec;
1639
1640 msg = msgb_alloc(1024, "output buffer");
1641 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1642 EXPECT_ENCODED("05 03 02 04 23");
1643
1644 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1645 OSMO_ASSERT(rc_dec == msg->len - 2);
1646 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr
1647 && enc_ci.id.ci == dec_ci.id.ci);
1648
1649 msgb_free(msg);
1650}
1651
1652static void test_gsm0808_enc_dec_cell_id_lac_and_ci()
1653{
1654 struct gsm0808_cell_id enc_ci = {
1655 .id_discr = CELL_IDENT_LAC_AND_CI,
1656 .id.lac_and_ci = {
1657 .lac = 0x423,
1658 .ci = 0x235,
1659 },
1660 };
1661 struct gsm0808_cell_id dec_ci;
1662 struct msgb *msg;
1663 uint8_t rc_enc;
1664 int rc_dec;
1665
1666 msg = msgb_alloc(1024, "output buffer");
1667 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1668 EXPECT_ENCODED("05 05 01 04 23 02 35");
1669
1670 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1671 OSMO_ASSERT(rc_dec == msg->len - 2);
1672 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr
1673 && enc_ci.id.lac_and_ci.lac == dec_ci.id.lac_and_ci.lac
1674 && enc_ci.id.lac_and_ci.ci == dec_ci.id.lac_and_ci.ci);
1675
1676 msgb_free(msg);
1677}
1678
1679static void test_gsm0808_enc_dec_cell_id_global()
1680{
1681 struct gsm0808_cell_id enc_ci = {
1682 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1683 .id.global = {
1684 .lai = {
1685 .plmn = { .mcc = 123, .mnc = 456 },
1686 .lac = 0x2342
1687 },
1688 .cell_identity = 0x423,
1689 }
1690 };
1691 struct gsm0808_cell_id dec_ci;
1692 struct msgb *msg;
1693 uint8_t rc_enc;
1694 int rc_dec;
1695
1696 msg = msgb_alloc(1024, "output buffer");
1697 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1698 EXPECT_ENCODED("05 08 00 21 63 54 23 42 04 23");
1699
1700 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1701 OSMO_ASSERT(rc_dec == msg->len - 2);
1702
1703 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr
1704 && osmo_plmn_cmp(&enc_ci.id.global.lai.plmn,
1705 &dec_ci.id.global.lai.plmn) == 0
1706 && enc_ci.id.global.lai.lac == dec_ci.id.global.lai.lac
1707 && enc_ci.id.global.cell_identity == dec_ci.id.global.cell_identity);
1708 msgb_free(msg);
1709}
1710
Philipp Maier5f2eb152018-09-19 13:40:21 +02001711static void test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(struct gsm48_multi_rate_conf *cfg)
1712{
1713 uint16_t s15_s0;
1714
1715 printf("Input:\n");
1716 printf(" m4_75= %u smod= %u\n", cfg->m4_75, cfg->smod);
1717 printf(" m5_15= %u spare= %u\n", cfg->m5_15, cfg->spare);
1718 printf(" m5_90= %u icmi= %u\n", cfg->m5_90, cfg->icmi);
1719 printf(" m6_70= %u nscb= %u\n", cfg->m6_70, cfg->nscb);
1720 printf(" m7_40= %u ver= %u\n", cfg->m7_40, cfg->ver);
1721 printf(" m7_95= %u\n", cfg->m7_95);
1722 printf(" m10_2= %u\n", cfg->m10_2);
1723 printf(" m12_2= %u\n", cfg->m12_2);
1724
1725 s15_s0 = gsm0808_sc_cfg_from_gsm48_mr_cfg(cfg, true);
1726 printf("Result (fr):\n");
1727 printf(" S15-S0 = %04x = 0b" OSMO_BIN_SPEC OSMO_BIN_SPEC "\n", s15_s0,
1728 OSMO_BIN_PRINT(s15_s0 >> 8), OSMO_BIN_PRINT(s15_s0));
1729
1730 s15_s0 = gsm0808_sc_cfg_from_gsm48_mr_cfg(cfg, false);
1731 printf("Result (hr):\n");
1732 printf(" S15-S0 = %04x = 0b" OSMO_BIN_SPEC OSMO_BIN_SPEC "\n", s15_s0,
1733 OSMO_BIN_PRINT(s15_s0 >> 8), OSMO_BIN_PRINT(s15_s0));
1734
1735 printf("\n");
1736}
1737
1738static void test_gsm0808_sc_cfg_from_gsm48_mr_cfg(void)
1739{
1740 struct gsm48_multi_rate_conf cfg;
1741
1742 printf("Testing gsm0808_sc_cfg_from_gsm48_mr_cfg():\n");
1743
1744 memset(&cfg, 0, sizeof(cfg));
1745
1746 cfg.m4_75 = 0;
1747 cfg.m5_15 = 0;
1748 cfg.m5_90 = 0;
1749 cfg.m6_70 = 0;
1750 cfg.m7_40 = 0;
1751 cfg.m7_95 = 0;
1752 cfg.m10_2 = 0;
1753 cfg.m12_2 = 0;
1754 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1755
1756 cfg.m4_75 = 1;
1757 cfg.m5_15 = 0;
1758 cfg.m5_90 = 0;
1759 cfg.m6_70 = 0;
1760 cfg.m7_40 = 0;
1761 cfg.m7_95 = 0;
1762 cfg.m10_2 = 0;
1763 cfg.m12_2 = 0;
1764 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1765
1766 cfg.m4_75 = 0;
1767 cfg.m5_15 = 1;
1768 cfg.m5_90 = 0;
1769 cfg.m6_70 = 0;
1770 cfg.m7_40 = 0;
1771 cfg.m7_95 = 0;
1772 cfg.m10_2 = 0;
1773 cfg.m12_2 = 0;
1774 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1775
1776 cfg.m4_75 = 0;
1777 cfg.m5_15 = 0;
1778 cfg.m5_90 = 1;
1779 cfg.m6_70 = 0;
1780 cfg.m7_40 = 0;
1781 cfg.m7_95 = 0;
1782 cfg.m10_2 = 0;
1783 cfg.m12_2 = 0;
1784 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1785
1786 cfg.m4_75 = 0;
1787 cfg.m5_15 = 0;
1788 cfg.m5_90 = 0;
1789 cfg.m6_70 = 1;
1790 cfg.m7_40 = 0;
1791 cfg.m7_95 = 0;
1792 cfg.m10_2 = 0;
1793 cfg.m12_2 = 0;
1794 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1795
1796 cfg.m4_75 = 0;
1797 cfg.m5_15 = 0;
1798 cfg.m5_90 = 0;
1799 cfg.m6_70 = 0;
1800 cfg.m7_40 = 1;
1801 cfg.m7_95 = 0;
1802 cfg.m10_2 = 0;
1803 cfg.m12_2 = 0;
1804 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1805
1806 cfg.m4_75 = 0;
1807 cfg.m5_15 = 0;
1808 cfg.m5_90 = 0;
1809 cfg.m6_70 = 0;
1810 cfg.m7_40 = 0;
1811 cfg.m7_95 = 1;
1812 cfg.m10_2 = 0;
1813 cfg.m12_2 = 0;
1814 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1815
1816 cfg.m4_75 = 0;
1817 cfg.m5_15 = 0;
1818 cfg.m5_90 = 0;
1819 cfg.m6_70 = 0;
1820 cfg.m7_40 = 0;
1821 cfg.m7_95 = 0;
1822 cfg.m10_2 = 1;
1823 cfg.m12_2 = 0;
1824 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1825
1826 cfg.m4_75 = 0;
1827 cfg.m5_15 = 0;
1828 cfg.m5_90 = 0;
1829 cfg.m6_70 = 0;
1830 cfg.m7_40 = 0;
1831 cfg.m7_95 = 0;
1832 cfg.m10_2 = 0;
1833 cfg.m12_2 = 1;
1834 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1835
1836 cfg.m4_75 = 1;
1837 cfg.m5_15 = 1;
1838 cfg.m5_90 = 1;
1839 cfg.m6_70 = 1;
1840 cfg.m7_40 = 0;
1841 cfg.m7_95 = 0;
1842 cfg.m10_2 = 0;
1843 cfg.m12_2 = 0;
1844 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1845
1846 cfg.m4_75 = 0;
1847 cfg.m5_15 = 0;
1848 cfg.m5_90 = 0;
1849 cfg.m6_70 = 0;
1850 cfg.m7_40 = 1;
1851 cfg.m7_95 = 1;
1852 cfg.m10_2 = 1;
1853 cfg.m12_2 = 1;
1854 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1855
1856 cfg.m4_75 = 0;
1857 cfg.m5_15 = 0;
1858 cfg.m5_90 = 1;
1859 cfg.m6_70 = 1;
1860 cfg.m7_40 = 0;
1861 cfg.m7_95 = 0;
1862 cfg.m10_2 = 1;
1863 cfg.m12_2 = 1;
1864 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1865
1866 cfg.m4_75 = 1;
1867 cfg.m5_15 = 1;
1868 cfg.m5_90 = 0;
1869 cfg.m6_70 = 0;
1870 cfg.m7_40 = 1;
1871 cfg.m7_95 = 1;
1872 cfg.m10_2 = 0;
1873 cfg.m12_2 = 0;
1874 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1875
1876 cfg.m4_75 = 0;
1877 cfg.m5_15 = 1;
1878 cfg.m5_90 = 0;
1879 cfg.m6_70 = 1;
1880 cfg.m7_40 = 0;
1881 cfg.m7_95 = 1;
1882 cfg.m10_2 = 0;
1883 cfg.m12_2 = 1;
1884 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1885
1886 cfg.m4_75 = 1;
1887 cfg.m5_15 = 0;
1888 cfg.m5_90 = 1;
1889 cfg.m6_70 = 0;
1890 cfg.m7_40 = 1;
1891 cfg.m7_95 = 0;
1892 cfg.m10_2 = 1;
1893 cfg.m12_2 = 0;
1894 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1895
1896 cfg.m4_75 = 1;
1897 cfg.m5_15 = 1;
1898 cfg.m5_90 = 1;
1899 cfg.m6_70 = 1;
1900 cfg.m7_40 = 1;
1901 cfg.m7_95 = 1;
1902 cfg.m10_2 = 1;
1903 cfg.m12_2 = 1;
1904 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1905}
1906
Philipp Maier8515d032018-09-25 15:57:49 +02001907static void test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single(uint16_t s15_s0)
1908{
1909 struct gsm48_multi_rate_conf cfg;
1910
1911 printf("Input:\n");
1912 printf(" S15-S0 = %04x = 0b" OSMO_BIN_SPEC OSMO_BIN_SPEC "\n", s15_s0,
1913 OSMO_BIN_PRINT(s15_s0 >> 8), OSMO_BIN_PRINT(s15_s0));
1914
1915 gsm48_mr_cfg_from_gsm0808_sc_cfg(&cfg, s15_s0);
1916
1917 printf("Output:\n");
1918 printf(" m4_75= %u smod= %u\n", cfg.m4_75, cfg.smod);
1919 printf(" m5_15= %u spare= %u\n", cfg.m5_15, cfg.spare);
1920 printf(" m5_90= %u icmi= %u\n", cfg.m5_90, cfg.icmi);
1921 printf(" m6_70= %u nscb= %u\n", cfg.m6_70, cfg.nscb);
1922 printf(" m7_40= %u ver= %u\n", cfg.m7_40, cfg.ver);
1923 printf(" m7_95= %u\n", cfg.m7_95);
1924 printf(" m10_2= %u\n", cfg.m10_2);
1925 printf(" m12_2= %u\n", cfg.m12_2);
1926
1927 printf("\n");
1928}
1929
1930void test_gsm48_mr_cfg_from_gsm0808_sc_cfg()
1931{
1932 printf("Testing gsm48_mr_cfg_from_gsm0808_sc_cfg():\n");
1933
1934 /* Only one codec per setting */
1935 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1936 (GSM0808_SC_CFG_DEFAULT_AMR_4_75);
1937 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1938 (GSM0808_SC_CFG_DEFAULT_AMR_5_15);
1939 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1940 (GSM0808_SC_CFG_DEFAULT_AMR_5_90);
1941 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1942 (GSM0808_SC_CFG_DEFAULT_AMR_6_70);
1943 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1944 (GSM0808_SC_CFG_DEFAULT_AMR_7_40);
1945 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1946 (GSM0808_SC_CFG_DEFAULT_AMR_7_95);
1947 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1948 (GSM0808_SC_CFG_DEFAULT_AMR_10_2);
1949 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1950 (GSM0808_SC_CFG_DEFAULT_AMR_12_2);
1951
1952 /* Combinations */
1953 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1954 (GSM0808_SC_CFG_DEFAULT_AMR_4_75 | GSM0808_SC_CFG_DEFAULT_AMR_6_70 |
1955 GSM0808_SC_CFG_DEFAULT_AMR_10_2);
1956 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1957 (GSM0808_SC_CFG_DEFAULT_AMR_10_2 | GSM0808_SC_CFG_DEFAULT_AMR_12_2 |
1958 GSM0808_SC_CFG_DEFAULT_AMR_7_40);
1959 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1960 (GSM0808_SC_CFG_DEFAULT_AMR_7_95 | GSM0808_SC_CFG_DEFAULT_AMR_12_2);
1961}
1962
Neels Hofmeyrd01ef752018-09-21 15:57:26 +02001963struct test_cell_id_matching_data {
1964 struct gsm0808_cell_id id;
1965 struct gsm0808_cell_id match_id;
1966 bool expect_match;
1967 bool expect_exact_match;
1968};
1969
1970#define lac_23 { .id_discr = CELL_IDENT_LAC, .id.lac = 23, }
1971#define lac_42 { .id_discr = CELL_IDENT_LAC, .id.lac = 42, }
1972#define ci_5 { .id_discr = CELL_IDENT_CI, .id.ci = 5, }
1973#define ci_6 { .id_discr = CELL_IDENT_CI, .id.ci = 6, }
1974#define lac_ci_23_5 { \
1975 .id_discr = CELL_IDENT_LAC_AND_CI, \
1976 .id.lac_and_ci = { .lac = 23, .ci = 5, }, \
1977 }
1978#define lac_ci_42_6 { \
1979 .id_discr = CELL_IDENT_LAC_AND_CI, \
1980 .id.lac_and_ci = { .lac = 42, .ci = 6, }, \
1981 }
1982#define lai_23_042_23 { \
1983 .id_discr = CELL_IDENT_LAI_AND_LAC, \
1984 .id.lai_and_lac = { .plmn = { .mcc = 23, .mnc = 42, .mnc_3_digits = true }, .lac = 23, }, \
1985 }
1986#define lai_23_042_42 { \
1987 .id_discr = CELL_IDENT_LAI_AND_LAC, \
1988 .id.lai_and_lac = { .plmn = { .mcc = 23, .mnc = 42, .mnc_3_digits = true }, .lac = 42, }, \
1989 }
1990#define lai_23_99_23 { \
1991 .id_discr = CELL_IDENT_LAI_AND_LAC, \
1992 .id.lai_and_lac = { .plmn = { .mcc = 23, .mnc = 99, .mnc_3_digits = false }, .lac = 23, }, \
1993 }
1994#define lai_23_42_23 { \
1995 .id_discr = CELL_IDENT_LAI_AND_LAC, \
1996 .id.lai_and_lac = { .plmn = { .mcc = 23, .mnc = 42, .mnc_3_digits = false }, .lac = 23, }, \
1997 }
1998#define cgi_23_042_23_5 { \
1999 .id_discr = CELL_IDENT_WHOLE_GLOBAL, \
2000 .id.global = { \
2001 .lai = { .plmn = { .mcc = 23, .mnc = 42, .mnc_3_digits = true }, .lac = 23, }, \
2002 .cell_identity = 5, \
2003 }, \
2004 }
2005#define cgi_23_042_42_6 { \
2006 .id_discr = CELL_IDENT_WHOLE_GLOBAL, \
2007 .id.global = { \
2008 .lai = { .plmn = { .mcc = 23, .mnc = 42, .mnc_3_digits = true }, .lac = 42, }, \
2009 .cell_identity = 6, \
2010 }, \
2011 }
2012#define cgi_23_99_23_5 { \
2013 .id_discr = CELL_IDENT_WHOLE_GLOBAL, \
2014 .id.global = { \
2015 .lai = { .plmn = { .mcc = 23, .mnc = 99, .mnc_3_digits = false }, .lac = 23, }, \
2016 .cell_identity = 5, \
2017 }, \
2018 }
2019
2020
2021static const struct test_cell_id_matching_data test_cell_id_matching_tests[] = {
2022 { .id = lac_23, .match_id = lac_23, .expect_match = true, .expect_exact_match = true },
2023 { .id = lac_23, .match_id = lac_42, .expect_match = false, .expect_exact_match = false },
2024 { .id = lac_23, .match_id = ci_5, .expect_match = true, .expect_exact_match = false },
2025 { .id = lac_23, .match_id = ci_6, .expect_match = true, .expect_exact_match = false },
2026 { .id = lac_23, .match_id = lac_ci_23_5, .expect_match = true, .expect_exact_match = false },
2027 { .id = lac_23, .match_id = lac_ci_42_6, .expect_match = false, .expect_exact_match = false },
2028 { .id = lac_23, .match_id = lai_23_042_23, .expect_match = true, .expect_exact_match = false },
2029 { .id = lac_23, .match_id = lai_23_042_42, .expect_match = false, .expect_exact_match = false },
2030 { .id = lac_23, .match_id = lai_23_99_23, .expect_match = true, .expect_exact_match = false },
2031 { .id = lac_23, .match_id = lai_23_42_23, .expect_match = true, .expect_exact_match = false },
2032 { .id = lac_23, .match_id = cgi_23_042_23_5, .expect_match = true, .expect_exact_match = false },
2033 { .id = lac_23, .match_id = cgi_23_042_42_6, .expect_match = false, .expect_exact_match = false },
2034 { .id = lac_23, .match_id = cgi_23_99_23_5, .expect_match = true, .expect_exact_match = false },
2035 { .id = ci_5, .match_id = lac_23, .expect_match = true, .expect_exact_match = false },
2036 { .id = ci_5, .match_id = lac_42, .expect_match = true, .expect_exact_match = false },
2037 { .id = ci_5, .match_id = ci_5, .expect_match = true, .expect_exact_match = true },
2038 { .id = ci_5, .match_id = ci_6, .expect_match = false, .expect_exact_match = false },
2039 { .id = ci_5, .match_id = lac_ci_23_5, .expect_match = true, .expect_exact_match = false },
2040 { .id = ci_5, .match_id = lac_ci_42_6, .expect_match = false, .expect_exact_match = false },
2041 { .id = ci_5, .match_id = lai_23_042_23, .expect_match = true, .expect_exact_match = false },
2042 { .id = ci_5, .match_id = lai_23_042_42, .expect_match = true, .expect_exact_match = false },
2043 { .id = ci_5, .match_id = lai_23_99_23, .expect_match = true, .expect_exact_match = false },
2044 { .id = ci_5, .match_id = lai_23_42_23, .expect_match = true, .expect_exact_match = false },
2045 { .id = ci_5, .match_id = cgi_23_042_23_5, .expect_match = true, .expect_exact_match = false },
2046 { .id = ci_5, .match_id = cgi_23_042_42_6, .expect_match = false, .expect_exact_match = false },
2047 { .id = ci_5, .match_id = cgi_23_99_23_5, .expect_match = true, .expect_exact_match = false },
2048 { .id = lac_ci_23_5, .match_id = lac_23, .expect_match = true, .expect_exact_match = false },
2049 { .id = lac_ci_23_5, .match_id = lac_42, .expect_match = false, .expect_exact_match = false },
2050 { .id = lac_ci_23_5, .match_id = ci_5, .expect_match = true, .expect_exact_match = false },
2051 { .id = lac_ci_23_5, .match_id = ci_6, .expect_match = false, .expect_exact_match = false },
2052 { .id = lac_ci_23_5, .match_id = lac_ci_23_5, .expect_match = true, .expect_exact_match = true },
2053 { .id = lac_ci_23_5, .match_id = lac_ci_42_6, .expect_match = false, .expect_exact_match = false },
2054 { .id = lac_ci_23_5, .match_id = lai_23_042_23, .expect_match = true, .expect_exact_match = false },
2055 { .id = lac_ci_23_5, .match_id = lai_23_042_42, .expect_match = false, .expect_exact_match = false },
2056 { .id = lac_ci_23_5, .match_id = lai_23_99_23, .expect_match = true, .expect_exact_match = false },
2057 { .id = lac_ci_23_5, .match_id = lai_23_42_23, .expect_match = true, .expect_exact_match = false },
2058 { .id = lac_ci_23_5, .match_id = cgi_23_042_23_5, .expect_match = true, .expect_exact_match = false },
2059 { .id = lac_ci_23_5, .match_id = cgi_23_042_42_6, .expect_match = false, .expect_exact_match = false },
2060 { .id = lac_ci_23_5, .match_id = cgi_23_99_23_5, .expect_match = true, .expect_exact_match = false },
2061 { .id = lai_23_042_23, .match_id = lac_23, .expect_match = true, .expect_exact_match = false },
2062 { .id = lai_23_042_23, .match_id = lac_42, .expect_match = false, .expect_exact_match = false },
2063 { .id = lai_23_042_23, .match_id = ci_5, .expect_match = true, .expect_exact_match = false },
2064 { .id = lai_23_042_23, .match_id = ci_6, .expect_match = true, .expect_exact_match = false },
2065 { .id = lai_23_042_23, .match_id = lac_ci_23_5, .expect_match = true, .expect_exact_match = false },
2066 { .id = lai_23_042_23, .match_id = lac_ci_42_6, .expect_match = false, .expect_exact_match = false },
2067 { .id = lai_23_042_23, .match_id = lai_23_042_23, .expect_match = true, .expect_exact_match = true },
2068 { .id = lai_23_042_23, .match_id = lai_23_042_42, .expect_match = false, .expect_exact_match = false },
2069 { .id = lai_23_042_23, .match_id = lai_23_99_23, .expect_match = false, .expect_exact_match = false },
2070 { .id = lai_23_042_23, .match_id = lai_23_42_23, .expect_match = false, .expect_exact_match = false },
2071 { .id = lai_23_042_23, .match_id = cgi_23_042_23_5, .expect_match = true, .expect_exact_match = false },
2072 { .id = lai_23_042_23, .match_id = cgi_23_042_42_6, .expect_match = false, .expect_exact_match = false },
2073 { .id = lai_23_042_23, .match_id = cgi_23_99_23_5, .expect_match = false, .expect_exact_match = false },
2074 { .id = cgi_23_042_23_5, .match_id = lac_23, .expect_match = true, .expect_exact_match = false },
2075 { .id = cgi_23_042_23_5, .match_id = lac_42, .expect_match = false, .expect_exact_match = false },
2076 { .id = cgi_23_042_23_5, .match_id = ci_5, .expect_match = true, .expect_exact_match = false },
2077 { .id = cgi_23_042_23_5, .match_id = ci_6, .expect_match = false, .expect_exact_match = false },
2078 { .id = cgi_23_042_23_5, .match_id = lac_ci_23_5, .expect_match = true, .expect_exact_match = false },
2079 { .id = cgi_23_042_23_5, .match_id = lac_ci_42_6, .expect_match = false, .expect_exact_match = false },
2080 { .id = cgi_23_042_23_5, .match_id = lai_23_042_23, .expect_match = true, .expect_exact_match = false },
2081 { .id = cgi_23_042_23_5, .match_id = lai_23_042_42, .expect_match = false, .expect_exact_match = false },
2082 { .id = cgi_23_042_23_5, .match_id = lai_23_99_23, .expect_match = false, .expect_exact_match = false },
2083 { .id = cgi_23_042_23_5, .match_id = lai_23_42_23, .expect_match = false, .expect_exact_match = false },
2084 { .id = cgi_23_042_23_5, .match_id = cgi_23_042_23_5, .expect_match = true, .expect_exact_match = true },
2085 { .id = cgi_23_042_23_5, .match_id = cgi_23_042_42_6, .expect_match = false, .expect_exact_match = false },
2086 { .id = cgi_23_042_23_5, .match_id = cgi_23_99_23_5, .expect_match = false, .expect_exact_match = false },
2087};
2088
2089static void test_cell_id_matching()
2090{
2091 int i;
2092 bool ok = true;
2093 printf("\n%s\n", __func__);
2094
2095 for (i = 0; i < ARRAY_SIZE(test_cell_id_matching_tests); i++) {
2096 const struct test_cell_id_matching_data *d = &test_cell_id_matching_tests[i];
2097 int exact_match;
2098
2099 for (exact_match = 0; exact_match < 2; exact_match++) {
2100 bool result;
2101 bool expect_result = exact_match ? d->expect_exact_match : d->expect_match;
2102
2103 result = gsm0808_cell_ids_match(&d->id, &d->match_id, (bool)exact_match);
2104
2105 printf("[%d] %s %s %s%s\n",
2106 i,
2107 gsm0808_cell_id_name(&d->id),
2108 gsm0808_cell_id_name2(&d->match_id),
2109 result ? "MATCH" : "don't match",
2110 exact_match ? " exactly" : "");
2111 if (result != expect_result) {
2112 printf(" ERROR: expected %s\n", d->expect_match ? "MATCH" : "no match");
2113 ok = false;
2114 }
2115 }
2116 }
2117
2118 OSMO_ASSERT(ok);
2119}
2120
2121static bool test_cell_id_list_matching_discrs(bool test_match,
2122 enum CELL_IDENT id_discr,
2123 enum CELL_IDENT list_discr)
2124{
2125 int i, j;
2126 const struct gsm0808_cell_id *id = NULL;
2127 struct gsm0808_cell_id_list2 list = {};
2128 int match_idx = -1;
2129 int result;
2130
2131 for (i = 0; i < ARRAY_SIZE(test_cell_id_matching_tests); i++) {
2132 const struct test_cell_id_matching_data *d = &test_cell_id_matching_tests[i];
2133 if (id_discr != d->id.id_discr)
2134 continue;
2135 id = &d->id;
2136 break;
2137 }
2138
2139 if (!id) {
2140 printf("Did not find any entry for %s\n", gsm0808_cell_id_discr_name(id_discr));
2141 return true;
2142 }
2143
2144 /* Collect those entries with exactly this id on the left, of type list_discr on the right.
2145 * Collect the mismatches first, for more interesting match indexes in the results. */
2146 for (j = 0; j < 2; j++) {
2147 bool collect_matches = (bool)j;
2148
2149 /* If we want to have a mismatching list, don't add any entries that match. */
2150 if (!test_match && collect_matches)
2151 continue;
2152
2153 for (i = 0; i < ARRAY_SIZE(test_cell_id_matching_tests); i++) {
2154 const struct test_cell_id_matching_data *d = &test_cell_id_matching_tests[i];
2155 struct gsm0808_cell_id_list2 add;
2156
2157 /* Ignore those with a different d->id */
2158 if (!gsm0808_cell_ids_match(&d->id, id, true))
2159 continue;
2160
2161 /* Ignore those with a different d->match_id discr */
2162 if (d->match_id.id_discr != list_discr)
2163 continue;
2164
2165 if (collect_matches != d->expect_match)
2166 continue;
2167
2168 if (match_idx < 0 && d->expect_match) {
2169 match_idx = list.id_list_len;
2170 }
2171
2172 gsm0808_cell_id_to_list(&add, &d->match_id);
2173 gsm0808_cell_id_list_add(&list, &add);
2174 }
2175 }
2176
2177 if (!list.id_list_len) {
2178 printf("%s vs. %s: No match_id entries to test %s\n",
2179 gsm0808_cell_id_name(id),
2180 gsm0808_cell_id_discr_name(list_discr),
2181 test_match ? "MATCH" : "mismatch");
2182 return true;
2183 }
2184
2185 result = gsm0808_cell_id_matches_list(id, &list, 0, false);
2186
2187 printf("%s and %s: ",
2188 gsm0808_cell_id_name(id),
2189 gsm0808_cell_id_list_name(&list));
2190 if (result >= 0)
2191 printf("MATCH at [%d]\n", result);
2192 else
2193 printf("mismatch\n");
2194
2195 if (test_match
2196 && (result < 0 || result != match_idx)) {
2197 printf(" ERROR: expected MATCH at %d\n", match_idx);
2198 return false;
2199 }
2200
2201 if (!test_match && result >= 0) {
2202 printf(" ERROR: expected mismatch\n");
2203 return false;
2204 }
2205
2206 return true;
2207}
2208
2209static void test_cell_id_list_matching(bool test_match)
2210{
2211 int i, j;
2212 bool ok = true;
2213
2214 const enum CELL_IDENT discrs[] = {
2215 CELL_IDENT_LAC, CELL_IDENT_CI, CELL_IDENT_LAC_AND_CI, CELL_IDENT_LAI_AND_LAC,
2216 CELL_IDENT_WHOLE_GLOBAL,
2217 };
2218
2219 printf("\n%s(%s)\n", __func__, test_match ? "test match" : "test mismatch");
2220
2221 /* Autogenerate Cell ID lists from above dataset, which should match / not match. */
2222 for (i = 0; i < ARRAY_SIZE(discrs); i++) {
2223 for (j = 0; j < ARRAY_SIZE(discrs); j++)
2224 if (!test_cell_id_list_matching_discrs(test_match,
2225 discrs[i], discrs[j]))
2226 ok = false;
2227 }
2228
2229 OSMO_ASSERT(ok);
2230}
2231
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002232int main(int argc, char **argv)
2233{
Max969fb2e2018-12-10 11:01:10 +01002234 void *ctx = talloc_named_const(NULL, 0, "gsm0808 test");
2235 msgb_talloc_ctx_init(ctx, 0);
2236 osmo_init_logging2(ctx, NULL);
2237
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002238 printf("Testing generation of GSM0808 messages\n");
Philipp Maier4f4905f2018-11-30 13:36:12 +01002239 test_gsm0808_enc_cause();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002240 test_create_layer3();
Philipp Maierfa896ab2017-03-27 16:55:32 +02002241 test_create_layer3_aoip();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002242 test_create_reset();
Philipp Maier15596e22017-04-05 17:55:27 +02002243 test_create_reset_ack();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002244 test_create_clear_command();
Harald Weltecf665fc2019-02-18 13:45:36 +01002245 test_create_clear_command2();
2246 test_create_clear_command2_csfb();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002247 test_create_clear_complete();
Philipp Maierb478dd32017-03-29 15:50:05 +02002248 test_create_cipher();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002249 test_create_cipher_complete();
2250 test_create_cipher_reject();
Maxed651d22018-11-07 15:25:05 +01002251 test_create_cipher_reject_ext();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002252 test_create_cm_u();
2253 test_create_sapi_reject();
Philipp Maierc6144a22017-03-29 17:53:43 +02002254 test_create_ass();
Max52074322018-11-30 10:44:07 +01002255 test_create_ass2();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002256 test_create_ass_compl();
Philipp Maierfa896ab2017-03-27 16:55:32 +02002257 test_create_ass_compl_aoip();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002258 test_create_ass_fail();
Philipp Maierfa896ab2017-03-27 16:55:32 +02002259 test_create_ass_fail_aoip();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002260 test_create_clear_rqst();
Philipp Maier3d48ec02017-03-29 17:37:55 +02002261 test_create_paging();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002262 test_create_dtap();
2263 test_prepend_dtap();
Max969fb2e2018-12-10 11:01:10 +01002264
Max47022152018-12-19 18:51:00 +01002265 test_enc_dec_lcls();
Max969fb2e2018-12-10 11:01:10 +01002266
Philipp Maier22401432017-03-24 17:59:26 +01002267 test_enc_dec_aoip_trasp_addr_v4();
2268 test_enc_dec_aoip_trasp_addr_v6();
Philipp Maier6f725d62017-03-24 18:03:17 +01002269 test_gsm0808_enc_dec_speech_codec();
Philipp Maier6f725d62017-03-24 18:03:17 +01002270 test_gsm0808_enc_dec_speech_codec_ext_with_cfg();
Philipp Maierbb839662017-06-01 17:11:19 +02002271 test_gsm0808_enc_dec_speech_codec_with_cfg();
Philipp Maier6f725d62017-03-24 18:03:17 +01002272 test_gsm0808_enc_dec_speech_codec_list();
Philipp Maierf6c369f2018-10-16 15:24:47 +02002273 test_gsm0808_enc_dec_empty_speech_codec_list();
Philipp Maiere0c65302017-03-28 17:05:40 +02002274 test_gsm0808_enc_dec_channel_type();
Philipp Maier14e76b92017-03-28 18:36:52 +02002275 test_gsm0808_enc_dec_encrypt_info();
Neels Hofmeyr250e7f72018-04-13 03:30:14 +02002276
Philipp Maier783047e2017-03-29 11:35:50 +02002277 test_gsm0808_enc_dec_cell_id_list_lac();
2278 test_gsm0808_enc_dec_cell_id_list_single_lac();
Stefan Sperlinge1a86742018-03-15 18:05:02 +01002279 test_gsm0808_enc_dec_cell_id_list_multi_lac();
Philipp Maier783047e2017-03-29 11:35:50 +02002280 test_gsm0808_enc_dec_cell_id_list_bss();
Stefan Sperling23381452018-03-15 19:38:15 +01002281 test_gsm0808_enc_dec_cell_id_list_multi_lai_and_lac();
Stefan Sperling9c62fc62018-03-16 10:23:34 +01002282 test_gsm0808_enc_dec_cell_id_list_multi_ci();
Stefan Sperlinged4327c2018-03-16 11:02:59 +01002283 test_gsm0808_enc_dec_cell_id_list_multi_lac_and_ci();
Stefan Sperling483f3862018-03-16 12:21:26 +01002284 test_gsm0808_enc_dec_cell_id_list_multi_global();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002285
Neels Hofmeyr74663d92018-03-23 01:46:42 +01002286 test_cell_id_list_add();
2287
Neels Hofmeyr250e7f72018-04-13 03:30:14 +02002288 test_gsm0808_enc_dec_cell_id_lac();
2289 test_gsm0808_enc_dec_cell_id_bss();
2290 test_gsm0808_enc_dec_cell_id_no_cell();
2291 test_gsm0808_enc_dec_cell_id_lai_and_lac();
2292 test_gsm0808_enc_dec_cell_id_ci();
2293 test_gsm0808_enc_dec_cell_id_lac_and_ci();
2294 test_gsm0808_enc_dec_cell_id_global();
2295
Philipp Maier5f2eb152018-09-19 13:40:21 +02002296 test_gsm0808_sc_cfg_from_gsm48_mr_cfg();
Philipp Maier8515d032018-09-25 15:57:49 +02002297 test_gsm48_mr_cfg_from_gsm0808_sc_cfg();
Philipp Maier5f2eb152018-09-19 13:40:21 +02002298
Neels Hofmeyrd01ef752018-09-21 15:57:26 +02002299 test_cell_id_matching();
2300 test_cell_id_list_matching(true);
2301 test_cell_id_list_matching(false);
2302
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002303 printf("Done\n");
2304 return EXIT_SUCCESS;
2305}