blob: 33fc0bfbc817006be4485430d7e97886593a118c [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{
Harald Welte0b8348d2009-02-18 03:43:01 +0000339 if (avail == 0xff)
340 return "OK";
Harald Weltee0590df2009-02-15 03:34:15 +0000341 if (avail >= ARRAY_SIZE(avail_names))
342 return "UNKNOWN";
343 return avail_names[avail];
344}
345
346
347/* obtain the gsm_nm_state data structure for a given object instance */
348static struct gsm_nm_state *
349objclass2nmstate(struct gsm_bts *bts, u_int8_t obj_class,
350 struct abis_om_obj_inst *obj_inst)
351{
352 struct gsm_bts_trx *trx;
353 struct gsm_nm_state *nm_state = NULL;
354
355 switch (obj_class) {
356 case NM_OC_BTS:
357 nm_state = &bts->nm_state;
358 break;
359 case NM_OC_RADIO_CARRIER:
360 if (obj_inst->trx_nr >= bts->num_trx)
361 return NULL;
362 trx = &bts->trx[obj_inst->trx_nr];
363 nm_state = &trx->nm_state;
364 break;
365 case NM_OC_BASEB_TRANSC:
366 if (obj_inst->trx_nr >= bts->num_trx)
367 return NULL;
368 trx = &bts->trx[obj_inst->trx_nr];
369 nm_state = &trx->bb_transc.nm_state;
370 break;
371 case NM_OC_CHANNEL:
372 if (obj_inst->trx_nr > bts->num_trx)
373 return NULL;
374 trx = &bts->trx[obj_inst->trx_nr];
375 if (obj_inst->ts_nr >= TRX_NR_TS)
376 return NULL;
377 nm_state = &trx->ts[obj_inst->ts_nr].nm_state;
378 break;
379 case NM_OC_SITE_MANAGER:
380 nm_state = &bts->site_mgr.nm_state;
381 break;
382 }
383 return nm_state;
384}
385
386/* obtain the in-memory data structure of a given object instance */
387static void *
388objclass2obj(struct gsm_bts *bts, u_int8_t obj_class,
389 struct abis_om_obj_inst *obj_inst)
390{
391 struct gsm_bts_trx *trx;
392 void *obj = NULL;
393
394 switch (obj_class) {
395 case NM_OC_BTS:
396 obj = bts;
397 break;
398 case NM_OC_RADIO_CARRIER:
399 if (obj_inst->trx_nr >= bts->num_trx)
400 return NULL;
401 trx = &bts->trx[obj_inst->trx_nr];
402 obj = trx;
403 break;
404 case NM_OC_BASEB_TRANSC:
405 if (obj_inst->trx_nr >= bts->num_trx)
406 return NULL;
407 trx = &bts->trx[obj_inst->trx_nr];
408 obj = &trx->bb_transc;
409 break;
410 case NM_OC_CHANNEL:
411 if (obj_inst->trx_nr > bts->num_trx)
412 return NULL;
413 trx = &bts->trx[obj_inst->trx_nr];
414 if (obj_inst->ts_nr >= TRX_NR_TS)
415 return NULL;
416 obj = &trx->ts[obj_inst->ts_nr];
417 break;
418 case NM_OC_SITE_MANAGER:
419 obj = &bts->site_mgr;
420 break;
421 }
422 return obj;
423}
424
425/* Update the administrative state of a given object in our in-memory data
426 * structures and send an event to the higher layer */
427static int update_admstate(struct gsm_bts *bts, u_int8_t obj_class,
428 struct abis_om_obj_inst *obj_inst, u_int8_t adm_state)
429{
430 struct gsm_nm_state *nm_state;
431 void *obj;
432 int rc;
433
434 nm_state = objclass2nmstate(bts, obj_class, obj_inst);
435 obj = objclass2obj(bts, obj_class, obj_inst);
436 rc = nm_state_event(EVT_STATECHG_ADM, obj_class, obj, nm_state, adm_state);
437 if (nm_state)
438 nm_state->administrative = adm_state;
439
440 return rc;
441}
442
Harald Welte97ed1e72009-02-06 13:38:02 +0000443static int abis_nm_rx_statechg_rep(struct msgb *mb)
444{
Harald Weltee0590df2009-02-15 03:34:15 +0000445 struct abis_om_hdr *oh = msgb_l2(mb);
Harald Welte97ed1e72009-02-06 13:38:02 +0000446 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Harald Welte22af0db2009-02-14 15:41:08 +0000447 struct gsm_bts *bts = mb->trx->bts;
Harald Weltee0590df2009-02-15 03:34:15 +0000448 struct tlv_parsed tp;
449 struct gsm_nm_state *nm_state, new_state;
450 int rc;
451
Harald Welte34a99682009-02-13 02:41:40 +0000452 DEBUGP(DNM, "STATE CHG: OC=%s(%02x) INST=(%02x,%02x,%02x) ",
453 obj_class_name(foh->obj_class), foh->obj_class,
454 foh->obj_inst.bts_nr, foh->obj_inst.trx_nr,
Harald Welte97ed1e72009-02-06 13:38:02 +0000455 foh->obj_inst.ts_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000456
457 nm_state = objclass2nmstate(bts, foh->obj_class, &foh->obj_inst);
458 if (!nm_state) {
459 DEBUGPC(DNM, "\n");
460 return -EINVAL;
Harald Welte22af0db2009-02-14 15:41:08 +0000461 }
Harald Weltee0590df2009-02-15 03:34:15 +0000462
463 new_state = *nm_state;
464
465 nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
466 if (TLVP_PRESENT(&tp, NM_ATT_OPER_STATE)) {
467 new_state.operational = *TLVP_VAL(&tp, NM_ATT_OPER_STATE);
468 DEBUGPC(DNM, "OP_STATE=%s ", opstate_name(new_state.operational));
469 }
470 if (TLVP_PRESENT(&tp, NM_ATT_AVAIL_STATUS)) {
Harald Welte0b8348d2009-02-18 03:43:01 +0000471 if (TLVP_LEN(&tp, NM_ATT_AVAIL_STATUS) == 0)
472 new_state.availability = 0xff;
473 else
474 new_state.availability = *TLVP_VAL(&tp, NM_ATT_AVAIL_STATUS);
Harald Weltee0590df2009-02-15 03:34:15 +0000475 DEBUGPC(DNM, "AVAIL=%s(%02x) ", avail_name(new_state.availability),
476 new_state.availability);
477 }
478 if (TLVP_PRESENT(&tp, NM_ATT_ADM_STATE)) {
479 new_state.administrative = *TLVP_VAL(&tp, NM_ATT_ADM_STATE);
480 DEBUGPC(DNM, "ADM=%02x ", new_state.administrative);
Harald Welte97ed1e72009-02-06 13:38:02 +0000481 }
482 DEBUGPC(DNM, "\n");
Harald Weltee0590df2009-02-15 03:34:15 +0000483
484 if (memcmp(&new_state, nm_state, sizeof(new_state))) {
485 /* Update the operational state of a given object in our in-memory data
486 * structures and send an event to the higher layer */
487 void *obj = objclass2obj(bts, foh->obj_class, &foh->obj_inst);
488 rc = nm_state_event(EVT_STATECHG_OPER, foh->obj_class, obj, nm_state, &new_state);
489 *nm_state = new_state;
490 }
491#if 0
Harald Welte22af0db2009-02-14 15:41:08 +0000492 if (op_state == 1) {
493 /* try to enable objects that are disabled */
494 abis_nm_opstart(bts, foh->obj_class,
495 foh->obj_inst.bts_nr,
496 foh->obj_inst.trx_nr,
497 foh->obj_inst.ts_nr);
498 }
Harald Weltee0590df2009-02-15 03:34:15 +0000499#endif
Harald Welte97ed1e72009-02-06 13:38:02 +0000500 return 0;
501}
502
503static int abis_nm_rcvmsg_report(struct msgb *mb)
504{
505 struct abis_om_fom_hdr *foh = msgb_l3(mb);
506 u_int8_t mt = foh->msg_type;
507
508 //nmh->cfg->report_cb(mb, foh);
509
510 switch (mt) {
511 case NM_MT_STATECHG_EVENT_REP:
512 return abis_nm_rx_statechg_rep(mb);
513 break;
Harald Welte34a99682009-02-13 02:41:40 +0000514 case NM_MT_SW_ACTIVATED_REP:
515 DEBUGP(DNM, "Software Activated Report\n");
516 break;
Harald Weltee0590df2009-02-15 03:34:15 +0000517 case NM_MT_FAILURE_EVENT_REP:
518 DEBUGP(DNM, "Failure Event Report\n");
519 break;
520 default:
521 DEBUGP(DNM, "reporting NM MT 0x%02x\n", mt);
522 break;
523
Harald Welte97ed1e72009-02-06 13:38:02 +0000524 };
525
Harald Welte97ed1e72009-02-06 13:38:02 +0000526 return 0;
527}
528
Harald Welte34a99682009-02-13 02:41:40 +0000529/* Activate the specified software into the BTS */
530static int ipacc_sw_activate(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1,
531 u_int8_t i2, u_int8_t *sw_desc, u_int8_t swdesc_len)
532{
533 struct abis_om_hdr *oh;
534 struct msgb *msg = nm_msgb_alloc();
535 u_int8_t len = swdesc_len;
536 u_int8_t *trailer;
537
538 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
539 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, obj_class, i0, i1, i2);
540
541 trailer = msgb_put(msg, swdesc_len);
542 memcpy(trailer, sw_desc, swdesc_len);
543
544 return abis_nm_sendmsg(bts, msg);
545}
546
547static int abis_nm_rx_sw_act_req(struct msgb *mb)
548{
549 struct abis_om_hdr *oh = msgb_l2(mb);
550 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Harald Welte5c1e4582009-02-15 11:57:29 +0000551 int nack = 0;
Harald Welte34a99682009-02-13 02:41:40 +0000552 int ret;
553
Harald Welte5c1e4582009-02-15 11:57:29 +0000554 DEBUGP(DNM, "Software Activate Request ");
Harald Welte34a99682009-02-13 02:41:40 +0000555
Harald Welte5c1e4582009-02-15 11:57:29 +0000556 if (foh->obj_class >= 0xf0 && foh->obj_class <= 0xf3) {
557 DEBUGPC(DNM, "NACKing for GPRS obj_class 0x%02x\n", foh->obj_class);
558 nack = 1;
559 } else
560 DEBUGPC(DNM, "ACKing and Activating\n");
561
562 ret = abis_nm_sw_act_req_ack(mb->trx->bts, foh->obj_class,
Harald Welte34a99682009-02-13 02:41:40 +0000563 foh->obj_inst.bts_nr,
564 foh->obj_inst.trx_nr,
Harald Welte5c1e4582009-02-15 11:57:29 +0000565 foh->obj_inst.ts_nr, nack,
Harald Welte34a99682009-02-13 02:41:40 +0000566 foh->data, oh->length-sizeof(*foh));
567
Harald Welte5c1e4582009-02-15 11:57:29 +0000568 if (nack)
569 return ret;
570
Harald Welte34a99682009-02-13 02:41:40 +0000571 /* FIXME: properly parse attributes */
572 return ipacc_sw_activate(mb->trx->bts, foh->obj_class,
573 foh->obj_inst.bts_nr,
574 foh->obj_inst.trx_nr,
575 foh->obj_inst.ts_nr,
576 foh->data + oh->length-sizeof(*foh)-22, 22);
577}
578
Harald Weltee0590df2009-02-15 03:34:15 +0000579/* Receive a CHANGE_ADM_STATE_ACK, parse the TLV and update local state */
580static int abis_nm_rx_chg_adm_state_ack(struct msgb *mb)
581{
582 struct abis_om_hdr *oh = msgb_l2(mb);
583 struct abis_om_fom_hdr *foh = msgb_l3(mb);
584 struct tlv_parsed tp;
585 u_int8_t adm_state;
586
587 nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
588 if (!TLVP_PRESENT(&tp, NM_ATT_ADM_STATE))
589 return -EINVAL;
590
591 adm_state = *TLVP_VAL(&tp, NM_ATT_ADM_STATE);
592
593 return update_admstate(mb->trx->bts, foh->obj_class, &foh->obj_inst, adm_state);
594}
595
Harald Welte52b1f982008-12-23 20:25:15 +0000596/* Receive a OML NM Message from BTS */
Harald Welte8470bf22008-12-25 23:28:35 +0000597static int abis_nm_rcvmsg_fom(struct msgb *mb)
Harald Welte52b1f982008-12-23 20:25:15 +0000598{
599 struct abis_om_fom_hdr *foh = msgb_l3(mb);
600 u_int8_t mt = foh->msg_type;
601
602 /* check for unsolicited message */
Harald Welte97ed1e72009-02-06 13:38:02 +0000603 if (is_report(mt))
604 return abis_nm_rcvmsg_report(mb);
Harald Welte52b1f982008-12-23 20:25:15 +0000605
Harald Welte4724f992009-01-18 18:01:49 +0000606 if (is_in_arr(mt, sw_load_msgs, ARRAY_SIZE(sw_load_msgs)))
607 return abis_nm_rcvmsg_sw(mb);
608
Harald Weltee0590df2009-02-15 03:34:15 +0000609 if (is_in_arr(mt, nacks, ARRAY_SIZE(nacks)))
610 DEBUGP(DNM, "NACK 0x%02x\n", mt);
Harald Weltead384642008-12-26 10:20:07 +0000611#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000612 /* check if last message is to be acked */
613 if (is_ack_nack(nmh->last_msgtype)) {
614 if (mt == MT_ACK(nmh->last_msgtype)) {
615 fprintf(stderr, "received ACK (0x%x)\n",
616 foh->msg_type);
617 /* we got our ACK, continue sending the next msg */
618 } else if (mt == MT_NACK(nmh->last_msgtype)) {
619 /* we got a NACK, signal this to the caller */
620 fprintf(stderr, "received NACK (0x%x)\n",
621 foh->msg_type);
622 /* FIXME: somehow signal this to the caller */
623 } else {
624 /* really strange things happen */
625 return -EINVAL;
626 }
627 }
Harald Weltead384642008-12-26 10:20:07 +0000628#endif
629
Harald Welte97ed1e72009-02-06 13:38:02 +0000630 switch (mt) {
Harald Weltee0590df2009-02-15 03:34:15 +0000631 case NM_MT_CHG_ADM_STATE_ACK:
632 return abis_nm_rx_chg_adm_state_ack(mb);
633 break;
Harald Welte34a99682009-02-13 02:41:40 +0000634 case NM_MT_SW_ACT_REQ:
635 return abis_nm_rx_sw_act_req(mb);
636 break;
Harald Welte97ed1e72009-02-06 13:38:02 +0000637 case NM_MT_BS11_LMT_SESSION:
638 DEBUGP(DNM, "LMT Event: \n");
639 break;
640 }
641
Harald Weltead384642008-12-26 10:20:07 +0000642 return 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000643}
644
Harald Welte677c21f2009-02-17 13:22:23 +0000645static int abis_nm_rx_ipacc(struct msgb *mb);
646
647static int abis_nm_rcvmsg_manuf(struct msgb *mb)
648{
649 int rc;
650 int bts_type = mb->trx->bts->type;
651
652 switch (bts_type) {
653 case GSM_BTS_TYPE_NANOBTS_900:
654 case GSM_BTS_TYPE_NANOBTS_1800:
655 rc = abis_nm_rx_ipacc(mb);
656 break;
657 default:
658 fprintf(stderr, "don't know how to parse OML for this "
659 "BTS type (%u)\n", bts_type);
660 rc = 0;
661 break;
662 }
663
664 return rc;
665}
666
Harald Welte52b1f982008-12-23 20:25:15 +0000667/* High-Level API */
668/* Entry-point where L2 OML from BTS enters the NM code */
Harald Welte8470bf22008-12-25 23:28:35 +0000669int abis_nm_rcvmsg(struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +0000670{
Harald Welte52b1f982008-12-23 20:25:15 +0000671 struct abis_om_hdr *oh = msgb_l2(msg);
Harald Welte677c21f2009-02-17 13:22:23 +0000672 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000673
674 /* Various consistency checks */
675 if (oh->placement != ABIS_OM_PLACEMENT_ONLY) {
676 fprintf(stderr, "ABIS OML placement 0x%x not supported\n",
677 oh->placement);
678 return -EINVAL;
679 }
680 if (oh->sequence != 0) {
681 fprintf(stderr, "ABIS OML sequence 0x%x != 0x00\n",
682 oh->sequence);
683 return -EINVAL;
684 }
Harald Welte702d8702008-12-26 20:25:35 +0000685#if 0
Holger Freytherca362a62009-01-04 21:05:01 +0000686 unsigned int l2_len = msg->tail - (u_int8_t *)msgb_l2(msg);
687 unsigned int hlen = sizeof(*oh) + sizeof(struct abis_om_fom_hdr);
Harald Welte702d8702008-12-26 20:25:35 +0000688 if (oh->length + hlen > l2_len) {
Harald Welte52b1f982008-12-23 20:25:15 +0000689 fprintf(stderr, "ABIS OML truncated message (%u > %u)\n",
690 oh->length + sizeof(*oh), l2_len);
691 return -EINVAL;
692 }
Harald Welte702d8702008-12-26 20:25:35 +0000693 if (oh->length + hlen < l2_len)
694 fprintf(stderr, "ABIS OML message with extra trailer?!? (oh->len=%d, sizeof_oh=%d l2_len=%d\n", oh->length, sizeof(*oh), l2_len);
695#endif
Harald Weltead384642008-12-26 10:20:07 +0000696 msg->l3h = (unsigned char *)oh + sizeof(*oh);
Harald Welte52b1f982008-12-23 20:25:15 +0000697
698 switch (oh->mdisc) {
699 case ABIS_OM_MDISC_FOM:
Harald Welte8470bf22008-12-25 23:28:35 +0000700 rc = abis_nm_rcvmsg_fom(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000701 break;
Harald Welte677c21f2009-02-17 13:22:23 +0000702 case ABIS_OM_MDISC_MANUF:
703 rc = abis_nm_rcvmsg_manuf(msg);
704 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000705 case ABIS_OM_MDISC_MMI:
706 case ABIS_OM_MDISC_TRAU:
Harald Welte677c21f2009-02-17 13:22:23 +0000707 fprintf(stderr, "unimplemented ABIS OML message discriminator 0x%x\n",
708 oh->mdisc);
709 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000710 default:
711 fprintf(stderr, "unknown ABIS OML message discriminator 0x%x\n",
712 oh->mdisc);
713 return -EINVAL;
714 }
715
Harald Weltead384642008-12-26 10:20:07 +0000716 msgb_free(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000717 return rc;
718}
719
720#if 0
721/* initialized all resources */
722struct abis_nm_h *abis_nm_init(struct abis_nm_cfg *cfg)
723{
724 struct abis_nm_h *nmh;
725
726 nmh = malloc(sizeof(*nmh));
727 if (!nmh)
728 return NULL;
729
730 nmh->cfg = cfg;
731
732 return nmh;
733}
734
735/* free all resources */
736void abis_nm_fini(struct abis_nm_h *nmh)
737{
738 free(nmh);
739}
740#endif
741
742/* Here we are trying to define a high-level API that can be used by
743 * the actual BSC implementation. However, the architecture is currently
744 * still under design. Ideally the calls to this API would be synchronous,
745 * while the underlying stack behind the APi runs in a traditional select
746 * based state machine.
747 */
748
Harald Welte4724f992009-01-18 18:01:49 +0000749/* 6.2 Software Load: */
750enum sw_state {
751 SW_STATE_NONE,
752 SW_STATE_WAIT_INITACK,
753 SW_STATE_WAIT_SEGACK,
754 SW_STATE_WAIT_ENDACK,
755 SW_STATE_WAIT_ACTACK,
756 SW_STATE_ERROR,
757};
Harald Welte52b1f982008-12-23 20:25:15 +0000758
Harald Welte52b1f982008-12-23 20:25:15 +0000759struct abis_nm_sw {
Harald Welte4724f992009-01-18 18:01:49 +0000760 struct gsm_bts *bts;
Harald Welte5e4d1b32009-02-01 13:36:56 +0000761 gsm_cbfn *cbfn;
762 void *cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +0000763 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +0000764
Harald Welte52b1f982008-12-23 20:25:15 +0000765 /* this will become part of the SW LOAD INITIATE */
766 u_int8_t obj_class;
767 u_int8_t obj_instance[3];
Harald Welte4724f992009-01-18 18:01:49 +0000768
769 u_int8_t file_id[255];
770 u_int8_t file_id_len;
771
772 u_int8_t file_version[255];
773 u_int8_t file_version_len;
774
775 u_int8_t window_size;
776 u_int8_t seg_in_window;
777
778 int fd;
779 FILE *stream;
780 enum sw_state state;
Harald Welte1602ade2009-01-29 21:12:39 +0000781 int last_seg;
Harald Welte52b1f982008-12-23 20:25:15 +0000782};
783
Harald Welte4724f992009-01-18 18:01:49 +0000784static struct abis_nm_sw g_sw;
785
786/* 6.2.1 / 8.3.1: Load Data Initiate */
787static int sw_load_init(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +0000788{
Harald Welte4724f992009-01-18 18:01:49 +0000789 struct abis_om_hdr *oh;
790 struct msgb *msg = nm_msgb_alloc();
791 u_int8_t len = 3*2 + sw->file_id_len + sw->file_version_len;
792
793 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
794 fill_om_fom_hdr(oh, len, NM_MT_LOAD_INIT, sw->obj_class,
795 sw->obj_instance[0], sw->obj_instance[1],
796 sw->obj_instance[2]);
797
798 /* FIXME: this is BS11 specific format */
799 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
800 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
801 sw->file_version);
802 msgb_tv_put(msg, NM_ATT_WINDOW_SIZE, sw->window_size);
803
804 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000805}
806
Harald Welte1602ade2009-01-29 21:12:39 +0000807static int is_last_line(FILE *stream)
808{
809 char next_seg_buf[256];
810 long pos;
811
812 /* check if we're sending the last line */
813 pos = ftell(stream);
814 if (!fgets(next_seg_buf, sizeof(next_seg_buf)-2, stream)) {
815 fseek(stream, pos, SEEK_SET);
816 return 1;
817 }
818
819 fseek(stream, pos, SEEK_SET);
820 return 0;
821}
822
Harald Welte4724f992009-01-18 18:01:49 +0000823/* 6.2.2 / 8.3.2 Load Data Segment */
824static int sw_load_segment(struct abis_nm_sw *sw)
825{
826 struct abis_om_hdr *oh;
827 struct msgb *msg = nm_msgb_alloc();
828 char seg_buf[256];
829 char *line_buf = seg_buf+2;
Harald Welte3b8ba212009-01-29 12:27:58 +0000830 unsigned char *tlv;
Harald Welte4724f992009-01-18 18:01:49 +0000831 u_int8_t len;
Harald Welte4724f992009-01-18 18:01:49 +0000832
833 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte3b8ba212009-01-29 12:27:58 +0000834
835 switch (sw->bts->type) {
836 case GSM_BTS_TYPE_BS11:
837 if (fgets(line_buf, sizeof(seg_buf)-2, sw->stream) == NULL) {
838 perror("fgets reading segment");
839 return -EINVAL;
840 }
841 seg_buf[0] = 0x00;
Harald Welte1602ade2009-01-29 21:12:39 +0000842
843 /* check if we're sending the last line */
844 sw->last_seg = is_last_line(sw->stream);
845 if (sw->last_seg)
846 seg_buf[1] = 0;
847 else
848 seg_buf[1] = 1 + sw->seg_in_window++;
Harald Welte3b8ba212009-01-29 12:27:58 +0000849
850 len = strlen(line_buf) + 2;
851 tlv = msgb_put(msg, TLV_GROSS_LEN(len));
852 tlv_put(tlv, NM_ATT_BS11_FILE_DATA, len, (u_int8_t *)seg_buf);
853 /* BS11 wants CR + LF in excess of the TLV length !?! */
854 tlv[1] -= 2;
855
856 /* we only now know the exact length for the OM hdr */
857 len = strlen(line_buf)+2;
858 break;
859 default:
860 /* FIXME: Other BTS types */
861 return -1;
Harald Welte4724f992009-01-18 18:01:49 +0000862 }
Harald Welte4724f992009-01-18 18:01:49 +0000863
Harald Welte4724f992009-01-18 18:01:49 +0000864 fill_om_fom_hdr(oh, len, NM_MT_LOAD_SEG, sw->obj_class,
865 sw->obj_instance[0], sw->obj_instance[1],
866 sw->obj_instance[2]);
867
868 return abis_nm_sendmsg(sw->bts, msg);
869}
870
871/* 6.2.4 / 8.3.4 Load Data End */
872static int sw_load_end(struct abis_nm_sw *sw)
873{
874 struct abis_om_hdr *oh;
875 struct msgb *msg = nm_msgb_alloc();
876 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
877
878 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
879 fill_om_fom_hdr(oh, len, NM_MT_LOAD_END, sw->obj_class,
880 sw->obj_instance[0], sw->obj_instance[1],
881 sw->obj_instance[2]);
882
883 /* FIXME: this is BS11 specific format */
884 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
885 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
886 sw->file_version);
887
888 return abis_nm_sendmsg(sw->bts, msg);
889}
Harald Welte5e4d1b32009-02-01 13:36:56 +0000890
Harald Welte52b1f982008-12-23 20:25:15 +0000891/* Activate the specified software into the BTS */
Harald Welte4724f992009-01-18 18:01:49 +0000892static int sw_activate(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +0000893{
Harald Welte4724f992009-01-18 18:01:49 +0000894 struct abis_om_hdr *oh;
895 struct msgb *msg = nm_msgb_alloc();
896 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
Harald Welte52b1f982008-12-23 20:25:15 +0000897
Harald Welte4724f992009-01-18 18:01:49 +0000898 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
899 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, sw->obj_class,
900 sw->obj_instance[0], sw->obj_instance[1],
901 sw->obj_instance[2]);
902
903 /* FIXME: this is BS11 specific format */
904 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
905 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
906 sw->file_version);
907
908 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000909}
Harald Welte4724f992009-01-18 18:01:49 +0000910
911static int sw_open_file(struct abis_nm_sw *sw, const char *fname)
912{
913 char file_id[12+1];
914 char file_version[80+1];
915 int rc;
916
917 sw->fd = open(fname, O_RDONLY);
918 if (sw->fd < 0)
919 return sw->fd;
920
921 switch (sw->bts->type) {
922 case GSM_BTS_TYPE_BS11:
923 sw->stream = fdopen(sw->fd, "r");
924 if (!sw->stream) {
925 perror("fdopen");
926 return -1;
927 }
928 /* read first line and parse file ID and VERSION */
Harald Welte3b8ba212009-01-29 12:27:58 +0000929 rc = fscanf(sw->stream, "@(#)%12s:%80s\r\n",
Harald Welte4724f992009-01-18 18:01:49 +0000930 file_id, file_version);
931 if (rc != 2) {
932 perror("parsing header line of software file");
933 return -1;
934 }
935 strcpy((char *)sw->file_id, file_id);
936 sw->file_id_len = strlen(file_id);
937 strcpy((char *)sw->file_version, file_version);
938 sw->file_version_len = strlen(file_version);
939 /* rewind to start of file */
Harald Welte3b8ba212009-01-29 12:27:58 +0000940 rewind(sw->stream);
Harald Welte4724f992009-01-18 18:01:49 +0000941 break;
942 default:
943 /* We don't know how to treat them yet */
944 close(sw->fd);
945 return -EINVAL;
946 }
947
948 return 0;
949}
950
951static void sw_close_file(struct abis_nm_sw *sw)
952{
953 switch (sw->bts->type) {
954 case GSM_BTS_TYPE_BS11:
955 fclose(sw->stream);
956 break;
957 default:
958 close(sw->fd);
959 break;
960 }
961}
962
963/* Fill the window */
964static int sw_fill_window(struct abis_nm_sw *sw)
965{
966 int rc;
967
968 while (sw->seg_in_window < sw->window_size) {
969 rc = sw_load_segment(sw);
970 if (rc < 0)
971 return rc;
Harald Welte1602ade2009-01-29 21:12:39 +0000972 if (sw->last_seg)
973 break;
Harald Welte4724f992009-01-18 18:01:49 +0000974 }
975 return 0;
976}
977
978/* callback function from abis_nm_rcvmsg() handler */
979static int abis_nm_rcvmsg_sw(struct msgb *mb)
980{
981 struct abis_om_fom_hdr *foh = msgb_l3(mb);
982 int rc = -1;
983 struct abis_nm_sw *sw = &g_sw;
984 enum sw_state old_state = sw->state;
985
Harald Welte3ffd1372009-02-01 22:15:49 +0000986 //DEBUGP(DNM, "state %u, NM MT 0x%02x\n", sw->state, foh->msg_type);
Harald Welte4724f992009-01-18 18:01:49 +0000987
988 switch (sw->state) {
989 case SW_STATE_WAIT_INITACK:
990 switch (foh->msg_type) {
991 case NM_MT_LOAD_INIT_ACK:
992 /* fill window with segments */
Harald Welte5e4d1b32009-02-01 13:36:56 +0000993 if (sw->cbfn)
994 sw->cbfn(GSM_HOOK_NM_SWLOAD,
995 NM_MT_LOAD_INIT_ACK, mb,
996 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +0000997 rc = sw_fill_window(sw);
998 sw->state = SW_STATE_WAIT_SEGACK;
999 break;
1000 case NM_MT_LOAD_INIT_NACK:
Harald Welte3ffd1372009-02-01 22:15:49 +00001001 if (sw->forced) {
1002 DEBUGP(DNM, "FORCED: Ignoring Software Load "
1003 "Init NACK\n");
1004 if (sw->cbfn)
1005 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1006 NM_MT_LOAD_INIT_ACK, mb,
1007 sw->cb_data, NULL);
1008 rc = sw_fill_window(sw);
1009 sw->state = SW_STATE_WAIT_SEGACK;
1010 } else {
1011 DEBUGP(DNM, "Software Load Init NACK\n");
1012 if (sw->cbfn)
1013 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1014 NM_MT_LOAD_INIT_NACK, mb,
1015 sw->cb_data, NULL);
1016 sw->state = SW_STATE_ERROR;
1017 }
Harald Welte4724f992009-01-18 18:01:49 +00001018 break;
1019 }
1020 break;
1021 case SW_STATE_WAIT_SEGACK:
1022 switch (foh->msg_type) {
1023 case NM_MT_LOAD_SEG_ACK:
Harald Welte3ffd1372009-02-01 22:15:49 +00001024 if (sw->cbfn)
1025 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1026 NM_MT_LOAD_SEG_ACK, mb,
1027 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001028 sw->seg_in_window = 0;
Harald Welte1602ade2009-01-29 21:12:39 +00001029 if (!sw->last_seg) {
1030 /* fill window with more segments */
1031 rc = sw_fill_window(sw);
1032 sw->state = SW_STATE_WAIT_SEGACK;
1033 } else {
1034 /* end the transfer */
1035 sw->state = SW_STATE_WAIT_ENDACK;
1036 rc = sw_load_end(sw);
1037 }
Harald Welte4724f992009-01-18 18:01:49 +00001038 break;
1039 }
1040 break;
1041 case SW_STATE_WAIT_ENDACK:
1042 switch (foh->msg_type) {
1043 case NM_MT_LOAD_END_ACK:
1044 sw_close_file(sw);
Harald Welte5e4d1b32009-02-01 13:36:56 +00001045 DEBUGP(DNM, "Software Load End (BTS %u)\n",
1046 sw->bts->nr);
1047 sw->state = SW_STATE_NONE;
1048 if (sw->cbfn)
1049 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1050 NM_MT_LOAD_END_ACK, mb,
1051 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001052 break;
1053 case NM_MT_LOAD_END_NACK:
Holger Freyther31338a12009-02-06 17:43:50 +00001054 if (sw->forced) {
1055 DEBUGP(DNM, "FORCED: Ignoring Software Load"
1056 "End NACK\n");
1057 sw->state = SW_STATE_NONE;
1058 if (sw->cbfn)
1059 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1060 NM_MT_LOAD_END_ACK, mb,
1061 sw->cb_data, NULL);
1062 } else {
1063 DEBUGP(DNM, "Software Load End NACK\n");
1064 sw->state = SW_STATE_ERROR;
1065 if (sw->cbfn)
1066 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1067 NM_MT_LOAD_END_NACK, mb,
1068 sw->cb_data, NULL);
1069 }
Harald Welte4724f992009-01-18 18:01:49 +00001070 break;
1071 }
1072 case SW_STATE_WAIT_ACTACK:
1073 switch (foh->msg_type) {
1074 case NM_MT_ACTIVATE_SW_ACK:
1075 /* we're done */
Harald Welte5e4d1b32009-02-01 13:36:56 +00001076 DEBUGP(DNM, "Activate Software DONE!\n");
Harald Welte4724f992009-01-18 18:01:49 +00001077 sw->state = SW_STATE_NONE;
1078 rc = 0;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001079 if (sw->cbfn)
1080 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1081 NM_MT_ACTIVATE_SW_ACK, mb,
1082 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001083 break;
1084 case NM_MT_ACTIVATE_SW_NACK:
Harald Welte1602ade2009-01-29 21:12:39 +00001085 DEBUGP(DNM, "Activate Software NACK\n");
Harald Welte4724f992009-01-18 18:01:49 +00001086 sw->state = SW_STATE_ERROR;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001087 if (sw->cbfn)
1088 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1089 NM_MT_ACTIVATE_SW_NACK, mb,
1090 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001091 break;
1092 }
1093 case SW_STATE_NONE:
1094 case SW_STATE_ERROR:
1095 break;
1096 }
1097
1098 if (rc)
1099 fprintf(stderr, "unexpected NM MT 0x%02x in state %u -> %u\n",
1100 foh->msg_type, old_state, sw->state);
1101
1102 return rc;
1103}
1104
1105/* Load the specified software into the BTS */
1106int abis_nm_software_load(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00001107 u_int8_t win_size, int forced,
1108 gsm_cbfn *cbfn, void *cb_data)
Harald Welte4724f992009-01-18 18:01:49 +00001109{
1110 struct abis_nm_sw *sw = &g_sw;
1111 int rc;
1112
Harald Welte5e4d1b32009-02-01 13:36:56 +00001113 DEBUGP(DNM, "Software Load (BTS %u, File \"%s\")\n",
1114 bts->nr, fname);
1115
Harald Welte4724f992009-01-18 18:01:49 +00001116 if (sw->state != SW_STATE_NONE)
1117 return -EBUSY;
1118
1119 sw->bts = bts;
1120 sw->obj_class = NM_OC_SITE_MANAGER;
1121 sw->obj_instance[0] = 0xff;
1122 sw->obj_instance[1] = 0xff;
1123 sw->obj_instance[2] = 0xff;
1124 sw->window_size = win_size;
1125 sw->state = SW_STATE_WAIT_INITACK;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001126 sw->cbfn = cbfn;
1127 sw->cb_data = cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +00001128 sw->forced = forced;
Harald Welte4724f992009-01-18 18:01:49 +00001129
1130 rc = sw_open_file(sw, fname);
1131 if (rc < 0) {
1132 sw->state = SW_STATE_NONE;
1133 return rc;
1134 }
1135
1136 return sw_load_init(sw);
1137}
Harald Welte52b1f982008-12-23 20:25:15 +00001138
Harald Welte1602ade2009-01-29 21:12:39 +00001139int abis_nm_software_load_status(struct gsm_bts *bts)
1140{
1141 struct abis_nm_sw *sw = &g_sw;
1142 struct stat st;
1143 int rc, percent;
1144
1145 rc = fstat(sw->fd, &st);
1146 if (rc < 0) {
1147 perror("ERROR during stat");
1148 return rc;
1149 }
1150
1151 percent = (ftell(sw->stream) * 100) / st.st_size;
1152 return percent;
1153}
1154
Harald Welte5e4d1b32009-02-01 13:36:56 +00001155/* Activate the specified software into the BTS */
1156int abis_nm_software_activate(struct gsm_bts *bts, const char *fname,
1157 gsm_cbfn *cbfn, void *cb_data)
1158{
1159 struct abis_nm_sw *sw = &g_sw;
1160 int rc;
1161
1162 DEBUGP(DNM, "Activating Software (BTS %u, File \"%s\")\n",
1163 bts->nr, fname);
1164
1165 if (sw->state != SW_STATE_NONE)
1166 return -EBUSY;
1167
1168 sw->bts = bts;
1169 sw->obj_class = NM_OC_SITE_MANAGER;
1170 sw->obj_instance[0] = 0xff;
1171 sw->obj_instance[1] = 0xff;
1172 sw->obj_instance[2] = 0xff;
1173 sw->state = SW_STATE_WAIT_ACTACK;
1174 sw->cbfn = cbfn;
1175 sw->cb_data = cb_data;
1176
1177 /* Open the file in order to fill some sw struct members */
1178 rc = sw_open_file(sw, fname);
1179 if (rc < 0) {
1180 sw->state = SW_STATE_NONE;
1181 return rc;
1182 }
1183 sw_close_file(sw);
1184
1185 return sw_activate(sw);
1186}
1187
Harald Welte8470bf22008-12-25 23:28:35 +00001188static void fill_nm_channel(struct abis_nm_channel *ch, u_int8_t bts_port,
Harald Welte52b1f982008-12-23 20:25:15 +00001189 u_int8_t ts_nr, u_int8_t subslot_nr)
1190{
Harald Welteadaf08b2009-01-18 11:08:10 +00001191 ch->attrib = NM_ATT_ABIS_CHANNEL;
Harald Welte52b1f982008-12-23 20:25:15 +00001192 ch->bts_port = bts_port;
1193 ch->timeslot = ts_nr;
1194 ch->subslot = subslot_nr;
1195}
1196
1197int abis_nm_establish_tei(struct gsm_bts *bts, u_int8_t trx_nr,
1198 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot,
1199 u_int8_t tei)
1200{
1201 struct abis_om_hdr *oh;
1202 struct abis_nm_channel *ch;
Harald Welte702d8702008-12-26 20:25:35 +00001203 u_int8_t len = sizeof(*ch) + 2;
Harald Welte8470bf22008-12-25 23:28:35 +00001204 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001205
1206 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1207 fill_om_fom_hdr(oh, len, NM_MT_ESTABLISH_TEI, NM_OC_RADIO_CARRIER,
1208 bts->bts_nr, trx_nr, 0xff);
1209
Harald Welte8470bf22008-12-25 23:28:35 +00001210 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte52b1f982008-12-23 20:25:15 +00001211
1212 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1213 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1214
1215 return abis_nm_sendmsg(bts, msg);
1216}
1217
1218/* connect signalling of one (BTS,TRX) to a particular timeslot on the E1 */
1219int abis_nm_conn_terr_sign(struct gsm_bts_trx *trx,
1220 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot)
1221{
Harald Welte8470bf22008-12-25 23:28:35 +00001222 struct gsm_bts *bts = trx->bts;
Harald Welte52b1f982008-12-23 20:25:15 +00001223 struct abis_om_hdr *oh;
1224 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +00001225 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001226
1227 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001228 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_SIGN,
Harald Welte52b1f982008-12-23 20:25:15 +00001229 NM_OC_RADIO_CARRIER, bts->bts_nr, trx->nr, 0xff);
1230
1231 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1232 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1233
1234 return abis_nm_sendmsg(bts, msg);
1235}
1236
1237#if 0
1238int abis_nm_disc_terr_sign(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1239 struct abis_nm_abis_channel *chan)
1240{
1241}
1242#endif
1243
1244int abis_nm_conn_terr_traf(struct gsm_bts_trx_ts *ts,
1245 u_int8_t e1_port, u_int8_t e1_timeslot,
1246 u_int8_t e1_subslot)
1247{
1248 struct gsm_bts *bts = ts->trx->bts;
1249 struct abis_om_hdr *oh;
1250 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +00001251 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001252
1253 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1254 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_TRAF,
Harald Welteb110cee2009-02-18 03:42:35 +00001255 NM_OC_CHANNEL, bts->bts_nr, ts->trx->nr, ts->nr);
Harald Welte52b1f982008-12-23 20:25:15 +00001256
1257 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1258 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1259
Harald Welteb110cee2009-02-18 03:42:35 +00001260 DEBUGP(DNM, "CONNECT TERR TRAF Um=(%u,%u,%u) E1=(%u,%u,%u)\n",
1261 bts->bts_nr, ts->trx->nr, ts->nr,
1262 e1_port, e1_timeslot, e1_subslot);
1263
Harald Welte52b1f982008-12-23 20:25:15 +00001264 return abis_nm_sendmsg(bts, msg);
1265}
1266
1267#if 0
1268int abis_nm_disc_terr_traf(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1269 struct abis_nm_abis_channel *chan,
1270 u_int8_t subchan)
1271{
1272}
1273#endif
1274
Harald Welte22af0db2009-02-14 15:41:08 +00001275/* Chapter 8.6.1 */
1276int abis_nm_set_bts_attr(struct gsm_bts *bts, u_int8_t *attr, int attr_len)
1277{
1278 struct abis_om_hdr *oh;
1279 struct msgb *msg = nm_msgb_alloc();
1280 u_int8_t *cur;
1281
1282 DEBUGP(DNM, "Set BTS Attr (bts=%d)\n", bts->nr);
1283
1284 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1285 fill_om_fom_hdr(oh, attr_len, NM_MT_SET_BTS_ATTR, NM_OC_BTS, bts->nr, 0xff, 0xff);
1286 cur = msgb_put(msg, attr_len);
1287 memcpy(cur, attr, attr_len);
1288
1289 return abis_nm_sendmsg(bts, msg);
1290}
1291
1292/* Chapter 8.6.2 */
1293int abis_nm_set_radio_attr(struct gsm_bts_trx *trx, u_int8_t *attr, int attr_len)
1294{
1295 struct abis_om_hdr *oh;
1296 struct msgb *msg = nm_msgb_alloc();
1297 u_int8_t *cur;
1298
1299 DEBUGP(DNM, "Set TRX Attr (bts=%d,trx=%d)\n", trx->bts->nr, trx->nr);
1300
1301 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1302 fill_om_fom_hdr(oh, attr_len, NM_MT_SET_RADIO_ATTR, NM_OC_RADIO_CARRIER,
1303 trx->bts->nr, trx->nr, 0xff);
1304 cur = msgb_put(msg, attr_len);
1305 memcpy(cur, attr, attr_len);
1306
1307 return abis_nm_sendmsg(trx->bts, msg);
1308}
1309
1310/* Chapter 8.6.3 */
Harald Welte52b1f982008-12-23 20:25:15 +00001311int abis_nm_set_channel_attr(struct gsm_bts_trx_ts *ts, u_int8_t chan_comb)
1312{
1313 struct gsm_bts *bts = ts->trx->bts;
1314 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001315 u_int16_t arfcn = htons(ts->trx->arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001316 u_int8_t zero = 0x00;
Harald Welte8470bf22008-12-25 23:28:35 +00001317 struct msgb *msg = nm_msgb_alloc();
Harald Weltee0590df2009-02-15 03:34:15 +00001318 u_int8_t len = 2 + 2;
1319
1320 if (bts->type == GSM_BTS_TYPE_BS11)
1321 len += 4 + 2 + 2 + 3;
Harald Welte52b1f982008-12-23 20:25:15 +00001322
Harald Welte22af0db2009-02-14 15:41:08 +00001323 DEBUGP(DNM, "Set Chan Attr (bts=%d,trx=%d,ts=%d)\n", bts->nr, ts->trx->nr, ts->nr);
1324
Harald Welte52b1f982008-12-23 20:25:15 +00001325 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001326 fill_om_fom_hdr(oh, len, NM_MT_SET_CHAN_ATTR,
Holger Freyther6b2d2622009-02-14 23:16:59 +00001327 NM_OC_CHANNEL, bts->bts_nr,
Harald Welte52b1f982008-12-23 20:25:15 +00001328 ts->trx->nr, ts->nr);
1329 /* FIXME: don't send ARFCN list, hopping sequence, mAIO, ...*/
Harald Weltee0590df2009-02-15 03:34:15 +00001330 if (bts->type == GSM_BTS_TYPE_BS11)
1331 msgb_tlv16_put(msg, NM_ATT_ARFCN_LIST, 1, &arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001332 msgb_tv_put(msg, NM_ATT_CHAN_COMB, chan_comb);
Harald Weltee0590df2009-02-15 03:34:15 +00001333 if (bts->type == GSM_BTS_TYPE_BS11) {
1334 msgb_tv_put(msg, NM_ATT_HSN, 0x00);
1335 msgb_tv_put(msg, NM_ATT_MAIO, 0x00);
1336 }
Harald Welte52b1f982008-12-23 20:25:15 +00001337 msgb_tv_put(msg, NM_ATT_TSC, 0x07); /* training sequence */
Harald Weltee0590df2009-02-15 03:34:15 +00001338 if (bts->type == GSM_BTS_TYPE_BS11)
1339 msgb_tlv_put(msg, 0x59, 1, &zero);
Harald Welte52b1f982008-12-23 20:25:15 +00001340
1341 return abis_nm_sendmsg(bts, msg);
1342}
1343
Harald Welte34a99682009-02-13 02:41:40 +00001344int 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 +00001345 u_int8_t i2, u_int8_t i3, int nack, u_int8_t *attr, int att_len)
Harald Welte34a99682009-02-13 02:41:40 +00001346{
1347 struct abis_om_hdr *oh;
1348 struct msgb *msg = nm_msgb_alloc();
Harald Welte5c1e4582009-02-15 11:57:29 +00001349 u_int8_t msgtype = NM_MT_SW_ACT_REQ_ACK;
1350 u_int8_t len = att_len;
1351
1352 if (nack) {
1353 len += 2;
1354 msgtype = NM_MT_SW_ACT_REQ_NACK;
1355 }
Harald Welte34a99682009-02-13 02:41:40 +00001356
1357 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte5c1e4582009-02-15 11:57:29 +00001358 fill_om_fom_hdr(oh, att_len, msgtype, obj_class, i1, i2, i3);
1359
Harald Welte34a99682009-02-13 02:41:40 +00001360 if (attr) {
1361 u_int8_t *ptr = msgb_put(msg, att_len);
1362 memcpy(ptr, attr, att_len);
1363 }
Harald Welte5c1e4582009-02-15 11:57:29 +00001364 if (nack)
1365 msgb_tv_put(msg, NM_ATT_NACK_CAUSES, NM_NACK_OBJCLASS_NOTSUPP);
Harald Welte34a99682009-02-13 02:41:40 +00001366
1367 return abis_nm_sendmsg(bts, msg);
1368}
1369
Harald Welte8470bf22008-12-25 23:28:35 +00001370int abis_nm_raw_msg(struct gsm_bts *bts, int len, u_int8_t *rawmsg)
Harald Welte52b1f982008-12-23 20:25:15 +00001371{
Harald Welte8470bf22008-12-25 23:28:35 +00001372 struct msgb *msg = nm_msgb_alloc();
1373 struct abis_om_hdr *oh;
Harald Welte52b1f982008-12-23 20:25:15 +00001374 u_int8_t *data;
1375
1376 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
1377 fill_om_hdr(oh, len);
1378 data = msgb_put(msg, len);
Harald Weltead384642008-12-26 10:20:07 +00001379 memcpy(data, rawmsg, len);
Harald Welte52b1f982008-12-23 20:25:15 +00001380
1381 return abis_nm_sendmsg(bts, msg);
1382}
1383
1384/* Siemens specific commands */
1385static int __simple_cmd(struct gsm_bts *bts, u_int8_t msg_type)
1386{
1387 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001388 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001389
1390 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001391 fill_om_fom_hdr(oh, 0, msg_type, NM_OC_SITE_MANAGER,
Harald Welte52b1f982008-12-23 20:25:15 +00001392 0xff, 0xff, 0xff);
1393
1394 return abis_nm_sendmsg(bts, msg);
1395}
1396
Harald Welte34a99682009-02-13 02:41:40 +00001397/* Chapter 8.9.2 */
1398int abis_nm_opstart(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1, u_int8_t i2)
1399{
1400 struct abis_om_hdr *oh;
1401 struct msgb *msg = nm_msgb_alloc();
1402
Harald Welte22af0db2009-02-14 15:41:08 +00001403 DEBUGP(DNM, "Sending OPSTART obj_class=0x%02x obj_inst=(0x%02x, 0x%02x, 0x%02x)\n",
1404 obj_class, i0, i1, i2);
Harald Welte34a99682009-02-13 02:41:40 +00001405 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1406 fill_om_fom_hdr(oh, 0, NM_MT_OPSTART, obj_class, i0, i1, i2);
1407
1408 return abis_nm_sendmsg(bts, msg);
1409}
1410
1411/* Chapter 8.8.5 */
1412int abis_nm_chg_adm_state(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0,
1413 u_int8_t i1, u_int8_t i2, u_int8_t adm_state)
1414{
1415 struct abis_om_hdr *oh;
1416 struct msgb *msg = nm_msgb_alloc();
1417
1418 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1419 fill_om_fom_hdr(oh, 2, NM_MT_CHG_ADM_STATE, obj_class, i0, i1, i2);
1420 msgb_tv_put(msg, NM_ATT_ADM_STATE, adm_state);
1421
1422 return abis_nm_sendmsg(bts, msg);
1423}
1424
1425
Harald Welte52b1f982008-12-23 20:25:15 +00001426int abis_nm_event_reports(struct gsm_bts *bts, int on)
1427{
1428 if (on == 0)
Harald Welte227d4072009-01-03 08:16:25 +00001429 return __simple_cmd(bts, NM_MT_STOP_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001430 else
Harald Welte227d4072009-01-03 08:16:25 +00001431 return __simple_cmd(bts, NM_MT_REST_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001432}
1433
Harald Welte47d88ae2009-01-04 12:02:08 +00001434/* Siemens (or BS-11) specific commands */
1435
Harald Welte3ffd1372009-02-01 22:15:49 +00001436int abis_nm_bs11_bsc_disconnect(struct gsm_bts *bts, int reconnect)
1437{
1438 if (reconnect == 0)
1439 return __simple_cmd(bts, NM_MT_BS11_DISCONNECT);
1440 else
1441 return __simple_cmd(bts, NM_MT_BS11_RECONNECT);
1442}
1443
Harald Welteb8427972009-02-05 19:27:17 +00001444int abis_nm_bs11_restart(struct gsm_bts *bts)
1445{
1446 return __simple_cmd(bts, NM_MT_BS11_RESTART);
1447}
1448
1449
Harald Welte268bb402009-02-01 19:11:56 +00001450struct bs11_date_time {
1451 u_int16_t year;
1452 u_int8_t month;
1453 u_int8_t day;
1454 u_int8_t hour;
1455 u_int8_t min;
1456 u_int8_t sec;
1457} __attribute__((packed));
1458
1459
1460void get_bs11_date_time(struct bs11_date_time *aet)
1461{
1462 time_t t;
1463 struct tm *tm;
1464
1465 t = time(NULL);
1466 tm = localtime(&t);
1467 aet->sec = tm->tm_sec;
1468 aet->min = tm->tm_min;
1469 aet->hour = tm->tm_hour;
1470 aet->day = tm->tm_mday;
1471 aet->month = tm->tm_mon;
1472 aet->year = htons(1900 + tm->tm_year);
1473}
1474
Harald Welte05188ee2009-01-18 11:39:08 +00001475int abis_nm_bs11_reset_resource(struct gsm_bts *bts)
Harald Welte52b1f982008-12-23 20:25:15 +00001476{
Harald Welte4668fda2009-01-03 08:19:29 +00001477 return __simple_cmd(bts, NM_MT_BS11_RESET_RESOURCE);
Harald Welte52b1f982008-12-23 20:25:15 +00001478}
1479
Harald Welte05188ee2009-01-18 11:39:08 +00001480int abis_nm_bs11_db_transmission(struct gsm_bts *bts, int begin)
Harald Welte52b1f982008-12-23 20:25:15 +00001481{
1482 if (begin)
Harald Welte4668fda2009-01-03 08:19:29 +00001483 return __simple_cmd(bts, NM_MT_BS11_BEGIN_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00001484 else
Harald Welte4668fda2009-01-03 08:19:29 +00001485 return __simple_cmd(bts, NM_MT_BS11_END_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00001486}
Harald Welte47d88ae2009-01-04 12:02:08 +00001487
Harald Welte05188ee2009-01-18 11:39:08 +00001488int abis_nm_bs11_create_object(struct gsm_bts *bts,
Harald Welte1bc09062009-01-18 14:17:52 +00001489 enum abis_bs11_objtype type, u_int8_t idx,
1490 u_int8_t attr_len, const u_int8_t *attr)
Harald Welte47d88ae2009-01-04 12:02:08 +00001491{
1492 struct abis_om_hdr *oh;
1493 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00001494 u_int8_t *cur;
Harald Welte47d88ae2009-01-04 12:02:08 +00001495
1496 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001497 fill_om_fom_hdr(oh, attr_len, NM_MT_BS11_CREATE_OBJ,
Harald Welte268bb402009-02-01 19:11:56 +00001498 NM_OC_BS11, type, 0, idx);
Harald Welte1bc09062009-01-18 14:17:52 +00001499 cur = msgb_put(msg, attr_len);
1500 memcpy(cur, attr, attr_len);
Harald Welte47d88ae2009-01-04 12:02:08 +00001501
1502 return abis_nm_sendmsg(bts, msg);
1503}
1504
Harald Welte05188ee2009-01-18 11:39:08 +00001505int abis_nm_bs11_create_envaBTSE(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00001506{
1507 struct abis_om_hdr *oh;
1508 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00001509 u_int8_t zero = 0x00;
Harald Welte47d88ae2009-01-04 12:02:08 +00001510
1511 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001512 fill_om_fom_hdr(oh, 3, NM_MT_BS11_CREATE_OBJ,
Harald Welte1bc09062009-01-18 14:17:52 +00001513 NM_OC_BS11_ENVABTSE, 0, idx, 0xff);
1514 msgb_tlv_put(msg, 0x99, 1, &zero);
Harald Welte47d88ae2009-01-04 12:02:08 +00001515
1516 return abis_nm_sendmsg(bts, msg);
1517}
1518
Harald Welte05188ee2009-01-18 11:39:08 +00001519int abis_nm_bs11_create_bport(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00001520{
1521 struct abis_om_hdr *oh;
1522 struct msgb *msg = nm_msgb_alloc();
1523
1524 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1525 fill_om_fom_hdr(oh, 0, NM_MT_BS11_CREATE_OBJ, NM_OC_BS11_BPORT,
1526 idx, 0, 0);
1527
1528 return abis_nm_sendmsg(bts, msg);
1529}
Harald Welte05188ee2009-01-18 11:39:08 +00001530
1531int abis_nm_bs11_set_oml_tei(struct gsm_bts *bts, u_int8_t tei)
1532{
1533 struct abis_om_hdr *oh;
1534 struct msgb *msg = nm_msgb_alloc();
Harald Welte05188ee2009-01-18 11:39:08 +00001535
1536 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001537 fill_om_fom_hdr(oh, 2, NM_MT_BS11_SET_ATTR, NM_OC_SITE_MANAGER,
Harald Welte05188ee2009-01-18 11:39:08 +00001538 0xff, 0xff, 0xff);
1539 msgb_tv_put(msg, NM_ATT_TEI, tei);
1540
1541 return abis_nm_sendmsg(bts, msg);
1542}
1543
1544/* like abis_nm_conn_terr_traf */
1545int abis_nm_bs11_conn_oml(struct gsm_bts *bts, u_int8_t e1_port,
1546 u_int8_t e1_timeslot, u_int8_t e1_subslot)
1547{
1548 struct abis_om_hdr *oh;
1549 struct abis_nm_channel *ch;
1550 struct msgb *msg = nm_msgb_alloc();
1551
1552 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte05188ee2009-01-18 11:39:08 +00001553 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_BS11_SET_ATTR,
1554 NM_OC_SITE_MANAGER, 0xff, 0xff, 0xff);
1555
1556 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1557 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1558
1559 return abis_nm_sendmsg(bts, msg);
1560}
1561
1562int abis_nm_bs11_set_trx_power(struct gsm_bts_trx *trx, u_int8_t level)
1563{
1564 struct abis_om_hdr *oh;
1565 struct msgb *msg = nm_msgb_alloc();
Harald Welte05188ee2009-01-18 11:39:08 +00001566
1567 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001568 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR,
Harald Welte05188ee2009-01-18 11:39:08 +00001569 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
1570 msgb_tlv_put(msg, NM_ATT_BS11_TXPWR, 1, &level);
1571
1572 return abis_nm_sendmsg(trx->bts, msg);
1573}
1574
Harald Welte268bb402009-02-01 19:11:56 +00001575//static const u_int8_t bs11_logon_c7[] = { 0x07, 0xd9, 0x01, 0x11, 0x0d, 0x10, 0x20 };
Harald Weltebb151312009-01-28 20:42:07 +00001576static const u_int8_t bs11_logon_c8[] = { 0x02 };
Harald Welte05188ee2009-01-18 11:39:08 +00001577static const u_int8_t bs11_logon_c9[] = "FACTORY";
1578
Harald Welte1bc09062009-01-18 14:17:52 +00001579int abis_nm_bs11_factory_logon(struct gsm_bts *bts, int on)
Harald Welte05188ee2009-01-18 11:39:08 +00001580{
1581 struct abis_om_hdr *oh;
1582 struct msgb *msg = nm_msgb_alloc();
Harald Welte268bb402009-02-01 19:11:56 +00001583 struct bs11_date_time bdt;
1584
1585 get_bs11_date_time(&bdt);
Harald Welte05188ee2009-01-18 11:39:08 +00001586
1587 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte1bc09062009-01-18 14:17:52 +00001588 if (on) {
Harald Welte268bb402009-02-01 19:11:56 +00001589 u_int8_t len = 3*2 + sizeof(bdt)
Harald Welte6f676a32009-01-18 14:27:48 +00001590 + sizeof(bs11_logon_c8) + sizeof(bs11_logon_c9);
Harald Welte043d04a2009-01-29 23:15:30 +00001591 fill_om_fom_hdr(oh, len, NM_MT_BS11_LMT_LOGON,
Harald Welte1bc09062009-01-18 14:17:52 +00001592 NM_OC_BS11_A3, 0xff, 0xff, 0xff);
Harald Welte043d04a2009-01-29 23:15:30 +00001593 msgb_tlv_put(msg, NM_ATT_BS11_LMT_LOGIN_TIME,
Harald Welte5083b0b2009-02-02 19:20:52 +00001594 sizeof(bdt), (u_int8_t *) &bdt);
Harald Welte043d04a2009-01-29 23:15:30 +00001595 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_ACC_LEV,
1596 sizeof(bs11_logon_c8), bs11_logon_c8);
1597 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_NAME,
1598 sizeof(bs11_logon_c9), bs11_logon_c9);
Harald Welte1bc09062009-01-18 14:17:52 +00001599 } else {
Harald Welte5e4d1b32009-02-01 13:36:56 +00001600 fill_om_fom_hdr(oh, 0, NM_MT_BS11_LMT_LOGOFF,
Harald Welte1bc09062009-01-18 14:17:52 +00001601 NM_OC_BS11_A3, 0xff, 0xff, 0xff);
1602 }
Harald Welte05188ee2009-01-18 11:39:08 +00001603
1604 return abis_nm_sendmsg(bts, msg);
1605}
Harald Welte1bc09062009-01-18 14:17:52 +00001606
1607int abis_nm_bs11_set_trx1_pw(struct gsm_bts *bts, const char *password)
1608{
1609 struct abis_om_hdr *oh;
1610 struct msgb *msg;
1611
1612 if (strlen(password) != 10)
1613 return -EINVAL;
1614
1615 msg = nm_msgb_alloc();
1616 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001617 fill_om_fom_hdr(oh, 2+strlen(password), NM_MT_BS11_SET_ATTR,
Harald Welte1bc09062009-01-18 14:17:52 +00001618 NM_OC_BS11, BS11_OBJ_TRX1, 0x00, 0x00);
1619 msgb_tlv_put(msg, NM_ATT_BS11_PASSWORD, 10, (const u_int8_t *)password);
1620
1621 return abis_nm_sendmsg(bts, msg);
1622}
1623
1624int abis_nm_bs11_get_state(struct gsm_bts *bts)
1625{
1626 return __simple_cmd(bts, NM_MT_BS11_GET_STATE);
1627}
Harald Welte5e4d1b32009-02-01 13:36:56 +00001628
1629/* BS11 SWL */
1630
1631struct abis_nm_bs11_sw {
1632 struct gsm_bts *bts;
1633 char swl_fname[PATH_MAX];
1634 u_int8_t win_size;
Harald Welte3ffd1372009-02-01 22:15:49 +00001635 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001636 struct llist_head file_list;
1637 gsm_cbfn *user_cb; /* specified by the user */
1638};
1639static struct abis_nm_bs11_sw _g_bs11_sw, *g_bs11_sw = &_g_bs11_sw;
1640
1641struct file_list_entry {
1642 struct llist_head list;
1643 char fname[PATH_MAX];
1644};
1645
1646struct file_list_entry *fl_dequeue(struct llist_head *queue)
1647{
1648 struct llist_head *lh;
1649
1650 if (llist_empty(queue))
1651 return NULL;
1652
1653 lh = queue->next;
1654 llist_del(lh);
1655
1656 return llist_entry(lh, struct file_list_entry, list);
1657}
1658
1659static int bs11_read_swl_file(struct abis_nm_bs11_sw *bs11_sw)
1660{
1661 char linebuf[255];
1662 struct llist_head *lh, *lh2;
1663 FILE *swl;
1664 int rc = 0;
1665
1666 swl = fopen(bs11_sw->swl_fname, "r");
1667 if (!swl)
1668 return -ENODEV;
1669
1670 /* zero the stale file list, if any */
1671 llist_for_each_safe(lh, lh2, &bs11_sw->file_list) {
1672 llist_del(lh);
1673 free(lh);
1674 }
1675
1676 while (fgets(linebuf, sizeof(linebuf), swl)) {
1677 char file_id[12+1];
1678 char file_version[80+1];
1679 struct file_list_entry *fle;
1680 static char dir[PATH_MAX];
1681
1682 if (strlen(linebuf) < 4)
1683 continue;
Harald Welte3ffd1372009-02-01 22:15:49 +00001684
Harald Welte5e4d1b32009-02-01 13:36:56 +00001685 rc = sscanf(linebuf+4, "%12s:%80s\r\n", file_id, file_version);
1686 if (rc < 0) {
1687 perror("ERR parsing SWL file");
1688 rc = -EINVAL;
1689 goto out;
1690 }
1691 if (rc < 2)
1692 continue;
1693
1694 fle = malloc(sizeof(*fle));
1695 if (!fle) {
1696 rc = -ENOMEM;
1697 goto out;
1698 }
1699 memset(fle, 0, sizeof(*fle));
1700
1701 /* construct new filename */
1702 strncpy(dir, bs11_sw->swl_fname, sizeof(dir));
1703 strncat(fle->fname, dirname(dir), sizeof(fle->fname) - 1);
1704 strcat(fle->fname, "/");
1705 strncat(fle->fname, file_id, sizeof(fle->fname) - 1 -strlen(fle->fname));
Harald Welte5e4d1b32009-02-01 13:36:56 +00001706
1707 llist_add_tail(&fle->list, &bs11_sw->file_list);
1708 }
1709
1710out:
1711 fclose(swl);
1712 return rc;
1713}
1714
1715/* bs11 swload specific callback, passed to abis_nm core swload */
1716static int bs11_swload_cbfn(unsigned int hook, unsigned int event,
1717 struct msgb *msg, void *data, void *param)
1718{
1719 struct abis_nm_bs11_sw *bs11_sw = data;
1720 struct file_list_entry *fle;
1721 int rc = 0;
1722
Harald Welte5e4d1b32009-02-01 13:36:56 +00001723 switch (event) {
1724 case NM_MT_LOAD_END_ACK:
1725 fle = fl_dequeue(&bs11_sw->file_list);
1726 if (fle) {
1727 /* start download the next file of our file list */
1728 rc = abis_nm_software_load(bs11_sw->bts, fle->fname,
1729 bs11_sw->win_size,
Harald Welte3ffd1372009-02-01 22:15:49 +00001730 bs11_sw->forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00001731 &bs11_swload_cbfn, bs11_sw);
1732 free(fle);
1733 } else {
1734 /* activate the SWL */
1735 rc = abis_nm_software_activate(bs11_sw->bts,
1736 bs11_sw->swl_fname,
1737 bs11_swload_cbfn,
1738 bs11_sw);
1739 }
1740 break;
Harald Welte3ffd1372009-02-01 22:15:49 +00001741 case NM_MT_LOAD_SEG_ACK:
Harald Welte5e4d1b32009-02-01 13:36:56 +00001742 case NM_MT_LOAD_END_NACK:
1743 case NM_MT_LOAD_INIT_ACK:
1744 case NM_MT_LOAD_INIT_NACK:
1745 case NM_MT_ACTIVATE_SW_NACK:
1746 case NM_MT_ACTIVATE_SW_ACK:
1747 default:
1748 /* fallthrough to the user callback */
Harald Welte97ed1e72009-02-06 13:38:02 +00001749 if (bs11_sw->user_cb)
1750 rc = bs11_sw->user_cb(hook, event, msg, NULL, NULL);
Harald Welte5e4d1b32009-02-01 13:36:56 +00001751 break;
1752 }
1753
1754 return rc;
1755}
1756
1757/* Siemens provides a SWL file that is a mere listing of all the other
1758 * files that are part of a software release. We need to upload first
1759 * the list file, and then each file that is listed in the list file */
1760int abis_nm_bs11_load_swl(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00001761 u_int8_t win_size, int forced, gsm_cbfn *cbfn)
Harald Welte5e4d1b32009-02-01 13:36:56 +00001762{
1763 struct abis_nm_bs11_sw *bs11_sw = g_bs11_sw;
1764 struct file_list_entry *fle;
1765 int rc = 0;
1766
1767 INIT_LLIST_HEAD(&bs11_sw->file_list);
1768 bs11_sw->bts = bts;
1769 bs11_sw->win_size = win_size;
1770 bs11_sw->user_cb = cbfn;
Harald Welte3ffd1372009-02-01 22:15:49 +00001771 bs11_sw->forced = forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001772
1773 strncpy(bs11_sw->swl_fname, fname, sizeof(bs11_sw->swl_fname));
1774 rc = bs11_read_swl_file(bs11_sw);
1775 if (rc < 0)
1776 return rc;
1777
1778 /* dequeue next item in file list */
1779 fle = fl_dequeue(&bs11_sw->file_list);
1780 if (!fle)
1781 return -EINVAL;
1782
1783 /* start download the next file of our file list */
Harald Welte3ffd1372009-02-01 22:15:49 +00001784 rc = abis_nm_software_load(bts, fle->fname, win_size, forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00001785 bs11_swload_cbfn, bs11_sw);
1786 free(fle);
1787 return rc;
1788}
1789
Harald Welte5083b0b2009-02-02 19:20:52 +00001790#if 0
Harald Welte5e4d1b32009-02-01 13:36:56 +00001791static u_int8_t req_attr_btse[] = {
1792 NM_ATT_ADM_STATE, NM_ATT_BS11_LMT_LOGON_SESSION,
1793 NM_ATT_BS11_LMT_LOGIN_TIME, NM_ATT_BS11_LMT_USER_ACC_LEV,
1794 NM_ATT_BS11_LMT_USER_NAME,
1795
1796 0xaf, NM_ATT_BS11_RX_OFFSET, NM_ATT_BS11_VENDOR_NAME,
1797
1798 NM_ATT_BS11_SW_LOAD_INTENDED, NM_ATT_BS11_SW_LOAD_SAFETY,
1799
1800 NM_ATT_BS11_SW_LOAD_STORED };
1801
1802static u_int8_t req_attr_btsm[] = {
1803 NM_ATT_ABIS_CHANNEL, NM_ATT_TEI, NM_ATT_BS11_ABIS_EXT_TIME,
1804 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xce, NM_ATT_FILE_ID,
1805 NM_ATT_FILE_VERSION, NM_ATT_OPER_STATE, 0xe8, NM_ATT_BS11_ALL_TEST_CATG,
1806 NM_ATT_SW_DESCR, NM_ATT_GET_ARI };
Harald Welte5083b0b2009-02-02 19:20:52 +00001807#endif
Harald Welte5e4d1b32009-02-01 13:36:56 +00001808
1809static u_int8_t req_attr[] = {
1810 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xa8, NM_ATT_OPER_STATE,
1811 0xd5, 0xa1, NM_ATT_BS11_ESN_FW_CODE_NO, NM_ATT_BS11_ESN_HW_CODE_NO,
1812 0x42, NM_ATT_BS11_ESN_PCB_SERIAL };
1813
1814int abis_nm_bs11_get_serno(struct gsm_bts *bts)
1815{
1816 struct abis_om_hdr *oh;
1817 struct msgb *msg = nm_msgb_alloc();
1818
1819 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1820 /* SiemensHW CCTRL object */
1821 fill_om_fom_hdr(oh, 2+sizeof(req_attr), NM_MT_GET_ATTR, NM_OC_BS11,
1822 0x03, 0x00, 0x00);
1823 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(req_attr), req_attr);
1824
1825 return abis_nm_sendmsg(bts, msg);
1826}
Harald Welte268bb402009-02-01 19:11:56 +00001827
1828int abis_nm_bs11_set_ext_time(struct gsm_bts *bts)
1829{
1830 struct abis_om_hdr *oh;
1831 struct msgb *msg = nm_msgb_alloc();
1832 struct bs11_date_time aet;
1833
1834 get_bs11_date_time(&aet);
1835 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1836 /* SiemensHW CCTRL object */
1837 fill_om_fom_hdr(oh, 2+sizeof(aet), NM_MT_BS11_SET_ATTR, NM_OC_SITE_MANAGER,
1838 0xff, 0xff, 0xff);
Harald Welte5083b0b2009-02-02 19:20:52 +00001839 msgb_tlv_put(msg, NM_ATT_BS11_ABIS_EXT_TIME, sizeof(aet), (u_int8_t *) &aet);
Harald Welte268bb402009-02-01 19:11:56 +00001840
1841 return abis_nm_sendmsg(bts, msg);
1842}
Harald Welte5c1e4582009-02-15 11:57:29 +00001843
1844/* ip.access nanoBTS specific commands */
Harald Welte5c1e4582009-02-15 11:57:29 +00001845static const char ipaccess_magic[] = "com.ipaccess";
1846
Harald Welte677c21f2009-02-17 13:22:23 +00001847
1848static int abis_nm_rx_ipacc(struct msgb *msg)
1849{
1850 struct abis_om_hdr *oh = msgb_l2(msg);
1851 struct abis_om_fom_hdr *foh;
1852 u_int8_t idstrlen = oh->data[0];
1853 struct tlv_parsed tp;
1854
1855 if (strncmp((char *)&oh->data[1], ipaccess_magic, idstrlen)) {
1856 DEBUGP(DNM, "id string is not com.ipaccess !?!\n");
1857 return -EINVAL;
1858 }
1859
1860 foh = (struct abis_om_fom_hdr *) oh->data + 1 + idstrlen;
1861 nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
1862
1863 switch (foh->msg_type) {
1864 case NM_MT_IPACC_RSL_CONNECT_ACK:
1865 DEBUGP(DNM, "IPACC: RSL CONNECT ACK");
1866 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_RSL_BSC_IP))
1867 DEBUGPC(DNM, "IP=%s\n",
1868 inet_ntoa(*((struct in_addr *)
1869 TLVP_VAL(&tp, NM_ATT_IPACC_RSL_BSC_IP))));
1870 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_RSL_BSC_PORT))
1871 DEBUGPC(DNM, "IP=%s\n",
1872 ntohs(*((u_int16_t *)
1873 TLVP_VAL(&tp, NM_ATT_IPACC_RSL_BSC_PORT))));
1874 break;
1875 case NM_MT_IPACC_RSL_CONNECT_NACK:
1876 DEBUGP(DNM, "IPACC: RSL CONNECT NACK");
1877 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
1878 DEBUGPC(DNM, " CAUSE=0x%02x\n", *TLVP_VAL(&tp, NM_ATT_NACK_CAUSES));
1879 else
1880 DEBUGPC(DNM, "\n");
1881 break;
1882 }
1883 return 0;
1884}
1885
Harald Welte5c1e4582009-02-15 11:57:29 +00001886int abis_nm_ipaccess_msg(struct gsm_bts *bts, u_int8_t msg_type,
1887 u_int8_t obj_class, u_int8_t bts_nr,
1888 u_int8_t trx_nr, u_int8_t ts_nr,
1889 u_int8_t *attr, int attr_len)
1890{
1891 struct msgb *msg = nm_msgb_alloc();
1892 struct abis_om_hdr *oh;
1893 struct abis_om_fom_hdr *foh;
1894 u_int8_t *data;
1895
1896 /* construct the 12.21 OM header, observe the erroneous length */
1897 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
1898 fill_om_hdr(oh, sizeof(*foh) + attr_len);
1899 oh->mdisc = ABIS_OM_MDISC_MANUF;
1900
1901 /* add the ip.access magic */
1902 data = msgb_put(msg, sizeof(ipaccess_magic)+1);
1903 *data++ = sizeof(ipaccess_magic);
1904 memcpy(data, ipaccess_magic, sizeof(ipaccess_magic));
1905
1906 /* fill the 12.21 FOM header */
1907 foh = (struct abis_om_fom_hdr *) msgb_put(msg, sizeof(*foh));
1908 foh->msg_type = msg_type;
1909 foh->obj_class = obj_class;
1910 foh->obj_inst.bts_nr = bts_nr;
1911 foh->obj_inst.trx_nr = trx_nr;
1912 foh->obj_inst.ts_nr = ts_nr;
1913
1914 if (attr && attr_len) {
1915 data = msgb_put(msg, attr_len);
1916 memcpy(data, attr, attr_len);
1917 }
1918
1919 return abis_nm_sendmsg(bts, msg);
1920}
Harald Welte677c21f2009-02-17 13:22:23 +00001921