blob: e5c1fd37332d387e7516c33b491f857715c38d5b [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[] =
Max414c8f52019-01-08 14:44:24 +0100513 { 0x00, 0x1f, 0x02, 0x15, 0x23, 0x21, 0x42, 0x2c, 0x11, 0x40, 0x22,
Philipp Maierfa896ab2017-03-27 16:55:32 +0200514 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,
Max414c8f52019-01-08 14:44:24 +0100517 0xcd, GSM0808_SCT_FR2 | 0xa0, 0x9f, GSM0808_SCT_CSD | 0x90, 0xc0,
518 GSM0808_IE_LCLS_BSS_STATUS, GSM0808_LCLS_STS_LOCALLY_SWITCHED };
Philipp Maierfa896ab2017-03-27 16:55:32 +0200519 struct msgb *msg;
520
521 memset(&sin, 0, sizeof(sin));
522 sin.sin_family = AF_INET;
523 sin.sin_port = htons(1234);
524 inet_aton("192.168.100.23", &sin.sin_addr);
525
526 memset(&ss, 0, sizeof(ss));
527 memcpy(&ss, &sin, sizeof(sin));
528
529 memset(&sc, 0, sizeof(sc));
530 sc.fi = true;
531 sc.tf = true;
Philipp Maierbb839662017-06-01 17:11:19 +0200532 sc.type = GSM0808_SCT_HR1;
Philipp Maierfa896ab2017-03-27 16:55:32 +0200533
534 setup_codec_list(&sc_list);
535
536 printf("Testing creating Assignment Complete (AoIP)\n");
Max414c8f52019-01-08 14:44:24 +0100537 msg = gsm0808_create_ass_compl2(0x23, 0x42, 0x11, 0x22,
538 &ss, &sc, &sc_list, GSM0808_LCLS_STS_LOCALLY_SWITCHED);
Philipp Maierfa896ab2017-03-27 16:55:32 +0200539 VERIFY(msg, res, ARRAY_SIZE(res));
540 msgb_free(msg);
541}
542
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100543static void test_create_ass_fail()
544{
545 static const uint8_t res1[] = { 0x00, 0x04, 0x03, 0x04, 0x01, 0x23 };
546 static const uint8_t res2[] = {
547 0x00, 0x06, 0x03, 0x04, 0x01, 0x23, 0x15, 0x02};
548 uint8_t rr_res = 2;
549 struct msgb *msg;
550
551 printf("Testing creating Assignment Failure\n");
552 msg = gsm0808_create_assignment_failure(0x23, NULL);
553 VERIFY(msg, res1, ARRAY_SIZE(res1));
554 msgb_free(msg);
555
556 msg = gsm0808_create_assignment_failure(0x23, &rr_res);
557 VERIFY(msg, res2, ARRAY_SIZE(res2));
558 msgb_free(msg);
559}
560
Philipp Maierfa896ab2017-03-27 16:55:32 +0200561static void test_create_ass_fail_aoip()
562{
563 static const uint8_t res1[] =
564 { 0x00, 0x0d, 0x03, 0x04, 0x01, 0x23, GSM0808_IE_SPEECH_CODEC_LIST,
Philipp Maier7e27b142018-03-22 17:26:46 +0100565 0x07, GSM0808_SCT_FR3 | 0x50, 0xef, 0xcd, GSM0808_SCT_FR2 | 0xa0,
Philipp Maierbb839662017-06-01 17:11:19 +0200566 0x9f, GSM0808_SCT_CSD | 0x90, 0xc0 };
Philipp Maierfa896ab2017-03-27 16:55:32 +0200567 static const uint8_t res2[] =
568 { 0x00, 0x0f, 0x03, 0x04, 0x01, 0x23, 0x15, 0x02,
Philipp Maier7e27b142018-03-22 17:26:46 +0100569 GSM0808_IE_SPEECH_CODEC_LIST, 0x07, GSM0808_SCT_FR3 | 0x50, 0xef,
570 0xcd, GSM0808_SCT_FR2 | 0xa0, 0x9f, GSM0808_SCT_CSD | 0x90, 0xc0 };
Philipp Maierfa896ab2017-03-27 16:55:32 +0200571 uint8_t rr_res = 2;
572 struct msgb *msg;
573 struct gsm0808_speech_codec_list sc_list;
574
575 setup_codec_list(&sc_list);
576
577 printf("Testing creating Assignment Failure (AoIP)\n");
578 msg = gsm0808_create_ass_fail(0x23, NULL, &sc_list);
579 VERIFY(msg, res1, ARRAY_SIZE(res1));
580 msgb_free(msg);
581
582 msg = gsm0808_create_ass_fail(0x23, &rr_res, &sc_list);
583 VERIFY(msg, res2, ARRAY_SIZE(res2));
584 msgb_free(msg);
585}
586
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100587static void test_create_clear_rqst()
588{
589 static const uint8_t res[] = { 0x00, 0x04, 0x22, 0x04, 0x01, 0x23 };
590 struct msgb *msg;
591
592 printf("Testing creating Clear Request\n");
593 msg = gsm0808_create_clear_rqst(0x23);
594 VERIFY(msg, res, ARRAY_SIZE(res));
595 msgb_free(msg);
596}
597
Philipp Maier3d48ec02017-03-29 17:37:55 +0200598static void test_create_paging()
599{
600 static const uint8_t res[] =
601 { 0x00, 0x10, 0x52, 0x08, 0x08, 0x09, 0x10, 0x10, 0x00, 0x00, 0x00,
602 0x21, 0x43, 0x1a, 0x03, 0x05, 0x23, 0x42 };
603 static const uint8_t res2[] =
604 { 0x00, 0x16, 0x52, 0x08, 0x08, 0x09, 0x10, 0x10, 0x00, 0x00, 0x00,
605 0x21, 0x43, GSM0808_IE_TMSI, 0x04, 0x12, 0x34, 0x56, 0x78, 0x1a,
606 0x03, 0x05, 0x23, 0x42 };
607 static const uint8_t res3[] =
608 { 0x00, 0x18, 0x52, 0x08, 0x08, 0x09, 0x10, 0x10, 0x00, 0x00, 0x00,
609 0x21, 0x43, GSM0808_IE_TMSI, 0x04, 0x12, 0x34, 0x56, 0x78, 0x1a,
610 0x03, 0x05, 0x23, 0x42, GSM0808_IE_CHANNEL_NEEDED,
611 RSL_CHANNEED_TCH_ForH };
612
613 struct msgb *msg;
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100614 struct gsm0808_cell_id_list2 cil;
Philipp Maier3d48ec02017-03-29 17:37:55 +0200615 uint32_t tmsi = 0x12345678;
616 uint8_t chan_needed = RSL_CHANNEED_TCH_ForH;
617
618 char imsi[] = "001010000001234";
619
620 cil.id_discr = CELL_IDENT_LAC;
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100621 cil.id_list[0].lac = 0x2342;
Philipp Maier3d48ec02017-03-29 17:37:55 +0200622 cil.id_list_len = 1;
623
624 printf("Testing creating Paging Request\n");
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100625 msg = gsm0808_create_paging2(imsi, NULL, &cil, NULL);
Philipp Maier3d48ec02017-03-29 17:37:55 +0200626 VERIFY(msg, res, ARRAY_SIZE(res));
627 msgb_free(msg);
628
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100629 msg = gsm0808_create_paging2(imsi, &tmsi, &cil, NULL);
Philipp Maier3d48ec02017-03-29 17:37:55 +0200630 VERIFY(msg, res2, ARRAY_SIZE(res2));
631 msgb_free(msg);
632
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100633 msg = gsm0808_create_paging2(imsi, &tmsi, &cil, &chan_needed);
Philipp Maier3d48ec02017-03-29 17:37:55 +0200634 VERIFY(msg, res3, ARRAY_SIZE(res3));
635 msgb_free(msg);
636}
637
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100638static void test_create_dtap()
639{
640 static const uint8_t res[] = { 0x01, 0x03, 0x02, 0x23, 0x42 };
641 struct msgb *msg, *l3;
642
643 printf("Testing creating DTAP\n");
644 l3 = msgb_alloc_headroom(512, 128, "test");
645 l3->l3h = l3->data;
646 msgb_v_put(l3, 0x23);
647 msgb_v_put(l3, 0x42);
648
649 msg = gsm0808_create_dtap(l3, 0x3);
650 VERIFY(msg, res, ARRAY_SIZE(res));
651 msgb_free(msg);
652 msgb_free(l3);
653}
654
655static void test_prepend_dtap()
656{
657 static const uint8_t res[] = { 0x01, 0x03, 0x02, 0x23, 0x42 };
658 struct msgb *in_msg;
659
660 printf("Testing prepend DTAP\n");
661
662 in_msg = msgb_alloc_headroom(512, 128, "test");
663 msgb_v_put(in_msg, 0x23);
664 msgb_v_put(in_msg, 0x42);
665
666 gsm0808_prepend_dtap_header(in_msg, 0x3);
667 in_msg->l3h = in_msg->data;
668 VERIFY(in_msg, res, ARRAY_SIZE(res));
669 msgb_free(in_msg);
670}
671
Max47022152018-12-19 18:51:00 +0100672static void test_enc_dec_lcls()
Max969fb2e2018-12-10 11:01:10 +0100673{
674 static const uint8_t res[] = {
675 GSM0808_IE_GLOBAL_CALL_REF,
676 0x0d, /* GCR length */
677 0x03, /* .net_len */
678 0xf1, 0xf2, 0xf3, /* .net */
679 0x02, /* .node length */
680 0xde, 0xad, /* .node */
681 0x05, /* length of Call. Ref. */
682 0x41, 0x42, 0x43, 0x44, 0x45 /* .cr - Call. Ref. */
683 };
684 uint8_t len;
685 struct msgb *msg;
686 struct osmo_gcr_parsed p = { 0 }, g = {
687 .net_len = 3,
688 .net = { 0xf1, 0xf2, 0xf3 },
689 .node = 0xDEAD,
690 .cr = { 0x41, 0x42, 0x43, 0x44, 0x45 },
691 };
692 int rc;
693 struct tlv_parsed tp;
Max47022152018-12-19 18:51:00 +0100694 struct osmo_lcls lcls_out = { .gcr = &p }, lcls_in = {
695 .gcr = &g,
696 .config = GSM0808_LCLS_CFG_NA,
697 .control = GSM0808_LCLS_CSC_NA,
698 .corr_needed = true,
699 };
700
701 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "LCLS IE");
Max969fb2e2018-12-10 11:01:10 +0100702 if (!msg)
703 return;
704
Max47022152018-12-19 18:51:00 +0100705 len = gsm0808_enc_lcls(msg, &lcls_in);
Max969fb2e2018-12-10 11:01:10 +0100706 printf("Testing Global Call Reference IE encoder...\n\t%d bytes added: %s\n",
707 len, len == ARRAY_SIZE(res) ? "OK" : "FAIL");
708
709 if (!msgb_eq_data_print(msg, res, ARRAY_SIZE(res)))
710 abort();
711
712 rc = osmo_bssap_tlv_parse(&tp, msgb_data(msg), msgb_length(msg));
713 if (rc < 0) {
714 printf("parsing failed: %s [%s]\n", strerror(-rc), msgb_hexdump(msg));
715 abort();
716 }
717
Max47022152018-12-19 18:51:00 +0100718 rc = gsm0808_dec_lcls(&lcls_out, &tp);
Max969fb2e2018-12-10 11:01:10 +0100719 if (rc < 0) {
720 printf("decoding failed: %s [%s]\n", strerror(-rc), msgb_hexdump(msg));
721 abort();
722 }
723
Max4fd64e52019-01-14 19:27:44 +0100724 if (lcls_out.config != lcls_in.config) {
725 printf("LCLS Config parsed wrong: %s != %s\n",
726 gsm0808_lcls_config_name(lcls_out.config), gsm0808_lcls_config_name(lcls_in.config));
727 abort();
728 }
729
730 if (lcls_out.control != lcls_in.control) {
731 printf("LCLS Control parsed wrong: %s != %s\n",
732 gsm0808_lcls_control_name(lcls_out.control), gsm0808_lcls_control_name(lcls_in.control));
733 abort();
734 }
735
Max1bec3902019-01-14 19:31:42 +0100736 if (!osmo_gcr_eq(lcls_out.gcr, lcls_in.gcr)) {
737 printf("GCR parsed wrong.\n");
738 abort();
739 }
Max969fb2e2018-12-10 11:01:10 +0100740
741 printf("\tdecoded %d bytes: %s\n", rc, rc == len ? "OK" : "FAIL");
742 msgb_free(msg);
743}
744
Philipp Maier22401432017-03-24 17:59:26 +0100745static void test_enc_dec_aoip_trasp_addr_v4()
746{
747 struct sockaddr_storage enc_addr;
748 struct sockaddr_storage dec_addr;
749 struct sockaddr_in enc_addr_in;
750 struct msgb *msg;
751 uint8_t rc_enc;
752 int rc_dec;
753
754 memset(&enc_addr_in, 0, sizeof(enc_addr_in));
755 enc_addr_in.sin_family = AF_INET;
756 enc_addr_in.sin_port = htons(1234);
757 inet_aton("255.0.255.255", &enc_addr_in.sin_addr);
758
759 memset(&enc_addr, 0, sizeof(enc_addr));
760 memcpy(&enc_addr, &enc_addr_in, sizeof(enc_addr_in));
761
762 msg = msgb_alloc(1024, "output buffer");
763 rc_enc = gsm0808_enc_aoip_trasp_addr(msg, &enc_addr);
764 OSMO_ASSERT(rc_enc == 8);
765 rc_dec =
766 gsm0808_dec_aoip_trasp_addr(&dec_addr, msg->data + 2, msg->len - 2);
767 OSMO_ASSERT(rc_dec == 6);
768 OSMO_ASSERT(memcmp(&enc_addr, &dec_addr, sizeof(enc_addr)) == 0);
769
770 msgb_free(msg);
771}
772
773static void test_enc_dec_aoip_trasp_addr_v6()
774{
775 struct sockaddr_storage enc_addr;
776 struct sockaddr_storage dec_addr;
777 struct sockaddr_in6 enc_addr_in;
778 struct msgb *msg;
779 uint8_t rc_enc;
780 int rc_dec;
781
782 memset(&enc_addr_in, 0, sizeof(enc_addr_in));
783 enc_addr_in.sin6_family = AF_INET6;
784 enc_addr_in.sin6_port = htons(4567);
785 inet_pton(AF_INET6, "2001:0db8:85a3:08d3:1319:8a2e:0370:7344",
786 &enc_addr_in.sin6_addr);
787
788 memset(&enc_addr, 0, sizeof(enc_addr));
789 memcpy(&enc_addr, &enc_addr_in, sizeof(enc_addr_in));
790
791 msg = msgb_alloc(1024, "output buffer");
792 rc_enc = gsm0808_enc_aoip_trasp_addr(msg, &enc_addr);
793 OSMO_ASSERT(rc_enc == 20);
794 rc_dec =
795 gsm0808_dec_aoip_trasp_addr(&dec_addr, msg->data + 2, msg->len - 2);
796 OSMO_ASSERT(rc_dec == 18);
797 OSMO_ASSERT(memcmp(&enc_addr, &dec_addr, sizeof(enc_addr)) == 0);
798
799 msgb_free(msg);
800}
801
Philipp Maier6f725d62017-03-24 18:03:17 +0100802static void test_gsm0808_enc_dec_speech_codec()
803{
Neels Hofmeyr9a4286b2018-04-20 12:27:52 +0200804 struct gsm0808_speech_codec enc_sc = {
805 .pi = true,
806 .tf = true,
807 .type = GSM0808_SCT_FR2,
808 };
809 struct gsm0808_speech_codec dec_sc = {};
Philipp Maier6f725d62017-03-24 18:03:17 +0100810 struct msgb *msg;
811 uint8_t rc_enc;
812 int rc_dec;
813
Philipp Maier6f725d62017-03-24 18:03:17 +0100814 msg = msgb_alloc(1024, "output buffer");
815 rc_enc = gsm0808_enc_speech_codec(msg, &enc_sc);
816 OSMO_ASSERT(rc_enc == 3);
817
818 rc_dec = gsm0808_dec_speech_codec(&dec_sc, msg->data + 2, msg->len - 2);
819 OSMO_ASSERT(rc_dec == 1);
820
821 OSMO_ASSERT(memcmp(&enc_sc, &dec_sc, sizeof(enc_sc)) == 0);
822
823 msgb_free(msg);
824}
825
826
Philipp Maierbb839662017-06-01 17:11:19 +0200827static void test_gsm0808_enc_dec_speech_codec_with_cfg()
828{
Neels Hofmeyrc62c9342018-04-15 23:31:47 +0200829 struct gsm0808_speech_codec enc_sc = {
830 .pi = true,
831 .tf = true,
832 .type = GSM0808_SCT_FR3,
833 .cfg = 0xabcd,
834 };
835 struct gsm0808_speech_codec dec_sc = {};
Philipp Maierbb839662017-06-01 17:11:19 +0200836 struct msgb *msg;
837 uint8_t rc_enc;
838 int rc_dec;
839
Philipp Maierbb839662017-06-01 17:11:19 +0200840 msg = msgb_alloc(1024, "output buffer");
841 rc_enc = gsm0808_enc_speech_codec(msg, &enc_sc);
842 OSMO_ASSERT(rc_enc == 5);
843
844 rc_dec = gsm0808_dec_speech_codec(&dec_sc, msg->data + 2, msg->len - 2);
845 OSMO_ASSERT(rc_dec == 3);
846
847 OSMO_ASSERT(memcmp(&enc_sc, &dec_sc, sizeof(enc_sc)) == 0);
848
849 msgb_free(msg);
850}
851
Philipp Maier6f725d62017-03-24 18:03:17 +0100852static void test_gsm0808_enc_dec_speech_codec_ext_with_cfg()
853{
Neels Hofmeyr9a4286b2018-04-20 12:27:52 +0200854 struct gsm0808_speech_codec enc_sc = {
855 .pi = true,
856 .tf = true,
857 .type = GSM0808_SCT_CSD,
858 .cfg = 0xc0,
859 };
860 struct gsm0808_speech_codec dec_sc = {};
Philipp Maier6f725d62017-03-24 18:03:17 +0100861 struct msgb *msg;
862 uint8_t rc_enc;
863 int rc_dec;
864
Philipp Maier6f725d62017-03-24 18:03:17 +0100865 msg = msgb_alloc(1024, "output buffer");
866 rc_enc = gsm0808_enc_speech_codec(msg, &enc_sc);
Philipp Maierbb839662017-06-01 17:11:19 +0200867 OSMO_ASSERT(rc_enc == 5);
Philipp Maier6f725d62017-03-24 18:03:17 +0100868
869 rc_dec = gsm0808_dec_speech_codec(&dec_sc, msg->data + 2, msg->len - 2);
Philipp Maierbb839662017-06-01 17:11:19 +0200870 OSMO_ASSERT(rc_dec == 3);
Philipp Maier6f725d62017-03-24 18:03:17 +0100871
872 OSMO_ASSERT(memcmp(&enc_sc, &dec_sc, sizeof(enc_sc)) == 0);
873
874 msgb_free(msg);
875}
876
877static void test_gsm0808_enc_dec_speech_codec_list()
878{
Neels Hofmeyr9a4286b2018-04-20 12:27:52 +0200879 struct gsm0808_speech_codec_list enc_scl = {
880 .codec = {
881 {
882 .pi = true,
883 .tf = true,
884 .type = GSM0808_SCT_FR3,
885 .cfg = 0xcdef,
886 },
887
888 {
889 .fi = true,
890 .pt = true,
891 .type = GSM0808_SCT_FR2,
892 },
893
894 {
895 .fi = true,
896 .tf = true,
897 .type = GSM0808_SCT_CSD,
898 .cfg = 0xc0,
899 },
900 },
901 .len = 3,
902 };
903 struct gsm0808_speech_codec_list dec_scl = {};
Philipp Maier6f725d62017-03-24 18:03:17 +0100904 struct msgb *msg;
905 uint8_t rc_enc;
906 int rc_dec;
907
Philipp Maier6f725d62017-03-24 18:03:17 +0100908 msg = msgb_alloc(1024, "output buffer");
909 rc_enc = gsm0808_enc_speech_codec_list(msg, &enc_scl);
910 OSMO_ASSERT(rc_enc == 9);
911
912 rc_dec = gsm0808_dec_speech_codec_list(&dec_scl, msg->data + 2, msg->len - 2);
913 OSMO_ASSERT(rc_dec == 7);
914
915 OSMO_ASSERT(memcmp(&enc_scl, &dec_scl, sizeof(enc_scl)) == 0);
916
917 msgb_free(msg);
918}
919
Philipp Maierf6c369f2018-10-16 15:24:47 +0200920static void test_gsm0808_enc_dec_empty_speech_codec_list()
921{
922 struct gsm0808_speech_codec_list enc_scl = {
923 .len = 0,
924 };
925 struct gsm0808_speech_codec_list dec_scl = {};
926 struct msgb *msg;
927 uint8_t rc_enc;
928 int rc_dec;
929
930 msg = msgb_alloc(1024, "output buffer");
931 rc_enc = gsm0808_enc_speech_codec_list(msg, &enc_scl);
932 OSMO_ASSERT(rc_enc == 2);
933
934 rc_dec = gsm0808_dec_speech_codec_list(&dec_scl, msg->data + 2, msg->len - 2);
935 OSMO_ASSERT(rc_dec == 0);
936
937 OSMO_ASSERT(memcmp(&enc_scl, &dec_scl, sizeof(enc_scl)) == 0);
938
939 msgb_free(msg);
940}
941
Philipp Maiere0c65302017-03-28 17:05:40 +0200942static void test_gsm0808_enc_dec_channel_type()
943{
Neels Hofmeyr9a4286b2018-04-20 12:27:52 +0200944 struct gsm0808_channel_type enc_ct = {
945 .ch_indctr = GSM0808_CHAN_SPEECH,
946 .ch_rate_type = GSM0808_SPEECH_HALF_PREF,
947 .perm_spch = { GSM0808_PERM_FR3, GSM0808_PERM_HR3 },
948 .perm_spch_len = 2,
949 };
950 struct gsm0808_channel_type dec_ct = {};
Philipp Maiere0c65302017-03-28 17:05:40 +0200951 struct msgb *msg;
952 uint8_t ct_enc_expected[] = { GSM0808_IE_CHANNEL_TYPE,
953 0x04, 0x01, 0x0b, 0xa1, 0x25
954 };
955 uint8_t rc_enc;
956 int rc_dec;
957
Philipp Maiere0c65302017-03-28 17:05:40 +0200958 msg = msgb_alloc(1024, "output buffer");
959 rc_enc = gsm0808_enc_channel_type(msg, &enc_ct);
960 OSMO_ASSERT(rc_enc == 6);
961 OSMO_ASSERT(memcmp(ct_enc_expected, msg->data, msg->len) == 0);
962
963 rc_dec = gsm0808_dec_channel_type(&dec_ct, msg->data + 2, msg->len - 2);
964 OSMO_ASSERT(rc_dec == 4);
965 OSMO_ASSERT(memcmp(&enc_ct, &dec_ct, sizeof(enc_ct)) == 0);
966
967 msgb_free(msg);
968}
969
Philipp Maier14e76b92017-03-28 18:36:52 +0200970static void test_gsm0808_enc_dec_encrypt_info()
971{
Neels Hofmeyr9a4286b2018-04-20 12:27:52 +0200972 struct gsm0808_encrypt_info enc_ei = {
973 .perm_algo = { GSM0808_ALG_ID_A5_0, GSM0808_ALG_ID_A5_1 },
974 .perm_algo_len = 2,
975 .key = { 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x23, 0x42, },
976 .key_len = 8,
977 };
978 struct gsm0808_encrypt_info dec_ei = {};
Philipp Maier14e76b92017-03-28 18:36:52 +0200979 struct msgb *msg;
980 uint8_t ei_enc_expected[] =
981 { GSM0808_IE_ENCRYPTION_INFORMATION, 0x09, 0x03, 0xaa, 0xbb,
982 0xcc, 0xdd, 0xee, 0xff, 0x23, 0x42
983 };
984 uint8_t rc_enc;
985 int rc_dec;
986
Philipp Maier14e76b92017-03-28 18:36:52 +0200987 msg = msgb_alloc(1024, "output buffer");
988 rc_enc = gsm0808_enc_encrypt_info(msg, &enc_ei);
989 OSMO_ASSERT(rc_enc == 11);
990 OSMO_ASSERT(memcmp(ei_enc_expected, msg->data, msg->len) == 0);
991
992 rc_dec = gsm0808_dec_encrypt_info(&dec_ei, msg->data + 2, msg->len - 2);
993 OSMO_ASSERT(rc_dec == 9);
994
995 OSMO_ASSERT(memcmp(&enc_ei, &dec_ei, sizeof(enc_ei)) == 0);
996
997 msgb_free(msg);
998}
999
Philipp Maier783047e2017-03-29 11:35:50 +02001000static void test_gsm0808_enc_dec_cell_id_list_lac()
1001{
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001002 struct gsm0808_cell_id_list2 enc_cil;
1003 struct gsm0808_cell_id_list2 dec_cil;
Philipp Maier783047e2017-03-29 11:35:50 +02001004 struct msgb *msg;
1005 uint8_t rc_enc;
1006 int rc_dec;
1007
1008 memset(&enc_cil, 0, sizeof(enc_cil));
1009 enc_cil.id_discr = CELL_IDENT_LAC;
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001010 enc_cil.id_list[0].lac = 0x0124;
Neels Hofmeyrdb2fa4e2018-04-13 04:11:20 +02001011 enc_cil.id_list[1].lac = 0xABCD;
1012 enc_cil.id_list[2].lac = 0x5678;
Philipp Maier783047e2017-03-29 11:35:50 +02001013 enc_cil.id_list_len = 3;
1014
1015 msg = msgb_alloc(1024, "output buffer");
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001016 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
Neels Hofmeyrdb2fa4e2018-04-13 04:11:20 +02001017 EXPECT_ENCODED("1a 07 05 01 24 ab cd 56 78");
Philipp Maier783047e2017-03-29 11:35:50 +02001018
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001019 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
Philipp Maier783047e2017-03-29 11:35:50 +02001020 OSMO_ASSERT(rc_dec == 7);
1021
1022 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
1023
1024 msgb_free(msg);
1025}
1026
1027static void test_gsm0808_enc_dec_cell_id_list_single_lac()
1028{
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001029 struct gsm0808_cell_id_list2 enc_cil;
1030 struct gsm0808_cell_id_list2 dec_cil;
Philipp Maier783047e2017-03-29 11:35:50 +02001031 struct msgb *msg;
1032 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x03,
1033 0x05, 0x23, 0x42
1034 };
1035 uint8_t rc_enc;
1036 int rc_dec;
1037
1038 memset(&enc_cil, 0, sizeof(enc_cil));
1039 enc_cil.id_discr = CELL_IDENT_LAC;
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001040 enc_cil.id_list[0].lac = 0x2342;
Philipp Maier783047e2017-03-29 11:35:50 +02001041 enc_cil.id_list_len = 1;
1042
1043 msg = msgb_alloc(1024, "output buffer");
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001044 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
Philipp Maier783047e2017-03-29 11:35:50 +02001045 OSMO_ASSERT(rc_enc == 5);
1046 OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0);
1047
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001048 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
Philipp Maier783047e2017-03-29 11:35:50 +02001049 OSMO_ASSERT(rc_dec == 3);
1050
1051 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
1052
1053 msgb_free(msg);
1054}
1055
Stefan Sperlinge1a86742018-03-15 18:05:02 +01001056static void test_gsm0808_enc_dec_cell_id_list_multi_lac()
1057{
1058 struct gsm0808_cell_id_list2 enc_cil;
1059 struct gsm0808_cell_id_list2 dec_cil;
1060 struct msgb *msg;
1061 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x0b, 0x05,
1062 0x23, 0x42,
1063 0x24, 0x43,
1064 0x25, 0x44,
1065 0x26, 0x45,
1066 0x27, 0x46
1067 };
1068 uint8_t rc_enc;
1069 int rc_dec;
1070
1071 memset(&enc_cil, 0, sizeof(enc_cil));
1072 enc_cil.id_discr = CELL_IDENT_LAC;
1073 enc_cil.id_list[0].lac = 0x2342;
1074 enc_cil.id_list[1].lac = 0x2443;
1075 enc_cil.id_list[2].lac = 0x2544;
1076 enc_cil.id_list[3].lac = 0x2645;
1077 enc_cil.id_list[4].lac = 0x2746;
1078 enc_cil.id_list_len = 5;
1079
1080 msg = msgb_alloc(1024, "output buffer");
1081 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
1082 OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected));
1083 OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0);
1084
1085 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
1086 OSMO_ASSERT(rc_dec == msg->len - 2);
1087 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
1088
1089 msgb_free(msg);
1090}
1091
Philipp Maier783047e2017-03-29 11:35:50 +02001092static void test_gsm0808_enc_dec_cell_id_list_bss()
1093{
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001094 struct gsm0808_cell_id_list2 enc_cil;
1095 struct gsm0808_cell_id_list2 dec_cil;
Philipp Maier783047e2017-03-29 11:35:50 +02001096 struct msgb *msg;
1097 uint8_t rc_enc;
1098 int rc_dec;
1099
1100 memset(&enc_cil, 0, sizeof(enc_cil));
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001101 enc_cil.id_discr = CELL_IDENT_BSS;
Philipp Maier783047e2017-03-29 11:35:50 +02001102
1103 msg = msgb_alloc(1024, "output buffer");
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001104 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
Philipp Maier783047e2017-03-29 11:35:50 +02001105 OSMO_ASSERT(rc_enc == 3);
1106
Stefan Sperling11a4d9d2018-02-15 18:28:04 +01001107 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
Philipp Maier783047e2017-03-29 11:35:50 +02001108 OSMO_ASSERT(rc_dec == 1);
1109
1110 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
1111
1112 msgb_free(msg);
1113}
1114
Stefan Sperling23381452018-03-15 19:38:15 +01001115static void test_gsm0808_enc_dec_cell_id_list_multi_lai_and_lac()
1116{
1117 struct gsm0808_cell_id_list2 enc_cil;
1118 struct gsm0808_cell_id_list2 dec_cil;
1119 struct osmo_location_area_id id;
1120 struct msgb *msg;
1121 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x10, 0x04,
1122 0x92, 0x61, 0x54, 0x23, 0x42,
1123 0x92, 0x72, 0x54, 0x24, 0x43,
1124 0x92, 0x83, 0x54, 0x25, 0x44
1125 };
1126 uint8_t rc_enc;
1127 int rc_dec, i;
1128
1129 memset(&enc_cil, 0, sizeof(enc_cil));
1130 enc_cil.id_discr = CELL_IDENT_LAI_AND_LAC;
1131
1132 id.plmn.mcc = 0x123;
1133 osmo_mnc_from_str("456", &id.plmn.mnc, &id.plmn.mnc_3_digits);
1134 id.lac = 0x2342;
1135 memcpy(&enc_cil.id_list[0].lai_and_lac, &id, sizeof(id));
1136
1137 id.plmn.mcc = 0x124;
1138 osmo_mnc_from_str("457", &id.plmn.mnc, &id.plmn.mnc_3_digits);
1139 id.lac = 0x2443;
1140 memcpy(&enc_cil.id_list[1].lai_and_lac, &id, sizeof(id));
1141
1142 id.plmn.mcc = 0x125;
1143 osmo_mnc_from_str("458", &id.plmn.mnc, &id.plmn.mnc_3_digits);
1144 id.lac = 0x2544;
1145 memcpy(&enc_cil.id_list[2].lai_and_lac, &id, sizeof(id));
1146
1147 enc_cil.id_list_len = 3;
1148
1149 msg = msgb_alloc(1024, "output buffer");
1150 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
1151 OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected));
1152 OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0);
1153
1154 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
1155 OSMO_ASSERT(rc_dec == msg->len - 2);
1156
1157 OSMO_ASSERT(dec_cil.id_list_len == 3);
1158 /* Check MAXLEN elements to ensure everything has been initialized. */
1159 for (i = 0; i < GSM0808_CELL_ID_LIST2_MAXLEN; i++) {
1160 struct osmo_location_area_id *enc_id;
1161 struct osmo_location_area_id *dec_id;
1162 enc_id = &enc_cil.id_list[i].lai_and_lac;
1163 dec_id = &dec_cil.id_list[i].lai_and_lac;
1164 OSMO_ASSERT(osmo_plmn_cmp(&enc_id->plmn, &dec_id->plmn) == 0);
1165 OSMO_ASSERT(enc_id->lac == dec_id->lac);
1166 }
1167
1168 msgb_free(msg);
1169}
1170
Stefan Sperling9c62fc62018-03-16 10:23:34 +01001171static void test_gsm0808_enc_dec_cell_id_list_multi_ci()
1172{
1173 struct gsm0808_cell_id_list2 enc_cil;
1174 struct gsm0808_cell_id_list2 dec_cil;
1175 struct msgb *msg;
1176 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x09, 0x02,
1177 0x00, 0x01,
1178 0x00, 0x02,
1179 0x00, 0x77,
1180 0x01, 0xff,
1181 };
1182 uint8_t rc_enc;
1183 int rc_dec;
1184
1185 memset(&enc_cil, 0, sizeof(enc_cil));
1186 enc_cil.id_discr = CELL_IDENT_CI;
1187 enc_cil.id_list[0].ci = 1;
1188 enc_cil.id_list[1].ci = 2;
1189 enc_cil.id_list[2].ci = 119;
1190 enc_cil.id_list[3].ci = 511;
1191 enc_cil.id_list_len = 4;
1192
1193 msg = msgb_alloc(1024, "output buffer");
1194 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
1195 OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected));
1196 OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0);
1197
1198 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
1199 OSMO_ASSERT(rc_dec == msg->len - 2);
1200 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
1201
1202 msgb_free(msg);
1203}
1204
Stefan Sperlinged4327c2018-03-16 11:02:59 +01001205static void test_gsm0808_enc_dec_cell_id_list_multi_lac_and_ci()
1206{
1207 struct gsm0808_cell_id_list2 enc_cil;
1208 struct gsm0808_cell_id_list2 dec_cil;
1209 struct msgb *msg;
1210 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x15, 0x01,
1211 0x23, 0x42, 0x00, 0x01,
1212 0x24, 0x43, 0x00, 0x02,
1213 0x25, 0x44, 0x00, 0x77,
1214 0x26, 0x45, 0x01, 0xff,
1215 0x27, 0x46, 0x02, 0xfe,
1216 };
1217 uint8_t rc_enc;
1218 int rc_dec;
1219
1220 memset(&enc_cil, 0, sizeof(enc_cil));
1221 enc_cil.id_discr = CELL_IDENT_LAC_AND_CI;
1222 enc_cil.id_list[0].lac_and_ci.lac = 0x2342;
1223 enc_cil.id_list[0].lac_and_ci.ci = 1;
1224 enc_cil.id_list[1].lac_and_ci.lac = 0x2443;
1225 enc_cil.id_list[1].lac_and_ci.ci = 2;
1226 enc_cil.id_list[2].lac_and_ci.lac = 0x2544;
1227 enc_cil.id_list[2].lac_and_ci.ci = 119;
1228 enc_cil.id_list[3].lac_and_ci.lac = 0x2645;
1229 enc_cil.id_list[3].lac_and_ci.ci = 511;
1230 enc_cil.id_list[4].lac_and_ci.lac = 0x2746;
1231 enc_cil.id_list[4].lac_and_ci.ci = 766;
1232 enc_cil.id_list_len = 5;
1233
1234 msg = msgb_alloc(1024, "output buffer");
1235 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
1236 OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected));
1237 OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0);
1238
1239 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
1240 OSMO_ASSERT(rc_dec == msg->len - 2);
1241 OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
1242
1243 msgb_free(msg);
1244}
1245
Stefan Sperling483f3862018-03-16 12:21:26 +01001246static void test_gsm0808_enc_dec_cell_id_list_multi_global()
1247{
1248 struct gsm0808_cell_id_list2 enc_cil;
1249 struct gsm0808_cell_id_list2 dec_cil;
1250 struct msgb *msg;
1251 uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x16, 0x00,
Neels Hofmeyr473485c2018-03-23 02:04:18 +01001252 0x21, 0x63, 0x54, 0x23, 0x42, 0x00, 0x1,
Neels Hofmeyrc44fc232018-03-23 02:15:12 +01001253 0x21, 0xf4, 0x75, 0x24, 0x43, 0x00, 0x2,
Neels Hofmeyr8b8cd932018-03-23 01:47:37 +01001254 0x21, 0x75, 0x00, 0x25, 0x44, 0x00, 0x77
Stefan Sperling483f3862018-03-16 12:21:26 +01001255 };
Stefan Sperling483f3862018-03-16 12:21:26 +01001256 uint8_t rc_enc;
1257 int rc_dec, i;
1258
Neels Hofmeyrc1991df2018-03-23 02:00:00 +01001259 enc_cil = (struct gsm0808_cell_id_list2){
1260 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1261 .id_list_len = 3,
1262 .id_list = {
1263 {
1264 .global = {
Neels Hofmeyr473485c2018-03-23 02:04:18 +01001265 .lai = { .plmn = { .mcc = 123, .mnc = 456 },
Neels Hofmeyrc1991df2018-03-23 02:00:00 +01001266 .lac = 0x2342 },
1267 .cell_identity = 1,
1268 }
1269 },
1270 {
1271 .global = {
Neels Hofmeyrc44fc232018-03-23 02:15:12 +01001272 .lai = { .plmn = { .mcc = 124, .mnc = 57 },
Neels Hofmeyrc1991df2018-03-23 02:00:00 +01001273 .lac = 0x2443 },
1274 .cell_identity = 2,
1275 }
1276 },
1277 {
1278 .global = {
Neels Hofmeyrc44fc232018-03-23 02:15:12 +01001279 .lai = { .plmn = { .mcc = 125, .mnc = 7,
1280 .mnc_3_digits = true },
Neels Hofmeyrc1991df2018-03-23 02:00:00 +01001281 .lac = 0x2544 },
1282 .cell_identity = 119,
1283 }
1284 },
1285 }
1286 };
Stefan Sperling483f3862018-03-16 12:21:26 +01001287
1288 msg = msgb_alloc(1024, "output buffer");
1289 rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
1290 OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected));
Neels Hofmeyrc1991df2018-03-23 02:00:00 +01001291 if (memcmp(cil_enc_expected, msg->data, msg->len)) {
1292 printf(" got: %s\n", osmo_hexdump(msg->data, msg->len));
1293 printf("expect: %s\n", osmo_hexdump(cil_enc_expected, sizeof(cil_enc_expected)));
1294 OSMO_ASSERT(false);
1295 }
Stefan Sperling483f3862018-03-16 12:21:26 +01001296
1297 rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
1298 OSMO_ASSERT(rc_dec == msg->len - 2);
1299
1300 /* Check MAXLEN elements to ensure everything has been initialized. */
1301 for (i = 0; i < GSM0808_CELL_ID_LIST2_MAXLEN; i++) {
1302 struct osmo_cell_global_id *enc_id;
1303 struct osmo_cell_global_id *dec_id;
1304 enc_id = &enc_cil.id_list[i].global;
1305 dec_id = &dec_cil.id_list[i].global;
1306 OSMO_ASSERT(osmo_plmn_cmp(&enc_id->lai.plmn, &dec_id->lai.plmn) == 0);
1307 OSMO_ASSERT(enc_id->lai.lac == dec_id->lai.lac);
1308 OSMO_ASSERT(enc_id->cell_identity == dec_id->cell_identity);
1309 }
1310
1311 msgb_free(msg);
1312}
1313
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001314static void print_cil(const struct gsm0808_cell_id_list2 *cil)
1315{
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001316 printf(" cell_id_list == %s\n", gsm0808_cell_id_list_name(cil));
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001317}
1318
1319void test_cell_id_list_add() {
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001320 size_t zu;
1321
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001322 const struct gsm0808_cell_id_list2 cgi1 = {
1323 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1324 .id_list_len = 1,
1325 .id_list = {
1326 {
1327 .global = {
1328 .lai = {
1329 .plmn = { .mcc = 1, .mnc = 2, .mnc_3_digits = false },
1330 .lac = 3,
1331 },
1332 .cell_identity = 4,
1333 }
1334 },
1335 },
1336 };
1337
1338 const struct gsm0808_cell_id_list2 cgi2 = {
1339 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1340 .id_list_len = 2,
1341 .id_list = {
1342 {
1343 .global = {
1344 .lai = {
1345 .plmn = { .mcc = 1, .mnc = 2, .mnc_3_digits = true },
1346 .lac = 3,
1347 },
1348 .cell_identity = 4,
1349 }
1350 },
1351 {
1352 .global = {
1353 .lai = {
1354 .plmn = { .mcc = 5, .mnc = 6, .mnc_3_digits = true },
1355 .lac = 7,
1356 },
1357 .cell_identity = 8,
1358 }
1359 },
1360 },
1361 };
1362
1363 const struct gsm0808_cell_id_list2 cgi2a = {
1364 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1365 .id_list_len = 2,
1366 .id_list = {
1367 {
1368 .global = cgi2.id_list[0].global
1369 },
1370 {
1371 .global = {
1372 .lai = {
1373 .plmn = { .mcc = 9, .mnc = 10, .mnc_3_digits = true },
1374 .lac = 11,
1375 },
1376 .cell_identity = 12,
1377 }
1378 },
1379 },
1380 };
1381
1382 const struct gsm0808_cell_id_list2 cgi3 = {
1383 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1384 .id_list_len = 2,
1385 .id_list = {
1386 {
1387 .global = {
1388 .lai = {
1389 .plmn = { .mcc = 13, .mnc = 14, .mnc_3_digits = true },
1390 .lac = 15,
1391 },
1392 .cell_identity = 16,
1393 }
1394 },
1395 {
1396 .global = {
1397 .lai = {
1398 .plmn = { .mcc = 16, .mnc = 17, .mnc_3_digits = true },
1399 .lac = 18,
1400 },
1401 .cell_identity = 19,
1402 }
1403 },
1404 },
1405 };
1406
1407
1408 const struct gsm0808_cell_id_list2 lac1 = {
1409 .id_discr = CELL_IDENT_LAC,
1410 .id_list_len = 1,
1411 .id_list = {
1412 {
1413 .lac = 123
1414 },
1415 },
1416 };
1417
1418 const struct gsm0808_cell_id_list2 lac2 = {
1419 .id_discr = CELL_IDENT_LAC,
1420 .id_list_len = 2,
1421 .id_list = {
1422 {
1423 .lac = 456
1424 },
1425 {
1426 .lac = 789
1427 },
1428 },
1429 };
1430
1431 struct gsm0808_cell_id_list2 cil = {};
1432
1433 printf("------- %s\n", __func__);
1434
1435 print_cil(&cil);
1436
1437#define ADD_QUIET(other_cil, expect_rc) do { \
1438 int rc = gsm0808_cell_id_list_add(&cil, &other_cil); \
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001439 printf("gsm0808_cell_id_list_add(&cil, &" #other_cil ") --> rc = %d\n", rc); \
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001440 OSMO_ASSERT(rc == expect_rc); \
1441 } while(0)
1442
1443#define ADD(other_cil, expect_rc) ADD_QUIET(other_cil, expect_rc); print_cil(&cil)
1444
1445 ADD(lac1, 1);
1446 ADD(lac1, 0);
1447 ADD(lac2, 2);
1448 ADD(lac2, 0);
1449 ADD(cil, 0);
1450 ADD(cgi1, -EINVAL);
1451
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001452 printf("* can't add to BSS list\n");
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001453 cil.id_list_len = 0;
1454 cil.id_discr = CELL_IDENT_BSS;
1455 print_cil(&cil);
1456 ADD(lac1, -EINVAL);
1457
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001458 printf("* other types (including NO_CELL) take on new type iff empty\n");
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001459 cil.id_list_len = 0;
1460 cil.id_discr = CELL_IDENT_NO_CELL;
1461 print_cil(&cil);
1462 ADD(cgi1, 1);
1463 ADD(cgi1, 0);
1464 ADD(cgi2, 2);
1465 ADD(cgi2, 0);
1466
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001467 printf("* test gsm0808_cell_id_list_name_buf()'s return val\n");
1468 zu = strlen(gsm0808_cell_id_list_name(&cil));
1469 printf(" strlen(gsm0808_cell_id_list_name(cil)) == %zu\n", zu);
1470 zu ++;
1471 while (1) {
1472 char buf[128] = "?";
1473 int rc;
1474 OSMO_ASSERT(zu < sizeof(buf));
1475 buf[zu] = '#';
1476 rc = gsm0808_cell_id_list_name_buf(buf, zu, &cil);
1477 printf(" gsm0808_cell_id_list_name_buf(buf, %zu, cil)) == %d \"%s\"\n",
1478 zu, rc, buf);
1479 OSMO_ASSERT(buf[zu] == '#');
1480 if (!zu)
1481 break;
1482 zu /= 2;
1483 }
1484
1485 printf("* list-full behavior\n");
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001486 cil.id_list_len = GSM0808_CELL_ID_LIST2_MAXLEN - 1;
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001487 printf("cil.id_list_len = %u\n", cil.id_list_len);
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001488 ADD_QUIET(cgi2a, 1);
1489 printf("cil.id_list_len = %u\n", cil.id_list_len);
1490
1491 cil.id_list_len = GSM0808_CELL_ID_LIST2_MAXLEN - 1;
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001492 printf("cil.id_list_len = %u\n", cil.id_list_len);
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001493 ADD_QUIET(cgi3, -ENOSPC);
Neels Hofmeyra4399c82018-04-17 02:26:10 +02001494 printf("cil.id_list_len = %u\n", cil.id_list_len);
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001495 ADD_QUIET(cgi2a, -ENOSPC);
1496 printf("cil.id_list_len = %u\n", cil.id_list_len);
1497
1498 printf("------- %s done\n", __func__);
1499}
1500
Neels Hofmeyr250e7f72018-04-13 03:30:14 +02001501static void test_gsm0808_enc_dec_cell_id_lac()
1502{
1503 struct gsm0808_cell_id enc_ci = {
1504 .id_discr = CELL_IDENT_LAC,
1505 .id.lac = 0x0124,
1506 };
1507 struct gsm0808_cell_id dec_ci;
1508 struct msgb *msg;
1509 uint8_t rc_enc;
1510 int rc_dec;
1511
1512 memset(&dec_ci, 0xa5, sizeof(dec_ci));
1513
1514 msg = msgb_alloc(1024, "output buffer");
1515 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1516 EXPECT_ENCODED("05 03 05 01 24");
1517
1518 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1519 OSMO_ASSERT(rc_dec == 3);
1520
1521 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr
1522 && enc_ci.id.lac == dec_ci.id.lac);
1523
1524 msgb_free(msg);
1525}
1526
1527static void test_gsm0808_enc_dec_cell_id_bss()
1528{
1529 struct gsm0808_cell_id enc_ci = {
1530 .id_discr = CELL_IDENT_BSS,
1531 };
1532 struct gsm0808_cell_id dec_ci;
1533 struct msgb *msg;
1534 uint8_t rc_enc;
1535 int rc_dec;
1536
1537 msg = msgb_alloc(1024, "output buffer");
1538 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1539 EXPECT_ENCODED("05 01 06");
1540
1541 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1542 OSMO_ASSERT(rc_dec == 1);
1543
1544 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr);
1545
1546 msgb_free(msg);
1547}
1548
1549static void test_gsm0808_enc_dec_cell_id_no_cell()
1550{
1551 struct gsm0808_cell_id enc_ci = {
1552 .id_discr = CELL_IDENT_NO_CELL,
1553 };
1554 struct gsm0808_cell_id dec_ci;
1555 struct msgb *msg;
1556 uint8_t rc_enc;
1557 int rc_dec;
1558
1559 msg = msgb_alloc(1024, "output buffer");
1560 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1561 EXPECT_ENCODED("05 01 03");
1562
1563 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1564 OSMO_ASSERT(rc_dec == 1);
1565
1566 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr);
1567
1568 msgb_free(msg);
1569}
1570
1571static void test_gsm0808_enc_dec_cell_id_lai_and_lac()
1572{
1573 struct gsm0808_cell_id enc_ci = {
1574 .id_discr = CELL_IDENT_LAI_AND_LAC,
1575 .id.lai_and_lac = {
1576 .plmn = {
1577 .mcc = 123,
1578 .mnc = 456,
1579 },
1580 .lac = 0x2342,
1581 },
1582 };
1583 struct gsm0808_cell_id dec_ci;
1584 struct msgb *msg;
1585 uint8_t rc_enc;
1586 int rc_dec;
1587
1588 msg = msgb_alloc(1024, "output buffer");
1589 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1590 EXPECT_ENCODED("05 06 04 21 63 54 23 42");
1591
1592 memset(&dec_ci, 0xa5, sizeof(dec_ci));
1593 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1594 OSMO_ASSERT(rc_dec == msg->len - 2);
1595
1596 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr
1597 && osmo_plmn_cmp(&enc_ci.id.lai_and_lac.plmn, &dec_ci.id.lai_and_lac.plmn) == 0
1598 && enc_ci.id.lai_and_lac.lac == dec_ci.id.lai_and_lac.lac);
1599 msgb_free(msg);
1600}
1601
1602static void test_gsm0808_enc_dec_cell_id_ci()
1603{
1604 struct gsm0808_cell_id enc_ci = {
1605 .id_discr = CELL_IDENT_CI,
1606 .id.ci = 0x423,
1607 };
1608 struct gsm0808_cell_id dec_ci;
1609 struct msgb *msg;
1610 uint8_t rc_enc;
1611 int rc_dec;
1612
1613 msg = msgb_alloc(1024, "output buffer");
1614 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1615 EXPECT_ENCODED("05 03 02 04 23");
1616
1617 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1618 OSMO_ASSERT(rc_dec == msg->len - 2);
1619 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr
1620 && enc_ci.id.ci == dec_ci.id.ci);
1621
1622 msgb_free(msg);
1623}
1624
1625static void test_gsm0808_enc_dec_cell_id_lac_and_ci()
1626{
1627 struct gsm0808_cell_id enc_ci = {
1628 .id_discr = CELL_IDENT_LAC_AND_CI,
1629 .id.lac_and_ci = {
1630 .lac = 0x423,
1631 .ci = 0x235,
1632 },
1633 };
1634 struct gsm0808_cell_id dec_ci;
1635 struct msgb *msg;
1636 uint8_t rc_enc;
1637 int rc_dec;
1638
1639 msg = msgb_alloc(1024, "output buffer");
1640 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1641 EXPECT_ENCODED("05 05 01 04 23 02 35");
1642
1643 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1644 OSMO_ASSERT(rc_dec == msg->len - 2);
1645 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr
1646 && enc_ci.id.lac_and_ci.lac == dec_ci.id.lac_and_ci.lac
1647 && enc_ci.id.lac_and_ci.ci == dec_ci.id.lac_and_ci.ci);
1648
1649 msgb_free(msg);
1650}
1651
1652static void test_gsm0808_enc_dec_cell_id_global()
1653{
1654 struct gsm0808_cell_id enc_ci = {
1655 .id_discr = CELL_IDENT_WHOLE_GLOBAL,
1656 .id.global = {
1657 .lai = {
1658 .plmn = { .mcc = 123, .mnc = 456 },
1659 .lac = 0x2342
1660 },
1661 .cell_identity = 0x423,
1662 }
1663 };
1664 struct gsm0808_cell_id dec_ci;
1665 struct msgb *msg;
1666 uint8_t rc_enc;
1667 int rc_dec;
1668
1669 msg = msgb_alloc(1024, "output buffer");
1670 rc_enc = gsm0808_enc_cell_id(msg, &enc_ci);
1671 EXPECT_ENCODED("05 08 00 21 63 54 23 42 04 23");
1672
1673 rc_dec = gsm0808_dec_cell_id(&dec_ci, msg->data + 2, msg->len - 2);
1674 OSMO_ASSERT(rc_dec == msg->len - 2);
1675
1676 OSMO_ASSERT(enc_ci.id_discr == dec_ci.id_discr
1677 && osmo_plmn_cmp(&enc_ci.id.global.lai.plmn,
1678 &dec_ci.id.global.lai.plmn) == 0
1679 && enc_ci.id.global.lai.lac == dec_ci.id.global.lai.lac
1680 && enc_ci.id.global.cell_identity == dec_ci.id.global.cell_identity);
1681 msgb_free(msg);
1682}
1683
Philipp Maier5f2eb152018-09-19 13:40:21 +02001684static void test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(struct gsm48_multi_rate_conf *cfg)
1685{
1686 uint16_t s15_s0;
1687
1688 printf("Input:\n");
1689 printf(" m4_75= %u smod= %u\n", cfg->m4_75, cfg->smod);
1690 printf(" m5_15= %u spare= %u\n", cfg->m5_15, cfg->spare);
1691 printf(" m5_90= %u icmi= %u\n", cfg->m5_90, cfg->icmi);
1692 printf(" m6_70= %u nscb= %u\n", cfg->m6_70, cfg->nscb);
1693 printf(" m7_40= %u ver= %u\n", cfg->m7_40, cfg->ver);
1694 printf(" m7_95= %u\n", cfg->m7_95);
1695 printf(" m10_2= %u\n", cfg->m10_2);
1696 printf(" m12_2= %u\n", cfg->m12_2);
1697
1698 s15_s0 = gsm0808_sc_cfg_from_gsm48_mr_cfg(cfg, true);
1699 printf("Result (fr):\n");
1700 printf(" S15-S0 = %04x = 0b" OSMO_BIN_SPEC OSMO_BIN_SPEC "\n", s15_s0,
1701 OSMO_BIN_PRINT(s15_s0 >> 8), OSMO_BIN_PRINT(s15_s0));
1702
1703 s15_s0 = gsm0808_sc_cfg_from_gsm48_mr_cfg(cfg, false);
1704 printf("Result (hr):\n");
1705 printf(" S15-S0 = %04x = 0b" OSMO_BIN_SPEC OSMO_BIN_SPEC "\n", s15_s0,
1706 OSMO_BIN_PRINT(s15_s0 >> 8), OSMO_BIN_PRINT(s15_s0));
1707
1708 printf("\n");
1709}
1710
1711static void test_gsm0808_sc_cfg_from_gsm48_mr_cfg(void)
1712{
1713 struct gsm48_multi_rate_conf cfg;
1714
1715 printf("Testing gsm0808_sc_cfg_from_gsm48_mr_cfg():\n");
1716
1717 memset(&cfg, 0, sizeof(cfg));
1718
1719 cfg.m4_75 = 0;
1720 cfg.m5_15 = 0;
1721 cfg.m5_90 = 0;
1722 cfg.m6_70 = 0;
1723 cfg.m7_40 = 0;
1724 cfg.m7_95 = 0;
1725 cfg.m10_2 = 0;
1726 cfg.m12_2 = 0;
1727 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1728
1729 cfg.m4_75 = 1;
1730 cfg.m5_15 = 0;
1731 cfg.m5_90 = 0;
1732 cfg.m6_70 = 0;
1733 cfg.m7_40 = 0;
1734 cfg.m7_95 = 0;
1735 cfg.m10_2 = 0;
1736 cfg.m12_2 = 0;
1737 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1738
1739 cfg.m4_75 = 0;
1740 cfg.m5_15 = 1;
1741 cfg.m5_90 = 0;
1742 cfg.m6_70 = 0;
1743 cfg.m7_40 = 0;
1744 cfg.m7_95 = 0;
1745 cfg.m10_2 = 0;
1746 cfg.m12_2 = 0;
1747 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1748
1749 cfg.m4_75 = 0;
1750 cfg.m5_15 = 0;
1751 cfg.m5_90 = 1;
1752 cfg.m6_70 = 0;
1753 cfg.m7_40 = 0;
1754 cfg.m7_95 = 0;
1755 cfg.m10_2 = 0;
1756 cfg.m12_2 = 0;
1757 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1758
1759 cfg.m4_75 = 0;
1760 cfg.m5_15 = 0;
1761 cfg.m5_90 = 0;
1762 cfg.m6_70 = 1;
1763 cfg.m7_40 = 0;
1764 cfg.m7_95 = 0;
1765 cfg.m10_2 = 0;
1766 cfg.m12_2 = 0;
1767 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1768
1769 cfg.m4_75 = 0;
1770 cfg.m5_15 = 0;
1771 cfg.m5_90 = 0;
1772 cfg.m6_70 = 0;
1773 cfg.m7_40 = 1;
1774 cfg.m7_95 = 0;
1775 cfg.m10_2 = 0;
1776 cfg.m12_2 = 0;
1777 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1778
1779 cfg.m4_75 = 0;
1780 cfg.m5_15 = 0;
1781 cfg.m5_90 = 0;
1782 cfg.m6_70 = 0;
1783 cfg.m7_40 = 0;
1784 cfg.m7_95 = 1;
1785 cfg.m10_2 = 0;
1786 cfg.m12_2 = 0;
1787 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1788
1789 cfg.m4_75 = 0;
1790 cfg.m5_15 = 0;
1791 cfg.m5_90 = 0;
1792 cfg.m6_70 = 0;
1793 cfg.m7_40 = 0;
1794 cfg.m7_95 = 0;
1795 cfg.m10_2 = 1;
1796 cfg.m12_2 = 0;
1797 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1798
1799 cfg.m4_75 = 0;
1800 cfg.m5_15 = 0;
1801 cfg.m5_90 = 0;
1802 cfg.m6_70 = 0;
1803 cfg.m7_40 = 0;
1804 cfg.m7_95 = 0;
1805 cfg.m10_2 = 0;
1806 cfg.m12_2 = 1;
1807 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1808
1809 cfg.m4_75 = 1;
1810 cfg.m5_15 = 1;
1811 cfg.m5_90 = 1;
1812 cfg.m6_70 = 1;
1813 cfg.m7_40 = 0;
1814 cfg.m7_95 = 0;
1815 cfg.m10_2 = 0;
1816 cfg.m12_2 = 0;
1817 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1818
1819 cfg.m4_75 = 0;
1820 cfg.m5_15 = 0;
1821 cfg.m5_90 = 0;
1822 cfg.m6_70 = 0;
1823 cfg.m7_40 = 1;
1824 cfg.m7_95 = 1;
1825 cfg.m10_2 = 1;
1826 cfg.m12_2 = 1;
1827 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1828
1829 cfg.m4_75 = 0;
1830 cfg.m5_15 = 0;
1831 cfg.m5_90 = 1;
1832 cfg.m6_70 = 1;
1833 cfg.m7_40 = 0;
1834 cfg.m7_95 = 0;
1835 cfg.m10_2 = 1;
1836 cfg.m12_2 = 1;
1837 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1838
1839 cfg.m4_75 = 1;
1840 cfg.m5_15 = 1;
1841 cfg.m5_90 = 0;
1842 cfg.m6_70 = 0;
1843 cfg.m7_40 = 1;
1844 cfg.m7_95 = 1;
1845 cfg.m10_2 = 0;
1846 cfg.m12_2 = 0;
1847 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1848
1849 cfg.m4_75 = 0;
1850 cfg.m5_15 = 1;
1851 cfg.m5_90 = 0;
1852 cfg.m6_70 = 1;
1853 cfg.m7_40 = 0;
1854 cfg.m7_95 = 1;
1855 cfg.m10_2 = 0;
1856 cfg.m12_2 = 1;
1857 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1858
1859 cfg.m4_75 = 1;
1860 cfg.m5_15 = 0;
1861 cfg.m5_90 = 1;
1862 cfg.m6_70 = 0;
1863 cfg.m7_40 = 1;
1864 cfg.m7_95 = 0;
1865 cfg.m10_2 = 1;
1866 cfg.m12_2 = 0;
1867 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1868
1869 cfg.m4_75 = 1;
1870 cfg.m5_15 = 1;
1871 cfg.m5_90 = 1;
1872 cfg.m6_70 = 1;
1873 cfg.m7_40 = 1;
1874 cfg.m7_95 = 1;
1875 cfg.m10_2 = 1;
1876 cfg.m12_2 = 1;
1877 test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
1878}
1879
Philipp Maier8515d032018-09-25 15:57:49 +02001880static void test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single(uint16_t s15_s0)
1881{
1882 struct gsm48_multi_rate_conf cfg;
1883
1884 printf("Input:\n");
1885 printf(" S15-S0 = %04x = 0b" OSMO_BIN_SPEC OSMO_BIN_SPEC "\n", s15_s0,
1886 OSMO_BIN_PRINT(s15_s0 >> 8), OSMO_BIN_PRINT(s15_s0));
1887
1888 gsm48_mr_cfg_from_gsm0808_sc_cfg(&cfg, s15_s0);
1889
1890 printf("Output:\n");
1891 printf(" m4_75= %u smod= %u\n", cfg.m4_75, cfg.smod);
1892 printf(" m5_15= %u spare= %u\n", cfg.m5_15, cfg.spare);
1893 printf(" m5_90= %u icmi= %u\n", cfg.m5_90, cfg.icmi);
1894 printf(" m6_70= %u nscb= %u\n", cfg.m6_70, cfg.nscb);
1895 printf(" m7_40= %u ver= %u\n", cfg.m7_40, cfg.ver);
1896 printf(" m7_95= %u\n", cfg.m7_95);
1897 printf(" m10_2= %u\n", cfg.m10_2);
1898 printf(" m12_2= %u\n", cfg.m12_2);
1899
1900 printf("\n");
1901}
1902
1903void test_gsm48_mr_cfg_from_gsm0808_sc_cfg()
1904{
1905 printf("Testing gsm48_mr_cfg_from_gsm0808_sc_cfg():\n");
1906
1907 /* Only one codec per setting */
1908 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1909 (GSM0808_SC_CFG_DEFAULT_AMR_4_75);
1910 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1911 (GSM0808_SC_CFG_DEFAULT_AMR_5_15);
1912 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1913 (GSM0808_SC_CFG_DEFAULT_AMR_5_90);
1914 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1915 (GSM0808_SC_CFG_DEFAULT_AMR_6_70);
1916 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1917 (GSM0808_SC_CFG_DEFAULT_AMR_7_40);
1918 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1919 (GSM0808_SC_CFG_DEFAULT_AMR_7_95);
1920 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1921 (GSM0808_SC_CFG_DEFAULT_AMR_10_2);
1922 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1923 (GSM0808_SC_CFG_DEFAULT_AMR_12_2);
1924
1925 /* Combinations */
1926 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1927 (GSM0808_SC_CFG_DEFAULT_AMR_4_75 | GSM0808_SC_CFG_DEFAULT_AMR_6_70 |
1928 GSM0808_SC_CFG_DEFAULT_AMR_10_2);
1929 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1930 (GSM0808_SC_CFG_DEFAULT_AMR_10_2 | GSM0808_SC_CFG_DEFAULT_AMR_12_2 |
1931 GSM0808_SC_CFG_DEFAULT_AMR_7_40);
1932 test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
1933 (GSM0808_SC_CFG_DEFAULT_AMR_7_95 | GSM0808_SC_CFG_DEFAULT_AMR_12_2);
1934}
1935
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01001936int main(int argc, char **argv)
1937{
Max969fb2e2018-12-10 11:01:10 +01001938 void *ctx = talloc_named_const(NULL, 0, "gsm0808 test");
1939 msgb_talloc_ctx_init(ctx, 0);
1940 osmo_init_logging2(ctx, NULL);
1941
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01001942 printf("Testing generation of GSM0808 messages\n");
Philipp Maier4f4905f2018-11-30 13:36:12 +01001943 test_gsm0808_enc_cause();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01001944 test_create_layer3();
Philipp Maierfa896ab2017-03-27 16:55:32 +02001945 test_create_layer3_aoip();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01001946 test_create_reset();
Philipp Maier15596e22017-04-05 17:55:27 +02001947 test_create_reset_ack();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01001948 test_create_clear_command();
1949 test_create_clear_complete();
Philipp Maierb478dd32017-03-29 15:50:05 +02001950 test_create_cipher();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01001951 test_create_cipher_complete();
1952 test_create_cipher_reject();
Maxed651d22018-11-07 15:25:05 +01001953 test_create_cipher_reject_ext();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01001954 test_create_cm_u();
1955 test_create_sapi_reject();
Philipp Maierc6144a22017-03-29 17:53:43 +02001956 test_create_ass();
Max52074322018-11-30 10:44:07 +01001957 test_create_ass2();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01001958 test_create_ass_compl();
Philipp Maierfa896ab2017-03-27 16:55:32 +02001959 test_create_ass_compl_aoip();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01001960 test_create_ass_fail();
Philipp Maierfa896ab2017-03-27 16:55:32 +02001961 test_create_ass_fail_aoip();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01001962 test_create_clear_rqst();
Philipp Maier3d48ec02017-03-29 17:37:55 +02001963 test_create_paging();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01001964 test_create_dtap();
1965 test_prepend_dtap();
Max969fb2e2018-12-10 11:01:10 +01001966
Max47022152018-12-19 18:51:00 +01001967 test_enc_dec_lcls();
Max969fb2e2018-12-10 11:01:10 +01001968
Philipp Maier22401432017-03-24 17:59:26 +01001969 test_enc_dec_aoip_trasp_addr_v4();
1970 test_enc_dec_aoip_trasp_addr_v6();
Philipp Maier6f725d62017-03-24 18:03:17 +01001971 test_gsm0808_enc_dec_speech_codec();
Philipp Maier6f725d62017-03-24 18:03:17 +01001972 test_gsm0808_enc_dec_speech_codec_ext_with_cfg();
Philipp Maierbb839662017-06-01 17:11:19 +02001973 test_gsm0808_enc_dec_speech_codec_with_cfg();
Philipp Maier6f725d62017-03-24 18:03:17 +01001974 test_gsm0808_enc_dec_speech_codec_list();
Philipp Maierf6c369f2018-10-16 15:24:47 +02001975 test_gsm0808_enc_dec_empty_speech_codec_list();
Philipp Maiere0c65302017-03-28 17:05:40 +02001976 test_gsm0808_enc_dec_channel_type();
Philipp Maier14e76b92017-03-28 18:36:52 +02001977 test_gsm0808_enc_dec_encrypt_info();
Neels Hofmeyr250e7f72018-04-13 03:30:14 +02001978
Philipp Maier783047e2017-03-29 11:35:50 +02001979 test_gsm0808_enc_dec_cell_id_list_lac();
1980 test_gsm0808_enc_dec_cell_id_list_single_lac();
Stefan Sperlinge1a86742018-03-15 18:05:02 +01001981 test_gsm0808_enc_dec_cell_id_list_multi_lac();
Philipp Maier783047e2017-03-29 11:35:50 +02001982 test_gsm0808_enc_dec_cell_id_list_bss();
Stefan Sperling23381452018-03-15 19:38:15 +01001983 test_gsm0808_enc_dec_cell_id_list_multi_lai_and_lac();
Stefan Sperling9c62fc62018-03-16 10:23:34 +01001984 test_gsm0808_enc_dec_cell_id_list_multi_ci();
Stefan Sperlinged4327c2018-03-16 11:02:59 +01001985 test_gsm0808_enc_dec_cell_id_list_multi_lac_and_ci();
Stefan Sperling483f3862018-03-16 12:21:26 +01001986 test_gsm0808_enc_dec_cell_id_list_multi_global();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01001987
Neels Hofmeyr74663d92018-03-23 01:46:42 +01001988 test_cell_id_list_add();
1989
Neels Hofmeyr250e7f72018-04-13 03:30:14 +02001990 test_gsm0808_enc_dec_cell_id_lac();
1991 test_gsm0808_enc_dec_cell_id_bss();
1992 test_gsm0808_enc_dec_cell_id_no_cell();
1993 test_gsm0808_enc_dec_cell_id_lai_and_lac();
1994 test_gsm0808_enc_dec_cell_id_ci();
1995 test_gsm0808_enc_dec_cell_id_lac_and_ci();
1996 test_gsm0808_enc_dec_cell_id_global();
1997
Philipp Maier5f2eb152018-09-19 13:40:21 +02001998 test_gsm0808_sc_cfg_from_gsm48_mr_cfg();
Philipp Maier8515d032018-09-25 15:57:49 +02001999 test_gsm48_mr_cfg_from_gsm0808_sc_cfg();
Philipp Maier5f2eb152018-09-19 13:40:21 +02002000
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01002001 printf("Done\n");
2002 return EXIT_SUCCESS;
2003}