blob: e98ac1ce38657d55ffd1adec5ce669a34f7595da [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 Weltee898ecc2011-03-06 19:26:11 +0100168 OM2K_DEI_ACCORDANCE_IND = 0x00,
Harald Weltea0ce3492011-03-05 14:13:14 +0100169 OM2K_DEI_BCC = 0x06,
Harald Welte1164dce2011-03-05 19:21:26 +0100170 OM2K_DEI_BS_AG_BKS_RES = 0x07,
Harald Weltea0ce3492011-03-05 14:13:14 +0100171 OM2K_DEI_BSIC = 0x09,
Harald Welte1164dce2011-03-05 19:21:26 +0100172 OM2K_DEI_BA_PA_MFRMS = 0x0a,
173 OM2K_DEI_CBCH_INDICATOR = 0x0b,
174 OM2K_DEI_CCCH_OPTIONS = 0x0c,
Harald Welte9a311ec2011-02-12 12:33:06 +0100175 OM2K_DEI_CAL_TIME = 0x0d,
Harald Weltea0ce3492011-03-05 14:13:14 +0100176 OM2K_DEI_COMBINATION = 0x0f,
Harald Weltefdb71942011-02-14 15:31:43 +0100177 OM2K_DEI_CON_CONN_LIST = 0x10,
Harald Welte1164dce2011-03-05 19:21:26 +0100178 OM2K_DEI_DRX_DEV_MAX = 0x12,
Harald Welte8bcb1a02011-02-12 20:23:40 +0100179 OM2K_DEI_END_LIST_NR = 0x13,
Harald Weltef6d6b212011-03-05 20:13:52 +0100180 OM2K_DEI_EXT_COND_MAP_1 = 0x14,
181 OM2K_DEI_EXT_COND_MAP_2 = 0x15,
Harald Weltea0ce3492011-03-05 14:13:14 +0100182 OM2K_DEI_FILLING_MARKER = 0x1c,
183 OM2K_DEI_FN_OFFSET = 0x1d,
184 OM2K_DEI_FREQ_LIST = 0x1e,
185 OM2K_DEI_FREQ_SPEC_RX = 0x1f,
186 OM2K_DEI_FREQ_SPEC_TX = 0x20,
187 OM2K_DEI_HSN = 0x21,
Harald Welte1164dce2011-03-05 19:21:26 +0100188 OM2K_DEI_ICM_INDICATOR = 0x22,
Harald Weltef6d6b212011-03-05 20:13:52 +0100189 OM2K_DEI_INT_FAULT_MAP_1A = 0x23,
190 OM2K_DEI_INT_FAULT_MAP_1B = 0x24,
191 OM2K_DEI_INT_FAULT_MAP_2A = 0x25,
192 OM2K_DEI_INT_FAULT_MAP_2A_EXT = 0x26,
Harald Welte8bcb1a02011-02-12 20:23:40 +0100193 OM2K_DEI_IS_CONN_LIST = 0x27,
194 OM2K_DEI_LIST_NR = 0x28,
Harald Weltef6d6b212011-03-05 20:13:52 +0100195 OM2K_DEI_LOCAL_ACCESS = 0x2a,
Harald Weltea0ce3492011-03-05 14:13:14 +0100196 OM2K_DEI_MAIO = 0x2b,
Harald Weltef6d6b212011-03-05 20:13:52 +0100197 OM2K_DEI_MO_STATE = 0x2c,
Harald Welte1164dce2011-03-05 19:21:26 +0100198 OM2K_DEI_NY1 = 0x2d,
Harald Welte9a311ec2011-02-12 12:33:06 +0100199 OM2K_DEI_OP_INFO = 0x2e,
Harald Weltea0ce3492011-03-05 14:13:14 +0100200 OM2K_DEI_POWER = 0x2f,
Harald Weltee6e83832011-03-05 17:52:09 +0100201 OM2K_DEI_REASON_CODE = 0x32,
Harald Weltea0ce3492011-03-05 14:13:14 +0100202 OM2K_DEI_RX_DIVERSITY = 0x33,
Harald Weltee6e83832011-03-05 17:52:09 +0100203 OM2K_DEI_RESULT_CODE = 0x35,
Harald Welte1164dce2011-03-05 19:21:26 +0100204 OM2K_DEI_T3105 = 0x38,
Harald Weltef9cf9612011-03-05 14:36:47 +0100205 OM2K_DEI_TF_MODE = 0x3a,
Harald Weltea0ce3492011-03-05 14:13:14 +0100206 OM2K_DEI_TS_NR = 0x3c,
Harald Welte1164dce2011-03-05 19:21:26 +0100207 OM2K_DEI_TSC = 0x3d,
Harald Weltef6d6b212011-03-05 20:13:52 +0100208 OM2K_DEI_BTS_VERSION = 0x40,
209 OM2K_DEI_OML_IWD_VERSION = 0x41,
210 OM2K_DEI_RSL_IWD_VERSION = 0x42,
211 OM2K_DEI_OML_FUNC_MAP_1 = 0x43,
212 OM2K_DEI_OML_FUNC_MAP_2 = 0x44,
213 OM2K_DEI_RSL_FUNC_MAP_1 = 0x45,
214 OM2K_DEI_RSL_FUNC_MAP_2 = 0x46,
Harald Weltea0ce3492011-03-05 14:13:14 +0100215 OM2K_DEI_EXT_RANGE = 0x47,
Harald Weltef6d6b212011-03-05 20:13:52 +0100216 OM2K_DEI_REQ_IND = 0x48,
217 OM2K_DEI_REPL_UNIT_MAP = 0x50,
Harald Welte75755c52011-03-05 20:38:35 +0100218 OM2K_DEI_ICM_BOUND_PARAMS = 0x74,
Harald Welte1164dce2011-03-05 19:21:26 +0100219 OM2K_DEI_LSC = 0x79,
220 OM2K_DEI_LSC_FILT_TIME = 0x7a,
221 OM2K_DEI_CALL_SUPV_TIME = 0x7b,
Harald Welte75755c52011-03-05 20:38:35 +0100222 OM2K_DEI_ICM_CHAN_RATE = 0x7e,
Harald Weltef6d6b212011-03-05 20:13:52 +0100223 OM2K_DEI_HW_INFO_SIG = 0x84,
Harald Welteba9adbb2011-03-06 19:01:16 +0100224 OM2K_DEI_TF_SYNC_SRC = 0x86,
Harald Welte1164dce2011-03-05 19:21:26 +0100225 OM2K_DEI_TTA = 0x87,
Harald Weltef6d6b212011-03-05 20:13:52 +0100226 OM2K_DEI_CAPA_SIG = 0x8a,
Harald Welte73541072011-02-12 13:44:14 +0100227 OM2K_DEI_NEGOT_REC1 = 0x90,
228 OM2K_DEI_NEGOT_REC2 = 0x91,
Harald Welte1164dce2011-03-05 19:21:26 +0100229 OM2K_DEI_ENCR_ALG = 0x92,
230 OM2K_DEI_INTERF_REJ_COMB = 0x94,
Harald Weltef9cf9612011-03-05 14:36:47 +0100231 OM2K_DEI_FS_OFFSET = 0x98,
Harald Weltef6d6b212011-03-05 20:13:52 +0100232 OM2K_DEI_EXT_COND_MAP_2_EXT = 0x9c,
Harald Welte9a311ec2011-02-12 12:33:06 +0100233};
234
Harald Weltee6e83832011-03-05 17:52:09 +0100235const struct tlv_definition om2k_att_tlvdef = {
236 .def = {
Harald Weltee898ecc2011-03-06 19:26:11 +0100237 [OM2K_DEI_ACCORDANCE_IND] = { TLV_TYPE_TV },
Harald Weltee6e83832011-03-05 17:52:09 +0100238 [OM2K_DEI_BCC] = { TLV_TYPE_TV },
Harald Welte1164dce2011-03-05 19:21:26 +0100239 [OM2K_DEI_BS_AG_BKS_RES] = { TLV_TYPE_TV },
Harald Weltee6e83832011-03-05 17:52:09 +0100240 [OM2K_DEI_BSIC] = { TLV_TYPE_TV },
Harald Welte1164dce2011-03-05 19:21:26 +0100241 [OM2K_DEI_BA_PA_MFRMS] = { TLV_TYPE_TV },
242 [OM2K_DEI_CBCH_INDICATOR] = { TLV_TYPE_TV },
Harald Weltef6d6b212011-03-05 20:13:52 +0100243 [OM2K_DEI_INT_FAULT_MAP_1A] = { TLV_TYPE_FIXED, 6 },
244 [OM2K_DEI_INT_FAULT_MAP_1B] = { TLV_TYPE_FIXED, 6 },
245 [OM2K_DEI_INT_FAULT_MAP_2A] = { TLV_TYPE_FIXED, 6 },
246 [OM2K_DEI_INT_FAULT_MAP_2A_EXT]={ TLV_TYPE_FIXED, 6 },
Harald Welte1164dce2011-03-05 19:21:26 +0100247 [OM2K_DEI_CCCH_OPTIONS] = { TLV_TYPE_TV },
Harald Weltee6e83832011-03-05 17:52:09 +0100248 [OM2K_DEI_CAL_TIME] = { TLV_TYPE_FIXED, 6 },
249 [OM2K_DEI_COMBINATION] = { TLV_TYPE_TV },
250 [OM2K_DEI_CON_CONN_LIST] = { TLV_TYPE_TLV },
Harald Welte1164dce2011-03-05 19:21:26 +0100251 [OM2K_DEI_DRX_DEV_MAX] = { TLV_TYPE_TV },
Harald Weltee6e83832011-03-05 17:52:09 +0100252 [OM2K_DEI_END_LIST_NR] = { TLV_TYPE_TV },
Harald Weltef6d6b212011-03-05 20:13:52 +0100253 [OM2K_DEI_EXT_COND_MAP_1] = { TLV_TYPE_FIXED, 2 },
254 [OM2K_DEI_EXT_COND_MAP_2] = { TLV_TYPE_FIXED, 2 },
Harald Weltee6e83832011-03-05 17:52:09 +0100255 [OM2K_DEI_FILLING_MARKER] = { TLV_TYPE_TV },
256 [OM2K_DEI_FN_OFFSET] = { TLV_TYPE_FIXED, 2 },
257 [OM2K_DEI_FREQ_LIST] = { TLV_TYPE_TLV },
258 [OM2K_DEI_FREQ_SPEC_RX] = { TLV_TYPE_FIXED, 2 },
259 [OM2K_DEI_FREQ_SPEC_TX] = { TLV_TYPE_FIXED, 2 },
260 [OM2K_DEI_HSN] = { TLV_TYPE_TV },
Harald Welte1164dce2011-03-05 19:21:26 +0100261 [OM2K_DEI_ICM_INDICATOR] = { TLV_TYPE_TV },
Harald Weltee6e83832011-03-05 17:52:09 +0100262 [OM2K_DEI_IS_CONN_LIST] = { TLV_TYPE_TLV },
263 [OM2K_DEI_LIST_NR] = { TLV_TYPE_TV },
Harald Weltef6d6b212011-03-05 20:13:52 +0100264 [OM2K_DEI_LOCAL_ACCESS] = { TLV_TYPE_TV },
Harald Weltee6e83832011-03-05 17:52:09 +0100265 [OM2K_DEI_MAIO] = { TLV_TYPE_TV },
Harald Weltef6d6b212011-03-05 20:13:52 +0100266 [OM2K_DEI_MO_STATE] = { TLV_TYPE_TV },
Harald Welte1164dce2011-03-05 19:21:26 +0100267 [OM2K_DEI_NY1] = { TLV_TYPE_TV },
Harald Weltee6e83832011-03-05 17:52:09 +0100268 [OM2K_DEI_OP_INFO] = { TLV_TYPE_TV },
269 [OM2K_DEI_POWER] = { TLV_TYPE_TV },
270 [OM2K_DEI_REASON_CODE] = { TLV_TYPE_TV },
271 [OM2K_DEI_RX_DIVERSITY] = { TLV_TYPE_TV },
272 [OM2K_DEI_RESULT_CODE] = { TLV_TYPE_TV },
Harald Welte1164dce2011-03-05 19:21:26 +0100273 [OM2K_DEI_T3105] = { TLV_TYPE_TV },
Harald Weltee6e83832011-03-05 17:52:09 +0100274 [OM2K_DEI_TF_MODE] = { TLV_TYPE_TV },
275 [OM2K_DEI_TS_NR] = { TLV_TYPE_TV },
Harald Welte1164dce2011-03-05 19:21:26 +0100276 [OM2K_DEI_TSC] = { TLV_TYPE_TV },
Harald Weltef6d6b212011-03-05 20:13:52 +0100277 [OM2K_DEI_BTS_VERSION] = { TLV_TYPE_FIXED, 12 },
278 [OM2K_DEI_OML_IWD_VERSION] = { TLV_TYPE_FIXED, 6 },
279 [OM2K_DEI_RSL_IWD_VERSION] = { TLV_TYPE_FIXED, 6 },
280 [OM2K_DEI_OML_FUNC_MAP_1] = { TLV_TYPE_TLV },
281 [OM2K_DEI_OML_FUNC_MAP_2] = { TLV_TYPE_TLV },
282 [OM2K_DEI_RSL_FUNC_MAP_1] = { TLV_TYPE_TLV },
283 [OM2K_DEI_RSL_FUNC_MAP_2] = { TLV_TYPE_TLV },
Harald Weltee6e83832011-03-05 17:52:09 +0100284 [OM2K_DEI_EXT_RANGE] = { TLV_TYPE_TV },
Harald Weltef6d6b212011-03-05 20:13:52 +0100285 [OM2K_DEI_REQ_IND] = { TLV_TYPE_TV },
286 [OM2K_DEI_REPL_UNIT_MAP] = { TLV_TYPE_FIXED, 6 },
Harald Welte75755c52011-03-05 20:38:35 +0100287 [OM2K_DEI_ICM_BOUND_PARAMS] = { TLV_TYPE_FIXED, 5 },
Harald Welte1164dce2011-03-05 19:21:26 +0100288 [OM2K_DEI_LSC] = { TLV_TYPE_TV },
289 [OM2K_DEI_LSC_FILT_TIME] = { TLV_TYPE_TV },
290 [OM2K_DEI_CALL_SUPV_TIME] = { TLV_TYPE_TV },
Harald Welte75755c52011-03-05 20:38:35 +0100291 [OM2K_DEI_ICM_CHAN_RATE] = { TLV_TYPE_TV },
Harald Weltef6d6b212011-03-05 20:13:52 +0100292 [OM2K_DEI_HW_INFO_SIG] = { TLV_TYPE_FIXED, 2 },
Harald Welteba9adbb2011-03-06 19:01:16 +0100293 [OM2K_DEI_TF_SYNC_SRC] = { TLV_TYPE_TV },
Harald Welte1164dce2011-03-05 19:21:26 +0100294 [OM2K_DEI_TTA] = { TLV_TYPE_TV },
Harald Weltef6d6b212011-03-05 20:13:52 +0100295 [OM2K_DEI_CAPA_SIG] = { TLV_TYPE_FIXED, 2 },
Harald Weltee6e83832011-03-05 17:52:09 +0100296 [OM2K_DEI_NEGOT_REC1] = { TLV_TYPE_TLV },
297 [OM2K_DEI_NEGOT_REC2] = { TLV_TYPE_TLV },
Harald Welte1164dce2011-03-05 19:21:26 +0100298 [OM2K_DEI_ENCR_ALG] = { TLV_TYPE_TV },
299 [OM2K_DEI_INTERF_REJ_COMB] = { TLV_TYPE_TV },
Harald Weltee6e83832011-03-05 17:52:09 +0100300 [OM2K_DEI_FS_OFFSET] = { TLV_TYPE_FIXED, 5 },
Harald Weltef6d6b212011-03-05 20:13:52 +0100301 [OM2K_DEI_EXT_COND_MAP_2_EXT] = { TLV_TYPE_FIXED, 4 },
Harald Weltee6e83832011-03-05 17:52:09 +0100302 },
303};
304
Harald Welte9a311ec2011-02-12 12:33:06 +0100305static const struct value_string om2k_msgcode_vals[] = {
306 { 0x0000, "Abort SP Command" },
307 { 0x0002, "Abort SP Complete" },
308 { 0x0004, "Alarm Report ACK" },
309 { 0x0005, "Alarm Report NACK" },
310 { 0x0006, "Alarm Report" },
311 { 0x0008, "Alarm Status Request" },
312 { 0x000a, "Alarm Status Request Accept" },
313 { 0x000b, "Alarm Status Request Reject" },
314 { 0x000c, "Alarm Status Result ACK" },
315 { 0x000d, "Alarm Status Result NACK" },
316 { 0x000e, "Alarm Status Result" },
317 { 0x0010, "Calendar Time Response" },
318 { 0x0011, "Calendar Time Reject" },
319 { 0x0012, "Calendar Time Request" },
320 { 0x0014, "CON Configuration Request" },
321 { 0x0016, "CON Configuration Request Accept" },
322 { 0x0017, "CON Configuration Request Reject" },
323 { 0x0018, "CON Configuration Result ACK" },
324 { 0x0019, "CON Configuration Result NACK" },
325 { 0x001a, "CON Configuration Result" },
326 { 0x001c, "Connect Command" },
327 { 0x001e, "Connect Complete" },
Harald Welte3ede7232011-03-05 17:58:13 +0100328 { 0x001f, "Connect Reject" },
Harald Welte9a311ec2011-02-12 12:33:06 +0100329 { 0x0028, "Disable Request" },
330 { 0x002a, "Disable Request Accept" },
331 { 0x002b, "Disable Request Reject" },
332 { 0x002c, "Disable Result ACK" },
333 { 0x002d, "Disable Result NACK" },
334 { 0x002e, "Disable Result" },
335 { 0x0030, "Disconnect Command" },
336 { 0x0032, "Disconnect Complete" },
337 { 0x0033, "Disconnect Reject" },
338 { 0x0034, "Enable Request" },
339 { 0x0036, "Enable Request Accept" },
340 { 0x0037, "Enable Request Reject" },
341 { 0x0038, "Enable Result ACK" },
342 { 0x0039, "Enable Result NACK" },
343 { 0x003a, "Enable Result" },
344 { 0x003c, "Escape Downlink Normal" },
345 { 0x003d, "Escape Downlink NACK" },
346 { 0x003e, "Escape Uplink Normal" },
347 { 0x003f, "Escape Uplink NACK" },
348 { 0x0040, "Fault Report ACK" },
349 { 0x0041, "Fault Report NACK" },
350 { 0x0042, "Fault Report" },
351 { 0x0044, "File Package End Command" },
352 { 0x0046, "File Package End Result" },
353 { 0x0047, "File Package End Reject" },
354 { 0x0048, "File Relation Request" },
355 { 0x004a, "File Relation Response" },
356 { 0x004b, "File Relation Request Reject" },
357 { 0x004c, "File Segment Transfer" },
358 { 0x004e, "File Segment Transfer Complete" },
359 { 0x004f, "File Segment Transfer Reject" },
360 { 0x0050, "HW Information Request" },
361 { 0x0052, "HW Information Request Accept" },
362 { 0x0053, "HW Information Request Reject" },
363 { 0x0054, "HW Information Result ACK" },
364 { 0x0055, "HW Information Result NACK" },
365 { 0x0056, "HW Information Result" },
366 { 0x0060, "IS Configuration Request" },
367 { 0x0062, "IS Configuration Request Accept" },
368 { 0x0063, "IS Configuration Request Reject" },
369 { 0x0064, "IS Configuration Result ACK" },
370 { 0x0065, "IS Configuration Result NACK" },
371 { 0x0066, "IS Configuration Result" },
372 { 0x0068, "Load Data End" },
373 { 0x006a, "Load Data End Result" },
374 { 0x006b, "Load Data End Reject" },
375 { 0x006c, "Load Data Init" },
376 { 0x006e, "Load Data Init Accept" },
377 { 0x006f, "Load Data Init Reject" },
378 { 0x0070, "Loop Control Command" },
379 { 0x0072, "Loop Control Complete" },
380 { 0x0073, "Loop Control Reject" },
381 { 0x0074, "Operational Information" },
382 { 0x0076, "Operational Information Accept" },
383 { 0x0077, "Operational Information Reject" },
384 { 0x0078, "Reset Command" },
385 { 0x007a, "Reset Complete" },
386 { 0x007b, "Reset Reject" },
387 { 0x007c, "RX Configuration Request" },
388 { 0x007e, "RX Configuration Request Accept" },
389 { 0x007f, "RX Configuration Request Reject" },
390 { 0x0080, "RX Configuration Result ACK" },
391 { 0x0081, "RX Configuration Result NACK" },
392 { 0x0082, "RX Configuration Result" },
393 { 0x0084, "Start Request" },
394 { 0x0086, "Start Request Accept" },
395 { 0x0087, "Start Request Reject" },
396 { 0x0088, "Start Result ACK" },
397 { 0x0089, "Start Result NACK" },
398 { 0x008a, "Start Result" },
399 { 0x008c, "Status Request" },
400 { 0x008e, "Status Response" },
401 { 0x008f, "Status Reject" },
402 { 0x0094, "Test Request" },
403 { 0x0096, "Test Request Accept" },
404 { 0x0097, "Test Request Reject" },
405 { 0x0098, "Test Result ACK" },
406 { 0x0099, "Test Result NACK" },
407 { 0x009a, "Test Result" },
408 { 0x00a0, "TF Configuration Request" },
409 { 0x00a2, "TF Configuration Request Accept" },
410 { 0x00a3, "TF Configuration Request Reject" },
411 { 0x00a4, "TF Configuration Result ACK" },
412 { 0x00a5, "TF Configuration Result NACK" },
413 { 0x00a6, "TF Configuration Result" },
414 { 0x00a8, "TS Configuration Request" },
415 { 0x00aa, "TS Configuration Request Accept" },
416 { 0x00ab, "TS Configuration Request Reject" },
417 { 0x00ac, "TS Configuration Result ACK" },
418 { 0x00ad, "TS Configuration Result NACK" },
419 { 0x00ae, "TS Configuration Result" },
420 { 0x00b0, "TX Configuration Request" },
421 { 0x00b2, "TX Configuration Request Accept" },
422 { 0x00b3, "TX Configuration Request Reject" },
423 { 0x00b4, "TX Configuration Result ACK" },
424 { 0x00b5, "TX Configuration Result NACK" },
425 { 0x00b6, "TX Configuration Result" },
426 { 0x00bc, "DIP Alarm Report ACK" },
427 { 0x00bd, "DIP Alarm Report NACK" },
428 { 0x00be, "DIP Alarm Report" },
429 { 0x00c0, "DIP Alarm Status Request" },
430 { 0x00c2, "DIP Alarm Status Response" },
431 { 0x00c3, "DIP Alarm Status Reject" },
432 { 0x00c4, "DIP Quality Report I ACK" },
433 { 0x00c5, "DIP Quality Report I NACK" },
434 { 0x00c6, "DIP Quality Report I" },
435 { 0x00c8, "DIP Quality Report II ACK" },
436 { 0x00c9, "DIP Quality Report II NACK" },
437 { 0x00ca, "DIP Quality Report II" },
438 { 0x00dc, "DP Configuration Request" },
439 { 0x00de, "DP Configuration Request Accept" },
440 { 0x00df, "DP Configuration Request Reject" },
441 { 0x00e0, "DP Configuration Result ACK" },
442 { 0x00e1, "DP Configuration Result NACK" },
443 { 0x00e2, "DP Configuration Result" },
444 { 0x00e4, "Capabilities HW Info Report ACK" },
445 { 0x00e5, "Capabilities HW Info Report NACK" },
446 { 0x00e6, "Capabilities HW Info Report" },
447 { 0x00e8, "Capabilities Request" },
448 { 0x00ea, "Capabilities Request Accept" },
449 { 0x00eb, "Capabilities Request Reject" },
450 { 0x00ec, "Capabilities Result ACK" },
451 { 0x00ed, "Capabilities Result NACK" },
452 { 0x00ee, "Capabilities Result" },
453 { 0x00f0, "FM Configuration Request" },
454 { 0x00f2, "FM Configuration Request Accept" },
455 { 0x00f3, "FM Configuration Request Reject" },
456 { 0x00f4, "FM Configuration Result ACK" },
457 { 0x00f5, "FM Configuration Result NACK" },
458 { 0x00f6, "FM Configuration Result" },
459 { 0x00f8, "FM Report Request" },
460 { 0x00fa, "FM Report Response" },
461 { 0x00fb, "FM Report Reject" },
462 { 0x00fc, "FM Start Command" },
463 { 0x00fe, "FM Start Complete" },
464 { 0x00ff, "FM Start Reject" },
465 { 0x0100, "FM Stop Command" },
466 { 0x0102, "FM Stop Complete" },
467 { 0x0103, "FM Stop Reject" },
468 { 0x0104, "Negotiation Request ACK" },
469 { 0x0105, "Negotiation Request NACK" },
470 { 0x0106, "Negotiation Request" },
471 { 0x0108, "BTS Initiated Request ACK" },
472 { 0x0109, "BTS Initiated Request NACK" },
473 { 0x010a, "BTS Initiated Request" },
474 { 0x010c, "Radio Channels Release Command" },
475 { 0x010e, "Radio Channels Release Complete" },
476 { 0x010f, "Radio Channels Release Reject" },
477 { 0x0118, "Feature Control Command" },
478 { 0x011a, "Feature Control Complete" },
479 { 0x011b, "Feature Control Reject" },
480
481 { 0, NULL }
482};
483
484/* TS 12.21 Section 9.4: Attributes */
485static const struct value_string om2k_attr_vals[] = {
486 { 0x00, "Accordance indication" },
487 { 0x01, "Alarm Id" },
488 { 0x02, "Alarm Data" },
489 { 0x03, "Alarm Severity" },
490 { 0x04, "Alarm Status" },
491 { 0x05, "Alarm Status Type" },
492 { 0x06, "BCC" },
493 { 0x07, "BS_AG_BKS_RES" },
494 { 0x09, "BSIC" },
495 { 0x0a, "BA_PA_MFRMS" },
496 { 0x0b, "CBCH Indicator" },
497 { 0x0c, "CCCH Options" },
498 { 0x0d, "Calendar Time" },
499 { 0x0f, "Channel Combination" },
500 { 0x10, "CON Connection List" },
501 { 0x11, "Data End Indication" },
502 { 0x12, "DRX_DEV_MAX" },
503 { 0x13, "End List Number" },
504 { 0x14, "External Condition Map Class 1" },
505 { 0x15, "External Condition Map Class 2" },
506 { 0x16, "File Relation Indication" },
507 { 0x17, "File Revision" },
508 { 0x18, "File Segment Data" },
509 { 0x19, "File Segment Length" },
510 { 0x1a, "File Segment Sequence Number" },
511 { 0x1b, "File Size" },
512 { 0x1c, "Filling Marker" },
513 { 0x1d, "FN Offset" },
514 { 0x1e, "Frequency List" },
515 { 0x1f, "Frequency Specifier RX" },
516 { 0x20, "Frequency Specifier TX" },
517 { 0x21, "HSN" },
518 { 0x22, "ICM Indicator" },
519 { 0x23, "Internal Fault Map Class 1A" },
520 { 0x24, "Internal Fault Map Class 1B" },
521 { 0x25, "Internal Fault Map Class 2A" },
522 { 0x26, "Internal Fault Map Class 2A Extension" },
523 { 0x27, "IS Connection List" },
524 { 0x28, "List Number" },
525 { 0x29, "File Package State Indication" },
526 { 0x2a, "Local Access State" },
527 { 0x2b, "MAIO" },
528 { 0x2c, "MO State" },
529 { 0x2d, "Ny1" },
530 { 0x2e, "Operational Information" },
531 { 0x2f, "Power" },
532 { 0x30, "RU Position Data" },
533 { 0x31, "Protocol Error" },
534 { 0x32, "Reason Code" },
535 { 0x33, "Receiver Diversity" },
536 { 0x34, "Replacement Unit Map" },
537 { 0x35, "Result Code" },
538 { 0x36, "RU Revision Data" },
539 { 0x38, "T3105" },
540 { 0x39, "Test Loop Setting" },
541 { 0x3a, "TF Mode" },
542 { 0x3b, "TF Compensation Value" },
543 { 0x3c, "Time Slot Number" },
544 { 0x3d, "TSC" },
545 { 0x3e, "RU Logical Id" },
546 { 0x3f, "RU Serial Number Data" },
547 { 0x40, "BTS Version" },
548 { 0x41, "OML IWD Version" },
549 { 0x42, "RWL IWD Version" },
550 { 0x43, "OML Function Map 1" },
551 { 0x44, "OML Function Map 2" },
552 { 0x45, "RSL Function Map 1" },
553 { 0x46, "RSL Function Map 2" },
554 { 0x47, "Extended Range Indicator" },
555 { 0x48, "Request Indicators" },
556 { 0x49, "DIP Alarm Condition Map" },
557 { 0x4a, "ES Incoming" },
558 { 0x4b, "ES Outgoing" },
559 { 0x4e, "SES Incoming" },
560 { 0x4f, "SES Outgoing" },
561 { 0x50, "Replacement Unit Map Extension" },
562 { 0x52, "UAS Incoming" },
563 { 0x53, "UAS Outgoing" },
564 { 0x58, "DF Incoming" },
565 { 0x5a, "DF Outgoing" },
566 { 0x5c, "SF" },
567 { 0x60, "S Bits Setting" },
568 { 0x61, "CRC-4 Use Option" },
569 { 0x62, "T Parameter" },
570 { 0x63, "N Parameter" },
571 { 0x64, "N1 Parameter" },
572 { 0x65, "N3 Parameter" },
573 { 0x66, "N4 Parameter" },
574 { 0x67, "P Parameter" },
575 { 0x68, "Q Parameter" },
576 { 0x69, "BI_Q1" },
577 { 0x6a, "BI_Q2" },
578 { 0x74, "ICM Boundary Parameters" },
579 { 0x77, "AFT" },
580 { 0x78, "AFT RAI" },
581 { 0x79, "Link Supervision Control" },
582 { 0x7a, "Link Supervision Filtering Time" },
583 { 0x7b, "Call Supervision Time" },
584 { 0x7c, "Interval Length UAS Incoming" },
585 { 0x7d, "Interval Length UAS Outgoing" },
586 { 0x7e, "ICM Channel Rate" },
587 { 0x7f, "Attribute Identifier" },
588 { 0x80, "FM Frequency List" },
589 { 0x81, "FM Frequency Report" },
590 { 0x82, "FM Percentile" },
591 { 0x83, "FM Clear Indication" },
592 { 0x84, "HW Info Signature" },
593 { 0x85, "MO Record" },
594 { 0x86, "TF Synchronisation Source" },
595 { 0x87, "TTA" },
596 { 0x88, "End Segment Number" },
597 { 0x89, "Segment Number" },
598 { 0x8a, "Capabilities Signature" },
599 { 0x8c, "File Relation List" },
600 { 0x90, "Negotiation Record I" },
601 { 0x91, "Negotiation Record II" },
602 { 0x92, "Encryption Algorithm" },
603 { 0x94, "Interference Rejection Combining" },
604 { 0x95, "Dedication Information" },
605 { 0x97, "Feature Code" },
606 { 0x98, "FS Offset" },
607 { 0x99, "ESB Timeslot" },
608 { 0x9a, "Master TG Instance" },
609 { 0x9b, "Master TX Chain Delay" },
610 { 0x9c, "External Condition Class 2 Extension" },
611 { 0x9d, "TSs MO State" },
612 { 0, NULL }
613};
614
Harald Weltee1d5eca2011-02-12 14:42:59 +0100615const struct value_string om2k_mo_class_short_vals[] = {
Harald Welte9a311ec2011-02-12 12:33:06 +0100616 { 0x01, "TRXC" },
617 { 0x03, "TS" },
618 { 0x04, "TF" },
619 { 0x05, "IS" },
620 { 0x06, "CON" },
621 { 0x07, "DP" },
622 { 0x0a, "CF" },
623 { 0x0b, "TX" },
624 { 0x0c, "RX" },
625 { 0, NULL }
626};
627
628static struct msgb *om2k_msgb_alloc(void)
629{
630 return msgb_alloc_headroom(OM_ALLOC_SIZE, OM_HEADROOM_SIZE,
631 "OM2000");
632}
633
Harald Weltee6e83832011-03-05 17:52:09 +0100634static int abis_om2k_tlv_parse(struct tlv_parsed *tp, const u_int8_t *buf, int len)
635{
636 return tlv_parse(tp, &om2k_att_tlvdef, buf, len, 0, 0);
637}
638
Harald Weltee898ecc2011-03-06 19:26:11 +0100639static int abis_om2k_msg_tlv_parse(struct tlv_parsed *tp, struct abis_om2k_hdr *oh)
640{
641 return abis_om2k_tlv_parse(tp, oh->data, oh->om.length - 6);
642}
643
Harald Welted88a3872011-02-14 15:26:13 +0100644static char *om2k_mo_name(const struct abis_om2k_mo *mo)
645{
646 static char mo_buf[64];
647
648 memset(mo_buf, 0, sizeof(mo_buf));
649 snprintf(mo_buf, sizeof(mo_buf), "%s/%02x/%02x/%02x",
650 get_value_string(om2k_mo_class_short_vals, mo->class),
651 mo->bts, mo->assoc_so, mo->inst);
652 return mo_buf;
653}
654
Harald Weltebc867d92011-02-12 13:09:38 +0100655static int abis_om2k_sendmsg(struct gsm_bts *bts, struct msgb *msg)
656{
Harald Welted88a3872011-02-14 15:26:13 +0100657 struct abis_om2k_hdr *o2h;
658 int to_trx_oml;
Harald Weltebc867d92011-02-12 13:09:38 +0100659
Harald Welted88a3872011-02-14 15:26:13 +0100660 msg->l2h = msg->data;
661 o2h = (struct abis_om2k_hdr *) msg->l2h;
662
Harald Welte1164dce2011-03-05 19:21:26 +0100663 /* Compute the length in the OML header */
664 o2h->om.length = 6 + msgb_l2len(msg)-sizeof(*o2h);
665
Harald Welted88a3872011-02-14 15:26:13 +0100666 switch (o2h->mo.class) {
667 case OM2K_MO_CLS_TRXC:
668 case OM2K_MO_CLS_TX:
669 case OM2K_MO_CLS_RX:
Harald Welted88a3872011-02-14 15:26:13 +0100670 /* Route through per-TRX OML Link to the appropriate TRX */
671 to_trx_oml = 1;
672 msg->trx = gsm_bts_trx_by_nr(bts, o2h->mo.inst);
673 if (!msg->trx) {
674 LOGP(DNM, LOGL_ERROR, "MO=%s Tx Dropping msg to "
675 "non-existing TRX\n", om2k_mo_name(&o2h->mo));
676 return -ENODEV;
677 }
678 break;
Harald Welte8aeac192011-03-05 20:15:09 +0100679 case OM2K_MO_CLS_TS:
680 /* Route through per-TRX OML Link to the appropriate TRX */
681 to_trx_oml = 1;
682 msg->trx = gsm_bts_trx_by_nr(bts, o2h->mo.assoc_so);
683 if (!msg->trx) {
684 LOGP(DNM, LOGL_ERROR, "MO=%s Tx Dropping msg to "
685 "non-existing TRX\n", om2k_mo_name(&o2h->mo));
686 return -ENODEV;
687 }
688 break;
Harald Welted88a3872011-02-14 15:26:13 +0100689 default:
690 /* Route through the IXU/DXU OML Link */
691 msg->trx = bts->c0;
692 to_trx_oml = 0;
693 break;
694 }
695
696 return _abis_nm_sendmsg(msg, to_trx_oml);
Harald Weltebc867d92011-02-12 13:09:38 +0100697}
698
Harald Welte9a311ec2011-02-12 12:33:06 +0100699static void fill_om2k_hdr(struct abis_om2k_hdr *o2h, const struct abis_om2k_mo *mo,
Harald Welte1164dce2011-03-05 19:21:26 +0100700 uint16_t msg_type)
Harald Welte9a311ec2011-02-12 12:33:06 +0100701{
702 o2h->om.mdisc = ABIS_OM_MDISC_FOM;
703 o2h->om.placement = ABIS_OM_PLACEMENT_ONLY;
704 o2h->om.sequence = 0;
Harald Welte1164dce2011-03-05 19:21:26 +0100705 /* We fill o2h->om.length later during om2k_sendmsg() */
Harald Welte9a311ec2011-02-12 12:33:06 +0100706 o2h->msg_type = htons(msg_type);
707 memcpy(&o2h->mo, mo, sizeof(o2h->mo));
708}
709
Harald Welte73541072011-02-12 13:44:14 +0100710const struct abis_om2k_mo om2k_mo_cf = { OM2K_MO_CLS_CF, 0, 0xFF, 0 };
Harald Welte8bcb1a02011-02-12 20:23:40 +0100711const struct abis_om2k_mo om2k_mo_is = { OM2K_MO_CLS_IS, 0, 0xFF, 0 };
Harald Weltefdb71942011-02-14 15:31:43 +0100712const struct abis_om2k_mo om2k_mo_con = { OM2K_MO_CLS_CON, 0, 0xFF, 0 };
Harald Weltef9cf9612011-03-05 14:36:47 +0100713const struct abis_om2k_mo om2k_mo_tf = { OM2K_MO_CLS_TF, 0, 0xFF, 0 };
Harald Welte9a311ec2011-02-12 12:33:06 +0100714
715static int abis_om2k_cal_time_resp(struct gsm_bts *bts)
716{
717 struct msgb *msg = om2k_msgb_alloc();
718 struct abis_om2k_hdr *o2k;
719 time_t tm_t;
720 struct tm *tm;
721
722 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
Harald Welte1164dce2011-03-05 19:21:26 +0100723 fill_om2k_hdr(o2k, &om2k_mo_cf, OM2K_MSGT_CAL_TIME_RESP);
Harald Welte9a311ec2011-02-12 12:33:06 +0100724
725 tm_t = time(NULL);
726 tm = localtime(&tm_t);
727
728 msgb_put_u8(msg, OM2K_DEI_CAL_TIME);
729 msgb_put_u8(msg, tm->tm_year % 100);
730 msgb_put_u8(msg, tm->tm_mon + 1);
731 msgb_put_u8(msg, tm->tm_mday);
732 msgb_put_u8(msg, tm->tm_hour);
733 msgb_put_u8(msg, tm->tm_min);
734 msgb_put_u8(msg, tm->tm_sec);
735
Harald Weltebc867d92011-02-12 13:09:38 +0100736 return abis_om2k_sendmsg(bts, msg);
Harald Welte9a311ec2011-02-12 12:33:06 +0100737}
738
Harald Welte6fec79d2011-02-12 14:57:17 +0100739static int abis_om2k_tx_simple(struct gsm_bts *bts, const struct abis_om2k_mo *mo,
Harald Welte9a311ec2011-02-12 12:33:06 +0100740 uint8_t msg_type)
741{
742 struct msgb *msg = om2k_msgb_alloc();
743 struct abis_om2k_hdr *o2k;
744
745 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
Harald Welte1164dce2011-03-05 19:21:26 +0100746 fill_om2k_hdr(o2k, mo, msg_type);
Harald Welte9a311ec2011-02-12 12:33:06 +0100747
Harald Welte73541072011-02-12 13:44:14 +0100748 DEBUGP(DNM, "Tx MO=%s %s\n", om2k_mo_name(mo),
749 get_value_string(om2k_msgcode_vals, msg_type));
750
Harald Weltebc867d92011-02-12 13:09:38 +0100751 return abis_om2k_sendmsg(bts, msg);
Harald Welte9a311ec2011-02-12 12:33:06 +0100752}
753
Harald Welte6fec79d2011-02-12 14:57:17 +0100754int abis_om2k_tx_reset_cmd(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
Harald Welte73541072011-02-12 13:44:14 +0100755{
756 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_RESET_CMD);
757}
758
Harald Welte6fec79d2011-02-12 14:57:17 +0100759int abis_om2k_tx_start_req(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
Harald Welte73541072011-02-12 13:44:14 +0100760{
761 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_START_REQ);
762}
763
Harald Welte6fec79d2011-02-12 14:57:17 +0100764int abis_om2k_tx_status_req(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
Harald Weltee1d5eca2011-02-12 14:42:59 +0100765{
766 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_STATUS_REQ);
767}
768
Harald Welte6fec79d2011-02-12 14:57:17 +0100769int abis_om2k_tx_connect_cmd(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
770{
771 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_CONNECT_CMD);
772}
773
774int abis_om2k_tx_disconnect_cmd(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
775{
776 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_DISCONNECT_CMD);
777}
778
Harald Welte8024d8f2011-02-12 15:07:30 +0100779int abis_om2k_tx_test_req(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
780{
781 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_TEST_REQ);
782}
783
Harald Welte0741ffe2011-02-12 18:48:53 +0100784int abis_om2k_tx_enable_req(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
785{
786 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_ENABLE_REQ);
787}
788
789int abis_om2k_tx_disable_req(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
790{
791 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_DISABLE_REQ);
792}
793
Harald Welte6fec79d2011-02-12 14:57:17 +0100794int abis_om2k_tx_op_info(struct gsm_bts *bts, const struct abis_om2k_mo *mo,
795 uint8_t operational)
Harald Welte9a311ec2011-02-12 12:33:06 +0100796{
797 struct msgb *msg = om2k_msgb_alloc();
798 struct abis_om2k_hdr *o2k;
799
800 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
Harald Welte1164dce2011-03-05 19:21:26 +0100801 fill_om2k_hdr(o2k, mo, OM2K_MSGT_OP_INFO);
Harald Welte9a311ec2011-02-12 12:33:06 +0100802
803 msgb_tv_put(msg, OM2K_DEI_OP_INFO, operational);
804
Harald Welte73541072011-02-12 13:44:14 +0100805 DEBUGP(DNM, "Tx MO=%s %s\n", om2k_mo_name(mo),
806 get_value_string(om2k_msgcode_vals, OM2K_MSGT_OP_INFO));
807
Harald Weltebc867d92011-02-12 13:09:38 +0100808 return abis_om2k_sendmsg(bts, msg);
Harald Welte9a311ec2011-02-12 12:33:06 +0100809}
810
Harald Welte8bcb1a02011-02-12 20:23:40 +0100811int abis_om2k_tx_is_conf_req(struct gsm_bts *bts, struct om2k_is_conn_grp *cg,
812 unsigned int num_cg )
813{
814 struct msgb *msg = om2k_msgb_alloc();
815 struct abis_om2k_hdr *o2k;
816
817 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
Harald Welte1164dce2011-03-05 19:21:26 +0100818 fill_om2k_hdr(o2k, &om2k_mo_is, OM2K_MSGT_IS_CONF_REQ);
Harald Welte8bcb1a02011-02-12 20:23:40 +0100819
820 msgb_tv_put(msg, OM2K_DEI_LIST_NR, 1);
821 msgb_tv_put(msg, OM2K_DEI_END_LIST_NR, 1);
822
823 msgb_tlv_put(msg, OM2K_DEI_IS_CONN_LIST,
824 num_cg * sizeof(*cg), (uint8_t *)cg);
825
826 return abis_om2k_sendmsg(bts, msg);
827}
828
Harald Weltefdb71942011-02-14 15:31:43 +0100829int abis_om2k_tx_con_conf_req(struct gsm_bts *bts, uint8_t *data,
830 unsigned int len)
831{
832 struct msgb *msg = om2k_msgb_alloc();
833 struct abis_om2k_hdr *o2k;
834
835 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
Harald Welte1164dce2011-03-05 19:21:26 +0100836 fill_om2k_hdr(o2k, &om2k_mo_con, OM2K_MSGT_CON_CONF_REQ);
Harald Weltefdb71942011-02-14 15:31:43 +0100837
838 msgb_tv_put(msg, OM2K_DEI_LIST_NR, 1);
839 msgb_tv_put(msg, OM2K_DEI_END_LIST_NR, 1);
840
841 msgb_tlv_put(msg, OM2K_DEI_CON_CONN_LIST, len, data);
842
843 return abis_om2k_sendmsg(bts, msg);
844}
845
Harald Weltea0ce3492011-03-05 14:13:14 +0100846static void om2k_trx_to_mo(struct abis_om2k_mo *mo,
847 const struct gsm_bts_trx *trx,
848 enum abis_om2k_mo_cls cls)
849{
850 mo->class = cls;
851 mo->bts = 0;
852 mo->inst = trx->nr;
Harald Welte53492c82011-03-05 16:21:01 +0100853 mo->assoc_so = 255;
Harald Weltea0ce3492011-03-05 14:13:14 +0100854}
855
856static void om2k_ts_to_mo(struct abis_om2k_mo *mo,
857 const struct gsm_bts_trx_ts *ts)
858{
859 mo->class = OM2K_MO_CLS_TS;
860 mo->bts = 0;
861 mo->inst = ts->nr;
862 mo->assoc_so = ts->trx->nr;
863}
864
865/* Configure a Receiver MO */
866int abis_om2k_tx_rx_conf_req(struct gsm_bts_trx *trx)
867{
868 struct msgb *msg = om2k_msgb_alloc();
869 struct abis_om2k_hdr *o2k;
870 struct abis_om2k_mo mo;
871
872 om2k_trx_to_mo(&mo, trx, OM2K_MO_CLS_RX);
873
874 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
Harald Welte1164dce2011-03-05 19:21:26 +0100875 fill_om2k_hdr(o2k, &mo, OM2K_MSGT_RX_CONF_REQ);
Harald Weltea0ce3492011-03-05 14:13:14 +0100876
877 msgb_tv16_put(msg, OM2K_DEI_FREQ_SPEC_RX, trx->arfcn);
Harald Welte1edc2b42011-03-06 19:01:54 +0100878 msgb_tv_put(msg, OM2K_DEI_RX_DIVERSITY, 0x02); /* A */
Harald Weltea0ce3492011-03-05 14:13:14 +0100879
880 return abis_om2k_sendmsg(trx->bts, msg);
881}
882
883/* Configure a Transmitter MO */
884int abis_om2k_tx_tx_conf_req(struct gsm_bts_trx *trx)
885{
886 struct msgb *msg = om2k_msgb_alloc();
887 struct abis_om2k_hdr *o2k;
888 struct abis_om2k_mo mo;
889
890 om2k_trx_to_mo(&mo, trx, OM2K_MO_CLS_TX);
891
892 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
Harald Welte1164dce2011-03-05 19:21:26 +0100893 fill_om2k_hdr(o2k, &mo, OM2K_MSGT_TX_CONF_REQ);
Harald Weltea0ce3492011-03-05 14:13:14 +0100894
895 msgb_tv16_put(msg, OM2K_DEI_FREQ_SPEC_TX, trx->arfcn);
896 msgb_tv_put(msg, OM2K_DEI_POWER, trx->nominal_power-trx->max_power_red);
897 msgb_tv_put(msg, OM2K_DEI_FILLING_MARKER, 0); /* Filling enabled */
898 msgb_tv_put(msg, OM2K_DEI_BCC, trx->bts->bsic & 0x7);
899 /* Dedication Information is optional */
900
901 return abis_om2k_sendmsg(trx->bts, msg);
902}
903
Harald Weltef9cf9612011-03-05 14:36:47 +0100904enum abis_om2k_tf_mode {
905 OM2K_TF_MODE_MASTER = 0x00,
906 OM2K_TF_MODE_STANDALONE = 0x01,
907 OM2K_TF_MODE_SLAVE = 0x02,
908 OM2K_TF_MODE_UNDEFINED = 0xff,
909};
910
911static const uint8_t fs_offset_undef[5] = { 0xff, 0xff, 0xff, 0xff, 0xff };
912
913int abis_om2k_tx_tf_conf_req(struct gsm_bts *bts)
914{
915 struct msgb *msg = om2k_msgb_alloc();
916 struct abis_om2k_hdr *o2k;
917
918 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
Harald Welte1164dce2011-03-05 19:21:26 +0100919 fill_om2k_hdr(o2k, &om2k_mo_tf, OM2K_MSGT_TF_CONF_REQ);
Harald Weltef9cf9612011-03-05 14:36:47 +0100920
921 msgb_tv_put(msg, OM2K_DEI_TF_MODE, OM2K_TF_MODE_STANDALONE);
Harald Welteba9adbb2011-03-06 19:01:16 +0100922 msgb_tv_put(msg, OM2K_DEI_TF_SYNC_SRC, 0x00);
Harald Weltef9cf9612011-03-05 14:36:47 +0100923 msgb_tv_fixed_put(msg, OM2K_DEI_FS_OFFSET,
924 sizeof(fs_offset_undef), fs_offset_undef);
925
926 return abis_om2k_sendmsg(bts, msg);
927}
928
Harald Weltea0ce3492011-03-05 14:13:14 +0100929static uint8_t pchan2comb(enum gsm_phys_chan_config pchan)
930{
931 switch (pchan) {
932 case GSM_PCHAN_CCCH:
933 return 4;
934 case GSM_PCHAN_CCCH_SDCCH4:
935 return 5;
936 case GSM_PCHAN_SDCCH8_SACCH8C:
937 return 3;
938 case GSM_PCHAN_TCH_F:
939 case GSM_PCHAN_TCH_H:
940 case GSM_PCHAN_PDCH:
941 case GSM_PCHAN_TCH_F_PDCH:
942 return 8;
943 default:
944 return 0;
945 }
946}
947
Harald Welte5748c202011-03-05 17:30:07 +0100948static int put_freq_list(uint8_t *buf, uint16_t arfcn)
949{
950 buf[0] = 0x00; /* TX/RX address */
951 buf[1] = (arfcn >> 8);
952 buf[2] = (arfcn & 0xff);
953
954 return 3;
955}
956
Harald Weltea0ce3492011-03-05 14:13:14 +0100957/* Compute a frequency list in OM2000 fomrmat */
958static int om2k_gen_freq_list(uint8_t *list, struct gsm_bts_trx_ts *ts)
959{
960 uint8_t *cur = list;
Harald Weltee6e83832011-03-05 17:52:09 +0100961 int len;
Harald Weltea0ce3492011-03-05 14:13:14 +0100962
963 if (ts->hopping.enabled) {
964 unsigned int i;
965 for (i = 0; i < ts->hopping.arfcns.data_len*8; i++) {
Harald Welte5748c202011-03-05 17:30:07 +0100966 if (bitvec_get_bit_pos(&ts->hopping.arfcns, i))
967 cur += put_freq_list(cur, i);
Harald Weltea0ce3492011-03-05 14:13:14 +0100968 }
Harald Welte5748c202011-03-05 17:30:07 +0100969 } else
970 cur += put_freq_list(cur, ts->trx->arfcn);
971
Harald Weltee6e83832011-03-05 17:52:09 +0100972 len = cur - list;
973
974 return len;
Harald Weltea0ce3492011-03-05 14:13:14 +0100975}
976
Harald Welte75755c52011-03-05 20:38:35 +0100977const uint8_t icm_bound_params[] = { 0x02, 0x06, 0x0c, 0x16, 0x06 };
978
Harald Weltea0ce3492011-03-05 14:13:14 +0100979int abis_om2k_tx_ts_conf_req(struct gsm_bts_trx_ts *ts)
980{
981 struct msgb *msg = om2k_msgb_alloc();
982 struct abis_om2k_hdr *o2k;
983 struct abis_om2k_mo mo;
984 uint8_t freq_list[64*3]; /* BA max size: 64 ARFCN */
985 int freq_list_len;
986
987 om2k_ts_to_mo(&mo, ts);
988
Harald Welte5748c202011-03-05 17:30:07 +0100989 memset(freq_list, 0, sizeof(freq_list));
Harald Weltea0ce3492011-03-05 14:13:14 +0100990 freq_list_len = om2k_gen_freq_list(freq_list, ts);
991 if (freq_list_len < 0)
992 return freq_list_len;
993
994 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
Harald Welte1164dce2011-03-05 19:21:26 +0100995 fill_om2k_hdr(o2k, &mo, OM2K_MSGT_TS_CONF_REQ);
Harald Weltea0ce3492011-03-05 14:13:14 +0100996
997 msgb_tv_put(msg, OM2K_DEI_COMBINATION, pchan2comb(ts->pchan));
998 msgb_tv_put(msg, OM2K_DEI_TS_NR, ts->nr);
999 msgb_tlv_put(msg, OM2K_DEI_FREQ_LIST, freq_list_len, freq_list);
1000 msgb_tv_put(msg, OM2K_DEI_HSN, ts->hopping.hsn);
1001 msgb_tv_put(msg, OM2K_DEI_MAIO, ts->hopping.maio);
1002 msgb_tv_put(msg, OM2K_DEI_BSIC, ts->trx->bts->bsic);
Harald Welte1edc2b42011-03-06 19:01:54 +01001003 msgb_tv_put(msg, OM2K_DEI_RX_DIVERSITY, 0x02); /* A */
Harald Weltea0ce3492011-03-05 14:13:14 +01001004 msgb_tv16_put(msg, OM2K_DEI_FN_OFFSET, 0);
1005 msgb_tv_put(msg, OM2K_DEI_EXT_RANGE, 0); /* Off */
1006 /* Optional: Interference Rejection Combining */
Harald Welte1164dce2011-03-05 19:21:26 +01001007 msgb_tv_put(msg, OM2K_DEI_INTERF_REJ_COMB, 0x00);
1008 switch (ts->pchan) {
1009 case GSM_PCHAN_CCCH:
Harald Welte1164dce2011-03-05 19:21:26 +01001010 msgb_tv_put(msg, OM2K_DEI_BA_PA_MFRMS, 0x06);
1011 msgb_tv_put(msg, OM2K_DEI_BS_AG_BKS_RES, 0x01);
1012 msgb_tv_put(msg, OM2K_DEI_DRX_DEV_MAX, 0x05);
1013 /* Repeat Paging/IMM.ASS: True, Allow Paging Type 3: Yes, Page for 5 seconds (default) */
1014 msgb_tv_put(msg, OM2K_DEI_CCCH_OPTIONS, 0x01);
1015 break;
Harald Welte75755c52011-03-05 20:38:35 +01001016 case GSM_PCHAN_CCCH_SDCCH4:
1017 msgb_tv_put(msg, OM2K_DEI_T3105, 0x04);
1018 msgb_tv_put(msg, OM2K_DEI_NY1, 35);
1019 msgb_tv_put(msg, OM2K_DEI_BA_PA_MFRMS, 0x06);
1020 msgb_tv_put(msg, OM2K_DEI_CBCH_INDICATOR, 0);
1021 msgb_tv_put(msg, OM2K_DEI_TSC, ts->trx->bts->tsc);
1022 msgb_tv_put(msg, OM2K_DEI_BS_AG_BKS_RES, 0x01);
1023 msgb_tv_put(msg, OM2K_DEI_ICM_INDICATOR, 0);
1024 msgb_tv_put(msg, OM2K_DEI_DRX_DEV_MAX, 0x05);
1025 /* Repeat Paging/IMM.ASS: True, Allow Paging Type 3: Yes, Page for 5 seconds (default) */
1026 msgb_tv_put(msg, OM2K_DEI_CCCH_OPTIONS, 0x01);
1027 msgb_tv_fixed_put(msg, OM2K_DEI_ICM_BOUND_PARAMS,
1028 sizeof(icm_bound_params), icm_bound_params);
1029 break;
Harald Welte1164dce2011-03-05 19:21:26 +01001030 case GSM_PCHAN_SDCCH8_SACCH8C:
1031 msgb_tv_put(msg, OM2K_DEI_T3105, 0x04);
1032 msgb_tv_put(msg, OM2K_DEI_NY1, 35);
1033 msgb_tv_put(msg, OM2K_DEI_CBCH_INDICATOR, 0);
1034 msgb_tv_put(msg, OM2K_DEI_TSC, ts->trx->bts->tsc);
1035 /* Disable RF RESOURCE INDICATION on idle channels */
1036 msgb_tv_put(msg, OM2K_DEI_ICM_INDICATOR, 0);
Harald Welte75755c52011-03-05 20:38:35 +01001037 msgb_tv_fixed_put(msg, OM2K_DEI_ICM_BOUND_PARAMS,
1038 sizeof(icm_bound_params), icm_bound_params);
Harald Welte1164dce2011-03-05 19:21:26 +01001039 break;
1040 default:
1041 msgb_tv_put(msg, OM2K_DEI_T3105, 0x04);
1042 msgb_tv_put(msg, OM2K_DEI_NY1, 35);
Harald Welte1164dce2011-03-05 19:21:26 +01001043 msgb_tv_put(msg, OM2K_DEI_TSC, ts->trx->bts->tsc);
1044 /* Disable RF RESOURCE INDICATION on idle channels */
1045 msgb_tv_put(msg, OM2K_DEI_ICM_INDICATOR, 0);
Harald Welte75755c52011-03-05 20:38:35 +01001046 msgb_tv_fixed_put(msg, OM2K_DEI_ICM_BOUND_PARAMS,
1047 sizeof(icm_bound_params), icm_bound_params);
Harald Welte1164dce2011-03-05 19:21:26 +01001048 msgb_tv_put(msg, OM2K_DEI_TTA, 10); /* Timer for Time Alignment */
Harald Welte75755c52011-03-05 20:38:35 +01001049 if (ts->pchan == GSM_PCHAN_TCH_H)
1050 msgb_tv_put(msg, OM2K_DEI_ICM_CHAN_RATE, 1); /* TCH/H */
1051 else
1052 msgb_tv_put(msg, OM2K_DEI_ICM_CHAN_RATE, 0); /* TCH/F */
Harald Welte1164dce2011-03-05 19:21:26 +01001053 msgb_tv_put(msg, OM2K_DEI_LSC, 1); /* enabled */
Harald Welte1edc2b42011-03-06 19:01:54 +01001054 msgb_tv_put(msg, OM2K_DEI_LSC_FILT_TIME, 10); /* units of 100ms */
Harald Welte1164dce2011-03-05 19:21:26 +01001055 msgb_tv_put(msg, OM2K_DEI_CALL_SUPV_TIME, 8);
1056 msgb_tv_put(msg, OM2K_DEI_ENCR_ALG, 0x00);
Harald Welte1164dce2011-03-05 19:21:26 +01001057 break;
1058 }
Harald Weltea0ce3492011-03-05 14:13:14 +01001059
1060 return abis_om2k_sendmsg(ts->trx->bts, msg);
1061}
Harald Weltefdb71942011-02-14 15:31:43 +01001062
Harald Welte6fec79d2011-02-12 14:57:17 +01001063static int abis_om2k_tx_negot_req_ack(struct gsm_bts *bts, const struct abis_om2k_mo *mo,
Harald Welte73541072011-02-12 13:44:14 +01001064 uint8_t *data, unsigned int len)
1065{
1066 struct msgb *msg = om2k_msgb_alloc();
1067 struct abis_om2k_hdr *o2k;
1068
1069 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
Harald Welte1164dce2011-03-05 19:21:26 +01001070 fill_om2k_hdr(o2k, mo, OM2K_MSGT_NEGOT_REQ_ACK);
Harald Welte73541072011-02-12 13:44:14 +01001071
1072 msgb_tlv_put(msg, OM2K_DEI_NEGOT_REC2, len, data);
1073
1074 DEBUGP(DNM, "Tx MO=%s %s\n", om2k_mo_name(mo),
1075 get_value_string(om2k_msgcode_vals, OM2K_MSGT_NEGOT_REQ_ACK));
1076
1077 return abis_om2k_sendmsg(bts, msg);
1078}
Harald Welte9a311ec2011-02-12 12:33:06 +01001079
Harald Welte563d3162011-02-12 18:11:16 +01001080struct iwd_version {
1081 uint8_t gen_char[3+1];
1082 uint8_t rev_char[3+1];
1083};
1084
1085struct iwd_type {
1086 uint8_t num_vers;
1087 struct iwd_version v[8];
1088};
1089
Harald Welte9a311ec2011-02-12 12:33:06 +01001090static int om2k_rx_negot_req(struct msgb *msg)
1091{
1092 struct abis_om2k_hdr *o2h = msgb_l2(msg);
Harald Welte563d3162011-02-12 18:11:16 +01001093 struct iwd_type iwd_types[16];
1094 uint8_t num_iwd_types = o2h->data[2];
1095 uint8_t *cur = o2h->data+3;
1096 unsigned int i, v;
Harald Welte9a311ec2011-02-12 12:33:06 +01001097
Harald Welte563d3162011-02-12 18:11:16 +01001098 uint8_t out_buf[1024];
1099 uint8_t *out_cur = out_buf+1;
1100 uint8_t out_num_types = 0;
1101
1102 memset(iwd_types, 0, sizeof(iwd_types));
1103
1104 /* Parse the RBS-supported IWD versions into iwd_types array */
1105 for (i = 0; i < num_iwd_types; i++) {
1106 uint8_t num_versions = *cur++;
1107 uint8_t iwd_type = *cur++;
1108
1109 iwd_types[iwd_type].num_vers = num_versions;
1110
1111 for (v = 0; v < num_versions; v++) {
1112 struct iwd_version *iwd_v = &iwd_types[iwd_type].v[v];
1113
1114 memcpy(iwd_v->gen_char, cur, 3);
Harald Welte56ee6b82011-02-12 18:13:37 +01001115 cur += 3;
1116 memcpy(iwd_v->rev_char, cur, 3);
1117 cur += 3;
1118
Harald Welte563d3162011-02-12 18:11:16 +01001119 DEBUGP(DNM, "\tIWD Type %u Gen %s Rev %s\n", iwd_type,
1120 iwd_v->gen_char, iwd_v->rev_char);
1121 }
1122 }
1123
1124 /* Select the last version for each IWD type */
1125 for (i = 0; i < ARRAY_SIZE(iwd_types); i++) {
1126 struct iwd_type *type = &iwd_types[i];
1127 struct iwd_version *last_v;
1128
1129 if (type->num_vers == 0)
1130 continue;
1131
1132 out_num_types++;
1133
1134 last_v = &type->v[type->num_vers-1];
1135
1136 *out_cur++ = i;
1137 memcpy(out_cur, last_v->gen_char, 3);
1138 out_cur += 3;
1139 memcpy(out_cur, last_v->rev_char, 3);
1140 out_cur += 3;
1141 }
1142
1143 out_buf[0] = out_num_types;
1144
1145 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 +01001146}
1147
1148static int om2k_rx_start_res(struct msgb *msg)
1149{
1150 struct abis_om2k_hdr *o2h = msgb_l2(msg);
1151 int rc;
1152
1153 rc = abis_om2k_tx_simple(msg->trx->bts, &o2h->mo, OM2K_MSGT_START_RES_ACK);
1154 rc = abis_om2k_tx_op_info(msg->trx->bts, &o2h->mo, 1);
1155
1156 return rc;
1157}
1158
Harald Welte0741ffe2011-02-12 18:48:53 +01001159static int om2k_rx_op_info_ack(struct msgb *msg)
Harald Welte9a311ec2011-02-12 12:33:06 +01001160{
1161 struct abis_om2k_hdr *o2h = msgb_l2(msg);
Harald Welte9a311ec2011-02-12 12:33:06 +01001162
Harald Welte0741ffe2011-02-12 18:48:53 +01001163 /* FIXME: update Operational state in our structures */
Harald Welte9a311ec2011-02-12 12:33:06 +01001164
Harald Welte0741ffe2011-02-12 18:48:53 +01001165 return 0;
Harald Welte9a311ec2011-02-12 12:33:06 +01001166}
1167
Harald Weltee6e83832011-03-05 17:52:09 +01001168const struct value_string om2k_result_strings[] = {
1169 { 0x02, "Wrong state or out of sequence" },
1170 { 0x03, "File error" },
1171 { 0x04, "Fault, unspecified" },
1172 { 0x05, "Tuning fault" },
1173 { 0x06, "Protocol error" },
1174 { 0x07, "MO not connected" },
1175 { 0x08, "Parameter error" },
1176 { 0x09, "Optional function not supported" },
1177 { 0x0a, "Local access state LOCALLY DISCONNECTED" },
1178 { 0, NULL }
1179};
1180
Harald Weltee898ecc2011-03-06 19:26:11 +01001181const struct value_string om2k_accordance_strings[] = {
1182 { 0x00, "Data according to request" },
1183 { 0x01, "Data not according to request" },
1184 { 0x02, "Inconsistent MO data" },
1185 { 0x03, "Capability constraint violation" },
1186 { 0, NULL }
1187};
1188
1189const struct value_string om2k_mostate_vals[] = {
1190 { 0x00, "RESET" },
1191 { 0x01, "STARTED" },
1192 { 0x02, "ENABLED" },
1193 { 0x03, "DISABLED" },
1194 { 0, NULL }
1195};
1196
Harald Weltee6e83832011-03-05 17:52:09 +01001197static int om2k_rx_nack(struct msgb *msg)
1198{
1199 struct abis_om2k_hdr *o2h = msgb_l2(msg);
1200 uint16_t msg_type = ntohs(o2h->msg_type);
1201 struct tlv_parsed tp;
1202
1203 LOGP(DNM, LOGL_ERROR, "Rx MO=%s %s", om2k_mo_name(&o2h->mo),
1204 get_value_string(om2k_msgcode_vals, msg_type));
1205
Harald Weltee898ecc2011-03-06 19:26:11 +01001206 abis_om2k_msg_tlv_parse(&tp, o2h);
Harald Weltee6e83832011-03-05 17:52:09 +01001207 if (TLVP_PRESENT(&tp, OM2K_DEI_REASON_CODE))
1208 LOGPC(DNM, LOGL_ERROR, ", Reason 0x%02x",
1209 *TLVP_VAL(&tp, OM2K_DEI_REASON_CODE));
1210
1211 if (TLVP_PRESENT(&tp, OM2K_DEI_RESULT_CODE))
1212 LOGPC(DNM, LOGL_ERROR, ", Result %s",
1213 get_value_string(om2k_result_strings,
1214 *TLVP_VAL(&tp, OM2K_DEI_RESULT_CODE)));
1215 LOGPC(DNM, LOGL_ERROR, "\n");
1216
1217 return 0;
1218}
1219
Harald Weltee898ecc2011-03-06 19:26:11 +01001220/* Process a Configuration Result message */
1221static int process_conf_res(struct gsm_bts *bts, struct msgb *msg)
1222{
1223 struct abis_om2k_hdr *o2h = msgb_l2(msg);
1224 uint16_t msg_type = ntohs(o2h->msg_type);
1225 struct tlv_parsed tp;
1226 uint8_t acc;
1227 unsigned int log_level;
1228 int ret;
1229
1230 abis_om2k_msg_tlv_parse(&tp, o2h);
1231 if (!TLVP_PRESENT(&tp, OM2K_DEI_ACCORDANCE_IND))
1232 return -EIO;
1233
1234 acc = *TLVP_VAL(&tp, OM2K_DEI_ACCORDANCE_IND);
1235
1236 switch (acc) {
1237 case 0:
1238 log_level = LOGL_DEBUG;
1239 ret = 0;
1240 break;
1241 default:
1242 log_level = LOGL_ERROR;
1243 ret = -EINVAL;
1244 break;
1245 }
1246
1247 LOGP(DNM, log_level, "Rx MO=%s %s, Accordance: %s\n",
1248 om2k_mo_name(&o2h->mo),
1249 get_value_string(om2k_msgcode_vals, msg_type),
1250 get_value_string(om2k_accordance_strings, acc));
1251
1252 return ret;
1253}
1254
1255static int process_mo_state(struct gsm_bts *bts, struct msgb *msg)
1256{
1257 struct abis_om2k_hdr *o2h = msgb_l2(msg);
1258 uint16_t msg_type = ntohs(o2h->msg_type);
1259 struct tlv_parsed tp;
1260 uint8_t mo_state;
1261
1262 abis_om2k_msg_tlv_parse(&tp, o2h);
1263 if (!TLVP_PRESENT(&tp, OM2K_DEI_MO_STATE))
1264 return -EIO;
1265 mo_state = *TLVP_VAL(&tp, OM2K_DEI_MO_STATE);
1266
1267 LOGP(DNM, LOGL_DEBUG, "Rx MO=%s %s, MO State: %s\n",
1268 om2k_mo_name(&o2h->mo),
1269 get_value_string(om2k_msgcode_vals, msg_type),
1270 get_value_string(om2k_mostate_vals, mo_state));
1271
1272 return 0;
1273}
1274
Harald Welte9a311ec2011-02-12 12:33:06 +01001275int abis_om2k_rcvmsg(struct msgb *msg)
1276{
1277 struct gsm_bts *bts = msg->trx->bts;
1278 struct abis_om2k_hdr *o2h = msgb_l2(msg);
1279 struct abis_om_hdr *oh = &o2h->om;
Harald Weltebc867d92011-02-12 13:09:38 +01001280 uint16_t msg_type = ntohs(o2h->msg_type);
Harald Welte9a311ec2011-02-12 12:33:06 +01001281 int rc = 0;
1282
1283 /* Various consistency checks */
1284 if (oh->placement != ABIS_OM_PLACEMENT_ONLY) {
1285 LOGP(DNM, LOGL_ERROR, "ABIS OML placement 0x%x not supported\n",
1286 oh->placement);
1287 if (oh->placement != ABIS_OM_PLACEMENT_FIRST)
1288 return -EINVAL;
1289 }
1290 if (oh->sequence != 0) {
1291 LOGP(DNM, LOGL_ERROR, "ABIS OML sequence 0x%x != 0x00\n",
1292 oh->sequence);
1293 return -EINVAL;
1294 }
1295
1296 msg->l3h = (unsigned char *)o2h + sizeof(*o2h);
1297
1298 if (oh->mdisc != ABIS_OM_MDISC_FOM) {
1299 LOGP(DNM, LOGL_ERROR, "unknown ABIS OM2000 message discriminator 0x%x\n",
1300 oh->mdisc);
1301 return -EINVAL;
1302 }
1303
Harald Welte73541072011-02-12 13:44:14 +01001304 DEBUGP(DNM, "Rx MO=%s %s (%s)\n", om2k_mo_name(&o2h->mo),
Harald Weltebc867d92011-02-12 13:09:38 +01001305 get_value_string(om2k_msgcode_vals, msg_type),
Harald Welte9a311ec2011-02-12 12:33:06 +01001306 hexdump(msg->l2h, msgb_l2len(msg)));
1307
Harald Weltebc867d92011-02-12 13:09:38 +01001308 switch (msg_type) {
Harald Welte9a311ec2011-02-12 12:33:06 +01001309 case OM2K_MSGT_CAL_TIME_REQ:
1310 rc = abis_om2k_cal_time_resp(bts);
1311 break;
1312 case OM2K_MSGT_FAULT_REP:
Harald Weltee898ecc2011-03-06 19:26:11 +01001313 process_mo_state(bts, msg);
Harald Welte9a311ec2011-02-12 12:33:06 +01001314 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_FAULT_REP_ACK);
1315 break;
1316 case OM2K_MSGT_NEGOT_REQ:
1317 rc = om2k_rx_negot_req(msg);
1318 break;
1319 case OM2K_MSGT_START_RES:
Harald Weltee898ecc2011-03-06 19:26:11 +01001320 process_mo_state(bts, msg);
Harald Welte9a311ec2011-02-12 12:33:06 +01001321 rc = om2k_rx_start_res(msg);
1322 break;
Harald Welte0741ffe2011-02-12 18:48:53 +01001323 case OM2K_MSGT_OP_INFO_ACK:
1324 rc = om2k_rx_op_info_ack(msg);
Harald Welte9a311ec2011-02-12 12:33:06 +01001325 break;
1326 case OM2K_MSGT_IS_CONF_RES:
Harald Weltee898ecc2011-03-06 19:26:11 +01001327 process_conf_res(bts, msg);
Harald Welte9a311ec2011-02-12 12:33:06 +01001328 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_IS_CONF_RES_ACK);
1329 break;
Harald Weltefdb71942011-02-14 15:31:43 +01001330 case OM2K_MSGT_CON_CONF_RES:
Harald Weltee898ecc2011-03-06 19:26:11 +01001331 process_conf_res(bts, msg);
Harald Weltefdb71942011-02-14 15:31:43 +01001332 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_CON_CONF_RES_ACK);
1333 break;
Harald Weltea0ce3492011-03-05 14:13:14 +01001334 case OM2K_MSGT_TX_CONF_RES:
Harald Weltee898ecc2011-03-06 19:26:11 +01001335 process_conf_res(bts, msg);
Harald Weltea0ce3492011-03-05 14:13:14 +01001336 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_TX_CONF_RES_ACK);
1337 break;
1338 case OM2K_MSGT_RX_CONF_RES:
Harald Weltee898ecc2011-03-06 19:26:11 +01001339 process_conf_res(bts, msg);
Harald Weltea0ce3492011-03-05 14:13:14 +01001340 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_RX_CONF_RES_ACK);
1341 break;
1342 case OM2K_MSGT_TS_CONF_RES:
Harald Weltee898ecc2011-03-06 19:26:11 +01001343 process_conf_res(bts, msg);
Harald Weltea0ce3492011-03-05 14:13:14 +01001344 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_TS_CONF_RES_ACK);
1345 break;
Harald Weltef9cf9612011-03-05 14:36:47 +01001346 case OM2K_MSGT_TF_CONF_RES:
Harald Weltee898ecc2011-03-06 19:26:11 +01001347 process_conf_res(bts, msg);
Harald Weltef9cf9612011-03-05 14:36:47 +01001348 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_TF_CONF_RES_ACK);
1349 break;
Harald Welte9a311ec2011-02-12 12:33:06 +01001350 case OM2K_MSGT_CONNECT_COMPL:
1351 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_RESET_CMD);
1352 break;
1353 case OM2K_MSGT_RESET_COMPL:
1354 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_START_REQ);
1355 break;
Harald Welteb3d70fd2011-02-13 12:43:44 +01001356 case OM2K_MSGT_ENABLE_RES:
Harald Weltee898ecc2011-03-06 19:26:11 +01001357 process_mo_state(bts, msg);
Harald Welteb3d70fd2011-02-13 12:43:44 +01001358 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_ENABLE_RES_ACK);
1359 break;
Harald Weltefdb71942011-02-14 15:31:43 +01001360 case OM2K_MSGT_DISABLE_RES:
Harald Weltee898ecc2011-03-06 19:26:11 +01001361 process_mo_state(bts, msg);
Harald Weltefdb71942011-02-14 15:31:43 +01001362 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_DISABLE_RES_ACK);
1363 break;
1364 case OM2K_MSGT_TEST_RES:
Harald Weltee898ecc2011-03-06 19:26:11 +01001365 process_mo_state(bts, msg);
Harald Weltefdb71942011-02-14 15:31:43 +01001366 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_TEST_RES_ACK);
Harald Welte9a311ec2011-02-12 12:33:06 +01001367 break;
Harald Welte0741ffe2011-02-12 18:48:53 +01001368 case OM2K_MSGT_STATUS_RESP:
Harald Weltee898ecc2011-03-06 19:26:11 +01001369 process_mo_state(bts, msg);
Harald Welte0741ffe2011-02-12 18:48:53 +01001370 break;
Harald Weltefdb71942011-02-14 15:31:43 +01001371 case OM2K_MSGT_START_REQ_ACK:
1372 case OM2K_MSGT_CON_CONF_REQ_ACK:
1373 case OM2K_MSGT_IS_CONF_REQ_ACK:
Harald Weltea0ce3492011-03-05 14:13:14 +01001374 case OM2K_MSGT_TX_CONF_REQ_ACK:
1375 case OM2K_MSGT_RX_CONF_REQ_ACK:
1376 case OM2K_MSGT_TS_CONF_REQ_ACK:
Harald Weltef9cf9612011-03-05 14:36:47 +01001377 case OM2K_MSGT_TF_CONF_REQ_ACK:
Harald Weltefdb71942011-02-14 15:31:43 +01001378 case OM2K_MSGT_ENABLE_REQ_ACK:
1379 case OM2K_MSGT_ALARM_STATUS_REQ_ACK:
1380 case OM2K_MSGT_DISABLE_REQ_ACK:
1381 break;
Harald Weltee6e83832011-03-05 17:52:09 +01001382 case OM2K_MSGT_START_REQ_REJ:
Harald Welte3ede7232011-03-05 17:58:13 +01001383 case OM2K_MSGT_CONNECT_REJ:
Harald Welteaff63bc2011-03-05 19:42:16 +01001384 case OM2K_MSGT_OP_INFO_REJ:
Harald Welte3ede7232011-03-05 17:58:13 +01001385 case OM2K_MSGT_DISCONNECT_REJ:
Harald Welteaff63bc2011-03-05 19:42:16 +01001386 case OM2K_MSGT_TEST_REQ_REJ:
Harald Weltee6e83832011-03-05 17:52:09 +01001387 case OM2K_MSGT_CON_CONF_REQ_REJ:
1388 case OM2K_MSGT_IS_CONF_REQ_REJ:
1389 case OM2K_MSGT_TX_CONF_REQ_REJ:
1390 case OM2K_MSGT_RX_CONF_REQ_REJ:
1391 case OM2K_MSGT_TS_CONF_REQ_REJ:
1392 case OM2K_MSGT_TF_CONF_REQ_REJ:
1393 case OM2K_MSGT_ENABLE_REQ_REJ:
1394 case OM2K_MSGT_ALARM_STATUS_REQ_REJ:
1395 case OM2K_MSGT_DISABLE_REQ_REJ:
1396 rc = om2k_rx_nack(msg);
1397 break;
Harald Welte9a311ec2011-02-12 12:33:06 +01001398 default:
Harald Welte0741ffe2011-02-12 18:48:53 +01001399 LOGP(DNM, LOGL_NOTICE, "Rx unhandled OM2000 msg %s\n",
Harald Weltebc867d92011-02-12 13:09:38 +01001400 get_value_string(om2k_msgcode_vals, msg_type));
Harald Welte9a311ec2011-02-12 12:33:06 +01001401 }
1402
1403 msgb_free(msg);
1404 return rc;
1405}