blob: 4a73930fc21d503973b994929a4c0c34400cd4db [file] [log] [blame]
Harald Welte52b1f982008-12-23 20:25:15 +00001/* 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 Welte4724f992009-01-18 18:01:49 +00004/* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org>
Harald Welte8470bf22008-12-25 23:28:35 +00005 *
Harald Welte52b1f982008-12-23 20:25:15 +00006 * 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 Welte4724f992009-01-18 18:01:49 +000026#include <unistd.h>
Harald Welte52b1f982008-12-23 20:25:15 +000027#include <stdio.h>
Harald Welte4724f992009-01-18 18:01:49 +000028#include <fcntl.h>
Harald Welte12247c62009-05-21 07:23:02 +000029#include <stdlib.h>
Harald Welte5e4d1b32009-02-01 13:36:56 +000030#include <libgen.h>
Harald Welte268bb402009-02-01 19:11:56 +000031#include <time.h>
Harald Welte5f6f1492009-02-02 14:50:29 +000032#include <limits.h>
Harald Welte4724f992009-01-18 18:01:49 +000033
Harald Welte52b1f982008-12-23 20:25:15 +000034#include <sys/types.h>
Harald Welte4724f992009-01-18 18:01:49 +000035#include <sys/stat.h>
Harald Welte8470bf22008-12-25 23:28:35 +000036#include <netinet/in.h>
Harald Welte677c21f2009-02-17 13:22:23 +000037#include <arpa/inet.h>
Harald Welte52b1f982008-12-23 20:25:15 +000038
Harald Welte8470bf22008-12-25 23:28:35 +000039#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 Freytherca362a62009-01-04 21:05:01 +000044#include <openbsc/misdn.h>
Harald Weltef9a8cc32009-05-01 15:39:49 +000045#include <openbsc/signal.h>
Harald Welte2cf161b2009-06-20 22:36:41 +020046#include <openbsc/talloc.h>
Harald Welte52b1f982008-12-23 20:25:15 +000047
Harald Welte8470bf22008-12-25 23:28:35 +000048#define OM_ALLOC_SIZE 1024
49#define OM_HEADROOM_SIZE 128
Harald Welte52b1f982008-12-23 20:25:15 +000050
51/* unidirectional messages from BTS to BSC */
52static 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 */
60static 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 Welte4724f992009-01-18 18:01:49 +000066/* Messages related to software load */
67static 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 Welte34a99682009-02-13 02:41:40 +000074 //NM_MT_SW_ACT_REQ,
Harald Welte4724f992009-01-18 18:01:49 +000075 NM_MT_ACTIVATE_SW_ACK,
76 NM_MT_ACTIVATE_SW_NACK,
77 NM_MT_SW_ACTIVATED_REP,
78};
79
Harald Weltee0590df2009-02-15 03:34:15 +000080static 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 Welte78fc0d42009-02-19 02:50:57 +0000115
116static 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 Welte6c96ba52009-05-01 13:03:40 +0000152/* Chapter 9.4.36 */
153static 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 Welte560982b2009-06-26 13:21:57 +0200182 [NM_NACK_FILE_NOTACTIVATE] = "File cannot be activate",
Harald Welte6c96ba52009-05-01 13:03:40 +0000183 [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
190static char namebuf[255];
191static 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 Welte0db97b22009-05-01 17:22:47 +0000200/* Chapter 9.4.16: Event Type */
201static 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
209static 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 */
219static 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
228static 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 Welte52b1f982008-12-23 20:25:15 +0000237/* Attributes that the BSC can set, not only get, according to Section 9.4 */
238static 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 Weltee0590df2009-02-15 03:34:15 +0000266static 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 Welte78fc0d42009-02-19 02:50:57 +0000334 [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 Weltee0590df2009-02-15 03:34:15 +0000340 [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 Welteee670472009-02-22 21:58:49 +0000347 [NM_ATT_BS11_LMT_LOGON_SESSION]={ TLV_TYPE_TLV },
Harald Weltee0590df2009-02-15 03:34:15 +0000348 [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 Welte03133942009-02-18 19:51:53 +0000351 [NM_ATT_BS11_BTS_STATE] = { TLV_TYPE_TLV },
352 [NM_ATT_BS11_E1_STATE] = { TLV_TYPE_TLV },
Harald Welteaaf02d92009-04-29 13:25:57 +0000353 [NM_ATT_BS11_PLL_MODE] = { TLV_TYPE_TLV },
Harald Weltea7cfa032009-04-29 22:33:02 +0000354 [NM_ATT_BS11_PLL] = { TLV_TYPE_TLV },
Harald Welteef061952009-05-17 12:43:42 +0000355 [NM_ATT_BS11_CCLK_ACCURACY] = { TLV_TYPE_TV },
356 [NM_ATT_BS11_CCLK_TYPE] = { TLV_TYPE_TV },
Harald Welte677c21f2009-02-17 13:22:23 +0000357 /* ip.access specifics */
358 [NM_ATT_IPACC_RSL_BSC_IP] = { TLV_TYPE_FIXED, 4 },
359 [NM_ATT_IPACC_RSL_BSC_PORT] = { TLV_TYPE_FIXED, 2 },
Harald Welte3bfbb842009-04-29 22:58:38 +0000360 [NM_ATT_IPACC_PRIM_OML_IP] = { TLV_TYPE_FIXED, 6 },
361 [0x95] = { TLV_TYPE_FIXED, 2 },
Harald Welte677c21f2009-02-17 13:22:23 +0000362 [0x85] = { TLV_TYPE_TV },
363
Harald Weltee0590df2009-02-15 03:34:15 +0000364 },
365};
Harald Welte03133942009-02-18 19:51:53 +0000366
367int abis_nm_tlv_parse(struct tlv_parsed *tp, const u_int8_t *buf, int len)
368{
Harald Weltea4d49e92009-05-23 06:39:58 +0000369 return tlv_parse(tp, &nm_att_tlvdef, buf, len, 0, 0);
Harald Welte03133942009-02-18 19:51:53 +0000370}
Harald Weltee0590df2009-02-15 03:34:15 +0000371
Harald Welte52b1f982008-12-23 20:25:15 +0000372static int is_in_arr(enum abis_nm_msgtype mt, const enum abis_nm_msgtype *arr, int size)
373{
374 int i;
375
376 for (i = 0; i < size; i++) {
377 if (arr[i] == mt)
378 return 1;
379 }
380
381 return 0;
382}
383
Holger Freytherca362a62009-01-04 21:05:01 +0000384#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000385/* is this msgtype the usual ACK/NACK type ? */
386static int is_ack_nack(enum abis_nm_msgtype mt)
387{
388 return !is_in_arr(mt, no_ack_nack, ARRAY_SIZE(no_ack_nack));
389}
Holger Freytherca362a62009-01-04 21:05:01 +0000390#endif
Harald Welte52b1f982008-12-23 20:25:15 +0000391
392/* is this msgtype a report ? */
393static int is_report(enum abis_nm_msgtype mt)
394{
Harald Welte8470bf22008-12-25 23:28:35 +0000395 return is_in_arr(mt, reports, ARRAY_SIZE(reports));
Harald Welte52b1f982008-12-23 20:25:15 +0000396}
397
398#define MT_ACK(x) (x+1)
399#define MT_NACK(x) (x+2)
400
401static void fill_om_hdr(struct abis_om_hdr *oh, u_int8_t len)
402{
403 oh->mdisc = ABIS_OM_MDISC_FOM;
404 oh->placement = ABIS_OM_PLACEMENT_ONLY;
405 oh->sequence = 0;
406 oh->length = len;
407}
408
409static void fill_om_fom_hdr(struct abis_om_hdr *oh, u_int8_t len,
410 u_int8_t msg_type, u_int8_t obj_class,
411 u_int8_t bts_nr, u_int8_t trx_nr, u_int8_t ts_nr)
412{
413 struct abis_om_fom_hdr *foh =
414 (struct abis_om_fom_hdr *) oh->data;
415
Harald Welte702d8702008-12-26 20:25:35 +0000416 fill_om_hdr(oh, len+sizeof(*foh));
Harald Welte52b1f982008-12-23 20:25:15 +0000417 foh->msg_type = msg_type;
418 foh->obj_class = obj_class;
419 foh->obj_inst.bts_nr = bts_nr;
420 foh->obj_inst.trx_nr = trx_nr;
421 foh->obj_inst.ts_nr = ts_nr;
422}
423
Harald Welte8470bf22008-12-25 23:28:35 +0000424static struct msgb *nm_msgb_alloc(void)
425{
Harald Welte966636f2009-06-26 19:39:35 +0200426 return msgb_alloc_headroom(OM_ALLOC_SIZE, OM_HEADROOM_SIZE,
427 "OML");
Harald Welte8470bf22008-12-25 23:28:35 +0000428}
429
Harald Welte52b1f982008-12-23 20:25:15 +0000430/* Send a OML NM Message from BSC to BTS */
431int abis_nm_sendmsg(struct gsm_bts *bts, struct msgb *msg)
432{
Holger Freyther59639e82009-02-09 23:09:55 +0000433 msg->trx = bts->c0;
434
Harald Weltead384642008-12-26 10:20:07 +0000435 return _abis_nm_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000436}
437
Harald Welte4724f992009-01-18 18:01:49 +0000438static int abis_nm_rcvmsg_sw(struct msgb *mb);
439
Harald Welte34a99682009-02-13 02:41:40 +0000440static const char *obj_class_name(u_int8_t oc)
441{
Harald Welte7b26bcb2009-05-28 11:39:21 +0000442 switch (oc) {
443 case NM_OC_SITE_MANAGER:
444 return "SITE MANAGER";
445 case NM_OC_BTS:
446 return "BTS";
447 case NM_OC_RADIO_CARRIER:
448 return "RADIO CARRIER";
449 case NM_OC_BASEB_TRANSC:
450 return "BASEBAND TRANSCEIVER";
451 case NM_OC_CHANNEL:
Harald Weltebd8f7e32009-06-09 20:17:12 +0000452 return "CHANNEL";
Harald Welte7b26bcb2009-05-28 11:39:21 +0000453 case NM_OC_BS11_ADJC:
454 return "ADJC";
455 case NM_OC_BS11_HANDOVER:
456 return "HANDOVER";
457 case NM_OC_BS11_PWR_CTRL:
458 return "POWER CONTROL";
459 case NM_OC_BS11_BTSE:
460 return "BTSE";
461 case NM_OC_BS11_RACK:
462 return "RACK";
463 case NM_OC_BS11_TEST:
464 return "TEST";
465 case NM_OC_BS11_ENVABTSE:
466 return "ENVABTSE";
467 case NM_OC_BS11_BPORT:
468 return "BPORT";
469 case NM_OC_GPRS_NSE:
470 return "GPRS NSE";
471 case NM_OC_GPRS_CELL:
472 return "GPRS CELL";
473 case NM_OC_GPRS_NSVC0:
474 return "GPRS NSVC0";
475 case NM_OC_GPRS_NSVC1:
476 return "GPRS NSVC1";
Harald Welte8b697c72009-06-05 19:18:45 +0000477 case NM_OC_BS11:
478 return "SIEMENSHW";
Harald Welte7b26bcb2009-05-28 11:39:21 +0000479 }
480
481 return "UNKNOWN";
Harald Welte34a99682009-02-13 02:41:40 +0000482}
483
Harald Welte4d87f242009-03-10 19:43:44 +0000484const char *nm_opstate_name(u_int8_t os)
Harald Welte34a99682009-02-13 02:41:40 +0000485{
486 switch (os) {
487 case 1:
488 return "Disabled";
489 case 2:
490 return "Enabled";
491 case 0xff:
492 return "NULL";
493 default:
494 return "RFU";
495 }
496}
497
Harald Weltee0590df2009-02-15 03:34:15 +0000498/* Chapter 9.4.7 */
Harald Welte4d87f242009-03-10 19:43:44 +0000499static const char *avail_names[] = {
Harald Weltee0590df2009-02-15 03:34:15 +0000500 "In test",
501 "Failed",
502 "Power off",
503 "Off line",
504 "<not used>",
505 "Dependency",
506 "Degraded",
507 "Not installed",
508};
509
Harald Welte4d87f242009-03-10 19:43:44 +0000510const char *nm_avail_name(u_int8_t avail)
Harald Weltee0590df2009-02-15 03:34:15 +0000511{
Harald Welte0b8348d2009-02-18 03:43:01 +0000512 if (avail == 0xff)
513 return "OK";
Harald Weltee0590df2009-02-15 03:34:15 +0000514 if (avail >= ARRAY_SIZE(avail_names))
515 return "UNKNOWN";
516 return avail_names[avail];
517}
Harald Welte7b26bcb2009-05-28 11:39:21 +0000518
519const char *nm_adm_name(u_int8_t adm)
520{
521 switch (adm) {
522 case 1:
523 return "Locked";
524 case 2:
525 return "Unlocked";
526 case 3:
527 return "Shutdown";
528 default:
529 return "<not used>";
530 }
531}
Harald Weltee0590df2009-02-15 03:34:15 +0000532
533/* obtain the gsm_nm_state data structure for a given object instance */
534static struct gsm_nm_state *
535objclass2nmstate(struct gsm_bts *bts, u_int8_t obj_class,
536 struct abis_om_obj_inst *obj_inst)
537{
538 struct gsm_bts_trx *trx;
539 struct gsm_nm_state *nm_state = NULL;
540
541 switch (obj_class) {
542 case NM_OC_BTS:
543 nm_state = &bts->nm_state;
544 break;
545 case NM_OC_RADIO_CARRIER:
546 if (obj_inst->trx_nr >= bts->num_trx)
547 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200548 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000549 nm_state = &trx->nm_state;
550 break;
551 case NM_OC_BASEB_TRANSC:
552 if (obj_inst->trx_nr >= bts->num_trx)
553 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200554 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000555 nm_state = &trx->bb_transc.nm_state;
556 break;
557 case NM_OC_CHANNEL:
558 if (obj_inst->trx_nr > bts->num_trx)
559 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200560 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000561 if (obj_inst->ts_nr >= TRX_NR_TS)
562 return NULL;
563 nm_state = &trx->ts[obj_inst->ts_nr].nm_state;
564 break;
565 case NM_OC_SITE_MANAGER:
566 nm_state = &bts->site_mgr.nm_state;
567 break;
Harald Welte7b26bcb2009-05-28 11:39:21 +0000568 case NM_OC_BS11:
569 switch (obj_inst->bts_nr) {
570 case BS11_OBJ_CCLK:
571 nm_state = &bts->bs11.cclk.nm_state;
572 break;
Harald Welte8b697c72009-06-05 19:18:45 +0000573 case BS11_OBJ_BBSIG:
574 if (obj_inst->ts_nr > bts->num_trx)
575 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200576 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Welte8b697c72009-06-05 19:18:45 +0000577 nm_state = &trx->bs11.bbsig.nm_state;
578 break;
579 case BS11_OBJ_PA:
580 if (obj_inst->ts_nr > bts->num_trx)
581 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200582 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Welte8b697c72009-06-05 19:18:45 +0000583 nm_state = &trx->bs11.pa.nm_state;
584 break;
Harald Welte7b26bcb2009-05-28 11:39:21 +0000585 default:
586 return NULL;
587 }
588 case NM_OC_BS11_RACK:
589 nm_state = &bts->bs11.rack.nm_state;
590 break;
Harald Welte8b697c72009-06-05 19:18:45 +0000591 case NM_OC_BS11_ENVABTSE:
592 if (obj_inst->trx_nr > ARRAY_SIZE(bts->bs11.envabtse))
593 return NULL;
594 nm_state = &bts->bs11.envabtse[obj_inst->trx_nr].nm_state;
595 break;
Harald Weltee0590df2009-02-15 03:34:15 +0000596 }
597 return nm_state;
598}
599
600/* obtain the in-memory data structure of a given object instance */
601static void *
602objclass2obj(struct gsm_bts *bts, u_int8_t obj_class,
603 struct abis_om_obj_inst *obj_inst)
604{
605 struct gsm_bts_trx *trx;
606 void *obj = NULL;
607
608 switch (obj_class) {
609 case NM_OC_BTS:
610 obj = bts;
611 break;
612 case NM_OC_RADIO_CARRIER:
613 if (obj_inst->trx_nr >= bts->num_trx)
614 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200615 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000616 obj = trx;
617 break;
618 case NM_OC_BASEB_TRANSC:
619 if (obj_inst->trx_nr >= bts->num_trx)
620 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200621 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000622 obj = &trx->bb_transc;
623 break;
624 case NM_OC_CHANNEL:
625 if (obj_inst->trx_nr > bts->num_trx)
626 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200627 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000628 if (obj_inst->ts_nr >= TRX_NR_TS)
629 return NULL;
630 obj = &trx->ts[obj_inst->ts_nr];
631 break;
632 case NM_OC_SITE_MANAGER:
633 obj = &bts->site_mgr;
634 break;
635 }
636 return obj;
637}
638
639/* Update the administrative state of a given object in our in-memory data
640 * structures and send an event to the higher layer */
641static int update_admstate(struct gsm_bts *bts, u_int8_t obj_class,
642 struct abis_om_obj_inst *obj_inst, u_int8_t adm_state)
643{
Harald Welteaeedeb42009-05-01 13:08:14 +0000644 struct gsm_nm_state *nm_state, new_state;
Harald Weltee0590df2009-02-15 03:34:15 +0000645 void *obj;
646 int rc;
647
Harald Weltee0590df2009-02-15 03:34:15 +0000648 obj = objclass2obj(bts, obj_class, obj_inst);
Harald Welteaeedeb42009-05-01 13:08:14 +0000649 nm_state = objclass2nmstate(bts, obj_class, obj_inst);
650 if (!nm_state)
651 return -1;
652
653 new_state = *nm_state;
654 new_state.administrative = adm_state;
655
656 rc = nm_state_event(EVT_STATECHG_ADM, obj_class, obj, nm_state, &new_state);
657
658 nm_state->administrative = adm_state;
Harald Weltee0590df2009-02-15 03:34:15 +0000659
660 return rc;
661}
662
Harald Welte97ed1e72009-02-06 13:38:02 +0000663static int abis_nm_rx_statechg_rep(struct msgb *mb)
664{
Harald Weltee0590df2009-02-15 03:34:15 +0000665 struct abis_om_hdr *oh = msgb_l2(mb);
Harald Welte97ed1e72009-02-06 13:38:02 +0000666 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Harald Welte22af0db2009-02-14 15:41:08 +0000667 struct gsm_bts *bts = mb->trx->bts;
Harald Weltee0590df2009-02-15 03:34:15 +0000668 struct tlv_parsed tp;
669 struct gsm_nm_state *nm_state, new_state;
670 int rc;
671
Harald Welte23897662009-05-01 14:52:51 +0000672 DEBUGPC(DNM, "STATE CHG: ");
Harald Weltee0590df2009-02-15 03:34:15 +0000673
Harald Welte8b697c72009-06-05 19:18:45 +0000674 memset(&new_state, 0, sizeof(new_state));
675
Harald Weltee0590df2009-02-15 03:34:15 +0000676 nm_state = objclass2nmstate(bts, foh->obj_class, &foh->obj_inst);
677 if (!nm_state) {
678 DEBUGPC(DNM, "\n");
679 return -EINVAL;
Harald Welte22af0db2009-02-14 15:41:08 +0000680 }
Harald Weltee0590df2009-02-15 03:34:15 +0000681
682 new_state = *nm_state;
683
Harald Welte03133942009-02-18 19:51:53 +0000684 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Weltee0590df2009-02-15 03:34:15 +0000685 if (TLVP_PRESENT(&tp, NM_ATT_OPER_STATE)) {
686 new_state.operational = *TLVP_VAL(&tp, NM_ATT_OPER_STATE);
Harald Welte4d87f242009-03-10 19:43:44 +0000687 DEBUGPC(DNM, "OP_STATE=%s ", nm_opstate_name(new_state.operational));
Harald Weltee0590df2009-02-15 03:34:15 +0000688 }
689 if (TLVP_PRESENT(&tp, NM_ATT_AVAIL_STATUS)) {
Harald Welte0b8348d2009-02-18 03:43:01 +0000690 if (TLVP_LEN(&tp, NM_ATT_AVAIL_STATUS) == 0)
691 new_state.availability = 0xff;
692 else
693 new_state.availability = *TLVP_VAL(&tp, NM_ATT_AVAIL_STATUS);
Harald Welte4d87f242009-03-10 19:43:44 +0000694 DEBUGPC(DNM, "AVAIL=%s(%02x) ", nm_avail_name(new_state.availability),
Harald Weltee0590df2009-02-15 03:34:15 +0000695 new_state.availability);
696 }
697 if (TLVP_PRESENT(&tp, NM_ATT_ADM_STATE)) {
698 new_state.administrative = *TLVP_VAL(&tp, NM_ATT_ADM_STATE);
Harald Welte5d4b1c22009-06-12 01:34:29 +0800699 DEBUGPC(DNM, "ADM=%02s ", nm_adm_name(new_state.administrative));
Harald Welte97ed1e72009-02-06 13:38:02 +0000700 }
701 DEBUGPC(DNM, "\n");
Harald Weltee0590df2009-02-15 03:34:15 +0000702
703 if (memcmp(&new_state, nm_state, sizeof(new_state))) {
704 /* Update the operational state of a given object in our in-memory data
705 * structures and send an event to the higher layer */
706 void *obj = objclass2obj(bts, foh->obj_class, &foh->obj_inst);
707 rc = nm_state_event(EVT_STATECHG_OPER, foh->obj_class, obj, nm_state, &new_state);
708 *nm_state = new_state;
709 }
710#if 0
Harald Welte22af0db2009-02-14 15:41:08 +0000711 if (op_state == 1) {
712 /* try to enable objects that are disabled */
713 abis_nm_opstart(bts, foh->obj_class,
714 foh->obj_inst.bts_nr,
715 foh->obj_inst.trx_nr,
716 foh->obj_inst.ts_nr);
717 }
Harald Weltee0590df2009-02-15 03:34:15 +0000718#endif
Harald Welte97ed1e72009-02-06 13:38:02 +0000719 return 0;
720}
721
Harald Welte0db97b22009-05-01 17:22:47 +0000722static int rx_fail_evt_rep(struct msgb *mb)
723{
724 struct abis_om_hdr *oh = msgb_l2(mb);
725 struct abis_om_fom_hdr *foh = msgb_l3(mb);
726 struct tlv_parsed tp;
727
728 DEBUGPC(DNM, "Failure Event Report ");
729
730 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
731
732 if (TLVP_PRESENT(&tp, NM_ATT_EVENT_TYPE))
733 DEBUGPC(DNM, "Type=%s ", event_type_name(*TLVP_VAL(&tp, NM_ATT_EVENT_TYPE)));
734 if (TLVP_PRESENT(&tp, NM_ATT_SEVERITY))
735 DEBUGPC(DNM, "Severity=%s ", severity_name(*TLVP_VAL(&tp, NM_ATT_SEVERITY)));
736
737 DEBUGPC(DNM, "\n");
738
739 return 0;
740}
741
Harald Welte97ed1e72009-02-06 13:38:02 +0000742static int abis_nm_rcvmsg_report(struct msgb *mb)
743{
744 struct abis_om_fom_hdr *foh = msgb_l3(mb);
745 u_int8_t mt = foh->msg_type;
746
Harald Welte23897662009-05-01 14:52:51 +0000747 DEBUGP(DNM, "OC=%s(%02x) INST=(%02x,%02x,%02x) ",
748 obj_class_name(foh->obj_class), foh->obj_class,
749 foh->obj_inst.bts_nr, foh->obj_inst.trx_nr,
750 foh->obj_inst.ts_nr);
751
Harald Welte97ed1e72009-02-06 13:38:02 +0000752 //nmh->cfg->report_cb(mb, foh);
753
754 switch (mt) {
755 case NM_MT_STATECHG_EVENT_REP:
756 return abis_nm_rx_statechg_rep(mb);
757 break;
Harald Welte34a99682009-02-13 02:41:40 +0000758 case NM_MT_SW_ACTIVATED_REP:
Harald Welte23897662009-05-01 14:52:51 +0000759 DEBUGPC(DNM, "Software Activated Report\n");
Harald Weltef9a8cc32009-05-01 15:39:49 +0000760 dispatch_signal(SS_NM, S_NM_SW_ACTIV_REP, mb);
Harald Welte34a99682009-02-13 02:41:40 +0000761 break;
Harald Weltee0590df2009-02-15 03:34:15 +0000762 case NM_MT_FAILURE_EVENT_REP:
Harald Welte0db97b22009-05-01 17:22:47 +0000763 rx_fail_evt_rep(mb);
Harald Weltef9a8cc32009-05-01 15:39:49 +0000764 dispatch_signal(SS_NM, S_NM_FAIL_REP, mb);
Harald Weltee0590df2009-02-15 03:34:15 +0000765 break;
766 default:
Harald Welte23897662009-05-01 14:52:51 +0000767 DEBUGPC(DNM, "reporting NM MT 0x%02x\n", mt);
Harald Weltee0590df2009-02-15 03:34:15 +0000768 break;
769
Harald Welte97ed1e72009-02-06 13:38:02 +0000770 };
771
Harald Welte97ed1e72009-02-06 13:38:02 +0000772 return 0;
773}
774
Harald Welte34a99682009-02-13 02:41:40 +0000775/* Activate the specified software into the BTS */
776static int ipacc_sw_activate(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1,
777 u_int8_t i2, u_int8_t *sw_desc, u_int8_t swdesc_len)
778{
779 struct abis_om_hdr *oh;
780 struct msgb *msg = nm_msgb_alloc();
781 u_int8_t len = swdesc_len;
782 u_int8_t *trailer;
783
784 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
785 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, obj_class, i0, i1, i2);
786
787 trailer = msgb_put(msg, swdesc_len);
788 memcpy(trailer, sw_desc, swdesc_len);
789
790 return abis_nm_sendmsg(bts, msg);
791}
792
793static int abis_nm_rx_sw_act_req(struct msgb *mb)
794{
795 struct abis_om_hdr *oh = msgb_l2(mb);
796 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Harald Welte5c1e4582009-02-15 11:57:29 +0000797 int nack = 0;
Harald Welte34a99682009-02-13 02:41:40 +0000798 int ret;
799
Harald Welte5c1e4582009-02-15 11:57:29 +0000800 DEBUGP(DNM, "Software Activate Request ");
Harald Welte34a99682009-02-13 02:41:40 +0000801
Harald Welte5c1e4582009-02-15 11:57:29 +0000802 if (foh->obj_class >= 0xf0 && foh->obj_class <= 0xf3) {
803 DEBUGPC(DNM, "NACKing for GPRS obj_class 0x%02x\n", foh->obj_class);
804 nack = 1;
805 } else
806 DEBUGPC(DNM, "ACKing and Activating\n");
807
808 ret = abis_nm_sw_act_req_ack(mb->trx->bts, foh->obj_class,
Harald Welte34a99682009-02-13 02:41:40 +0000809 foh->obj_inst.bts_nr,
810 foh->obj_inst.trx_nr,
Harald Welte5c1e4582009-02-15 11:57:29 +0000811 foh->obj_inst.ts_nr, nack,
Harald Welte34a99682009-02-13 02:41:40 +0000812 foh->data, oh->length-sizeof(*foh));
813
Harald Welte5c1e4582009-02-15 11:57:29 +0000814 if (nack)
815 return ret;
816
Harald Welte34a99682009-02-13 02:41:40 +0000817 /* FIXME: properly parse attributes */
818 return ipacc_sw_activate(mb->trx->bts, foh->obj_class,
819 foh->obj_inst.bts_nr,
820 foh->obj_inst.trx_nr,
821 foh->obj_inst.ts_nr,
822 foh->data + oh->length-sizeof(*foh)-22, 22);
823}
824
Harald Weltee0590df2009-02-15 03:34:15 +0000825/* Receive a CHANGE_ADM_STATE_ACK, parse the TLV and update local state */
826static int abis_nm_rx_chg_adm_state_ack(struct msgb *mb)
827{
828 struct abis_om_hdr *oh = msgb_l2(mb);
829 struct abis_om_fom_hdr *foh = msgb_l3(mb);
830 struct tlv_parsed tp;
831 u_int8_t adm_state;
832
Harald Welte03133942009-02-18 19:51:53 +0000833 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Weltee0590df2009-02-15 03:34:15 +0000834 if (!TLVP_PRESENT(&tp, NM_ATT_ADM_STATE))
835 return -EINVAL;
836
837 adm_state = *TLVP_VAL(&tp, NM_ATT_ADM_STATE);
838
839 return update_admstate(mb->trx->bts, foh->obj_class, &foh->obj_inst, adm_state);
840}
841
Harald Welteee670472009-02-22 21:58:49 +0000842static int abis_nm_rx_lmt_event(struct msgb *mb)
843{
844 struct abis_om_hdr *oh = msgb_l2(mb);
845 struct abis_om_fom_hdr *foh = msgb_l3(mb);
846 struct tlv_parsed tp;
847
848 DEBUGP(DNM, "LMT Event ");
849 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
850 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_LOGON_SESSION) &&
851 TLVP_LEN(&tp, NM_ATT_BS11_LMT_LOGON_SESSION) >= 1) {
852 u_int8_t onoff = *TLVP_VAL(&tp, NM_ATT_BS11_LMT_LOGON_SESSION);
853 DEBUGPC(DNM, "LOG%s ", onoff ? "ON" : "OFF");
854 }
855 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV) &&
856 TLVP_LEN(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV) >= 1) {
857 u_int8_t level = *TLVP_VAL(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV);
858 DEBUGPC(DNM, "Level=%u ", level);
859 }
860 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_USER_NAME) &&
861 TLVP_LEN(&tp, NM_ATT_BS11_LMT_USER_NAME) >= 1) {
862 char *name = (char *) TLVP_VAL(&tp, NM_ATT_BS11_LMT_USER_NAME);
863 DEBUGPC(DNM, "Username=%s ", name);
864 }
865 DEBUGPC(DNM, "\n");
866 /* FIXME: parse LMT LOGON TIME */
867 return 0;
868}
869
Harald Welte52b1f982008-12-23 20:25:15 +0000870/* Receive a OML NM Message from BTS */
Harald Welte8470bf22008-12-25 23:28:35 +0000871static int abis_nm_rcvmsg_fom(struct msgb *mb)
Harald Welte52b1f982008-12-23 20:25:15 +0000872{
Harald Welte6c96ba52009-05-01 13:03:40 +0000873 struct abis_om_hdr *oh = msgb_l2(mb);
Harald Welte52b1f982008-12-23 20:25:15 +0000874 struct abis_om_fom_hdr *foh = msgb_l3(mb);
875 u_int8_t mt = foh->msg_type;
876
877 /* check for unsolicited message */
Harald Welte97ed1e72009-02-06 13:38:02 +0000878 if (is_report(mt))
879 return abis_nm_rcvmsg_report(mb);
Harald Welte52b1f982008-12-23 20:25:15 +0000880
Harald Welte4724f992009-01-18 18:01:49 +0000881 if (is_in_arr(mt, sw_load_msgs, ARRAY_SIZE(sw_load_msgs)))
882 return abis_nm_rcvmsg_sw(mb);
883
Harald Welte78fc0d42009-02-19 02:50:57 +0000884 if (is_in_arr(mt, nacks, ARRAY_SIZE(nacks))) {
Harald Welte6c96ba52009-05-01 13:03:40 +0000885 struct tlv_parsed tp;
Harald Welte78fc0d42009-02-19 02:50:57 +0000886 if (nack_names[mt])
Harald Welte6c96ba52009-05-01 13:03:40 +0000887 DEBUGP(DNM, "%s NACK ", nack_names[mt]);
888 /* FIXME: NACK cause */
Harald Welte78fc0d42009-02-19 02:50:57 +0000889 else
Harald Welte6c96ba52009-05-01 13:03:40 +0000890 DEBUGP(DNM, "NACK 0x%02x ", mt);
891
892 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
893 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
894 DEBUGPC(DNM, "CAUSE=%s\n",
895 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
896 else
897 DEBUGPC(DNM, "\n");
Holger Hans Peter Freyther500f3ca2009-06-10 10:48:14 +0200898
899 dispatch_signal(SS_NM, S_NM_NACK, (void*) ((long)mt));
900 return 0;
Harald Welte78fc0d42009-02-19 02:50:57 +0000901 }
Harald Weltead384642008-12-26 10:20:07 +0000902#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000903 /* check if last message is to be acked */
904 if (is_ack_nack(nmh->last_msgtype)) {
905 if (mt == MT_ACK(nmh->last_msgtype)) {
906 fprintf(stderr, "received ACK (0x%x)\n",
907 foh->msg_type);
908 /* we got our ACK, continue sending the next msg */
909 } else if (mt == MT_NACK(nmh->last_msgtype)) {
910 /* we got a NACK, signal this to the caller */
911 fprintf(stderr, "received NACK (0x%x)\n",
912 foh->msg_type);
913 /* FIXME: somehow signal this to the caller */
914 } else {
915 /* really strange things happen */
916 return -EINVAL;
917 }
918 }
Harald Weltead384642008-12-26 10:20:07 +0000919#endif
920
Harald Welte97ed1e72009-02-06 13:38:02 +0000921 switch (mt) {
Harald Weltee0590df2009-02-15 03:34:15 +0000922 case NM_MT_CHG_ADM_STATE_ACK:
923 return abis_nm_rx_chg_adm_state_ack(mb);
924 break;
Harald Welte34a99682009-02-13 02:41:40 +0000925 case NM_MT_SW_ACT_REQ:
926 return abis_nm_rx_sw_act_req(mb);
927 break;
Harald Welte97ed1e72009-02-06 13:38:02 +0000928 case NM_MT_BS11_LMT_SESSION:
Harald Welteee670472009-02-22 21:58:49 +0000929 return abis_nm_rx_lmt_event(mb);
Harald Welte97ed1e72009-02-06 13:38:02 +0000930 break;
931 }
932
Harald Weltead384642008-12-26 10:20:07 +0000933 return 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000934}
935
Harald Welte677c21f2009-02-17 13:22:23 +0000936static int abis_nm_rx_ipacc(struct msgb *mb);
937
938static int abis_nm_rcvmsg_manuf(struct msgb *mb)
939{
940 int rc;
941 int bts_type = mb->trx->bts->type;
942
943 switch (bts_type) {
944 case GSM_BTS_TYPE_NANOBTS_900:
945 case GSM_BTS_TYPE_NANOBTS_1800:
946 rc = abis_nm_rx_ipacc(mb);
947 break;
948 default:
949 fprintf(stderr, "don't know how to parse OML for this "
950 "BTS type (%u)\n", bts_type);
951 rc = 0;
952 break;
953 }
954
955 return rc;
956}
957
Harald Welte52b1f982008-12-23 20:25:15 +0000958/* High-Level API */
959/* Entry-point where L2 OML from BTS enters the NM code */
Harald Welte8470bf22008-12-25 23:28:35 +0000960int abis_nm_rcvmsg(struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +0000961{
Harald Welte52b1f982008-12-23 20:25:15 +0000962 struct abis_om_hdr *oh = msgb_l2(msg);
Harald Welte677c21f2009-02-17 13:22:23 +0000963 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000964
965 /* Various consistency checks */
966 if (oh->placement != ABIS_OM_PLACEMENT_ONLY) {
967 fprintf(stderr, "ABIS OML placement 0x%x not supported\n",
968 oh->placement);
969 return -EINVAL;
970 }
971 if (oh->sequence != 0) {
972 fprintf(stderr, "ABIS OML sequence 0x%x != 0x00\n",
973 oh->sequence);
974 return -EINVAL;
975 }
Harald Welte702d8702008-12-26 20:25:35 +0000976#if 0
Holger Freytherca362a62009-01-04 21:05:01 +0000977 unsigned int l2_len = msg->tail - (u_int8_t *)msgb_l2(msg);
978 unsigned int hlen = sizeof(*oh) + sizeof(struct abis_om_fom_hdr);
Harald Welte702d8702008-12-26 20:25:35 +0000979 if (oh->length + hlen > l2_len) {
Harald Welte52b1f982008-12-23 20:25:15 +0000980 fprintf(stderr, "ABIS OML truncated message (%u > %u)\n",
981 oh->length + sizeof(*oh), l2_len);
982 return -EINVAL;
983 }
Harald Welte702d8702008-12-26 20:25:35 +0000984 if (oh->length + hlen < l2_len)
985 fprintf(stderr, "ABIS OML message with extra trailer?!? (oh->len=%d, sizeof_oh=%d l2_len=%d\n", oh->length, sizeof(*oh), l2_len);
986#endif
Harald Weltead384642008-12-26 10:20:07 +0000987 msg->l3h = (unsigned char *)oh + sizeof(*oh);
Harald Welte52b1f982008-12-23 20:25:15 +0000988
989 switch (oh->mdisc) {
990 case ABIS_OM_MDISC_FOM:
Harald Welte8470bf22008-12-25 23:28:35 +0000991 rc = abis_nm_rcvmsg_fom(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000992 break;
Harald Welte677c21f2009-02-17 13:22:23 +0000993 case ABIS_OM_MDISC_MANUF:
994 rc = abis_nm_rcvmsg_manuf(msg);
995 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000996 case ABIS_OM_MDISC_MMI:
997 case ABIS_OM_MDISC_TRAU:
Harald Welte677c21f2009-02-17 13:22:23 +0000998 fprintf(stderr, "unimplemented ABIS OML message discriminator 0x%x\n",
999 oh->mdisc);
1000 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001001 default:
1002 fprintf(stderr, "unknown ABIS OML message discriminator 0x%x\n",
1003 oh->mdisc);
1004 return -EINVAL;
1005 }
1006
Harald Weltead384642008-12-26 10:20:07 +00001007 msgb_free(msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001008 return rc;
1009}
1010
1011#if 0
1012/* initialized all resources */
1013struct abis_nm_h *abis_nm_init(struct abis_nm_cfg *cfg)
1014{
1015 struct abis_nm_h *nmh;
1016
1017 nmh = malloc(sizeof(*nmh));
1018 if (!nmh)
1019 return NULL;
1020
1021 nmh->cfg = cfg;
1022
1023 return nmh;
1024}
1025
1026/* free all resources */
1027void abis_nm_fini(struct abis_nm_h *nmh)
1028{
1029 free(nmh);
1030}
1031#endif
1032
1033/* Here we are trying to define a high-level API that can be used by
1034 * the actual BSC implementation. However, the architecture is currently
1035 * still under design. Ideally the calls to this API would be synchronous,
1036 * while the underlying stack behind the APi runs in a traditional select
1037 * based state machine.
1038 */
1039
Harald Welte4724f992009-01-18 18:01:49 +00001040/* 6.2 Software Load: */
1041enum sw_state {
1042 SW_STATE_NONE,
1043 SW_STATE_WAIT_INITACK,
1044 SW_STATE_WAIT_SEGACK,
1045 SW_STATE_WAIT_ENDACK,
1046 SW_STATE_WAIT_ACTACK,
1047 SW_STATE_ERROR,
1048};
Harald Welte52b1f982008-12-23 20:25:15 +00001049
Harald Welte52b1f982008-12-23 20:25:15 +00001050struct abis_nm_sw {
Harald Welte4724f992009-01-18 18:01:49 +00001051 struct gsm_bts *bts;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001052 gsm_cbfn *cbfn;
1053 void *cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +00001054 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001055
Harald Welte52b1f982008-12-23 20:25:15 +00001056 /* this will become part of the SW LOAD INITIATE */
1057 u_int8_t obj_class;
1058 u_int8_t obj_instance[3];
Harald Welte4724f992009-01-18 18:01:49 +00001059
1060 u_int8_t file_id[255];
1061 u_int8_t file_id_len;
1062
1063 u_int8_t file_version[255];
1064 u_int8_t file_version_len;
1065
1066 u_int8_t window_size;
1067 u_int8_t seg_in_window;
1068
1069 int fd;
1070 FILE *stream;
1071 enum sw_state state;
Harald Welte1602ade2009-01-29 21:12:39 +00001072 int last_seg;
Harald Welte52b1f982008-12-23 20:25:15 +00001073};
1074
Harald Welte4724f992009-01-18 18:01:49 +00001075static struct abis_nm_sw g_sw;
1076
1077/* 6.2.1 / 8.3.1: Load Data Initiate */
1078static int sw_load_init(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +00001079{
Harald Welte4724f992009-01-18 18:01:49 +00001080 struct abis_om_hdr *oh;
1081 struct msgb *msg = nm_msgb_alloc();
1082 u_int8_t len = 3*2 + sw->file_id_len + sw->file_version_len;
1083
1084 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1085 fill_om_fom_hdr(oh, len, NM_MT_LOAD_INIT, sw->obj_class,
1086 sw->obj_instance[0], sw->obj_instance[1],
1087 sw->obj_instance[2]);
1088
1089 /* FIXME: this is BS11 specific format */
1090 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1091 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1092 sw->file_version);
1093 msgb_tv_put(msg, NM_ATT_WINDOW_SIZE, sw->window_size);
1094
1095 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001096}
1097
Harald Welte1602ade2009-01-29 21:12:39 +00001098static int is_last_line(FILE *stream)
1099{
1100 char next_seg_buf[256];
1101 long pos;
1102
1103 /* check if we're sending the last line */
1104 pos = ftell(stream);
1105 if (!fgets(next_seg_buf, sizeof(next_seg_buf)-2, stream)) {
1106 fseek(stream, pos, SEEK_SET);
1107 return 1;
1108 }
1109
1110 fseek(stream, pos, SEEK_SET);
1111 return 0;
1112}
1113
Harald Welte4724f992009-01-18 18:01:49 +00001114/* 6.2.2 / 8.3.2 Load Data Segment */
1115static int sw_load_segment(struct abis_nm_sw *sw)
1116{
1117 struct abis_om_hdr *oh;
1118 struct msgb *msg = nm_msgb_alloc();
1119 char seg_buf[256];
1120 char *line_buf = seg_buf+2;
Harald Welte3b8ba212009-01-29 12:27:58 +00001121 unsigned char *tlv;
Harald Welte4724f992009-01-18 18:01:49 +00001122 u_int8_t len;
Harald Welte4724f992009-01-18 18:01:49 +00001123
1124 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte3b8ba212009-01-29 12:27:58 +00001125
1126 switch (sw->bts->type) {
1127 case GSM_BTS_TYPE_BS11:
1128 if (fgets(line_buf, sizeof(seg_buf)-2, sw->stream) == NULL) {
1129 perror("fgets reading segment");
1130 return -EINVAL;
1131 }
1132 seg_buf[0] = 0x00;
Harald Welte1602ade2009-01-29 21:12:39 +00001133
1134 /* check if we're sending the last line */
1135 sw->last_seg = is_last_line(sw->stream);
1136 if (sw->last_seg)
1137 seg_buf[1] = 0;
1138 else
1139 seg_buf[1] = 1 + sw->seg_in_window++;
Harald Welte3b8ba212009-01-29 12:27:58 +00001140
1141 len = strlen(line_buf) + 2;
1142 tlv = msgb_put(msg, TLV_GROSS_LEN(len));
1143 tlv_put(tlv, NM_ATT_BS11_FILE_DATA, len, (u_int8_t *)seg_buf);
1144 /* BS11 wants CR + LF in excess of the TLV length !?! */
1145 tlv[1] -= 2;
1146
1147 /* we only now know the exact length for the OM hdr */
1148 len = strlen(line_buf)+2;
1149 break;
1150 default:
1151 /* FIXME: Other BTS types */
1152 return -1;
Harald Welte4724f992009-01-18 18:01:49 +00001153 }
Harald Welte4724f992009-01-18 18:01:49 +00001154
Harald Welte4724f992009-01-18 18:01:49 +00001155 fill_om_fom_hdr(oh, len, NM_MT_LOAD_SEG, sw->obj_class,
1156 sw->obj_instance[0], sw->obj_instance[1],
1157 sw->obj_instance[2]);
1158
1159 return abis_nm_sendmsg(sw->bts, msg);
1160}
1161
1162/* 6.2.4 / 8.3.4 Load Data End */
1163static int sw_load_end(struct abis_nm_sw *sw)
1164{
1165 struct abis_om_hdr *oh;
1166 struct msgb *msg = nm_msgb_alloc();
1167 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
1168
1169 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1170 fill_om_fom_hdr(oh, len, NM_MT_LOAD_END, sw->obj_class,
1171 sw->obj_instance[0], sw->obj_instance[1],
1172 sw->obj_instance[2]);
1173
1174 /* FIXME: this is BS11 specific format */
1175 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1176 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1177 sw->file_version);
1178
1179 return abis_nm_sendmsg(sw->bts, msg);
1180}
Harald Welte5e4d1b32009-02-01 13:36:56 +00001181
Harald Welte52b1f982008-12-23 20:25:15 +00001182/* Activate the specified software into the BTS */
Harald Welte4724f992009-01-18 18:01:49 +00001183static int sw_activate(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +00001184{
Harald Welte4724f992009-01-18 18:01:49 +00001185 struct abis_om_hdr *oh;
1186 struct msgb *msg = nm_msgb_alloc();
1187 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
Harald Welte52b1f982008-12-23 20:25:15 +00001188
Harald Welte4724f992009-01-18 18:01:49 +00001189 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1190 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, sw->obj_class,
1191 sw->obj_instance[0], sw->obj_instance[1],
1192 sw->obj_instance[2]);
1193
1194 /* FIXME: this is BS11 specific format */
1195 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1196 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1197 sw->file_version);
1198
1199 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001200}
Harald Welte4724f992009-01-18 18:01:49 +00001201
1202static int sw_open_file(struct abis_nm_sw *sw, const char *fname)
1203{
1204 char file_id[12+1];
1205 char file_version[80+1];
1206 int rc;
1207
1208 sw->fd = open(fname, O_RDONLY);
1209 if (sw->fd < 0)
1210 return sw->fd;
1211
1212 switch (sw->bts->type) {
1213 case GSM_BTS_TYPE_BS11:
1214 sw->stream = fdopen(sw->fd, "r");
1215 if (!sw->stream) {
1216 perror("fdopen");
1217 return -1;
1218 }
1219 /* read first line and parse file ID and VERSION */
Harald Welte3b8ba212009-01-29 12:27:58 +00001220 rc = fscanf(sw->stream, "@(#)%12s:%80s\r\n",
Harald Welte4724f992009-01-18 18:01:49 +00001221 file_id, file_version);
1222 if (rc != 2) {
1223 perror("parsing header line of software file");
1224 return -1;
1225 }
1226 strcpy((char *)sw->file_id, file_id);
1227 sw->file_id_len = strlen(file_id);
1228 strcpy((char *)sw->file_version, file_version);
1229 sw->file_version_len = strlen(file_version);
1230 /* rewind to start of file */
Harald Welte3b8ba212009-01-29 12:27:58 +00001231 rewind(sw->stream);
Harald Welte4724f992009-01-18 18:01:49 +00001232 break;
1233 default:
1234 /* We don't know how to treat them yet */
1235 close(sw->fd);
1236 return -EINVAL;
1237 }
1238
1239 return 0;
1240}
1241
1242static void sw_close_file(struct abis_nm_sw *sw)
1243{
1244 switch (sw->bts->type) {
1245 case GSM_BTS_TYPE_BS11:
1246 fclose(sw->stream);
1247 break;
1248 default:
1249 close(sw->fd);
1250 break;
1251 }
1252}
1253
1254/* Fill the window */
1255static int sw_fill_window(struct abis_nm_sw *sw)
1256{
1257 int rc;
1258
1259 while (sw->seg_in_window < sw->window_size) {
1260 rc = sw_load_segment(sw);
1261 if (rc < 0)
1262 return rc;
Harald Welte1602ade2009-01-29 21:12:39 +00001263 if (sw->last_seg)
1264 break;
Harald Welte4724f992009-01-18 18:01:49 +00001265 }
1266 return 0;
1267}
1268
1269/* callback function from abis_nm_rcvmsg() handler */
1270static int abis_nm_rcvmsg_sw(struct msgb *mb)
1271{
1272 struct abis_om_fom_hdr *foh = msgb_l3(mb);
1273 int rc = -1;
1274 struct abis_nm_sw *sw = &g_sw;
1275 enum sw_state old_state = sw->state;
1276
Harald Welte3ffd1372009-02-01 22:15:49 +00001277 //DEBUGP(DNM, "state %u, NM MT 0x%02x\n", sw->state, foh->msg_type);
Harald Welte4724f992009-01-18 18:01:49 +00001278
1279 switch (sw->state) {
1280 case SW_STATE_WAIT_INITACK:
1281 switch (foh->msg_type) {
1282 case NM_MT_LOAD_INIT_ACK:
1283 /* fill window with segments */
Harald Welte5e4d1b32009-02-01 13:36:56 +00001284 if (sw->cbfn)
1285 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1286 NM_MT_LOAD_INIT_ACK, mb,
1287 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001288 rc = sw_fill_window(sw);
1289 sw->state = SW_STATE_WAIT_SEGACK;
1290 break;
1291 case NM_MT_LOAD_INIT_NACK:
Harald Welte3ffd1372009-02-01 22:15:49 +00001292 if (sw->forced) {
1293 DEBUGP(DNM, "FORCED: Ignoring Software Load "
1294 "Init NACK\n");
1295 if (sw->cbfn)
1296 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1297 NM_MT_LOAD_INIT_ACK, mb,
1298 sw->cb_data, NULL);
1299 rc = sw_fill_window(sw);
1300 sw->state = SW_STATE_WAIT_SEGACK;
1301 } else {
1302 DEBUGP(DNM, "Software Load Init NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001303 /* FIXME: cause */
Harald Welte3ffd1372009-02-01 22:15:49 +00001304 if (sw->cbfn)
1305 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1306 NM_MT_LOAD_INIT_NACK, mb,
1307 sw->cb_data, NULL);
1308 sw->state = SW_STATE_ERROR;
1309 }
Harald Welte4724f992009-01-18 18:01:49 +00001310 break;
1311 }
1312 break;
1313 case SW_STATE_WAIT_SEGACK:
1314 switch (foh->msg_type) {
1315 case NM_MT_LOAD_SEG_ACK:
Harald Welte3ffd1372009-02-01 22:15:49 +00001316 if (sw->cbfn)
1317 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1318 NM_MT_LOAD_SEG_ACK, mb,
1319 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001320 sw->seg_in_window = 0;
Harald Welte1602ade2009-01-29 21:12:39 +00001321 if (!sw->last_seg) {
1322 /* fill window with more segments */
1323 rc = sw_fill_window(sw);
1324 sw->state = SW_STATE_WAIT_SEGACK;
1325 } else {
1326 /* end the transfer */
1327 sw->state = SW_STATE_WAIT_ENDACK;
1328 rc = sw_load_end(sw);
1329 }
Harald Welte4724f992009-01-18 18:01:49 +00001330 break;
1331 }
1332 break;
1333 case SW_STATE_WAIT_ENDACK:
1334 switch (foh->msg_type) {
1335 case NM_MT_LOAD_END_ACK:
1336 sw_close_file(sw);
Harald Welte5e4d1b32009-02-01 13:36:56 +00001337 DEBUGP(DNM, "Software Load End (BTS %u)\n",
1338 sw->bts->nr);
1339 sw->state = SW_STATE_NONE;
1340 if (sw->cbfn)
1341 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1342 NM_MT_LOAD_END_ACK, mb,
1343 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001344 break;
1345 case NM_MT_LOAD_END_NACK:
Holger Freyther31338a12009-02-06 17:43:50 +00001346 if (sw->forced) {
1347 DEBUGP(DNM, "FORCED: Ignoring Software Load"
1348 "End NACK\n");
1349 sw->state = SW_STATE_NONE;
1350 if (sw->cbfn)
1351 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1352 NM_MT_LOAD_END_ACK, mb,
1353 sw->cb_data, NULL);
1354 } else {
1355 DEBUGP(DNM, "Software Load End NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001356 /* FIXME: cause */
Holger Freyther31338a12009-02-06 17:43:50 +00001357 sw->state = SW_STATE_ERROR;
1358 if (sw->cbfn)
1359 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1360 NM_MT_LOAD_END_NACK, mb,
1361 sw->cb_data, NULL);
1362 }
Harald Welte4724f992009-01-18 18:01:49 +00001363 break;
1364 }
1365 case SW_STATE_WAIT_ACTACK:
1366 switch (foh->msg_type) {
1367 case NM_MT_ACTIVATE_SW_ACK:
1368 /* we're done */
Harald Welte5e4d1b32009-02-01 13:36:56 +00001369 DEBUGP(DNM, "Activate Software DONE!\n");
Harald Welte4724f992009-01-18 18:01:49 +00001370 sw->state = SW_STATE_NONE;
1371 rc = 0;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001372 if (sw->cbfn)
1373 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1374 NM_MT_ACTIVATE_SW_ACK, mb,
1375 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001376 break;
1377 case NM_MT_ACTIVATE_SW_NACK:
Harald Welte1602ade2009-01-29 21:12:39 +00001378 DEBUGP(DNM, "Activate Software NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001379 /* FIXME: cause */
Harald Welte4724f992009-01-18 18:01:49 +00001380 sw->state = SW_STATE_ERROR;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001381 if (sw->cbfn)
1382 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1383 NM_MT_ACTIVATE_SW_NACK, mb,
1384 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001385 break;
1386 }
1387 case SW_STATE_NONE:
Harald Weltea994a482009-05-01 15:54:23 +00001388 switch (foh->msg_type) {
1389 case NM_MT_ACTIVATE_SW_ACK:
1390 rc = 0;
1391 break;
1392 }
1393 break;
Harald Welte4724f992009-01-18 18:01:49 +00001394 case SW_STATE_ERROR:
1395 break;
1396 }
1397
1398 if (rc)
Harald Weltea994a482009-05-01 15:54:23 +00001399 DEBUGP(DNM, "unexpected NM MT 0x%02x in state %u -> %u\n",
Harald Welte4724f992009-01-18 18:01:49 +00001400 foh->msg_type, old_state, sw->state);
1401
1402 return rc;
1403}
1404
1405/* Load the specified software into the BTS */
1406int abis_nm_software_load(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00001407 u_int8_t win_size, int forced,
1408 gsm_cbfn *cbfn, void *cb_data)
Harald Welte4724f992009-01-18 18:01:49 +00001409{
1410 struct abis_nm_sw *sw = &g_sw;
1411 int rc;
1412
Harald Welte5e4d1b32009-02-01 13:36:56 +00001413 DEBUGP(DNM, "Software Load (BTS %u, File \"%s\")\n",
1414 bts->nr, fname);
1415
Harald Welte4724f992009-01-18 18:01:49 +00001416 if (sw->state != SW_STATE_NONE)
1417 return -EBUSY;
1418
1419 sw->bts = bts;
1420 sw->obj_class = NM_OC_SITE_MANAGER;
1421 sw->obj_instance[0] = 0xff;
1422 sw->obj_instance[1] = 0xff;
1423 sw->obj_instance[2] = 0xff;
1424 sw->window_size = win_size;
1425 sw->state = SW_STATE_WAIT_INITACK;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001426 sw->cbfn = cbfn;
1427 sw->cb_data = cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +00001428 sw->forced = forced;
Harald Welte4724f992009-01-18 18:01:49 +00001429
1430 rc = sw_open_file(sw, fname);
1431 if (rc < 0) {
1432 sw->state = SW_STATE_NONE;
1433 return rc;
1434 }
1435
1436 return sw_load_init(sw);
1437}
Harald Welte52b1f982008-12-23 20:25:15 +00001438
Harald Welte1602ade2009-01-29 21:12:39 +00001439int abis_nm_software_load_status(struct gsm_bts *bts)
1440{
1441 struct abis_nm_sw *sw = &g_sw;
1442 struct stat st;
1443 int rc, percent;
1444
1445 rc = fstat(sw->fd, &st);
1446 if (rc < 0) {
1447 perror("ERROR during stat");
1448 return rc;
1449 }
1450
1451 percent = (ftell(sw->stream) * 100) / st.st_size;
1452 return percent;
1453}
1454
Harald Welte5e4d1b32009-02-01 13:36:56 +00001455/* Activate the specified software into the BTS */
1456int abis_nm_software_activate(struct gsm_bts *bts, const char *fname,
1457 gsm_cbfn *cbfn, void *cb_data)
1458{
1459 struct abis_nm_sw *sw = &g_sw;
1460 int rc;
1461
1462 DEBUGP(DNM, "Activating Software (BTS %u, File \"%s\")\n",
1463 bts->nr, fname);
1464
1465 if (sw->state != SW_STATE_NONE)
1466 return -EBUSY;
1467
1468 sw->bts = bts;
1469 sw->obj_class = NM_OC_SITE_MANAGER;
1470 sw->obj_instance[0] = 0xff;
1471 sw->obj_instance[1] = 0xff;
1472 sw->obj_instance[2] = 0xff;
1473 sw->state = SW_STATE_WAIT_ACTACK;
1474 sw->cbfn = cbfn;
1475 sw->cb_data = cb_data;
1476
1477 /* Open the file in order to fill some sw struct members */
1478 rc = sw_open_file(sw, fname);
1479 if (rc < 0) {
1480 sw->state = SW_STATE_NONE;
1481 return rc;
1482 }
1483 sw_close_file(sw);
1484
1485 return sw_activate(sw);
1486}
1487
Harald Welte8470bf22008-12-25 23:28:35 +00001488static void fill_nm_channel(struct abis_nm_channel *ch, u_int8_t bts_port,
Harald Welte52b1f982008-12-23 20:25:15 +00001489 u_int8_t ts_nr, u_int8_t subslot_nr)
1490{
Harald Welteadaf08b2009-01-18 11:08:10 +00001491 ch->attrib = NM_ATT_ABIS_CHANNEL;
Harald Welte52b1f982008-12-23 20:25:15 +00001492 ch->bts_port = bts_port;
1493 ch->timeslot = ts_nr;
1494 ch->subslot = subslot_nr;
1495}
1496
1497int abis_nm_establish_tei(struct gsm_bts *bts, u_int8_t trx_nr,
1498 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot,
1499 u_int8_t tei)
1500{
1501 struct abis_om_hdr *oh;
1502 struct abis_nm_channel *ch;
Harald Welte702d8702008-12-26 20:25:35 +00001503 u_int8_t len = sizeof(*ch) + 2;
Harald Welte8470bf22008-12-25 23:28:35 +00001504 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001505
1506 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1507 fill_om_fom_hdr(oh, len, NM_MT_ESTABLISH_TEI, NM_OC_RADIO_CARRIER,
1508 bts->bts_nr, trx_nr, 0xff);
1509
Harald Welte8470bf22008-12-25 23:28:35 +00001510 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte52b1f982008-12-23 20:25:15 +00001511
1512 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1513 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1514
1515 return abis_nm_sendmsg(bts, msg);
1516}
1517
1518/* connect signalling of one (BTS,TRX) to a particular timeslot on the E1 */
1519int abis_nm_conn_terr_sign(struct gsm_bts_trx *trx,
1520 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot)
1521{
Harald Welte8470bf22008-12-25 23:28:35 +00001522 struct gsm_bts *bts = trx->bts;
Harald Welte52b1f982008-12-23 20:25:15 +00001523 struct abis_om_hdr *oh;
1524 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +00001525 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001526
1527 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001528 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_SIGN,
Harald Welte52b1f982008-12-23 20:25:15 +00001529 NM_OC_RADIO_CARRIER, bts->bts_nr, trx->nr, 0xff);
1530
1531 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1532 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1533
1534 return abis_nm_sendmsg(bts, msg);
1535}
1536
1537#if 0
1538int abis_nm_disc_terr_sign(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1539 struct abis_nm_abis_channel *chan)
1540{
1541}
1542#endif
1543
1544int abis_nm_conn_terr_traf(struct gsm_bts_trx_ts *ts,
1545 u_int8_t e1_port, u_int8_t e1_timeslot,
1546 u_int8_t e1_subslot)
1547{
1548 struct gsm_bts *bts = ts->trx->bts;
1549 struct abis_om_hdr *oh;
1550 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +00001551 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001552
1553 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1554 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_TRAF,
Harald Welteb110cee2009-02-18 03:42:35 +00001555 NM_OC_CHANNEL, bts->bts_nr, ts->trx->nr, ts->nr);
Harald Welte52b1f982008-12-23 20:25:15 +00001556
1557 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1558 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1559
Harald Weltef325eb42009-02-19 17:07:39 +00001560 DEBUGP(DNM, "CONNECT TERR TRAF Um=%s E1=(%u,%u,%u)\n",
1561 gsm_ts_name(ts),
Harald Welteb110cee2009-02-18 03:42:35 +00001562 e1_port, e1_timeslot, e1_subslot);
1563
Harald Welte52b1f982008-12-23 20:25:15 +00001564 return abis_nm_sendmsg(bts, msg);
1565}
1566
1567#if 0
1568int abis_nm_disc_terr_traf(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1569 struct abis_nm_abis_channel *chan,
1570 u_int8_t subchan)
1571{
1572}
1573#endif
1574
Harald Welte22af0db2009-02-14 15:41:08 +00001575/* Chapter 8.6.1 */
1576int abis_nm_set_bts_attr(struct gsm_bts *bts, u_int8_t *attr, int attr_len)
1577{
1578 struct abis_om_hdr *oh;
1579 struct msgb *msg = nm_msgb_alloc();
1580 u_int8_t *cur;
1581
1582 DEBUGP(DNM, "Set BTS Attr (bts=%d)\n", bts->nr);
1583
1584 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte191280d2009-05-01 13:20:04 +00001585 fill_om_fom_hdr(oh, attr_len, NM_MT_SET_BTS_ATTR, NM_OC_BTS, bts->bts_nr, 0xff, 0xff);
Harald Welte22af0db2009-02-14 15:41:08 +00001586 cur = msgb_put(msg, attr_len);
1587 memcpy(cur, attr, attr_len);
1588
1589 return abis_nm_sendmsg(bts, msg);
1590}
1591
1592/* Chapter 8.6.2 */
1593int abis_nm_set_radio_attr(struct gsm_bts_trx *trx, u_int8_t *attr, int attr_len)
1594{
1595 struct abis_om_hdr *oh;
1596 struct msgb *msg = nm_msgb_alloc();
1597 u_int8_t *cur;
1598
1599 DEBUGP(DNM, "Set TRX Attr (bts=%d,trx=%d)\n", trx->bts->nr, trx->nr);
1600
1601 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1602 fill_om_fom_hdr(oh, attr_len, NM_MT_SET_RADIO_ATTR, NM_OC_RADIO_CARRIER,
Harald Welte191280d2009-05-01 13:20:04 +00001603 trx->bts->bts_nr, trx->nr, 0xff);
Harald Welte22af0db2009-02-14 15:41:08 +00001604 cur = msgb_put(msg, attr_len);
1605 memcpy(cur, attr, attr_len);
1606
1607 return abis_nm_sendmsg(trx->bts, msg);
1608}
1609
1610/* Chapter 8.6.3 */
Harald Welte52b1f982008-12-23 20:25:15 +00001611int abis_nm_set_channel_attr(struct gsm_bts_trx_ts *ts, u_int8_t chan_comb)
1612{
1613 struct gsm_bts *bts = ts->trx->bts;
1614 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001615 u_int16_t arfcn = htons(ts->trx->arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001616 u_int8_t zero = 0x00;
Harald Welte8470bf22008-12-25 23:28:35 +00001617 struct msgb *msg = nm_msgb_alloc();
Harald Weltee0590df2009-02-15 03:34:15 +00001618 u_int8_t len = 2 + 2;
1619
1620 if (bts->type == GSM_BTS_TYPE_BS11)
1621 len += 4 + 2 + 2 + 3;
Harald Welte52b1f982008-12-23 20:25:15 +00001622
Harald Weltef325eb42009-02-19 17:07:39 +00001623 DEBUGP(DNM, "Set Chan Attr %s\n", gsm_ts_name(ts));
Harald Welte22af0db2009-02-14 15:41:08 +00001624
Harald Welte52b1f982008-12-23 20:25:15 +00001625 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001626 fill_om_fom_hdr(oh, len, NM_MT_SET_CHAN_ATTR,
Holger Freyther6b2d2622009-02-14 23:16:59 +00001627 NM_OC_CHANNEL, bts->bts_nr,
Harald Welte52b1f982008-12-23 20:25:15 +00001628 ts->trx->nr, ts->nr);
1629 /* FIXME: don't send ARFCN list, hopping sequence, mAIO, ...*/
Harald Weltee0590df2009-02-15 03:34:15 +00001630 if (bts->type == GSM_BTS_TYPE_BS11)
1631 msgb_tlv16_put(msg, NM_ATT_ARFCN_LIST, 1, &arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001632 msgb_tv_put(msg, NM_ATT_CHAN_COMB, chan_comb);
Harald Weltee0590df2009-02-15 03:34:15 +00001633 if (bts->type == GSM_BTS_TYPE_BS11) {
1634 msgb_tv_put(msg, NM_ATT_HSN, 0x00);
1635 msgb_tv_put(msg, NM_ATT_MAIO, 0x00);
1636 }
Harald Welte52b1f982008-12-23 20:25:15 +00001637 msgb_tv_put(msg, NM_ATT_TSC, 0x07); /* training sequence */
Harald Weltee0590df2009-02-15 03:34:15 +00001638 if (bts->type == GSM_BTS_TYPE_BS11)
1639 msgb_tlv_put(msg, 0x59, 1, &zero);
Harald Welte52b1f982008-12-23 20:25:15 +00001640
1641 return abis_nm_sendmsg(bts, msg);
1642}
1643
Harald Welte34a99682009-02-13 02:41:40 +00001644int abis_nm_sw_act_req_ack(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i1,
Harald Welte5c1e4582009-02-15 11:57:29 +00001645 u_int8_t i2, u_int8_t i3, int nack, u_int8_t *attr, int att_len)
Harald Welte34a99682009-02-13 02:41:40 +00001646{
1647 struct abis_om_hdr *oh;
1648 struct msgb *msg = nm_msgb_alloc();
Harald Welte5c1e4582009-02-15 11:57:29 +00001649 u_int8_t msgtype = NM_MT_SW_ACT_REQ_ACK;
1650 u_int8_t len = att_len;
1651
1652 if (nack) {
1653 len += 2;
1654 msgtype = NM_MT_SW_ACT_REQ_NACK;
1655 }
Harald Welte34a99682009-02-13 02:41:40 +00001656
1657 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte5c1e4582009-02-15 11:57:29 +00001658 fill_om_fom_hdr(oh, att_len, msgtype, obj_class, i1, i2, i3);
1659
Harald Welte34a99682009-02-13 02:41:40 +00001660 if (attr) {
1661 u_int8_t *ptr = msgb_put(msg, att_len);
1662 memcpy(ptr, attr, att_len);
1663 }
Harald Welte5c1e4582009-02-15 11:57:29 +00001664 if (nack)
1665 msgb_tv_put(msg, NM_ATT_NACK_CAUSES, NM_NACK_OBJCLASS_NOTSUPP);
Harald Welte34a99682009-02-13 02:41:40 +00001666
1667 return abis_nm_sendmsg(bts, msg);
1668}
1669
Harald Welte8470bf22008-12-25 23:28:35 +00001670int abis_nm_raw_msg(struct gsm_bts *bts, int len, u_int8_t *rawmsg)
Harald Welte52b1f982008-12-23 20:25:15 +00001671{
Harald Welte8470bf22008-12-25 23:28:35 +00001672 struct msgb *msg = nm_msgb_alloc();
1673 struct abis_om_hdr *oh;
Harald Welte52b1f982008-12-23 20:25:15 +00001674 u_int8_t *data;
1675
1676 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
1677 fill_om_hdr(oh, len);
1678 data = msgb_put(msg, len);
Harald Weltead384642008-12-26 10:20:07 +00001679 memcpy(data, rawmsg, len);
Harald Welte52b1f982008-12-23 20:25:15 +00001680
1681 return abis_nm_sendmsg(bts, msg);
1682}
1683
1684/* Siemens specific commands */
1685static int __simple_cmd(struct gsm_bts *bts, u_int8_t msg_type)
1686{
1687 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001688 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001689
1690 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001691 fill_om_fom_hdr(oh, 0, msg_type, NM_OC_SITE_MANAGER,
Harald Welte52b1f982008-12-23 20:25:15 +00001692 0xff, 0xff, 0xff);
1693
1694 return abis_nm_sendmsg(bts, msg);
1695}
1696
Harald Welte34a99682009-02-13 02:41:40 +00001697/* Chapter 8.9.2 */
1698int abis_nm_opstart(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1, u_int8_t i2)
1699{
1700 struct abis_om_hdr *oh;
1701 struct msgb *msg = nm_msgb_alloc();
1702
Harald Welte22af0db2009-02-14 15:41:08 +00001703 DEBUGP(DNM, "Sending OPSTART obj_class=0x%02x obj_inst=(0x%02x, 0x%02x, 0x%02x)\n",
1704 obj_class, i0, i1, i2);
Harald Welte34a99682009-02-13 02:41:40 +00001705 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1706 fill_om_fom_hdr(oh, 0, NM_MT_OPSTART, obj_class, i0, i1, i2);
1707
1708 return abis_nm_sendmsg(bts, msg);
1709}
1710
1711/* Chapter 8.8.5 */
1712int abis_nm_chg_adm_state(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0,
1713 u_int8_t i1, u_int8_t i2, u_int8_t adm_state)
1714{
1715 struct abis_om_hdr *oh;
1716 struct msgb *msg = nm_msgb_alloc();
1717
1718 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1719 fill_om_fom_hdr(oh, 2, NM_MT_CHG_ADM_STATE, obj_class, i0, i1, i2);
1720 msgb_tv_put(msg, NM_ATT_ADM_STATE, adm_state);
1721
1722 return abis_nm_sendmsg(bts, msg);
1723}
1724
1725
Harald Welte52b1f982008-12-23 20:25:15 +00001726int abis_nm_event_reports(struct gsm_bts *bts, int on)
1727{
1728 if (on == 0)
Harald Welte227d4072009-01-03 08:16:25 +00001729 return __simple_cmd(bts, NM_MT_STOP_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001730 else
Harald Welte227d4072009-01-03 08:16:25 +00001731 return __simple_cmd(bts, NM_MT_REST_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001732}
1733
Harald Welte47d88ae2009-01-04 12:02:08 +00001734/* Siemens (or BS-11) specific commands */
1735
Harald Welte3ffd1372009-02-01 22:15:49 +00001736int abis_nm_bs11_bsc_disconnect(struct gsm_bts *bts, int reconnect)
1737{
1738 if (reconnect == 0)
1739 return __simple_cmd(bts, NM_MT_BS11_DISCONNECT);
1740 else
1741 return __simple_cmd(bts, NM_MT_BS11_RECONNECT);
1742}
1743
Harald Welteb8427972009-02-05 19:27:17 +00001744int abis_nm_bs11_restart(struct gsm_bts *bts)
1745{
1746 return __simple_cmd(bts, NM_MT_BS11_RESTART);
1747}
1748
1749
Harald Welte268bb402009-02-01 19:11:56 +00001750struct bs11_date_time {
1751 u_int16_t year;
1752 u_int8_t month;
1753 u_int8_t day;
1754 u_int8_t hour;
1755 u_int8_t min;
1756 u_int8_t sec;
1757} __attribute__((packed));
1758
1759
1760void get_bs11_date_time(struct bs11_date_time *aet)
1761{
1762 time_t t;
1763 struct tm *tm;
1764
1765 t = time(NULL);
1766 tm = localtime(&t);
1767 aet->sec = tm->tm_sec;
1768 aet->min = tm->tm_min;
1769 aet->hour = tm->tm_hour;
1770 aet->day = tm->tm_mday;
1771 aet->month = tm->tm_mon;
1772 aet->year = htons(1900 + tm->tm_year);
1773}
1774
Harald Welte05188ee2009-01-18 11:39:08 +00001775int abis_nm_bs11_reset_resource(struct gsm_bts *bts)
Harald Welte52b1f982008-12-23 20:25:15 +00001776{
Harald Welte4668fda2009-01-03 08:19:29 +00001777 return __simple_cmd(bts, NM_MT_BS11_RESET_RESOURCE);
Harald Welte52b1f982008-12-23 20:25:15 +00001778}
1779
Harald Welte05188ee2009-01-18 11:39:08 +00001780int abis_nm_bs11_db_transmission(struct gsm_bts *bts, int begin)
Harald Welte52b1f982008-12-23 20:25:15 +00001781{
1782 if (begin)
Harald Welte4668fda2009-01-03 08:19:29 +00001783 return __simple_cmd(bts, NM_MT_BS11_BEGIN_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00001784 else
Harald Welte4668fda2009-01-03 08:19:29 +00001785 return __simple_cmd(bts, NM_MT_BS11_END_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00001786}
Harald Welte47d88ae2009-01-04 12:02:08 +00001787
Harald Welte05188ee2009-01-18 11:39:08 +00001788int abis_nm_bs11_create_object(struct gsm_bts *bts,
Harald Welte1bc09062009-01-18 14:17:52 +00001789 enum abis_bs11_objtype type, u_int8_t idx,
1790 u_int8_t attr_len, const u_int8_t *attr)
Harald Welte47d88ae2009-01-04 12:02:08 +00001791{
1792 struct abis_om_hdr *oh;
1793 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00001794 u_int8_t *cur;
Harald Welte47d88ae2009-01-04 12:02:08 +00001795
1796 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001797 fill_om_fom_hdr(oh, attr_len, NM_MT_BS11_CREATE_OBJ,
Harald Welte268bb402009-02-01 19:11:56 +00001798 NM_OC_BS11, type, 0, idx);
Harald Welte1bc09062009-01-18 14:17:52 +00001799 cur = msgb_put(msg, attr_len);
1800 memcpy(cur, attr, attr_len);
Harald Welte47d88ae2009-01-04 12:02:08 +00001801
1802 return abis_nm_sendmsg(bts, msg);
1803}
1804
Harald Welte78fc0d42009-02-19 02:50:57 +00001805int abis_nm_bs11_delete_object(struct gsm_bts *bts,
1806 enum abis_bs11_objtype type, u_int8_t idx)
1807{
1808 struct abis_om_hdr *oh;
1809 struct msgb *msg = nm_msgb_alloc();
1810
1811 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1812 fill_om_fom_hdr(oh, 0, NM_MT_BS11_DELETE_OBJ,
1813 NM_OC_BS11, type, 0, idx);
1814
1815 return abis_nm_sendmsg(bts, msg);
1816}
1817
Harald Welte05188ee2009-01-18 11:39:08 +00001818int abis_nm_bs11_create_envaBTSE(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00001819{
1820 struct abis_om_hdr *oh;
1821 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00001822 u_int8_t zero = 0x00;
Harald Welte47d88ae2009-01-04 12:02:08 +00001823
1824 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001825 fill_om_fom_hdr(oh, 3, NM_MT_BS11_CREATE_OBJ,
Harald Welte1bc09062009-01-18 14:17:52 +00001826 NM_OC_BS11_ENVABTSE, 0, idx, 0xff);
1827 msgb_tlv_put(msg, 0x99, 1, &zero);
Harald Welte47d88ae2009-01-04 12:02:08 +00001828
1829 return abis_nm_sendmsg(bts, msg);
1830}
1831
Harald Welte05188ee2009-01-18 11:39:08 +00001832int abis_nm_bs11_create_bport(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00001833{
1834 struct abis_om_hdr *oh;
1835 struct msgb *msg = nm_msgb_alloc();
1836
1837 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1838 fill_om_fom_hdr(oh, 0, NM_MT_BS11_CREATE_OBJ, NM_OC_BS11_BPORT,
1839 idx, 0, 0);
1840
1841 return abis_nm_sendmsg(bts, msg);
1842}
Harald Welte05188ee2009-01-18 11:39:08 +00001843
Harald Welte78fc0d42009-02-19 02:50:57 +00001844static const u_int8_t sm_attr[] = { NM_ATT_TEI, NM_ATT_ABIS_CHANNEL };
1845int abis_nm_bs11_get_oml_tei_ts(struct gsm_bts *bts)
1846{
1847 struct abis_om_hdr *oh;
1848 struct msgb *msg = nm_msgb_alloc();
1849
1850 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1851 fill_om_fom_hdr(oh, 2+sizeof(sm_attr), NM_MT_GET_ATTR, NM_OC_SITE_MANAGER,
1852 0xff, 0xff, 0xff);
1853 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(sm_attr), sm_attr);
1854
1855 return abis_nm_sendmsg(bts, msg);
1856}
1857
Harald Welteb6c92ae2009-02-21 20:15:32 +00001858/* like abis_nm_conn_terr_traf + set_tei */
1859int abis_nm_bs11_conn_oml_tei(struct gsm_bts *bts, u_int8_t e1_port,
1860 u_int8_t e1_timeslot, u_int8_t e1_subslot,
1861 u_int8_t tei)
Harald Welte05188ee2009-01-18 11:39:08 +00001862{
1863 struct abis_om_hdr *oh;
1864 struct abis_nm_channel *ch;
1865 struct msgb *msg = nm_msgb_alloc();
1866
1867 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welteb6c92ae2009-02-21 20:15:32 +00001868 fill_om_fom_hdr(oh, sizeof(*ch)+2, NM_MT_BS11_SET_ATTR,
Harald Welte05188ee2009-01-18 11:39:08 +00001869 NM_OC_SITE_MANAGER, 0xff, 0xff, 0xff);
1870
1871 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1872 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
Harald Welteb6c92ae2009-02-21 20:15:32 +00001873 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte05188ee2009-01-18 11:39:08 +00001874
1875 return abis_nm_sendmsg(bts, msg);
1876}
1877
1878int abis_nm_bs11_set_trx_power(struct gsm_bts_trx *trx, u_int8_t level)
1879{
1880 struct abis_om_hdr *oh;
1881 struct msgb *msg = nm_msgb_alloc();
Harald Welte05188ee2009-01-18 11:39:08 +00001882
1883 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001884 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR,
Harald Welte05188ee2009-01-18 11:39:08 +00001885 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
1886 msgb_tlv_put(msg, NM_ATT_BS11_TXPWR, 1, &level);
1887
1888 return abis_nm_sendmsg(trx->bts, msg);
1889}
1890
Harald Welte78fc0d42009-02-19 02:50:57 +00001891int abis_nm_bs11_get_trx_power(struct gsm_bts_trx *trx)
1892{
1893 struct abis_om_hdr *oh;
1894 struct msgb *msg = nm_msgb_alloc();
1895 u_int8_t attr = NM_ATT_BS11_TXPWR;
1896
1897 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1898 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
1899 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
1900 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), &attr);
1901
1902 return abis_nm_sendmsg(trx->bts, msg);
1903}
1904
Harald Welteaaf02d92009-04-29 13:25:57 +00001905int abis_nm_bs11_get_pll_mode(struct gsm_bts *bts)
1906{
1907 struct abis_om_hdr *oh;
1908 struct msgb *msg = nm_msgb_alloc();
Harald Weltea7cfa032009-04-29 22:33:02 +00001909 u_int8_t attr[] = { NM_ATT_BS11_PLL_MODE };
Harald Welteaaf02d92009-04-29 13:25:57 +00001910
1911 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1912 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
1913 NM_OC_BS11, BS11_OBJ_LI, 0x00, 0x00);
Harald Welteaeedeb42009-05-01 13:08:14 +00001914 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), attr);
Harald Welteaaf02d92009-04-29 13:25:57 +00001915
1916 return abis_nm_sendmsg(bts, msg);
1917}
1918
Harald Welteef061952009-05-17 12:43:42 +00001919int abis_nm_bs11_get_cclk(struct gsm_bts *bts)
1920{
1921 struct abis_om_hdr *oh;
1922 struct msgb *msg = nm_msgb_alloc();
1923 u_int8_t attr[] = { NM_ATT_BS11_CCLK_ACCURACY,
1924 NM_ATT_BS11_CCLK_TYPE };
1925
1926 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1927 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
1928 NM_OC_BS11, BS11_OBJ_CCLK, 0x00, 0x00);
1929 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), attr);
1930
1931 return abis_nm_sendmsg(bts, msg);
1932
1933}
Harald Welteaaf02d92009-04-29 13:25:57 +00001934
Harald Welte268bb402009-02-01 19:11:56 +00001935//static const u_int8_t bs11_logon_c7[] = { 0x07, 0xd9, 0x01, 0x11, 0x0d, 0x10, 0x20 };
Harald Weltebb151312009-01-28 20:42:07 +00001936static const u_int8_t bs11_logon_c8[] = { 0x02 };
Harald Welte05188ee2009-01-18 11:39:08 +00001937static const u_int8_t bs11_logon_c9[] = "FACTORY";
1938
Harald Welte1bc09062009-01-18 14:17:52 +00001939int abis_nm_bs11_factory_logon(struct gsm_bts *bts, int on)
Harald Welte05188ee2009-01-18 11:39:08 +00001940{
1941 struct abis_om_hdr *oh;
1942 struct msgb *msg = nm_msgb_alloc();
Harald Welte268bb402009-02-01 19:11:56 +00001943 struct bs11_date_time bdt;
1944
1945 get_bs11_date_time(&bdt);
Harald Welte05188ee2009-01-18 11:39:08 +00001946
1947 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte1bc09062009-01-18 14:17:52 +00001948 if (on) {
Harald Welte268bb402009-02-01 19:11:56 +00001949 u_int8_t len = 3*2 + sizeof(bdt)
Harald Welte6f676a32009-01-18 14:27:48 +00001950 + sizeof(bs11_logon_c8) + sizeof(bs11_logon_c9);
Harald Welte043d04a2009-01-29 23:15:30 +00001951 fill_om_fom_hdr(oh, len, NM_MT_BS11_LMT_LOGON,
Harald Welte7b26bcb2009-05-28 11:39:21 +00001952 NM_OC_BS11_BTSE, 0xff, 0xff, 0xff);
Harald Welte043d04a2009-01-29 23:15:30 +00001953 msgb_tlv_put(msg, NM_ATT_BS11_LMT_LOGIN_TIME,
Harald Welte5083b0b2009-02-02 19:20:52 +00001954 sizeof(bdt), (u_int8_t *) &bdt);
Harald Welte043d04a2009-01-29 23:15:30 +00001955 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_ACC_LEV,
1956 sizeof(bs11_logon_c8), bs11_logon_c8);
1957 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_NAME,
1958 sizeof(bs11_logon_c9), bs11_logon_c9);
Harald Welte1bc09062009-01-18 14:17:52 +00001959 } else {
Harald Welte5e4d1b32009-02-01 13:36:56 +00001960 fill_om_fom_hdr(oh, 0, NM_MT_BS11_LMT_LOGOFF,
Harald Welte7b26bcb2009-05-28 11:39:21 +00001961 NM_OC_BS11_BTSE, 0xff, 0xff, 0xff);
Harald Welte1bc09062009-01-18 14:17:52 +00001962 }
Harald Welte05188ee2009-01-18 11:39:08 +00001963
1964 return abis_nm_sendmsg(bts, msg);
1965}
Harald Welte1bc09062009-01-18 14:17:52 +00001966
1967int abis_nm_bs11_set_trx1_pw(struct gsm_bts *bts, const char *password)
1968{
1969 struct abis_om_hdr *oh;
1970 struct msgb *msg;
1971
1972 if (strlen(password) != 10)
1973 return -EINVAL;
1974
1975 msg = nm_msgb_alloc();
1976 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001977 fill_om_fom_hdr(oh, 2+strlen(password), NM_MT_BS11_SET_ATTR,
Harald Welte1bc09062009-01-18 14:17:52 +00001978 NM_OC_BS11, BS11_OBJ_TRX1, 0x00, 0x00);
1979 msgb_tlv_put(msg, NM_ATT_BS11_PASSWORD, 10, (const u_int8_t *)password);
1980
1981 return abis_nm_sendmsg(bts, msg);
1982}
1983
Harald Weltee69f5fb2009-04-28 16:31:38 +00001984/* change the BS-11 PLL Mode to either locked (E1 derived) or standalone */
1985int abis_nm_bs11_set_pll_locked(struct gsm_bts *bts, int locked)
1986{
1987 struct abis_om_hdr *oh;
1988 struct msgb *msg;
Harald Weltea432cd32009-04-29 13:01:50 +00001989 u_int8_t tlv_value;
Harald Weltee69f5fb2009-04-28 16:31:38 +00001990
1991 msg = nm_msgb_alloc();
1992 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1993 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR, NM_OC_BS11,
1994 BS11_OBJ_LI, 0x00, 0x00);
Harald Weltea432cd32009-04-29 13:01:50 +00001995
1996 if (locked)
1997 tlv_value = BS11_LI_PLL_LOCKED;
1998 else
1999 tlv_value = BS11_LI_PLL_STANDALONE;
2000
2001 msgb_tlv_put(msg, NM_ATT_BS11_PLL_MODE, 1, &tlv_value);
Harald Weltee69f5fb2009-04-28 16:31:38 +00002002
2003 return abis_nm_sendmsg(bts, msg);
2004}
2005
Harald Welte1bc09062009-01-18 14:17:52 +00002006int abis_nm_bs11_get_state(struct gsm_bts *bts)
2007{
2008 return __simple_cmd(bts, NM_MT_BS11_GET_STATE);
2009}
Harald Welte5e4d1b32009-02-01 13:36:56 +00002010
2011/* BS11 SWL */
2012
Harald Welte2cf161b2009-06-20 22:36:41 +02002013static void *tall_fle_ctx;
2014
Harald Welte5e4d1b32009-02-01 13:36:56 +00002015struct abis_nm_bs11_sw {
2016 struct gsm_bts *bts;
2017 char swl_fname[PATH_MAX];
2018 u_int8_t win_size;
Harald Welte3ffd1372009-02-01 22:15:49 +00002019 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00002020 struct llist_head file_list;
2021 gsm_cbfn *user_cb; /* specified by the user */
2022};
2023static struct abis_nm_bs11_sw _g_bs11_sw, *g_bs11_sw = &_g_bs11_sw;
2024
2025struct file_list_entry {
2026 struct llist_head list;
2027 char fname[PATH_MAX];
2028};
2029
2030struct file_list_entry *fl_dequeue(struct llist_head *queue)
2031{
2032 struct llist_head *lh;
2033
2034 if (llist_empty(queue))
2035 return NULL;
2036
2037 lh = queue->next;
2038 llist_del(lh);
2039
2040 return llist_entry(lh, struct file_list_entry, list);
2041}
2042
2043static int bs11_read_swl_file(struct abis_nm_bs11_sw *bs11_sw)
2044{
2045 char linebuf[255];
2046 struct llist_head *lh, *lh2;
2047 FILE *swl;
2048 int rc = 0;
2049
Harald Welte2cf161b2009-06-20 22:36:41 +02002050 if (!tall_fle_ctx)
2051 tall_fle_ctx = talloc_named_const(tall_bsc_ctx, 1,
2052 "bs11_file_list_entry");
2053
Harald Welte5e4d1b32009-02-01 13:36:56 +00002054 swl = fopen(bs11_sw->swl_fname, "r");
2055 if (!swl)
2056 return -ENODEV;
2057
2058 /* zero the stale file list, if any */
2059 llist_for_each_safe(lh, lh2, &bs11_sw->file_list) {
2060 llist_del(lh);
Harald Welte2cf161b2009-06-20 22:36:41 +02002061 talloc_free(lh);
Harald Welte5e4d1b32009-02-01 13:36:56 +00002062 }
2063
2064 while (fgets(linebuf, sizeof(linebuf), swl)) {
2065 char file_id[12+1];
2066 char file_version[80+1];
2067 struct file_list_entry *fle;
2068 static char dir[PATH_MAX];
2069
2070 if (strlen(linebuf) < 4)
2071 continue;
Harald Welte3ffd1372009-02-01 22:15:49 +00002072
Harald Welte5e4d1b32009-02-01 13:36:56 +00002073 rc = sscanf(linebuf+4, "%12s:%80s\r\n", file_id, file_version);
2074 if (rc < 0) {
2075 perror("ERR parsing SWL file");
2076 rc = -EINVAL;
2077 goto out;
2078 }
2079 if (rc < 2)
2080 continue;
2081
Harald Welte2cf161b2009-06-20 22:36:41 +02002082 fle = talloc(tall_fle_ctx, struct file_list_entry);
Harald Welte5e4d1b32009-02-01 13:36:56 +00002083 if (!fle) {
2084 rc = -ENOMEM;
2085 goto out;
2086 }
2087 memset(fle, 0, sizeof(*fle));
2088
2089 /* construct new filename */
2090 strncpy(dir, bs11_sw->swl_fname, sizeof(dir));
2091 strncat(fle->fname, dirname(dir), sizeof(fle->fname) - 1);
2092 strcat(fle->fname, "/");
2093 strncat(fle->fname, file_id, sizeof(fle->fname) - 1 -strlen(fle->fname));
Harald Welte5e4d1b32009-02-01 13:36:56 +00002094
2095 llist_add_tail(&fle->list, &bs11_sw->file_list);
2096 }
2097
2098out:
2099 fclose(swl);
2100 return rc;
2101}
2102
2103/* bs11 swload specific callback, passed to abis_nm core swload */
2104static int bs11_swload_cbfn(unsigned int hook, unsigned int event,
2105 struct msgb *msg, void *data, void *param)
2106{
2107 struct abis_nm_bs11_sw *bs11_sw = data;
2108 struct file_list_entry *fle;
2109 int rc = 0;
2110
Harald Welte5e4d1b32009-02-01 13:36:56 +00002111 switch (event) {
2112 case NM_MT_LOAD_END_ACK:
2113 fle = fl_dequeue(&bs11_sw->file_list);
2114 if (fle) {
2115 /* start download the next file of our file list */
2116 rc = abis_nm_software_load(bs11_sw->bts, fle->fname,
2117 bs11_sw->win_size,
Harald Welte3ffd1372009-02-01 22:15:49 +00002118 bs11_sw->forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00002119 &bs11_swload_cbfn, bs11_sw);
2120 free(fle);
2121 } else {
2122 /* activate the SWL */
2123 rc = abis_nm_software_activate(bs11_sw->bts,
2124 bs11_sw->swl_fname,
2125 bs11_swload_cbfn,
2126 bs11_sw);
2127 }
2128 break;
Harald Welte3ffd1372009-02-01 22:15:49 +00002129 case NM_MT_LOAD_SEG_ACK:
Harald Welte5e4d1b32009-02-01 13:36:56 +00002130 case NM_MT_LOAD_END_NACK:
2131 case NM_MT_LOAD_INIT_ACK:
2132 case NM_MT_LOAD_INIT_NACK:
2133 case NM_MT_ACTIVATE_SW_NACK:
2134 case NM_MT_ACTIVATE_SW_ACK:
2135 default:
2136 /* fallthrough to the user callback */
Harald Welte97ed1e72009-02-06 13:38:02 +00002137 if (bs11_sw->user_cb)
2138 rc = bs11_sw->user_cb(hook, event, msg, NULL, NULL);
Harald Welte5e4d1b32009-02-01 13:36:56 +00002139 break;
2140 }
2141
2142 return rc;
2143}
2144
2145/* Siemens provides a SWL file that is a mere listing of all the other
2146 * files that are part of a software release. We need to upload first
2147 * the list file, and then each file that is listed in the list file */
2148int abis_nm_bs11_load_swl(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00002149 u_int8_t win_size, int forced, gsm_cbfn *cbfn)
Harald Welte5e4d1b32009-02-01 13:36:56 +00002150{
2151 struct abis_nm_bs11_sw *bs11_sw = g_bs11_sw;
2152 struct file_list_entry *fle;
2153 int rc = 0;
2154
2155 INIT_LLIST_HEAD(&bs11_sw->file_list);
2156 bs11_sw->bts = bts;
2157 bs11_sw->win_size = win_size;
2158 bs11_sw->user_cb = cbfn;
Harald Welte3ffd1372009-02-01 22:15:49 +00002159 bs11_sw->forced = forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00002160
2161 strncpy(bs11_sw->swl_fname, fname, sizeof(bs11_sw->swl_fname));
2162 rc = bs11_read_swl_file(bs11_sw);
2163 if (rc < 0)
2164 return rc;
2165
2166 /* dequeue next item in file list */
2167 fle = fl_dequeue(&bs11_sw->file_list);
2168 if (!fle)
2169 return -EINVAL;
2170
2171 /* start download the next file of our file list */
Harald Welte3ffd1372009-02-01 22:15:49 +00002172 rc = abis_nm_software_load(bts, fle->fname, win_size, forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00002173 bs11_swload_cbfn, bs11_sw);
2174 free(fle);
2175 return rc;
2176}
2177
Harald Welte5083b0b2009-02-02 19:20:52 +00002178#if 0
Harald Welte5e4d1b32009-02-01 13:36:56 +00002179static u_int8_t req_attr_btse[] = {
2180 NM_ATT_ADM_STATE, NM_ATT_BS11_LMT_LOGON_SESSION,
2181 NM_ATT_BS11_LMT_LOGIN_TIME, NM_ATT_BS11_LMT_USER_ACC_LEV,
2182 NM_ATT_BS11_LMT_USER_NAME,
2183
2184 0xaf, NM_ATT_BS11_RX_OFFSET, NM_ATT_BS11_VENDOR_NAME,
2185
2186 NM_ATT_BS11_SW_LOAD_INTENDED, NM_ATT_BS11_SW_LOAD_SAFETY,
2187
2188 NM_ATT_BS11_SW_LOAD_STORED };
2189
2190static u_int8_t req_attr_btsm[] = {
2191 NM_ATT_ABIS_CHANNEL, NM_ATT_TEI, NM_ATT_BS11_ABIS_EXT_TIME,
2192 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xce, NM_ATT_FILE_ID,
2193 NM_ATT_FILE_VERSION, NM_ATT_OPER_STATE, 0xe8, NM_ATT_BS11_ALL_TEST_CATG,
2194 NM_ATT_SW_DESCR, NM_ATT_GET_ARI };
Harald Welte5083b0b2009-02-02 19:20:52 +00002195#endif
Harald Welte5e4d1b32009-02-01 13:36:56 +00002196
2197static u_int8_t req_attr[] = {
2198 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xa8, NM_ATT_OPER_STATE,
2199 0xd5, 0xa1, NM_ATT_BS11_ESN_FW_CODE_NO, NM_ATT_BS11_ESN_HW_CODE_NO,
Harald Weltea7cfa032009-04-29 22:33:02 +00002200 0x42, NM_ATT_BS11_ESN_PCB_SERIAL, NM_ATT_BS11_PLL };
Harald Welte5e4d1b32009-02-01 13:36:56 +00002201
2202int abis_nm_bs11_get_serno(struct gsm_bts *bts)
2203{
2204 struct abis_om_hdr *oh;
2205 struct msgb *msg = nm_msgb_alloc();
2206
2207 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2208 /* SiemensHW CCTRL object */
2209 fill_om_fom_hdr(oh, 2+sizeof(req_attr), NM_MT_GET_ATTR, NM_OC_BS11,
2210 0x03, 0x00, 0x00);
2211 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(req_attr), req_attr);
2212
2213 return abis_nm_sendmsg(bts, msg);
2214}
Harald Welte268bb402009-02-01 19:11:56 +00002215
2216int abis_nm_bs11_set_ext_time(struct gsm_bts *bts)
2217{
2218 struct abis_om_hdr *oh;
2219 struct msgb *msg = nm_msgb_alloc();
2220 struct bs11_date_time aet;
2221
2222 get_bs11_date_time(&aet);
2223 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2224 /* SiemensHW CCTRL object */
2225 fill_om_fom_hdr(oh, 2+sizeof(aet), NM_MT_BS11_SET_ATTR, NM_OC_SITE_MANAGER,
2226 0xff, 0xff, 0xff);
Harald Welte5083b0b2009-02-02 19:20:52 +00002227 msgb_tlv_put(msg, NM_ATT_BS11_ABIS_EXT_TIME, sizeof(aet), (u_int8_t *) &aet);
Harald Welte268bb402009-02-01 19:11:56 +00002228
2229 return abis_nm_sendmsg(bts, msg);
2230}
Harald Welte5c1e4582009-02-15 11:57:29 +00002231
2232/* ip.access nanoBTS specific commands */
Harald Welte5c1e4582009-02-15 11:57:29 +00002233static const char ipaccess_magic[] = "com.ipaccess";
2234
Harald Welte677c21f2009-02-17 13:22:23 +00002235
2236static int abis_nm_rx_ipacc(struct msgb *msg)
2237{
2238 struct abis_om_hdr *oh = msgb_l2(msg);
2239 struct abis_om_fom_hdr *foh;
2240 u_int8_t idstrlen = oh->data[0];
2241 struct tlv_parsed tp;
2242
2243 if (strncmp((char *)&oh->data[1], ipaccess_magic, idstrlen)) {
2244 DEBUGP(DNM, "id string is not com.ipaccess !?!\n");
2245 return -EINVAL;
2246 }
2247
Harald Welte193fefc2009-04-30 15:16:27 +00002248 foh = (struct abis_om_fom_hdr *) (oh->data + 1 + idstrlen);
Harald Welte03133942009-02-18 19:51:53 +00002249 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Welte677c21f2009-02-17 13:22:23 +00002250
Harald Welte193fefc2009-04-30 15:16:27 +00002251 DEBUGP(DNM, "IPACCESS(0x%02x): ", foh->msg_type);
2252
Harald Welte677c21f2009-02-17 13:22:23 +00002253 switch (foh->msg_type) {
2254 case NM_MT_IPACC_RSL_CONNECT_ACK:
Harald Welte193fefc2009-04-30 15:16:27 +00002255 DEBUGPC(DNM, "RSL CONNECT ACK ");
Harald Welte677c21f2009-02-17 13:22:23 +00002256 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_RSL_BSC_IP))
Harald Welte9de2bf82009-04-30 15:59:55 +00002257 DEBUGPC(DNM, "IP=%s ",
Harald Welte677c21f2009-02-17 13:22:23 +00002258 inet_ntoa(*((struct in_addr *)
2259 TLVP_VAL(&tp, NM_ATT_IPACC_RSL_BSC_IP))));
2260 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_RSL_BSC_PORT))
Harald Welte9de2bf82009-04-30 15:59:55 +00002261 DEBUGPC(DNM, "PORT=%u ",
Harald Welte677c21f2009-02-17 13:22:23 +00002262 ntohs(*((u_int16_t *)
2263 TLVP_VAL(&tp, NM_ATT_IPACC_RSL_BSC_PORT))));
Harald Welte9de2bf82009-04-30 15:59:55 +00002264 DEBUGPC(DNM, "\n");
Harald Welte677c21f2009-02-17 13:22:23 +00002265 break;
2266 case NM_MT_IPACC_RSL_CONNECT_NACK:
Harald Welte193fefc2009-04-30 15:16:27 +00002267 DEBUGPC(DNM, "RSL CONNECT NACK ");
Harald Welte677c21f2009-02-17 13:22:23 +00002268 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
Harald Welte6c96ba52009-05-01 13:03:40 +00002269 DEBUGPC(DNM, " CAUSE=%s\n",
2270 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
Harald Welte677c21f2009-02-17 13:22:23 +00002271 else
2272 DEBUGPC(DNM, "\n");
2273 break;
Harald Welte193fefc2009-04-30 15:16:27 +00002274 case NM_MT_IPACC_SET_NVATTR_ACK:
2275 DEBUGPC(DNM, "SET NVATTR ACK\n");
2276 /* FIXME: decode and show the actual attributes */
2277 break;
2278 case NM_MT_IPACC_SET_NVATTR_NACK:
Harald Welte6c96ba52009-05-01 13:03:40 +00002279 DEBUGPC(DNM, "SET NVATTR NACK ");
2280 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
2281 DEBUGPC(DNM, " CAUSE=%s\n",
2282 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
2283 else
2284 DEBUGPC(DNM, "\n");
Harald Welte193fefc2009-04-30 15:16:27 +00002285 break;
2286 default:
2287 DEBUGPC(DNM, "unknown\n");
2288 break;
Harald Welte677c21f2009-02-17 13:22:23 +00002289 }
2290 return 0;
2291}
2292
Harald Welte193fefc2009-04-30 15:16:27 +00002293/* send an ip-access manufacturer specific message */
Harald Welte5c1e4582009-02-15 11:57:29 +00002294int abis_nm_ipaccess_msg(struct gsm_bts *bts, u_int8_t msg_type,
2295 u_int8_t obj_class, u_int8_t bts_nr,
2296 u_int8_t trx_nr, u_int8_t ts_nr,
2297 u_int8_t *attr, int attr_len)
2298{
2299 struct msgb *msg = nm_msgb_alloc();
2300 struct abis_om_hdr *oh;
2301 struct abis_om_fom_hdr *foh;
2302 u_int8_t *data;
2303
2304 /* construct the 12.21 OM header, observe the erroneous length */
2305 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
2306 fill_om_hdr(oh, sizeof(*foh) + attr_len);
2307 oh->mdisc = ABIS_OM_MDISC_MANUF;
2308
2309 /* add the ip.access magic */
2310 data = msgb_put(msg, sizeof(ipaccess_magic)+1);
2311 *data++ = sizeof(ipaccess_magic);
2312 memcpy(data, ipaccess_magic, sizeof(ipaccess_magic));
2313
2314 /* fill the 12.21 FOM header */
2315 foh = (struct abis_om_fom_hdr *) msgb_put(msg, sizeof(*foh));
2316 foh->msg_type = msg_type;
2317 foh->obj_class = obj_class;
2318 foh->obj_inst.bts_nr = bts_nr;
2319 foh->obj_inst.trx_nr = trx_nr;
2320 foh->obj_inst.ts_nr = ts_nr;
2321
2322 if (attr && attr_len) {
2323 data = msgb_put(msg, attr_len);
2324 memcpy(data, attr, attr_len);
2325 }
2326
2327 return abis_nm_sendmsg(bts, msg);
2328}
Harald Welte677c21f2009-02-17 13:22:23 +00002329
Harald Welte193fefc2009-04-30 15:16:27 +00002330/* set some attributes in NVRAM */
2331int abis_nm_ipaccess_set_nvattr(struct gsm_bts *bts, u_int8_t *attr,
2332 int attr_len)
2333{
2334 return abis_nm_ipaccess_msg(bts, NM_MT_IPACC_SET_NVATTR,
2335 NM_OC_BASEB_TRANSC, 0, 0, 0xff, attr,
2336 attr_len);
2337}
2338
2339/* restart / reboot an ip.access nanoBTS */
2340int abis_nm_ipaccess_restart(struct gsm_bts *bts)
2341{
2342 return __simple_cmd(bts, NM_MT_IPACC_RESTART);
2343}