blob: 3dd8baf862d5eff6a35f5230435289090df20846 [file] [log] [blame]
Harald Welte52b1f982008-12-23 20:25:15 +00001/* GSM Network Management (OML) messages on the A-bis interface
2 * 3GPP TS 12.21 version 8.0.0 Release 1999 / ETSI TS 100 623 V8.0.0 */
3
Harald Welte4724f992009-01-18 18:01:49 +00004/* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org>
Harald Welte8470bf22008-12-25 23:28:35 +00005 *
Harald Welte52b1f982008-12-23 20:25:15 +00006 * All Rights Reserved
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 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 General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 */
23
24
25#include <errno.h>
Harald Welte4724f992009-01-18 18:01:49 +000026#include <unistd.h>
Harald Welte52b1f982008-12-23 20:25:15 +000027#include <stdio.h>
Harald Welte4724f992009-01-18 18:01:49 +000028#include <fcntl.h>
29
Harald Welte52b1f982008-12-23 20:25:15 +000030#include <sys/types.h>
Harald Welte4724f992009-01-18 18:01:49 +000031#include <sys/stat.h>
Harald Welte8470bf22008-12-25 23:28:35 +000032#include <netinet/in.h>
Harald Welte52b1f982008-12-23 20:25:15 +000033
Harald Welte8470bf22008-12-25 23:28:35 +000034#include <openbsc/gsm_data.h>
35#include <openbsc/debug.h>
36#include <openbsc/msgb.h>
37#include <openbsc/tlv.h>
38#include <openbsc/abis_nm.h>
Holger Freytherca362a62009-01-04 21:05:01 +000039#include <openbsc/misdn.h>
Harald Welte52b1f982008-12-23 20:25:15 +000040
Harald Welte8470bf22008-12-25 23:28:35 +000041#define OM_ALLOC_SIZE 1024
42#define OM_HEADROOM_SIZE 128
Harald Welte52b1f982008-12-23 20:25:15 +000043
44/* unidirectional messages from BTS to BSC */
45static const enum abis_nm_msgtype reports[] = {
46 NM_MT_SW_ACTIVATED_REP,
47 NM_MT_TEST_REP,
48 NM_MT_STATECHG_EVENT_REP,
49 NM_MT_FAILURE_EVENT_REP,
50};
51
52/* messages without ACK/NACK */
53static const enum abis_nm_msgtype no_ack_nack[] = {
54 NM_MT_MEAS_RES_REQ,
55 NM_MT_STOP_MEAS,
56 NM_MT_START_MEAS,
57};
58
Harald Welte4724f992009-01-18 18:01:49 +000059/* Messages related to software load */
60static const enum abis_nm_msgtype sw_load_msgs[] = {
61 NM_MT_LOAD_INIT_ACK,
62 NM_MT_LOAD_INIT_NACK,
63 NM_MT_LOAD_SEG_ACK,
64 NM_MT_LOAD_ABORT,
65 NM_MT_LOAD_END_ACK,
66 NM_MT_LOAD_END_NACK,
67 NM_MT_SW_ACT_REQ,
68 NM_MT_ACTIVATE_SW_ACK,
69 NM_MT_ACTIVATE_SW_NACK,
70 NM_MT_SW_ACTIVATED_REP,
71};
72
Harald Welte52b1f982008-12-23 20:25:15 +000073/* Attributes that the BSC can set, not only get, according to Section 9.4 */
74static const enum abis_nm_attr nm_att_settable[] = {
75 NM_ATT_ADD_INFO,
76 NM_ATT_ADD_TEXT,
77 NM_ATT_DEST,
78 NM_ATT_EVENT_TYPE,
79 NM_ATT_FILE_DATA,
80 NM_ATT_GET_ARI,
81 NM_ATT_HW_CONF_CHG,
82 NM_ATT_LIST_REQ_ATTR,
83 NM_ATT_MDROP_LINK,
84 NM_ATT_MDROP_NEXT,
85 NM_ATT_NACK_CAUSES,
86 NM_ATT_OUTST_ALARM,
87 NM_ATT_PHYS_CONF,
88 NM_ATT_PROB_CAUSE,
89 NM_ATT_RAD_SUBC,
90 NM_ATT_SOURCE,
91 NM_ATT_SPEC_PROB,
92 NM_ATT_START_TIME,
93 NM_ATT_TEST_DUR,
94 NM_ATT_TEST_NO,
95 NM_ATT_TEST_REPORT,
96 NM_ATT_WINDOW_SIZE,
97 NM_ATT_SEVERITY,
98 NM_ATT_MEAS_RES,
99 NM_ATT_MEAS_TYPE,
100};
101
102static int is_in_arr(enum abis_nm_msgtype mt, const enum abis_nm_msgtype *arr, int size)
103{
104 int i;
105
106 for (i = 0; i < size; i++) {
107 if (arr[i] == mt)
108 return 1;
109 }
110
111 return 0;
112}
113
Holger Freytherca362a62009-01-04 21:05:01 +0000114#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000115/* is this msgtype the usual ACK/NACK type ? */
116static int is_ack_nack(enum abis_nm_msgtype mt)
117{
118 return !is_in_arr(mt, no_ack_nack, ARRAY_SIZE(no_ack_nack));
119}
Holger Freytherca362a62009-01-04 21:05:01 +0000120#endif
Harald Welte52b1f982008-12-23 20:25:15 +0000121
122/* is this msgtype a report ? */
123static int is_report(enum abis_nm_msgtype mt)
124{
Harald Welte8470bf22008-12-25 23:28:35 +0000125 return is_in_arr(mt, reports, ARRAY_SIZE(reports));
Harald Welte52b1f982008-12-23 20:25:15 +0000126}
127
128#define MT_ACK(x) (x+1)
129#define MT_NACK(x) (x+2)
130
131static void fill_om_hdr(struct abis_om_hdr *oh, u_int8_t len)
132{
133 oh->mdisc = ABIS_OM_MDISC_FOM;
134 oh->placement = ABIS_OM_PLACEMENT_ONLY;
135 oh->sequence = 0;
136 oh->length = len;
137}
138
139static void fill_om_fom_hdr(struct abis_om_hdr *oh, u_int8_t len,
140 u_int8_t msg_type, u_int8_t obj_class,
141 u_int8_t bts_nr, u_int8_t trx_nr, u_int8_t ts_nr)
142{
143 struct abis_om_fom_hdr *foh =
144 (struct abis_om_fom_hdr *) oh->data;
145
Harald Welte702d8702008-12-26 20:25:35 +0000146 fill_om_hdr(oh, len+sizeof(*foh));
Harald Welte52b1f982008-12-23 20:25:15 +0000147 foh->msg_type = msg_type;
148 foh->obj_class = obj_class;
149 foh->obj_inst.bts_nr = bts_nr;
150 foh->obj_inst.trx_nr = trx_nr;
151 foh->obj_inst.ts_nr = ts_nr;
152}
153
Harald Welte8470bf22008-12-25 23:28:35 +0000154static struct msgb *nm_msgb_alloc(void)
155{
156 return msgb_alloc_headroom(OM_ALLOC_SIZE, OM_HEADROOM_SIZE);
157}
158
Harald Welte52b1f982008-12-23 20:25:15 +0000159/* Send a OML NM Message from BSC to BTS */
160int abis_nm_sendmsg(struct gsm_bts *bts, struct msgb *msg)
161{
Harald Weltead384642008-12-26 10:20:07 +0000162 return _abis_nm_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000163}
164
Harald Welte4724f992009-01-18 18:01:49 +0000165static int abis_nm_rcvmsg_sw(struct msgb *mb);
166
Harald Welte52b1f982008-12-23 20:25:15 +0000167/* Receive a OML NM Message from BTS */
Harald Welte8470bf22008-12-25 23:28:35 +0000168static int abis_nm_rcvmsg_fom(struct msgb *mb)
Harald Welte52b1f982008-12-23 20:25:15 +0000169{
170 struct abis_om_fom_hdr *foh = msgb_l3(mb);
171 u_int8_t mt = foh->msg_type;
172
173 /* check for unsolicited message */
174 if (is_report(mt)) {
Harald Weltead384642008-12-26 10:20:07 +0000175 DEBUGP(DNM, "reporting NM MT 0x%02x\n", mt);
176 //nmh->cfg->report_cb(mb, foh);
Harald Welte52b1f982008-12-23 20:25:15 +0000177 return 0;
178 }
179
Harald Welte4724f992009-01-18 18:01:49 +0000180 if (is_in_arr(mt, sw_load_msgs, ARRAY_SIZE(sw_load_msgs)))
181 return abis_nm_rcvmsg_sw(mb);
182
Harald Weltead384642008-12-26 10:20:07 +0000183#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000184 /* check if last message is to be acked */
185 if (is_ack_nack(nmh->last_msgtype)) {
186 if (mt == MT_ACK(nmh->last_msgtype)) {
187 fprintf(stderr, "received ACK (0x%x)\n",
188 foh->msg_type);
189 /* we got our ACK, continue sending the next msg */
190 } else if (mt == MT_NACK(nmh->last_msgtype)) {
191 /* we got a NACK, signal this to the caller */
192 fprintf(stderr, "received NACK (0x%x)\n",
193 foh->msg_type);
194 /* FIXME: somehow signal this to the caller */
195 } else {
196 /* really strange things happen */
197 return -EINVAL;
198 }
199 }
Harald Weltead384642008-12-26 10:20:07 +0000200#endif
201
202 return 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000203}
204
205/* High-Level API */
206/* Entry-point where L2 OML from BTS enters the NM code */
Harald Welte8470bf22008-12-25 23:28:35 +0000207int abis_nm_rcvmsg(struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +0000208{
209 int rc;
210 struct abis_om_hdr *oh = msgb_l2(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000211
212 /* Various consistency checks */
213 if (oh->placement != ABIS_OM_PLACEMENT_ONLY) {
214 fprintf(stderr, "ABIS OML placement 0x%x not supported\n",
215 oh->placement);
216 return -EINVAL;
217 }
218 if (oh->sequence != 0) {
219 fprintf(stderr, "ABIS OML sequence 0x%x != 0x00\n",
220 oh->sequence);
221 return -EINVAL;
222 }
Harald Welte702d8702008-12-26 20:25:35 +0000223#if 0
Holger Freytherca362a62009-01-04 21:05:01 +0000224 unsigned int l2_len = msg->tail - (u_int8_t *)msgb_l2(msg);
225 unsigned int hlen = sizeof(*oh) + sizeof(struct abis_om_fom_hdr);
Harald Welte702d8702008-12-26 20:25:35 +0000226 if (oh->length + hlen > l2_len) {
Harald Welte52b1f982008-12-23 20:25:15 +0000227 fprintf(stderr, "ABIS OML truncated message (%u > %u)\n",
228 oh->length + sizeof(*oh), l2_len);
229 return -EINVAL;
230 }
Harald Welte702d8702008-12-26 20:25:35 +0000231 if (oh->length + hlen < l2_len)
232 fprintf(stderr, "ABIS OML message with extra trailer?!? (oh->len=%d, sizeof_oh=%d l2_len=%d\n", oh->length, sizeof(*oh), l2_len);
233#endif
Harald Weltead384642008-12-26 10:20:07 +0000234 msg->l3h = (unsigned char *)oh + sizeof(*oh);
Harald Welte52b1f982008-12-23 20:25:15 +0000235
236 switch (oh->mdisc) {
237 case ABIS_OM_MDISC_FOM:
Harald Welte8470bf22008-12-25 23:28:35 +0000238 rc = abis_nm_rcvmsg_fom(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000239 break;
240 case ABIS_OM_MDISC_MMI:
241 case ABIS_OM_MDISC_TRAU:
242 case ABIS_OM_MDISC_MANUF:
243 default:
244 fprintf(stderr, "unknown ABIS OML message discriminator 0x%x\n",
245 oh->mdisc);
246 return -EINVAL;
247 }
248
Harald Weltead384642008-12-26 10:20:07 +0000249 msgb_free(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000250 return rc;
251}
252
253#if 0
254/* initialized all resources */
255struct abis_nm_h *abis_nm_init(struct abis_nm_cfg *cfg)
256{
257 struct abis_nm_h *nmh;
258
259 nmh = malloc(sizeof(*nmh));
260 if (!nmh)
261 return NULL;
262
263 nmh->cfg = cfg;
264
265 return nmh;
266}
267
268/* free all resources */
269void abis_nm_fini(struct abis_nm_h *nmh)
270{
271 free(nmh);
272}
273#endif
274
275/* Here we are trying to define a high-level API that can be used by
276 * the actual BSC implementation. However, the architecture is currently
277 * still under design. Ideally the calls to this API would be synchronous,
278 * while the underlying stack behind the APi runs in a traditional select
279 * based state machine.
280 */
281
Harald Welte4724f992009-01-18 18:01:49 +0000282/* 6.2 Software Load: */
283enum sw_state {
284 SW_STATE_NONE,
285 SW_STATE_WAIT_INITACK,
286 SW_STATE_WAIT_SEGACK,
287 SW_STATE_WAIT_ENDACK,
288 SW_STATE_WAIT_ACTACK,
289 SW_STATE_ERROR,
290};
Harald Welte52b1f982008-12-23 20:25:15 +0000291
Harald Welte52b1f982008-12-23 20:25:15 +0000292struct abis_nm_sw {
Harald Welte4724f992009-01-18 18:01:49 +0000293 struct gsm_bts *bts;
Harald Welte52b1f982008-12-23 20:25:15 +0000294 /* this will become part of the SW LOAD INITIATE */
295 u_int8_t obj_class;
296 u_int8_t obj_instance[3];
Harald Welte4724f992009-01-18 18:01:49 +0000297
298 u_int8_t file_id[255];
299 u_int8_t file_id_len;
300
301 u_int8_t file_version[255];
302 u_int8_t file_version_len;
303
304 u_int8_t window_size;
305 u_int8_t seg_in_window;
306
307 int fd;
308 FILE *stream;
309 enum sw_state state;
Harald Welte52b1f982008-12-23 20:25:15 +0000310};
311
Harald Welte4724f992009-01-18 18:01:49 +0000312static struct abis_nm_sw g_sw;
313
314/* 6.2.1 / 8.3.1: Load Data Initiate */
315static int sw_load_init(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +0000316{
Harald Welte4724f992009-01-18 18:01:49 +0000317 struct abis_om_hdr *oh;
318 struct msgb *msg = nm_msgb_alloc();
319 u_int8_t len = 3*2 + sw->file_id_len + sw->file_version_len;
320
321 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
322 fill_om_fom_hdr(oh, len, NM_MT_LOAD_INIT, sw->obj_class,
323 sw->obj_instance[0], sw->obj_instance[1],
324 sw->obj_instance[2]);
325
326 /* FIXME: this is BS11 specific format */
327 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
328 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
329 sw->file_version);
330 msgb_tv_put(msg, NM_ATT_WINDOW_SIZE, sw->window_size);
331
332 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000333}
334
Harald Welte4724f992009-01-18 18:01:49 +0000335/* 6.2.2 / 8.3.2 Load Data Segment */
336static int sw_load_segment(struct abis_nm_sw *sw)
337{
338 struct abis_om_hdr *oh;
339 struct msgb *msg = nm_msgb_alloc();
340 char seg_buf[256];
341 char *line_buf = seg_buf+2;
Harald Welte3b8ba212009-01-29 12:27:58 +0000342 unsigned char *tlv;
Harald Welte4724f992009-01-18 18:01:49 +0000343 u_int8_t len;
Harald Welte4724f992009-01-18 18:01:49 +0000344
345 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte3b8ba212009-01-29 12:27:58 +0000346
347 switch (sw->bts->type) {
348 case GSM_BTS_TYPE_BS11:
349 if (fgets(line_buf, sizeof(seg_buf)-2, sw->stream) == NULL) {
350 perror("fgets reading segment");
351 return -EINVAL;
352 }
353 seg_buf[0] = 0x00;
354 seg_buf[1] = 1 + sw->seg_in_window++;
355
356 len = strlen(line_buf) + 2;
357 tlv = msgb_put(msg, TLV_GROSS_LEN(len));
358 tlv_put(tlv, NM_ATT_BS11_FILE_DATA, len, (u_int8_t *)seg_buf);
359 /* BS11 wants CR + LF in excess of the TLV length !?! */
360 tlv[1] -= 2;
361
362 /* we only now know the exact length for the OM hdr */
363 len = strlen(line_buf)+2;
364 break;
365 default:
366 /* FIXME: Other BTS types */
367 return -1;
Harald Welte4724f992009-01-18 18:01:49 +0000368 }
Harald Welte4724f992009-01-18 18:01:49 +0000369
Harald Welte4724f992009-01-18 18:01:49 +0000370 fill_om_fom_hdr(oh, len, NM_MT_LOAD_SEG, sw->obj_class,
371 sw->obj_instance[0], sw->obj_instance[1],
372 sw->obj_instance[2]);
373
374 return abis_nm_sendmsg(sw->bts, msg);
375}
376
377/* 6.2.4 / 8.3.4 Load Data End */
378static int sw_load_end(struct abis_nm_sw *sw)
379{
380 struct abis_om_hdr *oh;
381 struct msgb *msg = nm_msgb_alloc();
382 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
383
384 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
385 fill_om_fom_hdr(oh, len, NM_MT_LOAD_END, sw->obj_class,
386 sw->obj_instance[0], sw->obj_instance[1],
387 sw->obj_instance[2]);
388
389 /* FIXME: this is BS11 specific format */
390 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
391 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
392 sw->file_version);
393
394 return abis_nm_sendmsg(sw->bts, msg);
395}
Harald Welte52b1f982008-12-23 20:25:15 +0000396/* Activate the specified software into the BTS */
Harald Welte4724f992009-01-18 18:01:49 +0000397static int sw_activate(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +0000398{
Harald Welte4724f992009-01-18 18:01:49 +0000399 struct abis_om_hdr *oh;
400 struct msgb *msg = nm_msgb_alloc();
401 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
Harald Welte52b1f982008-12-23 20:25:15 +0000402
Harald Welte4724f992009-01-18 18:01:49 +0000403 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
404 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, sw->obj_class,
405 sw->obj_instance[0], sw->obj_instance[1],
406 sw->obj_instance[2]);
407
408 /* FIXME: this is BS11 specific format */
409 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
410 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
411 sw->file_version);
412
413 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000414}
Harald Welte4724f992009-01-18 18:01:49 +0000415
416static int sw_open_file(struct abis_nm_sw *sw, const char *fname)
417{
418 char file_id[12+1];
419 char file_version[80+1];
420 int rc;
421
422 sw->fd = open(fname, O_RDONLY);
423 if (sw->fd < 0)
424 return sw->fd;
425
426 switch (sw->bts->type) {
427 case GSM_BTS_TYPE_BS11:
428 sw->stream = fdopen(sw->fd, "r");
429 if (!sw->stream) {
430 perror("fdopen");
431 return -1;
432 }
433 /* read first line and parse file ID and VERSION */
Harald Welte3b8ba212009-01-29 12:27:58 +0000434 rc = fscanf(sw->stream, "@(#)%12s:%80s\r\n",
Harald Welte4724f992009-01-18 18:01:49 +0000435 file_id, file_version);
436 if (rc != 2) {
437 perror("parsing header line of software file");
438 return -1;
439 }
440 strcpy((char *)sw->file_id, file_id);
441 sw->file_id_len = strlen(file_id);
442 strcpy((char *)sw->file_version, file_version);
443 sw->file_version_len = strlen(file_version);
444 /* rewind to start of file */
Harald Welte3b8ba212009-01-29 12:27:58 +0000445 rewind(sw->stream);
Harald Welte4724f992009-01-18 18:01:49 +0000446 break;
447 default:
448 /* We don't know how to treat them yet */
449 close(sw->fd);
450 return -EINVAL;
451 }
452
453 return 0;
454}
455
456static void sw_close_file(struct abis_nm_sw *sw)
457{
458 switch (sw->bts->type) {
459 case GSM_BTS_TYPE_BS11:
460 fclose(sw->stream);
461 break;
462 default:
463 close(sw->fd);
464 break;
465 }
466}
467
468/* Fill the window */
469static int sw_fill_window(struct abis_nm_sw *sw)
470{
471 int rc;
472
473 while (sw->seg_in_window < sw->window_size) {
474 rc = sw_load_segment(sw);
475 if (rc < 0)
476 return rc;
477 if (rc == 1) {
478 sw->state = SW_STATE_WAIT_ENDACK;
479 return sw_load_end(sw);
480 }
481 }
482 return 0;
483}
484
485/* callback function from abis_nm_rcvmsg() handler */
486static int abis_nm_rcvmsg_sw(struct msgb *mb)
487{
488 struct abis_om_fom_hdr *foh = msgb_l3(mb);
489 int rc = -1;
490 struct abis_nm_sw *sw = &g_sw;
491 enum sw_state old_state = sw->state;
492
493 DEBUGP(DNM, "state %u, NM MT 0x%02x\n", sw->state, foh->msg_type);
494
495 switch (sw->state) {
496 case SW_STATE_WAIT_INITACK:
497 switch (foh->msg_type) {
498 case NM_MT_LOAD_INIT_ACK:
499 /* fill window with segments */
500 rc = sw_fill_window(sw);
501 sw->state = SW_STATE_WAIT_SEGACK;
502 break;
503 case NM_MT_LOAD_INIT_NACK:
504 sw->state = SW_STATE_ERROR;
505 break;
506 }
507 break;
508 case SW_STATE_WAIT_SEGACK:
509 switch (foh->msg_type) {
510 case NM_MT_LOAD_SEG_ACK:
511 sw->seg_in_window = 0;
512 /* fill window with more segments */
513 rc = sw_fill_window(sw);
514 sw->state = SW_STATE_WAIT_SEGACK;
515 break;
516 }
517 break;
518 case SW_STATE_WAIT_ENDACK:
519 switch (foh->msg_type) {
520 case NM_MT_LOAD_END_ACK:
521 sw_close_file(sw);
522 /* send activate request */
523 sw->state = SW_STATE_WAIT_ACTACK;
524 rc = sw_activate(sw);
525 break;
526 case NM_MT_LOAD_END_NACK:
527 sw->state = SW_STATE_ERROR;
528 break;
529 }
530 case SW_STATE_WAIT_ACTACK:
531 switch (foh->msg_type) {
532 case NM_MT_ACTIVATE_SW_ACK:
533 /* we're done */
534 sw->state = SW_STATE_NONE;
535 rc = 0;
536 DEBUGP(DMM, "DONE!\n");
537 break;
538 case NM_MT_ACTIVATE_SW_NACK:
539 sw->state = SW_STATE_ERROR;
540 break;
541 }
542 case SW_STATE_NONE:
543 case SW_STATE_ERROR:
544 break;
545 }
546
547 if (rc)
548 fprintf(stderr, "unexpected NM MT 0x%02x in state %u -> %u\n",
549 foh->msg_type, old_state, sw->state);
550
551 return rc;
552}
553
554/* Load the specified software into the BTS */
555int abis_nm_software_load(struct gsm_bts *bts, const char *fname,
556 u_int8_t win_size)
557{
558 struct abis_nm_sw *sw = &g_sw;
559 int rc;
560
561 if (sw->state != SW_STATE_NONE)
562 return -EBUSY;
563
564 sw->bts = bts;
565 sw->obj_class = NM_OC_SITE_MANAGER;
566 sw->obj_instance[0] = 0xff;
567 sw->obj_instance[1] = 0xff;
568 sw->obj_instance[2] = 0xff;
569 sw->window_size = win_size;
570 sw->state = SW_STATE_WAIT_INITACK;
571
572 rc = sw_open_file(sw, fname);
573 if (rc < 0) {
574 sw->state = SW_STATE_NONE;
575 return rc;
576 }
577
578 return sw_load_init(sw);
579}
Harald Welte52b1f982008-12-23 20:25:15 +0000580
Harald Welte8470bf22008-12-25 23:28:35 +0000581static void fill_nm_channel(struct abis_nm_channel *ch, u_int8_t bts_port,
Harald Welte52b1f982008-12-23 20:25:15 +0000582 u_int8_t ts_nr, u_int8_t subslot_nr)
583{
Harald Welteadaf08b2009-01-18 11:08:10 +0000584 ch->attrib = NM_ATT_ABIS_CHANNEL;
Harald Welte52b1f982008-12-23 20:25:15 +0000585 ch->bts_port = bts_port;
586 ch->timeslot = ts_nr;
587 ch->subslot = subslot_nr;
588}
589
590int abis_nm_establish_tei(struct gsm_bts *bts, u_int8_t trx_nr,
591 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot,
592 u_int8_t tei)
593{
594 struct abis_om_hdr *oh;
595 struct abis_nm_channel *ch;
Harald Welte702d8702008-12-26 20:25:35 +0000596 u_int8_t len = sizeof(*ch) + 2;
Harald Welte8470bf22008-12-25 23:28:35 +0000597 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000598
599 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
600 fill_om_fom_hdr(oh, len, NM_MT_ESTABLISH_TEI, NM_OC_RADIO_CARRIER,
601 bts->bts_nr, trx_nr, 0xff);
602
Harald Welte8470bf22008-12-25 23:28:35 +0000603 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte52b1f982008-12-23 20:25:15 +0000604
605 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
606 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
607
608 return abis_nm_sendmsg(bts, msg);
609}
610
611/* connect signalling of one (BTS,TRX) to a particular timeslot on the E1 */
612int abis_nm_conn_terr_sign(struct gsm_bts_trx *trx,
613 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot)
614{
Harald Welte8470bf22008-12-25 23:28:35 +0000615 struct gsm_bts *bts = trx->bts;
Harald Welte52b1f982008-12-23 20:25:15 +0000616 struct abis_om_hdr *oh;
617 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +0000618 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000619
620 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +0000621 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_SIGN,
Harald Welte52b1f982008-12-23 20:25:15 +0000622 NM_OC_RADIO_CARRIER, bts->bts_nr, trx->nr, 0xff);
623
624 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
625 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
626
627 return abis_nm_sendmsg(bts, msg);
628}
629
630#if 0
631int abis_nm_disc_terr_sign(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
632 struct abis_nm_abis_channel *chan)
633{
634}
635#endif
636
637int abis_nm_conn_terr_traf(struct gsm_bts_trx_ts *ts,
638 u_int8_t e1_port, u_int8_t e1_timeslot,
639 u_int8_t e1_subslot)
640{
641 struct gsm_bts *bts = ts->trx->bts;
642 struct abis_om_hdr *oh;
643 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +0000644 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000645
646 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
647 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_TRAF,
648 NM_OC_BASEB_TRANSC, bts->bts_nr, ts->trx->nr, ts->nr);
649
650 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
651 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
652
653 return abis_nm_sendmsg(bts, msg);
654}
655
656#if 0
657int abis_nm_disc_terr_traf(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
658 struct abis_nm_abis_channel *chan,
659 u_int8_t subchan)
660{
661}
662#endif
663
664int abis_nm_set_channel_attr(struct gsm_bts_trx_ts *ts, u_int8_t chan_comb)
665{
666 struct gsm_bts *bts = ts->trx->bts;
667 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +0000668 u_int16_t arfcn = htons(ts->trx->arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +0000669 u_int8_t zero = 0x00;
Harald Welte8470bf22008-12-25 23:28:35 +0000670 struct msgb *msg = nm_msgb_alloc();
Harald Welte702d8702008-12-26 20:25:35 +0000671 u_int8_t len = 4 + 2 + 2 + 2 + 2 +3;
Harald Welte52b1f982008-12-23 20:25:15 +0000672
673 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +0000674 fill_om_fom_hdr(oh, len, NM_MT_SET_CHAN_ATTR,
Harald Welte52b1f982008-12-23 20:25:15 +0000675 NM_OC_BASEB_TRANSC, bts->bts_nr,
676 ts->trx->nr, ts->nr);
677 /* FIXME: don't send ARFCN list, hopping sequence, mAIO, ...*/
678 msgb_tlv16_put(msg, NM_ATT_ARFCN_LIST, 1, &arfcn);
679 msgb_tv_put(msg, NM_ATT_CHAN_COMB, chan_comb);
680 msgb_tv_put(msg, NM_ATT_HSN, 0x00);
681 msgb_tv_put(msg, NM_ATT_MAIO, 0x00);
682 msgb_tv_put(msg, NM_ATT_TSC, 0x07); /* training sequence */
683 msgb_tlv_put(msg, 0x59, 1, &zero);
684
685 return abis_nm_sendmsg(bts, msg);
686}
687
Harald Welte8470bf22008-12-25 23:28:35 +0000688int abis_nm_raw_msg(struct gsm_bts *bts, int len, u_int8_t *rawmsg)
Harald Welte52b1f982008-12-23 20:25:15 +0000689{
Harald Welte8470bf22008-12-25 23:28:35 +0000690 struct msgb *msg = nm_msgb_alloc();
691 struct abis_om_hdr *oh;
Harald Welte52b1f982008-12-23 20:25:15 +0000692 u_int8_t *data;
693
694 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
695 fill_om_hdr(oh, len);
696 data = msgb_put(msg, len);
Harald Weltead384642008-12-26 10:20:07 +0000697 memcpy(data, rawmsg, len);
Harald Welte52b1f982008-12-23 20:25:15 +0000698
699 return abis_nm_sendmsg(bts, msg);
700}
701
702/* Siemens specific commands */
703static int __simple_cmd(struct gsm_bts *bts, u_int8_t msg_type)
704{
705 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +0000706 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000707
708 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +0000709 fill_om_fom_hdr(oh, 0, msg_type, NM_OC_SITE_MANAGER,
Harald Welte52b1f982008-12-23 20:25:15 +0000710 0xff, 0xff, 0xff);
711
712 return abis_nm_sendmsg(bts, msg);
713}
714
715int abis_nm_event_reports(struct gsm_bts *bts, int on)
716{
717 if (on == 0)
Harald Welte227d4072009-01-03 08:16:25 +0000718 return __simple_cmd(bts, NM_MT_STOP_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +0000719 else
Harald Welte227d4072009-01-03 08:16:25 +0000720 return __simple_cmd(bts, NM_MT_REST_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +0000721}
722
Harald Welte47d88ae2009-01-04 12:02:08 +0000723/* Siemens (or BS-11) specific commands */
724
Harald Welte05188ee2009-01-18 11:39:08 +0000725int abis_nm_bs11_reset_resource(struct gsm_bts *bts)
Harald Welte52b1f982008-12-23 20:25:15 +0000726{
Harald Welte4668fda2009-01-03 08:19:29 +0000727 return __simple_cmd(bts, NM_MT_BS11_RESET_RESOURCE);
Harald Welte52b1f982008-12-23 20:25:15 +0000728}
729
Harald Welte05188ee2009-01-18 11:39:08 +0000730int abis_nm_bs11_db_transmission(struct gsm_bts *bts, int begin)
Harald Welte52b1f982008-12-23 20:25:15 +0000731{
732 if (begin)
Harald Welte4668fda2009-01-03 08:19:29 +0000733 return __simple_cmd(bts, NM_MT_BS11_BEGIN_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +0000734 else
Harald Welte4668fda2009-01-03 08:19:29 +0000735 return __simple_cmd(bts, NM_MT_BS11_END_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +0000736}
Harald Welte47d88ae2009-01-04 12:02:08 +0000737
Harald Welte05188ee2009-01-18 11:39:08 +0000738int abis_nm_bs11_create_object(struct gsm_bts *bts,
Harald Welte1bc09062009-01-18 14:17:52 +0000739 enum abis_bs11_objtype type, u_int8_t idx,
740 u_int8_t attr_len, const u_int8_t *attr)
Harald Welte47d88ae2009-01-04 12:02:08 +0000741{
742 struct abis_om_hdr *oh;
743 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +0000744 u_int8_t *cur;
Harald Welte47d88ae2009-01-04 12:02:08 +0000745
746 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +0000747 fill_om_fom_hdr(oh, attr_len, NM_MT_BS11_CREATE_OBJ,
Harald Welte1bc09062009-01-18 14:17:52 +0000748 NM_OC_BS11, type, idx, 0);
749 cur = msgb_put(msg, attr_len);
750 memcpy(cur, attr, attr_len);
Harald Welte47d88ae2009-01-04 12:02:08 +0000751
752 return abis_nm_sendmsg(bts, msg);
753}
754
Harald Welte05188ee2009-01-18 11:39:08 +0000755int abis_nm_bs11_create_envaBTSE(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +0000756{
757 struct abis_om_hdr *oh;
758 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +0000759 u_int8_t zero = 0x00;
Harald Welte47d88ae2009-01-04 12:02:08 +0000760
761 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +0000762 fill_om_fom_hdr(oh, 3, NM_MT_BS11_CREATE_OBJ,
Harald Welte1bc09062009-01-18 14:17:52 +0000763 NM_OC_BS11_ENVABTSE, 0, idx, 0xff);
764 msgb_tlv_put(msg, 0x99, 1, &zero);
Harald Welte47d88ae2009-01-04 12:02:08 +0000765
766 return abis_nm_sendmsg(bts, msg);
767}
768
Harald Welte05188ee2009-01-18 11:39:08 +0000769int abis_nm_bs11_create_bport(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +0000770{
771 struct abis_om_hdr *oh;
772 struct msgb *msg = nm_msgb_alloc();
773
774 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
775 fill_om_fom_hdr(oh, 0, NM_MT_BS11_CREATE_OBJ, NM_OC_BS11_BPORT,
776 idx, 0, 0);
777
778 return abis_nm_sendmsg(bts, msg);
779}
Harald Welte05188ee2009-01-18 11:39:08 +0000780
781int abis_nm_bs11_set_oml_tei(struct gsm_bts *bts, u_int8_t tei)
782{
783 struct abis_om_hdr *oh;
784 struct msgb *msg = nm_msgb_alloc();
Harald Welte05188ee2009-01-18 11:39:08 +0000785
786 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +0000787 fill_om_fom_hdr(oh, 2, NM_MT_BS11_SET_ATTR, NM_OC_SITE_MANAGER,
Harald Welte05188ee2009-01-18 11:39:08 +0000788 0xff, 0xff, 0xff);
789 msgb_tv_put(msg, NM_ATT_TEI, tei);
790
791 return abis_nm_sendmsg(bts, msg);
792}
793
794/* like abis_nm_conn_terr_traf */
795int abis_nm_bs11_conn_oml(struct gsm_bts *bts, u_int8_t e1_port,
796 u_int8_t e1_timeslot, u_int8_t e1_subslot)
797{
798 struct abis_om_hdr *oh;
799 struct abis_nm_channel *ch;
800 struct msgb *msg = nm_msgb_alloc();
801
802 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte05188ee2009-01-18 11:39:08 +0000803 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_BS11_SET_ATTR,
804 NM_OC_SITE_MANAGER, 0xff, 0xff, 0xff);
805
806 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
807 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
808
809 return abis_nm_sendmsg(bts, msg);
810}
811
812int abis_nm_bs11_set_trx_power(struct gsm_bts_trx *trx, u_int8_t level)
813{
814 struct abis_om_hdr *oh;
815 struct msgb *msg = nm_msgb_alloc();
Harald Welte05188ee2009-01-18 11:39:08 +0000816
817 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +0000818 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR,
Harald Welte05188ee2009-01-18 11:39:08 +0000819 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
820 msgb_tlv_put(msg, NM_ATT_BS11_TXPWR, 1, &level);
821
822 return abis_nm_sendmsg(trx->bts, msg);
823}
824
825static const u_int8_t bs11_logon_c7[] =
826 { 0x07, 0xd9, 0x01, 0x11, 0x0d, 0x10, 0x20 };
Harald Weltebb151312009-01-28 20:42:07 +0000827static const u_int8_t bs11_logon_c8[] = { 0x02 };
Harald Welte05188ee2009-01-18 11:39:08 +0000828static const u_int8_t bs11_logon_c9[] = "FACTORY";
829
Harald Welte1bc09062009-01-18 14:17:52 +0000830int abis_nm_bs11_factory_logon(struct gsm_bts *bts, int on)
Harald Welte05188ee2009-01-18 11:39:08 +0000831{
832 struct abis_om_hdr *oh;
833 struct msgb *msg = nm_msgb_alloc();
Harald Welte05188ee2009-01-18 11:39:08 +0000834
835 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte1bc09062009-01-18 14:17:52 +0000836 if (on) {
Harald Welte6f676a32009-01-18 14:27:48 +0000837 u_int8_t len = 3*2 + sizeof(bs11_logon_c7)
838 + sizeof(bs11_logon_c8) + sizeof(bs11_logon_c9);
Harald Welte1bc09062009-01-18 14:17:52 +0000839 fill_om_fom_hdr(oh, len, NM_MT_BS11_FACTORY_LOGON,
840 NM_OC_BS11_A3, 0xff, 0xff, 0xff);
841 msgb_tlv_put(msg, 0xc7, sizeof(bs11_logon_c7), bs11_logon_c7);
842 msgb_tlv_put(msg, 0xc8, sizeof(bs11_logon_c8), bs11_logon_c8);
843 msgb_tlv_put(msg, 0xc9, sizeof(bs11_logon_c9), bs11_logon_c9);
844 } else {
Harald Welte6f676a32009-01-18 14:27:48 +0000845 fill_om_fom_hdr(oh, 0, NM_MT_BS11_LOGOFF,
Harald Welte1bc09062009-01-18 14:17:52 +0000846 NM_OC_BS11_A3, 0xff, 0xff, 0xff);
847 }
Harald Welte05188ee2009-01-18 11:39:08 +0000848
849 return abis_nm_sendmsg(bts, msg);
850}
Harald Welte1bc09062009-01-18 14:17:52 +0000851
852int abis_nm_bs11_set_trx1_pw(struct gsm_bts *bts, const char *password)
853{
854 struct abis_om_hdr *oh;
855 struct msgb *msg;
856
857 if (strlen(password) != 10)
858 return -EINVAL;
859
860 msg = nm_msgb_alloc();
861 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +0000862 fill_om_fom_hdr(oh, 2+strlen(password), NM_MT_BS11_SET_ATTR,
Harald Welte1bc09062009-01-18 14:17:52 +0000863 NM_OC_BS11, BS11_OBJ_TRX1, 0x00, 0x00);
864 msgb_tlv_put(msg, NM_ATT_BS11_PASSWORD, 10, (const u_int8_t *)password);
865
866 return abis_nm_sendmsg(bts, msg);
867}
868
869int abis_nm_bs11_get_state(struct gsm_bts *bts)
870{
871 return __simple_cmd(bts, NM_MT_BS11_GET_STATE);
872}