blob: 5fb53d72f3f2cc492736f5235aae0f0164291072 [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 Welte5e4d1b32009-02-01 13:36:56 +000029#include <malloc.h>
30#include <libgen.h>
Harald Welte268bb402009-02-01 19:11:56 +000031#include <time.h>
Harald Welte5f6f1492009-02-02 14:50:29 +000032#include <limits.h>
Harald Welte4724f992009-01-18 18:01:49 +000033
Harald Welte52b1f982008-12-23 20:25:15 +000034#include <sys/types.h>
Harald Welte4724f992009-01-18 18:01:49 +000035#include <sys/stat.h>
Harald Welte8470bf22008-12-25 23:28:35 +000036#include <netinet/in.h>
Harald Welte677c21f2009-02-17 13:22:23 +000037#include <arpa/inet.h>
Harald Welte52b1f982008-12-23 20:25:15 +000038
Harald Welte8470bf22008-12-25 23:28:35 +000039#include <openbsc/gsm_data.h>
40#include <openbsc/debug.h>
41#include <openbsc/msgb.h>
42#include <openbsc/tlv.h>
43#include <openbsc/abis_nm.h>
Holger Freytherca362a62009-01-04 21:05:01 +000044#include <openbsc/misdn.h>
Harald Weltef9a8cc32009-05-01 15:39:49 +000045#include <openbsc/signal.h>
Harald Welte52b1f982008-12-23 20:25:15 +000046
Harald Welte8470bf22008-12-25 23:28:35 +000047#define OM_ALLOC_SIZE 1024
48#define OM_HEADROOM_SIZE 128
Harald Welte52b1f982008-12-23 20:25:15 +000049
50/* unidirectional messages from BTS to BSC */
51static const enum abis_nm_msgtype reports[] = {
52 NM_MT_SW_ACTIVATED_REP,
53 NM_MT_TEST_REP,
54 NM_MT_STATECHG_EVENT_REP,
55 NM_MT_FAILURE_EVENT_REP,
56};
57
58/* messages without ACK/NACK */
59static const enum abis_nm_msgtype no_ack_nack[] = {
60 NM_MT_MEAS_RES_REQ,
61 NM_MT_STOP_MEAS,
62 NM_MT_START_MEAS,
63};
64
Harald Welte4724f992009-01-18 18:01:49 +000065/* Messages related to software load */
66static const enum abis_nm_msgtype sw_load_msgs[] = {
67 NM_MT_LOAD_INIT_ACK,
68 NM_MT_LOAD_INIT_NACK,
69 NM_MT_LOAD_SEG_ACK,
70 NM_MT_LOAD_ABORT,
71 NM_MT_LOAD_END_ACK,
72 NM_MT_LOAD_END_NACK,
Harald Welte34a99682009-02-13 02:41:40 +000073 //NM_MT_SW_ACT_REQ,
Harald Welte4724f992009-01-18 18:01:49 +000074 NM_MT_ACTIVATE_SW_ACK,
75 NM_MT_ACTIVATE_SW_NACK,
76 NM_MT_SW_ACTIVATED_REP,
77};
78
Harald Weltee0590df2009-02-15 03:34:15 +000079static const enum abis_nm_msgtype nacks[] = {
80 NM_MT_LOAD_INIT_NACK,
81 NM_MT_LOAD_END_NACK,
82 NM_MT_SW_ACT_REQ_NACK,
83 NM_MT_ACTIVATE_SW_NACK,
84 NM_MT_ESTABLISH_TEI_NACK,
85 NM_MT_CONN_TERR_SIGN_NACK,
86 NM_MT_DISC_TERR_SIGN_NACK,
87 NM_MT_CONN_TERR_TRAF_NACK,
88 NM_MT_DISC_TERR_TRAF_NACK,
89 NM_MT_CONN_MDROP_LINK_NACK,
90 NM_MT_DISC_MDROP_LINK_NACK,
91 NM_MT_SET_BTS_ATTR_NACK,
92 NM_MT_SET_RADIO_ATTR_NACK,
93 NM_MT_SET_CHAN_ATTR_NACK,
94 NM_MT_PERF_TEST_NACK,
95 NM_MT_SEND_TEST_REP_NACK,
96 NM_MT_STOP_TEST_NACK,
97 NM_MT_STOP_EVENT_REP_NACK,
98 NM_MT_REST_EVENT_REP_NACK,
99 NM_MT_CHG_ADM_STATE_NACK,
100 NM_MT_CHG_ADM_STATE_REQ_NACK,
101 NM_MT_REP_OUTST_ALARMS_NACK,
102 NM_MT_CHANGEOVER_NACK,
103 NM_MT_OPSTART_NACK,
104 NM_MT_REINIT_NACK,
105 NM_MT_SET_SITE_OUT_NACK,
106 NM_MT_CHG_HW_CONF_NACK,
107 NM_MT_GET_ATTR_NACK,
108 NM_MT_SET_ALARM_THRES_NACK,
109 NM_MT_BS11_BEGIN_DB_TX_NACK,
110 NM_MT_BS11_END_DB_TX_NACK,
111 NM_MT_BS11_CREATE_OBJ_NACK,
112 NM_MT_BS11_DELETE_OBJ_NACK,
113};
Harald Welte78fc0d42009-02-19 02:50:57 +0000114
115static const char *nack_names[0xff] = {
116 [NM_MT_LOAD_INIT_NACK] = "SOFTWARE LOAD INIT",
117 [NM_MT_LOAD_END_NACK] = "SOFTWARE LOAD END",
118 [NM_MT_SW_ACT_REQ_NACK] = "SOFTWARE ACTIVATE REQUEST",
119 [NM_MT_ACTIVATE_SW_NACK] = "ACTIVATE SOFTWARE",
120 [NM_MT_ESTABLISH_TEI_NACK] = "ESTABLISH TEI",
121 [NM_MT_CONN_TERR_SIGN_NACK] = "CONNECT TERRESTRIAL SIGNALLING",
122 [NM_MT_DISC_TERR_SIGN_NACK] = "DISCONNECT TERRESTRIAL SIGNALLING",
123 [NM_MT_CONN_TERR_TRAF_NACK] = "CONNECT TERRESTRIAL TRAFFIC",
124 [NM_MT_DISC_TERR_TRAF_NACK] = "DISCONNECT TERRESTRIAL TRAFFIC",
125 [NM_MT_CONN_MDROP_LINK_NACK] = "CONNECT MULTI-DROP LINK",
126 [NM_MT_DISC_MDROP_LINK_NACK] = "DISCONNECT MULTI-DROP LINK",
127 [NM_MT_SET_BTS_ATTR_NACK] = "SET BTS ATTRIBUTE",
128 [NM_MT_SET_RADIO_ATTR_NACK] = "SET RADIO ATTRIBUTE",
129 [NM_MT_SET_CHAN_ATTR_NACK] = "SET CHANNEL ATTRIBUTE",
130 [NM_MT_PERF_TEST_NACK] = "PERFORM TEST",
131 [NM_MT_SEND_TEST_REP_NACK] = "SEND TEST REPORT",
132 [NM_MT_STOP_TEST_NACK] = "STOP TEST",
133 [NM_MT_STOP_EVENT_REP_NACK] = "STOP EVENT REPORT",
134 [NM_MT_REST_EVENT_REP_NACK] = "RESET EVENT REPORT",
135 [NM_MT_CHG_ADM_STATE_NACK] = "CHANGE ADMINISTRATIVE STATE",
136 [NM_MT_CHG_ADM_STATE_REQ_NACK] = "CHANGE ADMINISTRATIVE STATE REQUEST",
137 [NM_MT_REP_OUTST_ALARMS_NACK] = "REPORT OUTSTANDING ALARMS",
138 [NM_MT_CHANGEOVER_NACK] = "CHANGEOVER",
139 [NM_MT_OPSTART_NACK] = "OPSTART",
140 [NM_MT_REINIT_NACK] = "REINIT",
141 [NM_MT_SET_SITE_OUT_NACK] = "SET SITE OUTPUT",
142 [NM_MT_CHG_HW_CONF_NACK] = "CHANGE HARDWARE CONFIGURATION",
143 [NM_MT_GET_ATTR_NACK] = "GET ATTRIBUTE",
144 [NM_MT_SET_ALARM_THRES_NACK] = "SET ALARM THRESHOLD",
145 [NM_MT_BS11_BEGIN_DB_TX_NACK] = "BS11 BEGIN DATABASE TRANSMISSION",
146 [NM_MT_BS11_END_DB_TX_NACK] = "BS11 END DATABASE TRANSMISSION",
147 [NM_MT_BS11_CREATE_OBJ_NACK] = "BS11 CREATE OBJECT",
148 [NM_MT_BS11_DELETE_OBJ_NACK] = "BS11 DELETE OBJECT",
149};
150
Harald Welte6c96ba52009-05-01 13:03:40 +0000151/* Chapter 9.4.36 */
152static const char *nack_cause_names[] = {
153 /* General Nack Causes */
154 [NM_NACK_INCORR_STRUCT] = "Incorrect message structure",
155 [NM_NACK_MSGTYPE_INVAL] = "Invalid message type value",
156 [NM_NACK_OBJCLASS_INVAL] = "Invalid Object class value",
157 [NM_NACK_OBJCLASS_NOTSUPP] = "Object class not supported",
158 [NM_NACK_BTSNR_UNKN] = "BTS no. unknown",
159 [NM_NACK_TRXNR_UNKN] = "Baseband Transceiver no. unknown",
160 [NM_NACK_OBJINST_UNKN] = "Object Instance unknown",
161 [NM_NACK_ATTRID_INVAL] = "Invalid attribute identifier value",
162 [NM_NACK_ATTRID_NOTSUPP] = "Attribute identifier not supported",
163 [NM_NACK_PARAM_RANGE] = "Parameter value outside permitted range",
164 [NM_NACK_ATTRLIST_INCONSISTENT] = "Inconsistency in attribute list",
165 [NM_NACK_SPEC_IMPL_NOTSUPP] = "Specified implementation not supported",
166 [NM_NACK_CANT_PERFORM] = "Message cannot be performed",
167 /* Specific Nack Causes */
168 [NM_NACK_RES_NOTIMPL] = "Resource not implemented",
169 [NM_NACK_RES_NOTAVAIL] = "Resource not available",
170 [NM_NACK_FREQ_NOTAVAIL] = "Frequency not available",
171 [NM_NACK_TEST_NOTSUPP] = "Test not supported",
172 [NM_NACK_CAPACITY_RESTR] = "Capacity restrictions",
173 [NM_NACK_PHYSCFG_NOTPERFORM] = "Physical configuration cannot be performed",
174 [NM_NACK_TEST_NOTINIT] = "Test not initiated",
175 [NM_NACK_PHYSCFG_NOTRESTORE] = "Physical configuration cannot be restored",
176 [NM_NACK_TEST_NOSUCH] = "No such test",
177 [NM_NACK_TEST_NOSTOP] = "Test cannot be stopped",
178 [NM_NACK_MSGINCONSIST_PHYSCFG] = "Message inconsistent with physical configuration",
179 [NM_NACK_FILE_INCOMPLETE] = "Complete file notreceived",
180 [NM_NACK_FILE_NOTAVAIL] = "File not available at destination",
181 [MN_NACK_FILE_NOTACTIVATE] = "File cannot be activate",
182 [NM_NACK_REQ_NOT_GRANT] = "Request not granted",
183 [NM_NACK_WAIT] = "Wait",
184 [NM_NACK_NOTH_REPORT_EXIST] = "Nothing reportable existing",
185 [NM_NACK_MEAS_NOTSUPP] = "Measurement not supported",
186 [NM_NACK_MEAS_NOTSTART] = "Measurement not started",
187};
188
189static char namebuf[255];
190static const char *nack_cause_name(u_int8_t cause)
191{
192 if (cause < ARRAY_SIZE(nack_cause_names) && nack_cause_names[cause])
193 return nack_cause_names[cause];
194
195 snprintf(namebuf, sizeof(namebuf), "0x%02x\n", cause);
196 return namebuf;
197}
198
Harald Welte0db97b22009-05-01 17:22:47 +0000199/* Chapter 9.4.16: Event Type */
200static const char *event_type_names[] = {
201 [NM_EVT_COMM_FAIL] = "communication failure",
202 [NM_EVT_QOS_FAIL] = "quality of service failure",
203 [NM_EVT_PROC_FAIL] = "processing failure",
204 [NM_EVT_EQUIP_FAIL] = "equipment failure",
205 [NM_EVT_ENV_FAIL] = "environment failure",
206};
207
208static const char *event_type_name(u_int8_t cause)
209{
210 if (cause < ARRAY_SIZE(event_type_names) && event_type_names[cause])
211 return event_type_names[cause];
212
213 snprintf(namebuf, sizeof(namebuf), "0x%02x\n", cause);
214 return namebuf;
215}
216
217/* Chapter 9.4.63: Perceived Severity */
218static const char *severity_names[] = {
219 [NM_SEVER_CEASED] = "failure ceased",
220 [NM_SEVER_CRITICAL] = "critical failure",
221 [NM_SEVER_MAJOR] = "major failure",
222 [NM_SEVER_MINOR] = "minor failure",
223 [NM_SEVER_WARNING] = "warning level failure",
224 [NM_SEVER_INDETERMINATE] = "indeterminate failure",
225};
226
227static const char *severity_name(u_int8_t cause)
228{
229 if (cause < ARRAY_SIZE(severity_names) && severity_names[cause])
230 return severity_names[cause];
231
232 snprintf(namebuf, sizeof(namebuf), "0x%02x\n", cause);
233 return namebuf;
234}
235
Harald Welte52b1f982008-12-23 20:25:15 +0000236/* Attributes that the BSC can set, not only get, according to Section 9.4 */
237static const enum abis_nm_attr nm_att_settable[] = {
238 NM_ATT_ADD_INFO,
239 NM_ATT_ADD_TEXT,
240 NM_ATT_DEST,
241 NM_ATT_EVENT_TYPE,
242 NM_ATT_FILE_DATA,
243 NM_ATT_GET_ARI,
244 NM_ATT_HW_CONF_CHG,
245 NM_ATT_LIST_REQ_ATTR,
246 NM_ATT_MDROP_LINK,
247 NM_ATT_MDROP_NEXT,
248 NM_ATT_NACK_CAUSES,
249 NM_ATT_OUTST_ALARM,
250 NM_ATT_PHYS_CONF,
251 NM_ATT_PROB_CAUSE,
252 NM_ATT_RAD_SUBC,
253 NM_ATT_SOURCE,
254 NM_ATT_SPEC_PROB,
255 NM_ATT_START_TIME,
256 NM_ATT_TEST_DUR,
257 NM_ATT_TEST_NO,
258 NM_ATT_TEST_REPORT,
259 NM_ATT_WINDOW_SIZE,
260 NM_ATT_SEVERITY,
261 NM_ATT_MEAS_RES,
262 NM_ATT_MEAS_TYPE,
263};
264
Harald Weltee0590df2009-02-15 03:34:15 +0000265static const struct tlv_definition nm_att_tlvdef = {
266 .def = {
267 [NM_ATT_ABIS_CHANNEL] = { TLV_TYPE_FIXED, 3 },
268 [NM_ATT_ADD_INFO] = { TLV_TYPE_TL16V },
269 [NM_ATT_ADD_TEXT] = { TLV_TYPE_TL16V },
270 [NM_ATT_ADM_STATE] = { TLV_TYPE_TV },
271 [NM_ATT_ARFCN_LIST]= { TLV_TYPE_TL16V },
272 [NM_ATT_AUTON_REPORT] = { TLV_TYPE_TV },
273 [NM_ATT_AVAIL_STATUS] = { TLV_TYPE_TL16V },
274 [NM_ATT_BCCH_ARFCN] = { TLV_TYPE_FIXED, 2 },
275 [NM_ATT_BSIC] = { TLV_TYPE_TV },
276 [NM_ATT_BTS_AIR_TIMER] = { TLV_TYPE_TV },
277 [NM_ATT_CCCH_L_I_P] = { TLV_TYPE_TV },
278 [NM_ATT_CCCH_L_T] = { TLV_TYPE_TV },
279 [NM_ATT_CHAN_COMB] = { TLV_TYPE_TV },
280 [NM_ATT_CONN_FAIL_CRIT] = { TLV_TYPE_TL16V },
281 [NM_ATT_DEST] = { TLV_TYPE_TL16V },
282 [NM_ATT_EVENT_TYPE] = { TLV_TYPE_TV },
283 [NM_ATT_FILE_DATA] = { TLV_TYPE_TL16V },
284 [NM_ATT_FILE_ID] = { TLV_TYPE_TL16V },
285 [NM_ATT_FILE_VERSION] = { TLV_TYPE_TL16V },
286 [NM_ATT_GSM_TIME] = { TLV_TYPE_FIXED, 2 },
287 [NM_ATT_HSN] = { TLV_TYPE_TV },
288 [NM_ATT_HW_CONFIG] = { TLV_TYPE_TL16V },
289 [NM_ATT_HW_DESC] = { TLV_TYPE_TL16V },
290 [NM_ATT_INTAVE_PARAM] = { TLV_TYPE_TV },
291 [NM_ATT_INTERF_BOUND] = { TLV_TYPE_FIXED, 6 },
292 [NM_ATT_LIST_REQ_ATTR] = { TLV_TYPE_TL16V },
293 [NM_ATT_MAIO] = { TLV_TYPE_TV },
294 [NM_ATT_MANUF_STATE] = { TLV_TYPE_TV },
295 [NM_ATT_MANUF_THRESH] = { TLV_TYPE_TL16V },
296 [NM_ATT_MANUF_ID] = { TLV_TYPE_TL16V },
297 [NM_ATT_MAX_TA] = { TLV_TYPE_TV },
298 [NM_ATT_MDROP_LINK] = { TLV_TYPE_FIXED, 2 },
299 [NM_ATT_MDROP_NEXT] = { TLV_TYPE_FIXED, 2 },
300 [NM_ATT_NACK_CAUSES] = { TLV_TYPE_TV },
301 [NM_ATT_NY1] = { TLV_TYPE_TV },
302 [NM_ATT_OPER_STATE] = { TLV_TYPE_TV },
303 [NM_ATT_OVERL_PERIOD] = { TLV_TYPE_TL16V },
304 [NM_ATT_PHYS_CONF] = { TLV_TYPE_TL16V },
305 [NM_ATT_POWER_CLASS] = { TLV_TYPE_TV },
306 [NM_ATT_POWER_THRESH] = { TLV_TYPE_FIXED, 3 },
307 [NM_ATT_PROB_CAUSE] = { TLV_TYPE_FIXED, 3 },
308 [NM_ATT_RACH_B_THRESH] = { TLV_TYPE_TV },
309 [NM_ATT_LDAVG_SLOTS] = { TLV_TYPE_FIXED, 2 },
310 [NM_ATT_RAD_SUBC] = { TLV_TYPE_TV },
311 [NM_ATT_RF_MAXPOWR_R] = { TLV_TYPE_TV },
312 [NM_ATT_SITE_INPUTS] = { TLV_TYPE_TL16V },
313 [NM_ATT_SITE_OUTPUTS] = { TLV_TYPE_TL16V },
314 [NM_ATT_SOURCE] = { TLV_TYPE_TL16V },
315 [NM_ATT_SPEC_PROB] = { TLV_TYPE_TV },
316 [NM_ATT_START_TIME] = { TLV_TYPE_FIXED, 2 },
317 [NM_ATT_T200] = { TLV_TYPE_FIXED, 7 },
318 [NM_ATT_TEI] = { TLV_TYPE_TV },
319 [NM_ATT_TEST_DUR] = { TLV_TYPE_FIXED, 2 },
320 [NM_ATT_TEST_NO] = { TLV_TYPE_TV },
321 [NM_ATT_TEST_REPORT] = { TLV_TYPE_TL16V },
322 [NM_ATT_VSWR_THRESH] = { TLV_TYPE_FIXED, 2 },
323 [NM_ATT_WINDOW_SIZE] = { TLV_TYPE_TV },
324 [NM_ATT_TSC] = { TLV_TYPE_TV },
325 [NM_ATT_SW_CONFIG] = { TLV_TYPE_TL16V },
326 [NM_ATT_SEVERITY] = { TLV_TYPE_TV },
327 [NM_ATT_GET_ARI] = { TLV_TYPE_TL16V },
328 [NM_ATT_HW_CONF_CHG] = { TLV_TYPE_TL16V },
329 [NM_ATT_OUTST_ALARM] = { TLV_TYPE_TV },
330 [NM_ATT_FILE_DATA] = { TLV_TYPE_TL16V },
331 [NM_ATT_MEAS_RES] = { TLV_TYPE_TL16V },
332 /* BS11 specifics */
Harald Welte78fc0d42009-02-19 02:50:57 +0000333 [NM_ATT_BS11_ESN_FW_CODE_NO] = { TLV_TYPE_TLV },
334 [NM_ATT_BS11_ESN_HW_CODE_NO] = { TLV_TYPE_TLV },
335 [NM_ATT_BS11_ESN_PCB_SERIAL] = { TLV_TYPE_TLV },
336 [NM_ATT_BS11_BOOT_SW_VERS] = { TLV_TYPE_TLV },
337 [0xd5] = { TLV_TYPE_TLV },
338 [0xa8] = { TLV_TYPE_TLV },
Harald Weltee0590df2009-02-15 03:34:15 +0000339 [NM_ATT_BS11_PASSWORD] = { TLV_TYPE_TLV },
340 [NM_ATT_BS11_TXPWR] = { TLV_TYPE_TLV },
341 [NM_ATT_BS11_RSSI_OFFS] = { TLV_TYPE_TLV },
342 [NM_ATT_BS11_LINE_CFG] = { TLV_TYPE_TV },
343 [NM_ATT_BS11_L1_PROT_TYPE] = { TLV_TYPE_TV },
344 [NM_ATT_BS11_BIT_ERR_THESH] = { TLV_TYPE_FIXED, 2 },
345 [NM_ATT_BS11_DIVERSITY] = { TLV_TYPE_TLV },
Harald Welteee670472009-02-22 21:58:49 +0000346 [NM_ATT_BS11_LMT_LOGON_SESSION]={ TLV_TYPE_TLV },
Harald Weltee0590df2009-02-15 03:34:15 +0000347 [NM_ATT_BS11_LMT_LOGIN_TIME] = { TLV_TYPE_TLV },
348 [NM_ATT_BS11_LMT_USER_ACC_LEV] ={ TLV_TYPE_TLV },
349 [NM_ATT_BS11_LMT_USER_NAME] = { TLV_TYPE_TLV },
Harald Welte03133942009-02-18 19:51:53 +0000350 [NM_ATT_BS11_BTS_STATE] = { TLV_TYPE_TLV },
351 [NM_ATT_BS11_E1_STATE] = { TLV_TYPE_TLV },
Harald Welteaaf02d92009-04-29 13:25:57 +0000352 [NM_ATT_BS11_PLL_MODE] = { TLV_TYPE_TLV },
Harald Weltea7cfa032009-04-29 22:33:02 +0000353 [NM_ATT_BS11_PLL] = { TLV_TYPE_TLV },
Harald Welte677c21f2009-02-17 13:22:23 +0000354 /* ip.access specifics */
355 [NM_ATT_IPACC_RSL_BSC_IP] = { TLV_TYPE_FIXED, 4 },
356 [NM_ATT_IPACC_RSL_BSC_PORT] = { TLV_TYPE_FIXED, 2 },
Harald Welte3bfbb842009-04-29 22:58:38 +0000357 [NM_ATT_IPACC_PRIM_OML_IP] = { TLV_TYPE_FIXED, 6 },
358 [0x95] = { TLV_TYPE_FIXED, 2 },
Harald Welte677c21f2009-02-17 13:22:23 +0000359 [0x85] = { TLV_TYPE_TV },
360
Harald Weltee0590df2009-02-15 03:34:15 +0000361 },
362};
Harald Welte03133942009-02-18 19:51:53 +0000363
364int abis_nm_tlv_parse(struct tlv_parsed *tp, const u_int8_t *buf, int len)
365{
366 return tlv_parse(tp, &nm_att_tlvdef, buf, len);
367}
Harald Weltee0590df2009-02-15 03:34:15 +0000368
Harald Welte52b1f982008-12-23 20:25:15 +0000369static int is_in_arr(enum abis_nm_msgtype mt, const enum abis_nm_msgtype *arr, int size)
370{
371 int i;
372
373 for (i = 0; i < size; i++) {
374 if (arr[i] == mt)
375 return 1;
376 }
377
378 return 0;
379}
380
Holger Freytherca362a62009-01-04 21:05:01 +0000381#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000382/* is this msgtype the usual ACK/NACK type ? */
383static int is_ack_nack(enum abis_nm_msgtype mt)
384{
385 return !is_in_arr(mt, no_ack_nack, ARRAY_SIZE(no_ack_nack));
386}
Holger Freytherca362a62009-01-04 21:05:01 +0000387#endif
Harald Welte52b1f982008-12-23 20:25:15 +0000388
389/* is this msgtype a report ? */
390static int is_report(enum abis_nm_msgtype mt)
391{
Harald Welte8470bf22008-12-25 23:28:35 +0000392 return is_in_arr(mt, reports, ARRAY_SIZE(reports));
Harald Welte52b1f982008-12-23 20:25:15 +0000393}
394
395#define MT_ACK(x) (x+1)
396#define MT_NACK(x) (x+2)
397
398static void fill_om_hdr(struct abis_om_hdr *oh, u_int8_t len)
399{
400 oh->mdisc = ABIS_OM_MDISC_FOM;
401 oh->placement = ABIS_OM_PLACEMENT_ONLY;
402 oh->sequence = 0;
403 oh->length = len;
404}
405
406static void fill_om_fom_hdr(struct abis_om_hdr *oh, u_int8_t len,
407 u_int8_t msg_type, u_int8_t obj_class,
408 u_int8_t bts_nr, u_int8_t trx_nr, u_int8_t ts_nr)
409{
410 struct abis_om_fom_hdr *foh =
411 (struct abis_om_fom_hdr *) oh->data;
412
Harald Welte702d8702008-12-26 20:25:35 +0000413 fill_om_hdr(oh, len+sizeof(*foh));
Harald Welte52b1f982008-12-23 20:25:15 +0000414 foh->msg_type = msg_type;
415 foh->obj_class = obj_class;
416 foh->obj_inst.bts_nr = bts_nr;
417 foh->obj_inst.trx_nr = trx_nr;
418 foh->obj_inst.ts_nr = ts_nr;
419}
420
Harald Welte8470bf22008-12-25 23:28:35 +0000421static struct msgb *nm_msgb_alloc(void)
422{
423 return msgb_alloc_headroom(OM_ALLOC_SIZE, OM_HEADROOM_SIZE);
424}
425
Harald Welte52b1f982008-12-23 20:25:15 +0000426/* Send a OML NM Message from BSC to BTS */
427int abis_nm_sendmsg(struct gsm_bts *bts, struct msgb *msg)
428{
Holger Freyther59639e82009-02-09 23:09:55 +0000429 msg->trx = bts->c0;
430
Harald Weltead384642008-12-26 10:20:07 +0000431 return _abis_nm_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000432}
433
Harald Welte4724f992009-01-18 18:01:49 +0000434static int abis_nm_rcvmsg_sw(struct msgb *mb);
435
Harald Welte34a99682009-02-13 02:41:40 +0000436const char *oc_names[] = {
437 [NM_OC_SITE_MANAGER] = "SITE MANAGER",
438 [NM_OC_BTS] = "BTS",
439 [NM_OC_RADIO_CARRIER] = "RADIO CARRIER",
440 [NM_OC_BASEB_TRANSC] = "BASEBAND TRANSCEIVER",
441 [NM_OC_CHANNEL] = "CHANNEL",
442};
443
444static const char *obj_class_name(u_int8_t oc)
445{
446 if (oc >= ARRAY_SIZE(oc_names))
447 return "UNKNOWN";
448 return oc_names[oc];
449}
450
Harald Welte4d87f242009-03-10 19:43:44 +0000451const char *nm_opstate_name(u_int8_t os)
Harald Welte34a99682009-02-13 02:41:40 +0000452{
453 switch (os) {
454 case 1:
455 return "Disabled";
456 case 2:
457 return "Enabled";
458 case 0xff:
459 return "NULL";
460 default:
461 return "RFU";
462 }
463}
464
Harald Weltee0590df2009-02-15 03:34:15 +0000465/* Chapter 9.4.7 */
Harald Welte4d87f242009-03-10 19:43:44 +0000466static const char *avail_names[] = {
Harald Weltee0590df2009-02-15 03:34:15 +0000467 "In test",
468 "Failed",
469 "Power off",
470 "Off line",
471 "<not used>",
472 "Dependency",
473 "Degraded",
474 "Not installed",
475};
476
Harald Welte4d87f242009-03-10 19:43:44 +0000477const char *nm_avail_name(u_int8_t avail)
Harald Weltee0590df2009-02-15 03:34:15 +0000478{
Harald Welte0b8348d2009-02-18 03:43:01 +0000479 if (avail == 0xff)
480 return "OK";
Harald Weltee0590df2009-02-15 03:34:15 +0000481 if (avail >= ARRAY_SIZE(avail_names))
482 return "UNKNOWN";
483 return avail_names[avail];
484}
485
486
487/* obtain the gsm_nm_state data structure for a given object instance */
488static struct gsm_nm_state *
489objclass2nmstate(struct gsm_bts *bts, u_int8_t obj_class,
490 struct abis_om_obj_inst *obj_inst)
491{
492 struct gsm_bts_trx *trx;
493 struct gsm_nm_state *nm_state = NULL;
494
495 switch (obj_class) {
496 case NM_OC_BTS:
497 nm_state = &bts->nm_state;
498 break;
499 case NM_OC_RADIO_CARRIER:
500 if (obj_inst->trx_nr >= bts->num_trx)
501 return NULL;
502 trx = &bts->trx[obj_inst->trx_nr];
503 nm_state = &trx->nm_state;
504 break;
505 case NM_OC_BASEB_TRANSC:
506 if (obj_inst->trx_nr >= bts->num_trx)
507 return NULL;
508 trx = &bts->trx[obj_inst->trx_nr];
509 nm_state = &trx->bb_transc.nm_state;
510 break;
511 case NM_OC_CHANNEL:
512 if (obj_inst->trx_nr > bts->num_trx)
513 return NULL;
514 trx = &bts->trx[obj_inst->trx_nr];
515 if (obj_inst->ts_nr >= TRX_NR_TS)
516 return NULL;
517 nm_state = &trx->ts[obj_inst->ts_nr].nm_state;
518 break;
519 case NM_OC_SITE_MANAGER:
520 nm_state = &bts->site_mgr.nm_state;
521 break;
522 }
523 return nm_state;
524}
525
526/* obtain the in-memory data structure of a given object instance */
527static void *
528objclass2obj(struct gsm_bts *bts, u_int8_t obj_class,
529 struct abis_om_obj_inst *obj_inst)
530{
531 struct gsm_bts_trx *trx;
532 void *obj = NULL;
533
534 switch (obj_class) {
535 case NM_OC_BTS:
536 obj = bts;
537 break;
538 case NM_OC_RADIO_CARRIER:
539 if (obj_inst->trx_nr >= bts->num_trx)
540 return NULL;
541 trx = &bts->trx[obj_inst->trx_nr];
542 obj = trx;
543 break;
544 case NM_OC_BASEB_TRANSC:
545 if (obj_inst->trx_nr >= bts->num_trx)
546 return NULL;
547 trx = &bts->trx[obj_inst->trx_nr];
548 obj = &trx->bb_transc;
549 break;
550 case NM_OC_CHANNEL:
551 if (obj_inst->trx_nr > bts->num_trx)
552 return NULL;
553 trx = &bts->trx[obj_inst->trx_nr];
554 if (obj_inst->ts_nr >= TRX_NR_TS)
555 return NULL;
556 obj = &trx->ts[obj_inst->ts_nr];
557 break;
558 case NM_OC_SITE_MANAGER:
559 obj = &bts->site_mgr;
560 break;
561 }
562 return obj;
563}
564
565/* Update the administrative state of a given object in our in-memory data
566 * structures and send an event to the higher layer */
567static int update_admstate(struct gsm_bts *bts, u_int8_t obj_class,
568 struct abis_om_obj_inst *obj_inst, u_int8_t adm_state)
569{
Harald Welteaeedeb42009-05-01 13:08:14 +0000570 struct gsm_nm_state *nm_state, new_state;
Harald Weltee0590df2009-02-15 03:34:15 +0000571 void *obj;
572 int rc;
573
Harald Weltee0590df2009-02-15 03:34:15 +0000574 obj = objclass2obj(bts, obj_class, obj_inst);
Harald Welteaeedeb42009-05-01 13:08:14 +0000575 nm_state = objclass2nmstate(bts, obj_class, obj_inst);
576 if (!nm_state)
577 return -1;
578
579 new_state = *nm_state;
580 new_state.administrative = adm_state;
581
582 rc = nm_state_event(EVT_STATECHG_ADM, obj_class, obj, nm_state, &new_state);
583
584 nm_state->administrative = adm_state;
Harald Weltee0590df2009-02-15 03:34:15 +0000585
586 return rc;
587}
588
Harald Welte97ed1e72009-02-06 13:38:02 +0000589static int abis_nm_rx_statechg_rep(struct msgb *mb)
590{
Harald Weltee0590df2009-02-15 03:34:15 +0000591 struct abis_om_hdr *oh = msgb_l2(mb);
Harald Welte97ed1e72009-02-06 13:38:02 +0000592 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Harald Welte22af0db2009-02-14 15:41:08 +0000593 struct gsm_bts *bts = mb->trx->bts;
Harald Weltee0590df2009-02-15 03:34:15 +0000594 struct tlv_parsed tp;
595 struct gsm_nm_state *nm_state, new_state;
596 int rc;
597
Harald Welte23897662009-05-01 14:52:51 +0000598 DEBUGPC(DNM, "STATE CHG: ");
Harald Weltee0590df2009-02-15 03:34:15 +0000599
600 nm_state = objclass2nmstate(bts, foh->obj_class, &foh->obj_inst);
601 if (!nm_state) {
602 DEBUGPC(DNM, "\n");
603 return -EINVAL;
Harald Welte22af0db2009-02-14 15:41:08 +0000604 }
Harald Weltee0590df2009-02-15 03:34:15 +0000605
606 new_state = *nm_state;
607
Harald Welte03133942009-02-18 19:51:53 +0000608 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Weltee0590df2009-02-15 03:34:15 +0000609 if (TLVP_PRESENT(&tp, NM_ATT_OPER_STATE)) {
610 new_state.operational = *TLVP_VAL(&tp, NM_ATT_OPER_STATE);
Harald Welte4d87f242009-03-10 19:43:44 +0000611 DEBUGPC(DNM, "OP_STATE=%s ", nm_opstate_name(new_state.operational));
Harald Weltee0590df2009-02-15 03:34:15 +0000612 }
613 if (TLVP_PRESENT(&tp, NM_ATT_AVAIL_STATUS)) {
Harald Welte0b8348d2009-02-18 03:43:01 +0000614 if (TLVP_LEN(&tp, NM_ATT_AVAIL_STATUS) == 0)
615 new_state.availability = 0xff;
616 else
617 new_state.availability = *TLVP_VAL(&tp, NM_ATT_AVAIL_STATUS);
Harald Welte4d87f242009-03-10 19:43:44 +0000618 DEBUGPC(DNM, "AVAIL=%s(%02x) ", nm_avail_name(new_state.availability),
Harald Weltee0590df2009-02-15 03:34:15 +0000619 new_state.availability);
620 }
621 if (TLVP_PRESENT(&tp, NM_ATT_ADM_STATE)) {
622 new_state.administrative = *TLVP_VAL(&tp, NM_ATT_ADM_STATE);
623 DEBUGPC(DNM, "ADM=%02x ", new_state.administrative);
Harald Welte97ed1e72009-02-06 13:38:02 +0000624 }
625 DEBUGPC(DNM, "\n");
Harald Weltee0590df2009-02-15 03:34:15 +0000626
627 if (memcmp(&new_state, nm_state, sizeof(new_state))) {
628 /* Update the operational state of a given object in our in-memory data
629 * structures and send an event to the higher layer */
630 void *obj = objclass2obj(bts, foh->obj_class, &foh->obj_inst);
631 rc = nm_state_event(EVT_STATECHG_OPER, foh->obj_class, obj, nm_state, &new_state);
632 *nm_state = new_state;
633 }
634#if 0
Harald Welte22af0db2009-02-14 15:41:08 +0000635 if (op_state == 1) {
636 /* try to enable objects that are disabled */
637 abis_nm_opstart(bts, foh->obj_class,
638 foh->obj_inst.bts_nr,
639 foh->obj_inst.trx_nr,
640 foh->obj_inst.ts_nr);
641 }
Harald Weltee0590df2009-02-15 03:34:15 +0000642#endif
Harald Welte97ed1e72009-02-06 13:38:02 +0000643 return 0;
644}
645
Harald Welte0db97b22009-05-01 17:22:47 +0000646static int rx_fail_evt_rep(struct msgb *mb)
647{
648 struct abis_om_hdr *oh = msgb_l2(mb);
649 struct abis_om_fom_hdr *foh = msgb_l3(mb);
650 struct tlv_parsed tp;
651
652 DEBUGPC(DNM, "Failure Event Report ");
653
654 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
655
656 if (TLVP_PRESENT(&tp, NM_ATT_EVENT_TYPE))
657 DEBUGPC(DNM, "Type=%s ", event_type_name(*TLVP_VAL(&tp, NM_ATT_EVENT_TYPE)));
658 if (TLVP_PRESENT(&tp, NM_ATT_SEVERITY))
659 DEBUGPC(DNM, "Severity=%s ", severity_name(*TLVP_VAL(&tp, NM_ATT_SEVERITY)));
660
661 DEBUGPC(DNM, "\n");
662
663 return 0;
664}
665
Harald Welte97ed1e72009-02-06 13:38:02 +0000666static int abis_nm_rcvmsg_report(struct msgb *mb)
667{
668 struct abis_om_fom_hdr *foh = msgb_l3(mb);
669 u_int8_t mt = foh->msg_type;
670
Harald Welte23897662009-05-01 14:52:51 +0000671 DEBUGP(DNM, "OC=%s(%02x) INST=(%02x,%02x,%02x) ",
672 obj_class_name(foh->obj_class), foh->obj_class,
673 foh->obj_inst.bts_nr, foh->obj_inst.trx_nr,
674 foh->obj_inst.ts_nr);
675
Harald Welte97ed1e72009-02-06 13:38:02 +0000676 //nmh->cfg->report_cb(mb, foh);
677
678 switch (mt) {
679 case NM_MT_STATECHG_EVENT_REP:
680 return abis_nm_rx_statechg_rep(mb);
681 break;
Harald Welte34a99682009-02-13 02:41:40 +0000682 case NM_MT_SW_ACTIVATED_REP:
Harald Welte23897662009-05-01 14:52:51 +0000683 DEBUGPC(DNM, "Software Activated Report\n");
Harald Weltef9a8cc32009-05-01 15:39:49 +0000684 dispatch_signal(SS_NM, S_NM_SW_ACTIV_REP, mb);
Harald Welte34a99682009-02-13 02:41:40 +0000685 break;
Harald Weltee0590df2009-02-15 03:34:15 +0000686 case NM_MT_FAILURE_EVENT_REP:
Harald Welte0db97b22009-05-01 17:22:47 +0000687 rx_fail_evt_rep(mb);
Harald Weltef9a8cc32009-05-01 15:39:49 +0000688 dispatch_signal(SS_NM, S_NM_FAIL_REP, mb);
Harald Weltee0590df2009-02-15 03:34:15 +0000689 break;
690 default:
Harald Welte23897662009-05-01 14:52:51 +0000691 DEBUGPC(DNM, "reporting NM MT 0x%02x\n", mt);
Harald Weltee0590df2009-02-15 03:34:15 +0000692 break;
693
Harald Welte97ed1e72009-02-06 13:38:02 +0000694 };
695
Harald Welte97ed1e72009-02-06 13:38:02 +0000696 return 0;
697}
698
Harald Welte34a99682009-02-13 02:41:40 +0000699/* Activate the specified software into the BTS */
700static int ipacc_sw_activate(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1,
701 u_int8_t i2, u_int8_t *sw_desc, u_int8_t swdesc_len)
702{
703 struct abis_om_hdr *oh;
704 struct msgb *msg = nm_msgb_alloc();
705 u_int8_t len = swdesc_len;
706 u_int8_t *trailer;
707
708 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
709 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, obj_class, i0, i1, i2);
710
711 trailer = msgb_put(msg, swdesc_len);
712 memcpy(trailer, sw_desc, swdesc_len);
713
714 return abis_nm_sendmsg(bts, msg);
715}
716
717static int abis_nm_rx_sw_act_req(struct msgb *mb)
718{
719 struct abis_om_hdr *oh = msgb_l2(mb);
720 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Harald Welte5c1e4582009-02-15 11:57:29 +0000721 int nack = 0;
Harald Welte34a99682009-02-13 02:41:40 +0000722 int ret;
723
Harald Welte5c1e4582009-02-15 11:57:29 +0000724 DEBUGP(DNM, "Software Activate Request ");
Harald Welte34a99682009-02-13 02:41:40 +0000725
Harald Welte5c1e4582009-02-15 11:57:29 +0000726 if (foh->obj_class >= 0xf0 && foh->obj_class <= 0xf3) {
727 DEBUGPC(DNM, "NACKing for GPRS obj_class 0x%02x\n", foh->obj_class);
728 nack = 1;
729 } else
730 DEBUGPC(DNM, "ACKing and Activating\n");
731
732 ret = abis_nm_sw_act_req_ack(mb->trx->bts, foh->obj_class,
Harald Welte34a99682009-02-13 02:41:40 +0000733 foh->obj_inst.bts_nr,
734 foh->obj_inst.trx_nr,
Harald Welte5c1e4582009-02-15 11:57:29 +0000735 foh->obj_inst.ts_nr, nack,
Harald Welte34a99682009-02-13 02:41:40 +0000736 foh->data, oh->length-sizeof(*foh));
737
Harald Welte5c1e4582009-02-15 11:57:29 +0000738 if (nack)
739 return ret;
740
Harald Welte34a99682009-02-13 02:41:40 +0000741 /* FIXME: properly parse attributes */
742 return ipacc_sw_activate(mb->trx->bts, foh->obj_class,
743 foh->obj_inst.bts_nr,
744 foh->obj_inst.trx_nr,
745 foh->obj_inst.ts_nr,
746 foh->data + oh->length-sizeof(*foh)-22, 22);
747}
748
Harald Weltee0590df2009-02-15 03:34:15 +0000749/* Receive a CHANGE_ADM_STATE_ACK, parse the TLV and update local state */
750static int abis_nm_rx_chg_adm_state_ack(struct msgb *mb)
751{
752 struct abis_om_hdr *oh = msgb_l2(mb);
753 struct abis_om_fom_hdr *foh = msgb_l3(mb);
754 struct tlv_parsed tp;
755 u_int8_t adm_state;
756
Harald Welte03133942009-02-18 19:51:53 +0000757 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Weltee0590df2009-02-15 03:34:15 +0000758 if (!TLVP_PRESENT(&tp, NM_ATT_ADM_STATE))
759 return -EINVAL;
760
761 adm_state = *TLVP_VAL(&tp, NM_ATT_ADM_STATE);
762
763 return update_admstate(mb->trx->bts, foh->obj_class, &foh->obj_inst, adm_state);
764}
765
Harald Welteee670472009-02-22 21:58:49 +0000766static int abis_nm_rx_lmt_event(struct msgb *mb)
767{
768 struct abis_om_hdr *oh = msgb_l2(mb);
769 struct abis_om_fom_hdr *foh = msgb_l3(mb);
770 struct tlv_parsed tp;
771
772 DEBUGP(DNM, "LMT Event ");
773 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
774 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_LOGON_SESSION) &&
775 TLVP_LEN(&tp, NM_ATT_BS11_LMT_LOGON_SESSION) >= 1) {
776 u_int8_t onoff = *TLVP_VAL(&tp, NM_ATT_BS11_LMT_LOGON_SESSION);
777 DEBUGPC(DNM, "LOG%s ", onoff ? "ON" : "OFF");
778 }
779 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV) &&
780 TLVP_LEN(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV) >= 1) {
781 u_int8_t level = *TLVP_VAL(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV);
782 DEBUGPC(DNM, "Level=%u ", level);
783 }
784 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_USER_NAME) &&
785 TLVP_LEN(&tp, NM_ATT_BS11_LMT_USER_NAME) >= 1) {
786 char *name = (char *) TLVP_VAL(&tp, NM_ATT_BS11_LMT_USER_NAME);
787 DEBUGPC(DNM, "Username=%s ", name);
788 }
789 DEBUGPC(DNM, "\n");
790 /* FIXME: parse LMT LOGON TIME */
791 return 0;
792}
793
Harald Welte52b1f982008-12-23 20:25:15 +0000794/* Receive a OML NM Message from BTS */
Harald Welte8470bf22008-12-25 23:28:35 +0000795static int abis_nm_rcvmsg_fom(struct msgb *mb)
Harald Welte52b1f982008-12-23 20:25:15 +0000796{
Harald Welte6c96ba52009-05-01 13:03:40 +0000797 struct abis_om_hdr *oh = msgb_l2(mb);
Harald Welte52b1f982008-12-23 20:25:15 +0000798 struct abis_om_fom_hdr *foh = msgb_l3(mb);
799 u_int8_t mt = foh->msg_type;
800
801 /* check for unsolicited message */
Harald Welte97ed1e72009-02-06 13:38:02 +0000802 if (is_report(mt))
803 return abis_nm_rcvmsg_report(mb);
Harald Welte52b1f982008-12-23 20:25:15 +0000804
Harald Welte4724f992009-01-18 18:01:49 +0000805 if (is_in_arr(mt, sw_load_msgs, ARRAY_SIZE(sw_load_msgs)))
806 return abis_nm_rcvmsg_sw(mb);
807
Harald Welte78fc0d42009-02-19 02:50:57 +0000808 if (is_in_arr(mt, nacks, ARRAY_SIZE(nacks))) {
Harald Welte6c96ba52009-05-01 13:03:40 +0000809 struct tlv_parsed tp;
Harald Welte78fc0d42009-02-19 02:50:57 +0000810 if (nack_names[mt])
Harald Welte6c96ba52009-05-01 13:03:40 +0000811 DEBUGP(DNM, "%s NACK ", nack_names[mt]);
812 /* FIXME: NACK cause */
Harald Welte78fc0d42009-02-19 02:50:57 +0000813 else
Harald Welte6c96ba52009-05-01 13:03:40 +0000814 DEBUGP(DNM, "NACK 0x%02x ", mt);
815
816 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
817 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
818 DEBUGPC(DNM, "CAUSE=%s\n",
819 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
820 else
821 DEBUGPC(DNM, "\n");
Harald Welte78fc0d42009-02-19 02:50:57 +0000822 }
Harald Weltead384642008-12-26 10:20:07 +0000823#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000824 /* check if last message is to be acked */
825 if (is_ack_nack(nmh->last_msgtype)) {
826 if (mt == MT_ACK(nmh->last_msgtype)) {
827 fprintf(stderr, "received ACK (0x%x)\n",
828 foh->msg_type);
829 /* we got our ACK, continue sending the next msg */
830 } else if (mt == MT_NACK(nmh->last_msgtype)) {
831 /* we got a NACK, signal this to the caller */
832 fprintf(stderr, "received NACK (0x%x)\n",
833 foh->msg_type);
834 /* FIXME: somehow signal this to the caller */
835 } else {
836 /* really strange things happen */
837 return -EINVAL;
838 }
839 }
Harald Weltead384642008-12-26 10:20:07 +0000840#endif
841
Harald Welte97ed1e72009-02-06 13:38:02 +0000842 switch (mt) {
Harald Weltee0590df2009-02-15 03:34:15 +0000843 case NM_MT_CHG_ADM_STATE_ACK:
844 return abis_nm_rx_chg_adm_state_ack(mb);
845 break;
Harald Welte34a99682009-02-13 02:41:40 +0000846 case NM_MT_SW_ACT_REQ:
847 return abis_nm_rx_sw_act_req(mb);
848 break;
Harald Welte97ed1e72009-02-06 13:38:02 +0000849 case NM_MT_BS11_LMT_SESSION:
Harald Welteee670472009-02-22 21:58:49 +0000850 return abis_nm_rx_lmt_event(mb);
Harald Welte97ed1e72009-02-06 13:38:02 +0000851 break;
852 }
853
Harald Weltead384642008-12-26 10:20:07 +0000854 return 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000855}
856
Harald Welte677c21f2009-02-17 13:22:23 +0000857static int abis_nm_rx_ipacc(struct msgb *mb);
858
859static int abis_nm_rcvmsg_manuf(struct msgb *mb)
860{
861 int rc;
862 int bts_type = mb->trx->bts->type;
863
864 switch (bts_type) {
865 case GSM_BTS_TYPE_NANOBTS_900:
866 case GSM_BTS_TYPE_NANOBTS_1800:
867 rc = abis_nm_rx_ipacc(mb);
868 break;
869 default:
870 fprintf(stderr, "don't know how to parse OML for this "
871 "BTS type (%u)\n", bts_type);
872 rc = 0;
873 break;
874 }
875
876 return rc;
877}
878
Harald Welte52b1f982008-12-23 20:25:15 +0000879/* High-Level API */
880/* Entry-point where L2 OML from BTS enters the NM code */
Harald Welte8470bf22008-12-25 23:28:35 +0000881int abis_nm_rcvmsg(struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +0000882{
Harald Welte52b1f982008-12-23 20:25:15 +0000883 struct abis_om_hdr *oh = msgb_l2(msg);
Harald Welte677c21f2009-02-17 13:22:23 +0000884 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000885
886 /* Various consistency checks */
887 if (oh->placement != ABIS_OM_PLACEMENT_ONLY) {
888 fprintf(stderr, "ABIS OML placement 0x%x not supported\n",
889 oh->placement);
890 return -EINVAL;
891 }
892 if (oh->sequence != 0) {
893 fprintf(stderr, "ABIS OML sequence 0x%x != 0x00\n",
894 oh->sequence);
895 return -EINVAL;
896 }
Harald Welte702d8702008-12-26 20:25:35 +0000897#if 0
Holger Freytherca362a62009-01-04 21:05:01 +0000898 unsigned int l2_len = msg->tail - (u_int8_t *)msgb_l2(msg);
899 unsigned int hlen = sizeof(*oh) + sizeof(struct abis_om_fom_hdr);
Harald Welte702d8702008-12-26 20:25:35 +0000900 if (oh->length + hlen > l2_len) {
Harald Welte52b1f982008-12-23 20:25:15 +0000901 fprintf(stderr, "ABIS OML truncated message (%u > %u)\n",
902 oh->length + sizeof(*oh), l2_len);
903 return -EINVAL;
904 }
Harald Welte702d8702008-12-26 20:25:35 +0000905 if (oh->length + hlen < l2_len)
906 fprintf(stderr, "ABIS OML message with extra trailer?!? (oh->len=%d, sizeof_oh=%d l2_len=%d\n", oh->length, sizeof(*oh), l2_len);
907#endif
Harald Weltead384642008-12-26 10:20:07 +0000908 msg->l3h = (unsigned char *)oh + sizeof(*oh);
Harald Welte52b1f982008-12-23 20:25:15 +0000909
910 switch (oh->mdisc) {
911 case ABIS_OM_MDISC_FOM:
Harald Welte8470bf22008-12-25 23:28:35 +0000912 rc = abis_nm_rcvmsg_fom(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000913 break;
Harald Welte677c21f2009-02-17 13:22:23 +0000914 case ABIS_OM_MDISC_MANUF:
915 rc = abis_nm_rcvmsg_manuf(msg);
916 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000917 case ABIS_OM_MDISC_MMI:
918 case ABIS_OM_MDISC_TRAU:
Harald Welte677c21f2009-02-17 13:22:23 +0000919 fprintf(stderr, "unimplemented ABIS OML message discriminator 0x%x\n",
920 oh->mdisc);
921 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000922 default:
923 fprintf(stderr, "unknown ABIS OML message discriminator 0x%x\n",
924 oh->mdisc);
925 return -EINVAL;
926 }
927
Harald Weltead384642008-12-26 10:20:07 +0000928 msgb_free(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000929 return rc;
930}
931
932#if 0
933/* initialized all resources */
934struct abis_nm_h *abis_nm_init(struct abis_nm_cfg *cfg)
935{
936 struct abis_nm_h *nmh;
937
938 nmh = malloc(sizeof(*nmh));
939 if (!nmh)
940 return NULL;
941
942 nmh->cfg = cfg;
943
944 return nmh;
945}
946
947/* free all resources */
948void abis_nm_fini(struct abis_nm_h *nmh)
949{
950 free(nmh);
951}
952#endif
953
954/* Here we are trying to define a high-level API that can be used by
955 * the actual BSC implementation. However, the architecture is currently
956 * still under design. Ideally the calls to this API would be synchronous,
957 * while the underlying stack behind the APi runs in a traditional select
958 * based state machine.
959 */
960
Harald Welte4724f992009-01-18 18:01:49 +0000961/* 6.2 Software Load: */
962enum sw_state {
963 SW_STATE_NONE,
964 SW_STATE_WAIT_INITACK,
965 SW_STATE_WAIT_SEGACK,
966 SW_STATE_WAIT_ENDACK,
967 SW_STATE_WAIT_ACTACK,
968 SW_STATE_ERROR,
969};
Harald Welte52b1f982008-12-23 20:25:15 +0000970
Harald Welte52b1f982008-12-23 20:25:15 +0000971struct abis_nm_sw {
Harald Welte4724f992009-01-18 18:01:49 +0000972 struct gsm_bts *bts;
Harald Welte5e4d1b32009-02-01 13:36:56 +0000973 gsm_cbfn *cbfn;
974 void *cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +0000975 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +0000976
Harald Welte52b1f982008-12-23 20:25:15 +0000977 /* this will become part of the SW LOAD INITIATE */
978 u_int8_t obj_class;
979 u_int8_t obj_instance[3];
Harald Welte4724f992009-01-18 18:01:49 +0000980
981 u_int8_t file_id[255];
982 u_int8_t file_id_len;
983
984 u_int8_t file_version[255];
985 u_int8_t file_version_len;
986
987 u_int8_t window_size;
988 u_int8_t seg_in_window;
989
990 int fd;
991 FILE *stream;
992 enum sw_state state;
Harald Welte1602ade2009-01-29 21:12:39 +0000993 int last_seg;
Harald Welte52b1f982008-12-23 20:25:15 +0000994};
995
Harald Welte4724f992009-01-18 18:01:49 +0000996static struct abis_nm_sw g_sw;
997
998/* 6.2.1 / 8.3.1: Load Data Initiate */
999static int sw_load_init(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +00001000{
Harald Welte4724f992009-01-18 18:01:49 +00001001 struct abis_om_hdr *oh;
1002 struct msgb *msg = nm_msgb_alloc();
1003 u_int8_t len = 3*2 + sw->file_id_len + sw->file_version_len;
1004
1005 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1006 fill_om_fom_hdr(oh, len, NM_MT_LOAD_INIT, sw->obj_class,
1007 sw->obj_instance[0], sw->obj_instance[1],
1008 sw->obj_instance[2]);
1009
1010 /* FIXME: this is BS11 specific format */
1011 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1012 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1013 sw->file_version);
1014 msgb_tv_put(msg, NM_ATT_WINDOW_SIZE, sw->window_size);
1015
1016 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001017}
1018
Harald Welte1602ade2009-01-29 21:12:39 +00001019static int is_last_line(FILE *stream)
1020{
1021 char next_seg_buf[256];
1022 long pos;
1023
1024 /* check if we're sending the last line */
1025 pos = ftell(stream);
1026 if (!fgets(next_seg_buf, sizeof(next_seg_buf)-2, stream)) {
1027 fseek(stream, pos, SEEK_SET);
1028 return 1;
1029 }
1030
1031 fseek(stream, pos, SEEK_SET);
1032 return 0;
1033}
1034
Harald Welte4724f992009-01-18 18:01:49 +00001035/* 6.2.2 / 8.3.2 Load Data Segment */
1036static int sw_load_segment(struct abis_nm_sw *sw)
1037{
1038 struct abis_om_hdr *oh;
1039 struct msgb *msg = nm_msgb_alloc();
1040 char seg_buf[256];
1041 char *line_buf = seg_buf+2;
Harald Welte3b8ba212009-01-29 12:27:58 +00001042 unsigned char *tlv;
Harald Welte4724f992009-01-18 18:01:49 +00001043 u_int8_t len;
Harald Welte4724f992009-01-18 18:01:49 +00001044
1045 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte3b8ba212009-01-29 12:27:58 +00001046
1047 switch (sw->bts->type) {
1048 case GSM_BTS_TYPE_BS11:
1049 if (fgets(line_buf, sizeof(seg_buf)-2, sw->stream) == NULL) {
1050 perror("fgets reading segment");
1051 return -EINVAL;
1052 }
1053 seg_buf[0] = 0x00;
Harald Welte1602ade2009-01-29 21:12:39 +00001054
1055 /* check if we're sending the last line */
1056 sw->last_seg = is_last_line(sw->stream);
1057 if (sw->last_seg)
1058 seg_buf[1] = 0;
1059 else
1060 seg_buf[1] = 1 + sw->seg_in_window++;
Harald Welte3b8ba212009-01-29 12:27:58 +00001061
1062 len = strlen(line_buf) + 2;
1063 tlv = msgb_put(msg, TLV_GROSS_LEN(len));
1064 tlv_put(tlv, NM_ATT_BS11_FILE_DATA, len, (u_int8_t *)seg_buf);
1065 /* BS11 wants CR + LF in excess of the TLV length !?! */
1066 tlv[1] -= 2;
1067
1068 /* we only now know the exact length for the OM hdr */
1069 len = strlen(line_buf)+2;
1070 break;
1071 default:
1072 /* FIXME: Other BTS types */
1073 return -1;
Harald Welte4724f992009-01-18 18:01:49 +00001074 }
Harald Welte4724f992009-01-18 18:01:49 +00001075
Harald Welte4724f992009-01-18 18:01:49 +00001076 fill_om_fom_hdr(oh, len, NM_MT_LOAD_SEG, sw->obj_class,
1077 sw->obj_instance[0], sw->obj_instance[1],
1078 sw->obj_instance[2]);
1079
1080 return abis_nm_sendmsg(sw->bts, msg);
1081}
1082
1083/* 6.2.4 / 8.3.4 Load Data End */
1084static int sw_load_end(struct abis_nm_sw *sw)
1085{
1086 struct abis_om_hdr *oh;
1087 struct msgb *msg = nm_msgb_alloc();
1088 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
1089
1090 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1091 fill_om_fom_hdr(oh, len, NM_MT_LOAD_END, sw->obj_class,
1092 sw->obj_instance[0], sw->obj_instance[1],
1093 sw->obj_instance[2]);
1094
1095 /* FIXME: this is BS11 specific format */
1096 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1097 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1098 sw->file_version);
1099
1100 return abis_nm_sendmsg(sw->bts, msg);
1101}
Harald Welte5e4d1b32009-02-01 13:36:56 +00001102
Harald Welte52b1f982008-12-23 20:25:15 +00001103/* Activate the specified software into the BTS */
Harald Welte4724f992009-01-18 18:01:49 +00001104static int sw_activate(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +00001105{
Harald Welte4724f992009-01-18 18:01:49 +00001106 struct abis_om_hdr *oh;
1107 struct msgb *msg = nm_msgb_alloc();
1108 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
Harald Welte52b1f982008-12-23 20:25:15 +00001109
Harald Welte4724f992009-01-18 18:01:49 +00001110 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1111 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, sw->obj_class,
1112 sw->obj_instance[0], sw->obj_instance[1],
1113 sw->obj_instance[2]);
1114
1115 /* FIXME: this is BS11 specific format */
1116 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1117 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1118 sw->file_version);
1119
1120 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001121}
Harald Welte4724f992009-01-18 18:01:49 +00001122
1123static int sw_open_file(struct abis_nm_sw *sw, const char *fname)
1124{
1125 char file_id[12+1];
1126 char file_version[80+1];
1127 int rc;
1128
1129 sw->fd = open(fname, O_RDONLY);
1130 if (sw->fd < 0)
1131 return sw->fd;
1132
1133 switch (sw->bts->type) {
1134 case GSM_BTS_TYPE_BS11:
1135 sw->stream = fdopen(sw->fd, "r");
1136 if (!sw->stream) {
1137 perror("fdopen");
1138 return -1;
1139 }
1140 /* read first line and parse file ID and VERSION */
Harald Welte3b8ba212009-01-29 12:27:58 +00001141 rc = fscanf(sw->stream, "@(#)%12s:%80s\r\n",
Harald Welte4724f992009-01-18 18:01:49 +00001142 file_id, file_version);
1143 if (rc != 2) {
1144 perror("parsing header line of software file");
1145 return -1;
1146 }
1147 strcpy((char *)sw->file_id, file_id);
1148 sw->file_id_len = strlen(file_id);
1149 strcpy((char *)sw->file_version, file_version);
1150 sw->file_version_len = strlen(file_version);
1151 /* rewind to start of file */
Harald Welte3b8ba212009-01-29 12:27:58 +00001152 rewind(sw->stream);
Harald Welte4724f992009-01-18 18:01:49 +00001153 break;
1154 default:
1155 /* We don't know how to treat them yet */
1156 close(sw->fd);
1157 return -EINVAL;
1158 }
1159
1160 return 0;
1161}
1162
1163static void sw_close_file(struct abis_nm_sw *sw)
1164{
1165 switch (sw->bts->type) {
1166 case GSM_BTS_TYPE_BS11:
1167 fclose(sw->stream);
1168 break;
1169 default:
1170 close(sw->fd);
1171 break;
1172 }
1173}
1174
1175/* Fill the window */
1176static int sw_fill_window(struct abis_nm_sw *sw)
1177{
1178 int rc;
1179
1180 while (sw->seg_in_window < sw->window_size) {
1181 rc = sw_load_segment(sw);
1182 if (rc < 0)
1183 return rc;
Harald Welte1602ade2009-01-29 21:12:39 +00001184 if (sw->last_seg)
1185 break;
Harald Welte4724f992009-01-18 18:01:49 +00001186 }
1187 return 0;
1188}
1189
1190/* callback function from abis_nm_rcvmsg() handler */
1191static int abis_nm_rcvmsg_sw(struct msgb *mb)
1192{
1193 struct abis_om_fom_hdr *foh = msgb_l3(mb);
1194 int rc = -1;
1195 struct abis_nm_sw *sw = &g_sw;
1196 enum sw_state old_state = sw->state;
1197
Harald Welte3ffd1372009-02-01 22:15:49 +00001198 //DEBUGP(DNM, "state %u, NM MT 0x%02x\n", sw->state, foh->msg_type);
Harald Welte4724f992009-01-18 18:01:49 +00001199
1200 switch (sw->state) {
1201 case SW_STATE_WAIT_INITACK:
1202 switch (foh->msg_type) {
1203 case NM_MT_LOAD_INIT_ACK:
1204 /* fill window with segments */
Harald Welte5e4d1b32009-02-01 13:36:56 +00001205 if (sw->cbfn)
1206 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1207 NM_MT_LOAD_INIT_ACK, mb,
1208 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001209 rc = sw_fill_window(sw);
1210 sw->state = SW_STATE_WAIT_SEGACK;
1211 break;
1212 case NM_MT_LOAD_INIT_NACK:
Harald Welte3ffd1372009-02-01 22:15:49 +00001213 if (sw->forced) {
1214 DEBUGP(DNM, "FORCED: Ignoring Software Load "
1215 "Init NACK\n");
1216 if (sw->cbfn)
1217 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1218 NM_MT_LOAD_INIT_ACK, mb,
1219 sw->cb_data, NULL);
1220 rc = sw_fill_window(sw);
1221 sw->state = SW_STATE_WAIT_SEGACK;
1222 } else {
1223 DEBUGP(DNM, "Software Load Init NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001224 /* FIXME: cause */
Harald Welte3ffd1372009-02-01 22:15:49 +00001225 if (sw->cbfn)
1226 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1227 NM_MT_LOAD_INIT_NACK, mb,
1228 sw->cb_data, NULL);
1229 sw->state = SW_STATE_ERROR;
1230 }
Harald Welte4724f992009-01-18 18:01:49 +00001231 break;
1232 }
1233 break;
1234 case SW_STATE_WAIT_SEGACK:
1235 switch (foh->msg_type) {
1236 case NM_MT_LOAD_SEG_ACK:
Harald Welte3ffd1372009-02-01 22:15:49 +00001237 if (sw->cbfn)
1238 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1239 NM_MT_LOAD_SEG_ACK, mb,
1240 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001241 sw->seg_in_window = 0;
Harald Welte1602ade2009-01-29 21:12:39 +00001242 if (!sw->last_seg) {
1243 /* fill window with more segments */
1244 rc = sw_fill_window(sw);
1245 sw->state = SW_STATE_WAIT_SEGACK;
1246 } else {
1247 /* end the transfer */
1248 sw->state = SW_STATE_WAIT_ENDACK;
1249 rc = sw_load_end(sw);
1250 }
Harald Welte4724f992009-01-18 18:01:49 +00001251 break;
1252 }
1253 break;
1254 case SW_STATE_WAIT_ENDACK:
1255 switch (foh->msg_type) {
1256 case NM_MT_LOAD_END_ACK:
1257 sw_close_file(sw);
Harald Welte5e4d1b32009-02-01 13:36:56 +00001258 DEBUGP(DNM, "Software Load End (BTS %u)\n",
1259 sw->bts->nr);
1260 sw->state = SW_STATE_NONE;
1261 if (sw->cbfn)
1262 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1263 NM_MT_LOAD_END_ACK, mb,
1264 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001265 break;
1266 case NM_MT_LOAD_END_NACK:
Holger Freyther31338a12009-02-06 17:43:50 +00001267 if (sw->forced) {
1268 DEBUGP(DNM, "FORCED: Ignoring Software Load"
1269 "End NACK\n");
1270 sw->state = SW_STATE_NONE;
1271 if (sw->cbfn)
1272 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1273 NM_MT_LOAD_END_ACK, mb,
1274 sw->cb_data, NULL);
1275 } else {
1276 DEBUGP(DNM, "Software Load End NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001277 /* FIXME: cause */
Holger Freyther31338a12009-02-06 17:43:50 +00001278 sw->state = SW_STATE_ERROR;
1279 if (sw->cbfn)
1280 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1281 NM_MT_LOAD_END_NACK, mb,
1282 sw->cb_data, NULL);
1283 }
Harald Welte4724f992009-01-18 18:01:49 +00001284 break;
1285 }
1286 case SW_STATE_WAIT_ACTACK:
1287 switch (foh->msg_type) {
1288 case NM_MT_ACTIVATE_SW_ACK:
1289 /* we're done */
Harald Welte5e4d1b32009-02-01 13:36:56 +00001290 DEBUGP(DNM, "Activate Software DONE!\n");
Harald Welte4724f992009-01-18 18:01:49 +00001291 sw->state = SW_STATE_NONE;
1292 rc = 0;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001293 if (sw->cbfn)
1294 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1295 NM_MT_ACTIVATE_SW_ACK, mb,
1296 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001297 break;
1298 case NM_MT_ACTIVATE_SW_NACK:
Harald Welte1602ade2009-01-29 21:12:39 +00001299 DEBUGP(DNM, "Activate Software NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001300 /* FIXME: cause */
Harald Welte4724f992009-01-18 18:01:49 +00001301 sw->state = SW_STATE_ERROR;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001302 if (sw->cbfn)
1303 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1304 NM_MT_ACTIVATE_SW_NACK, mb,
1305 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001306 break;
1307 }
1308 case SW_STATE_NONE:
Harald Weltea994a482009-05-01 15:54:23 +00001309 switch (foh->msg_type) {
1310 case NM_MT_ACTIVATE_SW_ACK:
1311 rc = 0;
1312 break;
1313 }
1314 break;
Harald Welte4724f992009-01-18 18:01:49 +00001315 case SW_STATE_ERROR:
1316 break;
1317 }
1318
1319 if (rc)
Harald Weltea994a482009-05-01 15:54:23 +00001320 DEBUGP(DNM, "unexpected NM MT 0x%02x in state %u -> %u\n",
Harald Welte4724f992009-01-18 18:01:49 +00001321 foh->msg_type, old_state, sw->state);
1322
1323 return rc;
1324}
1325
1326/* Load the specified software into the BTS */
1327int abis_nm_software_load(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00001328 u_int8_t win_size, int forced,
1329 gsm_cbfn *cbfn, void *cb_data)
Harald Welte4724f992009-01-18 18:01:49 +00001330{
1331 struct abis_nm_sw *sw = &g_sw;
1332 int rc;
1333
Harald Welte5e4d1b32009-02-01 13:36:56 +00001334 DEBUGP(DNM, "Software Load (BTS %u, File \"%s\")\n",
1335 bts->nr, fname);
1336
Harald Welte4724f992009-01-18 18:01:49 +00001337 if (sw->state != SW_STATE_NONE)
1338 return -EBUSY;
1339
1340 sw->bts = bts;
1341 sw->obj_class = NM_OC_SITE_MANAGER;
1342 sw->obj_instance[0] = 0xff;
1343 sw->obj_instance[1] = 0xff;
1344 sw->obj_instance[2] = 0xff;
1345 sw->window_size = win_size;
1346 sw->state = SW_STATE_WAIT_INITACK;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001347 sw->cbfn = cbfn;
1348 sw->cb_data = cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +00001349 sw->forced = forced;
Harald Welte4724f992009-01-18 18:01:49 +00001350
1351 rc = sw_open_file(sw, fname);
1352 if (rc < 0) {
1353 sw->state = SW_STATE_NONE;
1354 return rc;
1355 }
1356
1357 return sw_load_init(sw);
1358}
Harald Welte52b1f982008-12-23 20:25:15 +00001359
Harald Welte1602ade2009-01-29 21:12:39 +00001360int abis_nm_software_load_status(struct gsm_bts *bts)
1361{
1362 struct abis_nm_sw *sw = &g_sw;
1363 struct stat st;
1364 int rc, percent;
1365
1366 rc = fstat(sw->fd, &st);
1367 if (rc < 0) {
1368 perror("ERROR during stat");
1369 return rc;
1370 }
1371
1372 percent = (ftell(sw->stream) * 100) / st.st_size;
1373 return percent;
1374}
1375
Harald Welte5e4d1b32009-02-01 13:36:56 +00001376/* Activate the specified software into the BTS */
1377int abis_nm_software_activate(struct gsm_bts *bts, const char *fname,
1378 gsm_cbfn *cbfn, void *cb_data)
1379{
1380 struct abis_nm_sw *sw = &g_sw;
1381 int rc;
1382
1383 DEBUGP(DNM, "Activating Software (BTS %u, File \"%s\")\n",
1384 bts->nr, fname);
1385
1386 if (sw->state != SW_STATE_NONE)
1387 return -EBUSY;
1388
1389 sw->bts = bts;
1390 sw->obj_class = NM_OC_SITE_MANAGER;
1391 sw->obj_instance[0] = 0xff;
1392 sw->obj_instance[1] = 0xff;
1393 sw->obj_instance[2] = 0xff;
1394 sw->state = SW_STATE_WAIT_ACTACK;
1395 sw->cbfn = cbfn;
1396 sw->cb_data = cb_data;
1397
1398 /* Open the file in order to fill some sw struct members */
1399 rc = sw_open_file(sw, fname);
1400 if (rc < 0) {
1401 sw->state = SW_STATE_NONE;
1402 return rc;
1403 }
1404 sw_close_file(sw);
1405
1406 return sw_activate(sw);
1407}
1408
Harald Welte8470bf22008-12-25 23:28:35 +00001409static void fill_nm_channel(struct abis_nm_channel *ch, u_int8_t bts_port,
Harald Welte52b1f982008-12-23 20:25:15 +00001410 u_int8_t ts_nr, u_int8_t subslot_nr)
1411{
Harald Welteadaf08b2009-01-18 11:08:10 +00001412 ch->attrib = NM_ATT_ABIS_CHANNEL;
Harald Welte52b1f982008-12-23 20:25:15 +00001413 ch->bts_port = bts_port;
1414 ch->timeslot = ts_nr;
1415 ch->subslot = subslot_nr;
1416}
1417
1418int abis_nm_establish_tei(struct gsm_bts *bts, u_int8_t trx_nr,
1419 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot,
1420 u_int8_t tei)
1421{
1422 struct abis_om_hdr *oh;
1423 struct abis_nm_channel *ch;
Harald Welte702d8702008-12-26 20:25:35 +00001424 u_int8_t len = sizeof(*ch) + 2;
Harald Welte8470bf22008-12-25 23:28:35 +00001425 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001426
1427 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1428 fill_om_fom_hdr(oh, len, NM_MT_ESTABLISH_TEI, NM_OC_RADIO_CARRIER,
1429 bts->bts_nr, trx_nr, 0xff);
1430
Harald Welte8470bf22008-12-25 23:28:35 +00001431 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte52b1f982008-12-23 20:25:15 +00001432
1433 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1434 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1435
1436 return abis_nm_sendmsg(bts, msg);
1437}
1438
1439/* connect signalling of one (BTS,TRX) to a particular timeslot on the E1 */
1440int abis_nm_conn_terr_sign(struct gsm_bts_trx *trx,
1441 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot)
1442{
Harald Welte8470bf22008-12-25 23:28:35 +00001443 struct gsm_bts *bts = trx->bts;
Harald Welte52b1f982008-12-23 20:25:15 +00001444 struct abis_om_hdr *oh;
1445 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +00001446 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001447
1448 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001449 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_SIGN,
Harald Welte52b1f982008-12-23 20:25:15 +00001450 NM_OC_RADIO_CARRIER, bts->bts_nr, trx->nr, 0xff);
1451
1452 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1453 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1454
1455 return abis_nm_sendmsg(bts, msg);
1456}
1457
1458#if 0
1459int abis_nm_disc_terr_sign(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1460 struct abis_nm_abis_channel *chan)
1461{
1462}
1463#endif
1464
1465int abis_nm_conn_terr_traf(struct gsm_bts_trx_ts *ts,
1466 u_int8_t e1_port, u_int8_t e1_timeslot,
1467 u_int8_t e1_subslot)
1468{
1469 struct gsm_bts *bts = ts->trx->bts;
1470 struct abis_om_hdr *oh;
1471 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +00001472 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001473
1474 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1475 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_TRAF,
Harald Welteb110cee2009-02-18 03:42:35 +00001476 NM_OC_CHANNEL, bts->bts_nr, ts->trx->nr, ts->nr);
Harald Welte52b1f982008-12-23 20:25:15 +00001477
1478 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1479 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1480
Harald Weltef325eb42009-02-19 17:07:39 +00001481 DEBUGP(DNM, "CONNECT TERR TRAF Um=%s E1=(%u,%u,%u)\n",
1482 gsm_ts_name(ts),
Harald Welteb110cee2009-02-18 03:42:35 +00001483 e1_port, e1_timeslot, e1_subslot);
1484
Harald Welte52b1f982008-12-23 20:25:15 +00001485 return abis_nm_sendmsg(bts, msg);
1486}
1487
1488#if 0
1489int abis_nm_disc_terr_traf(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1490 struct abis_nm_abis_channel *chan,
1491 u_int8_t subchan)
1492{
1493}
1494#endif
1495
Harald Welte22af0db2009-02-14 15:41:08 +00001496/* Chapter 8.6.1 */
1497int abis_nm_set_bts_attr(struct gsm_bts *bts, u_int8_t *attr, int attr_len)
1498{
1499 struct abis_om_hdr *oh;
1500 struct msgb *msg = nm_msgb_alloc();
1501 u_int8_t *cur;
1502
1503 DEBUGP(DNM, "Set BTS Attr (bts=%d)\n", bts->nr);
1504
1505 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte191280d2009-05-01 13:20:04 +00001506 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 +00001507 cur = msgb_put(msg, attr_len);
1508 memcpy(cur, attr, attr_len);
1509
1510 return abis_nm_sendmsg(bts, msg);
1511}
1512
1513/* Chapter 8.6.2 */
1514int abis_nm_set_radio_attr(struct gsm_bts_trx *trx, u_int8_t *attr, int attr_len)
1515{
1516 struct abis_om_hdr *oh;
1517 struct msgb *msg = nm_msgb_alloc();
1518 u_int8_t *cur;
1519
1520 DEBUGP(DNM, "Set TRX Attr (bts=%d,trx=%d)\n", trx->bts->nr, trx->nr);
1521
1522 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1523 fill_om_fom_hdr(oh, attr_len, NM_MT_SET_RADIO_ATTR, NM_OC_RADIO_CARRIER,
Harald Welte191280d2009-05-01 13:20:04 +00001524 trx->bts->bts_nr, trx->nr, 0xff);
Harald Welte22af0db2009-02-14 15:41:08 +00001525 cur = msgb_put(msg, attr_len);
1526 memcpy(cur, attr, attr_len);
1527
1528 return abis_nm_sendmsg(trx->bts, msg);
1529}
1530
1531/* Chapter 8.6.3 */
Harald Welte52b1f982008-12-23 20:25:15 +00001532int abis_nm_set_channel_attr(struct gsm_bts_trx_ts *ts, u_int8_t chan_comb)
1533{
1534 struct gsm_bts *bts = ts->trx->bts;
1535 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001536 u_int16_t arfcn = htons(ts->trx->arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001537 u_int8_t zero = 0x00;
Harald Welte8470bf22008-12-25 23:28:35 +00001538 struct msgb *msg = nm_msgb_alloc();
Harald Weltee0590df2009-02-15 03:34:15 +00001539 u_int8_t len = 2 + 2;
1540
1541 if (bts->type == GSM_BTS_TYPE_BS11)
1542 len += 4 + 2 + 2 + 3;
Harald Welte52b1f982008-12-23 20:25:15 +00001543
Harald Weltef325eb42009-02-19 17:07:39 +00001544 DEBUGP(DNM, "Set Chan Attr %s\n", gsm_ts_name(ts));
Harald Welte22af0db2009-02-14 15:41:08 +00001545
Harald Welte52b1f982008-12-23 20:25:15 +00001546 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001547 fill_om_fom_hdr(oh, len, NM_MT_SET_CHAN_ATTR,
Holger Freyther6b2d2622009-02-14 23:16:59 +00001548 NM_OC_CHANNEL, bts->bts_nr,
Harald Welte52b1f982008-12-23 20:25:15 +00001549 ts->trx->nr, ts->nr);
1550 /* FIXME: don't send ARFCN list, hopping sequence, mAIO, ...*/
Harald Weltee0590df2009-02-15 03:34:15 +00001551 if (bts->type == GSM_BTS_TYPE_BS11)
1552 msgb_tlv16_put(msg, NM_ATT_ARFCN_LIST, 1, &arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001553 msgb_tv_put(msg, NM_ATT_CHAN_COMB, chan_comb);
Harald Weltee0590df2009-02-15 03:34:15 +00001554 if (bts->type == GSM_BTS_TYPE_BS11) {
1555 msgb_tv_put(msg, NM_ATT_HSN, 0x00);
1556 msgb_tv_put(msg, NM_ATT_MAIO, 0x00);
1557 }
Harald Welte52b1f982008-12-23 20:25:15 +00001558 msgb_tv_put(msg, NM_ATT_TSC, 0x07); /* training sequence */
Harald Weltee0590df2009-02-15 03:34:15 +00001559 if (bts->type == GSM_BTS_TYPE_BS11)
1560 msgb_tlv_put(msg, 0x59, 1, &zero);
Harald Welte52b1f982008-12-23 20:25:15 +00001561
1562 return abis_nm_sendmsg(bts, msg);
1563}
1564
Harald Welte34a99682009-02-13 02:41:40 +00001565int 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 +00001566 u_int8_t i2, u_int8_t i3, int nack, u_int8_t *attr, int att_len)
Harald Welte34a99682009-02-13 02:41:40 +00001567{
1568 struct abis_om_hdr *oh;
1569 struct msgb *msg = nm_msgb_alloc();
Harald Welte5c1e4582009-02-15 11:57:29 +00001570 u_int8_t msgtype = NM_MT_SW_ACT_REQ_ACK;
1571 u_int8_t len = att_len;
1572
1573 if (nack) {
1574 len += 2;
1575 msgtype = NM_MT_SW_ACT_REQ_NACK;
1576 }
Harald Welte34a99682009-02-13 02:41:40 +00001577
1578 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte5c1e4582009-02-15 11:57:29 +00001579 fill_om_fom_hdr(oh, att_len, msgtype, obj_class, i1, i2, i3);
1580
Harald Welte34a99682009-02-13 02:41:40 +00001581 if (attr) {
1582 u_int8_t *ptr = msgb_put(msg, att_len);
1583 memcpy(ptr, attr, att_len);
1584 }
Harald Welte5c1e4582009-02-15 11:57:29 +00001585 if (nack)
1586 msgb_tv_put(msg, NM_ATT_NACK_CAUSES, NM_NACK_OBJCLASS_NOTSUPP);
Harald Welte34a99682009-02-13 02:41:40 +00001587
1588 return abis_nm_sendmsg(bts, msg);
1589}
1590
Harald Welte8470bf22008-12-25 23:28:35 +00001591int abis_nm_raw_msg(struct gsm_bts *bts, int len, u_int8_t *rawmsg)
Harald Welte52b1f982008-12-23 20:25:15 +00001592{
Harald Welte8470bf22008-12-25 23:28:35 +00001593 struct msgb *msg = nm_msgb_alloc();
1594 struct abis_om_hdr *oh;
Harald Welte52b1f982008-12-23 20:25:15 +00001595 u_int8_t *data;
1596
1597 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
1598 fill_om_hdr(oh, len);
1599 data = msgb_put(msg, len);
Harald Weltead384642008-12-26 10:20:07 +00001600 memcpy(data, rawmsg, len);
Harald Welte52b1f982008-12-23 20:25:15 +00001601
1602 return abis_nm_sendmsg(bts, msg);
1603}
1604
1605/* Siemens specific commands */
1606static int __simple_cmd(struct gsm_bts *bts, u_int8_t msg_type)
1607{
1608 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001609 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001610
1611 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001612 fill_om_fom_hdr(oh, 0, msg_type, NM_OC_SITE_MANAGER,
Harald Welte52b1f982008-12-23 20:25:15 +00001613 0xff, 0xff, 0xff);
1614
1615 return abis_nm_sendmsg(bts, msg);
1616}
1617
Harald Welte34a99682009-02-13 02:41:40 +00001618/* Chapter 8.9.2 */
1619int abis_nm_opstart(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1, u_int8_t i2)
1620{
1621 struct abis_om_hdr *oh;
1622 struct msgb *msg = nm_msgb_alloc();
1623
Harald Welte22af0db2009-02-14 15:41:08 +00001624 DEBUGP(DNM, "Sending OPSTART obj_class=0x%02x obj_inst=(0x%02x, 0x%02x, 0x%02x)\n",
1625 obj_class, i0, i1, i2);
Harald Welte34a99682009-02-13 02:41:40 +00001626 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1627 fill_om_fom_hdr(oh, 0, NM_MT_OPSTART, obj_class, i0, i1, i2);
1628
1629 return abis_nm_sendmsg(bts, msg);
1630}
1631
1632/* Chapter 8.8.5 */
1633int abis_nm_chg_adm_state(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0,
1634 u_int8_t i1, u_int8_t i2, u_int8_t adm_state)
1635{
1636 struct abis_om_hdr *oh;
1637 struct msgb *msg = nm_msgb_alloc();
1638
1639 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1640 fill_om_fom_hdr(oh, 2, NM_MT_CHG_ADM_STATE, obj_class, i0, i1, i2);
1641 msgb_tv_put(msg, NM_ATT_ADM_STATE, adm_state);
1642
1643 return abis_nm_sendmsg(bts, msg);
1644}
1645
1646
Harald Welte52b1f982008-12-23 20:25:15 +00001647int abis_nm_event_reports(struct gsm_bts *bts, int on)
1648{
1649 if (on == 0)
Harald Welte227d4072009-01-03 08:16:25 +00001650 return __simple_cmd(bts, NM_MT_STOP_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001651 else
Harald Welte227d4072009-01-03 08:16:25 +00001652 return __simple_cmd(bts, NM_MT_REST_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001653}
1654
Harald Welte47d88ae2009-01-04 12:02:08 +00001655/* Siemens (or BS-11) specific commands */
1656
Harald Welte3ffd1372009-02-01 22:15:49 +00001657int abis_nm_bs11_bsc_disconnect(struct gsm_bts *bts, int reconnect)
1658{
1659 if (reconnect == 0)
1660 return __simple_cmd(bts, NM_MT_BS11_DISCONNECT);
1661 else
1662 return __simple_cmd(bts, NM_MT_BS11_RECONNECT);
1663}
1664
Harald Welteb8427972009-02-05 19:27:17 +00001665int abis_nm_bs11_restart(struct gsm_bts *bts)
1666{
1667 return __simple_cmd(bts, NM_MT_BS11_RESTART);
1668}
1669
1670
Harald Welte268bb402009-02-01 19:11:56 +00001671struct bs11_date_time {
1672 u_int16_t year;
1673 u_int8_t month;
1674 u_int8_t day;
1675 u_int8_t hour;
1676 u_int8_t min;
1677 u_int8_t sec;
1678} __attribute__((packed));
1679
1680
1681void get_bs11_date_time(struct bs11_date_time *aet)
1682{
1683 time_t t;
1684 struct tm *tm;
1685
1686 t = time(NULL);
1687 tm = localtime(&t);
1688 aet->sec = tm->tm_sec;
1689 aet->min = tm->tm_min;
1690 aet->hour = tm->tm_hour;
1691 aet->day = tm->tm_mday;
1692 aet->month = tm->tm_mon;
1693 aet->year = htons(1900 + tm->tm_year);
1694}
1695
Harald Welte05188ee2009-01-18 11:39:08 +00001696int abis_nm_bs11_reset_resource(struct gsm_bts *bts)
Harald Welte52b1f982008-12-23 20:25:15 +00001697{
Harald Welte4668fda2009-01-03 08:19:29 +00001698 return __simple_cmd(bts, NM_MT_BS11_RESET_RESOURCE);
Harald Welte52b1f982008-12-23 20:25:15 +00001699}
1700
Harald Welte05188ee2009-01-18 11:39:08 +00001701int abis_nm_bs11_db_transmission(struct gsm_bts *bts, int begin)
Harald Welte52b1f982008-12-23 20:25:15 +00001702{
1703 if (begin)
Harald Welte4668fda2009-01-03 08:19:29 +00001704 return __simple_cmd(bts, NM_MT_BS11_BEGIN_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00001705 else
Harald Welte4668fda2009-01-03 08:19:29 +00001706 return __simple_cmd(bts, NM_MT_BS11_END_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00001707}
Harald Welte47d88ae2009-01-04 12:02:08 +00001708
Harald Welte05188ee2009-01-18 11:39:08 +00001709int abis_nm_bs11_create_object(struct gsm_bts *bts,
Harald Welte1bc09062009-01-18 14:17:52 +00001710 enum abis_bs11_objtype type, u_int8_t idx,
1711 u_int8_t attr_len, const u_int8_t *attr)
Harald Welte47d88ae2009-01-04 12:02:08 +00001712{
1713 struct abis_om_hdr *oh;
1714 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00001715 u_int8_t *cur;
Harald Welte47d88ae2009-01-04 12:02:08 +00001716
1717 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001718 fill_om_fom_hdr(oh, attr_len, NM_MT_BS11_CREATE_OBJ,
Harald Welte268bb402009-02-01 19:11:56 +00001719 NM_OC_BS11, type, 0, idx);
Harald Welte1bc09062009-01-18 14:17:52 +00001720 cur = msgb_put(msg, attr_len);
1721 memcpy(cur, attr, attr_len);
Harald Welte47d88ae2009-01-04 12:02:08 +00001722
1723 return abis_nm_sendmsg(bts, msg);
1724}
1725
Harald Welte78fc0d42009-02-19 02:50:57 +00001726int abis_nm_bs11_delete_object(struct gsm_bts *bts,
1727 enum abis_bs11_objtype type, u_int8_t idx)
1728{
1729 struct abis_om_hdr *oh;
1730 struct msgb *msg = nm_msgb_alloc();
1731
1732 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1733 fill_om_fom_hdr(oh, 0, NM_MT_BS11_DELETE_OBJ,
1734 NM_OC_BS11, type, 0, idx);
1735
1736 return abis_nm_sendmsg(bts, msg);
1737}
1738
Harald Welte05188ee2009-01-18 11:39:08 +00001739int abis_nm_bs11_create_envaBTSE(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00001740{
1741 struct abis_om_hdr *oh;
1742 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00001743 u_int8_t zero = 0x00;
Harald Welte47d88ae2009-01-04 12:02:08 +00001744
1745 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001746 fill_om_fom_hdr(oh, 3, NM_MT_BS11_CREATE_OBJ,
Harald Welte1bc09062009-01-18 14:17:52 +00001747 NM_OC_BS11_ENVABTSE, 0, idx, 0xff);
1748 msgb_tlv_put(msg, 0x99, 1, &zero);
Harald Welte47d88ae2009-01-04 12:02:08 +00001749
1750 return abis_nm_sendmsg(bts, msg);
1751}
1752
Harald Welte05188ee2009-01-18 11:39:08 +00001753int abis_nm_bs11_create_bport(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00001754{
1755 struct abis_om_hdr *oh;
1756 struct msgb *msg = nm_msgb_alloc();
1757
1758 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1759 fill_om_fom_hdr(oh, 0, NM_MT_BS11_CREATE_OBJ, NM_OC_BS11_BPORT,
1760 idx, 0, 0);
1761
1762 return abis_nm_sendmsg(bts, msg);
1763}
Harald Welte05188ee2009-01-18 11:39:08 +00001764
Harald Welte78fc0d42009-02-19 02:50:57 +00001765static const u_int8_t sm_attr[] = { NM_ATT_TEI, NM_ATT_ABIS_CHANNEL };
1766int abis_nm_bs11_get_oml_tei_ts(struct gsm_bts *bts)
1767{
1768 struct abis_om_hdr *oh;
1769 struct msgb *msg = nm_msgb_alloc();
1770
1771 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1772 fill_om_fom_hdr(oh, 2+sizeof(sm_attr), NM_MT_GET_ATTR, NM_OC_SITE_MANAGER,
1773 0xff, 0xff, 0xff);
1774 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(sm_attr), sm_attr);
1775
1776 return abis_nm_sendmsg(bts, msg);
1777}
1778
Harald Welteb6c92ae2009-02-21 20:15:32 +00001779/* like abis_nm_conn_terr_traf + set_tei */
1780int abis_nm_bs11_conn_oml_tei(struct gsm_bts *bts, u_int8_t e1_port,
1781 u_int8_t e1_timeslot, u_int8_t e1_subslot,
1782 u_int8_t tei)
Harald Welte05188ee2009-01-18 11:39:08 +00001783{
1784 struct abis_om_hdr *oh;
1785 struct abis_nm_channel *ch;
1786 struct msgb *msg = nm_msgb_alloc();
1787
1788 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welteb6c92ae2009-02-21 20:15:32 +00001789 fill_om_fom_hdr(oh, sizeof(*ch)+2, NM_MT_BS11_SET_ATTR,
Harald Welte05188ee2009-01-18 11:39:08 +00001790 NM_OC_SITE_MANAGER, 0xff, 0xff, 0xff);
1791
1792 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1793 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
Harald Welteb6c92ae2009-02-21 20:15:32 +00001794 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte05188ee2009-01-18 11:39:08 +00001795
1796 return abis_nm_sendmsg(bts, msg);
1797}
1798
1799int abis_nm_bs11_set_trx_power(struct gsm_bts_trx *trx, u_int8_t level)
1800{
1801 struct abis_om_hdr *oh;
1802 struct msgb *msg = nm_msgb_alloc();
Harald Welte05188ee2009-01-18 11:39:08 +00001803
1804 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001805 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR,
Harald Welte05188ee2009-01-18 11:39:08 +00001806 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
1807 msgb_tlv_put(msg, NM_ATT_BS11_TXPWR, 1, &level);
1808
1809 return abis_nm_sendmsg(trx->bts, msg);
1810}
1811
Harald Welte78fc0d42009-02-19 02:50:57 +00001812int abis_nm_bs11_get_trx_power(struct gsm_bts_trx *trx)
1813{
1814 struct abis_om_hdr *oh;
1815 struct msgb *msg = nm_msgb_alloc();
1816 u_int8_t attr = NM_ATT_BS11_TXPWR;
1817
1818 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1819 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
1820 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
1821 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), &attr);
1822
1823 return abis_nm_sendmsg(trx->bts, msg);
1824}
1825
Harald Welteaaf02d92009-04-29 13:25:57 +00001826int abis_nm_bs11_get_pll_mode(struct gsm_bts *bts)
1827{
1828 struct abis_om_hdr *oh;
1829 struct msgb *msg = nm_msgb_alloc();
Harald Weltea7cfa032009-04-29 22:33:02 +00001830 u_int8_t attr[] = { NM_ATT_BS11_PLL_MODE };
Harald Welteaaf02d92009-04-29 13:25:57 +00001831
1832 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1833 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
1834 NM_OC_BS11, BS11_OBJ_LI, 0x00, 0x00);
Harald Welteaeedeb42009-05-01 13:08:14 +00001835 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), attr);
Harald Welteaaf02d92009-04-29 13:25:57 +00001836
1837 return abis_nm_sendmsg(bts, msg);
1838}
1839
1840
Harald Welte268bb402009-02-01 19:11:56 +00001841//static const u_int8_t bs11_logon_c7[] = { 0x07, 0xd9, 0x01, 0x11, 0x0d, 0x10, 0x20 };
Harald Weltebb151312009-01-28 20:42:07 +00001842static const u_int8_t bs11_logon_c8[] = { 0x02 };
Harald Welte05188ee2009-01-18 11:39:08 +00001843static const u_int8_t bs11_logon_c9[] = "FACTORY";
1844
Harald Welte1bc09062009-01-18 14:17:52 +00001845int abis_nm_bs11_factory_logon(struct gsm_bts *bts, int on)
Harald Welte05188ee2009-01-18 11:39:08 +00001846{
1847 struct abis_om_hdr *oh;
1848 struct msgb *msg = nm_msgb_alloc();
Harald Welte268bb402009-02-01 19:11:56 +00001849 struct bs11_date_time bdt;
1850
1851 get_bs11_date_time(&bdt);
Harald Welte05188ee2009-01-18 11:39:08 +00001852
1853 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte1bc09062009-01-18 14:17:52 +00001854 if (on) {
Harald Welte268bb402009-02-01 19:11:56 +00001855 u_int8_t len = 3*2 + sizeof(bdt)
Harald Welte6f676a32009-01-18 14:27:48 +00001856 + sizeof(bs11_logon_c8) + sizeof(bs11_logon_c9);
Harald Welte043d04a2009-01-29 23:15:30 +00001857 fill_om_fom_hdr(oh, len, NM_MT_BS11_LMT_LOGON,
Harald Welte1bc09062009-01-18 14:17:52 +00001858 NM_OC_BS11_A3, 0xff, 0xff, 0xff);
Harald Welte043d04a2009-01-29 23:15:30 +00001859 msgb_tlv_put(msg, NM_ATT_BS11_LMT_LOGIN_TIME,
Harald Welte5083b0b2009-02-02 19:20:52 +00001860 sizeof(bdt), (u_int8_t *) &bdt);
Harald Welte043d04a2009-01-29 23:15:30 +00001861 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_ACC_LEV,
1862 sizeof(bs11_logon_c8), bs11_logon_c8);
1863 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_NAME,
1864 sizeof(bs11_logon_c9), bs11_logon_c9);
Harald Welte1bc09062009-01-18 14:17:52 +00001865 } else {
Harald Welte5e4d1b32009-02-01 13:36:56 +00001866 fill_om_fom_hdr(oh, 0, NM_MT_BS11_LMT_LOGOFF,
Harald Welte1bc09062009-01-18 14:17:52 +00001867 NM_OC_BS11_A3, 0xff, 0xff, 0xff);
1868 }
Harald Welte05188ee2009-01-18 11:39:08 +00001869
1870 return abis_nm_sendmsg(bts, msg);
1871}
Harald Welte1bc09062009-01-18 14:17:52 +00001872
1873int abis_nm_bs11_set_trx1_pw(struct gsm_bts *bts, const char *password)
1874{
1875 struct abis_om_hdr *oh;
1876 struct msgb *msg;
1877
1878 if (strlen(password) != 10)
1879 return -EINVAL;
1880
1881 msg = nm_msgb_alloc();
1882 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001883 fill_om_fom_hdr(oh, 2+strlen(password), NM_MT_BS11_SET_ATTR,
Harald Welte1bc09062009-01-18 14:17:52 +00001884 NM_OC_BS11, BS11_OBJ_TRX1, 0x00, 0x00);
1885 msgb_tlv_put(msg, NM_ATT_BS11_PASSWORD, 10, (const u_int8_t *)password);
1886
1887 return abis_nm_sendmsg(bts, msg);
1888}
1889
Harald Weltee69f5fb2009-04-28 16:31:38 +00001890/* change the BS-11 PLL Mode to either locked (E1 derived) or standalone */
1891int abis_nm_bs11_set_pll_locked(struct gsm_bts *bts, int locked)
1892{
1893 struct abis_om_hdr *oh;
1894 struct msgb *msg;
Harald Weltea432cd32009-04-29 13:01:50 +00001895 u_int8_t tlv_value;
Harald Weltee69f5fb2009-04-28 16:31:38 +00001896
1897 msg = nm_msgb_alloc();
1898 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1899 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR, NM_OC_BS11,
1900 BS11_OBJ_LI, 0x00, 0x00);
Harald Weltea432cd32009-04-29 13:01:50 +00001901
1902 if (locked)
1903 tlv_value = BS11_LI_PLL_LOCKED;
1904 else
1905 tlv_value = BS11_LI_PLL_STANDALONE;
1906
1907 msgb_tlv_put(msg, NM_ATT_BS11_PLL_MODE, 1, &tlv_value);
Harald Weltee69f5fb2009-04-28 16:31:38 +00001908
1909 return abis_nm_sendmsg(bts, msg);
1910}
1911
Harald Welte1bc09062009-01-18 14:17:52 +00001912int abis_nm_bs11_get_state(struct gsm_bts *bts)
1913{
1914 return __simple_cmd(bts, NM_MT_BS11_GET_STATE);
1915}
Harald Welte5e4d1b32009-02-01 13:36:56 +00001916
1917/* BS11 SWL */
1918
1919struct abis_nm_bs11_sw {
1920 struct gsm_bts *bts;
1921 char swl_fname[PATH_MAX];
1922 u_int8_t win_size;
Harald Welte3ffd1372009-02-01 22:15:49 +00001923 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001924 struct llist_head file_list;
1925 gsm_cbfn *user_cb; /* specified by the user */
1926};
1927static struct abis_nm_bs11_sw _g_bs11_sw, *g_bs11_sw = &_g_bs11_sw;
1928
1929struct file_list_entry {
1930 struct llist_head list;
1931 char fname[PATH_MAX];
1932};
1933
1934struct file_list_entry *fl_dequeue(struct llist_head *queue)
1935{
1936 struct llist_head *lh;
1937
1938 if (llist_empty(queue))
1939 return NULL;
1940
1941 lh = queue->next;
1942 llist_del(lh);
1943
1944 return llist_entry(lh, struct file_list_entry, list);
1945}
1946
1947static int bs11_read_swl_file(struct abis_nm_bs11_sw *bs11_sw)
1948{
1949 char linebuf[255];
1950 struct llist_head *lh, *lh2;
1951 FILE *swl;
1952 int rc = 0;
1953
1954 swl = fopen(bs11_sw->swl_fname, "r");
1955 if (!swl)
1956 return -ENODEV;
1957
1958 /* zero the stale file list, if any */
1959 llist_for_each_safe(lh, lh2, &bs11_sw->file_list) {
1960 llist_del(lh);
1961 free(lh);
1962 }
1963
1964 while (fgets(linebuf, sizeof(linebuf), swl)) {
1965 char file_id[12+1];
1966 char file_version[80+1];
1967 struct file_list_entry *fle;
1968 static char dir[PATH_MAX];
1969
1970 if (strlen(linebuf) < 4)
1971 continue;
Harald Welte3ffd1372009-02-01 22:15:49 +00001972
Harald Welte5e4d1b32009-02-01 13:36:56 +00001973 rc = sscanf(linebuf+4, "%12s:%80s\r\n", file_id, file_version);
1974 if (rc < 0) {
1975 perror("ERR parsing SWL file");
1976 rc = -EINVAL;
1977 goto out;
1978 }
1979 if (rc < 2)
1980 continue;
1981
1982 fle = malloc(sizeof(*fle));
1983 if (!fle) {
1984 rc = -ENOMEM;
1985 goto out;
1986 }
1987 memset(fle, 0, sizeof(*fle));
1988
1989 /* construct new filename */
1990 strncpy(dir, bs11_sw->swl_fname, sizeof(dir));
1991 strncat(fle->fname, dirname(dir), sizeof(fle->fname) - 1);
1992 strcat(fle->fname, "/");
1993 strncat(fle->fname, file_id, sizeof(fle->fname) - 1 -strlen(fle->fname));
Harald Welte5e4d1b32009-02-01 13:36:56 +00001994
1995 llist_add_tail(&fle->list, &bs11_sw->file_list);
1996 }
1997
1998out:
1999 fclose(swl);
2000 return rc;
2001}
2002
2003/* bs11 swload specific callback, passed to abis_nm core swload */
2004static int bs11_swload_cbfn(unsigned int hook, unsigned int event,
2005 struct msgb *msg, void *data, void *param)
2006{
2007 struct abis_nm_bs11_sw *bs11_sw = data;
2008 struct file_list_entry *fle;
2009 int rc = 0;
2010
Harald Welte5e4d1b32009-02-01 13:36:56 +00002011 switch (event) {
2012 case NM_MT_LOAD_END_ACK:
2013 fle = fl_dequeue(&bs11_sw->file_list);
2014 if (fle) {
2015 /* start download the next file of our file list */
2016 rc = abis_nm_software_load(bs11_sw->bts, fle->fname,
2017 bs11_sw->win_size,
Harald Welte3ffd1372009-02-01 22:15:49 +00002018 bs11_sw->forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00002019 &bs11_swload_cbfn, bs11_sw);
2020 free(fle);
2021 } else {
2022 /* activate the SWL */
2023 rc = abis_nm_software_activate(bs11_sw->bts,
2024 bs11_sw->swl_fname,
2025 bs11_swload_cbfn,
2026 bs11_sw);
2027 }
2028 break;
Harald Welte3ffd1372009-02-01 22:15:49 +00002029 case NM_MT_LOAD_SEG_ACK:
Harald Welte5e4d1b32009-02-01 13:36:56 +00002030 case NM_MT_LOAD_END_NACK:
2031 case NM_MT_LOAD_INIT_ACK:
2032 case NM_MT_LOAD_INIT_NACK:
2033 case NM_MT_ACTIVATE_SW_NACK:
2034 case NM_MT_ACTIVATE_SW_ACK:
2035 default:
2036 /* fallthrough to the user callback */
Harald Welte97ed1e72009-02-06 13:38:02 +00002037 if (bs11_sw->user_cb)
2038 rc = bs11_sw->user_cb(hook, event, msg, NULL, NULL);
Harald Welte5e4d1b32009-02-01 13:36:56 +00002039 break;
2040 }
2041
2042 return rc;
2043}
2044
2045/* Siemens provides a SWL file that is a mere listing of all the other
2046 * files that are part of a software release. We need to upload first
2047 * the list file, and then each file that is listed in the list file */
2048int abis_nm_bs11_load_swl(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00002049 u_int8_t win_size, int forced, gsm_cbfn *cbfn)
Harald Welte5e4d1b32009-02-01 13:36:56 +00002050{
2051 struct abis_nm_bs11_sw *bs11_sw = g_bs11_sw;
2052 struct file_list_entry *fle;
2053 int rc = 0;
2054
2055 INIT_LLIST_HEAD(&bs11_sw->file_list);
2056 bs11_sw->bts = bts;
2057 bs11_sw->win_size = win_size;
2058 bs11_sw->user_cb = cbfn;
Harald Welte3ffd1372009-02-01 22:15:49 +00002059 bs11_sw->forced = forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00002060
2061 strncpy(bs11_sw->swl_fname, fname, sizeof(bs11_sw->swl_fname));
2062 rc = bs11_read_swl_file(bs11_sw);
2063 if (rc < 0)
2064 return rc;
2065
2066 /* dequeue next item in file list */
2067 fle = fl_dequeue(&bs11_sw->file_list);
2068 if (!fle)
2069 return -EINVAL;
2070
2071 /* start download the next file of our file list */
Harald Welte3ffd1372009-02-01 22:15:49 +00002072 rc = abis_nm_software_load(bts, fle->fname, win_size, forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00002073 bs11_swload_cbfn, bs11_sw);
2074 free(fle);
2075 return rc;
2076}
2077
Harald Welte5083b0b2009-02-02 19:20:52 +00002078#if 0
Harald Welte5e4d1b32009-02-01 13:36:56 +00002079static u_int8_t req_attr_btse[] = {
2080 NM_ATT_ADM_STATE, NM_ATT_BS11_LMT_LOGON_SESSION,
2081 NM_ATT_BS11_LMT_LOGIN_TIME, NM_ATT_BS11_LMT_USER_ACC_LEV,
2082 NM_ATT_BS11_LMT_USER_NAME,
2083
2084 0xaf, NM_ATT_BS11_RX_OFFSET, NM_ATT_BS11_VENDOR_NAME,
2085
2086 NM_ATT_BS11_SW_LOAD_INTENDED, NM_ATT_BS11_SW_LOAD_SAFETY,
2087
2088 NM_ATT_BS11_SW_LOAD_STORED };
2089
2090static u_int8_t req_attr_btsm[] = {
2091 NM_ATT_ABIS_CHANNEL, NM_ATT_TEI, NM_ATT_BS11_ABIS_EXT_TIME,
2092 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xce, NM_ATT_FILE_ID,
2093 NM_ATT_FILE_VERSION, NM_ATT_OPER_STATE, 0xe8, NM_ATT_BS11_ALL_TEST_CATG,
2094 NM_ATT_SW_DESCR, NM_ATT_GET_ARI };
Harald Welte5083b0b2009-02-02 19:20:52 +00002095#endif
Harald Welte5e4d1b32009-02-01 13:36:56 +00002096
2097static u_int8_t req_attr[] = {
2098 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xa8, NM_ATT_OPER_STATE,
2099 0xd5, 0xa1, NM_ATT_BS11_ESN_FW_CODE_NO, NM_ATT_BS11_ESN_HW_CODE_NO,
Harald Weltea7cfa032009-04-29 22:33:02 +00002100 0x42, NM_ATT_BS11_ESN_PCB_SERIAL, NM_ATT_BS11_PLL };
Harald Welte5e4d1b32009-02-01 13:36:56 +00002101
2102int abis_nm_bs11_get_serno(struct gsm_bts *bts)
2103{
2104 struct abis_om_hdr *oh;
2105 struct msgb *msg = nm_msgb_alloc();
2106
2107 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2108 /* SiemensHW CCTRL object */
2109 fill_om_fom_hdr(oh, 2+sizeof(req_attr), NM_MT_GET_ATTR, NM_OC_BS11,
2110 0x03, 0x00, 0x00);
2111 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(req_attr), req_attr);
2112
2113 return abis_nm_sendmsg(bts, msg);
2114}
Harald Welte268bb402009-02-01 19:11:56 +00002115
2116int abis_nm_bs11_set_ext_time(struct gsm_bts *bts)
2117{
2118 struct abis_om_hdr *oh;
2119 struct msgb *msg = nm_msgb_alloc();
2120 struct bs11_date_time aet;
2121
2122 get_bs11_date_time(&aet);
2123 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2124 /* SiemensHW CCTRL object */
2125 fill_om_fom_hdr(oh, 2+sizeof(aet), NM_MT_BS11_SET_ATTR, NM_OC_SITE_MANAGER,
2126 0xff, 0xff, 0xff);
Harald Welte5083b0b2009-02-02 19:20:52 +00002127 msgb_tlv_put(msg, NM_ATT_BS11_ABIS_EXT_TIME, sizeof(aet), (u_int8_t *) &aet);
Harald Welte268bb402009-02-01 19:11:56 +00002128
2129 return abis_nm_sendmsg(bts, msg);
2130}
Harald Welte5c1e4582009-02-15 11:57:29 +00002131
2132/* ip.access nanoBTS specific commands */
Harald Welte5c1e4582009-02-15 11:57:29 +00002133static const char ipaccess_magic[] = "com.ipaccess";
2134
Harald Welte677c21f2009-02-17 13:22:23 +00002135
2136static int abis_nm_rx_ipacc(struct msgb *msg)
2137{
2138 struct abis_om_hdr *oh = msgb_l2(msg);
2139 struct abis_om_fom_hdr *foh;
2140 u_int8_t idstrlen = oh->data[0];
2141 struct tlv_parsed tp;
2142
2143 if (strncmp((char *)&oh->data[1], ipaccess_magic, idstrlen)) {
2144 DEBUGP(DNM, "id string is not com.ipaccess !?!\n");
2145 return -EINVAL;
2146 }
2147
Harald Welte193fefc2009-04-30 15:16:27 +00002148 foh = (struct abis_om_fom_hdr *) (oh->data + 1 + idstrlen);
Harald Welte03133942009-02-18 19:51:53 +00002149 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Welte677c21f2009-02-17 13:22:23 +00002150
Harald Welte193fefc2009-04-30 15:16:27 +00002151 DEBUGP(DNM, "IPACCESS(0x%02x): ", foh->msg_type);
2152
Harald Welte677c21f2009-02-17 13:22:23 +00002153 switch (foh->msg_type) {
2154 case NM_MT_IPACC_RSL_CONNECT_ACK:
Harald Welte193fefc2009-04-30 15:16:27 +00002155 DEBUGPC(DNM, "RSL CONNECT ACK ");
Harald Welte677c21f2009-02-17 13:22:23 +00002156 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_RSL_BSC_IP))
Harald Welte9de2bf82009-04-30 15:59:55 +00002157 DEBUGPC(DNM, "IP=%s ",
Harald Welte677c21f2009-02-17 13:22:23 +00002158 inet_ntoa(*((struct in_addr *)
2159 TLVP_VAL(&tp, NM_ATT_IPACC_RSL_BSC_IP))));
2160 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_RSL_BSC_PORT))
Harald Welte9de2bf82009-04-30 15:59:55 +00002161 DEBUGPC(DNM, "PORT=%u ",
Harald Welte677c21f2009-02-17 13:22:23 +00002162 ntohs(*((u_int16_t *)
2163 TLVP_VAL(&tp, NM_ATT_IPACC_RSL_BSC_PORT))));
Harald Welte9de2bf82009-04-30 15:59:55 +00002164 DEBUGPC(DNM, "\n");
Harald Welte677c21f2009-02-17 13:22:23 +00002165 break;
2166 case NM_MT_IPACC_RSL_CONNECT_NACK:
Harald Welte193fefc2009-04-30 15:16:27 +00002167 DEBUGPC(DNM, "RSL CONNECT NACK ");
Harald Welte677c21f2009-02-17 13:22:23 +00002168 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
Harald Welte6c96ba52009-05-01 13:03:40 +00002169 DEBUGPC(DNM, " CAUSE=%s\n",
2170 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
Harald Welte677c21f2009-02-17 13:22:23 +00002171 else
2172 DEBUGPC(DNM, "\n");
2173 break;
Harald Welte193fefc2009-04-30 15:16:27 +00002174 case NM_MT_IPACC_SET_NVATTR_ACK:
2175 DEBUGPC(DNM, "SET NVATTR ACK\n");
2176 /* FIXME: decode and show the actual attributes */
2177 break;
2178 case NM_MT_IPACC_SET_NVATTR_NACK:
Harald Welte6c96ba52009-05-01 13:03:40 +00002179 DEBUGPC(DNM, "SET NVATTR NACK ");
2180 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
2181 DEBUGPC(DNM, " CAUSE=%s\n",
2182 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
2183 else
2184 DEBUGPC(DNM, "\n");
Harald Welte193fefc2009-04-30 15:16:27 +00002185 break;
2186 default:
2187 DEBUGPC(DNM, "unknown\n");
2188 break;
Harald Welte677c21f2009-02-17 13:22:23 +00002189 }
2190 return 0;
2191}
2192
Harald Welte193fefc2009-04-30 15:16:27 +00002193/* send an ip-access manufacturer specific message */
Harald Welte5c1e4582009-02-15 11:57:29 +00002194int abis_nm_ipaccess_msg(struct gsm_bts *bts, u_int8_t msg_type,
2195 u_int8_t obj_class, u_int8_t bts_nr,
2196 u_int8_t trx_nr, u_int8_t ts_nr,
2197 u_int8_t *attr, int attr_len)
2198{
2199 struct msgb *msg = nm_msgb_alloc();
2200 struct abis_om_hdr *oh;
2201 struct abis_om_fom_hdr *foh;
2202 u_int8_t *data;
2203
2204 /* construct the 12.21 OM header, observe the erroneous length */
2205 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
2206 fill_om_hdr(oh, sizeof(*foh) + attr_len);
2207 oh->mdisc = ABIS_OM_MDISC_MANUF;
2208
2209 /* add the ip.access magic */
2210 data = msgb_put(msg, sizeof(ipaccess_magic)+1);
2211 *data++ = sizeof(ipaccess_magic);
2212 memcpy(data, ipaccess_magic, sizeof(ipaccess_magic));
2213
2214 /* fill the 12.21 FOM header */
2215 foh = (struct abis_om_fom_hdr *) msgb_put(msg, sizeof(*foh));
2216 foh->msg_type = msg_type;
2217 foh->obj_class = obj_class;
2218 foh->obj_inst.bts_nr = bts_nr;
2219 foh->obj_inst.trx_nr = trx_nr;
2220 foh->obj_inst.ts_nr = ts_nr;
2221
2222 if (attr && attr_len) {
2223 data = msgb_put(msg, attr_len);
2224 memcpy(data, attr, attr_len);
2225 }
2226
2227 return abis_nm_sendmsg(bts, msg);
2228}
Harald Welte677c21f2009-02-17 13:22:23 +00002229
Harald Welte193fefc2009-04-30 15:16:27 +00002230/* set some attributes in NVRAM */
2231int abis_nm_ipaccess_set_nvattr(struct gsm_bts *bts, u_int8_t *attr,
2232 int attr_len)
2233{
2234 return abis_nm_ipaccess_msg(bts, NM_MT_IPACC_SET_NVATTR,
2235 NM_OC_BASEB_TRANSC, 0, 0, 0xff, attr,
2236 attr_len);
2237}
2238
2239/* restart / reboot an ip.access nanoBTS */
2240int abis_nm_ipaccess_restart(struct gsm_bts *bts)
2241{
2242 return __simple_cmd(bts, NM_MT_IPACC_RESTART);
2243}