blob: 749263651149e882eaa6d64d045c9b761a51bc6a [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>
Harald Welte5e4d1b32009-02-01 13:36:56 +000029#include <malloc.h>
30#include <libgen.h>
Harald Welte268bb402009-02-01 19:11:56 +000031#include <time.h>
Harald Welte5f6f1492009-02-02 14:50:29 +000032#include <limits.h>
Harald Welte4724f992009-01-18 18:01:49 +000033
Harald Welte52b1f982008-12-23 20:25:15 +000034#include <sys/types.h>
Harald Welte4724f992009-01-18 18:01:49 +000035#include <sys/stat.h>
Harald Welte8470bf22008-12-25 23:28:35 +000036#include <netinet/in.h>
Harald Welte52b1f982008-12-23 20:25:15 +000037
Harald Welte8470bf22008-12-25 23:28:35 +000038#include <openbsc/gsm_data.h>
39#include <openbsc/debug.h>
40#include <openbsc/msgb.h>
41#include <openbsc/tlv.h>
42#include <openbsc/abis_nm.h>
Holger Freytherca362a62009-01-04 21:05:01 +000043#include <openbsc/misdn.h>
Harald Welte52b1f982008-12-23 20:25:15 +000044
Harald Welte8470bf22008-12-25 23:28:35 +000045#define OM_ALLOC_SIZE 1024
46#define OM_HEADROOM_SIZE 128
Harald Welte52b1f982008-12-23 20:25:15 +000047
48/* unidirectional messages from BTS to BSC */
49static const enum abis_nm_msgtype reports[] = {
50 NM_MT_SW_ACTIVATED_REP,
51 NM_MT_TEST_REP,
52 NM_MT_STATECHG_EVENT_REP,
53 NM_MT_FAILURE_EVENT_REP,
54};
55
56/* messages without ACK/NACK */
57static const enum abis_nm_msgtype no_ack_nack[] = {
58 NM_MT_MEAS_RES_REQ,
59 NM_MT_STOP_MEAS,
60 NM_MT_START_MEAS,
61};
62
Harald Welte4724f992009-01-18 18:01:49 +000063/* Messages related to software load */
64static const enum abis_nm_msgtype sw_load_msgs[] = {
65 NM_MT_LOAD_INIT_ACK,
66 NM_MT_LOAD_INIT_NACK,
67 NM_MT_LOAD_SEG_ACK,
68 NM_MT_LOAD_ABORT,
69 NM_MT_LOAD_END_ACK,
70 NM_MT_LOAD_END_NACK,
Harald Welte34a99682009-02-13 02:41:40 +000071 //NM_MT_SW_ACT_REQ,
Harald Welte4724f992009-01-18 18:01:49 +000072 NM_MT_ACTIVATE_SW_ACK,
73 NM_MT_ACTIVATE_SW_NACK,
74 NM_MT_SW_ACTIVATED_REP,
75};
76
Harald Welte52b1f982008-12-23 20:25:15 +000077/* Attributes that the BSC can set, not only get, according to Section 9.4 */
78static const enum abis_nm_attr nm_att_settable[] = {
79 NM_ATT_ADD_INFO,
80 NM_ATT_ADD_TEXT,
81 NM_ATT_DEST,
82 NM_ATT_EVENT_TYPE,
83 NM_ATT_FILE_DATA,
84 NM_ATT_GET_ARI,
85 NM_ATT_HW_CONF_CHG,
86 NM_ATT_LIST_REQ_ATTR,
87 NM_ATT_MDROP_LINK,
88 NM_ATT_MDROP_NEXT,
89 NM_ATT_NACK_CAUSES,
90 NM_ATT_OUTST_ALARM,
91 NM_ATT_PHYS_CONF,
92 NM_ATT_PROB_CAUSE,
93 NM_ATT_RAD_SUBC,
94 NM_ATT_SOURCE,
95 NM_ATT_SPEC_PROB,
96 NM_ATT_START_TIME,
97 NM_ATT_TEST_DUR,
98 NM_ATT_TEST_NO,
99 NM_ATT_TEST_REPORT,
100 NM_ATT_WINDOW_SIZE,
101 NM_ATT_SEVERITY,
102 NM_ATT_MEAS_RES,
103 NM_ATT_MEAS_TYPE,
104};
105
106static int is_in_arr(enum abis_nm_msgtype mt, const enum abis_nm_msgtype *arr, int size)
107{
108 int i;
109
110 for (i = 0; i < size; i++) {
111 if (arr[i] == mt)
112 return 1;
113 }
114
115 return 0;
116}
117
Holger Freytherca362a62009-01-04 21:05:01 +0000118#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000119/* is this msgtype the usual ACK/NACK type ? */
120static int is_ack_nack(enum abis_nm_msgtype mt)
121{
122 return !is_in_arr(mt, no_ack_nack, ARRAY_SIZE(no_ack_nack));
123}
Holger Freytherca362a62009-01-04 21:05:01 +0000124#endif
Harald Welte52b1f982008-12-23 20:25:15 +0000125
126/* is this msgtype a report ? */
127static int is_report(enum abis_nm_msgtype mt)
128{
Harald Welte8470bf22008-12-25 23:28:35 +0000129 return is_in_arr(mt, reports, ARRAY_SIZE(reports));
Harald Welte52b1f982008-12-23 20:25:15 +0000130}
131
132#define MT_ACK(x) (x+1)
133#define MT_NACK(x) (x+2)
134
135static void fill_om_hdr(struct abis_om_hdr *oh, u_int8_t len)
136{
137 oh->mdisc = ABIS_OM_MDISC_FOM;
138 oh->placement = ABIS_OM_PLACEMENT_ONLY;
139 oh->sequence = 0;
140 oh->length = len;
141}
142
143static void fill_om_fom_hdr(struct abis_om_hdr *oh, u_int8_t len,
144 u_int8_t msg_type, u_int8_t obj_class,
145 u_int8_t bts_nr, u_int8_t trx_nr, u_int8_t ts_nr)
146{
147 struct abis_om_fom_hdr *foh =
148 (struct abis_om_fom_hdr *) oh->data;
149
Harald Welte702d8702008-12-26 20:25:35 +0000150 fill_om_hdr(oh, len+sizeof(*foh));
Harald Welte52b1f982008-12-23 20:25:15 +0000151 foh->msg_type = msg_type;
152 foh->obj_class = obj_class;
153 foh->obj_inst.bts_nr = bts_nr;
154 foh->obj_inst.trx_nr = trx_nr;
155 foh->obj_inst.ts_nr = ts_nr;
156}
157
Harald Welte8470bf22008-12-25 23:28:35 +0000158static struct msgb *nm_msgb_alloc(void)
159{
160 return msgb_alloc_headroom(OM_ALLOC_SIZE, OM_HEADROOM_SIZE);
161}
162
Harald Welte52b1f982008-12-23 20:25:15 +0000163/* Send a OML NM Message from BSC to BTS */
164int abis_nm_sendmsg(struct gsm_bts *bts, struct msgb *msg)
165{
Holger Freyther59639e82009-02-09 23:09:55 +0000166 msg->trx = bts->c0;
167
Harald Weltead384642008-12-26 10:20:07 +0000168 return _abis_nm_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000169}
170
Harald Welte4724f992009-01-18 18:01:49 +0000171static int abis_nm_rcvmsg_sw(struct msgb *mb);
172
Harald Welte34a99682009-02-13 02:41:40 +0000173const char *oc_names[] = {
174 [NM_OC_SITE_MANAGER] = "SITE MANAGER",
175 [NM_OC_BTS] = "BTS",
176 [NM_OC_RADIO_CARRIER] = "RADIO CARRIER",
177 [NM_OC_BASEB_TRANSC] = "BASEBAND TRANSCEIVER",
178 [NM_OC_CHANNEL] = "CHANNEL",
179};
180
181static const char *obj_class_name(u_int8_t oc)
182{
183 if (oc >= ARRAY_SIZE(oc_names))
184 return "UNKNOWN";
185 return oc_names[oc];
186}
187
188static const char *opstate_name(u_int8_t os)
189{
190 switch (os) {
191 case 1:
192 return "Disabled";
193 case 2:
194 return "Enabled";
195 case 0xff:
196 return "NULL";
197 default:
198 return "RFU";
199 }
200}
201
Harald Welte97ed1e72009-02-06 13:38:02 +0000202static int abis_nm_rx_statechg_rep(struct msgb *mb)
203{
204 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Harald Welte97ed1e72009-02-06 13:38:02 +0000205 u_int8_t *data = &foh->data[0];
Harald Welte22af0db2009-02-14 15:41:08 +0000206 struct gsm_bts *bts = mb->trx->bts;
207 u_int8_t op_state = 0;
Harald Welte97ed1e72009-02-06 13:38:02 +0000208
Harald Welte34a99682009-02-13 02:41:40 +0000209 DEBUGP(DNM, "STATE CHG: OC=%s(%02x) INST=(%02x,%02x,%02x) ",
210 obj_class_name(foh->obj_class), foh->obj_class,
211 foh->obj_inst.bts_nr, foh->obj_inst.trx_nr,
Harald Welte97ed1e72009-02-06 13:38:02 +0000212 foh->obj_inst.ts_nr);
Harald Welte22af0db2009-02-14 15:41:08 +0000213 if (*data++ == NM_ATT_OPER_STATE) {
214 u_int8_t op_state = *data++;
215 DEBUGPC(DNM, "OP_STATE=%s ", opstate_name(op_state));
216
217 }
Harald Welte97ed1e72009-02-06 13:38:02 +0000218 if (*data++ == NM_ATT_AVAIL_STATUS) {
219 u_int8_t att_len = *data++;
220 while (att_len--)
221 DEBUGPC(DNM, "AVAIL=%02x ", *data++);
222 }
223 DEBUGPC(DNM, "\n");
Harald Welte22af0db2009-02-14 15:41:08 +0000224 if (op_state == 1) {
225 /* try to enable objects that are disabled */
226 abis_nm_opstart(bts, foh->obj_class,
227 foh->obj_inst.bts_nr,
228 foh->obj_inst.trx_nr,
229 foh->obj_inst.ts_nr);
230 }
Harald Welte97ed1e72009-02-06 13:38:02 +0000231 return 0;
232}
233
234static int abis_nm_rcvmsg_report(struct msgb *mb)
235{
236 struct abis_om_fom_hdr *foh = msgb_l3(mb);
237 u_int8_t mt = foh->msg_type;
238
239 //nmh->cfg->report_cb(mb, foh);
240
241 switch (mt) {
242 case NM_MT_STATECHG_EVENT_REP:
243 return abis_nm_rx_statechg_rep(mb);
244 break;
Harald Welte34a99682009-02-13 02:41:40 +0000245 case NM_MT_SW_ACTIVATED_REP:
246 DEBUGP(DNM, "Software Activated Report\n");
247 break;
Harald Welte97ed1e72009-02-06 13:38:02 +0000248 };
249
250 DEBUGP(DNM, "reporting NM MT 0x%02x\n", mt);
251
252 return 0;
253}
254
Harald Welte34a99682009-02-13 02:41:40 +0000255/* Activate the specified software into the BTS */
256static int ipacc_sw_activate(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1,
257 u_int8_t i2, u_int8_t *sw_desc, u_int8_t swdesc_len)
258{
259 struct abis_om_hdr *oh;
260 struct msgb *msg = nm_msgb_alloc();
261 u_int8_t len = swdesc_len;
262 u_int8_t *trailer;
263
264 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
265 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, obj_class, i0, i1, i2);
266
267 trailer = msgb_put(msg, swdesc_len);
268 memcpy(trailer, sw_desc, swdesc_len);
269
270 return abis_nm_sendmsg(bts, msg);
271}
272
273static int abis_nm_rx_sw_act_req(struct msgb *mb)
274{
275 struct abis_om_hdr *oh = msgb_l2(mb);
276 struct abis_om_fom_hdr *foh = msgb_l3(mb);
277 int ret;
278
279 DEBUGP(DNM, "Software Activate Request, ACKing and Activating\n");
280
281 ret = abis_nm_sw_act_req_ack(mb->trx->bts, foh->obj_class,
282 foh->obj_inst.bts_nr,
283 foh->obj_inst.trx_nr,
284 foh->obj_inst.ts_nr,
285 foh->data, oh->length-sizeof(*foh));
286
287 /* FIXME: properly parse attributes */
288 return ipacc_sw_activate(mb->trx->bts, foh->obj_class,
289 foh->obj_inst.bts_nr,
290 foh->obj_inst.trx_nr,
291 foh->obj_inst.ts_nr,
292 foh->data + oh->length-sizeof(*foh)-22, 22);
293}
294
Harald Welte52b1f982008-12-23 20:25:15 +0000295/* Receive a OML NM Message from BTS */
Harald Welte8470bf22008-12-25 23:28:35 +0000296static int abis_nm_rcvmsg_fom(struct msgb *mb)
Harald Welte52b1f982008-12-23 20:25:15 +0000297{
298 struct abis_om_fom_hdr *foh = msgb_l3(mb);
299 u_int8_t mt = foh->msg_type;
300
301 /* check for unsolicited message */
Harald Welte97ed1e72009-02-06 13:38:02 +0000302 if (is_report(mt))
303 return abis_nm_rcvmsg_report(mb);
Harald Welte52b1f982008-12-23 20:25:15 +0000304
Harald Welte4724f992009-01-18 18:01:49 +0000305 if (is_in_arr(mt, sw_load_msgs, ARRAY_SIZE(sw_load_msgs)))
306 return abis_nm_rcvmsg_sw(mb);
307
Harald Weltead384642008-12-26 10:20:07 +0000308#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000309 /* check if last message is to be acked */
310 if (is_ack_nack(nmh->last_msgtype)) {
311 if (mt == MT_ACK(nmh->last_msgtype)) {
312 fprintf(stderr, "received ACK (0x%x)\n",
313 foh->msg_type);
314 /* we got our ACK, continue sending the next msg */
315 } else if (mt == MT_NACK(nmh->last_msgtype)) {
316 /* we got a NACK, signal this to the caller */
317 fprintf(stderr, "received NACK (0x%x)\n",
318 foh->msg_type);
319 /* FIXME: somehow signal this to the caller */
320 } else {
321 /* really strange things happen */
322 return -EINVAL;
323 }
324 }
Harald Weltead384642008-12-26 10:20:07 +0000325#endif
326
Harald Welte97ed1e72009-02-06 13:38:02 +0000327 switch (mt) {
Harald Welte34a99682009-02-13 02:41:40 +0000328 case NM_MT_SW_ACT_REQ:
329 return abis_nm_rx_sw_act_req(mb);
330 break;
Harald Welte97ed1e72009-02-06 13:38:02 +0000331 case NM_MT_BS11_LMT_SESSION:
332 DEBUGP(DNM, "LMT Event: \n");
333 break;
334 }
335
Harald Weltead384642008-12-26 10:20:07 +0000336 return 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000337}
338
339/* High-Level API */
340/* Entry-point where L2 OML from BTS enters the NM code */
Harald Welte8470bf22008-12-25 23:28:35 +0000341int abis_nm_rcvmsg(struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +0000342{
343 int rc;
344 struct abis_om_hdr *oh = msgb_l2(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000345
346 /* Various consistency checks */
347 if (oh->placement != ABIS_OM_PLACEMENT_ONLY) {
348 fprintf(stderr, "ABIS OML placement 0x%x not supported\n",
349 oh->placement);
350 return -EINVAL;
351 }
352 if (oh->sequence != 0) {
353 fprintf(stderr, "ABIS OML sequence 0x%x != 0x00\n",
354 oh->sequence);
355 return -EINVAL;
356 }
Harald Welte702d8702008-12-26 20:25:35 +0000357#if 0
Holger Freytherca362a62009-01-04 21:05:01 +0000358 unsigned int l2_len = msg->tail - (u_int8_t *)msgb_l2(msg);
359 unsigned int hlen = sizeof(*oh) + sizeof(struct abis_om_fom_hdr);
Harald Welte702d8702008-12-26 20:25:35 +0000360 if (oh->length + hlen > l2_len) {
Harald Welte52b1f982008-12-23 20:25:15 +0000361 fprintf(stderr, "ABIS OML truncated message (%u > %u)\n",
362 oh->length + sizeof(*oh), l2_len);
363 return -EINVAL;
364 }
Harald Welte702d8702008-12-26 20:25:35 +0000365 if (oh->length + hlen < l2_len)
366 fprintf(stderr, "ABIS OML message with extra trailer?!? (oh->len=%d, sizeof_oh=%d l2_len=%d\n", oh->length, sizeof(*oh), l2_len);
367#endif
Harald Weltead384642008-12-26 10:20:07 +0000368 msg->l3h = (unsigned char *)oh + sizeof(*oh);
Harald Welte52b1f982008-12-23 20:25:15 +0000369
370 switch (oh->mdisc) {
371 case ABIS_OM_MDISC_FOM:
Harald Welte8470bf22008-12-25 23:28:35 +0000372 rc = abis_nm_rcvmsg_fom(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000373 break;
374 case ABIS_OM_MDISC_MMI:
375 case ABIS_OM_MDISC_TRAU:
376 case ABIS_OM_MDISC_MANUF:
377 default:
378 fprintf(stderr, "unknown ABIS OML message discriminator 0x%x\n",
379 oh->mdisc);
380 return -EINVAL;
381 }
382
Harald Weltead384642008-12-26 10:20:07 +0000383 msgb_free(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000384 return rc;
385}
386
387#if 0
388/* initialized all resources */
389struct abis_nm_h *abis_nm_init(struct abis_nm_cfg *cfg)
390{
391 struct abis_nm_h *nmh;
392
393 nmh = malloc(sizeof(*nmh));
394 if (!nmh)
395 return NULL;
396
397 nmh->cfg = cfg;
398
399 return nmh;
400}
401
402/* free all resources */
403void abis_nm_fini(struct abis_nm_h *nmh)
404{
405 free(nmh);
406}
407#endif
408
409/* Here we are trying to define a high-level API that can be used by
410 * the actual BSC implementation. However, the architecture is currently
411 * still under design. Ideally the calls to this API would be synchronous,
412 * while the underlying stack behind the APi runs in a traditional select
413 * based state machine.
414 */
415
Harald Welte4724f992009-01-18 18:01:49 +0000416/* 6.2 Software Load: */
417enum sw_state {
418 SW_STATE_NONE,
419 SW_STATE_WAIT_INITACK,
420 SW_STATE_WAIT_SEGACK,
421 SW_STATE_WAIT_ENDACK,
422 SW_STATE_WAIT_ACTACK,
423 SW_STATE_ERROR,
424};
Harald Welte52b1f982008-12-23 20:25:15 +0000425
Harald Welte52b1f982008-12-23 20:25:15 +0000426struct abis_nm_sw {
Harald Welte4724f992009-01-18 18:01:49 +0000427 struct gsm_bts *bts;
Harald Welte5e4d1b32009-02-01 13:36:56 +0000428 gsm_cbfn *cbfn;
429 void *cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +0000430 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +0000431
Harald Welte52b1f982008-12-23 20:25:15 +0000432 /* this will become part of the SW LOAD INITIATE */
433 u_int8_t obj_class;
434 u_int8_t obj_instance[3];
Harald Welte4724f992009-01-18 18:01:49 +0000435
436 u_int8_t file_id[255];
437 u_int8_t file_id_len;
438
439 u_int8_t file_version[255];
440 u_int8_t file_version_len;
441
442 u_int8_t window_size;
443 u_int8_t seg_in_window;
444
445 int fd;
446 FILE *stream;
447 enum sw_state state;
Harald Welte1602ade2009-01-29 21:12:39 +0000448 int last_seg;
Harald Welte52b1f982008-12-23 20:25:15 +0000449};
450
Harald Welte4724f992009-01-18 18:01:49 +0000451static struct abis_nm_sw g_sw;
452
453/* 6.2.1 / 8.3.1: Load Data Initiate */
454static int sw_load_init(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +0000455{
Harald Welte4724f992009-01-18 18:01:49 +0000456 struct abis_om_hdr *oh;
457 struct msgb *msg = nm_msgb_alloc();
458 u_int8_t len = 3*2 + sw->file_id_len + sw->file_version_len;
459
460 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
461 fill_om_fom_hdr(oh, len, NM_MT_LOAD_INIT, sw->obj_class,
462 sw->obj_instance[0], sw->obj_instance[1],
463 sw->obj_instance[2]);
464
465 /* FIXME: this is BS11 specific format */
466 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
467 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
468 sw->file_version);
469 msgb_tv_put(msg, NM_ATT_WINDOW_SIZE, sw->window_size);
470
471 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000472}
473
Harald Welte1602ade2009-01-29 21:12:39 +0000474static int is_last_line(FILE *stream)
475{
476 char next_seg_buf[256];
477 long pos;
478
479 /* check if we're sending the last line */
480 pos = ftell(stream);
481 if (!fgets(next_seg_buf, sizeof(next_seg_buf)-2, stream)) {
482 fseek(stream, pos, SEEK_SET);
483 return 1;
484 }
485
486 fseek(stream, pos, SEEK_SET);
487 return 0;
488}
489
Harald Welte4724f992009-01-18 18:01:49 +0000490/* 6.2.2 / 8.3.2 Load Data Segment */
491static int sw_load_segment(struct abis_nm_sw *sw)
492{
493 struct abis_om_hdr *oh;
494 struct msgb *msg = nm_msgb_alloc();
495 char seg_buf[256];
496 char *line_buf = seg_buf+2;
Harald Welte3b8ba212009-01-29 12:27:58 +0000497 unsigned char *tlv;
Harald Welte4724f992009-01-18 18:01:49 +0000498 u_int8_t len;
Harald Welte4724f992009-01-18 18:01:49 +0000499
500 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte3b8ba212009-01-29 12:27:58 +0000501
502 switch (sw->bts->type) {
503 case GSM_BTS_TYPE_BS11:
504 if (fgets(line_buf, sizeof(seg_buf)-2, sw->stream) == NULL) {
505 perror("fgets reading segment");
506 return -EINVAL;
507 }
508 seg_buf[0] = 0x00;
Harald Welte1602ade2009-01-29 21:12:39 +0000509
510 /* check if we're sending the last line */
511 sw->last_seg = is_last_line(sw->stream);
512 if (sw->last_seg)
513 seg_buf[1] = 0;
514 else
515 seg_buf[1] = 1 + sw->seg_in_window++;
Harald Welte3b8ba212009-01-29 12:27:58 +0000516
517 len = strlen(line_buf) + 2;
518 tlv = msgb_put(msg, TLV_GROSS_LEN(len));
519 tlv_put(tlv, NM_ATT_BS11_FILE_DATA, len, (u_int8_t *)seg_buf);
520 /* BS11 wants CR + LF in excess of the TLV length !?! */
521 tlv[1] -= 2;
522
523 /* we only now know the exact length for the OM hdr */
524 len = strlen(line_buf)+2;
525 break;
526 default:
527 /* FIXME: Other BTS types */
528 return -1;
Harald Welte4724f992009-01-18 18:01:49 +0000529 }
Harald Welte4724f992009-01-18 18:01:49 +0000530
Harald Welte4724f992009-01-18 18:01:49 +0000531 fill_om_fom_hdr(oh, len, NM_MT_LOAD_SEG, sw->obj_class,
532 sw->obj_instance[0], sw->obj_instance[1],
533 sw->obj_instance[2]);
534
535 return abis_nm_sendmsg(sw->bts, msg);
536}
537
538/* 6.2.4 / 8.3.4 Load Data End */
539static int sw_load_end(struct abis_nm_sw *sw)
540{
541 struct abis_om_hdr *oh;
542 struct msgb *msg = nm_msgb_alloc();
543 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
544
545 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
546 fill_om_fom_hdr(oh, len, NM_MT_LOAD_END, sw->obj_class,
547 sw->obj_instance[0], sw->obj_instance[1],
548 sw->obj_instance[2]);
549
550 /* FIXME: this is BS11 specific format */
551 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
552 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
553 sw->file_version);
554
555 return abis_nm_sendmsg(sw->bts, msg);
556}
Harald Welte5e4d1b32009-02-01 13:36:56 +0000557
Harald Welte52b1f982008-12-23 20:25:15 +0000558/* Activate the specified software into the BTS */
Harald Welte4724f992009-01-18 18:01:49 +0000559static int sw_activate(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +0000560{
Harald Welte4724f992009-01-18 18:01:49 +0000561 struct abis_om_hdr *oh;
562 struct msgb *msg = nm_msgb_alloc();
563 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
Harald Welte52b1f982008-12-23 20:25:15 +0000564
Harald Welte4724f992009-01-18 18:01:49 +0000565 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
566 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, sw->obj_class,
567 sw->obj_instance[0], sw->obj_instance[1],
568 sw->obj_instance[2]);
569
570 /* FIXME: this is BS11 specific format */
571 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
572 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
573 sw->file_version);
574
575 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000576}
Harald Welte4724f992009-01-18 18:01:49 +0000577
578static int sw_open_file(struct abis_nm_sw *sw, const char *fname)
579{
580 char file_id[12+1];
581 char file_version[80+1];
582 int rc;
583
584 sw->fd = open(fname, O_RDONLY);
585 if (sw->fd < 0)
586 return sw->fd;
587
588 switch (sw->bts->type) {
589 case GSM_BTS_TYPE_BS11:
590 sw->stream = fdopen(sw->fd, "r");
591 if (!sw->stream) {
592 perror("fdopen");
593 return -1;
594 }
595 /* read first line and parse file ID and VERSION */
Harald Welte3b8ba212009-01-29 12:27:58 +0000596 rc = fscanf(sw->stream, "@(#)%12s:%80s\r\n",
Harald Welte4724f992009-01-18 18:01:49 +0000597 file_id, file_version);
598 if (rc != 2) {
599 perror("parsing header line of software file");
600 return -1;
601 }
602 strcpy((char *)sw->file_id, file_id);
603 sw->file_id_len = strlen(file_id);
604 strcpy((char *)sw->file_version, file_version);
605 sw->file_version_len = strlen(file_version);
606 /* rewind to start of file */
Harald Welte3b8ba212009-01-29 12:27:58 +0000607 rewind(sw->stream);
Harald Welte4724f992009-01-18 18:01:49 +0000608 break;
609 default:
610 /* We don't know how to treat them yet */
611 close(sw->fd);
612 return -EINVAL;
613 }
614
615 return 0;
616}
617
618static void sw_close_file(struct abis_nm_sw *sw)
619{
620 switch (sw->bts->type) {
621 case GSM_BTS_TYPE_BS11:
622 fclose(sw->stream);
623 break;
624 default:
625 close(sw->fd);
626 break;
627 }
628}
629
630/* Fill the window */
631static int sw_fill_window(struct abis_nm_sw *sw)
632{
633 int rc;
634
635 while (sw->seg_in_window < sw->window_size) {
636 rc = sw_load_segment(sw);
637 if (rc < 0)
638 return rc;
Harald Welte1602ade2009-01-29 21:12:39 +0000639 if (sw->last_seg)
640 break;
Harald Welte4724f992009-01-18 18:01:49 +0000641 }
642 return 0;
643}
644
645/* callback function from abis_nm_rcvmsg() handler */
646static int abis_nm_rcvmsg_sw(struct msgb *mb)
647{
648 struct abis_om_fom_hdr *foh = msgb_l3(mb);
649 int rc = -1;
650 struct abis_nm_sw *sw = &g_sw;
651 enum sw_state old_state = sw->state;
652
Harald Welte3ffd1372009-02-01 22:15:49 +0000653 //DEBUGP(DNM, "state %u, NM MT 0x%02x\n", sw->state, foh->msg_type);
Harald Welte4724f992009-01-18 18:01:49 +0000654
655 switch (sw->state) {
656 case SW_STATE_WAIT_INITACK:
657 switch (foh->msg_type) {
658 case NM_MT_LOAD_INIT_ACK:
659 /* fill window with segments */
Harald Welte5e4d1b32009-02-01 13:36:56 +0000660 if (sw->cbfn)
661 sw->cbfn(GSM_HOOK_NM_SWLOAD,
662 NM_MT_LOAD_INIT_ACK, mb,
663 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +0000664 rc = sw_fill_window(sw);
665 sw->state = SW_STATE_WAIT_SEGACK;
666 break;
667 case NM_MT_LOAD_INIT_NACK:
Harald Welte3ffd1372009-02-01 22:15:49 +0000668 if (sw->forced) {
669 DEBUGP(DNM, "FORCED: Ignoring Software Load "
670 "Init NACK\n");
671 if (sw->cbfn)
672 sw->cbfn(GSM_HOOK_NM_SWLOAD,
673 NM_MT_LOAD_INIT_ACK, mb,
674 sw->cb_data, NULL);
675 rc = sw_fill_window(sw);
676 sw->state = SW_STATE_WAIT_SEGACK;
677 } else {
678 DEBUGP(DNM, "Software Load Init NACK\n");
679 if (sw->cbfn)
680 sw->cbfn(GSM_HOOK_NM_SWLOAD,
681 NM_MT_LOAD_INIT_NACK, mb,
682 sw->cb_data, NULL);
683 sw->state = SW_STATE_ERROR;
684 }
Harald Welte4724f992009-01-18 18:01:49 +0000685 break;
686 }
687 break;
688 case SW_STATE_WAIT_SEGACK:
689 switch (foh->msg_type) {
690 case NM_MT_LOAD_SEG_ACK:
Harald Welte3ffd1372009-02-01 22:15:49 +0000691 if (sw->cbfn)
692 sw->cbfn(GSM_HOOK_NM_SWLOAD,
693 NM_MT_LOAD_SEG_ACK, mb,
694 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +0000695 sw->seg_in_window = 0;
Harald Welte1602ade2009-01-29 21:12:39 +0000696 if (!sw->last_seg) {
697 /* fill window with more segments */
698 rc = sw_fill_window(sw);
699 sw->state = SW_STATE_WAIT_SEGACK;
700 } else {
701 /* end the transfer */
702 sw->state = SW_STATE_WAIT_ENDACK;
703 rc = sw_load_end(sw);
704 }
Harald Welte4724f992009-01-18 18:01:49 +0000705 break;
706 }
707 break;
708 case SW_STATE_WAIT_ENDACK:
709 switch (foh->msg_type) {
710 case NM_MT_LOAD_END_ACK:
711 sw_close_file(sw);
Harald Welte5e4d1b32009-02-01 13:36:56 +0000712 DEBUGP(DNM, "Software Load End (BTS %u)\n",
713 sw->bts->nr);
714 sw->state = SW_STATE_NONE;
715 if (sw->cbfn)
716 sw->cbfn(GSM_HOOK_NM_SWLOAD,
717 NM_MT_LOAD_END_ACK, mb,
718 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +0000719 break;
720 case NM_MT_LOAD_END_NACK:
Holger Freyther31338a12009-02-06 17:43:50 +0000721 if (sw->forced) {
722 DEBUGP(DNM, "FORCED: Ignoring Software Load"
723 "End NACK\n");
724 sw->state = SW_STATE_NONE;
725 if (sw->cbfn)
726 sw->cbfn(GSM_HOOK_NM_SWLOAD,
727 NM_MT_LOAD_END_ACK, mb,
728 sw->cb_data, NULL);
729 } else {
730 DEBUGP(DNM, "Software Load End NACK\n");
731 sw->state = SW_STATE_ERROR;
732 if (sw->cbfn)
733 sw->cbfn(GSM_HOOK_NM_SWLOAD,
734 NM_MT_LOAD_END_NACK, mb,
735 sw->cb_data, NULL);
736 }
Harald Welte4724f992009-01-18 18:01:49 +0000737 break;
738 }
739 case SW_STATE_WAIT_ACTACK:
740 switch (foh->msg_type) {
741 case NM_MT_ACTIVATE_SW_ACK:
742 /* we're done */
Harald Welte5e4d1b32009-02-01 13:36:56 +0000743 DEBUGP(DNM, "Activate Software DONE!\n");
Harald Welte4724f992009-01-18 18:01:49 +0000744 sw->state = SW_STATE_NONE;
745 rc = 0;
Harald Welte5e4d1b32009-02-01 13:36:56 +0000746 if (sw->cbfn)
747 sw->cbfn(GSM_HOOK_NM_SWLOAD,
748 NM_MT_ACTIVATE_SW_ACK, mb,
749 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +0000750 break;
751 case NM_MT_ACTIVATE_SW_NACK:
Harald Welte1602ade2009-01-29 21:12:39 +0000752 DEBUGP(DNM, "Activate Software NACK\n");
Harald Welte4724f992009-01-18 18:01:49 +0000753 sw->state = SW_STATE_ERROR;
Harald Welte5e4d1b32009-02-01 13:36:56 +0000754 if (sw->cbfn)
755 sw->cbfn(GSM_HOOK_NM_SWLOAD,
756 NM_MT_ACTIVATE_SW_NACK, mb,
757 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +0000758 break;
759 }
760 case SW_STATE_NONE:
761 case SW_STATE_ERROR:
762 break;
763 }
764
765 if (rc)
766 fprintf(stderr, "unexpected NM MT 0x%02x in state %u -> %u\n",
767 foh->msg_type, old_state, sw->state);
768
769 return rc;
770}
771
772/* Load the specified software into the BTS */
773int abis_nm_software_load(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +0000774 u_int8_t win_size, int forced,
775 gsm_cbfn *cbfn, void *cb_data)
Harald Welte4724f992009-01-18 18:01:49 +0000776{
777 struct abis_nm_sw *sw = &g_sw;
778 int rc;
779
Harald Welte5e4d1b32009-02-01 13:36:56 +0000780 DEBUGP(DNM, "Software Load (BTS %u, File \"%s\")\n",
781 bts->nr, fname);
782
Harald Welte4724f992009-01-18 18:01:49 +0000783 if (sw->state != SW_STATE_NONE)
784 return -EBUSY;
785
786 sw->bts = bts;
787 sw->obj_class = NM_OC_SITE_MANAGER;
788 sw->obj_instance[0] = 0xff;
789 sw->obj_instance[1] = 0xff;
790 sw->obj_instance[2] = 0xff;
791 sw->window_size = win_size;
792 sw->state = SW_STATE_WAIT_INITACK;
Harald Welte5e4d1b32009-02-01 13:36:56 +0000793 sw->cbfn = cbfn;
794 sw->cb_data = cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +0000795 sw->forced = forced;
Harald Welte4724f992009-01-18 18:01:49 +0000796
797 rc = sw_open_file(sw, fname);
798 if (rc < 0) {
799 sw->state = SW_STATE_NONE;
800 return rc;
801 }
802
803 return sw_load_init(sw);
804}
Harald Welte52b1f982008-12-23 20:25:15 +0000805
Harald Welte1602ade2009-01-29 21:12:39 +0000806int abis_nm_software_load_status(struct gsm_bts *bts)
807{
808 struct abis_nm_sw *sw = &g_sw;
809 struct stat st;
810 int rc, percent;
811
812 rc = fstat(sw->fd, &st);
813 if (rc < 0) {
814 perror("ERROR during stat");
815 return rc;
816 }
817
818 percent = (ftell(sw->stream) * 100) / st.st_size;
819 return percent;
820}
821
Harald Welte5e4d1b32009-02-01 13:36:56 +0000822/* Activate the specified software into the BTS */
823int abis_nm_software_activate(struct gsm_bts *bts, const char *fname,
824 gsm_cbfn *cbfn, void *cb_data)
825{
826 struct abis_nm_sw *sw = &g_sw;
827 int rc;
828
829 DEBUGP(DNM, "Activating Software (BTS %u, File \"%s\")\n",
830 bts->nr, fname);
831
832 if (sw->state != SW_STATE_NONE)
833 return -EBUSY;
834
835 sw->bts = bts;
836 sw->obj_class = NM_OC_SITE_MANAGER;
837 sw->obj_instance[0] = 0xff;
838 sw->obj_instance[1] = 0xff;
839 sw->obj_instance[2] = 0xff;
840 sw->state = SW_STATE_WAIT_ACTACK;
841 sw->cbfn = cbfn;
842 sw->cb_data = cb_data;
843
844 /* Open the file in order to fill some sw struct members */
845 rc = sw_open_file(sw, fname);
846 if (rc < 0) {
847 sw->state = SW_STATE_NONE;
848 return rc;
849 }
850 sw_close_file(sw);
851
852 return sw_activate(sw);
853}
854
Harald Welte8470bf22008-12-25 23:28:35 +0000855static void fill_nm_channel(struct abis_nm_channel *ch, u_int8_t bts_port,
Harald Welte52b1f982008-12-23 20:25:15 +0000856 u_int8_t ts_nr, u_int8_t subslot_nr)
857{
Harald Welteadaf08b2009-01-18 11:08:10 +0000858 ch->attrib = NM_ATT_ABIS_CHANNEL;
Harald Welte52b1f982008-12-23 20:25:15 +0000859 ch->bts_port = bts_port;
860 ch->timeslot = ts_nr;
861 ch->subslot = subslot_nr;
862}
863
864int abis_nm_establish_tei(struct gsm_bts *bts, u_int8_t trx_nr,
865 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot,
866 u_int8_t tei)
867{
868 struct abis_om_hdr *oh;
869 struct abis_nm_channel *ch;
Harald Welte702d8702008-12-26 20:25:35 +0000870 u_int8_t len = sizeof(*ch) + 2;
Harald Welte8470bf22008-12-25 23:28:35 +0000871 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000872
873 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
874 fill_om_fom_hdr(oh, len, NM_MT_ESTABLISH_TEI, NM_OC_RADIO_CARRIER,
875 bts->bts_nr, trx_nr, 0xff);
876
Harald Welte8470bf22008-12-25 23:28:35 +0000877 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte52b1f982008-12-23 20:25:15 +0000878
879 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
880 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
881
882 return abis_nm_sendmsg(bts, msg);
883}
884
885/* connect signalling of one (BTS,TRX) to a particular timeslot on the E1 */
886int abis_nm_conn_terr_sign(struct gsm_bts_trx *trx,
887 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot)
888{
Harald Welte8470bf22008-12-25 23:28:35 +0000889 struct gsm_bts *bts = trx->bts;
Harald Welte52b1f982008-12-23 20:25:15 +0000890 struct abis_om_hdr *oh;
891 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +0000892 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000893
894 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +0000895 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_SIGN,
Harald Welte52b1f982008-12-23 20:25:15 +0000896 NM_OC_RADIO_CARRIER, bts->bts_nr, trx->nr, 0xff);
897
898 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
899 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
900
901 return abis_nm_sendmsg(bts, msg);
902}
903
904#if 0
905int abis_nm_disc_terr_sign(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
906 struct abis_nm_abis_channel *chan)
907{
908}
909#endif
910
911int abis_nm_conn_terr_traf(struct gsm_bts_trx_ts *ts,
912 u_int8_t e1_port, u_int8_t e1_timeslot,
913 u_int8_t e1_subslot)
914{
915 struct gsm_bts *bts = ts->trx->bts;
916 struct abis_om_hdr *oh;
917 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +0000918 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000919
920 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
921 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_TRAF,
922 NM_OC_BASEB_TRANSC, bts->bts_nr, ts->trx->nr, ts->nr);
923
924 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
925 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
926
927 return abis_nm_sendmsg(bts, msg);
928}
929
930#if 0
931int abis_nm_disc_terr_traf(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
932 struct abis_nm_abis_channel *chan,
933 u_int8_t subchan)
934{
935}
936#endif
937
Harald Welte22af0db2009-02-14 15:41:08 +0000938/* Chapter 8.6.1 */
939int abis_nm_set_bts_attr(struct gsm_bts *bts, u_int8_t *attr, int attr_len)
940{
941 struct abis_om_hdr *oh;
942 struct msgb *msg = nm_msgb_alloc();
943 u_int8_t *cur;
944
945 DEBUGP(DNM, "Set BTS Attr (bts=%d)\n", bts->nr);
946
947 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
948 fill_om_fom_hdr(oh, attr_len, NM_MT_SET_BTS_ATTR, NM_OC_BTS, bts->nr, 0xff, 0xff);
949 cur = msgb_put(msg, attr_len);
950 memcpy(cur, attr, attr_len);
951
952 return abis_nm_sendmsg(bts, msg);
953}
954
955/* Chapter 8.6.2 */
956int abis_nm_set_radio_attr(struct gsm_bts_trx *trx, u_int8_t *attr, int attr_len)
957{
958 struct abis_om_hdr *oh;
959 struct msgb *msg = nm_msgb_alloc();
960 u_int8_t *cur;
961
962 DEBUGP(DNM, "Set TRX Attr (bts=%d,trx=%d)\n", trx->bts->nr, trx->nr);
963
964 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
965 fill_om_fom_hdr(oh, attr_len, NM_MT_SET_RADIO_ATTR, NM_OC_RADIO_CARRIER,
966 trx->bts->nr, trx->nr, 0xff);
967 cur = msgb_put(msg, attr_len);
968 memcpy(cur, attr, attr_len);
969
970 return abis_nm_sendmsg(trx->bts, msg);
971}
972
973/* Chapter 8.6.3 */
Harald Welte52b1f982008-12-23 20:25:15 +0000974int abis_nm_set_channel_attr(struct gsm_bts_trx_ts *ts, u_int8_t chan_comb)
975{
976 struct gsm_bts *bts = ts->trx->bts;
977 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +0000978 u_int16_t arfcn = htons(ts->trx->arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +0000979 u_int8_t zero = 0x00;
Harald Welte8470bf22008-12-25 23:28:35 +0000980 struct msgb *msg = nm_msgb_alloc();
Harald Welte702d8702008-12-26 20:25:35 +0000981 u_int8_t len = 4 + 2 + 2 + 2 + 2 +3;
Harald Welte52b1f982008-12-23 20:25:15 +0000982
Harald Welte22af0db2009-02-14 15:41:08 +0000983 DEBUGP(DNM, "Set Chan Attr (bts=%d,trx=%d,ts=%d)\n", bts->nr, ts->trx->nr, ts->nr);
984
Harald Welte52b1f982008-12-23 20:25:15 +0000985 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +0000986 fill_om_fom_hdr(oh, len, NM_MT_SET_CHAN_ATTR,
Harald Welte52b1f982008-12-23 20:25:15 +0000987 NM_OC_BASEB_TRANSC, bts->bts_nr,
988 ts->trx->nr, ts->nr);
989 /* FIXME: don't send ARFCN list, hopping sequence, mAIO, ...*/
990 msgb_tlv16_put(msg, NM_ATT_ARFCN_LIST, 1, &arfcn);
991 msgb_tv_put(msg, NM_ATT_CHAN_COMB, chan_comb);
992 msgb_tv_put(msg, NM_ATT_HSN, 0x00);
993 msgb_tv_put(msg, NM_ATT_MAIO, 0x00);
994 msgb_tv_put(msg, NM_ATT_TSC, 0x07); /* training sequence */
995 msgb_tlv_put(msg, 0x59, 1, &zero);
996
997 return abis_nm_sendmsg(bts, msg);
998}
999
Harald Welte34a99682009-02-13 02:41:40 +00001000int abis_nm_sw_act_req_ack(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i1,
1001 u_int8_t i2, u_int8_t i3, u_int8_t *attr, int att_len)
1002{
1003 struct abis_om_hdr *oh;
1004 struct msgb *msg = nm_msgb_alloc();
1005
1006 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1007 fill_om_fom_hdr(oh, att_len, NM_MT_SW_ACT_REQ_ACK, obj_class, i1, i2, i3);
1008 /* FIXME: don't send ARFCN list, hopping sequence, mAIO, ...*/
1009 if (attr) {
1010 u_int8_t *ptr = msgb_put(msg, att_len);
1011 memcpy(ptr, attr, att_len);
1012 }
1013
1014 return abis_nm_sendmsg(bts, msg);
1015}
1016
Harald Welte8470bf22008-12-25 23:28:35 +00001017int abis_nm_raw_msg(struct gsm_bts *bts, int len, u_int8_t *rawmsg)
Harald Welte52b1f982008-12-23 20:25:15 +00001018{
Harald Welte8470bf22008-12-25 23:28:35 +00001019 struct msgb *msg = nm_msgb_alloc();
1020 struct abis_om_hdr *oh;
Harald Welte52b1f982008-12-23 20:25:15 +00001021 u_int8_t *data;
1022
1023 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
1024 fill_om_hdr(oh, len);
1025 data = msgb_put(msg, len);
Harald Weltead384642008-12-26 10:20:07 +00001026 memcpy(data, rawmsg, len);
Harald Welte52b1f982008-12-23 20:25:15 +00001027
1028 return abis_nm_sendmsg(bts, msg);
1029}
1030
1031/* Siemens specific commands */
1032static int __simple_cmd(struct gsm_bts *bts, u_int8_t msg_type)
1033{
1034 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001035 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001036
1037 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001038 fill_om_fom_hdr(oh, 0, msg_type, NM_OC_SITE_MANAGER,
Harald Welte52b1f982008-12-23 20:25:15 +00001039 0xff, 0xff, 0xff);
1040
1041 return abis_nm_sendmsg(bts, msg);
1042}
1043
Harald Welte34a99682009-02-13 02:41:40 +00001044/* Chapter 8.9.2 */
1045int abis_nm_opstart(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1, u_int8_t i2)
1046{
1047 struct abis_om_hdr *oh;
1048 struct msgb *msg = nm_msgb_alloc();
1049
Harald Welte22af0db2009-02-14 15:41:08 +00001050 DEBUGP(DNM, "Sending OPSTART obj_class=0x%02x obj_inst=(0x%02x, 0x%02x, 0x%02x)\n",
1051 obj_class, i0, i1, i2);
Harald Welte34a99682009-02-13 02:41:40 +00001052 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1053 fill_om_fom_hdr(oh, 0, NM_MT_OPSTART, obj_class, i0, i1, i2);
1054
1055 return abis_nm_sendmsg(bts, msg);
1056}
1057
1058/* Chapter 8.8.5 */
1059int abis_nm_chg_adm_state(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0,
1060 u_int8_t i1, u_int8_t i2, u_int8_t adm_state)
1061{
1062 struct abis_om_hdr *oh;
1063 struct msgb *msg = nm_msgb_alloc();
1064
1065 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1066 fill_om_fom_hdr(oh, 2, NM_MT_CHG_ADM_STATE, obj_class, i0, i1, i2);
1067 msgb_tv_put(msg, NM_ATT_ADM_STATE, adm_state);
1068
1069 return abis_nm_sendmsg(bts, msg);
1070}
1071
1072
Harald Welte52b1f982008-12-23 20:25:15 +00001073int abis_nm_event_reports(struct gsm_bts *bts, int on)
1074{
1075 if (on == 0)
Harald Welte227d4072009-01-03 08:16:25 +00001076 return __simple_cmd(bts, NM_MT_STOP_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001077 else
Harald Welte227d4072009-01-03 08:16:25 +00001078 return __simple_cmd(bts, NM_MT_REST_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001079}
1080
Harald Welte47d88ae2009-01-04 12:02:08 +00001081/* Siemens (or BS-11) specific commands */
1082
Harald Welte3ffd1372009-02-01 22:15:49 +00001083int abis_nm_bs11_bsc_disconnect(struct gsm_bts *bts, int reconnect)
1084{
1085 if (reconnect == 0)
1086 return __simple_cmd(bts, NM_MT_BS11_DISCONNECT);
1087 else
1088 return __simple_cmd(bts, NM_MT_BS11_RECONNECT);
1089}
1090
Harald Welteb8427972009-02-05 19:27:17 +00001091int abis_nm_bs11_restart(struct gsm_bts *bts)
1092{
1093 return __simple_cmd(bts, NM_MT_BS11_RESTART);
1094}
1095
1096
Harald Welte268bb402009-02-01 19:11:56 +00001097struct bs11_date_time {
1098 u_int16_t year;
1099 u_int8_t month;
1100 u_int8_t day;
1101 u_int8_t hour;
1102 u_int8_t min;
1103 u_int8_t sec;
1104} __attribute__((packed));
1105
1106
1107void get_bs11_date_time(struct bs11_date_time *aet)
1108{
1109 time_t t;
1110 struct tm *tm;
1111
1112 t = time(NULL);
1113 tm = localtime(&t);
1114 aet->sec = tm->tm_sec;
1115 aet->min = tm->tm_min;
1116 aet->hour = tm->tm_hour;
1117 aet->day = tm->tm_mday;
1118 aet->month = tm->tm_mon;
1119 aet->year = htons(1900 + tm->tm_year);
1120}
1121
Harald Welte05188ee2009-01-18 11:39:08 +00001122int abis_nm_bs11_reset_resource(struct gsm_bts *bts)
Harald Welte52b1f982008-12-23 20:25:15 +00001123{
Harald Welte4668fda2009-01-03 08:19:29 +00001124 return __simple_cmd(bts, NM_MT_BS11_RESET_RESOURCE);
Harald Welte52b1f982008-12-23 20:25:15 +00001125}
1126
Harald Welte05188ee2009-01-18 11:39:08 +00001127int abis_nm_bs11_db_transmission(struct gsm_bts *bts, int begin)
Harald Welte52b1f982008-12-23 20:25:15 +00001128{
1129 if (begin)
Harald Welte4668fda2009-01-03 08:19:29 +00001130 return __simple_cmd(bts, NM_MT_BS11_BEGIN_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00001131 else
Harald Welte4668fda2009-01-03 08:19:29 +00001132 return __simple_cmd(bts, NM_MT_BS11_END_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00001133}
Harald Welte47d88ae2009-01-04 12:02:08 +00001134
Harald Welte05188ee2009-01-18 11:39:08 +00001135int abis_nm_bs11_create_object(struct gsm_bts *bts,
Harald Welte1bc09062009-01-18 14:17:52 +00001136 enum abis_bs11_objtype type, u_int8_t idx,
1137 u_int8_t attr_len, const u_int8_t *attr)
Harald Welte47d88ae2009-01-04 12:02:08 +00001138{
1139 struct abis_om_hdr *oh;
1140 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00001141 u_int8_t *cur;
Harald Welte47d88ae2009-01-04 12:02:08 +00001142
1143 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001144 fill_om_fom_hdr(oh, attr_len, NM_MT_BS11_CREATE_OBJ,
Harald Welte268bb402009-02-01 19:11:56 +00001145 NM_OC_BS11, type, 0, idx);
Harald Welte1bc09062009-01-18 14:17:52 +00001146 cur = msgb_put(msg, attr_len);
1147 memcpy(cur, attr, attr_len);
Harald Welte47d88ae2009-01-04 12:02:08 +00001148
1149 return abis_nm_sendmsg(bts, msg);
1150}
1151
Harald Welte05188ee2009-01-18 11:39:08 +00001152int abis_nm_bs11_create_envaBTSE(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00001153{
1154 struct abis_om_hdr *oh;
1155 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00001156 u_int8_t zero = 0x00;
Harald Welte47d88ae2009-01-04 12:02:08 +00001157
1158 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001159 fill_om_fom_hdr(oh, 3, NM_MT_BS11_CREATE_OBJ,
Harald Welte1bc09062009-01-18 14:17:52 +00001160 NM_OC_BS11_ENVABTSE, 0, idx, 0xff);
1161 msgb_tlv_put(msg, 0x99, 1, &zero);
Harald Welte47d88ae2009-01-04 12:02:08 +00001162
1163 return abis_nm_sendmsg(bts, msg);
1164}
1165
Harald Welte05188ee2009-01-18 11:39:08 +00001166int abis_nm_bs11_create_bport(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00001167{
1168 struct abis_om_hdr *oh;
1169 struct msgb *msg = nm_msgb_alloc();
1170
1171 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1172 fill_om_fom_hdr(oh, 0, NM_MT_BS11_CREATE_OBJ, NM_OC_BS11_BPORT,
1173 idx, 0, 0);
1174
1175 return abis_nm_sendmsg(bts, msg);
1176}
Harald Welte05188ee2009-01-18 11:39:08 +00001177
1178int abis_nm_bs11_set_oml_tei(struct gsm_bts *bts, u_int8_t tei)
1179{
1180 struct abis_om_hdr *oh;
1181 struct msgb *msg = nm_msgb_alloc();
Harald Welte05188ee2009-01-18 11:39:08 +00001182
1183 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001184 fill_om_fom_hdr(oh, 2, NM_MT_BS11_SET_ATTR, NM_OC_SITE_MANAGER,
Harald Welte05188ee2009-01-18 11:39:08 +00001185 0xff, 0xff, 0xff);
1186 msgb_tv_put(msg, NM_ATT_TEI, tei);
1187
1188 return abis_nm_sendmsg(bts, msg);
1189}
1190
1191/* like abis_nm_conn_terr_traf */
1192int abis_nm_bs11_conn_oml(struct gsm_bts *bts, u_int8_t e1_port,
1193 u_int8_t e1_timeslot, u_int8_t e1_subslot)
1194{
1195 struct abis_om_hdr *oh;
1196 struct abis_nm_channel *ch;
1197 struct msgb *msg = nm_msgb_alloc();
1198
1199 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte05188ee2009-01-18 11:39:08 +00001200 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_BS11_SET_ATTR,
1201 NM_OC_SITE_MANAGER, 0xff, 0xff, 0xff);
1202
1203 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1204 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1205
1206 return abis_nm_sendmsg(bts, msg);
1207}
1208
1209int abis_nm_bs11_set_trx_power(struct gsm_bts_trx *trx, u_int8_t level)
1210{
1211 struct abis_om_hdr *oh;
1212 struct msgb *msg = nm_msgb_alloc();
Harald Welte05188ee2009-01-18 11:39:08 +00001213
1214 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001215 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR,
Harald Welte05188ee2009-01-18 11:39:08 +00001216 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
1217 msgb_tlv_put(msg, NM_ATT_BS11_TXPWR, 1, &level);
1218
1219 return abis_nm_sendmsg(trx->bts, msg);
1220}
1221
Harald Welte268bb402009-02-01 19:11:56 +00001222//static const u_int8_t bs11_logon_c7[] = { 0x07, 0xd9, 0x01, 0x11, 0x0d, 0x10, 0x20 };
Harald Weltebb151312009-01-28 20:42:07 +00001223static const u_int8_t bs11_logon_c8[] = { 0x02 };
Harald Welte05188ee2009-01-18 11:39:08 +00001224static const u_int8_t bs11_logon_c9[] = "FACTORY";
1225
Harald Welte1bc09062009-01-18 14:17:52 +00001226int abis_nm_bs11_factory_logon(struct gsm_bts *bts, int on)
Harald Welte05188ee2009-01-18 11:39:08 +00001227{
1228 struct abis_om_hdr *oh;
1229 struct msgb *msg = nm_msgb_alloc();
Harald Welte268bb402009-02-01 19:11:56 +00001230 struct bs11_date_time bdt;
1231
1232 get_bs11_date_time(&bdt);
Harald Welte05188ee2009-01-18 11:39:08 +00001233
1234 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte1bc09062009-01-18 14:17:52 +00001235 if (on) {
Harald Welte268bb402009-02-01 19:11:56 +00001236 u_int8_t len = 3*2 + sizeof(bdt)
Harald Welte6f676a32009-01-18 14:27:48 +00001237 + sizeof(bs11_logon_c8) + sizeof(bs11_logon_c9);
Harald Welte043d04a2009-01-29 23:15:30 +00001238 fill_om_fom_hdr(oh, len, NM_MT_BS11_LMT_LOGON,
Harald Welte1bc09062009-01-18 14:17:52 +00001239 NM_OC_BS11_A3, 0xff, 0xff, 0xff);
Harald Welte043d04a2009-01-29 23:15:30 +00001240 msgb_tlv_put(msg, NM_ATT_BS11_LMT_LOGIN_TIME,
Harald Welte5083b0b2009-02-02 19:20:52 +00001241 sizeof(bdt), (u_int8_t *) &bdt);
Harald Welte043d04a2009-01-29 23:15:30 +00001242 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_ACC_LEV,
1243 sizeof(bs11_logon_c8), bs11_logon_c8);
1244 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_NAME,
1245 sizeof(bs11_logon_c9), bs11_logon_c9);
Harald Welte1bc09062009-01-18 14:17:52 +00001246 } else {
Harald Welte5e4d1b32009-02-01 13:36:56 +00001247 fill_om_fom_hdr(oh, 0, NM_MT_BS11_LMT_LOGOFF,
Harald Welte1bc09062009-01-18 14:17:52 +00001248 NM_OC_BS11_A3, 0xff, 0xff, 0xff);
1249 }
Harald Welte05188ee2009-01-18 11:39:08 +00001250
1251 return abis_nm_sendmsg(bts, msg);
1252}
Harald Welte1bc09062009-01-18 14:17:52 +00001253
1254int abis_nm_bs11_set_trx1_pw(struct gsm_bts *bts, const char *password)
1255{
1256 struct abis_om_hdr *oh;
1257 struct msgb *msg;
1258
1259 if (strlen(password) != 10)
1260 return -EINVAL;
1261
1262 msg = nm_msgb_alloc();
1263 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001264 fill_om_fom_hdr(oh, 2+strlen(password), NM_MT_BS11_SET_ATTR,
Harald Welte1bc09062009-01-18 14:17:52 +00001265 NM_OC_BS11, BS11_OBJ_TRX1, 0x00, 0x00);
1266 msgb_tlv_put(msg, NM_ATT_BS11_PASSWORD, 10, (const u_int8_t *)password);
1267
1268 return abis_nm_sendmsg(bts, msg);
1269}
1270
1271int abis_nm_bs11_get_state(struct gsm_bts *bts)
1272{
1273 return __simple_cmd(bts, NM_MT_BS11_GET_STATE);
1274}
Harald Welte5e4d1b32009-02-01 13:36:56 +00001275
1276/* BS11 SWL */
1277
1278struct abis_nm_bs11_sw {
1279 struct gsm_bts *bts;
1280 char swl_fname[PATH_MAX];
1281 u_int8_t win_size;
Harald Welte3ffd1372009-02-01 22:15:49 +00001282 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001283 struct llist_head file_list;
1284 gsm_cbfn *user_cb; /* specified by the user */
1285};
1286static struct abis_nm_bs11_sw _g_bs11_sw, *g_bs11_sw = &_g_bs11_sw;
1287
1288struct file_list_entry {
1289 struct llist_head list;
1290 char fname[PATH_MAX];
1291};
1292
1293struct file_list_entry *fl_dequeue(struct llist_head *queue)
1294{
1295 struct llist_head *lh;
1296
1297 if (llist_empty(queue))
1298 return NULL;
1299
1300 lh = queue->next;
1301 llist_del(lh);
1302
1303 return llist_entry(lh, struct file_list_entry, list);
1304}
1305
1306static int bs11_read_swl_file(struct abis_nm_bs11_sw *bs11_sw)
1307{
1308 char linebuf[255];
1309 struct llist_head *lh, *lh2;
1310 FILE *swl;
1311 int rc = 0;
1312
1313 swl = fopen(bs11_sw->swl_fname, "r");
1314 if (!swl)
1315 return -ENODEV;
1316
1317 /* zero the stale file list, if any */
1318 llist_for_each_safe(lh, lh2, &bs11_sw->file_list) {
1319 llist_del(lh);
1320 free(lh);
1321 }
1322
1323 while (fgets(linebuf, sizeof(linebuf), swl)) {
1324 char file_id[12+1];
1325 char file_version[80+1];
1326 struct file_list_entry *fle;
1327 static char dir[PATH_MAX];
1328
1329 if (strlen(linebuf) < 4)
1330 continue;
Harald Welte3ffd1372009-02-01 22:15:49 +00001331
Harald Welte5e4d1b32009-02-01 13:36:56 +00001332 rc = sscanf(linebuf+4, "%12s:%80s\r\n", file_id, file_version);
1333 if (rc < 0) {
1334 perror("ERR parsing SWL file");
1335 rc = -EINVAL;
1336 goto out;
1337 }
1338 if (rc < 2)
1339 continue;
1340
1341 fle = malloc(sizeof(*fle));
1342 if (!fle) {
1343 rc = -ENOMEM;
1344 goto out;
1345 }
1346 memset(fle, 0, sizeof(*fle));
1347
1348 /* construct new filename */
1349 strncpy(dir, bs11_sw->swl_fname, sizeof(dir));
1350 strncat(fle->fname, dirname(dir), sizeof(fle->fname) - 1);
1351 strcat(fle->fname, "/");
1352 strncat(fle->fname, file_id, sizeof(fle->fname) - 1 -strlen(fle->fname));
Harald Welte5e4d1b32009-02-01 13:36:56 +00001353
1354 llist_add_tail(&fle->list, &bs11_sw->file_list);
1355 }
1356
1357out:
1358 fclose(swl);
1359 return rc;
1360}
1361
1362/* bs11 swload specific callback, passed to abis_nm core swload */
1363static int bs11_swload_cbfn(unsigned int hook, unsigned int event,
1364 struct msgb *msg, void *data, void *param)
1365{
1366 struct abis_nm_bs11_sw *bs11_sw = data;
1367 struct file_list_entry *fle;
1368 int rc = 0;
1369
Harald Welte5e4d1b32009-02-01 13:36:56 +00001370 switch (event) {
1371 case NM_MT_LOAD_END_ACK:
1372 fle = fl_dequeue(&bs11_sw->file_list);
1373 if (fle) {
1374 /* start download the next file of our file list */
1375 rc = abis_nm_software_load(bs11_sw->bts, fle->fname,
1376 bs11_sw->win_size,
Harald Welte3ffd1372009-02-01 22:15:49 +00001377 bs11_sw->forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00001378 &bs11_swload_cbfn, bs11_sw);
1379 free(fle);
1380 } else {
1381 /* activate the SWL */
1382 rc = abis_nm_software_activate(bs11_sw->bts,
1383 bs11_sw->swl_fname,
1384 bs11_swload_cbfn,
1385 bs11_sw);
1386 }
1387 break;
Harald Welte3ffd1372009-02-01 22:15:49 +00001388 case NM_MT_LOAD_SEG_ACK:
Harald Welte5e4d1b32009-02-01 13:36:56 +00001389 case NM_MT_LOAD_END_NACK:
1390 case NM_MT_LOAD_INIT_ACK:
1391 case NM_MT_LOAD_INIT_NACK:
1392 case NM_MT_ACTIVATE_SW_NACK:
1393 case NM_MT_ACTIVATE_SW_ACK:
1394 default:
1395 /* fallthrough to the user callback */
Harald Welte97ed1e72009-02-06 13:38:02 +00001396 if (bs11_sw->user_cb)
1397 rc = bs11_sw->user_cb(hook, event, msg, NULL, NULL);
Harald Welte5e4d1b32009-02-01 13:36:56 +00001398 break;
1399 }
1400
1401 return rc;
1402}
1403
1404/* Siemens provides a SWL file that is a mere listing of all the other
1405 * files that are part of a software release. We need to upload first
1406 * the list file, and then each file that is listed in the list file */
1407int abis_nm_bs11_load_swl(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00001408 u_int8_t win_size, int forced, gsm_cbfn *cbfn)
Harald Welte5e4d1b32009-02-01 13:36:56 +00001409{
1410 struct abis_nm_bs11_sw *bs11_sw = g_bs11_sw;
1411 struct file_list_entry *fle;
1412 int rc = 0;
1413
1414 INIT_LLIST_HEAD(&bs11_sw->file_list);
1415 bs11_sw->bts = bts;
1416 bs11_sw->win_size = win_size;
1417 bs11_sw->user_cb = cbfn;
Harald Welte3ffd1372009-02-01 22:15:49 +00001418 bs11_sw->forced = forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001419
1420 strncpy(bs11_sw->swl_fname, fname, sizeof(bs11_sw->swl_fname));
1421 rc = bs11_read_swl_file(bs11_sw);
1422 if (rc < 0)
1423 return rc;
1424
1425 /* dequeue next item in file list */
1426 fle = fl_dequeue(&bs11_sw->file_list);
1427 if (!fle)
1428 return -EINVAL;
1429
1430 /* start download the next file of our file list */
Harald Welte3ffd1372009-02-01 22:15:49 +00001431 rc = abis_nm_software_load(bts, fle->fname, win_size, forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00001432 bs11_swload_cbfn, bs11_sw);
1433 free(fle);
1434 return rc;
1435}
1436
Harald Welte5083b0b2009-02-02 19:20:52 +00001437#if 0
Harald Welte5e4d1b32009-02-01 13:36:56 +00001438static u_int8_t req_attr_btse[] = {
1439 NM_ATT_ADM_STATE, NM_ATT_BS11_LMT_LOGON_SESSION,
1440 NM_ATT_BS11_LMT_LOGIN_TIME, NM_ATT_BS11_LMT_USER_ACC_LEV,
1441 NM_ATT_BS11_LMT_USER_NAME,
1442
1443 0xaf, NM_ATT_BS11_RX_OFFSET, NM_ATT_BS11_VENDOR_NAME,
1444
1445 NM_ATT_BS11_SW_LOAD_INTENDED, NM_ATT_BS11_SW_LOAD_SAFETY,
1446
1447 NM_ATT_BS11_SW_LOAD_STORED };
1448
1449static u_int8_t req_attr_btsm[] = {
1450 NM_ATT_ABIS_CHANNEL, NM_ATT_TEI, NM_ATT_BS11_ABIS_EXT_TIME,
1451 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xce, NM_ATT_FILE_ID,
1452 NM_ATT_FILE_VERSION, NM_ATT_OPER_STATE, 0xe8, NM_ATT_BS11_ALL_TEST_CATG,
1453 NM_ATT_SW_DESCR, NM_ATT_GET_ARI };
Harald Welte5083b0b2009-02-02 19:20:52 +00001454#endif
Harald Welte5e4d1b32009-02-01 13:36:56 +00001455
1456static u_int8_t req_attr[] = {
1457 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xa8, NM_ATT_OPER_STATE,
1458 0xd5, 0xa1, NM_ATT_BS11_ESN_FW_CODE_NO, NM_ATT_BS11_ESN_HW_CODE_NO,
1459 0x42, NM_ATT_BS11_ESN_PCB_SERIAL };
1460
1461int abis_nm_bs11_get_serno(struct gsm_bts *bts)
1462{
1463 struct abis_om_hdr *oh;
1464 struct msgb *msg = nm_msgb_alloc();
1465
1466 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1467 /* SiemensHW CCTRL object */
1468 fill_om_fom_hdr(oh, 2+sizeof(req_attr), NM_MT_GET_ATTR, NM_OC_BS11,
1469 0x03, 0x00, 0x00);
1470 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(req_attr), req_attr);
1471
1472 return abis_nm_sendmsg(bts, msg);
1473}
Harald Welte268bb402009-02-01 19:11:56 +00001474
1475int abis_nm_bs11_set_ext_time(struct gsm_bts *bts)
1476{
1477 struct abis_om_hdr *oh;
1478 struct msgb *msg = nm_msgb_alloc();
1479 struct bs11_date_time aet;
1480
1481 get_bs11_date_time(&aet);
1482 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1483 /* SiemensHW CCTRL object */
1484 fill_om_fom_hdr(oh, 2+sizeof(aet), NM_MT_BS11_SET_ATTR, NM_OC_SITE_MANAGER,
1485 0xff, 0xff, 0xff);
Harald Welte5083b0b2009-02-02 19:20:52 +00001486 msgb_tlv_put(msg, NM_ATT_BS11_ABIS_EXT_TIME, sizeof(aet), (u_int8_t *) &aet);
Harald Welte268bb402009-02-01 19:11:56 +00001487
1488 return abis_nm_sendmsg(bts, msg);
1489}