blob: f68d560449db4190c89ec87ca1f2426d8a98e24e [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
Oliver Smith81e5a6f2023-01-31 12:34:26 +01001120static void test_gsm0808_dec_channel_type_err(void)
1121{
1122 struct gsm0808_channel_type ct;
1123 int rc;
1124
1125 /* Speech: extension bit is set in last byte */
1126 const uint8_t hex[] = { 0x01, 0x0b, 0xa1, 0xa5 };
1127 rc = gsm0808_dec_channel_type(&ct, hex, sizeof(hex));
1128 OSMO_ASSERT(rc == -EOVERFLOW);
1129}
1130
Harald Weltee61d4592022-11-03 11:05:58 +01001131static void test_gsm0808_enc_dec_encrypt_info(void)
Philipp Maier14e76b92017-03-28 18:36:52 +02001132{
Neels Hofmeyr9a4286b2018-04-20 12:27:52 +02001133 struct gsm0808_encrypt_info enc_ei = {
1134 .perm_algo = { GSM0808_ALG_ID_A5_0, GSM0808_ALG_ID_A5_1 },
1135 .perm_algo_len = 2,
1136 .key = { 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x23, 0x42, },
1137 .key_len = 8,
1138 };
1139 struct gsm0808_encrypt_info dec_ei = {};
Philipp Maier14e76b92017-03-28 18:36:52 +02001140 struct msgb *msg;
1141 uint8_t ei_enc_expected[] =
1142 { GSM0808_IE_ENCRYPTION_INFORMATION, 0x09, 0x03, 0xaa, 0xbb,
1143 0xcc, 0xdd, 0xee, 0xff, 0x23, 0x42
1144 };
1145 uint8_t rc_enc;
1146 int rc_dec;
1147
Philipp Maier14e76b92017-03-28 18:36:52 +02001148 msg = msgb_alloc(1024, "output buffer");
1149 rc_enc = gsm0808_enc_encrypt_info(msg, &enc_ei);
1150 OSMO_ASSERT(rc_enc == 11);
1151 OSMO_ASSERT(memcmp(ei_enc_expected, msg->data, msg->len) == 0);
1152
1153 rc_dec = gsm0808_dec_encrypt_info(&dec_ei, msg->data + 2, msg->len - 2);
1154 OSMO_ASSERT(rc_dec == 9);
1155
1156 OSMO_ASSERT(memcmp(&enc_ei, &dec_ei, sizeof(enc_ei)) == 0);
1157
1158 msgb_free(msg);
1159}
1160
Harald Weltee61d4592022-11-03 11:05:58 +01001161static void test_gsm0808_dec_cell_id_list_srvcc(void)
Harald Weltea87526d2022-02-15 20:06:16 +01001162{
1163 /* taken from a pcap file of a real-world 3rd party MSC (SYS#5838) */
1164 const uint8_t enc_cil[] = { 0x0b, 0x2, 0xf2, 0x10, 0x4e, 0x20, 0x15, 0xbe};
1165 struct gsm0808_cell_id_list2 dec_cil;
1166 int rc;
1167
1168 rc = gsm0808_dec_cell_id_list2(&dec_cil, enc_cil, sizeof(enc_cil));
Pau Espin Pedrolb5551ee2022-02-16 13:09:32 +01001169 OSMO_ASSERT(rc == sizeof(enc_cil));
1170 OSMO_ASSERT(dec_cil.id_discr = CELL_IDENT_SAI);
1171 OSMO_ASSERT(dec_cil.id_list_len = 1);
Harald Weltea87526d2022-02-15 20:06:16 +01001172}
1173
Harald Weltee61d4592022-11-03 11:05:58 +01001174static void test_gsm0808_enc_dec_cell_id_list_lac(void)
Philipp Maier783047e2017-03-29 11:35:50 +02001175{
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001176 struct gsm0808_cell_id_list2 enc_cil;
1177 struct gsm0808_cell_id_list2 dec_cil;
Philipp Maier783047e2017-03-29 11:35:50 +02001178 struct msgb *msg;
1179 uint8_t rc_enc;
1180 int rc_dec;
1181
1182 memset(&enc_cil, 0, sizeof(enc_cil));
1183 enc_cil.id_discr = CELL_IDENT_LAC;
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001184 enc_cil.id_list[0].lac = 0x0124;
Neels Hofmeyrdb2fa4e2018-04-13 04:11:20 +02001185 enc_cil.id_list[1].lac = 0xABCD;
1186 enc_cil.id_list[2].lac = 0x5678;
Philipp Maier783047e2017-03-29 11:35:50 +02001187 enc_cil.id_list_len = 3;
1188
1189 msg = msgb_alloc(1024, "output buffer");
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001190 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
Neels Hofmeyrdb2fa4e2018-04-13 04:11:20 +02001191 EXPECT_ENCODED("1a 07 05 01 24 ab cd 56 78");
Philipp Maier783047e2017-03-29 11:35:50 +02001192
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001193 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
Philipp Maier783047e2017-03-29 11:35:50 +02001194 OSMO_ASSERT(rc_dec == 7);
1195
1196 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
1197
1198 msgb_free(msg);
1199}
1200
Harald Weltee61d4592022-11-03 11:05:58 +01001201static void test_gsm0808_enc_dec_cell_id_list_single_lac(void)
Philipp Maier783047e2017-03-29 11:35:50 +02001202{
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001203 struct gsm0808_cell_id_list2 enc_cil;
1204 struct gsm0808_cell_id_list2 dec_cil;
Philipp Maier783047e2017-03-29 11:35:50 +02001205 struct msgb *msg;
1206 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x03,
1207 0x05, 0x23, 0x42
1208 };
1209 uint8_t rc_enc;
1210 int rc_dec;
1211
1212 memset(&enc_cil, 0, sizeof(enc_cil));
1213 enc_cil.id_discr = CELL_IDENT_LAC;
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001214 enc_cil.id_list[0].lac = 0x2342;
Philipp Maier783047e2017-03-29 11:35:50 +02001215 enc_cil.id_list_len = 1;
1216
1217 msg = msgb_alloc(1024, "output buffer");
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001218 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
Philipp Maier783047e2017-03-29 11:35:50 +02001219 OSMO_ASSERT(rc_enc == 5);
1220 OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0);
1221
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001222 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
Philipp Maier783047e2017-03-29 11:35:50 +02001223 OSMO_ASSERT(rc_dec == 3);
1224
1225 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
1226
1227 msgb_free(msg);
1228}
1229
Harald Weltee61d4592022-11-03 11:05:58 +01001230static void test_gsm0808_enc_dec_cell_id_list_multi_lac(void)
Stefan Sperlinge1a86742018-03-15 18:05:02 +01001231{
1232 struct gsm0808_cell_id_list2 enc_cil;
1233 struct gsm0808_cell_id_list2 dec_cil;
1234 struct msgb *msg;
1235 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x0b, 0x05,
1236 0x23, 0x42,
1237 0x24, 0x43,
1238 0x25, 0x44,
1239 0x26, 0x45,
1240 0x27, 0x46
1241 };
1242 uint8_t rc_enc;
1243 int rc_dec;
1244
1245 memset(&enc_cil, 0, sizeof(enc_cil));
1246 enc_cil.id_discr = CELL_IDENT_LAC;
1247 enc_cil.id_list[0].lac = 0x2342;
1248 enc_cil.id_list[1].lac = 0x2443;
1249 enc_cil.id_list[2].lac = 0x2544;
1250 enc_cil.id_list[3].lac = 0x2645;
1251 enc_cil.id_list[4].lac = 0x2746;
1252 enc_cil.id_list_len = 5;
1253
1254 msg = msgb_alloc(1024, "output buffer");
1255 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
1256 OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected));
1257 OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0);
1258
1259 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
1260 OSMO_ASSERT(rc_dec == msg->len - 2);
1261 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
1262
1263 msgb_free(msg);
1264}
1265
Harald Weltee61d4592022-11-03 11:05:58 +01001266static void test_gsm0808_enc_dec_cell_id_list_bss(void)
Philipp Maier783047e2017-03-29 11:35:50 +02001267{
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001268 struct gsm0808_cell_id_list2 enc_cil;
1269 struct gsm0808_cell_id_list2 dec_cil;
Philipp Maier783047e2017-03-29 11:35:50 +02001270 struct msgb *msg;
1271 uint8_t rc_enc;
1272 int rc_dec;
1273
1274 memset(&enc_cil, 0, sizeof(enc_cil));
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001275 enc_cil.id_discr = CELL_IDENT_BSS;
Philipp Maier783047e2017-03-29 11:35:50 +02001276
1277 msg = msgb_alloc(1024, "output buffer");
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001278 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
Philipp Maier783047e2017-03-29 11:35:50 +02001279 OSMO_ASSERT(rc_enc == 3);
1280
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001281 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
Philipp Maier783047e2017-03-29 11:35:50 +02001282 OSMO_ASSERT(rc_dec == 1);
1283
1284 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
1285
1286 msgb_free(msg);
1287}
1288
Harald Weltee61d4592022-11-03 11:05:58 +01001289static void test_gsm0808_enc_dec_cell_id_list_multi_lai_and_lac(void)
Stefan Sperling23381452018-03-15 19:38:15 +01001290{
1291 struct gsm0808_cell_id_list2 enc_cil;
1292 struct gsm0808_cell_id_list2 dec_cil;
1293 struct osmo_location_area_id id;
1294 struct msgb *msg;
1295 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x10, 0x04,
1296 0x92, 0x61, 0x54, 0x23, 0x42,
1297 0x92, 0x72, 0x54, 0x24, 0x43,
1298 0x92, 0x83, 0x54, 0x25, 0x44
1299 };
1300 uint8_t rc_enc;
1301 int rc_dec, i;
1302
1303 memset(&enc_cil, 0, sizeof(enc_cil));
1304 enc_cil.id_discr = CELL_IDENT_LAI_AND_LAC;
1305
1306 id.plmn.mcc = 0x123;
1307 osmo_mnc_from_str("456", &id.plmn.mnc, &id.plmn.mnc_3_digits);
1308 id.lac = 0x2342;
1309 memcpy(&enc_cil.id_list[0].lai_and_lac, &id, sizeof(id));
1310
1311 id.plmn.mcc = 0x124;
1312 osmo_mnc_from_str("457", &id.plmn.mnc, &id.plmn.mnc_3_digits);
1313 id.lac = 0x2443;
1314 memcpy(&enc_cil.id_list[1].lai_and_lac, &id, sizeof(id));
1315
1316 id.plmn.mcc = 0x125;
1317 osmo_mnc_from_str("458", &id.plmn.mnc, &id.plmn.mnc_3_digits);
1318 id.lac = 0x2544;
1319 memcpy(&enc_cil.id_list[2].lai_and_lac, &id, sizeof(id));
1320
1321 enc_cil.id_list_len = 3;
1322
1323 msg = msgb_alloc(1024, "output buffer");
1324 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
1325 OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected));
1326 OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0);
1327
1328 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
1329 OSMO_ASSERT(rc_dec == msg->len - 2);
1330
1331 OSMO_ASSERT(dec_cil.id_list_len == 3);
1332 /* Check MAXLEN elements to ensure everything has been initialized. */
1333 for (i = 0; i < GSM0808_CELL_ID_LIST2_MAXLEN; i++) {
1334 struct osmo_location_area_id *enc_id;
1335 struct osmo_location_area_id *dec_id;
1336 enc_id = &enc_cil.id_list[i].lai_and_lac;
1337 dec_id = &dec_cil.id_list[i].lai_and_lac;
1338 OSMO_ASSERT(osmo_plmn_cmp(&enc_id->plmn, &dec_id->plmn) == 0);
1339 OSMO_ASSERT(enc_id->lac == dec_id->lac);
1340 }
1341
1342 msgb_free(msg);
1343}
1344
Harald Weltee61d4592022-11-03 11:05:58 +01001345static void test_gsm0808_enc_dec_cell_id_list_multi_ci(void)
Stefan Sperling9c62fc62018-03-16 10:23:34 +01001346{
1347 struct gsm0808_cell_id_list2 enc_cil;
1348 struct gsm0808_cell_id_list2 dec_cil;
1349 struct msgb *msg;
1350 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x09, 0x02,
1351 0x00, 0x01,
1352 0x00, 0x02,
1353 0x00, 0x77,
1354 0x01, 0xff,
1355 };
1356 uint8_t rc_enc;
1357 int rc_dec;
1358
1359 memset(&enc_cil, 0, sizeof(enc_cil));
1360 enc_cil.id_discr = CELL_IDENT_CI;
1361 enc_cil.id_list[0].ci = 1;
1362 enc_cil.id_list[1].ci = 2;
1363 enc_cil.id_list[2].ci = 119;
1364 enc_cil.id_list[3].ci = 511;
1365 enc_cil.id_list_len = 4;
1366
1367 msg = msgb_alloc(1024, "output buffer");
1368 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
1369 OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected));
1370 OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0);
1371
1372 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
1373 OSMO_ASSERT(rc_dec == msg->len - 2);
1374 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
1375
1376 msgb_free(msg);
1377}
1378
Harald Weltee61d4592022-11-03 11:05:58 +01001379static void test_gsm0808_enc_dec_cell_id_list_multi_lac_and_ci(void)
Stefan Sperlinged4327c2018-03-16 11:02:59 +01001380{
1381 struct gsm0808_cell_id_list2 enc_cil;
1382 struct gsm0808_cell_id_list2 dec_cil;
1383 struct msgb *msg;
1384 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x15, 0x01,
1385 0x23, 0x42, 0x00, 0x01,
1386 0x24, 0x43, 0x00, 0x02,
1387 0x25, 0x44, 0x00, 0x77,
1388 0x26, 0x45, 0x01, 0xff,
1389 0x27, 0x46, 0x02, 0xfe,
1390 };
1391 uint8_t rc_enc;
1392 int rc_dec;
1393
1394 memset(&enc_cil, 0, sizeof(enc_cil));
1395 enc_cil.id_discr = CELL_IDENT_LAC_AND_CI;
1396 enc_cil.id_list[0].lac_and_ci.lac = 0x2342;
1397 enc_cil.id_list[0].lac_and_ci.ci = 1;
1398 enc_cil.id_list[1].lac_and_ci.lac = 0x2443;
1399 enc_cil.id_list[1].lac_and_ci.ci = 2;
1400 enc_cil.id_list[2].lac_and_ci.lac = 0x2544;
1401 enc_cil.id_list[2].lac_and_ci.ci = 119;
1402 enc_cil.id_list[3].lac_and_ci.lac = 0x2645;
1403 enc_cil.id_list[3].lac_and_ci.ci = 511;
1404 enc_cil.id_list[4].lac_and_ci.lac = 0x2746;
1405 enc_cil.id_list[4].lac_and_ci.ci = 766;
1406 enc_cil.id_list_len = 5;
1407
1408 msg = msgb_alloc(1024, "output buffer");
1409 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
1410 OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected));
1411 OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0);
1412
1413 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
1414 OSMO_ASSERT(rc_dec == msg->len - 2);
1415 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
1416
1417 msgb_free(msg);
1418}
1419
Harald Weltee61d4592022-11-03 11:05:58 +01001420static void test_gsm0808_enc_dec_cell_id_list_multi_global(void)
Stefan Sperling483f3862018-03-16 12:21:26 +01001421{
1422 struct gsm0808_cell_id_list2 enc_cil;
1423 struct gsm0808_cell_id_list2 dec_cil;
1424 struct msgb *msg;
1425 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x16, 0x00,
Neels Hofmeyr473485c2018-03-23 02:04:18 +01001426 0x21, 0x63, 0x54, 0x23, 0x42, 0x00, 0x1,
Neels Hofmeyrc44fc232018-03-23 02:15:12 +01001427 0x21, 0xf4, 0x75, 0x24, 0x43, 0x00, 0x2,
Neels Hofmeyr8b8cd932018-03-23 01:47:37 +01001428 0x21, 0x75, 0x00, 0x25, 0x44, 0x00, 0x77
Stefan Sperling483f3862018-03-16 12:21:26 +01001429 };
Stefan Sperling483f3862018-03-16 12:21:26 +01001430 uint8_t rc_enc;
1431 int rc_dec, i;
1432
Neels Hofmeyrc1991df2018-03-23 02:00:00 +01001433 enc_cil = (struct gsm0808_cell_id_list2){
1434 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1435 .id_list_len = 3,
1436 .id_list = {
1437 {
1438 .global = {
Neels Hofmeyr473485c2018-03-23 02:04:18 +01001439 .lai = { .plmn = { .mcc = 123, .mnc = 456 },
Neels Hofmeyrc1991df2018-03-23 02:00:00 +01001440 .lac = 0x2342 },
1441 .cell_identity = 1,
1442 }
1443 },
1444 {
1445 .global = {
Neels Hofmeyrc44fc232018-03-23 02:15:12 +01001446 .lai = { .plmn = { .mcc = 124, .mnc = 57 },
Neels Hofmeyrc1991df2018-03-23 02:00:00 +01001447 .lac = 0x2443 },
1448 .cell_identity = 2,
1449 }
1450 },
1451 {
1452 .global = {
Neels Hofmeyrc44fc232018-03-23 02:15:12 +01001453 .lai = { .plmn = { .mcc = 125, .mnc = 7,
1454 .mnc_3_digits = true },
Neels Hofmeyrc1991df2018-03-23 02:00:00 +01001455 .lac = 0x2544 },
1456 .cell_identity = 119,
1457 }
1458 },
1459 }
1460 };
Stefan Sperling483f3862018-03-16 12:21:26 +01001461
1462 msg = msgb_alloc(1024, "output buffer");
1463 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
1464 OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected));
Neels Hofmeyrc1991df2018-03-23 02:00:00 +01001465 if (memcmp(cil_enc_expected, msg->data, msg->len)) {
1466 printf(" got: %s\n", osmo_hexdump(msg->data, msg->len));
1467 printf("expect: %s\n", osmo_hexdump(cil_enc_expected, sizeof(cil_enc_expected)));
1468 OSMO_ASSERT(false);
1469 }
Stefan Sperling483f3862018-03-16 12:21:26 +01001470
1471 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
1472 OSMO_ASSERT(rc_dec == msg->len - 2);
1473
1474 /* Check MAXLEN elements to ensure everything has been initialized. */
1475 for (i = 0; i < GSM0808_CELL_ID_LIST2_MAXLEN; i++) {
1476 struct osmo_cell_global_id *enc_id;
1477 struct osmo_cell_global_id *dec_id;
1478 enc_id = &enc_cil.id_list[i].global;
1479 dec_id = &dec_cil.id_list[i].global;
1480 OSMO_ASSERT(osmo_plmn_cmp(&enc_id->lai.plmn, &dec_id->lai.plmn) == 0);
1481 OSMO_ASSERT(enc_id->lai.lac == dec_id->lai.lac);
1482 OSMO_ASSERT(enc_id->cell_identity == dec_id->cell_identity);
1483 }
1484
1485 msgb_free(msg);
1486}
1487
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001488static void print_cil(const struct gsm0808_cell_id_list2 *cil)
1489{
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001490 printf(" cell_id_list == %s\n", gsm0808_cell_id_list_name(cil));
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001491}
1492
Harald Weltee61d4592022-11-03 11:05:58 +01001493void test_cell_id_list_add(void) {
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001494 size_t zu;
1495
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001496 const struct gsm0808_cell_id_list2 cgi1 = {
1497 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1498 .id_list_len = 1,
1499 .id_list = {
1500 {
1501 .global = {
1502 .lai = {
1503 .plmn = { .mcc = 1, .mnc = 2, .mnc_3_digits = false },
1504 .lac = 3,
1505 },
1506 .cell_identity = 4,
1507 }
1508 },
1509 },
1510 };
1511
1512 const struct gsm0808_cell_id_list2 cgi2 = {
1513 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1514 .id_list_len = 2,
1515 .id_list = {
1516 {
1517 .global = {
1518 .lai = {
1519 .plmn = { .mcc = 1, .mnc = 2, .mnc_3_digits = true },
1520 .lac = 3,
1521 },
1522 .cell_identity = 4,
1523 }
1524 },
1525 {
1526 .global = {
1527 .lai = {
1528 .plmn = { .mcc = 5, .mnc = 6, .mnc_3_digits = true },
1529 .lac = 7,
1530 },
1531 .cell_identity = 8,
1532 }
1533 },
1534 },
1535 };
1536
1537 const struct gsm0808_cell_id_list2 cgi2a = {
1538 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1539 .id_list_len = 2,
1540 .id_list = {
1541 {
1542 .global = cgi2.id_list[0].global
1543 },
1544 {
1545 .global = {
1546 .lai = {
1547 .plmn = { .mcc = 9, .mnc = 10, .mnc_3_digits = true },
1548 .lac = 11,
1549 },
1550 .cell_identity = 12,
1551 }
1552 },
1553 },
1554 };
1555
1556 const struct gsm0808_cell_id_list2 cgi3 = {
1557 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1558 .id_list_len = 2,
1559 .id_list = {
1560 {
1561 .global = {
1562 .lai = {
1563 .plmn = { .mcc = 13, .mnc = 14, .mnc_3_digits = true },
1564 .lac = 15,
1565 },
1566 .cell_identity = 16,
1567 }
1568 },
1569 {
1570 .global = {
1571 .lai = {
1572 .plmn = { .mcc = 16, .mnc = 17, .mnc_3_digits = true },
1573 .lac = 18,
1574 },
1575 .cell_identity = 19,
1576 }
1577 },
1578 },
1579 };
1580
1581
1582 const struct gsm0808_cell_id_list2 lac1 = {
1583 .id_discr = CELL_IDENT_LAC,
1584 .id_list_len = 1,
1585 .id_list = {
1586 {
1587 .lac = 123
1588 },
1589 },
1590 };
1591
1592 const struct gsm0808_cell_id_list2 lac2 = {
1593 .id_discr = CELL_IDENT_LAC,
1594 .id_list_len = 2,
1595 .id_list = {
1596 {
1597 .lac = 456
1598 },
1599 {
1600 .lac = 789
1601 },
1602 },
1603 };
1604
1605 struct gsm0808_cell_id_list2 cil = {};
1606
1607 printf("------- %s\n", __func__);
1608
1609 print_cil(&cil);
1610
1611#define ADD_QUIET(other_cil, expect_rc) do { \
1612 int rc = gsm0808_cell_id_list_add(&cil, &other_cil); \
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001613 printf("gsm0808_cell_id_list_add(&cil, &" #other_cil ") --> rc = %d\n", rc); \
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001614 OSMO_ASSERT(rc == expect_rc); \
1615 } while(0)
1616
1617#define ADD(other_cil, expect_rc) ADD_QUIET(other_cil, expect_rc); print_cil(&cil)
1618
1619 ADD(lac1, 1);
1620 ADD(lac1, 0);
1621 ADD(lac2, 2);
1622 ADD(lac2, 0);
1623 ADD(cil, 0);
1624 ADD(cgi1, -EINVAL);
1625
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001626 printf("* can't add to BSS list\n");
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001627 cil.id_list_len = 0;
1628 cil.id_discr = CELL_IDENT_BSS;
1629 print_cil(&cil);
1630 ADD(lac1, -EINVAL);
1631
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001632 printf("* other types (including NO_CELL) take on new type iff empty\n");
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001633 cil.id_list_len = 0;
1634 cil.id_discr = CELL_IDENT_NO_CELL;
1635 print_cil(&cil);
1636 ADD(cgi1, 1);
1637 ADD(cgi1, 0);
1638 ADD(cgi2, 2);
1639 ADD(cgi2, 0);
1640
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001641 printf("* test gsm0808_cell_id_list_name_buf()'s return val\n");
1642 zu = strlen(gsm0808_cell_id_list_name(&cil));
1643 printf(" strlen(gsm0808_cell_id_list_name(cil)) == %zu\n", zu);
1644 zu ++;
1645 while (1) {
1646 char buf[128] = "?";
1647 int rc;
1648 OSMO_ASSERT(zu < sizeof(buf));
1649 buf[zu] = '#';
1650 rc = gsm0808_cell_id_list_name_buf(buf, zu, &cil);
1651 printf(" gsm0808_cell_id_list_name_buf(buf, %zu, cil)) == %d \"%s\"\n",
1652 zu, rc, buf);
1653 OSMO_ASSERT(buf[zu] == '#');
1654 if (!zu)
1655 break;
1656 zu /= 2;
1657 }
1658
1659 printf("* list-full behavior\n");
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001660 cil.id_list_len = GSM0808_CELL_ID_LIST2_MAXLEN - 1;
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001661 printf("cil.id_list_len = %u\n", cil.id_list_len);
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001662 ADD_QUIET(cgi2a, 1);
1663 printf("cil.id_list_len = %u\n", cil.id_list_len);
1664
1665 cil.id_list_len = GSM0808_CELL_ID_LIST2_MAXLEN - 1;
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001666 printf("cil.id_list_len = %u\n", cil.id_list_len);
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001667 ADD_QUIET(cgi3, -ENOSPC);
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001668 printf("cil.id_list_len = %u\n", cil.id_list_len);
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001669 ADD_QUIET(cgi2a, -ENOSPC);
1670 printf("cil.id_list_len = %u\n", cil.id_list_len);
1671
1672 printf("------- %s done\n", __func__);
1673}
1674
Harald Weltee61d4592022-11-03 11:05:58 +01001675static void test_gsm0808_enc_dec_cell_id_lac(void)
Neels Hofmeyr250e7f72018-04-13 03:30:14 +02001676{
1677 struct gsm0808_cell_id enc_ci = {
1678 .id_discr = CELL_IDENT_LAC,
1679 .id.lac = 0x0124,
1680 };
1681 struct gsm0808_cell_id dec_ci;
1682 struct msgb *msg;
1683 uint8_t rc_enc;
1684 int rc_dec;
1685
1686 memset(&dec_ci, 0xa5, sizeof(dec_ci));
1687
1688 msg = msgb_alloc(1024, "output buffer");
1689 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1690 EXPECT_ENCODED("05 03 05 01 24");
1691
1692 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1693 OSMO_ASSERT(rc_dec == 3);
1694
1695 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr
1696 && enc_ci.id.lac == dec_ci.id.lac);
1697
1698 msgb_free(msg);
1699}
1700
Harald Weltee61d4592022-11-03 11:05:58 +01001701static void test_gsm0808_enc_dec_cell_id_bss(void)
Neels Hofmeyr250e7f72018-04-13 03:30:14 +02001702{
1703 struct gsm0808_cell_id enc_ci = {
1704 .id_discr = CELL_IDENT_BSS,
1705 };
1706 struct gsm0808_cell_id dec_ci;
1707 struct msgb *msg;
1708 uint8_t rc_enc;
1709 int rc_dec;
1710
1711 msg = msgb_alloc(1024, "output buffer");
1712 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1713 EXPECT_ENCODED("05 01 06");
1714
1715 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1716 OSMO_ASSERT(rc_dec == 1);
1717
1718 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr);
1719
1720 msgb_free(msg);
1721}
1722
Harald Weltee61d4592022-11-03 11:05:58 +01001723static void test_gsm0808_enc_dec_cell_id_no_cell(void)
Neels Hofmeyr250e7f72018-04-13 03:30:14 +02001724{
1725 struct gsm0808_cell_id enc_ci = {
1726 .id_discr = CELL_IDENT_NO_CELL,
1727 };
1728 struct gsm0808_cell_id dec_ci;
1729 struct msgb *msg;
1730 uint8_t rc_enc;
1731 int rc_dec;
1732
1733 msg = msgb_alloc(1024, "output buffer");
1734 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1735 EXPECT_ENCODED("05 01 03");
1736
1737 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1738 OSMO_ASSERT(rc_dec == 1);
1739
1740 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr);
1741
1742 msgb_free(msg);
1743}
1744
Harald Weltee61d4592022-11-03 11:05:58 +01001745static void test_gsm0808_enc_dec_cell_id_lai_and_lac(void)
Neels Hofmeyr250e7f72018-04-13 03:30:14 +02001746{
1747 struct gsm0808_cell_id enc_ci = {
1748 .id_discr = CELL_IDENT_LAI_AND_LAC,
1749 .id.lai_and_lac = {
1750 .plmn = {
1751 .mcc = 123,
1752 .mnc = 456,
1753 },
1754 .lac = 0x2342,
1755 },
1756 };
1757 struct gsm0808_cell_id dec_ci;
1758 struct msgb *msg;
1759 uint8_t rc_enc;
1760 int rc_dec;
1761
1762 msg = msgb_alloc(1024, "output buffer");
1763 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1764 EXPECT_ENCODED("05 06 04 21 63 54 23 42");
1765
1766 memset(&dec_ci, 0xa5, sizeof(dec_ci));
1767 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1768 OSMO_ASSERT(rc_dec == msg->len - 2);
1769
1770 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr
1771 && osmo_plmn_cmp(&enc_ci.id.lai_and_lac.plmn, &dec_ci.id.lai_and_lac.plmn) == 0
1772 && enc_ci.id.lai_and_lac.lac == dec_ci.id.lai_and_lac.lac);
1773 msgb_free(msg);
1774}
1775
Harald Weltee61d4592022-11-03 11:05:58 +01001776static void test_gsm0808_enc_dec_cell_id_ci(void)
Neels Hofmeyr250e7f72018-04-13 03:30:14 +02001777{
1778 struct gsm0808_cell_id enc_ci = {
1779 .id_discr = CELL_IDENT_CI,
1780 .id.ci = 0x423,
1781 };
1782 struct gsm0808_cell_id dec_ci;
1783 struct msgb *msg;
1784 uint8_t rc_enc;
1785 int rc_dec;
1786
1787 msg = msgb_alloc(1024, "output buffer");
1788 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1789 EXPECT_ENCODED("05 03 02 04 23");
1790
1791 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1792 OSMO_ASSERT(rc_dec == msg->len - 2);
1793 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr
1794 && enc_ci.id.ci == dec_ci.id.ci);
1795
1796 msgb_free(msg);
1797}
1798
Harald Weltee61d4592022-11-03 11:05:58 +01001799static void test_gsm0808_enc_dec_cell_id_lac_and_ci(void)
Neels Hofmeyr250e7f72018-04-13 03:30:14 +02001800{
1801 struct gsm0808_cell_id enc_ci = {
1802 .id_discr = CELL_IDENT_LAC_AND_CI,
1803 .id.lac_and_ci = {
1804 .lac = 0x423,
1805 .ci = 0x235,
1806 },
1807 };
1808 struct gsm0808_cell_id dec_ci;
1809 struct msgb *msg;
1810 uint8_t rc_enc;
1811 int rc_dec;
1812
1813 msg = msgb_alloc(1024, "output buffer");
1814 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1815 EXPECT_ENCODED("05 05 01 04 23 02 35");
1816
1817 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1818 OSMO_ASSERT(rc_dec == msg->len - 2);
1819 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr
1820 && enc_ci.id.lac_and_ci.lac == dec_ci.id.lac_and_ci.lac
1821 && enc_ci.id.lac_and_ci.ci == dec_ci.id.lac_and_ci.ci);
1822
1823 msgb_free(msg);
1824}
1825
Harald Weltee61d4592022-11-03 11:05:58 +01001826static void test_gsm0808_enc_dec_cell_id_global(void)
Neels Hofmeyr250e7f72018-04-13 03:30:14 +02001827{
1828 struct gsm0808_cell_id enc_ci = {
1829 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1830 .id.global = {
1831 .lai = {
1832 .plmn = { .mcc = 123, .mnc = 456 },
1833 .lac = 0x2342
1834 },
1835 .cell_identity = 0x423,
1836 }
1837 };
1838 struct gsm0808_cell_id dec_ci;
1839 struct msgb *msg;
1840 uint8_t rc_enc;
1841 int rc_dec;
1842
1843 msg = msgb_alloc(1024, "output buffer");
1844 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1845 EXPECT_ENCODED("05 08 00 21 63 54 23 42 04 23");
1846
1847 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1848 OSMO_ASSERT(rc_dec == msg->len - 2);
1849
1850 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr
1851 && osmo_plmn_cmp(&enc_ci.id.global.lai.plmn,
1852 &dec_ci.id.global.lai.plmn) == 0
1853 && enc_ci.id.global.lai.lac == dec_ci.id.global.lai.lac
1854 && enc_ci.id.global.cell_identity == dec_ci.id.global.cell_identity);
1855 msgb_free(msg);
1856}
1857
Harald Weltee61d4592022-11-03 11:05:58 +01001858static void test_gsm0808_enc_dec_cell_id_global_ps(void)
Pau Espin Pedrol52489852021-02-15 16:26:37 +01001859{
1860 struct gsm0808_cell_id enc_cgi = {
1861 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1862 .id.global = {
1863 .lai = {
1864 .plmn = { .mcc = 123, .mnc = 456 },
1865 .lac = 0x2342
1866 },
1867 .cell_identity = 0x423,
1868 }
1869 };
1870 struct gsm0808_cell_id enc_cgi_ps = {
1871 .id_discr = CELL_IDENT_WHOLE_GLOBAL_PS,
1872 .id.global_ps = {
1873 .rai = {
1874 .lac = {
1875 .plmn = { .mcc = 123, .mnc = 456 },
1876 .lac = 0x2342
1877 },
1878 .rac = 0xcc,
1879 },
1880 .cell_identity = 0x423,
1881 }
1882 };
1883 struct msgb *msg_cgi, *msg_cgi_ps;
1884 uint8_t rc_enc;
1885
1886 msg_cgi = msgb_alloc(1024, "output buffer (CGI)");
1887 rc_enc = gsm0808_enc_cell_id(msg_cgi, &enc_cgi);
1888 OSMO_ASSERT(rc_enc > 0);
1889
1890 msg_cgi_ps = msgb_alloc(1024, "output buffer (CGI-PS)");
1891 rc_enc = gsm0808_enc_cell_id(msg_cgi_ps, &enc_cgi_ps);
1892 OSMO_ASSERT(rc_enc > 0);
1893
1894 OSMO_ASSERT(msgb_eq(msg_cgi, msg_cgi_ps));
1895
1896 msgb_free(msg_cgi);
1897 msgb_free(msg_cgi_ps);
1898}
1899
Philipp Maier5f2eb152018-09-19 13:40:21 +02001900static void test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(struct gsm48_multi_rate_conf *cfg)
1901{
1902 uint16_t s15_s0;
1903
1904 printf("Input:\n");
1905 printf(" m4_75= %u smod= %u\n", cfg->m4_75, cfg->smod);
1906 printf(" m5_15= %u spare= %u\n", cfg->m5_15, cfg->spare);
1907 printf(" m5_90= %u icmi= %u\n", cfg->m5_90, cfg->icmi);
1908 printf(" m6_70= %u nscb= %u\n", cfg->m6_70, cfg->nscb);
1909 printf(" m7_40= %u ver= %u\n", cfg->m7_40, cfg->ver);
1910 printf(" m7_95= %u\n", cfg->m7_95);
1911 printf(" m10_2= %u\n", cfg->m10_2);
1912 printf(" m12_2= %u\n", cfg->m12_2);
1913
1914 s15_s0 = gsm0808_sc_cfg_from_gsm48_mr_cfg(cfg, true);
1915 printf("Result (fr):\n");
1916 printf(" S15-S0 = %04x = 0b" OSMO_BIN_SPEC OSMO_BIN_SPEC "\n", s15_s0,
1917 OSMO_BIN_PRINT(s15_s0 >> 8), OSMO_BIN_PRINT(s15_s0));
1918
1919 s15_s0 = gsm0808_sc_cfg_from_gsm48_mr_cfg(cfg, false);
1920 printf("Result (hr):\n");
1921 printf(" S15-S0 = %04x = 0b" OSMO_BIN_SPEC OSMO_BIN_SPEC "\n", s15_s0,
1922 OSMO_BIN_PRINT(s15_s0 >> 8), OSMO_BIN_PRINT(s15_s0));
1923
1924 printf("\n");
1925}
1926
1927static void test_gsm0808_sc_cfg_from_gsm48_mr_cfg(void)
1928{
1929 struct gsm48_multi_rate_conf cfg;
1930
1931 printf("Testing gsm0808_sc_cfg_from_gsm48_mr_cfg():\n");
1932
1933 memset(&cfg, 0, sizeof(cfg));
1934
1935 cfg.m4_75 = 0;
1936 cfg.m5_15 = 0;
1937 cfg.m5_90 = 0;
1938 cfg.m6_70 = 0;
1939 cfg.m7_40 = 0;
1940 cfg.m7_95 = 0;
1941 cfg.m10_2 = 0;
1942 cfg.m12_2 = 0;
1943 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1944
1945 cfg.m4_75 = 1;
1946 cfg.m5_15 = 0;
1947 cfg.m5_90 = 0;
1948 cfg.m6_70 = 0;
1949 cfg.m7_40 = 0;
1950 cfg.m7_95 = 0;
1951 cfg.m10_2 = 0;
1952 cfg.m12_2 = 0;
1953 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1954
1955 cfg.m4_75 = 0;
1956 cfg.m5_15 = 1;
1957 cfg.m5_90 = 0;
1958 cfg.m6_70 = 0;
1959 cfg.m7_40 = 0;
1960 cfg.m7_95 = 0;
1961 cfg.m10_2 = 0;
1962 cfg.m12_2 = 0;
1963 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1964
1965 cfg.m4_75 = 0;
1966 cfg.m5_15 = 0;
1967 cfg.m5_90 = 1;
1968 cfg.m6_70 = 0;
1969 cfg.m7_40 = 0;
1970 cfg.m7_95 = 0;
1971 cfg.m10_2 = 0;
1972 cfg.m12_2 = 0;
1973 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1974
1975 cfg.m4_75 = 0;
1976 cfg.m5_15 = 0;
1977 cfg.m5_90 = 0;
1978 cfg.m6_70 = 1;
1979 cfg.m7_40 = 0;
1980 cfg.m7_95 = 0;
1981 cfg.m10_2 = 0;
1982 cfg.m12_2 = 0;
1983 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1984
1985 cfg.m4_75 = 0;
1986 cfg.m5_15 = 0;
1987 cfg.m5_90 = 0;
1988 cfg.m6_70 = 0;
1989 cfg.m7_40 = 1;
1990 cfg.m7_95 = 0;
1991 cfg.m10_2 = 0;
1992 cfg.m12_2 = 0;
1993 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1994
1995 cfg.m4_75 = 0;
1996 cfg.m5_15 = 0;
1997 cfg.m5_90 = 0;
1998 cfg.m6_70 = 0;
1999 cfg.m7_40 = 0;
2000 cfg.m7_95 = 1;
2001 cfg.m10_2 = 0;
2002 cfg.m12_2 = 0;
2003 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
2004
2005 cfg.m4_75 = 0;
2006 cfg.m5_15 = 0;
2007 cfg.m5_90 = 0;
2008 cfg.m6_70 = 0;
2009 cfg.m7_40 = 0;
2010 cfg.m7_95 = 0;
2011 cfg.m10_2 = 1;
2012 cfg.m12_2 = 0;
2013 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
2014
2015 cfg.m4_75 = 0;
2016 cfg.m5_15 = 0;
2017 cfg.m5_90 = 0;
2018 cfg.m6_70 = 0;
2019 cfg.m7_40 = 0;
2020 cfg.m7_95 = 0;
2021 cfg.m10_2 = 0;
2022 cfg.m12_2 = 1;
2023 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
2024
2025 cfg.m4_75 = 1;
2026 cfg.m5_15 = 1;
2027 cfg.m5_90 = 1;
2028 cfg.m6_70 = 1;
2029 cfg.m7_40 = 0;
2030 cfg.m7_95 = 0;
2031 cfg.m10_2 = 0;
2032 cfg.m12_2 = 0;
2033 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
2034
2035 cfg.m4_75 = 0;
2036 cfg.m5_15 = 0;
2037 cfg.m5_90 = 0;
2038 cfg.m6_70 = 0;
2039 cfg.m7_40 = 1;
2040 cfg.m7_95 = 1;
2041 cfg.m10_2 = 1;
2042 cfg.m12_2 = 1;
2043 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
2044
2045 cfg.m4_75 = 0;
2046 cfg.m5_15 = 0;
2047 cfg.m5_90 = 1;
2048 cfg.m6_70 = 1;
2049 cfg.m7_40 = 0;
2050 cfg.m7_95 = 0;
2051 cfg.m10_2 = 1;
2052 cfg.m12_2 = 1;
2053 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
2054
2055 cfg.m4_75 = 1;
2056 cfg.m5_15 = 1;
2057 cfg.m5_90 = 0;
2058 cfg.m6_70 = 0;
2059 cfg.m7_40 = 1;
2060 cfg.m7_95 = 1;
2061 cfg.m10_2 = 0;
2062 cfg.m12_2 = 0;
2063 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
2064
2065 cfg.m4_75 = 0;
2066 cfg.m5_15 = 1;
2067 cfg.m5_90 = 0;
2068 cfg.m6_70 = 1;
2069 cfg.m7_40 = 0;
2070 cfg.m7_95 = 1;
2071 cfg.m10_2 = 0;
2072 cfg.m12_2 = 1;
2073 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
2074
2075 cfg.m4_75 = 1;
2076 cfg.m5_15 = 0;
2077 cfg.m5_90 = 1;
2078 cfg.m6_70 = 0;
2079 cfg.m7_40 = 1;
2080 cfg.m7_95 = 0;
2081 cfg.m10_2 = 1;
2082 cfg.m12_2 = 0;
2083 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
2084
2085 cfg.m4_75 = 1;
2086 cfg.m5_15 = 1;
2087 cfg.m5_90 = 1;
2088 cfg.m6_70 = 1;
2089 cfg.m7_40 = 1;
2090 cfg.m7_95 = 1;
2091 cfg.m10_2 = 1;
2092 cfg.m12_2 = 1;
2093 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
Philipp Maier94d79fd2019-03-01 10:40:48 +01002094
2095 cfg.m4_75 = 1;
2096 cfg.m5_15 = 0;
2097 cfg.m5_90 = 1;
2098 cfg.m6_70 = 0;
2099 cfg.m7_40 = 1;
2100 cfg.m7_95 = 0;
2101 cfg.m10_2 = 0;
2102 cfg.m12_2 = 1;
2103 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
2104
2105 cfg.m4_75 = 1;
2106 cfg.m5_15 = 0;
2107 cfg.m5_90 = 1;
2108 cfg.m6_70 = 0;
2109 cfg.m7_40 = 1;
2110 cfg.m7_95 = 0;
2111 cfg.m10_2 = 0;
2112 cfg.m12_2 = 0;
2113 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
Pau Espin Pedrol1bd495a2021-02-15 16:15:59 +01002114
Philipp Maier5f2eb152018-09-19 13:40:21 +02002115}
2116
Philipp Maier8515d032018-09-25 15:57:49 +02002117static void test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single(uint16_t s15_s0)
2118{
2119 struct gsm48_multi_rate_conf cfg;
Philipp Maier3713af82019-02-27 16:48:25 +01002120 int rc;
Philipp Maier8515d032018-09-25 15:57:49 +02002121
2122 printf("Input:\n");
2123 printf(" S15-S0 = %04x = 0b" OSMO_BIN_SPEC OSMO_BIN_SPEC "\n", s15_s0,
2124 OSMO_BIN_PRINT(s15_s0 >> 8), OSMO_BIN_PRINT(s15_s0));
2125
Philipp Maier3713af82019-02-27 16:48:25 +01002126 rc = gsm48_mr_cfg_from_gsm0808_sc_cfg(&cfg, s15_s0);
Philipp Maier8515d032018-09-25 15:57:49 +02002127
2128 printf("Output:\n");
2129 printf(" m4_75= %u smod= %u\n", cfg.m4_75, cfg.smod);
2130 printf(" m5_15= %u spare= %u\n", cfg.m5_15, cfg.spare);
2131 printf(" m5_90= %u icmi= %u\n", cfg.m5_90, cfg.icmi);
2132 printf(" m6_70= %u nscb= %u\n", cfg.m6_70, cfg.nscb);
2133 printf(" m7_40= %u ver= %u\n", cfg.m7_40, cfg.ver);
2134 printf(" m7_95= %u\n", cfg.m7_95);
2135 printf(" m10_2= %u\n", cfg.m10_2);
2136 printf(" m12_2= %u\n", cfg.m12_2);
2137
Philipp Maier3713af82019-02-27 16:48:25 +01002138 if (rc != 0)
2139 printf(" Result invalid!\n");
2140
Philipp Maier8515d032018-09-25 15:57:49 +02002141 printf("\n");
2142}
2143
Harald Weltee61d4592022-11-03 11:05:58 +01002144void test_gsm48_mr_cfg_from_gsm0808_sc_cfg(void)
Philipp Maier8515d032018-09-25 15:57:49 +02002145{
2146 printf("Testing gsm48_mr_cfg_from_gsm0808_sc_cfg():\n");
2147
Philipp Maier3713af82019-02-27 16:48:25 +01002148 /* Test with settings as defined in 3GPP TS 28.062, Table 7.11.3.1.3-2,
2149 * (up to four codecs may become selected) */
Philipp Maier8515d032018-09-25 15:57:49 +02002150 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
2151 (GSM0808_SC_CFG_DEFAULT_AMR_4_75);
2152 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
2153 (GSM0808_SC_CFG_DEFAULT_AMR_5_15);
2154 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
2155 (GSM0808_SC_CFG_DEFAULT_AMR_5_90);
2156 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
2157 (GSM0808_SC_CFG_DEFAULT_AMR_6_70);
2158 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
2159 (GSM0808_SC_CFG_DEFAULT_AMR_7_40);
2160 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
2161 (GSM0808_SC_CFG_DEFAULT_AMR_7_95);
2162 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
2163 (GSM0808_SC_CFG_DEFAULT_AMR_10_2);
2164 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
2165 (GSM0808_SC_CFG_DEFAULT_AMR_12_2);
2166
Philipp Maier3713af82019-02-27 16:48:25 +01002167 /* Test with settings as defined in 3GPP TS 28.062, Table 7.11.3.1.3-2,
2168 * but pick only one distinctive setting at a time */
2169 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single(GSM0808_SC_CFG_AMR_4_75);
Philipp Maier8515d032018-09-25 15:57:49 +02002170 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
Philipp Maier3713af82019-02-27 16:48:25 +01002171 (GSM0808_SC_CFG_AMR_4_75_5_90_7_40_12_20);
2172 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single(GSM0808_SC_CFG_AMR_5_90);
2173 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single(GSM0808_SC_CFG_AMR_6_70);
2174 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single(GSM0808_SC_CFG_AMR_7_40);
2175 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single(GSM0808_SC_CFG_AMR_7_95);
2176 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single(GSM0808_SC_CFG_AMR_10_2);
2177 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single(GSM0808_SC_CFG_AMR_12_2);
2178
2179 /* Arbitrary, but valid combinations */
2180 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single(GSM0808_SC_CFG_AMR_7_40 |
2181 GSM0808_SC_CFG_AMR_6_70 |
2182 GSM0808_SC_CFG_AMR_10_2);
2183 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single(GSM0808_SC_CFG_AMR_7_95 |
2184 GSM0808_SC_CFG_AMR_4_75);
2185 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single(GSM0808_SC_CFG_AMR_5_90 |
2186 GSM0808_SC_CFG_AMR_12_2);
Philipp Maier8515d032018-09-25 15:57:49 +02002187 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
Philipp Maier3713af82019-02-27 16:48:25 +01002188 (GSM0808_SC_CFG_AMR_4_75_5_90_7_40_12_20 | GSM0808_SC_CFG_AMR_5_90 |
2189 GSM0808_SC_CFG_AMR_12_2);
2190
2191 /* Invalid combinations */
Philipp Maier8515d032018-09-25 15:57:49 +02002192 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
Philipp Maier3713af82019-02-27 16:48:25 +01002193 (GSM0808_SC_CFG_AMR_4_75_5_90_7_40_12_20 | GSM0808_SC_CFG_AMR_6_70);
2194 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single(GSM0808_SC_CFG_AMR_7_40 |
2195 GSM0808_SC_CFG_AMR_6_70 |
2196 GSM0808_SC_CFG_AMR_10_2 |
2197 GSM0808_SC_CFG_AMR_7_95 |
2198 GSM0808_SC_CFG_AMR_4_75);
2199 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single(0x0000);
2200 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single(0xffff);
Philipp Maier8515d032018-09-25 15:57:49 +02002201}
2202
Neels Hofmeyrd01ef752018-09-21 15:57:26 +02002203struct test_cell_id_matching_data {
2204 struct gsm0808_cell_id id;
2205 struct gsm0808_cell_id match_id;
2206 bool expect_match;
2207 bool expect_exact_match;
2208};
2209
2210#define lac_23 { .id_discr = CELL_IDENT_LAC, .id.lac = 23, }
2211#define lac_42 { .id_discr = CELL_IDENT_LAC, .id.lac = 42, }
2212#define ci_5 { .id_discr = CELL_IDENT_CI, .id.ci = 5, }
2213#define ci_6 { .id_discr = CELL_IDENT_CI, .id.ci = 6, }
2214#define lac_ci_23_5 { \
2215 .id_discr = CELL_IDENT_LAC_AND_CI, \
2216 .id.lac_and_ci = { .lac = 23, .ci = 5, }, \
2217 }
2218#define lac_ci_42_6 { \
2219 .id_discr = CELL_IDENT_LAC_AND_CI, \
2220 .id.lac_and_ci = { .lac = 42, .ci = 6, }, \
2221 }
2222#define lai_23_042_23 { \
2223 .id_discr = CELL_IDENT_LAI_AND_LAC, \
2224 .id.lai_and_lac = { .plmn = { .mcc = 23, .mnc = 42, .mnc_3_digits = true }, .lac = 23, }, \
2225 }
2226#define lai_23_042_42 { \
2227 .id_discr = CELL_IDENT_LAI_AND_LAC, \
2228 .id.lai_and_lac = { .plmn = { .mcc = 23, .mnc = 42, .mnc_3_digits = true }, .lac = 42, }, \
2229 }
2230#define lai_23_99_23 { \
2231 .id_discr = CELL_IDENT_LAI_AND_LAC, \
2232 .id.lai_and_lac = { .plmn = { .mcc = 23, .mnc = 99, .mnc_3_digits = false }, .lac = 23, }, \
2233 }
2234#define lai_23_42_23 { \
2235 .id_discr = CELL_IDENT_LAI_AND_LAC, \
2236 .id.lai_and_lac = { .plmn = { .mcc = 23, .mnc = 42, .mnc_3_digits = false }, .lac = 23, }, \
2237 }
2238#define cgi_23_042_23_5 { \
2239 .id_discr = CELL_IDENT_WHOLE_GLOBAL, \
2240 .id.global = { \
2241 .lai = { .plmn = { .mcc = 23, .mnc = 42, .mnc_3_digits = true }, .lac = 23, }, \
2242 .cell_identity = 5, \
2243 }, \
2244 }
2245#define cgi_23_042_42_6 { \
2246 .id_discr = CELL_IDENT_WHOLE_GLOBAL, \
2247 .id.global = { \
2248 .lai = { .plmn = { .mcc = 23, .mnc = 42, .mnc_3_digits = true }, .lac = 42, }, \
2249 .cell_identity = 6, \
2250 }, \
2251 }
2252#define cgi_23_99_23_5 { \
2253 .id_discr = CELL_IDENT_WHOLE_GLOBAL, \
2254 .id.global = { \
2255 .lai = { .plmn = { .mcc = 23, .mnc = 99, .mnc_3_digits = false }, .lac = 23, }, \
2256 .cell_identity = 5, \
2257 }, \
2258 }
2259
2260
2261static const struct test_cell_id_matching_data test_cell_id_matching_tests[] = {
2262 { .id = lac_23, .match_id = lac_23, .expect_match = true, .expect_exact_match = true },
2263 { .id = lac_23, .match_id = lac_42, .expect_match = false, .expect_exact_match = false },
2264 { .id = lac_23, .match_id = ci_5, .expect_match = true, .expect_exact_match = false },
2265 { .id = lac_23, .match_id = ci_6, .expect_match = true, .expect_exact_match = false },
2266 { .id = lac_23, .match_id = lac_ci_23_5, .expect_match = true, .expect_exact_match = false },
2267 { .id = lac_23, .match_id = lac_ci_42_6, .expect_match = false, .expect_exact_match = false },
2268 { .id = lac_23, .match_id = lai_23_042_23, .expect_match = true, .expect_exact_match = false },
2269 { .id = lac_23, .match_id = lai_23_042_42, .expect_match = false, .expect_exact_match = false },
2270 { .id = lac_23, .match_id = lai_23_99_23, .expect_match = true, .expect_exact_match = false },
2271 { .id = lac_23, .match_id = lai_23_42_23, .expect_match = true, .expect_exact_match = false },
2272 { .id = lac_23, .match_id = cgi_23_042_23_5, .expect_match = true, .expect_exact_match = false },
2273 { .id = lac_23, .match_id = cgi_23_042_42_6, .expect_match = false, .expect_exact_match = false },
2274 { .id = lac_23, .match_id = cgi_23_99_23_5, .expect_match = true, .expect_exact_match = false },
2275 { .id = ci_5, .match_id = lac_23, .expect_match = true, .expect_exact_match = false },
2276 { .id = ci_5, .match_id = lac_42, .expect_match = true, .expect_exact_match = false },
2277 { .id = ci_5, .match_id = ci_5, .expect_match = true, .expect_exact_match = true },
2278 { .id = ci_5, .match_id = ci_6, .expect_match = false, .expect_exact_match = false },
2279 { .id = ci_5, .match_id = lac_ci_23_5, .expect_match = true, .expect_exact_match = false },
2280 { .id = ci_5, .match_id = lac_ci_42_6, .expect_match = false, .expect_exact_match = false },
2281 { .id = ci_5, .match_id = lai_23_042_23, .expect_match = true, .expect_exact_match = false },
2282 { .id = ci_5, .match_id = lai_23_042_42, .expect_match = true, .expect_exact_match = false },
2283 { .id = ci_5, .match_id = lai_23_99_23, .expect_match = true, .expect_exact_match = false },
2284 { .id = ci_5, .match_id = lai_23_42_23, .expect_match = true, .expect_exact_match = false },
2285 { .id = ci_5, .match_id = cgi_23_042_23_5, .expect_match = true, .expect_exact_match = false },
2286 { .id = ci_5, .match_id = cgi_23_042_42_6, .expect_match = false, .expect_exact_match = false },
2287 { .id = ci_5, .match_id = cgi_23_99_23_5, .expect_match = true, .expect_exact_match = false },
2288 { .id = lac_ci_23_5, .match_id = lac_23, .expect_match = true, .expect_exact_match = false },
2289 { .id = lac_ci_23_5, .match_id = lac_42, .expect_match = false, .expect_exact_match = false },
2290 { .id = lac_ci_23_5, .match_id = ci_5, .expect_match = true, .expect_exact_match = false },
2291 { .id = lac_ci_23_5, .match_id = ci_6, .expect_match = false, .expect_exact_match = false },
2292 { .id = lac_ci_23_5, .match_id = lac_ci_23_5, .expect_match = true, .expect_exact_match = true },
2293 { .id = lac_ci_23_5, .match_id = lac_ci_42_6, .expect_match = false, .expect_exact_match = false },
2294 { .id = lac_ci_23_5, .match_id = lai_23_042_23, .expect_match = true, .expect_exact_match = false },
2295 { .id = lac_ci_23_5, .match_id = lai_23_042_42, .expect_match = false, .expect_exact_match = false },
2296 { .id = lac_ci_23_5, .match_id = lai_23_99_23, .expect_match = true, .expect_exact_match = false },
2297 { .id = lac_ci_23_5, .match_id = lai_23_42_23, .expect_match = true, .expect_exact_match = false },
2298 { .id = lac_ci_23_5, .match_id = cgi_23_042_23_5, .expect_match = true, .expect_exact_match = false },
2299 { .id = lac_ci_23_5, .match_id = cgi_23_042_42_6, .expect_match = false, .expect_exact_match = false },
2300 { .id = lac_ci_23_5, .match_id = cgi_23_99_23_5, .expect_match = true, .expect_exact_match = false },
2301 { .id = lai_23_042_23, .match_id = lac_23, .expect_match = true, .expect_exact_match = false },
2302 { .id = lai_23_042_23, .match_id = lac_42, .expect_match = false, .expect_exact_match = false },
2303 { .id = lai_23_042_23, .match_id = ci_5, .expect_match = true, .expect_exact_match = false },
2304 { .id = lai_23_042_23, .match_id = ci_6, .expect_match = true, .expect_exact_match = false },
2305 { .id = lai_23_042_23, .match_id = lac_ci_23_5, .expect_match = true, .expect_exact_match = false },
2306 { .id = lai_23_042_23, .match_id = lac_ci_42_6, .expect_match = false, .expect_exact_match = false },
2307 { .id = lai_23_042_23, .match_id = lai_23_042_23, .expect_match = true, .expect_exact_match = true },
2308 { .id = lai_23_042_23, .match_id = lai_23_042_42, .expect_match = false, .expect_exact_match = false },
2309 { .id = lai_23_042_23, .match_id = lai_23_99_23, .expect_match = false, .expect_exact_match = false },
2310 { .id = lai_23_042_23, .match_id = lai_23_42_23, .expect_match = false, .expect_exact_match = false },
2311 { .id = lai_23_042_23, .match_id = cgi_23_042_23_5, .expect_match = true, .expect_exact_match = false },
2312 { .id = lai_23_042_23, .match_id = cgi_23_042_42_6, .expect_match = false, .expect_exact_match = false },
2313 { .id = lai_23_042_23, .match_id = cgi_23_99_23_5, .expect_match = false, .expect_exact_match = false },
2314 { .id = cgi_23_042_23_5, .match_id = lac_23, .expect_match = true, .expect_exact_match = false },
2315 { .id = cgi_23_042_23_5, .match_id = lac_42, .expect_match = false, .expect_exact_match = false },
2316 { .id = cgi_23_042_23_5, .match_id = ci_5, .expect_match = true, .expect_exact_match = false },
2317 { .id = cgi_23_042_23_5, .match_id = ci_6, .expect_match = false, .expect_exact_match = false },
2318 { .id = cgi_23_042_23_5, .match_id = lac_ci_23_5, .expect_match = true, .expect_exact_match = false },
2319 { .id = cgi_23_042_23_5, .match_id = lac_ci_42_6, .expect_match = false, .expect_exact_match = false },
2320 { .id = cgi_23_042_23_5, .match_id = lai_23_042_23, .expect_match = true, .expect_exact_match = false },
2321 { .id = cgi_23_042_23_5, .match_id = lai_23_042_42, .expect_match = false, .expect_exact_match = false },
2322 { .id = cgi_23_042_23_5, .match_id = lai_23_99_23, .expect_match = false, .expect_exact_match = false },
2323 { .id = cgi_23_042_23_5, .match_id = lai_23_42_23, .expect_match = false, .expect_exact_match = false },
2324 { .id = cgi_23_042_23_5, .match_id = cgi_23_042_23_5, .expect_match = true, .expect_exact_match = true },
2325 { .id = cgi_23_042_23_5, .match_id = cgi_23_042_42_6, .expect_match = false, .expect_exact_match = false },
2326 { .id = cgi_23_042_23_5, .match_id = cgi_23_99_23_5, .expect_match = false, .expect_exact_match = false },
2327};
2328
Harald Weltee61d4592022-11-03 11:05:58 +01002329static void test_cell_id_matching(void)
Neels Hofmeyrd01ef752018-09-21 15:57:26 +02002330{
2331 int i;
2332 bool ok = true;
2333 printf("\n%s\n", __func__);
2334
2335 for (i = 0; i < ARRAY_SIZE(test_cell_id_matching_tests); i++) {
2336 const struct test_cell_id_matching_data *d = &test_cell_id_matching_tests[i];
2337 int exact_match;
2338
2339 for (exact_match = 0; exact_match < 2; exact_match++) {
2340 bool result;
2341 bool expect_result = exact_match ? d->expect_exact_match : d->expect_match;
2342
2343 result = gsm0808_cell_ids_match(&d->id, &d->match_id, (bool)exact_match);
2344
2345 printf("[%d] %s %s %s%s\n",
2346 i,
2347 gsm0808_cell_id_name(&d->id),
2348 gsm0808_cell_id_name2(&d->match_id),
2349 result ? "MATCH" : "don't match",
2350 exact_match ? " exactly" : "");
2351 if (result != expect_result) {
2352 printf(" ERROR: expected %s\n", d->expect_match ? "MATCH" : "no match");
2353 ok = false;
2354 }
2355 }
2356 }
2357
2358 OSMO_ASSERT(ok);
2359}
2360
2361static bool test_cell_id_list_matching_discrs(bool test_match,
2362 enum CELL_IDENT id_discr,
2363 enum CELL_IDENT list_discr)
2364{
2365 int i, j;
2366 const struct gsm0808_cell_id *id = NULL;
2367 struct gsm0808_cell_id_list2 list = {};
2368 int match_idx = -1;
2369 int result;
2370
2371 for (i = 0; i < ARRAY_SIZE(test_cell_id_matching_tests); i++) {
2372 const struct test_cell_id_matching_data *d = &test_cell_id_matching_tests[i];
2373 if (id_discr != d->id.id_discr)
2374 continue;
2375 id = &d->id;
2376 break;
2377 }
2378
2379 if (!id) {
2380 printf("Did not find any entry for %s\n", gsm0808_cell_id_discr_name(id_discr));
2381 return true;
2382 }
2383
2384 /* Collect those entries with exactly this id on the left, of type list_discr on the right.
2385 * Collect the mismatches first, for more interesting match indexes in the results. */
2386 for (j = 0; j < 2; j++) {
2387 bool collect_matches = (bool)j;
2388
2389 /* If we want to have a mismatching list, don't add any entries that match. */
2390 if (!test_match && collect_matches)
2391 continue;
2392
2393 for (i = 0; i < ARRAY_SIZE(test_cell_id_matching_tests); i++) {
2394 const struct test_cell_id_matching_data *d = &test_cell_id_matching_tests[i];
2395 struct gsm0808_cell_id_list2 add;
2396
2397 /* Ignore those with a different d->id */
2398 if (!gsm0808_cell_ids_match(&d->id, id, true))
2399 continue;
2400
2401 /* Ignore those with a different d->match_id discr */
2402 if (d->match_id.id_discr != list_discr)
2403 continue;
2404
2405 if (collect_matches != d->expect_match)
2406 continue;
2407
2408 if (match_idx < 0 && d->expect_match) {
2409 match_idx = list.id_list_len;
2410 }
2411
2412 gsm0808_cell_id_to_list(&add, &d->match_id);
2413 gsm0808_cell_id_list_add(&list, &add);
2414 }
2415 }
2416
2417 if (!list.id_list_len) {
2418 printf("%s vs. %s: No match_id entries to test %s\n",
2419 gsm0808_cell_id_name(id),
2420 gsm0808_cell_id_discr_name(list_discr),
2421 test_match ? "MATCH" : "mismatch");
2422 return true;
2423 }
2424
2425 result = gsm0808_cell_id_matches_list(id, &list, 0, false);
2426
2427 printf("%s and %s: ",
2428 gsm0808_cell_id_name(id),
2429 gsm0808_cell_id_list_name(&list));
2430 if (result >= 0)
2431 printf("MATCH at [%d]\n", result);
2432 else
2433 printf("mismatch\n");
2434
2435 if (test_match
2436 && (result < 0 || result != match_idx)) {
2437 printf(" ERROR: expected MATCH at %d\n", match_idx);
2438 return false;
2439 }
2440
2441 if (!test_match && result >= 0) {
2442 printf(" ERROR: expected mismatch\n");
2443 return false;
2444 }
2445
2446 return true;
2447}
2448
Neels Hofmeyr3a504532019-02-10 22:28:27 +01002449const enum CELL_IDENT cell_ident_discrs[] = {
2450 CELL_IDENT_LAC, CELL_IDENT_CI, CELL_IDENT_LAC_AND_CI, CELL_IDENT_LAI_AND_LAC,
2451 CELL_IDENT_WHOLE_GLOBAL,
2452};
2453
2454
Neels Hofmeyrd01ef752018-09-21 15:57:26 +02002455static void test_cell_id_list_matching(bool test_match)
2456{
2457 int i, j;
2458 bool ok = true;
2459
Neels Hofmeyrd01ef752018-09-21 15:57:26 +02002460 printf("\n%s(%s)\n", __func__, test_match ? "test match" : "test mismatch");
2461
2462 /* Autogenerate Cell ID lists from above dataset, which should match / not match. */
Neels Hofmeyr3a504532019-02-10 22:28:27 +01002463 for (i = 0; i < ARRAY_SIZE(cell_ident_discrs); i++) {
2464 for (j = 0; j < ARRAY_SIZE(cell_ident_discrs); j++)
Neels Hofmeyrd01ef752018-09-21 15:57:26 +02002465 if (!test_cell_id_list_matching_discrs(test_match,
Neels Hofmeyr3a504532019-02-10 22:28:27 +01002466 cell_ident_discrs[i], cell_ident_discrs[j]))
Neels Hofmeyrd01ef752018-09-21 15:57:26 +02002467 ok = false;
2468 }
2469
2470 OSMO_ASSERT(ok);
2471}
2472
Neels Hofmeyr3a504532019-02-10 22:28:27 +01002473
2474static const struct gsm0808_cell_id test_gsm0808_cell_id_to_from_cgi_data[] = {
2475 lac_23,
2476 lac_42,
2477 ci_5,
2478 ci_6,
2479 lac_ci_23_5,
2480 lac_ci_42_6,
2481 lai_23_042_23,
2482 lai_23_042_42,
2483 lai_23_99_23,
2484 lai_23_42_23,
2485 cgi_23_042_23_5,
2486 cgi_23_042_42_6,
2487 cgi_23_99_23_5,
2488 { .id_discr = CELL_IDENT_NO_CELL },
2489 { .id_discr = 423 },
2490};
2491
Harald Weltee61d4592022-11-03 11:05:58 +01002492static void test_gsm0808_cell_id_to_from_cgi(void)
Neels Hofmeyr3a504532019-02-10 22:28:27 +01002493{
2494 int i;
2495 int j;
2496
2497 printf("\n%s()\n", __func__);
2498
2499 for (i = 0; i < ARRAY_SIZE(test_gsm0808_cell_id_to_from_cgi_data); i++) {
2500 const struct gsm0808_cell_id *from_cid = &test_gsm0808_cell_id_to_from_cgi_data[i];
2501 struct osmo_cell_global_id cgi = {
2502 .lai = {
2503 .plmn = {
2504 .mcc = 777,
2505 .mnc = 7,
2506 .mnc_3_digits = true,
2507 },
2508 .lac = 7777,
2509 },
2510 .cell_identity = 7777,
2511 };
2512 struct gsm0808_cell_id cid = {};
2513 int rc;
2514
2515 rc = gsm0808_cell_id_to_cgi(&cgi, from_cid);
2516 printf("cid %s -> cgi %s", gsm0808_cell_id_name(from_cid), osmo_cgi_name(&cgi));
2517
2518 if (rc & OSMO_CGI_PART_PLMN)
2519 printf(" PLMN");
2520 if (rc & OSMO_CGI_PART_LAC)
2521 printf(" LAC");
2522 if (rc & OSMO_CGI_PART_CI)
2523 printf(" CI");
2524
2525 gsm0808_cell_id_from_cgi(&cid, from_cid->id_discr, &cgi);
2526 printf(" -> cid %s\n", gsm0808_cell_id_name(&cid));
2527 if (!gsm0808_cell_ids_match(from_cid, &cid, true))
2528 printf(" MISMATCH!\n");
2529
2530 for (j = 0; j < ARRAY_SIZE(cell_ident_discrs); j++) {
2531 enum CELL_IDENT discr = cell_ident_discrs[j];
2532
2533 gsm0808_cell_id_from_cgi(&cid, discr, &cgi);
2534 printf(" --> gsm0808_cell_id{%s} = %s\n", gsm0808_cell_id_discr_name(discr), gsm0808_cell_id_name(&cid));
2535 }
2536 }
2537}
2538
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002539int main(int argc, char **argv)
2540{
Max969fb2e2018-12-10 11:01:10 +01002541 void *ctx = talloc_named_const(NULL, 0, "gsm0808 test");
2542 msgb_talloc_ctx_init(ctx, 0);
2543 osmo_init_logging2(ctx, NULL);
2544
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002545 printf("Testing generation of GSM0808 messages\n");
Philipp Maier4f4905f2018-11-30 13:36:12 +01002546 test_gsm0808_enc_cause();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002547 test_create_layer3();
Philipp Maierfa896ab2017-03-27 16:55:32 +02002548 test_create_layer3_aoip();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002549 test_create_reset();
Philipp Maier15596e22017-04-05 17:55:27 +02002550 test_create_reset_ack();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002551 test_create_clear_command();
Harald Weltecf665fc2019-02-18 13:45:36 +01002552 test_create_clear_command2();
2553 test_create_clear_command2_csfb();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002554 test_create_clear_complete();
Philipp Maierb478dd32017-03-29 15:50:05 +02002555 test_create_cipher();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002556 test_create_cipher_complete();
2557 test_create_cipher_reject();
Maxed651d22018-11-07 15:25:05 +01002558 test_create_cipher_reject_ext();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002559 test_create_cm_u();
2560 test_create_sapi_reject();
Philipp Maierc6144a22017-03-29 17:53:43 +02002561 test_create_ass();
Max52074322018-11-30 10:44:07 +01002562 test_create_ass2();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002563 test_create_ass_compl();
Philipp Maierfa896ab2017-03-27 16:55:32 +02002564 test_create_ass_compl_aoip();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002565 test_create_ass_fail();
Philipp Maierfa896ab2017-03-27 16:55:32 +02002566 test_create_ass_fail_aoip();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002567 test_create_clear_rqst();
Philipp Maier3d48ec02017-03-29 17:37:55 +02002568 test_create_paging();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002569 test_create_dtap();
2570 test_prepend_dtap();
Max969fb2e2018-12-10 11:01:10 +01002571
Max47022152018-12-19 18:51:00 +01002572 test_enc_dec_lcls();
Max969fb2e2018-12-10 11:01:10 +01002573
Philipp Maier22401432017-03-24 17:59:26 +01002574 test_enc_dec_aoip_trasp_addr_v4();
2575 test_enc_dec_aoip_trasp_addr_v6();
Oliver Smithc66b35b2022-08-05 11:27:55 +02002576 test_enc_aoip_trasp_addr_msg_too_small();
Philipp Maier6f725d62017-03-24 18:03:17 +01002577 test_gsm0808_enc_dec_speech_codec();
Philipp Maier6f725d62017-03-24 18:03:17 +01002578 test_gsm0808_enc_dec_speech_codec_ext_with_cfg();
Philipp Maierbb839662017-06-01 17:11:19 +02002579 test_gsm0808_enc_dec_speech_codec_with_cfg();
Philipp Maier6f725d62017-03-24 18:03:17 +01002580 test_gsm0808_enc_dec_speech_codec_list();
Philipp Maierf6c369f2018-10-16 15:24:47 +02002581 test_gsm0808_enc_dec_empty_speech_codec_list();
Philipp Maiere0c65302017-03-28 17:05:40 +02002582 test_gsm0808_enc_dec_channel_type();
Oliver Smith81e5a6f2023-01-31 12:34:26 +01002583 test_gsm0808_dec_channel_type_err();
Philipp Maier14e76b92017-03-28 18:36:52 +02002584 test_gsm0808_enc_dec_encrypt_info();
Neels Hofmeyr250e7f72018-04-13 03:30:14 +02002585
Philipp Maier783047e2017-03-29 11:35:50 +02002586 test_gsm0808_enc_dec_cell_id_list_lac();
2587 test_gsm0808_enc_dec_cell_id_list_single_lac();
Stefan Sperlinge1a86742018-03-15 18:05:02 +01002588 test_gsm0808_enc_dec_cell_id_list_multi_lac();
Philipp Maier783047e2017-03-29 11:35:50 +02002589 test_gsm0808_enc_dec_cell_id_list_bss();
Stefan Sperling23381452018-03-15 19:38:15 +01002590 test_gsm0808_enc_dec_cell_id_list_multi_lai_and_lac();
Stefan Sperling9c62fc62018-03-16 10:23:34 +01002591 test_gsm0808_enc_dec_cell_id_list_multi_ci();
Stefan Sperlinged4327c2018-03-16 11:02:59 +01002592 test_gsm0808_enc_dec_cell_id_list_multi_lac_and_ci();
Stefan Sperling483f3862018-03-16 12:21:26 +01002593 test_gsm0808_enc_dec_cell_id_list_multi_global();
Harald Weltea87526d2022-02-15 20:06:16 +01002594 test_gsm0808_dec_cell_id_list_srvcc();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002595
Neels Hofmeyr74663d92018-03-23 01:46:42 +01002596 test_cell_id_list_add();
2597
Neels Hofmeyr250e7f72018-04-13 03:30:14 +02002598 test_gsm0808_enc_dec_cell_id_lac();
2599 test_gsm0808_enc_dec_cell_id_bss();
2600 test_gsm0808_enc_dec_cell_id_no_cell();
2601 test_gsm0808_enc_dec_cell_id_lai_and_lac();
2602 test_gsm0808_enc_dec_cell_id_ci();
2603 test_gsm0808_enc_dec_cell_id_lac_and_ci();
2604 test_gsm0808_enc_dec_cell_id_global();
Pau Espin Pedrol52489852021-02-15 16:26:37 +01002605 test_gsm0808_enc_dec_cell_id_global_ps();
Philipp Maier5f2eb152018-09-19 13:40:21 +02002606 test_gsm0808_sc_cfg_from_gsm48_mr_cfg();
Philipp Maier8515d032018-09-25 15:57:49 +02002607 test_gsm48_mr_cfg_from_gsm0808_sc_cfg();
Philipp Maier5f2eb152018-09-19 13:40:21 +02002608
Neels Hofmeyrd01ef752018-09-21 15:57:26 +02002609 test_cell_id_matching();
2610 test_cell_id_list_matching(true);
2611 test_cell_id_list_matching(false);
2612
Neels Hofmeyr3a504532019-02-10 22:28:27 +01002613 test_gsm0808_cell_id_to_from_cgi();
2614
Alexander Chemeris22630e62020-05-13 00:44:04 +03002615 test_dec_confusion();
Pau Espin Pedrola3987fc2022-03-18 13:17:28 +01002616 test_dec_perform_location_report_sys5891();
Alexander Chemeris22630e62020-05-13 00:44:04 +03002617
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002618 printf("Done\n");
2619 return EXIT_SUCCESS;
2620}