blob: 9906ec19bd6c5485c90d6b7ac97ee0e6001a6166 [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,
Harald Welte1164dce2011-03-05 19:21:26 +0100169 OM2K_DEI_BS_AG_BKS_RES = 0x07,
Harald Weltea0ce3492011-03-05 14:13:14 +0100170 OM2K_DEI_BSIC = 0x09,
Harald Welte1164dce2011-03-05 19:21:26 +0100171 OM2K_DEI_BA_PA_MFRMS = 0x0a,
172 OM2K_DEI_CBCH_INDICATOR = 0x0b,
173 OM2K_DEI_CCCH_OPTIONS = 0x0c,
Harald Welte9a311ec2011-02-12 12:33:06 +0100174 OM2K_DEI_CAL_TIME = 0x0d,
Harald Weltea0ce3492011-03-05 14:13:14 +0100175 OM2K_DEI_COMBINATION = 0x0f,
Harald Weltefdb71942011-02-14 15:31:43 +0100176 OM2K_DEI_CON_CONN_LIST = 0x10,
Harald Welte1164dce2011-03-05 19:21:26 +0100177 OM2K_DEI_DRX_DEV_MAX = 0x12,
Harald Welte8bcb1a02011-02-12 20:23:40 +0100178 OM2K_DEI_END_LIST_NR = 0x13,
Harald Weltef6d6b212011-03-05 20:13:52 +0100179 OM2K_DEI_EXT_COND_MAP_1 = 0x14,
180 OM2K_DEI_EXT_COND_MAP_2 = 0x15,
Harald Weltea0ce3492011-03-05 14:13:14 +0100181 OM2K_DEI_FILLING_MARKER = 0x1c,
182 OM2K_DEI_FN_OFFSET = 0x1d,
183 OM2K_DEI_FREQ_LIST = 0x1e,
184 OM2K_DEI_FREQ_SPEC_RX = 0x1f,
185 OM2K_DEI_FREQ_SPEC_TX = 0x20,
186 OM2K_DEI_HSN = 0x21,
Harald Welte1164dce2011-03-05 19:21:26 +0100187 OM2K_DEI_ICM_INDICATOR = 0x22,
Harald Weltef6d6b212011-03-05 20:13:52 +0100188 OM2K_DEI_INT_FAULT_MAP_1A = 0x23,
189 OM2K_DEI_INT_FAULT_MAP_1B = 0x24,
190 OM2K_DEI_INT_FAULT_MAP_2A = 0x25,
191 OM2K_DEI_INT_FAULT_MAP_2A_EXT = 0x26,
Harald Welte8bcb1a02011-02-12 20:23:40 +0100192 OM2K_DEI_IS_CONN_LIST = 0x27,
193 OM2K_DEI_LIST_NR = 0x28,
Harald Weltef6d6b212011-03-05 20:13:52 +0100194 OM2K_DEI_LOCAL_ACCESS = 0x2a,
Harald Weltea0ce3492011-03-05 14:13:14 +0100195 OM2K_DEI_MAIO = 0x2b,
Harald Weltef6d6b212011-03-05 20:13:52 +0100196 OM2K_DEI_MO_STATE = 0x2c,
Harald Welte1164dce2011-03-05 19:21:26 +0100197 OM2K_DEI_NY1 = 0x2d,
Harald Welte9a311ec2011-02-12 12:33:06 +0100198 OM2K_DEI_OP_INFO = 0x2e,
Harald Weltea0ce3492011-03-05 14:13:14 +0100199 OM2K_DEI_POWER = 0x2f,
Harald Weltee6e83832011-03-05 17:52:09 +0100200 OM2K_DEI_REASON_CODE = 0x32,
Harald Weltea0ce3492011-03-05 14:13:14 +0100201 OM2K_DEI_RX_DIVERSITY = 0x33,
Harald Weltee6e83832011-03-05 17:52:09 +0100202 OM2K_DEI_RESULT_CODE = 0x35,
Harald Welte1164dce2011-03-05 19:21:26 +0100203 OM2K_DEI_T3105 = 0x38,
Harald Weltef9cf9612011-03-05 14:36:47 +0100204 OM2K_DEI_TF_MODE = 0x3a,
Harald Weltea0ce3492011-03-05 14:13:14 +0100205 OM2K_DEI_TS_NR = 0x3c,
Harald Welte1164dce2011-03-05 19:21:26 +0100206 OM2K_DEI_TSC = 0x3d,
Harald Weltef6d6b212011-03-05 20:13:52 +0100207 OM2K_DEI_BTS_VERSION = 0x40,
208 OM2K_DEI_OML_IWD_VERSION = 0x41,
209 OM2K_DEI_RSL_IWD_VERSION = 0x42,
210 OM2K_DEI_OML_FUNC_MAP_1 = 0x43,
211 OM2K_DEI_OML_FUNC_MAP_2 = 0x44,
212 OM2K_DEI_RSL_FUNC_MAP_1 = 0x45,
213 OM2K_DEI_RSL_FUNC_MAP_2 = 0x46,
Harald Weltea0ce3492011-03-05 14:13:14 +0100214 OM2K_DEI_EXT_RANGE = 0x47,
Harald Weltef6d6b212011-03-05 20:13:52 +0100215 OM2K_DEI_REQ_IND = 0x48,
216 OM2K_DEI_REPL_UNIT_MAP = 0x50,
Harald Welte75755c52011-03-05 20:38:35 +0100217 OM2K_DEI_ICM_BOUND_PARAMS = 0x74,
Harald Welte1164dce2011-03-05 19:21:26 +0100218 OM2K_DEI_LSC = 0x79,
219 OM2K_DEI_LSC_FILT_TIME = 0x7a,
220 OM2K_DEI_CALL_SUPV_TIME = 0x7b,
Harald Welte75755c52011-03-05 20:38:35 +0100221 OM2K_DEI_ICM_CHAN_RATE = 0x7e,
Harald Weltef6d6b212011-03-05 20:13:52 +0100222 OM2K_DEI_HW_INFO_SIG = 0x84,
Harald Welte1164dce2011-03-05 19:21:26 +0100223 OM2K_DEI_TTA = 0x87,
Harald Weltef6d6b212011-03-05 20:13:52 +0100224 OM2K_DEI_CAPA_SIG = 0x8a,
Harald Welte73541072011-02-12 13:44:14 +0100225 OM2K_DEI_NEGOT_REC1 = 0x90,
226 OM2K_DEI_NEGOT_REC2 = 0x91,
Harald Welte1164dce2011-03-05 19:21:26 +0100227 OM2K_DEI_ENCR_ALG = 0x92,
228 OM2K_DEI_INTERF_REJ_COMB = 0x94,
Harald Weltef9cf9612011-03-05 14:36:47 +0100229 OM2K_DEI_FS_OFFSET = 0x98,
Harald Weltef6d6b212011-03-05 20:13:52 +0100230 OM2K_DEI_EXT_COND_MAP_2_EXT = 0x9c,
Harald Welte9a311ec2011-02-12 12:33:06 +0100231};
232
Harald Weltee6e83832011-03-05 17:52:09 +0100233const struct tlv_definition om2k_att_tlvdef = {
234 .def = {
235 [OM2K_DEI_BCC] = { TLV_TYPE_TV },
Harald Welte1164dce2011-03-05 19:21:26 +0100236 [OM2K_DEI_BS_AG_BKS_RES] = { TLV_TYPE_TV },
Harald Weltee6e83832011-03-05 17:52:09 +0100237 [OM2K_DEI_BSIC] = { TLV_TYPE_TV },
Harald Welte1164dce2011-03-05 19:21:26 +0100238 [OM2K_DEI_BA_PA_MFRMS] = { TLV_TYPE_TV },
239 [OM2K_DEI_CBCH_INDICATOR] = { TLV_TYPE_TV },
Harald Weltef6d6b212011-03-05 20:13:52 +0100240 [OM2K_DEI_INT_FAULT_MAP_1A] = { TLV_TYPE_FIXED, 6 },
241 [OM2K_DEI_INT_FAULT_MAP_1B] = { TLV_TYPE_FIXED, 6 },
242 [OM2K_DEI_INT_FAULT_MAP_2A] = { TLV_TYPE_FIXED, 6 },
243 [OM2K_DEI_INT_FAULT_MAP_2A_EXT]={ TLV_TYPE_FIXED, 6 },
Harald Welte1164dce2011-03-05 19:21:26 +0100244 [OM2K_DEI_CCCH_OPTIONS] = { TLV_TYPE_TV },
Harald Weltee6e83832011-03-05 17:52:09 +0100245 [OM2K_DEI_CAL_TIME] = { TLV_TYPE_FIXED, 6 },
246 [OM2K_DEI_COMBINATION] = { TLV_TYPE_TV },
247 [OM2K_DEI_CON_CONN_LIST] = { TLV_TYPE_TLV },
Harald Welte1164dce2011-03-05 19:21:26 +0100248 [OM2K_DEI_DRX_DEV_MAX] = { TLV_TYPE_TV },
Harald Weltee6e83832011-03-05 17:52:09 +0100249 [OM2K_DEI_END_LIST_NR] = { TLV_TYPE_TV },
Harald Weltef6d6b212011-03-05 20:13:52 +0100250 [OM2K_DEI_EXT_COND_MAP_1] = { TLV_TYPE_FIXED, 2 },
251 [OM2K_DEI_EXT_COND_MAP_2] = { TLV_TYPE_FIXED, 2 },
Harald Weltee6e83832011-03-05 17:52:09 +0100252 [OM2K_DEI_FILLING_MARKER] = { TLV_TYPE_TV },
253 [OM2K_DEI_FN_OFFSET] = { TLV_TYPE_FIXED, 2 },
254 [OM2K_DEI_FREQ_LIST] = { TLV_TYPE_TLV },
255 [OM2K_DEI_FREQ_SPEC_RX] = { TLV_TYPE_FIXED, 2 },
256 [OM2K_DEI_FREQ_SPEC_TX] = { TLV_TYPE_FIXED, 2 },
257 [OM2K_DEI_HSN] = { TLV_TYPE_TV },
Harald Welte1164dce2011-03-05 19:21:26 +0100258 [OM2K_DEI_ICM_INDICATOR] = { TLV_TYPE_TV },
Harald Weltee6e83832011-03-05 17:52:09 +0100259 [OM2K_DEI_IS_CONN_LIST] = { TLV_TYPE_TLV },
260 [OM2K_DEI_LIST_NR] = { TLV_TYPE_TV },
Harald Weltef6d6b212011-03-05 20:13:52 +0100261 [OM2K_DEI_LOCAL_ACCESS] = { TLV_TYPE_TV },
Harald Weltee6e83832011-03-05 17:52:09 +0100262 [OM2K_DEI_MAIO] = { TLV_TYPE_TV },
Harald Weltef6d6b212011-03-05 20:13:52 +0100263 [OM2K_DEI_MO_STATE] = { TLV_TYPE_TV },
Harald Welte1164dce2011-03-05 19:21:26 +0100264 [OM2K_DEI_NY1] = { TLV_TYPE_TV },
Harald Weltee6e83832011-03-05 17:52:09 +0100265 [OM2K_DEI_OP_INFO] = { TLV_TYPE_TV },
266 [OM2K_DEI_POWER] = { TLV_TYPE_TV },
267 [OM2K_DEI_REASON_CODE] = { TLV_TYPE_TV },
268 [OM2K_DEI_RX_DIVERSITY] = { TLV_TYPE_TV },
269 [OM2K_DEI_RESULT_CODE] = { TLV_TYPE_TV },
Harald Welte1164dce2011-03-05 19:21:26 +0100270 [OM2K_DEI_T3105] = { TLV_TYPE_TV },
Harald Weltee6e83832011-03-05 17:52:09 +0100271 [OM2K_DEI_TF_MODE] = { TLV_TYPE_TV },
272 [OM2K_DEI_TS_NR] = { TLV_TYPE_TV },
Harald Welte1164dce2011-03-05 19:21:26 +0100273 [OM2K_DEI_TSC] = { TLV_TYPE_TV },
Harald Weltef6d6b212011-03-05 20:13:52 +0100274 [OM2K_DEI_BTS_VERSION] = { TLV_TYPE_FIXED, 12 },
275 [OM2K_DEI_OML_IWD_VERSION] = { TLV_TYPE_FIXED, 6 },
276 [OM2K_DEI_RSL_IWD_VERSION] = { TLV_TYPE_FIXED, 6 },
277 [OM2K_DEI_OML_FUNC_MAP_1] = { TLV_TYPE_TLV },
278 [OM2K_DEI_OML_FUNC_MAP_2] = { TLV_TYPE_TLV },
279 [OM2K_DEI_RSL_FUNC_MAP_1] = { TLV_TYPE_TLV },
280 [OM2K_DEI_RSL_FUNC_MAP_2] = { TLV_TYPE_TLV },
Harald Weltee6e83832011-03-05 17:52:09 +0100281 [OM2K_DEI_EXT_RANGE] = { TLV_TYPE_TV },
Harald Weltef6d6b212011-03-05 20:13:52 +0100282 [OM2K_DEI_REQ_IND] = { TLV_TYPE_TV },
283 [OM2K_DEI_REPL_UNIT_MAP] = { TLV_TYPE_FIXED, 6 },
Harald Welte75755c52011-03-05 20:38:35 +0100284 [OM2K_DEI_ICM_BOUND_PARAMS] = { TLV_TYPE_FIXED, 5 },
Harald Welte1164dce2011-03-05 19:21:26 +0100285 [OM2K_DEI_LSC] = { TLV_TYPE_TV },
286 [OM2K_DEI_LSC_FILT_TIME] = { TLV_TYPE_TV },
287 [OM2K_DEI_CALL_SUPV_TIME] = { TLV_TYPE_TV },
Harald Welte75755c52011-03-05 20:38:35 +0100288 [OM2K_DEI_ICM_CHAN_RATE] = { TLV_TYPE_TV },
Harald Weltef6d6b212011-03-05 20:13:52 +0100289 [OM2K_DEI_HW_INFO_SIG] = { TLV_TYPE_FIXED, 2 },
Harald Welte1164dce2011-03-05 19:21:26 +0100290 [OM2K_DEI_TTA] = { TLV_TYPE_TV },
Harald Weltef6d6b212011-03-05 20:13:52 +0100291 [OM2K_DEI_CAPA_SIG] = { TLV_TYPE_FIXED, 2 },
Harald Weltee6e83832011-03-05 17:52:09 +0100292 [OM2K_DEI_NEGOT_REC1] = { TLV_TYPE_TLV },
293 [OM2K_DEI_NEGOT_REC2] = { TLV_TYPE_TLV },
Harald Welte1164dce2011-03-05 19:21:26 +0100294 [OM2K_DEI_ENCR_ALG] = { TLV_TYPE_TV },
295 [OM2K_DEI_INTERF_REJ_COMB] = { TLV_TYPE_TV },
Harald Weltee6e83832011-03-05 17:52:09 +0100296 [OM2K_DEI_FS_OFFSET] = { TLV_TYPE_FIXED, 5 },
Harald Weltef6d6b212011-03-05 20:13:52 +0100297 [OM2K_DEI_EXT_COND_MAP_2_EXT] = { TLV_TYPE_FIXED, 4 },
Harald Weltee6e83832011-03-05 17:52:09 +0100298 },
299};
300
Harald Welte9a311ec2011-02-12 12:33:06 +0100301static const struct value_string om2k_msgcode_vals[] = {
302 { 0x0000, "Abort SP Command" },
303 { 0x0002, "Abort SP Complete" },
304 { 0x0004, "Alarm Report ACK" },
305 { 0x0005, "Alarm Report NACK" },
306 { 0x0006, "Alarm Report" },
307 { 0x0008, "Alarm Status Request" },
308 { 0x000a, "Alarm Status Request Accept" },
309 { 0x000b, "Alarm Status Request Reject" },
310 { 0x000c, "Alarm Status Result ACK" },
311 { 0x000d, "Alarm Status Result NACK" },
312 { 0x000e, "Alarm Status Result" },
313 { 0x0010, "Calendar Time Response" },
314 { 0x0011, "Calendar Time Reject" },
315 { 0x0012, "Calendar Time Request" },
316 { 0x0014, "CON Configuration Request" },
317 { 0x0016, "CON Configuration Request Accept" },
318 { 0x0017, "CON Configuration Request Reject" },
319 { 0x0018, "CON Configuration Result ACK" },
320 { 0x0019, "CON Configuration Result NACK" },
321 { 0x001a, "CON Configuration Result" },
322 { 0x001c, "Connect Command" },
323 { 0x001e, "Connect Complete" },
Harald Welte3ede7232011-03-05 17:58:13 +0100324 { 0x001f, "Connect Reject" },
Harald Welte9a311ec2011-02-12 12:33:06 +0100325 { 0x0028, "Disable Request" },
326 { 0x002a, "Disable Request Accept" },
327 { 0x002b, "Disable Request Reject" },
328 { 0x002c, "Disable Result ACK" },
329 { 0x002d, "Disable Result NACK" },
330 { 0x002e, "Disable Result" },
331 { 0x0030, "Disconnect Command" },
332 { 0x0032, "Disconnect Complete" },
333 { 0x0033, "Disconnect Reject" },
334 { 0x0034, "Enable Request" },
335 { 0x0036, "Enable Request Accept" },
336 { 0x0037, "Enable Request Reject" },
337 { 0x0038, "Enable Result ACK" },
338 { 0x0039, "Enable Result NACK" },
339 { 0x003a, "Enable Result" },
340 { 0x003c, "Escape Downlink Normal" },
341 { 0x003d, "Escape Downlink NACK" },
342 { 0x003e, "Escape Uplink Normal" },
343 { 0x003f, "Escape Uplink NACK" },
344 { 0x0040, "Fault Report ACK" },
345 { 0x0041, "Fault Report NACK" },
346 { 0x0042, "Fault Report" },
347 { 0x0044, "File Package End Command" },
348 { 0x0046, "File Package End Result" },
349 { 0x0047, "File Package End Reject" },
350 { 0x0048, "File Relation Request" },
351 { 0x004a, "File Relation Response" },
352 { 0x004b, "File Relation Request Reject" },
353 { 0x004c, "File Segment Transfer" },
354 { 0x004e, "File Segment Transfer Complete" },
355 { 0x004f, "File Segment Transfer Reject" },
356 { 0x0050, "HW Information Request" },
357 { 0x0052, "HW Information Request Accept" },
358 { 0x0053, "HW Information Request Reject" },
359 { 0x0054, "HW Information Result ACK" },
360 { 0x0055, "HW Information Result NACK" },
361 { 0x0056, "HW Information Result" },
362 { 0x0060, "IS Configuration Request" },
363 { 0x0062, "IS Configuration Request Accept" },
364 { 0x0063, "IS Configuration Request Reject" },
365 { 0x0064, "IS Configuration Result ACK" },
366 { 0x0065, "IS Configuration Result NACK" },
367 { 0x0066, "IS Configuration Result" },
368 { 0x0068, "Load Data End" },
369 { 0x006a, "Load Data End Result" },
370 { 0x006b, "Load Data End Reject" },
371 { 0x006c, "Load Data Init" },
372 { 0x006e, "Load Data Init Accept" },
373 { 0x006f, "Load Data Init Reject" },
374 { 0x0070, "Loop Control Command" },
375 { 0x0072, "Loop Control Complete" },
376 { 0x0073, "Loop Control Reject" },
377 { 0x0074, "Operational Information" },
378 { 0x0076, "Operational Information Accept" },
379 { 0x0077, "Operational Information Reject" },
380 { 0x0078, "Reset Command" },
381 { 0x007a, "Reset Complete" },
382 { 0x007b, "Reset Reject" },
383 { 0x007c, "RX Configuration Request" },
384 { 0x007e, "RX Configuration Request Accept" },
385 { 0x007f, "RX Configuration Request Reject" },
386 { 0x0080, "RX Configuration Result ACK" },
387 { 0x0081, "RX Configuration Result NACK" },
388 { 0x0082, "RX Configuration Result" },
389 { 0x0084, "Start Request" },
390 { 0x0086, "Start Request Accept" },
391 { 0x0087, "Start Request Reject" },
392 { 0x0088, "Start Result ACK" },
393 { 0x0089, "Start Result NACK" },
394 { 0x008a, "Start Result" },
395 { 0x008c, "Status Request" },
396 { 0x008e, "Status Response" },
397 { 0x008f, "Status Reject" },
398 { 0x0094, "Test Request" },
399 { 0x0096, "Test Request Accept" },
400 { 0x0097, "Test Request Reject" },
401 { 0x0098, "Test Result ACK" },
402 { 0x0099, "Test Result NACK" },
403 { 0x009a, "Test Result" },
404 { 0x00a0, "TF Configuration Request" },
405 { 0x00a2, "TF Configuration Request Accept" },
406 { 0x00a3, "TF Configuration Request Reject" },
407 { 0x00a4, "TF Configuration Result ACK" },
408 { 0x00a5, "TF Configuration Result NACK" },
409 { 0x00a6, "TF Configuration Result" },
410 { 0x00a8, "TS Configuration Request" },
411 { 0x00aa, "TS Configuration Request Accept" },
412 { 0x00ab, "TS Configuration Request Reject" },
413 { 0x00ac, "TS Configuration Result ACK" },
414 { 0x00ad, "TS Configuration Result NACK" },
415 { 0x00ae, "TS Configuration Result" },
416 { 0x00b0, "TX Configuration Request" },
417 { 0x00b2, "TX Configuration Request Accept" },
418 { 0x00b3, "TX Configuration Request Reject" },
419 { 0x00b4, "TX Configuration Result ACK" },
420 { 0x00b5, "TX Configuration Result NACK" },
421 { 0x00b6, "TX Configuration Result" },
422 { 0x00bc, "DIP Alarm Report ACK" },
423 { 0x00bd, "DIP Alarm Report NACK" },
424 { 0x00be, "DIP Alarm Report" },
425 { 0x00c0, "DIP Alarm Status Request" },
426 { 0x00c2, "DIP Alarm Status Response" },
427 { 0x00c3, "DIP Alarm Status Reject" },
428 { 0x00c4, "DIP Quality Report I ACK" },
429 { 0x00c5, "DIP Quality Report I NACK" },
430 { 0x00c6, "DIP Quality Report I" },
431 { 0x00c8, "DIP Quality Report II ACK" },
432 { 0x00c9, "DIP Quality Report II NACK" },
433 { 0x00ca, "DIP Quality Report II" },
434 { 0x00dc, "DP Configuration Request" },
435 { 0x00de, "DP Configuration Request Accept" },
436 { 0x00df, "DP Configuration Request Reject" },
437 { 0x00e0, "DP Configuration Result ACK" },
438 { 0x00e1, "DP Configuration Result NACK" },
439 { 0x00e2, "DP Configuration Result" },
440 { 0x00e4, "Capabilities HW Info Report ACK" },
441 { 0x00e5, "Capabilities HW Info Report NACK" },
442 { 0x00e6, "Capabilities HW Info Report" },
443 { 0x00e8, "Capabilities Request" },
444 { 0x00ea, "Capabilities Request Accept" },
445 { 0x00eb, "Capabilities Request Reject" },
446 { 0x00ec, "Capabilities Result ACK" },
447 { 0x00ed, "Capabilities Result NACK" },
448 { 0x00ee, "Capabilities Result" },
449 { 0x00f0, "FM Configuration Request" },
450 { 0x00f2, "FM Configuration Request Accept" },
451 { 0x00f3, "FM Configuration Request Reject" },
452 { 0x00f4, "FM Configuration Result ACK" },
453 { 0x00f5, "FM Configuration Result NACK" },
454 { 0x00f6, "FM Configuration Result" },
455 { 0x00f8, "FM Report Request" },
456 { 0x00fa, "FM Report Response" },
457 { 0x00fb, "FM Report Reject" },
458 { 0x00fc, "FM Start Command" },
459 { 0x00fe, "FM Start Complete" },
460 { 0x00ff, "FM Start Reject" },
461 { 0x0100, "FM Stop Command" },
462 { 0x0102, "FM Stop Complete" },
463 { 0x0103, "FM Stop Reject" },
464 { 0x0104, "Negotiation Request ACK" },
465 { 0x0105, "Negotiation Request NACK" },
466 { 0x0106, "Negotiation Request" },
467 { 0x0108, "BTS Initiated Request ACK" },
468 { 0x0109, "BTS Initiated Request NACK" },
469 { 0x010a, "BTS Initiated Request" },
470 { 0x010c, "Radio Channels Release Command" },
471 { 0x010e, "Radio Channels Release Complete" },
472 { 0x010f, "Radio Channels Release Reject" },
473 { 0x0118, "Feature Control Command" },
474 { 0x011a, "Feature Control Complete" },
475 { 0x011b, "Feature Control Reject" },
476
477 { 0, NULL }
478};
479
480/* TS 12.21 Section 9.4: Attributes */
481static const struct value_string om2k_attr_vals[] = {
482 { 0x00, "Accordance indication" },
483 { 0x01, "Alarm Id" },
484 { 0x02, "Alarm Data" },
485 { 0x03, "Alarm Severity" },
486 { 0x04, "Alarm Status" },
487 { 0x05, "Alarm Status Type" },
488 { 0x06, "BCC" },
489 { 0x07, "BS_AG_BKS_RES" },
490 { 0x09, "BSIC" },
491 { 0x0a, "BA_PA_MFRMS" },
492 { 0x0b, "CBCH Indicator" },
493 { 0x0c, "CCCH Options" },
494 { 0x0d, "Calendar Time" },
495 { 0x0f, "Channel Combination" },
496 { 0x10, "CON Connection List" },
497 { 0x11, "Data End Indication" },
498 { 0x12, "DRX_DEV_MAX" },
499 { 0x13, "End List Number" },
500 { 0x14, "External Condition Map Class 1" },
501 { 0x15, "External Condition Map Class 2" },
502 { 0x16, "File Relation Indication" },
503 { 0x17, "File Revision" },
504 { 0x18, "File Segment Data" },
505 { 0x19, "File Segment Length" },
506 { 0x1a, "File Segment Sequence Number" },
507 { 0x1b, "File Size" },
508 { 0x1c, "Filling Marker" },
509 { 0x1d, "FN Offset" },
510 { 0x1e, "Frequency List" },
511 { 0x1f, "Frequency Specifier RX" },
512 { 0x20, "Frequency Specifier TX" },
513 { 0x21, "HSN" },
514 { 0x22, "ICM Indicator" },
515 { 0x23, "Internal Fault Map Class 1A" },
516 { 0x24, "Internal Fault Map Class 1B" },
517 { 0x25, "Internal Fault Map Class 2A" },
518 { 0x26, "Internal Fault Map Class 2A Extension" },
519 { 0x27, "IS Connection List" },
520 { 0x28, "List Number" },
521 { 0x29, "File Package State Indication" },
522 { 0x2a, "Local Access State" },
523 { 0x2b, "MAIO" },
524 { 0x2c, "MO State" },
525 { 0x2d, "Ny1" },
526 { 0x2e, "Operational Information" },
527 { 0x2f, "Power" },
528 { 0x30, "RU Position Data" },
529 { 0x31, "Protocol Error" },
530 { 0x32, "Reason Code" },
531 { 0x33, "Receiver Diversity" },
532 { 0x34, "Replacement Unit Map" },
533 { 0x35, "Result Code" },
534 { 0x36, "RU Revision Data" },
535 { 0x38, "T3105" },
536 { 0x39, "Test Loop Setting" },
537 { 0x3a, "TF Mode" },
538 { 0x3b, "TF Compensation Value" },
539 { 0x3c, "Time Slot Number" },
540 { 0x3d, "TSC" },
541 { 0x3e, "RU Logical Id" },
542 { 0x3f, "RU Serial Number Data" },
543 { 0x40, "BTS Version" },
544 { 0x41, "OML IWD Version" },
545 { 0x42, "RWL IWD Version" },
546 { 0x43, "OML Function Map 1" },
547 { 0x44, "OML Function Map 2" },
548 { 0x45, "RSL Function Map 1" },
549 { 0x46, "RSL Function Map 2" },
550 { 0x47, "Extended Range Indicator" },
551 { 0x48, "Request Indicators" },
552 { 0x49, "DIP Alarm Condition Map" },
553 { 0x4a, "ES Incoming" },
554 { 0x4b, "ES Outgoing" },
555 { 0x4e, "SES Incoming" },
556 { 0x4f, "SES Outgoing" },
557 { 0x50, "Replacement Unit Map Extension" },
558 { 0x52, "UAS Incoming" },
559 { 0x53, "UAS Outgoing" },
560 { 0x58, "DF Incoming" },
561 { 0x5a, "DF Outgoing" },
562 { 0x5c, "SF" },
563 { 0x60, "S Bits Setting" },
564 { 0x61, "CRC-4 Use Option" },
565 { 0x62, "T Parameter" },
566 { 0x63, "N Parameter" },
567 { 0x64, "N1 Parameter" },
568 { 0x65, "N3 Parameter" },
569 { 0x66, "N4 Parameter" },
570 { 0x67, "P Parameter" },
571 { 0x68, "Q Parameter" },
572 { 0x69, "BI_Q1" },
573 { 0x6a, "BI_Q2" },
574 { 0x74, "ICM Boundary Parameters" },
575 { 0x77, "AFT" },
576 { 0x78, "AFT RAI" },
577 { 0x79, "Link Supervision Control" },
578 { 0x7a, "Link Supervision Filtering Time" },
579 { 0x7b, "Call Supervision Time" },
580 { 0x7c, "Interval Length UAS Incoming" },
581 { 0x7d, "Interval Length UAS Outgoing" },
582 { 0x7e, "ICM Channel Rate" },
583 { 0x7f, "Attribute Identifier" },
584 { 0x80, "FM Frequency List" },
585 { 0x81, "FM Frequency Report" },
586 { 0x82, "FM Percentile" },
587 { 0x83, "FM Clear Indication" },
588 { 0x84, "HW Info Signature" },
589 { 0x85, "MO Record" },
590 { 0x86, "TF Synchronisation Source" },
591 { 0x87, "TTA" },
592 { 0x88, "End Segment Number" },
593 { 0x89, "Segment Number" },
594 { 0x8a, "Capabilities Signature" },
595 { 0x8c, "File Relation List" },
596 { 0x90, "Negotiation Record I" },
597 { 0x91, "Negotiation Record II" },
598 { 0x92, "Encryption Algorithm" },
599 { 0x94, "Interference Rejection Combining" },
600 { 0x95, "Dedication Information" },
601 { 0x97, "Feature Code" },
602 { 0x98, "FS Offset" },
603 { 0x99, "ESB Timeslot" },
604 { 0x9a, "Master TG Instance" },
605 { 0x9b, "Master TX Chain Delay" },
606 { 0x9c, "External Condition Class 2 Extension" },
607 { 0x9d, "TSs MO State" },
608 { 0, NULL }
609};
610
Harald Weltee1d5eca2011-02-12 14:42:59 +0100611const struct value_string om2k_mo_class_short_vals[] = {
Harald Welte9a311ec2011-02-12 12:33:06 +0100612 { 0x01, "TRXC" },
613 { 0x03, "TS" },
614 { 0x04, "TF" },
615 { 0x05, "IS" },
616 { 0x06, "CON" },
617 { 0x07, "DP" },
618 { 0x0a, "CF" },
619 { 0x0b, "TX" },
620 { 0x0c, "RX" },
621 { 0, NULL }
622};
623
624static struct msgb *om2k_msgb_alloc(void)
625{
626 return msgb_alloc_headroom(OM_ALLOC_SIZE, OM_HEADROOM_SIZE,
627 "OM2000");
628}
629
Harald Weltee6e83832011-03-05 17:52:09 +0100630static int abis_om2k_tlv_parse(struct tlv_parsed *tp, const u_int8_t *buf, int len)
631{
632 return tlv_parse(tp, &om2k_att_tlvdef, buf, len, 0, 0);
633}
634
Harald Welted88a3872011-02-14 15:26:13 +0100635static char *om2k_mo_name(const struct abis_om2k_mo *mo)
636{
637 static char mo_buf[64];
638
639 memset(mo_buf, 0, sizeof(mo_buf));
640 snprintf(mo_buf, sizeof(mo_buf), "%s/%02x/%02x/%02x",
641 get_value_string(om2k_mo_class_short_vals, mo->class),
642 mo->bts, mo->assoc_so, mo->inst);
643 return mo_buf;
644}
645
Harald Weltebc867d92011-02-12 13:09:38 +0100646static int abis_om2k_sendmsg(struct gsm_bts *bts, struct msgb *msg)
647{
Harald Welted88a3872011-02-14 15:26:13 +0100648 struct abis_om2k_hdr *o2h;
649 int to_trx_oml;
Harald Weltebc867d92011-02-12 13:09:38 +0100650
Harald Welted88a3872011-02-14 15:26:13 +0100651 msg->l2h = msg->data;
652 o2h = (struct abis_om2k_hdr *) msg->l2h;
653
Harald Welte1164dce2011-03-05 19:21:26 +0100654 /* Compute the length in the OML header */
655 o2h->om.length = 6 + msgb_l2len(msg)-sizeof(*o2h);
656
Harald Welted88a3872011-02-14 15:26:13 +0100657 switch (o2h->mo.class) {
658 case OM2K_MO_CLS_TRXC:
659 case OM2K_MO_CLS_TX:
660 case OM2K_MO_CLS_RX:
Harald Welted88a3872011-02-14 15:26:13 +0100661 /* Route through per-TRX OML Link to the appropriate TRX */
662 to_trx_oml = 1;
663 msg->trx = gsm_bts_trx_by_nr(bts, o2h->mo.inst);
664 if (!msg->trx) {
665 LOGP(DNM, LOGL_ERROR, "MO=%s Tx Dropping msg to "
666 "non-existing TRX\n", om2k_mo_name(&o2h->mo));
667 return -ENODEV;
668 }
669 break;
Harald Welte8aeac192011-03-05 20:15:09 +0100670 case OM2K_MO_CLS_TS:
671 /* Route through per-TRX OML Link to the appropriate TRX */
672 to_trx_oml = 1;
673 msg->trx = gsm_bts_trx_by_nr(bts, o2h->mo.assoc_so);
674 if (!msg->trx) {
675 LOGP(DNM, LOGL_ERROR, "MO=%s Tx Dropping msg to "
676 "non-existing TRX\n", om2k_mo_name(&o2h->mo));
677 return -ENODEV;
678 }
679 break;
Harald Welted88a3872011-02-14 15:26:13 +0100680 default:
681 /* Route through the IXU/DXU OML Link */
682 msg->trx = bts->c0;
683 to_trx_oml = 0;
684 break;
685 }
686
687 return _abis_nm_sendmsg(msg, to_trx_oml);
Harald Weltebc867d92011-02-12 13:09:38 +0100688}
689
Harald Welte9a311ec2011-02-12 12:33:06 +0100690static void fill_om2k_hdr(struct abis_om2k_hdr *o2h, const struct abis_om2k_mo *mo,
Harald Welte1164dce2011-03-05 19:21:26 +0100691 uint16_t msg_type)
Harald Welte9a311ec2011-02-12 12:33:06 +0100692{
693 o2h->om.mdisc = ABIS_OM_MDISC_FOM;
694 o2h->om.placement = ABIS_OM_PLACEMENT_ONLY;
695 o2h->om.sequence = 0;
Harald Welte1164dce2011-03-05 19:21:26 +0100696 /* We fill o2h->om.length later during om2k_sendmsg() */
Harald Welte9a311ec2011-02-12 12:33:06 +0100697 o2h->msg_type = htons(msg_type);
698 memcpy(&o2h->mo, mo, sizeof(o2h->mo));
699}
700
Harald Welte73541072011-02-12 13:44:14 +0100701const struct abis_om2k_mo om2k_mo_cf = { OM2K_MO_CLS_CF, 0, 0xFF, 0 };
Harald Welte8bcb1a02011-02-12 20:23:40 +0100702const struct abis_om2k_mo om2k_mo_is = { OM2K_MO_CLS_IS, 0, 0xFF, 0 };
Harald Weltefdb71942011-02-14 15:31:43 +0100703const struct abis_om2k_mo om2k_mo_con = { OM2K_MO_CLS_CON, 0, 0xFF, 0 };
Harald Weltef9cf9612011-03-05 14:36:47 +0100704const struct abis_om2k_mo om2k_mo_tf = { OM2K_MO_CLS_TF, 0, 0xFF, 0 };
Harald Welte9a311ec2011-02-12 12:33:06 +0100705
706static int abis_om2k_cal_time_resp(struct gsm_bts *bts)
707{
708 struct msgb *msg = om2k_msgb_alloc();
709 struct abis_om2k_hdr *o2k;
710 time_t tm_t;
711 struct tm *tm;
712
713 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
Harald Welte1164dce2011-03-05 19:21:26 +0100714 fill_om2k_hdr(o2k, &om2k_mo_cf, OM2K_MSGT_CAL_TIME_RESP);
Harald Welte9a311ec2011-02-12 12:33:06 +0100715
716 tm_t = time(NULL);
717 tm = localtime(&tm_t);
718
719 msgb_put_u8(msg, OM2K_DEI_CAL_TIME);
720 msgb_put_u8(msg, tm->tm_year % 100);
721 msgb_put_u8(msg, tm->tm_mon + 1);
722 msgb_put_u8(msg, tm->tm_mday);
723 msgb_put_u8(msg, tm->tm_hour);
724 msgb_put_u8(msg, tm->tm_min);
725 msgb_put_u8(msg, tm->tm_sec);
726
Harald Weltebc867d92011-02-12 13:09:38 +0100727 return abis_om2k_sendmsg(bts, msg);
Harald Welte9a311ec2011-02-12 12:33:06 +0100728}
729
Harald Welte6fec79d2011-02-12 14:57:17 +0100730static int abis_om2k_tx_simple(struct gsm_bts *bts, const struct abis_om2k_mo *mo,
Harald Welte9a311ec2011-02-12 12:33:06 +0100731 uint8_t msg_type)
732{
733 struct msgb *msg = om2k_msgb_alloc();
734 struct abis_om2k_hdr *o2k;
735
736 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
Harald Welte1164dce2011-03-05 19:21:26 +0100737 fill_om2k_hdr(o2k, mo, msg_type);
Harald Welte9a311ec2011-02-12 12:33:06 +0100738
Harald Welte73541072011-02-12 13:44:14 +0100739 DEBUGP(DNM, "Tx MO=%s %s\n", om2k_mo_name(mo),
740 get_value_string(om2k_msgcode_vals, msg_type));
741
Harald Weltebc867d92011-02-12 13:09:38 +0100742 return abis_om2k_sendmsg(bts, msg);
Harald Welte9a311ec2011-02-12 12:33:06 +0100743}
744
Harald Welte6fec79d2011-02-12 14:57:17 +0100745int abis_om2k_tx_reset_cmd(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
Harald Welte73541072011-02-12 13:44:14 +0100746{
747 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_RESET_CMD);
748}
749
Harald Welte6fec79d2011-02-12 14:57:17 +0100750int abis_om2k_tx_start_req(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
Harald Welte73541072011-02-12 13:44:14 +0100751{
752 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_START_REQ);
753}
754
Harald Welte6fec79d2011-02-12 14:57:17 +0100755int abis_om2k_tx_status_req(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
Harald Weltee1d5eca2011-02-12 14:42:59 +0100756{
757 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_STATUS_REQ);
758}
759
Harald Welte6fec79d2011-02-12 14:57:17 +0100760int abis_om2k_tx_connect_cmd(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
761{
762 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_CONNECT_CMD);
763}
764
765int abis_om2k_tx_disconnect_cmd(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
766{
767 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_DISCONNECT_CMD);
768}
769
Harald Welte8024d8f2011-02-12 15:07:30 +0100770int abis_om2k_tx_test_req(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
771{
772 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_TEST_REQ);
773}
774
Harald Welte0741ffe2011-02-12 18:48:53 +0100775int abis_om2k_tx_enable_req(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
776{
777 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_ENABLE_REQ);
778}
779
780int abis_om2k_tx_disable_req(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
781{
782 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_DISABLE_REQ);
783}
784
Harald Welte6fec79d2011-02-12 14:57:17 +0100785int abis_om2k_tx_op_info(struct gsm_bts *bts, const struct abis_om2k_mo *mo,
786 uint8_t operational)
Harald Welte9a311ec2011-02-12 12:33:06 +0100787{
788 struct msgb *msg = om2k_msgb_alloc();
789 struct abis_om2k_hdr *o2k;
790
791 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
Harald Welte1164dce2011-03-05 19:21:26 +0100792 fill_om2k_hdr(o2k, mo, OM2K_MSGT_OP_INFO);
Harald Welte9a311ec2011-02-12 12:33:06 +0100793
794 msgb_tv_put(msg, OM2K_DEI_OP_INFO, operational);
795
Harald Welte73541072011-02-12 13:44:14 +0100796 DEBUGP(DNM, "Tx MO=%s %s\n", om2k_mo_name(mo),
797 get_value_string(om2k_msgcode_vals, OM2K_MSGT_OP_INFO));
798
Harald Weltebc867d92011-02-12 13:09:38 +0100799 return abis_om2k_sendmsg(bts, msg);
Harald Welte9a311ec2011-02-12 12:33:06 +0100800}
801
Harald Welte8bcb1a02011-02-12 20:23:40 +0100802int abis_om2k_tx_is_conf_req(struct gsm_bts *bts, struct om2k_is_conn_grp *cg,
803 unsigned int num_cg )
804{
805 struct msgb *msg = om2k_msgb_alloc();
806 struct abis_om2k_hdr *o2k;
807
808 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
Harald Welte1164dce2011-03-05 19:21:26 +0100809 fill_om2k_hdr(o2k, &om2k_mo_is, OM2K_MSGT_IS_CONF_REQ);
Harald Welte8bcb1a02011-02-12 20:23:40 +0100810
811 msgb_tv_put(msg, OM2K_DEI_LIST_NR, 1);
812 msgb_tv_put(msg, OM2K_DEI_END_LIST_NR, 1);
813
814 msgb_tlv_put(msg, OM2K_DEI_IS_CONN_LIST,
815 num_cg * sizeof(*cg), (uint8_t *)cg);
816
817 return abis_om2k_sendmsg(bts, msg);
818}
819
Harald Weltefdb71942011-02-14 15:31:43 +0100820int abis_om2k_tx_con_conf_req(struct gsm_bts *bts, uint8_t *data,
821 unsigned int len)
822{
823 struct msgb *msg = om2k_msgb_alloc();
824 struct abis_om2k_hdr *o2k;
825
826 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
Harald Welte1164dce2011-03-05 19:21:26 +0100827 fill_om2k_hdr(o2k, &om2k_mo_con, OM2K_MSGT_CON_CONF_REQ);
Harald Weltefdb71942011-02-14 15:31:43 +0100828
829 msgb_tv_put(msg, OM2K_DEI_LIST_NR, 1);
830 msgb_tv_put(msg, OM2K_DEI_END_LIST_NR, 1);
831
832 msgb_tlv_put(msg, OM2K_DEI_CON_CONN_LIST, len, data);
833
834 return abis_om2k_sendmsg(bts, msg);
835}
836
Harald Weltea0ce3492011-03-05 14:13:14 +0100837static void om2k_trx_to_mo(struct abis_om2k_mo *mo,
838 const struct gsm_bts_trx *trx,
839 enum abis_om2k_mo_cls cls)
840{
841 mo->class = cls;
842 mo->bts = 0;
843 mo->inst = trx->nr;
Harald Welte53492c82011-03-05 16:21:01 +0100844 mo->assoc_so = 255;
Harald Weltea0ce3492011-03-05 14:13:14 +0100845}
846
847static void om2k_ts_to_mo(struct abis_om2k_mo *mo,
848 const struct gsm_bts_trx_ts *ts)
849{
850 mo->class = OM2K_MO_CLS_TS;
851 mo->bts = 0;
852 mo->inst = ts->nr;
853 mo->assoc_so = ts->trx->nr;
854}
855
856/* Configure a Receiver MO */
857int abis_om2k_tx_rx_conf_req(struct gsm_bts_trx *trx)
858{
859 struct msgb *msg = om2k_msgb_alloc();
860 struct abis_om2k_hdr *o2k;
861 struct abis_om2k_mo mo;
862
863 om2k_trx_to_mo(&mo, trx, OM2K_MO_CLS_RX);
864
865 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
Harald Welte1164dce2011-03-05 19:21:26 +0100866 fill_om2k_hdr(o2k, &mo, OM2K_MSGT_RX_CONF_REQ);
Harald Weltea0ce3492011-03-05 14:13:14 +0100867
868 msgb_tv16_put(msg, OM2K_DEI_FREQ_SPEC_RX, trx->arfcn);
869 msgb_tv_put(msg, OM2K_DEI_RX_DIVERSITY, 0x03); /* A+B */
870
871 return abis_om2k_sendmsg(trx->bts, msg);
872}
873
874/* Configure a Transmitter MO */
875int abis_om2k_tx_tx_conf_req(struct gsm_bts_trx *trx)
876{
877 struct msgb *msg = om2k_msgb_alloc();
878 struct abis_om2k_hdr *o2k;
879 struct abis_om2k_mo mo;
880
881 om2k_trx_to_mo(&mo, trx, OM2K_MO_CLS_TX);
882
883 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
Harald Welte1164dce2011-03-05 19:21:26 +0100884 fill_om2k_hdr(o2k, &mo, OM2K_MSGT_TX_CONF_REQ);
Harald Weltea0ce3492011-03-05 14:13:14 +0100885
886 msgb_tv16_put(msg, OM2K_DEI_FREQ_SPEC_TX, trx->arfcn);
887 msgb_tv_put(msg, OM2K_DEI_POWER, trx->nominal_power-trx->max_power_red);
888 msgb_tv_put(msg, OM2K_DEI_FILLING_MARKER, 0); /* Filling enabled */
889 msgb_tv_put(msg, OM2K_DEI_BCC, trx->bts->bsic & 0x7);
890 /* Dedication Information is optional */
891
892 return abis_om2k_sendmsg(trx->bts, msg);
893}
894
Harald Weltef9cf9612011-03-05 14:36:47 +0100895enum abis_om2k_tf_mode {
896 OM2K_TF_MODE_MASTER = 0x00,
897 OM2K_TF_MODE_STANDALONE = 0x01,
898 OM2K_TF_MODE_SLAVE = 0x02,
899 OM2K_TF_MODE_UNDEFINED = 0xff,
900};
901
902static const uint8_t fs_offset_undef[5] = { 0xff, 0xff, 0xff, 0xff, 0xff };
903
904int abis_om2k_tx_tf_conf_req(struct gsm_bts *bts)
905{
906 struct msgb *msg = om2k_msgb_alloc();
907 struct abis_om2k_hdr *o2k;
908
909 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
Harald Welte1164dce2011-03-05 19:21:26 +0100910 fill_om2k_hdr(o2k, &om2k_mo_tf, OM2K_MSGT_TF_CONF_REQ);
Harald Weltef9cf9612011-03-05 14:36:47 +0100911
912 msgb_tv_put(msg, OM2K_DEI_TF_MODE, OM2K_TF_MODE_STANDALONE);
913 msgb_tv_fixed_put(msg, OM2K_DEI_FS_OFFSET,
914 sizeof(fs_offset_undef), fs_offset_undef);
915
916 return abis_om2k_sendmsg(bts, msg);
917}
918
Harald Weltea0ce3492011-03-05 14:13:14 +0100919static uint8_t pchan2comb(enum gsm_phys_chan_config pchan)
920{
921 switch (pchan) {
922 case GSM_PCHAN_CCCH:
923 return 4;
924 case GSM_PCHAN_CCCH_SDCCH4:
925 return 5;
926 case GSM_PCHAN_SDCCH8_SACCH8C:
927 return 3;
928 case GSM_PCHAN_TCH_F:
929 case GSM_PCHAN_TCH_H:
930 case GSM_PCHAN_PDCH:
931 case GSM_PCHAN_TCH_F_PDCH:
932 return 8;
933 default:
934 return 0;
935 }
936}
937
Harald Welte5748c202011-03-05 17:30:07 +0100938static int put_freq_list(uint8_t *buf, uint16_t arfcn)
939{
940 buf[0] = 0x00; /* TX/RX address */
941 buf[1] = (arfcn >> 8);
942 buf[2] = (arfcn & 0xff);
943
944 return 3;
945}
946
Harald Weltea0ce3492011-03-05 14:13:14 +0100947/* Compute a frequency list in OM2000 fomrmat */
948static int om2k_gen_freq_list(uint8_t *list, struct gsm_bts_trx_ts *ts)
949{
950 uint8_t *cur = list;
Harald Weltee6e83832011-03-05 17:52:09 +0100951 int len;
Harald Weltea0ce3492011-03-05 14:13:14 +0100952
953 if (ts->hopping.enabled) {
954 unsigned int i;
955 for (i = 0; i < ts->hopping.arfcns.data_len*8; i++) {
Harald Welte5748c202011-03-05 17:30:07 +0100956 if (bitvec_get_bit_pos(&ts->hopping.arfcns, i))
957 cur += put_freq_list(cur, i);
Harald Weltea0ce3492011-03-05 14:13:14 +0100958 }
Harald Welte5748c202011-03-05 17:30:07 +0100959 } else
960 cur += put_freq_list(cur, ts->trx->arfcn);
961
Harald Weltee6e83832011-03-05 17:52:09 +0100962 len = cur - list;
963
964 return len;
Harald Weltea0ce3492011-03-05 14:13:14 +0100965}
966
Harald Welte75755c52011-03-05 20:38:35 +0100967const uint8_t icm_bound_params[] = { 0x02, 0x06, 0x0c, 0x16, 0x06 };
968
Harald Weltea0ce3492011-03-05 14:13:14 +0100969int abis_om2k_tx_ts_conf_req(struct gsm_bts_trx_ts *ts)
970{
971 struct msgb *msg = om2k_msgb_alloc();
972 struct abis_om2k_hdr *o2k;
973 struct abis_om2k_mo mo;
974 uint8_t freq_list[64*3]; /* BA max size: 64 ARFCN */
975 int freq_list_len;
976
977 om2k_ts_to_mo(&mo, ts);
978
Harald Welte5748c202011-03-05 17:30:07 +0100979 memset(freq_list, 0, sizeof(freq_list));
Harald Weltea0ce3492011-03-05 14:13:14 +0100980 freq_list_len = om2k_gen_freq_list(freq_list, ts);
981 if (freq_list_len < 0)
982 return freq_list_len;
983
984 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
Harald Welte1164dce2011-03-05 19:21:26 +0100985 fill_om2k_hdr(o2k, &mo, OM2K_MSGT_TS_CONF_REQ);
Harald Weltea0ce3492011-03-05 14:13:14 +0100986
987 msgb_tv_put(msg, OM2K_DEI_COMBINATION, pchan2comb(ts->pchan));
988 msgb_tv_put(msg, OM2K_DEI_TS_NR, ts->nr);
989 msgb_tlv_put(msg, OM2K_DEI_FREQ_LIST, freq_list_len, freq_list);
990 msgb_tv_put(msg, OM2K_DEI_HSN, ts->hopping.hsn);
991 msgb_tv_put(msg, OM2K_DEI_MAIO, ts->hopping.maio);
992 msgb_tv_put(msg, OM2K_DEI_BSIC, ts->trx->bts->bsic);
993 msgb_tv_put(msg, OM2K_DEI_RX_DIVERSITY, 0x03); /* A+B */
994 msgb_tv16_put(msg, OM2K_DEI_FN_OFFSET, 0);
995 msgb_tv_put(msg, OM2K_DEI_EXT_RANGE, 0); /* Off */
996 /* Optional: Interference Rejection Combining */
Harald Welte1164dce2011-03-05 19:21:26 +0100997 msgb_tv_put(msg, OM2K_DEI_INTERF_REJ_COMB, 0x00);
998 switch (ts->pchan) {
999 case GSM_PCHAN_CCCH:
Harald Welte1164dce2011-03-05 19:21:26 +01001000 msgb_tv_put(msg, OM2K_DEI_BA_PA_MFRMS, 0x06);
1001 msgb_tv_put(msg, OM2K_DEI_BS_AG_BKS_RES, 0x01);
1002 msgb_tv_put(msg, OM2K_DEI_DRX_DEV_MAX, 0x05);
1003 /* Repeat Paging/IMM.ASS: True, Allow Paging Type 3: Yes, Page for 5 seconds (default) */
1004 msgb_tv_put(msg, OM2K_DEI_CCCH_OPTIONS, 0x01);
1005 break;
Harald Welte75755c52011-03-05 20:38:35 +01001006 case GSM_PCHAN_CCCH_SDCCH4:
1007 msgb_tv_put(msg, OM2K_DEI_T3105, 0x04);
1008 msgb_tv_put(msg, OM2K_DEI_NY1, 35);
1009 msgb_tv_put(msg, OM2K_DEI_BA_PA_MFRMS, 0x06);
1010 msgb_tv_put(msg, OM2K_DEI_CBCH_INDICATOR, 0);
1011 msgb_tv_put(msg, OM2K_DEI_TSC, ts->trx->bts->tsc);
1012 msgb_tv_put(msg, OM2K_DEI_BS_AG_BKS_RES, 0x01);
1013 msgb_tv_put(msg, OM2K_DEI_ICM_INDICATOR, 0);
1014 msgb_tv_put(msg, OM2K_DEI_DRX_DEV_MAX, 0x05);
1015 /* Repeat Paging/IMM.ASS: True, Allow Paging Type 3: Yes, Page for 5 seconds (default) */
1016 msgb_tv_put(msg, OM2K_DEI_CCCH_OPTIONS, 0x01);
1017 msgb_tv_fixed_put(msg, OM2K_DEI_ICM_BOUND_PARAMS,
1018 sizeof(icm_bound_params), icm_bound_params);
1019 break;
Harald Welte1164dce2011-03-05 19:21:26 +01001020 case GSM_PCHAN_SDCCH8_SACCH8C:
1021 msgb_tv_put(msg, OM2K_DEI_T3105, 0x04);
1022 msgb_tv_put(msg, OM2K_DEI_NY1, 35);
1023 msgb_tv_put(msg, OM2K_DEI_CBCH_INDICATOR, 0);
1024 msgb_tv_put(msg, OM2K_DEI_TSC, ts->trx->bts->tsc);
1025 /* Disable RF RESOURCE INDICATION on idle channels */
1026 msgb_tv_put(msg, OM2K_DEI_ICM_INDICATOR, 0);
Harald Welte75755c52011-03-05 20:38:35 +01001027 msgb_tv_fixed_put(msg, OM2K_DEI_ICM_BOUND_PARAMS,
1028 sizeof(icm_bound_params), icm_bound_params);
Harald Welte1164dce2011-03-05 19:21:26 +01001029 break;
1030 default:
1031 msgb_tv_put(msg, OM2K_DEI_T3105, 0x04);
1032 msgb_tv_put(msg, OM2K_DEI_NY1, 35);
Harald Welte1164dce2011-03-05 19:21:26 +01001033 msgb_tv_put(msg, OM2K_DEI_TSC, ts->trx->bts->tsc);
1034 /* Disable RF RESOURCE INDICATION on idle channels */
1035 msgb_tv_put(msg, OM2K_DEI_ICM_INDICATOR, 0);
Harald Welte75755c52011-03-05 20:38:35 +01001036 msgb_tv_fixed_put(msg, OM2K_DEI_ICM_BOUND_PARAMS,
1037 sizeof(icm_bound_params), icm_bound_params);
Harald Welte1164dce2011-03-05 19:21:26 +01001038 msgb_tv_put(msg, OM2K_DEI_TTA, 10); /* Timer for Time Alignment */
Harald Welte75755c52011-03-05 20:38:35 +01001039 if (ts->pchan == GSM_PCHAN_TCH_H)
1040 msgb_tv_put(msg, OM2K_DEI_ICM_CHAN_RATE, 1); /* TCH/H */
1041 else
1042 msgb_tv_put(msg, OM2K_DEI_ICM_CHAN_RATE, 0); /* TCH/F */
Harald Welte1164dce2011-03-05 19:21:26 +01001043 msgb_tv_put(msg, OM2K_DEI_LSC, 1); /* enabled */
1044 msgb_tv_put(msg, OM2K_DEI_LSC_FILT_TIME, 160); /* units of 100ms */
1045 msgb_tv_put(msg, OM2K_DEI_CALL_SUPV_TIME, 8);
1046 msgb_tv_put(msg, OM2K_DEI_ENCR_ALG, 0x00);
1047 /* FIXME: do we need 9e/9f/a0? */
1048 break;
1049 }
Harald Weltea0ce3492011-03-05 14:13:14 +01001050
1051 return abis_om2k_sendmsg(ts->trx->bts, msg);
1052}
Harald Weltefdb71942011-02-14 15:31:43 +01001053
Harald Welte6fec79d2011-02-12 14:57:17 +01001054static int abis_om2k_tx_negot_req_ack(struct gsm_bts *bts, const struct abis_om2k_mo *mo,
Harald Welte73541072011-02-12 13:44:14 +01001055 uint8_t *data, unsigned int len)
1056{
1057 struct msgb *msg = om2k_msgb_alloc();
1058 struct abis_om2k_hdr *o2k;
1059
1060 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
Harald Welte1164dce2011-03-05 19:21:26 +01001061 fill_om2k_hdr(o2k, mo, OM2K_MSGT_NEGOT_REQ_ACK);
Harald Welte73541072011-02-12 13:44:14 +01001062
1063 msgb_tlv_put(msg, OM2K_DEI_NEGOT_REC2, len, data);
1064
1065 DEBUGP(DNM, "Tx MO=%s %s\n", om2k_mo_name(mo),
1066 get_value_string(om2k_msgcode_vals, OM2K_MSGT_NEGOT_REQ_ACK));
1067
1068 return abis_om2k_sendmsg(bts, msg);
1069}
Harald Welte9a311ec2011-02-12 12:33:06 +01001070
Harald Welte563d3162011-02-12 18:11:16 +01001071struct iwd_version {
1072 uint8_t gen_char[3+1];
1073 uint8_t rev_char[3+1];
1074};
1075
1076struct iwd_type {
1077 uint8_t num_vers;
1078 struct iwd_version v[8];
1079};
1080
Harald Welte9a311ec2011-02-12 12:33:06 +01001081static int om2k_rx_negot_req(struct msgb *msg)
1082{
1083 struct abis_om2k_hdr *o2h = msgb_l2(msg);
Harald Welte563d3162011-02-12 18:11:16 +01001084 struct iwd_type iwd_types[16];
1085 uint8_t num_iwd_types = o2h->data[2];
1086 uint8_t *cur = o2h->data+3;
1087 unsigned int i, v;
Harald Welte9a311ec2011-02-12 12:33:06 +01001088
Harald Welte563d3162011-02-12 18:11:16 +01001089 uint8_t out_buf[1024];
1090 uint8_t *out_cur = out_buf+1;
1091 uint8_t out_num_types = 0;
1092
1093 memset(iwd_types, 0, sizeof(iwd_types));
1094
1095 /* Parse the RBS-supported IWD versions into iwd_types array */
1096 for (i = 0; i < num_iwd_types; i++) {
1097 uint8_t num_versions = *cur++;
1098 uint8_t iwd_type = *cur++;
1099
1100 iwd_types[iwd_type].num_vers = num_versions;
1101
1102 for (v = 0; v < num_versions; v++) {
1103 struct iwd_version *iwd_v = &iwd_types[iwd_type].v[v];
1104
1105 memcpy(iwd_v->gen_char, cur, 3);
Harald Welte56ee6b82011-02-12 18:13:37 +01001106 cur += 3;
1107 memcpy(iwd_v->rev_char, cur, 3);
1108 cur += 3;
1109
Harald Welte563d3162011-02-12 18:11:16 +01001110 DEBUGP(DNM, "\tIWD Type %u Gen %s Rev %s\n", iwd_type,
1111 iwd_v->gen_char, iwd_v->rev_char);
1112 }
1113 }
1114
1115 /* Select the last version for each IWD type */
1116 for (i = 0; i < ARRAY_SIZE(iwd_types); i++) {
1117 struct iwd_type *type = &iwd_types[i];
1118 struct iwd_version *last_v;
1119
1120 if (type->num_vers == 0)
1121 continue;
1122
1123 out_num_types++;
1124
1125 last_v = &type->v[type->num_vers-1];
1126
1127 *out_cur++ = i;
1128 memcpy(out_cur, last_v->gen_char, 3);
1129 out_cur += 3;
1130 memcpy(out_cur, last_v->rev_char, 3);
1131 out_cur += 3;
1132 }
1133
1134 out_buf[0] = out_num_types;
1135
1136 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 +01001137}
1138
1139static int om2k_rx_start_res(struct msgb *msg)
1140{
1141 struct abis_om2k_hdr *o2h = msgb_l2(msg);
1142 int rc;
1143
1144 rc = abis_om2k_tx_simple(msg->trx->bts, &o2h->mo, OM2K_MSGT_START_RES_ACK);
1145 rc = abis_om2k_tx_op_info(msg->trx->bts, &o2h->mo, 1);
1146
1147 return rc;
1148}
1149
Harald Welte0741ffe2011-02-12 18:48:53 +01001150static int om2k_rx_op_info_ack(struct msgb *msg)
Harald Welte9a311ec2011-02-12 12:33:06 +01001151{
1152 struct abis_om2k_hdr *o2h = msgb_l2(msg);
Harald Welte9a311ec2011-02-12 12:33:06 +01001153
Harald Welte0741ffe2011-02-12 18:48:53 +01001154 /* FIXME: update Operational state in our structures */
Harald Welte9a311ec2011-02-12 12:33:06 +01001155
Harald Welte0741ffe2011-02-12 18:48:53 +01001156 return 0;
Harald Welte9a311ec2011-02-12 12:33:06 +01001157}
1158
Harald Weltee6e83832011-03-05 17:52:09 +01001159const struct value_string om2k_result_strings[] = {
1160 { 0x02, "Wrong state or out of sequence" },
1161 { 0x03, "File error" },
1162 { 0x04, "Fault, unspecified" },
1163 { 0x05, "Tuning fault" },
1164 { 0x06, "Protocol error" },
1165 { 0x07, "MO not connected" },
1166 { 0x08, "Parameter error" },
1167 { 0x09, "Optional function not supported" },
1168 { 0x0a, "Local access state LOCALLY DISCONNECTED" },
1169 { 0, NULL }
1170};
1171
1172static int om2k_rx_nack(struct msgb *msg)
1173{
1174 struct abis_om2k_hdr *o2h = msgb_l2(msg);
1175 uint16_t msg_type = ntohs(o2h->msg_type);
1176 struct tlv_parsed tp;
1177
1178 LOGP(DNM, LOGL_ERROR, "Rx MO=%s %s", om2k_mo_name(&o2h->mo),
1179 get_value_string(om2k_msgcode_vals, msg_type));
1180
1181 abis_om2k_tlv_parse(&tp, o2h->data, o2h->om.length - 6);
1182 if (TLVP_PRESENT(&tp, OM2K_DEI_REASON_CODE))
1183 LOGPC(DNM, LOGL_ERROR, ", Reason 0x%02x",
1184 *TLVP_VAL(&tp, OM2K_DEI_REASON_CODE));
1185
1186 if (TLVP_PRESENT(&tp, OM2K_DEI_RESULT_CODE))
1187 LOGPC(DNM, LOGL_ERROR, ", Result %s",
1188 get_value_string(om2k_result_strings,
1189 *TLVP_VAL(&tp, OM2K_DEI_RESULT_CODE)));
1190 LOGPC(DNM, LOGL_ERROR, "\n");
1191
1192 return 0;
1193}
1194
Harald Welte9a311ec2011-02-12 12:33:06 +01001195int abis_om2k_rcvmsg(struct msgb *msg)
1196{
1197 struct gsm_bts *bts = msg->trx->bts;
1198 struct abis_om2k_hdr *o2h = msgb_l2(msg);
1199 struct abis_om_hdr *oh = &o2h->om;
Harald Weltebc867d92011-02-12 13:09:38 +01001200 uint16_t msg_type = ntohs(o2h->msg_type);
Harald Welte9a311ec2011-02-12 12:33:06 +01001201 int rc = 0;
1202
1203 /* Various consistency checks */
1204 if (oh->placement != ABIS_OM_PLACEMENT_ONLY) {
1205 LOGP(DNM, LOGL_ERROR, "ABIS OML placement 0x%x not supported\n",
1206 oh->placement);
1207 if (oh->placement != ABIS_OM_PLACEMENT_FIRST)
1208 return -EINVAL;
1209 }
1210 if (oh->sequence != 0) {
1211 LOGP(DNM, LOGL_ERROR, "ABIS OML sequence 0x%x != 0x00\n",
1212 oh->sequence);
1213 return -EINVAL;
1214 }
1215
1216 msg->l3h = (unsigned char *)o2h + sizeof(*o2h);
1217
1218 if (oh->mdisc != ABIS_OM_MDISC_FOM) {
1219 LOGP(DNM, LOGL_ERROR, "unknown ABIS OM2000 message discriminator 0x%x\n",
1220 oh->mdisc);
1221 return -EINVAL;
1222 }
1223
Harald Welte73541072011-02-12 13:44:14 +01001224 DEBUGP(DNM, "Rx MO=%s %s (%s)\n", om2k_mo_name(&o2h->mo),
Harald Weltebc867d92011-02-12 13:09:38 +01001225 get_value_string(om2k_msgcode_vals, msg_type),
Harald Welte9a311ec2011-02-12 12:33:06 +01001226 hexdump(msg->l2h, msgb_l2len(msg)));
1227
Harald Weltebc867d92011-02-12 13:09:38 +01001228 switch (msg_type) {
Harald Welte9a311ec2011-02-12 12:33:06 +01001229 case OM2K_MSGT_CAL_TIME_REQ:
1230 rc = abis_om2k_cal_time_resp(bts);
1231 break;
1232 case OM2K_MSGT_FAULT_REP:
Harald Welte9a311ec2011-02-12 12:33:06 +01001233 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_FAULT_REP_ACK);
1234 break;
1235 case OM2K_MSGT_NEGOT_REQ:
1236 rc = om2k_rx_negot_req(msg);
1237 break;
1238 case OM2K_MSGT_START_RES:
1239 rc = om2k_rx_start_res(msg);
1240 break;
Harald Welte0741ffe2011-02-12 18:48:53 +01001241 case OM2K_MSGT_OP_INFO_ACK:
1242 rc = om2k_rx_op_info_ack(msg);
Harald Welte9a311ec2011-02-12 12:33:06 +01001243 break;
1244 case OM2K_MSGT_IS_CONF_RES:
1245 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_IS_CONF_RES_ACK);
1246 break;
Harald Weltefdb71942011-02-14 15:31:43 +01001247 case OM2K_MSGT_CON_CONF_RES:
1248 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_CON_CONF_RES_ACK);
1249 break;
Harald Weltea0ce3492011-03-05 14:13:14 +01001250 case OM2K_MSGT_TX_CONF_RES:
1251 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_TX_CONF_RES_ACK);
1252 break;
1253 case OM2K_MSGT_RX_CONF_RES:
1254 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_RX_CONF_RES_ACK);
1255 break;
1256 case OM2K_MSGT_TS_CONF_RES:
1257 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_TS_CONF_RES_ACK);
1258 break;
Harald Weltef9cf9612011-03-05 14:36:47 +01001259 case OM2K_MSGT_TF_CONF_RES:
1260 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_TF_CONF_RES_ACK);
1261 break;
Harald Welte9a311ec2011-02-12 12:33:06 +01001262 case OM2K_MSGT_CONNECT_COMPL:
1263 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_RESET_CMD);
1264 break;
1265 case OM2K_MSGT_RESET_COMPL:
1266 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_START_REQ);
1267 break;
Harald Welteb3d70fd2011-02-13 12:43:44 +01001268 case OM2K_MSGT_ENABLE_RES:
1269 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_ENABLE_RES_ACK);
1270 break;
Harald Weltefdb71942011-02-14 15:31:43 +01001271 case OM2K_MSGT_DISABLE_RES:
1272 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_DISABLE_RES_ACK);
1273 break;
1274 case OM2K_MSGT_TEST_RES:
1275 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_TEST_RES_ACK);
Harald Welte9a311ec2011-02-12 12:33:06 +01001276 break;
Harald Welte0741ffe2011-02-12 18:48:53 +01001277 case OM2K_MSGT_STATUS_RESP:
1278 break;
Harald Weltefdb71942011-02-14 15:31:43 +01001279 case OM2K_MSGT_START_REQ_ACK:
1280 case OM2K_MSGT_CON_CONF_REQ_ACK:
1281 case OM2K_MSGT_IS_CONF_REQ_ACK:
Harald Weltea0ce3492011-03-05 14:13:14 +01001282 case OM2K_MSGT_TX_CONF_REQ_ACK:
1283 case OM2K_MSGT_RX_CONF_REQ_ACK:
1284 case OM2K_MSGT_TS_CONF_REQ_ACK:
Harald Weltef9cf9612011-03-05 14:36:47 +01001285 case OM2K_MSGT_TF_CONF_REQ_ACK:
Harald Weltefdb71942011-02-14 15:31:43 +01001286 case OM2K_MSGT_ENABLE_REQ_ACK:
1287 case OM2K_MSGT_ALARM_STATUS_REQ_ACK:
1288 case OM2K_MSGT_DISABLE_REQ_ACK:
1289 break;
Harald Weltee6e83832011-03-05 17:52:09 +01001290 case OM2K_MSGT_START_REQ_REJ:
Harald Welte3ede7232011-03-05 17:58:13 +01001291 case OM2K_MSGT_CONNECT_REJ:
Harald Welteaff63bc2011-03-05 19:42:16 +01001292 case OM2K_MSGT_OP_INFO_REJ:
Harald Welte3ede7232011-03-05 17:58:13 +01001293 case OM2K_MSGT_DISCONNECT_REJ:
Harald Welteaff63bc2011-03-05 19:42:16 +01001294 case OM2K_MSGT_TEST_REQ_REJ:
Harald Weltee6e83832011-03-05 17:52:09 +01001295 case OM2K_MSGT_CON_CONF_REQ_REJ:
1296 case OM2K_MSGT_IS_CONF_REQ_REJ:
1297 case OM2K_MSGT_TX_CONF_REQ_REJ:
1298 case OM2K_MSGT_RX_CONF_REQ_REJ:
1299 case OM2K_MSGT_TS_CONF_REQ_REJ:
1300 case OM2K_MSGT_TF_CONF_REQ_REJ:
1301 case OM2K_MSGT_ENABLE_REQ_REJ:
1302 case OM2K_MSGT_ALARM_STATUS_REQ_REJ:
1303 case OM2K_MSGT_DISABLE_REQ_REJ:
1304 rc = om2k_rx_nack(msg);
1305 break;
Harald Welte9a311ec2011-02-12 12:33:06 +01001306 default:
Harald Welte0741ffe2011-02-12 18:48:53 +01001307 LOGP(DNM, LOGL_NOTICE, "Rx unhandled OM2000 msg %s\n",
Harald Weltebc867d92011-02-12 13:09:38 +01001308 get_value_string(om2k_msgcode_vals, msg_type));
Harald Welte9a311ec2011-02-12 12:33:06 +01001309 }
1310
1311 msgb_free(msg);
1312 return rc;
1313}