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