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