blob: 03d9deff0ee51eef34614f65597543d78098c908 [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,
Harald Weltea1499d02009-10-24 10:25:50 +0200413 [GSM_PCHAN_PDCH] = NM_CHANC_IPAC_PDCH,
414 [GSM_PCHAN_TCH_F_PDCH] = NM_CHANC_IPAC_TCHFull_PDCH,
Harald Welte21bd3a52009-08-10 12:21:22 +0200415 /* FIXME: bounds check */
416};
417
418int abis_nm_chcomb4pchan(enum gsm_phys_chan_config pchan)
419{
420 if (pchan < ARRAY_SIZE(chcomb4pchan))
421 return chcomb4pchan[pchan];
422
423 return -EINVAL;
424}
425
Harald Welte03133942009-02-18 19:51:53 +0000426int abis_nm_tlv_parse(struct tlv_parsed *tp, const u_int8_t *buf, int len)
427{
Harald Weltea4d49e92009-05-23 06:39:58 +0000428 return tlv_parse(tp, &nm_att_tlvdef, buf, len, 0, 0);
Harald Welte03133942009-02-18 19:51:53 +0000429}
Harald Weltee0590df2009-02-15 03:34:15 +0000430
Harald Welte52b1f982008-12-23 20:25:15 +0000431static int is_in_arr(enum abis_nm_msgtype mt, const enum abis_nm_msgtype *arr, int size)
432{
433 int i;
434
435 for (i = 0; i < size; i++) {
436 if (arr[i] == mt)
437 return 1;
438 }
439
440 return 0;
441}
442
Holger Freytherca362a62009-01-04 21:05:01 +0000443#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000444/* is this msgtype the usual ACK/NACK type ? */
445static int is_ack_nack(enum abis_nm_msgtype mt)
446{
447 return !is_in_arr(mt, no_ack_nack, ARRAY_SIZE(no_ack_nack));
448}
Holger Freytherca362a62009-01-04 21:05:01 +0000449#endif
Harald Welte52b1f982008-12-23 20:25:15 +0000450
451/* is this msgtype a report ? */
452static int is_report(enum abis_nm_msgtype mt)
453{
Harald Welte8470bf22008-12-25 23:28:35 +0000454 return is_in_arr(mt, reports, ARRAY_SIZE(reports));
Harald Welte52b1f982008-12-23 20:25:15 +0000455}
456
457#define MT_ACK(x) (x+1)
458#define MT_NACK(x) (x+2)
459
460static void fill_om_hdr(struct abis_om_hdr *oh, u_int8_t len)
461{
462 oh->mdisc = ABIS_OM_MDISC_FOM;
463 oh->placement = ABIS_OM_PLACEMENT_ONLY;
464 oh->sequence = 0;
465 oh->length = len;
466}
467
468static void fill_om_fom_hdr(struct abis_om_hdr *oh, u_int8_t len,
469 u_int8_t msg_type, u_int8_t obj_class,
470 u_int8_t bts_nr, u_int8_t trx_nr, u_int8_t ts_nr)
471{
472 struct abis_om_fom_hdr *foh =
473 (struct abis_om_fom_hdr *) oh->data;
474
Harald Welte702d8702008-12-26 20:25:35 +0000475 fill_om_hdr(oh, len+sizeof(*foh));
Harald Welte52b1f982008-12-23 20:25:15 +0000476 foh->msg_type = msg_type;
477 foh->obj_class = obj_class;
478 foh->obj_inst.bts_nr = bts_nr;
479 foh->obj_inst.trx_nr = trx_nr;
480 foh->obj_inst.ts_nr = ts_nr;
481}
482
Harald Welte8470bf22008-12-25 23:28:35 +0000483static struct msgb *nm_msgb_alloc(void)
484{
Harald Welte966636f2009-06-26 19:39:35 +0200485 return msgb_alloc_headroom(OM_ALLOC_SIZE, OM_HEADROOM_SIZE,
486 "OML");
Harald Welte8470bf22008-12-25 23:28:35 +0000487}
488
Harald Welte52b1f982008-12-23 20:25:15 +0000489/* Send a OML NM Message from BSC to BTS */
490int abis_nm_sendmsg(struct gsm_bts *bts, struct msgb *msg)
491{
Holger Freyther59639e82009-02-09 23:09:55 +0000492 msg->trx = bts->c0;
493
Harald Weltead384642008-12-26 10:20:07 +0000494 return _abis_nm_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000495}
496
Harald Welte4724f992009-01-18 18:01:49 +0000497static int abis_nm_rcvmsg_sw(struct msgb *mb);
498
Harald Welte34a99682009-02-13 02:41:40 +0000499static const char *obj_class_name(u_int8_t oc)
500{
Harald Welte7b26bcb2009-05-28 11:39:21 +0000501 switch (oc) {
502 case NM_OC_SITE_MANAGER:
503 return "SITE MANAGER";
504 case NM_OC_BTS:
505 return "BTS";
506 case NM_OC_RADIO_CARRIER:
507 return "RADIO CARRIER";
508 case NM_OC_BASEB_TRANSC:
509 return "BASEBAND TRANSCEIVER";
510 case NM_OC_CHANNEL:
Harald Weltebd8f7e32009-06-09 20:17:12 +0000511 return "CHANNEL";
Harald Welte7b26bcb2009-05-28 11:39:21 +0000512 case NM_OC_BS11_ADJC:
513 return "ADJC";
514 case NM_OC_BS11_HANDOVER:
515 return "HANDOVER";
516 case NM_OC_BS11_PWR_CTRL:
517 return "POWER CONTROL";
518 case NM_OC_BS11_BTSE:
519 return "BTSE";
520 case NM_OC_BS11_RACK:
521 return "RACK";
522 case NM_OC_BS11_TEST:
523 return "TEST";
524 case NM_OC_BS11_ENVABTSE:
525 return "ENVABTSE";
526 case NM_OC_BS11_BPORT:
527 return "BPORT";
528 case NM_OC_GPRS_NSE:
529 return "GPRS NSE";
530 case NM_OC_GPRS_CELL:
531 return "GPRS CELL";
Harald Welted83a1272009-07-12 10:56:06 +0200532 case NM_OC_GPRS_NSVC:
533 return "GPRS NSVC";
Harald Welte8b697c72009-06-05 19:18:45 +0000534 case NM_OC_BS11:
535 return "SIEMENSHW";
Harald Welte7b26bcb2009-05-28 11:39:21 +0000536 }
537
538 return "UNKNOWN";
Harald Welte34a99682009-02-13 02:41:40 +0000539}
540
Harald Welte4d87f242009-03-10 19:43:44 +0000541const char *nm_opstate_name(u_int8_t os)
Harald Welte34a99682009-02-13 02:41:40 +0000542{
543 switch (os) {
544 case 1:
545 return "Disabled";
546 case 2:
547 return "Enabled";
548 case 0xff:
549 return "NULL";
550 default:
551 return "RFU";
552 }
553}
554
Harald Weltee0590df2009-02-15 03:34:15 +0000555/* Chapter 9.4.7 */
Harald Welte4d87f242009-03-10 19:43:44 +0000556static const char *avail_names[] = {
Harald Weltee0590df2009-02-15 03:34:15 +0000557 "In test",
558 "Failed",
559 "Power off",
560 "Off line",
561 "<not used>",
562 "Dependency",
563 "Degraded",
564 "Not installed",
565};
566
Harald Welte4d87f242009-03-10 19:43:44 +0000567const char *nm_avail_name(u_int8_t avail)
Harald Weltee0590df2009-02-15 03:34:15 +0000568{
Harald Welte0b8348d2009-02-18 03:43:01 +0000569 if (avail == 0xff)
570 return "OK";
Harald Weltee0590df2009-02-15 03:34:15 +0000571 if (avail >= ARRAY_SIZE(avail_names))
572 return "UNKNOWN";
573 return avail_names[avail];
574}
Harald Welte7b26bcb2009-05-28 11:39:21 +0000575
576const char *nm_adm_name(u_int8_t adm)
577{
578 switch (adm) {
579 case 1:
580 return "Locked";
581 case 2:
582 return "Unlocked";
583 case 3:
584 return "Shutdown";
585 default:
586 return "<not used>";
587 }
588}
Harald Weltee0590df2009-02-15 03:34:15 +0000589
Harald Weltea8bd6d42009-10-20 09:56:18 +0200590static void debugp_foh(struct abis_om_fom_hdr *foh)
591{
592 DEBUGP(DNM, "OC=%s(%02x) INST=(%02x,%02x,%02x) ",
593 obj_class_name(foh->obj_class), foh->obj_class,
594 foh->obj_inst.bts_nr, foh->obj_inst.trx_nr,
595 foh->obj_inst.ts_nr);
596}
597
Harald Weltee0590df2009-02-15 03:34:15 +0000598/* obtain the gsm_nm_state data structure for a given object instance */
599static struct gsm_nm_state *
600objclass2nmstate(struct gsm_bts *bts, u_int8_t obj_class,
601 struct abis_om_obj_inst *obj_inst)
602{
603 struct gsm_bts_trx *trx;
604 struct gsm_nm_state *nm_state = NULL;
605
606 switch (obj_class) {
607 case NM_OC_BTS:
608 nm_state = &bts->nm_state;
609 break;
610 case NM_OC_RADIO_CARRIER:
611 if (obj_inst->trx_nr >= bts->num_trx)
612 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200613 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000614 nm_state = &trx->nm_state;
615 break;
616 case NM_OC_BASEB_TRANSC:
617 if (obj_inst->trx_nr >= bts->num_trx)
618 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200619 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000620 nm_state = &trx->bb_transc.nm_state;
621 break;
622 case NM_OC_CHANNEL:
623 if (obj_inst->trx_nr > bts->num_trx)
624 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200625 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000626 if (obj_inst->ts_nr >= TRX_NR_TS)
627 return NULL;
628 nm_state = &trx->ts[obj_inst->ts_nr].nm_state;
629 break;
630 case NM_OC_SITE_MANAGER:
631 nm_state = &bts->site_mgr.nm_state;
632 break;
Harald Welte7b26bcb2009-05-28 11:39:21 +0000633 case NM_OC_BS11:
634 switch (obj_inst->bts_nr) {
635 case BS11_OBJ_CCLK:
636 nm_state = &bts->bs11.cclk.nm_state;
637 break;
Harald Welte8b697c72009-06-05 19:18:45 +0000638 case BS11_OBJ_BBSIG:
639 if (obj_inst->ts_nr > bts->num_trx)
640 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200641 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Welte8b697c72009-06-05 19:18:45 +0000642 nm_state = &trx->bs11.bbsig.nm_state;
643 break;
644 case BS11_OBJ_PA:
645 if (obj_inst->ts_nr > bts->num_trx)
646 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200647 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Welte8b697c72009-06-05 19:18:45 +0000648 nm_state = &trx->bs11.pa.nm_state;
649 break;
Harald Welte7b26bcb2009-05-28 11:39:21 +0000650 default:
651 return NULL;
652 }
653 case NM_OC_BS11_RACK:
654 nm_state = &bts->bs11.rack.nm_state;
655 break;
Harald Welte8b697c72009-06-05 19:18:45 +0000656 case NM_OC_BS11_ENVABTSE:
657 if (obj_inst->trx_nr > ARRAY_SIZE(bts->bs11.envabtse))
658 return NULL;
659 nm_state = &bts->bs11.envabtse[obj_inst->trx_nr].nm_state;
660 break;
Harald Welte55dd4432009-10-24 10:19:14 +0200661 case NM_OC_GPRS_NSE:
662 nm_state = &bts->gprs.nse.nm_state;
663 break;
664 case NM_OC_GPRS_CELL:
665 nm_state = &bts->gprs.cell.nm_state;
666 break;
667 case NM_OC_GPRS_NSVC:
668 if (obj_inst->trx_nr > ARRAY_SIZE(bts->gprs.nsvc))
669 return NULL;
670 nm_state = &bts->gprs.nsvc[obj_inst->trx_nr].nm_state;
671 break;
Harald Weltee0590df2009-02-15 03:34:15 +0000672 }
673 return nm_state;
674}
675
676/* obtain the in-memory data structure of a given object instance */
677static void *
678objclass2obj(struct gsm_bts *bts, u_int8_t obj_class,
679 struct abis_om_obj_inst *obj_inst)
680{
681 struct gsm_bts_trx *trx;
682 void *obj = NULL;
683
684 switch (obj_class) {
685 case NM_OC_BTS:
686 obj = bts;
687 break;
688 case NM_OC_RADIO_CARRIER:
689 if (obj_inst->trx_nr >= bts->num_trx)
690 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200691 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000692 obj = trx;
693 break;
694 case NM_OC_BASEB_TRANSC:
695 if (obj_inst->trx_nr >= bts->num_trx)
696 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200697 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000698 obj = &trx->bb_transc;
699 break;
700 case NM_OC_CHANNEL:
701 if (obj_inst->trx_nr > bts->num_trx)
702 return NULL;
Harald Weltee441d9c2009-06-21 16:17:15 +0200703 trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000704 if (obj_inst->ts_nr >= TRX_NR_TS)
705 return NULL;
706 obj = &trx->ts[obj_inst->ts_nr];
707 break;
708 case NM_OC_SITE_MANAGER:
709 obj = &bts->site_mgr;
710 break;
Harald Welte55dd4432009-10-24 10:19:14 +0200711 case NM_OC_GPRS_NSE:
712 obj = &bts->gprs.nse;
713 break;
714 case NM_OC_GPRS_CELL:
715 obj = &bts->gprs.cell;
716 break;
717 case NM_OC_GPRS_NSVC:
718 if (obj_inst->trx_nr > ARRAY_SIZE(bts->gprs.nsvc))
719 return NULL;
720 obj = &bts->gprs.nsvc[obj_inst->trx_nr];
721 break;
Harald Weltee0590df2009-02-15 03:34:15 +0000722 }
723 return obj;
724}
725
726/* Update the administrative state of a given object in our in-memory data
727 * structures and send an event to the higher layer */
728static int update_admstate(struct gsm_bts *bts, u_int8_t obj_class,
729 struct abis_om_obj_inst *obj_inst, u_int8_t adm_state)
730{
Harald Welteaeedeb42009-05-01 13:08:14 +0000731 struct gsm_nm_state *nm_state, new_state;
Harald Weltee0590df2009-02-15 03:34:15 +0000732 void *obj;
733 int rc;
734
Harald Weltee0590df2009-02-15 03:34:15 +0000735 obj = objclass2obj(bts, obj_class, obj_inst);
Harald Welteaeedeb42009-05-01 13:08:14 +0000736 nm_state = objclass2nmstate(bts, obj_class, obj_inst);
737 if (!nm_state)
738 return -1;
739
740 new_state = *nm_state;
741 new_state.administrative = adm_state;
742
743 rc = nm_state_event(EVT_STATECHG_ADM, obj_class, obj, nm_state, &new_state);
744
745 nm_state->administrative = adm_state;
Harald Weltee0590df2009-02-15 03:34:15 +0000746
747 return rc;
748}
749
Harald Welte97ed1e72009-02-06 13:38:02 +0000750static int abis_nm_rx_statechg_rep(struct msgb *mb)
751{
Harald Weltee0590df2009-02-15 03:34:15 +0000752 struct abis_om_hdr *oh = msgb_l2(mb);
Harald Welte97ed1e72009-02-06 13:38:02 +0000753 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Harald Welte22af0db2009-02-14 15:41:08 +0000754 struct gsm_bts *bts = mb->trx->bts;
Harald Weltee0590df2009-02-15 03:34:15 +0000755 struct tlv_parsed tp;
756 struct gsm_nm_state *nm_state, new_state;
757 int rc;
758
Harald Welte23897662009-05-01 14:52:51 +0000759 DEBUGPC(DNM, "STATE CHG: ");
Harald Weltee0590df2009-02-15 03:34:15 +0000760
Harald Welte8b697c72009-06-05 19:18:45 +0000761 memset(&new_state, 0, sizeof(new_state));
762
Harald Weltee0590df2009-02-15 03:34:15 +0000763 nm_state = objclass2nmstate(bts, foh->obj_class, &foh->obj_inst);
764 if (!nm_state) {
765 DEBUGPC(DNM, "\n");
766 return -EINVAL;
Harald Welte22af0db2009-02-14 15:41:08 +0000767 }
Harald Weltee0590df2009-02-15 03:34:15 +0000768
769 new_state = *nm_state;
770
Harald Welte03133942009-02-18 19:51:53 +0000771 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Weltee0590df2009-02-15 03:34:15 +0000772 if (TLVP_PRESENT(&tp, NM_ATT_OPER_STATE)) {
773 new_state.operational = *TLVP_VAL(&tp, NM_ATT_OPER_STATE);
Harald Welte4d87f242009-03-10 19:43:44 +0000774 DEBUGPC(DNM, "OP_STATE=%s ", nm_opstate_name(new_state.operational));
Harald Weltee0590df2009-02-15 03:34:15 +0000775 }
776 if (TLVP_PRESENT(&tp, NM_ATT_AVAIL_STATUS)) {
Harald Welte0b8348d2009-02-18 03:43:01 +0000777 if (TLVP_LEN(&tp, NM_ATT_AVAIL_STATUS) == 0)
778 new_state.availability = 0xff;
779 else
780 new_state.availability = *TLVP_VAL(&tp, NM_ATT_AVAIL_STATUS);
Harald Welte4d87f242009-03-10 19:43:44 +0000781 DEBUGPC(DNM, "AVAIL=%s(%02x) ", nm_avail_name(new_state.availability),
Harald Weltee0590df2009-02-15 03:34:15 +0000782 new_state.availability);
783 }
784 if (TLVP_PRESENT(&tp, NM_ATT_ADM_STATE)) {
785 new_state.administrative = *TLVP_VAL(&tp, NM_ATT_ADM_STATE);
Holger Hans Peter Freyther2c481b22009-10-22 15:44:30 +0200786 DEBUGPC(DNM, "ADM=%2s ", nm_adm_name(new_state.administrative));
Harald Welte97ed1e72009-02-06 13:38:02 +0000787 }
788 DEBUGPC(DNM, "\n");
Harald Weltee0590df2009-02-15 03:34:15 +0000789
790 if (memcmp(&new_state, nm_state, sizeof(new_state))) {
791 /* Update the operational state of a given object in our in-memory data
792 * structures and send an event to the higher layer */
793 void *obj = objclass2obj(bts, foh->obj_class, &foh->obj_inst);
794 rc = nm_state_event(EVT_STATECHG_OPER, foh->obj_class, obj, nm_state, &new_state);
795 *nm_state = new_state;
796 }
797#if 0
Harald Welte22af0db2009-02-14 15:41:08 +0000798 if (op_state == 1) {
799 /* try to enable objects that are disabled */
800 abis_nm_opstart(bts, foh->obj_class,
801 foh->obj_inst.bts_nr,
802 foh->obj_inst.trx_nr,
803 foh->obj_inst.ts_nr);
804 }
Harald Weltee0590df2009-02-15 03:34:15 +0000805#endif
Harald Welte97ed1e72009-02-06 13:38:02 +0000806 return 0;
807}
808
Harald Welte0db97b22009-05-01 17:22:47 +0000809static int rx_fail_evt_rep(struct msgb *mb)
810{
811 struct abis_om_hdr *oh = msgb_l2(mb);
812 struct abis_om_fom_hdr *foh = msgb_l3(mb);
813 struct tlv_parsed tp;
814
815 DEBUGPC(DNM, "Failure Event Report ");
816
817 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
818
819 if (TLVP_PRESENT(&tp, NM_ATT_EVENT_TYPE))
820 DEBUGPC(DNM, "Type=%s ", event_type_name(*TLVP_VAL(&tp, NM_ATT_EVENT_TYPE)));
821 if (TLVP_PRESENT(&tp, NM_ATT_SEVERITY))
822 DEBUGPC(DNM, "Severity=%s ", severity_name(*TLVP_VAL(&tp, NM_ATT_SEVERITY)));
823
824 DEBUGPC(DNM, "\n");
825
826 return 0;
827}
828
Harald Welte97ed1e72009-02-06 13:38:02 +0000829static int abis_nm_rcvmsg_report(struct msgb *mb)
830{
831 struct abis_om_fom_hdr *foh = msgb_l3(mb);
832 u_int8_t mt = foh->msg_type;
833
Harald Weltea8bd6d42009-10-20 09:56:18 +0200834 debugp_foh(foh);
Harald Welte23897662009-05-01 14:52:51 +0000835
Harald Welte97ed1e72009-02-06 13:38:02 +0000836 //nmh->cfg->report_cb(mb, foh);
837
838 switch (mt) {
839 case NM_MT_STATECHG_EVENT_REP:
840 return abis_nm_rx_statechg_rep(mb);
841 break;
Harald Welte34a99682009-02-13 02:41:40 +0000842 case NM_MT_SW_ACTIVATED_REP:
Harald Welte23897662009-05-01 14:52:51 +0000843 DEBUGPC(DNM, "Software Activated Report\n");
Harald Weltef9a8cc32009-05-01 15:39:49 +0000844 dispatch_signal(SS_NM, S_NM_SW_ACTIV_REP, mb);
Harald Welte34a99682009-02-13 02:41:40 +0000845 break;
Harald Weltee0590df2009-02-15 03:34:15 +0000846 case NM_MT_FAILURE_EVENT_REP:
Harald Welte0db97b22009-05-01 17:22:47 +0000847 rx_fail_evt_rep(mb);
Harald Weltef9a8cc32009-05-01 15:39:49 +0000848 dispatch_signal(SS_NM, S_NM_FAIL_REP, mb);
Harald Weltee0590df2009-02-15 03:34:15 +0000849 break;
Harald Weltec7310382009-08-08 00:02:36 +0200850 case NM_MT_TEST_REP:
851 DEBUGPC(DNM, "Test Report\n");
852 dispatch_signal(SS_NM, S_NM_TEST_REP, mb);
853 break;
Harald Weltee0590df2009-02-15 03:34:15 +0000854 default:
Harald Welte23897662009-05-01 14:52:51 +0000855 DEBUGPC(DNM, "reporting NM MT 0x%02x\n", mt);
Harald Weltee0590df2009-02-15 03:34:15 +0000856 break;
857
Harald Welte97ed1e72009-02-06 13:38:02 +0000858 };
859
Harald Welte97ed1e72009-02-06 13:38:02 +0000860 return 0;
861}
862
Harald Welte34a99682009-02-13 02:41:40 +0000863/* Activate the specified software into the BTS */
864static 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 +0200865 u_int8_t i2, const u_int8_t *sw_desc, u_int8_t swdesc_len)
Harald Welte34a99682009-02-13 02:41:40 +0000866{
867 struct abis_om_hdr *oh;
868 struct msgb *msg = nm_msgb_alloc();
869 u_int8_t len = swdesc_len;
870 u_int8_t *trailer;
871
872 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
873 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, obj_class, i0, i1, i2);
874
875 trailer = msgb_put(msg, swdesc_len);
876 memcpy(trailer, sw_desc, swdesc_len);
877
878 return abis_nm_sendmsg(bts, msg);
879}
880
881static int abis_nm_rx_sw_act_req(struct msgb *mb)
882{
883 struct abis_om_hdr *oh = msgb_l2(mb);
884 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Mike Habena03f9772009-10-01 14:56:13 +0200885 struct tlv_parsed tp;
886 const u_int8_t *sw_config;
887 int sw_config_len;
888 int file_id_len;
Harald Welte5c1e4582009-02-15 11:57:29 +0000889 int nack = 0;
Harald Welte34a99682009-02-13 02:41:40 +0000890 int ret;
891
Harald Weltea8bd6d42009-10-20 09:56:18 +0200892 debugp_foh(foh);
893
894 DEBUGPC(DNM, "SW Activate Request: ");
Harald Welte34a99682009-02-13 02:41:40 +0000895
Harald Welte5c1e4582009-02-15 11:57:29 +0000896 if (foh->obj_class >= 0xf0 && foh->obj_class <= 0xf3) {
897 DEBUGPC(DNM, "NACKing for GPRS obj_class 0x%02x\n", foh->obj_class);
898 nack = 1;
899 } else
900 DEBUGPC(DNM, "ACKing and Activating\n");
901
902 ret = abis_nm_sw_act_req_ack(mb->trx->bts, foh->obj_class,
Harald Welte34a99682009-02-13 02:41:40 +0000903 foh->obj_inst.bts_nr,
904 foh->obj_inst.trx_nr,
Harald Welte5c1e4582009-02-15 11:57:29 +0000905 foh->obj_inst.ts_nr, nack,
Harald Welte34a99682009-02-13 02:41:40 +0000906 foh->data, oh->length-sizeof(*foh));
907
Harald Welte5c1e4582009-02-15 11:57:29 +0000908 if (nack)
909 return ret;
910
Mike Habena03f9772009-10-01 14:56:13 +0200911 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
912 sw_config = TLVP_VAL(&tp, NM_ATT_SW_CONFIG);
913 sw_config_len = TLVP_LEN(&tp, NM_ATT_SW_CONFIG);
914 if (!TLVP_PRESENT(&tp, NM_ATT_SW_CONFIG)) {
915 DEBUGP(DNM, "SW config not found! Can't continue.\n");
916 return -EINVAL;
917 } else {
918 DEBUGP(DNM, "Found SW config: %s\n", hexdump(sw_config, sw_config_len));
919 }
920
921 if (sw_config[0] != NM_ATT_SW_DESCR)
922 DEBUGP(DNM, "SW_DESCR attribute identifier not found!\n");
923 if (sw_config[1] != NM_ATT_FILE_ID)
924 DEBUGP(DNM, "FILE_ID attribute identifier not found!\n");
925 file_id_len = sw_config[2] * 256 + sw_config[3];
926
927 /* Assumes first SW file in list is the one to be activated */
928 /* sw_config + 4 to skip over 2 attribute ID bytes and 16-bit length field */
Harald Welte34a99682009-02-13 02:41:40 +0000929 return ipacc_sw_activate(mb->trx->bts, foh->obj_class,
930 foh->obj_inst.bts_nr,
931 foh->obj_inst.trx_nr,
932 foh->obj_inst.ts_nr,
Mike Habena03f9772009-10-01 14:56:13 +0200933 sw_config + 4,
934 file_id_len);
Harald Welte34a99682009-02-13 02:41:40 +0000935}
936
Harald Weltee0590df2009-02-15 03:34:15 +0000937/* Receive a CHANGE_ADM_STATE_ACK, parse the TLV and update local state */
938static int abis_nm_rx_chg_adm_state_ack(struct msgb *mb)
939{
940 struct abis_om_hdr *oh = msgb_l2(mb);
941 struct abis_om_fom_hdr *foh = msgb_l3(mb);
942 struct tlv_parsed tp;
943 u_int8_t adm_state;
944
Harald Welte03133942009-02-18 19:51:53 +0000945 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Weltee0590df2009-02-15 03:34:15 +0000946 if (!TLVP_PRESENT(&tp, NM_ATT_ADM_STATE))
947 return -EINVAL;
948
949 adm_state = *TLVP_VAL(&tp, NM_ATT_ADM_STATE);
950
951 return update_admstate(mb->trx->bts, foh->obj_class, &foh->obj_inst, adm_state);
952}
953
Harald Welteee670472009-02-22 21:58:49 +0000954static int abis_nm_rx_lmt_event(struct msgb *mb)
955{
956 struct abis_om_hdr *oh = msgb_l2(mb);
957 struct abis_om_fom_hdr *foh = msgb_l3(mb);
958 struct tlv_parsed tp;
959
960 DEBUGP(DNM, "LMT Event ");
961 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
962 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_LOGON_SESSION) &&
963 TLVP_LEN(&tp, NM_ATT_BS11_LMT_LOGON_SESSION) >= 1) {
964 u_int8_t onoff = *TLVP_VAL(&tp, NM_ATT_BS11_LMT_LOGON_SESSION);
965 DEBUGPC(DNM, "LOG%s ", onoff ? "ON" : "OFF");
966 }
967 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV) &&
968 TLVP_LEN(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV) >= 1) {
969 u_int8_t level = *TLVP_VAL(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV);
970 DEBUGPC(DNM, "Level=%u ", level);
971 }
972 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_USER_NAME) &&
973 TLVP_LEN(&tp, NM_ATT_BS11_LMT_USER_NAME) >= 1) {
974 char *name = (char *) TLVP_VAL(&tp, NM_ATT_BS11_LMT_USER_NAME);
975 DEBUGPC(DNM, "Username=%s ", name);
976 }
977 DEBUGPC(DNM, "\n");
978 /* FIXME: parse LMT LOGON TIME */
979 return 0;
980}
981
Harald Welte52b1f982008-12-23 20:25:15 +0000982/* Receive a OML NM Message from BTS */
Harald Welte8470bf22008-12-25 23:28:35 +0000983static int abis_nm_rcvmsg_fom(struct msgb *mb)
Harald Welte52b1f982008-12-23 20:25:15 +0000984{
Harald Welte6c96ba52009-05-01 13:03:40 +0000985 struct abis_om_hdr *oh = msgb_l2(mb);
Harald Welte52b1f982008-12-23 20:25:15 +0000986 struct abis_om_fom_hdr *foh = msgb_l3(mb);
987 u_int8_t mt = foh->msg_type;
988
989 /* check for unsolicited message */
Harald Welte97ed1e72009-02-06 13:38:02 +0000990 if (is_report(mt))
991 return abis_nm_rcvmsg_report(mb);
Harald Welte52b1f982008-12-23 20:25:15 +0000992
Harald Welte4724f992009-01-18 18:01:49 +0000993 if (is_in_arr(mt, sw_load_msgs, ARRAY_SIZE(sw_load_msgs)))
994 return abis_nm_rcvmsg_sw(mb);
995
Harald Welte78fc0d42009-02-19 02:50:57 +0000996 if (is_in_arr(mt, nacks, ARRAY_SIZE(nacks))) {
Harald Welte6c96ba52009-05-01 13:03:40 +0000997 struct tlv_parsed tp;
Harald Welte4bd0a982009-10-08 20:18:59 +0200998
Harald Weltea8bd6d42009-10-20 09:56:18 +0200999 debugp_foh(foh);
Harald Welte4bd0a982009-10-08 20:18:59 +02001000
Harald Welte78fc0d42009-02-19 02:50:57 +00001001 if (nack_names[mt])
Harald Welte4bd0a982009-10-08 20:18:59 +02001002 DEBUGPC(DNM, "%s NACK ", nack_names[mt]);
Harald Welte6c96ba52009-05-01 13:03:40 +00001003 /* FIXME: NACK cause */
Harald Welte78fc0d42009-02-19 02:50:57 +00001004 else
Harald Welte4bd0a982009-10-08 20:18:59 +02001005 DEBUGPC(DNM, "NACK 0x%02x ", mt);
Harald Welte6c96ba52009-05-01 13:03:40 +00001006
1007 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
1008 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
1009 DEBUGPC(DNM, "CAUSE=%s\n",
1010 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
1011 else
1012 DEBUGPC(DNM, "\n");
Holger Hans Peter Freyther500f3ca2009-06-10 10:48:14 +02001013
1014 dispatch_signal(SS_NM, S_NM_NACK, (void*) ((long)mt));
1015 return 0;
Harald Welte78fc0d42009-02-19 02:50:57 +00001016 }
Harald Weltead384642008-12-26 10:20:07 +00001017#if 0
Harald Welte52b1f982008-12-23 20:25:15 +00001018 /* check if last message is to be acked */
1019 if (is_ack_nack(nmh->last_msgtype)) {
1020 if (mt == MT_ACK(nmh->last_msgtype)) {
1021 fprintf(stderr, "received ACK (0x%x)\n",
1022 foh->msg_type);
1023 /* we got our ACK, continue sending the next msg */
1024 } else if (mt == MT_NACK(nmh->last_msgtype)) {
1025 /* we got a NACK, signal this to the caller */
1026 fprintf(stderr, "received NACK (0x%x)\n",
1027 foh->msg_type);
1028 /* FIXME: somehow signal this to the caller */
1029 } else {
1030 /* really strange things happen */
1031 return -EINVAL;
1032 }
1033 }
Harald Weltead384642008-12-26 10:20:07 +00001034#endif
1035
Harald Welte97ed1e72009-02-06 13:38:02 +00001036 switch (mt) {
Harald Weltee0590df2009-02-15 03:34:15 +00001037 case NM_MT_CHG_ADM_STATE_ACK:
1038 return abis_nm_rx_chg_adm_state_ack(mb);
1039 break;
Harald Welte34a99682009-02-13 02:41:40 +00001040 case NM_MT_SW_ACT_REQ:
1041 return abis_nm_rx_sw_act_req(mb);
1042 break;
Harald Welte97ed1e72009-02-06 13:38:02 +00001043 case NM_MT_BS11_LMT_SESSION:
Harald Welteee670472009-02-22 21:58:49 +00001044 return abis_nm_rx_lmt_event(mb);
Harald Welte97ed1e72009-02-06 13:38:02 +00001045 break;
Harald Welte1989c082009-08-06 17:58:31 +02001046 case NM_MT_CONN_MDROP_LINK_ACK:
1047 DEBUGP(DNM, "CONN MDROP LINK ACK\n");
1048 break;
Harald Welte97ed1e72009-02-06 13:38:02 +00001049 }
1050
Harald Weltead384642008-12-26 10:20:07 +00001051 return 0;
Harald Welte52b1f982008-12-23 20:25:15 +00001052}
1053
Harald Welte677c21f2009-02-17 13:22:23 +00001054static int abis_nm_rx_ipacc(struct msgb *mb);
1055
1056static int abis_nm_rcvmsg_manuf(struct msgb *mb)
1057{
1058 int rc;
1059 int bts_type = mb->trx->bts->type;
1060
1061 switch (bts_type) {
Mike Habene2d82272009-10-02 12:19:34 +01001062 case GSM_BTS_TYPE_NANOBTS:
Harald Welte677c21f2009-02-17 13:22:23 +00001063 rc = abis_nm_rx_ipacc(mb);
1064 break;
1065 default:
1066 fprintf(stderr, "don't know how to parse OML for this "
1067 "BTS type (%u)\n", bts_type);
1068 rc = 0;
1069 break;
1070 }
1071
1072 return rc;
1073}
1074
Harald Welte52b1f982008-12-23 20:25:15 +00001075/* High-Level API */
1076/* Entry-point where L2 OML from BTS enters the NM code */
Harald Welte8470bf22008-12-25 23:28:35 +00001077int abis_nm_rcvmsg(struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +00001078{
Harald Welte52b1f982008-12-23 20:25:15 +00001079 struct abis_om_hdr *oh = msgb_l2(msg);
Harald Welte677c21f2009-02-17 13:22:23 +00001080 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +00001081
1082 /* Various consistency checks */
1083 if (oh->placement != ABIS_OM_PLACEMENT_ONLY) {
1084 fprintf(stderr, "ABIS OML placement 0x%x not supported\n",
1085 oh->placement);
1086 return -EINVAL;
1087 }
1088 if (oh->sequence != 0) {
1089 fprintf(stderr, "ABIS OML sequence 0x%x != 0x00\n",
1090 oh->sequence);
1091 return -EINVAL;
1092 }
Harald Welte702d8702008-12-26 20:25:35 +00001093#if 0
Holger Freytherca362a62009-01-04 21:05:01 +00001094 unsigned int l2_len = msg->tail - (u_int8_t *)msgb_l2(msg);
1095 unsigned int hlen = sizeof(*oh) + sizeof(struct abis_om_fom_hdr);
Harald Welte702d8702008-12-26 20:25:35 +00001096 if (oh->length + hlen > l2_len) {
Harald Welte52b1f982008-12-23 20:25:15 +00001097 fprintf(stderr, "ABIS OML truncated message (%u > %u)\n",
1098 oh->length + sizeof(*oh), l2_len);
1099 return -EINVAL;
1100 }
Harald Welte702d8702008-12-26 20:25:35 +00001101 if (oh->length + hlen < l2_len)
1102 fprintf(stderr, "ABIS OML message with extra trailer?!? (oh->len=%d, sizeof_oh=%d l2_len=%d\n", oh->length, sizeof(*oh), l2_len);
1103#endif
Harald Weltead384642008-12-26 10:20:07 +00001104 msg->l3h = (unsigned char *)oh + sizeof(*oh);
Harald Welte52b1f982008-12-23 20:25:15 +00001105
1106 switch (oh->mdisc) {
1107 case ABIS_OM_MDISC_FOM:
Harald Welte8470bf22008-12-25 23:28:35 +00001108 rc = abis_nm_rcvmsg_fom(msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001109 break;
Harald Welte677c21f2009-02-17 13:22:23 +00001110 case ABIS_OM_MDISC_MANUF:
1111 rc = abis_nm_rcvmsg_manuf(msg);
1112 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001113 case ABIS_OM_MDISC_MMI:
1114 case ABIS_OM_MDISC_TRAU:
Harald Welte677c21f2009-02-17 13:22:23 +00001115 fprintf(stderr, "unimplemented ABIS OML message discriminator 0x%x\n",
1116 oh->mdisc);
1117 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001118 default:
1119 fprintf(stderr, "unknown ABIS OML message discriminator 0x%x\n",
1120 oh->mdisc);
1121 return -EINVAL;
1122 }
1123
Harald Weltead384642008-12-26 10:20:07 +00001124 msgb_free(msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001125 return rc;
1126}
1127
1128#if 0
1129/* initialized all resources */
1130struct abis_nm_h *abis_nm_init(struct abis_nm_cfg *cfg)
1131{
1132 struct abis_nm_h *nmh;
1133
1134 nmh = malloc(sizeof(*nmh));
1135 if (!nmh)
1136 return NULL;
1137
1138 nmh->cfg = cfg;
1139
1140 return nmh;
1141}
1142
1143/* free all resources */
1144void abis_nm_fini(struct abis_nm_h *nmh)
1145{
1146 free(nmh);
1147}
1148#endif
1149
1150/* Here we are trying to define a high-level API that can be used by
1151 * the actual BSC implementation. However, the architecture is currently
1152 * still under design. Ideally the calls to this API would be synchronous,
1153 * while the underlying stack behind the APi runs in a traditional select
1154 * based state machine.
1155 */
1156
Harald Welte4724f992009-01-18 18:01:49 +00001157/* 6.2 Software Load: */
1158enum sw_state {
1159 SW_STATE_NONE,
1160 SW_STATE_WAIT_INITACK,
1161 SW_STATE_WAIT_SEGACK,
1162 SW_STATE_WAIT_ENDACK,
1163 SW_STATE_WAIT_ACTACK,
1164 SW_STATE_ERROR,
1165};
Harald Welte52b1f982008-12-23 20:25:15 +00001166
Harald Welte52b1f982008-12-23 20:25:15 +00001167struct abis_nm_sw {
Harald Welte4724f992009-01-18 18:01:49 +00001168 struct gsm_bts *bts;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001169 gsm_cbfn *cbfn;
1170 void *cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +00001171 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001172
Harald Welte52b1f982008-12-23 20:25:15 +00001173 /* this will become part of the SW LOAD INITIATE */
1174 u_int8_t obj_class;
1175 u_int8_t obj_instance[3];
Harald Welte4724f992009-01-18 18:01:49 +00001176
1177 u_int8_t file_id[255];
1178 u_int8_t file_id_len;
1179
1180 u_int8_t file_version[255];
1181 u_int8_t file_version_len;
1182
1183 u_int8_t window_size;
1184 u_int8_t seg_in_window;
1185
1186 int fd;
1187 FILE *stream;
1188 enum sw_state state;
Harald Welte1602ade2009-01-29 21:12:39 +00001189 int last_seg;
Harald Welte52b1f982008-12-23 20:25:15 +00001190};
1191
Harald Welte4724f992009-01-18 18:01:49 +00001192static struct abis_nm_sw g_sw;
1193
1194/* 6.2.1 / 8.3.1: Load Data Initiate */
1195static int sw_load_init(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +00001196{
Harald Welte4724f992009-01-18 18:01:49 +00001197 struct abis_om_hdr *oh;
1198 struct msgb *msg = nm_msgb_alloc();
1199 u_int8_t len = 3*2 + sw->file_id_len + sw->file_version_len;
1200
1201 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1202 fill_om_fom_hdr(oh, len, NM_MT_LOAD_INIT, sw->obj_class,
1203 sw->obj_instance[0], sw->obj_instance[1],
1204 sw->obj_instance[2]);
1205
1206 /* FIXME: this is BS11 specific format */
1207 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1208 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1209 sw->file_version);
1210 msgb_tv_put(msg, NM_ATT_WINDOW_SIZE, sw->window_size);
1211
1212 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001213}
1214
Harald Welte1602ade2009-01-29 21:12:39 +00001215static int is_last_line(FILE *stream)
1216{
1217 char next_seg_buf[256];
1218 long pos;
1219
1220 /* check if we're sending the last line */
1221 pos = ftell(stream);
1222 if (!fgets(next_seg_buf, sizeof(next_seg_buf)-2, stream)) {
1223 fseek(stream, pos, SEEK_SET);
1224 return 1;
1225 }
1226
1227 fseek(stream, pos, SEEK_SET);
1228 return 0;
1229}
1230
Harald Welte4724f992009-01-18 18:01:49 +00001231/* 6.2.2 / 8.3.2 Load Data Segment */
1232static int sw_load_segment(struct abis_nm_sw *sw)
1233{
1234 struct abis_om_hdr *oh;
1235 struct msgb *msg = nm_msgb_alloc();
1236 char seg_buf[256];
1237 char *line_buf = seg_buf+2;
Harald Welte3b8ba212009-01-29 12:27:58 +00001238 unsigned char *tlv;
Harald Welte4724f992009-01-18 18:01:49 +00001239 u_int8_t len;
Harald Welte4724f992009-01-18 18:01:49 +00001240
1241 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte3b8ba212009-01-29 12:27:58 +00001242
1243 switch (sw->bts->type) {
1244 case GSM_BTS_TYPE_BS11:
1245 if (fgets(line_buf, sizeof(seg_buf)-2, sw->stream) == NULL) {
1246 perror("fgets reading segment");
1247 return -EINVAL;
1248 }
1249 seg_buf[0] = 0x00;
Harald Welte1602ade2009-01-29 21:12:39 +00001250
1251 /* check if we're sending the last line */
1252 sw->last_seg = is_last_line(sw->stream);
1253 if (sw->last_seg)
1254 seg_buf[1] = 0;
1255 else
1256 seg_buf[1] = 1 + sw->seg_in_window++;
Harald Welte3b8ba212009-01-29 12:27:58 +00001257
1258 len = strlen(line_buf) + 2;
1259 tlv = msgb_put(msg, TLV_GROSS_LEN(len));
1260 tlv_put(tlv, NM_ATT_BS11_FILE_DATA, len, (u_int8_t *)seg_buf);
1261 /* BS11 wants CR + LF in excess of the TLV length !?! */
1262 tlv[1] -= 2;
1263
1264 /* we only now know the exact length for the OM hdr */
1265 len = strlen(line_buf)+2;
1266 break;
1267 default:
1268 /* FIXME: Other BTS types */
1269 return -1;
Harald Welte4724f992009-01-18 18:01:49 +00001270 }
Harald Welte4724f992009-01-18 18:01:49 +00001271
Harald Welte4724f992009-01-18 18:01:49 +00001272 fill_om_fom_hdr(oh, len, NM_MT_LOAD_SEG, sw->obj_class,
1273 sw->obj_instance[0], sw->obj_instance[1],
1274 sw->obj_instance[2]);
1275
1276 return abis_nm_sendmsg(sw->bts, msg);
1277}
1278
1279/* 6.2.4 / 8.3.4 Load Data End */
1280static int sw_load_end(struct abis_nm_sw *sw)
1281{
1282 struct abis_om_hdr *oh;
1283 struct msgb *msg = nm_msgb_alloc();
1284 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
1285
1286 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1287 fill_om_fom_hdr(oh, len, NM_MT_LOAD_END, sw->obj_class,
1288 sw->obj_instance[0], sw->obj_instance[1],
1289 sw->obj_instance[2]);
1290
1291 /* FIXME: this is BS11 specific format */
1292 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1293 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1294 sw->file_version);
1295
1296 return abis_nm_sendmsg(sw->bts, msg);
1297}
Harald Welte5e4d1b32009-02-01 13:36:56 +00001298
Harald Welte52b1f982008-12-23 20:25:15 +00001299/* Activate the specified software into the BTS */
Harald Welte4724f992009-01-18 18:01:49 +00001300static int sw_activate(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +00001301{
Harald Welte4724f992009-01-18 18:01:49 +00001302 struct abis_om_hdr *oh;
1303 struct msgb *msg = nm_msgb_alloc();
1304 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
Harald Welte52b1f982008-12-23 20:25:15 +00001305
Harald Welte4724f992009-01-18 18:01:49 +00001306 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1307 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, sw->obj_class,
1308 sw->obj_instance[0], sw->obj_instance[1],
1309 sw->obj_instance[2]);
1310
1311 /* FIXME: this is BS11 specific format */
1312 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1313 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1314 sw->file_version);
1315
1316 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001317}
Harald Welte4724f992009-01-18 18:01:49 +00001318
1319static int sw_open_file(struct abis_nm_sw *sw, const char *fname)
1320{
1321 char file_id[12+1];
1322 char file_version[80+1];
1323 int rc;
1324
1325 sw->fd = open(fname, O_RDONLY);
1326 if (sw->fd < 0)
1327 return sw->fd;
1328
1329 switch (sw->bts->type) {
1330 case GSM_BTS_TYPE_BS11:
1331 sw->stream = fdopen(sw->fd, "r");
1332 if (!sw->stream) {
1333 perror("fdopen");
1334 return -1;
1335 }
1336 /* read first line and parse file ID and VERSION */
Harald Welte3b8ba212009-01-29 12:27:58 +00001337 rc = fscanf(sw->stream, "@(#)%12s:%80s\r\n",
Harald Welte4724f992009-01-18 18:01:49 +00001338 file_id, file_version);
1339 if (rc != 2) {
1340 perror("parsing header line of software file");
1341 return -1;
1342 }
1343 strcpy((char *)sw->file_id, file_id);
1344 sw->file_id_len = strlen(file_id);
1345 strcpy((char *)sw->file_version, file_version);
1346 sw->file_version_len = strlen(file_version);
1347 /* rewind to start of file */
Harald Welte3b8ba212009-01-29 12:27:58 +00001348 rewind(sw->stream);
Harald Welte4724f992009-01-18 18:01:49 +00001349 break;
1350 default:
1351 /* We don't know how to treat them yet */
1352 close(sw->fd);
1353 return -EINVAL;
1354 }
1355
1356 return 0;
1357}
1358
1359static void sw_close_file(struct abis_nm_sw *sw)
1360{
1361 switch (sw->bts->type) {
1362 case GSM_BTS_TYPE_BS11:
1363 fclose(sw->stream);
1364 break;
1365 default:
1366 close(sw->fd);
1367 break;
1368 }
1369}
1370
1371/* Fill the window */
1372static int sw_fill_window(struct abis_nm_sw *sw)
1373{
1374 int rc;
1375
1376 while (sw->seg_in_window < sw->window_size) {
1377 rc = sw_load_segment(sw);
1378 if (rc < 0)
1379 return rc;
Harald Welte1602ade2009-01-29 21:12:39 +00001380 if (sw->last_seg)
1381 break;
Harald Welte4724f992009-01-18 18:01:49 +00001382 }
1383 return 0;
1384}
1385
1386/* callback function from abis_nm_rcvmsg() handler */
1387static int abis_nm_rcvmsg_sw(struct msgb *mb)
1388{
1389 struct abis_om_fom_hdr *foh = msgb_l3(mb);
1390 int rc = -1;
1391 struct abis_nm_sw *sw = &g_sw;
1392 enum sw_state old_state = sw->state;
1393
Harald Welte3ffd1372009-02-01 22:15:49 +00001394 //DEBUGP(DNM, "state %u, NM MT 0x%02x\n", sw->state, foh->msg_type);
Harald Welte4724f992009-01-18 18:01:49 +00001395
1396 switch (sw->state) {
1397 case SW_STATE_WAIT_INITACK:
1398 switch (foh->msg_type) {
1399 case NM_MT_LOAD_INIT_ACK:
1400 /* fill window with segments */
Harald Welte5e4d1b32009-02-01 13:36:56 +00001401 if (sw->cbfn)
1402 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1403 NM_MT_LOAD_INIT_ACK, mb,
1404 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001405 rc = sw_fill_window(sw);
1406 sw->state = SW_STATE_WAIT_SEGACK;
1407 break;
1408 case NM_MT_LOAD_INIT_NACK:
Harald Welte3ffd1372009-02-01 22:15:49 +00001409 if (sw->forced) {
1410 DEBUGP(DNM, "FORCED: Ignoring Software Load "
1411 "Init NACK\n");
1412 if (sw->cbfn)
1413 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1414 NM_MT_LOAD_INIT_ACK, mb,
1415 sw->cb_data, NULL);
1416 rc = sw_fill_window(sw);
1417 sw->state = SW_STATE_WAIT_SEGACK;
1418 } else {
1419 DEBUGP(DNM, "Software Load Init NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001420 /* FIXME: cause */
Harald Welte3ffd1372009-02-01 22:15:49 +00001421 if (sw->cbfn)
1422 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1423 NM_MT_LOAD_INIT_NACK, mb,
1424 sw->cb_data, NULL);
1425 sw->state = SW_STATE_ERROR;
1426 }
Harald Welte4724f992009-01-18 18:01:49 +00001427 break;
1428 }
1429 break;
1430 case SW_STATE_WAIT_SEGACK:
1431 switch (foh->msg_type) {
1432 case NM_MT_LOAD_SEG_ACK:
Harald Welte3ffd1372009-02-01 22:15:49 +00001433 if (sw->cbfn)
1434 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1435 NM_MT_LOAD_SEG_ACK, mb,
1436 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001437 sw->seg_in_window = 0;
Harald Welte1602ade2009-01-29 21:12:39 +00001438 if (!sw->last_seg) {
1439 /* fill window with more segments */
1440 rc = sw_fill_window(sw);
1441 sw->state = SW_STATE_WAIT_SEGACK;
1442 } else {
1443 /* end the transfer */
1444 sw->state = SW_STATE_WAIT_ENDACK;
1445 rc = sw_load_end(sw);
1446 }
Harald Welte4724f992009-01-18 18:01:49 +00001447 break;
1448 }
1449 break;
1450 case SW_STATE_WAIT_ENDACK:
1451 switch (foh->msg_type) {
1452 case NM_MT_LOAD_END_ACK:
1453 sw_close_file(sw);
Harald Welte5e4d1b32009-02-01 13:36:56 +00001454 DEBUGP(DNM, "Software Load End (BTS %u)\n",
1455 sw->bts->nr);
1456 sw->state = SW_STATE_NONE;
1457 if (sw->cbfn)
1458 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1459 NM_MT_LOAD_END_ACK, mb,
1460 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001461 break;
1462 case NM_MT_LOAD_END_NACK:
Holger Freyther31338a12009-02-06 17:43:50 +00001463 if (sw->forced) {
1464 DEBUGP(DNM, "FORCED: Ignoring Software Load"
1465 "End NACK\n");
1466 sw->state = SW_STATE_NONE;
1467 if (sw->cbfn)
1468 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1469 NM_MT_LOAD_END_ACK, mb,
1470 sw->cb_data, NULL);
1471 } else {
1472 DEBUGP(DNM, "Software Load End NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001473 /* FIXME: cause */
Holger Freyther31338a12009-02-06 17:43:50 +00001474 sw->state = SW_STATE_ERROR;
1475 if (sw->cbfn)
1476 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1477 NM_MT_LOAD_END_NACK, mb,
1478 sw->cb_data, NULL);
1479 }
Harald Welte4724f992009-01-18 18:01:49 +00001480 break;
1481 }
1482 case SW_STATE_WAIT_ACTACK:
1483 switch (foh->msg_type) {
1484 case NM_MT_ACTIVATE_SW_ACK:
1485 /* we're done */
Harald Welte5e4d1b32009-02-01 13:36:56 +00001486 DEBUGP(DNM, "Activate Software DONE!\n");
Harald Welte4724f992009-01-18 18:01:49 +00001487 sw->state = SW_STATE_NONE;
1488 rc = 0;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001489 if (sw->cbfn)
1490 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1491 NM_MT_ACTIVATE_SW_ACK, mb,
1492 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001493 break;
1494 case NM_MT_ACTIVATE_SW_NACK:
Harald Welte1602ade2009-01-29 21:12:39 +00001495 DEBUGP(DNM, "Activate Software NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001496 /* FIXME: cause */
Harald Welte4724f992009-01-18 18:01:49 +00001497 sw->state = SW_STATE_ERROR;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001498 if (sw->cbfn)
1499 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1500 NM_MT_ACTIVATE_SW_NACK, mb,
1501 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001502 break;
1503 }
1504 case SW_STATE_NONE:
Harald Weltea994a482009-05-01 15:54:23 +00001505 switch (foh->msg_type) {
1506 case NM_MT_ACTIVATE_SW_ACK:
1507 rc = 0;
1508 break;
1509 }
1510 break;
Harald Welte4724f992009-01-18 18:01:49 +00001511 case SW_STATE_ERROR:
1512 break;
1513 }
1514
1515 if (rc)
Harald Weltea994a482009-05-01 15:54:23 +00001516 DEBUGP(DNM, "unexpected NM MT 0x%02x in state %u -> %u\n",
Harald Welte4724f992009-01-18 18:01:49 +00001517 foh->msg_type, old_state, sw->state);
1518
1519 return rc;
1520}
1521
1522/* Load the specified software into the BTS */
1523int abis_nm_software_load(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00001524 u_int8_t win_size, int forced,
1525 gsm_cbfn *cbfn, void *cb_data)
Harald Welte4724f992009-01-18 18:01:49 +00001526{
1527 struct abis_nm_sw *sw = &g_sw;
1528 int rc;
1529
Harald Welte5e4d1b32009-02-01 13:36:56 +00001530 DEBUGP(DNM, "Software Load (BTS %u, File \"%s\")\n",
1531 bts->nr, fname);
1532
Harald Welte4724f992009-01-18 18:01:49 +00001533 if (sw->state != SW_STATE_NONE)
1534 return -EBUSY;
1535
1536 sw->bts = bts;
1537 sw->obj_class = NM_OC_SITE_MANAGER;
1538 sw->obj_instance[0] = 0xff;
1539 sw->obj_instance[1] = 0xff;
1540 sw->obj_instance[2] = 0xff;
1541 sw->window_size = win_size;
1542 sw->state = SW_STATE_WAIT_INITACK;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001543 sw->cbfn = cbfn;
1544 sw->cb_data = cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +00001545 sw->forced = forced;
Harald Welte4724f992009-01-18 18:01:49 +00001546
1547 rc = sw_open_file(sw, fname);
1548 if (rc < 0) {
1549 sw->state = SW_STATE_NONE;
1550 return rc;
1551 }
1552
1553 return sw_load_init(sw);
1554}
Harald Welte52b1f982008-12-23 20:25:15 +00001555
Harald Welte1602ade2009-01-29 21:12:39 +00001556int abis_nm_software_load_status(struct gsm_bts *bts)
1557{
1558 struct abis_nm_sw *sw = &g_sw;
1559 struct stat st;
1560 int rc, percent;
1561
1562 rc = fstat(sw->fd, &st);
1563 if (rc < 0) {
1564 perror("ERROR during stat");
1565 return rc;
1566 }
1567
1568 percent = (ftell(sw->stream) * 100) / st.st_size;
1569 return percent;
1570}
1571
Harald Welte5e4d1b32009-02-01 13:36:56 +00001572/* Activate the specified software into the BTS */
1573int abis_nm_software_activate(struct gsm_bts *bts, const char *fname,
1574 gsm_cbfn *cbfn, void *cb_data)
1575{
1576 struct abis_nm_sw *sw = &g_sw;
1577 int rc;
1578
1579 DEBUGP(DNM, "Activating Software (BTS %u, File \"%s\")\n",
1580 bts->nr, fname);
1581
1582 if (sw->state != SW_STATE_NONE)
1583 return -EBUSY;
1584
1585 sw->bts = bts;
1586 sw->obj_class = NM_OC_SITE_MANAGER;
1587 sw->obj_instance[0] = 0xff;
1588 sw->obj_instance[1] = 0xff;
1589 sw->obj_instance[2] = 0xff;
1590 sw->state = SW_STATE_WAIT_ACTACK;
1591 sw->cbfn = cbfn;
1592 sw->cb_data = cb_data;
1593
1594 /* Open the file in order to fill some sw struct members */
1595 rc = sw_open_file(sw, fname);
1596 if (rc < 0) {
1597 sw->state = SW_STATE_NONE;
1598 return rc;
1599 }
1600 sw_close_file(sw);
1601
1602 return sw_activate(sw);
1603}
1604
Harald Welte8470bf22008-12-25 23:28:35 +00001605static void fill_nm_channel(struct abis_nm_channel *ch, u_int8_t bts_port,
Harald Welte52b1f982008-12-23 20:25:15 +00001606 u_int8_t ts_nr, u_int8_t subslot_nr)
1607{
Harald Welteadaf08b2009-01-18 11:08:10 +00001608 ch->attrib = NM_ATT_ABIS_CHANNEL;
Harald Welte52b1f982008-12-23 20:25:15 +00001609 ch->bts_port = bts_port;
1610 ch->timeslot = ts_nr;
1611 ch->subslot = subslot_nr;
1612}
1613
1614int abis_nm_establish_tei(struct gsm_bts *bts, u_int8_t trx_nr,
1615 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot,
1616 u_int8_t tei)
1617{
1618 struct abis_om_hdr *oh;
1619 struct abis_nm_channel *ch;
Harald Welte702d8702008-12-26 20:25:35 +00001620 u_int8_t len = sizeof(*ch) + 2;
Harald Welte8470bf22008-12-25 23:28:35 +00001621 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001622
1623 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1624 fill_om_fom_hdr(oh, len, NM_MT_ESTABLISH_TEI, NM_OC_RADIO_CARRIER,
1625 bts->bts_nr, trx_nr, 0xff);
1626
Harald Welte8470bf22008-12-25 23:28:35 +00001627 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte52b1f982008-12-23 20:25:15 +00001628
1629 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1630 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1631
1632 return abis_nm_sendmsg(bts, msg);
1633}
1634
1635/* connect signalling of one (BTS,TRX) to a particular timeslot on the E1 */
1636int abis_nm_conn_terr_sign(struct gsm_bts_trx *trx,
1637 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot)
1638{
Harald Welte8470bf22008-12-25 23:28:35 +00001639 struct gsm_bts *bts = trx->bts;
Harald Welte52b1f982008-12-23 20:25:15 +00001640 struct abis_om_hdr *oh;
1641 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +00001642 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001643
1644 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001645 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_SIGN,
Harald Welte52b1f982008-12-23 20:25:15 +00001646 NM_OC_RADIO_CARRIER, bts->bts_nr, trx->nr, 0xff);
1647
1648 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1649 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1650
1651 return abis_nm_sendmsg(bts, msg);
1652}
1653
1654#if 0
1655int abis_nm_disc_terr_sign(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1656 struct abis_nm_abis_channel *chan)
1657{
1658}
1659#endif
1660
1661int abis_nm_conn_terr_traf(struct gsm_bts_trx_ts *ts,
1662 u_int8_t e1_port, u_int8_t e1_timeslot,
1663 u_int8_t e1_subslot)
1664{
1665 struct gsm_bts *bts = ts->trx->bts;
1666 struct abis_om_hdr *oh;
1667 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +00001668 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001669
1670 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1671 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_TRAF,
Harald Welteb110cee2009-02-18 03:42:35 +00001672 NM_OC_CHANNEL, bts->bts_nr, ts->trx->nr, ts->nr);
Harald Welte52b1f982008-12-23 20:25:15 +00001673
1674 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1675 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1676
Harald Weltef325eb42009-02-19 17:07:39 +00001677 DEBUGP(DNM, "CONNECT TERR TRAF Um=%s E1=(%u,%u,%u)\n",
1678 gsm_ts_name(ts),
Harald Welteb110cee2009-02-18 03:42:35 +00001679 e1_port, e1_timeslot, e1_subslot);
1680
Harald Welte52b1f982008-12-23 20:25:15 +00001681 return abis_nm_sendmsg(bts, msg);
1682}
1683
1684#if 0
1685int abis_nm_disc_terr_traf(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1686 struct abis_nm_abis_channel *chan,
1687 u_int8_t subchan)
1688{
1689}
1690#endif
1691
Harald Welte22af0db2009-02-14 15:41:08 +00001692/* Chapter 8.6.1 */
1693int abis_nm_set_bts_attr(struct gsm_bts *bts, u_int8_t *attr, int attr_len)
1694{
1695 struct abis_om_hdr *oh;
1696 struct msgb *msg = nm_msgb_alloc();
1697 u_int8_t *cur;
1698
1699 DEBUGP(DNM, "Set BTS Attr (bts=%d)\n", bts->nr);
1700
1701 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte191280d2009-05-01 13:20:04 +00001702 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 +00001703 cur = msgb_put(msg, attr_len);
1704 memcpy(cur, attr, attr_len);
1705
1706 return abis_nm_sendmsg(bts, msg);
1707}
1708
1709/* Chapter 8.6.2 */
1710int abis_nm_set_radio_attr(struct gsm_bts_trx *trx, u_int8_t *attr, int attr_len)
1711{
1712 struct abis_om_hdr *oh;
1713 struct msgb *msg = nm_msgb_alloc();
1714 u_int8_t *cur;
1715
1716 DEBUGP(DNM, "Set TRX Attr (bts=%d,trx=%d)\n", trx->bts->nr, trx->nr);
1717
1718 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1719 fill_om_fom_hdr(oh, attr_len, NM_MT_SET_RADIO_ATTR, NM_OC_RADIO_CARRIER,
Harald Welte191280d2009-05-01 13:20:04 +00001720 trx->bts->bts_nr, trx->nr, 0xff);
Harald Welte22af0db2009-02-14 15:41:08 +00001721 cur = msgb_put(msg, attr_len);
1722 memcpy(cur, attr, attr_len);
1723
1724 return abis_nm_sendmsg(trx->bts, msg);
1725}
1726
Harald Welte39c7deb2009-08-09 21:49:48 +02001727static int verify_chan_comb(struct gsm_bts_trx_ts *ts, u_int8_t chan_comb)
1728{
1729 int i;
1730
1731 /* As it turns out, the BS-11 has some very peculiar restrictions
1732 * on the channel combinations it allows */
1733 if (ts->trx->bts->type == GSM_BTS_TYPE_BS11) {
1734 switch (chan_comb) {
1735 case NM_CHANC_TCHHalf:
1736 case NM_CHANC_TCHHalf2:
1737 /* not supported */
1738 return -EINVAL;
1739 case NM_CHANC_SDCCH:
1740 /* only one SDCCH/8 per TRX */
1741 for (i = 0; i < TRX_NR_TS; i++) {
1742 if (i == ts->nr)
1743 continue;
1744 if (ts->trx->ts[i].nm_chan_comb ==
1745 NM_CHANC_SDCCH)
1746 return -EINVAL;
1747 }
1748 /* not allowed for TS0 of BCCH-TRX */
1749 if (ts->trx == ts->trx->bts->c0 &&
1750 ts->nr == 0)
1751 return -EINVAL;
1752 /* not on the same TRX that has a BCCH+SDCCH4
1753 * combination */
1754 if (ts->trx == ts->trx->bts->c0 &&
1755 (ts->trx->ts[0].nm_chan_comb == 5 ||
1756 ts->trx->ts[0].nm_chan_comb == 8))
1757 return -EINVAL;
1758 break;
1759 case NM_CHANC_mainBCCH:
1760 case NM_CHANC_BCCHComb:
1761 /* allowed only for TS0 of C0 */
1762 if (ts->trx != ts->trx->bts->c0 ||
1763 ts->nr != 0)
1764 return -EINVAL;
1765 break;
1766 case NM_CHANC_BCCH:
1767 /* allowed only for TS 2/4/6 of C0 */
1768 if (ts->trx != ts->trx->bts->c0)
1769 return -EINVAL;
1770 if (ts->nr != 2 && ts->nr != 4 &&
1771 ts->nr != 6)
1772 return -EINVAL;
1773 break;
1774 case 8: /* this is not like 08.58, but in fact
1775 * FCCH+SCH+BCCH+CCCH+SDCCH/4+SACCH/C4+CBCH */
1776 /* FIXME: only one CBCH allowed per cell */
1777 break;
1778 }
1779 }
1780 return 0;
1781}
1782
Harald Welte22af0db2009-02-14 15:41:08 +00001783/* Chapter 8.6.3 */
Harald Welte52b1f982008-12-23 20:25:15 +00001784int abis_nm_set_channel_attr(struct gsm_bts_trx_ts *ts, u_int8_t chan_comb)
1785{
1786 struct gsm_bts *bts = ts->trx->bts;
1787 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001788 u_int16_t arfcn = htons(ts->trx->arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001789 u_int8_t zero = 0x00;
Harald Welte8470bf22008-12-25 23:28:35 +00001790 struct msgb *msg = nm_msgb_alloc();
Harald Weltee0590df2009-02-15 03:34:15 +00001791 u_int8_t len = 2 + 2;
1792
1793 if (bts->type == GSM_BTS_TYPE_BS11)
1794 len += 4 + 2 + 2 + 3;
Harald Welte52b1f982008-12-23 20:25:15 +00001795
Harald Weltef325eb42009-02-19 17:07:39 +00001796 DEBUGP(DNM, "Set Chan Attr %s\n", gsm_ts_name(ts));
Harald Welte39c7deb2009-08-09 21:49:48 +02001797 if (verify_chan_comb(ts, chan_comb) < 0) {
1798 msgb_free(msg);
1799 DEBUGP(DNM, "Invalid Channel Combination!!!\n");
1800 return -EINVAL;
1801 }
1802 ts->nm_chan_comb = chan_comb;
Harald Welte22af0db2009-02-14 15:41:08 +00001803
Harald Welte52b1f982008-12-23 20:25:15 +00001804 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001805 fill_om_fom_hdr(oh, len, NM_MT_SET_CHAN_ATTR,
Holger Freyther6b2d2622009-02-14 23:16:59 +00001806 NM_OC_CHANNEL, bts->bts_nr,
Harald Welte52b1f982008-12-23 20:25:15 +00001807 ts->trx->nr, ts->nr);
1808 /* FIXME: don't send ARFCN list, hopping sequence, mAIO, ...*/
Harald Weltee0590df2009-02-15 03:34:15 +00001809 if (bts->type == GSM_BTS_TYPE_BS11)
1810 msgb_tlv16_put(msg, NM_ATT_ARFCN_LIST, 1, &arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001811 msgb_tv_put(msg, NM_ATT_CHAN_COMB, chan_comb);
Harald Weltee0590df2009-02-15 03:34:15 +00001812 if (bts->type == GSM_BTS_TYPE_BS11) {
1813 msgb_tv_put(msg, NM_ATT_HSN, 0x00);
1814 msgb_tv_put(msg, NM_ATT_MAIO, 0x00);
1815 }
Harald Weltee6c22d92009-07-21 20:40:05 +02001816 msgb_tv_put(msg, NM_ATT_TSC, bts->tsc); /* training sequence */
Harald Weltee0590df2009-02-15 03:34:15 +00001817 if (bts->type == GSM_BTS_TYPE_BS11)
1818 msgb_tlv_put(msg, 0x59, 1, &zero);
Harald Welte52b1f982008-12-23 20:25:15 +00001819
1820 return abis_nm_sendmsg(bts, msg);
1821}
1822
Harald Welte34a99682009-02-13 02:41:40 +00001823int 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 +00001824 u_int8_t i2, u_int8_t i3, int nack, u_int8_t *attr, int att_len)
Harald Welte34a99682009-02-13 02:41:40 +00001825{
1826 struct abis_om_hdr *oh;
1827 struct msgb *msg = nm_msgb_alloc();
Harald Welte5c1e4582009-02-15 11:57:29 +00001828 u_int8_t msgtype = NM_MT_SW_ACT_REQ_ACK;
1829 u_int8_t len = att_len;
1830
1831 if (nack) {
1832 len += 2;
1833 msgtype = NM_MT_SW_ACT_REQ_NACK;
1834 }
Harald Welte34a99682009-02-13 02:41:40 +00001835
1836 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte5c1e4582009-02-15 11:57:29 +00001837 fill_om_fom_hdr(oh, att_len, msgtype, obj_class, i1, i2, i3);
1838
Harald Welte34a99682009-02-13 02:41:40 +00001839 if (attr) {
1840 u_int8_t *ptr = msgb_put(msg, att_len);
1841 memcpy(ptr, attr, att_len);
1842 }
Harald Welte5c1e4582009-02-15 11:57:29 +00001843 if (nack)
1844 msgb_tv_put(msg, NM_ATT_NACK_CAUSES, NM_NACK_OBJCLASS_NOTSUPP);
Harald Welte34a99682009-02-13 02:41:40 +00001845
1846 return abis_nm_sendmsg(bts, msg);
1847}
1848
Harald Welte8470bf22008-12-25 23:28:35 +00001849int abis_nm_raw_msg(struct gsm_bts *bts, int len, u_int8_t *rawmsg)
Harald Welte52b1f982008-12-23 20:25:15 +00001850{
Harald Welte8470bf22008-12-25 23:28:35 +00001851 struct msgb *msg = nm_msgb_alloc();
1852 struct abis_om_hdr *oh;
Harald Welte52b1f982008-12-23 20:25:15 +00001853 u_int8_t *data;
1854
1855 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
1856 fill_om_hdr(oh, len);
1857 data = msgb_put(msg, len);
Harald Weltead384642008-12-26 10:20:07 +00001858 memcpy(data, rawmsg, len);
Harald Welte52b1f982008-12-23 20:25:15 +00001859
1860 return abis_nm_sendmsg(bts, msg);
1861}
1862
1863/* Siemens specific commands */
1864static int __simple_cmd(struct gsm_bts *bts, u_int8_t msg_type)
1865{
1866 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001867 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001868
1869 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001870 fill_om_fom_hdr(oh, 0, msg_type, NM_OC_SITE_MANAGER,
Harald Welte52b1f982008-12-23 20:25:15 +00001871 0xff, 0xff, 0xff);
1872
1873 return abis_nm_sendmsg(bts, msg);
1874}
1875
Harald Welte34a99682009-02-13 02:41:40 +00001876/* Chapter 8.9.2 */
1877int abis_nm_opstart(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1, u_int8_t i2)
1878{
1879 struct abis_om_hdr *oh;
1880 struct msgb *msg = nm_msgb_alloc();
1881
1882 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1883 fill_om_fom_hdr(oh, 0, NM_MT_OPSTART, obj_class, i0, i1, i2);
1884
Harald Weltea8bd6d42009-10-20 09:56:18 +02001885 debugp_foh((struct abis_om_fom_hdr *) oh->data);
1886 DEBUGPC(DNM, "Sending OPSTART\n");
1887
Harald Welte34a99682009-02-13 02:41:40 +00001888 return abis_nm_sendmsg(bts, msg);
1889}
1890
1891/* Chapter 8.8.5 */
1892int 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 +02001893 u_int8_t i1, u_int8_t i2, enum abis_nm_adm_state adm_state)
Harald Welte34a99682009-02-13 02:41:40 +00001894{
1895 struct abis_om_hdr *oh;
1896 struct msgb *msg = nm_msgb_alloc();
1897
1898 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1899 fill_om_fom_hdr(oh, 2, NM_MT_CHG_ADM_STATE, obj_class, i0, i1, i2);
1900 msgb_tv_put(msg, NM_ATT_ADM_STATE, adm_state);
1901
1902 return abis_nm_sendmsg(bts, msg);
1903}
1904
Harald Welte1989c082009-08-06 17:58:31 +02001905int abis_nm_conn_mdrop_link(struct gsm_bts *bts, u_int8_t e1_port0, u_int8_t ts0,
1906 u_int8_t e1_port1, u_int8_t ts1)
1907{
1908 struct abis_om_hdr *oh;
1909 struct msgb *msg = nm_msgb_alloc();
1910 u_int8_t *attr;
1911
1912 DEBUGP(DNM, "CONNECT MDROP LINK E1=(%u,%u) -> E1=(%u, %u)\n",
1913 e1_port0, ts0, e1_port1, ts1);
1914
1915 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1916 fill_om_fom_hdr(oh, 6, NM_MT_CONN_MDROP_LINK,
1917 NM_OC_SITE_MANAGER, 0x00, 0x00, 0x00);
1918
1919 attr = msgb_put(msg, 3);
1920 attr[0] = NM_ATT_MDROP_LINK;
1921 attr[1] = e1_port0;
1922 attr[2] = ts0;
1923
1924 attr = msgb_put(msg, 3);
1925 attr[0] = NM_ATT_MDROP_NEXT;
1926 attr[1] = e1_port1;
1927 attr[2] = ts1;
1928
1929 return abis_nm_sendmsg(bts, msg);
1930}
Harald Welte34a99682009-02-13 02:41:40 +00001931
Harald Weltec7310382009-08-08 00:02:36 +02001932/* Chapter 8.7.1 */
1933int abis_nm_perform_test(struct gsm_bts *bts, u_int8_t obj_class,
1934 u_int8_t bts_nr, u_int8_t trx_nr, u_int8_t ts_nr,
1935 u_int8_t test_nr, u_int8_t auton_report,
1936 u_int8_t *phys_config, u_int16_t phys_config_len)
1937{
1938 struct abis_om_hdr *oh;
1939 struct msgb *msg = nm_msgb_alloc();
1940 int len = 4; /* 2 TV attributes */
1941
1942 DEBUGP(DNM, "PEFORM TEST\n");
1943
1944 if (phys_config_len)
1945 len += 3 + phys_config_len;
1946
1947 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1948 fill_om_fom_hdr(oh, len, NM_MT_PERF_TEST,
1949 obj_class, bts_nr, trx_nr, ts_nr);
1950 msgb_tv_put(msg, NM_ATT_TEST_NO, test_nr);
1951 msgb_tv_put(msg, NM_ATT_AUTON_REPORT, auton_report);
1952 if (phys_config_len)
1953 msgb_tl16v_put(msg, NM_ATT_PHYS_CONF, phys_config_len,
1954 phys_config);
1955
1956 return abis_nm_sendmsg(bts, msg);
1957}
1958
Harald Welte52b1f982008-12-23 20:25:15 +00001959int abis_nm_event_reports(struct gsm_bts *bts, int on)
1960{
1961 if (on == 0)
Harald Welte227d4072009-01-03 08:16:25 +00001962 return __simple_cmd(bts, NM_MT_STOP_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001963 else
Harald Welte227d4072009-01-03 08:16:25 +00001964 return __simple_cmd(bts, NM_MT_REST_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001965}
1966
Harald Welte47d88ae2009-01-04 12:02:08 +00001967/* Siemens (or BS-11) specific commands */
1968
Harald Welte3ffd1372009-02-01 22:15:49 +00001969int abis_nm_bs11_bsc_disconnect(struct gsm_bts *bts, int reconnect)
1970{
1971 if (reconnect == 0)
1972 return __simple_cmd(bts, NM_MT_BS11_DISCONNECT);
1973 else
1974 return __simple_cmd(bts, NM_MT_BS11_RECONNECT);
1975}
1976
Harald Welteb8427972009-02-05 19:27:17 +00001977int abis_nm_bs11_restart(struct gsm_bts *bts)
1978{
1979 return __simple_cmd(bts, NM_MT_BS11_RESTART);
1980}
1981
1982
Harald Welte268bb402009-02-01 19:11:56 +00001983struct bs11_date_time {
1984 u_int16_t year;
1985 u_int8_t month;
1986 u_int8_t day;
1987 u_int8_t hour;
1988 u_int8_t min;
1989 u_int8_t sec;
1990} __attribute__((packed));
1991
1992
1993void get_bs11_date_time(struct bs11_date_time *aet)
1994{
1995 time_t t;
1996 struct tm *tm;
1997
1998 t = time(NULL);
1999 tm = localtime(&t);
2000 aet->sec = tm->tm_sec;
2001 aet->min = tm->tm_min;
2002 aet->hour = tm->tm_hour;
2003 aet->day = tm->tm_mday;
2004 aet->month = tm->tm_mon;
2005 aet->year = htons(1900 + tm->tm_year);
2006}
2007
Harald Welte05188ee2009-01-18 11:39:08 +00002008int abis_nm_bs11_reset_resource(struct gsm_bts *bts)
Harald Welte52b1f982008-12-23 20:25:15 +00002009{
Harald Welte4668fda2009-01-03 08:19:29 +00002010 return __simple_cmd(bts, NM_MT_BS11_RESET_RESOURCE);
Harald Welte52b1f982008-12-23 20:25:15 +00002011}
2012
Harald Welte05188ee2009-01-18 11:39:08 +00002013int abis_nm_bs11_db_transmission(struct gsm_bts *bts, int begin)
Harald Welte52b1f982008-12-23 20:25:15 +00002014{
2015 if (begin)
Harald Welte4668fda2009-01-03 08:19:29 +00002016 return __simple_cmd(bts, NM_MT_BS11_BEGIN_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00002017 else
Harald Welte4668fda2009-01-03 08:19:29 +00002018 return __simple_cmd(bts, NM_MT_BS11_END_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00002019}
Harald Welte47d88ae2009-01-04 12:02:08 +00002020
Harald Welte05188ee2009-01-18 11:39:08 +00002021int abis_nm_bs11_create_object(struct gsm_bts *bts,
Harald Welte1bc09062009-01-18 14:17:52 +00002022 enum abis_bs11_objtype type, u_int8_t idx,
2023 u_int8_t attr_len, const u_int8_t *attr)
Harald Welte47d88ae2009-01-04 12:02:08 +00002024{
2025 struct abis_om_hdr *oh;
2026 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00002027 u_int8_t *cur;
Harald Welte47d88ae2009-01-04 12:02:08 +00002028
2029 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00002030 fill_om_fom_hdr(oh, attr_len, NM_MT_BS11_CREATE_OBJ,
Harald Welte268bb402009-02-01 19:11:56 +00002031 NM_OC_BS11, type, 0, idx);
Harald Welte1bc09062009-01-18 14:17:52 +00002032 cur = msgb_put(msg, attr_len);
2033 memcpy(cur, attr, attr_len);
Harald Welte47d88ae2009-01-04 12:02:08 +00002034
2035 return abis_nm_sendmsg(bts, msg);
2036}
2037
Harald Welte78fc0d42009-02-19 02:50:57 +00002038int abis_nm_bs11_delete_object(struct gsm_bts *bts,
2039 enum abis_bs11_objtype type, u_int8_t idx)
2040{
2041 struct abis_om_hdr *oh;
2042 struct msgb *msg = nm_msgb_alloc();
2043
2044 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2045 fill_om_fom_hdr(oh, 0, NM_MT_BS11_DELETE_OBJ,
2046 NM_OC_BS11, type, 0, idx);
2047
2048 return abis_nm_sendmsg(bts, msg);
2049}
2050
Harald Welte05188ee2009-01-18 11:39:08 +00002051int abis_nm_bs11_create_envaBTSE(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00002052{
2053 struct abis_om_hdr *oh;
2054 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00002055 u_int8_t zero = 0x00;
Harald Welte47d88ae2009-01-04 12:02:08 +00002056
2057 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00002058 fill_om_fom_hdr(oh, 3, NM_MT_BS11_CREATE_OBJ,
Harald Welte1bc09062009-01-18 14:17:52 +00002059 NM_OC_BS11_ENVABTSE, 0, idx, 0xff);
2060 msgb_tlv_put(msg, 0x99, 1, &zero);
Harald Welte47d88ae2009-01-04 12:02:08 +00002061
2062 return abis_nm_sendmsg(bts, msg);
2063}
2064
Harald Welte05188ee2009-01-18 11:39:08 +00002065int abis_nm_bs11_create_bport(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00002066{
2067 struct abis_om_hdr *oh;
2068 struct msgb *msg = nm_msgb_alloc();
2069
2070 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2071 fill_om_fom_hdr(oh, 0, NM_MT_BS11_CREATE_OBJ, NM_OC_BS11_BPORT,
Daniel Willmann65f68fa2009-08-10 11:49:36 +02002072 idx, 0xff, 0xff);
2073
2074 return abis_nm_sendmsg(bts, msg);
2075}
2076
2077int abis_nm_bs11_delete_bport(struct gsm_bts *bts, u_int8_t idx)
2078{
2079 struct abis_om_hdr *oh;
2080 struct msgb *msg = nm_msgb_alloc();
2081
2082 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2083 fill_om_fom_hdr(oh, 0, NM_MT_BS11_DELETE_OBJ, NM_OC_BS11_BPORT,
2084 idx, 0xff, 0xff);
Harald Welte47d88ae2009-01-04 12:02:08 +00002085
2086 return abis_nm_sendmsg(bts, msg);
2087}
Harald Welte05188ee2009-01-18 11:39:08 +00002088
Harald Welte78fc0d42009-02-19 02:50:57 +00002089static const u_int8_t sm_attr[] = { NM_ATT_TEI, NM_ATT_ABIS_CHANNEL };
2090int abis_nm_bs11_get_oml_tei_ts(struct gsm_bts *bts)
2091{
2092 struct abis_om_hdr *oh;
2093 struct msgb *msg = nm_msgb_alloc();
2094
2095 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2096 fill_om_fom_hdr(oh, 2+sizeof(sm_attr), NM_MT_GET_ATTR, NM_OC_SITE_MANAGER,
2097 0xff, 0xff, 0xff);
2098 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(sm_attr), sm_attr);
2099
2100 return abis_nm_sendmsg(bts, msg);
2101}
2102
Harald Welteb6c92ae2009-02-21 20:15:32 +00002103/* like abis_nm_conn_terr_traf + set_tei */
2104int abis_nm_bs11_conn_oml_tei(struct gsm_bts *bts, u_int8_t e1_port,
2105 u_int8_t e1_timeslot, u_int8_t e1_subslot,
2106 u_int8_t tei)
Harald Welte05188ee2009-01-18 11:39:08 +00002107{
2108 struct abis_om_hdr *oh;
2109 struct abis_nm_channel *ch;
2110 struct msgb *msg = nm_msgb_alloc();
2111
2112 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welteb6c92ae2009-02-21 20:15:32 +00002113 fill_om_fom_hdr(oh, sizeof(*ch)+2, NM_MT_BS11_SET_ATTR,
Harald Welte05188ee2009-01-18 11:39:08 +00002114 NM_OC_SITE_MANAGER, 0xff, 0xff, 0xff);
2115
2116 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
2117 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
Harald Welteb6c92ae2009-02-21 20:15:32 +00002118 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte05188ee2009-01-18 11:39:08 +00002119
2120 return abis_nm_sendmsg(bts, msg);
2121}
2122
2123int abis_nm_bs11_set_trx_power(struct gsm_bts_trx *trx, u_int8_t level)
2124{
2125 struct abis_om_hdr *oh;
2126 struct msgb *msg = nm_msgb_alloc();
Harald Welte05188ee2009-01-18 11:39:08 +00002127
2128 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00002129 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR,
Harald Welte05188ee2009-01-18 11:39:08 +00002130 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
2131 msgb_tlv_put(msg, NM_ATT_BS11_TXPWR, 1, &level);
2132
2133 return abis_nm_sendmsg(trx->bts, msg);
2134}
2135
Harald Welte78fc0d42009-02-19 02:50:57 +00002136int abis_nm_bs11_get_trx_power(struct gsm_bts_trx *trx)
2137{
2138 struct abis_om_hdr *oh;
2139 struct msgb *msg = nm_msgb_alloc();
2140 u_int8_t attr = NM_ATT_BS11_TXPWR;
2141
2142 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2143 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
2144 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
2145 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), &attr);
2146
2147 return abis_nm_sendmsg(trx->bts, msg);
2148}
2149
Harald Welteaaf02d92009-04-29 13:25:57 +00002150int abis_nm_bs11_get_pll_mode(struct gsm_bts *bts)
2151{
2152 struct abis_om_hdr *oh;
2153 struct msgb *msg = nm_msgb_alloc();
Harald Weltea7cfa032009-04-29 22:33:02 +00002154 u_int8_t attr[] = { NM_ATT_BS11_PLL_MODE };
Harald Welteaaf02d92009-04-29 13:25:57 +00002155
2156 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2157 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
2158 NM_OC_BS11, BS11_OBJ_LI, 0x00, 0x00);
Harald Welteaeedeb42009-05-01 13:08:14 +00002159 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), attr);
Harald Welteaaf02d92009-04-29 13:25:57 +00002160
2161 return abis_nm_sendmsg(bts, msg);
2162}
2163
Harald Welteef061952009-05-17 12:43:42 +00002164int abis_nm_bs11_get_cclk(struct gsm_bts *bts)
2165{
2166 struct abis_om_hdr *oh;
2167 struct msgb *msg = nm_msgb_alloc();
2168 u_int8_t attr[] = { NM_ATT_BS11_CCLK_ACCURACY,
2169 NM_ATT_BS11_CCLK_TYPE };
2170
2171 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2172 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
2173 NM_OC_BS11, BS11_OBJ_CCLK, 0x00, 0x00);
2174 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), attr);
2175
2176 return abis_nm_sendmsg(bts, msg);
2177
2178}
Harald Welteaaf02d92009-04-29 13:25:57 +00002179
Harald Welte268bb402009-02-01 19:11:56 +00002180//static const u_int8_t bs11_logon_c7[] = { 0x07, 0xd9, 0x01, 0x11, 0x0d, 0x10, 0x20 };
Harald Weltebb151312009-01-28 20:42:07 +00002181static const u_int8_t bs11_logon_c8[] = { 0x02 };
Harald Welte05188ee2009-01-18 11:39:08 +00002182static const u_int8_t bs11_logon_c9[] = "FACTORY";
2183
Harald Welte1bc09062009-01-18 14:17:52 +00002184int abis_nm_bs11_factory_logon(struct gsm_bts *bts, int on)
Harald Welte05188ee2009-01-18 11:39:08 +00002185{
2186 struct abis_om_hdr *oh;
2187 struct msgb *msg = nm_msgb_alloc();
Harald Welte268bb402009-02-01 19:11:56 +00002188 struct bs11_date_time bdt;
2189
2190 get_bs11_date_time(&bdt);
Harald Welte05188ee2009-01-18 11:39:08 +00002191
2192 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte1bc09062009-01-18 14:17:52 +00002193 if (on) {
Harald Welte268bb402009-02-01 19:11:56 +00002194 u_int8_t len = 3*2 + sizeof(bdt)
Harald Welte6f676a32009-01-18 14:27:48 +00002195 + sizeof(bs11_logon_c8) + sizeof(bs11_logon_c9);
Harald Welte043d04a2009-01-29 23:15:30 +00002196 fill_om_fom_hdr(oh, len, NM_MT_BS11_LMT_LOGON,
Harald Welte7b26bcb2009-05-28 11:39:21 +00002197 NM_OC_BS11_BTSE, 0xff, 0xff, 0xff);
Harald Welte043d04a2009-01-29 23:15:30 +00002198 msgb_tlv_put(msg, NM_ATT_BS11_LMT_LOGIN_TIME,
Harald Welte5083b0b2009-02-02 19:20:52 +00002199 sizeof(bdt), (u_int8_t *) &bdt);
Harald Welte043d04a2009-01-29 23:15:30 +00002200 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_ACC_LEV,
2201 sizeof(bs11_logon_c8), bs11_logon_c8);
2202 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_NAME,
2203 sizeof(bs11_logon_c9), bs11_logon_c9);
Harald Welte1bc09062009-01-18 14:17:52 +00002204 } else {
Harald Welte5e4d1b32009-02-01 13:36:56 +00002205 fill_om_fom_hdr(oh, 0, NM_MT_BS11_LMT_LOGOFF,
Harald Welte7b26bcb2009-05-28 11:39:21 +00002206 NM_OC_BS11_BTSE, 0xff, 0xff, 0xff);
Harald Welte1bc09062009-01-18 14:17:52 +00002207 }
Harald Welte05188ee2009-01-18 11:39:08 +00002208
2209 return abis_nm_sendmsg(bts, msg);
2210}
Harald Welte1bc09062009-01-18 14:17:52 +00002211
2212int abis_nm_bs11_set_trx1_pw(struct gsm_bts *bts, const char *password)
2213{
2214 struct abis_om_hdr *oh;
2215 struct msgb *msg;
2216
2217 if (strlen(password) != 10)
2218 return -EINVAL;
2219
2220 msg = nm_msgb_alloc();
2221 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00002222 fill_om_fom_hdr(oh, 2+strlen(password), NM_MT_BS11_SET_ATTR,
Harald Welte1bc09062009-01-18 14:17:52 +00002223 NM_OC_BS11, BS11_OBJ_TRX1, 0x00, 0x00);
2224 msgb_tlv_put(msg, NM_ATT_BS11_PASSWORD, 10, (const u_int8_t *)password);
2225
2226 return abis_nm_sendmsg(bts, msg);
2227}
2228
Harald Weltee69f5fb2009-04-28 16:31:38 +00002229/* change the BS-11 PLL Mode to either locked (E1 derived) or standalone */
2230int abis_nm_bs11_set_pll_locked(struct gsm_bts *bts, int locked)
2231{
2232 struct abis_om_hdr *oh;
2233 struct msgb *msg;
Harald Weltea432cd32009-04-29 13:01:50 +00002234 u_int8_t tlv_value;
Harald Weltee69f5fb2009-04-28 16:31:38 +00002235
2236 msg = nm_msgb_alloc();
2237 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2238 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR, NM_OC_BS11,
2239 BS11_OBJ_LI, 0x00, 0x00);
Harald Weltea432cd32009-04-29 13:01:50 +00002240
2241 if (locked)
2242 tlv_value = BS11_LI_PLL_LOCKED;
2243 else
2244 tlv_value = BS11_LI_PLL_STANDALONE;
2245
2246 msgb_tlv_put(msg, NM_ATT_BS11_PLL_MODE, 1, &tlv_value);
Harald Weltee69f5fb2009-04-28 16:31:38 +00002247
2248 return abis_nm_sendmsg(bts, msg);
2249}
2250
Harald Welte1bc09062009-01-18 14:17:52 +00002251int abis_nm_bs11_get_state(struct gsm_bts *bts)
2252{
2253 return __simple_cmd(bts, NM_MT_BS11_GET_STATE);
2254}
Harald Welte5e4d1b32009-02-01 13:36:56 +00002255
2256/* BS11 SWL */
2257
Harald Welte (local)d19e58b2009-08-15 02:30:58 +02002258void *tall_fle_ctx;
Harald Welte2cf161b2009-06-20 22:36:41 +02002259
Harald Welte5e4d1b32009-02-01 13:36:56 +00002260struct abis_nm_bs11_sw {
2261 struct gsm_bts *bts;
2262 char swl_fname[PATH_MAX];
2263 u_int8_t win_size;
Harald Welte3ffd1372009-02-01 22:15:49 +00002264 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00002265 struct llist_head file_list;
2266 gsm_cbfn *user_cb; /* specified by the user */
2267};
2268static struct abis_nm_bs11_sw _g_bs11_sw, *g_bs11_sw = &_g_bs11_sw;
2269
2270struct file_list_entry {
2271 struct llist_head list;
2272 char fname[PATH_MAX];
2273};
2274
2275struct file_list_entry *fl_dequeue(struct llist_head *queue)
2276{
2277 struct llist_head *lh;
2278
2279 if (llist_empty(queue))
2280 return NULL;
2281
2282 lh = queue->next;
2283 llist_del(lh);
2284
2285 return llist_entry(lh, struct file_list_entry, list);
2286}
2287
2288static int bs11_read_swl_file(struct abis_nm_bs11_sw *bs11_sw)
2289{
2290 char linebuf[255];
2291 struct llist_head *lh, *lh2;
2292 FILE *swl;
2293 int rc = 0;
2294
2295 swl = fopen(bs11_sw->swl_fname, "r");
2296 if (!swl)
2297 return -ENODEV;
2298
2299 /* zero the stale file list, if any */
2300 llist_for_each_safe(lh, lh2, &bs11_sw->file_list) {
2301 llist_del(lh);
Harald Welte2cf161b2009-06-20 22:36:41 +02002302 talloc_free(lh);
Harald Welte5e4d1b32009-02-01 13:36:56 +00002303 }
2304
2305 while (fgets(linebuf, sizeof(linebuf), swl)) {
2306 char file_id[12+1];
2307 char file_version[80+1];
2308 struct file_list_entry *fle;
2309 static char dir[PATH_MAX];
2310
2311 if (strlen(linebuf) < 4)
2312 continue;
Harald Welte3ffd1372009-02-01 22:15:49 +00002313
Harald Welte5e4d1b32009-02-01 13:36:56 +00002314 rc = sscanf(linebuf+4, "%12s:%80s\r\n", file_id, file_version);
2315 if (rc < 0) {
2316 perror("ERR parsing SWL file");
2317 rc = -EINVAL;
2318 goto out;
2319 }
2320 if (rc < 2)
2321 continue;
2322
Harald Welte470ec292009-06-26 20:25:23 +02002323 fle = talloc_zero(tall_fle_ctx, struct file_list_entry);
Harald Welte5e4d1b32009-02-01 13:36:56 +00002324 if (!fle) {
2325 rc = -ENOMEM;
2326 goto out;
2327 }
Harald Welte5e4d1b32009-02-01 13:36:56 +00002328
2329 /* construct new filename */
2330 strncpy(dir, bs11_sw->swl_fname, sizeof(dir));
2331 strncat(fle->fname, dirname(dir), sizeof(fle->fname) - 1);
2332 strcat(fle->fname, "/");
2333 strncat(fle->fname, file_id, sizeof(fle->fname) - 1 -strlen(fle->fname));
Harald Welte5e4d1b32009-02-01 13:36:56 +00002334
2335 llist_add_tail(&fle->list, &bs11_sw->file_list);
2336 }
2337
2338out:
2339 fclose(swl);
2340 return rc;
2341}
2342
2343/* bs11 swload specific callback, passed to abis_nm core swload */
2344static int bs11_swload_cbfn(unsigned int hook, unsigned int event,
2345 struct msgb *msg, void *data, void *param)
2346{
2347 struct abis_nm_bs11_sw *bs11_sw = data;
2348 struct file_list_entry *fle;
2349 int rc = 0;
2350
Harald Welte5e4d1b32009-02-01 13:36:56 +00002351 switch (event) {
2352 case NM_MT_LOAD_END_ACK:
2353 fle = fl_dequeue(&bs11_sw->file_list);
2354 if (fle) {
2355 /* start download the next file of our file list */
2356 rc = abis_nm_software_load(bs11_sw->bts, fle->fname,
2357 bs11_sw->win_size,
Harald Welte3ffd1372009-02-01 22:15:49 +00002358 bs11_sw->forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00002359 &bs11_swload_cbfn, bs11_sw);
Harald Welteac606dc2009-08-06 15:44:18 +02002360 talloc_free(fle);
Harald Welte5e4d1b32009-02-01 13:36:56 +00002361 } else {
2362 /* activate the SWL */
2363 rc = abis_nm_software_activate(bs11_sw->bts,
2364 bs11_sw->swl_fname,
2365 bs11_swload_cbfn,
2366 bs11_sw);
2367 }
2368 break;
Harald Welte3ffd1372009-02-01 22:15:49 +00002369 case NM_MT_LOAD_SEG_ACK:
Harald Welte5e4d1b32009-02-01 13:36:56 +00002370 case NM_MT_LOAD_END_NACK:
2371 case NM_MT_LOAD_INIT_ACK:
2372 case NM_MT_LOAD_INIT_NACK:
2373 case NM_MT_ACTIVATE_SW_NACK:
2374 case NM_MT_ACTIVATE_SW_ACK:
2375 default:
2376 /* fallthrough to the user callback */
Harald Welte97ed1e72009-02-06 13:38:02 +00002377 if (bs11_sw->user_cb)
2378 rc = bs11_sw->user_cb(hook, event, msg, NULL, NULL);
Harald Welte5e4d1b32009-02-01 13:36:56 +00002379 break;
2380 }
2381
2382 return rc;
2383}
2384
2385/* Siemens provides a SWL file that is a mere listing of all the other
2386 * files that are part of a software release. We need to upload first
2387 * the list file, and then each file that is listed in the list file */
2388int abis_nm_bs11_load_swl(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00002389 u_int8_t win_size, int forced, gsm_cbfn *cbfn)
Harald Welte5e4d1b32009-02-01 13:36:56 +00002390{
2391 struct abis_nm_bs11_sw *bs11_sw = g_bs11_sw;
2392 struct file_list_entry *fle;
2393 int rc = 0;
2394
2395 INIT_LLIST_HEAD(&bs11_sw->file_list);
2396 bs11_sw->bts = bts;
2397 bs11_sw->win_size = win_size;
2398 bs11_sw->user_cb = cbfn;
Harald Welte3ffd1372009-02-01 22:15:49 +00002399 bs11_sw->forced = forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00002400
2401 strncpy(bs11_sw->swl_fname, fname, sizeof(bs11_sw->swl_fname));
2402 rc = bs11_read_swl_file(bs11_sw);
2403 if (rc < 0)
2404 return rc;
2405
2406 /* dequeue next item in file list */
2407 fle = fl_dequeue(&bs11_sw->file_list);
2408 if (!fle)
2409 return -EINVAL;
2410
2411 /* start download the next file of our file list */
Harald Welte3ffd1372009-02-01 22:15:49 +00002412 rc = abis_nm_software_load(bts, fle->fname, win_size, forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00002413 bs11_swload_cbfn, bs11_sw);
Harald Welteac606dc2009-08-06 15:44:18 +02002414 talloc_free(fle);
Harald Welte5e4d1b32009-02-01 13:36:56 +00002415 return rc;
2416}
2417
Harald Welte5083b0b2009-02-02 19:20:52 +00002418#if 0
Harald Welte5e4d1b32009-02-01 13:36:56 +00002419static u_int8_t req_attr_btse[] = {
2420 NM_ATT_ADM_STATE, NM_ATT_BS11_LMT_LOGON_SESSION,
2421 NM_ATT_BS11_LMT_LOGIN_TIME, NM_ATT_BS11_LMT_USER_ACC_LEV,
2422 NM_ATT_BS11_LMT_USER_NAME,
2423
2424 0xaf, NM_ATT_BS11_RX_OFFSET, NM_ATT_BS11_VENDOR_NAME,
2425
2426 NM_ATT_BS11_SW_LOAD_INTENDED, NM_ATT_BS11_SW_LOAD_SAFETY,
2427
2428 NM_ATT_BS11_SW_LOAD_STORED };
2429
2430static u_int8_t req_attr_btsm[] = {
2431 NM_ATT_ABIS_CHANNEL, NM_ATT_TEI, NM_ATT_BS11_ABIS_EXT_TIME,
2432 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xce, NM_ATT_FILE_ID,
2433 NM_ATT_FILE_VERSION, NM_ATT_OPER_STATE, 0xe8, NM_ATT_BS11_ALL_TEST_CATG,
2434 NM_ATT_SW_DESCR, NM_ATT_GET_ARI };
Harald Welte5083b0b2009-02-02 19:20:52 +00002435#endif
Harald Welte5e4d1b32009-02-01 13:36:56 +00002436
2437static u_int8_t req_attr[] = {
2438 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xa8, NM_ATT_OPER_STATE,
2439 0xd5, 0xa1, NM_ATT_BS11_ESN_FW_CODE_NO, NM_ATT_BS11_ESN_HW_CODE_NO,
Harald Weltea7cfa032009-04-29 22:33:02 +00002440 0x42, NM_ATT_BS11_ESN_PCB_SERIAL, NM_ATT_BS11_PLL };
Harald Welte5e4d1b32009-02-01 13:36:56 +00002441
2442int abis_nm_bs11_get_serno(struct gsm_bts *bts)
2443{
2444 struct abis_om_hdr *oh;
2445 struct msgb *msg = nm_msgb_alloc();
2446
2447 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2448 /* SiemensHW CCTRL object */
2449 fill_om_fom_hdr(oh, 2+sizeof(req_attr), NM_MT_GET_ATTR, NM_OC_BS11,
2450 0x03, 0x00, 0x00);
2451 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(req_attr), req_attr);
2452
2453 return abis_nm_sendmsg(bts, msg);
2454}
Harald Welte268bb402009-02-01 19:11:56 +00002455
2456int abis_nm_bs11_set_ext_time(struct gsm_bts *bts)
2457{
2458 struct abis_om_hdr *oh;
2459 struct msgb *msg = nm_msgb_alloc();
2460 struct bs11_date_time aet;
2461
2462 get_bs11_date_time(&aet);
2463 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2464 /* SiemensHW CCTRL object */
2465 fill_om_fom_hdr(oh, 2+sizeof(aet), NM_MT_BS11_SET_ATTR, NM_OC_SITE_MANAGER,
2466 0xff, 0xff, 0xff);
Harald Welte5083b0b2009-02-02 19:20:52 +00002467 msgb_tlv_put(msg, NM_ATT_BS11_ABIS_EXT_TIME, sizeof(aet), (u_int8_t *) &aet);
Harald Welte268bb402009-02-01 19:11:56 +00002468
2469 return abis_nm_sendmsg(bts, msg);
2470}
Harald Welte5c1e4582009-02-15 11:57:29 +00002471
Daniel Willmann65f68fa2009-08-10 11:49:36 +02002472int abis_nm_bs11_set_bport_line_cfg(struct gsm_bts *bts, u_int8_t bport, enum abis_bs11_line_cfg line_cfg)
2473{
2474 struct abis_om_hdr *oh;
2475 struct msgb *msg = nm_msgb_alloc();
2476 struct bs11_date_time aet;
2477
2478 get_bs11_date_time(&aet);
2479 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2480 fill_om_fom_hdr(oh, 2, NM_MT_BS11_SET_ATTR, NM_OC_BS11_BPORT,
2481 bport, 0xff, 0x02);
2482 msgb_tv_put(msg, NM_ATT_BS11_LINE_CFG, line_cfg);
2483
2484 return abis_nm_sendmsg(bts, msg);
2485}
2486
Harald Welte5c1e4582009-02-15 11:57:29 +00002487/* ip.access nanoBTS specific commands */
Harald Welte5c1e4582009-02-15 11:57:29 +00002488static const char ipaccess_magic[] = "com.ipaccess";
2489
Harald Welte677c21f2009-02-17 13:22:23 +00002490
2491static int abis_nm_rx_ipacc(struct msgb *msg)
2492{
2493 struct abis_om_hdr *oh = msgb_l2(msg);
2494 struct abis_om_fom_hdr *foh;
2495 u_int8_t idstrlen = oh->data[0];
2496 struct tlv_parsed tp;
2497
2498 if (strncmp((char *)&oh->data[1], ipaccess_magic, idstrlen)) {
2499 DEBUGP(DNM, "id string is not com.ipaccess !?!\n");
2500 return -EINVAL;
2501 }
2502
Harald Welte193fefc2009-04-30 15:16:27 +00002503 foh = (struct abis_om_fom_hdr *) (oh->data + 1 + idstrlen);
Harald Welte03133942009-02-18 19:51:53 +00002504 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Welte677c21f2009-02-17 13:22:23 +00002505
Harald Weltea8bd6d42009-10-20 09:56:18 +02002506 debugp_foh(foh);
Harald Weltea62202b2009-10-19 21:46:54 +02002507
Harald Welte746d6092009-10-19 22:11:11 +02002508 DEBUGPC(DNM, "IPACCESS(0x%02x): ", foh->msg_type);
Harald Welte193fefc2009-04-30 15:16:27 +00002509
Harald Welte677c21f2009-02-17 13:22:23 +00002510 switch (foh->msg_type) {
2511 case NM_MT_IPACC_RSL_CONNECT_ACK:
Harald Welte193fefc2009-04-30 15:16:27 +00002512 DEBUGPC(DNM, "RSL CONNECT ACK ");
Harald Welte0efe9b72009-07-12 09:33:54 +02002513 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_DST_IP))
Harald Welte9de2bf82009-04-30 15:59:55 +00002514 DEBUGPC(DNM, "IP=%s ",
Harald Welte677c21f2009-02-17 13:22:23 +00002515 inet_ntoa(*((struct in_addr *)
Harald Welte0efe9b72009-07-12 09:33:54 +02002516 TLVP_VAL(&tp, NM_ATT_IPACC_DST_IP))));
2517 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_DST_IP_PORT))
Harald Welte9de2bf82009-04-30 15:59:55 +00002518 DEBUGPC(DNM, "PORT=%u ",
Harald Welte677c21f2009-02-17 13:22:23 +00002519 ntohs(*((u_int16_t *)
Harald Welte0efe9b72009-07-12 09:33:54 +02002520 TLVP_VAL(&tp, NM_ATT_IPACC_DST_IP_PORT))));
Harald Welte35d447b2009-10-19 22:49:33 +02002521 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_STREAM_ID))
2522 DEBUGPC(DNM, "STREAM=0x%02x ",
2523 *TLVP_VAL(&tp, NM_ATT_IPACC_STREAM_ID));
Harald Welte9de2bf82009-04-30 15:59:55 +00002524 DEBUGPC(DNM, "\n");
Harald Welte677c21f2009-02-17 13:22:23 +00002525 break;
2526 case NM_MT_IPACC_RSL_CONNECT_NACK:
Harald Welte193fefc2009-04-30 15:16:27 +00002527 DEBUGPC(DNM, "RSL CONNECT NACK ");
Harald Welte677c21f2009-02-17 13:22:23 +00002528 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
Harald Welte6c96ba52009-05-01 13:03:40 +00002529 DEBUGPC(DNM, " CAUSE=%s\n",
2530 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
Harald Welte677c21f2009-02-17 13:22:23 +00002531 else
2532 DEBUGPC(DNM, "\n");
2533 break;
Harald Welte193fefc2009-04-30 15:16:27 +00002534 case NM_MT_IPACC_SET_NVATTR_ACK:
2535 DEBUGPC(DNM, "SET NVATTR ACK\n");
2536 /* FIXME: decode and show the actual attributes */
2537 break;
2538 case NM_MT_IPACC_SET_NVATTR_NACK:
Harald Welte6c96ba52009-05-01 13:03:40 +00002539 DEBUGPC(DNM, "SET NVATTR NACK ");
2540 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
2541 DEBUGPC(DNM, " CAUSE=%s\n",
2542 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
2543 else
2544 DEBUGPC(DNM, "\n");
Harald Welte193fefc2009-04-30 15:16:27 +00002545 break;
Harald Welte684b1a82009-07-03 11:26:45 +02002546 case NM_MT_IPACC_GET_NVATTR_ACK:
2547 DEBUGPC(DNM, "GET NVATTR ACK\n");
2548 /* FIXME: decode and show the actual attributes */
2549 break;
2550 case NM_MT_IPACC_GET_NVATTR_NACK:
2551 DEBUGPC(DNM, "GET NVATTR NACK ");
2552 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
2553 DEBUGPC(DNM, " CAUSE=%s\n",
2554 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
2555 else
2556 DEBUGPC(DNM, "\n");
2557 break;
Harald Welte15c44172009-10-08 20:15:24 +02002558 case NM_MT_IPACC_SET_ATTR_ACK:
2559 DEBUGPC(DNM, "SET ATTR ACK\n");
2560 break;
2561 case NM_MT_IPACC_SET_ATTR_NACK:
2562 DEBUGPC(DNM, "SET ATTR NACK ");
2563 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
2564 DEBUGPC(DNM, " CAUSE=%s\n",
2565 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
2566 else
2567 DEBUGPC(DNM, "\n");
2568 break;
Harald Welte193fefc2009-04-30 15:16:27 +00002569 default:
2570 DEBUGPC(DNM, "unknown\n");
2571 break;
Harald Welte677c21f2009-02-17 13:22:23 +00002572 }
Holger Hans Peter Freythera7cd9fc2009-07-07 12:40:07 +02002573
2574 /* signal handling */
2575 switch (foh->msg_type) {
2576 case NM_MT_IPACC_RSL_CONNECT_NACK:
2577 case NM_MT_IPACC_SET_NVATTR_NACK:
2578 case NM_MT_IPACC_GET_NVATTR_NACK:
2579 dispatch_signal(SS_NM, S_NM_IPACC_NACK, (void*) ((long)foh->msg_type));
2580 break;
2581 default:
2582 break;
2583 }
2584
Harald Welte677c21f2009-02-17 13:22:23 +00002585 return 0;
2586}
2587
Harald Welte193fefc2009-04-30 15:16:27 +00002588/* send an ip-access manufacturer specific message */
Harald Welte5c1e4582009-02-15 11:57:29 +00002589int abis_nm_ipaccess_msg(struct gsm_bts *bts, u_int8_t msg_type,
2590 u_int8_t obj_class, u_int8_t bts_nr,
2591 u_int8_t trx_nr, u_int8_t ts_nr,
2592 u_int8_t *attr, int attr_len)
2593{
2594 struct msgb *msg = nm_msgb_alloc();
2595 struct abis_om_hdr *oh;
2596 struct abis_om_fom_hdr *foh;
2597 u_int8_t *data;
2598
2599 /* construct the 12.21 OM header, observe the erroneous length */
2600 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
2601 fill_om_hdr(oh, sizeof(*foh) + attr_len);
2602 oh->mdisc = ABIS_OM_MDISC_MANUF;
2603
2604 /* add the ip.access magic */
2605 data = msgb_put(msg, sizeof(ipaccess_magic)+1);
2606 *data++ = sizeof(ipaccess_magic);
2607 memcpy(data, ipaccess_magic, sizeof(ipaccess_magic));
2608
2609 /* fill the 12.21 FOM header */
2610 foh = (struct abis_om_fom_hdr *) msgb_put(msg, sizeof(*foh));
2611 foh->msg_type = msg_type;
2612 foh->obj_class = obj_class;
2613 foh->obj_inst.bts_nr = bts_nr;
2614 foh->obj_inst.trx_nr = trx_nr;
2615 foh->obj_inst.ts_nr = ts_nr;
2616
2617 if (attr && attr_len) {
2618 data = msgb_put(msg, attr_len);
2619 memcpy(data, attr, attr_len);
2620 }
2621
2622 return abis_nm_sendmsg(bts, msg);
2623}
Harald Welte677c21f2009-02-17 13:22:23 +00002624
Harald Welte193fefc2009-04-30 15:16:27 +00002625/* set some attributes in NVRAM */
2626int abis_nm_ipaccess_set_nvattr(struct gsm_bts *bts, u_int8_t *attr,
2627 int attr_len)
2628{
2629 return abis_nm_ipaccess_msg(bts, NM_MT_IPACC_SET_NVATTR,
2630 NM_OC_BASEB_TRANSC, 0, 0, 0xff, attr,
2631 attr_len);
2632}
2633
Harald Welte746d6092009-10-19 22:11:11 +02002634int abis_nm_ipaccess_rsl_connect(struct gsm_bts_trx *trx,
2635 u_int32_t ip, u_int16_t port, u_int8_t stream)
2636{
2637 struct in_addr ia;
2638 u_int8_t attr[] = { NM_ATT_IPACC_STREAM_ID, 0,
2639 NM_ATT_IPACC_DST_IP_PORT, 0, 0,
2640 NM_ATT_IPACC_DST_IP, 0, 0, 0, 0 };
2641
2642 int attr_len = sizeof(attr);
2643
2644 ia.s_addr = htonl(ip);
2645 attr[1] = stream;
2646 attr[3] = port >> 8;
2647 attr[4] = port & 0xff;
2648 *(u_int32_t *)(attr+6) = ia.s_addr;
2649
2650 /* if ip == 0, we use the default IP */
2651 if (ip == 0)
2652 attr_len -= 5;
2653
2654 DEBUGP(DNM, "ip.access RSL CONNECT IP=%s PORT=%u STREAM=0x%02x\n",
Harald Welte31a74902009-10-19 22:50:30 +02002655 inet_ntoa(ia), port, stream);
Harald Welte746d6092009-10-19 22:11:11 +02002656
2657 return abis_nm_ipaccess_msg(trx->bts, NM_MT_IPACC_RSL_CONNECT,
2658 NM_OC_BASEB_TRANSC, trx->bts->bts_nr,
2659 trx->nr, 0xff, attr, attr_len);
2660}
2661
Harald Welte193fefc2009-04-30 15:16:27 +00002662/* restart / reboot an ip.access nanoBTS */
2663int abis_nm_ipaccess_restart(struct gsm_bts *bts)
2664{
2665 return __simple_cmd(bts, NM_MT_IPACC_RESTART);
2666}
Harald Weltedaef5212009-10-24 10:20:41 +02002667
2668int abis_nm_ipaccess_set_attr(struct gsm_bts *bts, u_int8_t obj_class,
2669 u_int8_t bts_nr, u_int8_t trx_nr, u_int8_t ts_nr,
2670 u_int8_t *attr, u_int8_t attr_len)
2671{
2672 return abis_nm_ipaccess_msg(bts, NM_MT_IPACC_SET_ATTR,
2673 obj_class, bts_nr, trx_nr, ts_nr,
2674 attr, attr_len);
2675}