blob: d6bfd4ecd4fa917d3a2f52157b9437da1be37c46 [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{
532 struct gsm_nm_state *nm_state;
533 void *obj;
534 int rc;
535
536 nm_state = objclass2nmstate(bts, obj_class, obj_inst);
537 obj = objclass2obj(bts, obj_class, obj_inst);
538 rc = nm_state_event(EVT_STATECHG_ADM, obj_class, obj, nm_state, adm_state);
539 if (nm_state)
540 nm_state->administrative = adm_state;
541
542 return rc;
543}
544
Harald Welte97ed1e72009-02-06 13:38:02 +0000545static int abis_nm_rx_statechg_rep(struct msgb *mb)
546{
Harald Weltee0590df2009-02-15 03:34:15 +0000547 struct abis_om_hdr *oh = msgb_l2(mb);
Harald Welte97ed1e72009-02-06 13:38:02 +0000548 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Harald Welte22af0db2009-02-14 15:41:08 +0000549 struct gsm_bts *bts = mb->trx->bts;
Harald Weltee0590df2009-02-15 03:34:15 +0000550 struct tlv_parsed tp;
551 struct gsm_nm_state *nm_state, new_state;
552 int rc;
553
Harald Welte34a99682009-02-13 02:41:40 +0000554 DEBUGP(DNM, "STATE CHG: OC=%s(%02x) INST=(%02x,%02x,%02x) ",
555 obj_class_name(foh->obj_class), foh->obj_class,
556 foh->obj_inst.bts_nr, foh->obj_inst.trx_nr,
Harald Welte97ed1e72009-02-06 13:38:02 +0000557 foh->obj_inst.ts_nr);
Harald Weltee0590df2009-02-15 03:34:15 +0000558
559 nm_state = objclass2nmstate(bts, foh->obj_class, &foh->obj_inst);
560 if (!nm_state) {
561 DEBUGPC(DNM, "\n");
562 return -EINVAL;
Harald Welte22af0db2009-02-14 15:41:08 +0000563 }
Harald Weltee0590df2009-02-15 03:34:15 +0000564
565 new_state = *nm_state;
566
Harald Welte03133942009-02-18 19:51:53 +0000567 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Weltee0590df2009-02-15 03:34:15 +0000568 if (TLVP_PRESENT(&tp, NM_ATT_OPER_STATE)) {
569 new_state.operational = *TLVP_VAL(&tp, NM_ATT_OPER_STATE);
Harald Welte4d87f242009-03-10 19:43:44 +0000570 DEBUGPC(DNM, "OP_STATE=%s ", nm_opstate_name(new_state.operational));
Harald Weltee0590df2009-02-15 03:34:15 +0000571 }
572 if (TLVP_PRESENT(&tp, NM_ATT_AVAIL_STATUS)) {
Harald Welte0b8348d2009-02-18 03:43:01 +0000573 if (TLVP_LEN(&tp, NM_ATT_AVAIL_STATUS) == 0)
574 new_state.availability = 0xff;
575 else
576 new_state.availability = *TLVP_VAL(&tp, NM_ATT_AVAIL_STATUS);
Harald Welte4d87f242009-03-10 19:43:44 +0000577 DEBUGPC(DNM, "AVAIL=%s(%02x) ", nm_avail_name(new_state.availability),
Harald Weltee0590df2009-02-15 03:34:15 +0000578 new_state.availability);
579 }
580 if (TLVP_PRESENT(&tp, NM_ATT_ADM_STATE)) {
581 new_state.administrative = *TLVP_VAL(&tp, NM_ATT_ADM_STATE);
582 DEBUGPC(DNM, "ADM=%02x ", new_state.administrative);
Harald Welte97ed1e72009-02-06 13:38:02 +0000583 }
584 DEBUGPC(DNM, "\n");
Harald Weltee0590df2009-02-15 03:34:15 +0000585
586 if (memcmp(&new_state, nm_state, sizeof(new_state))) {
587 /* Update the operational state of a given object in our in-memory data
588 * structures and send an event to the higher layer */
589 void *obj = objclass2obj(bts, foh->obj_class, &foh->obj_inst);
590 rc = nm_state_event(EVT_STATECHG_OPER, foh->obj_class, obj, nm_state, &new_state);
591 *nm_state = new_state;
592 }
593#if 0
Harald Welte22af0db2009-02-14 15:41:08 +0000594 if (op_state == 1) {
595 /* try to enable objects that are disabled */
596 abis_nm_opstart(bts, foh->obj_class,
597 foh->obj_inst.bts_nr,
598 foh->obj_inst.trx_nr,
599 foh->obj_inst.ts_nr);
600 }
Harald Weltee0590df2009-02-15 03:34:15 +0000601#endif
Harald Welte97ed1e72009-02-06 13:38:02 +0000602 return 0;
603}
604
605static int abis_nm_rcvmsg_report(struct msgb *mb)
606{
607 struct abis_om_fom_hdr *foh = msgb_l3(mb);
608 u_int8_t mt = foh->msg_type;
609
610 //nmh->cfg->report_cb(mb, foh);
611
612 switch (mt) {
613 case NM_MT_STATECHG_EVENT_REP:
614 return abis_nm_rx_statechg_rep(mb);
615 break;
Harald Welte34a99682009-02-13 02:41:40 +0000616 case NM_MT_SW_ACTIVATED_REP:
617 DEBUGP(DNM, "Software Activated Report\n");
618 break;
Harald Weltee0590df2009-02-15 03:34:15 +0000619 case NM_MT_FAILURE_EVENT_REP:
620 DEBUGP(DNM, "Failure Event Report\n");
621 break;
622 default:
623 DEBUGP(DNM, "reporting NM MT 0x%02x\n", mt);
624 break;
625
Harald Welte97ed1e72009-02-06 13:38:02 +0000626 };
627
Harald Welte97ed1e72009-02-06 13:38:02 +0000628 return 0;
629}
630
Harald Welte34a99682009-02-13 02:41:40 +0000631/* Activate the specified software into the BTS */
632static int ipacc_sw_activate(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1,
633 u_int8_t i2, u_int8_t *sw_desc, u_int8_t swdesc_len)
634{
635 struct abis_om_hdr *oh;
636 struct msgb *msg = nm_msgb_alloc();
637 u_int8_t len = swdesc_len;
638 u_int8_t *trailer;
639
640 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
641 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, obj_class, i0, i1, i2);
642
643 trailer = msgb_put(msg, swdesc_len);
644 memcpy(trailer, sw_desc, swdesc_len);
645
646 return abis_nm_sendmsg(bts, msg);
647}
648
649static int abis_nm_rx_sw_act_req(struct msgb *mb)
650{
651 struct abis_om_hdr *oh = msgb_l2(mb);
652 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Harald Welte5c1e4582009-02-15 11:57:29 +0000653 int nack = 0;
Harald Welte34a99682009-02-13 02:41:40 +0000654 int ret;
655
Harald Welte5c1e4582009-02-15 11:57:29 +0000656 DEBUGP(DNM, "Software Activate Request ");
Harald Welte34a99682009-02-13 02:41:40 +0000657
Harald Welte5c1e4582009-02-15 11:57:29 +0000658 if (foh->obj_class >= 0xf0 && foh->obj_class <= 0xf3) {
659 DEBUGPC(DNM, "NACKing for GPRS obj_class 0x%02x\n", foh->obj_class);
660 nack = 1;
661 } else
662 DEBUGPC(DNM, "ACKing and Activating\n");
663
664 ret = abis_nm_sw_act_req_ack(mb->trx->bts, foh->obj_class,
Harald Welte34a99682009-02-13 02:41:40 +0000665 foh->obj_inst.bts_nr,
666 foh->obj_inst.trx_nr,
Harald Welte5c1e4582009-02-15 11:57:29 +0000667 foh->obj_inst.ts_nr, nack,
Harald Welte34a99682009-02-13 02:41:40 +0000668 foh->data, oh->length-sizeof(*foh));
669
Harald Welte5c1e4582009-02-15 11:57:29 +0000670 if (nack)
671 return ret;
672
Harald Welte34a99682009-02-13 02:41:40 +0000673 /* FIXME: properly parse attributes */
674 return ipacc_sw_activate(mb->trx->bts, foh->obj_class,
675 foh->obj_inst.bts_nr,
676 foh->obj_inst.trx_nr,
677 foh->obj_inst.ts_nr,
678 foh->data + oh->length-sizeof(*foh)-22, 22);
679}
680
Harald Weltee0590df2009-02-15 03:34:15 +0000681/* Receive a CHANGE_ADM_STATE_ACK, parse the TLV and update local state */
682static int abis_nm_rx_chg_adm_state_ack(struct msgb *mb)
683{
684 struct abis_om_hdr *oh = msgb_l2(mb);
685 struct abis_om_fom_hdr *foh = msgb_l3(mb);
686 struct tlv_parsed tp;
687 u_int8_t adm_state;
688
Harald Welte03133942009-02-18 19:51:53 +0000689 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Weltee0590df2009-02-15 03:34:15 +0000690 if (!TLVP_PRESENT(&tp, NM_ATT_ADM_STATE))
691 return -EINVAL;
692
693 adm_state = *TLVP_VAL(&tp, NM_ATT_ADM_STATE);
694
695 return update_admstate(mb->trx->bts, foh->obj_class, &foh->obj_inst, adm_state);
696}
697
Harald Welteee670472009-02-22 21:58:49 +0000698static int abis_nm_rx_lmt_event(struct msgb *mb)
699{
700 struct abis_om_hdr *oh = msgb_l2(mb);
701 struct abis_om_fom_hdr *foh = msgb_l3(mb);
702 struct tlv_parsed tp;
703
704 DEBUGP(DNM, "LMT Event ");
705 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
706 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_LOGON_SESSION) &&
707 TLVP_LEN(&tp, NM_ATT_BS11_LMT_LOGON_SESSION) >= 1) {
708 u_int8_t onoff = *TLVP_VAL(&tp, NM_ATT_BS11_LMT_LOGON_SESSION);
709 DEBUGPC(DNM, "LOG%s ", onoff ? "ON" : "OFF");
710 }
711 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV) &&
712 TLVP_LEN(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV) >= 1) {
713 u_int8_t level = *TLVP_VAL(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV);
714 DEBUGPC(DNM, "Level=%u ", level);
715 }
716 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_USER_NAME) &&
717 TLVP_LEN(&tp, NM_ATT_BS11_LMT_USER_NAME) >= 1) {
718 char *name = (char *) TLVP_VAL(&tp, NM_ATT_BS11_LMT_USER_NAME);
719 DEBUGPC(DNM, "Username=%s ", name);
720 }
721 DEBUGPC(DNM, "\n");
722 /* FIXME: parse LMT LOGON TIME */
723 return 0;
724}
725
Harald Welte52b1f982008-12-23 20:25:15 +0000726/* Receive a OML NM Message from BTS */
Harald Welte8470bf22008-12-25 23:28:35 +0000727static int abis_nm_rcvmsg_fom(struct msgb *mb)
Harald Welte52b1f982008-12-23 20:25:15 +0000728{
Harald Welte6c96ba52009-05-01 13:03:40 +0000729 struct abis_om_hdr *oh = msgb_l2(mb);
Harald Welte52b1f982008-12-23 20:25:15 +0000730 struct abis_om_fom_hdr *foh = msgb_l3(mb);
731 u_int8_t mt = foh->msg_type;
732
733 /* check for unsolicited message */
Harald Welte97ed1e72009-02-06 13:38:02 +0000734 if (is_report(mt))
735 return abis_nm_rcvmsg_report(mb);
Harald Welte52b1f982008-12-23 20:25:15 +0000736
Harald Welte4724f992009-01-18 18:01:49 +0000737 if (is_in_arr(mt, sw_load_msgs, ARRAY_SIZE(sw_load_msgs)))
738 return abis_nm_rcvmsg_sw(mb);
739
Harald Welte78fc0d42009-02-19 02:50:57 +0000740 if (is_in_arr(mt, nacks, ARRAY_SIZE(nacks))) {
Harald Welte6c96ba52009-05-01 13:03:40 +0000741 struct tlv_parsed tp;
Harald Welte78fc0d42009-02-19 02:50:57 +0000742 if (nack_names[mt])
Harald Welte6c96ba52009-05-01 13:03:40 +0000743 DEBUGP(DNM, "%s NACK ", nack_names[mt]);
744 /* FIXME: NACK cause */
Harald Welte78fc0d42009-02-19 02:50:57 +0000745 else
Harald Welte6c96ba52009-05-01 13:03:40 +0000746 DEBUGP(DNM, "NACK 0x%02x ", mt);
747
748 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
749 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
750 DEBUGPC(DNM, "CAUSE=%s\n",
751 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
752 else
753 DEBUGPC(DNM, "\n");
Harald Welte78fc0d42009-02-19 02:50:57 +0000754 }
Harald Weltead384642008-12-26 10:20:07 +0000755#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000756 /* check if last message is to be acked */
757 if (is_ack_nack(nmh->last_msgtype)) {
758 if (mt == MT_ACK(nmh->last_msgtype)) {
759 fprintf(stderr, "received ACK (0x%x)\n",
760 foh->msg_type);
761 /* we got our ACK, continue sending the next msg */
762 } else if (mt == MT_NACK(nmh->last_msgtype)) {
763 /* we got a NACK, signal this to the caller */
764 fprintf(stderr, "received NACK (0x%x)\n",
765 foh->msg_type);
766 /* FIXME: somehow signal this to the caller */
767 } else {
768 /* really strange things happen */
769 return -EINVAL;
770 }
771 }
Harald Weltead384642008-12-26 10:20:07 +0000772#endif
773
Harald Welte97ed1e72009-02-06 13:38:02 +0000774 switch (mt) {
Harald Weltee0590df2009-02-15 03:34:15 +0000775 case NM_MT_CHG_ADM_STATE_ACK:
776 return abis_nm_rx_chg_adm_state_ack(mb);
777 break;
Harald Welte34a99682009-02-13 02:41:40 +0000778 case NM_MT_SW_ACT_REQ:
779 return abis_nm_rx_sw_act_req(mb);
780 break;
Harald Welte97ed1e72009-02-06 13:38:02 +0000781 case NM_MT_BS11_LMT_SESSION:
Harald Welteee670472009-02-22 21:58:49 +0000782 return abis_nm_rx_lmt_event(mb);
Harald Welte97ed1e72009-02-06 13:38:02 +0000783 break;
784 }
785
Harald Weltead384642008-12-26 10:20:07 +0000786 return 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000787}
788
Harald Welte677c21f2009-02-17 13:22:23 +0000789static int abis_nm_rx_ipacc(struct msgb *mb);
790
791static int abis_nm_rcvmsg_manuf(struct msgb *mb)
792{
793 int rc;
794 int bts_type = mb->trx->bts->type;
795
796 switch (bts_type) {
797 case GSM_BTS_TYPE_NANOBTS_900:
798 case GSM_BTS_TYPE_NANOBTS_1800:
799 rc = abis_nm_rx_ipacc(mb);
800 break;
801 default:
802 fprintf(stderr, "don't know how to parse OML for this "
803 "BTS type (%u)\n", bts_type);
804 rc = 0;
805 break;
806 }
807
808 return rc;
809}
810
Harald Welte52b1f982008-12-23 20:25:15 +0000811/* High-Level API */
812/* Entry-point where L2 OML from BTS enters the NM code */
Harald Welte8470bf22008-12-25 23:28:35 +0000813int abis_nm_rcvmsg(struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +0000814{
Harald Welte52b1f982008-12-23 20:25:15 +0000815 struct abis_om_hdr *oh = msgb_l2(msg);
Harald Welte677c21f2009-02-17 13:22:23 +0000816 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000817
818 /* Various consistency checks */
819 if (oh->placement != ABIS_OM_PLACEMENT_ONLY) {
820 fprintf(stderr, "ABIS OML placement 0x%x not supported\n",
821 oh->placement);
822 return -EINVAL;
823 }
824 if (oh->sequence != 0) {
825 fprintf(stderr, "ABIS OML sequence 0x%x != 0x00\n",
826 oh->sequence);
827 return -EINVAL;
828 }
Harald Welte702d8702008-12-26 20:25:35 +0000829#if 0
Holger Freytherca362a62009-01-04 21:05:01 +0000830 unsigned int l2_len = msg->tail - (u_int8_t *)msgb_l2(msg);
831 unsigned int hlen = sizeof(*oh) + sizeof(struct abis_om_fom_hdr);
Harald Welte702d8702008-12-26 20:25:35 +0000832 if (oh->length + hlen > l2_len) {
Harald Welte52b1f982008-12-23 20:25:15 +0000833 fprintf(stderr, "ABIS OML truncated message (%u > %u)\n",
834 oh->length + sizeof(*oh), l2_len);
835 return -EINVAL;
836 }
Harald Welte702d8702008-12-26 20:25:35 +0000837 if (oh->length + hlen < l2_len)
838 fprintf(stderr, "ABIS OML message with extra trailer?!? (oh->len=%d, sizeof_oh=%d l2_len=%d\n", oh->length, sizeof(*oh), l2_len);
839#endif
Harald Weltead384642008-12-26 10:20:07 +0000840 msg->l3h = (unsigned char *)oh + sizeof(*oh);
Harald Welte52b1f982008-12-23 20:25:15 +0000841
842 switch (oh->mdisc) {
843 case ABIS_OM_MDISC_FOM:
Harald Welte8470bf22008-12-25 23:28:35 +0000844 rc = abis_nm_rcvmsg_fom(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000845 break;
Harald Welte677c21f2009-02-17 13:22:23 +0000846 case ABIS_OM_MDISC_MANUF:
847 rc = abis_nm_rcvmsg_manuf(msg);
848 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000849 case ABIS_OM_MDISC_MMI:
850 case ABIS_OM_MDISC_TRAU:
Harald Welte677c21f2009-02-17 13:22:23 +0000851 fprintf(stderr, "unimplemented ABIS OML message discriminator 0x%x\n",
852 oh->mdisc);
853 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000854 default:
855 fprintf(stderr, "unknown ABIS OML message discriminator 0x%x\n",
856 oh->mdisc);
857 return -EINVAL;
858 }
859
Harald Weltead384642008-12-26 10:20:07 +0000860 msgb_free(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000861 return rc;
862}
863
864#if 0
865/* initialized all resources */
866struct abis_nm_h *abis_nm_init(struct abis_nm_cfg *cfg)
867{
868 struct abis_nm_h *nmh;
869
870 nmh = malloc(sizeof(*nmh));
871 if (!nmh)
872 return NULL;
873
874 nmh->cfg = cfg;
875
876 return nmh;
877}
878
879/* free all resources */
880void abis_nm_fini(struct abis_nm_h *nmh)
881{
882 free(nmh);
883}
884#endif
885
886/* Here we are trying to define a high-level API that can be used by
887 * the actual BSC implementation. However, the architecture is currently
888 * still under design. Ideally the calls to this API would be synchronous,
889 * while the underlying stack behind the APi runs in a traditional select
890 * based state machine.
891 */
892
Harald Welte4724f992009-01-18 18:01:49 +0000893/* 6.2 Software Load: */
894enum sw_state {
895 SW_STATE_NONE,
896 SW_STATE_WAIT_INITACK,
897 SW_STATE_WAIT_SEGACK,
898 SW_STATE_WAIT_ENDACK,
899 SW_STATE_WAIT_ACTACK,
900 SW_STATE_ERROR,
901};
Harald Welte52b1f982008-12-23 20:25:15 +0000902
Harald Welte52b1f982008-12-23 20:25:15 +0000903struct abis_nm_sw {
Harald Welte4724f992009-01-18 18:01:49 +0000904 struct gsm_bts *bts;
Harald Welte5e4d1b32009-02-01 13:36:56 +0000905 gsm_cbfn *cbfn;
906 void *cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +0000907 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +0000908
Harald Welte52b1f982008-12-23 20:25:15 +0000909 /* this will become part of the SW LOAD INITIATE */
910 u_int8_t obj_class;
911 u_int8_t obj_instance[3];
Harald Welte4724f992009-01-18 18:01:49 +0000912
913 u_int8_t file_id[255];
914 u_int8_t file_id_len;
915
916 u_int8_t file_version[255];
917 u_int8_t file_version_len;
918
919 u_int8_t window_size;
920 u_int8_t seg_in_window;
921
922 int fd;
923 FILE *stream;
924 enum sw_state state;
Harald Welte1602ade2009-01-29 21:12:39 +0000925 int last_seg;
Harald Welte52b1f982008-12-23 20:25:15 +0000926};
927
Harald Welte4724f992009-01-18 18:01:49 +0000928static struct abis_nm_sw g_sw;
929
930/* 6.2.1 / 8.3.1: Load Data Initiate */
931static int sw_load_init(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +0000932{
Harald Welte4724f992009-01-18 18:01:49 +0000933 struct abis_om_hdr *oh;
934 struct msgb *msg = nm_msgb_alloc();
935 u_int8_t len = 3*2 + sw->file_id_len + sw->file_version_len;
936
937 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
938 fill_om_fom_hdr(oh, len, NM_MT_LOAD_INIT, sw->obj_class,
939 sw->obj_instance[0], sw->obj_instance[1],
940 sw->obj_instance[2]);
941
942 /* FIXME: this is BS11 specific format */
943 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
944 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
945 sw->file_version);
946 msgb_tv_put(msg, NM_ATT_WINDOW_SIZE, sw->window_size);
947
948 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000949}
950
Harald Welte1602ade2009-01-29 21:12:39 +0000951static int is_last_line(FILE *stream)
952{
953 char next_seg_buf[256];
954 long pos;
955
956 /* check if we're sending the last line */
957 pos = ftell(stream);
958 if (!fgets(next_seg_buf, sizeof(next_seg_buf)-2, stream)) {
959 fseek(stream, pos, SEEK_SET);
960 return 1;
961 }
962
963 fseek(stream, pos, SEEK_SET);
964 return 0;
965}
966
Harald Welte4724f992009-01-18 18:01:49 +0000967/* 6.2.2 / 8.3.2 Load Data Segment */
968static int sw_load_segment(struct abis_nm_sw *sw)
969{
970 struct abis_om_hdr *oh;
971 struct msgb *msg = nm_msgb_alloc();
972 char seg_buf[256];
973 char *line_buf = seg_buf+2;
Harald Welte3b8ba212009-01-29 12:27:58 +0000974 unsigned char *tlv;
Harald Welte4724f992009-01-18 18:01:49 +0000975 u_int8_t len;
Harald Welte4724f992009-01-18 18:01:49 +0000976
977 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte3b8ba212009-01-29 12:27:58 +0000978
979 switch (sw->bts->type) {
980 case GSM_BTS_TYPE_BS11:
981 if (fgets(line_buf, sizeof(seg_buf)-2, sw->stream) == NULL) {
982 perror("fgets reading segment");
983 return -EINVAL;
984 }
985 seg_buf[0] = 0x00;
Harald Welte1602ade2009-01-29 21:12:39 +0000986
987 /* check if we're sending the last line */
988 sw->last_seg = is_last_line(sw->stream);
989 if (sw->last_seg)
990 seg_buf[1] = 0;
991 else
992 seg_buf[1] = 1 + sw->seg_in_window++;
Harald Welte3b8ba212009-01-29 12:27:58 +0000993
994 len = strlen(line_buf) + 2;
995 tlv = msgb_put(msg, TLV_GROSS_LEN(len));
996 tlv_put(tlv, NM_ATT_BS11_FILE_DATA, len, (u_int8_t *)seg_buf);
997 /* BS11 wants CR + LF in excess of the TLV length !?! */
998 tlv[1] -= 2;
999
1000 /* we only now know the exact length for the OM hdr */
1001 len = strlen(line_buf)+2;
1002 break;
1003 default:
1004 /* FIXME: Other BTS types */
1005 return -1;
Harald Welte4724f992009-01-18 18:01:49 +00001006 }
Harald Welte4724f992009-01-18 18:01:49 +00001007
Harald Welte4724f992009-01-18 18:01:49 +00001008 fill_om_fom_hdr(oh, len, NM_MT_LOAD_SEG, sw->obj_class,
1009 sw->obj_instance[0], sw->obj_instance[1],
1010 sw->obj_instance[2]);
1011
1012 return abis_nm_sendmsg(sw->bts, msg);
1013}
1014
1015/* 6.2.4 / 8.3.4 Load Data End */
1016static int sw_load_end(struct abis_nm_sw *sw)
1017{
1018 struct abis_om_hdr *oh;
1019 struct msgb *msg = nm_msgb_alloc();
1020 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
1021
1022 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1023 fill_om_fom_hdr(oh, len, NM_MT_LOAD_END, sw->obj_class,
1024 sw->obj_instance[0], sw->obj_instance[1],
1025 sw->obj_instance[2]);
1026
1027 /* FIXME: this is BS11 specific format */
1028 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1029 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1030 sw->file_version);
1031
1032 return abis_nm_sendmsg(sw->bts, msg);
1033}
Harald Welte5e4d1b32009-02-01 13:36:56 +00001034
Harald Welte52b1f982008-12-23 20:25:15 +00001035/* Activate the specified software into the BTS */
Harald Welte4724f992009-01-18 18:01:49 +00001036static int sw_activate(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +00001037{
Harald Welte4724f992009-01-18 18:01:49 +00001038 struct abis_om_hdr *oh;
1039 struct msgb *msg = nm_msgb_alloc();
1040 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
Harald Welte52b1f982008-12-23 20:25:15 +00001041
Harald Welte4724f992009-01-18 18:01:49 +00001042 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1043 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, sw->obj_class,
1044 sw->obj_instance[0], sw->obj_instance[1],
1045 sw->obj_instance[2]);
1046
1047 /* FIXME: this is BS11 specific format */
1048 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1049 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1050 sw->file_version);
1051
1052 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001053}
Harald Welte4724f992009-01-18 18:01:49 +00001054
1055static int sw_open_file(struct abis_nm_sw *sw, const char *fname)
1056{
1057 char file_id[12+1];
1058 char file_version[80+1];
1059 int rc;
1060
1061 sw->fd = open(fname, O_RDONLY);
1062 if (sw->fd < 0)
1063 return sw->fd;
1064
1065 switch (sw->bts->type) {
1066 case GSM_BTS_TYPE_BS11:
1067 sw->stream = fdopen(sw->fd, "r");
1068 if (!sw->stream) {
1069 perror("fdopen");
1070 return -1;
1071 }
1072 /* read first line and parse file ID and VERSION */
Harald Welte3b8ba212009-01-29 12:27:58 +00001073 rc = fscanf(sw->stream, "@(#)%12s:%80s\r\n",
Harald Welte4724f992009-01-18 18:01:49 +00001074 file_id, file_version);
1075 if (rc != 2) {
1076 perror("parsing header line of software file");
1077 return -1;
1078 }
1079 strcpy((char *)sw->file_id, file_id);
1080 sw->file_id_len = strlen(file_id);
1081 strcpy((char *)sw->file_version, file_version);
1082 sw->file_version_len = strlen(file_version);
1083 /* rewind to start of file */
Harald Welte3b8ba212009-01-29 12:27:58 +00001084 rewind(sw->stream);
Harald Welte4724f992009-01-18 18:01:49 +00001085 break;
1086 default:
1087 /* We don't know how to treat them yet */
1088 close(sw->fd);
1089 return -EINVAL;
1090 }
1091
1092 return 0;
1093}
1094
1095static void sw_close_file(struct abis_nm_sw *sw)
1096{
1097 switch (sw->bts->type) {
1098 case GSM_BTS_TYPE_BS11:
1099 fclose(sw->stream);
1100 break;
1101 default:
1102 close(sw->fd);
1103 break;
1104 }
1105}
1106
1107/* Fill the window */
1108static int sw_fill_window(struct abis_nm_sw *sw)
1109{
1110 int rc;
1111
1112 while (sw->seg_in_window < sw->window_size) {
1113 rc = sw_load_segment(sw);
1114 if (rc < 0)
1115 return rc;
Harald Welte1602ade2009-01-29 21:12:39 +00001116 if (sw->last_seg)
1117 break;
Harald Welte4724f992009-01-18 18:01:49 +00001118 }
1119 return 0;
1120}
1121
1122/* callback function from abis_nm_rcvmsg() handler */
1123static int abis_nm_rcvmsg_sw(struct msgb *mb)
1124{
1125 struct abis_om_fom_hdr *foh = msgb_l3(mb);
1126 int rc = -1;
1127 struct abis_nm_sw *sw = &g_sw;
1128 enum sw_state old_state = sw->state;
1129
Harald Welte3ffd1372009-02-01 22:15:49 +00001130 //DEBUGP(DNM, "state %u, NM MT 0x%02x\n", sw->state, foh->msg_type);
Harald Welte4724f992009-01-18 18:01:49 +00001131
1132 switch (sw->state) {
1133 case SW_STATE_WAIT_INITACK:
1134 switch (foh->msg_type) {
1135 case NM_MT_LOAD_INIT_ACK:
1136 /* fill window with segments */
Harald Welte5e4d1b32009-02-01 13:36:56 +00001137 if (sw->cbfn)
1138 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1139 NM_MT_LOAD_INIT_ACK, mb,
1140 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001141 rc = sw_fill_window(sw);
1142 sw->state = SW_STATE_WAIT_SEGACK;
1143 break;
1144 case NM_MT_LOAD_INIT_NACK:
Harald Welte3ffd1372009-02-01 22:15:49 +00001145 if (sw->forced) {
1146 DEBUGP(DNM, "FORCED: Ignoring Software Load "
1147 "Init NACK\n");
1148 if (sw->cbfn)
1149 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1150 NM_MT_LOAD_INIT_ACK, mb,
1151 sw->cb_data, NULL);
1152 rc = sw_fill_window(sw);
1153 sw->state = SW_STATE_WAIT_SEGACK;
1154 } else {
1155 DEBUGP(DNM, "Software Load Init NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001156 /* FIXME: cause */
Harald Welte3ffd1372009-02-01 22:15:49 +00001157 if (sw->cbfn)
1158 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1159 NM_MT_LOAD_INIT_NACK, mb,
1160 sw->cb_data, NULL);
1161 sw->state = SW_STATE_ERROR;
1162 }
Harald Welte4724f992009-01-18 18:01:49 +00001163 break;
1164 }
1165 break;
1166 case SW_STATE_WAIT_SEGACK:
1167 switch (foh->msg_type) {
1168 case NM_MT_LOAD_SEG_ACK:
Harald Welte3ffd1372009-02-01 22:15:49 +00001169 if (sw->cbfn)
1170 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1171 NM_MT_LOAD_SEG_ACK, mb,
1172 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001173 sw->seg_in_window = 0;
Harald Welte1602ade2009-01-29 21:12:39 +00001174 if (!sw->last_seg) {
1175 /* fill window with more segments */
1176 rc = sw_fill_window(sw);
1177 sw->state = SW_STATE_WAIT_SEGACK;
1178 } else {
1179 /* end the transfer */
1180 sw->state = SW_STATE_WAIT_ENDACK;
1181 rc = sw_load_end(sw);
1182 }
Harald Welte4724f992009-01-18 18:01:49 +00001183 break;
1184 }
1185 break;
1186 case SW_STATE_WAIT_ENDACK:
1187 switch (foh->msg_type) {
1188 case NM_MT_LOAD_END_ACK:
1189 sw_close_file(sw);
Harald Welte5e4d1b32009-02-01 13:36:56 +00001190 DEBUGP(DNM, "Software Load End (BTS %u)\n",
1191 sw->bts->nr);
1192 sw->state = SW_STATE_NONE;
1193 if (sw->cbfn)
1194 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1195 NM_MT_LOAD_END_ACK, mb,
1196 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001197 break;
1198 case NM_MT_LOAD_END_NACK:
Holger Freyther31338a12009-02-06 17:43:50 +00001199 if (sw->forced) {
1200 DEBUGP(DNM, "FORCED: Ignoring Software Load"
1201 "End NACK\n");
1202 sw->state = SW_STATE_NONE;
1203 if (sw->cbfn)
1204 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1205 NM_MT_LOAD_END_ACK, mb,
1206 sw->cb_data, NULL);
1207 } else {
1208 DEBUGP(DNM, "Software Load End NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001209 /* FIXME: cause */
Holger Freyther31338a12009-02-06 17:43:50 +00001210 sw->state = SW_STATE_ERROR;
1211 if (sw->cbfn)
1212 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1213 NM_MT_LOAD_END_NACK, mb,
1214 sw->cb_data, NULL);
1215 }
Harald Welte4724f992009-01-18 18:01:49 +00001216 break;
1217 }
1218 case SW_STATE_WAIT_ACTACK:
1219 switch (foh->msg_type) {
1220 case NM_MT_ACTIVATE_SW_ACK:
1221 /* we're done */
Harald Welte5e4d1b32009-02-01 13:36:56 +00001222 DEBUGP(DNM, "Activate Software DONE!\n");
Harald Welte4724f992009-01-18 18:01:49 +00001223 sw->state = SW_STATE_NONE;
1224 rc = 0;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001225 if (sw->cbfn)
1226 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1227 NM_MT_ACTIVATE_SW_ACK, mb,
1228 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001229 break;
1230 case NM_MT_ACTIVATE_SW_NACK:
Harald Welte1602ade2009-01-29 21:12:39 +00001231 DEBUGP(DNM, "Activate Software NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001232 /* FIXME: cause */
Harald Welte4724f992009-01-18 18:01:49 +00001233 sw->state = SW_STATE_ERROR;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001234 if (sw->cbfn)
1235 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1236 NM_MT_ACTIVATE_SW_NACK, mb,
1237 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001238 break;
1239 }
1240 case SW_STATE_NONE:
1241 case SW_STATE_ERROR:
1242 break;
1243 }
1244
1245 if (rc)
1246 fprintf(stderr, "unexpected NM MT 0x%02x in state %u -> %u\n",
1247 foh->msg_type, old_state, sw->state);
1248
1249 return rc;
1250}
1251
1252/* Load the specified software into the BTS */
1253int abis_nm_software_load(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00001254 u_int8_t win_size, int forced,
1255 gsm_cbfn *cbfn, void *cb_data)
Harald Welte4724f992009-01-18 18:01:49 +00001256{
1257 struct abis_nm_sw *sw = &g_sw;
1258 int rc;
1259
Harald Welte5e4d1b32009-02-01 13:36:56 +00001260 DEBUGP(DNM, "Software Load (BTS %u, File \"%s\")\n",
1261 bts->nr, fname);
1262
Harald Welte4724f992009-01-18 18:01:49 +00001263 if (sw->state != SW_STATE_NONE)
1264 return -EBUSY;
1265
1266 sw->bts = bts;
1267 sw->obj_class = NM_OC_SITE_MANAGER;
1268 sw->obj_instance[0] = 0xff;
1269 sw->obj_instance[1] = 0xff;
1270 sw->obj_instance[2] = 0xff;
1271 sw->window_size = win_size;
1272 sw->state = SW_STATE_WAIT_INITACK;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001273 sw->cbfn = cbfn;
1274 sw->cb_data = cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +00001275 sw->forced = forced;
Harald Welte4724f992009-01-18 18:01:49 +00001276
1277 rc = sw_open_file(sw, fname);
1278 if (rc < 0) {
1279 sw->state = SW_STATE_NONE;
1280 return rc;
1281 }
1282
1283 return sw_load_init(sw);
1284}
Harald Welte52b1f982008-12-23 20:25:15 +00001285
Harald Welte1602ade2009-01-29 21:12:39 +00001286int abis_nm_software_load_status(struct gsm_bts *bts)
1287{
1288 struct abis_nm_sw *sw = &g_sw;
1289 struct stat st;
1290 int rc, percent;
1291
1292 rc = fstat(sw->fd, &st);
1293 if (rc < 0) {
1294 perror("ERROR during stat");
1295 return rc;
1296 }
1297
1298 percent = (ftell(sw->stream) * 100) / st.st_size;
1299 return percent;
1300}
1301
Harald Welte5e4d1b32009-02-01 13:36:56 +00001302/* Activate the specified software into the BTS */
1303int abis_nm_software_activate(struct gsm_bts *bts, const char *fname,
1304 gsm_cbfn *cbfn, void *cb_data)
1305{
1306 struct abis_nm_sw *sw = &g_sw;
1307 int rc;
1308
1309 DEBUGP(DNM, "Activating Software (BTS %u, File \"%s\")\n",
1310 bts->nr, fname);
1311
1312 if (sw->state != SW_STATE_NONE)
1313 return -EBUSY;
1314
1315 sw->bts = bts;
1316 sw->obj_class = NM_OC_SITE_MANAGER;
1317 sw->obj_instance[0] = 0xff;
1318 sw->obj_instance[1] = 0xff;
1319 sw->obj_instance[2] = 0xff;
1320 sw->state = SW_STATE_WAIT_ACTACK;
1321 sw->cbfn = cbfn;
1322 sw->cb_data = cb_data;
1323
1324 /* Open the file in order to fill some sw struct members */
1325 rc = sw_open_file(sw, fname);
1326 if (rc < 0) {
1327 sw->state = SW_STATE_NONE;
1328 return rc;
1329 }
1330 sw_close_file(sw);
1331
1332 return sw_activate(sw);
1333}
1334
Harald Welte8470bf22008-12-25 23:28:35 +00001335static void fill_nm_channel(struct abis_nm_channel *ch, u_int8_t bts_port,
Harald Welte52b1f982008-12-23 20:25:15 +00001336 u_int8_t ts_nr, u_int8_t subslot_nr)
1337{
Harald Welteadaf08b2009-01-18 11:08:10 +00001338 ch->attrib = NM_ATT_ABIS_CHANNEL;
Harald Welte52b1f982008-12-23 20:25:15 +00001339 ch->bts_port = bts_port;
1340 ch->timeslot = ts_nr;
1341 ch->subslot = subslot_nr;
1342}
1343
1344int abis_nm_establish_tei(struct gsm_bts *bts, u_int8_t trx_nr,
1345 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot,
1346 u_int8_t tei)
1347{
1348 struct abis_om_hdr *oh;
1349 struct abis_nm_channel *ch;
Harald Welte702d8702008-12-26 20:25:35 +00001350 u_int8_t len = sizeof(*ch) + 2;
Harald Welte8470bf22008-12-25 23:28:35 +00001351 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001352
1353 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1354 fill_om_fom_hdr(oh, len, NM_MT_ESTABLISH_TEI, NM_OC_RADIO_CARRIER,
1355 bts->bts_nr, trx_nr, 0xff);
1356
Harald Welte8470bf22008-12-25 23:28:35 +00001357 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte52b1f982008-12-23 20:25:15 +00001358
1359 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1360 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1361
1362 return abis_nm_sendmsg(bts, msg);
1363}
1364
1365/* connect signalling of one (BTS,TRX) to a particular timeslot on the E1 */
1366int abis_nm_conn_terr_sign(struct gsm_bts_trx *trx,
1367 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot)
1368{
Harald Welte8470bf22008-12-25 23:28:35 +00001369 struct gsm_bts *bts = trx->bts;
Harald Welte52b1f982008-12-23 20:25:15 +00001370 struct abis_om_hdr *oh;
1371 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +00001372 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001373
1374 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001375 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_SIGN,
Harald Welte52b1f982008-12-23 20:25:15 +00001376 NM_OC_RADIO_CARRIER, bts->bts_nr, trx->nr, 0xff);
1377
1378 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1379 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1380
1381 return abis_nm_sendmsg(bts, msg);
1382}
1383
1384#if 0
1385int abis_nm_disc_terr_sign(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1386 struct abis_nm_abis_channel *chan)
1387{
1388}
1389#endif
1390
1391int abis_nm_conn_terr_traf(struct gsm_bts_trx_ts *ts,
1392 u_int8_t e1_port, u_int8_t e1_timeslot,
1393 u_int8_t e1_subslot)
1394{
1395 struct gsm_bts *bts = ts->trx->bts;
1396 struct abis_om_hdr *oh;
1397 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +00001398 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001399
1400 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1401 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_TRAF,
Harald Welteb110cee2009-02-18 03:42:35 +00001402 NM_OC_CHANNEL, bts->bts_nr, ts->trx->nr, ts->nr);
Harald Welte52b1f982008-12-23 20:25:15 +00001403
1404 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1405 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1406
Harald Weltef325eb42009-02-19 17:07:39 +00001407 DEBUGP(DNM, "CONNECT TERR TRAF Um=%s E1=(%u,%u,%u)\n",
1408 gsm_ts_name(ts),
Harald Welteb110cee2009-02-18 03:42:35 +00001409 e1_port, e1_timeslot, e1_subslot);
1410
Harald Welte52b1f982008-12-23 20:25:15 +00001411 return abis_nm_sendmsg(bts, msg);
1412}
1413
1414#if 0
1415int abis_nm_disc_terr_traf(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1416 struct abis_nm_abis_channel *chan,
1417 u_int8_t subchan)
1418{
1419}
1420#endif
1421
Harald Welte22af0db2009-02-14 15:41:08 +00001422/* Chapter 8.6.1 */
1423int abis_nm_set_bts_attr(struct gsm_bts *bts, u_int8_t *attr, int attr_len)
1424{
1425 struct abis_om_hdr *oh;
1426 struct msgb *msg = nm_msgb_alloc();
1427 u_int8_t *cur;
1428
1429 DEBUGP(DNM, "Set BTS Attr (bts=%d)\n", bts->nr);
1430
1431 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1432 fill_om_fom_hdr(oh, attr_len, NM_MT_SET_BTS_ATTR, NM_OC_BTS, bts->nr, 0xff, 0xff);
1433 cur = msgb_put(msg, attr_len);
1434 memcpy(cur, attr, attr_len);
1435
1436 return abis_nm_sendmsg(bts, msg);
1437}
1438
1439/* Chapter 8.6.2 */
1440int abis_nm_set_radio_attr(struct gsm_bts_trx *trx, 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 TRX Attr (bts=%d,trx=%d)\n", trx->bts->nr, trx->nr);
1447
1448 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1449 fill_om_fom_hdr(oh, attr_len, NM_MT_SET_RADIO_ATTR, NM_OC_RADIO_CARRIER,
1450 trx->bts->nr, trx->nr, 0xff);
1451 cur = msgb_put(msg, attr_len);
1452 memcpy(cur, attr, attr_len);
1453
1454 return abis_nm_sendmsg(trx->bts, msg);
1455}
1456
1457/* Chapter 8.6.3 */
Harald Welte52b1f982008-12-23 20:25:15 +00001458int abis_nm_set_channel_attr(struct gsm_bts_trx_ts *ts, u_int8_t chan_comb)
1459{
1460 struct gsm_bts *bts = ts->trx->bts;
1461 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001462 u_int16_t arfcn = htons(ts->trx->arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001463 u_int8_t zero = 0x00;
Harald Welte8470bf22008-12-25 23:28:35 +00001464 struct msgb *msg = nm_msgb_alloc();
Harald Weltee0590df2009-02-15 03:34:15 +00001465 u_int8_t len = 2 + 2;
1466
1467 if (bts->type == GSM_BTS_TYPE_BS11)
1468 len += 4 + 2 + 2 + 3;
Harald Welte52b1f982008-12-23 20:25:15 +00001469
Harald Weltef325eb42009-02-19 17:07:39 +00001470 DEBUGP(DNM, "Set Chan Attr %s\n", gsm_ts_name(ts));
Harald Welte22af0db2009-02-14 15:41:08 +00001471
Harald Welte52b1f982008-12-23 20:25:15 +00001472 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001473 fill_om_fom_hdr(oh, len, NM_MT_SET_CHAN_ATTR,
Holger Freyther6b2d2622009-02-14 23:16:59 +00001474 NM_OC_CHANNEL, bts->bts_nr,
Harald Welte52b1f982008-12-23 20:25:15 +00001475 ts->trx->nr, ts->nr);
1476 /* FIXME: don't send ARFCN list, hopping sequence, mAIO, ...*/
Harald Weltee0590df2009-02-15 03:34:15 +00001477 if (bts->type == GSM_BTS_TYPE_BS11)
1478 msgb_tlv16_put(msg, NM_ATT_ARFCN_LIST, 1, &arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001479 msgb_tv_put(msg, NM_ATT_CHAN_COMB, chan_comb);
Harald Weltee0590df2009-02-15 03:34:15 +00001480 if (bts->type == GSM_BTS_TYPE_BS11) {
1481 msgb_tv_put(msg, NM_ATT_HSN, 0x00);
1482 msgb_tv_put(msg, NM_ATT_MAIO, 0x00);
1483 }
Harald Welte52b1f982008-12-23 20:25:15 +00001484 msgb_tv_put(msg, NM_ATT_TSC, 0x07); /* training sequence */
Harald Weltee0590df2009-02-15 03:34:15 +00001485 if (bts->type == GSM_BTS_TYPE_BS11)
1486 msgb_tlv_put(msg, 0x59, 1, &zero);
Harald Welte52b1f982008-12-23 20:25:15 +00001487
1488 return abis_nm_sendmsg(bts, msg);
1489}
1490
Harald Welte34a99682009-02-13 02:41:40 +00001491int 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 +00001492 u_int8_t i2, u_int8_t i3, int nack, u_int8_t *attr, int att_len)
Harald Welte34a99682009-02-13 02:41:40 +00001493{
1494 struct abis_om_hdr *oh;
1495 struct msgb *msg = nm_msgb_alloc();
Harald Welte5c1e4582009-02-15 11:57:29 +00001496 u_int8_t msgtype = NM_MT_SW_ACT_REQ_ACK;
1497 u_int8_t len = att_len;
1498
1499 if (nack) {
1500 len += 2;
1501 msgtype = NM_MT_SW_ACT_REQ_NACK;
1502 }
Harald Welte34a99682009-02-13 02:41:40 +00001503
1504 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte5c1e4582009-02-15 11:57:29 +00001505 fill_om_fom_hdr(oh, att_len, msgtype, obj_class, i1, i2, i3);
1506
Harald Welte34a99682009-02-13 02:41:40 +00001507 if (attr) {
1508 u_int8_t *ptr = msgb_put(msg, att_len);
1509 memcpy(ptr, attr, att_len);
1510 }
Harald Welte5c1e4582009-02-15 11:57:29 +00001511 if (nack)
1512 msgb_tv_put(msg, NM_ATT_NACK_CAUSES, NM_NACK_OBJCLASS_NOTSUPP);
Harald Welte34a99682009-02-13 02:41:40 +00001513
1514 return abis_nm_sendmsg(bts, msg);
1515}
1516
Harald Welte8470bf22008-12-25 23:28:35 +00001517int abis_nm_raw_msg(struct gsm_bts *bts, int len, u_int8_t *rawmsg)
Harald Welte52b1f982008-12-23 20:25:15 +00001518{
Harald Welte8470bf22008-12-25 23:28:35 +00001519 struct msgb *msg = nm_msgb_alloc();
1520 struct abis_om_hdr *oh;
Harald Welte52b1f982008-12-23 20:25:15 +00001521 u_int8_t *data;
1522
1523 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
1524 fill_om_hdr(oh, len);
1525 data = msgb_put(msg, len);
Harald Weltead384642008-12-26 10:20:07 +00001526 memcpy(data, rawmsg, len);
Harald Welte52b1f982008-12-23 20:25:15 +00001527
1528 return abis_nm_sendmsg(bts, msg);
1529}
1530
1531/* Siemens specific commands */
1532static int __simple_cmd(struct gsm_bts *bts, u_int8_t msg_type)
1533{
1534 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001535 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001536
1537 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001538 fill_om_fom_hdr(oh, 0, msg_type, NM_OC_SITE_MANAGER,
Harald Welte52b1f982008-12-23 20:25:15 +00001539 0xff, 0xff, 0xff);
1540
1541 return abis_nm_sendmsg(bts, msg);
1542}
1543
Harald Welte34a99682009-02-13 02:41:40 +00001544/* Chapter 8.9.2 */
1545int abis_nm_opstart(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1, u_int8_t i2)
1546{
1547 struct abis_om_hdr *oh;
1548 struct msgb *msg = nm_msgb_alloc();
1549
Harald Welte22af0db2009-02-14 15:41:08 +00001550 DEBUGP(DNM, "Sending OPSTART obj_class=0x%02x obj_inst=(0x%02x, 0x%02x, 0x%02x)\n",
1551 obj_class, i0, i1, i2);
Harald Welte34a99682009-02-13 02:41:40 +00001552 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1553 fill_om_fom_hdr(oh, 0, NM_MT_OPSTART, obj_class, i0, i1, i2);
1554
1555 return abis_nm_sendmsg(bts, msg);
1556}
1557
1558/* Chapter 8.8.5 */
1559int abis_nm_chg_adm_state(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0,
1560 u_int8_t i1, u_int8_t i2, u_int8_t adm_state)
1561{
1562 struct abis_om_hdr *oh;
1563 struct msgb *msg = nm_msgb_alloc();
1564
1565 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1566 fill_om_fom_hdr(oh, 2, NM_MT_CHG_ADM_STATE, obj_class, i0, i1, i2);
1567 msgb_tv_put(msg, NM_ATT_ADM_STATE, adm_state);
1568
1569 return abis_nm_sendmsg(bts, msg);
1570}
1571
1572
Harald Welte52b1f982008-12-23 20:25:15 +00001573int abis_nm_event_reports(struct gsm_bts *bts, int on)
1574{
1575 if (on == 0)
Harald Welte227d4072009-01-03 08:16:25 +00001576 return __simple_cmd(bts, NM_MT_STOP_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001577 else
Harald Welte227d4072009-01-03 08:16:25 +00001578 return __simple_cmd(bts, NM_MT_REST_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001579}
1580
Harald Welte47d88ae2009-01-04 12:02:08 +00001581/* Siemens (or BS-11) specific commands */
1582
Harald Welte3ffd1372009-02-01 22:15:49 +00001583int abis_nm_bs11_bsc_disconnect(struct gsm_bts *bts, int reconnect)
1584{
1585 if (reconnect == 0)
1586 return __simple_cmd(bts, NM_MT_BS11_DISCONNECT);
1587 else
1588 return __simple_cmd(bts, NM_MT_BS11_RECONNECT);
1589}
1590
Harald Welteb8427972009-02-05 19:27:17 +00001591int abis_nm_bs11_restart(struct gsm_bts *bts)
1592{
1593 return __simple_cmd(bts, NM_MT_BS11_RESTART);
1594}
1595
1596
Harald Welte268bb402009-02-01 19:11:56 +00001597struct bs11_date_time {
1598 u_int16_t year;
1599 u_int8_t month;
1600 u_int8_t day;
1601 u_int8_t hour;
1602 u_int8_t min;
1603 u_int8_t sec;
1604} __attribute__((packed));
1605
1606
1607void get_bs11_date_time(struct bs11_date_time *aet)
1608{
1609 time_t t;
1610 struct tm *tm;
1611
1612 t = time(NULL);
1613 tm = localtime(&t);
1614 aet->sec = tm->tm_sec;
1615 aet->min = tm->tm_min;
1616 aet->hour = tm->tm_hour;
1617 aet->day = tm->tm_mday;
1618 aet->month = tm->tm_mon;
1619 aet->year = htons(1900 + tm->tm_year);
1620}
1621
Harald Welte05188ee2009-01-18 11:39:08 +00001622int abis_nm_bs11_reset_resource(struct gsm_bts *bts)
Harald Welte52b1f982008-12-23 20:25:15 +00001623{
Harald Welte4668fda2009-01-03 08:19:29 +00001624 return __simple_cmd(bts, NM_MT_BS11_RESET_RESOURCE);
Harald Welte52b1f982008-12-23 20:25:15 +00001625}
1626
Harald Welte05188ee2009-01-18 11:39:08 +00001627int abis_nm_bs11_db_transmission(struct gsm_bts *bts, int begin)
Harald Welte52b1f982008-12-23 20:25:15 +00001628{
1629 if (begin)
Harald Welte4668fda2009-01-03 08:19:29 +00001630 return __simple_cmd(bts, NM_MT_BS11_BEGIN_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00001631 else
Harald Welte4668fda2009-01-03 08:19:29 +00001632 return __simple_cmd(bts, NM_MT_BS11_END_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00001633}
Harald Welte47d88ae2009-01-04 12:02:08 +00001634
Harald Welte05188ee2009-01-18 11:39:08 +00001635int abis_nm_bs11_create_object(struct gsm_bts *bts,
Harald Welte1bc09062009-01-18 14:17:52 +00001636 enum abis_bs11_objtype type, u_int8_t idx,
1637 u_int8_t attr_len, const u_int8_t *attr)
Harald Welte47d88ae2009-01-04 12:02:08 +00001638{
1639 struct abis_om_hdr *oh;
1640 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00001641 u_int8_t *cur;
Harald Welte47d88ae2009-01-04 12:02:08 +00001642
1643 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001644 fill_om_fom_hdr(oh, attr_len, NM_MT_BS11_CREATE_OBJ,
Harald Welte268bb402009-02-01 19:11:56 +00001645 NM_OC_BS11, type, 0, idx);
Harald Welte1bc09062009-01-18 14:17:52 +00001646 cur = msgb_put(msg, attr_len);
1647 memcpy(cur, attr, attr_len);
Harald Welte47d88ae2009-01-04 12:02:08 +00001648
1649 return abis_nm_sendmsg(bts, msg);
1650}
1651
Harald Welte78fc0d42009-02-19 02:50:57 +00001652int abis_nm_bs11_delete_object(struct gsm_bts *bts,
1653 enum abis_bs11_objtype type, u_int8_t idx)
1654{
1655 struct abis_om_hdr *oh;
1656 struct msgb *msg = nm_msgb_alloc();
1657
1658 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1659 fill_om_fom_hdr(oh, 0, NM_MT_BS11_DELETE_OBJ,
1660 NM_OC_BS11, type, 0, idx);
1661
1662 return abis_nm_sendmsg(bts, msg);
1663}
1664
Harald Welte05188ee2009-01-18 11:39:08 +00001665int abis_nm_bs11_create_envaBTSE(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00001666{
1667 struct abis_om_hdr *oh;
1668 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00001669 u_int8_t zero = 0x00;
Harald Welte47d88ae2009-01-04 12:02:08 +00001670
1671 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001672 fill_om_fom_hdr(oh, 3, NM_MT_BS11_CREATE_OBJ,
Harald Welte1bc09062009-01-18 14:17:52 +00001673 NM_OC_BS11_ENVABTSE, 0, idx, 0xff);
1674 msgb_tlv_put(msg, 0x99, 1, &zero);
Harald Welte47d88ae2009-01-04 12:02:08 +00001675
1676 return abis_nm_sendmsg(bts, msg);
1677}
1678
Harald Welte05188ee2009-01-18 11:39:08 +00001679int abis_nm_bs11_create_bport(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00001680{
1681 struct abis_om_hdr *oh;
1682 struct msgb *msg = nm_msgb_alloc();
1683
1684 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1685 fill_om_fom_hdr(oh, 0, NM_MT_BS11_CREATE_OBJ, NM_OC_BS11_BPORT,
1686 idx, 0, 0);
1687
1688 return abis_nm_sendmsg(bts, msg);
1689}
Harald Welte05188ee2009-01-18 11:39:08 +00001690
Harald Welte78fc0d42009-02-19 02:50:57 +00001691static const u_int8_t sm_attr[] = { NM_ATT_TEI, NM_ATT_ABIS_CHANNEL };
1692int abis_nm_bs11_get_oml_tei_ts(struct gsm_bts *bts)
1693{
1694 struct abis_om_hdr *oh;
1695 struct msgb *msg = nm_msgb_alloc();
1696
1697 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1698 fill_om_fom_hdr(oh, 2+sizeof(sm_attr), NM_MT_GET_ATTR, NM_OC_SITE_MANAGER,
1699 0xff, 0xff, 0xff);
1700 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(sm_attr), sm_attr);
1701
1702 return abis_nm_sendmsg(bts, msg);
1703}
1704
Harald Welteb6c92ae2009-02-21 20:15:32 +00001705/* like abis_nm_conn_terr_traf + set_tei */
1706int abis_nm_bs11_conn_oml_tei(struct gsm_bts *bts, u_int8_t e1_port,
1707 u_int8_t e1_timeslot, u_int8_t e1_subslot,
1708 u_int8_t tei)
Harald Welte05188ee2009-01-18 11:39:08 +00001709{
1710 struct abis_om_hdr *oh;
1711 struct abis_nm_channel *ch;
1712 struct msgb *msg = nm_msgb_alloc();
1713
1714 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welteb6c92ae2009-02-21 20:15:32 +00001715 fill_om_fom_hdr(oh, sizeof(*ch)+2, NM_MT_BS11_SET_ATTR,
Harald Welte05188ee2009-01-18 11:39:08 +00001716 NM_OC_SITE_MANAGER, 0xff, 0xff, 0xff);
1717
1718 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1719 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
Harald Welteb6c92ae2009-02-21 20:15:32 +00001720 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte05188ee2009-01-18 11:39:08 +00001721
1722 return abis_nm_sendmsg(bts, msg);
1723}
1724
1725int abis_nm_bs11_set_trx_power(struct gsm_bts_trx *trx, u_int8_t level)
1726{
1727 struct abis_om_hdr *oh;
1728 struct msgb *msg = nm_msgb_alloc();
Harald Welte05188ee2009-01-18 11:39:08 +00001729
1730 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001731 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR,
Harald Welte05188ee2009-01-18 11:39:08 +00001732 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
1733 msgb_tlv_put(msg, NM_ATT_BS11_TXPWR, 1, &level);
1734
1735 return abis_nm_sendmsg(trx->bts, msg);
1736}
1737
Harald Welte78fc0d42009-02-19 02:50:57 +00001738int abis_nm_bs11_get_trx_power(struct gsm_bts_trx *trx)
1739{
1740 struct abis_om_hdr *oh;
1741 struct msgb *msg = nm_msgb_alloc();
1742 u_int8_t attr = NM_ATT_BS11_TXPWR;
1743
1744 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1745 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
1746 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
1747 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), &attr);
1748
1749 return abis_nm_sendmsg(trx->bts, msg);
1750}
1751
Harald Welteaaf02d92009-04-29 13:25:57 +00001752int abis_nm_bs11_get_pll_mode(struct gsm_bts *bts)
1753{
1754 struct abis_om_hdr *oh;
1755 struct msgb *msg = nm_msgb_alloc();
Harald Weltea7cfa032009-04-29 22:33:02 +00001756 u_int8_t attr[] = { NM_ATT_BS11_PLL_MODE };
Harald Welteaaf02d92009-04-29 13:25:57 +00001757
1758 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1759 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
1760 NM_OC_BS11, BS11_OBJ_LI, 0x00, 0x00);
1761 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), &attr);
1762
1763 return abis_nm_sendmsg(bts, msg);
1764}
1765
1766
Harald Welte268bb402009-02-01 19:11:56 +00001767//static const u_int8_t bs11_logon_c7[] = { 0x07, 0xd9, 0x01, 0x11, 0x0d, 0x10, 0x20 };
Harald Weltebb151312009-01-28 20:42:07 +00001768static const u_int8_t bs11_logon_c8[] = { 0x02 };
Harald Welte05188ee2009-01-18 11:39:08 +00001769static const u_int8_t bs11_logon_c9[] = "FACTORY";
1770
Harald Welte1bc09062009-01-18 14:17:52 +00001771int abis_nm_bs11_factory_logon(struct gsm_bts *bts, int on)
Harald Welte05188ee2009-01-18 11:39:08 +00001772{
1773 struct abis_om_hdr *oh;
1774 struct msgb *msg = nm_msgb_alloc();
Harald Welte268bb402009-02-01 19:11:56 +00001775 struct bs11_date_time bdt;
1776
1777 get_bs11_date_time(&bdt);
Harald Welte05188ee2009-01-18 11:39:08 +00001778
1779 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte1bc09062009-01-18 14:17:52 +00001780 if (on) {
Harald Welte268bb402009-02-01 19:11:56 +00001781 u_int8_t len = 3*2 + sizeof(bdt)
Harald Welte6f676a32009-01-18 14:27:48 +00001782 + sizeof(bs11_logon_c8) + sizeof(bs11_logon_c9);
Harald Welte043d04a2009-01-29 23:15:30 +00001783 fill_om_fom_hdr(oh, len, NM_MT_BS11_LMT_LOGON,
Harald Welte1bc09062009-01-18 14:17:52 +00001784 NM_OC_BS11_A3, 0xff, 0xff, 0xff);
Harald Welte043d04a2009-01-29 23:15:30 +00001785 msgb_tlv_put(msg, NM_ATT_BS11_LMT_LOGIN_TIME,
Harald Welte5083b0b2009-02-02 19:20:52 +00001786 sizeof(bdt), (u_int8_t *) &bdt);
Harald Welte043d04a2009-01-29 23:15:30 +00001787 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_ACC_LEV,
1788 sizeof(bs11_logon_c8), bs11_logon_c8);
1789 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_NAME,
1790 sizeof(bs11_logon_c9), bs11_logon_c9);
Harald Welte1bc09062009-01-18 14:17:52 +00001791 } else {
Harald Welte5e4d1b32009-02-01 13:36:56 +00001792 fill_om_fom_hdr(oh, 0, NM_MT_BS11_LMT_LOGOFF,
Harald Welte1bc09062009-01-18 14:17:52 +00001793 NM_OC_BS11_A3, 0xff, 0xff, 0xff);
1794 }
Harald Welte05188ee2009-01-18 11:39:08 +00001795
1796 return abis_nm_sendmsg(bts, msg);
1797}
Harald Welte1bc09062009-01-18 14:17:52 +00001798
1799int abis_nm_bs11_set_trx1_pw(struct gsm_bts *bts, const char *password)
1800{
1801 struct abis_om_hdr *oh;
1802 struct msgb *msg;
1803
1804 if (strlen(password) != 10)
1805 return -EINVAL;
1806
1807 msg = nm_msgb_alloc();
1808 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001809 fill_om_fom_hdr(oh, 2+strlen(password), NM_MT_BS11_SET_ATTR,
Harald Welte1bc09062009-01-18 14:17:52 +00001810 NM_OC_BS11, BS11_OBJ_TRX1, 0x00, 0x00);
1811 msgb_tlv_put(msg, NM_ATT_BS11_PASSWORD, 10, (const u_int8_t *)password);
1812
1813 return abis_nm_sendmsg(bts, msg);
1814}
1815
Harald Weltee69f5fb2009-04-28 16:31:38 +00001816/* change the BS-11 PLL Mode to either locked (E1 derived) or standalone */
1817int abis_nm_bs11_set_pll_locked(struct gsm_bts *bts, int locked)
1818{
1819 struct abis_om_hdr *oh;
1820 struct msgb *msg;
Harald Weltea432cd32009-04-29 13:01:50 +00001821 u_int8_t tlv_value;
Harald Weltee69f5fb2009-04-28 16:31:38 +00001822
1823 msg = nm_msgb_alloc();
1824 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1825 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR, NM_OC_BS11,
1826 BS11_OBJ_LI, 0x00, 0x00);
Harald Weltea432cd32009-04-29 13:01:50 +00001827
1828 if (locked)
1829 tlv_value = BS11_LI_PLL_LOCKED;
1830 else
1831 tlv_value = BS11_LI_PLL_STANDALONE;
1832
1833 msgb_tlv_put(msg, NM_ATT_BS11_PLL_MODE, 1, &tlv_value);
Harald Weltee69f5fb2009-04-28 16:31:38 +00001834
1835 return abis_nm_sendmsg(bts, msg);
1836}
1837
Harald Welte1bc09062009-01-18 14:17:52 +00001838int abis_nm_bs11_get_state(struct gsm_bts *bts)
1839{
1840 return __simple_cmd(bts, NM_MT_BS11_GET_STATE);
1841}
Harald Welte5e4d1b32009-02-01 13:36:56 +00001842
1843/* BS11 SWL */
1844
1845struct abis_nm_bs11_sw {
1846 struct gsm_bts *bts;
1847 char swl_fname[PATH_MAX];
1848 u_int8_t win_size;
Harald Welte3ffd1372009-02-01 22:15:49 +00001849 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001850 struct llist_head file_list;
1851 gsm_cbfn *user_cb; /* specified by the user */
1852};
1853static struct abis_nm_bs11_sw _g_bs11_sw, *g_bs11_sw = &_g_bs11_sw;
1854
1855struct file_list_entry {
1856 struct llist_head list;
1857 char fname[PATH_MAX];
1858};
1859
1860struct file_list_entry *fl_dequeue(struct llist_head *queue)
1861{
1862 struct llist_head *lh;
1863
1864 if (llist_empty(queue))
1865 return NULL;
1866
1867 lh = queue->next;
1868 llist_del(lh);
1869
1870 return llist_entry(lh, struct file_list_entry, list);
1871}
1872
1873static int bs11_read_swl_file(struct abis_nm_bs11_sw *bs11_sw)
1874{
1875 char linebuf[255];
1876 struct llist_head *lh, *lh2;
1877 FILE *swl;
1878 int rc = 0;
1879
1880 swl = fopen(bs11_sw->swl_fname, "r");
1881 if (!swl)
1882 return -ENODEV;
1883
1884 /* zero the stale file list, if any */
1885 llist_for_each_safe(lh, lh2, &bs11_sw->file_list) {
1886 llist_del(lh);
1887 free(lh);
1888 }
1889
1890 while (fgets(linebuf, sizeof(linebuf), swl)) {
1891 char file_id[12+1];
1892 char file_version[80+1];
1893 struct file_list_entry *fle;
1894 static char dir[PATH_MAX];
1895
1896 if (strlen(linebuf) < 4)
1897 continue;
Harald Welte3ffd1372009-02-01 22:15:49 +00001898
Harald Welte5e4d1b32009-02-01 13:36:56 +00001899 rc = sscanf(linebuf+4, "%12s:%80s\r\n", file_id, file_version);
1900 if (rc < 0) {
1901 perror("ERR parsing SWL file");
1902 rc = -EINVAL;
1903 goto out;
1904 }
1905 if (rc < 2)
1906 continue;
1907
1908 fle = malloc(sizeof(*fle));
1909 if (!fle) {
1910 rc = -ENOMEM;
1911 goto out;
1912 }
1913 memset(fle, 0, sizeof(*fle));
1914
1915 /* construct new filename */
1916 strncpy(dir, bs11_sw->swl_fname, sizeof(dir));
1917 strncat(fle->fname, dirname(dir), sizeof(fle->fname) - 1);
1918 strcat(fle->fname, "/");
1919 strncat(fle->fname, file_id, sizeof(fle->fname) - 1 -strlen(fle->fname));
Harald Welte5e4d1b32009-02-01 13:36:56 +00001920
1921 llist_add_tail(&fle->list, &bs11_sw->file_list);
1922 }
1923
1924out:
1925 fclose(swl);
1926 return rc;
1927}
1928
1929/* bs11 swload specific callback, passed to abis_nm core swload */
1930static int bs11_swload_cbfn(unsigned int hook, unsigned int event,
1931 struct msgb *msg, void *data, void *param)
1932{
1933 struct abis_nm_bs11_sw *bs11_sw = data;
1934 struct file_list_entry *fle;
1935 int rc = 0;
1936
Harald Welte5e4d1b32009-02-01 13:36:56 +00001937 switch (event) {
1938 case NM_MT_LOAD_END_ACK:
1939 fle = fl_dequeue(&bs11_sw->file_list);
1940 if (fle) {
1941 /* start download the next file of our file list */
1942 rc = abis_nm_software_load(bs11_sw->bts, fle->fname,
1943 bs11_sw->win_size,
Harald Welte3ffd1372009-02-01 22:15:49 +00001944 bs11_sw->forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00001945 &bs11_swload_cbfn, bs11_sw);
1946 free(fle);
1947 } else {
1948 /* activate the SWL */
1949 rc = abis_nm_software_activate(bs11_sw->bts,
1950 bs11_sw->swl_fname,
1951 bs11_swload_cbfn,
1952 bs11_sw);
1953 }
1954 break;
Harald Welte3ffd1372009-02-01 22:15:49 +00001955 case NM_MT_LOAD_SEG_ACK:
Harald Welte5e4d1b32009-02-01 13:36:56 +00001956 case NM_MT_LOAD_END_NACK:
1957 case NM_MT_LOAD_INIT_ACK:
1958 case NM_MT_LOAD_INIT_NACK:
1959 case NM_MT_ACTIVATE_SW_NACK:
1960 case NM_MT_ACTIVATE_SW_ACK:
1961 default:
1962 /* fallthrough to the user callback */
Harald Welte97ed1e72009-02-06 13:38:02 +00001963 if (bs11_sw->user_cb)
1964 rc = bs11_sw->user_cb(hook, event, msg, NULL, NULL);
Harald Welte5e4d1b32009-02-01 13:36:56 +00001965 break;
1966 }
1967
1968 return rc;
1969}
1970
1971/* Siemens provides a SWL file that is a mere listing of all the other
1972 * files that are part of a software release. We need to upload first
1973 * the list file, and then each file that is listed in the list file */
1974int abis_nm_bs11_load_swl(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00001975 u_int8_t win_size, int forced, gsm_cbfn *cbfn)
Harald Welte5e4d1b32009-02-01 13:36:56 +00001976{
1977 struct abis_nm_bs11_sw *bs11_sw = g_bs11_sw;
1978 struct file_list_entry *fle;
1979 int rc = 0;
1980
1981 INIT_LLIST_HEAD(&bs11_sw->file_list);
1982 bs11_sw->bts = bts;
1983 bs11_sw->win_size = win_size;
1984 bs11_sw->user_cb = cbfn;
Harald Welte3ffd1372009-02-01 22:15:49 +00001985 bs11_sw->forced = forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001986
1987 strncpy(bs11_sw->swl_fname, fname, sizeof(bs11_sw->swl_fname));
1988 rc = bs11_read_swl_file(bs11_sw);
1989 if (rc < 0)
1990 return rc;
1991
1992 /* dequeue next item in file list */
1993 fle = fl_dequeue(&bs11_sw->file_list);
1994 if (!fle)
1995 return -EINVAL;
1996
1997 /* start download the next file of our file list */
Harald Welte3ffd1372009-02-01 22:15:49 +00001998 rc = abis_nm_software_load(bts, fle->fname, win_size, forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00001999 bs11_swload_cbfn, bs11_sw);
2000 free(fle);
2001 return rc;
2002}
2003
Harald Welte5083b0b2009-02-02 19:20:52 +00002004#if 0
Harald Welte5e4d1b32009-02-01 13:36:56 +00002005static u_int8_t req_attr_btse[] = {
2006 NM_ATT_ADM_STATE, NM_ATT_BS11_LMT_LOGON_SESSION,
2007 NM_ATT_BS11_LMT_LOGIN_TIME, NM_ATT_BS11_LMT_USER_ACC_LEV,
2008 NM_ATT_BS11_LMT_USER_NAME,
2009
2010 0xaf, NM_ATT_BS11_RX_OFFSET, NM_ATT_BS11_VENDOR_NAME,
2011
2012 NM_ATT_BS11_SW_LOAD_INTENDED, NM_ATT_BS11_SW_LOAD_SAFETY,
2013
2014 NM_ATT_BS11_SW_LOAD_STORED };
2015
2016static u_int8_t req_attr_btsm[] = {
2017 NM_ATT_ABIS_CHANNEL, NM_ATT_TEI, NM_ATT_BS11_ABIS_EXT_TIME,
2018 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xce, NM_ATT_FILE_ID,
2019 NM_ATT_FILE_VERSION, NM_ATT_OPER_STATE, 0xe8, NM_ATT_BS11_ALL_TEST_CATG,
2020 NM_ATT_SW_DESCR, NM_ATT_GET_ARI };
Harald Welte5083b0b2009-02-02 19:20:52 +00002021#endif
Harald Welte5e4d1b32009-02-01 13:36:56 +00002022
2023static u_int8_t req_attr[] = {
2024 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xa8, NM_ATT_OPER_STATE,
2025 0xd5, 0xa1, NM_ATT_BS11_ESN_FW_CODE_NO, NM_ATT_BS11_ESN_HW_CODE_NO,
Harald Weltea7cfa032009-04-29 22:33:02 +00002026 0x42, NM_ATT_BS11_ESN_PCB_SERIAL, NM_ATT_BS11_PLL };
Harald Welte5e4d1b32009-02-01 13:36:56 +00002027
2028int abis_nm_bs11_get_serno(struct gsm_bts *bts)
2029{
2030 struct abis_om_hdr *oh;
2031 struct msgb *msg = nm_msgb_alloc();
2032
2033 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2034 /* SiemensHW CCTRL object */
2035 fill_om_fom_hdr(oh, 2+sizeof(req_attr), NM_MT_GET_ATTR, NM_OC_BS11,
2036 0x03, 0x00, 0x00);
2037 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(req_attr), req_attr);
2038
2039 return abis_nm_sendmsg(bts, msg);
2040}
Harald Welte268bb402009-02-01 19:11:56 +00002041
2042int abis_nm_bs11_set_ext_time(struct gsm_bts *bts)
2043{
2044 struct abis_om_hdr *oh;
2045 struct msgb *msg = nm_msgb_alloc();
2046 struct bs11_date_time aet;
2047
2048 get_bs11_date_time(&aet);
2049 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2050 /* SiemensHW CCTRL object */
2051 fill_om_fom_hdr(oh, 2+sizeof(aet), NM_MT_BS11_SET_ATTR, NM_OC_SITE_MANAGER,
2052 0xff, 0xff, 0xff);
Harald Welte5083b0b2009-02-02 19:20:52 +00002053 msgb_tlv_put(msg, NM_ATT_BS11_ABIS_EXT_TIME, sizeof(aet), (u_int8_t *) &aet);
Harald Welte268bb402009-02-01 19:11:56 +00002054
2055 return abis_nm_sendmsg(bts, msg);
2056}
Harald Welte5c1e4582009-02-15 11:57:29 +00002057
2058/* ip.access nanoBTS specific commands */
Harald Welte5c1e4582009-02-15 11:57:29 +00002059static const char ipaccess_magic[] = "com.ipaccess";
2060
Harald Welte677c21f2009-02-17 13:22:23 +00002061
2062static int abis_nm_rx_ipacc(struct msgb *msg)
2063{
2064 struct abis_om_hdr *oh = msgb_l2(msg);
2065 struct abis_om_fom_hdr *foh;
2066 u_int8_t idstrlen = oh->data[0];
2067 struct tlv_parsed tp;
2068
2069 if (strncmp((char *)&oh->data[1], ipaccess_magic, idstrlen)) {
2070 DEBUGP(DNM, "id string is not com.ipaccess !?!\n");
2071 return -EINVAL;
2072 }
2073
Harald Welte193fefc2009-04-30 15:16:27 +00002074 foh = (struct abis_om_fom_hdr *) (oh->data + 1 + idstrlen);
Harald Welte03133942009-02-18 19:51:53 +00002075 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Welte677c21f2009-02-17 13:22:23 +00002076
Harald Welte193fefc2009-04-30 15:16:27 +00002077 DEBUGP(DNM, "IPACCESS(0x%02x): ", foh->msg_type);
2078
Harald Welte677c21f2009-02-17 13:22:23 +00002079 switch (foh->msg_type) {
2080 case NM_MT_IPACC_RSL_CONNECT_ACK:
Harald Welte193fefc2009-04-30 15:16:27 +00002081 DEBUGPC(DNM, "RSL CONNECT ACK ");
Harald Welte677c21f2009-02-17 13:22:23 +00002082 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_RSL_BSC_IP))
Harald Welte9de2bf82009-04-30 15:59:55 +00002083 DEBUGPC(DNM, "IP=%s ",
Harald Welte677c21f2009-02-17 13:22:23 +00002084 inet_ntoa(*((struct in_addr *)
2085 TLVP_VAL(&tp, NM_ATT_IPACC_RSL_BSC_IP))));
2086 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_RSL_BSC_PORT))
Harald Welte9de2bf82009-04-30 15:59:55 +00002087 DEBUGPC(DNM, "PORT=%u ",
Harald Welte677c21f2009-02-17 13:22:23 +00002088 ntohs(*((u_int16_t *)
2089 TLVP_VAL(&tp, NM_ATT_IPACC_RSL_BSC_PORT))));
Harald Welte9de2bf82009-04-30 15:59:55 +00002090 DEBUGPC(DNM, "\n");
Harald Welte677c21f2009-02-17 13:22:23 +00002091 break;
2092 case NM_MT_IPACC_RSL_CONNECT_NACK:
Harald Welte193fefc2009-04-30 15:16:27 +00002093 DEBUGPC(DNM, "RSL CONNECT NACK ");
Harald Welte677c21f2009-02-17 13:22:23 +00002094 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
Harald Welte6c96ba52009-05-01 13:03:40 +00002095 DEBUGPC(DNM, " CAUSE=%s\n",
2096 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
Harald Welte677c21f2009-02-17 13:22:23 +00002097 else
2098 DEBUGPC(DNM, "\n");
2099 break;
Harald Welte193fefc2009-04-30 15:16:27 +00002100 case NM_MT_IPACC_SET_NVATTR_ACK:
2101 DEBUGPC(DNM, "SET NVATTR ACK\n");
2102 /* FIXME: decode and show the actual attributes */
2103 break;
2104 case NM_MT_IPACC_SET_NVATTR_NACK:
Harald Welte6c96ba52009-05-01 13:03:40 +00002105 DEBUGPC(DNM, "SET NVATTR NACK ");
2106 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
2107 DEBUGPC(DNM, " CAUSE=%s\n",
2108 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
2109 else
2110 DEBUGPC(DNM, "\n");
Harald Welte193fefc2009-04-30 15:16:27 +00002111 break;
2112 default:
2113 DEBUGPC(DNM, "unknown\n");
2114 break;
Harald Welte677c21f2009-02-17 13:22:23 +00002115 }
2116 return 0;
2117}
2118
Harald Welte193fefc2009-04-30 15:16:27 +00002119/* send an ip-access manufacturer specific message */
Harald Welte5c1e4582009-02-15 11:57:29 +00002120int abis_nm_ipaccess_msg(struct gsm_bts *bts, u_int8_t msg_type,
2121 u_int8_t obj_class, u_int8_t bts_nr,
2122 u_int8_t trx_nr, u_int8_t ts_nr,
2123 u_int8_t *attr, int attr_len)
2124{
2125 struct msgb *msg = nm_msgb_alloc();
2126 struct abis_om_hdr *oh;
2127 struct abis_om_fom_hdr *foh;
2128 u_int8_t *data;
2129
2130 /* construct the 12.21 OM header, observe the erroneous length */
2131 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
2132 fill_om_hdr(oh, sizeof(*foh) + attr_len);
2133 oh->mdisc = ABIS_OM_MDISC_MANUF;
2134
2135 /* add the ip.access magic */
2136 data = msgb_put(msg, sizeof(ipaccess_magic)+1);
2137 *data++ = sizeof(ipaccess_magic);
2138 memcpy(data, ipaccess_magic, sizeof(ipaccess_magic));
2139
2140 /* fill the 12.21 FOM header */
2141 foh = (struct abis_om_fom_hdr *) msgb_put(msg, sizeof(*foh));
2142 foh->msg_type = msg_type;
2143 foh->obj_class = obj_class;
2144 foh->obj_inst.bts_nr = bts_nr;
2145 foh->obj_inst.trx_nr = trx_nr;
2146 foh->obj_inst.ts_nr = ts_nr;
2147
2148 if (attr && attr_len) {
2149 data = msgb_put(msg, attr_len);
2150 memcpy(data, attr, attr_len);
2151 }
2152
2153 return abis_nm_sendmsg(bts, msg);
2154}
Harald Welte677c21f2009-02-17 13:22:23 +00002155
Harald Welte193fefc2009-04-30 15:16:27 +00002156/* set some attributes in NVRAM */
2157int abis_nm_ipaccess_set_nvattr(struct gsm_bts *bts, u_int8_t *attr,
2158 int attr_len)
2159{
2160 return abis_nm_ipaccess_msg(bts, NM_MT_IPACC_SET_NVATTR,
2161 NM_OC_BASEB_TRANSC, 0, 0, 0xff, attr,
2162 attr_len);
2163}
2164
2165/* restart / reboot an ip.access nanoBTS */
2166int abis_nm_ipaccess_restart(struct gsm_bts *bts)
2167{
2168 return __simple_cmd(bts, NM_MT_IPACC_RESTART);
2169}