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