blob: 52a5a52e6b27f5e7eef6c005124a1bde689db423 [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
4/* (C) 2008 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>
26#include <stdio.h>
27#include <sys/types.h>
Harald Welte8470bf22008-12-25 23:28:35 +000028#include <netinet/in.h>
Harald Welte52b1f982008-12-23 20:25:15 +000029
Harald Welte8470bf22008-12-25 23:28:35 +000030#include <openbsc/gsm_data.h>
31#include <openbsc/debug.h>
32#include <openbsc/msgb.h>
33#include <openbsc/tlv.h>
34#include <openbsc/abis_nm.h>
Harald Welte52b1f982008-12-23 20:25:15 +000035
Harald Welte8470bf22008-12-25 23:28:35 +000036#define OM_ALLOC_SIZE 1024
37#define OM_HEADROOM_SIZE 128
Harald Welte52b1f982008-12-23 20:25:15 +000038
39/* unidirectional messages from BTS to BSC */
40static const enum abis_nm_msgtype reports[] = {
41 NM_MT_SW_ACTIVATED_REP,
42 NM_MT_TEST_REP,
43 NM_MT_STATECHG_EVENT_REP,
44 NM_MT_FAILURE_EVENT_REP,
45};
46
47/* messages without ACK/NACK */
48static const enum abis_nm_msgtype no_ack_nack[] = {
49 NM_MT_MEAS_RES_REQ,
50 NM_MT_STOP_MEAS,
51 NM_MT_START_MEAS,
52};
53
54/* Attributes that the BSC can set, not only get, according to Section 9.4 */
55static const enum abis_nm_attr nm_att_settable[] = {
56 NM_ATT_ADD_INFO,
57 NM_ATT_ADD_TEXT,
58 NM_ATT_DEST,
59 NM_ATT_EVENT_TYPE,
60 NM_ATT_FILE_DATA,
61 NM_ATT_GET_ARI,
62 NM_ATT_HW_CONF_CHG,
63 NM_ATT_LIST_REQ_ATTR,
64 NM_ATT_MDROP_LINK,
65 NM_ATT_MDROP_NEXT,
66 NM_ATT_NACK_CAUSES,
67 NM_ATT_OUTST_ALARM,
68 NM_ATT_PHYS_CONF,
69 NM_ATT_PROB_CAUSE,
70 NM_ATT_RAD_SUBC,
71 NM_ATT_SOURCE,
72 NM_ATT_SPEC_PROB,
73 NM_ATT_START_TIME,
74 NM_ATT_TEST_DUR,
75 NM_ATT_TEST_NO,
76 NM_ATT_TEST_REPORT,
77 NM_ATT_WINDOW_SIZE,
78 NM_ATT_SEVERITY,
79 NM_ATT_MEAS_RES,
80 NM_ATT_MEAS_TYPE,
81};
82
83static int is_in_arr(enum abis_nm_msgtype mt, const enum abis_nm_msgtype *arr, int size)
84{
85 int i;
86
87 for (i = 0; i < size; i++) {
88 if (arr[i] == mt)
89 return 1;
90 }
91
92 return 0;
93}
94
95/* is this msgtype the usual ACK/NACK type ? */
96static int is_ack_nack(enum abis_nm_msgtype mt)
97{
98 return !is_in_arr(mt, no_ack_nack, ARRAY_SIZE(no_ack_nack));
99}
100
101/* is this msgtype a report ? */
102static int is_report(enum abis_nm_msgtype mt)
103{
Harald Welte8470bf22008-12-25 23:28:35 +0000104 return is_in_arr(mt, reports, ARRAY_SIZE(reports));
Harald Welte52b1f982008-12-23 20:25:15 +0000105}
106
107#define MT_ACK(x) (x+1)
108#define MT_NACK(x) (x+2)
109
110static void fill_om_hdr(struct abis_om_hdr *oh, u_int8_t len)
111{
112 oh->mdisc = ABIS_OM_MDISC_FOM;
113 oh->placement = ABIS_OM_PLACEMENT_ONLY;
114 oh->sequence = 0;
115 oh->length = len;
116}
117
118static void fill_om_fom_hdr(struct abis_om_hdr *oh, u_int8_t len,
119 u_int8_t msg_type, u_int8_t obj_class,
120 u_int8_t bts_nr, u_int8_t trx_nr, u_int8_t ts_nr)
121{
122 struct abis_om_fom_hdr *foh =
123 (struct abis_om_fom_hdr *) oh->data;
124
Harald Welte702d8702008-12-26 20:25:35 +0000125 fill_om_hdr(oh, len+sizeof(*foh));
Harald Welte52b1f982008-12-23 20:25:15 +0000126 foh->msg_type = msg_type;
127 foh->obj_class = obj_class;
128 foh->obj_inst.bts_nr = bts_nr;
129 foh->obj_inst.trx_nr = trx_nr;
130 foh->obj_inst.ts_nr = ts_nr;
131}
132
Harald Welte8470bf22008-12-25 23:28:35 +0000133static struct msgb *nm_msgb_alloc(void)
134{
135 return msgb_alloc_headroom(OM_ALLOC_SIZE, OM_HEADROOM_SIZE);
136}
137
Harald Welte52b1f982008-12-23 20:25:15 +0000138/* Send a OML NM Message from BSC to BTS */
139int abis_nm_sendmsg(struct gsm_bts *bts, struct msgb *msg)
140{
Harald Weltead384642008-12-26 10:20:07 +0000141 return _abis_nm_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000142}
143
144/* Receive a OML NM Message from BTS */
Harald Welte8470bf22008-12-25 23:28:35 +0000145static int abis_nm_rcvmsg_fom(struct msgb *mb)
Harald Welte52b1f982008-12-23 20:25:15 +0000146{
147 struct abis_om_fom_hdr *foh = msgb_l3(mb);
148 u_int8_t mt = foh->msg_type;
149
150 /* check for unsolicited message */
151 if (is_report(mt)) {
Harald Weltead384642008-12-26 10:20:07 +0000152 DEBUGP(DNM, "reporting NM MT 0x%02x\n", mt);
153 //nmh->cfg->report_cb(mb, foh);
Harald Welte52b1f982008-12-23 20:25:15 +0000154 return 0;
155 }
156
Harald Weltead384642008-12-26 10:20:07 +0000157#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000158 /* check if last message is to be acked */
159 if (is_ack_nack(nmh->last_msgtype)) {
160 if (mt == MT_ACK(nmh->last_msgtype)) {
161 fprintf(stderr, "received ACK (0x%x)\n",
162 foh->msg_type);
163 /* we got our ACK, continue sending the next msg */
164 } else if (mt == MT_NACK(nmh->last_msgtype)) {
165 /* we got a NACK, signal this to the caller */
166 fprintf(stderr, "received NACK (0x%x)\n",
167 foh->msg_type);
168 /* FIXME: somehow signal this to the caller */
169 } else {
170 /* really strange things happen */
171 return -EINVAL;
172 }
173 }
Harald Weltead384642008-12-26 10:20:07 +0000174#endif
175
176 return 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000177}
178
179/* High-Level API */
180/* Entry-point where L2 OML from BTS enters the NM code */
Harald Welte8470bf22008-12-25 23:28:35 +0000181int abis_nm_rcvmsg(struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +0000182{
183 int rc;
184 struct abis_om_hdr *oh = msgb_l2(msg);
Harald Welte8470bf22008-12-25 23:28:35 +0000185 unsigned int l2_len = msg->tail - (u_int8_t *)msgb_l2(msg);
Harald Welte702d8702008-12-26 20:25:35 +0000186 unsigned int hlen = sizeof(*oh) + sizeof(struct abis_om_fom_hdr);
Harald Welte52b1f982008-12-23 20:25:15 +0000187
188 /* Various consistency checks */
189 if (oh->placement != ABIS_OM_PLACEMENT_ONLY) {
190 fprintf(stderr, "ABIS OML placement 0x%x not supported\n",
191 oh->placement);
192 return -EINVAL;
193 }
194 if (oh->sequence != 0) {
195 fprintf(stderr, "ABIS OML sequence 0x%x != 0x00\n",
196 oh->sequence);
197 return -EINVAL;
198 }
Harald Welte702d8702008-12-26 20:25:35 +0000199#if 0
200 if (oh->length + hlen > l2_len) {
Harald Welte52b1f982008-12-23 20:25:15 +0000201 fprintf(stderr, "ABIS OML truncated message (%u > %u)\n",
202 oh->length + sizeof(*oh), l2_len);
203 return -EINVAL;
204 }
Harald Welte702d8702008-12-26 20:25:35 +0000205 if (oh->length + hlen < l2_len)
206 fprintf(stderr, "ABIS OML message with extra trailer?!? (oh->len=%d, sizeof_oh=%d l2_len=%d\n", oh->length, sizeof(*oh), l2_len);
207#endif
Harald Weltead384642008-12-26 10:20:07 +0000208 msg->l3h = (unsigned char *)oh + sizeof(*oh);
Harald Welte52b1f982008-12-23 20:25:15 +0000209
210 switch (oh->mdisc) {
211 case ABIS_OM_MDISC_FOM:
Harald Welte8470bf22008-12-25 23:28:35 +0000212 rc = abis_nm_rcvmsg_fom(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000213 break;
214 case ABIS_OM_MDISC_MMI:
215 case ABIS_OM_MDISC_TRAU:
216 case ABIS_OM_MDISC_MANUF:
217 default:
218 fprintf(stderr, "unknown ABIS OML message discriminator 0x%x\n",
219 oh->mdisc);
220 return -EINVAL;
221 }
222
Harald Weltead384642008-12-26 10:20:07 +0000223 msgb_free(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000224 return rc;
225}
226
227#if 0
228/* initialized all resources */
229struct abis_nm_h *abis_nm_init(struct abis_nm_cfg *cfg)
230{
231 struct abis_nm_h *nmh;
232
233 nmh = malloc(sizeof(*nmh));
234 if (!nmh)
235 return NULL;
236
237 nmh->cfg = cfg;
238
239 return nmh;
240}
241
242/* free all resources */
243void abis_nm_fini(struct abis_nm_h *nmh)
244{
245 free(nmh);
246}
247#endif
248
249/* Here we are trying to define a high-level API that can be used by
250 * the actual BSC implementation. However, the architecture is currently
251 * still under design. Ideally the calls to this API would be synchronous,
252 * while the underlying stack behind the APi runs in a traditional select
253 * based state machine.
254 */
255
256/* 6.2 Software Load: FIXME */
257
258
259#if 0
260struct abis_nm_sw {
261 /* this will become part of the SW LOAD INITIATE */
262 u_int8_t obj_class;
263 u_int8_t obj_instance[3];
264 u_int8_t sw_description[255];
265 u_int16_t window_size;
266 /* the actual data that is to be sent subsequently */
267 unsigned char *sw;
268 unsigned int sw_len;
269};
270
271/* Load the specified software into the BTS */
272int abis_nm_sw_load(struct abis_nm_h *h, struct abis_nm_sw *sw);
273{
274 /* FIXME: Implementation */
275}
276
277/* Activate the specified software into the BTS */
278int abis_nm_sw_activate(struct abis_nm_h *h)
279{
280
281}
282#endif
283
Harald Welte8470bf22008-12-25 23:28:35 +0000284static void fill_nm_channel(struct abis_nm_channel *ch, u_int8_t bts_port,
Harald Welte52b1f982008-12-23 20:25:15 +0000285 u_int8_t ts_nr, u_int8_t subslot_nr)
286{
287 ch->attrib = NM_ATT_CHANNEL;
288 ch->bts_port = bts_port;
289 ch->timeslot = ts_nr;
290 ch->subslot = subslot_nr;
291}
292
293int abis_nm_establish_tei(struct gsm_bts *bts, u_int8_t trx_nr,
294 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot,
295 u_int8_t tei)
296{
297 struct abis_om_hdr *oh;
298 struct abis_nm_channel *ch;
299 u_int8_t *tei_attr;
Harald Welte702d8702008-12-26 20:25:35 +0000300 u_int8_t len = sizeof(*ch) + 2;
Harald Welte8470bf22008-12-25 23:28:35 +0000301 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000302
303 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
304 fill_om_fom_hdr(oh, len, NM_MT_ESTABLISH_TEI, NM_OC_RADIO_CARRIER,
305 bts->bts_nr, trx_nr, 0xff);
306
Harald Welte8470bf22008-12-25 23:28:35 +0000307 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte52b1f982008-12-23 20:25:15 +0000308
309 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
310 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
311
312 return abis_nm_sendmsg(bts, msg);
313}
314
315/* connect signalling of one (BTS,TRX) to a particular timeslot on the E1 */
316int abis_nm_conn_terr_sign(struct gsm_bts_trx *trx,
317 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot)
318{
Harald Welte8470bf22008-12-25 23:28:35 +0000319 struct gsm_bts *bts = trx->bts;
Harald Welte52b1f982008-12-23 20:25:15 +0000320 struct abis_om_hdr *oh;
321 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +0000322 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000323
324 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +0000325 fill_om_fom_hdr(oh, sizeof(*oh), NM_MT_CONN_TERR_SIGN,
Harald Welte52b1f982008-12-23 20:25:15 +0000326 NM_OC_RADIO_CARRIER, bts->bts_nr, trx->nr, 0xff);
327
328 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
329 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
330
331 return abis_nm_sendmsg(bts, msg);
332}
333
334#if 0
335int abis_nm_disc_terr_sign(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
336 struct abis_nm_abis_channel *chan)
337{
338}
339#endif
340
341int abis_nm_conn_terr_traf(struct gsm_bts_trx_ts *ts,
342 u_int8_t e1_port, u_int8_t e1_timeslot,
343 u_int8_t e1_subslot)
344{
345 struct gsm_bts *bts = ts->trx->bts;
346 struct abis_om_hdr *oh;
347 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +0000348 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000349
350 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
351 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_TRAF,
352 NM_OC_BASEB_TRANSC, bts->bts_nr, ts->trx->nr, ts->nr);
353
354 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
355 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
356
357 return abis_nm_sendmsg(bts, msg);
358}
359
360#if 0
361int abis_nm_disc_terr_traf(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
362 struct abis_nm_abis_channel *chan,
363 u_int8_t subchan)
364{
365}
366#endif
367
368int abis_nm_set_channel_attr(struct gsm_bts_trx_ts *ts, u_int8_t chan_comb)
369{
370 struct gsm_bts *bts = ts->trx->bts;
371 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +0000372 u_int16_t arfcn = htons(ts->trx->arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +0000373 u_int8_t zero = 0x00;
Harald Welte8470bf22008-12-25 23:28:35 +0000374 struct msgb *msg = nm_msgb_alloc();
Harald Welte702d8702008-12-26 20:25:35 +0000375 u_int8_t len = 4 + 2 + 2 + 2 + 2 +3;
Harald Welte52b1f982008-12-23 20:25:15 +0000376
377 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +0000378 fill_om_fom_hdr(oh, len, NM_MT_SET_CHAN_ATTR,
Harald Welte52b1f982008-12-23 20:25:15 +0000379 NM_OC_BASEB_TRANSC, bts->bts_nr,
380 ts->trx->nr, ts->nr);
381 /* FIXME: don't send ARFCN list, hopping sequence, mAIO, ...*/
382 msgb_tlv16_put(msg, NM_ATT_ARFCN_LIST, 1, &arfcn);
383 msgb_tv_put(msg, NM_ATT_CHAN_COMB, chan_comb);
384 msgb_tv_put(msg, NM_ATT_HSN, 0x00);
385 msgb_tv_put(msg, NM_ATT_MAIO, 0x00);
386 msgb_tv_put(msg, NM_ATT_TSC, 0x07); /* training sequence */
387 msgb_tlv_put(msg, 0x59, 1, &zero);
388
389 return abis_nm_sendmsg(bts, msg);
390}
391
Harald Welte8470bf22008-12-25 23:28:35 +0000392int abis_nm_raw_msg(struct gsm_bts *bts, int len, u_int8_t *rawmsg)
Harald Welte52b1f982008-12-23 20:25:15 +0000393{
Harald Welte8470bf22008-12-25 23:28:35 +0000394 struct msgb *msg = nm_msgb_alloc();
395 struct abis_om_hdr *oh;
Harald Welte52b1f982008-12-23 20:25:15 +0000396 u_int8_t *data;
397
398 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
399 fill_om_hdr(oh, len);
400 data = msgb_put(msg, len);
Harald Weltead384642008-12-26 10:20:07 +0000401 memcpy(data, rawmsg, len);
Harald Welte52b1f982008-12-23 20:25:15 +0000402
403 return abis_nm_sendmsg(bts, msg);
404}
405
406/* Siemens specific commands */
407static int __simple_cmd(struct gsm_bts *bts, u_int8_t msg_type)
408{
409 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +0000410 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000411
412 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +0000413 fill_om_fom_hdr(oh, 0, msg_type, NM_OC_SITE_MANAGER,
Harald Welte52b1f982008-12-23 20:25:15 +0000414 0xff, 0xff, 0xff);
415
416 return abis_nm_sendmsg(bts, msg);
417}
418
419int abis_nm_event_reports(struct gsm_bts *bts, int on)
420{
421 if (on == 0)
422 return __simple_cmd(bts, 0x63);
423 else
424 return __simple_cmd(bts, 0x66);
425}
426
427int abis_nm_reset_resource(struct gsm_bts *bts)
428{
429 return __simple_cmd(bts, 0x74);
430}
431
Harald Weltead384642008-12-26 10:20:07 +0000432int abis_nm_db_transmission(struct gsm_bts *bts, int begin)
Harald Welte52b1f982008-12-23 20:25:15 +0000433{
434 if (begin)
435 return __simple_cmd(bts, 0xA3);
436 else
437 return __simple_cmd(bts, 0xA6);
438}