blob: 9793dc4cd62135777fc11338d363b49433826ffb [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 Welte03133942009-02-18 19:51:53 +0000220 [NM_ATT_BS11_BTS_STATE] = { TLV_TYPE_TLV },
221 [NM_ATT_BS11_E1_STATE] = { TLV_TYPE_TLV },
Harald Welte677c21f2009-02-17 13:22:23 +0000222 /* ip.access specifics */
223 [NM_ATT_IPACC_RSL_BSC_IP] = { TLV_TYPE_FIXED, 4 },
224 [NM_ATT_IPACC_RSL_BSC_PORT] = { TLV_TYPE_FIXED, 2 },
225 [0x85] = { TLV_TYPE_TV },
226
Harald Weltee0590df2009-02-15 03:34:15 +0000227 },
228};
Harald Welte03133942009-02-18 19:51:53 +0000229
230int abis_nm_tlv_parse(struct tlv_parsed *tp, const u_int8_t *buf, int len)
231{
232 return tlv_parse(tp, &nm_att_tlvdef, buf, len);
233}
Harald Weltee0590df2009-02-15 03:34:15 +0000234
Harald Welte52b1f982008-12-23 20:25:15 +0000235static int is_in_arr(enum abis_nm_msgtype mt, const enum abis_nm_msgtype *arr, int size)
236{
237 int i;
238
239 for (i = 0; i < size; i++) {
240 if (arr[i] == mt)
241 return 1;
242 }
243
244 return 0;
245}
246
Holger Freytherca362a62009-01-04 21:05:01 +0000247#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000248/* is this msgtype the usual ACK/NACK type ? */
249static int is_ack_nack(enum abis_nm_msgtype mt)
250{
251 return !is_in_arr(mt, no_ack_nack, ARRAY_SIZE(no_ack_nack));
252}
Holger Freytherca362a62009-01-04 21:05:01 +0000253#endif
Harald Welte52b1f982008-12-23 20:25:15 +0000254
255/* is this msgtype a report ? */
256static int is_report(enum abis_nm_msgtype mt)
257{
Harald Welte8470bf22008-12-25 23:28:35 +0000258 return is_in_arr(mt, reports, ARRAY_SIZE(reports));
Harald Welte52b1f982008-12-23 20:25:15 +0000259}
260
261#define MT_ACK(x) (x+1)
262#define MT_NACK(x) (x+2)
263
264static void fill_om_hdr(struct abis_om_hdr *oh, u_int8_t len)
265{
266 oh->mdisc = ABIS_OM_MDISC_FOM;
267 oh->placement = ABIS_OM_PLACEMENT_ONLY;
268 oh->sequence = 0;
269 oh->length = len;
270}
271
272static void fill_om_fom_hdr(struct abis_om_hdr *oh, u_int8_t len,
273 u_int8_t msg_type, u_int8_t obj_class,
274 u_int8_t bts_nr, u_int8_t trx_nr, u_int8_t ts_nr)
275{
276 struct abis_om_fom_hdr *foh =
277 (struct abis_om_fom_hdr *) oh->data;
278
Harald Welte702d8702008-12-26 20:25:35 +0000279 fill_om_hdr(oh, len+sizeof(*foh));
Harald Welte52b1f982008-12-23 20:25:15 +0000280 foh->msg_type = msg_type;
281 foh->obj_class = obj_class;
282 foh->obj_inst.bts_nr = bts_nr;
283 foh->obj_inst.trx_nr = trx_nr;
284 foh->obj_inst.ts_nr = ts_nr;
285}
286
Harald Welte8470bf22008-12-25 23:28:35 +0000287static struct msgb *nm_msgb_alloc(void)
288{
289 return msgb_alloc_headroom(OM_ALLOC_SIZE, OM_HEADROOM_SIZE);
290}
291
Harald Welte52b1f982008-12-23 20:25:15 +0000292/* Send a OML NM Message from BSC to BTS */
293int abis_nm_sendmsg(struct gsm_bts *bts, struct msgb *msg)
294{
Holger Freyther59639e82009-02-09 23:09:55 +0000295 msg->trx = bts->c0;
296
Harald Weltead384642008-12-26 10:20:07 +0000297 return _abis_nm_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000298}
299
Harald Welte4724f992009-01-18 18:01:49 +0000300static int abis_nm_rcvmsg_sw(struct msgb *mb);
301
Harald Welte34a99682009-02-13 02:41:40 +0000302const char *oc_names[] = {
303 [NM_OC_SITE_MANAGER] = "SITE MANAGER",
304 [NM_OC_BTS] = "BTS",
305 [NM_OC_RADIO_CARRIER] = "RADIO CARRIER",
306 [NM_OC_BASEB_TRANSC] = "BASEBAND TRANSCEIVER",
307 [NM_OC_CHANNEL] = "CHANNEL",
308};
309
310static const char *obj_class_name(u_int8_t oc)
311{
312 if (oc >= ARRAY_SIZE(oc_names))
313 return "UNKNOWN";
314 return oc_names[oc];
315}
316
317static const char *opstate_name(u_int8_t os)
318{
319 switch (os) {
320 case 1:
321 return "Disabled";
322 case 2:
323 return "Enabled";
324 case 0xff:
325 return "NULL";
326 default:
327 return "RFU";
328 }
329}
330
Harald Weltee0590df2009-02-15 03:34:15 +0000331/* Chapter 9.4.7 */
332const char *avail_names[] = {
333 "In test",
334 "Failed",
335 "Power off",
336 "Off line",
337 "<not used>",
338 "Dependency",
339 "Degraded",
340 "Not installed",
341};
342
343static const char *avail_name(u_int8_t avail)
344{
Harald Welte0b8348d2009-02-18 03:43:01 +0000345 if (avail == 0xff)
346 return "OK";
Harald Weltee0590df2009-02-15 03:34:15 +0000347 if (avail >= ARRAY_SIZE(avail_names))
348 return "UNKNOWN";
349 return avail_names[avail];
350}
351
352
353/* obtain the gsm_nm_state data structure for a given object instance */
354static struct gsm_nm_state *
355objclass2nmstate(struct gsm_bts *bts, u_int8_t obj_class,
356 struct abis_om_obj_inst *obj_inst)
357{
358 struct gsm_bts_trx *trx;
359 struct gsm_nm_state *nm_state = NULL;
360
361 switch (obj_class) {
362 case NM_OC_BTS:
363 nm_state = &bts->nm_state;
364 break;
365 case NM_OC_RADIO_CARRIER:
366 if (obj_inst->trx_nr >= bts->num_trx)
367 return NULL;
368 trx = &bts->trx[obj_inst->trx_nr];
369 nm_state = &trx->nm_state;
370 break;
371 case NM_OC_BASEB_TRANSC:
372 if (obj_inst->trx_nr >= bts->num_trx)
373 return NULL;
374 trx = &bts->trx[obj_inst->trx_nr];
375 nm_state = &trx->bb_transc.nm_state;
376 break;
377 case NM_OC_CHANNEL:
378 if (obj_inst->trx_nr > bts->num_trx)
379 return NULL;
380 trx = &bts->trx[obj_inst->trx_nr];
381 if (obj_inst->ts_nr >= TRX_NR_TS)
382 return NULL;
383 nm_state = &trx->ts[obj_inst->ts_nr].nm_state;
384 break;
385 case NM_OC_SITE_MANAGER:
386 nm_state = &bts->site_mgr.nm_state;
387 break;
388 }
389 return nm_state;
390}
391
392/* obtain the in-memory data structure of a given object instance */
393static void *
394objclass2obj(struct gsm_bts *bts, u_int8_t obj_class,
395 struct abis_om_obj_inst *obj_inst)
396{
397 struct gsm_bts_trx *trx;
398 void *obj = NULL;
399
400 switch (obj_class) {
401 case NM_OC_BTS:
402 obj = bts;
403 break;
404 case NM_OC_RADIO_CARRIER:
405 if (obj_inst->trx_nr >= bts->num_trx)
406 return NULL;
407 trx = &bts->trx[obj_inst->trx_nr];
408 obj = trx;
409 break;
410 case NM_OC_BASEB_TRANSC:
411 if (obj_inst->trx_nr >= bts->num_trx)
412 return NULL;
413 trx = &bts->trx[obj_inst->trx_nr];
414 obj = &trx->bb_transc;
415 break;
416 case NM_OC_CHANNEL:
417 if (obj_inst->trx_nr > bts->num_trx)
418 return NULL;
419 trx = &bts->trx[obj_inst->trx_nr];
420 if (obj_inst->ts_nr >= TRX_NR_TS)
421 return NULL;
422 obj = &trx->ts[obj_inst->ts_nr];
423 break;
424 case NM_OC_SITE_MANAGER:
425 obj = &bts->site_mgr;
426 break;
427 }
428 return obj;
429}
430
431/* Update the administrative state of a given object in our in-memory data
432 * structures and send an event to the higher layer */
433static int update_admstate(struct gsm_bts *bts, u_int8_t obj_class,
434 struct abis_om_obj_inst *obj_inst, u_int8_t adm_state)
435{
436 struct gsm_nm_state *nm_state;
437 void *obj;
438 int rc;
439
440 nm_state = objclass2nmstate(bts, obj_class, obj_inst);
441 obj = objclass2obj(bts, obj_class, obj_inst);
442 rc = nm_state_event(EVT_STATECHG_ADM, obj_class, obj, nm_state, adm_state);
443 if (nm_state)
444 nm_state->administrative = adm_state;
445
446 return rc;
447}
448
Harald Welte97ed1e72009-02-06 13:38:02 +0000449static int abis_nm_rx_statechg_rep(struct msgb *mb)
450{
Harald Weltee0590df2009-02-15 03:34:15 +0000451 struct abis_om_hdr *oh = msgb_l2(mb);
Harald Welte97ed1e72009-02-06 13:38:02 +0000452 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Harald Welte22af0db2009-02-14 15:41:08 +0000453 struct gsm_bts *bts = mb->trx->bts;
Harald Weltee0590df2009-02-15 03:34:15 +0000454 struct tlv_parsed tp;
455 struct gsm_nm_state *nm_state, new_state;
456 int rc;
457
Harald Welte34a99682009-02-13 02:41:40 +0000458 DEBUGP(DNM, "STATE CHG: OC=%s(%02x) INST=(%02x,%02x,%02x) ",
459 obj_class_name(foh->obj_class), foh->obj_class,
460 foh->obj_inst.bts_nr, foh->obj_inst.trx_nr,
Harald Welte97ed1e72009-02-06 13:38:02 +0000461 foh->obj_inst.ts_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000462
463 nm_state = objclass2nmstate(bts, foh->obj_class, &foh->obj_inst);
464 if (!nm_state) {
465 DEBUGPC(DNM, "\n");
466 return -EINVAL;
Harald Welte22af0db2009-02-14 15:41:08 +0000467 }
Harald Weltee0590df2009-02-15 03:34:15 +0000468
469 new_state = *nm_state;
470
Harald Welte03133942009-02-18 19:51:53 +0000471 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Weltee0590df2009-02-15 03:34:15 +0000472 if (TLVP_PRESENT(&tp, NM_ATT_OPER_STATE)) {
473 new_state.operational = *TLVP_VAL(&tp, NM_ATT_OPER_STATE);
474 DEBUGPC(DNM, "OP_STATE=%s ", opstate_name(new_state.operational));
475 }
476 if (TLVP_PRESENT(&tp, NM_ATT_AVAIL_STATUS)) {
Harald Welte0b8348d2009-02-18 03:43:01 +0000477 if (TLVP_LEN(&tp, NM_ATT_AVAIL_STATUS) == 0)
478 new_state.availability = 0xff;
479 else
480 new_state.availability = *TLVP_VAL(&tp, NM_ATT_AVAIL_STATUS);
Harald Weltee0590df2009-02-15 03:34:15 +0000481 DEBUGPC(DNM, "AVAIL=%s(%02x) ", avail_name(new_state.availability),
482 new_state.availability);
483 }
484 if (TLVP_PRESENT(&tp, NM_ATT_ADM_STATE)) {
485 new_state.administrative = *TLVP_VAL(&tp, NM_ATT_ADM_STATE);
486 DEBUGPC(DNM, "ADM=%02x ", new_state.administrative);
Harald Welte97ed1e72009-02-06 13:38:02 +0000487 }
488 DEBUGPC(DNM, "\n");
Harald Weltee0590df2009-02-15 03:34:15 +0000489
490 if (memcmp(&new_state, nm_state, sizeof(new_state))) {
491 /* Update the operational state of a given object in our in-memory data
492 * structures and send an event to the higher layer */
493 void *obj = objclass2obj(bts, foh->obj_class, &foh->obj_inst);
494 rc = nm_state_event(EVT_STATECHG_OPER, foh->obj_class, obj, nm_state, &new_state);
495 *nm_state = new_state;
496 }
497#if 0
Harald Welte22af0db2009-02-14 15:41:08 +0000498 if (op_state == 1) {
499 /* try to enable objects that are disabled */
500 abis_nm_opstart(bts, foh->obj_class,
501 foh->obj_inst.bts_nr,
502 foh->obj_inst.trx_nr,
503 foh->obj_inst.ts_nr);
504 }
Harald Weltee0590df2009-02-15 03:34:15 +0000505#endif
Harald Welte97ed1e72009-02-06 13:38:02 +0000506 return 0;
507}
508
509static int abis_nm_rcvmsg_report(struct msgb *mb)
510{
511 struct abis_om_fom_hdr *foh = msgb_l3(mb);
512 u_int8_t mt = foh->msg_type;
513
514 //nmh->cfg->report_cb(mb, foh);
515
516 switch (mt) {
517 case NM_MT_STATECHG_EVENT_REP:
518 return abis_nm_rx_statechg_rep(mb);
519 break;
Harald Welte34a99682009-02-13 02:41:40 +0000520 case NM_MT_SW_ACTIVATED_REP:
521 DEBUGP(DNM, "Software Activated Report\n");
522 break;
Harald Weltee0590df2009-02-15 03:34:15 +0000523 case NM_MT_FAILURE_EVENT_REP:
524 DEBUGP(DNM, "Failure Event Report\n");
525 break;
526 default:
527 DEBUGP(DNM, "reporting NM MT 0x%02x\n", mt);
528 break;
529
Harald Welte97ed1e72009-02-06 13:38:02 +0000530 };
531
Harald Welte97ed1e72009-02-06 13:38:02 +0000532 return 0;
533}
534
Harald Welte34a99682009-02-13 02:41:40 +0000535/* Activate the specified software into the BTS */
536static int ipacc_sw_activate(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1,
537 u_int8_t i2, u_int8_t *sw_desc, u_int8_t swdesc_len)
538{
539 struct abis_om_hdr *oh;
540 struct msgb *msg = nm_msgb_alloc();
541 u_int8_t len = swdesc_len;
542 u_int8_t *trailer;
543
544 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
545 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, obj_class, i0, i1, i2);
546
547 trailer = msgb_put(msg, swdesc_len);
548 memcpy(trailer, sw_desc, swdesc_len);
549
550 return abis_nm_sendmsg(bts, msg);
551}
552
553static int abis_nm_rx_sw_act_req(struct msgb *mb)
554{
555 struct abis_om_hdr *oh = msgb_l2(mb);
556 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Harald Welte5c1e4582009-02-15 11:57:29 +0000557 int nack = 0;
Harald Welte34a99682009-02-13 02:41:40 +0000558 int ret;
559
Harald Welte5c1e4582009-02-15 11:57:29 +0000560 DEBUGP(DNM, "Software Activate Request ");
Harald Welte34a99682009-02-13 02:41:40 +0000561
Harald Welte5c1e4582009-02-15 11:57:29 +0000562 if (foh->obj_class >= 0xf0 && foh->obj_class <= 0xf3) {
563 DEBUGPC(DNM, "NACKing for GPRS obj_class 0x%02x\n", foh->obj_class);
564 nack = 1;
565 } else
566 DEBUGPC(DNM, "ACKing and Activating\n");
567
568 ret = abis_nm_sw_act_req_ack(mb->trx->bts, foh->obj_class,
Harald Welte34a99682009-02-13 02:41:40 +0000569 foh->obj_inst.bts_nr,
570 foh->obj_inst.trx_nr,
Harald Welte5c1e4582009-02-15 11:57:29 +0000571 foh->obj_inst.ts_nr, nack,
Harald Welte34a99682009-02-13 02:41:40 +0000572 foh->data, oh->length-sizeof(*foh));
573
Harald Welte5c1e4582009-02-15 11:57:29 +0000574 if (nack)
575 return ret;
576
Harald Welte34a99682009-02-13 02:41:40 +0000577 /* FIXME: properly parse attributes */
578 return ipacc_sw_activate(mb->trx->bts, foh->obj_class,
579 foh->obj_inst.bts_nr,
580 foh->obj_inst.trx_nr,
581 foh->obj_inst.ts_nr,
582 foh->data + oh->length-sizeof(*foh)-22, 22);
583}
584
Harald Weltee0590df2009-02-15 03:34:15 +0000585/* Receive a CHANGE_ADM_STATE_ACK, parse the TLV and update local state */
586static int abis_nm_rx_chg_adm_state_ack(struct msgb *mb)
587{
588 struct abis_om_hdr *oh = msgb_l2(mb);
589 struct abis_om_fom_hdr *foh = msgb_l3(mb);
590 struct tlv_parsed tp;
591 u_int8_t adm_state;
592
Harald Welte03133942009-02-18 19:51:53 +0000593 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Weltee0590df2009-02-15 03:34:15 +0000594 if (!TLVP_PRESENT(&tp, NM_ATT_ADM_STATE))
595 return -EINVAL;
596
597 adm_state = *TLVP_VAL(&tp, NM_ATT_ADM_STATE);
598
599 return update_admstate(mb->trx->bts, foh->obj_class, &foh->obj_inst, adm_state);
600}
601
Harald Welte52b1f982008-12-23 20:25:15 +0000602/* Receive a OML NM Message from BTS */
Harald Welte8470bf22008-12-25 23:28:35 +0000603static int abis_nm_rcvmsg_fom(struct msgb *mb)
Harald Welte52b1f982008-12-23 20:25:15 +0000604{
605 struct abis_om_fom_hdr *foh = msgb_l3(mb);
606 u_int8_t mt = foh->msg_type;
607
608 /* check for unsolicited message */
Harald Welte97ed1e72009-02-06 13:38:02 +0000609 if (is_report(mt))
610 return abis_nm_rcvmsg_report(mb);
Harald Welte52b1f982008-12-23 20:25:15 +0000611
Harald Welte4724f992009-01-18 18:01:49 +0000612 if (is_in_arr(mt, sw_load_msgs, ARRAY_SIZE(sw_load_msgs)))
613 return abis_nm_rcvmsg_sw(mb);
614
Harald Weltee0590df2009-02-15 03:34:15 +0000615 if (is_in_arr(mt, nacks, ARRAY_SIZE(nacks)))
616 DEBUGP(DNM, "NACK 0x%02x\n", mt);
Harald Weltead384642008-12-26 10:20:07 +0000617#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000618 /* check if last message is to be acked */
619 if (is_ack_nack(nmh->last_msgtype)) {
620 if (mt == MT_ACK(nmh->last_msgtype)) {
621 fprintf(stderr, "received ACK (0x%x)\n",
622 foh->msg_type);
623 /* we got our ACK, continue sending the next msg */
624 } else if (mt == MT_NACK(nmh->last_msgtype)) {
625 /* we got a NACK, signal this to the caller */
626 fprintf(stderr, "received NACK (0x%x)\n",
627 foh->msg_type);
628 /* FIXME: somehow signal this to the caller */
629 } else {
630 /* really strange things happen */
631 return -EINVAL;
632 }
633 }
Harald Weltead384642008-12-26 10:20:07 +0000634#endif
635
Harald Welte97ed1e72009-02-06 13:38:02 +0000636 switch (mt) {
Harald Weltee0590df2009-02-15 03:34:15 +0000637 case NM_MT_CHG_ADM_STATE_ACK:
638 return abis_nm_rx_chg_adm_state_ack(mb);
639 break;
Harald Welte34a99682009-02-13 02:41:40 +0000640 case NM_MT_SW_ACT_REQ:
641 return abis_nm_rx_sw_act_req(mb);
642 break;
Harald Welte97ed1e72009-02-06 13:38:02 +0000643 case NM_MT_BS11_LMT_SESSION:
644 DEBUGP(DNM, "LMT Event: \n");
645 break;
646 }
647
Harald Weltead384642008-12-26 10:20:07 +0000648 return 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000649}
650
Harald Welte677c21f2009-02-17 13:22:23 +0000651static int abis_nm_rx_ipacc(struct msgb *mb);
652
653static int abis_nm_rcvmsg_manuf(struct msgb *mb)
654{
655 int rc;
656 int bts_type = mb->trx->bts->type;
657
658 switch (bts_type) {
659 case GSM_BTS_TYPE_NANOBTS_900:
660 case GSM_BTS_TYPE_NANOBTS_1800:
661 rc = abis_nm_rx_ipacc(mb);
662 break;
663 default:
664 fprintf(stderr, "don't know how to parse OML for this "
665 "BTS type (%u)\n", bts_type);
666 rc = 0;
667 break;
668 }
669
670 return rc;
671}
672
Harald Welte52b1f982008-12-23 20:25:15 +0000673/* High-Level API */
674/* Entry-point where L2 OML from BTS enters the NM code */
Harald Welte8470bf22008-12-25 23:28:35 +0000675int abis_nm_rcvmsg(struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +0000676{
Harald Welte52b1f982008-12-23 20:25:15 +0000677 struct abis_om_hdr *oh = msgb_l2(msg);
Harald Welte677c21f2009-02-17 13:22:23 +0000678 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000679
680 /* Various consistency checks */
681 if (oh->placement != ABIS_OM_PLACEMENT_ONLY) {
682 fprintf(stderr, "ABIS OML placement 0x%x not supported\n",
683 oh->placement);
684 return -EINVAL;
685 }
686 if (oh->sequence != 0) {
687 fprintf(stderr, "ABIS OML sequence 0x%x != 0x00\n",
688 oh->sequence);
689 return -EINVAL;
690 }
Harald Welte702d8702008-12-26 20:25:35 +0000691#if 0
Holger Freytherca362a62009-01-04 21:05:01 +0000692 unsigned int l2_len = msg->tail - (u_int8_t *)msgb_l2(msg);
693 unsigned int hlen = sizeof(*oh) + sizeof(struct abis_om_fom_hdr);
Harald Welte702d8702008-12-26 20:25:35 +0000694 if (oh->length + hlen > l2_len) {
Harald Welte52b1f982008-12-23 20:25:15 +0000695 fprintf(stderr, "ABIS OML truncated message (%u > %u)\n",
696 oh->length + sizeof(*oh), l2_len);
697 return -EINVAL;
698 }
Harald Welte702d8702008-12-26 20:25:35 +0000699 if (oh->length + hlen < l2_len)
700 fprintf(stderr, "ABIS OML message with extra trailer?!? (oh->len=%d, sizeof_oh=%d l2_len=%d\n", oh->length, sizeof(*oh), l2_len);
701#endif
Harald Weltead384642008-12-26 10:20:07 +0000702 msg->l3h = (unsigned char *)oh + sizeof(*oh);
Harald Welte52b1f982008-12-23 20:25:15 +0000703
704 switch (oh->mdisc) {
705 case ABIS_OM_MDISC_FOM:
Harald Welte8470bf22008-12-25 23:28:35 +0000706 rc = abis_nm_rcvmsg_fom(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000707 break;
Harald Welte677c21f2009-02-17 13:22:23 +0000708 case ABIS_OM_MDISC_MANUF:
709 rc = abis_nm_rcvmsg_manuf(msg);
710 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000711 case ABIS_OM_MDISC_MMI:
712 case ABIS_OM_MDISC_TRAU:
Harald Welte677c21f2009-02-17 13:22:23 +0000713 fprintf(stderr, "unimplemented ABIS OML message discriminator 0x%x\n",
714 oh->mdisc);
715 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000716 default:
717 fprintf(stderr, "unknown ABIS OML message discriminator 0x%x\n",
718 oh->mdisc);
719 return -EINVAL;
720 }
721
Harald Weltead384642008-12-26 10:20:07 +0000722 msgb_free(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000723 return rc;
724}
725
726#if 0
727/* initialized all resources */
728struct abis_nm_h *abis_nm_init(struct abis_nm_cfg *cfg)
729{
730 struct abis_nm_h *nmh;
731
732 nmh = malloc(sizeof(*nmh));
733 if (!nmh)
734 return NULL;
735
736 nmh->cfg = cfg;
737
738 return nmh;
739}
740
741/* free all resources */
742void abis_nm_fini(struct abis_nm_h *nmh)
743{
744 free(nmh);
745}
746#endif
747
748/* Here we are trying to define a high-level API that can be used by
749 * the actual BSC implementation. However, the architecture is currently
750 * still under design. Ideally the calls to this API would be synchronous,
751 * while the underlying stack behind the APi runs in a traditional select
752 * based state machine.
753 */
754
Harald Welte4724f992009-01-18 18:01:49 +0000755/* 6.2 Software Load: */
756enum sw_state {
757 SW_STATE_NONE,
758 SW_STATE_WAIT_INITACK,
759 SW_STATE_WAIT_SEGACK,
760 SW_STATE_WAIT_ENDACK,
761 SW_STATE_WAIT_ACTACK,
762 SW_STATE_ERROR,
763};
Harald Welte52b1f982008-12-23 20:25:15 +0000764
Harald Welte52b1f982008-12-23 20:25:15 +0000765struct abis_nm_sw {
Harald Welte4724f992009-01-18 18:01:49 +0000766 struct gsm_bts *bts;
Harald Welte5e4d1b32009-02-01 13:36:56 +0000767 gsm_cbfn *cbfn;
768 void *cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +0000769 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +0000770
Harald Welte52b1f982008-12-23 20:25:15 +0000771 /* this will become part of the SW LOAD INITIATE */
772 u_int8_t obj_class;
773 u_int8_t obj_instance[3];
Harald Welte4724f992009-01-18 18:01:49 +0000774
775 u_int8_t file_id[255];
776 u_int8_t file_id_len;
777
778 u_int8_t file_version[255];
779 u_int8_t file_version_len;
780
781 u_int8_t window_size;
782 u_int8_t seg_in_window;
783
784 int fd;
785 FILE *stream;
786 enum sw_state state;
Harald Welte1602ade2009-01-29 21:12:39 +0000787 int last_seg;
Harald Welte52b1f982008-12-23 20:25:15 +0000788};
789
Harald Welte4724f992009-01-18 18:01:49 +0000790static struct abis_nm_sw g_sw;
791
792/* 6.2.1 / 8.3.1: Load Data Initiate */
793static int sw_load_init(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +0000794{
Harald Welte4724f992009-01-18 18:01:49 +0000795 struct abis_om_hdr *oh;
796 struct msgb *msg = nm_msgb_alloc();
797 u_int8_t len = 3*2 + sw->file_id_len + sw->file_version_len;
798
799 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
800 fill_om_fom_hdr(oh, len, NM_MT_LOAD_INIT, sw->obj_class,
801 sw->obj_instance[0], sw->obj_instance[1],
802 sw->obj_instance[2]);
803
804 /* FIXME: this is BS11 specific format */
805 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
806 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
807 sw->file_version);
808 msgb_tv_put(msg, NM_ATT_WINDOW_SIZE, sw->window_size);
809
810 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000811}
812
Harald Welte1602ade2009-01-29 21:12:39 +0000813static int is_last_line(FILE *stream)
814{
815 char next_seg_buf[256];
816 long pos;
817
818 /* check if we're sending the last line */
819 pos = ftell(stream);
820 if (!fgets(next_seg_buf, sizeof(next_seg_buf)-2, stream)) {
821 fseek(stream, pos, SEEK_SET);
822 return 1;
823 }
824
825 fseek(stream, pos, SEEK_SET);
826 return 0;
827}
828
Harald Welte4724f992009-01-18 18:01:49 +0000829/* 6.2.2 / 8.3.2 Load Data Segment */
830static int sw_load_segment(struct abis_nm_sw *sw)
831{
832 struct abis_om_hdr *oh;
833 struct msgb *msg = nm_msgb_alloc();
834 char seg_buf[256];
835 char *line_buf = seg_buf+2;
Harald Welte3b8ba212009-01-29 12:27:58 +0000836 unsigned char *tlv;
Harald Welte4724f992009-01-18 18:01:49 +0000837 u_int8_t len;
Harald Welte4724f992009-01-18 18:01:49 +0000838
839 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte3b8ba212009-01-29 12:27:58 +0000840
841 switch (sw->bts->type) {
842 case GSM_BTS_TYPE_BS11:
843 if (fgets(line_buf, sizeof(seg_buf)-2, sw->stream) == NULL) {
844 perror("fgets reading segment");
845 return -EINVAL;
846 }
847 seg_buf[0] = 0x00;
Harald Welte1602ade2009-01-29 21:12:39 +0000848
849 /* check if we're sending the last line */
850 sw->last_seg = is_last_line(sw->stream);
851 if (sw->last_seg)
852 seg_buf[1] = 0;
853 else
854 seg_buf[1] = 1 + sw->seg_in_window++;
Harald Welte3b8ba212009-01-29 12:27:58 +0000855
856 len = strlen(line_buf) + 2;
857 tlv = msgb_put(msg, TLV_GROSS_LEN(len));
858 tlv_put(tlv, NM_ATT_BS11_FILE_DATA, len, (u_int8_t *)seg_buf);
859 /* BS11 wants CR + LF in excess of the TLV length !?! */
860 tlv[1] -= 2;
861
862 /* we only now know the exact length for the OM hdr */
863 len = strlen(line_buf)+2;
864 break;
865 default:
866 /* FIXME: Other BTS types */
867 return -1;
Harald Welte4724f992009-01-18 18:01:49 +0000868 }
Harald Welte4724f992009-01-18 18:01:49 +0000869
Harald Welte4724f992009-01-18 18:01:49 +0000870 fill_om_fom_hdr(oh, len, NM_MT_LOAD_SEG, sw->obj_class,
871 sw->obj_instance[0], sw->obj_instance[1],
872 sw->obj_instance[2]);
873
874 return abis_nm_sendmsg(sw->bts, msg);
875}
876
877/* 6.2.4 / 8.3.4 Load Data End */
878static int sw_load_end(struct abis_nm_sw *sw)
879{
880 struct abis_om_hdr *oh;
881 struct msgb *msg = nm_msgb_alloc();
882 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
883
884 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
885 fill_om_fom_hdr(oh, len, NM_MT_LOAD_END, sw->obj_class,
886 sw->obj_instance[0], sw->obj_instance[1],
887 sw->obj_instance[2]);
888
889 /* FIXME: this is BS11 specific format */
890 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
891 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
892 sw->file_version);
893
894 return abis_nm_sendmsg(sw->bts, msg);
895}
Harald Welte5e4d1b32009-02-01 13:36:56 +0000896
Harald Welte52b1f982008-12-23 20:25:15 +0000897/* Activate the specified software into the BTS */
Harald Welte4724f992009-01-18 18:01:49 +0000898static int sw_activate(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +0000899{
Harald Welte4724f992009-01-18 18:01:49 +0000900 struct abis_om_hdr *oh;
901 struct msgb *msg = nm_msgb_alloc();
902 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
Harald Welte52b1f982008-12-23 20:25:15 +0000903
Harald Welte4724f992009-01-18 18:01:49 +0000904 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
905 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, sw->obj_class,
906 sw->obj_instance[0], sw->obj_instance[1],
907 sw->obj_instance[2]);
908
909 /* FIXME: this is BS11 specific format */
910 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
911 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
912 sw->file_version);
913
914 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000915}
Harald Welte4724f992009-01-18 18:01:49 +0000916
917static int sw_open_file(struct abis_nm_sw *sw, const char *fname)
918{
919 char file_id[12+1];
920 char file_version[80+1];
921 int rc;
922
923 sw->fd = open(fname, O_RDONLY);
924 if (sw->fd < 0)
925 return sw->fd;
926
927 switch (sw->bts->type) {
928 case GSM_BTS_TYPE_BS11:
929 sw->stream = fdopen(sw->fd, "r");
930 if (!sw->stream) {
931 perror("fdopen");
932 return -1;
933 }
934 /* read first line and parse file ID and VERSION */
Harald Welte3b8ba212009-01-29 12:27:58 +0000935 rc = fscanf(sw->stream, "@(#)%12s:%80s\r\n",
Harald Welte4724f992009-01-18 18:01:49 +0000936 file_id, file_version);
937 if (rc != 2) {
938 perror("parsing header line of software file");
939 return -1;
940 }
941 strcpy((char *)sw->file_id, file_id);
942 sw->file_id_len = strlen(file_id);
943 strcpy((char *)sw->file_version, file_version);
944 sw->file_version_len = strlen(file_version);
945 /* rewind to start of file */
Harald Welte3b8ba212009-01-29 12:27:58 +0000946 rewind(sw->stream);
Harald Welte4724f992009-01-18 18:01:49 +0000947 break;
948 default:
949 /* We don't know how to treat them yet */
950 close(sw->fd);
951 return -EINVAL;
952 }
953
954 return 0;
955}
956
957static void sw_close_file(struct abis_nm_sw *sw)
958{
959 switch (sw->bts->type) {
960 case GSM_BTS_TYPE_BS11:
961 fclose(sw->stream);
962 break;
963 default:
964 close(sw->fd);
965 break;
966 }
967}
968
969/* Fill the window */
970static int sw_fill_window(struct abis_nm_sw *sw)
971{
972 int rc;
973
974 while (sw->seg_in_window < sw->window_size) {
975 rc = sw_load_segment(sw);
976 if (rc < 0)
977 return rc;
Harald Welte1602ade2009-01-29 21:12:39 +0000978 if (sw->last_seg)
979 break;
Harald Welte4724f992009-01-18 18:01:49 +0000980 }
981 return 0;
982}
983
984/* callback function from abis_nm_rcvmsg() handler */
985static int abis_nm_rcvmsg_sw(struct msgb *mb)
986{
987 struct abis_om_fom_hdr *foh = msgb_l3(mb);
988 int rc = -1;
989 struct abis_nm_sw *sw = &g_sw;
990 enum sw_state old_state = sw->state;
991
Harald Welte3ffd1372009-02-01 22:15:49 +0000992 //DEBUGP(DNM, "state %u, NM MT 0x%02x\n", sw->state, foh->msg_type);
Harald Welte4724f992009-01-18 18:01:49 +0000993
994 switch (sw->state) {
995 case SW_STATE_WAIT_INITACK:
996 switch (foh->msg_type) {
997 case NM_MT_LOAD_INIT_ACK:
998 /* fill window with segments */
Harald Welte5e4d1b32009-02-01 13:36:56 +0000999 if (sw->cbfn)
1000 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1001 NM_MT_LOAD_INIT_ACK, mb,
1002 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001003 rc = sw_fill_window(sw);
1004 sw->state = SW_STATE_WAIT_SEGACK;
1005 break;
1006 case NM_MT_LOAD_INIT_NACK:
Harald Welte3ffd1372009-02-01 22:15:49 +00001007 if (sw->forced) {
1008 DEBUGP(DNM, "FORCED: Ignoring Software Load "
1009 "Init NACK\n");
1010 if (sw->cbfn)
1011 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1012 NM_MT_LOAD_INIT_ACK, mb,
1013 sw->cb_data, NULL);
1014 rc = sw_fill_window(sw);
1015 sw->state = SW_STATE_WAIT_SEGACK;
1016 } else {
1017 DEBUGP(DNM, "Software Load Init NACK\n");
1018 if (sw->cbfn)
1019 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1020 NM_MT_LOAD_INIT_NACK, mb,
1021 sw->cb_data, NULL);
1022 sw->state = SW_STATE_ERROR;
1023 }
Harald Welte4724f992009-01-18 18:01:49 +00001024 break;
1025 }
1026 break;
1027 case SW_STATE_WAIT_SEGACK:
1028 switch (foh->msg_type) {
1029 case NM_MT_LOAD_SEG_ACK:
Harald Welte3ffd1372009-02-01 22:15:49 +00001030 if (sw->cbfn)
1031 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1032 NM_MT_LOAD_SEG_ACK, mb,
1033 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001034 sw->seg_in_window = 0;
Harald Welte1602ade2009-01-29 21:12:39 +00001035 if (!sw->last_seg) {
1036 /* fill window with more segments */
1037 rc = sw_fill_window(sw);
1038 sw->state = SW_STATE_WAIT_SEGACK;
1039 } else {
1040 /* end the transfer */
1041 sw->state = SW_STATE_WAIT_ENDACK;
1042 rc = sw_load_end(sw);
1043 }
Harald Welte4724f992009-01-18 18:01:49 +00001044 break;
1045 }
1046 break;
1047 case SW_STATE_WAIT_ENDACK:
1048 switch (foh->msg_type) {
1049 case NM_MT_LOAD_END_ACK:
1050 sw_close_file(sw);
Harald Welte5e4d1b32009-02-01 13:36:56 +00001051 DEBUGP(DNM, "Software Load End (BTS %u)\n",
1052 sw->bts->nr);
1053 sw->state = SW_STATE_NONE;
1054 if (sw->cbfn)
1055 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1056 NM_MT_LOAD_END_ACK, mb,
1057 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001058 break;
1059 case NM_MT_LOAD_END_NACK:
Holger Freyther31338a12009-02-06 17:43:50 +00001060 if (sw->forced) {
1061 DEBUGP(DNM, "FORCED: Ignoring Software Load"
1062 "End NACK\n");
1063 sw->state = SW_STATE_NONE;
1064 if (sw->cbfn)
1065 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1066 NM_MT_LOAD_END_ACK, mb,
1067 sw->cb_data, NULL);
1068 } else {
1069 DEBUGP(DNM, "Software Load End NACK\n");
1070 sw->state = SW_STATE_ERROR;
1071 if (sw->cbfn)
1072 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1073 NM_MT_LOAD_END_NACK, mb,
1074 sw->cb_data, NULL);
1075 }
Harald Welte4724f992009-01-18 18:01:49 +00001076 break;
1077 }
1078 case SW_STATE_WAIT_ACTACK:
1079 switch (foh->msg_type) {
1080 case NM_MT_ACTIVATE_SW_ACK:
1081 /* we're done */
Harald Welte5e4d1b32009-02-01 13:36:56 +00001082 DEBUGP(DNM, "Activate Software DONE!\n");
Harald Welte4724f992009-01-18 18:01:49 +00001083 sw->state = SW_STATE_NONE;
1084 rc = 0;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001085 if (sw->cbfn)
1086 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1087 NM_MT_ACTIVATE_SW_ACK, mb,
1088 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001089 break;
1090 case NM_MT_ACTIVATE_SW_NACK:
Harald Welte1602ade2009-01-29 21:12:39 +00001091 DEBUGP(DNM, "Activate Software NACK\n");
Harald Welte4724f992009-01-18 18:01:49 +00001092 sw->state = SW_STATE_ERROR;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001093 if (sw->cbfn)
1094 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1095 NM_MT_ACTIVATE_SW_NACK, mb,
1096 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001097 break;
1098 }
1099 case SW_STATE_NONE:
1100 case SW_STATE_ERROR:
1101 break;
1102 }
1103
1104 if (rc)
1105 fprintf(stderr, "unexpected NM MT 0x%02x in state %u -> %u\n",
1106 foh->msg_type, old_state, sw->state);
1107
1108 return rc;
1109}
1110
1111/* Load the specified software into the BTS */
1112int abis_nm_software_load(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00001113 u_int8_t win_size, int forced,
1114 gsm_cbfn *cbfn, void *cb_data)
Harald Welte4724f992009-01-18 18:01:49 +00001115{
1116 struct abis_nm_sw *sw = &g_sw;
1117 int rc;
1118
Harald Welte5e4d1b32009-02-01 13:36:56 +00001119 DEBUGP(DNM, "Software Load (BTS %u, File \"%s\")\n",
1120 bts->nr, fname);
1121
Harald Welte4724f992009-01-18 18:01:49 +00001122 if (sw->state != SW_STATE_NONE)
1123 return -EBUSY;
1124
1125 sw->bts = bts;
1126 sw->obj_class = NM_OC_SITE_MANAGER;
1127 sw->obj_instance[0] = 0xff;
1128 sw->obj_instance[1] = 0xff;
1129 sw->obj_instance[2] = 0xff;
1130 sw->window_size = win_size;
1131 sw->state = SW_STATE_WAIT_INITACK;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001132 sw->cbfn = cbfn;
1133 sw->cb_data = cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +00001134 sw->forced = forced;
Harald Welte4724f992009-01-18 18:01:49 +00001135
1136 rc = sw_open_file(sw, fname);
1137 if (rc < 0) {
1138 sw->state = SW_STATE_NONE;
1139 return rc;
1140 }
1141
1142 return sw_load_init(sw);
1143}
Harald Welte52b1f982008-12-23 20:25:15 +00001144
Harald Welte1602ade2009-01-29 21:12:39 +00001145int abis_nm_software_load_status(struct gsm_bts *bts)
1146{
1147 struct abis_nm_sw *sw = &g_sw;
1148 struct stat st;
1149 int rc, percent;
1150
1151 rc = fstat(sw->fd, &st);
1152 if (rc < 0) {
1153 perror("ERROR during stat");
1154 return rc;
1155 }
1156
1157 percent = (ftell(sw->stream) * 100) / st.st_size;
1158 return percent;
1159}
1160
Harald Welte5e4d1b32009-02-01 13:36:56 +00001161/* Activate the specified software into the BTS */
1162int abis_nm_software_activate(struct gsm_bts *bts, const char *fname,
1163 gsm_cbfn *cbfn, void *cb_data)
1164{
1165 struct abis_nm_sw *sw = &g_sw;
1166 int rc;
1167
1168 DEBUGP(DNM, "Activating Software (BTS %u, File \"%s\")\n",
1169 bts->nr, fname);
1170
1171 if (sw->state != SW_STATE_NONE)
1172 return -EBUSY;
1173
1174 sw->bts = bts;
1175 sw->obj_class = NM_OC_SITE_MANAGER;
1176 sw->obj_instance[0] = 0xff;
1177 sw->obj_instance[1] = 0xff;
1178 sw->obj_instance[2] = 0xff;
1179 sw->state = SW_STATE_WAIT_ACTACK;
1180 sw->cbfn = cbfn;
1181 sw->cb_data = cb_data;
1182
1183 /* Open the file in order to fill some sw struct members */
1184 rc = sw_open_file(sw, fname);
1185 if (rc < 0) {
1186 sw->state = SW_STATE_NONE;
1187 return rc;
1188 }
1189 sw_close_file(sw);
1190
1191 return sw_activate(sw);
1192}
1193
Harald Welte8470bf22008-12-25 23:28:35 +00001194static void fill_nm_channel(struct abis_nm_channel *ch, u_int8_t bts_port,
Harald Welte52b1f982008-12-23 20:25:15 +00001195 u_int8_t ts_nr, u_int8_t subslot_nr)
1196{
Harald Welteadaf08b2009-01-18 11:08:10 +00001197 ch->attrib = NM_ATT_ABIS_CHANNEL;
Harald Welte52b1f982008-12-23 20:25:15 +00001198 ch->bts_port = bts_port;
1199 ch->timeslot = ts_nr;
1200 ch->subslot = subslot_nr;
1201}
1202
1203int abis_nm_establish_tei(struct gsm_bts *bts, u_int8_t trx_nr,
1204 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot,
1205 u_int8_t tei)
1206{
1207 struct abis_om_hdr *oh;
1208 struct abis_nm_channel *ch;
Harald Welte702d8702008-12-26 20:25:35 +00001209 u_int8_t len = sizeof(*ch) + 2;
Harald Welte8470bf22008-12-25 23:28:35 +00001210 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001211
1212 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1213 fill_om_fom_hdr(oh, len, NM_MT_ESTABLISH_TEI, NM_OC_RADIO_CARRIER,
1214 bts->bts_nr, trx_nr, 0xff);
1215
Harald Welte8470bf22008-12-25 23:28:35 +00001216 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte52b1f982008-12-23 20:25:15 +00001217
1218 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1219 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1220
1221 return abis_nm_sendmsg(bts, msg);
1222}
1223
1224/* connect signalling of one (BTS,TRX) to a particular timeslot on the E1 */
1225int abis_nm_conn_terr_sign(struct gsm_bts_trx *trx,
1226 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot)
1227{
Harald Welte8470bf22008-12-25 23:28:35 +00001228 struct gsm_bts *bts = trx->bts;
Harald Welte52b1f982008-12-23 20:25:15 +00001229 struct abis_om_hdr *oh;
1230 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +00001231 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001232
1233 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001234 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_SIGN,
Harald Welte52b1f982008-12-23 20:25:15 +00001235 NM_OC_RADIO_CARRIER, bts->bts_nr, trx->nr, 0xff);
1236
1237 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1238 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1239
1240 return abis_nm_sendmsg(bts, msg);
1241}
1242
1243#if 0
1244int abis_nm_disc_terr_sign(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1245 struct abis_nm_abis_channel *chan)
1246{
1247}
1248#endif
1249
1250int abis_nm_conn_terr_traf(struct gsm_bts_trx_ts *ts,
1251 u_int8_t e1_port, u_int8_t e1_timeslot,
1252 u_int8_t e1_subslot)
1253{
1254 struct gsm_bts *bts = ts->trx->bts;
1255 struct abis_om_hdr *oh;
1256 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +00001257 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001258
1259 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1260 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_TRAF,
Harald Welteb110cee2009-02-18 03:42:35 +00001261 NM_OC_CHANNEL, bts->bts_nr, ts->trx->nr, ts->nr);
Harald Welte52b1f982008-12-23 20:25:15 +00001262
1263 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1264 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1265
Harald Welteb110cee2009-02-18 03:42:35 +00001266 DEBUGP(DNM, "CONNECT TERR TRAF Um=(%u,%u,%u) E1=(%u,%u,%u)\n",
1267 bts->bts_nr, ts->trx->nr, ts->nr,
1268 e1_port, e1_timeslot, e1_subslot);
1269
Harald Welte52b1f982008-12-23 20:25:15 +00001270 return abis_nm_sendmsg(bts, msg);
1271}
1272
1273#if 0
1274int abis_nm_disc_terr_traf(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1275 struct abis_nm_abis_channel *chan,
1276 u_int8_t subchan)
1277{
1278}
1279#endif
1280
Harald Welte22af0db2009-02-14 15:41:08 +00001281/* Chapter 8.6.1 */
1282int abis_nm_set_bts_attr(struct gsm_bts *bts, u_int8_t *attr, int attr_len)
1283{
1284 struct abis_om_hdr *oh;
1285 struct msgb *msg = nm_msgb_alloc();
1286 u_int8_t *cur;
1287
1288 DEBUGP(DNM, "Set BTS Attr (bts=%d)\n", bts->nr);
1289
1290 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1291 fill_om_fom_hdr(oh, attr_len, NM_MT_SET_BTS_ATTR, NM_OC_BTS, bts->nr, 0xff, 0xff);
1292 cur = msgb_put(msg, attr_len);
1293 memcpy(cur, attr, attr_len);
1294
1295 return abis_nm_sendmsg(bts, msg);
1296}
1297
1298/* Chapter 8.6.2 */
1299int abis_nm_set_radio_attr(struct gsm_bts_trx *trx, u_int8_t *attr, int attr_len)
1300{
1301 struct abis_om_hdr *oh;
1302 struct msgb *msg = nm_msgb_alloc();
1303 u_int8_t *cur;
1304
1305 DEBUGP(DNM, "Set TRX Attr (bts=%d,trx=%d)\n", trx->bts->nr, trx->nr);
1306
1307 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1308 fill_om_fom_hdr(oh, attr_len, NM_MT_SET_RADIO_ATTR, NM_OC_RADIO_CARRIER,
1309 trx->bts->nr, trx->nr, 0xff);
1310 cur = msgb_put(msg, attr_len);
1311 memcpy(cur, attr, attr_len);
1312
1313 return abis_nm_sendmsg(trx->bts, msg);
1314}
1315
1316/* Chapter 8.6.3 */
Harald Welte52b1f982008-12-23 20:25:15 +00001317int abis_nm_set_channel_attr(struct gsm_bts_trx_ts *ts, u_int8_t chan_comb)
1318{
1319 struct gsm_bts *bts = ts->trx->bts;
1320 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001321 u_int16_t arfcn = htons(ts->trx->arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001322 u_int8_t zero = 0x00;
Harald Welte8470bf22008-12-25 23:28:35 +00001323 struct msgb *msg = nm_msgb_alloc();
Harald Weltee0590df2009-02-15 03:34:15 +00001324 u_int8_t len = 2 + 2;
1325
1326 if (bts->type == GSM_BTS_TYPE_BS11)
1327 len += 4 + 2 + 2 + 3;
Harald Welte52b1f982008-12-23 20:25:15 +00001328
Harald Welte22af0db2009-02-14 15:41:08 +00001329 DEBUGP(DNM, "Set Chan Attr (bts=%d,trx=%d,ts=%d)\n", bts->nr, ts->trx->nr, ts->nr);
1330
Harald Welte52b1f982008-12-23 20:25:15 +00001331 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001332 fill_om_fom_hdr(oh, len, NM_MT_SET_CHAN_ATTR,
Holger Freyther6b2d2622009-02-14 23:16:59 +00001333 NM_OC_CHANNEL, bts->bts_nr,
Harald Welte52b1f982008-12-23 20:25:15 +00001334 ts->trx->nr, ts->nr);
1335 /* FIXME: don't send ARFCN list, hopping sequence, mAIO, ...*/
Harald Weltee0590df2009-02-15 03:34:15 +00001336 if (bts->type == GSM_BTS_TYPE_BS11)
1337 msgb_tlv16_put(msg, NM_ATT_ARFCN_LIST, 1, &arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001338 msgb_tv_put(msg, NM_ATT_CHAN_COMB, chan_comb);
Harald Weltee0590df2009-02-15 03:34:15 +00001339 if (bts->type == GSM_BTS_TYPE_BS11) {
1340 msgb_tv_put(msg, NM_ATT_HSN, 0x00);
1341 msgb_tv_put(msg, NM_ATT_MAIO, 0x00);
1342 }
Harald Welte52b1f982008-12-23 20:25:15 +00001343 msgb_tv_put(msg, NM_ATT_TSC, 0x07); /* training sequence */
Harald Weltee0590df2009-02-15 03:34:15 +00001344 if (bts->type == GSM_BTS_TYPE_BS11)
1345 msgb_tlv_put(msg, 0x59, 1, &zero);
Harald Welte52b1f982008-12-23 20:25:15 +00001346
1347 return abis_nm_sendmsg(bts, msg);
1348}
1349
Harald Welte34a99682009-02-13 02:41:40 +00001350int 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 +00001351 u_int8_t i2, u_int8_t i3, int nack, u_int8_t *attr, int att_len)
Harald Welte34a99682009-02-13 02:41:40 +00001352{
1353 struct abis_om_hdr *oh;
1354 struct msgb *msg = nm_msgb_alloc();
Harald Welte5c1e4582009-02-15 11:57:29 +00001355 u_int8_t msgtype = NM_MT_SW_ACT_REQ_ACK;
1356 u_int8_t len = att_len;
1357
1358 if (nack) {
1359 len += 2;
1360 msgtype = NM_MT_SW_ACT_REQ_NACK;
1361 }
Harald Welte34a99682009-02-13 02:41:40 +00001362
1363 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte5c1e4582009-02-15 11:57:29 +00001364 fill_om_fom_hdr(oh, att_len, msgtype, obj_class, i1, i2, i3);
1365
Harald Welte34a99682009-02-13 02:41:40 +00001366 if (attr) {
1367 u_int8_t *ptr = msgb_put(msg, att_len);
1368 memcpy(ptr, attr, att_len);
1369 }
Harald Welte5c1e4582009-02-15 11:57:29 +00001370 if (nack)
1371 msgb_tv_put(msg, NM_ATT_NACK_CAUSES, NM_NACK_OBJCLASS_NOTSUPP);
Harald Welte34a99682009-02-13 02:41:40 +00001372
1373 return abis_nm_sendmsg(bts, msg);
1374}
1375
Harald Welte8470bf22008-12-25 23:28:35 +00001376int abis_nm_raw_msg(struct gsm_bts *bts, int len, u_int8_t *rawmsg)
Harald Welte52b1f982008-12-23 20:25:15 +00001377{
Harald Welte8470bf22008-12-25 23:28:35 +00001378 struct msgb *msg = nm_msgb_alloc();
1379 struct abis_om_hdr *oh;
Harald Welte52b1f982008-12-23 20:25:15 +00001380 u_int8_t *data;
1381
1382 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
1383 fill_om_hdr(oh, len);
1384 data = msgb_put(msg, len);
Harald Weltead384642008-12-26 10:20:07 +00001385 memcpy(data, rawmsg, len);
Harald Welte52b1f982008-12-23 20:25:15 +00001386
1387 return abis_nm_sendmsg(bts, msg);
1388}
1389
1390/* Siemens specific commands */
1391static int __simple_cmd(struct gsm_bts *bts, u_int8_t msg_type)
1392{
1393 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001394 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001395
1396 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001397 fill_om_fom_hdr(oh, 0, msg_type, NM_OC_SITE_MANAGER,
Harald Welte52b1f982008-12-23 20:25:15 +00001398 0xff, 0xff, 0xff);
1399
1400 return abis_nm_sendmsg(bts, msg);
1401}
1402
Harald Welte34a99682009-02-13 02:41:40 +00001403/* Chapter 8.9.2 */
1404int abis_nm_opstart(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1, u_int8_t i2)
1405{
1406 struct abis_om_hdr *oh;
1407 struct msgb *msg = nm_msgb_alloc();
1408
Harald Welte22af0db2009-02-14 15:41:08 +00001409 DEBUGP(DNM, "Sending OPSTART obj_class=0x%02x obj_inst=(0x%02x, 0x%02x, 0x%02x)\n",
1410 obj_class, i0, i1, i2);
Harald Welte34a99682009-02-13 02:41:40 +00001411 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1412 fill_om_fom_hdr(oh, 0, NM_MT_OPSTART, obj_class, i0, i1, i2);
1413
1414 return abis_nm_sendmsg(bts, msg);
1415}
1416
1417/* Chapter 8.8.5 */
1418int abis_nm_chg_adm_state(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0,
1419 u_int8_t i1, u_int8_t i2, u_int8_t adm_state)
1420{
1421 struct abis_om_hdr *oh;
1422 struct msgb *msg = nm_msgb_alloc();
1423
1424 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1425 fill_om_fom_hdr(oh, 2, NM_MT_CHG_ADM_STATE, obj_class, i0, i1, i2);
1426 msgb_tv_put(msg, NM_ATT_ADM_STATE, adm_state);
1427
1428 return abis_nm_sendmsg(bts, msg);
1429}
1430
1431
Harald Welte52b1f982008-12-23 20:25:15 +00001432int abis_nm_event_reports(struct gsm_bts *bts, int on)
1433{
1434 if (on == 0)
Harald Welte227d4072009-01-03 08:16:25 +00001435 return __simple_cmd(bts, NM_MT_STOP_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001436 else
Harald Welte227d4072009-01-03 08:16:25 +00001437 return __simple_cmd(bts, NM_MT_REST_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001438}
1439
Harald Welte47d88ae2009-01-04 12:02:08 +00001440/* Siemens (or BS-11) specific commands */
1441
Harald Welte3ffd1372009-02-01 22:15:49 +00001442int abis_nm_bs11_bsc_disconnect(struct gsm_bts *bts, int reconnect)
1443{
1444 if (reconnect == 0)
1445 return __simple_cmd(bts, NM_MT_BS11_DISCONNECT);
1446 else
1447 return __simple_cmd(bts, NM_MT_BS11_RECONNECT);
1448}
1449
Harald Welteb8427972009-02-05 19:27:17 +00001450int abis_nm_bs11_restart(struct gsm_bts *bts)
1451{
1452 return __simple_cmd(bts, NM_MT_BS11_RESTART);
1453}
1454
1455
Harald Welte268bb402009-02-01 19:11:56 +00001456struct bs11_date_time {
1457 u_int16_t year;
1458 u_int8_t month;
1459 u_int8_t day;
1460 u_int8_t hour;
1461 u_int8_t min;
1462 u_int8_t sec;
1463} __attribute__((packed));
1464
1465
1466void get_bs11_date_time(struct bs11_date_time *aet)
1467{
1468 time_t t;
1469 struct tm *tm;
1470
1471 t = time(NULL);
1472 tm = localtime(&t);
1473 aet->sec = tm->tm_sec;
1474 aet->min = tm->tm_min;
1475 aet->hour = tm->tm_hour;
1476 aet->day = tm->tm_mday;
1477 aet->month = tm->tm_mon;
1478 aet->year = htons(1900 + tm->tm_year);
1479}
1480
Harald Welte05188ee2009-01-18 11:39:08 +00001481int abis_nm_bs11_reset_resource(struct gsm_bts *bts)
Harald Welte52b1f982008-12-23 20:25:15 +00001482{
Harald Welte4668fda2009-01-03 08:19:29 +00001483 return __simple_cmd(bts, NM_MT_BS11_RESET_RESOURCE);
Harald Welte52b1f982008-12-23 20:25:15 +00001484}
1485
Harald Welte05188ee2009-01-18 11:39:08 +00001486int abis_nm_bs11_db_transmission(struct gsm_bts *bts, int begin)
Harald Welte52b1f982008-12-23 20:25:15 +00001487{
1488 if (begin)
Harald Welte4668fda2009-01-03 08:19:29 +00001489 return __simple_cmd(bts, NM_MT_BS11_BEGIN_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00001490 else
Harald Welte4668fda2009-01-03 08:19:29 +00001491 return __simple_cmd(bts, NM_MT_BS11_END_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00001492}
Harald Welte47d88ae2009-01-04 12:02:08 +00001493
Harald Welte05188ee2009-01-18 11:39:08 +00001494int abis_nm_bs11_create_object(struct gsm_bts *bts,
Harald Welte1bc09062009-01-18 14:17:52 +00001495 enum abis_bs11_objtype type, u_int8_t idx,
1496 u_int8_t attr_len, const u_int8_t *attr)
Harald Welte47d88ae2009-01-04 12:02:08 +00001497{
1498 struct abis_om_hdr *oh;
1499 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00001500 u_int8_t *cur;
Harald Welte47d88ae2009-01-04 12:02:08 +00001501
1502 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001503 fill_om_fom_hdr(oh, attr_len, NM_MT_BS11_CREATE_OBJ,
Harald Welte268bb402009-02-01 19:11:56 +00001504 NM_OC_BS11, type, 0, idx);
Harald Welte1bc09062009-01-18 14:17:52 +00001505 cur = msgb_put(msg, attr_len);
1506 memcpy(cur, attr, attr_len);
Harald Welte47d88ae2009-01-04 12:02:08 +00001507
1508 return abis_nm_sendmsg(bts, msg);
1509}
1510
Harald Welte05188ee2009-01-18 11:39:08 +00001511int abis_nm_bs11_create_envaBTSE(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00001512{
1513 struct abis_om_hdr *oh;
1514 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00001515 u_int8_t zero = 0x00;
Harald Welte47d88ae2009-01-04 12:02:08 +00001516
1517 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001518 fill_om_fom_hdr(oh, 3, NM_MT_BS11_CREATE_OBJ,
Harald Welte1bc09062009-01-18 14:17:52 +00001519 NM_OC_BS11_ENVABTSE, 0, idx, 0xff);
1520 msgb_tlv_put(msg, 0x99, 1, &zero);
Harald Welte47d88ae2009-01-04 12:02:08 +00001521
1522 return abis_nm_sendmsg(bts, msg);
1523}
1524
Harald Welte05188ee2009-01-18 11:39:08 +00001525int abis_nm_bs11_create_bport(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00001526{
1527 struct abis_om_hdr *oh;
1528 struct msgb *msg = nm_msgb_alloc();
1529
1530 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1531 fill_om_fom_hdr(oh, 0, NM_MT_BS11_CREATE_OBJ, NM_OC_BS11_BPORT,
1532 idx, 0, 0);
1533
1534 return abis_nm_sendmsg(bts, msg);
1535}
Harald Welte05188ee2009-01-18 11:39:08 +00001536
1537int abis_nm_bs11_set_oml_tei(struct gsm_bts *bts, u_int8_t tei)
1538{
1539 struct abis_om_hdr *oh;
1540 struct msgb *msg = nm_msgb_alloc();
Harald Welte05188ee2009-01-18 11:39:08 +00001541
1542 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001543 fill_om_fom_hdr(oh, 2, NM_MT_BS11_SET_ATTR, NM_OC_SITE_MANAGER,
Harald Welte05188ee2009-01-18 11:39:08 +00001544 0xff, 0xff, 0xff);
1545 msgb_tv_put(msg, NM_ATT_TEI, tei);
1546
1547 return abis_nm_sendmsg(bts, msg);
1548}
1549
1550/* like abis_nm_conn_terr_traf */
1551int abis_nm_bs11_conn_oml(struct gsm_bts *bts, u_int8_t e1_port,
1552 u_int8_t e1_timeslot, u_int8_t e1_subslot)
1553{
1554 struct abis_om_hdr *oh;
1555 struct abis_nm_channel *ch;
1556 struct msgb *msg = nm_msgb_alloc();
1557
1558 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte05188ee2009-01-18 11:39:08 +00001559 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_BS11_SET_ATTR,
1560 NM_OC_SITE_MANAGER, 0xff, 0xff, 0xff);
1561
1562 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1563 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1564
1565 return abis_nm_sendmsg(bts, msg);
1566}
1567
1568int abis_nm_bs11_set_trx_power(struct gsm_bts_trx *trx, u_int8_t level)
1569{
1570 struct abis_om_hdr *oh;
1571 struct msgb *msg = nm_msgb_alloc();
Harald Welte05188ee2009-01-18 11:39:08 +00001572
1573 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001574 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR,
Harald Welte05188ee2009-01-18 11:39:08 +00001575 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
1576 msgb_tlv_put(msg, NM_ATT_BS11_TXPWR, 1, &level);
1577
1578 return abis_nm_sendmsg(trx->bts, msg);
1579}
1580
Harald Welte268bb402009-02-01 19:11:56 +00001581//static const u_int8_t bs11_logon_c7[] = { 0x07, 0xd9, 0x01, 0x11, 0x0d, 0x10, 0x20 };
Harald Weltebb151312009-01-28 20:42:07 +00001582static const u_int8_t bs11_logon_c8[] = { 0x02 };
Harald Welte05188ee2009-01-18 11:39:08 +00001583static const u_int8_t bs11_logon_c9[] = "FACTORY";
1584
Harald Welte1bc09062009-01-18 14:17:52 +00001585int abis_nm_bs11_factory_logon(struct gsm_bts *bts, int on)
Harald Welte05188ee2009-01-18 11:39:08 +00001586{
1587 struct abis_om_hdr *oh;
1588 struct msgb *msg = nm_msgb_alloc();
Harald Welte268bb402009-02-01 19:11:56 +00001589 struct bs11_date_time bdt;
1590
1591 get_bs11_date_time(&bdt);
Harald Welte05188ee2009-01-18 11:39:08 +00001592
1593 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte1bc09062009-01-18 14:17:52 +00001594 if (on) {
Harald Welte268bb402009-02-01 19:11:56 +00001595 u_int8_t len = 3*2 + sizeof(bdt)
Harald Welte6f676a32009-01-18 14:27:48 +00001596 + sizeof(bs11_logon_c8) + sizeof(bs11_logon_c9);
Harald Welte043d04a2009-01-29 23:15:30 +00001597 fill_om_fom_hdr(oh, len, NM_MT_BS11_LMT_LOGON,
Harald Welte1bc09062009-01-18 14:17:52 +00001598 NM_OC_BS11_A3, 0xff, 0xff, 0xff);
Harald Welte043d04a2009-01-29 23:15:30 +00001599 msgb_tlv_put(msg, NM_ATT_BS11_LMT_LOGIN_TIME,
Harald Welte5083b0b2009-02-02 19:20:52 +00001600 sizeof(bdt), (u_int8_t *) &bdt);
Harald Welte043d04a2009-01-29 23:15:30 +00001601 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_ACC_LEV,
1602 sizeof(bs11_logon_c8), bs11_logon_c8);
1603 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_NAME,
1604 sizeof(bs11_logon_c9), bs11_logon_c9);
Harald Welte1bc09062009-01-18 14:17:52 +00001605 } else {
Harald Welte5e4d1b32009-02-01 13:36:56 +00001606 fill_om_fom_hdr(oh, 0, NM_MT_BS11_LMT_LOGOFF,
Harald Welte1bc09062009-01-18 14:17:52 +00001607 NM_OC_BS11_A3, 0xff, 0xff, 0xff);
1608 }
Harald Welte05188ee2009-01-18 11:39:08 +00001609
1610 return abis_nm_sendmsg(bts, msg);
1611}
Harald Welte1bc09062009-01-18 14:17:52 +00001612
1613int abis_nm_bs11_set_trx1_pw(struct gsm_bts *bts, const char *password)
1614{
1615 struct abis_om_hdr *oh;
1616 struct msgb *msg;
1617
1618 if (strlen(password) != 10)
1619 return -EINVAL;
1620
1621 msg = nm_msgb_alloc();
1622 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001623 fill_om_fom_hdr(oh, 2+strlen(password), NM_MT_BS11_SET_ATTR,
Harald Welte1bc09062009-01-18 14:17:52 +00001624 NM_OC_BS11, BS11_OBJ_TRX1, 0x00, 0x00);
1625 msgb_tlv_put(msg, NM_ATT_BS11_PASSWORD, 10, (const u_int8_t *)password);
1626
1627 return abis_nm_sendmsg(bts, msg);
1628}
1629
1630int abis_nm_bs11_get_state(struct gsm_bts *bts)
1631{
1632 return __simple_cmd(bts, NM_MT_BS11_GET_STATE);
1633}
Harald Welte5e4d1b32009-02-01 13:36:56 +00001634
1635/* BS11 SWL */
1636
1637struct abis_nm_bs11_sw {
1638 struct gsm_bts *bts;
1639 char swl_fname[PATH_MAX];
1640 u_int8_t win_size;
Harald Welte3ffd1372009-02-01 22:15:49 +00001641 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001642 struct llist_head file_list;
1643 gsm_cbfn *user_cb; /* specified by the user */
1644};
1645static struct abis_nm_bs11_sw _g_bs11_sw, *g_bs11_sw = &_g_bs11_sw;
1646
1647struct file_list_entry {
1648 struct llist_head list;
1649 char fname[PATH_MAX];
1650};
1651
1652struct file_list_entry *fl_dequeue(struct llist_head *queue)
1653{
1654 struct llist_head *lh;
1655
1656 if (llist_empty(queue))
1657 return NULL;
1658
1659 lh = queue->next;
1660 llist_del(lh);
1661
1662 return llist_entry(lh, struct file_list_entry, list);
1663}
1664
1665static int bs11_read_swl_file(struct abis_nm_bs11_sw *bs11_sw)
1666{
1667 char linebuf[255];
1668 struct llist_head *lh, *lh2;
1669 FILE *swl;
1670 int rc = 0;
1671
1672 swl = fopen(bs11_sw->swl_fname, "r");
1673 if (!swl)
1674 return -ENODEV;
1675
1676 /* zero the stale file list, if any */
1677 llist_for_each_safe(lh, lh2, &bs11_sw->file_list) {
1678 llist_del(lh);
1679 free(lh);
1680 }
1681
1682 while (fgets(linebuf, sizeof(linebuf), swl)) {
1683 char file_id[12+1];
1684 char file_version[80+1];
1685 struct file_list_entry *fle;
1686 static char dir[PATH_MAX];
1687
1688 if (strlen(linebuf) < 4)
1689 continue;
Harald Welte3ffd1372009-02-01 22:15:49 +00001690
Harald Welte5e4d1b32009-02-01 13:36:56 +00001691 rc = sscanf(linebuf+4, "%12s:%80s\r\n", file_id, file_version);
1692 if (rc < 0) {
1693 perror("ERR parsing SWL file");
1694 rc = -EINVAL;
1695 goto out;
1696 }
1697 if (rc < 2)
1698 continue;
1699
1700 fle = malloc(sizeof(*fle));
1701 if (!fle) {
1702 rc = -ENOMEM;
1703 goto out;
1704 }
1705 memset(fle, 0, sizeof(*fle));
1706
1707 /* construct new filename */
1708 strncpy(dir, bs11_sw->swl_fname, sizeof(dir));
1709 strncat(fle->fname, dirname(dir), sizeof(fle->fname) - 1);
1710 strcat(fle->fname, "/");
1711 strncat(fle->fname, file_id, sizeof(fle->fname) - 1 -strlen(fle->fname));
Harald Welte5e4d1b32009-02-01 13:36:56 +00001712
1713 llist_add_tail(&fle->list, &bs11_sw->file_list);
1714 }
1715
1716out:
1717 fclose(swl);
1718 return rc;
1719}
1720
1721/* bs11 swload specific callback, passed to abis_nm core swload */
1722static int bs11_swload_cbfn(unsigned int hook, unsigned int event,
1723 struct msgb *msg, void *data, void *param)
1724{
1725 struct abis_nm_bs11_sw *bs11_sw = data;
1726 struct file_list_entry *fle;
1727 int rc = 0;
1728
Harald Welte5e4d1b32009-02-01 13:36:56 +00001729 switch (event) {
1730 case NM_MT_LOAD_END_ACK:
1731 fle = fl_dequeue(&bs11_sw->file_list);
1732 if (fle) {
1733 /* start download the next file of our file list */
1734 rc = abis_nm_software_load(bs11_sw->bts, fle->fname,
1735 bs11_sw->win_size,
Harald Welte3ffd1372009-02-01 22:15:49 +00001736 bs11_sw->forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00001737 &bs11_swload_cbfn, bs11_sw);
1738 free(fle);
1739 } else {
1740 /* activate the SWL */
1741 rc = abis_nm_software_activate(bs11_sw->bts,
1742 bs11_sw->swl_fname,
1743 bs11_swload_cbfn,
1744 bs11_sw);
1745 }
1746 break;
Harald Welte3ffd1372009-02-01 22:15:49 +00001747 case NM_MT_LOAD_SEG_ACK:
Harald Welte5e4d1b32009-02-01 13:36:56 +00001748 case NM_MT_LOAD_END_NACK:
1749 case NM_MT_LOAD_INIT_ACK:
1750 case NM_MT_LOAD_INIT_NACK:
1751 case NM_MT_ACTIVATE_SW_NACK:
1752 case NM_MT_ACTIVATE_SW_ACK:
1753 default:
1754 /* fallthrough to the user callback */
Harald Welte97ed1e72009-02-06 13:38:02 +00001755 if (bs11_sw->user_cb)
1756 rc = bs11_sw->user_cb(hook, event, msg, NULL, NULL);
Harald Welte5e4d1b32009-02-01 13:36:56 +00001757 break;
1758 }
1759
1760 return rc;
1761}
1762
1763/* Siemens provides a SWL file that is a mere listing of all the other
1764 * files that are part of a software release. We need to upload first
1765 * the list file, and then each file that is listed in the list file */
1766int abis_nm_bs11_load_swl(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00001767 u_int8_t win_size, int forced, gsm_cbfn *cbfn)
Harald Welte5e4d1b32009-02-01 13:36:56 +00001768{
1769 struct abis_nm_bs11_sw *bs11_sw = g_bs11_sw;
1770 struct file_list_entry *fle;
1771 int rc = 0;
1772
1773 INIT_LLIST_HEAD(&bs11_sw->file_list);
1774 bs11_sw->bts = bts;
1775 bs11_sw->win_size = win_size;
1776 bs11_sw->user_cb = cbfn;
Harald Welte3ffd1372009-02-01 22:15:49 +00001777 bs11_sw->forced = forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001778
1779 strncpy(bs11_sw->swl_fname, fname, sizeof(bs11_sw->swl_fname));
1780 rc = bs11_read_swl_file(bs11_sw);
1781 if (rc < 0)
1782 return rc;
1783
1784 /* dequeue next item in file list */
1785 fle = fl_dequeue(&bs11_sw->file_list);
1786 if (!fle)
1787 return -EINVAL;
1788
1789 /* start download the next file of our file list */
Harald Welte3ffd1372009-02-01 22:15:49 +00001790 rc = abis_nm_software_load(bts, fle->fname, win_size, forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00001791 bs11_swload_cbfn, bs11_sw);
1792 free(fle);
1793 return rc;
1794}
1795
Harald Welte5083b0b2009-02-02 19:20:52 +00001796#if 0
Harald Welte5e4d1b32009-02-01 13:36:56 +00001797static u_int8_t req_attr_btse[] = {
1798 NM_ATT_ADM_STATE, NM_ATT_BS11_LMT_LOGON_SESSION,
1799 NM_ATT_BS11_LMT_LOGIN_TIME, NM_ATT_BS11_LMT_USER_ACC_LEV,
1800 NM_ATT_BS11_LMT_USER_NAME,
1801
1802 0xaf, NM_ATT_BS11_RX_OFFSET, NM_ATT_BS11_VENDOR_NAME,
1803
1804 NM_ATT_BS11_SW_LOAD_INTENDED, NM_ATT_BS11_SW_LOAD_SAFETY,
1805
1806 NM_ATT_BS11_SW_LOAD_STORED };
1807
1808static u_int8_t req_attr_btsm[] = {
1809 NM_ATT_ABIS_CHANNEL, NM_ATT_TEI, NM_ATT_BS11_ABIS_EXT_TIME,
1810 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xce, NM_ATT_FILE_ID,
1811 NM_ATT_FILE_VERSION, NM_ATT_OPER_STATE, 0xe8, NM_ATT_BS11_ALL_TEST_CATG,
1812 NM_ATT_SW_DESCR, NM_ATT_GET_ARI };
Harald Welte5083b0b2009-02-02 19:20:52 +00001813#endif
Harald Welte5e4d1b32009-02-01 13:36:56 +00001814
1815static u_int8_t req_attr[] = {
1816 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xa8, NM_ATT_OPER_STATE,
1817 0xd5, 0xa1, NM_ATT_BS11_ESN_FW_CODE_NO, NM_ATT_BS11_ESN_HW_CODE_NO,
1818 0x42, NM_ATT_BS11_ESN_PCB_SERIAL };
1819
1820int abis_nm_bs11_get_serno(struct gsm_bts *bts)
1821{
1822 struct abis_om_hdr *oh;
1823 struct msgb *msg = nm_msgb_alloc();
1824
1825 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1826 /* SiemensHW CCTRL object */
1827 fill_om_fom_hdr(oh, 2+sizeof(req_attr), NM_MT_GET_ATTR, NM_OC_BS11,
1828 0x03, 0x00, 0x00);
1829 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(req_attr), req_attr);
1830
1831 return abis_nm_sendmsg(bts, msg);
1832}
Harald Welte268bb402009-02-01 19:11:56 +00001833
1834int abis_nm_bs11_set_ext_time(struct gsm_bts *bts)
1835{
1836 struct abis_om_hdr *oh;
1837 struct msgb *msg = nm_msgb_alloc();
1838 struct bs11_date_time aet;
1839
1840 get_bs11_date_time(&aet);
1841 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1842 /* SiemensHW CCTRL object */
1843 fill_om_fom_hdr(oh, 2+sizeof(aet), NM_MT_BS11_SET_ATTR, NM_OC_SITE_MANAGER,
1844 0xff, 0xff, 0xff);
Harald Welte5083b0b2009-02-02 19:20:52 +00001845 msgb_tlv_put(msg, NM_ATT_BS11_ABIS_EXT_TIME, sizeof(aet), (u_int8_t *) &aet);
Harald Welte268bb402009-02-01 19:11:56 +00001846
1847 return abis_nm_sendmsg(bts, msg);
1848}
Harald Welte5c1e4582009-02-15 11:57:29 +00001849
1850/* ip.access nanoBTS specific commands */
Harald Welte5c1e4582009-02-15 11:57:29 +00001851static const char ipaccess_magic[] = "com.ipaccess";
1852
Harald Welte677c21f2009-02-17 13:22:23 +00001853
1854static int abis_nm_rx_ipacc(struct msgb *msg)
1855{
1856 struct abis_om_hdr *oh = msgb_l2(msg);
1857 struct abis_om_fom_hdr *foh;
1858 u_int8_t idstrlen = oh->data[0];
1859 struct tlv_parsed tp;
1860
1861 if (strncmp((char *)&oh->data[1], ipaccess_magic, idstrlen)) {
1862 DEBUGP(DNM, "id string is not com.ipaccess !?!\n");
1863 return -EINVAL;
1864 }
1865
1866 foh = (struct abis_om_fom_hdr *) oh->data + 1 + idstrlen;
Harald Welte03133942009-02-18 19:51:53 +00001867 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Welte677c21f2009-02-17 13:22:23 +00001868
1869 switch (foh->msg_type) {
1870 case NM_MT_IPACC_RSL_CONNECT_ACK:
1871 DEBUGP(DNM, "IPACC: RSL CONNECT ACK");
1872 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_RSL_BSC_IP))
1873 DEBUGPC(DNM, "IP=%s\n",
1874 inet_ntoa(*((struct in_addr *)
1875 TLVP_VAL(&tp, NM_ATT_IPACC_RSL_BSC_IP))));
1876 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_RSL_BSC_PORT))
1877 DEBUGPC(DNM, "IP=%s\n",
1878 ntohs(*((u_int16_t *)
1879 TLVP_VAL(&tp, NM_ATT_IPACC_RSL_BSC_PORT))));
1880 break;
1881 case NM_MT_IPACC_RSL_CONNECT_NACK:
1882 DEBUGP(DNM, "IPACC: RSL CONNECT NACK");
1883 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
1884 DEBUGPC(DNM, " CAUSE=0x%02x\n", *TLVP_VAL(&tp, NM_ATT_NACK_CAUSES));
1885 else
1886 DEBUGPC(DNM, "\n");
1887 break;
1888 }
1889 return 0;
1890}
1891
Harald Welte5c1e4582009-02-15 11:57:29 +00001892int abis_nm_ipaccess_msg(struct gsm_bts *bts, u_int8_t msg_type,
1893 u_int8_t obj_class, u_int8_t bts_nr,
1894 u_int8_t trx_nr, u_int8_t ts_nr,
1895 u_int8_t *attr, int attr_len)
1896{
1897 struct msgb *msg = nm_msgb_alloc();
1898 struct abis_om_hdr *oh;
1899 struct abis_om_fom_hdr *foh;
1900 u_int8_t *data;
1901
1902 /* construct the 12.21 OM header, observe the erroneous length */
1903 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
1904 fill_om_hdr(oh, sizeof(*foh) + attr_len);
1905 oh->mdisc = ABIS_OM_MDISC_MANUF;
1906
1907 /* add the ip.access magic */
1908 data = msgb_put(msg, sizeof(ipaccess_magic)+1);
1909 *data++ = sizeof(ipaccess_magic);
1910 memcpy(data, ipaccess_magic, sizeof(ipaccess_magic));
1911
1912 /* fill the 12.21 FOM header */
1913 foh = (struct abis_om_fom_hdr *) msgb_put(msg, sizeof(*foh));
1914 foh->msg_type = msg_type;
1915 foh->obj_class = obj_class;
1916 foh->obj_inst.bts_nr = bts_nr;
1917 foh->obj_inst.trx_nr = trx_nr;
1918 foh->obj_inst.ts_nr = ts_nr;
1919
1920 if (attr && attr_len) {
1921 data = msgb_put(msg, attr_len);
1922 memcpy(data, attr, attr_len);
1923 }
1924
1925 return abis_nm_sendmsg(bts, msg);
1926}
Harald Welte677c21f2009-02-17 13:22:23 +00001927