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