blob: 92626670c4971afe6335a04840c4a262847bf4c8 [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
Maxaafff962016-04-20 15:57:14 +0200106static inline void _bts_uarfcn_add(struct gsm_bts *bts, uint16_t arfcn,
107 uint16_t scramble, bool diversity)
108{
109 int r = bts_uarfcn_add(bts, arfcn, scramble, diversity);
110 if (r < 0)
111 printf("failed to add UARFCN to SI2quater: %s\n", strerror(-r));
112 else
113 gen(bts);
114}
115
Max26679e02016-04-20 15:57:13 +0200116static inline void test_si2q_u(void)
Max59a1bf32016-04-15 16:04:46 +0200117{
118 struct gsm_bts *bts;
119 struct gsm_network *network = gsm_network_init(1, 1, NULL);
Max26679e02016-04-20 15:57:13 +0200120 printf("Testing SYSINFO_TYPE_2quater UARFCN generation:\n");
121
122 if (!network)
123 exit(1);
124 bts = gsm_bts_alloc(network);
125
Maxaafff962016-04-20 15:57:14 +0200126 _bts_uarfcn_add(bts, 1982, 13, 1);
127 _bts_uarfcn_add(bts, 1982, 44, 0);
128 _bts_uarfcn_add(bts, 1982, 61, 1);
129 _bts_uarfcn_add(bts, 1982, 89, 1);
130 _bts_uarfcn_add(bts, 1982, 113, 0);
131 _bts_uarfcn_add(bts, 1982, 123, 0);
132 _bts_uarfcn_add(bts, 1982, 56, 1);
133 _bts_uarfcn_add(bts, 1982, 72, 1);
134 _bts_uarfcn_add(bts, 1982, 223, 1);
135 _bts_uarfcn_add(bts, 1982, 14, 0);
136 _bts_uarfcn_add(bts, 1982, 88, 0);
Max26679e02016-04-20 15:57:13 +0200137 gen(bts);
138}
139
140static inline void test_si2q_e(void)
141{
142 struct gsm_bts *bts;
143 struct gsm_network *network = gsm_network_init(1, 1, NULL);
144 printf("Testing SYSINFO_TYPE_2quater EARFCN generation:\n");
Max59a1bf32016-04-15 16:04:46 +0200145
146 if (!network)
147 exit(1);
148 bts = gsm_bts_alloc(network);
149
150 bts->si_common.si2quater_neigh_list.arfcn =
151 bts->si_common.data.earfcn_list;
152 bts->si_common.si2quater_neigh_list.meas_bw =
153 bts->si_common.data.meas_bw_list;
154 bts->si_common.si2quater_neigh_list.length = MAX_EARFCN_LIST;
155 bts->si_common.si2quater_neigh_list.thresh_hi = 5;
156
157 osmo_earfcn_init(&bts->si_common.si2quater_neigh_list);
158
159 add_arfcn_b(&bts->si_common.si2quater_neigh_list, 1917, 1);
160 gen(bts);
161
162 add_arfcn_b(&bts->si_common.si2quater_neigh_list, 1932,
163 OSMO_EARFCN_MEAS_INVALID);
164 gen(bts);
165
166 add_arfcn_b(&bts->si_common.si2quater_neigh_list, 1937, 2);
167 gen(bts);
168
169 add_arfcn_b(&bts->si_common.si2quater_neigh_list, 1945,
170 OSMO_EARFCN_MEAS_INVALID);
171 gen(bts);
172
173 add_arfcn_b(&bts->si_common.si2quater_neigh_list, 1965,
174 OSMO_EARFCN_MEAS_INVALID);
175 gen(bts);
176
177 add_arfcn_b(&bts->si_common.si2quater_neigh_list, 1967, 4);
178 gen(bts);
179
180 add_arfcn_b(&bts->si_common.si2quater_neigh_list, 1982, 3);
181 gen(bts);
182}
183
Holger Hans Peter Freyther5d0e56f2009-08-20 08:41:24 +0200184static void test_mi_functionality(void)
185{
186 const char *imsi_odd = "987654321098763";
187 const char *imsi_even = "9876543210987654";
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200188 const uint32_t tmsi = 0xfabeacd0;
189 uint8_t mi[128];
Holger Hans Peter Freyther5d0e56f2009-08-20 08:41:24 +0200190 unsigned int mi_len;
191 char mi_parsed[GSM48_MI_SIZE];
192
193 printf("Testing parsing and generating TMSI/IMSI\n");
194
195 /* tmsi code */
196 mi_len = gsm48_generate_mid_from_tmsi(mi, tmsi);
197 gsm48_mi_to_string(mi_parsed, sizeof(mi_parsed), mi + 2, mi_len - 2);
Harald Welte3ad03462016-03-17 14:41:26 +0100198 COMPARE((uint32_t)strtoul(mi_parsed, NULL, 10), ==, tmsi);
Holger Hans Peter Freyther5d0e56f2009-08-20 08:41:24 +0200199
200 /* imsi code */
201 mi_len = gsm48_generate_mid_from_imsi(mi, imsi_odd);
202 gsm48_mi_to_string(mi_parsed, sizeof(mi_parsed), mi + 2, mi_len -2);
Pablo Neira Ayusoc0d17f22011-05-07 12:12:48 +0200203 printf("hex: %s\n", osmo_hexdump(mi, mi_len));
Holger Hans Peter Freyther5d0e56f2009-08-20 08:41:24 +0200204 COMPARE_STR(mi_parsed, imsi_odd);
205
206 mi_len = gsm48_generate_mid_from_imsi(mi, imsi_even);
207 gsm48_mi_to_string(mi_parsed, sizeof(mi_parsed), mi + 2, mi_len -2);
Pablo Neira Ayusoc0d17f22011-05-07 12:12:48 +0200208 printf("hex: %s\n", osmo_hexdump(mi, mi_len));
Holger Hans Peter Freyther5d0e56f2009-08-20 08:41:24 +0200209 COMPARE_STR(mi_parsed, imsi_even);
210}
211
Jacob Erlbeck4b903b42014-01-10 17:43:41 +0100212struct {
213 int range;
214 int arfcns_num;
215 int arfcns[RANGE_ENC_MAX_ARFCNS];
216} arfcn_test_ranges[] = {
217 {ARFCN_RANGE_512, 12,
218 { 1, 12, 31, 51, 57, 91, 97, 98, 113, 117, 120, 125 }},
219 {ARFCN_RANGE_512, 17,
220 { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 }},
221 {ARFCN_RANGE_512, 18,
222 { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 }},
223 {ARFCN_RANGE_512, 18,
224 { 1, 17, 31, 45, 58, 79, 81, 97,
225 113, 127, 213, 277, 287, 311, 331, 391,
226 417, 511 }},
227 {ARFCN_RANGE_512, 6,
228 { 1, 17, 31, 45, 58, 79 }},
229 {ARFCN_RANGE_512, 6,
230 { 10, 17, 31, 45, 58, 79 }},
231 {ARFCN_RANGE_1024, 17,
232 { 0, 17, 31, 45, 58, 79, 81, 97,
233 113, 127, 213, 277, 287, 311, 331, 391,
234 1023 }},
235 {ARFCN_RANGE_1024, 16,
236 { 17, 31, 45, 58, 79, 81, 97, 113,
237 127, 213, 277, 287, 311, 331, 391, 1023 }},
238 {-1}
239};
240
241static int test_single_range_encoding(int range, const int *orig_arfcns,
242 int arfcns_num, int silent)
243{
244 int arfcns[RANGE_ENC_MAX_ARFCNS];
245 int w[RANGE_ENC_MAX_ARFCNS];
246 int f0_included = 0;
247 int rc, f0;
248 uint8_t chan_list[16] = {0};
249 struct gsm_sysinfo_freq dec_freq[1024] = {{0}};
250 int dec_arfcns[RANGE_ENC_MAX_ARFCNS] = {0};
251 int dec_arfcns_count = 0;
252 int arfcns_used = 0;
253 int i;
254
255 arfcns_used = arfcns_num;
256 memmove(arfcns, orig_arfcns, sizeof(arfcns));
257
Jacob Erlbeck45014a02014-01-14 10:42:58 +0100258 f0 = range == ARFCN_RANGE_1024 ? 0 : arfcns[0];
Jacob Erlbeck4b903b42014-01-10 17:43:41 +0100259 /*
260 * Manipulate the ARFCN list according to the rules in J4 depending
261 * on the selected range.
262 */
Jacob Erlbeck45014a02014-01-14 10:42:58 +0100263 arfcns_used = range_enc_filter_arfcns(arfcns, arfcns_used,
Jacob Erlbeck4b903b42014-01-10 17:43:41 +0100264 f0, &f0_included);
265
266 memset(w, 0, sizeof(w));
Max26679e02016-04-20 15:57:13 +0200267 range_enc_arfcns(range, arfcns, arfcns_used, w, 0);
Jacob Erlbeck4b903b42014-01-10 17:43:41 +0100268
269 if (!silent)
270 fprintf(stderr, "range=%d, arfcns_used=%d, f0=%d, f0_included=%d\n",
271 range, arfcns_used, f0, f0_included);
272
273 /* Select the range and the amount of bits needed */
274 switch (range) {
275 case ARFCN_RANGE_128:
Max26679e02016-04-20 15:57:13 +0200276 range_enc_range128(chan_list, f0, w);
Jacob Erlbeck4b903b42014-01-10 17:43:41 +0100277 break;
278 case ARFCN_RANGE_256:
Max26679e02016-04-20 15:57:13 +0200279 range_enc_range256(chan_list, f0, w);
Jacob Erlbeck4b903b42014-01-10 17:43:41 +0100280 break;
281 case ARFCN_RANGE_512:
Max26679e02016-04-20 15:57:13 +0200282 range_enc_range512(chan_list, f0, w);
Jacob Erlbeck4b903b42014-01-10 17:43:41 +0100283 break;
284 case ARFCN_RANGE_1024:
Max26679e02016-04-20 15:57:13 +0200285 range_enc_range1024(chan_list, f0, f0_included, w);
Jacob Erlbeck4b903b42014-01-10 17:43:41 +0100286 break;
287 default:
288 return 1;
289 };
Jacob Erlbeck4b903b42014-01-10 17:43:41 +0100290
291 if (!silent)
292 printf("chan_list = %s\n",
293 osmo_hexdump(chan_list, sizeof(chan_list)));
294
295 rc = gsm48_decode_freq_list(dec_freq, chan_list, sizeof(chan_list),
296 0xfe, 1);
297 if (rc != 0) {
298 printf("Cannot decode freq list, rc = %d\n", rc);
299 return 1;
300 }
301
302 for (i = 0; i < ARRAY_SIZE(dec_freq); i++) {
303 if (dec_freq[i].mask &&
304 dec_arfcns_count < ARRAY_SIZE(dec_arfcns))
305 dec_arfcns[dec_arfcns_count++] = i;
306 }
307
308 if (!silent) {
309 printf("Decoded freqs %d (expected %d)\n",
310 dec_arfcns_count, arfcns_num);
311 printf("Decoded: ");
312 for (i = 0; i < dec_arfcns_count; i++) {
313 printf("%d ", dec_arfcns[i]);
314 if (dec_arfcns[i] != orig_arfcns[i])
315 printf("(!= %d) ", orig_arfcns[i]);
316 }
317 printf("\n");
318 }
319
320 if (dec_arfcns_count != arfcns_num) {
321 printf("Wrong number of arfcns\n");
322 return 1;
323 }
324
325 if (memcmp(dec_arfcns, orig_arfcns, sizeof(dec_arfcns)) != 0) {
326 printf("Decoding error, got wrong freqs\n");
327 fprintf(stderr, " w = ");
328 for (i = 0; i < ARRAY_SIZE(w); i++)
329 fprintf(stderr, "%d ", w[i]);
330 fprintf(stderr, "\n");
331 return 1;
332 }
333
334 return 0;
335}
336
337static void test_random_range_encoding(int range, int max_arfcn_num)
338{
339 int arfcns_num = 0;
340 int test_idx;
341 int rc, max_count;
342 int num_tests = 1024;
343
344 printf("Random range test: range %d, max num ARFCNs %d\n",
345 range, max_arfcn_num);
346
347 srandom(1);
348
349 for (max_count = 1; max_count < max_arfcn_num; max_count++) {
350 for (test_idx = 0; test_idx < num_tests; test_idx++) {
351 int count;
352 int i;
353 int min_freq = 0;
354
355 int rnd_arfcns[RANGE_ENC_MAX_ARFCNS] = {0};
356 char rnd_arfcns_set[1024] = {0};
357
358 if (range < ARFCN_RANGE_1024)
359 min_freq = random() % (1023 - range);
360
361 for (count = max_count; count; ) {
362 int arfcn = min_freq + random() % (range + 1);
363 OSMO_ASSERT(arfcn < ARRAY_SIZE(rnd_arfcns_set));
364
365 if (!rnd_arfcns_set[arfcn]) {
366 rnd_arfcns_set[arfcn] = 1;
367 count -= 1;
368 }
369 }
370
371 arfcns_num = 0;
372 for (i = 0; i < ARRAY_SIZE(rnd_arfcns_set); i++)
373 if (rnd_arfcns_set[i])
374 rnd_arfcns[arfcns_num++] = i;
375
376 rc = test_single_range_encoding(range, rnd_arfcns,
377 arfcns_num, 1);
378 if (rc != 0) {
379 printf("Failed on test %d, range %d, num ARFCNs %d\n",
380 test_idx, range, max_count);
381 test_single_range_encoding(range, rnd_arfcns,
382 arfcns_num, 0);
383 return;
384 }
385 }
386 }
387}
388
389static void test_range_encoding()
390{
391 int *arfcns;
392 int arfcns_num = 0;
393 int test_idx;
394 int range;
395
396 for (test_idx = 0; arfcn_test_ranges[test_idx].arfcns_num > 0; test_idx++)
397 {
398 arfcns_num = arfcn_test_ranges[test_idx].arfcns_num;
399 arfcns = &arfcn_test_ranges[test_idx].arfcns[0];
400 range = arfcn_test_ranges[test_idx].range;
401
402 printf("Range test %d: range %d, num ARFCNs %d\n",
403 test_idx, range, arfcns_num);
404
405 test_single_range_encoding(range, arfcns, arfcns_num, 0);
406 }
407
408 test_random_range_encoding(ARFCN_RANGE_128, 29);
409 test_random_range_encoding(ARFCN_RANGE_256, 22);
410 test_random_range_encoding(ARFCN_RANGE_512, 18);
411 test_random_range_encoding(ARFCN_RANGE_1024, 16);
412}
413
Jacob Erlbeck9444d4f2014-01-13 14:43:40 +0100414static int freqs1[] = {
415 12, 70, 121, 190, 250, 320, 401, 475, 520, 574, 634, 700, 764, 830, 905, 980
416};
417
418static int freqs2[] = {
419 402, 460, 1, 67, 131, 197, 272, 347,
420};
421
422static int freqs3[] = {
423 68, 128, 198, 279, 353, 398, 452,
424
425};
426
427static int w_out[] = {
428 122, 2, 69, 204, 75, 66, 60, 70, 83, 3, 24, 67, 54, 64, 70, 9,
429};
430
431static int range128[] = {
432 1, 1 + 127,
433};
434
435static int range256[] = {
436 1, 1 + 128,
437};
438
439static int range512[] = {
440 1, 1+ 511,
441};
442
443
444static void test_arfcn_filter()
445{
446 int arfcns[50], i, res, f0_included;
447 for (i = 0; i < ARRAY_SIZE(arfcns); ++i)
448 arfcns[i] = (i + 1) * 2;
449
450 /* check that the arfcn is taken out. f0_included is only set for Range1024 */
451 f0_included = 24;
Jacob Erlbeck45014a02014-01-14 10:42:58 +0100452 res = range_enc_filter_arfcns(arfcns, ARRAY_SIZE(arfcns),
Jacob Erlbeck9444d4f2014-01-13 14:43:40 +0100453 arfcns[0], &f0_included);
454 VERIFY(res, ==, ARRAY_SIZE(arfcns) - 1);
455 VERIFY(f0_included, ==, 1);
456 for (i = 0; i < res; ++i)
Jacob Erlbeck45014a02014-01-14 10:42:58 +0100457 VERIFY(arfcns[i], ==, ((i+2) * 2) - (2+1));
Jacob Erlbeck9444d4f2014-01-13 14:43:40 +0100458
Jacob Erlbeck45014a02014-01-14 10:42:58 +0100459 /* check with range1024, ARFCN 0 is included */
460 for (i = 0; i < ARRAY_SIZE(arfcns); ++i)
461 arfcns[i] = i * 2;
462 res = range_enc_filter_arfcns(arfcns, ARRAY_SIZE(arfcns),
463 0, &f0_included);
464 VERIFY(res, ==, ARRAY_SIZE(arfcns) - 1);
465 VERIFY(f0_included, ==, 1);
466 for (i = 0; i < res; ++i)
467 VERIFY(arfcns[i], ==, (i + 1) * 2 - 1);
468
469 /* check with range1024, ARFCN 0 not included */
Jacob Erlbeck9444d4f2014-01-13 14:43:40 +0100470 for (i = 0; i < ARRAY_SIZE(arfcns); ++i)
471 arfcns[i] = (i + 1) * 2;
Jacob Erlbeck45014a02014-01-14 10:42:58 +0100472 res = range_enc_filter_arfcns(arfcns, ARRAY_SIZE(arfcns),
473 0, &f0_included);
Jacob Erlbeck9444d4f2014-01-13 14:43:40 +0100474 VERIFY(res, ==, ARRAY_SIZE(arfcns));
475 VERIFY(f0_included, ==, 0);
476 for (i = 0; i < res; ++i)
477 VERIFY(arfcns[i], ==, ((i + 1) * 2) - 1);
478}
479
480static void test_print_encoding()
481{
482 int rc;
483 int w[17];
484 uint8_t chan_list[16];
485 memset(chan_list, 0x23, sizeof(chan_list));
486
487 for (rc = 0; rc < ARRAY_SIZE(w); ++rc)
488 switch (rc % 3) {
489 case 0:
490 w[rc] = 0xAAAA;
491 break;
492 case 1:
493 w[rc] = 0x5555;
494 break;
495 case 2:
496 w[rc] = 0x9696;
497 break;
498 }
499
Max26679e02016-04-20 15:57:13 +0200500 range_enc_range512(chan_list, (1 << 9) | 0x96, w);
Jacob Erlbeck9444d4f2014-01-13 14:43:40 +0100501
502 printf("Range512: %s\n", osmo_hexdump(chan_list, ARRAY_SIZE(chan_list)));
503}
504
505static void test_si_range_helpers()
506{
507 int ws[(sizeof(freqs1)/sizeof(freqs1[0]))];
508 int i, f0 = 0xFFFFFF;
509
510 memset(&ws[0], 0x23, sizeof(ws));
511
512 i = range_enc_find_index(1023, freqs1, ARRAY_SIZE(freqs1));
Jacob Erlbeck1dc022c2014-01-17 09:22:57 +0100513 printf("Element is: %d => freqs[i] = %d\n", i, i >= 0 ? freqs1[i] : -1);
Jacob Erlbeck9444d4f2014-01-13 14:43:40 +0100514 VERIFY(i, ==, 2);
515
516 i = range_enc_find_index(511, freqs2, ARRAY_SIZE(freqs2));
Jacob Erlbeck1dc022c2014-01-17 09:22:57 +0100517 printf("Element is: %d => freqs[i] = %d\n", i, i >= 0 ? freqs2[i] : -1);
Jacob Erlbeck9444d4f2014-01-13 14:43:40 +0100518 VERIFY(i, ==, 2);
519
520 i = range_enc_find_index(511, freqs3, ARRAY_SIZE(freqs3));
Jacob Erlbeck1dc022c2014-01-17 09:22:57 +0100521 printf("Element is: %d => freqs[i] = %d\n", i, i >= 0 ? freqs3[i] : -1);
Jacob Erlbeck9444d4f2014-01-13 14:43:40 +0100522 VERIFY(i, ==, 0);
523
Max26679e02016-04-20 15:57:13 +0200524 range_enc_arfcns(1023, freqs1, ARRAY_SIZE(freqs1), ws, 0);
Jacob Erlbeck9444d4f2014-01-13 14:43:40 +0100525
526 for (i = 0; i < sizeof(freqs1)/sizeof(freqs1[0]); ++i) {
527 printf("w[%d]=%d\n", i, ws[i]);
528 VERIFY(ws[i], ==, w_out[i]);
529 }
530
531 i = range_enc_determine_range(range128, ARRAY_SIZE(range128), &f0);
532 VERIFY(i, ==, ARFCN_RANGE_128);
533 VERIFY(f0, ==, 1);
534
535 i = range_enc_determine_range(range256, ARRAY_SIZE(range256), &f0);
536 VERIFY(i, ==, ARFCN_RANGE_256);
537 VERIFY(f0, ==, 1);
538
539 i = range_enc_determine_range(range512, ARRAY_SIZE(range512), &f0);
540 VERIFY(i, ==, ARFCN_RANGE_512);
541 VERIFY(f0, ==, 1);
542}
543
Holger Hans Peter Freytherca114432014-02-08 15:20:48 +0100544static void test_gsm411_rp_ref_wrap(void)
545{
546 struct gsm_subscriber_connection conn;
547 int res;
548
549 printf("testing RP-Reference wrap\n");
550
551 memset(&conn, 0, sizeof(conn));
552 conn.next_rp_ref = 255;
553
554 res = sms_next_rp_msg_ref(&conn);
555 printf("Allocated reference: %d\n", res);
556 OSMO_ASSERT(res == 255);
557
558 res = sms_next_rp_msg_ref(&conn);
559 printf("Allocated reference: %d\n", res);
560 OSMO_ASSERT(res == 0);
561
562 res = sms_next_rp_msg_ref(&conn);
563 printf("Allocated reference: %d\n", res);
564 OSMO_ASSERT(res == 1);
565}
566
Holger Hans Peter Freytheradb6e1c2010-09-18 06:44:24 +0800567int main(int argc, char **argv)
Holger Freytheraa0fb362008-12-28 21:55:40 +0000568{
Jacob Erlbeck4b903b42014-01-10 17:43:41 +0100569 osmo_init_logging(&log_info);
570 log_set_log_level(osmo_stderr_target, LOGL_INFO);
571
Holger Hans Peter Freyther5d0e56f2009-08-20 08:41:24 +0200572 test_location_area_identifier();
573 test_mi_functionality();
Jacob Erlbeck9444d4f2014-01-13 14:43:40 +0100574
575 test_si_range_helpers();
576 test_arfcn_filter();
577 test_print_encoding();
Jacob Erlbeck4b903b42014-01-10 17:43:41 +0100578 test_range_encoding();
Holger Hans Peter Freytherca114432014-02-08 15:20:48 +0100579 test_gsm411_rp_ref_wrap();
Harald Welteafedeab2010-03-04 10:55:40 +0100580
Max26679e02016-04-20 15:57:13 +0200581 test_si2q_e();
582 test_si2q_u();
Holger Hans Peter Freyther300457b2012-01-06 15:03:28 +0100583 printf("Done.\n");
584 return EXIT_SUCCESS;
Holger Freytheraa0fb362008-12-28 21:55:40 +0000585}