blob: fcc192adce07eeae00118a26f84067e96e704cdf [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 Welte23897662009-05-01 14:52:51 +0000560 DEBUGPC(DNM, "STATE CHG: ");
Harald Weltee0590df2009-02-15 03:34:15 +0000561
562 nm_state = objclass2nmstate(bts, foh->obj_class, &foh->obj_inst);
563 if (!nm_state) {
564 DEBUGPC(DNM, "\n");
565 return -EINVAL;
Harald Welte22af0db2009-02-14 15:41:08 +0000566 }
Harald Weltee0590df2009-02-15 03:34:15 +0000567
568 new_state = *nm_state;
569
Harald Welte03133942009-02-18 19:51:53 +0000570 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Weltee0590df2009-02-15 03:34:15 +0000571 if (TLVP_PRESENT(&tp, NM_ATT_OPER_STATE)) {
572 new_state.operational = *TLVP_VAL(&tp, NM_ATT_OPER_STATE);
Harald Welte4d87f242009-03-10 19:43:44 +0000573 DEBUGPC(DNM, "OP_STATE=%s ", nm_opstate_name(new_state.operational));
Harald Weltee0590df2009-02-15 03:34:15 +0000574 }
575 if (TLVP_PRESENT(&tp, NM_ATT_AVAIL_STATUS)) {
Harald Welte0b8348d2009-02-18 03:43:01 +0000576 if (TLVP_LEN(&tp, NM_ATT_AVAIL_STATUS) == 0)
577 new_state.availability = 0xff;
578 else
579 new_state.availability = *TLVP_VAL(&tp, NM_ATT_AVAIL_STATUS);
Harald Welte4d87f242009-03-10 19:43:44 +0000580 DEBUGPC(DNM, "AVAIL=%s(%02x) ", nm_avail_name(new_state.availability),
Harald Weltee0590df2009-02-15 03:34:15 +0000581 new_state.availability);
582 }
583 if (TLVP_PRESENT(&tp, NM_ATT_ADM_STATE)) {
584 new_state.administrative = *TLVP_VAL(&tp, NM_ATT_ADM_STATE);
585 DEBUGPC(DNM, "ADM=%02x ", new_state.administrative);
Harald Welte97ed1e72009-02-06 13:38:02 +0000586 }
587 DEBUGPC(DNM, "\n");
Harald Weltee0590df2009-02-15 03:34:15 +0000588
589 if (memcmp(&new_state, nm_state, sizeof(new_state))) {
590 /* Update the operational state of a given object in our in-memory data
591 * structures and send an event to the higher layer */
592 void *obj = objclass2obj(bts, foh->obj_class, &foh->obj_inst);
593 rc = nm_state_event(EVT_STATECHG_OPER, foh->obj_class, obj, nm_state, &new_state);
594 *nm_state = new_state;
595 }
596#if 0
Harald Welte22af0db2009-02-14 15:41:08 +0000597 if (op_state == 1) {
598 /* try to enable objects that are disabled */
599 abis_nm_opstart(bts, foh->obj_class,
600 foh->obj_inst.bts_nr,
601 foh->obj_inst.trx_nr,
602 foh->obj_inst.ts_nr);
603 }
Harald Weltee0590df2009-02-15 03:34:15 +0000604#endif
Harald Welte97ed1e72009-02-06 13:38:02 +0000605 return 0;
606}
607
608static int abis_nm_rcvmsg_report(struct msgb *mb)
609{
610 struct abis_om_fom_hdr *foh = msgb_l3(mb);
611 u_int8_t mt = foh->msg_type;
612
Harald Welte23897662009-05-01 14:52:51 +0000613 DEBUGP(DNM, "OC=%s(%02x) INST=(%02x,%02x,%02x) ",
614 obj_class_name(foh->obj_class), foh->obj_class,
615 foh->obj_inst.bts_nr, foh->obj_inst.trx_nr,
616 foh->obj_inst.ts_nr);
617
Harald Welte97ed1e72009-02-06 13:38:02 +0000618 //nmh->cfg->report_cb(mb, foh);
619
620 switch (mt) {
621 case NM_MT_STATECHG_EVENT_REP:
622 return abis_nm_rx_statechg_rep(mb);
623 break;
Harald Welte34a99682009-02-13 02:41:40 +0000624 case NM_MT_SW_ACTIVATED_REP:
Harald Welte23897662009-05-01 14:52:51 +0000625 DEBUGPC(DNM, "Software Activated Report\n");
Harald Welte34a99682009-02-13 02:41:40 +0000626 break;
Harald Weltee0590df2009-02-15 03:34:15 +0000627 case NM_MT_FAILURE_EVENT_REP:
Harald Welte23897662009-05-01 14:52:51 +0000628 DEBUGPC(DNM, "Failure Event Report\n");
Harald Weltee0590df2009-02-15 03:34:15 +0000629 break;
630 default:
Harald Welte23897662009-05-01 14:52:51 +0000631 DEBUGPC(DNM, "reporting NM MT 0x%02x\n", mt);
Harald Weltee0590df2009-02-15 03:34:15 +0000632 break;
633
Harald Welte97ed1e72009-02-06 13:38:02 +0000634 };
635
Harald Welte97ed1e72009-02-06 13:38:02 +0000636 return 0;
637}
638
Harald Welte34a99682009-02-13 02:41:40 +0000639/* Activate the specified software into the BTS */
640static int ipacc_sw_activate(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1,
641 u_int8_t i2, u_int8_t *sw_desc, u_int8_t swdesc_len)
642{
643 struct abis_om_hdr *oh;
644 struct msgb *msg = nm_msgb_alloc();
645 u_int8_t len = swdesc_len;
646 u_int8_t *trailer;
647
648 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
649 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, obj_class, i0, i1, i2);
650
651 trailer = msgb_put(msg, swdesc_len);
652 memcpy(trailer, sw_desc, swdesc_len);
653
654 return abis_nm_sendmsg(bts, msg);
655}
656
657static int abis_nm_rx_sw_act_req(struct msgb *mb)
658{
659 struct abis_om_hdr *oh = msgb_l2(mb);
660 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Harald Welte5c1e4582009-02-15 11:57:29 +0000661 int nack = 0;
Harald Welte34a99682009-02-13 02:41:40 +0000662 int ret;
663
Harald Welte5c1e4582009-02-15 11:57:29 +0000664 DEBUGP(DNM, "Software Activate Request ");
Harald Welte34a99682009-02-13 02:41:40 +0000665
Harald Welte5c1e4582009-02-15 11:57:29 +0000666 if (foh->obj_class >= 0xf0 && foh->obj_class <= 0xf3) {
667 DEBUGPC(DNM, "NACKing for GPRS obj_class 0x%02x\n", foh->obj_class);
668 nack = 1;
669 } else
670 DEBUGPC(DNM, "ACKing and Activating\n");
671
672 ret = abis_nm_sw_act_req_ack(mb->trx->bts, foh->obj_class,
Harald Welte34a99682009-02-13 02:41:40 +0000673 foh->obj_inst.bts_nr,
674 foh->obj_inst.trx_nr,
Harald Welte5c1e4582009-02-15 11:57:29 +0000675 foh->obj_inst.ts_nr, nack,
Harald Welte34a99682009-02-13 02:41:40 +0000676 foh->data, oh->length-sizeof(*foh));
677
Harald Welte5c1e4582009-02-15 11:57:29 +0000678 if (nack)
679 return ret;
680
Harald Welte34a99682009-02-13 02:41:40 +0000681 /* FIXME: properly parse attributes */
682 return ipacc_sw_activate(mb->trx->bts, foh->obj_class,
683 foh->obj_inst.bts_nr,
684 foh->obj_inst.trx_nr,
685 foh->obj_inst.ts_nr,
686 foh->data + oh->length-sizeof(*foh)-22, 22);
687}
688
Harald Weltee0590df2009-02-15 03:34:15 +0000689/* Receive a CHANGE_ADM_STATE_ACK, parse the TLV and update local state */
690static int abis_nm_rx_chg_adm_state_ack(struct msgb *mb)
691{
692 struct abis_om_hdr *oh = msgb_l2(mb);
693 struct abis_om_fom_hdr *foh = msgb_l3(mb);
694 struct tlv_parsed tp;
695 u_int8_t adm_state;
696
Harald Welte03133942009-02-18 19:51:53 +0000697 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Weltee0590df2009-02-15 03:34:15 +0000698 if (!TLVP_PRESENT(&tp, NM_ATT_ADM_STATE))
699 return -EINVAL;
700
701 adm_state = *TLVP_VAL(&tp, NM_ATT_ADM_STATE);
702
703 return update_admstate(mb->trx->bts, foh->obj_class, &foh->obj_inst, adm_state);
704}
705
Harald Welteee670472009-02-22 21:58:49 +0000706static int abis_nm_rx_lmt_event(struct msgb *mb)
707{
708 struct abis_om_hdr *oh = msgb_l2(mb);
709 struct abis_om_fom_hdr *foh = msgb_l3(mb);
710 struct tlv_parsed tp;
711
712 DEBUGP(DNM, "LMT Event ");
713 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
714 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_LOGON_SESSION) &&
715 TLVP_LEN(&tp, NM_ATT_BS11_LMT_LOGON_SESSION) >= 1) {
716 u_int8_t onoff = *TLVP_VAL(&tp, NM_ATT_BS11_LMT_LOGON_SESSION);
717 DEBUGPC(DNM, "LOG%s ", onoff ? "ON" : "OFF");
718 }
719 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV) &&
720 TLVP_LEN(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV) >= 1) {
721 u_int8_t level = *TLVP_VAL(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV);
722 DEBUGPC(DNM, "Level=%u ", level);
723 }
724 if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_USER_NAME) &&
725 TLVP_LEN(&tp, NM_ATT_BS11_LMT_USER_NAME) >= 1) {
726 char *name = (char *) TLVP_VAL(&tp, NM_ATT_BS11_LMT_USER_NAME);
727 DEBUGPC(DNM, "Username=%s ", name);
728 }
729 DEBUGPC(DNM, "\n");
730 /* FIXME: parse LMT LOGON TIME */
731 return 0;
732}
733
Harald Welte52b1f982008-12-23 20:25:15 +0000734/* Receive a OML NM Message from BTS */
Harald Welte8470bf22008-12-25 23:28:35 +0000735static int abis_nm_rcvmsg_fom(struct msgb *mb)
Harald Welte52b1f982008-12-23 20:25:15 +0000736{
Harald Welte6c96ba52009-05-01 13:03:40 +0000737 struct abis_om_hdr *oh = msgb_l2(mb);
Harald Welte52b1f982008-12-23 20:25:15 +0000738 struct abis_om_fom_hdr *foh = msgb_l3(mb);
739 u_int8_t mt = foh->msg_type;
740
741 /* check for unsolicited message */
Harald Welte97ed1e72009-02-06 13:38:02 +0000742 if (is_report(mt))
743 return abis_nm_rcvmsg_report(mb);
Harald Welte52b1f982008-12-23 20:25:15 +0000744
Harald Welte4724f992009-01-18 18:01:49 +0000745 if (is_in_arr(mt, sw_load_msgs, ARRAY_SIZE(sw_load_msgs)))
746 return abis_nm_rcvmsg_sw(mb);
747
Harald Welte78fc0d42009-02-19 02:50:57 +0000748 if (is_in_arr(mt, nacks, ARRAY_SIZE(nacks))) {
Harald Welte6c96ba52009-05-01 13:03:40 +0000749 struct tlv_parsed tp;
Harald Welte78fc0d42009-02-19 02:50:57 +0000750 if (nack_names[mt])
Harald Welte6c96ba52009-05-01 13:03:40 +0000751 DEBUGP(DNM, "%s NACK ", nack_names[mt]);
752 /* FIXME: NACK cause */
Harald Welte78fc0d42009-02-19 02:50:57 +0000753 else
Harald Welte6c96ba52009-05-01 13:03:40 +0000754 DEBUGP(DNM, "NACK 0x%02x ", mt);
755
756 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
757 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
758 DEBUGPC(DNM, "CAUSE=%s\n",
759 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
760 else
761 DEBUGPC(DNM, "\n");
Harald Welte78fc0d42009-02-19 02:50:57 +0000762 }
Harald Weltead384642008-12-26 10:20:07 +0000763#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000764 /* check if last message is to be acked */
765 if (is_ack_nack(nmh->last_msgtype)) {
766 if (mt == MT_ACK(nmh->last_msgtype)) {
767 fprintf(stderr, "received ACK (0x%x)\n",
768 foh->msg_type);
769 /* we got our ACK, continue sending the next msg */
770 } else if (mt == MT_NACK(nmh->last_msgtype)) {
771 /* we got a NACK, signal this to the caller */
772 fprintf(stderr, "received NACK (0x%x)\n",
773 foh->msg_type);
774 /* FIXME: somehow signal this to the caller */
775 } else {
776 /* really strange things happen */
777 return -EINVAL;
778 }
779 }
Harald Weltead384642008-12-26 10:20:07 +0000780#endif
781
Harald Welte97ed1e72009-02-06 13:38:02 +0000782 switch (mt) {
Harald Weltee0590df2009-02-15 03:34:15 +0000783 case NM_MT_CHG_ADM_STATE_ACK:
784 return abis_nm_rx_chg_adm_state_ack(mb);
785 break;
Harald Welte34a99682009-02-13 02:41:40 +0000786 case NM_MT_SW_ACT_REQ:
787 return abis_nm_rx_sw_act_req(mb);
788 break;
Harald Welte97ed1e72009-02-06 13:38:02 +0000789 case NM_MT_BS11_LMT_SESSION:
Harald Welteee670472009-02-22 21:58:49 +0000790 return abis_nm_rx_lmt_event(mb);
Harald Welte97ed1e72009-02-06 13:38:02 +0000791 break;
792 }
793
Harald Weltead384642008-12-26 10:20:07 +0000794 return 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000795}
796
Harald Welte677c21f2009-02-17 13:22:23 +0000797static int abis_nm_rx_ipacc(struct msgb *mb);
798
799static int abis_nm_rcvmsg_manuf(struct msgb *mb)
800{
801 int rc;
802 int bts_type = mb->trx->bts->type;
803
804 switch (bts_type) {
805 case GSM_BTS_TYPE_NANOBTS_900:
806 case GSM_BTS_TYPE_NANOBTS_1800:
807 rc = abis_nm_rx_ipacc(mb);
808 break;
809 default:
810 fprintf(stderr, "don't know how to parse OML for this "
811 "BTS type (%u)\n", bts_type);
812 rc = 0;
813 break;
814 }
815
816 return rc;
817}
818
Harald Welte52b1f982008-12-23 20:25:15 +0000819/* High-Level API */
820/* Entry-point where L2 OML from BTS enters the NM code */
Harald Welte8470bf22008-12-25 23:28:35 +0000821int abis_nm_rcvmsg(struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +0000822{
Harald Welte52b1f982008-12-23 20:25:15 +0000823 struct abis_om_hdr *oh = msgb_l2(msg);
Harald Welte677c21f2009-02-17 13:22:23 +0000824 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000825
826 /* Various consistency checks */
827 if (oh->placement != ABIS_OM_PLACEMENT_ONLY) {
828 fprintf(stderr, "ABIS OML placement 0x%x not supported\n",
829 oh->placement);
830 return -EINVAL;
831 }
832 if (oh->sequence != 0) {
833 fprintf(stderr, "ABIS OML sequence 0x%x != 0x00\n",
834 oh->sequence);
835 return -EINVAL;
836 }
Harald Welte702d8702008-12-26 20:25:35 +0000837#if 0
Holger Freytherca362a62009-01-04 21:05:01 +0000838 unsigned int l2_len = msg->tail - (u_int8_t *)msgb_l2(msg);
839 unsigned int hlen = sizeof(*oh) + sizeof(struct abis_om_fom_hdr);
Harald Welte702d8702008-12-26 20:25:35 +0000840 if (oh->length + hlen > l2_len) {
Harald Welte52b1f982008-12-23 20:25:15 +0000841 fprintf(stderr, "ABIS OML truncated message (%u > %u)\n",
842 oh->length + sizeof(*oh), l2_len);
843 return -EINVAL;
844 }
Harald Welte702d8702008-12-26 20:25:35 +0000845 if (oh->length + hlen < l2_len)
846 fprintf(stderr, "ABIS OML message with extra trailer?!? (oh->len=%d, sizeof_oh=%d l2_len=%d\n", oh->length, sizeof(*oh), l2_len);
847#endif
Harald Weltead384642008-12-26 10:20:07 +0000848 msg->l3h = (unsigned char *)oh + sizeof(*oh);
Harald Welte52b1f982008-12-23 20:25:15 +0000849
850 switch (oh->mdisc) {
851 case ABIS_OM_MDISC_FOM:
Harald Welte8470bf22008-12-25 23:28:35 +0000852 rc = abis_nm_rcvmsg_fom(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000853 break;
Harald Welte677c21f2009-02-17 13:22:23 +0000854 case ABIS_OM_MDISC_MANUF:
855 rc = abis_nm_rcvmsg_manuf(msg);
856 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000857 case ABIS_OM_MDISC_MMI:
858 case ABIS_OM_MDISC_TRAU:
Harald Welte677c21f2009-02-17 13:22:23 +0000859 fprintf(stderr, "unimplemented ABIS OML message discriminator 0x%x\n",
860 oh->mdisc);
861 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000862 default:
863 fprintf(stderr, "unknown ABIS OML message discriminator 0x%x\n",
864 oh->mdisc);
865 return -EINVAL;
866 }
867
Harald Weltead384642008-12-26 10:20:07 +0000868 msgb_free(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000869 return rc;
870}
871
872#if 0
873/* initialized all resources */
874struct abis_nm_h *abis_nm_init(struct abis_nm_cfg *cfg)
875{
876 struct abis_nm_h *nmh;
877
878 nmh = malloc(sizeof(*nmh));
879 if (!nmh)
880 return NULL;
881
882 nmh->cfg = cfg;
883
884 return nmh;
885}
886
887/* free all resources */
888void abis_nm_fini(struct abis_nm_h *nmh)
889{
890 free(nmh);
891}
892#endif
893
894/* Here we are trying to define a high-level API that can be used by
895 * the actual BSC implementation. However, the architecture is currently
896 * still under design. Ideally the calls to this API would be synchronous,
897 * while the underlying stack behind the APi runs in a traditional select
898 * based state machine.
899 */
900
Harald Welte4724f992009-01-18 18:01:49 +0000901/* 6.2 Software Load: */
902enum sw_state {
903 SW_STATE_NONE,
904 SW_STATE_WAIT_INITACK,
905 SW_STATE_WAIT_SEGACK,
906 SW_STATE_WAIT_ENDACK,
907 SW_STATE_WAIT_ACTACK,
908 SW_STATE_ERROR,
909};
Harald Welte52b1f982008-12-23 20:25:15 +0000910
Harald Welte52b1f982008-12-23 20:25:15 +0000911struct abis_nm_sw {
Harald Welte4724f992009-01-18 18:01:49 +0000912 struct gsm_bts *bts;
Harald Welte5e4d1b32009-02-01 13:36:56 +0000913 gsm_cbfn *cbfn;
914 void *cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +0000915 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +0000916
Harald Welte52b1f982008-12-23 20:25:15 +0000917 /* this will become part of the SW LOAD INITIATE */
918 u_int8_t obj_class;
919 u_int8_t obj_instance[3];
Harald Welte4724f992009-01-18 18:01:49 +0000920
921 u_int8_t file_id[255];
922 u_int8_t file_id_len;
923
924 u_int8_t file_version[255];
925 u_int8_t file_version_len;
926
927 u_int8_t window_size;
928 u_int8_t seg_in_window;
929
930 int fd;
931 FILE *stream;
932 enum sw_state state;
Harald Welte1602ade2009-01-29 21:12:39 +0000933 int last_seg;
Harald Welte52b1f982008-12-23 20:25:15 +0000934};
935
Harald Welte4724f992009-01-18 18:01:49 +0000936static struct abis_nm_sw g_sw;
937
938/* 6.2.1 / 8.3.1: Load Data Initiate */
939static int sw_load_init(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +0000940{
Harald Welte4724f992009-01-18 18:01:49 +0000941 struct abis_om_hdr *oh;
942 struct msgb *msg = nm_msgb_alloc();
943 u_int8_t len = 3*2 + sw->file_id_len + sw->file_version_len;
944
945 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
946 fill_om_fom_hdr(oh, len, NM_MT_LOAD_INIT, sw->obj_class,
947 sw->obj_instance[0], sw->obj_instance[1],
948 sw->obj_instance[2]);
949
950 /* FIXME: this is BS11 specific format */
951 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
952 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
953 sw->file_version);
954 msgb_tv_put(msg, NM_ATT_WINDOW_SIZE, sw->window_size);
955
956 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000957}
958
Harald Welte1602ade2009-01-29 21:12:39 +0000959static int is_last_line(FILE *stream)
960{
961 char next_seg_buf[256];
962 long pos;
963
964 /* check if we're sending the last line */
965 pos = ftell(stream);
966 if (!fgets(next_seg_buf, sizeof(next_seg_buf)-2, stream)) {
967 fseek(stream, pos, SEEK_SET);
968 return 1;
969 }
970
971 fseek(stream, pos, SEEK_SET);
972 return 0;
973}
974
Harald Welte4724f992009-01-18 18:01:49 +0000975/* 6.2.2 / 8.3.2 Load Data Segment */
976static int sw_load_segment(struct abis_nm_sw *sw)
977{
978 struct abis_om_hdr *oh;
979 struct msgb *msg = nm_msgb_alloc();
980 char seg_buf[256];
981 char *line_buf = seg_buf+2;
Harald Welte3b8ba212009-01-29 12:27:58 +0000982 unsigned char *tlv;
Harald Welte4724f992009-01-18 18:01:49 +0000983 u_int8_t len;
Harald Welte4724f992009-01-18 18:01:49 +0000984
985 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte3b8ba212009-01-29 12:27:58 +0000986
987 switch (sw->bts->type) {
988 case GSM_BTS_TYPE_BS11:
989 if (fgets(line_buf, sizeof(seg_buf)-2, sw->stream) == NULL) {
990 perror("fgets reading segment");
991 return -EINVAL;
992 }
993 seg_buf[0] = 0x00;
Harald Welte1602ade2009-01-29 21:12:39 +0000994
995 /* check if we're sending the last line */
996 sw->last_seg = is_last_line(sw->stream);
997 if (sw->last_seg)
998 seg_buf[1] = 0;
999 else
1000 seg_buf[1] = 1 + sw->seg_in_window++;
Harald Welte3b8ba212009-01-29 12:27:58 +00001001
1002 len = strlen(line_buf) + 2;
1003 tlv = msgb_put(msg, TLV_GROSS_LEN(len));
1004 tlv_put(tlv, NM_ATT_BS11_FILE_DATA, len, (u_int8_t *)seg_buf);
1005 /* BS11 wants CR + LF in excess of the TLV length !?! */
1006 tlv[1] -= 2;
1007
1008 /* we only now know the exact length for the OM hdr */
1009 len = strlen(line_buf)+2;
1010 break;
1011 default:
1012 /* FIXME: Other BTS types */
1013 return -1;
Harald Welte4724f992009-01-18 18:01:49 +00001014 }
Harald Welte4724f992009-01-18 18:01:49 +00001015
Harald Welte4724f992009-01-18 18:01:49 +00001016 fill_om_fom_hdr(oh, len, NM_MT_LOAD_SEG, sw->obj_class,
1017 sw->obj_instance[0], sw->obj_instance[1],
1018 sw->obj_instance[2]);
1019
1020 return abis_nm_sendmsg(sw->bts, msg);
1021}
1022
1023/* 6.2.4 / 8.3.4 Load Data End */
1024static int sw_load_end(struct abis_nm_sw *sw)
1025{
1026 struct abis_om_hdr *oh;
1027 struct msgb *msg = nm_msgb_alloc();
1028 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
1029
1030 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1031 fill_om_fom_hdr(oh, len, NM_MT_LOAD_END, sw->obj_class,
1032 sw->obj_instance[0], sw->obj_instance[1],
1033 sw->obj_instance[2]);
1034
1035 /* FIXME: this is BS11 specific format */
1036 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1037 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1038 sw->file_version);
1039
1040 return abis_nm_sendmsg(sw->bts, msg);
1041}
Harald Welte5e4d1b32009-02-01 13:36:56 +00001042
Harald Welte52b1f982008-12-23 20:25:15 +00001043/* Activate the specified software into the BTS */
Harald Welte4724f992009-01-18 18:01:49 +00001044static int sw_activate(struct abis_nm_sw *sw)
Harald Welte52b1f982008-12-23 20:25:15 +00001045{
Harald Welte4724f992009-01-18 18:01:49 +00001046 struct abis_om_hdr *oh;
1047 struct msgb *msg = nm_msgb_alloc();
1048 u_int8_t len = 2*2 + sw->file_id_len + sw->file_version_len;
Harald Welte52b1f982008-12-23 20:25:15 +00001049
Harald Welte4724f992009-01-18 18:01:49 +00001050 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1051 fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, sw->obj_class,
1052 sw->obj_instance[0], sw->obj_instance[1],
1053 sw->obj_instance[2]);
1054
1055 /* FIXME: this is BS11 specific format */
1056 msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id);
1057 msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len,
1058 sw->file_version);
1059
1060 return abis_nm_sendmsg(sw->bts, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001061}
Harald Welte4724f992009-01-18 18:01:49 +00001062
1063static int sw_open_file(struct abis_nm_sw *sw, const char *fname)
1064{
1065 char file_id[12+1];
1066 char file_version[80+1];
1067 int rc;
1068
1069 sw->fd = open(fname, O_RDONLY);
1070 if (sw->fd < 0)
1071 return sw->fd;
1072
1073 switch (sw->bts->type) {
1074 case GSM_BTS_TYPE_BS11:
1075 sw->stream = fdopen(sw->fd, "r");
1076 if (!sw->stream) {
1077 perror("fdopen");
1078 return -1;
1079 }
1080 /* read first line and parse file ID and VERSION */
Harald Welte3b8ba212009-01-29 12:27:58 +00001081 rc = fscanf(sw->stream, "@(#)%12s:%80s\r\n",
Harald Welte4724f992009-01-18 18:01:49 +00001082 file_id, file_version);
1083 if (rc != 2) {
1084 perror("parsing header line of software file");
1085 return -1;
1086 }
1087 strcpy((char *)sw->file_id, file_id);
1088 sw->file_id_len = strlen(file_id);
1089 strcpy((char *)sw->file_version, file_version);
1090 sw->file_version_len = strlen(file_version);
1091 /* rewind to start of file */
Harald Welte3b8ba212009-01-29 12:27:58 +00001092 rewind(sw->stream);
Harald Welte4724f992009-01-18 18:01:49 +00001093 break;
1094 default:
1095 /* We don't know how to treat them yet */
1096 close(sw->fd);
1097 return -EINVAL;
1098 }
1099
1100 return 0;
1101}
1102
1103static void sw_close_file(struct abis_nm_sw *sw)
1104{
1105 switch (sw->bts->type) {
1106 case GSM_BTS_TYPE_BS11:
1107 fclose(sw->stream);
1108 break;
1109 default:
1110 close(sw->fd);
1111 break;
1112 }
1113}
1114
1115/* Fill the window */
1116static int sw_fill_window(struct abis_nm_sw *sw)
1117{
1118 int rc;
1119
1120 while (sw->seg_in_window < sw->window_size) {
1121 rc = sw_load_segment(sw);
1122 if (rc < 0)
1123 return rc;
Harald Welte1602ade2009-01-29 21:12:39 +00001124 if (sw->last_seg)
1125 break;
Harald Welte4724f992009-01-18 18:01:49 +00001126 }
1127 return 0;
1128}
1129
1130/* callback function from abis_nm_rcvmsg() handler */
1131static int abis_nm_rcvmsg_sw(struct msgb *mb)
1132{
1133 struct abis_om_fom_hdr *foh = msgb_l3(mb);
1134 int rc = -1;
1135 struct abis_nm_sw *sw = &g_sw;
1136 enum sw_state old_state = sw->state;
1137
Harald Welte3ffd1372009-02-01 22:15:49 +00001138 //DEBUGP(DNM, "state %u, NM MT 0x%02x\n", sw->state, foh->msg_type);
Harald Welte4724f992009-01-18 18:01:49 +00001139
1140 switch (sw->state) {
1141 case SW_STATE_WAIT_INITACK:
1142 switch (foh->msg_type) {
1143 case NM_MT_LOAD_INIT_ACK:
1144 /* fill window with segments */
Harald Welte5e4d1b32009-02-01 13:36:56 +00001145 if (sw->cbfn)
1146 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1147 NM_MT_LOAD_INIT_ACK, mb,
1148 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001149 rc = sw_fill_window(sw);
1150 sw->state = SW_STATE_WAIT_SEGACK;
1151 break;
1152 case NM_MT_LOAD_INIT_NACK:
Harald Welte3ffd1372009-02-01 22:15:49 +00001153 if (sw->forced) {
1154 DEBUGP(DNM, "FORCED: Ignoring Software Load "
1155 "Init NACK\n");
1156 if (sw->cbfn)
1157 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1158 NM_MT_LOAD_INIT_ACK, mb,
1159 sw->cb_data, NULL);
1160 rc = sw_fill_window(sw);
1161 sw->state = SW_STATE_WAIT_SEGACK;
1162 } else {
1163 DEBUGP(DNM, "Software Load Init NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001164 /* FIXME: cause */
Harald Welte3ffd1372009-02-01 22:15:49 +00001165 if (sw->cbfn)
1166 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1167 NM_MT_LOAD_INIT_NACK, mb,
1168 sw->cb_data, NULL);
1169 sw->state = SW_STATE_ERROR;
1170 }
Harald Welte4724f992009-01-18 18:01:49 +00001171 break;
1172 }
1173 break;
1174 case SW_STATE_WAIT_SEGACK:
1175 switch (foh->msg_type) {
1176 case NM_MT_LOAD_SEG_ACK:
Harald Welte3ffd1372009-02-01 22:15:49 +00001177 if (sw->cbfn)
1178 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1179 NM_MT_LOAD_SEG_ACK, mb,
1180 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001181 sw->seg_in_window = 0;
Harald Welte1602ade2009-01-29 21:12:39 +00001182 if (!sw->last_seg) {
1183 /* fill window with more segments */
1184 rc = sw_fill_window(sw);
1185 sw->state = SW_STATE_WAIT_SEGACK;
1186 } else {
1187 /* end the transfer */
1188 sw->state = SW_STATE_WAIT_ENDACK;
1189 rc = sw_load_end(sw);
1190 }
Harald Welte4724f992009-01-18 18:01:49 +00001191 break;
1192 }
1193 break;
1194 case SW_STATE_WAIT_ENDACK:
1195 switch (foh->msg_type) {
1196 case NM_MT_LOAD_END_ACK:
1197 sw_close_file(sw);
Harald Welte5e4d1b32009-02-01 13:36:56 +00001198 DEBUGP(DNM, "Software Load End (BTS %u)\n",
1199 sw->bts->nr);
1200 sw->state = SW_STATE_NONE;
1201 if (sw->cbfn)
1202 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1203 NM_MT_LOAD_END_ACK, mb,
1204 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001205 break;
1206 case NM_MT_LOAD_END_NACK:
Holger Freyther31338a12009-02-06 17:43:50 +00001207 if (sw->forced) {
1208 DEBUGP(DNM, "FORCED: Ignoring Software Load"
1209 "End NACK\n");
1210 sw->state = SW_STATE_NONE;
1211 if (sw->cbfn)
1212 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1213 NM_MT_LOAD_END_ACK, mb,
1214 sw->cb_data, NULL);
1215 } else {
1216 DEBUGP(DNM, "Software Load End NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001217 /* FIXME: cause */
Holger Freyther31338a12009-02-06 17:43:50 +00001218 sw->state = SW_STATE_ERROR;
1219 if (sw->cbfn)
1220 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1221 NM_MT_LOAD_END_NACK, mb,
1222 sw->cb_data, NULL);
1223 }
Harald Welte4724f992009-01-18 18:01:49 +00001224 break;
1225 }
1226 case SW_STATE_WAIT_ACTACK:
1227 switch (foh->msg_type) {
1228 case NM_MT_ACTIVATE_SW_ACK:
1229 /* we're done */
Harald Welte5e4d1b32009-02-01 13:36:56 +00001230 DEBUGP(DNM, "Activate Software DONE!\n");
Harald Welte4724f992009-01-18 18:01:49 +00001231 sw->state = SW_STATE_NONE;
1232 rc = 0;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001233 if (sw->cbfn)
1234 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1235 NM_MT_ACTIVATE_SW_ACK, mb,
1236 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001237 break;
1238 case NM_MT_ACTIVATE_SW_NACK:
Harald Welte1602ade2009-01-29 21:12:39 +00001239 DEBUGP(DNM, "Activate Software NACK\n");
Harald Welte6c96ba52009-05-01 13:03:40 +00001240 /* FIXME: cause */
Harald Welte4724f992009-01-18 18:01:49 +00001241 sw->state = SW_STATE_ERROR;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001242 if (sw->cbfn)
1243 sw->cbfn(GSM_HOOK_NM_SWLOAD,
1244 NM_MT_ACTIVATE_SW_NACK, mb,
1245 sw->cb_data, NULL);
Harald Welte4724f992009-01-18 18:01:49 +00001246 break;
1247 }
1248 case SW_STATE_NONE:
1249 case SW_STATE_ERROR:
1250 break;
1251 }
1252
1253 if (rc)
1254 fprintf(stderr, "unexpected NM MT 0x%02x in state %u -> %u\n",
1255 foh->msg_type, old_state, sw->state);
1256
1257 return rc;
1258}
1259
1260/* Load the specified software into the BTS */
1261int abis_nm_software_load(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00001262 u_int8_t win_size, int forced,
1263 gsm_cbfn *cbfn, void *cb_data)
Harald Welte4724f992009-01-18 18:01:49 +00001264{
1265 struct abis_nm_sw *sw = &g_sw;
1266 int rc;
1267
Harald Welte5e4d1b32009-02-01 13:36:56 +00001268 DEBUGP(DNM, "Software Load (BTS %u, File \"%s\")\n",
1269 bts->nr, fname);
1270
Harald Welte4724f992009-01-18 18:01:49 +00001271 if (sw->state != SW_STATE_NONE)
1272 return -EBUSY;
1273
1274 sw->bts = bts;
1275 sw->obj_class = NM_OC_SITE_MANAGER;
1276 sw->obj_instance[0] = 0xff;
1277 sw->obj_instance[1] = 0xff;
1278 sw->obj_instance[2] = 0xff;
1279 sw->window_size = win_size;
1280 sw->state = SW_STATE_WAIT_INITACK;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001281 sw->cbfn = cbfn;
1282 sw->cb_data = cb_data;
Harald Welte3ffd1372009-02-01 22:15:49 +00001283 sw->forced = forced;
Harald Welte4724f992009-01-18 18:01:49 +00001284
1285 rc = sw_open_file(sw, fname);
1286 if (rc < 0) {
1287 sw->state = SW_STATE_NONE;
1288 return rc;
1289 }
1290
1291 return sw_load_init(sw);
1292}
Harald Welte52b1f982008-12-23 20:25:15 +00001293
Harald Welte1602ade2009-01-29 21:12:39 +00001294int abis_nm_software_load_status(struct gsm_bts *bts)
1295{
1296 struct abis_nm_sw *sw = &g_sw;
1297 struct stat st;
1298 int rc, percent;
1299
1300 rc = fstat(sw->fd, &st);
1301 if (rc < 0) {
1302 perror("ERROR during stat");
1303 return rc;
1304 }
1305
1306 percent = (ftell(sw->stream) * 100) / st.st_size;
1307 return percent;
1308}
1309
Harald Welte5e4d1b32009-02-01 13:36:56 +00001310/* Activate the specified software into the BTS */
1311int abis_nm_software_activate(struct gsm_bts *bts, const char *fname,
1312 gsm_cbfn *cbfn, void *cb_data)
1313{
1314 struct abis_nm_sw *sw = &g_sw;
1315 int rc;
1316
1317 DEBUGP(DNM, "Activating Software (BTS %u, File \"%s\")\n",
1318 bts->nr, fname);
1319
1320 if (sw->state != SW_STATE_NONE)
1321 return -EBUSY;
1322
1323 sw->bts = bts;
1324 sw->obj_class = NM_OC_SITE_MANAGER;
1325 sw->obj_instance[0] = 0xff;
1326 sw->obj_instance[1] = 0xff;
1327 sw->obj_instance[2] = 0xff;
1328 sw->state = SW_STATE_WAIT_ACTACK;
1329 sw->cbfn = cbfn;
1330 sw->cb_data = cb_data;
1331
1332 /* Open the file in order to fill some sw struct members */
1333 rc = sw_open_file(sw, fname);
1334 if (rc < 0) {
1335 sw->state = SW_STATE_NONE;
1336 return rc;
1337 }
1338 sw_close_file(sw);
1339
1340 return sw_activate(sw);
1341}
1342
Harald Welte8470bf22008-12-25 23:28:35 +00001343static void fill_nm_channel(struct abis_nm_channel *ch, u_int8_t bts_port,
Harald Welte52b1f982008-12-23 20:25:15 +00001344 u_int8_t ts_nr, u_int8_t subslot_nr)
1345{
Harald Welteadaf08b2009-01-18 11:08:10 +00001346 ch->attrib = NM_ATT_ABIS_CHANNEL;
Harald Welte52b1f982008-12-23 20:25:15 +00001347 ch->bts_port = bts_port;
1348 ch->timeslot = ts_nr;
1349 ch->subslot = subslot_nr;
1350}
1351
1352int abis_nm_establish_tei(struct gsm_bts *bts, u_int8_t trx_nr,
1353 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot,
1354 u_int8_t tei)
1355{
1356 struct abis_om_hdr *oh;
1357 struct abis_nm_channel *ch;
Harald Welte702d8702008-12-26 20:25:35 +00001358 u_int8_t len = sizeof(*ch) + 2;
Harald Welte8470bf22008-12-25 23:28:35 +00001359 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001360
1361 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1362 fill_om_fom_hdr(oh, len, NM_MT_ESTABLISH_TEI, NM_OC_RADIO_CARRIER,
1363 bts->bts_nr, trx_nr, 0xff);
1364
Harald Welte8470bf22008-12-25 23:28:35 +00001365 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte52b1f982008-12-23 20:25:15 +00001366
1367 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1368 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1369
1370 return abis_nm_sendmsg(bts, msg);
1371}
1372
1373/* connect signalling of one (BTS,TRX) to a particular timeslot on the E1 */
1374int abis_nm_conn_terr_sign(struct gsm_bts_trx *trx,
1375 u_int8_t e1_port, u_int8_t e1_timeslot, u_int8_t e1_subslot)
1376{
Harald Welte8470bf22008-12-25 23:28:35 +00001377 struct gsm_bts *bts = trx->bts;
Harald Welte52b1f982008-12-23 20:25:15 +00001378 struct abis_om_hdr *oh;
1379 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +00001380 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001381
1382 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001383 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_SIGN,
Harald Welte52b1f982008-12-23 20:25:15 +00001384 NM_OC_RADIO_CARRIER, bts->bts_nr, trx->nr, 0xff);
1385
1386 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1387 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1388
1389 return abis_nm_sendmsg(bts, msg);
1390}
1391
1392#if 0
1393int abis_nm_disc_terr_sign(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1394 struct abis_nm_abis_channel *chan)
1395{
1396}
1397#endif
1398
1399int abis_nm_conn_terr_traf(struct gsm_bts_trx_ts *ts,
1400 u_int8_t e1_port, u_int8_t e1_timeslot,
1401 u_int8_t e1_subslot)
1402{
1403 struct gsm_bts *bts = ts->trx->bts;
1404 struct abis_om_hdr *oh;
1405 struct abis_nm_channel *ch;
Harald Welte8470bf22008-12-25 23:28:35 +00001406 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001407
1408 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1409 fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_TRAF,
Harald Welteb110cee2009-02-18 03:42:35 +00001410 NM_OC_CHANNEL, bts->bts_nr, ts->trx->nr, ts->nr);
Harald Welte52b1f982008-12-23 20:25:15 +00001411
1412 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1413 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
1414
Harald Weltef325eb42009-02-19 17:07:39 +00001415 DEBUGP(DNM, "CONNECT TERR TRAF Um=%s E1=(%u,%u,%u)\n",
1416 gsm_ts_name(ts),
Harald Welteb110cee2009-02-18 03:42:35 +00001417 e1_port, e1_timeslot, e1_subslot);
1418
Harald Welte52b1f982008-12-23 20:25:15 +00001419 return abis_nm_sendmsg(bts, msg);
1420}
1421
1422#if 0
1423int abis_nm_disc_terr_traf(struct abis_nm_h *h, struct abis_om_obj_inst *inst,
1424 struct abis_nm_abis_channel *chan,
1425 u_int8_t subchan)
1426{
1427}
1428#endif
1429
Harald Welte22af0db2009-02-14 15:41:08 +00001430/* Chapter 8.6.1 */
1431int abis_nm_set_bts_attr(struct gsm_bts *bts, u_int8_t *attr, int attr_len)
1432{
1433 struct abis_om_hdr *oh;
1434 struct msgb *msg = nm_msgb_alloc();
1435 u_int8_t *cur;
1436
1437 DEBUGP(DNM, "Set BTS Attr (bts=%d)\n", bts->nr);
1438
1439 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte191280d2009-05-01 13:20:04 +00001440 fill_om_fom_hdr(oh, attr_len, NM_MT_SET_BTS_ATTR, NM_OC_BTS, bts->bts_nr, 0xff, 0xff);
Harald Welte22af0db2009-02-14 15:41:08 +00001441 cur = msgb_put(msg, attr_len);
1442 memcpy(cur, attr, attr_len);
1443
1444 return abis_nm_sendmsg(bts, msg);
1445}
1446
1447/* Chapter 8.6.2 */
1448int abis_nm_set_radio_attr(struct gsm_bts_trx *trx, u_int8_t *attr, int attr_len)
1449{
1450 struct abis_om_hdr *oh;
1451 struct msgb *msg = nm_msgb_alloc();
1452 u_int8_t *cur;
1453
1454 DEBUGP(DNM, "Set TRX Attr (bts=%d,trx=%d)\n", trx->bts->nr, trx->nr);
1455
1456 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1457 fill_om_fom_hdr(oh, attr_len, NM_MT_SET_RADIO_ATTR, NM_OC_RADIO_CARRIER,
Harald Welte191280d2009-05-01 13:20:04 +00001458 trx->bts->bts_nr, trx->nr, 0xff);
Harald Welte22af0db2009-02-14 15:41:08 +00001459 cur = msgb_put(msg, attr_len);
1460 memcpy(cur, attr, attr_len);
1461
1462 return abis_nm_sendmsg(trx->bts, msg);
1463}
1464
1465/* Chapter 8.6.3 */
Harald Welte52b1f982008-12-23 20:25:15 +00001466int abis_nm_set_channel_attr(struct gsm_bts_trx_ts *ts, u_int8_t chan_comb)
1467{
1468 struct gsm_bts *bts = ts->trx->bts;
1469 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001470 u_int16_t arfcn = htons(ts->trx->arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001471 u_int8_t zero = 0x00;
Harald Welte8470bf22008-12-25 23:28:35 +00001472 struct msgb *msg = nm_msgb_alloc();
Harald Weltee0590df2009-02-15 03:34:15 +00001473 u_int8_t len = 2 + 2;
1474
1475 if (bts->type == GSM_BTS_TYPE_BS11)
1476 len += 4 + 2 + 2 + 3;
Harald Welte52b1f982008-12-23 20:25:15 +00001477
Harald Weltef325eb42009-02-19 17:07:39 +00001478 DEBUGP(DNM, "Set Chan Attr %s\n", gsm_ts_name(ts));
Harald Welte22af0db2009-02-14 15:41:08 +00001479
Harald Welte52b1f982008-12-23 20:25:15 +00001480 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001481 fill_om_fom_hdr(oh, len, NM_MT_SET_CHAN_ATTR,
Holger Freyther6b2d2622009-02-14 23:16:59 +00001482 NM_OC_CHANNEL, bts->bts_nr,
Harald Welte52b1f982008-12-23 20:25:15 +00001483 ts->trx->nr, ts->nr);
1484 /* FIXME: don't send ARFCN list, hopping sequence, mAIO, ...*/
Harald Weltee0590df2009-02-15 03:34:15 +00001485 if (bts->type == GSM_BTS_TYPE_BS11)
1486 msgb_tlv16_put(msg, NM_ATT_ARFCN_LIST, 1, &arfcn);
Harald Welte52b1f982008-12-23 20:25:15 +00001487 msgb_tv_put(msg, NM_ATT_CHAN_COMB, chan_comb);
Harald Weltee0590df2009-02-15 03:34:15 +00001488 if (bts->type == GSM_BTS_TYPE_BS11) {
1489 msgb_tv_put(msg, NM_ATT_HSN, 0x00);
1490 msgb_tv_put(msg, NM_ATT_MAIO, 0x00);
1491 }
Harald Welte52b1f982008-12-23 20:25:15 +00001492 msgb_tv_put(msg, NM_ATT_TSC, 0x07); /* training sequence */
Harald Weltee0590df2009-02-15 03:34:15 +00001493 if (bts->type == GSM_BTS_TYPE_BS11)
1494 msgb_tlv_put(msg, 0x59, 1, &zero);
Harald Welte52b1f982008-12-23 20:25:15 +00001495
1496 return abis_nm_sendmsg(bts, msg);
1497}
1498
Harald Welte34a99682009-02-13 02:41:40 +00001499int 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 +00001500 u_int8_t i2, u_int8_t i3, int nack, u_int8_t *attr, int att_len)
Harald Welte34a99682009-02-13 02:41:40 +00001501{
1502 struct abis_om_hdr *oh;
1503 struct msgb *msg = nm_msgb_alloc();
Harald Welte5c1e4582009-02-15 11:57:29 +00001504 u_int8_t msgtype = NM_MT_SW_ACT_REQ_ACK;
1505 u_int8_t len = att_len;
1506
1507 if (nack) {
1508 len += 2;
1509 msgtype = NM_MT_SW_ACT_REQ_NACK;
1510 }
Harald Welte34a99682009-02-13 02:41:40 +00001511
1512 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte5c1e4582009-02-15 11:57:29 +00001513 fill_om_fom_hdr(oh, att_len, msgtype, obj_class, i1, i2, i3);
1514
Harald Welte34a99682009-02-13 02:41:40 +00001515 if (attr) {
1516 u_int8_t *ptr = msgb_put(msg, att_len);
1517 memcpy(ptr, attr, att_len);
1518 }
Harald Welte5c1e4582009-02-15 11:57:29 +00001519 if (nack)
1520 msgb_tv_put(msg, NM_ATT_NACK_CAUSES, NM_NACK_OBJCLASS_NOTSUPP);
Harald Welte34a99682009-02-13 02:41:40 +00001521
1522 return abis_nm_sendmsg(bts, msg);
1523}
1524
Harald Welte8470bf22008-12-25 23:28:35 +00001525int abis_nm_raw_msg(struct gsm_bts *bts, int len, u_int8_t *rawmsg)
Harald Welte52b1f982008-12-23 20:25:15 +00001526{
Harald Welte8470bf22008-12-25 23:28:35 +00001527 struct msgb *msg = nm_msgb_alloc();
1528 struct abis_om_hdr *oh;
Harald Welte52b1f982008-12-23 20:25:15 +00001529 u_int8_t *data;
1530
1531 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
1532 fill_om_hdr(oh, len);
1533 data = msgb_put(msg, len);
Harald Weltead384642008-12-26 10:20:07 +00001534 memcpy(data, rawmsg, len);
Harald Welte52b1f982008-12-23 20:25:15 +00001535
1536 return abis_nm_sendmsg(bts, msg);
1537}
1538
1539/* Siemens specific commands */
1540static int __simple_cmd(struct gsm_bts *bts, u_int8_t msg_type)
1541{
1542 struct abis_om_hdr *oh;
Harald Welte8470bf22008-12-25 23:28:35 +00001543 struct msgb *msg = nm_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +00001544
1545 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte702d8702008-12-26 20:25:35 +00001546 fill_om_fom_hdr(oh, 0, msg_type, NM_OC_SITE_MANAGER,
Harald Welte52b1f982008-12-23 20:25:15 +00001547 0xff, 0xff, 0xff);
1548
1549 return abis_nm_sendmsg(bts, msg);
1550}
1551
Harald Welte34a99682009-02-13 02:41:40 +00001552/* Chapter 8.9.2 */
1553int abis_nm_opstart(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0, u_int8_t i1, u_int8_t i2)
1554{
1555 struct abis_om_hdr *oh;
1556 struct msgb *msg = nm_msgb_alloc();
1557
Harald Welte22af0db2009-02-14 15:41:08 +00001558 DEBUGP(DNM, "Sending OPSTART obj_class=0x%02x obj_inst=(0x%02x, 0x%02x, 0x%02x)\n",
1559 obj_class, i0, i1, i2);
Harald Welte34a99682009-02-13 02:41:40 +00001560 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1561 fill_om_fom_hdr(oh, 0, NM_MT_OPSTART, obj_class, i0, i1, i2);
1562
1563 return abis_nm_sendmsg(bts, msg);
1564}
1565
1566/* Chapter 8.8.5 */
1567int abis_nm_chg_adm_state(struct gsm_bts *bts, u_int8_t obj_class, u_int8_t i0,
1568 u_int8_t i1, u_int8_t i2, u_int8_t adm_state)
1569{
1570 struct abis_om_hdr *oh;
1571 struct msgb *msg = nm_msgb_alloc();
1572
1573 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1574 fill_om_fom_hdr(oh, 2, NM_MT_CHG_ADM_STATE, obj_class, i0, i1, i2);
1575 msgb_tv_put(msg, NM_ATT_ADM_STATE, adm_state);
1576
1577 return abis_nm_sendmsg(bts, msg);
1578}
1579
1580
Harald Welte52b1f982008-12-23 20:25:15 +00001581int abis_nm_event_reports(struct gsm_bts *bts, int on)
1582{
1583 if (on == 0)
Harald Welte227d4072009-01-03 08:16:25 +00001584 return __simple_cmd(bts, NM_MT_STOP_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001585 else
Harald Welte227d4072009-01-03 08:16:25 +00001586 return __simple_cmd(bts, NM_MT_REST_EVENT_REP);
Harald Welte52b1f982008-12-23 20:25:15 +00001587}
1588
Harald Welte47d88ae2009-01-04 12:02:08 +00001589/* Siemens (or BS-11) specific commands */
1590
Harald Welte3ffd1372009-02-01 22:15:49 +00001591int abis_nm_bs11_bsc_disconnect(struct gsm_bts *bts, int reconnect)
1592{
1593 if (reconnect == 0)
1594 return __simple_cmd(bts, NM_MT_BS11_DISCONNECT);
1595 else
1596 return __simple_cmd(bts, NM_MT_BS11_RECONNECT);
1597}
1598
Harald Welteb8427972009-02-05 19:27:17 +00001599int abis_nm_bs11_restart(struct gsm_bts *bts)
1600{
1601 return __simple_cmd(bts, NM_MT_BS11_RESTART);
1602}
1603
1604
Harald Welte268bb402009-02-01 19:11:56 +00001605struct bs11_date_time {
1606 u_int16_t year;
1607 u_int8_t month;
1608 u_int8_t day;
1609 u_int8_t hour;
1610 u_int8_t min;
1611 u_int8_t sec;
1612} __attribute__((packed));
1613
1614
1615void get_bs11_date_time(struct bs11_date_time *aet)
1616{
1617 time_t t;
1618 struct tm *tm;
1619
1620 t = time(NULL);
1621 tm = localtime(&t);
1622 aet->sec = tm->tm_sec;
1623 aet->min = tm->tm_min;
1624 aet->hour = tm->tm_hour;
1625 aet->day = tm->tm_mday;
1626 aet->month = tm->tm_mon;
1627 aet->year = htons(1900 + tm->tm_year);
1628}
1629
Harald Welte05188ee2009-01-18 11:39:08 +00001630int abis_nm_bs11_reset_resource(struct gsm_bts *bts)
Harald Welte52b1f982008-12-23 20:25:15 +00001631{
Harald Welte4668fda2009-01-03 08:19:29 +00001632 return __simple_cmd(bts, NM_MT_BS11_RESET_RESOURCE);
Harald Welte52b1f982008-12-23 20:25:15 +00001633}
1634
Harald Welte05188ee2009-01-18 11:39:08 +00001635int abis_nm_bs11_db_transmission(struct gsm_bts *bts, int begin)
Harald Welte52b1f982008-12-23 20:25:15 +00001636{
1637 if (begin)
Harald Welte4668fda2009-01-03 08:19:29 +00001638 return __simple_cmd(bts, NM_MT_BS11_BEGIN_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00001639 else
Harald Welte4668fda2009-01-03 08:19:29 +00001640 return __simple_cmd(bts, NM_MT_BS11_END_DB_TX);
Harald Welte52b1f982008-12-23 20:25:15 +00001641}
Harald Welte47d88ae2009-01-04 12:02:08 +00001642
Harald Welte05188ee2009-01-18 11:39:08 +00001643int abis_nm_bs11_create_object(struct gsm_bts *bts,
Harald Welte1bc09062009-01-18 14:17:52 +00001644 enum abis_bs11_objtype type, u_int8_t idx,
1645 u_int8_t attr_len, const u_int8_t *attr)
Harald Welte47d88ae2009-01-04 12:02:08 +00001646{
1647 struct abis_om_hdr *oh;
1648 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00001649 u_int8_t *cur;
Harald Welte47d88ae2009-01-04 12:02:08 +00001650
1651 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001652 fill_om_fom_hdr(oh, attr_len, NM_MT_BS11_CREATE_OBJ,
Harald Welte268bb402009-02-01 19:11:56 +00001653 NM_OC_BS11, type, 0, idx);
Harald Welte1bc09062009-01-18 14:17:52 +00001654 cur = msgb_put(msg, attr_len);
1655 memcpy(cur, attr, attr_len);
Harald Welte47d88ae2009-01-04 12:02:08 +00001656
1657 return abis_nm_sendmsg(bts, msg);
1658}
1659
Harald Welte78fc0d42009-02-19 02:50:57 +00001660int abis_nm_bs11_delete_object(struct gsm_bts *bts,
1661 enum abis_bs11_objtype type, u_int8_t idx)
1662{
1663 struct abis_om_hdr *oh;
1664 struct msgb *msg = nm_msgb_alloc();
1665
1666 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1667 fill_om_fom_hdr(oh, 0, NM_MT_BS11_DELETE_OBJ,
1668 NM_OC_BS11, type, 0, idx);
1669
1670 return abis_nm_sendmsg(bts, msg);
1671}
1672
Harald Welte05188ee2009-01-18 11:39:08 +00001673int abis_nm_bs11_create_envaBTSE(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00001674{
1675 struct abis_om_hdr *oh;
1676 struct msgb *msg = nm_msgb_alloc();
Harald Welte1bc09062009-01-18 14:17:52 +00001677 u_int8_t zero = 0x00;
Harald Welte47d88ae2009-01-04 12:02:08 +00001678
1679 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001680 fill_om_fom_hdr(oh, 3, NM_MT_BS11_CREATE_OBJ,
Harald Welte1bc09062009-01-18 14:17:52 +00001681 NM_OC_BS11_ENVABTSE, 0, idx, 0xff);
1682 msgb_tlv_put(msg, 0x99, 1, &zero);
Harald Welte47d88ae2009-01-04 12:02:08 +00001683
1684 return abis_nm_sendmsg(bts, msg);
1685}
1686
Harald Welte05188ee2009-01-18 11:39:08 +00001687int abis_nm_bs11_create_bport(struct gsm_bts *bts, u_int8_t idx)
Harald Welte47d88ae2009-01-04 12:02:08 +00001688{
1689 struct abis_om_hdr *oh;
1690 struct msgb *msg = nm_msgb_alloc();
1691
1692 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1693 fill_om_fom_hdr(oh, 0, NM_MT_BS11_CREATE_OBJ, NM_OC_BS11_BPORT,
1694 idx, 0, 0);
1695
1696 return abis_nm_sendmsg(bts, msg);
1697}
Harald Welte05188ee2009-01-18 11:39:08 +00001698
Harald Welte78fc0d42009-02-19 02:50:57 +00001699static const u_int8_t sm_attr[] = { NM_ATT_TEI, NM_ATT_ABIS_CHANNEL };
1700int abis_nm_bs11_get_oml_tei_ts(struct gsm_bts *bts)
1701{
1702 struct abis_om_hdr *oh;
1703 struct msgb *msg = nm_msgb_alloc();
1704
1705 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1706 fill_om_fom_hdr(oh, 2+sizeof(sm_attr), NM_MT_GET_ATTR, NM_OC_SITE_MANAGER,
1707 0xff, 0xff, 0xff);
1708 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(sm_attr), sm_attr);
1709
1710 return abis_nm_sendmsg(bts, msg);
1711}
1712
Harald Welteb6c92ae2009-02-21 20:15:32 +00001713/* like abis_nm_conn_terr_traf + set_tei */
1714int abis_nm_bs11_conn_oml_tei(struct gsm_bts *bts, u_int8_t e1_port,
1715 u_int8_t e1_timeslot, u_int8_t e1_subslot,
1716 u_int8_t tei)
Harald Welte05188ee2009-01-18 11:39:08 +00001717{
1718 struct abis_om_hdr *oh;
1719 struct abis_nm_channel *ch;
1720 struct msgb *msg = nm_msgb_alloc();
1721
1722 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welteb6c92ae2009-02-21 20:15:32 +00001723 fill_om_fom_hdr(oh, sizeof(*ch)+2, NM_MT_BS11_SET_ATTR,
Harald Welte05188ee2009-01-18 11:39:08 +00001724 NM_OC_SITE_MANAGER, 0xff, 0xff, 0xff);
1725
1726 ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch));
1727 fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot);
Harald Welteb6c92ae2009-02-21 20:15:32 +00001728 msgb_tv_put(msg, NM_ATT_TEI, tei);
Harald Welte05188ee2009-01-18 11:39:08 +00001729
1730 return abis_nm_sendmsg(bts, msg);
1731}
1732
1733int abis_nm_bs11_set_trx_power(struct gsm_bts_trx *trx, u_int8_t level)
1734{
1735 struct abis_om_hdr *oh;
1736 struct msgb *msg = nm_msgb_alloc();
Harald Welte05188ee2009-01-18 11:39:08 +00001737
1738 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001739 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR,
Harald Welte05188ee2009-01-18 11:39:08 +00001740 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
1741 msgb_tlv_put(msg, NM_ATT_BS11_TXPWR, 1, &level);
1742
1743 return abis_nm_sendmsg(trx->bts, msg);
1744}
1745
Harald Welte78fc0d42009-02-19 02:50:57 +00001746int abis_nm_bs11_get_trx_power(struct gsm_bts_trx *trx)
1747{
1748 struct abis_om_hdr *oh;
1749 struct msgb *msg = nm_msgb_alloc();
1750 u_int8_t attr = NM_ATT_BS11_TXPWR;
1751
1752 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1753 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
1754 NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr);
1755 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), &attr);
1756
1757 return abis_nm_sendmsg(trx->bts, msg);
1758}
1759
Harald Welteaaf02d92009-04-29 13:25:57 +00001760int abis_nm_bs11_get_pll_mode(struct gsm_bts *bts)
1761{
1762 struct abis_om_hdr *oh;
1763 struct msgb *msg = nm_msgb_alloc();
Harald Weltea7cfa032009-04-29 22:33:02 +00001764 u_int8_t attr[] = { NM_ATT_BS11_PLL_MODE };
Harald Welteaaf02d92009-04-29 13:25:57 +00001765
1766 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1767 fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR,
1768 NM_OC_BS11, BS11_OBJ_LI, 0x00, 0x00);
Harald Welteaeedeb42009-05-01 13:08:14 +00001769 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), attr);
Harald Welteaaf02d92009-04-29 13:25:57 +00001770
1771 return abis_nm_sendmsg(bts, msg);
1772}
1773
1774
Harald Welte268bb402009-02-01 19:11:56 +00001775//static const u_int8_t bs11_logon_c7[] = { 0x07, 0xd9, 0x01, 0x11, 0x0d, 0x10, 0x20 };
Harald Weltebb151312009-01-28 20:42:07 +00001776static const u_int8_t bs11_logon_c8[] = { 0x02 };
Harald Welte05188ee2009-01-18 11:39:08 +00001777static const u_int8_t bs11_logon_c9[] = "FACTORY";
1778
Harald Welte1bc09062009-01-18 14:17:52 +00001779int abis_nm_bs11_factory_logon(struct gsm_bts *bts, int on)
Harald Welte05188ee2009-01-18 11:39:08 +00001780{
1781 struct abis_om_hdr *oh;
1782 struct msgb *msg = nm_msgb_alloc();
Harald Welte268bb402009-02-01 19:11:56 +00001783 struct bs11_date_time bdt;
1784
1785 get_bs11_date_time(&bdt);
Harald Welte05188ee2009-01-18 11:39:08 +00001786
1787 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte1bc09062009-01-18 14:17:52 +00001788 if (on) {
Harald Welte268bb402009-02-01 19:11:56 +00001789 u_int8_t len = 3*2 + sizeof(bdt)
Harald Welte6f676a32009-01-18 14:27:48 +00001790 + sizeof(bs11_logon_c8) + sizeof(bs11_logon_c9);
Harald Welte043d04a2009-01-29 23:15:30 +00001791 fill_om_fom_hdr(oh, len, NM_MT_BS11_LMT_LOGON,
Harald Welte1bc09062009-01-18 14:17:52 +00001792 NM_OC_BS11_A3, 0xff, 0xff, 0xff);
Harald Welte043d04a2009-01-29 23:15:30 +00001793 msgb_tlv_put(msg, NM_ATT_BS11_LMT_LOGIN_TIME,
Harald Welte5083b0b2009-02-02 19:20:52 +00001794 sizeof(bdt), (u_int8_t *) &bdt);
Harald Welte043d04a2009-01-29 23:15:30 +00001795 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_ACC_LEV,
1796 sizeof(bs11_logon_c8), bs11_logon_c8);
1797 msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_NAME,
1798 sizeof(bs11_logon_c9), bs11_logon_c9);
Harald Welte1bc09062009-01-18 14:17:52 +00001799 } else {
Harald Welte5e4d1b32009-02-01 13:36:56 +00001800 fill_om_fom_hdr(oh, 0, NM_MT_BS11_LMT_LOGOFF,
Harald Welte1bc09062009-01-18 14:17:52 +00001801 NM_OC_BS11_A3, 0xff, 0xff, 0xff);
1802 }
Harald Welte05188ee2009-01-18 11:39:08 +00001803
1804 return abis_nm_sendmsg(bts, msg);
1805}
Harald Welte1bc09062009-01-18 14:17:52 +00001806
1807int abis_nm_bs11_set_trx1_pw(struct gsm_bts *bts, const char *password)
1808{
1809 struct abis_om_hdr *oh;
1810 struct msgb *msg;
1811
1812 if (strlen(password) != 10)
1813 return -EINVAL;
1814
1815 msg = nm_msgb_alloc();
1816 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
Harald Welte6f676a32009-01-18 14:27:48 +00001817 fill_om_fom_hdr(oh, 2+strlen(password), NM_MT_BS11_SET_ATTR,
Harald Welte1bc09062009-01-18 14:17:52 +00001818 NM_OC_BS11, BS11_OBJ_TRX1, 0x00, 0x00);
1819 msgb_tlv_put(msg, NM_ATT_BS11_PASSWORD, 10, (const u_int8_t *)password);
1820
1821 return abis_nm_sendmsg(bts, msg);
1822}
1823
Harald Weltee69f5fb2009-04-28 16:31:38 +00001824/* change the BS-11 PLL Mode to either locked (E1 derived) or standalone */
1825int abis_nm_bs11_set_pll_locked(struct gsm_bts *bts, int locked)
1826{
1827 struct abis_om_hdr *oh;
1828 struct msgb *msg;
Harald Weltea432cd32009-04-29 13:01:50 +00001829 u_int8_t tlv_value;
Harald Weltee69f5fb2009-04-28 16:31:38 +00001830
1831 msg = nm_msgb_alloc();
1832 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
1833 fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR, NM_OC_BS11,
1834 BS11_OBJ_LI, 0x00, 0x00);
Harald Weltea432cd32009-04-29 13:01:50 +00001835
1836 if (locked)
1837 tlv_value = BS11_LI_PLL_LOCKED;
1838 else
1839 tlv_value = BS11_LI_PLL_STANDALONE;
1840
1841 msgb_tlv_put(msg, NM_ATT_BS11_PLL_MODE, 1, &tlv_value);
Harald Weltee69f5fb2009-04-28 16:31:38 +00001842
1843 return abis_nm_sendmsg(bts, msg);
1844}
1845
Harald Welte1bc09062009-01-18 14:17:52 +00001846int abis_nm_bs11_get_state(struct gsm_bts *bts)
1847{
1848 return __simple_cmd(bts, NM_MT_BS11_GET_STATE);
1849}
Harald Welte5e4d1b32009-02-01 13:36:56 +00001850
1851/* BS11 SWL */
1852
1853struct abis_nm_bs11_sw {
1854 struct gsm_bts *bts;
1855 char swl_fname[PATH_MAX];
1856 u_int8_t win_size;
Harald Welte3ffd1372009-02-01 22:15:49 +00001857 int forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001858 struct llist_head file_list;
1859 gsm_cbfn *user_cb; /* specified by the user */
1860};
1861static struct abis_nm_bs11_sw _g_bs11_sw, *g_bs11_sw = &_g_bs11_sw;
1862
1863struct file_list_entry {
1864 struct llist_head list;
1865 char fname[PATH_MAX];
1866};
1867
1868struct file_list_entry *fl_dequeue(struct llist_head *queue)
1869{
1870 struct llist_head *lh;
1871
1872 if (llist_empty(queue))
1873 return NULL;
1874
1875 lh = queue->next;
1876 llist_del(lh);
1877
1878 return llist_entry(lh, struct file_list_entry, list);
1879}
1880
1881static int bs11_read_swl_file(struct abis_nm_bs11_sw *bs11_sw)
1882{
1883 char linebuf[255];
1884 struct llist_head *lh, *lh2;
1885 FILE *swl;
1886 int rc = 0;
1887
1888 swl = fopen(bs11_sw->swl_fname, "r");
1889 if (!swl)
1890 return -ENODEV;
1891
1892 /* zero the stale file list, if any */
1893 llist_for_each_safe(lh, lh2, &bs11_sw->file_list) {
1894 llist_del(lh);
1895 free(lh);
1896 }
1897
1898 while (fgets(linebuf, sizeof(linebuf), swl)) {
1899 char file_id[12+1];
1900 char file_version[80+1];
1901 struct file_list_entry *fle;
1902 static char dir[PATH_MAX];
1903
1904 if (strlen(linebuf) < 4)
1905 continue;
Harald Welte3ffd1372009-02-01 22:15:49 +00001906
Harald Welte5e4d1b32009-02-01 13:36:56 +00001907 rc = sscanf(linebuf+4, "%12s:%80s\r\n", file_id, file_version);
1908 if (rc < 0) {
1909 perror("ERR parsing SWL file");
1910 rc = -EINVAL;
1911 goto out;
1912 }
1913 if (rc < 2)
1914 continue;
1915
1916 fle = malloc(sizeof(*fle));
1917 if (!fle) {
1918 rc = -ENOMEM;
1919 goto out;
1920 }
1921 memset(fle, 0, sizeof(*fle));
1922
1923 /* construct new filename */
1924 strncpy(dir, bs11_sw->swl_fname, sizeof(dir));
1925 strncat(fle->fname, dirname(dir), sizeof(fle->fname) - 1);
1926 strcat(fle->fname, "/");
1927 strncat(fle->fname, file_id, sizeof(fle->fname) - 1 -strlen(fle->fname));
Harald Welte5e4d1b32009-02-01 13:36:56 +00001928
1929 llist_add_tail(&fle->list, &bs11_sw->file_list);
1930 }
1931
1932out:
1933 fclose(swl);
1934 return rc;
1935}
1936
1937/* bs11 swload specific callback, passed to abis_nm core swload */
1938static int bs11_swload_cbfn(unsigned int hook, unsigned int event,
1939 struct msgb *msg, void *data, void *param)
1940{
1941 struct abis_nm_bs11_sw *bs11_sw = data;
1942 struct file_list_entry *fle;
1943 int rc = 0;
1944
Harald Welte5e4d1b32009-02-01 13:36:56 +00001945 switch (event) {
1946 case NM_MT_LOAD_END_ACK:
1947 fle = fl_dequeue(&bs11_sw->file_list);
1948 if (fle) {
1949 /* start download the next file of our file list */
1950 rc = abis_nm_software_load(bs11_sw->bts, fle->fname,
1951 bs11_sw->win_size,
Harald Welte3ffd1372009-02-01 22:15:49 +00001952 bs11_sw->forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00001953 &bs11_swload_cbfn, bs11_sw);
1954 free(fle);
1955 } else {
1956 /* activate the SWL */
1957 rc = abis_nm_software_activate(bs11_sw->bts,
1958 bs11_sw->swl_fname,
1959 bs11_swload_cbfn,
1960 bs11_sw);
1961 }
1962 break;
Harald Welte3ffd1372009-02-01 22:15:49 +00001963 case NM_MT_LOAD_SEG_ACK:
Harald Welte5e4d1b32009-02-01 13:36:56 +00001964 case NM_MT_LOAD_END_NACK:
1965 case NM_MT_LOAD_INIT_ACK:
1966 case NM_MT_LOAD_INIT_NACK:
1967 case NM_MT_ACTIVATE_SW_NACK:
1968 case NM_MT_ACTIVATE_SW_ACK:
1969 default:
1970 /* fallthrough to the user callback */
Harald Welte97ed1e72009-02-06 13:38:02 +00001971 if (bs11_sw->user_cb)
1972 rc = bs11_sw->user_cb(hook, event, msg, NULL, NULL);
Harald Welte5e4d1b32009-02-01 13:36:56 +00001973 break;
1974 }
1975
1976 return rc;
1977}
1978
1979/* Siemens provides a SWL file that is a mere listing of all the other
1980 * files that are part of a software release. We need to upload first
1981 * the list file, and then each file that is listed in the list file */
1982int abis_nm_bs11_load_swl(struct gsm_bts *bts, const char *fname,
Harald Welte3ffd1372009-02-01 22:15:49 +00001983 u_int8_t win_size, int forced, gsm_cbfn *cbfn)
Harald Welte5e4d1b32009-02-01 13:36:56 +00001984{
1985 struct abis_nm_bs11_sw *bs11_sw = g_bs11_sw;
1986 struct file_list_entry *fle;
1987 int rc = 0;
1988
1989 INIT_LLIST_HEAD(&bs11_sw->file_list);
1990 bs11_sw->bts = bts;
1991 bs11_sw->win_size = win_size;
1992 bs11_sw->user_cb = cbfn;
Harald Welte3ffd1372009-02-01 22:15:49 +00001993 bs11_sw->forced = forced;
Harald Welte5e4d1b32009-02-01 13:36:56 +00001994
1995 strncpy(bs11_sw->swl_fname, fname, sizeof(bs11_sw->swl_fname));
1996 rc = bs11_read_swl_file(bs11_sw);
1997 if (rc < 0)
1998 return rc;
1999
2000 /* dequeue next item in file list */
2001 fle = fl_dequeue(&bs11_sw->file_list);
2002 if (!fle)
2003 return -EINVAL;
2004
2005 /* start download the next file of our file list */
Harald Welte3ffd1372009-02-01 22:15:49 +00002006 rc = abis_nm_software_load(bts, fle->fname, win_size, forced,
Harald Welte5e4d1b32009-02-01 13:36:56 +00002007 bs11_swload_cbfn, bs11_sw);
2008 free(fle);
2009 return rc;
2010}
2011
Harald Welte5083b0b2009-02-02 19:20:52 +00002012#if 0
Harald Welte5e4d1b32009-02-01 13:36:56 +00002013static u_int8_t req_attr_btse[] = {
2014 NM_ATT_ADM_STATE, NM_ATT_BS11_LMT_LOGON_SESSION,
2015 NM_ATT_BS11_LMT_LOGIN_TIME, NM_ATT_BS11_LMT_USER_ACC_LEV,
2016 NM_ATT_BS11_LMT_USER_NAME,
2017
2018 0xaf, NM_ATT_BS11_RX_OFFSET, NM_ATT_BS11_VENDOR_NAME,
2019
2020 NM_ATT_BS11_SW_LOAD_INTENDED, NM_ATT_BS11_SW_LOAD_SAFETY,
2021
2022 NM_ATT_BS11_SW_LOAD_STORED };
2023
2024static u_int8_t req_attr_btsm[] = {
2025 NM_ATT_ABIS_CHANNEL, NM_ATT_TEI, NM_ATT_BS11_ABIS_EXT_TIME,
2026 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xce, NM_ATT_FILE_ID,
2027 NM_ATT_FILE_VERSION, NM_ATT_OPER_STATE, 0xe8, NM_ATT_BS11_ALL_TEST_CATG,
2028 NM_ATT_SW_DESCR, NM_ATT_GET_ARI };
Harald Welte5083b0b2009-02-02 19:20:52 +00002029#endif
Harald Welte5e4d1b32009-02-01 13:36:56 +00002030
2031static u_int8_t req_attr[] = {
2032 NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xa8, NM_ATT_OPER_STATE,
2033 0xd5, 0xa1, NM_ATT_BS11_ESN_FW_CODE_NO, NM_ATT_BS11_ESN_HW_CODE_NO,
Harald Weltea7cfa032009-04-29 22:33:02 +00002034 0x42, NM_ATT_BS11_ESN_PCB_SERIAL, NM_ATT_BS11_PLL };
Harald Welte5e4d1b32009-02-01 13:36:56 +00002035
2036int abis_nm_bs11_get_serno(struct gsm_bts *bts)
2037{
2038 struct abis_om_hdr *oh;
2039 struct msgb *msg = nm_msgb_alloc();
2040
2041 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2042 /* SiemensHW CCTRL object */
2043 fill_om_fom_hdr(oh, 2+sizeof(req_attr), NM_MT_GET_ATTR, NM_OC_BS11,
2044 0x03, 0x00, 0x00);
2045 msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(req_attr), req_attr);
2046
2047 return abis_nm_sendmsg(bts, msg);
2048}
Harald Welte268bb402009-02-01 19:11:56 +00002049
2050int abis_nm_bs11_set_ext_time(struct gsm_bts *bts)
2051{
2052 struct abis_om_hdr *oh;
2053 struct msgb *msg = nm_msgb_alloc();
2054 struct bs11_date_time aet;
2055
2056 get_bs11_date_time(&aet);
2057 oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
2058 /* SiemensHW CCTRL object */
2059 fill_om_fom_hdr(oh, 2+sizeof(aet), NM_MT_BS11_SET_ATTR, NM_OC_SITE_MANAGER,
2060 0xff, 0xff, 0xff);
Harald Welte5083b0b2009-02-02 19:20:52 +00002061 msgb_tlv_put(msg, NM_ATT_BS11_ABIS_EXT_TIME, sizeof(aet), (u_int8_t *) &aet);
Harald Welte268bb402009-02-01 19:11:56 +00002062
2063 return abis_nm_sendmsg(bts, msg);
2064}
Harald Welte5c1e4582009-02-15 11:57:29 +00002065
2066/* ip.access nanoBTS specific commands */
Harald Welte5c1e4582009-02-15 11:57:29 +00002067static const char ipaccess_magic[] = "com.ipaccess";
2068
Harald Welte677c21f2009-02-17 13:22:23 +00002069
2070static int abis_nm_rx_ipacc(struct msgb *msg)
2071{
2072 struct abis_om_hdr *oh = msgb_l2(msg);
2073 struct abis_om_fom_hdr *foh;
2074 u_int8_t idstrlen = oh->data[0];
2075 struct tlv_parsed tp;
2076
2077 if (strncmp((char *)&oh->data[1], ipaccess_magic, idstrlen)) {
2078 DEBUGP(DNM, "id string is not com.ipaccess !?!\n");
2079 return -EINVAL;
2080 }
2081
Harald Welte193fefc2009-04-30 15:16:27 +00002082 foh = (struct abis_om_fom_hdr *) (oh->data + 1 + idstrlen);
Harald Welte03133942009-02-18 19:51:53 +00002083 abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh));
Harald Welte677c21f2009-02-17 13:22:23 +00002084
Harald Welte193fefc2009-04-30 15:16:27 +00002085 DEBUGP(DNM, "IPACCESS(0x%02x): ", foh->msg_type);
2086
Harald Welte677c21f2009-02-17 13:22:23 +00002087 switch (foh->msg_type) {
2088 case NM_MT_IPACC_RSL_CONNECT_ACK:
Harald Welte193fefc2009-04-30 15:16:27 +00002089 DEBUGPC(DNM, "RSL CONNECT ACK ");
Harald Welte677c21f2009-02-17 13:22:23 +00002090 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_RSL_BSC_IP))
Harald Welte9de2bf82009-04-30 15:59:55 +00002091 DEBUGPC(DNM, "IP=%s ",
Harald Welte677c21f2009-02-17 13:22:23 +00002092 inet_ntoa(*((struct in_addr *)
2093 TLVP_VAL(&tp, NM_ATT_IPACC_RSL_BSC_IP))));
2094 if (TLVP_PRESENT(&tp, NM_ATT_IPACC_RSL_BSC_PORT))
Harald Welte9de2bf82009-04-30 15:59:55 +00002095 DEBUGPC(DNM, "PORT=%u ",
Harald Welte677c21f2009-02-17 13:22:23 +00002096 ntohs(*((u_int16_t *)
2097 TLVP_VAL(&tp, NM_ATT_IPACC_RSL_BSC_PORT))));
Harald Welte9de2bf82009-04-30 15:59:55 +00002098 DEBUGPC(DNM, "\n");
Harald Welte677c21f2009-02-17 13:22:23 +00002099 break;
2100 case NM_MT_IPACC_RSL_CONNECT_NACK:
Harald Welte193fefc2009-04-30 15:16:27 +00002101 DEBUGPC(DNM, "RSL CONNECT NACK ");
Harald Welte677c21f2009-02-17 13:22:23 +00002102 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
Harald Welte6c96ba52009-05-01 13:03:40 +00002103 DEBUGPC(DNM, " CAUSE=%s\n",
2104 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
Harald Welte677c21f2009-02-17 13:22:23 +00002105 else
2106 DEBUGPC(DNM, "\n");
2107 break;
Harald Welte193fefc2009-04-30 15:16:27 +00002108 case NM_MT_IPACC_SET_NVATTR_ACK:
2109 DEBUGPC(DNM, "SET NVATTR ACK\n");
2110 /* FIXME: decode and show the actual attributes */
2111 break;
2112 case NM_MT_IPACC_SET_NVATTR_NACK:
Harald Welte6c96ba52009-05-01 13:03:40 +00002113 DEBUGPC(DNM, "SET NVATTR NACK ");
2114 if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES))
2115 DEBUGPC(DNM, " CAUSE=%s\n",
2116 nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES)));
2117 else
2118 DEBUGPC(DNM, "\n");
Harald Welte193fefc2009-04-30 15:16:27 +00002119 break;
2120 default:
2121 DEBUGPC(DNM, "unknown\n");
2122 break;
Harald Welte677c21f2009-02-17 13:22:23 +00002123 }
2124 return 0;
2125}
2126
Harald Welte193fefc2009-04-30 15:16:27 +00002127/* send an ip-access manufacturer specific message */
Harald Welte5c1e4582009-02-15 11:57:29 +00002128int abis_nm_ipaccess_msg(struct gsm_bts *bts, u_int8_t msg_type,
2129 u_int8_t obj_class, u_int8_t bts_nr,
2130 u_int8_t trx_nr, u_int8_t ts_nr,
2131 u_int8_t *attr, int attr_len)
2132{
2133 struct msgb *msg = nm_msgb_alloc();
2134 struct abis_om_hdr *oh;
2135 struct abis_om_fom_hdr *foh;
2136 u_int8_t *data;
2137
2138 /* construct the 12.21 OM header, observe the erroneous length */
2139 oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh));
2140 fill_om_hdr(oh, sizeof(*foh) + attr_len);
2141 oh->mdisc = ABIS_OM_MDISC_MANUF;
2142
2143 /* add the ip.access magic */
2144 data = msgb_put(msg, sizeof(ipaccess_magic)+1);
2145 *data++ = sizeof(ipaccess_magic);
2146 memcpy(data, ipaccess_magic, sizeof(ipaccess_magic));
2147
2148 /* fill the 12.21 FOM header */
2149 foh = (struct abis_om_fom_hdr *) msgb_put(msg, sizeof(*foh));
2150 foh->msg_type = msg_type;
2151 foh->obj_class = obj_class;
2152 foh->obj_inst.bts_nr = bts_nr;
2153 foh->obj_inst.trx_nr = trx_nr;
2154 foh->obj_inst.ts_nr = ts_nr;
2155
2156 if (attr && attr_len) {
2157 data = msgb_put(msg, attr_len);
2158 memcpy(data, attr, attr_len);
2159 }
2160
2161 return abis_nm_sendmsg(bts, msg);
2162}
Harald Welte677c21f2009-02-17 13:22:23 +00002163
Harald Welte193fefc2009-04-30 15:16:27 +00002164/* set some attributes in NVRAM */
2165int abis_nm_ipaccess_set_nvattr(struct gsm_bts *bts, u_int8_t *attr,
2166 int attr_len)
2167{
2168 return abis_nm_ipaccess_msg(bts, NM_MT_IPACC_SET_NVATTR,
2169 NM_OC_BASEB_TRANSC, 0, 0, 0xff, attr,
2170 attr_len);
2171}
2172
2173/* restart / reboot an ip.access nanoBTS */
2174int abis_nm_ipaccess_restart(struct gsm_bts *bts)
2175{
2176 return __simple_cmd(bts, NM_MT_IPACC_RESTART);
2177}