blob: 0eb8657dbb4a0a972bbd3a0cee0271fa05f58441 [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 },
331 [NM_ATT_FILE_DATA] = { TLV_TYPE_TL16V },
332 [NM_ATT_MEAS_RES] = { TLV_TYPE_TL16V },
333 /* BS11 specifics */
Harald Welte78fc0d42009-02-19 02:50:57 +0000334 [NM_ATT_BS11_ESN_FW_CODE_NO] = { TLV_TYPE_TLV },
335 [NM_ATT_BS11_ESN_HW_CODE_NO] = { TLV_TYPE_TLV },
336 [NM_ATT_BS11_ESN_PCB_SERIAL] = { TLV_TYPE_TLV },
337 [NM_ATT_BS11_BOOT_SW_VERS] = { TLV_TYPE_TLV },
338 [0xd5] = { TLV_TYPE_TLV },
339 [0xa8] = { TLV_TYPE_TLV },
Harald Weltee0590df2009-02-15 03:34:15 +0000340 [NM_ATT_BS11_PASSWORD] = { TLV_TYPE_TLV },
341 [NM_ATT_BS11_TXPWR] = { TLV_TYPE_TLV },
342 [NM_ATT_BS11_RSSI_OFFS] = { TLV_TYPE_TLV },
343 [NM_ATT_BS11_LINE_CFG] = { TLV_TYPE_TV },
344 [NM_ATT_BS11_L1_PROT_TYPE] = { TLV_TYPE_TV },
345 [NM_ATT_BS11_BIT_ERR_THESH] = { TLV_TYPE_FIXED, 2 },
346 [NM_ATT_BS11_DIVERSITY] = { TLV_TYPE_TLV },
Harald Welteee670472009-02-22 21:58:49 +0000347 [NM_ATT_BS11_LMT_LOGON_SESSION]={ TLV_TYPE_TLV },
Harald Weltee0590df2009-02-15 03:34:15 +0000348 [NM_ATT_BS11_LMT_LOGIN_TIME] = { TLV_TYPE_TLV },
349 [NM_ATT_BS11_LMT_USER_ACC_LEV] ={ TLV_TYPE_TLV },
350 [NM_ATT_BS11_LMT_USER_NAME] = { TLV_TYPE_TLV },
Harald Welte03133942009-02-18 19:51:53 +0000351 [NM_ATT_BS11_BTS_STATE] = { TLV_TYPE_TLV },
352 [NM_ATT_BS11_E1_STATE] = { TLV_TYPE_TLV },
Harald Welteaaf02d92009-04-29 13:25:57 +0000353 [NM_ATT_BS11_PLL_MODE] = { TLV_TYPE_TLV },
Harald Weltea7cfa032009-04-29 22:33:02 +0000354 [NM_ATT_BS11_PLL] = { TLV_TYPE_TLV },
Harald Welteef061952009-05-17 12:43:42 +0000355 [NM_ATT_BS11_CCLK_ACCURACY] = { TLV_TYPE_TV },
356 [NM_ATT_BS11_CCLK_TYPE] = { TLV_TYPE_TV },
Harald Welte677c21f2009-02-17 13:22:23 +0000357 /* ip.access specifics */
Harald Welte0efe9b72009-07-12 09:33:54 +0200358 [NM_ATT_IPACC_DST_IP] = { TLV_TYPE_FIXED, 4 },
359 [NM_ATT_IPACC_DST_IP_PORT] = { TLV_TYPE_FIXED, 2 },
Harald Welte4fbfd3a2009-08-06 17:57:23 +0200360 [NM_ATT_IPACC_STREAM_ID] = { TLV_TYPE_TV, },
361 [NM_ATT_IPACC_FREQ_CTRL] = { TLV_TYPE_TV, },
362 [NM_ATT_IPACC_SEC_OML_CFG] = { TLV_TYPE_FIXED, 6 },
363 [NM_ATT_IPACC_IP_IF_CFG] = { TLV_TYPE_FIXED, 8 },
364 [NM_ATT_IPACC_IP_GW_CFG] = { TLV_TYPE_FIXED, 12 },
365 [NM_ATT_IPACC_IN_SERV_TIME] = { TLV_TYPE_FIXED, 4 },
366 [NM_ATT_IPACC_LOCATION] = { TLV_TYPE_TL16V },
367 [NM_ATT_IPACC_PAGING_CFG] = { TLV_TYPE_FIXED, 2 },
368 [NM_ATT_IPACC_UNIT_ID] = { TLV_TYPE_TL16V },
369 [NM_ATT_IPACC_UNIT_NAME] = { TLV_TYPE_TL16V },
370 [NM_ATT_IPACC_SNMP_CFG] = { TLV_TYPE_TL16V },
Harald Welte0efe9b72009-07-12 09:33:54 +0200371 [NM_ATT_IPACC_PRIM_OML_CFG_LIST] = { TLV_TYPE_TL16V },
Harald Weltea0c0b572009-07-03 12:46:27 +0200372 [NM_ATT_IPACC_NV_FLAGS] = { TLV_TYPE_TL16V },
373 [NM_ATT_IPACC_FREQ_CTRL] = { TLV_TYPE_FIXED, 2 },
Harald Welte0efe9b72009-07-12 09:33:54 +0200374 [NM_ATT_IPACC_PRIM_OML_FB_TOUT] = { TLV_TYPE_TL16V },
Harald Welte4fbfd3a2009-08-06 17:57:23 +0200375 [NM_ATT_IPACC_CUR_SW_CFG] = { TLV_TYPE_TL16V },
376 [NM_ATT_IPACC_TIMING_BUS] = { TLV_TYPE_TL16V },
377 [NM_ATT_IPACC_CGI] = { TLV_TYPE_TL16V },
378 [NM_ATT_IPACC_RAC] = { TLV_TYPE_TL16V },
379 [NM_ATT_IPACC_OBJ_VERSION] = { TLV_TYPE_TL16V },
380 [NM_ATT_IPACC_GPRS_PAGING_CFG]= { TLV_TYPE_TL16V },
381 [NM_ATT_IPACC_NSEI] = { TLV_TYPE_TL16V },
382 [NM_ATT_IPACC_BVCI] = { TLV_TYPE_TL16V },
383 [NM_ATT_IPACC_NSVCI] = { TLV_TYPE_TL16V },
384 [NM_ATT_IPACC_NS_CFG] = { TLV_TYPE_TL16V },
385 [NM_ATT_IPACC_BSSGP_CFG] = { TLV_TYPE_TL16V },
386 [NM_ATT_IPACC_NS_LINK_CFG] = { TLV_TYPE_TL16V },
387 [NM_ATT_IPACC_RLC_CFG] = { TLV_TYPE_TL16V },
Harald Weltea0c0b572009-07-03 12:46:27 +0200388 [NM_ATT_IPACC_ALM_THRESH_LIST]= { TLV_TYPE_TL16V },
Harald Welte4fbfd3a2009-08-06 17:57:23 +0200389 [NM_ATT_IPACC_MONIT_VAL_LIST] = { TLV_TYPE_TL16V },
390 [NM_ATT_IPACC_TIB_CONTROL] = { TLV_TYPE_TL16V },
391 [NM_ATT_IPACC_SUPP_FEATURES] = { TLV_TYPE_TL16V },
392 [NM_ATT_IPACC_CODING_SCHEMES] = { TLV_TYPE_TL16V },
393 [NM_ATT_IPACC_RLC_CFG_2] = { TLV_TYPE_TL16V },
394 [NM_ATT_IPACC_HEARTB_TOUT] = { TLV_TYPE_TL16V },
395 [NM_ATT_IPACC_UPTIME] = { TLV_TYPE_TL16V },
396 [NM_ATT_IPACC_RLC_CFG_3] = { TLV_TYPE_TL16V },
397 [NM_ATT_IPACC_SSL_CFG] = { TLV_TYPE_TL16V },
398 [NM_ATT_IPACC_SEC_POSSIBLE] = { TLV_TYPE_TL16V },
399 [NM_ATT_IPACC_IML_SSL_STATE] = { TLV_TYPE_TL16V },
400 [NM_ATT_IPACC_REVOC_DATE] = { TLV_TYPE_TL16V },
Harald Weltea0c0b572009-07-03 12:46:27 +0200401 //[0x95] = { TLV_TYPE_FIXED, 2 },
Harald Welte677c21f2009-02-17 13:22:23 +0000402 [0x85] = { TLV_TYPE_TV },
403
Harald Weltee0590df2009-02-15 03:34:15 +0000404 },
405};
Harald Welte03133942009-02-18 19:51:53 +0000406
407int abis_nm_tlv_parse(struct tlv_parsed *tp, const u_int8_t *buf, int len)
408{
Harald Weltea4d49e92009-05-23 06:39:58 +0000409 return tlv_parse(tp, &nm_att_tlvdef, buf, len, 0, 0);
Harald Welte03133942009-02-18 19:51:53 +0000410}
Harald Weltee0590df2009-02-15 03:34:15 +0000411
Harald Welte52b1f982008-12-23 20:25:15 +0000412static int is_in_arr(enum abis_nm_msgtype mt, const enum abis_nm_msgtype *arr, int size)
413{
414 int i;
415
416 for (i = 0; i < size; i++) {
417 if (arr[i] == mt)
418 return 1;
419 }
420
421 return 0;
422}
423
Holger Freytherca362a62009-01-04 21:05:01 +0000424#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000425/* is this msgtype the usual ACK/NACK type ? */
426static int is_ack_nack(enum abis_nm_msgtype mt)
427{
428 return !is_in_arr(mt, no_ack_nack, ARRAY_SIZE(no_ack_nack));
429}
Holger Freytherca362a62009-01-04 21:05:01 +0000430#endif
Harald Welte52b1f982008-12-23 20:25:15 +0000431
432/* is this msgtype a report ? */
433static int is_report(enum abis_nm_msgtype mt)
434{
Harald Welte8470bf22008-12-25 23:28:35 +0000435 return is_in_arr(mt, reports, ARRAY_SIZE(reports));
Harald Welte52b1f982008-12-23 20:25:15 +0000436}
437
438#define MT_ACK(x) (x+1)
439#define MT_NACK(x) (x+2)
440
441static void fill_om_hdr(struct abis_om_hdr *oh, u_int8_t len)
442{
443 oh->mdisc = ABIS_OM_MDISC_FOM;
444 oh->placement = ABIS_OM_PLACEMENT_ONLY;
445 oh->sequence = 0;
446 oh->length = len;
447}
448
449static void fill_om_fom_hdr(struct abis_om_hdr *oh, u_int8_t len,
450 u_int8_t msg_type, u_int8_t obj_class,
451 u_int8_t bts_nr, u_int8_t trx_nr, u_int8_t ts_nr)
452{
453 struct abis_om_fom_hdr *foh =
454 (struct abis_om_fom_hdr *) oh->data;
455
Harald Welte702d8702008-12-26 20:25:35 +0000456 fill_om_hdr(oh, len+sizeof(*foh));
Harald Welte52b1f982008-12-23 20:25:15 +0000457 foh->msg_type = msg_type;
458 foh->obj_class = obj_class;
459 foh->obj_inst.bts_nr = bts_nr;
460 foh->obj_inst.trx_nr = trx_nr;
461 foh->obj_inst.ts_nr = ts_nr;
462}
463
Harald Welte8470bf22008-12-25 23:28:35 +0000464static struct msgb *nm_msgb_alloc(void)
465{
Harald Welte966636f2009-06-26 19:39:35 +0200466 return msgb_alloc_headroom(OM_ALLOC_SIZE, OM_HEADROOM_SIZE,
467 "OML");
Harald Welte8470bf22008-12-25 23:28:35 +0000468}
469
Harald Welte52b1f982008-12-23 20:25:15 +0000470/* Send a OML NM Message from BSC to BTS */
471int abis_nm_sendmsg(struct gsm_bts *bts, struct msgb *msg)
472{
Holger Freyther59639e82009-02-09 23:09:55 +0000473 msg->trx = bts->c0;
474
Harald Weltead384642008-12-26 10:20:07 +0000475 return _abis_nm_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000476}
477
Harald Welte4724f992009-01-18 18:01:49 +0000478static int abis_nm_rcvmsg_sw(struct msgb *mb);
479
Harald Welte34a99682009-02-13 02:41:40 +0000480static const char *obj_class_name(u_int8_t oc)
481{
Harald Welte7b26bcb2009-05-28 11:39:21 +0000482 switch (oc) {
483 case NM_OC_SITE_MANAGER:
484 return "SITE MANAGER";
485 case NM_OC_BTS:
486 return "BTS";
487 case NM_OC_RADIO_CARRIER:
488 return "RADIO CARRIER";
489 case NM_OC_BASEB_TRANSC:
490 return "BASEBAND TRANSCEIVER";
491 case NM_OC_CHANNEL:
Harald Weltebd8f7e32009-06-09 20:17:12 +0000492 return "CHANNEL";
Harald Welte7b26bcb2009-05-28 11:39:21 +0000493 case NM_OC_BS11_ADJC:
494 return "ADJC";
495 case NM_OC_BS11_HANDOVER:
496 return "HANDOVER";
497 case NM_OC_BS11_PWR_CTRL:
498 return "POWER CONTROL";
499 case NM_OC_BS11_BTSE:
500 return "BTSE";
501 case NM_OC_BS11_RACK:
502 return "RACK";
503 case NM_OC_BS11_TEST:
504 return "TEST";
505 case NM_OC_BS11_ENVABTSE:
506 return "ENVABTSE";
507 case NM_OC_BS11_BPORT:
508 return "BPORT";
509 case NM_OC_GPRS_NSE:
510 return "GPRS NSE";
511 case NM_OC_GPRS_CELL:
512 return "GPRS CELL";
Harald Welted83a1272009-07-12 10:56:06 +0200513 case NM_OC_GPRS_NSVC:
514 return "GPRS NSVC";
Harald Welte8b697c72009-06-05 19:18:45 +0000515 case NM_OC_BS11:
516 return "SIEMENSHW";
Harald Welte7b26bcb2009-05-28 11:39:21 +0000517 }
518
519 return "UNKNOWN";
Harald Welte34a99682009-02-13 02:41:40 +0000520}
521
Harald Welte4d87f242009-03-10 19:43:44 +0000522const char *nm_opstate_name(u_int8_t os)
Harald Welte34a99682009-02-13 02:41:40 +0000523{
524 switch (os) {
525 case 1:
526 return "Disabled";
527 case 2:
528 return "Enabled";
529 case 0xff:
530 return "NULL";
531 default:
532 return "RFU";
533 }
534}
535
Harald Weltee0590df2009-02-15 03:34:15 +0000536/* Chapter 9.4.7 */
Harald Welte4d87f242009-03-10 19:43:44 +0000537static const char *avail_names[] = {
Harald Weltee0590df2009-02-15 03:34:15 +0000538 "In test",
539 "Failed",
540 "Power off",
541 "Off line",
542 "<not used>",
543 "Dependency",
544 "Degraded",
545 "Not installed",
546};
547
Harald Welte4d87f242009-03-10 19:43:44 +0000548const char *nm_avail_name(u_int8_t avail)
Harald Weltee0590df2009-02-15 03:34:15 +0000549{
Harald Welte0b8348d2009-02-18 03:43:01 +0000550 if (avail == 0xff)
551 return "OK";
Harald Weltee0590df2009-02-15 03:34:15 +0000552 if (avail >= ARRAY_SIZE(avail_names))
553 return "UNKNOWN";
554 return avail_names[avail];
555}
Harald Welte7b26bcb2009-05-28 11:39:21 +0000556
557const char *nm_adm_name(u_int8_t adm)
558{
559 switch (adm) {
560 case 1:
561 return "Locked";
562 case 2:
563 return "Unlocked";
564 case 3:
565 return "Shutdown";
566 default:
567 return "<not used>";
568 }
569}
Harald Weltee0590df2009-02-15 03:34:15 +0000570
571/* obtain the gsm_nm_state data structure for a given object instance */
572static struct gsm_nm_state *
573objclass2nmstate(struct gsm_bts *bts, u_int8_t obj_class,
574 struct abis_om_obj_inst *obj_inst)
575{
576 struct gsm_bts_trx *trx;
577 struct gsm_nm_state *nm_state = NULL;
578
579 switch (obj_class) {
580 case NM_OC_BTS:
581 nm_state = &bts->nm_state;
582 break;
583 case NM_OC_RADIO_CARRIER:
584 if (obj_inst->trx_nr >= bts->num_trx)
585 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200586 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000587 nm_state = &trx->nm_state;
588 break;
589 case NM_OC_BASEB_TRANSC:
590 if (obj_inst->trx_nr >= bts->num_trx)
591 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200592 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000593 nm_state = &trx->bb_transc.nm_state;
594 break;
595 case NM_OC_CHANNEL:
596 if (obj_inst->trx_nr > bts->num_trx)
597 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200598 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000599 if (obj_inst->ts_nr >= TRX_NR_TS)
600 return NULL;
601 nm_state = &trx->ts[obj_inst->ts_nr].nm_state;
602 break;
603 case NM_OC_SITE_MANAGER:
604 nm_state = &bts->site_mgr.nm_state;
605 break;
Harald Welte7b26bcb2009-05-28 11:39:21 +0000606 case NM_OC_BS11:
607 switch (obj_inst->bts_nr) {
608 case BS11_OBJ_CCLK:
609 nm_state = &bts->bs11.cclk.nm_state;
610 break;
Harald Welte8b697c72009-06-05 19:18:45 +0000611 case BS11_OBJ_BBSIG:
612 if (obj_inst->ts_nr > bts->num_trx)
613 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200614 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Welte8b697c72009-06-05 19:18:45 +0000615 nm_state = &trx->bs11.bbsig.nm_state;
616 break;
617 case BS11_OBJ_PA:
618 if (obj_inst->ts_nr > bts->num_trx)
619 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200620 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Welte8b697c72009-06-05 19:18:45 +0000621 nm_state = &trx->bs11.pa.nm_state;
622 break;
Harald Welte7b26bcb2009-05-28 11:39:21 +0000623 default:
624 return NULL;
625 }
626 case NM_OC_BS11_RACK:
627 nm_state = &bts->bs11.rack.nm_state;
628 break;
Harald Welte8b697c72009-06-05 19:18:45 +0000629 case NM_OC_BS11_ENVABTSE:
630 if (obj_inst->trx_nr > ARRAY_SIZE(bts->bs11.envabtse))
631 return NULL;
632 nm_state = &bts->bs11.envabtse[obj_inst->trx_nr].nm_state;
633 break;
Harald Weltee0590df2009-02-15 03:34:15 +0000634 }
635 return nm_state;
636}
637
638/* obtain the in-memory data structure of a given object instance */
639static void *
640objclass2obj(struct gsm_bts *bts, u_int8_t obj_class,
641 struct abis_om_obj_inst *obj_inst)
642{
643 struct gsm_bts_trx *trx;
644 void *obj = NULL;
645
646 switch (obj_class) {
647 case NM_OC_BTS:
648 obj = bts;
649 break;
650 case NM_OC_RADIO_CARRIER:
651 if (obj_inst->trx_nr >= bts->num_trx)
652 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200653 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000654 obj = trx;
655 break;
656 case NM_OC_BASEB_TRANSC:
657 if (obj_inst->trx_nr >= bts->num_trx)
658 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200659 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000660 obj = &trx->bb_transc;
661 break;
662 case NM_OC_CHANNEL:
663 if (obj_inst->trx_nr > bts->num_trx)
664 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200665 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000666 if (obj_inst->ts_nr >= TRX_NR_TS)
667 return NULL;
668 obj = &trx->ts[obj_inst->ts_nr];
669 break;
670 case NM_OC_SITE_MANAGER:
671 obj = &bts->site_mgr;
672 break;
673 }
674 return obj;
675}
676
677/* Update the administrative state of a given object in our in-memory data
678 * structures and send an event to the higher layer */
679static int update_admstate(struct gsm_bts *bts, u_int8_t obj_class,
680 struct abis_om_obj_inst *obj_inst, u_int8_t adm_state)
681{
Harald Welteaeedeb42009-05-01 13:08:14 +0000682 struct gsm_nm_state *nm_state, new_state;
Harald Weltee0590df2009-02-15 03:34:15 +0000683 void *obj;
684 int rc;
685
Harald Weltee0590df2009-02-15 03:34:15 +0000686 obj = objclass2obj(bts, obj_class, obj_inst);
Harald Welteaeedeb42009-05-01 13:08:14 +0000687 nm_state = objclass2nmstate(bts, obj_class, obj_inst);
688 if (!nm_state)
689 return -1;
690
691 new_state = *nm_state;
692 new_state.administrative = adm_state;
693
694 rc = nm_state_event(EVT_STATECHG_ADM, obj_class, obj, nm_state, &new_state);
695
696 nm_state->administrative = adm_state;
Harald Weltee0590df2009-02-15 03:34:15 +0000697
698 return rc;
699}
700
Harald Welte97ed1e72009-02-06 13:38:02 +0000701static int abis_nm_rx_statechg_rep(struct msgb *mb)
702{
Harald Weltee0590df2009-02-15 03:34:15 +0000703 struct abis_om_hdr *oh = msgb_l2(mb);
Harald Welte97ed1e72009-02-06 13:38:02 +0000704 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Harald Welte22af0db2009-02-14 15:41:08 +0000705 struct gsm_bts *bts = mb->trx->bts;
Harald Weltee0590df2009-02-15 03:34:15 +0000706 struct tlv_parsed tp;
707 struct gsm_nm_state *nm_state, new_state;
708 int rc;
709
Harald Welte23897662009-05-01 14:52:51 +0000710 DEBUGPC(DNM, "STATE CHG: ");
Harald Weltee0590df2009-02-15 03:34:15 +0000711
Harald Welte8b697c72009-06-05 19:18:45 +0000712 memset(&new_state, 0, sizeof(new_state));
713
Harald Weltee0590df2009-02-15 03:34:15 +0000714 nm_state = objclass2nmstate(bts, foh->obj_class, &foh->obj_inst);
715 if (!nm_state) {
716 DEBUGPC(DNM, "\n");
717 return -EINVAL;
Harald Welte22af0db2009-02-14 15:41:08 +0000718 }
Harald Weltee0590df2009-02-15 03:34:15 +0000719
720 new_state = *nm_state;
721
Harald Welte03133942009-02-18 19:51:53 +0000722 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Weltee0590df2009-02-15 03:34:15 +0000723 if (TLVP_PRESENT(&tp, NM_ATT_OPER_STATE)) {
724 new_state.operational = *TLVP_VAL(&tp, NM_ATT_OPER_STATE);
Harald Welte4d87f242009-03-10 19:43:44 +0000725 DEBUGPC(DNM, "OP_STATE=%s ", nm_opstate_name(new_state.operational));
Harald Weltee0590df2009-02-15 03:34:15 +0000726 }
727 if (TLVP_PRESENT(&tp, NM_ATT_AVAIL_STATUS)) {
Harald Welte0b8348d2009-02-18 03:43:01 +0000728 if (TLVP_LEN(&tp, NM_ATT_AVAIL_STATUS) == 0)
729 new_state.availability = 0xff;
730 else
731 new_state.availability = *TLVP_VAL(&tp, NM_ATT_AVAIL_STATUS);
Harald Welte4d87f242009-03-10 19:43:44 +0000732 DEBUGPC(DNM, "AVAIL=%s(%02x) ", nm_avail_name(new_state.availability),
Harald Weltee0590df2009-02-15 03:34:15 +0000733 new_state.availability);
734 }
735 if (TLVP_PRESENT(&tp, NM_ATT_ADM_STATE)) {
736 new_state.administrative = *TLVP_VAL(&tp, NM_ATT_ADM_STATE);
Harald Welte5d4b1c22009-06-12 01:34:29 +0800737 DEBUGPC(DNM, "ADM=%02s ", nm_adm_name(new_state.administrative));
Harald Welte97ed1e72009-02-06 13:38:02 +0000738 }
739 DEBUGPC(DNM, "\n");
Harald Weltee0590df2009-02-15 03:34:15 +0000740
741 if (memcmp(&new_state, nm_state, sizeof(new_state))) {
742 /* Update the operational state of a given object in our in-memory data
743 * structures and send an event to the higher layer */
744 void *obj = objclass2obj(bts, foh->obj_class, &foh->obj_inst);
745 rc = nm_state_event(EVT_STATECHG_OPER, foh->obj_class, obj, nm_state, &new_state);
746 *nm_state = new_state;
747 }
748#if 0
Harald Welte22af0db2009-02-14 15:41:08 +0000749 if (op_state == 1) {
750 /* try to enable objects that are disabled */
751 abis_nm_opstart(bts, foh->obj_class,
752 foh->obj_inst.bts_nr,
753 foh->obj_inst.trx_nr,
754 foh->obj_inst.ts_nr);
755 }
Harald Weltee0590df2009-02-15 03:34:15 +0000756#endif
Harald Welte97ed1e72009-02-06 13:38:02 +0000757 return 0;
758}
759
Harald Welte0db97b22009-05-01 17:22:47 +0000760static int rx_fail_evt_rep(struct msgb *mb)
761{
762 struct abis_om_hdr *oh = msgb_l2(mb);
763 struct abis_om_fom_hdr *foh = msgb_l3(mb);
764 struct tlv_parsed tp;
765
766 DEBUGPC(DNM, "Failure Event Report ");
767
768 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
769
770 if (TLVP_PRESENT(&tp, NM_ATT_EVENT_TYPE))
771 DEBUGPC(DNM, "Type=%s ", event_type_name(*TLVP_VAL(&tp, NM_ATT_EVENT_TYPE)));
772 if (TLVP_PRESENT(&tp, NM_ATT_SEVERITY))
773 DEBUGPC(DNM, "Severity=%s ", severity_name(*TLVP_VAL(&tp, NM_ATT_SEVERITY)));
774
775 DEBUGPC(DNM, "\n");
776
777 return 0;
778}
779
Harald Welte97ed1e72009-02-06 13:38:02 +0000780static int abis_nm_rcvmsg_report(struct msgb *mb)
781{
782 struct abis_om_fom_hdr *foh = msgb_l3(mb);
783 u_int8_t mt = foh->msg_type;
784
Harald Welte23897662009-05-01 14:52:51 +0000785 DEBUGP(DNM, "OC=%s(%02x) INST=(%02x,%02x,%02x) ",
786 obj_class_name(foh->obj_class), foh->obj_class,
787 foh->obj_inst.bts_nr, foh->obj_inst.trx_nr,
788 foh->obj_inst.ts_nr);
789
Harald Welte97ed1e72009-02-06 13:38:02 +0000790 //nmh->cfg->report_cb(mb, foh);
791
792 switch (mt) {
793 case NM_MT_STATECHG_EVENT_REP:
794 return abis_nm_rx_statechg_rep(mb);
795 break;
Harald Welte34a99682009-02-13 02:41:40 +0000796 case NM_MT_SW_ACTIVATED_REP:
Harald Welte23897662009-05-01 14:52:51 +0000797 DEBUGPC(DNM, "Software Activated Report\n");
Harald Weltef9a8cc32009-05-01 15:39:49 +0000798 dispatch_signal(SS_NM, S_NM_SW_ACTIV_REP, mb);
Harald Welte34a99682009-02-13 02:41:40 +0000799 break;
Harald Weltee0590df2009-02-15 03:34:15 +0000800 case NM_MT_FAILURE_EVENT_REP:
Harald Welte0db97b22009-05-01 17:22:47 +0000801 rx_fail_evt_rep(mb);
Harald Weltef9a8cc32009-05-01 15:39:49 +0000802 dispatch_signal(SS_NM, S_NM_FAIL_REP, mb);
Harald Weltee0590df2009-02-15 03:34:15 +0000803 break;
804 default:
Harald Welte23897662009-05-01 14:52:51 +0000805 DEBUGPC(DNM, "reporting NM MT 0x%02x\n", mt);
Harald Weltee0590df2009-02-15 03:34:15 +0000806 break;
807
Harald Welte97ed1e72009-02-06 13:38:02 +0000808 };
809
Harald Welte97ed1e72009-02-06 13:38:02 +0000810 return 0;
811}
812
Harald Welte34a99682009-02-13 02:41:40 +0000813/* Activate the specified software into the BTS */
814static int ipacc_sw_activate(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1,
815 u_int8_t i2, u_int8_t *sw_desc, u_int8_t swdesc_len)
816{
817 struct abis_om_hdr *oh;
818 struct msgb *msg = nm_msgb_alloc();
819 u_int8_t len = swdesc_len;
820 u_int8_t *trailer;
821
822 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
823 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, obj_class, i0, i1, i2);
824
825 trailer = msgb_put(msg, swdesc_len);
826 memcpy(trailer, sw_desc, swdesc_len);
827
828 return abis_nm_sendmsg(bts, msg);
829}
830
831static int abis_nm_rx_sw_act_req(struct msgb *mb)
832{
833 struct abis_om_hdr *oh = msgb_l2(mb);
834 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Harald Welte5c1e4582009-02-15 11:57:29 +0000835 int nack = 0;
Harald Welte34a99682009-02-13 02:41:40 +0000836 int ret;
837
Harald Welte5c1e4582009-02-15 11:57:29 +0000838 DEBUGP(DNM, "Software Activate Request ");
Harald Welte34a99682009-02-13 02:41:40 +0000839
Harald Welte5c1e4582009-02-15 11:57:29 +0000840 if (foh->obj_class >= 0xf0 && foh->obj_class <= 0xf3) {
841 DEBUGPC(DNM, "NACKing for GPRS obj_class 0x%02x\n", foh->obj_class);
842 nack = 1;
843 } else
844 DEBUGPC(DNM, "ACKing and Activating\n");
845
846 ret = abis_nm_sw_act_req_ack(mb->trx->bts, foh->obj_class,
Harald Welte34a99682009-02-13 02:41:40 +0000847 foh->obj_inst.bts_nr,
848 foh->obj_inst.trx_nr,
Harald Welte5c1e4582009-02-15 11:57:29 +0000849 foh->obj_inst.ts_nr, nack,
Harald Welte34a99682009-02-13 02:41:40 +0000850 foh->data, oh->length-sizeof(*foh));
851
Harald Welte5c1e4582009-02-15 11:57:29 +0000852 if (nack)
853 return ret;
854
Harald Welte34a99682009-02-13 02:41:40 +0000855 /* FIXME: properly parse attributes */
856 return ipacc_sw_activate(mb->trx->bts, foh->obj_class,
857 foh->obj_inst.bts_nr,
858 foh->obj_inst.trx_nr,
859 foh->obj_inst.ts_nr,
860 foh->data + oh->length-sizeof(*foh)-22, 22);
861}
862
Harald Weltee0590df2009-02-15 03:34:15 +0000863/* Receive a CHANGE_ADM_STATE_ACK, parse the TLV and update local state */
864static int abis_nm_rx_chg_adm_state_ack(struct msgb *mb)
865{
866 struct abis_om_hdr *oh = msgb_l2(mb);
867 struct abis_om_fom_hdr *foh = msgb_l3(mb);
868 struct tlv_parsed tp;
869 u_int8_t adm_state;
870
Harald Welte03133942009-02-18 19:51:53 +0000871 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Weltee0590df2009-02-15 03:34:15 +0000872 if (!TLVP_PRESENT(&tp, NM_ATT_ADM_STATE))
873 return -EINVAL;
874
875 adm_state = *TLVP_VAL(&tp, NM_ATT_ADM_STATE);
876
877 return update_admstate(mb->trx->bts, foh->obj_class, &foh->obj_inst, adm_state);
878}
879
Harald Welteee670472009-02-22 21:58:49 +0000880static int abis_nm_rx_lmt_event(struct msgb *mb)
881{
882 struct abis_om_hdr *oh = msgb_l2(mb);
883 struct abis_om_fom_hdr *foh = msgb_l3(mb);
884 struct tlv_parsed tp;
885
886 DEBUGP(DNM, "LMT Event ");
887 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
888 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_LOGON_SESSION) &&
889 TLVP_LEN(&tp, NM_ATT_BS11_LMT_LOGON_SESSION) >= 1) {
890 u_int8_t onoff = *TLVP_VAL(&tp, NM_ATT_BS11_LMT_LOGON_SESSION);
891 DEBUGPC(DNM, "LOG%s ", onoff ? "ON" : "OFF");
892 }
893 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV) &&
894 TLVP_LEN(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV) >= 1) {
895 u_int8_t level = *TLVP_VAL(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV);
896 DEBUGPC(DNM, "Level=%u ", level);
897 }
898 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_USER_NAME) &&
899 TLVP_LEN(&tp, NM_ATT_BS11_LMT_USER_NAME) >= 1) {
900 char *name = (char *) TLVP_VAL(&tp, NM_ATT_BS11_LMT_USER_NAME);
901 DEBUGPC(DNM, "Username=%s ", name);
902 }
903 DEBUGPC(DNM, "\n");
904 /* FIXME: parse LMT LOGON TIME */
905 return 0;
906}
907
Harald Welte52b1f982008-12-23 20:25:15 +0000908/* Receive a OML NM Message from BTS */
Harald Welte8470bf22008-12-25 23:28:35 +0000909static int abis_nm_rcvmsg_fom(struct msgb *mb)
Harald Welte52b1f982008-12-23 20:25:15 +0000910{
Harald Welte6c96ba52009-05-01 13:03:40 +0000911 struct abis_om_hdr *oh = msgb_l2(mb);
Harald Welte52b1f982008-12-23 20:25:15 +0000912 struct abis_om_fom_hdr *foh = msgb_l3(mb);
913 u_int8_t mt = foh->msg_type;
914
915 /* check for unsolicited message */
Harald Welte97ed1e72009-02-06 13:38:02 +0000916 if (is_report(mt))
917 return abis_nm_rcvmsg_report(mb);
Harald Welte52b1f982008-12-23 20:25:15 +0000918
Harald Welte4724f992009-01-18 18:01:49 +0000919 if (is_in_arr(mt, sw_load_msgs, ARRAY_SIZE(sw_load_msgs)))
920 return abis_nm_rcvmsg_sw(mb);
921
Harald Welte78fc0d42009-02-19 02:50:57 +0000922 if (is_in_arr(mt, nacks, ARRAY_SIZE(nacks))) {
Harald Welte6c96ba52009-05-01 13:03:40 +0000923 struct tlv_parsed tp;
Harald Welte78fc0d42009-02-19 02:50:57 +0000924 if (nack_names[mt])
Harald Welte6c96ba52009-05-01 13:03:40 +0000925 DEBUGP(DNM, "%s NACK ", nack_names[mt]);
926 /* FIXME: NACK cause */
Harald Welte78fc0d42009-02-19 02:50:57 +0000927 else
Harald Welte6c96ba52009-05-01 13:03:40 +0000928 DEBUGP(DNM, "NACK 0x%02x ", mt);
929
930 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
931 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
932 DEBUGPC(DNM, "CAUSE=%s\n",
933 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
934 else
935 DEBUGPC(DNM, "\n");
Holger Hans Peter Freyther500f3ca2009-06-10 10:48:14 +0200936
937 dispatch_signal(SS_NM, S_NM_NACK, (void*) ((long)mt));
938 return 0;
Harald Welte78fc0d42009-02-19 02:50:57 +0000939 }
Harald Weltead384642008-12-26 10:20:07 +0000940#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000941 /* check if last message is to be acked */
942 if (is_ack_nack(nmh->last_msgtype)) {
943 if (mt == MT_ACK(nmh->last_msgtype)) {
944 fprintf(stderr, "received ACK (0x%x)\n",
945 foh->msg_type);
946 /* we got our ACK, continue sending the next msg */
947 } else if (mt == MT_NACK(nmh->last_msgtype)) {
948 /* we got a NACK, signal this to the caller */
949 fprintf(stderr, "received NACK (0x%x)\n",
950 foh->msg_type);
951 /* FIXME: somehow signal this to the caller */
952 } else {
953 /* really strange things happen */
954 return -EINVAL;
955 }
956 }
Harald Weltead384642008-12-26 10:20:07 +0000957#endif
958
Harald Welte97ed1e72009-02-06 13:38:02 +0000959 switch (mt) {
Harald Weltee0590df2009-02-15 03:34:15 +0000960 case NM_MT_CHG_ADM_STATE_ACK:
961 return abis_nm_rx_chg_adm_state_ack(mb);
962 break;
Harald Welte34a99682009-02-13 02:41:40 +0000963 case NM_MT_SW_ACT_REQ:
964 return abis_nm_rx_sw_act_req(mb);
965 break;
Harald Welte97ed1e72009-02-06 13:38:02 +0000966 case NM_MT_BS11_LMT_SESSION:
Harald Welteee670472009-02-22 21:58:49 +0000967 return abis_nm_rx_lmt_event(mb);
Harald Welte97ed1e72009-02-06 13:38:02 +0000968 break;
Harald Welte1989c082009-08-06 17:58:31 +0200969 case NM_MT_CONN_MDROP_LINK_ACK:
970 DEBUGP(DNM, "CONN MDROP LINK ACK\n");
971 break;
Harald Welte97ed1e72009-02-06 13:38:02 +0000972 }
973
Harald Weltead384642008-12-26 10:20:07 +0000974 return 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000975}
976
Harald Welte677c21f2009-02-17 13:22:23 +0000977static int abis_nm_rx_ipacc(struct msgb *mb);
978
979static int abis_nm_rcvmsg_manuf(struct msgb *mb)
980{
981 int rc;
982 int bts_type = mb->trx->bts->type;
983
984 switch (bts_type) {
985 case GSM_BTS_TYPE_NANOBTS_900:
986 case GSM_BTS_TYPE_NANOBTS_1800:
987 rc = abis_nm_rx_ipacc(mb);
988 break;
989 default:
990 fprintf(stderr, "don't know how to parse OML for this "
991 "BTS type (%u)\n", bts_type);
992 rc = 0;
993 break;
994 }
995
996 return rc;
997}
998
Harald Welte52b1f982008-12-23 20:25:15 +0000999/* High-Level API */
1000/* Entry-point where L2 OML from BTS enters the NM code */
Harald Welte8470bf22008-12-25 23:28:35 +00001001int abis_nm_rcvmsg(struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +00001002{
Harald Welte52b1f982008-12-23 20:25:15 +00001003 struct abis_om_hdr *oh = msgb_l2(msg);
Harald Welte677c21f2009-02-17 13:22:23 +00001004 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +00001005
1006 /* Various consistency checks */
1007 if (oh->placement != ABIS_OM_PLACEMENT_ONLY) {
1008 fprintf(stderr, "ABIS OML placement 0x%x not supported\n",
1009 oh->placement);
1010 return -EINVAL;
1011 }
1012 if (oh->sequence != 0) {
1013 fprintf(stderr, "ABIS OML sequence 0x%x != 0x00\n",
1014 oh->sequence);
1015 return -EINVAL;
1016 }
Harald Welte702d8702008-12-26 20:25:35 +00001017#if 0
Holger Freytherca362a62009-01-04 21:05:01 +00001018 unsigned int l2_len = msg->tail - (u_int8_t *)msgb_l2(msg);
1019 unsigned int hlen = sizeof(*oh) + sizeof(struct abis_om_fom_hdr);
Harald Welte702d8702008-12-26 20:25:35 +00001020 if (oh->length + hlen > l2_len) {
Harald Welte52b1f982008-12-23 20:25:15 +00001021 fprintf(stderr, "ABIS OML truncated message (%u > %u)\n",
1022 oh->length + sizeof(*oh), l2_len);
1023 return -EINVAL;
1024 }
Harald Welte702d8702008-12-26 20:25:35 +00001025 if (oh->length + hlen < l2_len)
1026 fprintf(stderr, "ABIS OML message with extra trailer?!? (oh->len=%d, sizeof_oh=%d l2_len=%d\n", oh->length, sizeof(*oh), l2_len);
1027#endif
Harald Weltead384642008-12-26 10:20:07 +00001028 msg->l3h = (unsigned char *)oh + sizeof(*oh);
Harald Welte52b1f982008-12-23 20:25:15 +00001029
1030 switch (oh->mdisc) {
1031 case ABIS_OM_MDISC_FOM:
Harald Welte8470bf22008-12-25 23:28:35 +00001032 rc = abis_nm_rcvmsg_fom(msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001033 break;
Harald Welte677c21f2009-02-17 13:22:23 +00001034 case ABIS_OM_MDISC_MANUF:
1035 rc = abis_nm_rcvmsg_manuf(msg);
1036 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001037 case ABIS_OM_MDISC_MMI:
1038 case ABIS_OM_MDISC_TRAU:
Harald Welte677c21f2009-02-17 13:22:23 +00001039 fprintf(stderr, "unimplemented ABIS OML message discriminator 0x%x\n",
1040 oh->mdisc);
1041 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001042 default:
1043 fprintf(stderr, "unknown ABIS OML message discriminator 0x%x\n",
1044 oh->mdisc);
1045 return -EINVAL;
1046 }
1047
Harald Weltead384642008-12-26 10:20:07 +00001048 msgb_free(msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001049 return rc;
1050}
1051
1052#if 0
1053/* initialized all resources */
1054struct abis_nm_h *abis_nm_init(struct abis_nm_cfg *cfg)
1055{
1056 struct abis_nm_h *nmh;
1057
1058 nmh = malloc(sizeof(*nmh));
1059 if (!nmh)
1060 return NULL;
1061
1062 nmh->cfg = cfg;
1063
1064 return nmh;
1065}
1066
1067/* free all resources */
1068void abis_nm_fini(struct abis_nm_h *nmh)
1069{
1070 free(nmh);
1071}
1072#endif
1073
1074/* Here we are trying to define a high-level API that can be used by
1075 * the actual BSC implementation. However, the architecture is currently
1076 * still under design. Ideally the calls to this API would be synchronous,
1077 * while the underlying stack behind the APi runs in a traditional select
1078 * based state machine.
1079 */
1080
Harald Welte4724f992009-01-18 18:01:49 +00001081/* 6.2 Software Load: */
1082enum sw_state {
1083 SW_STATE_NONE,
1084 SW_STATE_WAIT_INITACK,
1085 SW_STATE_WAIT_SEGACK,
1086 SW_STATE_WAIT_ENDACK,
1087 SW_STATE_WAIT_ACTACK,
1088 SW_STATE_ERROR,
1089};
Harald Welte52b1f982008-12-23 20:25:15 +00001090
Harald Welte52b1f982008-12-23 20:25:15 +00001091struct abis_nm_sw {
Harald Welte4724f992009-01-18 18:01:49 +00001092 struct gsm_bts *bts;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001093 gsm_cbfn *cbfn;
1094 void *cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +00001095 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001096
Harald Welte52b1f982008-12-23 20:25:15 +00001097 /* this will become part of the SW LOAD INITIATE */
1098 u_int8_t obj_class;
1099 u_int8_t obj_instance[3];
Harald Welte4724f992009-01-18 18:01:49 +00001100
1101 u_int8_t file_id[255];
1102 u_int8_t file_id_len;
1103
1104 u_int8_t file_version[255];
1105 u_int8_t file_version_len;
1106
1107 u_int8_t window_size;
1108 u_int8_t seg_in_window;
1109
1110 int fd;
1111 FILE *stream;
1112 enum sw_state state;
Harald Welte1602ade2009-01-29 21:12:39 +00001113 int last_seg;
Harald Welte52b1f982008-12-23 20:25:15 +00001114};
1115
Harald Welte4724f992009-01-18 18:01:49 +00001116static struct abis_nm_sw g_sw;
1117
1118/* 6.2.1 / 8.3.1: Load Data Initiate */
1119static int sw_load_init(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +00001120{
Harald Welte4724f992009-01-18 18:01:49 +00001121 struct abis_om_hdr *oh;
1122 struct msgb *msg = nm_msgb_alloc();
1123 u_int8_t len = 3*2 + sw->file_id_len + sw->file_version_len;
1124
1125 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1126 fill_om_fom_hdr(oh, len, NM_MT_LOAD_INIT, sw->obj_class,
1127 sw->obj_instance[0], sw->obj_instance[1],
1128 sw->obj_instance[2]);
1129
1130 /* FIXME: this is BS11 specific format */
1131 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1132 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1133 sw->file_version);
1134 msgb_tv_put(msg, NM_ATT_WINDOW_SIZE, sw->window_size);
1135
1136 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001137}
1138
Harald Welte1602ade2009-01-29 21:12:39 +00001139static int is_last_line(FILE *stream)
1140{
1141 char next_seg_buf[256];
1142 long pos;
1143
1144 /* check if we're sending the last line */
1145 pos = ftell(stream);
1146 if (!fgets(next_seg_buf, sizeof(next_seg_buf)-2, stream)) {
1147 fseek(stream, pos, SEEK_SET);
1148 return 1;
1149 }
1150
1151 fseek(stream, pos, SEEK_SET);
1152 return 0;
1153}
1154
Harald Welte4724f992009-01-18 18:01:49 +00001155/* 6.2.2 / 8.3.2 Load Data Segment */
1156static int sw_load_segment(struct abis_nm_sw *sw)
1157{
1158 struct abis_om_hdr *oh;
1159 struct msgb *msg = nm_msgb_alloc();
1160 char seg_buf[256];
1161 char *line_buf = seg_buf+2;
Harald Welte3b8ba212009-01-29 12:27:58 +00001162 unsigned char *tlv;
Harald Welte4724f992009-01-18 18:01:49 +00001163 u_int8_t len;
Harald Welte4724f992009-01-18 18:01:49 +00001164
1165 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte3b8ba212009-01-29 12:27:58 +00001166
1167 switch (sw->bts->type) {
1168 case GSM_BTS_TYPE_BS11:
1169 if (fgets(line_buf, sizeof(seg_buf)-2, sw->stream) == NULL) {
1170 perror("fgets reading segment");
1171 return -EINVAL;
1172 }
1173 seg_buf[0] = 0x00;
Harald Welte1602ade2009-01-29 21:12:39 +00001174
1175 /* check if we're sending the last line */
1176 sw->last_seg = is_last_line(sw->stream);
1177 if (sw->last_seg)
1178 seg_buf[1] = 0;
1179 else
1180 seg_buf[1] = 1 + sw->seg_in_window++;
Harald Welte3b8ba212009-01-29 12:27:58 +00001181
1182 len = strlen(line_buf) + 2;
1183 tlv = msgb_put(msg, TLV_GROSS_LEN(len));
1184 tlv_put(tlv, NM_ATT_BS11_FILE_DATA, len, (u_int8_t *)seg_buf);
1185 /* BS11 wants CR + LF in excess of the TLV length !?! */
1186 tlv[1] -= 2;
1187
1188 /* we only now know the exact length for the OM hdr */
1189 len = strlen(line_buf)+2;
1190 break;
1191 default:
1192 /* FIXME: Other BTS types */
1193 return -1;
Harald Welte4724f992009-01-18 18:01:49 +00001194 }
Harald Welte4724f992009-01-18 18:01:49 +00001195
Harald Welte4724f992009-01-18 18:01:49 +00001196 fill_om_fom_hdr(oh, len, NM_MT_LOAD_SEG, sw->obj_class,
1197 sw->obj_instance[0], sw->obj_instance[1],
1198 sw->obj_instance[2]);
1199
1200 return abis_nm_sendmsg(sw->bts, msg);
1201}
1202
1203/* 6.2.4 / 8.3.4 Load Data End */
1204static int sw_load_end(struct abis_nm_sw *sw)
1205{
1206 struct abis_om_hdr *oh;
1207 struct msgb *msg = nm_msgb_alloc();
1208 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
1209
1210 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1211 fill_om_fom_hdr(oh, len, NM_MT_LOAD_END, sw->obj_class,
1212 sw->obj_instance[0], sw->obj_instance[1],
1213 sw->obj_instance[2]);
1214
1215 /* FIXME: this is BS11 specific format */
1216 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1217 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1218 sw->file_version);
1219
1220 return abis_nm_sendmsg(sw->bts, msg);
1221}
Harald Welte5e4d1b32009-02-01 13:36:56 +00001222
Harald Welte52b1f982008-12-23 20:25:15 +00001223/* Activate the specified software into the BTS */
Harald Welte4724f992009-01-18 18:01:49 +00001224static int sw_activate(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +00001225{
Harald Welte4724f992009-01-18 18:01:49 +00001226 struct abis_om_hdr *oh;
1227 struct msgb *msg = nm_msgb_alloc();
1228 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
Harald Welte52b1f982008-12-23 20:25:15 +00001229
Harald Welte4724f992009-01-18 18:01:49 +00001230 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1231 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, sw->obj_class,
1232 sw->obj_instance[0], sw->obj_instance[1],
1233 sw->obj_instance[2]);
1234
1235 /* FIXME: this is BS11 specific format */
1236 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1237 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1238 sw->file_version);
1239
1240 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001241}
Harald Welte4724f992009-01-18 18:01:49 +00001242
1243static int sw_open_file(struct abis_nm_sw *sw, const char *fname)
1244{
1245 char file_id[12+1];
1246 char file_version[80+1];
1247 int rc;
1248
1249 sw->fd = open(fname, O_RDONLY);
1250 if (sw->fd < 0)
1251 return sw->fd;
1252
1253 switch (sw->bts->type) {
1254 case GSM_BTS_TYPE_BS11:
1255 sw->stream = fdopen(sw->fd, "r");
1256 if (!sw->stream) {
1257 perror("fdopen");
1258 return -1;
1259 }
1260 /* read first line and parse file ID and VERSION */
Harald Welte3b8ba212009-01-29 12:27:58 +00001261 rc = fscanf(sw->stream, "@(#)%12s:%80s\r\n",
Harald Welte4724f992009-01-18 18:01:49 +00001262 file_id, file_version);
1263 if (rc != 2) {
1264 perror("parsing header line of software file");
1265 return -1;
1266 }
1267 strcpy((char *)sw->file_id, file_id);
1268 sw->file_id_len = strlen(file_id);
1269 strcpy((char *)sw->file_version, file_version);
1270 sw->file_version_len = strlen(file_version);
1271 /* rewind to start of file */
Harald Welte3b8ba212009-01-29 12:27:58 +00001272 rewind(sw->stream);
Harald Welte4724f992009-01-18 18:01:49 +00001273 break;
1274 default:
1275 /* We don't know how to treat them yet */
1276 close(sw->fd);
1277 return -EINVAL;
1278 }
1279
1280 return 0;
1281}
1282
1283static void sw_close_file(struct abis_nm_sw *sw)
1284{
1285 switch (sw->bts->type) {
1286 case GSM_BTS_TYPE_BS11:
1287 fclose(sw->stream);
1288 break;
1289 default:
1290 close(sw->fd);
1291 break;
1292 }
1293}
1294
1295/* Fill the window */
1296static int sw_fill_window(struct abis_nm_sw *sw)
1297{
1298 int rc;
1299
1300 while (sw->seg_in_window < sw->window_size) {
1301 rc = sw_load_segment(sw);
1302 if (rc < 0)
1303 return rc;
Harald Welte1602ade2009-01-29 21:12:39 +00001304 if (sw->last_seg)
1305 break;
Harald Welte4724f992009-01-18 18:01:49 +00001306 }
1307 return 0;
1308}
1309
1310/* callback function from abis_nm_rcvmsg() handler */
1311static int abis_nm_rcvmsg_sw(struct msgb *mb)
1312{
1313 struct abis_om_fom_hdr *foh = msgb_l3(mb);
1314 int rc = -1;
1315 struct abis_nm_sw *sw = &g_sw;
1316 enum sw_state old_state = sw->state;
1317
Harald Welte3ffd1372009-02-01 22:15:49 +00001318 //DEBUGP(DNM, "state %u, NM MT 0x%02x\n", sw->state, foh->msg_type);
Harald Welte4724f992009-01-18 18:01:49 +00001319
1320 switch (sw->state) {
1321 case SW_STATE_WAIT_INITACK:
1322 switch (foh->msg_type) {
1323 case NM_MT_LOAD_INIT_ACK:
1324 /* fill window with segments */
Harald Welte5e4d1b32009-02-01 13:36:56 +00001325 if (sw->cbfn)
1326 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1327 NM_MT_LOAD_INIT_ACK, mb,
1328 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001329 rc = sw_fill_window(sw);
1330 sw->state = SW_STATE_WAIT_SEGACK;
1331 break;
1332 case NM_MT_LOAD_INIT_NACK:
Harald Welte3ffd1372009-02-01 22:15:49 +00001333 if (sw->forced) {
1334 DEBUGP(DNM, "FORCED: Ignoring Software Load "
1335 "Init NACK\n");
1336 if (sw->cbfn)
1337 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1338 NM_MT_LOAD_INIT_ACK, mb,
1339 sw->cb_data, NULL);
1340 rc = sw_fill_window(sw);
1341 sw->state = SW_STATE_WAIT_SEGACK;
1342 } else {
1343 DEBUGP(DNM, "Software Load Init NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001344 /* FIXME: cause */
Harald Welte3ffd1372009-02-01 22:15:49 +00001345 if (sw->cbfn)
1346 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1347 NM_MT_LOAD_INIT_NACK, mb,
1348 sw->cb_data, NULL);
1349 sw->state = SW_STATE_ERROR;
1350 }
Harald Welte4724f992009-01-18 18:01:49 +00001351 break;
1352 }
1353 break;
1354 case SW_STATE_WAIT_SEGACK:
1355 switch (foh->msg_type) {
1356 case NM_MT_LOAD_SEG_ACK:
Harald Welte3ffd1372009-02-01 22:15:49 +00001357 if (sw->cbfn)
1358 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1359 NM_MT_LOAD_SEG_ACK, mb,
1360 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001361 sw->seg_in_window = 0;
Harald Welte1602ade2009-01-29 21:12:39 +00001362 if (!sw->last_seg) {
1363 /* fill window with more segments */
1364 rc = sw_fill_window(sw);
1365 sw->state = SW_STATE_WAIT_SEGACK;
1366 } else {
1367 /* end the transfer */
1368 sw->state = SW_STATE_WAIT_ENDACK;
1369 rc = sw_load_end(sw);
1370 }
Harald Welte4724f992009-01-18 18:01:49 +00001371 break;
1372 }
1373 break;
1374 case SW_STATE_WAIT_ENDACK:
1375 switch (foh->msg_type) {
1376 case NM_MT_LOAD_END_ACK:
1377 sw_close_file(sw);
Harald Welte5e4d1b32009-02-01 13:36:56 +00001378 DEBUGP(DNM, "Software Load End (BTS %u)\n",
1379 sw->bts->nr);
1380 sw->state = SW_STATE_NONE;
1381 if (sw->cbfn)
1382 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1383 NM_MT_LOAD_END_ACK, mb,
1384 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001385 break;
1386 case NM_MT_LOAD_END_NACK:
Holger Freyther31338a12009-02-06 17:43:50 +00001387 if (sw->forced) {
1388 DEBUGP(DNM, "FORCED: Ignoring Software Load"
1389 "End NACK\n");
1390 sw->state = SW_STATE_NONE;
1391 if (sw->cbfn)
1392 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1393 NM_MT_LOAD_END_ACK, mb,
1394 sw->cb_data, NULL);
1395 } else {
1396 DEBUGP(DNM, "Software Load End NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001397 /* FIXME: cause */
Holger Freyther31338a12009-02-06 17:43:50 +00001398 sw->state = SW_STATE_ERROR;
1399 if (sw->cbfn)
1400 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1401 NM_MT_LOAD_END_NACK, mb,
1402 sw->cb_data, NULL);
1403 }
Harald Welte4724f992009-01-18 18:01:49 +00001404 break;
1405 }
1406 case SW_STATE_WAIT_ACTACK:
1407 switch (foh->msg_type) {
1408 case NM_MT_ACTIVATE_SW_ACK:
1409 /* we're done */
Harald Welte5e4d1b32009-02-01 13:36:56 +00001410 DEBUGP(DNM, "Activate Software DONE!\n");
Harald Welte4724f992009-01-18 18:01:49 +00001411 sw->state = SW_STATE_NONE;
1412 rc = 0;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001413 if (sw->cbfn)
1414 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1415 NM_MT_ACTIVATE_SW_ACK, mb,
1416 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001417 break;
1418 case NM_MT_ACTIVATE_SW_NACK:
Harald Welte1602ade2009-01-29 21:12:39 +00001419 DEBUGP(DNM, "Activate Software NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001420 /* FIXME: cause */
Harald Welte4724f992009-01-18 18:01:49 +00001421 sw->state = SW_STATE_ERROR;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001422 if (sw->cbfn)
1423 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1424 NM_MT_ACTIVATE_SW_NACK, mb,
1425 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001426 break;
1427 }
1428 case SW_STATE_NONE:
Harald Weltea994a482009-05-01 15:54:23 +00001429 switch (foh->msg_type) {
1430 case NM_MT_ACTIVATE_SW_ACK:
1431 rc = 0;
1432 break;
1433 }
1434 break;
Harald Welte4724f992009-01-18 18:01:49 +00001435 case SW_STATE_ERROR:
1436 break;
1437 }
1438
1439 if (rc)
Harald Weltea994a482009-05-01 15:54:23 +00001440 DEBUGP(DNM, "unexpected NM MT 0x%02x in state %u -> %u\n",
Harald Welte4724f992009-01-18 18:01:49 +00001441 foh->msg_type, old_state, sw->state);
1442
1443 return rc;
1444}
1445
1446/* Load the specified software into the BTS */
1447int abis_nm_software_load(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00001448 u_int8_t win_size, int forced,
1449 gsm_cbfn *cbfn, void *cb_data)
Harald Welte4724f992009-01-18 18:01:49 +00001450{
1451 struct abis_nm_sw *sw = &g_sw;
1452 int rc;
1453
Harald Welte5e4d1b32009-02-01 13:36:56 +00001454 DEBUGP(DNM, "Software Load (BTS %u, File \"%s\")\n",
1455 bts->nr, fname);
1456
Harald Welte4724f992009-01-18 18:01:49 +00001457 if (sw->state != SW_STATE_NONE)
1458 return -EBUSY;
1459
1460 sw->bts = bts;
1461 sw->obj_class = NM_OC_SITE_MANAGER;
1462 sw->obj_instance[0] = 0xff;
1463 sw->obj_instance[1] = 0xff;
1464 sw->obj_instance[2] = 0xff;
1465 sw->window_size = win_size;
1466 sw->state = SW_STATE_WAIT_INITACK;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001467 sw->cbfn = cbfn;
1468 sw->cb_data = cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +00001469 sw->forced = forced;
Harald Welte4724f992009-01-18 18:01:49 +00001470
1471 rc = sw_open_file(sw, fname);
1472 if (rc < 0) {
1473 sw->state = SW_STATE_NONE;
1474 return rc;
1475 }
1476
1477 return sw_load_init(sw);
1478}
Harald Welte52b1f982008-12-23 20:25:15 +00001479
Harald Welte1602ade2009-01-29 21:12:39 +00001480int abis_nm_software_load_status(struct gsm_bts *bts)
1481{
1482 struct abis_nm_sw *sw = &g_sw;
1483 struct stat st;
1484 int rc, percent;
1485
1486 rc = fstat(sw->fd, &st);
1487 if (rc < 0) {
1488 perror("ERROR during stat");
1489 return rc;
1490 }
1491
1492 percent = (ftell(sw->stream) * 100) / st.st_size;
1493 return percent;
1494}
1495
Harald Welte5e4d1b32009-02-01 13:36:56 +00001496/* Activate the specified software into the BTS */
1497int abis_nm_software_activate(struct gsm_bts *bts, const char *fname,
1498 gsm_cbfn *cbfn, void *cb_data)
1499{
1500 struct abis_nm_sw *sw = &g_sw;
1501 int rc;
1502
1503 DEBUGP(DNM, "Activating Software (BTS %u, File \"%s\")\n",
1504 bts->nr, fname);
1505
1506 if (sw->state != SW_STATE_NONE)
1507 return -EBUSY;
1508
1509 sw->bts = bts;
1510 sw->obj_class = NM_OC_SITE_MANAGER;
1511 sw->obj_instance[0] = 0xff;
1512 sw->obj_instance[1] = 0xff;
1513 sw->obj_instance[2] = 0xff;
1514 sw->state = SW_STATE_WAIT_ACTACK;
1515 sw->cbfn = cbfn;
1516 sw->cb_data = cb_data;
1517
1518 /* Open the file in order to fill some sw struct members */
1519 rc = sw_open_file(sw, fname);
1520 if (rc < 0) {
1521 sw->state = SW_STATE_NONE;
1522 return rc;
1523 }
1524 sw_close_file(sw);
1525
1526 return sw_activate(sw);
1527}
1528
Harald Welte8470bf22008-12-25 23:28:35 +00001529static void fill_nm_channel(struct abis_nm_channel *ch, u_int8_t bts_port,
Harald Welte52b1f982008-12-23 20:25:15 +00001530 u_int8_t ts_nr, u_int8_t subslot_nr)
1531{
Harald Welteadaf08b2009-01-18 11:08:10 +00001532 ch->attrib = NM_ATT_ABIS_CHANNEL;
Harald Welte52b1f982008-12-23 20:25:15 +00001533 ch->bts_port = bts_port;
1534 ch->timeslot = ts_nr;
1535 ch->subslot = subslot_nr;
1536}
1537
1538int abis_nm_establish_tei(struct gsm_bts *bts, u_int8_t trx_nr,
1539 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot,
1540 u_int8_t tei)
1541{
1542 struct abis_om_hdr *oh;
1543 struct abis_nm_channel *ch;
Harald Welte702d8702008-12-26 20:25:35 +00001544 u_int8_t len = sizeof(*ch) + 2;
Harald Welte8470bf22008-12-25 23:28:35 +00001545 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001546
1547 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1548 fill_om_fom_hdr(oh, len, NM_MT_ESTABLISH_TEI, NM_OC_RADIO_CARRIER,
1549 bts->bts_nr, trx_nr, 0xff);
1550
Harald Welte8470bf22008-12-25 23:28:35 +00001551 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte52b1f982008-12-23 20:25:15 +00001552
1553 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1554 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1555
1556 return abis_nm_sendmsg(bts, msg);
1557}
1558
1559/* connect signalling of one (BTS,TRX) to a particular timeslot on the E1 */
1560int abis_nm_conn_terr_sign(struct gsm_bts_trx *trx,
1561 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot)
1562{
Harald Welte8470bf22008-12-25 23:28:35 +00001563 struct gsm_bts *bts = trx->bts;
Harald Welte52b1f982008-12-23 20:25:15 +00001564 struct abis_om_hdr *oh;
1565 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +00001566 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001567
1568 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001569 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_SIGN,
Harald Welte52b1f982008-12-23 20:25:15 +00001570 NM_OC_RADIO_CARRIER, bts->bts_nr, trx->nr, 0xff);
1571
1572 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1573 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1574
1575 return abis_nm_sendmsg(bts, msg);
1576}
1577
1578#if 0
1579int abis_nm_disc_terr_sign(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1580 struct abis_nm_abis_channel *chan)
1581{
1582}
1583#endif
1584
1585int abis_nm_conn_terr_traf(struct gsm_bts_trx_ts *ts,
1586 u_int8_t e1_port, u_int8_t e1_timeslot,
1587 u_int8_t e1_subslot)
1588{
1589 struct gsm_bts *bts = ts->trx->bts;
1590 struct abis_om_hdr *oh;
1591 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +00001592 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001593
1594 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1595 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_TRAF,
Harald Welteb110cee2009-02-18 03:42:35 +00001596 NM_OC_CHANNEL, bts->bts_nr, ts->trx->nr, ts->nr);
Harald Welte52b1f982008-12-23 20:25:15 +00001597
1598 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1599 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1600
Harald Weltef325eb42009-02-19 17:07:39 +00001601 DEBUGP(DNM, "CONNECT TERR TRAF Um=%s E1=(%u,%u,%u)\n",
1602 gsm_ts_name(ts),
Harald Welteb110cee2009-02-18 03:42:35 +00001603 e1_port, e1_timeslot, e1_subslot);
1604
Harald Welte52b1f982008-12-23 20:25:15 +00001605 return abis_nm_sendmsg(bts, msg);
1606}
1607
1608#if 0
1609int abis_nm_disc_terr_traf(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1610 struct abis_nm_abis_channel *chan,
1611 u_int8_t subchan)
1612{
1613}
1614#endif
1615
Harald Welte22af0db2009-02-14 15:41:08 +00001616/* Chapter 8.6.1 */
1617int abis_nm_set_bts_attr(struct gsm_bts *bts, u_int8_t *attr, int attr_len)
1618{
1619 struct abis_om_hdr *oh;
1620 struct msgb *msg = nm_msgb_alloc();
1621 u_int8_t *cur;
1622
1623 DEBUGP(DNM, "Set BTS Attr (bts=%d)\n", bts->nr);
1624
1625 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte191280d2009-05-01 13:20:04 +00001626 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 +00001627 cur = msgb_put(msg, attr_len);
1628 memcpy(cur, attr, attr_len);
1629
1630 return abis_nm_sendmsg(bts, msg);
1631}
1632
1633/* Chapter 8.6.2 */
1634int abis_nm_set_radio_attr(struct gsm_bts_trx *trx, u_int8_t *attr, int attr_len)
1635{
1636 struct abis_om_hdr *oh;
1637 struct msgb *msg = nm_msgb_alloc();
1638 u_int8_t *cur;
1639
1640 DEBUGP(DNM, "Set TRX Attr (bts=%d,trx=%d)\n", trx->bts->nr, trx->nr);
1641
1642 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1643 fill_om_fom_hdr(oh, attr_len, NM_MT_SET_RADIO_ATTR, NM_OC_RADIO_CARRIER,
Harald Welte191280d2009-05-01 13:20:04 +00001644 trx->bts->bts_nr, trx->nr, 0xff);
Harald Welte22af0db2009-02-14 15:41:08 +00001645 cur = msgb_put(msg, attr_len);
1646 memcpy(cur, attr, attr_len);
1647
1648 return abis_nm_sendmsg(trx->bts, msg);
1649}
1650
1651/* Chapter 8.6.3 */
Harald Welte52b1f982008-12-23 20:25:15 +00001652int abis_nm_set_channel_attr(struct gsm_bts_trx_ts *ts, u_int8_t chan_comb)
1653{
1654 struct gsm_bts *bts = ts->trx->bts;
1655 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001656 u_int16_t arfcn = htons(ts->trx->arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001657 u_int8_t zero = 0x00;
Harald Welte8470bf22008-12-25 23:28:35 +00001658 struct msgb *msg = nm_msgb_alloc();
Harald Weltee0590df2009-02-15 03:34:15 +00001659 u_int8_t len = 2 + 2;
1660
1661 if (bts->type == GSM_BTS_TYPE_BS11)
1662 len += 4 + 2 + 2 + 3;
Harald Welte52b1f982008-12-23 20:25:15 +00001663
Harald Weltef325eb42009-02-19 17:07:39 +00001664 DEBUGP(DNM, "Set Chan Attr %s\n", gsm_ts_name(ts));
Harald Welte22af0db2009-02-14 15:41:08 +00001665
Harald Welte52b1f982008-12-23 20:25:15 +00001666 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001667 fill_om_fom_hdr(oh, len, NM_MT_SET_CHAN_ATTR,
Holger Freyther6b2d2622009-02-14 23:16:59 +00001668 NM_OC_CHANNEL, bts->bts_nr,
Harald Welte52b1f982008-12-23 20:25:15 +00001669 ts->trx->nr, ts->nr);
1670 /* FIXME: don't send ARFCN list, hopping sequence, mAIO, ...*/
Harald Weltee0590df2009-02-15 03:34:15 +00001671 if (bts->type == GSM_BTS_TYPE_BS11)
1672 msgb_tlv16_put(msg, NM_ATT_ARFCN_LIST, 1, &arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001673 msgb_tv_put(msg, NM_ATT_CHAN_COMB, chan_comb);
Harald Weltee0590df2009-02-15 03:34:15 +00001674 if (bts->type == GSM_BTS_TYPE_BS11) {
1675 msgb_tv_put(msg, NM_ATT_HSN, 0x00);
1676 msgb_tv_put(msg, NM_ATT_MAIO, 0x00);
1677 }
Harald Weltee6c22d92009-07-21 20:40:05 +02001678 msgb_tv_put(msg, NM_ATT_TSC, bts->tsc); /* training sequence */
Harald Weltee0590df2009-02-15 03:34:15 +00001679 if (bts->type == GSM_BTS_TYPE_BS11)
1680 msgb_tlv_put(msg, 0x59, 1, &zero);
Harald Welte52b1f982008-12-23 20:25:15 +00001681
1682 return abis_nm_sendmsg(bts, msg);
1683}
1684
Harald Welte34a99682009-02-13 02:41:40 +00001685int 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 +00001686 u_int8_t i2, u_int8_t i3, int nack, u_int8_t *attr, int att_len)
Harald Welte34a99682009-02-13 02:41:40 +00001687{
1688 struct abis_om_hdr *oh;
1689 struct msgb *msg = nm_msgb_alloc();
Harald Welte5c1e4582009-02-15 11:57:29 +00001690 u_int8_t msgtype = NM_MT_SW_ACT_REQ_ACK;
1691 u_int8_t len = att_len;
1692
1693 if (nack) {
1694 len += 2;
1695 msgtype = NM_MT_SW_ACT_REQ_NACK;
1696 }
Harald Welte34a99682009-02-13 02:41:40 +00001697
1698 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte5c1e4582009-02-15 11:57:29 +00001699 fill_om_fom_hdr(oh, att_len, msgtype, obj_class, i1, i2, i3);
1700
Harald Welte34a99682009-02-13 02:41:40 +00001701 if (attr) {
1702 u_int8_t *ptr = msgb_put(msg, att_len);
1703 memcpy(ptr, attr, att_len);
1704 }
Harald Welte5c1e4582009-02-15 11:57:29 +00001705 if (nack)
1706 msgb_tv_put(msg, NM_ATT_NACK_CAUSES, NM_NACK_OBJCLASS_NOTSUPP);
Harald Welte34a99682009-02-13 02:41:40 +00001707
1708 return abis_nm_sendmsg(bts, msg);
1709}
1710
Harald Welte8470bf22008-12-25 23:28:35 +00001711int abis_nm_raw_msg(struct gsm_bts *bts, int len, u_int8_t *rawmsg)
Harald Welte52b1f982008-12-23 20:25:15 +00001712{
Harald Welte8470bf22008-12-25 23:28:35 +00001713 struct msgb *msg = nm_msgb_alloc();
1714 struct abis_om_hdr *oh;
Harald Welte52b1f982008-12-23 20:25:15 +00001715 u_int8_t *data;
1716
1717 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
1718 fill_om_hdr(oh, len);
1719 data = msgb_put(msg, len);
Harald Weltead384642008-12-26 10:20:07 +00001720 memcpy(data, rawmsg, len);
Harald Welte52b1f982008-12-23 20:25:15 +00001721
1722 return abis_nm_sendmsg(bts, msg);
1723}
1724
1725/* Siemens specific commands */
1726static int __simple_cmd(struct gsm_bts *bts, u_int8_t msg_type)
1727{
1728 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001729 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001730
1731 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001732 fill_om_fom_hdr(oh, 0, msg_type, NM_OC_SITE_MANAGER,
Harald Welte52b1f982008-12-23 20:25:15 +00001733 0xff, 0xff, 0xff);
1734
1735 return abis_nm_sendmsg(bts, msg);
1736}
1737
Harald Welte34a99682009-02-13 02:41:40 +00001738/* Chapter 8.9.2 */
1739int abis_nm_opstart(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1, u_int8_t i2)
1740{
1741 struct abis_om_hdr *oh;
1742 struct msgb *msg = nm_msgb_alloc();
1743
Harald Welte22af0db2009-02-14 15:41:08 +00001744 DEBUGP(DNM, "Sending OPSTART obj_class=0x%02x obj_inst=(0x%02x, 0x%02x, 0x%02x)\n",
1745 obj_class, i0, i1, i2);
Harald Welte34a99682009-02-13 02:41:40 +00001746 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1747 fill_om_fom_hdr(oh, 0, NM_MT_OPSTART, obj_class, i0, i1, i2);
1748
1749 return abis_nm_sendmsg(bts, msg);
1750}
1751
1752/* Chapter 8.8.5 */
1753int abis_nm_chg_adm_state(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0,
1754 u_int8_t i1, u_int8_t i2, u_int8_t adm_state)
1755{
1756 struct abis_om_hdr *oh;
1757 struct msgb *msg = nm_msgb_alloc();
1758
1759 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1760 fill_om_fom_hdr(oh, 2, NM_MT_CHG_ADM_STATE, obj_class, i0, i1, i2);
1761 msgb_tv_put(msg, NM_ATT_ADM_STATE, adm_state);
1762
1763 return abis_nm_sendmsg(bts, msg);
1764}
1765
Harald Welte1989c082009-08-06 17:58:31 +02001766int abis_nm_conn_mdrop_link(struct gsm_bts *bts, u_int8_t e1_port0, u_int8_t ts0,
1767 u_int8_t e1_port1, u_int8_t ts1)
1768{
1769 struct abis_om_hdr *oh;
1770 struct msgb *msg = nm_msgb_alloc();
1771 u_int8_t *attr;
1772
1773 DEBUGP(DNM, "CONNECT MDROP LINK E1=(%u,%u) -> E1=(%u, %u)\n",
1774 e1_port0, ts0, e1_port1, ts1);
1775
1776 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1777 fill_om_fom_hdr(oh, 6, NM_MT_CONN_MDROP_LINK,
1778 NM_OC_SITE_MANAGER, 0x00, 0x00, 0x00);
1779
1780 attr = msgb_put(msg, 3);
1781 attr[0] = NM_ATT_MDROP_LINK;
1782 attr[1] = e1_port0;
1783 attr[2] = ts0;
1784
1785 attr = msgb_put(msg, 3);
1786 attr[0] = NM_ATT_MDROP_NEXT;
1787 attr[1] = e1_port1;
1788 attr[2] = ts1;
1789
1790 return abis_nm_sendmsg(bts, msg);
1791}
Harald Welte34a99682009-02-13 02:41:40 +00001792
Harald Welte52b1f982008-12-23 20:25:15 +00001793int abis_nm_event_reports(struct gsm_bts *bts, int on)
1794{
1795 if (on == 0)
Harald Welte227d4072009-01-03 08:16:25 +00001796 return __simple_cmd(bts, NM_MT_STOP_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001797 else
Harald Welte227d4072009-01-03 08:16:25 +00001798 return __simple_cmd(bts, NM_MT_REST_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001799}
1800
Harald Welte47d88ae2009-01-04 12:02:08 +00001801/* Siemens (or BS-11) specific commands */
1802
Harald Welte3ffd1372009-02-01 22:15:49 +00001803int abis_nm_bs11_bsc_disconnect(struct gsm_bts *bts, int reconnect)
1804{
1805 if (reconnect == 0)
1806 return __simple_cmd(bts, NM_MT_BS11_DISCONNECT);
1807 else
1808 return __simple_cmd(bts, NM_MT_BS11_RECONNECT);
1809}
1810
Harald Welteb8427972009-02-05 19:27:17 +00001811int abis_nm_bs11_restart(struct gsm_bts *bts)
1812{
1813 return __simple_cmd(bts, NM_MT_BS11_RESTART);
1814}
1815
1816
Harald Welte268bb402009-02-01 19:11:56 +00001817struct bs11_date_time {
1818 u_int16_t year;
1819 u_int8_t month;
1820 u_int8_t day;
1821 u_int8_t hour;
1822 u_int8_t min;
1823 u_int8_t sec;
1824} __attribute__((packed));
1825
1826
1827void get_bs11_date_time(struct bs11_date_time *aet)
1828{
1829 time_t t;
1830 struct tm *tm;
1831
1832 t = time(NULL);
1833 tm = localtime(&t);
1834 aet->sec = tm->tm_sec;
1835 aet->min = tm->tm_min;
1836 aet->hour = tm->tm_hour;
1837 aet->day = tm->tm_mday;
1838 aet->month = tm->tm_mon;
1839 aet->year = htons(1900 + tm->tm_year);
1840}
1841
Harald Welte05188ee2009-01-18 11:39:08 +00001842int abis_nm_bs11_reset_resource(struct gsm_bts *bts)
Harald Welte52b1f982008-12-23 20:25:15 +00001843{
Harald Welte4668fda2009-01-03 08:19:29 +00001844 return __simple_cmd(bts, NM_MT_BS11_RESET_RESOURCE);
Harald Welte52b1f982008-12-23 20:25:15 +00001845}
1846
Harald Welte05188ee2009-01-18 11:39:08 +00001847int abis_nm_bs11_db_transmission(struct gsm_bts *bts, int begin)
Harald Welte52b1f982008-12-23 20:25:15 +00001848{
1849 if (begin)
Harald Welte4668fda2009-01-03 08:19:29 +00001850 return __simple_cmd(bts, NM_MT_BS11_BEGIN_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00001851 else
Harald Welte4668fda2009-01-03 08:19:29 +00001852 return __simple_cmd(bts, NM_MT_BS11_END_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00001853}
Harald Welte47d88ae2009-01-04 12:02:08 +00001854
Harald Welte05188ee2009-01-18 11:39:08 +00001855int abis_nm_bs11_create_object(struct gsm_bts *bts,
Harald Welte1bc09062009-01-18 14:17:52 +00001856 enum abis_bs11_objtype type, u_int8_t idx,
1857 u_int8_t attr_len, const u_int8_t *attr)
Harald Welte47d88ae2009-01-04 12:02:08 +00001858{
1859 struct abis_om_hdr *oh;
1860 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00001861 u_int8_t *cur;
Harald Welte47d88ae2009-01-04 12:02:08 +00001862
1863 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001864 fill_om_fom_hdr(oh, attr_len, NM_MT_BS11_CREATE_OBJ,
Harald Welte268bb402009-02-01 19:11:56 +00001865 NM_OC_BS11, type, 0, idx);
Harald Welte1bc09062009-01-18 14:17:52 +00001866 cur = msgb_put(msg, attr_len);
1867 memcpy(cur, attr, attr_len);
Harald Welte47d88ae2009-01-04 12:02:08 +00001868
1869 return abis_nm_sendmsg(bts, msg);
1870}
1871
Harald Welte78fc0d42009-02-19 02:50:57 +00001872int abis_nm_bs11_delete_object(struct gsm_bts *bts,
1873 enum abis_bs11_objtype type, u_int8_t idx)
1874{
1875 struct abis_om_hdr *oh;
1876 struct msgb *msg = nm_msgb_alloc();
1877
1878 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1879 fill_om_fom_hdr(oh, 0, NM_MT_BS11_DELETE_OBJ,
1880 NM_OC_BS11, type, 0, idx);
1881
1882 return abis_nm_sendmsg(bts, msg);
1883}
1884
Harald Welte05188ee2009-01-18 11:39:08 +00001885int abis_nm_bs11_create_envaBTSE(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00001886{
1887 struct abis_om_hdr *oh;
1888 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00001889 u_int8_t zero = 0x00;
Harald Welte47d88ae2009-01-04 12:02:08 +00001890
1891 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001892 fill_om_fom_hdr(oh, 3, NM_MT_BS11_CREATE_OBJ,
Harald Welte1bc09062009-01-18 14:17:52 +00001893 NM_OC_BS11_ENVABTSE, 0, idx, 0xff);
1894 msgb_tlv_put(msg, 0x99, 1, &zero);
Harald Welte47d88ae2009-01-04 12:02:08 +00001895
1896 return abis_nm_sendmsg(bts, msg);
1897}
1898
Harald Welte05188ee2009-01-18 11:39:08 +00001899int abis_nm_bs11_create_bport(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00001900{
1901 struct abis_om_hdr *oh;
1902 struct msgb *msg = nm_msgb_alloc();
1903
1904 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1905 fill_om_fom_hdr(oh, 0, NM_MT_BS11_CREATE_OBJ, NM_OC_BS11_BPORT,
1906 idx, 0, 0);
1907
1908 return abis_nm_sendmsg(bts, msg);
1909}
Harald Welte05188ee2009-01-18 11:39:08 +00001910
Harald Welte78fc0d42009-02-19 02:50:57 +00001911static const u_int8_t sm_attr[] = { NM_ATT_TEI, NM_ATT_ABIS_CHANNEL };
1912int abis_nm_bs11_get_oml_tei_ts(struct gsm_bts *bts)
1913{
1914 struct abis_om_hdr *oh;
1915 struct msgb *msg = nm_msgb_alloc();
1916
1917 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1918 fill_om_fom_hdr(oh, 2+sizeof(sm_attr), NM_MT_GET_ATTR, NM_OC_SITE_MANAGER,
1919 0xff, 0xff, 0xff);
1920 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(sm_attr), sm_attr);
1921
1922 return abis_nm_sendmsg(bts, msg);
1923}
1924
Harald Welteb6c92ae2009-02-21 20:15:32 +00001925/* like abis_nm_conn_terr_traf + set_tei */
1926int abis_nm_bs11_conn_oml_tei(struct gsm_bts *bts, u_int8_t e1_port,
1927 u_int8_t e1_timeslot, u_int8_t e1_subslot,
1928 u_int8_t tei)
Harald Welte05188ee2009-01-18 11:39:08 +00001929{
1930 struct abis_om_hdr *oh;
1931 struct abis_nm_channel *ch;
1932 struct msgb *msg = nm_msgb_alloc();
1933
1934 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welteb6c92ae2009-02-21 20:15:32 +00001935 fill_om_fom_hdr(oh, sizeof(*ch)+2, NM_MT_BS11_SET_ATTR,
Harald Welte05188ee2009-01-18 11:39:08 +00001936 NM_OC_SITE_MANAGER, 0xff, 0xff, 0xff);
1937
1938 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1939 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
Harald Welteb6c92ae2009-02-21 20:15:32 +00001940 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte05188ee2009-01-18 11:39:08 +00001941
1942 return abis_nm_sendmsg(bts, msg);
1943}
1944
1945int abis_nm_bs11_set_trx_power(struct gsm_bts_trx *trx, u_int8_t level)
1946{
1947 struct abis_om_hdr *oh;
1948 struct msgb *msg = nm_msgb_alloc();
Harald Welte05188ee2009-01-18 11:39:08 +00001949
1950 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001951 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR,
Harald Welte05188ee2009-01-18 11:39:08 +00001952 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
1953 msgb_tlv_put(msg, NM_ATT_BS11_TXPWR, 1, &level);
1954
1955 return abis_nm_sendmsg(trx->bts, msg);
1956}
1957
Harald Welte78fc0d42009-02-19 02:50:57 +00001958int abis_nm_bs11_get_trx_power(struct gsm_bts_trx *trx)
1959{
1960 struct abis_om_hdr *oh;
1961 struct msgb *msg = nm_msgb_alloc();
1962 u_int8_t attr = NM_ATT_BS11_TXPWR;
1963
1964 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1965 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
1966 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
1967 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), &attr);
1968
1969 return abis_nm_sendmsg(trx->bts, msg);
1970}
1971
Harald Welteaaf02d92009-04-29 13:25:57 +00001972int abis_nm_bs11_get_pll_mode(struct gsm_bts *bts)
1973{
1974 struct abis_om_hdr *oh;
1975 struct msgb *msg = nm_msgb_alloc();
Harald Weltea7cfa032009-04-29 22:33:02 +00001976 u_int8_t attr[] = { NM_ATT_BS11_PLL_MODE };
Harald Welteaaf02d92009-04-29 13:25:57 +00001977
1978 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1979 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
1980 NM_OC_BS11, BS11_OBJ_LI, 0x00, 0x00);
Harald Welteaeedeb42009-05-01 13:08:14 +00001981 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), attr);
Harald Welteaaf02d92009-04-29 13:25:57 +00001982
1983 return abis_nm_sendmsg(bts, msg);
1984}
1985
Harald Welteef061952009-05-17 12:43:42 +00001986int abis_nm_bs11_get_cclk(struct gsm_bts *bts)
1987{
1988 struct abis_om_hdr *oh;
1989 struct msgb *msg = nm_msgb_alloc();
1990 u_int8_t attr[] = { NM_ATT_BS11_CCLK_ACCURACY,
1991 NM_ATT_BS11_CCLK_TYPE };
1992
1993 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1994 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
1995 NM_OC_BS11, BS11_OBJ_CCLK, 0x00, 0x00);
1996 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), attr);
1997
1998 return abis_nm_sendmsg(bts, msg);
1999
2000}
Harald Welteaaf02d92009-04-29 13:25:57 +00002001
Harald Welte268bb402009-02-01 19:11:56 +00002002//static const u_int8_t bs11_logon_c7[] = { 0x07, 0xd9, 0x01, 0x11, 0x0d, 0x10, 0x20 };
Harald Weltebb151312009-01-28 20:42:07 +00002003static const u_int8_t bs11_logon_c8[] = { 0x02 };
Harald Welte05188ee2009-01-18 11:39:08 +00002004static const u_int8_t bs11_logon_c9[] = "FACTORY";
2005
Harald Welte1bc09062009-01-18 14:17:52 +00002006int abis_nm_bs11_factory_logon(struct gsm_bts *bts, int on)
Harald Welte05188ee2009-01-18 11:39:08 +00002007{
2008 struct abis_om_hdr *oh;
2009 struct msgb *msg = nm_msgb_alloc();
Harald Welte268bb402009-02-01 19:11:56 +00002010 struct bs11_date_time bdt;
2011
2012 get_bs11_date_time(&bdt);
Harald Welte05188ee2009-01-18 11:39:08 +00002013
2014 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte1bc09062009-01-18 14:17:52 +00002015 if (on) {
Harald Welte268bb402009-02-01 19:11:56 +00002016 u_int8_t len = 3*2 + sizeof(bdt)
Harald Welte6f676a32009-01-18 14:27:48 +00002017 + sizeof(bs11_logon_c8) + sizeof(bs11_logon_c9);
Harald Welte043d04a2009-01-29 23:15:30 +00002018 fill_om_fom_hdr(oh, len, NM_MT_BS11_LMT_LOGON,
Harald Welte7b26bcb2009-05-28 11:39:21 +00002019 NM_OC_BS11_BTSE, 0xff, 0xff, 0xff);
Harald Welte043d04a2009-01-29 23:15:30 +00002020 msgb_tlv_put(msg, NM_ATT_BS11_LMT_LOGIN_TIME,
Harald Welte5083b0b2009-02-02 19:20:52 +00002021 sizeof(bdt), (u_int8_t *) &bdt);
Harald Welte043d04a2009-01-29 23:15:30 +00002022 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_ACC_LEV,
2023 sizeof(bs11_logon_c8), bs11_logon_c8);
2024 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_NAME,
2025 sizeof(bs11_logon_c9), bs11_logon_c9);
Harald Welte1bc09062009-01-18 14:17:52 +00002026 } else {
Harald Welte5e4d1b32009-02-01 13:36:56 +00002027 fill_om_fom_hdr(oh, 0, NM_MT_BS11_LMT_LOGOFF,
Harald Welte7b26bcb2009-05-28 11:39:21 +00002028 NM_OC_BS11_BTSE, 0xff, 0xff, 0xff);
Harald Welte1bc09062009-01-18 14:17:52 +00002029 }
Harald Welte05188ee2009-01-18 11:39:08 +00002030
2031 return abis_nm_sendmsg(bts, msg);
2032}
Harald Welte1bc09062009-01-18 14:17:52 +00002033
2034int abis_nm_bs11_set_trx1_pw(struct gsm_bts *bts, const char *password)
2035{
2036 struct abis_om_hdr *oh;
2037 struct msgb *msg;
2038
2039 if (strlen(password) != 10)
2040 return -EINVAL;
2041
2042 msg = nm_msgb_alloc();
2043 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00002044 fill_om_fom_hdr(oh, 2+strlen(password), NM_MT_BS11_SET_ATTR,
Harald Welte1bc09062009-01-18 14:17:52 +00002045 NM_OC_BS11, BS11_OBJ_TRX1, 0x00, 0x00);
2046 msgb_tlv_put(msg, NM_ATT_BS11_PASSWORD, 10, (const u_int8_t *)password);
2047
2048 return abis_nm_sendmsg(bts, msg);
2049}
2050
Harald Weltee69f5fb2009-04-28 16:31:38 +00002051/* change the BS-11 PLL Mode to either locked (E1 derived) or standalone */
2052int abis_nm_bs11_set_pll_locked(struct gsm_bts *bts, int locked)
2053{
2054 struct abis_om_hdr *oh;
2055 struct msgb *msg;
Harald Weltea432cd32009-04-29 13:01:50 +00002056 u_int8_t tlv_value;
Harald Weltee69f5fb2009-04-28 16:31:38 +00002057
2058 msg = nm_msgb_alloc();
2059 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2060 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR, NM_OC_BS11,
2061 BS11_OBJ_LI, 0x00, 0x00);
Harald Weltea432cd32009-04-29 13:01:50 +00002062
2063 if (locked)
2064 tlv_value = BS11_LI_PLL_LOCKED;
2065 else
2066 tlv_value = BS11_LI_PLL_STANDALONE;
2067
2068 msgb_tlv_put(msg, NM_ATT_BS11_PLL_MODE, 1, &tlv_value);
Harald Weltee69f5fb2009-04-28 16:31:38 +00002069
2070 return abis_nm_sendmsg(bts, msg);
2071}
2072
Harald Welte1bc09062009-01-18 14:17:52 +00002073int abis_nm_bs11_get_state(struct gsm_bts *bts)
2074{
2075 return __simple_cmd(bts, NM_MT_BS11_GET_STATE);
2076}
Harald Welte5e4d1b32009-02-01 13:36:56 +00002077
2078/* BS11 SWL */
2079
Harald Welte2cf161b2009-06-20 22:36:41 +02002080static void *tall_fle_ctx;
2081
Harald Welte5e4d1b32009-02-01 13:36:56 +00002082struct abis_nm_bs11_sw {
2083 struct gsm_bts *bts;
2084 char swl_fname[PATH_MAX];
2085 u_int8_t win_size;
Harald Welte3ffd1372009-02-01 22:15:49 +00002086 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00002087 struct llist_head file_list;
2088 gsm_cbfn *user_cb; /* specified by the user */
2089};
2090static struct abis_nm_bs11_sw _g_bs11_sw, *g_bs11_sw = &_g_bs11_sw;
2091
2092struct file_list_entry {
2093 struct llist_head list;
2094 char fname[PATH_MAX];
2095};
2096
2097struct file_list_entry *fl_dequeue(struct llist_head *queue)
2098{
2099 struct llist_head *lh;
2100
2101 if (llist_empty(queue))
2102 return NULL;
2103
2104 lh = queue->next;
2105 llist_del(lh);
2106
2107 return llist_entry(lh, struct file_list_entry, list);
2108}
2109
2110static int bs11_read_swl_file(struct abis_nm_bs11_sw *bs11_sw)
2111{
2112 char linebuf[255];
2113 struct llist_head *lh, *lh2;
2114 FILE *swl;
2115 int rc = 0;
2116
2117 swl = fopen(bs11_sw->swl_fname, "r");
2118 if (!swl)
2119 return -ENODEV;
2120
2121 /* zero the stale file list, if any */
2122 llist_for_each_safe(lh, lh2, &bs11_sw->file_list) {
2123 llist_del(lh);
Harald Welte2cf161b2009-06-20 22:36:41 +02002124 talloc_free(lh);
Harald Welte5e4d1b32009-02-01 13:36:56 +00002125 }
2126
2127 while (fgets(linebuf, sizeof(linebuf), swl)) {
2128 char file_id[12+1];
2129 char file_version[80+1];
2130 struct file_list_entry *fle;
2131 static char dir[PATH_MAX];
2132
2133 if (strlen(linebuf) < 4)
2134 continue;
Harald Welte3ffd1372009-02-01 22:15:49 +00002135
Harald Welte5e4d1b32009-02-01 13:36:56 +00002136 rc = sscanf(linebuf+4, "%12s:%80s\r\n", file_id, file_version);
2137 if (rc < 0) {
2138 perror("ERR parsing SWL file");
2139 rc = -EINVAL;
2140 goto out;
2141 }
2142 if (rc < 2)
2143 continue;
2144
Harald Welte470ec292009-06-26 20:25:23 +02002145 fle = talloc_zero(tall_fle_ctx, struct file_list_entry);
Harald Welte5e4d1b32009-02-01 13:36:56 +00002146 if (!fle) {
2147 rc = -ENOMEM;
2148 goto out;
2149 }
Harald Welte5e4d1b32009-02-01 13:36:56 +00002150
2151 /* construct new filename */
2152 strncpy(dir, bs11_sw->swl_fname, sizeof(dir));
2153 strncat(fle->fname, dirname(dir), sizeof(fle->fname) - 1);
2154 strcat(fle->fname, "/");
2155 strncat(fle->fname, file_id, sizeof(fle->fname) - 1 -strlen(fle->fname));
Harald Welte5e4d1b32009-02-01 13:36:56 +00002156
2157 llist_add_tail(&fle->list, &bs11_sw->file_list);
2158 }
2159
2160out:
2161 fclose(swl);
2162 return rc;
2163}
2164
2165/* bs11 swload specific callback, passed to abis_nm core swload */
2166static int bs11_swload_cbfn(unsigned int hook, unsigned int event,
2167 struct msgb *msg, void *data, void *param)
2168{
2169 struct abis_nm_bs11_sw *bs11_sw = data;
2170 struct file_list_entry *fle;
2171 int rc = 0;
2172
Harald Welte5e4d1b32009-02-01 13:36:56 +00002173 switch (event) {
2174 case NM_MT_LOAD_END_ACK:
2175 fle = fl_dequeue(&bs11_sw->file_list);
2176 if (fle) {
2177 /* start download the next file of our file list */
2178 rc = abis_nm_software_load(bs11_sw->bts, fle->fname,
2179 bs11_sw->win_size,
Harald Welte3ffd1372009-02-01 22:15:49 +00002180 bs11_sw->forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00002181 &bs11_swload_cbfn, bs11_sw);
Harald Welteac606dc2009-08-06 15:44:18 +02002182 talloc_free(fle);
Harald Welte5e4d1b32009-02-01 13:36:56 +00002183 } else {
2184 /* activate the SWL */
2185 rc = abis_nm_software_activate(bs11_sw->bts,
2186 bs11_sw->swl_fname,
2187 bs11_swload_cbfn,
2188 bs11_sw);
2189 }
2190 break;
Harald Welte3ffd1372009-02-01 22:15:49 +00002191 case NM_MT_LOAD_SEG_ACK:
Harald Welte5e4d1b32009-02-01 13:36:56 +00002192 case NM_MT_LOAD_END_NACK:
2193 case NM_MT_LOAD_INIT_ACK:
2194 case NM_MT_LOAD_INIT_NACK:
2195 case NM_MT_ACTIVATE_SW_NACK:
2196 case NM_MT_ACTIVATE_SW_ACK:
2197 default:
2198 /* fallthrough to the user callback */
Harald Welte97ed1e72009-02-06 13:38:02 +00002199 if (bs11_sw->user_cb)
2200 rc = bs11_sw->user_cb(hook, event, msg, NULL, NULL);
Harald Welte5e4d1b32009-02-01 13:36:56 +00002201 break;
2202 }
2203
2204 return rc;
2205}
2206
2207/* Siemens provides a SWL file that is a mere listing of all the other
2208 * files that are part of a software release. We need to upload first
2209 * the list file, and then each file that is listed in the list file */
2210int abis_nm_bs11_load_swl(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00002211 u_int8_t win_size, int forced, gsm_cbfn *cbfn)
Harald Welte5e4d1b32009-02-01 13:36:56 +00002212{
2213 struct abis_nm_bs11_sw *bs11_sw = g_bs11_sw;
2214 struct file_list_entry *fle;
2215 int rc = 0;
2216
2217 INIT_LLIST_HEAD(&bs11_sw->file_list);
2218 bs11_sw->bts = bts;
2219 bs11_sw->win_size = win_size;
2220 bs11_sw->user_cb = cbfn;
Harald Welte3ffd1372009-02-01 22:15:49 +00002221 bs11_sw->forced = forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00002222
2223 strncpy(bs11_sw->swl_fname, fname, sizeof(bs11_sw->swl_fname));
2224 rc = bs11_read_swl_file(bs11_sw);
2225 if (rc < 0)
2226 return rc;
2227
2228 /* dequeue next item in file list */
2229 fle = fl_dequeue(&bs11_sw->file_list);
2230 if (!fle)
2231 return -EINVAL;
2232
2233 /* start download the next file of our file list */
Harald Welte3ffd1372009-02-01 22:15:49 +00002234 rc = abis_nm_software_load(bts, fle->fname, win_size, forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00002235 bs11_swload_cbfn, bs11_sw);
Harald Welteac606dc2009-08-06 15:44:18 +02002236 talloc_free(fle);
Harald Welte5e4d1b32009-02-01 13:36:56 +00002237 return rc;
2238}
2239
Harald Welte5083b0b2009-02-02 19:20:52 +00002240#if 0
Harald Welte5e4d1b32009-02-01 13:36:56 +00002241static u_int8_t req_attr_btse[] = {
2242 NM_ATT_ADM_STATE, NM_ATT_BS11_LMT_LOGON_SESSION,
2243 NM_ATT_BS11_LMT_LOGIN_TIME, NM_ATT_BS11_LMT_USER_ACC_LEV,
2244 NM_ATT_BS11_LMT_USER_NAME,
2245
2246 0xaf, NM_ATT_BS11_RX_OFFSET, NM_ATT_BS11_VENDOR_NAME,
2247
2248 NM_ATT_BS11_SW_LOAD_INTENDED, NM_ATT_BS11_SW_LOAD_SAFETY,
2249
2250 NM_ATT_BS11_SW_LOAD_STORED };
2251
2252static u_int8_t req_attr_btsm[] = {
2253 NM_ATT_ABIS_CHANNEL, NM_ATT_TEI, NM_ATT_BS11_ABIS_EXT_TIME,
2254 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xce, NM_ATT_FILE_ID,
2255 NM_ATT_FILE_VERSION, NM_ATT_OPER_STATE, 0xe8, NM_ATT_BS11_ALL_TEST_CATG,
2256 NM_ATT_SW_DESCR, NM_ATT_GET_ARI };
Harald Welte5083b0b2009-02-02 19:20:52 +00002257#endif
Harald Welte5e4d1b32009-02-01 13:36:56 +00002258
2259static u_int8_t req_attr[] = {
2260 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xa8, NM_ATT_OPER_STATE,
2261 0xd5, 0xa1, NM_ATT_BS11_ESN_FW_CODE_NO, NM_ATT_BS11_ESN_HW_CODE_NO,
Harald Weltea7cfa032009-04-29 22:33:02 +00002262 0x42, NM_ATT_BS11_ESN_PCB_SERIAL, NM_ATT_BS11_PLL };
Harald Welte5e4d1b32009-02-01 13:36:56 +00002263
2264int abis_nm_bs11_get_serno(struct gsm_bts *bts)
2265{
2266 struct abis_om_hdr *oh;
2267 struct msgb *msg = nm_msgb_alloc();
2268
2269 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2270 /* SiemensHW CCTRL object */
2271 fill_om_fom_hdr(oh, 2+sizeof(req_attr), NM_MT_GET_ATTR, NM_OC_BS11,
2272 0x03, 0x00, 0x00);
2273 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(req_attr), req_attr);
2274
2275 return abis_nm_sendmsg(bts, msg);
2276}
Harald Welte268bb402009-02-01 19:11:56 +00002277
2278int abis_nm_bs11_set_ext_time(struct gsm_bts *bts)
2279{
2280 struct abis_om_hdr *oh;
2281 struct msgb *msg = nm_msgb_alloc();
2282 struct bs11_date_time aet;
2283
2284 get_bs11_date_time(&aet);
2285 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2286 /* SiemensHW CCTRL object */
2287 fill_om_fom_hdr(oh, 2+sizeof(aet), NM_MT_BS11_SET_ATTR, NM_OC_SITE_MANAGER,
2288 0xff, 0xff, 0xff);
Harald Welte5083b0b2009-02-02 19:20:52 +00002289 msgb_tlv_put(msg, NM_ATT_BS11_ABIS_EXT_TIME, sizeof(aet), (u_int8_t *) &aet);
Harald Welte268bb402009-02-01 19:11:56 +00002290
2291 return abis_nm_sendmsg(bts, msg);
2292}
Harald Welte5c1e4582009-02-15 11:57:29 +00002293
2294/* ip.access nanoBTS specific commands */
Harald Welte5c1e4582009-02-15 11:57:29 +00002295static const char ipaccess_magic[] = "com.ipaccess";
2296
Harald Welte677c21f2009-02-17 13:22:23 +00002297
2298static int abis_nm_rx_ipacc(struct msgb *msg)
2299{
2300 struct abis_om_hdr *oh = msgb_l2(msg);
2301 struct abis_om_fom_hdr *foh;
2302 u_int8_t idstrlen = oh->data[0];
2303 struct tlv_parsed tp;
2304
2305 if (strncmp((char *)&oh->data[1], ipaccess_magic, idstrlen)) {
2306 DEBUGP(DNM, "id string is not com.ipaccess !?!\n");
2307 return -EINVAL;
2308 }
2309
Harald Welte193fefc2009-04-30 15:16:27 +00002310 foh = (struct abis_om_fom_hdr *) (oh->data + 1 + idstrlen);
Harald Welte03133942009-02-18 19:51:53 +00002311 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Welte677c21f2009-02-17 13:22:23 +00002312
Harald Welte193fefc2009-04-30 15:16:27 +00002313 DEBUGP(DNM, "IPACCESS(0x%02x): ", foh->msg_type);
2314
Harald Welte677c21f2009-02-17 13:22:23 +00002315 switch (foh->msg_type) {
2316 case NM_MT_IPACC_RSL_CONNECT_ACK:
Harald Welte193fefc2009-04-30 15:16:27 +00002317 DEBUGPC(DNM, "RSL CONNECT ACK ");
Harald Welte0efe9b72009-07-12 09:33:54 +02002318 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_DST_IP))
Harald Welte9de2bf82009-04-30 15:59:55 +00002319 DEBUGPC(DNM, "IP=%s ",
Harald Welte677c21f2009-02-17 13:22:23 +00002320 inet_ntoa(*((struct in_addr *)
Harald Welte0efe9b72009-07-12 09:33:54 +02002321 TLVP_VAL(&tp, NM_ATT_IPACC_DST_IP))));
2322 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_DST_IP_PORT))
Harald Welte9de2bf82009-04-30 15:59:55 +00002323 DEBUGPC(DNM, "PORT=%u ",
Harald Welte677c21f2009-02-17 13:22:23 +00002324 ntohs(*((u_int16_t *)
Harald Welte0efe9b72009-07-12 09:33:54 +02002325 TLVP_VAL(&tp, NM_ATT_IPACC_DST_IP_PORT))));
Harald Welte9de2bf82009-04-30 15:59:55 +00002326 DEBUGPC(DNM, "\n");
Harald Welte677c21f2009-02-17 13:22:23 +00002327 break;
2328 case NM_MT_IPACC_RSL_CONNECT_NACK:
Harald Welte193fefc2009-04-30 15:16:27 +00002329 DEBUGPC(DNM, "RSL CONNECT NACK ");
Harald Welte677c21f2009-02-17 13:22:23 +00002330 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
Harald Welte6c96ba52009-05-01 13:03:40 +00002331 DEBUGPC(DNM, " CAUSE=%s\n",
2332 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
Harald Welte677c21f2009-02-17 13:22:23 +00002333 else
2334 DEBUGPC(DNM, "\n");
2335 break;
Harald Welte193fefc2009-04-30 15:16:27 +00002336 case NM_MT_IPACC_SET_NVATTR_ACK:
2337 DEBUGPC(DNM, "SET NVATTR ACK\n");
2338 /* FIXME: decode and show the actual attributes */
2339 break;
2340 case NM_MT_IPACC_SET_NVATTR_NACK:
Harald Welte6c96ba52009-05-01 13:03:40 +00002341 DEBUGPC(DNM, "SET NVATTR NACK ");
2342 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
2343 DEBUGPC(DNM, " CAUSE=%s\n",
2344 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
2345 else
2346 DEBUGPC(DNM, "\n");
Harald Welte193fefc2009-04-30 15:16:27 +00002347 break;
Harald Welte684b1a82009-07-03 11:26:45 +02002348 case NM_MT_IPACC_GET_NVATTR_ACK:
2349 DEBUGPC(DNM, "GET NVATTR ACK\n");
2350 /* FIXME: decode and show the actual attributes */
2351 break;
2352 case NM_MT_IPACC_GET_NVATTR_NACK:
2353 DEBUGPC(DNM, "GET NVATTR NACK ");
2354 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
2355 DEBUGPC(DNM, " CAUSE=%s\n",
2356 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
2357 else
2358 DEBUGPC(DNM, "\n");
2359 break;
Harald Welte193fefc2009-04-30 15:16:27 +00002360 default:
2361 DEBUGPC(DNM, "unknown\n");
2362 break;
Harald Welte677c21f2009-02-17 13:22:23 +00002363 }
Holger Hans Peter Freythera7cd9fc2009-07-07 12:40:07 +02002364
2365 /* signal handling */
2366 switch (foh->msg_type) {
2367 case NM_MT_IPACC_RSL_CONNECT_NACK:
2368 case NM_MT_IPACC_SET_NVATTR_NACK:
2369 case NM_MT_IPACC_GET_NVATTR_NACK:
2370 dispatch_signal(SS_NM, S_NM_IPACC_NACK, (void*) ((long)foh->msg_type));
2371 break;
2372 default:
2373 break;
2374 }
2375
Harald Welte677c21f2009-02-17 13:22:23 +00002376 return 0;
2377}
2378
Harald Welte193fefc2009-04-30 15:16:27 +00002379/* send an ip-access manufacturer specific message */
Harald Welte5c1e4582009-02-15 11:57:29 +00002380int abis_nm_ipaccess_msg(struct gsm_bts *bts, u_int8_t msg_type,
2381 u_int8_t obj_class, u_int8_t bts_nr,
2382 u_int8_t trx_nr, u_int8_t ts_nr,
2383 u_int8_t *attr, int attr_len)
2384{
2385 struct msgb *msg = nm_msgb_alloc();
2386 struct abis_om_hdr *oh;
2387 struct abis_om_fom_hdr *foh;
2388 u_int8_t *data;
2389
2390 /* construct the 12.21 OM header, observe the erroneous length */
2391 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
2392 fill_om_hdr(oh, sizeof(*foh) + attr_len);
2393 oh->mdisc = ABIS_OM_MDISC_MANUF;
2394
2395 /* add the ip.access magic */
2396 data = msgb_put(msg, sizeof(ipaccess_magic)+1);
2397 *data++ = sizeof(ipaccess_magic);
2398 memcpy(data, ipaccess_magic, sizeof(ipaccess_magic));
2399
2400 /* fill the 12.21 FOM header */
2401 foh = (struct abis_om_fom_hdr *) msgb_put(msg, sizeof(*foh));
2402 foh->msg_type = msg_type;
2403 foh->obj_class = obj_class;
2404 foh->obj_inst.bts_nr = bts_nr;
2405 foh->obj_inst.trx_nr = trx_nr;
2406 foh->obj_inst.ts_nr = ts_nr;
2407
2408 if (attr && attr_len) {
2409 data = msgb_put(msg, attr_len);
2410 memcpy(data, attr, attr_len);
2411 }
2412
2413 return abis_nm_sendmsg(bts, msg);
2414}
Harald Welte677c21f2009-02-17 13:22:23 +00002415
Harald Welte193fefc2009-04-30 15:16:27 +00002416/* set some attributes in NVRAM */
2417int abis_nm_ipaccess_set_nvattr(struct gsm_bts *bts, u_int8_t *attr,
2418 int attr_len)
2419{
2420 return abis_nm_ipaccess_msg(bts, NM_MT_IPACC_SET_NVATTR,
2421 NM_OC_BASEB_TRANSC, 0, 0, 0xff, attr,
2422 attr_len);
2423}
2424
2425/* restart / reboot an ip.access nanoBTS */
2426int abis_nm_ipaccess_restart(struct gsm_bts *bts)
2427{
2428 return __simple_cmd(bts, NM_MT_IPACC_RESTART);
2429}
Harald Welte7bfc2672009-07-28 00:41:45 +02002430
2431
2432static __attribute__((constructor)) void on_dso_load_abis_nm(void)
2433{
2434 tall_fle_ctx = talloc_named_const(tall_bsc_ctx, 1,
2435 "bs11_file_list_entry");
2436}