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