blob: 43934f364167b3e96e239bbe792bd75a98b9d1f7 [file] [log] [blame]
Holger Hans Peter Freytherbce56752012-11-22 14:59:46 +01001/*
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>
Maxfd2c1f92017-03-24 21:04:57 +010025#include <osmocom/gsm/protocol/gsm_12_21.h>
Neels Hofmeyr27dd53d2018-03-05 00:23:52 +010026#include <osmocom/gsm/gsm23003.h>
Holger Hans Peter Freytherbce56752012-11-22 14:59:46 +010027
Neels Hofmeyrc0164792017-09-04 15:15:32 +020028#include <osmocom/bsc/gsm_data.h>
29#include <osmocom/bsc/abis_nm.h>
30#include <osmocom/bsc/debug.h>
Holger Hans Peter Freytherbce56752012-11-22 14:59:46 +010031
Holger Hans Peter Freyther2f257472012-11-22 19:04:10 +010032static 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 Freyther2f257472012-11-22 19:04:10 +010042static void test_sw_selection(void)
43{
Maxfd2c1f92017-03-24 21:04:57 +010044 struct abis_nm_sw_desc descr[8], tmp;
45 uint16_t len0, len1;
Holger Hans Peter Freyther2f257472012-11-22 19:04:10 +010046 int rc, pos;
47
Maxfd2c1f92017-03-24 21:04:57 +010048 rc = abis_nm_get_sw_conf(load_config, ARRAY_SIZE(load_config),
Holger Hans Peter Freyther2f257472012-11-22 19:04:10 +010049 &descr[0], ARRAY_SIZE(descr));
50 if (rc != 2) {
Maxfd2c1f92017-03-24 21:04:57 +010051 printf("%s(): FAILED to parse the File Id/File version: %d\n",
52 __func__, rc);
Holger Hans Peter Freyther2f257472012-11-22 19:04:10 +010053 abort();
54 }
55
Maxfd2c1f92017-03-24 21:04:57 +010056 len0 = abis_nm_sw_desc_len(&descr[0], true);
57 printf("len: %u\n", len0);
Holger Hans Peter Freyther2f257472012-11-22 19:04:10 +010058 printf("file_id: %s\n", osmo_hexdump(descr[0].file_id, descr[0].file_id_len));
Maxfd2c1f92017-03-24 21:04:57 +010059 printf("file_ver: %s\n", osmo_hexdump(descr[0].file_version, descr[0].file_version_len));
Holger Hans Peter Freyther2f257472012-11-22 19:04:10 +010060
Maxfd2c1f92017-03-24 21:04:57 +010061 len1 = abis_nm_sw_desc_len(&descr[1], true);
62 printf("len: %u\n", len1);
Holger Hans Peter Freyther2f257472012-11-22 19:04:10 +010063 printf("file_id: %s\n", osmo_hexdump(descr[1].file_id, descr[1].file_id_len));
Maxfd2c1f92017-03-24 21:04:57 +010064 printf("file_ver: %s\n", osmo_hexdump(descr[1].file_version, descr[1].file_version_len));
Holger Hans Peter Freyther2f257472012-11-22 19:04:10 +010065
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);
Maxfd2c1f92017-03-24 21:04:57 +010084 printf("%s(): OK\n", __func__);
Holger Hans Peter Freyther2f257472012-11-22 19:04:10 +010085}
86
Neels Hofmeyr27dd53d2018-03-05 00:23:52 +010087struct 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};
93static 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,
Neels Hofmeyrf93970b2018-03-05 02:09:40 +0100104 .expect = "002100" "0003" "0004",
Neels Hofmeyr27dd53d2018-03-05 00:23:52 +0100105 },
106 {
107 .plmn = { .mcc = 0, .mnc = 0, .mnc_3_digits = false },
108 .lac = 0,
109 .cell_identity = 0,
110 .expect = "00f000" "0000" "0000",
111 },
112 {
113 .plmn = { .mcc = 0, .mnc = 0, .mnc_3_digits = true },
114 .lac = 0,
115 .cell_identity = 0,
Neels Hofmeyrf93970b2018-03-05 02:09:40 +0100116 .expect = "000000" "0000" "0000",
Neels Hofmeyr27dd53d2018-03-05 00:23:52 +0100117 },
118 {
119 .plmn = { .mcc = 999, .mnc = 999, .mnc_3_digits = false },
120 .lac = 65535,
121 .cell_identity = 65535,
122 .expect = "999999" "ffff" "ffff",
123 },
124 {
125 .plmn = { .mcc = 909, .mnc = 90, .mnc_3_digits = false },
126 .lac = 0xabcd,
127 .cell_identity = 0x2345,
128 .expect = "09f909" "abcd" "2345",
129 },
130 {
131 .plmn = { .mcc = 909, .mnc = 90, .mnc_3_digits = true },
132 .lac = 0xabcd,
133 .cell_identity = 0x2345,
Neels Hofmeyrf93970b2018-03-05 02:09:40 +0100134 .expect = "090990" "abcd" "2345",
Neels Hofmeyr27dd53d2018-03-05 00:23:52 +0100135 },
136};
137
138static void test_abis_nm_ipaccess_cgi()
139{
140 int i;
141 bool pass = true;
142
143 for (i = 0; i < ARRAY_SIZE(test_abis_nm_ipaccess_cgi_data); i++) {
144 struct gsm_network net;
145 struct gsm_bts bts;
146 const struct test_abis_nm_ipaccess_cgi *t = &test_abis_nm_ipaccess_cgi_data[i];
147 uint8_t result_buf[7] = {};
148 char *result;
149 bool ok;
150
Neels Hofmeyrf93970b2018-03-05 02:09:40 +0100151 net.plmn = t->plmn;
Neels Hofmeyr27dd53d2018-03-05 00:23:52 +0100152 bts.network = &net;
153 bts.location_area_code = t->lac;
154 bts.cell_identity = t->cell_identity;
155
156 abis_nm_ipaccess_cgi(result_buf, &bts);
157 result = osmo_hexdump_nospc(result_buf, sizeof(result_buf));
158
159 ok = (strcmp(result, t->expect) == 0);
160 printf("%s[%d]: result=%s %s\n", __func__, i, result, ok ? "pass" : "FAIL");
161 pass = pass && ok;
162 }
163
164 OSMO_ASSERT(pass);
165}
166
167
Neels Hofmeyr7997bf42018-02-13 17:16:44 +0100168static const struct log_info_cat log_categories[] = {
169};
170
171static const struct log_info log_info = {
172 .cat = log_categories,
173 .num_cat = ARRAY_SIZE(log_categories),
174};
175
Holger Hans Peter Freytherbce56752012-11-22 14:59:46 +0100176int main(int argc, char **argv)
177{
Neels Hofmeyre3416182018-03-05 05:31:14 +0100178 osmo_init_logging2(NULL, &log_info);
Maxfd2c1f92017-03-24 21:04:57 +0100179
Holger Hans Peter Freyther2f257472012-11-22 19:04:10 +0100180 test_sw_selection();
Neels Hofmeyr27dd53d2018-03-05 00:23:52 +0100181 test_abis_nm_ipaccess_cgi();
Holger Hans Peter Freytherbce56752012-11-22 14:59:46 +0100182
183 return EXIT_SUCCESS;
184}
Harald Welte3561bd42018-01-28 03:04:16 +0100185
186struct gsm_subscriber_connection *bsc_subscr_con_allocate(struct gsm_network *net) {
187 OSMO_ASSERT(0);
188}
Neels Hofmeyr958f2592018-05-27 01:26:31 +0200189
190bool on_gsm_ts_init(struct gsm_bts_trx_ts *ts) { return true; }
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200191void ts_fsm_alloc(struct gsm_bts_trx_ts *ts) {}
Pau Espin Pedrolf8d03892019-11-12 16:30:30 +0100192int rsl_chan_ms_power_ctrl(struct gsm_lchan *lchan) { return 0; }