blob: 9d26eddcdada1156644916d64483078281562a5b [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>
Pau Espin Pedrol388ed582020-07-15 20:53:16 +020029#include <osmocom/bsc/bts.h>
Neels Hofmeyrc0164792017-09-04 15:15:32 +020030#include <osmocom/bsc/abis_nm.h>
31#include <osmocom/bsc/debug.h>
Holger Hans Peter Freytherbce56752012-11-22 14:59:46 +010032
Holger Hans Peter Freyther2f257472012-11-22 19:04:10 +010033static const uint8_t load_config[] = {
34 0x42, 0x12, 0x00, 0x08, 0x31, 0x36, 0x38, 0x64,
35 0x34, 0x37, 0x32, 0x00, 0x13, 0x00, 0x0b, 0x76,
36 0x32, 0x30, 0x30, 0x62, 0x31, 0x34, 0x33, 0x64,
37 0x30, 0x00, 0x42, 0x12, 0x00, 0x08, 0x31, 0x36,
38 0x38, 0x64, 0x34, 0x37, 0x32, 0x00, 0x13, 0x00,
39 0x0b, 0x76, 0x32, 0x30, 0x30, 0x62, 0x31, 0x34,
40 0x33, 0x64, 0x31, 0x00
41};
42
Holger Hans Peter Freyther2f257472012-11-22 19:04:10 +010043static void test_sw_selection(void)
44{
Maxfd2c1f92017-03-24 21:04:57 +010045 struct abis_nm_sw_desc descr[8], tmp;
46 uint16_t len0, len1;
Holger Hans Peter Freyther2f257472012-11-22 19:04:10 +010047 int rc, pos;
48
Maxfd2c1f92017-03-24 21:04:57 +010049 rc = abis_nm_get_sw_conf(load_config, ARRAY_SIZE(load_config),
Holger Hans Peter Freyther2f257472012-11-22 19:04:10 +010050 &descr[0], ARRAY_SIZE(descr));
51 if (rc != 2) {
Maxfd2c1f92017-03-24 21:04:57 +010052 printf("%s(): FAILED to parse the File Id/File version: %d\n",
53 __func__, rc);
Holger Hans Peter Freyther2f257472012-11-22 19:04:10 +010054 abort();
55 }
56
Maxfd2c1f92017-03-24 21:04:57 +010057 len0 = abis_nm_sw_desc_len(&descr[0], true);
58 printf("len: %u\n", len0);
Holger Hans Peter Freyther2f257472012-11-22 19:04:10 +010059 printf("file_id: %s\n", osmo_hexdump(descr[0].file_id, descr[0].file_id_len));
Maxfd2c1f92017-03-24 21:04:57 +010060 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 +010061
Maxfd2c1f92017-03-24 21:04:57 +010062 len1 = abis_nm_sw_desc_len(&descr[1], true);
63 printf("len: %u\n", len1);
Holger Hans Peter Freyther2f257472012-11-22 19:04:10 +010064 printf("file_id: %s\n", osmo_hexdump(descr[1].file_id, descr[1].file_id_len));
Maxfd2c1f92017-03-24 21:04:57 +010065 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 +010066
67 /* start */
68 pos = abis_nm_select_newest_sw(descr, rc);
69 if (pos != 1) {
70 printf("Selected the wrong version: %d\n", pos);
71 abort();
72 }
73 printf("SELECTED: %d\n", pos);
74
75 /* shuffle */
76 tmp = descr[0];
77 descr[0] = descr[1];
78 descr[1] = tmp;
79 pos = abis_nm_select_newest_sw(descr, rc);
80 if (pos != 0) {
81 printf("Selected the wrong version: %d\n", pos);
82 abort();
83 }
84 printf("SELECTED: %d\n", pos);
Maxfd2c1f92017-03-24 21:04:57 +010085 printf("%s(): OK\n", __func__);
Holger Hans Peter Freyther2f257472012-11-22 19:04:10 +010086}
87
Neels Hofmeyr27dd53d2018-03-05 00:23:52 +010088struct test_abis_nm_ipaccess_cgi {
89 struct osmo_plmn_id plmn;
90 uint16_t lac;
91 uint16_t cell_identity;
92 const char *expect;
93};
94static const struct test_abis_nm_ipaccess_cgi test_abis_nm_ipaccess_cgi_data[] = {
95 {
96 .plmn = { .mcc = 1, .mnc = 2, .mnc_3_digits = false },
97 .lac = 3,
98 .cell_identity = 4,
99 .expect = "00f120" "0003" "0004",
100 },
101 {
102 .plmn = { .mcc = 1, .mnc = 2, .mnc_3_digits = true },
103 .lac = 3,
104 .cell_identity = 4,
Neels Hofmeyrf93970b2018-03-05 02:09:40 +0100105 .expect = "002100" "0003" "0004",
Neels Hofmeyr27dd53d2018-03-05 00:23:52 +0100106 },
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,
Neels Hofmeyrf93970b2018-03-05 02:09:40 +0100117 .expect = "000000" "0000" "0000",
Neels Hofmeyr27dd53d2018-03-05 00:23:52 +0100118 },
119 {
120 .plmn = { .mcc = 999, .mnc = 999, .mnc_3_digits = false },
121 .lac = 65535,
122 .cell_identity = 65535,
123 .expect = "999999" "ffff" "ffff",
124 },
125 {
126 .plmn = { .mcc = 909, .mnc = 90, .mnc_3_digits = false },
127 .lac = 0xabcd,
128 .cell_identity = 0x2345,
129 .expect = "09f909" "abcd" "2345",
130 },
131 {
132 .plmn = { .mcc = 909, .mnc = 90, .mnc_3_digits = true },
133 .lac = 0xabcd,
134 .cell_identity = 0x2345,
Neels Hofmeyrf93970b2018-03-05 02:09:40 +0100135 .expect = "090990" "abcd" "2345",
Neels Hofmeyr27dd53d2018-03-05 00:23:52 +0100136 },
137};
138
139static void test_abis_nm_ipaccess_cgi()
140{
141 int i;
142 bool pass = true;
143
144 for (i = 0; i < ARRAY_SIZE(test_abis_nm_ipaccess_cgi_data); i++) {
145 struct gsm_network net;
146 struct gsm_bts bts;
147 const struct test_abis_nm_ipaccess_cgi *t = &test_abis_nm_ipaccess_cgi_data[i];
148 uint8_t result_buf[7] = {};
149 char *result;
150 bool ok;
151
Neels Hofmeyrf93970b2018-03-05 02:09:40 +0100152 net.plmn = t->plmn;
Neels Hofmeyr27dd53d2018-03-05 00:23:52 +0100153 bts.network = &net;
154 bts.location_area_code = t->lac;
155 bts.cell_identity = t->cell_identity;
156
157 abis_nm_ipaccess_cgi(result_buf, &bts);
158 result = osmo_hexdump_nospc(result_buf, sizeof(result_buf));
159
160 ok = (strcmp(result, t->expect) == 0);
161 printf("%s[%d]: result=%s %s\n", __func__, i, result, ok ? "pass" : "FAIL");
162 pass = pass && ok;
163 }
164
165 OSMO_ASSERT(pass);
166}
167
168
Neels Hofmeyr7997bf42018-02-13 17:16:44 +0100169static const struct log_info_cat log_categories[] = {
170};
171
172static const struct log_info log_info = {
173 .cat = log_categories,
174 .num_cat = ARRAY_SIZE(log_categories),
175};
176
Holger Hans Peter Freytherbce56752012-11-22 14:59:46 +0100177int main(int argc, char **argv)
178{
Neels Hofmeyre3416182018-03-05 05:31:14 +0100179 osmo_init_logging2(NULL, &log_info);
Maxfd2c1f92017-03-24 21:04:57 +0100180
Holger Hans Peter Freyther2f257472012-11-22 19:04:10 +0100181 test_sw_selection();
Neels Hofmeyr27dd53d2018-03-05 00:23:52 +0100182 test_abis_nm_ipaccess_cgi();
Holger Hans Peter Freytherbce56752012-11-22 14:59:46 +0100183
184 return EXIT_SUCCESS;
185}
Harald Welte3561bd42018-01-28 03:04:16 +0100186
187struct gsm_subscriber_connection *bsc_subscr_con_allocate(struct gsm_network *net) {
188 OSMO_ASSERT(0);
189}
Neels Hofmeyr958f2592018-05-27 01:26:31 +0200190
191bool on_gsm_ts_init(struct gsm_bts_trx_ts *ts) { return true; }
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200192void ts_fsm_alloc(struct gsm_bts_trx_ts *ts) {}
Pau Espin Pedrolf8d03892019-11-12 16:30:30 +0100193int rsl_chan_ms_power_ctrl(struct gsm_lchan *lchan) { return 0; }
Pau Espin Pedrol8d4f94a2020-07-16 15:17:20 +0200194void pcu_info_update(struct gsm_bts *bts) {};
195int rsl_sacch_filling(struct gsm_bts_trx *trx, uint8_t type, const uint8_t *data, int len) { return 0; }
196int rsl_bcch_info(const struct gsm_bts_trx *trx, enum osmo_sysinfo_type si_type, const uint8_t *data, int len)
197{ return 0; }
198int gsm_generate_si(struct gsm_bts *bts, enum osmo_sysinfo_type si_type) { return 0; }