blob: 05dec220166ca1868d1c4b6bd363f937793eb1e3 [file] [log] [blame]
Harald Welte59b04682009-06-10 05:40:52 +08001/* 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
4/* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org>
5 *
6 * 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>
26#include <unistd.h>
27#include <stdio.h>
28#include <fcntl.h>
29#include <stdlib.h>
30#include <libgen.h>
31#include <time.h>
32#include <limits.h>
33
34#include <sys/types.h>
35#include <sys/stat.h>
36#include <netinet/in.h>
37#include <arpa/inet.h>
38
39#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>
44#include <openbsc/misdn.h>
45#include <openbsc/signal.h>
Harald Weltea8379772009-06-20 22:36:41 +020046#include <openbsc/talloc.h>
Harald Welte59b04682009-06-10 05:40:52 +080047
48#define OM_ALLOC_SIZE 1024
49#define OM_HEADROOM_SIZE 128
50
51/* unidirectional messages from BTS to BSC */
52static const enum abis_nm_msgtype reports[] = {
53 NM_MT_SW_ACTIVATED_REP,
54 NM_MT_TEST_REP,
55 NM_MT_STATECHG_EVENT_REP,
56 NM_MT_FAILURE_EVENT_REP,
57};
58
59/* messages without ACK/NACK */
60static const enum abis_nm_msgtype no_ack_nack[] = {
61 NM_MT_MEAS_RES_REQ,
62 NM_MT_STOP_MEAS,
63 NM_MT_START_MEAS,
64};
65
66/* Messages related to software load */
67static const enum abis_nm_msgtype sw_load_msgs[] = {
68 NM_MT_LOAD_INIT_ACK,
69 NM_MT_LOAD_INIT_NACK,
70 NM_MT_LOAD_SEG_ACK,
71 NM_MT_LOAD_ABORT,
72 NM_MT_LOAD_END_ACK,
73 NM_MT_LOAD_END_NACK,
74 //NM_MT_SW_ACT_REQ,
75 NM_MT_ACTIVATE_SW_ACK,
76 NM_MT_ACTIVATE_SW_NACK,
77 NM_MT_SW_ACTIVATED_REP,
78};
79
80static const enum abis_nm_msgtype nacks[] = {
81 NM_MT_LOAD_INIT_NACK,
82 NM_MT_LOAD_END_NACK,
83 NM_MT_SW_ACT_REQ_NACK,
84 NM_MT_ACTIVATE_SW_NACK,
85 NM_MT_ESTABLISH_TEI_NACK,
86 NM_MT_CONN_TERR_SIGN_NACK,
87 NM_MT_DISC_TERR_SIGN_NACK,
88 NM_MT_CONN_TERR_TRAF_NACK,
89 NM_MT_DISC_TERR_TRAF_NACK,
90 NM_MT_CONN_MDROP_LINK_NACK,
91 NM_MT_DISC_MDROP_LINK_NACK,
92 NM_MT_SET_BTS_ATTR_NACK,
93 NM_MT_SET_RADIO_ATTR_NACK,
94 NM_MT_SET_CHAN_ATTR_NACK,
95 NM_MT_PERF_TEST_NACK,
96 NM_MT_SEND_TEST_REP_NACK,
97 NM_MT_STOP_TEST_NACK,
98 NM_MT_STOP_EVENT_REP_NACK,
99 NM_MT_REST_EVENT_REP_NACK,
100 NM_MT_CHG_ADM_STATE_NACK,
101 NM_MT_CHG_ADM_STATE_REQ_NACK,
102 NM_MT_REP_OUTST_ALARMS_NACK,
103 NM_MT_CHANGEOVER_NACK,
104 NM_MT_OPSTART_NACK,
105 NM_MT_REINIT_NACK,
106 NM_MT_SET_SITE_OUT_NACK,
107 NM_MT_CHG_HW_CONF_NACK,
108 NM_MT_GET_ATTR_NACK,
109 NM_MT_SET_ALARM_THRES_NACK,
110 NM_MT_BS11_BEGIN_DB_TX_NACK,
111 NM_MT_BS11_END_DB_TX_NACK,
112 NM_MT_BS11_CREATE_OBJ_NACK,
113 NM_MT_BS11_DELETE_OBJ_NACK,
114};
115
116static const char *nack_names[0xff] = {
117 [NM_MT_LOAD_INIT_NACK] = "SOFTWARE LOAD INIT",
118 [NM_MT_LOAD_END_NACK] = "SOFTWARE LOAD END",
119 [NM_MT_SW_ACT_REQ_NACK] = "SOFTWARE ACTIVATE REQUEST",
120 [NM_MT_ACTIVATE_SW_NACK] = "ACTIVATE SOFTWARE",
121 [NM_MT_ESTABLISH_TEI_NACK] = "ESTABLISH TEI",
122 [NM_MT_CONN_TERR_SIGN_NACK] = "CONNECT TERRESTRIAL SIGNALLING",
123 [NM_MT_DISC_TERR_SIGN_NACK] = "DISCONNECT TERRESTRIAL SIGNALLING",
124 [NM_MT_CONN_TERR_TRAF_NACK] = "CONNECT TERRESTRIAL TRAFFIC",
125 [NM_MT_DISC_TERR_TRAF_NACK] = "DISCONNECT TERRESTRIAL TRAFFIC",
126 [NM_MT_CONN_MDROP_LINK_NACK] = "CONNECT MULTI-DROP LINK",
127 [NM_MT_DISC_MDROP_LINK_NACK] = "DISCONNECT MULTI-DROP LINK",
128 [NM_MT_SET_BTS_ATTR_NACK] = "SET BTS ATTRIBUTE",
129 [NM_MT_SET_RADIO_ATTR_NACK] = "SET RADIO ATTRIBUTE",
130 [NM_MT_SET_CHAN_ATTR_NACK] = "SET CHANNEL ATTRIBUTE",
131 [NM_MT_PERF_TEST_NACK] = "PERFORM TEST",
132 [NM_MT_SEND_TEST_REP_NACK] = "SEND TEST REPORT",
133 [NM_MT_STOP_TEST_NACK] = "STOP TEST",
134 [NM_MT_STOP_EVENT_REP_NACK] = "STOP EVENT REPORT",
135 [NM_MT_REST_EVENT_REP_NACK] = "RESET EVENT REPORT",
136 [NM_MT_CHG_ADM_STATE_NACK] = "CHANGE ADMINISTRATIVE STATE",
137 [NM_MT_CHG_ADM_STATE_REQ_NACK] = "CHANGE ADMINISTRATIVE STATE REQUEST",
138 [NM_MT_REP_OUTST_ALARMS_NACK] = "REPORT OUTSTANDING ALARMS",
139 [NM_MT_CHANGEOVER_NACK] = "CHANGEOVER",
140 [NM_MT_OPSTART_NACK] = "OPSTART",
141 [NM_MT_REINIT_NACK] = "REINIT",
142 [NM_MT_SET_SITE_OUT_NACK] = "SET SITE OUTPUT",
143 [NM_MT_CHG_HW_CONF_NACK] = "CHANGE HARDWARE CONFIGURATION",
144 [NM_MT_GET_ATTR_NACK] = "GET ATTRIBUTE",
145 [NM_MT_SET_ALARM_THRES_NACK] = "SET ALARM THRESHOLD",
146 [NM_MT_BS11_BEGIN_DB_TX_NACK] = "BS11 BEGIN DATABASE TRANSMISSION",
147 [NM_MT_BS11_END_DB_TX_NACK] = "BS11 END DATABASE TRANSMISSION",
148 [NM_MT_BS11_CREATE_OBJ_NACK] = "BS11 CREATE OBJECT",
149 [NM_MT_BS11_DELETE_OBJ_NACK] = "BS11 DELETE OBJECT",
150};
151
152/* Chapter 9.4.36 */
153static const char *nack_cause_names[] = {
154 /* General Nack Causes */
155 [NM_NACK_INCORR_STRUCT] = "Incorrect message structure",
156 [NM_NACK_MSGTYPE_INVAL] = "Invalid message type value",
157 [NM_NACK_OBJCLASS_INVAL] = "Invalid Object class value",
158 [NM_NACK_OBJCLASS_NOTSUPP] = "Object class not supported",
159 [NM_NACK_BTSNR_UNKN] = "BTS no. unknown",
160 [NM_NACK_TRXNR_UNKN] = "Baseband Transceiver no. unknown",
161 [NM_NACK_OBJINST_UNKN] = "Object Instance unknown",
162 [NM_NACK_ATTRID_INVAL] = "Invalid attribute identifier value",
163 [NM_NACK_ATTRID_NOTSUPP] = "Attribute identifier not supported",
164 [NM_NACK_PARAM_RANGE] = "Parameter value outside permitted range",
165 [NM_NACK_ATTRLIST_INCONSISTENT] = "Inconsistency in attribute list",
166 [NM_NACK_SPEC_IMPL_NOTSUPP] = "Specified implementation not supported",
167 [NM_NACK_CANT_PERFORM] = "Message cannot be performed",
168 /* Specific Nack Causes */
169 [NM_NACK_RES_NOTIMPL] = "Resource not implemented",
170 [NM_NACK_RES_NOTAVAIL] = "Resource not available",
171 [NM_NACK_FREQ_NOTAVAIL] = "Frequency not available",
172 [NM_NACK_TEST_NOTSUPP] = "Test not supported",
173 [NM_NACK_CAPACITY_RESTR] = "Capacity restrictions",
174 [NM_NACK_PHYSCFG_NOTPERFORM] = "Physical configuration cannot be performed",
175 [NM_NACK_TEST_NOTINIT] = "Test not initiated",
176 [NM_NACK_PHYSCFG_NOTRESTORE] = "Physical configuration cannot be restored",
177 [NM_NACK_TEST_NOSUCH] = "No such test",
178 [NM_NACK_TEST_NOSTOP] = "Test cannot be stopped",
179 [NM_NACK_MSGINCONSIST_PHYSCFG] = "Message inconsistent with physical configuration",
180 [NM_NACK_FILE_INCOMPLETE] = "Complete file notreceived",
181 [NM_NACK_FILE_NOTAVAIL] = "File not available at destination",
Harald Weltec3217a12009-06-26 13:21:57 +0200182 [NM_NACK_FILE_NOTACTIVATE] = "File cannot be activate",
Harald Welte59b04682009-06-10 05:40:52 +0800183 [NM_NACK_REQ_NOT_GRANT] = "Request not granted",
184 [NM_NACK_WAIT] = "Wait",
185 [NM_NACK_NOTH_REPORT_EXIST] = "Nothing reportable existing",
186 [NM_NACK_MEAS_NOTSUPP] = "Measurement not supported",
187 [NM_NACK_MEAS_NOTSTART] = "Measurement not started",
188};
189
190static char namebuf[255];
191static const char *nack_cause_name(u_int8_t cause)
192{
193 if (cause < ARRAY_SIZE(nack_cause_names) && nack_cause_names[cause])
194 return nack_cause_names[cause];
195
196 snprintf(namebuf, sizeof(namebuf), "0x%02x\n", cause);
197 return namebuf;
198}
199
200/* Chapter 9.4.16: Event Type */
201static const char *event_type_names[] = {
202 [NM_EVT_COMM_FAIL] = "communication failure",
203 [NM_EVT_QOS_FAIL] = "quality of service failure",
204 [NM_EVT_PROC_FAIL] = "processing failure",
205 [NM_EVT_EQUIP_FAIL] = "equipment failure",
206 [NM_EVT_ENV_FAIL] = "environment failure",
207};
208
209static const char *event_type_name(u_int8_t cause)
210{
211 if (cause < ARRAY_SIZE(event_type_names) && event_type_names[cause])
212 return event_type_names[cause];
213
214 snprintf(namebuf, sizeof(namebuf), "0x%02x\n", cause);
215 return namebuf;
216}
217
218/* Chapter 9.4.63: Perceived Severity */
219static const char *severity_names[] = {
220 [NM_SEVER_CEASED] = "failure ceased",
221 [NM_SEVER_CRITICAL] = "critical failure",
222 [NM_SEVER_MAJOR] = "major failure",
223 [NM_SEVER_MINOR] = "minor failure",
224 [NM_SEVER_WARNING] = "warning level failure",
225 [NM_SEVER_INDETERMINATE] = "indeterminate failure",
226};
227
228static const char *severity_name(u_int8_t cause)
229{
230 if (cause < ARRAY_SIZE(severity_names) && severity_names[cause])
231 return severity_names[cause];
232
233 snprintf(namebuf, sizeof(namebuf), "0x%02x\n", cause);
234 return namebuf;
235}
236
237/* Attributes that the BSC can set, not only get, according to Section 9.4 */
238static const enum abis_nm_attr nm_att_settable[] = {
239 NM_ATT_ADD_INFO,
240 NM_ATT_ADD_TEXT,
241 NM_ATT_DEST,
242 NM_ATT_EVENT_TYPE,
243 NM_ATT_FILE_DATA,
244 NM_ATT_GET_ARI,
245 NM_ATT_HW_CONF_CHG,
246 NM_ATT_LIST_REQ_ATTR,
247 NM_ATT_MDROP_LINK,
248 NM_ATT_MDROP_NEXT,
249 NM_ATT_NACK_CAUSES,
250 NM_ATT_OUTST_ALARM,
251 NM_ATT_PHYS_CONF,
252 NM_ATT_PROB_CAUSE,
253 NM_ATT_RAD_SUBC,
254 NM_ATT_SOURCE,
255 NM_ATT_SPEC_PROB,
256 NM_ATT_START_TIME,
257 NM_ATT_TEST_DUR,
258 NM_ATT_TEST_NO,
259 NM_ATT_TEST_REPORT,
260 NM_ATT_WINDOW_SIZE,
261 NM_ATT_SEVERITY,
262 NM_ATT_MEAS_RES,
263 NM_ATT_MEAS_TYPE,
264};
265
266static const struct tlv_definition nm_att_tlvdef = {
267 .def = {
268 [NM_ATT_ABIS_CHANNEL] = { TLV_TYPE_FIXED, 3 },
269 [NM_ATT_ADD_INFO] = { TLV_TYPE_TL16V },
270 [NM_ATT_ADD_TEXT] = { TLV_TYPE_TL16V },
271 [NM_ATT_ADM_STATE] = { TLV_TYPE_TV },
272 [NM_ATT_ARFCN_LIST]= { TLV_TYPE_TL16V },
273 [NM_ATT_AUTON_REPORT] = { TLV_TYPE_TV },
274 [NM_ATT_AVAIL_STATUS] = { TLV_TYPE_TL16V },
275 [NM_ATT_BCCH_ARFCN] = { TLV_TYPE_FIXED, 2 },
276 [NM_ATT_BSIC] = { TLV_TYPE_TV },
277 [NM_ATT_BTS_AIR_TIMER] = { TLV_TYPE_TV },
278 [NM_ATT_CCCH_L_I_P] = { TLV_TYPE_TV },
279 [NM_ATT_CCCH_L_T] = { TLV_TYPE_TV },
280 [NM_ATT_CHAN_COMB] = { TLV_TYPE_TV },
281 [NM_ATT_CONN_FAIL_CRIT] = { TLV_TYPE_TL16V },
282 [NM_ATT_DEST] = { TLV_TYPE_TL16V },
283 [NM_ATT_EVENT_TYPE] = { TLV_TYPE_TV },
284 [NM_ATT_FILE_DATA] = { TLV_TYPE_TL16V },
285 [NM_ATT_FILE_ID] = { TLV_TYPE_TL16V },
286 [NM_ATT_FILE_VERSION] = { TLV_TYPE_TL16V },
287 [NM_ATT_GSM_TIME] = { TLV_TYPE_FIXED, 2 },
288 [NM_ATT_HSN] = { TLV_TYPE_TV },
289 [NM_ATT_HW_CONFIG] = { TLV_TYPE_TL16V },
290 [NM_ATT_HW_DESC] = { TLV_TYPE_TL16V },
291 [NM_ATT_INTAVE_PARAM] = { TLV_TYPE_TV },
292 [NM_ATT_INTERF_BOUND] = { TLV_TYPE_FIXED, 6 },
293 [NM_ATT_LIST_REQ_ATTR] = { TLV_TYPE_TL16V },
294 [NM_ATT_MAIO] = { TLV_TYPE_TV },
295 [NM_ATT_MANUF_STATE] = { TLV_TYPE_TV },
296 [NM_ATT_MANUF_THRESH] = { TLV_TYPE_TL16V },
297 [NM_ATT_MANUF_ID] = { TLV_TYPE_TL16V },
298 [NM_ATT_MAX_TA] = { TLV_TYPE_TV },
299 [NM_ATT_MDROP_LINK] = { TLV_TYPE_FIXED, 2 },
300 [NM_ATT_MDROP_NEXT] = { TLV_TYPE_FIXED, 2 },
301 [NM_ATT_NACK_CAUSES] = { TLV_TYPE_TV },
302 [NM_ATT_NY1] = { TLV_TYPE_TV },
303 [NM_ATT_OPER_STATE] = { TLV_TYPE_TV },
304 [NM_ATT_OVERL_PERIOD] = { TLV_TYPE_TL16V },
305 [NM_ATT_PHYS_CONF] = { TLV_TYPE_TL16V },
306 [NM_ATT_POWER_CLASS] = { TLV_TYPE_TV },
307 [NM_ATT_POWER_THRESH] = { TLV_TYPE_FIXED, 3 },
308 [NM_ATT_PROB_CAUSE] = { TLV_TYPE_FIXED, 3 },
309 [NM_ATT_RACH_B_THRESH] = { TLV_TYPE_TV },
310 [NM_ATT_LDAVG_SLOTS] = { TLV_TYPE_FIXED, 2 },
311 [NM_ATT_RAD_SUBC] = { TLV_TYPE_TV },
312 [NM_ATT_RF_MAXPOWR_R] = { TLV_TYPE_TV },
313 [NM_ATT_SITE_INPUTS] = { TLV_TYPE_TL16V },
314 [NM_ATT_SITE_OUTPUTS] = { TLV_TYPE_TL16V },
315 [NM_ATT_SOURCE] = { TLV_TYPE_TL16V },
316 [NM_ATT_SPEC_PROB] = { TLV_TYPE_TV },
317 [NM_ATT_START_TIME] = { TLV_TYPE_FIXED, 2 },
318 [NM_ATT_T200] = { TLV_TYPE_FIXED, 7 },
319 [NM_ATT_TEI] = { TLV_TYPE_TV },
320 [NM_ATT_TEST_DUR] = { TLV_TYPE_FIXED, 2 },
321 [NM_ATT_TEST_NO] = { TLV_TYPE_TV },
322 [NM_ATT_TEST_REPORT] = { TLV_TYPE_TL16V },
323 [NM_ATT_VSWR_THRESH] = { TLV_TYPE_FIXED, 2 },
324 [NM_ATT_WINDOW_SIZE] = { TLV_TYPE_TV },
325 [NM_ATT_TSC] = { TLV_TYPE_TV },
326 [NM_ATT_SW_CONFIG] = { TLV_TYPE_TL16V },
327 [NM_ATT_SEVERITY] = { TLV_TYPE_TV },
328 [NM_ATT_GET_ARI] = { TLV_TYPE_TL16V },
329 [NM_ATT_HW_CONF_CHG] = { TLV_TYPE_TL16V },
330 [NM_ATT_OUTST_ALARM] = { TLV_TYPE_TV },
Harald Welte59b04682009-06-10 05:40:52 +0800331 [NM_ATT_MEAS_RES] = { TLV_TYPE_TL16V },
332 /* BS11 specifics */
333 [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 },
339 [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 },
346 [NM_ATT_BS11_LMT_LOGON_SESSION]={ TLV_TYPE_TLV },
347 [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 },
350 [NM_ATT_BS11_BTS_STATE] = { TLV_TYPE_TLV },
351 [NM_ATT_BS11_E1_STATE] = { TLV_TYPE_TLV },
352 [NM_ATT_BS11_PLL_MODE] = { TLV_TYPE_TLV },
353 [NM_ATT_BS11_PLL] = { TLV_TYPE_TLV },
354 [NM_ATT_BS11_CCLK_ACCURACY] = { TLV_TYPE_TV },
355 [NM_ATT_BS11_CCLK_TYPE] = { TLV_TYPE_TV },
356 /* ip.access specifics */
Harald Welte4206d982009-07-12 09:33:54 +0200357 [NM_ATT_IPACC_DST_IP] = { TLV_TYPE_FIXED, 4 },
358 [NM_ATT_IPACC_DST_IP_PORT] = { TLV_TYPE_FIXED, 2 },
Harald Weltedb1e7442009-08-06 17:57:23 +0200359 [NM_ATT_IPACC_STREAM_ID] = { TLV_TYPE_TV, },
360 [NM_ATT_IPACC_FREQ_CTRL] = { TLV_TYPE_TV, },
361 [NM_ATT_IPACC_SEC_OML_CFG] = { TLV_TYPE_FIXED, 6 },
362 [NM_ATT_IPACC_IP_IF_CFG] = { TLV_TYPE_FIXED, 8 },
363 [NM_ATT_IPACC_IP_GW_CFG] = { TLV_TYPE_FIXED, 12 },
364 [NM_ATT_IPACC_IN_SERV_TIME] = { TLV_TYPE_FIXED, 4 },
365 [NM_ATT_IPACC_LOCATION] = { TLV_TYPE_TL16V },
366 [NM_ATT_IPACC_PAGING_CFG] = { TLV_TYPE_FIXED, 2 },
367 [NM_ATT_IPACC_UNIT_ID] = { TLV_TYPE_TL16V },
368 [NM_ATT_IPACC_UNIT_NAME] = { TLV_TYPE_TL16V },
369 [NM_ATT_IPACC_SNMP_CFG] = { TLV_TYPE_TL16V },
Harald Welte4206d982009-07-12 09:33:54 +0200370 [NM_ATT_IPACC_PRIM_OML_CFG_LIST] = { TLV_TYPE_TL16V },
Harald Welte90a93cf2009-07-03 12:46:27 +0200371 [NM_ATT_IPACC_NV_FLAGS] = { TLV_TYPE_TL16V },
372 [NM_ATT_IPACC_FREQ_CTRL] = { TLV_TYPE_FIXED, 2 },
Harald Welte4206d982009-07-12 09:33:54 +0200373 [NM_ATT_IPACC_PRIM_OML_FB_TOUT] = { TLV_TYPE_TL16V },
Harald Weltedb1e7442009-08-06 17:57:23 +0200374 [NM_ATT_IPACC_CUR_SW_CFG] = { TLV_TYPE_TL16V },
375 [NM_ATT_IPACC_TIMING_BUS] = { TLV_TYPE_TL16V },
376 [NM_ATT_IPACC_CGI] = { TLV_TYPE_TL16V },
377 [NM_ATT_IPACC_RAC] = { TLV_TYPE_TL16V },
378 [NM_ATT_IPACC_OBJ_VERSION] = { TLV_TYPE_TL16V },
379 [NM_ATT_IPACC_GPRS_PAGING_CFG]= { TLV_TYPE_TL16V },
380 [NM_ATT_IPACC_NSEI] = { TLV_TYPE_TL16V },
381 [NM_ATT_IPACC_BVCI] = { TLV_TYPE_TL16V },
382 [NM_ATT_IPACC_NSVCI] = { TLV_TYPE_TL16V },
383 [NM_ATT_IPACC_NS_CFG] = { TLV_TYPE_TL16V },
384 [NM_ATT_IPACC_BSSGP_CFG] = { TLV_TYPE_TL16V },
385 [NM_ATT_IPACC_NS_LINK_CFG] = { TLV_TYPE_TL16V },
386 [NM_ATT_IPACC_RLC_CFG] = { TLV_TYPE_TL16V },
Harald Welte90a93cf2009-07-03 12:46:27 +0200387 [NM_ATT_IPACC_ALM_THRESH_LIST]= { TLV_TYPE_TL16V },
Harald Weltedb1e7442009-08-06 17:57:23 +0200388 [NM_ATT_IPACC_MONIT_VAL_LIST] = { TLV_TYPE_TL16V },
389 [NM_ATT_IPACC_TIB_CONTROL] = { TLV_TYPE_TL16V },
390 [NM_ATT_IPACC_SUPP_FEATURES] = { TLV_TYPE_TL16V },
391 [NM_ATT_IPACC_CODING_SCHEMES] = { TLV_TYPE_TL16V },
392 [NM_ATT_IPACC_RLC_CFG_2] = { TLV_TYPE_TL16V },
393 [NM_ATT_IPACC_HEARTB_TOUT] = { TLV_TYPE_TL16V },
394 [NM_ATT_IPACC_UPTIME] = { TLV_TYPE_TL16V },
395 [NM_ATT_IPACC_RLC_CFG_3] = { TLV_TYPE_TL16V },
396 [NM_ATT_IPACC_SSL_CFG] = { TLV_TYPE_TL16V },
397 [NM_ATT_IPACC_SEC_POSSIBLE] = { TLV_TYPE_TL16V },
398 [NM_ATT_IPACC_IML_SSL_STATE] = { TLV_TYPE_TL16V },
399 [NM_ATT_IPACC_REVOC_DATE] = { TLV_TYPE_TL16V },
Harald Welte90a93cf2009-07-03 12:46:27 +0200400 //[0x95] = { TLV_TYPE_FIXED, 2 },
Harald Welte59b04682009-06-10 05:40:52 +0800401 [0x85] = { TLV_TYPE_TV },
402
403 },
404};
405
Harald Welte35cd5e92009-08-10 12:21:22 +0200406static const enum abis_nm_chan_comb chcomb4pchan[] = {
407 [GSM_PCHAN_CCCH] = NM_CHANC_mainBCCH,
408 [GSM_PCHAN_CCCH_SDCCH4] = NM_CHANC_BCCHComb,
409 [GSM_PCHAN_TCH_F] = NM_CHANC_TCHFull,
410 [GSM_PCHAN_TCH_H] = NM_CHANC_TCHHalf,
411 [GSM_PCHAN_SDCCH8_SACCH8C] = NM_CHANC_SDCCH,
Harald Welte37884ed2009-10-24 10:25:50 +0200412 [GSM_PCHAN_PDCH] = NM_CHANC_IPAC_PDCH,
413 [GSM_PCHAN_TCH_F_PDCH] = NM_CHANC_IPAC_TCHFull_PDCH,
Harald Welte35cd5e92009-08-10 12:21:22 +0200414 /* FIXME: bounds check */
415};
416
417int abis_nm_chcomb4pchan(enum gsm_phys_chan_config pchan)
418{
419 if (pchan < ARRAY_SIZE(chcomb4pchan))
420 return chcomb4pchan[pchan];
421
422 return -EINVAL;
423}
424
Harald Welte59b04682009-06-10 05:40:52 +0800425int abis_nm_tlv_parse(struct tlv_parsed *tp, const u_int8_t *buf, int len)
426{
427 return tlv_parse(tp, &nm_att_tlvdef, buf, len, 0, 0);
428}
429
430static int is_in_arr(enum abis_nm_msgtype mt, const enum abis_nm_msgtype *arr, int size)
431{
432 int i;
433
434 for (i = 0; i < size; i++) {
435 if (arr[i] == mt)
436 return 1;
437 }
438
439 return 0;
440}
441
442#if 0
443/* is this msgtype the usual ACK/NACK type ? */
444static int is_ack_nack(enum abis_nm_msgtype mt)
445{
446 return !is_in_arr(mt, no_ack_nack, ARRAY_SIZE(no_ack_nack));
447}
448#endif
449
450/* is this msgtype a report ? */
451static int is_report(enum abis_nm_msgtype mt)
452{
453 return is_in_arr(mt, reports, ARRAY_SIZE(reports));
454}
455
456#define MT_ACK(x) (x+1)
457#define MT_NACK(x) (x+2)
458
459static void fill_om_hdr(struct abis_om_hdr *oh, u_int8_t len)
460{
461 oh->mdisc = ABIS_OM_MDISC_FOM;
462 oh->placement = ABIS_OM_PLACEMENT_ONLY;
463 oh->sequence = 0;
464 oh->length = len;
465}
466
467static void fill_om_fom_hdr(struct abis_om_hdr *oh, u_int8_t len,
468 u_int8_t msg_type, u_int8_t obj_class,
469 u_int8_t bts_nr, u_int8_t trx_nr, u_int8_t ts_nr)
470{
471 struct abis_om_fom_hdr *foh =
472 (struct abis_om_fom_hdr *) oh->data;
473
474 fill_om_hdr(oh, len+sizeof(*foh));
475 foh->msg_type = msg_type;
476 foh->obj_class = obj_class;
477 foh->obj_inst.bts_nr = bts_nr;
478 foh->obj_inst.trx_nr = trx_nr;
479 foh->obj_inst.ts_nr = ts_nr;
480}
481
482static struct msgb *nm_msgb_alloc(void)
483{
Harald Welte9cfc9352009-06-26 19:39:35 +0200484 return msgb_alloc_headroom(OM_ALLOC_SIZE, OM_HEADROOM_SIZE,
485 "OML");
Harald Welte59b04682009-06-10 05:40:52 +0800486}
487
488/* Send a OML NM Message from BSC to BTS */
489int abis_nm_sendmsg(struct gsm_bts *bts, struct msgb *msg)
490{
491 msg->trx = bts->c0;
492
493 return _abis_nm_sendmsg(msg);
494}
495
496static int abis_nm_rcvmsg_sw(struct msgb *mb);
497
498static const char *obj_class_name(u_int8_t oc)
499{
500 switch (oc) {
501 case NM_OC_SITE_MANAGER:
502 return "SITE MANAGER";
503 case NM_OC_BTS:
504 return "BTS";
505 case NM_OC_RADIO_CARRIER:
506 return "RADIO CARRIER";
507 case NM_OC_BASEB_TRANSC:
508 return "BASEBAND TRANSCEIVER";
509 case NM_OC_CHANNEL:
510 return "CHANNEL";
511 case NM_OC_BS11_ADJC:
512 return "ADJC";
513 case NM_OC_BS11_HANDOVER:
514 return "HANDOVER";
515 case NM_OC_BS11_PWR_CTRL:
516 return "POWER CONTROL";
517 case NM_OC_BS11_BTSE:
518 return "BTSE";
519 case NM_OC_BS11_RACK:
520 return "RACK";
521 case NM_OC_BS11_TEST:
522 return "TEST";
523 case NM_OC_BS11_ENVABTSE:
524 return "ENVABTSE";
525 case NM_OC_BS11_BPORT:
526 return "BPORT";
527 case NM_OC_GPRS_NSE:
528 return "GPRS NSE";
529 case NM_OC_GPRS_CELL:
530 return "GPRS CELL";
Harald Welte8f92cce2009-07-12 10:56:06 +0200531 case NM_OC_GPRS_NSVC:
532 return "GPRS NSVC";
Harald Welte59b04682009-06-10 05:40:52 +0800533 case NM_OC_BS11:
534 return "SIEMENSHW";
535 }
536
537 return "UNKNOWN";
538}
539
540const char *nm_opstate_name(u_int8_t os)
541{
542 switch (os) {
543 case 1:
544 return "Disabled";
545 case 2:
546 return "Enabled";
547 case 0xff:
548 return "NULL";
549 default:
550 return "RFU";
551 }
552}
553
554/* Chapter 9.4.7 */
555static const char *avail_names[] = {
556 "In test",
557 "Failed",
558 "Power off",
559 "Off line",
560 "<not used>",
561 "Dependency",
562 "Degraded",
563 "Not installed",
564};
565
566const char *nm_avail_name(u_int8_t avail)
567{
568 if (avail == 0xff)
569 return "OK";
570 if (avail >= ARRAY_SIZE(avail_names))
571 return "UNKNOWN";
572 return avail_names[avail];
573}
574
575const char *nm_adm_name(u_int8_t adm)
576{
577 switch (adm) {
578 case 1:
579 return "Locked";
580 case 2:
581 return "Unlocked";
582 case 3:
583 return "Shutdown";
584 default:
585 return "<not used>";
586 }
587}
588
Harald Welteb7284a92009-10-20 09:56:18 +0200589static void debugp_foh(struct abis_om_fom_hdr *foh)
590{
591 DEBUGP(DNM, "OC=%s(%02x) INST=(%02x,%02x,%02x) ",
592 obj_class_name(foh->obj_class), foh->obj_class,
593 foh->obj_inst.bts_nr, foh->obj_inst.trx_nr,
594 foh->obj_inst.ts_nr);
595}
596
Harald Welte59b04682009-06-10 05:40:52 +0800597/* obtain the gsm_nm_state data structure for a given object instance */
598static struct gsm_nm_state *
599objclass2nmstate(struct gsm_bts *bts, u_int8_t obj_class,
600 struct abis_om_obj_inst *obj_inst)
601{
602 struct gsm_bts_trx *trx;
603 struct gsm_nm_state *nm_state = NULL;
604
605 switch (obj_class) {
606 case NM_OC_BTS:
607 nm_state = &bts->nm_state;
608 break;
609 case NM_OC_RADIO_CARRIER:
610 if (obj_inst->trx_nr >= bts->num_trx)
611 return NULL;
Harald Weltee712a5f2009-06-21 16:17:15 +0200612 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800613 nm_state = &trx->nm_state;
614 break;
615 case NM_OC_BASEB_TRANSC:
616 if (obj_inst->trx_nr >= bts->num_trx)
617 return NULL;
Harald Weltee712a5f2009-06-21 16:17:15 +0200618 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800619 nm_state = &trx->bb_transc.nm_state;
620 break;
621 case NM_OC_CHANNEL:
622 if (obj_inst->trx_nr > bts->num_trx)
623 return NULL;
Harald Weltee712a5f2009-06-21 16:17:15 +0200624 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800625 if (obj_inst->ts_nr >= TRX_NR_TS)
626 return NULL;
627 nm_state = &trx->ts[obj_inst->ts_nr].nm_state;
628 break;
629 case NM_OC_SITE_MANAGER:
630 nm_state = &bts->site_mgr.nm_state;
631 break;
632 case NM_OC_BS11:
633 switch (obj_inst->bts_nr) {
634 case BS11_OBJ_CCLK:
635 nm_state = &bts->bs11.cclk.nm_state;
636 break;
637 case BS11_OBJ_BBSIG:
638 if (obj_inst->ts_nr > bts->num_trx)
639 return NULL;
Harald Weltee712a5f2009-06-21 16:17:15 +0200640 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800641 nm_state = &trx->bs11.bbsig.nm_state;
642 break;
643 case BS11_OBJ_PA:
644 if (obj_inst->ts_nr > bts->num_trx)
645 return NULL;
Harald Weltee712a5f2009-06-21 16:17:15 +0200646 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800647 nm_state = &trx->bs11.pa.nm_state;
648 break;
649 default:
650 return NULL;
651 }
652 case NM_OC_BS11_RACK:
653 nm_state = &bts->bs11.rack.nm_state;
654 break;
655 case NM_OC_BS11_ENVABTSE:
656 if (obj_inst->trx_nr > ARRAY_SIZE(bts->bs11.envabtse))
657 return NULL;
658 nm_state = &bts->bs11.envabtse[obj_inst->trx_nr].nm_state;
659 break;
Harald Welte439e1282009-10-24 10:19:14 +0200660 case NM_OC_GPRS_NSE:
661 nm_state = &bts->gprs.nse.nm_state;
662 break;
663 case NM_OC_GPRS_CELL:
664 nm_state = &bts->gprs.cell.nm_state;
665 break;
666 case NM_OC_GPRS_NSVC:
667 if (obj_inst->trx_nr > ARRAY_SIZE(bts->gprs.nsvc))
668 return NULL;
669 nm_state = &bts->gprs.nsvc[obj_inst->trx_nr].nm_state;
670 break;
Harald Welte59b04682009-06-10 05:40:52 +0800671 }
672 return nm_state;
673}
674
675/* obtain the in-memory data structure of a given object instance */
676static void *
677objclass2obj(struct gsm_bts *bts, u_int8_t obj_class,
678 struct abis_om_obj_inst *obj_inst)
679{
680 struct gsm_bts_trx *trx;
681 void *obj = NULL;
682
683 switch (obj_class) {
684 case NM_OC_BTS:
685 obj = bts;
686 break;
687 case NM_OC_RADIO_CARRIER:
688 if (obj_inst->trx_nr >= bts->num_trx)
689 return NULL;
Harald Weltee712a5f2009-06-21 16:17:15 +0200690 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800691 obj = trx;
692 break;
693 case NM_OC_BASEB_TRANSC:
694 if (obj_inst->trx_nr >= bts->num_trx)
695 return NULL;
Harald Weltee712a5f2009-06-21 16:17:15 +0200696 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800697 obj = &trx->bb_transc;
698 break;
699 case NM_OC_CHANNEL:
700 if (obj_inst->trx_nr > bts->num_trx)
701 return NULL;
Harald Weltee712a5f2009-06-21 16:17:15 +0200702 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800703 if (obj_inst->ts_nr >= TRX_NR_TS)
704 return NULL;
705 obj = &trx->ts[obj_inst->ts_nr];
706 break;
707 case NM_OC_SITE_MANAGER:
708 obj = &bts->site_mgr;
709 break;
Harald Welte439e1282009-10-24 10:19:14 +0200710 case NM_OC_GPRS_NSE:
711 obj = &bts->gprs.nse;
712 break;
713 case NM_OC_GPRS_CELL:
714 obj = &bts->gprs.cell;
715 break;
716 case NM_OC_GPRS_NSVC:
717 if (obj_inst->trx_nr > ARRAY_SIZE(bts->gprs.nsvc))
718 return NULL;
719 obj = &bts->gprs.nsvc[obj_inst->trx_nr];
720 break;
Harald Welte59b04682009-06-10 05:40:52 +0800721 }
722 return obj;
723}
724
725/* Update the administrative state of a given object in our in-memory data
726 * structures and send an event to the higher layer */
727static int update_admstate(struct gsm_bts *bts, u_int8_t obj_class,
728 struct abis_om_obj_inst *obj_inst, u_int8_t adm_state)
729{
730 struct gsm_nm_state *nm_state, new_state;
731 void *obj;
732 int rc;
733
734 obj = objclass2obj(bts, obj_class, obj_inst);
735 nm_state = objclass2nmstate(bts, obj_class, obj_inst);
736 if (!nm_state)
737 return -1;
738
739 new_state = *nm_state;
740 new_state.administrative = adm_state;
741
742 rc = nm_state_event(EVT_STATECHG_ADM, obj_class, obj, nm_state, &new_state);
743
744 nm_state->administrative = adm_state;
745
746 return rc;
747}
748
749static int abis_nm_rx_statechg_rep(struct msgb *mb)
750{
751 struct abis_om_hdr *oh = msgb_l2(mb);
752 struct abis_om_fom_hdr *foh = msgb_l3(mb);
753 struct gsm_bts *bts = mb->trx->bts;
754 struct tlv_parsed tp;
755 struct gsm_nm_state *nm_state, new_state;
756 int rc;
757
758 DEBUGPC(DNM, "STATE CHG: ");
759
760 memset(&new_state, 0, sizeof(new_state));
761
762 nm_state = objclass2nmstate(bts, foh->obj_class, &foh->obj_inst);
763 if (!nm_state) {
764 DEBUGPC(DNM, "\n");
765 return -EINVAL;
766 }
767
768 new_state = *nm_state;
769
770 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
771 if (TLVP_PRESENT(&tp, NM_ATT_OPER_STATE)) {
772 new_state.operational = *TLVP_VAL(&tp, NM_ATT_OPER_STATE);
773 DEBUGPC(DNM, "OP_STATE=%s ", nm_opstate_name(new_state.operational));
774 }
775 if (TLVP_PRESENT(&tp, NM_ATT_AVAIL_STATUS)) {
776 if (TLVP_LEN(&tp, NM_ATT_AVAIL_STATUS) == 0)
777 new_state.availability = 0xff;
778 else
779 new_state.availability = *TLVP_VAL(&tp, NM_ATT_AVAIL_STATUS);
780 DEBUGPC(DNM, "AVAIL=%s(%02x) ", nm_avail_name(new_state.availability),
781 new_state.availability);
782 }
783 if (TLVP_PRESENT(&tp, NM_ATT_ADM_STATE)) {
784 new_state.administrative = *TLVP_VAL(&tp, NM_ATT_ADM_STATE);
Holger Hans Peter Freyther460fb3b2009-10-22 15:44:30 +0200785 DEBUGPC(DNM, "ADM=%2s ", nm_adm_name(new_state.administrative));
Harald Welte59b04682009-06-10 05:40:52 +0800786 }
787 DEBUGPC(DNM, "\n");
788
789 if (memcmp(&new_state, nm_state, sizeof(new_state))) {
790 /* Update the operational state of a given object in our in-memory data
791 * structures and send an event to the higher layer */
792 void *obj = objclass2obj(bts, foh->obj_class, &foh->obj_inst);
793 rc = nm_state_event(EVT_STATECHG_OPER, foh->obj_class, obj, nm_state, &new_state);
794 *nm_state = new_state;
795 }
796#if 0
797 if (op_state == 1) {
798 /* try to enable objects that are disabled */
799 abis_nm_opstart(bts, foh->obj_class,
800 foh->obj_inst.bts_nr,
801 foh->obj_inst.trx_nr,
802 foh->obj_inst.ts_nr);
803 }
804#endif
805 return 0;
806}
807
808static int rx_fail_evt_rep(struct msgb *mb)
809{
810 struct abis_om_hdr *oh = msgb_l2(mb);
811 struct abis_om_fom_hdr *foh = msgb_l3(mb);
812 struct tlv_parsed tp;
813
814 DEBUGPC(DNM, "Failure Event Report ");
815
816 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
817
818 if (TLVP_PRESENT(&tp, NM_ATT_EVENT_TYPE))
819 DEBUGPC(DNM, "Type=%s ", event_type_name(*TLVP_VAL(&tp, NM_ATT_EVENT_TYPE)));
820 if (TLVP_PRESENT(&tp, NM_ATT_SEVERITY))
821 DEBUGPC(DNM, "Severity=%s ", severity_name(*TLVP_VAL(&tp, NM_ATT_SEVERITY)));
822
823 DEBUGPC(DNM, "\n");
824
825 return 0;
826}
827
828static int abis_nm_rcvmsg_report(struct msgb *mb)
829{
830 struct abis_om_fom_hdr *foh = msgb_l3(mb);
831 u_int8_t mt = foh->msg_type;
832
Harald Welteb7284a92009-10-20 09:56:18 +0200833 debugp_foh(foh);
Harald Welte59b04682009-06-10 05:40:52 +0800834
835 //nmh->cfg->report_cb(mb, foh);
836
837 switch (mt) {
838 case NM_MT_STATECHG_EVENT_REP:
839 return abis_nm_rx_statechg_rep(mb);
840 break;
841 case NM_MT_SW_ACTIVATED_REP:
842 DEBUGPC(DNM, "Software Activated Report\n");
843 dispatch_signal(SS_NM, S_NM_SW_ACTIV_REP, mb);
844 break;
845 case NM_MT_FAILURE_EVENT_REP:
846 rx_fail_evt_rep(mb);
847 dispatch_signal(SS_NM, S_NM_FAIL_REP, mb);
848 break;
Harald Welte0bf8e302009-08-08 00:02:36 +0200849 case NM_MT_TEST_REP:
850 DEBUGPC(DNM, "Test Report\n");
851 dispatch_signal(SS_NM, S_NM_TEST_REP, mb);
852 break;
Harald Welte59b04682009-06-10 05:40:52 +0800853 default:
854 DEBUGPC(DNM, "reporting NM MT 0x%02x\n", mt);
855 break;
856
857 };
858
859 return 0;
860}
861
862/* Activate the specified software into the BTS */
863static int ipacc_sw_activate(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1,
Mike Haben322fc582009-10-01 14:56:13 +0200864 u_int8_t i2, const u_int8_t *sw_desc, u_int8_t swdesc_len)
Harald Welte59b04682009-06-10 05:40:52 +0800865{
866 struct abis_om_hdr *oh;
867 struct msgb *msg = nm_msgb_alloc();
868 u_int8_t len = swdesc_len;
869 u_int8_t *trailer;
870
871 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
872 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, obj_class, i0, i1, i2);
873
874 trailer = msgb_put(msg, swdesc_len);
875 memcpy(trailer, sw_desc, swdesc_len);
876
877 return abis_nm_sendmsg(bts, msg);
878}
879
880static int abis_nm_rx_sw_act_req(struct msgb *mb)
881{
882 struct abis_om_hdr *oh = msgb_l2(mb);
883 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Mike Haben322fc582009-10-01 14:56:13 +0200884 struct tlv_parsed tp;
885 const u_int8_t *sw_config;
886 int sw_config_len;
887 int file_id_len;
Harald Welte59b04682009-06-10 05:40:52 +0800888 int nack = 0;
889 int ret;
890
Harald Welteb7284a92009-10-20 09:56:18 +0200891 debugp_foh(foh);
892
893 DEBUGPC(DNM, "SW Activate Request: ");
Harald Welte59b04682009-06-10 05:40:52 +0800894
895 if (foh->obj_class >= 0xf0 && foh->obj_class <= 0xf3) {
896 DEBUGPC(DNM, "NACKing for GPRS obj_class 0x%02x\n", foh->obj_class);
897 nack = 1;
898 } else
899 DEBUGPC(DNM, "ACKing and Activating\n");
900
901 ret = abis_nm_sw_act_req_ack(mb->trx->bts, foh->obj_class,
902 foh->obj_inst.bts_nr,
903 foh->obj_inst.trx_nr,
904 foh->obj_inst.ts_nr, nack,
905 foh->data, oh->length-sizeof(*foh));
906
907 if (nack)
908 return ret;
909
Mike Haben322fc582009-10-01 14:56:13 +0200910 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
911 sw_config = TLVP_VAL(&tp, NM_ATT_SW_CONFIG);
912 sw_config_len = TLVP_LEN(&tp, NM_ATT_SW_CONFIG);
913 if (!TLVP_PRESENT(&tp, NM_ATT_SW_CONFIG)) {
914 DEBUGP(DNM, "SW config not found! Can't continue.\n");
915 return -EINVAL;
916 } else {
917 DEBUGP(DNM, "Found SW config: %s\n", hexdump(sw_config, sw_config_len));
918 }
919
920 if (sw_config[0] != NM_ATT_SW_DESCR)
921 DEBUGP(DNM, "SW_DESCR attribute identifier not found!\n");
922 if (sw_config[1] != NM_ATT_FILE_ID)
923 DEBUGP(DNM, "FILE_ID attribute identifier not found!\n");
924 file_id_len = sw_config[2] * 256 + sw_config[3];
925
926 /* Assumes first SW file in list is the one to be activated */
927 /* sw_config + 4 to skip over 2 attribute ID bytes and 16-bit length field */
Harald Welte59b04682009-06-10 05:40:52 +0800928 return ipacc_sw_activate(mb->trx->bts, foh->obj_class,
929 foh->obj_inst.bts_nr,
930 foh->obj_inst.trx_nr,
931 foh->obj_inst.ts_nr,
Mike Haben322fc582009-10-01 14:56:13 +0200932 sw_config + 4,
933 file_id_len);
Harald Welte59b04682009-06-10 05:40:52 +0800934}
935
936/* Receive a CHANGE_ADM_STATE_ACK, parse the TLV and update local state */
937static int abis_nm_rx_chg_adm_state_ack(struct msgb *mb)
938{
939 struct abis_om_hdr *oh = msgb_l2(mb);
940 struct abis_om_fom_hdr *foh = msgb_l3(mb);
941 struct tlv_parsed tp;
942 u_int8_t adm_state;
943
944 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
945 if (!TLVP_PRESENT(&tp, NM_ATT_ADM_STATE))
946 return -EINVAL;
947
948 adm_state = *TLVP_VAL(&tp, NM_ATT_ADM_STATE);
949
950 return update_admstate(mb->trx->bts, foh->obj_class, &foh->obj_inst, adm_state);
951}
952
953static int abis_nm_rx_lmt_event(struct msgb *mb)
954{
955 struct abis_om_hdr *oh = msgb_l2(mb);
956 struct abis_om_fom_hdr *foh = msgb_l3(mb);
957 struct tlv_parsed tp;
958
959 DEBUGP(DNM, "LMT Event ");
960 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
961 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_LOGON_SESSION) &&
962 TLVP_LEN(&tp, NM_ATT_BS11_LMT_LOGON_SESSION) >= 1) {
963 u_int8_t onoff = *TLVP_VAL(&tp, NM_ATT_BS11_LMT_LOGON_SESSION);
964 DEBUGPC(DNM, "LOG%s ", onoff ? "ON" : "OFF");
965 }
966 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV) &&
967 TLVP_LEN(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV) >= 1) {
968 u_int8_t level = *TLVP_VAL(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV);
969 DEBUGPC(DNM, "Level=%u ", level);
970 }
971 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_USER_NAME) &&
972 TLVP_LEN(&tp, NM_ATT_BS11_LMT_USER_NAME) >= 1) {
973 char *name = (char *) TLVP_VAL(&tp, NM_ATT_BS11_LMT_USER_NAME);
974 DEBUGPC(DNM, "Username=%s ", name);
975 }
976 DEBUGPC(DNM, "\n");
977 /* FIXME: parse LMT LOGON TIME */
978 return 0;
979}
980
981/* Receive a OML NM Message from BTS */
982static int abis_nm_rcvmsg_fom(struct msgb *mb)
983{
984 struct abis_om_hdr *oh = msgb_l2(mb);
985 struct abis_om_fom_hdr *foh = msgb_l3(mb);
986 u_int8_t mt = foh->msg_type;
987
988 /* check for unsolicited message */
989 if (is_report(mt))
990 return abis_nm_rcvmsg_report(mb);
991
992 if (is_in_arr(mt, sw_load_msgs, ARRAY_SIZE(sw_load_msgs)))
993 return abis_nm_rcvmsg_sw(mb);
994
995 if (is_in_arr(mt, nacks, ARRAY_SIZE(nacks))) {
996 struct tlv_parsed tp;
Harald Welte935d10b2009-10-08 20:18:59 +0200997
Harald Welteb7284a92009-10-20 09:56:18 +0200998 debugp_foh(foh);
Harald Welte935d10b2009-10-08 20:18:59 +0200999
Harald Welte59b04682009-06-10 05:40:52 +08001000 if (nack_names[mt])
Harald Welte935d10b2009-10-08 20:18:59 +02001001 DEBUGPC(DNM, "%s NACK ", nack_names[mt]);
Harald Welte59b04682009-06-10 05:40:52 +08001002 /* FIXME: NACK cause */
1003 else
Harald Welte935d10b2009-10-08 20:18:59 +02001004 DEBUGPC(DNM, "NACK 0x%02x ", mt);
Harald Welte59b04682009-06-10 05:40:52 +08001005
1006 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
1007 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
1008 DEBUGPC(DNM, "CAUSE=%s\n",
1009 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
1010 else
1011 DEBUGPC(DNM, "\n");
Holger Hans Peter Freytherefedf942009-06-10 10:48:14 +02001012
1013 dispatch_signal(SS_NM, S_NM_NACK, (void*) ((long)mt));
1014 return 0;
Harald Welte59b04682009-06-10 05:40:52 +08001015 }
1016#if 0
1017 /* check if last message is to be acked */
1018 if (is_ack_nack(nmh->last_msgtype)) {
1019 if (mt == MT_ACK(nmh->last_msgtype)) {
1020 fprintf(stderr, "received ACK (0x%x)\n",
1021 foh->msg_type);
1022 /* we got our ACK, continue sending the next msg */
1023 } else if (mt == MT_NACK(nmh->last_msgtype)) {
1024 /* we got a NACK, signal this to the caller */
1025 fprintf(stderr, "received NACK (0x%x)\n",
1026 foh->msg_type);
1027 /* FIXME: somehow signal this to the caller */
1028 } else {
1029 /* really strange things happen */
1030 return -EINVAL;
1031 }
1032 }
1033#endif
1034
1035 switch (mt) {
1036 case NM_MT_CHG_ADM_STATE_ACK:
1037 return abis_nm_rx_chg_adm_state_ack(mb);
1038 break;
1039 case NM_MT_SW_ACT_REQ:
1040 return abis_nm_rx_sw_act_req(mb);
1041 break;
1042 case NM_MT_BS11_LMT_SESSION:
1043 return abis_nm_rx_lmt_event(mb);
1044 break;
Harald Welte204317e2009-08-06 17:58:31 +02001045 case NM_MT_CONN_MDROP_LINK_ACK:
1046 DEBUGP(DNM, "CONN MDROP LINK ACK\n");
1047 break;
Harald Welte59b04682009-06-10 05:40:52 +08001048 }
1049
1050 return 0;
1051}
1052
1053static int abis_nm_rx_ipacc(struct msgb *mb);
1054
1055static int abis_nm_rcvmsg_manuf(struct msgb *mb)
1056{
1057 int rc;
1058 int bts_type = mb->trx->bts->type;
1059
1060 switch (bts_type) {
Mike Haben66e0ba02009-10-02 12:19:34 +01001061 case GSM_BTS_TYPE_NANOBTS:
Harald Welte59b04682009-06-10 05:40:52 +08001062 rc = abis_nm_rx_ipacc(mb);
1063 break;
1064 default:
1065 fprintf(stderr, "don't know how to parse OML for this "
1066 "BTS type (%u)\n", bts_type);
1067 rc = 0;
1068 break;
1069 }
1070
1071 return rc;
1072}
1073
1074/* High-Level API */
1075/* Entry-point where L2 OML from BTS enters the NM code */
1076int abis_nm_rcvmsg(struct msgb *msg)
1077{
1078 struct abis_om_hdr *oh = msgb_l2(msg);
1079 int rc = 0;
1080
1081 /* Various consistency checks */
1082 if (oh->placement != ABIS_OM_PLACEMENT_ONLY) {
1083 fprintf(stderr, "ABIS OML placement 0x%x not supported\n",
1084 oh->placement);
1085 return -EINVAL;
1086 }
1087 if (oh->sequence != 0) {
1088 fprintf(stderr, "ABIS OML sequence 0x%x != 0x00\n",
1089 oh->sequence);
1090 return -EINVAL;
1091 }
1092#if 0
1093 unsigned int l2_len = msg->tail - (u_int8_t *)msgb_l2(msg);
1094 unsigned int hlen = sizeof(*oh) + sizeof(struct abis_om_fom_hdr);
1095 if (oh->length + hlen > l2_len) {
1096 fprintf(stderr, "ABIS OML truncated message (%u > %u)\n",
1097 oh->length + sizeof(*oh), l2_len);
1098 return -EINVAL;
1099 }
1100 if (oh->length + hlen < l2_len)
1101 fprintf(stderr, "ABIS OML message with extra trailer?!? (oh->len=%d, sizeof_oh=%d l2_len=%d\n", oh->length, sizeof(*oh), l2_len);
1102#endif
1103 msg->l3h = (unsigned char *)oh + sizeof(*oh);
1104
1105 switch (oh->mdisc) {
1106 case ABIS_OM_MDISC_FOM:
1107 rc = abis_nm_rcvmsg_fom(msg);
1108 break;
1109 case ABIS_OM_MDISC_MANUF:
1110 rc = abis_nm_rcvmsg_manuf(msg);
1111 break;
1112 case ABIS_OM_MDISC_MMI:
1113 case ABIS_OM_MDISC_TRAU:
1114 fprintf(stderr, "unimplemented ABIS OML message discriminator 0x%x\n",
1115 oh->mdisc);
1116 break;
1117 default:
1118 fprintf(stderr, "unknown ABIS OML message discriminator 0x%x\n",
1119 oh->mdisc);
1120 return -EINVAL;
1121 }
1122
1123 msgb_free(msg);
1124 return rc;
1125}
1126
1127#if 0
1128/* initialized all resources */
1129struct abis_nm_h *abis_nm_init(struct abis_nm_cfg *cfg)
1130{
1131 struct abis_nm_h *nmh;
1132
1133 nmh = malloc(sizeof(*nmh));
1134 if (!nmh)
1135 return NULL;
1136
1137 nmh->cfg = cfg;
1138
1139 return nmh;
1140}
1141
1142/* free all resources */
1143void abis_nm_fini(struct abis_nm_h *nmh)
1144{
1145 free(nmh);
1146}
1147#endif
1148
1149/* Here we are trying to define a high-level API that can be used by
1150 * the actual BSC implementation. However, the architecture is currently
1151 * still under design. Ideally the calls to this API would be synchronous,
1152 * while the underlying stack behind the APi runs in a traditional select
1153 * based state machine.
1154 */
1155
1156/* 6.2 Software Load: */
1157enum sw_state {
1158 SW_STATE_NONE,
1159 SW_STATE_WAIT_INITACK,
1160 SW_STATE_WAIT_SEGACK,
1161 SW_STATE_WAIT_ENDACK,
1162 SW_STATE_WAIT_ACTACK,
1163 SW_STATE_ERROR,
1164};
1165
1166struct abis_nm_sw {
1167 struct gsm_bts *bts;
1168 gsm_cbfn *cbfn;
1169 void *cb_data;
1170 int forced;
1171
1172 /* this will become part of the SW LOAD INITIATE */
1173 u_int8_t obj_class;
1174 u_int8_t obj_instance[3];
1175
1176 u_int8_t file_id[255];
1177 u_int8_t file_id_len;
1178
1179 u_int8_t file_version[255];
1180 u_int8_t file_version_len;
1181
1182 u_int8_t window_size;
1183 u_int8_t seg_in_window;
1184
1185 int fd;
1186 FILE *stream;
1187 enum sw_state state;
1188 int last_seg;
1189};
1190
1191static struct abis_nm_sw g_sw;
1192
1193/* 6.2.1 / 8.3.1: Load Data Initiate */
1194static int sw_load_init(struct abis_nm_sw *sw)
1195{
1196 struct abis_om_hdr *oh;
1197 struct msgb *msg = nm_msgb_alloc();
1198 u_int8_t len = 3*2 + sw->file_id_len + sw->file_version_len;
1199
1200 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1201 fill_om_fom_hdr(oh, len, NM_MT_LOAD_INIT, sw->obj_class,
1202 sw->obj_instance[0], sw->obj_instance[1],
1203 sw->obj_instance[2]);
1204
1205 /* FIXME: this is BS11 specific format */
1206 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1207 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1208 sw->file_version);
1209 msgb_tv_put(msg, NM_ATT_WINDOW_SIZE, sw->window_size);
1210
1211 return abis_nm_sendmsg(sw->bts, msg);
1212}
1213
1214static int is_last_line(FILE *stream)
1215{
1216 char next_seg_buf[256];
1217 long pos;
1218
1219 /* check if we're sending the last line */
1220 pos = ftell(stream);
1221 if (!fgets(next_seg_buf, sizeof(next_seg_buf)-2, stream)) {
1222 fseek(stream, pos, SEEK_SET);
1223 return 1;
1224 }
1225
1226 fseek(stream, pos, SEEK_SET);
1227 return 0;
1228}
1229
1230/* 6.2.2 / 8.3.2 Load Data Segment */
1231static int sw_load_segment(struct abis_nm_sw *sw)
1232{
1233 struct abis_om_hdr *oh;
1234 struct msgb *msg = nm_msgb_alloc();
1235 char seg_buf[256];
1236 char *line_buf = seg_buf+2;
1237 unsigned char *tlv;
1238 u_int8_t len;
1239
1240 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1241
1242 switch (sw->bts->type) {
1243 case GSM_BTS_TYPE_BS11:
1244 if (fgets(line_buf, sizeof(seg_buf)-2, sw->stream) == NULL) {
1245 perror("fgets reading segment");
1246 return -EINVAL;
1247 }
1248 seg_buf[0] = 0x00;
1249
1250 /* check if we're sending the last line */
1251 sw->last_seg = is_last_line(sw->stream);
1252 if (sw->last_seg)
1253 seg_buf[1] = 0;
1254 else
1255 seg_buf[1] = 1 + sw->seg_in_window++;
1256
1257 len = strlen(line_buf) + 2;
1258 tlv = msgb_put(msg, TLV_GROSS_LEN(len));
1259 tlv_put(tlv, NM_ATT_BS11_FILE_DATA, len, (u_int8_t *)seg_buf);
1260 /* BS11 wants CR + LF in excess of the TLV length !?! */
1261 tlv[1] -= 2;
1262
1263 /* we only now know the exact length for the OM hdr */
1264 len = strlen(line_buf)+2;
1265 break;
1266 default:
1267 /* FIXME: Other BTS types */
1268 return -1;
1269 }
1270
1271 fill_om_fom_hdr(oh, len, NM_MT_LOAD_SEG, sw->obj_class,
1272 sw->obj_instance[0], sw->obj_instance[1],
1273 sw->obj_instance[2]);
1274
1275 return abis_nm_sendmsg(sw->bts, msg);
1276}
1277
1278/* 6.2.4 / 8.3.4 Load Data End */
1279static int sw_load_end(struct abis_nm_sw *sw)
1280{
1281 struct abis_om_hdr *oh;
1282 struct msgb *msg = nm_msgb_alloc();
1283 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
1284
1285 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1286 fill_om_fom_hdr(oh, len, NM_MT_LOAD_END, sw->obj_class,
1287 sw->obj_instance[0], sw->obj_instance[1],
1288 sw->obj_instance[2]);
1289
1290 /* FIXME: this is BS11 specific format */
1291 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1292 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1293 sw->file_version);
1294
1295 return abis_nm_sendmsg(sw->bts, msg);
1296}
1297
1298/* Activate the specified software into the BTS */
1299static int sw_activate(struct abis_nm_sw *sw)
1300{
1301 struct abis_om_hdr *oh;
1302 struct msgb *msg = nm_msgb_alloc();
1303 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
1304
1305 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1306 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, sw->obj_class,
1307 sw->obj_instance[0], sw->obj_instance[1],
1308 sw->obj_instance[2]);
1309
1310 /* FIXME: this is BS11 specific format */
1311 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1312 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1313 sw->file_version);
1314
1315 return abis_nm_sendmsg(sw->bts, msg);
1316}
1317
1318static int sw_open_file(struct abis_nm_sw *sw, const char *fname)
1319{
1320 char file_id[12+1];
1321 char file_version[80+1];
1322 int rc;
1323
1324 sw->fd = open(fname, O_RDONLY);
1325 if (sw->fd < 0)
1326 return sw->fd;
1327
1328 switch (sw->bts->type) {
1329 case GSM_BTS_TYPE_BS11:
1330 sw->stream = fdopen(sw->fd, "r");
1331 if (!sw->stream) {
1332 perror("fdopen");
1333 return -1;
1334 }
1335 /* read first line and parse file ID and VERSION */
1336 rc = fscanf(sw->stream, "@(#)%12s:%80s\r\n",
1337 file_id, file_version);
1338 if (rc != 2) {
1339 perror("parsing header line of software file");
1340 return -1;
1341 }
1342 strcpy((char *)sw->file_id, file_id);
1343 sw->file_id_len = strlen(file_id);
1344 strcpy((char *)sw->file_version, file_version);
1345 sw->file_version_len = strlen(file_version);
1346 /* rewind to start of file */
1347 rewind(sw->stream);
1348 break;
1349 default:
1350 /* We don't know how to treat them yet */
1351 close(sw->fd);
1352 return -EINVAL;
1353 }
1354
1355 return 0;
1356}
1357
1358static void sw_close_file(struct abis_nm_sw *sw)
1359{
1360 switch (sw->bts->type) {
1361 case GSM_BTS_TYPE_BS11:
1362 fclose(sw->stream);
1363 break;
1364 default:
1365 close(sw->fd);
1366 break;
1367 }
1368}
1369
1370/* Fill the window */
1371static int sw_fill_window(struct abis_nm_sw *sw)
1372{
1373 int rc;
1374
1375 while (sw->seg_in_window < sw->window_size) {
1376 rc = sw_load_segment(sw);
1377 if (rc < 0)
1378 return rc;
1379 if (sw->last_seg)
1380 break;
1381 }
1382 return 0;
1383}
1384
1385/* callback function from abis_nm_rcvmsg() handler */
1386static int abis_nm_rcvmsg_sw(struct msgb *mb)
1387{
1388 struct abis_om_fom_hdr *foh = msgb_l3(mb);
1389 int rc = -1;
1390 struct abis_nm_sw *sw = &g_sw;
1391 enum sw_state old_state = sw->state;
1392
1393 //DEBUGP(DNM, "state %u, NM MT 0x%02x\n", sw->state, foh->msg_type);
1394
1395 switch (sw->state) {
1396 case SW_STATE_WAIT_INITACK:
1397 switch (foh->msg_type) {
1398 case NM_MT_LOAD_INIT_ACK:
1399 /* fill window with segments */
1400 if (sw->cbfn)
1401 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1402 NM_MT_LOAD_INIT_ACK, mb,
1403 sw->cb_data, NULL);
1404 rc = sw_fill_window(sw);
1405 sw->state = SW_STATE_WAIT_SEGACK;
1406 break;
1407 case NM_MT_LOAD_INIT_NACK:
1408 if (sw->forced) {
1409 DEBUGP(DNM, "FORCED: Ignoring Software Load "
1410 "Init NACK\n");
1411 if (sw->cbfn)
1412 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1413 NM_MT_LOAD_INIT_ACK, mb,
1414 sw->cb_data, NULL);
1415 rc = sw_fill_window(sw);
1416 sw->state = SW_STATE_WAIT_SEGACK;
1417 } else {
1418 DEBUGP(DNM, "Software Load Init NACK\n");
1419 /* FIXME: cause */
1420 if (sw->cbfn)
1421 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1422 NM_MT_LOAD_INIT_NACK, mb,
1423 sw->cb_data, NULL);
1424 sw->state = SW_STATE_ERROR;
1425 }
1426 break;
1427 }
1428 break;
1429 case SW_STATE_WAIT_SEGACK:
1430 switch (foh->msg_type) {
1431 case NM_MT_LOAD_SEG_ACK:
1432 if (sw->cbfn)
1433 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1434 NM_MT_LOAD_SEG_ACK, mb,
1435 sw->cb_data, NULL);
1436 sw->seg_in_window = 0;
1437 if (!sw->last_seg) {
1438 /* fill window with more segments */
1439 rc = sw_fill_window(sw);
1440 sw->state = SW_STATE_WAIT_SEGACK;
1441 } else {
1442 /* end the transfer */
1443 sw->state = SW_STATE_WAIT_ENDACK;
1444 rc = sw_load_end(sw);
1445 }
1446 break;
1447 }
1448 break;
1449 case SW_STATE_WAIT_ENDACK:
1450 switch (foh->msg_type) {
1451 case NM_MT_LOAD_END_ACK:
1452 sw_close_file(sw);
1453 DEBUGP(DNM, "Software Load End (BTS %u)\n",
1454 sw->bts->nr);
1455 sw->state = SW_STATE_NONE;
1456 if (sw->cbfn)
1457 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1458 NM_MT_LOAD_END_ACK, mb,
1459 sw->cb_data, NULL);
1460 break;
1461 case NM_MT_LOAD_END_NACK:
1462 if (sw->forced) {
1463 DEBUGP(DNM, "FORCED: Ignoring Software Load"
1464 "End NACK\n");
1465 sw->state = SW_STATE_NONE;
1466 if (sw->cbfn)
1467 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1468 NM_MT_LOAD_END_ACK, mb,
1469 sw->cb_data, NULL);
1470 } else {
1471 DEBUGP(DNM, "Software Load End NACK\n");
1472 /* FIXME: cause */
1473 sw->state = SW_STATE_ERROR;
1474 if (sw->cbfn)
1475 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1476 NM_MT_LOAD_END_NACK, mb,
1477 sw->cb_data, NULL);
1478 }
1479 break;
1480 }
1481 case SW_STATE_WAIT_ACTACK:
1482 switch (foh->msg_type) {
1483 case NM_MT_ACTIVATE_SW_ACK:
1484 /* we're done */
1485 DEBUGP(DNM, "Activate Software DONE!\n");
1486 sw->state = SW_STATE_NONE;
1487 rc = 0;
1488 if (sw->cbfn)
1489 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1490 NM_MT_ACTIVATE_SW_ACK, mb,
1491 sw->cb_data, NULL);
1492 break;
1493 case NM_MT_ACTIVATE_SW_NACK:
1494 DEBUGP(DNM, "Activate Software NACK\n");
1495 /* FIXME: cause */
1496 sw->state = SW_STATE_ERROR;
1497 if (sw->cbfn)
1498 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1499 NM_MT_ACTIVATE_SW_NACK, mb,
1500 sw->cb_data, NULL);
1501 break;
1502 }
1503 case SW_STATE_NONE:
1504 switch (foh->msg_type) {
1505 case NM_MT_ACTIVATE_SW_ACK:
1506 rc = 0;
1507 break;
1508 }
1509 break;
1510 case SW_STATE_ERROR:
1511 break;
1512 }
1513
1514 if (rc)
1515 DEBUGP(DNM, "unexpected NM MT 0x%02x in state %u -> %u\n",
1516 foh->msg_type, old_state, sw->state);
1517
1518 return rc;
1519}
1520
1521/* Load the specified software into the BTS */
1522int abis_nm_software_load(struct gsm_bts *bts, const char *fname,
1523 u_int8_t win_size, int forced,
1524 gsm_cbfn *cbfn, void *cb_data)
1525{
1526 struct abis_nm_sw *sw = &g_sw;
1527 int rc;
1528
1529 DEBUGP(DNM, "Software Load (BTS %u, File \"%s\")\n",
1530 bts->nr, fname);
1531
1532 if (sw->state != SW_STATE_NONE)
1533 return -EBUSY;
1534
1535 sw->bts = bts;
1536 sw->obj_class = NM_OC_SITE_MANAGER;
1537 sw->obj_instance[0] = 0xff;
1538 sw->obj_instance[1] = 0xff;
1539 sw->obj_instance[2] = 0xff;
1540 sw->window_size = win_size;
1541 sw->state = SW_STATE_WAIT_INITACK;
1542 sw->cbfn = cbfn;
1543 sw->cb_data = cb_data;
1544 sw->forced = forced;
1545
1546 rc = sw_open_file(sw, fname);
1547 if (rc < 0) {
1548 sw->state = SW_STATE_NONE;
1549 return rc;
1550 }
1551
1552 return sw_load_init(sw);
1553}
1554
1555int abis_nm_software_load_status(struct gsm_bts *bts)
1556{
1557 struct abis_nm_sw *sw = &g_sw;
1558 struct stat st;
1559 int rc, percent;
1560
1561 rc = fstat(sw->fd, &st);
1562 if (rc < 0) {
1563 perror("ERROR during stat");
1564 return rc;
1565 }
1566
1567 percent = (ftell(sw->stream) * 100) / st.st_size;
1568 return percent;
1569}
1570
1571/* Activate the specified software into the BTS */
1572int abis_nm_software_activate(struct gsm_bts *bts, const char *fname,
1573 gsm_cbfn *cbfn, void *cb_data)
1574{
1575 struct abis_nm_sw *sw = &g_sw;
1576 int rc;
1577
1578 DEBUGP(DNM, "Activating Software (BTS %u, File \"%s\")\n",
1579 bts->nr, fname);
1580
1581 if (sw->state != SW_STATE_NONE)
1582 return -EBUSY;
1583
1584 sw->bts = bts;
1585 sw->obj_class = NM_OC_SITE_MANAGER;
1586 sw->obj_instance[0] = 0xff;
1587 sw->obj_instance[1] = 0xff;
1588 sw->obj_instance[2] = 0xff;
1589 sw->state = SW_STATE_WAIT_ACTACK;
1590 sw->cbfn = cbfn;
1591 sw->cb_data = cb_data;
1592
1593 /* Open the file in order to fill some sw struct members */
1594 rc = sw_open_file(sw, fname);
1595 if (rc < 0) {
1596 sw->state = SW_STATE_NONE;
1597 return rc;
1598 }
1599 sw_close_file(sw);
1600
1601 return sw_activate(sw);
1602}
1603
1604static void fill_nm_channel(struct abis_nm_channel *ch, u_int8_t bts_port,
1605 u_int8_t ts_nr, u_int8_t subslot_nr)
1606{
1607 ch->attrib = NM_ATT_ABIS_CHANNEL;
1608 ch->bts_port = bts_port;
1609 ch->timeslot = ts_nr;
1610 ch->subslot = subslot_nr;
1611}
1612
1613int abis_nm_establish_tei(struct gsm_bts *bts, u_int8_t trx_nr,
1614 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot,
1615 u_int8_t tei)
1616{
1617 struct abis_om_hdr *oh;
1618 struct abis_nm_channel *ch;
1619 u_int8_t len = sizeof(*ch) + 2;
1620 struct msgb *msg = nm_msgb_alloc();
1621
1622 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1623 fill_om_fom_hdr(oh, len, NM_MT_ESTABLISH_TEI, NM_OC_RADIO_CARRIER,
1624 bts->bts_nr, trx_nr, 0xff);
1625
1626 msgb_tv_put(msg, NM_ATT_TEI, tei);
1627
1628 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1629 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1630
1631 return abis_nm_sendmsg(bts, msg);
1632}
1633
1634/* connect signalling of one (BTS,TRX) to a particular timeslot on the E1 */
1635int abis_nm_conn_terr_sign(struct gsm_bts_trx *trx,
1636 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot)
1637{
1638 struct gsm_bts *bts = trx->bts;
1639 struct abis_om_hdr *oh;
1640 struct abis_nm_channel *ch;
1641 struct msgb *msg = nm_msgb_alloc();
1642
1643 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1644 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_SIGN,
1645 NM_OC_RADIO_CARRIER, bts->bts_nr, trx->nr, 0xff);
1646
1647 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1648 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1649
1650 return abis_nm_sendmsg(bts, msg);
1651}
1652
1653#if 0
1654int abis_nm_disc_terr_sign(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1655 struct abis_nm_abis_channel *chan)
1656{
1657}
1658#endif
1659
1660int abis_nm_conn_terr_traf(struct gsm_bts_trx_ts *ts,
1661 u_int8_t e1_port, u_int8_t e1_timeslot,
1662 u_int8_t e1_subslot)
1663{
1664 struct gsm_bts *bts = ts->trx->bts;
1665 struct abis_om_hdr *oh;
1666 struct abis_nm_channel *ch;
1667 struct msgb *msg = nm_msgb_alloc();
1668
1669 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1670 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_TRAF,
1671 NM_OC_CHANNEL, bts->bts_nr, ts->trx->nr, ts->nr);
1672
1673 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1674 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1675
1676 DEBUGP(DNM, "CONNECT TERR TRAF Um=%s E1=(%u,%u,%u)\n",
1677 gsm_ts_name(ts),
1678 e1_port, e1_timeslot, e1_subslot);
1679
1680 return abis_nm_sendmsg(bts, msg);
1681}
1682
1683#if 0
1684int abis_nm_disc_terr_traf(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1685 struct abis_nm_abis_channel *chan,
1686 u_int8_t subchan)
1687{
1688}
1689#endif
1690
1691/* Chapter 8.6.1 */
1692int abis_nm_set_bts_attr(struct gsm_bts *bts, u_int8_t *attr, int attr_len)
1693{
1694 struct abis_om_hdr *oh;
1695 struct msgb *msg = nm_msgb_alloc();
1696 u_int8_t *cur;
1697
1698 DEBUGP(DNM, "Set BTS Attr (bts=%d)\n", bts->nr);
1699
1700 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1701 fill_om_fom_hdr(oh, attr_len, NM_MT_SET_BTS_ATTR, NM_OC_BTS, bts->bts_nr, 0xff, 0xff);
1702 cur = msgb_put(msg, attr_len);
1703 memcpy(cur, attr, attr_len);
1704
1705 return abis_nm_sendmsg(bts, msg);
1706}
1707
1708/* Chapter 8.6.2 */
1709int abis_nm_set_radio_attr(struct gsm_bts_trx *trx, u_int8_t *attr, int attr_len)
1710{
1711 struct abis_om_hdr *oh;
1712 struct msgb *msg = nm_msgb_alloc();
1713 u_int8_t *cur;
1714
1715 DEBUGP(DNM, "Set TRX Attr (bts=%d,trx=%d)\n", trx->bts->nr, trx->nr);
1716
1717 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1718 fill_om_fom_hdr(oh, attr_len, NM_MT_SET_RADIO_ATTR, NM_OC_RADIO_CARRIER,
1719 trx->bts->bts_nr, trx->nr, 0xff);
1720 cur = msgb_put(msg, attr_len);
1721 memcpy(cur, attr, attr_len);
1722
1723 return abis_nm_sendmsg(trx->bts, msg);
1724}
1725
Harald Weltef2eb2782009-08-09 21:49:48 +02001726static int verify_chan_comb(struct gsm_bts_trx_ts *ts, u_int8_t chan_comb)
1727{
1728 int i;
1729
1730 /* As it turns out, the BS-11 has some very peculiar restrictions
1731 * on the channel combinations it allows */
1732 if (ts->trx->bts->type == GSM_BTS_TYPE_BS11) {
1733 switch (chan_comb) {
1734 case NM_CHANC_TCHHalf:
1735 case NM_CHANC_TCHHalf2:
1736 /* not supported */
1737 return -EINVAL;
1738 case NM_CHANC_SDCCH:
1739 /* only one SDCCH/8 per TRX */
1740 for (i = 0; i < TRX_NR_TS; i++) {
1741 if (i == ts->nr)
1742 continue;
1743 if (ts->trx->ts[i].nm_chan_comb ==
1744 NM_CHANC_SDCCH)
1745 return -EINVAL;
1746 }
1747 /* not allowed for TS0 of BCCH-TRX */
1748 if (ts->trx == ts->trx->bts->c0 &&
1749 ts->nr == 0)
1750 return -EINVAL;
1751 /* not on the same TRX that has a BCCH+SDCCH4
1752 * combination */
1753 if (ts->trx == ts->trx->bts->c0 &&
1754 (ts->trx->ts[0].nm_chan_comb == 5 ||
1755 ts->trx->ts[0].nm_chan_comb == 8))
1756 return -EINVAL;
1757 break;
1758 case NM_CHANC_mainBCCH:
1759 case NM_CHANC_BCCHComb:
1760 /* allowed only for TS0 of C0 */
1761 if (ts->trx != ts->trx->bts->c0 ||
1762 ts->nr != 0)
1763 return -EINVAL;
1764 break;
1765 case NM_CHANC_BCCH:
1766 /* allowed only for TS 2/4/6 of C0 */
1767 if (ts->trx != ts->trx->bts->c0)
1768 return -EINVAL;
1769 if (ts->nr != 2 && ts->nr != 4 &&
1770 ts->nr != 6)
1771 return -EINVAL;
1772 break;
1773 case 8: /* this is not like 08.58, but in fact
1774 * FCCH+SCH+BCCH+CCCH+SDCCH/4+SACCH/C4+CBCH */
1775 /* FIXME: only one CBCH allowed per cell */
1776 break;
1777 }
1778 }
1779 return 0;
1780}
1781
Harald Welte59b04682009-06-10 05:40:52 +08001782/* Chapter 8.6.3 */
1783int abis_nm_set_channel_attr(struct gsm_bts_trx_ts *ts, u_int8_t chan_comb)
1784{
1785 struct gsm_bts *bts = ts->trx->bts;
1786 struct abis_om_hdr *oh;
1787 u_int16_t arfcn = htons(ts->trx->arfcn);
1788 u_int8_t zero = 0x00;
1789 struct msgb *msg = nm_msgb_alloc();
1790 u_int8_t len = 2 + 2;
1791
1792 if (bts->type == GSM_BTS_TYPE_BS11)
1793 len += 4 + 2 + 2 + 3;
1794
1795 DEBUGP(DNM, "Set Chan Attr %s\n", gsm_ts_name(ts));
Harald Weltef2eb2782009-08-09 21:49:48 +02001796 if (verify_chan_comb(ts, chan_comb) < 0) {
1797 msgb_free(msg);
1798 DEBUGP(DNM, "Invalid Channel Combination!!!\n");
1799 return -EINVAL;
1800 }
1801 ts->nm_chan_comb = chan_comb;
Harald Welte59b04682009-06-10 05:40:52 +08001802
1803 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1804 fill_om_fom_hdr(oh, len, NM_MT_SET_CHAN_ATTR,
1805 NM_OC_CHANNEL, bts->bts_nr,
1806 ts->trx->nr, ts->nr);
1807 /* FIXME: don't send ARFCN list, hopping sequence, mAIO, ...*/
1808 if (bts->type == GSM_BTS_TYPE_BS11)
1809 msgb_tlv16_put(msg, NM_ATT_ARFCN_LIST, 1, &arfcn);
1810 msgb_tv_put(msg, NM_ATT_CHAN_COMB, chan_comb);
1811 if (bts->type == GSM_BTS_TYPE_BS11) {
1812 msgb_tv_put(msg, NM_ATT_HSN, 0x00);
1813 msgb_tv_put(msg, NM_ATT_MAIO, 0x00);
1814 }
Harald Weltebeeb28f2009-07-21 20:40:05 +02001815 msgb_tv_put(msg, NM_ATT_TSC, bts->tsc); /* training sequence */
Harald Welte59b04682009-06-10 05:40:52 +08001816 if (bts->type == GSM_BTS_TYPE_BS11)
1817 msgb_tlv_put(msg, 0x59, 1, &zero);
1818
1819 return abis_nm_sendmsg(bts, msg);
1820}
1821
1822int abis_nm_sw_act_req_ack(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i1,
1823 u_int8_t i2, u_int8_t i3, int nack, u_int8_t *attr, int att_len)
1824{
1825 struct abis_om_hdr *oh;
1826 struct msgb *msg = nm_msgb_alloc();
1827 u_int8_t msgtype = NM_MT_SW_ACT_REQ_ACK;
1828 u_int8_t len = att_len;
1829
1830 if (nack) {
1831 len += 2;
1832 msgtype = NM_MT_SW_ACT_REQ_NACK;
1833 }
1834
1835 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1836 fill_om_fom_hdr(oh, att_len, msgtype, obj_class, i1, i2, i3);
1837
1838 if (attr) {
1839 u_int8_t *ptr = msgb_put(msg, att_len);
1840 memcpy(ptr, attr, att_len);
1841 }
1842 if (nack)
1843 msgb_tv_put(msg, NM_ATT_NACK_CAUSES, NM_NACK_OBJCLASS_NOTSUPP);
1844
1845 return abis_nm_sendmsg(bts, msg);
1846}
1847
1848int abis_nm_raw_msg(struct gsm_bts *bts, int len, u_int8_t *rawmsg)
1849{
1850 struct msgb *msg = nm_msgb_alloc();
1851 struct abis_om_hdr *oh;
1852 u_int8_t *data;
1853
1854 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
1855 fill_om_hdr(oh, len);
1856 data = msgb_put(msg, len);
1857 memcpy(data, rawmsg, len);
1858
1859 return abis_nm_sendmsg(bts, msg);
1860}
1861
1862/* Siemens specific commands */
1863static int __simple_cmd(struct gsm_bts *bts, u_int8_t msg_type)
1864{
1865 struct abis_om_hdr *oh;
1866 struct msgb *msg = nm_msgb_alloc();
1867
1868 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1869 fill_om_fom_hdr(oh, 0, msg_type, NM_OC_SITE_MANAGER,
1870 0xff, 0xff, 0xff);
1871
1872 return abis_nm_sendmsg(bts, msg);
1873}
1874
1875/* Chapter 8.9.2 */
1876int abis_nm_opstart(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1, u_int8_t i2)
1877{
1878 struct abis_om_hdr *oh;
1879 struct msgb *msg = nm_msgb_alloc();
1880
Harald Welte59b04682009-06-10 05:40:52 +08001881 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1882 fill_om_fom_hdr(oh, 0, NM_MT_OPSTART, obj_class, i0, i1, i2);
1883
Harald Welteb7284a92009-10-20 09:56:18 +02001884 debugp_foh((struct abis_om_fom_hdr *) oh->data);
1885 DEBUGPC(DNM, "Sending OPSTART\n");
1886
Harald Welte59b04682009-06-10 05:40:52 +08001887 return abis_nm_sendmsg(bts, msg);
1888}
1889
1890/* Chapter 8.8.5 */
1891int abis_nm_chg_adm_state(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0,
Daniel Willmann5655afe2009-08-10 11:49:36 +02001892 u_int8_t i1, u_int8_t i2, enum abis_nm_adm_state adm_state)
Harald Welte59b04682009-06-10 05:40:52 +08001893{
1894 struct abis_om_hdr *oh;
1895 struct msgb *msg = nm_msgb_alloc();
1896
1897 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1898 fill_om_fom_hdr(oh, 2, NM_MT_CHG_ADM_STATE, obj_class, i0, i1, i2);
1899 msgb_tv_put(msg, NM_ATT_ADM_STATE, adm_state);
1900
1901 return abis_nm_sendmsg(bts, msg);
1902}
1903
Harald Welte204317e2009-08-06 17:58:31 +02001904int abis_nm_conn_mdrop_link(struct gsm_bts *bts, u_int8_t e1_port0, u_int8_t ts0,
1905 u_int8_t e1_port1, u_int8_t ts1)
1906{
1907 struct abis_om_hdr *oh;
1908 struct msgb *msg = nm_msgb_alloc();
1909 u_int8_t *attr;
1910
1911 DEBUGP(DNM, "CONNECT MDROP LINK E1=(%u,%u) -> E1=(%u, %u)\n",
1912 e1_port0, ts0, e1_port1, ts1);
1913
1914 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1915 fill_om_fom_hdr(oh, 6, NM_MT_CONN_MDROP_LINK,
1916 NM_OC_SITE_MANAGER, 0x00, 0x00, 0x00);
1917
1918 attr = msgb_put(msg, 3);
1919 attr[0] = NM_ATT_MDROP_LINK;
1920 attr[1] = e1_port0;
1921 attr[2] = ts0;
1922
1923 attr = msgb_put(msg, 3);
1924 attr[0] = NM_ATT_MDROP_NEXT;
1925 attr[1] = e1_port1;
1926 attr[2] = ts1;
1927
1928 return abis_nm_sendmsg(bts, msg);
1929}
Harald Welte59b04682009-06-10 05:40:52 +08001930
Harald Welte0bf8e302009-08-08 00:02:36 +02001931/* Chapter 8.7.1 */
1932int abis_nm_perform_test(struct gsm_bts *bts, u_int8_t obj_class,
1933 u_int8_t bts_nr, u_int8_t trx_nr, u_int8_t ts_nr,
1934 u_int8_t test_nr, u_int8_t auton_report,
1935 u_int8_t *phys_config, u_int16_t phys_config_len)
1936{
1937 struct abis_om_hdr *oh;
1938 struct msgb *msg = nm_msgb_alloc();
1939 int len = 4; /* 2 TV attributes */
1940
1941 DEBUGP(DNM, "PEFORM TEST\n");
1942
1943 if (phys_config_len)
1944 len += 3 + phys_config_len;
1945
1946 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1947 fill_om_fom_hdr(oh, len, NM_MT_PERF_TEST,
1948 obj_class, bts_nr, trx_nr, ts_nr);
1949 msgb_tv_put(msg, NM_ATT_TEST_NO, test_nr);
1950 msgb_tv_put(msg, NM_ATT_AUTON_REPORT, auton_report);
1951 if (phys_config_len)
1952 msgb_tl16v_put(msg, NM_ATT_PHYS_CONF, phys_config_len,
1953 phys_config);
1954
1955 return abis_nm_sendmsg(bts, msg);
1956}
1957
Harald Welte59b04682009-06-10 05:40:52 +08001958int abis_nm_event_reports(struct gsm_bts *bts, int on)
1959{
1960 if (on == 0)
1961 return __simple_cmd(bts, NM_MT_STOP_EVENT_REP);
1962 else
1963 return __simple_cmd(bts, NM_MT_REST_EVENT_REP);
1964}
1965
1966/* Siemens (or BS-11) specific commands */
1967
1968int abis_nm_bs11_bsc_disconnect(struct gsm_bts *bts, int reconnect)
1969{
1970 if (reconnect == 0)
1971 return __simple_cmd(bts, NM_MT_BS11_DISCONNECT);
1972 else
1973 return __simple_cmd(bts, NM_MT_BS11_RECONNECT);
1974}
1975
1976int abis_nm_bs11_restart(struct gsm_bts *bts)
1977{
1978 return __simple_cmd(bts, NM_MT_BS11_RESTART);
1979}
1980
1981
1982struct bs11_date_time {
1983 u_int16_t year;
1984 u_int8_t month;
1985 u_int8_t day;
1986 u_int8_t hour;
1987 u_int8_t min;
1988 u_int8_t sec;
1989} __attribute__((packed));
1990
1991
1992void get_bs11_date_time(struct bs11_date_time *aet)
1993{
1994 time_t t;
1995 struct tm *tm;
1996
1997 t = time(NULL);
1998 tm = localtime(&t);
1999 aet->sec = tm->tm_sec;
2000 aet->min = tm->tm_min;
2001 aet->hour = tm->tm_hour;
2002 aet->day = tm->tm_mday;
2003 aet->month = tm->tm_mon;
2004 aet->year = htons(1900 + tm->tm_year);
2005}
2006
2007int abis_nm_bs11_reset_resource(struct gsm_bts *bts)
2008{
2009 return __simple_cmd(bts, NM_MT_BS11_RESET_RESOURCE);
2010}
2011
2012int abis_nm_bs11_db_transmission(struct gsm_bts *bts, int begin)
2013{
2014 if (begin)
2015 return __simple_cmd(bts, NM_MT_BS11_BEGIN_DB_TX);
2016 else
2017 return __simple_cmd(bts, NM_MT_BS11_END_DB_TX);
2018}
2019
2020int abis_nm_bs11_create_object(struct gsm_bts *bts,
2021 enum abis_bs11_objtype type, u_int8_t idx,
2022 u_int8_t attr_len, const u_int8_t *attr)
2023{
2024 struct abis_om_hdr *oh;
2025 struct msgb *msg = nm_msgb_alloc();
2026 u_int8_t *cur;
2027
2028 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2029 fill_om_fom_hdr(oh, attr_len, NM_MT_BS11_CREATE_OBJ,
2030 NM_OC_BS11, type, 0, idx);
2031 cur = msgb_put(msg, attr_len);
2032 memcpy(cur, attr, attr_len);
2033
2034 return abis_nm_sendmsg(bts, msg);
2035}
2036
2037int abis_nm_bs11_delete_object(struct gsm_bts *bts,
2038 enum abis_bs11_objtype type, u_int8_t idx)
2039{
2040 struct abis_om_hdr *oh;
2041 struct msgb *msg = nm_msgb_alloc();
2042
2043 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2044 fill_om_fom_hdr(oh, 0, NM_MT_BS11_DELETE_OBJ,
2045 NM_OC_BS11, type, 0, idx);
2046
2047 return abis_nm_sendmsg(bts, msg);
2048}
2049
2050int abis_nm_bs11_create_envaBTSE(struct gsm_bts *bts, u_int8_t idx)
2051{
2052 struct abis_om_hdr *oh;
2053 struct msgb *msg = nm_msgb_alloc();
2054 u_int8_t zero = 0x00;
2055
2056 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2057 fill_om_fom_hdr(oh, 3, NM_MT_BS11_CREATE_OBJ,
2058 NM_OC_BS11_ENVABTSE, 0, idx, 0xff);
2059 msgb_tlv_put(msg, 0x99, 1, &zero);
2060
2061 return abis_nm_sendmsg(bts, msg);
2062}
2063
2064int abis_nm_bs11_create_bport(struct gsm_bts *bts, u_int8_t idx)
2065{
2066 struct abis_om_hdr *oh;
2067 struct msgb *msg = nm_msgb_alloc();
2068
2069 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2070 fill_om_fom_hdr(oh, 0, NM_MT_BS11_CREATE_OBJ, NM_OC_BS11_BPORT,
Daniel Willmann5655afe2009-08-10 11:49:36 +02002071 idx, 0xff, 0xff);
2072
2073 return abis_nm_sendmsg(bts, msg);
2074}
2075
2076int abis_nm_bs11_delete_bport(struct gsm_bts *bts, u_int8_t idx)
2077{
2078 struct abis_om_hdr *oh;
2079 struct msgb *msg = nm_msgb_alloc();
2080
2081 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2082 fill_om_fom_hdr(oh, 0, NM_MT_BS11_DELETE_OBJ, NM_OC_BS11_BPORT,
2083 idx, 0xff, 0xff);
Harald Welte59b04682009-06-10 05:40:52 +08002084
2085 return abis_nm_sendmsg(bts, msg);
2086}
2087
2088static const u_int8_t sm_attr[] = { NM_ATT_TEI, NM_ATT_ABIS_CHANNEL };
2089int abis_nm_bs11_get_oml_tei_ts(struct gsm_bts *bts)
2090{
2091 struct abis_om_hdr *oh;
2092 struct msgb *msg = nm_msgb_alloc();
2093
2094 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2095 fill_om_fom_hdr(oh, 2+sizeof(sm_attr), NM_MT_GET_ATTR, NM_OC_SITE_MANAGER,
2096 0xff, 0xff, 0xff);
2097 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(sm_attr), sm_attr);
2098
2099 return abis_nm_sendmsg(bts, msg);
2100}
2101
2102/* like abis_nm_conn_terr_traf + set_tei */
2103int abis_nm_bs11_conn_oml_tei(struct gsm_bts *bts, u_int8_t e1_port,
2104 u_int8_t e1_timeslot, u_int8_t e1_subslot,
2105 u_int8_t tei)
2106{
2107 struct abis_om_hdr *oh;
2108 struct abis_nm_channel *ch;
2109 struct msgb *msg = nm_msgb_alloc();
2110
2111 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2112 fill_om_fom_hdr(oh, sizeof(*ch)+2, NM_MT_BS11_SET_ATTR,
2113 NM_OC_SITE_MANAGER, 0xff, 0xff, 0xff);
2114
2115 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
2116 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
2117 msgb_tv_put(msg, NM_ATT_TEI, tei);
2118
2119 return abis_nm_sendmsg(bts, msg);
2120}
2121
2122int abis_nm_bs11_set_trx_power(struct gsm_bts_trx *trx, u_int8_t level)
2123{
2124 struct abis_om_hdr *oh;
2125 struct msgb *msg = nm_msgb_alloc();
2126
2127 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2128 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR,
2129 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
2130 msgb_tlv_put(msg, NM_ATT_BS11_TXPWR, 1, &level);
2131
2132 return abis_nm_sendmsg(trx->bts, msg);
2133}
2134
2135int abis_nm_bs11_get_trx_power(struct gsm_bts_trx *trx)
2136{
2137 struct abis_om_hdr *oh;
2138 struct msgb *msg = nm_msgb_alloc();
2139 u_int8_t attr = NM_ATT_BS11_TXPWR;
2140
2141 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2142 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
2143 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
2144 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), &attr);
2145
2146 return abis_nm_sendmsg(trx->bts, msg);
2147}
2148
2149int abis_nm_bs11_get_pll_mode(struct gsm_bts *bts)
2150{
2151 struct abis_om_hdr *oh;
2152 struct msgb *msg = nm_msgb_alloc();
2153 u_int8_t attr[] = { NM_ATT_BS11_PLL_MODE };
2154
2155 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2156 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
2157 NM_OC_BS11, BS11_OBJ_LI, 0x00, 0x00);
2158 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), attr);
2159
2160 return abis_nm_sendmsg(bts, msg);
2161}
2162
2163int abis_nm_bs11_get_cclk(struct gsm_bts *bts)
2164{
2165 struct abis_om_hdr *oh;
2166 struct msgb *msg = nm_msgb_alloc();
2167 u_int8_t attr[] = { NM_ATT_BS11_CCLK_ACCURACY,
2168 NM_ATT_BS11_CCLK_TYPE };
2169
2170 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2171 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
2172 NM_OC_BS11, BS11_OBJ_CCLK, 0x00, 0x00);
2173 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), attr);
2174
2175 return abis_nm_sendmsg(bts, msg);
2176
2177}
2178
2179//static const u_int8_t bs11_logon_c7[] = { 0x07, 0xd9, 0x01, 0x11, 0x0d, 0x10, 0x20 };
2180static const u_int8_t bs11_logon_c8[] = { 0x02 };
2181static const u_int8_t bs11_logon_c9[] = "FACTORY";
2182
2183int abis_nm_bs11_factory_logon(struct gsm_bts *bts, int on)
2184{
2185 struct abis_om_hdr *oh;
2186 struct msgb *msg = nm_msgb_alloc();
2187 struct bs11_date_time bdt;
2188
2189 get_bs11_date_time(&bdt);
2190
2191 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2192 if (on) {
2193 u_int8_t len = 3*2 + sizeof(bdt)
2194 + sizeof(bs11_logon_c8) + sizeof(bs11_logon_c9);
2195 fill_om_fom_hdr(oh, len, NM_MT_BS11_LMT_LOGON,
2196 NM_OC_BS11_BTSE, 0xff, 0xff, 0xff);
2197 msgb_tlv_put(msg, NM_ATT_BS11_LMT_LOGIN_TIME,
2198 sizeof(bdt), (u_int8_t *) &bdt);
2199 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_ACC_LEV,
2200 sizeof(bs11_logon_c8), bs11_logon_c8);
2201 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_NAME,
2202 sizeof(bs11_logon_c9), bs11_logon_c9);
2203 } else {
2204 fill_om_fom_hdr(oh, 0, NM_MT_BS11_LMT_LOGOFF,
2205 NM_OC_BS11_BTSE, 0xff, 0xff, 0xff);
2206 }
2207
2208 return abis_nm_sendmsg(bts, msg);
2209}
2210
2211int abis_nm_bs11_set_trx1_pw(struct gsm_bts *bts, const char *password)
2212{
2213 struct abis_om_hdr *oh;
2214 struct msgb *msg;
2215
2216 if (strlen(password) != 10)
2217 return -EINVAL;
2218
2219 msg = nm_msgb_alloc();
2220 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2221 fill_om_fom_hdr(oh, 2+strlen(password), NM_MT_BS11_SET_ATTR,
2222 NM_OC_BS11, BS11_OBJ_TRX1, 0x00, 0x00);
2223 msgb_tlv_put(msg, NM_ATT_BS11_PASSWORD, 10, (const u_int8_t *)password);
2224
2225 return abis_nm_sendmsg(bts, msg);
2226}
2227
2228/* change the BS-11 PLL Mode to either locked (E1 derived) or standalone */
2229int abis_nm_bs11_set_pll_locked(struct gsm_bts *bts, int locked)
2230{
2231 struct abis_om_hdr *oh;
2232 struct msgb *msg;
2233 u_int8_t tlv_value;
2234
2235 msg = nm_msgb_alloc();
2236 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2237 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR, NM_OC_BS11,
2238 BS11_OBJ_LI, 0x00, 0x00);
2239
2240 if (locked)
2241 tlv_value = BS11_LI_PLL_LOCKED;
2242 else
2243 tlv_value = BS11_LI_PLL_STANDALONE;
2244
2245 msgb_tlv_put(msg, NM_ATT_BS11_PLL_MODE, 1, &tlv_value);
2246
2247 return abis_nm_sendmsg(bts, msg);
2248}
2249
2250int abis_nm_bs11_get_state(struct gsm_bts *bts)
2251{
2252 return __simple_cmd(bts, NM_MT_BS11_GET_STATE);
2253}
2254
2255/* BS11 SWL */
2256
Harald Welte (local)8751ee92009-08-15 02:30:58 +02002257void *tall_fle_ctx;
Harald Weltea8379772009-06-20 22:36:41 +02002258
Harald Welte59b04682009-06-10 05:40:52 +08002259struct abis_nm_bs11_sw {
2260 struct gsm_bts *bts;
2261 char swl_fname[PATH_MAX];
2262 u_int8_t win_size;
2263 int forced;
2264 struct llist_head file_list;
2265 gsm_cbfn *user_cb; /* specified by the user */
2266};
2267static struct abis_nm_bs11_sw _g_bs11_sw, *g_bs11_sw = &_g_bs11_sw;
2268
2269struct file_list_entry {
2270 struct llist_head list;
2271 char fname[PATH_MAX];
2272};
2273
2274struct file_list_entry *fl_dequeue(struct llist_head *queue)
2275{
2276 struct llist_head *lh;
2277
2278 if (llist_empty(queue))
2279 return NULL;
2280
2281 lh = queue->next;
2282 llist_del(lh);
2283
2284 return llist_entry(lh, struct file_list_entry, list);
2285}
2286
2287static int bs11_read_swl_file(struct abis_nm_bs11_sw *bs11_sw)
2288{
2289 char linebuf[255];
2290 struct llist_head *lh, *lh2;
2291 FILE *swl;
2292 int rc = 0;
2293
2294 swl = fopen(bs11_sw->swl_fname, "r");
2295 if (!swl)
2296 return -ENODEV;
2297
2298 /* zero the stale file list, if any */
2299 llist_for_each_safe(lh, lh2, &bs11_sw->file_list) {
2300 llist_del(lh);
Harald Weltea8379772009-06-20 22:36:41 +02002301 talloc_free(lh);
Harald Welte59b04682009-06-10 05:40:52 +08002302 }
2303
2304 while (fgets(linebuf, sizeof(linebuf), swl)) {
2305 char file_id[12+1];
2306 char file_version[80+1];
2307 struct file_list_entry *fle;
2308 static char dir[PATH_MAX];
2309
2310 if (strlen(linebuf) < 4)
2311 continue;
2312
2313 rc = sscanf(linebuf+4, "%12s:%80s\r\n", file_id, file_version);
2314 if (rc < 0) {
2315 perror("ERR parsing SWL file");
2316 rc = -EINVAL;
2317 goto out;
2318 }
2319 if (rc < 2)
2320 continue;
2321
Harald Welte857e00d2009-06-26 20:25:23 +02002322 fle = talloc_zero(tall_fle_ctx, struct file_list_entry);
Harald Welte59b04682009-06-10 05:40:52 +08002323 if (!fle) {
2324 rc = -ENOMEM;
2325 goto out;
2326 }
Harald Welte59b04682009-06-10 05:40:52 +08002327
2328 /* construct new filename */
2329 strncpy(dir, bs11_sw->swl_fname, sizeof(dir));
2330 strncat(fle->fname, dirname(dir), sizeof(fle->fname) - 1);
2331 strcat(fle->fname, "/");
2332 strncat(fle->fname, file_id, sizeof(fle->fname) - 1 -strlen(fle->fname));
2333
2334 llist_add_tail(&fle->list, &bs11_sw->file_list);
2335 }
2336
2337out:
2338 fclose(swl);
2339 return rc;
2340}
2341
2342/* bs11 swload specific callback, passed to abis_nm core swload */
2343static int bs11_swload_cbfn(unsigned int hook, unsigned int event,
2344 struct msgb *msg, void *data, void *param)
2345{
2346 struct abis_nm_bs11_sw *bs11_sw = data;
2347 struct file_list_entry *fle;
2348 int rc = 0;
2349
2350 switch (event) {
2351 case NM_MT_LOAD_END_ACK:
2352 fle = fl_dequeue(&bs11_sw->file_list);
2353 if (fle) {
2354 /* start download the next file of our file list */
2355 rc = abis_nm_software_load(bs11_sw->bts, fle->fname,
2356 bs11_sw->win_size,
2357 bs11_sw->forced,
2358 &bs11_swload_cbfn, bs11_sw);
Harald Welteb6328b92009-08-06 15:44:18 +02002359 talloc_free(fle);
Harald Welte59b04682009-06-10 05:40:52 +08002360 } else {
2361 /* activate the SWL */
2362 rc = abis_nm_software_activate(bs11_sw->bts,
2363 bs11_sw->swl_fname,
2364 bs11_swload_cbfn,
2365 bs11_sw);
2366 }
2367 break;
2368 case NM_MT_LOAD_SEG_ACK:
2369 case NM_MT_LOAD_END_NACK:
2370 case NM_MT_LOAD_INIT_ACK:
2371 case NM_MT_LOAD_INIT_NACK:
2372 case NM_MT_ACTIVATE_SW_NACK:
2373 case NM_MT_ACTIVATE_SW_ACK:
2374 default:
2375 /* fallthrough to the user callback */
2376 if (bs11_sw->user_cb)
2377 rc = bs11_sw->user_cb(hook, event, msg, NULL, NULL);
2378 break;
2379 }
2380
2381 return rc;
2382}
2383
2384/* Siemens provides a SWL file that is a mere listing of all the other
2385 * files that are part of a software release. We need to upload first
2386 * the list file, and then each file that is listed in the list file */
2387int abis_nm_bs11_load_swl(struct gsm_bts *bts, const char *fname,
2388 u_int8_t win_size, int forced, gsm_cbfn *cbfn)
2389{
2390 struct abis_nm_bs11_sw *bs11_sw = g_bs11_sw;
2391 struct file_list_entry *fle;
2392 int rc = 0;
2393
2394 INIT_LLIST_HEAD(&bs11_sw->file_list);
2395 bs11_sw->bts = bts;
2396 bs11_sw->win_size = win_size;
2397 bs11_sw->user_cb = cbfn;
2398 bs11_sw->forced = forced;
2399
2400 strncpy(bs11_sw->swl_fname, fname, sizeof(bs11_sw->swl_fname));
2401 rc = bs11_read_swl_file(bs11_sw);
2402 if (rc < 0)
2403 return rc;
2404
2405 /* dequeue next item in file list */
2406 fle = fl_dequeue(&bs11_sw->file_list);
2407 if (!fle)
2408 return -EINVAL;
2409
2410 /* start download the next file of our file list */
2411 rc = abis_nm_software_load(bts, fle->fname, win_size, forced,
2412 bs11_swload_cbfn, bs11_sw);
Harald Welteb6328b92009-08-06 15:44:18 +02002413 talloc_free(fle);
Harald Welte59b04682009-06-10 05:40:52 +08002414 return rc;
2415}
2416
2417#if 0
2418static u_int8_t req_attr_btse[] = {
2419 NM_ATT_ADM_STATE, NM_ATT_BS11_LMT_LOGON_SESSION,
2420 NM_ATT_BS11_LMT_LOGIN_TIME, NM_ATT_BS11_LMT_USER_ACC_LEV,
2421 NM_ATT_BS11_LMT_USER_NAME,
2422
2423 0xaf, NM_ATT_BS11_RX_OFFSET, NM_ATT_BS11_VENDOR_NAME,
2424
2425 NM_ATT_BS11_SW_LOAD_INTENDED, NM_ATT_BS11_SW_LOAD_SAFETY,
2426
2427 NM_ATT_BS11_SW_LOAD_STORED };
2428
2429static u_int8_t req_attr_btsm[] = {
2430 NM_ATT_ABIS_CHANNEL, NM_ATT_TEI, NM_ATT_BS11_ABIS_EXT_TIME,
2431 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xce, NM_ATT_FILE_ID,
2432 NM_ATT_FILE_VERSION, NM_ATT_OPER_STATE, 0xe8, NM_ATT_BS11_ALL_TEST_CATG,
2433 NM_ATT_SW_DESCR, NM_ATT_GET_ARI };
2434#endif
2435
2436static u_int8_t req_attr[] = {
2437 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xa8, NM_ATT_OPER_STATE,
2438 0xd5, 0xa1, NM_ATT_BS11_ESN_FW_CODE_NO, NM_ATT_BS11_ESN_HW_CODE_NO,
2439 0x42, NM_ATT_BS11_ESN_PCB_SERIAL, NM_ATT_BS11_PLL };
2440
2441int abis_nm_bs11_get_serno(struct gsm_bts *bts)
2442{
2443 struct abis_om_hdr *oh;
2444 struct msgb *msg = nm_msgb_alloc();
2445
2446 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2447 /* SiemensHW CCTRL object */
2448 fill_om_fom_hdr(oh, 2+sizeof(req_attr), NM_MT_GET_ATTR, NM_OC_BS11,
2449 0x03, 0x00, 0x00);
2450 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(req_attr), req_attr);
2451
2452 return abis_nm_sendmsg(bts, msg);
2453}
2454
2455int abis_nm_bs11_set_ext_time(struct gsm_bts *bts)
2456{
2457 struct abis_om_hdr *oh;
2458 struct msgb *msg = nm_msgb_alloc();
2459 struct bs11_date_time aet;
2460
2461 get_bs11_date_time(&aet);
2462 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2463 /* SiemensHW CCTRL object */
2464 fill_om_fom_hdr(oh, 2+sizeof(aet), NM_MT_BS11_SET_ATTR, NM_OC_SITE_MANAGER,
2465 0xff, 0xff, 0xff);
2466 msgb_tlv_put(msg, NM_ATT_BS11_ABIS_EXT_TIME, sizeof(aet), (u_int8_t *) &aet);
2467
2468 return abis_nm_sendmsg(bts, msg);
2469}
2470
Daniel Willmann5655afe2009-08-10 11:49:36 +02002471int abis_nm_bs11_set_bport_line_cfg(struct gsm_bts *bts, u_int8_t bport, enum abis_bs11_line_cfg line_cfg)
2472{
2473 struct abis_om_hdr *oh;
2474 struct msgb *msg = nm_msgb_alloc();
2475 struct bs11_date_time aet;
2476
2477 get_bs11_date_time(&aet);
2478 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2479 fill_om_fom_hdr(oh, 2, NM_MT_BS11_SET_ATTR, NM_OC_BS11_BPORT,
2480 bport, 0xff, 0x02);
2481 msgb_tv_put(msg, NM_ATT_BS11_LINE_CFG, line_cfg);
2482
2483 return abis_nm_sendmsg(bts, msg);
2484}
2485
Harald Welte59b04682009-06-10 05:40:52 +08002486/* ip.access nanoBTS specific commands */
2487static const char ipaccess_magic[] = "com.ipaccess";
2488
2489
2490static int abis_nm_rx_ipacc(struct msgb *msg)
2491{
2492 struct abis_om_hdr *oh = msgb_l2(msg);
2493 struct abis_om_fom_hdr *foh;
2494 u_int8_t idstrlen = oh->data[0];
2495 struct tlv_parsed tp;
2496
2497 if (strncmp((char *)&oh->data[1], ipaccess_magic, idstrlen)) {
2498 DEBUGP(DNM, "id string is not com.ipaccess !?!\n");
2499 return -EINVAL;
2500 }
2501
2502 foh = (struct abis_om_fom_hdr *) (oh->data + 1 + idstrlen);
2503 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
2504
Harald Welteb7284a92009-10-20 09:56:18 +02002505 debugp_foh(foh);
Harald Weltefd579d52009-10-19 21:46:54 +02002506
Harald Welte5aeedd42009-10-19 22:11:11 +02002507 DEBUGPC(DNM, "IPACCESS(0x%02x): ", foh->msg_type);
Harald Welte59b04682009-06-10 05:40:52 +08002508
2509 switch (foh->msg_type) {
2510 case NM_MT_IPACC_RSL_CONNECT_ACK:
2511 DEBUGPC(DNM, "RSL CONNECT ACK ");
Harald Welte4206d982009-07-12 09:33:54 +02002512 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_DST_IP))
Harald Welte59b04682009-06-10 05:40:52 +08002513 DEBUGPC(DNM, "IP=%s ",
2514 inet_ntoa(*((struct in_addr *)
Harald Welte4206d982009-07-12 09:33:54 +02002515 TLVP_VAL(&tp, NM_ATT_IPACC_DST_IP))));
2516 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_DST_IP_PORT))
Harald Welte59b04682009-06-10 05:40:52 +08002517 DEBUGPC(DNM, "PORT=%u ",
2518 ntohs(*((u_int16_t *)
Harald Welte4206d982009-07-12 09:33:54 +02002519 TLVP_VAL(&tp, NM_ATT_IPACC_DST_IP_PORT))));
Harald Welte0eccfd02009-10-19 22:49:33 +02002520 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_STREAM_ID))
2521 DEBUGPC(DNM, "STREAM=0x%02x ",
2522 *TLVP_VAL(&tp, NM_ATT_IPACC_STREAM_ID));
Harald Welte59b04682009-06-10 05:40:52 +08002523 DEBUGPC(DNM, "\n");
2524 break;
2525 case NM_MT_IPACC_RSL_CONNECT_NACK:
2526 DEBUGPC(DNM, "RSL CONNECT NACK ");
2527 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
2528 DEBUGPC(DNM, " CAUSE=%s\n",
2529 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
2530 else
2531 DEBUGPC(DNM, "\n");
2532 break;
2533 case NM_MT_IPACC_SET_NVATTR_ACK:
2534 DEBUGPC(DNM, "SET NVATTR ACK\n");
2535 /* FIXME: decode and show the actual attributes */
2536 break;
2537 case NM_MT_IPACC_SET_NVATTR_NACK:
2538 DEBUGPC(DNM, "SET NVATTR NACK ");
2539 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
2540 DEBUGPC(DNM, " CAUSE=%s\n",
2541 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
2542 else
2543 DEBUGPC(DNM, "\n");
2544 break;
Harald Welte21460f02009-07-03 11:26:45 +02002545 case NM_MT_IPACC_GET_NVATTR_ACK:
2546 DEBUGPC(DNM, "GET NVATTR ACK\n");
2547 /* FIXME: decode and show the actual attributes */
2548 break;
2549 case NM_MT_IPACC_GET_NVATTR_NACK:
2550 DEBUGPC(DNM, "GET NVATTR NACK ");
2551 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
2552 DEBUGPC(DNM, " CAUSE=%s\n",
2553 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
2554 else
2555 DEBUGPC(DNM, "\n");
2556 break;
Harald Weltec76a2172009-10-08 20:15:24 +02002557 case NM_MT_IPACC_SET_ATTR_ACK:
2558 DEBUGPC(DNM, "SET ATTR ACK\n");
2559 break;
2560 case NM_MT_IPACC_SET_ATTR_NACK:
2561 DEBUGPC(DNM, "SET ATTR NACK ");
2562 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
2563 DEBUGPC(DNM, " CAUSE=%s\n",
2564 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
2565 else
2566 DEBUGPC(DNM, "\n");
2567 break;
Harald Welte59b04682009-06-10 05:40:52 +08002568 default:
2569 DEBUGPC(DNM, "unknown\n");
2570 break;
2571 }
Holger Hans Peter Freyther72baef32009-07-07 12:40:07 +02002572
2573 /* signal handling */
2574 switch (foh->msg_type) {
2575 case NM_MT_IPACC_RSL_CONNECT_NACK:
2576 case NM_MT_IPACC_SET_NVATTR_NACK:
2577 case NM_MT_IPACC_GET_NVATTR_NACK:
2578 dispatch_signal(SS_NM, S_NM_IPACC_NACK, (void*) ((long)foh->msg_type));
2579 break;
2580 default:
2581 break;
2582 }
2583
Harald Welte59b04682009-06-10 05:40:52 +08002584 return 0;
2585}
2586
2587/* send an ip-access manufacturer specific message */
2588int abis_nm_ipaccess_msg(struct gsm_bts *bts, u_int8_t msg_type,
2589 u_int8_t obj_class, u_int8_t bts_nr,
2590 u_int8_t trx_nr, u_int8_t ts_nr,
2591 u_int8_t *attr, int attr_len)
2592{
2593 struct msgb *msg = nm_msgb_alloc();
2594 struct abis_om_hdr *oh;
2595 struct abis_om_fom_hdr *foh;
2596 u_int8_t *data;
2597
2598 /* construct the 12.21 OM header, observe the erroneous length */
2599 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
2600 fill_om_hdr(oh, sizeof(*foh) + attr_len);
2601 oh->mdisc = ABIS_OM_MDISC_MANUF;
2602
2603 /* add the ip.access magic */
2604 data = msgb_put(msg, sizeof(ipaccess_magic)+1);
2605 *data++ = sizeof(ipaccess_magic);
2606 memcpy(data, ipaccess_magic, sizeof(ipaccess_magic));
2607
2608 /* fill the 12.21 FOM header */
2609 foh = (struct abis_om_fom_hdr *) msgb_put(msg, sizeof(*foh));
2610 foh->msg_type = msg_type;
2611 foh->obj_class = obj_class;
2612 foh->obj_inst.bts_nr = bts_nr;
2613 foh->obj_inst.trx_nr = trx_nr;
2614 foh->obj_inst.ts_nr = ts_nr;
2615
2616 if (attr && attr_len) {
2617 data = msgb_put(msg, attr_len);
2618 memcpy(data, attr, attr_len);
2619 }
2620
2621 return abis_nm_sendmsg(bts, msg);
2622}
2623
2624/* set some attributes in NVRAM */
2625int abis_nm_ipaccess_set_nvattr(struct gsm_bts *bts, u_int8_t *attr,
2626 int attr_len)
2627{
2628 return abis_nm_ipaccess_msg(bts, NM_MT_IPACC_SET_NVATTR,
2629 NM_OC_BASEB_TRANSC, 0, 0, 0xff, attr,
2630 attr_len);
2631}
2632
Harald Welte5aeedd42009-10-19 22:11:11 +02002633int abis_nm_ipaccess_rsl_connect(struct gsm_bts_trx *trx,
2634 u_int32_t ip, u_int16_t port, u_int8_t stream)
2635{
2636 struct in_addr ia;
2637 u_int8_t attr[] = { NM_ATT_IPACC_STREAM_ID, 0,
2638 NM_ATT_IPACC_DST_IP_PORT, 0, 0,
2639 NM_ATT_IPACC_DST_IP, 0, 0, 0, 0 };
2640
2641 int attr_len = sizeof(attr);
2642
2643 ia.s_addr = htonl(ip);
2644 attr[1] = stream;
2645 attr[3] = port >> 8;
2646 attr[4] = port & 0xff;
2647 *(u_int32_t *)(attr+6) = ia.s_addr;
2648
2649 /* if ip == 0, we use the default IP */
2650 if (ip == 0)
2651 attr_len -= 5;
2652
2653 DEBUGP(DNM, "ip.access RSL CONNECT IP=%s PORT=%u STREAM=0x%02x\n",
Harald Welte6947c882009-10-19 22:50:30 +02002654 inet_ntoa(ia), port, stream);
Harald Welte5aeedd42009-10-19 22:11:11 +02002655
2656 return abis_nm_ipaccess_msg(trx->bts, NM_MT_IPACC_RSL_CONNECT,
2657 NM_OC_BASEB_TRANSC, trx->bts->bts_nr,
2658 trx->nr, 0xff, attr, attr_len);
2659}
2660
Harald Welte59b04682009-06-10 05:40:52 +08002661/* restart / reboot an ip.access nanoBTS */
2662int abis_nm_ipaccess_restart(struct gsm_bts *bts)
2663{
2664 return __simple_cmd(bts, NM_MT_IPACC_RESTART);
2665}
Harald Welte0dfc6232009-10-24 10:20:41 +02002666
2667int abis_nm_ipaccess_set_attr(struct gsm_bts *bts, u_int8_t obj_class,
2668 u_int8_t bts_nr, u_int8_t trx_nr, u_int8_t ts_nr,
2669 u_int8_t *attr, u_int8_t attr_len)
2670{
2671 return abis_nm_ipaccess_msg(bts, NM_MT_IPACC_SET_ATTR,
2672 obj_class, bts_nr, trx_nr, ts_nr,
2673 attr, attr_len);
2674}