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