blob: 5040541e0860188c3e8522ee7267d29d4361ea29 [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",
182 [MN_NACK_FILE_NOTACTIVATE] = "File cannot be activate",
183 [NM_NACK_REQ_NOT_GRANT] = "Request not granted",
184 [NM_NACK_WAIT] = "Wait",
185 [NM_NACK_NOTH_REPORT_EXIST] = "Nothing reportable existing",
186 [NM_NACK_MEAS_NOTSUPP] = "Measurement not supported",
187 [NM_NACK_MEAS_NOTSTART] = "Measurement not started",
188};
189
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{
426 return msgb_alloc_headroom(OM_ALLOC_SIZE, OM_HEADROOM_SIZE);
427}
428
Harald Welte52b1f982008-12-23 20:25:15 +0000429/* Send a OML NM Message from BSC to BTS */
430int abis_nm_sendmsg(struct gsm_bts *bts, struct msgb *msg)
431{
Holger Freyther59639e82009-02-09 23:09:55 +0000432 msg->trx = bts->c0;
433
Harald Weltead384642008-12-26 10:20:07 +0000434 return _abis_nm_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000435}
436
Harald Welte4724f992009-01-18 18:01:49 +0000437static int abis_nm_rcvmsg_sw(struct msgb *mb);
438
Harald Welte34a99682009-02-13 02:41:40 +0000439static const char *obj_class_name(u_int8_t oc)
440{
Harald Welte7b26bcb2009-05-28 11:39:21 +0000441 switch (oc) {
442 case NM_OC_SITE_MANAGER:
443 return "SITE MANAGER";
444 case NM_OC_BTS:
445 return "BTS";
446 case NM_OC_RADIO_CARRIER:
447 return "RADIO CARRIER";
448 case NM_OC_BASEB_TRANSC:
449 return "BASEBAND TRANSCEIVER";
450 case NM_OC_CHANNEL:
Harald Weltebd8f7e32009-06-09 20:17:12 +0000451 return "CHANNEL";
Harald Welte7b26bcb2009-05-28 11:39:21 +0000452 case NM_OC_BS11_ADJC:
453 return "ADJC";
454 case NM_OC_BS11_HANDOVER:
455 return "HANDOVER";
456 case NM_OC_BS11_PWR_CTRL:
457 return "POWER CONTROL";
458 case NM_OC_BS11_BTSE:
459 return "BTSE";
460 case NM_OC_BS11_RACK:
461 return "RACK";
462 case NM_OC_BS11_TEST:
463 return "TEST";
464 case NM_OC_BS11_ENVABTSE:
465 return "ENVABTSE";
466 case NM_OC_BS11_BPORT:
467 return "BPORT";
468 case NM_OC_GPRS_NSE:
469 return "GPRS NSE";
470 case NM_OC_GPRS_CELL:
471 return "GPRS CELL";
472 case NM_OC_GPRS_NSVC0:
473 return "GPRS NSVC0";
474 case NM_OC_GPRS_NSVC1:
475 return "GPRS NSVC1";
Harald Welte8b697c72009-06-05 19:18:45 +0000476 case NM_OC_BS11:
477 return "SIEMENSHW";
Harald Welte7b26bcb2009-05-28 11:39:21 +0000478 }
479
480 return "UNKNOWN";
Harald Welte34a99682009-02-13 02:41:40 +0000481}
482
Harald Welte4d87f242009-03-10 19:43:44 +0000483const char *nm_opstate_name(u_int8_t os)
Harald Welte34a99682009-02-13 02:41:40 +0000484{
485 switch (os) {
486 case 1:
487 return "Disabled";
488 case 2:
489 return "Enabled";
490 case 0xff:
491 return "NULL";
492 default:
493 return "RFU";
494 }
495}
496
Harald Weltee0590df2009-02-15 03:34:15 +0000497/* Chapter 9.4.7 */
Harald Welte4d87f242009-03-10 19:43:44 +0000498static const char *avail_names[] = {
Harald Weltee0590df2009-02-15 03:34:15 +0000499 "In test",
500 "Failed",
501 "Power off",
502 "Off line",
503 "<not used>",
504 "Dependency",
505 "Degraded",
506 "Not installed",
507};
508
Harald Welte4d87f242009-03-10 19:43:44 +0000509const char *nm_avail_name(u_int8_t avail)
Harald Weltee0590df2009-02-15 03:34:15 +0000510{
Harald Welte0b8348d2009-02-18 03:43:01 +0000511 if (avail == 0xff)
512 return "OK";
Harald Weltee0590df2009-02-15 03:34:15 +0000513 if (avail >= ARRAY_SIZE(avail_names))
514 return "UNKNOWN";
515 return avail_names[avail];
516}
Harald Welte7b26bcb2009-05-28 11:39:21 +0000517
518const char *nm_adm_name(u_int8_t adm)
519{
520 switch (adm) {
521 case 1:
522 return "Locked";
523 case 2:
524 return "Unlocked";
525 case 3:
526 return "Shutdown";
527 default:
528 return "<not used>";
529 }
530}
Harald Weltee0590df2009-02-15 03:34:15 +0000531
532/* obtain the gsm_nm_state data structure for a given object instance */
533static struct gsm_nm_state *
534objclass2nmstate(struct gsm_bts *bts, u_int8_t obj_class,
535 struct abis_om_obj_inst *obj_inst)
536{
537 struct gsm_bts_trx *trx;
538 struct gsm_nm_state *nm_state = NULL;
539
540 switch (obj_class) {
541 case NM_OC_BTS:
542 nm_state = &bts->nm_state;
543 break;
544 case NM_OC_RADIO_CARRIER:
545 if (obj_inst->trx_nr >= bts->num_trx)
546 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200547 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000548 nm_state = &trx->nm_state;
549 break;
550 case NM_OC_BASEB_TRANSC:
551 if (obj_inst->trx_nr >= bts->num_trx)
552 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200553 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000554 nm_state = &trx->bb_transc.nm_state;
555 break;
556 case NM_OC_CHANNEL:
557 if (obj_inst->trx_nr > bts->num_trx)
558 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200559 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000560 if (obj_inst->ts_nr >= TRX_NR_TS)
561 return NULL;
562 nm_state = &trx->ts[obj_inst->ts_nr].nm_state;
563 break;
564 case NM_OC_SITE_MANAGER:
565 nm_state = &bts->site_mgr.nm_state;
566 break;
Harald Welte7b26bcb2009-05-28 11:39:21 +0000567 case NM_OC_BS11:
568 switch (obj_inst->bts_nr) {
569 case BS11_OBJ_CCLK:
570 nm_state = &bts->bs11.cclk.nm_state;
571 break;
Harald Welte8b697c72009-06-05 19:18:45 +0000572 case BS11_OBJ_BBSIG:
573 if (obj_inst->ts_nr > bts->num_trx)
574 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200575 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Welte8b697c72009-06-05 19:18:45 +0000576 nm_state = &trx->bs11.bbsig.nm_state;
577 break;
578 case BS11_OBJ_PA:
579 if (obj_inst->ts_nr > bts->num_trx)
580 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200581 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Welte8b697c72009-06-05 19:18:45 +0000582 nm_state = &trx->bs11.pa.nm_state;
583 break;
Harald Welte7b26bcb2009-05-28 11:39:21 +0000584 default:
585 return NULL;
586 }
587 case NM_OC_BS11_RACK:
588 nm_state = &bts->bs11.rack.nm_state;
589 break;
Harald Welte8b697c72009-06-05 19:18:45 +0000590 case NM_OC_BS11_ENVABTSE:
591 if (obj_inst->trx_nr > ARRAY_SIZE(bts->bs11.envabtse))
592 return NULL;
593 nm_state = &bts->bs11.envabtse[obj_inst->trx_nr].nm_state;
594 break;
Harald Weltee0590df2009-02-15 03:34:15 +0000595 }
596 return nm_state;
597}
598
599/* obtain the in-memory data structure of a given object instance */
600static void *
601objclass2obj(struct gsm_bts *bts, u_int8_t obj_class,
602 struct abis_om_obj_inst *obj_inst)
603{
604 struct gsm_bts_trx *trx;
605 void *obj = NULL;
606
607 switch (obj_class) {
608 case NM_OC_BTS:
609 obj = bts;
610 break;
611 case NM_OC_RADIO_CARRIER:
612 if (obj_inst->trx_nr >= bts->num_trx)
613 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200614 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000615 obj = trx;
616 break;
617 case NM_OC_BASEB_TRANSC:
618 if (obj_inst->trx_nr >= bts->num_trx)
619 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200620 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000621 obj = &trx->bb_transc;
622 break;
623 case NM_OC_CHANNEL:
624 if (obj_inst->trx_nr > bts->num_trx)
625 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200626 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000627 if (obj_inst->ts_nr >= TRX_NR_TS)
628 return NULL;
629 obj = &trx->ts[obj_inst->ts_nr];
630 break;
631 case NM_OC_SITE_MANAGER:
632 obj = &bts->site_mgr;
633 break;
634 }
635 return obj;
636}
637
638/* Update the administrative state of a given object in our in-memory data
639 * structures and send an event to the higher layer */
640static int update_admstate(struct gsm_bts *bts, u_int8_t obj_class,
641 struct abis_om_obj_inst *obj_inst, u_int8_t adm_state)
642{
Harald Welteaeedeb42009-05-01 13:08:14 +0000643 struct gsm_nm_state *nm_state, new_state;
Harald Weltee0590df2009-02-15 03:34:15 +0000644 void *obj;
645 int rc;
646
Harald Weltee0590df2009-02-15 03:34:15 +0000647 obj = objclass2obj(bts, obj_class, obj_inst);
Harald Welteaeedeb42009-05-01 13:08:14 +0000648 nm_state = objclass2nmstate(bts, obj_class, obj_inst);
649 if (!nm_state)
650 return -1;
651
652 new_state = *nm_state;
653 new_state.administrative = adm_state;
654
655 rc = nm_state_event(EVT_STATECHG_ADM, obj_class, obj, nm_state, &new_state);
656
657 nm_state->administrative = adm_state;
Harald Weltee0590df2009-02-15 03:34:15 +0000658
659 return rc;
660}
661
Harald Welte97ed1e72009-02-06 13:38:02 +0000662static int abis_nm_rx_statechg_rep(struct msgb *mb)
663{
Harald Weltee0590df2009-02-15 03:34:15 +0000664 struct abis_om_hdr *oh = msgb_l2(mb);
Harald Welte97ed1e72009-02-06 13:38:02 +0000665 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Harald Welte22af0db2009-02-14 15:41:08 +0000666 struct gsm_bts *bts = mb->trx->bts;
Harald Weltee0590df2009-02-15 03:34:15 +0000667 struct tlv_parsed tp;
668 struct gsm_nm_state *nm_state, new_state;
669 int rc;
670
Harald Welte23897662009-05-01 14:52:51 +0000671 DEBUGPC(DNM, "STATE CHG: ");
Harald Weltee0590df2009-02-15 03:34:15 +0000672
Harald Welte8b697c72009-06-05 19:18:45 +0000673 memset(&new_state, 0, sizeof(new_state));
674
Harald Weltee0590df2009-02-15 03:34:15 +0000675 nm_state = objclass2nmstate(bts, foh->obj_class, &foh->obj_inst);
676 if (!nm_state) {
677 DEBUGPC(DNM, "\n");
678 return -EINVAL;
Harald Welte22af0db2009-02-14 15:41:08 +0000679 }
Harald Weltee0590df2009-02-15 03:34:15 +0000680
681 new_state = *nm_state;
682
Harald Welte03133942009-02-18 19:51:53 +0000683 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Weltee0590df2009-02-15 03:34:15 +0000684 if (TLVP_PRESENT(&tp, NM_ATT_OPER_STATE)) {
685 new_state.operational = *TLVP_VAL(&tp, NM_ATT_OPER_STATE);
Harald Welte4d87f242009-03-10 19:43:44 +0000686 DEBUGPC(DNM, "OP_STATE=%s ", nm_opstate_name(new_state.operational));
Harald Weltee0590df2009-02-15 03:34:15 +0000687 }
688 if (TLVP_PRESENT(&tp, NM_ATT_AVAIL_STATUS)) {
Harald Welte0b8348d2009-02-18 03:43:01 +0000689 if (TLVP_LEN(&tp, NM_ATT_AVAIL_STATUS) == 0)
690 new_state.availability = 0xff;
691 else
692 new_state.availability = *TLVP_VAL(&tp, NM_ATT_AVAIL_STATUS);
Harald Welte4d87f242009-03-10 19:43:44 +0000693 DEBUGPC(DNM, "AVAIL=%s(%02x) ", nm_avail_name(new_state.availability),
Harald Weltee0590df2009-02-15 03:34:15 +0000694 new_state.availability);
695 }
696 if (TLVP_PRESENT(&tp, NM_ATT_ADM_STATE)) {
697 new_state.administrative = *TLVP_VAL(&tp, NM_ATT_ADM_STATE);
Harald Welte5d4b1c22009-06-12 01:34:29 +0800698 DEBUGPC(DNM, "ADM=%02s ", nm_adm_name(new_state.administrative));
Harald Welte97ed1e72009-02-06 13:38:02 +0000699 }
700 DEBUGPC(DNM, "\n");
Harald Weltee0590df2009-02-15 03:34:15 +0000701
702 if (memcmp(&new_state, nm_state, sizeof(new_state))) {
703 /* Update the operational state of a given object in our in-memory data
704 * structures and send an event to the higher layer */
705 void *obj = objclass2obj(bts, foh->obj_class, &foh->obj_inst);
706 rc = nm_state_event(EVT_STATECHG_OPER, foh->obj_class, obj, nm_state, &new_state);
707 *nm_state = new_state;
708 }
709#if 0
Harald Welte22af0db2009-02-14 15:41:08 +0000710 if (op_state == 1) {
711 /* try to enable objects that are disabled */
712 abis_nm_opstart(bts, foh->obj_class,
713 foh->obj_inst.bts_nr,
714 foh->obj_inst.trx_nr,
715 foh->obj_inst.ts_nr);
716 }
Harald Weltee0590df2009-02-15 03:34:15 +0000717#endif
Harald Welte97ed1e72009-02-06 13:38:02 +0000718 return 0;
719}
720
Harald Welte0db97b22009-05-01 17:22:47 +0000721static int rx_fail_evt_rep(struct msgb *mb)
722{
723 struct abis_om_hdr *oh = msgb_l2(mb);
724 struct abis_om_fom_hdr *foh = msgb_l3(mb);
725 struct tlv_parsed tp;
726
727 DEBUGPC(DNM, "Failure Event Report ");
728
729 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
730
731 if (TLVP_PRESENT(&tp, NM_ATT_EVENT_TYPE))
732 DEBUGPC(DNM, "Type=%s ", event_type_name(*TLVP_VAL(&tp, NM_ATT_EVENT_TYPE)));
733 if (TLVP_PRESENT(&tp, NM_ATT_SEVERITY))
734 DEBUGPC(DNM, "Severity=%s ", severity_name(*TLVP_VAL(&tp, NM_ATT_SEVERITY)));
735
736 DEBUGPC(DNM, "\n");
737
738 return 0;
739}
740
Harald Welte97ed1e72009-02-06 13:38:02 +0000741static int abis_nm_rcvmsg_report(struct msgb *mb)
742{
743 struct abis_om_fom_hdr *foh = msgb_l3(mb);
744 u_int8_t mt = foh->msg_type;
745
Harald Welte23897662009-05-01 14:52:51 +0000746 DEBUGP(DNM, "OC=%s(%02x) INST=(%02x,%02x,%02x) ",
747 obj_class_name(foh->obj_class), foh->obj_class,
748 foh->obj_inst.bts_nr, foh->obj_inst.trx_nr,
749 foh->obj_inst.ts_nr);
750
Harald Welte97ed1e72009-02-06 13:38:02 +0000751 //nmh->cfg->report_cb(mb, foh);
752
753 switch (mt) {
754 case NM_MT_STATECHG_EVENT_REP:
755 return abis_nm_rx_statechg_rep(mb);
756 break;
Harald Welte34a99682009-02-13 02:41:40 +0000757 case NM_MT_SW_ACTIVATED_REP:
Harald Welte23897662009-05-01 14:52:51 +0000758 DEBUGPC(DNM, "Software Activated Report\n");
Harald Weltef9a8cc32009-05-01 15:39:49 +0000759 dispatch_signal(SS_NM, S_NM_SW_ACTIV_REP, mb);
Harald Welte34a99682009-02-13 02:41:40 +0000760 break;
Harald Weltee0590df2009-02-15 03:34:15 +0000761 case NM_MT_FAILURE_EVENT_REP:
Harald Welte0db97b22009-05-01 17:22:47 +0000762 rx_fail_evt_rep(mb);
Harald Weltef9a8cc32009-05-01 15:39:49 +0000763 dispatch_signal(SS_NM, S_NM_FAIL_REP, mb);
Harald Weltee0590df2009-02-15 03:34:15 +0000764 break;
765 default:
Harald Welte23897662009-05-01 14:52:51 +0000766 DEBUGPC(DNM, "reporting NM MT 0x%02x\n", mt);
Harald Weltee0590df2009-02-15 03:34:15 +0000767 break;
768
Harald Welte97ed1e72009-02-06 13:38:02 +0000769 };
770
Harald Welte97ed1e72009-02-06 13:38:02 +0000771 return 0;
772}
773
Harald Welte34a99682009-02-13 02:41:40 +0000774/* Activate the specified software into the BTS */
775static int ipacc_sw_activate(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1,
776 u_int8_t i2, u_int8_t *sw_desc, u_int8_t swdesc_len)
777{
778 struct abis_om_hdr *oh;
779 struct msgb *msg = nm_msgb_alloc();
780 u_int8_t len = swdesc_len;
781 u_int8_t *trailer;
782
783 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
784 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, obj_class, i0, i1, i2);
785
786 trailer = msgb_put(msg, swdesc_len);
787 memcpy(trailer, sw_desc, swdesc_len);
788
789 return abis_nm_sendmsg(bts, msg);
790}
791
792static int abis_nm_rx_sw_act_req(struct msgb *mb)
793{
794 struct abis_om_hdr *oh = msgb_l2(mb);
795 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Harald Welte5c1e4582009-02-15 11:57:29 +0000796 int nack = 0;
Harald Welte34a99682009-02-13 02:41:40 +0000797 int ret;
798
Harald Welte5c1e4582009-02-15 11:57:29 +0000799 DEBUGP(DNM, "Software Activate Request ");
Harald Welte34a99682009-02-13 02:41:40 +0000800
Harald Welte5c1e4582009-02-15 11:57:29 +0000801 if (foh->obj_class >= 0xf0 && foh->obj_class <= 0xf3) {
802 DEBUGPC(DNM, "NACKing for GPRS obj_class 0x%02x\n", foh->obj_class);
803 nack = 1;
804 } else
805 DEBUGPC(DNM, "ACKing and Activating\n");
806
807 ret = abis_nm_sw_act_req_ack(mb->trx->bts, foh->obj_class,
Harald Welte34a99682009-02-13 02:41:40 +0000808 foh->obj_inst.bts_nr,
809 foh->obj_inst.trx_nr,
Harald Welte5c1e4582009-02-15 11:57:29 +0000810 foh->obj_inst.ts_nr, nack,
Harald Welte34a99682009-02-13 02:41:40 +0000811 foh->data, oh->length-sizeof(*foh));
812
Harald Welte5c1e4582009-02-15 11:57:29 +0000813 if (nack)
814 return ret;
815
Harald Welte34a99682009-02-13 02:41:40 +0000816 /* FIXME: properly parse attributes */
817 return ipacc_sw_activate(mb->trx->bts, foh->obj_class,
818 foh->obj_inst.bts_nr,
819 foh->obj_inst.trx_nr,
820 foh->obj_inst.ts_nr,
821 foh->data + oh->length-sizeof(*foh)-22, 22);
822}
823
Harald Weltee0590df2009-02-15 03:34:15 +0000824/* Receive a CHANGE_ADM_STATE_ACK, parse the TLV and update local state */
825static int abis_nm_rx_chg_adm_state_ack(struct msgb *mb)
826{
827 struct abis_om_hdr *oh = msgb_l2(mb);
828 struct abis_om_fom_hdr *foh = msgb_l3(mb);
829 struct tlv_parsed tp;
830 u_int8_t adm_state;
831
Harald Welte03133942009-02-18 19:51:53 +0000832 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Weltee0590df2009-02-15 03:34:15 +0000833 if (!TLVP_PRESENT(&tp, NM_ATT_ADM_STATE))
834 return -EINVAL;
835
836 adm_state = *TLVP_VAL(&tp, NM_ATT_ADM_STATE);
837
838 return update_admstate(mb->trx->bts, foh->obj_class, &foh->obj_inst, adm_state);
839}
840
Harald Welteee670472009-02-22 21:58:49 +0000841static int abis_nm_rx_lmt_event(struct msgb *mb)
842{
843 struct abis_om_hdr *oh = msgb_l2(mb);
844 struct abis_om_fom_hdr *foh = msgb_l3(mb);
845 struct tlv_parsed tp;
846
847 DEBUGP(DNM, "LMT Event ");
848 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
849 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_LOGON_SESSION) &&
850 TLVP_LEN(&tp, NM_ATT_BS11_LMT_LOGON_SESSION) >= 1) {
851 u_int8_t onoff = *TLVP_VAL(&tp, NM_ATT_BS11_LMT_LOGON_SESSION);
852 DEBUGPC(DNM, "LOG%s ", onoff ? "ON" : "OFF");
853 }
854 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV) &&
855 TLVP_LEN(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV) >= 1) {
856 u_int8_t level = *TLVP_VAL(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV);
857 DEBUGPC(DNM, "Level=%u ", level);
858 }
859 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_USER_NAME) &&
860 TLVP_LEN(&tp, NM_ATT_BS11_LMT_USER_NAME) >= 1) {
861 char *name = (char *) TLVP_VAL(&tp, NM_ATT_BS11_LMT_USER_NAME);
862 DEBUGPC(DNM, "Username=%s ", name);
863 }
864 DEBUGPC(DNM, "\n");
865 /* FIXME: parse LMT LOGON TIME */
866 return 0;
867}
868
Harald Welte52b1f982008-12-23 20:25:15 +0000869/* Receive a OML NM Message from BTS */
Harald Welte8470bf22008-12-25 23:28:35 +0000870static int abis_nm_rcvmsg_fom(struct msgb *mb)
Harald Welte52b1f982008-12-23 20:25:15 +0000871{
Harald Welte6c96ba52009-05-01 13:03:40 +0000872 struct abis_om_hdr *oh = msgb_l2(mb);
Harald Welte52b1f982008-12-23 20:25:15 +0000873 struct abis_om_fom_hdr *foh = msgb_l3(mb);
874 u_int8_t mt = foh->msg_type;
875
876 /* check for unsolicited message */
Harald Welte97ed1e72009-02-06 13:38:02 +0000877 if (is_report(mt))
878 return abis_nm_rcvmsg_report(mb);
Harald Welte52b1f982008-12-23 20:25:15 +0000879
Harald Welte4724f992009-01-18 18:01:49 +0000880 if (is_in_arr(mt, sw_load_msgs, ARRAY_SIZE(sw_load_msgs)))
881 return abis_nm_rcvmsg_sw(mb);
882
Harald Welte78fc0d42009-02-19 02:50:57 +0000883 if (is_in_arr(mt, nacks, ARRAY_SIZE(nacks))) {
Harald Welte6c96ba52009-05-01 13:03:40 +0000884 struct tlv_parsed tp;
Harald Welte78fc0d42009-02-19 02:50:57 +0000885 if (nack_names[mt])
Harald Welte6c96ba52009-05-01 13:03:40 +0000886 DEBUGP(DNM, "%s NACK ", nack_names[mt]);
887 /* FIXME: NACK cause */
Harald Welte78fc0d42009-02-19 02:50:57 +0000888 else
Harald Welte6c96ba52009-05-01 13:03:40 +0000889 DEBUGP(DNM, "NACK 0x%02x ", mt);
890
891 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
892 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
893 DEBUGPC(DNM, "CAUSE=%s\n",
894 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
895 else
896 DEBUGPC(DNM, "\n");
Holger Hans Peter Freyther500f3ca2009-06-10 10:48:14 +0200897
898 dispatch_signal(SS_NM, S_NM_NACK, (void*) ((long)mt));
899 return 0;
Harald Welte78fc0d42009-02-19 02:50:57 +0000900 }
Harald Weltead384642008-12-26 10:20:07 +0000901#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000902 /* check if last message is to be acked */
903 if (is_ack_nack(nmh->last_msgtype)) {
904 if (mt == MT_ACK(nmh->last_msgtype)) {
905 fprintf(stderr, "received ACK (0x%x)\n",
906 foh->msg_type);
907 /* we got our ACK, continue sending the next msg */
908 } else if (mt == MT_NACK(nmh->last_msgtype)) {
909 /* we got a NACK, signal this to the caller */
910 fprintf(stderr, "received NACK (0x%x)\n",
911 foh->msg_type);
912 /* FIXME: somehow signal this to the caller */
913 } else {
914 /* really strange things happen */
915 return -EINVAL;
916 }
917 }
Harald Weltead384642008-12-26 10:20:07 +0000918#endif
919
Harald Welte97ed1e72009-02-06 13:38:02 +0000920 switch (mt) {
Harald Weltee0590df2009-02-15 03:34:15 +0000921 case NM_MT_CHG_ADM_STATE_ACK:
922 return abis_nm_rx_chg_adm_state_ack(mb);
923 break;
Harald Welte34a99682009-02-13 02:41:40 +0000924 case NM_MT_SW_ACT_REQ:
925 return abis_nm_rx_sw_act_req(mb);
926 break;
Harald Welte97ed1e72009-02-06 13:38:02 +0000927 case NM_MT_BS11_LMT_SESSION:
Harald Welteee670472009-02-22 21:58:49 +0000928 return abis_nm_rx_lmt_event(mb);
Harald Welte97ed1e72009-02-06 13:38:02 +0000929 break;
930 }
931
Harald Weltead384642008-12-26 10:20:07 +0000932 return 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000933}
934
Harald Welte677c21f2009-02-17 13:22:23 +0000935static int abis_nm_rx_ipacc(struct msgb *mb);
936
937static int abis_nm_rcvmsg_manuf(struct msgb *mb)
938{
939 int rc;
940 int bts_type = mb->trx->bts->type;
941
942 switch (bts_type) {
943 case GSM_BTS_TYPE_NANOBTS_900:
944 case GSM_BTS_TYPE_NANOBTS_1800:
945 rc = abis_nm_rx_ipacc(mb);
946 break;
947 default:
948 fprintf(stderr, "don't know how to parse OML for this "
949 "BTS type (%u)\n", bts_type);
950 rc = 0;
951 break;
952 }
953
954 return rc;
955}
956
Harald Welte52b1f982008-12-23 20:25:15 +0000957/* High-Level API */
958/* Entry-point where L2 OML from BTS enters the NM code */
Harald Welte8470bf22008-12-25 23:28:35 +0000959int abis_nm_rcvmsg(struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +0000960{
Harald Welte52b1f982008-12-23 20:25:15 +0000961 struct abis_om_hdr *oh = msgb_l2(msg);
Harald Welte677c21f2009-02-17 13:22:23 +0000962 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000963
964 /* Various consistency checks */
965 if (oh->placement != ABIS_OM_PLACEMENT_ONLY) {
966 fprintf(stderr, "ABIS OML placement 0x%x not supported\n",
967 oh->placement);
968 return -EINVAL;
969 }
970 if (oh->sequence != 0) {
971 fprintf(stderr, "ABIS OML sequence 0x%x != 0x00\n",
972 oh->sequence);
973 return -EINVAL;
974 }
Harald Welte702d8702008-12-26 20:25:35 +0000975#if 0
Holger Freytherca362a62009-01-04 21:05:01 +0000976 unsigned int l2_len = msg->tail - (u_int8_t *)msgb_l2(msg);
977 unsigned int hlen = sizeof(*oh) + sizeof(struct abis_om_fom_hdr);
Harald Welte702d8702008-12-26 20:25:35 +0000978 if (oh->length + hlen > l2_len) {
Harald Welte52b1f982008-12-23 20:25:15 +0000979 fprintf(stderr, "ABIS OML truncated message (%u > %u)\n",
980 oh->length + sizeof(*oh), l2_len);
981 return -EINVAL;
982 }
Harald Welte702d8702008-12-26 20:25:35 +0000983 if (oh->length + hlen < l2_len)
984 fprintf(stderr, "ABIS OML message with extra trailer?!? (oh->len=%d, sizeof_oh=%d l2_len=%d\n", oh->length, sizeof(*oh), l2_len);
985#endif
Harald Weltead384642008-12-26 10:20:07 +0000986 msg->l3h = (unsigned char *)oh + sizeof(*oh);
Harald Welte52b1f982008-12-23 20:25:15 +0000987
988 switch (oh->mdisc) {
989 case ABIS_OM_MDISC_FOM:
Harald Welte8470bf22008-12-25 23:28:35 +0000990 rc = abis_nm_rcvmsg_fom(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000991 break;
Harald Welte677c21f2009-02-17 13:22:23 +0000992 case ABIS_OM_MDISC_MANUF:
993 rc = abis_nm_rcvmsg_manuf(msg);
994 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000995 case ABIS_OM_MDISC_MMI:
996 case ABIS_OM_MDISC_TRAU:
Harald Welte677c21f2009-02-17 13:22:23 +0000997 fprintf(stderr, "unimplemented ABIS OML message discriminator 0x%x\n",
998 oh->mdisc);
999 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001000 default:
1001 fprintf(stderr, "unknown ABIS OML message discriminator 0x%x\n",
1002 oh->mdisc);
1003 return -EINVAL;
1004 }
1005
Harald Weltead384642008-12-26 10:20:07 +00001006 msgb_free(msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001007 return rc;
1008}
1009
1010#if 0
1011/* initialized all resources */
1012struct abis_nm_h *abis_nm_init(struct abis_nm_cfg *cfg)
1013{
1014 struct abis_nm_h *nmh;
1015
1016 nmh = malloc(sizeof(*nmh));
1017 if (!nmh)
1018 return NULL;
1019
1020 nmh->cfg = cfg;
1021
1022 return nmh;
1023}
1024
1025/* free all resources */
1026void abis_nm_fini(struct abis_nm_h *nmh)
1027{
1028 free(nmh);
1029}
1030#endif
1031
1032/* Here we are trying to define a high-level API that can be used by
1033 * the actual BSC implementation. However, the architecture is currently
1034 * still under design. Ideally the calls to this API would be synchronous,
1035 * while the underlying stack behind the APi runs in a traditional select
1036 * based state machine.
1037 */
1038
Harald Welte4724f992009-01-18 18:01:49 +00001039/* 6.2 Software Load: */
1040enum sw_state {
1041 SW_STATE_NONE,
1042 SW_STATE_WAIT_INITACK,
1043 SW_STATE_WAIT_SEGACK,
1044 SW_STATE_WAIT_ENDACK,
1045 SW_STATE_WAIT_ACTACK,
1046 SW_STATE_ERROR,
1047};
Harald Welte52b1f982008-12-23 20:25:15 +00001048
Harald Welte52b1f982008-12-23 20:25:15 +00001049struct abis_nm_sw {
Harald Welte4724f992009-01-18 18:01:49 +00001050 struct gsm_bts *bts;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001051 gsm_cbfn *cbfn;
1052 void *cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +00001053 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001054
Harald Welte52b1f982008-12-23 20:25:15 +00001055 /* this will become part of the SW LOAD INITIATE */
1056 u_int8_t obj_class;
1057 u_int8_t obj_instance[3];
Harald Welte4724f992009-01-18 18:01:49 +00001058
1059 u_int8_t file_id[255];
1060 u_int8_t file_id_len;
1061
1062 u_int8_t file_version[255];
1063 u_int8_t file_version_len;
1064
1065 u_int8_t window_size;
1066 u_int8_t seg_in_window;
1067
1068 int fd;
1069 FILE *stream;
1070 enum sw_state state;
Harald Welte1602ade2009-01-29 21:12:39 +00001071 int last_seg;
Harald Welte52b1f982008-12-23 20:25:15 +00001072};
1073
Harald Welte4724f992009-01-18 18:01:49 +00001074static struct abis_nm_sw g_sw;
1075
1076/* 6.2.1 / 8.3.1: Load Data Initiate */
1077static int sw_load_init(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +00001078{
Harald Welte4724f992009-01-18 18:01:49 +00001079 struct abis_om_hdr *oh;
1080 struct msgb *msg = nm_msgb_alloc();
1081 u_int8_t len = 3*2 + sw->file_id_len + sw->file_version_len;
1082
1083 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1084 fill_om_fom_hdr(oh, len, NM_MT_LOAD_INIT, sw->obj_class,
1085 sw->obj_instance[0], sw->obj_instance[1],
1086 sw->obj_instance[2]);
1087
1088 /* FIXME: this is BS11 specific format */
1089 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1090 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1091 sw->file_version);
1092 msgb_tv_put(msg, NM_ATT_WINDOW_SIZE, sw->window_size);
1093
1094 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001095}
1096
Harald Welte1602ade2009-01-29 21:12:39 +00001097static int is_last_line(FILE *stream)
1098{
1099 char next_seg_buf[256];
1100 long pos;
1101
1102 /* check if we're sending the last line */
1103 pos = ftell(stream);
1104 if (!fgets(next_seg_buf, sizeof(next_seg_buf)-2, stream)) {
1105 fseek(stream, pos, SEEK_SET);
1106 return 1;
1107 }
1108
1109 fseek(stream, pos, SEEK_SET);
1110 return 0;
1111}
1112
Harald Welte4724f992009-01-18 18:01:49 +00001113/* 6.2.2 / 8.3.2 Load Data Segment */
1114static int sw_load_segment(struct abis_nm_sw *sw)
1115{
1116 struct abis_om_hdr *oh;
1117 struct msgb *msg = nm_msgb_alloc();
1118 char seg_buf[256];
1119 char *line_buf = seg_buf+2;
Harald Welte3b8ba212009-01-29 12:27:58 +00001120 unsigned char *tlv;
Harald Welte4724f992009-01-18 18:01:49 +00001121 u_int8_t len;
Harald Welte4724f992009-01-18 18:01:49 +00001122
1123 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte3b8ba212009-01-29 12:27:58 +00001124
1125 switch (sw->bts->type) {
1126 case GSM_BTS_TYPE_BS11:
1127 if (fgets(line_buf, sizeof(seg_buf)-2, sw->stream) == NULL) {
1128 perror("fgets reading segment");
1129 return -EINVAL;
1130 }
1131 seg_buf[0] = 0x00;
Harald Welte1602ade2009-01-29 21:12:39 +00001132
1133 /* check if we're sending the last line */
1134 sw->last_seg = is_last_line(sw->stream);
1135 if (sw->last_seg)
1136 seg_buf[1] = 0;
1137 else
1138 seg_buf[1] = 1 + sw->seg_in_window++;
Harald Welte3b8ba212009-01-29 12:27:58 +00001139
1140 len = strlen(line_buf) + 2;
1141 tlv = msgb_put(msg, TLV_GROSS_LEN(len));
1142 tlv_put(tlv, NM_ATT_BS11_FILE_DATA, len, (u_int8_t *)seg_buf);
1143 /* BS11 wants CR + LF in excess of the TLV length !?! */
1144 tlv[1] -= 2;
1145
1146 /* we only now know the exact length for the OM hdr */
1147 len = strlen(line_buf)+2;
1148 break;
1149 default:
1150 /* FIXME: Other BTS types */
1151 return -1;
Harald Welte4724f992009-01-18 18:01:49 +00001152 }
Harald Welte4724f992009-01-18 18:01:49 +00001153
Harald Welte4724f992009-01-18 18:01:49 +00001154 fill_om_fom_hdr(oh, len, NM_MT_LOAD_SEG, sw->obj_class,
1155 sw->obj_instance[0], sw->obj_instance[1],
1156 sw->obj_instance[2]);
1157
1158 return abis_nm_sendmsg(sw->bts, msg);
1159}
1160
1161/* 6.2.4 / 8.3.4 Load Data End */
1162static int sw_load_end(struct abis_nm_sw *sw)
1163{
1164 struct abis_om_hdr *oh;
1165 struct msgb *msg = nm_msgb_alloc();
1166 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
1167
1168 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1169 fill_om_fom_hdr(oh, len, NM_MT_LOAD_END, sw->obj_class,
1170 sw->obj_instance[0], sw->obj_instance[1],
1171 sw->obj_instance[2]);
1172
1173 /* FIXME: this is BS11 specific format */
1174 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1175 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1176 sw->file_version);
1177
1178 return abis_nm_sendmsg(sw->bts, msg);
1179}
Harald Welte5e4d1b32009-02-01 13:36:56 +00001180
Harald Welte52b1f982008-12-23 20:25:15 +00001181/* Activate the specified software into the BTS */
Harald Welte4724f992009-01-18 18:01:49 +00001182static int sw_activate(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +00001183{
Harald Welte4724f992009-01-18 18:01:49 +00001184 struct abis_om_hdr *oh;
1185 struct msgb *msg = nm_msgb_alloc();
1186 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
Harald Welte52b1f982008-12-23 20:25:15 +00001187
Harald Welte4724f992009-01-18 18:01:49 +00001188 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1189 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, sw->obj_class,
1190 sw->obj_instance[0], sw->obj_instance[1],
1191 sw->obj_instance[2]);
1192
1193 /* FIXME: this is BS11 specific format */
1194 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1195 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1196 sw->file_version);
1197
1198 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001199}
Harald Welte4724f992009-01-18 18:01:49 +00001200
1201static int sw_open_file(struct abis_nm_sw *sw, const char *fname)
1202{
1203 char file_id[12+1];
1204 char file_version[80+1];
1205 int rc;
1206
1207 sw->fd = open(fname, O_RDONLY);
1208 if (sw->fd < 0)
1209 return sw->fd;
1210
1211 switch (sw->bts->type) {
1212 case GSM_BTS_TYPE_BS11:
1213 sw->stream = fdopen(sw->fd, "r");
1214 if (!sw->stream) {
1215 perror("fdopen");
1216 return -1;
1217 }
1218 /* read first line and parse file ID and VERSION */
Harald Welte3b8ba212009-01-29 12:27:58 +00001219 rc = fscanf(sw->stream, "@(#)%12s:%80s\r\n",
Harald Welte4724f992009-01-18 18:01:49 +00001220 file_id, file_version);
1221 if (rc != 2) {
1222 perror("parsing header line of software file");
1223 return -1;
1224 }
1225 strcpy((char *)sw->file_id, file_id);
1226 sw->file_id_len = strlen(file_id);
1227 strcpy((char *)sw->file_version, file_version);
1228 sw->file_version_len = strlen(file_version);
1229 /* rewind to start of file */
Harald Welte3b8ba212009-01-29 12:27:58 +00001230 rewind(sw->stream);
Harald Welte4724f992009-01-18 18:01:49 +00001231 break;
1232 default:
1233 /* We don't know how to treat them yet */
1234 close(sw->fd);
1235 return -EINVAL;
1236 }
1237
1238 return 0;
1239}
1240
1241static void sw_close_file(struct abis_nm_sw *sw)
1242{
1243 switch (sw->bts->type) {
1244 case GSM_BTS_TYPE_BS11:
1245 fclose(sw->stream);
1246 break;
1247 default:
1248 close(sw->fd);
1249 break;
1250 }
1251}
1252
1253/* Fill the window */
1254static int sw_fill_window(struct abis_nm_sw *sw)
1255{
1256 int rc;
1257
1258 while (sw->seg_in_window < sw->window_size) {
1259 rc = sw_load_segment(sw);
1260 if (rc < 0)
1261 return rc;
Harald Welte1602ade2009-01-29 21:12:39 +00001262 if (sw->last_seg)
1263 break;
Harald Welte4724f992009-01-18 18:01:49 +00001264 }
1265 return 0;
1266}
1267
1268/* callback function from abis_nm_rcvmsg() handler */
1269static int abis_nm_rcvmsg_sw(struct msgb *mb)
1270{
1271 struct abis_om_fom_hdr *foh = msgb_l3(mb);
1272 int rc = -1;
1273 struct abis_nm_sw *sw = &g_sw;
1274 enum sw_state old_state = sw->state;
1275
Harald Welte3ffd1372009-02-01 22:15:49 +00001276 //DEBUGP(DNM, "state %u, NM MT 0x%02x\n", sw->state, foh->msg_type);
Harald Welte4724f992009-01-18 18:01:49 +00001277
1278 switch (sw->state) {
1279 case SW_STATE_WAIT_INITACK:
1280 switch (foh->msg_type) {
1281 case NM_MT_LOAD_INIT_ACK:
1282 /* fill window with segments */
Harald Welte5e4d1b32009-02-01 13:36:56 +00001283 if (sw->cbfn)
1284 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1285 NM_MT_LOAD_INIT_ACK, mb,
1286 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001287 rc = sw_fill_window(sw);
1288 sw->state = SW_STATE_WAIT_SEGACK;
1289 break;
1290 case NM_MT_LOAD_INIT_NACK:
Harald Welte3ffd1372009-02-01 22:15:49 +00001291 if (sw->forced) {
1292 DEBUGP(DNM, "FORCED: Ignoring Software Load "
1293 "Init NACK\n");
1294 if (sw->cbfn)
1295 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1296 NM_MT_LOAD_INIT_ACK, mb,
1297 sw->cb_data, NULL);
1298 rc = sw_fill_window(sw);
1299 sw->state = SW_STATE_WAIT_SEGACK;
1300 } else {
1301 DEBUGP(DNM, "Software Load Init NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001302 /* FIXME: cause */
Harald Welte3ffd1372009-02-01 22:15:49 +00001303 if (sw->cbfn)
1304 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1305 NM_MT_LOAD_INIT_NACK, mb,
1306 sw->cb_data, NULL);
1307 sw->state = SW_STATE_ERROR;
1308 }
Harald Welte4724f992009-01-18 18:01:49 +00001309 break;
1310 }
1311 break;
1312 case SW_STATE_WAIT_SEGACK:
1313 switch (foh->msg_type) {
1314 case NM_MT_LOAD_SEG_ACK:
Harald Welte3ffd1372009-02-01 22:15:49 +00001315 if (sw->cbfn)
1316 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1317 NM_MT_LOAD_SEG_ACK, mb,
1318 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001319 sw->seg_in_window = 0;
Harald Welte1602ade2009-01-29 21:12:39 +00001320 if (!sw->last_seg) {
1321 /* fill window with more segments */
1322 rc = sw_fill_window(sw);
1323 sw->state = SW_STATE_WAIT_SEGACK;
1324 } else {
1325 /* end the transfer */
1326 sw->state = SW_STATE_WAIT_ENDACK;
1327 rc = sw_load_end(sw);
1328 }
Harald Welte4724f992009-01-18 18:01:49 +00001329 break;
1330 }
1331 break;
1332 case SW_STATE_WAIT_ENDACK:
1333 switch (foh->msg_type) {
1334 case NM_MT_LOAD_END_ACK:
1335 sw_close_file(sw);
Harald Welte5e4d1b32009-02-01 13:36:56 +00001336 DEBUGP(DNM, "Software Load End (BTS %u)\n",
1337 sw->bts->nr);
1338 sw->state = SW_STATE_NONE;
1339 if (sw->cbfn)
1340 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1341 NM_MT_LOAD_END_ACK, mb,
1342 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001343 break;
1344 case NM_MT_LOAD_END_NACK:
Holger Freyther31338a12009-02-06 17:43:50 +00001345 if (sw->forced) {
1346 DEBUGP(DNM, "FORCED: Ignoring Software Load"
1347 "End NACK\n");
1348 sw->state = SW_STATE_NONE;
1349 if (sw->cbfn)
1350 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1351 NM_MT_LOAD_END_ACK, mb,
1352 sw->cb_data, NULL);
1353 } else {
1354 DEBUGP(DNM, "Software Load End NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001355 /* FIXME: cause */
Holger Freyther31338a12009-02-06 17:43:50 +00001356 sw->state = SW_STATE_ERROR;
1357 if (sw->cbfn)
1358 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1359 NM_MT_LOAD_END_NACK, mb,
1360 sw->cb_data, NULL);
1361 }
Harald Welte4724f992009-01-18 18:01:49 +00001362 break;
1363 }
1364 case SW_STATE_WAIT_ACTACK:
1365 switch (foh->msg_type) {
1366 case NM_MT_ACTIVATE_SW_ACK:
1367 /* we're done */
Harald Welte5e4d1b32009-02-01 13:36:56 +00001368 DEBUGP(DNM, "Activate Software DONE!\n");
Harald Welte4724f992009-01-18 18:01:49 +00001369 sw->state = SW_STATE_NONE;
1370 rc = 0;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001371 if (sw->cbfn)
1372 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1373 NM_MT_ACTIVATE_SW_ACK, mb,
1374 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001375 break;
1376 case NM_MT_ACTIVATE_SW_NACK:
Harald Welte1602ade2009-01-29 21:12:39 +00001377 DEBUGP(DNM, "Activate Software NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001378 /* FIXME: cause */
Harald Welte4724f992009-01-18 18:01:49 +00001379 sw->state = SW_STATE_ERROR;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001380 if (sw->cbfn)
1381 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1382 NM_MT_ACTIVATE_SW_NACK, mb,
1383 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001384 break;
1385 }
1386 case SW_STATE_NONE:
Harald Weltea994a482009-05-01 15:54:23 +00001387 switch (foh->msg_type) {
1388 case NM_MT_ACTIVATE_SW_ACK:
1389 rc = 0;
1390 break;
1391 }
1392 break;
Harald Welte4724f992009-01-18 18:01:49 +00001393 case SW_STATE_ERROR:
1394 break;
1395 }
1396
1397 if (rc)
Harald Weltea994a482009-05-01 15:54:23 +00001398 DEBUGP(DNM, "unexpected NM MT 0x%02x in state %u -> %u\n",
Harald Welte4724f992009-01-18 18:01:49 +00001399 foh->msg_type, old_state, sw->state);
1400
1401 return rc;
1402}
1403
1404/* Load the specified software into the BTS */
1405int abis_nm_software_load(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00001406 u_int8_t win_size, int forced,
1407 gsm_cbfn *cbfn, void *cb_data)
Harald Welte4724f992009-01-18 18:01:49 +00001408{
1409 struct abis_nm_sw *sw = &g_sw;
1410 int rc;
1411
Harald Welte5e4d1b32009-02-01 13:36:56 +00001412 DEBUGP(DNM, "Software Load (BTS %u, File \"%s\")\n",
1413 bts->nr, fname);
1414
Harald Welte4724f992009-01-18 18:01:49 +00001415 if (sw->state != SW_STATE_NONE)
1416 return -EBUSY;
1417
1418 sw->bts = bts;
1419 sw->obj_class = NM_OC_SITE_MANAGER;
1420 sw->obj_instance[0] = 0xff;
1421 sw->obj_instance[1] = 0xff;
1422 sw->obj_instance[2] = 0xff;
1423 sw->window_size = win_size;
1424 sw->state = SW_STATE_WAIT_INITACK;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001425 sw->cbfn = cbfn;
1426 sw->cb_data = cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +00001427 sw->forced = forced;
Harald Welte4724f992009-01-18 18:01:49 +00001428
1429 rc = sw_open_file(sw, fname);
1430 if (rc < 0) {
1431 sw->state = SW_STATE_NONE;
1432 return rc;
1433 }
1434
1435 return sw_load_init(sw);
1436}
Harald Welte52b1f982008-12-23 20:25:15 +00001437
Harald Welte1602ade2009-01-29 21:12:39 +00001438int abis_nm_software_load_status(struct gsm_bts *bts)
1439{
1440 struct abis_nm_sw *sw = &g_sw;
1441 struct stat st;
1442 int rc, percent;
1443
1444 rc = fstat(sw->fd, &st);
1445 if (rc < 0) {
1446 perror("ERROR during stat");
1447 return rc;
1448 }
1449
1450 percent = (ftell(sw->stream) * 100) / st.st_size;
1451 return percent;
1452}
1453
Harald Welte5e4d1b32009-02-01 13:36:56 +00001454/* Activate the specified software into the BTS */
1455int abis_nm_software_activate(struct gsm_bts *bts, const char *fname,
1456 gsm_cbfn *cbfn, void *cb_data)
1457{
1458 struct abis_nm_sw *sw = &g_sw;
1459 int rc;
1460
1461 DEBUGP(DNM, "Activating Software (BTS %u, File \"%s\")\n",
1462 bts->nr, fname);
1463
1464 if (sw->state != SW_STATE_NONE)
1465 return -EBUSY;
1466
1467 sw->bts = bts;
1468 sw->obj_class = NM_OC_SITE_MANAGER;
1469 sw->obj_instance[0] = 0xff;
1470 sw->obj_instance[1] = 0xff;
1471 sw->obj_instance[2] = 0xff;
1472 sw->state = SW_STATE_WAIT_ACTACK;
1473 sw->cbfn = cbfn;
1474 sw->cb_data = cb_data;
1475
1476 /* Open the file in order to fill some sw struct members */
1477 rc = sw_open_file(sw, fname);
1478 if (rc < 0) {
1479 sw->state = SW_STATE_NONE;
1480 return rc;
1481 }
1482 sw_close_file(sw);
1483
1484 return sw_activate(sw);
1485}
1486
Harald Welte8470bf22008-12-25 23:28:35 +00001487static void fill_nm_channel(struct abis_nm_channel *ch, u_int8_t bts_port,
Harald Welte52b1f982008-12-23 20:25:15 +00001488 u_int8_t ts_nr, u_int8_t subslot_nr)
1489{
Harald Welteadaf08b2009-01-18 11:08:10 +00001490 ch->attrib = NM_ATT_ABIS_CHANNEL;
Harald Welte52b1f982008-12-23 20:25:15 +00001491 ch->bts_port = bts_port;
1492 ch->timeslot = ts_nr;
1493 ch->subslot = subslot_nr;
1494}
1495
1496int abis_nm_establish_tei(struct gsm_bts *bts, u_int8_t trx_nr,
1497 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot,
1498 u_int8_t tei)
1499{
1500 struct abis_om_hdr *oh;
1501 struct abis_nm_channel *ch;
Harald Welte702d8702008-12-26 20:25:35 +00001502 u_int8_t len = sizeof(*ch) + 2;
Harald Welte8470bf22008-12-25 23:28:35 +00001503 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001504
1505 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1506 fill_om_fom_hdr(oh, len, NM_MT_ESTABLISH_TEI, NM_OC_RADIO_CARRIER,
1507 bts->bts_nr, trx_nr, 0xff);
1508
Harald Welte8470bf22008-12-25 23:28:35 +00001509 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte52b1f982008-12-23 20:25:15 +00001510
1511 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1512 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1513
1514 return abis_nm_sendmsg(bts, msg);
1515}
1516
1517/* connect signalling of one (BTS,TRX) to a particular timeslot on the E1 */
1518int abis_nm_conn_terr_sign(struct gsm_bts_trx *trx,
1519 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot)
1520{
Harald Welte8470bf22008-12-25 23:28:35 +00001521 struct gsm_bts *bts = trx->bts;
Harald Welte52b1f982008-12-23 20:25:15 +00001522 struct abis_om_hdr *oh;
1523 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +00001524 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001525
1526 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001527 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_SIGN,
Harald Welte52b1f982008-12-23 20:25:15 +00001528 NM_OC_RADIO_CARRIER, bts->bts_nr, trx->nr, 0xff);
1529
1530 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1531 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1532
1533 return abis_nm_sendmsg(bts, msg);
1534}
1535
1536#if 0
1537int abis_nm_disc_terr_sign(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1538 struct abis_nm_abis_channel *chan)
1539{
1540}
1541#endif
1542
1543int abis_nm_conn_terr_traf(struct gsm_bts_trx_ts *ts,
1544 u_int8_t e1_port, u_int8_t e1_timeslot,
1545 u_int8_t e1_subslot)
1546{
1547 struct gsm_bts *bts = ts->trx->bts;
1548 struct abis_om_hdr *oh;
1549 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +00001550 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001551
1552 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1553 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_TRAF,
Harald Welteb110cee2009-02-18 03:42:35 +00001554 NM_OC_CHANNEL, bts->bts_nr, ts->trx->nr, ts->nr);
Harald Welte52b1f982008-12-23 20:25:15 +00001555
1556 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1557 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1558
Harald Weltef325eb42009-02-19 17:07:39 +00001559 DEBUGP(DNM, "CONNECT TERR TRAF Um=%s E1=(%u,%u,%u)\n",
1560 gsm_ts_name(ts),
Harald Welteb110cee2009-02-18 03:42:35 +00001561 e1_port, e1_timeslot, e1_subslot);
1562
Harald Welte52b1f982008-12-23 20:25:15 +00001563 return abis_nm_sendmsg(bts, msg);
1564}
1565
1566#if 0
1567int abis_nm_disc_terr_traf(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1568 struct abis_nm_abis_channel *chan,
1569 u_int8_t subchan)
1570{
1571}
1572#endif
1573
Harald Welte22af0db2009-02-14 15:41:08 +00001574/* Chapter 8.6.1 */
1575int abis_nm_set_bts_attr(struct gsm_bts *bts, u_int8_t *attr, int attr_len)
1576{
1577 struct abis_om_hdr *oh;
1578 struct msgb *msg = nm_msgb_alloc();
1579 u_int8_t *cur;
1580
1581 DEBUGP(DNM, "Set BTS Attr (bts=%d)\n", bts->nr);
1582
1583 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte191280d2009-05-01 13:20:04 +00001584 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 +00001585 cur = msgb_put(msg, attr_len);
1586 memcpy(cur, attr, attr_len);
1587
1588 return abis_nm_sendmsg(bts, msg);
1589}
1590
1591/* Chapter 8.6.2 */
1592int abis_nm_set_radio_attr(struct gsm_bts_trx *trx, u_int8_t *attr, int attr_len)
1593{
1594 struct abis_om_hdr *oh;
1595 struct msgb *msg = nm_msgb_alloc();
1596 u_int8_t *cur;
1597
1598 DEBUGP(DNM, "Set TRX Attr (bts=%d,trx=%d)\n", trx->bts->nr, trx->nr);
1599
1600 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1601 fill_om_fom_hdr(oh, attr_len, NM_MT_SET_RADIO_ATTR, NM_OC_RADIO_CARRIER,
Harald Welte191280d2009-05-01 13:20:04 +00001602 trx->bts->bts_nr, trx->nr, 0xff);
Harald Welte22af0db2009-02-14 15:41:08 +00001603 cur = msgb_put(msg, attr_len);
1604 memcpy(cur, attr, attr_len);
1605
1606 return abis_nm_sendmsg(trx->bts, msg);
1607}
1608
1609/* Chapter 8.6.3 */
Harald Welte52b1f982008-12-23 20:25:15 +00001610int abis_nm_set_channel_attr(struct gsm_bts_trx_ts *ts, u_int8_t chan_comb)
1611{
1612 struct gsm_bts *bts = ts->trx->bts;
1613 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001614 u_int16_t arfcn = htons(ts->trx->arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001615 u_int8_t zero = 0x00;
Harald Welte8470bf22008-12-25 23:28:35 +00001616 struct msgb *msg = nm_msgb_alloc();
Harald Weltee0590df2009-02-15 03:34:15 +00001617 u_int8_t len = 2 + 2;
1618
1619 if (bts->type == GSM_BTS_TYPE_BS11)
1620 len += 4 + 2 + 2 + 3;
Harald Welte52b1f982008-12-23 20:25:15 +00001621
Harald Weltef325eb42009-02-19 17:07:39 +00001622 DEBUGP(DNM, "Set Chan Attr %s\n", gsm_ts_name(ts));
Harald Welte22af0db2009-02-14 15:41:08 +00001623
Harald Welte52b1f982008-12-23 20:25:15 +00001624 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001625 fill_om_fom_hdr(oh, len, NM_MT_SET_CHAN_ATTR,
Holger Freyther6b2d2622009-02-14 23:16:59 +00001626 NM_OC_CHANNEL, bts->bts_nr,
Harald Welte52b1f982008-12-23 20:25:15 +00001627 ts->trx->nr, ts->nr);
1628 /* FIXME: don't send ARFCN list, hopping sequence, mAIO, ...*/
Harald Weltee0590df2009-02-15 03:34:15 +00001629 if (bts->type == GSM_BTS_TYPE_BS11)
1630 msgb_tlv16_put(msg, NM_ATT_ARFCN_LIST, 1, &arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001631 msgb_tv_put(msg, NM_ATT_CHAN_COMB, chan_comb);
Harald Weltee0590df2009-02-15 03:34:15 +00001632 if (bts->type == GSM_BTS_TYPE_BS11) {
1633 msgb_tv_put(msg, NM_ATT_HSN, 0x00);
1634 msgb_tv_put(msg, NM_ATT_MAIO, 0x00);
1635 }
Harald Welte52b1f982008-12-23 20:25:15 +00001636 msgb_tv_put(msg, NM_ATT_TSC, 0x07); /* training sequence */
Harald Weltee0590df2009-02-15 03:34:15 +00001637 if (bts->type == GSM_BTS_TYPE_BS11)
1638 msgb_tlv_put(msg, 0x59, 1, &zero);
Harald Welte52b1f982008-12-23 20:25:15 +00001639
1640 return abis_nm_sendmsg(bts, msg);
1641}
1642
Harald Welte34a99682009-02-13 02:41:40 +00001643int 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 +00001644 u_int8_t i2, u_int8_t i3, int nack, u_int8_t *attr, int att_len)
Harald Welte34a99682009-02-13 02:41:40 +00001645{
1646 struct abis_om_hdr *oh;
1647 struct msgb *msg = nm_msgb_alloc();
Harald Welte5c1e4582009-02-15 11:57:29 +00001648 u_int8_t msgtype = NM_MT_SW_ACT_REQ_ACK;
1649 u_int8_t len = att_len;
1650
1651 if (nack) {
1652 len += 2;
1653 msgtype = NM_MT_SW_ACT_REQ_NACK;
1654 }
Harald Welte34a99682009-02-13 02:41:40 +00001655
1656 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte5c1e4582009-02-15 11:57:29 +00001657 fill_om_fom_hdr(oh, att_len, msgtype, obj_class, i1, i2, i3);
1658
Harald Welte34a99682009-02-13 02:41:40 +00001659 if (attr) {
1660 u_int8_t *ptr = msgb_put(msg, att_len);
1661 memcpy(ptr, attr, att_len);
1662 }
Harald Welte5c1e4582009-02-15 11:57:29 +00001663 if (nack)
1664 msgb_tv_put(msg, NM_ATT_NACK_CAUSES, NM_NACK_OBJCLASS_NOTSUPP);
Harald Welte34a99682009-02-13 02:41:40 +00001665
1666 return abis_nm_sendmsg(bts, msg);
1667}
1668
Harald Welte8470bf22008-12-25 23:28:35 +00001669int abis_nm_raw_msg(struct gsm_bts *bts, int len, u_int8_t *rawmsg)
Harald Welte52b1f982008-12-23 20:25:15 +00001670{
Harald Welte8470bf22008-12-25 23:28:35 +00001671 struct msgb *msg = nm_msgb_alloc();
1672 struct abis_om_hdr *oh;
Harald Welte52b1f982008-12-23 20:25:15 +00001673 u_int8_t *data;
1674
1675 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
1676 fill_om_hdr(oh, len);
1677 data = msgb_put(msg, len);
Harald Weltead384642008-12-26 10:20:07 +00001678 memcpy(data, rawmsg, len);
Harald Welte52b1f982008-12-23 20:25:15 +00001679
1680 return abis_nm_sendmsg(bts, msg);
1681}
1682
1683/* Siemens specific commands */
1684static int __simple_cmd(struct gsm_bts *bts, u_int8_t msg_type)
1685{
1686 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001687 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001688
1689 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001690 fill_om_fom_hdr(oh, 0, msg_type, NM_OC_SITE_MANAGER,
Harald Welte52b1f982008-12-23 20:25:15 +00001691 0xff, 0xff, 0xff);
1692
1693 return abis_nm_sendmsg(bts, msg);
1694}
1695
Harald Welte34a99682009-02-13 02:41:40 +00001696/* Chapter 8.9.2 */
1697int abis_nm_opstart(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1, u_int8_t i2)
1698{
1699 struct abis_om_hdr *oh;
1700 struct msgb *msg = nm_msgb_alloc();
1701
Harald Welte22af0db2009-02-14 15:41:08 +00001702 DEBUGP(DNM, "Sending OPSTART obj_class=0x%02x obj_inst=(0x%02x, 0x%02x, 0x%02x)\n",
1703 obj_class, i0, i1, i2);
Harald Welte34a99682009-02-13 02:41:40 +00001704 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1705 fill_om_fom_hdr(oh, 0, NM_MT_OPSTART, obj_class, i0, i1, i2);
1706
1707 return abis_nm_sendmsg(bts, msg);
1708}
1709
1710/* Chapter 8.8.5 */
1711int abis_nm_chg_adm_state(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0,
1712 u_int8_t i1, u_int8_t i2, u_int8_t adm_state)
1713{
1714 struct abis_om_hdr *oh;
1715 struct msgb *msg = nm_msgb_alloc();
1716
1717 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1718 fill_om_fom_hdr(oh, 2, NM_MT_CHG_ADM_STATE, obj_class, i0, i1, i2);
1719 msgb_tv_put(msg, NM_ATT_ADM_STATE, adm_state);
1720
1721 return abis_nm_sendmsg(bts, msg);
1722}
1723
1724
Harald Welte52b1f982008-12-23 20:25:15 +00001725int abis_nm_event_reports(struct gsm_bts *bts, int on)
1726{
1727 if (on == 0)
Harald Welte227d4072009-01-03 08:16:25 +00001728 return __simple_cmd(bts, NM_MT_STOP_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001729 else
Harald Welte227d4072009-01-03 08:16:25 +00001730 return __simple_cmd(bts, NM_MT_REST_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001731}
1732
Harald Welte47d88ae2009-01-04 12:02:08 +00001733/* Siemens (or BS-11) specific commands */
1734
Harald Welte3ffd1372009-02-01 22:15:49 +00001735int abis_nm_bs11_bsc_disconnect(struct gsm_bts *bts, int reconnect)
1736{
1737 if (reconnect == 0)
1738 return __simple_cmd(bts, NM_MT_BS11_DISCONNECT);
1739 else
1740 return __simple_cmd(bts, NM_MT_BS11_RECONNECT);
1741}
1742
Harald Welteb8427972009-02-05 19:27:17 +00001743int abis_nm_bs11_restart(struct gsm_bts *bts)
1744{
1745 return __simple_cmd(bts, NM_MT_BS11_RESTART);
1746}
1747
1748
Harald Welte268bb402009-02-01 19:11:56 +00001749struct bs11_date_time {
1750 u_int16_t year;
1751 u_int8_t month;
1752 u_int8_t day;
1753 u_int8_t hour;
1754 u_int8_t min;
1755 u_int8_t sec;
1756} __attribute__((packed));
1757
1758
1759void get_bs11_date_time(struct bs11_date_time *aet)
1760{
1761 time_t t;
1762 struct tm *tm;
1763
1764 t = time(NULL);
1765 tm = localtime(&t);
1766 aet->sec = tm->tm_sec;
1767 aet->min = tm->tm_min;
1768 aet->hour = tm->tm_hour;
1769 aet->day = tm->tm_mday;
1770 aet->month = tm->tm_mon;
1771 aet->year = htons(1900 + tm->tm_year);
1772}
1773
Harald Welte05188ee2009-01-18 11:39:08 +00001774int abis_nm_bs11_reset_resource(struct gsm_bts *bts)
Harald Welte52b1f982008-12-23 20:25:15 +00001775{
Harald Welte4668fda2009-01-03 08:19:29 +00001776 return __simple_cmd(bts, NM_MT_BS11_RESET_RESOURCE);
Harald Welte52b1f982008-12-23 20:25:15 +00001777}
1778
Harald Welte05188ee2009-01-18 11:39:08 +00001779int abis_nm_bs11_db_transmission(struct gsm_bts *bts, int begin)
Harald Welte52b1f982008-12-23 20:25:15 +00001780{
1781 if (begin)
Harald Welte4668fda2009-01-03 08:19:29 +00001782 return __simple_cmd(bts, NM_MT_BS11_BEGIN_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00001783 else
Harald Welte4668fda2009-01-03 08:19:29 +00001784 return __simple_cmd(bts, NM_MT_BS11_END_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00001785}
Harald Welte47d88ae2009-01-04 12:02:08 +00001786
Harald Welte05188ee2009-01-18 11:39:08 +00001787int abis_nm_bs11_create_object(struct gsm_bts *bts,
Harald Welte1bc09062009-01-18 14:17:52 +00001788 enum abis_bs11_objtype type, u_int8_t idx,
1789 u_int8_t attr_len, const u_int8_t *attr)
Harald Welte47d88ae2009-01-04 12:02:08 +00001790{
1791 struct abis_om_hdr *oh;
1792 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00001793 u_int8_t *cur;
Harald Welte47d88ae2009-01-04 12:02:08 +00001794
1795 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001796 fill_om_fom_hdr(oh, attr_len, NM_MT_BS11_CREATE_OBJ,
Harald Welte268bb402009-02-01 19:11:56 +00001797 NM_OC_BS11, type, 0, idx);
Harald Welte1bc09062009-01-18 14:17:52 +00001798 cur = msgb_put(msg, attr_len);
1799 memcpy(cur, attr, attr_len);
Harald Welte47d88ae2009-01-04 12:02:08 +00001800
1801 return abis_nm_sendmsg(bts, msg);
1802}
1803
Harald Welte78fc0d42009-02-19 02:50:57 +00001804int abis_nm_bs11_delete_object(struct gsm_bts *bts,
1805 enum abis_bs11_objtype type, u_int8_t idx)
1806{
1807 struct abis_om_hdr *oh;
1808 struct msgb *msg = nm_msgb_alloc();
1809
1810 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1811 fill_om_fom_hdr(oh, 0, NM_MT_BS11_DELETE_OBJ,
1812 NM_OC_BS11, type, 0, idx);
1813
1814 return abis_nm_sendmsg(bts, msg);
1815}
1816
Harald Welte05188ee2009-01-18 11:39:08 +00001817int abis_nm_bs11_create_envaBTSE(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00001818{
1819 struct abis_om_hdr *oh;
1820 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00001821 u_int8_t zero = 0x00;
Harald Welte47d88ae2009-01-04 12:02:08 +00001822
1823 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001824 fill_om_fom_hdr(oh, 3, NM_MT_BS11_CREATE_OBJ,
Harald Welte1bc09062009-01-18 14:17:52 +00001825 NM_OC_BS11_ENVABTSE, 0, idx, 0xff);
1826 msgb_tlv_put(msg, 0x99, 1, &zero);
Harald Welte47d88ae2009-01-04 12:02:08 +00001827
1828 return abis_nm_sendmsg(bts, msg);
1829}
1830
Harald Welte05188ee2009-01-18 11:39:08 +00001831int abis_nm_bs11_create_bport(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00001832{
1833 struct abis_om_hdr *oh;
1834 struct msgb *msg = nm_msgb_alloc();
1835
1836 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1837 fill_om_fom_hdr(oh, 0, NM_MT_BS11_CREATE_OBJ, NM_OC_BS11_BPORT,
1838 idx, 0, 0);
1839
1840 return abis_nm_sendmsg(bts, msg);
1841}
Harald Welte05188ee2009-01-18 11:39:08 +00001842
Harald Welte78fc0d42009-02-19 02:50:57 +00001843static const u_int8_t sm_attr[] = { NM_ATT_TEI, NM_ATT_ABIS_CHANNEL };
1844int abis_nm_bs11_get_oml_tei_ts(struct gsm_bts *bts)
1845{
1846 struct abis_om_hdr *oh;
1847 struct msgb *msg = nm_msgb_alloc();
1848
1849 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1850 fill_om_fom_hdr(oh, 2+sizeof(sm_attr), NM_MT_GET_ATTR, NM_OC_SITE_MANAGER,
1851 0xff, 0xff, 0xff);
1852 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(sm_attr), sm_attr);
1853
1854 return abis_nm_sendmsg(bts, msg);
1855}
1856
Harald Welteb6c92ae2009-02-21 20:15:32 +00001857/* like abis_nm_conn_terr_traf + set_tei */
1858int abis_nm_bs11_conn_oml_tei(struct gsm_bts *bts, u_int8_t e1_port,
1859 u_int8_t e1_timeslot, u_int8_t e1_subslot,
1860 u_int8_t tei)
Harald Welte05188ee2009-01-18 11:39:08 +00001861{
1862 struct abis_om_hdr *oh;
1863 struct abis_nm_channel *ch;
1864 struct msgb *msg = nm_msgb_alloc();
1865
1866 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welteb6c92ae2009-02-21 20:15:32 +00001867 fill_om_fom_hdr(oh, sizeof(*ch)+2, NM_MT_BS11_SET_ATTR,
Harald Welte05188ee2009-01-18 11:39:08 +00001868 NM_OC_SITE_MANAGER, 0xff, 0xff, 0xff);
1869
1870 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1871 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
Harald Welteb6c92ae2009-02-21 20:15:32 +00001872 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte05188ee2009-01-18 11:39:08 +00001873
1874 return abis_nm_sendmsg(bts, msg);
1875}
1876
1877int abis_nm_bs11_set_trx_power(struct gsm_bts_trx *trx, u_int8_t level)
1878{
1879 struct abis_om_hdr *oh;
1880 struct msgb *msg = nm_msgb_alloc();
Harald Welte05188ee2009-01-18 11:39:08 +00001881
1882 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001883 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR,
Harald Welte05188ee2009-01-18 11:39:08 +00001884 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
1885 msgb_tlv_put(msg, NM_ATT_BS11_TXPWR, 1, &level);
1886
1887 return abis_nm_sendmsg(trx->bts, msg);
1888}
1889
Harald Welte78fc0d42009-02-19 02:50:57 +00001890int abis_nm_bs11_get_trx_power(struct gsm_bts_trx *trx)
1891{
1892 struct abis_om_hdr *oh;
1893 struct msgb *msg = nm_msgb_alloc();
1894 u_int8_t attr = NM_ATT_BS11_TXPWR;
1895
1896 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1897 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
1898 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
1899 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), &attr);
1900
1901 return abis_nm_sendmsg(trx->bts, msg);
1902}
1903
Harald Welteaaf02d92009-04-29 13:25:57 +00001904int abis_nm_bs11_get_pll_mode(struct gsm_bts *bts)
1905{
1906 struct abis_om_hdr *oh;
1907 struct msgb *msg = nm_msgb_alloc();
Harald Weltea7cfa032009-04-29 22:33:02 +00001908 u_int8_t attr[] = { NM_ATT_BS11_PLL_MODE };
Harald Welteaaf02d92009-04-29 13:25:57 +00001909
1910 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1911 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
1912 NM_OC_BS11, BS11_OBJ_LI, 0x00, 0x00);
Harald Welteaeedeb42009-05-01 13:08:14 +00001913 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), attr);
Harald Welteaaf02d92009-04-29 13:25:57 +00001914
1915 return abis_nm_sendmsg(bts, msg);
1916}
1917
Harald Welteef061952009-05-17 12:43:42 +00001918int abis_nm_bs11_get_cclk(struct gsm_bts *bts)
1919{
1920 struct abis_om_hdr *oh;
1921 struct msgb *msg = nm_msgb_alloc();
1922 u_int8_t attr[] = { NM_ATT_BS11_CCLK_ACCURACY,
1923 NM_ATT_BS11_CCLK_TYPE };
1924
1925 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1926 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
1927 NM_OC_BS11, BS11_OBJ_CCLK, 0x00, 0x00);
1928 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), attr);
1929
1930 return abis_nm_sendmsg(bts, msg);
1931
1932}
Harald Welteaaf02d92009-04-29 13:25:57 +00001933
Harald Welte268bb402009-02-01 19:11:56 +00001934//static const u_int8_t bs11_logon_c7[] = { 0x07, 0xd9, 0x01, 0x11, 0x0d, 0x10, 0x20 };
Harald Weltebb151312009-01-28 20:42:07 +00001935static const u_int8_t bs11_logon_c8[] = { 0x02 };
Harald Welte05188ee2009-01-18 11:39:08 +00001936static const u_int8_t bs11_logon_c9[] = "FACTORY";
1937
Harald Welte1bc09062009-01-18 14:17:52 +00001938int abis_nm_bs11_factory_logon(struct gsm_bts *bts, int on)
Harald Welte05188ee2009-01-18 11:39:08 +00001939{
1940 struct abis_om_hdr *oh;
1941 struct msgb *msg = nm_msgb_alloc();
Harald Welte268bb402009-02-01 19:11:56 +00001942 struct bs11_date_time bdt;
1943
1944 get_bs11_date_time(&bdt);
Harald Welte05188ee2009-01-18 11:39:08 +00001945
1946 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte1bc09062009-01-18 14:17:52 +00001947 if (on) {
Harald Welte268bb402009-02-01 19:11:56 +00001948 u_int8_t len = 3*2 + sizeof(bdt)
Harald Welte6f676a32009-01-18 14:27:48 +00001949 + sizeof(bs11_logon_c8) + sizeof(bs11_logon_c9);
Harald Welte043d04a2009-01-29 23:15:30 +00001950 fill_om_fom_hdr(oh, len, NM_MT_BS11_LMT_LOGON,
Harald Welte7b26bcb2009-05-28 11:39:21 +00001951 NM_OC_BS11_BTSE, 0xff, 0xff, 0xff);
Harald Welte043d04a2009-01-29 23:15:30 +00001952 msgb_tlv_put(msg, NM_ATT_BS11_LMT_LOGIN_TIME,
Harald Welte5083b0b2009-02-02 19:20:52 +00001953 sizeof(bdt), (u_int8_t *) &bdt);
Harald Welte043d04a2009-01-29 23:15:30 +00001954 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_ACC_LEV,
1955 sizeof(bs11_logon_c8), bs11_logon_c8);
1956 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_NAME,
1957 sizeof(bs11_logon_c9), bs11_logon_c9);
Harald Welte1bc09062009-01-18 14:17:52 +00001958 } else {
Harald Welte5e4d1b32009-02-01 13:36:56 +00001959 fill_om_fom_hdr(oh, 0, NM_MT_BS11_LMT_LOGOFF,
Harald Welte7b26bcb2009-05-28 11:39:21 +00001960 NM_OC_BS11_BTSE, 0xff, 0xff, 0xff);
Harald Welte1bc09062009-01-18 14:17:52 +00001961 }
Harald Welte05188ee2009-01-18 11:39:08 +00001962
1963 return abis_nm_sendmsg(bts, msg);
1964}
Harald Welte1bc09062009-01-18 14:17:52 +00001965
1966int abis_nm_bs11_set_trx1_pw(struct gsm_bts *bts, const char *password)
1967{
1968 struct abis_om_hdr *oh;
1969 struct msgb *msg;
1970
1971 if (strlen(password) != 10)
1972 return -EINVAL;
1973
1974 msg = nm_msgb_alloc();
1975 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001976 fill_om_fom_hdr(oh, 2+strlen(password), NM_MT_BS11_SET_ATTR,
Harald Welte1bc09062009-01-18 14:17:52 +00001977 NM_OC_BS11, BS11_OBJ_TRX1, 0x00, 0x00);
1978 msgb_tlv_put(msg, NM_ATT_BS11_PASSWORD, 10, (const u_int8_t *)password);
1979
1980 return abis_nm_sendmsg(bts, msg);
1981}
1982
Harald Weltee69f5fb2009-04-28 16:31:38 +00001983/* change the BS-11 PLL Mode to either locked (E1 derived) or standalone */
1984int abis_nm_bs11_set_pll_locked(struct gsm_bts *bts, int locked)
1985{
1986 struct abis_om_hdr *oh;
1987 struct msgb *msg;
Harald Weltea432cd32009-04-29 13:01:50 +00001988 u_int8_t tlv_value;
Harald Weltee69f5fb2009-04-28 16:31:38 +00001989
1990 msg = nm_msgb_alloc();
1991 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1992 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR, NM_OC_BS11,
1993 BS11_OBJ_LI, 0x00, 0x00);
Harald Weltea432cd32009-04-29 13:01:50 +00001994
1995 if (locked)
1996 tlv_value = BS11_LI_PLL_LOCKED;
1997 else
1998 tlv_value = BS11_LI_PLL_STANDALONE;
1999
2000 msgb_tlv_put(msg, NM_ATT_BS11_PLL_MODE, 1, &tlv_value);
Harald Weltee69f5fb2009-04-28 16:31:38 +00002001
2002 return abis_nm_sendmsg(bts, msg);
2003}
2004
Harald Welte1bc09062009-01-18 14:17:52 +00002005int abis_nm_bs11_get_state(struct gsm_bts *bts)
2006{
2007 return __simple_cmd(bts, NM_MT_BS11_GET_STATE);
2008}
Harald Welte5e4d1b32009-02-01 13:36:56 +00002009
2010/* BS11 SWL */
2011
Harald Welte2cf161b2009-06-20 22:36:41 +02002012static void *tall_fle_ctx;
2013
Harald Welte5e4d1b32009-02-01 13:36:56 +00002014struct abis_nm_bs11_sw {
2015 struct gsm_bts *bts;
2016 char swl_fname[PATH_MAX];
2017 u_int8_t win_size;
Harald Welte3ffd1372009-02-01 22:15:49 +00002018 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00002019 struct llist_head file_list;
2020 gsm_cbfn *user_cb; /* specified by the user */
2021};
2022static struct abis_nm_bs11_sw _g_bs11_sw, *g_bs11_sw = &_g_bs11_sw;
2023
2024struct file_list_entry {
2025 struct llist_head list;
2026 char fname[PATH_MAX];
2027};
2028
2029struct file_list_entry *fl_dequeue(struct llist_head *queue)
2030{
2031 struct llist_head *lh;
2032
2033 if (llist_empty(queue))
2034 return NULL;
2035
2036 lh = queue->next;
2037 llist_del(lh);
2038
2039 return llist_entry(lh, struct file_list_entry, list);
2040}
2041
2042static int bs11_read_swl_file(struct abis_nm_bs11_sw *bs11_sw)
2043{
2044 char linebuf[255];
2045 struct llist_head *lh, *lh2;
2046 FILE *swl;
2047 int rc = 0;
2048
Harald Welte2cf161b2009-06-20 22:36:41 +02002049 if (!tall_fle_ctx)
2050 tall_fle_ctx = talloc_named_const(tall_bsc_ctx, 1,
2051 "bs11_file_list_entry");
2052
Harald Welte5e4d1b32009-02-01 13:36:56 +00002053 swl = fopen(bs11_sw->swl_fname, "r");
2054 if (!swl)
2055 return -ENODEV;
2056
2057 /* zero the stale file list, if any */
2058 llist_for_each_safe(lh, lh2, &bs11_sw->file_list) {
2059 llist_del(lh);
Harald Welte2cf161b2009-06-20 22:36:41 +02002060 talloc_free(lh);
Harald Welte5e4d1b32009-02-01 13:36:56 +00002061 }
2062
2063 while (fgets(linebuf, sizeof(linebuf), swl)) {
2064 char file_id[12+1];
2065 char file_version[80+1];
2066 struct file_list_entry *fle;
2067 static char dir[PATH_MAX];
2068
2069 if (strlen(linebuf) < 4)
2070 continue;
Harald Welte3ffd1372009-02-01 22:15:49 +00002071
Harald Welte5e4d1b32009-02-01 13:36:56 +00002072 rc = sscanf(linebuf+4, "%12s:%80s\r\n", file_id, file_version);
2073 if (rc < 0) {
2074 perror("ERR parsing SWL file");
2075 rc = -EINVAL;
2076 goto out;
2077 }
2078 if (rc < 2)
2079 continue;
2080
Harald Welte2cf161b2009-06-20 22:36:41 +02002081 fle = talloc(tall_fle_ctx, struct file_list_entry);
Harald Welte5e4d1b32009-02-01 13:36:56 +00002082 if (!fle) {
2083 rc = -ENOMEM;
2084 goto out;
2085 }
2086 memset(fle, 0, sizeof(*fle));
2087
2088 /* construct new filename */
2089 strncpy(dir, bs11_sw->swl_fname, sizeof(dir));
2090 strncat(fle->fname, dirname(dir), sizeof(fle->fname) - 1);
2091 strcat(fle->fname, "/");
2092 strncat(fle->fname, file_id, sizeof(fle->fname) - 1 -strlen(fle->fname));
Harald Welte5e4d1b32009-02-01 13:36:56 +00002093
2094 llist_add_tail(&fle->list, &bs11_sw->file_list);
2095 }
2096
2097out:
2098 fclose(swl);
2099 return rc;
2100}
2101
2102/* bs11 swload specific callback, passed to abis_nm core swload */
2103static int bs11_swload_cbfn(unsigned int hook, unsigned int event,
2104 struct msgb *msg, void *data, void *param)
2105{
2106 struct abis_nm_bs11_sw *bs11_sw = data;
2107 struct file_list_entry *fle;
2108 int rc = 0;
2109
Harald Welte5e4d1b32009-02-01 13:36:56 +00002110 switch (event) {
2111 case NM_MT_LOAD_END_ACK:
2112 fle = fl_dequeue(&bs11_sw->file_list);
2113 if (fle) {
2114 /* start download the next file of our file list */
2115 rc = abis_nm_software_load(bs11_sw->bts, fle->fname,
2116 bs11_sw->win_size,
Harald Welte3ffd1372009-02-01 22:15:49 +00002117 bs11_sw->forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00002118 &bs11_swload_cbfn, bs11_sw);
2119 free(fle);
2120 } else {
2121 /* activate the SWL */
2122 rc = abis_nm_software_activate(bs11_sw->bts,
2123 bs11_sw->swl_fname,
2124 bs11_swload_cbfn,
2125 bs11_sw);
2126 }
2127 break;
Harald Welte3ffd1372009-02-01 22:15:49 +00002128 case NM_MT_LOAD_SEG_ACK:
Harald Welte5e4d1b32009-02-01 13:36:56 +00002129 case NM_MT_LOAD_END_NACK:
2130 case NM_MT_LOAD_INIT_ACK:
2131 case NM_MT_LOAD_INIT_NACK:
2132 case NM_MT_ACTIVATE_SW_NACK:
2133 case NM_MT_ACTIVATE_SW_ACK:
2134 default:
2135 /* fallthrough to the user callback */
Harald Welte97ed1e72009-02-06 13:38:02 +00002136 if (bs11_sw->user_cb)
2137 rc = bs11_sw->user_cb(hook, event, msg, NULL, NULL);
Harald Welte5e4d1b32009-02-01 13:36:56 +00002138 break;
2139 }
2140
2141 return rc;
2142}
2143
2144/* Siemens provides a SWL file that is a mere listing of all the other
2145 * files that are part of a software release. We need to upload first
2146 * the list file, and then each file that is listed in the list file */
2147int abis_nm_bs11_load_swl(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00002148 u_int8_t win_size, int forced, gsm_cbfn *cbfn)
Harald Welte5e4d1b32009-02-01 13:36:56 +00002149{
2150 struct abis_nm_bs11_sw *bs11_sw = g_bs11_sw;
2151 struct file_list_entry *fle;
2152 int rc = 0;
2153
2154 INIT_LLIST_HEAD(&bs11_sw->file_list);
2155 bs11_sw->bts = bts;
2156 bs11_sw->win_size = win_size;
2157 bs11_sw->user_cb = cbfn;
Harald Welte3ffd1372009-02-01 22:15:49 +00002158 bs11_sw->forced = forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00002159
2160 strncpy(bs11_sw->swl_fname, fname, sizeof(bs11_sw->swl_fname));
2161 rc = bs11_read_swl_file(bs11_sw);
2162 if (rc < 0)
2163 return rc;
2164
2165 /* dequeue next item in file list */
2166 fle = fl_dequeue(&bs11_sw->file_list);
2167 if (!fle)
2168 return -EINVAL;
2169
2170 /* start download the next file of our file list */
Harald Welte3ffd1372009-02-01 22:15:49 +00002171 rc = abis_nm_software_load(bts, fle->fname, win_size, forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00002172 bs11_swload_cbfn, bs11_sw);
2173 free(fle);
2174 return rc;
2175}
2176
Harald Welte5083b0b2009-02-02 19:20:52 +00002177#if 0
Harald Welte5e4d1b32009-02-01 13:36:56 +00002178static u_int8_t req_attr_btse[] = {
2179 NM_ATT_ADM_STATE, NM_ATT_BS11_LMT_LOGON_SESSION,
2180 NM_ATT_BS11_LMT_LOGIN_TIME, NM_ATT_BS11_LMT_USER_ACC_LEV,
2181 NM_ATT_BS11_LMT_USER_NAME,
2182
2183 0xaf, NM_ATT_BS11_RX_OFFSET, NM_ATT_BS11_VENDOR_NAME,
2184
2185 NM_ATT_BS11_SW_LOAD_INTENDED, NM_ATT_BS11_SW_LOAD_SAFETY,
2186
2187 NM_ATT_BS11_SW_LOAD_STORED };
2188
2189static u_int8_t req_attr_btsm[] = {
2190 NM_ATT_ABIS_CHANNEL, NM_ATT_TEI, NM_ATT_BS11_ABIS_EXT_TIME,
2191 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xce, NM_ATT_FILE_ID,
2192 NM_ATT_FILE_VERSION, NM_ATT_OPER_STATE, 0xe8, NM_ATT_BS11_ALL_TEST_CATG,
2193 NM_ATT_SW_DESCR, NM_ATT_GET_ARI };
Harald Welte5083b0b2009-02-02 19:20:52 +00002194#endif
Harald Welte5e4d1b32009-02-01 13:36:56 +00002195
2196static u_int8_t req_attr[] = {
2197 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xa8, NM_ATT_OPER_STATE,
2198 0xd5, 0xa1, NM_ATT_BS11_ESN_FW_CODE_NO, NM_ATT_BS11_ESN_HW_CODE_NO,
Harald Weltea7cfa032009-04-29 22:33:02 +00002199 0x42, NM_ATT_BS11_ESN_PCB_SERIAL, NM_ATT_BS11_PLL };
Harald Welte5e4d1b32009-02-01 13:36:56 +00002200
2201int abis_nm_bs11_get_serno(struct gsm_bts *bts)
2202{
2203 struct abis_om_hdr *oh;
2204 struct msgb *msg = nm_msgb_alloc();
2205
2206 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2207 /* SiemensHW CCTRL object */
2208 fill_om_fom_hdr(oh, 2+sizeof(req_attr), NM_MT_GET_ATTR, NM_OC_BS11,
2209 0x03, 0x00, 0x00);
2210 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(req_attr), req_attr);
2211
2212 return abis_nm_sendmsg(bts, msg);
2213}
Harald Welte268bb402009-02-01 19:11:56 +00002214
2215int abis_nm_bs11_set_ext_time(struct gsm_bts *bts)
2216{
2217 struct abis_om_hdr *oh;
2218 struct msgb *msg = nm_msgb_alloc();
2219 struct bs11_date_time aet;
2220
2221 get_bs11_date_time(&aet);
2222 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2223 /* SiemensHW CCTRL object */
2224 fill_om_fom_hdr(oh, 2+sizeof(aet), NM_MT_BS11_SET_ATTR, NM_OC_SITE_MANAGER,
2225 0xff, 0xff, 0xff);
Harald Welte5083b0b2009-02-02 19:20:52 +00002226 msgb_tlv_put(msg, NM_ATT_BS11_ABIS_EXT_TIME, sizeof(aet), (u_int8_t *) &aet);
Harald Welte268bb402009-02-01 19:11:56 +00002227
2228 return abis_nm_sendmsg(bts, msg);
2229}
Harald Welte5c1e4582009-02-15 11:57:29 +00002230
2231/* ip.access nanoBTS specific commands */
Harald Welte5c1e4582009-02-15 11:57:29 +00002232static const char ipaccess_magic[] = "com.ipaccess";
2233
Harald Welte677c21f2009-02-17 13:22:23 +00002234
2235static int abis_nm_rx_ipacc(struct msgb *msg)
2236{
2237 struct abis_om_hdr *oh = msgb_l2(msg);
2238 struct abis_om_fom_hdr *foh;
2239 u_int8_t idstrlen = oh->data[0];
2240 struct tlv_parsed tp;
2241
2242 if (strncmp((char *)&oh->data[1], ipaccess_magic, idstrlen)) {
2243 DEBUGP(DNM, "id string is not com.ipaccess !?!\n");
2244 return -EINVAL;
2245 }
2246
Harald Welte193fefc2009-04-30 15:16:27 +00002247 foh = (struct abis_om_fom_hdr *) (oh->data + 1 + idstrlen);
Harald Welte03133942009-02-18 19:51:53 +00002248 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Welte677c21f2009-02-17 13:22:23 +00002249
Harald Welte193fefc2009-04-30 15:16:27 +00002250 DEBUGP(DNM, "IPACCESS(0x%02x): ", foh->msg_type);
2251
Harald Welte677c21f2009-02-17 13:22:23 +00002252 switch (foh->msg_type) {
2253 case NM_MT_IPACC_RSL_CONNECT_ACK:
Harald Welte193fefc2009-04-30 15:16:27 +00002254 DEBUGPC(DNM, "RSL CONNECT ACK ");
Harald Welte677c21f2009-02-17 13:22:23 +00002255 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_RSL_BSC_IP))
Harald Welte9de2bf82009-04-30 15:59:55 +00002256 DEBUGPC(DNM, "IP=%s ",
Harald Welte677c21f2009-02-17 13:22:23 +00002257 inet_ntoa(*((struct in_addr *)
2258 TLVP_VAL(&tp, NM_ATT_IPACC_RSL_BSC_IP))));
2259 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_RSL_BSC_PORT))
Harald Welte9de2bf82009-04-30 15:59:55 +00002260 DEBUGPC(DNM, "PORT=%u ",
Harald Welte677c21f2009-02-17 13:22:23 +00002261 ntohs(*((u_int16_t *)
2262 TLVP_VAL(&tp, NM_ATT_IPACC_RSL_BSC_PORT))));
Harald Welte9de2bf82009-04-30 15:59:55 +00002263 DEBUGPC(DNM, "\n");
Harald Welte677c21f2009-02-17 13:22:23 +00002264 break;
2265 case NM_MT_IPACC_RSL_CONNECT_NACK:
Harald Welte193fefc2009-04-30 15:16:27 +00002266 DEBUGPC(DNM, "RSL CONNECT NACK ");
Harald Welte677c21f2009-02-17 13:22:23 +00002267 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
Harald Welte6c96ba52009-05-01 13:03:40 +00002268 DEBUGPC(DNM, " CAUSE=%s\n",
2269 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
Harald Welte677c21f2009-02-17 13:22:23 +00002270 else
2271 DEBUGPC(DNM, "\n");
2272 break;
Harald Welte193fefc2009-04-30 15:16:27 +00002273 case NM_MT_IPACC_SET_NVATTR_ACK:
2274 DEBUGPC(DNM, "SET NVATTR ACK\n");
2275 /* FIXME: decode and show the actual attributes */
2276 break;
2277 case NM_MT_IPACC_SET_NVATTR_NACK:
Harald Welte6c96ba52009-05-01 13:03:40 +00002278 DEBUGPC(DNM, "SET NVATTR NACK ");
2279 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
2280 DEBUGPC(DNM, " CAUSE=%s\n",
2281 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
2282 else
2283 DEBUGPC(DNM, "\n");
Harald Welte193fefc2009-04-30 15:16:27 +00002284 break;
2285 default:
2286 DEBUGPC(DNM, "unknown\n");
2287 break;
Harald Welte677c21f2009-02-17 13:22:23 +00002288 }
2289 return 0;
2290}
2291
Harald Welte193fefc2009-04-30 15:16:27 +00002292/* send an ip-access manufacturer specific message */
Harald Welte5c1e4582009-02-15 11:57:29 +00002293int abis_nm_ipaccess_msg(struct gsm_bts *bts, u_int8_t msg_type,
2294 u_int8_t obj_class, u_int8_t bts_nr,
2295 u_int8_t trx_nr, u_int8_t ts_nr,
2296 u_int8_t *attr, int attr_len)
2297{
2298 struct msgb *msg = nm_msgb_alloc();
2299 struct abis_om_hdr *oh;
2300 struct abis_om_fom_hdr *foh;
2301 u_int8_t *data;
2302
2303 /* construct the 12.21 OM header, observe the erroneous length */
2304 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
2305 fill_om_hdr(oh, sizeof(*foh) + attr_len);
2306 oh->mdisc = ABIS_OM_MDISC_MANUF;
2307
2308 /* add the ip.access magic */
2309 data = msgb_put(msg, sizeof(ipaccess_magic)+1);
2310 *data++ = sizeof(ipaccess_magic);
2311 memcpy(data, ipaccess_magic, sizeof(ipaccess_magic));
2312
2313 /* fill the 12.21 FOM header */
2314 foh = (struct abis_om_fom_hdr *) msgb_put(msg, sizeof(*foh));
2315 foh->msg_type = msg_type;
2316 foh->obj_class = obj_class;
2317 foh->obj_inst.bts_nr = bts_nr;
2318 foh->obj_inst.trx_nr = trx_nr;
2319 foh->obj_inst.ts_nr = ts_nr;
2320
2321 if (attr && attr_len) {
2322 data = msgb_put(msg, attr_len);
2323 memcpy(data, attr, attr_len);
2324 }
2325
2326 return abis_nm_sendmsg(bts, msg);
2327}
Harald Welte677c21f2009-02-17 13:22:23 +00002328
Harald Welte193fefc2009-04-30 15:16:27 +00002329/* set some attributes in NVRAM */
2330int abis_nm_ipaccess_set_nvattr(struct gsm_bts *bts, u_int8_t *attr,
2331 int attr_len)
2332{
2333 return abis_nm_ipaccess_msg(bts, NM_MT_IPACC_SET_NVATTR,
2334 NM_OC_BASEB_TRANSC, 0, 0, 0xff, attr,
2335 attr_len);
2336}
2337
2338/* restart / reboot an ip.access nanoBTS */
2339int abis_nm_ipaccess_restart(struct gsm_bts *bts)
2340{
2341 return __simple_cmd(bts, NM_MT_IPACC_RESTART);
2342}