blob: 57d4159840103ed2c7845579a7e4d6b50f018a14 [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:
450 return "CHANNL";
451 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";
475 }
476
477 return "UNKNOWN";
Harald Welte34a99682009-02-13 02:41:40 +0000478}
479
Harald Welte4d87f242009-03-10 19:43:44 +0000480const char *nm_opstate_name(u_int8_t os)
Harald Welte34a99682009-02-13 02:41:40 +0000481{
482 switch (os) {
483 case 1:
484 return "Disabled";
485 case 2:
486 return "Enabled";
487 case 0xff:
488 return "NULL";
489 default:
490 return "RFU";
491 }
492}
493
Harald Weltee0590df2009-02-15 03:34:15 +0000494/* Chapter 9.4.7 */
Harald Welte4d87f242009-03-10 19:43:44 +0000495static const char *avail_names[] = {
Harald Weltee0590df2009-02-15 03:34:15 +0000496 "In test",
497 "Failed",
498 "Power off",
499 "Off line",
500 "<not used>",
501 "Dependency",
502 "Degraded",
503 "Not installed",
504};
505
Harald Welte4d87f242009-03-10 19:43:44 +0000506const char *nm_avail_name(u_int8_t avail)
Harald Weltee0590df2009-02-15 03:34:15 +0000507{
Harald Welte0b8348d2009-02-18 03:43:01 +0000508 if (avail == 0xff)
509 return "OK";
Harald Weltee0590df2009-02-15 03:34:15 +0000510 if (avail >= ARRAY_SIZE(avail_names))
511 return "UNKNOWN";
512 return avail_names[avail];
513}
Harald Welte7b26bcb2009-05-28 11:39:21 +0000514
515const char *nm_adm_name(u_int8_t adm)
516{
517 switch (adm) {
518 case 1:
519 return "Locked";
520 case 2:
521 return "Unlocked";
522 case 3:
523 return "Shutdown";
524 default:
525 return "<not used>";
526 }
527}
Harald Weltee0590df2009-02-15 03:34:15 +0000528
529/* obtain the gsm_nm_state data structure for a given object instance */
530static struct gsm_nm_state *
531objclass2nmstate(struct gsm_bts *bts, u_int8_t obj_class,
532 struct abis_om_obj_inst *obj_inst)
533{
534 struct gsm_bts_trx *trx;
535 struct gsm_nm_state *nm_state = NULL;
536
537 switch (obj_class) {
538 case NM_OC_BTS:
539 nm_state = &bts->nm_state;
540 break;
541 case NM_OC_RADIO_CARRIER:
542 if (obj_inst->trx_nr >= bts->num_trx)
543 return NULL;
544 trx = &bts->trx[obj_inst->trx_nr];
545 nm_state = &trx->nm_state;
546 break;
547 case NM_OC_BASEB_TRANSC:
548 if (obj_inst->trx_nr >= bts->num_trx)
549 return NULL;
550 trx = &bts->trx[obj_inst->trx_nr];
551 nm_state = &trx->bb_transc.nm_state;
552 break;
553 case NM_OC_CHANNEL:
554 if (obj_inst->trx_nr > bts->num_trx)
555 return NULL;
556 trx = &bts->trx[obj_inst->trx_nr];
557 if (obj_inst->ts_nr >= TRX_NR_TS)
558 return NULL;
559 nm_state = &trx->ts[obj_inst->ts_nr].nm_state;
560 break;
561 case NM_OC_SITE_MANAGER:
562 nm_state = &bts->site_mgr.nm_state;
563 break;
Harald Welte7b26bcb2009-05-28 11:39:21 +0000564 case NM_OC_BS11:
565 switch (obj_inst->bts_nr) {
566 case BS11_OBJ_CCLK:
567 nm_state = &bts->bs11.cclk.nm_state;
568 break;
569 default:
570 return NULL;
571 }
572 case NM_OC_BS11_RACK:
573 nm_state = &bts->bs11.rack.nm_state;
574 break;
Harald Weltee0590df2009-02-15 03:34:15 +0000575 }
576 return nm_state;
577}
578
579/* obtain the in-memory data structure of a given object instance */
580static void *
581objclass2obj(struct gsm_bts *bts, u_int8_t obj_class,
582 struct abis_om_obj_inst *obj_inst)
583{
584 struct gsm_bts_trx *trx;
585 void *obj = NULL;
586
587 switch (obj_class) {
588 case NM_OC_BTS:
589 obj = bts;
590 break;
591 case NM_OC_RADIO_CARRIER:
592 if (obj_inst->trx_nr >= bts->num_trx)
593 return NULL;
594 trx = &bts->trx[obj_inst->trx_nr];
595 obj = trx;
596 break;
597 case NM_OC_BASEB_TRANSC:
598 if (obj_inst->trx_nr >= bts->num_trx)
599 return NULL;
600 trx = &bts->trx[obj_inst->trx_nr];
601 obj = &trx->bb_transc;
602 break;
603 case NM_OC_CHANNEL:
604 if (obj_inst->trx_nr > bts->num_trx)
605 return NULL;
606 trx = &bts->trx[obj_inst->trx_nr];
607 if (obj_inst->ts_nr >= TRX_NR_TS)
608 return NULL;
609 obj = &trx->ts[obj_inst->ts_nr];
610 break;
611 case NM_OC_SITE_MANAGER:
612 obj = &bts->site_mgr;
613 break;
614 }
615 return obj;
616}
617
618/* Update the administrative state of a given object in our in-memory data
619 * structures and send an event to the higher layer */
620static int update_admstate(struct gsm_bts *bts, u_int8_t obj_class,
621 struct abis_om_obj_inst *obj_inst, u_int8_t adm_state)
622{
Harald Welteaeedeb42009-05-01 13:08:14 +0000623 struct gsm_nm_state *nm_state, new_state;
Harald Weltee0590df2009-02-15 03:34:15 +0000624 void *obj;
625 int rc;
626
Harald Weltee0590df2009-02-15 03:34:15 +0000627 obj = objclass2obj(bts, obj_class, obj_inst);
Harald Welteaeedeb42009-05-01 13:08:14 +0000628 nm_state = objclass2nmstate(bts, obj_class, obj_inst);
629 if (!nm_state)
630 return -1;
631
632 new_state = *nm_state;
633 new_state.administrative = adm_state;
634
635 rc = nm_state_event(EVT_STATECHG_ADM, obj_class, obj, nm_state, &new_state);
636
637 nm_state->administrative = adm_state;
Harald Weltee0590df2009-02-15 03:34:15 +0000638
639 return rc;
640}
641
Harald Welte97ed1e72009-02-06 13:38:02 +0000642static int abis_nm_rx_statechg_rep(struct msgb *mb)
643{
Harald Weltee0590df2009-02-15 03:34:15 +0000644 struct abis_om_hdr *oh = msgb_l2(mb);
Harald Welte97ed1e72009-02-06 13:38:02 +0000645 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Harald Welte22af0db2009-02-14 15:41:08 +0000646 struct gsm_bts *bts = mb->trx->bts;
Harald Weltee0590df2009-02-15 03:34:15 +0000647 struct tlv_parsed tp;
648 struct gsm_nm_state *nm_state, new_state;
649 int rc;
650
Harald Welte23897662009-05-01 14:52:51 +0000651 DEBUGPC(DNM, "STATE CHG: ");
Harald Weltee0590df2009-02-15 03:34:15 +0000652
653 nm_state = objclass2nmstate(bts, foh->obj_class, &foh->obj_inst);
654 if (!nm_state) {
655 DEBUGPC(DNM, "\n");
656 return -EINVAL;
Harald Welte22af0db2009-02-14 15:41:08 +0000657 }
Harald Weltee0590df2009-02-15 03:34:15 +0000658
659 new_state = *nm_state;
660
Harald Welte03133942009-02-18 19:51:53 +0000661 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Weltee0590df2009-02-15 03:34:15 +0000662 if (TLVP_PRESENT(&tp, NM_ATT_OPER_STATE)) {
663 new_state.operational = *TLVP_VAL(&tp, NM_ATT_OPER_STATE);
Harald Welte4d87f242009-03-10 19:43:44 +0000664 DEBUGPC(DNM, "OP_STATE=%s ", nm_opstate_name(new_state.operational));
Harald Weltee0590df2009-02-15 03:34:15 +0000665 }
666 if (TLVP_PRESENT(&tp, NM_ATT_AVAIL_STATUS)) {
Harald Welte0b8348d2009-02-18 03:43:01 +0000667 if (TLVP_LEN(&tp, NM_ATT_AVAIL_STATUS) == 0)
668 new_state.availability = 0xff;
669 else
670 new_state.availability = *TLVP_VAL(&tp, NM_ATT_AVAIL_STATUS);
Harald Welte4d87f242009-03-10 19:43:44 +0000671 DEBUGPC(DNM, "AVAIL=%s(%02x) ", nm_avail_name(new_state.availability),
Harald Weltee0590df2009-02-15 03:34:15 +0000672 new_state.availability);
673 }
674 if (TLVP_PRESENT(&tp, NM_ATT_ADM_STATE)) {
675 new_state.administrative = *TLVP_VAL(&tp, NM_ATT_ADM_STATE);
Harald Welte7b26bcb2009-05-28 11:39:21 +0000676 DEBUGPC(DNM, "ADM=%02x ", nm_adm_name(new_state.administrative));
Harald Welte97ed1e72009-02-06 13:38:02 +0000677 }
678 DEBUGPC(DNM, "\n");
Harald Weltee0590df2009-02-15 03:34:15 +0000679
680 if (memcmp(&new_state, nm_state, sizeof(new_state))) {
681 /* Update the operational state of a given object in our in-memory data
682 * structures and send an event to the higher layer */
683 void *obj = objclass2obj(bts, foh->obj_class, &foh->obj_inst);
684 rc = nm_state_event(EVT_STATECHG_OPER, foh->obj_class, obj, nm_state, &new_state);
685 *nm_state = new_state;
686 }
687#if 0
Harald Welte22af0db2009-02-14 15:41:08 +0000688 if (op_state == 1) {
689 /* try to enable objects that are disabled */
690 abis_nm_opstart(bts, foh->obj_class,
691 foh->obj_inst.bts_nr,
692 foh->obj_inst.trx_nr,
693 foh->obj_inst.ts_nr);
694 }
Harald Weltee0590df2009-02-15 03:34:15 +0000695#endif
Harald Welte97ed1e72009-02-06 13:38:02 +0000696 return 0;
697}
698
Harald Welte0db97b22009-05-01 17:22:47 +0000699static int rx_fail_evt_rep(struct msgb *mb)
700{
701 struct abis_om_hdr *oh = msgb_l2(mb);
702 struct abis_om_fom_hdr *foh = msgb_l3(mb);
703 struct tlv_parsed tp;
704
705 DEBUGPC(DNM, "Failure Event Report ");
706
707 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
708
709 if (TLVP_PRESENT(&tp, NM_ATT_EVENT_TYPE))
710 DEBUGPC(DNM, "Type=%s ", event_type_name(*TLVP_VAL(&tp, NM_ATT_EVENT_TYPE)));
711 if (TLVP_PRESENT(&tp, NM_ATT_SEVERITY))
712 DEBUGPC(DNM, "Severity=%s ", severity_name(*TLVP_VAL(&tp, NM_ATT_SEVERITY)));
713
714 DEBUGPC(DNM, "\n");
715
716 return 0;
717}
718
Harald Welte97ed1e72009-02-06 13:38:02 +0000719static int abis_nm_rcvmsg_report(struct msgb *mb)
720{
721 struct abis_om_fom_hdr *foh = msgb_l3(mb);
722 u_int8_t mt = foh->msg_type;
723
Harald Welte23897662009-05-01 14:52:51 +0000724 DEBUGP(DNM, "OC=%s(%02x) INST=(%02x,%02x,%02x) ",
725 obj_class_name(foh->obj_class), foh->obj_class,
726 foh->obj_inst.bts_nr, foh->obj_inst.trx_nr,
727 foh->obj_inst.ts_nr);
728
Harald Welte97ed1e72009-02-06 13:38:02 +0000729 //nmh->cfg->report_cb(mb, foh);
730
731 switch (mt) {
732 case NM_MT_STATECHG_EVENT_REP:
733 return abis_nm_rx_statechg_rep(mb);
734 break;
Harald Welte34a99682009-02-13 02:41:40 +0000735 case NM_MT_SW_ACTIVATED_REP:
Harald Welte23897662009-05-01 14:52:51 +0000736 DEBUGPC(DNM, "Software Activated Report\n");
Harald Weltef9a8cc32009-05-01 15:39:49 +0000737 dispatch_signal(SS_NM, S_NM_SW_ACTIV_REP, mb);
Harald Welte34a99682009-02-13 02:41:40 +0000738 break;
Harald Weltee0590df2009-02-15 03:34:15 +0000739 case NM_MT_FAILURE_EVENT_REP:
Harald Welte0db97b22009-05-01 17:22:47 +0000740 rx_fail_evt_rep(mb);
Harald Weltef9a8cc32009-05-01 15:39:49 +0000741 dispatch_signal(SS_NM, S_NM_FAIL_REP, mb);
Harald Weltee0590df2009-02-15 03:34:15 +0000742 break;
743 default:
Harald Welte23897662009-05-01 14:52:51 +0000744 DEBUGPC(DNM, "reporting NM MT 0x%02x\n", mt);
Harald Weltee0590df2009-02-15 03:34:15 +0000745 break;
746
Harald Welte97ed1e72009-02-06 13:38:02 +0000747 };
748
Harald Welte97ed1e72009-02-06 13:38:02 +0000749 return 0;
750}
751
Harald Welte34a99682009-02-13 02:41:40 +0000752/* Activate the specified software into the BTS */
753static int ipacc_sw_activate(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1,
754 u_int8_t i2, u_int8_t *sw_desc, u_int8_t swdesc_len)
755{
756 struct abis_om_hdr *oh;
757 struct msgb *msg = nm_msgb_alloc();
758 u_int8_t len = swdesc_len;
759 u_int8_t *trailer;
760
761 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
762 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, obj_class, i0, i1, i2);
763
764 trailer = msgb_put(msg, swdesc_len);
765 memcpy(trailer, sw_desc, swdesc_len);
766
767 return abis_nm_sendmsg(bts, msg);
768}
769
770static int abis_nm_rx_sw_act_req(struct msgb *mb)
771{
772 struct abis_om_hdr *oh = msgb_l2(mb);
773 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Harald Welte5c1e4582009-02-15 11:57:29 +0000774 int nack = 0;
Harald Welte34a99682009-02-13 02:41:40 +0000775 int ret;
776
Harald Welte5c1e4582009-02-15 11:57:29 +0000777 DEBUGP(DNM, "Software Activate Request ");
Harald Welte34a99682009-02-13 02:41:40 +0000778
Harald Welte5c1e4582009-02-15 11:57:29 +0000779 if (foh->obj_class >= 0xf0 && foh->obj_class <= 0xf3) {
780 DEBUGPC(DNM, "NACKing for GPRS obj_class 0x%02x\n", foh->obj_class);
781 nack = 1;
782 } else
783 DEBUGPC(DNM, "ACKing and Activating\n");
784
785 ret = abis_nm_sw_act_req_ack(mb->trx->bts, foh->obj_class,
Harald Welte34a99682009-02-13 02:41:40 +0000786 foh->obj_inst.bts_nr,
787 foh->obj_inst.trx_nr,
Harald Welte5c1e4582009-02-15 11:57:29 +0000788 foh->obj_inst.ts_nr, nack,
Harald Welte34a99682009-02-13 02:41:40 +0000789 foh->data, oh->length-sizeof(*foh));
790
Harald Welte5c1e4582009-02-15 11:57:29 +0000791 if (nack)
792 return ret;
793
Harald Welte34a99682009-02-13 02:41:40 +0000794 /* FIXME: properly parse attributes */
795 return ipacc_sw_activate(mb->trx->bts, foh->obj_class,
796 foh->obj_inst.bts_nr,
797 foh->obj_inst.trx_nr,
798 foh->obj_inst.ts_nr,
799 foh->data + oh->length-sizeof(*foh)-22, 22);
800}
801
Harald Weltee0590df2009-02-15 03:34:15 +0000802/* Receive a CHANGE_ADM_STATE_ACK, parse the TLV and update local state */
803static int abis_nm_rx_chg_adm_state_ack(struct msgb *mb)
804{
805 struct abis_om_hdr *oh = msgb_l2(mb);
806 struct abis_om_fom_hdr *foh = msgb_l3(mb);
807 struct tlv_parsed tp;
808 u_int8_t adm_state;
809
Harald Welte03133942009-02-18 19:51:53 +0000810 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Weltee0590df2009-02-15 03:34:15 +0000811 if (!TLVP_PRESENT(&tp, NM_ATT_ADM_STATE))
812 return -EINVAL;
813
814 adm_state = *TLVP_VAL(&tp, NM_ATT_ADM_STATE);
815
816 return update_admstate(mb->trx->bts, foh->obj_class, &foh->obj_inst, adm_state);
817}
818
Harald Welteee670472009-02-22 21:58:49 +0000819static int abis_nm_rx_lmt_event(struct msgb *mb)
820{
821 struct abis_om_hdr *oh = msgb_l2(mb);
822 struct abis_om_fom_hdr *foh = msgb_l3(mb);
823 struct tlv_parsed tp;
824
825 DEBUGP(DNM, "LMT Event ");
826 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
827 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_LOGON_SESSION) &&
828 TLVP_LEN(&tp, NM_ATT_BS11_LMT_LOGON_SESSION) >= 1) {
829 u_int8_t onoff = *TLVP_VAL(&tp, NM_ATT_BS11_LMT_LOGON_SESSION);
830 DEBUGPC(DNM, "LOG%s ", onoff ? "ON" : "OFF");
831 }
832 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV) &&
833 TLVP_LEN(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV) >= 1) {
834 u_int8_t level = *TLVP_VAL(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV);
835 DEBUGPC(DNM, "Level=%u ", level);
836 }
837 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_USER_NAME) &&
838 TLVP_LEN(&tp, NM_ATT_BS11_LMT_USER_NAME) >= 1) {
839 char *name = (char *) TLVP_VAL(&tp, NM_ATT_BS11_LMT_USER_NAME);
840 DEBUGPC(DNM, "Username=%s ", name);
841 }
842 DEBUGPC(DNM, "\n");
843 /* FIXME: parse LMT LOGON TIME */
844 return 0;
845}
846
Harald Welte52b1f982008-12-23 20:25:15 +0000847/* Receive a OML NM Message from BTS */
Harald Welte8470bf22008-12-25 23:28:35 +0000848static int abis_nm_rcvmsg_fom(struct msgb *mb)
Harald Welte52b1f982008-12-23 20:25:15 +0000849{
Harald Welte6c96ba52009-05-01 13:03:40 +0000850 struct abis_om_hdr *oh = msgb_l2(mb);
Harald Welte52b1f982008-12-23 20:25:15 +0000851 struct abis_om_fom_hdr *foh = msgb_l3(mb);
852 u_int8_t mt = foh->msg_type;
853
854 /* check for unsolicited message */
Harald Welte97ed1e72009-02-06 13:38:02 +0000855 if (is_report(mt))
856 return abis_nm_rcvmsg_report(mb);
Harald Welte52b1f982008-12-23 20:25:15 +0000857
Harald Welte4724f992009-01-18 18:01:49 +0000858 if (is_in_arr(mt, sw_load_msgs, ARRAY_SIZE(sw_load_msgs)))
859 return abis_nm_rcvmsg_sw(mb);
860
Harald Welte78fc0d42009-02-19 02:50:57 +0000861 if (is_in_arr(mt, nacks, ARRAY_SIZE(nacks))) {
Harald Welte6c96ba52009-05-01 13:03:40 +0000862 struct tlv_parsed tp;
Harald Welte78fc0d42009-02-19 02:50:57 +0000863 if (nack_names[mt])
Harald Welte6c96ba52009-05-01 13:03:40 +0000864 DEBUGP(DNM, "%s NACK ", nack_names[mt]);
865 /* FIXME: NACK cause */
Harald Welte78fc0d42009-02-19 02:50:57 +0000866 else
Harald Welte6c96ba52009-05-01 13:03:40 +0000867 DEBUGP(DNM, "NACK 0x%02x ", mt);
868
869 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
870 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
871 DEBUGPC(DNM, "CAUSE=%s\n",
872 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
873 else
874 DEBUGPC(DNM, "\n");
Harald Welte78fc0d42009-02-19 02:50:57 +0000875 }
Harald Weltead384642008-12-26 10:20:07 +0000876#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000877 /* check if last message is to be acked */
878 if (is_ack_nack(nmh->last_msgtype)) {
879 if (mt == MT_ACK(nmh->last_msgtype)) {
880 fprintf(stderr, "received ACK (0x%x)\n",
881 foh->msg_type);
882 /* we got our ACK, continue sending the next msg */
883 } else if (mt == MT_NACK(nmh->last_msgtype)) {
884 /* we got a NACK, signal this to the caller */
885 fprintf(stderr, "received NACK (0x%x)\n",
886 foh->msg_type);
887 /* FIXME: somehow signal this to the caller */
888 } else {
889 /* really strange things happen */
890 return -EINVAL;
891 }
892 }
Harald Weltead384642008-12-26 10:20:07 +0000893#endif
894
Harald Welte97ed1e72009-02-06 13:38:02 +0000895 switch (mt) {
Harald Weltee0590df2009-02-15 03:34:15 +0000896 case NM_MT_CHG_ADM_STATE_ACK:
897 return abis_nm_rx_chg_adm_state_ack(mb);
898 break;
Harald Welte34a99682009-02-13 02:41:40 +0000899 case NM_MT_SW_ACT_REQ:
900 return abis_nm_rx_sw_act_req(mb);
901 break;
Harald Welte97ed1e72009-02-06 13:38:02 +0000902 case NM_MT_BS11_LMT_SESSION:
Harald Welteee670472009-02-22 21:58:49 +0000903 return abis_nm_rx_lmt_event(mb);
Harald Welte97ed1e72009-02-06 13:38:02 +0000904 break;
905 }
906
Harald Weltead384642008-12-26 10:20:07 +0000907 return 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000908}
909
Harald Welte677c21f2009-02-17 13:22:23 +0000910static int abis_nm_rx_ipacc(struct msgb *mb);
911
912static int abis_nm_rcvmsg_manuf(struct msgb *mb)
913{
914 int rc;
915 int bts_type = mb->trx->bts->type;
916
917 switch (bts_type) {
918 case GSM_BTS_TYPE_NANOBTS_900:
919 case GSM_BTS_TYPE_NANOBTS_1800:
920 rc = abis_nm_rx_ipacc(mb);
921 break;
922 default:
923 fprintf(stderr, "don't know how to parse OML for this "
924 "BTS type (%u)\n", bts_type);
925 rc = 0;
926 break;
927 }
928
929 return rc;
930}
931
Harald Welte52b1f982008-12-23 20:25:15 +0000932/* High-Level API */
933/* Entry-point where L2 OML from BTS enters the NM code */
Harald Welte8470bf22008-12-25 23:28:35 +0000934int abis_nm_rcvmsg(struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +0000935{
Harald Welte52b1f982008-12-23 20:25:15 +0000936 struct abis_om_hdr *oh = msgb_l2(msg);
Harald Welte677c21f2009-02-17 13:22:23 +0000937 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000938
939 /* Various consistency checks */
940 if (oh->placement != ABIS_OM_PLACEMENT_ONLY) {
941 fprintf(stderr, "ABIS OML placement 0x%x not supported\n",
942 oh->placement);
943 return -EINVAL;
944 }
945 if (oh->sequence != 0) {
946 fprintf(stderr, "ABIS OML sequence 0x%x != 0x00\n",
947 oh->sequence);
948 return -EINVAL;
949 }
Harald Welte702d8702008-12-26 20:25:35 +0000950#if 0
Holger Freytherca362a62009-01-04 21:05:01 +0000951 unsigned int l2_len = msg->tail - (u_int8_t *)msgb_l2(msg);
952 unsigned int hlen = sizeof(*oh) + sizeof(struct abis_om_fom_hdr);
Harald Welte702d8702008-12-26 20:25:35 +0000953 if (oh->length + hlen > l2_len) {
Harald Welte52b1f982008-12-23 20:25:15 +0000954 fprintf(stderr, "ABIS OML truncated message (%u > %u)\n",
955 oh->length + sizeof(*oh), l2_len);
956 return -EINVAL;
957 }
Harald Welte702d8702008-12-26 20:25:35 +0000958 if (oh->length + hlen < l2_len)
959 fprintf(stderr, "ABIS OML message with extra trailer?!? (oh->len=%d, sizeof_oh=%d l2_len=%d\n", oh->length, sizeof(*oh), l2_len);
960#endif
Harald Weltead384642008-12-26 10:20:07 +0000961 msg->l3h = (unsigned char *)oh + sizeof(*oh);
Harald Welte52b1f982008-12-23 20:25:15 +0000962
963 switch (oh->mdisc) {
964 case ABIS_OM_MDISC_FOM:
Harald Welte8470bf22008-12-25 23:28:35 +0000965 rc = abis_nm_rcvmsg_fom(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000966 break;
Harald Welte677c21f2009-02-17 13:22:23 +0000967 case ABIS_OM_MDISC_MANUF:
968 rc = abis_nm_rcvmsg_manuf(msg);
969 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000970 case ABIS_OM_MDISC_MMI:
971 case ABIS_OM_MDISC_TRAU:
Harald Welte677c21f2009-02-17 13:22:23 +0000972 fprintf(stderr, "unimplemented ABIS OML message discriminator 0x%x\n",
973 oh->mdisc);
974 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000975 default:
976 fprintf(stderr, "unknown ABIS OML message discriminator 0x%x\n",
977 oh->mdisc);
978 return -EINVAL;
979 }
980
Harald Weltead384642008-12-26 10:20:07 +0000981 msgb_free(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000982 return rc;
983}
984
985#if 0
986/* initialized all resources */
987struct abis_nm_h *abis_nm_init(struct abis_nm_cfg *cfg)
988{
989 struct abis_nm_h *nmh;
990
991 nmh = malloc(sizeof(*nmh));
992 if (!nmh)
993 return NULL;
994
995 nmh->cfg = cfg;
996
997 return nmh;
998}
999
1000/* free all resources */
1001void abis_nm_fini(struct abis_nm_h *nmh)
1002{
1003 free(nmh);
1004}
1005#endif
1006
1007/* Here we are trying to define a high-level API that can be used by
1008 * the actual BSC implementation. However, the architecture is currently
1009 * still under design. Ideally the calls to this API would be synchronous,
1010 * while the underlying stack behind the APi runs in a traditional select
1011 * based state machine.
1012 */
1013
Harald Welte4724f992009-01-18 18:01:49 +00001014/* 6.2 Software Load: */
1015enum sw_state {
1016 SW_STATE_NONE,
1017 SW_STATE_WAIT_INITACK,
1018 SW_STATE_WAIT_SEGACK,
1019 SW_STATE_WAIT_ENDACK,
1020 SW_STATE_WAIT_ACTACK,
1021 SW_STATE_ERROR,
1022};
Harald Welte52b1f982008-12-23 20:25:15 +00001023
Harald Welte52b1f982008-12-23 20:25:15 +00001024struct abis_nm_sw {
Harald Welte4724f992009-01-18 18:01:49 +00001025 struct gsm_bts *bts;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001026 gsm_cbfn *cbfn;
1027 void *cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +00001028 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001029
Harald Welte52b1f982008-12-23 20:25:15 +00001030 /* this will become part of the SW LOAD INITIATE */
1031 u_int8_t obj_class;
1032 u_int8_t obj_instance[3];
Harald Welte4724f992009-01-18 18:01:49 +00001033
1034 u_int8_t file_id[255];
1035 u_int8_t file_id_len;
1036
1037 u_int8_t file_version[255];
1038 u_int8_t file_version_len;
1039
1040 u_int8_t window_size;
1041 u_int8_t seg_in_window;
1042
1043 int fd;
1044 FILE *stream;
1045 enum sw_state state;
Harald Welte1602ade2009-01-29 21:12:39 +00001046 int last_seg;
Harald Welte52b1f982008-12-23 20:25:15 +00001047};
1048
Harald Welte4724f992009-01-18 18:01:49 +00001049static struct abis_nm_sw g_sw;
1050
1051/* 6.2.1 / 8.3.1: Load Data Initiate */
1052static int sw_load_init(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +00001053{
Harald Welte4724f992009-01-18 18:01:49 +00001054 struct abis_om_hdr *oh;
1055 struct msgb *msg = nm_msgb_alloc();
1056 u_int8_t len = 3*2 + sw->file_id_len + sw->file_version_len;
1057
1058 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1059 fill_om_fom_hdr(oh, len, NM_MT_LOAD_INIT, sw->obj_class,
1060 sw->obj_instance[0], sw->obj_instance[1],
1061 sw->obj_instance[2]);
1062
1063 /* FIXME: this is BS11 specific format */
1064 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1065 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1066 sw->file_version);
1067 msgb_tv_put(msg, NM_ATT_WINDOW_SIZE, sw->window_size);
1068
1069 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001070}
1071
Harald Welte1602ade2009-01-29 21:12:39 +00001072static int is_last_line(FILE *stream)
1073{
1074 char next_seg_buf[256];
1075 long pos;
1076
1077 /* check if we're sending the last line */
1078 pos = ftell(stream);
1079 if (!fgets(next_seg_buf, sizeof(next_seg_buf)-2, stream)) {
1080 fseek(stream, pos, SEEK_SET);
1081 return 1;
1082 }
1083
1084 fseek(stream, pos, SEEK_SET);
1085 return 0;
1086}
1087
Harald Welte4724f992009-01-18 18:01:49 +00001088/* 6.2.2 / 8.3.2 Load Data Segment */
1089static int sw_load_segment(struct abis_nm_sw *sw)
1090{
1091 struct abis_om_hdr *oh;
1092 struct msgb *msg = nm_msgb_alloc();
1093 char seg_buf[256];
1094 char *line_buf = seg_buf+2;
Harald Welte3b8ba212009-01-29 12:27:58 +00001095 unsigned char *tlv;
Harald Welte4724f992009-01-18 18:01:49 +00001096 u_int8_t len;
Harald Welte4724f992009-01-18 18:01:49 +00001097
1098 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte3b8ba212009-01-29 12:27:58 +00001099
1100 switch (sw->bts->type) {
1101 case GSM_BTS_TYPE_BS11:
1102 if (fgets(line_buf, sizeof(seg_buf)-2, sw->stream) == NULL) {
1103 perror("fgets reading segment");
1104 return -EINVAL;
1105 }
1106 seg_buf[0] = 0x00;
Harald Welte1602ade2009-01-29 21:12:39 +00001107
1108 /* check if we're sending the last line */
1109 sw->last_seg = is_last_line(sw->stream);
1110 if (sw->last_seg)
1111 seg_buf[1] = 0;
1112 else
1113 seg_buf[1] = 1 + sw->seg_in_window++;
Harald Welte3b8ba212009-01-29 12:27:58 +00001114
1115 len = strlen(line_buf) + 2;
1116 tlv = msgb_put(msg, TLV_GROSS_LEN(len));
1117 tlv_put(tlv, NM_ATT_BS11_FILE_DATA, len, (u_int8_t *)seg_buf);
1118 /* BS11 wants CR + LF in excess of the TLV length !?! */
1119 tlv[1] -= 2;
1120
1121 /* we only now know the exact length for the OM hdr */
1122 len = strlen(line_buf)+2;
1123 break;
1124 default:
1125 /* FIXME: Other BTS types */
1126 return -1;
Harald Welte4724f992009-01-18 18:01:49 +00001127 }
Harald Welte4724f992009-01-18 18:01:49 +00001128
Harald Welte4724f992009-01-18 18:01:49 +00001129 fill_om_fom_hdr(oh, len, NM_MT_LOAD_SEG, sw->obj_class,
1130 sw->obj_instance[0], sw->obj_instance[1],
1131 sw->obj_instance[2]);
1132
1133 return abis_nm_sendmsg(sw->bts, msg);
1134}
1135
1136/* 6.2.4 / 8.3.4 Load Data End */
1137static int sw_load_end(struct abis_nm_sw *sw)
1138{
1139 struct abis_om_hdr *oh;
1140 struct msgb *msg = nm_msgb_alloc();
1141 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
1142
1143 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1144 fill_om_fom_hdr(oh, len, NM_MT_LOAD_END, sw->obj_class,
1145 sw->obj_instance[0], sw->obj_instance[1],
1146 sw->obj_instance[2]);
1147
1148 /* FIXME: this is BS11 specific format */
1149 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1150 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1151 sw->file_version);
1152
1153 return abis_nm_sendmsg(sw->bts, msg);
1154}
Harald Welte5e4d1b32009-02-01 13:36:56 +00001155
Harald Welte52b1f982008-12-23 20:25:15 +00001156/* Activate the specified software into the BTS */
Harald Welte4724f992009-01-18 18:01:49 +00001157static int sw_activate(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +00001158{
Harald Welte4724f992009-01-18 18:01:49 +00001159 struct abis_om_hdr *oh;
1160 struct msgb *msg = nm_msgb_alloc();
1161 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
Harald Welte52b1f982008-12-23 20:25:15 +00001162
Harald Welte4724f992009-01-18 18:01:49 +00001163 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1164 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, sw->obj_class,
1165 sw->obj_instance[0], sw->obj_instance[1],
1166 sw->obj_instance[2]);
1167
1168 /* FIXME: this is BS11 specific format */
1169 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1170 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1171 sw->file_version);
1172
1173 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001174}
Harald Welte4724f992009-01-18 18:01:49 +00001175
1176static int sw_open_file(struct abis_nm_sw *sw, const char *fname)
1177{
1178 char file_id[12+1];
1179 char file_version[80+1];
1180 int rc;
1181
1182 sw->fd = open(fname, O_RDONLY);
1183 if (sw->fd < 0)
1184 return sw->fd;
1185
1186 switch (sw->bts->type) {
1187 case GSM_BTS_TYPE_BS11:
1188 sw->stream = fdopen(sw->fd, "r");
1189 if (!sw->stream) {
1190 perror("fdopen");
1191 return -1;
1192 }
1193 /* read first line and parse file ID and VERSION */
Harald Welte3b8ba212009-01-29 12:27:58 +00001194 rc = fscanf(sw->stream, "@(#)%12s:%80s\r\n",
Harald Welte4724f992009-01-18 18:01:49 +00001195 file_id, file_version);
1196 if (rc != 2) {
1197 perror("parsing header line of software file");
1198 return -1;
1199 }
1200 strcpy((char *)sw->file_id, file_id);
1201 sw->file_id_len = strlen(file_id);
1202 strcpy((char *)sw->file_version, file_version);
1203 sw->file_version_len = strlen(file_version);
1204 /* rewind to start of file */
Harald Welte3b8ba212009-01-29 12:27:58 +00001205 rewind(sw->stream);
Harald Welte4724f992009-01-18 18:01:49 +00001206 break;
1207 default:
1208 /* We don't know how to treat them yet */
1209 close(sw->fd);
1210 return -EINVAL;
1211 }
1212
1213 return 0;
1214}
1215
1216static void sw_close_file(struct abis_nm_sw *sw)
1217{
1218 switch (sw->bts->type) {
1219 case GSM_BTS_TYPE_BS11:
1220 fclose(sw->stream);
1221 break;
1222 default:
1223 close(sw->fd);
1224 break;
1225 }
1226}
1227
1228/* Fill the window */
1229static int sw_fill_window(struct abis_nm_sw *sw)
1230{
1231 int rc;
1232
1233 while (sw->seg_in_window < sw->window_size) {
1234 rc = sw_load_segment(sw);
1235 if (rc < 0)
1236 return rc;
Harald Welte1602ade2009-01-29 21:12:39 +00001237 if (sw->last_seg)
1238 break;
Harald Welte4724f992009-01-18 18:01:49 +00001239 }
1240 return 0;
1241}
1242
1243/* callback function from abis_nm_rcvmsg() handler */
1244static int abis_nm_rcvmsg_sw(struct msgb *mb)
1245{
1246 struct abis_om_fom_hdr *foh = msgb_l3(mb);
1247 int rc = -1;
1248 struct abis_nm_sw *sw = &g_sw;
1249 enum sw_state old_state = sw->state;
1250
Harald Welte3ffd1372009-02-01 22:15:49 +00001251 //DEBUGP(DNM, "state %u, NM MT 0x%02x\n", sw->state, foh->msg_type);
Harald Welte4724f992009-01-18 18:01:49 +00001252
1253 switch (sw->state) {
1254 case SW_STATE_WAIT_INITACK:
1255 switch (foh->msg_type) {
1256 case NM_MT_LOAD_INIT_ACK:
1257 /* fill window with segments */
Harald Welte5e4d1b32009-02-01 13:36:56 +00001258 if (sw->cbfn)
1259 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1260 NM_MT_LOAD_INIT_ACK, mb,
1261 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001262 rc = sw_fill_window(sw);
1263 sw->state = SW_STATE_WAIT_SEGACK;
1264 break;
1265 case NM_MT_LOAD_INIT_NACK:
Harald Welte3ffd1372009-02-01 22:15:49 +00001266 if (sw->forced) {
1267 DEBUGP(DNM, "FORCED: Ignoring Software Load "
1268 "Init NACK\n");
1269 if (sw->cbfn)
1270 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1271 NM_MT_LOAD_INIT_ACK, mb,
1272 sw->cb_data, NULL);
1273 rc = sw_fill_window(sw);
1274 sw->state = SW_STATE_WAIT_SEGACK;
1275 } else {
1276 DEBUGP(DNM, "Software Load Init NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001277 /* FIXME: cause */
Harald Welte3ffd1372009-02-01 22:15:49 +00001278 if (sw->cbfn)
1279 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1280 NM_MT_LOAD_INIT_NACK, mb,
1281 sw->cb_data, NULL);
1282 sw->state = SW_STATE_ERROR;
1283 }
Harald Welte4724f992009-01-18 18:01:49 +00001284 break;
1285 }
1286 break;
1287 case SW_STATE_WAIT_SEGACK:
1288 switch (foh->msg_type) {
1289 case NM_MT_LOAD_SEG_ACK:
Harald Welte3ffd1372009-02-01 22:15:49 +00001290 if (sw->cbfn)
1291 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1292 NM_MT_LOAD_SEG_ACK, mb,
1293 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001294 sw->seg_in_window = 0;
Harald Welte1602ade2009-01-29 21:12:39 +00001295 if (!sw->last_seg) {
1296 /* fill window with more segments */
1297 rc = sw_fill_window(sw);
1298 sw->state = SW_STATE_WAIT_SEGACK;
1299 } else {
1300 /* end the transfer */
1301 sw->state = SW_STATE_WAIT_ENDACK;
1302 rc = sw_load_end(sw);
1303 }
Harald Welte4724f992009-01-18 18:01:49 +00001304 break;
1305 }
1306 break;
1307 case SW_STATE_WAIT_ENDACK:
1308 switch (foh->msg_type) {
1309 case NM_MT_LOAD_END_ACK:
1310 sw_close_file(sw);
Harald Welte5e4d1b32009-02-01 13:36:56 +00001311 DEBUGP(DNM, "Software Load End (BTS %u)\n",
1312 sw->bts->nr);
1313 sw->state = SW_STATE_NONE;
1314 if (sw->cbfn)
1315 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1316 NM_MT_LOAD_END_ACK, mb,
1317 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001318 break;
1319 case NM_MT_LOAD_END_NACK:
Holger Freyther31338a12009-02-06 17:43:50 +00001320 if (sw->forced) {
1321 DEBUGP(DNM, "FORCED: Ignoring Software Load"
1322 "End NACK\n");
1323 sw->state = SW_STATE_NONE;
1324 if (sw->cbfn)
1325 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1326 NM_MT_LOAD_END_ACK, mb,
1327 sw->cb_data, NULL);
1328 } else {
1329 DEBUGP(DNM, "Software Load End NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001330 /* FIXME: cause */
Holger Freyther31338a12009-02-06 17:43:50 +00001331 sw->state = SW_STATE_ERROR;
1332 if (sw->cbfn)
1333 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1334 NM_MT_LOAD_END_NACK, mb,
1335 sw->cb_data, NULL);
1336 }
Harald Welte4724f992009-01-18 18:01:49 +00001337 break;
1338 }
1339 case SW_STATE_WAIT_ACTACK:
1340 switch (foh->msg_type) {
1341 case NM_MT_ACTIVATE_SW_ACK:
1342 /* we're done */
Harald Welte5e4d1b32009-02-01 13:36:56 +00001343 DEBUGP(DNM, "Activate Software DONE!\n");
Harald Welte4724f992009-01-18 18:01:49 +00001344 sw->state = SW_STATE_NONE;
1345 rc = 0;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001346 if (sw->cbfn)
1347 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1348 NM_MT_ACTIVATE_SW_ACK, mb,
1349 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001350 break;
1351 case NM_MT_ACTIVATE_SW_NACK:
Harald Welte1602ade2009-01-29 21:12:39 +00001352 DEBUGP(DNM, "Activate Software NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001353 /* FIXME: cause */
Harald Welte4724f992009-01-18 18:01:49 +00001354 sw->state = SW_STATE_ERROR;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001355 if (sw->cbfn)
1356 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1357 NM_MT_ACTIVATE_SW_NACK, mb,
1358 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001359 break;
1360 }
1361 case SW_STATE_NONE:
Harald Weltea994a482009-05-01 15:54:23 +00001362 switch (foh->msg_type) {
1363 case NM_MT_ACTIVATE_SW_ACK:
1364 rc = 0;
1365 break;
1366 }
1367 break;
Harald Welte4724f992009-01-18 18:01:49 +00001368 case SW_STATE_ERROR:
1369 break;
1370 }
1371
1372 if (rc)
Harald Weltea994a482009-05-01 15:54:23 +00001373 DEBUGP(DNM, "unexpected NM MT 0x%02x in state %u -> %u\n",
Harald Welte4724f992009-01-18 18:01:49 +00001374 foh->msg_type, old_state, sw->state);
1375
1376 return rc;
1377}
1378
1379/* Load the specified software into the BTS */
1380int abis_nm_software_load(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00001381 u_int8_t win_size, int forced,
1382 gsm_cbfn *cbfn, void *cb_data)
Harald Welte4724f992009-01-18 18:01:49 +00001383{
1384 struct abis_nm_sw *sw = &g_sw;
1385 int rc;
1386
Harald Welte5e4d1b32009-02-01 13:36:56 +00001387 DEBUGP(DNM, "Software Load (BTS %u, File \"%s\")\n",
1388 bts->nr, fname);
1389
Harald Welte4724f992009-01-18 18:01:49 +00001390 if (sw->state != SW_STATE_NONE)
1391 return -EBUSY;
1392
1393 sw->bts = bts;
1394 sw->obj_class = NM_OC_SITE_MANAGER;
1395 sw->obj_instance[0] = 0xff;
1396 sw->obj_instance[1] = 0xff;
1397 sw->obj_instance[2] = 0xff;
1398 sw->window_size = win_size;
1399 sw->state = SW_STATE_WAIT_INITACK;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001400 sw->cbfn = cbfn;
1401 sw->cb_data = cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +00001402 sw->forced = forced;
Harald Welte4724f992009-01-18 18:01:49 +00001403
1404 rc = sw_open_file(sw, fname);
1405 if (rc < 0) {
1406 sw->state = SW_STATE_NONE;
1407 return rc;
1408 }
1409
1410 return sw_load_init(sw);
1411}
Harald Welte52b1f982008-12-23 20:25:15 +00001412
Harald Welte1602ade2009-01-29 21:12:39 +00001413int abis_nm_software_load_status(struct gsm_bts *bts)
1414{
1415 struct abis_nm_sw *sw = &g_sw;
1416 struct stat st;
1417 int rc, percent;
1418
1419 rc = fstat(sw->fd, &st);
1420 if (rc < 0) {
1421 perror("ERROR during stat");
1422 return rc;
1423 }
1424
1425 percent = (ftell(sw->stream) * 100) / st.st_size;
1426 return percent;
1427}
1428
Harald Welte5e4d1b32009-02-01 13:36:56 +00001429/* Activate the specified software into the BTS */
1430int abis_nm_software_activate(struct gsm_bts *bts, const char *fname,
1431 gsm_cbfn *cbfn, void *cb_data)
1432{
1433 struct abis_nm_sw *sw = &g_sw;
1434 int rc;
1435
1436 DEBUGP(DNM, "Activating Software (BTS %u, File \"%s\")\n",
1437 bts->nr, fname);
1438
1439 if (sw->state != SW_STATE_NONE)
1440 return -EBUSY;
1441
1442 sw->bts = bts;
1443 sw->obj_class = NM_OC_SITE_MANAGER;
1444 sw->obj_instance[0] = 0xff;
1445 sw->obj_instance[1] = 0xff;
1446 sw->obj_instance[2] = 0xff;
1447 sw->state = SW_STATE_WAIT_ACTACK;
1448 sw->cbfn = cbfn;
1449 sw->cb_data = cb_data;
1450
1451 /* Open the file in order to fill some sw struct members */
1452 rc = sw_open_file(sw, fname);
1453 if (rc < 0) {
1454 sw->state = SW_STATE_NONE;
1455 return rc;
1456 }
1457 sw_close_file(sw);
1458
1459 return sw_activate(sw);
1460}
1461
Harald Welte8470bf22008-12-25 23:28:35 +00001462static void fill_nm_channel(struct abis_nm_channel *ch, u_int8_t bts_port,
Harald Welte52b1f982008-12-23 20:25:15 +00001463 u_int8_t ts_nr, u_int8_t subslot_nr)
1464{
Harald Welteadaf08b2009-01-18 11:08:10 +00001465 ch->attrib = NM_ATT_ABIS_CHANNEL;
Harald Welte52b1f982008-12-23 20:25:15 +00001466 ch->bts_port = bts_port;
1467 ch->timeslot = ts_nr;
1468 ch->subslot = subslot_nr;
1469}
1470
1471int abis_nm_establish_tei(struct gsm_bts *bts, u_int8_t trx_nr,
1472 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot,
1473 u_int8_t tei)
1474{
1475 struct abis_om_hdr *oh;
1476 struct abis_nm_channel *ch;
Harald Welte702d8702008-12-26 20:25:35 +00001477 u_int8_t len = sizeof(*ch) + 2;
Harald Welte8470bf22008-12-25 23:28:35 +00001478 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001479
1480 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1481 fill_om_fom_hdr(oh, len, NM_MT_ESTABLISH_TEI, NM_OC_RADIO_CARRIER,
1482 bts->bts_nr, trx_nr, 0xff);
1483
Harald Welte8470bf22008-12-25 23:28:35 +00001484 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte52b1f982008-12-23 20:25:15 +00001485
1486 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1487 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1488
1489 return abis_nm_sendmsg(bts, msg);
1490}
1491
1492/* connect signalling of one (BTS,TRX) to a particular timeslot on the E1 */
1493int abis_nm_conn_terr_sign(struct gsm_bts_trx *trx,
1494 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot)
1495{
Harald Welte8470bf22008-12-25 23:28:35 +00001496 struct gsm_bts *bts = trx->bts;
Harald Welte52b1f982008-12-23 20:25:15 +00001497 struct abis_om_hdr *oh;
1498 struct abis_nm_channel *ch;
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);
Harald Welte6f676a32009-01-18 14:27:48 +00001502 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_SIGN,
Harald Welte52b1f982008-12-23 20:25:15 +00001503 NM_OC_RADIO_CARRIER, bts->bts_nr, trx->nr, 0xff);
1504
1505 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1506 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1507
1508 return abis_nm_sendmsg(bts, msg);
1509}
1510
1511#if 0
1512int abis_nm_disc_terr_sign(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1513 struct abis_nm_abis_channel *chan)
1514{
1515}
1516#endif
1517
1518int abis_nm_conn_terr_traf(struct gsm_bts_trx_ts *ts,
1519 u_int8_t e1_port, u_int8_t e1_timeslot,
1520 u_int8_t e1_subslot)
1521{
1522 struct gsm_bts *bts = ts->trx->bts;
1523 struct abis_om_hdr *oh;
1524 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +00001525 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001526
1527 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1528 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_TRAF,
Harald Welteb110cee2009-02-18 03:42:35 +00001529 NM_OC_CHANNEL, bts->bts_nr, ts->trx->nr, ts->nr);
Harald Welte52b1f982008-12-23 20:25:15 +00001530
1531 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1532 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1533
Harald Weltef325eb42009-02-19 17:07:39 +00001534 DEBUGP(DNM, "CONNECT TERR TRAF Um=%s E1=(%u,%u,%u)\n",
1535 gsm_ts_name(ts),
Harald Welteb110cee2009-02-18 03:42:35 +00001536 e1_port, e1_timeslot, e1_subslot);
1537
Harald Welte52b1f982008-12-23 20:25:15 +00001538 return abis_nm_sendmsg(bts, msg);
1539}
1540
1541#if 0
1542int abis_nm_disc_terr_traf(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1543 struct abis_nm_abis_channel *chan,
1544 u_int8_t subchan)
1545{
1546}
1547#endif
1548
Harald Welte22af0db2009-02-14 15:41:08 +00001549/* Chapter 8.6.1 */
1550int abis_nm_set_bts_attr(struct gsm_bts *bts, u_int8_t *attr, int attr_len)
1551{
1552 struct abis_om_hdr *oh;
1553 struct msgb *msg = nm_msgb_alloc();
1554 u_int8_t *cur;
1555
1556 DEBUGP(DNM, "Set BTS Attr (bts=%d)\n", bts->nr);
1557
1558 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte191280d2009-05-01 13:20:04 +00001559 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 +00001560 cur = msgb_put(msg, attr_len);
1561 memcpy(cur, attr, attr_len);
1562
1563 return abis_nm_sendmsg(bts, msg);
1564}
1565
1566/* Chapter 8.6.2 */
1567int abis_nm_set_radio_attr(struct gsm_bts_trx *trx, u_int8_t *attr, int attr_len)
1568{
1569 struct abis_om_hdr *oh;
1570 struct msgb *msg = nm_msgb_alloc();
1571 u_int8_t *cur;
1572
1573 DEBUGP(DNM, "Set TRX Attr (bts=%d,trx=%d)\n", trx->bts->nr, trx->nr);
1574
1575 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1576 fill_om_fom_hdr(oh, attr_len, NM_MT_SET_RADIO_ATTR, NM_OC_RADIO_CARRIER,
Harald Welte191280d2009-05-01 13:20:04 +00001577 trx->bts->bts_nr, trx->nr, 0xff);
Harald Welte22af0db2009-02-14 15:41:08 +00001578 cur = msgb_put(msg, attr_len);
1579 memcpy(cur, attr, attr_len);
1580
1581 return abis_nm_sendmsg(trx->bts, msg);
1582}
1583
1584/* Chapter 8.6.3 */
Harald Welte52b1f982008-12-23 20:25:15 +00001585int abis_nm_set_channel_attr(struct gsm_bts_trx_ts *ts, u_int8_t chan_comb)
1586{
1587 struct gsm_bts *bts = ts->trx->bts;
1588 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001589 u_int16_t arfcn = htons(ts->trx->arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001590 u_int8_t zero = 0x00;
Harald Welte8470bf22008-12-25 23:28:35 +00001591 struct msgb *msg = nm_msgb_alloc();
Harald Weltee0590df2009-02-15 03:34:15 +00001592 u_int8_t len = 2 + 2;
1593
1594 if (bts->type == GSM_BTS_TYPE_BS11)
1595 len += 4 + 2 + 2 + 3;
Harald Welte52b1f982008-12-23 20:25:15 +00001596
Harald Weltef325eb42009-02-19 17:07:39 +00001597 DEBUGP(DNM, "Set Chan Attr %s\n", gsm_ts_name(ts));
Harald Welte22af0db2009-02-14 15:41:08 +00001598
Harald Welte52b1f982008-12-23 20:25:15 +00001599 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001600 fill_om_fom_hdr(oh, len, NM_MT_SET_CHAN_ATTR,
Holger Freyther6b2d2622009-02-14 23:16:59 +00001601 NM_OC_CHANNEL, bts->bts_nr,
Harald Welte52b1f982008-12-23 20:25:15 +00001602 ts->trx->nr, ts->nr);
1603 /* FIXME: don't send ARFCN list, hopping sequence, mAIO, ...*/
Harald Weltee0590df2009-02-15 03:34:15 +00001604 if (bts->type == GSM_BTS_TYPE_BS11)
1605 msgb_tlv16_put(msg, NM_ATT_ARFCN_LIST, 1, &arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001606 msgb_tv_put(msg, NM_ATT_CHAN_COMB, chan_comb);
Harald Weltee0590df2009-02-15 03:34:15 +00001607 if (bts->type == GSM_BTS_TYPE_BS11) {
1608 msgb_tv_put(msg, NM_ATT_HSN, 0x00);
1609 msgb_tv_put(msg, NM_ATT_MAIO, 0x00);
1610 }
Harald Welte52b1f982008-12-23 20:25:15 +00001611 msgb_tv_put(msg, NM_ATT_TSC, 0x07); /* training sequence */
Harald Weltee0590df2009-02-15 03:34:15 +00001612 if (bts->type == GSM_BTS_TYPE_BS11)
1613 msgb_tlv_put(msg, 0x59, 1, &zero);
Harald Welte52b1f982008-12-23 20:25:15 +00001614
1615 return abis_nm_sendmsg(bts, msg);
1616}
1617
Harald Welte34a99682009-02-13 02:41:40 +00001618int 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 +00001619 u_int8_t i2, u_int8_t i3, int nack, u_int8_t *attr, int att_len)
Harald Welte34a99682009-02-13 02:41:40 +00001620{
1621 struct abis_om_hdr *oh;
1622 struct msgb *msg = nm_msgb_alloc();
Harald Welte5c1e4582009-02-15 11:57:29 +00001623 u_int8_t msgtype = NM_MT_SW_ACT_REQ_ACK;
1624 u_int8_t len = att_len;
1625
1626 if (nack) {
1627 len += 2;
1628 msgtype = NM_MT_SW_ACT_REQ_NACK;
1629 }
Harald Welte34a99682009-02-13 02:41:40 +00001630
1631 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte5c1e4582009-02-15 11:57:29 +00001632 fill_om_fom_hdr(oh, att_len, msgtype, obj_class, i1, i2, i3);
1633
Harald Welte34a99682009-02-13 02:41:40 +00001634 if (attr) {
1635 u_int8_t *ptr = msgb_put(msg, att_len);
1636 memcpy(ptr, attr, att_len);
1637 }
Harald Welte5c1e4582009-02-15 11:57:29 +00001638 if (nack)
1639 msgb_tv_put(msg, NM_ATT_NACK_CAUSES, NM_NACK_OBJCLASS_NOTSUPP);
Harald Welte34a99682009-02-13 02:41:40 +00001640
1641 return abis_nm_sendmsg(bts, msg);
1642}
1643
Harald Welte8470bf22008-12-25 23:28:35 +00001644int abis_nm_raw_msg(struct gsm_bts *bts, int len, u_int8_t *rawmsg)
Harald Welte52b1f982008-12-23 20:25:15 +00001645{
Harald Welte8470bf22008-12-25 23:28:35 +00001646 struct msgb *msg = nm_msgb_alloc();
1647 struct abis_om_hdr *oh;
Harald Welte52b1f982008-12-23 20:25:15 +00001648 u_int8_t *data;
1649
1650 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
1651 fill_om_hdr(oh, len);
1652 data = msgb_put(msg, len);
Harald Weltead384642008-12-26 10:20:07 +00001653 memcpy(data, rawmsg, len);
Harald Welte52b1f982008-12-23 20:25:15 +00001654
1655 return abis_nm_sendmsg(bts, msg);
1656}
1657
1658/* Siemens specific commands */
1659static int __simple_cmd(struct gsm_bts *bts, u_int8_t msg_type)
1660{
1661 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001662 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001663
1664 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001665 fill_om_fom_hdr(oh, 0, msg_type, NM_OC_SITE_MANAGER,
Harald Welte52b1f982008-12-23 20:25:15 +00001666 0xff, 0xff, 0xff);
1667
1668 return abis_nm_sendmsg(bts, msg);
1669}
1670
Harald Welte34a99682009-02-13 02:41:40 +00001671/* Chapter 8.9.2 */
1672int abis_nm_opstart(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1, u_int8_t i2)
1673{
1674 struct abis_om_hdr *oh;
1675 struct msgb *msg = nm_msgb_alloc();
1676
Harald Welte22af0db2009-02-14 15:41:08 +00001677 DEBUGP(DNM, "Sending OPSTART obj_class=0x%02x obj_inst=(0x%02x, 0x%02x, 0x%02x)\n",
1678 obj_class, i0, i1, i2);
Harald Welte34a99682009-02-13 02:41:40 +00001679 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1680 fill_om_fom_hdr(oh, 0, NM_MT_OPSTART, obj_class, i0, i1, i2);
1681
1682 return abis_nm_sendmsg(bts, msg);
1683}
1684
1685/* Chapter 8.8.5 */
1686int abis_nm_chg_adm_state(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0,
1687 u_int8_t i1, u_int8_t i2, u_int8_t adm_state)
1688{
1689 struct abis_om_hdr *oh;
1690 struct msgb *msg = nm_msgb_alloc();
1691
1692 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1693 fill_om_fom_hdr(oh, 2, NM_MT_CHG_ADM_STATE, obj_class, i0, i1, i2);
1694 msgb_tv_put(msg, NM_ATT_ADM_STATE, adm_state);
1695
1696 return abis_nm_sendmsg(bts, msg);
1697}
1698
1699
Harald Welte52b1f982008-12-23 20:25:15 +00001700int abis_nm_event_reports(struct gsm_bts *bts, int on)
1701{
1702 if (on == 0)
Harald Welte227d4072009-01-03 08:16:25 +00001703 return __simple_cmd(bts, NM_MT_STOP_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001704 else
Harald Welte227d4072009-01-03 08:16:25 +00001705 return __simple_cmd(bts, NM_MT_REST_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001706}
1707
Harald Welte47d88ae2009-01-04 12:02:08 +00001708/* Siemens (or BS-11) specific commands */
1709
Harald Welte3ffd1372009-02-01 22:15:49 +00001710int abis_nm_bs11_bsc_disconnect(struct gsm_bts *bts, int reconnect)
1711{
1712 if (reconnect == 0)
1713 return __simple_cmd(bts, NM_MT_BS11_DISCONNECT);
1714 else
1715 return __simple_cmd(bts, NM_MT_BS11_RECONNECT);
1716}
1717
Harald Welteb8427972009-02-05 19:27:17 +00001718int abis_nm_bs11_restart(struct gsm_bts *bts)
1719{
1720 return __simple_cmd(bts, NM_MT_BS11_RESTART);
1721}
1722
1723
Harald Welte268bb402009-02-01 19:11:56 +00001724struct bs11_date_time {
1725 u_int16_t year;
1726 u_int8_t month;
1727 u_int8_t day;
1728 u_int8_t hour;
1729 u_int8_t min;
1730 u_int8_t sec;
1731} __attribute__((packed));
1732
1733
1734void get_bs11_date_time(struct bs11_date_time *aet)
1735{
1736 time_t t;
1737 struct tm *tm;
1738
1739 t = time(NULL);
1740 tm = localtime(&t);
1741 aet->sec = tm->tm_sec;
1742 aet->min = tm->tm_min;
1743 aet->hour = tm->tm_hour;
1744 aet->day = tm->tm_mday;
1745 aet->month = tm->tm_mon;
1746 aet->year = htons(1900 + tm->tm_year);
1747}
1748
Harald Welte05188ee2009-01-18 11:39:08 +00001749int abis_nm_bs11_reset_resource(struct gsm_bts *bts)
Harald Welte52b1f982008-12-23 20:25:15 +00001750{
Harald Welte4668fda2009-01-03 08:19:29 +00001751 return __simple_cmd(bts, NM_MT_BS11_RESET_RESOURCE);
Harald Welte52b1f982008-12-23 20:25:15 +00001752}
1753
Harald Welte05188ee2009-01-18 11:39:08 +00001754int abis_nm_bs11_db_transmission(struct gsm_bts *bts, int begin)
Harald Welte52b1f982008-12-23 20:25:15 +00001755{
1756 if (begin)
Harald Welte4668fda2009-01-03 08:19:29 +00001757 return __simple_cmd(bts, NM_MT_BS11_BEGIN_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00001758 else
Harald Welte4668fda2009-01-03 08:19:29 +00001759 return __simple_cmd(bts, NM_MT_BS11_END_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00001760}
Harald Welte47d88ae2009-01-04 12:02:08 +00001761
Harald Welte05188ee2009-01-18 11:39:08 +00001762int abis_nm_bs11_create_object(struct gsm_bts *bts,
Harald Welte1bc09062009-01-18 14:17:52 +00001763 enum abis_bs11_objtype type, u_int8_t idx,
1764 u_int8_t attr_len, const u_int8_t *attr)
Harald Welte47d88ae2009-01-04 12:02:08 +00001765{
1766 struct abis_om_hdr *oh;
1767 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00001768 u_int8_t *cur;
Harald Welte47d88ae2009-01-04 12:02:08 +00001769
1770 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001771 fill_om_fom_hdr(oh, attr_len, NM_MT_BS11_CREATE_OBJ,
Harald Welte268bb402009-02-01 19:11:56 +00001772 NM_OC_BS11, type, 0, idx);
Harald Welte1bc09062009-01-18 14:17:52 +00001773 cur = msgb_put(msg, attr_len);
1774 memcpy(cur, attr, attr_len);
Harald Welte47d88ae2009-01-04 12:02:08 +00001775
1776 return abis_nm_sendmsg(bts, msg);
1777}
1778
Harald Welte78fc0d42009-02-19 02:50:57 +00001779int abis_nm_bs11_delete_object(struct gsm_bts *bts,
1780 enum abis_bs11_objtype type, u_int8_t idx)
1781{
1782 struct abis_om_hdr *oh;
1783 struct msgb *msg = nm_msgb_alloc();
1784
1785 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1786 fill_om_fom_hdr(oh, 0, NM_MT_BS11_DELETE_OBJ,
1787 NM_OC_BS11, type, 0, idx);
1788
1789 return abis_nm_sendmsg(bts, msg);
1790}
1791
Harald Welte05188ee2009-01-18 11:39:08 +00001792int abis_nm_bs11_create_envaBTSE(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00001793{
1794 struct abis_om_hdr *oh;
1795 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00001796 u_int8_t zero = 0x00;
Harald Welte47d88ae2009-01-04 12:02:08 +00001797
1798 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001799 fill_om_fom_hdr(oh, 3, NM_MT_BS11_CREATE_OBJ,
Harald Welte1bc09062009-01-18 14:17:52 +00001800 NM_OC_BS11_ENVABTSE, 0, idx, 0xff);
1801 msgb_tlv_put(msg, 0x99, 1, &zero);
Harald Welte47d88ae2009-01-04 12:02:08 +00001802
1803 return abis_nm_sendmsg(bts, msg);
1804}
1805
Harald Welte05188ee2009-01-18 11:39:08 +00001806int abis_nm_bs11_create_bport(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00001807{
1808 struct abis_om_hdr *oh;
1809 struct msgb *msg = nm_msgb_alloc();
1810
1811 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1812 fill_om_fom_hdr(oh, 0, NM_MT_BS11_CREATE_OBJ, NM_OC_BS11_BPORT,
1813 idx, 0, 0);
1814
1815 return abis_nm_sendmsg(bts, msg);
1816}
Harald Welte05188ee2009-01-18 11:39:08 +00001817
Harald Welte78fc0d42009-02-19 02:50:57 +00001818static const u_int8_t sm_attr[] = { NM_ATT_TEI, NM_ATT_ABIS_CHANNEL };
1819int abis_nm_bs11_get_oml_tei_ts(struct gsm_bts *bts)
1820{
1821 struct abis_om_hdr *oh;
1822 struct msgb *msg = nm_msgb_alloc();
1823
1824 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1825 fill_om_fom_hdr(oh, 2+sizeof(sm_attr), NM_MT_GET_ATTR, NM_OC_SITE_MANAGER,
1826 0xff, 0xff, 0xff);
1827 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(sm_attr), sm_attr);
1828
1829 return abis_nm_sendmsg(bts, msg);
1830}
1831
Harald Welteb6c92ae2009-02-21 20:15:32 +00001832/* like abis_nm_conn_terr_traf + set_tei */
1833int abis_nm_bs11_conn_oml_tei(struct gsm_bts *bts, u_int8_t e1_port,
1834 u_int8_t e1_timeslot, u_int8_t e1_subslot,
1835 u_int8_t tei)
Harald Welte05188ee2009-01-18 11:39:08 +00001836{
1837 struct abis_om_hdr *oh;
1838 struct abis_nm_channel *ch;
1839 struct msgb *msg = nm_msgb_alloc();
1840
1841 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welteb6c92ae2009-02-21 20:15:32 +00001842 fill_om_fom_hdr(oh, sizeof(*ch)+2, NM_MT_BS11_SET_ATTR,
Harald Welte05188ee2009-01-18 11:39:08 +00001843 NM_OC_SITE_MANAGER, 0xff, 0xff, 0xff);
1844
1845 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1846 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
Harald Welteb6c92ae2009-02-21 20:15:32 +00001847 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte05188ee2009-01-18 11:39:08 +00001848
1849 return abis_nm_sendmsg(bts, msg);
1850}
1851
1852int abis_nm_bs11_set_trx_power(struct gsm_bts_trx *trx, u_int8_t level)
1853{
1854 struct abis_om_hdr *oh;
1855 struct msgb *msg = nm_msgb_alloc();
Harald Welte05188ee2009-01-18 11:39:08 +00001856
1857 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001858 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR,
Harald Welte05188ee2009-01-18 11:39:08 +00001859 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
1860 msgb_tlv_put(msg, NM_ATT_BS11_TXPWR, 1, &level);
1861
1862 return abis_nm_sendmsg(trx->bts, msg);
1863}
1864
Harald Welte78fc0d42009-02-19 02:50:57 +00001865int abis_nm_bs11_get_trx_power(struct gsm_bts_trx *trx)
1866{
1867 struct abis_om_hdr *oh;
1868 struct msgb *msg = nm_msgb_alloc();
1869 u_int8_t attr = NM_ATT_BS11_TXPWR;
1870
1871 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1872 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
1873 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
1874 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), &attr);
1875
1876 return abis_nm_sendmsg(trx->bts, msg);
1877}
1878
Harald Welteaaf02d92009-04-29 13:25:57 +00001879int abis_nm_bs11_get_pll_mode(struct gsm_bts *bts)
1880{
1881 struct abis_om_hdr *oh;
1882 struct msgb *msg = nm_msgb_alloc();
Harald Weltea7cfa032009-04-29 22:33:02 +00001883 u_int8_t attr[] = { NM_ATT_BS11_PLL_MODE };
Harald Welteaaf02d92009-04-29 13:25:57 +00001884
1885 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1886 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
1887 NM_OC_BS11, BS11_OBJ_LI, 0x00, 0x00);
Harald Welteaeedeb42009-05-01 13:08:14 +00001888 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), attr);
Harald Welteaaf02d92009-04-29 13:25:57 +00001889
1890 return abis_nm_sendmsg(bts, msg);
1891}
1892
Harald Welteef061952009-05-17 12:43:42 +00001893int abis_nm_bs11_get_cclk(struct gsm_bts *bts)
1894{
1895 struct abis_om_hdr *oh;
1896 struct msgb *msg = nm_msgb_alloc();
1897 u_int8_t attr[] = { NM_ATT_BS11_CCLK_ACCURACY,
1898 NM_ATT_BS11_CCLK_TYPE };
1899
1900 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1901 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
1902 NM_OC_BS11, BS11_OBJ_CCLK, 0x00, 0x00);
1903 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), attr);
1904
1905 return abis_nm_sendmsg(bts, msg);
1906
1907}
Harald Welteaaf02d92009-04-29 13:25:57 +00001908
Harald Welte268bb402009-02-01 19:11:56 +00001909//static const u_int8_t bs11_logon_c7[] = { 0x07, 0xd9, 0x01, 0x11, 0x0d, 0x10, 0x20 };
Harald Weltebb151312009-01-28 20:42:07 +00001910static const u_int8_t bs11_logon_c8[] = { 0x02 };
Harald Welte05188ee2009-01-18 11:39:08 +00001911static const u_int8_t bs11_logon_c9[] = "FACTORY";
1912
Harald Welte1bc09062009-01-18 14:17:52 +00001913int abis_nm_bs11_factory_logon(struct gsm_bts *bts, int on)
Harald Welte05188ee2009-01-18 11:39:08 +00001914{
1915 struct abis_om_hdr *oh;
1916 struct msgb *msg = nm_msgb_alloc();
Harald Welte268bb402009-02-01 19:11:56 +00001917 struct bs11_date_time bdt;
1918
1919 get_bs11_date_time(&bdt);
Harald Welte05188ee2009-01-18 11:39:08 +00001920
1921 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte1bc09062009-01-18 14:17:52 +00001922 if (on) {
Harald Welte268bb402009-02-01 19:11:56 +00001923 u_int8_t len = 3*2 + sizeof(bdt)
Harald Welte6f676a32009-01-18 14:27:48 +00001924 + sizeof(bs11_logon_c8) + sizeof(bs11_logon_c9);
Harald Welte043d04a2009-01-29 23:15:30 +00001925 fill_om_fom_hdr(oh, len, NM_MT_BS11_LMT_LOGON,
Harald Welte7b26bcb2009-05-28 11:39:21 +00001926 NM_OC_BS11_BTSE, 0xff, 0xff, 0xff);
Harald Welte043d04a2009-01-29 23:15:30 +00001927 msgb_tlv_put(msg, NM_ATT_BS11_LMT_LOGIN_TIME,
Harald Welte5083b0b2009-02-02 19:20:52 +00001928 sizeof(bdt), (u_int8_t *) &bdt);
Harald Welte043d04a2009-01-29 23:15:30 +00001929 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_ACC_LEV,
1930 sizeof(bs11_logon_c8), bs11_logon_c8);
1931 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_NAME,
1932 sizeof(bs11_logon_c9), bs11_logon_c9);
Harald Welte1bc09062009-01-18 14:17:52 +00001933 } else {
Harald Welte5e4d1b32009-02-01 13:36:56 +00001934 fill_om_fom_hdr(oh, 0, NM_MT_BS11_LMT_LOGOFF,
Harald Welte7b26bcb2009-05-28 11:39:21 +00001935 NM_OC_BS11_BTSE, 0xff, 0xff, 0xff);
Harald Welte1bc09062009-01-18 14:17:52 +00001936 }
Harald Welte05188ee2009-01-18 11:39:08 +00001937
1938 return abis_nm_sendmsg(bts, msg);
1939}
Harald Welte1bc09062009-01-18 14:17:52 +00001940
1941int abis_nm_bs11_set_trx1_pw(struct gsm_bts *bts, const char *password)
1942{
1943 struct abis_om_hdr *oh;
1944 struct msgb *msg;
1945
1946 if (strlen(password) != 10)
1947 return -EINVAL;
1948
1949 msg = nm_msgb_alloc();
1950 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001951 fill_om_fom_hdr(oh, 2+strlen(password), NM_MT_BS11_SET_ATTR,
Harald Welte1bc09062009-01-18 14:17:52 +00001952 NM_OC_BS11, BS11_OBJ_TRX1, 0x00, 0x00);
1953 msgb_tlv_put(msg, NM_ATT_BS11_PASSWORD, 10, (const u_int8_t *)password);
1954
1955 return abis_nm_sendmsg(bts, msg);
1956}
1957
Harald Weltee69f5fb2009-04-28 16:31:38 +00001958/* change the BS-11 PLL Mode to either locked (E1 derived) or standalone */
1959int abis_nm_bs11_set_pll_locked(struct gsm_bts *bts, int locked)
1960{
1961 struct abis_om_hdr *oh;
1962 struct msgb *msg;
Harald Weltea432cd32009-04-29 13:01:50 +00001963 u_int8_t tlv_value;
Harald Weltee69f5fb2009-04-28 16:31:38 +00001964
1965 msg = nm_msgb_alloc();
1966 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1967 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR, NM_OC_BS11,
1968 BS11_OBJ_LI, 0x00, 0x00);
Harald Weltea432cd32009-04-29 13:01:50 +00001969
1970 if (locked)
1971 tlv_value = BS11_LI_PLL_LOCKED;
1972 else
1973 tlv_value = BS11_LI_PLL_STANDALONE;
1974
1975 msgb_tlv_put(msg, NM_ATT_BS11_PLL_MODE, 1, &tlv_value);
Harald Weltee69f5fb2009-04-28 16:31:38 +00001976
1977 return abis_nm_sendmsg(bts, msg);
1978}
1979
Harald Welte1bc09062009-01-18 14:17:52 +00001980int abis_nm_bs11_get_state(struct gsm_bts *bts)
1981{
1982 return __simple_cmd(bts, NM_MT_BS11_GET_STATE);
1983}
Harald Welte5e4d1b32009-02-01 13:36:56 +00001984
1985/* BS11 SWL */
1986
1987struct abis_nm_bs11_sw {
1988 struct gsm_bts *bts;
1989 char swl_fname[PATH_MAX];
1990 u_int8_t win_size;
Harald Welte3ffd1372009-02-01 22:15:49 +00001991 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001992 struct llist_head file_list;
1993 gsm_cbfn *user_cb; /* specified by the user */
1994};
1995static struct abis_nm_bs11_sw _g_bs11_sw, *g_bs11_sw = &_g_bs11_sw;
1996
1997struct file_list_entry {
1998 struct llist_head list;
1999 char fname[PATH_MAX];
2000};
2001
2002struct file_list_entry *fl_dequeue(struct llist_head *queue)
2003{
2004 struct llist_head *lh;
2005
2006 if (llist_empty(queue))
2007 return NULL;
2008
2009 lh = queue->next;
2010 llist_del(lh);
2011
2012 return llist_entry(lh, struct file_list_entry, list);
2013}
2014
2015static int bs11_read_swl_file(struct abis_nm_bs11_sw *bs11_sw)
2016{
2017 char linebuf[255];
2018 struct llist_head *lh, *lh2;
2019 FILE *swl;
2020 int rc = 0;
2021
2022 swl = fopen(bs11_sw->swl_fname, "r");
2023 if (!swl)
2024 return -ENODEV;
2025
2026 /* zero the stale file list, if any */
2027 llist_for_each_safe(lh, lh2, &bs11_sw->file_list) {
2028 llist_del(lh);
2029 free(lh);
2030 }
2031
2032 while (fgets(linebuf, sizeof(linebuf), swl)) {
2033 char file_id[12+1];
2034 char file_version[80+1];
2035 struct file_list_entry *fle;
2036 static char dir[PATH_MAX];
2037
2038 if (strlen(linebuf) < 4)
2039 continue;
Harald Welte3ffd1372009-02-01 22:15:49 +00002040
Harald Welte5e4d1b32009-02-01 13:36:56 +00002041 rc = sscanf(linebuf+4, "%12s:%80s\r\n", file_id, file_version);
2042 if (rc < 0) {
2043 perror("ERR parsing SWL file");
2044 rc = -EINVAL;
2045 goto out;
2046 }
2047 if (rc < 2)
2048 continue;
2049
2050 fle = malloc(sizeof(*fle));
2051 if (!fle) {
2052 rc = -ENOMEM;
2053 goto out;
2054 }
2055 memset(fle, 0, sizeof(*fle));
2056
2057 /* construct new filename */
2058 strncpy(dir, bs11_sw->swl_fname, sizeof(dir));
2059 strncat(fle->fname, dirname(dir), sizeof(fle->fname) - 1);
2060 strcat(fle->fname, "/");
2061 strncat(fle->fname, file_id, sizeof(fle->fname) - 1 -strlen(fle->fname));
Harald Welte5e4d1b32009-02-01 13:36:56 +00002062
2063 llist_add_tail(&fle->list, &bs11_sw->file_list);
2064 }
2065
2066out:
2067 fclose(swl);
2068 return rc;
2069}
2070
2071/* bs11 swload specific callback, passed to abis_nm core swload */
2072static int bs11_swload_cbfn(unsigned int hook, unsigned int event,
2073 struct msgb *msg, void *data, void *param)
2074{
2075 struct abis_nm_bs11_sw *bs11_sw = data;
2076 struct file_list_entry *fle;
2077 int rc = 0;
2078
Harald Welte5e4d1b32009-02-01 13:36:56 +00002079 switch (event) {
2080 case NM_MT_LOAD_END_ACK:
2081 fle = fl_dequeue(&bs11_sw->file_list);
2082 if (fle) {
2083 /* start download the next file of our file list */
2084 rc = abis_nm_software_load(bs11_sw->bts, fle->fname,
2085 bs11_sw->win_size,
Harald Welte3ffd1372009-02-01 22:15:49 +00002086 bs11_sw->forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00002087 &bs11_swload_cbfn, bs11_sw);
2088 free(fle);
2089 } else {
2090 /* activate the SWL */
2091 rc = abis_nm_software_activate(bs11_sw->bts,
2092 bs11_sw->swl_fname,
2093 bs11_swload_cbfn,
2094 bs11_sw);
2095 }
2096 break;
Harald Welte3ffd1372009-02-01 22:15:49 +00002097 case NM_MT_LOAD_SEG_ACK:
Harald Welte5e4d1b32009-02-01 13:36:56 +00002098 case NM_MT_LOAD_END_NACK:
2099 case NM_MT_LOAD_INIT_ACK:
2100 case NM_MT_LOAD_INIT_NACK:
2101 case NM_MT_ACTIVATE_SW_NACK:
2102 case NM_MT_ACTIVATE_SW_ACK:
2103 default:
2104 /* fallthrough to the user callback */
Harald Welte97ed1e72009-02-06 13:38:02 +00002105 if (bs11_sw->user_cb)
2106 rc = bs11_sw->user_cb(hook, event, msg, NULL, NULL);
Harald Welte5e4d1b32009-02-01 13:36:56 +00002107 break;
2108 }
2109
2110 return rc;
2111}
2112
2113/* Siemens provides a SWL file that is a mere listing of all the other
2114 * files that are part of a software release. We need to upload first
2115 * the list file, and then each file that is listed in the list file */
2116int abis_nm_bs11_load_swl(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00002117 u_int8_t win_size, int forced, gsm_cbfn *cbfn)
Harald Welte5e4d1b32009-02-01 13:36:56 +00002118{
2119 struct abis_nm_bs11_sw *bs11_sw = g_bs11_sw;
2120 struct file_list_entry *fle;
2121 int rc = 0;
2122
2123 INIT_LLIST_HEAD(&bs11_sw->file_list);
2124 bs11_sw->bts = bts;
2125 bs11_sw->win_size = win_size;
2126 bs11_sw->user_cb = cbfn;
Harald Welte3ffd1372009-02-01 22:15:49 +00002127 bs11_sw->forced = forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00002128
2129 strncpy(bs11_sw->swl_fname, fname, sizeof(bs11_sw->swl_fname));
2130 rc = bs11_read_swl_file(bs11_sw);
2131 if (rc < 0)
2132 return rc;
2133
2134 /* dequeue next item in file list */
2135 fle = fl_dequeue(&bs11_sw->file_list);
2136 if (!fle)
2137 return -EINVAL;
2138
2139 /* start download the next file of our file list */
Harald Welte3ffd1372009-02-01 22:15:49 +00002140 rc = abis_nm_software_load(bts, fle->fname, win_size, forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00002141 bs11_swload_cbfn, bs11_sw);
2142 free(fle);
2143 return rc;
2144}
2145
Harald Welte5083b0b2009-02-02 19:20:52 +00002146#if 0
Harald Welte5e4d1b32009-02-01 13:36:56 +00002147static u_int8_t req_attr_btse[] = {
2148 NM_ATT_ADM_STATE, NM_ATT_BS11_LMT_LOGON_SESSION,
2149 NM_ATT_BS11_LMT_LOGIN_TIME, NM_ATT_BS11_LMT_USER_ACC_LEV,
2150 NM_ATT_BS11_LMT_USER_NAME,
2151
2152 0xaf, NM_ATT_BS11_RX_OFFSET, NM_ATT_BS11_VENDOR_NAME,
2153
2154 NM_ATT_BS11_SW_LOAD_INTENDED, NM_ATT_BS11_SW_LOAD_SAFETY,
2155
2156 NM_ATT_BS11_SW_LOAD_STORED };
2157
2158static u_int8_t req_attr_btsm[] = {
2159 NM_ATT_ABIS_CHANNEL, NM_ATT_TEI, NM_ATT_BS11_ABIS_EXT_TIME,
2160 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xce, NM_ATT_FILE_ID,
2161 NM_ATT_FILE_VERSION, NM_ATT_OPER_STATE, 0xe8, NM_ATT_BS11_ALL_TEST_CATG,
2162 NM_ATT_SW_DESCR, NM_ATT_GET_ARI };
Harald Welte5083b0b2009-02-02 19:20:52 +00002163#endif
Harald Welte5e4d1b32009-02-01 13:36:56 +00002164
2165static u_int8_t req_attr[] = {
2166 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xa8, NM_ATT_OPER_STATE,
2167 0xd5, 0xa1, NM_ATT_BS11_ESN_FW_CODE_NO, NM_ATT_BS11_ESN_HW_CODE_NO,
Harald Weltea7cfa032009-04-29 22:33:02 +00002168 0x42, NM_ATT_BS11_ESN_PCB_SERIAL, NM_ATT_BS11_PLL };
Harald Welte5e4d1b32009-02-01 13:36:56 +00002169
2170int abis_nm_bs11_get_serno(struct gsm_bts *bts)
2171{
2172 struct abis_om_hdr *oh;
2173 struct msgb *msg = nm_msgb_alloc();
2174
2175 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2176 /* SiemensHW CCTRL object */
2177 fill_om_fom_hdr(oh, 2+sizeof(req_attr), NM_MT_GET_ATTR, NM_OC_BS11,
2178 0x03, 0x00, 0x00);
2179 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(req_attr), req_attr);
2180
2181 return abis_nm_sendmsg(bts, msg);
2182}
Harald Welte268bb402009-02-01 19:11:56 +00002183
2184int abis_nm_bs11_set_ext_time(struct gsm_bts *bts)
2185{
2186 struct abis_om_hdr *oh;
2187 struct msgb *msg = nm_msgb_alloc();
2188 struct bs11_date_time aet;
2189
2190 get_bs11_date_time(&aet);
2191 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2192 /* SiemensHW CCTRL object */
2193 fill_om_fom_hdr(oh, 2+sizeof(aet), NM_MT_BS11_SET_ATTR, NM_OC_SITE_MANAGER,
2194 0xff, 0xff, 0xff);
Harald Welte5083b0b2009-02-02 19:20:52 +00002195 msgb_tlv_put(msg, NM_ATT_BS11_ABIS_EXT_TIME, sizeof(aet), (u_int8_t *) &aet);
Harald Welte268bb402009-02-01 19:11:56 +00002196
2197 return abis_nm_sendmsg(bts, msg);
2198}
Harald Welte5c1e4582009-02-15 11:57:29 +00002199
2200/* ip.access nanoBTS specific commands */
Harald Welte5c1e4582009-02-15 11:57:29 +00002201static const char ipaccess_magic[] = "com.ipaccess";
2202
Harald Welte677c21f2009-02-17 13:22:23 +00002203
2204static int abis_nm_rx_ipacc(struct msgb *msg)
2205{
2206 struct abis_om_hdr *oh = msgb_l2(msg);
2207 struct abis_om_fom_hdr *foh;
2208 u_int8_t idstrlen = oh->data[0];
2209 struct tlv_parsed tp;
2210
2211 if (strncmp((char *)&oh->data[1], ipaccess_magic, idstrlen)) {
2212 DEBUGP(DNM, "id string is not com.ipaccess !?!\n");
2213 return -EINVAL;
2214 }
2215
Harald Welte193fefc2009-04-30 15:16:27 +00002216 foh = (struct abis_om_fom_hdr *) (oh->data + 1 + idstrlen);
Harald Welte03133942009-02-18 19:51:53 +00002217 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Welte677c21f2009-02-17 13:22:23 +00002218
Harald Welte193fefc2009-04-30 15:16:27 +00002219 DEBUGP(DNM, "IPACCESS(0x%02x): ", foh->msg_type);
2220
Harald Welte677c21f2009-02-17 13:22:23 +00002221 switch (foh->msg_type) {
2222 case NM_MT_IPACC_RSL_CONNECT_ACK:
Harald Welte193fefc2009-04-30 15:16:27 +00002223 DEBUGPC(DNM, "RSL CONNECT ACK ");
Harald Welte677c21f2009-02-17 13:22:23 +00002224 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_RSL_BSC_IP))
Harald Welte9de2bf82009-04-30 15:59:55 +00002225 DEBUGPC(DNM, "IP=%s ",
Harald Welte677c21f2009-02-17 13:22:23 +00002226 inet_ntoa(*((struct in_addr *)
2227 TLVP_VAL(&tp, NM_ATT_IPACC_RSL_BSC_IP))));
2228 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_RSL_BSC_PORT))
Harald Welte9de2bf82009-04-30 15:59:55 +00002229 DEBUGPC(DNM, "PORT=%u ",
Harald Welte677c21f2009-02-17 13:22:23 +00002230 ntohs(*((u_int16_t *)
2231 TLVP_VAL(&tp, NM_ATT_IPACC_RSL_BSC_PORT))));
Harald Welte9de2bf82009-04-30 15:59:55 +00002232 DEBUGPC(DNM, "\n");
Harald Welte677c21f2009-02-17 13:22:23 +00002233 break;
2234 case NM_MT_IPACC_RSL_CONNECT_NACK:
Harald Welte193fefc2009-04-30 15:16:27 +00002235 DEBUGPC(DNM, "RSL CONNECT NACK ");
Harald Welte677c21f2009-02-17 13:22:23 +00002236 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
Harald Welte6c96ba52009-05-01 13:03:40 +00002237 DEBUGPC(DNM, " CAUSE=%s\n",
2238 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
Harald Welte677c21f2009-02-17 13:22:23 +00002239 else
2240 DEBUGPC(DNM, "\n");
2241 break;
Harald Welte193fefc2009-04-30 15:16:27 +00002242 case NM_MT_IPACC_SET_NVATTR_ACK:
2243 DEBUGPC(DNM, "SET NVATTR ACK\n");
2244 /* FIXME: decode and show the actual attributes */
2245 break;
2246 case NM_MT_IPACC_SET_NVATTR_NACK:
Harald Welte6c96ba52009-05-01 13:03:40 +00002247 DEBUGPC(DNM, "SET NVATTR NACK ");
2248 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
2249 DEBUGPC(DNM, " CAUSE=%s\n",
2250 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
2251 else
2252 DEBUGPC(DNM, "\n");
Harald Welte193fefc2009-04-30 15:16:27 +00002253 break;
2254 default:
2255 DEBUGPC(DNM, "unknown\n");
2256 break;
Harald Welte677c21f2009-02-17 13:22:23 +00002257 }
2258 return 0;
2259}
2260
Harald Welte193fefc2009-04-30 15:16:27 +00002261/* send an ip-access manufacturer specific message */
Harald Welte5c1e4582009-02-15 11:57:29 +00002262int abis_nm_ipaccess_msg(struct gsm_bts *bts, u_int8_t msg_type,
2263 u_int8_t obj_class, u_int8_t bts_nr,
2264 u_int8_t trx_nr, u_int8_t ts_nr,
2265 u_int8_t *attr, int attr_len)
2266{
2267 struct msgb *msg = nm_msgb_alloc();
2268 struct abis_om_hdr *oh;
2269 struct abis_om_fom_hdr *foh;
2270 u_int8_t *data;
2271
2272 /* construct the 12.21 OM header, observe the erroneous length */
2273 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
2274 fill_om_hdr(oh, sizeof(*foh) + attr_len);
2275 oh->mdisc = ABIS_OM_MDISC_MANUF;
2276
2277 /* add the ip.access magic */
2278 data = msgb_put(msg, sizeof(ipaccess_magic)+1);
2279 *data++ = sizeof(ipaccess_magic);
2280 memcpy(data, ipaccess_magic, sizeof(ipaccess_magic));
2281
2282 /* fill the 12.21 FOM header */
2283 foh = (struct abis_om_fom_hdr *) msgb_put(msg, sizeof(*foh));
2284 foh->msg_type = msg_type;
2285 foh->obj_class = obj_class;
2286 foh->obj_inst.bts_nr = bts_nr;
2287 foh->obj_inst.trx_nr = trx_nr;
2288 foh->obj_inst.ts_nr = ts_nr;
2289
2290 if (attr && attr_len) {
2291 data = msgb_put(msg, attr_len);
2292 memcpy(data, attr, attr_len);
2293 }
2294
2295 return abis_nm_sendmsg(bts, msg);
2296}
Harald Welte677c21f2009-02-17 13:22:23 +00002297
Harald Welte193fefc2009-04-30 15:16:27 +00002298/* set some attributes in NVRAM */
2299int abis_nm_ipaccess_set_nvattr(struct gsm_bts *bts, u_int8_t *attr,
2300 int attr_len)
2301{
2302 return abis_nm_ipaccess_msg(bts, NM_MT_IPACC_SET_NVATTR,
2303 NM_OC_BASEB_TRANSC, 0, 0, 0xff, attr,
2304 attr_len);
2305}
2306
2307/* restart / reboot an ip.access nanoBTS */
2308int abis_nm_ipaccess_restart(struct gsm_bts *bts)
2309{
2310 return __simple_cmd(bts, NM_MT_IPACC_RESTART);
2311}