blob: bf442fa43e9c907fb48a2903a5d84e0f488d4fba [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{
141 /* FIXME */
142}
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)) {
152 nmh->cfg->report_cb(mb, foh);
153 return 0;
154 }
155
156 /* check if last message is to be acked */
157 if (is_ack_nack(nmh->last_msgtype)) {
158 if (mt == MT_ACK(nmh->last_msgtype)) {
159 fprintf(stderr, "received ACK (0x%x)\n",
160 foh->msg_type);
161 /* we got our ACK, continue sending the next msg */
162 } else if (mt == MT_NACK(nmh->last_msgtype)) {
163 /* we got a NACK, signal this to the caller */
164 fprintf(stderr, "received NACK (0x%x)\n",
165 foh->msg_type);
166 /* FIXME: somehow signal this to the caller */
167 } else {
168 /* really strange things happen */
169 return -EINVAL;
170 }
171 }
172}
173
174/* High-Level API */
175/* Entry-point where L2 OML from BTS enters the NM code */
Harald Welte8470bf22008-12-25 23:28:35 +0000176int abis_nm_rcvmsg(struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +0000177{
178 int rc;
179 struct abis_om_hdr *oh = msgb_l2(msg);
Harald Welte8470bf22008-12-25 23:28:35 +0000180 unsigned int l2_len = msg->tail - (u_int8_t *)msgb_l2(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000181
182 /* Various consistency checks */
183 if (oh->placement != ABIS_OM_PLACEMENT_ONLY) {
184 fprintf(stderr, "ABIS OML placement 0x%x not supported\n",
185 oh->placement);
186 return -EINVAL;
187 }
188 if (oh->sequence != 0) {
189 fprintf(stderr, "ABIS OML sequence 0x%x != 0x00\n",
190 oh->sequence);
191 return -EINVAL;
192 }
193 if (oh->length + sizeof(*oh) > l2_len) {
194 fprintf(stderr, "ABIS OML truncated message (%u > %u)\n",
195 oh->length + sizeof(*oh), l2_len);
196 return -EINVAL;
197 }
198 if (oh->length + sizeof(*oh) < l2_len)
199 fprintf(stderr, "ABIS OML message with extra trailer?!?\n");
200
201 msg->l3_off = ((unsigned char *)oh + sizeof(*oh)) - msg->head;
202
203 switch (oh->mdisc) {
204 case ABIS_OM_MDISC_FOM:
Harald Welte8470bf22008-12-25 23:28:35 +0000205 rc = abis_nm_rcvmsg_fom(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000206 break;
207 case ABIS_OM_MDISC_MMI:
208 case ABIS_OM_MDISC_TRAU:
209 case ABIS_OM_MDISC_MANUF:
210 default:
211 fprintf(stderr, "unknown ABIS OML message discriminator 0x%x\n",
212 oh->mdisc);
213 return -EINVAL;
214 }
215
216 return rc;
217}
218
219#if 0
220/* initialized all resources */
221struct abis_nm_h *abis_nm_init(struct abis_nm_cfg *cfg)
222{
223 struct abis_nm_h *nmh;
224
225 nmh = malloc(sizeof(*nmh));
226 if (!nmh)
227 return NULL;
228
229 nmh->cfg = cfg;
230
231 return nmh;
232}
233
234/* free all resources */
235void abis_nm_fini(struct abis_nm_h *nmh)
236{
237 free(nmh);
238}
239#endif
240
241/* Here we are trying to define a high-level API that can be used by
242 * the actual BSC implementation. However, the architecture is currently
243 * still under design. Ideally the calls to this API would be synchronous,
244 * while the underlying stack behind the APi runs in a traditional select
245 * based state machine.
246 */
247
248/* 6.2 Software Load: FIXME */
249
250
251#if 0
252struct abis_nm_sw {
253 /* this will become part of the SW LOAD INITIATE */
254 u_int8_t obj_class;
255 u_int8_t obj_instance[3];
256 u_int8_t sw_description[255];
257 u_int16_t window_size;
258 /* the actual data that is to be sent subsequently */
259 unsigned char *sw;
260 unsigned int sw_len;
261};
262
263/* Load the specified software into the BTS */
264int abis_nm_sw_load(struct abis_nm_h *h, struct abis_nm_sw *sw);
265{
266 /* FIXME: Implementation */
267}
268
269/* Activate the specified software into the BTS */
270int abis_nm_sw_activate(struct abis_nm_h *h)
271{
272
273}
274#endif
275
Harald Welte8470bf22008-12-25 23:28:35 +0000276static void fill_nm_channel(struct abis_nm_channel *ch, u_int8_t bts_port,
Harald Welte52b1f982008-12-23 20:25:15 +0000277 u_int8_t ts_nr, u_int8_t subslot_nr)
278{
279 ch->attrib = NM_ATT_CHANNEL;
280 ch->bts_port = bts_port;
281 ch->timeslot = ts_nr;
282 ch->subslot = subslot_nr;
283}
284
285int abis_nm_establish_tei(struct gsm_bts *bts, u_int8_t trx_nr,
286 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot,
287 u_int8_t tei)
288{
289 struct abis_om_hdr *oh;
290 struct abis_nm_channel *ch;
291 u_int8_t *tei_attr;
292 u_int8_t len = 2 + sizeof(*ch);
Harald Welte8470bf22008-12-25 23:28:35 +0000293 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000294
295 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
296 fill_om_fom_hdr(oh, len, NM_MT_ESTABLISH_TEI, NM_OC_RADIO_CARRIER,
297 bts->bts_nr, trx_nr, 0xff);
298
Harald Welte8470bf22008-12-25 23:28:35 +0000299 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte52b1f982008-12-23 20:25:15 +0000300
301 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
302 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
303
304 return abis_nm_sendmsg(bts, msg);
305}
306
307/* connect signalling of one (BTS,TRX) to a particular timeslot on the E1 */
308int abis_nm_conn_terr_sign(struct gsm_bts_trx *trx,
309 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot)
310{
Harald Welte8470bf22008-12-25 23:28:35 +0000311 struct gsm_bts *bts = trx->bts;
Harald Welte52b1f982008-12-23 20:25:15 +0000312 struct abis_om_hdr *oh;
313 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +0000314 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000315
316 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
317 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_SIGN,
318 NM_OC_RADIO_CARRIER, bts->bts_nr, trx->nr, 0xff);
319
320 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
321 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
322
323 return abis_nm_sendmsg(bts, msg);
324}
325
326#if 0
327int abis_nm_disc_terr_sign(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
328 struct abis_nm_abis_channel *chan)
329{
330}
331#endif
332
333int abis_nm_conn_terr_traf(struct gsm_bts_trx_ts *ts,
334 u_int8_t e1_port, u_int8_t e1_timeslot,
335 u_int8_t e1_subslot)
336{
337 struct gsm_bts *bts = ts->trx->bts;
338 struct abis_om_hdr *oh;
339 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +0000340 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000341
342 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
343 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_TRAF,
344 NM_OC_BASEB_TRANSC, bts->bts_nr, ts->trx->nr, ts->nr);
345
346 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
347 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
348
349 return abis_nm_sendmsg(bts, msg);
350}
351
352#if 0
353int abis_nm_disc_terr_traf(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
354 struct abis_nm_abis_channel *chan,
355 u_int8_t subchan)
356{
357}
358#endif
359
360int abis_nm_set_channel_attr(struct gsm_bts_trx_ts *ts, u_int8_t chan_comb)
361{
362 struct gsm_bts *bts = ts->trx->bts;
363 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +0000364 u_int16_t arfcn = htons(ts->trx->arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +0000365 u_int8_t zero = 0x00;
Harald Welte8470bf22008-12-25 23:28:35 +0000366 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000367
368 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte8470bf22008-12-25 23:28:35 +0000369 fill_om_fom_hdr(oh, sizeof(*oh), NM_MT_SET_CHAN_ATTR,
Harald Welte52b1f982008-12-23 20:25:15 +0000370 NM_OC_BASEB_TRANSC, bts->bts_nr,
371 ts->trx->nr, ts->nr);
372 /* FIXME: don't send ARFCN list, hopping sequence, mAIO, ...*/
373 msgb_tlv16_put(msg, NM_ATT_ARFCN_LIST, 1, &arfcn);
374 msgb_tv_put(msg, NM_ATT_CHAN_COMB, chan_comb);
375 msgb_tv_put(msg, NM_ATT_HSN, 0x00);
376 msgb_tv_put(msg, NM_ATT_MAIO, 0x00);
377 msgb_tv_put(msg, NM_ATT_TSC, 0x07); /* training sequence */
378 msgb_tlv_put(msg, 0x59, 1, &zero);
379
380 return abis_nm_sendmsg(bts, msg);
381}
382
Harald Welte8470bf22008-12-25 23:28:35 +0000383int abis_nm_raw_msg(struct gsm_bts *bts, int len, u_int8_t *rawmsg)
Harald Welte52b1f982008-12-23 20:25:15 +0000384{
Harald Welte8470bf22008-12-25 23:28:35 +0000385 struct msgb *msg = nm_msgb_alloc();
386 struct abis_om_hdr *oh;
Harald Welte52b1f982008-12-23 20:25:15 +0000387 u_int8_t *data;
388
389 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
390 fill_om_hdr(oh, len);
391 data = msgb_put(msg, len);
Harald Welte8470bf22008-12-25 23:28:35 +0000392 memcpy(msg->data, rawmsg, len);
Harald Welte52b1f982008-12-23 20:25:15 +0000393
394 return abis_nm_sendmsg(bts, msg);
395}
396
397/* Siemens specific commands */
398static int __simple_cmd(struct gsm_bts *bts, u_int8_t msg_type)
399{
400 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +0000401 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000402
403 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte8470bf22008-12-25 23:28:35 +0000404 fill_om_fom_hdr(oh, sizeof(*oh), msg_type, NM_OC_SITE_MANAGER,
Harald Welte52b1f982008-12-23 20:25:15 +0000405 0xff, 0xff, 0xff);
406
407 return abis_nm_sendmsg(bts, msg);
408}
409
410int abis_nm_event_reports(struct gsm_bts *bts, int on)
411{
412 if (on == 0)
413 return __simple_cmd(bts, 0x63);
414 else
415 return __simple_cmd(bts, 0x66);
416}
417
418int abis_nm_reset_resource(struct gsm_bts *bts)
419{
420 return __simple_cmd(bts, 0x74);
421}
422
423int abis_nm_db_transaction(struct gsm_bts *bts, int begin)
424{
425 if (begin)
426 return __simple_cmd(bts, 0xA3);
427 else
428 return __simple_cmd(bts, 0xA6);
429}