Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1 | /* GSM Network Management (OML) messages on the A-bis interface |
| 2 | * 3GPP TS 12.21 version 8.0.0 Release 1999 / ETSI TS 100 623 V8.0.0 */ |
| 3 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 4 | /* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 5 | * |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 6 | * All Rights Reserved |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along |
| 19 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | |
| 25 | #include <errno.h> |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 26 | #include <unistd.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 27 | #include <stdio.h> |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 28 | #include <fcntl.h> |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 29 | #include <malloc.h> |
| 30 | #include <libgen.h> |
Harald Welte | 268bb40 | 2009-02-01 19:11:56 +0000 | [diff] [blame] | 31 | #include <time.h> |
Harald Welte | 5f6f149 | 2009-02-02 14:50:29 +0000 | [diff] [blame] | 32 | #include <limits.h> |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 33 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 34 | #include <sys/types.h> |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 35 | #include <sys/stat.h> |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 36 | #include <netinet/in.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 37 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 38 | #include <openbsc/gsm_data.h> |
| 39 | #include <openbsc/debug.h> |
| 40 | #include <openbsc/msgb.h> |
| 41 | #include <openbsc/tlv.h> |
| 42 | #include <openbsc/abis_nm.h> |
Holger Freyther | ca362a6 | 2009-01-04 21:05:01 +0000 | [diff] [blame] | 43 | #include <openbsc/misdn.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 44 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 45 | #define OM_ALLOC_SIZE 1024 |
| 46 | #define OM_HEADROOM_SIZE 128 |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 47 | |
| 48 | /* unidirectional messages from BTS to BSC */ |
| 49 | static const enum abis_nm_msgtype reports[] = { |
| 50 | NM_MT_SW_ACTIVATED_REP, |
| 51 | NM_MT_TEST_REP, |
| 52 | NM_MT_STATECHG_EVENT_REP, |
| 53 | NM_MT_FAILURE_EVENT_REP, |
| 54 | }; |
| 55 | |
| 56 | /* messages without ACK/NACK */ |
| 57 | static const enum abis_nm_msgtype no_ack_nack[] = { |
| 58 | NM_MT_MEAS_RES_REQ, |
| 59 | NM_MT_STOP_MEAS, |
| 60 | NM_MT_START_MEAS, |
| 61 | }; |
| 62 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 63 | /* Messages related to software load */ |
| 64 | static const enum abis_nm_msgtype sw_load_msgs[] = { |
| 65 | NM_MT_LOAD_INIT_ACK, |
| 66 | NM_MT_LOAD_INIT_NACK, |
| 67 | NM_MT_LOAD_SEG_ACK, |
| 68 | NM_MT_LOAD_ABORT, |
| 69 | NM_MT_LOAD_END_ACK, |
| 70 | NM_MT_LOAD_END_NACK, |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 71 | //NM_MT_SW_ACT_REQ, |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 72 | NM_MT_ACTIVATE_SW_ACK, |
| 73 | NM_MT_ACTIVATE_SW_NACK, |
| 74 | NM_MT_SW_ACTIVATED_REP, |
| 75 | }; |
| 76 | |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 77 | static const enum abis_nm_msgtype nacks[] = { |
| 78 | NM_MT_LOAD_INIT_NACK, |
| 79 | NM_MT_LOAD_END_NACK, |
| 80 | NM_MT_SW_ACT_REQ_NACK, |
| 81 | NM_MT_ACTIVATE_SW_NACK, |
| 82 | NM_MT_ESTABLISH_TEI_NACK, |
| 83 | NM_MT_CONN_TERR_SIGN_NACK, |
| 84 | NM_MT_DISC_TERR_SIGN_NACK, |
| 85 | NM_MT_CONN_TERR_TRAF_NACK, |
| 86 | NM_MT_DISC_TERR_TRAF_NACK, |
| 87 | NM_MT_CONN_MDROP_LINK_NACK, |
| 88 | NM_MT_DISC_MDROP_LINK_NACK, |
| 89 | NM_MT_SET_BTS_ATTR_NACK, |
| 90 | NM_MT_SET_RADIO_ATTR_NACK, |
| 91 | NM_MT_SET_CHAN_ATTR_NACK, |
| 92 | NM_MT_PERF_TEST_NACK, |
| 93 | NM_MT_SEND_TEST_REP_NACK, |
| 94 | NM_MT_STOP_TEST_NACK, |
| 95 | NM_MT_STOP_EVENT_REP_NACK, |
| 96 | NM_MT_REST_EVENT_REP_NACK, |
| 97 | NM_MT_CHG_ADM_STATE_NACK, |
| 98 | NM_MT_CHG_ADM_STATE_REQ_NACK, |
| 99 | NM_MT_REP_OUTST_ALARMS_NACK, |
| 100 | NM_MT_CHANGEOVER_NACK, |
| 101 | NM_MT_OPSTART_NACK, |
| 102 | NM_MT_REINIT_NACK, |
| 103 | NM_MT_SET_SITE_OUT_NACK, |
| 104 | NM_MT_CHG_HW_CONF_NACK, |
| 105 | NM_MT_GET_ATTR_NACK, |
| 106 | NM_MT_SET_ALARM_THRES_NACK, |
| 107 | NM_MT_BS11_BEGIN_DB_TX_NACK, |
| 108 | NM_MT_BS11_END_DB_TX_NACK, |
| 109 | NM_MT_BS11_CREATE_OBJ_NACK, |
| 110 | NM_MT_BS11_DELETE_OBJ_NACK, |
| 111 | }; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 112 | /* Attributes that the BSC can set, not only get, according to Section 9.4 */ |
| 113 | static const enum abis_nm_attr nm_att_settable[] = { |
| 114 | NM_ATT_ADD_INFO, |
| 115 | NM_ATT_ADD_TEXT, |
| 116 | NM_ATT_DEST, |
| 117 | NM_ATT_EVENT_TYPE, |
| 118 | NM_ATT_FILE_DATA, |
| 119 | NM_ATT_GET_ARI, |
| 120 | NM_ATT_HW_CONF_CHG, |
| 121 | NM_ATT_LIST_REQ_ATTR, |
| 122 | NM_ATT_MDROP_LINK, |
| 123 | NM_ATT_MDROP_NEXT, |
| 124 | NM_ATT_NACK_CAUSES, |
| 125 | NM_ATT_OUTST_ALARM, |
| 126 | NM_ATT_PHYS_CONF, |
| 127 | NM_ATT_PROB_CAUSE, |
| 128 | NM_ATT_RAD_SUBC, |
| 129 | NM_ATT_SOURCE, |
| 130 | NM_ATT_SPEC_PROB, |
| 131 | NM_ATT_START_TIME, |
| 132 | NM_ATT_TEST_DUR, |
| 133 | NM_ATT_TEST_NO, |
| 134 | NM_ATT_TEST_REPORT, |
| 135 | NM_ATT_WINDOW_SIZE, |
| 136 | NM_ATT_SEVERITY, |
| 137 | NM_ATT_MEAS_RES, |
| 138 | NM_ATT_MEAS_TYPE, |
| 139 | }; |
| 140 | |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 141 | static const struct tlv_definition nm_att_tlvdef = { |
| 142 | .def = { |
| 143 | [NM_ATT_ABIS_CHANNEL] = { TLV_TYPE_FIXED, 3 }, |
| 144 | [NM_ATT_ADD_INFO] = { TLV_TYPE_TL16V }, |
| 145 | [NM_ATT_ADD_TEXT] = { TLV_TYPE_TL16V }, |
| 146 | [NM_ATT_ADM_STATE] = { TLV_TYPE_TV }, |
| 147 | [NM_ATT_ARFCN_LIST]= { TLV_TYPE_TL16V }, |
| 148 | [NM_ATT_AUTON_REPORT] = { TLV_TYPE_TV }, |
| 149 | [NM_ATT_AVAIL_STATUS] = { TLV_TYPE_TL16V }, |
| 150 | [NM_ATT_BCCH_ARFCN] = { TLV_TYPE_FIXED, 2 }, |
| 151 | [NM_ATT_BSIC] = { TLV_TYPE_TV }, |
| 152 | [NM_ATT_BTS_AIR_TIMER] = { TLV_TYPE_TV }, |
| 153 | [NM_ATT_CCCH_L_I_P] = { TLV_TYPE_TV }, |
| 154 | [NM_ATT_CCCH_L_T] = { TLV_TYPE_TV }, |
| 155 | [NM_ATT_CHAN_COMB] = { TLV_TYPE_TV }, |
| 156 | [NM_ATT_CONN_FAIL_CRIT] = { TLV_TYPE_TL16V }, |
| 157 | [NM_ATT_DEST] = { TLV_TYPE_TL16V }, |
| 158 | [NM_ATT_EVENT_TYPE] = { TLV_TYPE_TV }, |
| 159 | [NM_ATT_FILE_DATA] = { TLV_TYPE_TL16V }, |
| 160 | [NM_ATT_FILE_ID] = { TLV_TYPE_TL16V }, |
| 161 | [NM_ATT_FILE_VERSION] = { TLV_TYPE_TL16V }, |
| 162 | [NM_ATT_GSM_TIME] = { TLV_TYPE_FIXED, 2 }, |
| 163 | [NM_ATT_HSN] = { TLV_TYPE_TV }, |
| 164 | [NM_ATT_HW_CONFIG] = { TLV_TYPE_TL16V }, |
| 165 | [NM_ATT_HW_DESC] = { TLV_TYPE_TL16V }, |
| 166 | [NM_ATT_INTAVE_PARAM] = { TLV_TYPE_TV }, |
| 167 | [NM_ATT_INTERF_BOUND] = { TLV_TYPE_FIXED, 6 }, |
| 168 | [NM_ATT_LIST_REQ_ATTR] = { TLV_TYPE_TL16V }, |
| 169 | [NM_ATT_MAIO] = { TLV_TYPE_TV }, |
| 170 | [NM_ATT_MANUF_STATE] = { TLV_TYPE_TV }, |
| 171 | [NM_ATT_MANUF_THRESH] = { TLV_TYPE_TL16V }, |
| 172 | [NM_ATT_MANUF_ID] = { TLV_TYPE_TL16V }, |
| 173 | [NM_ATT_MAX_TA] = { TLV_TYPE_TV }, |
| 174 | [NM_ATT_MDROP_LINK] = { TLV_TYPE_FIXED, 2 }, |
| 175 | [NM_ATT_MDROP_NEXT] = { TLV_TYPE_FIXED, 2 }, |
| 176 | [NM_ATT_NACK_CAUSES] = { TLV_TYPE_TV }, |
| 177 | [NM_ATT_NY1] = { TLV_TYPE_TV }, |
| 178 | [NM_ATT_OPER_STATE] = { TLV_TYPE_TV }, |
| 179 | [NM_ATT_OVERL_PERIOD] = { TLV_TYPE_TL16V }, |
| 180 | [NM_ATT_PHYS_CONF] = { TLV_TYPE_TL16V }, |
| 181 | [NM_ATT_POWER_CLASS] = { TLV_TYPE_TV }, |
| 182 | [NM_ATT_POWER_THRESH] = { TLV_TYPE_FIXED, 3 }, |
| 183 | [NM_ATT_PROB_CAUSE] = { TLV_TYPE_FIXED, 3 }, |
| 184 | [NM_ATT_RACH_B_THRESH] = { TLV_TYPE_TV }, |
| 185 | [NM_ATT_LDAVG_SLOTS] = { TLV_TYPE_FIXED, 2 }, |
| 186 | [NM_ATT_RAD_SUBC] = { TLV_TYPE_TV }, |
| 187 | [NM_ATT_RF_MAXPOWR_R] = { TLV_TYPE_TV }, |
| 188 | [NM_ATT_SITE_INPUTS] = { TLV_TYPE_TL16V }, |
| 189 | [NM_ATT_SITE_OUTPUTS] = { TLV_TYPE_TL16V }, |
| 190 | [NM_ATT_SOURCE] = { TLV_TYPE_TL16V }, |
| 191 | [NM_ATT_SPEC_PROB] = { TLV_TYPE_TV }, |
| 192 | [NM_ATT_START_TIME] = { TLV_TYPE_FIXED, 2 }, |
| 193 | [NM_ATT_T200] = { TLV_TYPE_FIXED, 7 }, |
| 194 | [NM_ATT_TEI] = { TLV_TYPE_TV }, |
| 195 | [NM_ATT_TEST_DUR] = { TLV_TYPE_FIXED, 2 }, |
| 196 | [NM_ATT_TEST_NO] = { TLV_TYPE_TV }, |
| 197 | [NM_ATT_TEST_REPORT] = { TLV_TYPE_TL16V }, |
| 198 | [NM_ATT_VSWR_THRESH] = { TLV_TYPE_FIXED, 2 }, |
| 199 | [NM_ATT_WINDOW_SIZE] = { TLV_TYPE_TV }, |
| 200 | [NM_ATT_TSC] = { TLV_TYPE_TV }, |
| 201 | [NM_ATT_SW_CONFIG] = { TLV_TYPE_TL16V }, |
| 202 | [NM_ATT_SEVERITY] = { TLV_TYPE_TV }, |
| 203 | [NM_ATT_GET_ARI] = { TLV_TYPE_TL16V }, |
| 204 | [NM_ATT_HW_CONF_CHG] = { TLV_TYPE_TL16V }, |
| 205 | [NM_ATT_OUTST_ALARM] = { TLV_TYPE_TV }, |
| 206 | [NM_ATT_FILE_DATA] = { TLV_TYPE_TL16V }, |
| 207 | [NM_ATT_MEAS_RES] = { TLV_TYPE_TL16V }, |
| 208 | /* BS11 specifics */ |
| 209 | [NM_ATT_BS11_PASSWORD] = { TLV_TYPE_TLV }, |
| 210 | [NM_ATT_BS11_TXPWR] = { TLV_TYPE_TLV }, |
| 211 | [NM_ATT_BS11_RSSI_OFFS] = { TLV_TYPE_TLV }, |
| 212 | [NM_ATT_BS11_LINE_CFG] = { TLV_TYPE_TV }, |
| 213 | [NM_ATT_BS11_L1_PROT_TYPE] = { TLV_TYPE_TV }, |
| 214 | [NM_ATT_BS11_BIT_ERR_THESH] = { TLV_TYPE_FIXED, 2 }, |
| 215 | [NM_ATT_BS11_DIVERSITY] = { TLV_TYPE_TLV }, |
| 216 | [NM_ATT_BS11_LMT_LOGIN_TIME] = { TLV_TYPE_TLV }, |
| 217 | [NM_ATT_BS11_LMT_USER_ACC_LEV] ={ TLV_TYPE_TLV }, |
| 218 | [NM_ATT_BS11_LMT_USER_NAME] = { TLV_TYPE_TLV }, |
| 219 | }, |
| 220 | }; |
| 221 | #define nm_tlv_parse(dec, buf, len) tlv_parse(dec, &nm_att_tlvdef, buf, len) |
| 222 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 223 | static int is_in_arr(enum abis_nm_msgtype mt, const enum abis_nm_msgtype *arr, int size) |
| 224 | { |
| 225 | int i; |
| 226 | |
| 227 | for (i = 0; i < size; i++) { |
| 228 | if (arr[i] == mt) |
| 229 | return 1; |
| 230 | } |
| 231 | |
| 232 | return 0; |
| 233 | } |
| 234 | |
Holger Freyther | ca362a6 | 2009-01-04 21:05:01 +0000 | [diff] [blame] | 235 | #if 0 |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 236 | /* is this msgtype the usual ACK/NACK type ? */ |
| 237 | static int is_ack_nack(enum abis_nm_msgtype mt) |
| 238 | { |
| 239 | return !is_in_arr(mt, no_ack_nack, ARRAY_SIZE(no_ack_nack)); |
| 240 | } |
Holger Freyther | ca362a6 | 2009-01-04 21:05:01 +0000 | [diff] [blame] | 241 | #endif |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 242 | |
| 243 | /* is this msgtype a report ? */ |
| 244 | static int is_report(enum abis_nm_msgtype mt) |
| 245 | { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 246 | return is_in_arr(mt, reports, ARRAY_SIZE(reports)); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | #define MT_ACK(x) (x+1) |
| 250 | #define MT_NACK(x) (x+2) |
| 251 | |
| 252 | static void fill_om_hdr(struct abis_om_hdr *oh, u_int8_t len) |
| 253 | { |
| 254 | oh->mdisc = ABIS_OM_MDISC_FOM; |
| 255 | oh->placement = ABIS_OM_PLACEMENT_ONLY; |
| 256 | oh->sequence = 0; |
| 257 | oh->length = len; |
| 258 | } |
| 259 | |
| 260 | static void fill_om_fom_hdr(struct abis_om_hdr *oh, u_int8_t len, |
| 261 | u_int8_t msg_type, u_int8_t obj_class, |
| 262 | u_int8_t bts_nr, u_int8_t trx_nr, u_int8_t ts_nr) |
| 263 | { |
| 264 | struct abis_om_fom_hdr *foh = |
| 265 | (struct abis_om_fom_hdr *) oh->data; |
| 266 | |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 267 | fill_om_hdr(oh, len+sizeof(*foh)); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 268 | foh->msg_type = msg_type; |
| 269 | foh->obj_class = obj_class; |
| 270 | foh->obj_inst.bts_nr = bts_nr; |
| 271 | foh->obj_inst.trx_nr = trx_nr; |
| 272 | foh->obj_inst.ts_nr = ts_nr; |
| 273 | } |
| 274 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 275 | static struct msgb *nm_msgb_alloc(void) |
| 276 | { |
| 277 | return msgb_alloc_headroom(OM_ALLOC_SIZE, OM_HEADROOM_SIZE); |
| 278 | } |
| 279 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 280 | /* Send a OML NM Message from BSC to BTS */ |
| 281 | int abis_nm_sendmsg(struct gsm_bts *bts, struct msgb *msg) |
| 282 | { |
Holger Freyther | 59639e8 | 2009-02-09 23:09:55 +0000 | [diff] [blame] | 283 | msg->trx = bts->c0; |
| 284 | |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 285 | return _abis_nm_sendmsg(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 286 | } |
| 287 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 288 | static int abis_nm_rcvmsg_sw(struct msgb *mb); |
| 289 | |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 290 | const char *oc_names[] = { |
| 291 | [NM_OC_SITE_MANAGER] = "SITE MANAGER", |
| 292 | [NM_OC_BTS] = "BTS", |
| 293 | [NM_OC_RADIO_CARRIER] = "RADIO CARRIER", |
| 294 | [NM_OC_BASEB_TRANSC] = "BASEBAND TRANSCEIVER", |
| 295 | [NM_OC_CHANNEL] = "CHANNEL", |
| 296 | }; |
| 297 | |
| 298 | static const char *obj_class_name(u_int8_t oc) |
| 299 | { |
| 300 | if (oc >= ARRAY_SIZE(oc_names)) |
| 301 | return "UNKNOWN"; |
| 302 | return oc_names[oc]; |
| 303 | } |
| 304 | |
| 305 | static const char *opstate_name(u_int8_t os) |
| 306 | { |
| 307 | switch (os) { |
| 308 | case 1: |
| 309 | return "Disabled"; |
| 310 | case 2: |
| 311 | return "Enabled"; |
| 312 | case 0xff: |
| 313 | return "NULL"; |
| 314 | default: |
| 315 | return "RFU"; |
| 316 | } |
| 317 | } |
| 318 | |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 319 | /* Chapter 9.4.7 */ |
| 320 | const char *avail_names[] = { |
| 321 | "In test", |
| 322 | "Failed", |
| 323 | "Power off", |
| 324 | "Off line", |
| 325 | "<not used>", |
| 326 | "Dependency", |
| 327 | "Degraded", |
| 328 | "Not installed", |
| 329 | }; |
| 330 | |
| 331 | static const char *avail_name(u_int8_t avail) |
| 332 | { |
| 333 | if (avail >= ARRAY_SIZE(avail_names)) |
| 334 | return "UNKNOWN"; |
| 335 | return avail_names[avail]; |
| 336 | } |
| 337 | |
| 338 | |
| 339 | /* obtain the gsm_nm_state data structure for a given object instance */ |
| 340 | static struct gsm_nm_state * |
| 341 | objclass2nmstate(struct gsm_bts *bts, u_int8_t obj_class, |
| 342 | struct abis_om_obj_inst *obj_inst) |
| 343 | { |
| 344 | struct gsm_bts_trx *trx; |
| 345 | struct gsm_nm_state *nm_state = NULL; |
| 346 | |
| 347 | switch (obj_class) { |
| 348 | case NM_OC_BTS: |
| 349 | nm_state = &bts->nm_state; |
| 350 | break; |
| 351 | case NM_OC_RADIO_CARRIER: |
| 352 | if (obj_inst->trx_nr >= bts->num_trx) |
| 353 | return NULL; |
| 354 | trx = &bts->trx[obj_inst->trx_nr]; |
| 355 | nm_state = &trx->nm_state; |
| 356 | break; |
| 357 | case NM_OC_BASEB_TRANSC: |
| 358 | if (obj_inst->trx_nr >= bts->num_trx) |
| 359 | return NULL; |
| 360 | trx = &bts->trx[obj_inst->trx_nr]; |
| 361 | nm_state = &trx->bb_transc.nm_state; |
| 362 | break; |
| 363 | case NM_OC_CHANNEL: |
| 364 | if (obj_inst->trx_nr > bts->num_trx) |
| 365 | return NULL; |
| 366 | trx = &bts->trx[obj_inst->trx_nr]; |
| 367 | if (obj_inst->ts_nr >= TRX_NR_TS) |
| 368 | return NULL; |
| 369 | nm_state = &trx->ts[obj_inst->ts_nr].nm_state; |
| 370 | break; |
| 371 | case NM_OC_SITE_MANAGER: |
| 372 | nm_state = &bts->site_mgr.nm_state; |
| 373 | break; |
| 374 | } |
| 375 | return nm_state; |
| 376 | } |
| 377 | |
| 378 | /* obtain the in-memory data structure of a given object instance */ |
| 379 | static void * |
| 380 | objclass2obj(struct gsm_bts *bts, u_int8_t obj_class, |
| 381 | struct abis_om_obj_inst *obj_inst) |
| 382 | { |
| 383 | struct gsm_bts_trx *trx; |
| 384 | void *obj = NULL; |
| 385 | |
| 386 | switch (obj_class) { |
| 387 | case NM_OC_BTS: |
| 388 | obj = bts; |
| 389 | break; |
| 390 | case NM_OC_RADIO_CARRIER: |
| 391 | if (obj_inst->trx_nr >= bts->num_trx) |
| 392 | return NULL; |
| 393 | trx = &bts->trx[obj_inst->trx_nr]; |
| 394 | obj = trx; |
| 395 | break; |
| 396 | case NM_OC_BASEB_TRANSC: |
| 397 | if (obj_inst->trx_nr >= bts->num_trx) |
| 398 | return NULL; |
| 399 | trx = &bts->trx[obj_inst->trx_nr]; |
| 400 | obj = &trx->bb_transc; |
| 401 | break; |
| 402 | case NM_OC_CHANNEL: |
| 403 | if (obj_inst->trx_nr > bts->num_trx) |
| 404 | return NULL; |
| 405 | trx = &bts->trx[obj_inst->trx_nr]; |
| 406 | if (obj_inst->ts_nr >= TRX_NR_TS) |
| 407 | return NULL; |
| 408 | obj = &trx->ts[obj_inst->ts_nr]; |
| 409 | break; |
| 410 | case NM_OC_SITE_MANAGER: |
| 411 | obj = &bts->site_mgr; |
| 412 | break; |
| 413 | } |
| 414 | return obj; |
| 415 | } |
| 416 | |
| 417 | /* Update the administrative state of a given object in our in-memory data |
| 418 | * structures and send an event to the higher layer */ |
| 419 | static int update_admstate(struct gsm_bts *bts, u_int8_t obj_class, |
| 420 | struct abis_om_obj_inst *obj_inst, u_int8_t adm_state) |
| 421 | { |
| 422 | struct gsm_nm_state *nm_state; |
| 423 | void *obj; |
| 424 | int rc; |
| 425 | |
| 426 | nm_state = objclass2nmstate(bts, obj_class, obj_inst); |
| 427 | obj = objclass2obj(bts, obj_class, obj_inst); |
| 428 | rc = nm_state_event(EVT_STATECHG_ADM, obj_class, obj, nm_state, adm_state); |
| 429 | if (nm_state) |
| 430 | nm_state->administrative = adm_state; |
| 431 | |
| 432 | return rc; |
| 433 | } |
| 434 | |
Harald Welte | 97ed1e7 | 2009-02-06 13:38:02 +0000 | [diff] [blame] | 435 | static int abis_nm_rx_statechg_rep(struct msgb *mb) |
| 436 | { |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 437 | struct abis_om_hdr *oh = msgb_l2(mb); |
Harald Welte | 97ed1e7 | 2009-02-06 13:38:02 +0000 | [diff] [blame] | 438 | struct abis_om_fom_hdr *foh = msgb_l3(mb); |
Harald Welte | 22af0db | 2009-02-14 15:41:08 +0000 | [diff] [blame] | 439 | struct gsm_bts *bts = mb->trx->bts; |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 440 | struct tlv_parsed tp; |
| 441 | struct gsm_nm_state *nm_state, new_state; |
| 442 | int rc; |
| 443 | |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 444 | DEBUGP(DNM, "STATE CHG: OC=%s(%02x) INST=(%02x,%02x,%02x) ", |
| 445 | obj_class_name(foh->obj_class), foh->obj_class, |
| 446 | foh->obj_inst.bts_nr, foh->obj_inst.trx_nr, |
Harald Welte | 97ed1e7 | 2009-02-06 13:38:02 +0000 | [diff] [blame] | 447 | foh->obj_inst.ts_nr); |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 448 | |
| 449 | nm_state = objclass2nmstate(bts, foh->obj_class, &foh->obj_inst); |
| 450 | if (!nm_state) { |
| 451 | DEBUGPC(DNM, "\n"); |
| 452 | return -EINVAL; |
Harald Welte | 22af0db | 2009-02-14 15:41:08 +0000 | [diff] [blame] | 453 | } |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 454 | |
| 455 | new_state = *nm_state; |
| 456 | |
| 457 | nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh)); |
| 458 | if (TLVP_PRESENT(&tp, NM_ATT_OPER_STATE)) { |
| 459 | new_state.operational = *TLVP_VAL(&tp, NM_ATT_OPER_STATE); |
| 460 | DEBUGPC(DNM, "OP_STATE=%s ", opstate_name(new_state.operational)); |
| 461 | } |
| 462 | if (TLVP_PRESENT(&tp, NM_ATT_AVAIL_STATUS)) { |
| 463 | new_state.availability = *TLVP_VAL(&tp, NM_ATT_AVAIL_STATUS); |
| 464 | DEBUGPC(DNM, "AVAIL=%s(%02x) ", avail_name(new_state.availability), |
| 465 | new_state.availability); |
| 466 | } |
| 467 | if (TLVP_PRESENT(&tp, NM_ATT_ADM_STATE)) { |
| 468 | new_state.administrative = *TLVP_VAL(&tp, NM_ATT_ADM_STATE); |
| 469 | DEBUGPC(DNM, "ADM=%02x ", new_state.administrative); |
Harald Welte | 97ed1e7 | 2009-02-06 13:38:02 +0000 | [diff] [blame] | 470 | } |
| 471 | DEBUGPC(DNM, "\n"); |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 472 | |
| 473 | if (memcmp(&new_state, nm_state, sizeof(new_state))) { |
| 474 | /* Update the operational state of a given object in our in-memory data |
| 475 | * structures and send an event to the higher layer */ |
| 476 | void *obj = objclass2obj(bts, foh->obj_class, &foh->obj_inst); |
| 477 | rc = nm_state_event(EVT_STATECHG_OPER, foh->obj_class, obj, nm_state, &new_state); |
| 478 | *nm_state = new_state; |
| 479 | } |
| 480 | #if 0 |
Harald Welte | 22af0db | 2009-02-14 15:41:08 +0000 | [diff] [blame] | 481 | if (op_state == 1) { |
| 482 | /* try to enable objects that are disabled */ |
| 483 | abis_nm_opstart(bts, foh->obj_class, |
| 484 | foh->obj_inst.bts_nr, |
| 485 | foh->obj_inst.trx_nr, |
| 486 | foh->obj_inst.ts_nr); |
| 487 | } |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 488 | #endif |
Harald Welte | 97ed1e7 | 2009-02-06 13:38:02 +0000 | [diff] [blame] | 489 | return 0; |
| 490 | } |
| 491 | |
| 492 | static int abis_nm_rcvmsg_report(struct msgb *mb) |
| 493 | { |
| 494 | struct abis_om_fom_hdr *foh = msgb_l3(mb); |
| 495 | u_int8_t mt = foh->msg_type; |
| 496 | |
| 497 | //nmh->cfg->report_cb(mb, foh); |
| 498 | |
| 499 | switch (mt) { |
| 500 | case NM_MT_STATECHG_EVENT_REP: |
| 501 | return abis_nm_rx_statechg_rep(mb); |
| 502 | break; |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 503 | case NM_MT_SW_ACTIVATED_REP: |
| 504 | DEBUGP(DNM, "Software Activated Report\n"); |
| 505 | break; |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 506 | case NM_MT_FAILURE_EVENT_REP: |
| 507 | DEBUGP(DNM, "Failure Event Report\n"); |
| 508 | break; |
| 509 | default: |
| 510 | DEBUGP(DNM, "reporting NM MT 0x%02x\n", mt); |
| 511 | break; |
| 512 | |
Harald Welte | 97ed1e7 | 2009-02-06 13:38:02 +0000 | [diff] [blame] | 513 | }; |
| 514 | |
Harald Welte | 97ed1e7 | 2009-02-06 13:38:02 +0000 | [diff] [blame] | 515 | return 0; |
| 516 | } |
| 517 | |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 518 | /* Activate the specified software into the BTS */ |
| 519 | static int ipacc_sw_activate(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1, |
| 520 | u_int8_t i2, u_int8_t *sw_desc, u_int8_t swdesc_len) |
| 521 | { |
| 522 | struct abis_om_hdr *oh; |
| 523 | struct msgb *msg = nm_msgb_alloc(); |
| 524 | u_int8_t len = swdesc_len; |
| 525 | u_int8_t *trailer; |
| 526 | |
| 527 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 528 | fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, obj_class, i0, i1, i2); |
| 529 | |
| 530 | trailer = msgb_put(msg, swdesc_len); |
| 531 | memcpy(trailer, sw_desc, swdesc_len); |
| 532 | |
| 533 | return abis_nm_sendmsg(bts, msg); |
| 534 | } |
| 535 | |
| 536 | static int abis_nm_rx_sw_act_req(struct msgb *mb) |
| 537 | { |
| 538 | struct abis_om_hdr *oh = msgb_l2(mb); |
| 539 | struct abis_om_fom_hdr *foh = msgb_l3(mb); |
Harald Welte | 5c1e458 | 2009-02-15 11:57:29 +0000 | [diff] [blame] | 540 | int nack = 0; |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 541 | int ret; |
| 542 | |
Harald Welte | 5c1e458 | 2009-02-15 11:57:29 +0000 | [diff] [blame] | 543 | DEBUGP(DNM, "Software Activate Request "); |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 544 | |
Harald Welte | 5c1e458 | 2009-02-15 11:57:29 +0000 | [diff] [blame] | 545 | if (foh->obj_class >= 0xf0 && foh->obj_class <= 0xf3) { |
| 546 | DEBUGPC(DNM, "NACKing for GPRS obj_class 0x%02x\n", foh->obj_class); |
| 547 | nack = 1; |
| 548 | } else |
| 549 | DEBUGPC(DNM, "ACKing and Activating\n"); |
| 550 | |
| 551 | ret = abis_nm_sw_act_req_ack(mb->trx->bts, foh->obj_class, |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 552 | foh->obj_inst.bts_nr, |
| 553 | foh->obj_inst.trx_nr, |
Harald Welte | 5c1e458 | 2009-02-15 11:57:29 +0000 | [diff] [blame] | 554 | foh->obj_inst.ts_nr, nack, |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 555 | foh->data, oh->length-sizeof(*foh)); |
| 556 | |
Harald Welte | 5c1e458 | 2009-02-15 11:57:29 +0000 | [diff] [blame] | 557 | if (nack) |
| 558 | return ret; |
| 559 | |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 560 | /* FIXME: properly parse attributes */ |
| 561 | return ipacc_sw_activate(mb->trx->bts, foh->obj_class, |
| 562 | foh->obj_inst.bts_nr, |
| 563 | foh->obj_inst.trx_nr, |
| 564 | foh->obj_inst.ts_nr, |
| 565 | foh->data + oh->length-sizeof(*foh)-22, 22); |
| 566 | } |
| 567 | |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 568 | /* Receive a CHANGE_ADM_STATE_ACK, parse the TLV and update local state */ |
| 569 | static int abis_nm_rx_chg_adm_state_ack(struct msgb *mb) |
| 570 | { |
| 571 | struct abis_om_hdr *oh = msgb_l2(mb); |
| 572 | struct abis_om_fom_hdr *foh = msgb_l3(mb); |
| 573 | struct tlv_parsed tp; |
| 574 | u_int8_t adm_state; |
| 575 | |
| 576 | nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh)); |
| 577 | if (!TLVP_PRESENT(&tp, NM_ATT_ADM_STATE)) |
| 578 | return -EINVAL; |
| 579 | |
| 580 | adm_state = *TLVP_VAL(&tp, NM_ATT_ADM_STATE); |
| 581 | |
| 582 | return update_admstate(mb->trx->bts, foh->obj_class, &foh->obj_inst, adm_state); |
| 583 | } |
| 584 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 585 | /* Receive a OML NM Message from BTS */ |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 586 | static int abis_nm_rcvmsg_fom(struct msgb *mb) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 587 | { |
| 588 | struct abis_om_fom_hdr *foh = msgb_l3(mb); |
| 589 | u_int8_t mt = foh->msg_type; |
| 590 | |
| 591 | /* check for unsolicited message */ |
Harald Welte | 97ed1e7 | 2009-02-06 13:38:02 +0000 | [diff] [blame] | 592 | if (is_report(mt)) |
| 593 | return abis_nm_rcvmsg_report(mb); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 594 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 595 | if (is_in_arr(mt, sw_load_msgs, ARRAY_SIZE(sw_load_msgs))) |
| 596 | return abis_nm_rcvmsg_sw(mb); |
| 597 | |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 598 | if (is_in_arr(mt, nacks, ARRAY_SIZE(nacks))) |
| 599 | DEBUGP(DNM, "NACK 0x%02x\n", mt); |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 600 | #if 0 |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 601 | /* check if last message is to be acked */ |
| 602 | if (is_ack_nack(nmh->last_msgtype)) { |
| 603 | if (mt == MT_ACK(nmh->last_msgtype)) { |
| 604 | fprintf(stderr, "received ACK (0x%x)\n", |
| 605 | foh->msg_type); |
| 606 | /* we got our ACK, continue sending the next msg */ |
| 607 | } else if (mt == MT_NACK(nmh->last_msgtype)) { |
| 608 | /* we got a NACK, signal this to the caller */ |
| 609 | fprintf(stderr, "received NACK (0x%x)\n", |
| 610 | foh->msg_type); |
| 611 | /* FIXME: somehow signal this to the caller */ |
| 612 | } else { |
| 613 | /* really strange things happen */ |
| 614 | return -EINVAL; |
| 615 | } |
| 616 | } |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 617 | #endif |
| 618 | |
Harald Welte | 97ed1e7 | 2009-02-06 13:38:02 +0000 | [diff] [blame] | 619 | switch (mt) { |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 620 | case NM_MT_CHG_ADM_STATE_ACK: |
| 621 | return abis_nm_rx_chg_adm_state_ack(mb); |
| 622 | break; |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 623 | case NM_MT_SW_ACT_REQ: |
| 624 | return abis_nm_rx_sw_act_req(mb); |
| 625 | break; |
Harald Welte | 97ed1e7 | 2009-02-06 13:38:02 +0000 | [diff] [blame] | 626 | case NM_MT_BS11_LMT_SESSION: |
| 627 | DEBUGP(DNM, "LMT Event: \n"); |
| 628 | break; |
| 629 | } |
| 630 | |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 631 | return 0; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | /* High-Level API */ |
| 635 | /* Entry-point where L2 OML from BTS enters the NM code */ |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 636 | int abis_nm_rcvmsg(struct msgb *msg) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 637 | { |
| 638 | int rc; |
| 639 | struct abis_om_hdr *oh = msgb_l2(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 640 | |
| 641 | /* Various consistency checks */ |
| 642 | if (oh->placement != ABIS_OM_PLACEMENT_ONLY) { |
| 643 | fprintf(stderr, "ABIS OML placement 0x%x not supported\n", |
| 644 | oh->placement); |
| 645 | return -EINVAL; |
| 646 | } |
| 647 | if (oh->sequence != 0) { |
| 648 | fprintf(stderr, "ABIS OML sequence 0x%x != 0x00\n", |
| 649 | oh->sequence); |
| 650 | return -EINVAL; |
| 651 | } |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 652 | #if 0 |
Holger Freyther | ca362a6 | 2009-01-04 21:05:01 +0000 | [diff] [blame] | 653 | unsigned int l2_len = msg->tail - (u_int8_t *)msgb_l2(msg); |
| 654 | unsigned int hlen = sizeof(*oh) + sizeof(struct abis_om_fom_hdr); |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 655 | if (oh->length + hlen > l2_len) { |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 656 | fprintf(stderr, "ABIS OML truncated message (%u > %u)\n", |
| 657 | oh->length + sizeof(*oh), l2_len); |
| 658 | return -EINVAL; |
| 659 | } |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 660 | if (oh->length + hlen < l2_len) |
| 661 | fprintf(stderr, "ABIS OML message with extra trailer?!? (oh->len=%d, sizeof_oh=%d l2_len=%d\n", oh->length, sizeof(*oh), l2_len); |
| 662 | #endif |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 663 | msg->l3h = (unsigned char *)oh + sizeof(*oh); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 664 | |
| 665 | switch (oh->mdisc) { |
| 666 | case ABIS_OM_MDISC_FOM: |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 667 | rc = abis_nm_rcvmsg_fom(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 668 | break; |
| 669 | case ABIS_OM_MDISC_MMI: |
| 670 | case ABIS_OM_MDISC_TRAU: |
| 671 | case ABIS_OM_MDISC_MANUF: |
| 672 | default: |
| 673 | fprintf(stderr, "unknown ABIS OML message discriminator 0x%x\n", |
| 674 | oh->mdisc); |
| 675 | return -EINVAL; |
| 676 | } |
| 677 | |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 678 | msgb_free(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 679 | return rc; |
| 680 | } |
| 681 | |
| 682 | #if 0 |
| 683 | /* initialized all resources */ |
| 684 | struct abis_nm_h *abis_nm_init(struct abis_nm_cfg *cfg) |
| 685 | { |
| 686 | struct abis_nm_h *nmh; |
| 687 | |
| 688 | nmh = malloc(sizeof(*nmh)); |
| 689 | if (!nmh) |
| 690 | return NULL; |
| 691 | |
| 692 | nmh->cfg = cfg; |
| 693 | |
| 694 | return nmh; |
| 695 | } |
| 696 | |
| 697 | /* free all resources */ |
| 698 | void abis_nm_fini(struct abis_nm_h *nmh) |
| 699 | { |
| 700 | free(nmh); |
| 701 | } |
| 702 | #endif |
| 703 | |
| 704 | /* Here we are trying to define a high-level API that can be used by |
| 705 | * the actual BSC implementation. However, the architecture is currently |
| 706 | * still under design. Ideally the calls to this API would be synchronous, |
| 707 | * while the underlying stack behind the APi runs in a traditional select |
| 708 | * based state machine. |
| 709 | */ |
| 710 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 711 | /* 6.2 Software Load: */ |
| 712 | enum sw_state { |
| 713 | SW_STATE_NONE, |
| 714 | SW_STATE_WAIT_INITACK, |
| 715 | SW_STATE_WAIT_SEGACK, |
| 716 | SW_STATE_WAIT_ENDACK, |
| 717 | SW_STATE_WAIT_ACTACK, |
| 718 | SW_STATE_ERROR, |
| 719 | }; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 720 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 721 | struct abis_nm_sw { |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 722 | struct gsm_bts *bts; |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 723 | gsm_cbfn *cbfn; |
| 724 | void *cb_data; |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 725 | int forced; |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 726 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 727 | /* this will become part of the SW LOAD INITIATE */ |
| 728 | u_int8_t obj_class; |
| 729 | u_int8_t obj_instance[3]; |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 730 | |
| 731 | u_int8_t file_id[255]; |
| 732 | u_int8_t file_id_len; |
| 733 | |
| 734 | u_int8_t file_version[255]; |
| 735 | u_int8_t file_version_len; |
| 736 | |
| 737 | u_int8_t window_size; |
| 738 | u_int8_t seg_in_window; |
| 739 | |
| 740 | int fd; |
| 741 | FILE *stream; |
| 742 | enum sw_state state; |
Harald Welte | 1602ade | 2009-01-29 21:12:39 +0000 | [diff] [blame] | 743 | int last_seg; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 744 | }; |
| 745 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 746 | static struct abis_nm_sw g_sw; |
| 747 | |
| 748 | /* 6.2.1 / 8.3.1: Load Data Initiate */ |
| 749 | static int sw_load_init(struct abis_nm_sw *sw) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 750 | { |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 751 | struct abis_om_hdr *oh; |
| 752 | struct msgb *msg = nm_msgb_alloc(); |
| 753 | u_int8_t len = 3*2 + sw->file_id_len + sw->file_version_len; |
| 754 | |
| 755 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 756 | fill_om_fom_hdr(oh, len, NM_MT_LOAD_INIT, sw->obj_class, |
| 757 | sw->obj_instance[0], sw->obj_instance[1], |
| 758 | sw->obj_instance[2]); |
| 759 | |
| 760 | /* FIXME: this is BS11 specific format */ |
| 761 | msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id); |
| 762 | msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len, |
| 763 | sw->file_version); |
| 764 | msgb_tv_put(msg, NM_ATT_WINDOW_SIZE, sw->window_size); |
| 765 | |
| 766 | return abis_nm_sendmsg(sw->bts, msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 767 | } |
| 768 | |
Harald Welte | 1602ade | 2009-01-29 21:12:39 +0000 | [diff] [blame] | 769 | static int is_last_line(FILE *stream) |
| 770 | { |
| 771 | char next_seg_buf[256]; |
| 772 | long pos; |
| 773 | |
| 774 | /* check if we're sending the last line */ |
| 775 | pos = ftell(stream); |
| 776 | if (!fgets(next_seg_buf, sizeof(next_seg_buf)-2, stream)) { |
| 777 | fseek(stream, pos, SEEK_SET); |
| 778 | return 1; |
| 779 | } |
| 780 | |
| 781 | fseek(stream, pos, SEEK_SET); |
| 782 | return 0; |
| 783 | } |
| 784 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 785 | /* 6.2.2 / 8.3.2 Load Data Segment */ |
| 786 | static int sw_load_segment(struct abis_nm_sw *sw) |
| 787 | { |
| 788 | struct abis_om_hdr *oh; |
| 789 | struct msgb *msg = nm_msgb_alloc(); |
| 790 | char seg_buf[256]; |
| 791 | char *line_buf = seg_buf+2; |
Harald Welte | 3b8ba21 | 2009-01-29 12:27:58 +0000 | [diff] [blame] | 792 | unsigned char *tlv; |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 793 | u_int8_t len; |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 794 | |
| 795 | 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] | 796 | |
| 797 | switch (sw->bts->type) { |
| 798 | case GSM_BTS_TYPE_BS11: |
| 799 | if (fgets(line_buf, sizeof(seg_buf)-2, sw->stream) == NULL) { |
| 800 | perror("fgets reading segment"); |
| 801 | return -EINVAL; |
| 802 | } |
| 803 | seg_buf[0] = 0x00; |
Harald Welte | 1602ade | 2009-01-29 21:12:39 +0000 | [diff] [blame] | 804 | |
| 805 | /* check if we're sending the last line */ |
| 806 | sw->last_seg = is_last_line(sw->stream); |
| 807 | if (sw->last_seg) |
| 808 | seg_buf[1] = 0; |
| 809 | else |
| 810 | seg_buf[1] = 1 + sw->seg_in_window++; |
Harald Welte | 3b8ba21 | 2009-01-29 12:27:58 +0000 | [diff] [blame] | 811 | |
| 812 | len = strlen(line_buf) + 2; |
| 813 | tlv = msgb_put(msg, TLV_GROSS_LEN(len)); |
| 814 | tlv_put(tlv, NM_ATT_BS11_FILE_DATA, len, (u_int8_t *)seg_buf); |
| 815 | /* BS11 wants CR + LF in excess of the TLV length !?! */ |
| 816 | tlv[1] -= 2; |
| 817 | |
| 818 | /* we only now know the exact length for the OM hdr */ |
| 819 | len = strlen(line_buf)+2; |
| 820 | break; |
| 821 | default: |
| 822 | /* FIXME: Other BTS types */ |
| 823 | return -1; |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 824 | } |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 825 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 826 | fill_om_fom_hdr(oh, len, NM_MT_LOAD_SEG, sw->obj_class, |
| 827 | sw->obj_instance[0], sw->obj_instance[1], |
| 828 | sw->obj_instance[2]); |
| 829 | |
| 830 | return abis_nm_sendmsg(sw->bts, msg); |
| 831 | } |
| 832 | |
| 833 | /* 6.2.4 / 8.3.4 Load Data End */ |
| 834 | static int sw_load_end(struct abis_nm_sw *sw) |
| 835 | { |
| 836 | struct abis_om_hdr *oh; |
| 837 | struct msgb *msg = nm_msgb_alloc(); |
| 838 | u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len; |
| 839 | |
| 840 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 841 | fill_om_fom_hdr(oh, len, NM_MT_LOAD_END, sw->obj_class, |
| 842 | sw->obj_instance[0], sw->obj_instance[1], |
| 843 | sw->obj_instance[2]); |
| 844 | |
| 845 | /* FIXME: this is BS11 specific format */ |
| 846 | msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id); |
| 847 | msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len, |
| 848 | sw->file_version); |
| 849 | |
| 850 | return abis_nm_sendmsg(sw->bts, msg); |
| 851 | } |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 852 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 853 | /* Activate the specified software into the BTS */ |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 854 | static int sw_activate(struct abis_nm_sw *sw) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 855 | { |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 856 | struct abis_om_hdr *oh; |
| 857 | struct msgb *msg = nm_msgb_alloc(); |
| 858 | 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] | 859 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 860 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 861 | fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, sw->obj_class, |
| 862 | sw->obj_instance[0], sw->obj_instance[1], |
| 863 | sw->obj_instance[2]); |
| 864 | |
| 865 | /* FIXME: this is BS11 specific format */ |
| 866 | msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id); |
| 867 | msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len, |
| 868 | sw->file_version); |
| 869 | |
| 870 | return abis_nm_sendmsg(sw->bts, msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 871 | } |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 872 | |
| 873 | static int sw_open_file(struct abis_nm_sw *sw, const char *fname) |
| 874 | { |
| 875 | char file_id[12+1]; |
| 876 | char file_version[80+1]; |
| 877 | int rc; |
| 878 | |
| 879 | sw->fd = open(fname, O_RDONLY); |
| 880 | if (sw->fd < 0) |
| 881 | return sw->fd; |
| 882 | |
| 883 | switch (sw->bts->type) { |
| 884 | case GSM_BTS_TYPE_BS11: |
| 885 | sw->stream = fdopen(sw->fd, "r"); |
| 886 | if (!sw->stream) { |
| 887 | perror("fdopen"); |
| 888 | return -1; |
| 889 | } |
| 890 | /* read first line and parse file ID and VERSION */ |
Harald Welte | 3b8ba21 | 2009-01-29 12:27:58 +0000 | [diff] [blame] | 891 | rc = fscanf(sw->stream, "@(#)%12s:%80s\r\n", |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 892 | file_id, file_version); |
| 893 | if (rc != 2) { |
| 894 | perror("parsing header line of software file"); |
| 895 | return -1; |
| 896 | } |
| 897 | strcpy((char *)sw->file_id, file_id); |
| 898 | sw->file_id_len = strlen(file_id); |
| 899 | strcpy((char *)sw->file_version, file_version); |
| 900 | sw->file_version_len = strlen(file_version); |
| 901 | /* rewind to start of file */ |
Harald Welte | 3b8ba21 | 2009-01-29 12:27:58 +0000 | [diff] [blame] | 902 | rewind(sw->stream); |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 903 | break; |
| 904 | default: |
| 905 | /* We don't know how to treat them yet */ |
| 906 | close(sw->fd); |
| 907 | return -EINVAL; |
| 908 | } |
| 909 | |
| 910 | return 0; |
| 911 | } |
| 912 | |
| 913 | static void sw_close_file(struct abis_nm_sw *sw) |
| 914 | { |
| 915 | switch (sw->bts->type) { |
| 916 | case GSM_BTS_TYPE_BS11: |
| 917 | fclose(sw->stream); |
| 918 | break; |
| 919 | default: |
| 920 | close(sw->fd); |
| 921 | break; |
| 922 | } |
| 923 | } |
| 924 | |
| 925 | /* Fill the window */ |
| 926 | static int sw_fill_window(struct abis_nm_sw *sw) |
| 927 | { |
| 928 | int rc; |
| 929 | |
| 930 | while (sw->seg_in_window < sw->window_size) { |
| 931 | rc = sw_load_segment(sw); |
| 932 | if (rc < 0) |
| 933 | return rc; |
Harald Welte | 1602ade | 2009-01-29 21:12:39 +0000 | [diff] [blame] | 934 | if (sw->last_seg) |
| 935 | break; |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 936 | } |
| 937 | return 0; |
| 938 | } |
| 939 | |
| 940 | /* callback function from abis_nm_rcvmsg() handler */ |
| 941 | static int abis_nm_rcvmsg_sw(struct msgb *mb) |
| 942 | { |
| 943 | struct abis_om_fom_hdr *foh = msgb_l3(mb); |
| 944 | int rc = -1; |
| 945 | struct abis_nm_sw *sw = &g_sw; |
| 946 | enum sw_state old_state = sw->state; |
| 947 | |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 948 | //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] | 949 | |
| 950 | switch (sw->state) { |
| 951 | case SW_STATE_WAIT_INITACK: |
| 952 | switch (foh->msg_type) { |
| 953 | case NM_MT_LOAD_INIT_ACK: |
| 954 | /* fill window with segments */ |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 955 | if (sw->cbfn) |
| 956 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 957 | NM_MT_LOAD_INIT_ACK, mb, |
| 958 | sw->cb_data, NULL); |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 959 | rc = sw_fill_window(sw); |
| 960 | sw->state = SW_STATE_WAIT_SEGACK; |
| 961 | break; |
| 962 | case NM_MT_LOAD_INIT_NACK: |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 963 | if (sw->forced) { |
| 964 | DEBUGP(DNM, "FORCED: Ignoring Software Load " |
| 965 | "Init NACK\n"); |
| 966 | if (sw->cbfn) |
| 967 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 968 | NM_MT_LOAD_INIT_ACK, mb, |
| 969 | sw->cb_data, NULL); |
| 970 | rc = sw_fill_window(sw); |
| 971 | sw->state = SW_STATE_WAIT_SEGACK; |
| 972 | } else { |
| 973 | DEBUGP(DNM, "Software Load Init NACK\n"); |
| 974 | if (sw->cbfn) |
| 975 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 976 | NM_MT_LOAD_INIT_NACK, mb, |
| 977 | sw->cb_data, NULL); |
| 978 | sw->state = SW_STATE_ERROR; |
| 979 | } |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 980 | break; |
| 981 | } |
| 982 | break; |
| 983 | case SW_STATE_WAIT_SEGACK: |
| 984 | switch (foh->msg_type) { |
| 985 | case NM_MT_LOAD_SEG_ACK: |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 986 | if (sw->cbfn) |
| 987 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 988 | NM_MT_LOAD_SEG_ACK, mb, |
| 989 | sw->cb_data, NULL); |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 990 | sw->seg_in_window = 0; |
Harald Welte | 1602ade | 2009-01-29 21:12:39 +0000 | [diff] [blame] | 991 | if (!sw->last_seg) { |
| 992 | /* fill window with more segments */ |
| 993 | rc = sw_fill_window(sw); |
| 994 | sw->state = SW_STATE_WAIT_SEGACK; |
| 995 | } else { |
| 996 | /* end the transfer */ |
| 997 | sw->state = SW_STATE_WAIT_ENDACK; |
| 998 | rc = sw_load_end(sw); |
| 999 | } |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1000 | break; |
| 1001 | } |
| 1002 | break; |
| 1003 | case SW_STATE_WAIT_ENDACK: |
| 1004 | switch (foh->msg_type) { |
| 1005 | case NM_MT_LOAD_END_ACK: |
| 1006 | sw_close_file(sw); |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1007 | DEBUGP(DNM, "Software Load End (BTS %u)\n", |
| 1008 | sw->bts->nr); |
| 1009 | sw->state = SW_STATE_NONE; |
| 1010 | if (sw->cbfn) |
| 1011 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 1012 | NM_MT_LOAD_END_ACK, mb, |
| 1013 | sw->cb_data, NULL); |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1014 | break; |
| 1015 | case NM_MT_LOAD_END_NACK: |
Holger Freyther | 31338a1 | 2009-02-06 17:43:50 +0000 | [diff] [blame] | 1016 | if (sw->forced) { |
| 1017 | DEBUGP(DNM, "FORCED: Ignoring Software Load" |
| 1018 | "End NACK\n"); |
| 1019 | sw->state = SW_STATE_NONE; |
| 1020 | if (sw->cbfn) |
| 1021 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 1022 | NM_MT_LOAD_END_ACK, mb, |
| 1023 | sw->cb_data, NULL); |
| 1024 | } else { |
| 1025 | DEBUGP(DNM, "Software Load End NACK\n"); |
| 1026 | sw->state = SW_STATE_ERROR; |
| 1027 | if (sw->cbfn) |
| 1028 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 1029 | NM_MT_LOAD_END_NACK, mb, |
| 1030 | sw->cb_data, NULL); |
| 1031 | } |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1032 | break; |
| 1033 | } |
| 1034 | case SW_STATE_WAIT_ACTACK: |
| 1035 | switch (foh->msg_type) { |
| 1036 | case NM_MT_ACTIVATE_SW_ACK: |
| 1037 | /* we're done */ |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1038 | DEBUGP(DNM, "Activate Software DONE!\n"); |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1039 | sw->state = SW_STATE_NONE; |
| 1040 | rc = 0; |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1041 | if (sw->cbfn) |
| 1042 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 1043 | NM_MT_ACTIVATE_SW_ACK, mb, |
| 1044 | sw->cb_data, NULL); |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1045 | break; |
| 1046 | case NM_MT_ACTIVATE_SW_NACK: |
Harald Welte | 1602ade | 2009-01-29 21:12:39 +0000 | [diff] [blame] | 1047 | DEBUGP(DNM, "Activate Software NACK\n"); |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1048 | sw->state = SW_STATE_ERROR; |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1049 | if (sw->cbfn) |
| 1050 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 1051 | NM_MT_ACTIVATE_SW_NACK, mb, |
| 1052 | sw->cb_data, NULL); |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1053 | break; |
| 1054 | } |
| 1055 | case SW_STATE_NONE: |
| 1056 | case SW_STATE_ERROR: |
| 1057 | break; |
| 1058 | } |
| 1059 | |
| 1060 | if (rc) |
| 1061 | fprintf(stderr, "unexpected NM MT 0x%02x in state %u -> %u\n", |
| 1062 | foh->msg_type, old_state, sw->state); |
| 1063 | |
| 1064 | return rc; |
| 1065 | } |
| 1066 | |
| 1067 | /* Load the specified software into the BTS */ |
| 1068 | int abis_nm_software_load(struct gsm_bts *bts, const char *fname, |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 1069 | u_int8_t win_size, int forced, |
| 1070 | gsm_cbfn *cbfn, void *cb_data) |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1071 | { |
| 1072 | struct abis_nm_sw *sw = &g_sw; |
| 1073 | int rc; |
| 1074 | |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1075 | DEBUGP(DNM, "Software Load (BTS %u, File \"%s\")\n", |
| 1076 | bts->nr, fname); |
| 1077 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1078 | if (sw->state != SW_STATE_NONE) |
| 1079 | return -EBUSY; |
| 1080 | |
| 1081 | sw->bts = bts; |
| 1082 | sw->obj_class = NM_OC_SITE_MANAGER; |
| 1083 | sw->obj_instance[0] = 0xff; |
| 1084 | sw->obj_instance[1] = 0xff; |
| 1085 | sw->obj_instance[2] = 0xff; |
| 1086 | sw->window_size = win_size; |
| 1087 | sw->state = SW_STATE_WAIT_INITACK; |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1088 | sw->cbfn = cbfn; |
| 1089 | sw->cb_data = cb_data; |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 1090 | sw->forced = forced; |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1091 | |
| 1092 | rc = sw_open_file(sw, fname); |
| 1093 | if (rc < 0) { |
| 1094 | sw->state = SW_STATE_NONE; |
| 1095 | return rc; |
| 1096 | } |
| 1097 | |
| 1098 | return sw_load_init(sw); |
| 1099 | } |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1100 | |
Harald Welte | 1602ade | 2009-01-29 21:12:39 +0000 | [diff] [blame] | 1101 | int abis_nm_software_load_status(struct gsm_bts *bts) |
| 1102 | { |
| 1103 | struct abis_nm_sw *sw = &g_sw; |
| 1104 | struct stat st; |
| 1105 | int rc, percent; |
| 1106 | |
| 1107 | rc = fstat(sw->fd, &st); |
| 1108 | if (rc < 0) { |
| 1109 | perror("ERROR during stat"); |
| 1110 | return rc; |
| 1111 | } |
| 1112 | |
| 1113 | percent = (ftell(sw->stream) * 100) / st.st_size; |
| 1114 | return percent; |
| 1115 | } |
| 1116 | |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1117 | /* Activate the specified software into the BTS */ |
| 1118 | int abis_nm_software_activate(struct gsm_bts *bts, const char *fname, |
| 1119 | gsm_cbfn *cbfn, void *cb_data) |
| 1120 | { |
| 1121 | struct abis_nm_sw *sw = &g_sw; |
| 1122 | int rc; |
| 1123 | |
| 1124 | DEBUGP(DNM, "Activating Software (BTS %u, File \"%s\")\n", |
| 1125 | bts->nr, fname); |
| 1126 | |
| 1127 | if (sw->state != SW_STATE_NONE) |
| 1128 | return -EBUSY; |
| 1129 | |
| 1130 | sw->bts = bts; |
| 1131 | sw->obj_class = NM_OC_SITE_MANAGER; |
| 1132 | sw->obj_instance[0] = 0xff; |
| 1133 | sw->obj_instance[1] = 0xff; |
| 1134 | sw->obj_instance[2] = 0xff; |
| 1135 | sw->state = SW_STATE_WAIT_ACTACK; |
| 1136 | sw->cbfn = cbfn; |
| 1137 | sw->cb_data = cb_data; |
| 1138 | |
| 1139 | /* Open the file in order to fill some sw struct members */ |
| 1140 | rc = sw_open_file(sw, fname); |
| 1141 | if (rc < 0) { |
| 1142 | sw->state = SW_STATE_NONE; |
| 1143 | return rc; |
| 1144 | } |
| 1145 | sw_close_file(sw); |
| 1146 | |
| 1147 | return sw_activate(sw); |
| 1148 | } |
| 1149 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1150 | 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] | 1151 | u_int8_t ts_nr, u_int8_t subslot_nr) |
| 1152 | { |
Harald Welte | adaf08b | 2009-01-18 11:08:10 +0000 | [diff] [blame] | 1153 | ch->attrib = NM_ATT_ABIS_CHANNEL; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1154 | ch->bts_port = bts_port; |
| 1155 | ch->timeslot = ts_nr; |
| 1156 | ch->subslot = subslot_nr; |
| 1157 | } |
| 1158 | |
| 1159 | int abis_nm_establish_tei(struct gsm_bts *bts, u_int8_t trx_nr, |
| 1160 | u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot, |
| 1161 | u_int8_t tei) |
| 1162 | { |
| 1163 | struct abis_om_hdr *oh; |
| 1164 | struct abis_nm_channel *ch; |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 1165 | u_int8_t len = sizeof(*ch) + 2; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1166 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1167 | |
| 1168 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1169 | fill_om_fom_hdr(oh, len, NM_MT_ESTABLISH_TEI, NM_OC_RADIO_CARRIER, |
| 1170 | bts->bts_nr, trx_nr, 0xff); |
| 1171 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1172 | msgb_tv_put(msg, NM_ATT_TEI, tei); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1173 | |
| 1174 | ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch)); |
| 1175 | fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot); |
| 1176 | |
| 1177 | return abis_nm_sendmsg(bts, msg); |
| 1178 | } |
| 1179 | |
| 1180 | /* connect signalling of one (BTS,TRX) to a particular timeslot on the E1 */ |
| 1181 | int abis_nm_conn_terr_sign(struct gsm_bts_trx *trx, |
| 1182 | u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot) |
| 1183 | { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1184 | struct gsm_bts *bts = trx->bts; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1185 | struct abis_om_hdr *oh; |
| 1186 | struct abis_nm_channel *ch; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1187 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1188 | |
| 1189 | 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] | 1190 | fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_SIGN, |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1191 | NM_OC_RADIO_CARRIER, bts->bts_nr, trx->nr, 0xff); |
| 1192 | |
| 1193 | ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch)); |
| 1194 | fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot); |
| 1195 | |
| 1196 | return abis_nm_sendmsg(bts, msg); |
| 1197 | } |
| 1198 | |
| 1199 | #if 0 |
| 1200 | int abis_nm_disc_terr_sign(struct abis_nm_h *h, struct abis_om_obj_inst *inst, |
| 1201 | struct abis_nm_abis_channel *chan) |
| 1202 | { |
| 1203 | } |
| 1204 | #endif |
| 1205 | |
| 1206 | int abis_nm_conn_terr_traf(struct gsm_bts_trx_ts *ts, |
| 1207 | u_int8_t e1_port, u_int8_t e1_timeslot, |
| 1208 | u_int8_t e1_subslot) |
| 1209 | { |
| 1210 | struct gsm_bts *bts = ts->trx->bts; |
| 1211 | struct abis_om_hdr *oh; |
| 1212 | struct abis_nm_channel *ch; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1213 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1214 | |
| 1215 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1216 | fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_TRAF, |
| 1217 | NM_OC_BASEB_TRANSC, bts->bts_nr, ts->trx->nr, ts->nr); |
| 1218 | |
| 1219 | ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch)); |
| 1220 | fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot); |
| 1221 | |
| 1222 | return abis_nm_sendmsg(bts, msg); |
| 1223 | } |
| 1224 | |
| 1225 | #if 0 |
| 1226 | int abis_nm_disc_terr_traf(struct abis_nm_h *h, struct abis_om_obj_inst *inst, |
| 1227 | struct abis_nm_abis_channel *chan, |
| 1228 | u_int8_t subchan) |
| 1229 | { |
| 1230 | } |
| 1231 | #endif |
| 1232 | |
Harald Welte | 22af0db | 2009-02-14 15:41:08 +0000 | [diff] [blame] | 1233 | /* Chapter 8.6.1 */ |
| 1234 | int abis_nm_set_bts_attr(struct gsm_bts *bts, u_int8_t *attr, int attr_len) |
| 1235 | { |
| 1236 | struct abis_om_hdr *oh; |
| 1237 | struct msgb *msg = nm_msgb_alloc(); |
| 1238 | u_int8_t *cur; |
| 1239 | |
| 1240 | DEBUGP(DNM, "Set BTS Attr (bts=%d)\n", bts->nr); |
| 1241 | |
| 1242 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1243 | fill_om_fom_hdr(oh, attr_len, NM_MT_SET_BTS_ATTR, NM_OC_BTS, bts->nr, 0xff, 0xff); |
| 1244 | cur = msgb_put(msg, attr_len); |
| 1245 | memcpy(cur, attr, attr_len); |
| 1246 | |
| 1247 | return abis_nm_sendmsg(bts, msg); |
| 1248 | } |
| 1249 | |
| 1250 | /* Chapter 8.6.2 */ |
| 1251 | int abis_nm_set_radio_attr(struct gsm_bts_trx *trx, u_int8_t *attr, int attr_len) |
| 1252 | { |
| 1253 | struct abis_om_hdr *oh; |
| 1254 | struct msgb *msg = nm_msgb_alloc(); |
| 1255 | u_int8_t *cur; |
| 1256 | |
| 1257 | DEBUGP(DNM, "Set TRX Attr (bts=%d,trx=%d)\n", trx->bts->nr, trx->nr); |
| 1258 | |
| 1259 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1260 | fill_om_fom_hdr(oh, attr_len, NM_MT_SET_RADIO_ATTR, NM_OC_RADIO_CARRIER, |
| 1261 | trx->bts->nr, trx->nr, 0xff); |
| 1262 | cur = msgb_put(msg, attr_len); |
| 1263 | memcpy(cur, attr, attr_len); |
| 1264 | |
| 1265 | return abis_nm_sendmsg(trx->bts, msg); |
| 1266 | } |
| 1267 | |
| 1268 | /* Chapter 8.6.3 */ |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1269 | int abis_nm_set_channel_attr(struct gsm_bts_trx_ts *ts, u_int8_t chan_comb) |
| 1270 | { |
| 1271 | struct gsm_bts *bts = ts->trx->bts; |
| 1272 | struct abis_om_hdr *oh; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1273 | u_int16_t arfcn = htons(ts->trx->arfcn); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1274 | u_int8_t zero = 0x00; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1275 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 1276 | u_int8_t len = 2 + 2; |
| 1277 | |
| 1278 | if (bts->type == GSM_BTS_TYPE_BS11) |
| 1279 | len += 4 + 2 + 2 + 3; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1280 | |
Harald Welte | 22af0db | 2009-02-14 15:41:08 +0000 | [diff] [blame] | 1281 | DEBUGP(DNM, "Set Chan Attr (bts=%d,trx=%d,ts=%d)\n", bts->nr, ts->trx->nr, ts->nr); |
| 1282 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1283 | 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] | 1284 | fill_om_fom_hdr(oh, len, NM_MT_SET_CHAN_ATTR, |
Holger Freyther | 6b2d262 | 2009-02-14 23:16:59 +0000 | [diff] [blame] | 1285 | NM_OC_CHANNEL, bts->bts_nr, |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1286 | ts->trx->nr, ts->nr); |
| 1287 | /* FIXME: don't send ARFCN list, hopping sequence, mAIO, ...*/ |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 1288 | if (bts->type == GSM_BTS_TYPE_BS11) |
| 1289 | msgb_tlv16_put(msg, NM_ATT_ARFCN_LIST, 1, &arfcn); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1290 | msgb_tv_put(msg, NM_ATT_CHAN_COMB, chan_comb); |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 1291 | if (bts->type == GSM_BTS_TYPE_BS11) { |
| 1292 | msgb_tv_put(msg, NM_ATT_HSN, 0x00); |
| 1293 | msgb_tv_put(msg, NM_ATT_MAIO, 0x00); |
| 1294 | } |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1295 | msgb_tv_put(msg, NM_ATT_TSC, 0x07); /* training sequence */ |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 1296 | if (bts->type == GSM_BTS_TYPE_BS11) |
| 1297 | msgb_tlv_put(msg, 0x59, 1, &zero); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1298 | |
| 1299 | return abis_nm_sendmsg(bts, msg); |
| 1300 | } |
| 1301 | |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 1302 | int abis_nm_sw_act_req_ack(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i1, |
Harald Welte | 5c1e458 | 2009-02-15 11:57:29 +0000 | [diff] [blame] | 1303 | u_int8_t i2, u_int8_t i3, int nack, u_int8_t *attr, int att_len) |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 1304 | { |
| 1305 | struct abis_om_hdr *oh; |
| 1306 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 5c1e458 | 2009-02-15 11:57:29 +0000 | [diff] [blame] | 1307 | u_int8_t msgtype = NM_MT_SW_ACT_REQ_ACK; |
| 1308 | u_int8_t len = att_len; |
| 1309 | |
| 1310 | if (nack) { |
| 1311 | len += 2; |
| 1312 | msgtype = NM_MT_SW_ACT_REQ_NACK; |
| 1313 | } |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 1314 | |
| 1315 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
Harald Welte | 5c1e458 | 2009-02-15 11:57:29 +0000 | [diff] [blame] | 1316 | fill_om_fom_hdr(oh, att_len, msgtype, obj_class, i1, i2, i3); |
| 1317 | |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 1318 | if (attr) { |
| 1319 | u_int8_t *ptr = msgb_put(msg, att_len); |
| 1320 | memcpy(ptr, attr, att_len); |
| 1321 | } |
Harald Welte | 5c1e458 | 2009-02-15 11:57:29 +0000 | [diff] [blame] | 1322 | if (nack) |
| 1323 | msgb_tv_put(msg, NM_ATT_NACK_CAUSES, NM_NACK_OBJCLASS_NOTSUPP); |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 1324 | |
| 1325 | return abis_nm_sendmsg(bts, msg); |
| 1326 | } |
| 1327 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1328 | 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] | 1329 | { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1330 | struct msgb *msg = nm_msgb_alloc(); |
| 1331 | struct abis_om_hdr *oh; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1332 | u_int8_t *data; |
| 1333 | |
| 1334 | oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh)); |
| 1335 | fill_om_hdr(oh, len); |
| 1336 | data = msgb_put(msg, len); |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 1337 | memcpy(data, rawmsg, len); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1338 | |
| 1339 | return abis_nm_sendmsg(bts, msg); |
| 1340 | } |
| 1341 | |
| 1342 | /* Siemens specific commands */ |
| 1343 | static int __simple_cmd(struct gsm_bts *bts, u_int8_t msg_type) |
| 1344 | { |
| 1345 | struct abis_om_hdr *oh; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1346 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1347 | |
| 1348 | 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] | 1349 | fill_om_fom_hdr(oh, 0, msg_type, NM_OC_SITE_MANAGER, |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1350 | 0xff, 0xff, 0xff); |
| 1351 | |
| 1352 | return abis_nm_sendmsg(bts, msg); |
| 1353 | } |
| 1354 | |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 1355 | /* Chapter 8.9.2 */ |
| 1356 | int abis_nm_opstart(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1, u_int8_t i2) |
| 1357 | { |
| 1358 | struct abis_om_hdr *oh; |
| 1359 | struct msgb *msg = nm_msgb_alloc(); |
| 1360 | |
Harald Welte | 22af0db | 2009-02-14 15:41:08 +0000 | [diff] [blame] | 1361 | DEBUGP(DNM, "Sending OPSTART obj_class=0x%02x obj_inst=(0x%02x, 0x%02x, 0x%02x)\n", |
| 1362 | obj_class, i0, i1, i2); |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 1363 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1364 | fill_om_fom_hdr(oh, 0, NM_MT_OPSTART, obj_class, i0, i1, i2); |
| 1365 | |
| 1366 | return abis_nm_sendmsg(bts, msg); |
| 1367 | } |
| 1368 | |
| 1369 | /* Chapter 8.8.5 */ |
| 1370 | int abis_nm_chg_adm_state(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, |
| 1371 | u_int8_t i1, u_int8_t i2, u_int8_t adm_state) |
| 1372 | { |
| 1373 | struct abis_om_hdr *oh; |
| 1374 | struct msgb *msg = nm_msgb_alloc(); |
| 1375 | |
| 1376 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1377 | fill_om_fom_hdr(oh, 2, NM_MT_CHG_ADM_STATE, obj_class, i0, i1, i2); |
| 1378 | msgb_tv_put(msg, NM_ATT_ADM_STATE, adm_state); |
| 1379 | |
| 1380 | return abis_nm_sendmsg(bts, msg); |
| 1381 | } |
| 1382 | |
| 1383 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1384 | int abis_nm_event_reports(struct gsm_bts *bts, int on) |
| 1385 | { |
| 1386 | if (on == 0) |
Harald Welte | 227d407 | 2009-01-03 08:16:25 +0000 | [diff] [blame] | 1387 | return __simple_cmd(bts, NM_MT_STOP_EVENT_REP); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1388 | else |
Harald Welte | 227d407 | 2009-01-03 08:16:25 +0000 | [diff] [blame] | 1389 | return __simple_cmd(bts, NM_MT_REST_EVENT_REP); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1390 | } |
| 1391 | |
Harald Welte | 47d88ae | 2009-01-04 12:02:08 +0000 | [diff] [blame] | 1392 | /* Siemens (or BS-11) specific commands */ |
| 1393 | |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 1394 | int abis_nm_bs11_bsc_disconnect(struct gsm_bts *bts, int reconnect) |
| 1395 | { |
| 1396 | if (reconnect == 0) |
| 1397 | return __simple_cmd(bts, NM_MT_BS11_DISCONNECT); |
| 1398 | else |
| 1399 | return __simple_cmd(bts, NM_MT_BS11_RECONNECT); |
| 1400 | } |
| 1401 | |
Harald Welte | b842797 | 2009-02-05 19:27:17 +0000 | [diff] [blame] | 1402 | int abis_nm_bs11_restart(struct gsm_bts *bts) |
| 1403 | { |
| 1404 | return __simple_cmd(bts, NM_MT_BS11_RESTART); |
| 1405 | } |
| 1406 | |
| 1407 | |
Harald Welte | 268bb40 | 2009-02-01 19:11:56 +0000 | [diff] [blame] | 1408 | struct bs11_date_time { |
| 1409 | u_int16_t year; |
| 1410 | u_int8_t month; |
| 1411 | u_int8_t day; |
| 1412 | u_int8_t hour; |
| 1413 | u_int8_t min; |
| 1414 | u_int8_t sec; |
| 1415 | } __attribute__((packed)); |
| 1416 | |
| 1417 | |
| 1418 | void get_bs11_date_time(struct bs11_date_time *aet) |
| 1419 | { |
| 1420 | time_t t; |
| 1421 | struct tm *tm; |
| 1422 | |
| 1423 | t = time(NULL); |
| 1424 | tm = localtime(&t); |
| 1425 | aet->sec = tm->tm_sec; |
| 1426 | aet->min = tm->tm_min; |
| 1427 | aet->hour = tm->tm_hour; |
| 1428 | aet->day = tm->tm_mday; |
| 1429 | aet->month = tm->tm_mon; |
| 1430 | aet->year = htons(1900 + tm->tm_year); |
| 1431 | } |
| 1432 | |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1433 | int abis_nm_bs11_reset_resource(struct gsm_bts *bts) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1434 | { |
Harald Welte | 4668fda | 2009-01-03 08:19:29 +0000 | [diff] [blame] | 1435 | return __simple_cmd(bts, NM_MT_BS11_RESET_RESOURCE); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1436 | } |
| 1437 | |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1438 | int abis_nm_bs11_db_transmission(struct gsm_bts *bts, int begin) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1439 | { |
| 1440 | if (begin) |
Harald Welte | 4668fda | 2009-01-03 08:19:29 +0000 | [diff] [blame] | 1441 | return __simple_cmd(bts, NM_MT_BS11_BEGIN_DB_TX); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1442 | else |
Harald Welte | 4668fda | 2009-01-03 08:19:29 +0000 | [diff] [blame] | 1443 | return __simple_cmd(bts, NM_MT_BS11_END_DB_TX); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1444 | } |
Harald Welte | 47d88ae | 2009-01-04 12:02:08 +0000 | [diff] [blame] | 1445 | |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1446 | int abis_nm_bs11_create_object(struct gsm_bts *bts, |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1447 | enum abis_bs11_objtype type, u_int8_t idx, |
| 1448 | u_int8_t attr_len, const u_int8_t *attr) |
Harald Welte | 47d88ae | 2009-01-04 12:02:08 +0000 | [diff] [blame] | 1449 | { |
| 1450 | struct abis_om_hdr *oh; |
| 1451 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1452 | u_int8_t *cur; |
Harald Welte | 47d88ae | 2009-01-04 12:02:08 +0000 | [diff] [blame] | 1453 | |
| 1454 | 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] | 1455 | fill_om_fom_hdr(oh, attr_len, NM_MT_BS11_CREATE_OBJ, |
Harald Welte | 268bb40 | 2009-02-01 19:11:56 +0000 | [diff] [blame] | 1456 | NM_OC_BS11, type, 0, idx); |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1457 | cur = msgb_put(msg, attr_len); |
| 1458 | memcpy(cur, attr, attr_len); |
Harald Welte | 47d88ae | 2009-01-04 12:02:08 +0000 | [diff] [blame] | 1459 | |
| 1460 | return abis_nm_sendmsg(bts, msg); |
| 1461 | } |
| 1462 | |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1463 | 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] | 1464 | { |
| 1465 | struct abis_om_hdr *oh; |
| 1466 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1467 | u_int8_t zero = 0x00; |
Harald Welte | 47d88ae | 2009-01-04 12:02:08 +0000 | [diff] [blame] | 1468 | |
| 1469 | 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] | 1470 | fill_om_fom_hdr(oh, 3, NM_MT_BS11_CREATE_OBJ, |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1471 | NM_OC_BS11_ENVABTSE, 0, idx, 0xff); |
| 1472 | msgb_tlv_put(msg, 0x99, 1, &zero); |
Harald Welte | 47d88ae | 2009-01-04 12:02:08 +0000 | [diff] [blame] | 1473 | |
| 1474 | return abis_nm_sendmsg(bts, msg); |
| 1475 | } |
| 1476 | |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1477 | 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] | 1478 | { |
| 1479 | struct abis_om_hdr *oh; |
| 1480 | struct msgb *msg = nm_msgb_alloc(); |
| 1481 | |
| 1482 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1483 | fill_om_fom_hdr(oh, 0, NM_MT_BS11_CREATE_OBJ, NM_OC_BS11_BPORT, |
| 1484 | idx, 0, 0); |
| 1485 | |
| 1486 | return abis_nm_sendmsg(bts, msg); |
| 1487 | } |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1488 | |
| 1489 | int abis_nm_bs11_set_oml_tei(struct gsm_bts *bts, u_int8_t tei) |
| 1490 | { |
| 1491 | struct abis_om_hdr *oh; |
| 1492 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1493 | |
| 1494 | 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] | 1495 | 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] | 1496 | 0xff, 0xff, 0xff); |
| 1497 | msgb_tv_put(msg, NM_ATT_TEI, tei); |
| 1498 | |
| 1499 | return abis_nm_sendmsg(bts, msg); |
| 1500 | } |
| 1501 | |
| 1502 | /* like abis_nm_conn_terr_traf */ |
| 1503 | int abis_nm_bs11_conn_oml(struct gsm_bts *bts, u_int8_t e1_port, |
| 1504 | u_int8_t e1_timeslot, u_int8_t e1_subslot) |
| 1505 | { |
| 1506 | struct abis_om_hdr *oh; |
| 1507 | struct abis_nm_channel *ch; |
| 1508 | struct msgb *msg = nm_msgb_alloc(); |
| 1509 | |
| 1510 | 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] | 1511 | fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_BS11_SET_ATTR, |
| 1512 | NM_OC_SITE_MANAGER, 0xff, 0xff, 0xff); |
| 1513 | |
| 1514 | ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch)); |
| 1515 | fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot); |
| 1516 | |
| 1517 | return abis_nm_sendmsg(bts, msg); |
| 1518 | } |
| 1519 | |
| 1520 | int abis_nm_bs11_set_trx_power(struct gsm_bts_trx *trx, u_int8_t level) |
| 1521 | { |
| 1522 | struct abis_om_hdr *oh; |
| 1523 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1524 | |
| 1525 | 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] | 1526 | fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR, |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1527 | NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr); |
| 1528 | msgb_tlv_put(msg, NM_ATT_BS11_TXPWR, 1, &level); |
| 1529 | |
| 1530 | return abis_nm_sendmsg(trx->bts, msg); |
| 1531 | } |
| 1532 | |
Harald Welte | 268bb40 | 2009-02-01 19:11:56 +0000 | [diff] [blame] | 1533 | //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] | 1534 | static const u_int8_t bs11_logon_c8[] = { 0x02 }; |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1535 | static const u_int8_t bs11_logon_c9[] = "FACTORY"; |
| 1536 | |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1537 | int abis_nm_bs11_factory_logon(struct gsm_bts *bts, int on) |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1538 | { |
| 1539 | struct abis_om_hdr *oh; |
| 1540 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 268bb40 | 2009-02-01 19:11:56 +0000 | [diff] [blame] | 1541 | struct bs11_date_time bdt; |
| 1542 | |
| 1543 | get_bs11_date_time(&bdt); |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1544 | |
| 1545 | 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] | 1546 | if (on) { |
Harald Welte | 268bb40 | 2009-02-01 19:11:56 +0000 | [diff] [blame] | 1547 | u_int8_t len = 3*2 + sizeof(bdt) |
Harald Welte | 6f676a3 | 2009-01-18 14:27:48 +0000 | [diff] [blame] | 1548 | + sizeof(bs11_logon_c8) + sizeof(bs11_logon_c9); |
Harald Welte | 043d04a | 2009-01-29 23:15:30 +0000 | [diff] [blame] | 1549 | fill_om_fom_hdr(oh, len, NM_MT_BS11_LMT_LOGON, |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1550 | NM_OC_BS11_A3, 0xff, 0xff, 0xff); |
Harald Welte | 043d04a | 2009-01-29 23:15:30 +0000 | [diff] [blame] | 1551 | msgb_tlv_put(msg, NM_ATT_BS11_LMT_LOGIN_TIME, |
Harald Welte | 5083b0b | 2009-02-02 19:20:52 +0000 | [diff] [blame] | 1552 | sizeof(bdt), (u_int8_t *) &bdt); |
Harald Welte | 043d04a | 2009-01-29 23:15:30 +0000 | [diff] [blame] | 1553 | msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_ACC_LEV, |
| 1554 | sizeof(bs11_logon_c8), bs11_logon_c8); |
| 1555 | msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_NAME, |
| 1556 | sizeof(bs11_logon_c9), bs11_logon_c9); |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1557 | } else { |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1558 | fill_om_fom_hdr(oh, 0, NM_MT_BS11_LMT_LOGOFF, |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1559 | NM_OC_BS11_A3, 0xff, 0xff, 0xff); |
| 1560 | } |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1561 | |
| 1562 | return abis_nm_sendmsg(bts, msg); |
| 1563 | } |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1564 | |
| 1565 | int abis_nm_bs11_set_trx1_pw(struct gsm_bts *bts, const char *password) |
| 1566 | { |
| 1567 | struct abis_om_hdr *oh; |
| 1568 | struct msgb *msg; |
| 1569 | |
| 1570 | if (strlen(password) != 10) |
| 1571 | return -EINVAL; |
| 1572 | |
| 1573 | msg = nm_msgb_alloc(); |
| 1574 | 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] | 1575 | 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] | 1576 | NM_OC_BS11, BS11_OBJ_TRX1, 0x00, 0x00); |
| 1577 | msgb_tlv_put(msg, NM_ATT_BS11_PASSWORD, 10, (const u_int8_t *)password); |
| 1578 | |
| 1579 | return abis_nm_sendmsg(bts, msg); |
| 1580 | } |
| 1581 | |
| 1582 | int abis_nm_bs11_get_state(struct gsm_bts *bts) |
| 1583 | { |
| 1584 | return __simple_cmd(bts, NM_MT_BS11_GET_STATE); |
| 1585 | } |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1586 | |
| 1587 | /* BS11 SWL */ |
| 1588 | |
| 1589 | struct abis_nm_bs11_sw { |
| 1590 | struct gsm_bts *bts; |
| 1591 | char swl_fname[PATH_MAX]; |
| 1592 | u_int8_t win_size; |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 1593 | int forced; |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1594 | struct llist_head file_list; |
| 1595 | gsm_cbfn *user_cb; /* specified by the user */ |
| 1596 | }; |
| 1597 | static struct abis_nm_bs11_sw _g_bs11_sw, *g_bs11_sw = &_g_bs11_sw; |
| 1598 | |
| 1599 | struct file_list_entry { |
| 1600 | struct llist_head list; |
| 1601 | char fname[PATH_MAX]; |
| 1602 | }; |
| 1603 | |
| 1604 | struct file_list_entry *fl_dequeue(struct llist_head *queue) |
| 1605 | { |
| 1606 | struct llist_head *lh; |
| 1607 | |
| 1608 | if (llist_empty(queue)) |
| 1609 | return NULL; |
| 1610 | |
| 1611 | lh = queue->next; |
| 1612 | llist_del(lh); |
| 1613 | |
| 1614 | return llist_entry(lh, struct file_list_entry, list); |
| 1615 | } |
| 1616 | |
| 1617 | static int bs11_read_swl_file(struct abis_nm_bs11_sw *bs11_sw) |
| 1618 | { |
| 1619 | char linebuf[255]; |
| 1620 | struct llist_head *lh, *lh2; |
| 1621 | FILE *swl; |
| 1622 | int rc = 0; |
| 1623 | |
| 1624 | swl = fopen(bs11_sw->swl_fname, "r"); |
| 1625 | if (!swl) |
| 1626 | return -ENODEV; |
| 1627 | |
| 1628 | /* zero the stale file list, if any */ |
| 1629 | llist_for_each_safe(lh, lh2, &bs11_sw->file_list) { |
| 1630 | llist_del(lh); |
| 1631 | free(lh); |
| 1632 | } |
| 1633 | |
| 1634 | while (fgets(linebuf, sizeof(linebuf), swl)) { |
| 1635 | char file_id[12+1]; |
| 1636 | char file_version[80+1]; |
| 1637 | struct file_list_entry *fle; |
| 1638 | static char dir[PATH_MAX]; |
| 1639 | |
| 1640 | if (strlen(linebuf) < 4) |
| 1641 | continue; |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 1642 | |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1643 | rc = sscanf(linebuf+4, "%12s:%80s\r\n", file_id, file_version); |
| 1644 | if (rc < 0) { |
| 1645 | perror("ERR parsing SWL file"); |
| 1646 | rc = -EINVAL; |
| 1647 | goto out; |
| 1648 | } |
| 1649 | if (rc < 2) |
| 1650 | continue; |
| 1651 | |
| 1652 | fle = malloc(sizeof(*fle)); |
| 1653 | if (!fle) { |
| 1654 | rc = -ENOMEM; |
| 1655 | goto out; |
| 1656 | } |
| 1657 | memset(fle, 0, sizeof(*fle)); |
| 1658 | |
| 1659 | /* construct new filename */ |
| 1660 | strncpy(dir, bs11_sw->swl_fname, sizeof(dir)); |
| 1661 | strncat(fle->fname, dirname(dir), sizeof(fle->fname) - 1); |
| 1662 | strcat(fle->fname, "/"); |
| 1663 | strncat(fle->fname, file_id, sizeof(fle->fname) - 1 -strlen(fle->fname)); |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1664 | |
| 1665 | llist_add_tail(&fle->list, &bs11_sw->file_list); |
| 1666 | } |
| 1667 | |
| 1668 | out: |
| 1669 | fclose(swl); |
| 1670 | return rc; |
| 1671 | } |
| 1672 | |
| 1673 | /* bs11 swload specific callback, passed to abis_nm core swload */ |
| 1674 | static int bs11_swload_cbfn(unsigned int hook, unsigned int event, |
| 1675 | struct msgb *msg, void *data, void *param) |
| 1676 | { |
| 1677 | struct abis_nm_bs11_sw *bs11_sw = data; |
| 1678 | struct file_list_entry *fle; |
| 1679 | int rc = 0; |
| 1680 | |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1681 | switch (event) { |
| 1682 | case NM_MT_LOAD_END_ACK: |
| 1683 | fle = fl_dequeue(&bs11_sw->file_list); |
| 1684 | if (fle) { |
| 1685 | /* start download the next file of our file list */ |
| 1686 | rc = abis_nm_software_load(bs11_sw->bts, fle->fname, |
| 1687 | bs11_sw->win_size, |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 1688 | bs11_sw->forced, |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1689 | &bs11_swload_cbfn, bs11_sw); |
| 1690 | free(fle); |
| 1691 | } else { |
| 1692 | /* activate the SWL */ |
| 1693 | rc = abis_nm_software_activate(bs11_sw->bts, |
| 1694 | bs11_sw->swl_fname, |
| 1695 | bs11_swload_cbfn, |
| 1696 | bs11_sw); |
| 1697 | } |
| 1698 | break; |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 1699 | case NM_MT_LOAD_SEG_ACK: |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1700 | case NM_MT_LOAD_END_NACK: |
| 1701 | case NM_MT_LOAD_INIT_ACK: |
| 1702 | case NM_MT_LOAD_INIT_NACK: |
| 1703 | case NM_MT_ACTIVATE_SW_NACK: |
| 1704 | case NM_MT_ACTIVATE_SW_ACK: |
| 1705 | default: |
| 1706 | /* fallthrough to the user callback */ |
Harald Welte | 97ed1e7 | 2009-02-06 13:38:02 +0000 | [diff] [blame] | 1707 | if (bs11_sw->user_cb) |
| 1708 | rc = bs11_sw->user_cb(hook, event, msg, NULL, NULL); |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1709 | break; |
| 1710 | } |
| 1711 | |
| 1712 | return rc; |
| 1713 | } |
| 1714 | |
| 1715 | /* Siemens provides a SWL file that is a mere listing of all the other |
| 1716 | * files that are part of a software release. We need to upload first |
| 1717 | * the list file, and then each file that is listed in the list file */ |
| 1718 | 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] | 1719 | u_int8_t win_size, int forced, gsm_cbfn *cbfn) |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1720 | { |
| 1721 | struct abis_nm_bs11_sw *bs11_sw = g_bs11_sw; |
| 1722 | struct file_list_entry *fle; |
| 1723 | int rc = 0; |
| 1724 | |
| 1725 | INIT_LLIST_HEAD(&bs11_sw->file_list); |
| 1726 | bs11_sw->bts = bts; |
| 1727 | bs11_sw->win_size = win_size; |
| 1728 | bs11_sw->user_cb = cbfn; |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 1729 | bs11_sw->forced = forced; |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1730 | |
| 1731 | strncpy(bs11_sw->swl_fname, fname, sizeof(bs11_sw->swl_fname)); |
| 1732 | rc = bs11_read_swl_file(bs11_sw); |
| 1733 | if (rc < 0) |
| 1734 | return rc; |
| 1735 | |
| 1736 | /* dequeue next item in file list */ |
| 1737 | fle = fl_dequeue(&bs11_sw->file_list); |
| 1738 | if (!fle) |
| 1739 | return -EINVAL; |
| 1740 | |
| 1741 | /* start download the next file of our file list */ |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 1742 | rc = abis_nm_software_load(bts, fle->fname, win_size, forced, |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1743 | bs11_swload_cbfn, bs11_sw); |
| 1744 | free(fle); |
| 1745 | return rc; |
| 1746 | } |
| 1747 | |
Harald Welte | 5083b0b | 2009-02-02 19:20:52 +0000 | [diff] [blame] | 1748 | #if 0 |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1749 | static u_int8_t req_attr_btse[] = { |
| 1750 | NM_ATT_ADM_STATE, NM_ATT_BS11_LMT_LOGON_SESSION, |
| 1751 | NM_ATT_BS11_LMT_LOGIN_TIME, NM_ATT_BS11_LMT_USER_ACC_LEV, |
| 1752 | NM_ATT_BS11_LMT_USER_NAME, |
| 1753 | |
| 1754 | 0xaf, NM_ATT_BS11_RX_OFFSET, NM_ATT_BS11_VENDOR_NAME, |
| 1755 | |
| 1756 | NM_ATT_BS11_SW_LOAD_INTENDED, NM_ATT_BS11_SW_LOAD_SAFETY, |
| 1757 | |
| 1758 | NM_ATT_BS11_SW_LOAD_STORED }; |
| 1759 | |
| 1760 | static u_int8_t req_attr_btsm[] = { |
| 1761 | NM_ATT_ABIS_CHANNEL, NM_ATT_TEI, NM_ATT_BS11_ABIS_EXT_TIME, |
| 1762 | NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xce, NM_ATT_FILE_ID, |
| 1763 | NM_ATT_FILE_VERSION, NM_ATT_OPER_STATE, 0xe8, NM_ATT_BS11_ALL_TEST_CATG, |
| 1764 | NM_ATT_SW_DESCR, NM_ATT_GET_ARI }; |
Harald Welte | 5083b0b | 2009-02-02 19:20:52 +0000 | [diff] [blame] | 1765 | #endif |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1766 | |
| 1767 | static u_int8_t req_attr[] = { |
| 1768 | NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xa8, NM_ATT_OPER_STATE, |
| 1769 | 0xd5, 0xa1, NM_ATT_BS11_ESN_FW_CODE_NO, NM_ATT_BS11_ESN_HW_CODE_NO, |
| 1770 | 0x42, NM_ATT_BS11_ESN_PCB_SERIAL }; |
| 1771 | |
| 1772 | int abis_nm_bs11_get_serno(struct gsm_bts *bts) |
| 1773 | { |
| 1774 | struct abis_om_hdr *oh; |
| 1775 | struct msgb *msg = nm_msgb_alloc(); |
| 1776 | |
| 1777 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1778 | /* SiemensHW CCTRL object */ |
| 1779 | fill_om_fom_hdr(oh, 2+sizeof(req_attr), NM_MT_GET_ATTR, NM_OC_BS11, |
| 1780 | 0x03, 0x00, 0x00); |
| 1781 | msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(req_attr), req_attr); |
| 1782 | |
| 1783 | return abis_nm_sendmsg(bts, msg); |
| 1784 | } |
Harald Welte | 268bb40 | 2009-02-01 19:11:56 +0000 | [diff] [blame] | 1785 | |
| 1786 | int abis_nm_bs11_set_ext_time(struct gsm_bts *bts) |
| 1787 | { |
| 1788 | struct abis_om_hdr *oh; |
| 1789 | struct msgb *msg = nm_msgb_alloc(); |
| 1790 | struct bs11_date_time aet; |
| 1791 | |
| 1792 | get_bs11_date_time(&aet); |
| 1793 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1794 | /* SiemensHW CCTRL object */ |
| 1795 | fill_om_fom_hdr(oh, 2+sizeof(aet), NM_MT_BS11_SET_ATTR, NM_OC_SITE_MANAGER, |
| 1796 | 0xff, 0xff, 0xff); |
Harald Welte | 5083b0b | 2009-02-02 19:20:52 +0000 | [diff] [blame] | 1797 | 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] | 1798 | |
| 1799 | return abis_nm_sendmsg(bts, msg); |
| 1800 | } |
Harald Welte | 5c1e458 | 2009-02-15 11:57:29 +0000 | [diff] [blame] | 1801 | |
| 1802 | /* ip.access nanoBTS specific commands */ |
| 1803 | |
| 1804 | static const char ipaccess_magic[] = "com.ipaccess"; |
| 1805 | |
| 1806 | int abis_nm_ipaccess_msg(struct gsm_bts *bts, u_int8_t msg_type, |
| 1807 | u_int8_t obj_class, u_int8_t bts_nr, |
| 1808 | u_int8_t trx_nr, u_int8_t ts_nr, |
| 1809 | u_int8_t *attr, int attr_len) |
| 1810 | { |
| 1811 | struct msgb *msg = nm_msgb_alloc(); |
| 1812 | struct abis_om_hdr *oh; |
| 1813 | struct abis_om_fom_hdr *foh; |
| 1814 | u_int8_t *data; |
| 1815 | |
| 1816 | /* construct the 12.21 OM header, observe the erroneous length */ |
| 1817 | oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh)); |
| 1818 | fill_om_hdr(oh, sizeof(*foh) + attr_len); |
| 1819 | oh->mdisc = ABIS_OM_MDISC_MANUF; |
| 1820 | |
| 1821 | /* add the ip.access magic */ |
| 1822 | data = msgb_put(msg, sizeof(ipaccess_magic)+1); |
| 1823 | *data++ = sizeof(ipaccess_magic); |
| 1824 | memcpy(data, ipaccess_magic, sizeof(ipaccess_magic)); |
| 1825 | |
| 1826 | /* fill the 12.21 FOM header */ |
| 1827 | foh = (struct abis_om_fom_hdr *) msgb_put(msg, sizeof(*foh)); |
| 1828 | foh->msg_type = msg_type; |
| 1829 | foh->obj_class = obj_class; |
| 1830 | foh->obj_inst.bts_nr = bts_nr; |
| 1831 | foh->obj_inst.trx_nr = trx_nr; |
| 1832 | foh->obj_inst.ts_nr = ts_nr; |
| 1833 | |
| 1834 | if (attr && attr_len) { |
| 1835 | data = msgb_put(msg, attr_len); |
| 1836 | memcpy(data, attr, attr_len); |
| 1837 | } |
| 1838 | |
| 1839 | return abis_nm_sendmsg(bts, msg); |
| 1840 | } |