blob: 9db2936f8815564b3a3132096cdb3d47fdc51bbe [file] [log] [blame]
Harald Welte52b1f982008-12-23 20:25:15 +00001/* GSM Network Management (OML) messages on the A-bis interface
2 * 3GPP TS 12.21 version 8.0.0 Release 1999 / ETSI TS 100 623 V8.0.0 */
3
Harald Welte4724f992009-01-18 18:01:49 +00004/* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org>
Harald Welte8470bf22008-12-25 23:28:35 +00005 *
Harald Welte52b1f982008-12-23 20:25:15 +00006 * All Rights Reserved
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 */
23
24
25#include <errno.h>
Harald Welte4724f992009-01-18 18:01:49 +000026#include <unistd.h>
Harald Welte52b1f982008-12-23 20:25:15 +000027#include <stdio.h>
Harald Welte4724f992009-01-18 18:01:49 +000028#include <fcntl.h>
Harald Welte5e4d1b32009-02-01 13:36:56 +000029#include <malloc.h>
30#include <libgen.h>
Harald Welte268bb402009-02-01 19:11:56 +000031#include <time.h>
Harald Welte5f6f1492009-02-02 14:50:29 +000032#include <limits.h>
Harald Welte4724f992009-01-18 18:01:49 +000033
Harald Welte52b1f982008-12-23 20:25:15 +000034#include <sys/types.h>
Harald Welte4724f992009-01-18 18:01:49 +000035#include <sys/stat.h>
Harald Welte8470bf22008-12-25 23:28:35 +000036#include <netinet/in.h>
Harald Welte677c21f2009-02-17 13:22:23 +000037#include <arpa/inet.h>
Harald Welte52b1f982008-12-23 20:25:15 +000038
Harald Welte8470bf22008-12-25 23:28:35 +000039#include <openbsc/gsm_data.h>
40#include <openbsc/debug.h>
41#include <openbsc/msgb.h>
42#include <openbsc/tlv.h>
43#include <openbsc/abis_nm.h>
Holger Freytherca362a62009-01-04 21:05:01 +000044#include <openbsc/misdn.h>
Harald Weltef9a8cc32009-05-01 15:39:49 +000045#include <openbsc/signal.h>
Harald Welte52b1f982008-12-23 20:25:15 +000046
Harald Welte8470bf22008-12-25 23:28:35 +000047#define OM_ALLOC_SIZE 1024
48#define OM_HEADROOM_SIZE 128
Harald Welte52b1f982008-12-23 20:25:15 +000049
50/* unidirectional messages from BTS to BSC */
51static const enum abis_nm_msgtype reports[] = {
52 NM_MT_SW_ACTIVATED_REP,
53 NM_MT_TEST_REP,
54 NM_MT_STATECHG_EVENT_REP,
55 NM_MT_FAILURE_EVENT_REP,
56};
57
58/* messages without ACK/NACK */
59static const enum abis_nm_msgtype no_ack_nack[] = {
60 NM_MT_MEAS_RES_REQ,
61 NM_MT_STOP_MEAS,
62 NM_MT_START_MEAS,
63};
64
Harald Welte4724f992009-01-18 18:01:49 +000065/* Messages related to software load */
66static const enum abis_nm_msgtype sw_load_msgs[] = {
67 NM_MT_LOAD_INIT_ACK,
68 NM_MT_LOAD_INIT_NACK,
69 NM_MT_LOAD_SEG_ACK,
70 NM_MT_LOAD_ABORT,
71 NM_MT_LOAD_END_ACK,
72 NM_MT_LOAD_END_NACK,
Harald Welte34a99682009-02-13 02:41:40 +000073 //NM_MT_SW_ACT_REQ,
Harald Welte4724f992009-01-18 18:01:49 +000074 NM_MT_ACTIVATE_SW_ACK,
75 NM_MT_ACTIVATE_SW_NACK,
76 NM_MT_SW_ACTIVATED_REP,
77};
78
Harald Weltee0590df2009-02-15 03:34:15 +000079static const enum abis_nm_msgtype nacks[] = {
80 NM_MT_LOAD_INIT_NACK,
81 NM_MT_LOAD_END_NACK,
82 NM_MT_SW_ACT_REQ_NACK,
83 NM_MT_ACTIVATE_SW_NACK,
84 NM_MT_ESTABLISH_TEI_NACK,
85 NM_MT_CONN_TERR_SIGN_NACK,
86 NM_MT_DISC_TERR_SIGN_NACK,
87 NM_MT_CONN_TERR_TRAF_NACK,
88 NM_MT_DISC_TERR_TRAF_NACK,
89 NM_MT_CONN_MDROP_LINK_NACK,
90 NM_MT_DISC_MDROP_LINK_NACK,
91 NM_MT_SET_BTS_ATTR_NACK,
92 NM_MT_SET_RADIO_ATTR_NACK,
93 NM_MT_SET_CHAN_ATTR_NACK,
94 NM_MT_PERF_TEST_NACK,
95 NM_MT_SEND_TEST_REP_NACK,
96 NM_MT_STOP_TEST_NACK,
97 NM_MT_STOP_EVENT_REP_NACK,
98 NM_MT_REST_EVENT_REP_NACK,
99 NM_MT_CHG_ADM_STATE_NACK,
100 NM_MT_CHG_ADM_STATE_REQ_NACK,
101 NM_MT_REP_OUTST_ALARMS_NACK,
102 NM_MT_CHANGEOVER_NACK,
103 NM_MT_OPSTART_NACK,
104 NM_MT_REINIT_NACK,
105 NM_MT_SET_SITE_OUT_NACK,
106 NM_MT_CHG_HW_CONF_NACK,
107 NM_MT_GET_ATTR_NACK,
108 NM_MT_SET_ALARM_THRES_NACK,
109 NM_MT_BS11_BEGIN_DB_TX_NACK,
110 NM_MT_BS11_END_DB_TX_NACK,
111 NM_MT_BS11_CREATE_OBJ_NACK,
112 NM_MT_BS11_DELETE_OBJ_NACK,
113};
Harald Welte78fc0d42009-02-19 02:50:57 +0000114
115static const char *nack_names[0xff] = {
116 [NM_MT_LOAD_INIT_NACK] = "SOFTWARE LOAD INIT",
117 [NM_MT_LOAD_END_NACK] = "SOFTWARE LOAD END",
118 [NM_MT_SW_ACT_REQ_NACK] = "SOFTWARE ACTIVATE REQUEST",
119 [NM_MT_ACTIVATE_SW_NACK] = "ACTIVATE SOFTWARE",
120 [NM_MT_ESTABLISH_TEI_NACK] = "ESTABLISH TEI",
121 [NM_MT_CONN_TERR_SIGN_NACK] = "CONNECT TERRESTRIAL SIGNALLING",
122 [NM_MT_DISC_TERR_SIGN_NACK] = "DISCONNECT TERRESTRIAL SIGNALLING",
123 [NM_MT_CONN_TERR_TRAF_NACK] = "CONNECT TERRESTRIAL TRAFFIC",
124 [NM_MT_DISC_TERR_TRAF_NACK] = "DISCONNECT TERRESTRIAL TRAFFIC",
125 [NM_MT_CONN_MDROP_LINK_NACK] = "CONNECT MULTI-DROP LINK",
126 [NM_MT_DISC_MDROP_LINK_NACK] = "DISCONNECT MULTI-DROP LINK",
127 [NM_MT_SET_BTS_ATTR_NACK] = "SET BTS ATTRIBUTE",
128 [NM_MT_SET_RADIO_ATTR_NACK] = "SET RADIO ATTRIBUTE",
129 [NM_MT_SET_CHAN_ATTR_NACK] = "SET CHANNEL ATTRIBUTE",
130 [NM_MT_PERF_TEST_NACK] = "PERFORM TEST",
131 [NM_MT_SEND_TEST_REP_NACK] = "SEND TEST REPORT",
132 [NM_MT_STOP_TEST_NACK] = "STOP TEST",
133 [NM_MT_STOP_EVENT_REP_NACK] = "STOP EVENT REPORT",
134 [NM_MT_REST_EVENT_REP_NACK] = "RESET EVENT REPORT",
135 [NM_MT_CHG_ADM_STATE_NACK] = "CHANGE ADMINISTRATIVE STATE",
136 [NM_MT_CHG_ADM_STATE_REQ_NACK] = "CHANGE ADMINISTRATIVE STATE REQUEST",
137 [NM_MT_REP_OUTST_ALARMS_NACK] = "REPORT OUTSTANDING ALARMS",
138 [NM_MT_CHANGEOVER_NACK] = "CHANGEOVER",
139 [NM_MT_OPSTART_NACK] = "OPSTART",
140 [NM_MT_REINIT_NACK] = "REINIT",
141 [NM_MT_SET_SITE_OUT_NACK] = "SET SITE OUTPUT",
142 [NM_MT_CHG_HW_CONF_NACK] = "CHANGE HARDWARE CONFIGURATION",
143 [NM_MT_GET_ATTR_NACK] = "GET ATTRIBUTE",
144 [NM_MT_SET_ALARM_THRES_NACK] = "SET ALARM THRESHOLD",
145 [NM_MT_BS11_BEGIN_DB_TX_NACK] = "BS11 BEGIN DATABASE TRANSMISSION",
146 [NM_MT_BS11_END_DB_TX_NACK] = "BS11 END DATABASE TRANSMISSION",
147 [NM_MT_BS11_CREATE_OBJ_NACK] = "BS11 CREATE OBJECT",
148 [NM_MT_BS11_DELETE_OBJ_NACK] = "BS11 DELETE OBJECT",
149};
150
Harald Welte6c96ba52009-05-01 13:03:40 +0000151/* Chapter 9.4.36 */
152static const char *nack_cause_names[] = {
153 /* General Nack Causes */
154 [NM_NACK_INCORR_STRUCT] = "Incorrect message structure",
155 [NM_NACK_MSGTYPE_INVAL] = "Invalid message type value",
156 [NM_NACK_OBJCLASS_INVAL] = "Invalid Object class value",
157 [NM_NACK_OBJCLASS_NOTSUPP] = "Object class not supported",
158 [NM_NACK_BTSNR_UNKN] = "BTS no. unknown",
159 [NM_NACK_TRXNR_UNKN] = "Baseband Transceiver no. unknown",
160 [NM_NACK_OBJINST_UNKN] = "Object Instance unknown",
161 [NM_NACK_ATTRID_INVAL] = "Invalid attribute identifier value",
162 [NM_NACK_ATTRID_NOTSUPP] = "Attribute identifier not supported",
163 [NM_NACK_PARAM_RANGE] = "Parameter value outside permitted range",
164 [NM_NACK_ATTRLIST_INCONSISTENT] = "Inconsistency in attribute list",
165 [NM_NACK_SPEC_IMPL_NOTSUPP] = "Specified implementation not supported",
166 [NM_NACK_CANT_PERFORM] = "Message cannot be performed",
167 /* Specific Nack Causes */
168 [NM_NACK_RES_NOTIMPL] = "Resource not implemented",
169 [NM_NACK_RES_NOTAVAIL] = "Resource not available",
170 [NM_NACK_FREQ_NOTAVAIL] = "Frequency not available",
171 [NM_NACK_TEST_NOTSUPP] = "Test not supported",
172 [NM_NACK_CAPACITY_RESTR] = "Capacity restrictions",
173 [NM_NACK_PHYSCFG_NOTPERFORM] = "Physical configuration cannot be performed",
174 [NM_NACK_TEST_NOTINIT] = "Test not initiated",
175 [NM_NACK_PHYSCFG_NOTRESTORE] = "Physical configuration cannot be restored",
176 [NM_NACK_TEST_NOSUCH] = "No such test",
177 [NM_NACK_TEST_NOSTOP] = "Test cannot be stopped",
178 [NM_NACK_MSGINCONSIST_PHYSCFG] = "Message inconsistent with physical configuration",
179 [NM_NACK_FILE_INCOMPLETE] = "Complete file notreceived",
180 [NM_NACK_FILE_NOTAVAIL] = "File not available at destination",
181 [MN_NACK_FILE_NOTACTIVATE] = "File cannot be activate",
182 [NM_NACK_REQ_NOT_GRANT] = "Request not granted",
183 [NM_NACK_WAIT] = "Wait",
184 [NM_NACK_NOTH_REPORT_EXIST] = "Nothing reportable existing",
185 [NM_NACK_MEAS_NOTSUPP] = "Measurement not supported",
186 [NM_NACK_MEAS_NOTSTART] = "Measurement not started",
187};
188
189static char namebuf[255];
190static const char *nack_cause_name(u_int8_t cause)
191{
192 if (cause < ARRAY_SIZE(nack_cause_names) && nack_cause_names[cause])
193 return nack_cause_names[cause];
194
195 snprintf(namebuf, sizeof(namebuf), "0x%02x\n", cause);
196 return namebuf;
197}
198
Harald Welte52b1f982008-12-23 20:25:15 +0000199/* Attributes that the BSC can set, not only get, according to Section 9.4 */
200static const enum abis_nm_attr nm_att_settable[] = {
201 NM_ATT_ADD_INFO,
202 NM_ATT_ADD_TEXT,
203 NM_ATT_DEST,
204 NM_ATT_EVENT_TYPE,
205 NM_ATT_FILE_DATA,
206 NM_ATT_GET_ARI,
207 NM_ATT_HW_CONF_CHG,
208 NM_ATT_LIST_REQ_ATTR,
209 NM_ATT_MDROP_LINK,
210 NM_ATT_MDROP_NEXT,
211 NM_ATT_NACK_CAUSES,
212 NM_ATT_OUTST_ALARM,
213 NM_ATT_PHYS_CONF,
214 NM_ATT_PROB_CAUSE,
215 NM_ATT_RAD_SUBC,
216 NM_ATT_SOURCE,
217 NM_ATT_SPEC_PROB,
218 NM_ATT_START_TIME,
219 NM_ATT_TEST_DUR,
220 NM_ATT_TEST_NO,
221 NM_ATT_TEST_REPORT,
222 NM_ATT_WINDOW_SIZE,
223 NM_ATT_SEVERITY,
224 NM_ATT_MEAS_RES,
225 NM_ATT_MEAS_TYPE,
226};
227
Harald Weltee0590df2009-02-15 03:34:15 +0000228static const struct tlv_definition nm_att_tlvdef = {
229 .def = {
230 [NM_ATT_ABIS_CHANNEL] = { TLV_TYPE_FIXED, 3 },
231 [NM_ATT_ADD_INFO] = { TLV_TYPE_TL16V },
232 [NM_ATT_ADD_TEXT] = { TLV_TYPE_TL16V },
233 [NM_ATT_ADM_STATE] = { TLV_TYPE_TV },
234 [NM_ATT_ARFCN_LIST]= { TLV_TYPE_TL16V },
235 [NM_ATT_AUTON_REPORT] = { TLV_TYPE_TV },
236 [NM_ATT_AVAIL_STATUS] = { TLV_TYPE_TL16V },
237 [NM_ATT_BCCH_ARFCN] = { TLV_TYPE_FIXED, 2 },
238 [NM_ATT_BSIC] = { TLV_TYPE_TV },
239 [NM_ATT_BTS_AIR_TIMER] = { TLV_TYPE_TV },
240 [NM_ATT_CCCH_L_I_P] = { TLV_TYPE_TV },
241 [NM_ATT_CCCH_L_T] = { TLV_TYPE_TV },
242 [NM_ATT_CHAN_COMB] = { TLV_TYPE_TV },
243 [NM_ATT_CONN_FAIL_CRIT] = { TLV_TYPE_TL16V },
244 [NM_ATT_DEST] = { TLV_TYPE_TL16V },
245 [NM_ATT_EVENT_TYPE] = { TLV_TYPE_TV },
246 [NM_ATT_FILE_DATA] = { TLV_TYPE_TL16V },
247 [NM_ATT_FILE_ID] = { TLV_TYPE_TL16V },
248 [NM_ATT_FILE_VERSION] = { TLV_TYPE_TL16V },
249 [NM_ATT_GSM_TIME] = { TLV_TYPE_FIXED, 2 },
250 [NM_ATT_HSN] = { TLV_TYPE_TV },
251 [NM_ATT_HW_CONFIG] = { TLV_TYPE_TL16V },
252 [NM_ATT_HW_DESC] = { TLV_TYPE_TL16V },
253 [NM_ATT_INTAVE_PARAM] = { TLV_TYPE_TV },
254 [NM_ATT_INTERF_BOUND] = { TLV_TYPE_FIXED, 6 },
255 [NM_ATT_LIST_REQ_ATTR] = { TLV_TYPE_TL16V },
256 [NM_ATT_MAIO] = { TLV_TYPE_TV },
257 [NM_ATT_MANUF_STATE] = { TLV_TYPE_TV },
258 [NM_ATT_MANUF_THRESH] = { TLV_TYPE_TL16V },
259 [NM_ATT_MANUF_ID] = { TLV_TYPE_TL16V },
260 [NM_ATT_MAX_TA] = { TLV_TYPE_TV },
261 [NM_ATT_MDROP_LINK] = { TLV_TYPE_FIXED, 2 },
262 [NM_ATT_MDROP_NEXT] = { TLV_TYPE_FIXED, 2 },
263 [NM_ATT_NACK_CAUSES] = { TLV_TYPE_TV },
264 [NM_ATT_NY1] = { TLV_TYPE_TV },
265 [NM_ATT_OPER_STATE] = { TLV_TYPE_TV },
266 [NM_ATT_OVERL_PERIOD] = { TLV_TYPE_TL16V },
267 [NM_ATT_PHYS_CONF] = { TLV_TYPE_TL16V },
268 [NM_ATT_POWER_CLASS] = { TLV_TYPE_TV },
269 [NM_ATT_POWER_THRESH] = { TLV_TYPE_FIXED, 3 },
270 [NM_ATT_PROB_CAUSE] = { TLV_TYPE_FIXED, 3 },
271 [NM_ATT_RACH_B_THRESH] = { TLV_TYPE_TV },
272 [NM_ATT_LDAVG_SLOTS] = { TLV_TYPE_FIXED, 2 },
273 [NM_ATT_RAD_SUBC] = { TLV_TYPE_TV },
274 [NM_ATT_RF_MAXPOWR_R] = { TLV_TYPE_TV },
275 [NM_ATT_SITE_INPUTS] = { TLV_TYPE_TL16V },
276 [NM_ATT_SITE_OUTPUTS] = { TLV_TYPE_TL16V },
277 [NM_ATT_SOURCE] = { TLV_TYPE_TL16V },
278 [NM_ATT_SPEC_PROB] = { TLV_TYPE_TV },
279 [NM_ATT_START_TIME] = { TLV_TYPE_FIXED, 2 },
280 [NM_ATT_T200] = { TLV_TYPE_FIXED, 7 },
281 [NM_ATT_TEI] = { TLV_TYPE_TV },
282 [NM_ATT_TEST_DUR] = { TLV_TYPE_FIXED, 2 },
283 [NM_ATT_TEST_NO] = { TLV_TYPE_TV },
284 [NM_ATT_TEST_REPORT] = { TLV_TYPE_TL16V },
285 [NM_ATT_VSWR_THRESH] = { TLV_TYPE_FIXED, 2 },
286 [NM_ATT_WINDOW_SIZE] = { TLV_TYPE_TV },
287 [NM_ATT_TSC] = { TLV_TYPE_TV },
288 [NM_ATT_SW_CONFIG] = { TLV_TYPE_TL16V },
289 [NM_ATT_SEVERITY] = { TLV_TYPE_TV },
290 [NM_ATT_GET_ARI] = { TLV_TYPE_TL16V },
291 [NM_ATT_HW_CONF_CHG] = { TLV_TYPE_TL16V },
292 [NM_ATT_OUTST_ALARM] = { TLV_TYPE_TV },
293 [NM_ATT_FILE_DATA] = { TLV_TYPE_TL16V },
294 [NM_ATT_MEAS_RES] = { TLV_TYPE_TL16V },
295 /* BS11 specifics */
Harald Welte78fc0d42009-02-19 02:50:57 +0000296 [NM_ATT_BS11_ESN_FW_CODE_NO] = { TLV_TYPE_TLV },
297 [NM_ATT_BS11_ESN_HW_CODE_NO] = { TLV_TYPE_TLV },
298 [NM_ATT_BS11_ESN_PCB_SERIAL] = { TLV_TYPE_TLV },
299 [NM_ATT_BS11_BOOT_SW_VERS] = { TLV_TYPE_TLV },
300 [0xd5] = { TLV_TYPE_TLV },
301 [0xa8] = { TLV_TYPE_TLV },
Harald Weltee0590df2009-02-15 03:34:15 +0000302 [NM_ATT_BS11_PASSWORD] = { TLV_TYPE_TLV },
303 [NM_ATT_BS11_TXPWR] = { TLV_TYPE_TLV },
304 [NM_ATT_BS11_RSSI_OFFS] = { TLV_TYPE_TLV },
305 [NM_ATT_BS11_LINE_CFG] = { TLV_TYPE_TV },
306 [NM_ATT_BS11_L1_PROT_TYPE] = { TLV_TYPE_TV },
307 [NM_ATT_BS11_BIT_ERR_THESH] = { TLV_TYPE_FIXED, 2 },
308 [NM_ATT_BS11_DIVERSITY] = { TLV_TYPE_TLV },
Harald Welteee670472009-02-22 21:58:49 +0000309 [NM_ATT_BS11_LMT_LOGON_SESSION]={ TLV_TYPE_TLV },
Harald Weltee0590df2009-02-15 03:34:15 +0000310 [NM_ATT_BS11_LMT_LOGIN_TIME] = { TLV_TYPE_TLV },
311 [NM_ATT_BS11_LMT_USER_ACC_LEV] ={ TLV_TYPE_TLV },
312 [NM_ATT_BS11_LMT_USER_NAME] = { TLV_TYPE_TLV },
Harald Welte03133942009-02-18 19:51:53 +0000313 [NM_ATT_BS11_BTS_STATE] = { TLV_TYPE_TLV },
314 [NM_ATT_BS11_E1_STATE] = { TLV_TYPE_TLV },
Harald Welteaaf02d92009-04-29 13:25:57 +0000315 [NM_ATT_BS11_PLL_MODE] = { TLV_TYPE_TLV },
Harald Weltea7cfa032009-04-29 22:33:02 +0000316 [NM_ATT_BS11_PLL] = { TLV_TYPE_TLV },
Harald Welte677c21f2009-02-17 13:22:23 +0000317 /* ip.access specifics */
318 [NM_ATT_IPACC_RSL_BSC_IP] = { TLV_TYPE_FIXED, 4 },
319 [NM_ATT_IPACC_RSL_BSC_PORT] = { TLV_TYPE_FIXED, 2 },
Harald Welte3bfbb842009-04-29 22:58:38 +0000320 [NM_ATT_IPACC_PRIM_OML_IP] = { TLV_TYPE_FIXED, 6 },
321 [0x95] = { TLV_TYPE_FIXED, 2 },
Harald Welte677c21f2009-02-17 13:22:23 +0000322 [0x85] = { TLV_TYPE_TV },
323
Harald Weltee0590df2009-02-15 03:34:15 +0000324 },
325};
Harald Welte03133942009-02-18 19:51:53 +0000326
327int abis_nm_tlv_parse(struct tlv_parsed *tp, const u_int8_t *buf, int len)
328{
329 return tlv_parse(tp, &nm_att_tlvdef, buf, len);
330}
Harald Weltee0590df2009-02-15 03:34:15 +0000331
Harald Welte52b1f982008-12-23 20:25:15 +0000332static int is_in_arr(enum abis_nm_msgtype mt, const enum abis_nm_msgtype *arr, int size)
333{
334 int i;
335
336 for (i = 0; i < size; i++) {
337 if (arr[i] == mt)
338 return 1;
339 }
340
341 return 0;
342}
343
Holger Freytherca362a62009-01-04 21:05:01 +0000344#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000345/* is this msgtype the usual ACK/NACK type ? */
346static int is_ack_nack(enum abis_nm_msgtype mt)
347{
348 return !is_in_arr(mt, no_ack_nack, ARRAY_SIZE(no_ack_nack));
349}
Holger Freytherca362a62009-01-04 21:05:01 +0000350#endif
Harald Welte52b1f982008-12-23 20:25:15 +0000351
352/* is this msgtype a report ? */
353static int is_report(enum abis_nm_msgtype mt)
354{
Harald Welte8470bf22008-12-25 23:28:35 +0000355 return is_in_arr(mt, reports, ARRAY_SIZE(reports));
Harald Welte52b1f982008-12-23 20:25:15 +0000356}
357
358#define MT_ACK(x) (x+1)
359#define MT_NACK(x) (x+2)
360
361static void fill_om_hdr(struct abis_om_hdr *oh, u_int8_t len)
362{
363 oh->mdisc = ABIS_OM_MDISC_FOM;
364 oh->placement = ABIS_OM_PLACEMENT_ONLY;
365 oh->sequence = 0;
366 oh->length = len;
367}
368
369static void fill_om_fom_hdr(struct abis_om_hdr *oh, u_int8_t len,
370 u_int8_t msg_type, u_int8_t obj_class,
371 u_int8_t bts_nr, u_int8_t trx_nr, u_int8_t ts_nr)
372{
373 struct abis_om_fom_hdr *foh =
374 (struct abis_om_fom_hdr *) oh->data;
375
Harald Welte702d8702008-12-26 20:25:35 +0000376 fill_om_hdr(oh, len+sizeof(*foh));
Harald Welte52b1f982008-12-23 20:25:15 +0000377 foh->msg_type = msg_type;
378 foh->obj_class = obj_class;
379 foh->obj_inst.bts_nr = bts_nr;
380 foh->obj_inst.trx_nr = trx_nr;
381 foh->obj_inst.ts_nr = ts_nr;
382}
383
Harald Welte8470bf22008-12-25 23:28:35 +0000384static struct msgb *nm_msgb_alloc(void)
385{
386 return msgb_alloc_headroom(OM_ALLOC_SIZE, OM_HEADROOM_SIZE);
387}
388
Harald Welte52b1f982008-12-23 20:25:15 +0000389/* Send a OML NM Message from BSC to BTS */
390int abis_nm_sendmsg(struct gsm_bts *bts, struct msgb *msg)
391{
Holger Freyther59639e82009-02-09 23:09:55 +0000392 msg->trx = bts->c0;
393
Harald Weltead384642008-12-26 10:20:07 +0000394 return _abis_nm_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000395}
396
Harald Welte4724f992009-01-18 18:01:49 +0000397static int abis_nm_rcvmsg_sw(struct msgb *mb);
398
Harald Welte34a99682009-02-13 02:41:40 +0000399const char *oc_names[] = {
400 [NM_OC_SITE_MANAGER] = "SITE MANAGER",
401 [NM_OC_BTS] = "BTS",
402 [NM_OC_RADIO_CARRIER] = "RADIO CARRIER",
403 [NM_OC_BASEB_TRANSC] = "BASEBAND TRANSCEIVER",
404 [NM_OC_CHANNEL] = "CHANNEL",
405};
406
407static const char *obj_class_name(u_int8_t oc)
408{
409 if (oc >= ARRAY_SIZE(oc_names))
410 return "UNKNOWN";
411 return oc_names[oc];
412}
413
Harald Welte4d87f242009-03-10 19:43:44 +0000414const char *nm_opstate_name(u_int8_t os)
Harald Welte34a99682009-02-13 02:41:40 +0000415{
416 switch (os) {
417 case 1:
418 return "Disabled";
419 case 2:
420 return "Enabled";
421 case 0xff:
422 return "NULL";
423 default:
424 return "RFU";
425 }
426}
427
Harald Weltee0590df2009-02-15 03:34:15 +0000428/* Chapter 9.4.7 */
Harald Welte4d87f242009-03-10 19:43:44 +0000429static const char *avail_names[] = {
Harald Weltee0590df2009-02-15 03:34:15 +0000430 "In test",
431 "Failed",
432 "Power off",
433 "Off line",
434 "<not used>",
435 "Dependency",
436 "Degraded",
437 "Not installed",
438};
439
Harald Welte4d87f242009-03-10 19:43:44 +0000440const char *nm_avail_name(u_int8_t avail)
Harald Weltee0590df2009-02-15 03:34:15 +0000441{
Harald Welte0b8348d2009-02-18 03:43:01 +0000442 if (avail == 0xff)
443 return "OK";
Harald Weltee0590df2009-02-15 03:34:15 +0000444 if (avail >= ARRAY_SIZE(avail_names))
445 return "UNKNOWN";
446 return avail_names[avail];
447}
448
449
450/* obtain the gsm_nm_state data structure for a given object instance */
451static struct gsm_nm_state *
452objclass2nmstate(struct gsm_bts *bts, u_int8_t obj_class,
453 struct abis_om_obj_inst *obj_inst)
454{
455 struct gsm_bts_trx *trx;
456 struct gsm_nm_state *nm_state = NULL;
457
458 switch (obj_class) {
459 case NM_OC_BTS:
460 nm_state = &bts->nm_state;
461 break;
462 case NM_OC_RADIO_CARRIER:
463 if (obj_inst->trx_nr >= bts->num_trx)
464 return NULL;
465 trx = &bts->trx[obj_inst->trx_nr];
466 nm_state = &trx->nm_state;
467 break;
468 case NM_OC_BASEB_TRANSC:
469 if (obj_inst->trx_nr >= bts->num_trx)
470 return NULL;
471 trx = &bts->trx[obj_inst->trx_nr];
472 nm_state = &trx->bb_transc.nm_state;
473 break;
474 case NM_OC_CHANNEL:
475 if (obj_inst->trx_nr > bts->num_trx)
476 return NULL;
477 trx = &bts->trx[obj_inst->trx_nr];
478 if (obj_inst->ts_nr >= TRX_NR_TS)
479 return NULL;
480 nm_state = &trx->ts[obj_inst->ts_nr].nm_state;
481 break;
482 case NM_OC_SITE_MANAGER:
483 nm_state = &bts->site_mgr.nm_state;
484 break;
485 }
486 return nm_state;
487}
488
489/* obtain the in-memory data structure of a given object instance */
490static void *
491objclass2obj(struct gsm_bts *bts, u_int8_t obj_class,
492 struct abis_om_obj_inst *obj_inst)
493{
494 struct gsm_bts_trx *trx;
495 void *obj = NULL;
496
497 switch (obj_class) {
498 case NM_OC_BTS:
499 obj = bts;
500 break;
501 case NM_OC_RADIO_CARRIER:
502 if (obj_inst->trx_nr >= bts->num_trx)
503 return NULL;
504 trx = &bts->trx[obj_inst->trx_nr];
505 obj = trx;
506 break;
507 case NM_OC_BASEB_TRANSC:
508 if (obj_inst->trx_nr >= bts->num_trx)
509 return NULL;
510 trx = &bts->trx[obj_inst->trx_nr];
511 obj = &trx->bb_transc;
512 break;
513 case NM_OC_CHANNEL:
514 if (obj_inst->trx_nr > bts->num_trx)
515 return NULL;
516 trx = &bts->trx[obj_inst->trx_nr];
517 if (obj_inst->ts_nr >= TRX_NR_TS)
518 return NULL;
519 obj = &trx->ts[obj_inst->ts_nr];
520 break;
521 case NM_OC_SITE_MANAGER:
522 obj = &bts->site_mgr;
523 break;
524 }
525 return obj;
526}
527
528/* Update the administrative state of a given object in our in-memory data
529 * structures and send an event to the higher layer */
530static int update_admstate(struct gsm_bts *bts, u_int8_t obj_class,
531 struct abis_om_obj_inst *obj_inst, u_int8_t adm_state)
532{
Harald Welteaeedeb42009-05-01 13:08:14 +0000533 struct gsm_nm_state *nm_state, new_state;
Harald Weltee0590df2009-02-15 03:34:15 +0000534 void *obj;
535 int rc;
536
Harald Weltee0590df2009-02-15 03:34:15 +0000537 obj = objclass2obj(bts, obj_class, obj_inst);
Harald Welteaeedeb42009-05-01 13:08:14 +0000538 nm_state = objclass2nmstate(bts, obj_class, obj_inst);
539 if (!nm_state)
540 return -1;
541
542 new_state = *nm_state;
543 new_state.administrative = adm_state;
544
545 rc = nm_state_event(EVT_STATECHG_ADM, obj_class, obj, nm_state, &new_state);
546
547 nm_state->administrative = adm_state;
Harald Weltee0590df2009-02-15 03:34:15 +0000548
549 return rc;
550}
551
Harald Welte97ed1e72009-02-06 13:38:02 +0000552static int abis_nm_rx_statechg_rep(struct msgb *mb)
553{
Harald Weltee0590df2009-02-15 03:34:15 +0000554 struct abis_om_hdr *oh = msgb_l2(mb);
Harald Welte97ed1e72009-02-06 13:38:02 +0000555 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Harald Welte22af0db2009-02-14 15:41:08 +0000556 struct gsm_bts *bts = mb->trx->bts;
Harald Weltee0590df2009-02-15 03:34:15 +0000557 struct tlv_parsed tp;
558 struct gsm_nm_state *nm_state, new_state;
559 int rc;
560
Harald Welte23897662009-05-01 14:52:51 +0000561 DEBUGPC(DNM, "STATE CHG: ");
Harald Weltee0590df2009-02-15 03:34:15 +0000562
563 nm_state = objclass2nmstate(bts, foh->obj_class, &foh->obj_inst);
564 if (!nm_state) {
565 DEBUGPC(DNM, "\n");
566 return -EINVAL;
Harald Welte22af0db2009-02-14 15:41:08 +0000567 }
Harald Weltee0590df2009-02-15 03:34:15 +0000568
569 new_state = *nm_state;
570
Harald Welte03133942009-02-18 19:51:53 +0000571 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Weltee0590df2009-02-15 03:34:15 +0000572 if (TLVP_PRESENT(&tp, NM_ATT_OPER_STATE)) {
573 new_state.operational = *TLVP_VAL(&tp, NM_ATT_OPER_STATE);
Harald Welte4d87f242009-03-10 19:43:44 +0000574 DEBUGPC(DNM, "OP_STATE=%s ", nm_opstate_name(new_state.operational));
Harald Weltee0590df2009-02-15 03:34:15 +0000575 }
576 if (TLVP_PRESENT(&tp, NM_ATT_AVAIL_STATUS)) {
Harald Welte0b8348d2009-02-18 03:43:01 +0000577 if (TLVP_LEN(&tp, NM_ATT_AVAIL_STATUS) == 0)
578 new_state.availability = 0xff;
579 else
580 new_state.availability = *TLVP_VAL(&tp, NM_ATT_AVAIL_STATUS);
Harald Welte4d87f242009-03-10 19:43:44 +0000581 DEBUGPC(DNM, "AVAIL=%s(%02x) ", nm_avail_name(new_state.availability),
Harald Weltee0590df2009-02-15 03:34:15 +0000582 new_state.availability);
583 }
584 if (TLVP_PRESENT(&tp, NM_ATT_ADM_STATE)) {
585 new_state.administrative = *TLVP_VAL(&tp, NM_ATT_ADM_STATE);
586 DEBUGPC(DNM, "ADM=%02x ", new_state.administrative);
Harald Welte97ed1e72009-02-06 13:38:02 +0000587 }
588 DEBUGPC(DNM, "\n");
Harald Weltee0590df2009-02-15 03:34:15 +0000589
590 if (memcmp(&new_state, nm_state, sizeof(new_state))) {
591 /* Update the operational state of a given object in our in-memory data
592 * structures and send an event to the higher layer */
593 void *obj = objclass2obj(bts, foh->obj_class, &foh->obj_inst);
594 rc = nm_state_event(EVT_STATECHG_OPER, foh->obj_class, obj, nm_state, &new_state);
595 *nm_state = new_state;
596 }
597#if 0
Harald Welte22af0db2009-02-14 15:41:08 +0000598 if (op_state == 1) {
599 /* try to enable objects that are disabled */
600 abis_nm_opstart(bts, foh->obj_class,
601 foh->obj_inst.bts_nr,
602 foh->obj_inst.trx_nr,
603 foh->obj_inst.ts_nr);
604 }
Harald Weltee0590df2009-02-15 03:34:15 +0000605#endif
Harald Welte97ed1e72009-02-06 13:38:02 +0000606 return 0;
607}
608
609static int abis_nm_rcvmsg_report(struct msgb *mb)
610{
611 struct abis_om_fom_hdr *foh = msgb_l3(mb);
612 u_int8_t mt = foh->msg_type;
613
Harald Welte23897662009-05-01 14:52:51 +0000614 DEBUGP(DNM, "OC=%s(%02x) INST=(%02x,%02x,%02x) ",
615 obj_class_name(foh->obj_class), foh->obj_class,
616 foh->obj_inst.bts_nr, foh->obj_inst.trx_nr,
617 foh->obj_inst.ts_nr);
618
Harald Welte97ed1e72009-02-06 13:38:02 +0000619 //nmh->cfg->report_cb(mb, foh);
620
621 switch (mt) {
622 case NM_MT_STATECHG_EVENT_REP:
623 return abis_nm_rx_statechg_rep(mb);
624 break;
Harald Welte34a99682009-02-13 02:41:40 +0000625 case NM_MT_SW_ACTIVATED_REP:
Harald Welte23897662009-05-01 14:52:51 +0000626 DEBUGPC(DNM, "Software Activated Report\n");
Harald Weltef9a8cc32009-05-01 15:39:49 +0000627 dispatch_signal(SS_NM, S_NM_SW_ACTIV_REP, mb);
Harald Welte34a99682009-02-13 02:41:40 +0000628 break;
Harald Weltee0590df2009-02-15 03:34:15 +0000629 case NM_MT_FAILURE_EVENT_REP:
Harald Welte23897662009-05-01 14:52:51 +0000630 DEBUGPC(DNM, "Failure Event Report\n");
Harald Weltef9a8cc32009-05-01 15:39:49 +0000631 dispatch_signal(SS_NM, S_NM_FAIL_REP, mb);
Harald Weltee0590df2009-02-15 03:34:15 +0000632 break;
633 default:
Harald Welte23897662009-05-01 14:52:51 +0000634 DEBUGPC(DNM, "reporting NM MT 0x%02x\n", mt);
Harald Weltee0590df2009-02-15 03:34:15 +0000635 break;
636
Harald Welte97ed1e72009-02-06 13:38:02 +0000637 };
638
Harald Welte97ed1e72009-02-06 13:38:02 +0000639 return 0;
640}
641
Harald Welte34a99682009-02-13 02:41:40 +0000642/* Activate the specified software into the BTS */
643static int ipacc_sw_activate(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1,
644 u_int8_t i2, u_int8_t *sw_desc, u_int8_t swdesc_len)
645{
646 struct abis_om_hdr *oh;
647 struct msgb *msg = nm_msgb_alloc();
648 u_int8_t len = swdesc_len;
649 u_int8_t *trailer;
650
651 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
652 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, obj_class, i0, i1, i2);
653
654 trailer = msgb_put(msg, swdesc_len);
655 memcpy(trailer, sw_desc, swdesc_len);
656
657 return abis_nm_sendmsg(bts, msg);
658}
659
660static int abis_nm_rx_sw_act_req(struct msgb *mb)
661{
662 struct abis_om_hdr *oh = msgb_l2(mb);
663 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Harald Welte5c1e4582009-02-15 11:57:29 +0000664 int nack = 0;
Harald Welte34a99682009-02-13 02:41:40 +0000665 int ret;
666
Harald Welte5c1e4582009-02-15 11:57:29 +0000667 DEBUGP(DNM, "Software Activate Request ");
Harald Welte34a99682009-02-13 02:41:40 +0000668
Harald Welte5c1e4582009-02-15 11:57:29 +0000669 if (foh->obj_class >= 0xf0 && foh->obj_class <= 0xf3) {
670 DEBUGPC(DNM, "NACKing for GPRS obj_class 0x%02x\n", foh->obj_class);
671 nack = 1;
672 } else
673 DEBUGPC(DNM, "ACKing and Activating\n");
674
675 ret = abis_nm_sw_act_req_ack(mb->trx->bts, foh->obj_class,
Harald Welte34a99682009-02-13 02:41:40 +0000676 foh->obj_inst.bts_nr,
677 foh->obj_inst.trx_nr,
Harald Welte5c1e4582009-02-15 11:57:29 +0000678 foh->obj_inst.ts_nr, nack,
Harald Welte34a99682009-02-13 02:41:40 +0000679 foh->data, oh->length-sizeof(*foh));
680
Harald Welte5c1e4582009-02-15 11:57:29 +0000681 if (nack)
682 return ret;
683
Harald Welte34a99682009-02-13 02:41:40 +0000684 /* FIXME: properly parse attributes */
685 return ipacc_sw_activate(mb->trx->bts, foh->obj_class,
686 foh->obj_inst.bts_nr,
687 foh->obj_inst.trx_nr,
688 foh->obj_inst.ts_nr,
689 foh->data + oh->length-sizeof(*foh)-22, 22);
690}
691
Harald Weltee0590df2009-02-15 03:34:15 +0000692/* Receive a CHANGE_ADM_STATE_ACK, parse the TLV and update local state */
693static int abis_nm_rx_chg_adm_state_ack(struct msgb *mb)
694{
695 struct abis_om_hdr *oh = msgb_l2(mb);
696 struct abis_om_fom_hdr *foh = msgb_l3(mb);
697 struct tlv_parsed tp;
698 u_int8_t adm_state;
699
Harald Welte03133942009-02-18 19:51:53 +0000700 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Weltee0590df2009-02-15 03:34:15 +0000701 if (!TLVP_PRESENT(&tp, NM_ATT_ADM_STATE))
702 return -EINVAL;
703
704 adm_state = *TLVP_VAL(&tp, NM_ATT_ADM_STATE);
705
706 return update_admstate(mb->trx->bts, foh->obj_class, &foh->obj_inst, adm_state);
707}
708
Harald Welteee670472009-02-22 21:58:49 +0000709static int abis_nm_rx_lmt_event(struct msgb *mb)
710{
711 struct abis_om_hdr *oh = msgb_l2(mb);
712 struct abis_om_fom_hdr *foh = msgb_l3(mb);
713 struct tlv_parsed tp;
714
715 DEBUGP(DNM, "LMT Event ");
716 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
717 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_LOGON_SESSION) &&
718 TLVP_LEN(&tp, NM_ATT_BS11_LMT_LOGON_SESSION) >= 1) {
719 u_int8_t onoff = *TLVP_VAL(&tp, NM_ATT_BS11_LMT_LOGON_SESSION);
720 DEBUGPC(DNM, "LOG%s ", onoff ? "ON" : "OFF");
721 }
722 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV) &&
723 TLVP_LEN(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV) >= 1) {
724 u_int8_t level = *TLVP_VAL(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV);
725 DEBUGPC(DNM, "Level=%u ", level);
726 }
727 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_USER_NAME) &&
728 TLVP_LEN(&tp, NM_ATT_BS11_LMT_USER_NAME) >= 1) {
729 char *name = (char *) TLVP_VAL(&tp, NM_ATT_BS11_LMT_USER_NAME);
730 DEBUGPC(DNM, "Username=%s ", name);
731 }
732 DEBUGPC(DNM, "\n");
733 /* FIXME: parse LMT LOGON TIME */
734 return 0;
735}
736
Harald Welte52b1f982008-12-23 20:25:15 +0000737/* Receive a OML NM Message from BTS */
Harald Welte8470bf22008-12-25 23:28:35 +0000738static int abis_nm_rcvmsg_fom(struct msgb *mb)
Harald Welte52b1f982008-12-23 20:25:15 +0000739{
Harald Welte6c96ba52009-05-01 13:03:40 +0000740 struct abis_om_hdr *oh = msgb_l2(mb);
Harald Welte52b1f982008-12-23 20:25:15 +0000741 struct abis_om_fom_hdr *foh = msgb_l3(mb);
742 u_int8_t mt = foh->msg_type;
743
744 /* check for unsolicited message */
Harald Welte97ed1e72009-02-06 13:38:02 +0000745 if (is_report(mt))
746 return abis_nm_rcvmsg_report(mb);
Harald Welte52b1f982008-12-23 20:25:15 +0000747
Harald Welte4724f992009-01-18 18:01:49 +0000748 if (is_in_arr(mt, sw_load_msgs, ARRAY_SIZE(sw_load_msgs)))
749 return abis_nm_rcvmsg_sw(mb);
750
Harald Welte78fc0d42009-02-19 02:50:57 +0000751 if (is_in_arr(mt, nacks, ARRAY_SIZE(nacks))) {
Harald Welte6c96ba52009-05-01 13:03:40 +0000752 struct tlv_parsed tp;
Harald Welte78fc0d42009-02-19 02:50:57 +0000753 if (nack_names[mt])
Harald Welte6c96ba52009-05-01 13:03:40 +0000754 DEBUGP(DNM, "%s NACK ", nack_names[mt]);
755 /* FIXME: NACK cause */
Harald Welte78fc0d42009-02-19 02:50:57 +0000756 else
Harald Welte6c96ba52009-05-01 13:03:40 +0000757 DEBUGP(DNM, "NACK 0x%02x ", mt);
758
759 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
760 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
761 DEBUGPC(DNM, "CAUSE=%s\n",
762 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
763 else
764 DEBUGPC(DNM, "\n");
Harald Welte78fc0d42009-02-19 02:50:57 +0000765 }
Harald Weltead384642008-12-26 10:20:07 +0000766#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000767 /* check if last message is to be acked */
768 if (is_ack_nack(nmh->last_msgtype)) {
769 if (mt == MT_ACK(nmh->last_msgtype)) {
770 fprintf(stderr, "received ACK (0x%x)\n",
771 foh->msg_type);
772 /* we got our ACK, continue sending the next msg */
773 } else if (mt == MT_NACK(nmh->last_msgtype)) {
774 /* we got a NACK, signal this to the caller */
775 fprintf(stderr, "received NACK (0x%x)\n",
776 foh->msg_type);
777 /* FIXME: somehow signal this to the caller */
778 } else {
779 /* really strange things happen */
780 return -EINVAL;
781 }
782 }
Harald Weltead384642008-12-26 10:20:07 +0000783#endif
784
Harald Welte97ed1e72009-02-06 13:38:02 +0000785 switch (mt) {
Harald Weltee0590df2009-02-15 03:34:15 +0000786 case NM_MT_CHG_ADM_STATE_ACK:
787 return abis_nm_rx_chg_adm_state_ack(mb);
788 break;
Harald Welte34a99682009-02-13 02:41:40 +0000789 case NM_MT_SW_ACT_REQ:
790 return abis_nm_rx_sw_act_req(mb);
791 break;
Harald Welte97ed1e72009-02-06 13:38:02 +0000792 case NM_MT_BS11_LMT_SESSION:
Harald Welteee670472009-02-22 21:58:49 +0000793 return abis_nm_rx_lmt_event(mb);
Harald Welte97ed1e72009-02-06 13:38:02 +0000794 break;
795 }
796
Harald Weltead384642008-12-26 10:20:07 +0000797 return 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000798}
799
Harald Welte677c21f2009-02-17 13:22:23 +0000800static int abis_nm_rx_ipacc(struct msgb *mb);
801
802static int abis_nm_rcvmsg_manuf(struct msgb *mb)
803{
804 int rc;
805 int bts_type = mb->trx->bts->type;
806
807 switch (bts_type) {
808 case GSM_BTS_TYPE_NANOBTS_900:
809 case GSM_BTS_TYPE_NANOBTS_1800:
810 rc = abis_nm_rx_ipacc(mb);
811 break;
812 default:
813 fprintf(stderr, "don't know how to parse OML for this "
814 "BTS type (%u)\n", bts_type);
815 rc = 0;
816 break;
817 }
818
819 return rc;
820}
821
Harald Welte52b1f982008-12-23 20:25:15 +0000822/* High-Level API */
823/* Entry-point where L2 OML from BTS enters the NM code */
Harald Welte8470bf22008-12-25 23:28:35 +0000824int abis_nm_rcvmsg(struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +0000825{
Harald Welte52b1f982008-12-23 20:25:15 +0000826 struct abis_om_hdr *oh = msgb_l2(msg);
Harald Welte677c21f2009-02-17 13:22:23 +0000827 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000828
829 /* Various consistency checks */
830 if (oh->placement != ABIS_OM_PLACEMENT_ONLY) {
831 fprintf(stderr, "ABIS OML placement 0x%x not supported\n",
832 oh->placement);
833 return -EINVAL;
834 }
835 if (oh->sequence != 0) {
836 fprintf(stderr, "ABIS OML sequence 0x%x != 0x00\n",
837 oh->sequence);
838 return -EINVAL;
839 }
Harald Welte702d8702008-12-26 20:25:35 +0000840#if 0
Holger Freytherca362a62009-01-04 21:05:01 +0000841 unsigned int l2_len = msg->tail - (u_int8_t *)msgb_l2(msg);
842 unsigned int hlen = sizeof(*oh) + sizeof(struct abis_om_fom_hdr);
Harald Welte702d8702008-12-26 20:25:35 +0000843 if (oh->length + hlen > l2_len) {
Harald Welte52b1f982008-12-23 20:25:15 +0000844 fprintf(stderr, "ABIS OML truncated message (%u > %u)\n",
845 oh->length + sizeof(*oh), l2_len);
846 return -EINVAL;
847 }
Harald Welte702d8702008-12-26 20:25:35 +0000848 if (oh->length + hlen < l2_len)
849 fprintf(stderr, "ABIS OML message with extra trailer?!? (oh->len=%d, sizeof_oh=%d l2_len=%d\n", oh->length, sizeof(*oh), l2_len);
850#endif
Harald Weltead384642008-12-26 10:20:07 +0000851 msg->l3h = (unsigned char *)oh + sizeof(*oh);
Harald Welte52b1f982008-12-23 20:25:15 +0000852
853 switch (oh->mdisc) {
854 case ABIS_OM_MDISC_FOM:
Harald Welte8470bf22008-12-25 23:28:35 +0000855 rc = abis_nm_rcvmsg_fom(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000856 break;
Harald Welte677c21f2009-02-17 13:22:23 +0000857 case ABIS_OM_MDISC_MANUF:
858 rc = abis_nm_rcvmsg_manuf(msg);
859 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000860 case ABIS_OM_MDISC_MMI:
861 case ABIS_OM_MDISC_TRAU:
Harald Welte677c21f2009-02-17 13:22:23 +0000862 fprintf(stderr, "unimplemented ABIS OML message discriminator 0x%x\n",
863 oh->mdisc);
864 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000865 default:
866 fprintf(stderr, "unknown ABIS OML message discriminator 0x%x\n",
867 oh->mdisc);
868 return -EINVAL;
869 }
870
Harald Weltead384642008-12-26 10:20:07 +0000871 msgb_free(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000872 return rc;
873}
874
875#if 0
876/* initialized all resources */
877struct abis_nm_h *abis_nm_init(struct abis_nm_cfg *cfg)
878{
879 struct abis_nm_h *nmh;
880
881 nmh = malloc(sizeof(*nmh));
882 if (!nmh)
883 return NULL;
884
885 nmh->cfg = cfg;
886
887 return nmh;
888}
889
890/* free all resources */
891void abis_nm_fini(struct abis_nm_h *nmh)
892{
893 free(nmh);
894}
895#endif
896
897/* Here we are trying to define a high-level API that can be used by
898 * the actual BSC implementation. However, the architecture is currently
899 * still under design. Ideally the calls to this API would be synchronous,
900 * while the underlying stack behind the APi runs in a traditional select
901 * based state machine.
902 */
903
Harald Welte4724f992009-01-18 18:01:49 +0000904/* 6.2 Software Load: */
905enum sw_state {
906 SW_STATE_NONE,
907 SW_STATE_WAIT_INITACK,
908 SW_STATE_WAIT_SEGACK,
909 SW_STATE_WAIT_ENDACK,
910 SW_STATE_WAIT_ACTACK,
911 SW_STATE_ERROR,
912};
Harald Welte52b1f982008-12-23 20:25:15 +0000913
Harald Welte52b1f982008-12-23 20:25:15 +0000914struct abis_nm_sw {
Harald Welte4724f992009-01-18 18:01:49 +0000915 struct gsm_bts *bts;
Harald Welte5e4d1b32009-02-01 13:36:56 +0000916 gsm_cbfn *cbfn;
917 void *cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +0000918 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +0000919
Harald Welte52b1f982008-12-23 20:25:15 +0000920 /* this will become part of the SW LOAD INITIATE */
921 u_int8_t obj_class;
922 u_int8_t obj_instance[3];
Harald Welte4724f992009-01-18 18:01:49 +0000923
924 u_int8_t file_id[255];
925 u_int8_t file_id_len;
926
927 u_int8_t file_version[255];
928 u_int8_t file_version_len;
929
930 u_int8_t window_size;
931 u_int8_t seg_in_window;
932
933 int fd;
934 FILE *stream;
935 enum sw_state state;
Harald Welte1602ade2009-01-29 21:12:39 +0000936 int last_seg;
Harald Welte52b1f982008-12-23 20:25:15 +0000937};
938
Harald Welte4724f992009-01-18 18:01:49 +0000939static struct abis_nm_sw g_sw;
940
941/* 6.2.1 / 8.3.1: Load Data Initiate */
942static int sw_load_init(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +0000943{
Harald Welte4724f992009-01-18 18:01:49 +0000944 struct abis_om_hdr *oh;
945 struct msgb *msg = nm_msgb_alloc();
946 u_int8_t len = 3*2 + sw->file_id_len + sw->file_version_len;
947
948 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
949 fill_om_fom_hdr(oh, len, NM_MT_LOAD_INIT, sw->obj_class,
950 sw->obj_instance[0], sw->obj_instance[1],
951 sw->obj_instance[2]);
952
953 /* FIXME: this is BS11 specific format */
954 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
955 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
956 sw->file_version);
957 msgb_tv_put(msg, NM_ATT_WINDOW_SIZE, sw->window_size);
958
959 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000960}
961
Harald Welte1602ade2009-01-29 21:12:39 +0000962static int is_last_line(FILE *stream)
963{
964 char next_seg_buf[256];
965 long pos;
966
967 /* check if we're sending the last line */
968 pos = ftell(stream);
969 if (!fgets(next_seg_buf, sizeof(next_seg_buf)-2, stream)) {
970 fseek(stream, pos, SEEK_SET);
971 return 1;
972 }
973
974 fseek(stream, pos, SEEK_SET);
975 return 0;
976}
977
Harald Welte4724f992009-01-18 18:01:49 +0000978/* 6.2.2 / 8.3.2 Load Data Segment */
979static int sw_load_segment(struct abis_nm_sw *sw)
980{
981 struct abis_om_hdr *oh;
982 struct msgb *msg = nm_msgb_alloc();
983 char seg_buf[256];
984 char *line_buf = seg_buf+2;
Harald Welte3b8ba212009-01-29 12:27:58 +0000985 unsigned char *tlv;
Harald Welte4724f992009-01-18 18:01:49 +0000986 u_int8_t len;
Harald Welte4724f992009-01-18 18:01:49 +0000987
988 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte3b8ba212009-01-29 12:27:58 +0000989
990 switch (sw->bts->type) {
991 case GSM_BTS_TYPE_BS11:
992 if (fgets(line_buf, sizeof(seg_buf)-2, sw->stream) == NULL) {
993 perror("fgets reading segment");
994 return -EINVAL;
995 }
996 seg_buf[0] = 0x00;
Harald Welte1602ade2009-01-29 21:12:39 +0000997
998 /* check if we're sending the last line */
999 sw->last_seg = is_last_line(sw->stream);
1000 if (sw->last_seg)
1001 seg_buf[1] = 0;
1002 else
1003 seg_buf[1] = 1 + sw->seg_in_window++;
Harald Welte3b8ba212009-01-29 12:27:58 +00001004
1005 len = strlen(line_buf) + 2;
1006 tlv = msgb_put(msg, TLV_GROSS_LEN(len));
1007 tlv_put(tlv, NM_ATT_BS11_FILE_DATA, len, (u_int8_t *)seg_buf);
1008 /* BS11 wants CR + LF in excess of the TLV length !?! */
1009 tlv[1] -= 2;
1010
1011 /* we only now know the exact length for the OM hdr */
1012 len = strlen(line_buf)+2;
1013 break;
1014 default:
1015 /* FIXME: Other BTS types */
1016 return -1;
Harald Welte4724f992009-01-18 18:01:49 +00001017 }
Harald Welte4724f992009-01-18 18:01:49 +00001018
Harald Welte4724f992009-01-18 18:01:49 +00001019 fill_om_fom_hdr(oh, len, NM_MT_LOAD_SEG, sw->obj_class,
1020 sw->obj_instance[0], sw->obj_instance[1],
1021 sw->obj_instance[2]);
1022
1023 return abis_nm_sendmsg(sw->bts, msg);
1024}
1025
1026/* 6.2.4 / 8.3.4 Load Data End */
1027static int sw_load_end(struct abis_nm_sw *sw)
1028{
1029 struct abis_om_hdr *oh;
1030 struct msgb *msg = nm_msgb_alloc();
1031 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
1032
1033 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1034 fill_om_fom_hdr(oh, len, NM_MT_LOAD_END, sw->obj_class,
1035 sw->obj_instance[0], sw->obj_instance[1],
1036 sw->obj_instance[2]);
1037
1038 /* FIXME: this is BS11 specific format */
1039 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1040 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1041 sw->file_version);
1042
1043 return abis_nm_sendmsg(sw->bts, msg);
1044}
Harald Welte5e4d1b32009-02-01 13:36:56 +00001045
Harald Welte52b1f982008-12-23 20:25:15 +00001046/* Activate the specified software into the BTS */
Harald Welte4724f992009-01-18 18:01:49 +00001047static int sw_activate(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +00001048{
Harald Welte4724f992009-01-18 18:01:49 +00001049 struct abis_om_hdr *oh;
1050 struct msgb *msg = nm_msgb_alloc();
1051 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
Harald Welte52b1f982008-12-23 20:25:15 +00001052
Harald Welte4724f992009-01-18 18:01:49 +00001053 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1054 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, sw->obj_class,
1055 sw->obj_instance[0], sw->obj_instance[1],
1056 sw->obj_instance[2]);
1057
1058 /* FIXME: this is BS11 specific format */
1059 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1060 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1061 sw->file_version);
1062
1063 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001064}
Harald Welte4724f992009-01-18 18:01:49 +00001065
1066static int sw_open_file(struct abis_nm_sw *sw, const char *fname)
1067{
1068 char file_id[12+1];
1069 char file_version[80+1];
1070 int rc;
1071
1072 sw->fd = open(fname, O_RDONLY);
1073 if (sw->fd < 0)
1074 return sw->fd;
1075
1076 switch (sw->bts->type) {
1077 case GSM_BTS_TYPE_BS11:
1078 sw->stream = fdopen(sw->fd, "r");
1079 if (!sw->stream) {
1080 perror("fdopen");
1081 return -1;
1082 }
1083 /* read first line and parse file ID and VERSION */
Harald Welte3b8ba212009-01-29 12:27:58 +00001084 rc = fscanf(sw->stream, "@(#)%12s:%80s\r\n",
Harald Welte4724f992009-01-18 18:01:49 +00001085 file_id, file_version);
1086 if (rc != 2) {
1087 perror("parsing header line of software file");
1088 return -1;
1089 }
1090 strcpy((char *)sw->file_id, file_id);
1091 sw->file_id_len = strlen(file_id);
1092 strcpy((char *)sw->file_version, file_version);
1093 sw->file_version_len = strlen(file_version);
1094 /* rewind to start of file */
Harald Welte3b8ba212009-01-29 12:27:58 +00001095 rewind(sw->stream);
Harald Welte4724f992009-01-18 18:01:49 +00001096 break;
1097 default:
1098 /* We don't know how to treat them yet */
1099 close(sw->fd);
1100 return -EINVAL;
1101 }
1102
1103 return 0;
1104}
1105
1106static void sw_close_file(struct abis_nm_sw *sw)
1107{
1108 switch (sw->bts->type) {
1109 case GSM_BTS_TYPE_BS11:
1110 fclose(sw->stream);
1111 break;
1112 default:
1113 close(sw->fd);
1114 break;
1115 }
1116}
1117
1118/* Fill the window */
1119static int sw_fill_window(struct abis_nm_sw *sw)
1120{
1121 int rc;
1122
1123 while (sw->seg_in_window < sw->window_size) {
1124 rc = sw_load_segment(sw);
1125 if (rc < 0)
1126 return rc;
Harald Welte1602ade2009-01-29 21:12:39 +00001127 if (sw->last_seg)
1128 break;
Harald Welte4724f992009-01-18 18:01:49 +00001129 }
1130 return 0;
1131}
1132
1133/* callback function from abis_nm_rcvmsg() handler */
1134static int abis_nm_rcvmsg_sw(struct msgb *mb)
1135{
1136 struct abis_om_fom_hdr *foh = msgb_l3(mb);
1137 int rc = -1;
1138 struct abis_nm_sw *sw = &g_sw;
1139 enum sw_state old_state = sw->state;
1140
Harald Welte3ffd1372009-02-01 22:15:49 +00001141 //DEBUGP(DNM, "state %u, NM MT 0x%02x\n", sw->state, foh->msg_type);
Harald Welte4724f992009-01-18 18:01:49 +00001142
1143 switch (sw->state) {
1144 case SW_STATE_WAIT_INITACK:
1145 switch (foh->msg_type) {
1146 case NM_MT_LOAD_INIT_ACK:
1147 /* fill window with segments */
Harald Welte5e4d1b32009-02-01 13:36:56 +00001148 if (sw->cbfn)
1149 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1150 NM_MT_LOAD_INIT_ACK, mb,
1151 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001152 rc = sw_fill_window(sw);
1153 sw->state = SW_STATE_WAIT_SEGACK;
1154 break;
1155 case NM_MT_LOAD_INIT_NACK:
Harald Welte3ffd1372009-02-01 22:15:49 +00001156 if (sw->forced) {
1157 DEBUGP(DNM, "FORCED: Ignoring Software Load "
1158 "Init NACK\n");
1159 if (sw->cbfn)
1160 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1161 NM_MT_LOAD_INIT_ACK, mb,
1162 sw->cb_data, NULL);
1163 rc = sw_fill_window(sw);
1164 sw->state = SW_STATE_WAIT_SEGACK;
1165 } else {
1166 DEBUGP(DNM, "Software Load Init NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001167 /* FIXME: cause */
Harald Welte3ffd1372009-02-01 22:15:49 +00001168 if (sw->cbfn)
1169 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1170 NM_MT_LOAD_INIT_NACK, mb,
1171 sw->cb_data, NULL);
1172 sw->state = SW_STATE_ERROR;
1173 }
Harald Welte4724f992009-01-18 18:01:49 +00001174 break;
1175 }
1176 break;
1177 case SW_STATE_WAIT_SEGACK:
1178 switch (foh->msg_type) {
1179 case NM_MT_LOAD_SEG_ACK:
Harald Welte3ffd1372009-02-01 22:15:49 +00001180 if (sw->cbfn)
1181 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1182 NM_MT_LOAD_SEG_ACK, mb,
1183 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001184 sw->seg_in_window = 0;
Harald Welte1602ade2009-01-29 21:12:39 +00001185 if (!sw->last_seg) {
1186 /* fill window with more segments */
1187 rc = sw_fill_window(sw);
1188 sw->state = SW_STATE_WAIT_SEGACK;
1189 } else {
1190 /* end the transfer */
1191 sw->state = SW_STATE_WAIT_ENDACK;
1192 rc = sw_load_end(sw);
1193 }
Harald Welte4724f992009-01-18 18:01:49 +00001194 break;
1195 }
1196 break;
1197 case SW_STATE_WAIT_ENDACK:
1198 switch (foh->msg_type) {
1199 case NM_MT_LOAD_END_ACK:
1200 sw_close_file(sw);
Harald Welte5e4d1b32009-02-01 13:36:56 +00001201 DEBUGP(DNM, "Software Load End (BTS %u)\n",
1202 sw->bts->nr);
1203 sw->state = SW_STATE_NONE;
1204 if (sw->cbfn)
1205 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1206 NM_MT_LOAD_END_ACK, mb,
1207 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001208 break;
1209 case NM_MT_LOAD_END_NACK:
Holger Freyther31338a12009-02-06 17:43:50 +00001210 if (sw->forced) {
1211 DEBUGP(DNM, "FORCED: Ignoring Software Load"
1212 "End NACK\n");
1213 sw->state = SW_STATE_NONE;
1214 if (sw->cbfn)
1215 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1216 NM_MT_LOAD_END_ACK, mb,
1217 sw->cb_data, NULL);
1218 } else {
1219 DEBUGP(DNM, "Software Load End NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001220 /* FIXME: cause */
Holger Freyther31338a12009-02-06 17:43:50 +00001221 sw->state = SW_STATE_ERROR;
1222 if (sw->cbfn)
1223 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1224 NM_MT_LOAD_END_NACK, mb,
1225 sw->cb_data, NULL);
1226 }
Harald Welte4724f992009-01-18 18:01:49 +00001227 break;
1228 }
1229 case SW_STATE_WAIT_ACTACK:
1230 switch (foh->msg_type) {
1231 case NM_MT_ACTIVATE_SW_ACK:
1232 /* we're done */
Harald Welte5e4d1b32009-02-01 13:36:56 +00001233 DEBUGP(DNM, "Activate Software DONE!\n");
Harald Welte4724f992009-01-18 18:01:49 +00001234 sw->state = SW_STATE_NONE;
1235 rc = 0;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001236 if (sw->cbfn)
1237 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1238 NM_MT_ACTIVATE_SW_ACK, mb,
1239 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001240 break;
1241 case NM_MT_ACTIVATE_SW_NACK:
Harald Welte1602ade2009-01-29 21:12:39 +00001242 DEBUGP(DNM, "Activate Software NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001243 /* FIXME: cause */
Harald Welte4724f992009-01-18 18:01:49 +00001244 sw->state = SW_STATE_ERROR;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001245 if (sw->cbfn)
1246 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1247 NM_MT_ACTIVATE_SW_NACK, mb,
1248 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001249 break;
1250 }
1251 case SW_STATE_NONE:
1252 case SW_STATE_ERROR:
1253 break;
1254 }
1255
1256 if (rc)
1257 fprintf(stderr, "unexpected NM MT 0x%02x in state %u -> %u\n",
1258 foh->msg_type, old_state, sw->state);
1259
1260 return rc;
1261}
1262
1263/* Load the specified software into the BTS */
1264int abis_nm_software_load(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00001265 u_int8_t win_size, int forced,
1266 gsm_cbfn *cbfn, void *cb_data)
Harald Welte4724f992009-01-18 18:01:49 +00001267{
1268 struct abis_nm_sw *sw = &g_sw;
1269 int rc;
1270
Harald Welte5e4d1b32009-02-01 13:36:56 +00001271 DEBUGP(DNM, "Software Load (BTS %u, File \"%s\")\n",
1272 bts->nr, fname);
1273
Harald Welte4724f992009-01-18 18:01:49 +00001274 if (sw->state != SW_STATE_NONE)
1275 return -EBUSY;
1276
1277 sw->bts = bts;
1278 sw->obj_class = NM_OC_SITE_MANAGER;
1279 sw->obj_instance[0] = 0xff;
1280 sw->obj_instance[1] = 0xff;
1281 sw->obj_instance[2] = 0xff;
1282 sw->window_size = win_size;
1283 sw->state = SW_STATE_WAIT_INITACK;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001284 sw->cbfn = cbfn;
1285 sw->cb_data = cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +00001286 sw->forced = forced;
Harald Welte4724f992009-01-18 18:01:49 +00001287
1288 rc = sw_open_file(sw, fname);
1289 if (rc < 0) {
1290 sw->state = SW_STATE_NONE;
1291 return rc;
1292 }
1293
1294 return sw_load_init(sw);
1295}
Harald Welte52b1f982008-12-23 20:25:15 +00001296
Harald Welte1602ade2009-01-29 21:12:39 +00001297int abis_nm_software_load_status(struct gsm_bts *bts)
1298{
1299 struct abis_nm_sw *sw = &g_sw;
1300 struct stat st;
1301 int rc, percent;
1302
1303 rc = fstat(sw->fd, &st);
1304 if (rc < 0) {
1305 perror("ERROR during stat");
1306 return rc;
1307 }
1308
1309 percent = (ftell(sw->stream) * 100) / st.st_size;
1310 return percent;
1311}
1312
Harald Welte5e4d1b32009-02-01 13:36:56 +00001313/* Activate the specified software into the BTS */
1314int abis_nm_software_activate(struct gsm_bts *bts, const char *fname,
1315 gsm_cbfn *cbfn, void *cb_data)
1316{
1317 struct abis_nm_sw *sw = &g_sw;
1318 int rc;
1319
1320 DEBUGP(DNM, "Activating Software (BTS %u, File \"%s\")\n",
1321 bts->nr, fname);
1322
1323 if (sw->state != SW_STATE_NONE)
1324 return -EBUSY;
1325
1326 sw->bts = bts;
1327 sw->obj_class = NM_OC_SITE_MANAGER;
1328 sw->obj_instance[0] = 0xff;
1329 sw->obj_instance[1] = 0xff;
1330 sw->obj_instance[2] = 0xff;
1331 sw->state = SW_STATE_WAIT_ACTACK;
1332 sw->cbfn = cbfn;
1333 sw->cb_data = cb_data;
1334
1335 /* Open the file in order to fill some sw struct members */
1336 rc = sw_open_file(sw, fname);
1337 if (rc < 0) {
1338 sw->state = SW_STATE_NONE;
1339 return rc;
1340 }
1341 sw_close_file(sw);
1342
1343 return sw_activate(sw);
1344}
1345
Harald Welte8470bf22008-12-25 23:28:35 +00001346static void fill_nm_channel(struct abis_nm_channel *ch, u_int8_t bts_port,
Harald Welte52b1f982008-12-23 20:25:15 +00001347 u_int8_t ts_nr, u_int8_t subslot_nr)
1348{
Harald Welteadaf08b2009-01-18 11:08:10 +00001349 ch->attrib = NM_ATT_ABIS_CHANNEL;
Harald Welte52b1f982008-12-23 20:25:15 +00001350 ch->bts_port = bts_port;
1351 ch->timeslot = ts_nr;
1352 ch->subslot = subslot_nr;
1353}
1354
1355int abis_nm_establish_tei(struct gsm_bts *bts, u_int8_t trx_nr,
1356 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot,
1357 u_int8_t tei)
1358{
1359 struct abis_om_hdr *oh;
1360 struct abis_nm_channel *ch;
Harald Welte702d8702008-12-26 20:25:35 +00001361 u_int8_t len = sizeof(*ch) + 2;
Harald Welte8470bf22008-12-25 23:28:35 +00001362 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001363
1364 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1365 fill_om_fom_hdr(oh, len, NM_MT_ESTABLISH_TEI, NM_OC_RADIO_CARRIER,
1366 bts->bts_nr, trx_nr, 0xff);
1367
Harald Welte8470bf22008-12-25 23:28:35 +00001368 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte52b1f982008-12-23 20:25:15 +00001369
1370 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1371 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1372
1373 return abis_nm_sendmsg(bts, msg);
1374}
1375
1376/* connect signalling of one (BTS,TRX) to a particular timeslot on the E1 */
1377int abis_nm_conn_terr_sign(struct gsm_bts_trx *trx,
1378 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot)
1379{
Harald Welte8470bf22008-12-25 23:28:35 +00001380 struct gsm_bts *bts = trx->bts;
Harald Welte52b1f982008-12-23 20:25:15 +00001381 struct abis_om_hdr *oh;
1382 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +00001383 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001384
1385 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001386 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_SIGN,
Harald Welte52b1f982008-12-23 20:25:15 +00001387 NM_OC_RADIO_CARRIER, bts->bts_nr, trx->nr, 0xff);
1388
1389 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1390 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1391
1392 return abis_nm_sendmsg(bts, msg);
1393}
1394
1395#if 0
1396int abis_nm_disc_terr_sign(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1397 struct abis_nm_abis_channel *chan)
1398{
1399}
1400#endif
1401
1402int abis_nm_conn_terr_traf(struct gsm_bts_trx_ts *ts,
1403 u_int8_t e1_port, u_int8_t e1_timeslot,
1404 u_int8_t e1_subslot)
1405{
1406 struct gsm_bts *bts = ts->trx->bts;
1407 struct abis_om_hdr *oh;
1408 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +00001409 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001410
1411 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1412 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_TRAF,
Harald Welteb110cee2009-02-18 03:42:35 +00001413 NM_OC_CHANNEL, bts->bts_nr, ts->trx->nr, ts->nr);
Harald Welte52b1f982008-12-23 20:25:15 +00001414
1415 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1416 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1417
Harald Weltef325eb42009-02-19 17:07:39 +00001418 DEBUGP(DNM, "CONNECT TERR TRAF Um=%s E1=(%u,%u,%u)\n",
1419 gsm_ts_name(ts),
Harald Welteb110cee2009-02-18 03:42:35 +00001420 e1_port, e1_timeslot, e1_subslot);
1421
Harald Welte52b1f982008-12-23 20:25:15 +00001422 return abis_nm_sendmsg(bts, msg);
1423}
1424
1425#if 0
1426int abis_nm_disc_terr_traf(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1427 struct abis_nm_abis_channel *chan,
1428 u_int8_t subchan)
1429{
1430}
1431#endif
1432
Harald Welte22af0db2009-02-14 15:41:08 +00001433/* Chapter 8.6.1 */
1434int abis_nm_set_bts_attr(struct gsm_bts *bts, u_int8_t *attr, int attr_len)
1435{
1436 struct abis_om_hdr *oh;
1437 struct msgb *msg = nm_msgb_alloc();
1438 u_int8_t *cur;
1439
1440 DEBUGP(DNM, "Set BTS Attr (bts=%d)\n", bts->nr);
1441
1442 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte191280d2009-05-01 13:20:04 +00001443 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 +00001444 cur = msgb_put(msg, attr_len);
1445 memcpy(cur, attr, attr_len);
1446
1447 return abis_nm_sendmsg(bts, msg);
1448}
1449
1450/* Chapter 8.6.2 */
1451int abis_nm_set_radio_attr(struct gsm_bts_trx *trx, u_int8_t *attr, int attr_len)
1452{
1453 struct abis_om_hdr *oh;
1454 struct msgb *msg = nm_msgb_alloc();
1455 u_int8_t *cur;
1456
1457 DEBUGP(DNM, "Set TRX Attr (bts=%d,trx=%d)\n", trx->bts->nr, trx->nr);
1458
1459 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1460 fill_om_fom_hdr(oh, attr_len, NM_MT_SET_RADIO_ATTR, NM_OC_RADIO_CARRIER,
Harald Welte191280d2009-05-01 13:20:04 +00001461 trx->bts->bts_nr, trx->nr, 0xff);
Harald Welte22af0db2009-02-14 15:41:08 +00001462 cur = msgb_put(msg, attr_len);
1463 memcpy(cur, attr, attr_len);
1464
1465 return abis_nm_sendmsg(trx->bts, msg);
1466}
1467
1468/* Chapter 8.6.3 */
Harald Welte52b1f982008-12-23 20:25:15 +00001469int abis_nm_set_channel_attr(struct gsm_bts_trx_ts *ts, u_int8_t chan_comb)
1470{
1471 struct gsm_bts *bts = ts->trx->bts;
1472 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001473 u_int16_t arfcn = htons(ts->trx->arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001474 u_int8_t zero = 0x00;
Harald Welte8470bf22008-12-25 23:28:35 +00001475 struct msgb *msg = nm_msgb_alloc();
Harald Weltee0590df2009-02-15 03:34:15 +00001476 u_int8_t len = 2 + 2;
1477
1478 if (bts->type == GSM_BTS_TYPE_BS11)
1479 len += 4 + 2 + 2 + 3;
Harald Welte52b1f982008-12-23 20:25:15 +00001480
Harald Weltef325eb42009-02-19 17:07:39 +00001481 DEBUGP(DNM, "Set Chan Attr %s\n", gsm_ts_name(ts));
Harald Welte22af0db2009-02-14 15:41:08 +00001482
Harald Welte52b1f982008-12-23 20:25:15 +00001483 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001484 fill_om_fom_hdr(oh, len, NM_MT_SET_CHAN_ATTR,
Holger Freyther6b2d2622009-02-14 23:16:59 +00001485 NM_OC_CHANNEL, bts->bts_nr,
Harald Welte52b1f982008-12-23 20:25:15 +00001486 ts->trx->nr, ts->nr);
1487 /* FIXME: don't send ARFCN list, hopping sequence, mAIO, ...*/
Harald Weltee0590df2009-02-15 03:34:15 +00001488 if (bts->type == GSM_BTS_TYPE_BS11)
1489 msgb_tlv16_put(msg, NM_ATT_ARFCN_LIST, 1, &arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001490 msgb_tv_put(msg, NM_ATT_CHAN_COMB, chan_comb);
Harald Weltee0590df2009-02-15 03:34:15 +00001491 if (bts->type == GSM_BTS_TYPE_BS11) {
1492 msgb_tv_put(msg, NM_ATT_HSN, 0x00);
1493 msgb_tv_put(msg, NM_ATT_MAIO, 0x00);
1494 }
Harald Welte52b1f982008-12-23 20:25:15 +00001495 msgb_tv_put(msg, NM_ATT_TSC, 0x07); /* training sequence */
Harald Weltee0590df2009-02-15 03:34:15 +00001496 if (bts->type == GSM_BTS_TYPE_BS11)
1497 msgb_tlv_put(msg, 0x59, 1, &zero);
Harald Welte52b1f982008-12-23 20:25:15 +00001498
1499 return abis_nm_sendmsg(bts, msg);
1500}
1501
Harald Welte34a99682009-02-13 02:41:40 +00001502int 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 +00001503 u_int8_t i2, u_int8_t i3, int nack, u_int8_t *attr, int att_len)
Harald Welte34a99682009-02-13 02:41:40 +00001504{
1505 struct abis_om_hdr *oh;
1506 struct msgb *msg = nm_msgb_alloc();
Harald Welte5c1e4582009-02-15 11:57:29 +00001507 u_int8_t msgtype = NM_MT_SW_ACT_REQ_ACK;
1508 u_int8_t len = att_len;
1509
1510 if (nack) {
1511 len += 2;
1512 msgtype = NM_MT_SW_ACT_REQ_NACK;
1513 }
Harald Welte34a99682009-02-13 02:41:40 +00001514
1515 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte5c1e4582009-02-15 11:57:29 +00001516 fill_om_fom_hdr(oh, att_len, msgtype, obj_class, i1, i2, i3);
1517
Harald Welte34a99682009-02-13 02:41:40 +00001518 if (attr) {
1519 u_int8_t *ptr = msgb_put(msg, att_len);
1520 memcpy(ptr, attr, att_len);
1521 }
Harald Welte5c1e4582009-02-15 11:57:29 +00001522 if (nack)
1523 msgb_tv_put(msg, NM_ATT_NACK_CAUSES, NM_NACK_OBJCLASS_NOTSUPP);
Harald Welte34a99682009-02-13 02:41:40 +00001524
1525 return abis_nm_sendmsg(bts, msg);
1526}
1527
Harald Welte8470bf22008-12-25 23:28:35 +00001528int abis_nm_raw_msg(struct gsm_bts *bts, int len, u_int8_t *rawmsg)
Harald Welte52b1f982008-12-23 20:25:15 +00001529{
Harald Welte8470bf22008-12-25 23:28:35 +00001530 struct msgb *msg = nm_msgb_alloc();
1531 struct abis_om_hdr *oh;
Harald Welte52b1f982008-12-23 20:25:15 +00001532 u_int8_t *data;
1533
1534 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
1535 fill_om_hdr(oh, len);
1536 data = msgb_put(msg, len);
Harald Weltead384642008-12-26 10:20:07 +00001537 memcpy(data, rawmsg, len);
Harald Welte52b1f982008-12-23 20:25:15 +00001538
1539 return abis_nm_sendmsg(bts, msg);
1540}
1541
1542/* Siemens specific commands */
1543static int __simple_cmd(struct gsm_bts *bts, u_int8_t msg_type)
1544{
1545 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001546 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001547
1548 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001549 fill_om_fom_hdr(oh, 0, msg_type, NM_OC_SITE_MANAGER,
Harald Welte52b1f982008-12-23 20:25:15 +00001550 0xff, 0xff, 0xff);
1551
1552 return abis_nm_sendmsg(bts, msg);
1553}
1554
Harald Welte34a99682009-02-13 02:41:40 +00001555/* Chapter 8.9.2 */
1556int abis_nm_opstart(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1, u_int8_t i2)
1557{
1558 struct abis_om_hdr *oh;
1559 struct msgb *msg = nm_msgb_alloc();
1560
Harald Welte22af0db2009-02-14 15:41:08 +00001561 DEBUGP(DNM, "Sending OPSTART obj_class=0x%02x obj_inst=(0x%02x, 0x%02x, 0x%02x)\n",
1562 obj_class, i0, i1, i2);
Harald Welte34a99682009-02-13 02:41:40 +00001563 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1564 fill_om_fom_hdr(oh, 0, NM_MT_OPSTART, obj_class, i0, i1, i2);
1565
1566 return abis_nm_sendmsg(bts, msg);
1567}
1568
1569/* Chapter 8.8.5 */
1570int abis_nm_chg_adm_state(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0,
1571 u_int8_t i1, u_int8_t i2, u_int8_t adm_state)
1572{
1573 struct abis_om_hdr *oh;
1574 struct msgb *msg = nm_msgb_alloc();
1575
1576 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1577 fill_om_fom_hdr(oh, 2, NM_MT_CHG_ADM_STATE, obj_class, i0, i1, i2);
1578 msgb_tv_put(msg, NM_ATT_ADM_STATE, adm_state);
1579
1580 return abis_nm_sendmsg(bts, msg);
1581}
1582
1583
Harald Welte52b1f982008-12-23 20:25:15 +00001584int abis_nm_event_reports(struct gsm_bts *bts, int on)
1585{
1586 if (on == 0)
Harald Welte227d4072009-01-03 08:16:25 +00001587 return __simple_cmd(bts, NM_MT_STOP_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001588 else
Harald Welte227d4072009-01-03 08:16:25 +00001589 return __simple_cmd(bts, NM_MT_REST_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001590}
1591
Harald Welte47d88ae2009-01-04 12:02:08 +00001592/* Siemens (or BS-11) specific commands */
1593
Harald Welte3ffd1372009-02-01 22:15:49 +00001594int abis_nm_bs11_bsc_disconnect(struct gsm_bts *bts, int reconnect)
1595{
1596 if (reconnect == 0)
1597 return __simple_cmd(bts, NM_MT_BS11_DISCONNECT);
1598 else
1599 return __simple_cmd(bts, NM_MT_BS11_RECONNECT);
1600}
1601
Harald Welteb8427972009-02-05 19:27:17 +00001602int abis_nm_bs11_restart(struct gsm_bts *bts)
1603{
1604 return __simple_cmd(bts, NM_MT_BS11_RESTART);
1605}
1606
1607
Harald Welte268bb402009-02-01 19:11:56 +00001608struct bs11_date_time {
1609 u_int16_t year;
1610 u_int8_t month;
1611 u_int8_t day;
1612 u_int8_t hour;
1613 u_int8_t min;
1614 u_int8_t sec;
1615} __attribute__((packed));
1616
1617
1618void get_bs11_date_time(struct bs11_date_time *aet)
1619{
1620 time_t t;
1621 struct tm *tm;
1622
1623 t = time(NULL);
1624 tm = localtime(&t);
1625 aet->sec = tm->tm_sec;
1626 aet->min = tm->tm_min;
1627 aet->hour = tm->tm_hour;
1628 aet->day = tm->tm_mday;
1629 aet->month = tm->tm_mon;
1630 aet->year = htons(1900 + tm->tm_year);
1631}
1632
Harald Welte05188ee2009-01-18 11:39:08 +00001633int abis_nm_bs11_reset_resource(struct gsm_bts *bts)
Harald Welte52b1f982008-12-23 20:25:15 +00001634{
Harald Welte4668fda2009-01-03 08:19:29 +00001635 return __simple_cmd(bts, NM_MT_BS11_RESET_RESOURCE);
Harald Welte52b1f982008-12-23 20:25:15 +00001636}
1637
Harald Welte05188ee2009-01-18 11:39:08 +00001638int abis_nm_bs11_db_transmission(struct gsm_bts *bts, int begin)
Harald Welte52b1f982008-12-23 20:25:15 +00001639{
1640 if (begin)
Harald Welte4668fda2009-01-03 08:19:29 +00001641 return __simple_cmd(bts, NM_MT_BS11_BEGIN_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00001642 else
Harald Welte4668fda2009-01-03 08:19:29 +00001643 return __simple_cmd(bts, NM_MT_BS11_END_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00001644}
Harald Welte47d88ae2009-01-04 12:02:08 +00001645
Harald Welte05188ee2009-01-18 11:39:08 +00001646int abis_nm_bs11_create_object(struct gsm_bts *bts,
Harald Welte1bc09062009-01-18 14:17:52 +00001647 enum abis_bs11_objtype type, u_int8_t idx,
1648 u_int8_t attr_len, const u_int8_t *attr)
Harald Welte47d88ae2009-01-04 12:02:08 +00001649{
1650 struct abis_om_hdr *oh;
1651 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00001652 u_int8_t *cur;
Harald Welte47d88ae2009-01-04 12:02:08 +00001653
1654 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001655 fill_om_fom_hdr(oh, attr_len, NM_MT_BS11_CREATE_OBJ,
Harald Welte268bb402009-02-01 19:11:56 +00001656 NM_OC_BS11, type, 0, idx);
Harald Welte1bc09062009-01-18 14:17:52 +00001657 cur = msgb_put(msg, attr_len);
1658 memcpy(cur, attr, attr_len);
Harald Welte47d88ae2009-01-04 12:02:08 +00001659
1660 return abis_nm_sendmsg(bts, msg);
1661}
1662
Harald Welte78fc0d42009-02-19 02:50:57 +00001663int abis_nm_bs11_delete_object(struct gsm_bts *bts,
1664 enum abis_bs11_objtype type, u_int8_t idx)
1665{
1666 struct abis_om_hdr *oh;
1667 struct msgb *msg = nm_msgb_alloc();
1668
1669 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1670 fill_om_fom_hdr(oh, 0, NM_MT_BS11_DELETE_OBJ,
1671 NM_OC_BS11, type, 0, idx);
1672
1673 return abis_nm_sendmsg(bts, msg);
1674}
1675
Harald Welte05188ee2009-01-18 11:39:08 +00001676int abis_nm_bs11_create_envaBTSE(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00001677{
1678 struct abis_om_hdr *oh;
1679 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00001680 u_int8_t zero = 0x00;
Harald Welte47d88ae2009-01-04 12:02:08 +00001681
1682 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001683 fill_om_fom_hdr(oh, 3, NM_MT_BS11_CREATE_OBJ,
Harald Welte1bc09062009-01-18 14:17:52 +00001684 NM_OC_BS11_ENVABTSE, 0, idx, 0xff);
1685 msgb_tlv_put(msg, 0x99, 1, &zero);
Harald Welte47d88ae2009-01-04 12:02:08 +00001686
1687 return abis_nm_sendmsg(bts, msg);
1688}
1689
Harald Welte05188ee2009-01-18 11:39:08 +00001690int abis_nm_bs11_create_bport(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00001691{
1692 struct abis_om_hdr *oh;
1693 struct msgb *msg = nm_msgb_alloc();
1694
1695 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1696 fill_om_fom_hdr(oh, 0, NM_MT_BS11_CREATE_OBJ, NM_OC_BS11_BPORT,
1697 idx, 0, 0);
1698
1699 return abis_nm_sendmsg(bts, msg);
1700}
Harald Welte05188ee2009-01-18 11:39:08 +00001701
Harald Welte78fc0d42009-02-19 02:50:57 +00001702static const u_int8_t sm_attr[] = { NM_ATT_TEI, NM_ATT_ABIS_CHANNEL };
1703int abis_nm_bs11_get_oml_tei_ts(struct gsm_bts *bts)
1704{
1705 struct abis_om_hdr *oh;
1706 struct msgb *msg = nm_msgb_alloc();
1707
1708 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1709 fill_om_fom_hdr(oh, 2+sizeof(sm_attr), NM_MT_GET_ATTR, NM_OC_SITE_MANAGER,
1710 0xff, 0xff, 0xff);
1711 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(sm_attr), sm_attr);
1712
1713 return abis_nm_sendmsg(bts, msg);
1714}
1715
Harald Welteb6c92ae2009-02-21 20:15:32 +00001716/* like abis_nm_conn_terr_traf + set_tei */
1717int abis_nm_bs11_conn_oml_tei(struct gsm_bts *bts, u_int8_t e1_port,
1718 u_int8_t e1_timeslot, u_int8_t e1_subslot,
1719 u_int8_t tei)
Harald Welte05188ee2009-01-18 11:39:08 +00001720{
1721 struct abis_om_hdr *oh;
1722 struct abis_nm_channel *ch;
1723 struct msgb *msg = nm_msgb_alloc();
1724
1725 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welteb6c92ae2009-02-21 20:15:32 +00001726 fill_om_fom_hdr(oh, sizeof(*ch)+2, NM_MT_BS11_SET_ATTR,
Harald Welte05188ee2009-01-18 11:39:08 +00001727 NM_OC_SITE_MANAGER, 0xff, 0xff, 0xff);
1728
1729 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1730 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
Harald Welteb6c92ae2009-02-21 20:15:32 +00001731 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte05188ee2009-01-18 11:39:08 +00001732
1733 return abis_nm_sendmsg(bts, msg);
1734}
1735
1736int abis_nm_bs11_set_trx_power(struct gsm_bts_trx *trx, u_int8_t level)
1737{
1738 struct abis_om_hdr *oh;
1739 struct msgb *msg = nm_msgb_alloc();
Harald Welte05188ee2009-01-18 11:39:08 +00001740
1741 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001742 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR,
Harald Welte05188ee2009-01-18 11:39:08 +00001743 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
1744 msgb_tlv_put(msg, NM_ATT_BS11_TXPWR, 1, &level);
1745
1746 return abis_nm_sendmsg(trx->bts, msg);
1747}
1748
Harald Welte78fc0d42009-02-19 02:50:57 +00001749int abis_nm_bs11_get_trx_power(struct gsm_bts_trx *trx)
1750{
1751 struct abis_om_hdr *oh;
1752 struct msgb *msg = nm_msgb_alloc();
1753 u_int8_t attr = NM_ATT_BS11_TXPWR;
1754
1755 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1756 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
1757 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
1758 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), &attr);
1759
1760 return abis_nm_sendmsg(trx->bts, msg);
1761}
1762
Harald Welteaaf02d92009-04-29 13:25:57 +00001763int abis_nm_bs11_get_pll_mode(struct gsm_bts *bts)
1764{
1765 struct abis_om_hdr *oh;
1766 struct msgb *msg = nm_msgb_alloc();
Harald Weltea7cfa032009-04-29 22:33:02 +00001767 u_int8_t attr[] = { NM_ATT_BS11_PLL_MODE };
Harald Welteaaf02d92009-04-29 13:25:57 +00001768
1769 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1770 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
1771 NM_OC_BS11, BS11_OBJ_LI, 0x00, 0x00);
Harald Welteaeedeb42009-05-01 13:08:14 +00001772 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), attr);
Harald Welteaaf02d92009-04-29 13:25:57 +00001773
1774 return abis_nm_sendmsg(bts, msg);
1775}
1776
1777
Harald Welte268bb402009-02-01 19:11:56 +00001778//static const u_int8_t bs11_logon_c7[] = { 0x07, 0xd9, 0x01, 0x11, 0x0d, 0x10, 0x20 };
Harald Weltebb151312009-01-28 20:42:07 +00001779static const u_int8_t bs11_logon_c8[] = { 0x02 };
Harald Welte05188ee2009-01-18 11:39:08 +00001780static const u_int8_t bs11_logon_c9[] = "FACTORY";
1781
Harald Welte1bc09062009-01-18 14:17:52 +00001782int abis_nm_bs11_factory_logon(struct gsm_bts *bts, int on)
Harald Welte05188ee2009-01-18 11:39:08 +00001783{
1784 struct abis_om_hdr *oh;
1785 struct msgb *msg = nm_msgb_alloc();
Harald Welte268bb402009-02-01 19:11:56 +00001786 struct bs11_date_time bdt;
1787
1788 get_bs11_date_time(&bdt);
Harald Welte05188ee2009-01-18 11:39:08 +00001789
1790 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte1bc09062009-01-18 14:17:52 +00001791 if (on) {
Harald Welte268bb402009-02-01 19:11:56 +00001792 u_int8_t len = 3*2 + sizeof(bdt)
Harald Welte6f676a32009-01-18 14:27:48 +00001793 + sizeof(bs11_logon_c8) + sizeof(bs11_logon_c9);
Harald Welte043d04a2009-01-29 23:15:30 +00001794 fill_om_fom_hdr(oh, len, NM_MT_BS11_LMT_LOGON,
Harald Welte1bc09062009-01-18 14:17:52 +00001795 NM_OC_BS11_A3, 0xff, 0xff, 0xff);
Harald Welte043d04a2009-01-29 23:15:30 +00001796 msgb_tlv_put(msg, NM_ATT_BS11_LMT_LOGIN_TIME,
Harald Welte5083b0b2009-02-02 19:20:52 +00001797 sizeof(bdt), (u_int8_t *) &bdt);
Harald Welte043d04a2009-01-29 23:15:30 +00001798 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_ACC_LEV,
1799 sizeof(bs11_logon_c8), bs11_logon_c8);
1800 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_NAME,
1801 sizeof(bs11_logon_c9), bs11_logon_c9);
Harald Welte1bc09062009-01-18 14:17:52 +00001802 } else {
Harald Welte5e4d1b32009-02-01 13:36:56 +00001803 fill_om_fom_hdr(oh, 0, NM_MT_BS11_LMT_LOGOFF,
Harald Welte1bc09062009-01-18 14:17:52 +00001804 NM_OC_BS11_A3, 0xff, 0xff, 0xff);
1805 }
Harald Welte05188ee2009-01-18 11:39:08 +00001806
1807 return abis_nm_sendmsg(bts, msg);
1808}
Harald Welte1bc09062009-01-18 14:17:52 +00001809
1810int abis_nm_bs11_set_trx1_pw(struct gsm_bts *bts, const char *password)
1811{
1812 struct abis_om_hdr *oh;
1813 struct msgb *msg;
1814
1815 if (strlen(password) != 10)
1816 return -EINVAL;
1817
1818 msg = nm_msgb_alloc();
1819 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001820 fill_om_fom_hdr(oh, 2+strlen(password), NM_MT_BS11_SET_ATTR,
Harald Welte1bc09062009-01-18 14:17:52 +00001821 NM_OC_BS11, BS11_OBJ_TRX1, 0x00, 0x00);
1822 msgb_tlv_put(msg, NM_ATT_BS11_PASSWORD, 10, (const u_int8_t *)password);
1823
1824 return abis_nm_sendmsg(bts, msg);
1825}
1826
Harald Weltee69f5fb2009-04-28 16:31:38 +00001827/* change the BS-11 PLL Mode to either locked (E1 derived) or standalone */
1828int abis_nm_bs11_set_pll_locked(struct gsm_bts *bts, int locked)
1829{
1830 struct abis_om_hdr *oh;
1831 struct msgb *msg;
Harald Weltea432cd32009-04-29 13:01:50 +00001832 u_int8_t tlv_value;
Harald Weltee69f5fb2009-04-28 16:31:38 +00001833
1834 msg = nm_msgb_alloc();
1835 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1836 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR, NM_OC_BS11,
1837 BS11_OBJ_LI, 0x00, 0x00);
Harald Weltea432cd32009-04-29 13:01:50 +00001838
1839 if (locked)
1840 tlv_value = BS11_LI_PLL_LOCKED;
1841 else
1842 tlv_value = BS11_LI_PLL_STANDALONE;
1843
1844 msgb_tlv_put(msg, NM_ATT_BS11_PLL_MODE, 1, &tlv_value);
Harald Weltee69f5fb2009-04-28 16:31:38 +00001845
1846 return abis_nm_sendmsg(bts, msg);
1847}
1848
Harald Welte1bc09062009-01-18 14:17:52 +00001849int abis_nm_bs11_get_state(struct gsm_bts *bts)
1850{
1851 return __simple_cmd(bts, NM_MT_BS11_GET_STATE);
1852}
Harald Welte5e4d1b32009-02-01 13:36:56 +00001853
1854/* BS11 SWL */
1855
1856struct abis_nm_bs11_sw {
1857 struct gsm_bts *bts;
1858 char swl_fname[PATH_MAX];
1859 u_int8_t win_size;
Harald Welte3ffd1372009-02-01 22:15:49 +00001860 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001861 struct llist_head file_list;
1862 gsm_cbfn *user_cb; /* specified by the user */
1863};
1864static struct abis_nm_bs11_sw _g_bs11_sw, *g_bs11_sw = &_g_bs11_sw;
1865
1866struct file_list_entry {
1867 struct llist_head list;
1868 char fname[PATH_MAX];
1869};
1870
1871struct file_list_entry *fl_dequeue(struct llist_head *queue)
1872{
1873 struct llist_head *lh;
1874
1875 if (llist_empty(queue))
1876 return NULL;
1877
1878 lh = queue->next;
1879 llist_del(lh);
1880
1881 return llist_entry(lh, struct file_list_entry, list);
1882}
1883
1884static int bs11_read_swl_file(struct abis_nm_bs11_sw *bs11_sw)
1885{
1886 char linebuf[255];
1887 struct llist_head *lh, *lh2;
1888 FILE *swl;
1889 int rc = 0;
1890
1891 swl = fopen(bs11_sw->swl_fname, "r");
1892 if (!swl)
1893 return -ENODEV;
1894
1895 /* zero the stale file list, if any */
1896 llist_for_each_safe(lh, lh2, &bs11_sw->file_list) {
1897 llist_del(lh);
1898 free(lh);
1899 }
1900
1901 while (fgets(linebuf, sizeof(linebuf), swl)) {
1902 char file_id[12+1];
1903 char file_version[80+1];
1904 struct file_list_entry *fle;
1905 static char dir[PATH_MAX];
1906
1907 if (strlen(linebuf) < 4)
1908 continue;
Harald Welte3ffd1372009-02-01 22:15:49 +00001909
Harald Welte5e4d1b32009-02-01 13:36:56 +00001910 rc = sscanf(linebuf+4, "%12s:%80s\r\n", file_id, file_version);
1911 if (rc < 0) {
1912 perror("ERR parsing SWL file");
1913 rc = -EINVAL;
1914 goto out;
1915 }
1916 if (rc < 2)
1917 continue;
1918
1919 fle = malloc(sizeof(*fle));
1920 if (!fle) {
1921 rc = -ENOMEM;
1922 goto out;
1923 }
1924 memset(fle, 0, sizeof(*fle));
1925
1926 /* construct new filename */
1927 strncpy(dir, bs11_sw->swl_fname, sizeof(dir));
1928 strncat(fle->fname, dirname(dir), sizeof(fle->fname) - 1);
1929 strcat(fle->fname, "/");
1930 strncat(fle->fname, file_id, sizeof(fle->fname) - 1 -strlen(fle->fname));
Harald Welte5e4d1b32009-02-01 13:36:56 +00001931
1932 llist_add_tail(&fle->list, &bs11_sw->file_list);
1933 }
1934
1935out:
1936 fclose(swl);
1937 return rc;
1938}
1939
1940/* bs11 swload specific callback, passed to abis_nm core swload */
1941static int bs11_swload_cbfn(unsigned int hook, unsigned int event,
1942 struct msgb *msg, void *data, void *param)
1943{
1944 struct abis_nm_bs11_sw *bs11_sw = data;
1945 struct file_list_entry *fle;
1946 int rc = 0;
1947
Harald Welte5e4d1b32009-02-01 13:36:56 +00001948 switch (event) {
1949 case NM_MT_LOAD_END_ACK:
1950 fle = fl_dequeue(&bs11_sw->file_list);
1951 if (fle) {
1952 /* start download the next file of our file list */
1953 rc = abis_nm_software_load(bs11_sw->bts, fle->fname,
1954 bs11_sw->win_size,
Harald Welte3ffd1372009-02-01 22:15:49 +00001955 bs11_sw->forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00001956 &bs11_swload_cbfn, bs11_sw);
1957 free(fle);
1958 } else {
1959 /* activate the SWL */
1960 rc = abis_nm_software_activate(bs11_sw->bts,
1961 bs11_sw->swl_fname,
1962 bs11_swload_cbfn,
1963 bs11_sw);
1964 }
1965 break;
Harald Welte3ffd1372009-02-01 22:15:49 +00001966 case NM_MT_LOAD_SEG_ACK:
Harald Welte5e4d1b32009-02-01 13:36:56 +00001967 case NM_MT_LOAD_END_NACK:
1968 case NM_MT_LOAD_INIT_ACK:
1969 case NM_MT_LOAD_INIT_NACK:
1970 case NM_MT_ACTIVATE_SW_NACK:
1971 case NM_MT_ACTIVATE_SW_ACK:
1972 default:
1973 /* fallthrough to the user callback */
Harald Welte97ed1e72009-02-06 13:38:02 +00001974 if (bs11_sw->user_cb)
1975 rc = bs11_sw->user_cb(hook, event, msg, NULL, NULL);
Harald Welte5e4d1b32009-02-01 13:36:56 +00001976 break;
1977 }
1978
1979 return rc;
1980}
1981
1982/* Siemens provides a SWL file that is a mere listing of all the other
1983 * files that are part of a software release. We need to upload first
1984 * the list file, and then each file that is listed in the list file */
1985int abis_nm_bs11_load_swl(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00001986 u_int8_t win_size, int forced, gsm_cbfn *cbfn)
Harald Welte5e4d1b32009-02-01 13:36:56 +00001987{
1988 struct abis_nm_bs11_sw *bs11_sw = g_bs11_sw;
1989 struct file_list_entry *fle;
1990 int rc = 0;
1991
1992 INIT_LLIST_HEAD(&bs11_sw->file_list);
1993 bs11_sw->bts = bts;
1994 bs11_sw->win_size = win_size;
1995 bs11_sw->user_cb = cbfn;
Harald Welte3ffd1372009-02-01 22:15:49 +00001996 bs11_sw->forced = forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001997
1998 strncpy(bs11_sw->swl_fname, fname, sizeof(bs11_sw->swl_fname));
1999 rc = bs11_read_swl_file(bs11_sw);
2000 if (rc < 0)
2001 return rc;
2002
2003 /* dequeue next item in file list */
2004 fle = fl_dequeue(&bs11_sw->file_list);
2005 if (!fle)
2006 return -EINVAL;
2007
2008 /* start download the next file of our file list */
Harald Welte3ffd1372009-02-01 22:15:49 +00002009 rc = abis_nm_software_load(bts, fle->fname, win_size, forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00002010 bs11_swload_cbfn, bs11_sw);
2011 free(fle);
2012 return rc;
2013}
2014
Harald Welte5083b0b2009-02-02 19:20:52 +00002015#if 0
Harald Welte5e4d1b32009-02-01 13:36:56 +00002016static u_int8_t req_attr_btse[] = {
2017 NM_ATT_ADM_STATE, NM_ATT_BS11_LMT_LOGON_SESSION,
2018 NM_ATT_BS11_LMT_LOGIN_TIME, NM_ATT_BS11_LMT_USER_ACC_LEV,
2019 NM_ATT_BS11_LMT_USER_NAME,
2020
2021 0xaf, NM_ATT_BS11_RX_OFFSET, NM_ATT_BS11_VENDOR_NAME,
2022
2023 NM_ATT_BS11_SW_LOAD_INTENDED, NM_ATT_BS11_SW_LOAD_SAFETY,
2024
2025 NM_ATT_BS11_SW_LOAD_STORED };
2026
2027static u_int8_t req_attr_btsm[] = {
2028 NM_ATT_ABIS_CHANNEL, NM_ATT_TEI, NM_ATT_BS11_ABIS_EXT_TIME,
2029 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xce, NM_ATT_FILE_ID,
2030 NM_ATT_FILE_VERSION, NM_ATT_OPER_STATE, 0xe8, NM_ATT_BS11_ALL_TEST_CATG,
2031 NM_ATT_SW_DESCR, NM_ATT_GET_ARI };
Harald Welte5083b0b2009-02-02 19:20:52 +00002032#endif
Harald Welte5e4d1b32009-02-01 13:36:56 +00002033
2034static u_int8_t req_attr[] = {
2035 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xa8, NM_ATT_OPER_STATE,
2036 0xd5, 0xa1, NM_ATT_BS11_ESN_FW_CODE_NO, NM_ATT_BS11_ESN_HW_CODE_NO,
Harald Weltea7cfa032009-04-29 22:33:02 +00002037 0x42, NM_ATT_BS11_ESN_PCB_SERIAL, NM_ATT_BS11_PLL };
Harald Welte5e4d1b32009-02-01 13:36:56 +00002038
2039int abis_nm_bs11_get_serno(struct gsm_bts *bts)
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 /* SiemensHW CCTRL object */
2046 fill_om_fom_hdr(oh, 2+sizeof(req_attr), NM_MT_GET_ATTR, NM_OC_BS11,
2047 0x03, 0x00, 0x00);
2048 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(req_attr), req_attr);
2049
2050 return abis_nm_sendmsg(bts, msg);
2051}
Harald Welte268bb402009-02-01 19:11:56 +00002052
2053int abis_nm_bs11_set_ext_time(struct gsm_bts *bts)
2054{
2055 struct abis_om_hdr *oh;
2056 struct msgb *msg = nm_msgb_alloc();
2057 struct bs11_date_time aet;
2058
2059 get_bs11_date_time(&aet);
2060 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2061 /* SiemensHW CCTRL object */
2062 fill_om_fom_hdr(oh, 2+sizeof(aet), NM_MT_BS11_SET_ATTR, NM_OC_SITE_MANAGER,
2063 0xff, 0xff, 0xff);
Harald Welte5083b0b2009-02-02 19:20:52 +00002064 msgb_tlv_put(msg, NM_ATT_BS11_ABIS_EXT_TIME, sizeof(aet), (u_int8_t *) &aet);
Harald Welte268bb402009-02-01 19:11:56 +00002065
2066 return abis_nm_sendmsg(bts, msg);
2067}
Harald Welte5c1e4582009-02-15 11:57:29 +00002068
2069/* ip.access nanoBTS specific commands */
Harald Welte5c1e4582009-02-15 11:57:29 +00002070static const char ipaccess_magic[] = "com.ipaccess";
2071
Harald Welte677c21f2009-02-17 13:22:23 +00002072
2073static int abis_nm_rx_ipacc(struct msgb *msg)
2074{
2075 struct abis_om_hdr *oh = msgb_l2(msg);
2076 struct abis_om_fom_hdr *foh;
2077 u_int8_t idstrlen = oh->data[0];
2078 struct tlv_parsed tp;
2079
2080 if (strncmp((char *)&oh->data[1], ipaccess_magic, idstrlen)) {
2081 DEBUGP(DNM, "id string is not com.ipaccess !?!\n");
2082 return -EINVAL;
2083 }
2084
Harald Welte193fefc2009-04-30 15:16:27 +00002085 foh = (struct abis_om_fom_hdr *) (oh->data + 1 + idstrlen);
Harald Welte03133942009-02-18 19:51:53 +00002086 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Welte677c21f2009-02-17 13:22:23 +00002087
Harald Welte193fefc2009-04-30 15:16:27 +00002088 DEBUGP(DNM, "IPACCESS(0x%02x): ", foh->msg_type);
2089
Harald Welte677c21f2009-02-17 13:22:23 +00002090 switch (foh->msg_type) {
2091 case NM_MT_IPACC_RSL_CONNECT_ACK:
Harald Welte193fefc2009-04-30 15:16:27 +00002092 DEBUGPC(DNM, "RSL CONNECT ACK ");
Harald Welte677c21f2009-02-17 13:22:23 +00002093 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_RSL_BSC_IP))
Harald Welte9de2bf82009-04-30 15:59:55 +00002094 DEBUGPC(DNM, "IP=%s ",
Harald Welte677c21f2009-02-17 13:22:23 +00002095 inet_ntoa(*((struct in_addr *)
2096 TLVP_VAL(&tp, NM_ATT_IPACC_RSL_BSC_IP))));
2097 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_RSL_BSC_PORT))
Harald Welte9de2bf82009-04-30 15:59:55 +00002098 DEBUGPC(DNM, "PORT=%u ",
Harald Welte677c21f2009-02-17 13:22:23 +00002099 ntohs(*((u_int16_t *)
2100 TLVP_VAL(&tp, NM_ATT_IPACC_RSL_BSC_PORT))));
Harald Welte9de2bf82009-04-30 15:59:55 +00002101 DEBUGPC(DNM, "\n");
Harald Welte677c21f2009-02-17 13:22:23 +00002102 break;
2103 case NM_MT_IPACC_RSL_CONNECT_NACK:
Harald Welte193fefc2009-04-30 15:16:27 +00002104 DEBUGPC(DNM, "RSL CONNECT NACK ");
Harald Welte677c21f2009-02-17 13:22:23 +00002105 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
Harald Welte6c96ba52009-05-01 13:03:40 +00002106 DEBUGPC(DNM, " CAUSE=%s\n",
2107 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
Harald Welte677c21f2009-02-17 13:22:23 +00002108 else
2109 DEBUGPC(DNM, "\n");
2110 break;
Harald Welte193fefc2009-04-30 15:16:27 +00002111 case NM_MT_IPACC_SET_NVATTR_ACK:
2112 DEBUGPC(DNM, "SET NVATTR ACK\n");
2113 /* FIXME: decode and show the actual attributes */
2114 break;
2115 case NM_MT_IPACC_SET_NVATTR_NACK:
Harald Welte6c96ba52009-05-01 13:03:40 +00002116 DEBUGPC(DNM, "SET NVATTR NACK ");
2117 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
2118 DEBUGPC(DNM, " CAUSE=%s\n",
2119 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
2120 else
2121 DEBUGPC(DNM, "\n");
Harald Welte193fefc2009-04-30 15:16:27 +00002122 break;
2123 default:
2124 DEBUGPC(DNM, "unknown\n");
2125 break;
Harald Welte677c21f2009-02-17 13:22:23 +00002126 }
2127 return 0;
2128}
2129
Harald Welte193fefc2009-04-30 15:16:27 +00002130/* send an ip-access manufacturer specific message */
Harald Welte5c1e4582009-02-15 11:57:29 +00002131int abis_nm_ipaccess_msg(struct gsm_bts *bts, u_int8_t msg_type,
2132 u_int8_t obj_class, u_int8_t bts_nr,
2133 u_int8_t trx_nr, u_int8_t ts_nr,
2134 u_int8_t *attr, int attr_len)
2135{
2136 struct msgb *msg = nm_msgb_alloc();
2137 struct abis_om_hdr *oh;
2138 struct abis_om_fom_hdr *foh;
2139 u_int8_t *data;
2140
2141 /* construct the 12.21 OM header, observe the erroneous length */
2142 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
2143 fill_om_hdr(oh, sizeof(*foh) + attr_len);
2144 oh->mdisc = ABIS_OM_MDISC_MANUF;
2145
2146 /* add the ip.access magic */
2147 data = msgb_put(msg, sizeof(ipaccess_magic)+1);
2148 *data++ = sizeof(ipaccess_magic);
2149 memcpy(data, ipaccess_magic, sizeof(ipaccess_magic));
2150
2151 /* fill the 12.21 FOM header */
2152 foh = (struct abis_om_fom_hdr *) msgb_put(msg, sizeof(*foh));
2153 foh->msg_type = msg_type;
2154 foh->obj_class = obj_class;
2155 foh->obj_inst.bts_nr = bts_nr;
2156 foh->obj_inst.trx_nr = trx_nr;
2157 foh->obj_inst.ts_nr = ts_nr;
2158
2159 if (attr && attr_len) {
2160 data = msgb_put(msg, attr_len);
2161 memcpy(data, attr, attr_len);
2162 }
2163
2164 return abis_nm_sendmsg(bts, msg);
2165}
Harald Welte677c21f2009-02-17 13:22:23 +00002166
Harald Welte193fefc2009-04-30 15:16:27 +00002167/* set some attributes in NVRAM */
2168int abis_nm_ipaccess_set_nvattr(struct gsm_bts *bts, u_int8_t *attr,
2169 int attr_len)
2170{
2171 return abis_nm_ipaccess_msg(bts, NM_MT_IPACC_SET_NVATTR,
2172 NM_OC_BASEB_TRANSC, 0, 0, 0xff, attr,
2173 attr_len);
2174}
2175
2176/* restart / reboot an ip.access nanoBTS */
2177int abis_nm_ipaccess_restart(struct gsm_bts *bts)
2178{
2179 return __simple_cmd(bts, NM_MT_IPACC_RESTART);
2180}