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); |
| 540 | int ret; |
| 541 | |
| 542 | DEBUGP(DNM, "Software Activate Request, ACKing and Activating\n"); |
| 543 | |
| 544 | ret = abis_nm_sw_act_req_ack(mb->trx->bts, foh->obj_class, |
| 545 | foh->obj_inst.bts_nr, |
| 546 | foh->obj_inst.trx_nr, |
| 547 | foh->obj_inst.ts_nr, |
| 548 | foh->data, oh->length-sizeof(*foh)); |
| 549 | |
| 550 | /* FIXME: properly parse attributes */ |
| 551 | return ipacc_sw_activate(mb->trx->bts, foh->obj_class, |
| 552 | foh->obj_inst.bts_nr, |
| 553 | foh->obj_inst.trx_nr, |
| 554 | foh->obj_inst.ts_nr, |
| 555 | foh->data + oh->length-sizeof(*foh)-22, 22); |
| 556 | } |
| 557 | |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 558 | /* Receive a CHANGE_ADM_STATE_ACK, parse the TLV and update local state */ |
| 559 | static int abis_nm_rx_chg_adm_state_ack(struct msgb *mb) |
| 560 | { |
| 561 | struct abis_om_hdr *oh = msgb_l2(mb); |
| 562 | struct abis_om_fom_hdr *foh = msgb_l3(mb); |
| 563 | struct tlv_parsed tp; |
| 564 | u_int8_t adm_state; |
| 565 | |
| 566 | nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh)); |
| 567 | if (!TLVP_PRESENT(&tp, NM_ATT_ADM_STATE)) |
| 568 | return -EINVAL; |
| 569 | |
| 570 | adm_state = *TLVP_VAL(&tp, NM_ATT_ADM_STATE); |
| 571 | |
| 572 | return update_admstate(mb->trx->bts, foh->obj_class, &foh->obj_inst, adm_state); |
| 573 | } |
| 574 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 575 | /* Receive a OML NM Message from BTS */ |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 576 | static int abis_nm_rcvmsg_fom(struct msgb *mb) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 577 | { |
| 578 | struct abis_om_fom_hdr *foh = msgb_l3(mb); |
| 579 | u_int8_t mt = foh->msg_type; |
| 580 | |
| 581 | /* check for unsolicited message */ |
Harald Welte | 97ed1e7 | 2009-02-06 13:38:02 +0000 | [diff] [blame] | 582 | if (is_report(mt)) |
| 583 | return abis_nm_rcvmsg_report(mb); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 584 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 585 | if (is_in_arr(mt, sw_load_msgs, ARRAY_SIZE(sw_load_msgs))) |
| 586 | return abis_nm_rcvmsg_sw(mb); |
| 587 | |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 588 | if (is_in_arr(mt, nacks, ARRAY_SIZE(nacks))) |
| 589 | DEBUGP(DNM, "NACK 0x%02x\n", mt); |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 590 | #if 0 |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 591 | /* check if last message is to be acked */ |
| 592 | if (is_ack_nack(nmh->last_msgtype)) { |
| 593 | if (mt == MT_ACK(nmh->last_msgtype)) { |
| 594 | fprintf(stderr, "received ACK (0x%x)\n", |
| 595 | foh->msg_type); |
| 596 | /* we got our ACK, continue sending the next msg */ |
| 597 | } else if (mt == MT_NACK(nmh->last_msgtype)) { |
| 598 | /* we got a NACK, signal this to the caller */ |
| 599 | fprintf(stderr, "received NACK (0x%x)\n", |
| 600 | foh->msg_type); |
| 601 | /* FIXME: somehow signal this to the caller */ |
| 602 | } else { |
| 603 | /* really strange things happen */ |
| 604 | return -EINVAL; |
| 605 | } |
| 606 | } |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 607 | #endif |
| 608 | |
Harald Welte | 97ed1e7 | 2009-02-06 13:38:02 +0000 | [diff] [blame] | 609 | switch (mt) { |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 610 | case NM_MT_CHG_ADM_STATE_ACK: |
| 611 | return abis_nm_rx_chg_adm_state_ack(mb); |
| 612 | break; |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 613 | case NM_MT_SW_ACT_REQ: |
| 614 | return abis_nm_rx_sw_act_req(mb); |
| 615 | break; |
Harald Welte | 97ed1e7 | 2009-02-06 13:38:02 +0000 | [diff] [blame] | 616 | case NM_MT_BS11_LMT_SESSION: |
| 617 | DEBUGP(DNM, "LMT Event: \n"); |
| 618 | break; |
| 619 | } |
| 620 | |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 621 | return 0; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | /* High-Level API */ |
| 625 | /* Entry-point where L2 OML from BTS enters the NM code */ |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 626 | int abis_nm_rcvmsg(struct msgb *msg) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 627 | { |
| 628 | int rc; |
| 629 | struct abis_om_hdr *oh = msgb_l2(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 630 | |
| 631 | /* Various consistency checks */ |
| 632 | if (oh->placement != ABIS_OM_PLACEMENT_ONLY) { |
| 633 | fprintf(stderr, "ABIS OML placement 0x%x not supported\n", |
| 634 | oh->placement); |
| 635 | return -EINVAL; |
| 636 | } |
| 637 | if (oh->sequence != 0) { |
| 638 | fprintf(stderr, "ABIS OML sequence 0x%x != 0x00\n", |
| 639 | oh->sequence); |
| 640 | return -EINVAL; |
| 641 | } |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 642 | #if 0 |
Holger Freyther | ca362a6 | 2009-01-04 21:05:01 +0000 | [diff] [blame] | 643 | unsigned int l2_len = msg->tail - (u_int8_t *)msgb_l2(msg); |
| 644 | unsigned int hlen = sizeof(*oh) + sizeof(struct abis_om_fom_hdr); |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 645 | if (oh->length + hlen > l2_len) { |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 646 | fprintf(stderr, "ABIS OML truncated message (%u > %u)\n", |
| 647 | oh->length + sizeof(*oh), l2_len); |
| 648 | return -EINVAL; |
| 649 | } |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 650 | if (oh->length + hlen < l2_len) |
| 651 | fprintf(stderr, "ABIS OML message with extra trailer?!? (oh->len=%d, sizeof_oh=%d l2_len=%d\n", oh->length, sizeof(*oh), l2_len); |
| 652 | #endif |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 653 | msg->l3h = (unsigned char *)oh + sizeof(*oh); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 654 | |
| 655 | switch (oh->mdisc) { |
| 656 | case ABIS_OM_MDISC_FOM: |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 657 | rc = abis_nm_rcvmsg_fom(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 658 | break; |
| 659 | case ABIS_OM_MDISC_MMI: |
| 660 | case ABIS_OM_MDISC_TRAU: |
| 661 | case ABIS_OM_MDISC_MANUF: |
| 662 | default: |
| 663 | fprintf(stderr, "unknown ABIS OML message discriminator 0x%x\n", |
| 664 | oh->mdisc); |
| 665 | return -EINVAL; |
| 666 | } |
| 667 | |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 668 | msgb_free(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 669 | return rc; |
| 670 | } |
| 671 | |
| 672 | #if 0 |
| 673 | /* initialized all resources */ |
| 674 | struct abis_nm_h *abis_nm_init(struct abis_nm_cfg *cfg) |
| 675 | { |
| 676 | struct abis_nm_h *nmh; |
| 677 | |
| 678 | nmh = malloc(sizeof(*nmh)); |
| 679 | if (!nmh) |
| 680 | return NULL; |
| 681 | |
| 682 | nmh->cfg = cfg; |
| 683 | |
| 684 | return nmh; |
| 685 | } |
| 686 | |
| 687 | /* free all resources */ |
| 688 | void abis_nm_fini(struct abis_nm_h *nmh) |
| 689 | { |
| 690 | free(nmh); |
| 691 | } |
| 692 | #endif |
| 693 | |
| 694 | /* Here we are trying to define a high-level API that can be used by |
| 695 | * the actual BSC implementation. However, the architecture is currently |
| 696 | * still under design. Ideally the calls to this API would be synchronous, |
| 697 | * while the underlying stack behind the APi runs in a traditional select |
| 698 | * based state machine. |
| 699 | */ |
| 700 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 701 | /* 6.2 Software Load: */ |
| 702 | enum sw_state { |
| 703 | SW_STATE_NONE, |
| 704 | SW_STATE_WAIT_INITACK, |
| 705 | SW_STATE_WAIT_SEGACK, |
| 706 | SW_STATE_WAIT_ENDACK, |
| 707 | SW_STATE_WAIT_ACTACK, |
| 708 | SW_STATE_ERROR, |
| 709 | }; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 710 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 711 | struct abis_nm_sw { |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 712 | struct gsm_bts *bts; |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 713 | gsm_cbfn *cbfn; |
| 714 | void *cb_data; |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 715 | int forced; |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 716 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 717 | /* this will become part of the SW LOAD INITIATE */ |
| 718 | u_int8_t obj_class; |
| 719 | u_int8_t obj_instance[3]; |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 720 | |
| 721 | u_int8_t file_id[255]; |
| 722 | u_int8_t file_id_len; |
| 723 | |
| 724 | u_int8_t file_version[255]; |
| 725 | u_int8_t file_version_len; |
| 726 | |
| 727 | u_int8_t window_size; |
| 728 | u_int8_t seg_in_window; |
| 729 | |
| 730 | int fd; |
| 731 | FILE *stream; |
| 732 | enum sw_state state; |
Harald Welte | 1602ade | 2009-01-29 21:12:39 +0000 | [diff] [blame] | 733 | int last_seg; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 734 | }; |
| 735 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 736 | static struct abis_nm_sw g_sw; |
| 737 | |
| 738 | /* 6.2.1 / 8.3.1: Load Data Initiate */ |
| 739 | static int sw_load_init(struct abis_nm_sw *sw) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 740 | { |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 741 | struct abis_om_hdr *oh; |
| 742 | struct msgb *msg = nm_msgb_alloc(); |
| 743 | u_int8_t len = 3*2 + sw->file_id_len + sw->file_version_len; |
| 744 | |
| 745 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 746 | fill_om_fom_hdr(oh, len, NM_MT_LOAD_INIT, sw->obj_class, |
| 747 | sw->obj_instance[0], sw->obj_instance[1], |
| 748 | sw->obj_instance[2]); |
| 749 | |
| 750 | /* FIXME: this is BS11 specific format */ |
| 751 | msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id); |
| 752 | msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len, |
| 753 | sw->file_version); |
| 754 | msgb_tv_put(msg, NM_ATT_WINDOW_SIZE, sw->window_size); |
| 755 | |
| 756 | return abis_nm_sendmsg(sw->bts, msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 757 | } |
| 758 | |
Harald Welte | 1602ade | 2009-01-29 21:12:39 +0000 | [diff] [blame] | 759 | static int is_last_line(FILE *stream) |
| 760 | { |
| 761 | char next_seg_buf[256]; |
| 762 | long pos; |
| 763 | |
| 764 | /* check if we're sending the last line */ |
| 765 | pos = ftell(stream); |
| 766 | if (!fgets(next_seg_buf, sizeof(next_seg_buf)-2, stream)) { |
| 767 | fseek(stream, pos, SEEK_SET); |
| 768 | return 1; |
| 769 | } |
| 770 | |
| 771 | fseek(stream, pos, SEEK_SET); |
| 772 | return 0; |
| 773 | } |
| 774 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 775 | /* 6.2.2 / 8.3.2 Load Data Segment */ |
| 776 | static int sw_load_segment(struct abis_nm_sw *sw) |
| 777 | { |
| 778 | struct abis_om_hdr *oh; |
| 779 | struct msgb *msg = nm_msgb_alloc(); |
| 780 | char seg_buf[256]; |
| 781 | char *line_buf = seg_buf+2; |
Harald Welte | 3b8ba21 | 2009-01-29 12:27:58 +0000 | [diff] [blame] | 782 | unsigned char *tlv; |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 783 | u_int8_t len; |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 784 | |
| 785 | 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] | 786 | |
| 787 | switch (sw->bts->type) { |
| 788 | case GSM_BTS_TYPE_BS11: |
| 789 | if (fgets(line_buf, sizeof(seg_buf)-2, sw->stream) == NULL) { |
| 790 | perror("fgets reading segment"); |
| 791 | return -EINVAL; |
| 792 | } |
| 793 | seg_buf[0] = 0x00; |
Harald Welte | 1602ade | 2009-01-29 21:12:39 +0000 | [diff] [blame] | 794 | |
| 795 | /* check if we're sending the last line */ |
| 796 | sw->last_seg = is_last_line(sw->stream); |
| 797 | if (sw->last_seg) |
| 798 | seg_buf[1] = 0; |
| 799 | else |
| 800 | seg_buf[1] = 1 + sw->seg_in_window++; |
Harald Welte | 3b8ba21 | 2009-01-29 12:27:58 +0000 | [diff] [blame] | 801 | |
| 802 | len = strlen(line_buf) + 2; |
| 803 | tlv = msgb_put(msg, TLV_GROSS_LEN(len)); |
| 804 | tlv_put(tlv, NM_ATT_BS11_FILE_DATA, len, (u_int8_t *)seg_buf); |
| 805 | /* BS11 wants CR + LF in excess of the TLV length !?! */ |
| 806 | tlv[1] -= 2; |
| 807 | |
| 808 | /* we only now know the exact length for the OM hdr */ |
| 809 | len = strlen(line_buf)+2; |
| 810 | break; |
| 811 | default: |
| 812 | /* FIXME: Other BTS types */ |
| 813 | return -1; |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 814 | } |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 815 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 816 | fill_om_fom_hdr(oh, len, NM_MT_LOAD_SEG, sw->obj_class, |
| 817 | sw->obj_instance[0], sw->obj_instance[1], |
| 818 | sw->obj_instance[2]); |
| 819 | |
| 820 | return abis_nm_sendmsg(sw->bts, msg); |
| 821 | } |
| 822 | |
| 823 | /* 6.2.4 / 8.3.4 Load Data End */ |
| 824 | static int sw_load_end(struct abis_nm_sw *sw) |
| 825 | { |
| 826 | struct abis_om_hdr *oh; |
| 827 | struct msgb *msg = nm_msgb_alloc(); |
| 828 | u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len; |
| 829 | |
| 830 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 831 | fill_om_fom_hdr(oh, len, NM_MT_LOAD_END, sw->obj_class, |
| 832 | sw->obj_instance[0], sw->obj_instance[1], |
| 833 | sw->obj_instance[2]); |
| 834 | |
| 835 | /* FIXME: this is BS11 specific format */ |
| 836 | msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id); |
| 837 | msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len, |
| 838 | sw->file_version); |
| 839 | |
| 840 | return abis_nm_sendmsg(sw->bts, msg); |
| 841 | } |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 842 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 843 | /* Activate the specified software into the BTS */ |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 844 | static int sw_activate(struct abis_nm_sw *sw) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 845 | { |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 846 | struct abis_om_hdr *oh; |
| 847 | struct msgb *msg = nm_msgb_alloc(); |
| 848 | 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] | 849 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 850 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 851 | fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, sw->obj_class, |
| 852 | sw->obj_instance[0], sw->obj_instance[1], |
| 853 | sw->obj_instance[2]); |
| 854 | |
| 855 | /* FIXME: this is BS11 specific format */ |
| 856 | msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id); |
| 857 | msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len, |
| 858 | sw->file_version); |
| 859 | |
| 860 | return abis_nm_sendmsg(sw->bts, msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 861 | } |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 862 | |
| 863 | static int sw_open_file(struct abis_nm_sw *sw, const char *fname) |
| 864 | { |
| 865 | char file_id[12+1]; |
| 866 | char file_version[80+1]; |
| 867 | int rc; |
| 868 | |
| 869 | sw->fd = open(fname, O_RDONLY); |
| 870 | if (sw->fd < 0) |
| 871 | return sw->fd; |
| 872 | |
| 873 | switch (sw->bts->type) { |
| 874 | case GSM_BTS_TYPE_BS11: |
| 875 | sw->stream = fdopen(sw->fd, "r"); |
| 876 | if (!sw->stream) { |
| 877 | perror("fdopen"); |
| 878 | return -1; |
| 879 | } |
| 880 | /* read first line and parse file ID and VERSION */ |
Harald Welte | 3b8ba21 | 2009-01-29 12:27:58 +0000 | [diff] [blame] | 881 | rc = fscanf(sw->stream, "@(#)%12s:%80s\r\n", |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 882 | file_id, file_version); |
| 883 | if (rc != 2) { |
| 884 | perror("parsing header line of software file"); |
| 885 | return -1; |
| 886 | } |
| 887 | strcpy((char *)sw->file_id, file_id); |
| 888 | sw->file_id_len = strlen(file_id); |
| 889 | strcpy((char *)sw->file_version, file_version); |
| 890 | sw->file_version_len = strlen(file_version); |
| 891 | /* rewind to start of file */ |
Harald Welte | 3b8ba21 | 2009-01-29 12:27:58 +0000 | [diff] [blame] | 892 | rewind(sw->stream); |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 893 | break; |
| 894 | default: |
| 895 | /* We don't know how to treat them yet */ |
| 896 | close(sw->fd); |
| 897 | return -EINVAL; |
| 898 | } |
| 899 | |
| 900 | return 0; |
| 901 | } |
| 902 | |
| 903 | static void sw_close_file(struct abis_nm_sw *sw) |
| 904 | { |
| 905 | switch (sw->bts->type) { |
| 906 | case GSM_BTS_TYPE_BS11: |
| 907 | fclose(sw->stream); |
| 908 | break; |
| 909 | default: |
| 910 | close(sw->fd); |
| 911 | break; |
| 912 | } |
| 913 | } |
| 914 | |
| 915 | /* Fill the window */ |
| 916 | static int sw_fill_window(struct abis_nm_sw *sw) |
| 917 | { |
| 918 | int rc; |
| 919 | |
| 920 | while (sw->seg_in_window < sw->window_size) { |
| 921 | rc = sw_load_segment(sw); |
| 922 | if (rc < 0) |
| 923 | return rc; |
Harald Welte | 1602ade | 2009-01-29 21:12:39 +0000 | [diff] [blame] | 924 | if (sw->last_seg) |
| 925 | break; |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 926 | } |
| 927 | return 0; |
| 928 | } |
| 929 | |
| 930 | /* callback function from abis_nm_rcvmsg() handler */ |
| 931 | static int abis_nm_rcvmsg_sw(struct msgb *mb) |
| 932 | { |
| 933 | struct abis_om_fom_hdr *foh = msgb_l3(mb); |
| 934 | int rc = -1; |
| 935 | struct abis_nm_sw *sw = &g_sw; |
| 936 | enum sw_state old_state = sw->state; |
| 937 | |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 938 | //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] | 939 | |
| 940 | switch (sw->state) { |
| 941 | case SW_STATE_WAIT_INITACK: |
| 942 | switch (foh->msg_type) { |
| 943 | case NM_MT_LOAD_INIT_ACK: |
| 944 | /* fill window with segments */ |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 945 | if (sw->cbfn) |
| 946 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 947 | NM_MT_LOAD_INIT_ACK, mb, |
| 948 | sw->cb_data, NULL); |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 949 | rc = sw_fill_window(sw); |
| 950 | sw->state = SW_STATE_WAIT_SEGACK; |
| 951 | break; |
| 952 | case NM_MT_LOAD_INIT_NACK: |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 953 | if (sw->forced) { |
| 954 | DEBUGP(DNM, "FORCED: Ignoring Software Load " |
| 955 | "Init NACK\n"); |
| 956 | if (sw->cbfn) |
| 957 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 958 | NM_MT_LOAD_INIT_ACK, mb, |
| 959 | sw->cb_data, NULL); |
| 960 | rc = sw_fill_window(sw); |
| 961 | sw->state = SW_STATE_WAIT_SEGACK; |
| 962 | } else { |
| 963 | DEBUGP(DNM, "Software Load Init NACK\n"); |
| 964 | if (sw->cbfn) |
| 965 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 966 | NM_MT_LOAD_INIT_NACK, mb, |
| 967 | sw->cb_data, NULL); |
| 968 | sw->state = SW_STATE_ERROR; |
| 969 | } |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 970 | break; |
| 971 | } |
| 972 | break; |
| 973 | case SW_STATE_WAIT_SEGACK: |
| 974 | switch (foh->msg_type) { |
| 975 | case NM_MT_LOAD_SEG_ACK: |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 976 | if (sw->cbfn) |
| 977 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 978 | NM_MT_LOAD_SEG_ACK, mb, |
| 979 | sw->cb_data, NULL); |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 980 | sw->seg_in_window = 0; |
Harald Welte | 1602ade | 2009-01-29 21:12:39 +0000 | [diff] [blame] | 981 | if (!sw->last_seg) { |
| 982 | /* fill window with more segments */ |
| 983 | rc = sw_fill_window(sw); |
| 984 | sw->state = SW_STATE_WAIT_SEGACK; |
| 985 | } else { |
| 986 | /* end the transfer */ |
| 987 | sw->state = SW_STATE_WAIT_ENDACK; |
| 988 | rc = sw_load_end(sw); |
| 989 | } |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 990 | break; |
| 991 | } |
| 992 | break; |
| 993 | case SW_STATE_WAIT_ENDACK: |
| 994 | switch (foh->msg_type) { |
| 995 | case NM_MT_LOAD_END_ACK: |
| 996 | sw_close_file(sw); |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 997 | DEBUGP(DNM, "Software Load End (BTS %u)\n", |
| 998 | sw->bts->nr); |
| 999 | sw->state = SW_STATE_NONE; |
| 1000 | if (sw->cbfn) |
| 1001 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 1002 | NM_MT_LOAD_END_ACK, mb, |
| 1003 | sw->cb_data, NULL); |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1004 | break; |
| 1005 | case NM_MT_LOAD_END_NACK: |
Holger Freyther | 31338a1 | 2009-02-06 17:43:50 +0000 | [diff] [blame] | 1006 | if (sw->forced) { |
| 1007 | DEBUGP(DNM, "FORCED: Ignoring Software Load" |
| 1008 | "End NACK\n"); |
| 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); |
| 1014 | } else { |
| 1015 | DEBUGP(DNM, "Software Load End NACK\n"); |
| 1016 | sw->state = SW_STATE_ERROR; |
| 1017 | if (sw->cbfn) |
| 1018 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 1019 | NM_MT_LOAD_END_NACK, mb, |
| 1020 | sw->cb_data, NULL); |
| 1021 | } |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1022 | break; |
| 1023 | } |
| 1024 | case SW_STATE_WAIT_ACTACK: |
| 1025 | switch (foh->msg_type) { |
| 1026 | case NM_MT_ACTIVATE_SW_ACK: |
| 1027 | /* we're done */ |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1028 | DEBUGP(DNM, "Activate Software DONE!\n"); |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1029 | sw->state = SW_STATE_NONE; |
| 1030 | rc = 0; |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1031 | if (sw->cbfn) |
| 1032 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 1033 | NM_MT_ACTIVATE_SW_ACK, mb, |
| 1034 | sw->cb_data, NULL); |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1035 | break; |
| 1036 | case NM_MT_ACTIVATE_SW_NACK: |
Harald Welte | 1602ade | 2009-01-29 21:12:39 +0000 | [diff] [blame] | 1037 | DEBUGP(DNM, "Activate Software NACK\n"); |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1038 | sw->state = SW_STATE_ERROR; |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1039 | if (sw->cbfn) |
| 1040 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 1041 | NM_MT_ACTIVATE_SW_NACK, mb, |
| 1042 | sw->cb_data, NULL); |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1043 | break; |
| 1044 | } |
| 1045 | case SW_STATE_NONE: |
| 1046 | case SW_STATE_ERROR: |
| 1047 | break; |
| 1048 | } |
| 1049 | |
| 1050 | if (rc) |
| 1051 | fprintf(stderr, "unexpected NM MT 0x%02x in state %u -> %u\n", |
| 1052 | foh->msg_type, old_state, sw->state); |
| 1053 | |
| 1054 | return rc; |
| 1055 | } |
| 1056 | |
| 1057 | /* Load the specified software into the BTS */ |
| 1058 | int abis_nm_software_load(struct gsm_bts *bts, const char *fname, |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 1059 | u_int8_t win_size, int forced, |
| 1060 | gsm_cbfn *cbfn, void *cb_data) |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1061 | { |
| 1062 | struct abis_nm_sw *sw = &g_sw; |
| 1063 | int rc; |
| 1064 | |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1065 | DEBUGP(DNM, "Software Load (BTS %u, File \"%s\")\n", |
| 1066 | bts->nr, fname); |
| 1067 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1068 | if (sw->state != SW_STATE_NONE) |
| 1069 | return -EBUSY; |
| 1070 | |
| 1071 | sw->bts = bts; |
| 1072 | sw->obj_class = NM_OC_SITE_MANAGER; |
| 1073 | sw->obj_instance[0] = 0xff; |
| 1074 | sw->obj_instance[1] = 0xff; |
| 1075 | sw->obj_instance[2] = 0xff; |
| 1076 | sw->window_size = win_size; |
| 1077 | sw->state = SW_STATE_WAIT_INITACK; |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1078 | sw->cbfn = cbfn; |
| 1079 | sw->cb_data = cb_data; |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 1080 | sw->forced = forced; |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1081 | |
| 1082 | rc = sw_open_file(sw, fname); |
| 1083 | if (rc < 0) { |
| 1084 | sw->state = SW_STATE_NONE; |
| 1085 | return rc; |
| 1086 | } |
| 1087 | |
| 1088 | return sw_load_init(sw); |
| 1089 | } |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1090 | |
Harald Welte | 1602ade | 2009-01-29 21:12:39 +0000 | [diff] [blame] | 1091 | int abis_nm_software_load_status(struct gsm_bts *bts) |
| 1092 | { |
| 1093 | struct abis_nm_sw *sw = &g_sw; |
| 1094 | struct stat st; |
| 1095 | int rc, percent; |
| 1096 | |
| 1097 | rc = fstat(sw->fd, &st); |
| 1098 | if (rc < 0) { |
| 1099 | perror("ERROR during stat"); |
| 1100 | return rc; |
| 1101 | } |
| 1102 | |
| 1103 | percent = (ftell(sw->stream) * 100) / st.st_size; |
| 1104 | return percent; |
| 1105 | } |
| 1106 | |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1107 | /* Activate the specified software into the BTS */ |
| 1108 | int abis_nm_software_activate(struct gsm_bts *bts, const char *fname, |
| 1109 | gsm_cbfn *cbfn, void *cb_data) |
| 1110 | { |
| 1111 | struct abis_nm_sw *sw = &g_sw; |
| 1112 | int rc; |
| 1113 | |
| 1114 | DEBUGP(DNM, "Activating Software (BTS %u, File \"%s\")\n", |
| 1115 | bts->nr, fname); |
| 1116 | |
| 1117 | if (sw->state != SW_STATE_NONE) |
| 1118 | return -EBUSY; |
| 1119 | |
| 1120 | sw->bts = bts; |
| 1121 | sw->obj_class = NM_OC_SITE_MANAGER; |
| 1122 | sw->obj_instance[0] = 0xff; |
| 1123 | sw->obj_instance[1] = 0xff; |
| 1124 | sw->obj_instance[2] = 0xff; |
| 1125 | sw->state = SW_STATE_WAIT_ACTACK; |
| 1126 | sw->cbfn = cbfn; |
| 1127 | sw->cb_data = cb_data; |
| 1128 | |
| 1129 | /* Open the file in order to fill some sw struct members */ |
| 1130 | rc = sw_open_file(sw, fname); |
| 1131 | if (rc < 0) { |
| 1132 | sw->state = SW_STATE_NONE; |
| 1133 | return rc; |
| 1134 | } |
| 1135 | sw_close_file(sw); |
| 1136 | |
| 1137 | return sw_activate(sw); |
| 1138 | } |
| 1139 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1140 | 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] | 1141 | u_int8_t ts_nr, u_int8_t subslot_nr) |
| 1142 | { |
Harald Welte | adaf08b | 2009-01-18 11:08:10 +0000 | [diff] [blame] | 1143 | ch->attrib = NM_ATT_ABIS_CHANNEL; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1144 | ch->bts_port = bts_port; |
| 1145 | ch->timeslot = ts_nr; |
| 1146 | ch->subslot = subslot_nr; |
| 1147 | } |
| 1148 | |
| 1149 | int abis_nm_establish_tei(struct gsm_bts *bts, u_int8_t trx_nr, |
| 1150 | u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot, |
| 1151 | u_int8_t tei) |
| 1152 | { |
| 1153 | struct abis_om_hdr *oh; |
| 1154 | struct abis_nm_channel *ch; |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 1155 | u_int8_t len = sizeof(*ch) + 2; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1156 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1157 | |
| 1158 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1159 | fill_om_fom_hdr(oh, len, NM_MT_ESTABLISH_TEI, NM_OC_RADIO_CARRIER, |
| 1160 | bts->bts_nr, trx_nr, 0xff); |
| 1161 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1162 | msgb_tv_put(msg, NM_ATT_TEI, tei); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1163 | |
| 1164 | ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch)); |
| 1165 | fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot); |
| 1166 | |
| 1167 | return abis_nm_sendmsg(bts, msg); |
| 1168 | } |
| 1169 | |
| 1170 | /* connect signalling of one (BTS,TRX) to a particular timeslot on the E1 */ |
| 1171 | int abis_nm_conn_terr_sign(struct gsm_bts_trx *trx, |
| 1172 | u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot) |
| 1173 | { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1174 | struct gsm_bts *bts = trx->bts; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1175 | struct abis_om_hdr *oh; |
| 1176 | struct abis_nm_channel *ch; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1177 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1178 | |
| 1179 | 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] | 1180 | fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_SIGN, |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1181 | NM_OC_RADIO_CARRIER, bts->bts_nr, trx->nr, 0xff); |
| 1182 | |
| 1183 | ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch)); |
| 1184 | fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot); |
| 1185 | |
| 1186 | return abis_nm_sendmsg(bts, msg); |
| 1187 | } |
| 1188 | |
| 1189 | #if 0 |
| 1190 | int abis_nm_disc_terr_sign(struct abis_nm_h *h, struct abis_om_obj_inst *inst, |
| 1191 | struct abis_nm_abis_channel *chan) |
| 1192 | { |
| 1193 | } |
| 1194 | #endif |
| 1195 | |
| 1196 | int abis_nm_conn_terr_traf(struct gsm_bts_trx_ts *ts, |
| 1197 | u_int8_t e1_port, u_int8_t e1_timeslot, |
| 1198 | u_int8_t e1_subslot) |
| 1199 | { |
| 1200 | struct gsm_bts *bts = ts->trx->bts; |
| 1201 | struct abis_om_hdr *oh; |
| 1202 | struct abis_nm_channel *ch; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1203 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1204 | |
| 1205 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1206 | fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_TRAF, |
| 1207 | NM_OC_BASEB_TRANSC, bts->bts_nr, ts->trx->nr, ts->nr); |
| 1208 | |
| 1209 | ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch)); |
| 1210 | fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot); |
| 1211 | |
| 1212 | return abis_nm_sendmsg(bts, msg); |
| 1213 | } |
| 1214 | |
| 1215 | #if 0 |
| 1216 | int abis_nm_disc_terr_traf(struct abis_nm_h *h, struct abis_om_obj_inst *inst, |
| 1217 | struct abis_nm_abis_channel *chan, |
| 1218 | u_int8_t subchan) |
| 1219 | { |
| 1220 | } |
| 1221 | #endif |
| 1222 | |
Harald Welte | 22af0db | 2009-02-14 15:41:08 +0000 | [diff] [blame] | 1223 | /* Chapter 8.6.1 */ |
| 1224 | int abis_nm_set_bts_attr(struct gsm_bts *bts, u_int8_t *attr, int attr_len) |
| 1225 | { |
| 1226 | struct abis_om_hdr *oh; |
| 1227 | struct msgb *msg = nm_msgb_alloc(); |
| 1228 | u_int8_t *cur; |
| 1229 | |
| 1230 | DEBUGP(DNM, "Set BTS Attr (bts=%d)\n", bts->nr); |
| 1231 | |
| 1232 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1233 | fill_om_fom_hdr(oh, attr_len, NM_MT_SET_BTS_ATTR, NM_OC_BTS, bts->nr, 0xff, 0xff); |
| 1234 | cur = msgb_put(msg, attr_len); |
| 1235 | memcpy(cur, attr, attr_len); |
| 1236 | |
| 1237 | return abis_nm_sendmsg(bts, msg); |
| 1238 | } |
| 1239 | |
| 1240 | /* Chapter 8.6.2 */ |
| 1241 | int abis_nm_set_radio_attr(struct gsm_bts_trx *trx, u_int8_t *attr, int attr_len) |
| 1242 | { |
| 1243 | struct abis_om_hdr *oh; |
| 1244 | struct msgb *msg = nm_msgb_alloc(); |
| 1245 | u_int8_t *cur; |
| 1246 | |
| 1247 | DEBUGP(DNM, "Set TRX Attr (bts=%d,trx=%d)\n", trx->bts->nr, trx->nr); |
| 1248 | |
| 1249 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1250 | fill_om_fom_hdr(oh, attr_len, NM_MT_SET_RADIO_ATTR, NM_OC_RADIO_CARRIER, |
| 1251 | trx->bts->nr, trx->nr, 0xff); |
| 1252 | cur = msgb_put(msg, attr_len); |
| 1253 | memcpy(cur, attr, attr_len); |
| 1254 | |
| 1255 | return abis_nm_sendmsg(trx->bts, msg); |
| 1256 | } |
| 1257 | |
| 1258 | /* Chapter 8.6.3 */ |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1259 | int abis_nm_set_channel_attr(struct gsm_bts_trx_ts *ts, u_int8_t chan_comb) |
| 1260 | { |
| 1261 | struct gsm_bts *bts = ts->trx->bts; |
| 1262 | struct abis_om_hdr *oh; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1263 | u_int16_t arfcn = htons(ts->trx->arfcn); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1264 | u_int8_t zero = 0x00; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1265 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 1266 | u_int8_t len = 2 + 2; |
| 1267 | |
| 1268 | if (bts->type == GSM_BTS_TYPE_BS11) |
| 1269 | len += 4 + 2 + 2 + 3; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1270 | |
Harald Welte | 22af0db | 2009-02-14 15:41:08 +0000 | [diff] [blame] | 1271 | DEBUGP(DNM, "Set Chan Attr (bts=%d,trx=%d,ts=%d)\n", bts->nr, ts->trx->nr, ts->nr); |
| 1272 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1273 | 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] | 1274 | fill_om_fom_hdr(oh, len, NM_MT_SET_CHAN_ATTR, |
Holger Freyther | 6b2d262 | 2009-02-14 23:16:59 +0000 | [diff] [blame] | 1275 | NM_OC_CHANNEL, bts->bts_nr, |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1276 | ts->trx->nr, ts->nr); |
| 1277 | /* FIXME: don't send ARFCN list, hopping sequence, mAIO, ...*/ |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 1278 | if (bts->type == GSM_BTS_TYPE_BS11) |
| 1279 | msgb_tlv16_put(msg, NM_ATT_ARFCN_LIST, 1, &arfcn); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1280 | msgb_tv_put(msg, NM_ATT_CHAN_COMB, chan_comb); |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 1281 | if (bts->type == GSM_BTS_TYPE_BS11) { |
| 1282 | msgb_tv_put(msg, NM_ATT_HSN, 0x00); |
| 1283 | msgb_tv_put(msg, NM_ATT_MAIO, 0x00); |
| 1284 | } |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1285 | msgb_tv_put(msg, NM_ATT_TSC, 0x07); /* training sequence */ |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 1286 | if (bts->type == GSM_BTS_TYPE_BS11) |
| 1287 | msgb_tlv_put(msg, 0x59, 1, &zero); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1288 | |
| 1289 | return abis_nm_sendmsg(bts, msg); |
| 1290 | } |
| 1291 | |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 1292 | int abis_nm_sw_act_req_ack(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i1, |
| 1293 | u_int8_t i2, u_int8_t i3, u_int8_t *attr, int att_len) |
| 1294 | { |
| 1295 | struct abis_om_hdr *oh; |
| 1296 | struct msgb *msg = nm_msgb_alloc(); |
| 1297 | |
| 1298 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1299 | fill_om_fom_hdr(oh, att_len, NM_MT_SW_ACT_REQ_ACK, obj_class, i1, i2, i3); |
| 1300 | /* FIXME: don't send ARFCN list, hopping sequence, mAIO, ...*/ |
| 1301 | if (attr) { |
| 1302 | u_int8_t *ptr = msgb_put(msg, att_len); |
| 1303 | memcpy(ptr, attr, att_len); |
| 1304 | } |
| 1305 | |
| 1306 | return abis_nm_sendmsg(bts, msg); |
| 1307 | } |
| 1308 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1309 | 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] | 1310 | { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1311 | struct msgb *msg = nm_msgb_alloc(); |
| 1312 | struct abis_om_hdr *oh; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1313 | u_int8_t *data; |
| 1314 | |
| 1315 | oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh)); |
| 1316 | fill_om_hdr(oh, len); |
| 1317 | data = msgb_put(msg, len); |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 1318 | memcpy(data, rawmsg, len); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1319 | |
| 1320 | return abis_nm_sendmsg(bts, msg); |
| 1321 | } |
| 1322 | |
| 1323 | /* Siemens specific commands */ |
| 1324 | static int __simple_cmd(struct gsm_bts *bts, u_int8_t msg_type) |
| 1325 | { |
| 1326 | struct abis_om_hdr *oh; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1327 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1328 | |
| 1329 | 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] | 1330 | fill_om_fom_hdr(oh, 0, msg_type, NM_OC_SITE_MANAGER, |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1331 | 0xff, 0xff, 0xff); |
| 1332 | |
| 1333 | return abis_nm_sendmsg(bts, msg); |
| 1334 | } |
| 1335 | |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 1336 | /* Chapter 8.9.2 */ |
| 1337 | 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) |
| 1338 | { |
| 1339 | struct abis_om_hdr *oh; |
| 1340 | struct msgb *msg = nm_msgb_alloc(); |
| 1341 | |
Harald Welte | 22af0db | 2009-02-14 15:41:08 +0000 | [diff] [blame] | 1342 | DEBUGP(DNM, "Sending OPSTART obj_class=0x%02x obj_inst=(0x%02x, 0x%02x, 0x%02x)\n", |
| 1343 | obj_class, i0, i1, i2); |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 1344 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1345 | fill_om_fom_hdr(oh, 0, NM_MT_OPSTART, obj_class, i0, i1, i2); |
| 1346 | |
| 1347 | return abis_nm_sendmsg(bts, msg); |
| 1348 | } |
| 1349 | |
| 1350 | /* Chapter 8.8.5 */ |
| 1351 | int abis_nm_chg_adm_state(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, |
| 1352 | u_int8_t i1, u_int8_t i2, u_int8_t adm_state) |
| 1353 | { |
| 1354 | struct abis_om_hdr *oh; |
| 1355 | struct msgb *msg = nm_msgb_alloc(); |
| 1356 | |
| 1357 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1358 | fill_om_fom_hdr(oh, 2, NM_MT_CHG_ADM_STATE, obj_class, i0, i1, i2); |
| 1359 | msgb_tv_put(msg, NM_ATT_ADM_STATE, adm_state); |
| 1360 | |
| 1361 | return abis_nm_sendmsg(bts, msg); |
| 1362 | } |
| 1363 | |
| 1364 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1365 | int abis_nm_event_reports(struct gsm_bts *bts, int on) |
| 1366 | { |
| 1367 | if (on == 0) |
Harald Welte | 227d407 | 2009-01-03 08:16:25 +0000 | [diff] [blame] | 1368 | return __simple_cmd(bts, NM_MT_STOP_EVENT_REP); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1369 | else |
Harald Welte | 227d407 | 2009-01-03 08:16:25 +0000 | [diff] [blame] | 1370 | return __simple_cmd(bts, NM_MT_REST_EVENT_REP); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1371 | } |
| 1372 | |
Harald Welte | 47d88ae | 2009-01-04 12:02:08 +0000 | [diff] [blame] | 1373 | /* Siemens (or BS-11) specific commands */ |
| 1374 | |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 1375 | int abis_nm_bs11_bsc_disconnect(struct gsm_bts *bts, int reconnect) |
| 1376 | { |
| 1377 | if (reconnect == 0) |
| 1378 | return __simple_cmd(bts, NM_MT_BS11_DISCONNECT); |
| 1379 | else |
| 1380 | return __simple_cmd(bts, NM_MT_BS11_RECONNECT); |
| 1381 | } |
| 1382 | |
Harald Welte | b842797 | 2009-02-05 19:27:17 +0000 | [diff] [blame] | 1383 | int abis_nm_bs11_restart(struct gsm_bts *bts) |
| 1384 | { |
| 1385 | return __simple_cmd(bts, NM_MT_BS11_RESTART); |
| 1386 | } |
| 1387 | |
| 1388 | |
Harald Welte | 268bb40 | 2009-02-01 19:11:56 +0000 | [diff] [blame] | 1389 | struct bs11_date_time { |
| 1390 | u_int16_t year; |
| 1391 | u_int8_t month; |
| 1392 | u_int8_t day; |
| 1393 | u_int8_t hour; |
| 1394 | u_int8_t min; |
| 1395 | u_int8_t sec; |
| 1396 | } __attribute__((packed)); |
| 1397 | |
| 1398 | |
| 1399 | void get_bs11_date_time(struct bs11_date_time *aet) |
| 1400 | { |
| 1401 | time_t t; |
| 1402 | struct tm *tm; |
| 1403 | |
| 1404 | t = time(NULL); |
| 1405 | tm = localtime(&t); |
| 1406 | aet->sec = tm->tm_sec; |
| 1407 | aet->min = tm->tm_min; |
| 1408 | aet->hour = tm->tm_hour; |
| 1409 | aet->day = tm->tm_mday; |
| 1410 | aet->month = tm->tm_mon; |
| 1411 | aet->year = htons(1900 + tm->tm_year); |
| 1412 | } |
| 1413 | |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1414 | int abis_nm_bs11_reset_resource(struct gsm_bts *bts) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1415 | { |
Harald Welte | 4668fda | 2009-01-03 08:19:29 +0000 | [diff] [blame] | 1416 | return __simple_cmd(bts, NM_MT_BS11_RESET_RESOURCE); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1417 | } |
| 1418 | |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1419 | int abis_nm_bs11_db_transmission(struct gsm_bts *bts, int begin) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1420 | { |
| 1421 | if (begin) |
Harald Welte | 4668fda | 2009-01-03 08:19:29 +0000 | [diff] [blame] | 1422 | return __simple_cmd(bts, NM_MT_BS11_BEGIN_DB_TX); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1423 | else |
Harald Welte | 4668fda | 2009-01-03 08:19:29 +0000 | [diff] [blame] | 1424 | return __simple_cmd(bts, NM_MT_BS11_END_DB_TX); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1425 | } |
Harald Welte | 47d88ae | 2009-01-04 12:02:08 +0000 | [diff] [blame] | 1426 | |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1427 | int abis_nm_bs11_create_object(struct gsm_bts *bts, |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1428 | enum abis_bs11_objtype type, u_int8_t idx, |
| 1429 | u_int8_t attr_len, const u_int8_t *attr) |
Harald Welte | 47d88ae | 2009-01-04 12:02:08 +0000 | [diff] [blame] | 1430 | { |
| 1431 | struct abis_om_hdr *oh; |
| 1432 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1433 | u_int8_t *cur; |
Harald Welte | 47d88ae | 2009-01-04 12:02:08 +0000 | [diff] [blame] | 1434 | |
| 1435 | 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] | 1436 | fill_om_fom_hdr(oh, attr_len, NM_MT_BS11_CREATE_OBJ, |
Harald Welte | 268bb40 | 2009-02-01 19:11:56 +0000 | [diff] [blame] | 1437 | NM_OC_BS11, type, 0, idx); |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1438 | cur = msgb_put(msg, attr_len); |
| 1439 | memcpy(cur, attr, attr_len); |
Harald Welte | 47d88ae | 2009-01-04 12:02:08 +0000 | [diff] [blame] | 1440 | |
| 1441 | return abis_nm_sendmsg(bts, msg); |
| 1442 | } |
| 1443 | |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1444 | 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] | 1445 | { |
| 1446 | struct abis_om_hdr *oh; |
| 1447 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1448 | u_int8_t zero = 0x00; |
Harald Welte | 47d88ae | 2009-01-04 12:02:08 +0000 | [diff] [blame] | 1449 | |
| 1450 | 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] | 1451 | fill_om_fom_hdr(oh, 3, NM_MT_BS11_CREATE_OBJ, |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1452 | NM_OC_BS11_ENVABTSE, 0, idx, 0xff); |
| 1453 | msgb_tlv_put(msg, 0x99, 1, &zero); |
Harald Welte | 47d88ae | 2009-01-04 12:02:08 +0000 | [diff] [blame] | 1454 | |
| 1455 | return abis_nm_sendmsg(bts, msg); |
| 1456 | } |
| 1457 | |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1458 | 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] | 1459 | { |
| 1460 | struct abis_om_hdr *oh; |
| 1461 | struct msgb *msg = nm_msgb_alloc(); |
| 1462 | |
| 1463 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1464 | fill_om_fom_hdr(oh, 0, NM_MT_BS11_CREATE_OBJ, NM_OC_BS11_BPORT, |
| 1465 | idx, 0, 0); |
| 1466 | |
| 1467 | return abis_nm_sendmsg(bts, msg); |
| 1468 | } |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1469 | |
| 1470 | int abis_nm_bs11_set_oml_tei(struct gsm_bts *bts, u_int8_t tei) |
| 1471 | { |
| 1472 | struct abis_om_hdr *oh; |
| 1473 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1474 | |
| 1475 | 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] | 1476 | 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] | 1477 | 0xff, 0xff, 0xff); |
| 1478 | msgb_tv_put(msg, NM_ATT_TEI, tei); |
| 1479 | |
| 1480 | return abis_nm_sendmsg(bts, msg); |
| 1481 | } |
| 1482 | |
| 1483 | /* like abis_nm_conn_terr_traf */ |
| 1484 | int abis_nm_bs11_conn_oml(struct gsm_bts *bts, u_int8_t e1_port, |
| 1485 | u_int8_t e1_timeslot, u_int8_t e1_subslot) |
| 1486 | { |
| 1487 | struct abis_om_hdr *oh; |
| 1488 | struct abis_nm_channel *ch; |
| 1489 | struct msgb *msg = nm_msgb_alloc(); |
| 1490 | |
| 1491 | 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] | 1492 | fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_BS11_SET_ATTR, |
| 1493 | NM_OC_SITE_MANAGER, 0xff, 0xff, 0xff); |
| 1494 | |
| 1495 | ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch)); |
| 1496 | fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot); |
| 1497 | |
| 1498 | return abis_nm_sendmsg(bts, msg); |
| 1499 | } |
| 1500 | |
| 1501 | int abis_nm_bs11_set_trx_power(struct gsm_bts_trx *trx, u_int8_t level) |
| 1502 | { |
| 1503 | struct abis_om_hdr *oh; |
| 1504 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1505 | |
| 1506 | 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] | 1507 | fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR, |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1508 | NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr); |
| 1509 | msgb_tlv_put(msg, NM_ATT_BS11_TXPWR, 1, &level); |
| 1510 | |
| 1511 | return abis_nm_sendmsg(trx->bts, msg); |
| 1512 | } |
| 1513 | |
Harald Welte | 268bb40 | 2009-02-01 19:11:56 +0000 | [diff] [blame] | 1514 | //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] | 1515 | static const u_int8_t bs11_logon_c8[] = { 0x02 }; |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1516 | static const u_int8_t bs11_logon_c9[] = "FACTORY"; |
| 1517 | |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1518 | int abis_nm_bs11_factory_logon(struct gsm_bts *bts, int on) |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1519 | { |
| 1520 | struct abis_om_hdr *oh; |
| 1521 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 268bb40 | 2009-02-01 19:11:56 +0000 | [diff] [blame] | 1522 | struct bs11_date_time bdt; |
| 1523 | |
| 1524 | get_bs11_date_time(&bdt); |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1525 | |
| 1526 | 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] | 1527 | if (on) { |
Harald Welte | 268bb40 | 2009-02-01 19:11:56 +0000 | [diff] [blame] | 1528 | u_int8_t len = 3*2 + sizeof(bdt) |
Harald Welte | 6f676a3 | 2009-01-18 14:27:48 +0000 | [diff] [blame] | 1529 | + sizeof(bs11_logon_c8) + sizeof(bs11_logon_c9); |
Harald Welte | 043d04a | 2009-01-29 23:15:30 +0000 | [diff] [blame] | 1530 | fill_om_fom_hdr(oh, len, NM_MT_BS11_LMT_LOGON, |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1531 | NM_OC_BS11_A3, 0xff, 0xff, 0xff); |
Harald Welte | 043d04a | 2009-01-29 23:15:30 +0000 | [diff] [blame] | 1532 | msgb_tlv_put(msg, NM_ATT_BS11_LMT_LOGIN_TIME, |
Harald Welte | 5083b0b | 2009-02-02 19:20:52 +0000 | [diff] [blame] | 1533 | sizeof(bdt), (u_int8_t *) &bdt); |
Harald Welte | 043d04a | 2009-01-29 23:15:30 +0000 | [diff] [blame] | 1534 | msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_ACC_LEV, |
| 1535 | sizeof(bs11_logon_c8), bs11_logon_c8); |
| 1536 | msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_NAME, |
| 1537 | sizeof(bs11_logon_c9), bs11_logon_c9); |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1538 | } else { |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1539 | fill_om_fom_hdr(oh, 0, NM_MT_BS11_LMT_LOGOFF, |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1540 | NM_OC_BS11_A3, 0xff, 0xff, 0xff); |
| 1541 | } |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1542 | |
| 1543 | return abis_nm_sendmsg(bts, msg); |
| 1544 | } |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1545 | |
| 1546 | int abis_nm_bs11_set_trx1_pw(struct gsm_bts *bts, const char *password) |
| 1547 | { |
| 1548 | struct abis_om_hdr *oh; |
| 1549 | struct msgb *msg; |
| 1550 | |
| 1551 | if (strlen(password) != 10) |
| 1552 | return -EINVAL; |
| 1553 | |
| 1554 | msg = nm_msgb_alloc(); |
| 1555 | 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] | 1556 | 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] | 1557 | NM_OC_BS11, BS11_OBJ_TRX1, 0x00, 0x00); |
| 1558 | msgb_tlv_put(msg, NM_ATT_BS11_PASSWORD, 10, (const u_int8_t *)password); |
| 1559 | |
| 1560 | return abis_nm_sendmsg(bts, msg); |
| 1561 | } |
| 1562 | |
| 1563 | int abis_nm_bs11_get_state(struct gsm_bts *bts) |
| 1564 | { |
| 1565 | return __simple_cmd(bts, NM_MT_BS11_GET_STATE); |
| 1566 | } |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1567 | |
| 1568 | /* BS11 SWL */ |
| 1569 | |
| 1570 | struct abis_nm_bs11_sw { |
| 1571 | struct gsm_bts *bts; |
| 1572 | char swl_fname[PATH_MAX]; |
| 1573 | u_int8_t win_size; |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 1574 | int forced; |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1575 | struct llist_head file_list; |
| 1576 | gsm_cbfn *user_cb; /* specified by the user */ |
| 1577 | }; |
| 1578 | static struct abis_nm_bs11_sw _g_bs11_sw, *g_bs11_sw = &_g_bs11_sw; |
| 1579 | |
| 1580 | struct file_list_entry { |
| 1581 | struct llist_head list; |
| 1582 | char fname[PATH_MAX]; |
| 1583 | }; |
| 1584 | |
| 1585 | struct file_list_entry *fl_dequeue(struct llist_head *queue) |
| 1586 | { |
| 1587 | struct llist_head *lh; |
| 1588 | |
| 1589 | if (llist_empty(queue)) |
| 1590 | return NULL; |
| 1591 | |
| 1592 | lh = queue->next; |
| 1593 | llist_del(lh); |
| 1594 | |
| 1595 | return llist_entry(lh, struct file_list_entry, list); |
| 1596 | } |
| 1597 | |
| 1598 | static int bs11_read_swl_file(struct abis_nm_bs11_sw *bs11_sw) |
| 1599 | { |
| 1600 | char linebuf[255]; |
| 1601 | struct llist_head *lh, *lh2; |
| 1602 | FILE *swl; |
| 1603 | int rc = 0; |
| 1604 | |
| 1605 | swl = fopen(bs11_sw->swl_fname, "r"); |
| 1606 | if (!swl) |
| 1607 | return -ENODEV; |
| 1608 | |
| 1609 | /* zero the stale file list, if any */ |
| 1610 | llist_for_each_safe(lh, lh2, &bs11_sw->file_list) { |
| 1611 | llist_del(lh); |
| 1612 | free(lh); |
| 1613 | } |
| 1614 | |
| 1615 | while (fgets(linebuf, sizeof(linebuf), swl)) { |
| 1616 | char file_id[12+1]; |
| 1617 | char file_version[80+1]; |
| 1618 | struct file_list_entry *fle; |
| 1619 | static char dir[PATH_MAX]; |
| 1620 | |
| 1621 | if (strlen(linebuf) < 4) |
| 1622 | continue; |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 1623 | |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1624 | rc = sscanf(linebuf+4, "%12s:%80s\r\n", file_id, file_version); |
| 1625 | if (rc < 0) { |
| 1626 | perror("ERR parsing SWL file"); |
| 1627 | rc = -EINVAL; |
| 1628 | goto out; |
| 1629 | } |
| 1630 | if (rc < 2) |
| 1631 | continue; |
| 1632 | |
| 1633 | fle = malloc(sizeof(*fle)); |
| 1634 | if (!fle) { |
| 1635 | rc = -ENOMEM; |
| 1636 | goto out; |
| 1637 | } |
| 1638 | memset(fle, 0, sizeof(*fle)); |
| 1639 | |
| 1640 | /* construct new filename */ |
| 1641 | strncpy(dir, bs11_sw->swl_fname, sizeof(dir)); |
| 1642 | strncat(fle->fname, dirname(dir), sizeof(fle->fname) - 1); |
| 1643 | strcat(fle->fname, "/"); |
| 1644 | strncat(fle->fname, file_id, sizeof(fle->fname) - 1 -strlen(fle->fname)); |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1645 | |
| 1646 | llist_add_tail(&fle->list, &bs11_sw->file_list); |
| 1647 | } |
| 1648 | |
| 1649 | out: |
| 1650 | fclose(swl); |
| 1651 | return rc; |
| 1652 | } |
| 1653 | |
| 1654 | /* bs11 swload specific callback, passed to abis_nm core swload */ |
| 1655 | static int bs11_swload_cbfn(unsigned int hook, unsigned int event, |
| 1656 | struct msgb *msg, void *data, void *param) |
| 1657 | { |
| 1658 | struct abis_nm_bs11_sw *bs11_sw = data; |
| 1659 | struct file_list_entry *fle; |
| 1660 | int rc = 0; |
| 1661 | |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1662 | switch (event) { |
| 1663 | case NM_MT_LOAD_END_ACK: |
| 1664 | fle = fl_dequeue(&bs11_sw->file_list); |
| 1665 | if (fle) { |
| 1666 | /* start download the next file of our file list */ |
| 1667 | rc = abis_nm_software_load(bs11_sw->bts, fle->fname, |
| 1668 | bs11_sw->win_size, |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 1669 | bs11_sw->forced, |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1670 | &bs11_swload_cbfn, bs11_sw); |
| 1671 | free(fle); |
| 1672 | } else { |
| 1673 | /* activate the SWL */ |
| 1674 | rc = abis_nm_software_activate(bs11_sw->bts, |
| 1675 | bs11_sw->swl_fname, |
| 1676 | bs11_swload_cbfn, |
| 1677 | bs11_sw); |
| 1678 | } |
| 1679 | break; |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 1680 | case NM_MT_LOAD_SEG_ACK: |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1681 | case NM_MT_LOAD_END_NACK: |
| 1682 | case NM_MT_LOAD_INIT_ACK: |
| 1683 | case NM_MT_LOAD_INIT_NACK: |
| 1684 | case NM_MT_ACTIVATE_SW_NACK: |
| 1685 | case NM_MT_ACTIVATE_SW_ACK: |
| 1686 | default: |
| 1687 | /* fallthrough to the user callback */ |
Harald Welte | 97ed1e7 | 2009-02-06 13:38:02 +0000 | [diff] [blame] | 1688 | if (bs11_sw->user_cb) |
| 1689 | rc = bs11_sw->user_cb(hook, event, msg, NULL, NULL); |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1690 | break; |
| 1691 | } |
| 1692 | |
| 1693 | return rc; |
| 1694 | } |
| 1695 | |
| 1696 | /* Siemens provides a SWL file that is a mere listing of all the other |
| 1697 | * files that are part of a software release. We need to upload first |
| 1698 | * the list file, and then each file that is listed in the list file */ |
| 1699 | 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] | 1700 | u_int8_t win_size, int forced, gsm_cbfn *cbfn) |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1701 | { |
| 1702 | struct abis_nm_bs11_sw *bs11_sw = g_bs11_sw; |
| 1703 | struct file_list_entry *fle; |
| 1704 | int rc = 0; |
| 1705 | |
| 1706 | INIT_LLIST_HEAD(&bs11_sw->file_list); |
| 1707 | bs11_sw->bts = bts; |
| 1708 | bs11_sw->win_size = win_size; |
| 1709 | bs11_sw->user_cb = cbfn; |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 1710 | bs11_sw->forced = forced; |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1711 | |
| 1712 | strncpy(bs11_sw->swl_fname, fname, sizeof(bs11_sw->swl_fname)); |
| 1713 | rc = bs11_read_swl_file(bs11_sw); |
| 1714 | if (rc < 0) |
| 1715 | return rc; |
| 1716 | |
| 1717 | /* dequeue next item in file list */ |
| 1718 | fle = fl_dequeue(&bs11_sw->file_list); |
| 1719 | if (!fle) |
| 1720 | return -EINVAL; |
| 1721 | |
| 1722 | /* start download the next file of our file list */ |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 1723 | rc = abis_nm_software_load(bts, fle->fname, win_size, forced, |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1724 | bs11_swload_cbfn, bs11_sw); |
| 1725 | free(fle); |
| 1726 | return rc; |
| 1727 | } |
| 1728 | |
Harald Welte | 5083b0b | 2009-02-02 19:20:52 +0000 | [diff] [blame] | 1729 | #if 0 |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1730 | static u_int8_t req_attr_btse[] = { |
| 1731 | NM_ATT_ADM_STATE, NM_ATT_BS11_LMT_LOGON_SESSION, |
| 1732 | NM_ATT_BS11_LMT_LOGIN_TIME, NM_ATT_BS11_LMT_USER_ACC_LEV, |
| 1733 | NM_ATT_BS11_LMT_USER_NAME, |
| 1734 | |
| 1735 | 0xaf, NM_ATT_BS11_RX_OFFSET, NM_ATT_BS11_VENDOR_NAME, |
| 1736 | |
| 1737 | NM_ATT_BS11_SW_LOAD_INTENDED, NM_ATT_BS11_SW_LOAD_SAFETY, |
| 1738 | |
| 1739 | NM_ATT_BS11_SW_LOAD_STORED }; |
| 1740 | |
| 1741 | static u_int8_t req_attr_btsm[] = { |
| 1742 | NM_ATT_ABIS_CHANNEL, NM_ATT_TEI, NM_ATT_BS11_ABIS_EXT_TIME, |
| 1743 | NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xce, NM_ATT_FILE_ID, |
| 1744 | NM_ATT_FILE_VERSION, NM_ATT_OPER_STATE, 0xe8, NM_ATT_BS11_ALL_TEST_CATG, |
| 1745 | NM_ATT_SW_DESCR, NM_ATT_GET_ARI }; |
Harald Welte | 5083b0b | 2009-02-02 19:20:52 +0000 | [diff] [blame] | 1746 | #endif |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1747 | |
| 1748 | static u_int8_t req_attr[] = { |
| 1749 | NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xa8, NM_ATT_OPER_STATE, |
| 1750 | 0xd5, 0xa1, NM_ATT_BS11_ESN_FW_CODE_NO, NM_ATT_BS11_ESN_HW_CODE_NO, |
| 1751 | 0x42, NM_ATT_BS11_ESN_PCB_SERIAL }; |
| 1752 | |
| 1753 | int abis_nm_bs11_get_serno(struct gsm_bts *bts) |
| 1754 | { |
| 1755 | struct abis_om_hdr *oh; |
| 1756 | struct msgb *msg = nm_msgb_alloc(); |
| 1757 | |
| 1758 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1759 | /* SiemensHW CCTRL object */ |
| 1760 | fill_om_fom_hdr(oh, 2+sizeof(req_attr), NM_MT_GET_ATTR, NM_OC_BS11, |
| 1761 | 0x03, 0x00, 0x00); |
| 1762 | msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(req_attr), req_attr); |
| 1763 | |
| 1764 | return abis_nm_sendmsg(bts, msg); |
| 1765 | } |
Harald Welte | 268bb40 | 2009-02-01 19:11:56 +0000 | [diff] [blame] | 1766 | |
| 1767 | int abis_nm_bs11_set_ext_time(struct gsm_bts *bts) |
| 1768 | { |
| 1769 | struct abis_om_hdr *oh; |
| 1770 | struct msgb *msg = nm_msgb_alloc(); |
| 1771 | struct bs11_date_time aet; |
| 1772 | |
| 1773 | get_bs11_date_time(&aet); |
| 1774 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1775 | /* SiemensHW CCTRL object */ |
| 1776 | fill_om_fom_hdr(oh, 2+sizeof(aet), NM_MT_BS11_SET_ATTR, NM_OC_SITE_MANAGER, |
| 1777 | 0xff, 0xff, 0xff); |
Harald Welte | 5083b0b | 2009-02-02 19:20:52 +0000 | [diff] [blame] | 1778 | 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] | 1779 | |
| 1780 | return abis_nm_sendmsg(bts, msg); |
| 1781 | } |