blob: ee138b8f7c678295b7ced46f4e471da460af5a6b [file] [log] [blame]
Philippb4cb8382016-09-29 17:01:57 +02001/* Test OML attribute generator */
2
3/* (C) 2016 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
4 * All Rights Reserved
5 *
6 * Author: Philipp Maier
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include <openbsc/gprs_llc_xid.h>
23#include <openbsc/debug.h>
24#include <openbsc/gsm_data.h>
25#include <openbsc/bts_ipaccess_nanobts_omlattr.h>
26
27#include <osmocom/core/talloc.h>
28#include <osmocom/core/utils.h>
29#include <osmocom/core/application.h>
30
31#include <stdio.h>
32#include <string.h>
33
34struct gsm_bts_model bts_model_nanobts = {
35 .type = GSM_BTS_TYPE_NANOBTS,
36 .name = "nanobts",
37 .start = NULL,
38 .oml_rcvmsg = NULL,
39 .e1line_bind_ops = NULL,
40 .nm_att_tlvdef = {
41 .def = {
42 /* ip.access specifics */
43 [NM_ATT_IPACC_DST_IP] = {TLV_TYPE_FIXED, 4},
44 [NM_ATT_IPACC_DST_IP_PORT] =
45 {TLV_TYPE_FIXED, 2},
46 [NM_ATT_IPACC_STREAM_ID] = {TLV_TYPE_TV,},
47 [NM_ATT_IPACC_SEC_OML_CFG] =
48 {TLV_TYPE_FIXED, 6},
49 [NM_ATT_IPACC_IP_IF_CFG] =
50 {TLV_TYPE_FIXED, 8},
51 [NM_ATT_IPACC_IP_GW_CFG] =
52 {TLV_TYPE_FIXED, 12},
53 [NM_ATT_IPACC_IN_SERV_TIME] =
54 {TLV_TYPE_FIXED, 4},
55 [NM_ATT_IPACC_LOCATION] = {TLV_TYPE_TL16V},
56 [NM_ATT_IPACC_PAGING_CFG] =
57 {TLV_TYPE_FIXED, 2},
58 [NM_ATT_IPACC_UNIT_ID] = {TLV_TYPE_TL16V},
59 [NM_ATT_IPACC_UNIT_NAME] = {TLV_TYPE_TL16V},
60 [NM_ATT_IPACC_SNMP_CFG] = {TLV_TYPE_TL16V},
61 [NM_ATT_IPACC_PRIM_OML_CFG_LIST] =
62 {TLV_TYPE_TL16V},
63 [NM_ATT_IPACC_NV_FLAGS] = {TLV_TYPE_TL16V},
64 [NM_ATT_IPACC_FREQ_CTRL] =
65 {TLV_TYPE_FIXED, 2},
66 [NM_ATT_IPACC_PRIM_OML_FB_TOUT] =
67 {TLV_TYPE_TL16V},
68 [NM_ATT_IPACC_CUR_SW_CFG] = {TLV_TYPE_TL16V},
69 [NM_ATT_IPACC_TIMING_BUS] = {TLV_TYPE_TL16V},
70 [NM_ATT_IPACC_CGI] = {TLV_TYPE_TL16V},
71 [NM_ATT_IPACC_RAC] = {TLV_TYPE_TL16V},
72 [NM_ATT_IPACC_OBJ_VERSION] = {TLV_TYPE_TL16V},
73 [NM_ATT_IPACC_GPRS_PAGING_CFG] =
74 {TLV_TYPE_TL16V},
75 [NM_ATT_IPACC_NSEI] = {TLV_TYPE_TL16V},
76 [NM_ATT_IPACC_BVCI] = {TLV_TYPE_TL16V},
77 [NM_ATT_IPACC_NSVCI] = {TLV_TYPE_TL16V},
78 [NM_ATT_IPACC_NS_CFG] = {TLV_TYPE_TL16V},
79 [NM_ATT_IPACC_BSSGP_CFG] = {TLV_TYPE_TL16V},
80 [NM_ATT_IPACC_NS_LINK_CFG] = {TLV_TYPE_TL16V},
81 [NM_ATT_IPACC_RLC_CFG] = {TLV_TYPE_TL16V},
82 [NM_ATT_IPACC_ALM_THRESH_LIST] =
83 {TLV_TYPE_TL16V},
84 [NM_ATT_IPACC_MONIT_VAL_LIST] =
85 {TLV_TYPE_TL16V},
86 [NM_ATT_IPACC_TIB_CONTROL] = {TLV_TYPE_TL16V},
87 [NM_ATT_IPACC_SUPP_FEATURES] =
88 {TLV_TYPE_TL16V},
89 [NM_ATT_IPACC_CODING_SCHEMES] =
90 {TLV_TYPE_TL16V},
91 [NM_ATT_IPACC_RLC_CFG_2] = {TLV_TYPE_TL16V},
92 [NM_ATT_IPACC_HEARTB_TOUT] = {TLV_TYPE_TL16V},
93 [NM_ATT_IPACC_UPTIME] = {TLV_TYPE_TL16V},
94 [NM_ATT_IPACC_RLC_CFG_3] = {TLV_TYPE_TL16V},
95 [NM_ATT_IPACC_SSL_CFG] = {TLV_TYPE_TL16V},
96 [NM_ATT_IPACC_SEC_POSSIBLE] =
97 {TLV_TYPE_TL16V},
98 [NM_ATT_IPACC_IML_SSL_STATE] =
99 {TLV_TYPE_TL16V},
100 [NM_ATT_IPACC_REVOC_DATE] = {TLV_TYPE_TL16V},
101 },
102 },
103};
104
105static void test_nanobts_attr_bts_get(struct gsm_bts *bts, uint8_t *expected)
106{
107 struct msgb *msgb;
108
109 printf("Testing nanobts_attr_bts_get()...\n");
110
111 msgb = nanobts_attr_bts_get(bts);
112 printf("result= %s\n", osmo_hexdump_nospc(msgb->data, msgb->len));
113 printf("expected=%s\n", osmo_hexdump_nospc(expected, msgb->len));
114 OSMO_ASSERT(memcmp(msgb->data, expected, msgb->len) == 0);
115 msgb_free(msgb);
116
117 printf("ok.\n");
118 printf("\n");
119}
120
121static void test_nanobts_attr_nse_get(struct gsm_bts *bts, uint8_t *expected)
122{
123 struct msgb *msgb;
124
125 printf("Testing nanobts_attr_nse_get()...\n");
126
127 msgb = nanobts_attr_nse_get(bts);
128 printf("result= %s\n", osmo_hexdump_nospc(msgb->data, msgb->len));
129 printf("expected=%s\n", osmo_hexdump_nospc(expected, msgb->len));
130 OSMO_ASSERT(memcmp(msgb->data, expected, msgb->len) == 0);
131 msgb_free(msgb);
132
133 printf("ok.\n");
134 printf("\n");
135}
136
137static void test_nanobts_attr_cell_get(struct gsm_bts *bts, uint8_t *expected)
138{
139 struct msgb *msgb;
140
141 printf("Testing nanobts_attr_cell_get()...\n");
142
143 msgb = nanobts_attr_cell_get(bts);
144 printf("result= %s\n", osmo_hexdump_nospc(msgb->data, msgb->len));
145 printf("expected=%s\n", osmo_hexdump_nospc(expected, msgb->len));
146 OSMO_ASSERT(memcmp(msgb->data, expected, msgb->len) == 0);
147 msgb_free(msgb);
148
149 printf("ok.\n");
150 printf("\n");
151}
152
153static void test_nanobts_attr_nscv_get(struct gsm_bts *bts, uint8_t *expected)
154{
155 struct msgb *msgb;
156
157 printf("Testing nanobts_attr_nscv_get()...\n");
158
159 msgb = nanobts_attr_nscv_get(bts);
160 printf("result= %s\n", osmo_hexdump_nospc(msgb->data, msgb->len));
161 printf("expected=%s\n", osmo_hexdump_nospc(expected, msgb->len));
162 OSMO_ASSERT(memcmp(msgb->data, expected, msgb->len) == 0);
163 msgb_free(msgb);
164
165 printf("ok.\n");
166 printf("\n");
167}
168
169static void test_nanobts_attr_radio_get(struct gsm_bts *bts,
170 struct gsm_bts_trx *trx,
171 uint8_t *expected)
172{
173 struct msgb *msgb;
174
175 printf("Testing nanobts_attr_nscv_get()...\n");
176
177 msgb = nanobts_attr_radio_get(bts, trx);
178 printf("result= %s\n", osmo_hexdump_nospc(msgb->data, msgb->len));
179 printf("expected=%s\n", osmo_hexdump_nospc(expected, msgb->len));
180 OSMO_ASSERT(memcmp(msgb->data, expected, msgb->len) == 0);
181 msgb_free(msgb);
182
183 printf("ok.\n");
184 printf("\n");
185}
186
187int main(int argc, char **argv)
188{
189 void *ctx;
190
191 struct gsm_bts *bts;
192 struct gsm_network *net;
193 struct gsm_bts_trx *trx;
194
195 ctx = talloc_named_const(NULL, 0, "ctx");
196
197 /* Allocate environmental structs (bts, net, trx) */
198 net = talloc_zero(ctx, struct gsm_network);
199 INIT_LLIST_HEAD(&net->bts_list);
200 gsm_bts_model_register(&bts_model_nanobts);
201 bts = gsm_bts_alloc_register(net, GSM_BTS_TYPE_NANOBTS, 63);
202 OSMO_ASSERT(bts);
203 trx = talloc_zero(ctx, struct gsm_bts_trx);
204
205 /* Parameters needed by nanobts_attr_bts_get() */
206 bts->rach_b_thresh = -1;
207 bts->rach_ldavg_slots = -1;
208 bts->c0->arfcn = 866;
209 bts->cell_identity = 1337;
210 bts->network->country_code = 1;
211 bts->network->network_code = 1;
212 bts->location_area_code = 1;
213 bts->gprs.rac = 0;
214 uint8_t attr_bts_expected[] =
215 { 0x19, 0x55, 0x5b, 0x61, 0x67, 0x6d, 0x73, 0x18, 0x06, 0x0e, 0x00,
216 0x02, 0x01, 0x20, 0x33, 0x1e, 0x24, 0x24, 0xa8, 0x34, 0x21,
217 0xa8, 0x1f, 0x3f, 0x25,
218 0x00, 0x01, 0x0a, 0x0c, 0x0a, 0x0b, 0x01, 0x2a, 0x0a, 0x2b,
219 0x03, 0xe8, 0x0a, 0x80,
220 0x23, 0x0a, 0x08, 0x03, 0x62, 0x09, 0x3f, 0x99, 0x00, 0x07,
221 0x00, 0xf1, 0x10, 0x00,
222 0x01, 0x05, 0x39
223 };
224
225 /* Parameters needed to test nanobts_attr_nse_get() */
226 bts->gprs.nse.nsei = 101;
227 uint8_t attr_nse_expected[] =
228 { 0x9d, 0x00, 0x02, 0x00, 0x65, 0xa0, 0x00, 0x07, 0x03, 0x03, 0x03,
229 0x03, 0x1e, 0x03, 0x0a, 0xa1, 0x00, 0x0b, 0x03, 0x03, 0x03,
230 0x03, 0x03, 0x0a, 0x03,
231 0x0a, 0x03, 0x0a, 0x03
232 };
233
234 /* Parameters needed to test nanobts_attr_cell_get() */
235 bts->gprs.rac = 0x00;
236 bts->gprs.cell.bvci = 2;
237 bts->gprs.mode = BTS_GPRS_GPRS;
238 uint8_t attr_cell_expected[] =
239 { 0x9a, 0x00, 0x01, 0x00, 0x9c, 0x00, 0x02, 0x05, 0x03, 0x9e, 0x00,
240 0x02, 0x00, 0x02, 0xa3, 0x00, 0x09, 0x14, 0x05, 0x05, 0xa0,
241 0x05, 0x0a, 0x04, 0x08,
242 0x0f, 0xa8, 0x00, 0x02, 0x0f, 0x00, 0xa9, 0x00, 0x05, 0x00,
243 0xfa, 0x00, 0xfa, 0x02
244 };
245
246 /* Parameters needed to test nanobts_attr_nscv_get() */
247 bts->gprs.nsvc[0].nsvci = 0x65;
248 bts->gprs.nsvc[0].remote_port = 0x59d8;
249 bts->gprs.nsvc[0].remote_ip = 0x0a090165;
250 bts->gprs.nsvc[0].local_port = 0x5a3c;
251 uint8_t attr_nscv_expected[] =
252 { 0x9f, 0x00, 0x02, 0x00, 0x65, 0xa2, 0x00, 0x08, 0x59, 0xd8, 0x0a,
253 0x09, 0x01, 0x65, 0x5a, 0x3c
254 };
255
256 /* Parameters needed to test nanobts_attr_radio_get() */
257 trx->arfcn = 866;
258 trx->max_power_red = 22;
259 bts->c0->max_power_red = 22;
260 uint8_t attr_radio_expected[] =
261 { 0x2d, 0x0b, 0x05, 0x00, 0x02, 0x03, 0x62 };
262
263 /* Run tests */
264 test_nanobts_attr_bts_get(bts, attr_bts_expected);
265 test_nanobts_attr_nse_get(bts, attr_nse_expected);
266 test_nanobts_attr_cell_get(bts, attr_cell_expected);
267 test_nanobts_attr_nscv_get(bts, attr_nscv_expected);
268 test_nanobts_attr_radio_get(bts, trx, attr_radio_expected);
269
270 printf("Done\n");
271 talloc_free(bts);
272 talloc_free(net);
273 talloc_free(trx);
274 talloc_report_full(ctx, stderr);
275 OSMO_ASSERT(talloc_total_blocks(ctx) == 1);
276 return 0;
277}
278
279/* stubs */
280struct osmo_prim_hdr;
281int bssgp_prim_cb(struct osmo_prim_hdr *oph, void *ctx)
282{
283 abort();
284}