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