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