blob: b865038299d28c592d06af2ed81a3bd600e7cc32 [file] [log] [blame]
Harald Welte9a311ec2011-02-12 12:33:06 +01001/* Ericsson RBS 2xxx GSM O&M (OM2000) messages on the A-bis interface
2 * implemented based on protocol trace analysis, no formal documentation */
3
4/* (C) 2010-2011 by Harald Welte <laforge@gnumonks.org>
5 *
6 * 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 Affero General Public License as published by
10 * the Free Software Foundation; either version 3 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 Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23
24#include <errno.h>
25#include <unistd.h>
26#include <stdio.h>
27#include <stdlib.h>
28#include <time.h>
29#include <stdint.h>
30
31#include <arpa/inet.h>
32
33#include <osmocore/msgb.h>
34#include <osmocore/tlv.h>
35#include <osmocore/talloc.h>
36#include <osmocore/utils.h>
37
38#include <openbsc/gsm_data.h>
39#include <openbsc/debug.h>
40#include <openbsc/abis_nm.h>
Harald Welte73541072011-02-12 13:44:14 +010041#include <openbsc/abis_om2000.h>
Harald Welte9a311ec2011-02-12 12:33:06 +010042#include <openbsc/signal.h>
Harald Welted88a3872011-02-14 15:26:13 +010043#include <openbsc/e1_input.h>
Harald Welte9a311ec2011-02-12 12:33:06 +010044
45#define OM_ALLOC_SIZE 1024
46#define OM_HEADROOM_SIZE 128
47
48/* use following functions from abis_nm.c:
49 * om2k_msgb_alloc()
Harald Weltebc867d92011-02-12 13:09:38 +010050 * abis_om2k_sendmsg()
Harald Welte9a311ec2011-02-12 12:33:06 +010051 */
52
Harald Welte9a311ec2011-02-12 12:33:06 +010053struct abis_om2k_hdr {
54 struct abis_om_hdr om;
55 uint16_t msg_type;
56 struct abis_om2k_mo mo;
57 uint8_t data[0];
58} __attribute__ ((packed));
59
60enum abis_om2k_msgtype {
61 OM2K_MSGT_ABORT_SP_CMD = 0x0000,
62 OM2K_MSGT_ABORT_SP_COMPL = 0x0002,
63 OM2K_MSGT_ALARM_REP_ACK = 0x0004,
64 OM2K_MSGT_ALARM_REP_NACK = 0x0005,
65 OM2K_MSGT_ALARM_REP = 0x0006,
66 OM2K_MSGT_ALARM_STATUS_REQ = 0x0008,
67 OM2K_MSGT_ALARM_STATUS_REQ_ACK = 0x000a,
68 OM2K_MSGT_ALARM_STATUS_REQ_REJ = 0x000b,
69 OM2K_MSGT_ALARM_STATUS_RES_ACK = 0x000c,
70 OM2K_MSGT_ALARM_STATUS_RES_NACK = 0x000d,
71 OM2K_MSGT_ALARM_STATUS_RES = 0x000e,
72 OM2K_MSGT_CAL_TIME_RESP = 0x0010,
73 OM2K_MSGT_CAL_TIME_REJ = 0x0011,
74 OM2K_MSGT_CAL_TIME_REQ = 0x0012,
75
Harald Weltefdb71942011-02-14 15:31:43 +010076 OM2K_MSGT_CON_CONF_REQ = 0x0014,
77 OM2K_MSGT_CON_CONF_REQ_ACK = 0x0016,
78 OM2K_MSGT_CON_CONF_REQ_REJ = 0x0017,
79 OM2K_MSGT_CON_CONF_RES_ACK = 0x0018,
80 OM2K_MSGT_CON_CONF_RES_NACK = 0x0019,
81 OM2K_MSGT_CON_CONF_RES = 0x001a,
82
Harald Welte9a311ec2011-02-12 12:33:06 +010083 OM2K_MSGT_CONNECT_CMD = 0x001c,
84 OM2K_MSGT_CONNECT_COMPL = 0x001e,
85 OM2K_MSGT_CONNECT_REJ = 0x001f,
86
Harald Welte0741ffe2011-02-12 18:48:53 +010087 OM2K_MSGT_DISABLE_REQ = 0x0028,
88 OM2K_MSGT_DISABLE_REQ_ACK = 0x002a,
89 OM2K_MSGT_DISABLE_REQ_REJ = 0x002b,
90 OM2K_MSGT_DISABLE_RES_ACK = 0x002c,
91 OM2K_MSGT_DISABLE_RES_NACK = 0x002d,
92 OM2K_MSGT_DISABLE_RES = 0x002e,
Harald Welte6fec79d2011-02-12 14:57:17 +010093 OM2K_MSGT_DISCONNECT_CMD = 0x0030,
94 OM2K_MSGT_DISCONNECT_COMPL = 0x0032,
95 OM2K_MSGT_DISCONNECT_REJ = 0x0033,
Harald Welte0741ffe2011-02-12 18:48:53 +010096 OM2K_MSGT_ENABLE_REQ = 0x0034,
97 OM2K_MSGT_ENABLE_REQ_ACK = 0x0036,
98 OM2K_MSGT_ENABLE_REQ_REJ = 0x0037,
99 OM2K_MSGT_ENABLE_RES_ACK = 0x0038,
100 OM2K_MSGT_ENABLE_RES_NACK = 0x0039,
101 OM2K_MSGT_ENABLE_RES = 0x003a,
Harald Welte6fec79d2011-02-12 14:57:17 +0100102
Harald Welte9a311ec2011-02-12 12:33:06 +0100103 OM2K_MSGT_FAULT_REP_ACK = 0x0040,
104 OM2K_MSGT_FAULT_REP_NACK = 0x0041,
105 OM2K_MSGT_FAULT_REP = 0x0042,
106
107 OM2K_MSGT_IS_CONF_REQ = 0x0060,
108 OM2K_MSGT_IS_CONF_REQ_ACK = 0x0062,
109 OM2K_MSGT_IS_CONF_REQ_REJ = 0x0063,
110 OM2K_MSGT_IS_CONF_RES_ACK = 0x0064,
111 OM2K_MSGT_IS_CONF_RES_NACK = 0x0065,
112 OM2K_MSGT_IS_CONF_RES = 0x0066,
113
114 OM2K_MSGT_OP_INFO = 0x0074,
115 OM2K_MSGT_OP_INFO_ACK = 0x0076,
116 OM2K_MSGT_OP_INFO_REJ = 0x0077,
117 OM2K_MSGT_RESET_CMD = 0x0078,
118 OM2K_MSGT_RESET_COMPL = 0x007a,
119 OM2K_MSGT_RESET_REJ = 0x007b,
Harald Weltea0ce3492011-03-05 14:13:14 +0100120 OM2K_MSGT_RX_CONF_REQ = 0x007c,
121 OM2K_MSGT_RX_CONF_REQ_ACK = 0x007e,
122 OM2K_MSGT_RX_CONF_REQ_REJ = 0x007f,
123 OM2K_MSGT_RX_CONF_RES_ACK = 0x0080,
124 OM2K_MSGT_RX_CONF_RES_NACK = 0x0081,
125 OM2K_MSGT_RX_CONF_RES = 0x0082,
Harald Welte9a311ec2011-02-12 12:33:06 +0100126 OM2K_MSGT_START_REQ = 0x0084,
127 OM2K_MSGT_START_REQ_ACK = 0x0086,
128 OM2K_MSGT_START_REQ_REJ = 0x0087,
129 OM2K_MSGT_START_RES_ACK = 0x0088,
130 OM2K_MSGT_START_RES_NACK = 0x0089,
131 OM2K_MSGT_START_RES = 0x008a,
Harald Weltee1d5eca2011-02-12 14:42:59 +0100132 OM2K_MSGT_STATUS_REQ = 0x008c,
133 OM2K_MSGT_STATUS_RESP = 0x008e,
134 OM2K_MSGT_STATUS_REJ = 0x008f,
Harald Welte9a311ec2011-02-12 12:33:06 +0100135
Harald Welte8024d8f2011-02-12 15:07:30 +0100136 OM2K_MSGT_TEST_REQ = 0x0094,
137 OM2K_MSGT_TEST_REQ_ACK = 0x0096,
138 OM2K_MSGT_TEST_REQ_REJ = 0x0097,
139 OM2K_MSGT_TEST_RES_ACK = 0x0098,
140 OM2K_MSGT_TEST_RES_NACK = 0x0099,
141 OM2K_MSGT_TEST_RES = 0x009a,
142
Harald Weltef9cf9612011-03-05 14:36:47 +0100143 OM2K_MSGT_TF_CONF_REQ = 0x00a0,
144 OM2K_MSGT_TF_CONF_REQ_ACK = 0x00a2,
145 OM2K_MSGT_TF_CONF_REQ_REJ = 0x00a3,
146 OM2K_MSGT_TF_CONF_RES_ACK = 0x00a4,
147 OM2K_MSGT_TF_CONF_RES_NACK = 0x00a5,
148 OM2K_MSGT_TF_CONF_RES = 0x00a6,
Harald Weltea0ce3492011-03-05 14:13:14 +0100149 OM2K_MSGT_TS_CONF_REQ = 0x00a8,
150 OM2K_MSGT_TS_CONF_REQ_ACK = 0x00aa,
151 OM2K_MSGT_TS_CONF_REQ_REJ = 0x00ab,
152 OM2K_MSGT_TS_CONF_RES_ACK = 0x00ac,
153 OM2K_MSGT_TS_CONF_RES_NACK = 0x00ad,
154 OM2K_MSGT_TS_CONF_RES = 0x00ae,
155 OM2K_MSGT_TX_CONF_REQ = 0x00b0,
156 OM2K_MSGT_TX_CONF_REQ_ACK = 0x00b2,
157 OM2K_MSGT_TX_CONF_REQ_REJ = 0x00b3,
158 OM2K_MSGT_TX_CONF_RES_ACK = 0x00b4,
159 OM2K_MSGT_TX_CONF_RES_NACK = 0x00b5,
160 OM2K_MSGT_TX_CONF_RES = 0x00b6,
161
Harald Welte9a311ec2011-02-12 12:33:06 +0100162 OM2K_MSGT_NEGOT_REQ_ACK = 0x0104,
163 OM2K_MSGT_NEGOT_REQ_NACK = 0x0105,
164 OM2K_MSGT_NEGOT_REQ = 0x0106,
165};
166
167enum abis_om2k_dei {
Harald Weltea0ce3492011-03-05 14:13:14 +0100168 OM2K_DEI_BCC = 0x06,
169 OM2K_DEI_BSIC = 0x09,
Harald Welte9a311ec2011-02-12 12:33:06 +0100170 OM2K_DEI_CAL_TIME = 0x0d,
Harald Weltea0ce3492011-03-05 14:13:14 +0100171 OM2K_DEI_COMBINATION = 0x0f,
Harald Weltefdb71942011-02-14 15:31:43 +0100172 OM2K_DEI_CON_CONN_LIST = 0x10,
Harald Welte8bcb1a02011-02-12 20:23:40 +0100173 OM2K_DEI_END_LIST_NR = 0x13,
Harald Weltea0ce3492011-03-05 14:13:14 +0100174 OM2K_DEI_FILLING_MARKER = 0x1c,
175 OM2K_DEI_FN_OFFSET = 0x1d,
176 OM2K_DEI_FREQ_LIST = 0x1e,
177 OM2K_DEI_FREQ_SPEC_RX = 0x1f,
178 OM2K_DEI_FREQ_SPEC_TX = 0x20,
179 OM2K_DEI_HSN = 0x21,
Harald Welte8bcb1a02011-02-12 20:23:40 +0100180 OM2K_DEI_IS_CONN_LIST = 0x27,
181 OM2K_DEI_LIST_NR = 0x28,
Harald Weltea0ce3492011-03-05 14:13:14 +0100182 OM2K_DEI_MAIO = 0x2b,
Harald Welte9a311ec2011-02-12 12:33:06 +0100183 OM2K_DEI_OP_INFO = 0x2e,
Harald Weltea0ce3492011-03-05 14:13:14 +0100184 OM2K_DEI_POWER = 0x2f,
Harald Weltee6e83832011-03-05 17:52:09 +0100185 OM2K_DEI_REASON_CODE = 0x32,
Harald Weltea0ce3492011-03-05 14:13:14 +0100186 OM2K_DEI_RX_DIVERSITY = 0x33,
Harald Weltee6e83832011-03-05 17:52:09 +0100187 OM2K_DEI_RESULT_CODE = 0x35,
Harald Weltef9cf9612011-03-05 14:36:47 +0100188 OM2K_DEI_TF_MODE = 0x3a,
Harald Weltea0ce3492011-03-05 14:13:14 +0100189 OM2K_DEI_TS_NR = 0x3c,
190 OM2K_DEI_EXT_RANGE = 0x47,
Harald Welte73541072011-02-12 13:44:14 +0100191 OM2K_DEI_NEGOT_REC1 = 0x90,
192 OM2K_DEI_NEGOT_REC2 = 0x91,
Harald Weltef9cf9612011-03-05 14:36:47 +0100193 OM2K_DEI_FS_OFFSET = 0x98,
Harald Welte9a311ec2011-02-12 12:33:06 +0100194};
195
Harald Weltee6e83832011-03-05 17:52:09 +0100196const struct tlv_definition om2k_att_tlvdef = {
197 .def = {
198 [OM2K_DEI_BCC] = { TLV_TYPE_TV },
199 [OM2K_DEI_BSIC] = { TLV_TYPE_TV },
200 [OM2K_DEI_CAL_TIME] = { TLV_TYPE_FIXED, 6 },
201 [OM2K_DEI_COMBINATION] = { TLV_TYPE_TV },
202 [OM2K_DEI_CON_CONN_LIST] = { TLV_TYPE_TLV },
203 [OM2K_DEI_END_LIST_NR] = { TLV_TYPE_TV },
204 [OM2K_DEI_FILLING_MARKER] = { TLV_TYPE_TV },
205 [OM2K_DEI_FN_OFFSET] = { TLV_TYPE_FIXED, 2 },
206 [OM2K_DEI_FREQ_LIST] = { TLV_TYPE_TLV },
207 [OM2K_DEI_FREQ_SPEC_RX] = { TLV_TYPE_FIXED, 2 },
208 [OM2K_DEI_FREQ_SPEC_TX] = { TLV_TYPE_FIXED, 2 },
209 [OM2K_DEI_HSN] = { TLV_TYPE_TV },
210 [OM2K_DEI_IS_CONN_LIST] = { TLV_TYPE_TLV },
211 [OM2K_DEI_LIST_NR] = { TLV_TYPE_TV },
212 [OM2K_DEI_MAIO] = { TLV_TYPE_TV },
213 [OM2K_DEI_OP_INFO] = { TLV_TYPE_TV },
214 [OM2K_DEI_POWER] = { TLV_TYPE_TV },
215 [OM2K_DEI_REASON_CODE] = { TLV_TYPE_TV },
216 [OM2K_DEI_RX_DIVERSITY] = { TLV_TYPE_TV },
217 [OM2K_DEI_RESULT_CODE] = { TLV_TYPE_TV },
218 [OM2K_DEI_TF_MODE] = { TLV_TYPE_TV },
219 [OM2K_DEI_TS_NR] = { TLV_TYPE_TV },
220 [OM2K_DEI_EXT_RANGE] = { TLV_TYPE_TV },
221 [OM2K_DEI_NEGOT_REC1] = { TLV_TYPE_TLV },
222 [OM2K_DEI_NEGOT_REC2] = { TLV_TYPE_TLV },
223 [OM2K_DEI_FS_OFFSET] = { TLV_TYPE_FIXED, 5 },
224 },
225};
226
Harald Welte9a311ec2011-02-12 12:33:06 +0100227static const struct value_string om2k_msgcode_vals[] = {
228 { 0x0000, "Abort SP Command" },
229 { 0x0002, "Abort SP Complete" },
230 { 0x0004, "Alarm Report ACK" },
231 { 0x0005, "Alarm Report NACK" },
232 { 0x0006, "Alarm Report" },
233 { 0x0008, "Alarm Status Request" },
234 { 0x000a, "Alarm Status Request Accept" },
235 { 0x000b, "Alarm Status Request Reject" },
236 { 0x000c, "Alarm Status Result ACK" },
237 { 0x000d, "Alarm Status Result NACK" },
238 { 0x000e, "Alarm Status Result" },
239 { 0x0010, "Calendar Time Response" },
240 { 0x0011, "Calendar Time Reject" },
241 { 0x0012, "Calendar Time Request" },
242 { 0x0014, "CON Configuration Request" },
243 { 0x0016, "CON Configuration Request Accept" },
244 { 0x0017, "CON Configuration Request Reject" },
245 { 0x0018, "CON Configuration Result ACK" },
246 { 0x0019, "CON Configuration Result NACK" },
247 { 0x001a, "CON Configuration Result" },
248 { 0x001c, "Connect Command" },
249 { 0x001e, "Connect Complete" },
Harald Welte3ede7232011-03-05 17:58:13 +0100250 { 0x001f, "Connect Reject" },
Harald Welte9a311ec2011-02-12 12:33:06 +0100251 { 0x0028, "Disable Request" },
252 { 0x002a, "Disable Request Accept" },
253 { 0x002b, "Disable Request Reject" },
254 { 0x002c, "Disable Result ACK" },
255 { 0x002d, "Disable Result NACK" },
256 { 0x002e, "Disable Result" },
257 { 0x0030, "Disconnect Command" },
258 { 0x0032, "Disconnect Complete" },
259 { 0x0033, "Disconnect Reject" },
260 { 0x0034, "Enable Request" },
261 { 0x0036, "Enable Request Accept" },
262 { 0x0037, "Enable Request Reject" },
263 { 0x0038, "Enable Result ACK" },
264 { 0x0039, "Enable Result NACK" },
265 { 0x003a, "Enable Result" },
266 { 0x003c, "Escape Downlink Normal" },
267 { 0x003d, "Escape Downlink NACK" },
268 { 0x003e, "Escape Uplink Normal" },
269 { 0x003f, "Escape Uplink NACK" },
270 { 0x0040, "Fault Report ACK" },
271 { 0x0041, "Fault Report NACK" },
272 { 0x0042, "Fault Report" },
273 { 0x0044, "File Package End Command" },
274 { 0x0046, "File Package End Result" },
275 { 0x0047, "File Package End Reject" },
276 { 0x0048, "File Relation Request" },
277 { 0x004a, "File Relation Response" },
278 { 0x004b, "File Relation Request Reject" },
279 { 0x004c, "File Segment Transfer" },
280 { 0x004e, "File Segment Transfer Complete" },
281 { 0x004f, "File Segment Transfer Reject" },
282 { 0x0050, "HW Information Request" },
283 { 0x0052, "HW Information Request Accept" },
284 { 0x0053, "HW Information Request Reject" },
285 { 0x0054, "HW Information Result ACK" },
286 { 0x0055, "HW Information Result NACK" },
287 { 0x0056, "HW Information Result" },
288 { 0x0060, "IS Configuration Request" },
289 { 0x0062, "IS Configuration Request Accept" },
290 { 0x0063, "IS Configuration Request Reject" },
291 { 0x0064, "IS Configuration Result ACK" },
292 { 0x0065, "IS Configuration Result NACK" },
293 { 0x0066, "IS Configuration Result" },
294 { 0x0068, "Load Data End" },
295 { 0x006a, "Load Data End Result" },
296 { 0x006b, "Load Data End Reject" },
297 { 0x006c, "Load Data Init" },
298 { 0x006e, "Load Data Init Accept" },
299 { 0x006f, "Load Data Init Reject" },
300 { 0x0070, "Loop Control Command" },
301 { 0x0072, "Loop Control Complete" },
302 { 0x0073, "Loop Control Reject" },
303 { 0x0074, "Operational Information" },
304 { 0x0076, "Operational Information Accept" },
305 { 0x0077, "Operational Information Reject" },
306 { 0x0078, "Reset Command" },
307 { 0x007a, "Reset Complete" },
308 { 0x007b, "Reset Reject" },
309 { 0x007c, "RX Configuration Request" },
310 { 0x007e, "RX Configuration Request Accept" },
311 { 0x007f, "RX Configuration Request Reject" },
312 { 0x0080, "RX Configuration Result ACK" },
313 { 0x0081, "RX Configuration Result NACK" },
314 { 0x0082, "RX Configuration Result" },
315 { 0x0084, "Start Request" },
316 { 0x0086, "Start Request Accept" },
317 { 0x0087, "Start Request Reject" },
318 { 0x0088, "Start Result ACK" },
319 { 0x0089, "Start Result NACK" },
320 { 0x008a, "Start Result" },
321 { 0x008c, "Status Request" },
322 { 0x008e, "Status Response" },
323 { 0x008f, "Status Reject" },
324 { 0x0094, "Test Request" },
325 { 0x0096, "Test Request Accept" },
326 { 0x0097, "Test Request Reject" },
327 { 0x0098, "Test Result ACK" },
328 { 0x0099, "Test Result NACK" },
329 { 0x009a, "Test Result" },
330 { 0x00a0, "TF Configuration Request" },
331 { 0x00a2, "TF Configuration Request Accept" },
332 { 0x00a3, "TF Configuration Request Reject" },
333 { 0x00a4, "TF Configuration Result ACK" },
334 { 0x00a5, "TF Configuration Result NACK" },
335 { 0x00a6, "TF Configuration Result" },
336 { 0x00a8, "TS Configuration Request" },
337 { 0x00aa, "TS Configuration Request Accept" },
338 { 0x00ab, "TS Configuration Request Reject" },
339 { 0x00ac, "TS Configuration Result ACK" },
340 { 0x00ad, "TS Configuration Result NACK" },
341 { 0x00ae, "TS Configuration Result" },
342 { 0x00b0, "TX Configuration Request" },
343 { 0x00b2, "TX Configuration Request Accept" },
344 { 0x00b3, "TX Configuration Request Reject" },
345 { 0x00b4, "TX Configuration Result ACK" },
346 { 0x00b5, "TX Configuration Result NACK" },
347 { 0x00b6, "TX Configuration Result" },
348 { 0x00bc, "DIP Alarm Report ACK" },
349 { 0x00bd, "DIP Alarm Report NACK" },
350 { 0x00be, "DIP Alarm Report" },
351 { 0x00c0, "DIP Alarm Status Request" },
352 { 0x00c2, "DIP Alarm Status Response" },
353 { 0x00c3, "DIP Alarm Status Reject" },
354 { 0x00c4, "DIP Quality Report I ACK" },
355 { 0x00c5, "DIP Quality Report I NACK" },
356 { 0x00c6, "DIP Quality Report I" },
357 { 0x00c8, "DIP Quality Report II ACK" },
358 { 0x00c9, "DIP Quality Report II NACK" },
359 { 0x00ca, "DIP Quality Report II" },
360 { 0x00dc, "DP Configuration Request" },
361 { 0x00de, "DP Configuration Request Accept" },
362 { 0x00df, "DP Configuration Request Reject" },
363 { 0x00e0, "DP Configuration Result ACK" },
364 { 0x00e1, "DP Configuration Result NACK" },
365 { 0x00e2, "DP Configuration Result" },
366 { 0x00e4, "Capabilities HW Info Report ACK" },
367 { 0x00e5, "Capabilities HW Info Report NACK" },
368 { 0x00e6, "Capabilities HW Info Report" },
369 { 0x00e8, "Capabilities Request" },
370 { 0x00ea, "Capabilities Request Accept" },
371 { 0x00eb, "Capabilities Request Reject" },
372 { 0x00ec, "Capabilities Result ACK" },
373 { 0x00ed, "Capabilities Result NACK" },
374 { 0x00ee, "Capabilities Result" },
375 { 0x00f0, "FM Configuration Request" },
376 { 0x00f2, "FM Configuration Request Accept" },
377 { 0x00f3, "FM Configuration Request Reject" },
378 { 0x00f4, "FM Configuration Result ACK" },
379 { 0x00f5, "FM Configuration Result NACK" },
380 { 0x00f6, "FM Configuration Result" },
381 { 0x00f8, "FM Report Request" },
382 { 0x00fa, "FM Report Response" },
383 { 0x00fb, "FM Report Reject" },
384 { 0x00fc, "FM Start Command" },
385 { 0x00fe, "FM Start Complete" },
386 { 0x00ff, "FM Start Reject" },
387 { 0x0100, "FM Stop Command" },
388 { 0x0102, "FM Stop Complete" },
389 { 0x0103, "FM Stop Reject" },
390 { 0x0104, "Negotiation Request ACK" },
391 { 0x0105, "Negotiation Request NACK" },
392 { 0x0106, "Negotiation Request" },
393 { 0x0108, "BTS Initiated Request ACK" },
394 { 0x0109, "BTS Initiated Request NACK" },
395 { 0x010a, "BTS Initiated Request" },
396 { 0x010c, "Radio Channels Release Command" },
397 { 0x010e, "Radio Channels Release Complete" },
398 { 0x010f, "Radio Channels Release Reject" },
399 { 0x0118, "Feature Control Command" },
400 { 0x011a, "Feature Control Complete" },
401 { 0x011b, "Feature Control Reject" },
402
403 { 0, NULL }
404};
405
406/* TS 12.21 Section 9.4: Attributes */
407static const struct value_string om2k_attr_vals[] = {
408 { 0x00, "Accordance indication" },
409 { 0x01, "Alarm Id" },
410 { 0x02, "Alarm Data" },
411 { 0x03, "Alarm Severity" },
412 { 0x04, "Alarm Status" },
413 { 0x05, "Alarm Status Type" },
414 { 0x06, "BCC" },
415 { 0x07, "BS_AG_BKS_RES" },
416 { 0x09, "BSIC" },
417 { 0x0a, "BA_PA_MFRMS" },
418 { 0x0b, "CBCH Indicator" },
419 { 0x0c, "CCCH Options" },
420 { 0x0d, "Calendar Time" },
421 { 0x0f, "Channel Combination" },
422 { 0x10, "CON Connection List" },
423 { 0x11, "Data End Indication" },
424 { 0x12, "DRX_DEV_MAX" },
425 { 0x13, "End List Number" },
426 { 0x14, "External Condition Map Class 1" },
427 { 0x15, "External Condition Map Class 2" },
428 { 0x16, "File Relation Indication" },
429 { 0x17, "File Revision" },
430 { 0x18, "File Segment Data" },
431 { 0x19, "File Segment Length" },
432 { 0x1a, "File Segment Sequence Number" },
433 { 0x1b, "File Size" },
434 { 0x1c, "Filling Marker" },
435 { 0x1d, "FN Offset" },
436 { 0x1e, "Frequency List" },
437 { 0x1f, "Frequency Specifier RX" },
438 { 0x20, "Frequency Specifier TX" },
439 { 0x21, "HSN" },
440 { 0x22, "ICM Indicator" },
441 { 0x23, "Internal Fault Map Class 1A" },
442 { 0x24, "Internal Fault Map Class 1B" },
443 { 0x25, "Internal Fault Map Class 2A" },
444 { 0x26, "Internal Fault Map Class 2A Extension" },
445 { 0x27, "IS Connection List" },
446 { 0x28, "List Number" },
447 { 0x29, "File Package State Indication" },
448 { 0x2a, "Local Access State" },
449 { 0x2b, "MAIO" },
450 { 0x2c, "MO State" },
451 { 0x2d, "Ny1" },
452 { 0x2e, "Operational Information" },
453 { 0x2f, "Power" },
454 { 0x30, "RU Position Data" },
455 { 0x31, "Protocol Error" },
456 { 0x32, "Reason Code" },
457 { 0x33, "Receiver Diversity" },
458 { 0x34, "Replacement Unit Map" },
459 { 0x35, "Result Code" },
460 { 0x36, "RU Revision Data" },
461 { 0x38, "T3105" },
462 { 0x39, "Test Loop Setting" },
463 { 0x3a, "TF Mode" },
464 { 0x3b, "TF Compensation Value" },
465 { 0x3c, "Time Slot Number" },
466 { 0x3d, "TSC" },
467 { 0x3e, "RU Logical Id" },
468 { 0x3f, "RU Serial Number Data" },
469 { 0x40, "BTS Version" },
470 { 0x41, "OML IWD Version" },
471 { 0x42, "RWL IWD Version" },
472 { 0x43, "OML Function Map 1" },
473 { 0x44, "OML Function Map 2" },
474 { 0x45, "RSL Function Map 1" },
475 { 0x46, "RSL Function Map 2" },
476 { 0x47, "Extended Range Indicator" },
477 { 0x48, "Request Indicators" },
478 { 0x49, "DIP Alarm Condition Map" },
479 { 0x4a, "ES Incoming" },
480 { 0x4b, "ES Outgoing" },
481 { 0x4e, "SES Incoming" },
482 { 0x4f, "SES Outgoing" },
483 { 0x50, "Replacement Unit Map Extension" },
484 { 0x52, "UAS Incoming" },
485 { 0x53, "UAS Outgoing" },
486 { 0x58, "DF Incoming" },
487 { 0x5a, "DF Outgoing" },
488 { 0x5c, "SF" },
489 { 0x60, "S Bits Setting" },
490 { 0x61, "CRC-4 Use Option" },
491 { 0x62, "T Parameter" },
492 { 0x63, "N Parameter" },
493 { 0x64, "N1 Parameter" },
494 { 0x65, "N3 Parameter" },
495 { 0x66, "N4 Parameter" },
496 { 0x67, "P Parameter" },
497 { 0x68, "Q Parameter" },
498 { 0x69, "BI_Q1" },
499 { 0x6a, "BI_Q2" },
500 { 0x74, "ICM Boundary Parameters" },
501 { 0x77, "AFT" },
502 { 0x78, "AFT RAI" },
503 { 0x79, "Link Supervision Control" },
504 { 0x7a, "Link Supervision Filtering Time" },
505 { 0x7b, "Call Supervision Time" },
506 { 0x7c, "Interval Length UAS Incoming" },
507 { 0x7d, "Interval Length UAS Outgoing" },
508 { 0x7e, "ICM Channel Rate" },
509 { 0x7f, "Attribute Identifier" },
510 { 0x80, "FM Frequency List" },
511 { 0x81, "FM Frequency Report" },
512 { 0x82, "FM Percentile" },
513 { 0x83, "FM Clear Indication" },
514 { 0x84, "HW Info Signature" },
515 { 0x85, "MO Record" },
516 { 0x86, "TF Synchronisation Source" },
517 { 0x87, "TTA" },
518 { 0x88, "End Segment Number" },
519 { 0x89, "Segment Number" },
520 { 0x8a, "Capabilities Signature" },
521 { 0x8c, "File Relation List" },
522 { 0x90, "Negotiation Record I" },
523 { 0x91, "Negotiation Record II" },
524 { 0x92, "Encryption Algorithm" },
525 { 0x94, "Interference Rejection Combining" },
526 { 0x95, "Dedication Information" },
527 { 0x97, "Feature Code" },
528 { 0x98, "FS Offset" },
529 { 0x99, "ESB Timeslot" },
530 { 0x9a, "Master TG Instance" },
531 { 0x9b, "Master TX Chain Delay" },
532 { 0x9c, "External Condition Class 2 Extension" },
533 { 0x9d, "TSs MO State" },
534 { 0, NULL }
535};
536
Harald Weltee1d5eca2011-02-12 14:42:59 +0100537const struct value_string om2k_mo_class_short_vals[] = {
Harald Welte9a311ec2011-02-12 12:33:06 +0100538 { 0x01, "TRXC" },
539 { 0x03, "TS" },
540 { 0x04, "TF" },
541 { 0x05, "IS" },
542 { 0x06, "CON" },
543 { 0x07, "DP" },
544 { 0x0a, "CF" },
545 { 0x0b, "TX" },
546 { 0x0c, "RX" },
547 { 0, NULL }
548};
549
550static struct msgb *om2k_msgb_alloc(void)
551{
552 return msgb_alloc_headroom(OM_ALLOC_SIZE, OM_HEADROOM_SIZE,
553 "OM2000");
554}
555
Harald Weltee6e83832011-03-05 17:52:09 +0100556static int abis_om2k_tlv_parse(struct tlv_parsed *tp, const u_int8_t *buf, int len)
557{
558 return tlv_parse(tp, &om2k_att_tlvdef, buf, len, 0, 0);
559}
560
Harald Welted88a3872011-02-14 15:26:13 +0100561static char *om2k_mo_name(const struct abis_om2k_mo *mo)
562{
563 static char mo_buf[64];
564
565 memset(mo_buf, 0, sizeof(mo_buf));
566 snprintf(mo_buf, sizeof(mo_buf), "%s/%02x/%02x/%02x",
567 get_value_string(om2k_mo_class_short_vals, mo->class),
568 mo->bts, mo->assoc_so, mo->inst);
569 return mo_buf;
570}
571
Harald Weltebc867d92011-02-12 13:09:38 +0100572static int abis_om2k_sendmsg(struct gsm_bts *bts, struct msgb *msg)
573{
Harald Welted88a3872011-02-14 15:26:13 +0100574 struct abis_om2k_hdr *o2h;
575 int to_trx_oml;
Harald Weltebc867d92011-02-12 13:09:38 +0100576
Harald Welted88a3872011-02-14 15:26:13 +0100577 msg->l2h = msg->data;
578 o2h = (struct abis_om2k_hdr *) msg->l2h;
579
580 switch (o2h->mo.class) {
581 case OM2K_MO_CLS_TRXC:
582 case OM2K_MO_CLS_TX:
583 case OM2K_MO_CLS_RX:
584 case OM2K_MO_CLS_TS:
585 /* Route through per-TRX OML Link to the appropriate TRX */
586 to_trx_oml = 1;
587 msg->trx = gsm_bts_trx_by_nr(bts, o2h->mo.inst);
588 if (!msg->trx) {
589 LOGP(DNM, LOGL_ERROR, "MO=%s Tx Dropping msg to "
590 "non-existing TRX\n", om2k_mo_name(&o2h->mo));
591 return -ENODEV;
592 }
593 break;
594 default:
595 /* Route through the IXU/DXU OML Link */
596 msg->trx = bts->c0;
597 to_trx_oml = 0;
598 break;
599 }
600
601 return _abis_nm_sendmsg(msg, to_trx_oml);
Harald Weltebc867d92011-02-12 13:09:38 +0100602}
603
Harald Welte9a311ec2011-02-12 12:33:06 +0100604static void fill_om2k_hdr(struct abis_om2k_hdr *o2h, const struct abis_om2k_mo *mo,
605 uint16_t msg_type, uint8_t attr_len)
606{
607 o2h->om.mdisc = ABIS_OM_MDISC_FOM;
608 o2h->om.placement = ABIS_OM_PLACEMENT_ONLY;
609 o2h->om.sequence = 0;
Harald Weltebc867d92011-02-12 13:09:38 +0100610 o2h->om.length = 6 + attr_len;
Harald Welte9a311ec2011-02-12 12:33:06 +0100611 o2h->msg_type = htons(msg_type);
612 memcpy(&o2h->mo, mo, sizeof(o2h->mo));
613}
614
Harald Welte73541072011-02-12 13:44:14 +0100615const struct abis_om2k_mo om2k_mo_cf = { OM2K_MO_CLS_CF, 0, 0xFF, 0 };
Harald Welte8bcb1a02011-02-12 20:23:40 +0100616const struct abis_om2k_mo om2k_mo_is = { OM2K_MO_CLS_IS, 0, 0xFF, 0 };
Harald Weltefdb71942011-02-14 15:31:43 +0100617const struct abis_om2k_mo om2k_mo_con = { OM2K_MO_CLS_CON, 0, 0xFF, 0 };
Harald Weltef9cf9612011-03-05 14:36:47 +0100618const struct abis_om2k_mo om2k_mo_tf = { OM2K_MO_CLS_TF, 0, 0xFF, 0 };
Harald Welte9a311ec2011-02-12 12:33:06 +0100619
620static int abis_om2k_cal_time_resp(struct gsm_bts *bts)
621{
622 struct msgb *msg = om2k_msgb_alloc();
623 struct abis_om2k_hdr *o2k;
624 time_t tm_t;
625 struct tm *tm;
626
627 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
628 fill_om2k_hdr(o2k, &om2k_mo_cf, OM2K_MSGT_CAL_TIME_RESP, 7);
629
630 tm_t = time(NULL);
631 tm = localtime(&tm_t);
632
633 msgb_put_u8(msg, OM2K_DEI_CAL_TIME);
634 msgb_put_u8(msg, tm->tm_year % 100);
635 msgb_put_u8(msg, tm->tm_mon + 1);
636 msgb_put_u8(msg, tm->tm_mday);
637 msgb_put_u8(msg, tm->tm_hour);
638 msgb_put_u8(msg, tm->tm_min);
639 msgb_put_u8(msg, tm->tm_sec);
640
Harald Weltebc867d92011-02-12 13:09:38 +0100641 return abis_om2k_sendmsg(bts, msg);
Harald Welte9a311ec2011-02-12 12:33:06 +0100642}
643
Harald Welte6fec79d2011-02-12 14:57:17 +0100644static int abis_om2k_tx_simple(struct gsm_bts *bts, const struct abis_om2k_mo *mo,
Harald Welte9a311ec2011-02-12 12:33:06 +0100645 uint8_t msg_type)
646{
647 struct msgb *msg = om2k_msgb_alloc();
648 struct abis_om2k_hdr *o2k;
649
650 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
651 fill_om2k_hdr(o2k, mo, msg_type, 0);
652
Harald Welte73541072011-02-12 13:44:14 +0100653 DEBUGP(DNM, "Tx MO=%s %s\n", om2k_mo_name(mo),
654 get_value_string(om2k_msgcode_vals, msg_type));
655
Harald Weltebc867d92011-02-12 13:09:38 +0100656 return abis_om2k_sendmsg(bts, msg);
Harald Welte9a311ec2011-02-12 12:33:06 +0100657}
658
Harald Welte6fec79d2011-02-12 14:57:17 +0100659int abis_om2k_tx_reset_cmd(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
Harald Welte73541072011-02-12 13:44:14 +0100660{
661 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_RESET_CMD);
662}
663
Harald Welte6fec79d2011-02-12 14:57:17 +0100664int abis_om2k_tx_start_req(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
Harald Welte73541072011-02-12 13:44:14 +0100665{
666 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_START_REQ);
667}
668
Harald Welte6fec79d2011-02-12 14:57:17 +0100669int abis_om2k_tx_status_req(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
Harald Weltee1d5eca2011-02-12 14:42:59 +0100670{
671 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_STATUS_REQ);
672}
673
Harald Welte6fec79d2011-02-12 14:57:17 +0100674int abis_om2k_tx_connect_cmd(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
675{
676 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_CONNECT_CMD);
677}
678
679int abis_om2k_tx_disconnect_cmd(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
680{
681 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_DISCONNECT_CMD);
682}
683
Harald Welte8024d8f2011-02-12 15:07:30 +0100684int abis_om2k_tx_test_req(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
685{
686 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_TEST_REQ);
687}
688
Harald Welte0741ffe2011-02-12 18:48:53 +0100689int abis_om2k_tx_enable_req(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
690{
691 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_ENABLE_REQ);
692}
693
694int abis_om2k_tx_disable_req(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
695{
696 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_DISABLE_REQ);
697}
698
Harald Welte6fec79d2011-02-12 14:57:17 +0100699int abis_om2k_tx_op_info(struct gsm_bts *bts, const struct abis_om2k_mo *mo,
700 uint8_t operational)
Harald Welte9a311ec2011-02-12 12:33:06 +0100701{
702 struct msgb *msg = om2k_msgb_alloc();
703 struct abis_om2k_hdr *o2k;
704
705 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
706 fill_om2k_hdr(o2k, mo, OM2K_MSGT_OP_INFO, 2);
707
708 msgb_tv_put(msg, OM2K_DEI_OP_INFO, operational);
709
Harald Welte73541072011-02-12 13:44:14 +0100710 DEBUGP(DNM, "Tx MO=%s %s\n", om2k_mo_name(mo),
711 get_value_string(om2k_msgcode_vals, OM2K_MSGT_OP_INFO));
712
Harald Weltebc867d92011-02-12 13:09:38 +0100713 return abis_om2k_sendmsg(bts, msg);
Harald Welte9a311ec2011-02-12 12:33:06 +0100714}
715
Harald Welte8bcb1a02011-02-12 20:23:40 +0100716int abis_om2k_tx_is_conf_req(struct gsm_bts *bts, struct om2k_is_conn_grp *cg,
717 unsigned int num_cg )
718{
719 struct msgb *msg = om2k_msgb_alloc();
720 struct abis_om2k_hdr *o2k;
721
722 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
723 fill_om2k_hdr(o2k, &om2k_mo_is, OM2K_MSGT_IS_CONF_REQ,
724 2 + 2 + TLV_GROSS_LEN(num_cg * sizeof(*cg)));
725
726 msgb_tv_put(msg, OM2K_DEI_LIST_NR, 1);
727 msgb_tv_put(msg, OM2K_DEI_END_LIST_NR, 1);
728
729 msgb_tlv_put(msg, OM2K_DEI_IS_CONN_LIST,
730 num_cg * sizeof(*cg), (uint8_t *)cg);
731
732 return abis_om2k_sendmsg(bts, msg);
733}
734
Harald Weltefdb71942011-02-14 15:31:43 +0100735int abis_om2k_tx_con_conf_req(struct gsm_bts *bts, uint8_t *data,
736 unsigned int len)
737{
738 struct msgb *msg = om2k_msgb_alloc();
739 struct abis_om2k_hdr *o2k;
740
741 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
742 fill_om2k_hdr(o2k, &om2k_mo_con, OM2K_MSGT_CON_CONF_REQ,
743 2 + 2 + TLV_GROSS_LEN(len));
744
745 msgb_tv_put(msg, OM2K_DEI_LIST_NR, 1);
746 msgb_tv_put(msg, OM2K_DEI_END_LIST_NR, 1);
747
748 msgb_tlv_put(msg, OM2K_DEI_CON_CONN_LIST, len, data);
749
750 return abis_om2k_sendmsg(bts, msg);
751}
752
Harald Weltea0ce3492011-03-05 14:13:14 +0100753static void om2k_trx_to_mo(struct abis_om2k_mo *mo,
754 const struct gsm_bts_trx *trx,
755 enum abis_om2k_mo_cls cls)
756{
757 mo->class = cls;
758 mo->bts = 0;
759 mo->inst = trx->nr;
Harald Welte53492c82011-03-05 16:21:01 +0100760 mo->assoc_so = 255;
Harald Weltea0ce3492011-03-05 14:13:14 +0100761}
762
763static void om2k_ts_to_mo(struct abis_om2k_mo *mo,
764 const struct gsm_bts_trx_ts *ts)
765{
766 mo->class = OM2K_MO_CLS_TS;
767 mo->bts = 0;
768 mo->inst = ts->nr;
769 mo->assoc_so = ts->trx->nr;
770}
771
772/* Configure a Receiver MO */
773int abis_om2k_tx_rx_conf_req(struct gsm_bts_trx *trx)
774{
775 struct msgb *msg = om2k_msgb_alloc();
776 struct abis_om2k_hdr *o2k;
777 struct abis_om2k_mo mo;
778
779 om2k_trx_to_mo(&mo, trx, OM2K_MO_CLS_RX);
780
781 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
782 fill_om2k_hdr(o2k, &mo, OM2K_MSGT_RX_CONF_REQ, 3+2);
783
784 msgb_tv16_put(msg, OM2K_DEI_FREQ_SPEC_RX, trx->arfcn);
785 msgb_tv_put(msg, OM2K_DEI_RX_DIVERSITY, 0x03); /* A+B */
786
787 return abis_om2k_sendmsg(trx->bts, msg);
788}
789
790/* Configure a Transmitter MO */
791int abis_om2k_tx_tx_conf_req(struct gsm_bts_trx *trx)
792{
793 struct msgb *msg = om2k_msgb_alloc();
794 struct abis_om2k_hdr *o2k;
795 struct abis_om2k_mo mo;
796
797 om2k_trx_to_mo(&mo, trx, OM2K_MO_CLS_TX);
798
799 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
800 fill_om2k_hdr(o2k, &mo, OM2K_MSGT_TX_CONF_REQ, 3+2+2+2);
801
802 msgb_tv16_put(msg, OM2K_DEI_FREQ_SPEC_TX, trx->arfcn);
803 msgb_tv_put(msg, OM2K_DEI_POWER, trx->nominal_power-trx->max_power_red);
804 msgb_tv_put(msg, OM2K_DEI_FILLING_MARKER, 0); /* Filling enabled */
805 msgb_tv_put(msg, OM2K_DEI_BCC, trx->bts->bsic & 0x7);
806 /* Dedication Information is optional */
807
808 return abis_om2k_sendmsg(trx->bts, msg);
809}
810
Harald Weltef9cf9612011-03-05 14:36:47 +0100811enum abis_om2k_tf_mode {
812 OM2K_TF_MODE_MASTER = 0x00,
813 OM2K_TF_MODE_STANDALONE = 0x01,
814 OM2K_TF_MODE_SLAVE = 0x02,
815 OM2K_TF_MODE_UNDEFINED = 0xff,
816};
817
818static const uint8_t fs_offset_undef[5] = { 0xff, 0xff, 0xff, 0xff, 0xff };
819
820int abis_om2k_tx_tf_conf_req(struct gsm_bts *bts)
821{
822 struct msgb *msg = om2k_msgb_alloc();
823 struct abis_om2k_hdr *o2k;
824
825 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
826 fill_om2k_hdr(o2k, &om2k_mo_tf, OM2K_MSGT_TF_CONF_REQ,
827 2+1+sizeof(fs_offset_undef));
828
829 msgb_tv_put(msg, OM2K_DEI_TF_MODE, OM2K_TF_MODE_STANDALONE);
830 msgb_tv_fixed_put(msg, OM2K_DEI_FS_OFFSET,
831 sizeof(fs_offset_undef), fs_offset_undef);
832
833 return abis_om2k_sendmsg(bts, msg);
834}
835
Harald Weltea0ce3492011-03-05 14:13:14 +0100836static uint8_t pchan2comb(enum gsm_phys_chan_config pchan)
837{
838 switch (pchan) {
839 case GSM_PCHAN_CCCH:
840 return 4;
841 case GSM_PCHAN_CCCH_SDCCH4:
842 return 5;
843 case GSM_PCHAN_SDCCH8_SACCH8C:
844 return 3;
845 case GSM_PCHAN_TCH_F:
846 case GSM_PCHAN_TCH_H:
847 case GSM_PCHAN_PDCH:
848 case GSM_PCHAN_TCH_F_PDCH:
849 return 8;
850 default:
851 return 0;
852 }
853}
854
Harald Welte5748c202011-03-05 17:30:07 +0100855static int put_freq_list(uint8_t *buf, uint16_t arfcn)
856{
857 buf[0] = 0x00; /* TX/RX address */
858 buf[1] = (arfcn >> 8);
859 buf[2] = (arfcn & 0xff);
860
861 return 3;
862}
863
Harald Weltea0ce3492011-03-05 14:13:14 +0100864/* Compute a frequency list in OM2000 fomrmat */
865static int om2k_gen_freq_list(uint8_t *list, struct gsm_bts_trx_ts *ts)
866{
867 uint8_t *cur = list;
Harald Weltee6e83832011-03-05 17:52:09 +0100868 int len;
Harald Weltea0ce3492011-03-05 14:13:14 +0100869
870 if (ts->hopping.enabled) {
871 unsigned int i;
872 for (i = 0; i < ts->hopping.arfcns.data_len*8; i++) {
Harald Welte5748c202011-03-05 17:30:07 +0100873 if (bitvec_get_bit_pos(&ts->hopping.arfcns, i))
874 cur += put_freq_list(cur, i);
Harald Weltea0ce3492011-03-05 14:13:14 +0100875 }
Harald Welte5748c202011-03-05 17:30:07 +0100876 } else
877 cur += put_freq_list(cur, ts->trx->arfcn);
878
Harald Weltee6e83832011-03-05 17:52:09 +0100879 len = cur - list;
880
881 return len;
Harald Weltea0ce3492011-03-05 14:13:14 +0100882}
883
884int abis_om2k_tx_ts_conf_req(struct gsm_bts_trx_ts *ts)
885{
886 struct msgb *msg = om2k_msgb_alloc();
887 struct abis_om2k_hdr *o2k;
888 struct abis_om2k_mo mo;
889 uint8_t freq_list[64*3]; /* BA max size: 64 ARFCN */
890 int freq_list_len;
891
892 om2k_ts_to_mo(&mo, ts);
893
Harald Welte5748c202011-03-05 17:30:07 +0100894 memset(freq_list, 0, sizeof(freq_list));
Harald Weltea0ce3492011-03-05 14:13:14 +0100895 freq_list_len = om2k_gen_freq_list(freq_list, ts);
896 if (freq_list_len < 0)
897 return freq_list_len;
898
899 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
900 fill_om2k_hdr(o2k, &mo, OM2K_MSGT_TS_CONF_REQ,
901 2+2+TLV_GROSS_LEN(freq_list_len)+2+2+2+2+3+2);
902
903 msgb_tv_put(msg, OM2K_DEI_COMBINATION, pchan2comb(ts->pchan));
904 msgb_tv_put(msg, OM2K_DEI_TS_NR, ts->nr);
905 msgb_tlv_put(msg, OM2K_DEI_FREQ_LIST, freq_list_len, freq_list);
906 msgb_tv_put(msg, OM2K_DEI_HSN, ts->hopping.hsn);
907 msgb_tv_put(msg, OM2K_DEI_MAIO, ts->hopping.maio);
908 msgb_tv_put(msg, OM2K_DEI_BSIC, ts->trx->bts->bsic);
909 msgb_tv_put(msg, OM2K_DEI_RX_DIVERSITY, 0x03); /* A+B */
910 msgb_tv16_put(msg, OM2K_DEI_FN_OFFSET, 0);
911 msgb_tv_put(msg, OM2K_DEI_EXT_RANGE, 0); /* Off */
912 /* Optional: Interference Rejection Combining */
913
914 return abis_om2k_sendmsg(ts->trx->bts, msg);
915}
Harald Weltefdb71942011-02-14 15:31:43 +0100916
Harald Welte6fec79d2011-02-12 14:57:17 +0100917static int abis_om2k_tx_negot_req_ack(struct gsm_bts *bts, const struct abis_om2k_mo *mo,
Harald Welte73541072011-02-12 13:44:14 +0100918 uint8_t *data, unsigned int len)
919{
920 struct msgb *msg = om2k_msgb_alloc();
921 struct abis_om2k_hdr *o2k;
922
923 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
924 fill_om2k_hdr(o2k, mo, OM2K_MSGT_NEGOT_REQ_ACK, 2+len);
925
926 msgb_tlv_put(msg, OM2K_DEI_NEGOT_REC2, len, data);
927
928 DEBUGP(DNM, "Tx MO=%s %s\n", om2k_mo_name(mo),
929 get_value_string(om2k_msgcode_vals, OM2K_MSGT_NEGOT_REQ_ACK));
930
931 return abis_om2k_sendmsg(bts, msg);
932}
Harald Welte9a311ec2011-02-12 12:33:06 +0100933
Harald Welte563d3162011-02-12 18:11:16 +0100934struct iwd_version {
935 uint8_t gen_char[3+1];
936 uint8_t rev_char[3+1];
937};
938
939struct iwd_type {
940 uint8_t num_vers;
941 struct iwd_version v[8];
942};
943
Harald Welte9a311ec2011-02-12 12:33:06 +0100944static int om2k_rx_negot_req(struct msgb *msg)
945{
946 struct abis_om2k_hdr *o2h = msgb_l2(msg);
Harald Welte563d3162011-02-12 18:11:16 +0100947 struct iwd_type iwd_types[16];
948 uint8_t num_iwd_types = o2h->data[2];
949 uint8_t *cur = o2h->data+3;
950 unsigned int i, v;
Harald Welte9a311ec2011-02-12 12:33:06 +0100951
Harald Welte563d3162011-02-12 18:11:16 +0100952 uint8_t out_buf[1024];
953 uint8_t *out_cur = out_buf+1;
954 uint8_t out_num_types = 0;
955
956 memset(iwd_types, 0, sizeof(iwd_types));
957
958 /* Parse the RBS-supported IWD versions into iwd_types array */
959 for (i = 0; i < num_iwd_types; i++) {
960 uint8_t num_versions = *cur++;
961 uint8_t iwd_type = *cur++;
962
963 iwd_types[iwd_type].num_vers = num_versions;
964
965 for (v = 0; v < num_versions; v++) {
966 struct iwd_version *iwd_v = &iwd_types[iwd_type].v[v];
967
968 memcpy(iwd_v->gen_char, cur, 3);
Harald Welte56ee6b82011-02-12 18:13:37 +0100969 cur += 3;
970 memcpy(iwd_v->rev_char, cur, 3);
971 cur += 3;
972
Harald Welte563d3162011-02-12 18:11:16 +0100973 DEBUGP(DNM, "\tIWD Type %u Gen %s Rev %s\n", iwd_type,
974 iwd_v->gen_char, iwd_v->rev_char);
975 }
976 }
977
978 /* Select the last version for each IWD type */
979 for (i = 0; i < ARRAY_SIZE(iwd_types); i++) {
980 struct iwd_type *type = &iwd_types[i];
981 struct iwd_version *last_v;
982
983 if (type->num_vers == 0)
984 continue;
985
986 out_num_types++;
987
988 last_v = &type->v[type->num_vers-1];
989
990 *out_cur++ = i;
991 memcpy(out_cur, last_v->gen_char, 3);
992 out_cur += 3;
993 memcpy(out_cur, last_v->rev_char, 3);
994 out_cur += 3;
995 }
996
997 out_buf[0] = out_num_types;
998
999 return abis_om2k_tx_negot_req_ack(msg->trx->bts, &o2h->mo, out_buf, out_cur - out_buf);
Harald Welte9a311ec2011-02-12 12:33:06 +01001000}
1001
1002static int om2k_rx_start_res(struct msgb *msg)
1003{
1004 struct abis_om2k_hdr *o2h = msgb_l2(msg);
1005 int rc;
1006
1007 rc = abis_om2k_tx_simple(msg->trx->bts, &o2h->mo, OM2K_MSGT_START_RES_ACK);
1008 rc = abis_om2k_tx_op_info(msg->trx->bts, &o2h->mo, 1);
1009
1010 return rc;
1011}
1012
Harald Welte0741ffe2011-02-12 18:48:53 +01001013static int om2k_rx_op_info_ack(struct msgb *msg)
Harald Welte9a311ec2011-02-12 12:33:06 +01001014{
1015 struct abis_om2k_hdr *o2h = msgb_l2(msg);
Harald Welte9a311ec2011-02-12 12:33:06 +01001016
Harald Welte0741ffe2011-02-12 18:48:53 +01001017 /* FIXME: update Operational state in our structures */
Harald Welte9a311ec2011-02-12 12:33:06 +01001018
Harald Welte0741ffe2011-02-12 18:48:53 +01001019 return 0;
Harald Welte9a311ec2011-02-12 12:33:06 +01001020}
1021
Harald Weltee6e83832011-03-05 17:52:09 +01001022const struct value_string om2k_result_strings[] = {
1023 { 0x02, "Wrong state or out of sequence" },
1024 { 0x03, "File error" },
1025 { 0x04, "Fault, unspecified" },
1026 { 0x05, "Tuning fault" },
1027 { 0x06, "Protocol error" },
1028 { 0x07, "MO not connected" },
1029 { 0x08, "Parameter error" },
1030 { 0x09, "Optional function not supported" },
1031 { 0x0a, "Local access state LOCALLY DISCONNECTED" },
1032 { 0, NULL }
1033};
1034
1035static int om2k_rx_nack(struct msgb *msg)
1036{
1037 struct abis_om2k_hdr *o2h = msgb_l2(msg);
1038 uint16_t msg_type = ntohs(o2h->msg_type);
1039 struct tlv_parsed tp;
1040
1041 LOGP(DNM, LOGL_ERROR, "Rx MO=%s %s", om2k_mo_name(&o2h->mo),
1042 get_value_string(om2k_msgcode_vals, msg_type));
1043
1044 abis_om2k_tlv_parse(&tp, o2h->data, o2h->om.length - 6);
1045 if (TLVP_PRESENT(&tp, OM2K_DEI_REASON_CODE))
1046 LOGPC(DNM, LOGL_ERROR, ", Reason 0x%02x",
1047 *TLVP_VAL(&tp, OM2K_DEI_REASON_CODE));
1048
1049 if (TLVP_PRESENT(&tp, OM2K_DEI_RESULT_CODE))
1050 LOGPC(DNM, LOGL_ERROR, ", Result %s",
1051 get_value_string(om2k_result_strings,
1052 *TLVP_VAL(&tp, OM2K_DEI_RESULT_CODE)));
1053 LOGPC(DNM, LOGL_ERROR, "\n");
1054
1055 return 0;
1056}
1057
Harald Welte9a311ec2011-02-12 12:33:06 +01001058int abis_om2k_rcvmsg(struct msgb *msg)
1059{
1060 struct gsm_bts *bts = msg->trx->bts;
1061 struct abis_om2k_hdr *o2h = msgb_l2(msg);
1062 struct abis_om_hdr *oh = &o2h->om;
Harald Weltebc867d92011-02-12 13:09:38 +01001063 uint16_t msg_type = ntohs(o2h->msg_type);
Harald Welte9a311ec2011-02-12 12:33:06 +01001064 int rc = 0;
1065
1066 /* Various consistency checks */
1067 if (oh->placement != ABIS_OM_PLACEMENT_ONLY) {
1068 LOGP(DNM, LOGL_ERROR, "ABIS OML placement 0x%x not supported\n",
1069 oh->placement);
1070 if (oh->placement != ABIS_OM_PLACEMENT_FIRST)
1071 return -EINVAL;
1072 }
1073 if (oh->sequence != 0) {
1074 LOGP(DNM, LOGL_ERROR, "ABIS OML sequence 0x%x != 0x00\n",
1075 oh->sequence);
1076 return -EINVAL;
1077 }
1078
1079 msg->l3h = (unsigned char *)o2h + sizeof(*o2h);
1080
1081 if (oh->mdisc != ABIS_OM_MDISC_FOM) {
1082 LOGP(DNM, LOGL_ERROR, "unknown ABIS OM2000 message discriminator 0x%x\n",
1083 oh->mdisc);
1084 return -EINVAL;
1085 }
1086
Harald Welte73541072011-02-12 13:44:14 +01001087 DEBUGP(DNM, "Rx MO=%s %s (%s)\n", om2k_mo_name(&o2h->mo),
Harald Weltebc867d92011-02-12 13:09:38 +01001088 get_value_string(om2k_msgcode_vals, msg_type),
Harald Welte9a311ec2011-02-12 12:33:06 +01001089 hexdump(msg->l2h, msgb_l2len(msg)));
1090
Harald Weltebc867d92011-02-12 13:09:38 +01001091 switch (msg_type) {
Harald Welte9a311ec2011-02-12 12:33:06 +01001092 case OM2K_MSGT_CAL_TIME_REQ:
1093 rc = abis_om2k_cal_time_resp(bts);
1094 break;
1095 case OM2K_MSGT_FAULT_REP:
Harald Welte9a311ec2011-02-12 12:33:06 +01001096 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_FAULT_REP_ACK);
1097 break;
1098 case OM2K_MSGT_NEGOT_REQ:
1099 rc = om2k_rx_negot_req(msg);
1100 break;
1101 case OM2K_MSGT_START_RES:
1102 rc = om2k_rx_start_res(msg);
1103 break;
Harald Welte0741ffe2011-02-12 18:48:53 +01001104 case OM2K_MSGT_OP_INFO_ACK:
1105 rc = om2k_rx_op_info_ack(msg);
Harald Welte9a311ec2011-02-12 12:33:06 +01001106 break;
1107 case OM2K_MSGT_IS_CONF_RES:
1108 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_IS_CONF_RES_ACK);
1109 break;
Harald Weltefdb71942011-02-14 15:31:43 +01001110 case OM2K_MSGT_CON_CONF_RES:
1111 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_CON_CONF_RES_ACK);
1112 break;
Harald Weltea0ce3492011-03-05 14:13:14 +01001113 case OM2K_MSGT_TX_CONF_RES:
1114 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_TX_CONF_RES_ACK);
1115 break;
1116 case OM2K_MSGT_RX_CONF_RES:
1117 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_RX_CONF_RES_ACK);
1118 break;
1119 case OM2K_MSGT_TS_CONF_RES:
1120 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_TS_CONF_RES_ACK);
1121 break;
Harald Weltef9cf9612011-03-05 14:36:47 +01001122 case OM2K_MSGT_TF_CONF_RES:
1123 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_TF_CONF_RES_ACK);
1124 break;
Harald Welte9a311ec2011-02-12 12:33:06 +01001125 case OM2K_MSGT_CONNECT_COMPL:
1126 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_RESET_CMD);
1127 break;
1128 case OM2K_MSGT_RESET_COMPL:
1129 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_START_REQ);
1130 break;
Harald Welteb3d70fd2011-02-13 12:43:44 +01001131 case OM2K_MSGT_ENABLE_RES:
1132 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_ENABLE_RES_ACK);
1133 break;
Harald Weltefdb71942011-02-14 15:31:43 +01001134 case OM2K_MSGT_DISABLE_RES:
1135 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_DISABLE_RES_ACK);
1136 break;
1137 case OM2K_MSGT_TEST_RES:
1138 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_TEST_RES_ACK);
Harald Welte9a311ec2011-02-12 12:33:06 +01001139 break;
Harald Welte0741ffe2011-02-12 18:48:53 +01001140 case OM2K_MSGT_STATUS_RESP:
1141 break;
Harald Weltefdb71942011-02-14 15:31:43 +01001142 case OM2K_MSGT_START_REQ_ACK:
1143 case OM2K_MSGT_CON_CONF_REQ_ACK:
1144 case OM2K_MSGT_IS_CONF_REQ_ACK:
Harald Weltea0ce3492011-03-05 14:13:14 +01001145 case OM2K_MSGT_TX_CONF_REQ_ACK:
1146 case OM2K_MSGT_RX_CONF_REQ_ACK:
1147 case OM2K_MSGT_TS_CONF_REQ_ACK:
Harald Weltef9cf9612011-03-05 14:36:47 +01001148 case OM2K_MSGT_TF_CONF_REQ_ACK:
Harald Weltefdb71942011-02-14 15:31:43 +01001149 case OM2K_MSGT_ENABLE_REQ_ACK:
1150 case OM2K_MSGT_ALARM_STATUS_REQ_ACK:
1151 case OM2K_MSGT_DISABLE_REQ_ACK:
1152 break;
Harald Weltee6e83832011-03-05 17:52:09 +01001153 case OM2K_MSGT_START_REQ_REJ:
Harald Welte3ede7232011-03-05 17:58:13 +01001154 case OM2K_MSGT_CONNECT_REJ:
1155 case OM2K_MSGT_DISCONNECT_REJ:
Harald Weltee6e83832011-03-05 17:52:09 +01001156 case OM2K_MSGT_CON_CONF_REQ_REJ:
1157 case OM2K_MSGT_IS_CONF_REQ_REJ:
1158 case OM2K_MSGT_TX_CONF_REQ_REJ:
1159 case OM2K_MSGT_RX_CONF_REQ_REJ:
1160 case OM2K_MSGT_TS_CONF_REQ_REJ:
1161 case OM2K_MSGT_TF_CONF_REQ_REJ:
1162 case OM2K_MSGT_ENABLE_REQ_REJ:
1163 case OM2K_MSGT_ALARM_STATUS_REQ_REJ:
1164 case OM2K_MSGT_DISABLE_REQ_REJ:
1165 rc = om2k_rx_nack(msg);
1166 break;
Harald Welte9a311ec2011-02-12 12:33:06 +01001167 default:
Harald Welte0741ffe2011-02-12 18:48:53 +01001168 LOGP(DNM, LOGL_NOTICE, "Rx unhandled OM2000 msg %s\n",
Harald Weltebc867d92011-02-12 13:09:38 +01001169 get_value_string(om2k_msgcode_vals, msg_type));
Harald Welte9a311ec2011-02-12 12:33:06 +01001170 }
1171
1172 msgb_free(msg);
1173 return rc;
1174}