blob: 905289b6d4ffe48bef6184feae9b390e30cc2a5f [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 Welte5d4b1c22009-06-12 01:34:29 +0800697 DEBUGPC(DNM, "ADM=%02s ", 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");
Holger Hans Peter Freyther500f3ca2009-06-10 10:48:14 +0200896
897 dispatch_signal(SS_NM, S_NM_NACK, (void*) ((long)mt));
898 return 0;
Harald Welte78fc0d42009-02-19 02:50:57 +0000899 }
Harald Weltead384642008-12-26 10:20:07 +0000900#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000901 /* check if last message is to be acked */
902 if (is_ack_nack(nmh->last_msgtype)) {
903 if (mt == MT_ACK(nmh->last_msgtype)) {
904 fprintf(stderr, "received ACK (0x%x)\n",
905 foh->msg_type);
906 /* we got our ACK, continue sending the next msg */
907 } else if (mt == MT_NACK(nmh->last_msgtype)) {
908 /* we got a NACK, signal this to the caller */
909 fprintf(stderr, "received NACK (0x%x)\n",
910 foh->msg_type);
911 /* FIXME: somehow signal this to the caller */
912 } else {
913 /* really strange things happen */
914 return -EINVAL;
915 }
916 }
Harald Weltead384642008-12-26 10:20:07 +0000917#endif
918
Harald Welte97ed1e72009-02-06 13:38:02 +0000919 switch (mt) {
Harald Weltee0590df2009-02-15 03:34:15 +0000920 case NM_MT_CHG_ADM_STATE_ACK:
921 return abis_nm_rx_chg_adm_state_ack(mb);
922 break;
Harald Welte34a99682009-02-13 02:41:40 +0000923 case NM_MT_SW_ACT_REQ:
924 return abis_nm_rx_sw_act_req(mb);
925 break;
Harald Welte97ed1e72009-02-06 13:38:02 +0000926 case NM_MT_BS11_LMT_SESSION:
Harald Welteee670472009-02-22 21:58:49 +0000927 return abis_nm_rx_lmt_event(mb);
Harald Welte97ed1e72009-02-06 13:38:02 +0000928 break;
929 }
930
Harald Weltead384642008-12-26 10:20:07 +0000931 return 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000932}
933
Harald Welte677c21f2009-02-17 13:22:23 +0000934static int abis_nm_rx_ipacc(struct msgb *mb);
935
936static int abis_nm_rcvmsg_manuf(struct msgb *mb)
937{
938 int rc;
939 int bts_type = mb->trx->bts->type;
940
941 switch (bts_type) {
942 case GSM_BTS_TYPE_NANOBTS_900:
943 case GSM_BTS_TYPE_NANOBTS_1800:
944 rc = abis_nm_rx_ipacc(mb);
945 break;
946 default:
947 fprintf(stderr, "don't know how to parse OML for this "
948 "BTS type (%u)\n", bts_type);
949 rc = 0;
950 break;
951 }
952
953 return rc;
954}
955
Harald Welte52b1f982008-12-23 20:25:15 +0000956/* High-Level API */
957/* Entry-point where L2 OML from BTS enters the NM code */
Harald Welte8470bf22008-12-25 23:28:35 +0000958int abis_nm_rcvmsg(struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +0000959{
Harald Welte52b1f982008-12-23 20:25:15 +0000960 struct abis_om_hdr *oh = msgb_l2(msg);
Harald Welte677c21f2009-02-17 13:22:23 +0000961 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000962
963 /* Various consistency checks */
964 if (oh->placement != ABIS_OM_PLACEMENT_ONLY) {
965 fprintf(stderr, "ABIS OML placement 0x%x not supported\n",
966 oh->placement);
967 return -EINVAL;
968 }
969 if (oh->sequence != 0) {
970 fprintf(stderr, "ABIS OML sequence 0x%x != 0x00\n",
971 oh->sequence);
972 return -EINVAL;
973 }
Harald Welte702d8702008-12-26 20:25:35 +0000974#if 0
Holger Freytherca362a62009-01-04 21:05:01 +0000975 unsigned int l2_len = msg->tail - (u_int8_t *)msgb_l2(msg);
976 unsigned int hlen = sizeof(*oh) + sizeof(struct abis_om_fom_hdr);
Harald Welte702d8702008-12-26 20:25:35 +0000977 if (oh->length + hlen > l2_len) {
Harald Welte52b1f982008-12-23 20:25:15 +0000978 fprintf(stderr, "ABIS OML truncated message (%u > %u)\n",
979 oh->length + sizeof(*oh), l2_len);
980 return -EINVAL;
981 }
Harald Welte702d8702008-12-26 20:25:35 +0000982 if (oh->length + hlen < l2_len)
983 fprintf(stderr, "ABIS OML message with extra trailer?!? (oh->len=%d, sizeof_oh=%d l2_len=%d\n", oh->length, sizeof(*oh), l2_len);
984#endif
Harald Weltead384642008-12-26 10:20:07 +0000985 msg->l3h = (unsigned char *)oh + sizeof(*oh);
Harald Welte52b1f982008-12-23 20:25:15 +0000986
987 switch (oh->mdisc) {
988 case ABIS_OM_MDISC_FOM:
Harald Welte8470bf22008-12-25 23:28:35 +0000989 rc = abis_nm_rcvmsg_fom(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000990 break;
Harald Welte677c21f2009-02-17 13:22:23 +0000991 case ABIS_OM_MDISC_MANUF:
992 rc = abis_nm_rcvmsg_manuf(msg);
993 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000994 case ABIS_OM_MDISC_MMI:
995 case ABIS_OM_MDISC_TRAU:
Harald Welte677c21f2009-02-17 13:22:23 +0000996 fprintf(stderr, "unimplemented ABIS OML message discriminator 0x%x\n",
997 oh->mdisc);
998 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000999 default:
1000 fprintf(stderr, "unknown ABIS OML message discriminator 0x%x\n",
1001 oh->mdisc);
1002 return -EINVAL;
1003 }
1004
Harald Weltead384642008-12-26 10:20:07 +00001005 msgb_free(msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001006 return rc;
1007}
1008
1009#if 0
1010/* initialized all resources */
1011struct abis_nm_h *abis_nm_init(struct abis_nm_cfg *cfg)
1012{
1013 struct abis_nm_h *nmh;
1014
1015 nmh = malloc(sizeof(*nmh));
1016 if (!nmh)
1017 return NULL;
1018
1019 nmh->cfg = cfg;
1020
1021 return nmh;
1022}
1023
1024/* free all resources */
1025void abis_nm_fini(struct abis_nm_h *nmh)
1026{
1027 free(nmh);
1028}
1029#endif
1030
1031/* Here we are trying to define a high-level API that can be used by
1032 * the actual BSC implementation. However, the architecture is currently
1033 * still under design. Ideally the calls to this API would be synchronous,
1034 * while the underlying stack behind the APi runs in a traditional select
1035 * based state machine.
1036 */
1037
Harald Welte4724f992009-01-18 18:01:49 +00001038/* 6.2 Software Load: */
1039enum sw_state {
1040 SW_STATE_NONE,
1041 SW_STATE_WAIT_INITACK,
1042 SW_STATE_WAIT_SEGACK,
1043 SW_STATE_WAIT_ENDACK,
1044 SW_STATE_WAIT_ACTACK,
1045 SW_STATE_ERROR,
1046};
Harald Welte52b1f982008-12-23 20:25:15 +00001047
Harald Welte52b1f982008-12-23 20:25:15 +00001048struct abis_nm_sw {
Harald Welte4724f992009-01-18 18:01:49 +00001049 struct gsm_bts *bts;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001050 gsm_cbfn *cbfn;
1051 void *cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +00001052 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001053
Harald Welte52b1f982008-12-23 20:25:15 +00001054 /* this will become part of the SW LOAD INITIATE */
1055 u_int8_t obj_class;
1056 u_int8_t obj_instance[3];
Harald Welte4724f992009-01-18 18:01:49 +00001057
1058 u_int8_t file_id[255];
1059 u_int8_t file_id_len;
1060
1061 u_int8_t file_version[255];
1062 u_int8_t file_version_len;
1063
1064 u_int8_t window_size;
1065 u_int8_t seg_in_window;
1066
1067 int fd;
1068 FILE *stream;
1069 enum sw_state state;
Harald Welte1602ade2009-01-29 21:12:39 +00001070 int last_seg;
Harald Welte52b1f982008-12-23 20:25:15 +00001071};
1072
Harald Welte4724f992009-01-18 18:01:49 +00001073static struct abis_nm_sw g_sw;
1074
1075/* 6.2.1 / 8.3.1: Load Data Initiate */
1076static int sw_load_init(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +00001077{
Harald Welte4724f992009-01-18 18:01:49 +00001078 struct abis_om_hdr *oh;
1079 struct msgb *msg = nm_msgb_alloc();
1080 u_int8_t len = 3*2 + sw->file_id_len + sw->file_version_len;
1081
1082 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1083 fill_om_fom_hdr(oh, len, NM_MT_LOAD_INIT, sw->obj_class,
1084 sw->obj_instance[0], sw->obj_instance[1],
1085 sw->obj_instance[2]);
1086
1087 /* FIXME: this is BS11 specific format */
1088 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1089 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1090 sw->file_version);
1091 msgb_tv_put(msg, NM_ATT_WINDOW_SIZE, sw->window_size);
1092
1093 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001094}
1095
Harald Welte1602ade2009-01-29 21:12:39 +00001096static int is_last_line(FILE *stream)
1097{
1098 char next_seg_buf[256];
1099 long pos;
1100
1101 /* check if we're sending the last line */
1102 pos = ftell(stream);
1103 if (!fgets(next_seg_buf, sizeof(next_seg_buf)-2, stream)) {
1104 fseek(stream, pos, SEEK_SET);
1105 return 1;
1106 }
1107
1108 fseek(stream, pos, SEEK_SET);
1109 return 0;
1110}
1111
Harald Welte4724f992009-01-18 18:01:49 +00001112/* 6.2.2 / 8.3.2 Load Data Segment */
1113static int sw_load_segment(struct abis_nm_sw *sw)
1114{
1115 struct abis_om_hdr *oh;
1116 struct msgb *msg = nm_msgb_alloc();
1117 char seg_buf[256];
1118 char *line_buf = seg_buf+2;
Harald Welte3b8ba212009-01-29 12:27:58 +00001119 unsigned char *tlv;
Harald Welte4724f992009-01-18 18:01:49 +00001120 u_int8_t len;
Harald Welte4724f992009-01-18 18:01:49 +00001121
1122 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte3b8ba212009-01-29 12:27:58 +00001123
1124 switch (sw->bts->type) {
1125 case GSM_BTS_TYPE_BS11:
1126 if (fgets(line_buf, sizeof(seg_buf)-2, sw->stream) == NULL) {
1127 perror("fgets reading segment");
1128 return -EINVAL;
1129 }
1130 seg_buf[0] = 0x00;
Harald Welte1602ade2009-01-29 21:12:39 +00001131
1132 /* check if we're sending the last line */
1133 sw->last_seg = is_last_line(sw->stream);
1134 if (sw->last_seg)
1135 seg_buf[1] = 0;
1136 else
1137 seg_buf[1] = 1 + sw->seg_in_window++;
Harald Welte3b8ba212009-01-29 12:27:58 +00001138
1139 len = strlen(line_buf) + 2;
1140 tlv = msgb_put(msg, TLV_GROSS_LEN(len));
1141 tlv_put(tlv, NM_ATT_BS11_FILE_DATA, len, (u_int8_t *)seg_buf);
1142 /* BS11 wants CR + LF in excess of the TLV length !?! */
1143 tlv[1] -= 2;
1144
1145 /* we only now know the exact length for the OM hdr */
1146 len = strlen(line_buf)+2;
1147 break;
1148 default:
1149 /* FIXME: Other BTS types */
1150 return -1;
Harald Welte4724f992009-01-18 18:01:49 +00001151 }
Harald Welte4724f992009-01-18 18:01:49 +00001152
Harald Welte4724f992009-01-18 18:01:49 +00001153 fill_om_fom_hdr(oh, len, NM_MT_LOAD_SEG, sw->obj_class,
1154 sw->obj_instance[0], sw->obj_instance[1],
1155 sw->obj_instance[2]);
1156
1157 return abis_nm_sendmsg(sw->bts, msg);
1158}
1159
1160/* 6.2.4 / 8.3.4 Load Data End */
1161static int sw_load_end(struct abis_nm_sw *sw)
1162{
1163 struct abis_om_hdr *oh;
1164 struct msgb *msg = nm_msgb_alloc();
1165 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
1166
1167 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1168 fill_om_fom_hdr(oh, len, NM_MT_LOAD_END, sw->obj_class,
1169 sw->obj_instance[0], sw->obj_instance[1],
1170 sw->obj_instance[2]);
1171
1172 /* FIXME: this is BS11 specific format */
1173 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1174 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1175 sw->file_version);
1176
1177 return abis_nm_sendmsg(sw->bts, msg);
1178}
Harald Welte5e4d1b32009-02-01 13:36:56 +00001179
Harald Welte52b1f982008-12-23 20:25:15 +00001180/* Activate the specified software into the BTS */
Harald Welte4724f992009-01-18 18:01:49 +00001181static int sw_activate(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +00001182{
Harald Welte4724f992009-01-18 18:01:49 +00001183 struct abis_om_hdr *oh;
1184 struct msgb *msg = nm_msgb_alloc();
1185 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
Harald Welte52b1f982008-12-23 20:25:15 +00001186
Harald Welte4724f992009-01-18 18:01:49 +00001187 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1188 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, sw->obj_class,
1189 sw->obj_instance[0], sw->obj_instance[1],
1190 sw->obj_instance[2]);
1191
1192 /* FIXME: this is BS11 specific format */
1193 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1194 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1195 sw->file_version);
1196
1197 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001198}
Harald Welte4724f992009-01-18 18:01:49 +00001199
1200static int sw_open_file(struct abis_nm_sw *sw, const char *fname)
1201{
1202 char file_id[12+1];
1203 char file_version[80+1];
1204 int rc;
1205
1206 sw->fd = open(fname, O_RDONLY);
1207 if (sw->fd < 0)
1208 return sw->fd;
1209
1210 switch (sw->bts->type) {
1211 case GSM_BTS_TYPE_BS11:
1212 sw->stream = fdopen(sw->fd, "r");
1213 if (!sw->stream) {
1214 perror("fdopen");
1215 return -1;
1216 }
1217 /* read first line and parse file ID and VERSION */
Harald Welte3b8ba212009-01-29 12:27:58 +00001218 rc = fscanf(sw->stream, "@(#)%12s:%80s\r\n",
Harald Welte4724f992009-01-18 18:01:49 +00001219 file_id, file_version);
1220 if (rc != 2) {
1221 perror("parsing header line of software file");
1222 return -1;
1223 }
1224 strcpy((char *)sw->file_id, file_id);
1225 sw->file_id_len = strlen(file_id);
1226 strcpy((char *)sw->file_version, file_version);
1227 sw->file_version_len = strlen(file_version);
1228 /* rewind to start of file */
Harald Welte3b8ba212009-01-29 12:27:58 +00001229 rewind(sw->stream);
Harald Welte4724f992009-01-18 18:01:49 +00001230 break;
1231 default:
1232 /* We don't know how to treat them yet */
1233 close(sw->fd);
1234 return -EINVAL;
1235 }
1236
1237 return 0;
1238}
1239
1240static void sw_close_file(struct abis_nm_sw *sw)
1241{
1242 switch (sw->bts->type) {
1243 case GSM_BTS_TYPE_BS11:
1244 fclose(sw->stream);
1245 break;
1246 default:
1247 close(sw->fd);
1248 break;
1249 }
1250}
1251
1252/* Fill the window */
1253static int sw_fill_window(struct abis_nm_sw *sw)
1254{
1255 int rc;
1256
1257 while (sw->seg_in_window < sw->window_size) {
1258 rc = sw_load_segment(sw);
1259 if (rc < 0)
1260 return rc;
Harald Welte1602ade2009-01-29 21:12:39 +00001261 if (sw->last_seg)
1262 break;
Harald Welte4724f992009-01-18 18:01:49 +00001263 }
1264 return 0;
1265}
1266
1267/* callback function from abis_nm_rcvmsg() handler */
1268static int abis_nm_rcvmsg_sw(struct msgb *mb)
1269{
1270 struct abis_om_fom_hdr *foh = msgb_l3(mb);
1271 int rc = -1;
1272 struct abis_nm_sw *sw = &g_sw;
1273 enum sw_state old_state = sw->state;
1274
Harald Welte3ffd1372009-02-01 22:15:49 +00001275 //DEBUGP(DNM, "state %u, NM MT 0x%02x\n", sw->state, foh->msg_type);
Harald Welte4724f992009-01-18 18:01:49 +00001276
1277 switch (sw->state) {
1278 case SW_STATE_WAIT_INITACK:
1279 switch (foh->msg_type) {
1280 case NM_MT_LOAD_INIT_ACK:
1281 /* fill window with segments */
Harald Welte5e4d1b32009-02-01 13:36:56 +00001282 if (sw->cbfn)
1283 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1284 NM_MT_LOAD_INIT_ACK, mb,
1285 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001286 rc = sw_fill_window(sw);
1287 sw->state = SW_STATE_WAIT_SEGACK;
1288 break;
1289 case NM_MT_LOAD_INIT_NACK:
Harald Welte3ffd1372009-02-01 22:15:49 +00001290 if (sw->forced) {
1291 DEBUGP(DNM, "FORCED: Ignoring Software Load "
1292 "Init NACK\n");
1293 if (sw->cbfn)
1294 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1295 NM_MT_LOAD_INIT_ACK, mb,
1296 sw->cb_data, NULL);
1297 rc = sw_fill_window(sw);
1298 sw->state = SW_STATE_WAIT_SEGACK;
1299 } else {
1300 DEBUGP(DNM, "Software Load Init NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001301 /* FIXME: cause */
Harald Welte3ffd1372009-02-01 22:15:49 +00001302 if (sw->cbfn)
1303 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1304 NM_MT_LOAD_INIT_NACK, mb,
1305 sw->cb_data, NULL);
1306 sw->state = SW_STATE_ERROR;
1307 }
Harald Welte4724f992009-01-18 18:01:49 +00001308 break;
1309 }
1310 break;
1311 case SW_STATE_WAIT_SEGACK:
1312 switch (foh->msg_type) {
1313 case NM_MT_LOAD_SEG_ACK:
Harald Welte3ffd1372009-02-01 22:15:49 +00001314 if (sw->cbfn)
1315 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1316 NM_MT_LOAD_SEG_ACK, mb,
1317 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001318 sw->seg_in_window = 0;
Harald Welte1602ade2009-01-29 21:12:39 +00001319 if (!sw->last_seg) {
1320 /* fill window with more segments */
1321 rc = sw_fill_window(sw);
1322 sw->state = SW_STATE_WAIT_SEGACK;
1323 } else {
1324 /* end the transfer */
1325 sw->state = SW_STATE_WAIT_ENDACK;
1326 rc = sw_load_end(sw);
1327 }
Harald Welte4724f992009-01-18 18:01:49 +00001328 break;
1329 }
1330 break;
1331 case SW_STATE_WAIT_ENDACK:
1332 switch (foh->msg_type) {
1333 case NM_MT_LOAD_END_ACK:
1334 sw_close_file(sw);
Harald Welte5e4d1b32009-02-01 13:36:56 +00001335 DEBUGP(DNM, "Software Load End (BTS %u)\n",
1336 sw->bts->nr);
1337 sw->state = SW_STATE_NONE;
1338 if (sw->cbfn)
1339 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1340 NM_MT_LOAD_END_ACK, mb,
1341 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001342 break;
1343 case NM_MT_LOAD_END_NACK:
Holger Freyther31338a12009-02-06 17:43:50 +00001344 if (sw->forced) {
1345 DEBUGP(DNM, "FORCED: Ignoring Software Load"
1346 "End NACK\n");
1347 sw->state = SW_STATE_NONE;
1348 if (sw->cbfn)
1349 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1350 NM_MT_LOAD_END_ACK, mb,
1351 sw->cb_data, NULL);
1352 } else {
1353 DEBUGP(DNM, "Software Load End NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001354 /* FIXME: cause */
Holger Freyther31338a12009-02-06 17:43:50 +00001355 sw->state = SW_STATE_ERROR;
1356 if (sw->cbfn)
1357 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1358 NM_MT_LOAD_END_NACK, mb,
1359 sw->cb_data, NULL);
1360 }
Harald Welte4724f992009-01-18 18:01:49 +00001361 break;
1362 }
1363 case SW_STATE_WAIT_ACTACK:
1364 switch (foh->msg_type) {
1365 case NM_MT_ACTIVATE_SW_ACK:
1366 /* we're done */
Harald Welte5e4d1b32009-02-01 13:36:56 +00001367 DEBUGP(DNM, "Activate Software DONE!\n");
Harald Welte4724f992009-01-18 18:01:49 +00001368 sw->state = SW_STATE_NONE;
1369 rc = 0;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001370 if (sw->cbfn)
1371 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1372 NM_MT_ACTIVATE_SW_ACK, mb,
1373 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001374 break;
1375 case NM_MT_ACTIVATE_SW_NACK:
Harald Welte1602ade2009-01-29 21:12:39 +00001376 DEBUGP(DNM, "Activate Software NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001377 /* FIXME: cause */
Harald Welte4724f992009-01-18 18:01:49 +00001378 sw->state = SW_STATE_ERROR;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001379 if (sw->cbfn)
1380 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1381 NM_MT_ACTIVATE_SW_NACK, mb,
1382 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001383 break;
1384 }
1385 case SW_STATE_NONE:
Harald Weltea994a482009-05-01 15:54:23 +00001386 switch (foh->msg_type) {
1387 case NM_MT_ACTIVATE_SW_ACK:
1388 rc = 0;
1389 break;
1390 }
1391 break;
Harald Welte4724f992009-01-18 18:01:49 +00001392 case SW_STATE_ERROR:
1393 break;
1394 }
1395
1396 if (rc)
Harald Weltea994a482009-05-01 15:54:23 +00001397 DEBUGP(DNM, "unexpected NM MT 0x%02x in state %u -> %u\n",
Harald Welte4724f992009-01-18 18:01:49 +00001398 foh->msg_type, old_state, sw->state);
1399
1400 return rc;
1401}
1402
1403/* Load the specified software into the BTS */
1404int abis_nm_software_load(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00001405 u_int8_t win_size, int forced,
1406 gsm_cbfn *cbfn, void *cb_data)
Harald Welte4724f992009-01-18 18:01:49 +00001407{
1408 struct abis_nm_sw *sw = &g_sw;
1409 int rc;
1410
Harald Welte5e4d1b32009-02-01 13:36:56 +00001411 DEBUGP(DNM, "Software Load (BTS %u, File \"%s\")\n",
1412 bts->nr, fname);
1413
Harald Welte4724f992009-01-18 18:01:49 +00001414 if (sw->state != SW_STATE_NONE)
1415 return -EBUSY;
1416
1417 sw->bts = bts;
1418 sw->obj_class = NM_OC_SITE_MANAGER;
1419 sw->obj_instance[0] = 0xff;
1420 sw->obj_instance[1] = 0xff;
1421 sw->obj_instance[2] = 0xff;
1422 sw->window_size = win_size;
1423 sw->state = SW_STATE_WAIT_INITACK;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001424 sw->cbfn = cbfn;
1425 sw->cb_data = cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +00001426 sw->forced = forced;
Harald Welte4724f992009-01-18 18:01:49 +00001427
1428 rc = sw_open_file(sw, fname);
1429 if (rc < 0) {
1430 sw->state = SW_STATE_NONE;
1431 return rc;
1432 }
1433
1434 return sw_load_init(sw);
1435}
Harald Welte52b1f982008-12-23 20:25:15 +00001436
Harald Welte1602ade2009-01-29 21:12:39 +00001437int abis_nm_software_load_status(struct gsm_bts *bts)
1438{
1439 struct abis_nm_sw *sw = &g_sw;
1440 struct stat st;
1441 int rc, percent;
1442
1443 rc = fstat(sw->fd, &st);
1444 if (rc < 0) {
1445 perror("ERROR during stat");
1446 return rc;
1447 }
1448
1449 percent = (ftell(sw->stream) * 100) / st.st_size;
1450 return percent;
1451}
1452
Harald Welte5e4d1b32009-02-01 13:36:56 +00001453/* Activate the specified software into the BTS */
1454int abis_nm_software_activate(struct gsm_bts *bts, const char *fname,
1455 gsm_cbfn *cbfn, void *cb_data)
1456{
1457 struct abis_nm_sw *sw = &g_sw;
1458 int rc;
1459
1460 DEBUGP(DNM, "Activating Software (BTS %u, File \"%s\")\n",
1461 bts->nr, fname);
1462
1463 if (sw->state != SW_STATE_NONE)
1464 return -EBUSY;
1465
1466 sw->bts = bts;
1467 sw->obj_class = NM_OC_SITE_MANAGER;
1468 sw->obj_instance[0] = 0xff;
1469 sw->obj_instance[1] = 0xff;
1470 sw->obj_instance[2] = 0xff;
1471 sw->state = SW_STATE_WAIT_ACTACK;
1472 sw->cbfn = cbfn;
1473 sw->cb_data = cb_data;
1474
1475 /* Open the file in order to fill some sw struct members */
1476 rc = sw_open_file(sw, fname);
1477 if (rc < 0) {
1478 sw->state = SW_STATE_NONE;
1479 return rc;
1480 }
1481 sw_close_file(sw);
1482
1483 return sw_activate(sw);
1484}
1485
Harald Welte8470bf22008-12-25 23:28:35 +00001486static void fill_nm_channel(struct abis_nm_channel *ch, u_int8_t bts_port,
Harald Welte52b1f982008-12-23 20:25:15 +00001487 u_int8_t ts_nr, u_int8_t subslot_nr)
1488{
Harald Welteadaf08b2009-01-18 11:08:10 +00001489 ch->attrib = NM_ATT_ABIS_CHANNEL;
Harald Welte52b1f982008-12-23 20:25:15 +00001490 ch->bts_port = bts_port;
1491 ch->timeslot = ts_nr;
1492 ch->subslot = subslot_nr;
1493}
1494
1495int abis_nm_establish_tei(struct gsm_bts *bts, u_int8_t trx_nr,
1496 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot,
1497 u_int8_t tei)
1498{
1499 struct abis_om_hdr *oh;
1500 struct abis_nm_channel *ch;
Harald Welte702d8702008-12-26 20:25:35 +00001501 u_int8_t len = sizeof(*ch) + 2;
Harald Welte8470bf22008-12-25 23:28:35 +00001502 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001503
1504 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1505 fill_om_fom_hdr(oh, len, NM_MT_ESTABLISH_TEI, NM_OC_RADIO_CARRIER,
1506 bts->bts_nr, trx_nr, 0xff);
1507
Harald Welte8470bf22008-12-25 23:28:35 +00001508 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte52b1f982008-12-23 20:25:15 +00001509
1510 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1511 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1512
1513 return abis_nm_sendmsg(bts, msg);
1514}
1515
1516/* connect signalling of one (BTS,TRX) to a particular timeslot on the E1 */
1517int abis_nm_conn_terr_sign(struct gsm_bts_trx *trx,
1518 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot)
1519{
Harald Welte8470bf22008-12-25 23:28:35 +00001520 struct gsm_bts *bts = trx->bts;
Harald Welte52b1f982008-12-23 20:25:15 +00001521 struct abis_om_hdr *oh;
1522 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +00001523 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001524
1525 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001526 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_SIGN,
Harald Welte52b1f982008-12-23 20:25:15 +00001527 NM_OC_RADIO_CARRIER, bts->bts_nr, trx->nr, 0xff);
1528
1529 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1530 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1531
1532 return abis_nm_sendmsg(bts, msg);
1533}
1534
1535#if 0
1536int abis_nm_disc_terr_sign(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1537 struct abis_nm_abis_channel *chan)
1538{
1539}
1540#endif
1541
1542int abis_nm_conn_terr_traf(struct gsm_bts_trx_ts *ts,
1543 u_int8_t e1_port, u_int8_t e1_timeslot,
1544 u_int8_t e1_subslot)
1545{
1546 struct gsm_bts *bts = ts->trx->bts;
1547 struct abis_om_hdr *oh;
1548 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +00001549 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001550
1551 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1552 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_TRAF,
Harald Welteb110cee2009-02-18 03:42:35 +00001553 NM_OC_CHANNEL, bts->bts_nr, ts->trx->nr, ts->nr);
Harald Welte52b1f982008-12-23 20:25:15 +00001554
1555 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1556 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1557
Harald Weltef325eb42009-02-19 17:07:39 +00001558 DEBUGP(DNM, "CONNECT TERR TRAF Um=%s E1=(%u,%u,%u)\n",
1559 gsm_ts_name(ts),
Harald Welteb110cee2009-02-18 03:42:35 +00001560 e1_port, e1_timeslot, e1_subslot);
1561
Harald Welte52b1f982008-12-23 20:25:15 +00001562 return abis_nm_sendmsg(bts, msg);
1563}
1564
1565#if 0
1566int abis_nm_disc_terr_traf(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1567 struct abis_nm_abis_channel *chan,
1568 u_int8_t subchan)
1569{
1570}
1571#endif
1572
Harald Welte22af0db2009-02-14 15:41:08 +00001573/* Chapter 8.6.1 */
1574int abis_nm_set_bts_attr(struct gsm_bts *bts, u_int8_t *attr, int attr_len)
1575{
1576 struct abis_om_hdr *oh;
1577 struct msgb *msg = nm_msgb_alloc();
1578 u_int8_t *cur;
1579
1580 DEBUGP(DNM, "Set BTS Attr (bts=%d)\n", bts->nr);
1581
1582 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte191280d2009-05-01 13:20:04 +00001583 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 +00001584 cur = msgb_put(msg, attr_len);
1585 memcpy(cur, attr, attr_len);
1586
1587 return abis_nm_sendmsg(bts, msg);
1588}
1589
1590/* Chapter 8.6.2 */
1591int abis_nm_set_radio_attr(struct gsm_bts_trx *trx, u_int8_t *attr, int attr_len)
1592{
1593 struct abis_om_hdr *oh;
1594 struct msgb *msg = nm_msgb_alloc();
1595 u_int8_t *cur;
1596
1597 DEBUGP(DNM, "Set TRX Attr (bts=%d,trx=%d)\n", trx->bts->nr, trx->nr);
1598
1599 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1600 fill_om_fom_hdr(oh, attr_len, NM_MT_SET_RADIO_ATTR, NM_OC_RADIO_CARRIER,
Harald Welte191280d2009-05-01 13:20:04 +00001601 trx->bts->bts_nr, trx->nr, 0xff);
Harald Welte22af0db2009-02-14 15:41:08 +00001602 cur = msgb_put(msg, attr_len);
1603 memcpy(cur, attr, attr_len);
1604
1605 return abis_nm_sendmsg(trx->bts, msg);
1606}
1607
1608/* Chapter 8.6.3 */
Harald Welte52b1f982008-12-23 20:25:15 +00001609int abis_nm_set_channel_attr(struct gsm_bts_trx_ts *ts, u_int8_t chan_comb)
1610{
1611 struct gsm_bts *bts = ts->trx->bts;
1612 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001613 u_int16_t arfcn = htons(ts->trx->arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001614 u_int8_t zero = 0x00;
Harald Welte8470bf22008-12-25 23:28:35 +00001615 struct msgb *msg = nm_msgb_alloc();
Harald Weltee0590df2009-02-15 03:34:15 +00001616 u_int8_t len = 2 + 2;
1617
1618 if (bts->type == GSM_BTS_TYPE_BS11)
1619 len += 4 + 2 + 2 + 3;
Harald Welte52b1f982008-12-23 20:25:15 +00001620
Harald Weltef325eb42009-02-19 17:07:39 +00001621 DEBUGP(DNM, "Set Chan Attr %s\n", gsm_ts_name(ts));
Harald Welte22af0db2009-02-14 15:41:08 +00001622
Harald Welte52b1f982008-12-23 20:25:15 +00001623 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001624 fill_om_fom_hdr(oh, len, NM_MT_SET_CHAN_ATTR,
Holger Freyther6b2d2622009-02-14 23:16:59 +00001625 NM_OC_CHANNEL, bts->bts_nr,
Harald Welte52b1f982008-12-23 20:25:15 +00001626 ts->trx->nr, ts->nr);
1627 /* FIXME: don't send ARFCN list, hopping sequence, mAIO, ...*/
Harald Weltee0590df2009-02-15 03:34:15 +00001628 if (bts->type == GSM_BTS_TYPE_BS11)
1629 msgb_tlv16_put(msg, NM_ATT_ARFCN_LIST, 1, &arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001630 msgb_tv_put(msg, NM_ATT_CHAN_COMB, chan_comb);
Harald Weltee0590df2009-02-15 03:34:15 +00001631 if (bts->type == GSM_BTS_TYPE_BS11) {
1632 msgb_tv_put(msg, NM_ATT_HSN, 0x00);
1633 msgb_tv_put(msg, NM_ATT_MAIO, 0x00);
1634 }
Harald Welte52b1f982008-12-23 20:25:15 +00001635 msgb_tv_put(msg, NM_ATT_TSC, 0x07); /* training sequence */
Harald Weltee0590df2009-02-15 03:34:15 +00001636 if (bts->type == GSM_BTS_TYPE_BS11)
1637 msgb_tlv_put(msg, 0x59, 1, &zero);
Harald Welte52b1f982008-12-23 20:25:15 +00001638
1639 return abis_nm_sendmsg(bts, msg);
1640}
1641
Harald Welte34a99682009-02-13 02:41:40 +00001642int 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 +00001643 u_int8_t i2, u_int8_t i3, int nack, u_int8_t *attr, int att_len)
Harald Welte34a99682009-02-13 02:41:40 +00001644{
1645 struct abis_om_hdr *oh;
1646 struct msgb *msg = nm_msgb_alloc();
Harald Welte5c1e4582009-02-15 11:57:29 +00001647 u_int8_t msgtype = NM_MT_SW_ACT_REQ_ACK;
1648 u_int8_t len = att_len;
1649
1650 if (nack) {
1651 len += 2;
1652 msgtype = NM_MT_SW_ACT_REQ_NACK;
1653 }
Harald Welte34a99682009-02-13 02:41:40 +00001654
1655 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte5c1e4582009-02-15 11:57:29 +00001656 fill_om_fom_hdr(oh, att_len, msgtype, obj_class, i1, i2, i3);
1657
Harald Welte34a99682009-02-13 02:41:40 +00001658 if (attr) {
1659 u_int8_t *ptr = msgb_put(msg, att_len);
1660 memcpy(ptr, attr, att_len);
1661 }
Harald Welte5c1e4582009-02-15 11:57:29 +00001662 if (nack)
1663 msgb_tv_put(msg, NM_ATT_NACK_CAUSES, NM_NACK_OBJCLASS_NOTSUPP);
Harald Welte34a99682009-02-13 02:41:40 +00001664
1665 return abis_nm_sendmsg(bts, msg);
1666}
1667
Harald Welte8470bf22008-12-25 23:28:35 +00001668int abis_nm_raw_msg(struct gsm_bts *bts, int len, u_int8_t *rawmsg)
Harald Welte52b1f982008-12-23 20:25:15 +00001669{
Harald Welte8470bf22008-12-25 23:28:35 +00001670 struct msgb *msg = nm_msgb_alloc();
1671 struct abis_om_hdr *oh;
Harald Welte52b1f982008-12-23 20:25:15 +00001672 u_int8_t *data;
1673
1674 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
1675 fill_om_hdr(oh, len);
1676 data = msgb_put(msg, len);
Harald Weltead384642008-12-26 10:20:07 +00001677 memcpy(data, rawmsg, len);
Harald Welte52b1f982008-12-23 20:25:15 +00001678
1679 return abis_nm_sendmsg(bts, msg);
1680}
1681
1682/* Siemens specific commands */
1683static int __simple_cmd(struct gsm_bts *bts, u_int8_t msg_type)
1684{
1685 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001686 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001687
1688 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001689 fill_om_fom_hdr(oh, 0, msg_type, NM_OC_SITE_MANAGER,
Harald Welte52b1f982008-12-23 20:25:15 +00001690 0xff, 0xff, 0xff);
1691
1692 return abis_nm_sendmsg(bts, msg);
1693}
1694
Harald Welte34a99682009-02-13 02:41:40 +00001695/* Chapter 8.9.2 */
1696int abis_nm_opstart(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1, u_int8_t i2)
1697{
1698 struct abis_om_hdr *oh;
1699 struct msgb *msg = nm_msgb_alloc();
1700
Harald Welte22af0db2009-02-14 15:41:08 +00001701 DEBUGP(DNM, "Sending OPSTART obj_class=0x%02x obj_inst=(0x%02x, 0x%02x, 0x%02x)\n",
1702 obj_class, i0, i1, i2);
Harald Welte34a99682009-02-13 02:41:40 +00001703 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1704 fill_om_fom_hdr(oh, 0, NM_MT_OPSTART, obj_class, i0, i1, i2);
1705
1706 return abis_nm_sendmsg(bts, msg);
1707}
1708
1709/* Chapter 8.8.5 */
1710int abis_nm_chg_adm_state(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0,
1711 u_int8_t i1, u_int8_t i2, u_int8_t adm_state)
1712{
1713 struct abis_om_hdr *oh;
1714 struct msgb *msg = nm_msgb_alloc();
1715
1716 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1717 fill_om_fom_hdr(oh, 2, NM_MT_CHG_ADM_STATE, obj_class, i0, i1, i2);
1718 msgb_tv_put(msg, NM_ATT_ADM_STATE, adm_state);
1719
1720 return abis_nm_sendmsg(bts, msg);
1721}
1722
1723
Harald Welte52b1f982008-12-23 20:25:15 +00001724int abis_nm_event_reports(struct gsm_bts *bts, int on)
1725{
1726 if (on == 0)
Harald Welte227d4072009-01-03 08:16:25 +00001727 return __simple_cmd(bts, NM_MT_STOP_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001728 else
Harald Welte227d4072009-01-03 08:16:25 +00001729 return __simple_cmd(bts, NM_MT_REST_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001730}
1731
Harald Welte47d88ae2009-01-04 12:02:08 +00001732/* Siemens (or BS-11) specific commands */
1733
Harald Welte3ffd1372009-02-01 22:15:49 +00001734int abis_nm_bs11_bsc_disconnect(struct gsm_bts *bts, int reconnect)
1735{
1736 if (reconnect == 0)
1737 return __simple_cmd(bts, NM_MT_BS11_DISCONNECT);
1738 else
1739 return __simple_cmd(bts, NM_MT_BS11_RECONNECT);
1740}
1741
Harald Welteb8427972009-02-05 19:27:17 +00001742int abis_nm_bs11_restart(struct gsm_bts *bts)
1743{
1744 return __simple_cmd(bts, NM_MT_BS11_RESTART);
1745}
1746
1747
Harald Welte268bb402009-02-01 19:11:56 +00001748struct bs11_date_time {
1749 u_int16_t year;
1750 u_int8_t month;
1751 u_int8_t day;
1752 u_int8_t hour;
1753 u_int8_t min;
1754 u_int8_t sec;
1755} __attribute__((packed));
1756
1757
1758void get_bs11_date_time(struct bs11_date_time *aet)
1759{
1760 time_t t;
1761 struct tm *tm;
1762
1763 t = time(NULL);
1764 tm = localtime(&t);
1765 aet->sec = tm->tm_sec;
1766 aet->min = tm->tm_min;
1767 aet->hour = tm->tm_hour;
1768 aet->day = tm->tm_mday;
1769 aet->month = tm->tm_mon;
1770 aet->year = htons(1900 + tm->tm_year);
1771}
1772
Harald Welte05188ee2009-01-18 11:39:08 +00001773int abis_nm_bs11_reset_resource(struct gsm_bts *bts)
Harald Welte52b1f982008-12-23 20:25:15 +00001774{
Harald Welte4668fda2009-01-03 08:19:29 +00001775 return __simple_cmd(bts, NM_MT_BS11_RESET_RESOURCE);
Harald Welte52b1f982008-12-23 20:25:15 +00001776}
1777
Harald Welte05188ee2009-01-18 11:39:08 +00001778int abis_nm_bs11_db_transmission(struct gsm_bts *bts, int begin)
Harald Welte52b1f982008-12-23 20:25:15 +00001779{
1780 if (begin)
Harald Welte4668fda2009-01-03 08:19:29 +00001781 return __simple_cmd(bts, NM_MT_BS11_BEGIN_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00001782 else
Harald Welte4668fda2009-01-03 08:19:29 +00001783 return __simple_cmd(bts, NM_MT_BS11_END_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00001784}
Harald Welte47d88ae2009-01-04 12:02:08 +00001785
Harald Welte05188ee2009-01-18 11:39:08 +00001786int abis_nm_bs11_create_object(struct gsm_bts *bts,
Harald Welte1bc09062009-01-18 14:17:52 +00001787 enum abis_bs11_objtype type, u_int8_t idx,
1788 u_int8_t attr_len, const u_int8_t *attr)
Harald Welte47d88ae2009-01-04 12:02:08 +00001789{
1790 struct abis_om_hdr *oh;
1791 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00001792 u_int8_t *cur;
Harald Welte47d88ae2009-01-04 12:02:08 +00001793
1794 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001795 fill_om_fom_hdr(oh, attr_len, NM_MT_BS11_CREATE_OBJ,
Harald Welte268bb402009-02-01 19:11:56 +00001796 NM_OC_BS11, type, 0, idx);
Harald Welte1bc09062009-01-18 14:17:52 +00001797 cur = msgb_put(msg, attr_len);
1798 memcpy(cur, attr, attr_len);
Harald Welte47d88ae2009-01-04 12:02:08 +00001799
1800 return abis_nm_sendmsg(bts, msg);
1801}
1802
Harald Welte78fc0d42009-02-19 02:50:57 +00001803int abis_nm_bs11_delete_object(struct gsm_bts *bts,
1804 enum abis_bs11_objtype type, u_int8_t idx)
1805{
1806 struct abis_om_hdr *oh;
1807 struct msgb *msg = nm_msgb_alloc();
1808
1809 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1810 fill_om_fom_hdr(oh, 0, NM_MT_BS11_DELETE_OBJ,
1811 NM_OC_BS11, type, 0, idx);
1812
1813 return abis_nm_sendmsg(bts, msg);
1814}
1815
Harald Welte05188ee2009-01-18 11:39:08 +00001816int abis_nm_bs11_create_envaBTSE(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00001817{
1818 struct abis_om_hdr *oh;
1819 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00001820 u_int8_t zero = 0x00;
Harald Welte47d88ae2009-01-04 12:02:08 +00001821
1822 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001823 fill_om_fom_hdr(oh, 3, NM_MT_BS11_CREATE_OBJ,
Harald Welte1bc09062009-01-18 14:17:52 +00001824 NM_OC_BS11_ENVABTSE, 0, idx, 0xff);
1825 msgb_tlv_put(msg, 0x99, 1, &zero);
Harald Welte47d88ae2009-01-04 12:02:08 +00001826
1827 return abis_nm_sendmsg(bts, msg);
1828}
1829
Harald Welte05188ee2009-01-18 11:39:08 +00001830int abis_nm_bs11_create_bport(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00001831{
1832 struct abis_om_hdr *oh;
1833 struct msgb *msg = nm_msgb_alloc();
1834
1835 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1836 fill_om_fom_hdr(oh, 0, NM_MT_BS11_CREATE_OBJ, NM_OC_BS11_BPORT,
1837 idx, 0, 0);
1838
1839 return abis_nm_sendmsg(bts, msg);
1840}
Harald Welte05188ee2009-01-18 11:39:08 +00001841
Harald Welte78fc0d42009-02-19 02:50:57 +00001842static const u_int8_t sm_attr[] = { NM_ATT_TEI, NM_ATT_ABIS_CHANNEL };
1843int abis_nm_bs11_get_oml_tei_ts(struct gsm_bts *bts)
1844{
1845 struct abis_om_hdr *oh;
1846 struct msgb *msg = nm_msgb_alloc();
1847
1848 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1849 fill_om_fom_hdr(oh, 2+sizeof(sm_attr), NM_MT_GET_ATTR, NM_OC_SITE_MANAGER,
1850 0xff, 0xff, 0xff);
1851 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(sm_attr), sm_attr);
1852
1853 return abis_nm_sendmsg(bts, msg);
1854}
1855
Harald Welteb6c92ae2009-02-21 20:15:32 +00001856/* like abis_nm_conn_terr_traf + set_tei */
1857int abis_nm_bs11_conn_oml_tei(struct gsm_bts *bts, u_int8_t e1_port,
1858 u_int8_t e1_timeslot, u_int8_t e1_subslot,
1859 u_int8_t tei)
Harald Welte05188ee2009-01-18 11:39:08 +00001860{
1861 struct abis_om_hdr *oh;
1862 struct abis_nm_channel *ch;
1863 struct msgb *msg = nm_msgb_alloc();
1864
1865 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welteb6c92ae2009-02-21 20:15:32 +00001866 fill_om_fom_hdr(oh, sizeof(*ch)+2, NM_MT_BS11_SET_ATTR,
Harald Welte05188ee2009-01-18 11:39:08 +00001867 NM_OC_SITE_MANAGER, 0xff, 0xff, 0xff);
1868
1869 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1870 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
Harald Welteb6c92ae2009-02-21 20:15:32 +00001871 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte05188ee2009-01-18 11:39:08 +00001872
1873 return abis_nm_sendmsg(bts, msg);
1874}
1875
1876int abis_nm_bs11_set_trx_power(struct gsm_bts_trx *trx, u_int8_t level)
1877{
1878 struct abis_om_hdr *oh;
1879 struct msgb *msg = nm_msgb_alloc();
Harald Welte05188ee2009-01-18 11:39:08 +00001880
1881 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001882 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR,
Harald Welte05188ee2009-01-18 11:39:08 +00001883 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
1884 msgb_tlv_put(msg, NM_ATT_BS11_TXPWR, 1, &level);
1885
1886 return abis_nm_sendmsg(trx->bts, msg);
1887}
1888
Harald Welte78fc0d42009-02-19 02:50:57 +00001889int abis_nm_bs11_get_trx_power(struct gsm_bts_trx *trx)
1890{
1891 struct abis_om_hdr *oh;
1892 struct msgb *msg = nm_msgb_alloc();
1893 u_int8_t attr = NM_ATT_BS11_TXPWR;
1894
1895 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1896 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
1897 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
1898 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), &attr);
1899
1900 return abis_nm_sendmsg(trx->bts, msg);
1901}
1902
Harald Welteaaf02d92009-04-29 13:25:57 +00001903int abis_nm_bs11_get_pll_mode(struct gsm_bts *bts)
1904{
1905 struct abis_om_hdr *oh;
1906 struct msgb *msg = nm_msgb_alloc();
Harald Weltea7cfa032009-04-29 22:33:02 +00001907 u_int8_t attr[] = { NM_ATT_BS11_PLL_MODE };
Harald Welteaaf02d92009-04-29 13:25:57 +00001908
1909 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1910 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
1911 NM_OC_BS11, BS11_OBJ_LI, 0x00, 0x00);
Harald Welteaeedeb42009-05-01 13:08:14 +00001912 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), attr);
Harald Welteaaf02d92009-04-29 13:25:57 +00001913
1914 return abis_nm_sendmsg(bts, msg);
1915}
1916
Harald Welteef061952009-05-17 12:43:42 +00001917int abis_nm_bs11_get_cclk(struct gsm_bts *bts)
1918{
1919 struct abis_om_hdr *oh;
1920 struct msgb *msg = nm_msgb_alloc();
1921 u_int8_t attr[] = { NM_ATT_BS11_CCLK_ACCURACY,
1922 NM_ATT_BS11_CCLK_TYPE };
1923
1924 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1925 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
1926 NM_OC_BS11, BS11_OBJ_CCLK, 0x00, 0x00);
1927 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), attr);
1928
1929 return abis_nm_sendmsg(bts, msg);
1930
1931}
Harald Welteaaf02d92009-04-29 13:25:57 +00001932
Harald Welte268bb402009-02-01 19:11:56 +00001933//static const u_int8_t bs11_logon_c7[] = { 0x07, 0xd9, 0x01, 0x11, 0x0d, 0x10, 0x20 };
Harald Weltebb151312009-01-28 20:42:07 +00001934static const u_int8_t bs11_logon_c8[] = { 0x02 };
Harald Welte05188ee2009-01-18 11:39:08 +00001935static const u_int8_t bs11_logon_c9[] = "FACTORY";
1936
Harald Welte1bc09062009-01-18 14:17:52 +00001937int abis_nm_bs11_factory_logon(struct gsm_bts *bts, int on)
Harald Welte05188ee2009-01-18 11:39:08 +00001938{
1939 struct abis_om_hdr *oh;
1940 struct msgb *msg = nm_msgb_alloc();
Harald Welte268bb402009-02-01 19:11:56 +00001941 struct bs11_date_time bdt;
1942
1943 get_bs11_date_time(&bdt);
Harald Welte05188ee2009-01-18 11:39:08 +00001944
1945 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte1bc09062009-01-18 14:17:52 +00001946 if (on) {
Harald Welte268bb402009-02-01 19:11:56 +00001947 u_int8_t len = 3*2 + sizeof(bdt)
Harald Welte6f676a32009-01-18 14:27:48 +00001948 + sizeof(bs11_logon_c8) + sizeof(bs11_logon_c9);
Harald Welte043d04a2009-01-29 23:15:30 +00001949 fill_om_fom_hdr(oh, len, NM_MT_BS11_LMT_LOGON,
Harald Welte7b26bcb2009-05-28 11:39:21 +00001950 NM_OC_BS11_BTSE, 0xff, 0xff, 0xff);
Harald Welte043d04a2009-01-29 23:15:30 +00001951 msgb_tlv_put(msg, NM_ATT_BS11_LMT_LOGIN_TIME,
Harald Welte5083b0b2009-02-02 19:20:52 +00001952 sizeof(bdt), (u_int8_t *) &bdt);
Harald Welte043d04a2009-01-29 23:15:30 +00001953 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_ACC_LEV,
1954 sizeof(bs11_logon_c8), bs11_logon_c8);
1955 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_NAME,
1956 sizeof(bs11_logon_c9), bs11_logon_c9);
Harald Welte1bc09062009-01-18 14:17:52 +00001957 } else {
Harald Welte5e4d1b32009-02-01 13:36:56 +00001958 fill_om_fom_hdr(oh, 0, NM_MT_BS11_LMT_LOGOFF,
Harald Welte7b26bcb2009-05-28 11:39:21 +00001959 NM_OC_BS11_BTSE, 0xff, 0xff, 0xff);
Harald Welte1bc09062009-01-18 14:17:52 +00001960 }
Harald Welte05188ee2009-01-18 11:39:08 +00001961
1962 return abis_nm_sendmsg(bts, msg);
1963}
Harald Welte1bc09062009-01-18 14:17:52 +00001964
1965int abis_nm_bs11_set_trx1_pw(struct gsm_bts *bts, const char *password)
1966{
1967 struct abis_om_hdr *oh;
1968 struct msgb *msg;
1969
1970 if (strlen(password) != 10)
1971 return -EINVAL;
1972
1973 msg = nm_msgb_alloc();
1974 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001975 fill_om_fom_hdr(oh, 2+strlen(password), NM_MT_BS11_SET_ATTR,
Harald Welte1bc09062009-01-18 14:17:52 +00001976 NM_OC_BS11, BS11_OBJ_TRX1, 0x00, 0x00);
1977 msgb_tlv_put(msg, NM_ATT_BS11_PASSWORD, 10, (const u_int8_t *)password);
1978
1979 return abis_nm_sendmsg(bts, msg);
1980}
1981
Harald Weltee69f5fb2009-04-28 16:31:38 +00001982/* change the BS-11 PLL Mode to either locked (E1 derived) or standalone */
1983int abis_nm_bs11_set_pll_locked(struct gsm_bts *bts, int locked)
1984{
1985 struct abis_om_hdr *oh;
1986 struct msgb *msg;
Harald Weltea432cd32009-04-29 13:01:50 +00001987 u_int8_t tlv_value;
Harald Weltee69f5fb2009-04-28 16:31:38 +00001988
1989 msg = nm_msgb_alloc();
1990 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1991 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR, NM_OC_BS11,
1992 BS11_OBJ_LI, 0x00, 0x00);
Harald Weltea432cd32009-04-29 13:01:50 +00001993
1994 if (locked)
1995 tlv_value = BS11_LI_PLL_LOCKED;
1996 else
1997 tlv_value = BS11_LI_PLL_STANDALONE;
1998
1999 msgb_tlv_put(msg, NM_ATT_BS11_PLL_MODE, 1, &tlv_value);
Harald Weltee69f5fb2009-04-28 16:31:38 +00002000
2001 return abis_nm_sendmsg(bts, msg);
2002}
2003
Harald Welte1bc09062009-01-18 14:17:52 +00002004int abis_nm_bs11_get_state(struct gsm_bts *bts)
2005{
2006 return __simple_cmd(bts, NM_MT_BS11_GET_STATE);
2007}
Harald Welte5e4d1b32009-02-01 13:36:56 +00002008
2009/* BS11 SWL */
2010
2011struct abis_nm_bs11_sw {
2012 struct gsm_bts *bts;
2013 char swl_fname[PATH_MAX];
2014 u_int8_t win_size;
Harald Welte3ffd1372009-02-01 22:15:49 +00002015 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00002016 struct llist_head file_list;
2017 gsm_cbfn *user_cb; /* specified by the user */
2018};
2019static struct abis_nm_bs11_sw _g_bs11_sw, *g_bs11_sw = &_g_bs11_sw;
2020
2021struct file_list_entry {
2022 struct llist_head list;
2023 char fname[PATH_MAX];
2024};
2025
2026struct file_list_entry *fl_dequeue(struct llist_head *queue)
2027{
2028 struct llist_head *lh;
2029
2030 if (llist_empty(queue))
2031 return NULL;
2032
2033 lh = queue->next;
2034 llist_del(lh);
2035
2036 return llist_entry(lh, struct file_list_entry, list);
2037}
2038
2039static int bs11_read_swl_file(struct abis_nm_bs11_sw *bs11_sw)
2040{
2041 char linebuf[255];
2042 struct llist_head *lh, *lh2;
2043 FILE *swl;
2044 int rc = 0;
2045
2046 swl = fopen(bs11_sw->swl_fname, "r");
2047 if (!swl)
2048 return -ENODEV;
2049
2050 /* zero the stale file list, if any */
2051 llist_for_each_safe(lh, lh2, &bs11_sw->file_list) {
2052 llist_del(lh);
2053 free(lh);
2054 }
2055
2056 while (fgets(linebuf, sizeof(linebuf), swl)) {
2057 char file_id[12+1];
2058 char file_version[80+1];
2059 struct file_list_entry *fle;
2060 static char dir[PATH_MAX];
2061
2062 if (strlen(linebuf) < 4)
2063 continue;
Harald Welte3ffd1372009-02-01 22:15:49 +00002064
Harald Welte5e4d1b32009-02-01 13:36:56 +00002065 rc = sscanf(linebuf+4, "%12s:%80s\r\n", file_id, file_version);
2066 if (rc < 0) {
2067 perror("ERR parsing SWL file");
2068 rc = -EINVAL;
2069 goto out;
2070 }
2071 if (rc < 2)
2072 continue;
2073
2074 fle = malloc(sizeof(*fle));
2075 if (!fle) {
2076 rc = -ENOMEM;
2077 goto out;
2078 }
2079 memset(fle, 0, sizeof(*fle));
2080
2081 /* construct new filename */
2082 strncpy(dir, bs11_sw->swl_fname, sizeof(dir));
2083 strncat(fle->fname, dirname(dir), sizeof(fle->fname) - 1);
2084 strcat(fle->fname, "/");
2085 strncat(fle->fname, file_id, sizeof(fle->fname) - 1 -strlen(fle->fname));
Harald Welte5e4d1b32009-02-01 13:36:56 +00002086
2087 llist_add_tail(&fle->list, &bs11_sw->file_list);
2088 }
2089
2090out:
2091 fclose(swl);
2092 return rc;
2093}
2094
2095/* bs11 swload specific callback, passed to abis_nm core swload */
2096static int bs11_swload_cbfn(unsigned int hook, unsigned int event,
2097 struct msgb *msg, void *data, void *param)
2098{
2099 struct abis_nm_bs11_sw *bs11_sw = data;
2100 struct file_list_entry *fle;
2101 int rc = 0;
2102
Harald Welte5e4d1b32009-02-01 13:36:56 +00002103 switch (event) {
2104 case NM_MT_LOAD_END_ACK:
2105 fle = fl_dequeue(&bs11_sw->file_list);
2106 if (fle) {
2107 /* start download the next file of our file list */
2108 rc = abis_nm_software_load(bs11_sw->bts, fle->fname,
2109 bs11_sw->win_size,
Harald Welte3ffd1372009-02-01 22:15:49 +00002110 bs11_sw->forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00002111 &bs11_swload_cbfn, bs11_sw);
2112 free(fle);
2113 } else {
2114 /* activate the SWL */
2115 rc = abis_nm_software_activate(bs11_sw->bts,
2116 bs11_sw->swl_fname,
2117 bs11_swload_cbfn,
2118 bs11_sw);
2119 }
2120 break;
Harald Welte3ffd1372009-02-01 22:15:49 +00002121 case NM_MT_LOAD_SEG_ACK:
Harald Welte5e4d1b32009-02-01 13:36:56 +00002122 case NM_MT_LOAD_END_NACK:
2123 case NM_MT_LOAD_INIT_ACK:
2124 case NM_MT_LOAD_INIT_NACK:
2125 case NM_MT_ACTIVATE_SW_NACK:
2126 case NM_MT_ACTIVATE_SW_ACK:
2127 default:
2128 /* fallthrough to the user callback */
Harald Welte97ed1e72009-02-06 13:38:02 +00002129 if (bs11_sw->user_cb)
2130 rc = bs11_sw->user_cb(hook, event, msg, NULL, NULL);
Harald Welte5e4d1b32009-02-01 13:36:56 +00002131 break;
2132 }
2133
2134 return rc;
2135}
2136
2137/* Siemens provides a SWL file that is a mere listing of all the other
2138 * files that are part of a software release. We need to upload first
2139 * the list file, and then each file that is listed in the list file */
2140int abis_nm_bs11_load_swl(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00002141 u_int8_t win_size, int forced, gsm_cbfn *cbfn)
Harald Welte5e4d1b32009-02-01 13:36:56 +00002142{
2143 struct abis_nm_bs11_sw *bs11_sw = g_bs11_sw;
2144 struct file_list_entry *fle;
2145 int rc = 0;
2146
2147 INIT_LLIST_HEAD(&bs11_sw->file_list);
2148 bs11_sw->bts = bts;
2149 bs11_sw->win_size = win_size;
2150 bs11_sw->user_cb = cbfn;
Harald Welte3ffd1372009-02-01 22:15:49 +00002151 bs11_sw->forced = forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00002152
2153 strncpy(bs11_sw->swl_fname, fname, sizeof(bs11_sw->swl_fname));
2154 rc = bs11_read_swl_file(bs11_sw);
2155 if (rc < 0)
2156 return rc;
2157
2158 /* dequeue next item in file list */
2159 fle = fl_dequeue(&bs11_sw->file_list);
2160 if (!fle)
2161 return -EINVAL;
2162
2163 /* start download the next file of our file list */
Harald Welte3ffd1372009-02-01 22:15:49 +00002164 rc = abis_nm_software_load(bts, fle->fname, win_size, forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00002165 bs11_swload_cbfn, bs11_sw);
2166 free(fle);
2167 return rc;
2168}
2169
Harald Welte5083b0b2009-02-02 19:20:52 +00002170#if 0
Harald Welte5e4d1b32009-02-01 13:36:56 +00002171static u_int8_t req_attr_btse[] = {
2172 NM_ATT_ADM_STATE, NM_ATT_BS11_LMT_LOGON_SESSION,
2173 NM_ATT_BS11_LMT_LOGIN_TIME, NM_ATT_BS11_LMT_USER_ACC_LEV,
2174 NM_ATT_BS11_LMT_USER_NAME,
2175
2176 0xaf, NM_ATT_BS11_RX_OFFSET, NM_ATT_BS11_VENDOR_NAME,
2177
2178 NM_ATT_BS11_SW_LOAD_INTENDED, NM_ATT_BS11_SW_LOAD_SAFETY,
2179
2180 NM_ATT_BS11_SW_LOAD_STORED };
2181
2182static u_int8_t req_attr_btsm[] = {
2183 NM_ATT_ABIS_CHANNEL, NM_ATT_TEI, NM_ATT_BS11_ABIS_EXT_TIME,
2184 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xce, NM_ATT_FILE_ID,
2185 NM_ATT_FILE_VERSION, NM_ATT_OPER_STATE, 0xe8, NM_ATT_BS11_ALL_TEST_CATG,
2186 NM_ATT_SW_DESCR, NM_ATT_GET_ARI };
Harald Welte5083b0b2009-02-02 19:20:52 +00002187#endif
Harald Welte5e4d1b32009-02-01 13:36:56 +00002188
2189static u_int8_t req_attr[] = {
2190 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xa8, NM_ATT_OPER_STATE,
2191 0xd5, 0xa1, NM_ATT_BS11_ESN_FW_CODE_NO, NM_ATT_BS11_ESN_HW_CODE_NO,
Harald Weltea7cfa032009-04-29 22:33:02 +00002192 0x42, NM_ATT_BS11_ESN_PCB_SERIAL, NM_ATT_BS11_PLL };
Harald Welte5e4d1b32009-02-01 13:36:56 +00002193
2194int abis_nm_bs11_get_serno(struct gsm_bts *bts)
2195{
2196 struct abis_om_hdr *oh;
2197 struct msgb *msg = nm_msgb_alloc();
2198
2199 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2200 /* SiemensHW CCTRL object */
2201 fill_om_fom_hdr(oh, 2+sizeof(req_attr), NM_MT_GET_ATTR, NM_OC_BS11,
2202 0x03, 0x00, 0x00);
2203 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(req_attr), req_attr);
2204
2205 return abis_nm_sendmsg(bts, msg);
2206}
Harald Welte268bb402009-02-01 19:11:56 +00002207
2208int abis_nm_bs11_set_ext_time(struct gsm_bts *bts)
2209{
2210 struct abis_om_hdr *oh;
2211 struct msgb *msg = nm_msgb_alloc();
2212 struct bs11_date_time aet;
2213
2214 get_bs11_date_time(&aet);
2215 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2216 /* SiemensHW CCTRL object */
2217 fill_om_fom_hdr(oh, 2+sizeof(aet), NM_MT_BS11_SET_ATTR, NM_OC_SITE_MANAGER,
2218 0xff, 0xff, 0xff);
Harald Welte5083b0b2009-02-02 19:20:52 +00002219 msgb_tlv_put(msg, NM_ATT_BS11_ABIS_EXT_TIME, sizeof(aet), (u_int8_t *) &aet);
Harald Welte268bb402009-02-01 19:11:56 +00002220
2221 return abis_nm_sendmsg(bts, msg);
2222}
Harald Welte5c1e4582009-02-15 11:57:29 +00002223
2224/* ip.access nanoBTS specific commands */
Harald Welte5c1e4582009-02-15 11:57:29 +00002225static const char ipaccess_magic[] = "com.ipaccess";
2226
Harald Welte677c21f2009-02-17 13:22:23 +00002227
2228static int abis_nm_rx_ipacc(struct msgb *msg)
2229{
2230 struct abis_om_hdr *oh = msgb_l2(msg);
2231 struct abis_om_fom_hdr *foh;
2232 u_int8_t idstrlen = oh->data[0];
2233 struct tlv_parsed tp;
2234
2235 if (strncmp((char *)&oh->data[1], ipaccess_magic, idstrlen)) {
2236 DEBUGP(DNM, "id string is not com.ipaccess !?!\n");
2237 return -EINVAL;
2238 }
2239
Harald Welte193fefc2009-04-30 15:16:27 +00002240 foh = (struct abis_om_fom_hdr *) (oh->data + 1 + idstrlen);
Harald Welte03133942009-02-18 19:51:53 +00002241 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Welte677c21f2009-02-17 13:22:23 +00002242
Harald Welte193fefc2009-04-30 15:16:27 +00002243 DEBUGP(DNM, "IPACCESS(0x%02x): ", foh->msg_type);
2244
Harald Welte677c21f2009-02-17 13:22:23 +00002245 switch (foh->msg_type) {
2246 case NM_MT_IPACC_RSL_CONNECT_ACK:
Harald Welte193fefc2009-04-30 15:16:27 +00002247 DEBUGPC(DNM, "RSL CONNECT ACK ");
Harald Welte677c21f2009-02-17 13:22:23 +00002248 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_RSL_BSC_IP))
Harald Welte9de2bf82009-04-30 15:59:55 +00002249 DEBUGPC(DNM, "IP=%s ",
Harald Welte677c21f2009-02-17 13:22:23 +00002250 inet_ntoa(*((struct in_addr *)
2251 TLVP_VAL(&tp, NM_ATT_IPACC_RSL_BSC_IP))));
2252 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_RSL_BSC_PORT))
Harald Welte9de2bf82009-04-30 15:59:55 +00002253 DEBUGPC(DNM, "PORT=%u ",
Harald Welte677c21f2009-02-17 13:22:23 +00002254 ntohs(*((u_int16_t *)
2255 TLVP_VAL(&tp, NM_ATT_IPACC_RSL_BSC_PORT))));
Harald Welte9de2bf82009-04-30 15:59:55 +00002256 DEBUGPC(DNM, "\n");
Harald Welte677c21f2009-02-17 13:22:23 +00002257 break;
2258 case NM_MT_IPACC_RSL_CONNECT_NACK:
Harald Welte193fefc2009-04-30 15:16:27 +00002259 DEBUGPC(DNM, "RSL CONNECT NACK ");
Harald Welte677c21f2009-02-17 13:22:23 +00002260 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
Harald Welte6c96ba52009-05-01 13:03:40 +00002261 DEBUGPC(DNM, " CAUSE=%s\n",
2262 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
Harald Welte677c21f2009-02-17 13:22:23 +00002263 else
2264 DEBUGPC(DNM, "\n");
2265 break;
Harald Welte193fefc2009-04-30 15:16:27 +00002266 case NM_MT_IPACC_SET_NVATTR_ACK:
2267 DEBUGPC(DNM, "SET NVATTR ACK\n");
2268 /* FIXME: decode and show the actual attributes */
2269 break;
2270 case NM_MT_IPACC_SET_NVATTR_NACK:
Harald Welte6c96ba52009-05-01 13:03:40 +00002271 DEBUGPC(DNM, "SET NVATTR NACK ");
2272 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
2273 DEBUGPC(DNM, " CAUSE=%s\n",
2274 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
2275 else
2276 DEBUGPC(DNM, "\n");
Harald Welte193fefc2009-04-30 15:16:27 +00002277 break;
2278 default:
2279 DEBUGPC(DNM, "unknown\n");
2280 break;
Harald Welte677c21f2009-02-17 13:22:23 +00002281 }
2282 return 0;
2283}
2284
Harald Welte193fefc2009-04-30 15:16:27 +00002285/* send an ip-access manufacturer specific message */
Harald Welte5c1e4582009-02-15 11:57:29 +00002286int abis_nm_ipaccess_msg(struct gsm_bts *bts, u_int8_t msg_type,
2287 u_int8_t obj_class, u_int8_t bts_nr,
2288 u_int8_t trx_nr, u_int8_t ts_nr,
2289 u_int8_t *attr, int attr_len)
2290{
2291 struct msgb *msg = nm_msgb_alloc();
2292 struct abis_om_hdr *oh;
2293 struct abis_om_fom_hdr *foh;
2294 u_int8_t *data;
2295
2296 /* construct the 12.21 OM header, observe the erroneous length */
2297 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
2298 fill_om_hdr(oh, sizeof(*foh) + attr_len);
2299 oh->mdisc = ABIS_OM_MDISC_MANUF;
2300
2301 /* add the ip.access magic */
2302 data = msgb_put(msg, sizeof(ipaccess_magic)+1);
2303 *data++ = sizeof(ipaccess_magic);
2304 memcpy(data, ipaccess_magic, sizeof(ipaccess_magic));
2305
2306 /* fill the 12.21 FOM header */
2307 foh = (struct abis_om_fom_hdr *) msgb_put(msg, sizeof(*foh));
2308 foh->msg_type = msg_type;
2309 foh->obj_class = obj_class;
2310 foh->obj_inst.bts_nr = bts_nr;
2311 foh->obj_inst.trx_nr = trx_nr;
2312 foh->obj_inst.ts_nr = ts_nr;
2313
2314 if (attr && attr_len) {
2315 data = msgb_put(msg, attr_len);
2316 memcpy(data, attr, attr_len);
2317 }
2318
2319 return abis_nm_sendmsg(bts, msg);
2320}
Harald Welte677c21f2009-02-17 13:22:23 +00002321
Harald Welte193fefc2009-04-30 15:16:27 +00002322/* set some attributes in NVRAM */
2323int abis_nm_ipaccess_set_nvattr(struct gsm_bts *bts, u_int8_t *attr,
2324 int attr_len)
2325{
2326 return abis_nm_ipaccess_msg(bts, NM_MT_IPACC_SET_NVATTR,
2327 NM_OC_BASEB_TRANSC, 0, 0, 0xff, attr,
2328 attr_len);
2329}
2330
2331/* restart / reboot an ip.access nanoBTS */
2332int abis_nm_ipaccess_restart(struct gsm_bts *bts)
2333{
2334 return __simple_cmd(bts, NM_MT_IPACC_RESTART);
2335}