blob: 2d91b68f0ef0bd667930b41a28a7b19f7db53cdb [file] [log] [blame]
Holger Freytheraa0fb362008-12-28 21:55:40 +00001/* simple test for the gsm0408 formatting functions */
2/*
3 * (C) 2008 by Holger Hans Peter Freyther <zecke@selfish.org>
4 * All Rights Reserved
5 *
6 * This program is free software; you can redistribute it and/or modify
Harald Welte9af6ddf2011-01-01 15:25:50 +01007 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
Holger Freytheraa0fb362008-12-28 21:55:40 +00009 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010016 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Holger Freytheraa0fb362008-12-28 21:55:40 +000018 *
19 */
20
21#include <assert.h>
22#include <stdio.h>
23#include <stdlib.h>
24
Harald Welteafedeab2010-03-04 10:55:40 +010025#include <arpa/inet.h>
26
Holger Freytheraa0fb362008-12-28 21:55:40 +000027#include <openbsc/gsm_04_08.h>
Holger Hans Peter Freytherca114432014-02-08 15:20:48 +010028#include <openbsc/gsm_04_11.h>
Holger Hans Peter Freyther5d0e56f2009-08-20 08:41:24 +020029#include <openbsc/gsm_subscriber.h>
30#include <openbsc/debug.h>
Jacob Erlbeck4b903b42014-01-10 17:43:41 +010031#include <openbsc/arfcn_range_encode.h>
Max59a1bf32016-04-15 16:04:46 +020032#include <openbsc/system_information.h>
33#include <openbsc/abis_rsl.h>
34
Jacob Erlbeck4b903b42014-01-10 17:43:41 +010035#include <osmocom/core/application.h>
Max59a1bf32016-04-15 16:04:46 +020036#include <osmocom/gsm/sysinfo.h>
Holger Freytheraa0fb362008-12-28 21:55:40 +000037
38#define COMPARE(result, op, value) \
39 if (!((result) op (value))) {\
40 fprintf(stderr, "Compare failed. Was %x should be %x in %s:%d\n",result, value, __FILE__, __LINE__); \
41 exit(-1); \
42 }
Holger Hans Peter Freyther5d0e56f2009-08-20 08:41:24 +020043
44#define COMPARE_STR(result, value) \
45 if (strcmp(result, value) != 0) { \
46 fprintf(stderr, "Compare failed. Was %s should be %s in %s:%d\n",result, value, __FILE__, __LINE__); \
47 exit(-1); \
48 }
Holger Freytheraa0fb362008-12-28 21:55:40 +000049
Jacob Erlbeck9444d4f2014-01-13 14:43:40 +010050#define DBG(...)
51
52#define VERIFY(res, cmp, wanted) \
53 if (!(res cmp wanted)) { \
54 printf("ASSERT failed: %s:%d Wanted: %d %s %d\n", \
Holger Hans Peter Freytherdaaea0c2015-08-03 09:28:41 +020055 __FILE__, __LINE__, (int) res, # cmp, (int) wanted); \
Jacob Erlbeck9444d4f2014-01-13 14:43:40 +010056 }
57
58
59
Holger Freytheraa0fb362008-12-28 21:55:40 +000060/*
61 * Test Location Area Identifier formatting. Table 10.5.3 of 04.08
62 */
63static void test_location_area_identifier(void)
64{
65 struct gsm48_loc_area_id lai48;
66
67 printf("Testing test location area identifier\n");
68
69 /*
70 * Test the default/test setup. Coming from
71 * bsc_hack.c dumps
72 */
Harald Welteafedeab2010-03-04 10:55:40 +010073 gsm48_generate_lai(&lai48, 1, 1, 1);
Holger Freytheraa0fb362008-12-28 21:55:40 +000074 COMPARE(lai48.digits[0], ==, 0x00);
75 COMPARE(lai48.digits[1], ==, 0xF1);
76 COMPARE(lai48.digits[2], ==, 0x10);
77 COMPARE(lai48.lac, ==, htons(0x0001));
78
Harald Welteafedeab2010-03-04 10:55:40 +010079 gsm48_generate_lai(&lai48, 602, 1, 15);
Holger Freytheraa0fb362008-12-28 21:55:40 +000080 COMPARE(lai48.digits[0], ==, 0x06);
81 COMPARE(lai48.digits[1], ==, 0xF2);
82 COMPARE(lai48.digits[2], ==, 0x10);
83 COMPARE(lai48.lac, ==, htons(0x000f));
84}
85
Max59a1bf32016-04-15 16:04:46 +020086static inline void add_arfcn_b(struct osmo_earfcn_si2q *e, uint16_t earfcn,
87 uint8_t bw)
88{
89 int r = osmo_earfcn_add(e, earfcn, bw);
90 if (r)
91 printf("failed to add EARFCN %u: %s\n", earfcn, strerror(r));
92 else
93 printf("added EARFCN %u - ", earfcn);
94}
95
96static inline void gen(struct gsm_bts *bts)
97{
98 int r = gsm_generate_si(bts, SYSINFO_TYPE_2quater);
99 if (r > 0)
100 printf("generated SI2quater: [%d] %s\n", r,
101 osmo_hexdump(bts->si_buf[SYSINFO_TYPE_2quater], r));
102 else
103 printf("failed to generate SI2quater: %s\n", strerror(-r));
104}
105
Max26679e02016-04-20 15:57:13 +0200106static inline void test_si2q_u(void)
Max59a1bf32016-04-15 16:04:46 +0200107{
108 struct gsm_bts *bts;
109 struct gsm_network *network = gsm_network_init(1, 1, NULL);
Max26679e02016-04-20 15:57:13 +0200110 printf("Testing SYSINFO_TYPE_2quater UARFCN generation:\n");
111
112 if (!network)
113 exit(1);
114 bts = gsm_bts_alloc(network);
115
116 bts_uarfcn_add(bts, 1982, 13, 1);
117 gen(bts);
118
119 bts_uarfcn_add(bts, 1982, 44, 0);
120 gen(bts);
121
122 bts_uarfcn_add(bts, 1982, 61, 1);
123 gen(bts);
124
125 bts_uarfcn_add(bts, 1982, 89, 1);
126 gen(bts);
127
128 bts_uarfcn_add(bts, 1982, 113, 0);
129 gen(bts);
130
131 bts_uarfcn_add(bts, 1982, 123, 0);
132 gen(bts);
133
134 bts_uarfcn_add(bts, 1982, 56, 1);
135 gen(bts);
136
137 bts_uarfcn_add(bts, 1982, 72, 1);
138 gen(bts);
139
140 bts_uarfcn_add(bts, 1982, 223, 1);
141 gen(bts);
142
143 bts_uarfcn_add(bts, 1982, 14, 0);
144 gen(bts);
145
146 bts_uarfcn_add(bts, 1982, 88, 0);
147 gen(bts);
148}
149
150static inline void test_si2q_e(void)
151{
152 struct gsm_bts *bts;
153 struct gsm_network *network = gsm_network_init(1, 1, NULL);
154 printf("Testing SYSINFO_TYPE_2quater EARFCN generation:\n");
Max59a1bf32016-04-15 16:04:46 +0200155
156 if (!network)
157 exit(1);
158 bts = gsm_bts_alloc(network);
159
160 bts->si_common.si2quater_neigh_list.arfcn =
161 bts->si_common.data.earfcn_list;
162 bts->si_common.si2quater_neigh_list.meas_bw =
163 bts->si_common.data.meas_bw_list;
164 bts->si_common.si2quater_neigh_list.length = MAX_EARFCN_LIST;
165 bts->si_common.si2quater_neigh_list.thresh_hi = 5;
166
167 osmo_earfcn_init(&bts->si_common.si2quater_neigh_list);
168
169 add_arfcn_b(&bts->si_common.si2quater_neigh_list, 1917, 1);
170 gen(bts);
171
172 add_arfcn_b(&bts->si_common.si2quater_neigh_list, 1932,
173 OSMO_EARFCN_MEAS_INVALID);
174 gen(bts);
175
176 add_arfcn_b(&bts->si_common.si2quater_neigh_list, 1937, 2);
177 gen(bts);
178
179 add_arfcn_b(&bts->si_common.si2quater_neigh_list, 1945,
180 OSMO_EARFCN_MEAS_INVALID);
181 gen(bts);
182
183 add_arfcn_b(&bts->si_common.si2quater_neigh_list, 1965,
184 OSMO_EARFCN_MEAS_INVALID);
185 gen(bts);
186
187 add_arfcn_b(&bts->si_common.si2quater_neigh_list, 1967, 4);
188 gen(bts);
189
190 add_arfcn_b(&bts->si_common.si2quater_neigh_list, 1982, 3);
191 gen(bts);
192}
193
Holger Hans Peter Freyther5d0e56f2009-08-20 08:41:24 +0200194static void test_mi_functionality(void)
195{
196 const char *imsi_odd = "987654321098763";
197 const char *imsi_even = "9876543210987654";
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200198 const uint32_t tmsi = 0xfabeacd0;
199 uint8_t mi[128];
Holger Hans Peter Freyther5d0e56f2009-08-20 08:41:24 +0200200 unsigned int mi_len;
201 char mi_parsed[GSM48_MI_SIZE];
202
203 printf("Testing parsing and generating TMSI/IMSI\n");
204
205 /* tmsi code */
206 mi_len = gsm48_generate_mid_from_tmsi(mi, tmsi);
207 gsm48_mi_to_string(mi_parsed, sizeof(mi_parsed), mi + 2, mi_len - 2);
Harald Welte3ad03462016-03-17 14:41:26 +0100208 COMPARE((uint32_t)strtoul(mi_parsed, NULL, 10), ==, tmsi);
Holger Hans Peter Freyther5d0e56f2009-08-20 08:41:24 +0200209
210 /* imsi code */
211 mi_len = gsm48_generate_mid_from_imsi(mi, imsi_odd);
212 gsm48_mi_to_string(mi_parsed, sizeof(mi_parsed), mi + 2, mi_len -2);
Pablo Neira Ayusoc0d17f22011-05-07 12:12:48 +0200213 printf("hex: %s\n", osmo_hexdump(mi, mi_len));
Holger Hans Peter Freyther5d0e56f2009-08-20 08:41:24 +0200214 COMPARE_STR(mi_parsed, imsi_odd);
215
216 mi_len = gsm48_generate_mid_from_imsi(mi, imsi_even);
217 gsm48_mi_to_string(mi_parsed, sizeof(mi_parsed), mi + 2, mi_len -2);
Pablo Neira Ayusoc0d17f22011-05-07 12:12:48 +0200218 printf("hex: %s\n", osmo_hexdump(mi, mi_len));
Holger Hans Peter Freyther5d0e56f2009-08-20 08:41:24 +0200219 COMPARE_STR(mi_parsed, imsi_even);
220}
221
Jacob Erlbeck4b903b42014-01-10 17:43:41 +0100222struct {
223 int range;
224 int arfcns_num;
225 int arfcns[RANGE_ENC_MAX_ARFCNS];
226} arfcn_test_ranges[] = {
227 {ARFCN_RANGE_512, 12,
228 { 1, 12, 31, 51, 57, 91, 97, 98, 113, 117, 120, 125 }},
229 {ARFCN_RANGE_512, 17,
230 { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 }},
231 {ARFCN_RANGE_512, 18,
232 { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 }},
233 {ARFCN_RANGE_512, 18,
234 { 1, 17, 31, 45, 58, 79, 81, 97,
235 113, 127, 213, 277, 287, 311, 331, 391,
236 417, 511 }},
237 {ARFCN_RANGE_512, 6,
238 { 1, 17, 31, 45, 58, 79 }},
239 {ARFCN_RANGE_512, 6,
240 { 10, 17, 31, 45, 58, 79 }},
241 {ARFCN_RANGE_1024, 17,
242 { 0, 17, 31, 45, 58, 79, 81, 97,
243 113, 127, 213, 277, 287, 311, 331, 391,
244 1023 }},
245 {ARFCN_RANGE_1024, 16,
246 { 17, 31, 45, 58, 79, 81, 97, 113,
247 127, 213, 277, 287, 311, 331, 391, 1023 }},
248 {-1}
249};
250
251static int test_single_range_encoding(int range, const int *orig_arfcns,
252 int arfcns_num, int silent)
253{
254 int arfcns[RANGE_ENC_MAX_ARFCNS];
255 int w[RANGE_ENC_MAX_ARFCNS];
256 int f0_included = 0;
257 int rc, f0;
258 uint8_t chan_list[16] = {0};
259 struct gsm_sysinfo_freq dec_freq[1024] = {{0}};
260 int dec_arfcns[RANGE_ENC_MAX_ARFCNS] = {0};
261 int dec_arfcns_count = 0;
262 int arfcns_used = 0;
263 int i;
264
265 arfcns_used = arfcns_num;
266 memmove(arfcns, orig_arfcns, sizeof(arfcns));
267
Jacob Erlbeck45014a02014-01-14 10:42:58 +0100268 f0 = range == ARFCN_RANGE_1024 ? 0 : arfcns[0];
Jacob Erlbeck4b903b42014-01-10 17:43:41 +0100269 /*
270 * Manipulate the ARFCN list according to the rules in J4 depending
271 * on the selected range.
272 */
Jacob Erlbeck45014a02014-01-14 10:42:58 +0100273 arfcns_used = range_enc_filter_arfcns(arfcns, arfcns_used,
Jacob Erlbeck4b903b42014-01-10 17:43:41 +0100274 f0, &f0_included);
275
276 memset(w, 0, sizeof(w));
Max26679e02016-04-20 15:57:13 +0200277 range_enc_arfcns(range, arfcns, arfcns_used, w, 0);
Jacob Erlbeck4b903b42014-01-10 17:43:41 +0100278
279 if (!silent)
280 fprintf(stderr, "range=%d, arfcns_used=%d, f0=%d, f0_included=%d\n",
281 range, arfcns_used, f0, f0_included);
282
283 /* Select the range and the amount of bits needed */
284 switch (range) {
285 case ARFCN_RANGE_128:
Max26679e02016-04-20 15:57:13 +0200286 range_enc_range128(chan_list, f0, w);
Jacob Erlbeck4b903b42014-01-10 17:43:41 +0100287 break;
288 case ARFCN_RANGE_256:
Max26679e02016-04-20 15:57:13 +0200289 range_enc_range256(chan_list, f0, w);
Jacob Erlbeck4b903b42014-01-10 17:43:41 +0100290 break;
291 case ARFCN_RANGE_512:
Max26679e02016-04-20 15:57:13 +0200292 range_enc_range512(chan_list, f0, w);
Jacob Erlbeck4b903b42014-01-10 17:43:41 +0100293 break;
294 case ARFCN_RANGE_1024:
Max26679e02016-04-20 15:57:13 +0200295 range_enc_range1024(chan_list, f0, f0_included, w);
Jacob Erlbeck4b903b42014-01-10 17:43:41 +0100296 break;
297 default:
298 return 1;
299 };
Jacob Erlbeck4b903b42014-01-10 17:43:41 +0100300
301 if (!silent)
302 printf("chan_list = %s\n",
303 osmo_hexdump(chan_list, sizeof(chan_list)));
304
305 rc = gsm48_decode_freq_list(dec_freq, chan_list, sizeof(chan_list),
306 0xfe, 1);
307 if (rc != 0) {
308 printf("Cannot decode freq list, rc = %d\n", rc);
309 return 1;
310 }
311
312 for (i = 0; i < ARRAY_SIZE(dec_freq); i++) {
313 if (dec_freq[i].mask &&
314 dec_arfcns_count < ARRAY_SIZE(dec_arfcns))
315 dec_arfcns[dec_arfcns_count++] = i;
316 }
317
318 if (!silent) {
319 printf("Decoded freqs %d (expected %d)\n",
320 dec_arfcns_count, arfcns_num);
321 printf("Decoded: ");
322 for (i = 0; i < dec_arfcns_count; i++) {
323 printf("%d ", dec_arfcns[i]);
324 if (dec_arfcns[i] != orig_arfcns[i])
325 printf("(!= %d) ", orig_arfcns[i]);
326 }
327 printf("\n");
328 }
329
330 if (dec_arfcns_count != arfcns_num) {
331 printf("Wrong number of arfcns\n");
332 return 1;
333 }
334
335 if (memcmp(dec_arfcns, orig_arfcns, sizeof(dec_arfcns)) != 0) {
336 printf("Decoding error, got wrong freqs\n");
337 fprintf(stderr, " w = ");
338 for (i = 0; i < ARRAY_SIZE(w); i++)
339 fprintf(stderr, "%d ", w[i]);
340 fprintf(stderr, "\n");
341 return 1;
342 }
343
344 return 0;
345}
346
347static void test_random_range_encoding(int range, int max_arfcn_num)
348{
349 int arfcns_num = 0;
350 int test_idx;
351 int rc, max_count;
352 int num_tests = 1024;
353
354 printf("Random range test: range %d, max num ARFCNs %d\n",
355 range, max_arfcn_num);
356
357 srandom(1);
358
359 for (max_count = 1; max_count < max_arfcn_num; max_count++) {
360 for (test_idx = 0; test_idx < num_tests; test_idx++) {
361 int count;
362 int i;
363 int min_freq = 0;
364
365 int rnd_arfcns[RANGE_ENC_MAX_ARFCNS] = {0};
366 char rnd_arfcns_set[1024] = {0};
367
368 if (range < ARFCN_RANGE_1024)
369 min_freq = random() % (1023 - range);
370
371 for (count = max_count; count; ) {
372 int arfcn = min_freq + random() % (range + 1);
373 OSMO_ASSERT(arfcn < ARRAY_SIZE(rnd_arfcns_set));
374
375 if (!rnd_arfcns_set[arfcn]) {
376 rnd_arfcns_set[arfcn] = 1;
377 count -= 1;
378 }
379 }
380
381 arfcns_num = 0;
382 for (i = 0; i < ARRAY_SIZE(rnd_arfcns_set); i++)
383 if (rnd_arfcns_set[i])
384 rnd_arfcns[arfcns_num++] = i;
385
386 rc = test_single_range_encoding(range, rnd_arfcns,
387 arfcns_num, 1);
388 if (rc != 0) {
389 printf("Failed on test %d, range %d, num ARFCNs %d\n",
390 test_idx, range, max_count);
391 test_single_range_encoding(range, rnd_arfcns,
392 arfcns_num, 0);
393 return;
394 }
395 }
396 }
397}
398
399static void test_range_encoding()
400{
401 int *arfcns;
402 int arfcns_num = 0;
403 int test_idx;
404 int range;
405
406 for (test_idx = 0; arfcn_test_ranges[test_idx].arfcns_num > 0; test_idx++)
407 {
408 arfcns_num = arfcn_test_ranges[test_idx].arfcns_num;
409 arfcns = &arfcn_test_ranges[test_idx].arfcns[0];
410 range = arfcn_test_ranges[test_idx].range;
411
412 printf("Range test %d: range %d, num ARFCNs %d\n",
413 test_idx, range, arfcns_num);
414
415 test_single_range_encoding(range, arfcns, arfcns_num, 0);
416 }
417
418 test_random_range_encoding(ARFCN_RANGE_128, 29);
419 test_random_range_encoding(ARFCN_RANGE_256, 22);
420 test_random_range_encoding(ARFCN_RANGE_512, 18);
421 test_random_range_encoding(ARFCN_RANGE_1024, 16);
422}
423
Jacob Erlbeck9444d4f2014-01-13 14:43:40 +0100424static int freqs1[] = {
425 12, 70, 121, 190, 250, 320, 401, 475, 520, 574, 634, 700, 764, 830, 905, 980
426};
427
428static int freqs2[] = {
429 402, 460, 1, 67, 131, 197, 272, 347,
430};
431
432static int freqs3[] = {
433 68, 128, 198, 279, 353, 398, 452,
434
435};
436
437static int w_out[] = {
438 122, 2, 69, 204, 75, 66, 60, 70, 83, 3, 24, 67, 54, 64, 70, 9,
439};
440
441static int range128[] = {
442 1, 1 + 127,
443};
444
445static int range256[] = {
446 1, 1 + 128,
447};
448
449static int range512[] = {
450 1, 1+ 511,
451};
452
453
454static void test_arfcn_filter()
455{
456 int arfcns[50], i, res, f0_included;
457 for (i = 0; i < ARRAY_SIZE(arfcns); ++i)
458 arfcns[i] = (i + 1) * 2;
459
460 /* check that the arfcn is taken out. f0_included is only set for Range1024 */
461 f0_included = 24;
Jacob Erlbeck45014a02014-01-14 10:42:58 +0100462 res = range_enc_filter_arfcns(arfcns, ARRAY_SIZE(arfcns),
Jacob Erlbeck9444d4f2014-01-13 14:43:40 +0100463 arfcns[0], &f0_included);
464 VERIFY(res, ==, ARRAY_SIZE(arfcns) - 1);
465 VERIFY(f0_included, ==, 1);
466 for (i = 0; i < res; ++i)
Jacob Erlbeck45014a02014-01-14 10:42:58 +0100467 VERIFY(arfcns[i], ==, ((i+2) * 2) - (2+1));
Jacob Erlbeck9444d4f2014-01-13 14:43:40 +0100468
Jacob Erlbeck45014a02014-01-14 10:42:58 +0100469 /* check with range1024, ARFCN 0 is included */
470 for (i = 0; i < ARRAY_SIZE(arfcns); ++i)
471 arfcns[i] = i * 2;
472 res = range_enc_filter_arfcns(arfcns, ARRAY_SIZE(arfcns),
473 0, &f0_included);
474 VERIFY(res, ==, ARRAY_SIZE(arfcns) - 1);
475 VERIFY(f0_included, ==, 1);
476 for (i = 0; i < res; ++i)
477 VERIFY(arfcns[i], ==, (i + 1) * 2 - 1);
478
479 /* check with range1024, ARFCN 0 not included */
Jacob Erlbeck9444d4f2014-01-13 14:43:40 +0100480 for (i = 0; i < ARRAY_SIZE(arfcns); ++i)
481 arfcns[i] = (i + 1) * 2;
Jacob Erlbeck45014a02014-01-14 10:42:58 +0100482 res = range_enc_filter_arfcns(arfcns, ARRAY_SIZE(arfcns),
483 0, &f0_included);
Jacob Erlbeck9444d4f2014-01-13 14:43:40 +0100484 VERIFY(res, ==, ARRAY_SIZE(arfcns));
485 VERIFY(f0_included, ==, 0);
486 for (i = 0; i < res; ++i)
487 VERIFY(arfcns[i], ==, ((i + 1) * 2) - 1);
488}
489
490static void test_print_encoding()
491{
492 int rc;
493 int w[17];
494 uint8_t chan_list[16];
495 memset(chan_list, 0x23, sizeof(chan_list));
496
497 for (rc = 0; rc < ARRAY_SIZE(w); ++rc)
498 switch (rc % 3) {
499 case 0:
500 w[rc] = 0xAAAA;
501 break;
502 case 1:
503 w[rc] = 0x5555;
504 break;
505 case 2:
506 w[rc] = 0x9696;
507 break;
508 }
509
Max26679e02016-04-20 15:57:13 +0200510 range_enc_range512(chan_list, (1 << 9) | 0x96, w);
Jacob Erlbeck9444d4f2014-01-13 14:43:40 +0100511
512 printf("Range512: %s\n", osmo_hexdump(chan_list, ARRAY_SIZE(chan_list)));
513}
514
515static void test_si_range_helpers()
516{
517 int ws[(sizeof(freqs1)/sizeof(freqs1[0]))];
518 int i, f0 = 0xFFFFFF;
519
520 memset(&ws[0], 0x23, sizeof(ws));
521
522 i = range_enc_find_index(1023, freqs1, ARRAY_SIZE(freqs1));
Jacob Erlbeck1dc022c2014-01-17 09:22:57 +0100523 printf("Element is: %d => freqs[i] = %d\n", i, i >= 0 ? freqs1[i] : -1);
Jacob Erlbeck9444d4f2014-01-13 14:43:40 +0100524 VERIFY(i, ==, 2);
525
526 i = range_enc_find_index(511, freqs2, ARRAY_SIZE(freqs2));
Jacob Erlbeck1dc022c2014-01-17 09:22:57 +0100527 printf("Element is: %d => freqs[i] = %d\n", i, i >= 0 ? freqs2[i] : -1);
Jacob Erlbeck9444d4f2014-01-13 14:43:40 +0100528 VERIFY(i, ==, 2);
529
530 i = range_enc_find_index(511, freqs3, ARRAY_SIZE(freqs3));
Jacob Erlbeck1dc022c2014-01-17 09:22:57 +0100531 printf("Element is: %d => freqs[i] = %d\n", i, i >= 0 ? freqs3[i] : -1);
Jacob Erlbeck9444d4f2014-01-13 14:43:40 +0100532 VERIFY(i, ==, 0);
533
Max26679e02016-04-20 15:57:13 +0200534 range_enc_arfcns(1023, freqs1, ARRAY_SIZE(freqs1), ws, 0);
Jacob Erlbeck9444d4f2014-01-13 14:43:40 +0100535
536 for (i = 0; i < sizeof(freqs1)/sizeof(freqs1[0]); ++i) {
537 printf("w[%d]=%d\n", i, ws[i]);
538 VERIFY(ws[i], ==, w_out[i]);
539 }
540
541 i = range_enc_determine_range(range128, ARRAY_SIZE(range128), &f0);
542 VERIFY(i, ==, ARFCN_RANGE_128);
543 VERIFY(f0, ==, 1);
544
545 i = range_enc_determine_range(range256, ARRAY_SIZE(range256), &f0);
546 VERIFY(i, ==, ARFCN_RANGE_256);
547 VERIFY(f0, ==, 1);
548
549 i = range_enc_determine_range(range512, ARRAY_SIZE(range512), &f0);
550 VERIFY(i, ==, ARFCN_RANGE_512);
551 VERIFY(f0, ==, 1);
552}
553
Holger Hans Peter Freytherca114432014-02-08 15:20:48 +0100554static void test_gsm411_rp_ref_wrap(void)
555{
556 struct gsm_subscriber_connection conn;
557 int res;
558
559 printf("testing RP-Reference wrap\n");
560
561 memset(&conn, 0, sizeof(conn));
562 conn.next_rp_ref = 255;
563
564 res = sms_next_rp_msg_ref(&conn);
565 printf("Allocated reference: %d\n", res);
566 OSMO_ASSERT(res == 255);
567
568 res = sms_next_rp_msg_ref(&conn);
569 printf("Allocated reference: %d\n", res);
570 OSMO_ASSERT(res == 0);
571
572 res = sms_next_rp_msg_ref(&conn);
573 printf("Allocated reference: %d\n", res);
574 OSMO_ASSERT(res == 1);
575}
576
Holger Hans Peter Freytheradb6e1c2010-09-18 06:44:24 +0800577int main(int argc, char **argv)
Holger Freytheraa0fb362008-12-28 21:55:40 +0000578{
Jacob Erlbeck4b903b42014-01-10 17:43:41 +0100579 osmo_init_logging(&log_info);
580 log_set_log_level(osmo_stderr_target, LOGL_INFO);
581
Holger Hans Peter Freyther5d0e56f2009-08-20 08:41:24 +0200582 test_location_area_identifier();
583 test_mi_functionality();
Jacob Erlbeck9444d4f2014-01-13 14:43:40 +0100584
585 test_si_range_helpers();
586 test_arfcn_filter();
587 test_print_encoding();
Jacob Erlbeck4b903b42014-01-10 17:43:41 +0100588 test_range_encoding();
Holger Hans Peter Freytherca114432014-02-08 15:20:48 +0100589 test_gsm411_rp_ref_wrap();
Harald Welteafedeab2010-03-04 10:55:40 +0100590
Max26679e02016-04-20 15:57:13 +0200591 test_si2q_e();
592 test_si2q_u();
Holger Hans Peter Freyther300457b2012-01-06 15:03:28 +0100593 printf("Done.\n");
594 return EXIT_SUCCESS;
Holger Freytheraa0fb362008-12-28 21:55:40 +0000595}