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