blob: 63fda92e0f39b501b8ad56f54242e143cd141728 [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 Welte2cf161b2009-06-20 22:36:41 +020046#include <openbsc/talloc.h>
Harald Welte52b1f982008-12-23 20:25:15 +000047
Harald Welte8470bf22008-12-25 23:28:35 +000048#define OM_ALLOC_SIZE 1024
49#define OM_HEADROOM_SIZE 128
Harald Welte52b1f982008-12-23 20:25:15 +000050
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
Harald Welte4724f992009-01-18 18:01:49 +000066/* 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,
Harald Welte34a99682009-02-13 02:41:40 +000074 //NM_MT_SW_ACT_REQ,
Harald Welte4724f992009-01-18 18:01:49 +000075 NM_MT_ACTIVATE_SW_ACK,
76 NM_MT_ACTIVATE_SW_NACK,
77 NM_MT_SW_ACTIVATED_REP,
78};
79
Harald Weltee0590df2009-02-15 03:34:15 +000080static 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};
Harald Welte78fc0d42009-02-19 02:50:57 +0000115
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
Harald Welte6c96ba52009-05-01 13:03:40 +0000152/* 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 Welte560982b2009-06-26 13:21:57 +0200182 [NM_NACK_FILE_NOTACTIVATE] = "File cannot be activate",
Harald Welte6c96ba52009-05-01 13:03:40 +0000183 [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
Harald Welte0db97b22009-05-01 17:22:47 +0000200/* 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
Harald Welte52b1f982008-12-23 20:25:15 +0000237/* 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
Harald Weltee0590df2009-02-15 03:34:15 +0000266static 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 Weltee0590df2009-02-15 03:34:15 +0000331 [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 */
Harald Welte0efe9b72009-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 Welte4fbfd3a2009-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 Welte0efe9b72009-07-12 09:33:54 +0200370 [NM_ATT_IPACC_PRIM_OML_CFG_LIST] = { TLV_TYPE_TL16V },
Harald Weltea0c0b572009-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 Welte0efe9b72009-07-12 09:33:54 +0200373 [NM_ATT_IPACC_PRIM_OML_FB_TOUT] = { TLV_TYPE_TL16V },
Harald Welte4fbfd3a2009-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 Weltea0c0b572009-07-03 12:46:27 +0200387 [NM_ATT_IPACC_ALM_THRESH_LIST]= { TLV_TYPE_TL16V },
Harald Welte4fbfd3a2009-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 Weltea0c0b572009-07-03 12:46:27 +0200400 //[0x95] = { TLV_TYPE_FIXED, 2 },
Harald Welte677c21f2009-02-17 13:22:23 +0000401 [0x85] = { TLV_TYPE_TV },
402
Harald Weltee0590df2009-02-15 03:34:15 +0000403 },
404};
Harald Welte03133942009-02-18 19:51:53 +0000405
Harald Welte21bd3a52009-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 Weltea1499d02009-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 Welte21bd3a52009-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 Welte03133942009-02-18 19:51:53 +0000425int abis_nm_tlv_parse(struct tlv_parsed *tp, const u_int8_t *buf, int len)
426{
Harald Weltea4d49e92009-05-23 06:39:58 +0000427 return tlv_parse(tp, &nm_att_tlvdef, buf, len, 0, 0);
Harald Welte03133942009-02-18 19:51:53 +0000428}
Harald Weltee0590df2009-02-15 03:34:15 +0000429
Harald Welte52b1f982008-12-23 20:25:15 +0000430static 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
Holger Freytherca362a62009-01-04 21:05:01 +0000442#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000443/* 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}
Holger Freytherca362a62009-01-04 21:05:01 +0000448#endif
Harald Welte52b1f982008-12-23 20:25:15 +0000449
450/* is this msgtype a report ? */
451static int is_report(enum abis_nm_msgtype mt)
452{
Harald Welte8470bf22008-12-25 23:28:35 +0000453 return is_in_arr(mt, reports, ARRAY_SIZE(reports));
Harald Welte52b1f982008-12-23 20:25:15 +0000454}
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
Harald Welte702d8702008-12-26 20:25:35 +0000474 fill_om_hdr(oh, len+sizeof(*foh));
Harald Welte52b1f982008-12-23 20:25:15 +0000475 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
Harald Welte8470bf22008-12-25 23:28:35 +0000482static struct msgb *nm_msgb_alloc(void)
483{
Harald Welte966636f2009-06-26 19:39:35 +0200484 return msgb_alloc_headroom(OM_ALLOC_SIZE, OM_HEADROOM_SIZE,
485 "OML");
Harald Welte8470bf22008-12-25 23:28:35 +0000486}
487
Harald Welte52b1f982008-12-23 20:25:15 +0000488/* Send a OML NM Message from BSC to BTS */
489int abis_nm_sendmsg(struct gsm_bts *bts, struct msgb *msg)
490{
Holger Freyther59639e82009-02-09 23:09:55 +0000491 msg->trx = bts->c0;
492
Harald Weltead384642008-12-26 10:20:07 +0000493 return _abis_nm_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000494}
495
Harald Welte4724f992009-01-18 18:01:49 +0000496static int abis_nm_rcvmsg_sw(struct msgb *mb);
497
Harald Welte34a99682009-02-13 02:41:40 +0000498static const char *obj_class_name(u_int8_t oc)
499{
Harald Welte7b26bcb2009-05-28 11:39:21 +0000500 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:
Harald Weltebd8f7e32009-06-09 20:17:12 +0000510 return "CHANNEL";
Harald Welte7b26bcb2009-05-28 11:39:21 +0000511 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 Welted83a1272009-07-12 10:56:06 +0200531 case NM_OC_GPRS_NSVC:
532 return "GPRS NSVC";
Harald Welte8b697c72009-06-05 19:18:45 +0000533 case NM_OC_BS11:
534 return "SIEMENSHW";
Harald Welte7b26bcb2009-05-28 11:39:21 +0000535 }
536
537 return "UNKNOWN";
Harald Welte34a99682009-02-13 02:41:40 +0000538}
539
Harald Welte4d87f242009-03-10 19:43:44 +0000540const char *nm_opstate_name(u_int8_t os)
Harald Welte34a99682009-02-13 02:41:40 +0000541{
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
Harald Weltee0590df2009-02-15 03:34:15 +0000554/* Chapter 9.4.7 */
Harald Welte4d87f242009-03-10 19:43:44 +0000555static const char *avail_names[] = {
Harald Weltee0590df2009-02-15 03:34:15 +0000556 "In test",
557 "Failed",
558 "Power off",
559 "Off line",
560 "<not used>",
561 "Dependency",
562 "Degraded",
563 "Not installed",
564};
565
Harald Welte4d87f242009-03-10 19:43:44 +0000566const char *nm_avail_name(u_int8_t avail)
Harald Weltee0590df2009-02-15 03:34:15 +0000567{
Harald Welte0b8348d2009-02-18 03:43:01 +0000568 if (avail == 0xff)
569 return "OK";
Harald Weltee0590df2009-02-15 03:34:15 +0000570 if (avail >= ARRAY_SIZE(avail_names))
571 return "UNKNOWN";
572 return avail_names[avail];
573}
Harald Welte7b26bcb2009-05-28 11:39:21 +0000574
Harald Welte0f255852009-11-12 14:48:42 +0100575static struct value_string test_names[] = {
576 /* FIXME: standard test names */
577 { NM_IPACC_TESTNO_CHAN_USAGE, "Channel Usage" },
578 { NM_IPACC_TESTNO_BCCH_CHAN_USAGE, "BCCH Channel Usage" },
579 { NM_IPACC_TESTNO_FREQ_SYNC, "Frequency Synchronization" },
580 { NM_IPACC_TESTNO_BCCH_INFO, "BCCH Info" },
581 { NM_IPACC_TESTNO_TX_BEACON, "Transmit Beacon" },
582 { NM_IPACC_TESTNO_SYSINFO_MONITOR, "System Info Monitor" },
583 { NM_IPACC_TESTNO_BCCCH_MONITOR, "BCCH Monitor" },
584 { 0, NULL }
585};
586
Harald Welte7b26bcb2009-05-28 11:39:21 +0000587const char *nm_adm_name(u_int8_t adm)
588{
589 switch (adm) {
590 case 1:
591 return "Locked";
592 case 2:
593 return "Unlocked";
594 case 3:
595 return "Shutdown";
596 default:
597 return "<not used>";
598 }
599}
Harald Weltee0590df2009-02-15 03:34:15 +0000600
Harald Weltea8bd6d42009-10-20 09:56:18 +0200601static void debugp_foh(struct abis_om_fom_hdr *foh)
602{
603 DEBUGP(DNM, "OC=%s(%02x) INST=(%02x,%02x,%02x) ",
604 obj_class_name(foh->obj_class), foh->obj_class,
605 foh->obj_inst.bts_nr, foh->obj_inst.trx_nr,
606 foh->obj_inst.ts_nr);
607}
608
Harald Weltee0590df2009-02-15 03:34:15 +0000609/* obtain the gsm_nm_state data structure for a given object instance */
610static struct gsm_nm_state *
611objclass2nmstate(struct gsm_bts *bts, u_int8_t obj_class,
612 struct abis_om_obj_inst *obj_inst)
613{
614 struct gsm_bts_trx *trx;
615 struct gsm_nm_state *nm_state = NULL;
616
617 switch (obj_class) {
618 case NM_OC_BTS:
619 nm_state = &bts->nm_state;
620 break;
621 case NM_OC_RADIO_CARRIER:
622 if (obj_inst->trx_nr >= bts->num_trx)
623 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200624 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000625 nm_state = &trx->nm_state;
626 break;
627 case NM_OC_BASEB_TRANSC:
628 if (obj_inst->trx_nr >= bts->num_trx)
629 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200630 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000631 nm_state = &trx->bb_transc.nm_state;
632 break;
633 case NM_OC_CHANNEL:
634 if (obj_inst->trx_nr > bts->num_trx)
635 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200636 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000637 if (obj_inst->ts_nr >= TRX_NR_TS)
638 return NULL;
639 nm_state = &trx->ts[obj_inst->ts_nr].nm_state;
640 break;
641 case NM_OC_SITE_MANAGER:
642 nm_state = &bts->site_mgr.nm_state;
643 break;
Harald Welte7b26bcb2009-05-28 11:39:21 +0000644 case NM_OC_BS11:
645 switch (obj_inst->bts_nr) {
646 case BS11_OBJ_CCLK:
647 nm_state = &bts->bs11.cclk.nm_state;
648 break;
Harald Welte8b697c72009-06-05 19:18:45 +0000649 case BS11_OBJ_BBSIG:
650 if (obj_inst->ts_nr > bts->num_trx)
651 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200652 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Welte8b697c72009-06-05 19:18:45 +0000653 nm_state = &trx->bs11.bbsig.nm_state;
654 break;
655 case BS11_OBJ_PA:
656 if (obj_inst->ts_nr > bts->num_trx)
657 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200658 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Welte8b697c72009-06-05 19:18:45 +0000659 nm_state = &trx->bs11.pa.nm_state;
660 break;
Harald Welte7b26bcb2009-05-28 11:39:21 +0000661 default:
662 return NULL;
663 }
664 case NM_OC_BS11_RACK:
665 nm_state = &bts->bs11.rack.nm_state;
666 break;
Harald Welte8b697c72009-06-05 19:18:45 +0000667 case NM_OC_BS11_ENVABTSE:
668 if (obj_inst->trx_nr > ARRAY_SIZE(bts->bs11.envabtse))
669 return NULL;
670 nm_state = &bts->bs11.envabtse[obj_inst->trx_nr].nm_state;
671 break;
Harald Welte55dd4432009-10-24 10:19:14 +0200672 case NM_OC_GPRS_NSE:
673 nm_state = &bts->gprs.nse.nm_state;
674 break;
675 case NM_OC_GPRS_CELL:
676 nm_state = &bts->gprs.cell.nm_state;
677 break;
678 case NM_OC_GPRS_NSVC:
679 if (obj_inst->trx_nr > ARRAY_SIZE(bts->gprs.nsvc))
680 return NULL;
681 nm_state = &bts->gprs.nsvc[obj_inst->trx_nr].nm_state;
682 break;
Harald Weltee0590df2009-02-15 03:34:15 +0000683 }
684 return nm_state;
685}
686
687/* obtain the in-memory data structure of a given object instance */
688static void *
689objclass2obj(struct gsm_bts *bts, u_int8_t obj_class,
690 struct abis_om_obj_inst *obj_inst)
691{
692 struct gsm_bts_trx *trx;
693 void *obj = NULL;
694
695 switch (obj_class) {
696 case NM_OC_BTS:
697 obj = bts;
698 break;
699 case NM_OC_RADIO_CARRIER:
700 if (obj_inst->trx_nr >= bts->num_trx)
701 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200702 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000703 obj = trx;
704 break;
705 case NM_OC_BASEB_TRANSC:
706 if (obj_inst->trx_nr >= bts->num_trx)
707 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200708 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000709 obj = &trx->bb_transc;
710 break;
711 case NM_OC_CHANNEL:
712 if (obj_inst->trx_nr > bts->num_trx)
713 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200714 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000715 if (obj_inst->ts_nr >= TRX_NR_TS)
716 return NULL;
717 obj = &trx->ts[obj_inst->ts_nr];
718 break;
719 case NM_OC_SITE_MANAGER:
720 obj = &bts->site_mgr;
721 break;
Harald Welte55dd4432009-10-24 10:19:14 +0200722 case NM_OC_GPRS_NSE:
723 obj = &bts->gprs.nse;
724 break;
725 case NM_OC_GPRS_CELL:
726 obj = &bts->gprs.cell;
727 break;
728 case NM_OC_GPRS_NSVC:
729 if (obj_inst->trx_nr > ARRAY_SIZE(bts->gprs.nsvc))
730 return NULL;
731 obj = &bts->gprs.nsvc[obj_inst->trx_nr];
732 break;
Harald Weltee0590df2009-02-15 03:34:15 +0000733 }
734 return obj;
735}
736
737/* Update the administrative state of a given object in our in-memory data
738 * structures and send an event to the higher layer */
739static int update_admstate(struct gsm_bts *bts, u_int8_t obj_class,
740 struct abis_om_obj_inst *obj_inst, u_int8_t adm_state)
741{
Harald Welteaeedeb42009-05-01 13:08:14 +0000742 struct gsm_nm_state *nm_state, new_state;
Harald Weltee0590df2009-02-15 03:34:15 +0000743 void *obj;
744 int rc;
745
Harald Weltee0590df2009-02-15 03:34:15 +0000746 obj = objclass2obj(bts, obj_class, obj_inst);
Harald Welteaeedeb42009-05-01 13:08:14 +0000747 nm_state = objclass2nmstate(bts, obj_class, obj_inst);
748 if (!nm_state)
749 return -1;
750
751 new_state = *nm_state;
752 new_state.administrative = adm_state;
753
754 rc = nm_state_event(EVT_STATECHG_ADM, obj_class, obj, nm_state, &new_state);
755
756 nm_state->administrative = adm_state;
Harald Weltee0590df2009-02-15 03:34:15 +0000757
758 return rc;
759}
760
Harald Welte97ed1e72009-02-06 13:38:02 +0000761static int abis_nm_rx_statechg_rep(struct msgb *mb)
762{
Harald Weltee0590df2009-02-15 03:34:15 +0000763 struct abis_om_hdr *oh = msgb_l2(mb);
Harald Welte97ed1e72009-02-06 13:38:02 +0000764 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Harald Welte22af0db2009-02-14 15:41:08 +0000765 struct gsm_bts *bts = mb->trx->bts;
Harald Weltee0590df2009-02-15 03:34:15 +0000766 struct tlv_parsed tp;
767 struct gsm_nm_state *nm_state, new_state;
768 int rc;
769
Harald Welte23897662009-05-01 14:52:51 +0000770 DEBUGPC(DNM, "STATE CHG: ");
Harald Weltee0590df2009-02-15 03:34:15 +0000771
Harald Welte8b697c72009-06-05 19:18:45 +0000772 memset(&new_state, 0, sizeof(new_state));
773
Harald Weltee0590df2009-02-15 03:34:15 +0000774 nm_state = objclass2nmstate(bts, foh->obj_class, &foh->obj_inst);
775 if (!nm_state) {
776 DEBUGPC(DNM, "\n");
777 return -EINVAL;
Harald Welte22af0db2009-02-14 15:41:08 +0000778 }
Harald Weltee0590df2009-02-15 03:34:15 +0000779
780 new_state = *nm_state;
781
Harald Welte03133942009-02-18 19:51:53 +0000782 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Weltee0590df2009-02-15 03:34:15 +0000783 if (TLVP_PRESENT(&tp, NM_ATT_OPER_STATE)) {
784 new_state.operational = *TLVP_VAL(&tp, NM_ATT_OPER_STATE);
Harald Welte4d87f242009-03-10 19:43:44 +0000785 DEBUGPC(DNM, "OP_STATE=%s ", nm_opstate_name(new_state.operational));
Harald Weltee0590df2009-02-15 03:34:15 +0000786 }
787 if (TLVP_PRESENT(&tp, NM_ATT_AVAIL_STATUS)) {
Harald Welte0b8348d2009-02-18 03:43:01 +0000788 if (TLVP_LEN(&tp, NM_ATT_AVAIL_STATUS) == 0)
789 new_state.availability = 0xff;
790 else
791 new_state.availability = *TLVP_VAL(&tp, NM_ATT_AVAIL_STATUS);
Harald Welte4d87f242009-03-10 19:43:44 +0000792 DEBUGPC(DNM, "AVAIL=%s(%02x) ", nm_avail_name(new_state.availability),
Harald Weltee0590df2009-02-15 03:34:15 +0000793 new_state.availability);
794 }
795 if (TLVP_PRESENT(&tp, NM_ATT_ADM_STATE)) {
796 new_state.administrative = *TLVP_VAL(&tp, NM_ATT_ADM_STATE);
Holger Hans Peter Freyther2c481b22009-10-22 15:44:30 +0200797 DEBUGPC(DNM, "ADM=%2s ", nm_adm_name(new_state.administrative));
Harald Welte97ed1e72009-02-06 13:38:02 +0000798 }
799 DEBUGPC(DNM, "\n");
Harald Weltee0590df2009-02-15 03:34:15 +0000800
801 if (memcmp(&new_state, nm_state, sizeof(new_state))) {
802 /* Update the operational state of a given object in our in-memory data
803 * structures and send an event to the higher layer */
804 void *obj = objclass2obj(bts, foh->obj_class, &foh->obj_inst);
805 rc = nm_state_event(EVT_STATECHG_OPER, foh->obj_class, obj, nm_state, &new_state);
806 *nm_state = new_state;
807 }
808#if 0
Harald Welte22af0db2009-02-14 15:41:08 +0000809 if (op_state == 1) {
810 /* try to enable objects that are disabled */
811 abis_nm_opstart(bts, foh->obj_class,
812 foh->obj_inst.bts_nr,
813 foh->obj_inst.trx_nr,
814 foh->obj_inst.ts_nr);
815 }
Harald Weltee0590df2009-02-15 03:34:15 +0000816#endif
Harald Welte97ed1e72009-02-06 13:38:02 +0000817 return 0;
818}
819
Harald Welte0db97b22009-05-01 17:22:47 +0000820static int rx_fail_evt_rep(struct msgb *mb)
821{
822 struct abis_om_hdr *oh = msgb_l2(mb);
823 struct abis_om_fom_hdr *foh = msgb_l3(mb);
824 struct tlv_parsed tp;
825
826 DEBUGPC(DNM, "Failure Event Report ");
827
828 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
829
830 if (TLVP_PRESENT(&tp, NM_ATT_EVENT_TYPE))
831 DEBUGPC(DNM, "Type=%s ", event_type_name(*TLVP_VAL(&tp, NM_ATT_EVENT_TYPE)));
832 if (TLVP_PRESENT(&tp, NM_ATT_SEVERITY))
833 DEBUGPC(DNM, "Severity=%s ", severity_name(*TLVP_VAL(&tp, NM_ATT_SEVERITY)));
834
835 DEBUGPC(DNM, "\n");
836
837 return 0;
838}
839
Harald Welte97ed1e72009-02-06 13:38:02 +0000840static int abis_nm_rcvmsg_report(struct msgb *mb)
841{
842 struct abis_om_fom_hdr *foh = msgb_l3(mb);
843 u_int8_t mt = foh->msg_type;
844
Harald Weltea8bd6d42009-10-20 09:56:18 +0200845 debugp_foh(foh);
Harald Welte23897662009-05-01 14:52:51 +0000846
Harald Welte97ed1e72009-02-06 13:38:02 +0000847 //nmh->cfg->report_cb(mb, foh);
848
849 switch (mt) {
850 case NM_MT_STATECHG_EVENT_REP:
851 return abis_nm_rx_statechg_rep(mb);
852 break;
Harald Welte34a99682009-02-13 02:41:40 +0000853 case NM_MT_SW_ACTIVATED_REP:
Harald Welte23897662009-05-01 14:52:51 +0000854 DEBUGPC(DNM, "Software Activated Report\n");
Harald Weltef9a8cc32009-05-01 15:39:49 +0000855 dispatch_signal(SS_NM, S_NM_SW_ACTIV_REP, mb);
Harald Welte34a99682009-02-13 02:41:40 +0000856 break;
Harald Weltee0590df2009-02-15 03:34:15 +0000857 case NM_MT_FAILURE_EVENT_REP:
Harald Welte0db97b22009-05-01 17:22:47 +0000858 rx_fail_evt_rep(mb);
Harald Weltef9a8cc32009-05-01 15:39:49 +0000859 dispatch_signal(SS_NM, S_NM_FAIL_REP, mb);
Harald Weltee0590df2009-02-15 03:34:15 +0000860 break;
Harald Weltec7310382009-08-08 00:02:36 +0200861 case NM_MT_TEST_REP:
862 DEBUGPC(DNM, "Test Report\n");
863 dispatch_signal(SS_NM, S_NM_TEST_REP, mb);
864 break;
Harald Weltee0590df2009-02-15 03:34:15 +0000865 default:
Harald Welte23897662009-05-01 14:52:51 +0000866 DEBUGPC(DNM, "reporting NM MT 0x%02x\n", mt);
Harald Weltee0590df2009-02-15 03:34:15 +0000867 break;
868
Harald Welte97ed1e72009-02-06 13:38:02 +0000869 };
870
Harald Welte97ed1e72009-02-06 13:38:02 +0000871 return 0;
872}
873
Harald Welte34a99682009-02-13 02:41:40 +0000874/* Activate the specified software into the BTS */
875static int ipacc_sw_activate(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1,
Mike Habena03f9772009-10-01 14:56:13 +0200876 u_int8_t i2, const u_int8_t *sw_desc, u_int8_t swdesc_len)
Harald Welte34a99682009-02-13 02:41:40 +0000877{
878 struct abis_om_hdr *oh;
879 struct msgb *msg = nm_msgb_alloc();
880 u_int8_t len = swdesc_len;
881 u_int8_t *trailer;
882
883 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
884 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, obj_class, i0, i1, i2);
885
886 trailer = msgb_put(msg, swdesc_len);
887 memcpy(trailer, sw_desc, swdesc_len);
888
889 return abis_nm_sendmsg(bts, msg);
890}
891
892static int abis_nm_rx_sw_act_req(struct msgb *mb)
893{
894 struct abis_om_hdr *oh = msgb_l2(mb);
895 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Mike Habena03f9772009-10-01 14:56:13 +0200896 struct tlv_parsed tp;
897 const u_int8_t *sw_config;
898 int sw_config_len;
899 int file_id_len;
Harald Welte5c1e4582009-02-15 11:57:29 +0000900 int nack = 0;
Harald Welte34a99682009-02-13 02:41:40 +0000901 int ret;
902
Harald Weltea8bd6d42009-10-20 09:56:18 +0200903 debugp_foh(foh);
904
905 DEBUGPC(DNM, "SW Activate Request: ");
Harald Welte34a99682009-02-13 02:41:40 +0000906
Harald Welte5c1e4582009-02-15 11:57:29 +0000907 if (foh->obj_class >= 0xf0 && foh->obj_class <= 0xf3) {
908 DEBUGPC(DNM, "NACKing for GPRS obj_class 0x%02x\n", foh->obj_class);
909 nack = 1;
910 } else
911 DEBUGPC(DNM, "ACKing and Activating\n");
912
913 ret = abis_nm_sw_act_req_ack(mb->trx->bts, foh->obj_class,
Harald Welte34a99682009-02-13 02:41:40 +0000914 foh->obj_inst.bts_nr,
915 foh->obj_inst.trx_nr,
Harald Welte5c1e4582009-02-15 11:57:29 +0000916 foh->obj_inst.ts_nr, nack,
Harald Welte34a99682009-02-13 02:41:40 +0000917 foh->data, oh->length-sizeof(*foh));
918
Harald Welte5c1e4582009-02-15 11:57:29 +0000919 if (nack)
920 return ret;
921
Mike Habena03f9772009-10-01 14:56:13 +0200922 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
923 sw_config = TLVP_VAL(&tp, NM_ATT_SW_CONFIG);
924 sw_config_len = TLVP_LEN(&tp, NM_ATT_SW_CONFIG);
925 if (!TLVP_PRESENT(&tp, NM_ATT_SW_CONFIG)) {
926 DEBUGP(DNM, "SW config not found! Can't continue.\n");
927 return -EINVAL;
928 } else {
929 DEBUGP(DNM, "Found SW config: %s\n", hexdump(sw_config, sw_config_len));
930 }
931
932 if (sw_config[0] != NM_ATT_SW_DESCR)
933 DEBUGP(DNM, "SW_DESCR attribute identifier not found!\n");
934 if (sw_config[1] != NM_ATT_FILE_ID)
935 DEBUGP(DNM, "FILE_ID attribute identifier not found!\n");
936 file_id_len = sw_config[2] * 256 + sw_config[3];
937
938 /* Assumes first SW file in list is the one to be activated */
939 /* sw_config + 4 to skip over 2 attribute ID bytes and 16-bit length field */
Harald Welte34a99682009-02-13 02:41:40 +0000940 return ipacc_sw_activate(mb->trx->bts, foh->obj_class,
941 foh->obj_inst.bts_nr,
942 foh->obj_inst.trx_nr,
943 foh->obj_inst.ts_nr,
Mike Habena03f9772009-10-01 14:56:13 +0200944 sw_config + 4,
945 file_id_len);
Harald Welte34a99682009-02-13 02:41:40 +0000946}
947
Harald Weltee0590df2009-02-15 03:34:15 +0000948/* Receive a CHANGE_ADM_STATE_ACK, parse the TLV and update local state */
949static int abis_nm_rx_chg_adm_state_ack(struct msgb *mb)
950{
951 struct abis_om_hdr *oh = msgb_l2(mb);
952 struct abis_om_fom_hdr *foh = msgb_l3(mb);
953 struct tlv_parsed tp;
954 u_int8_t adm_state;
955
Harald Welte03133942009-02-18 19:51:53 +0000956 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Weltee0590df2009-02-15 03:34:15 +0000957 if (!TLVP_PRESENT(&tp, NM_ATT_ADM_STATE))
958 return -EINVAL;
959
960 adm_state = *TLVP_VAL(&tp, NM_ATT_ADM_STATE);
961
962 return update_admstate(mb->trx->bts, foh->obj_class, &foh->obj_inst, adm_state);
963}
964
Harald Welteee670472009-02-22 21:58:49 +0000965static int abis_nm_rx_lmt_event(struct msgb *mb)
966{
967 struct abis_om_hdr *oh = msgb_l2(mb);
968 struct abis_om_fom_hdr *foh = msgb_l3(mb);
969 struct tlv_parsed tp;
970
971 DEBUGP(DNM, "LMT Event ");
972 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
973 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_LOGON_SESSION) &&
974 TLVP_LEN(&tp, NM_ATT_BS11_LMT_LOGON_SESSION) >= 1) {
975 u_int8_t onoff = *TLVP_VAL(&tp, NM_ATT_BS11_LMT_LOGON_SESSION);
976 DEBUGPC(DNM, "LOG%s ", onoff ? "ON" : "OFF");
977 }
978 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV) &&
979 TLVP_LEN(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV) >= 1) {
980 u_int8_t level = *TLVP_VAL(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV);
981 DEBUGPC(DNM, "Level=%u ", level);
982 }
983 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_USER_NAME) &&
984 TLVP_LEN(&tp, NM_ATT_BS11_LMT_USER_NAME) >= 1) {
985 char *name = (char *) TLVP_VAL(&tp, NM_ATT_BS11_LMT_USER_NAME);
986 DEBUGPC(DNM, "Username=%s ", name);
987 }
988 DEBUGPC(DNM, "\n");
989 /* FIXME: parse LMT LOGON TIME */
990 return 0;
991}
992
Harald Welte52b1f982008-12-23 20:25:15 +0000993/* Receive a OML NM Message from BTS */
Harald Welte8470bf22008-12-25 23:28:35 +0000994static int abis_nm_rcvmsg_fom(struct msgb *mb)
Harald Welte52b1f982008-12-23 20:25:15 +0000995{
Harald Welte6c96ba52009-05-01 13:03:40 +0000996 struct abis_om_hdr *oh = msgb_l2(mb);
Harald Welte52b1f982008-12-23 20:25:15 +0000997 struct abis_om_fom_hdr *foh = msgb_l3(mb);
998 u_int8_t mt = foh->msg_type;
999
1000 /* check for unsolicited message */
Harald Welte97ed1e72009-02-06 13:38:02 +00001001 if (is_report(mt))
1002 return abis_nm_rcvmsg_report(mb);
Harald Welte52b1f982008-12-23 20:25:15 +00001003
Harald Welte4724f992009-01-18 18:01:49 +00001004 if (is_in_arr(mt, sw_load_msgs, ARRAY_SIZE(sw_load_msgs)))
1005 return abis_nm_rcvmsg_sw(mb);
1006
Harald Welte78fc0d42009-02-19 02:50:57 +00001007 if (is_in_arr(mt, nacks, ARRAY_SIZE(nacks))) {
Harald Welte6c96ba52009-05-01 13:03:40 +00001008 struct tlv_parsed tp;
Harald Welte4bd0a982009-10-08 20:18:59 +02001009
Harald Weltea8bd6d42009-10-20 09:56:18 +02001010 debugp_foh(foh);
Harald Welte4bd0a982009-10-08 20:18:59 +02001011
Harald Welte78fc0d42009-02-19 02:50:57 +00001012 if (nack_names[mt])
Harald Welte4bd0a982009-10-08 20:18:59 +02001013 DEBUGPC(DNM, "%s NACK ", nack_names[mt]);
Harald Welte6c96ba52009-05-01 13:03:40 +00001014 /* FIXME: NACK cause */
Harald Welte78fc0d42009-02-19 02:50:57 +00001015 else
Harald Welte4bd0a982009-10-08 20:18:59 +02001016 DEBUGPC(DNM, "NACK 0x%02x ", mt);
Harald Welte6c96ba52009-05-01 13:03:40 +00001017
1018 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
1019 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
1020 DEBUGPC(DNM, "CAUSE=%s\n",
1021 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
1022 else
1023 DEBUGPC(DNM, "\n");
Holger Hans Peter Freyther500f3ca2009-06-10 10:48:14 +02001024
1025 dispatch_signal(SS_NM, S_NM_NACK, (void*) ((long)mt));
1026 return 0;
Harald Welte78fc0d42009-02-19 02:50:57 +00001027 }
Harald Weltead384642008-12-26 10:20:07 +00001028#if 0
Harald Welte52b1f982008-12-23 20:25:15 +00001029 /* check if last message is to be acked */
1030 if (is_ack_nack(nmh->last_msgtype)) {
1031 if (mt == MT_ACK(nmh->last_msgtype)) {
1032 fprintf(stderr, "received ACK (0x%x)\n",
1033 foh->msg_type);
1034 /* we got our ACK, continue sending the next msg */
1035 } else if (mt == MT_NACK(nmh->last_msgtype)) {
1036 /* we got a NACK, signal this to the caller */
1037 fprintf(stderr, "received NACK (0x%x)\n",
1038 foh->msg_type);
1039 /* FIXME: somehow signal this to the caller */
1040 } else {
1041 /* really strange things happen */
1042 return -EINVAL;
1043 }
1044 }
Harald Weltead384642008-12-26 10:20:07 +00001045#endif
1046
Harald Welte97ed1e72009-02-06 13:38:02 +00001047 switch (mt) {
Harald Weltee0590df2009-02-15 03:34:15 +00001048 case NM_MT_CHG_ADM_STATE_ACK:
1049 return abis_nm_rx_chg_adm_state_ack(mb);
1050 break;
Harald Welte34a99682009-02-13 02:41:40 +00001051 case NM_MT_SW_ACT_REQ:
1052 return abis_nm_rx_sw_act_req(mb);
1053 break;
Harald Welte97ed1e72009-02-06 13:38:02 +00001054 case NM_MT_BS11_LMT_SESSION:
Harald Welteee670472009-02-22 21:58:49 +00001055 return abis_nm_rx_lmt_event(mb);
Harald Welte97ed1e72009-02-06 13:38:02 +00001056 break;
Harald Welte1989c082009-08-06 17:58:31 +02001057 case NM_MT_CONN_MDROP_LINK_ACK:
1058 DEBUGP(DNM, "CONN MDROP LINK ACK\n");
1059 break;
Harald Welte97ed1e72009-02-06 13:38:02 +00001060 }
1061
Harald Weltead384642008-12-26 10:20:07 +00001062 return 0;
Harald Welte52b1f982008-12-23 20:25:15 +00001063}
1064
Harald Welte677c21f2009-02-17 13:22:23 +00001065static int abis_nm_rx_ipacc(struct msgb *mb);
1066
1067static int abis_nm_rcvmsg_manuf(struct msgb *mb)
1068{
1069 int rc;
1070 int bts_type = mb->trx->bts->type;
1071
1072 switch (bts_type) {
Mike Habene2d82272009-10-02 12:19:34 +01001073 case GSM_BTS_TYPE_NANOBTS:
Harald Welte677c21f2009-02-17 13:22:23 +00001074 rc = abis_nm_rx_ipacc(mb);
1075 break;
1076 default:
1077 fprintf(stderr, "don't know how to parse OML for this "
1078 "BTS type (%u)\n", bts_type);
1079 rc = 0;
1080 break;
1081 }
1082
1083 return rc;
1084}
1085
Harald Welte52b1f982008-12-23 20:25:15 +00001086/* High-Level API */
1087/* Entry-point where L2 OML from BTS enters the NM code */
Harald Welte8470bf22008-12-25 23:28:35 +00001088int abis_nm_rcvmsg(struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +00001089{
Harald Welte52b1f982008-12-23 20:25:15 +00001090 struct abis_om_hdr *oh = msgb_l2(msg);
Harald Welte677c21f2009-02-17 13:22:23 +00001091 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +00001092
1093 /* Various consistency checks */
1094 if (oh->placement != ABIS_OM_PLACEMENT_ONLY) {
1095 fprintf(stderr, "ABIS OML placement 0x%x not supported\n",
1096 oh->placement);
1097 return -EINVAL;
1098 }
1099 if (oh->sequence != 0) {
1100 fprintf(stderr, "ABIS OML sequence 0x%x != 0x00\n",
1101 oh->sequence);
1102 return -EINVAL;
1103 }
Harald Welte702d8702008-12-26 20:25:35 +00001104#if 0
Holger Freytherca362a62009-01-04 21:05:01 +00001105 unsigned int l2_len = msg->tail - (u_int8_t *)msgb_l2(msg);
1106 unsigned int hlen = sizeof(*oh) + sizeof(struct abis_om_fom_hdr);
Harald Welte702d8702008-12-26 20:25:35 +00001107 if (oh->length + hlen > l2_len) {
Harald Welte52b1f982008-12-23 20:25:15 +00001108 fprintf(stderr, "ABIS OML truncated message (%u > %u)\n",
1109 oh->length + sizeof(*oh), l2_len);
1110 return -EINVAL;
1111 }
Harald Welte702d8702008-12-26 20:25:35 +00001112 if (oh->length + hlen < l2_len)
1113 fprintf(stderr, "ABIS OML message with extra trailer?!? (oh->len=%d, sizeof_oh=%d l2_len=%d\n", oh->length, sizeof(*oh), l2_len);
1114#endif
Harald Weltead384642008-12-26 10:20:07 +00001115 msg->l3h = (unsigned char *)oh + sizeof(*oh);
Harald Welte52b1f982008-12-23 20:25:15 +00001116
1117 switch (oh->mdisc) {
1118 case ABIS_OM_MDISC_FOM:
Harald Welte8470bf22008-12-25 23:28:35 +00001119 rc = abis_nm_rcvmsg_fom(msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001120 break;
Harald Welte677c21f2009-02-17 13:22:23 +00001121 case ABIS_OM_MDISC_MANUF:
1122 rc = abis_nm_rcvmsg_manuf(msg);
1123 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001124 case ABIS_OM_MDISC_MMI:
1125 case ABIS_OM_MDISC_TRAU:
Harald Welte677c21f2009-02-17 13:22:23 +00001126 fprintf(stderr, "unimplemented ABIS OML message discriminator 0x%x\n",
1127 oh->mdisc);
1128 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001129 default:
1130 fprintf(stderr, "unknown ABIS OML message discriminator 0x%x\n",
1131 oh->mdisc);
1132 return -EINVAL;
1133 }
1134
Harald Weltead384642008-12-26 10:20:07 +00001135 msgb_free(msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001136 return rc;
1137}
1138
1139#if 0
1140/* initialized all resources */
1141struct abis_nm_h *abis_nm_init(struct abis_nm_cfg *cfg)
1142{
1143 struct abis_nm_h *nmh;
1144
1145 nmh = malloc(sizeof(*nmh));
1146 if (!nmh)
1147 return NULL;
1148
1149 nmh->cfg = cfg;
1150
1151 return nmh;
1152}
1153
1154/* free all resources */
1155void abis_nm_fini(struct abis_nm_h *nmh)
1156{
1157 free(nmh);
1158}
1159#endif
1160
1161/* Here we are trying to define a high-level API that can be used by
1162 * the actual BSC implementation. However, the architecture is currently
1163 * still under design. Ideally the calls to this API would be synchronous,
1164 * while the underlying stack behind the APi runs in a traditional select
1165 * based state machine.
1166 */
1167
Harald Welte4724f992009-01-18 18:01:49 +00001168/* 6.2 Software Load: */
1169enum sw_state {
1170 SW_STATE_NONE,
1171 SW_STATE_WAIT_INITACK,
1172 SW_STATE_WAIT_SEGACK,
1173 SW_STATE_WAIT_ENDACK,
1174 SW_STATE_WAIT_ACTACK,
1175 SW_STATE_ERROR,
1176};
Harald Welte52b1f982008-12-23 20:25:15 +00001177
Harald Welte52b1f982008-12-23 20:25:15 +00001178struct abis_nm_sw {
Harald Welte4724f992009-01-18 18:01:49 +00001179 struct gsm_bts *bts;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001180 gsm_cbfn *cbfn;
1181 void *cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +00001182 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001183
Harald Welte52b1f982008-12-23 20:25:15 +00001184 /* this will become part of the SW LOAD INITIATE */
1185 u_int8_t obj_class;
1186 u_int8_t obj_instance[3];
Harald Welte4724f992009-01-18 18:01:49 +00001187
1188 u_int8_t file_id[255];
1189 u_int8_t file_id_len;
1190
1191 u_int8_t file_version[255];
1192 u_int8_t file_version_len;
1193
1194 u_int8_t window_size;
1195 u_int8_t seg_in_window;
1196
1197 int fd;
1198 FILE *stream;
1199 enum sw_state state;
Harald Welte1602ade2009-01-29 21:12:39 +00001200 int last_seg;
Harald Welte52b1f982008-12-23 20:25:15 +00001201};
1202
Harald Welte4724f992009-01-18 18:01:49 +00001203static struct abis_nm_sw g_sw;
1204
1205/* 6.2.1 / 8.3.1: Load Data Initiate */
1206static int sw_load_init(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +00001207{
Harald Welte4724f992009-01-18 18:01:49 +00001208 struct abis_om_hdr *oh;
1209 struct msgb *msg = nm_msgb_alloc();
1210 u_int8_t len = 3*2 + sw->file_id_len + sw->file_version_len;
1211
1212 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1213 fill_om_fom_hdr(oh, len, NM_MT_LOAD_INIT, sw->obj_class,
1214 sw->obj_instance[0], sw->obj_instance[1],
1215 sw->obj_instance[2]);
1216
1217 /* FIXME: this is BS11 specific format */
1218 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1219 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1220 sw->file_version);
1221 msgb_tv_put(msg, NM_ATT_WINDOW_SIZE, sw->window_size);
1222
1223 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001224}
1225
Harald Welte1602ade2009-01-29 21:12:39 +00001226static int is_last_line(FILE *stream)
1227{
1228 char next_seg_buf[256];
1229 long pos;
1230
1231 /* check if we're sending the last line */
1232 pos = ftell(stream);
1233 if (!fgets(next_seg_buf, sizeof(next_seg_buf)-2, stream)) {
1234 fseek(stream, pos, SEEK_SET);
1235 return 1;
1236 }
1237
1238 fseek(stream, pos, SEEK_SET);
1239 return 0;
1240}
1241
Harald Welte4724f992009-01-18 18:01:49 +00001242/* 6.2.2 / 8.3.2 Load Data Segment */
1243static int sw_load_segment(struct abis_nm_sw *sw)
1244{
1245 struct abis_om_hdr *oh;
1246 struct msgb *msg = nm_msgb_alloc();
1247 char seg_buf[256];
1248 char *line_buf = seg_buf+2;
Harald Welte3b8ba212009-01-29 12:27:58 +00001249 unsigned char *tlv;
Harald Welte4724f992009-01-18 18:01:49 +00001250 u_int8_t len;
Harald Welte4724f992009-01-18 18:01:49 +00001251
1252 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte3b8ba212009-01-29 12:27:58 +00001253
1254 switch (sw->bts->type) {
1255 case GSM_BTS_TYPE_BS11:
1256 if (fgets(line_buf, sizeof(seg_buf)-2, sw->stream) == NULL) {
1257 perror("fgets reading segment");
1258 return -EINVAL;
1259 }
1260 seg_buf[0] = 0x00;
Harald Welte1602ade2009-01-29 21:12:39 +00001261
1262 /* check if we're sending the last line */
1263 sw->last_seg = is_last_line(sw->stream);
1264 if (sw->last_seg)
1265 seg_buf[1] = 0;
1266 else
1267 seg_buf[1] = 1 + sw->seg_in_window++;
Harald Welte3b8ba212009-01-29 12:27:58 +00001268
1269 len = strlen(line_buf) + 2;
1270 tlv = msgb_put(msg, TLV_GROSS_LEN(len));
1271 tlv_put(tlv, NM_ATT_BS11_FILE_DATA, len, (u_int8_t *)seg_buf);
1272 /* BS11 wants CR + LF in excess of the TLV length !?! */
1273 tlv[1] -= 2;
1274
1275 /* we only now know the exact length for the OM hdr */
1276 len = strlen(line_buf)+2;
1277 break;
1278 default:
1279 /* FIXME: Other BTS types */
1280 return -1;
Harald Welte4724f992009-01-18 18:01:49 +00001281 }
Harald Welte4724f992009-01-18 18:01:49 +00001282
Harald Welte4724f992009-01-18 18:01:49 +00001283 fill_om_fom_hdr(oh, len, NM_MT_LOAD_SEG, sw->obj_class,
1284 sw->obj_instance[0], sw->obj_instance[1],
1285 sw->obj_instance[2]);
1286
1287 return abis_nm_sendmsg(sw->bts, msg);
1288}
1289
1290/* 6.2.4 / 8.3.4 Load Data End */
1291static int sw_load_end(struct abis_nm_sw *sw)
1292{
1293 struct abis_om_hdr *oh;
1294 struct msgb *msg = nm_msgb_alloc();
1295 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
1296
1297 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1298 fill_om_fom_hdr(oh, len, NM_MT_LOAD_END, sw->obj_class,
1299 sw->obj_instance[0], sw->obj_instance[1],
1300 sw->obj_instance[2]);
1301
1302 /* FIXME: this is BS11 specific format */
1303 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1304 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1305 sw->file_version);
1306
1307 return abis_nm_sendmsg(sw->bts, msg);
1308}
Harald Welte5e4d1b32009-02-01 13:36:56 +00001309
Harald Welte52b1f982008-12-23 20:25:15 +00001310/* Activate the specified software into the BTS */
Harald Welte4724f992009-01-18 18:01:49 +00001311static int sw_activate(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +00001312{
Harald Welte4724f992009-01-18 18:01:49 +00001313 struct abis_om_hdr *oh;
1314 struct msgb *msg = nm_msgb_alloc();
1315 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
Harald Welte52b1f982008-12-23 20:25:15 +00001316
Harald Welte4724f992009-01-18 18:01:49 +00001317 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1318 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, sw->obj_class,
1319 sw->obj_instance[0], sw->obj_instance[1],
1320 sw->obj_instance[2]);
1321
1322 /* FIXME: this is BS11 specific format */
1323 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1324 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1325 sw->file_version);
1326
1327 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001328}
Harald Welte4724f992009-01-18 18:01:49 +00001329
1330static int sw_open_file(struct abis_nm_sw *sw, const char *fname)
1331{
1332 char file_id[12+1];
1333 char file_version[80+1];
1334 int rc;
1335
1336 sw->fd = open(fname, O_RDONLY);
1337 if (sw->fd < 0)
1338 return sw->fd;
1339
1340 switch (sw->bts->type) {
1341 case GSM_BTS_TYPE_BS11:
1342 sw->stream = fdopen(sw->fd, "r");
1343 if (!sw->stream) {
1344 perror("fdopen");
1345 return -1;
1346 }
1347 /* read first line and parse file ID and VERSION */
Harald Welte3b8ba212009-01-29 12:27:58 +00001348 rc = fscanf(sw->stream, "@(#)%12s:%80s\r\n",
Harald Welte4724f992009-01-18 18:01:49 +00001349 file_id, file_version);
1350 if (rc != 2) {
1351 perror("parsing header line of software file");
1352 return -1;
1353 }
1354 strcpy((char *)sw->file_id, file_id);
1355 sw->file_id_len = strlen(file_id);
1356 strcpy((char *)sw->file_version, file_version);
1357 sw->file_version_len = strlen(file_version);
1358 /* rewind to start of file */
Harald Welte3b8ba212009-01-29 12:27:58 +00001359 rewind(sw->stream);
Harald Welte4724f992009-01-18 18:01:49 +00001360 break;
1361 default:
1362 /* We don't know how to treat them yet */
1363 close(sw->fd);
1364 return -EINVAL;
1365 }
1366
1367 return 0;
1368}
1369
1370static void sw_close_file(struct abis_nm_sw *sw)
1371{
1372 switch (sw->bts->type) {
1373 case GSM_BTS_TYPE_BS11:
1374 fclose(sw->stream);
1375 break;
1376 default:
1377 close(sw->fd);
1378 break;
1379 }
1380}
1381
1382/* Fill the window */
1383static int sw_fill_window(struct abis_nm_sw *sw)
1384{
1385 int rc;
1386
1387 while (sw->seg_in_window < sw->window_size) {
1388 rc = sw_load_segment(sw);
1389 if (rc < 0)
1390 return rc;
Harald Welte1602ade2009-01-29 21:12:39 +00001391 if (sw->last_seg)
1392 break;
Harald Welte4724f992009-01-18 18:01:49 +00001393 }
1394 return 0;
1395}
1396
1397/* callback function from abis_nm_rcvmsg() handler */
1398static int abis_nm_rcvmsg_sw(struct msgb *mb)
1399{
1400 struct abis_om_fom_hdr *foh = msgb_l3(mb);
1401 int rc = -1;
1402 struct abis_nm_sw *sw = &g_sw;
1403 enum sw_state old_state = sw->state;
1404
Harald Welte3ffd1372009-02-01 22:15:49 +00001405 //DEBUGP(DNM, "state %u, NM MT 0x%02x\n", sw->state, foh->msg_type);
Harald Welte4724f992009-01-18 18:01:49 +00001406
1407 switch (sw->state) {
1408 case SW_STATE_WAIT_INITACK:
1409 switch (foh->msg_type) {
1410 case NM_MT_LOAD_INIT_ACK:
1411 /* fill window with segments */
Harald Welte5e4d1b32009-02-01 13:36:56 +00001412 if (sw->cbfn)
1413 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1414 NM_MT_LOAD_INIT_ACK, mb,
1415 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001416 rc = sw_fill_window(sw);
1417 sw->state = SW_STATE_WAIT_SEGACK;
1418 break;
1419 case NM_MT_LOAD_INIT_NACK:
Harald Welte3ffd1372009-02-01 22:15:49 +00001420 if (sw->forced) {
1421 DEBUGP(DNM, "FORCED: Ignoring Software Load "
1422 "Init NACK\n");
1423 if (sw->cbfn)
1424 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1425 NM_MT_LOAD_INIT_ACK, mb,
1426 sw->cb_data, NULL);
1427 rc = sw_fill_window(sw);
1428 sw->state = SW_STATE_WAIT_SEGACK;
1429 } else {
1430 DEBUGP(DNM, "Software Load Init NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001431 /* FIXME: cause */
Harald Welte3ffd1372009-02-01 22:15:49 +00001432 if (sw->cbfn)
1433 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1434 NM_MT_LOAD_INIT_NACK, mb,
1435 sw->cb_data, NULL);
1436 sw->state = SW_STATE_ERROR;
1437 }
Harald Welte4724f992009-01-18 18:01:49 +00001438 break;
1439 }
1440 break;
1441 case SW_STATE_WAIT_SEGACK:
1442 switch (foh->msg_type) {
1443 case NM_MT_LOAD_SEG_ACK:
Harald Welte3ffd1372009-02-01 22:15:49 +00001444 if (sw->cbfn)
1445 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1446 NM_MT_LOAD_SEG_ACK, mb,
1447 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001448 sw->seg_in_window = 0;
Harald Welte1602ade2009-01-29 21:12:39 +00001449 if (!sw->last_seg) {
1450 /* fill window with more segments */
1451 rc = sw_fill_window(sw);
1452 sw->state = SW_STATE_WAIT_SEGACK;
1453 } else {
1454 /* end the transfer */
1455 sw->state = SW_STATE_WAIT_ENDACK;
1456 rc = sw_load_end(sw);
1457 }
Harald Welte4724f992009-01-18 18:01:49 +00001458 break;
1459 }
1460 break;
1461 case SW_STATE_WAIT_ENDACK:
1462 switch (foh->msg_type) {
1463 case NM_MT_LOAD_END_ACK:
1464 sw_close_file(sw);
Harald Welte5e4d1b32009-02-01 13:36:56 +00001465 DEBUGP(DNM, "Software Load End (BTS %u)\n",
1466 sw->bts->nr);
1467 sw->state = SW_STATE_NONE;
1468 if (sw->cbfn)
1469 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1470 NM_MT_LOAD_END_ACK, mb,
1471 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001472 break;
1473 case NM_MT_LOAD_END_NACK:
Holger Freyther31338a12009-02-06 17:43:50 +00001474 if (sw->forced) {
1475 DEBUGP(DNM, "FORCED: Ignoring Software Load"
1476 "End NACK\n");
1477 sw->state = SW_STATE_NONE;
1478 if (sw->cbfn)
1479 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1480 NM_MT_LOAD_END_ACK, mb,
1481 sw->cb_data, NULL);
1482 } else {
1483 DEBUGP(DNM, "Software Load End NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001484 /* FIXME: cause */
Holger Freyther31338a12009-02-06 17:43:50 +00001485 sw->state = SW_STATE_ERROR;
1486 if (sw->cbfn)
1487 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1488 NM_MT_LOAD_END_NACK, mb,
1489 sw->cb_data, NULL);
1490 }
Harald Welte4724f992009-01-18 18:01:49 +00001491 break;
1492 }
1493 case SW_STATE_WAIT_ACTACK:
1494 switch (foh->msg_type) {
1495 case NM_MT_ACTIVATE_SW_ACK:
1496 /* we're done */
Harald Welte5e4d1b32009-02-01 13:36:56 +00001497 DEBUGP(DNM, "Activate Software DONE!\n");
Harald Welte4724f992009-01-18 18:01:49 +00001498 sw->state = SW_STATE_NONE;
1499 rc = 0;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001500 if (sw->cbfn)
1501 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1502 NM_MT_ACTIVATE_SW_ACK, mb,
1503 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001504 break;
1505 case NM_MT_ACTIVATE_SW_NACK:
Harald Welte1602ade2009-01-29 21:12:39 +00001506 DEBUGP(DNM, "Activate Software NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001507 /* FIXME: cause */
Harald Welte4724f992009-01-18 18:01:49 +00001508 sw->state = SW_STATE_ERROR;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001509 if (sw->cbfn)
1510 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1511 NM_MT_ACTIVATE_SW_NACK, mb,
1512 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001513 break;
1514 }
1515 case SW_STATE_NONE:
Harald Weltea994a482009-05-01 15:54:23 +00001516 switch (foh->msg_type) {
1517 case NM_MT_ACTIVATE_SW_ACK:
1518 rc = 0;
1519 break;
1520 }
1521 break;
Harald Welte4724f992009-01-18 18:01:49 +00001522 case SW_STATE_ERROR:
1523 break;
1524 }
1525
1526 if (rc)
Harald Weltea994a482009-05-01 15:54:23 +00001527 DEBUGP(DNM, "unexpected NM MT 0x%02x in state %u -> %u\n",
Harald Welte4724f992009-01-18 18:01:49 +00001528 foh->msg_type, old_state, sw->state);
1529
1530 return rc;
1531}
1532
1533/* Load the specified software into the BTS */
1534int abis_nm_software_load(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00001535 u_int8_t win_size, int forced,
1536 gsm_cbfn *cbfn, void *cb_data)
Harald Welte4724f992009-01-18 18:01:49 +00001537{
1538 struct abis_nm_sw *sw = &g_sw;
1539 int rc;
1540
Harald Welte5e4d1b32009-02-01 13:36:56 +00001541 DEBUGP(DNM, "Software Load (BTS %u, File \"%s\")\n",
1542 bts->nr, fname);
1543
Harald Welte4724f992009-01-18 18:01:49 +00001544 if (sw->state != SW_STATE_NONE)
1545 return -EBUSY;
1546
1547 sw->bts = bts;
1548 sw->obj_class = NM_OC_SITE_MANAGER;
1549 sw->obj_instance[0] = 0xff;
1550 sw->obj_instance[1] = 0xff;
1551 sw->obj_instance[2] = 0xff;
1552 sw->window_size = win_size;
1553 sw->state = SW_STATE_WAIT_INITACK;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001554 sw->cbfn = cbfn;
1555 sw->cb_data = cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +00001556 sw->forced = forced;
Harald Welte4724f992009-01-18 18:01:49 +00001557
1558 rc = sw_open_file(sw, fname);
1559 if (rc < 0) {
1560 sw->state = SW_STATE_NONE;
1561 return rc;
1562 }
1563
1564 return sw_load_init(sw);
1565}
Harald Welte52b1f982008-12-23 20:25:15 +00001566
Harald Welte1602ade2009-01-29 21:12:39 +00001567int abis_nm_software_load_status(struct gsm_bts *bts)
1568{
1569 struct abis_nm_sw *sw = &g_sw;
1570 struct stat st;
1571 int rc, percent;
1572
1573 rc = fstat(sw->fd, &st);
1574 if (rc < 0) {
1575 perror("ERROR during stat");
1576 return rc;
1577 }
1578
1579 percent = (ftell(sw->stream) * 100) / st.st_size;
1580 return percent;
1581}
1582
Harald Welte5e4d1b32009-02-01 13:36:56 +00001583/* Activate the specified software into the BTS */
1584int abis_nm_software_activate(struct gsm_bts *bts, const char *fname,
1585 gsm_cbfn *cbfn, void *cb_data)
1586{
1587 struct abis_nm_sw *sw = &g_sw;
1588 int rc;
1589
1590 DEBUGP(DNM, "Activating Software (BTS %u, File \"%s\")\n",
1591 bts->nr, fname);
1592
1593 if (sw->state != SW_STATE_NONE)
1594 return -EBUSY;
1595
1596 sw->bts = bts;
1597 sw->obj_class = NM_OC_SITE_MANAGER;
1598 sw->obj_instance[0] = 0xff;
1599 sw->obj_instance[1] = 0xff;
1600 sw->obj_instance[2] = 0xff;
1601 sw->state = SW_STATE_WAIT_ACTACK;
1602 sw->cbfn = cbfn;
1603 sw->cb_data = cb_data;
1604
1605 /* Open the file in order to fill some sw struct members */
1606 rc = sw_open_file(sw, fname);
1607 if (rc < 0) {
1608 sw->state = SW_STATE_NONE;
1609 return rc;
1610 }
1611 sw_close_file(sw);
1612
1613 return sw_activate(sw);
1614}
1615
Harald Welte8470bf22008-12-25 23:28:35 +00001616static void fill_nm_channel(struct abis_nm_channel *ch, u_int8_t bts_port,
Harald Welte52b1f982008-12-23 20:25:15 +00001617 u_int8_t ts_nr, u_int8_t subslot_nr)
1618{
Harald Welteadaf08b2009-01-18 11:08:10 +00001619 ch->attrib = NM_ATT_ABIS_CHANNEL;
Harald Welte52b1f982008-12-23 20:25:15 +00001620 ch->bts_port = bts_port;
1621 ch->timeslot = ts_nr;
1622 ch->subslot = subslot_nr;
1623}
1624
1625int abis_nm_establish_tei(struct gsm_bts *bts, u_int8_t trx_nr,
1626 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot,
1627 u_int8_t tei)
1628{
1629 struct abis_om_hdr *oh;
1630 struct abis_nm_channel *ch;
Harald Welte702d8702008-12-26 20:25:35 +00001631 u_int8_t len = sizeof(*ch) + 2;
Harald Welte8470bf22008-12-25 23:28:35 +00001632 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001633
1634 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1635 fill_om_fom_hdr(oh, len, NM_MT_ESTABLISH_TEI, NM_OC_RADIO_CARRIER,
1636 bts->bts_nr, trx_nr, 0xff);
1637
Harald Welte8470bf22008-12-25 23:28:35 +00001638 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte52b1f982008-12-23 20:25:15 +00001639
1640 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1641 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1642
1643 return abis_nm_sendmsg(bts, msg);
1644}
1645
1646/* connect signalling of one (BTS,TRX) to a particular timeslot on the E1 */
1647int abis_nm_conn_terr_sign(struct gsm_bts_trx *trx,
1648 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot)
1649{
Harald Welte8470bf22008-12-25 23:28:35 +00001650 struct gsm_bts *bts = trx->bts;
Harald Welte52b1f982008-12-23 20:25:15 +00001651 struct abis_om_hdr *oh;
1652 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +00001653 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001654
1655 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001656 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_SIGN,
Harald Welte52b1f982008-12-23 20:25:15 +00001657 NM_OC_RADIO_CARRIER, bts->bts_nr, trx->nr, 0xff);
1658
1659 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1660 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1661
1662 return abis_nm_sendmsg(bts, msg);
1663}
1664
1665#if 0
1666int abis_nm_disc_terr_sign(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1667 struct abis_nm_abis_channel *chan)
1668{
1669}
1670#endif
1671
1672int abis_nm_conn_terr_traf(struct gsm_bts_trx_ts *ts,
1673 u_int8_t e1_port, u_int8_t e1_timeslot,
1674 u_int8_t e1_subslot)
1675{
1676 struct gsm_bts *bts = ts->trx->bts;
1677 struct abis_om_hdr *oh;
1678 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +00001679 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001680
1681 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1682 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_TRAF,
Harald Welteb110cee2009-02-18 03:42:35 +00001683 NM_OC_CHANNEL, bts->bts_nr, ts->trx->nr, ts->nr);
Harald Welte52b1f982008-12-23 20:25:15 +00001684
1685 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1686 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1687
Harald Weltef325eb42009-02-19 17:07:39 +00001688 DEBUGP(DNM, "CONNECT TERR TRAF Um=%s E1=(%u,%u,%u)\n",
1689 gsm_ts_name(ts),
Harald Welteb110cee2009-02-18 03:42:35 +00001690 e1_port, e1_timeslot, e1_subslot);
1691
Harald Welte52b1f982008-12-23 20:25:15 +00001692 return abis_nm_sendmsg(bts, msg);
1693}
1694
1695#if 0
1696int abis_nm_disc_terr_traf(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1697 struct abis_nm_abis_channel *chan,
1698 u_int8_t subchan)
1699{
1700}
1701#endif
1702
Harald Welte22af0db2009-02-14 15:41:08 +00001703/* Chapter 8.6.1 */
1704int abis_nm_set_bts_attr(struct gsm_bts *bts, u_int8_t *attr, int attr_len)
1705{
1706 struct abis_om_hdr *oh;
1707 struct msgb *msg = nm_msgb_alloc();
1708 u_int8_t *cur;
1709
1710 DEBUGP(DNM, "Set BTS Attr (bts=%d)\n", bts->nr);
1711
1712 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte191280d2009-05-01 13:20:04 +00001713 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 +00001714 cur = msgb_put(msg, attr_len);
1715 memcpy(cur, attr, attr_len);
1716
1717 return abis_nm_sendmsg(bts, msg);
1718}
1719
1720/* Chapter 8.6.2 */
1721int abis_nm_set_radio_attr(struct gsm_bts_trx *trx, u_int8_t *attr, int attr_len)
1722{
1723 struct abis_om_hdr *oh;
1724 struct msgb *msg = nm_msgb_alloc();
1725 u_int8_t *cur;
1726
1727 DEBUGP(DNM, "Set TRX Attr (bts=%d,trx=%d)\n", trx->bts->nr, trx->nr);
1728
1729 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1730 fill_om_fom_hdr(oh, attr_len, NM_MT_SET_RADIO_ATTR, NM_OC_RADIO_CARRIER,
Harald Welte191280d2009-05-01 13:20:04 +00001731 trx->bts->bts_nr, trx->nr, 0xff);
Harald Welte22af0db2009-02-14 15:41:08 +00001732 cur = msgb_put(msg, attr_len);
1733 memcpy(cur, attr, attr_len);
1734
1735 return abis_nm_sendmsg(trx->bts, msg);
1736}
1737
Harald Welte39c7deb2009-08-09 21:49:48 +02001738static int verify_chan_comb(struct gsm_bts_trx_ts *ts, u_int8_t chan_comb)
1739{
1740 int i;
1741
1742 /* As it turns out, the BS-11 has some very peculiar restrictions
1743 * on the channel combinations it allows */
1744 if (ts->trx->bts->type == GSM_BTS_TYPE_BS11) {
1745 switch (chan_comb) {
1746 case NM_CHANC_TCHHalf:
1747 case NM_CHANC_TCHHalf2:
1748 /* not supported */
1749 return -EINVAL;
1750 case NM_CHANC_SDCCH:
1751 /* only one SDCCH/8 per TRX */
1752 for (i = 0; i < TRX_NR_TS; i++) {
1753 if (i == ts->nr)
1754 continue;
1755 if (ts->trx->ts[i].nm_chan_comb ==
1756 NM_CHANC_SDCCH)
1757 return -EINVAL;
1758 }
1759 /* not allowed for TS0 of BCCH-TRX */
1760 if (ts->trx == ts->trx->bts->c0 &&
1761 ts->nr == 0)
1762 return -EINVAL;
1763 /* not on the same TRX that has a BCCH+SDCCH4
1764 * combination */
1765 if (ts->trx == ts->trx->bts->c0 &&
1766 (ts->trx->ts[0].nm_chan_comb == 5 ||
1767 ts->trx->ts[0].nm_chan_comb == 8))
1768 return -EINVAL;
1769 break;
1770 case NM_CHANC_mainBCCH:
1771 case NM_CHANC_BCCHComb:
1772 /* allowed only for TS0 of C0 */
1773 if (ts->trx != ts->trx->bts->c0 ||
1774 ts->nr != 0)
1775 return -EINVAL;
1776 break;
1777 case NM_CHANC_BCCH:
1778 /* allowed only for TS 2/4/6 of C0 */
1779 if (ts->trx != ts->trx->bts->c0)
1780 return -EINVAL;
1781 if (ts->nr != 2 && ts->nr != 4 &&
1782 ts->nr != 6)
1783 return -EINVAL;
1784 break;
1785 case 8: /* this is not like 08.58, but in fact
1786 * FCCH+SCH+BCCH+CCCH+SDCCH/4+SACCH/C4+CBCH */
1787 /* FIXME: only one CBCH allowed per cell */
1788 break;
1789 }
1790 }
1791 return 0;
1792}
1793
Harald Welte22af0db2009-02-14 15:41:08 +00001794/* Chapter 8.6.3 */
Harald Welte52b1f982008-12-23 20:25:15 +00001795int abis_nm_set_channel_attr(struct gsm_bts_trx_ts *ts, u_int8_t chan_comb)
1796{
1797 struct gsm_bts *bts = ts->trx->bts;
1798 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001799 u_int16_t arfcn = htons(ts->trx->arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001800 u_int8_t zero = 0x00;
Harald Welte8470bf22008-12-25 23:28:35 +00001801 struct msgb *msg = nm_msgb_alloc();
Harald Weltee0590df2009-02-15 03:34:15 +00001802 u_int8_t len = 2 + 2;
1803
1804 if (bts->type == GSM_BTS_TYPE_BS11)
1805 len += 4 + 2 + 2 + 3;
Harald Welte52b1f982008-12-23 20:25:15 +00001806
Harald Weltef325eb42009-02-19 17:07:39 +00001807 DEBUGP(DNM, "Set Chan Attr %s\n", gsm_ts_name(ts));
Harald Welte39c7deb2009-08-09 21:49:48 +02001808 if (verify_chan_comb(ts, chan_comb) < 0) {
1809 msgb_free(msg);
1810 DEBUGP(DNM, "Invalid Channel Combination!!!\n");
1811 return -EINVAL;
1812 }
1813 ts->nm_chan_comb = chan_comb;
Harald Welte22af0db2009-02-14 15:41:08 +00001814
Harald Welte52b1f982008-12-23 20:25:15 +00001815 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001816 fill_om_fom_hdr(oh, len, NM_MT_SET_CHAN_ATTR,
Holger Freyther6b2d2622009-02-14 23:16:59 +00001817 NM_OC_CHANNEL, bts->bts_nr,
Harald Welte52b1f982008-12-23 20:25:15 +00001818 ts->trx->nr, ts->nr);
1819 /* FIXME: don't send ARFCN list, hopping sequence, mAIO, ...*/
Harald Weltee0590df2009-02-15 03:34:15 +00001820 if (bts->type == GSM_BTS_TYPE_BS11)
1821 msgb_tlv16_put(msg, NM_ATT_ARFCN_LIST, 1, &arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001822 msgb_tv_put(msg, NM_ATT_CHAN_COMB, chan_comb);
Harald Weltee0590df2009-02-15 03:34:15 +00001823 if (bts->type == GSM_BTS_TYPE_BS11) {
1824 msgb_tv_put(msg, NM_ATT_HSN, 0x00);
1825 msgb_tv_put(msg, NM_ATT_MAIO, 0x00);
1826 }
Harald Weltee6c22d92009-07-21 20:40:05 +02001827 msgb_tv_put(msg, NM_ATT_TSC, bts->tsc); /* training sequence */
Harald Weltee0590df2009-02-15 03:34:15 +00001828 if (bts->type == GSM_BTS_TYPE_BS11)
1829 msgb_tlv_put(msg, 0x59, 1, &zero);
Harald Welte52b1f982008-12-23 20:25:15 +00001830
1831 return abis_nm_sendmsg(bts, msg);
1832}
1833
Harald Welte34a99682009-02-13 02:41:40 +00001834int 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 +00001835 u_int8_t i2, u_int8_t i3, int nack, u_int8_t *attr, int att_len)
Harald Welte34a99682009-02-13 02:41:40 +00001836{
1837 struct abis_om_hdr *oh;
1838 struct msgb *msg = nm_msgb_alloc();
Harald Welte5c1e4582009-02-15 11:57:29 +00001839 u_int8_t msgtype = NM_MT_SW_ACT_REQ_ACK;
1840 u_int8_t len = att_len;
1841
1842 if (nack) {
1843 len += 2;
1844 msgtype = NM_MT_SW_ACT_REQ_NACK;
1845 }
Harald Welte34a99682009-02-13 02:41:40 +00001846
1847 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte5c1e4582009-02-15 11:57:29 +00001848 fill_om_fom_hdr(oh, att_len, msgtype, obj_class, i1, i2, i3);
1849
Harald Welte34a99682009-02-13 02:41:40 +00001850 if (attr) {
1851 u_int8_t *ptr = msgb_put(msg, att_len);
1852 memcpy(ptr, attr, att_len);
1853 }
Harald Welte5c1e4582009-02-15 11:57:29 +00001854 if (nack)
1855 msgb_tv_put(msg, NM_ATT_NACK_CAUSES, NM_NACK_OBJCLASS_NOTSUPP);
Harald Welte34a99682009-02-13 02:41:40 +00001856
1857 return abis_nm_sendmsg(bts, msg);
1858}
1859
Harald Welte8470bf22008-12-25 23:28:35 +00001860int abis_nm_raw_msg(struct gsm_bts *bts, int len, u_int8_t *rawmsg)
Harald Welte52b1f982008-12-23 20:25:15 +00001861{
Harald Welte8470bf22008-12-25 23:28:35 +00001862 struct msgb *msg = nm_msgb_alloc();
1863 struct abis_om_hdr *oh;
Harald Welte52b1f982008-12-23 20:25:15 +00001864 u_int8_t *data;
1865
1866 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
1867 fill_om_hdr(oh, len);
1868 data = msgb_put(msg, len);
Harald Weltead384642008-12-26 10:20:07 +00001869 memcpy(data, rawmsg, len);
Harald Welte52b1f982008-12-23 20:25:15 +00001870
1871 return abis_nm_sendmsg(bts, msg);
1872}
1873
1874/* Siemens specific commands */
1875static int __simple_cmd(struct gsm_bts *bts, u_int8_t msg_type)
1876{
1877 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001878 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001879
1880 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001881 fill_om_fom_hdr(oh, 0, msg_type, NM_OC_SITE_MANAGER,
Harald Welte52b1f982008-12-23 20:25:15 +00001882 0xff, 0xff, 0xff);
1883
1884 return abis_nm_sendmsg(bts, msg);
1885}
1886
Harald Welte34a99682009-02-13 02:41:40 +00001887/* Chapter 8.9.2 */
1888int abis_nm_opstart(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1, u_int8_t i2)
1889{
1890 struct abis_om_hdr *oh;
1891 struct msgb *msg = nm_msgb_alloc();
1892
1893 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1894 fill_om_fom_hdr(oh, 0, NM_MT_OPSTART, obj_class, i0, i1, i2);
1895
Harald Weltea8bd6d42009-10-20 09:56:18 +02001896 debugp_foh((struct abis_om_fom_hdr *) oh->data);
1897 DEBUGPC(DNM, "Sending OPSTART\n");
1898
Harald Welte34a99682009-02-13 02:41:40 +00001899 return abis_nm_sendmsg(bts, msg);
1900}
1901
1902/* Chapter 8.8.5 */
1903int abis_nm_chg_adm_state(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0,
Daniel Willmann65f68fa2009-08-10 11:49:36 +02001904 u_int8_t i1, u_int8_t i2, enum abis_nm_adm_state adm_state)
Harald Welte34a99682009-02-13 02:41:40 +00001905{
1906 struct abis_om_hdr *oh;
1907 struct msgb *msg = nm_msgb_alloc();
1908
1909 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1910 fill_om_fom_hdr(oh, 2, NM_MT_CHG_ADM_STATE, obj_class, i0, i1, i2);
1911 msgb_tv_put(msg, NM_ATT_ADM_STATE, adm_state);
1912
1913 return abis_nm_sendmsg(bts, msg);
1914}
1915
Harald Welte1989c082009-08-06 17:58:31 +02001916int abis_nm_conn_mdrop_link(struct gsm_bts *bts, u_int8_t e1_port0, u_int8_t ts0,
1917 u_int8_t e1_port1, u_int8_t ts1)
1918{
1919 struct abis_om_hdr *oh;
1920 struct msgb *msg = nm_msgb_alloc();
1921 u_int8_t *attr;
1922
1923 DEBUGP(DNM, "CONNECT MDROP LINK E1=(%u,%u) -> E1=(%u, %u)\n",
1924 e1_port0, ts0, e1_port1, ts1);
1925
1926 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1927 fill_om_fom_hdr(oh, 6, NM_MT_CONN_MDROP_LINK,
1928 NM_OC_SITE_MANAGER, 0x00, 0x00, 0x00);
1929
1930 attr = msgb_put(msg, 3);
1931 attr[0] = NM_ATT_MDROP_LINK;
1932 attr[1] = e1_port0;
1933 attr[2] = ts0;
1934
1935 attr = msgb_put(msg, 3);
1936 attr[0] = NM_ATT_MDROP_NEXT;
1937 attr[1] = e1_port1;
1938 attr[2] = ts1;
1939
1940 return abis_nm_sendmsg(bts, msg);
1941}
Harald Welte34a99682009-02-13 02:41:40 +00001942
Harald Weltec7310382009-08-08 00:02:36 +02001943/* Chapter 8.7.1 */
1944int abis_nm_perform_test(struct gsm_bts *bts, u_int8_t obj_class,
1945 u_int8_t bts_nr, u_int8_t trx_nr, u_int8_t ts_nr,
1946 u_int8_t test_nr, u_int8_t auton_report,
1947 u_int8_t *phys_config, u_int16_t phys_config_len)
1948{
1949 struct abis_om_hdr *oh;
1950 struct msgb *msg = nm_msgb_alloc();
1951 int len = 4; /* 2 TV attributes */
1952
1953 DEBUGP(DNM, "PEFORM TEST\n");
1954
1955 if (phys_config_len)
1956 len += 3 + phys_config_len;
1957
1958 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1959 fill_om_fom_hdr(oh, len, NM_MT_PERF_TEST,
1960 obj_class, bts_nr, trx_nr, ts_nr);
1961 msgb_tv_put(msg, NM_ATT_TEST_NO, test_nr);
1962 msgb_tv_put(msg, NM_ATT_AUTON_REPORT, auton_report);
1963 if (phys_config_len)
1964 msgb_tl16v_put(msg, NM_ATT_PHYS_CONF, phys_config_len,
1965 phys_config);
1966
1967 return abis_nm_sendmsg(bts, msg);
1968}
1969
Harald Welte52b1f982008-12-23 20:25:15 +00001970int abis_nm_event_reports(struct gsm_bts *bts, int on)
1971{
1972 if (on == 0)
Harald Welte227d4072009-01-03 08:16:25 +00001973 return __simple_cmd(bts, NM_MT_STOP_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001974 else
Harald Welte227d4072009-01-03 08:16:25 +00001975 return __simple_cmd(bts, NM_MT_REST_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001976}
1977
Harald Welte47d88ae2009-01-04 12:02:08 +00001978/* Siemens (or BS-11) specific commands */
1979
Harald Welte3ffd1372009-02-01 22:15:49 +00001980int abis_nm_bs11_bsc_disconnect(struct gsm_bts *bts, int reconnect)
1981{
1982 if (reconnect == 0)
1983 return __simple_cmd(bts, NM_MT_BS11_DISCONNECT);
1984 else
1985 return __simple_cmd(bts, NM_MT_BS11_RECONNECT);
1986}
1987
Harald Welteb8427972009-02-05 19:27:17 +00001988int abis_nm_bs11_restart(struct gsm_bts *bts)
1989{
1990 return __simple_cmd(bts, NM_MT_BS11_RESTART);
1991}
1992
1993
Harald Welte268bb402009-02-01 19:11:56 +00001994struct bs11_date_time {
1995 u_int16_t year;
1996 u_int8_t month;
1997 u_int8_t day;
1998 u_int8_t hour;
1999 u_int8_t min;
2000 u_int8_t sec;
2001} __attribute__((packed));
2002
2003
2004void get_bs11_date_time(struct bs11_date_time *aet)
2005{
2006 time_t t;
2007 struct tm *tm;
2008
2009 t = time(NULL);
2010 tm = localtime(&t);
2011 aet->sec = tm->tm_sec;
2012 aet->min = tm->tm_min;
2013 aet->hour = tm->tm_hour;
2014 aet->day = tm->tm_mday;
2015 aet->month = tm->tm_mon;
2016 aet->year = htons(1900 + tm->tm_year);
2017}
2018
Harald Welte05188ee2009-01-18 11:39:08 +00002019int abis_nm_bs11_reset_resource(struct gsm_bts *bts)
Harald Welte52b1f982008-12-23 20:25:15 +00002020{
Harald Welte4668fda2009-01-03 08:19:29 +00002021 return __simple_cmd(bts, NM_MT_BS11_RESET_RESOURCE);
Harald Welte52b1f982008-12-23 20:25:15 +00002022}
2023
Harald Welte05188ee2009-01-18 11:39:08 +00002024int abis_nm_bs11_db_transmission(struct gsm_bts *bts, int begin)
Harald Welte52b1f982008-12-23 20:25:15 +00002025{
2026 if (begin)
Harald Welte4668fda2009-01-03 08:19:29 +00002027 return __simple_cmd(bts, NM_MT_BS11_BEGIN_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00002028 else
Harald Welte4668fda2009-01-03 08:19:29 +00002029 return __simple_cmd(bts, NM_MT_BS11_END_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00002030}
Harald Welte47d88ae2009-01-04 12:02:08 +00002031
Harald Welte05188ee2009-01-18 11:39:08 +00002032int abis_nm_bs11_create_object(struct gsm_bts *bts,
Harald Welte1bc09062009-01-18 14:17:52 +00002033 enum abis_bs11_objtype type, u_int8_t idx,
2034 u_int8_t attr_len, const u_int8_t *attr)
Harald Welte47d88ae2009-01-04 12:02:08 +00002035{
2036 struct abis_om_hdr *oh;
2037 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00002038 u_int8_t *cur;
Harald Welte47d88ae2009-01-04 12:02:08 +00002039
2040 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00002041 fill_om_fom_hdr(oh, attr_len, NM_MT_BS11_CREATE_OBJ,
Harald Welte268bb402009-02-01 19:11:56 +00002042 NM_OC_BS11, type, 0, idx);
Harald Welte1bc09062009-01-18 14:17:52 +00002043 cur = msgb_put(msg, attr_len);
2044 memcpy(cur, attr, attr_len);
Harald Welte47d88ae2009-01-04 12:02:08 +00002045
2046 return abis_nm_sendmsg(bts, msg);
2047}
2048
Harald Welte78fc0d42009-02-19 02:50:57 +00002049int abis_nm_bs11_delete_object(struct gsm_bts *bts,
2050 enum abis_bs11_objtype type, u_int8_t idx)
2051{
2052 struct abis_om_hdr *oh;
2053 struct msgb *msg = nm_msgb_alloc();
2054
2055 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2056 fill_om_fom_hdr(oh, 0, NM_MT_BS11_DELETE_OBJ,
2057 NM_OC_BS11, type, 0, idx);
2058
2059 return abis_nm_sendmsg(bts, msg);
2060}
2061
Harald Welte05188ee2009-01-18 11:39:08 +00002062int abis_nm_bs11_create_envaBTSE(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00002063{
2064 struct abis_om_hdr *oh;
2065 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00002066 u_int8_t zero = 0x00;
Harald Welte47d88ae2009-01-04 12:02:08 +00002067
2068 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00002069 fill_om_fom_hdr(oh, 3, NM_MT_BS11_CREATE_OBJ,
Harald Welte1bc09062009-01-18 14:17:52 +00002070 NM_OC_BS11_ENVABTSE, 0, idx, 0xff);
2071 msgb_tlv_put(msg, 0x99, 1, &zero);
Harald Welte47d88ae2009-01-04 12:02:08 +00002072
2073 return abis_nm_sendmsg(bts, msg);
2074}
2075
Harald Welte05188ee2009-01-18 11:39:08 +00002076int abis_nm_bs11_create_bport(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00002077{
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_CREATE_OBJ, NM_OC_BS11_BPORT,
Daniel Willmann65f68fa2009-08-10 11:49:36 +02002083 idx, 0xff, 0xff);
2084
2085 return abis_nm_sendmsg(bts, msg);
2086}
2087
2088int abis_nm_bs11_delete_bport(struct gsm_bts *bts, u_int8_t idx)
2089{
2090 struct abis_om_hdr *oh;
2091 struct msgb *msg = nm_msgb_alloc();
2092
2093 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2094 fill_om_fom_hdr(oh, 0, NM_MT_BS11_DELETE_OBJ, NM_OC_BS11_BPORT,
2095 idx, 0xff, 0xff);
Harald Welte47d88ae2009-01-04 12:02:08 +00002096
2097 return abis_nm_sendmsg(bts, msg);
2098}
Harald Welte05188ee2009-01-18 11:39:08 +00002099
Harald Welte78fc0d42009-02-19 02:50:57 +00002100static const u_int8_t sm_attr[] = { NM_ATT_TEI, NM_ATT_ABIS_CHANNEL };
2101int abis_nm_bs11_get_oml_tei_ts(struct gsm_bts *bts)
2102{
2103 struct abis_om_hdr *oh;
2104 struct msgb *msg = nm_msgb_alloc();
2105
2106 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2107 fill_om_fom_hdr(oh, 2+sizeof(sm_attr), NM_MT_GET_ATTR, NM_OC_SITE_MANAGER,
2108 0xff, 0xff, 0xff);
2109 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(sm_attr), sm_attr);
2110
2111 return abis_nm_sendmsg(bts, msg);
2112}
2113
Harald Welteb6c92ae2009-02-21 20:15:32 +00002114/* like abis_nm_conn_terr_traf + set_tei */
2115int abis_nm_bs11_conn_oml_tei(struct gsm_bts *bts, u_int8_t e1_port,
2116 u_int8_t e1_timeslot, u_int8_t e1_subslot,
2117 u_int8_t tei)
Harald Welte05188ee2009-01-18 11:39:08 +00002118{
2119 struct abis_om_hdr *oh;
2120 struct abis_nm_channel *ch;
2121 struct msgb *msg = nm_msgb_alloc();
2122
2123 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welteb6c92ae2009-02-21 20:15:32 +00002124 fill_om_fom_hdr(oh, sizeof(*ch)+2, NM_MT_BS11_SET_ATTR,
Harald Welte05188ee2009-01-18 11:39:08 +00002125 NM_OC_SITE_MANAGER, 0xff, 0xff, 0xff);
2126
2127 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
2128 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
Harald Welteb6c92ae2009-02-21 20:15:32 +00002129 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte05188ee2009-01-18 11:39:08 +00002130
2131 return abis_nm_sendmsg(bts, msg);
2132}
2133
2134int abis_nm_bs11_set_trx_power(struct gsm_bts_trx *trx, u_int8_t level)
2135{
2136 struct abis_om_hdr *oh;
2137 struct msgb *msg = nm_msgb_alloc();
Harald Welte05188ee2009-01-18 11:39:08 +00002138
2139 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00002140 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR,
Harald Welte05188ee2009-01-18 11:39:08 +00002141 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
2142 msgb_tlv_put(msg, NM_ATT_BS11_TXPWR, 1, &level);
2143
2144 return abis_nm_sendmsg(trx->bts, msg);
2145}
2146
Harald Welte78fc0d42009-02-19 02:50:57 +00002147int abis_nm_bs11_get_trx_power(struct gsm_bts_trx *trx)
2148{
2149 struct abis_om_hdr *oh;
2150 struct msgb *msg = nm_msgb_alloc();
2151 u_int8_t attr = NM_ATT_BS11_TXPWR;
2152
2153 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2154 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
2155 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
2156 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), &attr);
2157
2158 return abis_nm_sendmsg(trx->bts, msg);
2159}
2160
Harald Welteaaf02d92009-04-29 13:25:57 +00002161int abis_nm_bs11_get_pll_mode(struct gsm_bts *bts)
2162{
2163 struct abis_om_hdr *oh;
2164 struct msgb *msg = nm_msgb_alloc();
Harald Weltea7cfa032009-04-29 22:33:02 +00002165 u_int8_t attr[] = { NM_ATT_BS11_PLL_MODE };
Harald Welteaaf02d92009-04-29 13:25:57 +00002166
2167 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2168 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
2169 NM_OC_BS11, BS11_OBJ_LI, 0x00, 0x00);
Harald Welteaeedeb42009-05-01 13:08:14 +00002170 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), attr);
Harald Welteaaf02d92009-04-29 13:25:57 +00002171
2172 return abis_nm_sendmsg(bts, msg);
2173}
2174
Harald Welteef061952009-05-17 12:43:42 +00002175int abis_nm_bs11_get_cclk(struct gsm_bts *bts)
2176{
2177 struct abis_om_hdr *oh;
2178 struct msgb *msg = nm_msgb_alloc();
2179 u_int8_t attr[] = { NM_ATT_BS11_CCLK_ACCURACY,
2180 NM_ATT_BS11_CCLK_TYPE };
2181
2182 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2183 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
2184 NM_OC_BS11, BS11_OBJ_CCLK, 0x00, 0x00);
2185 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), attr);
2186
2187 return abis_nm_sendmsg(bts, msg);
2188
2189}
Harald Welteaaf02d92009-04-29 13:25:57 +00002190
Harald Welte268bb402009-02-01 19:11:56 +00002191//static const u_int8_t bs11_logon_c7[] = { 0x07, 0xd9, 0x01, 0x11, 0x0d, 0x10, 0x20 };
Harald Weltebb151312009-01-28 20:42:07 +00002192static const u_int8_t bs11_logon_c8[] = { 0x02 };
Harald Welte05188ee2009-01-18 11:39:08 +00002193static const u_int8_t bs11_logon_c9[] = "FACTORY";
2194
Harald Welte1bc09062009-01-18 14:17:52 +00002195int abis_nm_bs11_factory_logon(struct gsm_bts *bts, int on)
Harald Welte05188ee2009-01-18 11:39:08 +00002196{
2197 struct abis_om_hdr *oh;
2198 struct msgb *msg = nm_msgb_alloc();
Harald Welte268bb402009-02-01 19:11:56 +00002199 struct bs11_date_time bdt;
2200
2201 get_bs11_date_time(&bdt);
Harald Welte05188ee2009-01-18 11:39:08 +00002202
2203 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte1bc09062009-01-18 14:17:52 +00002204 if (on) {
Harald Welte268bb402009-02-01 19:11:56 +00002205 u_int8_t len = 3*2 + sizeof(bdt)
Harald Welte6f676a32009-01-18 14:27:48 +00002206 + sizeof(bs11_logon_c8) + sizeof(bs11_logon_c9);
Harald Welte043d04a2009-01-29 23:15:30 +00002207 fill_om_fom_hdr(oh, len, NM_MT_BS11_LMT_LOGON,
Harald Welte7b26bcb2009-05-28 11:39:21 +00002208 NM_OC_BS11_BTSE, 0xff, 0xff, 0xff);
Harald Welte043d04a2009-01-29 23:15:30 +00002209 msgb_tlv_put(msg, NM_ATT_BS11_LMT_LOGIN_TIME,
Harald Welte5083b0b2009-02-02 19:20:52 +00002210 sizeof(bdt), (u_int8_t *) &bdt);
Harald Welte043d04a2009-01-29 23:15:30 +00002211 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_ACC_LEV,
2212 sizeof(bs11_logon_c8), bs11_logon_c8);
2213 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_NAME,
2214 sizeof(bs11_logon_c9), bs11_logon_c9);
Harald Welte1bc09062009-01-18 14:17:52 +00002215 } else {
Harald Welte5e4d1b32009-02-01 13:36:56 +00002216 fill_om_fom_hdr(oh, 0, NM_MT_BS11_LMT_LOGOFF,
Harald Welte7b26bcb2009-05-28 11:39:21 +00002217 NM_OC_BS11_BTSE, 0xff, 0xff, 0xff);
Harald Welte1bc09062009-01-18 14:17:52 +00002218 }
Harald Welte05188ee2009-01-18 11:39:08 +00002219
2220 return abis_nm_sendmsg(bts, msg);
2221}
Harald Welte1bc09062009-01-18 14:17:52 +00002222
2223int abis_nm_bs11_set_trx1_pw(struct gsm_bts *bts, const char *password)
2224{
2225 struct abis_om_hdr *oh;
2226 struct msgb *msg;
2227
2228 if (strlen(password) != 10)
2229 return -EINVAL;
2230
2231 msg = nm_msgb_alloc();
2232 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00002233 fill_om_fom_hdr(oh, 2+strlen(password), NM_MT_BS11_SET_ATTR,
Harald Welte1bc09062009-01-18 14:17:52 +00002234 NM_OC_BS11, BS11_OBJ_TRX1, 0x00, 0x00);
2235 msgb_tlv_put(msg, NM_ATT_BS11_PASSWORD, 10, (const u_int8_t *)password);
2236
2237 return abis_nm_sendmsg(bts, msg);
2238}
2239
Harald Weltee69f5fb2009-04-28 16:31:38 +00002240/* change the BS-11 PLL Mode to either locked (E1 derived) or standalone */
2241int abis_nm_bs11_set_pll_locked(struct gsm_bts *bts, int locked)
2242{
2243 struct abis_om_hdr *oh;
2244 struct msgb *msg;
Harald Weltea432cd32009-04-29 13:01:50 +00002245 u_int8_t tlv_value;
Harald Weltee69f5fb2009-04-28 16:31:38 +00002246
2247 msg = nm_msgb_alloc();
2248 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2249 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR, NM_OC_BS11,
2250 BS11_OBJ_LI, 0x00, 0x00);
Harald Weltea432cd32009-04-29 13:01:50 +00002251
2252 if (locked)
2253 tlv_value = BS11_LI_PLL_LOCKED;
2254 else
2255 tlv_value = BS11_LI_PLL_STANDALONE;
2256
2257 msgb_tlv_put(msg, NM_ATT_BS11_PLL_MODE, 1, &tlv_value);
Harald Weltee69f5fb2009-04-28 16:31:38 +00002258
2259 return abis_nm_sendmsg(bts, msg);
2260}
2261
Harald Welte1bc09062009-01-18 14:17:52 +00002262int abis_nm_bs11_get_state(struct gsm_bts *bts)
2263{
2264 return __simple_cmd(bts, NM_MT_BS11_GET_STATE);
2265}
Harald Welte5e4d1b32009-02-01 13:36:56 +00002266
2267/* BS11 SWL */
2268
Harald Welte (local)d19e58b2009-08-15 02:30:58 +02002269void *tall_fle_ctx;
Harald Welte2cf161b2009-06-20 22:36:41 +02002270
Harald Welte5e4d1b32009-02-01 13:36:56 +00002271struct abis_nm_bs11_sw {
2272 struct gsm_bts *bts;
2273 char swl_fname[PATH_MAX];
2274 u_int8_t win_size;
Harald Welte3ffd1372009-02-01 22:15:49 +00002275 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00002276 struct llist_head file_list;
2277 gsm_cbfn *user_cb; /* specified by the user */
2278};
2279static struct abis_nm_bs11_sw _g_bs11_sw, *g_bs11_sw = &_g_bs11_sw;
2280
2281struct file_list_entry {
2282 struct llist_head list;
2283 char fname[PATH_MAX];
2284};
2285
2286struct file_list_entry *fl_dequeue(struct llist_head *queue)
2287{
2288 struct llist_head *lh;
2289
2290 if (llist_empty(queue))
2291 return NULL;
2292
2293 lh = queue->next;
2294 llist_del(lh);
2295
2296 return llist_entry(lh, struct file_list_entry, list);
2297}
2298
2299static int bs11_read_swl_file(struct abis_nm_bs11_sw *bs11_sw)
2300{
2301 char linebuf[255];
2302 struct llist_head *lh, *lh2;
2303 FILE *swl;
2304 int rc = 0;
2305
2306 swl = fopen(bs11_sw->swl_fname, "r");
2307 if (!swl)
2308 return -ENODEV;
2309
2310 /* zero the stale file list, if any */
2311 llist_for_each_safe(lh, lh2, &bs11_sw->file_list) {
2312 llist_del(lh);
Harald Welte2cf161b2009-06-20 22:36:41 +02002313 talloc_free(lh);
Harald Welte5e4d1b32009-02-01 13:36:56 +00002314 }
2315
2316 while (fgets(linebuf, sizeof(linebuf), swl)) {
2317 char file_id[12+1];
2318 char file_version[80+1];
2319 struct file_list_entry *fle;
2320 static char dir[PATH_MAX];
2321
2322 if (strlen(linebuf) < 4)
2323 continue;
Harald Welte3ffd1372009-02-01 22:15:49 +00002324
Harald Welte5e4d1b32009-02-01 13:36:56 +00002325 rc = sscanf(linebuf+4, "%12s:%80s\r\n", file_id, file_version);
2326 if (rc < 0) {
2327 perror("ERR parsing SWL file");
2328 rc = -EINVAL;
2329 goto out;
2330 }
2331 if (rc < 2)
2332 continue;
2333
Harald Welte470ec292009-06-26 20:25:23 +02002334 fle = talloc_zero(tall_fle_ctx, struct file_list_entry);
Harald Welte5e4d1b32009-02-01 13:36:56 +00002335 if (!fle) {
2336 rc = -ENOMEM;
2337 goto out;
2338 }
Harald Welte5e4d1b32009-02-01 13:36:56 +00002339
2340 /* construct new filename */
2341 strncpy(dir, bs11_sw->swl_fname, sizeof(dir));
2342 strncat(fle->fname, dirname(dir), sizeof(fle->fname) - 1);
2343 strcat(fle->fname, "/");
2344 strncat(fle->fname, file_id, sizeof(fle->fname) - 1 -strlen(fle->fname));
Harald Welte5e4d1b32009-02-01 13:36:56 +00002345
2346 llist_add_tail(&fle->list, &bs11_sw->file_list);
2347 }
2348
2349out:
2350 fclose(swl);
2351 return rc;
2352}
2353
2354/* bs11 swload specific callback, passed to abis_nm core swload */
2355static int bs11_swload_cbfn(unsigned int hook, unsigned int event,
2356 struct msgb *msg, void *data, void *param)
2357{
2358 struct abis_nm_bs11_sw *bs11_sw = data;
2359 struct file_list_entry *fle;
2360 int rc = 0;
2361
Harald Welte5e4d1b32009-02-01 13:36:56 +00002362 switch (event) {
2363 case NM_MT_LOAD_END_ACK:
2364 fle = fl_dequeue(&bs11_sw->file_list);
2365 if (fle) {
2366 /* start download the next file of our file list */
2367 rc = abis_nm_software_load(bs11_sw->bts, fle->fname,
2368 bs11_sw->win_size,
Harald Welte3ffd1372009-02-01 22:15:49 +00002369 bs11_sw->forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00002370 &bs11_swload_cbfn, bs11_sw);
Harald Welteac606dc2009-08-06 15:44:18 +02002371 talloc_free(fle);
Harald Welte5e4d1b32009-02-01 13:36:56 +00002372 } else {
2373 /* activate the SWL */
2374 rc = abis_nm_software_activate(bs11_sw->bts,
2375 bs11_sw->swl_fname,
2376 bs11_swload_cbfn,
2377 bs11_sw);
2378 }
2379 break;
Harald Welte3ffd1372009-02-01 22:15:49 +00002380 case NM_MT_LOAD_SEG_ACK:
Harald Welte5e4d1b32009-02-01 13:36:56 +00002381 case NM_MT_LOAD_END_NACK:
2382 case NM_MT_LOAD_INIT_ACK:
2383 case NM_MT_LOAD_INIT_NACK:
2384 case NM_MT_ACTIVATE_SW_NACK:
2385 case NM_MT_ACTIVATE_SW_ACK:
2386 default:
2387 /* fallthrough to the user callback */
Harald Welte97ed1e72009-02-06 13:38:02 +00002388 if (bs11_sw->user_cb)
2389 rc = bs11_sw->user_cb(hook, event, msg, NULL, NULL);
Harald Welte5e4d1b32009-02-01 13:36:56 +00002390 break;
2391 }
2392
2393 return rc;
2394}
2395
2396/* Siemens provides a SWL file that is a mere listing of all the other
2397 * files that are part of a software release. We need to upload first
2398 * the list file, and then each file that is listed in the list file */
2399int abis_nm_bs11_load_swl(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00002400 u_int8_t win_size, int forced, gsm_cbfn *cbfn)
Harald Welte5e4d1b32009-02-01 13:36:56 +00002401{
2402 struct abis_nm_bs11_sw *bs11_sw = g_bs11_sw;
2403 struct file_list_entry *fle;
2404 int rc = 0;
2405
2406 INIT_LLIST_HEAD(&bs11_sw->file_list);
2407 bs11_sw->bts = bts;
2408 bs11_sw->win_size = win_size;
2409 bs11_sw->user_cb = cbfn;
Harald Welte3ffd1372009-02-01 22:15:49 +00002410 bs11_sw->forced = forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00002411
2412 strncpy(bs11_sw->swl_fname, fname, sizeof(bs11_sw->swl_fname));
2413 rc = bs11_read_swl_file(bs11_sw);
2414 if (rc < 0)
2415 return rc;
2416
2417 /* dequeue next item in file list */
2418 fle = fl_dequeue(&bs11_sw->file_list);
2419 if (!fle)
2420 return -EINVAL;
2421
2422 /* start download the next file of our file list */
Harald Welte3ffd1372009-02-01 22:15:49 +00002423 rc = abis_nm_software_load(bts, fle->fname, win_size, forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00002424 bs11_swload_cbfn, bs11_sw);
Harald Welteac606dc2009-08-06 15:44:18 +02002425 talloc_free(fle);
Harald Welte5e4d1b32009-02-01 13:36:56 +00002426 return rc;
2427}
2428
Harald Welte5083b0b2009-02-02 19:20:52 +00002429#if 0
Harald Welte5e4d1b32009-02-01 13:36:56 +00002430static u_int8_t req_attr_btse[] = {
2431 NM_ATT_ADM_STATE, NM_ATT_BS11_LMT_LOGON_SESSION,
2432 NM_ATT_BS11_LMT_LOGIN_TIME, NM_ATT_BS11_LMT_USER_ACC_LEV,
2433 NM_ATT_BS11_LMT_USER_NAME,
2434
2435 0xaf, NM_ATT_BS11_RX_OFFSET, NM_ATT_BS11_VENDOR_NAME,
2436
2437 NM_ATT_BS11_SW_LOAD_INTENDED, NM_ATT_BS11_SW_LOAD_SAFETY,
2438
2439 NM_ATT_BS11_SW_LOAD_STORED };
2440
2441static u_int8_t req_attr_btsm[] = {
2442 NM_ATT_ABIS_CHANNEL, NM_ATT_TEI, NM_ATT_BS11_ABIS_EXT_TIME,
2443 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xce, NM_ATT_FILE_ID,
2444 NM_ATT_FILE_VERSION, NM_ATT_OPER_STATE, 0xe8, NM_ATT_BS11_ALL_TEST_CATG,
2445 NM_ATT_SW_DESCR, NM_ATT_GET_ARI };
Harald Welte5083b0b2009-02-02 19:20:52 +00002446#endif
Harald Welte5e4d1b32009-02-01 13:36:56 +00002447
2448static u_int8_t req_attr[] = {
2449 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xa8, NM_ATT_OPER_STATE,
2450 0xd5, 0xa1, NM_ATT_BS11_ESN_FW_CODE_NO, NM_ATT_BS11_ESN_HW_CODE_NO,
Harald Weltea7cfa032009-04-29 22:33:02 +00002451 0x42, NM_ATT_BS11_ESN_PCB_SERIAL, NM_ATT_BS11_PLL };
Harald Welte5e4d1b32009-02-01 13:36:56 +00002452
2453int abis_nm_bs11_get_serno(struct gsm_bts *bts)
2454{
2455 struct abis_om_hdr *oh;
2456 struct msgb *msg = nm_msgb_alloc();
2457
2458 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2459 /* SiemensHW CCTRL object */
2460 fill_om_fom_hdr(oh, 2+sizeof(req_attr), NM_MT_GET_ATTR, NM_OC_BS11,
2461 0x03, 0x00, 0x00);
2462 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(req_attr), req_attr);
2463
2464 return abis_nm_sendmsg(bts, msg);
2465}
Harald Welte268bb402009-02-01 19:11:56 +00002466
2467int abis_nm_bs11_set_ext_time(struct gsm_bts *bts)
2468{
2469 struct abis_om_hdr *oh;
2470 struct msgb *msg = nm_msgb_alloc();
2471 struct bs11_date_time aet;
2472
2473 get_bs11_date_time(&aet);
2474 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2475 /* SiemensHW CCTRL object */
2476 fill_om_fom_hdr(oh, 2+sizeof(aet), NM_MT_BS11_SET_ATTR, NM_OC_SITE_MANAGER,
2477 0xff, 0xff, 0xff);
Harald Welte5083b0b2009-02-02 19:20:52 +00002478 msgb_tlv_put(msg, NM_ATT_BS11_ABIS_EXT_TIME, sizeof(aet), (u_int8_t *) &aet);
Harald Welte268bb402009-02-01 19:11:56 +00002479
2480 return abis_nm_sendmsg(bts, msg);
2481}
Harald Welte5c1e4582009-02-15 11:57:29 +00002482
Daniel Willmann65f68fa2009-08-10 11:49:36 +02002483int abis_nm_bs11_set_bport_line_cfg(struct gsm_bts *bts, u_int8_t bport, enum abis_bs11_line_cfg line_cfg)
2484{
2485 struct abis_om_hdr *oh;
2486 struct msgb *msg = nm_msgb_alloc();
2487 struct bs11_date_time aet;
2488
2489 get_bs11_date_time(&aet);
2490 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2491 fill_om_fom_hdr(oh, 2, NM_MT_BS11_SET_ATTR, NM_OC_BS11_BPORT,
2492 bport, 0xff, 0x02);
2493 msgb_tv_put(msg, NM_ATT_BS11_LINE_CFG, line_cfg);
2494
2495 return abis_nm_sendmsg(bts, msg);
2496}
2497
Harald Welte5c1e4582009-02-15 11:57:29 +00002498/* ip.access nanoBTS specific commands */
Harald Welte5c1e4582009-02-15 11:57:29 +00002499static const char ipaccess_magic[] = "com.ipaccess";
2500
Harald Welte677c21f2009-02-17 13:22:23 +00002501
2502static int abis_nm_rx_ipacc(struct msgb *msg)
2503{
2504 struct abis_om_hdr *oh = msgb_l2(msg);
2505 struct abis_om_fom_hdr *foh;
2506 u_int8_t idstrlen = oh->data[0];
2507 struct tlv_parsed tp;
2508
2509 if (strncmp((char *)&oh->data[1], ipaccess_magic, idstrlen)) {
2510 DEBUGP(DNM, "id string is not com.ipaccess !?!\n");
2511 return -EINVAL;
2512 }
2513
Harald Welte193fefc2009-04-30 15:16:27 +00002514 foh = (struct abis_om_fom_hdr *) (oh->data + 1 + idstrlen);
Harald Welte03133942009-02-18 19:51:53 +00002515 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Welte677c21f2009-02-17 13:22:23 +00002516
Harald Weltea8bd6d42009-10-20 09:56:18 +02002517 debugp_foh(foh);
Harald Weltea62202b2009-10-19 21:46:54 +02002518
Harald Welte746d6092009-10-19 22:11:11 +02002519 DEBUGPC(DNM, "IPACCESS(0x%02x): ", foh->msg_type);
Harald Welte193fefc2009-04-30 15:16:27 +00002520
Harald Welte677c21f2009-02-17 13:22:23 +00002521 switch (foh->msg_type) {
2522 case NM_MT_IPACC_RSL_CONNECT_ACK:
Harald Welte193fefc2009-04-30 15:16:27 +00002523 DEBUGPC(DNM, "RSL CONNECT ACK ");
Harald Welte0efe9b72009-07-12 09:33:54 +02002524 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_DST_IP))
Harald Welte9de2bf82009-04-30 15:59:55 +00002525 DEBUGPC(DNM, "IP=%s ",
Harald Welte677c21f2009-02-17 13:22:23 +00002526 inet_ntoa(*((struct in_addr *)
Harald Welte0efe9b72009-07-12 09:33:54 +02002527 TLVP_VAL(&tp, NM_ATT_IPACC_DST_IP))));
2528 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_DST_IP_PORT))
Harald Welte9de2bf82009-04-30 15:59:55 +00002529 DEBUGPC(DNM, "PORT=%u ",
Harald Welte677c21f2009-02-17 13:22:23 +00002530 ntohs(*((u_int16_t *)
Harald Welte0efe9b72009-07-12 09:33:54 +02002531 TLVP_VAL(&tp, NM_ATT_IPACC_DST_IP_PORT))));
Harald Welte35d447b2009-10-19 22:49:33 +02002532 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_STREAM_ID))
2533 DEBUGPC(DNM, "STREAM=0x%02x ",
2534 *TLVP_VAL(&tp, NM_ATT_IPACC_STREAM_ID));
Harald Welte9de2bf82009-04-30 15:59:55 +00002535 DEBUGPC(DNM, "\n");
Harald Welte677c21f2009-02-17 13:22:23 +00002536 break;
2537 case NM_MT_IPACC_RSL_CONNECT_NACK:
Harald Welte193fefc2009-04-30 15:16:27 +00002538 DEBUGPC(DNM, "RSL CONNECT NACK ");
Harald Welte677c21f2009-02-17 13:22:23 +00002539 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
Harald Welte6c96ba52009-05-01 13:03:40 +00002540 DEBUGPC(DNM, " CAUSE=%s\n",
2541 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
Harald Welte677c21f2009-02-17 13:22:23 +00002542 else
2543 DEBUGPC(DNM, "\n");
2544 break;
Harald Welte193fefc2009-04-30 15:16:27 +00002545 case NM_MT_IPACC_SET_NVATTR_ACK:
2546 DEBUGPC(DNM, "SET NVATTR ACK\n");
2547 /* FIXME: decode and show the actual attributes */
2548 break;
2549 case NM_MT_IPACC_SET_NVATTR_NACK:
Harald Welte6c96ba52009-05-01 13:03:40 +00002550 DEBUGPC(DNM, "SET 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");
Harald Welte193fefc2009-04-30 15:16:27 +00002556 break;
Harald Welte684b1a82009-07-03 11:26:45 +02002557 case NM_MT_IPACC_GET_NVATTR_ACK:
2558 DEBUGPC(DNM, "GET NVATTR ACK\n");
2559 /* FIXME: decode and show the actual attributes */
2560 break;
2561 case NM_MT_IPACC_GET_NVATTR_NACK:
2562 DEBUGPC(DNM, "GET NVATTR NACK ");
2563 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
2564 DEBUGPC(DNM, " CAUSE=%s\n",
2565 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
2566 else
2567 DEBUGPC(DNM, "\n");
2568 break;
Harald Welte15c44172009-10-08 20:15:24 +02002569 case NM_MT_IPACC_SET_ATTR_ACK:
2570 DEBUGPC(DNM, "SET ATTR ACK\n");
2571 break;
2572 case NM_MT_IPACC_SET_ATTR_NACK:
2573 DEBUGPC(DNM, "SET ATTR NACK ");
2574 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
2575 DEBUGPC(DNM, " CAUSE=%s\n",
2576 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
2577 else
2578 DEBUGPC(DNM, "\n");
2579 break;
Harald Welte193fefc2009-04-30 15:16:27 +00002580 default:
2581 DEBUGPC(DNM, "unknown\n");
2582 break;
Harald Welte677c21f2009-02-17 13:22:23 +00002583 }
Holger Hans Peter Freythera7cd9fc2009-07-07 12:40:07 +02002584
2585 /* signal handling */
2586 switch (foh->msg_type) {
2587 case NM_MT_IPACC_RSL_CONNECT_NACK:
2588 case NM_MT_IPACC_SET_NVATTR_NACK:
2589 case NM_MT_IPACC_GET_NVATTR_NACK:
2590 dispatch_signal(SS_NM, S_NM_IPACC_NACK, (void*) ((long)foh->msg_type));
2591 break;
2592 default:
2593 break;
2594 }
2595
Harald Welte677c21f2009-02-17 13:22:23 +00002596 return 0;
2597}
2598
Harald Welte193fefc2009-04-30 15:16:27 +00002599/* send an ip-access manufacturer specific message */
Harald Welte5c1e4582009-02-15 11:57:29 +00002600int abis_nm_ipaccess_msg(struct gsm_bts *bts, u_int8_t msg_type,
2601 u_int8_t obj_class, u_int8_t bts_nr,
2602 u_int8_t trx_nr, u_int8_t ts_nr,
2603 u_int8_t *attr, int attr_len)
2604{
2605 struct msgb *msg = nm_msgb_alloc();
2606 struct abis_om_hdr *oh;
2607 struct abis_om_fom_hdr *foh;
2608 u_int8_t *data;
2609
2610 /* construct the 12.21 OM header, observe the erroneous length */
2611 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
2612 fill_om_hdr(oh, sizeof(*foh) + attr_len);
2613 oh->mdisc = ABIS_OM_MDISC_MANUF;
2614
2615 /* add the ip.access magic */
2616 data = msgb_put(msg, sizeof(ipaccess_magic)+1);
2617 *data++ = sizeof(ipaccess_magic);
2618 memcpy(data, ipaccess_magic, sizeof(ipaccess_magic));
2619
2620 /* fill the 12.21 FOM header */
2621 foh = (struct abis_om_fom_hdr *) msgb_put(msg, sizeof(*foh));
2622 foh->msg_type = msg_type;
2623 foh->obj_class = obj_class;
2624 foh->obj_inst.bts_nr = bts_nr;
2625 foh->obj_inst.trx_nr = trx_nr;
2626 foh->obj_inst.ts_nr = ts_nr;
2627
2628 if (attr && attr_len) {
2629 data = msgb_put(msg, attr_len);
2630 memcpy(data, attr, attr_len);
2631 }
2632
2633 return abis_nm_sendmsg(bts, msg);
2634}
Harald Welte677c21f2009-02-17 13:22:23 +00002635
Harald Welte193fefc2009-04-30 15:16:27 +00002636/* set some attributes in NVRAM */
2637int abis_nm_ipaccess_set_nvattr(struct gsm_bts *bts, u_int8_t *attr,
2638 int attr_len)
2639{
2640 return abis_nm_ipaccess_msg(bts, NM_MT_IPACC_SET_NVATTR,
2641 NM_OC_BASEB_TRANSC, 0, 0, 0xff, attr,
2642 attr_len);
2643}
2644
Harald Welte746d6092009-10-19 22:11:11 +02002645int abis_nm_ipaccess_rsl_connect(struct gsm_bts_trx *trx,
2646 u_int32_t ip, u_int16_t port, u_int8_t stream)
2647{
2648 struct in_addr ia;
2649 u_int8_t attr[] = { NM_ATT_IPACC_STREAM_ID, 0,
2650 NM_ATT_IPACC_DST_IP_PORT, 0, 0,
2651 NM_ATT_IPACC_DST_IP, 0, 0, 0, 0 };
2652
2653 int attr_len = sizeof(attr);
2654
2655 ia.s_addr = htonl(ip);
2656 attr[1] = stream;
2657 attr[3] = port >> 8;
2658 attr[4] = port & 0xff;
2659 *(u_int32_t *)(attr+6) = ia.s_addr;
2660
2661 /* if ip == 0, we use the default IP */
2662 if (ip == 0)
2663 attr_len -= 5;
2664
2665 DEBUGP(DNM, "ip.access RSL CONNECT IP=%s PORT=%u STREAM=0x%02x\n",
Harald Welte31a74902009-10-19 22:50:30 +02002666 inet_ntoa(ia), port, stream);
Harald Welte746d6092009-10-19 22:11:11 +02002667
2668 return abis_nm_ipaccess_msg(trx->bts, NM_MT_IPACC_RSL_CONNECT,
2669 NM_OC_BASEB_TRANSC, trx->bts->bts_nr,
2670 trx->nr, 0xff, attr, attr_len);
2671}
2672
Harald Welte193fefc2009-04-30 15:16:27 +00002673/* restart / reboot an ip.access nanoBTS */
2674int abis_nm_ipaccess_restart(struct gsm_bts *bts)
2675{
2676 return __simple_cmd(bts, NM_MT_IPACC_RESTART);
2677}
Harald Weltedaef5212009-10-24 10:20:41 +02002678
2679int abis_nm_ipaccess_set_attr(struct gsm_bts *bts, u_int8_t obj_class,
2680 u_int8_t bts_nr, u_int8_t trx_nr, u_int8_t ts_nr,
2681 u_int8_t *attr, u_int8_t attr_len)
2682{
2683 return abis_nm_ipaccess_msg(bts, NM_MT_IPACC_SET_ATTR,
2684 obj_class, bts_nr, trx_nr, ts_nr,
2685 attr, attr_len);
2686}
Harald Welte0f255852009-11-12 14:48:42 +01002687
2688static const char *ipacc_testres_names[] = {
2689 [NM_IPACC_TESTRES_SUCCESS] = "SUCCESS",
2690 [NM_IPACC_TESTRES_TIMEOUT] = "TIMEOUT",
2691 [NM_IPACC_TESTRES_NO_CHANS] = "NO CHANNELS",
2692 [NM_IPACC_TESTRES_PARTIAL] = "PARTIAL",
2693 [NM_IPACC_TESTRES_STOPPED] = "STOPPED",
2694};
2695
2696const char *ipacc_testres_name(u_int8_t res)
2697{
2698 if (res < ARRAY_SIZE(ipacc_testres_names) &&
2699 ipacc_testres_names[res])
2700 return ipacc_testres_names[res];
2701
2702 return "unknown";
2703}
2704
Harald Welteb40a38f2009-11-13 11:56:05 +01002705void ipac_parse_cgi(struct cell_global_id *cid, const u_int8_t *buf)
2706{
2707 cid->mcc = (buf[0] & 0xf) * 100;
2708 cid->mcc += (buf[0] >> 4) * 10;
2709 cid->mcc += (buf[1] & 0xf) * 1;
2710
2711 if (buf[1] >> 4 == 0xf) {
2712 cid->mnc = (buf[2] & 0xf) * 10;
2713 cid->mnc += (buf[2] >> 4) * 1;
2714 } else {
2715 cid->mnc = (buf[2] & 0xf) * 100;
2716 cid->mnc += (buf[2] >> 4) * 10;
2717 cid->mnc += (buf[1] >> 4) * 1;
2718 }
2719
2720 cid->lac = ntohs(buf+3);
2721 cid->ci = ntohs(buf+5);
2722}
2723
Harald Welte0f255852009-11-12 14:48:42 +01002724/* parse BCCH information IEI from wire format to struct ipac_bcch_info */
2725int ipac_parse_bcch_info(struct ipac_bcch_info *binf, u_int8_t *buf)
2726{
2727 u_int8_t *cur = buf;
2728 u_int16_t len;
2729
2730 memset(binf, 0, sizeof(binf));
2731
2732 if (cur[0] != NM_IPAC_EIE_BCCH_INFO)
2733 return -EINVAL;
2734 cur++;
2735
2736 len = ntohs(*(u_int16_t *)cur);
2737 cur += 2;
2738
2739 binf->info_type = ntohs(*(u_int16_t *)cur);
2740 cur += 2;
2741
2742 if (binf->info_type & IPAC_BINF_FREQ_ERR_QUAL)
2743 binf->freq_qual = *cur >> 2;
2744
2745 binf->arfcn = *cur++ & 3 << 8;
2746 binf->arfcn |= *cur++;
2747
2748 if (binf->info_type & IPAC_BINF_RXLEV)
2749 binf->rx_lev = *cur & 0x3f;
2750 cur++;
2751
2752 if (binf->info_type & IPAC_BINF_RXQUAL)
2753 binf->rx_qual = *cur & 0x7;
2754 cur++;
2755
2756 if (binf->info_type & IPAC_BINF_FREQ_ERR_QUAL)
2757 binf->freq_err = ntohs(*(u_int16_t *)cur);
2758 cur += 2;
2759
2760 if (binf->info_type & IPAC_BINF_FRAME_OFFSET)
2761 binf->frame_offset = ntohs(*(u_int16_t *)cur);
2762 cur += 2;
2763
2764 if (binf->info_type & IPAC_BINF_FRAME_NR_OFFSET)
2765 binf->frame_nr_offset = ntohl(*(u_int32_t *)cur);
2766 cur += 4;
2767
2768 if (binf->info_type & IPAC_BINF_BSIC)
2769 binf->bsic = *cur++ & 0x3f;
2770 cur++;
2771
Harald Welteb40a38f2009-11-13 11:56:05 +01002772 ipac_parse_cgi(&binf->cgi, cur);
2773 cur += 7;
Harald Welte0f255852009-11-12 14:48:42 +01002774
2775 if (binf->info_type & IPAC_BINF_NEIGH_BA_SI2) {
2776 memcpy(binf->ba_list_si2, cur, sizeof(binf->ba_list_si2));
2777 cur += sizeof(binf->ba_list_si2);
2778 }
2779
2780 if (binf->info_type & IPAC_BINF_NEIGH_BA_SI2bis) {
2781 memcpy(binf->ba_list_si2bis, cur,
2782 sizeof(binf->ba_list_si2bis));
2783 cur += sizeof(binf->ba_list_si2bis);
2784 }
2785
2786 if (binf->info_type & IPAC_BINF_NEIGH_BA_SI2ter) {
2787 memcpy(binf->ba_list_si2ter, cur,
2788 sizeof(binf->ba_list_si2ter));
2789 cur += sizeof(binf->ba_list_si2ter);
2790 }
2791
2792 return 0;
2793}
2794
2795