blob: ab9f29b69c2d2810cea63305e8192ddeae086f9e [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 *
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +010015 */
16
17#include <osmocom/gsm/gsm0808.h>
Philipp Maier22401432017-03-24 17:59:26 +010018#include <osmocom/gsm/gsm0808_utils.h>
19#include <osmocom/gsm/protocol/gsm_08_08.h>
Philipp Maier3d48ec02017-03-29 17:37:55 +020020#include <osmocom/gsm/protocol/gsm_08_58.h>
Max969fb2e2018-12-10 11:01:10 +010021#include <osmocom/core/logging.h>
22#include <osmocom/core/application.h>
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +010023
24#include <stdio.h>
25#include <stdlib.h>
Philipp Maier22401432017-03-24 17:59:26 +010026#include <sys/socket.h>
27#include <netinet/in.h>
28#include <arpa/inet.h>
Neels Hofmeyr74663d92018-03-23 01:46:42 +010029#include <errno.h>
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +010030
Philipp Maier4f4905f2018-11-30 13:36:12 +010031#define EXPECT_ENCODED(hexstr) do { \
32 const char *enc_str = msgb_hexdump(msg); \
33 printf("%s: encoded: %s(rc = %u)\n", __func__, enc_str, rc_enc); \
34 OSMO_ASSERT(strcmp(enc_str, hexstr " ") == 0); \
35 OSMO_ASSERT(rc_enc == msg->len); \
36 } while(0)
37
Vadim Yanitskiycf6ee642018-12-20 05:23:00 +070038#define VERIFY(msg, data, data_len) do { \
39 if (!msgb_eq_l3_data_print(msg, data, data_len)) \
40 abort(); \
41 } while(0)
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +010042
Philipp Maierfa896ab2017-03-27 16:55:32 +020043/* Setup a fake codec list for testing */
44static void setup_codec_list(struct gsm0808_speech_codec_list *scl)
45{
46 memset(scl, 0, sizeof(*scl));
47
48 scl->codec[0].pi = true;
49 scl->codec[0].tf = true;
Philipp Maierbb839662017-06-01 17:11:19 +020050 scl->codec[0].type = GSM0808_SCT_FR3;
Philipp Maierfa896ab2017-03-27 16:55:32 +020051 scl->codec[0].cfg = 0xcdef;
52
53 scl->codec[1].fi = true;
54 scl->codec[1].pt = true;
Philipp Maierbb839662017-06-01 17:11:19 +020055 scl->codec[1].type = GSM0808_SCT_FR2;
Philipp Maierfa896ab2017-03-27 16:55:32 +020056
57 scl->codec[2].fi = true;
58 scl->codec[2].tf = true;
Philipp Maierbb839662017-06-01 17:11:19 +020059 scl->codec[2].type = GSM0808_SCT_CSD;
60 scl->codec[2].cfg = 0xc0;
Philipp Maierfa896ab2017-03-27 16:55:32 +020061
62 scl->len = 3;
63}
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +010064
Philipp Maier4f4905f2018-11-30 13:36:12 +010065void test_gsm0808_enc_cause(void)
66{
67 /* NOTE: This must be tested early because many of the following tests
68 * rely on the generation of a proper cause code. */
69
70 uint8_t rc_enc;
71 struct msgb *msg;
72
73 /* Test with a single byte cause code */
74 msg = msgb_alloc(1024, "output buffer");
75 rc_enc = gsm0808_enc_cause(msg, 0x41);
76 EXPECT_ENCODED("04 01 41");
77 msgb_free(msg);
78
79 /* Test with an extended (two byte) cause code */
80 msg = msgb_alloc(1024, "output buffer");
81 rc_enc = gsm0808_enc_cause(msg, 0x8041);
82 EXPECT_ENCODED("04 02 80 41");
83 msgb_free(msg);
84}
85
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +010086static void test_create_layer3(void)
87{
88 static const uint8_t res[] = {
89 0x00, 0x0e, 0x57, 0x05, 0x08, 0x00, 0x77, 0x62,
90 0x83, 0x33, 0x66, 0x44, 0x88, 0x17, 0x01, 0x23 };
91 struct msgb *msg, *in_msg;
Neels Hofmeyr178bf7a2018-04-20 12:23:45 +020092 struct osmo_cell_global_id cgi = {
93 .lai = {
94 .plmn = {
95 .mcc = 0x2244,
96 .mnc = 0x1122,
97 },
98 .lac = 0x3366,
99 },
100 .cell_identity = 0x4488,
101 };
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100102 printf("Testing creating Layer3\n");
103
104 in_msg = msgb_alloc_headroom(512, 128, "foo");
105 in_msg->l3h = in_msg->data;
106 msgb_v_put(in_msg, 0x23);
107
Neels Hofmeyr178bf7a2018-04-20 12:23:45 +0200108 msg = gsm0808_create_layer3_2(in_msg, &cgi, NULL);
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100109 VERIFY(msg, res, ARRAY_SIZE(res));
110 msgb_free(msg);
111 msgb_free(in_msg);
112}
113
Harald Weltee61d4592022-11-03 11:05:58 +0100114static void test_create_layer3_aoip(void)
Philipp Maierfa896ab2017-03-27 16:55:32 +0200115{
116 static const uint8_t res[] = {
117 0x00, 0x17, 0x57, 0x05, 0x08, 0x00, 0x77, 0x62,
118 0x83, 0x33, 0x66, 0x44, 0x88, 0x17, 0x01, 0x23,
Philipp Maierbb839662017-06-01 17:11:19 +0200119 GSM0808_IE_SPEECH_CODEC_LIST, 0x07, GSM0808_SCT_FR3 | 0x50,
Philipp Maier7e27b142018-03-22 17:26:46 +0100120 0xef, 0xcd, GSM0808_SCT_FR2 | 0xa0, 0x9f,
Philipp Maierbb839662017-06-01 17:11:19 +0200121 GSM0808_SCT_CSD | 0x90, 0xc0
Philipp Maierfa896ab2017-03-27 16:55:32 +0200122 };
Maxfa3b4822018-11-05 14:59:54 +0100123 struct osmo_cell_global_id cgi = {
124 .lai = {
125 .plmn = {
126 .mcc = 0x2244,
127 .mnc = 0x1122,
128 },
129 .lac = 0x3366,
130 },
131 .cell_identity = 0x4488,
132 };
Philipp Maierfa896ab2017-03-27 16:55:32 +0200133 struct msgb *msg, *in_msg;
134 struct gsm0808_speech_codec_list sc_list;
135 printf("Testing creating Layer3 (AoIP)\n");
136
137 setup_codec_list(&sc_list);
138
139 in_msg = msgb_alloc_headroom(512, 128, "foo");
140 in_msg->l3h = in_msg->data;
141 msgb_v_put(in_msg, 0x23);
142
Maxfa3b4822018-11-05 14:59:54 +0100143 msg = gsm0808_create_layer3_2(in_msg, &cgi, &sc_list);
144
Philipp Maierfa896ab2017-03-27 16:55:32 +0200145 VERIFY(msg, res, ARRAY_SIZE(res));
146
147 msgb_free(msg);
148 msgb_free(in_msg);
149}
150
Harald Weltee61d4592022-11-03 11:05:58 +0100151static void test_create_reset(void)
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100152{
153 static const uint8_t res[] = { 0x00, 0x04, 0x30, 0x04, 0x01, 0x20 };
154 struct msgb *msg;
155
156 printf("Testing creating Reset\n");
157 msg = gsm0808_create_reset();
158 VERIFY(msg, res, ARRAY_SIZE(res));
159 msgb_free(msg);
160}
161
Harald Weltee61d4592022-11-03 11:05:58 +0100162static void test_create_reset_ack(void)
Philipp Maier15596e22017-04-05 17:55:27 +0200163{
164 static const uint8_t res[] = { 0x00, 0x01, 0x31 };
165 struct msgb *msg;
166
167 printf("Testing creating Reset Ack\n");
168 msg = gsm0808_create_reset_ack();
169 VERIFY(msg, res, ARRAY_SIZE(res));
170 msgb_free(msg);
171}
172
173
Harald Weltee61d4592022-11-03 11:05:58 +0100174static void test_create_clear_command(void)
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100175{
176 static const uint8_t res[] = { 0x20, 0x04, 0x01, 0x23 };
177 struct msgb *msg;
178
179 printf("Testing creating Clear Command\n");
180 msg = gsm0808_create_clear_command(0x23);
181 VERIFY(msg, res, ARRAY_SIZE(res));
182 msgb_free(msg);
183}
184
Harald Weltee61d4592022-11-03 11:05:58 +0100185static void test_create_clear_command2(void)
Harald Weltecf665fc2019-02-18 13:45:36 +0100186{
187 static const uint8_t res[] = { 0x00, 0x04, 0x20, 0x04, 0x01, 0x23 };
188 struct msgb *msg;
189
190 printf("Testing creating Clear Command 2\n");
191 msg = gsm0808_create_clear_command2(0x23, false);
192 VERIFY(msg, res, ARRAY_SIZE(res));
193 msgb_free(msg);
194}
195
Harald Weltee61d4592022-11-03 11:05:58 +0100196static void test_create_clear_command2_csfb(void)
Harald Weltecf665fc2019-02-18 13:45:36 +0100197{
198 static const uint8_t res[] = { 0x00, 0x05, 0x20, 0x04, 0x01, 0x23, 0x8F };
199 struct msgb *msg;
200
201 printf("Testing creating Clear Command 2 (CSFB)\n");
202 msg = gsm0808_create_clear_command2(0x23, true);
203 VERIFY(msg, res, ARRAY_SIZE(res));
204 msgb_free(msg);
205}
206
Harald Weltee61d4592022-11-03 11:05:58 +0100207static void test_create_clear_complete(void)
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100208{
209 static const uint8_t res[] = { 0x00, 0x01, 0x21 };
210 struct msgb *msg;
211
212 printf("Testing creating Clear Complete\n");
213 msg = gsm0808_create_clear_complete();
214 VERIFY(msg, res, ARRAY_SIZE(res));
215 msgb_free(msg);
216}
217
Harald Weltee61d4592022-11-03 11:05:58 +0100218static void test_create_cipher(void)
Philipp Maierb478dd32017-03-29 15:50:05 +0200219{
220 static const uint8_t res[] =
221 { 0x00, 0x0c, 0x53, 0x0a, 0x09, 0x03, 0xaa,
222 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x23, 0x42 };
223 static const uint8_t res2[] =
224 { 0x00, 0x0e, 0x53, 0x0a, 0x09, 0x03, 0xaa,
225 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x23, 0x42,
226 GSM0808_IE_CIPHER_RESPONSE_MODE, 0x01 };
227 struct msgb *msg;
228 struct gsm0808_encrypt_info ei;
229 uint8_t include_imeisv;
230
231 memset(&ei, 0, sizeof(ei));
232 ei.perm_algo[0] = GSM0808_ALG_ID_A5_0;
233 ei.perm_algo[1] = GSM0808_ALG_ID_A5_1;
234 ei.perm_algo_len = 2;
235 ei.key[0] = 0xaa;
236 ei.key[1] = 0xbb;
237 ei.key[2] = 0xcc;
238 ei.key[3] = 0xdd;
239 ei.key[4] = 0xee;
240 ei.key[5] = 0xff;
241 ei.key[6] = 0x23;
242 ei.key[7] = 0x42;
243 ei.key_len = 8;
244 include_imeisv = 1;
245
246 printf("Testing creating Chipher Mode Command\n");
247 msg = gsm0808_create_cipher(&ei, NULL);
248 OSMO_ASSERT(msg);
249 VERIFY(msg, res, ARRAY_SIZE(res));
250 msgb_free(msg);
251
252 msg = gsm0808_create_cipher(&ei, &include_imeisv);
253 OSMO_ASSERT(msg);
254 VERIFY(msg, res2, ARRAY_SIZE(res2));
255 msgb_free(msg);
256}
257
Harald Weltee61d4592022-11-03 11:05:58 +0100258static void test_create_cipher_complete(void)
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100259{
260 static const uint8_t res1[] = {
261 0x00, 0x08, 0x55, 0x20, 0x03, 0x23, 0x42, 0x21, 0x2c, 0x04 };
262 static const uint8_t res2[] = { 0x00, 0x03, 0x55, 0x2c, 0x04};
263 struct msgb *l3, *msg;
264
265 printf("Testing creating Cipher Complete\n");
266 l3 = msgb_alloc_headroom(512, 128, "l3h");
267 l3->l3h = l3->data;
268 msgb_v_put(l3, 0x23);
269 msgb_v_put(l3, 0x42);
270 msgb_v_put(l3, 0x21);
271
272 /* with l3 data */
273 msg = gsm0808_create_cipher_complete(l3, 4);
274 VERIFY(msg, res1, ARRAY_SIZE(res1));
275 msgb_free(msg);
276
277 /* with l3 data but short */
278 l3->len -= 1;
279 l3->tail -= 1;
280 msg = gsm0808_create_cipher_complete(l3, 4);
281 VERIFY(msg, res2, ARRAY_SIZE(res2));
282 msgb_free(msg);
283
284 /* without l3 data */
285 msg = gsm0808_create_cipher_complete(NULL, 4);
286 VERIFY(msg, res2, ARRAY_SIZE(res2));
287 msgb_free(msg);
288
289
290 msgb_free(l3);
291}
292
Maxed651d22018-11-07 15:25:05 +0100293static inline void parse_cipher_reject(struct msgb *msg, uint8_t exp)
294{
295 struct tlv_parsed tp;
296 int rc;
297
298 /* skip header and message type so we can parse Cause IE directly */
299 msg->l2h = msgb_data(msg) + sizeof(struct bssmap_header) + 1;
300
301 rc = osmo_bssap_tlv_parse(&tp, msg->l2h, msgb_l2len(msg));
302 if (rc < 0)
303 printf("FIXME: failed (%d) to parse created message %s\n", rc, msgb_hexdump(msg));
304
Alexander Chemerisfdfe25b2020-05-12 23:21:56 +0300305 rc = gsm0808_get_cause(&tp);
Maxed651d22018-11-07 15:25:05 +0100306 if (rc < 0)
307 printf("FIXME: failed (%s) to extract Cause from created message %s\n",
308 strerror(-rc), msgb_hexdump(msg));
309
310 if (exp != (enum gsm0808_cause)rc)
311 printf("FIXME: wrong Cause %d != %u (" OSMO_BIN_SPEC ") extracted from created message %s\n",
312 rc, exp, OSMO_BIT_PRINT(exp), msgb_hexdump(msg));
313}
314
Harald Weltee61d4592022-11-03 11:05:58 +0100315static void test_create_cipher_reject(void)
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100316{
Harald Welte62e40852017-12-17 20:50:34 +0100317 static const uint8_t res[] = { 0x00, 0x04, 0x59, 0x04, 0x01, 0x23 };
Maxed651d22018-11-07 15:25:05 +0100318 enum gsm0808_cause cause = GSM0808_CAUSE_CCCH_OVERLOAD;
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100319 struct msgb *msg;
320
321 printf("Testing creating Cipher Reject\n");
Maxed651d22018-11-07 15:25:05 +0100322 msg = gsm0808_create_cipher_reject(cause);
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100323 VERIFY(msg, res, ARRAY_SIZE(res));
Maxed651d22018-11-07 15:25:05 +0100324
325 parse_cipher_reject(msg, cause);
326
327 msgb_free(msg);
328}
329
Harald Weltee61d4592022-11-03 11:05:58 +0100330static void test_create_cipher_reject_ext(void)
Maxed651d22018-11-07 15:25:05 +0100331{
332 static const uint8_t res[] = { 0x00, 0x05, 0x59, 0x04, 0x02, 0xd0, 0xFA };
333 uint8_t cause = 0xFA;
334 struct msgb *msg;
335
336 printf("Testing creating Cipher Reject (extended)\n");
337 msg = gsm0808_create_cipher_reject_ext(GSM0808_CAUSE_CLASS_INVAL, cause);
338 VERIFY(msg, res, ARRAY_SIZE(res));
339
340 parse_cipher_reject(msg, cause);
341
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100342 msgb_free(msg);
343}
344
Harald Weltee61d4592022-11-03 11:05:58 +0100345static void test_create_cm_u(void)
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100346{
Harald Welte07b625d2012-01-23 10:02:58 +0100347 static const uint8_t res[] = {
348 0x00, 0x07, 0x54, 0x12, 0x01, 0x23, 0x13, 0x01, 0x42 };
349 static const uint8_t res2o[] = {
350 0x00, 0x04, 0x54, 0x12, 0x01, 0x23 };
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100351 struct msgb *msg;
Harald Welte07b625d2012-01-23 10:02:58 +0100352 const uint8_t cm2 = 0x23;
353 const uint8_t cm3 = 0x42;
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100354
355 printf("Testing creating CM U\n");
Harald Welte07b625d2012-01-23 10:02:58 +0100356 msg = gsm0808_create_classmark_update(&cm2, 1, &cm3, 1);
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100357 VERIFY(msg, res, ARRAY_SIZE(res));
Harald Welte07b625d2012-01-23 10:02:58 +0100358
Neels Hofmeyr9a938ae2017-11-16 17:34:07 +0100359 msgb_free(msg);
360
Harald Welte07b625d2012-01-23 10:02:58 +0100361 msg = gsm0808_create_classmark_update(&cm2, 1, NULL, 0);
362 VERIFY(msg, res2o, ARRAY_SIZE(res2o));
363
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100364 msgb_free(msg);
365}
366
Harald Weltee61d4592022-11-03 11:05:58 +0100367static void test_create_sapi_reject(void)
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100368{
Alexander Chemerisa5b1b862020-05-12 01:03:08 +0300369 static const uint8_t res[] = { 0x00, 0x06, 0x25, 0x18, 0x03, 0x04, 0x01, 0x25 };
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100370 struct msgb *msg;
371
372 printf("Testing creating SAPI Reject\n");
Vadim Yanitskiyfa6cd882020-08-26 18:03:59 +0700373 msg = gsm0808_create_sapi_reject_cause(3, GSM0808_CAUSE_BSS_NOT_EQUIPPED);
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100374 VERIFY(msg, res, ARRAY_SIZE(res));
375 msgb_free(msg);
376}
377
Harald Weltee61d4592022-11-03 11:05:58 +0100378static void test_dec_confusion(void)
Alexander Chemeris22630e62020-05-13 00:44:04 +0300379{
380 static const uint8_t hex[] =
381 { 0x26, 0x04, 0x01, 0x52, 0x1f, 0x07, 0x00, 0xff, 0x00, 0x03, 0x25, 0x03, 0x25 };
382 struct tlv_parsed tp;
383 int diag_len;
384 enum gsm0808_cause cause;
385 enum gsm0808_cause_class cause_class;
386 struct gsm0808_diagnostics *diag;
387
388 printf("Testing decoding CONFUSION\n");
389
390 tlv_parse(&tp, gsm0808_att_tlvdef(), hex+1, sizeof(hex)-1, 0, 0);
391
392 /* Check for the Cause and Diagnostic mandatory elements */
393 if (!TLVP_PRESENT(&tp, GSM0808_IE_CAUSE) || !TLVP_PRESENT(&tp, GSM0808_IE_DIAGNOSTIC)) {
394 printf("Either Cause or Diagnostic mandatory IE are not detected\n");
395 return;
396 }
397
398 diag_len = TLVP_LEN(&tp, GSM0808_IE_DIAGNOSTIC);
399 if (diag_len < 5) {
400 printf("Diagnostic length is too short: %d (expected > 5)\n",
401 diag_len);
402 return;
403 }
404
405 cause = gsm0808_get_cause(&tp);
406 if ((int)cause < 0) {
407 printf("ERROR: failed (%s) to extract Cause, aborting\n", strerror(-(int)cause));
408 return;
409 }
410 cause_class = gsm0808_cause_class(cause);
411 printf(" Cause class %d/0x%x (%s)\n",
412 cause_class, cause_class, gsm0808_cause_class_name(cause_class));
413 printf(" Cause %d/0x%x (%s)\n",
414 cause, cause, gsm0808_cause_name(cause));
415
416 diag = (struct gsm0808_diagnostics *)TLVP_VAL(&tp, GSM0808_IE_DIAGNOSTIC);
417 printf(" Diagnostics error octet location %d (%s)\n",
418 diag->error_pointer_octet,
419 gsm0808_diagnostics_octet_location_str(diag->error_pointer_octet));
420 printf(" Diagnostics error bit location %d (%s)\n",
421 diag->error_pointer_bit,
422 gsm0808_diagnostics_bit_location_str(diag->error_pointer_bit));
423 printf(" Diagnostics message that provoked the error: %s\n",
424 osmo_hexdump(diag->msg, diag_len-2));
425}
426
Pau Espin Pedrola3987fc2022-03-18 13:17:28 +0100427/* Test Perform Location Report SYS#5891 */
Harald Weltee61d4592022-11-03 11:05:58 +0100428static void test_dec_perform_location_report_sys5891(void)
Pau Espin Pedrola3987fc2022-03-18 13:17:28 +0100429{
430/* Message Type Perform Location Request
431 Location Type
432 Element ID: 0x44
433 Length: 1
434 Location Information: current geographic location (0x00)
435 Cell Identifier/CI (25911)
436 Element ID: 0x05
437 Length: 8
438 0000 .... = Spare bit(s): 0x00
439 .... 0000 = Cell identification discriminator: The whole Cell Global Identification, CGI, is used to identify the cells. (0)
440 Mobile Country Code (MCC): (removed))
441 Mobile Network Code (MNC): (removed))
442 Cell LAC: 0x001e (30)
443 Cell CI: 0x6537 (25911)
444 LCS Client Type
445 Element ID: 0x48
446 Length: 1
447 0011 .... = Client Category: Emergency Services (0x03)
448 .... 0000 = Client Subtype: unspecified (0x00)
449 LCS Priority
450 Element ID: 0x43
451 Length: 1
452 Periodicity: highest (0)
453 LCS QoS
454 Element ID: 0x3e
455 Length: 4
456 0000 00.. = Spare: 0x00
457 .... ..0. = Velocity Requested: do not report velocity (0x00)
458 .... ...0 = Vertical Coordinate Indicator: vertical coordinate not requested (0x00)
459 1... .... = Horizontal Accuracy Indicator: horizontal accuracy is specified (0x01)
460 .001 0010 = Horizontal Accuracy: 0x12
461 0... .... = Vertical Accuracy Indicator: vertical accuracy is not specified (0x00)
462 .000 0000 = Spare: 0x00
463 00.. .... = Response Time Category: Response Time is not specified (0x00)
464*/
465 const uint8_t hex[] = {
466 0x2b, 0x44, 0x01, 0x00, 0x05, 0x08, 0x00, 0xab, 0xbc, 0xcd, 0x00, 0x1e,
467 0x65, 0x37, 0x48, 0x01, 0x30, 0x43, 0x01, 0x00, 0x3e, 0x04, 0x00, 0x92,
468 0x00, 0x00
469 };
470
471 struct tlv_parsed tp;
472 int rc;
473
474 printf("Testing decoding Perform Location Report SYS#5891\n");
475
476 rc = tlv_parse(&tp, gsm0808_att_tlvdef(), hex+1, sizeof(hex)-1, 0, 0);
Pau Espin Pedrolfffd7c32022-03-18 13:45:42 +0100477 OSMO_ASSERT(rc == 5);
Pau Espin Pedrola3987fc2022-03-18 13:17:28 +0100478}
479
Harald Weltee61d4592022-11-03 11:05:58 +0100480static void test_create_ass(void)
Philipp Maierc6144a22017-03-29 17:53:43 +0200481{
482 static const uint8_t res1[] =
483 { 0x00, 0x0a, 0x01, 0x0b, 0x04, 0x01, 0x0b, 0xa1, 0x25, 0x01, 0x00,
484 0x04 };
485 static const uint8_t res2[] =
486 { 0x00, 0x20, 0x01, 0x0b, 0x04, 0x01, 0x0b, 0xa1, 0x25, 0x01, 0x00,
487 0x04, GSM0808_IE_AOIP_TRASP_ADDR, 0x06, 0xc0, 0xa8, 0x64, 0x17,
Philipp Maierbb839662017-06-01 17:11:19 +0200488 0x04, 0xd2, GSM0808_IE_SPEECH_CODEC_LIST, 0x07,
Philipp Maier7e27b142018-03-22 17:26:46 +0100489 GSM0808_SCT_FR3 | 0x50, 0xef, 0xcd, GSM0808_SCT_FR2 | 0xa0, 0x9f,
Philipp Maier2908dbf2020-06-05 14:16:11 +0200490 GSM0808_SCT_CSD | 0x90, 0xc0, GSM0808_IE_CALL_ID, 0xdd, 0xcc,
491 0xbb, 0xaa };
Philipp Maierc6144a22017-03-29 17:53:43 +0200492
493 struct msgb *msg;
494 struct gsm0808_channel_type ct;
495 uint16_t cic = 0004;
496 struct sockaddr_storage ss;
497 struct sockaddr_in sin;
498 struct gsm0808_speech_codec_list sc_list;
499 uint32_t call_id = 0xAABBCCDD;
500
501 memset(&ct, 0, sizeof(ct));
502 ct.ch_indctr = GSM0808_CHAN_SPEECH;
503 ct.ch_rate_type = GSM0808_SPEECH_HALF_PREF;
504 ct.perm_spch[0] = GSM0808_PERM_FR3;
505 ct.perm_spch[1] = GSM0808_PERM_HR3;
506 ct.perm_spch_len = 2;
507
508 memset(&sin, 0, sizeof(sin));
509 sin.sin_family = AF_INET;
510 sin.sin_port = htons(1234);
511 inet_aton("192.168.100.23", &sin.sin_addr);
512
513 memset(&ss, 0, sizeof(ss));
514 memcpy(&ss, &sin, sizeof(sin));
515
516 setup_codec_list(&sc_list);
517
518 printf("Testing creating Assignment Request\n");
519 msg = gsm0808_create_ass(&ct, &cic, NULL, NULL, NULL);
520 OSMO_ASSERT(msg);
521 VERIFY(msg, res1, ARRAY_SIZE(res1));
522 msgb_free(msg);
523
524 msg = gsm0808_create_ass(&ct, &cic, &ss, &sc_list, &call_id);
525 OSMO_ASSERT(msg);
526 VERIFY(msg, res2, ARRAY_SIZE(res2));
527 msgb_free(msg);
528}
529
Harald Weltee61d4592022-11-03 11:05:58 +0100530static void test_create_ass2(void)
Max52074322018-11-30 10:44:07 +0100531{
532 static const uint8_t res[] = {
533 BSSAP_MSG_BSS_MANAGEMENT,
534 0x45,
535 BSS_MAP_MSG_ASSIGMENT_RQST,
536 GSM0808_IE_CHANNEL_TYPE,
537 0x04, 0x01, 0x0b, 0x91, 0x15, 0x01, 0x00, 0x04,
538 GSM0808_IE_AOIP_TRASP_ADDR,
539 0x06,
540 0xac, 0x0c, 0x65, 0x0d, /* IPv4 */
541 0x02, 0x9a,
542 GSM0808_IE_SPEECH_CODEC_LIST,
543 0x07,
544 GSM0808_SCT_FR3 | 0x50,
545 0xef, 0xcd,
546 GSM0808_SCT_FR2 | 0xa0,
547 0x9f,
548 GSM0808_SCT_CSD | 0x90,
549 0xc0,
550 GSM0808_IE_CALL_ID,
Pau Espin Pedrol1bd495a2021-02-15 16:15:59 +0100551 0xce, 0xfa, 0xad, 0xde, /* CallID */
Max52074322018-11-30 10:44:07 +0100552 0x83, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, /* Kc */
553 GSM0808_IE_GLOBAL_CALL_REF, 0x0d, /* GCR, length */
554 0x03, 0x44, 0x44, 0x44, /* GCR, Net ID */
555 0x02, 0xfe, 0xed, /* GCR, Node ID */
556 0x05, 0x41, 0x41, 0x41, 0x41, 0x41, /* GCR, Call ref. ID */
557 GSM0808_IE_LCLS_CONFIG, GSM0808_LCLS_CFG_BOTH_WAY,
558 GSM0808_IE_LCLS_CONN_STATUS_CTRL, GSM0808_LCLS_CSC_CONNECT,
559 GSM0808_IE_LCLS_CORR_NOT_NEEDED,
560 };
561 struct msgb *msg;
562 struct gsm0808_channel_type ct;
563 uint16_t cic = 4;
564 struct sockaddr_storage ss;
565 struct sockaddr_in sin;
566 struct gsm0808_speech_codec_list sc_list;
567 uint32_t call_id = 0xDEADFACE;
Max52074322018-11-30 10:44:07 +0100568 uint8_t Kc[16];
569 struct osmo_lcls lcls = {
570 .config = GSM0808_LCLS_CFG_BOTH_WAY,
571 .control = GSM0808_LCLS_CSC_CONNECT,
Max3b901252019-01-15 14:15:11 +0100572 .gcr = { .net_len = 3, .node = 0xFEED },
573 .gcr_available = true,
Max52074322018-11-30 10:44:07 +0100574 .corr_needed = false
575 };
576
Max3b901252019-01-15 14:15:11 +0100577 memset(lcls.gcr.cr, 'A', 5);
578 memset(lcls.gcr.net, 'D', lcls.gcr.net_len);
Max52074322018-11-30 10:44:07 +0100579 memset(Kc, 'E', 16);
580
581 memset(&ct, 0, sizeof(ct));
582 ct.ch_indctr = GSM0808_CHAN_SPEECH;
583 ct.ch_rate_type = GSM0808_SPEECH_HALF_PREF;
584 ct.perm_spch[0] = GSM0808_PERM_FR2;
585 ct.perm_spch[1] = GSM0808_PERM_HR2;
586 ct.perm_spch_len = 2;
587
588 memset(&sin, 0, sizeof(sin));
589 sin.sin_family = AF_INET;
590 sin.sin_port = htons(666);
591 inet_aton("172.12.101.13", &sin.sin_addr); /* IPv4 */
592
593 memset(&ss, 0, sizeof(ss));
594 memcpy(&ss, &sin, sizeof(sin));
595
596 setup_codec_list(&sc_list);
597
598 printf("Testing creating Assignment Request with Kc and LCLS\n");
599
600 msg = gsm0808_create_ass2(&ct, &cic, &ss, &sc_list, &call_id, Kc, &lcls);
601 if (!msgb_eq_l3_data_print(msg, res, ARRAY_SIZE(res)))
602 abort();
603
604 msgb_free(msg);
605}
606
Harald Weltee61d4592022-11-03 11:05:58 +0100607static void test_create_ass_compl(void)
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100608{
609 static const uint8_t res1[] = {
610 0x00, 0x09, 0x02, 0x15, 0x23, 0x21, 0x42, 0x2c,
611 0x11, 0x40, 0x22 };
612 static const uint8_t res2[] = {
613 0x00, 0x07, 0x02, 0x15, 0x23, 0x21, 0x42, 0x2c, 0x11};
614 struct msgb *msg;
615
616 printf("Testing creating Assignment Complete\n");
617 msg = gsm0808_create_assignment_completed(0x23, 0x42, 0x11, 0x22);
618 VERIFY(msg, res1, ARRAY_SIZE(res1));
619 msgb_free(msg);
620
621 msg = gsm0808_create_assignment_completed(0x23, 0x42, 0x11, 0);
622 VERIFY(msg, res2, ARRAY_SIZE(res2));
623 msgb_free(msg);
624}
625
Harald Weltee61d4592022-11-03 11:05:58 +0100626static void test_create_ass_compl_aoip(void)
Philipp Maierfa896ab2017-03-27 16:55:32 +0200627{
628 struct sockaddr_storage ss;
629 struct sockaddr_in sin;
630 struct gsm0808_speech_codec sc;
631 struct gsm0808_speech_codec_list sc_list;
632 static const uint8_t res[] =
Max414c8f52019-01-08 14:44:24 +0100633 { 0x00, 0x1f, 0x02, 0x15, 0x23, 0x21, 0x42, 0x2c, 0x11, 0x40, 0x22,
Philipp Maierfa896ab2017-03-27 16:55:32 +0200634 GSM0808_IE_AOIP_TRASP_ADDR, 0x06, 0xc0, 0xa8, 0x64, 0x17, 0x04,
Philipp Maierbb839662017-06-01 17:11:19 +0200635 0xd2, GSM0808_IE_SPEECH_CODEC, 0x01, GSM0808_SCT_HR1 | 0x90,
Philipp Maier7e27b142018-03-22 17:26:46 +0100636 GSM0808_IE_SPEECH_CODEC_LIST, 0x07, GSM0808_SCT_FR3 | 0x50, 0xef,
Max414c8f52019-01-08 14:44:24 +0100637 0xcd, GSM0808_SCT_FR2 | 0xa0, 0x9f, GSM0808_SCT_CSD | 0x90, 0xc0,
638 GSM0808_IE_LCLS_BSS_STATUS, GSM0808_LCLS_STS_LOCALLY_SWITCHED };
Philipp Maierfa896ab2017-03-27 16:55:32 +0200639 struct msgb *msg;
640
641 memset(&sin, 0, sizeof(sin));
642 sin.sin_family = AF_INET;
643 sin.sin_port = htons(1234);
644 inet_aton("192.168.100.23", &sin.sin_addr);
645
646 memset(&ss, 0, sizeof(ss));
647 memcpy(&ss, &sin, sizeof(sin));
648
649 memset(&sc, 0, sizeof(sc));
650 sc.fi = true;
651 sc.tf = true;
Philipp Maierbb839662017-06-01 17:11:19 +0200652 sc.type = GSM0808_SCT_HR1;
Philipp Maierfa896ab2017-03-27 16:55:32 +0200653
654 setup_codec_list(&sc_list);
655
656 printf("Testing creating Assignment Complete (AoIP)\n");
Max414c8f52019-01-08 14:44:24 +0100657 msg = gsm0808_create_ass_compl2(0x23, 0x42, 0x11, 0x22,
658 &ss, &sc, &sc_list, GSM0808_LCLS_STS_LOCALLY_SWITCHED);
Philipp Maierfa896ab2017-03-27 16:55:32 +0200659 VERIFY(msg, res, ARRAY_SIZE(res));
660 msgb_free(msg);
661}
662
Harald Weltee61d4592022-11-03 11:05:58 +0100663static void test_create_ass_fail(void)
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100664{
665 static const uint8_t res1[] = { 0x00, 0x04, 0x03, 0x04, 0x01, 0x23 };
666 static const uint8_t res2[] = {
667 0x00, 0x06, 0x03, 0x04, 0x01, 0x23, 0x15, 0x02};
668 uint8_t rr_res = 2;
669 struct msgb *msg;
670
671 printf("Testing creating Assignment Failure\n");
672 msg = gsm0808_create_assignment_failure(0x23, NULL);
673 VERIFY(msg, res1, ARRAY_SIZE(res1));
674 msgb_free(msg);
675
676 msg = gsm0808_create_assignment_failure(0x23, &rr_res);
677 VERIFY(msg, res2, ARRAY_SIZE(res2));
678 msgb_free(msg);
679}
680
Harald Weltee61d4592022-11-03 11:05:58 +0100681static void test_create_ass_fail_aoip(void)
Philipp Maierfa896ab2017-03-27 16:55:32 +0200682{
683 static const uint8_t res1[] =
684 { 0x00, 0x0d, 0x03, 0x04, 0x01, 0x23, GSM0808_IE_SPEECH_CODEC_LIST,
Philipp Maier7e27b142018-03-22 17:26:46 +0100685 0x07, GSM0808_SCT_FR3 | 0x50, 0xef, 0xcd, GSM0808_SCT_FR2 | 0xa0,
Philipp Maierbb839662017-06-01 17:11:19 +0200686 0x9f, GSM0808_SCT_CSD | 0x90, 0xc0 };
Philipp Maierfa896ab2017-03-27 16:55:32 +0200687 static const uint8_t res2[] =
688 { 0x00, 0x0f, 0x03, 0x04, 0x01, 0x23, 0x15, 0x02,
Philipp Maier7e27b142018-03-22 17:26:46 +0100689 GSM0808_IE_SPEECH_CODEC_LIST, 0x07, GSM0808_SCT_FR3 | 0x50, 0xef,
690 0xcd, GSM0808_SCT_FR2 | 0xa0, 0x9f, GSM0808_SCT_CSD | 0x90, 0xc0 };
Philipp Maierfa896ab2017-03-27 16:55:32 +0200691 uint8_t rr_res = 2;
692 struct msgb *msg;
693 struct gsm0808_speech_codec_list sc_list;
694
695 setup_codec_list(&sc_list);
696
697 printf("Testing creating Assignment Failure (AoIP)\n");
698 msg = gsm0808_create_ass_fail(0x23, NULL, &sc_list);
699 VERIFY(msg, res1, ARRAY_SIZE(res1));
700 msgb_free(msg);
701
702 msg = gsm0808_create_ass_fail(0x23, &rr_res, &sc_list);
703 VERIFY(msg, res2, ARRAY_SIZE(res2));
704 msgb_free(msg);
705}
706
Harald Weltee61d4592022-11-03 11:05:58 +0100707static void test_create_clear_rqst(void)
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100708{
709 static const uint8_t res[] = { 0x00, 0x04, 0x22, 0x04, 0x01, 0x23 };
710 struct msgb *msg;
711
712 printf("Testing creating Clear Request\n");
713 msg = gsm0808_create_clear_rqst(0x23);
714 VERIFY(msg, res, ARRAY_SIZE(res));
715 msgb_free(msg);
716}
717
Harald Weltee61d4592022-11-03 11:05:58 +0100718static void test_create_paging(void)
Philipp Maier3d48ec02017-03-29 17:37:55 +0200719{
720 static const uint8_t res[] =
721 { 0x00, 0x10, 0x52, 0x08, 0x08, 0x09, 0x10, 0x10, 0x00, 0x00, 0x00,
722 0x21, 0x43, 0x1a, 0x03, 0x05, 0x23, 0x42 };
723 static const uint8_t res2[] =
724 { 0x00, 0x16, 0x52, 0x08, 0x08, 0x09, 0x10, 0x10, 0x00, 0x00, 0x00,
725 0x21, 0x43, GSM0808_IE_TMSI, 0x04, 0x12, 0x34, 0x56, 0x78, 0x1a,
726 0x03, 0x05, 0x23, 0x42 };
727 static const uint8_t res3[] =
728 { 0x00, 0x18, 0x52, 0x08, 0x08, 0x09, 0x10, 0x10, 0x00, 0x00, 0x00,
729 0x21, 0x43, GSM0808_IE_TMSI, 0x04, 0x12, 0x34, 0x56, 0x78, 0x1a,
730 0x03, 0x05, 0x23, 0x42, GSM0808_IE_CHANNEL_NEEDED,
731 RSL_CHANNEED_TCH_ForH };
732
733 struct msgb *msg;
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100734 struct gsm0808_cell_id_list2 cil;
Philipp Maier3d48ec02017-03-29 17:37:55 +0200735 uint32_t tmsi = 0x12345678;
736 uint8_t chan_needed = RSL_CHANNEED_TCH_ForH;
737
738 char imsi[] = "001010000001234";
739
740 cil.id_discr = CELL_IDENT_LAC;
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100741 cil.id_list[0].lac = 0x2342;
Philipp Maier3d48ec02017-03-29 17:37:55 +0200742 cil.id_list_len = 1;
743
744 printf("Testing creating Paging Request\n");
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100745 msg = gsm0808_create_paging2(imsi, NULL, &cil, NULL);
Philipp Maier3d48ec02017-03-29 17:37:55 +0200746 VERIFY(msg, res, ARRAY_SIZE(res));
747 msgb_free(msg);
748
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100749 msg = gsm0808_create_paging2(imsi, &tmsi, &cil, NULL);
Philipp Maier3d48ec02017-03-29 17:37:55 +0200750 VERIFY(msg, res2, ARRAY_SIZE(res2));
751 msgb_free(msg);
752
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100753 msg = gsm0808_create_paging2(imsi, &tmsi, &cil, &chan_needed);
Philipp Maier3d48ec02017-03-29 17:37:55 +0200754 VERIFY(msg, res3, ARRAY_SIZE(res3));
755 msgb_free(msg);
756}
757
Harald Weltee61d4592022-11-03 11:05:58 +0100758static void test_create_dtap(void)
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100759{
760 static const uint8_t res[] = { 0x01, 0x03, 0x02, 0x23, 0x42 };
761 struct msgb *msg, *l3;
762
763 printf("Testing creating DTAP\n");
764 l3 = msgb_alloc_headroom(512, 128, "test");
765 l3->l3h = l3->data;
766 msgb_v_put(l3, 0x23);
767 msgb_v_put(l3, 0x42);
768
769 msg = gsm0808_create_dtap(l3, 0x3);
770 VERIFY(msg, res, ARRAY_SIZE(res));
771 msgb_free(msg);
772 msgb_free(l3);
773}
774
Harald Weltee61d4592022-11-03 11:05:58 +0100775static void test_prepend_dtap(void)
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100776{
777 static const uint8_t res[] = { 0x01, 0x03, 0x02, 0x23, 0x42 };
778 struct msgb *in_msg;
779
780 printf("Testing prepend DTAP\n");
781
782 in_msg = msgb_alloc_headroom(512, 128, "test");
783 msgb_v_put(in_msg, 0x23);
784 msgb_v_put(in_msg, 0x42);
785
786 gsm0808_prepend_dtap_header(in_msg, 0x3);
787 in_msg->l3h = in_msg->data;
788 VERIFY(in_msg, res, ARRAY_SIZE(res));
789 msgb_free(in_msg);
790}
791
Harald Weltee61d4592022-11-03 11:05:58 +0100792static void test_enc_dec_lcls(void)
Max969fb2e2018-12-10 11:01:10 +0100793{
794 static const uint8_t res[] = {
795 GSM0808_IE_GLOBAL_CALL_REF,
796 0x0d, /* GCR length */
797 0x03, /* .net_len */
798 0xf1, 0xf2, 0xf3, /* .net */
799 0x02, /* .node length */
800 0xde, 0xad, /* .node */
801 0x05, /* length of Call. Ref. */
802 0x41, 0x42, 0x43, 0x44, 0x45 /* .cr - Call. Ref. */
803 };
804 uint8_t len;
805 struct msgb *msg;
Max969fb2e2018-12-10 11:01:10 +0100806 int rc;
807 struct tlv_parsed tp;
Max3b901252019-01-15 14:15:11 +0100808 struct osmo_lcls *lcls_out, lcls_in = {
809 .gcr = {
810 .net_len = 3,
811 .net = { 0xf1, 0xf2, 0xf3 },
812 .node = 0xDEAD,
813 .cr = { 0x41, 0x42, 0x43, 0x44, 0x45 },
814 },
815 .gcr_available = true,
Max47022152018-12-19 18:51:00 +0100816 .config = GSM0808_LCLS_CFG_NA,
817 .control = GSM0808_LCLS_CSC_NA,
818 .corr_needed = true,
819 };
820
821 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "LCLS IE");
Max969fb2e2018-12-10 11:01:10 +0100822 if (!msg)
823 return;
824
Max3b901252019-01-15 14:15:11 +0100825 lcls_out = talloc_zero(msg, struct osmo_lcls);
826 if (!lcls_out)
827 return;
828
Max47022152018-12-19 18:51:00 +0100829 len = gsm0808_enc_lcls(msg, &lcls_in);
Max969fb2e2018-12-10 11:01:10 +0100830 printf("Testing Global Call Reference IE encoder...\n\t%d bytes added: %s\n",
831 len, len == ARRAY_SIZE(res) ? "OK" : "FAIL");
832
833 if (!msgb_eq_data_print(msg, res, ARRAY_SIZE(res)))
834 abort();
835
836 rc = osmo_bssap_tlv_parse(&tp, msgb_data(msg), msgb_length(msg));
837 if (rc < 0) {
838 printf("parsing failed: %s [%s]\n", strerror(-rc), msgb_hexdump(msg));
839 abort();
840 }
841
Max3b901252019-01-15 14:15:11 +0100842 rc = gsm0808_dec_lcls(lcls_out, &tp);
Max969fb2e2018-12-10 11:01:10 +0100843 if (rc < 0) {
844 printf("decoding failed: %s [%s]\n", strerror(-rc), msgb_hexdump(msg));
845 abort();
846 }
847
Max3b901252019-01-15 14:15:11 +0100848 if (lcls_out->config != lcls_in.config) {
Max4fd64e52019-01-14 19:27:44 +0100849 printf("LCLS Config parsed wrong: %s != %s\n",
Max3b901252019-01-15 14:15:11 +0100850 gsm0808_lcls_config_name(lcls_out->config), gsm0808_lcls_config_name(lcls_in.config));
Max4fd64e52019-01-14 19:27:44 +0100851 abort();
852 }
853
Max3b901252019-01-15 14:15:11 +0100854 if (lcls_out->control != lcls_in.control) {
Max4fd64e52019-01-14 19:27:44 +0100855 printf("LCLS Control parsed wrong: %s != %s\n",
Max3b901252019-01-15 14:15:11 +0100856 gsm0808_lcls_control_name(lcls_out->control), gsm0808_lcls_control_name(lcls_in.control));
Max4fd64e52019-01-14 19:27:44 +0100857 abort();
858 }
859
Max3b901252019-01-15 14:15:11 +0100860 if (!osmo_gcr_eq(&lcls_out->gcr, &lcls_in.gcr)) {
Max5ec0cf52019-01-15 16:37:09 +0100861 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 +0100862 abort();
863 }
Max969fb2e2018-12-10 11:01:10 +0100864
Max5ec0cf52019-01-15 16:37:09 +0100865 printf("\tdecoded %d bytes: %s:\n%s\n", rc, rc == len ? "OK" : "FAIL", osmo_lcls_dump(lcls_out));
866 printf("\t%s\n", osmo_gcr_dump(lcls_out));
Max969fb2e2018-12-10 11:01:10 +0100867 msgb_free(msg);
868}
869
Harald Weltee61d4592022-11-03 11:05:58 +0100870static void test_enc_dec_aoip_trasp_addr_v4(void)
Philipp Maier22401432017-03-24 17:59:26 +0100871{
872 struct sockaddr_storage enc_addr;
873 struct sockaddr_storage dec_addr;
874 struct sockaddr_in enc_addr_in;
875 struct msgb *msg;
876 uint8_t rc_enc;
877 int rc_dec;
878
879 memset(&enc_addr_in, 0, sizeof(enc_addr_in));
880 enc_addr_in.sin_family = AF_INET;
881 enc_addr_in.sin_port = htons(1234);
882 inet_aton("255.0.255.255", &enc_addr_in.sin_addr);
883
884 memset(&enc_addr, 0, sizeof(enc_addr));
885 memcpy(&enc_addr, &enc_addr_in, sizeof(enc_addr_in));
886
887 msg = msgb_alloc(1024, "output buffer");
888 rc_enc = gsm0808_enc_aoip_trasp_addr(msg, &enc_addr);
889 OSMO_ASSERT(rc_enc == 8);
890 rc_dec =
891 gsm0808_dec_aoip_trasp_addr(&dec_addr, msg->data + 2, msg->len - 2);
892 OSMO_ASSERT(rc_dec == 6);
893 OSMO_ASSERT(memcmp(&enc_addr, &dec_addr, sizeof(enc_addr)) == 0);
894
895 msgb_free(msg);
896}
897
Harald Weltee61d4592022-11-03 11:05:58 +0100898static void test_enc_dec_aoip_trasp_addr_v6(void)
Philipp Maier22401432017-03-24 17:59:26 +0100899{
900 struct sockaddr_storage enc_addr;
901 struct sockaddr_storage dec_addr;
902 struct sockaddr_in6 enc_addr_in;
903 struct msgb *msg;
904 uint8_t rc_enc;
905 int rc_dec;
906
907 memset(&enc_addr_in, 0, sizeof(enc_addr_in));
908 enc_addr_in.sin6_family = AF_INET6;
909 enc_addr_in.sin6_port = htons(4567);
910 inet_pton(AF_INET6, "2001:0db8:85a3:08d3:1319:8a2e:0370:7344",
911 &enc_addr_in.sin6_addr);
912
913 memset(&enc_addr, 0, sizeof(enc_addr));
914 memcpy(&enc_addr, &enc_addr_in, sizeof(enc_addr_in));
915
916 msg = msgb_alloc(1024, "output buffer");
917 rc_enc = gsm0808_enc_aoip_trasp_addr(msg, &enc_addr);
918 OSMO_ASSERT(rc_enc == 20);
919 rc_dec =
920 gsm0808_dec_aoip_trasp_addr(&dec_addr, msg->data + 2, msg->len - 2);
921 OSMO_ASSERT(rc_dec == 18);
922 OSMO_ASSERT(memcmp(&enc_addr, &dec_addr, sizeof(enc_addr)) == 0);
923
924 msgb_free(msg);
925}
926
Harald Weltee61d4592022-11-03 11:05:58 +0100927static void test_enc_aoip_trasp_addr_msg_too_small(void)
Oliver Smithc66b35b2022-08-05 11:27:55 +0200928{
929 struct msgb *msg;
930 struct sockaddr_storage enc_addr;
931 struct sockaddr_in enc_addr_in;
932 uint8_t rc_enc;
933
934 memset(&enc_addr_in, 0, sizeof(enc_addr_in));
935 enc_addr_in.sin_family = AF_INET;
936 enc_addr_in.sin_port = htons(1234);
937 inet_aton("255.0.255.255", &enc_addr_in.sin_addr);
938
939 memset(&enc_addr, 0, sizeof(enc_addr));
940 memcpy(&enc_addr, &enc_addr_in, sizeof(enc_addr_in));
941
942 msg = msgb_alloc(7, "output buffer");
943 rc_enc = gsm0808_enc_aoip_trasp_addr(msg, &enc_addr);
944 OSMO_ASSERT(rc_enc == 0);
945
946 msgb_free(msg);
947}
948
Harald Weltee61d4592022-11-03 11:05:58 +0100949static void test_gsm0808_enc_dec_speech_codec(void)
Philipp Maier6f725d62017-03-24 18:03:17 +0100950{
Neels Hofmeyr9a4286b2018-04-20 12:27:52 +0200951 struct gsm0808_speech_codec enc_sc = {
952 .pi = true,
953 .tf = true,
954 .type = GSM0808_SCT_FR2,
955 };
956 struct gsm0808_speech_codec dec_sc = {};
Philipp Maier6f725d62017-03-24 18:03:17 +0100957 struct msgb *msg;
958 uint8_t rc_enc;
959 int rc_dec;
960
Philipp Maier6f725d62017-03-24 18:03:17 +0100961 msg = msgb_alloc(1024, "output buffer");
Vadim Yanitskiy6db830f2022-12-14 00:45:25 +0700962 rc_enc = gsm0808_enc_speech_codec2(msg, &enc_sc);
Philipp Maier6f725d62017-03-24 18:03:17 +0100963 OSMO_ASSERT(rc_enc == 3);
964
965 rc_dec = gsm0808_dec_speech_codec(&dec_sc, msg->data + 2, msg->len - 2);
966 OSMO_ASSERT(rc_dec == 1);
967
968 OSMO_ASSERT(memcmp(&enc_sc, &dec_sc, sizeof(enc_sc)) == 0);
969
970 msgb_free(msg);
971}
972
973
Harald Weltee61d4592022-11-03 11:05:58 +0100974static void test_gsm0808_enc_dec_speech_codec_with_cfg(void)
Philipp Maierbb839662017-06-01 17:11:19 +0200975{
Neels Hofmeyrc62c9342018-04-15 23:31:47 +0200976 struct gsm0808_speech_codec enc_sc = {
977 .pi = true,
978 .tf = true,
979 .type = GSM0808_SCT_FR3,
980 .cfg = 0xabcd,
981 };
982 struct gsm0808_speech_codec dec_sc = {};
Philipp Maierbb839662017-06-01 17:11:19 +0200983 struct msgb *msg;
984 uint8_t rc_enc;
985 int rc_dec;
986
Philipp Maierbb839662017-06-01 17:11:19 +0200987 msg = msgb_alloc(1024, "output buffer");
Vadim Yanitskiy6db830f2022-12-14 00:45:25 +0700988 rc_enc = gsm0808_enc_speech_codec2(msg, &enc_sc);
Philipp Maierbb839662017-06-01 17:11:19 +0200989 OSMO_ASSERT(rc_enc == 5);
990
991 rc_dec = gsm0808_dec_speech_codec(&dec_sc, msg->data + 2, msg->len - 2);
992 OSMO_ASSERT(rc_dec == 3);
993
994 OSMO_ASSERT(memcmp(&enc_sc, &dec_sc, sizeof(enc_sc)) == 0);
995
996 msgb_free(msg);
997}
998
Harald Weltee61d4592022-11-03 11:05:58 +0100999static void test_gsm0808_enc_dec_speech_codec_ext_with_cfg(void)
Philipp Maier6f725d62017-03-24 18:03:17 +01001000{
Neels Hofmeyr9a4286b2018-04-20 12:27:52 +02001001 struct gsm0808_speech_codec enc_sc = {
1002 .pi = true,
1003 .tf = true,
1004 .type = GSM0808_SCT_CSD,
1005 .cfg = 0xc0,
1006 };
1007 struct gsm0808_speech_codec dec_sc = {};
Philipp Maier6f725d62017-03-24 18:03:17 +01001008 struct msgb *msg;
1009 uint8_t rc_enc;
1010 int rc_dec;
1011
Philipp Maier6f725d62017-03-24 18:03:17 +01001012 msg = msgb_alloc(1024, "output buffer");
Vadim Yanitskiy6db830f2022-12-14 00:45:25 +07001013 rc_enc = gsm0808_enc_speech_codec2(msg, &enc_sc);
Philipp Maierbb839662017-06-01 17:11:19 +02001014 OSMO_ASSERT(rc_enc == 5);
Philipp Maier6f725d62017-03-24 18:03:17 +01001015
1016 rc_dec = gsm0808_dec_speech_codec(&dec_sc, msg->data + 2, msg->len - 2);
Philipp Maierbb839662017-06-01 17:11:19 +02001017 OSMO_ASSERT(rc_dec == 3);
Philipp Maier6f725d62017-03-24 18:03:17 +01001018
1019 OSMO_ASSERT(memcmp(&enc_sc, &dec_sc, sizeof(enc_sc)) == 0);
1020
1021 msgb_free(msg);
1022}
1023
Harald Weltee61d4592022-11-03 11:05:58 +01001024static void test_gsm0808_enc_dec_speech_codec_list(void)
Philipp Maier6f725d62017-03-24 18:03:17 +01001025{
Neels Hofmeyr9a4286b2018-04-20 12:27:52 +02001026 struct gsm0808_speech_codec_list enc_scl = {
1027 .codec = {
1028 {
1029 .pi = true,
1030 .tf = true,
1031 .type = GSM0808_SCT_FR3,
1032 .cfg = 0xcdef,
1033 },
1034
1035 {
1036 .fi = true,
1037 .pt = true,
1038 .type = GSM0808_SCT_FR2,
1039 },
1040
1041 {
1042 .fi = true,
1043 .tf = true,
1044 .type = GSM0808_SCT_CSD,
1045 .cfg = 0xc0,
1046 },
1047 },
1048 .len = 3,
1049 };
1050 struct gsm0808_speech_codec_list dec_scl = {};
Philipp Maier6f725d62017-03-24 18:03:17 +01001051 struct msgb *msg;
1052 uint8_t rc_enc;
1053 int rc_dec;
1054
Philipp Maier6f725d62017-03-24 18:03:17 +01001055 msg = msgb_alloc(1024, "output buffer");
Vadim Yanitskiy6db830f2022-12-14 00:45:25 +07001056 rc_enc = gsm0808_enc_speech_codec_list2(msg, &enc_scl);
Philipp Maier6f725d62017-03-24 18:03:17 +01001057 OSMO_ASSERT(rc_enc == 9);
1058
1059 rc_dec = gsm0808_dec_speech_codec_list(&dec_scl, msg->data + 2, msg->len - 2);
1060 OSMO_ASSERT(rc_dec == 7);
1061
1062 OSMO_ASSERT(memcmp(&enc_scl, &dec_scl, sizeof(enc_scl)) == 0);
1063
1064 msgb_free(msg);
1065}
1066
Harald Weltee61d4592022-11-03 11:05:58 +01001067static void test_gsm0808_enc_dec_empty_speech_codec_list(void)
Philipp Maierf6c369f2018-10-16 15:24:47 +02001068{
1069 struct gsm0808_speech_codec_list enc_scl = {
1070 .len = 0,
1071 };
1072 struct gsm0808_speech_codec_list dec_scl = {};
1073 struct msgb *msg;
1074 uint8_t rc_enc;
1075 int rc_dec;
1076
1077 msg = msgb_alloc(1024, "output buffer");
Vadim Yanitskiy6db830f2022-12-14 00:45:25 +07001078 rc_enc = gsm0808_enc_speech_codec_list2(msg, &enc_scl);
Philipp Maierf6c369f2018-10-16 15:24:47 +02001079 OSMO_ASSERT(rc_enc == 2);
1080
1081 rc_dec = gsm0808_dec_speech_codec_list(&dec_scl, msg->data + 2, msg->len - 2);
1082 OSMO_ASSERT(rc_dec == 0);
1083
1084 OSMO_ASSERT(memcmp(&enc_scl, &dec_scl, sizeof(enc_scl)) == 0);
1085
1086 msgb_free(msg);
1087}
1088
Harald Weltee61d4592022-11-03 11:05:58 +01001089static void test_gsm0808_enc_dec_channel_type(void)
Philipp Maiere0c65302017-03-28 17:05:40 +02001090{
Neels Hofmeyr9a4286b2018-04-20 12:27:52 +02001091 struct gsm0808_channel_type enc_ct = {
1092 .ch_indctr = GSM0808_CHAN_SPEECH,
1093 .ch_rate_type = GSM0808_SPEECH_HALF_PREF,
1094 .perm_spch = { GSM0808_PERM_FR3, GSM0808_PERM_HR3 },
1095 .perm_spch_len = 2,
1096 };
1097 struct gsm0808_channel_type dec_ct = {};
Philipp Maiere0c65302017-03-28 17:05:40 +02001098 struct msgb *msg;
1099 uint8_t ct_enc_expected[] = { GSM0808_IE_CHANNEL_TYPE,
1100 0x04, 0x01, 0x0b, 0xa1, 0x25
1101 };
1102 uint8_t rc_enc;
1103 int rc_dec;
1104
Philipp Maiere0c65302017-03-28 17:05:40 +02001105 msg = msgb_alloc(1024, "output buffer");
1106 rc_enc = gsm0808_enc_channel_type(msg, &enc_ct);
1107 OSMO_ASSERT(rc_enc == 6);
1108 OSMO_ASSERT(memcmp(ct_enc_expected, msg->data, msg->len) == 0);
1109
1110 rc_dec = gsm0808_dec_channel_type(&dec_ct, msg->data + 2, msg->len - 2);
1111 OSMO_ASSERT(rc_dec == 4);
Pau Espin Pedrol2605ffc2019-07-29 16:44:22 +02001112 OSMO_ASSERT(enc_ct.ch_indctr == dec_ct.ch_indctr);
1113 OSMO_ASSERT(enc_ct.ch_rate_type == dec_ct.ch_rate_type);
1114 OSMO_ASSERT(enc_ct.perm_spch_len == dec_ct.perm_spch_len);
1115 OSMO_ASSERT(memcmp(&enc_ct.perm_spch[0], &dec_ct.perm_spch[0], enc_ct.perm_spch_len) == 0);
Philipp Maiere0c65302017-03-28 17:05:40 +02001116
1117 msgb_free(msg);
1118}
1119
Harald Weltee61d4592022-11-03 11:05:58 +01001120static void test_gsm0808_enc_dec_encrypt_info(void)
Philipp Maier14e76b92017-03-28 18:36:52 +02001121{
Neels Hofmeyr9a4286b2018-04-20 12:27:52 +02001122 struct gsm0808_encrypt_info enc_ei = {
1123 .perm_algo = { GSM0808_ALG_ID_A5_0, GSM0808_ALG_ID_A5_1 },
1124 .perm_algo_len = 2,
1125 .key = { 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x23, 0x42, },
1126 .key_len = 8,
1127 };
1128 struct gsm0808_encrypt_info dec_ei = {};
Philipp Maier14e76b92017-03-28 18:36:52 +02001129 struct msgb *msg;
1130 uint8_t ei_enc_expected[] =
1131 { GSM0808_IE_ENCRYPTION_INFORMATION, 0x09, 0x03, 0xaa, 0xbb,
1132 0xcc, 0xdd, 0xee, 0xff, 0x23, 0x42
1133 };
1134 uint8_t rc_enc;
1135 int rc_dec;
1136
Philipp Maier14e76b92017-03-28 18:36:52 +02001137 msg = msgb_alloc(1024, "output buffer");
1138 rc_enc = gsm0808_enc_encrypt_info(msg, &enc_ei);
1139 OSMO_ASSERT(rc_enc == 11);
1140 OSMO_ASSERT(memcmp(ei_enc_expected, msg->data, msg->len) == 0);
1141
1142 rc_dec = gsm0808_dec_encrypt_info(&dec_ei, msg->data + 2, msg->len - 2);
1143 OSMO_ASSERT(rc_dec == 9);
1144
1145 OSMO_ASSERT(memcmp(&enc_ei, &dec_ei, sizeof(enc_ei)) == 0);
1146
1147 msgb_free(msg);
1148}
1149
Harald Weltee61d4592022-11-03 11:05:58 +01001150static void test_gsm0808_dec_cell_id_list_srvcc(void)
Harald Weltea87526d2022-02-15 20:06:16 +01001151{
1152 /* taken from a pcap file of a real-world 3rd party MSC (SYS#5838) */
1153 const uint8_t enc_cil[] = { 0x0b, 0x2, 0xf2, 0x10, 0x4e, 0x20, 0x15, 0xbe};
1154 struct gsm0808_cell_id_list2 dec_cil;
1155 int rc;
1156
1157 rc = gsm0808_dec_cell_id_list2(&dec_cil, enc_cil, sizeof(enc_cil));
Pau Espin Pedrolb5551ee2022-02-16 13:09:32 +01001158 OSMO_ASSERT(rc == sizeof(enc_cil));
1159 OSMO_ASSERT(dec_cil.id_discr = CELL_IDENT_SAI);
1160 OSMO_ASSERT(dec_cil.id_list_len = 1);
Harald Weltea87526d2022-02-15 20:06:16 +01001161}
1162
Harald Weltee61d4592022-11-03 11:05:58 +01001163static void test_gsm0808_enc_dec_cell_id_list_lac(void)
Philipp Maier783047e2017-03-29 11:35:50 +02001164{
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001165 struct gsm0808_cell_id_list2 enc_cil;
1166 struct gsm0808_cell_id_list2 dec_cil;
Philipp Maier783047e2017-03-29 11:35:50 +02001167 struct msgb *msg;
1168 uint8_t rc_enc;
1169 int rc_dec;
1170
1171 memset(&enc_cil, 0, sizeof(enc_cil));
1172 enc_cil.id_discr = CELL_IDENT_LAC;
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001173 enc_cil.id_list[0].lac = 0x0124;
Neels Hofmeyrdb2fa4e2018-04-13 04:11:20 +02001174 enc_cil.id_list[1].lac = 0xABCD;
1175 enc_cil.id_list[2].lac = 0x5678;
Philipp Maier783047e2017-03-29 11:35:50 +02001176 enc_cil.id_list_len = 3;
1177
1178 msg = msgb_alloc(1024, "output buffer");
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001179 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
Neels Hofmeyrdb2fa4e2018-04-13 04:11:20 +02001180 EXPECT_ENCODED("1a 07 05 01 24 ab cd 56 78");
Philipp Maier783047e2017-03-29 11:35:50 +02001181
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001182 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
Philipp Maier783047e2017-03-29 11:35:50 +02001183 OSMO_ASSERT(rc_dec == 7);
1184
1185 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
1186
1187 msgb_free(msg);
1188}
1189
Harald Weltee61d4592022-11-03 11:05:58 +01001190static void test_gsm0808_enc_dec_cell_id_list_single_lac(void)
Philipp Maier783047e2017-03-29 11:35:50 +02001191{
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001192 struct gsm0808_cell_id_list2 enc_cil;
1193 struct gsm0808_cell_id_list2 dec_cil;
Philipp Maier783047e2017-03-29 11:35:50 +02001194 struct msgb *msg;
1195 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x03,
1196 0x05, 0x23, 0x42
1197 };
1198 uint8_t rc_enc;
1199 int rc_dec;
1200
1201 memset(&enc_cil, 0, sizeof(enc_cil));
1202 enc_cil.id_discr = CELL_IDENT_LAC;
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001203 enc_cil.id_list[0].lac = 0x2342;
Philipp Maier783047e2017-03-29 11:35:50 +02001204 enc_cil.id_list_len = 1;
1205
1206 msg = msgb_alloc(1024, "output buffer");
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001207 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
Philipp Maier783047e2017-03-29 11:35:50 +02001208 OSMO_ASSERT(rc_enc == 5);
1209 OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0);
1210
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001211 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
Philipp Maier783047e2017-03-29 11:35:50 +02001212 OSMO_ASSERT(rc_dec == 3);
1213
1214 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
1215
1216 msgb_free(msg);
1217}
1218
Harald Weltee61d4592022-11-03 11:05:58 +01001219static void test_gsm0808_enc_dec_cell_id_list_multi_lac(void)
Stefan Sperlinge1a86742018-03-15 18:05:02 +01001220{
1221 struct gsm0808_cell_id_list2 enc_cil;
1222 struct gsm0808_cell_id_list2 dec_cil;
1223 struct msgb *msg;
1224 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x0b, 0x05,
1225 0x23, 0x42,
1226 0x24, 0x43,
1227 0x25, 0x44,
1228 0x26, 0x45,
1229 0x27, 0x46
1230 };
1231 uint8_t rc_enc;
1232 int rc_dec;
1233
1234 memset(&enc_cil, 0, sizeof(enc_cil));
1235 enc_cil.id_discr = CELL_IDENT_LAC;
1236 enc_cil.id_list[0].lac = 0x2342;
1237 enc_cil.id_list[1].lac = 0x2443;
1238 enc_cil.id_list[2].lac = 0x2544;
1239 enc_cil.id_list[3].lac = 0x2645;
1240 enc_cil.id_list[4].lac = 0x2746;
1241 enc_cil.id_list_len = 5;
1242
1243 msg = msgb_alloc(1024, "output buffer");
1244 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
1245 OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected));
1246 OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0);
1247
1248 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
1249 OSMO_ASSERT(rc_dec == msg->len - 2);
1250 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
1251
1252 msgb_free(msg);
1253}
1254
Harald Weltee61d4592022-11-03 11:05:58 +01001255static void test_gsm0808_enc_dec_cell_id_list_bss(void)
Philipp Maier783047e2017-03-29 11:35:50 +02001256{
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001257 struct gsm0808_cell_id_list2 enc_cil;
1258 struct gsm0808_cell_id_list2 dec_cil;
Philipp Maier783047e2017-03-29 11:35:50 +02001259 struct msgb *msg;
1260 uint8_t rc_enc;
1261 int rc_dec;
1262
1263 memset(&enc_cil, 0, sizeof(enc_cil));
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001264 enc_cil.id_discr = CELL_IDENT_BSS;
Philipp Maier783047e2017-03-29 11:35:50 +02001265
1266 msg = msgb_alloc(1024, "output buffer");
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001267 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
Philipp Maier783047e2017-03-29 11:35:50 +02001268 OSMO_ASSERT(rc_enc == 3);
1269
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001270 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
Philipp Maier783047e2017-03-29 11:35:50 +02001271 OSMO_ASSERT(rc_dec == 1);
1272
1273 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
1274
1275 msgb_free(msg);
1276}
1277
Harald Weltee61d4592022-11-03 11:05:58 +01001278static void test_gsm0808_enc_dec_cell_id_list_multi_lai_and_lac(void)
Stefan Sperling23381452018-03-15 19:38:15 +01001279{
1280 struct gsm0808_cell_id_list2 enc_cil;
1281 struct gsm0808_cell_id_list2 dec_cil;
1282 struct osmo_location_area_id id;
1283 struct msgb *msg;
1284 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x10, 0x04,
1285 0x92, 0x61, 0x54, 0x23, 0x42,
1286 0x92, 0x72, 0x54, 0x24, 0x43,
1287 0x92, 0x83, 0x54, 0x25, 0x44
1288 };
1289 uint8_t rc_enc;
1290 int rc_dec, i;
1291
1292 memset(&enc_cil, 0, sizeof(enc_cil));
1293 enc_cil.id_discr = CELL_IDENT_LAI_AND_LAC;
1294
1295 id.plmn.mcc = 0x123;
1296 osmo_mnc_from_str("456", &id.plmn.mnc, &id.plmn.mnc_3_digits);
1297 id.lac = 0x2342;
1298 memcpy(&enc_cil.id_list[0].lai_and_lac, &id, sizeof(id));
1299
1300 id.plmn.mcc = 0x124;
1301 osmo_mnc_from_str("457", &id.plmn.mnc, &id.plmn.mnc_3_digits);
1302 id.lac = 0x2443;
1303 memcpy(&enc_cil.id_list[1].lai_and_lac, &id, sizeof(id));
1304
1305 id.plmn.mcc = 0x125;
1306 osmo_mnc_from_str("458", &id.plmn.mnc, &id.plmn.mnc_3_digits);
1307 id.lac = 0x2544;
1308 memcpy(&enc_cil.id_list[2].lai_and_lac, &id, sizeof(id));
1309
1310 enc_cil.id_list_len = 3;
1311
1312 msg = msgb_alloc(1024, "output buffer");
1313 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
1314 OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected));
1315 OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0);
1316
1317 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
1318 OSMO_ASSERT(rc_dec == msg->len - 2);
1319
1320 OSMO_ASSERT(dec_cil.id_list_len == 3);
1321 /* Check MAXLEN elements to ensure everything has been initialized. */
1322 for (i = 0; i < GSM0808_CELL_ID_LIST2_MAXLEN; i++) {
1323 struct osmo_location_area_id *enc_id;
1324 struct osmo_location_area_id *dec_id;
1325 enc_id = &enc_cil.id_list[i].lai_and_lac;
1326 dec_id = &dec_cil.id_list[i].lai_and_lac;
1327 OSMO_ASSERT(osmo_plmn_cmp(&enc_id->plmn, &dec_id->plmn) == 0);
1328 OSMO_ASSERT(enc_id->lac == dec_id->lac);
1329 }
1330
1331 msgb_free(msg);
1332}
1333
Harald Weltee61d4592022-11-03 11:05:58 +01001334static void test_gsm0808_enc_dec_cell_id_list_multi_ci(void)
Stefan Sperling9c62fc62018-03-16 10:23:34 +01001335{
1336 struct gsm0808_cell_id_list2 enc_cil;
1337 struct gsm0808_cell_id_list2 dec_cil;
1338 struct msgb *msg;
1339 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x09, 0x02,
1340 0x00, 0x01,
1341 0x00, 0x02,
1342 0x00, 0x77,
1343 0x01, 0xff,
1344 };
1345 uint8_t rc_enc;
1346 int rc_dec;
1347
1348 memset(&enc_cil, 0, sizeof(enc_cil));
1349 enc_cil.id_discr = CELL_IDENT_CI;
1350 enc_cil.id_list[0].ci = 1;
1351 enc_cil.id_list[1].ci = 2;
1352 enc_cil.id_list[2].ci = 119;
1353 enc_cil.id_list[3].ci = 511;
1354 enc_cil.id_list_len = 4;
1355
1356 msg = msgb_alloc(1024, "output buffer");
1357 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
1358 OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected));
1359 OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0);
1360
1361 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
1362 OSMO_ASSERT(rc_dec == msg->len - 2);
1363 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
1364
1365 msgb_free(msg);
1366}
1367
Harald Weltee61d4592022-11-03 11:05:58 +01001368static void test_gsm0808_enc_dec_cell_id_list_multi_lac_and_ci(void)
Stefan Sperlinged4327c2018-03-16 11:02:59 +01001369{
1370 struct gsm0808_cell_id_list2 enc_cil;
1371 struct gsm0808_cell_id_list2 dec_cil;
1372 struct msgb *msg;
1373 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x15, 0x01,
1374 0x23, 0x42, 0x00, 0x01,
1375 0x24, 0x43, 0x00, 0x02,
1376 0x25, 0x44, 0x00, 0x77,
1377 0x26, 0x45, 0x01, 0xff,
1378 0x27, 0x46, 0x02, 0xfe,
1379 };
1380 uint8_t rc_enc;
1381 int rc_dec;
1382
1383 memset(&enc_cil, 0, sizeof(enc_cil));
1384 enc_cil.id_discr = CELL_IDENT_LAC_AND_CI;
1385 enc_cil.id_list[0].lac_and_ci.lac = 0x2342;
1386 enc_cil.id_list[0].lac_and_ci.ci = 1;
1387 enc_cil.id_list[1].lac_and_ci.lac = 0x2443;
1388 enc_cil.id_list[1].lac_and_ci.ci = 2;
1389 enc_cil.id_list[2].lac_and_ci.lac = 0x2544;
1390 enc_cil.id_list[2].lac_and_ci.ci = 119;
1391 enc_cil.id_list[3].lac_and_ci.lac = 0x2645;
1392 enc_cil.id_list[3].lac_and_ci.ci = 511;
1393 enc_cil.id_list[4].lac_and_ci.lac = 0x2746;
1394 enc_cil.id_list[4].lac_and_ci.ci = 766;
1395 enc_cil.id_list_len = 5;
1396
1397 msg = msgb_alloc(1024, "output buffer");
1398 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
1399 OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected));
1400 OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0);
1401
1402 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
1403 OSMO_ASSERT(rc_dec == msg->len - 2);
1404 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
1405
1406 msgb_free(msg);
1407}
1408
Harald Weltee61d4592022-11-03 11:05:58 +01001409static void test_gsm0808_enc_dec_cell_id_list_multi_global(void)
Stefan Sperling483f3862018-03-16 12:21:26 +01001410{
1411 struct gsm0808_cell_id_list2 enc_cil;
1412 struct gsm0808_cell_id_list2 dec_cil;
1413 struct msgb *msg;
1414 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x16, 0x00,
Neels Hofmeyr473485c2018-03-23 02:04:18 +01001415 0x21, 0x63, 0x54, 0x23, 0x42, 0x00, 0x1,
Neels Hofmeyrc44fc232018-03-23 02:15:12 +01001416 0x21, 0xf4, 0x75, 0x24, 0x43, 0x00, 0x2,
Neels Hofmeyr8b8cd932018-03-23 01:47:37 +01001417 0x21, 0x75, 0x00, 0x25, 0x44, 0x00, 0x77
Stefan Sperling483f3862018-03-16 12:21:26 +01001418 };
Stefan Sperling483f3862018-03-16 12:21:26 +01001419 uint8_t rc_enc;
1420 int rc_dec, i;
1421
Neels Hofmeyrc1991df2018-03-23 02:00:00 +01001422 enc_cil = (struct gsm0808_cell_id_list2){
1423 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1424 .id_list_len = 3,
1425 .id_list = {
1426 {
1427 .global = {
Neels Hofmeyr473485c2018-03-23 02:04:18 +01001428 .lai = { .plmn = { .mcc = 123, .mnc = 456 },
Neels Hofmeyrc1991df2018-03-23 02:00:00 +01001429 .lac = 0x2342 },
1430 .cell_identity = 1,
1431 }
1432 },
1433 {
1434 .global = {
Neels Hofmeyrc44fc232018-03-23 02:15:12 +01001435 .lai = { .plmn = { .mcc = 124, .mnc = 57 },
Neels Hofmeyrc1991df2018-03-23 02:00:00 +01001436 .lac = 0x2443 },
1437 .cell_identity = 2,
1438 }
1439 },
1440 {
1441 .global = {
Neels Hofmeyrc44fc232018-03-23 02:15:12 +01001442 .lai = { .plmn = { .mcc = 125, .mnc = 7,
1443 .mnc_3_digits = true },
Neels Hofmeyrc1991df2018-03-23 02:00:00 +01001444 .lac = 0x2544 },
1445 .cell_identity = 119,
1446 }
1447 },
1448 }
1449 };
Stefan Sperling483f3862018-03-16 12:21:26 +01001450
1451 msg = msgb_alloc(1024, "output buffer");
1452 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
1453 OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected));
Neels Hofmeyrc1991df2018-03-23 02:00:00 +01001454 if (memcmp(cil_enc_expected, msg->data, msg->len)) {
1455 printf(" got: %s\n", osmo_hexdump(msg->data, msg->len));
1456 printf("expect: %s\n", osmo_hexdump(cil_enc_expected, sizeof(cil_enc_expected)));
1457 OSMO_ASSERT(false);
1458 }
Stefan Sperling483f3862018-03-16 12:21:26 +01001459
1460 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
1461 OSMO_ASSERT(rc_dec == msg->len - 2);
1462
1463 /* Check MAXLEN elements to ensure everything has been initialized. */
1464 for (i = 0; i < GSM0808_CELL_ID_LIST2_MAXLEN; i++) {
1465 struct osmo_cell_global_id *enc_id;
1466 struct osmo_cell_global_id *dec_id;
1467 enc_id = &enc_cil.id_list[i].global;
1468 dec_id = &dec_cil.id_list[i].global;
1469 OSMO_ASSERT(osmo_plmn_cmp(&enc_id->lai.plmn, &dec_id->lai.plmn) == 0);
1470 OSMO_ASSERT(enc_id->lai.lac == dec_id->lai.lac);
1471 OSMO_ASSERT(enc_id->cell_identity == dec_id->cell_identity);
1472 }
1473
1474 msgb_free(msg);
1475}
1476
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001477static void print_cil(const struct gsm0808_cell_id_list2 *cil)
1478{
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001479 printf(" cell_id_list == %s\n", gsm0808_cell_id_list_name(cil));
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001480}
1481
Harald Weltee61d4592022-11-03 11:05:58 +01001482void test_cell_id_list_add(void) {
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001483 size_t zu;
1484
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001485 const struct gsm0808_cell_id_list2 cgi1 = {
1486 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1487 .id_list_len = 1,
1488 .id_list = {
1489 {
1490 .global = {
1491 .lai = {
1492 .plmn = { .mcc = 1, .mnc = 2, .mnc_3_digits = false },
1493 .lac = 3,
1494 },
1495 .cell_identity = 4,
1496 }
1497 },
1498 },
1499 };
1500
1501 const struct gsm0808_cell_id_list2 cgi2 = {
1502 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1503 .id_list_len = 2,
1504 .id_list = {
1505 {
1506 .global = {
1507 .lai = {
1508 .plmn = { .mcc = 1, .mnc = 2, .mnc_3_digits = true },
1509 .lac = 3,
1510 },
1511 .cell_identity = 4,
1512 }
1513 },
1514 {
1515 .global = {
1516 .lai = {
1517 .plmn = { .mcc = 5, .mnc = 6, .mnc_3_digits = true },
1518 .lac = 7,
1519 },
1520 .cell_identity = 8,
1521 }
1522 },
1523 },
1524 };
1525
1526 const struct gsm0808_cell_id_list2 cgi2a = {
1527 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1528 .id_list_len = 2,
1529 .id_list = {
1530 {
1531 .global = cgi2.id_list[0].global
1532 },
1533 {
1534 .global = {
1535 .lai = {
1536 .plmn = { .mcc = 9, .mnc = 10, .mnc_3_digits = true },
1537 .lac = 11,
1538 },
1539 .cell_identity = 12,
1540 }
1541 },
1542 },
1543 };
1544
1545 const struct gsm0808_cell_id_list2 cgi3 = {
1546 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1547 .id_list_len = 2,
1548 .id_list = {
1549 {
1550 .global = {
1551 .lai = {
1552 .plmn = { .mcc = 13, .mnc = 14, .mnc_3_digits = true },
1553 .lac = 15,
1554 },
1555 .cell_identity = 16,
1556 }
1557 },
1558 {
1559 .global = {
1560 .lai = {
1561 .plmn = { .mcc = 16, .mnc = 17, .mnc_3_digits = true },
1562 .lac = 18,
1563 },
1564 .cell_identity = 19,
1565 }
1566 },
1567 },
1568 };
1569
1570
1571 const struct gsm0808_cell_id_list2 lac1 = {
1572 .id_discr = CELL_IDENT_LAC,
1573 .id_list_len = 1,
1574 .id_list = {
1575 {
1576 .lac = 123
1577 },
1578 },
1579 };
1580
1581 const struct gsm0808_cell_id_list2 lac2 = {
1582 .id_discr = CELL_IDENT_LAC,
1583 .id_list_len = 2,
1584 .id_list = {
1585 {
1586 .lac = 456
1587 },
1588 {
1589 .lac = 789
1590 },
1591 },
1592 };
1593
1594 struct gsm0808_cell_id_list2 cil = {};
1595
1596 printf("------- %s\n", __func__);
1597
1598 print_cil(&cil);
1599
1600#define ADD_QUIET(other_cil, expect_rc) do { \
1601 int rc = gsm0808_cell_id_list_add(&cil, &other_cil); \
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001602 printf("gsm0808_cell_id_list_add(&cil, &" #other_cil ") --> rc = %d\n", rc); \
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001603 OSMO_ASSERT(rc == expect_rc); \
1604 } while(0)
1605
1606#define ADD(other_cil, expect_rc) ADD_QUIET(other_cil, expect_rc); print_cil(&cil)
1607
1608 ADD(lac1, 1);
1609 ADD(lac1, 0);
1610 ADD(lac2, 2);
1611 ADD(lac2, 0);
1612 ADD(cil, 0);
1613 ADD(cgi1, -EINVAL);
1614
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001615 printf("* can't add to BSS list\n");
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001616 cil.id_list_len = 0;
1617 cil.id_discr = CELL_IDENT_BSS;
1618 print_cil(&cil);
1619 ADD(lac1, -EINVAL);
1620
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001621 printf("* other types (including NO_CELL) take on new type iff empty\n");
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001622 cil.id_list_len = 0;
1623 cil.id_discr = CELL_IDENT_NO_CELL;
1624 print_cil(&cil);
1625 ADD(cgi1, 1);
1626 ADD(cgi1, 0);
1627 ADD(cgi2, 2);
1628 ADD(cgi2, 0);
1629
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001630 printf("* test gsm0808_cell_id_list_name_buf()'s return val\n");
1631 zu = strlen(gsm0808_cell_id_list_name(&cil));
1632 printf(" strlen(gsm0808_cell_id_list_name(cil)) == %zu\n", zu);
1633 zu ++;
1634 while (1) {
1635 char buf[128] = "?";
1636 int rc;
1637 OSMO_ASSERT(zu < sizeof(buf));
1638 buf[zu] = '#';
1639 rc = gsm0808_cell_id_list_name_buf(buf, zu, &cil);
1640 printf(" gsm0808_cell_id_list_name_buf(buf, %zu, cil)) == %d \"%s\"\n",
1641 zu, rc, buf);
1642 OSMO_ASSERT(buf[zu] == '#');
1643 if (!zu)
1644 break;
1645 zu /= 2;
1646 }
1647
1648 printf("* list-full behavior\n");
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001649 cil.id_list_len = GSM0808_CELL_ID_LIST2_MAXLEN - 1;
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001650 printf("cil.id_list_len = %u\n", cil.id_list_len);
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001651 ADD_QUIET(cgi2a, 1);
1652 printf("cil.id_list_len = %u\n", cil.id_list_len);
1653
1654 cil.id_list_len = GSM0808_CELL_ID_LIST2_MAXLEN - 1;
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001655 printf("cil.id_list_len = %u\n", cil.id_list_len);
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001656 ADD_QUIET(cgi3, -ENOSPC);
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001657 printf("cil.id_list_len = %u\n", cil.id_list_len);
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001658 ADD_QUIET(cgi2a, -ENOSPC);
1659 printf("cil.id_list_len = %u\n", cil.id_list_len);
1660
1661 printf("------- %s done\n", __func__);
1662}
1663
Harald Weltee61d4592022-11-03 11:05:58 +01001664static void test_gsm0808_enc_dec_cell_id_lac(void)
Neels Hofmeyr250e7f72018-04-13 03:30:14 +02001665{
1666 struct gsm0808_cell_id enc_ci = {
1667 .id_discr = CELL_IDENT_LAC,
1668 .id.lac = 0x0124,
1669 };
1670 struct gsm0808_cell_id dec_ci;
1671 struct msgb *msg;
1672 uint8_t rc_enc;
1673 int rc_dec;
1674
1675 memset(&dec_ci, 0xa5, sizeof(dec_ci));
1676
1677 msg = msgb_alloc(1024, "output buffer");
1678 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1679 EXPECT_ENCODED("05 03 05 01 24");
1680
1681 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1682 OSMO_ASSERT(rc_dec == 3);
1683
1684 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr
1685 && enc_ci.id.lac == dec_ci.id.lac);
1686
1687 msgb_free(msg);
1688}
1689
Harald Weltee61d4592022-11-03 11:05:58 +01001690static void test_gsm0808_enc_dec_cell_id_bss(void)
Neels Hofmeyr250e7f72018-04-13 03:30:14 +02001691{
1692 struct gsm0808_cell_id enc_ci = {
1693 .id_discr = CELL_IDENT_BSS,
1694 };
1695 struct gsm0808_cell_id dec_ci;
1696 struct msgb *msg;
1697 uint8_t rc_enc;
1698 int rc_dec;
1699
1700 msg = msgb_alloc(1024, "output buffer");
1701 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1702 EXPECT_ENCODED("05 01 06");
1703
1704 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1705 OSMO_ASSERT(rc_dec == 1);
1706
1707 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr);
1708
1709 msgb_free(msg);
1710}
1711
Harald Weltee61d4592022-11-03 11:05:58 +01001712static void test_gsm0808_enc_dec_cell_id_no_cell(void)
Neels Hofmeyr250e7f72018-04-13 03:30:14 +02001713{
1714 struct gsm0808_cell_id enc_ci = {
1715 .id_discr = CELL_IDENT_NO_CELL,
1716 };
1717 struct gsm0808_cell_id dec_ci;
1718 struct msgb *msg;
1719 uint8_t rc_enc;
1720 int rc_dec;
1721
1722 msg = msgb_alloc(1024, "output buffer");
1723 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1724 EXPECT_ENCODED("05 01 03");
1725
1726 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1727 OSMO_ASSERT(rc_dec == 1);
1728
1729 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr);
1730
1731 msgb_free(msg);
1732}
1733
Harald Weltee61d4592022-11-03 11:05:58 +01001734static void test_gsm0808_enc_dec_cell_id_lai_and_lac(void)
Neels Hofmeyr250e7f72018-04-13 03:30:14 +02001735{
1736 struct gsm0808_cell_id enc_ci = {
1737 .id_discr = CELL_IDENT_LAI_AND_LAC,
1738 .id.lai_and_lac = {
1739 .plmn = {
1740 .mcc = 123,
1741 .mnc = 456,
1742 },
1743 .lac = 0x2342,
1744 },
1745 };
1746 struct gsm0808_cell_id dec_ci;
1747 struct msgb *msg;
1748 uint8_t rc_enc;
1749 int rc_dec;
1750
1751 msg = msgb_alloc(1024, "output buffer");
1752 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1753 EXPECT_ENCODED("05 06 04 21 63 54 23 42");
1754
1755 memset(&dec_ci, 0xa5, sizeof(dec_ci));
1756 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1757 OSMO_ASSERT(rc_dec == msg->len - 2);
1758
1759 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr
1760 && osmo_plmn_cmp(&enc_ci.id.lai_and_lac.plmn, &dec_ci.id.lai_and_lac.plmn) == 0
1761 && enc_ci.id.lai_and_lac.lac == dec_ci.id.lai_and_lac.lac);
1762 msgb_free(msg);
1763}
1764
Harald Weltee61d4592022-11-03 11:05:58 +01001765static void test_gsm0808_enc_dec_cell_id_ci(void)
Neels Hofmeyr250e7f72018-04-13 03:30:14 +02001766{
1767 struct gsm0808_cell_id enc_ci = {
1768 .id_discr = CELL_IDENT_CI,
1769 .id.ci = 0x423,
1770 };
1771 struct gsm0808_cell_id dec_ci;
1772 struct msgb *msg;
1773 uint8_t rc_enc;
1774 int rc_dec;
1775
1776 msg = msgb_alloc(1024, "output buffer");
1777 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1778 EXPECT_ENCODED("05 03 02 04 23");
1779
1780 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1781 OSMO_ASSERT(rc_dec == msg->len - 2);
1782 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr
1783 && enc_ci.id.ci == dec_ci.id.ci);
1784
1785 msgb_free(msg);
1786}
1787
Harald Weltee61d4592022-11-03 11:05:58 +01001788static void test_gsm0808_enc_dec_cell_id_lac_and_ci(void)
Neels Hofmeyr250e7f72018-04-13 03:30:14 +02001789{
1790 struct gsm0808_cell_id enc_ci = {
1791 .id_discr = CELL_IDENT_LAC_AND_CI,
1792 .id.lac_and_ci = {
1793 .lac = 0x423,
1794 .ci = 0x235,
1795 },
1796 };
1797 struct gsm0808_cell_id dec_ci;
1798 struct msgb *msg;
1799 uint8_t rc_enc;
1800 int rc_dec;
1801
1802 msg = msgb_alloc(1024, "output buffer");
1803 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1804 EXPECT_ENCODED("05 05 01 04 23 02 35");
1805
1806 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1807 OSMO_ASSERT(rc_dec == msg->len - 2);
1808 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr
1809 && enc_ci.id.lac_and_ci.lac == dec_ci.id.lac_and_ci.lac
1810 && enc_ci.id.lac_and_ci.ci == dec_ci.id.lac_and_ci.ci);
1811
1812 msgb_free(msg);
1813}
1814
Harald Weltee61d4592022-11-03 11:05:58 +01001815static void test_gsm0808_enc_dec_cell_id_global(void)
Neels Hofmeyr250e7f72018-04-13 03:30:14 +02001816{
1817 struct gsm0808_cell_id enc_ci = {
1818 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1819 .id.global = {
1820 .lai = {
1821 .plmn = { .mcc = 123, .mnc = 456 },
1822 .lac = 0x2342
1823 },
1824 .cell_identity = 0x423,
1825 }
1826 };
1827 struct gsm0808_cell_id dec_ci;
1828 struct msgb *msg;
1829 uint8_t rc_enc;
1830 int rc_dec;
1831
1832 msg = msgb_alloc(1024, "output buffer");
1833 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1834 EXPECT_ENCODED("05 08 00 21 63 54 23 42 04 23");
1835
1836 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1837 OSMO_ASSERT(rc_dec == msg->len - 2);
1838
1839 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr
1840 && osmo_plmn_cmp(&enc_ci.id.global.lai.plmn,
1841 &dec_ci.id.global.lai.plmn) == 0
1842 && enc_ci.id.global.lai.lac == dec_ci.id.global.lai.lac
1843 && enc_ci.id.global.cell_identity == dec_ci.id.global.cell_identity);
1844 msgb_free(msg);
1845}
1846
Harald Weltee61d4592022-11-03 11:05:58 +01001847static void test_gsm0808_enc_dec_cell_id_global_ps(void)
Pau Espin Pedrol52489852021-02-15 16:26:37 +01001848{
1849 struct gsm0808_cell_id enc_cgi = {
1850 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1851 .id.global = {
1852 .lai = {
1853 .plmn = { .mcc = 123, .mnc = 456 },
1854 .lac = 0x2342
1855 },
1856 .cell_identity = 0x423,
1857 }
1858 };
1859 struct gsm0808_cell_id enc_cgi_ps = {
1860 .id_discr = CELL_IDENT_WHOLE_GLOBAL_PS,
1861 .id.global_ps = {
1862 .rai = {
1863 .lac = {
1864 .plmn = { .mcc = 123, .mnc = 456 },
1865 .lac = 0x2342
1866 },
1867 .rac = 0xcc,
1868 },
1869 .cell_identity = 0x423,
1870 }
1871 };
1872 struct msgb *msg_cgi, *msg_cgi_ps;
1873 uint8_t rc_enc;
1874
1875 msg_cgi = msgb_alloc(1024, "output buffer (CGI)");
1876 rc_enc = gsm0808_enc_cell_id(msg_cgi, &enc_cgi);
1877 OSMO_ASSERT(rc_enc > 0);
1878
1879 msg_cgi_ps = msgb_alloc(1024, "output buffer (CGI-PS)");
1880 rc_enc = gsm0808_enc_cell_id(msg_cgi_ps, &enc_cgi_ps);
1881 OSMO_ASSERT(rc_enc > 0);
1882
1883 OSMO_ASSERT(msgb_eq(msg_cgi, msg_cgi_ps));
1884
1885 msgb_free(msg_cgi);
1886 msgb_free(msg_cgi_ps);
1887}
1888
Philipp Maier5f2eb152018-09-19 13:40:21 +02001889static void test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(struct gsm48_multi_rate_conf *cfg)
1890{
1891 uint16_t s15_s0;
1892
1893 printf("Input:\n");
1894 printf(" m4_75= %u smod= %u\n", cfg->m4_75, cfg->smod);
1895 printf(" m5_15= %u spare= %u\n", cfg->m5_15, cfg->spare);
1896 printf(" m5_90= %u icmi= %u\n", cfg->m5_90, cfg->icmi);
1897 printf(" m6_70= %u nscb= %u\n", cfg->m6_70, cfg->nscb);
1898 printf(" m7_40= %u ver= %u\n", cfg->m7_40, cfg->ver);
1899 printf(" m7_95= %u\n", cfg->m7_95);
1900 printf(" m10_2= %u\n", cfg->m10_2);
1901 printf(" m12_2= %u\n", cfg->m12_2);
1902
1903 s15_s0 = gsm0808_sc_cfg_from_gsm48_mr_cfg(cfg, true);
1904 printf("Result (fr):\n");
1905 printf(" S15-S0 = %04x = 0b" OSMO_BIN_SPEC OSMO_BIN_SPEC "\n", s15_s0,
1906 OSMO_BIN_PRINT(s15_s0 >> 8), OSMO_BIN_PRINT(s15_s0));
1907
1908 s15_s0 = gsm0808_sc_cfg_from_gsm48_mr_cfg(cfg, false);
1909 printf("Result (hr):\n");
1910 printf(" S15-S0 = %04x = 0b" OSMO_BIN_SPEC OSMO_BIN_SPEC "\n", s15_s0,
1911 OSMO_BIN_PRINT(s15_s0 >> 8), OSMO_BIN_PRINT(s15_s0));
1912
1913 printf("\n");
1914}
1915
1916static void test_gsm0808_sc_cfg_from_gsm48_mr_cfg(void)
1917{
1918 struct gsm48_multi_rate_conf cfg;
1919
1920 printf("Testing gsm0808_sc_cfg_from_gsm48_mr_cfg():\n");
1921
1922 memset(&cfg, 0, sizeof(cfg));
1923
1924 cfg.m4_75 = 0;
1925 cfg.m5_15 = 0;
1926 cfg.m5_90 = 0;
1927 cfg.m6_70 = 0;
1928 cfg.m7_40 = 0;
1929 cfg.m7_95 = 0;
1930 cfg.m10_2 = 0;
1931 cfg.m12_2 = 0;
1932 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1933
1934 cfg.m4_75 = 1;
1935 cfg.m5_15 = 0;
1936 cfg.m5_90 = 0;
1937 cfg.m6_70 = 0;
1938 cfg.m7_40 = 0;
1939 cfg.m7_95 = 0;
1940 cfg.m10_2 = 0;
1941 cfg.m12_2 = 0;
1942 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1943
1944 cfg.m4_75 = 0;
1945 cfg.m5_15 = 1;
1946 cfg.m5_90 = 0;
1947 cfg.m6_70 = 0;
1948 cfg.m7_40 = 0;
1949 cfg.m7_95 = 0;
1950 cfg.m10_2 = 0;
1951 cfg.m12_2 = 0;
1952 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1953
1954 cfg.m4_75 = 0;
1955 cfg.m5_15 = 0;
1956 cfg.m5_90 = 1;
1957 cfg.m6_70 = 0;
1958 cfg.m7_40 = 0;
1959 cfg.m7_95 = 0;
1960 cfg.m10_2 = 0;
1961 cfg.m12_2 = 0;
1962 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1963
1964 cfg.m4_75 = 0;
1965 cfg.m5_15 = 0;
1966 cfg.m5_90 = 0;
1967 cfg.m6_70 = 1;
1968 cfg.m7_40 = 0;
1969 cfg.m7_95 = 0;
1970 cfg.m10_2 = 0;
1971 cfg.m12_2 = 0;
1972 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1973
1974 cfg.m4_75 = 0;
1975 cfg.m5_15 = 0;
1976 cfg.m5_90 = 0;
1977 cfg.m6_70 = 0;
1978 cfg.m7_40 = 1;
1979 cfg.m7_95 = 0;
1980 cfg.m10_2 = 0;
1981 cfg.m12_2 = 0;
1982 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1983
1984 cfg.m4_75 = 0;
1985 cfg.m5_15 = 0;
1986 cfg.m5_90 = 0;
1987 cfg.m6_70 = 0;
1988 cfg.m7_40 = 0;
1989 cfg.m7_95 = 1;
1990 cfg.m10_2 = 0;
1991 cfg.m12_2 = 0;
1992 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1993
1994 cfg.m4_75 = 0;
1995 cfg.m5_15 = 0;
1996 cfg.m5_90 = 0;
1997 cfg.m6_70 = 0;
1998 cfg.m7_40 = 0;
1999 cfg.m7_95 = 0;
2000 cfg.m10_2 = 1;
2001 cfg.m12_2 = 0;
2002 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
2003
2004 cfg.m4_75 = 0;
2005 cfg.m5_15 = 0;
2006 cfg.m5_90 = 0;
2007 cfg.m6_70 = 0;
2008 cfg.m7_40 = 0;
2009 cfg.m7_95 = 0;
2010 cfg.m10_2 = 0;
2011 cfg.m12_2 = 1;
2012 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
2013
2014 cfg.m4_75 = 1;
2015 cfg.m5_15 = 1;
2016 cfg.m5_90 = 1;
2017 cfg.m6_70 = 1;
2018 cfg.m7_40 = 0;
2019 cfg.m7_95 = 0;
2020 cfg.m10_2 = 0;
2021 cfg.m12_2 = 0;
2022 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
2023
2024 cfg.m4_75 = 0;
2025 cfg.m5_15 = 0;
2026 cfg.m5_90 = 0;
2027 cfg.m6_70 = 0;
2028 cfg.m7_40 = 1;
2029 cfg.m7_95 = 1;
2030 cfg.m10_2 = 1;
2031 cfg.m12_2 = 1;
2032 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
2033
2034 cfg.m4_75 = 0;
2035 cfg.m5_15 = 0;
2036 cfg.m5_90 = 1;
2037 cfg.m6_70 = 1;
2038 cfg.m7_40 = 0;
2039 cfg.m7_95 = 0;
2040 cfg.m10_2 = 1;
2041 cfg.m12_2 = 1;
2042 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
2043
2044 cfg.m4_75 = 1;
2045 cfg.m5_15 = 1;
2046 cfg.m5_90 = 0;
2047 cfg.m6_70 = 0;
2048 cfg.m7_40 = 1;
2049 cfg.m7_95 = 1;
2050 cfg.m10_2 = 0;
2051 cfg.m12_2 = 0;
2052 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
2053
2054 cfg.m4_75 = 0;
2055 cfg.m5_15 = 1;
2056 cfg.m5_90 = 0;
2057 cfg.m6_70 = 1;
2058 cfg.m7_40 = 0;
2059 cfg.m7_95 = 1;
2060 cfg.m10_2 = 0;
2061 cfg.m12_2 = 1;
2062 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
2063
2064 cfg.m4_75 = 1;
2065 cfg.m5_15 = 0;
2066 cfg.m5_90 = 1;
2067 cfg.m6_70 = 0;
2068 cfg.m7_40 = 1;
2069 cfg.m7_95 = 0;
2070 cfg.m10_2 = 1;
2071 cfg.m12_2 = 0;
2072 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
2073
2074 cfg.m4_75 = 1;
2075 cfg.m5_15 = 1;
2076 cfg.m5_90 = 1;
2077 cfg.m6_70 = 1;
2078 cfg.m7_40 = 1;
2079 cfg.m7_95 = 1;
2080 cfg.m10_2 = 1;
2081 cfg.m12_2 = 1;
2082 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
Philipp Maier94d79fd2019-03-01 10:40:48 +01002083
2084 cfg.m4_75 = 1;
2085 cfg.m5_15 = 0;
2086 cfg.m5_90 = 1;
2087 cfg.m6_70 = 0;
2088 cfg.m7_40 = 1;
2089 cfg.m7_95 = 0;
2090 cfg.m10_2 = 0;
2091 cfg.m12_2 = 1;
2092 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
2093
2094 cfg.m4_75 = 1;
2095 cfg.m5_15 = 0;
2096 cfg.m5_90 = 1;
2097 cfg.m6_70 = 0;
2098 cfg.m7_40 = 1;
2099 cfg.m7_95 = 0;
2100 cfg.m10_2 = 0;
2101 cfg.m12_2 = 0;
2102 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
Pau Espin Pedrol1bd495a2021-02-15 16:15:59 +01002103
Philipp Maier5f2eb152018-09-19 13:40:21 +02002104}
2105
Philipp Maier8515d032018-09-25 15:57:49 +02002106static void test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single(uint16_t s15_s0)
2107{
2108 struct gsm48_multi_rate_conf cfg;
Philipp Maier3713af82019-02-27 16:48:25 +01002109 int rc;
Philipp Maier8515d032018-09-25 15:57:49 +02002110
2111 printf("Input:\n");
2112 printf(" S15-S0 = %04x = 0b" OSMO_BIN_SPEC OSMO_BIN_SPEC "\n", s15_s0,
2113 OSMO_BIN_PRINT(s15_s0 >> 8), OSMO_BIN_PRINT(s15_s0));
2114
Philipp Maier3713af82019-02-27 16:48:25 +01002115 rc = gsm48_mr_cfg_from_gsm0808_sc_cfg(&cfg, s15_s0);
Philipp Maier8515d032018-09-25 15:57:49 +02002116
2117 printf("Output:\n");
2118 printf(" m4_75= %u smod= %u\n", cfg.m4_75, cfg.smod);
2119 printf(" m5_15= %u spare= %u\n", cfg.m5_15, cfg.spare);
2120 printf(" m5_90= %u icmi= %u\n", cfg.m5_90, cfg.icmi);
2121 printf(" m6_70= %u nscb= %u\n", cfg.m6_70, cfg.nscb);
2122 printf(" m7_40= %u ver= %u\n", cfg.m7_40, cfg.ver);
2123 printf(" m7_95= %u\n", cfg.m7_95);
2124 printf(" m10_2= %u\n", cfg.m10_2);
2125 printf(" m12_2= %u\n", cfg.m12_2);
2126
Philipp Maier3713af82019-02-27 16:48:25 +01002127 if (rc != 0)
2128 printf(" Result invalid!\n");
2129
Philipp Maier8515d032018-09-25 15:57:49 +02002130 printf("\n");
2131}
2132
Harald Weltee61d4592022-11-03 11:05:58 +01002133void test_gsm48_mr_cfg_from_gsm0808_sc_cfg(void)
Philipp Maier8515d032018-09-25 15:57:49 +02002134{
2135 printf("Testing gsm48_mr_cfg_from_gsm0808_sc_cfg():\n");
2136
Philipp Maier3713af82019-02-27 16:48:25 +01002137 /* Test with settings as defined in 3GPP TS 28.062, Table 7.11.3.1.3-2,
2138 * (up to four codecs may become selected) */
Philipp Maier8515d032018-09-25 15:57:49 +02002139 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
2140 (GSM0808_SC_CFG_DEFAULT_AMR_4_75);
2141 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
2142 (GSM0808_SC_CFG_DEFAULT_AMR_5_15);
2143 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
2144 (GSM0808_SC_CFG_DEFAULT_AMR_5_90);
2145 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
2146 (GSM0808_SC_CFG_DEFAULT_AMR_6_70);
2147 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
2148 (GSM0808_SC_CFG_DEFAULT_AMR_7_40);
2149 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
2150 (GSM0808_SC_CFG_DEFAULT_AMR_7_95);
2151 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
2152 (GSM0808_SC_CFG_DEFAULT_AMR_10_2);
2153 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
2154 (GSM0808_SC_CFG_DEFAULT_AMR_12_2);
2155
Philipp Maier3713af82019-02-27 16:48:25 +01002156 /* Test with settings as defined in 3GPP TS 28.062, Table 7.11.3.1.3-2,
2157 * but pick only one distinctive setting at a time */
2158 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single(GSM0808_SC_CFG_AMR_4_75);
Philipp Maier8515d032018-09-25 15:57:49 +02002159 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
Philipp Maier3713af82019-02-27 16:48:25 +01002160 (GSM0808_SC_CFG_AMR_4_75_5_90_7_40_12_20);
2161 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single(GSM0808_SC_CFG_AMR_5_90);
2162 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single(GSM0808_SC_CFG_AMR_6_70);
2163 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single(GSM0808_SC_CFG_AMR_7_40);
2164 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single(GSM0808_SC_CFG_AMR_7_95);
2165 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single(GSM0808_SC_CFG_AMR_10_2);
2166 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single(GSM0808_SC_CFG_AMR_12_2);
2167
2168 /* Arbitrary, but valid combinations */
2169 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single(GSM0808_SC_CFG_AMR_7_40 |
2170 GSM0808_SC_CFG_AMR_6_70 |
2171 GSM0808_SC_CFG_AMR_10_2);
2172 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single(GSM0808_SC_CFG_AMR_7_95 |
2173 GSM0808_SC_CFG_AMR_4_75);
2174 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single(GSM0808_SC_CFG_AMR_5_90 |
2175 GSM0808_SC_CFG_AMR_12_2);
Philipp Maier8515d032018-09-25 15:57:49 +02002176 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
Philipp Maier3713af82019-02-27 16:48:25 +01002177 (GSM0808_SC_CFG_AMR_4_75_5_90_7_40_12_20 | GSM0808_SC_CFG_AMR_5_90 |
2178 GSM0808_SC_CFG_AMR_12_2);
2179
2180 /* Invalid combinations */
Philipp Maier8515d032018-09-25 15:57:49 +02002181 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
Philipp Maier3713af82019-02-27 16:48:25 +01002182 (GSM0808_SC_CFG_AMR_4_75_5_90_7_40_12_20 | GSM0808_SC_CFG_AMR_6_70);
2183 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single(GSM0808_SC_CFG_AMR_7_40 |
2184 GSM0808_SC_CFG_AMR_6_70 |
2185 GSM0808_SC_CFG_AMR_10_2 |
2186 GSM0808_SC_CFG_AMR_7_95 |
2187 GSM0808_SC_CFG_AMR_4_75);
2188 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single(0x0000);
2189 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single(0xffff);
Philipp Maier8515d032018-09-25 15:57:49 +02002190}
2191
Neels Hofmeyrd01ef752018-09-21 15:57:26 +02002192struct test_cell_id_matching_data {
2193 struct gsm0808_cell_id id;
2194 struct gsm0808_cell_id match_id;
2195 bool expect_match;
2196 bool expect_exact_match;
2197};
2198
2199#define lac_23 { .id_discr = CELL_IDENT_LAC, .id.lac = 23, }
2200#define lac_42 { .id_discr = CELL_IDENT_LAC, .id.lac = 42, }
2201#define ci_5 { .id_discr = CELL_IDENT_CI, .id.ci = 5, }
2202#define ci_6 { .id_discr = CELL_IDENT_CI, .id.ci = 6, }
2203#define lac_ci_23_5 { \
2204 .id_discr = CELL_IDENT_LAC_AND_CI, \
2205 .id.lac_and_ci = { .lac = 23, .ci = 5, }, \
2206 }
2207#define lac_ci_42_6 { \
2208 .id_discr = CELL_IDENT_LAC_AND_CI, \
2209 .id.lac_and_ci = { .lac = 42, .ci = 6, }, \
2210 }
2211#define lai_23_042_23 { \
2212 .id_discr = CELL_IDENT_LAI_AND_LAC, \
2213 .id.lai_and_lac = { .plmn = { .mcc = 23, .mnc = 42, .mnc_3_digits = true }, .lac = 23, }, \
2214 }
2215#define lai_23_042_42 { \
2216 .id_discr = CELL_IDENT_LAI_AND_LAC, \
2217 .id.lai_and_lac = { .plmn = { .mcc = 23, .mnc = 42, .mnc_3_digits = true }, .lac = 42, }, \
2218 }
2219#define lai_23_99_23 { \
2220 .id_discr = CELL_IDENT_LAI_AND_LAC, \
2221 .id.lai_and_lac = { .plmn = { .mcc = 23, .mnc = 99, .mnc_3_digits = false }, .lac = 23, }, \
2222 }
2223#define lai_23_42_23 { \
2224 .id_discr = CELL_IDENT_LAI_AND_LAC, \
2225 .id.lai_and_lac = { .plmn = { .mcc = 23, .mnc = 42, .mnc_3_digits = false }, .lac = 23, }, \
2226 }
2227#define cgi_23_042_23_5 { \
2228 .id_discr = CELL_IDENT_WHOLE_GLOBAL, \
2229 .id.global = { \
2230 .lai = { .plmn = { .mcc = 23, .mnc = 42, .mnc_3_digits = true }, .lac = 23, }, \
2231 .cell_identity = 5, \
2232 }, \
2233 }
2234#define cgi_23_042_42_6 { \
2235 .id_discr = CELL_IDENT_WHOLE_GLOBAL, \
2236 .id.global = { \
2237 .lai = { .plmn = { .mcc = 23, .mnc = 42, .mnc_3_digits = true }, .lac = 42, }, \
2238 .cell_identity = 6, \
2239 }, \
2240 }
2241#define cgi_23_99_23_5 { \
2242 .id_discr = CELL_IDENT_WHOLE_GLOBAL, \
2243 .id.global = { \
2244 .lai = { .plmn = { .mcc = 23, .mnc = 99, .mnc_3_digits = false }, .lac = 23, }, \
2245 .cell_identity = 5, \
2246 }, \
2247 }
2248
2249
2250static const struct test_cell_id_matching_data test_cell_id_matching_tests[] = {
2251 { .id = lac_23, .match_id = lac_23, .expect_match = true, .expect_exact_match = true },
2252 { .id = lac_23, .match_id = lac_42, .expect_match = false, .expect_exact_match = false },
2253 { .id = lac_23, .match_id = ci_5, .expect_match = true, .expect_exact_match = false },
2254 { .id = lac_23, .match_id = ci_6, .expect_match = true, .expect_exact_match = false },
2255 { .id = lac_23, .match_id = lac_ci_23_5, .expect_match = true, .expect_exact_match = false },
2256 { .id = lac_23, .match_id = lac_ci_42_6, .expect_match = false, .expect_exact_match = false },
2257 { .id = lac_23, .match_id = lai_23_042_23, .expect_match = true, .expect_exact_match = false },
2258 { .id = lac_23, .match_id = lai_23_042_42, .expect_match = false, .expect_exact_match = false },
2259 { .id = lac_23, .match_id = lai_23_99_23, .expect_match = true, .expect_exact_match = false },
2260 { .id = lac_23, .match_id = lai_23_42_23, .expect_match = true, .expect_exact_match = false },
2261 { .id = lac_23, .match_id = cgi_23_042_23_5, .expect_match = true, .expect_exact_match = false },
2262 { .id = lac_23, .match_id = cgi_23_042_42_6, .expect_match = false, .expect_exact_match = false },
2263 { .id = lac_23, .match_id = cgi_23_99_23_5, .expect_match = true, .expect_exact_match = false },
2264 { .id = ci_5, .match_id = lac_23, .expect_match = true, .expect_exact_match = false },
2265 { .id = ci_5, .match_id = lac_42, .expect_match = true, .expect_exact_match = false },
2266 { .id = ci_5, .match_id = ci_5, .expect_match = true, .expect_exact_match = true },
2267 { .id = ci_5, .match_id = ci_6, .expect_match = false, .expect_exact_match = false },
2268 { .id = ci_5, .match_id = lac_ci_23_5, .expect_match = true, .expect_exact_match = false },
2269 { .id = ci_5, .match_id = lac_ci_42_6, .expect_match = false, .expect_exact_match = false },
2270 { .id = ci_5, .match_id = lai_23_042_23, .expect_match = true, .expect_exact_match = false },
2271 { .id = ci_5, .match_id = lai_23_042_42, .expect_match = true, .expect_exact_match = false },
2272 { .id = ci_5, .match_id = lai_23_99_23, .expect_match = true, .expect_exact_match = false },
2273 { .id = ci_5, .match_id = lai_23_42_23, .expect_match = true, .expect_exact_match = false },
2274 { .id = ci_5, .match_id = cgi_23_042_23_5, .expect_match = true, .expect_exact_match = false },
2275 { .id = ci_5, .match_id = cgi_23_042_42_6, .expect_match = false, .expect_exact_match = false },
2276 { .id = ci_5, .match_id = cgi_23_99_23_5, .expect_match = true, .expect_exact_match = false },
2277 { .id = lac_ci_23_5, .match_id = lac_23, .expect_match = true, .expect_exact_match = false },
2278 { .id = lac_ci_23_5, .match_id = lac_42, .expect_match = false, .expect_exact_match = false },
2279 { .id = lac_ci_23_5, .match_id = ci_5, .expect_match = true, .expect_exact_match = false },
2280 { .id = lac_ci_23_5, .match_id = ci_6, .expect_match = false, .expect_exact_match = false },
2281 { .id = lac_ci_23_5, .match_id = lac_ci_23_5, .expect_match = true, .expect_exact_match = true },
2282 { .id = lac_ci_23_5, .match_id = lac_ci_42_6, .expect_match = false, .expect_exact_match = false },
2283 { .id = lac_ci_23_5, .match_id = lai_23_042_23, .expect_match = true, .expect_exact_match = false },
2284 { .id = lac_ci_23_5, .match_id = lai_23_042_42, .expect_match = false, .expect_exact_match = false },
2285 { .id = lac_ci_23_5, .match_id = lai_23_99_23, .expect_match = true, .expect_exact_match = false },
2286 { .id = lac_ci_23_5, .match_id = lai_23_42_23, .expect_match = true, .expect_exact_match = false },
2287 { .id = lac_ci_23_5, .match_id = cgi_23_042_23_5, .expect_match = true, .expect_exact_match = false },
2288 { .id = lac_ci_23_5, .match_id = cgi_23_042_42_6, .expect_match = false, .expect_exact_match = false },
2289 { .id = lac_ci_23_5, .match_id = cgi_23_99_23_5, .expect_match = true, .expect_exact_match = false },
2290 { .id = lai_23_042_23, .match_id = lac_23, .expect_match = true, .expect_exact_match = false },
2291 { .id = lai_23_042_23, .match_id = lac_42, .expect_match = false, .expect_exact_match = false },
2292 { .id = lai_23_042_23, .match_id = ci_5, .expect_match = true, .expect_exact_match = false },
2293 { .id = lai_23_042_23, .match_id = ci_6, .expect_match = true, .expect_exact_match = false },
2294 { .id = lai_23_042_23, .match_id = lac_ci_23_5, .expect_match = true, .expect_exact_match = false },
2295 { .id = lai_23_042_23, .match_id = lac_ci_42_6, .expect_match = false, .expect_exact_match = false },
2296 { .id = lai_23_042_23, .match_id = lai_23_042_23, .expect_match = true, .expect_exact_match = true },
2297 { .id = lai_23_042_23, .match_id = lai_23_042_42, .expect_match = false, .expect_exact_match = false },
2298 { .id = lai_23_042_23, .match_id = lai_23_99_23, .expect_match = false, .expect_exact_match = false },
2299 { .id = lai_23_042_23, .match_id = lai_23_42_23, .expect_match = false, .expect_exact_match = false },
2300 { .id = lai_23_042_23, .match_id = cgi_23_042_23_5, .expect_match = true, .expect_exact_match = false },
2301 { .id = lai_23_042_23, .match_id = cgi_23_042_42_6, .expect_match = false, .expect_exact_match = false },
2302 { .id = lai_23_042_23, .match_id = cgi_23_99_23_5, .expect_match = false, .expect_exact_match = false },
2303 { .id = cgi_23_042_23_5, .match_id = lac_23, .expect_match = true, .expect_exact_match = false },
2304 { .id = cgi_23_042_23_5, .match_id = lac_42, .expect_match = false, .expect_exact_match = false },
2305 { .id = cgi_23_042_23_5, .match_id = ci_5, .expect_match = true, .expect_exact_match = false },
2306 { .id = cgi_23_042_23_5, .match_id = ci_6, .expect_match = false, .expect_exact_match = false },
2307 { .id = cgi_23_042_23_5, .match_id = lac_ci_23_5, .expect_match = true, .expect_exact_match = false },
2308 { .id = cgi_23_042_23_5, .match_id = lac_ci_42_6, .expect_match = false, .expect_exact_match = false },
2309 { .id = cgi_23_042_23_5, .match_id = lai_23_042_23, .expect_match = true, .expect_exact_match = false },
2310 { .id = cgi_23_042_23_5, .match_id = lai_23_042_42, .expect_match = false, .expect_exact_match = false },
2311 { .id = cgi_23_042_23_5, .match_id = lai_23_99_23, .expect_match = false, .expect_exact_match = false },
2312 { .id = cgi_23_042_23_5, .match_id = lai_23_42_23, .expect_match = false, .expect_exact_match = false },
2313 { .id = cgi_23_042_23_5, .match_id = cgi_23_042_23_5, .expect_match = true, .expect_exact_match = true },
2314 { .id = cgi_23_042_23_5, .match_id = cgi_23_042_42_6, .expect_match = false, .expect_exact_match = false },
2315 { .id = cgi_23_042_23_5, .match_id = cgi_23_99_23_5, .expect_match = false, .expect_exact_match = false },
2316};
2317
Harald Weltee61d4592022-11-03 11:05:58 +01002318static void test_cell_id_matching(void)
Neels Hofmeyrd01ef752018-09-21 15:57:26 +02002319{
2320 int i;
2321 bool ok = true;
2322 printf("\n%s\n", __func__);
2323
2324 for (i = 0; i < ARRAY_SIZE(test_cell_id_matching_tests); i++) {
2325 const struct test_cell_id_matching_data *d = &test_cell_id_matching_tests[i];
2326 int exact_match;
2327
2328 for (exact_match = 0; exact_match < 2; exact_match++) {
2329 bool result;
2330 bool expect_result = exact_match ? d->expect_exact_match : d->expect_match;
2331
2332 result = gsm0808_cell_ids_match(&d->id, &d->match_id, (bool)exact_match);
2333
2334 printf("[%d] %s %s %s%s\n",
2335 i,
2336 gsm0808_cell_id_name(&d->id),
2337 gsm0808_cell_id_name2(&d->match_id),
2338 result ? "MATCH" : "don't match",
2339 exact_match ? " exactly" : "");
2340 if (result != expect_result) {
2341 printf(" ERROR: expected %s\n", d->expect_match ? "MATCH" : "no match");
2342 ok = false;
2343 }
2344 }
2345 }
2346
2347 OSMO_ASSERT(ok);
2348}
2349
2350static bool test_cell_id_list_matching_discrs(bool test_match,
2351 enum CELL_IDENT id_discr,
2352 enum CELL_IDENT list_discr)
2353{
2354 int i, j;
2355 const struct gsm0808_cell_id *id = NULL;
2356 struct gsm0808_cell_id_list2 list = {};
2357 int match_idx = -1;
2358 int result;
2359
2360 for (i = 0; i < ARRAY_SIZE(test_cell_id_matching_tests); i++) {
2361 const struct test_cell_id_matching_data *d = &test_cell_id_matching_tests[i];
2362 if (id_discr != d->id.id_discr)
2363 continue;
2364 id = &d->id;
2365 break;
2366 }
2367
2368 if (!id) {
2369 printf("Did not find any entry for %s\n", gsm0808_cell_id_discr_name(id_discr));
2370 return true;
2371 }
2372
2373 /* Collect those entries with exactly this id on the left, of type list_discr on the right.
2374 * Collect the mismatches first, for more interesting match indexes in the results. */
2375 for (j = 0; j < 2; j++) {
2376 bool collect_matches = (bool)j;
2377
2378 /* If we want to have a mismatching list, don't add any entries that match. */
2379 if (!test_match && collect_matches)
2380 continue;
2381
2382 for (i = 0; i < ARRAY_SIZE(test_cell_id_matching_tests); i++) {
2383 const struct test_cell_id_matching_data *d = &test_cell_id_matching_tests[i];
2384 struct gsm0808_cell_id_list2 add;
2385
2386 /* Ignore those with a different d->id */
2387 if (!gsm0808_cell_ids_match(&d->id, id, true))
2388 continue;
2389
2390 /* Ignore those with a different d->match_id discr */
2391 if (d->match_id.id_discr != list_discr)
2392 continue;
2393
2394 if (collect_matches != d->expect_match)
2395 continue;
2396
2397 if (match_idx < 0 && d->expect_match) {
2398 match_idx = list.id_list_len;
2399 }
2400
2401 gsm0808_cell_id_to_list(&add, &d->match_id);
2402 gsm0808_cell_id_list_add(&list, &add);
2403 }
2404 }
2405
2406 if (!list.id_list_len) {
2407 printf("%s vs. %s: No match_id entries to test %s\n",
2408 gsm0808_cell_id_name(id),
2409 gsm0808_cell_id_discr_name(list_discr),
2410 test_match ? "MATCH" : "mismatch");
2411 return true;
2412 }
2413
2414 result = gsm0808_cell_id_matches_list(id, &list, 0, false);
2415
2416 printf("%s and %s: ",
2417 gsm0808_cell_id_name(id),
2418 gsm0808_cell_id_list_name(&list));
2419 if (result >= 0)
2420 printf("MATCH at [%d]\n", result);
2421 else
2422 printf("mismatch\n");
2423
2424 if (test_match
2425 && (result < 0 || result != match_idx)) {
2426 printf(" ERROR: expected MATCH at %d\n", match_idx);
2427 return false;
2428 }
2429
2430 if (!test_match && result >= 0) {
2431 printf(" ERROR: expected mismatch\n");
2432 return false;
2433 }
2434
2435 return true;
2436}
2437
Neels Hofmeyr3a504532019-02-10 22:28:27 +01002438const enum CELL_IDENT cell_ident_discrs[] = {
2439 CELL_IDENT_LAC, CELL_IDENT_CI, CELL_IDENT_LAC_AND_CI, CELL_IDENT_LAI_AND_LAC,
2440 CELL_IDENT_WHOLE_GLOBAL,
2441};
2442
2443
Neels Hofmeyrd01ef752018-09-21 15:57:26 +02002444static void test_cell_id_list_matching(bool test_match)
2445{
2446 int i, j;
2447 bool ok = true;
2448
Neels Hofmeyrd01ef752018-09-21 15:57:26 +02002449 printf("\n%s(%s)\n", __func__, test_match ? "test match" : "test mismatch");
2450
2451 /* Autogenerate Cell ID lists from above dataset, which should match / not match. */
Neels Hofmeyr3a504532019-02-10 22:28:27 +01002452 for (i = 0; i < ARRAY_SIZE(cell_ident_discrs); i++) {
2453 for (j = 0; j < ARRAY_SIZE(cell_ident_discrs); j++)
Neels Hofmeyrd01ef752018-09-21 15:57:26 +02002454 if (!test_cell_id_list_matching_discrs(test_match,
Neels Hofmeyr3a504532019-02-10 22:28:27 +01002455 cell_ident_discrs[i], cell_ident_discrs[j]))
Neels Hofmeyrd01ef752018-09-21 15:57:26 +02002456 ok = false;
2457 }
2458
2459 OSMO_ASSERT(ok);
2460}
2461
Neels Hofmeyr3a504532019-02-10 22:28:27 +01002462
2463static const struct gsm0808_cell_id test_gsm0808_cell_id_to_from_cgi_data[] = {
2464 lac_23,
2465 lac_42,
2466 ci_5,
2467 ci_6,
2468 lac_ci_23_5,
2469 lac_ci_42_6,
2470 lai_23_042_23,
2471 lai_23_042_42,
2472 lai_23_99_23,
2473 lai_23_42_23,
2474 cgi_23_042_23_5,
2475 cgi_23_042_42_6,
2476 cgi_23_99_23_5,
2477 { .id_discr = CELL_IDENT_NO_CELL },
2478 { .id_discr = 423 },
2479};
2480
Harald Weltee61d4592022-11-03 11:05:58 +01002481static void test_gsm0808_cell_id_to_from_cgi(void)
Neels Hofmeyr3a504532019-02-10 22:28:27 +01002482{
2483 int i;
2484 int j;
2485
2486 printf("\n%s()\n", __func__);
2487
2488 for (i = 0; i < ARRAY_SIZE(test_gsm0808_cell_id_to_from_cgi_data); i++) {
2489 const struct gsm0808_cell_id *from_cid = &test_gsm0808_cell_id_to_from_cgi_data[i];
2490 struct osmo_cell_global_id cgi = {
2491 .lai = {
2492 .plmn = {
2493 .mcc = 777,
2494 .mnc = 7,
2495 .mnc_3_digits = true,
2496 },
2497 .lac = 7777,
2498 },
2499 .cell_identity = 7777,
2500 };
2501 struct gsm0808_cell_id cid = {};
2502 int rc;
2503
2504 rc = gsm0808_cell_id_to_cgi(&cgi, from_cid);
2505 printf("cid %s -> cgi %s", gsm0808_cell_id_name(from_cid), osmo_cgi_name(&cgi));
2506
2507 if (rc & OSMO_CGI_PART_PLMN)
2508 printf(" PLMN");
2509 if (rc & OSMO_CGI_PART_LAC)
2510 printf(" LAC");
2511 if (rc & OSMO_CGI_PART_CI)
2512 printf(" CI");
2513
2514 gsm0808_cell_id_from_cgi(&cid, from_cid->id_discr, &cgi);
2515 printf(" -> cid %s\n", gsm0808_cell_id_name(&cid));
2516 if (!gsm0808_cell_ids_match(from_cid, &cid, true))
2517 printf(" MISMATCH!\n");
2518
2519 for (j = 0; j < ARRAY_SIZE(cell_ident_discrs); j++) {
2520 enum CELL_IDENT discr = cell_ident_discrs[j];
2521
2522 gsm0808_cell_id_from_cgi(&cid, discr, &cgi);
2523 printf(" --> gsm0808_cell_id{%s} = %s\n", gsm0808_cell_id_discr_name(discr), gsm0808_cell_id_name(&cid));
2524 }
2525 }
2526}
2527
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002528int main(int argc, char **argv)
2529{
Max969fb2e2018-12-10 11:01:10 +01002530 void *ctx = talloc_named_const(NULL, 0, "gsm0808 test");
2531 msgb_talloc_ctx_init(ctx, 0);
2532 osmo_init_logging2(ctx, NULL);
2533
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002534 printf("Testing generation of GSM0808 messages\n");
Philipp Maier4f4905f2018-11-30 13:36:12 +01002535 test_gsm0808_enc_cause();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002536 test_create_layer3();
Philipp Maierfa896ab2017-03-27 16:55:32 +02002537 test_create_layer3_aoip();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002538 test_create_reset();
Philipp Maier15596e22017-04-05 17:55:27 +02002539 test_create_reset_ack();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002540 test_create_clear_command();
Harald Weltecf665fc2019-02-18 13:45:36 +01002541 test_create_clear_command2();
2542 test_create_clear_command2_csfb();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002543 test_create_clear_complete();
Philipp Maierb478dd32017-03-29 15:50:05 +02002544 test_create_cipher();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002545 test_create_cipher_complete();
2546 test_create_cipher_reject();
Maxed651d22018-11-07 15:25:05 +01002547 test_create_cipher_reject_ext();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002548 test_create_cm_u();
2549 test_create_sapi_reject();
Philipp Maierc6144a22017-03-29 17:53:43 +02002550 test_create_ass();
Max52074322018-11-30 10:44:07 +01002551 test_create_ass2();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002552 test_create_ass_compl();
Philipp Maierfa896ab2017-03-27 16:55:32 +02002553 test_create_ass_compl_aoip();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002554 test_create_ass_fail();
Philipp Maierfa896ab2017-03-27 16:55:32 +02002555 test_create_ass_fail_aoip();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002556 test_create_clear_rqst();
Philipp Maier3d48ec02017-03-29 17:37:55 +02002557 test_create_paging();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002558 test_create_dtap();
2559 test_prepend_dtap();
Max969fb2e2018-12-10 11:01:10 +01002560
Max47022152018-12-19 18:51:00 +01002561 test_enc_dec_lcls();
Max969fb2e2018-12-10 11:01:10 +01002562
Philipp Maier22401432017-03-24 17:59:26 +01002563 test_enc_dec_aoip_trasp_addr_v4();
2564 test_enc_dec_aoip_trasp_addr_v6();
Oliver Smithc66b35b2022-08-05 11:27:55 +02002565 test_enc_aoip_trasp_addr_msg_too_small();
Philipp Maier6f725d62017-03-24 18:03:17 +01002566 test_gsm0808_enc_dec_speech_codec();
Philipp Maier6f725d62017-03-24 18:03:17 +01002567 test_gsm0808_enc_dec_speech_codec_ext_with_cfg();
Philipp Maierbb839662017-06-01 17:11:19 +02002568 test_gsm0808_enc_dec_speech_codec_with_cfg();
Philipp Maier6f725d62017-03-24 18:03:17 +01002569 test_gsm0808_enc_dec_speech_codec_list();
Philipp Maierf6c369f2018-10-16 15:24:47 +02002570 test_gsm0808_enc_dec_empty_speech_codec_list();
Philipp Maiere0c65302017-03-28 17:05:40 +02002571 test_gsm0808_enc_dec_channel_type();
Philipp Maier14e76b92017-03-28 18:36:52 +02002572 test_gsm0808_enc_dec_encrypt_info();
Neels Hofmeyr250e7f72018-04-13 03:30:14 +02002573
Philipp Maier783047e2017-03-29 11:35:50 +02002574 test_gsm0808_enc_dec_cell_id_list_lac();
2575 test_gsm0808_enc_dec_cell_id_list_single_lac();
Stefan Sperlinge1a86742018-03-15 18:05:02 +01002576 test_gsm0808_enc_dec_cell_id_list_multi_lac();
Philipp Maier783047e2017-03-29 11:35:50 +02002577 test_gsm0808_enc_dec_cell_id_list_bss();
Stefan Sperling23381452018-03-15 19:38:15 +01002578 test_gsm0808_enc_dec_cell_id_list_multi_lai_and_lac();
Stefan Sperling9c62fc62018-03-16 10:23:34 +01002579 test_gsm0808_enc_dec_cell_id_list_multi_ci();
Stefan Sperlinged4327c2018-03-16 11:02:59 +01002580 test_gsm0808_enc_dec_cell_id_list_multi_lac_and_ci();
Stefan Sperling483f3862018-03-16 12:21:26 +01002581 test_gsm0808_enc_dec_cell_id_list_multi_global();
Harald Weltea87526d2022-02-15 20:06:16 +01002582 test_gsm0808_dec_cell_id_list_srvcc();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002583
Neels Hofmeyr74663d92018-03-23 01:46:42 +01002584 test_cell_id_list_add();
2585
Neels Hofmeyr250e7f72018-04-13 03:30:14 +02002586 test_gsm0808_enc_dec_cell_id_lac();
2587 test_gsm0808_enc_dec_cell_id_bss();
2588 test_gsm0808_enc_dec_cell_id_no_cell();
2589 test_gsm0808_enc_dec_cell_id_lai_and_lac();
2590 test_gsm0808_enc_dec_cell_id_ci();
2591 test_gsm0808_enc_dec_cell_id_lac_and_ci();
2592 test_gsm0808_enc_dec_cell_id_global();
Pau Espin Pedrol52489852021-02-15 16:26:37 +01002593 test_gsm0808_enc_dec_cell_id_global_ps();
Philipp Maier5f2eb152018-09-19 13:40:21 +02002594 test_gsm0808_sc_cfg_from_gsm48_mr_cfg();
Philipp Maier8515d032018-09-25 15:57:49 +02002595 test_gsm48_mr_cfg_from_gsm0808_sc_cfg();
Philipp Maier5f2eb152018-09-19 13:40:21 +02002596
Neels Hofmeyrd01ef752018-09-21 15:57:26 +02002597 test_cell_id_matching();
2598 test_cell_id_list_matching(true);
2599 test_cell_id_list_matching(false);
2600
Neels Hofmeyr3a504532019-02-10 22:28:27 +01002601 test_gsm0808_cell_id_to_from_cgi();
2602
Alexander Chemeris22630e62020-05-13 00:44:04 +03002603 test_dec_confusion();
Pau Espin Pedrola3987fc2022-03-18 13:17:28 +01002604 test_dec_perform_location_report_sys5891();
Alexander Chemeris22630e62020-05-13 00:44:04 +03002605
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002606 printf("Done\n");
2607 return EXIT_SUCCESS;
2608}