blob: fc0fbd87b83bbb8affd6b56fec9a29b8ab352506 [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>
43
44#define OM_ALLOC_SIZE 1024
45#define OM_HEADROOM_SIZE 128
46
47/* use following functions from abis_nm.c:
48 * om2k_msgb_alloc()
Harald Weltebc867d92011-02-12 13:09:38 +010049 * abis_om2k_sendmsg()
Harald Welte9a311ec2011-02-12 12:33:06 +010050 */
51
Harald Welte9a311ec2011-02-12 12:33:06 +010052struct abis_om2k_hdr {
53 struct abis_om_hdr om;
54 uint16_t msg_type;
55 struct abis_om2k_mo mo;
56 uint8_t data[0];
57} __attribute__ ((packed));
58
59enum abis_om2k_msgtype {
60 OM2K_MSGT_ABORT_SP_CMD = 0x0000,
61 OM2K_MSGT_ABORT_SP_COMPL = 0x0002,
62 OM2K_MSGT_ALARM_REP_ACK = 0x0004,
63 OM2K_MSGT_ALARM_REP_NACK = 0x0005,
64 OM2K_MSGT_ALARM_REP = 0x0006,
65 OM2K_MSGT_ALARM_STATUS_REQ = 0x0008,
66 OM2K_MSGT_ALARM_STATUS_REQ_ACK = 0x000a,
67 OM2K_MSGT_ALARM_STATUS_REQ_REJ = 0x000b,
68 OM2K_MSGT_ALARM_STATUS_RES_ACK = 0x000c,
69 OM2K_MSGT_ALARM_STATUS_RES_NACK = 0x000d,
70 OM2K_MSGT_ALARM_STATUS_RES = 0x000e,
71 OM2K_MSGT_CAL_TIME_RESP = 0x0010,
72 OM2K_MSGT_CAL_TIME_REJ = 0x0011,
73 OM2K_MSGT_CAL_TIME_REQ = 0x0012,
74
75 OM2K_MSGT_CONNECT_CMD = 0x001c,
76 OM2K_MSGT_CONNECT_COMPL = 0x001e,
77 OM2K_MSGT_CONNECT_REJ = 0x001f,
78
Harald Welte6fec79d2011-02-12 14:57:17 +010079 OM2K_MSGT_DISCONNECT_CMD = 0x0030,
80 OM2K_MSGT_DISCONNECT_COMPL = 0x0032,
81 OM2K_MSGT_DISCONNECT_REJ = 0x0033,
82
Harald Welte9a311ec2011-02-12 12:33:06 +010083 OM2K_MSGT_FAULT_REP_ACK = 0x0040,
84 OM2K_MSGT_FAULT_REP_NACK = 0x0041,
85 OM2K_MSGT_FAULT_REP = 0x0042,
86
87 OM2K_MSGT_IS_CONF_REQ = 0x0060,
88 OM2K_MSGT_IS_CONF_REQ_ACK = 0x0062,
89 OM2K_MSGT_IS_CONF_REQ_REJ = 0x0063,
90 OM2K_MSGT_IS_CONF_RES_ACK = 0x0064,
91 OM2K_MSGT_IS_CONF_RES_NACK = 0x0065,
92 OM2K_MSGT_IS_CONF_RES = 0x0066,
93
94 OM2K_MSGT_OP_INFO = 0x0074,
95 OM2K_MSGT_OP_INFO_ACK = 0x0076,
96 OM2K_MSGT_OP_INFO_REJ = 0x0077,
97 OM2K_MSGT_RESET_CMD = 0x0078,
98 OM2K_MSGT_RESET_COMPL = 0x007a,
99 OM2K_MSGT_RESET_REJ = 0x007b,
100
101 OM2K_MSGT_START_REQ = 0x0084,
102 OM2K_MSGT_START_REQ_ACK = 0x0086,
103 OM2K_MSGT_START_REQ_REJ = 0x0087,
104 OM2K_MSGT_START_RES_ACK = 0x0088,
105 OM2K_MSGT_START_RES_NACK = 0x0089,
106 OM2K_MSGT_START_RES = 0x008a,
Harald Weltee1d5eca2011-02-12 14:42:59 +0100107 OM2K_MSGT_STATUS_REQ = 0x008c,
108 OM2K_MSGT_STATUS_RESP = 0x008e,
109 OM2K_MSGT_STATUS_REJ = 0x008f,
Harald Welte9a311ec2011-02-12 12:33:06 +0100110
Harald Welte8024d8f2011-02-12 15:07:30 +0100111 OM2K_MSGT_TEST_REQ = 0x0094,
112 OM2K_MSGT_TEST_REQ_ACK = 0x0096,
113 OM2K_MSGT_TEST_REQ_REJ = 0x0097,
114 OM2K_MSGT_TEST_RES_ACK = 0x0098,
115 OM2K_MSGT_TEST_RES_NACK = 0x0099,
116 OM2K_MSGT_TEST_RES = 0x009a,
117
Harald Welte9a311ec2011-02-12 12:33:06 +0100118 OM2K_MSGT_NEGOT_REQ_ACK = 0x0104,
119 OM2K_MSGT_NEGOT_REQ_NACK = 0x0105,
120 OM2K_MSGT_NEGOT_REQ = 0x0106,
121};
122
123enum abis_om2k_dei {
124 OM2K_DEI_CAL_TIME = 0x0d,
125 OM2K_DEI_OP_INFO = 0x2e,
Harald Welte73541072011-02-12 13:44:14 +0100126 OM2K_DEI_NEGOT_REC1 = 0x90,
127 OM2K_DEI_NEGOT_REC2 = 0x91,
Harald Welte9a311ec2011-02-12 12:33:06 +0100128};
129
130enum abis_om2k_mo_cls {
131 OM2K_MO_CLS_TRXC = 0x01,
132 OM2K_MO_CLS_TS = 0x03,
133 OM2K_MO_CLS_TF = 0x04,
134 OM2K_MO_CLS_IS = 0x05,
135 OM2K_MO_CLS_CON = 0x06,
136 OM2K_MO_CLS_DP = 0x07,
137 OM2K_MO_CLS_CF = 0x0a,
138 OM2K_MO_CLS_TX = 0x0b,
139 OM2K_MO_CLS_RX = 0x0c,
140};
141
142static const struct value_string om2k_msgcode_vals[] = {
143 { 0x0000, "Abort SP Command" },
144 { 0x0002, "Abort SP Complete" },
145 { 0x0004, "Alarm Report ACK" },
146 { 0x0005, "Alarm Report NACK" },
147 { 0x0006, "Alarm Report" },
148 { 0x0008, "Alarm Status Request" },
149 { 0x000a, "Alarm Status Request Accept" },
150 { 0x000b, "Alarm Status Request Reject" },
151 { 0x000c, "Alarm Status Result ACK" },
152 { 0x000d, "Alarm Status Result NACK" },
153 { 0x000e, "Alarm Status Result" },
154 { 0x0010, "Calendar Time Response" },
155 { 0x0011, "Calendar Time Reject" },
156 { 0x0012, "Calendar Time Request" },
157 { 0x0014, "CON Configuration Request" },
158 { 0x0016, "CON Configuration Request Accept" },
159 { 0x0017, "CON Configuration Request Reject" },
160 { 0x0018, "CON Configuration Result ACK" },
161 { 0x0019, "CON Configuration Result NACK" },
162 { 0x001a, "CON Configuration Result" },
163 { 0x001c, "Connect Command" },
164 { 0x001e, "Connect Complete" },
165 { 0x001f, "Connect Rejecte" },
166 { 0x0028, "Disable Request" },
167 { 0x002a, "Disable Request Accept" },
168 { 0x002b, "Disable Request Reject" },
169 { 0x002c, "Disable Result ACK" },
170 { 0x002d, "Disable Result NACK" },
171 { 0x002e, "Disable Result" },
172 { 0x0030, "Disconnect Command" },
173 { 0x0032, "Disconnect Complete" },
174 { 0x0033, "Disconnect Reject" },
175 { 0x0034, "Enable Request" },
176 { 0x0036, "Enable Request Accept" },
177 { 0x0037, "Enable Request Reject" },
178 { 0x0038, "Enable Result ACK" },
179 { 0x0039, "Enable Result NACK" },
180 { 0x003a, "Enable Result" },
181 { 0x003c, "Escape Downlink Normal" },
182 { 0x003d, "Escape Downlink NACK" },
183 { 0x003e, "Escape Uplink Normal" },
184 { 0x003f, "Escape Uplink NACK" },
185 { 0x0040, "Fault Report ACK" },
186 { 0x0041, "Fault Report NACK" },
187 { 0x0042, "Fault Report" },
188 { 0x0044, "File Package End Command" },
189 { 0x0046, "File Package End Result" },
190 { 0x0047, "File Package End Reject" },
191 { 0x0048, "File Relation Request" },
192 { 0x004a, "File Relation Response" },
193 { 0x004b, "File Relation Request Reject" },
194 { 0x004c, "File Segment Transfer" },
195 { 0x004e, "File Segment Transfer Complete" },
196 { 0x004f, "File Segment Transfer Reject" },
197 { 0x0050, "HW Information Request" },
198 { 0x0052, "HW Information Request Accept" },
199 { 0x0053, "HW Information Request Reject" },
200 { 0x0054, "HW Information Result ACK" },
201 { 0x0055, "HW Information Result NACK" },
202 { 0x0056, "HW Information Result" },
203 { 0x0060, "IS Configuration Request" },
204 { 0x0062, "IS Configuration Request Accept" },
205 { 0x0063, "IS Configuration Request Reject" },
206 { 0x0064, "IS Configuration Result ACK" },
207 { 0x0065, "IS Configuration Result NACK" },
208 { 0x0066, "IS Configuration Result" },
209 { 0x0068, "Load Data End" },
210 { 0x006a, "Load Data End Result" },
211 { 0x006b, "Load Data End Reject" },
212 { 0x006c, "Load Data Init" },
213 { 0x006e, "Load Data Init Accept" },
214 { 0x006f, "Load Data Init Reject" },
215 { 0x0070, "Loop Control Command" },
216 { 0x0072, "Loop Control Complete" },
217 { 0x0073, "Loop Control Reject" },
218 { 0x0074, "Operational Information" },
219 { 0x0076, "Operational Information Accept" },
220 { 0x0077, "Operational Information Reject" },
221 { 0x0078, "Reset Command" },
222 { 0x007a, "Reset Complete" },
223 { 0x007b, "Reset Reject" },
224 { 0x007c, "RX Configuration Request" },
225 { 0x007e, "RX Configuration Request Accept" },
226 { 0x007f, "RX Configuration Request Reject" },
227 { 0x0080, "RX Configuration Result ACK" },
228 { 0x0081, "RX Configuration Result NACK" },
229 { 0x0082, "RX Configuration Result" },
230 { 0x0084, "Start Request" },
231 { 0x0086, "Start Request Accept" },
232 { 0x0087, "Start Request Reject" },
233 { 0x0088, "Start Result ACK" },
234 { 0x0089, "Start Result NACK" },
235 { 0x008a, "Start Result" },
236 { 0x008c, "Status Request" },
237 { 0x008e, "Status Response" },
238 { 0x008f, "Status Reject" },
239 { 0x0094, "Test Request" },
240 { 0x0096, "Test Request Accept" },
241 { 0x0097, "Test Request Reject" },
242 { 0x0098, "Test Result ACK" },
243 { 0x0099, "Test Result NACK" },
244 { 0x009a, "Test Result" },
245 { 0x00a0, "TF Configuration Request" },
246 { 0x00a2, "TF Configuration Request Accept" },
247 { 0x00a3, "TF Configuration Request Reject" },
248 { 0x00a4, "TF Configuration Result ACK" },
249 { 0x00a5, "TF Configuration Result NACK" },
250 { 0x00a6, "TF Configuration Result" },
251 { 0x00a8, "TS Configuration Request" },
252 { 0x00aa, "TS Configuration Request Accept" },
253 { 0x00ab, "TS Configuration Request Reject" },
254 { 0x00ac, "TS Configuration Result ACK" },
255 { 0x00ad, "TS Configuration Result NACK" },
256 { 0x00ae, "TS Configuration Result" },
257 { 0x00b0, "TX Configuration Request" },
258 { 0x00b2, "TX Configuration Request Accept" },
259 { 0x00b3, "TX Configuration Request Reject" },
260 { 0x00b4, "TX Configuration Result ACK" },
261 { 0x00b5, "TX Configuration Result NACK" },
262 { 0x00b6, "TX Configuration Result" },
263 { 0x00bc, "DIP Alarm Report ACK" },
264 { 0x00bd, "DIP Alarm Report NACK" },
265 { 0x00be, "DIP Alarm Report" },
266 { 0x00c0, "DIP Alarm Status Request" },
267 { 0x00c2, "DIP Alarm Status Response" },
268 { 0x00c3, "DIP Alarm Status Reject" },
269 { 0x00c4, "DIP Quality Report I ACK" },
270 { 0x00c5, "DIP Quality Report I NACK" },
271 { 0x00c6, "DIP Quality Report I" },
272 { 0x00c8, "DIP Quality Report II ACK" },
273 { 0x00c9, "DIP Quality Report II NACK" },
274 { 0x00ca, "DIP Quality Report II" },
275 { 0x00dc, "DP Configuration Request" },
276 { 0x00de, "DP Configuration Request Accept" },
277 { 0x00df, "DP Configuration Request Reject" },
278 { 0x00e0, "DP Configuration Result ACK" },
279 { 0x00e1, "DP Configuration Result NACK" },
280 { 0x00e2, "DP Configuration Result" },
281 { 0x00e4, "Capabilities HW Info Report ACK" },
282 { 0x00e5, "Capabilities HW Info Report NACK" },
283 { 0x00e6, "Capabilities HW Info Report" },
284 { 0x00e8, "Capabilities Request" },
285 { 0x00ea, "Capabilities Request Accept" },
286 { 0x00eb, "Capabilities Request Reject" },
287 { 0x00ec, "Capabilities Result ACK" },
288 { 0x00ed, "Capabilities Result NACK" },
289 { 0x00ee, "Capabilities Result" },
290 { 0x00f0, "FM Configuration Request" },
291 { 0x00f2, "FM Configuration Request Accept" },
292 { 0x00f3, "FM Configuration Request Reject" },
293 { 0x00f4, "FM Configuration Result ACK" },
294 { 0x00f5, "FM Configuration Result NACK" },
295 { 0x00f6, "FM Configuration Result" },
296 { 0x00f8, "FM Report Request" },
297 { 0x00fa, "FM Report Response" },
298 { 0x00fb, "FM Report Reject" },
299 { 0x00fc, "FM Start Command" },
300 { 0x00fe, "FM Start Complete" },
301 { 0x00ff, "FM Start Reject" },
302 { 0x0100, "FM Stop Command" },
303 { 0x0102, "FM Stop Complete" },
304 { 0x0103, "FM Stop Reject" },
305 { 0x0104, "Negotiation Request ACK" },
306 { 0x0105, "Negotiation Request NACK" },
307 { 0x0106, "Negotiation Request" },
308 { 0x0108, "BTS Initiated Request ACK" },
309 { 0x0109, "BTS Initiated Request NACK" },
310 { 0x010a, "BTS Initiated Request" },
311 { 0x010c, "Radio Channels Release Command" },
312 { 0x010e, "Radio Channels Release Complete" },
313 { 0x010f, "Radio Channels Release Reject" },
314 { 0x0118, "Feature Control Command" },
315 { 0x011a, "Feature Control Complete" },
316 { 0x011b, "Feature Control Reject" },
317
318 { 0, NULL }
319};
320
321/* TS 12.21 Section 9.4: Attributes */
322static const struct value_string om2k_attr_vals[] = {
323 { 0x00, "Accordance indication" },
324 { 0x01, "Alarm Id" },
325 { 0x02, "Alarm Data" },
326 { 0x03, "Alarm Severity" },
327 { 0x04, "Alarm Status" },
328 { 0x05, "Alarm Status Type" },
329 { 0x06, "BCC" },
330 { 0x07, "BS_AG_BKS_RES" },
331 { 0x09, "BSIC" },
332 { 0x0a, "BA_PA_MFRMS" },
333 { 0x0b, "CBCH Indicator" },
334 { 0x0c, "CCCH Options" },
335 { 0x0d, "Calendar Time" },
336 { 0x0f, "Channel Combination" },
337 { 0x10, "CON Connection List" },
338 { 0x11, "Data End Indication" },
339 { 0x12, "DRX_DEV_MAX" },
340 { 0x13, "End List Number" },
341 { 0x14, "External Condition Map Class 1" },
342 { 0x15, "External Condition Map Class 2" },
343 { 0x16, "File Relation Indication" },
344 { 0x17, "File Revision" },
345 { 0x18, "File Segment Data" },
346 { 0x19, "File Segment Length" },
347 { 0x1a, "File Segment Sequence Number" },
348 { 0x1b, "File Size" },
349 { 0x1c, "Filling Marker" },
350 { 0x1d, "FN Offset" },
351 { 0x1e, "Frequency List" },
352 { 0x1f, "Frequency Specifier RX" },
353 { 0x20, "Frequency Specifier TX" },
354 { 0x21, "HSN" },
355 { 0x22, "ICM Indicator" },
356 { 0x23, "Internal Fault Map Class 1A" },
357 { 0x24, "Internal Fault Map Class 1B" },
358 { 0x25, "Internal Fault Map Class 2A" },
359 { 0x26, "Internal Fault Map Class 2A Extension" },
360 { 0x27, "IS Connection List" },
361 { 0x28, "List Number" },
362 { 0x29, "File Package State Indication" },
363 { 0x2a, "Local Access State" },
364 { 0x2b, "MAIO" },
365 { 0x2c, "MO State" },
366 { 0x2d, "Ny1" },
367 { 0x2e, "Operational Information" },
368 { 0x2f, "Power" },
369 { 0x30, "RU Position Data" },
370 { 0x31, "Protocol Error" },
371 { 0x32, "Reason Code" },
372 { 0x33, "Receiver Diversity" },
373 { 0x34, "Replacement Unit Map" },
374 { 0x35, "Result Code" },
375 { 0x36, "RU Revision Data" },
376 { 0x38, "T3105" },
377 { 0x39, "Test Loop Setting" },
378 { 0x3a, "TF Mode" },
379 { 0x3b, "TF Compensation Value" },
380 { 0x3c, "Time Slot Number" },
381 { 0x3d, "TSC" },
382 { 0x3e, "RU Logical Id" },
383 { 0x3f, "RU Serial Number Data" },
384 { 0x40, "BTS Version" },
385 { 0x41, "OML IWD Version" },
386 { 0x42, "RWL IWD Version" },
387 { 0x43, "OML Function Map 1" },
388 { 0x44, "OML Function Map 2" },
389 { 0x45, "RSL Function Map 1" },
390 { 0x46, "RSL Function Map 2" },
391 { 0x47, "Extended Range Indicator" },
392 { 0x48, "Request Indicators" },
393 { 0x49, "DIP Alarm Condition Map" },
394 { 0x4a, "ES Incoming" },
395 { 0x4b, "ES Outgoing" },
396 { 0x4e, "SES Incoming" },
397 { 0x4f, "SES Outgoing" },
398 { 0x50, "Replacement Unit Map Extension" },
399 { 0x52, "UAS Incoming" },
400 { 0x53, "UAS Outgoing" },
401 { 0x58, "DF Incoming" },
402 { 0x5a, "DF Outgoing" },
403 { 0x5c, "SF" },
404 { 0x60, "S Bits Setting" },
405 { 0x61, "CRC-4 Use Option" },
406 { 0x62, "T Parameter" },
407 { 0x63, "N Parameter" },
408 { 0x64, "N1 Parameter" },
409 { 0x65, "N3 Parameter" },
410 { 0x66, "N4 Parameter" },
411 { 0x67, "P Parameter" },
412 { 0x68, "Q Parameter" },
413 { 0x69, "BI_Q1" },
414 { 0x6a, "BI_Q2" },
415 { 0x74, "ICM Boundary Parameters" },
416 { 0x77, "AFT" },
417 { 0x78, "AFT RAI" },
418 { 0x79, "Link Supervision Control" },
419 { 0x7a, "Link Supervision Filtering Time" },
420 { 0x7b, "Call Supervision Time" },
421 { 0x7c, "Interval Length UAS Incoming" },
422 { 0x7d, "Interval Length UAS Outgoing" },
423 { 0x7e, "ICM Channel Rate" },
424 { 0x7f, "Attribute Identifier" },
425 { 0x80, "FM Frequency List" },
426 { 0x81, "FM Frequency Report" },
427 { 0x82, "FM Percentile" },
428 { 0x83, "FM Clear Indication" },
429 { 0x84, "HW Info Signature" },
430 { 0x85, "MO Record" },
431 { 0x86, "TF Synchronisation Source" },
432 { 0x87, "TTA" },
433 { 0x88, "End Segment Number" },
434 { 0x89, "Segment Number" },
435 { 0x8a, "Capabilities Signature" },
436 { 0x8c, "File Relation List" },
437 { 0x90, "Negotiation Record I" },
438 { 0x91, "Negotiation Record II" },
439 { 0x92, "Encryption Algorithm" },
440 { 0x94, "Interference Rejection Combining" },
441 { 0x95, "Dedication Information" },
442 { 0x97, "Feature Code" },
443 { 0x98, "FS Offset" },
444 { 0x99, "ESB Timeslot" },
445 { 0x9a, "Master TG Instance" },
446 { 0x9b, "Master TX Chain Delay" },
447 { 0x9c, "External Condition Class 2 Extension" },
448 { 0x9d, "TSs MO State" },
449 { 0, NULL }
450};
451
Harald Weltee1d5eca2011-02-12 14:42:59 +0100452const struct value_string om2k_mo_class_short_vals[] = {
Harald Welte9a311ec2011-02-12 12:33:06 +0100453 { 0x01, "TRXC" },
454 { 0x03, "TS" },
455 { 0x04, "TF" },
456 { 0x05, "IS" },
457 { 0x06, "CON" },
458 { 0x07, "DP" },
459 { 0x0a, "CF" },
460 { 0x0b, "TX" },
461 { 0x0c, "RX" },
462 { 0, NULL }
463};
464
465static struct msgb *om2k_msgb_alloc(void)
466{
467 return msgb_alloc_headroom(OM_ALLOC_SIZE, OM_HEADROOM_SIZE,
468 "OM2000");
469}
470
Harald Weltebc867d92011-02-12 13:09:38 +0100471static int abis_om2k_sendmsg(struct gsm_bts *bts, struct msgb *msg)
472{
473 msg->trx = bts->c0;
474
475 return _abis_nm_sendmsg(msg);
476}
477
Harald Welte9a311ec2011-02-12 12:33:06 +0100478static void fill_om2k_hdr(struct abis_om2k_hdr *o2h, const struct abis_om2k_mo *mo,
479 uint16_t msg_type, uint8_t attr_len)
480{
481 o2h->om.mdisc = ABIS_OM_MDISC_FOM;
482 o2h->om.placement = ABIS_OM_PLACEMENT_ONLY;
483 o2h->om.sequence = 0;
Harald Weltebc867d92011-02-12 13:09:38 +0100484 o2h->om.length = 6 + attr_len;
Harald Welte9a311ec2011-02-12 12:33:06 +0100485 o2h->msg_type = htons(msg_type);
486 memcpy(&o2h->mo, mo, sizeof(o2h->mo));
487}
488
489static char *om2k_mo_name(const struct abis_om2k_mo *mo)
490{
491 static char mo_buf[64];
492
493 memset(mo_buf, 0, sizeof(mo_buf));
494 snprintf(mo_buf, sizeof(mo_buf), "%s/%02x/%02x/%02x",
495 get_value_string(om2k_mo_class_short_vals, mo->class),
496 mo->bts, mo->assoc_so, mo->inst);
497 return mo_buf;
498}
499
Harald Welte73541072011-02-12 13:44:14 +0100500const struct abis_om2k_mo om2k_mo_cf = { OM2K_MO_CLS_CF, 0, 0xFF, 0 };
Harald Welte9a311ec2011-02-12 12:33:06 +0100501
502static int abis_om2k_cal_time_resp(struct gsm_bts *bts)
503{
504 struct msgb *msg = om2k_msgb_alloc();
505 struct abis_om2k_hdr *o2k;
506 time_t tm_t;
507 struct tm *tm;
508
509 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
510 fill_om2k_hdr(o2k, &om2k_mo_cf, OM2K_MSGT_CAL_TIME_RESP, 7);
511
512 tm_t = time(NULL);
513 tm = localtime(&tm_t);
514
515 msgb_put_u8(msg, OM2K_DEI_CAL_TIME);
516 msgb_put_u8(msg, tm->tm_year % 100);
517 msgb_put_u8(msg, tm->tm_mon + 1);
518 msgb_put_u8(msg, tm->tm_mday);
519 msgb_put_u8(msg, tm->tm_hour);
520 msgb_put_u8(msg, tm->tm_min);
521 msgb_put_u8(msg, tm->tm_sec);
522
Harald Weltebc867d92011-02-12 13:09:38 +0100523 return abis_om2k_sendmsg(bts, msg);
Harald Welte9a311ec2011-02-12 12:33:06 +0100524}
525
Harald Welte6fec79d2011-02-12 14:57:17 +0100526static int abis_om2k_tx_simple(struct gsm_bts *bts, const struct abis_om2k_mo *mo,
Harald Welte9a311ec2011-02-12 12:33:06 +0100527 uint8_t msg_type)
528{
529 struct msgb *msg = om2k_msgb_alloc();
530 struct abis_om2k_hdr *o2k;
531
532 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
533 fill_om2k_hdr(o2k, mo, msg_type, 0);
534
Harald Welte73541072011-02-12 13:44:14 +0100535 DEBUGP(DNM, "Tx MO=%s %s\n", om2k_mo_name(mo),
536 get_value_string(om2k_msgcode_vals, msg_type));
537
Harald Weltebc867d92011-02-12 13:09:38 +0100538 return abis_om2k_sendmsg(bts, msg);
Harald Welte9a311ec2011-02-12 12:33:06 +0100539}
540
Harald Welte6fec79d2011-02-12 14:57:17 +0100541int abis_om2k_tx_reset_cmd(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
Harald Welte73541072011-02-12 13:44:14 +0100542{
543 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_RESET_CMD);
544}
545
Harald Welte6fec79d2011-02-12 14:57:17 +0100546int abis_om2k_tx_start_req(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
Harald Welte73541072011-02-12 13:44:14 +0100547{
548 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_START_REQ);
549}
550
Harald Welte6fec79d2011-02-12 14:57:17 +0100551int abis_om2k_tx_status_req(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
Harald Weltee1d5eca2011-02-12 14:42:59 +0100552{
553 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_STATUS_REQ);
554}
555
Harald Welte6fec79d2011-02-12 14:57:17 +0100556int abis_om2k_tx_connect_cmd(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
557{
558 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_CONNECT_CMD);
559}
560
561int abis_om2k_tx_disconnect_cmd(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
562{
563 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_DISCONNECT_CMD);
564}
565
Harald Welte8024d8f2011-02-12 15:07:30 +0100566int abis_om2k_tx_test_req(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
567{
568 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_TEST_REQ);
569}
570
Harald Welte6fec79d2011-02-12 14:57:17 +0100571int abis_om2k_tx_op_info(struct gsm_bts *bts, const struct abis_om2k_mo *mo,
572 uint8_t operational)
Harald Welte9a311ec2011-02-12 12:33:06 +0100573{
574 struct msgb *msg = om2k_msgb_alloc();
575 struct abis_om2k_hdr *o2k;
576
577 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
578 fill_om2k_hdr(o2k, mo, OM2K_MSGT_OP_INFO, 2);
579
580 msgb_tv_put(msg, OM2K_DEI_OP_INFO, operational);
581
Harald Welte73541072011-02-12 13:44:14 +0100582 DEBUGP(DNM, "Tx MO=%s %s\n", om2k_mo_name(mo),
583 get_value_string(om2k_msgcode_vals, OM2K_MSGT_OP_INFO));
584
Harald Weltebc867d92011-02-12 13:09:38 +0100585 return abis_om2k_sendmsg(bts, msg);
Harald Welte9a311ec2011-02-12 12:33:06 +0100586}
587
Harald Welte6fec79d2011-02-12 14:57:17 +0100588static int abis_om2k_tx_negot_req_ack(struct gsm_bts *bts, const struct abis_om2k_mo *mo,
Harald Welte73541072011-02-12 13:44:14 +0100589 uint8_t *data, unsigned int len)
590{
591 struct msgb *msg = om2k_msgb_alloc();
592 struct abis_om2k_hdr *o2k;
593
594 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
595 fill_om2k_hdr(o2k, mo, OM2K_MSGT_NEGOT_REQ_ACK, 2+len);
596
597 msgb_tlv_put(msg, OM2K_DEI_NEGOT_REC2, len, data);
598
599 DEBUGP(DNM, "Tx MO=%s %s\n", om2k_mo_name(mo),
600 get_value_string(om2k_msgcode_vals, OM2K_MSGT_NEGOT_REQ_ACK));
601
602 return abis_om2k_sendmsg(bts, msg);
603}
Harald Welte9a311ec2011-02-12 12:33:06 +0100604
Harald Welte563d3162011-02-12 18:11:16 +0100605struct iwd_version {
606 uint8_t gen_char[3+1];
607 uint8_t rev_char[3+1];
608};
609
610struct iwd_type {
611 uint8_t num_vers;
612 struct iwd_version v[8];
613};
614
Harald Welte9a311ec2011-02-12 12:33:06 +0100615static int om2k_rx_negot_req(struct msgb *msg)
616{
617 struct abis_om2k_hdr *o2h = msgb_l2(msg);
Harald Welte563d3162011-02-12 18:11:16 +0100618 struct iwd_type iwd_types[16];
619 uint8_t num_iwd_types = o2h->data[2];
620 uint8_t *cur = o2h->data+3;
621 unsigned int i, v;
Harald Welte9a311ec2011-02-12 12:33:06 +0100622
Harald Welte563d3162011-02-12 18:11:16 +0100623 uint8_t out_buf[1024];
624 uint8_t *out_cur = out_buf+1;
625 uint8_t out_num_types = 0;
626
627 memset(iwd_types, 0, sizeof(iwd_types));
628
629 /* Parse the RBS-supported IWD versions into iwd_types array */
630 for (i = 0; i < num_iwd_types; i++) {
631 uint8_t num_versions = *cur++;
632 uint8_t iwd_type = *cur++;
633
634 iwd_types[iwd_type].num_vers = num_versions;
635
636 for (v = 0; v < num_versions; v++) {
637 struct iwd_version *iwd_v = &iwd_types[iwd_type].v[v];
638
639 memcpy(iwd_v->gen_char, cur, 3);
640 memcpy(iwd_v->rev_char, cur+3, 3);
641 DEBUGP(DNM, "\tIWD Type %u Gen %s Rev %s\n", iwd_type,
642 iwd_v->gen_char, iwd_v->rev_char);
643 }
644 }
645
646 /* Select the last version for each IWD type */
647 for (i = 0; i < ARRAY_SIZE(iwd_types); i++) {
648 struct iwd_type *type = &iwd_types[i];
649 struct iwd_version *last_v;
650
651 if (type->num_vers == 0)
652 continue;
653
654 out_num_types++;
655
656 last_v = &type->v[type->num_vers-1];
657
658 *out_cur++ = i;
659 memcpy(out_cur, last_v->gen_char, 3);
660 out_cur += 3;
661 memcpy(out_cur, last_v->rev_char, 3);
662 out_cur += 3;
663 }
664
665 out_buf[0] = out_num_types;
666
667 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 +0100668}
669
670static int om2k_rx_start_res(struct msgb *msg)
671{
672 struct abis_om2k_hdr *o2h = msgb_l2(msg);
673 int rc;
674
675 rc = abis_om2k_tx_simple(msg->trx->bts, &o2h->mo, OM2K_MSGT_START_RES_ACK);
676 rc = abis_om2k_tx_op_info(msg->trx->bts, &o2h->mo, 1);
677
678 return rc;
679}
680
681static int om2k_rx_op_info(struct msgb *msg)
682{
683 struct abis_om2k_hdr *o2h = msgb_l2(msg);
684 uint8_t op_info = o2h->data[1];
685
Harald Welte73541072011-02-12 13:44:14 +0100686 DEBUGP(DNM, "Rx MO=%s OPERATIONAL INFO: %u\n", om2k_mo_name(&o2h->mo), op_info);
Harald Welte9a311ec2011-02-12 12:33:06 +0100687
688 return abis_om2k_tx_simple(msg->trx->bts, &o2h->mo, OM2K_MSGT_OP_INFO_ACK);
689}
690
691int abis_om2k_rcvmsg(struct msgb *msg)
692{
693 struct gsm_bts *bts = msg->trx->bts;
694 struct abis_om2k_hdr *o2h = msgb_l2(msg);
695 struct abis_om_hdr *oh = &o2h->om;
Harald Weltebc867d92011-02-12 13:09:38 +0100696 uint16_t msg_type = ntohs(o2h->msg_type);
Harald Welte9a311ec2011-02-12 12:33:06 +0100697 int rc = 0;
698
699 /* Various consistency checks */
700 if (oh->placement != ABIS_OM_PLACEMENT_ONLY) {
701 LOGP(DNM, LOGL_ERROR, "ABIS OML placement 0x%x not supported\n",
702 oh->placement);
703 if (oh->placement != ABIS_OM_PLACEMENT_FIRST)
704 return -EINVAL;
705 }
706 if (oh->sequence != 0) {
707 LOGP(DNM, LOGL_ERROR, "ABIS OML sequence 0x%x != 0x00\n",
708 oh->sequence);
709 return -EINVAL;
710 }
711
712 msg->l3h = (unsigned char *)o2h + sizeof(*o2h);
713
714 if (oh->mdisc != ABIS_OM_MDISC_FOM) {
715 LOGP(DNM, LOGL_ERROR, "unknown ABIS OM2000 message discriminator 0x%x\n",
716 oh->mdisc);
717 return -EINVAL;
718 }
719
Harald Welte73541072011-02-12 13:44:14 +0100720 DEBUGP(DNM, "Rx MO=%s %s (%s)\n", om2k_mo_name(&o2h->mo),
Harald Weltebc867d92011-02-12 13:09:38 +0100721 get_value_string(om2k_msgcode_vals, msg_type),
Harald Welte9a311ec2011-02-12 12:33:06 +0100722 hexdump(msg->l2h, msgb_l2len(msg)));
723
Harald Weltebc867d92011-02-12 13:09:38 +0100724 switch (msg_type) {
Harald Welte9a311ec2011-02-12 12:33:06 +0100725 case OM2K_MSGT_CAL_TIME_REQ:
726 rc = abis_om2k_cal_time_resp(bts);
727 break;
728 case OM2K_MSGT_FAULT_REP:
729 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_START_REQ);
730 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_FAULT_REP_ACK);
731 break;
732 case OM2K_MSGT_NEGOT_REQ:
733 rc = om2k_rx_negot_req(msg);
734 break;
735 case OM2K_MSGT_START_RES:
736 rc = om2k_rx_start_res(msg);
737 break;
738 case OM2K_MSGT_OP_INFO:
739 rc = om2k_rx_op_info(msg);
740 break;
741 case OM2K_MSGT_IS_CONF_RES:
742 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_IS_CONF_RES_ACK);
743 break;
744 case OM2K_MSGT_CONNECT_COMPL:
745 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_RESET_CMD);
746 break;
747 case OM2K_MSGT_RESET_COMPL:
748 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_START_REQ);
749 break;
750 case OM2K_MSGT_START_REQ_ACK:
751 break;
752 default:
753 LOGP(DNM, LOGL_NOTICE, "Rx unknown OM2000 msg %s\n",
Harald Weltebc867d92011-02-12 13:09:38 +0100754 get_value_string(om2k_msgcode_vals, msg_type));
Harald Welte9a311ec2011-02-12 12:33:06 +0100755 }
756
757 msgb_free(msg);
758 return rc;
759}