blob: 93cd0fce6c4b054a8f7f3d45afa5bf7a08db1c81 [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:
Harald Weltea994a482009-05-01 15:54:23 +00001252 switch (foh->msg_type) {
1253 case NM_MT_ACTIVATE_SW_ACK:
1254 rc = 0;
1255 break;
1256 }
1257 break;
Harald Welte4724f992009-01-18 18:01:49 +00001258 case SW_STATE_ERROR:
1259 break;
1260 }
1261
1262 if (rc)
Harald Weltea994a482009-05-01 15:54:23 +00001263 DEBUGP(DNM, "unexpected NM MT 0x%02x in state %u -> %u\n",
Harald Welte4724f992009-01-18 18:01:49 +00001264 foh->msg_type, old_state, sw->state);
1265
1266 return rc;
1267}
1268
1269/* Load the specified software into the BTS */
1270int abis_nm_software_load(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00001271 u_int8_t win_size, int forced,
1272 gsm_cbfn *cbfn, void *cb_data)
Harald Welte4724f992009-01-18 18:01:49 +00001273{
1274 struct abis_nm_sw *sw = &g_sw;
1275 int rc;
1276
Harald Welte5e4d1b32009-02-01 13:36:56 +00001277 DEBUGP(DNM, "Software Load (BTS %u, File \"%s\")\n",
1278 bts->nr, fname);
1279
Harald Welte4724f992009-01-18 18:01:49 +00001280 if (sw->state != SW_STATE_NONE)
1281 return -EBUSY;
1282
1283 sw->bts = bts;
1284 sw->obj_class = NM_OC_SITE_MANAGER;
1285 sw->obj_instance[0] = 0xff;
1286 sw->obj_instance[1] = 0xff;
1287 sw->obj_instance[2] = 0xff;
1288 sw->window_size = win_size;
1289 sw->state = SW_STATE_WAIT_INITACK;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001290 sw->cbfn = cbfn;
1291 sw->cb_data = cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +00001292 sw->forced = forced;
Harald Welte4724f992009-01-18 18:01:49 +00001293
1294 rc = sw_open_file(sw, fname);
1295 if (rc < 0) {
1296 sw->state = SW_STATE_NONE;
1297 return rc;
1298 }
1299
1300 return sw_load_init(sw);
1301}
Harald Welte52b1f982008-12-23 20:25:15 +00001302
Harald Welte1602ade2009-01-29 21:12:39 +00001303int abis_nm_software_load_status(struct gsm_bts *bts)
1304{
1305 struct abis_nm_sw *sw = &g_sw;
1306 struct stat st;
1307 int rc, percent;
1308
1309 rc = fstat(sw->fd, &st);
1310 if (rc < 0) {
1311 perror("ERROR during stat");
1312 return rc;
1313 }
1314
1315 percent = (ftell(sw->stream) * 100) / st.st_size;
1316 return percent;
1317}
1318
Harald Welte5e4d1b32009-02-01 13:36:56 +00001319/* Activate the specified software into the BTS */
1320int abis_nm_software_activate(struct gsm_bts *bts, const char *fname,
1321 gsm_cbfn *cbfn, void *cb_data)
1322{
1323 struct abis_nm_sw *sw = &g_sw;
1324 int rc;
1325
1326 DEBUGP(DNM, "Activating Software (BTS %u, File \"%s\")\n",
1327 bts->nr, fname);
1328
1329 if (sw->state != SW_STATE_NONE)
1330 return -EBUSY;
1331
1332 sw->bts = bts;
1333 sw->obj_class = NM_OC_SITE_MANAGER;
1334 sw->obj_instance[0] = 0xff;
1335 sw->obj_instance[1] = 0xff;
1336 sw->obj_instance[2] = 0xff;
1337 sw->state = SW_STATE_WAIT_ACTACK;
1338 sw->cbfn = cbfn;
1339 sw->cb_data = cb_data;
1340
1341 /* Open the file in order to fill some sw struct members */
1342 rc = sw_open_file(sw, fname);
1343 if (rc < 0) {
1344 sw->state = SW_STATE_NONE;
1345 return rc;
1346 }
1347 sw_close_file(sw);
1348
1349 return sw_activate(sw);
1350}
1351
Harald Welte8470bf22008-12-25 23:28:35 +00001352static void fill_nm_channel(struct abis_nm_channel *ch, u_int8_t bts_port,
Harald Welte52b1f982008-12-23 20:25:15 +00001353 u_int8_t ts_nr, u_int8_t subslot_nr)
1354{
Harald Welteadaf08b2009-01-18 11:08:10 +00001355 ch->attrib = NM_ATT_ABIS_CHANNEL;
Harald Welte52b1f982008-12-23 20:25:15 +00001356 ch->bts_port = bts_port;
1357 ch->timeslot = ts_nr;
1358 ch->subslot = subslot_nr;
1359}
1360
1361int abis_nm_establish_tei(struct gsm_bts *bts, u_int8_t trx_nr,
1362 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot,
1363 u_int8_t tei)
1364{
1365 struct abis_om_hdr *oh;
1366 struct abis_nm_channel *ch;
Harald Welte702d8702008-12-26 20:25:35 +00001367 u_int8_t len = sizeof(*ch) + 2;
Harald Welte8470bf22008-12-25 23:28:35 +00001368 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001369
1370 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1371 fill_om_fom_hdr(oh, len, NM_MT_ESTABLISH_TEI, NM_OC_RADIO_CARRIER,
1372 bts->bts_nr, trx_nr, 0xff);
1373
Harald Welte8470bf22008-12-25 23:28:35 +00001374 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte52b1f982008-12-23 20:25:15 +00001375
1376 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1377 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1378
1379 return abis_nm_sendmsg(bts, msg);
1380}
1381
1382/* connect signalling of one (BTS,TRX) to a particular timeslot on the E1 */
1383int abis_nm_conn_terr_sign(struct gsm_bts_trx *trx,
1384 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot)
1385{
Harald Welte8470bf22008-12-25 23:28:35 +00001386 struct gsm_bts *bts = trx->bts;
Harald Welte52b1f982008-12-23 20:25:15 +00001387 struct abis_om_hdr *oh;
1388 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +00001389 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001390
1391 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001392 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_SIGN,
Harald Welte52b1f982008-12-23 20:25:15 +00001393 NM_OC_RADIO_CARRIER, bts->bts_nr, trx->nr, 0xff);
1394
1395 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1396 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1397
1398 return abis_nm_sendmsg(bts, msg);
1399}
1400
1401#if 0
1402int abis_nm_disc_terr_sign(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1403 struct abis_nm_abis_channel *chan)
1404{
1405}
1406#endif
1407
1408int abis_nm_conn_terr_traf(struct gsm_bts_trx_ts *ts,
1409 u_int8_t e1_port, u_int8_t e1_timeslot,
1410 u_int8_t e1_subslot)
1411{
1412 struct gsm_bts *bts = ts->trx->bts;
1413 struct abis_om_hdr *oh;
1414 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +00001415 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001416
1417 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1418 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_TRAF,
Harald Welteb110cee2009-02-18 03:42:35 +00001419 NM_OC_CHANNEL, bts->bts_nr, ts->trx->nr, ts->nr);
Harald Welte52b1f982008-12-23 20:25:15 +00001420
1421 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1422 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1423
Harald Weltef325eb42009-02-19 17:07:39 +00001424 DEBUGP(DNM, "CONNECT TERR TRAF Um=%s E1=(%u,%u,%u)\n",
1425 gsm_ts_name(ts),
Harald Welteb110cee2009-02-18 03:42:35 +00001426 e1_port, e1_timeslot, e1_subslot);
1427
Harald Welte52b1f982008-12-23 20:25:15 +00001428 return abis_nm_sendmsg(bts, msg);
1429}
1430
1431#if 0
1432int abis_nm_disc_terr_traf(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1433 struct abis_nm_abis_channel *chan,
1434 u_int8_t subchan)
1435{
1436}
1437#endif
1438
Harald Welte22af0db2009-02-14 15:41:08 +00001439/* Chapter 8.6.1 */
1440int abis_nm_set_bts_attr(struct gsm_bts *bts, u_int8_t *attr, int attr_len)
1441{
1442 struct abis_om_hdr *oh;
1443 struct msgb *msg = nm_msgb_alloc();
1444 u_int8_t *cur;
1445
1446 DEBUGP(DNM, "Set BTS Attr (bts=%d)\n", bts->nr);
1447
1448 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte191280d2009-05-01 13:20:04 +00001449 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 +00001450 cur = msgb_put(msg, attr_len);
1451 memcpy(cur, attr, attr_len);
1452
1453 return abis_nm_sendmsg(bts, msg);
1454}
1455
1456/* Chapter 8.6.2 */
1457int abis_nm_set_radio_attr(struct gsm_bts_trx *trx, u_int8_t *attr, int attr_len)
1458{
1459 struct abis_om_hdr *oh;
1460 struct msgb *msg = nm_msgb_alloc();
1461 u_int8_t *cur;
1462
1463 DEBUGP(DNM, "Set TRX Attr (bts=%d,trx=%d)\n", trx->bts->nr, trx->nr);
1464
1465 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1466 fill_om_fom_hdr(oh, attr_len, NM_MT_SET_RADIO_ATTR, NM_OC_RADIO_CARRIER,
Harald Welte191280d2009-05-01 13:20:04 +00001467 trx->bts->bts_nr, trx->nr, 0xff);
Harald Welte22af0db2009-02-14 15:41:08 +00001468 cur = msgb_put(msg, attr_len);
1469 memcpy(cur, attr, attr_len);
1470
1471 return abis_nm_sendmsg(trx->bts, msg);
1472}
1473
1474/* Chapter 8.6.3 */
Harald Welte52b1f982008-12-23 20:25:15 +00001475int abis_nm_set_channel_attr(struct gsm_bts_trx_ts *ts, u_int8_t chan_comb)
1476{
1477 struct gsm_bts *bts = ts->trx->bts;
1478 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001479 u_int16_t arfcn = htons(ts->trx->arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001480 u_int8_t zero = 0x00;
Harald Welte8470bf22008-12-25 23:28:35 +00001481 struct msgb *msg = nm_msgb_alloc();
Harald Weltee0590df2009-02-15 03:34:15 +00001482 u_int8_t len = 2 + 2;
1483
1484 if (bts->type == GSM_BTS_TYPE_BS11)
1485 len += 4 + 2 + 2 + 3;
Harald Welte52b1f982008-12-23 20:25:15 +00001486
Harald Weltef325eb42009-02-19 17:07:39 +00001487 DEBUGP(DNM, "Set Chan Attr %s\n", gsm_ts_name(ts));
Harald Welte22af0db2009-02-14 15:41:08 +00001488
Harald Welte52b1f982008-12-23 20:25:15 +00001489 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001490 fill_om_fom_hdr(oh, len, NM_MT_SET_CHAN_ATTR,
Holger Freyther6b2d2622009-02-14 23:16:59 +00001491 NM_OC_CHANNEL, bts->bts_nr,
Harald Welte52b1f982008-12-23 20:25:15 +00001492 ts->trx->nr, ts->nr);
1493 /* FIXME: don't send ARFCN list, hopping sequence, mAIO, ...*/
Harald Weltee0590df2009-02-15 03:34:15 +00001494 if (bts->type == GSM_BTS_TYPE_BS11)
1495 msgb_tlv16_put(msg, NM_ATT_ARFCN_LIST, 1, &arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001496 msgb_tv_put(msg, NM_ATT_CHAN_COMB, chan_comb);
Harald Weltee0590df2009-02-15 03:34:15 +00001497 if (bts->type == GSM_BTS_TYPE_BS11) {
1498 msgb_tv_put(msg, NM_ATT_HSN, 0x00);
1499 msgb_tv_put(msg, NM_ATT_MAIO, 0x00);
1500 }
Harald Welte52b1f982008-12-23 20:25:15 +00001501 msgb_tv_put(msg, NM_ATT_TSC, 0x07); /* training sequence */
Harald Weltee0590df2009-02-15 03:34:15 +00001502 if (bts->type == GSM_BTS_TYPE_BS11)
1503 msgb_tlv_put(msg, 0x59, 1, &zero);
Harald Welte52b1f982008-12-23 20:25:15 +00001504
1505 return abis_nm_sendmsg(bts, msg);
1506}
1507
Harald Welte34a99682009-02-13 02:41:40 +00001508int 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 +00001509 u_int8_t i2, u_int8_t i3, int nack, u_int8_t *attr, int att_len)
Harald Welte34a99682009-02-13 02:41:40 +00001510{
1511 struct abis_om_hdr *oh;
1512 struct msgb *msg = nm_msgb_alloc();
Harald Welte5c1e4582009-02-15 11:57:29 +00001513 u_int8_t msgtype = NM_MT_SW_ACT_REQ_ACK;
1514 u_int8_t len = att_len;
1515
1516 if (nack) {
1517 len += 2;
1518 msgtype = NM_MT_SW_ACT_REQ_NACK;
1519 }
Harald Welte34a99682009-02-13 02:41:40 +00001520
1521 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte5c1e4582009-02-15 11:57:29 +00001522 fill_om_fom_hdr(oh, att_len, msgtype, obj_class, i1, i2, i3);
1523
Harald Welte34a99682009-02-13 02:41:40 +00001524 if (attr) {
1525 u_int8_t *ptr = msgb_put(msg, att_len);
1526 memcpy(ptr, attr, att_len);
1527 }
Harald Welte5c1e4582009-02-15 11:57:29 +00001528 if (nack)
1529 msgb_tv_put(msg, NM_ATT_NACK_CAUSES, NM_NACK_OBJCLASS_NOTSUPP);
Harald Welte34a99682009-02-13 02:41:40 +00001530
1531 return abis_nm_sendmsg(bts, msg);
1532}
1533
Harald Welte8470bf22008-12-25 23:28:35 +00001534int abis_nm_raw_msg(struct gsm_bts *bts, int len, u_int8_t *rawmsg)
Harald Welte52b1f982008-12-23 20:25:15 +00001535{
Harald Welte8470bf22008-12-25 23:28:35 +00001536 struct msgb *msg = nm_msgb_alloc();
1537 struct abis_om_hdr *oh;
Harald Welte52b1f982008-12-23 20:25:15 +00001538 u_int8_t *data;
1539
1540 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
1541 fill_om_hdr(oh, len);
1542 data = msgb_put(msg, len);
Harald Weltead384642008-12-26 10:20:07 +00001543 memcpy(data, rawmsg, len);
Harald Welte52b1f982008-12-23 20:25:15 +00001544
1545 return abis_nm_sendmsg(bts, msg);
1546}
1547
1548/* Siemens specific commands */
1549static int __simple_cmd(struct gsm_bts *bts, u_int8_t msg_type)
1550{
1551 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001552 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001553
1554 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001555 fill_om_fom_hdr(oh, 0, msg_type, NM_OC_SITE_MANAGER,
Harald Welte52b1f982008-12-23 20:25:15 +00001556 0xff, 0xff, 0xff);
1557
1558 return abis_nm_sendmsg(bts, msg);
1559}
1560
Harald Welte34a99682009-02-13 02:41:40 +00001561/* Chapter 8.9.2 */
1562int abis_nm_opstart(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1, u_int8_t i2)
1563{
1564 struct abis_om_hdr *oh;
1565 struct msgb *msg = nm_msgb_alloc();
1566
Harald Welte22af0db2009-02-14 15:41:08 +00001567 DEBUGP(DNM, "Sending OPSTART obj_class=0x%02x obj_inst=(0x%02x, 0x%02x, 0x%02x)\n",
1568 obj_class, i0, i1, i2);
Harald Welte34a99682009-02-13 02:41:40 +00001569 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1570 fill_om_fom_hdr(oh, 0, NM_MT_OPSTART, obj_class, i0, i1, i2);
1571
1572 return abis_nm_sendmsg(bts, msg);
1573}
1574
1575/* Chapter 8.8.5 */
1576int abis_nm_chg_adm_state(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0,
1577 u_int8_t i1, u_int8_t i2, u_int8_t adm_state)
1578{
1579 struct abis_om_hdr *oh;
1580 struct msgb *msg = nm_msgb_alloc();
1581
1582 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1583 fill_om_fom_hdr(oh, 2, NM_MT_CHG_ADM_STATE, obj_class, i0, i1, i2);
1584 msgb_tv_put(msg, NM_ATT_ADM_STATE, adm_state);
1585
1586 return abis_nm_sendmsg(bts, msg);
1587}
1588
1589
Harald Welte52b1f982008-12-23 20:25:15 +00001590int abis_nm_event_reports(struct gsm_bts *bts, int on)
1591{
1592 if (on == 0)
Harald Welte227d4072009-01-03 08:16:25 +00001593 return __simple_cmd(bts, NM_MT_STOP_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001594 else
Harald Welte227d4072009-01-03 08:16:25 +00001595 return __simple_cmd(bts, NM_MT_REST_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001596}
1597
Harald Welte47d88ae2009-01-04 12:02:08 +00001598/* Siemens (or BS-11) specific commands */
1599
Harald Welte3ffd1372009-02-01 22:15:49 +00001600int abis_nm_bs11_bsc_disconnect(struct gsm_bts *bts, int reconnect)
1601{
1602 if (reconnect == 0)
1603 return __simple_cmd(bts, NM_MT_BS11_DISCONNECT);
1604 else
1605 return __simple_cmd(bts, NM_MT_BS11_RECONNECT);
1606}
1607
Harald Welteb8427972009-02-05 19:27:17 +00001608int abis_nm_bs11_restart(struct gsm_bts *bts)
1609{
1610 return __simple_cmd(bts, NM_MT_BS11_RESTART);
1611}
1612
1613
Harald Welte268bb402009-02-01 19:11:56 +00001614struct bs11_date_time {
1615 u_int16_t year;
1616 u_int8_t month;
1617 u_int8_t day;
1618 u_int8_t hour;
1619 u_int8_t min;
1620 u_int8_t sec;
1621} __attribute__((packed));
1622
1623
1624void get_bs11_date_time(struct bs11_date_time *aet)
1625{
1626 time_t t;
1627 struct tm *tm;
1628
1629 t = time(NULL);
1630 tm = localtime(&t);
1631 aet->sec = tm->tm_sec;
1632 aet->min = tm->tm_min;
1633 aet->hour = tm->tm_hour;
1634 aet->day = tm->tm_mday;
1635 aet->month = tm->tm_mon;
1636 aet->year = htons(1900 + tm->tm_year);
1637}
1638
Harald Welte05188ee2009-01-18 11:39:08 +00001639int abis_nm_bs11_reset_resource(struct gsm_bts *bts)
Harald Welte52b1f982008-12-23 20:25:15 +00001640{
Harald Welte4668fda2009-01-03 08:19:29 +00001641 return __simple_cmd(bts, NM_MT_BS11_RESET_RESOURCE);
Harald Welte52b1f982008-12-23 20:25:15 +00001642}
1643
Harald Welte05188ee2009-01-18 11:39:08 +00001644int abis_nm_bs11_db_transmission(struct gsm_bts *bts, int begin)
Harald Welte52b1f982008-12-23 20:25:15 +00001645{
1646 if (begin)
Harald Welte4668fda2009-01-03 08:19:29 +00001647 return __simple_cmd(bts, NM_MT_BS11_BEGIN_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00001648 else
Harald Welte4668fda2009-01-03 08:19:29 +00001649 return __simple_cmd(bts, NM_MT_BS11_END_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00001650}
Harald Welte47d88ae2009-01-04 12:02:08 +00001651
Harald Welte05188ee2009-01-18 11:39:08 +00001652int abis_nm_bs11_create_object(struct gsm_bts *bts,
Harald Welte1bc09062009-01-18 14:17:52 +00001653 enum abis_bs11_objtype type, u_int8_t idx,
1654 u_int8_t attr_len, const u_int8_t *attr)
Harald Welte47d88ae2009-01-04 12:02:08 +00001655{
1656 struct abis_om_hdr *oh;
1657 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00001658 u_int8_t *cur;
Harald Welte47d88ae2009-01-04 12:02:08 +00001659
1660 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001661 fill_om_fom_hdr(oh, attr_len, NM_MT_BS11_CREATE_OBJ,
Harald Welte268bb402009-02-01 19:11:56 +00001662 NM_OC_BS11, type, 0, idx);
Harald Welte1bc09062009-01-18 14:17:52 +00001663 cur = msgb_put(msg, attr_len);
1664 memcpy(cur, attr, attr_len);
Harald Welte47d88ae2009-01-04 12:02:08 +00001665
1666 return abis_nm_sendmsg(bts, msg);
1667}
1668
Harald Welte78fc0d42009-02-19 02:50:57 +00001669int abis_nm_bs11_delete_object(struct gsm_bts *bts,
1670 enum abis_bs11_objtype type, u_int8_t idx)
1671{
1672 struct abis_om_hdr *oh;
1673 struct msgb *msg = nm_msgb_alloc();
1674
1675 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1676 fill_om_fom_hdr(oh, 0, NM_MT_BS11_DELETE_OBJ,
1677 NM_OC_BS11, type, 0, idx);
1678
1679 return abis_nm_sendmsg(bts, msg);
1680}
1681
Harald Welte05188ee2009-01-18 11:39:08 +00001682int abis_nm_bs11_create_envaBTSE(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00001683{
1684 struct abis_om_hdr *oh;
1685 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00001686 u_int8_t zero = 0x00;
Harald Welte47d88ae2009-01-04 12:02:08 +00001687
1688 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001689 fill_om_fom_hdr(oh, 3, NM_MT_BS11_CREATE_OBJ,
Harald Welte1bc09062009-01-18 14:17:52 +00001690 NM_OC_BS11_ENVABTSE, 0, idx, 0xff);
1691 msgb_tlv_put(msg, 0x99, 1, &zero);
Harald Welte47d88ae2009-01-04 12:02:08 +00001692
1693 return abis_nm_sendmsg(bts, msg);
1694}
1695
Harald Welte05188ee2009-01-18 11:39:08 +00001696int abis_nm_bs11_create_bport(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00001697{
1698 struct abis_om_hdr *oh;
1699 struct msgb *msg = nm_msgb_alloc();
1700
1701 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1702 fill_om_fom_hdr(oh, 0, NM_MT_BS11_CREATE_OBJ, NM_OC_BS11_BPORT,
1703 idx, 0, 0);
1704
1705 return abis_nm_sendmsg(bts, msg);
1706}
Harald Welte05188ee2009-01-18 11:39:08 +00001707
Harald Welte78fc0d42009-02-19 02:50:57 +00001708static const u_int8_t sm_attr[] = { NM_ATT_TEI, NM_ATT_ABIS_CHANNEL };
1709int abis_nm_bs11_get_oml_tei_ts(struct gsm_bts *bts)
1710{
1711 struct abis_om_hdr *oh;
1712 struct msgb *msg = nm_msgb_alloc();
1713
1714 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1715 fill_om_fom_hdr(oh, 2+sizeof(sm_attr), NM_MT_GET_ATTR, NM_OC_SITE_MANAGER,
1716 0xff, 0xff, 0xff);
1717 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(sm_attr), sm_attr);
1718
1719 return abis_nm_sendmsg(bts, msg);
1720}
1721
Harald Welteb6c92ae2009-02-21 20:15:32 +00001722/* like abis_nm_conn_terr_traf + set_tei */
1723int abis_nm_bs11_conn_oml_tei(struct gsm_bts *bts, u_int8_t e1_port,
1724 u_int8_t e1_timeslot, u_int8_t e1_subslot,
1725 u_int8_t tei)
Harald Welte05188ee2009-01-18 11:39:08 +00001726{
1727 struct abis_om_hdr *oh;
1728 struct abis_nm_channel *ch;
1729 struct msgb *msg = nm_msgb_alloc();
1730
1731 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welteb6c92ae2009-02-21 20:15:32 +00001732 fill_om_fom_hdr(oh, sizeof(*ch)+2, NM_MT_BS11_SET_ATTR,
Harald Welte05188ee2009-01-18 11:39:08 +00001733 NM_OC_SITE_MANAGER, 0xff, 0xff, 0xff);
1734
1735 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1736 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
Harald Welteb6c92ae2009-02-21 20:15:32 +00001737 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte05188ee2009-01-18 11:39:08 +00001738
1739 return abis_nm_sendmsg(bts, msg);
1740}
1741
1742int abis_nm_bs11_set_trx_power(struct gsm_bts_trx *trx, u_int8_t level)
1743{
1744 struct abis_om_hdr *oh;
1745 struct msgb *msg = nm_msgb_alloc();
Harald Welte05188ee2009-01-18 11:39:08 +00001746
1747 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001748 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR,
Harald Welte05188ee2009-01-18 11:39:08 +00001749 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
1750 msgb_tlv_put(msg, NM_ATT_BS11_TXPWR, 1, &level);
1751
1752 return abis_nm_sendmsg(trx->bts, msg);
1753}
1754
Harald Welte78fc0d42009-02-19 02:50:57 +00001755int abis_nm_bs11_get_trx_power(struct gsm_bts_trx *trx)
1756{
1757 struct abis_om_hdr *oh;
1758 struct msgb *msg = nm_msgb_alloc();
1759 u_int8_t attr = NM_ATT_BS11_TXPWR;
1760
1761 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1762 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
1763 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
1764 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), &attr);
1765
1766 return abis_nm_sendmsg(trx->bts, msg);
1767}
1768
Harald Welteaaf02d92009-04-29 13:25:57 +00001769int abis_nm_bs11_get_pll_mode(struct gsm_bts *bts)
1770{
1771 struct abis_om_hdr *oh;
1772 struct msgb *msg = nm_msgb_alloc();
Harald Weltea7cfa032009-04-29 22:33:02 +00001773 u_int8_t attr[] = { NM_ATT_BS11_PLL_MODE };
Harald Welteaaf02d92009-04-29 13:25:57 +00001774
1775 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1776 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
1777 NM_OC_BS11, BS11_OBJ_LI, 0x00, 0x00);
Harald Welteaeedeb42009-05-01 13:08:14 +00001778 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), attr);
Harald Welteaaf02d92009-04-29 13:25:57 +00001779
1780 return abis_nm_sendmsg(bts, msg);
1781}
1782
1783
Harald Welte268bb402009-02-01 19:11:56 +00001784//static const u_int8_t bs11_logon_c7[] = { 0x07, 0xd9, 0x01, 0x11, 0x0d, 0x10, 0x20 };
Harald Weltebb151312009-01-28 20:42:07 +00001785static const u_int8_t bs11_logon_c8[] = { 0x02 };
Harald Welte05188ee2009-01-18 11:39:08 +00001786static const u_int8_t bs11_logon_c9[] = "FACTORY";
1787
Harald Welte1bc09062009-01-18 14:17:52 +00001788int abis_nm_bs11_factory_logon(struct gsm_bts *bts, int on)
Harald Welte05188ee2009-01-18 11:39:08 +00001789{
1790 struct abis_om_hdr *oh;
1791 struct msgb *msg = nm_msgb_alloc();
Harald Welte268bb402009-02-01 19:11:56 +00001792 struct bs11_date_time bdt;
1793
1794 get_bs11_date_time(&bdt);
Harald Welte05188ee2009-01-18 11:39:08 +00001795
1796 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte1bc09062009-01-18 14:17:52 +00001797 if (on) {
Harald Welte268bb402009-02-01 19:11:56 +00001798 u_int8_t len = 3*2 + sizeof(bdt)
Harald Welte6f676a32009-01-18 14:27:48 +00001799 + sizeof(bs11_logon_c8) + sizeof(bs11_logon_c9);
Harald Welte043d04a2009-01-29 23:15:30 +00001800 fill_om_fom_hdr(oh, len, NM_MT_BS11_LMT_LOGON,
Harald Welte1bc09062009-01-18 14:17:52 +00001801 NM_OC_BS11_A3, 0xff, 0xff, 0xff);
Harald Welte043d04a2009-01-29 23:15:30 +00001802 msgb_tlv_put(msg, NM_ATT_BS11_LMT_LOGIN_TIME,
Harald Welte5083b0b2009-02-02 19:20:52 +00001803 sizeof(bdt), (u_int8_t *) &bdt);
Harald Welte043d04a2009-01-29 23:15:30 +00001804 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_ACC_LEV,
1805 sizeof(bs11_logon_c8), bs11_logon_c8);
1806 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_NAME,
1807 sizeof(bs11_logon_c9), bs11_logon_c9);
Harald Welte1bc09062009-01-18 14:17:52 +00001808 } else {
Harald Welte5e4d1b32009-02-01 13:36:56 +00001809 fill_om_fom_hdr(oh, 0, NM_MT_BS11_LMT_LOGOFF,
Harald Welte1bc09062009-01-18 14:17:52 +00001810 NM_OC_BS11_A3, 0xff, 0xff, 0xff);
1811 }
Harald Welte05188ee2009-01-18 11:39:08 +00001812
1813 return abis_nm_sendmsg(bts, msg);
1814}
Harald Welte1bc09062009-01-18 14:17:52 +00001815
1816int abis_nm_bs11_set_trx1_pw(struct gsm_bts *bts, const char *password)
1817{
1818 struct abis_om_hdr *oh;
1819 struct msgb *msg;
1820
1821 if (strlen(password) != 10)
1822 return -EINVAL;
1823
1824 msg = nm_msgb_alloc();
1825 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001826 fill_om_fom_hdr(oh, 2+strlen(password), NM_MT_BS11_SET_ATTR,
Harald Welte1bc09062009-01-18 14:17:52 +00001827 NM_OC_BS11, BS11_OBJ_TRX1, 0x00, 0x00);
1828 msgb_tlv_put(msg, NM_ATT_BS11_PASSWORD, 10, (const u_int8_t *)password);
1829
1830 return abis_nm_sendmsg(bts, msg);
1831}
1832
Harald Weltee69f5fb2009-04-28 16:31:38 +00001833/* change the BS-11 PLL Mode to either locked (E1 derived) or standalone */
1834int abis_nm_bs11_set_pll_locked(struct gsm_bts *bts, int locked)
1835{
1836 struct abis_om_hdr *oh;
1837 struct msgb *msg;
Harald Weltea432cd32009-04-29 13:01:50 +00001838 u_int8_t tlv_value;
Harald Weltee69f5fb2009-04-28 16:31:38 +00001839
1840 msg = nm_msgb_alloc();
1841 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1842 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR, NM_OC_BS11,
1843 BS11_OBJ_LI, 0x00, 0x00);
Harald Weltea432cd32009-04-29 13:01:50 +00001844
1845 if (locked)
1846 tlv_value = BS11_LI_PLL_LOCKED;
1847 else
1848 tlv_value = BS11_LI_PLL_STANDALONE;
1849
1850 msgb_tlv_put(msg, NM_ATT_BS11_PLL_MODE, 1, &tlv_value);
Harald Weltee69f5fb2009-04-28 16:31:38 +00001851
1852 return abis_nm_sendmsg(bts, msg);
1853}
1854
Harald Welte1bc09062009-01-18 14:17:52 +00001855int abis_nm_bs11_get_state(struct gsm_bts *bts)
1856{
1857 return __simple_cmd(bts, NM_MT_BS11_GET_STATE);
1858}
Harald Welte5e4d1b32009-02-01 13:36:56 +00001859
1860/* BS11 SWL */
1861
1862struct abis_nm_bs11_sw {
1863 struct gsm_bts *bts;
1864 char swl_fname[PATH_MAX];
1865 u_int8_t win_size;
Harald Welte3ffd1372009-02-01 22:15:49 +00001866 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001867 struct llist_head file_list;
1868 gsm_cbfn *user_cb; /* specified by the user */
1869};
1870static struct abis_nm_bs11_sw _g_bs11_sw, *g_bs11_sw = &_g_bs11_sw;
1871
1872struct file_list_entry {
1873 struct llist_head list;
1874 char fname[PATH_MAX];
1875};
1876
1877struct file_list_entry *fl_dequeue(struct llist_head *queue)
1878{
1879 struct llist_head *lh;
1880
1881 if (llist_empty(queue))
1882 return NULL;
1883
1884 lh = queue->next;
1885 llist_del(lh);
1886
1887 return llist_entry(lh, struct file_list_entry, list);
1888}
1889
1890static int bs11_read_swl_file(struct abis_nm_bs11_sw *bs11_sw)
1891{
1892 char linebuf[255];
1893 struct llist_head *lh, *lh2;
1894 FILE *swl;
1895 int rc = 0;
1896
1897 swl = fopen(bs11_sw->swl_fname, "r");
1898 if (!swl)
1899 return -ENODEV;
1900
1901 /* zero the stale file list, if any */
1902 llist_for_each_safe(lh, lh2, &bs11_sw->file_list) {
1903 llist_del(lh);
1904 free(lh);
1905 }
1906
1907 while (fgets(linebuf, sizeof(linebuf), swl)) {
1908 char file_id[12+1];
1909 char file_version[80+1];
1910 struct file_list_entry *fle;
1911 static char dir[PATH_MAX];
1912
1913 if (strlen(linebuf) < 4)
1914 continue;
Harald Welte3ffd1372009-02-01 22:15:49 +00001915
Harald Welte5e4d1b32009-02-01 13:36:56 +00001916 rc = sscanf(linebuf+4, "%12s:%80s\r\n", file_id, file_version);
1917 if (rc < 0) {
1918 perror("ERR parsing SWL file");
1919 rc = -EINVAL;
1920 goto out;
1921 }
1922 if (rc < 2)
1923 continue;
1924
1925 fle = malloc(sizeof(*fle));
1926 if (!fle) {
1927 rc = -ENOMEM;
1928 goto out;
1929 }
1930 memset(fle, 0, sizeof(*fle));
1931
1932 /* construct new filename */
1933 strncpy(dir, bs11_sw->swl_fname, sizeof(dir));
1934 strncat(fle->fname, dirname(dir), sizeof(fle->fname) - 1);
1935 strcat(fle->fname, "/");
1936 strncat(fle->fname, file_id, sizeof(fle->fname) - 1 -strlen(fle->fname));
Harald Welte5e4d1b32009-02-01 13:36:56 +00001937
1938 llist_add_tail(&fle->list, &bs11_sw->file_list);
1939 }
1940
1941out:
1942 fclose(swl);
1943 return rc;
1944}
1945
1946/* bs11 swload specific callback, passed to abis_nm core swload */
1947static int bs11_swload_cbfn(unsigned int hook, unsigned int event,
1948 struct msgb *msg, void *data, void *param)
1949{
1950 struct abis_nm_bs11_sw *bs11_sw = data;
1951 struct file_list_entry *fle;
1952 int rc = 0;
1953
Harald Welte5e4d1b32009-02-01 13:36:56 +00001954 switch (event) {
1955 case NM_MT_LOAD_END_ACK:
1956 fle = fl_dequeue(&bs11_sw->file_list);
1957 if (fle) {
1958 /* start download the next file of our file list */
1959 rc = abis_nm_software_load(bs11_sw->bts, fle->fname,
1960 bs11_sw->win_size,
Harald Welte3ffd1372009-02-01 22:15:49 +00001961 bs11_sw->forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00001962 &bs11_swload_cbfn, bs11_sw);
1963 free(fle);
1964 } else {
1965 /* activate the SWL */
1966 rc = abis_nm_software_activate(bs11_sw->bts,
1967 bs11_sw->swl_fname,
1968 bs11_swload_cbfn,
1969 bs11_sw);
1970 }
1971 break;
Harald Welte3ffd1372009-02-01 22:15:49 +00001972 case NM_MT_LOAD_SEG_ACK:
Harald Welte5e4d1b32009-02-01 13:36:56 +00001973 case NM_MT_LOAD_END_NACK:
1974 case NM_MT_LOAD_INIT_ACK:
1975 case NM_MT_LOAD_INIT_NACK:
1976 case NM_MT_ACTIVATE_SW_NACK:
1977 case NM_MT_ACTIVATE_SW_ACK:
1978 default:
1979 /* fallthrough to the user callback */
Harald Welte97ed1e72009-02-06 13:38:02 +00001980 if (bs11_sw->user_cb)
1981 rc = bs11_sw->user_cb(hook, event, msg, NULL, NULL);
Harald Welte5e4d1b32009-02-01 13:36:56 +00001982 break;
1983 }
1984
1985 return rc;
1986}
1987
1988/* Siemens provides a SWL file that is a mere listing of all the other
1989 * files that are part of a software release. We need to upload first
1990 * the list file, and then each file that is listed in the list file */
1991int abis_nm_bs11_load_swl(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00001992 u_int8_t win_size, int forced, gsm_cbfn *cbfn)
Harald Welte5e4d1b32009-02-01 13:36:56 +00001993{
1994 struct abis_nm_bs11_sw *bs11_sw = g_bs11_sw;
1995 struct file_list_entry *fle;
1996 int rc = 0;
1997
1998 INIT_LLIST_HEAD(&bs11_sw->file_list);
1999 bs11_sw->bts = bts;
2000 bs11_sw->win_size = win_size;
2001 bs11_sw->user_cb = cbfn;
Harald Welte3ffd1372009-02-01 22:15:49 +00002002 bs11_sw->forced = forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00002003
2004 strncpy(bs11_sw->swl_fname, fname, sizeof(bs11_sw->swl_fname));
2005 rc = bs11_read_swl_file(bs11_sw);
2006 if (rc < 0)
2007 return rc;
2008
2009 /* dequeue next item in file list */
2010 fle = fl_dequeue(&bs11_sw->file_list);
2011 if (!fle)
2012 return -EINVAL;
2013
2014 /* start download the next file of our file list */
Harald Welte3ffd1372009-02-01 22:15:49 +00002015 rc = abis_nm_software_load(bts, fle->fname, win_size, forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00002016 bs11_swload_cbfn, bs11_sw);
2017 free(fle);
2018 return rc;
2019}
2020
Harald Welte5083b0b2009-02-02 19:20:52 +00002021#if 0
Harald Welte5e4d1b32009-02-01 13:36:56 +00002022static u_int8_t req_attr_btse[] = {
2023 NM_ATT_ADM_STATE, NM_ATT_BS11_LMT_LOGON_SESSION,
2024 NM_ATT_BS11_LMT_LOGIN_TIME, NM_ATT_BS11_LMT_USER_ACC_LEV,
2025 NM_ATT_BS11_LMT_USER_NAME,
2026
2027 0xaf, NM_ATT_BS11_RX_OFFSET, NM_ATT_BS11_VENDOR_NAME,
2028
2029 NM_ATT_BS11_SW_LOAD_INTENDED, NM_ATT_BS11_SW_LOAD_SAFETY,
2030
2031 NM_ATT_BS11_SW_LOAD_STORED };
2032
2033static u_int8_t req_attr_btsm[] = {
2034 NM_ATT_ABIS_CHANNEL, NM_ATT_TEI, NM_ATT_BS11_ABIS_EXT_TIME,
2035 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xce, NM_ATT_FILE_ID,
2036 NM_ATT_FILE_VERSION, NM_ATT_OPER_STATE, 0xe8, NM_ATT_BS11_ALL_TEST_CATG,
2037 NM_ATT_SW_DESCR, NM_ATT_GET_ARI };
Harald Welte5083b0b2009-02-02 19:20:52 +00002038#endif
Harald Welte5e4d1b32009-02-01 13:36:56 +00002039
2040static u_int8_t req_attr[] = {
2041 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xa8, NM_ATT_OPER_STATE,
2042 0xd5, 0xa1, NM_ATT_BS11_ESN_FW_CODE_NO, NM_ATT_BS11_ESN_HW_CODE_NO,
Harald Weltea7cfa032009-04-29 22:33:02 +00002043 0x42, NM_ATT_BS11_ESN_PCB_SERIAL, NM_ATT_BS11_PLL };
Harald Welte5e4d1b32009-02-01 13:36:56 +00002044
2045int abis_nm_bs11_get_serno(struct gsm_bts *bts)
2046{
2047 struct abis_om_hdr *oh;
2048 struct msgb *msg = nm_msgb_alloc();
2049
2050 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2051 /* SiemensHW CCTRL object */
2052 fill_om_fom_hdr(oh, 2+sizeof(req_attr), NM_MT_GET_ATTR, NM_OC_BS11,
2053 0x03, 0x00, 0x00);
2054 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(req_attr), req_attr);
2055
2056 return abis_nm_sendmsg(bts, msg);
2057}
Harald Welte268bb402009-02-01 19:11:56 +00002058
2059int abis_nm_bs11_set_ext_time(struct gsm_bts *bts)
2060{
2061 struct abis_om_hdr *oh;
2062 struct msgb *msg = nm_msgb_alloc();
2063 struct bs11_date_time aet;
2064
2065 get_bs11_date_time(&aet);
2066 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2067 /* SiemensHW CCTRL object */
2068 fill_om_fom_hdr(oh, 2+sizeof(aet), NM_MT_BS11_SET_ATTR, NM_OC_SITE_MANAGER,
2069 0xff, 0xff, 0xff);
Harald Welte5083b0b2009-02-02 19:20:52 +00002070 msgb_tlv_put(msg, NM_ATT_BS11_ABIS_EXT_TIME, sizeof(aet), (u_int8_t *) &aet);
Harald Welte268bb402009-02-01 19:11:56 +00002071
2072 return abis_nm_sendmsg(bts, msg);
2073}
Harald Welte5c1e4582009-02-15 11:57:29 +00002074
2075/* ip.access nanoBTS specific commands */
Harald Welte5c1e4582009-02-15 11:57:29 +00002076static const char ipaccess_magic[] = "com.ipaccess";
2077
Harald Welte677c21f2009-02-17 13:22:23 +00002078
2079static int abis_nm_rx_ipacc(struct msgb *msg)
2080{
2081 struct abis_om_hdr *oh = msgb_l2(msg);
2082 struct abis_om_fom_hdr *foh;
2083 u_int8_t idstrlen = oh->data[0];
2084 struct tlv_parsed tp;
2085
2086 if (strncmp((char *)&oh->data[1], ipaccess_magic, idstrlen)) {
2087 DEBUGP(DNM, "id string is not com.ipaccess !?!\n");
2088 return -EINVAL;
2089 }
2090
Harald Welte193fefc2009-04-30 15:16:27 +00002091 foh = (struct abis_om_fom_hdr *) (oh->data + 1 + idstrlen);
Harald Welte03133942009-02-18 19:51:53 +00002092 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Welte677c21f2009-02-17 13:22:23 +00002093
Harald Welte193fefc2009-04-30 15:16:27 +00002094 DEBUGP(DNM, "IPACCESS(0x%02x): ", foh->msg_type);
2095
Harald Welte677c21f2009-02-17 13:22:23 +00002096 switch (foh->msg_type) {
2097 case NM_MT_IPACC_RSL_CONNECT_ACK:
Harald Welte193fefc2009-04-30 15:16:27 +00002098 DEBUGPC(DNM, "RSL CONNECT ACK ");
Harald Welte677c21f2009-02-17 13:22:23 +00002099 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_RSL_BSC_IP))
Harald Welte9de2bf82009-04-30 15:59:55 +00002100 DEBUGPC(DNM, "IP=%s ",
Harald Welte677c21f2009-02-17 13:22:23 +00002101 inet_ntoa(*((struct in_addr *)
2102 TLVP_VAL(&tp, NM_ATT_IPACC_RSL_BSC_IP))));
2103 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_RSL_BSC_PORT))
Harald Welte9de2bf82009-04-30 15:59:55 +00002104 DEBUGPC(DNM, "PORT=%u ",
Harald Welte677c21f2009-02-17 13:22:23 +00002105 ntohs(*((u_int16_t *)
2106 TLVP_VAL(&tp, NM_ATT_IPACC_RSL_BSC_PORT))));
Harald Welte9de2bf82009-04-30 15:59:55 +00002107 DEBUGPC(DNM, "\n");
Harald Welte677c21f2009-02-17 13:22:23 +00002108 break;
2109 case NM_MT_IPACC_RSL_CONNECT_NACK:
Harald Welte193fefc2009-04-30 15:16:27 +00002110 DEBUGPC(DNM, "RSL CONNECT NACK ");
Harald Welte677c21f2009-02-17 13:22:23 +00002111 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
Harald Welte6c96ba52009-05-01 13:03:40 +00002112 DEBUGPC(DNM, " CAUSE=%s\n",
2113 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
Harald Welte677c21f2009-02-17 13:22:23 +00002114 else
2115 DEBUGPC(DNM, "\n");
2116 break;
Harald Welte193fefc2009-04-30 15:16:27 +00002117 case NM_MT_IPACC_SET_NVATTR_ACK:
2118 DEBUGPC(DNM, "SET NVATTR ACK\n");
2119 /* FIXME: decode and show the actual attributes */
2120 break;
2121 case NM_MT_IPACC_SET_NVATTR_NACK:
Harald Welte6c96ba52009-05-01 13:03:40 +00002122 DEBUGPC(DNM, "SET NVATTR NACK ");
2123 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
2124 DEBUGPC(DNM, " CAUSE=%s\n",
2125 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
2126 else
2127 DEBUGPC(DNM, "\n");
Harald Welte193fefc2009-04-30 15:16:27 +00002128 break;
2129 default:
2130 DEBUGPC(DNM, "unknown\n");
2131 break;
Harald Welte677c21f2009-02-17 13:22:23 +00002132 }
2133 return 0;
2134}
2135
Harald Welte193fefc2009-04-30 15:16:27 +00002136/* send an ip-access manufacturer specific message */
Harald Welte5c1e4582009-02-15 11:57:29 +00002137int abis_nm_ipaccess_msg(struct gsm_bts *bts, u_int8_t msg_type,
2138 u_int8_t obj_class, u_int8_t bts_nr,
2139 u_int8_t trx_nr, u_int8_t ts_nr,
2140 u_int8_t *attr, int attr_len)
2141{
2142 struct msgb *msg = nm_msgb_alloc();
2143 struct abis_om_hdr *oh;
2144 struct abis_om_fom_hdr *foh;
2145 u_int8_t *data;
2146
2147 /* construct the 12.21 OM header, observe the erroneous length */
2148 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
2149 fill_om_hdr(oh, sizeof(*foh) + attr_len);
2150 oh->mdisc = ABIS_OM_MDISC_MANUF;
2151
2152 /* add the ip.access magic */
2153 data = msgb_put(msg, sizeof(ipaccess_magic)+1);
2154 *data++ = sizeof(ipaccess_magic);
2155 memcpy(data, ipaccess_magic, sizeof(ipaccess_magic));
2156
2157 /* fill the 12.21 FOM header */
2158 foh = (struct abis_om_fom_hdr *) msgb_put(msg, sizeof(*foh));
2159 foh->msg_type = msg_type;
2160 foh->obj_class = obj_class;
2161 foh->obj_inst.bts_nr = bts_nr;
2162 foh->obj_inst.trx_nr = trx_nr;
2163 foh->obj_inst.ts_nr = ts_nr;
2164
2165 if (attr && attr_len) {
2166 data = msgb_put(msg, attr_len);
2167 memcpy(data, attr, attr_len);
2168 }
2169
2170 return abis_nm_sendmsg(bts, msg);
2171}
Harald Welte677c21f2009-02-17 13:22:23 +00002172
Harald Welte193fefc2009-04-30 15:16:27 +00002173/* set some attributes in NVRAM */
2174int abis_nm_ipaccess_set_nvattr(struct gsm_bts *bts, u_int8_t *attr,
2175 int attr_len)
2176{
2177 return abis_nm_ipaccess_msg(bts, NM_MT_IPACC_SET_NVATTR,
2178 NM_OC_BASEB_TRANSC, 0, 0, 0xff, attr,
2179 attr_len);
2180}
2181
2182/* restart / reboot an ip.access nanoBTS */
2183int abis_nm_ipaccess_restart(struct gsm_bts *bts)
2184{
2185 return __simple_cmd(bts, NM_MT_IPACC_RESTART);
2186}