blob: a446f29bf7dcf2becdc8be76f4dc6e62b349a6c3 [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 Welte677c21f2009-02-17 13:22:23 +000037#include <arpa/inet.h>
Harald Welte52b1f982008-12-23 20:25:15 +000038
Harald Welte8470bf22008-12-25 23:28:35 +000039#include <openbsc/gsm_data.h>
40#include <openbsc/debug.h>
41#include <openbsc/msgb.h>
42#include <openbsc/tlv.h>
43#include <openbsc/abis_nm.h>
Holger Freytherca362a62009-01-04 21:05:01 +000044#include <openbsc/misdn.h>
Harald Welte52b1f982008-12-23 20:25:15 +000045
Harald Welte8470bf22008-12-25 23:28:35 +000046#define OM_ALLOC_SIZE 1024
47#define OM_HEADROOM_SIZE 128
Harald Welte52b1f982008-12-23 20:25:15 +000048
49/* unidirectional messages from BTS to BSC */
50static const enum abis_nm_msgtype reports[] = {
51 NM_MT_SW_ACTIVATED_REP,
52 NM_MT_TEST_REP,
53 NM_MT_STATECHG_EVENT_REP,
54 NM_MT_FAILURE_EVENT_REP,
55};
56
57/* messages without ACK/NACK */
58static const enum abis_nm_msgtype no_ack_nack[] = {
59 NM_MT_MEAS_RES_REQ,
60 NM_MT_STOP_MEAS,
61 NM_MT_START_MEAS,
62};
63
Harald Welte4724f992009-01-18 18:01:49 +000064/* Messages related to software load */
65static const enum abis_nm_msgtype sw_load_msgs[] = {
66 NM_MT_LOAD_INIT_ACK,
67 NM_MT_LOAD_INIT_NACK,
68 NM_MT_LOAD_SEG_ACK,
69 NM_MT_LOAD_ABORT,
70 NM_MT_LOAD_END_ACK,
71 NM_MT_LOAD_END_NACK,
Harald Welte34a99682009-02-13 02:41:40 +000072 //NM_MT_SW_ACT_REQ,
Harald Welte4724f992009-01-18 18:01:49 +000073 NM_MT_ACTIVATE_SW_ACK,
74 NM_MT_ACTIVATE_SW_NACK,
75 NM_MT_SW_ACTIVATED_REP,
76};
77
Harald Weltee0590df2009-02-15 03:34:15 +000078static const enum abis_nm_msgtype nacks[] = {
79 NM_MT_LOAD_INIT_NACK,
80 NM_MT_LOAD_END_NACK,
81 NM_MT_SW_ACT_REQ_NACK,
82 NM_MT_ACTIVATE_SW_NACK,
83 NM_MT_ESTABLISH_TEI_NACK,
84 NM_MT_CONN_TERR_SIGN_NACK,
85 NM_MT_DISC_TERR_SIGN_NACK,
86 NM_MT_CONN_TERR_TRAF_NACK,
87 NM_MT_DISC_TERR_TRAF_NACK,
88 NM_MT_CONN_MDROP_LINK_NACK,
89 NM_MT_DISC_MDROP_LINK_NACK,
90 NM_MT_SET_BTS_ATTR_NACK,
91 NM_MT_SET_RADIO_ATTR_NACK,
92 NM_MT_SET_CHAN_ATTR_NACK,
93 NM_MT_PERF_TEST_NACK,
94 NM_MT_SEND_TEST_REP_NACK,
95 NM_MT_STOP_TEST_NACK,
96 NM_MT_STOP_EVENT_REP_NACK,
97 NM_MT_REST_EVENT_REP_NACK,
98 NM_MT_CHG_ADM_STATE_NACK,
99 NM_MT_CHG_ADM_STATE_REQ_NACK,
100 NM_MT_REP_OUTST_ALARMS_NACK,
101 NM_MT_CHANGEOVER_NACK,
102 NM_MT_OPSTART_NACK,
103 NM_MT_REINIT_NACK,
104 NM_MT_SET_SITE_OUT_NACK,
105 NM_MT_CHG_HW_CONF_NACK,
106 NM_MT_GET_ATTR_NACK,
107 NM_MT_SET_ALARM_THRES_NACK,
108 NM_MT_BS11_BEGIN_DB_TX_NACK,
109 NM_MT_BS11_END_DB_TX_NACK,
110 NM_MT_BS11_CREATE_OBJ_NACK,
111 NM_MT_BS11_DELETE_OBJ_NACK,
112};
Harald Welte52b1f982008-12-23 20:25:15 +0000113/* Attributes that the BSC can set, not only get, according to Section 9.4 */
114static const enum abis_nm_attr nm_att_settable[] = {
115 NM_ATT_ADD_INFO,
116 NM_ATT_ADD_TEXT,
117 NM_ATT_DEST,
118 NM_ATT_EVENT_TYPE,
119 NM_ATT_FILE_DATA,
120 NM_ATT_GET_ARI,
121 NM_ATT_HW_CONF_CHG,
122 NM_ATT_LIST_REQ_ATTR,
123 NM_ATT_MDROP_LINK,
124 NM_ATT_MDROP_NEXT,
125 NM_ATT_NACK_CAUSES,
126 NM_ATT_OUTST_ALARM,
127 NM_ATT_PHYS_CONF,
128 NM_ATT_PROB_CAUSE,
129 NM_ATT_RAD_SUBC,
130 NM_ATT_SOURCE,
131 NM_ATT_SPEC_PROB,
132 NM_ATT_START_TIME,
133 NM_ATT_TEST_DUR,
134 NM_ATT_TEST_NO,
135 NM_ATT_TEST_REPORT,
136 NM_ATT_WINDOW_SIZE,
137 NM_ATT_SEVERITY,
138 NM_ATT_MEAS_RES,
139 NM_ATT_MEAS_TYPE,
140};
141
Harald Weltee0590df2009-02-15 03:34:15 +0000142static const struct tlv_definition nm_att_tlvdef = {
143 .def = {
144 [NM_ATT_ABIS_CHANNEL] = { TLV_TYPE_FIXED, 3 },
145 [NM_ATT_ADD_INFO] = { TLV_TYPE_TL16V },
146 [NM_ATT_ADD_TEXT] = { TLV_TYPE_TL16V },
147 [NM_ATT_ADM_STATE] = { TLV_TYPE_TV },
148 [NM_ATT_ARFCN_LIST]= { TLV_TYPE_TL16V },
149 [NM_ATT_AUTON_REPORT] = { TLV_TYPE_TV },
150 [NM_ATT_AVAIL_STATUS] = { TLV_TYPE_TL16V },
151 [NM_ATT_BCCH_ARFCN] = { TLV_TYPE_FIXED, 2 },
152 [NM_ATT_BSIC] = { TLV_TYPE_TV },
153 [NM_ATT_BTS_AIR_TIMER] = { TLV_TYPE_TV },
154 [NM_ATT_CCCH_L_I_P] = { TLV_TYPE_TV },
155 [NM_ATT_CCCH_L_T] = { TLV_TYPE_TV },
156 [NM_ATT_CHAN_COMB] = { TLV_TYPE_TV },
157 [NM_ATT_CONN_FAIL_CRIT] = { TLV_TYPE_TL16V },
158 [NM_ATT_DEST] = { TLV_TYPE_TL16V },
159 [NM_ATT_EVENT_TYPE] = { TLV_TYPE_TV },
160 [NM_ATT_FILE_DATA] = { TLV_TYPE_TL16V },
161 [NM_ATT_FILE_ID] = { TLV_TYPE_TL16V },
162 [NM_ATT_FILE_VERSION] = { TLV_TYPE_TL16V },
163 [NM_ATT_GSM_TIME] = { TLV_TYPE_FIXED, 2 },
164 [NM_ATT_HSN] = { TLV_TYPE_TV },
165 [NM_ATT_HW_CONFIG] = { TLV_TYPE_TL16V },
166 [NM_ATT_HW_DESC] = { TLV_TYPE_TL16V },
167 [NM_ATT_INTAVE_PARAM] = { TLV_TYPE_TV },
168 [NM_ATT_INTERF_BOUND] = { TLV_TYPE_FIXED, 6 },
169 [NM_ATT_LIST_REQ_ATTR] = { TLV_TYPE_TL16V },
170 [NM_ATT_MAIO] = { TLV_TYPE_TV },
171 [NM_ATT_MANUF_STATE] = { TLV_TYPE_TV },
172 [NM_ATT_MANUF_THRESH] = { TLV_TYPE_TL16V },
173 [NM_ATT_MANUF_ID] = { TLV_TYPE_TL16V },
174 [NM_ATT_MAX_TA] = { TLV_TYPE_TV },
175 [NM_ATT_MDROP_LINK] = { TLV_TYPE_FIXED, 2 },
176 [NM_ATT_MDROP_NEXT] = { TLV_TYPE_FIXED, 2 },
177 [NM_ATT_NACK_CAUSES] = { TLV_TYPE_TV },
178 [NM_ATT_NY1] = { TLV_TYPE_TV },
179 [NM_ATT_OPER_STATE] = { TLV_TYPE_TV },
180 [NM_ATT_OVERL_PERIOD] = { TLV_TYPE_TL16V },
181 [NM_ATT_PHYS_CONF] = { TLV_TYPE_TL16V },
182 [NM_ATT_POWER_CLASS] = { TLV_TYPE_TV },
183 [NM_ATT_POWER_THRESH] = { TLV_TYPE_FIXED, 3 },
184 [NM_ATT_PROB_CAUSE] = { TLV_TYPE_FIXED, 3 },
185 [NM_ATT_RACH_B_THRESH] = { TLV_TYPE_TV },
186 [NM_ATT_LDAVG_SLOTS] = { TLV_TYPE_FIXED, 2 },
187 [NM_ATT_RAD_SUBC] = { TLV_TYPE_TV },
188 [NM_ATT_RF_MAXPOWR_R] = { TLV_TYPE_TV },
189 [NM_ATT_SITE_INPUTS] = { TLV_TYPE_TL16V },
190 [NM_ATT_SITE_OUTPUTS] = { TLV_TYPE_TL16V },
191 [NM_ATT_SOURCE] = { TLV_TYPE_TL16V },
192 [NM_ATT_SPEC_PROB] = { TLV_TYPE_TV },
193 [NM_ATT_START_TIME] = { TLV_TYPE_FIXED, 2 },
194 [NM_ATT_T200] = { TLV_TYPE_FIXED, 7 },
195 [NM_ATT_TEI] = { TLV_TYPE_TV },
196 [NM_ATT_TEST_DUR] = { TLV_TYPE_FIXED, 2 },
197 [NM_ATT_TEST_NO] = { TLV_TYPE_TV },
198 [NM_ATT_TEST_REPORT] = { TLV_TYPE_TL16V },
199 [NM_ATT_VSWR_THRESH] = { TLV_TYPE_FIXED, 2 },
200 [NM_ATT_WINDOW_SIZE] = { TLV_TYPE_TV },
201 [NM_ATT_TSC] = { TLV_TYPE_TV },
202 [NM_ATT_SW_CONFIG] = { TLV_TYPE_TL16V },
203 [NM_ATT_SEVERITY] = { TLV_TYPE_TV },
204 [NM_ATT_GET_ARI] = { TLV_TYPE_TL16V },
205 [NM_ATT_HW_CONF_CHG] = { TLV_TYPE_TL16V },
206 [NM_ATT_OUTST_ALARM] = { TLV_TYPE_TV },
207 [NM_ATT_FILE_DATA] = { TLV_TYPE_TL16V },
208 [NM_ATT_MEAS_RES] = { TLV_TYPE_TL16V },
209 /* BS11 specifics */
210 [NM_ATT_BS11_PASSWORD] = { TLV_TYPE_TLV },
211 [NM_ATT_BS11_TXPWR] = { TLV_TYPE_TLV },
212 [NM_ATT_BS11_RSSI_OFFS] = { TLV_TYPE_TLV },
213 [NM_ATT_BS11_LINE_CFG] = { TLV_TYPE_TV },
214 [NM_ATT_BS11_L1_PROT_TYPE] = { TLV_TYPE_TV },
215 [NM_ATT_BS11_BIT_ERR_THESH] = { TLV_TYPE_FIXED, 2 },
216 [NM_ATT_BS11_DIVERSITY] = { TLV_TYPE_TLV },
217 [NM_ATT_BS11_LMT_LOGIN_TIME] = { TLV_TYPE_TLV },
218 [NM_ATT_BS11_LMT_USER_ACC_LEV] ={ TLV_TYPE_TLV },
219 [NM_ATT_BS11_LMT_USER_NAME] = { TLV_TYPE_TLV },
Harald Welte677c21f2009-02-17 13:22:23 +0000220 /* ip.access specifics */
221 [NM_ATT_IPACC_RSL_BSC_IP] = { TLV_TYPE_FIXED, 4 },
222 [NM_ATT_IPACC_RSL_BSC_PORT] = { TLV_TYPE_FIXED, 2 },
223 [0x85] = { TLV_TYPE_TV },
224
Harald Weltee0590df2009-02-15 03:34:15 +0000225 },
226};
227#define nm_tlv_parse(dec, buf, len) tlv_parse(dec, &nm_att_tlvdef, buf, len)
228
Harald Welte52b1f982008-12-23 20:25:15 +0000229static int is_in_arr(enum abis_nm_msgtype mt, const enum abis_nm_msgtype *arr, int size)
230{
231 int i;
232
233 for (i = 0; i < size; i++) {
234 if (arr[i] == mt)
235 return 1;
236 }
237
238 return 0;
239}
240
Holger Freytherca362a62009-01-04 21:05:01 +0000241#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000242/* is this msgtype the usual ACK/NACK type ? */
243static int is_ack_nack(enum abis_nm_msgtype mt)
244{
245 return !is_in_arr(mt, no_ack_nack, ARRAY_SIZE(no_ack_nack));
246}
Holger Freytherca362a62009-01-04 21:05:01 +0000247#endif
Harald Welte52b1f982008-12-23 20:25:15 +0000248
249/* is this msgtype a report ? */
250static int is_report(enum abis_nm_msgtype mt)
251{
Harald Welte8470bf22008-12-25 23:28:35 +0000252 return is_in_arr(mt, reports, ARRAY_SIZE(reports));
Harald Welte52b1f982008-12-23 20:25:15 +0000253}
254
255#define MT_ACK(x) (x+1)
256#define MT_NACK(x) (x+2)
257
258static void fill_om_hdr(struct abis_om_hdr *oh, u_int8_t len)
259{
260 oh->mdisc = ABIS_OM_MDISC_FOM;
261 oh->placement = ABIS_OM_PLACEMENT_ONLY;
262 oh->sequence = 0;
263 oh->length = len;
264}
265
266static void fill_om_fom_hdr(struct abis_om_hdr *oh, u_int8_t len,
267 u_int8_t msg_type, u_int8_t obj_class,
268 u_int8_t bts_nr, u_int8_t trx_nr, u_int8_t ts_nr)
269{
270 struct abis_om_fom_hdr *foh =
271 (struct abis_om_fom_hdr *) oh->data;
272
Harald Welte702d8702008-12-26 20:25:35 +0000273 fill_om_hdr(oh, len+sizeof(*foh));
Harald Welte52b1f982008-12-23 20:25:15 +0000274 foh->msg_type = msg_type;
275 foh->obj_class = obj_class;
276 foh->obj_inst.bts_nr = bts_nr;
277 foh->obj_inst.trx_nr = trx_nr;
278 foh->obj_inst.ts_nr = ts_nr;
279}
280
Harald Welte8470bf22008-12-25 23:28:35 +0000281static struct msgb *nm_msgb_alloc(void)
282{
283 return msgb_alloc_headroom(OM_ALLOC_SIZE, OM_HEADROOM_SIZE);
284}
285
Harald Welte52b1f982008-12-23 20:25:15 +0000286/* Send a OML NM Message from BSC to BTS */
287int abis_nm_sendmsg(struct gsm_bts *bts, struct msgb *msg)
288{
Holger Freyther59639e82009-02-09 23:09:55 +0000289 msg->trx = bts->c0;
290
Harald Weltead384642008-12-26 10:20:07 +0000291 return _abis_nm_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000292}
293
Harald Welte4724f992009-01-18 18:01:49 +0000294static int abis_nm_rcvmsg_sw(struct msgb *mb);
295
Harald Welte34a99682009-02-13 02:41:40 +0000296const char *oc_names[] = {
297 [NM_OC_SITE_MANAGER] = "SITE MANAGER",
298 [NM_OC_BTS] = "BTS",
299 [NM_OC_RADIO_CARRIER] = "RADIO CARRIER",
300 [NM_OC_BASEB_TRANSC] = "BASEBAND TRANSCEIVER",
301 [NM_OC_CHANNEL] = "CHANNEL",
302};
303
304static const char *obj_class_name(u_int8_t oc)
305{
306 if (oc >= ARRAY_SIZE(oc_names))
307 return "UNKNOWN";
308 return oc_names[oc];
309}
310
311static const char *opstate_name(u_int8_t os)
312{
313 switch (os) {
314 case 1:
315 return "Disabled";
316 case 2:
317 return "Enabled";
318 case 0xff:
319 return "NULL";
320 default:
321 return "RFU";
322 }
323}
324
Harald Weltee0590df2009-02-15 03:34:15 +0000325/* Chapter 9.4.7 */
326const char *avail_names[] = {
327 "In test",
328 "Failed",
329 "Power off",
330 "Off line",
331 "<not used>",
332 "Dependency",
333 "Degraded",
334 "Not installed",
335};
336
337static const char *avail_name(u_int8_t avail)
338{
339 if (avail >= ARRAY_SIZE(avail_names))
340 return "UNKNOWN";
341 return avail_names[avail];
342}
343
344
345/* obtain the gsm_nm_state data structure for a given object instance */
346static struct gsm_nm_state *
347objclass2nmstate(struct gsm_bts *bts, u_int8_t obj_class,
348 struct abis_om_obj_inst *obj_inst)
349{
350 struct gsm_bts_trx *trx;
351 struct gsm_nm_state *nm_state = NULL;
352
353 switch (obj_class) {
354 case NM_OC_BTS:
355 nm_state = &bts->nm_state;
356 break;
357 case NM_OC_RADIO_CARRIER:
358 if (obj_inst->trx_nr >= bts->num_trx)
359 return NULL;
360 trx = &bts->trx[obj_inst->trx_nr];
361 nm_state = &trx->nm_state;
362 break;
363 case NM_OC_BASEB_TRANSC:
364 if (obj_inst->trx_nr >= bts->num_trx)
365 return NULL;
366 trx = &bts->trx[obj_inst->trx_nr];
367 nm_state = &trx->bb_transc.nm_state;
368 break;
369 case NM_OC_CHANNEL:
370 if (obj_inst->trx_nr > bts->num_trx)
371 return NULL;
372 trx = &bts->trx[obj_inst->trx_nr];
373 if (obj_inst->ts_nr >= TRX_NR_TS)
374 return NULL;
375 nm_state = &trx->ts[obj_inst->ts_nr].nm_state;
376 break;
377 case NM_OC_SITE_MANAGER:
378 nm_state = &bts->site_mgr.nm_state;
379 break;
380 }
381 return nm_state;
382}
383
384/* obtain the in-memory data structure of a given object instance */
385static void *
386objclass2obj(struct gsm_bts *bts, u_int8_t obj_class,
387 struct abis_om_obj_inst *obj_inst)
388{
389 struct gsm_bts_trx *trx;
390 void *obj = NULL;
391
392 switch (obj_class) {
393 case NM_OC_BTS:
394 obj = bts;
395 break;
396 case NM_OC_RADIO_CARRIER:
397 if (obj_inst->trx_nr >= bts->num_trx)
398 return NULL;
399 trx = &bts->trx[obj_inst->trx_nr];
400 obj = trx;
401 break;
402 case NM_OC_BASEB_TRANSC:
403 if (obj_inst->trx_nr >= bts->num_trx)
404 return NULL;
405 trx = &bts->trx[obj_inst->trx_nr];
406 obj = &trx->bb_transc;
407 break;
408 case NM_OC_CHANNEL:
409 if (obj_inst->trx_nr > bts->num_trx)
410 return NULL;
411 trx = &bts->trx[obj_inst->trx_nr];
412 if (obj_inst->ts_nr >= TRX_NR_TS)
413 return NULL;
414 obj = &trx->ts[obj_inst->ts_nr];
415 break;
416 case NM_OC_SITE_MANAGER:
417 obj = &bts->site_mgr;
418 break;
419 }
420 return obj;
421}
422
423/* Update the administrative state of a given object in our in-memory data
424 * structures and send an event to the higher layer */
425static int update_admstate(struct gsm_bts *bts, u_int8_t obj_class,
426 struct abis_om_obj_inst *obj_inst, u_int8_t adm_state)
427{
428 struct gsm_nm_state *nm_state;
429 void *obj;
430 int rc;
431
432 nm_state = objclass2nmstate(bts, obj_class, obj_inst);
433 obj = objclass2obj(bts, obj_class, obj_inst);
434 rc = nm_state_event(EVT_STATECHG_ADM, obj_class, obj, nm_state, adm_state);
435 if (nm_state)
436 nm_state->administrative = adm_state;
437
438 return rc;
439}
440
Harald Welte97ed1e72009-02-06 13:38:02 +0000441static int abis_nm_rx_statechg_rep(struct msgb *mb)
442{
Harald Weltee0590df2009-02-15 03:34:15 +0000443 struct abis_om_hdr *oh = msgb_l2(mb);
Harald Welte97ed1e72009-02-06 13:38:02 +0000444 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Harald Welte22af0db2009-02-14 15:41:08 +0000445 struct gsm_bts *bts = mb->trx->bts;
Harald Weltee0590df2009-02-15 03:34:15 +0000446 struct tlv_parsed tp;
447 struct gsm_nm_state *nm_state, new_state;
448 int rc;
449
Harald Welte34a99682009-02-13 02:41:40 +0000450 DEBUGP(DNM, "STATE CHG: OC=%s(%02x) INST=(%02x,%02x,%02x) ",
451 obj_class_name(foh->obj_class), foh->obj_class,
452 foh->obj_inst.bts_nr, foh->obj_inst.trx_nr,
Harald Welte97ed1e72009-02-06 13:38:02 +0000453 foh->obj_inst.ts_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000454
455 nm_state = objclass2nmstate(bts, foh->obj_class, &foh->obj_inst);
456 if (!nm_state) {
457 DEBUGPC(DNM, "\n");
458 return -EINVAL;
Harald Welte22af0db2009-02-14 15:41:08 +0000459 }
Harald Weltee0590df2009-02-15 03:34:15 +0000460
461 new_state = *nm_state;
462
463 nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
464 if (TLVP_PRESENT(&tp, NM_ATT_OPER_STATE)) {
465 new_state.operational = *TLVP_VAL(&tp, NM_ATT_OPER_STATE);
466 DEBUGPC(DNM, "OP_STATE=%s ", opstate_name(new_state.operational));
467 }
468 if (TLVP_PRESENT(&tp, NM_ATT_AVAIL_STATUS)) {
469 new_state.availability = *TLVP_VAL(&tp, NM_ATT_AVAIL_STATUS);
470 DEBUGPC(DNM, "AVAIL=%s(%02x) ", avail_name(new_state.availability),
471 new_state.availability);
472 }
473 if (TLVP_PRESENT(&tp, NM_ATT_ADM_STATE)) {
474 new_state.administrative = *TLVP_VAL(&tp, NM_ATT_ADM_STATE);
475 DEBUGPC(DNM, "ADM=%02x ", new_state.administrative);
Harald Welte97ed1e72009-02-06 13:38:02 +0000476 }
477 DEBUGPC(DNM, "\n");
Harald Weltee0590df2009-02-15 03:34:15 +0000478
479 if (memcmp(&new_state, nm_state, sizeof(new_state))) {
480 /* Update the operational state of a given object in our in-memory data
481 * structures and send an event to the higher layer */
482 void *obj = objclass2obj(bts, foh->obj_class, &foh->obj_inst);
483 rc = nm_state_event(EVT_STATECHG_OPER, foh->obj_class, obj, nm_state, &new_state);
484 *nm_state = new_state;
485 }
486#if 0
Harald Welte22af0db2009-02-14 15:41:08 +0000487 if (op_state == 1) {
488 /* try to enable objects that are disabled */
489 abis_nm_opstart(bts, foh->obj_class,
490 foh->obj_inst.bts_nr,
491 foh->obj_inst.trx_nr,
492 foh->obj_inst.ts_nr);
493 }
Harald Weltee0590df2009-02-15 03:34:15 +0000494#endif
Harald Welte97ed1e72009-02-06 13:38:02 +0000495 return 0;
496}
497
498static int abis_nm_rcvmsg_report(struct msgb *mb)
499{
500 struct abis_om_fom_hdr *foh = msgb_l3(mb);
501 u_int8_t mt = foh->msg_type;
502
503 //nmh->cfg->report_cb(mb, foh);
504
505 switch (mt) {
506 case NM_MT_STATECHG_EVENT_REP:
507 return abis_nm_rx_statechg_rep(mb);
508 break;
Harald Welte34a99682009-02-13 02:41:40 +0000509 case NM_MT_SW_ACTIVATED_REP:
510 DEBUGP(DNM, "Software Activated Report\n");
511 break;
Harald Weltee0590df2009-02-15 03:34:15 +0000512 case NM_MT_FAILURE_EVENT_REP:
513 DEBUGP(DNM, "Failure Event Report\n");
514 break;
515 default:
516 DEBUGP(DNM, "reporting NM MT 0x%02x\n", mt);
517 break;
518
Harald Welte97ed1e72009-02-06 13:38:02 +0000519 };
520
Harald Welte97ed1e72009-02-06 13:38:02 +0000521 return 0;
522}
523
Harald Welte34a99682009-02-13 02:41:40 +0000524/* Activate the specified software into the BTS */
525static int ipacc_sw_activate(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1,
526 u_int8_t i2, u_int8_t *sw_desc, u_int8_t swdesc_len)
527{
528 struct abis_om_hdr *oh;
529 struct msgb *msg = nm_msgb_alloc();
530 u_int8_t len = swdesc_len;
531 u_int8_t *trailer;
532
533 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
534 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, obj_class, i0, i1, i2);
535
536 trailer = msgb_put(msg, swdesc_len);
537 memcpy(trailer, sw_desc, swdesc_len);
538
539 return abis_nm_sendmsg(bts, msg);
540}
541
542static int abis_nm_rx_sw_act_req(struct msgb *mb)
543{
544 struct abis_om_hdr *oh = msgb_l2(mb);
545 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Harald Welte5c1e4582009-02-15 11:57:29 +0000546 int nack = 0;
Harald Welte34a99682009-02-13 02:41:40 +0000547 int ret;
548
Harald Welte5c1e4582009-02-15 11:57:29 +0000549 DEBUGP(DNM, "Software Activate Request ");
Harald Welte34a99682009-02-13 02:41:40 +0000550
Harald Welte5c1e4582009-02-15 11:57:29 +0000551 if (foh->obj_class >= 0xf0 && foh->obj_class <= 0xf3) {
552 DEBUGPC(DNM, "NACKing for GPRS obj_class 0x%02x\n", foh->obj_class);
553 nack = 1;
554 } else
555 DEBUGPC(DNM, "ACKing and Activating\n");
556
557 ret = abis_nm_sw_act_req_ack(mb->trx->bts, foh->obj_class,
Harald Welte34a99682009-02-13 02:41:40 +0000558 foh->obj_inst.bts_nr,
559 foh->obj_inst.trx_nr,
Harald Welte5c1e4582009-02-15 11:57:29 +0000560 foh->obj_inst.ts_nr, nack,
Harald Welte34a99682009-02-13 02:41:40 +0000561 foh->data, oh->length-sizeof(*foh));
562
Harald Welte5c1e4582009-02-15 11:57:29 +0000563 if (nack)
564 return ret;
565
Harald Welte34a99682009-02-13 02:41:40 +0000566 /* FIXME: properly parse attributes */
567 return ipacc_sw_activate(mb->trx->bts, foh->obj_class,
568 foh->obj_inst.bts_nr,
569 foh->obj_inst.trx_nr,
570 foh->obj_inst.ts_nr,
571 foh->data + oh->length-sizeof(*foh)-22, 22);
572}
573
Harald Weltee0590df2009-02-15 03:34:15 +0000574/* Receive a CHANGE_ADM_STATE_ACK, parse the TLV and update local state */
575static int abis_nm_rx_chg_adm_state_ack(struct msgb *mb)
576{
577 struct abis_om_hdr *oh = msgb_l2(mb);
578 struct abis_om_fom_hdr *foh = msgb_l3(mb);
579 struct tlv_parsed tp;
580 u_int8_t adm_state;
581
582 nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
583 if (!TLVP_PRESENT(&tp, NM_ATT_ADM_STATE))
584 return -EINVAL;
585
586 adm_state = *TLVP_VAL(&tp, NM_ATT_ADM_STATE);
587
588 return update_admstate(mb->trx->bts, foh->obj_class, &foh->obj_inst, adm_state);
589}
590
Harald Welte52b1f982008-12-23 20:25:15 +0000591/* Receive a OML NM Message from BTS */
Harald Welte8470bf22008-12-25 23:28:35 +0000592static int abis_nm_rcvmsg_fom(struct msgb *mb)
Harald Welte52b1f982008-12-23 20:25:15 +0000593{
594 struct abis_om_fom_hdr *foh = msgb_l3(mb);
595 u_int8_t mt = foh->msg_type;
596
597 /* check for unsolicited message */
Harald Welte97ed1e72009-02-06 13:38:02 +0000598 if (is_report(mt))
599 return abis_nm_rcvmsg_report(mb);
Harald Welte52b1f982008-12-23 20:25:15 +0000600
Harald Welte4724f992009-01-18 18:01:49 +0000601 if (is_in_arr(mt, sw_load_msgs, ARRAY_SIZE(sw_load_msgs)))
602 return abis_nm_rcvmsg_sw(mb);
603
Harald Weltee0590df2009-02-15 03:34:15 +0000604 if (is_in_arr(mt, nacks, ARRAY_SIZE(nacks)))
605 DEBUGP(DNM, "NACK 0x%02x\n", mt);
Harald Weltead384642008-12-26 10:20:07 +0000606#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000607 /* check if last message is to be acked */
608 if (is_ack_nack(nmh->last_msgtype)) {
609 if (mt == MT_ACK(nmh->last_msgtype)) {
610 fprintf(stderr, "received ACK (0x%x)\n",
611 foh->msg_type);
612 /* we got our ACK, continue sending the next msg */
613 } else if (mt == MT_NACK(nmh->last_msgtype)) {
614 /* we got a NACK, signal this to the caller */
615 fprintf(stderr, "received NACK (0x%x)\n",
616 foh->msg_type);
617 /* FIXME: somehow signal this to the caller */
618 } else {
619 /* really strange things happen */
620 return -EINVAL;
621 }
622 }
Harald Weltead384642008-12-26 10:20:07 +0000623#endif
624
Harald Welte97ed1e72009-02-06 13:38:02 +0000625 switch (mt) {
Harald Weltee0590df2009-02-15 03:34:15 +0000626 case NM_MT_CHG_ADM_STATE_ACK:
627 return abis_nm_rx_chg_adm_state_ack(mb);
628 break;
Harald Welte34a99682009-02-13 02:41:40 +0000629 case NM_MT_SW_ACT_REQ:
630 return abis_nm_rx_sw_act_req(mb);
631 break;
Harald Welte97ed1e72009-02-06 13:38:02 +0000632 case NM_MT_BS11_LMT_SESSION:
633 DEBUGP(DNM, "LMT Event: \n");
634 break;
635 }
636
Harald Weltead384642008-12-26 10:20:07 +0000637 return 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000638}
639
Harald Welte677c21f2009-02-17 13:22:23 +0000640static int abis_nm_rx_ipacc(struct msgb *mb);
641
642static int abis_nm_rcvmsg_manuf(struct msgb *mb)
643{
644 int rc;
645 int bts_type = mb->trx->bts->type;
646
647 switch (bts_type) {
648 case GSM_BTS_TYPE_NANOBTS_900:
649 case GSM_BTS_TYPE_NANOBTS_1800:
650 rc = abis_nm_rx_ipacc(mb);
651 break;
652 default:
653 fprintf(stderr, "don't know how to parse OML for this "
654 "BTS type (%u)\n", bts_type);
655 rc = 0;
656 break;
657 }
658
659 return rc;
660}
661
Harald Welte52b1f982008-12-23 20:25:15 +0000662/* High-Level API */
663/* Entry-point where L2 OML from BTS enters the NM code */
Harald Welte8470bf22008-12-25 23:28:35 +0000664int abis_nm_rcvmsg(struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +0000665{
Harald Welte52b1f982008-12-23 20:25:15 +0000666 struct abis_om_hdr *oh = msgb_l2(msg);
Harald Welte677c21f2009-02-17 13:22:23 +0000667 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000668
669 /* Various consistency checks */
670 if (oh->placement != ABIS_OM_PLACEMENT_ONLY) {
671 fprintf(stderr, "ABIS OML placement 0x%x not supported\n",
672 oh->placement);
673 return -EINVAL;
674 }
675 if (oh->sequence != 0) {
676 fprintf(stderr, "ABIS OML sequence 0x%x != 0x00\n",
677 oh->sequence);
678 return -EINVAL;
679 }
Harald Welte702d8702008-12-26 20:25:35 +0000680#if 0
Holger Freytherca362a62009-01-04 21:05:01 +0000681 unsigned int l2_len = msg->tail - (u_int8_t *)msgb_l2(msg);
682 unsigned int hlen = sizeof(*oh) + sizeof(struct abis_om_fom_hdr);
Harald Welte702d8702008-12-26 20:25:35 +0000683 if (oh->length + hlen > l2_len) {
Harald Welte52b1f982008-12-23 20:25:15 +0000684 fprintf(stderr, "ABIS OML truncated message (%u > %u)\n",
685 oh->length + sizeof(*oh), l2_len);
686 return -EINVAL;
687 }
Harald Welte702d8702008-12-26 20:25:35 +0000688 if (oh->length + hlen < l2_len)
689 fprintf(stderr, "ABIS OML message with extra trailer?!? (oh->len=%d, sizeof_oh=%d l2_len=%d\n", oh->length, sizeof(*oh), l2_len);
690#endif
Harald Weltead384642008-12-26 10:20:07 +0000691 msg->l3h = (unsigned char *)oh + sizeof(*oh);
Harald Welte52b1f982008-12-23 20:25:15 +0000692
693 switch (oh->mdisc) {
694 case ABIS_OM_MDISC_FOM:
Harald Welte8470bf22008-12-25 23:28:35 +0000695 rc = abis_nm_rcvmsg_fom(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000696 break;
Harald Welte677c21f2009-02-17 13:22:23 +0000697 case ABIS_OM_MDISC_MANUF:
698 rc = abis_nm_rcvmsg_manuf(msg);
699 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000700 case ABIS_OM_MDISC_MMI:
701 case ABIS_OM_MDISC_TRAU:
Harald Welte677c21f2009-02-17 13:22:23 +0000702 fprintf(stderr, "unimplemented ABIS OML message discriminator 0x%x\n",
703 oh->mdisc);
704 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000705 default:
706 fprintf(stderr, "unknown ABIS OML message discriminator 0x%x\n",
707 oh->mdisc);
708 return -EINVAL;
709 }
710
Harald Weltead384642008-12-26 10:20:07 +0000711 msgb_free(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000712 return rc;
713}
714
715#if 0
716/* initialized all resources */
717struct abis_nm_h *abis_nm_init(struct abis_nm_cfg *cfg)
718{
719 struct abis_nm_h *nmh;
720
721 nmh = malloc(sizeof(*nmh));
722 if (!nmh)
723 return NULL;
724
725 nmh->cfg = cfg;
726
727 return nmh;
728}
729
730/* free all resources */
731void abis_nm_fini(struct abis_nm_h *nmh)
732{
733 free(nmh);
734}
735#endif
736
737/* Here we are trying to define a high-level API that can be used by
738 * the actual BSC implementation. However, the architecture is currently
739 * still under design. Ideally the calls to this API would be synchronous,
740 * while the underlying stack behind the APi runs in a traditional select
741 * based state machine.
742 */
743
Harald Welte4724f992009-01-18 18:01:49 +0000744/* 6.2 Software Load: */
745enum sw_state {
746 SW_STATE_NONE,
747 SW_STATE_WAIT_INITACK,
748 SW_STATE_WAIT_SEGACK,
749 SW_STATE_WAIT_ENDACK,
750 SW_STATE_WAIT_ACTACK,
751 SW_STATE_ERROR,
752};
Harald Welte52b1f982008-12-23 20:25:15 +0000753
Harald Welte52b1f982008-12-23 20:25:15 +0000754struct abis_nm_sw {
Harald Welte4724f992009-01-18 18:01:49 +0000755 struct gsm_bts *bts;
Harald Welte5e4d1b32009-02-01 13:36:56 +0000756 gsm_cbfn *cbfn;
757 void *cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +0000758 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +0000759
Harald Welte52b1f982008-12-23 20:25:15 +0000760 /* this will become part of the SW LOAD INITIATE */
761 u_int8_t obj_class;
762 u_int8_t obj_instance[3];
Harald Welte4724f992009-01-18 18:01:49 +0000763
764 u_int8_t file_id[255];
765 u_int8_t file_id_len;
766
767 u_int8_t file_version[255];
768 u_int8_t file_version_len;
769
770 u_int8_t window_size;
771 u_int8_t seg_in_window;
772
773 int fd;
774 FILE *stream;
775 enum sw_state state;
Harald Welte1602ade2009-01-29 21:12:39 +0000776 int last_seg;
Harald Welte52b1f982008-12-23 20:25:15 +0000777};
778
Harald Welte4724f992009-01-18 18:01:49 +0000779static struct abis_nm_sw g_sw;
780
781/* 6.2.1 / 8.3.1: Load Data Initiate */
782static int sw_load_init(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +0000783{
Harald Welte4724f992009-01-18 18:01:49 +0000784 struct abis_om_hdr *oh;
785 struct msgb *msg = nm_msgb_alloc();
786 u_int8_t len = 3*2 + sw->file_id_len + sw->file_version_len;
787
788 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
789 fill_om_fom_hdr(oh, len, NM_MT_LOAD_INIT, sw->obj_class,
790 sw->obj_instance[0], sw->obj_instance[1],
791 sw->obj_instance[2]);
792
793 /* FIXME: this is BS11 specific format */
794 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
795 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
796 sw->file_version);
797 msgb_tv_put(msg, NM_ATT_WINDOW_SIZE, sw->window_size);
798
799 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000800}
801
Harald Welte1602ade2009-01-29 21:12:39 +0000802static int is_last_line(FILE *stream)
803{
804 char next_seg_buf[256];
805 long pos;
806
807 /* check if we're sending the last line */
808 pos = ftell(stream);
809 if (!fgets(next_seg_buf, sizeof(next_seg_buf)-2, stream)) {
810 fseek(stream, pos, SEEK_SET);
811 return 1;
812 }
813
814 fseek(stream, pos, SEEK_SET);
815 return 0;
816}
817
Harald Welte4724f992009-01-18 18:01:49 +0000818/* 6.2.2 / 8.3.2 Load Data Segment */
819static int sw_load_segment(struct abis_nm_sw *sw)
820{
821 struct abis_om_hdr *oh;
822 struct msgb *msg = nm_msgb_alloc();
823 char seg_buf[256];
824 char *line_buf = seg_buf+2;
Harald Welte3b8ba212009-01-29 12:27:58 +0000825 unsigned char *tlv;
Harald Welte4724f992009-01-18 18:01:49 +0000826 u_int8_t len;
Harald Welte4724f992009-01-18 18:01:49 +0000827
828 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte3b8ba212009-01-29 12:27:58 +0000829
830 switch (sw->bts->type) {
831 case GSM_BTS_TYPE_BS11:
832 if (fgets(line_buf, sizeof(seg_buf)-2, sw->stream) == NULL) {
833 perror("fgets reading segment");
834 return -EINVAL;
835 }
836 seg_buf[0] = 0x00;
Harald Welte1602ade2009-01-29 21:12:39 +0000837
838 /* check if we're sending the last line */
839 sw->last_seg = is_last_line(sw->stream);
840 if (sw->last_seg)
841 seg_buf[1] = 0;
842 else
843 seg_buf[1] = 1 + sw->seg_in_window++;
Harald Welte3b8ba212009-01-29 12:27:58 +0000844
845 len = strlen(line_buf) + 2;
846 tlv = msgb_put(msg, TLV_GROSS_LEN(len));
847 tlv_put(tlv, NM_ATT_BS11_FILE_DATA, len, (u_int8_t *)seg_buf);
848 /* BS11 wants CR + LF in excess of the TLV length !?! */
849 tlv[1] -= 2;
850
851 /* we only now know the exact length for the OM hdr */
852 len = strlen(line_buf)+2;
853 break;
854 default:
855 /* FIXME: Other BTS types */
856 return -1;
Harald Welte4724f992009-01-18 18:01:49 +0000857 }
Harald Welte4724f992009-01-18 18:01:49 +0000858
Harald Welte4724f992009-01-18 18:01:49 +0000859 fill_om_fom_hdr(oh, len, NM_MT_LOAD_SEG, sw->obj_class,
860 sw->obj_instance[0], sw->obj_instance[1],
861 sw->obj_instance[2]);
862
863 return abis_nm_sendmsg(sw->bts, msg);
864}
865
866/* 6.2.4 / 8.3.4 Load Data End */
867static int sw_load_end(struct abis_nm_sw *sw)
868{
869 struct abis_om_hdr *oh;
870 struct msgb *msg = nm_msgb_alloc();
871 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
872
873 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
874 fill_om_fom_hdr(oh, len, NM_MT_LOAD_END, sw->obj_class,
875 sw->obj_instance[0], sw->obj_instance[1],
876 sw->obj_instance[2]);
877
878 /* FIXME: this is BS11 specific format */
879 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
880 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
881 sw->file_version);
882
883 return abis_nm_sendmsg(sw->bts, msg);
884}
Harald Welte5e4d1b32009-02-01 13:36:56 +0000885
Harald Welte52b1f982008-12-23 20:25:15 +0000886/* Activate the specified software into the BTS */
Harald Welte4724f992009-01-18 18:01:49 +0000887static int sw_activate(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +0000888{
Harald Welte4724f992009-01-18 18:01:49 +0000889 struct abis_om_hdr *oh;
890 struct msgb *msg = nm_msgb_alloc();
891 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
Harald Welte52b1f982008-12-23 20:25:15 +0000892
Harald Welte4724f992009-01-18 18:01:49 +0000893 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
894 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, sw->obj_class,
895 sw->obj_instance[0], sw->obj_instance[1],
896 sw->obj_instance[2]);
897
898 /* FIXME: this is BS11 specific format */
899 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
900 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
901 sw->file_version);
902
903 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000904}
Harald Welte4724f992009-01-18 18:01:49 +0000905
906static int sw_open_file(struct abis_nm_sw *sw, const char *fname)
907{
908 char file_id[12+1];
909 char file_version[80+1];
910 int rc;
911
912 sw->fd = open(fname, O_RDONLY);
913 if (sw->fd < 0)
914 return sw->fd;
915
916 switch (sw->bts->type) {
917 case GSM_BTS_TYPE_BS11:
918 sw->stream = fdopen(sw->fd, "r");
919 if (!sw->stream) {
920 perror("fdopen");
921 return -1;
922 }
923 /* read first line and parse file ID and VERSION */
Harald Welte3b8ba212009-01-29 12:27:58 +0000924 rc = fscanf(sw->stream, "@(#)%12s:%80s\r\n",
Harald Welte4724f992009-01-18 18:01:49 +0000925 file_id, file_version);
926 if (rc != 2) {
927 perror("parsing header line of software file");
928 return -1;
929 }
930 strcpy((char *)sw->file_id, file_id);
931 sw->file_id_len = strlen(file_id);
932 strcpy((char *)sw->file_version, file_version);
933 sw->file_version_len = strlen(file_version);
934 /* rewind to start of file */
Harald Welte3b8ba212009-01-29 12:27:58 +0000935 rewind(sw->stream);
Harald Welte4724f992009-01-18 18:01:49 +0000936 break;
937 default:
938 /* We don't know how to treat them yet */
939 close(sw->fd);
940 return -EINVAL;
941 }
942
943 return 0;
944}
945
946static void sw_close_file(struct abis_nm_sw *sw)
947{
948 switch (sw->bts->type) {
949 case GSM_BTS_TYPE_BS11:
950 fclose(sw->stream);
951 break;
952 default:
953 close(sw->fd);
954 break;
955 }
956}
957
958/* Fill the window */
959static int sw_fill_window(struct abis_nm_sw *sw)
960{
961 int rc;
962
963 while (sw->seg_in_window < sw->window_size) {
964 rc = sw_load_segment(sw);
965 if (rc < 0)
966 return rc;
Harald Welte1602ade2009-01-29 21:12:39 +0000967 if (sw->last_seg)
968 break;
Harald Welte4724f992009-01-18 18:01:49 +0000969 }
970 return 0;
971}
972
973/* callback function from abis_nm_rcvmsg() handler */
974static int abis_nm_rcvmsg_sw(struct msgb *mb)
975{
976 struct abis_om_fom_hdr *foh = msgb_l3(mb);
977 int rc = -1;
978 struct abis_nm_sw *sw = &g_sw;
979 enum sw_state old_state = sw->state;
980
Harald Welte3ffd1372009-02-01 22:15:49 +0000981 //DEBUGP(DNM, "state %u, NM MT 0x%02x\n", sw->state, foh->msg_type);
Harald Welte4724f992009-01-18 18:01:49 +0000982
983 switch (sw->state) {
984 case SW_STATE_WAIT_INITACK:
985 switch (foh->msg_type) {
986 case NM_MT_LOAD_INIT_ACK:
987 /* fill window with segments */
Harald Welte5e4d1b32009-02-01 13:36:56 +0000988 if (sw->cbfn)
989 sw->cbfn(GSM_HOOK_NM_SWLOAD,
990 NM_MT_LOAD_INIT_ACK, mb,
991 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +0000992 rc = sw_fill_window(sw);
993 sw->state = SW_STATE_WAIT_SEGACK;
994 break;
995 case NM_MT_LOAD_INIT_NACK:
Harald Welte3ffd1372009-02-01 22:15:49 +0000996 if (sw->forced) {
997 DEBUGP(DNM, "FORCED: Ignoring Software Load "
998 "Init NACK\n");
999 if (sw->cbfn)
1000 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1001 NM_MT_LOAD_INIT_ACK, mb,
1002 sw->cb_data, NULL);
1003 rc = sw_fill_window(sw);
1004 sw->state = SW_STATE_WAIT_SEGACK;
1005 } else {
1006 DEBUGP(DNM, "Software Load Init NACK\n");
1007 if (sw->cbfn)
1008 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1009 NM_MT_LOAD_INIT_NACK, mb,
1010 sw->cb_data, NULL);
1011 sw->state = SW_STATE_ERROR;
1012 }
Harald Welte4724f992009-01-18 18:01:49 +00001013 break;
1014 }
1015 break;
1016 case SW_STATE_WAIT_SEGACK:
1017 switch (foh->msg_type) {
1018 case NM_MT_LOAD_SEG_ACK:
Harald Welte3ffd1372009-02-01 22:15:49 +00001019 if (sw->cbfn)
1020 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1021 NM_MT_LOAD_SEG_ACK, mb,
1022 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001023 sw->seg_in_window = 0;
Harald Welte1602ade2009-01-29 21:12:39 +00001024 if (!sw->last_seg) {
1025 /* fill window with more segments */
1026 rc = sw_fill_window(sw);
1027 sw->state = SW_STATE_WAIT_SEGACK;
1028 } else {
1029 /* end the transfer */
1030 sw->state = SW_STATE_WAIT_ENDACK;
1031 rc = sw_load_end(sw);
1032 }
Harald Welte4724f992009-01-18 18:01:49 +00001033 break;
1034 }
1035 break;
1036 case SW_STATE_WAIT_ENDACK:
1037 switch (foh->msg_type) {
1038 case NM_MT_LOAD_END_ACK:
1039 sw_close_file(sw);
Harald Welte5e4d1b32009-02-01 13:36:56 +00001040 DEBUGP(DNM, "Software Load End (BTS %u)\n",
1041 sw->bts->nr);
1042 sw->state = SW_STATE_NONE;
1043 if (sw->cbfn)
1044 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1045 NM_MT_LOAD_END_ACK, mb,
1046 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001047 break;
1048 case NM_MT_LOAD_END_NACK:
Holger Freyther31338a12009-02-06 17:43:50 +00001049 if (sw->forced) {
1050 DEBUGP(DNM, "FORCED: Ignoring Software Load"
1051 "End NACK\n");
1052 sw->state = SW_STATE_NONE;
1053 if (sw->cbfn)
1054 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1055 NM_MT_LOAD_END_ACK, mb,
1056 sw->cb_data, NULL);
1057 } else {
1058 DEBUGP(DNM, "Software Load End NACK\n");
1059 sw->state = SW_STATE_ERROR;
1060 if (sw->cbfn)
1061 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1062 NM_MT_LOAD_END_NACK, mb,
1063 sw->cb_data, NULL);
1064 }
Harald Welte4724f992009-01-18 18:01:49 +00001065 break;
1066 }
1067 case SW_STATE_WAIT_ACTACK:
1068 switch (foh->msg_type) {
1069 case NM_MT_ACTIVATE_SW_ACK:
1070 /* we're done */
Harald Welte5e4d1b32009-02-01 13:36:56 +00001071 DEBUGP(DNM, "Activate Software DONE!\n");
Harald Welte4724f992009-01-18 18:01:49 +00001072 sw->state = SW_STATE_NONE;
1073 rc = 0;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001074 if (sw->cbfn)
1075 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1076 NM_MT_ACTIVATE_SW_ACK, mb,
1077 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001078 break;
1079 case NM_MT_ACTIVATE_SW_NACK:
Harald Welte1602ade2009-01-29 21:12:39 +00001080 DEBUGP(DNM, "Activate Software NACK\n");
Harald Welte4724f992009-01-18 18:01:49 +00001081 sw->state = SW_STATE_ERROR;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001082 if (sw->cbfn)
1083 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1084 NM_MT_ACTIVATE_SW_NACK, mb,
1085 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001086 break;
1087 }
1088 case SW_STATE_NONE:
1089 case SW_STATE_ERROR:
1090 break;
1091 }
1092
1093 if (rc)
1094 fprintf(stderr, "unexpected NM MT 0x%02x in state %u -> %u\n",
1095 foh->msg_type, old_state, sw->state);
1096
1097 return rc;
1098}
1099
1100/* Load the specified software into the BTS */
1101int abis_nm_software_load(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00001102 u_int8_t win_size, int forced,
1103 gsm_cbfn *cbfn, void *cb_data)
Harald Welte4724f992009-01-18 18:01:49 +00001104{
1105 struct abis_nm_sw *sw = &g_sw;
1106 int rc;
1107
Harald Welte5e4d1b32009-02-01 13:36:56 +00001108 DEBUGP(DNM, "Software Load (BTS %u, File \"%s\")\n",
1109 bts->nr, fname);
1110
Harald Welte4724f992009-01-18 18:01:49 +00001111 if (sw->state != SW_STATE_NONE)
1112 return -EBUSY;
1113
1114 sw->bts = bts;
1115 sw->obj_class = NM_OC_SITE_MANAGER;
1116 sw->obj_instance[0] = 0xff;
1117 sw->obj_instance[1] = 0xff;
1118 sw->obj_instance[2] = 0xff;
1119 sw->window_size = win_size;
1120 sw->state = SW_STATE_WAIT_INITACK;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001121 sw->cbfn = cbfn;
1122 sw->cb_data = cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +00001123 sw->forced = forced;
Harald Welte4724f992009-01-18 18:01:49 +00001124
1125 rc = sw_open_file(sw, fname);
1126 if (rc < 0) {
1127 sw->state = SW_STATE_NONE;
1128 return rc;
1129 }
1130
1131 return sw_load_init(sw);
1132}
Harald Welte52b1f982008-12-23 20:25:15 +00001133
Harald Welte1602ade2009-01-29 21:12:39 +00001134int abis_nm_software_load_status(struct gsm_bts *bts)
1135{
1136 struct abis_nm_sw *sw = &g_sw;
1137 struct stat st;
1138 int rc, percent;
1139
1140 rc = fstat(sw->fd, &st);
1141 if (rc < 0) {
1142 perror("ERROR during stat");
1143 return rc;
1144 }
1145
1146 percent = (ftell(sw->stream) * 100) / st.st_size;
1147 return percent;
1148}
1149
Harald Welte5e4d1b32009-02-01 13:36:56 +00001150/* Activate the specified software into the BTS */
1151int abis_nm_software_activate(struct gsm_bts *bts, const char *fname,
1152 gsm_cbfn *cbfn, void *cb_data)
1153{
1154 struct abis_nm_sw *sw = &g_sw;
1155 int rc;
1156
1157 DEBUGP(DNM, "Activating Software (BTS %u, File \"%s\")\n",
1158 bts->nr, fname);
1159
1160 if (sw->state != SW_STATE_NONE)
1161 return -EBUSY;
1162
1163 sw->bts = bts;
1164 sw->obj_class = NM_OC_SITE_MANAGER;
1165 sw->obj_instance[0] = 0xff;
1166 sw->obj_instance[1] = 0xff;
1167 sw->obj_instance[2] = 0xff;
1168 sw->state = SW_STATE_WAIT_ACTACK;
1169 sw->cbfn = cbfn;
1170 sw->cb_data = cb_data;
1171
1172 /* Open the file in order to fill some sw struct members */
1173 rc = sw_open_file(sw, fname);
1174 if (rc < 0) {
1175 sw->state = SW_STATE_NONE;
1176 return rc;
1177 }
1178 sw_close_file(sw);
1179
1180 return sw_activate(sw);
1181}
1182
Harald Welte8470bf22008-12-25 23:28:35 +00001183static void fill_nm_channel(struct abis_nm_channel *ch, u_int8_t bts_port,
Harald Welte52b1f982008-12-23 20:25:15 +00001184 u_int8_t ts_nr, u_int8_t subslot_nr)
1185{
Harald Welteadaf08b2009-01-18 11:08:10 +00001186 ch->attrib = NM_ATT_ABIS_CHANNEL;
Harald Welte52b1f982008-12-23 20:25:15 +00001187 ch->bts_port = bts_port;
1188 ch->timeslot = ts_nr;
1189 ch->subslot = subslot_nr;
1190}
1191
1192int abis_nm_establish_tei(struct gsm_bts *bts, u_int8_t trx_nr,
1193 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot,
1194 u_int8_t tei)
1195{
1196 struct abis_om_hdr *oh;
1197 struct abis_nm_channel *ch;
Harald Welte702d8702008-12-26 20:25:35 +00001198 u_int8_t len = sizeof(*ch) + 2;
Harald Welte8470bf22008-12-25 23:28:35 +00001199 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001200
1201 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1202 fill_om_fom_hdr(oh, len, NM_MT_ESTABLISH_TEI, NM_OC_RADIO_CARRIER,
1203 bts->bts_nr, trx_nr, 0xff);
1204
Harald Welte8470bf22008-12-25 23:28:35 +00001205 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte52b1f982008-12-23 20:25:15 +00001206
1207 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1208 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1209
1210 return abis_nm_sendmsg(bts, msg);
1211}
1212
1213/* connect signalling of one (BTS,TRX) to a particular timeslot on the E1 */
1214int abis_nm_conn_terr_sign(struct gsm_bts_trx *trx,
1215 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot)
1216{
Harald Welte8470bf22008-12-25 23:28:35 +00001217 struct gsm_bts *bts = trx->bts;
Harald Welte52b1f982008-12-23 20:25:15 +00001218 struct abis_om_hdr *oh;
1219 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +00001220 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001221
1222 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001223 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_SIGN,
Harald Welte52b1f982008-12-23 20:25:15 +00001224 NM_OC_RADIO_CARRIER, bts->bts_nr, trx->nr, 0xff);
1225
1226 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1227 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1228
1229 return abis_nm_sendmsg(bts, msg);
1230}
1231
1232#if 0
1233int abis_nm_disc_terr_sign(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1234 struct abis_nm_abis_channel *chan)
1235{
1236}
1237#endif
1238
1239int abis_nm_conn_terr_traf(struct gsm_bts_trx_ts *ts,
1240 u_int8_t e1_port, u_int8_t e1_timeslot,
1241 u_int8_t e1_subslot)
1242{
1243 struct gsm_bts *bts = ts->trx->bts;
1244 struct abis_om_hdr *oh;
1245 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +00001246 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001247
1248 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1249 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_TRAF,
Harald Welteb110cee2009-02-18 03:42:35 +00001250 NM_OC_CHANNEL, bts->bts_nr, ts->trx->nr, ts->nr);
Harald Welte52b1f982008-12-23 20:25:15 +00001251
1252 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1253 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1254
Harald Welteb110cee2009-02-18 03:42:35 +00001255 DEBUGP(DNM, "CONNECT TERR TRAF Um=(%u,%u,%u) E1=(%u,%u,%u)\n",
1256 bts->bts_nr, ts->trx->nr, ts->nr,
1257 e1_port, e1_timeslot, e1_subslot);
1258
Harald Welte52b1f982008-12-23 20:25:15 +00001259 return abis_nm_sendmsg(bts, msg);
1260}
1261
1262#if 0
1263int abis_nm_disc_terr_traf(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1264 struct abis_nm_abis_channel *chan,
1265 u_int8_t subchan)
1266{
1267}
1268#endif
1269
Harald Welte22af0db2009-02-14 15:41:08 +00001270/* Chapter 8.6.1 */
1271int abis_nm_set_bts_attr(struct gsm_bts *bts, u_int8_t *attr, int attr_len)
1272{
1273 struct abis_om_hdr *oh;
1274 struct msgb *msg = nm_msgb_alloc();
1275 u_int8_t *cur;
1276
1277 DEBUGP(DNM, "Set BTS Attr (bts=%d)\n", bts->nr);
1278
1279 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1280 fill_om_fom_hdr(oh, attr_len, NM_MT_SET_BTS_ATTR, NM_OC_BTS, bts->nr, 0xff, 0xff);
1281 cur = msgb_put(msg, attr_len);
1282 memcpy(cur, attr, attr_len);
1283
1284 return abis_nm_sendmsg(bts, msg);
1285}
1286
1287/* Chapter 8.6.2 */
1288int abis_nm_set_radio_attr(struct gsm_bts_trx *trx, u_int8_t *attr, int attr_len)
1289{
1290 struct abis_om_hdr *oh;
1291 struct msgb *msg = nm_msgb_alloc();
1292 u_int8_t *cur;
1293
1294 DEBUGP(DNM, "Set TRX Attr (bts=%d,trx=%d)\n", trx->bts->nr, trx->nr);
1295
1296 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1297 fill_om_fom_hdr(oh, attr_len, NM_MT_SET_RADIO_ATTR, NM_OC_RADIO_CARRIER,
1298 trx->bts->nr, trx->nr, 0xff);
1299 cur = msgb_put(msg, attr_len);
1300 memcpy(cur, attr, attr_len);
1301
1302 return abis_nm_sendmsg(trx->bts, msg);
1303}
1304
1305/* Chapter 8.6.3 */
Harald Welte52b1f982008-12-23 20:25:15 +00001306int abis_nm_set_channel_attr(struct gsm_bts_trx_ts *ts, u_int8_t chan_comb)
1307{
1308 struct gsm_bts *bts = ts->trx->bts;
1309 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001310 u_int16_t arfcn = htons(ts->trx->arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001311 u_int8_t zero = 0x00;
Harald Welte8470bf22008-12-25 23:28:35 +00001312 struct msgb *msg = nm_msgb_alloc();
Harald Weltee0590df2009-02-15 03:34:15 +00001313 u_int8_t len = 2 + 2;
1314
1315 if (bts->type == GSM_BTS_TYPE_BS11)
1316 len += 4 + 2 + 2 + 3;
Harald Welte52b1f982008-12-23 20:25:15 +00001317
Harald Welte22af0db2009-02-14 15:41:08 +00001318 DEBUGP(DNM, "Set Chan Attr (bts=%d,trx=%d,ts=%d)\n", bts->nr, ts->trx->nr, ts->nr);
1319
Harald Welte52b1f982008-12-23 20:25:15 +00001320 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001321 fill_om_fom_hdr(oh, len, NM_MT_SET_CHAN_ATTR,
Holger Freyther6b2d2622009-02-14 23:16:59 +00001322 NM_OC_CHANNEL, bts->bts_nr,
Harald Welte52b1f982008-12-23 20:25:15 +00001323 ts->trx->nr, ts->nr);
1324 /* FIXME: don't send ARFCN list, hopping sequence, mAIO, ...*/
Harald Weltee0590df2009-02-15 03:34:15 +00001325 if (bts->type == GSM_BTS_TYPE_BS11)
1326 msgb_tlv16_put(msg, NM_ATT_ARFCN_LIST, 1, &arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001327 msgb_tv_put(msg, NM_ATT_CHAN_COMB, chan_comb);
Harald Weltee0590df2009-02-15 03:34:15 +00001328 if (bts->type == GSM_BTS_TYPE_BS11) {
1329 msgb_tv_put(msg, NM_ATT_HSN, 0x00);
1330 msgb_tv_put(msg, NM_ATT_MAIO, 0x00);
1331 }
Harald Welte52b1f982008-12-23 20:25:15 +00001332 msgb_tv_put(msg, NM_ATT_TSC, 0x07); /* training sequence */
Harald Weltee0590df2009-02-15 03:34:15 +00001333 if (bts->type == GSM_BTS_TYPE_BS11)
1334 msgb_tlv_put(msg, 0x59, 1, &zero);
Harald Welte52b1f982008-12-23 20:25:15 +00001335
1336 return abis_nm_sendmsg(bts, msg);
1337}
1338
Harald Welte34a99682009-02-13 02:41:40 +00001339int 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 +00001340 u_int8_t i2, u_int8_t i3, int nack, u_int8_t *attr, int att_len)
Harald Welte34a99682009-02-13 02:41:40 +00001341{
1342 struct abis_om_hdr *oh;
1343 struct msgb *msg = nm_msgb_alloc();
Harald Welte5c1e4582009-02-15 11:57:29 +00001344 u_int8_t msgtype = NM_MT_SW_ACT_REQ_ACK;
1345 u_int8_t len = att_len;
1346
1347 if (nack) {
1348 len += 2;
1349 msgtype = NM_MT_SW_ACT_REQ_NACK;
1350 }
Harald Welte34a99682009-02-13 02:41:40 +00001351
1352 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte5c1e4582009-02-15 11:57:29 +00001353 fill_om_fom_hdr(oh, att_len, msgtype, obj_class, i1, i2, i3);
1354
Harald Welte34a99682009-02-13 02:41:40 +00001355 if (attr) {
1356 u_int8_t *ptr = msgb_put(msg, att_len);
1357 memcpy(ptr, attr, att_len);
1358 }
Harald Welte5c1e4582009-02-15 11:57:29 +00001359 if (nack)
1360 msgb_tv_put(msg, NM_ATT_NACK_CAUSES, NM_NACK_OBJCLASS_NOTSUPP);
Harald Welte34a99682009-02-13 02:41:40 +00001361
1362 return abis_nm_sendmsg(bts, msg);
1363}
1364
Harald Welte8470bf22008-12-25 23:28:35 +00001365int abis_nm_raw_msg(struct gsm_bts *bts, int len, u_int8_t *rawmsg)
Harald Welte52b1f982008-12-23 20:25:15 +00001366{
Harald Welte8470bf22008-12-25 23:28:35 +00001367 struct msgb *msg = nm_msgb_alloc();
1368 struct abis_om_hdr *oh;
Harald Welte52b1f982008-12-23 20:25:15 +00001369 u_int8_t *data;
1370
1371 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
1372 fill_om_hdr(oh, len);
1373 data = msgb_put(msg, len);
Harald Weltead384642008-12-26 10:20:07 +00001374 memcpy(data, rawmsg, len);
Harald Welte52b1f982008-12-23 20:25:15 +00001375
1376 return abis_nm_sendmsg(bts, msg);
1377}
1378
1379/* Siemens specific commands */
1380static int __simple_cmd(struct gsm_bts *bts, u_int8_t msg_type)
1381{
1382 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001383 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001384
1385 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001386 fill_om_fom_hdr(oh, 0, msg_type, NM_OC_SITE_MANAGER,
Harald Welte52b1f982008-12-23 20:25:15 +00001387 0xff, 0xff, 0xff);
1388
1389 return abis_nm_sendmsg(bts, msg);
1390}
1391
Harald Welte34a99682009-02-13 02:41:40 +00001392/* Chapter 8.9.2 */
1393int abis_nm_opstart(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1, u_int8_t i2)
1394{
1395 struct abis_om_hdr *oh;
1396 struct msgb *msg = nm_msgb_alloc();
1397
Harald Welte22af0db2009-02-14 15:41:08 +00001398 DEBUGP(DNM, "Sending OPSTART obj_class=0x%02x obj_inst=(0x%02x, 0x%02x, 0x%02x)\n",
1399 obj_class, i0, i1, i2);
Harald Welte34a99682009-02-13 02:41:40 +00001400 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1401 fill_om_fom_hdr(oh, 0, NM_MT_OPSTART, obj_class, i0, i1, i2);
1402
1403 return abis_nm_sendmsg(bts, msg);
1404}
1405
1406/* Chapter 8.8.5 */
1407int abis_nm_chg_adm_state(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0,
1408 u_int8_t i1, u_int8_t i2, u_int8_t adm_state)
1409{
1410 struct abis_om_hdr *oh;
1411 struct msgb *msg = nm_msgb_alloc();
1412
1413 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1414 fill_om_fom_hdr(oh, 2, NM_MT_CHG_ADM_STATE, obj_class, i0, i1, i2);
1415 msgb_tv_put(msg, NM_ATT_ADM_STATE, adm_state);
1416
1417 return abis_nm_sendmsg(bts, msg);
1418}
1419
1420
Harald Welte52b1f982008-12-23 20:25:15 +00001421int abis_nm_event_reports(struct gsm_bts *bts, int on)
1422{
1423 if (on == 0)
Harald Welte227d4072009-01-03 08:16:25 +00001424 return __simple_cmd(bts, NM_MT_STOP_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001425 else
Harald Welte227d4072009-01-03 08:16:25 +00001426 return __simple_cmd(bts, NM_MT_REST_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001427}
1428
Harald Welte47d88ae2009-01-04 12:02:08 +00001429/* Siemens (or BS-11) specific commands */
1430
Harald Welte3ffd1372009-02-01 22:15:49 +00001431int abis_nm_bs11_bsc_disconnect(struct gsm_bts *bts, int reconnect)
1432{
1433 if (reconnect == 0)
1434 return __simple_cmd(bts, NM_MT_BS11_DISCONNECT);
1435 else
1436 return __simple_cmd(bts, NM_MT_BS11_RECONNECT);
1437}
1438
Harald Welteb8427972009-02-05 19:27:17 +00001439int abis_nm_bs11_restart(struct gsm_bts *bts)
1440{
1441 return __simple_cmd(bts, NM_MT_BS11_RESTART);
1442}
1443
1444
Harald Welte268bb402009-02-01 19:11:56 +00001445struct bs11_date_time {
1446 u_int16_t year;
1447 u_int8_t month;
1448 u_int8_t day;
1449 u_int8_t hour;
1450 u_int8_t min;
1451 u_int8_t sec;
1452} __attribute__((packed));
1453
1454
1455void get_bs11_date_time(struct bs11_date_time *aet)
1456{
1457 time_t t;
1458 struct tm *tm;
1459
1460 t = time(NULL);
1461 tm = localtime(&t);
1462 aet->sec = tm->tm_sec;
1463 aet->min = tm->tm_min;
1464 aet->hour = tm->tm_hour;
1465 aet->day = tm->tm_mday;
1466 aet->month = tm->tm_mon;
1467 aet->year = htons(1900 + tm->tm_year);
1468}
1469
Harald Welte05188ee2009-01-18 11:39:08 +00001470int abis_nm_bs11_reset_resource(struct gsm_bts *bts)
Harald Welte52b1f982008-12-23 20:25:15 +00001471{
Harald Welte4668fda2009-01-03 08:19:29 +00001472 return __simple_cmd(bts, NM_MT_BS11_RESET_RESOURCE);
Harald Welte52b1f982008-12-23 20:25:15 +00001473}
1474
Harald Welte05188ee2009-01-18 11:39:08 +00001475int abis_nm_bs11_db_transmission(struct gsm_bts *bts, int begin)
Harald Welte52b1f982008-12-23 20:25:15 +00001476{
1477 if (begin)
Harald Welte4668fda2009-01-03 08:19:29 +00001478 return __simple_cmd(bts, NM_MT_BS11_BEGIN_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00001479 else
Harald Welte4668fda2009-01-03 08:19:29 +00001480 return __simple_cmd(bts, NM_MT_BS11_END_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00001481}
Harald Welte47d88ae2009-01-04 12:02:08 +00001482
Harald Welte05188ee2009-01-18 11:39:08 +00001483int abis_nm_bs11_create_object(struct gsm_bts *bts,
Harald Welte1bc09062009-01-18 14:17:52 +00001484 enum abis_bs11_objtype type, u_int8_t idx,
1485 u_int8_t attr_len, const u_int8_t *attr)
Harald Welte47d88ae2009-01-04 12:02:08 +00001486{
1487 struct abis_om_hdr *oh;
1488 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00001489 u_int8_t *cur;
Harald Welte47d88ae2009-01-04 12:02:08 +00001490
1491 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001492 fill_om_fom_hdr(oh, attr_len, NM_MT_BS11_CREATE_OBJ,
Harald Welte268bb402009-02-01 19:11:56 +00001493 NM_OC_BS11, type, 0, idx);
Harald Welte1bc09062009-01-18 14:17:52 +00001494 cur = msgb_put(msg, attr_len);
1495 memcpy(cur, attr, attr_len);
Harald Welte47d88ae2009-01-04 12:02:08 +00001496
1497 return abis_nm_sendmsg(bts, msg);
1498}
1499
Harald Welte05188ee2009-01-18 11:39:08 +00001500int abis_nm_bs11_create_envaBTSE(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00001501{
1502 struct abis_om_hdr *oh;
1503 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00001504 u_int8_t zero = 0x00;
Harald Welte47d88ae2009-01-04 12:02:08 +00001505
1506 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001507 fill_om_fom_hdr(oh, 3, NM_MT_BS11_CREATE_OBJ,
Harald Welte1bc09062009-01-18 14:17:52 +00001508 NM_OC_BS11_ENVABTSE, 0, idx, 0xff);
1509 msgb_tlv_put(msg, 0x99, 1, &zero);
Harald Welte47d88ae2009-01-04 12:02:08 +00001510
1511 return abis_nm_sendmsg(bts, msg);
1512}
1513
Harald Welte05188ee2009-01-18 11:39:08 +00001514int abis_nm_bs11_create_bport(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00001515{
1516 struct abis_om_hdr *oh;
1517 struct msgb *msg = nm_msgb_alloc();
1518
1519 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1520 fill_om_fom_hdr(oh, 0, NM_MT_BS11_CREATE_OBJ, NM_OC_BS11_BPORT,
1521 idx, 0, 0);
1522
1523 return abis_nm_sendmsg(bts, msg);
1524}
Harald Welte05188ee2009-01-18 11:39:08 +00001525
1526int abis_nm_bs11_set_oml_tei(struct gsm_bts *bts, u_int8_t tei)
1527{
1528 struct abis_om_hdr *oh;
1529 struct msgb *msg = nm_msgb_alloc();
Harald Welte05188ee2009-01-18 11:39:08 +00001530
1531 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001532 fill_om_fom_hdr(oh, 2, NM_MT_BS11_SET_ATTR, NM_OC_SITE_MANAGER,
Harald Welte05188ee2009-01-18 11:39:08 +00001533 0xff, 0xff, 0xff);
1534 msgb_tv_put(msg, NM_ATT_TEI, tei);
1535
1536 return abis_nm_sendmsg(bts, msg);
1537}
1538
1539/* like abis_nm_conn_terr_traf */
1540int abis_nm_bs11_conn_oml(struct gsm_bts *bts, u_int8_t e1_port,
1541 u_int8_t e1_timeslot, u_int8_t e1_subslot)
1542{
1543 struct abis_om_hdr *oh;
1544 struct abis_nm_channel *ch;
1545 struct msgb *msg = nm_msgb_alloc();
1546
1547 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte05188ee2009-01-18 11:39:08 +00001548 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_BS11_SET_ATTR,
1549 NM_OC_SITE_MANAGER, 0xff, 0xff, 0xff);
1550
1551 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1552 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1553
1554 return abis_nm_sendmsg(bts, msg);
1555}
1556
1557int abis_nm_bs11_set_trx_power(struct gsm_bts_trx *trx, u_int8_t level)
1558{
1559 struct abis_om_hdr *oh;
1560 struct msgb *msg = nm_msgb_alloc();
Harald Welte05188ee2009-01-18 11:39:08 +00001561
1562 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001563 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR,
Harald Welte05188ee2009-01-18 11:39:08 +00001564 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
1565 msgb_tlv_put(msg, NM_ATT_BS11_TXPWR, 1, &level);
1566
1567 return abis_nm_sendmsg(trx->bts, msg);
1568}
1569
Harald Welte268bb402009-02-01 19:11:56 +00001570//static const u_int8_t bs11_logon_c7[] = { 0x07, 0xd9, 0x01, 0x11, 0x0d, 0x10, 0x20 };
Harald Weltebb151312009-01-28 20:42:07 +00001571static const u_int8_t bs11_logon_c8[] = { 0x02 };
Harald Welte05188ee2009-01-18 11:39:08 +00001572static const u_int8_t bs11_logon_c9[] = "FACTORY";
1573
Harald Welte1bc09062009-01-18 14:17:52 +00001574int abis_nm_bs11_factory_logon(struct gsm_bts *bts, int on)
Harald Welte05188ee2009-01-18 11:39:08 +00001575{
1576 struct abis_om_hdr *oh;
1577 struct msgb *msg = nm_msgb_alloc();
Harald Welte268bb402009-02-01 19:11:56 +00001578 struct bs11_date_time bdt;
1579
1580 get_bs11_date_time(&bdt);
Harald Welte05188ee2009-01-18 11:39:08 +00001581
1582 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte1bc09062009-01-18 14:17:52 +00001583 if (on) {
Harald Welte268bb402009-02-01 19:11:56 +00001584 u_int8_t len = 3*2 + sizeof(bdt)
Harald Welte6f676a32009-01-18 14:27:48 +00001585 + sizeof(bs11_logon_c8) + sizeof(bs11_logon_c9);
Harald Welte043d04a2009-01-29 23:15:30 +00001586 fill_om_fom_hdr(oh, len, NM_MT_BS11_LMT_LOGON,
Harald Welte1bc09062009-01-18 14:17:52 +00001587 NM_OC_BS11_A3, 0xff, 0xff, 0xff);
Harald Welte043d04a2009-01-29 23:15:30 +00001588 msgb_tlv_put(msg, NM_ATT_BS11_LMT_LOGIN_TIME,
Harald Welte5083b0b2009-02-02 19:20:52 +00001589 sizeof(bdt), (u_int8_t *) &bdt);
Harald Welte043d04a2009-01-29 23:15:30 +00001590 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_ACC_LEV,
1591 sizeof(bs11_logon_c8), bs11_logon_c8);
1592 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_NAME,
1593 sizeof(bs11_logon_c9), bs11_logon_c9);
Harald Welte1bc09062009-01-18 14:17:52 +00001594 } else {
Harald Welte5e4d1b32009-02-01 13:36:56 +00001595 fill_om_fom_hdr(oh, 0, NM_MT_BS11_LMT_LOGOFF,
Harald Welte1bc09062009-01-18 14:17:52 +00001596 NM_OC_BS11_A3, 0xff, 0xff, 0xff);
1597 }
Harald Welte05188ee2009-01-18 11:39:08 +00001598
1599 return abis_nm_sendmsg(bts, msg);
1600}
Harald Welte1bc09062009-01-18 14:17:52 +00001601
1602int abis_nm_bs11_set_trx1_pw(struct gsm_bts *bts, const char *password)
1603{
1604 struct abis_om_hdr *oh;
1605 struct msgb *msg;
1606
1607 if (strlen(password) != 10)
1608 return -EINVAL;
1609
1610 msg = nm_msgb_alloc();
1611 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001612 fill_om_fom_hdr(oh, 2+strlen(password), NM_MT_BS11_SET_ATTR,
Harald Welte1bc09062009-01-18 14:17:52 +00001613 NM_OC_BS11, BS11_OBJ_TRX1, 0x00, 0x00);
1614 msgb_tlv_put(msg, NM_ATT_BS11_PASSWORD, 10, (const u_int8_t *)password);
1615
1616 return abis_nm_sendmsg(bts, msg);
1617}
1618
1619int abis_nm_bs11_get_state(struct gsm_bts *bts)
1620{
1621 return __simple_cmd(bts, NM_MT_BS11_GET_STATE);
1622}
Harald Welte5e4d1b32009-02-01 13:36:56 +00001623
1624/* BS11 SWL */
1625
1626struct abis_nm_bs11_sw {
1627 struct gsm_bts *bts;
1628 char swl_fname[PATH_MAX];
1629 u_int8_t win_size;
Harald Welte3ffd1372009-02-01 22:15:49 +00001630 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001631 struct llist_head file_list;
1632 gsm_cbfn *user_cb; /* specified by the user */
1633};
1634static struct abis_nm_bs11_sw _g_bs11_sw, *g_bs11_sw = &_g_bs11_sw;
1635
1636struct file_list_entry {
1637 struct llist_head list;
1638 char fname[PATH_MAX];
1639};
1640
1641struct file_list_entry *fl_dequeue(struct llist_head *queue)
1642{
1643 struct llist_head *lh;
1644
1645 if (llist_empty(queue))
1646 return NULL;
1647
1648 lh = queue->next;
1649 llist_del(lh);
1650
1651 return llist_entry(lh, struct file_list_entry, list);
1652}
1653
1654static int bs11_read_swl_file(struct abis_nm_bs11_sw *bs11_sw)
1655{
1656 char linebuf[255];
1657 struct llist_head *lh, *lh2;
1658 FILE *swl;
1659 int rc = 0;
1660
1661 swl = fopen(bs11_sw->swl_fname, "r");
1662 if (!swl)
1663 return -ENODEV;
1664
1665 /* zero the stale file list, if any */
1666 llist_for_each_safe(lh, lh2, &bs11_sw->file_list) {
1667 llist_del(lh);
1668 free(lh);
1669 }
1670
1671 while (fgets(linebuf, sizeof(linebuf), swl)) {
1672 char file_id[12+1];
1673 char file_version[80+1];
1674 struct file_list_entry *fle;
1675 static char dir[PATH_MAX];
1676
1677 if (strlen(linebuf) < 4)
1678 continue;
Harald Welte3ffd1372009-02-01 22:15:49 +00001679
Harald Welte5e4d1b32009-02-01 13:36:56 +00001680 rc = sscanf(linebuf+4, "%12s:%80s\r\n", file_id, file_version);
1681 if (rc < 0) {
1682 perror("ERR parsing SWL file");
1683 rc = -EINVAL;
1684 goto out;
1685 }
1686 if (rc < 2)
1687 continue;
1688
1689 fle = malloc(sizeof(*fle));
1690 if (!fle) {
1691 rc = -ENOMEM;
1692 goto out;
1693 }
1694 memset(fle, 0, sizeof(*fle));
1695
1696 /* construct new filename */
1697 strncpy(dir, bs11_sw->swl_fname, sizeof(dir));
1698 strncat(fle->fname, dirname(dir), sizeof(fle->fname) - 1);
1699 strcat(fle->fname, "/");
1700 strncat(fle->fname, file_id, sizeof(fle->fname) - 1 -strlen(fle->fname));
Harald Welte5e4d1b32009-02-01 13:36:56 +00001701
1702 llist_add_tail(&fle->list, &bs11_sw->file_list);
1703 }
1704
1705out:
1706 fclose(swl);
1707 return rc;
1708}
1709
1710/* bs11 swload specific callback, passed to abis_nm core swload */
1711static int bs11_swload_cbfn(unsigned int hook, unsigned int event,
1712 struct msgb *msg, void *data, void *param)
1713{
1714 struct abis_nm_bs11_sw *bs11_sw = data;
1715 struct file_list_entry *fle;
1716 int rc = 0;
1717
Harald Welte5e4d1b32009-02-01 13:36:56 +00001718 switch (event) {
1719 case NM_MT_LOAD_END_ACK:
1720 fle = fl_dequeue(&bs11_sw->file_list);
1721 if (fle) {
1722 /* start download the next file of our file list */
1723 rc = abis_nm_software_load(bs11_sw->bts, fle->fname,
1724 bs11_sw->win_size,
Harald Welte3ffd1372009-02-01 22:15:49 +00001725 bs11_sw->forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00001726 &bs11_swload_cbfn, bs11_sw);
1727 free(fle);
1728 } else {
1729 /* activate the SWL */
1730 rc = abis_nm_software_activate(bs11_sw->bts,
1731 bs11_sw->swl_fname,
1732 bs11_swload_cbfn,
1733 bs11_sw);
1734 }
1735 break;
Harald Welte3ffd1372009-02-01 22:15:49 +00001736 case NM_MT_LOAD_SEG_ACK:
Harald Welte5e4d1b32009-02-01 13:36:56 +00001737 case NM_MT_LOAD_END_NACK:
1738 case NM_MT_LOAD_INIT_ACK:
1739 case NM_MT_LOAD_INIT_NACK:
1740 case NM_MT_ACTIVATE_SW_NACK:
1741 case NM_MT_ACTIVATE_SW_ACK:
1742 default:
1743 /* fallthrough to the user callback */
Harald Welte97ed1e72009-02-06 13:38:02 +00001744 if (bs11_sw->user_cb)
1745 rc = bs11_sw->user_cb(hook, event, msg, NULL, NULL);
Harald Welte5e4d1b32009-02-01 13:36:56 +00001746 break;
1747 }
1748
1749 return rc;
1750}
1751
1752/* Siemens provides a SWL file that is a mere listing of all the other
1753 * files that are part of a software release. We need to upload first
1754 * the list file, and then each file that is listed in the list file */
1755int abis_nm_bs11_load_swl(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00001756 u_int8_t win_size, int forced, gsm_cbfn *cbfn)
Harald Welte5e4d1b32009-02-01 13:36:56 +00001757{
1758 struct abis_nm_bs11_sw *bs11_sw = g_bs11_sw;
1759 struct file_list_entry *fle;
1760 int rc = 0;
1761
1762 INIT_LLIST_HEAD(&bs11_sw->file_list);
1763 bs11_sw->bts = bts;
1764 bs11_sw->win_size = win_size;
1765 bs11_sw->user_cb = cbfn;
Harald Welte3ffd1372009-02-01 22:15:49 +00001766 bs11_sw->forced = forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001767
1768 strncpy(bs11_sw->swl_fname, fname, sizeof(bs11_sw->swl_fname));
1769 rc = bs11_read_swl_file(bs11_sw);
1770 if (rc < 0)
1771 return rc;
1772
1773 /* dequeue next item in file list */
1774 fle = fl_dequeue(&bs11_sw->file_list);
1775 if (!fle)
1776 return -EINVAL;
1777
1778 /* start download the next file of our file list */
Harald Welte3ffd1372009-02-01 22:15:49 +00001779 rc = abis_nm_software_load(bts, fle->fname, win_size, forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00001780 bs11_swload_cbfn, bs11_sw);
1781 free(fle);
1782 return rc;
1783}
1784
Harald Welte5083b0b2009-02-02 19:20:52 +00001785#if 0
Harald Welte5e4d1b32009-02-01 13:36:56 +00001786static u_int8_t req_attr_btse[] = {
1787 NM_ATT_ADM_STATE, NM_ATT_BS11_LMT_LOGON_SESSION,
1788 NM_ATT_BS11_LMT_LOGIN_TIME, NM_ATT_BS11_LMT_USER_ACC_LEV,
1789 NM_ATT_BS11_LMT_USER_NAME,
1790
1791 0xaf, NM_ATT_BS11_RX_OFFSET, NM_ATT_BS11_VENDOR_NAME,
1792
1793 NM_ATT_BS11_SW_LOAD_INTENDED, NM_ATT_BS11_SW_LOAD_SAFETY,
1794
1795 NM_ATT_BS11_SW_LOAD_STORED };
1796
1797static u_int8_t req_attr_btsm[] = {
1798 NM_ATT_ABIS_CHANNEL, NM_ATT_TEI, NM_ATT_BS11_ABIS_EXT_TIME,
1799 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xce, NM_ATT_FILE_ID,
1800 NM_ATT_FILE_VERSION, NM_ATT_OPER_STATE, 0xe8, NM_ATT_BS11_ALL_TEST_CATG,
1801 NM_ATT_SW_DESCR, NM_ATT_GET_ARI };
Harald Welte5083b0b2009-02-02 19:20:52 +00001802#endif
Harald Welte5e4d1b32009-02-01 13:36:56 +00001803
1804static u_int8_t req_attr[] = {
1805 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xa8, NM_ATT_OPER_STATE,
1806 0xd5, 0xa1, NM_ATT_BS11_ESN_FW_CODE_NO, NM_ATT_BS11_ESN_HW_CODE_NO,
1807 0x42, NM_ATT_BS11_ESN_PCB_SERIAL };
1808
1809int abis_nm_bs11_get_serno(struct gsm_bts *bts)
1810{
1811 struct abis_om_hdr *oh;
1812 struct msgb *msg = nm_msgb_alloc();
1813
1814 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1815 /* SiemensHW CCTRL object */
1816 fill_om_fom_hdr(oh, 2+sizeof(req_attr), NM_MT_GET_ATTR, NM_OC_BS11,
1817 0x03, 0x00, 0x00);
1818 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(req_attr), req_attr);
1819
1820 return abis_nm_sendmsg(bts, msg);
1821}
Harald Welte268bb402009-02-01 19:11:56 +00001822
1823int abis_nm_bs11_set_ext_time(struct gsm_bts *bts)
1824{
1825 struct abis_om_hdr *oh;
1826 struct msgb *msg = nm_msgb_alloc();
1827 struct bs11_date_time aet;
1828
1829 get_bs11_date_time(&aet);
1830 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1831 /* SiemensHW CCTRL object */
1832 fill_om_fom_hdr(oh, 2+sizeof(aet), NM_MT_BS11_SET_ATTR, NM_OC_SITE_MANAGER,
1833 0xff, 0xff, 0xff);
Harald Welte5083b0b2009-02-02 19:20:52 +00001834 msgb_tlv_put(msg, NM_ATT_BS11_ABIS_EXT_TIME, sizeof(aet), (u_int8_t *) &aet);
Harald Welte268bb402009-02-01 19:11:56 +00001835
1836 return abis_nm_sendmsg(bts, msg);
1837}
Harald Welte5c1e4582009-02-15 11:57:29 +00001838
1839/* ip.access nanoBTS specific commands */
Harald Welte5c1e4582009-02-15 11:57:29 +00001840static const char ipaccess_magic[] = "com.ipaccess";
1841
Harald Welte677c21f2009-02-17 13:22:23 +00001842
1843static int abis_nm_rx_ipacc(struct msgb *msg)
1844{
1845 struct abis_om_hdr *oh = msgb_l2(msg);
1846 struct abis_om_fom_hdr *foh;
1847 u_int8_t idstrlen = oh->data[0];
1848 struct tlv_parsed tp;
1849
1850 if (strncmp((char *)&oh->data[1], ipaccess_magic, idstrlen)) {
1851 DEBUGP(DNM, "id string is not com.ipaccess !?!\n");
1852 return -EINVAL;
1853 }
1854
1855 foh = (struct abis_om_fom_hdr *) oh->data + 1 + idstrlen;
1856 nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
1857
1858 switch (foh->msg_type) {
1859 case NM_MT_IPACC_RSL_CONNECT_ACK:
1860 DEBUGP(DNM, "IPACC: RSL CONNECT ACK");
1861 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_RSL_BSC_IP))
1862 DEBUGPC(DNM, "IP=%s\n",
1863 inet_ntoa(*((struct in_addr *)
1864 TLVP_VAL(&tp, NM_ATT_IPACC_RSL_BSC_IP))));
1865 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_RSL_BSC_PORT))
1866 DEBUGPC(DNM, "IP=%s\n",
1867 ntohs(*((u_int16_t *)
1868 TLVP_VAL(&tp, NM_ATT_IPACC_RSL_BSC_PORT))));
1869 break;
1870 case NM_MT_IPACC_RSL_CONNECT_NACK:
1871 DEBUGP(DNM, "IPACC: RSL CONNECT NACK");
1872 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
1873 DEBUGPC(DNM, " CAUSE=0x%02x\n", *TLVP_VAL(&tp, NM_ATT_NACK_CAUSES));
1874 else
1875 DEBUGPC(DNM, "\n");
1876 break;
1877 }
1878 return 0;
1879}
1880
Harald Welte5c1e4582009-02-15 11:57:29 +00001881int abis_nm_ipaccess_msg(struct gsm_bts *bts, u_int8_t msg_type,
1882 u_int8_t obj_class, u_int8_t bts_nr,
1883 u_int8_t trx_nr, u_int8_t ts_nr,
1884 u_int8_t *attr, int attr_len)
1885{
1886 struct msgb *msg = nm_msgb_alloc();
1887 struct abis_om_hdr *oh;
1888 struct abis_om_fom_hdr *foh;
1889 u_int8_t *data;
1890
1891 /* construct the 12.21 OM header, observe the erroneous length */
1892 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
1893 fill_om_hdr(oh, sizeof(*foh) + attr_len);
1894 oh->mdisc = ABIS_OM_MDISC_MANUF;
1895
1896 /* add the ip.access magic */
1897 data = msgb_put(msg, sizeof(ipaccess_magic)+1);
1898 *data++ = sizeof(ipaccess_magic);
1899 memcpy(data, ipaccess_magic, sizeof(ipaccess_magic));
1900
1901 /* fill the 12.21 FOM header */
1902 foh = (struct abis_om_fom_hdr *) msgb_put(msg, sizeof(*foh));
1903 foh->msg_type = msg_type;
1904 foh->obj_class = obj_class;
1905 foh->obj_inst.bts_nr = bts_nr;
1906 foh->obj_inst.trx_nr = trx_nr;
1907 foh->obj_inst.ts_nr = ts_nr;
1908
1909 if (attr && attr_len) {
1910 data = msgb_put(msg, attr_len);
1911 memcpy(data, attr, attr_len);
1912 }
1913
1914 return abis_nm_sendmsg(bts, msg);
1915}
Harald Welte677c21f2009-02-17 13:22:23 +00001916