blob: e8424526498e1e9b1c07ad28ee4da0841e5bb67e [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 Welte52b1f982008-12-23 20:25:15 +000045
Harald Welte8470bf22008-12-25 23:28:35 +000046#define OM_ALLOC_SIZE 1024
47#define OM_HEADROOM_SIZE 128
Harald Welte52b1f982008-12-23 20:25:15 +000048
49/* unidirectional messages from BTS to BSC */
50static const enum abis_nm_msgtype reports[] = {
51 NM_MT_SW_ACTIVATED_REP,
52 NM_MT_TEST_REP,
53 NM_MT_STATECHG_EVENT_REP,
54 NM_MT_FAILURE_EVENT_REP,
55};
56
57/* messages without ACK/NACK */
58static const enum abis_nm_msgtype no_ack_nack[] = {
59 NM_MT_MEAS_RES_REQ,
60 NM_MT_STOP_MEAS,
61 NM_MT_START_MEAS,
62};
63
Harald Welte4724f992009-01-18 18:01:49 +000064/* Messages related to software load */
65static const enum abis_nm_msgtype sw_load_msgs[] = {
66 NM_MT_LOAD_INIT_ACK,
67 NM_MT_LOAD_INIT_NACK,
68 NM_MT_LOAD_SEG_ACK,
69 NM_MT_LOAD_ABORT,
70 NM_MT_LOAD_END_ACK,
71 NM_MT_LOAD_END_NACK,
Harald Welte34a99682009-02-13 02:41:40 +000072 //NM_MT_SW_ACT_REQ,
Harald Welte4724f992009-01-18 18:01:49 +000073 NM_MT_ACTIVATE_SW_ACK,
74 NM_MT_ACTIVATE_SW_NACK,
75 NM_MT_SW_ACTIVATED_REP,
76};
77
Harald Weltee0590df2009-02-15 03:34:15 +000078static const enum abis_nm_msgtype nacks[] = {
79 NM_MT_LOAD_INIT_NACK,
80 NM_MT_LOAD_END_NACK,
81 NM_MT_SW_ACT_REQ_NACK,
82 NM_MT_ACTIVATE_SW_NACK,
83 NM_MT_ESTABLISH_TEI_NACK,
84 NM_MT_CONN_TERR_SIGN_NACK,
85 NM_MT_DISC_TERR_SIGN_NACK,
86 NM_MT_CONN_TERR_TRAF_NACK,
87 NM_MT_DISC_TERR_TRAF_NACK,
88 NM_MT_CONN_MDROP_LINK_NACK,
89 NM_MT_DISC_MDROP_LINK_NACK,
90 NM_MT_SET_BTS_ATTR_NACK,
91 NM_MT_SET_RADIO_ATTR_NACK,
92 NM_MT_SET_CHAN_ATTR_NACK,
93 NM_MT_PERF_TEST_NACK,
94 NM_MT_SEND_TEST_REP_NACK,
95 NM_MT_STOP_TEST_NACK,
96 NM_MT_STOP_EVENT_REP_NACK,
97 NM_MT_REST_EVENT_REP_NACK,
98 NM_MT_CHG_ADM_STATE_NACK,
99 NM_MT_CHG_ADM_STATE_REQ_NACK,
100 NM_MT_REP_OUTST_ALARMS_NACK,
101 NM_MT_CHANGEOVER_NACK,
102 NM_MT_OPSTART_NACK,
103 NM_MT_REINIT_NACK,
104 NM_MT_SET_SITE_OUT_NACK,
105 NM_MT_CHG_HW_CONF_NACK,
106 NM_MT_GET_ATTR_NACK,
107 NM_MT_SET_ALARM_THRES_NACK,
108 NM_MT_BS11_BEGIN_DB_TX_NACK,
109 NM_MT_BS11_END_DB_TX_NACK,
110 NM_MT_BS11_CREATE_OBJ_NACK,
111 NM_MT_BS11_DELETE_OBJ_NACK,
112};
Harald Welte78fc0d42009-02-19 02:50:57 +0000113
114static const char *nack_names[0xff] = {
115 [NM_MT_LOAD_INIT_NACK] = "SOFTWARE LOAD INIT",
116 [NM_MT_LOAD_END_NACK] = "SOFTWARE LOAD END",
117 [NM_MT_SW_ACT_REQ_NACK] = "SOFTWARE ACTIVATE REQUEST",
118 [NM_MT_ACTIVATE_SW_NACK] = "ACTIVATE SOFTWARE",
119 [NM_MT_ESTABLISH_TEI_NACK] = "ESTABLISH TEI",
120 [NM_MT_CONN_TERR_SIGN_NACK] = "CONNECT TERRESTRIAL SIGNALLING",
121 [NM_MT_DISC_TERR_SIGN_NACK] = "DISCONNECT TERRESTRIAL SIGNALLING",
122 [NM_MT_CONN_TERR_TRAF_NACK] = "CONNECT TERRESTRIAL TRAFFIC",
123 [NM_MT_DISC_TERR_TRAF_NACK] = "DISCONNECT TERRESTRIAL TRAFFIC",
124 [NM_MT_CONN_MDROP_LINK_NACK] = "CONNECT MULTI-DROP LINK",
125 [NM_MT_DISC_MDROP_LINK_NACK] = "DISCONNECT MULTI-DROP LINK",
126 [NM_MT_SET_BTS_ATTR_NACK] = "SET BTS ATTRIBUTE",
127 [NM_MT_SET_RADIO_ATTR_NACK] = "SET RADIO ATTRIBUTE",
128 [NM_MT_SET_CHAN_ATTR_NACK] = "SET CHANNEL ATTRIBUTE",
129 [NM_MT_PERF_TEST_NACK] = "PERFORM TEST",
130 [NM_MT_SEND_TEST_REP_NACK] = "SEND TEST REPORT",
131 [NM_MT_STOP_TEST_NACK] = "STOP TEST",
132 [NM_MT_STOP_EVENT_REP_NACK] = "STOP EVENT REPORT",
133 [NM_MT_REST_EVENT_REP_NACK] = "RESET EVENT REPORT",
134 [NM_MT_CHG_ADM_STATE_NACK] = "CHANGE ADMINISTRATIVE STATE",
135 [NM_MT_CHG_ADM_STATE_REQ_NACK] = "CHANGE ADMINISTRATIVE STATE REQUEST",
136 [NM_MT_REP_OUTST_ALARMS_NACK] = "REPORT OUTSTANDING ALARMS",
137 [NM_MT_CHANGEOVER_NACK] = "CHANGEOVER",
138 [NM_MT_OPSTART_NACK] = "OPSTART",
139 [NM_MT_REINIT_NACK] = "REINIT",
140 [NM_MT_SET_SITE_OUT_NACK] = "SET SITE OUTPUT",
141 [NM_MT_CHG_HW_CONF_NACK] = "CHANGE HARDWARE CONFIGURATION",
142 [NM_MT_GET_ATTR_NACK] = "GET ATTRIBUTE",
143 [NM_MT_SET_ALARM_THRES_NACK] = "SET ALARM THRESHOLD",
144 [NM_MT_BS11_BEGIN_DB_TX_NACK] = "BS11 BEGIN DATABASE TRANSMISSION",
145 [NM_MT_BS11_END_DB_TX_NACK] = "BS11 END DATABASE TRANSMISSION",
146 [NM_MT_BS11_CREATE_OBJ_NACK] = "BS11 CREATE OBJECT",
147 [NM_MT_BS11_DELETE_OBJ_NACK] = "BS11 DELETE OBJECT",
148};
149
Harald Welte6c96ba52009-05-01 13:03:40 +0000150/* Chapter 9.4.36 */
151static const char *nack_cause_names[] = {
152 /* General Nack Causes */
153 [NM_NACK_INCORR_STRUCT] = "Incorrect message structure",
154 [NM_NACK_MSGTYPE_INVAL] = "Invalid message type value",
155 [NM_NACK_OBJCLASS_INVAL] = "Invalid Object class value",
156 [NM_NACK_OBJCLASS_NOTSUPP] = "Object class not supported",
157 [NM_NACK_BTSNR_UNKN] = "BTS no. unknown",
158 [NM_NACK_TRXNR_UNKN] = "Baseband Transceiver no. unknown",
159 [NM_NACK_OBJINST_UNKN] = "Object Instance unknown",
160 [NM_NACK_ATTRID_INVAL] = "Invalid attribute identifier value",
161 [NM_NACK_ATTRID_NOTSUPP] = "Attribute identifier not supported",
162 [NM_NACK_PARAM_RANGE] = "Parameter value outside permitted range",
163 [NM_NACK_ATTRLIST_INCONSISTENT] = "Inconsistency in attribute list",
164 [NM_NACK_SPEC_IMPL_NOTSUPP] = "Specified implementation not supported",
165 [NM_NACK_CANT_PERFORM] = "Message cannot be performed",
166 /* Specific Nack Causes */
167 [NM_NACK_RES_NOTIMPL] = "Resource not implemented",
168 [NM_NACK_RES_NOTAVAIL] = "Resource not available",
169 [NM_NACK_FREQ_NOTAVAIL] = "Frequency not available",
170 [NM_NACK_TEST_NOTSUPP] = "Test not supported",
171 [NM_NACK_CAPACITY_RESTR] = "Capacity restrictions",
172 [NM_NACK_PHYSCFG_NOTPERFORM] = "Physical configuration cannot be performed",
173 [NM_NACK_TEST_NOTINIT] = "Test not initiated",
174 [NM_NACK_PHYSCFG_NOTRESTORE] = "Physical configuration cannot be restored",
175 [NM_NACK_TEST_NOSUCH] = "No such test",
176 [NM_NACK_TEST_NOSTOP] = "Test cannot be stopped",
177 [NM_NACK_MSGINCONSIST_PHYSCFG] = "Message inconsistent with physical configuration",
178 [NM_NACK_FILE_INCOMPLETE] = "Complete file notreceived",
179 [NM_NACK_FILE_NOTAVAIL] = "File not available at destination",
180 [MN_NACK_FILE_NOTACTIVATE] = "File cannot be activate",
181 [NM_NACK_REQ_NOT_GRANT] = "Request not granted",
182 [NM_NACK_WAIT] = "Wait",
183 [NM_NACK_NOTH_REPORT_EXIST] = "Nothing reportable existing",
184 [NM_NACK_MEAS_NOTSUPP] = "Measurement not supported",
185 [NM_NACK_MEAS_NOTSTART] = "Measurement not started",
186};
187
188static char namebuf[255];
189static const char *nack_cause_name(u_int8_t cause)
190{
191 if (cause < ARRAY_SIZE(nack_cause_names) && nack_cause_names[cause])
192 return nack_cause_names[cause];
193
194 snprintf(namebuf, sizeof(namebuf), "0x%02x\n", cause);
195 return namebuf;
196}
197
Harald Welte52b1f982008-12-23 20:25:15 +0000198/* Attributes that the BSC can set, not only get, according to Section 9.4 */
199static const enum abis_nm_attr nm_att_settable[] = {
200 NM_ATT_ADD_INFO,
201 NM_ATT_ADD_TEXT,
202 NM_ATT_DEST,
203 NM_ATT_EVENT_TYPE,
204 NM_ATT_FILE_DATA,
205 NM_ATT_GET_ARI,
206 NM_ATT_HW_CONF_CHG,
207 NM_ATT_LIST_REQ_ATTR,
208 NM_ATT_MDROP_LINK,
209 NM_ATT_MDROP_NEXT,
210 NM_ATT_NACK_CAUSES,
211 NM_ATT_OUTST_ALARM,
212 NM_ATT_PHYS_CONF,
213 NM_ATT_PROB_CAUSE,
214 NM_ATT_RAD_SUBC,
215 NM_ATT_SOURCE,
216 NM_ATT_SPEC_PROB,
217 NM_ATT_START_TIME,
218 NM_ATT_TEST_DUR,
219 NM_ATT_TEST_NO,
220 NM_ATT_TEST_REPORT,
221 NM_ATT_WINDOW_SIZE,
222 NM_ATT_SEVERITY,
223 NM_ATT_MEAS_RES,
224 NM_ATT_MEAS_TYPE,
225};
226
Harald Weltee0590df2009-02-15 03:34:15 +0000227static const struct tlv_definition nm_att_tlvdef = {
228 .def = {
229 [NM_ATT_ABIS_CHANNEL] = { TLV_TYPE_FIXED, 3 },
230 [NM_ATT_ADD_INFO] = { TLV_TYPE_TL16V },
231 [NM_ATT_ADD_TEXT] = { TLV_TYPE_TL16V },
232 [NM_ATT_ADM_STATE] = { TLV_TYPE_TV },
233 [NM_ATT_ARFCN_LIST]= { TLV_TYPE_TL16V },
234 [NM_ATT_AUTON_REPORT] = { TLV_TYPE_TV },
235 [NM_ATT_AVAIL_STATUS] = { TLV_TYPE_TL16V },
236 [NM_ATT_BCCH_ARFCN] = { TLV_TYPE_FIXED, 2 },
237 [NM_ATT_BSIC] = { TLV_TYPE_TV },
238 [NM_ATT_BTS_AIR_TIMER] = { TLV_TYPE_TV },
239 [NM_ATT_CCCH_L_I_P] = { TLV_TYPE_TV },
240 [NM_ATT_CCCH_L_T] = { TLV_TYPE_TV },
241 [NM_ATT_CHAN_COMB] = { TLV_TYPE_TV },
242 [NM_ATT_CONN_FAIL_CRIT] = { TLV_TYPE_TL16V },
243 [NM_ATT_DEST] = { TLV_TYPE_TL16V },
244 [NM_ATT_EVENT_TYPE] = { TLV_TYPE_TV },
245 [NM_ATT_FILE_DATA] = { TLV_TYPE_TL16V },
246 [NM_ATT_FILE_ID] = { TLV_TYPE_TL16V },
247 [NM_ATT_FILE_VERSION] = { TLV_TYPE_TL16V },
248 [NM_ATT_GSM_TIME] = { TLV_TYPE_FIXED, 2 },
249 [NM_ATT_HSN] = { TLV_TYPE_TV },
250 [NM_ATT_HW_CONFIG] = { TLV_TYPE_TL16V },
251 [NM_ATT_HW_DESC] = { TLV_TYPE_TL16V },
252 [NM_ATT_INTAVE_PARAM] = { TLV_TYPE_TV },
253 [NM_ATT_INTERF_BOUND] = { TLV_TYPE_FIXED, 6 },
254 [NM_ATT_LIST_REQ_ATTR] = { TLV_TYPE_TL16V },
255 [NM_ATT_MAIO] = { TLV_TYPE_TV },
256 [NM_ATT_MANUF_STATE] = { TLV_TYPE_TV },
257 [NM_ATT_MANUF_THRESH] = { TLV_TYPE_TL16V },
258 [NM_ATT_MANUF_ID] = { TLV_TYPE_TL16V },
259 [NM_ATT_MAX_TA] = { TLV_TYPE_TV },
260 [NM_ATT_MDROP_LINK] = { TLV_TYPE_FIXED, 2 },
261 [NM_ATT_MDROP_NEXT] = { TLV_TYPE_FIXED, 2 },
262 [NM_ATT_NACK_CAUSES] = { TLV_TYPE_TV },
263 [NM_ATT_NY1] = { TLV_TYPE_TV },
264 [NM_ATT_OPER_STATE] = { TLV_TYPE_TV },
265 [NM_ATT_OVERL_PERIOD] = { TLV_TYPE_TL16V },
266 [NM_ATT_PHYS_CONF] = { TLV_TYPE_TL16V },
267 [NM_ATT_POWER_CLASS] = { TLV_TYPE_TV },
268 [NM_ATT_POWER_THRESH] = { TLV_TYPE_FIXED, 3 },
269 [NM_ATT_PROB_CAUSE] = { TLV_TYPE_FIXED, 3 },
270 [NM_ATT_RACH_B_THRESH] = { TLV_TYPE_TV },
271 [NM_ATT_LDAVG_SLOTS] = { TLV_TYPE_FIXED, 2 },
272 [NM_ATT_RAD_SUBC] = { TLV_TYPE_TV },
273 [NM_ATT_RF_MAXPOWR_R] = { TLV_TYPE_TV },
274 [NM_ATT_SITE_INPUTS] = { TLV_TYPE_TL16V },
275 [NM_ATT_SITE_OUTPUTS] = { TLV_TYPE_TL16V },
276 [NM_ATT_SOURCE] = { TLV_TYPE_TL16V },
277 [NM_ATT_SPEC_PROB] = { TLV_TYPE_TV },
278 [NM_ATT_START_TIME] = { TLV_TYPE_FIXED, 2 },
279 [NM_ATT_T200] = { TLV_TYPE_FIXED, 7 },
280 [NM_ATT_TEI] = { TLV_TYPE_TV },
281 [NM_ATT_TEST_DUR] = { TLV_TYPE_FIXED, 2 },
282 [NM_ATT_TEST_NO] = { TLV_TYPE_TV },
283 [NM_ATT_TEST_REPORT] = { TLV_TYPE_TL16V },
284 [NM_ATT_VSWR_THRESH] = { TLV_TYPE_FIXED, 2 },
285 [NM_ATT_WINDOW_SIZE] = { TLV_TYPE_TV },
286 [NM_ATT_TSC] = { TLV_TYPE_TV },
287 [NM_ATT_SW_CONFIG] = { TLV_TYPE_TL16V },
288 [NM_ATT_SEVERITY] = { TLV_TYPE_TV },
289 [NM_ATT_GET_ARI] = { TLV_TYPE_TL16V },
290 [NM_ATT_HW_CONF_CHG] = { TLV_TYPE_TL16V },
291 [NM_ATT_OUTST_ALARM] = { TLV_TYPE_TV },
292 [NM_ATT_FILE_DATA] = { TLV_TYPE_TL16V },
293 [NM_ATT_MEAS_RES] = { TLV_TYPE_TL16V },
294 /* BS11 specifics */
Harald Welte78fc0d42009-02-19 02:50:57 +0000295 [NM_ATT_BS11_ESN_FW_CODE_NO] = { TLV_TYPE_TLV },
296 [NM_ATT_BS11_ESN_HW_CODE_NO] = { TLV_TYPE_TLV },
297 [NM_ATT_BS11_ESN_PCB_SERIAL] = { TLV_TYPE_TLV },
298 [NM_ATT_BS11_BOOT_SW_VERS] = { TLV_TYPE_TLV },
299 [0xd5] = { TLV_TYPE_TLV },
300 [0xa8] = { TLV_TYPE_TLV },
Harald Weltee0590df2009-02-15 03:34:15 +0000301 [NM_ATT_BS11_PASSWORD] = { TLV_TYPE_TLV },
302 [NM_ATT_BS11_TXPWR] = { TLV_TYPE_TLV },
303 [NM_ATT_BS11_RSSI_OFFS] = { TLV_TYPE_TLV },
304 [NM_ATT_BS11_LINE_CFG] = { TLV_TYPE_TV },
305 [NM_ATT_BS11_L1_PROT_TYPE] = { TLV_TYPE_TV },
306 [NM_ATT_BS11_BIT_ERR_THESH] = { TLV_TYPE_FIXED, 2 },
307 [NM_ATT_BS11_DIVERSITY] = { TLV_TYPE_TLV },
Harald Welteee670472009-02-22 21:58:49 +0000308 [NM_ATT_BS11_LMT_LOGON_SESSION]={ TLV_TYPE_TLV },
Harald Weltee0590df2009-02-15 03:34:15 +0000309 [NM_ATT_BS11_LMT_LOGIN_TIME] = { TLV_TYPE_TLV },
310 [NM_ATT_BS11_LMT_USER_ACC_LEV] ={ TLV_TYPE_TLV },
311 [NM_ATT_BS11_LMT_USER_NAME] = { TLV_TYPE_TLV },
Harald Welte03133942009-02-18 19:51:53 +0000312 [NM_ATT_BS11_BTS_STATE] = { TLV_TYPE_TLV },
313 [NM_ATT_BS11_E1_STATE] = { TLV_TYPE_TLV },
Harald Welteaaf02d92009-04-29 13:25:57 +0000314 [NM_ATT_BS11_PLL_MODE] = { TLV_TYPE_TLV },
Harald Weltea7cfa032009-04-29 22:33:02 +0000315 [NM_ATT_BS11_PLL] = { TLV_TYPE_TLV },
Harald Welte677c21f2009-02-17 13:22:23 +0000316 /* ip.access specifics */
317 [NM_ATT_IPACC_RSL_BSC_IP] = { TLV_TYPE_FIXED, 4 },
318 [NM_ATT_IPACC_RSL_BSC_PORT] = { TLV_TYPE_FIXED, 2 },
Harald Welte3bfbb842009-04-29 22:58:38 +0000319 [NM_ATT_IPACC_PRIM_OML_IP] = { TLV_TYPE_FIXED, 6 },
320 [0x95] = { TLV_TYPE_FIXED, 2 },
Harald Welte677c21f2009-02-17 13:22:23 +0000321 [0x85] = { TLV_TYPE_TV },
322
Harald Weltee0590df2009-02-15 03:34:15 +0000323 },
324};
Harald Welte03133942009-02-18 19:51:53 +0000325
326int abis_nm_tlv_parse(struct tlv_parsed *tp, const u_int8_t *buf, int len)
327{
328 return tlv_parse(tp, &nm_att_tlvdef, buf, len);
329}
Harald Weltee0590df2009-02-15 03:34:15 +0000330
Harald Welte52b1f982008-12-23 20:25:15 +0000331static int is_in_arr(enum abis_nm_msgtype mt, const enum abis_nm_msgtype *arr, int size)
332{
333 int i;
334
335 for (i = 0; i < size; i++) {
336 if (arr[i] == mt)
337 return 1;
338 }
339
340 return 0;
341}
342
Holger Freytherca362a62009-01-04 21:05:01 +0000343#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000344/* is this msgtype the usual ACK/NACK type ? */
345static int is_ack_nack(enum abis_nm_msgtype mt)
346{
347 return !is_in_arr(mt, no_ack_nack, ARRAY_SIZE(no_ack_nack));
348}
Holger Freytherca362a62009-01-04 21:05:01 +0000349#endif
Harald Welte52b1f982008-12-23 20:25:15 +0000350
351/* is this msgtype a report ? */
352static int is_report(enum abis_nm_msgtype mt)
353{
Harald Welte8470bf22008-12-25 23:28:35 +0000354 return is_in_arr(mt, reports, ARRAY_SIZE(reports));
Harald Welte52b1f982008-12-23 20:25:15 +0000355}
356
357#define MT_ACK(x) (x+1)
358#define MT_NACK(x) (x+2)
359
360static void fill_om_hdr(struct abis_om_hdr *oh, u_int8_t len)
361{
362 oh->mdisc = ABIS_OM_MDISC_FOM;
363 oh->placement = ABIS_OM_PLACEMENT_ONLY;
364 oh->sequence = 0;
365 oh->length = len;
366}
367
368static void fill_om_fom_hdr(struct abis_om_hdr *oh, u_int8_t len,
369 u_int8_t msg_type, u_int8_t obj_class,
370 u_int8_t bts_nr, u_int8_t trx_nr, u_int8_t ts_nr)
371{
372 struct abis_om_fom_hdr *foh =
373 (struct abis_om_fom_hdr *) oh->data;
374
Harald Welte702d8702008-12-26 20:25:35 +0000375 fill_om_hdr(oh, len+sizeof(*foh));
Harald Welte52b1f982008-12-23 20:25:15 +0000376 foh->msg_type = msg_type;
377 foh->obj_class = obj_class;
378 foh->obj_inst.bts_nr = bts_nr;
379 foh->obj_inst.trx_nr = trx_nr;
380 foh->obj_inst.ts_nr = ts_nr;
381}
382
Harald Welte8470bf22008-12-25 23:28:35 +0000383static struct msgb *nm_msgb_alloc(void)
384{
385 return msgb_alloc_headroom(OM_ALLOC_SIZE, OM_HEADROOM_SIZE);
386}
387
Harald Welte52b1f982008-12-23 20:25:15 +0000388/* Send a OML NM Message from BSC to BTS */
389int abis_nm_sendmsg(struct gsm_bts *bts, struct msgb *msg)
390{
Holger Freyther59639e82009-02-09 23:09:55 +0000391 msg->trx = bts->c0;
392
Harald Weltead384642008-12-26 10:20:07 +0000393 return _abis_nm_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000394}
395
Harald Welte4724f992009-01-18 18:01:49 +0000396static int abis_nm_rcvmsg_sw(struct msgb *mb);
397
Harald Welte34a99682009-02-13 02:41:40 +0000398const char *oc_names[] = {
399 [NM_OC_SITE_MANAGER] = "SITE MANAGER",
400 [NM_OC_BTS] = "BTS",
401 [NM_OC_RADIO_CARRIER] = "RADIO CARRIER",
402 [NM_OC_BASEB_TRANSC] = "BASEBAND TRANSCEIVER",
403 [NM_OC_CHANNEL] = "CHANNEL",
404};
405
406static const char *obj_class_name(u_int8_t oc)
407{
408 if (oc >= ARRAY_SIZE(oc_names))
409 return "UNKNOWN";
410 return oc_names[oc];
411}
412
Harald Welte4d87f242009-03-10 19:43:44 +0000413const char *nm_opstate_name(u_int8_t os)
Harald Welte34a99682009-02-13 02:41:40 +0000414{
415 switch (os) {
416 case 1:
417 return "Disabled";
418 case 2:
419 return "Enabled";
420 case 0xff:
421 return "NULL";
422 default:
423 return "RFU";
424 }
425}
426
Harald Weltee0590df2009-02-15 03:34:15 +0000427/* Chapter 9.4.7 */
Harald Welte4d87f242009-03-10 19:43:44 +0000428static const char *avail_names[] = {
Harald Weltee0590df2009-02-15 03:34:15 +0000429 "In test",
430 "Failed",
431 "Power off",
432 "Off line",
433 "<not used>",
434 "Dependency",
435 "Degraded",
436 "Not installed",
437};
438
Harald Welte4d87f242009-03-10 19:43:44 +0000439const char *nm_avail_name(u_int8_t avail)
Harald Weltee0590df2009-02-15 03:34:15 +0000440{
Harald Welte0b8348d2009-02-18 03:43:01 +0000441 if (avail == 0xff)
442 return "OK";
Harald Weltee0590df2009-02-15 03:34:15 +0000443 if (avail >= ARRAY_SIZE(avail_names))
444 return "UNKNOWN";
445 return avail_names[avail];
446}
447
448
449/* obtain the gsm_nm_state data structure for a given object instance */
450static struct gsm_nm_state *
451objclass2nmstate(struct gsm_bts *bts, u_int8_t obj_class,
452 struct abis_om_obj_inst *obj_inst)
453{
454 struct gsm_bts_trx *trx;
455 struct gsm_nm_state *nm_state = NULL;
456
457 switch (obj_class) {
458 case NM_OC_BTS:
459 nm_state = &bts->nm_state;
460 break;
461 case NM_OC_RADIO_CARRIER:
462 if (obj_inst->trx_nr >= bts->num_trx)
463 return NULL;
464 trx = &bts->trx[obj_inst->trx_nr];
465 nm_state = &trx->nm_state;
466 break;
467 case NM_OC_BASEB_TRANSC:
468 if (obj_inst->trx_nr >= bts->num_trx)
469 return NULL;
470 trx = &bts->trx[obj_inst->trx_nr];
471 nm_state = &trx->bb_transc.nm_state;
472 break;
473 case NM_OC_CHANNEL:
474 if (obj_inst->trx_nr > bts->num_trx)
475 return NULL;
476 trx = &bts->trx[obj_inst->trx_nr];
477 if (obj_inst->ts_nr >= TRX_NR_TS)
478 return NULL;
479 nm_state = &trx->ts[obj_inst->ts_nr].nm_state;
480 break;
481 case NM_OC_SITE_MANAGER:
482 nm_state = &bts->site_mgr.nm_state;
483 break;
484 }
485 return nm_state;
486}
487
488/* obtain the in-memory data structure of a given object instance */
489static void *
490objclass2obj(struct gsm_bts *bts, u_int8_t obj_class,
491 struct abis_om_obj_inst *obj_inst)
492{
493 struct gsm_bts_trx *trx;
494 void *obj = NULL;
495
496 switch (obj_class) {
497 case NM_OC_BTS:
498 obj = bts;
499 break;
500 case NM_OC_RADIO_CARRIER:
501 if (obj_inst->trx_nr >= bts->num_trx)
502 return NULL;
503 trx = &bts->trx[obj_inst->trx_nr];
504 obj = trx;
505 break;
506 case NM_OC_BASEB_TRANSC:
507 if (obj_inst->trx_nr >= bts->num_trx)
508 return NULL;
509 trx = &bts->trx[obj_inst->trx_nr];
510 obj = &trx->bb_transc;
511 break;
512 case NM_OC_CHANNEL:
513 if (obj_inst->trx_nr > bts->num_trx)
514 return NULL;
515 trx = &bts->trx[obj_inst->trx_nr];
516 if (obj_inst->ts_nr >= TRX_NR_TS)
517 return NULL;
518 obj = &trx->ts[obj_inst->ts_nr];
519 break;
520 case NM_OC_SITE_MANAGER:
521 obj = &bts->site_mgr;
522 break;
523 }
524 return obj;
525}
526
527/* Update the administrative state of a given object in our in-memory data
528 * structures and send an event to the higher layer */
529static int update_admstate(struct gsm_bts *bts, u_int8_t obj_class,
530 struct abis_om_obj_inst *obj_inst, u_int8_t adm_state)
531{
Harald Welteaeedeb42009-05-01 13:08:14 +0000532 struct gsm_nm_state *nm_state, new_state;
Harald Weltee0590df2009-02-15 03:34:15 +0000533 void *obj;
534 int rc;
535
Harald Weltee0590df2009-02-15 03:34:15 +0000536 obj = objclass2obj(bts, obj_class, obj_inst);
Harald Welteaeedeb42009-05-01 13:08:14 +0000537 nm_state = objclass2nmstate(bts, obj_class, obj_inst);
538 if (!nm_state)
539 return -1;
540
541 new_state = *nm_state;
542 new_state.administrative = adm_state;
543
544 rc = nm_state_event(EVT_STATECHG_ADM, obj_class, obj, nm_state, &new_state);
545
546 nm_state->administrative = adm_state;
Harald Weltee0590df2009-02-15 03:34:15 +0000547
548 return rc;
549}
550
Harald Welte97ed1e72009-02-06 13:38:02 +0000551static int abis_nm_rx_statechg_rep(struct msgb *mb)
552{
Harald Weltee0590df2009-02-15 03:34:15 +0000553 struct abis_om_hdr *oh = msgb_l2(mb);
Harald Welte97ed1e72009-02-06 13:38:02 +0000554 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Harald Welte22af0db2009-02-14 15:41:08 +0000555 struct gsm_bts *bts = mb->trx->bts;
Harald Weltee0590df2009-02-15 03:34:15 +0000556 struct tlv_parsed tp;
557 struct gsm_nm_state *nm_state, new_state;
558 int rc;
559
Harald Welte34a99682009-02-13 02:41:40 +0000560 DEBUGP(DNM, "STATE CHG: OC=%s(%02x) INST=(%02x,%02x,%02x) ",
561 obj_class_name(foh->obj_class), foh->obj_class,
562 foh->obj_inst.bts_nr, foh->obj_inst.trx_nr,
Harald Welte97ed1e72009-02-06 13:38:02 +0000563 foh->obj_inst.ts_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000564
565 nm_state = objclass2nmstate(bts, foh->obj_class, &foh->obj_inst);
566 if (!nm_state) {
567 DEBUGPC(DNM, "\n");
568 return -EINVAL;
Harald Welte22af0db2009-02-14 15:41:08 +0000569 }
Harald Weltee0590df2009-02-15 03:34:15 +0000570
571 new_state = *nm_state;
572
Harald Welte03133942009-02-18 19:51:53 +0000573 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Weltee0590df2009-02-15 03:34:15 +0000574 if (TLVP_PRESENT(&tp, NM_ATT_OPER_STATE)) {
575 new_state.operational = *TLVP_VAL(&tp, NM_ATT_OPER_STATE);
Harald Welte4d87f242009-03-10 19:43:44 +0000576 DEBUGPC(DNM, "OP_STATE=%s ", nm_opstate_name(new_state.operational));
Harald Weltee0590df2009-02-15 03:34:15 +0000577 }
578 if (TLVP_PRESENT(&tp, NM_ATT_AVAIL_STATUS)) {
Harald Welte0b8348d2009-02-18 03:43:01 +0000579 if (TLVP_LEN(&tp, NM_ATT_AVAIL_STATUS) == 0)
580 new_state.availability = 0xff;
581 else
582 new_state.availability = *TLVP_VAL(&tp, NM_ATT_AVAIL_STATUS);
Harald Welte4d87f242009-03-10 19:43:44 +0000583 DEBUGPC(DNM, "AVAIL=%s(%02x) ", nm_avail_name(new_state.availability),
Harald Weltee0590df2009-02-15 03:34:15 +0000584 new_state.availability);
585 }
586 if (TLVP_PRESENT(&tp, NM_ATT_ADM_STATE)) {
587 new_state.administrative = *TLVP_VAL(&tp, NM_ATT_ADM_STATE);
588 DEBUGPC(DNM, "ADM=%02x ", new_state.administrative);
Harald Welte97ed1e72009-02-06 13:38:02 +0000589 }
590 DEBUGPC(DNM, "\n");
Harald Weltee0590df2009-02-15 03:34:15 +0000591
592 if (memcmp(&new_state, nm_state, sizeof(new_state))) {
593 /* Update the operational state of a given object in our in-memory data
594 * structures and send an event to the higher layer */
595 void *obj = objclass2obj(bts, foh->obj_class, &foh->obj_inst);
596 rc = nm_state_event(EVT_STATECHG_OPER, foh->obj_class, obj, nm_state, &new_state);
597 *nm_state = new_state;
598 }
599#if 0
Harald Welte22af0db2009-02-14 15:41:08 +0000600 if (op_state == 1) {
601 /* try to enable objects that are disabled */
602 abis_nm_opstart(bts, foh->obj_class,
603 foh->obj_inst.bts_nr,
604 foh->obj_inst.trx_nr,
605 foh->obj_inst.ts_nr);
606 }
Harald Weltee0590df2009-02-15 03:34:15 +0000607#endif
Harald Welte97ed1e72009-02-06 13:38:02 +0000608 return 0;
609}
610
611static int abis_nm_rcvmsg_report(struct msgb *mb)
612{
613 struct abis_om_fom_hdr *foh = msgb_l3(mb);
614 u_int8_t mt = foh->msg_type;
615
616 //nmh->cfg->report_cb(mb, foh);
617
618 switch (mt) {
619 case NM_MT_STATECHG_EVENT_REP:
620 return abis_nm_rx_statechg_rep(mb);
621 break;
Harald Welte34a99682009-02-13 02:41:40 +0000622 case NM_MT_SW_ACTIVATED_REP:
623 DEBUGP(DNM, "Software Activated Report\n");
624 break;
Harald Weltee0590df2009-02-15 03:34:15 +0000625 case NM_MT_FAILURE_EVENT_REP:
626 DEBUGP(DNM, "Failure Event Report\n");
627 break;
628 default:
629 DEBUGP(DNM, "reporting NM MT 0x%02x\n", mt);
630 break;
631
Harald Welte97ed1e72009-02-06 13:38:02 +0000632 };
633
Harald Welte97ed1e72009-02-06 13:38:02 +0000634 return 0;
635}
636
Harald Welte34a99682009-02-13 02:41:40 +0000637/* Activate the specified software into the BTS */
638static int ipacc_sw_activate(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1,
639 u_int8_t i2, u_int8_t *sw_desc, u_int8_t swdesc_len)
640{
641 struct abis_om_hdr *oh;
642 struct msgb *msg = nm_msgb_alloc();
643 u_int8_t len = swdesc_len;
644 u_int8_t *trailer;
645
646 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
647 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, obj_class, i0, i1, i2);
648
649 trailer = msgb_put(msg, swdesc_len);
650 memcpy(trailer, sw_desc, swdesc_len);
651
652 return abis_nm_sendmsg(bts, msg);
653}
654
655static int abis_nm_rx_sw_act_req(struct msgb *mb)
656{
657 struct abis_om_hdr *oh = msgb_l2(mb);
658 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Harald Welte5c1e4582009-02-15 11:57:29 +0000659 int nack = 0;
Harald Welte34a99682009-02-13 02:41:40 +0000660 int ret;
661
Harald Welte5c1e4582009-02-15 11:57:29 +0000662 DEBUGP(DNM, "Software Activate Request ");
Harald Welte34a99682009-02-13 02:41:40 +0000663
Harald Welte5c1e4582009-02-15 11:57:29 +0000664 if (foh->obj_class >= 0xf0 && foh->obj_class <= 0xf3) {
665 DEBUGPC(DNM, "NACKing for GPRS obj_class 0x%02x\n", foh->obj_class);
666 nack = 1;
667 } else
668 DEBUGPC(DNM, "ACKing and Activating\n");
669
670 ret = abis_nm_sw_act_req_ack(mb->trx->bts, foh->obj_class,
Harald Welte34a99682009-02-13 02:41:40 +0000671 foh->obj_inst.bts_nr,
672 foh->obj_inst.trx_nr,
Harald Welte5c1e4582009-02-15 11:57:29 +0000673 foh->obj_inst.ts_nr, nack,
Harald Welte34a99682009-02-13 02:41:40 +0000674 foh->data, oh->length-sizeof(*foh));
675
Harald Welte5c1e4582009-02-15 11:57:29 +0000676 if (nack)
677 return ret;
678
Harald Welte34a99682009-02-13 02:41:40 +0000679 /* FIXME: properly parse attributes */
680 return ipacc_sw_activate(mb->trx->bts, foh->obj_class,
681 foh->obj_inst.bts_nr,
682 foh->obj_inst.trx_nr,
683 foh->obj_inst.ts_nr,
684 foh->data + oh->length-sizeof(*foh)-22, 22);
685}
686
Harald Weltee0590df2009-02-15 03:34:15 +0000687/* Receive a CHANGE_ADM_STATE_ACK, parse the TLV and update local state */
688static int abis_nm_rx_chg_adm_state_ack(struct msgb *mb)
689{
690 struct abis_om_hdr *oh = msgb_l2(mb);
691 struct abis_om_fom_hdr *foh = msgb_l3(mb);
692 struct tlv_parsed tp;
693 u_int8_t adm_state;
694
Harald Welte03133942009-02-18 19:51:53 +0000695 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Weltee0590df2009-02-15 03:34:15 +0000696 if (!TLVP_PRESENT(&tp, NM_ATT_ADM_STATE))
697 return -EINVAL;
698
699 adm_state = *TLVP_VAL(&tp, NM_ATT_ADM_STATE);
700
701 return update_admstate(mb->trx->bts, foh->obj_class, &foh->obj_inst, adm_state);
702}
703
Harald Welteee670472009-02-22 21:58:49 +0000704static int abis_nm_rx_lmt_event(struct msgb *mb)
705{
706 struct abis_om_hdr *oh = msgb_l2(mb);
707 struct abis_om_fom_hdr *foh = msgb_l3(mb);
708 struct tlv_parsed tp;
709
710 DEBUGP(DNM, "LMT Event ");
711 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
712 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_LOGON_SESSION) &&
713 TLVP_LEN(&tp, NM_ATT_BS11_LMT_LOGON_SESSION) >= 1) {
714 u_int8_t onoff = *TLVP_VAL(&tp, NM_ATT_BS11_LMT_LOGON_SESSION);
715 DEBUGPC(DNM, "LOG%s ", onoff ? "ON" : "OFF");
716 }
717 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV) &&
718 TLVP_LEN(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV) >= 1) {
719 u_int8_t level = *TLVP_VAL(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV);
720 DEBUGPC(DNM, "Level=%u ", level);
721 }
722 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_USER_NAME) &&
723 TLVP_LEN(&tp, NM_ATT_BS11_LMT_USER_NAME) >= 1) {
724 char *name = (char *) TLVP_VAL(&tp, NM_ATT_BS11_LMT_USER_NAME);
725 DEBUGPC(DNM, "Username=%s ", name);
726 }
727 DEBUGPC(DNM, "\n");
728 /* FIXME: parse LMT LOGON TIME */
729 return 0;
730}
731
Harald Welte52b1f982008-12-23 20:25:15 +0000732/* Receive a OML NM Message from BTS */
Harald Welte8470bf22008-12-25 23:28:35 +0000733static int abis_nm_rcvmsg_fom(struct msgb *mb)
Harald Welte52b1f982008-12-23 20:25:15 +0000734{
Harald Welte6c96ba52009-05-01 13:03:40 +0000735 struct abis_om_hdr *oh = msgb_l2(mb);
Harald Welte52b1f982008-12-23 20:25:15 +0000736 struct abis_om_fom_hdr *foh = msgb_l3(mb);
737 u_int8_t mt = foh->msg_type;
738
739 /* check for unsolicited message */
Harald Welte97ed1e72009-02-06 13:38:02 +0000740 if (is_report(mt))
741 return abis_nm_rcvmsg_report(mb);
Harald Welte52b1f982008-12-23 20:25:15 +0000742
Harald Welte4724f992009-01-18 18:01:49 +0000743 if (is_in_arr(mt, sw_load_msgs, ARRAY_SIZE(sw_load_msgs)))
744 return abis_nm_rcvmsg_sw(mb);
745
Harald Welte78fc0d42009-02-19 02:50:57 +0000746 if (is_in_arr(mt, nacks, ARRAY_SIZE(nacks))) {
Harald Welte6c96ba52009-05-01 13:03:40 +0000747 struct tlv_parsed tp;
Harald Welte78fc0d42009-02-19 02:50:57 +0000748 if (nack_names[mt])
Harald Welte6c96ba52009-05-01 13:03:40 +0000749 DEBUGP(DNM, "%s NACK ", nack_names[mt]);
750 /* FIXME: NACK cause */
Harald Welte78fc0d42009-02-19 02:50:57 +0000751 else
Harald Welte6c96ba52009-05-01 13:03:40 +0000752 DEBUGP(DNM, "NACK 0x%02x ", mt);
753
754 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
755 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
756 DEBUGPC(DNM, "CAUSE=%s\n",
757 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
758 else
759 DEBUGPC(DNM, "\n");
Harald Welte78fc0d42009-02-19 02:50:57 +0000760 }
Harald Weltead384642008-12-26 10:20:07 +0000761#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000762 /* check if last message is to be acked */
763 if (is_ack_nack(nmh->last_msgtype)) {
764 if (mt == MT_ACK(nmh->last_msgtype)) {
765 fprintf(stderr, "received ACK (0x%x)\n",
766 foh->msg_type);
767 /* we got our ACK, continue sending the next msg */
768 } else if (mt == MT_NACK(nmh->last_msgtype)) {
769 /* we got a NACK, signal this to the caller */
770 fprintf(stderr, "received NACK (0x%x)\n",
771 foh->msg_type);
772 /* FIXME: somehow signal this to the caller */
773 } else {
774 /* really strange things happen */
775 return -EINVAL;
776 }
777 }
Harald Weltead384642008-12-26 10:20:07 +0000778#endif
779
Harald Welte97ed1e72009-02-06 13:38:02 +0000780 switch (mt) {
Harald Weltee0590df2009-02-15 03:34:15 +0000781 case NM_MT_CHG_ADM_STATE_ACK:
782 return abis_nm_rx_chg_adm_state_ack(mb);
783 break;
Harald Welte34a99682009-02-13 02:41:40 +0000784 case NM_MT_SW_ACT_REQ:
785 return abis_nm_rx_sw_act_req(mb);
786 break;
Harald Welte97ed1e72009-02-06 13:38:02 +0000787 case NM_MT_BS11_LMT_SESSION:
Harald Welteee670472009-02-22 21:58:49 +0000788 return abis_nm_rx_lmt_event(mb);
Harald Welte97ed1e72009-02-06 13:38:02 +0000789 break;
790 }
791
Harald Weltead384642008-12-26 10:20:07 +0000792 return 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000793}
794
Harald Welte677c21f2009-02-17 13:22:23 +0000795static int abis_nm_rx_ipacc(struct msgb *mb);
796
797static int abis_nm_rcvmsg_manuf(struct msgb *mb)
798{
799 int rc;
800 int bts_type = mb->trx->bts->type;
801
802 switch (bts_type) {
803 case GSM_BTS_TYPE_NANOBTS_900:
804 case GSM_BTS_TYPE_NANOBTS_1800:
805 rc = abis_nm_rx_ipacc(mb);
806 break;
807 default:
808 fprintf(stderr, "don't know how to parse OML for this "
809 "BTS type (%u)\n", bts_type);
810 rc = 0;
811 break;
812 }
813
814 return rc;
815}
816
Harald Welte52b1f982008-12-23 20:25:15 +0000817/* High-Level API */
818/* Entry-point where L2 OML from BTS enters the NM code */
Harald Welte8470bf22008-12-25 23:28:35 +0000819int abis_nm_rcvmsg(struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +0000820{
Harald Welte52b1f982008-12-23 20:25:15 +0000821 struct abis_om_hdr *oh = msgb_l2(msg);
Harald Welte677c21f2009-02-17 13:22:23 +0000822 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000823
824 /* Various consistency checks */
825 if (oh->placement != ABIS_OM_PLACEMENT_ONLY) {
826 fprintf(stderr, "ABIS OML placement 0x%x not supported\n",
827 oh->placement);
828 return -EINVAL;
829 }
830 if (oh->sequence != 0) {
831 fprintf(stderr, "ABIS OML sequence 0x%x != 0x00\n",
832 oh->sequence);
833 return -EINVAL;
834 }
Harald Welte702d8702008-12-26 20:25:35 +0000835#if 0
Holger Freytherca362a62009-01-04 21:05:01 +0000836 unsigned int l2_len = msg->tail - (u_int8_t *)msgb_l2(msg);
837 unsigned int hlen = sizeof(*oh) + sizeof(struct abis_om_fom_hdr);
Harald Welte702d8702008-12-26 20:25:35 +0000838 if (oh->length + hlen > l2_len) {
Harald Welte52b1f982008-12-23 20:25:15 +0000839 fprintf(stderr, "ABIS OML truncated message (%u > %u)\n",
840 oh->length + sizeof(*oh), l2_len);
841 return -EINVAL;
842 }
Harald Welte702d8702008-12-26 20:25:35 +0000843 if (oh->length + hlen < l2_len)
844 fprintf(stderr, "ABIS OML message with extra trailer?!? (oh->len=%d, sizeof_oh=%d l2_len=%d\n", oh->length, sizeof(*oh), l2_len);
845#endif
Harald Weltead384642008-12-26 10:20:07 +0000846 msg->l3h = (unsigned char *)oh + sizeof(*oh);
Harald Welte52b1f982008-12-23 20:25:15 +0000847
848 switch (oh->mdisc) {
849 case ABIS_OM_MDISC_FOM:
Harald Welte8470bf22008-12-25 23:28:35 +0000850 rc = abis_nm_rcvmsg_fom(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000851 break;
Harald Welte677c21f2009-02-17 13:22:23 +0000852 case ABIS_OM_MDISC_MANUF:
853 rc = abis_nm_rcvmsg_manuf(msg);
854 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000855 case ABIS_OM_MDISC_MMI:
856 case ABIS_OM_MDISC_TRAU:
Harald Welte677c21f2009-02-17 13:22:23 +0000857 fprintf(stderr, "unimplemented ABIS OML message discriminator 0x%x\n",
858 oh->mdisc);
859 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000860 default:
861 fprintf(stderr, "unknown ABIS OML message discriminator 0x%x\n",
862 oh->mdisc);
863 return -EINVAL;
864 }
865
Harald Weltead384642008-12-26 10:20:07 +0000866 msgb_free(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000867 return rc;
868}
869
870#if 0
871/* initialized all resources */
872struct abis_nm_h *abis_nm_init(struct abis_nm_cfg *cfg)
873{
874 struct abis_nm_h *nmh;
875
876 nmh = malloc(sizeof(*nmh));
877 if (!nmh)
878 return NULL;
879
880 nmh->cfg = cfg;
881
882 return nmh;
883}
884
885/* free all resources */
886void abis_nm_fini(struct abis_nm_h *nmh)
887{
888 free(nmh);
889}
890#endif
891
892/* Here we are trying to define a high-level API that can be used by
893 * the actual BSC implementation. However, the architecture is currently
894 * still under design. Ideally the calls to this API would be synchronous,
895 * while the underlying stack behind the APi runs in a traditional select
896 * based state machine.
897 */
898
Harald Welte4724f992009-01-18 18:01:49 +0000899/* 6.2 Software Load: */
900enum sw_state {
901 SW_STATE_NONE,
902 SW_STATE_WAIT_INITACK,
903 SW_STATE_WAIT_SEGACK,
904 SW_STATE_WAIT_ENDACK,
905 SW_STATE_WAIT_ACTACK,
906 SW_STATE_ERROR,
907};
Harald Welte52b1f982008-12-23 20:25:15 +0000908
Harald Welte52b1f982008-12-23 20:25:15 +0000909struct abis_nm_sw {
Harald Welte4724f992009-01-18 18:01:49 +0000910 struct gsm_bts *bts;
Harald Welte5e4d1b32009-02-01 13:36:56 +0000911 gsm_cbfn *cbfn;
912 void *cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +0000913 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +0000914
Harald Welte52b1f982008-12-23 20:25:15 +0000915 /* this will become part of the SW LOAD INITIATE */
916 u_int8_t obj_class;
917 u_int8_t obj_instance[3];
Harald Welte4724f992009-01-18 18:01:49 +0000918
919 u_int8_t file_id[255];
920 u_int8_t file_id_len;
921
922 u_int8_t file_version[255];
923 u_int8_t file_version_len;
924
925 u_int8_t window_size;
926 u_int8_t seg_in_window;
927
928 int fd;
929 FILE *stream;
930 enum sw_state state;
Harald Welte1602ade2009-01-29 21:12:39 +0000931 int last_seg;
Harald Welte52b1f982008-12-23 20:25:15 +0000932};
933
Harald Welte4724f992009-01-18 18:01:49 +0000934static struct abis_nm_sw g_sw;
935
936/* 6.2.1 / 8.3.1: Load Data Initiate */
937static int sw_load_init(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +0000938{
Harald Welte4724f992009-01-18 18:01:49 +0000939 struct abis_om_hdr *oh;
940 struct msgb *msg = nm_msgb_alloc();
941 u_int8_t len = 3*2 + sw->file_id_len + sw->file_version_len;
942
943 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
944 fill_om_fom_hdr(oh, len, NM_MT_LOAD_INIT, sw->obj_class,
945 sw->obj_instance[0], sw->obj_instance[1],
946 sw->obj_instance[2]);
947
948 /* FIXME: this is BS11 specific format */
949 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
950 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
951 sw->file_version);
952 msgb_tv_put(msg, NM_ATT_WINDOW_SIZE, sw->window_size);
953
954 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000955}
956
Harald Welte1602ade2009-01-29 21:12:39 +0000957static int is_last_line(FILE *stream)
958{
959 char next_seg_buf[256];
960 long pos;
961
962 /* check if we're sending the last line */
963 pos = ftell(stream);
964 if (!fgets(next_seg_buf, sizeof(next_seg_buf)-2, stream)) {
965 fseek(stream, pos, SEEK_SET);
966 return 1;
967 }
968
969 fseek(stream, pos, SEEK_SET);
970 return 0;
971}
972
Harald Welte4724f992009-01-18 18:01:49 +0000973/* 6.2.2 / 8.3.2 Load Data Segment */
974static int sw_load_segment(struct abis_nm_sw *sw)
975{
976 struct abis_om_hdr *oh;
977 struct msgb *msg = nm_msgb_alloc();
978 char seg_buf[256];
979 char *line_buf = seg_buf+2;
Harald Welte3b8ba212009-01-29 12:27:58 +0000980 unsigned char *tlv;
Harald Welte4724f992009-01-18 18:01:49 +0000981 u_int8_t len;
Harald Welte4724f992009-01-18 18:01:49 +0000982
983 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte3b8ba212009-01-29 12:27:58 +0000984
985 switch (sw->bts->type) {
986 case GSM_BTS_TYPE_BS11:
987 if (fgets(line_buf, sizeof(seg_buf)-2, sw->stream) == NULL) {
988 perror("fgets reading segment");
989 return -EINVAL;
990 }
991 seg_buf[0] = 0x00;
Harald Welte1602ade2009-01-29 21:12:39 +0000992
993 /* check if we're sending the last line */
994 sw->last_seg = is_last_line(sw->stream);
995 if (sw->last_seg)
996 seg_buf[1] = 0;
997 else
998 seg_buf[1] = 1 + sw->seg_in_window++;
Harald Welte3b8ba212009-01-29 12:27:58 +0000999
1000 len = strlen(line_buf) + 2;
1001 tlv = msgb_put(msg, TLV_GROSS_LEN(len));
1002 tlv_put(tlv, NM_ATT_BS11_FILE_DATA, len, (u_int8_t *)seg_buf);
1003 /* BS11 wants CR + LF in excess of the TLV length !?! */
1004 tlv[1] -= 2;
1005
1006 /* we only now know the exact length for the OM hdr */
1007 len = strlen(line_buf)+2;
1008 break;
1009 default:
1010 /* FIXME: Other BTS types */
1011 return -1;
Harald Welte4724f992009-01-18 18:01:49 +00001012 }
Harald Welte4724f992009-01-18 18:01:49 +00001013
Harald Welte4724f992009-01-18 18:01:49 +00001014 fill_om_fom_hdr(oh, len, NM_MT_LOAD_SEG, sw->obj_class,
1015 sw->obj_instance[0], sw->obj_instance[1],
1016 sw->obj_instance[2]);
1017
1018 return abis_nm_sendmsg(sw->bts, msg);
1019}
1020
1021/* 6.2.4 / 8.3.4 Load Data End */
1022static int sw_load_end(struct abis_nm_sw *sw)
1023{
1024 struct abis_om_hdr *oh;
1025 struct msgb *msg = nm_msgb_alloc();
1026 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
1027
1028 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1029 fill_om_fom_hdr(oh, len, NM_MT_LOAD_END, sw->obj_class,
1030 sw->obj_instance[0], sw->obj_instance[1],
1031 sw->obj_instance[2]);
1032
1033 /* FIXME: this is BS11 specific format */
1034 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1035 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1036 sw->file_version);
1037
1038 return abis_nm_sendmsg(sw->bts, msg);
1039}
Harald Welte5e4d1b32009-02-01 13:36:56 +00001040
Harald Welte52b1f982008-12-23 20:25:15 +00001041/* Activate the specified software into the BTS */
Harald Welte4724f992009-01-18 18:01:49 +00001042static int sw_activate(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +00001043{
Harald Welte4724f992009-01-18 18:01:49 +00001044 struct abis_om_hdr *oh;
1045 struct msgb *msg = nm_msgb_alloc();
1046 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
Harald Welte52b1f982008-12-23 20:25:15 +00001047
Harald Welte4724f992009-01-18 18:01:49 +00001048 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1049 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, sw->obj_class,
1050 sw->obj_instance[0], sw->obj_instance[1],
1051 sw->obj_instance[2]);
1052
1053 /* FIXME: this is BS11 specific format */
1054 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1055 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1056 sw->file_version);
1057
1058 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001059}
Harald Welte4724f992009-01-18 18:01:49 +00001060
1061static int sw_open_file(struct abis_nm_sw *sw, const char *fname)
1062{
1063 char file_id[12+1];
1064 char file_version[80+1];
1065 int rc;
1066
1067 sw->fd = open(fname, O_RDONLY);
1068 if (sw->fd < 0)
1069 return sw->fd;
1070
1071 switch (sw->bts->type) {
1072 case GSM_BTS_TYPE_BS11:
1073 sw->stream = fdopen(sw->fd, "r");
1074 if (!sw->stream) {
1075 perror("fdopen");
1076 return -1;
1077 }
1078 /* read first line and parse file ID and VERSION */
Harald Welte3b8ba212009-01-29 12:27:58 +00001079 rc = fscanf(sw->stream, "@(#)%12s:%80s\r\n",
Harald Welte4724f992009-01-18 18:01:49 +00001080 file_id, file_version);
1081 if (rc != 2) {
1082 perror("parsing header line of software file");
1083 return -1;
1084 }
1085 strcpy((char *)sw->file_id, file_id);
1086 sw->file_id_len = strlen(file_id);
1087 strcpy((char *)sw->file_version, file_version);
1088 sw->file_version_len = strlen(file_version);
1089 /* rewind to start of file */
Harald Welte3b8ba212009-01-29 12:27:58 +00001090 rewind(sw->stream);
Harald Welte4724f992009-01-18 18:01:49 +00001091 break;
1092 default:
1093 /* We don't know how to treat them yet */
1094 close(sw->fd);
1095 return -EINVAL;
1096 }
1097
1098 return 0;
1099}
1100
1101static void sw_close_file(struct abis_nm_sw *sw)
1102{
1103 switch (sw->bts->type) {
1104 case GSM_BTS_TYPE_BS11:
1105 fclose(sw->stream);
1106 break;
1107 default:
1108 close(sw->fd);
1109 break;
1110 }
1111}
1112
1113/* Fill the window */
1114static int sw_fill_window(struct abis_nm_sw *sw)
1115{
1116 int rc;
1117
1118 while (sw->seg_in_window < sw->window_size) {
1119 rc = sw_load_segment(sw);
1120 if (rc < 0)
1121 return rc;
Harald Welte1602ade2009-01-29 21:12:39 +00001122 if (sw->last_seg)
1123 break;
Harald Welte4724f992009-01-18 18:01:49 +00001124 }
1125 return 0;
1126}
1127
1128/* callback function from abis_nm_rcvmsg() handler */
1129static int abis_nm_rcvmsg_sw(struct msgb *mb)
1130{
1131 struct abis_om_fom_hdr *foh = msgb_l3(mb);
1132 int rc = -1;
1133 struct abis_nm_sw *sw = &g_sw;
1134 enum sw_state old_state = sw->state;
1135
Harald Welte3ffd1372009-02-01 22:15:49 +00001136 //DEBUGP(DNM, "state %u, NM MT 0x%02x\n", sw->state, foh->msg_type);
Harald Welte4724f992009-01-18 18:01:49 +00001137
1138 switch (sw->state) {
1139 case SW_STATE_WAIT_INITACK:
1140 switch (foh->msg_type) {
1141 case NM_MT_LOAD_INIT_ACK:
1142 /* fill window with segments */
Harald Welte5e4d1b32009-02-01 13:36:56 +00001143 if (sw->cbfn)
1144 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1145 NM_MT_LOAD_INIT_ACK, mb,
1146 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001147 rc = sw_fill_window(sw);
1148 sw->state = SW_STATE_WAIT_SEGACK;
1149 break;
1150 case NM_MT_LOAD_INIT_NACK:
Harald Welte3ffd1372009-02-01 22:15:49 +00001151 if (sw->forced) {
1152 DEBUGP(DNM, "FORCED: Ignoring Software Load "
1153 "Init NACK\n");
1154 if (sw->cbfn)
1155 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1156 NM_MT_LOAD_INIT_ACK, mb,
1157 sw->cb_data, NULL);
1158 rc = sw_fill_window(sw);
1159 sw->state = SW_STATE_WAIT_SEGACK;
1160 } else {
1161 DEBUGP(DNM, "Software Load Init NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001162 /* FIXME: cause */
Harald Welte3ffd1372009-02-01 22:15:49 +00001163 if (sw->cbfn)
1164 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1165 NM_MT_LOAD_INIT_NACK, mb,
1166 sw->cb_data, NULL);
1167 sw->state = SW_STATE_ERROR;
1168 }
Harald Welte4724f992009-01-18 18:01:49 +00001169 break;
1170 }
1171 break;
1172 case SW_STATE_WAIT_SEGACK:
1173 switch (foh->msg_type) {
1174 case NM_MT_LOAD_SEG_ACK:
Harald Welte3ffd1372009-02-01 22:15:49 +00001175 if (sw->cbfn)
1176 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1177 NM_MT_LOAD_SEG_ACK, mb,
1178 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001179 sw->seg_in_window = 0;
Harald Welte1602ade2009-01-29 21:12:39 +00001180 if (!sw->last_seg) {
1181 /* fill window with more segments */
1182 rc = sw_fill_window(sw);
1183 sw->state = SW_STATE_WAIT_SEGACK;
1184 } else {
1185 /* end the transfer */
1186 sw->state = SW_STATE_WAIT_ENDACK;
1187 rc = sw_load_end(sw);
1188 }
Harald Welte4724f992009-01-18 18:01:49 +00001189 break;
1190 }
1191 break;
1192 case SW_STATE_WAIT_ENDACK:
1193 switch (foh->msg_type) {
1194 case NM_MT_LOAD_END_ACK:
1195 sw_close_file(sw);
Harald Welte5e4d1b32009-02-01 13:36:56 +00001196 DEBUGP(DNM, "Software Load End (BTS %u)\n",
1197 sw->bts->nr);
1198 sw->state = SW_STATE_NONE;
1199 if (sw->cbfn)
1200 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1201 NM_MT_LOAD_END_ACK, mb,
1202 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001203 break;
1204 case NM_MT_LOAD_END_NACK:
Holger Freyther31338a12009-02-06 17:43:50 +00001205 if (sw->forced) {
1206 DEBUGP(DNM, "FORCED: Ignoring Software Load"
1207 "End NACK\n");
1208 sw->state = SW_STATE_NONE;
1209 if (sw->cbfn)
1210 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1211 NM_MT_LOAD_END_ACK, mb,
1212 sw->cb_data, NULL);
1213 } else {
1214 DEBUGP(DNM, "Software Load End NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001215 /* FIXME: cause */
Holger Freyther31338a12009-02-06 17:43:50 +00001216 sw->state = SW_STATE_ERROR;
1217 if (sw->cbfn)
1218 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1219 NM_MT_LOAD_END_NACK, mb,
1220 sw->cb_data, NULL);
1221 }
Harald Welte4724f992009-01-18 18:01:49 +00001222 break;
1223 }
1224 case SW_STATE_WAIT_ACTACK:
1225 switch (foh->msg_type) {
1226 case NM_MT_ACTIVATE_SW_ACK:
1227 /* we're done */
Harald Welte5e4d1b32009-02-01 13:36:56 +00001228 DEBUGP(DNM, "Activate Software DONE!\n");
Harald Welte4724f992009-01-18 18:01:49 +00001229 sw->state = SW_STATE_NONE;
1230 rc = 0;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001231 if (sw->cbfn)
1232 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1233 NM_MT_ACTIVATE_SW_ACK, mb,
1234 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001235 break;
1236 case NM_MT_ACTIVATE_SW_NACK:
Harald Welte1602ade2009-01-29 21:12:39 +00001237 DEBUGP(DNM, "Activate Software NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001238 /* FIXME: cause */
Harald Welte4724f992009-01-18 18:01:49 +00001239 sw->state = SW_STATE_ERROR;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001240 if (sw->cbfn)
1241 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1242 NM_MT_ACTIVATE_SW_NACK, mb,
1243 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001244 break;
1245 }
1246 case SW_STATE_NONE:
1247 case SW_STATE_ERROR:
1248 break;
1249 }
1250
1251 if (rc)
1252 fprintf(stderr, "unexpected NM MT 0x%02x in state %u -> %u\n",
1253 foh->msg_type, old_state, sw->state);
1254
1255 return rc;
1256}
1257
1258/* Load the specified software into the BTS */
1259int abis_nm_software_load(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00001260 u_int8_t win_size, int forced,
1261 gsm_cbfn *cbfn, void *cb_data)
Harald Welte4724f992009-01-18 18:01:49 +00001262{
1263 struct abis_nm_sw *sw = &g_sw;
1264 int rc;
1265
Harald Welte5e4d1b32009-02-01 13:36:56 +00001266 DEBUGP(DNM, "Software Load (BTS %u, File \"%s\")\n",
1267 bts->nr, fname);
1268
Harald Welte4724f992009-01-18 18:01:49 +00001269 if (sw->state != SW_STATE_NONE)
1270 return -EBUSY;
1271
1272 sw->bts = bts;
1273 sw->obj_class = NM_OC_SITE_MANAGER;
1274 sw->obj_instance[0] = 0xff;
1275 sw->obj_instance[1] = 0xff;
1276 sw->obj_instance[2] = 0xff;
1277 sw->window_size = win_size;
1278 sw->state = SW_STATE_WAIT_INITACK;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001279 sw->cbfn = cbfn;
1280 sw->cb_data = cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +00001281 sw->forced = forced;
Harald Welte4724f992009-01-18 18:01:49 +00001282
1283 rc = sw_open_file(sw, fname);
1284 if (rc < 0) {
1285 sw->state = SW_STATE_NONE;
1286 return rc;
1287 }
1288
1289 return sw_load_init(sw);
1290}
Harald Welte52b1f982008-12-23 20:25:15 +00001291
Harald Welte1602ade2009-01-29 21:12:39 +00001292int abis_nm_software_load_status(struct gsm_bts *bts)
1293{
1294 struct abis_nm_sw *sw = &g_sw;
1295 struct stat st;
1296 int rc, percent;
1297
1298 rc = fstat(sw->fd, &st);
1299 if (rc < 0) {
1300 perror("ERROR during stat");
1301 return rc;
1302 }
1303
1304 percent = (ftell(sw->stream) * 100) / st.st_size;
1305 return percent;
1306}
1307
Harald Welte5e4d1b32009-02-01 13:36:56 +00001308/* Activate the specified software into the BTS */
1309int abis_nm_software_activate(struct gsm_bts *bts, const char *fname,
1310 gsm_cbfn *cbfn, void *cb_data)
1311{
1312 struct abis_nm_sw *sw = &g_sw;
1313 int rc;
1314
1315 DEBUGP(DNM, "Activating Software (BTS %u, File \"%s\")\n",
1316 bts->nr, fname);
1317
1318 if (sw->state != SW_STATE_NONE)
1319 return -EBUSY;
1320
1321 sw->bts = bts;
1322 sw->obj_class = NM_OC_SITE_MANAGER;
1323 sw->obj_instance[0] = 0xff;
1324 sw->obj_instance[1] = 0xff;
1325 sw->obj_instance[2] = 0xff;
1326 sw->state = SW_STATE_WAIT_ACTACK;
1327 sw->cbfn = cbfn;
1328 sw->cb_data = cb_data;
1329
1330 /* Open the file in order to fill some sw struct members */
1331 rc = sw_open_file(sw, fname);
1332 if (rc < 0) {
1333 sw->state = SW_STATE_NONE;
1334 return rc;
1335 }
1336 sw_close_file(sw);
1337
1338 return sw_activate(sw);
1339}
1340
Harald Welte8470bf22008-12-25 23:28:35 +00001341static void fill_nm_channel(struct abis_nm_channel *ch, u_int8_t bts_port,
Harald Welte52b1f982008-12-23 20:25:15 +00001342 u_int8_t ts_nr, u_int8_t subslot_nr)
1343{
Harald Welteadaf08b2009-01-18 11:08:10 +00001344 ch->attrib = NM_ATT_ABIS_CHANNEL;
Harald Welte52b1f982008-12-23 20:25:15 +00001345 ch->bts_port = bts_port;
1346 ch->timeslot = ts_nr;
1347 ch->subslot = subslot_nr;
1348}
1349
1350int abis_nm_establish_tei(struct gsm_bts *bts, u_int8_t trx_nr,
1351 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot,
1352 u_int8_t tei)
1353{
1354 struct abis_om_hdr *oh;
1355 struct abis_nm_channel *ch;
Harald Welte702d8702008-12-26 20:25:35 +00001356 u_int8_t len = sizeof(*ch) + 2;
Harald Welte8470bf22008-12-25 23:28:35 +00001357 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001358
1359 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1360 fill_om_fom_hdr(oh, len, NM_MT_ESTABLISH_TEI, NM_OC_RADIO_CARRIER,
1361 bts->bts_nr, trx_nr, 0xff);
1362
Harald Welte8470bf22008-12-25 23:28:35 +00001363 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte52b1f982008-12-23 20:25:15 +00001364
1365 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1366 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1367
1368 return abis_nm_sendmsg(bts, msg);
1369}
1370
1371/* connect signalling of one (BTS,TRX) to a particular timeslot on the E1 */
1372int abis_nm_conn_terr_sign(struct gsm_bts_trx *trx,
1373 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot)
1374{
Harald Welte8470bf22008-12-25 23:28:35 +00001375 struct gsm_bts *bts = trx->bts;
Harald Welte52b1f982008-12-23 20:25:15 +00001376 struct abis_om_hdr *oh;
1377 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +00001378 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001379
1380 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001381 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_SIGN,
Harald Welte52b1f982008-12-23 20:25:15 +00001382 NM_OC_RADIO_CARRIER, bts->bts_nr, trx->nr, 0xff);
1383
1384 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1385 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1386
1387 return abis_nm_sendmsg(bts, msg);
1388}
1389
1390#if 0
1391int abis_nm_disc_terr_sign(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1392 struct abis_nm_abis_channel *chan)
1393{
1394}
1395#endif
1396
1397int abis_nm_conn_terr_traf(struct gsm_bts_trx_ts *ts,
1398 u_int8_t e1_port, u_int8_t e1_timeslot,
1399 u_int8_t e1_subslot)
1400{
1401 struct gsm_bts *bts = ts->trx->bts;
1402 struct abis_om_hdr *oh;
1403 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +00001404 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001405
1406 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1407 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_TRAF,
Harald Welteb110cee2009-02-18 03:42:35 +00001408 NM_OC_CHANNEL, bts->bts_nr, ts->trx->nr, ts->nr);
Harald Welte52b1f982008-12-23 20:25:15 +00001409
1410 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1411 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1412
Harald Weltef325eb42009-02-19 17:07:39 +00001413 DEBUGP(DNM, "CONNECT TERR TRAF Um=%s E1=(%u,%u,%u)\n",
1414 gsm_ts_name(ts),
Harald Welteb110cee2009-02-18 03:42:35 +00001415 e1_port, e1_timeslot, e1_subslot);
1416
Harald Welte52b1f982008-12-23 20:25:15 +00001417 return abis_nm_sendmsg(bts, msg);
1418}
1419
1420#if 0
1421int abis_nm_disc_terr_traf(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1422 struct abis_nm_abis_channel *chan,
1423 u_int8_t subchan)
1424{
1425}
1426#endif
1427
Harald Welte22af0db2009-02-14 15:41:08 +00001428/* Chapter 8.6.1 */
1429int abis_nm_set_bts_attr(struct gsm_bts *bts, u_int8_t *attr, int attr_len)
1430{
1431 struct abis_om_hdr *oh;
1432 struct msgb *msg = nm_msgb_alloc();
1433 u_int8_t *cur;
1434
1435 DEBUGP(DNM, "Set BTS Attr (bts=%d)\n", bts->nr);
1436
1437 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1438 fill_om_fom_hdr(oh, attr_len, NM_MT_SET_BTS_ATTR, NM_OC_BTS, bts->nr, 0xff, 0xff);
1439 cur = msgb_put(msg, attr_len);
1440 memcpy(cur, attr, attr_len);
1441
1442 return abis_nm_sendmsg(bts, msg);
1443}
1444
1445/* Chapter 8.6.2 */
1446int abis_nm_set_radio_attr(struct gsm_bts_trx *trx, u_int8_t *attr, int attr_len)
1447{
1448 struct abis_om_hdr *oh;
1449 struct msgb *msg = nm_msgb_alloc();
1450 u_int8_t *cur;
1451
1452 DEBUGP(DNM, "Set TRX Attr (bts=%d,trx=%d)\n", trx->bts->nr, trx->nr);
1453
1454 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1455 fill_om_fom_hdr(oh, attr_len, NM_MT_SET_RADIO_ATTR, NM_OC_RADIO_CARRIER,
1456 trx->bts->nr, trx->nr, 0xff);
1457 cur = msgb_put(msg, attr_len);
1458 memcpy(cur, attr, attr_len);
1459
1460 return abis_nm_sendmsg(trx->bts, msg);
1461}
1462
1463/* Chapter 8.6.3 */
Harald Welte52b1f982008-12-23 20:25:15 +00001464int abis_nm_set_channel_attr(struct gsm_bts_trx_ts *ts, u_int8_t chan_comb)
1465{
1466 struct gsm_bts *bts = ts->trx->bts;
1467 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001468 u_int16_t arfcn = htons(ts->trx->arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001469 u_int8_t zero = 0x00;
Harald Welte8470bf22008-12-25 23:28:35 +00001470 struct msgb *msg = nm_msgb_alloc();
Harald Weltee0590df2009-02-15 03:34:15 +00001471 u_int8_t len = 2 + 2;
1472
1473 if (bts->type == GSM_BTS_TYPE_BS11)
1474 len += 4 + 2 + 2 + 3;
Harald Welte52b1f982008-12-23 20:25:15 +00001475
Harald Weltef325eb42009-02-19 17:07:39 +00001476 DEBUGP(DNM, "Set Chan Attr %s\n", gsm_ts_name(ts));
Harald Welte22af0db2009-02-14 15:41:08 +00001477
Harald Welte52b1f982008-12-23 20:25:15 +00001478 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001479 fill_om_fom_hdr(oh, len, NM_MT_SET_CHAN_ATTR,
Holger Freyther6b2d2622009-02-14 23:16:59 +00001480 NM_OC_CHANNEL, bts->bts_nr,
Harald Welte52b1f982008-12-23 20:25:15 +00001481 ts->trx->nr, ts->nr);
1482 /* FIXME: don't send ARFCN list, hopping sequence, mAIO, ...*/
Harald Weltee0590df2009-02-15 03:34:15 +00001483 if (bts->type == GSM_BTS_TYPE_BS11)
1484 msgb_tlv16_put(msg, NM_ATT_ARFCN_LIST, 1, &arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001485 msgb_tv_put(msg, NM_ATT_CHAN_COMB, chan_comb);
Harald Weltee0590df2009-02-15 03:34:15 +00001486 if (bts->type == GSM_BTS_TYPE_BS11) {
1487 msgb_tv_put(msg, NM_ATT_HSN, 0x00);
1488 msgb_tv_put(msg, NM_ATT_MAIO, 0x00);
1489 }
Harald Welte52b1f982008-12-23 20:25:15 +00001490 msgb_tv_put(msg, NM_ATT_TSC, 0x07); /* training sequence */
Harald Weltee0590df2009-02-15 03:34:15 +00001491 if (bts->type == GSM_BTS_TYPE_BS11)
1492 msgb_tlv_put(msg, 0x59, 1, &zero);
Harald Welte52b1f982008-12-23 20:25:15 +00001493
1494 return abis_nm_sendmsg(bts, msg);
1495}
1496
Harald Welte34a99682009-02-13 02:41:40 +00001497int 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 +00001498 u_int8_t i2, u_int8_t i3, int nack, u_int8_t *attr, int att_len)
Harald Welte34a99682009-02-13 02:41:40 +00001499{
1500 struct abis_om_hdr *oh;
1501 struct msgb *msg = nm_msgb_alloc();
Harald Welte5c1e4582009-02-15 11:57:29 +00001502 u_int8_t msgtype = NM_MT_SW_ACT_REQ_ACK;
1503 u_int8_t len = att_len;
1504
1505 if (nack) {
1506 len += 2;
1507 msgtype = NM_MT_SW_ACT_REQ_NACK;
1508 }
Harald Welte34a99682009-02-13 02:41:40 +00001509
1510 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte5c1e4582009-02-15 11:57:29 +00001511 fill_om_fom_hdr(oh, att_len, msgtype, obj_class, i1, i2, i3);
1512
Harald Welte34a99682009-02-13 02:41:40 +00001513 if (attr) {
1514 u_int8_t *ptr = msgb_put(msg, att_len);
1515 memcpy(ptr, attr, att_len);
1516 }
Harald Welte5c1e4582009-02-15 11:57:29 +00001517 if (nack)
1518 msgb_tv_put(msg, NM_ATT_NACK_CAUSES, NM_NACK_OBJCLASS_NOTSUPP);
Harald Welte34a99682009-02-13 02:41:40 +00001519
1520 return abis_nm_sendmsg(bts, msg);
1521}
1522
Harald Welte8470bf22008-12-25 23:28:35 +00001523int abis_nm_raw_msg(struct gsm_bts *bts, int len, u_int8_t *rawmsg)
Harald Welte52b1f982008-12-23 20:25:15 +00001524{
Harald Welte8470bf22008-12-25 23:28:35 +00001525 struct msgb *msg = nm_msgb_alloc();
1526 struct abis_om_hdr *oh;
Harald Welte52b1f982008-12-23 20:25:15 +00001527 u_int8_t *data;
1528
1529 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
1530 fill_om_hdr(oh, len);
1531 data = msgb_put(msg, len);
Harald Weltead384642008-12-26 10:20:07 +00001532 memcpy(data, rawmsg, len);
Harald Welte52b1f982008-12-23 20:25:15 +00001533
1534 return abis_nm_sendmsg(bts, msg);
1535}
1536
1537/* Siemens specific commands */
1538static int __simple_cmd(struct gsm_bts *bts, u_int8_t msg_type)
1539{
1540 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001541 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001542
1543 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001544 fill_om_fom_hdr(oh, 0, msg_type, NM_OC_SITE_MANAGER,
Harald Welte52b1f982008-12-23 20:25:15 +00001545 0xff, 0xff, 0xff);
1546
1547 return abis_nm_sendmsg(bts, msg);
1548}
1549
Harald Welte34a99682009-02-13 02:41:40 +00001550/* Chapter 8.9.2 */
1551int abis_nm_opstart(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1, u_int8_t i2)
1552{
1553 struct abis_om_hdr *oh;
1554 struct msgb *msg = nm_msgb_alloc();
1555
Harald Welte22af0db2009-02-14 15:41:08 +00001556 DEBUGP(DNM, "Sending OPSTART obj_class=0x%02x obj_inst=(0x%02x, 0x%02x, 0x%02x)\n",
1557 obj_class, i0, i1, i2);
Harald Welte34a99682009-02-13 02:41:40 +00001558 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1559 fill_om_fom_hdr(oh, 0, NM_MT_OPSTART, obj_class, i0, i1, i2);
1560
1561 return abis_nm_sendmsg(bts, msg);
1562}
1563
1564/* Chapter 8.8.5 */
1565int abis_nm_chg_adm_state(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0,
1566 u_int8_t i1, u_int8_t i2, u_int8_t adm_state)
1567{
1568 struct abis_om_hdr *oh;
1569 struct msgb *msg = nm_msgb_alloc();
1570
1571 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1572 fill_om_fom_hdr(oh, 2, NM_MT_CHG_ADM_STATE, obj_class, i0, i1, i2);
1573 msgb_tv_put(msg, NM_ATT_ADM_STATE, adm_state);
1574
1575 return abis_nm_sendmsg(bts, msg);
1576}
1577
1578
Harald Welte52b1f982008-12-23 20:25:15 +00001579int abis_nm_event_reports(struct gsm_bts *bts, int on)
1580{
1581 if (on == 0)
Harald Welte227d4072009-01-03 08:16:25 +00001582 return __simple_cmd(bts, NM_MT_STOP_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001583 else
Harald Welte227d4072009-01-03 08:16:25 +00001584 return __simple_cmd(bts, NM_MT_REST_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001585}
1586
Harald Welte47d88ae2009-01-04 12:02:08 +00001587/* Siemens (or BS-11) specific commands */
1588
Harald Welte3ffd1372009-02-01 22:15:49 +00001589int abis_nm_bs11_bsc_disconnect(struct gsm_bts *bts, int reconnect)
1590{
1591 if (reconnect == 0)
1592 return __simple_cmd(bts, NM_MT_BS11_DISCONNECT);
1593 else
1594 return __simple_cmd(bts, NM_MT_BS11_RECONNECT);
1595}
1596
Harald Welteb8427972009-02-05 19:27:17 +00001597int abis_nm_bs11_restart(struct gsm_bts *bts)
1598{
1599 return __simple_cmd(bts, NM_MT_BS11_RESTART);
1600}
1601
1602
Harald Welte268bb402009-02-01 19:11:56 +00001603struct bs11_date_time {
1604 u_int16_t year;
1605 u_int8_t month;
1606 u_int8_t day;
1607 u_int8_t hour;
1608 u_int8_t min;
1609 u_int8_t sec;
1610} __attribute__((packed));
1611
1612
1613void get_bs11_date_time(struct bs11_date_time *aet)
1614{
1615 time_t t;
1616 struct tm *tm;
1617
1618 t = time(NULL);
1619 tm = localtime(&t);
1620 aet->sec = tm->tm_sec;
1621 aet->min = tm->tm_min;
1622 aet->hour = tm->tm_hour;
1623 aet->day = tm->tm_mday;
1624 aet->month = tm->tm_mon;
1625 aet->year = htons(1900 + tm->tm_year);
1626}
1627
Harald Welte05188ee2009-01-18 11:39:08 +00001628int abis_nm_bs11_reset_resource(struct gsm_bts *bts)
Harald Welte52b1f982008-12-23 20:25:15 +00001629{
Harald Welte4668fda2009-01-03 08:19:29 +00001630 return __simple_cmd(bts, NM_MT_BS11_RESET_RESOURCE);
Harald Welte52b1f982008-12-23 20:25:15 +00001631}
1632
Harald Welte05188ee2009-01-18 11:39:08 +00001633int abis_nm_bs11_db_transmission(struct gsm_bts *bts, int begin)
Harald Welte52b1f982008-12-23 20:25:15 +00001634{
1635 if (begin)
Harald Welte4668fda2009-01-03 08:19:29 +00001636 return __simple_cmd(bts, NM_MT_BS11_BEGIN_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00001637 else
Harald Welte4668fda2009-01-03 08:19:29 +00001638 return __simple_cmd(bts, NM_MT_BS11_END_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00001639}
Harald Welte47d88ae2009-01-04 12:02:08 +00001640
Harald Welte05188ee2009-01-18 11:39:08 +00001641int abis_nm_bs11_create_object(struct gsm_bts *bts,
Harald Welte1bc09062009-01-18 14:17:52 +00001642 enum abis_bs11_objtype type, u_int8_t idx,
1643 u_int8_t attr_len, const u_int8_t *attr)
Harald Welte47d88ae2009-01-04 12:02:08 +00001644{
1645 struct abis_om_hdr *oh;
1646 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00001647 u_int8_t *cur;
Harald Welte47d88ae2009-01-04 12:02:08 +00001648
1649 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001650 fill_om_fom_hdr(oh, attr_len, NM_MT_BS11_CREATE_OBJ,
Harald Welte268bb402009-02-01 19:11:56 +00001651 NM_OC_BS11, type, 0, idx);
Harald Welte1bc09062009-01-18 14:17:52 +00001652 cur = msgb_put(msg, attr_len);
1653 memcpy(cur, attr, attr_len);
Harald Welte47d88ae2009-01-04 12:02:08 +00001654
1655 return abis_nm_sendmsg(bts, msg);
1656}
1657
Harald Welte78fc0d42009-02-19 02:50:57 +00001658int abis_nm_bs11_delete_object(struct gsm_bts *bts,
1659 enum abis_bs11_objtype type, u_int8_t idx)
1660{
1661 struct abis_om_hdr *oh;
1662 struct msgb *msg = nm_msgb_alloc();
1663
1664 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1665 fill_om_fom_hdr(oh, 0, NM_MT_BS11_DELETE_OBJ,
1666 NM_OC_BS11, type, 0, idx);
1667
1668 return abis_nm_sendmsg(bts, msg);
1669}
1670
Harald Welte05188ee2009-01-18 11:39:08 +00001671int abis_nm_bs11_create_envaBTSE(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00001672{
1673 struct abis_om_hdr *oh;
1674 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00001675 u_int8_t zero = 0x00;
Harald Welte47d88ae2009-01-04 12:02:08 +00001676
1677 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001678 fill_om_fom_hdr(oh, 3, NM_MT_BS11_CREATE_OBJ,
Harald Welte1bc09062009-01-18 14:17:52 +00001679 NM_OC_BS11_ENVABTSE, 0, idx, 0xff);
1680 msgb_tlv_put(msg, 0x99, 1, &zero);
Harald Welte47d88ae2009-01-04 12:02:08 +00001681
1682 return abis_nm_sendmsg(bts, msg);
1683}
1684
Harald Welte05188ee2009-01-18 11:39:08 +00001685int abis_nm_bs11_create_bport(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00001686{
1687 struct abis_om_hdr *oh;
1688 struct msgb *msg = nm_msgb_alloc();
1689
1690 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1691 fill_om_fom_hdr(oh, 0, NM_MT_BS11_CREATE_OBJ, NM_OC_BS11_BPORT,
1692 idx, 0, 0);
1693
1694 return abis_nm_sendmsg(bts, msg);
1695}
Harald Welte05188ee2009-01-18 11:39:08 +00001696
Harald Welte78fc0d42009-02-19 02:50:57 +00001697static const u_int8_t sm_attr[] = { NM_ATT_TEI, NM_ATT_ABIS_CHANNEL };
1698int abis_nm_bs11_get_oml_tei_ts(struct gsm_bts *bts)
1699{
1700 struct abis_om_hdr *oh;
1701 struct msgb *msg = nm_msgb_alloc();
1702
1703 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1704 fill_om_fom_hdr(oh, 2+sizeof(sm_attr), NM_MT_GET_ATTR, NM_OC_SITE_MANAGER,
1705 0xff, 0xff, 0xff);
1706 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(sm_attr), sm_attr);
1707
1708 return abis_nm_sendmsg(bts, msg);
1709}
1710
Harald Welteb6c92ae2009-02-21 20:15:32 +00001711/* like abis_nm_conn_terr_traf + set_tei */
1712int abis_nm_bs11_conn_oml_tei(struct gsm_bts *bts, u_int8_t e1_port,
1713 u_int8_t e1_timeslot, u_int8_t e1_subslot,
1714 u_int8_t tei)
Harald Welte05188ee2009-01-18 11:39:08 +00001715{
1716 struct abis_om_hdr *oh;
1717 struct abis_nm_channel *ch;
1718 struct msgb *msg = nm_msgb_alloc();
1719
1720 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welteb6c92ae2009-02-21 20:15:32 +00001721 fill_om_fom_hdr(oh, sizeof(*ch)+2, NM_MT_BS11_SET_ATTR,
Harald Welte05188ee2009-01-18 11:39:08 +00001722 NM_OC_SITE_MANAGER, 0xff, 0xff, 0xff);
1723
1724 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1725 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
Harald Welteb6c92ae2009-02-21 20:15:32 +00001726 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte05188ee2009-01-18 11:39:08 +00001727
1728 return abis_nm_sendmsg(bts, msg);
1729}
1730
1731int abis_nm_bs11_set_trx_power(struct gsm_bts_trx *trx, u_int8_t level)
1732{
1733 struct abis_om_hdr *oh;
1734 struct msgb *msg = nm_msgb_alloc();
Harald Welte05188ee2009-01-18 11:39:08 +00001735
1736 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001737 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR,
Harald Welte05188ee2009-01-18 11:39:08 +00001738 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
1739 msgb_tlv_put(msg, NM_ATT_BS11_TXPWR, 1, &level);
1740
1741 return abis_nm_sendmsg(trx->bts, msg);
1742}
1743
Harald Welte78fc0d42009-02-19 02:50:57 +00001744int abis_nm_bs11_get_trx_power(struct gsm_bts_trx *trx)
1745{
1746 struct abis_om_hdr *oh;
1747 struct msgb *msg = nm_msgb_alloc();
1748 u_int8_t attr = NM_ATT_BS11_TXPWR;
1749
1750 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1751 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
1752 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
1753 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), &attr);
1754
1755 return abis_nm_sendmsg(trx->bts, msg);
1756}
1757
Harald Welteaaf02d92009-04-29 13:25:57 +00001758int abis_nm_bs11_get_pll_mode(struct gsm_bts *bts)
1759{
1760 struct abis_om_hdr *oh;
1761 struct msgb *msg = nm_msgb_alloc();
Harald Weltea7cfa032009-04-29 22:33:02 +00001762 u_int8_t attr[] = { NM_ATT_BS11_PLL_MODE };
Harald Welteaaf02d92009-04-29 13:25:57 +00001763
1764 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1765 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
1766 NM_OC_BS11, BS11_OBJ_LI, 0x00, 0x00);
Harald Welteaeedeb42009-05-01 13:08:14 +00001767 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), attr);
Harald Welteaaf02d92009-04-29 13:25:57 +00001768
1769 return abis_nm_sendmsg(bts, msg);
1770}
1771
1772
Harald Welte268bb402009-02-01 19:11:56 +00001773//static const u_int8_t bs11_logon_c7[] = { 0x07, 0xd9, 0x01, 0x11, 0x0d, 0x10, 0x20 };
Harald Weltebb151312009-01-28 20:42:07 +00001774static const u_int8_t bs11_logon_c8[] = { 0x02 };
Harald Welte05188ee2009-01-18 11:39:08 +00001775static const u_int8_t bs11_logon_c9[] = "FACTORY";
1776
Harald Welte1bc09062009-01-18 14:17:52 +00001777int abis_nm_bs11_factory_logon(struct gsm_bts *bts, int on)
Harald Welte05188ee2009-01-18 11:39:08 +00001778{
1779 struct abis_om_hdr *oh;
1780 struct msgb *msg = nm_msgb_alloc();
Harald Welte268bb402009-02-01 19:11:56 +00001781 struct bs11_date_time bdt;
1782
1783 get_bs11_date_time(&bdt);
Harald Welte05188ee2009-01-18 11:39:08 +00001784
1785 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte1bc09062009-01-18 14:17:52 +00001786 if (on) {
Harald Welte268bb402009-02-01 19:11:56 +00001787 u_int8_t len = 3*2 + sizeof(bdt)
Harald Welte6f676a32009-01-18 14:27:48 +00001788 + sizeof(bs11_logon_c8) + sizeof(bs11_logon_c9);
Harald Welte043d04a2009-01-29 23:15:30 +00001789 fill_om_fom_hdr(oh, len, NM_MT_BS11_LMT_LOGON,
Harald Welte1bc09062009-01-18 14:17:52 +00001790 NM_OC_BS11_A3, 0xff, 0xff, 0xff);
Harald Welte043d04a2009-01-29 23:15:30 +00001791 msgb_tlv_put(msg, NM_ATT_BS11_LMT_LOGIN_TIME,
Harald Welte5083b0b2009-02-02 19:20:52 +00001792 sizeof(bdt), (u_int8_t *) &bdt);
Harald Welte043d04a2009-01-29 23:15:30 +00001793 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_ACC_LEV,
1794 sizeof(bs11_logon_c8), bs11_logon_c8);
1795 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_NAME,
1796 sizeof(bs11_logon_c9), bs11_logon_c9);
Harald Welte1bc09062009-01-18 14:17:52 +00001797 } else {
Harald Welte5e4d1b32009-02-01 13:36:56 +00001798 fill_om_fom_hdr(oh, 0, NM_MT_BS11_LMT_LOGOFF,
Harald Welte1bc09062009-01-18 14:17:52 +00001799 NM_OC_BS11_A3, 0xff, 0xff, 0xff);
1800 }
Harald Welte05188ee2009-01-18 11:39:08 +00001801
1802 return abis_nm_sendmsg(bts, msg);
1803}
Harald Welte1bc09062009-01-18 14:17:52 +00001804
1805int abis_nm_bs11_set_trx1_pw(struct gsm_bts *bts, const char *password)
1806{
1807 struct abis_om_hdr *oh;
1808 struct msgb *msg;
1809
1810 if (strlen(password) != 10)
1811 return -EINVAL;
1812
1813 msg = nm_msgb_alloc();
1814 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001815 fill_om_fom_hdr(oh, 2+strlen(password), NM_MT_BS11_SET_ATTR,
Harald Welte1bc09062009-01-18 14:17:52 +00001816 NM_OC_BS11, BS11_OBJ_TRX1, 0x00, 0x00);
1817 msgb_tlv_put(msg, NM_ATT_BS11_PASSWORD, 10, (const u_int8_t *)password);
1818
1819 return abis_nm_sendmsg(bts, msg);
1820}
1821
Harald Weltee69f5fb2009-04-28 16:31:38 +00001822/* change the BS-11 PLL Mode to either locked (E1 derived) or standalone */
1823int abis_nm_bs11_set_pll_locked(struct gsm_bts *bts, int locked)
1824{
1825 struct abis_om_hdr *oh;
1826 struct msgb *msg;
Harald Weltea432cd32009-04-29 13:01:50 +00001827 u_int8_t tlv_value;
Harald Weltee69f5fb2009-04-28 16:31:38 +00001828
1829 msg = nm_msgb_alloc();
1830 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1831 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR, NM_OC_BS11,
1832 BS11_OBJ_LI, 0x00, 0x00);
Harald Weltea432cd32009-04-29 13:01:50 +00001833
1834 if (locked)
1835 tlv_value = BS11_LI_PLL_LOCKED;
1836 else
1837 tlv_value = BS11_LI_PLL_STANDALONE;
1838
1839 msgb_tlv_put(msg, NM_ATT_BS11_PLL_MODE, 1, &tlv_value);
Harald Weltee69f5fb2009-04-28 16:31:38 +00001840
1841 return abis_nm_sendmsg(bts, msg);
1842}
1843
Harald Welte1bc09062009-01-18 14:17:52 +00001844int abis_nm_bs11_get_state(struct gsm_bts *bts)
1845{
1846 return __simple_cmd(bts, NM_MT_BS11_GET_STATE);
1847}
Harald Welte5e4d1b32009-02-01 13:36:56 +00001848
1849/* BS11 SWL */
1850
1851struct abis_nm_bs11_sw {
1852 struct gsm_bts *bts;
1853 char swl_fname[PATH_MAX];
1854 u_int8_t win_size;
Harald Welte3ffd1372009-02-01 22:15:49 +00001855 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001856 struct llist_head file_list;
1857 gsm_cbfn *user_cb; /* specified by the user */
1858};
1859static struct abis_nm_bs11_sw _g_bs11_sw, *g_bs11_sw = &_g_bs11_sw;
1860
1861struct file_list_entry {
1862 struct llist_head list;
1863 char fname[PATH_MAX];
1864};
1865
1866struct file_list_entry *fl_dequeue(struct llist_head *queue)
1867{
1868 struct llist_head *lh;
1869
1870 if (llist_empty(queue))
1871 return NULL;
1872
1873 lh = queue->next;
1874 llist_del(lh);
1875
1876 return llist_entry(lh, struct file_list_entry, list);
1877}
1878
1879static int bs11_read_swl_file(struct abis_nm_bs11_sw *bs11_sw)
1880{
1881 char linebuf[255];
1882 struct llist_head *lh, *lh2;
1883 FILE *swl;
1884 int rc = 0;
1885
1886 swl = fopen(bs11_sw->swl_fname, "r");
1887 if (!swl)
1888 return -ENODEV;
1889
1890 /* zero the stale file list, if any */
1891 llist_for_each_safe(lh, lh2, &bs11_sw->file_list) {
1892 llist_del(lh);
1893 free(lh);
1894 }
1895
1896 while (fgets(linebuf, sizeof(linebuf), swl)) {
1897 char file_id[12+1];
1898 char file_version[80+1];
1899 struct file_list_entry *fle;
1900 static char dir[PATH_MAX];
1901
1902 if (strlen(linebuf) < 4)
1903 continue;
Harald Welte3ffd1372009-02-01 22:15:49 +00001904
Harald Welte5e4d1b32009-02-01 13:36:56 +00001905 rc = sscanf(linebuf+4, "%12s:%80s\r\n", file_id, file_version);
1906 if (rc < 0) {
1907 perror("ERR parsing SWL file");
1908 rc = -EINVAL;
1909 goto out;
1910 }
1911 if (rc < 2)
1912 continue;
1913
1914 fle = malloc(sizeof(*fle));
1915 if (!fle) {
1916 rc = -ENOMEM;
1917 goto out;
1918 }
1919 memset(fle, 0, sizeof(*fle));
1920
1921 /* construct new filename */
1922 strncpy(dir, bs11_sw->swl_fname, sizeof(dir));
1923 strncat(fle->fname, dirname(dir), sizeof(fle->fname) - 1);
1924 strcat(fle->fname, "/");
1925 strncat(fle->fname, file_id, sizeof(fle->fname) - 1 -strlen(fle->fname));
Harald Welte5e4d1b32009-02-01 13:36:56 +00001926
1927 llist_add_tail(&fle->list, &bs11_sw->file_list);
1928 }
1929
1930out:
1931 fclose(swl);
1932 return rc;
1933}
1934
1935/* bs11 swload specific callback, passed to abis_nm core swload */
1936static int bs11_swload_cbfn(unsigned int hook, unsigned int event,
1937 struct msgb *msg, void *data, void *param)
1938{
1939 struct abis_nm_bs11_sw *bs11_sw = data;
1940 struct file_list_entry *fle;
1941 int rc = 0;
1942
Harald Welte5e4d1b32009-02-01 13:36:56 +00001943 switch (event) {
1944 case NM_MT_LOAD_END_ACK:
1945 fle = fl_dequeue(&bs11_sw->file_list);
1946 if (fle) {
1947 /* start download the next file of our file list */
1948 rc = abis_nm_software_load(bs11_sw->bts, fle->fname,
1949 bs11_sw->win_size,
Harald Welte3ffd1372009-02-01 22:15:49 +00001950 bs11_sw->forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00001951 &bs11_swload_cbfn, bs11_sw);
1952 free(fle);
1953 } else {
1954 /* activate the SWL */
1955 rc = abis_nm_software_activate(bs11_sw->bts,
1956 bs11_sw->swl_fname,
1957 bs11_swload_cbfn,
1958 bs11_sw);
1959 }
1960 break;
Harald Welte3ffd1372009-02-01 22:15:49 +00001961 case NM_MT_LOAD_SEG_ACK:
Harald Welte5e4d1b32009-02-01 13:36:56 +00001962 case NM_MT_LOAD_END_NACK:
1963 case NM_MT_LOAD_INIT_ACK:
1964 case NM_MT_LOAD_INIT_NACK:
1965 case NM_MT_ACTIVATE_SW_NACK:
1966 case NM_MT_ACTIVATE_SW_ACK:
1967 default:
1968 /* fallthrough to the user callback */
Harald Welte97ed1e72009-02-06 13:38:02 +00001969 if (bs11_sw->user_cb)
1970 rc = bs11_sw->user_cb(hook, event, msg, NULL, NULL);
Harald Welte5e4d1b32009-02-01 13:36:56 +00001971 break;
1972 }
1973
1974 return rc;
1975}
1976
1977/* Siemens provides a SWL file that is a mere listing of all the other
1978 * files that are part of a software release. We need to upload first
1979 * the list file, and then each file that is listed in the list file */
1980int abis_nm_bs11_load_swl(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00001981 u_int8_t win_size, int forced, gsm_cbfn *cbfn)
Harald Welte5e4d1b32009-02-01 13:36:56 +00001982{
1983 struct abis_nm_bs11_sw *bs11_sw = g_bs11_sw;
1984 struct file_list_entry *fle;
1985 int rc = 0;
1986
1987 INIT_LLIST_HEAD(&bs11_sw->file_list);
1988 bs11_sw->bts = bts;
1989 bs11_sw->win_size = win_size;
1990 bs11_sw->user_cb = cbfn;
Harald Welte3ffd1372009-02-01 22:15:49 +00001991 bs11_sw->forced = forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001992
1993 strncpy(bs11_sw->swl_fname, fname, sizeof(bs11_sw->swl_fname));
1994 rc = bs11_read_swl_file(bs11_sw);
1995 if (rc < 0)
1996 return rc;
1997
1998 /* dequeue next item in file list */
1999 fle = fl_dequeue(&bs11_sw->file_list);
2000 if (!fle)
2001 return -EINVAL;
2002
2003 /* start download the next file of our file list */
Harald Welte3ffd1372009-02-01 22:15:49 +00002004 rc = abis_nm_software_load(bts, fle->fname, win_size, forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00002005 bs11_swload_cbfn, bs11_sw);
2006 free(fle);
2007 return rc;
2008}
2009
Harald Welte5083b0b2009-02-02 19:20:52 +00002010#if 0
Harald Welte5e4d1b32009-02-01 13:36:56 +00002011static u_int8_t req_attr_btse[] = {
2012 NM_ATT_ADM_STATE, NM_ATT_BS11_LMT_LOGON_SESSION,
2013 NM_ATT_BS11_LMT_LOGIN_TIME, NM_ATT_BS11_LMT_USER_ACC_LEV,
2014 NM_ATT_BS11_LMT_USER_NAME,
2015
2016 0xaf, NM_ATT_BS11_RX_OFFSET, NM_ATT_BS11_VENDOR_NAME,
2017
2018 NM_ATT_BS11_SW_LOAD_INTENDED, NM_ATT_BS11_SW_LOAD_SAFETY,
2019
2020 NM_ATT_BS11_SW_LOAD_STORED };
2021
2022static u_int8_t req_attr_btsm[] = {
2023 NM_ATT_ABIS_CHANNEL, NM_ATT_TEI, NM_ATT_BS11_ABIS_EXT_TIME,
2024 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xce, NM_ATT_FILE_ID,
2025 NM_ATT_FILE_VERSION, NM_ATT_OPER_STATE, 0xe8, NM_ATT_BS11_ALL_TEST_CATG,
2026 NM_ATT_SW_DESCR, NM_ATT_GET_ARI };
Harald Welte5083b0b2009-02-02 19:20:52 +00002027#endif
Harald Welte5e4d1b32009-02-01 13:36:56 +00002028
2029static u_int8_t req_attr[] = {
2030 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xa8, NM_ATT_OPER_STATE,
2031 0xd5, 0xa1, NM_ATT_BS11_ESN_FW_CODE_NO, NM_ATT_BS11_ESN_HW_CODE_NO,
Harald Weltea7cfa032009-04-29 22:33:02 +00002032 0x42, NM_ATT_BS11_ESN_PCB_SERIAL, NM_ATT_BS11_PLL };
Harald Welte5e4d1b32009-02-01 13:36:56 +00002033
2034int abis_nm_bs11_get_serno(struct gsm_bts *bts)
2035{
2036 struct abis_om_hdr *oh;
2037 struct msgb *msg = nm_msgb_alloc();
2038
2039 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2040 /* SiemensHW CCTRL object */
2041 fill_om_fom_hdr(oh, 2+sizeof(req_attr), NM_MT_GET_ATTR, NM_OC_BS11,
2042 0x03, 0x00, 0x00);
2043 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(req_attr), req_attr);
2044
2045 return abis_nm_sendmsg(bts, msg);
2046}
Harald Welte268bb402009-02-01 19:11:56 +00002047
2048int abis_nm_bs11_set_ext_time(struct gsm_bts *bts)
2049{
2050 struct abis_om_hdr *oh;
2051 struct msgb *msg = nm_msgb_alloc();
2052 struct bs11_date_time aet;
2053
2054 get_bs11_date_time(&aet);
2055 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2056 /* SiemensHW CCTRL object */
2057 fill_om_fom_hdr(oh, 2+sizeof(aet), NM_MT_BS11_SET_ATTR, NM_OC_SITE_MANAGER,
2058 0xff, 0xff, 0xff);
Harald Welte5083b0b2009-02-02 19:20:52 +00002059 msgb_tlv_put(msg, NM_ATT_BS11_ABIS_EXT_TIME, sizeof(aet), (u_int8_t *) &aet);
Harald Welte268bb402009-02-01 19:11:56 +00002060
2061 return abis_nm_sendmsg(bts, msg);
2062}
Harald Welte5c1e4582009-02-15 11:57:29 +00002063
2064/* ip.access nanoBTS specific commands */
Harald Welte5c1e4582009-02-15 11:57:29 +00002065static const char ipaccess_magic[] = "com.ipaccess";
2066
Harald Welte677c21f2009-02-17 13:22:23 +00002067
2068static int abis_nm_rx_ipacc(struct msgb *msg)
2069{
2070 struct abis_om_hdr *oh = msgb_l2(msg);
2071 struct abis_om_fom_hdr *foh;
2072 u_int8_t idstrlen = oh->data[0];
2073 struct tlv_parsed tp;
2074
2075 if (strncmp((char *)&oh->data[1], ipaccess_magic, idstrlen)) {
2076 DEBUGP(DNM, "id string is not com.ipaccess !?!\n");
2077 return -EINVAL;
2078 }
2079
Harald Welte193fefc2009-04-30 15:16:27 +00002080 foh = (struct abis_om_fom_hdr *) (oh->data + 1 + idstrlen);
Harald Welte03133942009-02-18 19:51:53 +00002081 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Welte677c21f2009-02-17 13:22:23 +00002082
Harald Welte193fefc2009-04-30 15:16:27 +00002083 DEBUGP(DNM, "IPACCESS(0x%02x): ", foh->msg_type);
2084
Harald Welte677c21f2009-02-17 13:22:23 +00002085 switch (foh->msg_type) {
2086 case NM_MT_IPACC_RSL_CONNECT_ACK:
Harald Welte193fefc2009-04-30 15:16:27 +00002087 DEBUGPC(DNM, "RSL CONNECT ACK ");
Harald Welte677c21f2009-02-17 13:22:23 +00002088 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_RSL_BSC_IP))
Harald Welte9de2bf82009-04-30 15:59:55 +00002089 DEBUGPC(DNM, "IP=%s ",
Harald Welte677c21f2009-02-17 13:22:23 +00002090 inet_ntoa(*((struct in_addr *)
2091 TLVP_VAL(&tp, NM_ATT_IPACC_RSL_BSC_IP))));
2092 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_RSL_BSC_PORT))
Harald Welte9de2bf82009-04-30 15:59:55 +00002093 DEBUGPC(DNM, "PORT=%u ",
Harald Welte677c21f2009-02-17 13:22:23 +00002094 ntohs(*((u_int16_t *)
2095 TLVP_VAL(&tp, NM_ATT_IPACC_RSL_BSC_PORT))));
Harald Welte9de2bf82009-04-30 15:59:55 +00002096 DEBUGPC(DNM, "\n");
Harald Welte677c21f2009-02-17 13:22:23 +00002097 break;
2098 case NM_MT_IPACC_RSL_CONNECT_NACK:
Harald Welte193fefc2009-04-30 15:16:27 +00002099 DEBUGPC(DNM, "RSL CONNECT NACK ");
Harald Welte677c21f2009-02-17 13:22:23 +00002100 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
Harald Welte6c96ba52009-05-01 13:03:40 +00002101 DEBUGPC(DNM, " CAUSE=%s\n",
2102 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
Harald Welte677c21f2009-02-17 13:22:23 +00002103 else
2104 DEBUGPC(DNM, "\n");
2105 break;
Harald Welte193fefc2009-04-30 15:16:27 +00002106 case NM_MT_IPACC_SET_NVATTR_ACK:
2107 DEBUGPC(DNM, "SET NVATTR ACK\n");
2108 /* FIXME: decode and show the actual attributes */
2109 break;
2110 case NM_MT_IPACC_SET_NVATTR_NACK:
Harald Welte6c96ba52009-05-01 13:03:40 +00002111 DEBUGPC(DNM, "SET NVATTR NACK ");
2112 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
2113 DEBUGPC(DNM, " CAUSE=%s\n",
2114 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
2115 else
2116 DEBUGPC(DNM, "\n");
Harald Welte193fefc2009-04-30 15:16:27 +00002117 break;
2118 default:
2119 DEBUGPC(DNM, "unknown\n");
2120 break;
Harald Welte677c21f2009-02-17 13:22:23 +00002121 }
2122 return 0;
2123}
2124
Harald Welte193fefc2009-04-30 15:16:27 +00002125/* send an ip-access manufacturer specific message */
Harald Welte5c1e4582009-02-15 11:57:29 +00002126int abis_nm_ipaccess_msg(struct gsm_bts *bts, u_int8_t msg_type,
2127 u_int8_t obj_class, u_int8_t bts_nr,
2128 u_int8_t trx_nr, u_int8_t ts_nr,
2129 u_int8_t *attr, int attr_len)
2130{
2131 struct msgb *msg = nm_msgb_alloc();
2132 struct abis_om_hdr *oh;
2133 struct abis_om_fom_hdr *foh;
2134 u_int8_t *data;
2135
2136 /* construct the 12.21 OM header, observe the erroneous length */
2137 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
2138 fill_om_hdr(oh, sizeof(*foh) + attr_len);
2139 oh->mdisc = ABIS_OM_MDISC_MANUF;
2140
2141 /* add the ip.access magic */
2142 data = msgb_put(msg, sizeof(ipaccess_magic)+1);
2143 *data++ = sizeof(ipaccess_magic);
2144 memcpy(data, ipaccess_magic, sizeof(ipaccess_magic));
2145
2146 /* fill the 12.21 FOM header */
2147 foh = (struct abis_om_fom_hdr *) msgb_put(msg, sizeof(*foh));
2148 foh->msg_type = msg_type;
2149 foh->obj_class = obj_class;
2150 foh->obj_inst.bts_nr = bts_nr;
2151 foh->obj_inst.trx_nr = trx_nr;
2152 foh->obj_inst.ts_nr = ts_nr;
2153
2154 if (attr && attr_len) {
2155 data = msgb_put(msg, attr_len);
2156 memcpy(data, attr, attr_len);
2157 }
2158
2159 return abis_nm_sendmsg(bts, msg);
2160}
Harald Welte677c21f2009-02-17 13:22:23 +00002161
Harald Welte193fefc2009-04-30 15:16:27 +00002162/* set some attributes in NVRAM */
2163int abis_nm_ipaccess_set_nvattr(struct gsm_bts *bts, u_int8_t *attr,
2164 int attr_len)
2165{
2166 return abis_nm_ipaccess_msg(bts, NM_MT_IPACC_SET_NVATTR,
2167 NM_OC_BASEB_TRANSC, 0, 0, 0xff, attr,
2168 attr_len);
2169}
2170
2171/* restart / reboot an ip.access nanoBTS */
2172int abis_nm_ipaccess_restart(struct gsm_bts *bts)
2173{
2174 return __simple_cmd(bts, NM_MT_IPACC_RESTART);
2175}