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 | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 560 | DEBUGP(DNM, "STATE CHG: OC=%s(%02x) INST=(%02x,%02x,%02x) ", |
| 561 | obj_class_name(foh->obj_class), foh->obj_class, |
| 562 | foh->obj_inst.bts_nr, foh->obj_inst.trx_nr, |
Harald Welte | 97ed1e7 | 2009-02-06 13:38:02 +0000 | [diff] [blame] | 563 | foh->obj_inst.ts_nr); |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 564 | |
| 565 | nm_state = objclass2nmstate(bts, foh->obj_class, &foh->obj_inst); |
| 566 | if (!nm_state) { |
| 567 | DEBUGPC(DNM, "\n"); |
| 568 | return -EINVAL; |
Harald Welte | 22af0db | 2009-02-14 15:41:08 +0000 | [diff] [blame] | 569 | } |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 570 | |
| 571 | new_state = *nm_state; |
| 572 | |
Harald Welte | 0313394 | 2009-02-18 19:51:53 +0000 | [diff] [blame] | 573 | abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh)); |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 574 | if (TLVP_PRESENT(&tp, NM_ATT_OPER_STATE)) { |
| 575 | new_state.operational = *TLVP_VAL(&tp, NM_ATT_OPER_STATE); |
Harald Welte | 4d87f24 | 2009-03-10 19:43:44 +0000 | [diff] [blame] | 576 | DEBUGPC(DNM, "OP_STATE=%s ", nm_opstate_name(new_state.operational)); |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 577 | } |
| 578 | if (TLVP_PRESENT(&tp, NM_ATT_AVAIL_STATUS)) { |
Harald Welte | 0b8348d | 2009-02-18 03:43:01 +0000 | [diff] [blame] | 579 | if (TLVP_LEN(&tp, NM_ATT_AVAIL_STATUS) == 0) |
| 580 | new_state.availability = 0xff; |
| 581 | else |
| 582 | new_state.availability = *TLVP_VAL(&tp, NM_ATT_AVAIL_STATUS); |
Harald Welte | 4d87f24 | 2009-03-10 19:43:44 +0000 | [diff] [blame] | 583 | DEBUGPC(DNM, "AVAIL=%s(%02x) ", nm_avail_name(new_state.availability), |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 584 | new_state.availability); |
| 585 | } |
| 586 | if (TLVP_PRESENT(&tp, NM_ATT_ADM_STATE)) { |
| 587 | new_state.administrative = *TLVP_VAL(&tp, NM_ATT_ADM_STATE); |
| 588 | DEBUGPC(DNM, "ADM=%02x ", new_state.administrative); |
Harald Welte | 97ed1e7 | 2009-02-06 13:38:02 +0000 | [diff] [blame] | 589 | } |
| 590 | DEBUGPC(DNM, "\n"); |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 591 | |
| 592 | if (memcmp(&new_state, nm_state, sizeof(new_state))) { |
| 593 | /* Update the operational state of a given object in our in-memory data |
| 594 | * structures and send an event to the higher layer */ |
| 595 | void *obj = objclass2obj(bts, foh->obj_class, &foh->obj_inst); |
| 596 | rc = nm_state_event(EVT_STATECHG_OPER, foh->obj_class, obj, nm_state, &new_state); |
| 597 | *nm_state = new_state; |
| 598 | } |
| 599 | #if 0 |
Harald Welte | 22af0db | 2009-02-14 15:41:08 +0000 | [diff] [blame] | 600 | if (op_state == 1) { |
| 601 | /* try to enable objects that are disabled */ |
| 602 | abis_nm_opstart(bts, foh->obj_class, |
| 603 | foh->obj_inst.bts_nr, |
| 604 | foh->obj_inst.trx_nr, |
| 605 | foh->obj_inst.ts_nr); |
| 606 | } |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 607 | #endif |
Harald Welte | 97ed1e7 | 2009-02-06 13:38:02 +0000 | [diff] [blame] | 608 | return 0; |
| 609 | } |
| 610 | |
| 611 | static int abis_nm_rcvmsg_report(struct msgb *mb) |
| 612 | { |
| 613 | struct abis_om_fom_hdr *foh = msgb_l3(mb); |
| 614 | u_int8_t mt = foh->msg_type; |
| 615 | |
| 616 | //nmh->cfg->report_cb(mb, foh); |
| 617 | |
| 618 | switch (mt) { |
| 619 | case NM_MT_STATECHG_EVENT_REP: |
| 620 | return abis_nm_rx_statechg_rep(mb); |
| 621 | break; |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 622 | case NM_MT_SW_ACTIVATED_REP: |
| 623 | DEBUGP(DNM, "Software Activated Report\n"); |
| 624 | break; |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 625 | case NM_MT_FAILURE_EVENT_REP: |
| 626 | DEBUGP(DNM, "Failure Event Report\n"); |
| 627 | break; |
| 628 | default: |
| 629 | DEBUGP(DNM, "reporting NM MT 0x%02x\n", mt); |
| 630 | break; |
| 631 | |
Harald Welte | 97ed1e7 | 2009-02-06 13:38:02 +0000 | [diff] [blame] | 632 | }; |
| 633 | |
Harald Welte | 97ed1e7 | 2009-02-06 13:38:02 +0000 | [diff] [blame] | 634 | return 0; |
| 635 | } |
| 636 | |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 637 | /* Activate the specified software into the BTS */ |
| 638 | static int ipacc_sw_activate(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1, |
| 639 | u_int8_t i2, u_int8_t *sw_desc, u_int8_t swdesc_len) |
| 640 | { |
| 641 | struct abis_om_hdr *oh; |
| 642 | struct msgb *msg = nm_msgb_alloc(); |
| 643 | u_int8_t len = swdesc_len; |
| 644 | u_int8_t *trailer; |
| 645 | |
| 646 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 647 | fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, obj_class, i0, i1, i2); |
| 648 | |
| 649 | trailer = msgb_put(msg, swdesc_len); |
| 650 | memcpy(trailer, sw_desc, swdesc_len); |
| 651 | |
| 652 | return abis_nm_sendmsg(bts, msg); |
| 653 | } |
| 654 | |
| 655 | static int abis_nm_rx_sw_act_req(struct msgb *mb) |
| 656 | { |
| 657 | struct abis_om_hdr *oh = msgb_l2(mb); |
| 658 | struct abis_om_fom_hdr *foh = msgb_l3(mb); |
Harald Welte | 5c1e458 | 2009-02-15 11:57:29 +0000 | [diff] [blame] | 659 | int nack = 0; |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 660 | int ret; |
| 661 | |
Harald Welte | 5c1e458 | 2009-02-15 11:57:29 +0000 | [diff] [blame] | 662 | DEBUGP(DNM, "Software Activate Request "); |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 663 | |
Harald Welte | 5c1e458 | 2009-02-15 11:57:29 +0000 | [diff] [blame] | 664 | if (foh->obj_class >= 0xf0 && foh->obj_class <= 0xf3) { |
| 665 | DEBUGPC(DNM, "NACKing for GPRS obj_class 0x%02x\n", foh->obj_class); |
| 666 | nack = 1; |
| 667 | } else |
| 668 | DEBUGPC(DNM, "ACKing and Activating\n"); |
| 669 | |
| 670 | 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] | 671 | foh->obj_inst.bts_nr, |
| 672 | foh->obj_inst.trx_nr, |
Harald Welte | 5c1e458 | 2009-02-15 11:57:29 +0000 | [diff] [blame] | 673 | foh->obj_inst.ts_nr, nack, |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 674 | foh->data, oh->length-sizeof(*foh)); |
| 675 | |
Harald Welte | 5c1e458 | 2009-02-15 11:57:29 +0000 | [diff] [blame] | 676 | if (nack) |
| 677 | return ret; |
| 678 | |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 679 | /* FIXME: properly parse attributes */ |
| 680 | return ipacc_sw_activate(mb->trx->bts, foh->obj_class, |
| 681 | foh->obj_inst.bts_nr, |
| 682 | foh->obj_inst.trx_nr, |
| 683 | foh->obj_inst.ts_nr, |
| 684 | foh->data + oh->length-sizeof(*foh)-22, 22); |
| 685 | } |
| 686 | |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 687 | /* Receive a CHANGE_ADM_STATE_ACK, parse the TLV and update local state */ |
| 688 | static int abis_nm_rx_chg_adm_state_ack(struct msgb *mb) |
| 689 | { |
| 690 | struct abis_om_hdr *oh = msgb_l2(mb); |
| 691 | struct abis_om_fom_hdr *foh = msgb_l3(mb); |
| 692 | struct tlv_parsed tp; |
| 693 | u_int8_t adm_state; |
| 694 | |
Harald Welte | 0313394 | 2009-02-18 19:51:53 +0000 | [diff] [blame] | 695 | abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh)); |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 696 | if (!TLVP_PRESENT(&tp, NM_ATT_ADM_STATE)) |
| 697 | return -EINVAL; |
| 698 | |
| 699 | adm_state = *TLVP_VAL(&tp, NM_ATT_ADM_STATE); |
| 700 | |
| 701 | return update_admstate(mb->trx->bts, foh->obj_class, &foh->obj_inst, adm_state); |
| 702 | } |
| 703 | |
Harald Welte | ee67047 | 2009-02-22 21:58:49 +0000 | [diff] [blame] | 704 | static int abis_nm_rx_lmt_event(struct msgb *mb) |
| 705 | { |
| 706 | struct abis_om_hdr *oh = msgb_l2(mb); |
| 707 | struct abis_om_fom_hdr *foh = msgb_l3(mb); |
| 708 | struct tlv_parsed tp; |
| 709 | |
| 710 | DEBUGP(DNM, "LMT Event "); |
| 711 | abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh)); |
| 712 | if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_LOGON_SESSION) && |
| 713 | TLVP_LEN(&tp, NM_ATT_BS11_LMT_LOGON_SESSION) >= 1) { |
| 714 | u_int8_t onoff = *TLVP_VAL(&tp, NM_ATT_BS11_LMT_LOGON_SESSION); |
| 715 | DEBUGPC(DNM, "LOG%s ", onoff ? "ON" : "OFF"); |
| 716 | } |
| 717 | if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV) && |
| 718 | TLVP_LEN(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV) >= 1) { |
| 719 | u_int8_t level = *TLVP_VAL(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV); |
| 720 | DEBUGPC(DNM, "Level=%u ", level); |
| 721 | } |
| 722 | if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_USER_NAME) && |
| 723 | TLVP_LEN(&tp, NM_ATT_BS11_LMT_USER_NAME) >= 1) { |
| 724 | char *name = (char *) TLVP_VAL(&tp, NM_ATT_BS11_LMT_USER_NAME); |
| 725 | DEBUGPC(DNM, "Username=%s ", name); |
| 726 | } |
| 727 | DEBUGPC(DNM, "\n"); |
| 728 | /* FIXME: parse LMT LOGON TIME */ |
| 729 | return 0; |
| 730 | } |
| 731 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 732 | /* Receive a OML NM Message from BTS */ |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 733 | static int abis_nm_rcvmsg_fom(struct msgb *mb) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 734 | { |
Harald Welte | 6c96ba5 | 2009-05-01 13:03:40 +0000 | [diff] [blame] | 735 | struct abis_om_hdr *oh = msgb_l2(mb); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 736 | struct abis_om_fom_hdr *foh = msgb_l3(mb); |
| 737 | u_int8_t mt = foh->msg_type; |
| 738 | |
| 739 | /* check for unsolicited message */ |
Harald Welte | 97ed1e7 | 2009-02-06 13:38:02 +0000 | [diff] [blame] | 740 | if (is_report(mt)) |
| 741 | return abis_nm_rcvmsg_report(mb); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 742 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 743 | if (is_in_arr(mt, sw_load_msgs, ARRAY_SIZE(sw_load_msgs))) |
| 744 | return abis_nm_rcvmsg_sw(mb); |
| 745 | |
Harald Welte | 78fc0d4 | 2009-02-19 02:50:57 +0000 | [diff] [blame] | 746 | if (is_in_arr(mt, nacks, ARRAY_SIZE(nacks))) { |
Harald Welte | 6c96ba5 | 2009-05-01 13:03:40 +0000 | [diff] [blame] | 747 | struct tlv_parsed tp; |
Harald Welte | 78fc0d4 | 2009-02-19 02:50:57 +0000 | [diff] [blame] | 748 | if (nack_names[mt]) |
Harald Welte | 6c96ba5 | 2009-05-01 13:03:40 +0000 | [diff] [blame] | 749 | DEBUGP(DNM, "%s NACK ", nack_names[mt]); |
| 750 | /* FIXME: NACK cause */ |
Harald Welte | 78fc0d4 | 2009-02-19 02:50:57 +0000 | [diff] [blame] | 751 | else |
Harald Welte | 6c96ba5 | 2009-05-01 13:03:40 +0000 | [diff] [blame] | 752 | DEBUGP(DNM, "NACK 0x%02x ", mt); |
| 753 | |
| 754 | abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh)); |
| 755 | if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES)) |
| 756 | DEBUGPC(DNM, "CAUSE=%s\n", |
| 757 | nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES))); |
| 758 | else |
| 759 | DEBUGPC(DNM, "\n"); |
Harald Welte | 78fc0d4 | 2009-02-19 02:50:57 +0000 | [diff] [blame] | 760 | } |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 761 | #if 0 |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 762 | /* check if last message is to be acked */ |
| 763 | if (is_ack_nack(nmh->last_msgtype)) { |
| 764 | if (mt == MT_ACK(nmh->last_msgtype)) { |
| 765 | fprintf(stderr, "received ACK (0x%x)\n", |
| 766 | foh->msg_type); |
| 767 | /* we got our ACK, continue sending the next msg */ |
| 768 | } else if (mt == MT_NACK(nmh->last_msgtype)) { |
| 769 | /* we got a NACK, signal this to the caller */ |
| 770 | fprintf(stderr, "received NACK (0x%x)\n", |
| 771 | foh->msg_type); |
| 772 | /* FIXME: somehow signal this to the caller */ |
| 773 | } else { |
| 774 | /* really strange things happen */ |
| 775 | return -EINVAL; |
| 776 | } |
| 777 | } |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 778 | #endif |
| 779 | |
Harald Welte | 97ed1e7 | 2009-02-06 13:38:02 +0000 | [diff] [blame] | 780 | switch (mt) { |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 781 | case NM_MT_CHG_ADM_STATE_ACK: |
| 782 | return abis_nm_rx_chg_adm_state_ack(mb); |
| 783 | break; |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 784 | case NM_MT_SW_ACT_REQ: |
| 785 | return abis_nm_rx_sw_act_req(mb); |
| 786 | break; |
Harald Welte | 97ed1e7 | 2009-02-06 13:38:02 +0000 | [diff] [blame] | 787 | case NM_MT_BS11_LMT_SESSION: |
Harald Welte | ee67047 | 2009-02-22 21:58:49 +0000 | [diff] [blame] | 788 | return abis_nm_rx_lmt_event(mb); |
Harald Welte | 97ed1e7 | 2009-02-06 13:38:02 +0000 | [diff] [blame] | 789 | break; |
| 790 | } |
| 791 | |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 792 | return 0; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 793 | } |
| 794 | |
Harald Welte | 677c21f | 2009-02-17 13:22:23 +0000 | [diff] [blame] | 795 | static int abis_nm_rx_ipacc(struct msgb *mb); |
| 796 | |
| 797 | static int abis_nm_rcvmsg_manuf(struct msgb *mb) |
| 798 | { |
| 799 | int rc; |
| 800 | int bts_type = mb->trx->bts->type; |
| 801 | |
| 802 | switch (bts_type) { |
| 803 | case GSM_BTS_TYPE_NANOBTS_900: |
| 804 | case GSM_BTS_TYPE_NANOBTS_1800: |
| 805 | rc = abis_nm_rx_ipacc(mb); |
| 806 | break; |
| 807 | default: |
| 808 | fprintf(stderr, "don't know how to parse OML for this " |
| 809 | "BTS type (%u)\n", bts_type); |
| 810 | rc = 0; |
| 811 | break; |
| 812 | } |
| 813 | |
| 814 | return rc; |
| 815 | } |
| 816 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 817 | /* High-Level API */ |
| 818 | /* Entry-point where L2 OML from BTS enters the NM code */ |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 819 | int abis_nm_rcvmsg(struct msgb *msg) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 820 | { |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 821 | struct abis_om_hdr *oh = msgb_l2(msg); |
Harald Welte | 677c21f | 2009-02-17 13:22:23 +0000 | [diff] [blame] | 822 | int rc = 0; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 823 | |
| 824 | /* Various consistency checks */ |
| 825 | if (oh->placement != ABIS_OM_PLACEMENT_ONLY) { |
| 826 | fprintf(stderr, "ABIS OML placement 0x%x not supported\n", |
| 827 | oh->placement); |
| 828 | return -EINVAL; |
| 829 | } |
| 830 | if (oh->sequence != 0) { |
| 831 | fprintf(stderr, "ABIS OML sequence 0x%x != 0x00\n", |
| 832 | oh->sequence); |
| 833 | return -EINVAL; |
| 834 | } |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 835 | #if 0 |
Holger Freyther | ca362a6 | 2009-01-04 21:05:01 +0000 | [diff] [blame] | 836 | unsigned int l2_len = msg->tail - (u_int8_t *)msgb_l2(msg); |
| 837 | unsigned int hlen = sizeof(*oh) + sizeof(struct abis_om_fom_hdr); |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 838 | if (oh->length + hlen > l2_len) { |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 839 | fprintf(stderr, "ABIS OML truncated message (%u > %u)\n", |
| 840 | oh->length + sizeof(*oh), l2_len); |
| 841 | return -EINVAL; |
| 842 | } |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 843 | if (oh->length + hlen < l2_len) |
| 844 | fprintf(stderr, "ABIS OML message with extra trailer?!? (oh->len=%d, sizeof_oh=%d l2_len=%d\n", oh->length, sizeof(*oh), l2_len); |
| 845 | #endif |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 846 | msg->l3h = (unsigned char *)oh + sizeof(*oh); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 847 | |
| 848 | switch (oh->mdisc) { |
| 849 | case ABIS_OM_MDISC_FOM: |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 850 | rc = abis_nm_rcvmsg_fom(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 851 | break; |
Harald Welte | 677c21f | 2009-02-17 13:22:23 +0000 | [diff] [blame] | 852 | case ABIS_OM_MDISC_MANUF: |
| 853 | rc = abis_nm_rcvmsg_manuf(msg); |
| 854 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 855 | case ABIS_OM_MDISC_MMI: |
| 856 | case ABIS_OM_MDISC_TRAU: |
Harald Welte | 677c21f | 2009-02-17 13:22:23 +0000 | [diff] [blame] | 857 | fprintf(stderr, "unimplemented ABIS OML message discriminator 0x%x\n", |
| 858 | oh->mdisc); |
| 859 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 860 | default: |
| 861 | fprintf(stderr, "unknown ABIS OML message discriminator 0x%x\n", |
| 862 | oh->mdisc); |
| 863 | return -EINVAL; |
| 864 | } |
| 865 | |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 866 | msgb_free(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 867 | return rc; |
| 868 | } |
| 869 | |
| 870 | #if 0 |
| 871 | /* initialized all resources */ |
| 872 | struct abis_nm_h *abis_nm_init(struct abis_nm_cfg *cfg) |
| 873 | { |
| 874 | struct abis_nm_h *nmh; |
| 875 | |
| 876 | nmh = malloc(sizeof(*nmh)); |
| 877 | if (!nmh) |
| 878 | return NULL; |
| 879 | |
| 880 | nmh->cfg = cfg; |
| 881 | |
| 882 | return nmh; |
| 883 | } |
| 884 | |
| 885 | /* free all resources */ |
| 886 | void abis_nm_fini(struct abis_nm_h *nmh) |
| 887 | { |
| 888 | free(nmh); |
| 889 | } |
| 890 | #endif |
| 891 | |
| 892 | /* Here we are trying to define a high-level API that can be used by |
| 893 | * the actual BSC implementation. However, the architecture is currently |
| 894 | * still under design. Ideally the calls to this API would be synchronous, |
| 895 | * while the underlying stack behind the APi runs in a traditional select |
| 896 | * based state machine. |
| 897 | */ |
| 898 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 899 | /* 6.2 Software Load: */ |
| 900 | enum sw_state { |
| 901 | SW_STATE_NONE, |
| 902 | SW_STATE_WAIT_INITACK, |
| 903 | SW_STATE_WAIT_SEGACK, |
| 904 | SW_STATE_WAIT_ENDACK, |
| 905 | SW_STATE_WAIT_ACTACK, |
| 906 | SW_STATE_ERROR, |
| 907 | }; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 908 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 909 | struct abis_nm_sw { |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 910 | struct gsm_bts *bts; |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 911 | gsm_cbfn *cbfn; |
| 912 | void *cb_data; |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 913 | int forced; |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 914 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 915 | /* this will become part of the SW LOAD INITIATE */ |
| 916 | u_int8_t obj_class; |
| 917 | u_int8_t obj_instance[3]; |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 918 | |
| 919 | u_int8_t file_id[255]; |
| 920 | u_int8_t file_id_len; |
| 921 | |
| 922 | u_int8_t file_version[255]; |
| 923 | u_int8_t file_version_len; |
| 924 | |
| 925 | u_int8_t window_size; |
| 926 | u_int8_t seg_in_window; |
| 927 | |
| 928 | int fd; |
| 929 | FILE *stream; |
| 930 | enum sw_state state; |
Harald Welte | 1602ade | 2009-01-29 21:12:39 +0000 | [diff] [blame] | 931 | int last_seg; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 932 | }; |
| 933 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 934 | static struct abis_nm_sw g_sw; |
| 935 | |
| 936 | /* 6.2.1 / 8.3.1: Load Data Initiate */ |
| 937 | static int sw_load_init(struct abis_nm_sw *sw) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 938 | { |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 939 | struct abis_om_hdr *oh; |
| 940 | struct msgb *msg = nm_msgb_alloc(); |
| 941 | u_int8_t len = 3*2 + sw->file_id_len + sw->file_version_len; |
| 942 | |
| 943 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 944 | fill_om_fom_hdr(oh, len, NM_MT_LOAD_INIT, sw->obj_class, |
| 945 | sw->obj_instance[0], sw->obj_instance[1], |
| 946 | sw->obj_instance[2]); |
| 947 | |
| 948 | /* FIXME: this is BS11 specific format */ |
| 949 | msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id); |
| 950 | msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len, |
| 951 | sw->file_version); |
| 952 | msgb_tv_put(msg, NM_ATT_WINDOW_SIZE, sw->window_size); |
| 953 | |
| 954 | return abis_nm_sendmsg(sw->bts, msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 955 | } |
| 956 | |
Harald Welte | 1602ade | 2009-01-29 21:12:39 +0000 | [diff] [blame] | 957 | static int is_last_line(FILE *stream) |
| 958 | { |
| 959 | char next_seg_buf[256]; |
| 960 | long pos; |
| 961 | |
| 962 | /* check if we're sending the last line */ |
| 963 | pos = ftell(stream); |
| 964 | if (!fgets(next_seg_buf, sizeof(next_seg_buf)-2, stream)) { |
| 965 | fseek(stream, pos, SEEK_SET); |
| 966 | return 1; |
| 967 | } |
| 968 | |
| 969 | fseek(stream, pos, SEEK_SET); |
| 970 | return 0; |
| 971 | } |
| 972 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 973 | /* 6.2.2 / 8.3.2 Load Data Segment */ |
| 974 | static int sw_load_segment(struct abis_nm_sw *sw) |
| 975 | { |
| 976 | struct abis_om_hdr *oh; |
| 977 | struct msgb *msg = nm_msgb_alloc(); |
| 978 | char seg_buf[256]; |
| 979 | char *line_buf = seg_buf+2; |
Harald Welte | 3b8ba21 | 2009-01-29 12:27:58 +0000 | [diff] [blame] | 980 | unsigned char *tlv; |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 981 | u_int8_t len; |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 982 | |
| 983 | 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] | 984 | |
| 985 | switch (sw->bts->type) { |
| 986 | case GSM_BTS_TYPE_BS11: |
| 987 | if (fgets(line_buf, sizeof(seg_buf)-2, sw->stream) == NULL) { |
| 988 | perror("fgets reading segment"); |
| 989 | return -EINVAL; |
| 990 | } |
| 991 | seg_buf[0] = 0x00; |
Harald Welte | 1602ade | 2009-01-29 21:12:39 +0000 | [diff] [blame] | 992 | |
| 993 | /* check if we're sending the last line */ |
| 994 | sw->last_seg = is_last_line(sw->stream); |
| 995 | if (sw->last_seg) |
| 996 | seg_buf[1] = 0; |
| 997 | else |
| 998 | seg_buf[1] = 1 + sw->seg_in_window++; |
Harald Welte | 3b8ba21 | 2009-01-29 12:27:58 +0000 | [diff] [blame] | 999 | |
| 1000 | len = strlen(line_buf) + 2; |
| 1001 | tlv = msgb_put(msg, TLV_GROSS_LEN(len)); |
| 1002 | tlv_put(tlv, NM_ATT_BS11_FILE_DATA, len, (u_int8_t *)seg_buf); |
| 1003 | /* BS11 wants CR + LF in excess of the TLV length !?! */ |
| 1004 | tlv[1] -= 2; |
| 1005 | |
| 1006 | /* we only now know the exact length for the OM hdr */ |
| 1007 | len = strlen(line_buf)+2; |
| 1008 | break; |
| 1009 | default: |
| 1010 | /* FIXME: Other BTS types */ |
| 1011 | return -1; |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1012 | } |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1013 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1014 | fill_om_fom_hdr(oh, len, NM_MT_LOAD_SEG, sw->obj_class, |
| 1015 | sw->obj_instance[0], sw->obj_instance[1], |
| 1016 | sw->obj_instance[2]); |
| 1017 | |
| 1018 | return abis_nm_sendmsg(sw->bts, msg); |
| 1019 | } |
| 1020 | |
| 1021 | /* 6.2.4 / 8.3.4 Load Data End */ |
| 1022 | static int sw_load_end(struct abis_nm_sw *sw) |
| 1023 | { |
| 1024 | struct abis_om_hdr *oh; |
| 1025 | struct msgb *msg = nm_msgb_alloc(); |
| 1026 | u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len; |
| 1027 | |
| 1028 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1029 | fill_om_fom_hdr(oh, len, NM_MT_LOAD_END, sw->obj_class, |
| 1030 | sw->obj_instance[0], sw->obj_instance[1], |
| 1031 | sw->obj_instance[2]); |
| 1032 | |
| 1033 | /* FIXME: this is BS11 specific format */ |
| 1034 | msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id); |
| 1035 | msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len, |
| 1036 | sw->file_version); |
| 1037 | |
| 1038 | return abis_nm_sendmsg(sw->bts, msg); |
| 1039 | } |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1040 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1041 | /* Activate the specified software into the BTS */ |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1042 | static int sw_activate(struct abis_nm_sw *sw) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1043 | { |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1044 | struct abis_om_hdr *oh; |
| 1045 | struct msgb *msg = nm_msgb_alloc(); |
| 1046 | 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] | 1047 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1048 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1049 | fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, sw->obj_class, |
| 1050 | sw->obj_instance[0], sw->obj_instance[1], |
| 1051 | sw->obj_instance[2]); |
| 1052 | |
| 1053 | /* FIXME: this is BS11 specific format */ |
| 1054 | msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id); |
| 1055 | msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len, |
| 1056 | sw->file_version); |
| 1057 | |
| 1058 | return abis_nm_sendmsg(sw->bts, msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1059 | } |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1060 | |
| 1061 | static int sw_open_file(struct abis_nm_sw *sw, const char *fname) |
| 1062 | { |
| 1063 | char file_id[12+1]; |
| 1064 | char file_version[80+1]; |
| 1065 | int rc; |
| 1066 | |
| 1067 | sw->fd = open(fname, O_RDONLY); |
| 1068 | if (sw->fd < 0) |
| 1069 | return sw->fd; |
| 1070 | |
| 1071 | switch (sw->bts->type) { |
| 1072 | case GSM_BTS_TYPE_BS11: |
| 1073 | sw->stream = fdopen(sw->fd, "r"); |
| 1074 | if (!sw->stream) { |
| 1075 | perror("fdopen"); |
| 1076 | return -1; |
| 1077 | } |
| 1078 | /* read first line and parse file ID and VERSION */ |
Harald Welte | 3b8ba21 | 2009-01-29 12:27:58 +0000 | [diff] [blame] | 1079 | rc = fscanf(sw->stream, "@(#)%12s:%80s\r\n", |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1080 | file_id, file_version); |
| 1081 | if (rc != 2) { |
| 1082 | perror("parsing header line of software file"); |
| 1083 | return -1; |
| 1084 | } |
| 1085 | strcpy((char *)sw->file_id, file_id); |
| 1086 | sw->file_id_len = strlen(file_id); |
| 1087 | strcpy((char *)sw->file_version, file_version); |
| 1088 | sw->file_version_len = strlen(file_version); |
| 1089 | /* rewind to start of file */ |
Harald Welte | 3b8ba21 | 2009-01-29 12:27:58 +0000 | [diff] [blame] | 1090 | rewind(sw->stream); |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1091 | break; |
| 1092 | default: |
| 1093 | /* We don't know how to treat them yet */ |
| 1094 | close(sw->fd); |
| 1095 | return -EINVAL; |
| 1096 | } |
| 1097 | |
| 1098 | return 0; |
| 1099 | } |
| 1100 | |
| 1101 | static void sw_close_file(struct abis_nm_sw *sw) |
| 1102 | { |
| 1103 | switch (sw->bts->type) { |
| 1104 | case GSM_BTS_TYPE_BS11: |
| 1105 | fclose(sw->stream); |
| 1106 | break; |
| 1107 | default: |
| 1108 | close(sw->fd); |
| 1109 | break; |
| 1110 | } |
| 1111 | } |
| 1112 | |
| 1113 | /* Fill the window */ |
| 1114 | static int sw_fill_window(struct abis_nm_sw *sw) |
| 1115 | { |
| 1116 | int rc; |
| 1117 | |
| 1118 | while (sw->seg_in_window < sw->window_size) { |
| 1119 | rc = sw_load_segment(sw); |
| 1120 | if (rc < 0) |
| 1121 | return rc; |
Harald Welte | 1602ade | 2009-01-29 21:12:39 +0000 | [diff] [blame] | 1122 | if (sw->last_seg) |
| 1123 | break; |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1124 | } |
| 1125 | return 0; |
| 1126 | } |
| 1127 | |
| 1128 | /* callback function from abis_nm_rcvmsg() handler */ |
| 1129 | static int abis_nm_rcvmsg_sw(struct msgb *mb) |
| 1130 | { |
| 1131 | struct abis_om_fom_hdr *foh = msgb_l3(mb); |
| 1132 | int rc = -1; |
| 1133 | struct abis_nm_sw *sw = &g_sw; |
| 1134 | enum sw_state old_state = sw->state; |
| 1135 | |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 1136 | //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] | 1137 | |
| 1138 | switch (sw->state) { |
| 1139 | case SW_STATE_WAIT_INITACK: |
| 1140 | switch (foh->msg_type) { |
| 1141 | case NM_MT_LOAD_INIT_ACK: |
| 1142 | /* fill window with segments */ |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1143 | if (sw->cbfn) |
| 1144 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 1145 | NM_MT_LOAD_INIT_ACK, mb, |
| 1146 | sw->cb_data, NULL); |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1147 | rc = sw_fill_window(sw); |
| 1148 | sw->state = SW_STATE_WAIT_SEGACK; |
| 1149 | break; |
| 1150 | case NM_MT_LOAD_INIT_NACK: |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 1151 | if (sw->forced) { |
| 1152 | DEBUGP(DNM, "FORCED: Ignoring Software Load " |
| 1153 | "Init NACK\n"); |
| 1154 | if (sw->cbfn) |
| 1155 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 1156 | NM_MT_LOAD_INIT_ACK, mb, |
| 1157 | sw->cb_data, NULL); |
| 1158 | rc = sw_fill_window(sw); |
| 1159 | sw->state = SW_STATE_WAIT_SEGACK; |
| 1160 | } else { |
| 1161 | DEBUGP(DNM, "Software Load Init NACK\n"); |
Harald Welte | 6c96ba5 | 2009-05-01 13:03:40 +0000 | [diff] [blame] | 1162 | /* FIXME: cause */ |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 1163 | if (sw->cbfn) |
| 1164 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 1165 | NM_MT_LOAD_INIT_NACK, mb, |
| 1166 | sw->cb_data, NULL); |
| 1167 | sw->state = SW_STATE_ERROR; |
| 1168 | } |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1169 | break; |
| 1170 | } |
| 1171 | break; |
| 1172 | case SW_STATE_WAIT_SEGACK: |
| 1173 | switch (foh->msg_type) { |
| 1174 | case NM_MT_LOAD_SEG_ACK: |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 1175 | if (sw->cbfn) |
| 1176 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 1177 | NM_MT_LOAD_SEG_ACK, mb, |
| 1178 | sw->cb_data, NULL); |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1179 | sw->seg_in_window = 0; |
Harald Welte | 1602ade | 2009-01-29 21:12:39 +0000 | [diff] [blame] | 1180 | if (!sw->last_seg) { |
| 1181 | /* fill window with more segments */ |
| 1182 | rc = sw_fill_window(sw); |
| 1183 | sw->state = SW_STATE_WAIT_SEGACK; |
| 1184 | } else { |
| 1185 | /* end the transfer */ |
| 1186 | sw->state = SW_STATE_WAIT_ENDACK; |
| 1187 | rc = sw_load_end(sw); |
| 1188 | } |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1189 | break; |
| 1190 | } |
| 1191 | break; |
| 1192 | case SW_STATE_WAIT_ENDACK: |
| 1193 | switch (foh->msg_type) { |
| 1194 | case NM_MT_LOAD_END_ACK: |
| 1195 | sw_close_file(sw); |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1196 | DEBUGP(DNM, "Software Load End (BTS %u)\n", |
| 1197 | sw->bts->nr); |
| 1198 | sw->state = SW_STATE_NONE; |
| 1199 | if (sw->cbfn) |
| 1200 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 1201 | NM_MT_LOAD_END_ACK, mb, |
| 1202 | sw->cb_data, NULL); |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1203 | break; |
| 1204 | case NM_MT_LOAD_END_NACK: |
Holger Freyther | 31338a1 | 2009-02-06 17:43:50 +0000 | [diff] [blame] | 1205 | if (sw->forced) { |
| 1206 | DEBUGP(DNM, "FORCED: Ignoring Software Load" |
| 1207 | "End NACK\n"); |
| 1208 | sw->state = SW_STATE_NONE; |
| 1209 | if (sw->cbfn) |
| 1210 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 1211 | NM_MT_LOAD_END_ACK, mb, |
| 1212 | sw->cb_data, NULL); |
| 1213 | } else { |
| 1214 | DEBUGP(DNM, "Software Load End NACK\n"); |
Harald Welte | 6c96ba5 | 2009-05-01 13:03:40 +0000 | [diff] [blame] | 1215 | /* FIXME: cause */ |
Holger Freyther | 31338a1 | 2009-02-06 17:43:50 +0000 | [diff] [blame] | 1216 | sw->state = SW_STATE_ERROR; |
| 1217 | if (sw->cbfn) |
| 1218 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 1219 | NM_MT_LOAD_END_NACK, mb, |
| 1220 | sw->cb_data, NULL); |
| 1221 | } |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1222 | break; |
| 1223 | } |
| 1224 | case SW_STATE_WAIT_ACTACK: |
| 1225 | switch (foh->msg_type) { |
| 1226 | case NM_MT_ACTIVATE_SW_ACK: |
| 1227 | /* we're done */ |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1228 | DEBUGP(DNM, "Activate Software DONE!\n"); |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1229 | sw->state = SW_STATE_NONE; |
| 1230 | rc = 0; |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1231 | if (sw->cbfn) |
| 1232 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 1233 | NM_MT_ACTIVATE_SW_ACK, mb, |
| 1234 | sw->cb_data, NULL); |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1235 | break; |
| 1236 | case NM_MT_ACTIVATE_SW_NACK: |
Harald Welte | 1602ade | 2009-01-29 21:12:39 +0000 | [diff] [blame] | 1237 | DEBUGP(DNM, "Activate Software NACK\n"); |
Harald Welte | 6c96ba5 | 2009-05-01 13:03:40 +0000 | [diff] [blame] | 1238 | /* FIXME: cause */ |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1239 | sw->state = SW_STATE_ERROR; |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1240 | if (sw->cbfn) |
| 1241 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 1242 | NM_MT_ACTIVATE_SW_NACK, mb, |
| 1243 | sw->cb_data, NULL); |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1244 | break; |
| 1245 | } |
| 1246 | case SW_STATE_NONE: |
| 1247 | case SW_STATE_ERROR: |
| 1248 | break; |
| 1249 | } |
| 1250 | |
| 1251 | if (rc) |
| 1252 | fprintf(stderr, "unexpected NM MT 0x%02x in state %u -> %u\n", |
| 1253 | foh->msg_type, old_state, sw->state); |
| 1254 | |
| 1255 | return rc; |
| 1256 | } |
| 1257 | |
| 1258 | /* Load the specified software into the BTS */ |
| 1259 | int abis_nm_software_load(struct gsm_bts *bts, const char *fname, |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 1260 | u_int8_t win_size, int forced, |
| 1261 | gsm_cbfn *cbfn, void *cb_data) |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1262 | { |
| 1263 | struct abis_nm_sw *sw = &g_sw; |
| 1264 | int rc; |
| 1265 | |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1266 | DEBUGP(DNM, "Software Load (BTS %u, File \"%s\")\n", |
| 1267 | bts->nr, fname); |
| 1268 | |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1269 | if (sw->state != SW_STATE_NONE) |
| 1270 | return -EBUSY; |
| 1271 | |
| 1272 | sw->bts = bts; |
| 1273 | sw->obj_class = NM_OC_SITE_MANAGER; |
| 1274 | sw->obj_instance[0] = 0xff; |
| 1275 | sw->obj_instance[1] = 0xff; |
| 1276 | sw->obj_instance[2] = 0xff; |
| 1277 | sw->window_size = win_size; |
| 1278 | sw->state = SW_STATE_WAIT_INITACK; |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1279 | sw->cbfn = cbfn; |
| 1280 | sw->cb_data = cb_data; |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 1281 | sw->forced = forced; |
Harald Welte | 4724f99 | 2009-01-18 18:01:49 +0000 | [diff] [blame] | 1282 | |
| 1283 | rc = sw_open_file(sw, fname); |
| 1284 | if (rc < 0) { |
| 1285 | sw->state = SW_STATE_NONE; |
| 1286 | return rc; |
| 1287 | } |
| 1288 | |
| 1289 | return sw_load_init(sw); |
| 1290 | } |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1291 | |
Harald Welte | 1602ade | 2009-01-29 21:12:39 +0000 | [diff] [blame] | 1292 | int abis_nm_software_load_status(struct gsm_bts *bts) |
| 1293 | { |
| 1294 | struct abis_nm_sw *sw = &g_sw; |
| 1295 | struct stat st; |
| 1296 | int rc, percent; |
| 1297 | |
| 1298 | rc = fstat(sw->fd, &st); |
| 1299 | if (rc < 0) { |
| 1300 | perror("ERROR during stat"); |
| 1301 | return rc; |
| 1302 | } |
| 1303 | |
| 1304 | percent = (ftell(sw->stream) * 100) / st.st_size; |
| 1305 | return percent; |
| 1306 | } |
| 1307 | |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1308 | /* Activate the specified software into the BTS */ |
| 1309 | int abis_nm_software_activate(struct gsm_bts *bts, const char *fname, |
| 1310 | gsm_cbfn *cbfn, void *cb_data) |
| 1311 | { |
| 1312 | struct abis_nm_sw *sw = &g_sw; |
| 1313 | int rc; |
| 1314 | |
| 1315 | DEBUGP(DNM, "Activating Software (BTS %u, File \"%s\")\n", |
| 1316 | bts->nr, fname); |
| 1317 | |
| 1318 | if (sw->state != SW_STATE_NONE) |
| 1319 | return -EBUSY; |
| 1320 | |
| 1321 | sw->bts = bts; |
| 1322 | sw->obj_class = NM_OC_SITE_MANAGER; |
| 1323 | sw->obj_instance[0] = 0xff; |
| 1324 | sw->obj_instance[1] = 0xff; |
| 1325 | sw->obj_instance[2] = 0xff; |
| 1326 | sw->state = SW_STATE_WAIT_ACTACK; |
| 1327 | sw->cbfn = cbfn; |
| 1328 | sw->cb_data = cb_data; |
| 1329 | |
| 1330 | /* Open the file in order to fill some sw struct members */ |
| 1331 | rc = sw_open_file(sw, fname); |
| 1332 | if (rc < 0) { |
| 1333 | sw->state = SW_STATE_NONE; |
| 1334 | return rc; |
| 1335 | } |
| 1336 | sw_close_file(sw); |
| 1337 | |
| 1338 | return sw_activate(sw); |
| 1339 | } |
| 1340 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1341 | 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] | 1342 | u_int8_t ts_nr, u_int8_t subslot_nr) |
| 1343 | { |
Harald Welte | adaf08b | 2009-01-18 11:08:10 +0000 | [diff] [blame] | 1344 | ch->attrib = NM_ATT_ABIS_CHANNEL; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1345 | ch->bts_port = bts_port; |
| 1346 | ch->timeslot = ts_nr; |
| 1347 | ch->subslot = subslot_nr; |
| 1348 | } |
| 1349 | |
| 1350 | int abis_nm_establish_tei(struct gsm_bts *bts, u_int8_t trx_nr, |
| 1351 | u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot, |
| 1352 | u_int8_t tei) |
| 1353 | { |
| 1354 | struct abis_om_hdr *oh; |
| 1355 | struct abis_nm_channel *ch; |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 1356 | u_int8_t len = sizeof(*ch) + 2; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1357 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1358 | |
| 1359 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1360 | fill_om_fom_hdr(oh, len, NM_MT_ESTABLISH_TEI, NM_OC_RADIO_CARRIER, |
| 1361 | bts->bts_nr, trx_nr, 0xff); |
| 1362 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1363 | msgb_tv_put(msg, NM_ATT_TEI, tei); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1364 | |
| 1365 | ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch)); |
| 1366 | fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot); |
| 1367 | |
| 1368 | return abis_nm_sendmsg(bts, msg); |
| 1369 | } |
| 1370 | |
| 1371 | /* connect signalling of one (BTS,TRX) to a particular timeslot on the E1 */ |
| 1372 | int abis_nm_conn_terr_sign(struct gsm_bts_trx *trx, |
| 1373 | u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot) |
| 1374 | { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1375 | struct gsm_bts *bts = trx->bts; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1376 | struct abis_om_hdr *oh; |
| 1377 | struct abis_nm_channel *ch; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1378 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1379 | |
| 1380 | 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] | 1381 | fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_SIGN, |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1382 | NM_OC_RADIO_CARRIER, bts->bts_nr, trx->nr, 0xff); |
| 1383 | |
| 1384 | ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch)); |
| 1385 | fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot); |
| 1386 | |
| 1387 | return abis_nm_sendmsg(bts, msg); |
| 1388 | } |
| 1389 | |
| 1390 | #if 0 |
| 1391 | int abis_nm_disc_terr_sign(struct abis_nm_h *h, struct abis_om_obj_inst *inst, |
| 1392 | struct abis_nm_abis_channel *chan) |
| 1393 | { |
| 1394 | } |
| 1395 | #endif |
| 1396 | |
| 1397 | int abis_nm_conn_terr_traf(struct gsm_bts_trx_ts *ts, |
| 1398 | u_int8_t e1_port, u_int8_t e1_timeslot, |
| 1399 | u_int8_t e1_subslot) |
| 1400 | { |
| 1401 | struct gsm_bts *bts = ts->trx->bts; |
| 1402 | struct abis_om_hdr *oh; |
| 1403 | struct abis_nm_channel *ch; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1404 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1405 | |
| 1406 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1407 | fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_TRAF, |
Harald Welte | b110cee | 2009-02-18 03:42:35 +0000 | [diff] [blame] | 1408 | NM_OC_CHANNEL, bts->bts_nr, ts->trx->nr, ts->nr); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1409 | |
| 1410 | ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch)); |
| 1411 | fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot); |
| 1412 | |
Harald Welte | f325eb4 | 2009-02-19 17:07:39 +0000 | [diff] [blame] | 1413 | DEBUGP(DNM, "CONNECT TERR TRAF Um=%s E1=(%u,%u,%u)\n", |
| 1414 | gsm_ts_name(ts), |
Harald Welte | b110cee | 2009-02-18 03:42:35 +0000 | [diff] [blame] | 1415 | e1_port, e1_timeslot, e1_subslot); |
| 1416 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1417 | return abis_nm_sendmsg(bts, msg); |
| 1418 | } |
| 1419 | |
| 1420 | #if 0 |
| 1421 | int abis_nm_disc_terr_traf(struct abis_nm_h *h, struct abis_om_obj_inst *inst, |
| 1422 | struct abis_nm_abis_channel *chan, |
| 1423 | u_int8_t subchan) |
| 1424 | { |
| 1425 | } |
| 1426 | #endif |
| 1427 | |
Harald Welte | 22af0db | 2009-02-14 15:41:08 +0000 | [diff] [blame] | 1428 | /* Chapter 8.6.1 */ |
| 1429 | int abis_nm_set_bts_attr(struct gsm_bts *bts, u_int8_t *attr, int attr_len) |
| 1430 | { |
| 1431 | struct abis_om_hdr *oh; |
| 1432 | struct msgb *msg = nm_msgb_alloc(); |
| 1433 | u_int8_t *cur; |
| 1434 | |
| 1435 | DEBUGP(DNM, "Set BTS Attr (bts=%d)\n", bts->nr); |
| 1436 | |
| 1437 | 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^] | 1438 | 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] | 1439 | cur = msgb_put(msg, attr_len); |
| 1440 | memcpy(cur, attr, attr_len); |
| 1441 | |
| 1442 | return abis_nm_sendmsg(bts, msg); |
| 1443 | } |
| 1444 | |
| 1445 | /* Chapter 8.6.2 */ |
| 1446 | int abis_nm_set_radio_attr(struct gsm_bts_trx *trx, u_int8_t *attr, int attr_len) |
| 1447 | { |
| 1448 | struct abis_om_hdr *oh; |
| 1449 | struct msgb *msg = nm_msgb_alloc(); |
| 1450 | u_int8_t *cur; |
| 1451 | |
| 1452 | DEBUGP(DNM, "Set TRX Attr (bts=%d,trx=%d)\n", trx->bts->nr, trx->nr); |
| 1453 | |
| 1454 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1455 | 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^] | 1456 | trx->bts->bts_nr, trx->nr, 0xff); |
Harald Welte | 22af0db | 2009-02-14 15:41:08 +0000 | [diff] [blame] | 1457 | cur = msgb_put(msg, attr_len); |
| 1458 | memcpy(cur, attr, attr_len); |
| 1459 | |
| 1460 | return abis_nm_sendmsg(trx->bts, msg); |
| 1461 | } |
| 1462 | |
| 1463 | /* Chapter 8.6.3 */ |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1464 | int abis_nm_set_channel_attr(struct gsm_bts_trx_ts *ts, u_int8_t chan_comb) |
| 1465 | { |
| 1466 | struct gsm_bts *bts = ts->trx->bts; |
| 1467 | struct abis_om_hdr *oh; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1468 | u_int16_t arfcn = htons(ts->trx->arfcn); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1469 | u_int8_t zero = 0x00; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1470 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 1471 | u_int8_t len = 2 + 2; |
| 1472 | |
| 1473 | if (bts->type == GSM_BTS_TYPE_BS11) |
| 1474 | len += 4 + 2 + 2 + 3; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1475 | |
Harald Welte | f325eb4 | 2009-02-19 17:07:39 +0000 | [diff] [blame] | 1476 | DEBUGP(DNM, "Set Chan Attr %s\n", gsm_ts_name(ts)); |
Harald Welte | 22af0db | 2009-02-14 15:41:08 +0000 | [diff] [blame] | 1477 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1478 | 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] | 1479 | fill_om_fom_hdr(oh, len, NM_MT_SET_CHAN_ATTR, |
Holger Freyther | 6b2d262 | 2009-02-14 23:16:59 +0000 | [diff] [blame] | 1480 | NM_OC_CHANNEL, bts->bts_nr, |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1481 | ts->trx->nr, ts->nr); |
| 1482 | /* FIXME: don't send ARFCN list, hopping sequence, mAIO, ...*/ |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 1483 | if (bts->type == GSM_BTS_TYPE_BS11) |
| 1484 | msgb_tlv16_put(msg, NM_ATT_ARFCN_LIST, 1, &arfcn); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1485 | msgb_tv_put(msg, NM_ATT_CHAN_COMB, chan_comb); |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 1486 | if (bts->type == GSM_BTS_TYPE_BS11) { |
| 1487 | msgb_tv_put(msg, NM_ATT_HSN, 0x00); |
| 1488 | msgb_tv_put(msg, NM_ATT_MAIO, 0x00); |
| 1489 | } |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1490 | msgb_tv_put(msg, NM_ATT_TSC, 0x07); /* training sequence */ |
Harald Welte | e0590df | 2009-02-15 03:34:15 +0000 | [diff] [blame] | 1491 | if (bts->type == GSM_BTS_TYPE_BS11) |
| 1492 | msgb_tlv_put(msg, 0x59, 1, &zero); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1493 | |
| 1494 | return abis_nm_sendmsg(bts, msg); |
| 1495 | } |
| 1496 | |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 1497 | 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] | 1498 | 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] | 1499 | { |
| 1500 | struct abis_om_hdr *oh; |
| 1501 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 5c1e458 | 2009-02-15 11:57:29 +0000 | [diff] [blame] | 1502 | u_int8_t msgtype = NM_MT_SW_ACT_REQ_ACK; |
| 1503 | u_int8_t len = att_len; |
| 1504 | |
| 1505 | if (nack) { |
| 1506 | len += 2; |
| 1507 | msgtype = NM_MT_SW_ACT_REQ_NACK; |
| 1508 | } |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 1509 | |
| 1510 | 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] | 1511 | fill_om_fom_hdr(oh, att_len, msgtype, obj_class, i1, i2, i3); |
| 1512 | |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 1513 | if (attr) { |
| 1514 | u_int8_t *ptr = msgb_put(msg, att_len); |
| 1515 | memcpy(ptr, attr, att_len); |
| 1516 | } |
Harald Welte | 5c1e458 | 2009-02-15 11:57:29 +0000 | [diff] [blame] | 1517 | if (nack) |
| 1518 | msgb_tv_put(msg, NM_ATT_NACK_CAUSES, NM_NACK_OBJCLASS_NOTSUPP); |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 1519 | |
| 1520 | return abis_nm_sendmsg(bts, msg); |
| 1521 | } |
| 1522 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1523 | 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] | 1524 | { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1525 | struct msgb *msg = nm_msgb_alloc(); |
| 1526 | struct abis_om_hdr *oh; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1527 | u_int8_t *data; |
| 1528 | |
| 1529 | oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh)); |
| 1530 | fill_om_hdr(oh, len); |
| 1531 | data = msgb_put(msg, len); |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 1532 | memcpy(data, rawmsg, len); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1533 | |
| 1534 | return abis_nm_sendmsg(bts, msg); |
| 1535 | } |
| 1536 | |
| 1537 | /* Siemens specific commands */ |
| 1538 | static int __simple_cmd(struct gsm_bts *bts, u_int8_t msg_type) |
| 1539 | { |
| 1540 | struct abis_om_hdr *oh; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1541 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1542 | |
| 1543 | 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] | 1544 | fill_om_fom_hdr(oh, 0, msg_type, NM_OC_SITE_MANAGER, |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1545 | 0xff, 0xff, 0xff); |
| 1546 | |
| 1547 | return abis_nm_sendmsg(bts, msg); |
| 1548 | } |
| 1549 | |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 1550 | /* Chapter 8.9.2 */ |
| 1551 | 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) |
| 1552 | { |
| 1553 | struct abis_om_hdr *oh; |
| 1554 | struct msgb *msg = nm_msgb_alloc(); |
| 1555 | |
Harald Welte | 22af0db | 2009-02-14 15:41:08 +0000 | [diff] [blame] | 1556 | DEBUGP(DNM, "Sending OPSTART obj_class=0x%02x obj_inst=(0x%02x, 0x%02x, 0x%02x)\n", |
| 1557 | obj_class, i0, i1, i2); |
Harald Welte | 34a9968 | 2009-02-13 02:41:40 +0000 | [diff] [blame] | 1558 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1559 | fill_om_fom_hdr(oh, 0, NM_MT_OPSTART, obj_class, i0, i1, i2); |
| 1560 | |
| 1561 | return abis_nm_sendmsg(bts, msg); |
| 1562 | } |
| 1563 | |
| 1564 | /* Chapter 8.8.5 */ |
| 1565 | int abis_nm_chg_adm_state(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, |
| 1566 | u_int8_t i1, u_int8_t i2, u_int8_t adm_state) |
| 1567 | { |
| 1568 | struct abis_om_hdr *oh; |
| 1569 | struct msgb *msg = nm_msgb_alloc(); |
| 1570 | |
| 1571 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1572 | fill_om_fom_hdr(oh, 2, NM_MT_CHG_ADM_STATE, obj_class, i0, i1, i2); |
| 1573 | msgb_tv_put(msg, NM_ATT_ADM_STATE, adm_state); |
| 1574 | |
| 1575 | return abis_nm_sendmsg(bts, msg); |
| 1576 | } |
| 1577 | |
| 1578 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1579 | int abis_nm_event_reports(struct gsm_bts *bts, int on) |
| 1580 | { |
| 1581 | if (on == 0) |
Harald Welte | 227d407 | 2009-01-03 08:16:25 +0000 | [diff] [blame] | 1582 | return __simple_cmd(bts, NM_MT_STOP_EVENT_REP); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1583 | else |
Harald Welte | 227d407 | 2009-01-03 08:16:25 +0000 | [diff] [blame] | 1584 | return __simple_cmd(bts, NM_MT_REST_EVENT_REP); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1585 | } |
| 1586 | |
Harald Welte | 47d88ae | 2009-01-04 12:02:08 +0000 | [diff] [blame] | 1587 | /* Siemens (or BS-11) specific commands */ |
| 1588 | |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 1589 | int abis_nm_bs11_bsc_disconnect(struct gsm_bts *bts, int reconnect) |
| 1590 | { |
| 1591 | if (reconnect == 0) |
| 1592 | return __simple_cmd(bts, NM_MT_BS11_DISCONNECT); |
| 1593 | else |
| 1594 | return __simple_cmd(bts, NM_MT_BS11_RECONNECT); |
| 1595 | } |
| 1596 | |
Harald Welte | b842797 | 2009-02-05 19:27:17 +0000 | [diff] [blame] | 1597 | int abis_nm_bs11_restart(struct gsm_bts *bts) |
| 1598 | { |
| 1599 | return __simple_cmd(bts, NM_MT_BS11_RESTART); |
| 1600 | } |
| 1601 | |
| 1602 | |
Harald Welte | 268bb40 | 2009-02-01 19:11:56 +0000 | [diff] [blame] | 1603 | struct bs11_date_time { |
| 1604 | u_int16_t year; |
| 1605 | u_int8_t month; |
| 1606 | u_int8_t day; |
| 1607 | u_int8_t hour; |
| 1608 | u_int8_t min; |
| 1609 | u_int8_t sec; |
| 1610 | } __attribute__((packed)); |
| 1611 | |
| 1612 | |
| 1613 | void get_bs11_date_time(struct bs11_date_time *aet) |
| 1614 | { |
| 1615 | time_t t; |
| 1616 | struct tm *tm; |
| 1617 | |
| 1618 | t = time(NULL); |
| 1619 | tm = localtime(&t); |
| 1620 | aet->sec = tm->tm_sec; |
| 1621 | aet->min = tm->tm_min; |
| 1622 | aet->hour = tm->tm_hour; |
| 1623 | aet->day = tm->tm_mday; |
| 1624 | aet->month = tm->tm_mon; |
| 1625 | aet->year = htons(1900 + tm->tm_year); |
| 1626 | } |
| 1627 | |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1628 | int abis_nm_bs11_reset_resource(struct gsm_bts *bts) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1629 | { |
Harald Welte | 4668fda | 2009-01-03 08:19:29 +0000 | [diff] [blame] | 1630 | return __simple_cmd(bts, NM_MT_BS11_RESET_RESOURCE); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1631 | } |
| 1632 | |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1633 | int abis_nm_bs11_db_transmission(struct gsm_bts *bts, int begin) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1634 | { |
| 1635 | if (begin) |
Harald Welte | 4668fda | 2009-01-03 08:19:29 +0000 | [diff] [blame] | 1636 | return __simple_cmd(bts, NM_MT_BS11_BEGIN_DB_TX); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1637 | else |
Harald Welte | 4668fda | 2009-01-03 08:19:29 +0000 | [diff] [blame] | 1638 | return __simple_cmd(bts, NM_MT_BS11_END_DB_TX); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1639 | } |
Harald Welte | 47d88ae | 2009-01-04 12:02:08 +0000 | [diff] [blame] | 1640 | |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1641 | int abis_nm_bs11_create_object(struct gsm_bts *bts, |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1642 | enum abis_bs11_objtype type, u_int8_t idx, |
| 1643 | u_int8_t attr_len, const u_int8_t *attr) |
Harald Welte | 47d88ae | 2009-01-04 12:02:08 +0000 | [diff] [blame] | 1644 | { |
| 1645 | struct abis_om_hdr *oh; |
| 1646 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1647 | u_int8_t *cur; |
Harald Welte | 47d88ae | 2009-01-04 12:02:08 +0000 | [diff] [blame] | 1648 | |
| 1649 | 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] | 1650 | fill_om_fom_hdr(oh, attr_len, NM_MT_BS11_CREATE_OBJ, |
Harald Welte | 268bb40 | 2009-02-01 19:11:56 +0000 | [diff] [blame] | 1651 | NM_OC_BS11, type, 0, idx); |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1652 | cur = msgb_put(msg, attr_len); |
| 1653 | memcpy(cur, attr, attr_len); |
Harald Welte | 47d88ae | 2009-01-04 12:02:08 +0000 | [diff] [blame] | 1654 | |
| 1655 | return abis_nm_sendmsg(bts, msg); |
| 1656 | } |
| 1657 | |
Harald Welte | 78fc0d4 | 2009-02-19 02:50:57 +0000 | [diff] [blame] | 1658 | int abis_nm_bs11_delete_object(struct gsm_bts *bts, |
| 1659 | enum abis_bs11_objtype type, u_int8_t idx) |
| 1660 | { |
| 1661 | struct abis_om_hdr *oh; |
| 1662 | struct msgb *msg = nm_msgb_alloc(); |
| 1663 | |
| 1664 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1665 | fill_om_fom_hdr(oh, 0, NM_MT_BS11_DELETE_OBJ, |
| 1666 | NM_OC_BS11, type, 0, idx); |
| 1667 | |
| 1668 | return abis_nm_sendmsg(bts, msg); |
| 1669 | } |
| 1670 | |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1671 | 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] | 1672 | { |
| 1673 | struct abis_om_hdr *oh; |
| 1674 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1675 | u_int8_t zero = 0x00; |
Harald Welte | 47d88ae | 2009-01-04 12:02:08 +0000 | [diff] [blame] | 1676 | |
| 1677 | 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] | 1678 | fill_om_fom_hdr(oh, 3, NM_MT_BS11_CREATE_OBJ, |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1679 | NM_OC_BS11_ENVABTSE, 0, idx, 0xff); |
| 1680 | msgb_tlv_put(msg, 0x99, 1, &zero); |
Harald Welte | 47d88ae | 2009-01-04 12:02:08 +0000 | [diff] [blame] | 1681 | |
| 1682 | return abis_nm_sendmsg(bts, msg); |
| 1683 | } |
| 1684 | |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1685 | 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] | 1686 | { |
| 1687 | struct abis_om_hdr *oh; |
| 1688 | struct msgb *msg = nm_msgb_alloc(); |
| 1689 | |
| 1690 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1691 | fill_om_fom_hdr(oh, 0, NM_MT_BS11_CREATE_OBJ, NM_OC_BS11_BPORT, |
| 1692 | idx, 0, 0); |
| 1693 | |
| 1694 | return abis_nm_sendmsg(bts, msg); |
| 1695 | } |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1696 | |
Harald Welte | 78fc0d4 | 2009-02-19 02:50:57 +0000 | [diff] [blame] | 1697 | static const u_int8_t sm_attr[] = { NM_ATT_TEI, NM_ATT_ABIS_CHANNEL }; |
| 1698 | int abis_nm_bs11_get_oml_tei_ts(struct gsm_bts *bts) |
| 1699 | { |
| 1700 | struct abis_om_hdr *oh; |
| 1701 | struct msgb *msg = nm_msgb_alloc(); |
| 1702 | |
| 1703 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1704 | fill_om_fom_hdr(oh, 2+sizeof(sm_attr), NM_MT_GET_ATTR, NM_OC_SITE_MANAGER, |
| 1705 | 0xff, 0xff, 0xff); |
| 1706 | msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(sm_attr), sm_attr); |
| 1707 | |
| 1708 | return abis_nm_sendmsg(bts, msg); |
| 1709 | } |
| 1710 | |
Harald Welte | b6c92ae | 2009-02-21 20:15:32 +0000 | [diff] [blame] | 1711 | /* like abis_nm_conn_terr_traf + set_tei */ |
| 1712 | int abis_nm_bs11_conn_oml_tei(struct gsm_bts *bts, u_int8_t e1_port, |
| 1713 | u_int8_t e1_timeslot, u_int8_t e1_subslot, |
| 1714 | u_int8_t tei) |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1715 | { |
| 1716 | struct abis_om_hdr *oh; |
| 1717 | struct abis_nm_channel *ch; |
| 1718 | struct msgb *msg = nm_msgb_alloc(); |
| 1719 | |
| 1720 | 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] | 1721 | 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] | 1722 | NM_OC_SITE_MANAGER, 0xff, 0xff, 0xff); |
| 1723 | |
| 1724 | ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch)); |
| 1725 | fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot); |
Harald Welte | b6c92ae | 2009-02-21 20:15:32 +0000 | [diff] [blame] | 1726 | msgb_tv_put(msg, NM_ATT_TEI, tei); |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1727 | |
| 1728 | return abis_nm_sendmsg(bts, msg); |
| 1729 | } |
| 1730 | |
| 1731 | int abis_nm_bs11_set_trx_power(struct gsm_bts_trx *trx, u_int8_t level) |
| 1732 | { |
| 1733 | struct abis_om_hdr *oh; |
| 1734 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1735 | |
| 1736 | 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] | 1737 | fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR, |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1738 | NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr); |
| 1739 | msgb_tlv_put(msg, NM_ATT_BS11_TXPWR, 1, &level); |
| 1740 | |
| 1741 | return abis_nm_sendmsg(trx->bts, msg); |
| 1742 | } |
| 1743 | |
Harald Welte | 78fc0d4 | 2009-02-19 02:50:57 +0000 | [diff] [blame] | 1744 | int abis_nm_bs11_get_trx_power(struct gsm_bts_trx *trx) |
| 1745 | { |
| 1746 | struct abis_om_hdr *oh; |
| 1747 | struct msgb *msg = nm_msgb_alloc(); |
| 1748 | u_int8_t attr = NM_ATT_BS11_TXPWR; |
| 1749 | |
| 1750 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1751 | fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR, |
| 1752 | NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr); |
| 1753 | msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), &attr); |
| 1754 | |
| 1755 | return abis_nm_sendmsg(trx->bts, msg); |
| 1756 | } |
| 1757 | |
Harald Welte | aaf02d9 | 2009-04-29 13:25:57 +0000 | [diff] [blame] | 1758 | int abis_nm_bs11_get_pll_mode(struct gsm_bts *bts) |
| 1759 | { |
| 1760 | struct abis_om_hdr *oh; |
| 1761 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | a7cfa03 | 2009-04-29 22:33:02 +0000 | [diff] [blame] | 1762 | u_int8_t attr[] = { NM_ATT_BS11_PLL_MODE }; |
Harald Welte | aaf02d9 | 2009-04-29 13:25:57 +0000 | [diff] [blame] | 1763 | |
| 1764 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1765 | fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR, |
| 1766 | NM_OC_BS11, BS11_OBJ_LI, 0x00, 0x00); |
Harald Welte | aeedeb4 | 2009-05-01 13:08:14 +0000 | [diff] [blame] | 1767 | msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), attr); |
Harald Welte | aaf02d9 | 2009-04-29 13:25:57 +0000 | [diff] [blame] | 1768 | |
| 1769 | return abis_nm_sendmsg(bts, msg); |
| 1770 | } |
| 1771 | |
| 1772 | |
Harald Welte | 268bb40 | 2009-02-01 19:11:56 +0000 | [diff] [blame] | 1773 | //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] | 1774 | static const u_int8_t bs11_logon_c8[] = { 0x02 }; |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1775 | static const u_int8_t bs11_logon_c9[] = "FACTORY"; |
| 1776 | |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1777 | int abis_nm_bs11_factory_logon(struct gsm_bts *bts, int on) |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1778 | { |
| 1779 | struct abis_om_hdr *oh; |
| 1780 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 268bb40 | 2009-02-01 19:11:56 +0000 | [diff] [blame] | 1781 | struct bs11_date_time bdt; |
| 1782 | |
| 1783 | get_bs11_date_time(&bdt); |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1784 | |
| 1785 | 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] | 1786 | if (on) { |
Harald Welte | 268bb40 | 2009-02-01 19:11:56 +0000 | [diff] [blame] | 1787 | u_int8_t len = 3*2 + sizeof(bdt) |
Harald Welte | 6f676a3 | 2009-01-18 14:27:48 +0000 | [diff] [blame] | 1788 | + sizeof(bs11_logon_c8) + sizeof(bs11_logon_c9); |
Harald Welte | 043d04a | 2009-01-29 23:15:30 +0000 | [diff] [blame] | 1789 | fill_om_fom_hdr(oh, len, NM_MT_BS11_LMT_LOGON, |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1790 | NM_OC_BS11_A3, 0xff, 0xff, 0xff); |
Harald Welte | 043d04a | 2009-01-29 23:15:30 +0000 | [diff] [blame] | 1791 | msgb_tlv_put(msg, NM_ATT_BS11_LMT_LOGIN_TIME, |
Harald Welte | 5083b0b | 2009-02-02 19:20:52 +0000 | [diff] [blame] | 1792 | sizeof(bdt), (u_int8_t *) &bdt); |
Harald Welte | 043d04a | 2009-01-29 23:15:30 +0000 | [diff] [blame] | 1793 | msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_ACC_LEV, |
| 1794 | sizeof(bs11_logon_c8), bs11_logon_c8); |
| 1795 | msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_NAME, |
| 1796 | sizeof(bs11_logon_c9), bs11_logon_c9); |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1797 | } else { |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1798 | fill_om_fom_hdr(oh, 0, NM_MT_BS11_LMT_LOGOFF, |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1799 | NM_OC_BS11_A3, 0xff, 0xff, 0xff); |
| 1800 | } |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 1801 | |
| 1802 | return abis_nm_sendmsg(bts, msg); |
| 1803 | } |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1804 | |
| 1805 | int abis_nm_bs11_set_trx1_pw(struct gsm_bts *bts, const char *password) |
| 1806 | { |
| 1807 | struct abis_om_hdr *oh; |
| 1808 | struct msgb *msg; |
| 1809 | |
| 1810 | if (strlen(password) != 10) |
| 1811 | return -EINVAL; |
| 1812 | |
| 1813 | msg = nm_msgb_alloc(); |
| 1814 | 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] | 1815 | 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] | 1816 | NM_OC_BS11, BS11_OBJ_TRX1, 0x00, 0x00); |
| 1817 | msgb_tlv_put(msg, NM_ATT_BS11_PASSWORD, 10, (const u_int8_t *)password); |
| 1818 | |
| 1819 | return abis_nm_sendmsg(bts, msg); |
| 1820 | } |
| 1821 | |
Harald Welte | e69f5fb | 2009-04-28 16:31:38 +0000 | [diff] [blame] | 1822 | /* change the BS-11 PLL Mode to either locked (E1 derived) or standalone */ |
| 1823 | int abis_nm_bs11_set_pll_locked(struct gsm_bts *bts, int locked) |
| 1824 | { |
| 1825 | struct abis_om_hdr *oh; |
| 1826 | struct msgb *msg; |
Harald Welte | a432cd3 | 2009-04-29 13:01:50 +0000 | [diff] [blame] | 1827 | u_int8_t tlv_value; |
Harald Welte | e69f5fb | 2009-04-28 16:31:38 +0000 | [diff] [blame] | 1828 | |
| 1829 | msg = nm_msgb_alloc(); |
| 1830 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1831 | fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR, NM_OC_BS11, |
| 1832 | BS11_OBJ_LI, 0x00, 0x00); |
Harald Welte | a432cd3 | 2009-04-29 13:01:50 +0000 | [diff] [blame] | 1833 | |
| 1834 | if (locked) |
| 1835 | tlv_value = BS11_LI_PLL_LOCKED; |
| 1836 | else |
| 1837 | tlv_value = BS11_LI_PLL_STANDALONE; |
| 1838 | |
| 1839 | msgb_tlv_put(msg, NM_ATT_BS11_PLL_MODE, 1, &tlv_value); |
Harald Welte | e69f5fb | 2009-04-28 16:31:38 +0000 | [diff] [blame] | 1840 | |
| 1841 | return abis_nm_sendmsg(bts, msg); |
| 1842 | } |
| 1843 | |
Harald Welte | 1bc0906 | 2009-01-18 14:17:52 +0000 | [diff] [blame] | 1844 | int abis_nm_bs11_get_state(struct gsm_bts *bts) |
| 1845 | { |
| 1846 | return __simple_cmd(bts, NM_MT_BS11_GET_STATE); |
| 1847 | } |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1848 | |
| 1849 | /* BS11 SWL */ |
| 1850 | |
| 1851 | struct abis_nm_bs11_sw { |
| 1852 | struct gsm_bts *bts; |
| 1853 | char swl_fname[PATH_MAX]; |
| 1854 | u_int8_t win_size; |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 1855 | int forced; |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1856 | struct llist_head file_list; |
| 1857 | gsm_cbfn *user_cb; /* specified by the user */ |
| 1858 | }; |
| 1859 | static struct abis_nm_bs11_sw _g_bs11_sw, *g_bs11_sw = &_g_bs11_sw; |
| 1860 | |
| 1861 | struct file_list_entry { |
| 1862 | struct llist_head list; |
| 1863 | char fname[PATH_MAX]; |
| 1864 | }; |
| 1865 | |
| 1866 | struct file_list_entry *fl_dequeue(struct llist_head *queue) |
| 1867 | { |
| 1868 | struct llist_head *lh; |
| 1869 | |
| 1870 | if (llist_empty(queue)) |
| 1871 | return NULL; |
| 1872 | |
| 1873 | lh = queue->next; |
| 1874 | llist_del(lh); |
| 1875 | |
| 1876 | return llist_entry(lh, struct file_list_entry, list); |
| 1877 | } |
| 1878 | |
| 1879 | static int bs11_read_swl_file(struct abis_nm_bs11_sw *bs11_sw) |
| 1880 | { |
| 1881 | char linebuf[255]; |
| 1882 | struct llist_head *lh, *lh2; |
| 1883 | FILE *swl; |
| 1884 | int rc = 0; |
| 1885 | |
| 1886 | swl = fopen(bs11_sw->swl_fname, "r"); |
| 1887 | if (!swl) |
| 1888 | return -ENODEV; |
| 1889 | |
| 1890 | /* zero the stale file list, if any */ |
| 1891 | llist_for_each_safe(lh, lh2, &bs11_sw->file_list) { |
| 1892 | llist_del(lh); |
| 1893 | free(lh); |
| 1894 | } |
| 1895 | |
| 1896 | while (fgets(linebuf, sizeof(linebuf), swl)) { |
| 1897 | char file_id[12+1]; |
| 1898 | char file_version[80+1]; |
| 1899 | struct file_list_entry *fle; |
| 1900 | static char dir[PATH_MAX]; |
| 1901 | |
| 1902 | if (strlen(linebuf) < 4) |
| 1903 | continue; |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 1904 | |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1905 | rc = sscanf(linebuf+4, "%12s:%80s\r\n", file_id, file_version); |
| 1906 | if (rc < 0) { |
| 1907 | perror("ERR parsing SWL file"); |
| 1908 | rc = -EINVAL; |
| 1909 | goto out; |
| 1910 | } |
| 1911 | if (rc < 2) |
| 1912 | continue; |
| 1913 | |
| 1914 | fle = malloc(sizeof(*fle)); |
| 1915 | if (!fle) { |
| 1916 | rc = -ENOMEM; |
| 1917 | goto out; |
| 1918 | } |
| 1919 | memset(fle, 0, sizeof(*fle)); |
| 1920 | |
| 1921 | /* construct new filename */ |
| 1922 | strncpy(dir, bs11_sw->swl_fname, sizeof(dir)); |
| 1923 | strncat(fle->fname, dirname(dir), sizeof(fle->fname) - 1); |
| 1924 | strcat(fle->fname, "/"); |
| 1925 | strncat(fle->fname, file_id, sizeof(fle->fname) - 1 -strlen(fle->fname)); |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1926 | |
| 1927 | llist_add_tail(&fle->list, &bs11_sw->file_list); |
| 1928 | } |
| 1929 | |
| 1930 | out: |
| 1931 | fclose(swl); |
| 1932 | return rc; |
| 1933 | } |
| 1934 | |
| 1935 | /* bs11 swload specific callback, passed to abis_nm core swload */ |
| 1936 | static int bs11_swload_cbfn(unsigned int hook, unsigned int event, |
| 1937 | struct msgb *msg, void *data, void *param) |
| 1938 | { |
| 1939 | struct abis_nm_bs11_sw *bs11_sw = data; |
| 1940 | struct file_list_entry *fle; |
| 1941 | int rc = 0; |
| 1942 | |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1943 | switch (event) { |
| 1944 | case NM_MT_LOAD_END_ACK: |
| 1945 | fle = fl_dequeue(&bs11_sw->file_list); |
| 1946 | if (fle) { |
| 1947 | /* start download the next file of our file list */ |
| 1948 | rc = abis_nm_software_load(bs11_sw->bts, fle->fname, |
| 1949 | bs11_sw->win_size, |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 1950 | bs11_sw->forced, |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1951 | &bs11_swload_cbfn, bs11_sw); |
| 1952 | free(fle); |
| 1953 | } else { |
| 1954 | /* activate the SWL */ |
| 1955 | rc = abis_nm_software_activate(bs11_sw->bts, |
| 1956 | bs11_sw->swl_fname, |
| 1957 | bs11_swload_cbfn, |
| 1958 | bs11_sw); |
| 1959 | } |
| 1960 | break; |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 1961 | case NM_MT_LOAD_SEG_ACK: |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1962 | case NM_MT_LOAD_END_NACK: |
| 1963 | case NM_MT_LOAD_INIT_ACK: |
| 1964 | case NM_MT_LOAD_INIT_NACK: |
| 1965 | case NM_MT_ACTIVATE_SW_NACK: |
| 1966 | case NM_MT_ACTIVATE_SW_ACK: |
| 1967 | default: |
| 1968 | /* fallthrough to the user callback */ |
Harald Welte | 97ed1e7 | 2009-02-06 13:38:02 +0000 | [diff] [blame] | 1969 | if (bs11_sw->user_cb) |
| 1970 | rc = bs11_sw->user_cb(hook, event, msg, NULL, NULL); |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1971 | break; |
| 1972 | } |
| 1973 | |
| 1974 | return rc; |
| 1975 | } |
| 1976 | |
| 1977 | /* Siemens provides a SWL file that is a mere listing of all the other |
| 1978 | * files that are part of a software release. We need to upload first |
| 1979 | * the list file, and then each file that is listed in the list file */ |
| 1980 | 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] | 1981 | u_int8_t win_size, int forced, gsm_cbfn *cbfn) |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1982 | { |
| 1983 | struct abis_nm_bs11_sw *bs11_sw = g_bs11_sw; |
| 1984 | struct file_list_entry *fle; |
| 1985 | int rc = 0; |
| 1986 | |
| 1987 | INIT_LLIST_HEAD(&bs11_sw->file_list); |
| 1988 | bs11_sw->bts = bts; |
| 1989 | bs11_sw->win_size = win_size; |
| 1990 | bs11_sw->user_cb = cbfn; |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 1991 | bs11_sw->forced = forced; |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 1992 | |
| 1993 | strncpy(bs11_sw->swl_fname, fname, sizeof(bs11_sw->swl_fname)); |
| 1994 | rc = bs11_read_swl_file(bs11_sw); |
| 1995 | if (rc < 0) |
| 1996 | return rc; |
| 1997 | |
| 1998 | /* dequeue next item in file list */ |
| 1999 | fle = fl_dequeue(&bs11_sw->file_list); |
| 2000 | if (!fle) |
| 2001 | return -EINVAL; |
| 2002 | |
| 2003 | /* start download the next file of our file list */ |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 2004 | rc = abis_nm_software_load(bts, fle->fname, win_size, forced, |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 2005 | bs11_swload_cbfn, bs11_sw); |
| 2006 | free(fle); |
| 2007 | return rc; |
| 2008 | } |
| 2009 | |
Harald Welte | 5083b0b | 2009-02-02 19:20:52 +0000 | [diff] [blame] | 2010 | #if 0 |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 2011 | static u_int8_t req_attr_btse[] = { |
| 2012 | NM_ATT_ADM_STATE, NM_ATT_BS11_LMT_LOGON_SESSION, |
| 2013 | NM_ATT_BS11_LMT_LOGIN_TIME, NM_ATT_BS11_LMT_USER_ACC_LEV, |
| 2014 | NM_ATT_BS11_LMT_USER_NAME, |
| 2015 | |
| 2016 | 0xaf, NM_ATT_BS11_RX_OFFSET, NM_ATT_BS11_VENDOR_NAME, |
| 2017 | |
| 2018 | NM_ATT_BS11_SW_LOAD_INTENDED, NM_ATT_BS11_SW_LOAD_SAFETY, |
| 2019 | |
| 2020 | NM_ATT_BS11_SW_LOAD_STORED }; |
| 2021 | |
| 2022 | static u_int8_t req_attr_btsm[] = { |
| 2023 | NM_ATT_ABIS_CHANNEL, NM_ATT_TEI, NM_ATT_BS11_ABIS_EXT_TIME, |
| 2024 | NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xce, NM_ATT_FILE_ID, |
| 2025 | NM_ATT_FILE_VERSION, NM_ATT_OPER_STATE, 0xe8, NM_ATT_BS11_ALL_TEST_CATG, |
| 2026 | NM_ATT_SW_DESCR, NM_ATT_GET_ARI }; |
Harald Welte | 5083b0b | 2009-02-02 19:20:52 +0000 | [diff] [blame] | 2027 | #endif |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 2028 | |
| 2029 | static u_int8_t req_attr[] = { |
| 2030 | NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xa8, NM_ATT_OPER_STATE, |
| 2031 | 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] | 2032 | 0x42, NM_ATT_BS11_ESN_PCB_SERIAL, NM_ATT_BS11_PLL }; |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 2033 | |
| 2034 | int abis_nm_bs11_get_serno(struct gsm_bts *bts) |
| 2035 | { |
| 2036 | struct abis_om_hdr *oh; |
| 2037 | struct msgb *msg = nm_msgb_alloc(); |
| 2038 | |
| 2039 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 2040 | /* SiemensHW CCTRL object */ |
| 2041 | fill_om_fom_hdr(oh, 2+sizeof(req_attr), NM_MT_GET_ATTR, NM_OC_BS11, |
| 2042 | 0x03, 0x00, 0x00); |
| 2043 | msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(req_attr), req_attr); |
| 2044 | |
| 2045 | return abis_nm_sendmsg(bts, msg); |
| 2046 | } |
Harald Welte | 268bb40 | 2009-02-01 19:11:56 +0000 | [diff] [blame] | 2047 | |
| 2048 | int abis_nm_bs11_set_ext_time(struct gsm_bts *bts) |
| 2049 | { |
| 2050 | struct abis_om_hdr *oh; |
| 2051 | struct msgb *msg = nm_msgb_alloc(); |
| 2052 | struct bs11_date_time aet; |
| 2053 | |
| 2054 | get_bs11_date_time(&aet); |
| 2055 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 2056 | /* SiemensHW CCTRL object */ |
| 2057 | fill_om_fom_hdr(oh, 2+sizeof(aet), NM_MT_BS11_SET_ATTR, NM_OC_SITE_MANAGER, |
| 2058 | 0xff, 0xff, 0xff); |
Harald Welte | 5083b0b | 2009-02-02 19:20:52 +0000 | [diff] [blame] | 2059 | 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] | 2060 | |
| 2061 | return abis_nm_sendmsg(bts, msg); |
| 2062 | } |
Harald Welte | 5c1e458 | 2009-02-15 11:57:29 +0000 | [diff] [blame] | 2063 | |
| 2064 | /* ip.access nanoBTS specific commands */ |
Harald Welte | 5c1e458 | 2009-02-15 11:57:29 +0000 | [diff] [blame] | 2065 | static const char ipaccess_magic[] = "com.ipaccess"; |
| 2066 | |
Harald Welte | 677c21f | 2009-02-17 13:22:23 +0000 | [diff] [blame] | 2067 | |
| 2068 | static int abis_nm_rx_ipacc(struct msgb *msg) |
| 2069 | { |
| 2070 | struct abis_om_hdr *oh = msgb_l2(msg); |
| 2071 | struct abis_om_fom_hdr *foh; |
| 2072 | u_int8_t idstrlen = oh->data[0]; |
| 2073 | struct tlv_parsed tp; |
| 2074 | |
| 2075 | if (strncmp((char *)&oh->data[1], ipaccess_magic, idstrlen)) { |
| 2076 | DEBUGP(DNM, "id string is not com.ipaccess !?!\n"); |
| 2077 | return -EINVAL; |
| 2078 | } |
| 2079 | |
Harald Welte | 193fefc | 2009-04-30 15:16:27 +0000 | [diff] [blame] | 2080 | foh = (struct abis_om_fom_hdr *) (oh->data + 1 + idstrlen); |
Harald Welte | 0313394 | 2009-02-18 19:51:53 +0000 | [diff] [blame] | 2081 | abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh)); |
Harald Welte | 677c21f | 2009-02-17 13:22:23 +0000 | [diff] [blame] | 2082 | |
Harald Welte | 193fefc | 2009-04-30 15:16:27 +0000 | [diff] [blame] | 2083 | DEBUGP(DNM, "IPACCESS(0x%02x): ", foh->msg_type); |
| 2084 | |
Harald Welte | 677c21f | 2009-02-17 13:22:23 +0000 | [diff] [blame] | 2085 | switch (foh->msg_type) { |
| 2086 | case NM_MT_IPACC_RSL_CONNECT_ACK: |
Harald Welte | 193fefc | 2009-04-30 15:16:27 +0000 | [diff] [blame] | 2087 | DEBUGPC(DNM, "RSL CONNECT ACK "); |
Harald Welte | 677c21f | 2009-02-17 13:22:23 +0000 | [diff] [blame] | 2088 | if (TLVP_PRESENT(&tp, NM_ATT_IPACC_RSL_BSC_IP)) |
Harald Welte | 9de2bf8 | 2009-04-30 15:59:55 +0000 | [diff] [blame] | 2089 | DEBUGPC(DNM, "IP=%s ", |
Harald Welte | 677c21f | 2009-02-17 13:22:23 +0000 | [diff] [blame] | 2090 | inet_ntoa(*((struct in_addr *) |
| 2091 | TLVP_VAL(&tp, NM_ATT_IPACC_RSL_BSC_IP)))); |
| 2092 | if (TLVP_PRESENT(&tp, NM_ATT_IPACC_RSL_BSC_PORT)) |
Harald Welte | 9de2bf8 | 2009-04-30 15:59:55 +0000 | [diff] [blame] | 2093 | DEBUGPC(DNM, "PORT=%u ", |
Harald Welte | 677c21f | 2009-02-17 13:22:23 +0000 | [diff] [blame] | 2094 | ntohs(*((u_int16_t *) |
| 2095 | TLVP_VAL(&tp, NM_ATT_IPACC_RSL_BSC_PORT)))); |
Harald Welte | 9de2bf8 | 2009-04-30 15:59:55 +0000 | [diff] [blame] | 2096 | DEBUGPC(DNM, "\n"); |
Harald Welte | 677c21f | 2009-02-17 13:22:23 +0000 | [diff] [blame] | 2097 | break; |
| 2098 | case NM_MT_IPACC_RSL_CONNECT_NACK: |
Harald Welte | 193fefc | 2009-04-30 15:16:27 +0000 | [diff] [blame] | 2099 | DEBUGPC(DNM, "RSL CONNECT NACK "); |
Harald Welte | 677c21f | 2009-02-17 13:22:23 +0000 | [diff] [blame] | 2100 | if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES)) |
Harald Welte | 6c96ba5 | 2009-05-01 13:03:40 +0000 | [diff] [blame] | 2101 | DEBUGPC(DNM, " CAUSE=%s\n", |
| 2102 | nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES))); |
Harald Welte | 677c21f | 2009-02-17 13:22:23 +0000 | [diff] [blame] | 2103 | else |
| 2104 | DEBUGPC(DNM, "\n"); |
| 2105 | break; |
Harald Welte | 193fefc | 2009-04-30 15:16:27 +0000 | [diff] [blame] | 2106 | case NM_MT_IPACC_SET_NVATTR_ACK: |
| 2107 | DEBUGPC(DNM, "SET NVATTR ACK\n"); |
| 2108 | /* FIXME: decode and show the actual attributes */ |
| 2109 | break; |
| 2110 | case NM_MT_IPACC_SET_NVATTR_NACK: |
Harald Welte | 6c96ba5 | 2009-05-01 13:03:40 +0000 | [diff] [blame] | 2111 | DEBUGPC(DNM, "SET NVATTR NACK "); |
| 2112 | if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES)) |
| 2113 | DEBUGPC(DNM, " CAUSE=%s\n", |
| 2114 | nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES))); |
| 2115 | else |
| 2116 | DEBUGPC(DNM, "\n"); |
Harald Welte | 193fefc | 2009-04-30 15:16:27 +0000 | [diff] [blame] | 2117 | break; |
| 2118 | default: |
| 2119 | DEBUGPC(DNM, "unknown\n"); |
| 2120 | break; |
Harald Welte | 677c21f | 2009-02-17 13:22:23 +0000 | [diff] [blame] | 2121 | } |
| 2122 | return 0; |
| 2123 | } |
| 2124 | |
Harald Welte | 193fefc | 2009-04-30 15:16:27 +0000 | [diff] [blame] | 2125 | /* send an ip-access manufacturer specific message */ |
Harald Welte | 5c1e458 | 2009-02-15 11:57:29 +0000 | [diff] [blame] | 2126 | int abis_nm_ipaccess_msg(struct gsm_bts *bts, u_int8_t msg_type, |
| 2127 | u_int8_t obj_class, u_int8_t bts_nr, |
| 2128 | u_int8_t trx_nr, u_int8_t ts_nr, |
| 2129 | u_int8_t *attr, int attr_len) |
| 2130 | { |
| 2131 | struct msgb *msg = nm_msgb_alloc(); |
| 2132 | struct abis_om_hdr *oh; |
| 2133 | struct abis_om_fom_hdr *foh; |
| 2134 | u_int8_t *data; |
| 2135 | |
| 2136 | /* construct the 12.21 OM header, observe the erroneous length */ |
| 2137 | oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh)); |
| 2138 | fill_om_hdr(oh, sizeof(*foh) + attr_len); |
| 2139 | oh->mdisc = ABIS_OM_MDISC_MANUF; |
| 2140 | |
| 2141 | /* add the ip.access magic */ |
| 2142 | data = msgb_put(msg, sizeof(ipaccess_magic)+1); |
| 2143 | *data++ = sizeof(ipaccess_magic); |
| 2144 | memcpy(data, ipaccess_magic, sizeof(ipaccess_magic)); |
| 2145 | |
| 2146 | /* fill the 12.21 FOM header */ |
| 2147 | foh = (struct abis_om_fom_hdr *) msgb_put(msg, sizeof(*foh)); |
| 2148 | foh->msg_type = msg_type; |
| 2149 | foh->obj_class = obj_class; |
| 2150 | foh->obj_inst.bts_nr = bts_nr; |
| 2151 | foh->obj_inst.trx_nr = trx_nr; |
| 2152 | foh->obj_inst.ts_nr = ts_nr; |
| 2153 | |
| 2154 | if (attr && attr_len) { |
| 2155 | data = msgb_put(msg, attr_len); |
| 2156 | memcpy(data, attr, attr_len); |
| 2157 | } |
| 2158 | |
| 2159 | return abis_nm_sendmsg(bts, msg); |
| 2160 | } |
Harald Welte | 677c21f | 2009-02-17 13:22:23 +0000 | [diff] [blame] | 2161 | |
Harald Welte | 193fefc | 2009-04-30 15:16:27 +0000 | [diff] [blame] | 2162 | /* set some attributes in NVRAM */ |
| 2163 | int abis_nm_ipaccess_set_nvattr(struct gsm_bts *bts, u_int8_t *attr, |
| 2164 | int attr_len) |
| 2165 | { |
| 2166 | return abis_nm_ipaccess_msg(bts, NM_MT_IPACC_SET_NVATTR, |
| 2167 | NM_OC_BASEB_TRANSC, 0, 0, 0xff, attr, |
| 2168 | attr_len); |
| 2169 | } |
| 2170 | |
| 2171 | /* restart / reboot an ip.access nanoBTS */ |
| 2172 | int abis_nm_ipaccess_restart(struct gsm_bts *bts) |
| 2173 | { |
| 2174 | return __simple_cmd(bts, NM_MT_IPACC_RESTART); |
| 2175 | } |