blob: 546a487b25b5a448e6c75fb923b47af46b101ecf [file] [log] [blame]
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01001/*
2 * (C) 2012 by Holger Hans Peter Freyther
3 * All Rights Reserved
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 */
20
21#include <osmocom/gsm/gsm0808.h>
Philipp Maier22401432017-03-24 17:59:26 +010022#include <osmocom/gsm/gsm0808_utils.h>
23#include <osmocom/gsm/protocol/gsm_08_08.h>
Philipp Maier3d48ec02017-03-29 17:37:55 +020024#include <osmocom/gsm/protocol/gsm_08_58.h>
Max969fb2e2018-12-10 11:01:10 +010025#include <osmocom/core/logging.h>
26#include <osmocom/core/application.h>
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +010027
28#include <stdio.h>
29#include <stdlib.h>
Philipp Maier22401432017-03-24 17:59:26 +010030#include <sys/socket.h>
31#include <netinet/in.h>
32#include <arpa/inet.h>
Neels Hofmeyr74663d92018-03-23 01:46:42 +010033#include <errno.h>
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +010034
Philipp Maier4f4905f2018-11-30 13:36:12 +010035#define EXPECT_ENCODED(hexstr) do { \
36 const char *enc_str = msgb_hexdump(msg); \
37 printf("%s: encoded: %s(rc = %u)\n", __func__, enc_str, rc_enc); \
38 OSMO_ASSERT(strcmp(enc_str, hexstr " ") == 0); \
39 OSMO_ASSERT(rc_enc == msg->len); \
40 } while(0)
41
Vadim Yanitskiycf6ee642018-12-20 05:23:00 +070042#define VERIFY(msg, data, data_len) do { \
43 if (!msgb_eq_l3_data_print(msg, data, data_len)) \
44 abort(); \
45 } while(0)
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +010046
Philipp Maierfa896ab2017-03-27 16:55:32 +020047/* Setup a fake codec list for testing */
48static void setup_codec_list(struct gsm0808_speech_codec_list *scl)
49{
50 memset(scl, 0, sizeof(*scl));
51
52 scl->codec[0].pi = true;
53 scl->codec[0].tf = true;
Philipp Maierbb839662017-06-01 17:11:19 +020054 scl->codec[0].type = GSM0808_SCT_FR3;
Philipp Maierfa896ab2017-03-27 16:55:32 +020055 scl->codec[0].cfg = 0xcdef;
56
57 scl->codec[1].fi = true;
58 scl->codec[1].pt = true;
Philipp Maierbb839662017-06-01 17:11:19 +020059 scl->codec[1].type = GSM0808_SCT_FR2;
Philipp Maierfa896ab2017-03-27 16:55:32 +020060
61 scl->codec[2].fi = true;
62 scl->codec[2].tf = true;
Philipp Maierbb839662017-06-01 17:11:19 +020063 scl->codec[2].type = GSM0808_SCT_CSD;
64 scl->codec[2].cfg = 0xc0;
Philipp Maierfa896ab2017-03-27 16:55:32 +020065
66 scl->len = 3;
67}
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +010068
Philipp Maier4f4905f2018-11-30 13:36:12 +010069void test_gsm0808_enc_cause(void)
70{
71 /* NOTE: This must be tested early because many of the following tests
72 * rely on the generation of a proper cause code. */
73
74 uint8_t rc_enc;
75 struct msgb *msg;
76
77 /* Test with a single byte cause code */
78 msg = msgb_alloc(1024, "output buffer");
79 rc_enc = gsm0808_enc_cause(msg, 0x41);
80 EXPECT_ENCODED("04 01 41");
81 msgb_free(msg);
82
83 /* Test with an extended (two byte) cause code */
84 msg = msgb_alloc(1024, "output buffer");
85 rc_enc = gsm0808_enc_cause(msg, 0x8041);
86 EXPECT_ENCODED("04 02 80 41");
87 msgb_free(msg);
88}
89
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +010090static void test_create_layer3(void)
91{
92 static const uint8_t res[] = {
93 0x00, 0x0e, 0x57, 0x05, 0x08, 0x00, 0x77, 0x62,
94 0x83, 0x33, 0x66, 0x44, 0x88, 0x17, 0x01, 0x23 };
95 struct msgb *msg, *in_msg;
Neels Hofmeyr178bf7a2018-04-20 12:23:45 +020096 struct osmo_cell_global_id cgi = {
97 .lai = {
98 .plmn = {
99 .mcc = 0x2244,
100 .mnc = 0x1122,
101 },
102 .lac = 0x3366,
103 },
104 .cell_identity = 0x4488,
105 };
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100106 printf("Testing creating Layer3\n");
107
108 in_msg = msgb_alloc_headroom(512, 128, "foo");
109 in_msg->l3h = in_msg->data;
110 msgb_v_put(in_msg, 0x23);
111
Neels Hofmeyr178bf7a2018-04-20 12:23:45 +0200112 msg = gsm0808_create_layer3_2(in_msg, &cgi, NULL);
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100113 VERIFY(msg, res, ARRAY_SIZE(res));
114 msgb_free(msg);
115 msgb_free(in_msg);
116}
117
Philipp Maierfa896ab2017-03-27 16:55:32 +0200118static void test_create_layer3_aoip()
119{
120 static const uint8_t res[] = {
121 0x00, 0x17, 0x57, 0x05, 0x08, 0x00, 0x77, 0x62,
122 0x83, 0x33, 0x66, 0x44, 0x88, 0x17, 0x01, 0x23,
Philipp Maierbb839662017-06-01 17:11:19 +0200123 GSM0808_IE_SPEECH_CODEC_LIST, 0x07, GSM0808_SCT_FR3 | 0x50,
Philipp Maier7e27b142018-03-22 17:26:46 +0100124 0xef, 0xcd, GSM0808_SCT_FR2 | 0xa0, 0x9f,
Philipp Maierbb839662017-06-01 17:11:19 +0200125 GSM0808_SCT_CSD | 0x90, 0xc0
Philipp Maierfa896ab2017-03-27 16:55:32 +0200126 };
Maxfa3b4822018-11-05 14:59:54 +0100127 struct osmo_cell_global_id cgi = {
128 .lai = {
129 .plmn = {
130 .mcc = 0x2244,
131 .mnc = 0x1122,
132 },
133 .lac = 0x3366,
134 },
135 .cell_identity = 0x4488,
136 };
Philipp Maierfa896ab2017-03-27 16:55:32 +0200137 struct msgb *msg, *in_msg;
138 struct gsm0808_speech_codec_list sc_list;
139 printf("Testing creating Layer3 (AoIP)\n");
140
141 setup_codec_list(&sc_list);
142
143 in_msg = msgb_alloc_headroom(512, 128, "foo");
144 in_msg->l3h = in_msg->data;
145 msgb_v_put(in_msg, 0x23);
146
Maxfa3b4822018-11-05 14:59:54 +0100147 msg = gsm0808_create_layer3_2(in_msg, &cgi, &sc_list);
148
Philipp Maierfa896ab2017-03-27 16:55:32 +0200149 VERIFY(msg, res, ARRAY_SIZE(res));
150
151 msgb_free(msg);
152 msgb_free(in_msg);
153}
154
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100155static void test_create_reset()
156{
157 static const uint8_t res[] = { 0x00, 0x04, 0x30, 0x04, 0x01, 0x20 };
158 struct msgb *msg;
159
160 printf("Testing creating Reset\n");
161 msg = gsm0808_create_reset();
162 VERIFY(msg, res, ARRAY_SIZE(res));
163 msgb_free(msg);
164}
165
Philipp Maier15596e22017-04-05 17:55:27 +0200166static void test_create_reset_ack()
167{
168 static const uint8_t res[] = { 0x00, 0x01, 0x31 };
169 struct msgb *msg;
170
171 printf("Testing creating Reset Ack\n");
172 msg = gsm0808_create_reset_ack();
173 VERIFY(msg, res, ARRAY_SIZE(res));
174 msgb_free(msg);
175}
176
177
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100178static void test_create_clear_command()
179{
180 static const uint8_t res[] = { 0x20, 0x04, 0x01, 0x23 };
181 struct msgb *msg;
182
183 printf("Testing creating Clear Command\n");
184 msg = gsm0808_create_clear_command(0x23);
185 VERIFY(msg, res, ARRAY_SIZE(res));
186 msgb_free(msg);
187}
188
189static void test_create_clear_complete()
190{
191 static const uint8_t res[] = { 0x00, 0x01, 0x21 };
192 struct msgb *msg;
193
194 printf("Testing creating Clear Complete\n");
195 msg = gsm0808_create_clear_complete();
196 VERIFY(msg, res, ARRAY_SIZE(res));
197 msgb_free(msg);
198}
199
Philipp Maierb478dd32017-03-29 15:50:05 +0200200static void test_create_cipher()
201{
202 static const uint8_t res[] =
203 { 0x00, 0x0c, 0x53, 0x0a, 0x09, 0x03, 0xaa,
204 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x23, 0x42 };
205 static const uint8_t res2[] =
206 { 0x00, 0x0e, 0x53, 0x0a, 0x09, 0x03, 0xaa,
207 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x23, 0x42,
208 GSM0808_IE_CIPHER_RESPONSE_MODE, 0x01 };
209 struct msgb *msg;
210 struct gsm0808_encrypt_info ei;
211 uint8_t include_imeisv;
212
213 memset(&ei, 0, sizeof(ei));
214 ei.perm_algo[0] = GSM0808_ALG_ID_A5_0;
215 ei.perm_algo[1] = GSM0808_ALG_ID_A5_1;
216 ei.perm_algo_len = 2;
217 ei.key[0] = 0xaa;
218 ei.key[1] = 0xbb;
219 ei.key[2] = 0xcc;
220 ei.key[3] = 0xdd;
221 ei.key[4] = 0xee;
222 ei.key[5] = 0xff;
223 ei.key[6] = 0x23;
224 ei.key[7] = 0x42;
225 ei.key_len = 8;
226 include_imeisv = 1;
227
228 printf("Testing creating Chipher Mode Command\n");
229 msg = gsm0808_create_cipher(&ei, NULL);
230 OSMO_ASSERT(msg);
231 VERIFY(msg, res, ARRAY_SIZE(res));
232 msgb_free(msg);
233
234 msg = gsm0808_create_cipher(&ei, &include_imeisv);
235 OSMO_ASSERT(msg);
236 VERIFY(msg, res2, ARRAY_SIZE(res2));
237 msgb_free(msg);
238}
239
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100240static void test_create_cipher_complete()
241{
242 static const uint8_t res1[] = {
243 0x00, 0x08, 0x55, 0x20, 0x03, 0x23, 0x42, 0x21, 0x2c, 0x04 };
244 static const uint8_t res2[] = { 0x00, 0x03, 0x55, 0x2c, 0x04};
245 struct msgb *l3, *msg;
246
247 printf("Testing creating Cipher Complete\n");
248 l3 = msgb_alloc_headroom(512, 128, "l3h");
249 l3->l3h = l3->data;
250 msgb_v_put(l3, 0x23);
251 msgb_v_put(l3, 0x42);
252 msgb_v_put(l3, 0x21);
253
254 /* with l3 data */
255 msg = gsm0808_create_cipher_complete(l3, 4);
256 VERIFY(msg, res1, ARRAY_SIZE(res1));
257 msgb_free(msg);
258
259 /* with l3 data but short */
260 l3->len -= 1;
261 l3->tail -= 1;
262 msg = gsm0808_create_cipher_complete(l3, 4);
263 VERIFY(msg, res2, ARRAY_SIZE(res2));
264 msgb_free(msg);
265
266 /* without l3 data */
267 msg = gsm0808_create_cipher_complete(NULL, 4);
268 VERIFY(msg, res2, ARRAY_SIZE(res2));
269 msgb_free(msg);
270
271
272 msgb_free(l3);
273}
274
Maxed651d22018-11-07 15:25:05 +0100275static inline void parse_cipher_reject(struct msgb *msg, uint8_t exp)
276{
277 struct tlv_parsed tp;
278 int rc;
279
280 /* skip header and message type so we can parse Cause IE directly */
281 msg->l2h = msgb_data(msg) + sizeof(struct bssmap_header) + 1;
282
283 rc = osmo_bssap_tlv_parse(&tp, msg->l2h, msgb_l2len(msg));
284 if (rc < 0)
285 printf("FIXME: failed (%d) to parse created message %s\n", rc, msgb_hexdump(msg));
286
287 rc = gsm0808_get_cipher_reject_cause(&tp);
288 if (rc < 0)
289 printf("FIXME: failed (%s) to extract Cause from created message %s\n",
290 strerror(-rc), msgb_hexdump(msg));
291
292 if (exp != (enum gsm0808_cause)rc)
293 printf("FIXME: wrong Cause %d != %u (" OSMO_BIN_SPEC ") extracted from created message %s\n",
294 rc, exp, OSMO_BIT_PRINT(exp), msgb_hexdump(msg));
295}
296
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100297static void test_create_cipher_reject()
298{
Harald Welte62e40852017-12-17 20:50:34 +0100299 static const uint8_t res[] = { 0x00, 0x04, 0x59, 0x04, 0x01, 0x23 };
Maxed651d22018-11-07 15:25:05 +0100300 enum gsm0808_cause cause = GSM0808_CAUSE_CCCH_OVERLOAD;
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100301 struct msgb *msg;
302
303 printf("Testing creating Cipher Reject\n");
Maxed651d22018-11-07 15:25:05 +0100304 msg = gsm0808_create_cipher_reject(cause);
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100305 VERIFY(msg, res, ARRAY_SIZE(res));
Maxed651d22018-11-07 15:25:05 +0100306
307 parse_cipher_reject(msg, cause);
308
309 msgb_free(msg);
310}
311
312static void test_create_cipher_reject_ext()
313{
314 static const uint8_t res[] = { 0x00, 0x05, 0x59, 0x04, 0x02, 0xd0, 0xFA };
315 uint8_t cause = 0xFA;
316 struct msgb *msg;
317
318 printf("Testing creating Cipher Reject (extended)\n");
319 msg = gsm0808_create_cipher_reject_ext(GSM0808_CAUSE_CLASS_INVAL, cause);
320 VERIFY(msg, res, ARRAY_SIZE(res));
321
322 parse_cipher_reject(msg, cause);
323
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100324 msgb_free(msg);
325}
326
327static void test_create_cm_u()
328{
Harald Welte07b625d2012-01-23 10:02:58 +0100329 static const uint8_t res[] = {
330 0x00, 0x07, 0x54, 0x12, 0x01, 0x23, 0x13, 0x01, 0x42 };
331 static const uint8_t res2o[] = {
332 0x00, 0x04, 0x54, 0x12, 0x01, 0x23 };
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100333 struct msgb *msg;
Harald Welte07b625d2012-01-23 10:02:58 +0100334 const uint8_t cm2 = 0x23;
335 const uint8_t cm3 = 0x42;
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100336
337 printf("Testing creating CM U\n");
Harald Welte07b625d2012-01-23 10:02:58 +0100338 msg = gsm0808_create_classmark_update(&cm2, 1, &cm3, 1);
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100339 VERIFY(msg, res, ARRAY_SIZE(res));
Harald Welte07b625d2012-01-23 10:02:58 +0100340
Neels Hofmeyr9a938ae2017-11-16 17:34:07 +0100341 msgb_free(msg);
342
Harald Welte07b625d2012-01-23 10:02:58 +0100343 msg = gsm0808_create_classmark_update(&cm2, 1, NULL, 0);
344 VERIFY(msg, res2o, ARRAY_SIZE(res2o));
345
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100346 msgb_free(msg);
347}
348
349static void test_create_sapi_reject()
350{
351 static const uint8_t res[] = { 0x00, 0x03, 0x25, 0x03, 0x25 };
352 struct msgb *msg;
353
354 printf("Testing creating SAPI Reject\n");
355 msg = gsm0808_create_sapi_reject(3);
356 VERIFY(msg, res, ARRAY_SIZE(res));
357 msgb_free(msg);
358}
359
Philipp Maierc6144a22017-03-29 17:53:43 +0200360static void test_create_ass()
361{
362 static const uint8_t res1[] =
363 { 0x00, 0x0a, 0x01, 0x0b, 0x04, 0x01, 0x0b, 0xa1, 0x25, 0x01, 0x00,
364 0x04 };
365 static const uint8_t res2[] =
366 { 0x00, 0x20, 0x01, 0x0b, 0x04, 0x01, 0x0b, 0xa1, 0x25, 0x01, 0x00,
367 0x04, GSM0808_IE_AOIP_TRASP_ADDR, 0x06, 0xc0, 0xa8, 0x64, 0x17,
Philipp Maierbb839662017-06-01 17:11:19 +0200368 0x04, 0xd2, GSM0808_IE_SPEECH_CODEC_LIST, 0x07,
Philipp Maier7e27b142018-03-22 17:26:46 +0100369 GSM0808_SCT_FR3 | 0x50, 0xef, 0xcd, GSM0808_SCT_FR2 | 0xa0, 0x9f,
Philipp Maierbb839662017-06-01 17:11:19 +0200370 GSM0808_SCT_CSD | 0x90, 0xc0, GSM0808_IE_CALL_ID, 0xaa, 0xbb,
371 0xcc, 0xdd };
Philipp Maierc6144a22017-03-29 17:53:43 +0200372
373 struct msgb *msg;
374 struct gsm0808_channel_type ct;
375 uint16_t cic = 0004;
376 struct sockaddr_storage ss;
377 struct sockaddr_in sin;
378 struct gsm0808_speech_codec_list sc_list;
379 uint32_t call_id = 0xAABBCCDD;
380
381 memset(&ct, 0, sizeof(ct));
382 ct.ch_indctr = GSM0808_CHAN_SPEECH;
383 ct.ch_rate_type = GSM0808_SPEECH_HALF_PREF;
384 ct.perm_spch[0] = GSM0808_PERM_FR3;
385 ct.perm_spch[1] = GSM0808_PERM_HR3;
386 ct.perm_spch_len = 2;
387
388 memset(&sin, 0, sizeof(sin));
389 sin.sin_family = AF_INET;
390 sin.sin_port = htons(1234);
391 inet_aton("192.168.100.23", &sin.sin_addr);
392
393 memset(&ss, 0, sizeof(ss));
394 memcpy(&ss, &sin, sizeof(sin));
395
396 setup_codec_list(&sc_list);
397
398 printf("Testing creating Assignment Request\n");
399 msg = gsm0808_create_ass(&ct, &cic, NULL, NULL, NULL);
400 OSMO_ASSERT(msg);
401 VERIFY(msg, res1, ARRAY_SIZE(res1));
402 msgb_free(msg);
403
404 msg = gsm0808_create_ass(&ct, &cic, &ss, &sc_list, &call_id);
405 OSMO_ASSERT(msg);
406 VERIFY(msg, res2, ARRAY_SIZE(res2));
407 msgb_free(msg);
408}
409
Max52074322018-11-30 10:44:07 +0100410static void test_create_ass2()
411{
412 static const uint8_t res[] = {
413 BSSAP_MSG_BSS_MANAGEMENT,
414 0x45,
415 BSS_MAP_MSG_ASSIGMENT_RQST,
416 GSM0808_IE_CHANNEL_TYPE,
417 0x04, 0x01, 0x0b, 0x91, 0x15, 0x01, 0x00, 0x04,
418 GSM0808_IE_AOIP_TRASP_ADDR,
419 0x06,
420 0xac, 0x0c, 0x65, 0x0d, /* IPv4 */
421 0x02, 0x9a,
422 GSM0808_IE_SPEECH_CODEC_LIST,
423 0x07,
424 GSM0808_SCT_FR3 | 0x50,
425 0xef, 0xcd,
426 GSM0808_SCT_FR2 | 0xa0,
427 0x9f,
428 GSM0808_SCT_CSD | 0x90,
429 0xc0,
430 GSM0808_IE_CALL_ID,
431 0xde, 0xad, 0xfa, 0xce, /* CallID */
432 0x83, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, /* Kc */
433 GSM0808_IE_GLOBAL_CALL_REF, 0x0d, /* GCR, length */
434 0x03, 0x44, 0x44, 0x44, /* GCR, Net ID */
435 0x02, 0xfe, 0xed, /* GCR, Node ID */
436 0x05, 0x41, 0x41, 0x41, 0x41, 0x41, /* GCR, Call ref. ID */
437 GSM0808_IE_LCLS_CONFIG, GSM0808_LCLS_CFG_BOTH_WAY,
438 GSM0808_IE_LCLS_CONN_STATUS_CTRL, GSM0808_LCLS_CSC_CONNECT,
439 GSM0808_IE_LCLS_CORR_NOT_NEEDED,
440 };
441 struct msgb *msg;
442 struct gsm0808_channel_type ct;
443 uint16_t cic = 4;
444 struct sockaddr_storage ss;
445 struct sockaddr_in sin;
446 struct gsm0808_speech_codec_list sc_list;
447 uint32_t call_id = 0xDEADFACE;
448 struct osmo_gcr_parsed gcr = { .net_len = 3, .node = 0xFEED };
449 uint8_t Kc[16];
450 struct osmo_lcls lcls = {
451 .config = GSM0808_LCLS_CFG_BOTH_WAY,
452 .control = GSM0808_LCLS_CSC_CONNECT,
453 .gcr = &gcr,
454 .corr_needed = false
455 };
456
457 memset(gcr.cr, 'A', 5);
458 memset(gcr.net, 'D', gcr.net_len);
459 memset(Kc, 'E', 16);
460
461 memset(&ct, 0, sizeof(ct));
462 ct.ch_indctr = GSM0808_CHAN_SPEECH;
463 ct.ch_rate_type = GSM0808_SPEECH_HALF_PREF;
464 ct.perm_spch[0] = GSM0808_PERM_FR2;
465 ct.perm_spch[1] = GSM0808_PERM_HR2;
466 ct.perm_spch_len = 2;
467
468 memset(&sin, 0, sizeof(sin));
469 sin.sin_family = AF_INET;
470 sin.sin_port = htons(666);
471 inet_aton("172.12.101.13", &sin.sin_addr); /* IPv4 */
472
473 memset(&ss, 0, sizeof(ss));
474 memcpy(&ss, &sin, sizeof(sin));
475
476 setup_codec_list(&sc_list);
477
478 printf("Testing creating Assignment Request with Kc and LCLS\n");
479
480 msg = gsm0808_create_ass2(&ct, &cic, &ss, &sc_list, &call_id, Kc, &lcls);
481 if (!msgb_eq_l3_data_print(msg, res, ARRAY_SIZE(res)))
482 abort();
483
484 msgb_free(msg);
485}
486
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100487static void test_create_ass_compl()
488{
489 static const uint8_t res1[] = {
490 0x00, 0x09, 0x02, 0x15, 0x23, 0x21, 0x42, 0x2c,
491 0x11, 0x40, 0x22 };
492 static const uint8_t res2[] = {
493 0x00, 0x07, 0x02, 0x15, 0x23, 0x21, 0x42, 0x2c, 0x11};
494 struct msgb *msg;
495
496 printf("Testing creating Assignment Complete\n");
497 msg = gsm0808_create_assignment_completed(0x23, 0x42, 0x11, 0x22);
498 VERIFY(msg, res1, ARRAY_SIZE(res1));
499 msgb_free(msg);
500
501 msg = gsm0808_create_assignment_completed(0x23, 0x42, 0x11, 0);
502 VERIFY(msg, res2, ARRAY_SIZE(res2));
503 msgb_free(msg);
504}
505
Philipp Maierfa896ab2017-03-27 16:55:32 +0200506static void test_create_ass_compl_aoip()
507{
508 struct sockaddr_storage ss;
509 struct sockaddr_in sin;
510 struct gsm0808_speech_codec sc;
511 struct gsm0808_speech_codec_list sc_list;
512 static const uint8_t res[] =
513 { 0x00, 0x1d, 0x02, 0x15, 0x23, 0x21, 0x42, 0x2c, 0x11, 0x40, 0x22,
514 GSM0808_IE_AOIP_TRASP_ADDR, 0x06, 0xc0, 0xa8, 0x64, 0x17, 0x04,
Philipp Maierbb839662017-06-01 17:11:19 +0200515 0xd2, GSM0808_IE_SPEECH_CODEC, 0x01, GSM0808_SCT_HR1 | 0x90,
Philipp Maier7e27b142018-03-22 17:26:46 +0100516 GSM0808_IE_SPEECH_CODEC_LIST, 0x07, GSM0808_SCT_FR3 | 0x50, 0xef,
517 0xcd, GSM0808_SCT_FR2 | 0xa0, 0x9f, GSM0808_SCT_CSD | 0x90, 0xc0 };
Philipp Maierfa896ab2017-03-27 16:55:32 +0200518 struct msgb *msg;
519
520 memset(&sin, 0, sizeof(sin));
521 sin.sin_family = AF_INET;
522 sin.sin_port = htons(1234);
523 inet_aton("192.168.100.23", &sin.sin_addr);
524
525 memset(&ss, 0, sizeof(ss));
526 memcpy(&ss, &sin, sizeof(sin));
527
528 memset(&sc, 0, sizeof(sc));
529 sc.fi = true;
530 sc.tf = true;
Philipp Maierbb839662017-06-01 17:11:19 +0200531 sc.type = GSM0808_SCT_HR1;
Philipp Maierfa896ab2017-03-27 16:55:32 +0200532
533 setup_codec_list(&sc_list);
534
535 printf("Testing creating Assignment Complete (AoIP)\n");
536 msg = gsm0808_create_ass_compl(0x23, 0x42, 0x11, 0x22,
537 &ss, &sc, &sc_list);
538 VERIFY(msg, res, ARRAY_SIZE(res));
539 msgb_free(msg);
540}
541
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100542static void test_create_ass_fail()
543{
544 static const uint8_t res1[] = { 0x00, 0x04, 0x03, 0x04, 0x01, 0x23 };
545 static const uint8_t res2[] = {
546 0x00, 0x06, 0x03, 0x04, 0x01, 0x23, 0x15, 0x02};
547 uint8_t rr_res = 2;
548 struct msgb *msg;
549
550 printf("Testing creating Assignment Failure\n");
551 msg = gsm0808_create_assignment_failure(0x23, NULL);
552 VERIFY(msg, res1, ARRAY_SIZE(res1));
553 msgb_free(msg);
554
555 msg = gsm0808_create_assignment_failure(0x23, &rr_res);
556 VERIFY(msg, res2, ARRAY_SIZE(res2));
557 msgb_free(msg);
558}
559
Philipp Maierfa896ab2017-03-27 16:55:32 +0200560static void test_create_ass_fail_aoip()
561{
562 static const uint8_t res1[] =
563 { 0x00, 0x0d, 0x03, 0x04, 0x01, 0x23, GSM0808_IE_SPEECH_CODEC_LIST,
Philipp Maier7e27b142018-03-22 17:26:46 +0100564 0x07, GSM0808_SCT_FR3 | 0x50, 0xef, 0xcd, GSM0808_SCT_FR2 | 0xa0,
Philipp Maierbb839662017-06-01 17:11:19 +0200565 0x9f, GSM0808_SCT_CSD | 0x90, 0xc0 };
Philipp Maierfa896ab2017-03-27 16:55:32 +0200566 static const uint8_t res2[] =
567 { 0x00, 0x0f, 0x03, 0x04, 0x01, 0x23, 0x15, 0x02,
Philipp Maier7e27b142018-03-22 17:26:46 +0100568 GSM0808_IE_SPEECH_CODEC_LIST, 0x07, GSM0808_SCT_FR3 | 0x50, 0xef,
569 0xcd, GSM0808_SCT_FR2 | 0xa0, 0x9f, GSM0808_SCT_CSD | 0x90, 0xc0 };
Philipp Maierfa896ab2017-03-27 16:55:32 +0200570 uint8_t rr_res = 2;
571 struct msgb *msg;
572 struct gsm0808_speech_codec_list sc_list;
573
574 setup_codec_list(&sc_list);
575
576 printf("Testing creating Assignment Failure (AoIP)\n");
577 msg = gsm0808_create_ass_fail(0x23, NULL, &sc_list);
578 VERIFY(msg, res1, ARRAY_SIZE(res1));
579 msgb_free(msg);
580
581 msg = gsm0808_create_ass_fail(0x23, &rr_res, &sc_list);
582 VERIFY(msg, res2, ARRAY_SIZE(res2));
583 msgb_free(msg);
584}
585
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100586static void test_create_clear_rqst()
587{
588 static const uint8_t res[] = { 0x00, 0x04, 0x22, 0x04, 0x01, 0x23 };
589 struct msgb *msg;
590
591 printf("Testing creating Clear Request\n");
592 msg = gsm0808_create_clear_rqst(0x23);
593 VERIFY(msg, res, ARRAY_SIZE(res));
594 msgb_free(msg);
595}
596
Philipp Maier3d48ec02017-03-29 17:37:55 +0200597static void test_create_paging()
598{
599 static const uint8_t res[] =
600 { 0x00, 0x10, 0x52, 0x08, 0x08, 0x09, 0x10, 0x10, 0x00, 0x00, 0x00,
601 0x21, 0x43, 0x1a, 0x03, 0x05, 0x23, 0x42 };
602 static const uint8_t res2[] =
603 { 0x00, 0x16, 0x52, 0x08, 0x08, 0x09, 0x10, 0x10, 0x00, 0x00, 0x00,
604 0x21, 0x43, GSM0808_IE_TMSI, 0x04, 0x12, 0x34, 0x56, 0x78, 0x1a,
605 0x03, 0x05, 0x23, 0x42 };
606 static const uint8_t res3[] =
607 { 0x00, 0x18, 0x52, 0x08, 0x08, 0x09, 0x10, 0x10, 0x00, 0x00, 0x00,
608 0x21, 0x43, GSM0808_IE_TMSI, 0x04, 0x12, 0x34, 0x56, 0x78, 0x1a,
609 0x03, 0x05, 0x23, 0x42, GSM0808_IE_CHANNEL_NEEDED,
610 RSL_CHANNEED_TCH_ForH };
611
612 struct msgb *msg;
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100613 struct gsm0808_cell_id_list2 cil;
Philipp Maier3d48ec02017-03-29 17:37:55 +0200614 uint32_t tmsi = 0x12345678;
615 uint8_t chan_needed = RSL_CHANNEED_TCH_ForH;
616
617 char imsi[] = "001010000001234";
618
619 cil.id_discr = CELL_IDENT_LAC;
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100620 cil.id_list[0].lac = 0x2342;
Philipp Maier3d48ec02017-03-29 17:37:55 +0200621 cil.id_list_len = 1;
622
623 printf("Testing creating Paging Request\n");
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100624 msg = gsm0808_create_paging2(imsi, NULL, &cil, NULL);
Philipp Maier3d48ec02017-03-29 17:37:55 +0200625 VERIFY(msg, res, ARRAY_SIZE(res));
626 msgb_free(msg);
627
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100628 msg = gsm0808_create_paging2(imsi, &tmsi, &cil, NULL);
Philipp Maier3d48ec02017-03-29 17:37:55 +0200629 VERIFY(msg, res2, ARRAY_SIZE(res2));
630 msgb_free(msg);
631
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100632 msg = gsm0808_create_paging2(imsi, &tmsi, &cil, &chan_needed);
Philipp Maier3d48ec02017-03-29 17:37:55 +0200633 VERIFY(msg, res3, ARRAY_SIZE(res3));
634 msgb_free(msg);
635}
636
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100637static void test_create_dtap()
638{
639 static const uint8_t res[] = { 0x01, 0x03, 0x02, 0x23, 0x42 };
640 struct msgb *msg, *l3;
641
642 printf("Testing creating DTAP\n");
643 l3 = msgb_alloc_headroom(512, 128, "test");
644 l3->l3h = l3->data;
645 msgb_v_put(l3, 0x23);
646 msgb_v_put(l3, 0x42);
647
648 msg = gsm0808_create_dtap(l3, 0x3);
649 VERIFY(msg, res, ARRAY_SIZE(res));
650 msgb_free(msg);
651 msgb_free(l3);
652}
653
654static void test_prepend_dtap()
655{
656 static const uint8_t res[] = { 0x01, 0x03, 0x02, 0x23, 0x42 };
657 struct msgb *in_msg;
658
659 printf("Testing prepend DTAP\n");
660
661 in_msg = msgb_alloc_headroom(512, 128, "test");
662 msgb_v_put(in_msg, 0x23);
663 msgb_v_put(in_msg, 0x42);
664
665 gsm0808_prepend_dtap_header(in_msg, 0x3);
666 in_msg->l3h = in_msg->data;
667 VERIFY(in_msg, res, ARRAY_SIZE(res));
668 msgb_free(in_msg);
669}
670
Max47022152018-12-19 18:51:00 +0100671static void test_enc_dec_lcls()
Max969fb2e2018-12-10 11:01:10 +0100672{
673 static const uint8_t res[] = {
674 GSM0808_IE_GLOBAL_CALL_REF,
675 0x0d, /* GCR length */
676 0x03, /* .net_len */
677 0xf1, 0xf2, 0xf3, /* .net */
678 0x02, /* .node length */
679 0xde, 0xad, /* .node */
680 0x05, /* length of Call. Ref. */
681 0x41, 0x42, 0x43, 0x44, 0x45 /* .cr - Call. Ref. */
682 };
683 uint8_t len;
684 struct msgb *msg;
685 struct osmo_gcr_parsed p = { 0 }, g = {
686 .net_len = 3,
687 .net = { 0xf1, 0xf2, 0xf3 },
688 .node = 0xDEAD,
689 .cr = { 0x41, 0x42, 0x43, 0x44, 0x45 },
690 };
691 int rc;
692 struct tlv_parsed tp;
Max47022152018-12-19 18:51:00 +0100693 struct osmo_lcls lcls_out = { .gcr = &p }, lcls_in = {
694 .gcr = &g,
695 .config = GSM0808_LCLS_CFG_NA,
696 .control = GSM0808_LCLS_CSC_NA,
697 .corr_needed = true,
698 };
699
700 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "LCLS IE");
Max969fb2e2018-12-10 11:01:10 +0100701 if (!msg)
702 return;
703
Max47022152018-12-19 18:51:00 +0100704 len = gsm0808_enc_lcls(msg, &lcls_in);
Max969fb2e2018-12-10 11:01:10 +0100705 printf("Testing Global Call Reference IE encoder...\n\t%d bytes added: %s\n",
706 len, len == ARRAY_SIZE(res) ? "OK" : "FAIL");
707
708 if (!msgb_eq_data_print(msg, res, ARRAY_SIZE(res)))
709 abort();
710
711 rc = osmo_bssap_tlv_parse(&tp, msgb_data(msg), msgb_length(msg));
712 if (rc < 0) {
713 printf("parsing failed: %s [%s]\n", strerror(-rc), msgb_hexdump(msg));
714 abort();
715 }
716
Max47022152018-12-19 18:51:00 +0100717 rc = gsm0808_dec_lcls(&lcls_out, &tp);
Max969fb2e2018-12-10 11:01:10 +0100718 if (rc < 0) {
719 printf("decoding failed: %s [%s]\n", strerror(-rc), msgb_hexdump(msg));
720 abort();
721 }
722
Max4fd64e52019-01-14 19:27:44 +0100723 if (lcls_out.config != lcls_in.config) {
724 printf("LCLS Config parsed wrong: %s != %s\n",
725 gsm0808_lcls_config_name(lcls_out.config), gsm0808_lcls_config_name(lcls_in.config));
726 abort();
727 }
728
729 if (lcls_out.control != lcls_in.control) {
730 printf("LCLS Control parsed wrong: %s != %s\n",
731 gsm0808_lcls_control_name(lcls_out.control), gsm0808_lcls_control_name(lcls_in.control));
732 abort();
733 }
734
Max1bec3902019-01-14 19:31:42 +0100735 if (!osmo_gcr_eq(lcls_out.gcr, lcls_in.gcr)) {
736 printf("GCR parsed wrong.\n");
737 abort();
738 }
Max969fb2e2018-12-10 11:01:10 +0100739
740 printf("\tdecoded %d bytes: %s\n", rc, rc == len ? "OK" : "FAIL");
741 msgb_free(msg);
742}
743
Philipp Maier22401432017-03-24 17:59:26 +0100744static void test_enc_dec_aoip_trasp_addr_v4()
745{
746 struct sockaddr_storage enc_addr;
747 struct sockaddr_storage dec_addr;
748 struct sockaddr_in enc_addr_in;
749 struct msgb *msg;
750 uint8_t rc_enc;
751 int rc_dec;
752
753 memset(&enc_addr_in, 0, sizeof(enc_addr_in));
754 enc_addr_in.sin_family = AF_INET;
755 enc_addr_in.sin_port = htons(1234);
756 inet_aton("255.0.255.255", &enc_addr_in.sin_addr);
757
758 memset(&enc_addr, 0, sizeof(enc_addr));
759 memcpy(&enc_addr, &enc_addr_in, sizeof(enc_addr_in));
760
761 msg = msgb_alloc(1024, "output buffer");
762 rc_enc = gsm0808_enc_aoip_trasp_addr(msg, &enc_addr);
763 OSMO_ASSERT(rc_enc == 8);
764 rc_dec =
765 gsm0808_dec_aoip_trasp_addr(&dec_addr, msg->data + 2, msg->len - 2);
766 OSMO_ASSERT(rc_dec == 6);
767 OSMO_ASSERT(memcmp(&enc_addr, &dec_addr, sizeof(enc_addr)) == 0);
768
769 msgb_free(msg);
770}
771
772static void test_enc_dec_aoip_trasp_addr_v6()
773{
774 struct sockaddr_storage enc_addr;
775 struct sockaddr_storage dec_addr;
776 struct sockaddr_in6 enc_addr_in;
777 struct msgb *msg;
778 uint8_t rc_enc;
779 int rc_dec;
780
781 memset(&enc_addr_in, 0, sizeof(enc_addr_in));
782 enc_addr_in.sin6_family = AF_INET6;
783 enc_addr_in.sin6_port = htons(4567);
784 inet_pton(AF_INET6, "2001:0db8:85a3:08d3:1319:8a2e:0370:7344",
785 &enc_addr_in.sin6_addr);
786
787 memset(&enc_addr, 0, sizeof(enc_addr));
788 memcpy(&enc_addr, &enc_addr_in, sizeof(enc_addr_in));
789
790 msg = msgb_alloc(1024, "output buffer");
791 rc_enc = gsm0808_enc_aoip_trasp_addr(msg, &enc_addr);
792 OSMO_ASSERT(rc_enc == 20);
793 rc_dec =
794 gsm0808_dec_aoip_trasp_addr(&dec_addr, msg->data + 2, msg->len - 2);
795 OSMO_ASSERT(rc_dec == 18);
796 OSMO_ASSERT(memcmp(&enc_addr, &dec_addr, sizeof(enc_addr)) == 0);
797
798 msgb_free(msg);
799}
800
Philipp Maier6f725d62017-03-24 18:03:17 +0100801static void test_gsm0808_enc_dec_speech_codec()
802{
Neels Hofmeyr9a4286b2018-04-20 12:27:52 +0200803 struct gsm0808_speech_codec enc_sc = {
804 .pi = true,
805 .tf = true,
806 .type = GSM0808_SCT_FR2,
807 };
808 struct gsm0808_speech_codec dec_sc = {};
Philipp Maier6f725d62017-03-24 18:03:17 +0100809 struct msgb *msg;
810 uint8_t rc_enc;
811 int rc_dec;
812
Philipp Maier6f725d62017-03-24 18:03:17 +0100813 msg = msgb_alloc(1024, "output buffer");
814 rc_enc = gsm0808_enc_speech_codec(msg, &enc_sc);
815 OSMO_ASSERT(rc_enc == 3);
816
817 rc_dec = gsm0808_dec_speech_codec(&dec_sc, msg->data + 2, msg->len - 2);
818 OSMO_ASSERT(rc_dec == 1);
819
820 OSMO_ASSERT(memcmp(&enc_sc, &dec_sc, sizeof(enc_sc)) == 0);
821
822 msgb_free(msg);
823}
824
825
Philipp Maierbb839662017-06-01 17:11:19 +0200826static void test_gsm0808_enc_dec_speech_codec_with_cfg()
827{
Neels Hofmeyrc62c9342018-04-15 23:31:47 +0200828 struct gsm0808_speech_codec enc_sc = {
829 .pi = true,
830 .tf = true,
831 .type = GSM0808_SCT_FR3,
832 .cfg = 0xabcd,
833 };
834 struct gsm0808_speech_codec dec_sc = {};
Philipp Maierbb839662017-06-01 17:11:19 +0200835 struct msgb *msg;
836 uint8_t rc_enc;
837 int rc_dec;
838
Philipp Maierbb839662017-06-01 17:11:19 +0200839 msg = msgb_alloc(1024, "output buffer");
840 rc_enc = gsm0808_enc_speech_codec(msg, &enc_sc);
841 OSMO_ASSERT(rc_enc == 5);
842
843 rc_dec = gsm0808_dec_speech_codec(&dec_sc, msg->data + 2, msg->len - 2);
844 OSMO_ASSERT(rc_dec == 3);
845
846 OSMO_ASSERT(memcmp(&enc_sc, &dec_sc, sizeof(enc_sc)) == 0);
847
848 msgb_free(msg);
849}
850
Philipp Maier6f725d62017-03-24 18:03:17 +0100851static void test_gsm0808_enc_dec_speech_codec_ext_with_cfg()
852{
Neels Hofmeyr9a4286b2018-04-20 12:27:52 +0200853 struct gsm0808_speech_codec enc_sc = {
854 .pi = true,
855 .tf = true,
856 .type = GSM0808_SCT_CSD,
857 .cfg = 0xc0,
858 };
859 struct gsm0808_speech_codec dec_sc = {};
Philipp Maier6f725d62017-03-24 18:03:17 +0100860 struct msgb *msg;
861 uint8_t rc_enc;
862 int rc_dec;
863
Philipp Maier6f725d62017-03-24 18:03:17 +0100864 msg = msgb_alloc(1024, "output buffer");
865 rc_enc = gsm0808_enc_speech_codec(msg, &enc_sc);
Philipp Maierbb839662017-06-01 17:11:19 +0200866 OSMO_ASSERT(rc_enc == 5);
Philipp Maier6f725d62017-03-24 18:03:17 +0100867
868 rc_dec = gsm0808_dec_speech_codec(&dec_sc, msg->data + 2, msg->len - 2);
Philipp Maierbb839662017-06-01 17:11:19 +0200869 OSMO_ASSERT(rc_dec == 3);
Philipp Maier6f725d62017-03-24 18:03:17 +0100870
871 OSMO_ASSERT(memcmp(&enc_sc, &dec_sc, sizeof(enc_sc)) == 0);
872
873 msgb_free(msg);
874}
875
876static void test_gsm0808_enc_dec_speech_codec_list()
877{
Neels Hofmeyr9a4286b2018-04-20 12:27:52 +0200878 struct gsm0808_speech_codec_list enc_scl = {
879 .codec = {
880 {
881 .pi = true,
882 .tf = true,
883 .type = GSM0808_SCT_FR3,
884 .cfg = 0xcdef,
885 },
886
887 {
888 .fi = true,
889 .pt = true,
890 .type = GSM0808_SCT_FR2,
891 },
892
893 {
894 .fi = true,
895 .tf = true,
896 .type = GSM0808_SCT_CSD,
897 .cfg = 0xc0,
898 },
899 },
900 .len = 3,
901 };
902 struct gsm0808_speech_codec_list dec_scl = {};
Philipp Maier6f725d62017-03-24 18:03:17 +0100903 struct msgb *msg;
904 uint8_t rc_enc;
905 int rc_dec;
906
Philipp Maier6f725d62017-03-24 18:03:17 +0100907 msg = msgb_alloc(1024, "output buffer");
908 rc_enc = gsm0808_enc_speech_codec_list(msg, &enc_scl);
909 OSMO_ASSERT(rc_enc == 9);
910
911 rc_dec = gsm0808_dec_speech_codec_list(&dec_scl, msg->data + 2, msg->len - 2);
912 OSMO_ASSERT(rc_dec == 7);
913
914 OSMO_ASSERT(memcmp(&enc_scl, &dec_scl, sizeof(enc_scl)) == 0);
915
916 msgb_free(msg);
917}
918
Philipp Maierf6c369f2018-10-16 15:24:47 +0200919static void test_gsm0808_enc_dec_empty_speech_codec_list()
920{
921 struct gsm0808_speech_codec_list enc_scl = {
922 .len = 0,
923 };
924 struct gsm0808_speech_codec_list dec_scl = {};
925 struct msgb *msg;
926 uint8_t rc_enc;
927 int rc_dec;
928
929 msg = msgb_alloc(1024, "output buffer");
930 rc_enc = gsm0808_enc_speech_codec_list(msg, &enc_scl);
931 OSMO_ASSERT(rc_enc == 2);
932
933 rc_dec = gsm0808_dec_speech_codec_list(&dec_scl, msg->data + 2, msg->len - 2);
934 OSMO_ASSERT(rc_dec == 0);
935
936 OSMO_ASSERT(memcmp(&enc_scl, &dec_scl, sizeof(enc_scl)) == 0);
937
938 msgb_free(msg);
939}
940
Philipp Maiere0c65302017-03-28 17:05:40 +0200941static void test_gsm0808_enc_dec_channel_type()
942{
Neels Hofmeyr9a4286b2018-04-20 12:27:52 +0200943 struct gsm0808_channel_type enc_ct = {
944 .ch_indctr = GSM0808_CHAN_SPEECH,
945 .ch_rate_type = GSM0808_SPEECH_HALF_PREF,
946 .perm_spch = { GSM0808_PERM_FR3, GSM0808_PERM_HR3 },
947 .perm_spch_len = 2,
948 };
949 struct gsm0808_channel_type dec_ct = {};
Philipp Maiere0c65302017-03-28 17:05:40 +0200950 struct msgb *msg;
951 uint8_t ct_enc_expected[] = { GSM0808_IE_CHANNEL_TYPE,
952 0x04, 0x01, 0x0b, 0xa1, 0x25
953 };
954 uint8_t rc_enc;
955 int rc_dec;
956
Philipp Maiere0c65302017-03-28 17:05:40 +0200957 msg = msgb_alloc(1024, "output buffer");
958 rc_enc = gsm0808_enc_channel_type(msg, &enc_ct);
959 OSMO_ASSERT(rc_enc == 6);
960 OSMO_ASSERT(memcmp(ct_enc_expected, msg->data, msg->len) == 0);
961
962 rc_dec = gsm0808_dec_channel_type(&dec_ct, msg->data + 2, msg->len - 2);
963 OSMO_ASSERT(rc_dec == 4);
964 OSMO_ASSERT(memcmp(&enc_ct, &dec_ct, sizeof(enc_ct)) == 0);
965
966 msgb_free(msg);
967}
968
Philipp Maier14e76b92017-03-28 18:36:52 +0200969static void test_gsm0808_enc_dec_encrypt_info()
970{
Neels Hofmeyr9a4286b2018-04-20 12:27:52 +0200971 struct gsm0808_encrypt_info enc_ei = {
972 .perm_algo = { GSM0808_ALG_ID_A5_0, GSM0808_ALG_ID_A5_1 },
973 .perm_algo_len = 2,
974 .key = { 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x23, 0x42, },
975 .key_len = 8,
976 };
977 struct gsm0808_encrypt_info dec_ei = {};
Philipp Maier14e76b92017-03-28 18:36:52 +0200978 struct msgb *msg;
979 uint8_t ei_enc_expected[] =
980 { GSM0808_IE_ENCRYPTION_INFORMATION, 0x09, 0x03, 0xaa, 0xbb,
981 0xcc, 0xdd, 0xee, 0xff, 0x23, 0x42
982 };
983 uint8_t rc_enc;
984 int rc_dec;
985
Philipp Maier14e76b92017-03-28 18:36:52 +0200986 msg = msgb_alloc(1024, "output buffer");
987 rc_enc = gsm0808_enc_encrypt_info(msg, &enc_ei);
988 OSMO_ASSERT(rc_enc == 11);
989 OSMO_ASSERT(memcmp(ei_enc_expected, msg->data, msg->len) == 0);
990
991 rc_dec = gsm0808_dec_encrypt_info(&dec_ei, msg->data + 2, msg->len - 2);
992 OSMO_ASSERT(rc_dec == 9);
993
994 OSMO_ASSERT(memcmp(&enc_ei, &dec_ei, sizeof(enc_ei)) == 0);
995
996 msgb_free(msg);
997}
998
Philipp Maier783047e2017-03-29 11:35:50 +0200999static void test_gsm0808_enc_dec_cell_id_list_lac()
1000{
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001001 struct gsm0808_cell_id_list2 enc_cil;
1002 struct gsm0808_cell_id_list2 dec_cil;
Philipp Maier783047e2017-03-29 11:35:50 +02001003 struct msgb *msg;
1004 uint8_t rc_enc;
1005 int rc_dec;
1006
1007 memset(&enc_cil, 0, sizeof(enc_cil));
1008 enc_cil.id_discr = CELL_IDENT_LAC;
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001009 enc_cil.id_list[0].lac = 0x0124;
Neels Hofmeyrdb2fa4e2018-04-13 04:11:20 +02001010 enc_cil.id_list[1].lac = 0xABCD;
1011 enc_cil.id_list[2].lac = 0x5678;
Philipp Maier783047e2017-03-29 11:35:50 +02001012 enc_cil.id_list_len = 3;
1013
1014 msg = msgb_alloc(1024, "output buffer");
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001015 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
Neels Hofmeyrdb2fa4e2018-04-13 04:11:20 +02001016 EXPECT_ENCODED("1a 07 05 01 24 ab cd 56 78");
Philipp Maier783047e2017-03-29 11:35:50 +02001017
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001018 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
Philipp Maier783047e2017-03-29 11:35:50 +02001019 OSMO_ASSERT(rc_dec == 7);
1020
1021 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
1022
1023 msgb_free(msg);
1024}
1025
1026static void test_gsm0808_enc_dec_cell_id_list_single_lac()
1027{
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001028 struct gsm0808_cell_id_list2 enc_cil;
1029 struct gsm0808_cell_id_list2 dec_cil;
Philipp Maier783047e2017-03-29 11:35:50 +02001030 struct msgb *msg;
1031 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x03,
1032 0x05, 0x23, 0x42
1033 };
1034 uint8_t rc_enc;
1035 int rc_dec;
1036
1037 memset(&enc_cil, 0, sizeof(enc_cil));
1038 enc_cil.id_discr = CELL_IDENT_LAC;
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001039 enc_cil.id_list[0].lac = 0x2342;
Philipp Maier783047e2017-03-29 11:35:50 +02001040 enc_cil.id_list_len = 1;
1041
1042 msg = msgb_alloc(1024, "output buffer");
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001043 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
Philipp Maier783047e2017-03-29 11:35:50 +02001044 OSMO_ASSERT(rc_enc == 5);
1045 OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0);
1046
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001047 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
Philipp Maier783047e2017-03-29 11:35:50 +02001048 OSMO_ASSERT(rc_dec == 3);
1049
1050 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
1051
1052 msgb_free(msg);
1053}
1054
Stefan Sperlinge1a86742018-03-15 18:05:02 +01001055static void test_gsm0808_enc_dec_cell_id_list_multi_lac()
1056{
1057 struct gsm0808_cell_id_list2 enc_cil;
1058 struct gsm0808_cell_id_list2 dec_cil;
1059 struct msgb *msg;
1060 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x0b, 0x05,
1061 0x23, 0x42,
1062 0x24, 0x43,
1063 0x25, 0x44,
1064 0x26, 0x45,
1065 0x27, 0x46
1066 };
1067 uint8_t rc_enc;
1068 int rc_dec;
1069
1070 memset(&enc_cil, 0, sizeof(enc_cil));
1071 enc_cil.id_discr = CELL_IDENT_LAC;
1072 enc_cil.id_list[0].lac = 0x2342;
1073 enc_cil.id_list[1].lac = 0x2443;
1074 enc_cil.id_list[2].lac = 0x2544;
1075 enc_cil.id_list[3].lac = 0x2645;
1076 enc_cil.id_list[4].lac = 0x2746;
1077 enc_cil.id_list_len = 5;
1078
1079 msg = msgb_alloc(1024, "output buffer");
1080 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
1081 OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected));
1082 OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0);
1083
1084 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
1085 OSMO_ASSERT(rc_dec == msg->len - 2);
1086 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
1087
1088 msgb_free(msg);
1089}
1090
Philipp Maier783047e2017-03-29 11:35:50 +02001091static void test_gsm0808_enc_dec_cell_id_list_bss()
1092{
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001093 struct gsm0808_cell_id_list2 enc_cil;
1094 struct gsm0808_cell_id_list2 dec_cil;
Philipp Maier783047e2017-03-29 11:35:50 +02001095 struct msgb *msg;
1096 uint8_t rc_enc;
1097 int rc_dec;
1098
1099 memset(&enc_cil, 0, sizeof(enc_cil));
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001100 enc_cil.id_discr = CELL_IDENT_BSS;
Philipp Maier783047e2017-03-29 11:35:50 +02001101
1102 msg = msgb_alloc(1024, "output buffer");
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001103 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
Philipp Maier783047e2017-03-29 11:35:50 +02001104 OSMO_ASSERT(rc_enc == 3);
1105
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001106 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
Philipp Maier783047e2017-03-29 11:35:50 +02001107 OSMO_ASSERT(rc_dec == 1);
1108
1109 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
1110
1111 msgb_free(msg);
1112}
1113
Stefan Sperling23381452018-03-15 19:38:15 +01001114static void test_gsm0808_enc_dec_cell_id_list_multi_lai_and_lac()
1115{
1116 struct gsm0808_cell_id_list2 enc_cil;
1117 struct gsm0808_cell_id_list2 dec_cil;
1118 struct osmo_location_area_id id;
1119 struct msgb *msg;
1120 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x10, 0x04,
1121 0x92, 0x61, 0x54, 0x23, 0x42,
1122 0x92, 0x72, 0x54, 0x24, 0x43,
1123 0x92, 0x83, 0x54, 0x25, 0x44
1124 };
1125 uint8_t rc_enc;
1126 int rc_dec, i;
1127
1128 memset(&enc_cil, 0, sizeof(enc_cil));
1129 enc_cil.id_discr = CELL_IDENT_LAI_AND_LAC;
1130
1131 id.plmn.mcc = 0x123;
1132 osmo_mnc_from_str("456", &id.plmn.mnc, &id.plmn.mnc_3_digits);
1133 id.lac = 0x2342;
1134 memcpy(&enc_cil.id_list[0].lai_and_lac, &id, sizeof(id));
1135
1136 id.plmn.mcc = 0x124;
1137 osmo_mnc_from_str("457", &id.plmn.mnc, &id.plmn.mnc_3_digits);
1138 id.lac = 0x2443;
1139 memcpy(&enc_cil.id_list[1].lai_and_lac, &id, sizeof(id));
1140
1141 id.plmn.mcc = 0x125;
1142 osmo_mnc_from_str("458", &id.plmn.mnc, &id.plmn.mnc_3_digits);
1143 id.lac = 0x2544;
1144 memcpy(&enc_cil.id_list[2].lai_and_lac, &id, sizeof(id));
1145
1146 enc_cil.id_list_len = 3;
1147
1148 msg = msgb_alloc(1024, "output buffer");
1149 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
1150 OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected));
1151 OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0);
1152
1153 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
1154 OSMO_ASSERT(rc_dec == msg->len - 2);
1155
1156 OSMO_ASSERT(dec_cil.id_list_len == 3);
1157 /* Check MAXLEN elements to ensure everything has been initialized. */
1158 for (i = 0; i < GSM0808_CELL_ID_LIST2_MAXLEN; i++) {
1159 struct osmo_location_area_id *enc_id;
1160 struct osmo_location_area_id *dec_id;
1161 enc_id = &enc_cil.id_list[i].lai_and_lac;
1162 dec_id = &dec_cil.id_list[i].lai_and_lac;
1163 OSMO_ASSERT(osmo_plmn_cmp(&enc_id->plmn, &dec_id->plmn) == 0);
1164 OSMO_ASSERT(enc_id->lac == dec_id->lac);
1165 }
1166
1167 msgb_free(msg);
1168}
1169
Stefan Sperling9c62fc62018-03-16 10:23:34 +01001170static void test_gsm0808_enc_dec_cell_id_list_multi_ci()
1171{
1172 struct gsm0808_cell_id_list2 enc_cil;
1173 struct gsm0808_cell_id_list2 dec_cil;
1174 struct msgb *msg;
1175 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x09, 0x02,
1176 0x00, 0x01,
1177 0x00, 0x02,
1178 0x00, 0x77,
1179 0x01, 0xff,
1180 };
1181 uint8_t rc_enc;
1182 int rc_dec;
1183
1184 memset(&enc_cil, 0, sizeof(enc_cil));
1185 enc_cil.id_discr = CELL_IDENT_CI;
1186 enc_cil.id_list[0].ci = 1;
1187 enc_cil.id_list[1].ci = 2;
1188 enc_cil.id_list[2].ci = 119;
1189 enc_cil.id_list[3].ci = 511;
1190 enc_cil.id_list_len = 4;
1191
1192 msg = msgb_alloc(1024, "output buffer");
1193 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
1194 OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected));
1195 OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0);
1196
1197 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
1198 OSMO_ASSERT(rc_dec == msg->len - 2);
1199 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
1200
1201 msgb_free(msg);
1202}
1203
Stefan Sperlinged4327c2018-03-16 11:02:59 +01001204static void test_gsm0808_enc_dec_cell_id_list_multi_lac_and_ci()
1205{
1206 struct gsm0808_cell_id_list2 enc_cil;
1207 struct gsm0808_cell_id_list2 dec_cil;
1208 struct msgb *msg;
1209 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x15, 0x01,
1210 0x23, 0x42, 0x00, 0x01,
1211 0x24, 0x43, 0x00, 0x02,
1212 0x25, 0x44, 0x00, 0x77,
1213 0x26, 0x45, 0x01, 0xff,
1214 0x27, 0x46, 0x02, 0xfe,
1215 };
1216 uint8_t rc_enc;
1217 int rc_dec;
1218
1219 memset(&enc_cil, 0, sizeof(enc_cil));
1220 enc_cil.id_discr = CELL_IDENT_LAC_AND_CI;
1221 enc_cil.id_list[0].lac_and_ci.lac = 0x2342;
1222 enc_cil.id_list[0].lac_and_ci.ci = 1;
1223 enc_cil.id_list[1].lac_and_ci.lac = 0x2443;
1224 enc_cil.id_list[1].lac_and_ci.ci = 2;
1225 enc_cil.id_list[2].lac_and_ci.lac = 0x2544;
1226 enc_cil.id_list[2].lac_and_ci.ci = 119;
1227 enc_cil.id_list[3].lac_and_ci.lac = 0x2645;
1228 enc_cil.id_list[3].lac_and_ci.ci = 511;
1229 enc_cil.id_list[4].lac_and_ci.lac = 0x2746;
1230 enc_cil.id_list[4].lac_and_ci.ci = 766;
1231 enc_cil.id_list_len = 5;
1232
1233 msg = msgb_alloc(1024, "output buffer");
1234 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
1235 OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected));
1236 OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0);
1237
1238 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
1239 OSMO_ASSERT(rc_dec == msg->len - 2);
1240 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
1241
1242 msgb_free(msg);
1243}
1244
Stefan Sperling483f3862018-03-16 12:21:26 +01001245static void test_gsm0808_enc_dec_cell_id_list_multi_global()
1246{
1247 struct gsm0808_cell_id_list2 enc_cil;
1248 struct gsm0808_cell_id_list2 dec_cil;
1249 struct msgb *msg;
1250 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x16, 0x00,
Neels Hofmeyr473485c2018-03-23 02:04:18 +01001251 0x21, 0x63, 0x54, 0x23, 0x42, 0x00, 0x1,
Neels Hofmeyrc44fc232018-03-23 02:15:12 +01001252 0x21, 0xf4, 0x75, 0x24, 0x43, 0x00, 0x2,
Neels Hofmeyr8b8cd932018-03-23 01:47:37 +01001253 0x21, 0x75, 0x00, 0x25, 0x44, 0x00, 0x77
Stefan Sperling483f3862018-03-16 12:21:26 +01001254 };
Stefan Sperling483f3862018-03-16 12:21:26 +01001255 uint8_t rc_enc;
1256 int rc_dec, i;
1257
Neels Hofmeyrc1991df2018-03-23 02:00:00 +01001258 enc_cil = (struct gsm0808_cell_id_list2){
1259 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1260 .id_list_len = 3,
1261 .id_list = {
1262 {
1263 .global = {
Neels Hofmeyr473485c2018-03-23 02:04:18 +01001264 .lai = { .plmn = { .mcc = 123, .mnc = 456 },
Neels Hofmeyrc1991df2018-03-23 02:00:00 +01001265 .lac = 0x2342 },
1266 .cell_identity = 1,
1267 }
1268 },
1269 {
1270 .global = {
Neels Hofmeyrc44fc232018-03-23 02:15:12 +01001271 .lai = { .plmn = { .mcc = 124, .mnc = 57 },
Neels Hofmeyrc1991df2018-03-23 02:00:00 +01001272 .lac = 0x2443 },
1273 .cell_identity = 2,
1274 }
1275 },
1276 {
1277 .global = {
Neels Hofmeyrc44fc232018-03-23 02:15:12 +01001278 .lai = { .plmn = { .mcc = 125, .mnc = 7,
1279 .mnc_3_digits = true },
Neels Hofmeyrc1991df2018-03-23 02:00:00 +01001280 .lac = 0x2544 },
1281 .cell_identity = 119,
1282 }
1283 },
1284 }
1285 };
Stefan Sperling483f3862018-03-16 12:21:26 +01001286
1287 msg = msgb_alloc(1024, "output buffer");
1288 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
1289 OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected));
Neels Hofmeyrc1991df2018-03-23 02:00:00 +01001290 if (memcmp(cil_enc_expected, msg->data, msg->len)) {
1291 printf(" got: %s\n", osmo_hexdump(msg->data, msg->len));
1292 printf("expect: %s\n", osmo_hexdump(cil_enc_expected, sizeof(cil_enc_expected)));
1293 OSMO_ASSERT(false);
1294 }
Stefan Sperling483f3862018-03-16 12:21:26 +01001295
1296 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
1297 OSMO_ASSERT(rc_dec == msg->len - 2);
1298
1299 /* Check MAXLEN elements to ensure everything has been initialized. */
1300 for (i = 0; i < GSM0808_CELL_ID_LIST2_MAXLEN; i++) {
1301 struct osmo_cell_global_id *enc_id;
1302 struct osmo_cell_global_id *dec_id;
1303 enc_id = &enc_cil.id_list[i].global;
1304 dec_id = &dec_cil.id_list[i].global;
1305 OSMO_ASSERT(osmo_plmn_cmp(&enc_id->lai.plmn, &dec_id->lai.plmn) == 0);
1306 OSMO_ASSERT(enc_id->lai.lac == dec_id->lai.lac);
1307 OSMO_ASSERT(enc_id->cell_identity == dec_id->cell_identity);
1308 }
1309
1310 msgb_free(msg);
1311}
1312
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001313static void print_cil(const struct gsm0808_cell_id_list2 *cil)
1314{
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001315 printf(" cell_id_list == %s\n", gsm0808_cell_id_list_name(cil));
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001316}
1317
1318void test_cell_id_list_add() {
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001319 size_t zu;
1320
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001321 const struct gsm0808_cell_id_list2 cgi1 = {
1322 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1323 .id_list_len = 1,
1324 .id_list = {
1325 {
1326 .global = {
1327 .lai = {
1328 .plmn = { .mcc = 1, .mnc = 2, .mnc_3_digits = false },
1329 .lac = 3,
1330 },
1331 .cell_identity = 4,
1332 }
1333 },
1334 },
1335 };
1336
1337 const struct gsm0808_cell_id_list2 cgi2 = {
1338 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1339 .id_list_len = 2,
1340 .id_list = {
1341 {
1342 .global = {
1343 .lai = {
1344 .plmn = { .mcc = 1, .mnc = 2, .mnc_3_digits = true },
1345 .lac = 3,
1346 },
1347 .cell_identity = 4,
1348 }
1349 },
1350 {
1351 .global = {
1352 .lai = {
1353 .plmn = { .mcc = 5, .mnc = 6, .mnc_3_digits = true },
1354 .lac = 7,
1355 },
1356 .cell_identity = 8,
1357 }
1358 },
1359 },
1360 };
1361
1362 const struct gsm0808_cell_id_list2 cgi2a = {
1363 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1364 .id_list_len = 2,
1365 .id_list = {
1366 {
1367 .global = cgi2.id_list[0].global
1368 },
1369 {
1370 .global = {
1371 .lai = {
1372 .plmn = { .mcc = 9, .mnc = 10, .mnc_3_digits = true },
1373 .lac = 11,
1374 },
1375 .cell_identity = 12,
1376 }
1377 },
1378 },
1379 };
1380
1381 const struct gsm0808_cell_id_list2 cgi3 = {
1382 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1383 .id_list_len = 2,
1384 .id_list = {
1385 {
1386 .global = {
1387 .lai = {
1388 .plmn = { .mcc = 13, .mnc = 14, .mnc_3_digits = true },
1389 .lac = 15,
1390 },
1391 .cell_identity = 16,
1392 }
1393 },
1394 {
1395 .global = {
1396 .lai = {
1397 .plmn = { .mcc = 16, .mnc = 17, .mnc_3_digits = true },
1398 .lac = 18,
1399 },
1400 .cell_identity = 19,
1401 }
1402 },
1403 },
1404 };
1405
1406
1407 const struct gsm0808_cell_id_list2 lac1 = {
1408 .id_discr = CELL_IDENT_LAC,
1409 .id_list_len = 1,
1410 .id_list = {
1411 {
1412 .lac = 123
1413 },
1414 },
1415 };
1416
1417 const struct gsm0808_cell_id_list2 lac2 = {
1418 .id_discr = CELL_IDENT_LAC,
1419 .id_list_len = 2,
1420 .id_list = {
1421 {
1422 .lac = 456
1423 },
1424 {
1425 .lac = 789
1426 },
1427 },
1428 };
1429
1430 struct gsm0808_cell_id_list2 cil = {};
1431
1432 printf("------- %s\n", __func__);
1433
1434 print_cil(&cil);
1435
1436#define ADD_QUIET(other_cil, expect_rc) do { \
1437 int rc = gsm0808_cell_id_list_add(&cil, &other_cil); \
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001438 printf("gsm0808_cell_id_list_add(&cil, &" #other_cil ") --> rc = %d\n", rc); \
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001439 OSMO_ASSERT(rc == expect_rc); \
1440 } while(0)
1441
1442#define ADD(other_cil, expect_rc) ADD_QUIET(other_cil, expect_rc); print_cil(&cil)
1443
1444 ADD(lac1, 1);
1445 ADD(lac1, 0);
1446 ADD(lac2, 2);
1447 ADD(lac2, 0);
1448 ADD(cil, 0);
1449 ADD(cgi1, -EINVAL);
1450
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001451 printf("* can't add to BSS list\n");
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001452 cil.id_list_len = 0;
1453 cil.id_discr = CELL_IDENT_BSS;
1454 print_cil(&cil);
1455 ADD(lac1, -EINVAL);
1456
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001457 printf("* other types (including NO_CELL) take on new type iff empty\n");
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001458 cil.id_list_len = 0;
1459 cil.id_discr = CELL_IDENT_NO_CELL;
1460 print_cil(&cil);
1461 ADD(cgi1, 1);
1462 ADD(cgi1, 0);
1463 ADD(cgi2, 2);
1464 ADD(cgi2, 0);
1465
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001466 printf("* test gsm0808_cell_id_list_name_buf()'s return val\n");
1467 zu = strlen(gsm0808_cell_id_list_name(&cil));
1468 printf(" strlen(gsm0808_cell_id_list_name(cil)) == %zu\n", zu);
1469 zu ++;
1470 while (1) {
1471 char buf[128] = "?";
1472 int rc;
1473 OSMO_ASSERT(zu < sizeof(buf));
1474 buf[zu] = '#';
1475 rc = gsm0808_cell_id_list_name_buf(buf, zu, &cil);
1476 printf(" gsm0808_cell_id_list_name_buf(buf, %zu, cil)) == %d \"%s\"\n",
1477 zu, rc, buf);
1478 OSMO_ASSERT(buf[zu] == '#');
1479 if (!zu)
1480 break;
1481 zu /= 2;
1482 }
1483
1484 printf("* list-full behavior\n");
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001485 cil.id_list_len = GSM0808_CELL_ID_LIST2_MAXLEN - 1;
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001486 printf("cil.id_list_len = %u\n", cil.id_list_len);
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001487 ADD_QUIET(cgi2a, 1);
1488 printf("cil.id_list_len = %u\n", cil.id_list_len);
1489
1490 cil.id_list_len = GSM0808_CELL_ID_LIST2_MAXLEN - 1;
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001491 printf("cil.id_list_len = %u\n", cil.id_list_len);
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001492 ADD_QUIET(cgi3, -ENOSPC);
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001493 printf("cil.id_list_len = %u\n", cil.id_list_len);
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001494 ADD_QUIET(cgi2a, -ENOSPC);
1495 printf("cil.id_list_len = %u\n", cil.id_list_len);
1496
1497 printf("------- %s done\n", __func__);
1498}
1499
Neels Hofmeyr250e7f72018-04-13 03:30:14 +02001500static void test_gsm0808_enc_dec_cell_id_lac()
1501{
1502 struct gsm0808_cell_id enc_ci = {
1503 .id_discr = CELL_IDENT_LAC,
1504 .id.lac = 0x0124,
1505 };
1506 struct gsm0808_cell_id dec_ci;
1507 struct msgb *msg;
1508 uint8_t rc_enc;
1509 int rc_dec;
1510
1511 memset(&dec_ci, 0xa5, sizeof(dec_ci));
1512
1513 msg = msgb_alloc(1024, "output buffer");
1514 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1515 EXPECT_ENCODED("05 03 05 01 24");
1516
1517 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1518 OSMO_ASSERT(rc_dec == 3);
1519
1520 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr
1521 && enc_ci.id.lac == dec_ci.id.lac);
1522
1523 msgb_free(msg);
1524}
1525
1526static void test_gsm0808_enc_dec_cell_id_bss()
1527{
1528 struct gsm0808_cell_id enc_ci = {
1529 .id_discr = CELL_IDENT_BSS,
1530 };
1531 struct gsm0808_cell_id dec_ci;
1532 struct msgb *msg;
1533 uint8_t rc_enc;
1534 int rc_dec;
1535
1536 msg = msgb_alloc(1024, "output buffer");
1537 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1538 EXPECT_ENCODED("05 01 06");
1539
1540 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1541 OSMO_ASSERT(rc_dec == 1);
1542
1543 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr);
1544
1545 msgb_free(msg);
1546}
1547
1548static void test_gsm0808_enc_dec_cell_id_no_cell()
1549{
1550 struct gsm0808_cell_id enc_ci = {
1551 .id_discr = CELL_IDENT_NO_CELL,
1552 };
1553 struct gsm0808_cell_id dec_ci;
1554 struct msgb *msg;
1555 uint8_t rc_enc;
1556 int rc_dec;
1557
1558 msg = msgb_alloc(1024, "output buffer");
1559 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1560 EXPECT_ENCODED("05 01 03");
1561
1562 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1563 OSMO_ASSERT(rc_dec == 1);
1564
1565 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr);
1566
1567 msgb_free(msg);
1568}
1569
1570static void test_gsm0808_enc_dec_cell_id_lai_and_lac()
1571{
1572 struct gsm0808_cell_id enc_ci = {
1573 .id_discr = CELL_IDENT_LAI_AND_LAC,
1574 .id.lai_and_lac = {
1575 .plmn = {
1576 .mcc = 123,
1577 .mnc = 456,
1578 },
1579 .lac = 0x2342,
1580 },
1581 };
1582 struct gsm0808_cell_id dec_ci;
1583 struct msgb *msg;
1584 uint8_t rc_enc;
1585 int rc_dec;
1586
1587 msg = msgb_alloc(1024, "output buffer");
1588 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1589 EXPECT_ENCODED("05 06 04 21 63 54 23 42");
1590
1591 memset(&dec_ci, 0xa5, sizeof(dec_ci));
1592 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1593 OSMO_ASSERT(rc_dec == msg->len - 2);
1594
1595 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr
1596 && osmo_plmn_cmp(&enc_ci.id.lai_and_lac.plmn, &dec_ci.id.lai_and_lac.plmn) == 0
1597 && enc_ci.id.lai_and_lac.lac == dec_ci.id.lai_and_lac.lac);
1598 msgb_free(msg);
1599}
1600
1601static void test_gsm0808_enc_dec_cell_id_ci()
1602{
1603 struct gsm0808_cell_id enc_ci = {
1604 .id_discr = CELL_IDENT_CI,
1605 .id.ci = 0x423,
1606 };
1607 struct gsm0808_cell_id dec_ci;
1608 struct msgb *msg;
1609 uint8_t rc_enc;
1610 int rc_dec;
1611
1612 msg = msgb_alloc(1024, "output buffer");
1613 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1614 EXPECT_ENCODED("05 03 02 04 23");
1615
1616 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1617 OSMO_ASSERT(rc_dec == msg->len - 2);
1618 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr
1619 && enc_ci.id.ci == dec_ci.id.ci);
1620
1621 msgb_free(msg);
1622}
1623
1624static void test_gsm0808_enc_dec_cell_id_lac_and_ci()
1625{
1626 struct gsm0808_cell_id enc_ci = {
1627 .id_discr = CELL_IDENT_LAC_AND_CI,
1628 .id.lac_and_ci = {
1629 .lac = 0x423,
1630 .ci = 0x235,
1631 },
1632 };
1633 struct gsm0808_cell_id dec_ci;
1634 struct msgb *msg;
1635 uint8_t rc_enc;
1636 int rc_dec;
1637
1638 msg = msgb_alloc(1024, "output buffer");
1639 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1640 EXPECT_ENCODED("05 05 01 04 23 02 35");
1641
1642 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1643 OSMO_ASSERT(rc_dec == msg->len - 2);
1644 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr
1645 && enc_ci.id.lac_and_ci.lac == dec_ci.id.lac_and_ci.lac
1646 && enc_ci.id.lac_and_ci.ci == dec_ci.id.lac_and_ci.ci);
1647
1648 msgb_free(msg);
1649}
1650
1651static void test_gsm0808_enc_dec_cell_id_global()
1652{
1653 struct gsm0808_cell_id enc_ci = {
1654 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1655 .id.global = {
1656 .lai = {
1657 .plmn = { .mcc = 123, .mnc = 456 },
1658 .lac = 0x2342
1659 },
1660 .cell_identity = 0x423,
1661 }
1662 };
1663 struct gsm0808_cell_id dec_ci;
1664 struct msgb *msg;
1665 uint8_t rc_enc;
1666 int rc_dec;
1667
1668 msg = msgb_alloc(1024, "output buffer");
1669 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1670 EXPECT_ENCODED("05 08 00 21 63 54 23 42 04 23");
1671
1672 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1673 OSMO_ASSERT(rc_dec == msg->len - 2);
1674
1675 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr
1676 && osmo_plmn_cmp(&enc_ci.id.global.lai.plmn,
1677 &dec_ci.id.global.lai.plmn) == 0
1678 && enc_ci.id.global.lai.lac == dec_ci.id.global.lai.lac
1679 && enc_ci.id.global.cell_identity == dec_ci.id.global.cell_identity);
1680 msgb_free(msg);
1681}
1682
Philipp Maier5f2eb152018-09-19 13:40:21 +02001683static void test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(struct gsm48_multi_rate_conf *cfg)
1684{
1685 uint16_t s15_s0;
1686
1687 printf("Input:\n");
1688 printf(" m4_75= %u smod= %u\n", cfg->m4_75, cfg->smod);
1689 printf(" m5_15= %u spare= %u\n", cfg->m5_15, cfg->spare);
1690 printf(" m5_90= %u icmi= %u\n", cfg->m5_90, cfg->icmi);
1691 printf(" m6_70= %u nscb= %u\n", cfg->m6_70, cfg->nscb);
1692 printf(" m7_40= %u ver= %u\n", cfg->m7_40, cfg->ver);
1693 printf(" m7_95= %u\n", cfg->m7_95);
1694 printf(" m10_2= %u\n", cfg->m10_2);
1695 printf(" m12_2= %u\n", cfg->m12_2);
1696
1697 s15_s0 = gsm0808_sc_cfg_from_gsm48_mr_cfg(cfg, true);
1698 printf("Result (fr):\n");
1699 printf(" S15-S0 = %04x = 0b" OSMO_BIN_SPEC OSMO_BIN_SPEC "\n", s15_s0,
1700 OSMO_BIN_PRINT(s15_s0 >> 8), OSMO_BIN_PRINT(s15_s0));
1701
1702 s15_s0 = gsm0808_sc_cfg_from_gsm48_mr_cfg(cfg, false);
1703 printf("Result (hr):\n");
1704 printf(" S15-S0 = %04x = 0b" OSMO_BIN_SPEC OSMO_BIN_SPEC "\n", s15_s0,
1705 OSMO_BIN_PRINT(s15_s0 >> 8), OSMO_BIN_PRINT(s15_s0));
1706
1707 printf("\n");
1708}
1709
1710static void test_gsm0808_sc_cfg_from_gsm48_mr_cfg(void)
1711{
1712 struct gsm48_multi_rate_conf cfg;
1713
1714 printf("Testing gsm0808_sc_cfg_from_gsm48_mr_cfg():\n");
1715
1716 memset(&cfg, 0, sizeof(cfg));
1717
1718 cfg.m4_75 = 0;
1719 cfg.m5_15 = 0;
1720 cfg.m5_90 = 0;
1721 cfg.m6_70 = 0;
1722 cfg.m7_40 = 0;
1723 cfg.m7_95 = 0;
1724 cfg.m10_2 = 0;
1725 cfg.m12_2 = 0;
1726 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1727
1728 cfg.m4_75 = 1;
1729 cfg.m5_15 = 0;
1730 cfg.m5_90 = 0;
1731 cfg.m6_70 = 0;
1732 cfg.m7_40 = 0;
1733 cfg.m7_95 = 0;
1734 cfg.m10_2 = 0;
1735 cfg.m12_2 = 0;
1736 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1737
1738 cfg.m4_75 = 0;
1739 cfg.m5_15 = 1;
1740 cfg.m5_90 = 0;
1741 cfg.m6_70 = 0;
1742 cfg.m7_40 = 0;
1743 cfg.m7_95 = 0;
1744 cfg.m10_2 = 0;
1745 cfg.m12_2 = 0;
1746 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1747
1748 cfg.m4_75 = 0;
1749 cfg.m5_15 = 0;
1750 cfg.m5_90 = 1;
1751 cfg.m6_70 = 0;
1752 cfg.m7_40 = 0;
1753 cfg.m7_95 = 0;
1754 cfg.m10_2 = 0;
1755 cfg.m12_2 = 0;
1756 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1757
1758 cfg.m4_75 = 0;
1759 cfg.m5_15 = 0;
1760 cfg.m5_90 = 0;
1761 cfg.m6_70 = 1;
1762 cfg.m7_40 = 0;
1763 cfg.m7_95 = 0;
1764 cfg.m10_2 = 0;
1765 cfg.m12_2 = 0;
1766 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1767
1768 cfg.m4_75 = 0;
1769 cfg.m5_15 = 0;
1770 cfg.m5_90 = 0;
1771 cfg.m6_70 = 0;
1772 cfg.m7_40 = 1;
1773 cfg.m7_95 = 0;
1774 cfg.m10_2 = 0;
1775 cfg.m12_2 = 0;
1776 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1777
1778 cfg.m4_75 = 0;
1779 cfg.m5_15 = 0;
1780 cfg.m5_90 = 0;
1781 cfg.m6_70 = 0;
1782 cfg.m7_40 = 0;
1783 cfg.m7_95 = 1;
1784 cfg.m10_2 = 0;
1785 cfg.m12_2 = 0;
1786 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1787
1788 cfg.m4_75 = 0;
1789 cfg.m5_15 = 0;
1790 cfg.m5_90 = 0;
1791 cfg.m6_70 = 0;
1792 cfg.m7_40 = 0;
1793 cfg.m7_95 = 0;
1794 cfg.m10_2 = 1;
1795 cfg.m12_2 = 0;
1796 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1797
1798 cfg.m4_75 = 0;
1799 cfg.m5_15 = 0;
1800 cfg.m5_90 = 0;
1801 cfg.m6_70 = 0;
1802 cfg.m7_40 = 0;
1803 cfg.m7_95 = 0;
1804 cfg.m10_2 = 0;
1805 cfg.m12_2 = 1;
1806 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1807
1808 cfg.m4_75 = 1;
1809 cfg.m5_15 = 1;
1810 cfg.m5_90 = 1;
1811 cfg.m6_70 = 1;
1812 cfg.m7_40 = 0;
1813 cfg.m7_95 = 0;
1814 cfg.m10_2 = 0;
1815 cfg.m12_2 = 0;
1816 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1817
1818 cfg.m4_75 = 0;
1819 cfg.m5_15 = 0;
1820 cfg.m5_90 = 0;
1821 cfg.m6_70 = 0;
1822 cfg.m7_40 = 1;
1823 cfg.m7_95 = 1;
1824 cfg.m10_2 = 1;
1825 cfg.m12_2 = 1;
1826 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1827
1828 cfg.m4_75 = 0;
1829 cfg.m5_15 = 0;
1830 cfg.m5_90 = 1;
1831 cfg.m6_70 = 1;
1832 cfg.m7_40 = 0;
1833 cfg.m7_95 = 0;
1834 cfg.m10_2 = 1;
1835 cfg.m12_2 = 1;
1836 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1837
1838 cfg.m4_75 = 1;
1839 cfg.m5_15 = 1;
1840 cfg.m5_90 = 0;
1841 cfg.m6_70 = 0;
1842 cfg.m7_40 = 1;
1843 cfg.m7_95 = 1;
1844 cfg.m10_2 = 0;
1845 cfg.m12_2 = 0;
1846 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1847
1848 cfg.m4_75 = 0;
1849 cfg.m5_15 = 1;
1850 cfg.m5_90 = 0;
1851 cfg.m6_70 = 1;
1852 cfg.m7_40 = 0;
1853 cfg.m7_95 = 1;
1854 cfg.m10_2 = 0;
1855 cfg.m12_2 = 1;
1856 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1857
1858 cfg.m4_75 = 1;
1859 cfg.m5_15 = 0;
1860 cfg.m5_90 = 1;
1861 cfg.m6_70 = 0;
1862 cfg.m7_40 = 1;
1863 cfg.m7_95 = 0;
1864 cfg.m10_2 = 1;
1865 cfg.m12_2 = 0;
1866 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1867
1868 cfg.m4_75 = 1;
1869 cfg.m5_15 = 1;
1870 cfg.m5_90 = 1;
1871 cfg.m6_70 = 1;
1872 cfg.m7_40 = 1;
1873 cfg.m7_95 = 1;
1874 cfg.m10_2 = 1;
1875 cfg.m12_2 = 1;
1876 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1877}
1878
Philipp Maier8515d032018-09-25 15:57:49 +02001879static void test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single(uint16_t s15_s0)
1880{
1881 struct gsm48_multi_rate_conf cfg;
1882
1883 printf("Input:\n");
1884 printf(" S15-S0 = %04x = 0b" OSMO_BIN_SPEC OSMO_BIN_SPEC "\n", s15_s0,
1885 OSMO_BIN_PRINT(s15_s0 >> 8), OSMO_BIN_PRINT(s15_s0));
1886
1887 gsm48_mr_cfg_from_gsm0808_sc_cfg(&cfg, s15_s0);
1888
1889 printf("Output:\n");
1890 printf(" m4_75= %u smod= %u\n", cfg.m4_75, cfg.smod);
1891 printf(" m5_15= %u spare= %u\n", cfg.m5_15, cfg.spare);
1892 printf(" m5_90= %u icmi= %u\n", cfg.m5_90, cfg.icmi);
1893 printf(" m6_70= %u nscb= %u\n", cfg.m6_70, cfg.nscb);
1894 printf(" m7_40= %u ver= %u\n", cfg.m7_40, cfg.ver);
1895 printf(" m7_95= %u\n", cfg.m7_95);
1896 printf(" m10_2= %u\n", cfg.m10_2);
1897 printf(" m12_2= %u\n", cfg.m12_2);
1898
1899 printf("\n");
1900}
1901
1902void test_gsm48_mr_cfg_from_gsm0808_sc_cfg()
1903{
1904 printf("Testing gsm48_mr_cfg_from_gsm0808_sc_cfg():\n");
1905
1906 /* Only one codec per setting */
1907 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1908 (GSM0808_SC_CFG_DEFAULT_AMR_4_75);
1909 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1910 (GSM0808_SC_CFG_DEFAULT_AMR_5_15);
1911 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1912 (GSM0808_SC_CFG_DEFAULT_AMR_5_90);
1913 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1914 (GSM0808_SC_CFG_DEFAULT_AMR_6_70);
1915 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1916 (GSM0808_SC_CFG_DEFAULT_AMR_7_40);
1917 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1918 (GSM0808_SC_CFG_DEFAULT_AMR_7_95);
1919 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1920 (GSM0808_SC_CFG_DEFAULT_AMR_10_2);
1921 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1922 (GSM0808_SC_CFG_DEFAULT_AMR_12_2);
1923
1924 /* Combinations */
1925 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1926 (GSM0808_SC_CFG_DEFAULT_AMR_4_75 | GSM0808_SC_CFG_DEFAULT_AMR_6_70 |
1927 GSM0808_SC_CFG_DEFAULT_AMR_10_2);
1928 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1929 (GSM0808_SC_CFG_DEFAULT_AMR_10_2 | GSM0808_SC_CFG_DEFAULT_AMR_12_2 |
1930 GSM0808_SC_CFG_DEFAULT_AMR_7_40);
1931 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1932 (GSM0808_SC_CFG_DEFAULT_AMR_7_95 | GSM0808_SC_CFG_DEFAULT_AMR_12_2);
1933}
1934
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01001935int main(int argc, char **argv)
1936{
Max969fb2e2018-12-10 11:01:10 +01001937 void *ctx = talloc_named_const(NULL, 0, "gsm0808 test");
1938 msgb_talloc_ctx_init(ctx, 0);
1939 osmo_init_logging2(ctx, NULL);
1940
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01001941 printf("Testing generation of GSM0808 messages\n");
Philipp Maier4f4905f2018-11-30 13:36:12 +01001942 test_gsm0808_enc_cause();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01001943 test_create_layer3();
Philipp Maierfa896ab2017-03-27 16:55:32 +02001944 test_create_layer3_aoip();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01001945 test_create_reset();
Philipp Maier15596e22017-04-05 17:55:27 +02001946 test_create_reset_ack();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01001947 test_create_clear_command();
1948 test_create_clear_complete();
Philipp Maierb478dd32017-03-29 15:50:05 +02001949 test_create_cipher();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01001950 test_create_cipher_complete();
1951 test_create_cipher_reject();
Maxed651d22018-11-07 15:25:05 +01001952 test_create_cipher_reject_ext();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01001953 test_create_cm_u();
1954 test_create_sapi_reject();
Philipp Maierc6144a22017-03-29 17:53:43 +02001955 test_create_ass();
Max52074322018-11-30 10:44:07 +01001956 test_create_ass2();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01001957 test_create_ass_compl();
Philipp Maierfa896ab2017-03-27 16:55:32 +02001958 test_create_ass_compl_aoip();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01001959 test_create_ass_fail();
Philipp Maierfa896ab2017-03-27 16:55:32 +02001960 test_create_ass_fail_aoip();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01001961 test_create_clear_rqst();
Philipp Maier3d48ec02017-03-29 17:37:55 +02001962 test_create_paging();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01001963 test_create_dtap();
1964 test_prepend_dtap();
Max969fb2e2018-12-10 11:01:10 +01001965
Max47022152018-12-19 18:51:00 +01001966 test_enc_dec_lcls();
Max969fb2e2018-12-10 11:01:10 +01001967
Philipp Maier22401432017-03-24 17:59:26 +01001968 test_enc_dec_aoip_trasp_addr_v4();
1969 test_enc_dec_aoip_trasp_addr_v6();
Philipp Maier6f725d62017-03-24 18:03:17 +01001970 test_gsm0808_enc_dec_speech_codec();
Philipp Maier6f725d62017-03-24 18:03:17 +01001971 test_gsm0808_enc_dec_speech_codec_ext_with_cfg();
Philipp Maierbb839662017-06-01 17:11:19 +02001972 test_gsm0808_enc_dec_speech_codec_with_cfg();
Philipp Maier6f725d62017-03-24 18:03:17 +01001973 test_gsm0808_enc_dec_speech_codec_list();
Philipp Maierf6c369f2018-10-16 15:24:47 +02001974 test_gsm0808_enc_dec_empty_speech_codec_list();
Philipp Maiere0c65302017-03-28 17:05:40 +02001975 test_gsm0808_enc_dec_channel_type();
Philipp Maier14e76b92017-03-28 18:36:52 +02001976 test_gsm0808_enc_dec_encrypt_info();
Neels Hofmeyr250e7f72018-04-13 03:30:14 +02001977
Philipp Maier783047e2017-03-29 11:35:50 +02001978 test_gsm0808_enc_dec_cell_id_list_lac();
1979 test_gsm0808_enc_dec_cell_id_list_single_lac();
Stefan Sperlinge1a86742018-03-15 18:05:02 +01001980 test_gsm0808_enc_dec_cell_id_list_multi_lac();
Philipp Maier783047e2017-03-29 11:35:50 +02001981 test_gsm0808_enc_dec_cell_id_list_bss();
Stefan Sperling23381452018-03-15 19:38:15 +01001982 test_gsm0808_enc_dec_cell_id_list_multi_lai_and_lac();
Stefan Sperling9c62fc62018-03-16 10:23:34 +01001983 test_gsm0808_enc_dec_cell_id_list_multi_ci();
Stefan Sperlinged4327c2018-03-16 11:02:59 +01001984 test_gsm0808_enc_dec_cell_id_list_multi_lac_and_ci();
Stefan Sperling483f3862018-03-16 12:21:26 +01001985 test_gsm0808_enc_dec_cell_id_list_multi_global();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01001986
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001987 test_cell_id_list_add();
1988
Neels Hofmeyr250e7f72018-04-13 03:30:14 +02001989 test_gsm0808_enc_dec_cell_id_lac();
1990 test_gsm0808_enc_dec_cell_id_bss();
1991 test_gsm0808_enc_dec_cell_id_no_cell();
1992 test_gsm0808_enc_dec_cell_id_lai_and_lac();
1993 test_gsm0808_enc_dec_cell_id_ci();
1994 test_gsm0808_enc_dec_cell_id_lac_and_ci();
1995 test_gsm0808_enc_dec_cell_id_global();
1996
Philipp Maier5f2eb152018-09-19 13:40:21 +02001997 test_gsm0808_sc_cfg_from_gsm48_mr_cfg();
Philipp Maier8515d032018-09-25 15:57:49 +02001998 test_gsm48_mr_cfg_from_gsm0808_sc_cfg();
Philipp Maier5f2eb152018-09-19 13:40:21 +02001999
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002000 printf("Done\n");
2001 return EXIT_SUCCESS;
2002}