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 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 4 | /* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 5 | * |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 6 | * 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 Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 26 | #include <unistd.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 27 | #include <stdio.h> |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 28 | #include <fcntl.h> |
| 29 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 30 | #include <sys/types.h> |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 31 | #include <sys/stat.h> |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 32 | #include <netinet/in.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 33 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 34 | #include <openbsc/gsm_data.h> |
| 35 | #include <openbsc/debug.h> |
| 36 | #include <openbsc/msgb.h> |
| 37 | #include <openbsc/tlv.h> |
| 38 | #include <openbsc/abis_nm.h> |
Holger Freyther | ca362a6 | 2009-01-04 21:05:01 +0000 | [diff] [blame] | 39 | #include <openbsc/misdn.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 40 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 41 | #define OM_ALLOC_SIZE 1024 |
| 42 | #define OM_HEADROOM_SIZE 128 |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 43 | |
| 44 | /* unidirectional messages from BTS to BSC */ |
| 45 | static const enum abis_nm_msgtype reports[] = { |
| 46 | NM_MT_SW_ACTIVATED_REP, |
| 47 | NM_MT_TEST_REP, |
| 48 | NM_MT_STATECHG_EVENT_REP, |
| 49 | NM_MT_FAILURE_EVENT_REP, |
| 50 | }; |
| 51 | |
| 52 | /* messages without ACK/NACK */ |
| 53 | static const enum abis_nm_msgtype no_ack_nack[] = { |
| 54 | NM_MT_MEAS_RES_REQ, |
| 55 | NM_MT_STOP_MEAS, |
| 56 | NM_MT_START_MEAS, |
| 57 | }; |
| 58 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 59 | /* Messages related to software load */ |
| 60 | static const enum abis_nm_msgtype sw_load_msgs[] = { |
| 61 | NM_MT_LOAD_INIT_ACK, |
| 62 | NM_MT_LOAD_INIT_NACK, |
| 63 | NM_MT_LOAD_SEG_ACK, |
| 64 | NM_MT_LOAD_ABORT, |
| 65 | NM_MT_LOAD_END_ACK, |
| 66 | NM_MT_LOAD_END_NACK, |
| 67 | NM_MT_SW_ACT_REQ, |
| 68 | NM_MT_ACTIVATE_SW_ACK, |
| 69 | NM_MT_ACTIVATE_SW_NACK, |
| 70 | NM_MT_SW_ACTIVATED_REP, |
| 71 | }; |
| 72 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 73 | /* Attributes that the BSC can set, not only get, according to Section 9.4 */ |
| 74 | static const enum abis_nm_attr nm_att_settable[] = { |
| 75 | NM_ATT_ADD_INFO, |
| 76 | NM_ATT_ADD_TEXT, |
| 77 | NM_ATT_DEST, |
| 78 | NM_ATT_EVENT_TYPE, |
| 79 | NM_ATT_FILE_DATA, |
| 80 | NM_ATT_GET_ARI, |
| 81 | NM_ATT_HW_CONF_CHG, |
| 82 | NM_ATT_LIST_REQ_ATTR, |
| 83 | NM_ATT_MDROP_LINK, |
| 84 | NM_ATT_MDROP_NEXT, |
| 85 | NM_ATT_NACK_CAUSES, |
| 86 | NM_ATT_OUTST_ALARM, |
| 87 | NM_ATT_PHYS_CONF, |
| 88 | NM_ATT_PROB_CAUSE, |
| 89 | NM_ATT_RAD_SUBC, |
| 90 | NM_ATT_SOURCE, |
| 91 | NM_ATT_SPEC_PROB, |
| 92 | NM_ATT_START_TIME, |
| 93 | NM_ATT_TEST_DUR, |
| 94 | NM_ATT_TEST_NO, |
| 95 | NM_ATT_TEST_REPORT, |
| 96 | NM_ATT_WINDOW_SIZE, |
| 97 | NM_ATT_SEVERITY, |
| 98 | NM_ATT_MEAS_RES, |
| 99 | NM_ATT_MEAS_TYPE, |
| 100 | }; |
| 101 | |
| 102 | static int is_in_arr(enum abis_nm_msgtype mt, const enum abis_nm_msgtype *arr, int size) |
| 103 | { |
| 104 | int i; |
| 105 | |
| 106 | for (i = 0; i < size; i++) { |
| 107 | if (arr[i] == mt) |
| 108 | return 1; |
| 109 | } |
| 110 | |
| 111 | return 0; |
| 112 | } |
| 113 | |
Holger Freyther | ca362a6 | 2009-01-04 21:05:01 +0000 | [diff] [blame] | 114 | #if 0 |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 115 | /* is this msgtype the usual ACK/NACK type ? */ |
| 116 | static int is_ack_nack(enum abis_nm_msgtype mt) |
| 117 | { |
| 118 | return !is_in_arr(mt, no_ack_nack, ARRAY_SIZE(no_ack_nack)); |
| 119 | } |
Holger Freyther | ca362a6 | 2009-01-04 21:05:01 +0000 | [diff] [blame] | 120 | #endif |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 121 | |
| 122 | /* is this msgtype a report ? */ |
| 123 | static int is_report(enum abis_nm_msgtype mt) |
| 124 | { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 125 | return is_in_arr(mt, reports, ARRAY_SIZE(reports)); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | #define MT_ACK(x) (x+1) |
| 129 | #define MT_NACK(x) (x+2) |
| 130 | |
| 131 | static void fill_om_hdr(struct abis_om_hdr *oh, u_int8_t len) |
| 132 | { |
| 133 | oh->mdisc = ABIS_OM_MDISC_FOM; |
| 134 | oh->placement = ABIS_OM_PLACEMENT_ONLY; |
| 135 | oh->sequence = 0; |
| 136 | oh->length = len; |
| 137 | } |
| 138 | |
| 139 | static void fill_om_fom_hdr(struct abis_om_hdr *oh, u_int8_t len, |
| 140 | u_int8_t msg_type, u_int8_t obj_class, |
| 141 | u_int8_t bts_nr, u_int8_t trx_nr, u_int8_t ts_nr) |
| 142 | { |
| 143 | struct abis_om_fom_hdr *foh = |
| 144 | (struct abis_om_fom_hdr *) oh->data; |
| 145 | |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 146 | fill_om_hdr(oh, len+sizeof(*foh)); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 147 | foh->msg_type = msg_type; |
| 148 | foh->obj_class = obj_class; |
| 149 | foh->obj_inst.bts_nr = bts_nr; |
| 150 | foh->obj_inst.trx_nr = trx_nr; |
| 151 | foh->obj_inst.ts_nr = ts_nr; |
| 152 | } |
| 153 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 154 | static struct msgb *nm_msgb_alloc(void) |
| 155 | { |
| 156 | return msgb_alloc_headroom(OM_ALLOC_SIZE, OM_HEADROOM_SIZE); |
| 157 | } |
| 158 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 159 | /* Send a OML NM Message from BSC to BTS */ |
| 160 | int abis_nm_sendmsg(struct gsm_bts *bts, struct msgb *msg) |
| 161 | { |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 162 | return _abis_nm_sendmsg(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 163 | } |
| 164 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 165 | static int abis_nm_rcvmsg_sw(struct msgb *mb); |
| 166 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 167 | /* Receive a OML NM Message from BTS */ |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 168 | static int abis_nm_rcvmsg_fom(struct msgb *mb) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 169 | { |
| 170 | struct abis_om_fom_hdr *foh = msgb_l3(mb); |
| 171 | u_int8_t mt = foh->msg_type; |
| 172 | |
| 173 | /* check for unsolicited message */ |
| 174 | if (is_report(mt)) { |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 175 | DEBUGP(DNM, "reporting NM MT 0x%02x\n", mt); |
| 176 | //nmh->cfg->report_cb(mb, foh); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 177 | return 0; |
| 178 | } |
| 179 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 180 | if (is_in_arr(mt, sw_load_msgs, ARRAY_SIZE(sw_load_msgs))) |
| 181 | return abis_nm_rcvmsg_sw(mb); |
| 182 | |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 183 | #if 0 |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 184 | /* check if last message is to be acked */ |
| 185 | if (is_ack_nack(nmh->last_msgtype)) { |
| 186 | if (mt == MT_ACK(nmh->last_msgtype)) { |
| 187 | fprintf(stderr, "received ACK (0x%x)\n", |
| 188 | foh->msg_type); |
| 189 | /* we got our ACK, continue sending the next msg */ |
| 190 | } else if (mt == MT_NACK(nmh->last_msgtype)) { |
| 191 | /* we got a NACK, signal this to the caller */ |
| 192 | fprintf(stderr, "received NACK (0x%x)\n", |
| 193 | foh->msg_type); |
| 194 | /* FIXME: somehow signal this to the caller */ |
| 195 | } else { |
| 196 | /* really strange things happen */ |
| 197 | return -EINVAL; |
| 198 | } |
| 199 | } |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 200 | #endif |
| 201 | |
| 202 | return 0; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | /* High-Level API */ |
| 206 | /* Entry-point where L2 OML from BTS enters the NM code */ |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 207 | int abis_nm_rcvmsg(struct msgb *msg) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 208 | { |
| 209 | int rc; |
| 210 | struct abis_om_hdr *oh = msgb_l2(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 211 | |
| 212 | /* Various consistency checks */ |
| 213 | if (oh->placement != ABIS_OM_PLACEMENT_ONLY) { |
| 214 | fprintf(stderr, "ABIS OML placement 0x%x not supported\n", |
| 215 | oh->placement); |
| 216 | return -EINVAL; |
| 217 | } |
| 218 | if (oh->sequence != 0) { |
| 219 | fprintf(stderr, "ABIS OML sequence 0x%x != 0x00\n", |
| 220 | oh->sequence); |
| 221 | return -EINVAL; |
| 222 | } |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 223 | #if 0 |
Holger Freyther | ca362a6 | 2009-01-04 21:05:01 +0000 | [diff] [blame] | 224 | unsigned int l2_len = msg->tail - (u_int8_t *)msgb_l2(msg); |
| 225 | unsigned int hlen = sizeof(*oh) + sizeof(struct abis_om_fom_hdr); |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 226 | if (oh->length + hlen > l2_len) { |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 227 | fprintf(stderr, "ABIS OML truncated message (%u > %u)\n", |
| 228 | oh->length + sizeof(*oh), l2_len); |
| 229 | return -EINVAL; |
| 230 | } |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 231 | if (oh->length + hlen < l2_len) |
| 232 | fprintf(stderr, "ABIS OML message with extra trailer?!? (oh->len=%d, sizeof_oh=%d l2_len=%d\n", oh->length, sizeof(*oh), l2_len); |
| 233 | #endif |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 234 | msg->l3h = (unsigned char *)oh + sizeof(*oh); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 235 | |
| 236 | switch (oh->mdisc) { |
| 237 | case ABIS_OM_MDISC_FOM: |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 238 | rc = abis_nm_rcvmsg_fom(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 239 | break; |
| 240 | case ABIS_OM_MDISC_MMI: |
| 241 | case ABIS_OM_MDISC_TRAU: |
| 242 | case ABIS_OM_MDISC_MANUF: |
| 243 | default: |
| 244 | fprintf(stderr, "unknown ABIS OML message discriminator 0x%x\n", |
| 245 | oh->mdisc); |
| 246 | return -EINVAL; |
| 247 | } |
| 248 | |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 249 | msgb_free(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 250 | return rc; |
| 251 | } |
| 252 | |
| 253 | #if 0 |
| 254 | /* initialized all resources */ |
| 255 | struct abis_nm_h *abis_nm_init(struct abis_nm_cfg *cfg) |
| 256 | { |
| 257 | struct abis_nm_h *nmh; |
| 258 | |
| 259 | nmh = malloc(sizeof(*nmh)); |
| 260 | if (!nmh) |
| 261 | return NULL; |
| 262 | |
| 263 | nmh->cfg = cfg; |
| 264 | |
| 265 | return nmh; |
| 266 | } |
| 267 | |
| 268 | /* free all resources */ |
| 269 | void abis_nm_fini(struct abis_nm_h *nmh) |
| 270 | { |
| 271 | free(nmh); |
| 272 | } |
| 273 | #endif |
| 274 | |
| 275 | /* Here we are trying to define a high-level API that can be used by |
| 276 | * the actual BSC implementation. However, the architecture is currently |
| 277 | * still under design. Ideally the calls to this API would be synchronous, |
| 278 | * while the underlying stack behind the APi runs in a traditional select |
| 279 | * based state machine. |
| 280 | */ |
| 281 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 282 | /* 6.2 Software Load: */ |
| 283 | enum sw_state { |
| 284 | SW_STATE_NONE, |
| 285 | SW_STATE_WAIT_INITACK, |
| 286 | SW_STATE_WAIT_SEGACK, |
| 287 | SW_STATE_WAIT_ENDACK, |
| 288 | SW_STATE_WAIT_ACTACK, |
| 289 | SW_STATE_ERROR, |
| 290 | }; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 291 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 292 | struct abis_nm_sw { |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 293 | struct gsm_bts *bts; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 294 | /* this will become part of the SW LOAD INITIATE */ |
| 295 | u_int8_t obj_class; |
| 296 | u_int8_t obj_instance[3]; |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 297 | |
| 298 | u_int8_t file_id[255]; |
| 299 | u_int8_t file_id_len; |
| 300 | |
| 301 | u_int8_t file_version[255]; |
| 302 | u_int8_t file_version_len; |
| 303 | |
| 304 | u_int8_t window_size; |
| 305 | u_int8_t seg_in_window; |
| 306 | |
| 307 | int fd; |
| 308 | FILE *stream; |
| 309 | enum sw_state state; |
Harald Welte | 1602ade | 2009-01-29 21:12:39 +0000 | [diff] [blame] | 310 | int last_seg; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 311 | }; |
| 312 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 313 | static struct abis_nm_sw g_sw; |
| 314 | |
| 315 | /* 6.2.1 / 8.3.1: Load Data Initiate */ |
| 316 | static int sw_load_init(struct abis_nm_sw *sw) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 317 | { |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 318 | struct abis_om_hdr *oh; |
| 319 | struct msgb *msg = nm_msgb_alloc(); |
| 320 | u_int8_t len = 3*2 + sw->file_id_len + sw->file_version_len; |
| 321 | |
| 322 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 323 | fill_om_fom_hdr(oh, len, NM_MT_LOAD_INIT, sw->obj_class, |
| 324 | sw->obj_instance[0], sw->obj_instance[1], |
| 325 | sw->obj_instance[2]); |
| 326 | |
| 327 | /* FIXME: this is BS11 specific format */ |
| 328 | msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id); |
| 329 | msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len, |
| 330 | sw->file_version); |
| 331 | msgb_tv_put(msg, NM_ATT_WINDOW_SIZE, sw->window_size); |
| 332 | |
| 333 | return abis_nm_sendmsg(sw->bts, msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 334 | } |
| 335 | |
Harald Welte | 1602ade | 2009-01-29 21:12:39 +0000 | [diff] [blame] | 336 | static int is_last_line(FILE *stream) |
| 337 | { |
| 338 | char next_seg_buf[256]; |
| 339 | long pos; |
| 340 | |
| 341 | /* check if we're sending the last line */ |
| 342 | pos = ftell(stream); |
| 343 | if (!fgets(next_seg_buf, sizeof(next_seg_buf)-2, stream)) { |
| 344 | fseek(stream, pos, SEEK_SET); |
| 345 | return 1; |
| 346 | } |
| 347 | |
| 348 | fseek(stream, pos, SEEK_SET); |
| 349 | return 0; |
| 350 | } |
| 351 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 352 | /* 6.2.2 / 8.3.2 Load Data Segment */ |
| 353 | static int sw_load_segment(struct abis_nm_sw *sw) |
| 354 | { |
| 355 | struct abis_om_hdr *oh; |
| 356 | struct msgb *msg = nm_msgb_alloc(); |
| 357 | char seg_buf[256]; |
| 358 | char *line_buf = seg_buf+2; |
Harald Welte | 3b8ba21 | 2009-01-29 12:27:58 +0000 | [diff] [blame] | 359 | unsigned char *tlv; |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 360 | u_int8_t len; |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 361 | |
| 362 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
Harald Welte | 3b8ba21 | 2009-01-29 12:27:58 +0000 | [diff] [blame] | 363 | |
| 364 | switch (sw->bts->type) { |
| 365 | case GSM_BTS_TYPE_BS11: |
| 366 | if (fgets(line_buf, sizeof(seg_buf)-2, sw->stream) == NULL) { |
| 367 | perror("fgets reading segment"); |
| 368 | return -EINVAL; |
| 369 | } |
| 370 | seg_buf[0] = 0x00; |
Harald Welte | 1602ade | 2009-01-29 21:12:39 +0000 | [diff] [blame] | 371 | |
| 372 | /* check if we're sending the last line */ |
| 373 | sw->last_seg = is_last_line(sw->stream); |
| 374 | if (sw->last_seg) |
| 375 | seg_buf[1] = 0; |
| 376 | else |
| 377 | seg_buf[1] = 1 + sw->seg_in_window++; |
Harald Welte | 3b8ba21 | 2009-01-29 12:27:58 +0000 | [diff] [blame] | 378 | |
| 379 | len = strlen(line_buf) + 2; |
| 380 | tlv = msgb_put(msg, TLV_GROSS_LEN(len)); |
| 381 | tlv_put(tlv, NM_ATT_BS11_FILE_DATA, len, (u_int8_t *)seg_buf); |
| 382 | /* BS11 wants CR + LF in excess of the TLV length !?! */ |
| 383 | tlv[1] -= 2; |
| 384 | |
| 385 | /* we only now know the exact length for the OM hdr */ |
| 386 | len = strlen(line_buf)+2; |
| 387 | break; |
| 388 | default: |
| 389 | /* FIXME: Other BTS types */ |
| 390 | return -1; |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 391 | } |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 392 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 393 | fill_om_fom_hdr(oh, len, NM_MT_LOAD_SEG, sw->obj_class, |
| 394 | sw->obj_instance[0], sw->obj_instance[1], |
| 395 | sw->obj_instance[2]); |
| 396 | |
| 397 | return abis_nm_sendmsg(sw->bts, msg); |
| 398 | } |
| 399 | |
| 400 | /* 6.2.4 / 8.3.4 Load Data End */ |
| 401 | static int sw_load_end(struct abis_nm_sw *sw) |
| 402 | { |
| 403 | struct abis_om_hdr *oh; |
| 404 | struct msgb *msg = nm_msgb_alloc(); |
| 405 | u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len; |
| 406 | |
| 407 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 408 | fill_om_fom_hdr(oh, len, NM_MT_LOAD_END, sw->obj_class, |
| 409 | sw->obj_instance[0], sw->obj_instance[1], |
| 410 | sw->obj_instance[2]); |
| 411 | |
| 412 | /* FIXME: this is BS11 specific format */ |
| 413 | msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id); |
| 414 | msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len, |
| 415 | sw->file_version); |
| 416 | |
| 417 | return abis_nm_sendmsg(sw->bts, msg); |
| 418 | } |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 419 | /* Activate the specified software into the BTS */ |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 420 | static int sw_activate(struct abis_nm_sw *sw) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 421 | { |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 422 | struct abis_om_hdr *oh; |
| 423 | struct msgb *msg = nm_msgb_alloc(); |
| 424 | u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 425 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 426 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 427 | fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, sw->obj_class, |
| 428 | sw->obj_instance[0], sw->obj_instance[1], |
| 429 | sw->obj_instance[2]); |
| 430 | |
| 431 | /* FIXME: this is BS11 specific format */ |
| 432 | msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id); |
| 433 | msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len, |
| 434 | sw->file_version); |
| 435 | |
| 436 | return abis_nm_sendmsg(sw->bts, msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 437 | } |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 438 | |
| 439 | static int sw_open_file(struct abis_nm_sw *sw, const char *fname) |
| 440 | { |
| 441 | char file_id[12+1]; |
| 442 | char file_version[80+1]; |
| 443 | int rc; |
| 444 | |
| 445 | sw->fd = open(fname, O_RDONLY); |
| 446 | if (sw->fd < 0) |
| 447 | return sw->fd; |
| 448 | |
| 449 | switch (sw->bts->type) { |
| 450 | case GSM_BTS_TYPE_BS11: |
| 451 | sw->stream = fdopen(sw->fd, "r"); |
| 452 | if (!sw->stream) { |
| 453 | perror("fdopen"); |
| 454 | return -1; |
| 455 | } |
| 456 | /* read first line and parse file ID and VERSION */ |
Harald Welte | 3b8ba21 | 2009-01-29 12:27:58 +0000 | [diff] [blame] | 457 | rc = fscanf(sw->stream, "@(#)%12s:%80s\r\n", |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 458 | file_id, file_version); |
| 459 | if (rc != 2) { |
| 460 | perror("parsing header line of software file"); |
| 461 | return -1; |
| 462 | } |
| 463 | strcpy((char *)sw->file_id, file_id); |
| 464 | sw->file_id_len = strlen(file_id); |
| 465 | strcpy((char *)sw->file_version, file_version); |
| 466 | sw->file_version_len = strlen(file_version); |
| 467 | /* rewind to start of file */ |
Harald Welte | 3b8ba21 | 2009-01-29 12:27:58 +0000 | [diff] [blame] | 468 | rewind(sw->stream); |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 469 | break; |
| 470 | default: |
| 471 | /* We don't know how to treat them yet */ |
| 472 | close(sw->fd); |
| 473 | return -EINVAL; |
| 474 | } |
| 475 | |
| 476 | return 0; |
| 477 | } |
| 478 | |
| 479 | static void sw_close_file(struct abis_nm_sw *sw) |
| 480 | { |
| 481 | switch (sw->bts->type) { |
| 482 | case GSM_BTS_TYPE_BS11: |
| 483 | fclose(sw->stream); |
| 484 | break; |
| 485 | default: |
| 486 | close(sw->fd); |
| 487 | break; |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | /* Fill the window */ |
| 492 | static int sw_fill_window(struct abis_nm_sw *sw) |
| 493 | { |
| 494 | int rc; |
| 495 | |
| 496 | while (sw->seg_in_window < sw->window_size) { |
| 497 | rc = sw_load_segment(sw); |
| 498 | if (rc < 0) |
| 499 | return rc; |
Harald Welte | 1602ade | 2009-01-29 21:12:39 +0000 | [diff] [blame] | 500 | if (sw->last_seg) |
| 501 | break; |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 502 | } |
| 503 | return 0; |
| 504 | } |
| 505 | |
| 506 | /* callback function from abis_nm_rcvmsg() handler */ |
| 507 | static int abis_nm_rcvmsg_sw(struct msgb *mb) |
| 508 | { |
| 509 | struct abis_om_fom_hdr *foh = msgb_l3(mb); |
| 510 | int rc = -1; |
| 511 | struct abis_nm_sw *sw = &g_sw; |
| 512 | enum sw_state old_state = sw->state; |
| 513 | |
| 514 | DEBUGP(DNM, "state %u, NM MT 0x%02x\n", sw->state, foh->msg_type); |
| 515 | |
| 516 | switch (sw->state) { |
| 517 | case SW_STATE_WAIT_INITACK: |
| 518 | switch (foh->msg_type) { |
| 519 | case NM_MT_LOAD_INIT_ACK: |
| 520 | /* fill window with segments */ |
| 521 | rc = sw_fill_window(sw); |
| 522 | sw->state = SW_STATE_WAIT_SEGACK; |
| 523 | break; |
| 524 | case NM_MT_LOAD_INIT_NACK: |
Harald Welte | 1602ade | 2009-01-29 21:12:39 +0000 | [diff] [blame] | 525 | DEBUGP(DNM, "Software Load Init NACK\n"); |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 526 | sw->state = SW_STATE_ERROR; |
| 527 | break; |
| 528 | } |
| 529 | break; |
| 530 | case SW_STATE_WAIT_SEGACK: |
| 531 | switch (foh->msg_type) { |
| 532 | case NM_MT_LOAD_SEG_ACK: |
| 533 | sw->seg_in_window = 0; |
Harald Welte | 1602ade | 2009-01-29 21:12:39 +0000 | [diff] [blame] | 534 | if (!sw->last_seg) { |
| 535 | /* fill window with more segments */ |
| 536 | rc = sw_fill_window(sw); |
| 537 | sw->state = SW_STATE_WAIT_SEGACK; |
| 538 | } else { |
| 539 | /* end the transfer */ |
| 540 | sw->state = SW_STATE_WAIT_ENDACK; |
| 541 | rc = sw_load_end(sw); |
| 542 | } |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 543 | break; |
| 544 | } |
| 545 | break; |
| 546 | case SW_STATE_WAIT_ENDACK: |
| 547 | switch (foh->msg_type) { |
| 548 | case NM_MT_LOAD_END_ACK: |
| 549 | sw_close_file(sw); |
| 550 | /* send activate request */ |
| 551 | sw->state = SW_STATE_WAIT_ACTACK; |
| 552 | rc = sw_activate(sw); |
| 553 | break; |
| 554 | case NM_MT_LOAD_END_NACK: |
Harald Welte | 1602ade | 2009-01-29 21:12:39 +0000 | [diff] [blame] | 555 | DEBUGP(DNM, "Software Load End NACK\n"); |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 556 | sw->state = SW_STATE_ERROR; |
| 557 | break; |
| 558 | } |
| 559 | case SW_STATE_WAIT_ACTACK: |
| 560 | switch (foh->msg_type) { |
| 561 | case NM_MT_ACTIVATE_SW_ACK: |
| 562 | /* we're done */ |
| 563 | sw->state = SW_STATE_NONE; |
| 564 | rc = 0; |
| 565 | DEBUGP(DMM, "DONE!\n"); |
| 566 | break; |
| 567 | case NM_MT_ACTIVATE_SW_NACK: |
Harald Welte | 1602ade | 2009-01-29 21:12:39 +0000 | [diff] [blame] | 568 | DEBUGP(DNM, "Activate Software NACK\n"); |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 569 | sw->state = SW_STATE_ERROR; |
| 570 | break; |
| 571 | } |
| 572 | case SW_STATE_NONE: |
| 573 | case SW_STATE_ERROR: |
| 574 | break; |
| 575 | } |
| 576 | |
| 577 | if (rc) |
| 578 | fprintf(stderr, "unexpected NM MT 0x%02x in state %u -> %u\n", |
| 579 | foh->msg_type, old_state, sw->state); |
| 580 | |
| 581 | return rc; |
| 582 | } |
| 583 | |
| 584 | /* Load the specified software into the BTS */ |
| 585 | int abis_nm_software_load(struct gsm_bts *bts, const char *fname, |
| 586 | u_int8_t win_size) |
| 587 | { |
| 588 | struct abis_nm_sw *sw = &g_sw; |
| 589 | int rc; |
| 590 | |
| 591 | if (sw->state != SW_STATE_NONE) |
| 592 | return -EBUSY; |
| 593 | |
| 594 | sw->bts = bts; |
| 595 | sw->obj_class = NM_OC_SITE_MANAGER; |
| 596 | sw->obj_instance[0] = 0xff; |
| 597 | sw->obj_instance[1] = 0xff; |
| 598 | sw->obj_instance[2] = 0xff; |
| 599 | sw->window_size = win_size; |
| 600 | sw->state = SW_STATE_WAIT_INITACK; |
| 601 | |
| 602 | rc = sw_open_file(sw, fname); |
| 603 | if (rc < 0) { |
| 604 | sw->state = SW_STATE_NONE; |
| 605 | return rc; |
| 606 | } |
| 607 | |
| 608 | return sw_load_init(sw); |
| 609 | } |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 610 | |
Harald Welte | 1602ade | 2009-01-29 21:12:39 +0000 | [diff] [blame] | 611 | int abis_nm_software_load_status(struct gsm_bts *bts) |
| 612 | { |
| 613 | struct abis_nm_sw *sw = &g_sw; |
| 614 | struct stat st; |
| 615 | int rc, percent; |
| 616 | |
| 617 | rc = fstat(sw->fd, &st); |
| 618 | if (rc < 0) { |
| 619 | perror("ERROR during stat"); |
| 620 | return rc; |
| 621 | } |
| 622 | |
| 623 | percent = (ftell(sw->stream) * 100) / st.st_size; |
| 624 | return percent; |
| 625 | } |
| 626 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 627 | static void fill_nm_channel(struct abis_nm_channel *ch, u_int8_t bts_port, |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 628 | u_int8_t ts_nr, u_int8_t subslot_nr) |
| 629 | { |
Harald Welte | adaf08b | 2009-01-18 11:08:10 +0000 | [diff] [blame] | 630 | ch->attrib = NM_ATT_ABIS_CHANNEL; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 631 | ch->bts_port = bts_port; |
| 632 | ch->timeslot = ts_nr; |
| 633 | ch->subslot = subslot_nr; |
| 634 | } |
| 635 | |
| 636 | int abis_nm_establish_tei(struct gsm_bts *bts, u_int8_t trx_nr, |
| 637 | u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot, |
| 638 | u_int8_t tei) |
| 639 | { |
| 640 | struct abis_om_hdr *oh; |
| 641 | struct abis_nm_channel *ch; |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 642 | u_int8_t len = sizeof(*ch) + 2; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 643 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 644 | |
| 645 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 646 | fill_om_fom_hdr(oh, len, NM_MT_ESTABLISH_TEI, NM_OC_RADIO_CARRIER, |
| 647 | bts->bts_nr, trx_nr, 0xff); |
| 648 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 649 | msgb_tv_put(msg, NM_ATT_TEI, tei); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 650 | |
| 651 | ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch)); |
| 652 | fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot); |
| 653 | |
| 654 | return abis_nm_sendmsg(bts, msg); |
| 655 | } |
| 656 | |
| 657 | /* connect signalling of one (BTS,TRX) to a particular timeslot on the E1 */ |
| 658 | int abis_nm_conn_terr_sign(struct gsm_bts_trx *trx, |
| 659 | u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot) |
| 660 | { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 661 | struct gsm_bts *bts = trx->bts; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 662 | struct abis_om_hdr *oh; |
| 663 | struct abis_nm_channel *ch; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 664 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 665 | |
| 666 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
Harald Welte | 6f676a3 | 2009-01-18 14:27:48 +0000 | [diff] [blame] | 667 | fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_SIGN, |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 668 | NM_OC_RADIO_CARRIER, bts->bts_nr, trx->nr, 0xff); |
| 669 | |
| 670 | ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch)); |
| 671 | fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot); |
| 672 | |
| 673 | return abis_nm_sendmsg(bts, msg); |
| 674 | } |
| 675 | |
| 676 | #if 0 |
| 677 | int abis_nm_disc_terr_sign(struct abis_nm_h *h, struct abis_om_obj_inst *inst, |
| 678 | struct abis_nm_abis_channel *chan) |
| 679 | { |
| 680 | } |
| 681 | #endif |
| 682 | |
| 683 | int abis_nm_conn_terr_traf(struct gsm_bts_trx_ts *ts, |
| 684 | u_int8_t e1_port, u_int8_t e1_timeslot, |
| 685 | u_int8_t e1_subslot) |
| 686 | { |
| 687 | struct gsm_bts *bts = ts->trx->bts; |
| 688 | struct abis_om_hdr *oh; |
| 689 | struct abis_nm_channel *ch; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 690 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 691 | |
| 692 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 693 | fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_TRAF, |
| 694 | NM_OC_BASEB_TRANSC, bts->bts_nr, ts->trx->nr, ts->nr); |
| 695 | |
| 696 | ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch)); |
| 697 | fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot); |
| 698 | |
| 699 | return abis_nm_sendmsg(bts, msg); |
| 700 | } |
| 701 | |
| 702 | #if 0 |
| 703 | int abis_nm_disc_terr_traf(struct abis_nm_h *h, struct abis_om_obj_inst *inst, |
| 704 | struct abis_nm_abis_channel *chan, |
| 705 | u_int8_t subchan) |
| 706 | { |
| 707 | } |
| 708 | #endif |
| 709 | |
| 710 | int abis_nm_set_channel_attr(struct gsm_bts_trx_ts *ts, u_int8_t chan_comb) |
| 711 | { |
| 712 | struct gsm_bts *bts = ts->trx->bts; |
| 713 | struct abis_om_hdr *oh; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 714 | u_int16_t arfcn = htons(ts->trx->arfcn); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 715 | u_int8_t zero = 0x00; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 716 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 717 | u_int8_t len = 4 + 2 + 2 + 2 + 2 +3; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 718 | |
| 719 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 720 | fill_om_fom_hdr(oh, len, NM_MT_SET_CHAN_ATTR, |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 721 | NM_OC_BASEB_TRANSC, bts->bts_nr, |
| 722 | ts->trx->nr, ts->nr); |
| 723 | /* FIXME: don't send ARFCN list, hopping sequence, mAIO, ...*/ |
| 724 | msgb_tlv16_put(msg, NM_ATT_ARFCN_LIST, 1, &arfcn); |
| 725 | msgb_tv_put(msg, NM_ATT_CHAN_COMB, chan_comb); |
| 726 | msgb_tv_put(msg, NM_ATT_HSN, 0x00); |
| 727 | msgb_tv_put(msg, NM_ATT_MAIO, 0x00); |
| 728 | msgb_tv_put(msg, NM_ATT_TSC, 0x07); /* training sequence */ |
| 729 | msgb_tlv_put(msg, 0x59, 1, &zero); |
| 730 | |
| 731 | return abis_nm_sendmsg(bts, msg); |
| 732 | } |
| 733 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 734 | int abis_nm_raw_msg(struct gsm_bts *bts, int len, u_int8_t *rawmsg) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 735 | { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 736 | struct msgb *msg = nm_msgb_alloc(); |
| 737 | struct abis_om_hdr *oh; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 738 | u_int8_t *data; |
| 739 | |
| 740 | oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh)); |
| 741 | fill_om_hdr(oh, len); |
| 742 | data = msgb_put(msg, len); |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 743 | memcpy(data, rawmsg, len); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 744 | |
| 745 | return abis_nm_sendmsg(bts, msg); |
| 746 | } |
| 747 | |
| 748 | /* Siemens specific commands */ |
| 749 | static int __simple_cmd(struct gsm_bts *bts, u_int8_t msg_type) |
| 750 | { |
| 751 | struct abis_om_hdr *oh; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 752 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 753 | |
| 754 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 755 | fill_om_fom_hdr(oh, 0, msg_type, NM_OC_SITE_MANAGER, |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 756 | 0xff, 0xff, 0xff); |
| 757 | |
| 758 | return abis_nm_sendmsg(bts, msg); |
| 759 | } |
| 760 | |
| 761 | int abis_nm_event_reports(struct gsm_bts *bts, int on) |
| 762 | { |
| 763 | if (on == 0) |
Harald Welte | 227d407 | 2009-01-03 08:16:25 +0000 | [diff] [blame] | 764 | return __simple_cmd(bts, NM_MT_STOP_EVENT_REP); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 765 | else |
Harald Welte | 227d407 | 2009-01-03 08:16:25 +0000 | [diff] [blame] | 766 | return __simple_cmd(bts, NM_MT_REST_EVENT_REP); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 767 | } |
| 768 | |
Harald Welte | 47d88ae | 2009-01-04 12:02:08 +0000 | [diff] [blame] | 769 | /* Siemens (or BS-11) specific commands */ |
| 770 | |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 771 | int abis_nm_bs11_reset_resource(struct gsm_bts *bts) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 772 | { |
Harald Welte | 4668fda | 2009-01-03 08:19:29 +0000 | [diff] [blame] | 773 | return __simple_cmd(bts, NM_MT_BS11_RESET_RESOURCE); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 774 | } |
| 775 | |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 776 | int abis_nm_bs11_db_transmission(struct gsm_bts *bts, int begin) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 777 | { |
| 778 | if (begin) |
Harald Welte | 4668fda | 2009-01-03 08:19:29 +0000 | [diff] [blame] | 779 | return __simple_cmd(bts, NM_MT_BS11_BEGIN_DB_TX); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 780 | else |
Harald Welte | 4668fda | 2009-01-03 08:19:29 +0000 | [diff] [blame] | 781 | return __simple_cmd(bts, NM_MT_BS11_END_DB_TX); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 782 | } |
Harald Welte | 47d88ae | 2009-01-04 12:02:08 +0000 | [diff] [blame] | 783 | |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 784 | int abis_nm_bs11_create_object(struct gsm_bts *bts, |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 785 | enum abis_bs11_objtype type, u_int8_t idx, |
| 786 | u_int8_t attr_len, const u_int8_t *attr) |
Harald Welte | 47d88ae | 2009-01-04 12:02:08 +0000 | [diff] [blame] | 787 | { |
| 788 | struct abis_om_hdr *oh; |
| 789 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 790 | u_int8_t *cur; |
Harald Welte | 47d88ae | 2009-01-04 12:02:08 +0000 | [diff] [blame] | 791 | |
| 792 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
Harald Welte | 6f676a3 | 2009-01-18 14:27:48 +0000 | [diff] [blame] | 793 | fill_om_fom_hdr(oh, attr_len, NM_MT_BS11_CREATE_OBJ, |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 794 | NM_OC_BS11, type, idx, 0); |
| 795 | cur = msgb_put(msg, attr_len); |
| 796 | memcpy(cur, attr, attr_len); |
Harald Welte | 47d88ae | 2009-01-04 12:02:08 +0000 | [diff] [blame] | 797 | |
| 798 | return abis_nm_sendmsg(bts, msg); |
| 799 | } |
| 800 | |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 801 | int abis_nm_bs11_create_envaBTSE(struct gsm_bts *bts, u_int8_t idx) |
Harald Welte | 47d88ae | 2009-01-04 12:02:08 +0000 | [diff] [blame] | 802 | { |
| 803 | struct abis_om_hdr *oh; |
| 804 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 805 | u_int8_t zero = 0x00; |
Harald Welte | 47d88ae | 2009-01-04 12:02:08 +0000 | [diff] [blame] | 806 | |
| 807 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
Harald Welte | 6f676a3 | 2009-01-18 14:27:48 +0000 | [diff] [blame] | 808 | fill_om_fom_hdr(oh, 3, NM_MT_BS11_CREATE_OBJ, |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 809 | NM_OC_BS11_ENVABTSE, 0, idx, 0xff); |
| 810 | msgb_tlv_put(msg, 0x99, 1, &zero); |
Harald Welte | 47d88ae | 2009-01-04 12:02:08 +0000 | [diff] [blame] | 811 | |
| 812 | return abis_nm_sendmsg(bts, msg); |
| 813 | } |
| 814 | |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 815 | int abis_nm_bs11_create_bport(struct gsm_bts *bts, u_int8_t idx) |
Harald Welte | 47d88ae | 2009-01-04 12:02:08 +0000 | [diff] [blame] | 816 | { |
| 817 | struct abis_om_hdr *oh; |
| 818 | struct msgb *msg = nm_msgb_alloc(); |
| 819 | |
| 820 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 821 | fill_om_fom_hdr(oh, 0, NM_MT_BS11_CREATE_OBJ, NM_OC_BS11_BPORT, |
| 822 | idx, 0, 0); |
| 823 | |
| 824 | return abis_nm_sendmsg(bts, msg); |
| 825 | } |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 826 | |
| 827 | int abis_nm_bs11_set_oml_tei(struct gsm_bts *bts, u_int8_t tei) |
| 828 | { |
| 829 | struct abis_om_hdr *oh; |
| 830 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 831 | |
| 832 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
Harald Welte | 6f676a3 | 2009-01-18 14:27:48 +0000 | [diff] [blame] | 833 | fill_om_fom_hdr(oh, 2, NM_MT_BS11_SET_ATTR, NM_OC_SITE_MANAGER, |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 834 | 0xff, 0xff, 0xff); |
| 835 | msgb_tv_put(msg, NM_ATT_TEI, tei); |
| 836 | |
| 837 | return abis_nm_sendmsg(bts, msg); |
| 838 | } |
| 839 | |
| 840 | /* like abis_nm_conn_terr_traf */ |
| 841 | int abis_nm_bs11_conn_oml(struct gsm_bts *bts, u_int8_t e1_port, |
| 842 | u_int8_t e1_timeslot, u_int8_t e1_subslot) |
| 843 | { |
| 844 | struct abis_om_hdr *oh; |
| 845 | struct abis_nm_channel *ch; |
| 846 | struct msgb *msg = nm_msgb_alloc(); |
| 847 | |
| 848 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 849 | fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_BS11_SET_ATTR, |
| 850 | NM_OC_SITE_MANAGER, 0xff, 0xff, 0xff); |
| 851 | |
| 852 | ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch)); |
| 853 | fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot); |
| 854 | |
| 855 | return abis_nm_sendmsg(bts, msg); |
| 856 | } |
| 857 | |
| 858 | int abis_nm_bs11_set_trx_power(struct gsm_bts_trx *trx, u_int8_t level) |
| 859 | { |
| 860 | struct abis_om_hdr *oh; |
| 861 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 862 | |
| 863 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
Harald Welte | 6f676a3 | 2009-01-18 14:27:48 +0000 | [diff] [blame] | 864 | fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR, |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 865 | NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr); |
| 866 | msgb_tlv_put(msg, NM_ATT_BS11_TXPWR, 1, &level); |
| 867 | |
| 868 | return abis_nm_sendmsg(trx->bts, msg); |
| 869 | } |
| 870 | |
| 871 | static const u_int8_t bs11_logon_c7[] = |
| 872 | { 0x07, 0xd9, 0x01, 0x11, 0x0d, 0x10, 0x20 }; |
Harald Welte | bb15131 | 2009-01-28 20:42:07 +0000 | [diff] [blame] | 873 | static const u_int8_t bs11_logon_c8[] = { 0x02 }; |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 874 | static const u_int8_t bs11_logon_c9[] = "FACTORY"; |
| 875 | |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 876 | int abis_nm_bs11_factory_logon(struct gsm_bts *bts, int on) |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 877 | { |
| 878 | struct abis_om_hdr *oh; |
| 879 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 880 | |
| 881 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 882 | if (on) { |
Harald Welte | 6f676a3 | 2009-01-18 14:27:48 +0000 | [diff] [blame] | 883 | u_int8_t len = 3*2 + sizeof(bs11_logon_c7) |
| 884 | + sizeof(bs11_logon_c8) + sizeof(bs11_logon_c9); |
Harald Welte | 043d04a | 2009-01-29 23:15:30 +0000 | [diff] [blame^] | 885 | fill_om_fom_hdr(oh, len, NM_MT_BS11_LMT_LOGON, |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 886 | NM_OC_BS11_A3, 0xff, 0xff, 0xff); |
Harald Welte | 043d04a | 2009-01-29 23:15:30 +0000 | [diff] [blame^] | 887 | msgb_tlv_put(msg, NM_ATT_BS11_LMT_LOGIN_TIME, |
| 888 | sizeof(bs11_logon_c7), bs11_logon_c7); |
| 889 | msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_ACC_LEV, |
| 890 | sizeof(bs11_logon_c8), bs11_logon_c8); |
| 891 | msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_NAME, |
| 892 | sizeof(bs11_logon_c9), bs11_logon_c9); |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 893 | } else { |
Harald Welte | 6f676a3 | 2009-01-18 14:27:48 +0000 | [diff] [blame] | 894 | fill_om_fom_hdr(oh, 0, NM_MT_BS11_LOGOFF, |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 895 | NM_OC_BS11_A3, 0xff, 0xff, 0xff); |
| 896 | } |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 897 | |
| 898 | return abis_nm_sendmsg(bts, msg); |
| 899 | } |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 900 | |
| 901 | int abis_nm_bs11_set_trx1_pw(struct gsm_bts *bts, const char *password) |
| 902 | { |
| 903 | struct abis_om_hdr *oh; |
| 904 | struct msgb *msg; |
| 905 | |
| 906 | if (strlen(password) != 10) |
| 907 | return -EINVAL; |
| 908 | |
| 909 | msg = nm_msgb_alloc(); |
| 910 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
Harald Welte | 6f676a3 | 2009-01-18 14:27:48 +0000 | [diff] [blame] | 911 | fill_om_fom_hdr(oh, 2+strlen(password), NM_MT_BS11_SET_ATTR, |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 912 | NM_OC_BS11, BS11_OBJ_TRX1, 0x00, 0x00); |
| 913 | msgb_tlv_put(msg, NM_ATT_BS11_PASSWORD, 10, (const u_int8_t *)password); |
| 914 | |
| 915 | return abis_nm_sendmsg(bts, msg); |
| 916 | } |
| 917 | |
| 918 | int abis_nm_bs11_get_state(struct gsm_bts *bts) |
| 919 | { |
| 920 | return __simple_cmd(bts, NM_MT_BS11_GET_STATE); |
| 921 | } |