blob: 74dba2377d6cf3a37c5ac6c1e848a83ffc80bfc3 [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 Welte52b1f982008-12-23 20:25:15 +000046
Harald Welte8470bf22008-12-25 23:28:35 +000047#define OM_ALLOC_SIZE 1024
48#define OM_HEADROOM_SIZE 128
Harald Welte52b1f982008-12-23 20:25:15 +000049
50/* unidirectional messages from BTS to BSC */
51static const enum abis_nm_msgtype reports[] = {
52 NM_MT_SW_ACTIVATED_REP,
53 NM_MT_TEST_REP,
54 NM_MT_STATECHG_EVENT_REP,
55 NM_MT_FAILURE_EVENT_REP,
56};
57
58/* messages without ACK/NACK */
59static const enum abis_nm_msgtype no_ack_nack[] = {
60 NM_MT_MEAS_RES_REQ,
61 NM_MT_STOP_MEAS,
62 NM_MT_START_MEAS,
63};
64
Harald Welte4724f992009-01-18 18:01:49 +000065/* Messages related to software load */
66static const enum abis_nm_msgtype sw_load_msgs[] = {
67 NM_MT_LOAD_INIT_ACK,
68 NM_MT_LOAD_INIT_NACK,
69 NM_MT_LOAD_SEG_ACK,
70 NM_MT_LOAD_ABORT,
71 NM_MT_LOAD_END_ACK,
72 NM_MT_LOAD_END_NACK,
Harald Welte34a99682009-02-13 02:41:40 +000073 //NM_MT_SW_ACT_REQ,
Harald Welte4724f992009-01-18 18:01:49 +000074 NM_MT_ACTIVATE_SW_ACK,
75 NM_MT_ACTIVATE_SW_NACK,
76 NM_MT_SW_ACTIVATED_REP,
77};
78
Harald Weltee0590df2009-02-15 03:34:15 +000079static const enum abis_nm_msgtype nacks[] = {
80 NM_MT_LOAD_INIT_NACK,
81 NM_MT_LOAD_END_NACK,
82 NM_MT_SW_ACT_REQ_NACK,
83 NM_MT_ACTIVATE_SW_NACK,
84 NM_MT_ESTABLISH_TEI_NACK,
85 NM_MT_CONN_TERR_SIGN_NACK,
86 NM_MT_DISC_TERR_SIGN_NACK,
87 NM_MT_CONN_TERR_TRAF_NACK,
88 NM_MT_DISC_TERR_TRAF_NACK,
89 NM_MT_CONN_MDROP_LINK_NACK,
90 NM_MT_DISC_MDROP_LINK_NACK,
91 NM_MT_SET_BTS_ATTR_NACK,
92 NM_MT_SET_RADIO_ATTR_NACK,
93 NM_MT_SET_CHAN_ATTR_NACK,
94 NM_MT_PERF_TEST_NACK,
95 NM_MT_SEND_TEST_REP_NACK,
96 NM_MT_STOP_TEST_NACK,
97 NM_MT_STOP_EVENT_REP_NACK,
98 NM_MT_REST_EVENT_REP_NACK,
99 NM_MT_CHG_ADM_STATE_NACK,
100 NM_MT_CHG_ADM_STATE_REQ_NACK,
101 NM_MT_REP_OUTST_ALARMS_NACK,
102 NM_MT_CHANGEOVER_NACK,
103 NM_MT_OPSTART_NACK,
104 NM_MT_REINIT_NACK,
105 NM_MT_SET_SITE_OUT_NACK,
106 NM_MT_CHG_HW_CONF_NACK,
107 NM_MT_GET_ATTR_NACK,
108 NM_MT_SET_ALARM_THRES_NACK,
109 NM_MT_BS11_BEGIN_DB_TX_NACK,
110 NM_MT_BS11_END_DB_TX_NACK,
111 NM_MT_BS11_CREATE_OBJ_NACK,
112 NM_MT_BS11_DELETE_OBJ_NACK,
113};
Harald Welte78fc0d42009-02-19 02:50:57 +0000114
115static const char *nack_names[0xff] = {
116 [NM_MT_LOAD_INIT_NACK] = "SOFTWARE LOAD INIT",
117 [NM_MT_LOAD_END_NACK] = "SOFTWARE LOAD END",
118 [NM_MT_SW_ACT_REQ_NACK] = "SOFTWARE ACTIVATE REQUEST",
119 [NM_MT_ACTIVATE_SW_NACK] = "ACTIVATE SOFTWARE",
120 [NM_MT_ESTABLISH_TEI_NACK] = "ESTABLISH TEI",
121 [NM_MT_CONN_TERR_SIGN_NACK] = "CONNECT TERRESTRIAL SIGNALLING",
122 [NM_MT_DISC_TERR_SIGN_NACK] = "DISCONNECT TERRESTRIAL SIGNALLING",
123 [NM_MT_CONN_TERR_TRAF_NACK] = "CONNECT TERRESTRIAL TRAFFIC",
124 [NM_MT_DISC_TERR_TRAF_NACK] = "DISCONNECT TERRESTRIAL TRAFFIC",
125 [NM_MT_CONN_MDROP_LINK_NACK] = "CONNECT MULTI-DROP LINK",
126 [NM_MT_DISC_MDROP_LINK_NACK] = "DISCONNECT MULTI-DROP LINK",
127 [NM_MT_SET_BTS_ATTR_NACK] = "SET BTS ATTRIBUTE",
128 [NM_MT_SET_RADIO_ATTR_NACK] = "SET RADIO ATTRIBUTE",
129 [NM_MT_SET_CHAN_ATTR_NACK] = "SET CHANNEL ATTRIBUTE",
130 [NM_MT_PERF_TEST_NACK] = "PERFORM TEST",
131 [NM_MT_SEND_TEST_REP_NACK] = "SEND TEST REPORT",
132 [NM_MT_STOP_TEST_NACK] = "STOP TEST",
133 [NM_MT_STOP_EVENT_REP_NACK] = "STOP EVENT REPORT",
134 [NM_MT_REST_EVENT_REP_NACK] = "RESET EVENT REPORT",
135 [NM_MT_CHG_ADM_STATE_NACK] = "CHANGE ADMINISTRATIVE STATE",
136 [NM_MT_CHG_ADM_STATE_REQ_NACK] = "CHANGE ADMINISTRATIVE STATE REQUEST",
137 [NM_MT_REP_OUTST_ALARMS_NACK] = "REPORT OUTSTANDING ALARMS",
138 [NM_MT_CHANGEOVER_NACK] = "CHANGEOVER",
139 [NM_MT_OPSTART_NACK] = "OPSTART",
140 [NM_MT_REINIT_NACK] = "REINIT",
141 [NM_MT_SET_SITE_OUT_NACK] = "SET SITE OUTPUT",
142 [NM_MT_CHG_HW_CONF_NACK] = "CHANGE HARDWARE CONFIGURATION",
143 [NM_MT_GET_ATTR_NACK] = "GET ATTRIBUTE",
144 [NM_MT_SET_ALARM_THRES_NACK] = "SET ALARM THRESHOLD",
145 [NM_MT_BS11_BEGIN_DB_TX_NACK] = "BS11 BEGIN DATABASE TRANSMISSION",
146 [NM_MT_BS11_END_DB_TX_NACK] = "BS11 END DATABASE TRANSMISSION",
147 [NM_MT_BS11_CREATE_OBJ_NACK] = "BS11 CREATE OBJECT",
148 [NM_MT_BS11_DELETE_OBJ_NACK] = "BS11 DELETE OBJECT",
149};
150
Harald Welte6c96ba52009-05-01 13:03:40 +0000151/* Chapter 9.4.36 */
152static const char *nack_cause_names[] = {
153 /* General Nack Causes */
154 [NM_NACK_INCORR_STRUCT] = "Incorrect message structure",
155 [NM_NACK_MSGTYPE_INVAL] = "Invalid message type value",
156 [NM_NACK_OBJCLASS_INVAL] = "Invalid Object class value",
157 [NM_NACK_OBJCLASS_NOTSUPP] = "Object class not supported",
158 [NM_NACK_BTSNR_UNKN] = "BTS no. unknown",
159 [NM_NACK_TRXNR_UNKN] = "Baseband Transceiver no. unknown",
160 [NM_NACK_OBJINST_UNKN] = "Object Instance unknown",
161 [NM_NACK_ATTRID_INVAL] = "Invalid attribute identifier value",
162 [NM_NACK_ATTRID_NOTSUPP] = "Attribute identifier not supported",
163 [NM_NACK_PARAM_RANGE] = "Parameter value outside permitted range",
164 [NM_NACK_ATTRLIST_INCONSISTENT] = "Inconsistency in attribute list",
165 [NM_NACK_SPEC_IMPL_NOTSUPP] = "Specified implementation not supported",
166 [NM_NACK_CANT_PERFORM] = "Message cannot be performed",
167 /* Specific Nack Causes */
168 [NM_NACK_RES_NOTIMPL] = "Resource not implemented",
169 [NM_NACK_RES_NOTAVAIL] = "Resource not available",
170 [NM_NACK_FREQ_NOTAVAIL] = "Frequency not available",
171 [NM_NACK_TEST_NOTSUPP] = "Test not supported",
172 [NM_NACK_CAPACITY_RESTR] = "Capacity restrictions",
173 [NM_NACK_PHYSCFG_NOTPERFORM] = "Physical configuration cannot be performed",
174 [NM_NACK_TEST_NOTINIT] = "Test not initiated",
175 [NM_NACK_PHYSCFG_NOTRESTORE] = "Physical configuration cannot be restored",
176 [NM_NACK_TEST_NOSUCH] = "No such test",
177 [NM_NACK_TEST_NOSTOP] = "Test cannot be stopped",
178 [NM_NACK_MSGINCONSIST_PHYSCFG] = "Message inconsistent with physical configuration",
179 [NM_NACK_FILE_INCOMPLETE] = "Complete file notreceived",
180 [NM_NACK_FILE_NOTAVAIL] = "File not available at destination",
181 [MN_NACK_FILE_NOTACTIVATE] = "File cannot be activate",
182 [NM_NACK_REQ_NOT_GRANT] = "Request not granted",
183 [NM_NACK_WAIT] = "Wait",
184 [NM_NACK_NOTH_REPORT_EXIST] = "Nothing reportable existing",
185 [NM_NACK_MEAS_NOTSUPP] = "Measurement not supported",
186 [NM_NACK_MEAS_NOTSTART] = "Measurement not started",
187};
188
189static char namebuf[255];
190static const char *nack_cause_name(u_int8_t cause)
191{
192 if (cause < ARRAY_SIZE(nack_cause_names) && nack_cause_names[cause])
193 return nack_cause_names[cause];
194
195 snprintf(namebuf, sizeof(namebuf), "0x%02x\n", cause);
196 return namebuf;
197}
198
Harald Welte0db97b22009-05-01 17:22:47 +0000199/* Chapter 9.4.16: Event Type */
200static const char *event_type_names[] = {
201 [NM_EVT_COMM_FAIL] = "communication failure",
202 [NM_EVT_QOS_FAIL] = "quality of service failure",
203 [NM_EVT_PROC_FAIL] = "processing failure",
204 [NM_EVT_EQUIP_FAIL] = "equipment failure",
205 [NM_EVT_ENV_FAIL] = "environment failure",
206};
207
208static const char *event_type_name(u_int8_t cause)
209{
210 if (cause < ARRAY_SIZE(event_type_names) && event_type_names[cause])
211 return event_type_names[cause];
212
213 snprintf(namebuf, sizeof(namebuf), "0x%02x\n", cause);
214 return namebuf;
215}
216
217/* Chapter 9.4.63: Perceived Severity */
218static const char *severity_names[] = {
219 [NM_SEVER_CEASED] = "failure ceased",
220 [NM_SEVER_CRITICAL] = "critical failure",
221 [NM_SEVER_MAJOR] = "major failure",
222 [NM_SEVER_MINOR] = "minor failure",
223 [NM_SEVER_WARNING] = "warning level failure",
224 [NM_SEVER_INDETERMINATE] = "indeterminate failure",
225};
226
227static const char *severity_name(u_int8_t cause)
228{
229 if (cause < ARRAY_SIZE(severity_names) && severity_names[cause])
230 return severity_names[cause];
231
232 snprintf(namebuf, sizeof(namebuf), "0x%02x\n", cause);
233 return namebuf;
234}
235
Harald Welte52b1f982008-12-23 20:25:15 +0000236/* Attributes that the BSC can set, not only get, according to Section 9.4 */
237static const enum abis_nm_attr nm_att_settable[] = {
238 NM_ATT_ADD_INFO,
239 NM_ATT_ADD_TEXT,
240 NM_ATT_DEST,
241 NM_ATT_EVENT_TYPE,
242 NM_ATT_FILE_DATA,
243 NM_ATT_GET_ARI,
244 NM_ATT_HW_CONF_CHG,
245 NM_ATT_LIST_REQ_ATTR,
246 NM_ATT_MDROP_LINK,
247 NM_ATT_MDROP_NEXT,
248 NM_ATT_NACK_CAUSES,
249 NM_ATT_OUTST_ALARM,
250 NM_ATT_PHYS_CONF,
251 NM_ATT_PROB_CAUSE,
252 NM_ATT_RAD_SUBC,
253 NM_ATT_SOURCE,
254 NM_ATT_SPEC_PROB,
255 NM_ATT_START_TIME,
256 NM_ATT_TEST_DUR,
257 NM_ATT_TEST_NO,
258 NM_ATT_TEST_REPORT,
259 NM_ATT_WINDOW_SIZE,
260 NM_ATT_SEVERITY,
261 NM_ATT_MEAS_RES,
262 NM_ATT_MEAS_TYPE,
263};
264
Harald Weltee0590df2009-02-15 03:34:15 +0000265static const struct tlv_definition nm_att_tlvdef = {
266 .def = {
267 [NM_ATT_ABIS_CHANNEL] = { TLV_TYPE_FIXED, 3 },
268 [NM_ATT_ADD_INFO] = { TLV_TYPE_TL16V },
269 [NM_ATT_ADD_TEXT] = { TLV_TYPE_TL16V },
270 [NM_ATT_ADM_STATE] = { TLV_TYPE_TV },
271 [NM_ATT_ARFCN_LIST]= { TLV_TYPE_TL16V },
272 [NM_ATT_AUTON_REPORT] = { TLV_TYPE_TV },
273 [NM_ATT_AVAIL_STATUS] = { TLV_TYPE_TL16V },
274 [NM_ATT_BCCH_ARFCN] = { TLV_TYPE_FIXED, 2 },
275 [NM_ATT_BSIC] = { TLV_TYPE_TV },
276 [NM_ATT_BTS_AIR_TIMER] = { TLV_TYPE_TV },
277 [NM_ATT_CCCH_L_I_P] = { TLV_TYPE_TV },
278 [NM_ATT_CCCH_L_T] = { TLV_TYPE_TV },
279 [NM_ATT_CHAN_COMB] = { TLV_TYPE_TV },
280 [NM_ATT_CONN_FAIL_CRIT] = { TLV_TYPE_TL16V },
281 [NM_ATT_DEST] = { TLV_TYPE_TL16V },
282 [NM_ATT_EVENT_TYPE] = { TLV_TYPE_TV },
283 [NM_ATT_FILE_DATA] = { TLV_TYPE_TL16V },
284 [NM_ATT_FILE_ID] = { TLV_TYPE_TL16V },
285 [NM_ATT_FILE_VERSION] = { TLV_TYPE_TL16V },
286 [NM_ATT_GSM_TIME] = { TLV_TYPE_FIXED, 2 },
287 [NM_ATT_HSN] = { TLV_TYPE_TV },
288 [NM_ATT_HW_CONFIG] = { TLV_TYPE_TL16V },
289 [NM_ATT_HW_DESC] = { TLV_TYPE_TL16V },
290 [NM_ATT_INTAVE_PARAM] = { TLV_TYPE_TV },
291 [NM_ATT_INTERF_BOUND] = { TLV_TYPE_FIXED, 6 },
292 [NM_ATT_LIST_REQ_ATTR] = { TLV_TYPE_TL16V },
293 [NM_ATT_MAIO] = { TLV_TYPE_TV },
294 [NM_ATT_MANUF_STATE] = { TLV_TYPE_TV },
295 [NM_ATT_MANUF_THRESH] = { TLV_TYPE_TL16V },
296 [NM_ATT_MANUF_ID] = { TLV_TYPE_TL16V },
297 [NM_ATT_MAX_TA] = { TLV_TYPE_TV },
298 [NM_ATT_MDROP_LINK] = { TLV_TYPE_FIXED, 2 },
299 [NM_ATT_MDROP_NEXT] = { TLV_TYPE_FIXED, 2 },
300 [NM_ATT_NACK_CAUSES] = { TLV_TYPE_TV },
301 [NM_ATT_NY1] = { TLV_TYPE_TV },
302 [NM_ATT_OPER_STATE] = { TLV_TYPE_TV },
303 [NM_ATT_OVERL_PERIOD] = { TLV_TYPE_TL16V },
304 [NM_ATT_PHYS_CONF] = { TLV_TYPE_TL16V },
305 [NM_ATT_POWER_CLASS] = { TLV_TYPE_TV },
306 [NM_ATT_POWER_THRESH] = { TLV_TYPE_FIXED, 3 },
307 [NM_ATT_PROB_CAUSE] = { TLV_TYPE_FIXED, 3 },
308 [NM_ATT_RACH_B_THRESH] = { TLV_TYPE_TV },
309 [NM_ATT_LDAVG_SLOTS] = { TLV_TYPE_FIXED, 2 },
310 [NM_ATT_RAD_SUBC] = { TLV_TYPE_TV },
311 [NM_ATT_RF_MAXPOWR_R] = { TLV_TYPE_TV },
312 [NM_ATT_SITE_INPUTS] = { TLV_TYPE_TL16V },
313 [NM_ATT_SITE_OUTPUTS] = { TLV_TYPE_TL16V },
314 [NM_ATT_SOURCE] = { TLV_TYPE_TL16V },
315 [NM_ATT_SPEC_PROB] = { TLV_TYPE_TV },
316 [NM_ATT_START_TIME] = { TLV_TYPE_FIXED, 2 },
317 [NM_ATT_T200] = { TLV_TYPE_FIXED, 7 },
318 [NM_ATT_TEI] = { TLV_TYPE_TV },
319 [NM_ATT_TEST_DUR] = { TLV_TYPE_FIXED, 2 },
320 [NM_ATT_TEST_NO] = { TLV_TYPE_TV },
321 [NM_ATT_TEST_REPORT] = { TLV_TYPE_TL16V },
322 [NM_ATT_VSWR_THRESH] = { TLV_TYPE_FIXED, 2 },
323 [NM_ATT_WINDOW_SIZE] = { TLV_TYPE_TV },
324 [NM_ATT_TSC] = { TLV_TYPE_TV },
325 [NM_ATT_SW_CONFIG] = { TLV_TYPE_TL16V },
326 [NM_ATT_SEVERITY] = { TLV_TYPE_TV },
327 [NM_ATT_GET_ARI] = { TLV_TYPE_TL16V },
328 [NM_ATT_HW_CONF_CHG] = { TLV_TYPE_TL16V },
329 [NM_ATT_OUTST_ALARM] = { TLV_TYPE_TV },
330 [NM_ATT_FILE_DATA] = { TLV_TYPE_TL16V },
331 [NM_ATT_MEAS_RES] = { TLV_TYPE_TL16V },
332 /* BS11 specifics */
Harald Welte78fc0d42009-02-19 02:50:57 +0000333 [NM_ATT_BS11_ESN_FW_CODE_NO] = { TLV_TYPE_TLV },
334 [NM_ATT_BS11_ESN_HW_CODE_NO] = { TLV_TYPE_TLV },
335 [NM_ATT_BS11_ESN_PCB_SERIAL] = { TLV_TYPE_TLV },
336 [NM_ATT_BS11_BOOT_SW_VERS] = { TLV_TYPE_TLV },
337 [0xd5] = { TLV_TYPE_TLV },
338 [0xa8] = { TLV_TYPE_TLV },
Harald Weltee0590df2009-02-15 03:34:15 +0000339 [NM_ATT_BS11_PASSWORD] = { TLV_TYPE_TLV },
340 [NM_ATT_BS11_TXPWR] = { TLV_TYPE_TLV },
341 [NM_ATT_BS11_RSSI_OFFS] = { TLV_TYPE_TLV },
342 [NM_ATT_BS11_LINE_CFG] = { TLV_TYPE_TV },
343 [NM_ATT_BS11_L1_PROT_TYPE] = { TLV_TYPE_TV },
344 [NM_ATT_BS11_BIT_ERR_THESH] = { TLV_TYPE_FIXED, 2 },
345 [NM_ATT_BS11_DIVERSITY] = { TLV_TYPE_TLV },
Harald Welteee670472009-02-22 21:58:49 +0000346 [NM_ATT_BS11_LMT_LOGON_SESSION]={ TLV_TYPE_TLV },
Harald Weltee0590df2009-02-15 03:34:15 +0000347 [NM_ATT_BS11_LMT_LOGIN_TIME] = { TLV_TYPE_TLV },
348 [NM_ATT_BS11_LMT_USER_ACC_LEV] ={ TLV_TYPE_TLV },
349 [NM_ATT_BS11_LMT_USER_NAME] = { TLV_TYPE_TLV },
Harald Welte03133942009-02-18 19:51:53 +0000350 [NM_ATT_BS11_BTS_STATE] = { TLV_TYPE_TLV },
351 [NM_ATT_BS11_E1_STATE] = { TLV_TYPE_TLV },
Harald Welteaaf02d92009-04-29 13:25:57 +0000352 [NM_ATT_BS11_PLL_MODE] = { TLV_TYPE_TLV },
Harald Weltea7cfa032009-04-29 22:33:02 +0000353 [NM_ATT_BS11_PLL] = { TLV_TYPE_TLV },
Harald Welteef061952009-05-17 12:43:42 +0000354 [NM_ATT_BS11_CCLK_ACCURACY] = { TLV_TYPE_TV },
355 [NM_ATT_BS11_CCLK_TYPE] = { TLV_TYPE_TV },
Harald Welte677c21f2009-02-17 13:22:23 +0000356 /* ip.access specifics */
357 [NM_ATT_IPACC_RSL_BSC_IP] = { TLV_TYPE_FIXED, 4 },
358 [NM_ATT_IPACC_RSL_BSC_PORT] = { TLV_TYPE_FIXED, 2 },
Harald Welte3bfbb842009-04-29 22:58:38 +0000359 [NM_ATT_IPACC_PRIM_OML_IP] = { TLV_TYPE_FIXED, 6 },
360 [0x95] = { TLV_TYPE_FIXED, 2 },
Harald Welte677c21f2009-02-17 13:22:23 +0000361 [0x85] = { TLV_TYPE_TV },
362
Harald Weltee0590df2009-02-15 03:34:15 +0000363 },
364};
Harald Welte03133942009-02-18 19:51:53 +0000365
366int abis_nm_tlv_parse(struct tlv_parsed *tp, const u_int8_t *buf, int len)
367{
Harald Weltea4d49e92009-05-23 06:39:58 +0000368 return tlv_parse(tp, &nm_att_tlvdef, buf, len, 0, 0);
Harald Welte03133942009-02-18 19:51:53 +0000369}
Harald Weltee0590df2009-02-15 03:34:15 +0000370
Harald Welte52b1f982008-12-23 20:25:15 +0000371static int is_in_arr(enum abis_nm_msgtype mt, const enum abis_nm_msgtype *arr, int size)
372{
373 int i;
374
375 for (i = 0; i < size; i++) {
376 if (arr[i] == mt)
377 return 1;
378 }
379
380 return 0;
381}
382
Holger Freytherca362a62009-01-04 21:05:01 +0000383#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000384/* is this msgtype the usual ACK/NACK type ? */
385static int is_ack_nack(enum abis_nm_msgtype mt)
386{
387 return !is_in_arr(mt, no_ack_nack, ARRAY_SIZE(no_ack_nack));
388}
Holger Freytherca362a62009-01-04 21:05:01 +0000389#endif
Harald Welte52b1f982008-12-23 20:25:15 +0000390
391/* is this msgtype a report ? */
392static int is_report(enum abis_nm_msgtype mt)
393{
Harald Welte8470bf22008-12-25 23:28:35 +0000394 return is_in_arr(mt, reports, ARRAY_SIZE(reports));
Harald Welte52b1f982008-12-23 20:25:15 +0000395}
396
397#define MT_ACK(x) (x+1)
398#define MT_NACK(x) (x+2)
399
400static void fill_om_hdr(struct abis_om_hdr *oh, u_int8_t len)
401{
402 oh->mdisc = ABIS_OM_MDISC_FOM;
403 oh->placement = ABIS_OM_PLACEMENT_ONLY;
404 oh->sequence = 0;
405 oh->length = len;
406}
407
408static void fill_om_fom_hdr(struct abis_om_hdr *oh, u_int8_t len,
409 u_int8_t msg_type, u_int8_t obj_class,
410 u_int8_t bts_nr, u_int8_t trx_nr, u_int8_t ts_nr)
411{
412 struct abis_om_fom_hdr *foh =
413 (struct abis_om_fom_hdr *) oh->data;
414
Harald Welte702d8702008-12-26 20:25:35 +0000415 fill_om_hdr(oh, len+sizeof(*foh));
Harald Welte52b1f982008-12-23 20:25:15 +0000416 foh->msg_type = msg_type;
417 foh->obj_class = obj_class;
418 foh->obj_inst.bts_nr = bts_nr;
419 foh->obj_inst.trx_nr = trx_nr;
420 foh->obj_inst.ts_nr = ts_nr;
421}
422
Harald Welte8470bf22008-12-25 23:28:35 +0000423static struct msgb *nm_msgb_alloc(void)
424{
425 return msgb_alloc_headroom(OM_ALLOC_SIZE, OM_HEADROOM_SIZE);
426}
427
Harald Welte52b1f982008-12-23 20:25:15 +0000428/* Send a OML NM Message from BSC to BTS */
429int abis_nm_sendmsg(struct gsm_bts *bts, struct msgb *msg)
430{
Holger Freyther59639e82009-02-09 23:09:55 +0000431 msg->trx = bts->c0;
432
Harald Weltead384642008-12-26 10:20:07 +0000433 return _abis_nm_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000434}
435
Harald Welte4724f992009-01-18 18:01:49 +0000436static int abis_nm_rcvmsg_sw(struct msgb *mb);
437
Harald Welte34a99682009-02-13 02:41:40 +0000438static const char *obj_class_name(u_int8_t oc)
439{
Harald Welte7b26bcb2009-05-28 11:39:21 +0000440 switch (oc) {
441 case NM_OC_SITE_MANAGER:
442 return "SITE MANAGER";
443 case NM_OC_BTS:
444 return "BTS";
445 case NM_OC_RADIO_CARRIER:
446 return "RADIO CARRIER";
447 case NM_OC_BASEB_TRANSC:
448 return "BASEBAND TRANSCEIVER";
449 case NM_OC_CHANNEL:
Harald Weltebd8f7e32009-06-09 20:17:12 +0000450 return "CHANNEL";
Harald Welte7b26bcb2009-05-28 11:39:21 +0000451 case NM_OC_BS11_ADJC:
452 return "ADJC";
453 case NM_OC_BS11_HANDOVER:
454 return "HANDOVER";
455 case NM_OC_BS11_PWR_CTRL:
456 return "POWER CONTROL";
457 case NM_OC_BS11_BTSE:
458 return "BTSE";
459 case NM_OC_BS11_RACK:
460 return "RACK";
461 case NM_OC_BS11_TEST:
462 return "TEST";
463 case NM_OC_BS11_ENVABTSE:
464 return "ENVABTSE";
465 case NM_OC_BS11_BPORT:
466 return "BPORT";
467 case NM_OC_GPRS_NSE:
468 return "GPRS NSE";
469 case NM_OC_GPRS_CELL:
470 return "GPRS CELL";
471 case NM_OC_GPRS_NSVC0:
472 return "GPRS NSVC0";
473 case NM_OC_GPRS_NSVC1:
474 return "GPRS NSVC1";
Harald Welte8b697c72009-06-05 19:18:45 +0000475 case NM_OC_BS11:
476 return "SIEMENSHW";
Harald Welte7b26bcb2009-05-28 11:39:21 +0000477 }
478
479 return "UNKNOWN";
Harald Welte34a99682009-02-13 02:41:40 +0000480}
481
Harald Welte4d87f242009-03-10 19:43:44 +0000482const char *nm_opstate_name(u_int8_t os)
Harald Welte34a99682009-02-13 02:41:40 +0000483{
484 switch (os) {
485 case 1:
486 return "Disabled";
487 case 2:
488 return "Enabled";
489 case 0xff:
490 return "NULL";
491 default:
492 return "RFU";
493 }
494}
495
Harald Weltee0590df2009-02-15 03:34:15 +0000496/* Chapter 9.4.7 */
Harald Welte4d87f242009-03-10 19:43:44 +0000497static const char *avail_names[] = {
Harald Weltee0590df2009-02-15 03:34:15 +0000498 "In test",
499 "Failed",
500 "Power off",
501 "Off line",
502 "<not used>",
503 "Dependency",
504 "Degraded",
505 "Not installed",
506};
507
Harald Welte4d87f242009-03-10 19:43:44 +0000508const char *nm_avail_name(u_int8_t avail)
Harald Weltee0590df2009-02-15 03:34:15 +0000509{
Harald Welte0b8348d2009-02-18 03:43:01 +0000510 if (avail == 0xff)
511 return "OK";
Harald Weltee0590df2009-02-15 03:34:15 +0000512 if (avail >= ARRAY_SIZE(avail_names))
513 return "UNKNOWN";
514 return avail_names[avail];
515}
Harald Welte7b26bcb2009-05-28 11:39:21 +0000516
517const char *nm_adm_name(u_int8_t adm)
518{
519 switch (adm) {
520 case 1:
521 return "Locked";
522 case 2:
523 return "Unlocked";
524 case 3:
525 return "Shutdown";
526 default:
527 return "<not used>";
528 }
529}
Harald Weltee0590df2009-02-15 03:34:15 +0000530
531/* obtain the gsm_nm_state data structure for a given object instance */
532static struct gsm_nm_state *
533objclass2nmstate(struct gsm_bts *bts, u_int8_t obj_class,
534 struct abis_om_obj_inst *obj_inst)
535{
536 struct gsm_bts_trx *trx;
537 struct gsm_nm_state *nm_state = NULL;
538
539 switch (obj_class) {
540 case NM_OC_BTS:
541 nm_state = &bts->nm_state;
542 break;
543 case NM_OC_RADIO_CARRIER:
544 if (obj_inst->trx_nr >= bts->num_trx)
545 return NULL;
546 trx = &bts->trx[obj_inst->trx_nr];
547 nm_state = &trx->nm_state;
548 break;
549 case NM_OC_BASEB_TRANSC:
550 if (obj_inst->trx_nr >= bts->num_trx)
551 return NULL;
552 trx = &bts->trx[obj_inst->trx_nr];
553 nm_state = &trx->bb_transc.nm_state;
554 break;
555 case NM_OC_CHANNEL:
556 if (obj_inst->trx_nr > bts->num_trx)
557 return NULL;
558 trx = &bts->trx[obj_inst->trx_nr];
559 if (obj_inst->ts_nr >= TRX_NR_TS)
560 return NULL;
561 nm_state = &trx->ts[obj_inst->ts_nr].nm_state;
562 break;
563 case NM_OC_SITE_MANAGER:
564 nm_state = &bts->site_mgr.nm_state;
565 break;
Harald Welte7b26bcb2009-05-28 11:39:21 +0000566 case NM_OC_BS11:
567 switch (obj_inst->bts_nr) {
568 case BS11_OBJ_CCLK:
569 nm_state = &bts->bs11.cclk.nm_state;
570 break;
Harald Welte8b697c72009-06-05 19:18:45 +0000571 case BS11_OBJ_BBSIG:
572 if (obj_inst->ts_nr > bts->num_trx)
573 return NULL;
574 trx = &bts->trx[obj_inst->ts_nr];
575 nm_state = &trx->bs11.bbsig.nm_state;
576 break;
577 case BS11_OBJ_PA:
578 if (obj_inst->ts_nr > bts->num_trx)
579 return NULL;
580 trx = &bts->trx[obj_inst->ts_nr];
581 nm_state = &trx->bs11.pa.nm_state;
582 break;
Harald Welte7b26bcb2009-05-28 11:39:21 +0000583 default:
584 return NULL;
585 }
586 case NM_OC_BS11_RACK:
587 nm_state = &bts->bs11.rack.nm_state;
588 break;
Harald Welte8b697c72009-06-05 19:18:45 +0000589 case NM_OC_BS11_ENVABTSE:
590 if (obj_inst->trx_nr > ARRAY_SIZE(bts->bs11.envabtse))
591 return NULL;
592 nm_state = &bts->bs11.envabtse[obj_inst->trx_nr].nm_state;
593 break;
Harald Weltee0590df2009-02-15 03:34:15 +0000594 }
595 return nm_state;
596}
597
598/* obtain the in-memory data structure of a given object instance */
599static void *
600objclass2obj(struct gsm_bts *bts, u_int8_t obj_class,
601 struct abis_om_obj_inst *obj_inst)
602{
603 struct gsm_bts_trx *trx;
604 void *obj = NULL;
605
606 switch (obj_class) {
607 case NM_OC_BTS:
608 obj = bts;
609 break;
610 case NM_OC_RADIO_CARRIER:
611 if (obj_inst->trx_nr >= bts->num_trx)
612 return NULL;
613 trx = &bts->trx[obj_inst->trx_nr];
614 obj = trx;
615 break;
616 case NM_OC_BASEB_TRANSC:
617 if (obj_inst->trx_nr >= bts->num_trx)
618 return NULL;
619 trx = &bts->trx[obj_inst->trx_nr];
620 obj = &trx->bb_transc;
621 break;
622 case NM_OC_CHANNEL:
623 if (obj_inst->trx_nr > bts->num_trx)
624 return NULL;
625 trx = &bts->trx[obj_inst->trx_nr];
626 if (obj_inst->ts_nr >= TRX_NR_TS)
627 return NULL;
628 obj = &trx->ts[obj_inst->ts_nr];
629 break;
630 case NM_OC_SITE_MANAGER:
631 obj = &bts->site_mgr;
632 break;
633 }
634 return obj;
635}
636
637/* Update the administrative state of a given object in our in-memory data
638 * structures and send an event to the higher layer */
639static int update_admstate(struct gsm_bts *bts, u_int8_t obj_class,
640 struct abis_om_obj_inst *obj_inst, u_int8_t adm_state)
641{
Harald Welteaeedeb42009-05-01 13:08:14 +0000642 struct gsm_nm_state *nm_state, new_state;
Harald Weltee0590df2009-02-15 03:34:15 +0000643 void *obj;
644 int rc;
645
Harald Weltee0590df2009-02-15 03:34:15 +0000646 obj = objclass2obj(bts, obj_class, obj_inst);
Harald Welteaeedeb42009-05-01 13:08:14 +0000647 nm_state = objclass2nmstate(bts, obj_class, obj_inst);
648 if (!nm_state)
649 return -1;
650
651 new_state = *nm_state;
652 new_state.administrative = adm_state;
653
654 rc = nm_state_event(EVT_STATECHG_ADM, obj_class, obj, nm_state, &new_state);
655
656 nm_state->administrative = adm_state;
Harald Weltee0590df2009-02-15 03:34:15 +0000657
658 return rc;
659}
660
Harald Welte97ed1e72009-02-06 13:38:02 +0000661static int abis_nm_rx_statechg_rep(struct msgb *mb)
662{
Harald Weltee0590df2009-02-15 03:34:15 +0000663 struct abis_om_hdr *oh = msgb_l2(mb);
Harald Welte97ed1e72009-02-06 13:38:02 +0000664 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Harald Welte22af0db2009-02-14 15:41:08 +0000665 struct gsm_bts *bts = mb->trx->bts;
Harald Weltee0590df2009-02-15 03:34:15 +0000666 struct tlv_parsed tp;
667 struct gsm_nm_state *nm_state, new_state;
668 int rc;
669
Harald Welte23897662009-05-01 14:52:51 +0000670 DEBUGPC(DNM, "STATE CHG: ");
Harald Weltee0590df2009-02-15 03:34:15 +0000671
Harald Welte8b697c72009-06-05 19:18:45 +0000672 memset(&new_state, 0, sizeof(new_state));
673
Harald Weltee0590df2009-02-15 03:34:15 +0000674 nm_state = objclass2nmstate(bts, foh->obj_class, &foh->obj_inst);
675 if (!nm_state) {
676 DEBUGPC(DNM, "\n");
677 return -EINVAL;
Harald Welte22af0db2009-02-14 15:41:08 +0000678 }
Harald Weltee0590df2009-02-15 03:34:15 +0000679
680 new_state = *nm_state;
681
Harald Welte03133942009-02-18 19:51:53 +0000682 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Weltee0590df2009-02-15 03:34:15 +0000683 if (TLVP_PRESENT(&tp, NM_ATT_OPER_STATE)) {
684 new_state.operational = *TLVP_VAL(&tp, NM_ATT_OPER_STATE);
Harald Welte4d87f242009-03-10 19:43:44 +0000685 DEBUGPC(DNM, "OP_STATE=%s ", nm_opstate_name(new_state.operational));
Harald Weltee0590df2009-02-15 03:34:15 +0000686 }
687 if (TLVP_PRESENT(&tp, NM_ATT_AVAIL_STATUS)) {
Harald Welte0b8348d2009-02-18 03:43:01 +0000688 if (TLVP_LEN(&tp, NM_ATT_AVAIL_STATUS) == 0)
689 new_state.availability = 0xff;
690 else
691 new_state.availability = *TLVP_VAL(&tp, NM_ATT_AVAIL_STATUS);
Harald Welte4d87f242009-03-10 19:43:44 +0000692 DEBUGPC(DNM, "AVAIL=%s(%02x) ", nm_avail_name(new_state.availability),
Harald Weltee0590df2009-02-15 03:34:15 +0000693 new_state.availability);
694 }
695 if (TLVP_PRESENT(&tp, NM_ATT_ADM_STATE)) {
696 new_state.administrative = *TLVP_VAL(&tp, NM_ATT_ADM_STATE);
Harald Welte7b26bcb2009-05-28 11:39:21 +0000697 DEBUGPC(DNM, "ADM=%02x ", nm_adm_name(new_state.administrative));
Harald Welte97ed1e72009-02-06 13:38:02 +0000698 }
699 DEBUGPC(DNM, "\n");
Harald Weltee0590df2009-02-15 03:34:15 +0000700
701 if (memcmp(&new_state, nm_state, sizeof(new_state))) {
702 /* Update the operational state of a given object in our in-memory data
703 * structures and send an event to the higher layer */
704 void *obj = objclass2obj(bts, foh->obj_class, &foh->obj_inst);
705 rc = nm_state_event(EVT_STATECHG_OPER, foh->obj_class, obj, nm_state, &new_state);
706 *nm_state = new_state;
707 }
708#if 0
Harald Welte22af0db2009-02-14 15:41:08 +0000709 if (op_state == 1) {
710 /* try to enable objects that are disabled */
711 abis_nm_opstart(bts, foh->obj_class,
712 foh->obj_inst.bts_nr,
713 foh->obj_inst.trx_nr,
714 foh->obj_inst.ts_nr);
715 }
Harald Weltee0590df2009-02-15 03:34:15 +0000716#endif
Harald Welte97ed1e72009-02-06 13:38:02 +0000717 return 0;
718}
719
Harald Welte0db97b22009-05-01 17:22:47 +0000720static int rx_fail_evt_rep(struct msgb *mb)
721{
722 struct abis_om_hdr *oh = msgb_l2(mb);
723 struct abis_om_fom_hdr *foh = msgb_l3(mb);
724 struct tlv_parsed tp;
725
726 DEBUGPC(DNM, "Failure Event Report ");
727
728 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
729
730 if (TLVP_PRESENT(&tp, NM_ATT_EVENT_TYPE))
731 DEBUGPC(DNM, "Type=%s ", event_type_name(*TLVP_VAL(&tp, NM_ATT_EVENT_TYPE)));
732 if (TLVP_PRESENT(&tp, NM_ATT_SEVERITY))
733 DEBUGPC(DNM, "Severity=%s ", severity_name(*TLVP_VAL(&tp, NM_ATT_SEVERITY)));
734
735 DEBUGPC(DNM, "\n");
736
737 return 0;
738}
739
Harald Welte97ed1e72009-02-06 13:38:02 +0000740static int abis_nm_rcvmsg_report(struct msgb *mb)
741{
742 struct abis_om_fom_hdr *foh = msgb_l3(mb);
743 u_int8_t mt = foh->msg_type;
744
Harald Welte23897662009-05-01 14:52:51 +0000745 DEBUGP(DNM, "OC=%s(%02x) INST=(%02x,%02x,%02x) ",
746 obj_class_name(foh->obj_class), foh->obj_class,
747 foh->obj_inst.bts_nr, foh->obj_inst.trx_nr,
748 foh->obj_inst.ts_nr);
749
Harald Welte97ed1e72009-02-06 13:38:02 +0000750 //nmh->cfg->report_cb(mb, foh);
751
752 switch (mt) {
753 case NM_MT_STATECHG_EVENT_REP:
754 return abis_nm_rx_statechg_rep(mb);
755 break;
Harald Welte34a99682009-02-13 02:41:40 +0000756 case NM_MT_SW_ACTIVATED_REP:
Harald Welte23897662009-05-01 14:52:51 +0000757 DEBUGPC(DNM, "Software Activated Report\n");
Harald Weltef9a8cc32009-05-01 15:39:49 +0000758 dispatch_signal(SS_NM, S_NM_SW_ACTIV_REP, mb);
Harald Welte34a99682009-02-13 02:41:40 +0000759 break;
Harald Weltee0590df2009-02-15 03:34:15 +0000760 case NM_MT_FAILURE_EVENT_REP:
Harald Welte0db97b22009-05-01 17:22:47 +0000761 rx_fail_evt_rep(mb);
Harald Weltef9a8cc32009-05-01 15:39:49 +0000762 dispatch_signal(SS_NM, S_NM_FAIL_REP, mb);
Harald Weltee0590df2009-02-15 03:34:15 +0000763 break;
764 default:
Harald Welte23897662009-05-01 14:52:51 +0000765 DEBUGPC(DNM, "reporting NM MT 0x%02x\n", mt);
Harald Weltee0590df2009-02-15 03:34:15 +0000766 break;
767
Harald Welte97ed1e72009-02-06 13:38:02 +0000768 };
769
Harald Welte97ed1e72009-02-06 13:38:02 +0000770 return 0;
771}
772
Harald Welte34a99682009-02-13 02:41:40 +0000773/* Activate the specified software into the BTS */
774static int ipacc_sw_activate(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1,
775 u_int8_t i2, u_int8_t *sw_desc, u_int8_t swdesc_len)
776{
777 struct abis_om_hdr *oh;
778 struct msgb *msg = nm_msgb_alloc();
779 u_int8_t len = swdesc_len;
780 u_int8_t *trailer;
781
782 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
783 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, obj_class, i0, i1, i2);
784
785 trailer = msgb_put(msg, swdesc_len);
786 memcpy(trailer, sw_desc, swdesc_len);
787
788 return abis_nm_sendmsg(bts, msg);
789}
790
791static int abis_nm_rx_sw_act_req(struct msgb *mb)
792{
793 struct abis_om_hdr *oh = msgb_l2(mb);
794 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Harald Welte5c1e4582009-02-15 11:57:29 +0000795 int nack = 0;
Harald Welte34a99682009-02-13 02:41:40 +0000796 int ret;
797
Harald Welte5c1e4582009-02-15 11:57:29 +0000798 DEBUGP(DNM, "Software Activate Request ");
Harald Welte34a99682009-02-13 02:41:40 +0000799
Harald Welte5c1e4582009-02-15 11:57:29 +0000800 if (foh->obj_class >= 0xf0 && foh->obj_class <= 0xf3) {
801 DEBUGPC(DNM, "NACKing for GPRS obj_class 0x%02x\n", foh->obj_class);
802 nack = 1;
803 } else
804 DEBUGPC(DNM, "ACKing and Activating\n");
805
806 ret = abis_nm_sw_act_req_ack(mb->trx->bts, foh->obj_class,
Harald Welte34a99682009-02-13 02:41:40 +0000807 foh->obj_inst.bts_nr,
808 foh->obj_inst.trx_nr,
Harald Welte5c1e4582009-02-15 11:57:29 +0000809 foh->obj_inst.ts_nr, nack,
Harald Welte34a99682009-02-13 02:41:40 +0000810 foh->data, oh->length-sizeof(*foh));
811
Harald Welte5c1e4582009-02-15 11:57:29 +0000812 if (nack)
813 return ret;
814
Harald Welte34a99682009-02-13 02:41:40 +0000815 /* FIXME: properly parse attributes */
816 return ipacc_sw_activate(mb->trx->bts, foh->obj_class,
817 foh->obj_inst.bts_nr,
818 foh->obj_inst.trx_nr,
819 foh->obj_inst.ts_nr,
820 foh->data + oh->length-sizeof(*foh)-22, 22);
821}
822
Harald Weltee0590df2009-02-15 03:34:15 +0000823/* Receive a CHANGE_ADM_STATE_ACK, parse the TLV and update local state */
824static int abis_nm_rx_chg_adm_state_ack(struct msgb *mb)
825{
826 struct abis_om_hdr *oh = msgb_l2(mb);
827 struct abis_om_fom_hdr *foh = msgb_l3(mb);
828 struct tlv_parsed tp;
829 u_int8_t adm_state;
830
Harald Welte03133942009-02-18 19:51:53 +0000831 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Weltee0590df2009-02-15 03:34:15 +0000832 if (!TLVP_PRESENT(&tp, NM_ATT_ADM_STATE))
833 return -EINVAL;
834
835 adm_state = *TLVP_VAL(&tp, NM_ATT_ADM_STATE);
836
837 return update_admstate(mb->trx->bts, foh->obj_class, &foh->obj_inst, adm_state);
838}
839
Harald Welteee670472009-02-22 21:58:49 +0000840static int abis_nm_rx_lmt_event(struct msgb *mb)
841{
842 struct abis_om_hdr *oh = msgb_l2(mb);
843 struct abis_om_fom_hdr *foh = msgb_l3(mb);
844 struct tlv_parsed tp;
845
846 DEBUGP(DNM, "LMT Event ");
847 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
848 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_LOGON_SESSION) &&
849 TLVP_LEN(&tp, NM_ATT_BS11_LMT_LOGON_SESSION) >= 1) {
850 u_int8_t onoff = *TLVP_VAL(&tp, NM_ATT_BS11_LMT_LOGON_SESSION);
851 DEBUGPC(DNM, "LOG%s ", onoff ? "ON" : "OFF");
852 }
853 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV) &&
854 TLVP_LEN(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV) >= 1) {
855 u_int8_t level = *TLVP_VAL(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV);
856 DEBUGPC(DNM, "Level=%u ", level);
857 }
858 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_USER_NAME) &&
859 TLVP_LEN(&tp, NM_ATT_BS11_LMT_USER_NAME) >= 1) {
860 char *name = (char *) TLVP_VAL(&tp, NM_ATT_BS11_LMT_USER_NAME);
861 DEBUGPC(DNM, "Username=%s ", name);
862 }
863 DEBUGPC(DNM, "\n");
864 /* FIXME: parse LMT LOGON TIME */
865 return 0;
866}
867
Harald Welte52b1f982008-12-23 20:25:15 +0000868/* Receive a OML NM Message from BTS */
Harald Welte8470bf22008-12-25 23:28:35 +0000869static int abis_nm_rcvmsg_fom(struct msgb *mb)
Harald Welte52b1f982008-12-23 20:25:15 +0000870{
Harald Welte6c96ba52009-05-01 13:03:40 +0000871 struct abis_om_hdr *oh = msgb_l2(mb);
Harald Welte52b1f982008-12-23 20:25:15 +0000872 struct abis_om_fom_hdr *foh = msgb_l3(mb);
873 u_int8_t mt = foh->msg_type;
874
875 /* check for unsolicited message */
Harald Welte97ed1e72009-02-06 13:38:02 +0000876 if (is_report(mt))
877 return abis_nm_rcvmsg_report(mb);
Harald Welte52b1f982008-12-23 20:25:15 +0000878
Harald Welte4724f992009-01-18 18:01:49 +0000879 if (is_in_arr(mt, sw_load_msgs, ARRAY_SIZE(sw_load_msgs)))
880 return abis_nm_rcvmsg_sw(mb);
881
Harald Welte78fc0d42009-02-19 02:50:57 +0000882 if (is_in_arr(mt, nacks, ARRAY_SIZE(nacks))) {
Harald Welte6c96ba52009-05-01 13:03:40 +0000883 struct tlv_parsed tp;
Harald Welte78fc0d42009-02-19 02:50:57 +0000884 if (nack_names[mt])
Harald Welte6c96ba52009-05-01 13:03:40 +0000885 DEBUGP(DNM, "%s NACK ", nack_names[mt]);
886 /* FIXME: NACK cause */
Harald Welte78fc0d42009-02-19 02:50:57 +0000887 else
Harald Welte6c96ba52009-05-01 13:03:40 +0000888 DEBUGP(DNM, "NACK 0x%02x ", mt);
889
890 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
891 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
892 DEBUGPC(DNM, "CAUSE=%s\n",
893 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
894 else
895 DEBUGPC(DNM, "\n");
Harald Welte78fc0d42009-02-19 02:50:57 +0000896 }
Harald Weltead384642008-12-26 10:20:07 +0000897#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000898 /* check if last message is to be acked */
899 if (is_ack_nack(nmh->last_msgtype)) {
900 if (mt == MT_ACK(nmh->last_msgtype)) {
901 fprintf(stderr, "received ACK (0x%x)\n",
902 foh->msg_type);
903 /* we got our ACK, continue sending the next msg */
904 } else if (mt == MT_NACK(nmh->last_msgtype)) {
905 /* we got a NACK, signal this to the caller */
906 fprintf(stderr, "received NACK (0x%x)\n",
907 foh->msg_type);
908 /* FIXME: somehow signal this to the caller */
909 } else {
910 /* really strange things happen */
911 return -EINVAL;
912 }
913 }
Harald Weltead384642008-12-26 10:20:07 +0000914#endif
915
Harald Welte97ed1e72009-02-06 13:38:02 +0000916 switch (mt) {
Harald Weltee0590df2009-02-15 03:34:15 +0000917 case NM_MT_CHG_ADM_STATE_ACK:
918 return abis_nm_rx_chg_adm_state_ack(mb);
919 break;
Harald Welte34a99682009-02-13 02:41:40 +0000920 case NM_MT_SW_ACT_REQ:
921 return abis_nm_rx_sw_act_req(mb);
922 break;
Harald Welte97ed1e72009-02-06 13:38:02 +0000923 case NM_MT_BS11_LMT_SESSION:
Harald Welteee670472009-02-22 21:58:49 +0000924 return abis_nm_rx_lmt_event(mb);
Harald Welte97ed1e72009-02-06 13:38:02 +0000925 break;
926 }
927
Harald Weltead384642008-12-26 10:20:07 +0000928 return 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000929}
930
Harald Welte677c21f2009-02-17 13:22:23 +0000931static int abis_nm_rx_ipacc(struct msgb *mb);
932
933static int abis_nm_rcvmsg_manuf(struct msgb *mb)
934{
935 int rc;
936 int bts_type = mb->trx->bts->type;
937
938 switch (bts_type) {
939 case GSM_BTS_TYPE_NANOBTS_900:
940 case GSM_BTS_TYPE_NANOBTS_1800:
941 rc = abis_nm_rx_ipacc(mb);
942 break;
943 default:
944 fprintf(stderr, "don't know how to parse OML for this "
945 "BTS type (%u)\n", bts_type);
946 rc = 0;
947 break;
948 }
949
950 return rc;
951}
952
Harald Welte52b1f982008-12-23 20:25:15 +0000953/* High-Level API */
954/* Entry-point where L2 OML from BTS enters the NM code */
Harald Welte8470bf22008-12-25 23:28:35 +0000955int abis_nm_rcvmsg(struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +0000956{
Harald Welte52b1f982008-12-23 20:25:15 +0000957 struct abis_om_hdr *oh = msgb_l2(msg);
Harald Welte677c21f2009-02-17 13:22:23 +0000958 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000959
960 /* Various consistency checks */
961 if (oh->placement != ABIS_OM_PLACEMENT_ONLY) {
962 fprintf(stderr, "ABIS OML placement 0x%x not supported\n",
963 oh->placement);
964 return -EINVAL;
965 }
966 if (oh->sequence != 0) {
967 fprintf(stderr, "ABIS OML sequence 0x%x != 0x00\n",
968 oh->sequence);
969 return -EINVAL;
970 }
Harald Welte702d8702008-12-26 20:25:35 +0000971#if 0
Holger Freytherca362a62009-01-04 21:05:01 +0000972 unsigned int l2_len = msg->tail - (u_int8_t *)msgb_l2(msg);
973 unsigned int hlen = sizeof(*oh) + sizeof(struct abis_om_fom_hdr);
Harald Welte702d8702008-12-26 20:25:35 +0000974 if (oh->length + hlen > l2_len) {
Harald Welte52b1f982008-12-23 20:25:15 +0000975 fprintf(stderr, "ABIS OML truncated message (%u > %u)\n",
976 oh->length + sizeof(*oh), l2_len);
977 return -EINVAL;
978 }
Harald Welte702d8702008-12-26 20:25:35 +0000979 if (oh->length + hlen < l2_len)
980 fprintf(stderr, "ABIS OML message with extra trailer?!? (oh->len=%d, sizeof_oh=%d l2_len=%d\n", oh->length, sizeof(*oh), l2_len);
981#endif
Harald Weltead384642008-12-26 10:20:07 +0000982 msg->l3h = (unsigned char *)oh + sizeof(*oh);
Harald Welte52b1f982008-12-23 20:25:15 +0000983
984 switch (oh->mdisc) {
985 case ABIS_OM_MDISC_FOM:
Harald Welte8470bf22008-12-25 23:28:35 +0000986 rc = abis_nm_rcvmsg_fom(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000987 break;
Harald Welte677c21f2009-02-17 13:22:23 +0000988 case ABIS_OM_MDISC_MANUF:
989 rc = abis_nm_rcvmsg_manuf(msg);
990 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000991 case ABIS_OM_MDISC_MMI:
992 case ABIS_OM_MDISC_TRAU:
Harald Welte677c21f2009-02-17 13:22:23 +0000993 fprintf(stderr, "unimplemented ABIS OML message discriminator 0x%x\n",
994 oh->mdisc);
995 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000996 default:
997 fprintf(stderr, "unknown ABIS OML message discriminator 0x%x\n",
998 oh->mdisc);
999 return -EINVAL;
1000 }
1001
Harald Weltead384642008-12-26 10:20:07 +00001002 msgb_free(msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001003 return rc;
1004}
1005
1006#if 0
1007/* initialized all resources */
1008struct abis_nm_h *abis_nm_init(struct abis_nm_cfg *cfg)
1009{
1010 struct abis_nm_h *nmh;
1011
1012 nmh = malloc(sizeof(*nmh));
1013 if (!nmh)
1014 return NULL;
1015
1016 nmh->cfg = cfg;
1017
1018 return nmh;
1019}
1020
1021/* free all resources */
1022void abis_nm_fini(struct abis_nm_h *nmh)
1023{
1024 free(nmh);
1025}
1026#endif
1027
1028/* Here we are trying to define a high-level API that can be used by
1029 * the actual BSC implementation. However, the architecture is currently
1030 * still under design. Ideally the calls to this API would be synchronous,
1031 * while the underlying stack behind the APi runs in a traditional select
1032 * based state machine.
1033 */
1034
Harald Welte4724f992009-01-18 18:01:49 +00001035/* 6.2 Software Load: */
1036enum sw_state {
1037 SW_STATE_NONE,
1038 SW_STATE_WAIT_INITACK,
1039 SW_STATE_WAIT_SEGACK,
1040 SW_STATE_WAIT_ENDACK,
1041 SW_STATE_WAIT_ACTACK,
1042 SW_STATE_ERROR,
1043};
Harald Welte52b1f982008-12-23 20:25:15 +00001044
Harald Welte52b1f982008-12-23 20:25:15 +00001045struct abis_nm_sw {
Harald Welte4724f992009-01-18 18:01:49 +00001046 struct gsm_bts *bts;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001047 gsm_cbfn *cbfn;
1048 void *cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +00001049 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001050
Harald Welte52b1f982008-12-23 20:25:15 +00001051 /* this will become part of the SW LOAD INITIATE */
1052 u_int8_t obj_class;
1053 u_int8_t obj_instance[3];
Harald Welte4724f992009-01-18 18:01:49 +00001054
1055 u_int8_t file_id[255];
1056 u_int8_t file_id_len;
1057
1058 u_int8_t file_version[255];
1059 u_int8_t file_version_len;
1060
1061 u_int8_t window_size;
1062 u_int8_t seg_in_window;
1063
1064 int fd;
1065 FILE *stream;
1066 enum sw_state state;
Harald Welte1602ade2009-01-29 21:12:39 +00001067 int last_seg;
Harald Welte52b1f982008-12-23 20:25:15 +00001068};
1069
Harald Welte4724f992009-01-18 18:01:49 +00001070static struct abis_nm_sw g_sw;
1071
1072/* 6.2.1 / 8.3.1: Load Data Initiate */
1073static int sw_load_init(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +00001074{
Harald Welte4724f992009-01-18 18:01:49 +00001075 struct abis_om_hdr *oh;
1076 struct msgb *msg = nm_msgb_alloc();
1077 u_int8_t len = 3*2 + sw->file_id_len + sw->file_version_len;
1078
1079 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1080 fill_om_fom_hdr(oh, len, NM_MT_LOAD_INIT, sw->obj_class,
1081 sw->obj_instance[0], sw->obj_instance[1],
1082 sw->obj_instance[2]);
1083
1084 /* FIXME: this is BS11 specific format */
1085 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1086 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1087 sw->file_version);
1088 msgb_tv_put(msg, NM_ATT_WINDOW_SIZE, sw->window_size);
1089
1090 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001091}
1092
Harald Welte1602ade2009-01-29 21:12:39 +00001093static int is_last_line(FILE *stream)
1094{
1095 char next_seg_buf[256];
1096 long pos;
1097
1098 /* check if we're sending the last line */
1099 pos = ftell(stream);
1100 if (!fgets(next_seg_buf, sizeof(next_seg_buf)-2, stream)) {
1101 fseek(stream, pos, SEEK_SET);
1102 return 1;
1103 }
1104
1105 fseek(stream, pos, SEEK_SET);
1106 return 0;
1107}
1108
Harald Welte4724f992009-01-18 18:01:49 +00001109/* 6.2.2 / 8.3.2 Load Data Segment */
1110static int sw_load_segment(struct abis_nm_sw *sw)
1111{
1112 struct abis_om_hdr *oh;
1113 struct msgb *msg = nm_msgb_alloc();
1114 char seg_buf[256];
1115 char *line_buf = seg_buf+2;
Harald Welte3b8ba212009-01-29 12:27:58 +00001116 unsigned char *tlv;
Harald Welte4724f992009-01-18 18:01:49 +00001117 u_int8_t len;
Harald Welte4724f992009-01-18 18:01:49 +00001118
1119 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte3b8ba212009-01-29 12:27:58 +00001120
1121 switch (sw->bts->type) {
1122 case GSM_BTS_TYPE_BS11:
1123 if (fgets(line_buf, sizeof(seg_buf)-2, sw->stream) == NULL) {
1124 perror("fgets reading segment");
1125 return -EINVAL;
1126 }
1127 seg_buf[0] = 0x00;
Harald Welte1602ade2009-01-29 21:12:39 +00001128
1129 /* check if we're sending the last line */
1130 sw->last_seg = is_last_line(sw->stream);
1131 if (sw->last_seg)
1132 seg_buf[1] = 0;
1133 else
1134 seg_buf[1] = 1 + sw->seg_in_window++;
Harald Welte3b8ba212009-01-29 12:27:58 +00001135
1136 len = strlen(line_buf) + 2;
1137 tlv = msgb_put(msg, TLV_GROSS_LEN(len));
1138 tlv_put(tlv, NM_ATT_BS11_FILE_DATA, len, (u_int8_t *)seg_buf);
1139 /* BS11 wants CR + LF in excess of the TLV length !?! */
1140 tlv[1] -= 2;
1141
1142 /* we only now know the exact length for the OM hdr */
1143 len = strlen(line_buf)+2;
1144 break;
1145 default:
1146 /* FIXME: Other BTS types */
1147 return -1;
Harald Welte4724f992009-01-18 18:01:49 +00001148 }
Harald Welte4724f992009-01-18 18:01:49 +00001149
Harald Welte4724f992009-01-18 18:01:49 +00001150 fill_om_fom_hdr(oh, len, NM_MT_LOAD_SEG, sw->obj_class,
1151 sw->obj_instance[0], sw->obj_instance[1],
1152 sw->obj_instance[2]);
1153
1154 return abis_nm_sendmsg(sw->bts, msg);
1155}
1156
1157/* 6.2.4 / 8.3.4 Load Data End */
1158static int sw_load_end(struct abis_nm_sw *sw)
1159{
1160 struct abis_om_hdr *oh;
1161 struct msgb *msg = nm_msgb_alloc();
1162 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
1163
1164 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1165 fill_om_fom_hdr(oh, len, NM_MT_LOAD_END, sw->obj_class,
1166 sw->obj_instance[0], sw->obj_instance[1],
1167 sw->obj_instance[2]);
1168
1169 /* FIXME: this is BS11 specific format */
1170 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1171 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1172 sw->file_version);
1173
1174 return abis_nm_sendmsg(sw->bts, msg);
1175}
Harald Welte5e4d1b32009-02-01 13:36:56 +00001176
Harald Welte52b1f982008-12-23 20:25:15 +00001177/* Activate the specified software into the BTS */
Harald Welte4724f992009-01-18 18:01:49 +00001178static int sw_activate(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +00001179{
Harald Welte4724f992009-01-18 18:01:49 +00001180 struct abis_om_hdr *oh;
1181 struct msgb *msg = nm_msgb_alloc();
1182 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
Harald Welte52b1f982008-12-23 20:25:15 +00001183
Harald Welte4724f992009-01-18 18:01:49 +00001184 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1185 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, sw->obj_class,
1186 sw->obj_instance[0], sw->obj_instance[1],
1187 sw->obj_instance[2]);
1188
1189 /* FIXME: this is BS11 specific format */
1190 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1191 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1192 sw->file_version);
1193
1194 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001195}
Harald Welte4724f992009-01-18 18:01:49 +00001196
1197static int sw_open_file(struct abis_nm_sw *sw, const char *fname)
1198{
1199 char file_id[12+1];
1200 char file_version[80+1];
1201 int rc;
1202
1203 sw->fd = open(fname, O_RDONLY);
1204 if (sw->fd < 0)
1205 return sw->fd;
1206
1207 switch (sw->bts->type) {
1208 case GSM_BTS_TYPE_BS11:
1209 sw->stream = fdopen(sw->fd, "r");
1210 if (!sw->stream) {
1211 perror("fdopen");
1212 return -1;
1213 }
1214 /* read first line and parse file ID and VERSION */
Harald Welte3b8ba212009-01-29 12:27:58 +00001215 rc = fscanf(sw->stream, "@(#)%12s:%80s\r\n",
Harald Welte4724f992009-01-18 18:01:49 +00001216 file_id, file_version);
1217 if (rc != 2) {
1218 perror("parsing header line of software file");
1219 return -1;
1220 }
1221 strcpy((char *)sw->file_id, file_id);
1222 sw->file_id_len = strlen(file_id);
1223 strcpy((char *)sw->file_version, file_version);
1224 sw->file_version_len = strlen(file_version);
1225 /* rewind to start of file */
Harald Welte3b8ba212009-01-29 12:27:58 +00001226 rewind(sw->stream);
Harald Welte4724f992009-01-18 18:01:49 +00001227 break;
1228 default:
1229 /* We don't know how to treat them yet */
1230 close(sw->fd);
1231 return -EINVAL;
1232 }
1233
1234 return 0;
1235}
1236
1237static void sw_close_file(struct abis_nm_sw *sw)
1238{
1239 switch (sw->bts->type) {
1240 case GSM_BTS_TYPE_BS11:
1241 fclose(sw->stream);
1242 break;
1243 default:
1244 close(sw->fd);
1245 break;
1246 }
1247}
1248
1249/* Fill the window */
1250static int sw_fill_window(struct abis_nm_sw *sw)
1251{
1252 int rc;
1253
1254 while (sw->seg_in_window < sw->window_size) {
1255 rc = sw_load_segment(sw);
1256 if (rc < 0)
1257 return rc;
Harald Welte1602ade2009-01-29 21:12:39 +00001258 if (sw->last_seg)
1259 break;
Harald Welte4724f992009-01-18 18:01:49 +00001260 }
1261 return 0;
1262}
1263
1264/* callback function from abis_nm_rcvmsg() handler */
1265static int abis_nm_rcvmsg_sw(struct msgb *mb)
1266{
1267 struct abis_om_fom_hdr *foh = msgb_l3(mb);
1268 int rc = -1;
1269 struct abis_nm_sw *sw = &g_sw;
1270 enum sw_state old_state = sw->state;
1271
Harald Welte3ffd1372009-02-01 22:15:49 +00001272 //DEBUGP(DNM, "state %u, NM MT 0x%02x\n", sw->state, foh->msg_type);
Harald Welte4724f992009-01-18 18:01:49 +00001273
1274 switch (sw->state) {
1275 case SW_STATE_WAIT_INITACK:
1276 switch (foh->msg_type) {
1277 case NM_MT_LOAD_INIT_ACK:
1278 /* fill window with segments */
Harald Welte5e4d1b32009-02-01 13:36:56 +00001279 if (sw->cbfn)
1280 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1281 NM_MT_LOAD_INIT_ACK, mb,
1282 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001283 rc = sw_fill_window(sw);
1284 sw->state = SW_STATE_WAIT_SEGACK;
1285 break;
1286 case NM_MT_LOAD_INIT_NACK:
Harald Welte3ffd1372009-02-01 22:15:49 +00001287 if (sw->forced) {
1288 DEBUGP(DNM, "FORCED: Ignoring Software Load "
1289 "Init NACK\n");
1290 if (sw->cbfn)
1291 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1292 NM_MT_LOAD_INIT_ACK, mb,
1293 sw->cb_data, NULL);
1294 rc = sw_fill_window(sw);
1295 sw->state = SW_STATE_WAIT_SEGACK;
1296 } else {
1297 DEBUGP(DNM, "Software Load Init NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001298 /* FIXME: cause */
Harald Welte3ffd1372009-02-01 22:15:49 +00001299 if (sw->cbfn)
1300 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1301 NM_MT_LOAD_INIT_NACK, mb,
1302 sw->cb_data, NULL);
1303 sw->state = SW_STATE_ERROR;
1304 }
Harald Welte4724f992009-01-18 18:01:49 +00001305 break;
1306 }
1307 break;
1308 case SW_STATE_WAIT_SEGACK:
1309 switch (foh->msg_type) {
1310 case NM_MT_LOAD_SEG_ACK:
Harald Welte3ffd1372009-02-01 22:15:49 +00001311 if (sw->cbfn)
1312 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1313 NM_MT_LOAD_SEG_ACK, mb,
1314 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001315 sw->seg_in_window = 0;
Harald Welte1602ade2009-01-29 21:12:39 +00001316 if (!sw->last_seg) {
1317 /* fill window with more segments */
1318 rc = sw_fill_window(sw);
1319 sw->state = SW_STATE_WAIT_SEGACK;
1320 } else {
1321 /* end the transfer */
1322 sw->state = SW_STATE_WAIT_ENDACK;
1323 rc = sw_load_end(sw);
1324 }
Harald Welte4724f992009-01-18 18:01:49 +00001325 break;
1326 }
1327 break;
1328 case SW_STATE_WAIT_ENDACK:
1329 switch (foh->msg_type) {
1330 case NM_MT_LOAD_END_ACK:
1331 sw_close_file(sw);
Harald Welte5e4d1b32009-02-01 13:36:56 +00001332 DEBUGP(DNM, "Software Load End (BTS %u)\n",
1333 sw->bts->nr);
1334 sw->state = SW_STATE_NONE;
1335 if (sw->cbfn)
1336 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1337 NM_MT_LOAD_END_ACK, mb,
1338 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001339 break;
1340 case NM_MT_LOAD_END_NACK:
Holger Freyther31338a12009-02-06 17:43:50 +00001341 if (sw->forced) {
1342 DEBUGP(DNM, "FORCED: Ignoring Software Load"
1343 "End NACK\n");
1344 sw->state = SW_STATE_NONE;
1345 if (sw->cbfn)
1346 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1347 NM_MT_LOAD_END_ACK, mb,
1348 sw->cb_data, NULL);
1349 } else {
1350 DEBUGP(DNM, "Software Load End NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001351 /* FIXME: cause */
Holger Freyther31338a12009-02-06 17:43:50 +00001352 sw->state = SW_STATE_ERROR;
1353 if (sw->cbfn)
1354 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1355 NM_MT_LOAD_END_NACK, mb,
1356 sw->cb_data, NULL);
1357 }
Harald Welte4724f992009-01-18 18:01:49 +00001358 break;
1359 }
1360 case SW_STATE_WAIT_ACTACK:
1361 switch (foh->msg_type) {
1362 case NM_MT_ACTIVATE_SW_ACK:
1363 /* we're done */
Harald Welte5e4d1b32009-02-01 13:36:56 +00001364 DEBUGP(DNM, "Activate Software DONE!\n");
Harald Welte4724f992009-01-18 18:01:49 +00001365 sw->state = SW_STATE_NONE;
1366 rc = 0;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001367 if (sw->cbfn)
1368 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1369 NM_MT_ACTIVATE_SW_ACK, mb,
1370 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001371 break;
1372 case NM_MT_ACTIVATE_SW_NACK:
Harald Welte1602ade2009-01-29 21:12:39 +00001373 DEBUGP(DNM, "Activate Software NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001374 /* FIXME: cause */
Harald Welte4724f992009-01-18 18:01:49 +00001375 sw->state = SW_STATE_ERROR;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001376 if (sw->cbfn)
1377 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1378 NM_MT_ACTIVATE_SW_NACK, mb,
1379 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001380 break;
1381 }
1382 case SW_STATE_NONE:
Harald Weltea994a482009-05-01 15:54:23 +00001383 switch (foh->msg_type) {
1384 case NM_MT_ACTIVATE_SW_ACK:
1385 rc = 0;
1386 break;
1387 }
1388 break;
Harald Welte4724f992009-01-18 18:01:49 +00001389 case SW_STATE_ERROR:
1390 break;
1391 }
1392
1393 if (rc)
Harald Weltea994a482009-05-01 15:54:23 +00001394 DEBUGP(DNM, "unexpected NM MT 0x%02x in state %u -> %u\n",
Harald Welte4724f992009-01-18 18:01:49 +00001395 foh->msg_type, old_state, sw->state);
1396
1397 return rc;
1398}
1399
1400/* Load the specified software into the BTS */
1401int abis_nm_software_load(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00001402 u_int8_t win_size, int forced,
1403 gsm_cbfn *cbfn, void *cb_data)
Harald Welte4724f992009-01-18 18:01:49 +00001404{
1405 struct abis_nm_sw *sw = &g_sw;
1406 int rc;
1407
Harald Welte5e4d1b32009-02-01 13:36:56 +00001408 DEBUGP(DNM, "Software Load (BTS %u, File \"%s\")\n",
1409 bts->nr, fname);
1410
Harald Welte4724f992009-01-18 18:01:49 +00001411 if (sw->state != SW_STATE_NONE)
1412 return -EBUSY;
1413
1414 sw->bts = bts;
1415 sw->obj_class = NM_OC_SITE_MANAGER;
1416 sw->obj_instance[0] = 0xff;
1417 sw->obj_instance[1] = 0xff;
1418 sw->obj_instance[2] = 0xff;
1419 sw->window_size = win_size;
1420 sw->state = SW_STATE_WAIT_INITACK;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001421 sw->cbfn = cbfn;
1422 sw->cb_data = cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +00001423 sw->forced = forced;
Harald Welte4724f992009-01-18 18:01:49 +00001424
1425 rc = sw_open_file(sw, fname);
1426 if (rc < 0) {
1427 sw->state = SW_STATE_NONE;
1428 return rc;
1429 }
1430
1431 return sw_load_init(sw);
1432}
Harald Welte52b1f982008-12-23 20:25:15 +00001433
Harald Welte1602ade2009-01-29 21:12:39 +00001434int abis_nm_software_load_status(struct gsm_bts *bts)
1435{
1436 struct abis_nm_sw *sw = &g_sw;
1437 struct stat st;
1438 int rc, percent;
1439
1440 rc = fstat(sw->fd, &st);
1441 if (rc < 0) {
1442 perror("ERROR during stat");
1443 return rc;
1444 }
1445
1446 percent = (ftell(sw->stream) * 100) / st.st_size;
1447 return percent;
1448}
1449
Harald Welte5e4d1b32009-02-01 13:36:56 +00001450/* Activate the specified software into the BTS */
1451int abis_nm_software_activate(struct gsm_bts *bts, const char *fname,
1452 gsm_cbfn *cbfn, void *cb_data)
1453{
1454 struct abis_nm_sw *sw = &g_sw;
1455 int rc;
1456
1457 DEBUGP(DNM, "Activating Software (BTS %u, File \"%s\")\n",
1458 bts->nr, fname);
1459
1460 if (sw->state != SW_STATE_NONE)
1461 return -EBUSY;
1462
1463 sw->bts = bts;
1464 sw->obj_class = NM_OC_SITE_MANAGER;
1465 sw->obj_instance[0] = 0xff;
1466 sw->obj_instance[1] = 0xff;
1467 sw->obj_instance[2] = 0xff;
1468 sw->state = SW_STATE_WAIT_ACTACK;
1469 sw->cbfn = cbfn;
1470 sw->cb_data = cb_data;
1471
1472 /* Open the file in order to fill some sw struct members */
1473 rc = sw_open_file(sw, fname);
1474 if (rc < 0) {
1475 sw->state = SW_STATE_NONE;
1476 return rc;
1477 }
1478 sw_close_file(sw);
1479
1480 return sw_activate(sw);
1481}
1482
Harald Welte8470bf22008-12-25 23:28:35 +00001483static void fill_nm_channel(struct abis_nm_channel *ch, u_int8_t bts_port,
Harald Welte52b1f982008-12-23 20:25:15 +00001484 u_int8_t ts_nr, u_int8_t subslot_nr)
1485{
Harald Welteadaf08b2009-01-18 11:08:10 +00001486 ch->attrib = NM_ATT_ABIS_CHANNEL;
Harald Welte52b1f982008-12-23 20:25:15 +00001487 ch->bts_port = bts_port;
1488 ch->timeslot = ts_nr;
1489 ch->subslot = subslot_nr;
1490}
1491
1492int abis_nm_establish_tei(struct gsm_bts *bts, u_int8_t trx_nr,
1493 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot,
1494 u_int8_t tei)
1495{
1496 struct abis_om_hdr *oh;
1497 struct abis_nm_channel *ch;
Harald Welte702d8702008-12-26 20:25:35 +00001498 u_int8_t len = sizeof(*ch) + 2;
Harald Welte8470bf22008-12-25 23:28:35 +00001499 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001500
1501 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1502 fill_om_fom_hdr(oh, len, NM_MT_ESTABLISH_TEI, NM_OC_RADIO_CARRIER,
1503 bts->bts_nr, trx_nr, 0xff);
1504
Harald Welte8470bf22008-12-25 23:28:35 +00001505 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte52b1f982008-12-23 20:25:15 +00001506
1507 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1508 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1509
1510 return abis_nm_sendmsg(bts, msg);
1511}
1512
1513/* connect signalling of one (BTS,TRX) to a particular timeslot on the E1 */
1514int abis_nm_conn_terr_sign(struct gsm_bts_trx *trx,
1515 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot)
1516{
Harald Welte8470bf22008-12-25 23:28:35 +00001517 struct gsm_bts *bts = trx->bts;
Harald Welte52b1f982008-12-23 20:25:15 +00001518 struct abis_om_hdr *oh;
1519 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +00001520 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001521
1522 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001523 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_SIGN,
Harald Welte52b1f982008-12-23 20:25:15 +00001524 NM_OC_RADIO_CARRIER, bts->bts_nr, trx->nr, 0xff);
1525
1526 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1527 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1528
1529 return abis_nm_sendmsg(bts, msg);
1530}
1531
1532#if 0
1533int abis_nm_disc_terr_sign(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1534 struct abis_nm_abis_channel *chan)
1535{
1536}
1537#endif
1538
1539int abis_nm_conn_terr_traf(struct gsm_bts_trx_ts *ts,
1540 u_int8_t e1_port, u_int8_t e1_timeslot,
1541 u_int8_t e1_subslot)
1542{
1543 struct gsm_bts *bts = ts->trx->bts;
1544 struct abis_om_hdr *oh;
1545 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +00001546 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001547
1548 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1549 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_TRAF,
Harald Welteb110cee2009-02-18 03:42:35 +00001550 NM_OC_CHANNEL, bts->bts_nr, ts->trx->nr, ts->nr);
Harald Welte52b1f982008-12-23 20:25:15 +00001551
1552 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1553 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1554
Harald Weltef325eb42009-02-19 17:07:39 +00001555 DEBUGP(DNM, "CONNECT TERR TRAF Um=%s E1=(%u,%u,%u)\n",
1556 gsm_ts_name(ts),
Harald Welteb110cee2009-02-18 03:42:35 +00001557 e1_port, e1_timeslot, e1_subslot);
1558
Harald Welte52b1f982008-12-23 20:25:15 +00001559 return abis_nm_sendmsg(bts, msg);
1560}
1561
1562#if 0
1563int abis_nm_disc_terr_traf(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1564 struct abis_nm_abis_channel *chan,
1565 u_int8_t subchan)
1566{
1567}
1568#endif
1569
Harald Welte22af0db2009-02-14 15:41:08 +00001570/* Chapter 8.6.1 */
1571int abis_nm_set_bts_attr(struct gsm_bts *bts, u_int8_t *attr, int attr_len)
1572{
1573 struct abis_om_hdr *oh;
1574 struct msgb *msg = nm_msgb_alloc();
1575 u_int8_t *cur;
1576
1577 DEBUGP(DNM, "Set BTS Attr (bts=%d)\n", bts->nr);
1578
1579 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte191280d2009-05-01 13:20:04 +00001580 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 +00001581 cur = msgb_put(msg, attr_len);
1582 memcpy(cur, attr, attr_len);
1583
1584 return abis_nm_sendmsg(bts, msg);
1585}
1586
1587/* Chapter 8.6.2 */
1588int abis_nm_set_radio_attr(struct gsm_bts_trx *trx, u_int8_t *attr, int attr_len)
1589{
1590 struct abis_om_hdr *oh;
1591 struct msgb *msg = nm_msgb_alloc();
1592 u_int8_t *cur;
1593
1594 DEBUGP(DNM, "Set TRX Attr (bts=%d,trx=%d)\n", trx->bts->nr, trx->nr);
1595
1596 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1597 fill_om_fom_hdr(oh, attr_len, NM_MT_SET_RADIO_ATTR, NM_OC_RADIO_CARRIER,
Harald Welte191280d2009-05-01 13:20:04 +00001598 trx->bts->bts_nr, trx->nr, 0xff);
Harald Welte22af0db2009-02-14 15:41:08 +00001599 cur = msgb_put(msg, attr_len);
1600 memcpy(cur, attr, attr_len);
1601
1602 return abis_nm_sendmsg(trx->bts, msg);
1603}
1604
1605/* Chapter 8.6.3 */
Harald Welte52b1f982008-12-23 20:25:15 +00001606int abis_nm_set_channel_attr(struct gsm_bts_trx_ts *ts, u_int8_t chan_comb)
1607{
1608 struct gsm_bts *bts = ts->trx->bts;
1609 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001610 u_int16_t arfcn = htons(ts->trx->arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001611 u_int8_t zero = 0x00;
Harald Welte8470bf22008-12-25 23:28:35 +00001612 struct msgb *msg = nm_msgb_alloc();
Harald Weltee0590df2009-02-15 03:34:15 +00001613 u_int8_t len = 2 + 2;
1614
1615 if (bts->type == GSM_BTS_TYPE_BS11)
1616 len += 4 + 2 + 2 + 3;
Harald Welte52b1f982008-12-23 20:25:15 +00001617
Harald Weltef325eb42009-02-19 17:07:39 +00001618 DEBUGP(DNM, "Set Chan Attr %s\n", gsm_ts_name(ts));
Harald Welte22af0db2009-02-14 15:41:08 +00001619
Harald Welte52b1f982008-12-23 20:25:15 +00001620 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001621 fill_om_fom_hdr(oh, len, NM_MT_SET_CHAN_ATTR,
Holger Freyther6b2d2622009-02-14 23:16:59 +00001622 NM_OC_CHANNEL, bts->bts_nr,
Harald Welte52b1f982008-12-23 20:25:15 +00001623 ts->trx->nr, ts->nr);
1624 /* FIXME: don't send ARFCN list, hopping sequence, mAIO, ...*/
Harald Weltee0590df2009-02-15 03:34:15 +00001625 if (bts->type == GSM_BTS_TYPE_BS11)
1626 msgb_tlv16_put(msg, NM_ATT_ARFCN_LIST, 1, &arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001627 msgb_tv_put(msg, NM_ATT_CHAN_COMB, chan_comb);
Harald Weltee0590df2009-02-15 03:34:15 +00001628 if (bts->type == GSM_BTS_TYPE_BS11) {
1629 msgb_tv_put(msg, NM_ATT_HSN, 0x00);
1630 msgb_tv_put(msg, NM_ATT_MAIO, 0x00);
1631 }
Harald Welte52b1f982008-12-23 20:25:15 +00001632 msgb_tv_put(msg, NM_ATT_TSC, 0x07); /* training sequence */
Harald Weltee0590df2009-02-15 03:34:15 +00001633 if (bts->type == GSM_BTS_TYPE_BS11)
1634 msgb_tlv_put(msg, 0x59, 1, &zero);
Harald Welte52b1f982008-12-23 20:25:15 +00001635
1636 return abis_nm_sendmsg(bts, msg);
1637}
1638
Harald Welte34a99682009-02-13 02:41:40 +00001639int 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 +00001640 u_int8_t i2, u_int8_t i3, int nack, u_int8_t *attr, int att_len)
Harald Welte34a99682009-02-13 02:41:40 +00001641{
1642 struct abis_om_hdr *oh;
1643 struct msgb *msg = nm_msgb_alloc();
Harald Welte5c1e4582009-02-15 11:57:29 +00001644 u_int8_t msgtype = NM_MT_SW_ACT_REQ_ACK;
1645 u_int8_t len = att_len;
1646
1647 if (nack) {
1648 len += 2;
1649 msgtype = NM_MT_SW_ACT_REQ_NACK;
1650 }
Harald Welte34a99682009-02-13 02:41:40 +00001651
1652 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte5c1e4582009-02-15 11:57:29 +00001653 fill_om_fom_hdr(oh, att_len, msgtype, obj_class, i1, i2, i3);
1654
Harald Welte34a99682009-02-13 02:41:40 +00001655 if (attr) {
1656 u_int8_t *ptr = msgb_put(msg, att_len);
1657 memcpy(ptr, attr, att_len);
1658 }
Harald Welte5c1e4582009-02-15 11:57:29 +00001659 if (nack)
1660 msgb_tv_put(msg, NM_ATT_NACK_CAUSES, NM_NACK_OBJCLASS_NOTSUPP);
Harald Welte34a99682009-02-13 02:41:40 +00001661
1662 return abis_nm_sendmsg(bts, msg);
1663}
1664
Harald Welte8470bf22008-12-25 23:28:35 +00001665int abis_nm_raw_msg(struct gsm_bts *bts, int len, u_int8_t *rawmsg)
Harald Welte52b1f982008-12-23 20:25:15 +00001666{
Harald Welte8470bf22008-12-25 23:28:35 +00001667 struct msgb *msg = nm_msgb_alloc();
1668 struct abis_om_hdr *oh;
Harald Welte52b1f982008-12-23 20:25:15 +00001669 u_int8_t *data;
1670
1671 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
1672 fill_om_hdr(oh, len);
1673 data = msgb_put(msg, len);
Harald Weltead384642008-12-26 10:20:07 +00001674 memcpy(data, rawmsg, len);
Harald Welte52b1f982008-12-23 20:25:15 +00001675
1676 return abis_nm_sendmsg(bts, msg);
1677}
1678
1679/* Siemens specific commands */
1680static int __simple_cmd(struct gsm_bts *bts, u_int8_t msg_type)
1681{
1682 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001683 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001684
1685 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001686 fill_om_fom_hdr(oh, 0, msg_type, NM_OC_SITE_MANAGER,
Harald Welte52b1f982008-12-23 20:25:15 +00001687 0xff, 0xff, 0xff);
1688
1689 return abis_nm_sendmsg(bts, msg);
1690}
1691
Harald Welte34a99682009-02-13 02:41:40 +00001692/* Chapter 8.9.2 */
1693int abis_nm_opstart(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1, u_int8_t i2)
1694{
1695 struct abis_om_hdr *oh;
1696 struct msgb *msg = nm_msgb_alloc();
1697
Harald Welte22af0db2009-02-14 15:41:08 +00001698 DEBUGP(DNM, "Sending OPSTART obj_class=0x%02x obj_inst=(0x%02x, 0x%02x, 0x%02x)\n",
1699 obj_class, i0, i1, i2);
Harald Welte34a99682009-02-13 02:41:40 +00001700 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1701 fill_om_fom_hdr(oh, 0, NM_MT_OPSTART, obj_class, i0, i1, i2);
1702
1703 return abis_nm_sendmsg(bts, msg);
1704}
1705
1706/* Chapter 8.8.5 */
1707int abis_nm_chg_adm_state(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0,
1708 u_int8_t i1, u_int8_t i2, u_int8_t adm_state)
1709{
1710 struct abis_om_hdr *oh;
1711 struct msgb *msg = nm_msgb_alloc();
1712
1713 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1714 fill_om_fom_hdr(oh, 2, NM_MT_CHG_ADM_STATE, obj_class, i0, i1, i2);
1715 msgb_tv_put(msg, NM_ATT_ADM_STATE, adm_state);
1716
1717 return abis_nm_sendmsg(bts, msg);
1718}
1719
1720
Harald Welte52b1f982008-12-23 20:25:15 +00001721int abis_nm_event_reports(struct gsm_bts *bts, int on)
1722{
1723 if (on == 0)
Harald Welte227d4072009-01-03 08:16:25 +00001724 return __simple_cmd(bts, NM_MT_STOP_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001725 else
Harald Welte227d4072009-01-03 08:16:25 +00001726 return __simple_cmd(bts, NM_MT_REST_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001727}
1728
Harald Welte47d88ae2009-01-04 12:02:08 +00001729/* Siemens (or BS-11) specific commands */
1730
Harald Welte3ffd1372009-02-01 22:15:49 +00001731int abis_nm_bs11_bsc_disconnect(struct gsm_bts *bts, int reconnect)
1732{
1733 if (reconnect == 0)
1734 return __simple_cmd(bts, NM_MT_BS11_DISCONNECT);
1735 else
1736 return __simple_cmd(bts, NM_MT_BS11_RECONNECT);
1737}
1738
Harald Welteb8427972009-02-05 19:27:17 +00001739int abis_nm_bs11_restart(struct gsm_bts *bts)
1740{
1741 return __simple_cmd(bts, NM_MT_BS11_RESTART);
1742}
1743
1744
Harald Welte268bb402009-02-01 19:11:56 +00001745struct bs11_date_time {
1746 u_int16_t year;
1747 u_int8_t month;
1748 u_int8_t day;
1749 u_int8_t hour;
1750 u_int8_t min;
1751 u_int8_t sec;
1752} __attribute__((packed));
1753
1754
1755void get_bs11_date_time(struct bs11_date_time *aet)
1756{
1757 time_t t;
1758 struct tm *tm;
1759
1760 t = time(NULL);
1761 tm = localtime(&t);
1762 aet->sec = tm->tm_sec;
1763 aet->min = tm->tm_min;
1764 aet->hour = tm->tm_hour;
1765 aet->day = tm->tm_mday;
1766 aet->month = tm->tm_mon;
1767 aet->year = htons(1900 + tm->tm_year);
1768}
1769
Harald Welte05188ee2009-01-18 11:39:08 +00001770int abis_nm_bs11_reset_resource(struct gsm_bts *bts)
Harald Welte52b1f982008-12-23 20:25:15 +00001771{
Harald Welte4668fda2009-01-03 08:19:29 +00001772 return __simple_cmd(bts, NM_MT_BS11_RESET_RESOURCE);
Harald Welte52b1f982008-12-23 20:25:15 +00001773}
1774
Harald Welte05188ee2009-01-18 11:39:08 +00001775int abis_nm_bs11_db_transmission(struct gsm_bts *bts, int begin)
Harald Welte52b1f982008-12-23 20:25:15 +00001776{
1777 if (begin)
Harald Welte4668fda2009-01-03 08:19:29 +00001778 return __simple_cmd(bts, NM_MT_BS11_BEGIN_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00001779 else
Harald Welte4668fda2009-01-03 08:19:29 +00001780 return __simple_cmd(bts, NM_MT_BS11_END_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00001781}
Harald Welte47d88ae2009-01-04 12:02:08 +00001782
Harald Welte05188ee2009-01-18 11:39:08 +00001783int abis_nm_bs11_create_object(struct gsm_bts *bts,
Harald Welte1bc09062009-01-18 14:17:52 +00001784 enum abis_bs11_objtype type, u_int8_t idx,
1785 u_int8_t attr_len, const u_int8_t *attr)
Harald Welte47d88ae2009-01-04 12:02:08 +00001786{
1787 struct abis_om_hdr *oh;
1788 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00001789 u_int8_t *cur;
Harald Welte47d88ae2009-01-04 12:02:08 +00001790
1791 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001792 fill_om_fom_hdr(oh, attr_len, NM_MT_BS11_CREATE_OBJ,
Harald Welte268bb402009-02-01 19:11:56 +00001793 NM_OC_BS11, type, 0, idx);
Harald Welte1bc09062009-01-18 14:17:52 +00001794 cur = msgb_put(msg, attr_len);
1795 memcpy(cur, attr, attr_len);
Harald Welte47d88ae2009-01-04 12:02:08 +00001796
1797 return abis_nm_sendmsg(bts, msg);
1798}
1799
Harald Welte78fc0d42009-02-19 02:50:57 +00001800int abis_nm_bs11_delete_object(struct gsm_bts *bts,
1801 enum abis_bs11_objtype type, u_int8_t idx)
1802{
1803 struct abis_om_hdr *oh;
1804 struct msgb *msg = nm_msgb_alloc();
1805
1806 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1807 fill_om_fom_hdr(oh, 0, NM_MT_BS11_DELETE_OBJ,
1808 NM_OC_BS11, type, 0, idx);
1809
1810 return abis_nm_sendmsg(bts, msg);
1811}
1812
Harald Welte05188ee2009-01-18 11:39:08 +00001813int abis_nm_bs11_create_envaBTSE(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00001814{
1815 struct abis_om_hdr *oh;
1816 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00001817 u_int8_t zero = 0x00;
Harald Welte47d88ae2009-01-04 12:02:08 +00001818
1819 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001820 fill_om_fom_hdr(oh, 3, NM_MT_BS11_CREATE_OBJ,
Harald Welte1bc09062009-01-18 14:17:52 +00001821 NM_OC_BS11_ENVABTSE, 0, idx, 0xff);
1822 msgb_tlv_put(msg, 0x99, 1, &zero);
Harald Welte47d88ae2009-01-04 12:02:08 +00001823
1824 return abis_nm_sendmsg(bts, msg);
1825}
1826
Harald Welte05188ee2009-01-18 11:39:08 +00001827int abis_nm_bs11_create_bport(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00001828{
1829 struct abis_om_hdr *oh;
1830 struct msgb *msg = nm_msgb_alloc();
1831
1832 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1833 fill_om_fom_hdr(oh, 0, NM_MT_BS11_CREATE_OBJ, NM_OC_BS11_BPORT,
1834 idx, 0, 0);
1835
1836 return abis_nm_sendmsg(bts, msg);
1837}
Harald Welte05188ee2009-01-18 11:39:08 +00001838
Harald Welte78fc0d42009-02-19 02:50:57 +00001839static const u_int8_t sm_attr[] = { NM_ATT_TEI, NM_ATT_ABIS_CHANNEL };
1840int abis_nm_bs11_get_oml_tei_ts(struct gsm_bts *bts)
1841{
1842 struct abis_om_hdr *oh;
1843 struct msgb *msg = nm_msgb_alloc();
1844
1845 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1846 fill_om_fom_hdr(oh, 2+sizeof(sm_attr), NM_MT_GET_ATTR, NM_OC_SITE_MANAGER,
1847 0xff, 0xff, 0xff);
1848 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(sm_attr), sm_attr);
1849
1850 return abis_nm_sendmsg(bts, msg);
1851}
1852
Harald Welteb6c92ae2009-02-21 20:15:32 +00001853/* like abis_nm_conn_terr_traf + set_tei */
1854int abis_nm_bs11_conn_oml_tei(struct gsm_bts *bts, u_int8_t e1_port,
1855 u_int8_t e1_timeslot, u_int8_t e1_subslot,
1856 u_int8_t tei)
Harald Welte05188ee2009-01-18 11:39:08 +00001857{
1858 struct abis_om_hdr *oh;
1859 struct abis_nm_channel *ch;
1860 struct msgb *msg = nm_msgb_alloc();
1861
1862 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welteb6c92ae2009-02-21 20:15:32 +00001863 fill_om_fom_hdr(oh, sizeof(*ch)+2, NM_MT_BS11_SET_ATTR,
Harald Welte05188ee2009-01-18 11:39:08 +00001864 NM_OC_SITE_MANAGER, 0xff, 0xff, 0xff);
1865
1866 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1867 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
Harald Welteb6c92ae2009-02-21 20:15:32 +00001868 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte05188ee2009-01-18 11:39:08 +00001869
1870 return abis_nm_sendmsg(bts, msg);
1871}
1872
1873int abis_nm_bs11_set_trx_power(struct gsm_bts_trx *trx, u_int8_t level)
1874{
1875 struct abis_om_hdr *oh;
1876 struct msgb *msg = nm_msgb_alloc();
Harald Welte05188ee2009-01-18 11:39:08 +00001877
1878 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001879 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR,
Harald Welte05188ee2009-01-18 11:39:08 +00001880 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
1881 msgb_tlv_put(msg, NM_ATT_BS11_TXPWR, 1, &level);
1882
1883 return abis_nm_sendmsg(trx->bts, msg);
1884}
1885
Harald Welte78fc0d42009-02-19 02:50:57 +00001886int abis_nm_bs11_get_trx_power(struct gsm_bts_trx *trx)
1887{
1888 struct abis_om_hdr *oh;
1889 struct msgb *msg = nm_msgb_alloc();
1890 u_int8_t attr = NM_ATT_BS11_TXPWR;
1891
1892 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1893 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
1894 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
1895 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), &attr);
1896
1897 return abis_nm_sendmsg(trx->bts, msg);
1898}
1899
Harald Welteaaf02d92009-04-29 13:25:57 +00001900int abis_nm_bs11_get_pll_mode(struct gsm_bts *bts)
1901{
1902 struct abis_om_hdr *oh;
1903 struct msgb *msg = nm_msgb_alloc();
Harald Weltea7cfa032009-04-29 22:33:02 +00001904 u_int8_t attr[] = { NM_ATT_BS11_PLL_MODE };
Harald Welteaaf02d92009-04-29 13:25:57 +00001905
1906 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1907 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
1908 NM_OC_BS11, BS11_OBJ_LI, 0x00, 0x00);
Harald Welteaeedeb42009-05-01 13:08:14 +00001909 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), attr);
Harald Welteaaf02d92009-04-29 13:25:57 +00001910
1911 return abis_nm_sendmsg(bts, msg);
1912}
1913
Harald Welteef061952009-05-17 12:43:42 +00001914int abis_nm_bs11_get_cclk(struct gsm_bts *bts)
1915{
1916 struct abis_om_hdr *oh;
1917 struct msgb *msg = nm_msgb_alloc();
1918 u_int8_t attr[] = { NM_ATT_BS11_CCLK_ACCURACY,
1919 NM_ATT_BS11_CCLK_TYPE };
1920
1921 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1922 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
1923 NM_OC_BS11, BS11_OBJ_CCLK, 0x00, 0x00);
1924 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), attr);
1925
1926 return abis_nm_sendmsg(bts, msg);
1927
1928}
Harald Welteaaf02d92009-04-29 13:25:57 +00001929
Harald Welte268bb402009-02-01 19:11:56 +00001930//static const u_int8_t bs11_logon_c7[] = { 0x07, 0xd9, 0x01, 0x11, 0x0d, 0x10, 0x20 };
Harald Weltebb151312009-01-28 20:42:07 +00001931static const u_int8_t bs11_logon_c8[] = { 0x02 };
Harald Welte05188ee2009-01-18 11:39:08 +00001932static const u_int8_t bs11_logon_c9[] = "FACTORY";
1933
Harald Welte1bc09062009-01-18 14:17:52 +00001934int abis_nm_bs11_factory_logon(struct gsm_bts *bts, int on)
Harald Welte05188ee2009-01-18 11:39:08 +00001935{
1936 struct abis_om_hdr *oh;
1937 struct msgb *msg = nm_msgb_alloc();
Harald Welte268bb402009-02-01 19:11:56 +00001938 struct bs11_date_time bdt;
1939
1940 get_bs11_date_time(&bdt);
Harald Welte05188ee2009-01-18 11:39:08 +00001941
1942 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte1bc09062009-01-18 14:17:52 +00001943 if (on) {
Harald Welte268bb402009-02-01 19:11:56 +00001944 u_int8_t len = 3*2 + sizeof(bdt)
Harald Welte6f676a32009-01-18 14:27:48 +00001945 + sizeof(bs11_logon_c8) + sizeof(bs11_logon_c9);
Harald Welte043d04a2009-01-29 23:15:30 +00001946 fill_om_fom_hdr(oh, len, NM_MT_BS11_LMT_LOGON,
Harald Welte7b26bcb2009-05-28 11:39:21 +00001947 NM_OC_BS11_BTSE, 0xff, 0xff, 0xff);
Harald Welte043d04a2009-01-29 23:15:30 +00001948 msgb_tlv_put(msg, NM_ATT_BS11_LMT_LOGIN_TIME,
Harald Welte5083b0b2009-02-02 19:20:52 +00001949 sizeof(bdt), (u_int8_t *) &bdt);
Harald Welte043d04a2009-01-29 23:15:30 +00001950 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_ACC_LEV,
1951 sizeof(bs11_logon_c8), bs11_logon_c8);
1952 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_NAME,
1953 sizeof(bs11_logon_c9), bs11_logon_c9);
Harald Welte1bc09062009-01-18 14:17:52 +00001954 } else {
Harald Welte5e4d1b32009-02-01 13:36:56 +00001955 fill_om_fom_hdr(oh, 0, NM_MT_BS11_LMT_LOGOFF,
Harald Welte7b26bcb2009-05-28 11:39:21 +00001956 NM_OC_BS11_BTSE, 0xff, 0xff, 0xff);
Harald Welte1bc09062009-01-18 14:17:52 +00001957 }
Harald Welte05188ee2009-01-18 11:39:08 +00001958
1959 return abis_nm_sendmsg(bts, msg);
1960}
Harald Welte1bc09062009-01-18 14:17:52 +00001961
1962int abis_nm_bs11_set_trx1_pw(struct gsm_bts *bts, const char *password)
1963{
1964 struct abis_om_hdr *oh;
1965 struct msgb *msg;
1966
1967 if (strlen(password) != 10)
1968 return -EINVAL;
1969
1970 msg = nm_msgb_alloc();
1971 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001972 fill_om_fom_hdr(oh, 2+strlen(password), NM_MT_BS11_SET_ATTR,
Harald Welte1bc09062009-01-18 14:17:52 +00001973 NM_OC_BS11, BS11_OBJ_TRX1, 0x00, 0x00);
1974 msgb_tlv_put(msg, NM_ATT_BS11_PASSWORD, 10, (const u_int8_t *)password);
1975
1976 return abis_nm_sendmsg(bts, msg);
1977}
1978
Harald Weltee69f5fb2009-04-28 16:31:38 +00001979/* change the BS-11 PLL Mode to either locked (E1 derived) or standalone */
1980int abis_nm_bs11_set_pll_locked(struct gsm_bts *bts, int locked)
1981{
1982 struct abis_om_hdr *oh;
1983 struct msgb *msg;
Harald Weltea432cd32009-04-29 13:01:50 +00001984 u_int8_t tlv_value;
Harald Weltee69f5fb2009-04-28 16:31:38 +00001985
1986 msg = nm_msgb_alloc();
1987 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1988 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR, NM_OC_BS11,
1989 BS11_OBJ_LI, 0x00, 0x00);
Harald Weltea432cd32009-04-29 13:01:50 +00001990
1991 if (locked)
1992 tlv_value = BS11_LI_PLL_LOCKED;
1993 else
1994 tlv_value = BS11_LI_PLL_STANDALONE;
1995
1996 msgb_tlv_put(msg, NM_ATT_BS11_PLL_MODE, 1, &tlv_value);
Harald Weltee69f5fb2009-04-28 16:31:38 +00001997
1998 return abis_nm_sendmsg(bts, msg);
1999}
2000
Harald Welte1bc09062009-01-18 14:17:52 +00002001int abis_nm_bs11_get_state(struct gsm_bts *bts)
2002{
2003 return __simple_cmd(bts, NM_MT_BS11_GET_STATE);
2004}
Harald Welte5e4d1b32009-02-01 13:36:56 +00002005
2006/* BS11 SWL */
2007
2008struct abis_nm_bs11_sw {
2009 struct gsm_bts *bts;
2010 char swl_fname[PATH_MAX];
2011 u_int8_t win_size;
Harald Welte3ffd1372009-02-01 22:15:49 +00002012 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00002013 struct llist_head file_list;
2014 gsm_cbfn *user_cb; /* specified by the user */
2015};
2016static struct abis_nm_bs11_sw _g_bs11_sw, *g_bs11_sw = &_g_bs11_sw;
2017
2018struct file_list_entry {
2019 struct llist_head list;
2020 char fname[PATH_MAX];
2021};
2022
2023struct file_list_entry *fl_dequeue(struct llist_head *queue)
2024{
2025 struct llist_head *lh;
2026
2027 if (llist_empty(queue))
2028 return NULL;
2029
2030 lh = queue->next;
2031 llist_del(lh);
2032
2033 return llist_entry(lh, struct file_list_entry, list);
2034}
2035
2036static int bs11_read_swl_file(struct abis_nm_bs11_sw *bs11_sw)
2037{
2038 char linebuf[255];
2039 struct llist_head *lh, *lh2;
2040 FILE *swl;
2041 int rc = 0;
2042
2043 swl = fopen(bs11_sw->swl_fname, "r");
2044 if (!swl)
2045 return -ENODEV;
2046
2047 /* zero the stale file list, if any */
2048 llist_for_each_safe(lh, lh2, &bs11_sw->file_list) {
2049 llist_del(lh);
2050 free(lh);
2051 }
2052
2053 while (fgets(linebuf, sizeof(linebuf), swl)) {
2054 char file_id[12+1];
2055 char file_version[80+1];
2056 struct file_list_entry *fle;
2057 static char dir[PATH_MAX];
2058
2059 if (strlen(linebuf) < 4)
2060 continue;
Harald Welte3ffd1372009-02-01 22:15:49 +00002061
Harald Welte5e4d1b32009-02-01 13:36:56 +00002062 rc = sscanf(linebuf+4, "%12s:%80s\r\n", file_id, file_version);
2063 if (rc < 0) {
2064 perror("ERR parsing SWL file");
2065 rc = -EINVAL;
2066 goto out;
2067 }
2068 if (rc < 2)
2069 continue;
2070
2071 fle = malloc(sizeof(*fle));
2072 if (!fle) {
2073 rc = -ENOMEM;
2074 goto out;
2075 }
2076 memset(fle, 0, sizeof(*fle));
2077
2078 /* construct new filename */
2079 strncpy(dir, bs11_sw->swl_fname, sizeof(dir));
2080 strncat(fle->fname, dirname(dir), sizeof(fle->fname) - 1);
2081 strcat(fle->fname, "/");
2082 strncat(fle->fname, file_id, sizeof(fle->fname) - 1 -strlen(fle->fname));
Harald Welte5e4d1b32009-02-01 13:36:56 +00002083
2084 llist_add_tail(&fle->list, &bs11_sw->file_list);
2085 }
2086
2087out:
2088 fclose(swl);
2089 return rc;
2090}
2091
2092/* bs11 swload specific callback, passed to abis_nm core swload */
2093static int bs11_swload_cbfn(unsigned int hook, unsigned int event,
2094 struct msgb *msg, void *data, void *param)
2095{
2096 struct abis_nm_bs11_sw *bs11_sw = data;
2097 struct file_list_entry *fle;
2098 int rc = 0;
2099
Harald Welte5e4d1b32009-02-01 13:36:56 +00002100 switch (event) {
2101 case NM_MT_LOAD_END_ACK:
2102 fle = fl_dequeue(&bs11_sw->file_list);
2103 if (fle) {
2104 /* start download the next file of our file list */
2105 rc = abis_nm_software_load(bs11_sw->bts, fle->fname,
2106 bs11_sw->win_size,
Harald Welte3ffd1372009-02-01 22:15:49 +00002107 bs11_sw->forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00002108 &bs11_swload_cbfn, bs11_sw);
2109 free(fle);
2110 } else {
2111 /* activate the SWL */
2112 rc = abis_nm_software_activate(bs11_sw->bts,
2113 bs11_sw->swl_fname,
2114 bs11_swload_cbfn,
2115 bs11_sw);
2116 }
2117 break;
Harald Welte3ffd1372009-02-01 22:15:49 +00002118 case NM_MT_LOAD_SEG_ACK:
Harald Welte5e4d1b32009-02-01 13:36:56 +00002119 case NM_MT_LOAD_END_NACK:
2120 case NM_MT_LOAD_INIT_ACK:
2121 case NM_MT_LOAD_INIT_NACK:
2122 case NM_MT_ACTIVATE_SW_NACK:
2123 case NM_MT_ACTIVATE_SW_ACK:
2124 default:
2125 /* fallthrough to the user callback */
Harald Welte97ed1e72009-02-06 13:38:02 +00002126 if (bs11_sw->user_cb)
2127 rc = bs11_sw->user_cb(hook, event, msg, NULL, NULL);
Harald Welte5e4d1b32009-02-01 13:36:56 +00002128 break;
2129 }
2130
2131 return rc;
2132}
2133
2134/* Siemens provides a SWL file that is a mere listing of all the other
2135 * files that are part of a software release. We need to upload first
2136 * the list file, and then each file that is listed in the list file */
2137int abis_nm_bs11_load_swl(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00002138 u_int8_t win_size, int forced, gsm_cbfn *cbfn)
Harald Welte5e4d1b32009-02-01 13:36:56 +00002139{
2140 struct abis_nm_bs11_sw *bs11_sw = g_bs11_sw;
2141 struct file_list_entry *fle;
2142 int rc = 0;
2143
2144 INIT_LLIST_HEAD(&bs11_sw->file_list);
2145 bs11_sw->bts = bts;
2146 bs11_sw->win_size = win_size;
2147 bs11_sw->user_cb = cbfn;
Harald Welte3ffd1372009-02-01 22:15:49 +00002148 bs11_sw->forced = forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00002149
2150 strncpy(bs11_sw->swl_fname, fname, sizeof(bs11_sw->swl_fname));
2151 rc = bs11_read_swl_file(bs11_sw);
2152 if (rc < 0)
2153 return rc;
2154
2155 /* dequeue next item in file list */
2156 fle = fl_dequeue(&bs11_sw->file_list);
2157 if (!fle)
2158 return -EINVAL;
2159
2160 /* start download the next file of our file list */
Harald Welte3ffd1372009-02-01 22:15:49 +00002161 rc = abis_nm_software_load(bts, fle->fname, win_size, forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00002162 bs11_swload_cbfn, bs11_sw);
2163 free(fle);
2164 return rc;
2165}
2166
Harald Welte5083b0b2009-02-02 19:20:52 +00002167#if 0
Harald Welte5e4d1b32009-02-01 13:36:56 +00002168static u_int8_t req_attr_btse[] = {
2169 NM_ATT_ADM_STATE, NM_ATT_BS11_LMT_LOGON_SESSION,
2170 NM_ATT_BS11_LMT_LOGIN_TIME, NM_ATT_BS11_LMT_USER_ACC_LEV,
2171 NM_ATT_BS11_LMT_USER_NAME,
2172
2173 0xaf, NM_ATT_BS11_RX_OFFSET, NM_ATT_BS11_VENDOR_NAME,
2174
2175 NM_ATT_BS11_SW_LOAD_INTENDED, NM_ATT_BS11_SW_LOAD_SAFETY,
2176
2177 NM_ATT_BS11_SW_LOAD_STORED };
2178
2179static u_int8_t req_attr_btsm[] = {
2180 NM_ATT_ABIS_CHANNEL, NM_ATT_TEI, NM_ATT_BS11_ABIS_EXT_TIME,
2181 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xce, NM_ATT_FILE_ID,
2182 NM_ATT_FILE_VERSION, NM_ATT_OPER_STATE, 0xe8, NM_ATT_BS11_ALL_TEST_CATG,
2183 NM_ATT_SW_DESCR, NM_ATT_GET_ARI };
Harald Welte5083b0b2009-02-02 19:20:52 +00002184#endif
Harald Welte5e4d1b32009-02-01 13:36:56 +00002185
2186static u_int8_t req_attr[] = {
2187 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xa8, NM_ATT_OPER_STATE,
2188 0xd5, 0xa1, NM_ATT_BS11_ESN_FW_CODE_NO, NM_ATT_BS11_ESN_HW_CODE_NO,
Harald Weltea7cfa032009-04-29 22:33:02 +00002189 0x42, NM_ATT_BS11_ESN_PCB_SERIAL, NM_ATT_BS11_PLL };
Harald Welte5e4d1b32009-02-01 13:36:56 +00002190
2191int abis_nm_bs11_get_serno(struct gsm_bts *bts)
2192{
2193 struct abis_om_hdr *oh;
2194 struct msgb *msg = nm_msgb_alloc();
2195
2196 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2197 /* SiemensHW CCTRL object */
2198 fill_om_fom_hdr(oh, 2+sizeof(req_attr), NM_MT_GET_ATTR, NM_OC_BS11,
2199 0x03, 0x00, 0x00);
2200 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(req_attr), req_attr);
2201
2202 return abis_nm_sendmsg(bts, msg);
2203}
Harald Welte268bb402009-02-01 19:11:56 +00002204
2205int abis_nm_bs11_set_ext_time(struct gsm_bts *bts)
2206{
2207 struct abis_om_hdr *oh;
2208 struct msgb *msg = nm_msgb_alloc();
2209 struct bs11_date_time aet;
2210
2211 get_bs11_date_time(&aet);
2212 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2213 /* SiemensHW CCTRL object */
2214 fill_om_fom_hdr(oh, 2+sizeof(aet), NM_MT_BS11_SET_ATTR, NM_OC_SITE_MANAGER,
2215 0xff, 0xff, 0xff);
Harald Welte5083b0b2009-02-02 19:20:52 +00002216 msgb_tlv_put(msg, NM_ATT_BS11_ABIS_EXT_TIME, sizeof(aet), (u_int8_t *) &aet);
Harald Welte268bb402009-02-01 19:11:56 +00002217
2218 return abis_nm_sendmsg(bts, msg);
2219}
Harald Welte5c1e4582009-02-15 11:57:29 +00002220
2221/* ip.access nanoBTS specific commands */
Harald Welte5c1e4582009-02-15 11:57:29 +00002222static const char ipaccess_magic[] = "com.ipaccess";
2223
Harald Welte677c21f2009-02-17 13:22:23 +00002224
2225static int abis_nm_rx_ipacc(struct msgb *msg)
2226{
2227 struct abis_om_hdr *oh = msgb_l2(msg);
2228 struct abis_om_fom_hdr *foh;
2229 u_int8_t idstrlen = oh->data[0];
2230 struct tlv_parsed tp;
2231
2232 if (strncmp((char *)&oh->data[1], ipaccess_magic, idstrlen)) {
2233 DEBUGP(DNM, "id string is not com.ipaccess !?!\n");
2234 return -EINVAL;
2235 }
2236
Harald Welte193fefc2009-04-30 15:16:27 +00002237 foh = (struct abis_om_fom_hdr *) (oh->data + 1 + idstrlen);
Harald Welte03133942009-02-18 19:51:53 +00002238 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Welte677c21f2009-02-17 13:22:23 +00002239
Harald Welte193fefc2009-04-30 15:16:27 +00002240 DEBUGP(DNM, "IPACCESS(0x%02x): ", foh->msg_type);
2241
Harald Welte677c21f2009-02-17 13:22:23 +00002242 switch (foh->msg_type) {
2243 case NM_MT_IPACC_RSL_CONNECT_ACK:
Harald Welte193fefc2009-04-30 15:16:27 +00002244 DEBUGPC(DNM, "RSL CONNECT ACK ");
Harald Welte677c21f2009-02-17 13:22:23 +00002245 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_RSL_BSC_IP))
Harald Welte9de2bf82009-04-30 15:59:55 +00002246 DEBUGPC(DNM, "IP=%s ",
Harald Welte677c21f2009-02-17 13:22:23 +00002247 inet_ntoa(*((struct in_addr *)
2248 TLVP_VAL(&tp, NM_ATT_IPACC_RSL_BSC_IP))));
2249 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_RSL_BSC_PORT))
Harald Welte9de2bf82009-04-30 15:59:55 +00002250 DEBUGPC(DNM, "PORT=%u ",
Harald Welte677c21f2009-02-17 13:22:23 +00002251 ntohs(*((u_int16_t *)
2252 TLVP_VAL(&tp, NM_ATT_IPACC_RSL_BSC_PORT))));
Harald Welte9de2bf82009-04-30 15:59:55 +00002253 DEBUGPC(DNM, "\n");
Harald Welte677c21f2009-02-17 13:22:23 +00002254 break;
2255 case NM_MT_IPACC_RSL_CONNECT_NACK:
Harald Welte193fefc2009-04-30 15:16:27 +00002256 DEBUGPC(DNM, "RSL CONNECT NACK ");
Harald Welte677c21f2009-02-17 13:22:23 +00002257 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
Harald Welte6c96ba52009-05-01 13:03:40 +00002258 DEBUGPC(DNM, " CAUSE=%s\n",
2259 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
Harald Welte677c21f2009-02-17 13:22:23 +00002260 else
2261 DEBUGPC(DNM, "\n");
2262 break;
Harald Welte193fefc2009-04-30 15:16:27 +00002263 case NM_MT_IPACC_SET_NVATTR_ACK:
2264 DEBUGPC(DNM, "SET NVATTR ACK\n");
2265 /* FIXME: decode and show the actual attributes */
2266 break;
2267 case NM_MT_IPACC_SET_NVATTR_NACK:
Harald Welte6c96ba52009-05-01 13:03:40 +00002268 DEBUGPC(DNM, "SET NVATTR NACK ");
2269 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
2270 DEBUGPC(DNM, " CAUSE=%s\n",
2271 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
2272 else
2273 DEBUGPC(DNM, "\n");
Harald Welte193fefc2009-04-30 15:16:27 +00002274 break;
2275 default:
2276 DEBUGPC(DNM, "unknown\n");
2277 break;
Harald Welte677c21f2009-02-17 13:22:23 +00002278 }
2279 return 0;
2280}
2281
Harald Welte193fefc2009-04-30 15:16:27 +00002282/* send an ip-access manufacturer specific message */
Harald Welte5c1e4582009-02-15 11:57:29 +00002283int abis_nm_ipaccess_msg(struct gsm_bts *bts, u_int8_t msg_type,
2284 u_int8_t obj_class, u_int8_t bts_nr,
2285 u_int8_t trx_nr, u_int8_t ts_nr,
2286 u_int8_t *attr, int attr_len)
2287{
2288 struct msgb *msg = nm_msgb_alloc();
2289 struct abis_om_hdr *oh;
2290 struct abis_om_fom_hdr *foh;
2291 u_int8_t *data;
2292
2293 /* construct the 12.21 OM header, observe the erroneous length */
2294 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
2295 fill_om_hdr(oh, sizeof(*foh) + attr_len);
2296 oh->mdisc = ABIS_OM_MDISC_MANUF;
2297
2298 /* add the ip.access magic */
2299 data = msgb_put(msg, sizeof(ipaccess_magic)+1);
2300 *data++ = sizeof(ipaccess_magic);
2301 memcpy(data, ipaccess_magic, sizeof(ipaccess_magic));
2302
2303 /* fill the 12.21 FOM header */
2304 foh = (struct abis_om_fom_hdr *) msgb_put(msg, sizeof(*foh));
2305 foh->msg_type = msg_type;
2306 foh->obj_class = obj_class;
2307 foh->obj_inst.bts_nr = bts_nr;
2308 foh->obj_inst.trx_nr = trx_nr;
2309 foh->obj_inst.ts_nr = ts_nr;
2310
2311 if (attr && attr_len) {
2312 data = msgb_put(msg, attr_len);
2313 memcpy(data, attr, attr_len);
2314 }
2315
2316 return abis_nm_sendmsg(bts, msg);
2317}
Harald Welte677c21f2009-02-17 13:22:23 +00002318
Harald Welte193fefc2009-04-30 15:16:27 +00002319/* set some attributes in NVRAM */
2320int abis_nm_ipaccess_set_nvattr(struct gsm_bts *bts, u_int8_t *attr,
2321 int attr_len)
2322{
2323 return abis_nm_ipaccess_msg(bts, NM_MT_IPACC_SET_NVATTR,
2324 NM_OC_BASEB_TRANSC, 0, 0, 0xff, attr,
2325 attr_len);
2326}
2327
2328/* restart / reboot an ip.access nanoBTS */
2329int abis_nm_ipaccess_restart(struct gsm_bts *bts)
2330{
2331 return __simple_cmd(bts, NM_MT_IPACC_RESTART);
2332}