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> |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 29 | #include <malloc.h> |
| 30 | #include <libgen.h> |
Harald Welte | 268bb40 | 2009-02-01 19:11:56 +0000 | [diff] [blame] | 31 | #include <time.h> |
Harald Welte | 5f6f149 | 2009-02-02 14:50:29 +0000 | [diff] [blame] | 32 | #include <limits.h> |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 33 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 34 | #include <sys/types.h> |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 35 | #include <sys/stat.h> |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 36 | #include <netinet/in.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 37 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 38 | #include <openbsc/gsm_data.h> |
| 39 | #include <openbsc/debug.h> |
| 40 | #include <openbsc/msgb.h> |
| 41 | #include <openbsc/tlv.h> |
| 42 | #include <openbsc/abis_nm.h> |
Holger Freyther | ca362a6 | 2009-01-04 21:05:01 +0000 | [diff] [blame] | 43 | #include <openbsc/misdn.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 44 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 45 | #define OM_ALLOC_SIZE 1024 |
| 46 | #define OM_HEADROOM_SIZE 128 |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 47 | |
| 48 | /* unidirectional messages from BTS to BSC */ |
| 49 | static const enum abis_nm_msgtype reports[] = { |
| 50 | NM_MT_SW_ACTIVATED_REP, |
| 51 | NM_MT_TEST_REP, |
| 52 | NM_MT_STATECHG_EVENT_REP, |
| 53 | NM_MT_FAILURE_EVENT_REP, |
| 54 | }; |
| 55 | |
| 56 | /* messages without ACK/NACK */ |
| 57 | static const enum abis_nm_msgtype no_ack_nack[] = { |
| 58 | NM_MT_MEAS_RES_REQ, |
| 59 | NM_MT_STOP_MEAS, |
| 60 | NM_MT_START_MEAS, |
| 61 | }; |
| 62 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 63 | /* Messages related to software load */ |
| 64 | static const enum abis_nm_msgtype sw_load_msgs[] = { |
| 65 | NM_MT_LOAD_INIT_ACK, |
| 66 | NM_MT_LOAD_INIT_NACK, |
| 67 | NM_MT_LOAD_SEG_ACK, |
| 68 | NM_MT_LOAD_ABORT, |
| 69 | NM_MT_LOAD_END_ACK, |
| 70 | NM_MT_LOAD_END_NACK, |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 71 | //NM_MT_SW_ACT_REQ, |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 72 | NM_MT_ACTIVATE_SW_ACK, |
| 73 | NM_MT_ACTIVATE_SW_NACK, |
| 74 | NM_MT_SW_ACTIVATED_REP, |
| 75 | }; |
| 76 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 77 | /* Attributes that the BSC can set, not only get, according to Section 9.4 */ |
| 78 | static const enum abis_nm_attr nm_att_settable[] = { |
| 79 | NM_ATT_ADD_INFO, |
| 80 | NM_ATT_ADD_TEXT, |
| 81 | NM_ATT_DEST, |
| 82 | NM_ATT_EVENT_TYPE, |
| 83 | NM_ATT_FILE_DATA, |
| 84 | NM_ATT_GET_ARI, |
| 85 | NM_ATT_HW_CONF_CHG, |
| 86 | NM_ATT_LIST_REQ_ATTR, |
| 87 | NM_ATT_MDROP_LINK, |
| 88 | NM_ATT_MDROP_NEXT, |
| 89 | NM_ATT_NACK_CAUSES, |
| 90 | NM_ATT_OUTST_ALARM, |
| 91 | NM_ATT_PHYS_CONF, |
| 92 | NM_ATT_PROB_CAUSE, |
| 93 | NM_ATT_RAD_SUBC, |
| 94 | NM_ATT_SOURCE, |
| 95 | NM_ATT_SPEC_PROB, |
| 96 | NM_ATT_START_TIME, |
| 97 | NM_ATT_TEST_DUR, |
| 98 | NM_ATT_TEST_NO, |
| 99 | NM_ATT_TEST_REPORT, |
| 100 | NM_ATT_WINDOW_SIZE, |
| 101 | NM_ATT_SEVERITY, |
| 102 | NM_ATT_MEAS_RES, |
| 103 | NM_ATT_MEAS_TYPE, |
| 104 | }; |
| 105 | |
| 106 | static int is_in_arr(enum abis_nm_msgtype mt, const enum abis_nm_msgtype *arr, int size) |
| 107 | { |
| 108 | int i; |
| 109 | |
| 110 | for (i = 0; i < size; i++) { |
| 111 | if (arr[i] == mt) |
| 112 | return 1; |
| 113 | } |
| 114 | |
| 115 | return 0; |
| 116 | } |
| 117 | |
Holger Freyther | ca362a6 | 2009-01-04 21:05:01 +0000 | [diff] [blame] | 118 | #if 0 |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 119 | /* is this msgtype the usual ACK/NACK type ? */ |
| 120 | static int is_ack_nack(enum abis_nm_msgtype mt) |
| 121 | { |
| 122 | return !is_in_arr(mt, no_ack_nack, ARRAY_SIZE(no_ack_nack)); |
| 123 | } |
Holger Freyther | ca362a6 | 2009-01-04 21:05:01 +0000 | [diff] [blame] | 124 | #endif |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 125 | |
| 126 | /* is this msgtype a report ? */ |
| 127 | static int is_report(enum abis_nm_msgtype mt) |
| 128 | { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 129 | return is_in_arr(mt, reports, ARRAY_SIZE(reports)); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | #define MT_ACK(x) (x+1) |
| 133 | #define MT_NACK(x) (x+2) |
| 134 | |
| 135 | static void fill_om_hdr(struct abis_om_hdr *oh, u_int8_t len) |
| 136 | { |
| 137 | oh->mdisc = ABIS_OM_MDISC_FOM; |
| 138 | oh->placement = ABIS_OM_PLACEMENT_ONLY; |
| 139 | oh->sequence = 0; |
| 140 | oh->length = len; |
| 141 | } |
| 142 | |
| 143 | static void fill_om_fom_hdr(struct abis_om_hdr *oh, u_int8_t len, |
| 144 | u_int8_t msg_type, u_int8_t obj_class, |
| 145 | u_int8_t bts_nr, u_int8_t trx_nr, u_int8_t ts_nr) |
| 146 | { |
| 147 | struct abis_om_fom_hdr *foh = |
| 148 | (struct abis_om_fom_hdr *) oh->data; |
| 149 | |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 150 | fill_om_hdr(oh, len+sizeof(*foh)); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 151 | foh->msg_type = msg_type; |
| 152 | foh->obj_class = obj_class; |
| 153 | foh->obj_inst.bts_nr = bts_nr; |
| 154 | foh->obj_inst.trx_nr = trx_nr; |
| 155 | foh->obj_inst.ts_nr = ts_nr; |
| 156 | } |
| 157 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 158 | static struct msgb *nm_msgb_alloc(void) |
| 159 | { |
| 160 | return msgb_alloc_headroom(OM_ALLOC_SIZE, OM_HEADROOM_SIZE); |
| 161 | } |
| 162 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 163 | /* Send a OML NM Message from BSC to BTS */ |
| 164 | int abis_nm_sendmsg(struct gsm_bts *bts, struct msgb *msg) |
| 165 | { |
Holger Freyther | 59639e8 | 2009-02-09 23:09:55 +0000 | [diff] [blame] | 166 | msg->trx = bts->c0; |
| 167 | |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 168 | return _abis_nm_sendmsg(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 169 | } |
| 170 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 171 | static int abis_nm_rcvmsg_sw(struct msgb *mb); |
| 172 | |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 173 | const char *oc_names[] = { |
| 174 | [NM_OC_SITE_MANAGER] = "SITE MANAGER", |
| 175 | [NM_OC_BTS] = "BTS", |
| 176 | [NM_OC_RADIO_CARRIER] = "RADIO CARRIER", |
| 177 | [NM_OC_BASEB_TRANSC] = "BASEBAND TRANSCEIVER", |
| 178 | [NM_OC_CHANNEL] = "CHANNEL", |
| 179 | }; |
| 180 | |
| 181 | static const char *obj_class_name(u_int8_t oc) |
| 182 | { |
| 183 | if (oc >= ARRAY_SIZE(oc_names)) |
| 184 | return "UNKNOWN"; |
| 185 | return oc_names[oc]; |
| 186 | } |
| 187 | |
| 188 | static const char *opstate_name(u_int8_t os) |
| 189 | { |
| 190 | switch (os) { |
| 191 | case 1: |
| 192 | return "Disabled"; |
| 193 | case 2: |
| 194 | return "Enabled"; |
| 195 | case 0xff: |
| 196 | return "NULL"; |
| 197 | default: |
| 198 | return "RFU"; |
| 199 | } |
| 200 | } |
| 201 | |
Harald Welte | 97ed1e7 | 2009-02-06 13:38:02 +0000 | [diff] [blame] | 202 | static int abis_nm_rx_statechg_rep(struct msgb *mb) |
| 203 | { |
| 204 | struct abis_om_fom_hdr *foh = msgb_l3(mb); |
Harald Welte | 97ed1e7 | 2009-02-06 13:38:02 +0000 | [diff] [blame] | 205 | u_int8_t *data = &foh->data[0]; |
Harald Welte | 22af0db | 2009-02-14 15:41:08 +0000 | [diff] [blame] | 206 | struct gsm_bts *bts = mb->trx->bts; |
| 207 | u_int8_t op_state = 0; |
Harald Welte | 97ed1e7 | 2009-02-06 13:38:02 +0000 | [diff] [blame] | 208 | |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 209 | DEBUGP(DNM, "STATE CHG: OC=%s(%02x) INST=(%02x,%02x,%02x) ", |
| 210 | obj_class_name(foh->obj_class), foh->obj_class, |
| 211 | foh->obj_inst.bts_nr, foh->obj_inst.trx_nr, |
Harald Welte | 97ed1e7 | 2009-02-06 13:38:02 +0000 | [diff] [blame] | 212 | foh->obj_inst.ts_nr); |
Harald Welte | 22af0db | 2009-02-14 15:41:08 +0000 | [diff] [blame] | 213 | if (*data++ == NM_ATT_OPER_STATE) { |
| 214 | u_int8_t op_state = *data++; |
| 215 | DEBUGPC(DNM, "OP_STATE=%s ", opstate_name(op_state)); |
| 216 | |
| 217 | } |
Harald Welte | 97ed1e7 | 2009-02-06 13:38:02 +0000 | [diff] [blame] | 218 | if (*data++ == NM_ATT_AVAIL_STATUS) { |
| 219 | u_int8_t att_len = *data++; |
| 220 | while (att_len--) |
| 221 | DEBUGPC(DNM, "AVAIL=%02x ", *data++); |
| 222 | } |
| 223 | DEBUGPC(DNM, "\n"); |
Harald Welte | 22af0db | 2009-02-14 15:41:08 +0000 | [diff] [blame] | 224 | if (op_state == 1) { |
| 225 | /* try to enable objects that are disabled */ |
| 226 | abis_nm_opstart(bts, foh->obj_class, |
| 227 | foh->obj_inst.bts_nr, |
| 228 | foh->obj_inst.trx_nr, |
| 229 | foh->obj_inst.ts_nr); |
| 230 | } |
Harald Welte | 97ed1e7 | 2009-02-06 13:38:02 +0000 | [diff] [blame] | 231 | return 0; |
| 232 | } |
| 233 | |
| 234 | static int abis_nm_rcvmsg_report(struct msgb *mb) |
| 235 | { |
| 236 | struct abis_om_fom_hdr *foh = msgb_l3(mb); |
| 237 | u_int8_t mt = foh->msg_type; |
| 238 | |
| 239 | //nmh->cfg->report_cb(mb, foh); |
| 240 | |
| 241 | switch (mt) { |
| 242 | case NM_MT_STATECHG_EVENT_REP: |
| 243 | return abis_nm_rx_statechg_rep(mb); |
| 244 | break; |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 245 | case NM_MT_SW_ACTIVATED_REP: |
| 246 | DEBUGP(DNM, "Software Activated Report\n"); |
| 247 | break; |
Harald Welte | 97ed1e7 | 2009-02-06 13:38:02 +0000 | [diff] [blame] | 248 | }; |
| 249 | |
| 250 | DEBUGP(DNM, "reporting NM MT 0x%02x\n", mt); |
| 251 | |
| 252 | return 0; |
| 253 | } |
| 254 | |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 255 | /* Activate the specified software into the BTS */ |
| 256 | static int ipacc_sw_activate(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1, |
| 257 | u_int8_t i2, u_int8_t *sw_desc, u_int8_t swdesc_len) |
| 258 | { |
| 259 | struct abis_om_hdr *oh; |
| 260 | struct msgb *msg = nm_msgb_alloc(); |
| 261 | u_int8_t len = swdesc_len; |
| 262 | u_int8_t *trailer; |
| 263 | |
| 264 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 265 | fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, obj_class, i0, i1, i2); |
| 266 | |
| 267 | trailer = msgb_put(msg, swdesc_len); |
| 268 | memcpy(trailer, sw_desc, swdesc_len); |
| 269 | |
| 270 | return abis_nm_sendmsg(bts, msg); |
| 271 | } |
| 272 | |
| 273 | static int abis_nm_rx_sw_act_req(struct msgb *mb) |
| 274 | { |
| 275 | struct abis_om_hdr *oh = msgb_l2(mb); |
| 276 | struct abis_om_fom_hdr *foh = msgb_l3(mb); |
| 277 | int ret; |
| 278 | |
| 279 | DEBUGP(DNM, "Software Activate Request, ACKing and Activating\n"); |
| 280 | |
| 281 | ret = abis_nm_sw_act_req_ack(mb->trx->bts, foh->obj_class, |
| 282 | foh->obj_inst.bts_nr, |
| 283 | foh->obj_inst.trx_nr, |
| 284 | foh->obj_inst.ts_nr, |
| 285 | foh->data, oh->length-sizeof(*foh)); |
| 286 | |
| 287 | /* FIXME: properly parse attributes */ |
| 288 | return ipacc_sw_activate(mb->trx->bts, foh->obj_class, |
| 289 | foh->obj_inst.bts_nr, |
| 290 | foh->obj_inst.trx_nr, |
| 291 | foh->obj_inst.ts_nr, |
| 292 | foh->data + oh->length-sizeof(*foh)-22, 22); |
| 293 | } |
| 294 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 295 | /* Receive a OML NM Message from BTS */ |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 296 | static int abis_nm_rcvmsg_fom(struct msgb *mb) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 297 | { |
| 298 | struct abis_om_fom_hdr *foh = msgb_l3(mb); |
| 299 | u_int8_t mt = foh->msg_type; |
| 300 | |
| 301 | /* check for unsolicited message */ |
Harald Welte | 97ed1e7 | 2009-02-06 13:38:02 +0000 | [diff] [blame] | 302 | if (is_report(mt)) |
| 303 | return abis_nm_rcvmsg_report(mb); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 304 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 305 | if (is_in_arr(mt, sw_load_msgs, ARRAY_SIZE(sw_load_msgs))) |
| 306 | return abis_nm_rcvmsg_sw(mb); |
| 307 | |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 308 | #if 0 |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 309 | /* check if last message is to be acked */ |
| 310 | if (is_ack_nack(nmh->last_msgtype)) { |
| 311 | if (mt == MT_ACK(nmh->last_msgtype)) { |
| 312 | fprintf(stderr, "received ACK (0x%x)\n", |
| 313 | foh->msg_type); |
| 314 | /* we got our ACK, continue sending the next msg */ |
| 315 | } else if (mt == MT_NACK(nmh->last_msgtype)) { |
| 316 | /* we got a NACK, signal this to the caller */ |
| 317 | fprintf(stderr, "received NACK (0x%x)\n", |
| 318 | foh->msg_type); |
| 319 | /* FIXME: somehow signal this to the caller */ |
| 320 | } else { |
| 321 | /* really strange things happen */ |
| 322 | return -EINVAL; |
| 323 | } |
| 324 | } |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 325 | #endif |
| 326 | |
Harald Welte | 97ed1e7 | 2009-02-06 13:38:02 +0000 | [diff] [blame] | 327 | switch (mt) { |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 328 | case NM_MT_SW_ACT_REQ: |
| 329 | return abis_nm_rx_sw_act_req(mb); |
| 330 | break; |
Harald Welte | 97ed1e7 | 2009-02-06 13:38:02 +0000 | [diff] [blame] | 331 | case NM_MT_BS11_LMT_SESSION: |
| 332 | DEBUGP(DNM, "LMT Event: \n"); |
| 333 | break; |
| 334 | } |
| 335 | |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 336 | return 0; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | /* High-Level API */ |
| 340 | /* Entry-point where L2 OML from BTS enters the NM code */ |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 341 | int abis_nm_rcvmsg(struct msgb *msg) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 342 | { |
| 343 | int rc; |
| 344 | struct abis_om_hdr *oh = msgb_l2(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 345 | |
| 346 | /* Various consistency checks */ |
| 347 | if (oh->placement != ABIS_OM_PLACEMENT_ONLY) { |
| 348 | fprintf(stderr, "ABIS OML placement 0x%x not supported\n", |
| 349 | oh->placement); |
| 350 | return -EINVAL; |
| 351 | } |
| 352 | if (oh->sequence != 0) { |
| 353 | fprintf(stderr, "ABIS OML sequence 0x%x != 0x00\n", |
| 354 | oh->sequence); |
| 355 | return -EINVAL; |
| 356 | } |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 357 | #if 0 |
Holger Freyther | ca362a6 | 2009-01-04 21:05:01 +0000 | [diff] [blame] | 358 | unsigned int l2_len = msg->tail - (u_int8_t *)msgb_l2(msg); |
| 359 | unsigned int hlen = sizeof(*oh) + sizeof(struct abis_om_fom_hdr); |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 360 | if (oh->length + hlen > l2_len) { |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 361 | fprintf(stderr, "ABIS OML truncated message (%u > %u)\n", |
| 362 | oh->length + sizeof(*oh), l2_len); |
| 363 | return -EINVAL; |
| 364 | } |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 365 | if (oh->length + hlen < l2_len) |
| 366 | fprintf(stderr, "ABIS OML message with extra trailer?!? (oh->len=%d, sizeof_oh=%d l2_len=%d\n", oh->length, sizeof(*oh), l2_len); |
| 367 | #endif |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 368 | msg->l3h = (unsigned char *)oh + sizeof(*oh); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 369 | |
| 370 | switch (oh->mdisc) { |
| 371 | case ABIS_OM_MDISC_FOM: |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 372 | rc = abis_nm_rcvmsg_fom(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 373 | break; |
| 374 | case ABIS_OM_MDISC_MMI: |
| 375 | case ABIS_OM_MDISC_TRAU: |
| 376 | case ABIS_OM_MDISC_MANUF: |
| 377 | default: |
| 378 | fprintf(stderr, "unknown ABIS OML message discriminator 0x%x\n", |
| 379 | oh->mdisc); |
| 380 | return -EINVAL; |
| 381 | } |
| 382 | |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 383 | msgb_free(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 384 | return rc; |
| 385 | } |
| 386 | |
| 387 | #if 0 |
| 388 | /* initialized all resources */ |
| 389 | struct abis_nm_h *abis_nm_init(struct abis_nm_cfg *cfg) |
| 390 | { |
| 391 | struct abis_nm_h *nmh; |
| 392 | |
| 393 | nmh = malloc(sizeof(*nmh)); |
| 394 | if (!nmh) |
| 395 | return NULL; |
| 396 | |
| 397 | nmh->cfg = cfg; |
| 398 | |
| 399 | return nmh; |
| 400 | } |
| 401 | |
| 402 | /* free all resources */ |
| 403 | void abis_nm_fini(struct abis_nm_h *nmh) |
| 404 | { |
| 405 | free(nmh); |
| 406 | } |
| 407 | #endif |
| 408 | |
| 409 | /* Here we are trying to define a high-level API that can be used by |
| 410 | * the actual BSC implementation. However, the architecture is currently |
| 411 | * still under design. Ideally the calls to this API would be synchronous, |
| 412 | * while the underlying stack behind the APi runs in a traditional select |
| 413 | * based state machine. |
| 414 | */ |
| 415 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 416 | /* 6.2 Software Load: */ |
| 417 | enum sw_state { |
| 418 | SW_STATE_NONE, |
| 419 | SW_STATE_WAIT_INITACK, |
| 420 | SW_STATE_WAIT_SEGACK, |
| 421 | SW_STATE_WAIT_ENDACK, |
| 422 | SW_STATE_WAIT_ACTACK, |
| 423 | SW_STATE_ERROR, |
| 424 | }; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 425 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 426 | struct abis_nm_sw { |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 427 | struct gsm_bts *bts; |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 428 | gsm_cbfn *cbfn; |
| 429 | void *cb_data; |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 430 | int forced; |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 431 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 432 | /* this will become part of the SW LOAD INITIATE */ |
| 433 | u_int8_t obj_class; |
| 434 | u_int8_t obj_instance[3]; |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 435 | |
| 436 | u_int8_t file_id[255]; |
| 437 | u_int8_t file_id_len; |
| 438 | |
| 439 | u_int8_t file_version[255]; |
| 440 | u_int8_t file_version_len; |
| 441 | |
| 442 | u_int8_t window_size; |
| 443 | u_int8_t seg_in_window; |
| 444 | |
| 445 | int fd; |
| 446 | FILE *stream; |
| 447 | enum sw_state state; |
Harald Welte | 1602ade | 2009-01-29 21:12:39 +0000 | [diff] [blame] | 448 | int last_seg; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 449 | }; |
| 450 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 451 | static struct abis_nm_sw g_sw; |
| 452 | |
| 453 | /* 6.2.1 / 8.3.1: Load Data Initiate */ |
| 454 | static int sw_load_init(struct abis_nm_sw *sw) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 455 | { |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 456 | struct abis_om_hdr *oh; |
| 457 | struct msgb *msg = nm_msgb_alloc(); |
| 458 | u_int8_t len = 3*2 + sw->file_id_len + sw->file_version_len; |
| 459 | |
| 460 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 461 | fill_om_fom_hdr(oh, len, NM_MT_LOAD_INIT, sw->obj_class, |
| 462 | sw->obj_instance[0], sw->obj_instance[1], |
| 463 | sw->obj_instance[2]); |
| 464 | |
| 465 | /* FIXME: this is BS11 specific format */ |
| 466 | msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id); |
| 467 | msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len, |
| 468 | sw->file_version); |
| 469 | msgb_tv_put(msg, NM_ATT_WINDOW_SIZE, sw->window_size); |
| 470 | |
| 471 | return abis_nm_sendmsg(sw->bts, msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 472 | } |
| 473 | |
Harald Welte | 1602ade | 2009-01-29 21:12:39 +0000 | [diff] [blame] | 474 | static int is_last_line(FILE *stream) |
| 475 | { |
| 476 | char next_seg_buf[256]; |
| 477 | long pos; |
| 478 | |
| 479 | /* check if we're sending the last line */ |
| 480 | pos = ftell(stream); |
| 481 | if (!fgets(next_seg_buf, sizeof(next_seg_buf)-2, stream)) { |
| 482 | fseek(stream, pos, SEEK_SET); |
| 483 | return 1; |
| 484 | } |
| 485 | |
| 486 | fseek(stream, pos, SEEK_SET); |
| 487 | return 0; |
| 488 | } |
| 489 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 490 | /* 6.2.2 / 8.3.2 Load Data Segment */ |
| 491 | static int sw_load_segment(struct abis_nm_sw *sw) |
| 492 | { |
| 493 | struct abis_om_hdr *oh; |
| 494 | struct msgb *msg = nm_msgb_alloc(); |
| 495 | char seg_buf[256]; |
| 496 | char *line_buf = seg_buf+2; |
Harald Welte | 3b8ba21 | 2009-01-29 12:27:58 +0000 | [diff] [blame] | 497 | unsigned char *tlv; |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 498 | u_int8_t len; |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 499 | |
| 500 | 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] | 501 | |
| 502 | switch (sw->bts->type) { |
| 503 | case GSM_BTS_TYPE_BS11: |
| 504 | if (fgets(line_buf, sizeof(seg_buf)-2, sw->stream) == NULL) { |
| 505 | perror("fgets reading segment"); |
| 506 | return -EINVAL; |
| 507 | } |
| 508 | seg_buf[0] = 0x00; |
Harald Welte | 1602ade | 2009-01-29 21:12:39 +0000 | [diff] [blame] | 509 | |
| 510 | /* check if we're sending the last line */ |
| 511 | sw->last_seg = is_last_line(sw->stream); |
| 512 | if (sw->last_seg) |
| 513 | seg_buf[1] = 0; |
| 514 | else |
| 515 | seg_buf[1] = 1 + sw->seg_in_window++; |
Harald Welte | 3b8ba21 | 2009-01-29 12:27:58 +0000 | [diff] [blame] | 516 | |
| 517 | len = strlen(line_buf) + 2; |
| 518 | tlv = msgb_put(msg, TLV_GROSS_LEN(len)); |
| 519 | tlv_put(tlv, NM_ATT_BS11_FILE_DATA, len, (u_int8_t *)seg_buf); |
| 520 | /* BS11 wants CR + LF in excess of the TLV length !?! */ |
| 521 | tlv[1] -= 2; |
| 522 | |
| 523 | /* we only now know the exact length for the OM hdr */ |
| 524 | len = strlen(line_buf)+2; |
| 525 | break; |
| 526 | default: |
| 527 | /* FIXME: Other BTS types */ |
| 528 | return -1; |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 529 | } |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 530 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 531 | fill_om_fom_hdr(oh, len, NM_MT_LOAD_SEG, sw->obj_class, |
| 532 | sw->obj_instance[0], sw->obj_instance[1], |
| 533 | sw->obj_instance[2]); |
| 534 | |
| 535 | return abis_nm_sendmsg(sw->bts, msg); |
| 536 | } |
| 537 | |
| 538 | /* 6.2.4 / 8.3.4 Load Data End */ |
| 539 | static int sw_load_end(struct abis_nm_sw *sw) |
| 540 | { |
| 541 | struct abis_om_hdr *oh; |
| 542 | struct msgb *msg = nm_msgb_alloc(); |
| 543 | u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len; |
| 544 | |
| 545 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 546 | fill_om_fom_hdr(oh, len, NM_MT_LOAD_END, sw->obj_class, |
| 547 | sw->obj_instance[0], sw->obj_instance[1], |
| 548 | sw->obj_instance[2]); |
| 549 | |
| 550 | /* FIXME: this is BS11 specific format */ |
| 551 | msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id); |
| 552 | msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len, |
| 553 | sw->file_version); |
| 554 | |
| 555 | return abis_nm_sendmsg(sw->bts, msg); |
| 556 | } |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 557 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 558 | /* Activate the specified software into the BTS */ |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 559 | static int sw_activate(struct abis_nm_sw *sw) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 560 | { |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 561 | struct abis_om_hdr *oh; |
| 562 | struct msgb *msg = nm_msgb_alloc(); |
| 563 | 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] | 564 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 565 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 566 | fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, sw->obj_class, |
| 567 | sw->obj_instance[0], sw->obj_instance[1], |
| 568 | sw->obj_instance[2]); |
| 569 | |
| 570 | /* FIXME: this is BS11 specific format */ |
| 571 | msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id); |
| 572 | msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len, |
| 573 | sw->file_version); |
| 574 | |
| 575 | return abis_nm_sendmsg(sw->bts, msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 576 | } |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 577 | |
| 578 | static int sw_open_file(struct abis_nm_sw *sw, const char *fname) |
| 579 | { |
| 580 | char file_id[12+1]; |
| 581 | char file_version[80+1]; |
| 582 | int rc; |
| 583 | |
| 584 | sw->fd = open(fname, O_RDONLY); |
| 585 | if (sw->fd < 0) |
| 586 | return sw->fd; |
| 587 | |
| 588 | switch (sw->bts->type) { |
| 589 | case GSM_BTS_TYPE_BS11: |
| 590 | sw->stream = fdopen(sw->fd, "r"); |
| 591 | if (!sw->stream) { |
| 592 | perror("fdopen"); |
| 593 | return -1; |
| 594 | } |
| 595 | /* read first line and parse file ID and VERSION */ |
Harald Welte | 3b8ba21 | 2009-01-29 12:27:58 +0000 | [diff] [blame] | 596 | rc = fscanf(sw->stream, "@(#)%12s:%80s\r\n", |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 597 | file_id, file_version); |
| 598 | if (rc != 2) { |
| 599 | perror("parsing header line of software file"); |
| 600 | return -1; |
| 601 | } |
| 602 | strcpy((char *)sw->file_id, file_id); |
| 603 | sw->file_id_len = strlen(file_id); |
| 604 | strcpy((char *)sw->file_version, file_version); |
| 605 | sw->file_version_len = strlen(file_version); |
| 606 | /* rewind to start of file */ |
Harald Welte | 3b8ba21 | 2009-01-29 12:27:58 +0000 | [diff] [blame] | 607 | rewind(sw->stream); |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 608 | break; |
| 609 | default: |
| 610 | /* We don't know how to treat them yet */ |
| 611 | close(sw->fd); |
| 612 | return -EINVAL; |
| 613 | } |
| 614 | |
| 615 | return 0; |
| 616 | } |
| 617 | |
| 618 | static void sw_close_file(struct abis_nm_sw *sw) |
| 619 | { |
| 620 | switch (sw->bts->type) { |
| 621 | case GSM_BTS_TYPE_BS11: |
| 622 | fclose(sw->stream); |
| 623 | break; |
| 624 | default: |
| 625 | close(sw->fd); |
| 626 | break; |
| 627 | } |
| 628 | } |
| 629 | |
| 630 | /* Fill the window */ |
| 631 | static int sw_fill_window(struct abis_nm_sw *sw) |
| 632 | { |
| 633 | int rc; |
| 634 | |
| 635 | while (sw->seg_in_window < sw->window_size) { |
| 636 | rc = sw_load_segment(sw); |
| 637 | if (rc < 0) |
| 638 | return rc; |
Harald Welte | 1602ade | 2009-01-29 21:12:39 +0000 | [diff] [blame] | 639 | if (sw->last_seg) |
| 640 | break; |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 641 | } |
| 642 | return 0; |
| 643 | } |
| 644 | |
| 645 | /* callback function from abis_nm_rcvmsg() handler */ |
| 646 | static int abis_nm_rcvmsg_sw(struct msgb *mb) |
| 647 | { |
| 648 | struct abis_om_fom_hdr *foh = msgb_l3(mb); |
| 649 | int rc = -1; |
| 650 | struct abis_nm_sw *sw = &g_sw; |
| 651 | enum sw_state old_state = sw->state; |
| 652 | |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 653 | //DEBUGP(DNM, "state %u, NM MT 0x%02x\n", sw->state, foh->msg_type); |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 654 | |
| 655 | switch (sw->state) { |
| 656 | case SW_STATE_WAIT_INITACK: |
| 657 | switch (foh->msg_type) { |
| 658 | case NM_MT_LOAD_INIT_ACK: |
| 659 | /* fill window with segments */ |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 660 | if (sw->cbfn) |
| 661 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 662 | NM_MT_LOAD_INIT_ACK, mb, |
| 663 | sw->cb_data, NULL); |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 664 | rc = sw_fill_window(sw); |
| 665 | sw->state = SW_STATE_WAIT_SEGACK; |
| 666 | break; |
| 667 | case NM_MT_LOAD_INIT_NACK: |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 668 | if (sw->forced) { |
| 669 | DEBUGP(DNM, "FORCED: Ignoring Software Load " |
| 670 | "Init NACK\n"); |
| 671 | if (sw->cbfn) |
| 672 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 673 | NM_MT_LOAD_INIT_ACK, mb, |
| 674 | sw->cb_data, NULL); |
| 675 | rc = sw_fill_window(sw); |
| 676 | sw->state = SW_STATE_WAIT_SEGACK; |
| 677 | } else { |
| 678 | DEBUGP(DNM, "Software Load Init NACK\n"); |
| 679 | if (sw->cbfn) |
| 680 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 681 | NM_MT_LOAD_INIT_NACK, mb, |
| 682 | sw->cb_data, NULL); |
| 683 | sw->state = SW_STATE_ERROR; |
| 684 | } |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 685 | break; |
| 686 | } |
| 687 | break; |
| 688 | case SW_STATE_WAIT_SEGACK: |
| 689 | switch (foh->msg_type) { |
| 690 | case NM_MT_LOAD_SEG_ACK: |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 691 | if (sw->cbfn) |
| 692 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 693 | NM_MT_LOAD_SEG_ACK, mb, |
| 694 | sw->cb_data, NULL); |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 695 | sw->seg_in_window = 0; |
Harald Welte | 1602ade | 2009-01-29 21:12:39 +0000 | [diff] [blame] | 696 | if (!sw->last_seg) { |
| 697 | /* fill window with more segments */ |
| 698 | rc = sw_fill_window(sw); |
| 699 | sw->state = SW_STATE_WAIT_SEGACK; |
| 700 | } else { |
| 701 | /* end the transfer */ |
| 702 | sw->state = SW_STATE_WAIT_ENDACK; |
| 703 | rc = sw_load_end(sw); |
| 704 | } |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 705 | break; |
| 706 | } |
| 707 | break; |
| 708 | case SW_STATE_WAIT_ENDACK: |
| 709 | switch (foh->msg_type) { |
| 710 | case NM_MT_LOAD_END_ACK: |
| 711 | sw_close_file(sw); |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 712 | DEBUGP(DNM, "Software Load End (BTS %u)\n", |
| 713 | sw->bts->nr); |
| 714 | sw->state = SW_STATE_NONE; |
| 715 | if (sw->cbfn) |
| 716 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 717 | NM_MT_LOAD_END_ACK, mb, |
| 718 | sw->cb_data, NULL); |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 719 | break; |
| 720 | case NM_MT_LOAD_END_NACK: |
Holger Freyther | 31338a1 | 2009-02-06 17:43:50 +0000 | [diff] [blame] | 721 | if (sw->forced) { |
| 722 | DEBUGP(DNM, "FORCED: Ignoring Software Load" |
| 723 | "End NACK\n"); |
| 724 | sw->state = SW_STATE_NONE; |
| 725 | if (sw->cbfn) |
| 726 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 727 | NM_MT_LOAD_END_ACK, mb, |
| 728 | sw->cb_data, NULL); |
| 729 | } else { |
| 730 | DEBUGP(DNM, "Software Load End NACK\n"); |
| 731 | sw->state = SW_STATE_ERROR; |
| 732 | if (sw->cbfn) |
| 733 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 734 | NM_MT_LOAD_END_NACK, mb, |
| 735 | sw->cb_data, NULL); |
| 736 | } |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 737 | break; |
| 738 | } |
| 739 | case SW_STATE_WAIT_ACTACK: |
| 740 | switch (foh->msg_type) { |
| 741 | case NM_MT_ACTIVATE_SW_ACK: |
| 742 | /* we're done */ |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 743 | DEBUGP(DNM, "Activate Software DONE!\n"); |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 744 | sw->state = SW_STATE_NONE; |
| 745 | rc = 0; |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 746 | if (sw->cbfn) |
| 747 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 748 | NM_MT_ACTIVATE_SW_ACK, mb, |
| 749 | sw->cb_data, NULL); |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 750 | break; |
| 751 | case NM_MT_ACTIVATE_SW_NACK: |
Harald Welte | 1602ade | 2009-01-29 21:12:39 +0000 | [diff] [blame] | 752 | DEBUGP(DNM, "Activate Software NACK\n"); |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 753 | sw->state = SW_STATE_ERROR; |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 754 | if (sw->cbfn) |
| 755 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 756 | NM_MT_ACTIVATE_SW_NACK, mb, |
| 757 | sw->cb_data, NULL); |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 758 | break; |
| 759 | } |
| 760 | case SW_STATE_NONE: |
| 761 | case SW_STATE_ERROR: |
| 762 | break; |
| 763 | } |
| 764 | |
| 765 | if (rc) |
| 766 | fprintf(stderr, "unexpected NM MT 0x%02x in state %u -> %u\n", |
| 767 | foh->msg_type, old_state, sw->state); |
| 768 | |
| 769 | return rc; |
| 770 | } |
| 771 | |
| 772 | /* Load the specified software into the BTS */ |
| 773 | int abis_nm_software_load(struct gsm_bts *bts, const char *fname, |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 774 | u_int8_t win_size, int forced, |
| 775 | gsm_cbfn *cbfn, void *cb_data) |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 776 | { |
| 777 | struct abis_nm_sw *sw = &g_sw; |
| 778 | int rc; |
| 779 | |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 780 | DEBUGP(DNM, "Software Load (BTS %u, File \"%s\")\n", |
| 781 | bts->nr, fname); |
| 782 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 783 | if (sw->state != SW_STATE_NONE) |
| 784 | return -EBUSY; |
| 785 | |
| 786 | sw->bts = bts; |
| 787 | sw->obj_class = NM_OC_SITE_MANAGER; |
| 788 | sw->obj_instance[0] = 0xff; |
| 789 | sw->obj_instance[1] = 0xff; |
| 790 | sw->obj_instance[2] = 0xff; |
| 791 | sw->window_size = win_size; |
| 792 | sw->state = SW_STATE_WAIT_INITACK; |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 793 | sw->cbfn = cbfn; |
| 794 | sw->cb_data = cb_data; |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 795 | sw->forced = forced; |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 796 | |
| 797 | rc = sw_open_file(sw, fname); |
| 798 | if (rc < 0) { |
| 799 | sw->state = SW_STATE_NONE; |
| 800 | return rc; |
| 801 | } |
| 802 | |
| 803 | return sw_load_init(sw); |
| 804 | } |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 805 | |
Harald Welte | 1602ade | 2009-01-29 21:12:39 +0000 | [diff] [blame] | 806 | int abis_nm_software_load_status(struct gsm_bts *bts) |
| 807 | { |
| 808 | struct abis_nm_sw *sw = &g_sw; |
| 809 | struct stat st; |
| 810 | int rc, percent; |
| 811 | |
| 812 | rc = fstat(sw->fd, &st); |
| 813 | if (rc < 0) { |
| 814 | perror("ERROR during stat"); |
| 815 | return rc; |
| 816 | } |
| 817 | |
| 818 | percent = (ftell(sw->stream) * 100) / st.st_size; |
| 819 | return percent; |
| 820 | } |
| 821 | |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 822 | /* Activate the specified software into the BTS */ |
| 823 | int abis_nm_software_activate(struct gsm_bts *bts, const char *fname, |
| 824 | gsm_cbfn *cbfn, void *cb_data) |
| 825 | { |
| 826 | struct abis_nm_sw *sw = &g_sw; |
| 827 | int rc; |
| 828 | |
| 829 | DEBUGP(DNM, "Activating Software (BTS %u, File \"%s\")\n", |
| 830 | bts->nr, fname); |
| 831 | |
| 832 | if (sw->state != SW_STATE_NONE) |
| 833 | return -EBUSY; |
| 834 | |
| 835 | sw->bts = bts; |
| 836 | sw->obj_class = NM_OC_SITE_MANAGER; |
| 837 | sw->obj_instance[0] = 0xff; |
| 838 | sw->obj_instance[1] = 0xff; |
| 839 | sw->obj_instance[2] = 0xff; |
| 840 | sw->state = SW_STATE_WAIT_ACTACK; |
| 841 | sw->cbfn = cbfn; |
| 842 | sw->cb_data = cb_data; |
| 843 | |
| 844 | /* Open the file in order to fill some sw struct members */ |
| 845 | rc = sw_open_file(sw, fname); |
| 846 | if (rc < 0) { |
| 847 | sw->state = SW_STATE_NONE; |
| 848 | return rc; |
| 849 | } |
| 850 | sw_close_file(sw); |
| 851 | |
| 852 | return sw_activate(sw); |
| 853 | } |
| 854 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 855 | 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] | 856 | u_int8_t ts_nr, u_int8_t subslot_nr) |
| 857 | { |
Harald Welte | adaf08b | 2009-01-18 11:08:10 +0000 | [diff] [blame] | 858 | ch->attrib = NM_ATT_ABIS_CHANNEL; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 859 | ch->bts_port = bts_port; |
| 860 | ch->timeslot = ts_nr; |
| 861 | ch->subslot = subslot_nr; |
| 862 | } |
| 863 | |
| 864 | int abis_nm_establish_tei(struct gsm_bts *bts, u_int8_t trx_nr, |
| 865 | u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot, |
| 866 | u_int8_t tei) |
| 867 | { |
| 868 | struct abis_om_hdr *oh; |
| 869 | struct abis_nm_channel *ch; |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 870 | u_int8_t len = sizeof(*ch) + 2; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 871 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 872 | |
| 873 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 874 | fill_om_fom_hdr(oh, len, NM_MT_ESTABLISH_TEI, NM_OC_RADIO_CARRIER, |
| 875 | bts->bts_nr, trx_nr, 0xff); |
| 876 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 877 | msgb_tv_put(msg, NM_ATT_TEI, tei); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 878 | |
| 879 | ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch)); |
| 880 | fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot); |
| 881 | |
| 882 | return abis_nm_sendmsg(bts, msg); |
| 883 | } |
| 884 | |
| 885 | /* connect signalling of one (BTS,TRX) to a particular timeslot on the E1 */ |
| 886 | int abis_nm_conn_terr_sign(struct gsm_bts_trx *trx, |
| 887 | u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot) |
| 888 | { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 889 | struct gsm_bts *bts = trx->bts; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 890 | struct abis_om_hdr *oh; |
| 891 | struct abis_nm_channel *ch; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 892 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 893 | |
| 894 | 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] | 895 | fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_SIGN, |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 896 | NM_OC_RADIO_CARRIER, bts->bts_nr, trx->nr, 0xff); |
| 897 | |
| 898 | ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch)); |
| 899 | fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot); |
| 900 | |
| 901 | return abis_nm_sendmsg(bts, msg); |
| 902 | } |
| 903 | |
| 904 | #if 0 |
| 905 | int abis_nm_disc_terr_sign(struct abis_nm_h *h, struct abis_om_obj_inst *inst, |
| 906 | struct abis_nm_abis_channel *chan) |
| 907 | { |
| 908 | } |
| 909 | #endif |
| 910 | |
| 911 | int abis_nm_conn_terr_traf(struct gsm_bts_trx_ts *ts, |
| 912 | u_int8_t e1_port, u_int8_t e1_timeslot, |
| 913 | u_int8_t e1_subslot) |
| 914 | { |
| 915 | struct gsm_bts *bts = ts->trx->bts; |
| 916 | struct abis_om_hdr *oh; |
| 917 | struct abis_nm_channel *ch; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 918 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 919 | |
| 920 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 921 | fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_TRAF, |
| 922 | NM_OC_BASEB_TRANSC, bts->bts_nr, ts->trx->nr, ts->nr); |
| 923 | |
| 924 | ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch)); |
| 925 | fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot); |
| 926 | |
| 927 | return abis_nm_sendmsg(bts, msg); |
| 928 | } |
| 929 | |
| 930 | #if 0 |
| 931 | int abis_nm_disc_terr_traf(struct abis_nm_h *h, struct abis_om_obj_inst *inst, |
| 932 | struct abis_nm_abis_channel *chan, |
| 933 | u_int8_t subchan) |
| 934 | { |
| 935 | } |
| 936 | #endif |
| 937 | |
Harald Welte | 22af0db | 2009-02-14 15:41:08 +0000 | [diff] [blame] | 938 | /* Chapter 8.6.1 */ |
| 939 | int abis_nm_set_bts_attr(struct gsm_bts *bts, u_int8_t *attr, int attr_len) |
| 940 | { |
| 941 | struct abis_om_hdr *oh; |
| 942 | struct msgb *msg = nm_msgb_alloc(); |
| 943 | u_int8_t *cur; |
| 944 | |
| 945 | DEBUGP(DNM, "Set BTS Attr (bts=%d)\n", bts->nr); |
| 946 | |
| 947 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 948 | fill_om_fom_hdr(oh, attr_len, NM_MT_SET_BTS_ATTR, NM_OC_BTS, bts->nr, 0xff, 0xff); |
| 949 | cur = msgb_put(msg, attr_len); |
| 950 | memcpy(cur, attr, attr_len); |
| 951 | |
| 952 | return abis_nm_sendmsg(bts, msg); |
| 953 | } |
| 954 | |
| 955 | /* Chapter 8.6.2 */ |
| 956 | int abis_nm_set_radio_attr(struct gsm_bts_trx *trx, u_int8_t *attr, int attr_len) |
| 957 | { |
| 958 | struct abis_om_hdr *oh; |
| 959 | struct msgb *msg = nm_msgb_alloc(); |
| 960 | u_int8_t *cur; |
| 961 | |
| 962 | DEBUGP(DNM, "Set TRX Attr (bts=%d,trx=%d)\n", trx->bts->nr, trx->nr); |
| 963 | |
| 964 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 965 | fill_om_fom_hdr(oh, attr_len, NM_MT_SET_RADIO_ATTR, NM_OC_RADIO_CARRIER, |
| 966 | trx->bts->nr, trx->nr, 0xff); |
| 967 | cur = msgb_put(msg, attr_len); |
| 968 | memcpy(cur, attr, attr_len); |
| 969 | |
| 970 | return abis_nm_sendmsg(trx->bts, msg); |
| 971 | } |
| 972 | |
| 973 | /* Chapter 8.6.3 */ |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 974 | int abis_nm_set_channel_attr(struct gsm_bts_trx_ts *ts, u_int8_t chan_comb) |
| 975 | { |
| 976 | struct gsm_bts *bts = ts->trx->bts; |
| 977 | struct abis_om_hdr *oh; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 978 | u_int16_t arfcn = htons(ts->trx->arfcn); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 979 | u_int8_t zero = 0x00; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 980 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 981 | u_int8_t len = 4 + 2 + 2 + 2 + 2 +3; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 982 | |
Harald Welte | 22af0db | 2009-02-14 15:41:08 +0000 | [diff] [blame] | 983 | DEBUGP(DNM, "Set Chan Attr (bts=%d,trx=%d,ts=%d)\n", bts->nr, ts->trx->nr, ts->nr); |
| 984 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 985 | 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] | 986 | fill_om_fom_hdr(oh, len, NM_MT_SET_CHAN_ATTR, |
Holger Freyther | 6b2d262 | 2009-02-14 23:16:59 +0000 | [diff] [blame] | 987 | NM_OC_CHANNEL, bts->bts_nr, |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 988 | ts->trx->nr, ts->nr); |
| 989 | /* FIXME: don't send ARFCN list, hopping sequence, mAIO, ...*/ |
| 990 | msgb_tlv16_put(msg, NM_ATT_ARFCN_LIST, 1, &arfcn); |
| 991 | msgb_tv_put(msg, NM_ATT_CHAN_COMB, chan_comb); |
| 992 | msgb_tv_put(msg, NM_ATT_HSN, 0x00); |
| 993 | msgb_tv_put(msg, NM_ATT_MAIO, 0x00); |
| 994 | msgb_tv_put(msg, NM_ATT_TSC, 0x07); /* training sequence */ |
| 995 | msgb_tlv_put(msg, 0x59, 1, &zero); |
| 996 | |
| 997 | return abis_nm_sendmsg(bts, msg); |
| 998 | } |
| 999 | |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 1000 | int abis_nm_sw_act_req_ack(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i1, |
| 1001 | u_int8_t i2, u_int8_t i3, u_int8_t *attr, int att_len) |
| 1002 | { |
| 1003 | struct abis_om_hdr *oh; |
| 1004 | struct msgb *msg = nm_msgb_alloc(); |
| 1005 | |
| 1006 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1007 | fill_om_fom_hdr(oh, att_len, NM_MT_SW_ACT_REQ_ACK, obj_class, i1, i2, i3); |
| 1008 | /* FIXME: don't send ARFCN list, hopping sequence, mAIO, ...*/ |
| 1009 | if (attr) { |
| 1010 | u_int8_t *ptr = msgb_put(msg, att_len); |
| 1011 | memcpy(ptr, attr, att_len); |
| 1012 | } |
| 1013 | |
| 1014 | return abis_nm_sendmsg(bts, msg); |
| 1015 | } |
| 1016 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1017 | 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] | 1018 | { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1019 | struct msgb *msg = nm_msgb_alloc(); |
| 1020 | struct abis_om_hdr *oh; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1021 | u_int8_t *data; |
| 1022 | |
| 1023 | oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh)); |
| 1024 | fill_om_hdr(oh, len); |
| 1025 | data = msgb_put(msg, len); |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 1026 | memcpy(data, rawmsg, len); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1027 | |
| 1028 | return abis_nm_sendmsg(bts, msg); |
| 1029 | } |
| 1030 | |
| 1031 | /* Siemens specific commands */ |
| 1032 | static int __simple_cmd(struct gsm_bts *bts, u_int8_t msg_type) |
| 1033 | { |
| 1034 | struct abis_om_hdr *oh; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1035 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1036 | |
| 1037 | 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] | 1038 | fill_om_fom_hdr(oh, 0, msg_type, NM_OC_SITE_MANAGER, |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1039 | 0xff, 0xff, 0xff); |
| 1040 | |
| 1041 | return abis_nm_sendmsg(bts, msg); |
| 1042 | } |
| 1043 | |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 1044 | /* Chapter 8.9.2 */ |
| 1045 | int abis_nm_opstart(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1, u_int8_t i2) |
| 1046 | { |
| 1047 | struct abis_om_hdr *oh; |
| 1048 | struct msgb *msg = nm_msgb_alloc(); |
| 1049 | |
Harald Welte | 22af0db | 2009-02-14 15:41:08 +0000 | [diff] [blame] | 1050 | DEBUGP(DNM, "Sending OPSTART obj_class=0x%02x obj_inst=(0x%02x, 0x%02x, 0x%02x)\n", |
| 1051 | obj_class, i0, i1, i2); |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 1052 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1053 | fill_om_fom_hdr(oh, 0, NM_MT_OPSTART, obj_class, i0, i1, i2); |
| 1054 | |
| 1055 | return abis_nm_sendmsg(bts, msg); |
| 1056 | } |
| 1057 | |
| 1058 | /* Chapter 8.8.5 */ |
| 1059 | int abis_nm_chg_adm_state(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, |
| 1060 | u_int8_t i1, u_int8_t i2, u_int8_t adm_state) |
| 1061 | { |
| 1062 | struct abis_om_hdr *oh; |
| 1063 | struct msgb *msg = nm_msgb_alloc(); |
| 1064 | |
| 1065 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1066 | fill_om_fom_hdr(oh, 2, NM_MT_CHG_ADM_STATE, obj_class, i0, i1, i2); |
| 1067 | msgb_tv_put(msg, NM_ATT_ADM_STATE, adm_state); |
| 1068 | |
| 1069 | return abis_nm_sendmsg(bts, msg); |
| 1070 | } |
| 1071 | |
| 1072 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1073 | int abis_nm_event_reports(struct gsm_bts *bts, int on) |
| 1074 | { |
| 1075 | if (on == 0) |
Harald Welte | 227d407 | 2009-01-03 08:16:25 +0000 | [diff] [blame] | 1076 | return __simple_cmd(bts, NM_MT_STOP_EVENT_REP); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1077 | else |
Harald Welte | 227d407 | 2009-01-03 08:16:25 +0000 | [diff] [blame] | 1078 | return __simple_cmd(bts, NM_MT_REST_EVENT_REP); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1079 | } |
| 1080 | |
Harald Welte | 47d88ae | 2009-01-04 12:02:08 +0000 | [diff] [blame] | 1081 | /* Siemens (or BS-11) specific commands */ |
| 1082 | |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 1083 | int abis_nm_bs11_bsc_disconnect(struct gsm_bts *bts, int reconnect) |
| 1084 | { |
| 1085 | if (reconnect == 0) |
| 1086 | return __simple_cmd(bts, NM_MT_BS11_DISCONNECT); |
| 1087 | else |
| 1088 | return __simple_cmd(bts, NM_MT_BS11_RECONNECT); |
| 1089 | } |
| 1090 | |
Harald Welte | b842797 | 2009-02-05 19:27:17 +0000 | [diff] [blame] | 1091 | int abis_nm_bs11_restart(struct gsm_bts *bts) |
| 1092 | { |
| 1093 | return __simple_cmd(bts, NM_MT_BS11_RESTART); |
| 1094 | } |
| 1095 | |
| 1096 | |
Harald Welte | 268bb40 | 2009-02-01 19:11:56 +0000 | [diff] [blame] | 1097 | struct bs11_date_time { |
| 1098 | u_int16_t year; |
| 1099 | u_int8_t month; |
| 1100 | u_int8_t day; |
| 1101 | u_int8_t hour; |
| 1102 | u_int8_t min; |
| 1103 | u_int8_t sec; |
| 1104 | } __attribute__((packed)); |
| 1105 | |
| 1106 | |
| 1107 | void get_bs11_date_time(struct bs11_date_time *aet) |
| 1108 | { |
| 1109 | time_t t; |
| 1110 | struct tm *tm; |
| 1111 | |
| 1112 | t = time(NULL); |
| 1113 | tm = localtime(&t); |
| 1114 | aet->sec = tm->tm_sec; |
| 1115 | aet->min = tm->tm_min; |
| 1116 | aet->hour = tm->tm_hour; |
| 1117 | aet->day = tm->tm_mday; |
| 1118 | aet->month = tm->tm_mon; |
| 1119 | aet->year = htons(1900 + tm->tm_year); |
| 1120 | } |
| 1121 | |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1122 | int abis_nm_bs11_reset_resource(struct gsm_bts *bts) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1123 | { |
Harald Welte | 4668fda | 2009-01-03 08:19:29 +0000 | [diff] [blame] | 1124 | return __simple_cmd(bts, NM_MT_BS11_RESET_RESOURCE); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1125 | } |
| 1126 | |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1127 | int abis_nm_bs11_db_transmission(struct gsm_bts *bts, int begin) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1128 | { |
| 1129 | if (begin) |
Harald Welte | 4668fda | 2009-01-03 08:19:29 +0000 | [diff] [blame] | 1130 | return __simple_cmd(bts, NM_MT_BS11_BEGIN_DB_TX); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1131 | else |
Harald Welte | 4668fda | 2009-01-03 08:19:29 +0000 | [diff] [blame] | 1132 | return __simple_cmd(bts, NM_MT_BS11_END_DB_TX); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1133 | } |
Harald Welte | 47d88ae | 2009-01-04 12:02:08 +0000 | [diff] [blame] | 1134 | |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1135 | int abis_nm_bs11_create_object(struct gsm_bts *bts, |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1136 | enum abis_bs11_objtype type, u_int8_t idx, |
| 1137 | u_int8_t attr_len, const u_int8_t *attr) |
Harald Welte | 47d88ae | 2009-01-04 12:02:08 +0000 | [diff] [blame] | 1138 | { |
| 1139 | struct abis_om_hdr *oh; |
| 1140 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1141 | u_int8_t *cur; |
Harald Welte | 47d88ae | 2009-01-04 12:02:08 +0000 | [diff] [blame] | 1142 | |
| 1143 | 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] | 1144 | fill_om_fom_hdr(oh, attr_len, NM_MT_BS11_CREATE_OBJ, |
Harald Welte | 268bb40 | 2009-02-01 19:11:56 +0000 | [diff] [blame] | 1145 | NM_OC_BS11, type, 0, idx); |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1146 | cur = msgb_put(msg, attr_len); |
| 1147 | memcpy(cur, attr, attr_len); |
Harald Welte | 47d88ae | 2009-01-04 12:02:08 +0000 | [diff] [blame] | 1148 | |
| 1149 | return abis_nm_sendmsg(bts, msg); |
| 1150 | } |
| 1151 | |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1152 | 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] | 1153 | { |
| 1154 | struct abis_om_hdr *oh; |
| 1155 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1156 | u_int8_t zero = 0x00; |
Harald Welte | 47d88ae | 2009-01-04 12:02:08 +0000 | [diff] [blame] | 1157 | |
| 1158 | 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] | 1159 | fill_om_fom_hdr(oh, 3, NM_MT_BS11_CREATE_OBJ, |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1160 | NM_OC_BS11_ENVABTSE, 0, idx, 0xff); |
| 1161 | msgb_tlv_put(msg, 0x99, 1, &zero); |
Harald Welte | 47d88ae | 2009-01-04 12:02:08 +0000 | [diff] [blame] | 1162 | |
| 1163 | return abis_nm_sendmsg(bts, msg); |
| 1164 | } |
| 1165 | |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1166 | 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] | 1167 | { |
| 1168 | struct abis_om_hdr *oh; |
| 1169 | struct msgb *msg = nm_msgb_alloc(); |
| 1170 | |
| 1171 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1172 | fill_om_fom_hdr(oh, 0, NM_MT_BS11_CREATE_OBJ, NM_OC_BS11_BPORT, |
| 1173 | idx, 0, 0); |
| 1174 | |
| 1175 | return abis_nm_sendmsg(bts, msg); |
| 1176 | } |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1177 | |
| 1178 | int abis_nm_bs11_set_oml_tei(struct gsm_bts *bts, u_int8_t tei) |
| 1179 | { |
| 1180 | struct abis_om_hdr *oh; |
| 1181 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1182 | |
| 1183 | 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] | 1184 | 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] | 1185 | 0xff, 0xff, 0xff); |
| 1186 | msgb_tv_put(msg, NM_ATT_TEI, tei); |
| 1187 | |
| 1188 | return abis_nm_sendmsg(bts, msg); |
| 1189 | } |
| 1190 | |
| 1191 | /* like abis_nm_conn_terr_traf */ |
| 1192 | int abis_nm_bs11_conn_oml(struct gsm_bts *bts, u_int8_t e1_port, |
| 1193 | u_int8_t e1_timeslot, u_int8_t e1_subslot) |
| 1194 | { |
| 1195 | struct abis_om_hdr *oh; |
| 1196 | struct abis_nm_channel *ch; |
| 1197 | struct msgb *msg = nm_msgb_alloc(); |
| 1198 | |
| 1199 | 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] | 1200 | fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_BS11_SET_ATTR, |
| 1201 | NM_OC_SITE_MANAGER, 0xff, 0xff, 0xff); |
| 1202 | |
| 1203 | ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch)); |
| 1204 | fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot); |
| 1205 | |
| 1206 | return abis_nm_sendmsg(bts, msg); |
| 1207 | } |
| 1208 | |
| 1209 | int abis_nm_bs11_set_trx_power(struct gsm_bts_trx *trx, u_int8_t level) |
| 1210 | { |
| 1211 | struct abis_om_hdr *oh; |
| 1212 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1213 | |
| 1214 | 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] | 1215 | fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR, |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1216 | NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr); |
| 1217 | msgb_tlv_put(msg, NM_ATT_BS11_TXPWR, 1, &level); |
| 1218 | |
| 1219 | return abis_nm_sendmsg(trx->bts, msg); |
| 1220 | } |
| 1221 | |
Harald Welte | 268bb40 | 2009-02-01 19:11:56 +0000 | [diff] [blame] | 1222 | //static const u_int8_t bs11_logon_c7[] = { 0x07, 0xd9, 0x01, 0x11, 0x0d, 0x10, 0x20 }; |
Harald Welte | bb15131 | 2009-01-28 20:42:07 +0000 | [diff] [blame] | 1223 | static const u_int8_t bs11_logon_c8[] = { 0x02 }; |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1224 | static const u_int8_t bs11_logon_c9[] = "FACTORY"; |
| 1225 | |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1226 | int abis_nm_bs11_factory_logon(struct gsm_bts *bts, int on) |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1227 | { |
| 1228 | struct abis_om_hdr *oh; |
| 1229 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 268bb40 | 2009-02-01 19:11:56 +0000 | [diff] [blame] | 1230 | struct bs11_date_time bdt; |
| 1231 | |
| 1232 | get_bs11_date_time(&bdt); |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1233 | |
| 1234 | 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] | 1235 | if (on) { |
Harald Welte | 268bb40 | 2009-02-01 19:11:56 +0000 | [diff] [blame] | 1236 | u_int8_t len = 3*2 + sizeof(bdt) |
Harald Welte | 6f676a3 | 2009-01-18 14:27:48 +0000 | [diff] [blame] | 1237 | + sizeof(bs11_logon_c8) + sizeof(bs11_logon_c9); |
Harald Welte | 043d04a | 2009-01-29 23:15:30 +0000 | [diff] [blame] | 1238 | fill_om_fom_hdr(oh, len, NM_MT_BS11_LMT_LOGON, |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1239 | NM_OC_BS11_A3, 0xff, 0xff, 0xff); |
Harald Welte | 043d04a | 2009-01-29 23:15:30 +0000 | [diff] [blame] | 1240 | msgb_tlv_put(msg, NM_ATT_BS11_LMT_LOGIN_TIME, |
Harald Welte | 5083b0b | 2009-02-02 19:20:52 +0000 | [diff] [blame] | 1241 | sizeof(bdt), (u_int8_t *) &bdt); |
Harald Welte | 043d04a | 2009-01-29 23:15:30 +0000 | [diff] [blame] | 1242 | msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_ACC_LEV, |
| 1243 | sizeof(bs11_logon_c8), bs11_logon_c8); |
| 1244 | msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_NAME, |
| 1245 | sizeof(bs11_logon_c9), bs11_logon_c9); |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1246 | } else { |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1247 | fill_om_fom_hdr(oh, 0, NM_MT_BS11_LMT_LOGOFF, |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1248 | NM_OC_BS11_A3, 0xff, 0xff, 0xff); |
| 1249 | } |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1250 | |
| 1251 | return abis_nm_sendmsg(bts, msg); |
| 1252 | } |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1253 | |
| 1254 | int abis_nm_bs11_set_trx1_pw(struct gsm_bts *bts, const char *password) |
| 1255 | { |
| 1256 | struct abis_om_hdr *oh; |
| 1257 | struct msgb *msg; |
| 1258 | |
| 1259 | if (strlen(password) != 10) |
| 1260 | return -EINVAL; |
| 1261 | |
| 1262 | msg = nm_msgb_alloc(); |
| 1263 | 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] | 1264 | 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] | 1265 | NM_OC_BS11, BS11_OBJ_TRX1, 0x00, 0x00); |
| 1266 | msgb_tlv_put(msg, NM_ATT_BS11_PASSWORD, 10, (const u_int8_t *)password); |
| 1267 | |
| 1268 | return abis_nm_sendmsg(bts, msg); |
| 1269 | } |
| 1270 | |
| 1271 | int abis_nm_bs11_get_state(struct gsm_bts *bts) |
| 1272 | { |
| 1273 | return __simple_cmd(bts, NM_MT_BS11_GET_STATE); |
| 1274 | } |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1275 | |
| 1276 | /* BS11 SWL */ |
| 1277 | |
| 1278 | struct abis_nm_bs11_sw { |
| 1279 | struct gsm_bts *bts; |
| 1280 | char swl_fname[PATH_MAX]; |
| 1281 | u_int8_t win_size; |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 1282 | int forced; |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1283 | struct llist_head file_list; |
| 1284 | gsm_cbfn *user_cb; /* specified by the user */ |
| 1285 | }; |
| 1286 | static struct abis_nm_bs11_sw _g_bs11_sw, *g_bs11_sw = &_g_bs11_sw; |
| 1287 | |
| 1288 | struct file_list_entry { |
| 1289 | struct llist_head list; |
| 1290 | char fname[PATH_MAX]; |
| 1291 | }; |
| 1292 | |
| 1293 | struct file_list_entry *fl_dequeue(struct llist_head *queue) |
| 1294 | { |
| 1295 | struct llist_head *lh; |
| 1296 | |
| 1297 | if (llist_empty(queue)) |
| 1298 | return NULL; |
| 1299 | |
| 1300 | lh = queue->next; |
| 1301 | llist_del(lh); |
| 1302 | |
| 1303 | return llist_entry(lh, struct file_list_entry, list); |
| 1304 | } |
| 1305 | |
| 1306 | static int bs11_read_swl_file(struct abis_nm_bs11_sw *bs11_sw) |
| 1307 | { |
| 1308 | char linebuf[255]; |
| 1309 | struct llist_head *lh, *lh2; |
| 1310 | FILE *swl; |
| 1311 | int rc = 0; |
| 1312 | |
| 1313 | swl = fopen(bs11_sw->swl_fname, "r"); |
| 1314 | if (!swl) |
| 1315 | return -ENODEV; |
| 1316 | |
| 1317 | /* zero the stale file list, if any */ |
| 1318 | llist_for_each_safe(lh, lh2, &bs11_sw->file_list) { |
| 1319 | llist_del(lh); |
| 1320 | free(lh); |
| 1321 | } |
| 1322 | |
| 1323 | while (fgets(linebuf, sizeof(linebuf), swl)) { |
| 1324 | char file_id[12+1]; |
| 1325 | char file_version[80+1]; |
| 1326 | struct file_list_entry *fle; |
| 1327 | static char dir[PATH_MAX]; |
| 1328 | |
| 1329 | if (strlen(linebuf) < 4) |
| 1330 | continue; |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 1331 | |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1332 | rc = sscanf(linebuf+4, "%12s:%80s\r\n", file_id, file_version); |
| 1333 | if (rc < 0) { |
| 1334 | perror("ERR parsing SWL file"); |
| 1335 | rc = -EINVAL; |
| 1336 | goto out; |
| 1337 | } |
| 1338 | if (rc < 2) |
| 1339 | continue; |
| 1340 | |
| 1341 | fle = malloc(sizeof(*fle)); |
| 1342 | if (!fle) { |
| 1343 | rc = -ENOMEM; |
| 1344 | goto out; |
| 1345 | } |
| 1346 | memset(fle, 0, sizeof(*fle)); |
| 1347 | |
| 1348 | /* construct new filename */ |
| 1349 | strncpy(dir, bs11_sw->swl_fname, sizeof(dir)); |
| 1350 | strncat(fle->fname, dirname(dir), sizeof(fle->fname) - 1); |
| 1351 | strcat(fle->fname, "/"); |
| 1352 | strncat(fle->fname, file_id, sizeof(fle->fname) - 1 -strlen(fle->fname)); |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1353 | |
| 1354 | llist_add_tail(&fle->list, &bs11_sw->file_list); |
| 1355 | } |
| 1356 | |
| 1357 | out: |
| 1358 | fclose(swl); |
| 1359 | return rc; |
| 1360 | } |
| 1361 | |
| 1362 | /* bs11 swload specific callback, passed to abis_nm core swload */ |
| 1363 | static int bs11_swload_cbfn(unsigned int hook, unsigned int event, |
| 1364 | struct msgb *msg, void *data, void *param) |
| 1365 | { |
| 1366 | struct abis_nm_bs11_sw *bs11_sw = data; |
| 1367 | struct file_list_entry *fle; |
| 1368 | int rc = 0; |
| 1369 | |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1370 | switch (event) { |
| 1371 | case NM_MT_LOAD_END_ACK: |
| 1372 | fle = fl_dequeue(&bs11_sw->file_list); |
| 1373 | if (fle) { |
| 1374 | /* start download the next file of our file list */ |
| 1375 | rc = abis_nm_software_load(bs11_sw->bts, fle->fname, |
| 1376 | bs11_sw->win_size, |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 1377 | bs11_sw->forced, |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1378 | &bs11_swload_cbfn, bs11_sw); |
| 1379 | free(fle); |
| 1380 | } else { |
| 1381 | /* activate the SWL */ |
| 1382 | rc = abis_nm_software_activate(bs11_sw->bts, |
| 1383 | bs11_sw->swl_fname, |
| 1384 | bs11_swload_cbfn, |
| 1385 | bs11_sw); |
| 1386 | } |
| 1387 | break; |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 1388 | case NM_MT_LOAD_SEG_ACK: |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1389 | case NM_MT_LOAD_END_NACK: |
| 1390 | case NM_MT_LOAD_INIT_ACK: |
| 1391 | case NM_MT_LOAD_INIT_NACK: |
| 1392 | case NM_MT_ACTIVATE_SW_NACK: |
| 1393 | case NM_MT_ACTIVATE_SW_ACK: |
| 1394 | default: |
| 1395 | /* fallthrough to the user callback */ |
Harald Welte | 97ed1e7 | 2009-02-06 13:38:02 +0000 | [diff] [blame] | 1396 | if (bs11_sw->user_cb) |
| 1397 | rc = bs11_sw->user_cb(hook, event, msg, NULL, NULL); |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1398 | break; |
| 1399 | } |
| 1400 | |
| 1401 | return rc; |
| 1402 | } |
| 1403 | |
| 1404 | /* Siemens provides a SWL file that is a mere listing of all the other |
| 1405 | * files that are part of a software release. We need to upload first |
| 1406 | * the list file, and then each file that is listed in the list file */ |
| 1407 | int abis_nm_bs11_load_swl(struct gsm_bts *bts, const char *fname, |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 1408 | u_int8_t win_size, int forced, gsm_cbfn *cbfn) |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1409 | { |
| 1410 | struct abis_nm_bs11_sw *bs11_sw = g_bs11_sw; |
| 1411 | struct file_list_entry *fle; |
| 1412 | int rc = 0; |
| 1413 | |
| 1414 | INIT_LLIST_HEAD(&bs11_sw->file_list); |
| 1415 | bs11_sw->bts = bts; |
| 1416 | bs11_sw->win_size = win_size; |
| 1417 | bs11_sw->user_cb = cbfn; |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 1418 | bs11_sw->forced = forced; |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1419 | |
| 1420 | strncpy(bs11_sw->swl_fname, fname, sizeof(bs11_sw->swl_fname)); |
| 1421 | rc = bs11_read_swl_file(bs11_sw); |
| 1422 | if (rc < 0) |
| 1423 | return rc; |
| 1424 | |
| 1425 | /* dequeue next item in file list */ |
| 1426 | fle = fl_dequeue(&bs11_sw->file_list); |
| 1427 | if (!fle) |
| 1428 | return -EINVAL; |
| 1429 | |
| 1430 | /* start download the next file of our file list */ |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 1431 | rc = abis_nm_software_load(bts, fle->fname, win_size, forced, |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1432 | bs11_swload_cbfn, bs11_sw); |
| 1433 | free(fle); |
| 1434 | return rc; |
| 1435 | } |
| 1436 | |
Harald Welte | 5083b0b | 2009-02-02 19:20:52 +0000 | [diff] [blame] | 1437 | #if 0 |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1438 | static u_int8_t req_attr_btse[] = { |
| 1439 | NM_ATT_ADM_STATE, NM_ATT_BS11_LMT_LOGON_SESSION, |
| 1440 | NM_ATT_BS11_LMT_LOGIN_TIME, NM_ATT_BS11_LMT_USER_ACC_LEV, |
| 1441 | NM_ATT_BS11_LMT_USER_NAME, |
| 1442 | |
| 1443 | 0xaf, NM_ATT_BS11_RX_OFFSET, NM_ATT_BS11_VENDOR_NAME, |
| 1444 | |
| 1445 | NM_ATT_BS11_SW_LOAD_INTENDED, NM_ATT_BS11_SW_LOAD_SAFETY, |
| 1446 | |
| 1447 | NM_ATT_BS11_SW_LOAD_STORED }; |
| 1448 | |
| 1449 | static u_int8_t req_attr_btsm[] = { |
| 1450 | NM_ATT_ABIS_CHANNEL, NM_ATT_TEI, NM_ATT_BS11_ABIS_EXT_TIME, |
| 1451 | NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xce, NM_ATT_FILE_ID, |
| 1452 | NM_ATT_FILE_VERSION, NM_ATT_OPER_STATE, 0xe8, NM_ATT_BS11_ALL_TEST_CATG, |
| 1453 | NM_ATT_SW_DESCR, NM_ATT_GET_ARI }; |
Harald Welte | 5083b0b | 2009-02-02 19:20:52 +0000 | [diff] [blame] | 1454 | #endif |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1455 | |
| 1456 | static u_int8_t req_attr[] = { |
| 1457 | NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xa8, NM_ATT_OPER_STATE, |
| 1458 | 0xd5, 0xa1, NM_ATT_BS11_ESN_FW_CODE_NO, NM_ATT_BS11_ESN_HW_CODE_NO, |
| 1459 | 0x42, NM_ATT_BS11_ESN_PCB_SERIAL }; |
| 1460 | |
| 1461 | int abis_nm_bs11_get_serno(struct gsm_bts *bts) |
| 1462 | { |
| 1463 | struct abis_om_hdr *oh; |
| 1464 | struct msgb *msg = nm_msgb_alloc(); |
| 1465 | |
| 1466 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1467 | /* SiemensHW CCTRL object */ |
| 1468 | fill_om_fom_hdr(oh, 2+sizeof(req_attr), NM_MT_GET_ATTR, NM_OC_BS11, |
| 1469 | 0x03, 0x00, 0x00); |
| 1470 | msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(req_attr), req_attr); |
| 1471 | |
| 1472 | return abis_nm_sendmsg(bts, msg); |
| 1473 | } |
Harald Welte | 268bb40 | 2009-02-01 19:11:56 +0000 | [diff] [blame] | 1474 | |
| 1475 | int abis_nm_bs11_set_ext_time(struct gsm_bts *bts) |
| 1476 | { |
| 1477 | struct abis_om_hdr *oh; |
| 1478 | struct msgb *msg = nm_msgb_alloc(); |
| 1479 | struct bs11_date_time aet; |
| 1480 | |
| 1481 | get_bs11_date_time(&aet); |
| 1482 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1483 | /* SiemensHW CCTRL object */ |
| 1484 | fill_om_fom_hdr(oh, 2+sizeof(aet), NM_MT_BS11_SET_ATTR, NM_OC_SITE_MANAGER, |
| 1485 | 0xff, 0xff, 0xff); |
Harald Welte | 5083b0b | 2009-02-02 19:20:52 +0000 | [diff] [blame] | 1486 | msgb_tlv_put(msg, NM_ATT_BS11_ABIS_EXT_TIME, sizeof(aet), (u_int8_t *) &aet); |
Harald Welte | 268bb40 | 2009-02-01 19:11:56 +0000 | [diff] [blame] | 1487 | |
| 1488 | return abis_nm_sendmsg(bts, msg); |
| 1489 | } |