blob: 35ed8dbc671332e53908dffa7260aed6d1367f8c [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
Harald Welte21bd3a52009-08-10 12:21:22 +0200407static const enum abis_nm_chan_comb chcomb4pchan[] = {
408 [GSM_PCHAN_CCCH] = NM_CHANC_mainBCCH,
409 [GSM_PCHAN_CCCH_SDCCH4] = NM_CHANC_BCCHComb,
410 [GSM_PCHAN_TCH_F] = NM_CHANC_TCHFull,
411 [GSM_PCHAN_TCH_H] = NM_CHANC_TCHHalf,
412 [GSM_PCHAN_SDCCH8_SACCH8C] = NM_CHANC_SDCCH,
413 /* FIXME: bounds check */
414};
415
416int abis_nm_chcomb4pchan(enum gsm_phys_chan_config pchan)
417{
418 if (pchan < ARRAY_SIZE(chcomb4pchan))
419 return chcomb4pchan[pchan];
420
421 return -EINVAL;
422}
423
Harald Welte03133942009-02-18 19:51:53 +0000424int abis_nm_tlv_parse(struct tlv_parsed *tp, const u_int8_t *buf, int len)
425{
Harald Weltea4d49e92009-05-23 06:39:58 +0000426 return tlv_parse(tp, &nm_att_tlvdef, buf, len, 0, 0);
Harald Welte03133942009-02-18 19:51:53 +0000427}
Harald Weltee0590df2009-02-15 03:34:15 +0000428
Harald Welte52b1f982008-12-23 20:25:15 +0000429static int is_in_arr(enum abis_nm_msgtype mt, const enum abis_nm_msgtype *arr, int size)
430{
431 int i;
432
433 for (i = 0; i < size; i++) {
434 if (arr[i] == mt)
435 return 1;
436 }
437
438 return 0;
439}
440
Holger Freytherca362a62009-01-04 21:05:01 +0000441#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000442/* is this msgtype the usual ACK/NACK type ? */
443static int is_ack_nack(enum abis_nm_msgtype mt)
444{
445 return !is_in_arr(mt, no_ack_nack, ARRAY_SIZE(no_ack_nack));
446}
Holger Freytherca362a62009-01-04 21:05:01 +0000447#endif
Harald Welte52b1f982008-12-23 20:25:15 +0000448
449/* is this msgtype a report ? */
450static int is_report(enum abis_nm_msgtype mt)
451{
Harald Welte8470bf22008-12-25 23:28:35 +0000452 return is_in_arr(mt, reports, ARRAY_SIZE(reports));
Harald Welte52b1f982008-12-23 20:25:15 +0000453}
454
455#define MT_ACK(x) (x+1)
456#define MT_NACK(x) (x+2)
457
458static void fill_om_hdr(struct abis_om_hdr *oh, u_int8_t len)
459{
460 oh->mdisc = ABIS_OM_MDISC_FOM;
461 oh->placement = ABIS_OM_PLACEMENT_ONLY;
462 oh->sequence = 0;
463 oh->length = len;
464}
465
466static void fill_om_fom_hdr(struct abis_om_hdr *oh, u_int8_t len,
467 u_int8_t msg_type, u_int8_t obj_class,
468 u_int8_t bts_nr, u_int8_t trx_nr, u_int8_t ts_nr)
469{
470 struct abis_om_fom_hdr *foh =
471 (struct abis_om_fom_hdr *) oh->data;
472
Harald Welte702d8702008-12-26 20:25:35 +0000473 fill_om_hdr(oh, len+sizeof(*foh));
Harald Welte52b1f982008-12-23 20:25:15 +0000474 foh->msg_type = msg_type;
475 foh->obj_class = obj_class;
476 foh->obj_inst.bts_nr = bts_nr;
477 foh->obj_inst.trx_nr = trx_nr;
478 foh->obj_inst.ts_nr = ts_nr;
479}
480
Harald Welte8470bf22008-12-25 23:28:35 +0000481static struct msgb *nm_msgb_alloc(void)
482{
Harald Welte966636f2009-06-26 19:39:35 +0200483 return msgb_alloc_headroom(OM_ALLOC_SIZE, OM_HEADROOM_SIZE,
484 "OML");
Harald Welte8470bf22008-12-25 23:28:35 +0000485}
486
Harald Welte52b1f982008-12-23 20:25:15 +0000487/* Send a OML NM Message from BSC to BTS */
488int abis_nm_sendmsg(struct gsm_bts *bts, struct msgb *msg)
489{
Holger Freyther59639e82009-02-09 23:09:55 +0000490 msg->trx = bts->c0;
491
Harald Weltead384642008-12-26 10:20:07 +0000492 return _abis_nm_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000493}
494
Harald Welte4724f992009-01-18 18:01:49 +0000495static int abis_nm_rcvmsg_sw(struct msgb *mb);
496
Harald Welte34a99682009-02-13 02:41:40 +0000497static const char *obj_class_name(u_int8_t oc)
498{
Harald Welte7b26bcb2009-05-28 11:39:21 +0000499 switch (oc) {
500 case NM_OC_SITE_MANAGER:
501 return "SITE MANAGER";
502 case NM_OC_BTS:
503 return "BTS";
504 case NM_OC_RADIO_CARRIER:
505 return "RADIO CARRIER";
506 case NM_OC_BASEB_TRANSC:
507 return "BASEBAND TRANSCEIVER";
508 case NM_OC_CHANNEL:
Harald Weltebd8f7e32009-06-09 20:17:12 +0000509 return "CHANNEL";
Harald Welte7b26bcb2009-05-28 11:39:21 +0000510 case NM_OC_BS11_ADJC:
511 return "ADJC";
512 case NM_OC_BS11_HANDOVER:
513 return "HANDOVER";
514 case NM_OC_BS11_PWR_CTRL:
515 return "POWER CONTROL";
516 case NM_OC_BS11_BTSE:
517 return "BTSE";
518 case NM_OC_BS11_RACK:
519 return "RACK";
520 case NM_OC_BS11_TEST:
521 return "TEST";
522 case NM_OC_BS11_ENVABTSE:
523 return "ENVABTSE";
524 case NM_OC_BS11_BPORT:
525 return "BPORT";
526 case NM_OC_GPRS_NSE:
527 return "GPRS NSE";
528 case NM_OC_GPRS_CELL:
529 return "GPRS CELL";
Harald Welted83a1272009-07-12 10:56:06 +0200530 case NM_OC_GPRS_NSVC:
531 return "GPRS NSVC";
Harald Welte8b697c72009-06-05 19:18:45 +0000532 case NM_OC_BS11:
533 return "SIEMENSHW";
Harald Welte7b26bcb2009-05-28 11:39:21 +0000534 }
535
536 return "UNKNOWN";
Harald Welte34a99682009-02-13 02:41:40 +0000537}
538
Harald Welte4d87f242009-03-10 19:43:44 +0000539const char *nm_opstate_name(u_int8_t os)
Harald Welte34a99682009-02-13 02:41:40 +0000540{
541 switch (os) {
542 case 1:
543 return "Disabled";
544 case 2:
545 return "Enabled";
546 case 0xff:
547 return "NULL";
548 default:
549 return "RFU";
550 }
551}
552
Harald Weltee0590df2009-02-15 03:34:15 +0000553/* Chapter 9.4.7 */
Harald Welte4d87f242009-03-10 19:43:44 +0000554static const char *avail_names[] = {
Harald Weltee0590df2009-02-15 03:34:15 +0000555 "In test",
556 "Failed",
557 "Power off",
558 "Off line",
559 "<not used>",
560 "Dependency",
561 "Degraded",
562 "Not installed",
563};
564
Harald Welte4d87f242009-03-10 19:43:44 +0000565const char *nm_avail_name(u_int8_t avail)
Harald Weltee0590df2009-02-15 03:34:15 +0000566{
Harald Welte0b8348d2009-02-18 03:43:01 +0000567 if (avail == 0xff)
568 return "OK";
Harald Weltee0590df2009-02-15 03:34:15 +0000569 if (avail >= ARRAY_SIZE(avail_names))
570 return "UNKNOWN";
571 return avail_names[avail];
572}
Harald Welte7b26bcb2009-05-28 11:39:21 +0000573
574const char *nm_adm_name(u_int8_t adm)
575{
576 switch (adm) {
577 case 1:
578 return "Locked";
579 case 2:
580 return "Unlocked";
581 case 3:
582 return "Shutdown";
583 default:
584 return "<not used>";
585 }
586}
Harald Weltee0590df2009-02-15 03:34:15 +0000587
588/* obtain the gsm_nm_state data structure for a given object instance */
589static struct gsm_nm_state *
590objclass2nmstate(struct gsm_bts *bts, u_int8_t obj_class,
591 struct abis_om_obj_inst *obj_inst)
592{
593 struct gsm_bts_trx *trx;
594 struct gsm_nm_state *nm_state = NULL;
595
596 switch (obj_class) {
597 case NM_OC_BTS:
598 nm_state = &bts->nm_state;
599 break;
600 case NM_OC_RADIO_CARRIER:
601 if (obj_inst->trx_nr >= bts->num_trx)
602 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200603 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000604 nm_state = &trx->nm_state;
605 break;
606 case NM_OC_BASEB_TRANSC:
607 if (obj_inst->trx_nr >= bts->num_trx)
608 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200609 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000610 nm_state = &trx->bb_transc.nm_state;
611 break;
612 case NM_OC_CHANNEL:
613 if (obj_inst->trx_nr > bts->num_trx)
614 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200615 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000616 if (obj_inst->ts_nr >= TRX_NR_TS)
617 return NULL;
618 nm_state = &trx->ts[obj_inst->ts_nr].nm_state;
619 break;
620 case NM_OC_SITE_MANAGER:
621 nm_state = &bts->site_mgr.nm_state;
622 break;
Harald Welte7b26bcb2009-05-28 11:39:21 +0000623 case NM_OC_BS11:
624 switch (obj_inst->bts_nr) {
625 case BS11_OBJ_CCLK:
626 nm_state = &bts->bs11.cclk.nm_state;
627 break;
Harald Welte8b697c72009-06-05 19:18:45 +0000628 case BS11_OBJ_BBSIG:
629 if (obj_inst->ts_nr > bts->num_trx)
630 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200631 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Welte8b697c72009-06-05 19:18:45 +0000632 nm_state = &trx->bs11.bbsig.nm_state;
633 break;
634 case BS11_OBJ_PA:
635 if (obj_inst->ts_nr > bts->num_trx)
636 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200637 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Welte8b697c72009-06-05 19:18:45 +0000638 nm_state = &trx->bs11.pa.nm_state;
639 break;
Harald Welte7b26bcb2009-05-28 11:39:21 +0000640 default:
641 return NULL;
642 }
643 case NM_OC_BS11_RACK:
644 nm_state = &bts->bs11.rack.nm_state;
645 break;
Harald Welte8b697c72009-06-05 19:18:45 +0000646 case NM_OC_BS11_ENVABTSE:
647 if (obj_inst->trx_nr > ARRAY_SIZE(bts->bs11.envabtse))
648 return NULL;
649 nm_state = &bts->bs11.envabtse[obj_inst->trx_nr].nm_state;
650 break;
Harald Weltee0590df2009-02-15 03:34:15 +0000651 }
652 return nm_state;
653}
654
655/* obtain the in-memory data structure of a given object instance */
656static void *
657objclass2obj(struct gsm_bts *bts, u_int8_t obj_class,
658 struct abis_om_obj_inst *obj_inst)
659{
660 struct gsm_bts_trx *trx;
661 void *obj = NULL;
662
663 switch (obj_class) {
664 case NM_OC_BTS:
665 obj = bts;
666 break;
667 case NM_OC_RADIO_CARRIER:
668 if (obj_inst->trx_nr >= bts->num_trx)
669 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200670 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000671 obj = trx;
672 break;
673 case NM_OC_BASEB_TRANSC:
674 if (obj_inst->trx_nr >= bts->num_trx)
675 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200676 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000677 obj = &trx->bb_transc;
678 break;
679 case NM_OC_CHANNEL:
680 if (obj_inst->trx_nr > bts->num_trx)
681 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200682 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000683 if (obj_inst->ts_nr >= TRX_NR_TS)
684 return NULL;
685 obj = &trx->ts[obj_inst->ts_nr];
686 break;
687 case NM_OC_SITE_MANAGER:
688 obj = &bts->site_mgr;
689 break;
690 }
691 return obj;
692}
693
694/* Update the administrative state of a given object in our in-memory data
695 * structures and send an event to the higher layer */
696static int update_admstate(struct gsm_bts *bts, u_int8_t obj_class,
697 struct abis_om_obj_inst *obj_inst, u_int8_t adm_state)
698{
Harald Welteaeedeb42009-05-01 13:08:14 +0000699 struct gsm_nm_state *nm_state, new_state;
Harald Weltee0590df2009-02-15 03:34:15 +0000700 void *obj;
701 int rc;
702
Harald Weltee0590df2009-02-15 03:34:15 +0000703 obj = objclass2obj(bts, obj_class, obj_inst);
Harald Welteaeedeb42009-05-01 13:08:14 +0000704 nm_state = objclass2nmstate(bts, obj_class, obj_inst);
705 if (!nm_state)
706 return -1;
707
708 new_state = *nm_state;
709 new_state.administrative = adm_state;
710
711 rc = nm_state_event(EVT_STATECHG_ADM, obj_class, obj, nm_state, &new_state);
712
713 nm_state->administrative = adm_state;
Harald Weltee0590df2009-02-15 03:34:15 +0000714
715 return rc;
716}
717
Harald Welte97ed1e72009-02-06 13:38:02 +0000718static int abis_nm_rx_statechg_rep(struct msgb *mb)
719{
Harald Weltee0590df2009-02-15 03:34:15 +0000720 struct abis_om_hdr *oh = msgb_l2(mb);
Harald Welte97ed1e72009-02-06 13:38:02 +0000721 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Harald Welte22af0db2009-02-14 15:41:08 +0000722 struct gsm_bts *bts = mb->trx->bts;
Harald Weltee0590df2009-02-15 03:34:15 +0000723 struct tlv_parsed tp;
724 struct gsm_nm_state *nm_state, new_state;
725 int rc;
726
Harald Welte23897662009-05-01 14:52:51 +0000727 DEBUGPC(DNM, "STATE CHG: ");
Harald Weltee0590df2009-02-15 03:34:15 +0000728
Harald Welte8b697c72009-06-05 19:18:45 +0000729 memset(&new_state, 0, sizeof(new_state));
730
Harald Weltee0590df2009-02-15 03:34:15 +0000731 nm_state = objclass2nmstate(bts, foh->obj_class, &foh->obj_inst);
732 if (!nm_state) {
733 DEBUGPC(DNM, "\n");
734 return -EINVAL;
Harald Welte22af0db2009-02-14 15:41:08 +0000735 }
Harald Weltee0590df2009-02-15 03:34:15 +0000736
737 new_state = *nm_state;
738
Harald Welte03133942009-02-18 19:51:53 +0000739 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Weltee0590df2009-02-15 03:34:15 +0000740 if (TLVP_PRESENT(&tp, NM_ATT_OPER_STATE)) {
741 new_state.operational = *TLVP_VAL(&tp, NM_ATT_OPER_STATE);
Harald Welte4d87f242009-03-10 19:43:44 +0000742 DEBUGPC(DNM, "OP_STATE=%s ", nm_opstate_name(new_state.operational));
Harald Weltee0590df2009-02-15 03:34:15 +0000743 }
744 if (TLVP_PRESENT(&tp, NM_ATT_AVAIL_STATUS)) {
Harald Welte0b8348d2009-02-18 03:43:01 +0000745 if (TLVP_LEN(&tp, NM_ATT_AVAIL_STATUS) == 0)
746 new_state.availability = 0xff;
747 else
748 new_state.availability = *TLVP_VAL(&tp, NM_ATT_AVAIL_STATUS);
Harald Welte4d87f242009-03-10 19:43:44 +0000749 DEBUGPC(DNM, "AVAIL=%s(%02x) ", nm_avail_name(new_state.availability),
Harald Weltee0590df2009-02-15 03:34:15 +0000750 new_state.availability);
751 }
752 if (TLVP_PRESENT(&tp, NM_ATT_ADM_STATE)) {
753 new_state.administrative = *TLVP_VAL(&tp, NM_ATT_ADM_STATE);
Harald Welte5d4b1c22009-06-12 01:34:29 +0800754 DEBUGPC(DNM, "ADM=%02s ", nm_adm_name(new_state.administrative));
Harald Welte97ed1e72009-02-06 13:38:02 +0000755 }
756 DEBUGPC(DNM, "\n");
Harald Weltee0590df2009-02-15 03:34:15 +0000757
758 if (memcmp(&new_state, nm_state, sizeof(new_state))) {
759 /* Update the operational state of a given object in our in-memory data
760 * structures and send an event to the higher layer */
761 void *obj = objclass2obj(bts, foh->obj_class, &foh->obj_inst);
762 rc = nm_state_event(EVT_STATECHG_OPER, foh->obj_class, obj, nm_state, &new_state);
763 *nm_state = new_state;
764 }
765#if 0
Harald Welte22af0db2009-02-14 15:41:08 +0000766 if (op_state == 1) {
767 /* try to enable objects that are disabled */
768 abis_nm_opstart(bts, foh->obj_class,
769 foh->obj_inst.bts_nr,
770 foh->obj_inst.trx_nr,
771 foh->obj_inst.ts_nr);
772 }
Harald Weltee0590df2009-02-15 03:34:15 +0000773#endif
Harald Welte97ed1e72009-02-06 13:38:02 +0000774 return 0;
775}
776
Harald Welte0db97b22009-05-01 17:22:47 +0000777static int rx_fail_evt_rep(struct msgb *mb)
778{
779 struct abis_om_hdr *oh = msgb_l2(mb);
780 struct abis_om_fom_hdr *foh = msgb_l3(mb);
781 struct tlv_parsed tp;
782
783 DEBUGPC(DNM, "Failure Event Report ");
784
785 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
786
787 if (TLVP_PRESENT(&tp, NM_ATT_EVENT_TYPE))
788 DEBUGPC(DNM, "Type=%s ", event_type_name(*TLVP_VAL(&tp, NM_ATT_EVENT_TYPE)));
789 if (TLVP_PRESENT(&tp, NM_ATT_SEVERITY))
790 DEBUGPC(DNM, "Severity=%s ", severity_name(*TLVP_VAL(&tp, NM_ATT_SEVERITY)));
791
792 DEBUGPC(DNM, "\n");
793
794 return 0;
795}
796
Harald Welte97ed1e72009-02-06 13:38:02 +0000797static int abis_nm_rcvmsg_report(struct msgb *mb)
798{
799 struct abis_om_fom_hdr *foh = msgb_l3(mb);
800 u_int8_t mt = foh->msg_type;
801
Harald Welte23897662009-05-01 14:52:51 +0000802 DEBUGP(DNM, "OC=%s(%02x) INST=(%02x,%02x,%02x) ",
803 obj_class_name(foh->obj_class), foh->obj_class,
804 foh->obj_inst.bts_nr, foh->obj_inst.trx_nr,
805 foh->obj_inst.ts_nr);
806
Harald Welte97ed1e72009-02-06 13:38:02 +0000807 //nmh->cfg->report_cb(mb, foh);
808
809 switch (mt) {
810 case NM_MT_STATECHG_EVENT_REP:
811 return abis_nm_rx_statechg_rep(mb);
812 break;
Harald Welte34a99682009-02-13 02:41:40 +0000813 case NM_MT_SW_ACTIVATED_REP:
Harald Welte23897662009-05-01 14:52:51 +0000814 DEBUGPC(DNM, "Software Activated Report\n");
Harald Weltef9a8cc32009-05-01 15:39:49 +0000815 dispatch_signal(SS_NM, S_NM_SW_ACTIV_REP, mb);
Harald Welte34a99682009-02-13 02:41:40 +0000816 break;
Harald Weltee0590df2009-02-15 03:34:15 +0000817 case NM_MT_FAILURE_EVENT_REP:
Harald Welte0db97b22009-05-01 17:22:47 +0000818 rx_fail_evt_rep(mb);
Harald Weltef9a8cc32009-05-01 15:39:49 +0000819 dispatch_signal(SS_NM, S_NM_FAIL_REP, mb);
Harald Weltee0590df2009-02-15 03:34:15 +0000820 break;
Harald Weltec7310382009-08-08 00:02:36 +0200821 case NM_MT_TEST_REP:
822 DEBUGPC(DNM, "Test Report\n");
823 dispatch_signal(SS_NM, S_NM_TEST_REP, mb);
824 break;
Harald Weltee0590df2009-02-15 03:34:15 +0000825 default:
Harald Welte23897662009-05-01 14:52:51 +0000826 DEBUGPC(DNM, "reporting NM MT 0x%02x\n", mt);
Harald Weltee0590df2009-02-15 03:34:15 +0000827 break;
828
Harald Welte97ed1e72009-02-06 13:38:02 +0000829 };
830
Harald Welte97ed1e72009-02-06 13:38:02 +0000831 return 0;
832}
833
Harald Welte34a99682009-02-13 02:41:40 +0000834/* Activate the specified software into the BTS */
835static int ipacc_sw_activate(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1,
Mike Habena03f9772009-10-01 14:56:13 +0200836 u_int8_t i2, const u_int8_t *sw_desc, u_int8_t swdesc_len)
Harald Welte34a99682009-02-13 02:41:40 +0000837{
838 struct abis_om_hdr *oh;
839 struct msgb *msg = nm_msgb_alloc();
840 u_int8_t len = swdesc_len;
841 u_int8_t *trailer;
842
843 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
844 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, obj_class, i0, i1, i2);
845
846 trailer = msgb_put(msg, swdesc_len);
847 memcpy(trailer, sw_desc, swdesc_len);
848
849 return abis_nm_sendmsg(bts, msg);
850}
851
852static int abis_nm_rx_sw_act_req(struct msgb *mb)
853{
854 struct abis_om_hdr *oh = msgb_l2(mb);
855 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Mike Habena03f9772009-10-01 14:56:13 +0200856 struct tlv_parsed tp;
857 const u_int8_t *sw_config;
858 int sw_config_len;
859 int file_id_len;
Harald Welte5c1e4582009-02-15 11:57:29 +0000860 int nack = 0;
Harald Welte34a99682009-02-13 02:41:40 +0000861 int ret;
862
Harald Welte5c1e4582009-02-15 11:57:29 +0000863 DEBUGP(DNM, "Software Activate Request ");
Harald Welte34a99682009-02-13 02:41:40 +0000864
Harald Welte5c1e4582009-02-15 11:57:29 +0000865 if (foh->obj_class >= 0xf0 && foh->obj_class <= 0xf3) {
866 DEBUGPC(DNM, "NACKing for GPRS obj_class 0x%02x\n", foh->obj_class);
867 nack = 1;
868 } else
869 DEBUGPC(DNM, "ACKing and Activating\n");
870
871 ret = abis_nm_sw_act_req_ack(mb->trx->bts, foh->obj_class,
Harald Welte34a99682009-02-13 02:41:40 +0000872 foh->obj_inst.bts_nr,
873 foh->obj_inst.trx_nr,
Harald Welte5c1e4582009-02-15 11:57:29 +0000874 foh->obj_inst.ts_nr, nack,
Harald Welte34a99682009-02-13 02:41:40 +0000875 foh->data, oh->length-sizeof(*foh));
876
Harald Welte5c1e4582009-02-15 11:57:29 +0000877 if (nack)
878 return ret;
879
Mike Habena03f9772009-10-01 14:56:13 +0200880 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
881 sw_config = TLVP_VAL(&tp, NM_ATT_SW_CONFIG);
882 sw_config_len = TLVP_LEN(&tp, NM_ATT_SW_CONFIG);
883 if (!TLVP_PRESENT(&tp, NM_ATT_SW_CONFIG)) {
884 DEBUGP(DNM, "SW config not found! Can't continue.\n");
885 return -EINVAL;
886 } else {
887 DEBUGP(DNM, "Found SW config: %s\n", hexdump(sw_config, sw_config_len));
888 }
889
890 if (sw_config[0] != NM_ATT_SW_DESCR)
891 DEBUGP(DNM, "SW_DESCR attribute identifier not found!\n");
892 if (sw_config[1] != NM_ATT_FILE_ID)
893 DEBUGP(DNM, "FILE_ID attribute identifier not found!\n");
894 file_id_len = sw_config[2] * 256 + sw_config[3];
895
896 /* Assumes first SW file in list is the one to be activated */
897 /* sw_config + 4 to skip over 2 attribute ID bytes and 16-bit length field */
Harald Welte34a99682009-02-13 02:41:40 +0000898 return ipacc_sw_activate(mb->trx->bts, foh->obj_class,
899 foh->obj_inst.bts_nr,
900 foh->obj_inst.trx_nr,
901 foh->obj_inst.ts_nr,
Mike Habena03f9772009-10-01 14:56:13 +0200902 sw_config + 4,
903 file_id_len);
Harald Welte34a99682009-02-13 02:41:40 +0000904}
905
Harald Weltee0590df2009-02-15 03:34:15 +0000906/* Receive a CHANGE_ADM_STATE_ACK, parse the TLV and update local state */
907static int abis_nm_rx_chg_adm_state_ack(struct msgb *mb)
908{
909 struct abis_om_hdr *oh = msgb_l2(mb);
910 struct abis_om_fom_hdr *foh = msgb_l3(mb);
911 struct tlv_parsed tp;
912 u_int8_t adm_state;
913
Harald Welte03133942009-02-18 19:51:53 +0000914 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Weltee0590df2009-02-15 03:34:15 +0000915 if (!TLVP_PRESENT(&tp, NM_ATT_ADM_STATE))
916 return -EINVAL;
917
918 adm_state = *TLVP_VAL(&tp, NM_ATT_ADM_STATE);
919
920 return update_admstate(mb->trx->bts, foh->obj_class, &foh->obj_inst, adm_state);
921}
922
Harald Welteee670472009-02-22 21:58:49 +0000923static int abis_nm_rx_lmt_event(struct msgb *mb)
924{
925 struct abis_om_hdr *oh = msgb_l2(mb);
926 struct abis_om_fom_hdr *foh = msgb_l3(mb);
927 struct tlv_parsed tp;
928
929 DEBUGP(DNM, "LMT Event ");
930 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
931 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_LOGON_SESSION) &&
932 TLVP_LEN(&tp, NM_ATT_BS11_LMT_LOGON_SESSION) >= 1) {
933 u_int8_t onoff = *TLVP_VAL(&tp, NM_ATT_BS11_LMT_LOGON_SESSION);
934 DEBUGPC(DNM, "LOG%s ", onoff ? "ON" : "OFF");
935 }
936 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV) &&
937 TLVP_LEN(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV) >= 1) {
938 u_int8_t level = *TLVP_VAL(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV);
939 DEBUGPC(DNM, "Level=%u ", level);
940 }
941 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_USER_NAME) &&
942 TLVP_LEN(&tp, NM_ATT_BS11_LMT_USER_NAME) >= 1) {
943 char *name = (char *) TLVP_VAL(&tp, NM_ATT_BS11_LMT_USER_NAME);
944 DEBUGPC(DNM, "Username=%s ", name);
945 }
946 DEBUGPC(DNM, "\n");
947 /* FIXME: parse LMT LOGON TIME */
948 return 0;
949}
950
Harald Welte52b1f982008-12-23 20:25:15 +0000951/* Receive a OML NM Message from BTS */
Harald Welte8470bf22008-12-25 23:28:35 +0000952static int abis_nm_rcvmsg_fom(struct msgb *mb)
Harald Welte52b1f982008-12-23 20:25:15 +0000953{
Harald Welte6c96ba52009-05-01 13:03:40 +0000954 struct abis_om_hdr *oh = msgb_l2(mb);
Harald Welte52b1f982008-12-23 20:25:15 +0000955 struct abis_om_fom_hdr *foh = msgb_l3(mb);
956 u_int8_t mt = foh->msg_type;
957
958 /* check for unsolicited message */
Harald Welte97ed1e72009-02-06 13:38:02 +0000959 if (is_report(mt))
960 return abis_nm_rcvmsg_report(mb);
Harald Welte52b1f982008-12-23 20:25:15 +0000961
Harald Welte4724f992009-01-18 18:01:49 +0000962 if (is_in_arr(mt, sw_load_msgs, ARRAY_SIZE(sw_load_msgs)))
963 return abis_nm_rcvmsg_sw(mb);
964
Harald Welte78fc0d42009-02-19 02:50:57 +0000965 if (is_in_arr(mt, nacks, ARRAY_SIZE(nacks))) {
Harald Welte6c96ba52009-05-01 13:03:40 +0000966 struct tlv_parsed tp;
Harald Welte78fc0d42009-02-19 02:50:57 +0000967 if (nack_names[mt])
Harald Welte6c96ba52009-05-01 13:03:40 +0000968 DEBUGP(DNM, "%s NACK ", nack_names[mt]);
969 /* FIXME: NACK cause */
Harald Welte78fc0d42009-02-19 02:50:57 +0000970 else
Harald Welte6c96ba52009-05-01 13:03:40 +0000971 DEBUGP(DNM, "NACK 0x%02x ", mt);
972
973 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
974 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
975 DEBUGPC(DNM, "CAUSE=%s\n",
976 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
977 else
978 DEBUGPC(DNM, "\n");
Holger Hans Peter Freyther500f3ca2009-06-10 10:48:14 +0200979
980 dispatch_signal(SS_NM, S_NM_NACK, (void*) ((long)mt));
981 return 0;
Harald Welte78fc0d42009-02-19 02:50:57 +0000982 }
Harald Weltead384642008-12-26 10:20:07 +0000983#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000984 /* check if last message is to be acked */
985 if (is_ack_nack(nmh->last_msgtype)) {
986 if (mt == MT_ACK(nmh->last_msgtype)) {
987 fprintf(stderr, "received ACK (0x%x)\n",
988 foh->msg_type);
989 /* we got our ACK, continue sending the next msg */
990 } else if (mt == MT_NACK(nmh->last_msgtype)) {
991 /* we got a NACK, signal this to the caller */
992 fprintf(stderr, "received NACK (0x%x)\n",
993 foh->msg_type);
994 /* FIXME: somehow signal this to the caller */
995 } else {
996 /* really strange things happen */
997 return -EINVAL;
998 }
999 }
Harald Weltead384642008-12-26 10:20:07 +00001000#endif
1001
Harald Welte97ed1e72009-02-06 13:38:02 +00001002 switch (mt) {
Harald Weltee0590df2009-02-15 03:34:15 +00001003 case NM_MT_CHG_ADM_STATE_ACK:
1004 return abis_nm_rx_chg_adm_state_ack(mb);
1005 break;
Harald Welte34a99682009-02-13 02:41:40 +00001006 case NM_MT_SW_ACT_REQ:
1007 return abis_nm_rx_sw_act_req(mb);
1008 break;
Harald Welte97ed1e72009-02-06 13:38:02 +00001009 case NM_MT_BS11_LMT_SESSION:
Harald Welteee670472009-02-22 21:58:49 +00001010 return abis_nm_rx_lmt_event(mb);
Harald Welte97ed1e72009-02-06 13:38:02 +00001011 break;
Harald Welte1989c082009-08-06 17:58:31 +02001012 case NM_MT_CONN_MDROP_LINK_ACK:
1013 DEBUGP(DNM, "CONN MDROP LINK ACK\n");
1014 break;
Harald Welte97ed1e72009-02-06 13:38:02 +00001015 }
1016
Harald Weltead384642008-12-26 10:20:07 +00001017 return 0;
Harald Welte52b1f982008-12-23 20:25:15 +00001018}
1019
Harald Welte677c21f2009-02-17 13:22:23 +00001020static int abis_nm_rx_ipacc(struct msgb *mb);
1021
1022static int abis_nm_rcvmsg_manuf(struct msgb *mb)
1023{
1024 int rc;
1025 int bts_type = mb->trx->bts->type;
1026
1027 switch (bts_type) {
1028 case GSM_BTS_TYPE_NANOBTS_900:
1029 case GSM_BTS_TYPE_NANOBTS_1800:
1030 rc = abis_nm_rx_ipacc(mb);
1031 break;
1032 default:
1033 fprintf(stderr, "don't know how to parse OML for this "
1034 "BTS type (%u)\n", bts_type);
1035 rc = 0;
1036 break;
1037 }
1038
1039 return rc;
1040}
1041
Harald Welte52b1f982008-12-23 20:25:15 +00001042/* High-Level API */
1043/* Entry-point where L2 OML from BTS enters the NM code */
Harald Welte8470bf22008-12-25 23:28:35 +00001044int abis_nm_rcvmsg(struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +00001045{
Harald Welte52b1f982008-12-23 20:25:15 +00001046 struct abis_om_hdr *oh = msgb_l2(msg);
Harald Welte677c21f2009-02-17 13:22:23 +00001047 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +00001048
1049 /* Various consistency checks */
1050 if (oh->placement != ABIS_OM_PLACEMENT_ONLY) {
1051 fprintf(stderr, "ABIS OML placement 0x%x not supported\n",
1052 oh->placement);
1053 return -EINVAL;
1054 }
1055 if (oh->sequence != 0) {
1056 fprintf(stderr, "ABIS OML sequence 0x%x != 0x00\n",
1057 oh->sequence);
1058 return -EINVAL;
1059 }
Harald Welte702d8702008-12-26 20:25:35 +00001060#if 0
Holger Freytherca362a62009-01-04 21:05:01 +00001061 unsigned int l2_len = msg->tail - (u_int8_t *)msgb_l2(msg);
1062 unsigned int hlen = sizeof(*oh) + sizeof(struct abis_om_fom_hdr);
Harald Welte702d8702008-12-26 20:25:35 +00001063 if (oh->length + hlen > l2_len) {
Harald Welte52b1f982008-12-23 20:25:15 +00001064 fprintf(stderr, "ABIS OML truncated message (%u > %u)\n",
1065 oh->length + sizeof(*oh), l2_len);
1066 return -EINVAL;
1067 }
Harald Welte702d8702008-12-26 20:25:35 +00001068 if (oh->length + hlen < l2_len)
1069 fprintf(stderr, "ABIS OML message with extra trailer?!? (oh->len=%d, sizeof_oh=%d l2_len=%d\n", oh->length, sizeof(*oh), l2_len);
1070#endif
Harald Weltead384642008-12-26 10:20:07 +00001071 msg->l3h = (unsigned char *)oh + sizeof(*oh);
Harald Welte52b1f982008-12-23 20:25:15 +00001072
1073 switch (oh->mdisc) {
1074 case ABIS_OM_MDISC_FOM:
Harald Welte8470bf22008-12-25 23:28:35 +00001075 rc = abis_nm_rcvmsg_fom(msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001076 break;
Harald Welte677c21f2009-02-17 13:22:23 +00001077 case ABIS_OM_MDISC_MANUF:
1078 rc = abis_nm_rcvmsg_manuf(msg);
1079 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001080 case ABIS_OM_MDISC_MMI:
1081 case ABIS_OM_MDISC_TRAU:
Harald Welte677c21f2009-02-17 13:22:23 +00001082 fprintf(stderr, "unimplemented ABIS OML message discriminator 0x%x\n",
1083 oh->mdisc);
1084 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001085 default:
1086 fprintf(stderr, "unknown ABIS OML message discriminator 0x%x\n",
1087 oh->mdisc);
1088 return -EINVAL;
1089 }
1090
Harald Weltead384642008-12-26 10:20:07 +00001091 msgb_free(msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001092 return rc;
1093}
1094
1095#if 0
1096/* initialized all resources */
1097struct abis_nm_h *abis_nm_init(struct abis_nm_cfg *cfg)
1098{
1099 struct abis_nm_h *nmh;
1100
1101 nmh = malloc(sizeof(*nmh));
1102 if (!nmh)
1103 return NULL;
1104
1105 nmh->cfg = cfg;
1106
1107 return nmh;
1108}
1109
1110/* free all resources */
1111void abis_nm_fini(struct abis_nm_h *nmh)
1112{
1113 free(nmh);
1114}
1115#endif
1116
1117/* Here we are trying to define a high-level API that can be used by
1118 * the actual BSC implementation. However, the architecture is currently
1119 * still under design. Ideally the calls to this API would be synchronous,
1120 * while the underlying stack behind the APi runs in a traditional select
1121 * based state machine.
1122 */
1123
Harald Welte4724f992009-01-18 18:01:49 +00001124/* 6.2 Software Load: */
1125enum sw_state {
1126 SW_STATE_NONE,
1127 SW_STATE_WAIT_INITACK,
1128 SW_STATE_WAIT_SEGACK,
1129 SW_STATE_WAIT_ENDACK,
1130 SW_STATE_WAIT_ACTACK,
1131 SW_STATE_ERROR,
1132};
Harald Welte52b1f982008-12-23 20:25:15 +00001133
Harald Welte52b1f982008-12-23 20:25:15 +00001134struct abis_nm_sw {
Harald Welte4724f992009-01-18 18:01:49 +00001135 struct gsm_bts *bts;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001136 gsm_cbfn *cbfn;
1137 void *cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +00001138 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001139
Harald Welte52b1f982008-12-23 20:25:15 +00001140 /* this will become part of the SW LOAD INITIATE */
1141 u_int8_t obj_class;
1142 u_int8_t obj_instance[3];
Harald Welte4724f992009-01-18 18:01:49 +00001143
1144 u_int8_t file_id[255];
1145 u_int8_t file_id_len;
1146
1147 u_int8_t file_version[255];
1148 u_int8_t file_version_len;
1149
1150 u_int8_t window_size;
1151 u_int8_t seg_in_window;
1152
1153 int fd;
1154 FILE *stream;
1155 enum sw_state state;
Harald Welte1602ade2009-01-29 21:12:39 +00001156 int last_seg;
Harald Welte52b1f982008-12-23 20:25:15 +00001157};
1158
Harald Welte4724f992009-01-18 18:01:49 +00001159static struct abis_nm_sw g_sw;
1160
1161/* 6.2.1 / 8.3.1: Load Data Initiate */
1162static int sw_load_init(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +00001163{
Harald Welte4724f992009-01-18 18:01:49 +00001164 struct abis_om_hdr *oh;
1165 struct msgb *msg = nm_msgb_alloc();
1166 u_int8_t len = 3*2 + sw->file_id_len + sw->file_version_len;
1167
1168 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1169 fill_om_fom_hdr(oh, len, NM_MT_LOAD_INIT, sw->obj_class,
1170 sw->obj_instance[0], sw->obj_instance[1],
1171 sw->obj_instance[2]);
1172
1173 /* FIXME: this is BS11 specific format */
1174 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1175 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1176 sw->file_version);
1177 msgb_tv_put(msg, NM_ATT_WINDOW_SIZE, sw->window_size);
1178
1179 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001180}
1181
Harald Welte1602ade2009-01-29 21:12:39 +00001182static int is_last_line(FILE *stream)
1183{
1184 char next_seg_buf[256];
1185 long pos;
1186
1187 /* check if we're sending the last line */
1188 pos = ftell(stream);
1189 if (!fgets(next_seg_buf, sizeof(next_seg_buf)-2, stream)) {
1190 fseek(stream, pos, SEEK_SET);
1191 return 1;
1192 }
1193
1194 fseek(stream, pos, SEEK_SET);
1195 return 0;
1196}
1197
Harald Welte4724f992009-01-18 18:01:49 +00001198/* 6.2.2 / 8.3.2 Load Data Segment */
1199static int sw_load_segment(struct abis_nm_sw *sw)
1200{
1201 struct abis_om_hdr *oh;
1202 struct msgb *msg = nm_msgb_alloc();
1203 char seg_buf[256];
1204 char *line_buf = seg_buf+2;
Harald Welte3b8ba212009-01-29 12:27:58 +00001205 unsigned char *tlv;
Harald Welte4724f992009-01-18 18:01:49 +00001206 u_int8_t len;
Harald Welte4724f992009-01-18 18:01:49 +00001207
1208 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte3b8ba212009-01-29 12:27:58 +00001209
1210 switch (sw->bts->type) {
1211 case GSM_BTS_TYPE_BS11:
1212 if (fgets(line_buf, sizeof(seg_buf)-2, sw->stream) == NULL) {
1213 perror("fgets reading segment");
1214 return -EINVAL;
1215 }
1216 seg_buf[0] = 0x00;
Harald Welte1602ade2009-01-29 21:12:39 +00001217
1218 /* check if we're sending the last line */
1219 sw->last_seg = is_last_line(sw->stream);
1220 if (sw->last_seg)
1221 seg_buf[1] = 0;
1222 else
1223 seg_buf[1] = 1 + sw->seg_in_window++;
Harald Welte3b8ba212009-01-29 12:27:58 +00001224
1225 len = strlen(line_buf) + 2;
1226 tlv = msgb_put(msg, TLV_GROSS_LEN(len));
1227 tlv_put(tlv, NM_ATT_BS11_FILE_DATA, len, (u_int8_t *)seg_buf);
1228 /* BS11 wants CR + LF in excess of the TLV length !?! */
1229 tlv[1] -= 2;
1230
1231 /* we only now know the exact length for the OM hdr */
1232 len = strlen(line_buf)+2;
1233 break;
1234 default:
1235 /* FIXME: Other BTS types */
1236 return -1;
Harald Welte4724f992009-01-18 18:01:49 +00001237 }
Harald Welte4724f992009-01-18 18:01:49 +00001238
Harald Welte4724f992009-01-18 18:01:49 +00001239 fill_om_fom_hdr(oh, len, NM_MT_LOAD_SEG, sw->obj_class,
1240 sw->obj_instance[0], sw->obj_instance[1],
1241 sw->obj_instance[2]);
1242
1243 return abis_nm_sendmsg(sw->bts, msg);
1244}
1245
1246/* 6.2.4 / 8.3.4 Load Data End */
1247static int sw_load_end(struct abis_nm_sw *sw)
1248{
1249 struct abis_om_hdr *oh;
1250 struct msgb *msg = nm_msgb_alloc();
1251 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
1252
1253 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1254 fill_om_fom_hdr(oh, len, NM_MT_LOAD_END, sw->obj_class,
1255 sw->obj_instance[0], sw->obj_instance[1],
1256 sw->obj_instance[2]);
1257
1258 /* FIXME: this is BS11 specific format */
1259 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1260 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1261 sw->file_version);
1262
1263 return abis_nm_sendmsg(sw->bts, msg);
1264}
Harald Welte5e4d1b32009-02-01 13:36:56 +00001265
Harald Welte52b1f982008-12-23 20:25:15 +00001266/* Activate the specified software into the BTS */
Harald Welte4724f992009-01-18 18:01:49 +00001267static int sw_activate(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +00001268{
Harald Welte4724f992009-01-18 18:01:49 +00001269 struct abis_om_hdr *oh;
1270 struct msgb *msg = nm_msgb_alloc();
1271 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
Harald Welte52b1f982008-12-23 20:25:15 +00001272
Harald Welte4724f992009-01-18 18:01:49 +00001273 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1274 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, sw->obj_class,
1275 sw->obj_instance[0], sw->obj_instance[1],
1276 sw->obj_instance[2]);
1277
1278 /* FIXME: this is BS11 specific format */
1279 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1280 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1281 sw->file_version);
1282
1283 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001284}
Harald Welte4724f992009-01-18 18:01:49 +00001285
1286static int sw_open_file(struct abis_nm_sw *sw, const char *fname)
1287{
1288 char file_id[12+1];
1289 char file_version[80+1];
1290 int rc;
1291
1292 sw->fd = open(fname, O_RDONLY);
1293 if (sw->fd < 0)
1294 return sw->fd;
1295
1296 switch (sw->bts->type) {
1297 case GSM_BTS_TYPE_BS11:
1298 sw->stream = fdopen(sw->fd, "r");
1299 if (!sw->stream) {
1300 perror("fdopen");
1301 return -1;
1302 }
1303 /* read first line and parse file ID and VERSION */
Harald Welte3b8ba212009-01-29 12:27:58 +00001304 rc = fscanf(sw->stream, "@(#)%12s:%80s\r\n",
Harald Welte4724f992009-01-18 18:01:49 +00001305 file_id, file_version);
1306 if (rc != 2) {
1307 perror("parsing header line of software file");
1308 return -1;
1309 }
1310 strcpy((char *)sw->file_id, file_id);
1311 sw->file_id_len = strlen(file_id);
1312 strcpy((char *)sw->file_version, file_version);
1313 sw->file_version_len = strlen(file_version);
1314 /* rewind to start of file */
Harald Welte3b8ba212009-01-29 12:27:58 +00001315 rewind(sw->stream);
Harald Welte4724f992009-01-18 18:01:49 +00001316 break;
1317 default:
1318 /* We don't know how to treat them yet */
1319 close(sw->fd);
1320 return -EINVAL;
1321 }
1322
1323 return 0;
1324}
1325
1326static void sw_close_file(struct abis_nm_sw *sw)
1327{
1328 switch (sw->bts->type) {
1329 case GSM_BTS_TYPE_BS11:
1330 fclose(sw->stream);
1331 break;
1332 default:
1333 close(sw->fd);
1334 break;
1335 }
1336}
1337
1338/* Fill the window */
1339static int sw_fill_window(struct abis_nm_sw *sw)
1340{
1341 int rc;
1342
1343 while (sw->seg_in_window < sw->window_size) {
1344 rc = sw_load_segment(sw);
1345 if (rc < 0)
1346 return rc;
Harald Welte1602ade2009-01-29 21:12:39 +00001347 if (sw->last_seg)
1348 break;
Harald Welte4724f992009-01-18 18:01:49 +00001349 }
1350 return 0;
1351}
1352
1353/* callback function from abis_nm_rcvmsg() handler */
1354static int abis_nm_rcvmsg_sw(struct msgb *mb)
1355{
1356 struct abis_om_fom_hdr *foh = msgb_l3(mb);
1357 int rc = -1;
1358 struct abis_nm_sw *sw = &g_sw;
1359 enum sw_state old_state = sw->state;
1360
Harald Welte3ffd1372009-02-01 22:15:49 +00001361 //DEBUGP(DNM, "state %u, NM MT 0x%02x\n", sw->state, foh->msg_type);
Harald Welte4724f992009-01-18 18:01:49 +00001362
1363 switch (sw->state) {
1364 case SW_STATE_WAIT_INITACK:
1365 switch (foh->msg_type) {
1366 case NM_MT_LOAD_INIT_ACK:
1367 /* fill window with segments */
Harald Welte5e4d1b32009-02-01 13:36:56 +00001368 if (sw->cbfn)
1369 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1370 NM_MT_LOAD_INIT_ACK, mb,
1371 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001372 rc = sw_fill_window(sw);
1373 sw->state = SW_STATE_WAIT_SEGACK;
1374 break;
1375 case NM_MT_LOAD_INIT_NACK:
Harald Welte3ffd1372009-02-01 22:15:49 +00001376 if (sw->forced) {
1377 DEBUGP(DNM, "FORCED: Ignoring Software Load "
1378 "Init NACK\n");
1379 if (sw->cbfn)
1380 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1381 NM_MT_LOAD_INIT_ACK, mb,
1382 sw->cb_data, NULL);
1383 rc = sw_fill_window(sw);
1384 sw->state = SW_STATE_WAIT_SEGACK;
1385 } else {
1386 DEBUGP(DNM, "Software Load Init NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001387 /* FIXME: cause */
Harald Welte3ffd1372009-02-01 22:15:49 +00001388 if (sw->cbfn)
1389 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1390 NM_MT_LOAD_INIT_NACK, mb,
1391 sw->cb_data, NULL);
1392 sw->state = SW_STATE_ERROR;
1393 }
Harald Welte4724f992009-01-18 18:01:49 +00001394 break;
1395 }
1396 break;
1397 case SW_STATE_WAIT_SEGACK:
1398 switch (foh->msg_type) {
1399 case NM_MT_LOAD_SEG_ACK:
Harald Welte3ffd1372009-02-01 22:15:49 +00001400 if (sw->cbfn)
1401 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1402 NM_MT_LOAD_SEG_ACK, mb,
1403 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001404 sw->seg_in_window = 0;
Harald Welte1602ade2009-01-29 21:12:39 +00001405 if (!sw->last_seg) {
1406 /* fill window with more segments */
1407 rc = sw_fill_window(sw);
1408 sw->state = SW_STATE_WAIT_SEGACK;
1409 } else {
1410 /* end the transfer */
1411 sw->state = SW_STATE_WAIT_ENDACK;
1412 rc = sw_load_end(sw);
1413 }
Harald Welte4724f992009-01-18 18:01:49 +00001414 break;
1415 }
1416 break;
1417 case SW_STATE_WAIT_ENDACK:
1418 switch (foh->msg_type) {
1419 case NM_MT_LOAD_END_ACK:
1420 sw_close_file(sw);
Harald Welte5e4d1b32009-02-01 13:36:56 +00001421 DEBUGP(DNM, "Software Load End (BTS %u)\n",
1422 sw->bts->nr);
1423 sw->state = SW_STATE_NONE;
1424 if (sw->cbfn)
1425 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1426 NM_MT_LOAD_END_ACK, mb,
1427 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001428 break;
1429 case NM_MT_LOAD_END_NACK:
Holger Freyther31338a12009-02-06 17:43:50 +00001430 if (sw->forced) {
1431 DEBUGP(DNM, "FORCED: Ignoring Software Load"
1432 "End NACK\n");
1433 sw->state = SW_STATE_NONE;
1434 if (sw->cbfn)
1435 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1436 NM_MT_LOAD_END_ACK, mb,
1437 sw->cb_data, NULL);
1438 } else {
1439 DEBUGP(DNM, "Software Load End NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001440 /* FIXME: cause */
Holger Freyther31338a12009-02-06 17:43:50 +00001441 sw->state = SW_STATE_ERROR;
1442 if (sw->cbfn)
1443 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1444 NM_MT_LOAD_END_NACK, mb,
1445 sw->cb_data, NULL);
1446 }
Harald Welte4724f992009-01-18 18:01:49 +00001447 break;
1448 }
1449 case SW_STATE_WAIT_ACTACK:
1450 switch (foh->msg_type) {
1451 case NM_MT_ACTIVATE_SW_ACK:
1452 /* we're done */
Harald Welte5e4d1b32009-02-01 13:36:56 +00001453 DEBUGP(DNM, "Activate Software DONE!\n");
Harald Welte4724f992009-01-18 18:01:49 +00001454 sw->state = SW_STATE_NONE;
1455 rc = 0;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001456 if (sw->cbfn)
1457 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1458 NM_MT_ACTIVATE_SW_ACK, mb,
1459 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001460 break;
1461 case NM_MT_ACTIVATE_SW_NACK:
Harald Welte1602ade2009-01-29 21:12:39 +00001462 DEBUGP(DNM, "Activate Software NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001463 /* FIXME: cause */
Harald Welte4724f992009-01-18 18:01:49 +00001464 sw->state = SW_STATE_ERROR;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001465 if (sw->cbfn)
1466 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1467 NM_MT_ACTIVATE_SW_NACK, mb,
1468 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001469 break;
1470 }
1471 case SW_STATE_NONE:
Harald Weltea994a482009-05-01 15:54:23 +00001472 switch (foh->msg_type) {
1473 case NM_MT_ACTIVATE_SW_ACK:
1474 rc = 0;
1475 break;
1476 }
1477 break;
Harald Welte4724f992009-01-18 18:01:49 +00001478 case SW_STATE_ERROR:
1479 break;
1480 }
1481
1482 if (rc)
Harald Weltea994a482009-05-01 15:54:23 +00001483 DEBUGP(DNM, "unexpected NM MT 0x%02x in state %u -> %u\n",
Harald Welte4724f992009-01-18 18:01:49 +00001484 foh->msg_type, old_state, sw->state);
1485
1486 return rc;
1487}
1488
1489/* Load the specified software into the BTS */
1490int abis_nm_software_load(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00001491 u_int8_t win_size, int forced,
1492 gsm_cbfn *cbfn, void *cb_data)
Harald Welte4724f992009-01-18 18:01:49 +00001493{
1494 struct abis_nm_sw *sw = &g_sw;
1495 int rc;
1496
Harald Welte5e4d1b32009-02-01 13:36:56 +00001497 DEBUGP(DNM, "Software Load (BTS %u, File \"%s\")\n",
1498 bts->nr, fname);
1499
Harald Welte4724f992009-01-18 18:01:49 +00001500 if (sw->state != SW_STATE_NONE)
1501 return -EBUSY;
1502
1503 sw->bts = bts;
1504 sw->obj_class = NM_OC_SITE_MANAGER;
1505 sw->obj_instance[0] = 0xff;
1506 sw->obj_instance[1] = 0xff;
1507 sw->obj_instance[2] = 0xff;
1508 sw->window_size = win_size;
1509 sw->state = SW_STATE_WAIT_INITACK;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001510 sw->cbfn = cbfn;
1511 sw->cb_data = cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +00001512 sw->forced = forced;
Harald Welte4724f992009-01-18 18:01:49 +00001513
1514 rc = sw_open_file(sw, fname);
1515 if (rc < 0) {
1516 sw->state = SW_STATE_NONE;
1517 return rc;
1518 }
1519
1520 return sw_load_init(sw);
1521}
Harald Welte52b1f982008-12-23 20:25:15 +00001522
Harald Welte1602ade2009-01-29 21:12:39 +00001523int abis_nm_software_load_status(struct gsm_bts *bts)
1524{
1525 struct abis_nm_sw *sw = &g_sw;
1526 struct stat st;
1527 int rc, percent;
1528
1529 rc = fstat(sw->fd, &st);
1530 if (rc < 0) {
1531 perror("ERROR during stat");
1532 return rc;
1533 }
1534
1535 percent = (ftell(sw->stream) * 100) / st.st_size;
1536 return percent;
1537}
1538
Harald Welte5e4d1b32009-02-01 13:36:56 +00001539/* Activate the specified software into the BTS */
1540int abis_nm_software_activate(struct gsm_bts *bts, const char *fname,
1541 gsm_cbfn *cbfn, void *cb_data)
1542{
1543 struct abis_nm_sw *sw = &g_sw;
1544 int rc;
1545
1546 DEBUGP(DNM, "Activating Software (BTS %u, File \"%s\")\n",
1547 bts->nr, fname);
1548
1549 if (sw->state != SW_STATE_NONE)
1550 return -EBUSY;
1551
1552 sw->bts = bts;
1553 sw->obj_class = NM_OC_SITE_MANAGER;
1554 sw->obj_instance[0] = 0xff;
1555 sw->obj_instance[1] = 0xff;
1556 sw->obj_instance[2] = 0xff;
1557 sw->state = SW_STATE_WAIT_ACTACK;
1558 sw->cbfn = cbfn;
1559 sw->cb_data = cb_data;
1560
1561 /* Open the file in order to fill some sw struct members */
1562 rc = sw_open_file(sw, fname);
1563 if (rc < 0) {
1564 sw->state = SW_STATE_NONE;
1565 return rc;
1566 }
1567 sw_close_file(sw);
1568
1569 return sw_activate(sw);
1570}
1571
Harald Welte8470bf22008-12-25 23:28:35 +00001572static void fill_nm_channel(struct abis_nm_channel *ch, u_int8_t bts_port,
Harald Welte52b1f982008-12-23 20:25:15 +00001573 u_int8_t ts_nr, u_int8_t subslot_nr)
1574{
Harald Welteadaf08b2009-01-18 11:08:10 +00001575 ch->attrib = NM_ATT_ABIS_CHANNEL;
Harald Welte52b1f982008-12-23 20:25:15 +00001576 ch->bts_port = bts_port;
1577 ch->timeslot = ts_nr;
1578 ch->subslot = subslot_nr;
1579}
1580
1581int abis_nm_establish_tei(struct gsm_bts *bts, u_int8_t trx_nr,
1582 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot,
1583 u_int8_t tei)
1584{
1585 struct abis_om_hdr *oh;
1586 struct abis_nm_channel *ch;
Harald Welte702d8702008-12-26 20:25:35 +00001587 u_int8_t len = sizeof(*ch) + 2;
Harald Welte8470bf22008-12-25 23:28:35 +00001588 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001589
1590 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1591 fill_om_fom_hdr(oh, len, NM_MT_ESTABLISH_TEI, NM_OC_RADIO_CARRIER,
1592 bts->bts_nr, trx_nr, 0xff);
1593
Harald Welte8470bf22008-12-25 23:28:35 +00001594 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte52b1f982008-12-23 20:25:15 +00001595
1596 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1597 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1598
1599 return abis_nm_sendmsg(bts, msg);
1600}
1601
1602/* connect signalling of one (BTS,TRX) to a particular timeslot on the E1 */
1603int abis_nm_conn_terr_sign(struct gsm_bts_trx *trx,
1604 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot)
1605{
Harald Welte8470bf22008-12-25 23:28:35 +00001606 struct gsm_bts *bts = trx->bts;
Harald Welte52b1f982008-12-23 20:25:15 +00001607 struct abis_om_hdr *oh;
1608 struct abis_nm_channel *ch;
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 Welte6f676a32009-01-18 14:27:48 +00001612 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_SIGN,
Harald Welte52b1f982008-12-23 20:25:15 +00001613 NM_OC_RADIO_CARRIER, bts->bts_nr, trx->nr, 0xff);
1614
1615 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1616 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1617
1618 return abis_nm_sendmsg(bts, msg);
1619}
1620
1621#if 0
1622int abis_nm_disc_terr_sign(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1623 struct abis_nm_abis_channel *chan)
1624{
1625}
1626#endif
1627
1628int abis_nm_conn_terr_traf(struct gsm_bts_trx_ts *ts,
1629 u_int8_t e1_port, u_int8_t e1_timeslot,
1630 u_int8_t e1_subslot)
1631{
1632 struct gsm_bts *bts = ts->trx->bts;
1633 struct abis_om_hdr *oh;
1634 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +00001635 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001636
1637 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1638 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_TRAF,
Harald Welteb110cee2009-02-18 03:42:35 +00001639 NM_OC_CHANNEL, bts->bts_nr, ts->trx->nr, ts->nr);
Harald Welte52b1f982008-12-23 20:25:15 +00001640
1641 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1642 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1643
Harald Weltef325eb42009-02-19 17:07:39 +00001644 DEBUGP(DNM, "CONNECT TERR TRAF Um=%s E1=(%u,%u,%u)\n",
1645 gsm_ts_name(ts),
Harald Welteb110cee2009-02-18 03:42:35 +00001646 e1_port, e1_timeslot, e1_subslot);
1647
Harald Welte52b1f982008-12-23 20:25:15 +00001648 return abis_nm_sendmsg(bts, msg);
1649}
1650
1651#if 0
1652int abis_nm_disc_terr_traf(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1653 struct abis_nm_abis_channel *chan,
1654 u_int8_t subchan)
1655{
1656}
1657#endif
1658
Harald Welte22af0db2009-02-14 15:41:08 +00001659/* Chapter 8.6.1 */
1660int abis_nm_set_bts_attr(struct gsm_bts *bts, u_int8_t *attr, int attr_len)
1661{
1662 struct abis_om_hdr *oh;
1663 struct msgb *msg = nm_msgb_alloc();
1664 u_int8_t *cur;
1665
1666 DEBUGP(DNM, "Set BTS Attr (bts=%d)\n", bts->nr);
1667
1668 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte191280d2009-05-01 13:20:04 +00001669 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 +00001670 cur = msgb_put(msg, attr_len);
1671 memcpy(cur, attr, attr_len);
1672
1673 return abis_nm_sendmsg(bts, msg);
1674}
1675
1676/* Chapter 8.6.2 */
1677int abis_nm_set_radio_attr(struct gsm_bts_trx *trx, u_int8_t *attr, int attr_len)
1678{
1679 struct abis_om_hdr *oh;
1680 struct msgb *msg = nm_msgb_alloc();
1681 u_int8_t *cur;
1682
1683 DEBUGP(DNM, "Set TRX Attr (bts=%d,trx=%d)\n", trx->bts->nr, trx->nr);
1684
1685 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1686 fill_om_fom_hdr(oh, attr_len, NM_MT_SET_RADIO_ATTR, NM_OC_RADIO_CARRIER,
Harald Welte191280d2009-05-01 13:20:04 +00001687 trx->bts->bts_nr, trx->nr, 0xff);
Harald Welte22af0db2009-02-14 15:41:08 +00001688 cur = msgb_put(msg, attr_len);
1689 memcpy(cur, attr, attr_len);
1690
1691 return abis_nm_sendmsg(trx->bts, msg);
1692}
1693
Harald Welte39c7deb2009-08-09 21:49:48 +02001694static int verify_chan_comb(struct gsm_bts_trx_ts *ts, u_int8_t chan_comb)
1695{
1696 int i;
1697
1698 /* As it turns out, the BS-11 has some very peculiar restrictions
1699 * on the channel combinations it allows */
1700 if (ts->trx->bts->type == GSM_BTS_TYPE_BS11) {
1701 switch (chan_comb) {
1702 case NM_CHANC_TCHHalf:
1703 case NM_CHANC_TCHHalf2:
1704 /* not supported */
1705 return -EINVAL;
1706 case NM_CHANC_SDCCH:
1707 /* only one SDCCH/8 per TRX */
1708 for (i = 0; i < TRX_NR_TS; i++) {
1709 if (i == ts->nr)
1710 continue;
1711 if (ts->trx->ts[i].nm_chan_comb ==
1712 NM_CHANC_SDCCH)
1713 return -EINVAL;
1714 }
1715 /* not allowed for TS0 of BCCH-TRX */
1716 if (ts->trx == ts->trx->bts->c0 &&
1717 ts->nr == 0)
1718 return -EINVAL;
1719 /* not on the same TRX that has a BCCH+SDCCH4
1720 * combination */
1721 if (ts->trx == ts->trx->bts->c0 &&
1722 (ts->trx->ts[0].nm_chan_comb == 5 ||
1723 ts->trx->ts[0].nm_chan_comb == 8))
1724 return -EINVAL;
1725 break;
1726 case NM_CHANC_mainBCCH:
1727 case NM_CHANC_BCCHComb:
1728 /* allowed only for TS0 of C0 */
1729 if (ts->trx != ts->trx->bts->c0 ||
1730 ts->nr != 0)
1731 return -EINVAL;
1732 break;
1733 case NM_CHANC_BCCH:
1734 /* allowed only for TS 2/4/6 of C0 */
1735 if (ts->trx != ts->trx->bts->c0)
1736 return -EINVAL;
1737 if (ts->nr != 2 && ts->nr != 4 &&
1738 ts->nr != 6)
1739 return -EINVAL;
1740 break;
1741 case 8: /* this is not like 08.58, but in fact
1742 * FCCH+SCH+BCCH+CCCH+SDCCH/4+SACCH/C4+CBCH */
1743 /* FIXME: only one CBCH allowed per cell */
1744 break;
1745 }
1746 }
1747 return 0;
1748}
1749
Harald Welte22af0db2009-02-14 15:41:08 +00001750/* Chapter 8.6.3 */
Harald Welte52b1f982008-12-23 20:25:15 +00001751int abis_nm_set_channel_attr(struct gsm_bts_trx_ts *ts, u_int8_t chan_comb)
1752{
1753 struct gsm_bts *bts = ts->trx->bts;
1754 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001755 u_int16_t arfcn = htons(ts->trx->arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001756 u_int8_t zero = 0x00;
Harald Welte8470bf22008-12-25 23:28:35 +00001757 struct msgb *msg = nm_msgb_alloc();
Harald Weltee0590df2009-02-15 03:34:15 +00001758 u_int8_t len = 2 + 2;
1759
1760 if (bts->type == GSM_BTS_TYPE_BS11)
1761 len += 4 + 2 + 2 + 3;
Harald Welte52b1f982008-12-23 20:25:15 +00001762
Harald Weltef325eb42009-02-19 17:07:39 +00001763 DEBUGP(DNM, "Set Chan Attr %s\n", gsm_ts_name(ts));
Harald Welte39c7deb2009-08-09 21:49:48 +02001764 if (verify_chan_comb(ts, chan_comb) < 0) {
1765 msgb_free(msg);
1766 DEBUGP(DNM, "Invalid Channel Combination!!!\n");
1767 return -EINVAL;
1768 }
1769 ts->nm_chan_comb = chan_comb;
Harald Welte22af0db2009-02-14 15:41:08 +00001770
Harald Welte52b1f982008-12-23 20:25:15 +00001771 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001772 fill_om_fom_hdr(oh, len, NM_MT_SET_CHAN_ATTR,
Holger Freyther6b2d2622009-02-14 23:16:59 +00001773 NM_OC_CHANNEL, bts->bts_nr,
Harald Welte52b1f982008-12-23 20:25:15 +00001774 ts->trx->nr, ts->nr);
1775 /* FIXME: don't send ARFCN list, hopping sequence, mAIO, ...*/
Harald Weltee0590df2009-02-15 03:34:15 +00001776 if (bts->type == GSM_BTS_TYPE_BS11)
1777 msgb_tlv16_put(msg, NM_ATT_ARFCN_LIST, 1, &arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001778 msgb_tv_put(msg, NM_ATT_CHAN_COMB, chan_comb);
Harald Weltee0590df2009-02-15 03:34:15 +00001779 if (bts->type == GSM_BTS_TYPE_BS11) {
1780 msgb_tv_put(msg, NM_ATT_HSN, 0x00);
1781 msgb_tv_put(msg, NM_ATT_MAIO, 0x00);
1782 }
Harald Weltee6c22d92009-07-21 20:40:05 +02001783 msgb_tv_put(msg, NM_ATT_TSC, bts->tsc); /* training sequence */
Harald Weltee0590df2009-02-15 03:34:15 +00001784 if (bts->type == GSM_BTS_TYPE_BS11)
1785 msgb_tlv_put(msg, 0x59, 1, &zero);
Harald Welte52b1f982008-12-23 20:25:15 +00001786
1787 return abis_nm_sendmsg(bts, msg);
1788}
1789
Harald Welte34a99682009-02-13 02:41:40 +00001790int 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 +00001791 u_int8_t i2, u_int8_t i3, int nack, u_int8_t *attr, int att_len)
Harald Welte34a99682009-02-13 02:41:40 +00001792{
1793 struct abis_om_hdr *oh;
1794 struct msgb *msg = nm_msgb_alloc();
Harald Welte5c1e4582009-02-15 11:57:29 +00001795 u_int8_t msgtype = NM_MT_SW_ACT_REQ_ACK;
1796 u_int8_t len = att_len;
1797
1798 if (nack) {
1799 len += 2;
1800 msgtype = NM_MT_SW_ACT_REQ_NACK;
1801 }
Harald Welte34a99682009-02-13 02:41:40 +00001802
1803 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte5c1e4582009-02-15 11:57:29 +00001804 fill_om_fom_hdr(oh, att_len, msgtype, obj_class, i1, i2, i3);
1805
Harald Welte34a99682009-02-13 02:41:40 +00001806 if (attr) {
1807 u_int8_t *ptr = msgb_put(msg, att_len);
1808 memcpy(ptr, attr, att_len);
1809 }
Harald Welte5c1e4582009-02-15 11:57:29 +00001810 if (nack)
1811 msgb_tv_put(msg, NM_ATT_NACK_CAUSES, NM_NACK_OBJCLASS_NOTSUPP);
Harald Welte34a99682009-02-13 02:41:40 +00001812
1813 return abis_nm_sendmsg(bts, msg);
1814}
1815
Harald Welte8470bf22008-12-25 23:28:35 +00001816int abis_nm_raw_msg(struct gsm_bts *bts, int len, u_int8_t *rawmsg)
Harald Welte52b1f982008-12-23 20:25:15 +00001817{
Harald Welte8470bf22008-12-25 23:28:35 +00001818 struct msgb *msg = nm_msgb_alloc();
1819 struct abis_om_hdr *oh;
Harald Welte52b1f982008-12-23 20:25:15 +00001820 u_int8_t *data;
1821
1822 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
1823 fill_om_hdr(oh, len);
1824 data = msgb_put(msg, len);
Harald Weltead384642008-12-26 10:20:07 +00001825 memcpy(data, rawmsg, len);
Harald Welte52b1f982008-12-23 20:25:15 +00001826
1827 return abis_nm_sendmsg(bts, msg);
1828}
1829
1830/* Siemens specific commands */
1831static int __simple_cmd(struct gsm_bts *bts, u_int8_t msg_type)
1832{
1833 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001834 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001835
1836 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001837 fill_om_fom_hdr(oh, 0, msg_type, NM_OC_SITE_MANAGER,
Harald Welte52b1f982008-12-23 20:25:15 +00001838 0xff, 0xff, 0xff);
1839
1840 return abis_nm_sendmsg(bts, msg);
1841}
1842
Harald Welte34a99682009-02-13 02:41:40 +00001843/* Chapter 8.9.2 */
1844int abis_nm_opstart(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1, u_int8_t i2)
1845{
1846 struct abis_om_hdr *oh;
1847 struct msgb *msg = nm_msgb_alloc();
1848
Harald Welte22af0db2009-02-14 15:41:08 +00001849 DEBUGP(DNM, "Sending OPSTART obj_class=0x%02x obj_inst=(0x%02x, 0x%02x, 0x%02x)\n",
1850 obj_class, i0, i1, i2);
Harald Welte34a99682009-02-13 02:41:40 +00001851 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1852 fill_om_fom_hdr(oh, 0, NM_MT_OPSTART, obj_class, i0, i1, i2);
1853
1854 return abis_nm_sendmsg(bts, msg);
1855}
1856
1857/* Chapter 8.8.5 */
1858int abis_nm_chg_adm_state(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0,
Daniel Willmann65f68fa2009-08-10 11:49:36 +02001859 u_int8_t i1, u_int8_t i2, enum abis_nm_adm_state adm_state)
Harald Welte34a99682009-02-13 02:41:40 +00001860{
1861 struct abis_om_hdr *oh;
1862 struct msgb *msg = nm_msgb_alloc();
1863
1864 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1865 fill_om_fom_hdr(oh, 2, NM_MT_CHG_ADM_STATE, obj_class, i0, i1, i2);
1866 msgb_tv_put(msg, NM_ATT_ADM_STATE, adm_state);
1867
1868 return abis_nm_sendmsg(bts, msg);
1869}
1870
Harald Welte1989c082009-08-06 17:58:31 +02001871int abis_nm_conn_mdrop_link(struct gsm_bts *bts, u_int8_t e1_port0, u_int8_t ts0,
1872 u_int8_t e1_port1, u_int8_t ts1)
1873{
1874 struct abis_om_hdr *oh;
1875 struct msgb *msg = nm_msgb_alloc();
1876 u_int8_t *attr;
1877
1878 DEBUGP(DNM, "CONNECT MDROP LINK E1=(%u,%u) -> E1=(%u, %u)\n",
1879 e1_port0, ts0, e1_port1, ts1);
1880
1881 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1882 fill_om_fom_hdr(oh, 6, NM_MT_CONN_MDROP_LINK,
1883 NM_OC_SITE_MANAGER, 0x00, 0x00, 0x00);
1884
1885 attr = msgb_put(msg, 3);
1886 attr[0] = NM_ATT_MDROP_LINK;
1887 attr[1] = e1_port0;
1888 attr[2] = ts0;
1889
1890 attr = msgb_put(msg, 3);
1891 attr[0] = NM_ATT_MDROP_NEXT;
1892 attr[1] = e1_port1;
1893 attr[2] = ts1;
1894
1895 return abis_nm_sendmsg(bts, msg);
1896}
Harald Welte34a99682009-02-13 02:41:40 +00001897
Harald Weltec7310382009-08-08 00:02:36 +02001898/* Chapter 8.7.1 */
1899int abis_nm_perform_test(struct gsm_bts *bts, u_int8_t obj_class,
1900 u_int8_t bts_nr, u_int8_t trx_nr, u_int8_t ts_nr,
1901 u_int8_t test_nr, u_int8_t auton_report,
1902 u_int8_t *phys_config, u_int16_t phys_config_len)
1903{
1904 struct abis_om_hdr *oh;
1905 struct msgb *msg = nm_msgb_alloc();
1906 int len = 4; /* 2 TV attributes */
1907
1908 DEBUGP(DNM, "PEFORM TEST\n");
1909
1910 if (phys_config_len)
1911 len += 3 + phys_config_len;
1912
1913 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1914 fill_om_fom_hdr(oh, len, NM_MT_PERF_TEST,
1915 obj_class, bts_nr, trx_nr, ts_nr);
1916 msgb_tv_put(msg, NM_ATT_TEST_NO, test_nr);
1917 msgb_tv_put(msg, NM_ATT_AUTON_REPORT, auton_report);
1918 if (phys_config_len)
1919 msgb_tl16v_put(msg, NM_ATT_PHYS_CONF, phys_config_len,
1920 phys_config);
1921
1922 return abis_nm_sendmsg(bts, msg);
1923}
1924
Harald Welte52b1f982008-12-23 20:25:15 +00001925int abis_nm_event_reports(struct gsm_bts *bts, int on)
1926{
1927 if (on == 0)
Harald Welte227d4072009-01-03 08:16:25 +00001928 return __simple_cmd(bts, NM_MT_STOP_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001929 else
Harald Welte227d4072009-01-03 08:16:25 +00001930 return __simple_cmd(bts, NM_MT_REST_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001931}
1932
Harald Welte47d88ae2009-01-04 12:02:08 +00001933/* Siemens (or BS-11) specific commands */
1934
Harald Welte3ffd1372009-02-01 22:15:49 +00001935int abis_nm_bs11_bsc_disconnect(struct gsm_bts *bts, int reconnect)
1936{
1937 if (reconnect == 0)
1938 return __simple_cmd(bts, NM_MT_BS11_DISCONNECT);
1939 else
1940 return __simple_cmd(bts, NM_MT_BS11_RECONNECT);
1941}
1942
Harald Welteb8427972009-02-05 19:27:17 +00001943int abis_nm_bs11_restart(struct gsm_bts *bts)
1944{
1945 return __simple_cmd(bts, NM_MT_BS11_RESTART);
1946}
1947
1948
Harald Welte268bb402009-02-01 19:11:56 +00001949struct bs11_date_time {
1950 u_int16_t year;
1951 u_int8_t month;
1952 u_int8_t day;
1953 u_int8_t hour;
1954 u_int8_t min;
1955 u_int8_t sec;
1956} __attribute__((packed));
1957
1958
1959void get_bs11_date_time(struct bs11_date_time *aet)
1960{
1961 time_t t;
1962 struct tm *tm;
1963
1964 t = time(NULL);
1965 tm = localtime(&t);
1966 aet->sec = tm->tm_sec;
1967 aet->min = tm->tm_min;
1968 aet->hour = tm->tm_hour;
1969 aet->day = tm->tm_mday;
1970 aet->month = tm->tm_mon;
1971 aet->year = htons(1900 + tm->tm_year);
1972}
1973
Harald Welte05188ee2009-01-18 11:39:08 +00001974int abis_nm_bs11_reset_resource(struct gsm_bts *bts)
Harald Welte52b1f982008-12-23 20:25:15 +00001975{
Harald Welte4668fda2009-01-03 08:19:29 +00001976 return __simple_cmd(bts, NM_MT_BS11_RESET_RESOURCE);
Harald Welte52b1f982008-12-23 20:25:15 +00001977}
1978
Harald Welte05188ee2009-01-18 11:39:08 +00001979int abis_nm_bs11_db_transmission(struct gsm_bts *bts, int begin)
Harald Welte52b1f982008-12-23 20:25:15 +00001980{
1981 if (begin)
Harald Welte4668fda2009-01-03 08:19:29 +00001982 return __simple_cmd(bts, NM_MT_BS11_BEGIN_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00001983 else
Harald Welte4668fda2009-01-03 08:19:29 +00001984 return __simple_cmd(bts, NM_MT_BS11_END_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00001985}
Harald Welte47d88ae2009-01-04 12:02:08 +00001986
Harald Welte05188ee2009-01-18 11:39:08 +00001987int abis_nm_bs11_create_object(struct gsm_bts *bts,
Harald Welte1bc09062009-01-18 14:17:52 +00001988 enum abis_bs11_objtype type, u_int8_t idx,
1989 u_int8_t attr_len, const u_int8_t *attr)
Harald Welte47d88ae2009-01-04 12:02:08 +00001990{
1991 struct abis_om_hdr *oh;
1992 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00001993 u_int8_t *cur;
Harald Welte47d88ae2009-01-04 12:02:08 +00001994
1995 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001996 fill_om_fom_hdr(oh, attr_len, NM_MT_BS11_CREATE_OBJ,
Harald Welte268bb402009-02-01 19:11:56 +00001997 NM_OC_BS11, type, 0, idx);
Harald Welte1bc09062009-01-18 14:17:52 +00001998 cur = msgb_put(msg, attr_len);
1999 memcpy(cur, attr, attr_len);
Harald Welte47d88ae2009-01-04 12:02:08 +00002000
2001 return abis_nm_sendmsg(bts, msg);
2002}
2003
Harald Welte78fc0d42009-02-19 02:50:57 +00002004int abis_nm_bs11_delete_object(struct gsm_bts *bts,
2005 enum abis_bs11_objtype type, u_int8_t idx)
2006{
2007 struct abis_om_hdr *oh;
2008 struct msgb *msg = nm_msgb_alloc();
2009
2010 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2011 fill_om_fom_hdr(oh, 0, NM_MT_BS11_DELETE_OBJ,
2012 NM_OC_BS11, type, 0, idx);
2013
2014 return abis_nm_sendmsg(bts, msg);
2015}
2016
Harald Welte05188ee2009-01-18 11:39:08 +00002017int abis_nm_bs11_create_envaBTSE(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00002018{
2019 struct abis_om_hdr *oh;
2020 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00002021 u_int8_t zero = 0x00;
Harald Welte47d88ae2009-01-04 12:02:08 +00002022
2023 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00002024 fill_om_fom_hdr(oh, 3, NM_MT_BS11_CREATE_OBJ,
Harald Welte1bc09062009-01-18 14:17:52 +00002025 NM_OC_BS11_ENVABTSE, 0, idx, 0xff);
2026 msgb_tlv_put(msg, 0x99, 1, &zero);
Harald Welte47d88ae2009-01-04 12:02:08 +00002027
2028 return abis_nm_sendmsg(bts, msg);
2029}
2030
Harald Welte05188ee2009-01-18 11:39:08 +00002031int abis_nm_bs11_create_bport(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00002032{
2033 struct abis_om_hdr *oh;
2034 struct msgb *msg = nm_msgb_alloc();
2035
2036 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2037 fill_om_fom_hdr(oh, 0, NM_MT_BS11_CREATE_OBJ, NM_OC_BS11_BPORT,
Daniel Willmann65f68fa2009-08-10 11:49:36 +02002038 idx, 0xff, 0xff);
2039
2040 return abis_nm_sendmsg(bts, msg);
2041}
2042
2043int abis_nm_bs11_delete_bport(struct gsm_bts *bts, u_int8_t idx)
2044{
2045 struct abis_om_hdr *oh;
2046 struct msgb *msg = nm_msgb_alloc();
2047
2048 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2049 fill_om_fom_hdr(oh, 0, NM_MT_BS11_DELETE_OBJ, NM_OC_BS11_BPORT,
2050 idx, 0xff, 0xff);
Harald Welte47d88ae2009-01-04 12:02:08 +00002051
2052 return abis_nm_sendmsg(bts, msg);
2053}
Harald Welte05188ee2009-01-18 11:39:08 +00002054
Harald Welte78fc0d42009-02-19 02:50:57 +00002055static const u_int8_t sm_attr[] = { NM_ATT_TEI, NM_ATT_ABIS_CHANNEL };
2056int abis_nm_bs11_get_oml_tei_ts(struct gsm_bts *bts)
2057{
2058 struct abis_om_hdr *oh;
2059 struct msgb *msg = nm_msgb_alloc();
2060
2061 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2062 fill_om_fom_hdr(oh, 2+sizeof(sm_attr), NM_MT_GET_ATTR, NM_OC_SITE_MANAGER,
2063 0xff, 0xff, 0xff);
2064 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(sm_attr), sm_attr);
2065
2066 return abis_nm_sendmsg(bts, msg);
2067}
2068
Harald Welteb6c92ae2009-02-21 20:15:32 +00002069/* like abis_nm_conn_terr_traf + set_tei */
2070int abis_nm_bs11_conn_oml_tei(struct gsm_bts *bts, u_int8_t e1_port,
2071 u_int8_t e1_timeslot, u_int8_t e1_subslot,
2072 u_int8_t tei)
Harald Welte05188ee2009-01-18 11:39:08 +00002073{
2074 struct abis_om_hdr *oh;
2075 struct abis_nm_channel *ch;
2076 struct msgb *msg = nm_msgb_alloc();
2077
2078 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welteb6c92ae2009-02-21 20:15:32 +00002079 fill_om_fom_hdr(oh, sizeof(*ch)+2, NM_MT_BS11_SET_ATTR,
Harald Welte05188ee2009-01-18 11:39:08 +00002080 NM_OC_SITE_MANAGER, 0xff, 0xff, 0xff);
2081
2082 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
2083 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
Harald Welteb6c92ae2009-02-21 20:15:32 +00002084 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte05188ee2009-01-18 11:39:08 +00002085
2086 return abis_nm_sendmsg(bts, msg);
2087}
2088
2089int abis_nm_bs11_set_trx_power(struct gsm_bts_trx *trx, u_int8_t level)
2090{
2091 struct abis_om_hdr *oh;
2092 struct msgb *msg = nm_msgb_alloc();
Harald Welte05188ee2009-01-18 11:39:08 +00002093
2094 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00002095 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR,
Harald Welte05188ee2009-01-18 11:39:08 +00002096 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
2097 msgb_tlv_put(msg, NM_ATT_BS11_TXPWR, 1, &level);
2098
2099 return abis_nm_sendmsg(trx->bts, msg);
2100}
2101
Harald Welte78fc0d42009-02-19 02:50:57 +00002102int abis_nm_bs11_get_trx_power(struct gsm_bts_trx *trx)
2103{
2104 struct abis_om_hdr *oh;
2105 struct msgb *msg = nm_msgb_alloc();
2106 u_int8_t attr = NM_ATT_BS11_TXPWR;
2107
2108 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2109 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
2110 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
2111 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), &attr);
2112
2113 return abis_nm_sendmsg(trx->bts, msg);
2114}
2115
Harald Welteaaf02d92009-04-29 13:25:57 +00002116int abis_nm_bs11_get_pll_mode(struct gsm_bts *bts)
2117{
2118 struct abis_om_hdr *oh;
2119 struct msgb *msg = nm_msgb_alloc();
Harald Weltea7cfa032009-04-29 22:33:02 +00002120 u_int8_t attr[] = { NM_ATT_BS11_PLL_MODE };
Harald Welteaaf02d92009-04-29 13:25:57 +00002121
2122 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2123 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
2124 NM_OC_BS11, BS11_OBJ_LI, 0x00, 0x00);
Harald Welteaeedeb42009-05-01 13:08:14 +00002125 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), attr);
Harald Welteaaf02d92009-04-29 13:25:57 +00002126
2127 return abis_nm_sendmsg(bts, msg);
2128}
2129
Harald Welteef061952009-05-17 12:43:42 +00002130int abis_nm_bs11_get_cclk(struct gsm_bts *bts)
2131{
2132 struct abis_om_hdr *oh;
2133 struct msgb *msg = nm_msgb_alloc();
2134 u_int8_t attr[] = { NM_ATT_BS11_CCLK_ACCURACY,
2135 NM_ATT_BS11_CCLK_TYPE };
2136
2137 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2138 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
2139 NM_OC_BS11, BS11_OBJ_CCLK, 0x00, 0x00);
2140 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), attr);
2141
2142 return abis_nm_sendmsg(bts, msg);
2143
2144}
Harald Welteaaf02d92009-04-29 13:25:57 +00002145
Harald Welte268bb402009-02-01 19:11:56 +00002146//static const u_int8_t bs11_logon_c7[] = { 0x07, 0xd9, 0x01, 0x11, 0x0d, 0x10, 0x20 };
Harald Weltebb151312009-01-28 20:42:07 +00002147static const u_int8_t bs11_logon_c8[] = { 0x02 };
Harald Welte05188ee2009-01-18 11:39:08 +00002148static const u_int8_t bs11_logon_c9[] = "FACTORY";
2149
Harald Welte1bc09062009-01-18 14:17:52 +00002150int abis_nm_bs11_factory_logon(struct gsm_bts *bts, int on)
Harald Welte05188ee2009-01-18 11:39:08 +00002151{
2152 struct abis_om_hdr *oh;
2153 struct msgb *msg = nm_msgb_alloc();
Harald Welte268bb402009-02-01 19:11:56 +00002154 struct bs11_date_time bdt;
2155
2156 get_bs11_date_time(&bdt);
Harald Welte05188ee2009-01-18 11:39:08 +00002157
2158 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte1bc09062009-01-18 14:17:52 +00002159 if (on) {
Harald Welte268bb402009-02-01 19:11:56 +00002160 u_int8_t len = 3*2 + sizeof(bdt)
Harald Welte6f676a32009-01-18 14:27:48 +00002161 + sizeof(bs11_logon_c8) + sizeof(bs11_logon_c9);
Harald Welte043d04a2009-01-29 23:15:30 +00002162 fill_om_fom_hdr(oh, len, NM_MT_BS11_LMT_LOGON,
Harald Welte7b26bcb2009-05-28 11:39:21 +00002163 NM_OC_BS11_BTSE, 0xff, 0xff, 0xff);
Harald Welte043d04a2009-01-29 23:15:30 +00002164 msgb_tlv_put(msg, NM_ATT_BS11_LMT_LOGIN_TIME,
Harald Welte5083b0b2009-02-02 19:20:52 +00002165 sizeof(bdt), (u_int8_t *) &bdt);
Harald Welte043d04a2009-01-29 23:15:30 +00002166 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_ACC_LEV,
2167 sizeof(bs11_logon_c8), bs11_logon_c8);
2168 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_NAME,
2169 sizeof(bs11_logon_c9), bs11_logon_c9);
Harald Welte1bc09062009-01-18 14:17:52 +00002170 } else {
Harald Welte5e4d1b32009-02-01 13:36:56 +00002171 fill_om_fom_hdr(oh, 0, NM_MT_BS11_LMT_LOGOFF,
Harald Welte7b26bcb2009-05-28 11:39:21 +00002172 NM_OC_BS11_BTSE, 0xff, 0xff, 0xff);
Harald Welte1bc09062009-01-18 14:17:52 +00002173 }
Harald Welte05188ee2009-01-18 11:39:08 +00002174
2175 return abis_nm_sendmsg(bts, msg);
2176}
Harald Welte1bc09062009-01-18 14:17:52 +00002177
2178int abis_nm_bs11_set_trx1_pw(struct gsm_bts *bts, const char *password)
2179{
2180 struct abis_om_hdr *oh;
2181 struct msgb *msg;
2182
2183 if (strlen(password) != 10)
2184 return -EINVAL;
2185
2186 msg = nm_msgb_alloc();
2187 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00002188 fill_om_fom_hdr(oh, 2+strlen(password), NM_MT_BS11_SET_ATTR,
Harald Welte1bc09062009-01-18 14:17:52 +00002189 NM_OC_BS11, BS11_OBJ_TRX1, 0x00, 0x00);
2190 msgb_tlv_put(msg, NM_ATT_BS11_PASSWORD, 10, (const u_int8_t *)password);
2191
2192 return abis_nm_sendmsg(bts, msg);
2193}
2194
Harald Weltee69f5fb2009-04-28 16:31:38 +00002195/* change the BS-11 PLL Mode to either locked (E1 derived) or standalone */
2196int abis_nm_bs11_set_pll_locked(struct gsm_bts *bts, int locked)
2197{
2198 struct abis_om_hdr *oh;
2199 struct msgb *msg;
Harald Weltea432cd32009-04-29 13:01:50 +00002200 u_int8_t tlv_value;
Harald Weltee69f5fb2009-04-28 16:31:38 +00002201
2202 msg = nm_msgb_alloc();
2203 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2204 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR, NM_OC_BS11,
2205 BS11_OBJ_LI, 0x00, 0x00);
Harald Weltea432cd32009-04-29 13:01:50 +00002206
2207 if (locked)
2208 tlv_value = BS11_LI_PLL_LOCKED;
2209 else
2210 tlv_value = BS11_LI_PLL_STANDALONE;
2211
2212 msgb_tlv_put(msg, NM_ATT_BS11_PLL_MODE, 1, &tlv_value);
Harald Weltee69f5fb2009-04-28 16:31:38 +00002213
2214 return abis_nm_sendmsg(bts, msg);
2215}
2216
Harald Welte1bc09062009-01-18 14:17:52 +00002217int abis_nm_bs11_get_state(struct gsm_bts *bts)
2218{
2219 return __simple_cmd(bts, NM_MT_BS11_GET_STATE);
2220}
Harald Welte5e4d1b32009-02-01 13:36:56 +00002221
2222/* BS11 SWL */
2223
Harald Welte (local)d19e58b2009-08-15 02:30:58 +02002224void *tall_fle_ctx;
Harald Welte2cf161b2009-06-20 22:36:41 +02002225
Harald Welte5e4d1b32009-02-01 13:36:56 +00002226struct abis_nm_bs11_sw {
2227 struct gsm_bts *bts;
2228 char swl_fname[PATH_MAX];
2229 u_int8_t win_size;
Harald Welte3ffd1372009-02-01 22:15:49 +00002230 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00002231 struct llist_head file_list;
2232 gsm_cbfn *user_cb; /* specified by the user */
2233};
2234static struct abis_nm_bs11_sw _g_bs11_sw, *g_bs11_sw = &_g_bs11_sw;
2235
2236struct file_list_entry {
2237 struct llist_head list;
2238 char fname[PATH_MAX];
2239};
2240
2241struct file_list_entry *fl_dequeue(struct llist_head *queue)
2242{
2243 struct llist_head *lh;
2244
2245 if (llist_empty(queue))
2246 return NULL;
2247
2248 lh = queue->next;
2249 llist_del(lh);
2250
2251 return llist_entry(lh, struct file_list_entry, list);
2252}
2253
2254static int bs11_read_swl_file(struct abis_nm_bs11_sw *bs11_sw)
2255{
2256 char linebuf[255];
2257 struct llist_head *lh, *lh2;
2258 FILE *swl;
2259 int rc = 0;
2260
2261 swl = fopen(bs11_sw->swl_fname, "r");
2262 if (!swl)
2263 return -ENODEV;
2264
2265 /* zero the stale file list, if any */
2266 llist_for_each_safe(lh, lh2, &bs11_sw->file_list) {
2267 llist_del(lh);
Harald Welte2cf161b2009-06-20 22:36:41 +02002268 talloc_free(lh);
Harald Welte5e4d1b32009-02-01 13:36:56 +00002269 }
2270
2271 while (fgets(linebuf, sizeof(linebuf), swl)) {
2272 char file_id[12+1];
2273 char file_version[80+1];
2274 struct file_list_entry *fle;
2275 static char dir[PATH_MAX];
2276
2277 if (strlen(linebuf) < 4)
2278 continue;
Harald Welte3ffd1372009-02-01 22:15:49 +00002279
Harald Welte5e4d1b32009-02-01 13:36:56 +00002280 rc = sscanf(linebuf+4, "%12s:%80s\r\n", file_id, file_version);
2281 if (rc < 0) {
2282 perror("ERR parsing SWL file");
2283 rc = -EINVAL;
2284 goto out;
2285 }
2286 if (rc < 2)
2287 continue;
2288
Harald Welte470ec292009-06-26 20:25:23 +02002289 fle = talloc_zero(tall_fle_ctx, struct file_list_entry);
Harald Welte5e4d1b32009-02-01 13:36:56 +00002290 if (!fle) {
2291 rc = -ENOMEM;
2292 goto out;
2293 }
Harald Welte5e4d1b32009-02-01 13:36:56 +00002294
2295 /* construct new filename */
2296 strncpy(dir, bs11_sw->swl_fname, sizeof(dir));
2297 strncat(fle->fname, dirname(dir), sizeof(fle->fname) - 1);
2298 strcat(fle->fname, "/");
2299 strncat(fle->fname, file_id, sizeof(fle->fname) - 1 -strlen(fle->fname));
Harald Welte5e4d1b32009-02-01 13:36:56 +00002300
2301 llist_add_tail(&fle->list, &bs11_sw->file_list);
2302 }
2303
2304out:
2305 fclose(swl);
2306 return rc;
2307}
2308
2309/* bs11 swload specific callback, passed to abis_nm core swload */
2310static int bs11_swload_cbfn(unsigned int hook, unsigned int event,
2311 struct msgb *msg, void *data, void *param)
2312{
2313 struct abis_nm_bs11_sw *bs11_sw = data;
2314 struct file_list_entry *fle;
2315 int rc = 0;
2316
Harald Welte5e4d1b32009-02-01 13:36:56 +00002317 switch (event) {
2318 case NM_MT_LOAD_END_ACK:
2319 fle = fl_dequeue(&bs11_sw->file_list);
2320 if (fle) {
2321 /* start download the next file of our file list */
2322 rc = abis_nm_software_load(bs11_sw->bts, fle->fname,
2323 bs11_sw->win_size,
Harald Welte3ffd1372009-02-01 22:15:49 +00002324 bs11_sw->forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00002325 &bs11_swload_cbfn, bs11_sw);
Harald Welteac606dc2009-08-06 15:44:18 +02002326 talloc_free(fle);
Harald Welte5e4d1b32009-02-01 13:36:56 +00002327 } else {
2328 /* activate the SWL */
2329 rc = abis_nm_software_activate(bs11_sw->bts,
2330 bs11_sw->swl_fname,
2331 bs11_swload_cbfn,
2332 bs11_sw);
2333 }
2334 break;
Harald Welte3ffd1372009-02-01 22:15:49 +00002335 case NM_MT_LOAD_SEG_ACK:
Harald Welte5e4d1b32009-02-01 13:36:56 +00002336 case NM_MT_LOAD_END_NACK:
2337 case NM_MT_LOAD_INIT_ACK:
2338 case NM_MT_LOAD_INIT_NACK:
2339 case NM_MT_ACTIVATE_SW_NACK:
2340 case NM_MT_ACTIVATE_SW_ACK:
2341 default:
2342 /* fallthrough to the user callback */
Harald Welte97ed1e72009-02-06 13:38:02 +00002343 if (bs11_sw->user_cb)
2344 rc = bs11_sw->user_cb(hook, event, msg, NULL, NULL);
Harald Welte5e4d1b32009-02-01 13:36:56 +00002345 break;
2346 }
2347
2348 return rc;
2349}
2350
2351/* Siemens provides a SWL file that is a mere listing of all the other
2352 * files that are part of a software release. We need to upload first
2353 * the list file, and then each file that is listed in the list file */
2354int abis_nm_bs11_load_swl(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00002355 u_int8_t win_size, int forced, gsm_cbfn *cbfn)
Harald Welte5e4d1b32009-02-01 13:36:56 +00002356{
2357 struct abis_nm_bs11_sw *bs11_sw = g_bs11_sw;
2358 struct file_list_entry *fle;
2359 int rc = 0;
2360
2361 INIT_LLIST_HEAD(&bs11_sw->file_list);
2362 bs11_sw->bts = bts;
2363 bs11_sw->win_size = win_size;
2364 bs11_sw->user_cb = cbfn;
Harald Welte3ffd1372009-02-01 22:15:49 +00002365 bs11_sw->forced = forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00002366
2367 strncpy(bs11_sw->swl_fname, fname, sizeof(bs11_sw->swl_fname));
2368 rc = bs11_read_swl_file(bs11_sw);
2369 if (rc < 0)
2370 return rc;
2371
2372 /* dequeue next item in file list */
2373 fle = fl_dequeue(&bs11_sw->file_list);
2374 if (!fle)
2375 return -EINVAL;
2376
2377 /* start download the next file of our file list */
Harald Welte3ffd1372009-02-01 22:15:49 +00002378 rc = abis_nm_software_load(bts, fle->fname, win_size, forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00002379 bs11_swload_cbfn, bs11_sw);
Harald Welteac606dc2009-08-06 15:44:18 +02002380 talloc_free(fle);
Harald Welte5e4d1b32009-02-01 13:36:56 +00002381 return rc;
2382}
2383
Harald Welte5083b0b2009-02-02 19:20:52 +00002384#if 0
Harald Welte5e4d1b32009-02-01 13:36:56 +00002385static u_int8_t req_attr_btse[] = {
2386 NM_ATT_ADM_STATE, NM_ATT_BS11_LMT_LOGON_SESSION,
2387 NM_ATT_BS11_LMT_LOGIN_TIME, NM_ATT_BS11_LMT_USER_ACC_LEV,
2388 NM_ATT_BS11_LMT_USER_NAME,
2389
2390 0xaf, NM_ATT_BS11_RX_OFFSET, NM_ATT_BS11_VENDOR_NAME,
2391
2392 NM_ATT_BS11_SW_LOAD_INTENDED, NM_ATT_BS11_SW_LOAD_SAFETY,
2393
2394 NM_ATT_BS11_SW_LOAD_STORED };
2395
2396static u_int8_t req_attr_btsm[] = {
2397 NM_ATT_ABIS_CHANNEL, NM_ATT_TEI, NM_ATT_BS11_ABIS_EXT_TIME,
2398 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xce, NM_ATT_FILE_ID,
2399 NM_ATT_FILE_VERSION, NM_ATT_OPER_STATE, 0xe8, NM_ATT_BS11_ALL_TEST_CATG,
2400 NM_ATT_SW_DESCR, NM_ATT_GET_ARI };
Harald Welte5083b0b2009-02-02 19:20:52 +00002401#endif
Harald Welte5e4d1b32009-02-01 13:36:56 +00002402
2403static u_int8_t req_attr[] = {
2404 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xa8, NM_ATT_OPER_STATE,
2405 0xd5, 0xa1, NM_ATT_BS11_ESN_FW_CODE_NO, NM_ATT_BS11_ESN_HW_CODE_NO,
Harald Weltea7cfa032009-04-29 22:33:02 +00002406 0x42, NM_ATT_BS11_ESN_PCB_SERIAL, NM_ATT_BS11_PLL };
Harald Welte5e4d1b32009-02-01 13:36:56 +00002407
2408int abis_nm_bs11_get_serno(struct gsm_bts *bts)
2409{
2410 struct abis_om_hdr *oh;
2411 struct msgb *msg = nm_msgb_alloc();
2412
2413 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2414 /* SiemensHW CCTRL object */
2415 fill_om_fom_hdr(oh, 2+sizeof(req_attr), NM_MT_GET_ATTR, NM_OC_BS11,
2416 0x03, 0x00, 0x00);
2417 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(req_attr), req_attr);
2418
2419 return abis_nm_sendmsg(bts, msg);
2420}
Harald Welte268bb402009-02-01 19:11:56 +00002421
2422int abis_nm_bs11_set_ext_time(struct gsm_bts *bts)
2423{
2424 struct abis_om_hdr *oh;
2425 struct msgb *msg = nm_msgb_alloc();
2426 struct bs11_date_time aet;
2427
2428 get_bs11_date_time(&aet);
2429 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2430 /* SiemensHW CCTRL object */
2431 fill_om_fom_hdr(oh, 2+sizeof(aet), NM_MT_BS11_SET_ATTR, NM_OC_SITE_MANAGER,
2432 0xff, 0xff, 0xff);
Harald Welte5083b0b2009-02-02 19:20:52 +00002433 msgb_tlv_put(msg, NM_ATT_BS11_ABIS_EXT_TIME, sizeof(aet), (u_int8_t *) &aet);
Harald Welte268bb402009-02-01 19:11:56 +00002434
2435 return abis_nm_sendmsg(bts, msg);
2436}
Harald Welte5c1e4582009-02-15 11:57:29 +00002437
Daniel Willmann65f68fa2009-08-10 11:49:36 +02002438int abis_nm_bs11_set_bport_line_cfg(struct gsm_bts *bts, u_int8_t bport, enum abis_bs11_line_cfg line_cfg)
2439{
2440 struct abis_om_hdr *oh;
2441 struct msgb *msg = nm_msgb_alloc();
2442 struct bs11_date_time aet;
2443
2444 get_bs11_date_time(&aet);
2445 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2446 fill_om_fom_hdr(oh, 2, NM_MT_BS11_SET_ATTR, NM_OC_BS11_BPORT,
2447 bport, 0xff, 0x02);
2448 msgb_tv_put(msg, NM_ATT_BS11_LINE_CFG, line_cfg);
2449
2450 return abis_nm_sendmsg(bts, msg);
2451}
2452
Harald Welte5c1e4582009-02-15 11:57:29 +00002453/* ip.access nanoBTS specific commands */
Harald Welte5c1e4582009-02-15 11:57:29 +00002454static const char ipaccess_magic[] = "com.ipaccess";
2455
Harald Welte677c21f2009-02-17 13:22:23 +00002456
2457static int abis_nm_rx_ipacc(struct msgb *msg)
2458{
2459 struct abis_om_hdr *oh = msgb_l2(msg);
2460 struct abis_om_fom_hdr *foh;
2461 u_int8_t idstrlen = oh->data[0];
2462 struct tlv_parsed tp;
2463
2464 if (strncmp((char *)&oh->data[1], ipaccess_magic, idstrlen)) {
2465 DEBUGP(DNM, "id string is not com.ipaccess !?!\n");
2466 return -EINVAL;
2467 }
2468
Harald Welte193fefc2009-04-30 15:16:27 +00002469 foh = (struct abis_om_fom_hdr *) (oh->data + 1 + idstrlen);
Harald Welte03133942009-02-18 19:51:53 +00002470 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Welte677c21f2009-02-17 13:22:23 +00002471
Harald Welte193fefc2009-04-30 15:16:27 +00002472 DEBUGP(DNM, "IPACCESS(0x%02x): ", foh->msg_type);
2473
Harald Welte677c21f2009-02-17 13:22:23 +00002474 switch (foh->msg_type) {
2475 case NM_MT_IPACC_RSL_CONNECT_ACK:
Harald Welte193fefc2009-04-30 15:16:27 +00002476 DEBUGPC(DNM, "RSL CONNECT ACK ");
Harald Welte0efe9b72009-07-12 09:33:54 +02002477 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_DST_IP))
Harald Welte9de2bf82009-04-30 15:59:55 +00002478 DEBUGPC(DNM, "IP=%s ",
Harald Welte677c21f2009-02-17 13:22:23 +00002479 inet_ntoa(*((struct in_addr *)
Harald Welte0efe9b72009-07-12 09:33:54 +02002480 TLVP_VAL(&tp, NM_ATT_IPACC_DST_IP))));
2481 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_DST_IP_PORT))
Harald Welte9de2bf82009-04-30 15:59:55 +00002482 DEBUGPC(DNM, "PORT=%u ",
Harald Welte677c21f2009-02-17 13:22:23 +00002483 ntohs(*((u_int16_t *)
Harald Welte0efe9b72009-07-12 09:33:54 +02002484 TLVP_VAL(&tp, NM_ATT_IPACC_DST_IP_PORT))));
Harald Welte9de2bf82009-04-30 15:59:55 +00002485 DEBUGPC(DNM, "\n");
Harald Welte677c21f2009-02-17 13:22:23 +00002486 break;
2487 case NM_MT_IPACC_RSL_CONNECT_NACK:
Harald Welte193fefc2009-04-30 15:16:27 +00002488 DEBUGPC(DNM, "RSL CONNECT NACK ");
Harald Welte677c21f2009-02-17 13:22:23 +00002489 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
Harald Welte6c96ba52009-05-01 13:03:40 +00002490 DEBUGPC(DNM, " CAUSE=%s\n",
2491 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
Harald Welte677c21f2009-02-17 13:22:23 +00002492 else
2493 DEBUGPC(DNM, "\n");
2494 break;
Harald Welte193fefc2009-04-30 15:16:27 +00002495 case NM_MT_IPACC_SET_NVATTR_ACK:
2496 DEBUGPC(DNM, "SET NVATTR ACK\n");
2497 /* FIXME: decode and show the actual attributes */
2498 break;
2499 case NM_MT_IPACC_SET_NVATTR_NACK:
Harald Welte6c96ba52009-05-01 13:03:40 +00002500 DEBUGPC(DNM, "SET NVATTR NACK ");
2501 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
2502 DEBUGPC(DNM, " CAUSE=%s\n",
2503 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
2504 else
2505 DEBUGPC(DNM, "\n");
Harald Welte193fefc2009-04-30 15:16:27 +00002506 break;
Harald Welte684b1a82009-07-03 11:26:45 +02002507 case NM_MT_IPACC_GET_NVATTR_ACK:
2508 DEBUGPC(DNM, "GET NVATTR ACK\n");
2509 /* FIXME: decode and show the actual attributes */
2510 break;
2511 case NM_MT_IPACC_GET_NVATTR_NACK:
2512 DEBUGPC(DNM, "GET NVATTR NACK ");
2513 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
2514 DEBUGPC(DNM, " CAUSE=%s\n",
2515 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
2516 else
2517 DEBUGPC(DNM, "\n");
2518 break;
Harald Welte193fefc2009-04-30 15:16:27 +00002519 default:
2520 DEBUGPC(DNM, "unknown\n");
2521 break;
Harald Welte677c21f2009-02-17 13:22:23 +00002522 }
Holger Hans Peter Freythera7cd9fc2009-07-07 12:40:07 +02002523
2524 /* signal handling */
2525 switch (foh->msg_type) {
2526 case NM_MT_IPACC_RSL_CONNECT_NACK:
2527 case NM_MT_IPACC_SET_NVATTR_NACK:
2528 case NM_MT_IPACC_GET_NVATTR_NACK:
2529 dispatch_signal(SS_NM, S_NM_IPACC_NACK, (void*) ((long)foh->msg_type));
2530 break;
2531 default:
2532 break;
2533 }
2534
Harald Welte677c21f2009-02-17 13:22:23 +00002535 return 0;
2536}
2537
Harald Welte193fefc2009-04-30 15:16:27 +00002538/* send an ip-access manufacturer specific message */
Harald Welte5c1e4582009-02-15 11:57:29 +00002539int abis_nm_ipaccess_msg(struct gsm_bts *bts, u_int8_t msg_type,
2540 u_int8_t obj_class, u_int8_t bts_nr,
2541 u_int8_t trx_nr, u_int8_t ts_nr,
2542 u_int8_t *attr, int attr_len)
2543{
2544 struct msgb *msg = nm_msgb_alloc();
2545 struct abis_om_hdr *oh;
2546 struct abis_om_fom_hdr *foh;
2547 u_int8_t *data;
2548
2549 /* construct the 12.21 OM header, observe the erroneous length */
2550 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
2551 fill_om_hdr(oh, sizeof(*foh) + attr_len);
2552 oh->mdisc = ABIS_OM_MDISC_MANUF;
2553
2554 /* add the ip.access magic */
2555 data = msgb_put(msg, sizeof(ipaccess_magic)+1);
2556 *data++ = sizeof(ipaccess_magic);
2557 memcpy(data, ipaccess_magic, sizeof(ipaccess_magic));
2558
2559 /* fill the 12.21 FOM header */
2560 foh = (struct abis_om_fom_hdr *) msgb_put(msg, sizeof(*foh));
2561 foh->msg_type = msg_type;
2562 foh->obj_class = obj_class;
2563 foh->obj_inst.bts_nr = bts_nr;
2564 foh->obj_inst.trx_nr = trx_nr;
2565 foh->obj_inst.ts_nr = ts_nr;
2566
2567 if (attr && attr_len) {
2568 data = msgb_put(msg, attr_len);
2569 memcpy(data, attr, attr_len);
2570 }
2571
2572 return abis_nm_sendmsg(bts, msg);
2573}
Harald Welte677c21f2009-02-17 13:22:23 +00002574
Harald Welte193fefc2009-04-30 15:16:27 +00002575/* set some attributes in NVRAM */
2576int abis_nm_ipaccess_set_nvattr(struct gsm_bts *bts, u_int8_t *attr,
2577 int attr_len)
2578{
2579 return abis_nm_ipaccess_msg(bts, NM_MT_IPACC_SET_NVATTR,
2580 NM_OC_BASEB_TRANSC, 0, 0, 0xff, attr,
2581 attr_len);
2582}
2583
2584/* restart / reboot an ip.access nanoBTS */
2585int abis_nm_ipaccess_restart(struct gsm_bts *bts)
2586{
2587 return __simple_cmd(bts, NM_MT_IPACC_RESTART);
2588}