Holger Hans Peter Freyther | bce5675 | 2012-11-22 14:59:46 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) 2012 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 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 Affero General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 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 Affero General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | * |
| 18 | */ |
| 19 | |
| 20 | #include <stdio.h> |
| 21 | #include <stdlib.h> |
| 22 | |
| 23 | #include <osmocom/core/application.h> |
| 24 | #include <osmocom/core/utils.h> |
Max | fd2c1f9 | 2017-03-24 21:04:57 +0100 | [diff] [blame] | 25 | #include <osmocom/gsm/protocol/gsm_12_21.h> |
Neels Hofmeyr | 27dd53d | 2018-03-05 00:23:52 +0100 | [diff] [blame^] | 26 | #include <osmocom/gsm/gsm23003.h> |
Holger Hans Peter Freyther | bce5675 | 2012-11-22 14:59:46 +0100 | [diff] [blame] | 27 | |
Neels Hofmeyr | c016479 | 2017-09-04 15:15:32 +0200 | [diff] [blame] | 28 | #include <osmocom/bsc/gsm_data.h> |
| 29 | #include <osmocom/bsc/abis_nm.h> |
| 30 | #include <osmocom/bsc/debug.h> |
Holger Hans Peter Freyther | bce5675 | 2012-11-22 14:59:46 +0100 | [diff] [blame] | 31 | |
Holger Hans Peter Freyther | 2f25747 | 2012-11-22 19:04:10 +0100 | [diff] [blame] | 32 | static const uint8_t load_config[] = { |
| 33 | 0x42, 0x12, 0x00, 0x08, 0x31, 0x36, 0x38, 0x64, |
| 34 | 0x34, 0x37, 0x32, 0x00, 0x13, 0x00, 0x0b, 0x76, |
| 35 | 0x32, 0x30, 0x30, 0x62, 0x31, 0x34, 0x33, 0x64, |
| 36 | 0x30, 0x00, 0x42, 0x12, 0x00, 0x08, 0x31, 0x36, |
| 37 | 0x38, 0x64, 0x34, 0x37, 0x32, 0x00, 0x13, 0x00, |
| 38 | 0x0b, 0x76, 0x32, 0x30, 0x30, 0x62, 0x31, 0x34, |
| 39 | 0x33, 0x64, 0x31, 0x00 |
| 40 | }; |
| 41 | |
Holger Hans Peter Freyther | 2f25747 | 2012-11-22 19:04:10 +0100 | [diff] [blame] | 42 | static void test_sw_selection(void) |
| 43 | { |
Max | fd2c1f9 | 2017-03-24 21:04:57 +0100 | [diff] [blame] | 44 | struct abis_nm_sw_desc descr[8], tmp; |
| 45 | uint16_t len0, len1; |
Holger Hans Peter Freyther | 2f25747 | 2012-11-22 19:04:10 +0100 | [diff] [blame] | 46 | int rc, pos; |
| 47 | |
Max | fd2c1f9 | 2017-03-24 21:04:57 +0100 | [diff] [blame] | 48 | rc = abis_nm_get_sw_conf(load_config, ARRAY_SIZE(load_config), |
Holger Hans Peter Freyther | 2f25747 | 2012-11-22 19:04:10 +0100 | [diff] [blame] | 49 | &descr[0], ARRAY_SIZE(descr)); |
| 50 | if (rc != 2) { |
Max | fd2c1f9 | 2017-03-24 21:04:57 +0100 | [diff] [blame] | 51 | printf("%s(): FAILED to parse the File Id/File version: %d\n", |
| 52 | __func__, rc); |
Holger Hans Peter Freyther | 2f25747 | 2012-11-22 19:04:10 +0100 | [diff] [blame] | 53 | abort(); |
| 54 | } |
| 55 | |
Max | fd2c1f9 | 2017-03-24 21:04:57 +0100 | [diff] [blame] | 56 | len0 = abis_nm_sw_desc_len(&descr[0], true); |
| 57 | printf("len: %u\n", len0); |
Holger Hans Peter Freyther | 2f25747 | 2012-11-22 19:04:10 +0100 | [diff] [blame] | 58 | printf("file_id: %s\n", osmo_hexdump(descr[0].file_id, descr[0].file_id_len)); |
Max | fd2c1f9 | 2017-03-24 21:04:57 +0100 | [diff] [blame] | 59 | printf("file_ver: %s\n", osmo_hexdump(descr[0].file_version, descr[0].file_version_len)); |
Holger Hans Peter Freyther | 2f25747 | 2012-11-22 19:04:10 +0100 | [diff] [blame] | 60 | |
Max | fd2c1f9 | 2017-03-24 21:04:57 +0100 | [diff] [blame] | 61 | len1 = abis_nm_sw_desc_len(&descr[1], true); |
| 62 | printf("len: %u\n", len1); |
Holger Hans Peter Freyther | 2f25747 | 2012-11-22 19:04:10 +0100 | [diff] [blame] | 63 | printf("file_id: %s\n", osmo_hexdump(descr[1].file_id, descr[1].file_id_len)); |
Max | fd2c1f9 | 2017-03-24 21:04:57 +0100 | [diff] [blame] | 64 | printf("file_ver: %s\n", osmo_hexdump(descr[1].file_version, descr[1].file_version_len)); |
Holger Hans Peter Freyther | 2f25747 | 2012-11-22 19:04:10 +0100 | [diff] [blame] | 65 | |
| 66 | /* start */ |
| 67 | pos = abis_nm_select_newest_sw(descr, rc); |
| 68 | if (pos != 1) { |
| 69 | printf("Selected the wrong version: %d\n", pos); |
| 70 | abort(); |
| 71 | } |
| 72 | printf("SELECTED: %d\n", pos); |
| 73 | |
| 74 | /* shuffle */ |
| 75 | tmp = descr[0]; |
| 76 | descr[0] = descr[1]; |
| 77 | descr[1] = tmp; |
| 78 | pos = abis_nm_select_newest_sw(descr, rc); |
| 79 | if (pos != 0) { |
| 80 | printf("Selected the wrong version: %d\n", pos); |
| 81 | abort(); |
| 82 | } |
| 83 | printf("SELECTED: %d\n", pos); |
Max | fd2c1f9 | 2017-03-24 21:04:57 +0100 | [diff] [blame] | 84 | printf("%s(): OK\n", __func__); |
Holger Hans Peter Freyther | 2f25747 | 2012-11-22 19:04:10 +0100 | [diff] [blame] | 85 | } |
| 86 | |
Neels Hofmeyr | 27dd53d | 2018-03-05 00:23:52 +0100 | [diff] [blame^] | 87 | struct test_abis_nm_ipaccess_cgi { |
| 88 | struct osmo_plmn_id plmn; |
| 89 | uint16_t lac; |
| 90 | uint16_t cell_identity; |
| 91 | const char *expect; |
| 92 | }; |
| 93 | static const struct test_abis_nm_ipaccess_cgi test_abis_nm_ipaccess_cgi_data[] = { |
| 94 | { |
| 95 | .plmn = { .mcc = 1, .mnc = 2, .mnc_3_digits = false }, |
| 96 | .lac = 3, |
| 97 | .cell_identity = 4, |
| 98 | .expect = "00f120" "0003" "0004", |
| 99 | }, |
| 100 | { |
| 101 | .plmn = { .mcc = 1, .mnc = 2, .mnc_3_digits = true }, |
| 102 | .lac = 3, |
| 103 | .cell_identity = 4, |
| 104 | .expect = "00f120" /* FAIL: should be "002100" */ |
| 105 | "0003" "0004", |
| 106 | }, |
| 107 | { |
| 108 | .plmn = { .mcc = 0, .mnc = 0, .mnc_3_digits = false }, |
| 109 | .lac = 0, |
| 110 | .cell_identity = 0, |
| 111 | .expect = "00f000" "0000" "0000", |
| 112 | }, |
| 113 | { |
| 114 | .plmn = { .mcc = 0, .mnc = 0, .mnc_3_digits = true }, |
| 115 | .lac = 0, |
| 116 | .cell_identity = 0, |
| 117 | .expect = "00f000" /* FAIL: should be "000000" */ |
| 118 | "0000" "0000", |
| 119 | }, |
| 120 | { |
| 121 | .plmn = { .mcc = 999, .mnc = 999, .mnc_3_digits = false }, |
| 122 | .lac = 65535, |
| 123 | .cell_identity = 65535, |
| 124 | .expect = "999999" "ffff" "ffff", |
| 125 | }, |
| 126 | { |
| 127 | .plmn = { .mcc = 909, .mnc = 90, .mnc_3_digits = false }, |
| 128 | .lac = 0xabcd, |
| 129 | .cell_identity = 0x2345, |
| 130 | .expect = "09f909" "abcd" "2345", |
| 131 | }, |
| 132 | { |
| 133 | .plmn = { .mcc = 909, .mnc = 90, .mnc_3_digits = true }, |
| 134 | .lac = 0xabcd, |
| 135 | .cell_identity = 0x2345, |
| 136 | .expect = "09f909" /* FAIL: should be "090990" */ |
| 137 | "abcd" "2345", |
| 138 | }, |
| 139 | }; |
| 140 | |
| 141 | static void test_abis_nm_ipaccess_cgi() |
| 142 | { |
| 143 | int i; |
| 144 | bool pass = true; |
| 145 | |
| 146 | for (i = 0; i < ARRAY_SIZE(test_abis_nm_ipaccess_cgi_data); i++) { |
| 147 | struct gsm_network net; |
| 148 | struct gsm_bts bts; |
| 149 | const struct test_abis_nm_ipaccess_cgi *t = &test_abis_nm_ipaccess_cgi_data[i]; |
| 150 | uint8_t result_buf[7] = {}; |
| 151 | char *result; |
| 152 | bool ok; |
| 153 | |
| 154 | net.country_code = t->plmn.mcc; |
| 155 | net.network_code = t->plmn.mnc; |
| 156 | bts.network = &net; |
| 157 | bts.location_area_code = t->lac; |
| 158 | bts.cell_identity = t->cell_identity; |
| 159 | |
| 160 | abis_nm_ipaccess_cgi(result_buf, &bts); |
| 161 | result = osmo_hexdump_nospc(result_buf, sizeof(result_buf)); |
| 162 | |
| 163 | ok = (strcmp(result, t->expect) == 0); |
| 164 | printf("%s[%d]: result=%s %s\n", __func__, i, result, ok ? "pass" : "FAIL"); |
| 165 | pass = pass && ok; |
| 166 | } |
| 167 | |
| 168 | OSMO_ASSERT(pass); |
| 169 | } |
| 170 | |
| 171 | |
Neels Hofmeyr | 7997bf4 | 2018-02-13 17:16:44 +0100 | [diff] [blame] | 172 | static const struct log_info_cat log_categories[] = { |
| 173 | }; |
| 174 | |
| 175 | static const struct log_info log_info = { |
| 176 | .cat = log_categories, |
| 177 | .num_cat = ARRAY_SIZE(log_categories), |
| 178 | }; |
| 179 | |
Holger Hans Peter Freyther | bce5675 | 2012-11-22 14:59:46 +0100 | [diff] [blame] | 180 | int main(int argc, char **argv) |
| 181 | { |
| 182 | osmo_init_logging(&log_info); |
Max | fd2c1f9 | 2017-03-24 21:04:57 +0100 | [diff] [blame] | 183 | |
Holger Hans Peter Freyther | 2f25747 | 2012-11-22 19:04:10 +0100 | [diff] [blame] | 184 | test_sw_selection(); |
Neels Hofmeyr | 27dd53d | 2018-03-05 00:23:52 +0100 | [diff] [blame^] | 185 | test_abis_nm_ipaccess_cgi(); |
Holger Hans Peter Freyther | bce5675 | 2012-11-22 14:59:46 +0100 | [diff] [blame] | 186 | |
| 187 | return EXIT_SUCCESS; |
| 188 | } |