blob: e3346a6f44a2a9c92df4b4016363990053191799 [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 Weltee0590df2009-02-15 03:34:15 +000077static const enum abis_nm_msgtype nacks[] = {
78 NM_MT_LOAD_INIT_NACK,
79 NM_MT_LOAD_END_NACK,
80 NM_MT_SW_ACT_REQ_NACK,
81 NM_MT_ACTIVATE_SW_NACK,
82 NM_MT_ESTABLISH_TEI_NACK,
83 NM_MT_CONN_TERR_SIGN_NACK,
84 NM_MT_DISC_TERR_SIGN_NACK,
85 NM_MT_CONN_TERR_TRAF_NACK,
86 NM_MT_DISC_TERR_TRAF_NACK,
87 NM_MT_CONN_MDROP_LINK_NACK,
88 NM_MT_DISC_MDROP_LINK_NACK,
89 NM_MT_SET_BTS_ATTR_NACK,
90 NM_MT_SET_RADIO_ATTR_NACK,
91 NM_MT_SET_CHAN_ATTR_NACK,
92 NM_MT_PERF_TEST_NACK,
93 NM_MT_SEND_TEST_REP_NACK,
94 NM_MT_STOP_TEST_NACK,
95 NM_MT_STOP_EVENT_REP_NACK,
96 NM_MT_REST_EVENT_REP_NACK,
97 NM_MT_CHG_ADM_STATE_NACK,
98 NM_MT_CHG_ADM_STATE_REQ_NACK,
99 NM_MT_REP_OUTST_ALARMS_NACK,
100 NM_MT_CHANGEOVER_NACK,
101 NM_MT_OPSTART_NACK,
102 NM_MT_REINIT_NACK,
103 NM_MT_SET_SITE_OUT_NACK,
104 NM_MT_CHG_HW_CONF_NACK,
105 NM_MT_GET_ATTR_NACK,
106 NM_MT_SET_ALARM_THRES_NACK,
107 NM_MT_BS11_BEGIN_DB_TX_NACK,
108 NM_MT_BS11_END_DB_TX_NACK,
109 NM_MT_BS11_CREATE_OBJ_NACK,
110 NM_MT_BS11_DELETE_OBJ_NACK,
111};
Harald Welte52b1f982008-12-23 20:25:15 +0000112/* Attributes that the BSC can set, not only get, according to Section 9.4 */
113static const enum abis_nm_attr nm_att_settable[] = {
114 NM_ATT_ADD_INFO,
115 NM_ATT_ADD_TEXT,
116 NM_ATT_DEST,
117 NM_ATT_EVENT_TYPE,
118 NM_ATT_FILE_DATA,
119 NM_ATT_GET_ARI,
120 NM_ATT_HW_CONF_CHG,
121 NM_ATT_LIST_REQ_ATTR,
122 NM_ATT_MDROP_LINK,
123 NM_ATT_MDROP_NEXT,
124 NM_ATT_NACK_CAUSES,
125 NM_ATT_OUTST_ALARM,
126 NM_ATT_PHYS_CONF,
127 NM_ATT_PROB_CAUSE,
128 NM_ATT_RAD_SUBC,
129 NM_ATT_SOURCE,
130 NM_ATT_SPEC_PROB,
131 NM_ATT_START_TIME,
132 NM_ATT_TEST_DUR,
133 NM_ATT_TEST_NO,
134 NM_ATT_TEST_REPORT,
135 NM_ATT_WINDOW_SIZE,
136 NM_ATT_SEVERITY,
137 NM_ATT_MEAS_RES,
138 NM_ATT_MEAS_TYPE,
139};
140
Harald Weltee0590df2009-02-15 03:34:15 +0000141static const struct tlv_definition nm_att_tlvdef = {
142 .def = {
143 [NM_ATT_ABIS_CHANNEL] = { TLV_TYPE_FIXED, 3 },
144 [NM_ATT_ADD_INFO] = { TLV_TYPE_TL16V },
145 [NM_ATT_ADD_TEXT] = { TLV_TYPE_TL16V },
146 [NM_ATT_ADM_STATE] = { TLV_TYPE_TV },
147 [NM_ATT_ARFCN_LIST]= { TLV_TYPE_TL16V },
148 [NM_ATT_AUTON_REPORT] = { TLV_TYPE_TV },
149 [NM_ATT_AVAIL_STATUS] = { TLV_TYPE_TL16V },
150 [NM_ATT_BCCH_ARFCN] = { TLV_TYPE_FIXED, 2 },
151 [NM_ATT_BSIC] = { TLV_TYPE_TV },
152 [NM_ATT_BTS_AIR_TIMER] = { TLV_TYPE_TV },
153 [NM_ATT_CCCH_L_I_P] = { TLV_TYPE_TV },
154 [NM_ATT_CCCH_L_T] = { TLV_TYPE_TV },
155 [NM_ATT_CHAN_COMB] = { TLV_TYPE_TV },
156 [NM_ATT_CONN_FAIL_CRIT] = { TLV_TYPE_TL16V },
157 [NM_ATT_DEST] = { TLV_TYPE_TL16V },
158 [NM_ATT_EVENT_TYPE] = { TLV_TYPE_TV },
159 [NM_ATT_FILE_DATA] = { TLV_TYPE_TL16V },
160 [NM_ATT_FILE_ID] = { TLV_TYPE_TL16V },
161 [NM_ATT_FILE_VERSION] = { TLV_TYPE_TL16V },
162 [NM_ATT_GSM_TIME] = { TLV_TYPE_FIXED, 2 },
163 [NM_ATT_HSN] = { TLV_TYPE_TV },
164 [NM_ATT_HW_CONFIG] = { TLV_TYPE_TL16V },
165 [NM_ATT_HW_DESC] = { TLV_TYPE_TL16V },
166 [NM_ATT_INTAVE_PARAM] = { TLV_TYPE_TV },
167 [NM_ATT_INTERF_BOUND] = { TLV_TYPE_FIXED, 6 },
168 [NM_ATT_LIST_REQ_ATTR] = { TLV_TYPE_TL16V },
169 [NM_ATT_MAIO] = { TLV_TYPE_TV },
170 [NM_ATT_MANUF_STATE] = { TLV_TYPE_TV },
171 [NM_ATT_MANUF_THRESH] = { TLV_TYPE_TL16V },
172 [NM_ATT_MANUF_ID] = { TLV_TYPE_TL16V },
173 [NM_ATT_MAX_TA] = { TLV_TYPE_TV },
174 [NM_ATT_MDROP_LINK] = { TLV_TYPE_FIXED, 2 },
175 [NM_ATT_MDROP_NEXT] = { TLV_TYPE_FIXED, 2 },
176 [NM_ATT_NACK_CAUSES] = { TLV_TYPE_TV },
177 [NM_ATT_NY1] = { TLV_TYPE_TV },
178 [NM_ATT_OPER_STATE] = { TLV_TYPE_TV },
179 [NM_ATT_OVERL_PERIOD] = { TLV_TYPE_TL16V },
180 [NM_ATT_PHYS_CONF] = { TLV_TYPE_TL16V },
181 [NM_ATT_POWER_CLASS] = { TLV_TYPE_TV },
182 [NM_ATT_POWER_THRESH] = { TLV_TYPE_FIXED, 3 },
183 [NM_ATT_PROB_CAUSE] = { TLV_TYPE_FIXED, 3 },
184 [NM_ATT_RACH_B_THRESH] = { TLV_TYPE_TV },
185 [NM_ATT_LDAVG_SLOTS] = { TLV_TYPE_FIXED, 2 },
186 [NM_ATT_RAD_SUBC] = { TLV_TYPE_TV },
187 [NM_ATT_RF_MAXPOWR_R] = { TLV_TYPE_TV },
188 [NM_ATT_SITE_INPUTS] = { TLV_TYPE_TL16V },
189 [NM_ATT_SITE_OUTPUTS] = { TLV_TYPE_TL16V },
190 [NM_ATT_SOURCE] = { TLV_TYPE_TL16V },
191 [NM_ATT_SPEC_PROB] = { TLV_TYPE_TV },
192 [NM_ATT_START_TIME] = { TLV_TYPE_FIXED, 2 },
193 [NM_ATT_T200] = { TLV_TYPE_FIXED, 7 },
194 [NM_ATT_TEI] = { TLV_TYPE_TV },
195 [NM_ATT_TEST_DUR] = { TLV_TYPE_FIXED, 2 },
196 [NM_ATT_TEST_NO] = { TLV_TYPE_TV },
197 [NM_ATT_TEST_REPORT] = { TLV_TYPE_TL16V },
198 [NM_ATT_VSWR_THRESH] = { TLV_TYPE_FIXED, 2 },
199 [NM_ATT_WINDOW_SIZE] = { TLV_TYPE_TV },
200 [NM_ATT_TSC] = { TLV_TYPE_TV },
201 [NM_ATT_SW_CONFIG] = { TLV_TYPE_TL16V },
202 [NM_ATT_SEVERITY] = { TLV_TYPE_TV },
203 [NM_ATT_GET_ARI] = { TLV_TYPE_TL16V },
204 [NM_ATT_HW_CONF_CHG] = { TLV_TYPE_TL16V },
205 [NM_ATT_OUTST_ALARM] = { TLV_TYPE_TV },
206 [NM_ATT_FILE_DATA] = { TLV_TYPE_TL16V },
207 [NM_ATT_MEAS_RES] = { TLV_TYPE_TL16V },
208 /* BS11 specifics */
209 [NM_ATT_BS11_PASSWORD] = { TLV_TYPE_TLV },
210 [NM_ATT_BS11_TXPWR] = { TLV_TYPE_TLV },
211 [NM_ATT_BS11_RSSI_OFFS] = { TLV_TYPE_TLV },
212 [NM_ATT_BS11_LINE_CFG] = { TLV_TYPE_TV },
213 [NM_ATT_BS11_L1_PROT_TYPE] = { TLV_TYPE_TV },
214 [NM_ATT_BS11_BIT_ERR_THESH] = { TLV_TYPE_FIXED, 2 },
215 [NM_ATT_BS11_DIVERSITY] = { TLV_TYPE_TLV },
216 [NM_ATT_BS11_LMT_LOGIN_TIME] = { TLV_TYPE_TLV },
217 [NM_ATT_BS11_LMT_USER_ACC_LEV] ={ TLV_TYPE_TLV },
218 [NM_ATT_BS11_LMT_USER_NAME] = { TLV_TYPE_TLV },
219 },
220};
221#define nm_tlv_parse(dec, buf, len) tlv_parse(dec, &nm_att_tlvdef, buf, len)
222
Harald Welte52b1f982008-12-23 20:25:15 +0000223static int is_in_arr(enum abis_nm_msgtype mt, const enum abis_nm_msgtype *arr, int size)
224{
225 int i;
226
227 for (i = 0; i < size; i++) {
228 if (arr[i] == mt)
229 return 1;
230 }
231
232 return 0;
233}
234
Holger Freytherca362a62009-01-04 21:05:01 +0000235#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000236/* is this msgtype the usual ACK/NACK type ? */
237static int is_ack_nack(enum abis_nm_msgtype mt)
238{
239 return !is_in_arr(mt, no_ack_nack, ARRAY_SIZE(no_ack_nack));
240}
Holger Freytherca362a62009-01-04 21:05:01 +0000241#endif
Harald Welte52b1f982008-12-23 20:25:15 +0000242
243/* is this msgtype a report ? */
244static int is_report(enum abis_nm_msgtype mt)
245{
Harald Welte8470bf22008-12-25 23:28:35 +0000246 return is_in_arr(mt, reports, ARRAY_SIZE(reports));
Harald Welte52b1f982008-12-23 20:25:15 +0000247}
248
249#define MT_ACK(x) (x+1)
250#define MT_NACK(x) (x+2)
251
252static void fill_om_hdr(struct abis_om_hdr *oh, u_int8_t len)
253{
254 oh->mdisc = ABIS_OM_MDISC_FOM;
255 oh->placement = ABIS_OM_PLACEMENT_ONLY;
256 oh->sequence = 0;
257 oh->length = len;
258}
259
260static void fill_om_fom_hdr(struct abis_om_hdr *oh, u_int8_t len,
261 u_int8_t msg_type, u_int8_t obj_class,
262 u_int8_t bts_nr, u_int8_t trx_nr, u_int8_t ts_nr)
263{
264 struct abis_om_fom_hdr *foh =
265 (struct abis_om_fom_hdr *) oh->data;
266
Harald Welte702d8702008-12-26 20:25:35 +0000267 fill_om_hdr(oh, len+sizeof(*foh));
Harald Welte52b1f982008-12-23 20:25:15 +0000268 foh->msg_type = msg_type;
269 foh->obj_class = obj_class;
270 foh->obj_inst.bts_nr = bts_nr;
271 foh->obj_inst.trx_nr = trx_nr;
272 foh->obj_inst.ts_nr = ts_nr;
273}
274
Harald Welte8470bf22008-12-25 23:28:35 +0000275static struct msgb *nm_msgb_alloc(void)
276{
277 return msgb_alloc_headroom(OM_ALLOC_SIZE, OM_HEADROOM_SIZE);
278}
279
Harald Welte52b1f982008-12-23 20:25:15 +0000280/* Send a OML NM Message from BSC to BTS */
281int abis_nm_sendmsg(struct gsm_bts *bts, struct msgb *msg)
282{
Holger Freyther59639e82009-02-09 23:09:55 +0000283 msg->trx = bts->c0;
284
Harald Weltead384642008-12-26 10:20:07 +0000285 return _abis_nm_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000286}
287
Harald Welte4724f992009-01-18 18:01:49 +0000288static int abis_nm_rcvmsg_sw(struct msgb *mb);
289
Harald Welte34a99682009-02-13 02:41:40 +0000290const char *oc_names[] = {
291 [NM_OC_SITE_MANAGER] = "SITE MANAGER",
292 [NM_OC_BTS] = "BTS",
293 [NM_OC_RADIO_CARRIER] = "RADIO CARRIER",
294 [NM_OC_BASEB_TRANSC] = "BASEBAND TRANSCEIVER",
295 [NM_OC_CHANNEL] = "CHANNEL",
296};
297
298static const char *obj_class_name(u_int8_t oc)
299{
300 if (oc >= ARRAY_SIZE(oc_names))
301 return "UNKNOWN";
302 return oc_names[oc];
303}
304
305static const char *opstate_name(u_int8_t os)
306{
307 switch (os) {
308 case 1:
309 return "Disabled";
310 case 2:
311 return "Enabled";
312 case 0xff:
313 return "NULL";
314 default:
315 return "RFU";
316 }
317}
318
Harald Weltee0590df2009-02-15 03:34:15 +0000319/* Chapter 9.4.7 */
320const char *avail_names[] = {
321 "In test",
322 "Failed",
323 "Power off",
324 "Off line",
325 "<not used>",
326 "Dependency",
327 "Degraded",
328 "Not installed",
329};
330
331static const char *avail_name(u_int8_t avail)
332{
333 if (avail >= ARRAY_SIZE(avail_names))
334 return "UNKNOWN";
335 return avail_names[avail];
336}
337
338
339/* obtain the gsm_nm_state data structure for a given object instance */
340static struct gsm_nm_state *
341objclass2nmstate(struct gsm_bts *bts, u_int8_t obj_class,
342 struct abis_om_obj_inst *obj_inst)
343{
344 struct gsm_bts_trx *trx;
345 struct gsm_nm_state *nm_state = NULL;
346
347 switch (obj_class) {
348 case NM_OC_BTS:
349 nm_state = &bts->nm_state;
350 break;
351 case NM_OC_RADIO_CARRIER:
352 if (obj_inst->trx_nr >= bts->num_trx)
353 return NULL;
354 trx = &bts->trx[obj_inst->trx_nr];
355 nm_state = &trx->nm_state;
356 break;
357 case NM_OC_BASEB_TRANSC:
358 if (obj_inst->trx_nr >= bts->num_trx)
359 return NULL;
360 trx = &bts->trx[obj_inst->trx_nr];
361 nm_state = &trx->bb_transc.nm_state;
362 break;
363 case NM_OC_CHANNEL:
364 if (obj_inst->trx_nr > bts->num_trx)
365 return NULL;
366 trx = &bts->trx[obj_inst->trx_nr];
367 if (obj_inst->ts_nr >= TRX_NR_TS)
368 return NULL;
369 nm_state = &trx->ts[obj_inst->ts_nr].nm_state;
370 break;
371 case NM_OC_SITE_MANAGER:
372 nm_state = &bts->site_mgr.nm_state;
373 break;
374 }
375 return nm_state;
376}
377
378/* obtain the in-memory data structure of a given object instance */
379static void *
380objclass2obj(struct gsm_bts *bts, u_int8_t obj_class,
381 struct abis_om_obj_inst *obj_inst)
382{
383 struct gsm_bts_trx *trx;
384 void *obj = NULL;
385
386 switch (obj_class) {
387 case NM_OC_BTS:
388 obj = bts;
389 break;
390 case NM_OC_RADIO_CARRIER:
391 if (obj_inst->trx_nr >= bts->num_trx)
392 return NULL;
393 trx = &bts->trx[obj_inst->trx_nr];
394 obj = trx;
395 break;
396 case NM_OC_BASEB_TRANSC:
397 if (obj_inst->trx_nr >= bts->num_trx)
398 return NULL;
399 trx = &bts->trx[obj_inst->trx_nr];
400 obj = &trx->bb_transc;
401 break;
402 case NM_OC_CHANNEL:
403 if (obj_inst->trx_nr > bts->num_trx)
404 return NULL;
405 trx = &bts->trx[obj_inst->trx_nr];
406 if (obj_inst->ts_nr >= TRX_NR_TS)
407 return NULL;
408 obj = &trx->ts[obj_inst->ts_nr];
409 break;
410 case NM_OC_SITE_MANAGER:
411 obj = &bts->site_mgr;
412 break;
413 }
414 return obj;
415}
416
417/* Update the administrative state of a given object in our in-memory data
418 * structures and send an event to the higher layer */
419static int update_admstate(struct gsm_bts *bts, u_int8_t obj_class,
420 struct abis_om_obj_inst *obj_inst, u_int8_t adm_state)
421{
422 struct gsm_nm_state *nm_state;
423 void *obj;
424 int rc;
425
426 nm_state = objclass2nmstate(bts, obj_class, obj_inst);
427 obj = objclass2obj(bts, obj_class, obj_inst);
428 rc = nm_state_event(EVT_STATECHG_ADM, obj_class, obj, nm_state, adm_state);
429 if (nm_state)
430 nm_state->administrative = adm_state;
431
432 return rc;
433}
434
Harald Welte97ed1e72009-02-06 13:38:02 +0000435static int abis_nm_rx_statechg_rep(struct msgb *mb)
436{
Harald Weltee0590df2009-02-15 03:34:15 +0000437 struct abis_om_hdr *oh = msgb_l2(mb);
Harald Welte97ed1e72009-02-06 13:38:02 +0000438 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Harald Welte22af0db2009-02-14 15:41:08 +0000439 struct gsm_bts *bts = mb->trx->bts;
Harald Weltee0590df2009-02-15 03:34:15 +0000440 struct tlv_parsed tp;
441 struct gsm_nm_state *nm_state, new_state;
442 int rc;
443
Harald Welte34a99682009-02-13 02:41:40 +0000444 DEBUGP(DNM, "STATE CHG: OC=%s(%02x) INST=(%02x,%02x,%02x) ",
445 obj_class_name(foh->obj_class), foh->obj_class,
446 foh->obj_inst.bts_nr, foh->obj_inst.trx_nr,
Harald Welte97ed1e72009-02-06 13:38:02 +0000447 foh->obj_inst.ts_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000448
449 nm_state = objclass2nmstate(bts, foh->obj_class, &foh->obj_inst);
450 if (!nm_state) {
451 DEBUGPC(DNM, "\n");
452 return -EINVAL;
Harald Welte22af0db2009-02-14 15:41:08 +0000453 }
Harald Weltee0590df2009-02-15 03:34:15 +0000454
455 new_state = *nm_state;
456
457 nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
458 if (TLVP_PRESENT(&tp, NM_ATT_OPER_STATE)) {
459 new_state.operational = *TLVP_VAL(&tp, NM_ATT_OPER_STATE);
460 DEBUGPC(DNM, "OP_STATE=%s ", opstate_name(new_state.operational));
461 }
462 if (TLVP_PRESENT(&tp, NM_ATT_AVAIL_STATUS)) {
463 new_state.availability = *TLVP_VAL(&tp, NM_ATT_AVAIL_STATUS);
464 DEBUGPC(DNM, "AVAIL=%s(%02x) ", avail_name(new_state.availability),
465 new_state.availability);
466 }
467 if (TLVP_PRESENT(&tp, NM_ATT_ADM_STATE)) {
468 new_state.administrative = *TLVP_VAL(&tp, NM_ATT_ADM_STATE);
469 DEBUGPC(DNM, "ADM=%02x ", new_state.administrative);
Harald Welte97ed1e72009-02-06 13:38:02 +0000470 }
471 DEBUGPC(DNM, "\n");
Harald Weltee0590df2009-02-15 03:34:15 +0000472
473 if (memcmp(&new_state, nm_state, sizeof(new_state))) {
474 /* Update the operational state of a given object in our in-memory data
475 * structures and send an event to the higher layer */
476 void *obj = objclass2obj(bts, foh->obj_class, &foh->obj_inst);
477 rc = nm_state_event(EVT_STATECHG_OPER, foh->obj_class, obj, nm_state, &new_state);
478 *nm_state = new_state;
479 }
480#if 0
Harald Welte22af0db2009-02-14 15:41:08 +0000481 if (op_state == 1) {
482 /* try to enable objects that are disabled */
483 abis_nm_opstart(bts, foh->obj_class,
484 foh->obj_inst.bts_nr,
485 foh->obj_inst.trx_nr,
486 foh->obj_inst.ts_nr);
487 }
Harald Weltee0590df2009-02-15 03:34:15 +0000488#endif
Harald Welte97ed1e72009-02-06 13:38:02 +0000489 return 0;
490}
491
492static int abis_nm_rcvmsg_report(struct msgb *mb)
493{
494 struct abis_om_fom_hdr *foh = msgb_l3(mb);
495 u_int8_t mt = foh->msg_type;
496
497 //nmh->cfg->report_cb(mb, foh);
498
499 switch (mt) {
500 case NM_MT_STATECHG_EVENT_REP:
501 return abis_nm_rx_statechg_rep(mb);
502 break;
Harald Welte34a99682009-02-13 02:41:40 +0000503 case NM_MT_SW_ACTIVATED_REP:
504 DEBUGP(DNM, "Software Activated Report\n");
505 break;
Harald Weltee0590df2009-02-15 03:34:15 +0000506 case NM_MT_FAILURE_EVENT_REP:
507 DEBUGP(DNM, "Failure Event Report\n");
508 break;
509 default:
510 DEBUGP(DNM, "reporting NM MT 0x%02x\n", mt);
511 break;
512
Harald Welte97ed1e72009-02-06 13:38:02 +0000513 };
514
Harald Welte97ed1e72009-02-06 13:38:02 +0000515 return 0;
516}
517
Harald Welte34a99682009-02-13 02:41:40 +0000518/* Activate the specified software into the BTS */
519static int ipacc_sw_activate(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1,
520 u_int8_t i2, u_int8_t *sw_desc, u_int8_t swdesc_len)
521{
522 struct abis_om_hdr *oh;
523 struct msgb *msg = nm_msgb_alloc();
524 u_int8_t len = swdesc_len;
525 u_int8_t *trailer;
526
527 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
528 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, obj_class, i0, i1, i2);
529
530 trailer = msgb_put(msg, swdesc_len);
531 memcpy(trailer, sw_desc, swdesc_len);
532
533 return abis_nm_sendmsg(bts, msg);
534}
535
536static int abis_nm_rx_sw_act_req(struct msgb *mb)
537{
538 struct abis_om_hdr *oh = msgb_l2(mb);
539 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Harald Welte5c1e4582009-02-15 11:57:29 +0000540 int nack = 0;
Harald Welte34a99682009-02-13 02:41:40 +0000541 int ret;
542
Harald Welte5c1e4582009-02-15 11:57:29 +0000543 DEBUGP(DNM, "Software Activate Request ");
Harald Welte34a99682009-02-13 02:41:40 +0000544
Harald Welte5c1e4582009-02-15 11:57:29 +0000545 if (foh->obj_class >= 0xf0 && foh->obj_class <= 0xf3) {
546 DEBUGPC(DNM, "NACKing for GPRS obj_class 0x%02x\n", foh->obj_class);
547 nack = 1;
548 } else
549 DEBUGPC(DNM, "ACKing and Activating\n");
550
551 ret = abis_nm_sw_act_req_ack(mb->trx->bts, foh->obj_class,
Harald Welte34a99682009-02-13 02:41:40 +0000552 foh->obj_inst.bts_nr,
553 foh->obj_inst.trx_nr,
Harald Welte5c1e4582009-02-15 11:57:29 +0000554 foh->obj_inst.ts_nr, nack,
Harald Welte34a99682009-02-13 02:41:40 +0000555 foh->data, oh->length-sizeof(*foh));
556
Harald Welte5c1e4582009-02-15 11:57:29 +0000557 if (nack)
558 return ret;
559
Harald Welte34a99682009-02-13 02:41:40 +0000560 /* FIXME: properly parse attributes */
561 return ipacc_sw_activate(mb->trx->bts, foh->obj_class,
562 foh->obj_inst.bts_nr,
563 foh->obj_inst.trx_nr,
564 foh->obj_inst.ts_nr,
565 foh->data + oh->length-sizeof(*foh)-22, 22);
566}
567
Harald Weltee0590df2009-02-15 03:34:15 +0000568/* Receive a CHANGE_ADM_STATE_ACK, parse the TLV and update local state */
569static int abis_nm_rx_chg_adm_state_ack(struct msgb *mb)
570{
571 struct abis_om_hdr *oh = msgb_l2(mb);
572 struct abis_om_fom_hdr *foh = msgb_l3(mb);
573 struct tlv_parsed tp;
574 u_int8_t adm_state;
575
576 nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
577 if (!TLVP_PRESENT(&tp, NM_ATT_ADM_STATE))
578 return -EINVAL;
579
580 adm_state = *TLVP_VAL(&tp, NM_ATT_ADM_STATE);
581
582 return update_admstate(mb->trx->bts, foh->obj_class, &foh->obj_inst, adm_state);
583}
584
Harald Welte52b1f982008-12-23 20:25:15 +0000585/* Receive a OML NM Message from BTS */
Harald Welte8470bf22008-12-25 23:28:35 +0000586static int abis_nm_rcvmsg_fom(struct msgb *mb)
Harald Welte52b1f982008-12-23 20:25:15 +0000587{
588 struct abis_om_fom_hdr *foh = msgb_l3(mb);
589 u_int8_t mt = foh->msg_type;
590
591 /* check for unsolicited message */
Harald Welte97ed1e72009-02-06 13:38:02 +0000592 if (is_report(mt))
593 return abis_nm_rcvmsg_report(mb);
Harald Welte52b1f982008-12-23 20:25:15 +0000594
Harald Welte4724f992009-01-18 18:01:49 +0000595 if (is_in_arr(mt, sw_load_msgs, ARRAY_SIZE(sw_load_msgs)))
596 return abis_nm_rcvmsg_sw(mb);
597
Harald Weltee0590df2009-02-15 03:34:15 +0000598 if (is_in_arr(mt, nacks, ARRAY_SIZE(nacks)))
599 DEBUGP(DNM, "NACK 0x%02x\n", mt);
Harald Weltead384642008-12-26 10:20:07 +0000600#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000601 /* check if last message is to be acked */
602 if (is_ack_nack(nmh->last_msgtype)) {
603 if (mt == MT_ACK(nmh->last_msgtype)) {
604 fprintf(stderr, "received ACK (0x%x)\n",
605 foh->msg_type);
606 /* we got our ACK, continue sending the next msg */
607 } else if (mt == MT_NACK(nmh->last_msgtype)) {
608 /* we got a NACK, signal this to the caller */
609 fprintf(stderr, "received NACK (0x%x)\n",
610 foh->msg_type);
611 /* FIXME: somehow signal this to the caller */
612 } else {
613 /* really strange things happen */
614 return -EINVAL;
615 }
616 }
Harald Weltead384642008-12-26 10:20:07 +0000617#endif
618
Harald Welte97ed1e72009-02-06 13:38:02 +0000619 switch (mt) {
Harald Weltee0590df2009-02-15 03:34:15 +0000620 case NM_MT_CHG_ADM_STATE_ACK:
621 return abis_nm_rx_chg_adm_state_ack(mb);
622 break;
Harald Welte34a99682009-02-13 02:41:40 +0000623 case NM_MT_SW_ACT_REQ:
624 return abis_nm_rx_sw_act_req(mb);
625 break;
Harald Welte97ed1e72009-02-06 13:38:02 +0000626 case NM_MT_BS11_LMT_SESSION:
627 DEBUGP(DNM, "LMT Event: \n");
628 break;
629 }
630
Harald Weltead384642008-12-26 10:20:07 +0000631 return 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000632}
633
634/* High-Level API */
635/* Entry-point where L2 OML from BTS enters the NM code */
Harald Welte8470bf22008-12-25 23:28:35 +0000636int abis_nm_rcvmsg(struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +0000637{
638 int rc;
639 struct abis_om_hdr *oh = msgb_l2(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000640
641 /* Various consistency checks */
642 if (oh->placement != ABIS_OM_PLACEMENT_ONLY) {
643 fprintf(stderr, "ABIS OML placement 0x%x not supported\n",
644 oh->placement);
645 return -EINVAL;
646 }
647 if (oh->sequence != 0) {
648 fprintf(stderr, "ABIS OML sequence 0x%x != 0x00\n",
649 oh->sequence);
650 return -EINVAL;
651 }
Harald Welte702d8702008-12-26 20:25:35 +0000652#if 0
Holger Freytherca362a62009-01-04 21:05:01 +0000653 unsigned int l2_len = msg->tail - (u_int8_t *)msgb_l2(msg);
654 unsigned int hlen = sizeof(*oh) + sizeof(struct abis_om_fom_hdr);
Harald Welte702d8702008-12-26 20:25:35 +0000655 if (oh->length + hlen > l2_len) {
Harald Welte52b1f982008-12-23 20:25:15 +0000656 fprintf(stderr, "ABIS OML truncated message (%u > %u)\n",
657 oh->length + sizeof(*oh), l2_len);
658 return -EINVAL;
659 }
Harald Welte702d8702008-12-26 20:25:35 +0000660 if (oh->length + hlen < l2_len)
661 fprintf(stderr, "ABIS OML message with extra trailer?!? (oh->len=%d, sizeof_oh=%d l2_len=%d\n", oh->length, sizeof(*oh), l2_len);
662#endif
Harald Weltead384642008-12-26 10:20:07 +0000663 msg->l3h = (unsigned char *)oh + sizeof(*oh);
Harald Welte52b1f982008-12-23 20:25:15 +0000664
665 switch (oh->mdisc) {
666 case ABIS_OM_MDISC_FOM:
Harald Welte8470bf22008-12-25 23:28:35 +0000667 rc = abis_nm_rcvmsg_fom(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000668 break;
669 case ABIS_OM_MDISC_MMI:
670 case ABIS_OM_MDISC_TRAU:
671 case ABIS_OM_MDISC_MANUF:
672 default:
673 fprintf(stderr, "unknown ABIS OML message discriminator 0x%x\n",
674 oh->mdisc);
675 return -EINVAL;
676 }
677
Harald Weltead384642008-12-26 10:20:07 +0000678 msgb_free(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000679 return rc;
680}
681
682#if 0
683/* initialized all resources */
684struct abis_nm_h *abis_nm_init(struct abis_nm_cfg *cfg)
685{
686 struct abis_nm_h *nmh;
687
688 nmh = malloc(sizeof(*nmh));
689 if (!nmh)
690 return NULL;
691
692 nmh->cfg = cfg;
693
694 return nmh;
695}
696
697/* free all resources */
698void abis_nm_fini(struct abis_nm_h *nmh)
699{
700 free(nmh);
701}
702#endif
703
704/* Here we are trying to define a high-level API that can be used by
705 * the actual BSC implementation. However, the architecture is currently
706 * still under design. Ideally the calls to this API would be synchronous,
707 * while the underlying stack behind the APi runs in a traditional select
708 * based state machine.
709 */
710
Harald Welte4724f992009-01-18 18:01:49 +0000711/* 6.2 Software Load: */
712enum sw_state {
713 SW_STATE_NONE,
714 SW_STATE_WAIT_INITACK,
715 SW_STATE_WAIT_SEGACK,
716 SW_STATE_WAIT_ENDACK,
717 SW_STATE_WAIT_ACTACK,
718 SW_STATE_ERROR,
719};
Harald Welte52b1f982008-12-23 20:25:15 +0000720
Harald Welte52b1f982008-12-23 20:25:15 +0000721struct abis_nm_sw {
Harald Welte4724f992009-01-18 18:01:49 +0000722 struct gsm_bts *bts;
Harald Welte5e4d1b32009-02-01 13:36:56 +0000723 gsm_cbfn *cbfn;
724 void *cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +0000725 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +0000726
Harald Welte52b1f982008-12-23 20:25:15 +0000727 /* this will become part of the SW LOAD INITIATE */
728 u_int8_t obj_class;
729 u_int8_t obj_instance[3];
Harald Welte4724f992009-01-18 18:01:49 +0000730
731 u_int8_t file_id[255];
732 u_int8_t file_id_len;
733
734 u_int8_t file_version[255];
735 u_int8_t file_version_len;
736
737 u_int8_t window_size;
738 u_int8_t seg_in_window;
739
740 int fd;
741 FILE *stream;
742 enum sw_state state;
Harald Welte1602ade2009-01-29 21:12:39 +0000743 int last_seg;
Harald Welte52b1f982008-12-23 20:25:15 +0000744};
745
Harald Welte4724f992009-01-18 18:01:49 +0000746static struct abis_nm_sw g_sw;
747
748/* 6.2.1 / 8.3.1: Load Data Initiate */
749static int sw_load_init(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +0000750{
Harald Welte4724f992009-01-18 18:01:49 +0000751 struct abis_om_hdr *oh;
752 struct msgb *msg = nm_msgb_alloc();
753 u_int8_t len = 3*2 + sw->file_id_len + sw->file_version_len;
754
755 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
756 fill_om_fom_hdr(oh, len, NM_MT_LOAD_INIT, sw->obj_class,
757 sw->obj_instance[0], sw->obj_instance[1],
758 sw->obj_instance[2]);
759
760 /* FIXME: this is BS11 specific format */
761 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
762 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
763 sw->file_version);
764 msgb_tv_put(msg, NM_ATT_WINDOW_SIZE, sw->window_size);
765
766 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000767}
768
Harald Welte1602ade2009-01-29 21:12:39 +0000769static int is_last_line(FILE *stream)
770{
771 char next_seg_buf[256];
772 long pos;
773
774 /* check if we're sending the last line */
775 pos = ftell(stream);
776 if (!fgets(next_seg_buf, sizeof(next_seg_buf)-2, stream)) {
777 fseek(stream, pos, SEEK_SET);
778 return 1;
779 }
780
781 fseek(stream, pos, SEEK_SET);
782 return 0;
783}
784
Harald Welte4724f992009-01-18 18:01:49 +0000785/* 6.2.2 / 8.3.2 Load Data Segment */
786static int sw_load_segment(struct abis_nm_sw *sw)
787{
788 struct abis_om_hdr *oh;
789 struct msgb *msg = nm_msgb_alloc();
790 char seg_buf[256];
791 char *line_buf = seg_buf+2;
Harald Welte3b8ba212009-01-29 12:27:58 +0000792 unsigned char *tlv;
Harald Welte4724f992009-01-18 18:01:49 +0000793 u_int8_t len;
Harald Welte4724f992009-01-18 18:01:49 +0000794
795 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte3b8ba212009-01-29 12:27:58 +0000796
797 switch (sw->bts->type) {
798 case GSM_BTS_TYPE_BS11:
799 if (fgets(line_buf, sizeof(seg_buf)-2, sw->stream) == NULL) {
800 perror("fgets reading segment");
801 return -EINVAL;
802 }
803 seg_buf[0] = 0x00;
Harald Welte1602ade2009-01-29 21:12:39 +0000804
805 /* check if we're sending the last line */
806 sw->last_seg = is_last_line(sw->stream);
807 if (sw->last_seg)
808 seg_buf[1] = 0;
809 else
810 seg_buf[1] = 1 + sw->seg_in_window++;
Harald Welte3b8ba212009-01-29 12:27:58 +0000811
812 len = strlen(line_buf) + 2;
813 tlv = msgb_put(msg, TLV_GROSS_LEN(len));
814 tlv_put(tlv, NM_ATT_BS11_FILE_DATA, len, (u_int8_t *)seg_buf);
815 /* BS11 wants CR + LF in excess of the TLV length !?! */
816 tlv[1] -= 2;
817
818 /* we only now know the exact length for the OM hdr */
819 len = strlen(line_buf)+2;
820 break;
821 default:
822 /* FIXME: Other BTS types */
823 return -1;
Harald Welte4724f992009-01-18 18:01:49 +0000824 }
Harald Welte4724f992009-01-18 18:01:49 +0000825
Harald Welte4724f992009-01-18 18:01:49 +0000826 fill_om_fom_hdr(oh, len, NM_MT_LOAD_SEG, sw->obj_class,
827 sw->obj_instance[0], sw->obj_instance[1],
828 sw->obj_instance[2]);
829
830 return abis_nm_sendmsg(sw->bts, msg);
831}
832
833/* 6.2.4 / 8.3.4 Load Data End */
834static int sw_load_end(struct abis_nm_sw *sw)
835{
836 struct abis_om_hdr *oh;
837 struct msgb *msg = nm_msgb_alloc();
838 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
839
840 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
841 fill_om_fom_hdr(oh, len, NM_MT_LOAD_END, sw->obj_class,
842 sw->obj_instance[0], sw->obj_instance[1],
843 sw->obj_instance[2]);
844
845 /* FIXME: this is BS11 specific format */
846 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
847 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
848 sw->file_version);
849
850 return abis_nm_sendmsg(sw->bts, msg);
851}
Harald Welte5e4d1b32009-02-01 13:36:56 +0000852
Harald Welte52b1f982008-12-23 20:25:15 +0000853/* Activate the specified software into the BTS */
Harald Welte4724f992009-01-18 18:01:49 +0000854static int sw_activate(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +0000855{
Harald Welte4724f992009-01-18 18:01:49 +0000856 struct abis_om_hdr *oh;
857 struct msgb *msg = nm_msgb_alloc();
858 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
Harald Welte52b1f982008-12-23 20:25:15 +0000859
Harald Welte4724f992009-01-18 18:01:49 +0000860 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
861 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, sw->obj_class,
862 sw->obj_instance[0], sw->obj_instance[1],
863 sw->obj_instance[2]);
864
865 /* FIXME: this is BS11 specific format */
866 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
867 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
868 sw->file_version);
869
870 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000871}
Harald Welte4724f992009-01-18 18:01:49 +0000872
873static int sw_open_file(struct abis_nm_sw *sw, const char *fname)
874{
875 char file_id[12+1];
876 char file_version[80+1];
877 int rc;
878
879 sw->fd = open(fname, O_RDONLY);
880 if (sw->fd < 0)
881 return sw->fd;
882
883 switch (sw->bts->type) {
884 case GSM_BTS_TYPE_BS11:
885 sw->stream = fdopen(sw->fd, "r");
886 if (!sw->stream) {
887 perror("fdopen");
888 return -1;
889 }
890 /* read first line and parse file ID and VERSION */
Harald Welte3b8ba212009-01-29 12:27:58 +0000891 rc = fscanf(sw->stream, "@(#)%12s:%80s\r\n",
Harald Welte4724f992009-01-18 18:01:49 +0000892 file_id, file_version);
893 if (rc != 2) {
894 perror("parsing header line of software file");
895 return -1;
896 }
897 strcpy((char *)sw->file_id, file_id);
898 sw->file_id_len = strlen(file_id);
899 strcpy((char *)sw->file_version, file_version);
900 sw->file_version_len = strlen(file_version);
901 /* rewind to start of file */
Harald Welte3b8ba212009-01-29 12:27:58 +0000902 rewind(sw->stream);
Harald Welte4724f992009-01-18 18:01:49 +0000903 break;
904 default:
905 /* We don't know how to treat them yet */
906 close(sw->fd);
907 return -EINVAL;
908 }
909
910 return 0;
911}
912
913static void sw_close_file(struct abis_nm_sw *sw)
914{
915 switch (sw->bts->type) {
916 case GSM_BTS_TYPE_BS11:
917 fclose(sw->stream);
918 break;
919 default:
920 close(sw->fd);
921 break;
922 }
923}
924
925/* Fill the window */
926static int sw_fill_window(struct abis_nm_sw *sw)
927{
928 int rc;
929
930 while (sw->seg_in_window < sw->window_size) {
931 rc = sw_load_segment(sw);
932 if (rc < 0)
933 return rc;
Harald Welte1602ade2009-01-29 21:12:39 +0000934 if (sw->last_seg)
935 break;
Harald Welte4724f992009-01-18 18:01:49 +0000936 }
937 return 0;
938}
939
940/* callback function from abis_nm_rcvmsg() handler */
941static int abis_nm_rcvmsg_sw(struct msgb *mb)
942{
943 struct abis_om_fom_hdr *foh = msgb_l3(mb);
944 int rc = -1;
945 struct abis_nm_sw *sw = &g_sw;
946 enum sw_state old_state = sw->state;
947
Harald Welte3ffd1372009-02-01 22:15:49 +0000948 //DEBUGP(DNM, "state %u, NM MT 0x%02x\n", sw->state, foh->msg_type);
Harald Welte4724f992009-01-18 18:01:49 +0000949
950 switch (sw->state) {
951 case SW_STATE_WAIT_INITACK:
952 switch (foh->msg_type) {
953 case NM_MT_LOAD_INIT_ACK:
954 /* fill window with segments */
Harald Welte5e4d1b32009-02-01 13:36:56 +0000955 if (sw->cbfn)
956 sw->cbfn(GSM_HOOK_NM_SWLOAD,
957 NM_MT_LOAD_INIT_ACK, mb,
958 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +0000959 rc = sw_fill_window(sw);
960 sw->state = SW_STATE_WAIT_SEGACK;
961 break;
962 case NM_MT_LOAD_INIT_NACK:
Harald Welte3ffd1372009-02-01 22:15:49 +0000963 if (sw->forced) {
964 DEBUGP(DNM, "FORCED: Ignoring Software Load "
965 "Init NACK\n");
966 if (sw->cbfn)
967 sw->cbfn(GSM_HOOK_NM_SWLOAD,
968 NM_MT_LOAD_INIT_ACK, mb,
969 sw->cb_data, NULL);
970 rc = sw_fill_window(sw);
971 sw->state = SW_STATE_WAIT_SEGACK;
972 } else {
973 DEBUGP(DNM, "Software Load Init NACK\n");
974 if (sw->cbfn)
975 sw->cbfn(GSM_HOOK_NM_SWLOAD,
976 NM_MT_LOAD_INIT_NACK, mb,
977 sw->cb_data, NULL);
978 sw->state = SW_STATE_ERROR;
979 }
Harald Welte4724f992009-01-18 18:01:49 +0000980 break;
981 }
982 break;
983 case SW_STATE_WAIT_SEGACK:
984 switch (foh->msg_type) {
985 case NM_MT_LOAD_SEG_ACK:
Harald Welte3ffd1372009-02-01 22:15:49 +0000986 if (sw->cbfn)
987 sw->cbfn(GSM_HOOK_NM_SWLOAD,
988 NM_MT_LOAD_SEG_ACK, mb,
989 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +0000990 sw->seg_in_window = 0;
Harald Welte1602ade2009-01-29 21:12:39 +0000991 if (!sw->last_seg) {
992 /* fill window with more segments */
993 rc = sw_fill_window(sw);
994 sw->state = SW_STATE_WAIT_SEGACK;
995 } else {
996 /* end the transfer */
997 sw->state = SW_STATE_WAIT_ENDACK;
998 rc = sw_load_end(sw);
999 }
Harald Welte4724f992009-01-18 18:01:49 +00001000 break;
1001 }
1002 break;
1003 case SW_STATE_WAIT_ENDACK:
1004 switch (foh->msg_type) {
1005 case NM_MT_LOAD_END_ACK:
1006 sw_close_file(sw);
Harald Welte5e4d1b32009-02-01 13:36:56 +00001007 DEBUGP(DNM, "Software Load End (BTS %u)\n",
1008 sw->bts->nr);
1009 sw->state = SW_STATE_NONE;
1010 if (sw->cbfn)
1011 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1012 NM_MT_LOAD_END_ACK, mb,
1013 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001014 break;
1015 case NM_MT_LOAD_END_NACK:
Holger Freyther31338a12009-02-06 17:43:50 +00001016 if (sw->forced) {
1017 DEBUGP(DNM, "FORCED: Ignoring Software Load"
1018 "End NACK\n");
1019 sw->state = SW_STATE_NONE;
1020 if (sw->cbfn)
1021 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1022 NM_MT_LOAD_END_ACK, mb,
1023 sw->cb_data, NULL);
1024 } else {
1025 DEBUGP(DNM, "Software Load End NACK\n");
1026 sw->state = SW_STATE_ERROR;
1027 if (sw->cbfn)
1028 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1029 NM_MT_LOAD_END_NACK, mb,
1030 sw->cb_data, NULL);
1031 }
Harald Welte4724f992009-01-18 18:01:49 +00001032 break;
1033 }
1034 case SW_STATE_WAIT_ACTACK:
1035 switch (foh->msg_type) {
1036 case NM_MT_ACTIVATE_SW_ACK:
1037 /* we're done */
Harald Welte5e4d1b32009-02-01 13:36:56 +00001038 DEBUGP(DNM, "Activate Software DONE!\n");
Harald Welte4724f992009-01-18 18:01:49 +00001039 sw->state = SW_STATE_NONE;
1040 rc = 0;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001041 if (sw->cbfn)
1042 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1043 NM_MT_ACTIVATE_SW_ACK, mb,
1044 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001045 break;
1046 case NM_MT_ACTIVATE_SW_NACK:
Harald Welte1602ade2009-01-29 21:12:39 +00001047 DEBUGP(DNM, "Activate Software NACK\n");
Harald Welte4724f992009-01-18 18:01:49 +00001048 sw->state = SW_STATE_ERROR;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001049 if (sw->cbfn)
1050 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1051 NM_MT_ACTIVATE_SW_NACK, mb,
1052 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001053 break;
1054 }
1055 case SW_STATE_NONE:
1056 case SW_STATE_ERROR:
1057 break;
1058 }
1059
1060 if (rc)
1061 fprintf(stderr, "unexpected NM MT 0x%02x in state %u -> %u\n",
1062 foh->msg_type, old_state, sw->state);
1063
1064 return rc;
1065}
1066
1067/* Load the specified software into the BTS */
1068int abis_nm_software_load(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00001069 u_int8_t win_size, int forced,
1070 gsm_cbfn *cbfn, void *cb_data)
Harald Welte4724f992009-01-18 18:01:49 +00001071{
1072 struct abis_nm_sw *sw = &g_sw;
1073 int rc;
1074
Harald Welte5e4d1b32009-02-01 13:36:56 +00001075 DEBUGP(DNM, "Software Load (BTS %u, File \"%s\")\n",
1076 bts->nr, fname);
1077
Harald Welte4724f992009-01-18 18:01:49 +00001078 if (sw->state != SW_STATE_NONE)
1079 return -EBUSY;
1080
1081 sw->bts = bts;
1082 sw->obj_class = NM_OC_SITE_MANAGER;
1083 sw->obj_instance[0] = 0xff;
1084 sw->obj_instance[1] = 0xff;
1085 sw->obj_instance[2] = 0xff;
1086 sw->window_size = win_size;
1087 sw->state = SW_STATE_WAIT_INITACK;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001088 sw->cbfn = cbfn;
1089 sw->cb_data = cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +00001090 sw->forced = forced;
Harald Welte4724f992009-01-18 18:01:49 +00001091
1092 rc = sw_open_file(sw, fname);
1093 if (rc < 0) {
1094 sw->state = SW_STATE_NONE;
1095 return rc;
1096 }
1097
1098 return sw_load_init(sw);
1099}
Harald Welte52b1f982008-12-23 20:25:15 +00001100
Harald Welte1602ade2009-01-29 21:12:39 +00001101int abis_nm_software_load_status(struct gsm_bts *bts)
1102{
1103 struct abis_nm_sw *sw = &g_sw;
1104 struct stat st;
1105 int rc, percent;
1106
1107 rc = fstat(sw->fd, &st);
1108 if (rc < 0) {
1109 perror("ERROR during stat");
1110 return rc;
1111 }
1112
1113 percent = (ftell(sw->stream) * 100) / st.st_size;
1114 return percent;
1115}
1116
Harald Welte5e4d1b32009-02-01 13:36:56 +00001117/* Activate the specified software into the BTS */
1118int abis_nm_software_activate(struct gsm_bts *bts, const char *fname,
1119 gsm_cbfn *cbfn, void *cb_data)
1120{
1121 struct abis_nm_sw *sw = &g_sw;
1122 int rc;
1123
1124 DEBUGP(DNM, "Activating Software (BTS %u, File \"%s\")\n",
1125 bts->nr, fname);
1126
1127 if (sw->state != SW_STATE_NONE)
1128 return -EBUSY;
1129
1130 sw->bts = bts;
1131 sw->obj_class = NM_OC_SITE_MANAGER;
1132 sw->obj_instance[0] = 0xff;
1133 sw->obj_instance[1] = 0xff;
1134 sw->obj_instance[2] = 0xff;
1135 sw->state = SW_STATE_WAIT_ACTACK;
1136 sw->cbfn = cbfn;
1137 sw->cb_data = cb_data;
1138
1139 /* Open the file in order to fill some sw struct members */
1140 rc = sw_open_file(sw, fname);
1141 if (rc < 0) {
1142 sw->state = SW_STATE_NONE;
1143 return rc;
1144 }
1145 sw_close_file(sw);
1146
1147 return sw_activate(sw);
1148}
1149
Harald Welte8470bf22008-12-25 23:28:35 +00001150static void fill_nm_channel(struct abis_nm_channel *ch, u_int8_t bts_port,
Harald Welte52b1f982008-12-23 20:25:15 +00001151 u_int8_t ts_nr, u_int8_t subslot_nr)
1152{
Harald Welteadaf08b2009-01-18 11:08:10 +00001153 ch->attrib = NM_ATT_ABIS_CHANNEL;
Harald Welte52b1f982008-12-23 20:25:15 +00001154 ch->bts_port = bts_port;
1155 ch->timeslot = ts_nr;
1156 ch->subslot = subslot_nr;
1157}
1158
1159int abis_nm_establish_tei(struct gsm_bts *bts, u_int8_t trx_nr,
1160 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot,
1161 u_int8_t tei)
1162{
1163 struct abis_om_hdr *oh;
1164 struct abis_nm_channel *ch;
Harald Welte702d8702008-12-26 20:25:35 +00001165 u_int8_t len = sizeof(*ch) + 2;
Harald Welte8470bf22008-12-25 23:28:35 +00001166 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001167
1168 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1169 fill_om_fom_hdr(oh, len, NM_MT_ESTABLISH_TEI, NM_OC_RADIO_CARRIER,
1170 bts->bts_nr, trx_nr, 0xff);
1171
Harald Welte8470bf22008-12-25 23:28:35 +00001172 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte52b1f982008-12-23 20:25:15 +00001173
1174 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1175 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1176
1177 return abis_nm_sendmsg(bts, msg);
1178}
1179
1180/* connect signalling of one (BTS,TRX) to a particular timeslot on the E1 */
1181int abis_nm_conn_terr_sign(struct gsm_bts_trx *trx,
1182 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot)
1183{
Harald Welte8470bf22008-12-25 23:28:35 +00001184 struct gsm_bts *bts = trx->bts;
Harald Welte52b1f982008-12-23 20:25:15 +00001185 struct abis_om_hdr *oh;
1186 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +00001187 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001188
1189 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001190 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_SIGN,
Harald Welte52b1f982008-12-23 20:25:15 +00001191 NM_OC_RADIO_CARRIER, bts->bts_nr, trx->nr, 0xff);
1192
1193 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1194 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1195
1196 return abis_nm_sendmsg(bts, msg);
1197}
1198
1199#if 0
1200int abis_nm_disc_terr_sign(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1201 struct abis_nm_abis_channel *chan)
1202{
1203}
1204#endif
1205
1206int abis_nm_conn_terr_traf(struct gsm_bts_trx_ts *ts,
1207 u_int8_t e1_port, u_int8_t e1_timeslot,
1208 u_int8_t e1_subslot)
1209{
1210 struct gsm_bts *bts = ts->trx->bts;
1211 struct abis_om_hdr *oh;
1212 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +00001213 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001214
1215 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1216 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_TRAF,
1217 NM_OC_BASEB_TRANSC, bts->bts_nr, ts->trx->nr, ts->nr);
1218
1219 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1220 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1221
1222 return abis_nm_sendmsg(bts, msg);
1223}
1224
1225#if 0
1226int abis_nm_disc_terr_traf(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1227 struct abis_nm_abis_channel *chan,
1228 u_int8_t subchan)
1229{
1230}
1231#endif
1232
Harald Welte22af0db2009-02-14 15:41:08 +00001233/* Chapter 8.6.1 */
1234int abis_nm_set_bts_attr(struct gsm_bts *bts, u_int8_t *attr, int attr_len)
1235{
1236 struct abis_om_hdr *oh;
1237 struct msgb *msg = nm_msgb_alloc();
1238 u_int8_t *cur;
1239
1240 DEBUGP(DNM, "Set BTS Attr (bts=%d)\n", bts->nr);
1241
1242 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1243 fill_om_fom_hdr(oh, attr_len, NM_MT_SET_BTS_ATTR, NM_OC_BTS, bts->nr, 0xff, 0xff);
1244 cur = msgb_put(msg, attr_len);
1245 memcpy(cur, attr, attr_len);
1246
1247 return abis_nm_sendmsg(bts, msg);
1248}
1249
1250/* Chapter 8.6.2 */
1251int abis_nm_set_radio_attr(struct gsm_bts_trx *trx, u_int8_t *attr, int attr_len)
1252{
1253 struct abis_om_hdr *oh;
1254 struct msgb *msg = nm_msgb_alloc();
1255 u_int8_t *cur;
1256
1257 DEBUGP(DNM, "Set TRX Attr (bts=%d,trx=%d)\n", trx->bts->nr, trx->nr);
1258
1259 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1260 fill_om_fom_hdr(oh, attr_len, NM_MT_SET_RADIO_ATTR, NM_OC_RADIO_CARRIER,
1261 trx->bts->nr, trx->nr, 0xff);
1262 cur = msgb_put(msg, attr_len);
1263 memcpy(cur, attr, attr_len);
1264
1265 return abis_nm_sendmsg(trx->bts, msg);
1266}
1267
1268/* Chapter 8.6.3 */
Harald Welte52b1f982008-12-23 20:25:15 +00001269int abis_nm_set_channel_attr(struct gsm_bts_trx_ts *ts, u_int8_t chan_comb)
1270{
1271 struct gsm_bts *bts = ts->trx->bts;
1272 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001273 u_int16_t arfcn = htons(ts->trx->arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001274 u_int8_t zero = 0x00;
Harald Welte8470bf22008-12-25 23:28:35 +00001275 struct msgb *msg = nm_msgb_alloc();
Harald Weltee0590df2009-02-15 03:34:15 +00001276 u_int8_t len = 2 + 2;
1277
1278 if (bts->type == GSM_BTS_TYPE_BS11)
1279 len += 4 + 2 + 2 + 3;
Harald Welte52b1f982008-12-23 20:25:15 +00001280
Harald Welte22af0db2009-02-14 15:41:08 +00001281 DEBUGP(DNM, "Set Chan Attr (bts=%d,trx=%d,ts=%d)\n", bts->nr, ts->trx->nr, ts->nr);
1282
Harald Welte52b1f982008-12-23 20:25:15 +00001283 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001284 fill_om_fom_hdr(oh, len, NM_MT_SET_CHAN_ATTR,
Holger Freyther6b2d2622009-02-14 23:16:59 +00001285 NM_OC_CHANNEL, bts->bts_nr,
Harald Welte52b1f982008-12-23 20:25:15 +00001286 ts->trx->nr, ts->nr);
1287 /* FIXME: don't send ARFCN list, hopping sequence, mAIO, ...*/
Harald Weltee0590df2009-02-15 03:34:15 +00001288 if (bts->type == GSM_BTS_TYPE_BS11)
1289 msgb_tlv16_put(msg, NM_ATT_ARFCN_LIST, 1, &arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001290 msgb_tv_put(msg, NM_ATT_CHAN_COMB, chan_comb);
Harald Weltee0590df2009-02-15 03:34:15 +00001291 if (bts->type == GSM_BTS_TYPE_BS11) {
1292 msgb_tv_put(msg, NM_ATT_HSN, 0x00);
1293 msgb_tv_put(msg, NM_ATT_MAIO, 0x00);
1294 }
Harald Welte52b1f982008-12-23 20:25:15 +00001295 msgb_tv_put(msg, NM_ATT_TSC, 0x07); /* training sequence */
Harald Weltee0590df2009-02-15 03:34:15 +00001296 if (bts->type == GSM_BTS_TYPE_BS11)
1297 msgb_tlv_put(msg, 0x59, 1, &zero);
Harald Welte52b1f982008-12-23 20:25:15 +00001298
1299 return abis_nm_sendmsg(bts, msg);
1300}
1301
Harald Welte34a99682009-02-13 02:41:40 +00001302int abis_nm_sw_act_req_ack(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i1,
Harald Welte5c1e4582009-02-15 11:57:29 +00001303 u_int8_t i2, u_int8_t i3, int nack, u_int8_t *attr, int att_len)
Harald Welte34a99682009-02-13 02:41:40 +00001304{
1305 struct abis_om_hdr *oh;
1306 struct msgb *msg = nm_msgb_alloc();
Harald Welte5c1e4582009-02-15 11:57:29 +00001307 u_int8_t msgtype = NM_MT_SW_ACT_REQ_ACK;
1308 u_int8_t len = att_len;
1309
1310 if (nack) {
1311 len += 2;
1312 msgtype = NM_MT_SW_ACT_REQ_NACK;
1313 }
Harald Welte34a99682009-02-13 02:41:40 +00001314
1315 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte5c1e4582009-02-15 11:57:29 +00001316 fill_om_fom_hdr(oh, att_len, msgtype, obj_class, i1, i2, i3);
1317
Harald Welte34a99682009-02-13 02:41:40 +00001318 if (attr) {
1319 u_int8_t *ptr = msgb_put(msg, att_len);
1320 memcpy(ptr, attr, att_len);
1321 }
Harald Welte5c1e4582009-02-15 11:57:29 +00001322 if (nack)
1323 msgb_tv_put(msg, NM_ATT_NACK_CAUSES, NM_NACK_OBJCLASS_NOTSUPP);
Harald Welte34a99682009-02-13 02:41:40 +00001324
1325 return abis_nm_sendmsg(bts, msg);
1326}
1327
Harald Welte8470bf22008-12-25 23:28:35 +00001328int abis_nm_raw_msg(struct gsm_bts *bts, int len, u_int8_t *rawmsg)
Harald Welte52b1f982008-12-23 20:25:15 +00001329{
Harald Welte8470bf22008-12-25 23:28:35 +00001330 struct msgb *msg = nm_msgb_alloc();
1331 struct abis_om_hdr *oh;
Harald Welte52b1f982008-12-23 20:25:15 +00001332 u_int8_t *data;
1333
1334 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
1335 fill_om_hdr(oh, len);
1336 data = msgb_put(msg, len);
Harald Weltead384642008-12-26 10:20:07 +00001337 memcpy(data, rawmsg, len);
Harald Welte52b1f982008-12-23 20:25:15 +00001338
1339 return abis_nm_sendmsg(bts, msg);
1340}
1341
1342/* Siemens specific commands */
1343static int __simple_cmd(struct gsm_bts *bts, u_int8_t msg_type)
1344{
1345 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001346 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001347
1348 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001349 fill_om_fom_hdr(oh, 0, msg_type, NM_OC_SITE_MANAGER,
Harald Welte52b1f982008-12-23 20:25:15 +00001350 0xff, 0xff, 0xff);
1351
1352 return abis_nm_sendmsg(bts, msg);
1353}
1354
Harald Welte34a99682009-02-13 02:41:40 +00001355/* Chapter 8.9.2 */
1356int abis_nm_opstart(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1, u_int8_t i2)
1357{
1358 struct abis_om_hdr *oh;
1359 struct msgb *msg = nm_msgb_alloc();
1360
Harald Welte22af0db2009-02-14 15:41:08 +00001361 DEBUGP(DNM, "Sending OPSTART obj_class=0x%02x obj_inst=(0x%02x, 0x%02x, 0x%02x)\n",
1362 obj_class, i0, i1, i2);
Harald Welte34a99682009-02-13 02:41:40 +00001363 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1364 fill_om_fom_hdr(oh, 0, NM_MT_OPSTART, obj_class, i0, i1, i2);
1365
1366 return abis_nm_sendmsg(bts, msg);
1367}
1368
1369/* Chapter 8.8.5 */
1370int abis_nm_chg_adm_state(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0,
1371 u_int8_t i1, u_int8_t i2, u_int8_t adm_state)
1372{
1373 struct abis_om_hdr *oh;
1374 struct msgb *msg = nm_msgb_alloc();
1375
1376 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1377 fill_om_fom_hdr(oh, 2, NM_MT_CHG_ADM_STATE, obj_class, i0, i1, i2);
1378 msgb_tv_put(msg, NM_ATT_ADM_STATE, adm_state);
1379
1380 return abis_nm_sendmsg(bts, msg);
1381}
1382
1383
Harald Welte52b1f982008-12-23 20:25:15 +00001384int abis_nm_event_reports(struct gsm_bts *bts, int on)
1385{
1386 if (on == 0)
Harald Welte227d4072009-01-03 08:16:25 +00001387 return __simple_cmd(bts, NM_MT_STOP_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001388 else
Harald Welte227d4072009-01-03 08:16:25 +00001389 return __simple_cmd(bts, NM_MT_REST_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001390}
1391
Harald Welte47d88ae2009-01-04 12:02:08 +00001392/* Siemens (or BS-11) specific commands */
1393
Harald Welte3ffd1372009-02-01 22:15:49 +00001394int abis_nm_bs11_bsc_disconnect(struct gsm_bts *bts, int reconnect)
1395{
1396 if (reconnect == 0)
1397 return __simple_cmd(bts, NM_MT_BS11_DISCONNECT);
1398 else
1399 return __simple_cmd(bts, NM_MT_BS11_RECONNECT);
1400}
1401
Harald Welteb8427972009-02-05 19:27:17 +00001402int abis_nm_bs11_restart(struct gsm_bts *bts)
1403{
1404 return __simple_cmd(bts, NM_MT_BS11_RESTART);
1405}
1406
1407
Harald Welte268bb402009-02-01 19:11:56 +00001408struct bs11_date_time {
1409 u_int16_t year;
1410 u_int8_t month;
1411 u_int8_t day;
1412 u_int8_t hour;
1413 u_int8_t min;
1414 u_int8_t sec;
1415} __attribute__((packed));
1416
1417
1418void get_bs11_date_time(struct bs11_date_time *aet)
1419{
1420 time_t t;
1421 struct tm *tm;
1422
1423 t = time(NULL);
1424 tm = localtime(&t);
1425 aet->sec = tm->tm_sec;
1426 aet->min = tm->tm_min;
1427 aet->hour = tm->tm_hour;
1428 aet->day = tm->tm_mday;
1429 aet->month = tm->tm_mon;
1430 aet->year = htons(1900 + tm->tm_year);
1431}
1432
Harald Welte05188ee2009-01-18 11:39:08 +00001433int abis_nm_bs11_reset_resource(struct gsm_bts *bts)
Harald Welte52b1f982008-12-23 20:25:15 +00001434{
Harald Welte4668fda2009-01-03 08:19:29 +00001435 return __simple_cmd(bts, NM_MT_BS11_RESET_RESOURCE);
Harald Welte52b1f982008-12-23 20:25:15 +00001436}
1437
Harald Welte05188ee2009-01-18 11:39:08 +00001438int abis_nm_bs11_db_transmission(struct gsm_bts *bts, int begin)
Harald Welte52b1f982008-12-23 20:25:15 +00001439{
1440 if (begin)
Harald Welte4668fda2009-01-03 08:19:29 +00001441 return __simple_cmd(bts, NM_MT_BS11_BEGIN_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00001442 else
Harald Welte4668fda2009-01-03 08:19:29 +00001443 return __simple_cmd(bts, NM_MT_BS11_END_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00001444}
Harald Welte47d88ae2009-01-04 12:02:08 +00001445
Harald Welte05188ee2009-01-18 11:39:08 +00001446int abis_nm_bs11_create_object(struct gsm_bts *bts,
Harald Welte1bc09062009-01-18 14:17:52 +00001447 enum abis_bs11_objtype type, u_int8_t idx,
1448 u_int8_t attr_len, const u_int8_t *attr)
Harald Welte47d88ae2009-01-04 12:02:08 +00001449{
1450 struct abis_om_hdr *oh;
1451 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00001452 u_int8_t *cur;
Harald Welte47d88ae2009-01-04 12:02:08 +00001453
1454 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001455 fill_om_fom_hdr(oh, attr_len, NM_MT_BS11_CREATE_OBJ,
Harald Welte268bb402009-02-01 19:11:56 +00001456 NM_OC_BS11, type, 0, idx);
Harald Welte1bc09062009-01-18 14:17:52 +00001457 cur = msgb_put(msg, attr_len);
1458 memcpy(cur, attr, attr_len);
Harald Welte47d88ae2009-01-04 12:02:08 +00001459
1460 return abis_nm_sendmsg(bts, msg);
1461}
1462
Harald Welte05188ee2009-01-18 11:39:08 +00001463int abis_nm_bs11_create_envaBTSE(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00001464{
1465 struct abis_om_hdr *oh;
1466 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00001467 u_int8_t zero = 0x00;
Harald Welte47d88ae2009-01-04 12:02:08 +00001468
1469 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001470 fill_om_fom_hdr(oh, 3, NM_MT_BS11_CREATE_OBJ,
Harald Welte1bc09062009-01-18 14:17:52 +00001471 NM_OC_BS11_ENVABTSE, 0, idx, 0xff);
1472 msgb_tlv_put(msg, 0x99, 1, &zero);
Harald Welte47d88ae2009-01-04 12:02:08 +00001473
1474 return abis_nm_sendmsg(bts, msg);
1475}
1476
Harald Welte05188ee2009-01-18 11:39:08 +00001477int abis_nm_bs11_create_bport(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00001478{
1479 struct abis_om_hdr *oh;
1480 struct msgb *msg = nm_msgb_alloc();
1481
1482 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1483 fill_om_fom_hdr(oh, 0, NM_MT_BS11_CREATE_OBJ, NM_OC_BS11_BPORT,
1484 idx, 0, 0);
1485
1486 return abis_nm_sendmsg(bts, msg);
1487}
Harald Welte05188ee2009-01-18 11:39:08 +00001488
1489int abis_nm_bs11_set_oml_tei(struct gsm_bts *bts, u_int8_t tei)
1490{
1491 struct abis_om_hdr *oh;
1492 struct msgb *msg = nm_msgb_alloc();
Harald Welte05188ee2009-01-18 11:39:08 +00001493
1494 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001495 fill_om_fom_hdr(oh, 2, NM_MT_BS11_SET_ATTR, NM_OC_SITE_MANAGER,
Harald Welte05188ee2009-01-18 11:39:08 +00001496 0xff, 0xff, 0xff);
1497 msgb_tv_put(msg, NM_ATT_TEI, tei);
1498
1499 return abis_nm_sendmsg(bts, msg);
1500}
1501
1502/* like abis_nm_conn_terr_traf */
1503int abis_nm_bs11_conn_oml(struct gsm_bts *bts, u_int8_t e1_port,
1504 u_int8_t e1_timeslot, u_int8_t e1_subslot)
1505{
1506 struct abis_om_hdr *oh;
1507 struct abis_nm_channel *ch;
1508 struct msgb *msg = nm_msgb_alloc();
1509
1510 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte05188ee2009-01-18 11:39:08 +00001511 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_BS11_SET_ATTR,
1512 NM_OC_SITE_MANAGER, 0xff, 0xff, 0xff);
1513
1514 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1515 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1516
1517 return abis_nm_sendmsg(bts, msg);
1518}
1519
1520int abis_nm_bs11_set_trx_power(struct gsm_bts_trx *trx, u_int8_t level)
1521{
1522 struct abis_om_hdr *oh;
1523 struct msgb *msg = nm_msgb_alloc();
Harald Welte05188ee2009-01-18 11:39:08 +00001524
1525 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001526 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR,
Harald Welte05188ee2009-01-18 11:39:08 +00001527 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
1528 msgb_tlv_put(msg, NM_ATT_BS11_TXPWR, 1, &level);
1529
1530 return abis_nm_sendmsg(trx->bts, msg);
1531}
1532
Harald Welte268bb402009-02-01 19:11:56 +00001533//static const u_int8_t bs11_logon_c7[] = { 0x07, 0xd9, 0x01, 0x11, 0x0d, 0x10, 0x20 };
Harald Weltebb151312009-01-28 20:42:07 +00001534static const u_int8_t bs11_logon_c8[] = { 0x02 };
Harald Welte05188ee2009-01-18 11:39:08 +00001535static const u_int8_t bs11_logon_c9[] = "FACTORY";
1536
Harald Welte1bc09062009-01-18 14:17:52 +00001537int abis_nm_bs11_factory_logon(struct gsm_bts *bts, int on)
Harald Welte05188ee2009-01-18 11:39:08 +00001538{
1539 struct abis_om_hdr *oh;
1540 struct msgb *msg = nm_msgb_alloc();
Harald Welte268bb402009-02-01 19:11:56 +00001541 struct bs11_date_time bdt;
1542
1543 get_bs11_date_time(&bdt);
Harald Welte05188ee2009-01-18 11:39:08 +00001544
1545 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte1bc09062009-01-18 14:17:52 +00001546 if (on) {
Harald Welte268bb402009-02-01 19:11:56 +00001547 u_int8_t len = 3*2 + sizeof(bdt)
Harald Welte6f676a32009-01-18 14:27:48 +00001548 + sizeof(bs11_logon_c8) + sizeof(bs11_logon_c9);
Harald Welte043d04a2009-01-29 23:15:30 +00001549 fill_om_fom_hdr(oh, len, NM_MT_BS11_LMT_LOGON,
Harald Welte1bc09062009-01-18 14:17:52 +00001550 NM_OC_BS11_A3, 0xff, 0xff, 0xff);
Harald Welte043d04a2009-01-29 23:15:30 +00001551 msgb_tlv_put(msg, NM_ATT_BS11_LMT_LOGIN_TIME,
Harald Welte5083b0b2009-02-02 19:20:52 +00001552 sizeof(bdt), (u_int8_t *) &bdt);
Harald Welte043d04a2009-01-29 23:15:30 +00001553 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_ACC_LEV,
1554 sizeof(bs11_logon_c8), bs11_logon_c8);
1555 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_NAME,
1556 sizeof(bs11_logon_c9), bs11_logon_c9);
Harald Welte1bc09062009-01-18 14:17:52 +00001557 } else {
Harald Welte5e4d1b32009-02-01 13:36:56 +00001558 fill_om_fom_hdr(oh, 0, NM_MT_BS11_LMT_LOGOFF,
Harald Welte1bc09062009-01-18 14:17:52 +00001559 NM_OC_BS11_A3, 0xff, 0xff, 0xff);
1560 }
Harald Welte05188ee2009-01-18 11:39:08 +00001561
1562 return abis_nm_sendmsg(bts, msg);
1563}
Harald Welte1bc09062009-01-18 14:17:52 +00001564
1565int abis_nm_bs11_set_trx1_pw(struct gsm_bts *bts, const char *password)
1566{
1567 struct abis_om_hdr *oh;
1568 struct msgb *msg;
1569
1570 if (strlen(password) != 10)
1571 return -EINVAL;
1572
1573 msg = nm_msgb_alloc();
1574 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001575 fill_om_fom_hdr(oh, 2+strlen(password), NM_MT_BS11_SET_ATTR,
Harald Welte1bc09062009-01-18 14:17:52 +00001576 NM_OC_BS11, BS11_OBJ_TRX1, 0x00, 0x00);
1577 msgb_tlv_put(msg, NM_ATT_BS11_PASSWORD, 10, (const u_int8_t *)password);
1578
1579 return abis_nm_sendmsg(bts, msg);
1580}
1581
1582int abis_nm_bs11_get_state(struct gsm_bts *bts)
1583{
1584 return __simple_cmd(bts, NM_MT_BS11_GET_STATE);
1585}
Harald Welte5e4d1b32009-02-01 13:36:56 +00001586
1587/* BS11 SWL */
1588
1589struct abis_nm_bs11_sw {
1590 struct gsm_bts *bts;
1591 char swl_fname[PATH_MAX];
1592 u_int8_t win_size;
Harald Welte3ffd1372009-02-01 22:15:49 +00001593 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001594 struct llist_head file_list;
1595 gsm_cbfn *user_cb; /* specified by the user */
1596};
1597static struct abis_nm_bs11_sw _g_bs11_sw, *g_bs11_sw = &_g_bs11_sw;
1598
1599struct file_list_entry {
1600 struct llist_head list;
1601 char fname[PATH_MAX];
1602};
1603
1604struct file_list_entry *fl_dequeue(struct llist_head *queue)
1605{
1606 struct llist_head *lh;
1607
1608 if (llist_empty(queue))
1609 return NULL;
1610
1611 lh = queue->next;
1612 llist_del(lh);
1613
1614 return llist_entry(lh, struct file_list_entry, list);
1615}
1616
1617static int bs11_read_swl_file(struct abis_nm_bs11_sw *bs11_sw)
1618{
1619 char linebuf[255];
1620 struct llist_head *lh, *lh2;
1621 FILE *swl;
1622 int rc = 0;
1623
1624 swl = fopen(bs11_sw->swl_fname, "r");
1625 if (!swl)
1626 return -ENODEV;
1627
1628 /* zero the stale file list, if any */
1629 llist_for_each_safe(lh, lh2, &bs11_sw->file_list) {
1630 llist_del(lh);
1631 free(lh);
1632 }
1633
1634 while (fgets(linebuf, sizeof(linebuf), swl)) {
1635 char file_id[12+1];
1636 char file_version[80+1];
1637 struct file_list_entry *fle;
1638 static char dir[PATH_MAX];
1639
1640 if (strlen(linebuf) < 4)
1641 continue;
Harald Welte3ffd1372009-02-01 22:15:49 +00001642
Harald Welte5e4d1b32009-02-01 13:36:56 +00001643 rc = sscanf(linebuf+4, "%12s:%80s\r\n", file_id, file_version);
1644 if (rc < 0) {
1645 perror("ERR parsing SWL file");
1646 rc = -EINVAL;
1647 goto out;
1648 }
1649 if (rc < 2)
1650 continue;
1651
1652 fle = malloc(sizeof(*fle));
1653 if (!fle) {
1654 rc = -ENOMEM;
1655 goto out;
1656 }
1657 memset(fle, 0, sizeof(*fle));
1658
1659 /* construct new filename */
1660 strncpy(dir, bs11_sw->swl_fname, sizeof(dir));
1661 strncat(fle->fname, dirname(dir), sizeof(fle->fname) - 1);
1662 strcat(fle->fname, "/");
1663 strncat(fle->fname, file_id, sizeof(fle->fname) - 1 -strlen(fle->fname));
Harald Welte5e4d1b32009-02-01 13:36:56 +00001664
1665 llist_add_tail(&fle->list, &bs11_sw->file_list);
1666 }
1667
1668out:
1669 fclose(swl);
1670 return rc;
1671}
1672
1673/* bs11 swload specific callback, passed to abis_nm core swload */
1674static int bs11_swload_cbfn(unsigned int hook, unsigned int event,
1675 struct msgb *msg, void *data, void *param)
1676{
1677 struct abis_nm_bs11_sw *bs11_sw = data;
1678 struct file_list_entry *fle;
1679 int rc = 0;
1680
Harald Welte5e4d1b32009-02-01 13:36:56 +00001681 switch (event) {
1682 case NM_MT_LOAD_END_ACK:
1683 fle = fl_dequeue(&bs11_sw->file_list);
1684 if (fle) {
1685 /* start download the next file of our file list */
1686 rc = abis_nm_software_load(bs11_sw->bts, fle->fname,
1687 bs11_sw->win_size,
Harald Welte3ffd1372009-02-01 22:15:49 +00001688 bs11_sw->forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00001689 &bs11_swload_cbfn, bs11_sw);
1690 free(fle);
1691 } else {
1692 /* activate the SWL */
1693 rc = abis_nm_software_activate(bs11_sw->bts,
1694 bs11_sw->swl_fname,
1695 bs11_swload_cbfn,
1696 bs11_sw);
1697 }
1698 break;
Harald Welte3ffd1372009-02-01 22:15:49 +00001699 case NM_MT_LOAD_SEG_ACK:
Harald Welte5e4d1b32009-02-01 13:36:56 +00001700 case NM_MT_LOAD_END_NACK:
1701 case NM_MT_LOAD_INIT_ACK:
1702 case NM_MT_LOAD_INIT_NACK:
1703 case NM_MT_ACTIVATE_SW_NACK:
1704 case NM_MT_ACTIVATE_SW_ACK:
1705 default:
1706 /* fallthrough to the user callback */
Harald Welte97ed1e72009-02-06 13:38:02 +00001707 if (bs11_sw->user_cb)
1708 rc = bs11_sw->user_cb(hook, event, msg, NULL, NULL);
Harald Welte5e4d1b32009-02-01 13:36:56 +00001709 break;
1710 }
1711
1712 return rc;
1713}
1714
1715/* Siemens provides a SWL file that is a mere listing of all the other
1716 * files that are part of a software release. We need to upload first
1717 * the list file, and then each file that is listed in the list file */
1718int abis_nm_bs11_load_swl(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00001719 u_int8_t win_size, int forced, gsm_cbfn *cbfn)
Harald Welte5e4d1b32009-02-01 13:36:56 +00001720{
1721 struct abis_nm_bs11_sw *bs11_sw = g_bs11_sw;
1722 struct file_list_entry *fle;
1723 int rc = 0;
1724
1725 INIT_LLIST_HEAD(&bs11_sw->file_list);
1726 bs11_sw->bts = bts;
1727 bs11_sw->win_size = win_size;
1728 bs11_sw->user_cb = cbfn;
Harald Welte3ffd1372009-02-01 22:15:49 +00001729 bs11_sw->forced = forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001730
1731 strncpy(bs11_sw->swl_fname, fname, sizeof(bs11_sw->swl_fname));
1732 rc = bs11_read_swl_file(bs11_sw);
1733 if (rc < 0)
1734 return rc;
1735
1736 /* dequeue next item in file list */
1737 fle = fl_dequeue(&bs11_sw->file_list);
1738 if (!fle)
1739 return -EINVAL;
1740
1741 /* start download the next file of our file list */
Harald Welte3ffd1372009-02-01 22:15:49 +00001742 rc = abis_nm_software_load(bts, fle->fname, win_size, forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00001743 bs11_swload_cbfn, bs11_sw);
1744 free(fle);
1745 return rc;
1746}
1747
Harald Welte5083b0b2009-02-02 19:20:52 +00001748#if 0
Harald Welte5e4d1b32009-02-01 13:36:56 +00001749static u_int8_t req_attr_btse[] = {
1750 NM_ATT_ADM_STATE, NM_ATT_BS11_LMT_LOGON_SESSION,
1751 NM_ATT_BS11_LMT_LOGIN_TIME, NM_ATT_BS11_LMT_USER_ACC_LEV,
1752 NM_ATT_BS11_LMT_USER_NAME,
1753
1754 0xaf, NM_ATT_BS11_RX_OFFSET, NM_ATT_BS11_VENDOR_NAME,
1755
1756 NM_ATT_BS11_SW_LOAD_INTENDED, NM_ATT_BS11_SW_LOAD_SAFETY,
1757
1758 NM_ATT_BS11_SW_LOAD_STORED };
1759
1760static u_int8_t req_attr_btsm[] = {
1761 NM_ATT_ABIS_CHANNEL, NM_ATT_TEI, NM_ATT_BS11_ABIS_EXT_TIME,
1762 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xce, NM_ATT_FILE_ID,
1763 NM_ATT_FILE_VERSION, NM_ATT_OPER_STATE, 0xe8, NM_ATT_BS11_ALL_TEST_CATG,
1764 NM_ATT_SW_DESCR, NM_ATT_GET_ARI };
Harald Welte5083b0b2009-02-02 19:20:52 +00001765#endif
Harald Welte5e4d1b32009-02-01 13:36:56 +00001766
1767static u_int8_t req_attr[] = {
1768 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xa8, NM_ATT_OPER_STATE,
1769 0xd5, 0xa1, NM_ATT_BS11_ESN_FW_CODE_NO, NM_ATT_BS11_ESN_HW_CODE_NO,
1770 0x42, NM_ATT_BS11_ESN_PCB_SERIAL };
1771
1772int abis_nm_bs11_get_serno(struct gsm_bts *bts)
1773{
1774 struct abis_om_hdr *oh;
1775 struct msgb *msg = nm_msgb_alloc();
1776
1777 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1778 /* SiemensHW CCTRL object */
1779 fill_om_fom_hdr(oh, 2+sizeof(req_attr), NM_MT_GET_ATTR, NM_OC_BS11,
1780 0x03, 0x00, 0x00);
1781 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(req_attr), req_attr);
1782
1783 return abis_nm_sendmsg(bts, msg);
1784}
Harald Welte268bb402009-02-01 19:11:56 +00001785
1786int abis_nm_bs11_set_ext_time(struct gsm_bts *bts)
1787{
1788 struct abis_om_hdr *oh;
1789 struct msgb *msg = nm_msgb_alloc();
1790 struct bs11_date_time aet;
1791
1792 get_bs11_date_time(&aet);
1793 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1794 /* SiemensHW CCTRL object */
1795 fill_om_fom_hdr(oh, 2+sizeof(aet), NM_MT_BS11_SET_ATTR, NM_OC_SITE_MANAGER,
1796 0xff, 0xff, 0xff);
Harald Welte5083b0b2009-02-02 19:20:52 +00001797 msgb_tlv_put(msg, NM_ATT_BS11_ABIS_EXT_TIME, sizeof(aet), (u_int8_t *) &aet);
Harald Welte268bb402009-02-01 19:11:56 +00001798
1799 return abis_nm_sendmsg(bts, msg);
1800}
Harald Welte5c1e4582009-02-15 11:57:29 +00001801
1802/* ip.access nanoBTS specific commands */
1803
1804static const char ipaccess_magic[] = "com.ipaccess";
1805
1806int abis_nm_ipaccess_msg(struct gsm_bts *bts, u_int8_t msg_type,
1807 u_int8_t obj_class, u_int8_t bts_nr,
1808 u_int8_t trx_nr, u_int8_t ts_nr,
1809 u_int8_t *attr, int attr_len)
1810{
1811 struct msgb *msg = nm_msgb_alloc();
1812 struct abis_om_hdr *oh;
1813 struct abis_om_fom_hdr *foh;
1814 u_int8_t *data;
1815
1816 /* construct the 12.21 OM header, observe the erroneous length */
1817 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
1818 fill_om_hdr(oh, sizeof(*foh) + attr_len);
1819 oh->mdisc = ABIS_OM_MDISC_MANUF;
1820
1821 /* add the ip.access magic */
1822 data = msgb_put(msg, sizeof(ipaccess_magic)+1);
1823 *data++ = sizeof(ipaccess_magic);
1824 memcpy(data, ipaccess_magic, sizeof(ipaccess_magic));
1825
1826 /* fill the 12.21 FOM header */
1827 foh = (struct abis_om_fom_hdr *) msgb_put(msg, sizeof(*foh));
1828 foh->msg_type = msg_type;
1829 foh->obj_class = obj_class;
1830 foh->obj_inst.bts_nr = bts_nr;
1831 foh->obj_inst.trx_nr = trx_nr;
1832 foh->obj_inst.ts_nr = ts_nr;
1833
1834 if (attr && attr_len) {
1835 data = msgb_put(msg, attr_len);
1836 memcpy(data, attr, attr_len);
1837 }
1838
1839 return abis_nm_sendmsg(bts, msg);
1840}