Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1 | /* 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> |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along |
| 18 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | |
| 24 | #include <errno.h> |
| 25 | #include <stdio.h> |
| 26 | #include <sys/types.h> |
| 27 | |
| 28 | #include "gsm_data.h" |
| 29 | #include "debug.h" |
| 30 | #include "msgb.h" |
| 31 | #include "abis_nm.h" |
| 32 | |
| 33 | #define OM_ALLOC_SIZE 1024 |
| 34 | |
| 35 | /* unidirectional messages from BTS to BSC */ |
| 36 | static const enum abis_nm_msgtype reports[] = { |
| 37 | NM_MT_SW_ACTIVATED_REP, |
| 38 | NM_MT_TEST_REP, |
| 39 | NM_MT_STATECHG_EVENT_REP, |
| 40 | NM_MT_FAILURE_EVENT_REP, |
| 41 | }; |
| 42 | |
| 43 | /* messages without ACK/NACK */ |
| 44 | static const enum abis_nm_msgtype no_ack_nack[] = { |
| 45 | NM_MT_MEAS_RES_REQ, |
| 46 | NM_MT_STOP_MEAS, |
| 47 | NM_MT_START_MEAS, |
| 48 | }; |
| 49 | |
| 50 | /* Attributes that the BSC can set, not only get, according to Section 9.4 */ |
| 51 | static const enum abis_nm_attr nm_att_settable[] = { |
| 52 | NM_ATT_ADD_INFO, |
| 53 | NM_ATT_ADD_TEXT, |
| 54 | NM_ATT_DEST, |
| 55 | NM_ATT_EVENT_TYPE, |
| 56 | NM_ATT_FILE_DATA, |
| 57 | NM_ATT_GET_ARI, |
| 58 | NM_ATT_HW_CONF_CHG, |
| 59 | NM_ATT_LIST_REQ_ATTR, |
| 60 | NM_ATT_MDROP_LINK, |
| 61 | NM_ATT_MDROP_NEXT, |
| 62 | NM_ATT_NACK_CAUSES, |
| 63 | NM_ATT_OUTST_ALARM, |
| 64 | NM_ATT_PHYS_CONF, |
| 65 | NM_ATT_PROB_CAUSE, |
| 66 | NM_ATT_RAD_SUBC, |
| 67 | NM_ATT_SOURCE, |
| 68 | NM_ATT_SPEC_PROB, |
| 69 | NM_ATT_START_TIME, |
| 70 | NM_ATT_TEST_DUR, |
| 71 | NM_ATT_TEST_NO, |
| 72 | NM_ATT_TEST_REPORT, |
| 73 | NM_ATT_WINDOW_SIZE, |
| 74 | NM_ATT_SEVERITY, |
| 75 | NM_ATT_MEAS_RES, |
| 76 | NM_ATT_MEAS_TYPE, |
| 77 | }; |
| 78 | |
| 79 | static int is_in_arr(enum abis_nm_msgtype mt, const enum abis_nm_msgtype *arr, int size) |
| 80 | { |
| 81 | int i; |
| 82 | |
| 83 | for (i = 0; i < size; i++) { |
| 84 | if (arr[i] == mt) |
| 85 | return 1; |
| 86 | } |
| 87 | |
| 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | /* is this msgtype the usual ACK/NACK type ? */ |
| 92 | static int is_ack_nack(enum abis_nm_msgtype mt) |
| 93 | { |
| 94 | return !is_in_arr(mt, no_ack_nack, ARRAY_SIZE(no_ack_nack)); |
| 95 | } |
| 96 | |
| 97 | /* is this msgtype a report ? */ |
| 98 | static int is_report(enum abis_nm_msgtype mt) |
| 99 | { |
| 100 | return is_in_arr(mt, reports, ARRA_YSIZE(reports)); |
| 101 | } |
| 102 | |
| 103 | #define MT_ACK(x) (x+1) |
| 104 | #define MT_NACK(x) (x+2) |
| 105 | |
| 106 | static void fill_om_hdr(struct abis_om_hdr *oh, u_int8_t len) |
| 107 | { |
| 108 | oh->mdisc = ABIS_OM_MDISC_FOM; |
| 109 | oh->placement = ABIS_OM_PLACEMENT_ONLY; |
| 110 | oh->sequence = 0; |
| 111 | oh->length = len; |
| 112 | } |
| 113 | |
| 114 | static void fill_om_fom_hdr(struct abis_om_hdr *oh, u_int8_t len, |
| 115 | u_int8_t msg_type, u_int8_t obj_class, |
| 116 | u_int8_t bts_nr, u_int8_t trx_nr, u_int8_t ts_nr) |
| 117 | { |
| 118 | struct abis_om_fom_hdr *foh = |
| 119 | (struct abis_om_fom_hdr *) oh->data; |
| 120 | |
| 121 | fill_om_hdr(oh, len); |
| 122 | foh->msg_type = msg_type; |
| 123 | foh->obj_class = obj_class; |
| 124 | foh->obj_inst.bts_nr = bts_nr; |
| 125 | foh->obj_inst.trx_nr = trx_nr; |
| 126 | foh->obj_inst.ts_nr = ts_nr; |
| 127 | } |
| 128 | |
| 129 | /* Send a OML NM Message from BSC to BTS */ |
| 130 | int abis_nm_sendmsg(struct gsm_bts *bts, struct msgb *msg) |
| 131 | { |
| 132 | /* FIXME */ |
| 133 | } |
| 134 | |
| 135 | /* Receive a OML NM Message from BTS */ |
| 136 | static int abis_nm_rcvmsg(struct msgb *mb) |
| 137 | { |
| 138 | struct abis_om_fom_hdr *foh = msgb_l3(mb); |
| 139 | u_int8_t mt = foh->msg_type; |
| 140 | |
| 141 | /* check for unsolicited message */ |
| 142 | if (is_report(mt)) { |
| 143 | nmh->cfg->report_cb(mb, foh); |
| 144 | return 0; |
| 145 | } |
| 146 | |
| 147 | /* check if last message is to be acked */ |
| 148 | if (is_ack_nack(nmh->last_msgtype)) { |
| 149 | if (mt == MT_ACK(nmh->last_msgtype)) { |
| 150 | fprintf(stderr, "received ACK (0x%x)\n", |
| 151 | foh->msg_type); |
| 152 | /* we got our ACK, continue sending the next msg */ |
| 153 | } else if (mt == MT_NACK(nmh->last_msgtype)) { |
| 154 | /* we got a NACK, signal this to the caller */ |
| 155 | fprintf(stderr, "received NACK (0x%x)\n", |
| 156 | foh->msg_type); |
| 157 | /* FIXME: somehow signal this to the caller */ |
| 158 | } else { |
| 159 | /* really strange things happen */ |
| 160 | return -EINVAL; |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | /* High-Level API */ |
| 166 | /* Entry-point where L2 OML from BTS enters the NM code */ |
| 167 | int abis_nm_rx(struct msgb *msg) |
| 168 | { |
| 169 | int rc; |
| 170 | struct abis_om_hdr *oh = msgb_l2(msg); |
| 171 | unsigned int l2_len = msg->tail - msg_l2(msg); |
| 172 | |
| 173 | /* Various consistency checks */ |
| 174 | if (oh->placement != ABIS_OM_PLACEMENT_ONLY) { |
| 175 | fprintf(stderr, "ABIS OML placement 0x%x not supported\n", |
| 176 | oh->placement); |
| 177 | return -EINVAL; |
| 178 | } |
| 179 | if (oh->sequence != 0) { |
| 180 | fprintf(stderr, "ABIS OML sequence 0x%x != 0x00\n", |
| 181 | oh->sequence); |
| 182 | return -EINVAL; |
| 183 | } |
| 184 | if (oh->length + sizeof(*oh) > l2_len) { |
| 185 | fprintf(stderr, "ABIS OML truncated message (%u > %u)\n", |
| 186 | oh->length + sizeof(*oh), l2_len); |
| 187 | return -EINVAL; |
| 188 | } |
| 189 | if (oh->length + sizeof(*oh) < l2_len) |
| 190 | fprintf(stderr, "ABIS OML message with extra trailer?!?\n"); |
| 191 | |
| 192 | msg->l3_off = ((unsigned char *)oh + sizeof(*oh)) - msg->head; |
| 193 | |
| 194 | switch (oh->mdisc) { |
| 195 | case ABIS_OM_MDISC_FOM: |
| 196 | rc = abis_nm_rcvmsg(msg); |
| 197 | break; |
| 198 | case ABIS_OM_MDISC_MMI: |
| 199 | case ABIS_OM_MDISC_TRAU: |
| 200 | case ABIS_OM_MDISC_MANUF: |
| 201 | default: |
| 202 | fprintf(stderr, "unknown ABIS OML message discriminator 0x%x\n", |
| 203 | oh->mdisc); |
| 204 | return -EINVAL; |
| 205 | } |
| 206 | |
| 207 | return rc; |
| 208 | } |
| 209 | |
| 210 | #if 0 |
| 211 | /* initialized all resources */ |
| 212 | struct abis_nm_h *abis_nm_init(struct abis_nm_cfg *cfg) |
| 213 | { |
| 214 | struct abis_nm_h *nmh; |
| 215 | |
| 216 | nmh = malloc(sizeof(*nmh)); |
| 217 | if (!nmh) |
| 218 | return NULL; |
| 219 | |
| 220 | nmh->cfg = cfg; |
| 221 | |
| 222 | return nmh; |
| 223 | } |
| 224 | |
| 225 | /* free all resources */ |
| 226 | void abis_nm_fini(struct abis_nm_h *nmh) |
| 227 | { |
| 228 | free(nmh); |
| 229 | } |
| 230 | #endif |
| 231 | |
| 232 | /* Here we are trying to define a high-level API that can be used by |
| 233 | * the actual BSC implementation. However, the architecture is currently |
| 234 | * still under design. Ideally the calls to this API would be synchronous, |
| 235 | * while the underlying stack behind the APi runs in a traditional select |
| 236 | * based state machine. |
| 237 | */ |
| 238 | |
| 239 | /* 6.2 Software Load: FIXME */ |
| 240 | |
| 241 | |
| 242 | #if 0 |
| 243 | struct abis_nm_sw { |
| 244 | /* this will become part of the SW LOAD INITIATE */ |
| 245 | u_int8_t obj_class; |
| 246 | u_int8_t obj_instance[3]; |
| 247 | u_int8_t sw_description[255]; |
| 248 | u_int16_t window_size; |
| 249 | /* the actual data that is to be sent subsequently */ |
| 250 | unsigned char *sw; |
| 251 | unsigned int sw_len; |
| 252 | }; |
| 253 | |
| 254 | /* Load the specified software into the BTS */ |
| 255 | int abis_nm_sw_load(struct abis_nm_h *h, struct abis_nm_sw *sw); |
| 256 | { |
| 257 | /* FIXME: Implementation */ |
| 258 | } |
| 259 | |
| 260 | /* Activate the specified software into the BTS */ |
| 261 | int abis_nm_sw_activate(struct abis_nm_h *h) |
| 262 | { |
| 263 | |
| 264 | } |
| 265 | #endif |
| 266 | |
| 267 | static fill_nm_channel(struct abis_nm_channel *ch, u_int8_t bts_port, |
| 268 | u_int8_t ts_nr, u_int8_t subslot_nr) |
| 269 | { |
| 270 | ch->attrib = NM_ATT_CHANNEL; |
| 271 | ch->bts_port = bts_port; |
| 272 | ch->timeslot = ts_nr; |
| 273 | ch->subslot = subslot_nr; |
| 274 | } |
| 275 | |
| 276 | int abis_nm_establish_tei(struct gsm_bts *bts, u_int8_t trx_nr, |
| 277 | u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot, |
| 278 | u_int8_t tei) |
| 279 | { |
| 280 | struct abis_om_hdr *oh; |
| 281 | struct abis_nm_channel *ch; |
| 282 | u_int8_t *tei_attr; |
| 283 | u_int8_t len = 2 + sizeof(*ch); |
| 284 | struct mgsb *msg = msgb_alloc(OM_ALLOC_SIZE); |
| 285 | |
| 286 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 287 | fill_om_fom_hdr(oh, len, NM_MT_ESTABLISH_TEI, NM_OC_RADIO_CARRIER, |
| 288 | bts->bts_nr, trx_nr, 0xff); |
| 289 | |
| 290 | msgb_tv_put(msgb, NM_ATT_TEI, tei); |
| 291 | |
| 292 | ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch)); |
| 293 | fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot); |
| 294 | |
| 295 | return abis_nm_sendmsg(bts, msg); |
| 296 | } |
| 297 | |
| 298 | /* connect signalling of one (BTS,TRX) to a particular timeslot on the E1 */ |
| 299 | int abis_nm_conn_terr_sign(struct gsm_bts_trx *trx, |
| 300 | u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot) |
| 301 | { |
| 302 | struct gsm_bts *bts = ts->trx->bts; |
| 303 | struct abis_om_hdr *oh; |
| 304 | struct abis_nm_channel *ch; |
| 305 | struct mgsb *msg = msgb_alloc(OM_ALLOC_SIZE); |
| 306 | |
| 307 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 308 | fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_SIGN, |
| 309 | NM_OC_RADIO_CARRIER, bts->bts_nr, trx->nr, 0xff); |
| 310 | |
| 311 | ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch)); |
| 312 | fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot); |
| 313 | |
| 314 | return abis_nm_sendmsg(bts, msg); |
| 315 | } |
| 316 | |
| 317 | #if 0 |
| 318 | int abis_nm_disc_terr_sign(struct abis_nm_h *h, struct abis_om_obj_inst *inst, |
| 319 | struct abis_nm_abis_channel *chan) |
| 320 | { |
| 321 | } |
| 322 | #endif |
| 323 | |
| 324 | int abis_nm_conn_terr_traf(struct gsm_bts_trx_ts *ts, |
| 325 | u_int8_t e1_port, u_int8_t e1_timeslot, |
| 326 | u_int8_t e1_subslot) |
| 327 | { |
| 328 | struct gsm_bts *bts = ts->trx->bts; |
| 329 | struct abis_om_hdr *oh; |
| 330 | struct abis_nm_channel *ch; |
| 331 | struct msgb *msg = msgb_alloc(OM_ALLOC_SIZE); |
| 332 | |
| 333 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 334 | fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_TRAF, |
| 335 | NM_OC_BASEB_TRANSC, bts->bts_nr, ts->trx->nr, ts->nr); |
| 336 | |
| 337 | ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch)); |
| 338 | fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot); |
| 339 | |
| 340 | return abis_nm_sendmsg(bts, msg); |
| 341 | } |
| 342 | |
| 343 | #if 0 |
| 344 | int abis_nm_disc_terr_traf(struct abis_nm_h *h, struct abis_om_obj_inst *inst, |
| 345 | struct abis_nm_abis_channel *chan, |
| 346 | u_int8_t subchan) |
| 347 | { |
| 348 | } |
| 349 | #endif |
| 350 | |
| 351 | int abis_nm_set_channel_attr(struct gsm_bts_trx_ts *ts, u_int8_t chan_comb) |
| 352 | { |
| 353 | struct gsm_bts *bts = ts->trx->bts; |
| 354 | struct abis_om_hdr *oh; |
| 355 | u_int8_t arfcn = htons(ts->trx->arfcn); |
| 356 | u_int8_t zero = 0x00; |
| 357 | struct msgb *msg = msgb_alloc(OM_ALLOC_SIZE); |
| 358 | |
| 359 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 360 | fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_SET_CHAN_ATTR, |
| 361 | NM_OC_BASEB_TRANSC, bts->bts_nr, |
| 362 | ts->trx->nr, ts->nr); |
| 363 | /* FIXME: don't send ARFCN list, hopping sequence, mAIO, ...*/ |
| 364 | msgb_tlv16_put(msg, NM_ATT_ARFCN_LIST, 1, &arfcn); |
| 365 | msgb_tv_put(msg, NM_ATT_CHAN_COMB, chan_comb); |
| 366 | msgb_tv_put(msg, NM_ATT_HSN, 0x00); |
| 367 | msgb_tv_put(msg, NM_ATT_MAIO, 0x00); |
| 368 | msgb_tv_put(msg, NM_ATT_TSC, 0x07); /* training sequence */ |
| 369 | msgb_tlv_put(msg, 0x59, 1, &zero); |
| 370 | |
| 371 | return abis_nm_sendmsg(bts, msg); |
| 372 | } |
| 373 | |
| 374 | int abis_nm_raw_msg(struct gsm_bts *bts, int len, u_int8_t *msg) |
| 375 | { |
| 376 | struct msgb *msg = msgb_alloc(OM_ALLOC_SIZE); |
| 377 | u_int8_t *data; |
| 378 | |
| 379 | oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh)); |
| 380 | fill_om_hdr(oh, len); |
| 381 | data = msgb_put(msg, len); |
| 382 | memcpy(msgb->data, msg, len); |
| 383 | |
| 384 | return abis_nm_sendmsg(bts, msg); |
| 385 | } |
| 386 | |
| 387 | /* Siemens specific commands */ |
| 388 | static int __simple_cmd(struct gsm_bts *bts, u_int8_t msg_type) |
| 389 | { |
| 390 | struct abis_om_hdr *oh; |
| 391 | struct msg = msgb_alloc(OM_ALLOC_SIZE); |
| 392 | |
| 393 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 394 | fill_om_fom_hdr(oh, sizeof(*ch), msg_type, NM_OC_SITE_MANAGER, |
| 395 | 0xff, 0xff, 0xff); |
| 396 | |
| 397 | return abis_nm_sendmsg(bts, msg); |
| 398 | } |
| 399 | |
| 400 | int abis_nm_event_reports(struct gsm_bts *bts, int on) |
| 401 | { |
| 402 | if (on == 0) |
| 403 | return __simple_cmd(bts, 0x63); |
| 404 | else |
| 405 | return __simple_cmd(bts, 0x66); |
| 406 | } |
| 407 | |
| 408 | int abis_nm_reset_resource(struct gsm_bts *bts) |
| 409 | { |
| 410 | return __simple_cmd(bts, 0x74); |
| 411 | } |
| 412 | |
| 413 | int abis_nm_db_transaction(struct gsm_bts *bts, int begin) |
| 414 | { |
| 415 | if (begin) |
| 416 | return __simple_cmd(bts, 0xA3); |
| 417 | else |
| 418 | return __simple_cmd(bts, 0xA6); |
| 419 | } |