Holger Freyther | aa0fb36 | 2008-12-28 21:55:40 +0000 | [diff] [blame] | 1 | /* 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 Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 7 | * 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 Freyther | aa0fb36 | 2008-12-28 21:55:40 +0000 | [diff] [blame] | 9 | * (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 Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 16 | * 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 Freyther | aa0fb36 | 2008-12-28 21:55:40 +0000 | [diff] [blame] | 18 | * |
| 19 | */ |
| 20 | |
| 21 | #include <assert.h> |
| 22 | #include <stdio.h> |
| 23 | #include <stdlib.h> |
| 24 | |
Harald Welte | afedeab | 2010-03-04 10:55:40 +0100 | [diff] [blame] | 25 | #include <arpa/inet.h> |
| 26 | |
Holger Freyther | aa0fb36 | 2008-12-28 21:55:40 +0000 | [diff] [blame] | 27 | #include <openbsc/gsm_04_08.h> |
Holger Hans Peter Freyther | ca11443 | 2014-02-08 15:20:48 +0100 | [diff] [blame] | 28 | #include <openbsc/gsm_04_11.h> |
Holger Hans Peter Freyther | 5d0e56f | 2009-08-20 08:41:24 +0200 | [diff] [blame] | 29 | #include <openbsc/gsm_subscriber.h> |
| 30 | #include <openbsc/debug.h> |
Jacob Erlbeck | 4b903b4 | 2014-01-10 17:43:41 +0100 | [diff] [blame] | 31 | #include <openbsc/arfcn_range_encode.h> |
| 32 | #include <osmocom/core/application.h> |
Holger Freyther | aa0fb36 | 2008-12-28 21:55:40 +0000 | [diff] [blame] | 33 | |
| 34 | #define COMPARE(result, op, value) \ |
| 35 | if (!((result) op (value))) {\ |
| 36 | fprintf(stderr, "Compare failed. Was %x should be %x in %s:%d\n",result, value, __FILE__, __LINE__); \ |
| 37 | exit(-1); \ |
| 38 | } |
Holger Hans Peter Freyther | 5d0e56f | 2009-08-20 08:41:24 +0200 | [diff] [blame] | 39 | |
| 40 | #define COMPARE_STR(result, value) \ |
| 41 | if (strcmp(result, value) != 0) { \ |
| 42 | fprintf(stderr, "Compare failed. Was %s should be %s in %s:%d\n",result, value, __FILE__, __LINE__); \ |
| 43 | exit(-1); \ |
| 44 | } |
Holger Freyther | aa0fb36 | 2008-12-28 21:55:40 +0000 | [diff] [blame] | 45 | |
Jacob Erlbeck | 9444d4f | 2014-01-13 14:43:40 +0100 | [diff] [blame] | 46 | #define DBG(...) |
| 47 | |
| 48 | #define VERIFY(res, cmp, wanted) \ |
| 49 | if (!(res cmp wanted)) { \ |
| 50 | printf("ASSERT failed: %s:%d Wanted: %d %s %d\n", \ |
| 51 | __FILE__, __LINE__, res, # cmp, wanted); \ |
| 52 | } |
| 53 | |
| 54 | |
| 55 | |
Holger Freyther | aa0fb36 | 2008-12-28 21:55:40 +0000 | [diff] [blame] | 56 | /* |
| 57 | * Test Location Area Identifier formatting. Table 10.5.3 of 04.08 |
| 58 | */ |
| 59 | static void test_location_area_identifier(void) |
| 60 | { |
| 61 | struct gsm48_loc_area_id lai48; |
| 62 | |
| 63 | printf("Testing test location area identifier\n"); |
| 64 | |
| 65 | /* |
| 66 | * Test the default/test setup. Coming from |
| 67 | * bsc_hack.c dumps |
| 68 | */ |
Harald Welte | afedeab | 2010-03-04 10:55:40 +0100 | [diff] [blame] | 69 | gsm48_generate_lai(&lai48, 1, 1, 1); |
Holger Freyther | aa0fb36 | 2008-12-28 21:55:40 +0000 | [diff] [blame] | 70 | COMPARE(lai48.digits[0], ==, 0x00); |
| 71 | COMPARE(lai48.digits[1], ==, 0xF1); |
| 72 | COMPARE(lai48.digits[2], ==, 0x10); |
| 73 | COMPARE(lai48.lac, ==, htons(0x0001)); |
| 74 | |
Harald Welte | afedeab | 2010-03-04 10:55:40 +0100 | [diff] [blame] | 75 | gsm48_generate_lai(&lai48, 602, 1, 15); |
Holger Freyther | aa0fb36 | 2008-12-28 21:55:40 +0000 | [diff] [blame] | 76 | COMPARE(lai48.digits[0], ==, 0x06); |
| 77 | COMPARE(lai48.digits[1], ==, 0xF2); |
| 78 | COMPARE(lai48.digits[2], ==, 0x10); |
| 79 | COMPARE(lai48.lac, ==, htons(0x000f)); |
| 80 | } |
| 81 | |
Holger Hans Peter Freyther | 5d0e56f | 2009-08-20 08:41:24 +0200 | [diff] [blame] | 82 | static void test_mi_functionality(void) |
| 83 | { |
| 84 | const char *imsi_odd = "987654321098763"; |
| 85 | const char *imsi_even = "9876543210987654"; |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 86 | const uint32_t tmsi = 0xfabeacd0; |
| 87 | uint8_t mi[128]; |
Holger Hans Peter Freyther | 5d0e56f | 2009-08-20 08:41:24 +0200 | [diff] [blame] | 88 | unsigned int mi_len; |
| 89 | char mi_parsed[GSM48_MI_SIZE]; |
| 90 | |
| 91 | printf("Testing parsing and generating TMSI/IMSI\n"); |
| 92 | |
| 93 | /* tmsi code */ |
| 94 | mi_len = gsm48_generate_mid_from_tmsi(mi, tmsi); |
| 95 | gsm48_mi_to_string(mi_parsed, sizeof(mi_parsed), mi + 2, mi_len - 2); |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 96 | COMPARE((uint32_t)strtoul(mi_parsed, NULL, 10), ==, tmsi); |
Holger Hans Peter Freyther | 5d0e56f | 2009-08-20 08:41:24 +0200 | [diff] [blame] | 97 | |
| 98 | /* imsi code */ |
| 99 | mi_len = gsm48_generate_mid_from_imsi(mi, imsi_odd); |
| 100 | gsm48_mi_to_string(mi_parsed, sizeof(mi_parsed), mi + 2, mi_len -2); |
Pablo Neira Ayuso | c0d17f2 | 2011-05-07 12:12:48 +0200 | [diff] [blame] | 101 | printf("hex: %s\n", osmo_hexdump(mi, mi_len)); |
Holger Hans Peter Freyther | 5d0e56f | 2009-08-20 08:41:24 +0200 | [diff] [blame] | 102 | COMPARE_STR(mi_parsed, imsi_odd); |
| 103 | |
| 104 | mi_len = gsm48_generate_mid_from_imsi(mi, imsi_even); |
| 105 | gsm48_mi_to_string(mi_parsed, sizeof(mi_parsed), mi + 2, mi_len -2); |
Pablo Neira Ayuso | c0d17f2 | 2011-05-07 12:12:48 +0200 | [diff] [blame] | 106 | printf("hex: %s\n", osmo_hexdump(mi, mi_len)); |
Holger Hans Peter Freyther | 5d0e56f | 2009-08-20 08:41:24 +0200 | [diff] [blame] | 107 | COMPARE_STR(mi_parsed, imsi_even); |
| 108 | } |
| 109 | |
Jacob Erlbeck | 4b903b4 | 2014-01-10 17:43:41 +0100 | [diff] [blame] | 110 | struct { |
| 111 | int range; |
| 112 | int arfcns_num; |
| 113 | int arfcns[RANGE_ENC_MAX_ARFCNS]; |
| 114 | } arfcn_test_ranges[] = { |
| 115 | {ARFCN_RANGE_512, 12, |
| 116 | { 1, 12, 31, 51, 57, 91, 97, 98, 113, 117, 120, 125 }}, |
| 117 | {ARFCN_RANGE_512, 17, |
| 118 | { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 }}, |
| 119 | {ARFCN_RANGE_512, 18, |
| 120 | { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 }}, |
| 121 | {ARFCN_RANGE_512, 18, |
| 122 | { 1, 17, 31, 45, 58, 79, 81, 97, |
| 123 | 113, 127, 213, 277, 287, 311, 331, 391, |
| 124 | 417, 511 }}, |
| 125 | {ARFCN_RANGE_512, 6, |
| 126 | { 1, 17, 31, 45, 58, 79 }}, |
| 127 | {ARFCN_RANGE_512, 6, |
| 128 | { 10, 17, 31, 45, 58, 79 }}, |
| 129 | {ARFCN_RANGE_1024, 17, |
| 130 | { 0, 17, 31, 45, 58, 79, 81, 97, |
| 131 | 113, 127, 213, 277, 287, 311, 331, 391, |
| 132 | 1023 }}, |
| 133 | {ARFCN_RANGE_1024, 16, |
| 134 | { 17, 31, 45, 58, 79, 81, 97, 113, |
| 135 | 127, 213, 277, 287, 311, 331, 391, 1023 }}, |
| 136 | {-1} |
| 137 | }; |
| 138 | |
| 139 | static int test_single_range_encoding(int range, const int *orig_arfcns, |
| 140 | int arfcns_num, int silent) |
| 141 | { |
| 142 | int arfcns[RANGE_ENC_MAX_ARFCNS]; |
| 143 | int w[RANGE_ENC_MAX_ARFCNS]; |
| 144 | int f0_included = 0; |
| 145 | int rc, f0; |
| 146 | uint8_t chan_list[16] = {0}; |
| 147 | struct gsm_sysinfo_freq dec_freq[1024] = {{0}}; |
| 148 | int dec_arfcns[RANGE_ENC_MAX_ARFCNS] = {0}; |
| 149 | int dec_arfcns_count = 0; |
| 150 | int arfcns_used = 0; |
| 151 | int i; |
| 152 | |
| 153 | arfcns_used = arfcns_num; |
| 154 | memmove(arfcns, orig_arfcns, sizeof(arfcns)); |
| 155 | |
Jacob Erlbeck | 45014a0 | 2014-01-14 10:42:58 +0100 | [diff] [blame] | 156 | f0 = range == ARFCN_RANGE_1024 ? 0 : arfcns[0]; |
Jacob Erlbeck | 4b903b4 | 2014-01-10 17:43:41 +0100 | [diff] [blame] | 157 | /* |
| 158 | * Manipulate the ARFCN list according to the rules in J4 depending |
| 159 | * on the selected range. |
| 160 | */ |
Jacob Erlbeck | 45014a0 | 2014-01-14 10:42:58 +0100 | [diff] [blame] | 161 | arfcns_used = range_enc_filter_arfcns(arfcns, arfcns_used, |
Jacob Erlbeck | 4b903b4 | 2014-01-10 17:43:41 +0100 | [diff] [blame] | 162 | f0, &f0_included); |
| 163 | |
| 164 | memset(w, 0, sizeof(w)); |
| 165 | rc = range_enc_arfcns(range, arfcns, arfcns_used, w, 0); |
| 166 | if (rc != 0) { |
| 167 | printf("Cannot compute range W(k), rc = %d\n", rc); |
| 168 | return 1; |
| 169 | } |
| 170 | |
| 171 | if (!silent) |
| 172 | fprintf(stderr, "range=%d, arfcns_used=%d, f0=%d, f0_included=%d\n", |
| 173 | range, arfcns_used, f0, f0_included); |
| 174 | |
| 175 | /* Select the range and the amount of bits needed */ |
| 176 | switch (range) { |
| 177 | case ARFCN_RANGE_128: |
| 178 | rc = range_enc_range128(chan_list, f0, w); |
| 179 | break; |
| 180 | case ARFCN_RANGE_256: |
| 181 | rc = range_enc_range256(chan_list, f0, w); |
| 182 | break; |
| 183 | case ARFCN_RANGE_512: |
| 184 | rc = range_enc_range512(chan_list, f0, w); |
| 185 | break; |
| 186 | case ARFCN_RANGE_1024: |
| 187 | rc = range_enc_range1024(chan_list, f0, f0_included, w); |
| 188 | break; |
| 189 | default: |
| 190 | return 1; |
| 191 | }; |
| 192 | if (rc != 0) { |
| 193 | printf("Cannot encode range, rc = %d\n", rc); |
| 194 | return 1; |
| 195 | } |
| 196 | |
| 197 | if (!silent) |
| 198 | printf("chan_list = %s\n", |
| 199 | osmo_hexdump(chan_list, sizeof(chan_list))); |
| 200 | |
| 201 | rc = gsm48_decode_freq_list(dec_freq, chan_list, sizeof(chan_list), |
| 202 | 0xfe, 1); |
| 203 | if (rc != 0) { |
| 204 | printf("Cannot decode freq list, rc = %d\n", rc); |
| 205 | return 1; |
| 206 | } |
| 207 | |
| 208 | for (i = 0; i < ARRAY_SIZE(dec_freq); i++) { |
| 209 | if (dec_freq[i].mask && |
| 210 | dec_arfcns_count < ARRAY_SIZE(dec_arfcns)) |
| 211 | dec_arfcns[dec_arfcns_count++] = i; |
| 212 | } |
| 213 | |
| 214 | if (!silent) { |
| 215 | printf("Decoded freqs %d (expected %d)\n", |
| 216 | dec_arfcns_count, arfcns_num); |
| 217 | printf("Decoded: "); |
| 218 | for (i = 0; i < dec_arfcns_count; i++) { |
| 219 | printf("%d ", dec_arfcns[i]); |
| 220 | if (dec_arfcns[i] != orig_arfcns[i]) |
| 221 | printf("(!= %d) ", orig_arfcns[i]); |
| 222 | } |
| 223 | printf("\n"); |
| 224 | } |
| 225 | |
| 226 | if (dec_arfcns_count != arfcns_num) { |
| 227 | printf("Wrong number of arfcns\n"); |
| 228 | return 1; |
| 229 | } |
| 230 | |
| 231 | if (memcmp(dec_arfcns, orig_arfcns, sizeof(dec_arfcns)) != 0) { |
| 232 | printf("Decoding error, got wrong freqs\n"); |
| 233 | fprintf(stderr, " w = "); |
| 234 | for (i = 0; i < ARRAY_SIZE(w); i++) |
| 235 | fprintf(stderr, "%d ", w[i]); |
| 236 | fprintf(stderr, "\n"); |
| 237 | return 1; |
| 238 | } |
| 239 | |
| 240 | return 0; |
| 241 | } |
| 242 | |
| 243 | static void test_random_range_encoding(int range, int max_arfcn_num) |
| 244 | { |
| 245 | int arfcns_num = 0; |
| 246 | int test_idx; |
| 247 | int rc, max_count; |
| 248 | int num_tests = 1024; |
| 249 | |
| 250 | printf("Random range test: range %d, max num ARFCNs %d\n", |
| 251 | range, max_arfcn_num); |
| 252 | |
| 253 | srandom(1); |
| 254 | |
| 255 | for (max_count = 1; max_count < max_arfcn_num; max_count++) { |
| 256 | for (test_idx = 0; test_idx < num_tests; test_idx++) { |
| 257 | int count; |
| 258 | int i; |
| 259 | int min_freq = 0; |
| 260 | |
| 261 | int rnd_arfcns[RANGE_ENC_MAX_ARFCNS] = {0}; |
| 262 | char rnd_arfcns_set[1024] = {0}; |
| 263 | |
| 264 | if (range < ARFCN_RANGE_1024) |
| 265 | min_freq = random() % (1023 - range); |
| 266 | |
| 267 | for (count = max_count; count; ) { |
| 268 | int arfcn = min_freq + random() % (range + 1); |
| 269 | OSMO_ASSERT(arfcn < ARRAY_SIZE(rnd_arfcns_set)); |
| 270 | |
| 271 | if (!rnd_arfcns_set[arfcn]) { |
| 272 | rnd_arfcns_set[arfcn] = 1; |
| 273 | count -= 1; |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | arfcns_num = 0; |
| 278 | for (i = 0; i < ARRAY_SIZE(rnd_arfcns_set); i++) |
| 279 | if (rnd_arfcns_set[i]) |
| 280 | rnd_arfcns[arfcns_num++] = i; |
| 281 | |
| 282 | rc = test_single_range_encoding(range, rnd_arfcns, |
| 283 | arfcns_num, 1); |
| 284 | if (rc != 0) { |
| 285 | printf("Failed on test %d, range %d, num ARFCNs %d\n", |
| 286 | test_idx, range, max_count); |
| 287 | test_single_range_encoding(range, rnd_arfcns, |
| 288 | arfcns_num, 0); |
| 289 | return; |
| 290 | } |
| 291 | } |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | static void test_range_encoding() |
| 296 | { |
| 297 | int *arfcns; |
| 298 | int arfcns_num = 0; |
| 299 | int test_idx; |
| 300 | int range; |
| 301 | |
| 302 | for (test_idx = 0; arfcn_test_ranges[test_idx].arfcns_num > 0; test_idx++) |
| 303 | { |
| 304 | arfcns_num = arfcn_test_ranges[test_idx].arfcns_num; |
| 305 | arfcns = &arfcn_test_ranges[test_idx].arfcns[0]; |
| 306 | range = arfcn_test_ranges[test_idx].range; |
| 307 | |
| 308 | printf("Range test %d: range %d, num ARFCNs %d\n", |
| 309 | test_idx, range, arfcns_num); |
| 310 | |
| 311 | test_single_range_encoding(range, arfcns, arfcns_num, 0); |
| 312 | } |
| 313 | |
| 314 | test_random_range_encoding(ARFCN_RANGE_128, 29); |
| 315 | test_random_range_encoding(ARFCN_RANGE_256, 22); |
| 316 | test_random_range_encoding(ARFCN_RANGE_512, 18); |
| 317 | test_random_range_encoding(ARFCN_RANGE_1024, 16); |
| 318 | } |
| 319 | |
Jacob Erlbeck | 9444d4f | 2014-01-13 14:43:40 +0100 | [diff] [blame] | 320 | static int freqs1[] = { |
| 321 | 12, 70, 121, 190, 250, 320, 401, 475, 520, 574, 634, 700, 764, 830, 905, 980 |
| 322 | }; |
| 323 | |
| 324 | static int freqs2[] = { |
| 325 | 402, 460, 1, 67, 131, 197, 272, 347, |
| 326 | }; |
| 327 | |
| 328 | static int freqs3[] = { |
| 329 | 68, 128, 198, 279, 353, 398, 452, |
| 330 | |
| 331 | }; |
| 332 | |
| 333 | static int w_out[] = { |
| 334 | 122, 2, 69, 204, 75, 66, 60, 70, 83, 3, 24, 67, 54, 64, 70, 9, |
| 335 | }; |
| 336 | |
| 337 | static int range128[] = { |
| 338 | 1, 1 + 127, |
| 339 | }; |
| 340 | |
| 341 | static int range256[] = { |
| 342 | 1, 1 + 128, |
| 343 | }; |
| 344 | |
| 345 | static int range512[] = { |
| 346 | 1, 1+ 511, |
| 347 | }; |
| 348 | |
| 349 | |
| 350 | static void test_arfcn_filter() |
| 351 | { |
| 352 | int arfcns[50], i, res, f0_included; |
| 353 | for (i = 0; i < ARRAY_SIZE(arfcns); ++i) |
| 354 | arfcns[i] = (i + 1) * 2; |
| 355 | |
| 356 | /* check that the arfcn is taken out. f0_included is only set for Range1024 */ |
| 357 | f0_included = 24; |
Jacob Erlbeck | 45014a0 | 2014-01-14 10:42:58 +0100 | [diff] [blame] | 358 | res = range_enc_filter_arfcns(arfcns, ARRAY_SIZE(arfcns), |
Jacob Erlbeck | 9444d4f | 2014-01-13 14:43:40 +0100 | [diff] [blame] | 359 | arfcns[0], &f0_included); |
| 360 | VERIFY(res, ==, ARRAY_SIZE(arfcns) - 1); |
| 361 | VERIFY(f0_included, ==, 1); |
| 362 | for (i = 0; i < res; ++i) |
Jacob Erlbeck | 45014a0 | 2014-01-14 10:42:58 +0100 | [diff] [blame] | 363 | VERIFY(arfcns[i], ==, ((i+2) * 2) - (2+1)); |
Jacob Erlbeck | 9444d4f | 2014-01-13 14:43:40 +0100 | [diff] [blame] | 364 | |
Jacob Erlbeck | 45014a0 | 2014-01-14 10:42:58 +0100 | [diff] [blame] | 365 | /* check with range1024, ARFCN 0 is included */ |
| 366 | for (i = 0; i < ARRAY_SIZE(arfcns); ++i) |
| 367 | arfcns[i] = i * 2; |
| 368 | res = range_enc_filter_arfcns(arfcns, ARRAY_SIZE(arfcns), |
| 369 | 0, &f0_included); |
| 370 | VERIFY(res, ==, ARRAY_SIZE(arfcns) - 1); |
| 371 | VERIFY(f0_included, ==, 1); |
| 372 | for (i = 0; i < res; ++i) |
| 373 | VERIFY(arfcns[i], ==, (i + 1) * 2 - 1); |
| 374 | |
| 375 | /* check with range1024, ARFCN 0 not included */ |
Jacob Erlbeck | 9444d4f | 2014-01-13 14:43:40 +0100 | [diff] [blame] | 376 | for (i = 0; i < ARRAY_SIZE(arfcns); ++i) |
| 377 | arfcns[i] = (i + 1) * 2; |
Jacob Erlbeck | 45014a0 | 2014-01-14 10:42:58 +0100 | [diff] [blame] | 378 | res = range_enc_filter_arfcns(arfcns, ARRAY_SIZE(arfcns), |
| 379 | 0, &f0_included); |
Jacob Erlbeck | 9444d4f | 2014-01-13 14:43:40 +0100 | [diff] [blame] | 380 | VERIFY(res, ==, ARRAY_SIZE(arfcns)); |
| 381 | VERIFY(f0_included, ==, 0); |
| 382 | for (i = 0; i < res; ++i) |
| 383 | VERIFY(arfcns[i], ==, ((i + 1) * 2) - 1); |
| 384 | } |
| 385 | |
| 386 | static void test_print_encoding() |
| 387 | { |
| 388 | int rc; |
| 389 | int w[17]; |
| 390 | uint8_t chan_list[16]; |
| 391 | memset(chan_list, 0x23, sizeof(chan_list)); |
| 392 | |
| 393 | for (rc = 0; rc < ARRAY_SIZE(w); ++rc) |
| 394 | switch (rc % 3) { |
| 395 | case 0: |
| 396 | w[rc] = 0xAAAA; |
| 397 | break; |
| 398 | case 1: |
| 399 | w[rc] = 0x5555; |
| 400 | break; |
| 401 | case 2: |
| 402 | w[rc] = 0x9696; |
| 403 | break; |
| 404 | } |
| 405 | |
| 406 | rc = range_enc_range512(chan_list, (1 << 9) | 0x96, w); |
| 407 | VERIFY(rc, ==, 0); |
| 408 | |
| 409 | printf("Range512: %s\n", osmo_hexdump(chan_list, ARRAY_SIZE(chan_list))); |
| 410 | } |
| 411 | |
| 412 | static void test_si_range_helpers() |
| 413 | { |
| 414 | int ws[(sizeof(freqs1)/sizeof(freqs1[0]))]; |
| 415 | int i, f0 = 0xFFFFFF; |
| 416 | |
| 417 | memset(&ws[0], 0x23, sizeof(ws)); |
| 418 | |
| 419 | i = range_enc_find_index(1023, freqs1, ARRAY_SIZE(freqs1)); |
Jacob Erlbeck | 1dc022c | 2014-01-17 09:22:57 +0100 | [diff] [blame] | 420 | printf("Element is: %d => freqs[i] = %d\n", i, i >= 0 ? freqs1[i] : -1); |
Jacob Erlbeck | 9444d4f | 2014-01-13 14:43:40 +0100 | [diff] [blame] | 421 | VERIFY(i, ==, 2); |
| 422 | |
| 423 | i = range_enc_find_index(511, freqs2, ARRAY_SIZE(freqs2)); |
Jacob Erlbeck | 1dc022c | 2014-01-17 09:22:57 +0100 | [diff] [blame] | 424 | printf("Element is: %d => freqs[i] = %d\n", i, i >= 0 ? freqs2[i] : -1); |
Jacob Erlbeck | 9444d4f | 2014-01-13 14:43:40 +0100 | [diff] [blame] | 425 | VERIFY(i, ==, 2); |
| 426 | |
| 427 | i = range_enc_find_index(511, freqs3, ARRAY_SIZE(freqs3)); |
Jacob Erlbeck | 1dc022c | 2014-01-17 09:22:57 +0100 | [diff] [blame] | 428 | printf("Element is: %d => freqs[i] = %d\n", i, i >= 0 ? freqs3[i] : -1); |
Jacob Erlbeck | 9444d4f | 2014-01-13 14:43:40 +0100 | [diff] [blame] | 429 | VERIFY(i, ==, 0); |
| 430 | |
| 431 | i = range_enc_arfcns(1023, freqs1, ARRAY_SIZE(freqs1), ws, 0); |
| 432 | VERIFY(i, ==, 0); |
| 433 | |
| 434 | for (i = 0; i < sizeof(freqs1)/sizeof(freqs1[0]); ++i) { |
| 435 | printf("w[%d]=%d\n", i, ws[i]); |
| 436 | VERIFY(ws[i], ==, w_out[i]); |
| 437 | } |
| 438 | |
| 439 | i = range_enc_determine_range(range128, ARRAY_SIZE(range128), &f0); |
| 440 | VERIFY(i, ==, ARFCN_RANGE_128); |
| 441 | VERIFY(f0, ==, 1); |
| 442 | |
| 443 | i = range_enc_determine_range(range256, ARRAY_SIZE(range256), &f0); |
| 444 | VERIFY(i, ==, ARFCN_RANGE_256); |
| 445 | VERIFY(f0, ==, 1); |
| 446 | |
| 447 | i = range_enc_determine_range(range512, ARRAY_SIZE(range512), &f0); |
| 448 | VERIFY(i, ==, ARFCN_RANGE_512); |
| 449 | VERIFY(f0, ==, 1); |
| 450 | } |
| 451 | |
Holger Hans Peter Freyther | ca11443 | 2014-02-08 15:20:48 +0100 | [diff] [blame] | 452 | static void test_gsm411_rp_ref_wrap(void) |
| 453 | { |
| 454 | struct gsm_subscriber_connection conn; |
| 455 | int res; |
| 456 | |
| 457 | printf("testing RP-Reference wrap\n"); |
| 458 | |
| 459 | memset(&conn, 0, sizeof(conn)); |
| 460 | conn.next_rp_ref = 255; |
| 461 | |
| 462 | res = sms_next_rp_msg_ref(&conn); |
| 463 | printf("Allocated reference: %d\n", res); |
| 464 | OSMO_ASSERT(res == 255); |
| 465 | |
| 466 | res = sms_next_rp_msg_ref(&conn); |
| 467 | printf("Allocated reference: %d\n", res); |
| 468 | OSMO_ASSERT(res == 0); |
| 469 | |
| 470 | res = sms_next_rp_msg_ref(&conn); |
| 471 | printf("Allocated reference: %d\n", res); |
| 472 | OSMO_ASSERT(res == 1); |
| 473 | } |
| 474 | |
Holger Hans Peter Freyther | adb6e1c | 2010-09-18 06:44:24 +0800 | [diff] [blame] | 475 | int main(int argc, char **argv) |
Holger Freyther | aa0fb36 | 2008-12-28 21:55:40 +0000 | [diff] [blame] | 476 | { |
Jacob Erlbeck | 4b903b4 | 2014-01-10 17:43:41 +0100 | [diff] [blame] | 477 | osmo_init_logging(&log_info); |
| 478 | log_set_log_level(osmo_stderr_target, LOGL_INFO); |
| 479 | |
Holger Hans Peter Freyther | 5d0e56f | 2009-08-20 08:41:24 +0200 | [diff] [blame] | 480 | test_location_area_identifier(); |
| 481 | test_mi_functionality(); |
Jacob Erlbeck | 9444d4f | 2014-01-13 14:43:40 +0100 | [diff] [blame] | 482 | |
| 483 | test_si_range_helpers(); |
| 484 | test_arfcn_filter(); |
| 485 | test_print_encoding(); |
Jacob Erlbeck | 4b903b4 | 2014-01-10 17:43:41 +0100 | [diff] [blame] | 486 | test_range_encoding(); |
Holger Hans Peter Freyther | ca11443 | 2014-02-08 15:20:48 +0100 | [diff] [blame] | 487 | test_gsm411_rp_ref_wrap(); |
Harald Welte | afedeab | 2010-03-04 10:55:40 +0100 | [diff] [blame] | 488 | |
Holger Hans Peter Freyther | 300457b | 2012-01-06 15:03:28 +0100 | [diff] [blame] | 489 | printf("Done.\n"); |
| 490 | return EXIT_SUCCESS; |
Holger Freyther | aa0fb36 | 2008-12-28 21:55:40 +0000 | [diff] [blame] | 491 | } |