blob: e1a641b53451eafc57391ac19d95540d5def9350 [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
125 fill_om_hdr(oh, len);
126 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 Welte52b1f982008-12-23 20:25:15 +0000186
187 /* Various consistency checks */
188 if (oh->placement != ABIS_OM_PLACEMENT_ONLY) {
189 fprintf(stderr, "ABIS OML placement 0x%x not supported\n",
190 oh->placement);
191 return -EINVAL;
192 }
193 if (oh->sequence != 0) {
194 fprintf(stderr, "ABIS OML sequence 0x%x != 0x00\n",
195 oh->sequence);
196 return -EINVAL;
197 }
198 if (oh->length + sizeof(*oh) > l2_len) {
199 fprintf(stderr, "ABIS OML truncated message (%u > %u)\n",
200 oh->length + sizeof(*oh), l2_len);
201 return -EINVAL;
202 }
203 if (oh->length + sizeof(*oh) < l2_len)
204 fprintf(stderr, "ABIS OML message with extra trailer?!?\n");
205
Harald Weltead384642008-12-26 10:20:07 +0000206 msg->l3h = (unsigned char *)oh + sizeof(*oh);
Harald Welte52b1f982008-12-23 20:25:15 +0000207
208 switch (oh->mdisc) {
209 case ABIS_OM_MDISC_FOM:
Harald Welte8470bf22008-12-25 23:28:35 +0000210 rc = abis_nm_rcvmsg_fom(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000211 break;
212 case ABIS_OM_MDISC_MMI:
213 case ABIS_OM_MDISC_TRAU:
214 case ABIS_OM_MDISC_MANUF:
215 default:
216 fprintf(stderr, "unknown ABIS OML message discriminator 0x%x\n",
217 oh->mdisc);
218 return -EINVAL;
219 }
220
Harald Weltead384642008-12-26 10:20:07 +0000221 msgb_free(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000222 return rc;
223}
224
225#if 0
226/* initialized all resources */
227struct abis_nm_h *abis_nm_init(struct abis_nm_cfg *cfg)
228{
229 struct abis_nm_h *nmh;
230
231 nmh = malloc(sizeof(*nmh));
232 if (!nmh)
233 return NULL;
234
235 nmh->cfg = cfg;
236
237 return nmh;
238}
239
240/* free all resources */
241void abis_nm_fini(struct abis_nm_h *nmh)
242{
243 free(nmh);
244}
245#endif
246
247/* Here we are trying to define a high-level API that can be used by
248 * the actual BSC implementation. However, the architecture is currently
249 * still under design. Ideally the calls to this API would be synchronous,
250 * while the underlying stack behind the APi runs in a traditional select
251 * based state machine.
252 */
253
254/* 6.2 Software Load: FIXME */
255
256
257#if 0
258struct abis_nm_sw {
259 /* this will become part of the SW LOAD INITIATE */
260 u_int8_t obj_class;
261 u_int8_t obj_instance[3];
262 u_int8_t sw_description[255];
263 u_int16_t window_size;
264 /* the actual data that is to be sent subsequently */
265 unsigned char *sw;
266 unsigned int sw_len;
267};
268
269/* Load the specified software into the BTS */
270int abis_nm_sw_load(struct abis_nm_h *h, struct abis_nm_sw *sw);
271{
272 /* FIXME: Implementation */
273}
274
275/* Activate the specified software into the BTS */
276int abis_nm_sw_activate(struct abis_nm_h *h)
277{
278
279}
280#endif
281
Harald Welte8470bf22008-12-25 23:28:35 +0000282static void fill_nm_channel(struct abis_nm_channel *ch, u_int8_t bts_port,
Harald Welte52b1f982008-12-23 20:25:15 +0000283 u_int8_t ts_nr, u_int8_t subslot_nr)
284{
285 ch->attrib = NM_ATT_CHANNEL;
286 ch->bts_port = bts_port;
287 ch->timeslot = ts_nr;
288 ch->subslot = subslot_nr;
289}
290
291int abis_nm_establish_tei(struct gsm_bts *bts, u_int8_t trx_nr,
292 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot,
293 u_int8_t tei)
294{
295 struct abis_om_hdr *oh;
296 struct abis_nm_channel *ch;
297 u_int8_t *tei_attr;
298 u_int8_t len = 2 + sizeof(*ch);
Harald Welte8470bf22008-12-25 23:28:35 +0000299 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000300
301 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
302 fill_om_fom_hdr(oh, len, NM_MT_ESTABLISH_TEI, NM_OC_RADIO_CARRIER,
303 bts->bts_nr, trx_nr, 0xff);
304
Harald Welte8470bf22008-12-25 23:28:35 +0000305 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte52b1f982008-12-23 20:25:15 +0000306
307 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
308 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
309
310 return abis_nm_sendmsg(bts, msg);
311}
312
313/* connect signalling of one (BTS,TRX) to a particular timeslot on the E1 */
314int abis_nm_conn_terr_sign(struct gsm_bts_trx *trx,
315 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot)
316{
Harald Welte8470bf22008-12-25 23:28:35 +0000317 struct gsm_bts *bts = trx->bts;
Harald Welte52b1f982008-12-23 20:25:15 +0000318 struct abis_om_hdr *oh;
319 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +0000320 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000321
322 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
323 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_SIGN,
324 NM_OC_RADIO_CARRIER, bts->bts_nr, trx->nr, 0xff);
325
326 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
327 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
328
329 return abis_nm_sendmsg(bts, msg);
330}
331
332#if 0
333int abis_nm_disc_terr_sign(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
334 struct abis_nm_abis_channel *chan)
335{
336}
337#endif
338
339int abis_nm_conn_terr_traf(struct gsm_bts_trx_ts *ts,
340 u_int8_t e1_port, u_int8_t e1_timeslot,
341 u_int8_t e1_subslot)
342{
343 struct gsm_bts *bts = ts->trx->bts;
344 struct abis_om_hdr *oh;
345 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +0000346 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000347
348 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
349 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_TRAF,
350 NM_OC_BASEB_TRANSC, bts->bts_nr, ts->trx->nr, ts->nr);
351
352 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
353 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
354
355 return abis_nm_sendmsg(bts, msg);
356}
357
358#if 0
359int abis_nm_disc_terr_traf(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
360 struct abis_nm_abis_channel *chan,
361 u_int8_t subchan)
362{
363}
364#endif
365
366int abis_nm_set_channel_attr(struct gsm_bts_trx_ts *ts, u_int8_t chan_comb)
367{
368 struct gsm_bts *bts = ts->trx->bts;
369 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +0000370 u_int16_t arfcn = htons(ts->trx->arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +0000371 u_int8_t zero = 0x00;
Harald Welte8470bf22008-12-25 23:28:35 +0000372 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000373
374 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte8470bf22008-12-25 23:28:35 +0000375 fill_om_fom_hdr(oh, sizeof(*oh), NM_MT_SET_CHAN_ATTR,
Harald Welte52b1f982008-12-23 20:25:15 +0000376 NM_OC_BASEB_TRANSC, bts->bts_nr,
377 ts->trx->nr, ts->nr);
378 /* FIXME: don't send ARFCN list, hopping sequence, mAIO, ...*/
379 msgb_tlv16_put(msg, NM_ATT_ARFCN_LIST, 1, &arfcn);
380 msgb_tv_put(msg, NM_ATT_CHAN_COMB, chan_comb);
381 msgb_tv_put(msg, NM_ATT_HSN, 0x00);
382 msgb_tv_put(msg, NM_ATT_MAIO, 0x00);
383 msgb_tv_put(msg, NM_ATT_TSC, 0x07); /* training sequence */
384 msgb_tlv_put(msg, 0x59, 1, &zero);
385
386 return abis_nm_sendmsg(bts, msg);
387}
388
Harald Welte8470bf22008-12-25 23:28:35 +0000389int abis_nm_raw_msg(struct gsm_bts *bts, int len, u_int8_t *rawmsg)
Harald Welte52b1f982008-12-23 20:25:15 +0000390{
Harald Welte8470bf22008-12-25 23:28:35 +0000391 struct msgb *msg = nm_msgb_alloc();
392 struct abis_om_hdr *oh;
Harald Welte52b1f982008-12-23 20:25:15 +0000393 u_int8_t *data;
394
395 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
396 fill_om_hdr(oh, len);
397 data = msgb_put(msg, len);
Harald Weltead384642008-12-26 10:20:07 +0000398 memcpy(data, rawmsg, len);
Harald Welte52b1f982008-12-23 20:25:15 +0000399
400 return abis_nm_sendmsg(bts, msg);
401}
402
403/* Siemens specific commands */
404static int __simple_cmd(struct gsm_bts *bts, u_int8_t msg_type)
405{
406 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +0000407 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000408
409 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte8470bf22008-12-25 23:28:35 +0000410 fill_om_fom_hdr(oh, sizeof(*oh), msg_type, NM_OC_SITE_MANAGER,
Harald Welte52b1f982008-12-23 20:25:15 +0000411 0xff, 0xff, 0xff);
412
413 return abis_nm_sendmsg(bts, msg);
414}
415
416int abis_nm_event_reports(struct gsm_bts *bts, int on)
417{
418 if (on == 0)
419 return __simple_cmd(bts, 0x63);
420 else
421 return __simple_cmd(bts, 0x66);
422}
423
424int abis_nm_reset_resource(struct gsm_bts *bts)
425{
426 return __simple_cmd(bts, 0x74);
427}
428
Harald Weltead384642008-12-26 10:20:07 +0000429int abis_nm_db_transmission(struct gsm_bts *bts, int begin)
Harald Welte52b1f982008-12-23 20:25:15 +0000430{
431 if (begin)
432 return __simple_cmd(bts, 0xA3);
433 else
434 return __simple_cmd(bts, 0xA6);
435}