blob: 0107c294ec08719d68a616b3b91bfd238676418c [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 +0000438const char *oc_names[] = {
439 [NM_OC_SITE_MANAGER] = "SITE MANAGER",
440 [NM_OC_BTS] = "BTS",
441 [NM_OC_RADIO_CARRIER] = "RADIO CARRIER",
442 [NM_OC_BASEB_TRANSC] = "BASEBAND TRANSCEIVER",
443 [NM_OC_CHANNEL] = "CHANNEL",
444};
445
446static const char *obj_class_name(u_int8_t oc)
447{
448 if (oc >= ARRAY_SIZE(oc_names))
449 return "UNKNOWN";
450 return oc_names[oc];
451}
452
Harald Welte4d87f242009-03-10 19:43:44 +0000453const char *nm_opstate_name(u_int8_t os)
Harald Welte34a99682009-02-13 02:41:40 +0000454{
455 switch (os) {
456 case 1:
457 return "Disabled";
458 case 2:
459 return "Enabled";
460 case 0xff:
461 return "NULL";
462 default:
463 return "RFU";
464 }
465}
466
Harald Weltee0590df2009-02-15 03:34:15 +0000467/* Chapter 9.4.7 */
Harald Welte4d87f242009-03-10 19:43:44 +0000468static const char *avail_names[] = {
Harald Weltee0590df2009-02-15 03:34:15 +0000469 "In test",
470 "Failed",
471 "Power off",
472 "Off line",
473 "<not used>",
474 "Dependency",
475 "Degraded",
476 "Not installed",
477};
478
Harald Welte4d87f242009-03-10 19:43:44 +0000479const char *nm_avail_name(u_int8_t avail)
Harald Weltee0590df2009-02-15 03:34:15 +0000480{
Harald Welte0b8348d2009-02-18 03:43:01 +0000481 if (avail == 0xff)
482 return "OK";
Harald Weltee0590df2009-02-15 03:34:15 +0000483 if (avail >= ARRAY_SIZE(avail_names))
484 return "UNKNOWN";
485 return avail_names[avail];
486}
487
488
489/* obtain the gsm_nm_state data structure for a given object instance */
490static struct gsm_nm_state *
491objclass2nmstate(struct gsm_bts *bts, u_int8_t obj_class,
492 struct abis_om_obj_inst *obj_inst)
493{
494 struct gsm_bts_trx *trx;
495 struct gsm_nm_state *nm_state = NULL;
496
497 switch (obj_class) {
498 case NM_OC_BTS:
499 nm_state = &bts->nm_state;
500 break;
501 case NM_OC_RADIO_CARRIER:
502 if (obj_inst->trx_nr >= bts->num_trx)
503 return NULL;
504 trx = &bts->trx[obj_inst->trx_nr];
505 nm_state = &trx->nm_state;
506 break;
507 case NM_OC_BASEB_TRANSC:
508 if (obj_inst->trx_nr >= bts->num_trx)
509 return NULL;
510 trx = &bts->trx[obj_inst->trx_nr];
511 nm_state = &trx->bb_transc.nm_state;
512 break;
513 case NM_OC_CHANNEL:
514 if (obj_inst->trx_nr > bts->num_trx)
515 return NULL;
516 trx = &bts->trx[obj_inst->trx_nr];
517 if (obj_inst->ts_nr >= TRX_NR_TS)
518 return NULL;
519 nm_state = &trx->ts[obj_inst->ts_nr].nm_state;
520 break;
521 case NM_OC_SITE_MANAGER:
522 nm_state = &bts->site_mgr.nm_state;
523 break;
524 }
525 return nm_state;
526}
527
528/* obtain the in-memory data structure of a given object instance */
529static void *
530objclass2obj(struct gsm_bts *bts, u_int8_t obj_class,
531 struct abis_om_obj_inst *obj_inst)
532{
533 struct gsm_bts_trx *trx;
534 void *obj = NULL;
535
536 switch (obj_class) {
537 case NM_OC_BTS:
538 obj = bts;
539 break;
540 case NM_OC_RADIO_CARRIER:
541 if (obj_inst->trx_nr >= bts->num_trx)
542 return NULL;
543 trx = &bts->trx[obj_inst->trx_nr];
544 obj = trx;
545 break;
546 case NM_OC_BASEB_TRANSC:
547 if (obj_inst->trx_nr >= bts->num_trx)
548 return NULL;
549 trx = &bts->trx[obj_inst->trx_nr];
550 obj = &trx->bb_transc;
551 break;
552 case NM_OC_CHANNEL:
553 if (obj_inst->trx_nr > bts->num_trx)
554 return NULL;
555 trx = &bts->trx[obj_inst->trx_nr];
556 if (obj_inst->ts_nr >= TRX_NR_TS)
557 return NULL;
558 obj = &trx->ts[obj_inst->ts_nr];
559 break;
560 case NM_OC_SITE_MANAGER:
561 obj = &bts->site_mgr;
562 break;
563 }
564 return obj;
565}
566
567/* Update the administrative state of a given object in our in-memory data
568 * structures and send an event to the higher layer */
569static int update_admstate(struct gsm_bts *bts, u_int8_t obj_class,
570 struct abis_om_obj_inst *obj_inst, u_int8_t adm_state)
571{
Harald Welteaeedeb42009-05-01 13:08:14 +0000572 struct gsm_nm_state *nm_state, new_state;
Harald Weltee0590df2009-02-15 03:34:15 +0000573 void *obj;
574 int rc;
575
Harald Weltee0590df2009-02-15 03:34:15 +0000576 obj = objclass2obj(bts, obj_class, obj_inst);
Harald Welteaeedeb42009-05-01 13:08:14 +0000577 nm_state = objclass2nmstate(bts, obj_class, obj_inst);
578 if (!nm_state)
579 return -1;
580
581 new_state = *nm_state;
582 new_state.administrative = adm_state;
583
584 rc = nm_state_event(EVT_STATECHG_ADM, obj_class, obj, nm_state, &new_state);
585
586 nm_state->administrative = adm_state;
Harald Weltee0590df2009-02-15 03:34:15 +0000587
588 return rc;
589}
590
Harald Welte97ed1e72009-02-06 13:38:02 +0000591static int abis_nm_rx_statechg_rep(struct msgb *mb)
592{
Harald Weltee0590df2009-02-15 03:34:15 +0000593 struct abis_om_hdr *oh = msgb_l2(mb);
Harald Welte97ed1e72009-02-06 13:38:02 +0000594 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Harald Welte22af0db2009-02-14 15:41:08 +0000595 struct gsm_bts *bts = mb->trx->bts;
Harald Weltee0590df2009-02-15 03:34:15 +0000596 struct tlv_parsed tp;
597 struct gsm_nm_state *nm_state, new_state;
598 int rc;
599
Harald Welte23897662009-05-01 14:52:51 +0000600 DEBUGPC(DNM, "STATE CHG: ");
Harald Weltee0590df2009-02-15 03:34:15 +0000601
602 nm_state = objclass2nmstate(bts, foh->obj_class, &foh->obj_inst);
603 if (!nm_state) {
604 DEBUGPC(DNM, "\n");
605 return -EINVAL;
Harald Welte22af0db2009-02-14 15:41:08 +0000606 }
Harald Weltee0590df2009-02-15 03:34:15 +0000607
608 new_state = *nm_state;
609
Harald Welte03133942009-02-18 19:51:53 +0000610 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Weltee0590df2009-02-15 03:34:15 +0000611 if (TLVP_PRESENT(&tp, NM_ATT_OPER_STATE)) {
612 new_state.operational = *TLVP_VAL(&tp, NM_ATT_OPER_STATE);
Harald Welte4d87f242009-03-10 19:43:44 +0000613 DEBUGPC(DNM, "OP_STATE=%s ", nm_opstate_name(new_state.operational));
Harald Weltee0590df2009-02-15 03:34:15 +0000614 }
615 if (TLVP_PRESENT(&tp, NM_ATT_AVAIL_STATUS)) {
Harald Welte0b8348d2009-02-18 03:43:01 +0000616 if (TLVP_LEN(&tp, NM_ATT_AVAIL_STATUS) == 0)
617 new_state.availability = 0xff;
618 else
619 new_state.availability = *TLVP_VAL(&tp, NM_ATT_AVAIL_STATUS);
Harald Welte4d87f242009-03-10 19:43:44 +0000620 DEBUGPC(DNM, "AVAIL=%s(%02x) ", nm_avail_name(new_state.availability),
Harald Weltee0590df2009-02-15 03:34:15 +0000621 new_state.availability);
622 }
623 if (TLVP_PRESENT(&tp, NM_ATT_ADM_STATE)) {
624 new_state.administrative = *TLVP_VAL(&tp, NM_ATT_ADM_STATE);
625 DEBUGPC(DNM, "ADM=%02x ", new_state.administrative);
Harald Welte97ed1e72009-02-06 13:38:02 +0000626 }
627 DEBUGPC(DNM, "\n");
Harald Weltee0590df2009-02-15 03:34:15 +0000628
629 if (memcmp(&new_state, nm_state, sizeof(new_state))) {
630 /* Update the operational state of a given object in our in-memory data
631 * structures and send an event to the higher layer */
632 void *obj = objclass2obj(bts, foh->obj_class, &foh->obj_inst);
633 rc = nm_state_event(EVT_STATECHG_OPER, foh->obj_class, obj, nm_state, &new_state);
634 *nm_state = new_state;
635 }
636#if 0
Harald Welte22af0db2009-02-14 15:41:08 +0000637 if (op_state == 1) {
638 /* try to enable objects that are disabled */
639 abis_nm_opstart(bts, foh->obj_class,
640 foh->obj_inst.bts_nr,
641 foh->obj_inst.trx_nr,
642 foh->obj_inst.ts_nr);
643 }
Harald Weltee0590df2009-02-15 03:34:15 +0000644#endif
Harald Welte97ed1e72009-02-06 13:38:02 +0000645 return 0;
646}
647
Harald Welte0db97b22009-05-01 17:22:47 +0000648static int rx_fail_evt_rep(struct msgb *mb)
649{
650 struct abis_om_hdr *oh = msgb_l2(mb);
651 struct abis_om_fom_hdr *foh = msgb_l3(mb);
652 struct tlv_parsed tp;
653
654 DEBUGPC(DNM, "Failure Event Report ");
655
656 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
657
658 if (TLVP_PRESENT(&tp, NM_ATT_EVENT_TYPE))
659 DEBUGPC(DNM, "Type=%s ", event_type_name(*TLVP_VAL(&tp, NM_ATT_EVENT_TYPE)));
660 if (TLVP_PRESENT(&tp, NM_ATT_SEVERITY))
661 DEBUGPC(DNM, "Severity=%s ", severity_name(*TLVP_VAL(&tp, NM_ATT_SEVERITY)));
662
663 DEBUGPC(DNM, "\n");
664
665 return 0;
666}
667
Harald Welte97ed1e72009-02-06 13:38:02 +0000668static int abis_nm_rcvmsg_report(struct msgb *mb)
669{
670 struct abis_om_fom_hdr *foh = msgb_l3(mb);
671 u_int8_t mt = foh->msg_type;
672
Harald Welte23897662009-05-01 14:52:51 +0000673 DEBUGP(DNM, "OC=%s(%02x) INST=(%02x,%02x,%02x) ",
674 obj_class_name(foh->obj_class), foh->obj_class,
675 foh->obj_inst.bts_nr, foh->obj_inst.trx_nr,
676 foh->obj_inst.ts_nr);
677
Harald Welte97ed1e72009-02-06 13:38:02 +0000678 //nmh->cfg->report_cb(mb, foh);
679
680 switch (mt) {
681 case NM_MT_STATECHG_EVENT_REP:
682 return abis_nm_rx_statechg_rep(mb);
683 break;
Harald Welte34a99682009-02-13 02:41:40 +0000684 case NM_MT_SW_ACTIVATED_REP:
Harald Welte23897662009-05-01 14:52:51 +0000685 DEBUGPC(DNM, "Software Activated Report\n");
Harald Weltef9a8cc32009-05-01 15:39:49 +0000686 dispatch_signal(SS_NM, S_NM_SW_ACTIV_REP, mb);
Harald Welte34a99682009-02-13 02:41:40 +0000687 break;
Harald Weltee0590df2009-02-15 03:34:15 +0000688 case NM_MT_FAILURE_EVENT_REP:
Harald Welte0db97b22009-05-01 17:22:47 +0000689 rx_fail_evt_rep(mb);
Harald Weltef9a8cc32009-05-01 15:39:49 +0000690 dispatch_signal(SS_NM, S_NM_FAIL_REP, mb);
Harald Weltee0590df2009-02-15 03:34:15 +0000691 break;
692 default:
Harald Welte23897662009-05-01 14:52:51 +0000693 DEBUGPC(DNM, "reporting NM MT 0x%02x\n", mt);
Harald Weltee0590df2009-02-15 03:34:15 +0000694 break;
695
Harald Welte97ed1e72009-02-06 13:38:02 +0000696 };
697
Harald Welte97ed1e72009-02-06 13:38:02 +0000698 return 0;
699}
700
Harald Welte34a99682009-02-13 02:41:40 +0000701/* Activate the specified software into the BTS */
702static int ipacc_sw_activate(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1,
703 u_int8_t i2, u_int8_t *sw_desc, u_int8_t swdesc_len)
704{
705 struct abis_om_hdr *oh;
706 struct msgb *msg = nm_msgb_alloc();
707 u_int8_t len = swdesc_len;
708 u_int8_t *trailer;
709
710 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
711 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, obj_class, i0, i1, i2);
712
713 trailer = msgb_put(msg, swdesc_len);
714 memcpy(trailer, sw_desc, swdesc_len);
715
716 return abis_nm_sendmsg(bts, msg);
717}
718
719static int abis_nm_rx_sw_act_req(struct msgb *mb)
720{
721 struct abis_om_hdr *oh = msgb_l2(mb);
722 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Harald Welte5c1e4582009-02-15 11:57:29 +0000723 int nack = 0;
Harald Welte34a99682009-02-13 02:41:40 +0000724 int ret;
725
Harald Welte5c1e4582009-02-15 11:57:29 +0000726 DEBUGP(DNM, "Software Activate Request ");
Harald Welte34a99682009-02-13 02:41:40 +0000727
Harald Welte5c1e4582009-02-15 11:57:29 +0000728 if (foh->obj_class >= 0xf0 && foh->obj_class <= 0xf3) {
729 DEBUGPC(DNM, "NACKing for GPRS obj_class 0x%02x\n", foh->obj_class);
730 nack = 1;
731 } else
732 DEBUGPC(DNM, "ACKing and Activating\n");
733
734 ret = abis_nm_sw_act_req_ack(mb->trx->bts, foh->obj_class,
Harald Welte34a99682009-02-13 02:41:40 +0000735 foh->obj_inst.bts_nr,
736 foh->obj_inst.trx_nr,
Harald Welte5c1e4582009-02-15 11:57:29 +0000737 foh->obj_inst.ts_nr, nack,
Harald Welte34a99682009-02-13 02:41:40 +0000738 foh->data, oh->length-sizeof(*foh));
739
Harald Welte5c1e4582009-02-15 11:57:29 +0000740 if (nack)
741 return ret;
742
Harald Welte34a99682009-02-13 02:41:40 +0000743 /* FIXME: properly parse attributes */
744 return ipacc_sw_activate(mb->trx->bts, foh->obj_class,
745 foh->obj_inst.bts_nr,
746 foh->obj_inst.trx_nr,
747 foh->obj_inst.ts_nr,
748 foh->data + oh->length-sizeof(*foh)-22, 22);
749}
750
Harald Weltee0590df2009-02-15 03:34:15 +0000751/* Receive a CHANGE_ADM_STATE_ACK, parse the TLV and update local state */
752static int abis_nm_rx_chg_adm_state_ack(struct msgb *mb)
753{
754 struct abis_om_hdr *oh = msgb_l2(mb);
755 struct abis_om_fom_hdr *foh = msgb_l3(mb);
756 struct tlv_parsed tp;
757 u_int8_t adm_state;
758
Harald Welte03133942009-02-18 19:51:53 +0000759 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Weltee0590df2009-02-15 03:34:15 +0000760 if (!TLVP_PRESENT(&tp, NM_ATT_ADM_STATE))
761 return -EINVAL;
762
763 adm_state = *TLVP_VAL(&tp, NM_ATT_ADM_STATE);
764
765 return update_admstate(mb->trx->bts, foh->obj_class, &foh->obj_inst, adm_state);
766}
767
Harald Welteee670472009-02-22 21:58:49 +0000768static int abis_nm_rx_lmt_event(struct msgb *mb)
769{
770 struct abis_om_hdr *oh = msgb_l2(mb);
771 struct abis_om_fom_hdr *foh = msgb_l3(mb);
772 struct tlv_parsed tp;
773
774 DEBUGP(DNM, "LMT Event ");
775 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
776 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_LOGON_SESSION) &&
777 TLVP_LEN(&tp, NM_ATT_BS11_LMT_LOGON_SESSION) >= 1) {
778 u_int8_t onoff = *TLVP_VAL(&tp, NM_ATT_BS11_LMT_LOGON_SESSION);
779 DEBUGPC(DNM, "LOG%s ", onoff ? "ON" : "OFF");
780 }
781 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV) &&
782 TLVP_LEN(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV) >= 1) {
783 u_int8_t level = *TLVP_VAL(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV);
784 DEBUGPC(DNM, "Level=%u ", level);
785 }
786 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_USER_NAME) &&
787 TLVP_LEN(&tp, NM_ATT_BS11_LMT_USER_NAME) >= 1) {
788 char *name = (char *) TLVP_VAL(&tp, NM_ATT_BS11_LMT_USER_NAME);
789 DEBUGPC(DNM, "Username=%s ", name);
790 }
791 DEBUGPC(DNM, "\n");
792 /* FIXME: parse LMT LOGON TIME */
793 return 0;
794}
795
Harald Welte52b1f982008-12-23 20:25:15 +0000796/* Receive a OML NM Message from BTS */
Harald Welte8470bf22008-12-25 23:28:35 +0000797static int abis_nm_rcvmsg_fom(struct msgb *mb)
Harald Welte52b1f982008-12-23 20:25:15 +0000798{
Harald Welte6c96ba52009-05-01 13:03:40 +0000799 struct abis_om_hdr *oh = msgb_l2(mb);
Harald Welte52b1f982008-12-23 20:25:15 +0000800 struct abis_om_fom_hdr *foh = msgb_l3(mb);
801 u_int8_t mt = foh->msg_type;
802
803 /* check for unsolicited message */
Harald Welte97ed1e72009-02-06 13:38:02 +0000804 if (is_report(mt))
805 return abis_nm_rcvmsg_report(mb);
Harald Welte52b1f982008-12-23 20:25:15 +0000806
Harald Welte4724f992009-01-18 18:01:49 +0000807 if (is_in_arr(mt, sw_load_msgs, ARRAY_SIZE(sw_load_msgs)))
808 return abis_nm_rcvmsg_sw(mb);
809
Harald Welte78fc0d42009-02-19 02:50:57 +0000810 if (is_in_arr(mt, nacks, ARRAY_SIZE(nacks))) {
Harald Welte6c96ba52009-05-01 13:03:40 +0000811 struct tlv_parsed tp;
Harald Welte78fc0d42009-02-19 02:50:57 +0000812 if (nack_names[mt])
Harald Welte6c96ba52009-05-01 13:03:40 +0000813 DEBUGP(DNM, "%s NACK ", nack_names[mt]);
814 /* FIXME: NACK cause */
Harald Welte78fc0d42009-02-19 02:50:57 +0000815 else
Harald Welte6c96ba52009-05-01 13:03:40 +0000816 DEBUGP(DNM, "NACK 0x%02x ", mt);
817
818 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
819 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
820 DEBUGPC(DNM, "CAUSE=%s\n",
821 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
822 else
823 DEBUGPC(DNM, "\n");
Harald Welte78fc0d42009-02-19 02:50:57 +0000824 }
Harald Weltead384642008-12-26 10:20:07 +0000825#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000826 /* check if last message is to be acked */
827 if (is_ack_nack(nmh->last_msgtype)) {
828 if (mt == MT_ACK(nmh->last_msgtype)) {
829 fprintf(stderr, "received ACK (0x%x)\n",
830 foh->msg_type);
831 /* we got our ACK, continue sending the next msg */
832 } else if (mt == MT_NACK(nmh->last_msgtype)) {
833 /* we got a NACK, signal this to the caller */
834 fprintf(stderr, "received NACK (0x%x)\n",
835 foh->msg_type);
836 /* FIXME: somehow signal this to the caller */
837 } else {
838 /* really strange things happen */
839 return -EINVAL;
840 }
841 }
Harald Weltead384642008-12-26 10:20:07 +0000842#endif
843
Harald Welte97ed1e72009-02-06 13:38:02 +0000844 switch (mt) {
Harald Weltee0590df2009-02-15 03:34:15 +0000845 case NM_MT_CHG_ADM_STATE_ACK:
846 return abis_nm_rx_chg_adm_state_ack(mb);
847 break;
Harald Welte34a99682009-02-13 02:41:40 +0000848 case NM_MT_SW_ACT_REQ:
849 return abis_nm_rx_sw_act_req(mb);
850 break;
Harald Welte97ed1e72009-02-06 13:38:02 +0000851 case NM_MT_BS11_LMT_SESSION:
Harald Welteee670472009-02-22 21:58:49 +0000852 return abis_nm_rx_lmt_event(mb);
Harald Welte97ed1e72009-02-06 13:38:02 +0000853 break;
854 }
855
Harald Weltead384642008-12-26 10:20:07 +0000856 return 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000857}
858
Harald Welte677c21f2009-02-17 13:22:23 +0000859static int abis_nm_rx_ipacc(struct msgb *mb);
860
861static int abis_nm_rcvmsg_manuf(struct msgb *mb)
862{
863 int rc;
864 int bts_type = mb->trx->bts->type;
865
866 switch (bts_type) {
867 case GSM_BTS_TYPE_NANOBTS_900:
868 case GSM_BTS_TYPE_NANOBTS_1800:
869 rc = abis_nm_rx_ipacc(mb);
870 break;
871 default:
872 fprintf(stderr, "don't know how to parse OML for this "
873 "BTS type (%u)\n", bts_type);
874 rc = 0;
875 break;
876 }
877
878 return rc;
879}
880
Harald Welte52b1f982008-12-23 20:25:15 +0000881/* High-Level API */
882/* Entry-point where L2 OML from BTS enters the NM code */
Harald Welte8470bf22008-12-25 23:28:35 +0000883int abis_nm_rcvmsg(struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +0000884{
Harald Welte52b1f982008-12-23 20:25:15 +0000885 struct abis_om_hdr *oh = msgb_l2(msg);
Harald Welte677c21f2009-02-17 13:22:23 +0000886 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000887
888 /* Various consistency checks */
889 if (oh->placement != ABIS_OM_PLACEMENT_ONLY) {
890 fprintf(stderr, "ABIS OML placement 0x%x not supported\n",
891 oh->placement);
892 return -EINVAL;
893 }
894 if (oh->sequence != 0) {
895 fprintf(stderr, "ABIS OML sequence 0x%x != 0x00\n",
896 oh->sequence);
897 return -EINVAL;
898 }
Harald Welte702d8702008-12-26 20:25:35 +0000899#if 0
Holger Freytherca362a62009-01-04 21:05:01 +0000900 unsigned int l2_len = msg->tail - (u_int8_t *)msgb_l2(msg);
901 unsigned int hlen = sizeof(*oh) + sizeof(struct abis_om_fom_hdr);
Harald Welte702d8702008-12-26 20:25:35 +0000902 if (oh->length + hlen > l2_len) {
Harald Welte52b1f982008-12-23 20:25:15 +0000903 fprintf(stderr, "ABIS OML truncated message (%u > %u)\n",
904 oh->length + sizeof(*oh), l2_len);
905 return -EINVAL;
906 }
Harald Welte702d8702008-12-26 20:25:35 +0000907 if (oh->length + hlen < l2_len)
908 fprintf(stderr, "ABIS OML message with extra trailer?!? (oh->len=%d, sizeof_oh=%d l2_len=%d\n", oh->length, sizeof(*oh), l2_len);
909#endif
Harald Weltead384642008-12-26 10:20:07 +0000910 msg->l3h = (unsigned char *)oh + sizeof(*oh);
Harald Welte52b1f982008-12-23 20:25:15 +0000911
912 switch (oh->mdisc) {
913 case ABIS_OM_MDISC_FOM:
Harald Welte8470bf22008-12-25 23:28:35 +0000914 rc = abis_nm_rcvmsg_fom(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000915 break;
Harald Welte677c21f2009-02-17 13:22:23 +0000916 case ABIS_OM_MDISC_MANUF:
917 rc = abis_nm_rcvmsg_manuf(msg);
918 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000919 case ABIS_OM_MDISC_MMI:
920 case ABIS_OM_MDISC_TRAU:
Harald Welte677c21f2009-02-17 13:22:23 +0000921 fprintf(stderr, "unimplemented ABIS OML message discriminator 0x%x\n",
922 oh->mdisc);
923 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000924 default:
925 fprintf(stderr, "unknown ABIS OML message discriminator 0x%x\n",
926 oh->mdisc);
927 return -EINVAL;
928 }
929
Harald Weltead384642008-12-26 10:20:07 +0000930 msgb_free(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000931 return rc;
932}
933
934#if 0
935/* initialized all resources */
936struct abis_nm_h *abis_nm_init(struct abis_nm_cfg *cfg)
937{
938 struct abis_nm_h *nmh;
939
940 nmh = malloc(sizeof(*nmh));
941 if (!nmh)
942 return NULL;
943
944 nmh->cfg = cfg;
945
946 return nmh;
947}
948
949/* free all resources */
950void abis_nm_fini(struct abis_nm_h *nmh)
951{
952 free(nmh);
953}
954#endif
955
956/* Here we are trying to define a high-level API that can be used by
957 * the actual BSC implementation. However, the architecture is currently
958 * still under design. Ideally the calls to this API would be synchronous,
959 * while the underlying stack behind the APi runs in a traditional select
960 * based state machine.
961 */
962
Harald Welte4724f992009-01-18 18:01:49 +0000963/* 6.2 Software Load: */
964enum sw_state {
965 SW_STATE_NONE,
966 SW_STATE_WAIT_INITACK,
967 SW_STATE_WAIT_SEGACK,
968 SW_STATE_WAIT_ENDACK,
969 SW_STATE_WAIT_ACTACK,
970 SW_STATE_ERROR,
971};
Harald Welte52b1f982008-12-23 20:25:15 +0000972
Harald Welte52b1f982008-12-23 20:25:15 +0000973struct abis_nm_sw {
Harald Welte4724f992009-01-18 18:01:49 +0000974 struct gsm_bts *bts;
Harald Welte5e4d1b32009-02-01 13:36:56 +0000975 gsm_cbfn *cbfn;
976 void *cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +0000977 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +0000978
Harald Welte52b1f982008-12-23 20:25:15 +0000979 /* this will become part of the SW LOAD INITIATE */
980 u_int8_t obj_class;
981 u_int8_t obj_instance[3];
Harald Welte4724f992009-01-18 18:01:49 +0000982
983 u_int8_t file_id[255];
984 u_int8_t file_id_len;
985
986 u_int8_t file_version[255];
987 u_int8_t file_version_len;
988
989 u_int8_t window_size;
990 u_int8_t seg_in_window;
991
992 int fd;
993 FILE *stream;
994 enum sw_state state;
Harald Welte1602ade2009-01-29 21:12:39 +0000995 int last_seg;
Harald Welte52b1f982008-12-23 20:25:15 +0000996};
997
Harald Welte4724f992009-01-18 18:01:49 +0000998static struct abis_nm_sw g_sw;
999
1000/* 6.2.1 / 8.3.1: Load Data Initiate */
1001static int sw_load_init(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +00001002{
Harald Welte4724f992009-01-18 18:01:49 +00001003 struct abis_om_hdr *oh;
1004 struct msgb *msg = nm_msgb_alloc();
1005 u_int8_t len = 3*2 + sw->file_id_len + sw->file_version_len;
1006
1007 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1008 fill_om_fom_hdr(oh, len, NM_MT_LOAD_INIT, sw->obj_class,
1009 sw->obj_instance[0], sw->obj_instance[1],
1010 sw->obj_instance[2]);
1011
1012 /* FIXME: this is BS11 specific format */
1013 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1014 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1015 sw->file_version);
1016 msgb_tv_put(msg, NM_ATT_WINDOW_SIZE, sw->window_size);
1017
1018 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001019}
1020
Harald Welte1602ade2009-01-29 21:12:39 +00001021static int is_last_line(FILE *stream)
1022{
1023 char next_seg_buf[256];
1024 long pos;
1025
1026 /* check if we're sending the last line */
1027 pos = ftell(stream);
1028 if (!fgets(next_seg_buf, sizeof(next_seg_buf)-2, stream)) {
1029 fseek(stream, pos, SEEK_SET);
1030 return 1;
1031 }
1032
1033 fseek(stream, pos, SEEK_SET);
1034 return 0;
1035}
1036
Harald Welte4724f992009-01-18 18:01:49 +00001037/* 6.2.2 / 8.3.2 Load Data Segment */
1038static int sw_load_segment(struct abis_nm_sw *sw)
1039{
1040 struct abis_om_hdr *oh;
1041 struct msgb *msg = nm_msgb_alloc();
1042 char seg_buf[256];
1043 char *line_buf = seg_buf+2;
Harald Welte3b8ba212009-01-29 12:27:58 +00001044 unsigned char *tlv;
Harald Welte4724f992009-01-18 18:01:49 +00001045 u_int8_t len;
Harald Welte4724f992009-01-18 18:01:49 +00001046
1047 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte3b8ba212009-01-29 12:27:58 +00001048
1049 switch (sw->bts->type) {
1050 case GSM_BTS_TYPE_BS11:
1051 if (fgets(line_buf, sizeof(seg_buf)-2, sw->stream) == NULL) {
1052 perror("fgets reading segment");
1053 return -EINVAL;
1054 }
1055 seg_buf[0] = 0x00;
Harald Welte1602ade2009-01-29 21:12:39 +00001056
1057 /* check if we're sending the last line */
1058 sw->last_seg = is_last_line(sw->stream);
1059 if (sw->last_seg)
1060 seg_buf[1] = 0;
1061 else
1062 seg_buf[1] = 1 + sw->seg_in_window++;
Harald Welte3b8ba212009-01-29 12:27:58 +00001063
1064 len = strlen(line_buf) + 2;
1065 tlv = msgb_put(msg, TLV_GROSS_LEN(len));
1066 tlv_put(tlv, NM_ATT_BS11_FILE_DATA, len, (u_int8_t *)seg_buf);
1067 /* BS11 wants CR + LF in excess of the TLV length !?! */
1068 tlv[1] -= 2;
1069
1070 /* we only now know the exact length for the OM hdr */
1071 len = strlen(line_buf)+2;
1072 break;
1073 default:
1074 /* FIXME: Other BTS types */
1075 return -1;
Harald Welte4724f992009-01-18 18:01:49 +00001076 }
Harald Welte4724f992009-01-18 18:01:49 +00001077
Harald Welte4724f992009-01-18 18:01:49 +00001078 fill_om_fom_hdr(oh, len, NM_MT_LOAD_SEG, sw->obj_class,
1079 sw->obj_instance[0], sw->obj_instance[1],
1080 sw->obj_instance[2]);
1081
1082 return abis_nm_sendmsg(sw->bts, msg);
1083}
1084
1085/* 6.2.4 / 8.3.4 Load Data End */
1086static int sw_load_end(struct abis_nm_sw *sw)
1087{
1088 struct abis_om_hdr *oh;
1089 struct msgb *msg = nm_msgb_alloc();
1090 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
1091
1092 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1093 fill_om_fom_hdr(oh, len, NM_MT_LOAD_END, sw->obj_class,
1094 sw->obj_instance[0], sw->obj_instance[1],
1095 sw->obj_instance[2]);
1096
1097 /* FIXME: this is BS11 specific format */
1098 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1099 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1100 sw->file_version);
1101
1102 return abis_nm_sendmsg(sw->bts, msg);
1103}
Harald Welte5e4d1b32009-02-01 13:36:56 +00001104
Harald Welte52b1f982008-12-23 20:25:15 +00001105/* Activate the specified software into the BTS */
Harald Welte4724f992009-01-18 18:01:49 +00001106static int sw_activate(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +00001107{
Harald Welte4724f992009-01-18 18:01:49 +00001108 struct abis_om_hdr *oh;
1109 struct msgb *msg = nm_msgb_alloc();
1110 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
Harald Welte52b1f982008-12-23 20:25:15 +00001111
Harald Welte4724f992009-01-18 18:01:49 +00001112 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1113 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, sw->obj_class,
1114 sw->obj_instance[0], sw->obj_instance[1],
1115 sw->obj_instance[2]);
1116
1117 /* FIXME: this is BS11 specific format */
1118 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1119 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1120 sw->file_version);
1121
1122 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001123}
Harald Welte4724f992009-01-18 18:01:49 +00001124
1125static int sw_open_file(struct abis_nm_sw *sw, const char *fname)
1126{
1127 char file_id[12+1];
1128 char file_version[80+1];
1129 int rc;
1130
1131 sw->fd = open(fname, O_RDONLY);
1132 if (sw->fd < 0)
1133 return sw->fd;
1134
1135 switch (sw->bts->type) {
1136 case GSM_BTS_TYPE_BS11:
1137 sw->stream = fdopen(sw->fd, "r");
1138 if (!sw->stream) {
1139 perror("fdopen");
1140 return -1;
1141 }
1142 /* read first line and parse file ID and VERSION */
Harald Welte3b8ba212009-01-29 12:27:58 +00001143 rc = fscanf(sw->stream, "@(#)%12s:%80s\r\n",
Harald Welte4724f992009-01-18 18:01:49 +00001144 file_id, file_version);
1145 if (rc != 2) {
1146 perror("parsing header line of software file");
1147 return -1;
1148 }
1149 strcpy((char *)sw->file_id, file_id);
1150 sw->file_id_len = strlen(file_id);
1151 strcpy((char *)sw->file_version, file_version);
1152 sw->file_version_len = strlen(file_version);
1153 /* rewind to start of file */
Harald Welte3b8ba212009-01-29 12:27:58 +00001154 rewind(sw->stream);
Harald Welte4724f992009-01-18 18:01:49 +00001155 break;
1156 default:
1157 /* We don't know how to treat them yet */
1158 close(sw->fd);
1159 return -EINVAL;
1160 }
1161
1162 return 0;
1163}
1164
1165static void sw_close_file(struct abis_nm_sw *sw)
1166{
1167 switch (sw->bts->type) {
1168 case GSM_BTS_TYPE_BS11:
1169 fclose(sw->stream);
1170 break;
1171 default:
1172 close(sw->fd);
1173 break;
1174 }
1175}
1176
1177/* Fill the window */
1178static int sw_fill_window(struct abis_nm_sw *sw)
1179{
1180 int rc;
1181
1182 while (sw->seg_in_window < sw->window_size) {
1183 rc = sw_load_segment(sw);
1184 if (rc < 0)
1185 return rc;
Harald Welte1602ade2009-01-29 21:12:39 +00001186 if (sw->last_seg)
1187 break;
Harald Welte4724f992009-01-18 18:01:49 +00001188 }
1189 return 0;
1190}
1191
1192/* callback function from abis_nm_rcvmsg() handler */
1193static int abis_nm_rcvmsg_sw(struct msgb *mb)
1194{
1195 struct abis_om_fom_hdr *foh = msgb_l3(mb);
1196 int rc = -1;
1197 struct abis_nm_sw *sw = &g_sw;
1198 enum sw_state old_state = sw->state;
1199
Harald Welte3ffd1372009-02-01 22:15:49 +00001200 //DEBUGP(DNM, "state %u, NM MT 0x%02x\n", sw->state, foh->msg_type);
Harald Welte4724f992009-01-18 18:01:49 +00001201
1202 switch (sw->state) {
1203 case SW_STATE_WAIT_INITACK:
1204 switch (foh->msg_type) {
1205 case NM_MT_LOAD_INIT_ACK:
1206 /* fill window with segments */
Harald Welte5e4d1b32009-02-01 13:36:56 +00001207 if (sw->cbfn)
1208 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1209 NM_MT_LOAD_INIT_ACK, mb,
1210 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001211 rc = sw_fill_window(sw);
1212 sw->state = SW_STATE_WAIT_SEGACK;
1213 break;
1214 case NM_MT_LOAD_INIT_NACK:
Harald Welte3ffd1372009-02-01 22:15:49 +00001215 if (sw->forced) {
1216 DEBUGP(DNM, "FORCED: Ignoring Software Load "
1217 "Init NACK\n");
1218 if (sw->cbfn)
1219 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1220 NM_MT_LOAD_INIT_ACK, mb,
1221 sw->cb_data, NULL);
1222 rc = sw_fill_window(sw);
1223 sw->state = SW_STATE_WAIT_SEGACK;
1224 } else {
1225 DEBUGP(DNM, "Software Load Init NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001226 /* FIXME: cause */
Harald Welte3ffd1372009-02-01 22:15:49 +00001227 if (sw->cbfn)
1228 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1229 NM_MT_LOAD_INIT_NACK, mb,
1230 sw->cb_data, NULL);
1231 sw->state = SW_STATE_ERROR;
1232 }
Harald Welte4724f992009-01-18 18:01:49 +00001233 break;
1234 }
1235 break;
1236 case SW_STATE_WAIT_SEGACK:
1237 switch (foh->msg_type) {
1238 case NM_MT_LOAD_SEG_ACK:
Harald Welte3ffd1372009-02-01 22:15:49 +00001239 if (sw->cbfn)
1240 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1241 NM_MT_LOAD_SEG_ACK, mb,
1242 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001243 sw->seg_in_window = 0;
Harald Welte1602ade2009-01-29 21:12:39 +00001244 if (!sw->last_seg) {
1245 /* fill window with more segments */
1246 rc = sw_fill_window(sw);
1247 sw->state = SW_STATE_WAIT_SEGACK;
1248 } else {
1249 /* end the transfer */
1250 sw->state = SW_STATE_WAIT_ENDACK;
1251 rc = sw_load_end(sw);
1252 }
Harald Welte4724f992009-01-18 18:01:49 +00001253 break;
1254 }
1255 break;
1256 case SW_STATE_WAIT_ENDACK:
1257 switch (foh->msg_type) {
1258 case NM_MT_LOAD_END_ACK:
1259 sw_close_file(sw);
Harald Welte5e4d1b32009-02-01 13:36:56 +00001260 DEBUGP(DNM, "Software Load End (BTS %u)\n",
1261 sw->bts->nr);
1262 sw->state = SW_STATE_NONE;
1263 if (sw->cbfn)
1264 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1265 NM_MT_LOAD_END_ACK, mb,
1266 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001267 break;
1268 case NM_MT_LOAD_END_NACK:
Holger Freyther31338a12009-02-06 17:43:50 +00001269 if (sw->forced) {
1270 DEBUGP(DNM, "FORCED: Ignoring Software Load"
1271 "End NACK\n");
1272 sw->state = SW_STATE_NONE;
1273 if (sw->cbfn)
1274 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1275 NM_MT_LOAD_END_ACK, mb,
1276 sw->cb_data, NULL);
1277 } else {
1278 DEBUGP(DNM, "Software Load End NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001279 /* FIXME: cause */
Holger Freyther31338a12009-02-06 17:43:50 +00001280 sw->state = SW_STATE_ERROR;
1281 if (sw->cbfn)
1282 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1283 NM_MT_LOAD_END_NACK, mb,
1284 sw->cb_data, NULL);
1285 }
Harald Welte4724f992009-01-18 18:01:49 +00001286 break;
1287 }
1288 case SW_STATE_WAIT_ACTACK:
1289 switch (foh->msg_type) {
1290 case NM_MT_ACTIVATE_SW_ACK:
1291 /* we're done */
Harald Welte5e4d1b32009-02-01 13:36:56 +00001292 DEBUGP(DNM, "Activate Software DONE!\n");
Harald Welte4724f992009-01-18 18:01:49 +00001293 sw->state = SW_STATE_NONE;
1294 rc = 0;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001295 if (sw->cbfn)
1296 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1297 NM_MT_ACTIVATE_SW_ACK, mb,
1298 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001299 break;
1300 case NM_MT_ACTIVATE_SW_NACK:
Harald Welte1602ade2009-01-29 21:12:39 +00001301 DEBUGP(DNM, "Activate Software NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001302 /* FIXME: cause */
Harald Welte4724f992009-01-18 18:01:49 +00001303 sw->state = SW_STATE_ERROR;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001304 if (sw->cbfn)
1305 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1306 NM_MT_ACTIVATE_SW_NACK, mb,
1307 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001308 break;
1309 }
1310 case SW_STATE_NONE:
Harald Weltea994a482009-05-01 15:54:23 +00001311 switch (foh->msg_type) {
1312 case NM_MT_ACTIVATE_SW_ACK:
1313 rc = 0;
1314 break;
1315 }
1316 break;
Harald Welte4724f992009-01-18 18:01:49 +00001317 case SW_STATE_ERROR:
1318 break;
1319 }
1320
1321 if (rc)
Harald Weltea994a482009-05-01 15:54:23 +00001322 DEBUGP(DNM, "unexpected NM MT 0x%02x in state %u -> %u\n",
Harald Welte4724f992009-01-18 18:01:49 +00001323 foh->msg_type, old_state, sw->state);
1324
1325 return rc;
1326}
1327
1328/* Load the specified software into the BTS */
1329int abis_nm_software_load(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00001330 u_int8_t win_size, int forced,
1331 gsm_cbfn *cbfn, void *cb_data)
Harald Welte4724f992009-01-18 18:01:49 +00001332{
1333 struct abis_nm_sw *sw = &g_sw;
1334 int rc;
1335
Harald Welte5e4d1b32009-02-01 13:36:56 +00001336 DEBUGP(DNM, "Software Load (BTS %u, File \"%s\")\n",
1337 bts->nr, fname);
1338
Harald Welte4724f992009-01-18 18:01:49 +00001339 if (sw->state != SW_STATE_NONE)
1340 return -EBUSY;
1341
1342 sw->bts = bts;
1343 sw->obj_class = NM_OC_SITE_MANAGER;
1344 sw->obj_instance[0] = 0xff;
1345 sw->obj_instance[1] = 0xff;
1346 sw->obj_instance[2] = 0xff;
1347 sw->window_size = win_size;
1348 sw->state = SW_STATE_WAIT_INITACK;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001349 sw->cbfn = cbfn;
1350 sw->cb_data = cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +00001351 sw->forced = forced;
Harald Welte4724f992009-01-18 18:01:49 +00001352
1353 rc = sw_open_file(sw, fname);
1354 if (rc < 0) {
1355 sw->state = SW_STATE_NONE;
1356 return rc;
1357 }
1358
1359 return sw_load_init(sw);
1360}
Harald Welte52b1f982008-12-23 20:25:15 +00001361
Harald Welte1602ade2009-01-29 21:12:39 +00001362int abis_nm_software_load_status(struct gsm_bts *bts)
1363{
1364 struct abis_nm_sw *sw = &g_sw;
1365 struct stat st;
1366 int rc, percent;
1367
1368 rc = fstat(sw->fd, &st);
1369 if (rc < 0) {
1370 perror("ERROR during stat");
1371 return rc;
1372 }
1373
1374 percent = (ftell(sw->stream) * 100) / st.st_size;
1375 return percent;
1376}
1377
Harald Welte5e4d1b32009-02-01 13:36:56 +00001378/* Activate the specified software into the BTS */
1379int abis_nm_software_activate(struct gsm_bts *bts, const char *fname,
1380 gsm_cbfn *cbfn, void *cb_data)
1381{
1382 struct abis_nm_sw *sw = &g_sw;
1383 int rc;
1384
1385 DEBUGP(DNM, "Activating Software (BTS %u, File \"%s\")\n",
1386 bts->nr, fname);
1387
1388 if (sw->state != SW_STATE_NONE)
1389 return -EBUSY;
1390
1391 sw->bts = bts;
1392 sw->obj_class = NM_OC_SITE_MANAGER;
1393 sw->obj_instance[0] = 0xff;
1394 sw->obj_instance[1] = 0xff;
1395 sw->obj_instance[2] = 0xff;
1396 sw->state = SW_STATE_WAIT_ACTACK;
1397 sw->cbfn = cbfn;
1398 sw->cb_data = cb_data;
1399
1400 /* Open the file in order to fill some sw struct members */
1401 rc = sw_open_file(sw, fname);
1402 if (rc < 0) {
1403 sw->state = SW_STATE_NONE;
1404 return rc;
1405 }
1406 sw_close_file(sw);
1407
1408 return sw_activate(sw);
1409}
1410
Harald Welte8470bf22008-12-25 23:28:35 +00001411static void fill_nm_channel(struct abis_nm_channel *ch, u_int8_t bts_port,
Harald Welte52b1f982008-12-23 20:25:15 +00001412 u_int8_t ts_nr, u_int8_t subslot_nr)
1413{
Harald Welteadaf08b2009-01-18 11:08:10 +00001414 ch->attrib = NM_ATT_ABIS_CHANNEL;
Harald Welte52b1f982008-12-23 20:25:15 +00001415 ch->bts_port = bts_port;
1416 ch->timeslot = ts_nr;
1417 ch->subslot = subslot_nr;
1418}
1419
1420int abis_nm_establish_tei(struct gsm_bts *bts, u_int8_t trx_nr,
1421 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot,
1422 u_int8_t tei)
1423{
1424 struct abis_om_hdr *oh;
1425 struct abis_nm_channel *ch;
Harald Welte702d8702008-12-26 20:25:35 +00001426 u_int8_t len = sizeof(*ch) + 2;
Harald Welte8470bf22008-12-25 23:28:35 +00001427 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001428
1429 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1430 fill_om_fom_hdr(oh, len, NM_MT_ESTABLISH_TEI, NM_OC_RADIO_CARRIER,
1431 bts->bts_nr, trx_nr, 0xff);
1432
Harald Welte8470bf22008-12-25 23:28:35 +00001433 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte52b1f982008-12-23 20:25:15 +00001434
1435 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1436 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1437
1438 return abis_nm_sendmsg(bts, msg);
1439}
1440
1441/* connect signalling of one (BTS,TRX) to a particular timeslot on the E1 */
1442int abis_nm_conn_terr_sign(struct gsm_bts_trx *trx,
1443 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot)
1444{
Harald Welte8470bf22008-12-25 23:28:35 +00001445 struct gsm_bts *bts = trx->bts;
Harald Welte52b1f982008-12-23 20:25:15 +00001446 struct abis_om_hdr *oh;
1447 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +00001448 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001449
1450 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001451 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_SIGN,
Harald Welte52b1f982008-12-23 20:25:15 +00001452 NM_OC_RADIO_CARRIER, bts->bts_nr, trx->nr, 0xff);
1453
1454 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1455 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1456
1457 return abis_nm_sendmsg(bts, msg);
1458}
1459
1460#if 0
1461int abis_nm_disc_terr_sign(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1462 struct abis_nm_abis_channel *chan)
1463{
1464}
1465#endif
1466
1467int abis_nm_conn_terr_traf(struct gsm_bts_trx_ts *ts,
1468 u_int8_t e1_port, u_int8_t e1_timeslot,
1469 u_int8_t e1_subslot)
1470{
1471 struct gsm_bts *bts = ts->trx->bts;
1472 struct abis_om_hdr *oh;
1473 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +00001474 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001475
1476 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1477 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_TRAF,
Harald Welteb110cee2009-02-18 03:42:35 +00001478 NM_OC_CHANNEL, bts->bts_nr, ts->trx->nr, ts->nr);
Harald Welte52b1f982008-12-23 20:25:15 +00001479
1480 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1481 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1482
Harald Weltef325eb42009-02-19 17:07:39 +00001483 DEBUGP(DNM, "CONNECT TERR TRAF Um=%s E1=(%u,%u,%u)\n",
1484 gsm_ts_name(ts),
Harald Welteb110cee2009-02-18 03:42:35 +00001485 e1_port, e1_timeslot, e1_subslot);
1486
Harald Welte52b1f982008-12-23 20:25:15 +00001487 return abis_nm_sendmsg(bts, msg);
1488}
1489
1490#if 0
1491int abis_nm_disc_terr_traf(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1492 struct abis_nm_abis_channel *chan,
1493 u_int8_t subchan)
1494{
1495}
1496#endif
1497
Harald Welte22af0db2009-02-14 15:41:08 +00001498/* Chapter 8.6.1 */
1499int abis_nm_set_bts_attr(struct gsm_bts *bts, u_int8_t *attr, int attr_len)
1500{
1501 struct abis_om_hdr *oh;
1502 struct msgb *msg = nm_msgb_alloc();
1503 u_int8_t *cur;
1504
1505 DEBUGP(DNM, "Set BTS Attr (bts=%d)\n", bts->nr);
1506
1507 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte191280d2009-05-01 13:20:04 +00001508 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 +00001509 cur = msgb_put(msg, attr_len);
1510 memcpy(cur, attr, attr_len);
1511
1512 return abis_nm_sendmsg(bts, msg);
1513}
1514
1515/* Chapter 8.6.2 */
1516int abis_nm_set_radio_attr(struct gsm_bts_trx *trx, u_int8_t *attr, int attr_len)
1517{
1518 struct abis_om_hdr *oh;
1519 struct msgb *msg = nm_msgb_alloc();
1520 u_int8_t *cur;
1521
1522 DEBUGP(DNM, "Set TRX Attr (bts=%d,trx=%d)\n", trx->bts->nr, trx->nr);
1523
1524 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1525 fill_om_fom_hdr(oh, attr_len, NM_MT_SET_RADIO_ATTR, NM_OC_RADIO_CARRIER,
Harald Welte191280d2009-05-01 13:20:04 +00001526 trx->bts->bts_nr, trx->nr, 0xff);
Harald Welte22af0db2009-02-14 15:41:08 +00001527 cur = msgb_put(msg, attr_len);
1528 memcpy(cur, attr, attr_len);
1529
1530 return abis_nm_sendmsg(trx->bts, msg);
1531}
1532
1533/* Chapter 8.6.3 */
Harald Welte52b1f982008-12-23 20:25:15 +00001534int abis_nm_set_channel_attr(struct gsm_bts_trx_ts *ts, u_int8_t chan_comb)
1535{
1536 struct gsm_bts *bts = ts->trx->bts;
1537 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001538 u_int16_t arfcn = htons(ts->trx->arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001539 u_int8_t zero = 0x00;
Harald Welte8470bf22008-12-25 23:28:35 +00001540 struct msgb *msg = nm_msgb_alloc();
Harald Weltee0590df2009-02-15 03:34:15 +00001541 u_int8_t len = 2 + 2;
1542
1543 if (bts->type == GSM_BTS_TYPE_BS11)
1544 len += 4 + 2 + 2 + 3;
Harald Welte52b1f982008-12-23 20:25:15 +00001545
Harald Weltef325eb42009-02-19 17:07:39 +00001546 DEBUGP(DNM, "Set Chan Attr %s\n", gsm_ts_name(ts));
Harald Welte22af0db2009-02-14 15:41:08 +00001547
Harald Welte52b1f982008-12-23 20:25:15 +00001548 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001549 fill_om_fom_hdr(oh, len, NM_MT_SET_CHAN_ATTR,
Holger Freyther6b2d2622009-02-14 23:16:59 +00001550 NM_OC_CHANNEL, bts->bts_nr,
Harald Welte52b1f982008-12-23 20:25:15 +00001551 ts->trx->nr, ts->nr);
1552 /* FIXME: don't send ARFCN list, hopping sequence, mAIO, ...*/
Harald Weltee0590df2009-02-15 03:34:15 +00001553 if (bts->type == GSM_BTS_TYPE_BS11)
1554 msgb_tlv16_put(msg, NM_ATT_ARFCN_LIST, 1, &arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001555 msgb_tv_put(msg, NM_ATT_CHAN_COMB, chan_comb);
Harald Weltee0590df2009-02-15 03:34:15 +00001556 if (bts->type == GSM_BTS_TYPE_BS11) {
1557 msgb_tv_put(msg, NM_ATT_HSN, 0x00);
1558 msgb_tv_put(msg, NM_ATT_MAIO, 0x00);
1559 }
Harald Welte52b1f982008-12-23 20:25:15 +00001560 msgb_tv_put(msg, NM_ATT_TSC, 0x07); /* training sequence */
Harald Weltee0590df2009-02-15 03:34:15 +00001561 if (bts->type == GSM_BTS_TYPE_BS11)
1562 msgb_tlv_put(msg, 0x59, 1, &zero);
Harald Welte52b1f982008-12-23 20:25:15 +00001563
1564 return abis_nm_sendmsg(bts, msg);
1565}
1566
Harald Welte34a99682009-02-13 02:41:40 +00001567int 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 +00001568 u_int8_t i2, u_int8_t i3, int nack, u_int8_t *attr, int att_len)
Harald Welte34a99682009-02-13 02:41:40 +00001569{
1570 struct abis_om_hdr *oh;
1571 struct msgb *msg = nm_msgb_alloc();
Harald Welte5c1e4582009-02-15 11:57:29 +00001572 u_int8_t msgtype = NM_MT_SW_ACT_REQ_ACK;
1573 u_int8_t len = att_len;
1574
1575 if (nack) {
1576 len += 2;
1577 msgtype = NM_MT_SW_ACT_REQ_NACK;
1578 }
Harald Welte34a99682009-02-13 02:41:40 +00001579
1580 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte5c1e4582009-02-15 11:57:29 +00001581 fill_om_fom_hdr(oh, att_len, msgtype, obj_class, i1, i2, i3);
1582
Harald Welte34a99682009-02-13 02:41:40 +00001583 if (attr) {
1584 u_int8_t *ptr = msgb_put(msg, att_len);
1585 memcpy(ptr, attr, att_len);
1586 }
Harald Welte5c1e4582009-02-15 11:57:29 +00001587 if (nack)
1588 msgb_tv_put(msg, NM_ATT_NACK_CAUSES, NM_NACK_OBJCLASS_NOTSUPP);
Harald Welte34a99682009-02-13 02:41:40 +00001589
1590 return abis_nm_sendmsg(bts, msg);
1591}
1592
Harald Welte8470bf22008-12-25 23:28:35 +00001593int abis_nm_raw_msg(struct gsm_bts *bts, int len, u_int8_t *rawmsg)
Harald Welte52b1f982008-12-23 20:25:15 +00001594{
Harald Welte8470bf22008-12-25 23:28:35 +00001595 struct msgb *msg = nm_msgb_alloc();
1596 struct abis_om_hdr *oh;
Harald Welte52b1f982008-12-23 20:25:15 +00001597 u_int8_t *data;
1598
1599 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
1600 fill_om_hdr(oh, len);
1601 data = msgb_put(msg, len);
Harald Weltead384642008-12-26 10:20:07 +00001602 memcpy(data, rawmsg, len);
Harald Welte52b1f982008-12-23 20:25:15 +00001603
1604 return abis_nm_sendmsg(bts, msg);
1605}
1606
1607/* Siemens specific commands */
1608static int __simple_cmd(struct gsm_bts *bts, u_int8_t msg_type)
1609{
1610 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001611 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001612
1613 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001614 fill_om_fom_hdr(oh, 0, msg_type, NM_OC_SITE_MANAGER,
Harald Welte52b1f982008-12-23 20:25:15 +00001615 0xff, 0xff, 0xff);
1616
1617 return abis_nm_sendmsg(bts, msg);
1618}
1619
Harald Welte34a99682009-02-13 02:41:40 +00001620/* Chapter 8.9.2 */
1621int abis_nm_opstart(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1, u_int8_t i2)
1622{
1623 struct abis_om_hdr *oh;
1624 struct msgb *msg = nm_msgb_alloc();
1625
Harald Welte22af0db2009-02-14 15:41:08 +00001626 DEBUGP(DNM, "Sending OPSTART obj_class=0x%02x obj_inst=(0x%02x, 0x%02x, 0x%02x)\n",
1627 obj_class, i0, i1, i2);
Harald Welte34a99682009-02-13 02:41:40 +00001628 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1629 fill_om_fom_hdr(oh, 0, NM_MT_OPSTART, obj_class, i0, i1, i2);
1630
1631 return abis_nm_sendmsg(bts, msg);
1632}
1633
1634/* Chapter 8.8.5 */
1635int abis_nm_chg_adm_state(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0,
1636 u_int8_t i1, u_int8_t i2, u_int8_t adm_state)
1637{
1638 struct abis_om_hdr *oh;
1639 struct msgb *msg = nm_msgb_alloc();
1640
1641 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1642 fill_om_fom_hdr(oh, 2, NM_MT_CHG_ADM_STATE, obj_class, i0, i1, i2);
1643 msgb_tv_put(msg, NM_ATT_ADM_STATE, adm_state);
1644
1645 return abis_nm_sendmsg(bts, msg);
1646}
1647
1648
Harald Welte52b1f982008-12-23 20:25:15 +00001649int abis_nm_event_reports(struct gsm_bts *bts, int on)
1650{
1651 if (on == 0)
Harald Welte227d4072009-01-03 08:16:25 +00001652 return __simple_cmd(bts, NM_MT_STOP_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001653 else
Harald Welte227d4072009-01-03 08:16:25 +00001654 return __simple_cmd(bts, NM_MT_REST_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001655}
1656
Harald Welte47d88ae2009-01-04 12:02:08 +00001657/* Siemens (or BS-11) specific commands */
1658
Harald Welte3ffd1372009-02-01 22:15:49 +00001659int abis_nm_bs11_bsc_disconnect(struct gsm_bts *bts, int reconnect)
1660{
1661 if (reconnect == 0)
1662 return __simple_cmd(bts, NM_MT_BS11_DISCONNECT);
1663 else
1664 return __simple_cmd(bts, NM_MT_BS11_RECONNECT);
1665}
1666
Harald Welteb8427972009-02-05 19:27:17 +00001667int abis_nm_bs11_restart(struct gsm_bts *bts)
1668{
1669 return __simple_cmd(bts, NM_MT_BS11_RESTART);
1670}
1671
1672
Harald Welte268bb402009-02-01 19:11:56 +00001673struct bs11_date_time {
1674 u_int16_t year;
1675 u_int8_t month;
1676 u_int8_t day;
1677 u_int8_t hour;
1678 u_int8_t min;
1679 u_int8_t sec;
1680} __attribute__((packed));
1681
1682
1683void get_bs11_date_time(struct bs11_date_time *aet)
1684{
1685 time_t t;
1686 struct tm *tm;
1687
1688 t = time(NULL);
1689 tm = localtime(&t);
1690 aet->sec = tm->tm_sec;
1691 aet->min = tm->tm_min;
1692 aet->hour = tm->tm_hour;
1693 aet->day = tm->tm_mday;
1694 aet->month = tm->tm_mon;
1695 aet->year = htons(1900 + tm->tm_year);
1696}
1697
Harald Welte05188ee2009-01-18 11:39:08 +00001698int abis_nm_bs11_reset_resource(struct gsm_bts *bts)
Harald Welte52b1f982008-12-23 20:25:15 +00001699{
Harald Welte4668fda2009-01-03 08:19:29 +00001700 return __simple_cmd(bts, NM_MT_BS11_RESET_RESOURCE);
Harald Welte52b1f982008-12-23 20:25:15 +00001701}
1702
Harald Welte05188ee2009-01-18 11:39:08 +00001703int abis_nm_bs11_db_transmission(struct gsm_bts *bts, int begin)
Harald Welte52b1f982008-12-23 20:25:15 +00001704{
1705 if (begin)
Harald Welte4668fda2009-01-03 08:19:29 +00001706 return __simple_cmd(bts, NM_MT_BS11_BEGIN_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00001707 else
Harald Welte4668fda2009-01-03 08:19:29 +00001708 return __simple_cmd(bts, NM_MT_BS11_END_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00001709}
Harald Welte47d88ae2009-01-04 12:02:08 +00001710
Harald Welte05188ee2009-01-18 11:39:08 +00001711int abis_nm_bs11_create_object(struct gsm_bts *bts,
Harald Welte1bc09062009-01-18 14:17:52 +00001712 enum abis_bs11_objtype type, u_int8_t idx,
1713 u_int8_t attr_len, const u_int8_t *attr)
Harald Welte47d88ae2009-01-04 12:02:08 +00001714{
1715 struct abis_om_hdr *oh;
1716 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00001717 u_int8_t *cur;
Harald Welte47d88ae2009-01-04 12:02:08 +00001718
1719 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001720 fill_om_fom_hdr(oh, attr_len, NM_MT_BS11_CREATE_OBJ,
Harald Welte268bb402009-02-01 19:11:56 +00001721 NM_OC_BS11, type, 0, idx);
Harald Welte1bc09062009-01-18 14:17:52 +00001722 cur = msgb_put(msg, attr_len);
1723 memcpy(cur, attr, attr_len);
Harald Welte47d88ae2009-01-04 12:02:08 +00001724
1725 return abis_nm_sendmsg(bts, msg);
1726}
1727
Harald Welte78fc0d42009-02-19 02:50:57 +00001728int abis_nm_bs11_delete_object(struct gsm_bts *bts,
1729 enum abis_bs11_objtype type, u_int8_t idx)
1730{
1731 struct abis_om_hdr *oh;
1732 struct msgb *msg = nm_msgb_alloc();
1733
1734 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1735 fill_om_fom_hdr(oh, 0, NM_MT_BS11_DELETE_OBJ,
1736 NM_OC_BS11, type, 0, idx);
1737
1738 return abis_nm_sendmsg(bts, msg);
1739}
1740
Harald Welte05188ee2009-01-18 11:39:08 +00001741int abis_nm_bs11_create_envaBTSE(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00001742{
1743 struct abis_om_hdr *oh;
1744 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00001745 u_int8_t zero = 0x00;
Harald Welte47d88ae2009-01-04 12:02:08 +00001746
1747 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001748 fill_om_fom_hdr(oh, 3, NM_MT_BS11_CREATE_OBJ,
Harald Welte1bc09062009-01-18 14:17:52 +00001749 NM_OC_BS11_ENVABTSE, 0, idx, 0xff);
1750 msgb_tlv_put(msg, 0x99, 1, &zero);
Harald Welte47d88ae2009-01-04 12:02:08 +00001751
1752 return abis_nm_sendmsg(bts, msg);
1753}
1754
Harald Welte05188ee2009-01-18 11:39:08 +00001755int abis_nm_bs11_create_bport(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00001756{
1757 struct abis_om_hdr *oh;
1758 struct msgb *msg = nm_msgb_alloc();
1759
1760 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1761 fill_om_fom_hdr(oh, 0, NM_MT_BS11_CREATE_OBJ, NM_OC_BS11_BPORT,
1762 idx, 0, 0);
1763
1764 return abis_nm_sendmsg(bts, msg);
1765}
Harald Welte05188ee2009-01-18 11:39:08 +00001766
Harald Welte78fc0d42009-02-19 02:50:57 +00001767static const u_int8_t sm_attr[] = { NM_ATT_TEI, NM_ATT_ABIS_CHANNEL };
1768int abis_nm_bs11_get_oml_tei_ts(struct gsm_bts *bts)
1769{
1770 struct abis_om_hdr *oh;
1771 struct msgb *msg = nm_msgb_alloc();
1772
1773 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1774 fill_om_fom_hdr(oh, 2+sizeof(sm_attr), NM_MT_GET_ATTR, NM_OC_SITE_MANAGER,
1775 0xff, 0xff, 0xff);
1776 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(sm_attr), sm_attr);
1777
1778 return abis_nm_sendmsg(bts, msg);
1779}
1780
Harald Welteb6c92ae2009-02-21 20:15:32 +00001781/* like abis_nm_conn_terr_traf + set_tei */
1782int abis_nm_bs11_conn_oml_tei(struct gsm_bts *bts, u_int8_t e1_port,
1783 u_int8_t e1_timeslot, u_int8_t e1_subslot,
1784 u_int8_t tei)
Harald Welte05188ee2009-01-18 11:39:08 +00001785{
1786 struct abis_om_hdr *oh;
1787 struct abis_nm_channel *ch;
1788 struct msgb *msg = nm_msgb_alloc();
1789
1790 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welteb6c92ae2009-02-21 20:15:32 +00001791 fill_om_fom_hdr(oh, sizeof(*ch)+2, NM_MT_BS11_SET_ATTR,
Harald Welte05188ee2009-01-18 11:39:08 +00001792 NM_OC_SITE_MANAGER, 0xff, 0xff, 0xff);
1793
1794 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1795 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
Harald Welteb6c92ae2009-02-21 20:15:32 +00001796 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte05188ee2009-01-18 11:39:08 +00001797
1798 return abis_nm_sendmsg(bts, msg);
1799}
1800
1801int abis_nm_bs11_set_trx_power(struct gsm_bts_trx *trx, u_int8_t level)
1802{
1803 struct abis_om_hdr *oh;
1804 struct msgb *msg = nm_msgb_alloc();
Harald Welte05188ee2009-01-18 11:39:08 +00001805
1806 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001807 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR,
Harald Welte05188ee2009-01-18 11:39:08 +00001808 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
1809 msgb_tlv_put(msg, NM_ATT_BS11_TXPWR, 1, &level);
1810
1811 return abis_nm_sendmsg(trx->bts, msg);
1812}
1813
Harald Welte78fc0d42009-02-19 02:50:57 +00001814int abis_nm_bs11_get_trx_power(struct gsm_bts_trx *trx)
1815{
1816 struct abis_om_hdr *oh;
1817 struct msgb *msg = nm_msgb_alloc();
1818 u_int8_t attr = NM_ATT_BS11_TXPWR;
1819
1820 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1821 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
1822 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
1823 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), &attr);
1824
1825 return abis_nm_sendmsg(trx->bts, msg);
1826}
1827
Harald Welteaaf02d92009-04-29 13:25:57 +00001828int abis_nm_bs11_get_pll_mode(struct gsm_bts *bts)
1829{
1830 struct abis_om_hdr *oh;
1831 struct msgb *msg = nm_msgb_alloc();
Harald Weltea7cfa032009-04-29 22:33:02 +00001832 u_int8_t attr[] = { NM_ATT_BS11_PLL_MODE };
Harald Welteaaf02d92009-04-29 13:25:57 +00001833
1834 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1835 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
1836 NM_OC_BS11, BS11_OBJ_LI, 0x00, 0x00);
Harald Welteaeedeb42009-05-01 13:08:14 +00001837 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), attr);
Harald Welteaaf02d92009-04-29 13:25:57 +00001838
1839 return abis_nm_sendmsg(bts, msg);
1840}
1841
Harald Welteef061952009-05-17 12:43:42 +00001842int abis_nm_bs11_get_cclk(struct gsm_bts *bts)
1843{
1844 struct abis_om_hdr *oh;
1845 struct msgb *msg = nm_msgb_alloc();
1846 u_int8_t attr[] = { NM_ATT_BS11_CCLK_ACCURACY,
1847 NM_ATT_BS11_CCLK_TYPE };
1848
1849 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1850 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
1851 NM_OC_BS11, BS11_OBJ_CCLK, 0x00, 0x00);
1852 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), attr);
1853
1854 return abis_nm_sendmsg(bts, msg);
1855
1856}
Harald Welteaaf02d92009-04-29 13:25:57 +00001857
Harald Welte268bb402009-02-01 19:11:56 +00001858//static const u_int8_t bs11_logon_c7[] = { 0x07, 0xd9, 0x01, 0x11, 0x0d, 0x10, 0x20 };
Harald Weltebb151312009-01-28 20:42:07 +00001859static const u_int8_t bs11_logon_c8[] = { 0x02 };
Harald Welte05188ee2009-01-18 11:39:08 +00001860static const u_int8_t bs11_logon_c9[] = "FACTORY";
1861
Harald Welte1bc09062009-01-18 14:17:52 +00001862int abis_nm_bs11_factory_logon(struct gsm_bts *bts, int on)
Harald Welte05188ee2009-01-18 11:39:08 +00001863{
1864 struct abis_om_hdr *oh;
1865 struct msgb *msg = nm_msgb_alloc();
Harald Welte268bb402009-02-01 19:11:56 +00001866 struct bs11_date_time bdt;
1867
1868 get_bs11_date_time(&bdt);
Harald Welte05188ee2009-01-18 11:39:08 +00001869
1870 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte1bc09062009-01-18 14:17:52 +00001871 if (on) {
Harald Welte268bb402009-02-01 19:11:56 +00001872 u_int8_t len = 3*2 + sizeof(bdt)
Harald Welte6f676a32009-01-18 14:27:48 +00001873 + sizeof(bs11_logon_c8) + sizeof(bs11_logon_c9);
Harald Welte043d04a2009-01-29 23:15:30 +00001874 fill_om_fom_hdr(oh, len, NM_MT_BS11_LMT_LOGON,
Harald Welte1bc09062009-01-18 14:17:52 +00001875 NM_OC_BS11_A3, 0xff, 0xff, 0xff);
Harald Welte043d04a2009-01-29 23:15:30 +00001876 msgb_tlv_put(msg, NM_ATT_BS11_LMT_LOGIN_TIME,
Harald Welte5083b0b2009-02-02 19:20:52 +00001877 sizeof(bdt), (u_int8_t *) &bdt);
Harald Welte043d04a2009-01-29 23:15:30 +00001878 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_ACC_LEV,
1879 sizeof(bs11_logon_c8), bs11_logon_c8);
1880 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_NAME,
1881 sizeof(bs11_logon_c9), bs11_logon_c9);
Harald Welte1bc09062009-01-18 14:17:52 +00001882 } else {
Harald Welte5e4d1b32009-02-01 13:36:56 +00001883 fill_om_fom_hdr(oh, 0, NM_MT_BS11_LMT_LOGOFF,
Harald Welte1bc09062009-01-18 14:17:52 +00001884 NM_OC_BS11_A3, 0xff, 0xff, 0xff);
1885 }
Harald Welte05188ee2009-01-18 11:39:08 +00001886
1887 return abis_nm_sendmsg(bts, msg);
1888}
Harald Welte1bc09062009-01-18 14:17:52 +00001889
1890int abis_nm_bs11_set_trx1_pw(struct gsm_bts *bts, const char *password)
1891{
1892 struct abis_om_hdr *oh;
1893 struct msgb *msg;
1894
1895 if (strlen(password) != 10)
1896 return -EINVAL;
1897
1898 msg = nm_msgb_alloc();
1899 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001900 fill_om_fom_hdr(oh, 2+strlen(password), NM_MT_BS11_SET_ATTR,
Harald Welte1bc09062009-01-18 14:17:52 +00001901 NM_OC_BS11, BS11_OBJ_TRX1, 0x00, 0x00);
1902 msgb_tlv_put(msg, NM_ATT_BS11_PASSWORD, 10, (const u_int8_t *)password);
1903
1904 return abis_nm_sendmsg(bts, msg);
1905}
1906
Harald Weltee69f5fb2009-04-28 16:31:38 +00001907/* change the BS-11 PLL Mode to either locked (E1 derived) or standalone */
1908int abis_nm_bs11_set_pll_locked(struct gsm_bts *bts, int locked)
1909{
1910 struct abis_om_hdr *oh;
1911 struct msgb *msg;
Harald Weltea432cd32009-04-29 13:01:50 +00001912 u_int8_t tlv_value;
Harald Weltee69f5fb2009-04-28 16:31:38 +00001913
1914 msg = nm_msgb_alloc();
1915 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1916 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR, NM_OC_BS11,
1917 BS11_OBJ_LI, 0x00, 0x00);
Harald Weltea432cd32009-04-29 13:01:50 +00001918
1919 if (locked)
1920 tlv_value = BS11_LI_PLL_LOCKED;
1921 else
1922 tlv_value = BS11_LI_PLL_STANDALONE;
1923
1924 msgb_tlv_put(msg, NM_ATT_BS11_PLL_MODE, 1, &tlv_value);
Harald Weltee69f5fb2009-04-28 16:31:38 +00001925
1926 return abis_nm_sendmsg(bts, msg);
1927}
1928
Harald Welte1bc09062009-01-18 14:17:52 +00001929int abis_nm_bs11_get_state(struct gsm_bts *bts)
1930{
1931 return __simple_cmd(bts, NM_MT_BS11_GET_STATE);
1932}
Harald Welte5e4d1b32009-02-01 13:36:56 +00001933
1934/* BS11 SWL */
1935
1936struct abis_nm_bs11_sw {
1937 struct gsm_bts *bts;
1938 char swl_fname[PATH_MAX];
1939 u_int8_t win_size;
Harald Welte3ffd1372009-02-01 22:15:49 +00001940 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001941 struct llist_head file_list;
1942 gsm_cbfn *user_cb; /* specified by the user */
1943};
1944static struct abis_nm_bs11_sw _g_bs11_sw, *g_bs11_sw = &_g_bs11_sw;
1945
1946struct file_list_entry {
1947 struct llist_head list;
1948 char fname[PATH_MAX];
1949};
1950
1951struct file_list_entry *fl_dequeue(struct llist_head *queue)
1952{
1953 struct llist_head *lh;
1954
1955 if (llist_empty(queue))
1956 return NULL;
1957
1958 lh = queue->next;
1959 llist_del(lh);
1960
1961 return llist_entry(lh, struct file_list_entry, list);
1962}
1963
1964static int bs11_read_swl_file(struct abis_nm_bs11_sw *bs11_sw)
1965{
1966 char linebuf[255];
1967 struct llist_head *lh, *lh2;
1968 FILE *swl;
1969 int rc = 0;
1970
1971 swl = fopen(bs11_sw->swl_fname, "r");
1972 if (!swl)
1973 return -ENODEV;
1974
1975 /* zero the stale file list, if any */
1976 llist_for_each_safe(lh, lh2, &bs11_sw->file_list) {
1977 llist_del(lh);
1978 free(lh);
1979 }
1980
1981 while (fgets(linebuf, sizeof(linebuf), swl)) {
1982 char file_id[12+1];
1983 char file_version[80+1];
1984 struct file_list_entry *fle;
1985 static char dir[PATH_MAX];
1986
1987 if (strlen(linebuf) < 4)
1988 continue;
Harald Welte3ffd1372009-02-01 22:15:49 +00001989
Harald Welte5e4d1b32009-02-01 13:36:56 +00001990 rc = sscanf(linebuf+4, "%12s:%80s\r\n", file_id, file_version);
1991 if (rc < 0) {
1992 perror("ERR parsing SWL file");
1993 rc = -EINVAL;
1994 goto out;
1995 }
1996 if (rc < 2)
1997 continue;
1998
1999 fle = malloc(sizeof(*fle));
2000 if (!fle) {
2001 rc = -ENOMEM;
2002 goto out;
2003 }
2004 memset(fle, 0, sizeof(*fle));
2005
2006 /* construct new filename */
2007 strncpy(dir, bs11_sw->swl_fname, sizeof(dir));
2008 strncat(fle->fname, dirname(dir), sizeof(fle->fname) - 1);
2009 strcat(fle->fname, "/");
2010 strncat(fle->fname, file_id, sizeof(fle->fname) - 1 -strlen(fle->fname));
Harald Welte5e4d1b32009-02-01 13:36:56 +00002011
2012 llist_add_tail(&fle->list, &bs11_sw->file_list);
2013 }
2014
2015out:
2016 fclose(swl);
2017 return rc;
2018}
2019
2020/* bs11 swload specific callback, passed to abis_nm core swload */
2021static int bs11_swload_cbfn(unsigned int hook, unsigned int event,
2022 struct msgb *msg, void *data, void *param)
2023{
2024 struct abis_nm_bs11_sw *bs11_sw = data;
2025 struct file_list_entry *fle;
2026 int rc = 0;
2027
Harald Welte5e4d1b32009-02-01 13:36:56 +00002028 switch (event) {
2029 case NM_MT_LOAD_END_ACK:
2030 fle = fl_dequeue(&bs11_sw->file_list);
2031 if (fle) {
2032 /* start download the next file of our file list */
2033 rc = abis_nm_software_load(bs11_sw->bts, fle->fname,
2034 bs11_sw->win_size,
Harald Welte3ffd1372009-02-01 22:15:49 +00002035 bs11_sw->forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00002036 &bs11_swload_cbfn, bs11_sw);
2037 free(fle);
2038 } else {
2039 /* activate the SWL */
2040 rc = abis_nm_software_activate(bs11_sw->bts,
2041 bs11_sw->swl_fname,
2042 bs11_swload_cbfn,
2043 bs11_sw);
2044 }
2045 break;
Harald Welte3ffd1372009-02-01 22:15:49 +00002046 case NM_MT_LOAD_SEG_ACK:
Harald Welte5e4d1b32009-02-01 13:36:56 +00002047 case NM_MT_LOAD_END_NACK:
2048 case NM_MT_LOAD_INIT_ACK:
2049 case NM_MT_LOAD_INIT_NACK:
2050 case NM_MT_ACTIVATE_SW_NACK:
2051 case NM_MT_ACTIVATE_SW_ACK:
2052 default:
2053 /* fallthrough to the user callback */
Harald Welte97ed1e72009-02-06 13:38:02 +00002054 if (bs11_sw->user_cb)
2055 rc = bs11_sw->user_cb(hook, event, msg, NULL, NULL);
Harald Welte5e4d1b32009-02-01 13:36:56 +00002056 break;
2057 }
2058
2059 return rc;
2060}
2061
2062/* Siemens provides a SWL file that is a mere listing of all the other
2063 * files that are part of a software release. We need to upload first
2064 * the list file, and then each file that is listed in the list file */
2065int abis_nm_bs11_load_swl(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00002066 u_int8_t win_size, int forced, gsm_cbfn *cbfn)
Harald Welte5e4d1b32009-02-01 13:36:56 +00002067{
2068 struct abis_nm_bs11_sw *bs11_sw = g_bs11_sw;
2069 struct file_list_entry *fle;
2070 int rc = 0;
2071
2072 INIT_LLIST_HEAD(&bs11_sw->file_list);
2073 bs11_sw->bts = bts;
2074 bs11_sw->win_size = win_size;
2075 bs11_sw->user_cb = cbfn;
Harald Welte3ffd1372009-02-01 22:15:49 +00002076 bs11_sw->forced = forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00002077
2078 strncpy(bs11_sw->swl_fname, fname, sizeof(bs11_sw->swl_fname));
2079 rc = bs11_read_swl_file(bs11_sw);
2080 if (rc < 0)
2081 return rc;
2082
2083 /* dequeue next item in file list */
2084 fle = fl_dequeue(&bs11_sw->file_list);
2085 if (!fle)
2086 return -EINVAL;
2087
2088 /* start download the next file of our file list */
Harald Welte3ffd1372009-02-01 22:15:49 +00002089 rc = abis_nm_software_load(bts, fle->fname, win_size, forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00002090 bs11_swload_cbfn, bs11_sw);
2091 free(fle);
2092 return rc;
2093}
2094
Harald Welte5083b0b2009-02-02 19:20:52 +00002095#if 0
Harald Welte5e4d1b32009-02-01 13:36:56 +00002096static u_int8_t req_attr_btse[] = {
2097 NM_ATT_ADM_STATE, NM_ATT_BS11_LMT_LOGON_SESSION,
2098 NM_ATT_BS11_LMT_LOGIN_TIME, NM_ATT_BS11_LMT_USER_ACC_LEV,
2099 NM_ATT_BS11_LMT_USER_NAME,
2100
2101 0xaf, NM_ATT_BS11_RX_OFFSET, NM_ATT_BS11_VENDOR_NAME,
2102
2103 NM_ATT_BS11_SW_LOAD_INTENDED, NM_ATT_BS11_SW_LOAD_SAFETY,
2104
2105 NM_ATT_BS11_SW_LOAD_STORED };
2106
2107static u_int8_t req_attr_btsm[] = {
2108 NM_ATT_ABIS_CHANNEL, NM_ATT_TEI, NM_ATT_BS11_ABIS_EXT_TIME,
2109 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xce, NM_ATT_FILE_ID,
2110 NM_ATT_FILE_VERSION, NM_ATT_OPER_STATE, 0xe8, NM_ATT_BS11_ALL_TEST_CATG,
2111 NM_ATT_SW_DESCR, NM_ATT_GET_ARI };
Harald Welte5083b0b2009-02-02 19:20:52 +00002112#endif
Harald Welte5e4d1b32009-02-01 13:36:56 +00002113
2114static u_int8_t req_attr[] = {
2115 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xa8, NM_ATT_OPER_STATE,
2116 0xd5, 0xa1, NM_ATT_BS11_ESN_FW_CODE_NO, NM_ATT_BS11_ESN_HW_CODE_NO,
Harald Weltea7cfa032009-04-29 22:33:02 +00002117 0x42, NM_ATT_BS11_ESN_PCB_SERIAL, NM_ATT_BS11_PLL };
Harald Welte5e4d1b32009-02-01 13:36:56 +00002118
2119int abis_nm_bs11_get_serno(struct gsm_bts *bts)
2120{
2121 struct abis_om_hdr *oh;
2122 struct msgb *msg = nm_msgb_alloc();
2123
2124 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2125 /* SiemensHW CCTRL object */
2126 fill_om_fom_hdr(oh, 2+sizeof(req_attr), NM_MT_GET_ATTR, NM_OC_BS11,
2127 0x03, 0x00, 0x00);
2128 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(req_attr), req_attr);
2129
2130 return abis_nm_sendmsg(bts, msg);
2131}
Harald Welte268bb402009-02-01 19:11:56 +00002132
2133int abis_nm_bs11_set_ext_time(struct gsm_bts *bts)
2134{
2135 struct abis_om_hdr *oh;
2136 struct msgb *msg = nm_msgb_alloc();
2137 struct bs11_date_time aet;
2138
2139 get_bs11_date_time(&aet);
2140 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2141 /* SiemensHW CCTRL object */
2142 fill_om_fom_hdr(oh, 2+sizeof(aet), NM_MT_BS11_SET_ATTR, NM_OC_SITE_MANAGER,
2143 0xff, 0xff, 0xff);
Harald Welte5083b0b2009-02-02 19:20:52 +00002144 msgb_tlv_put(msg, NM_ATT_BS11_ABIS_EXT_TIME, sizeof(aet), (u_int8_t *) &aet);
Harald Welte268bb402009-02-01 19:11:56 +00002145
2146 return abis_nm_sendmsg(bts, msg);
2147}
Harald Welte5c1e4582009-02-15 11:57:29 +00002148
2149/* ip.access nanoBTS specific commands */
Harald Welte5c1e4582009-02-15 11:57:29 +00002150static const char ipaccess_magic[] = "com.ipaccess";
2151
Harald Welte677c21f2009-02-17 13:22:23 +00002152
2153static int abis_nm_rx_ipacc(struct msgb *msg)
2154{
2155 struct abis_om_hdr *oh = msgb_l2(msg);
2156 struct abis_om_fom_hdr *foh;
2157 u_int8_t idstrlen = oh->data[0];
2158 struct tlv_parsed tp;
2159
2160 if (strncmp((char *)&oh->data[1], ipaccess_magic, idstrlen)) {
2161 DEBUGP(DNM, "id string is not com.ipaccess !?!\n");
2162 return -EINVAL;
2163 }
2164
Harald Welte193fefc2009-04-30 15:16:27 +00002165 foh = (struct abis_om_fom_hdr *) (oh->data + 1 + idstrlen);
Harald Welte03133942009-02-18 19:51:53 +00002166 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Welte677c21f2009-02-17 13:22:23 +00002167
Harald Welte193fefc2009-04-30 15:16:27 +00002168 DEBUGP(DNM, "IPACCESS(0x%02x): ", foh->msg_type);
2169
Harald Welte677c21f2009-02-17 13:22:23 +00002170 switch (foh->msg_type) {
2171 case NM_MT_IPACC_RSL_CONNECT_ACK:
Harald Welte193fefc2009-04-30 15:16:27 +00002172 DEBUGPC(DNM, "RSL CONNECT ACK ");
Harald Welte677c21f2009-02-17 13:22:23 +00002173 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_RSL_BSC_IP))
Harald Welte9de2bf82009-04-30 15:59:55 +00002174 DEBUGPC(DNM, "IP=%s ",
Harald Welte677c21f2009-02-17 13:22:23 +00002175 inet_ntoa(*((struct in_addr *)
2176 TLVP_VAL(&tp, NM_ATT_IPACC_RSL_BSC_IP))));
2177 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_RSL_BSC_PORT))
Harald Welte9de2bf82009-04-30 15:59:55 +00002178 DEBUGPC(DNM, "PORT=%u ",
Harald Welte677c21f2009-02-17 13:22:23 +00002179 ntohs(*((u_int16_t *)
2180 TLVP_VAL(&tp, NM_ATT_IPACC_RSL_BSC_PORT))));
Harald Welte9de2bf82009-04-30 15:59:55 +00002181 DEBUGPC(DNM, "\n");
Harald Welte677c21f2009-02-17 13:22:23 +00002182 break;
2183 case NM_MT_IPACC_RSL_CONNECT_NACK:
Harald Welte193fefc2009-04-30 15:16:27 +00002184 DEBUGPC(DNM, "RSL CONNECT NACK ");
Harald Welte677c21f2009-02-17 13:22:23 +00002185 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
Harald Welte6c96ba52009-05-01 13:03:40 +00002186 DEBUGPC(DNM, " CAUSE=%s\n",
2187 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
Harald Welte677c21f2009-02-17 13:22:23 +00002188 else
2189 DEBUGPC(DNM, "\n");
2190 break;
Harald Welte193fefc2009-04-30 15:16:27 +00002191 case NM_MT_IPACC_SET_NVATTR_ACK:
2192 DEBUGPC(DNM, "SET NVATTR ACK\n");
2193 /* FIXME: decode and show the actual attributes */
2194 break;
2195 case NM_MT_IPACC_SET_NVATTR_NACK:
Harald Welte6c96ba52009-05-01 13:03:40 +00002196 DEBUGPC(DNM, "SET NVATTR NACK ");
2197 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
2198 DEBUGPC(DNM, " CAUSE=%s\n",
2199 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
2200 else
2201 DEBUGPC(DNM, "\n");
Harald Welte193fefc2009-04-30 15:16:27 +00002202 break;
2203 default:
2204 DEBUGPC(DNM, "unknown\n");
2205 break;
Harald Welte677c21f2009-02-17 13:22:23 +00002206 }
2207 return 0;
2208}
2209
Harald Welte193fefc2009-04-30 15:16:27 +00002210/* send an ip-access manufacturer specific message */
Harald Welte5c1e4582009-02-15 11:57:29 +00002211int abis_nm_ipaccess_msg(struct gsm_bts *bts, u_int8_t msg_type,
2212 u_int8_t obj_class, u_int8_t bts_nr,
2213 u_int8_t trx_nr, u_int8_t ts_nr,
2214 u_int8_t *attr, int attr_len)
2215{
2216 struct msgb *msg = nm_msgb_alloc();
2217 struct abis_om_hdr *oh;
2218 struct abis_om_fom_hdr *foh;
2219 u_int8_t *data;
2220
2221 /* construct the 12.21 OM header, observe the erroneous length */
2222 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
2223 fill_om_hdr(oh, sizeof(*foh) + attr_len);
2224 oh->mdisc = ABIS_OM_MDISC_MANUF;
2225
2226 /* add the ip.access magic */
2227 data = msgb_put(msg, sizeof(ipaccess_magic)+1);
2228 *data++ = sizeof(ipaccess_magic);
2229 memcpy(data, ipaccess_magic, sizeof(ipaccess_magic));
2230
2231 /* fill the 12.21 FOM header */
2232 foh = (struct abis_om_fom_hdr *) msgb_put(msg, sizeof(*foh));
2233 foh->msg_type = msg_type;
2234 foh->obj_class = obj_class;
2235 foh->obj_inst.bts_nr = bts_nr;
2236 foh->obj_inst.trx_nr = trx_nr;
2237 foh->obj_inst.ts_nr = ts_nr;
2238
2239 if (attr && attr_len) {
2240 data = msgb_put(msg, attr_len);
2241 memcpy(data, attr, attr_len);
2242 }
2243
2244 return abis_nm_sendmsg(bts, msg);
2245}
Harald Welte677c21f2009-02-17 13:22:23 +00002246
Harald Welte193fefc2009-04-30 15:16:27 +00002247/* set some attributes in NVRAM */
2248int abis_nm_ipaccess_set_nvattr(struct gsm_bts *bts, u_int8_t *attr,
2249 int attr_len)
2250{
2251 return abis_nm_ipaccess_msg(bts, NM_MT_IPACC_SET_NVATTR,
2252 NM_OC_BASEB_TRANSC, 0, 0, 0xff, attr,
2253 attr_len);
2254}
2255
2256/* restart / reboot an ip.access nanoBTS */
2257int abis_nm_ipaccess_restart(struct gsm_bts *bts)
2258{
2259 return __simple_cmd(bts, NM_MT_IPACC_RESTART);
2260}