blob: 82a14b269e38e7ab5bf5b8fd0006f173debb8fce [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
Harald Welte591e1d72016-07-09 22:20:57 +02004/* (C) 2010-2011,2016 by Harald Welte <laforge@gnumonks.org>
Harald Welte9a311ec2011-02-12 12:33:06 +01005 *
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
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010033#include <osmocom/core/msgb.h>
34#include <osmocom/gsm/tlv.h>
35#include <osmocom/core/talloc.h>
36#include <osmocom/core/utils.h>
Harald Welte591e1d72016-07-09 22:20:57 +020037#include <osmocom/core/fsm.h>
Harald Welte9a311ec2011-02-12 12:33:06 +010038
39#include <openbsc/gsm_data.h>
40#include <openbsc/debug.h>
41#include <openbsc/abis_nm.h>
Harald Welte80ccb952016-11-15 23:23:42 +010042#include <openbsc/abis_rsl.h>
Harald Welte73541072011-02-12 13:44:14 +010043#include <openbsc/abis_om2000.h>
Harald Welte9a311ec2011-02-12 12:33:06 +010044#include <openbsc/signal.h>
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +020045#include <osmocom/abis/e1_input.h>
Harald Welte9a311ec2011-02-12 12:33:06 +010046
Harald Welte591e1d72016-07-09 22:20:57 +020047/* FIXME: move to libosmocore */
48struct osmo_fsm_inst *osmo_fsm_inst_alloc_child_id(struct osmo_fsm *fsm,
49 struct osmo_fsm_inst *parent,
50 uint32_t parent_term_event,
51 const char *id)
52{
53 struct osmo_fsm_inst *fi;
54
55 fi = osmo_fsm_inst_alloc(fsm, parent, NULL, parent->log_level,
56 id ? id : parent->id);
57 if (!fi) {
58 /* indicate immediate termination to caller */
59 osmo_fsm_inst_dispatch(parent, parent_term_event, NULL);
60 return NULL;
61 }
62
63 LOGPFSM(fi, "is child of %s\n", osmo_fsm_inst_name(parent));
64
65 fi->proc.parent = parent;
66 fi->proc.parent_term_event = parent_term_event;
67 llist_add(&fi->proc.child, &parent->proc.children);
68
69 return fi;
70}
71
72
Harald Welte9a311ec2011-02-12 12:33:06 +010073#define OM_ALLOC_SIZE 1024
74#define OM_HEADROOM_SIZE 128
75
Harald Welte591e1d72016-07-09 22:20:57 +020076#define OM2K_TIMEOUT 10
77#define TRX_FSM_TIMEOUT 60
78#define BTS_FSM_TIMEOUT 60
79
Harald Welte9a311ec2011-02-12 12:33:06 +010080/* use following functions from abis_nm.c:
81 * om2k_msgb_alloc()
Harald Weltebc867d92011-02-12 13:09:38 +010082 * abis_om2k_sendmsg()
Harald Welte9a311ec2011-02-12 12:33:06 +010083 */
84
Harald Welte9a311ec2011-02-12 12:33:06 +010085struct abis_om2k_hdr {
86 struct abis_om_hdr om;
87 uint16_t msg_type;
88 struct abis_om2k_mo mo;
89 uint8_t data[0];
90} __attribute__ ((packed));
91
92enum abis_om2k_msgtype {
93 OM2K_MSGT_ABORT_SP_CMD = 0x0000,
94 OM2K_MSGT_ABORT_SP_COMPL = 0x0002,
95 OM2K_MSGT_ALARM_REP_ACK = 0x0004,
96 OM2K_MSGT_ALARM_REP_NACK = 0x0005,
97 OM2K_MSGT_ALARM_REP = 0x0006,
98 OM2K_MSGT_ALARM_STATUS_REQ = 0x0008,
99 OM2K_MSGT_ALARM_STATUS_REQ_ACK = 0x000a,
100 OM2K_MSGT_ALARM_STATUS_REQ_REJ = 0x000b,
101 OM2K_MSGT_ALARM_STATUS_RES_ACK = 0x000c,
102 OM2K_MSGT_ALARM_STATUS_RES_NACK = 0x000d,
103 OM2K_MSGT_ALARM_STATUS_RES = 0x000e,
104 OM2K_MSGT_CAL_TIME_RESP = 0x0010,
105 OM2K_MSGT_CAL_TIME_REJ = 0x0011,
106 OM2K_MSGT_CAL_TIME_REQ = 0x0012,
107
Harald Weltefdb71942011-02-14 15:31:43 +0100108 OM2K_MSGT_CON_CONF_REQ = 0x0014,
109 OM2K_MSGT_CON_CONF_REQ_ACK = 0x0016,
110 OM2K_MSGT_CON_CONF_REQ_REJ = 0x0017,
111 OM2K_MSGT_CON_CONF_RES_ACK = 0x0018,
112 OM2K_MSGT_CON_CONF_RES_NACK = 0x0019,
113 OM2K_MSGT_CON_CONF_RES = 0x001a,
114
Harald Welte9a311ec2011-02-12 12:33:06 +0100115 OM2K_MSGT_CONNECT_CMD = 0x001c,
116 OM2K_MSGT_CONNECT_COMPL = 0x001e,
117 OM2K_MSGT_CONNECT_REJ = 0x001f,
118
Harald Welte0741ffe2011-02-12 18:48:53 +0100119 OM2K_MSGT_DISABLE_REQ = 0x0028,
120 OM2K_MSGT_DISABLE_REQ_ACK = 0x002a,
121 OM2K_MSGT_DISABLE_REQ_REJ = 0x002b,
122 OM2K_MSGT_DISABLE_RES_ACK = 0x002c,
123 OM2K_MSGT_DISABLE_RES_NACK = 0x002d,
124 OM2K_MSGT_DISABLE_RES = 0x002e,
Harald Welte6fec79d2011-02-12 14:57:17 +0100125 OM2K_MSGT_DISCONNECT_CMD = 0x0030,
126 OM2K_MSGT_DISCONNECT_COMPL = 0x0032,
127 OM2K_MSGT_DISCONNECT_REJ = 0x0033,
Harald Welte0741ffe2011-02-12 18:48:53 +0100128 OM2K_MSGT_ENABLE_REQ = 0x0034,
129 OM2K_MSGT_ENABLE_REQ_ACK = 0x0036,
130 OM2K_MSGT_ENABLE_REQ_REJ = 0x0037,
131 OM2K_MSGT_ENABLE_RES_ACK = 0x0038,
132 OM2K_MSGT_ENABLE_RES_NACK = 0x0039,
133 OM2K_MSGT_ENABLE_RES = 0x003a,
Harald Welte6fec79d2011-02-12 14:57:17 +0100134
Harald Welte9a311ec2011-02-12 12:33:06 +0100135 OM2K_MSGT_FAULT_REP_ACK = 0x0040,
136 OM2K_MSGT_FAULT_REP_NACK = 0x0041,
137 OM2K_MSGT_FAULT_REP = 0x0042,
138
139 OM2K_MSGT_IS_CONF_REQ = 0x0060,
140 OM2K_MSGT_IS_CONF_REQ_ACK = 0x0062,
141 OM2K_MSGT_IS_CONF_REQ_REJ = 0x0063,
142 OM2K_MSGT_IS_CONF_RES_ACK = 0x0064,
143 OM2K_MSGT_IS_CONF_RES_NACK = 0x0065,
144 OM2K_MSGT_IS_CONF_RES = 0x0066,
145
146 OM2K_MSGT_OP_INFO = 0x0074,
147 OM2K_MSGT_OP_INFO_ACK = 0x0076,
148 OM2K_MSGT_OP_INFO_REJ = 0x0077,
149 OM2K_MSGT_RESET_CMD = 0x0078,
150 OM2K_MSGT_RESET_COMPL = 0x007a,
151 OM2K_MSGT_RESET_REJ = 0x007b,
Harald Weltea0ce3492011-03-05 14:13:14 +0100152 OM2K_MSGT_RX_CONF_REQ = 0x007c,
153 OM2K_MSGT_RX_CONF_REQ_ACK = 0x007e,
154 OM2K_MSGT_RX_CONF_REQ_REJ = 0x007f,
155 OM2K_MSGT_RX_CONF_RES_ACK = 0x0080,
156 OM2K_MSGT_RX_CONF_RES_NACK = 0x0081,
157 OM2K_MSGT_RX_CONF_RES = 0x0082,
Harald Welte9a311ec2011-02-12 12:33:06 +0100158 OM2K_MSGT_START_REQ = 0x0084,
159 OM2K_MSGT_START_REQ_ACK = 0x0086,
160 OM2K_MSGT_START_REQ_REJ = 0x0087,
161 OM2K_MSGT_START_RES_ACK = 0x0088,
162 OM2K_MSGT_START_RES_NACK = 0x0089,
163 OM2K_MSGT_START_RES = 0x008a,
Harald Weltee1d5eca2011-02-12 14:42:59 +0100164 OM2K_MSGT_STATUS_REQ = 0x008c,
165 OM2K_MSGT_STATUS_RESP = 0x008e,
166 OM2K_MSGT_STATUS_REJ = 0x008f,
Harald Welte9a311ec2011-02-12 12:33:06 +0100167
Harald Welte8024d8f2011-02-12 15:07:30 +0100168 OM2K_MSGT_TEST_REQ = 0x0094,
169 OM2K_MSGT_TEST_REQ_ACK = 0x0096,
170 OM2K_MSGT_TEST_REQ_REJ = 0x0097,
171 OM2K_MSGT_TEST_RES_ACK = 0x0098,
172 OM2K_MSGT_TEST_RES_NACK = 0x0099,
173 OM2K_MSGT_TEST_RES = 0x009a,
174
Harald Weltef9cf9612011-03-05 14:36:47 +0100175 OM2K_MSGT_TF_CONF_REQ = 0x00a0,
176 OM2K_MSGT_TF_CONF_REQ_ACK = 0x00a2,
177 OM2K_MSGT_TF_CONF_REQ_REJ = 0x00a3,
178 OM2K_MSGT_TF_CONF_RES_ACK = 0x00a4,
179 OM2K_MSGT_TF_CONF_RES_NACK = 0x00a5,
180 OM2K_MSGT_TF_CONF_RES = 0x00a6,
Harald Weltea0ce3492011-03-05 14:13:14 +0100181 OM2K_MSGT_TS_CONF_REQ = 0x00a8,
182 OM2K_MSGT_TS_CONF_REQ_ACK = 0x00aa,
183 OM2K_MSGT_TS_CONF_REQ_REJ = 0x00ab,
184 OM2K_MSGT_TS_CONF_RES_ACK = 0x00ac,
185 OM2K_MSGT_TS_CONF_RES_NACK = 0x00ad,
186 OM2K_MSGT_TS_CONF_RES = 0x00ae,
187 OM2K_MSGT_TX_CONF_REQ = 0x00b0,
188 OM2K_MSGT_TX_CONF_REQ_ACK = 0x00b2,
189 OM2K_MSGT_TX_CONF_REQ_REJ = 0x00b3,
190 OM2K_MSGT_TX_CONF_RES_ACK = 0x00b4,
191 OM2K_MSGT_TX_CONF_RES_NACK = 0x00b5,
192 OM2K_MSGT_TX_CONF_RES = 0x00b6,
193
root45799782016-10-15 21:24:57 +0200194 OM2K_MSGT_CAPA_REQ = 0x00e8,
195 OM2K_MSGT_CAPA_REQ_ACK = 0x00ea,
196 OM2K_MSGT_CAPA_REQ_REJ = 0x00eb,
197 OM2K_MSGT_CAPA_RES = 0x00ee,
198 OM2K_MSGT_CAPA_RES_ACK = 0x00ec,
199 OM2K_MSGT_CAPA_RES_NACK = 0x00ed,
200
Harald Welte9a311ec2011-02-12 12:33:06 +0100201 OM2K_MSGT_NEGOT_REQ_ACK = 0x0104,
202 OM2K_MSGT_NEGOT_REQ_NACK = 0x0105,
203 OM2K_MSGT_NEGOT_REQ = 0x0106,
204};
205
206enum abis_om2k_dei {
Harald Weltee898ecc2011-03-06 19:26:11 +0100207 OM2K_DEI_ACCORDANCE_IND = 0x00,
Harald Weltea0ce3492011-03-05 14:13:14 +0100208 OM2K_DEI_BCC = 0x06,
Harald Welte1164dce2011-03-05 19:21:26 +0100209 OM2K_DEI_BS_AG_BKS_RES = 0x07,
Harald Weltea0ce3492011-03-05 14:13:14 +0100210 OM2K_DEI_BSIC = 0x09,
Harald Welte1164dce2011-03-05 19:21:26 +0100211 OM2K_DEI_BA_PA_MFRMS = 0x0a,
212 OM2K_DEI_CBCH_INDICATOR = 0x0b,
213 OM2K_DEI_CCCH_OPTIONS = 0x0c,
Harald Welte9a311ec2011-02-12 12:33:06 +0100214 OM2K_DEI_CAL_TIME = 0x0d,
Harald Weltea0ce3492011-03-05 14:13:14 +0100215 OM2K_DEI_COMBINATION = 0x0f,
Harald Weltefdb71942011-02-14 15:31:43 +0100216 OM2K_DEI_CON_CONN_LIST = 0x10,
Harald Welte1164dce2011-03-05 19:21:26 +0100217 OM2K_DEI_DRX_DEV_MAX = 0x12,
Harald Welte8bcb1a02011-02-12 20:23:40 +0100218 OM2K_DEI_END_LIST_NR = 0x13,
Harald Weltef6d6b212011-03-05 20:13:52 +0100219 OM2K_DEI_EXT_COND_MAP_1 = 0x14,
220 OM2K_DEI_EXT_COND_MAP_2 = 0x15,
Harald Weltea0ce3492011-03-05 14:13:14 +0100221 OM2K_DEI_FILLING_MARKER = 0x1c,
222 OM2K_DEI_FN_OFFSET = 0x1d,
223 OM2K_DEI_FREQ_LIST = 0x1e,
224 OM2K_DEI_FREQ_SPEC_RX = 0x1f,
225 OM2K_DEI_FREQ_SPEC_TX = 0x20,
226 OM2K_DEI_HSN = 0x21,
Harald Welte1164dce2011-03-05 19:21:26 +0100227 OM2K_DEI_ICM_INDICATOR = 0x22,
Harald Weltef6d6b212011-03-05 20:13:52 +0100228 OM2K_DEI_INT_FAULT_MAP_1A = 0x23,
229 OM2K_DEI_INT_FAULT_MAP_1B = 0x24,
230 OM2K_DEI_INT_FAULT_MAP_2A = 0x25,
231 OM2K_DEI_INT_FAULT_MAP_2A_EXT = 0x26,
Harald Welte8bcb1a02011-02-12 20:23:40 +0100232 OM2K_DEI_IS_CONN_LIST = 0x27,
233 OM2K_DEI_LIST_NR = 0x28,
Harald Weltef6d6b212011-03-05 20:13:52 +0100234 OM2K_DEI_LOCAL_ACCESS = 0x2a,
Harald Weltea0ce3492011-03-05 14:13:14 +0100235 OM2K_DEI_MAIO = 0x2b,
Harald Weltef6d6b212011-03-05 20:13:52 +0100236 OM2K_DEI_MO_STATE = 0x2c,
Harald Welte1164dce2011-03-05 19:21:26 +0100237 OM2K_DEI_NY1 = 0x2d,
Harald Welte9a311ec2011-02-12 12:33:06 +0100238 OM2K_DEI_OP_INFO = 0x2e,
Harald Weltea0ce3492011-03-05 14:13:14 +0100239 OM2K_DEI_POWER = 0x2f,
Harald Weltee6e83832011-03-05 17:52:09 +0100240 OM2K_DEI_REASON_CODE = 0x32,
Harald Weltea0ce3492011-03-05 14:13:14 +0100241 OM2K_DEI_RX_DIVERSITY = 0x33,
Philipp8136e4b2016-10-19 10:14:35 +0200242 OM2K_DEI_REPL_UNIT_MAP = 0x34,
Harald Weltee6e83832011-03-05 17:52:09 +0100243 OM2K_DEI_RESULT_CODE = 0x35,
Harald Welte1164dce2011-03-05 19:21:26 +0100244 OM2K_DEI_T3105 = 0x38,
Harald Weltef9cf9612011-03-05 14:36:47 +0100245 OM2K_DEI_TF_MODE = 0x3a,
Harald Weltea0ce3492011-03-05 14:13:14 +0100246 OM2K_DEI_TS_NR = 0x3c,
Harald Welte1164dce2011-03-05 19:21:26 +0100247 OM2K_DEI_TSC = 0x3d,
Harald Weltef6d6b212011-03-05 20:13:52 +0100248 OM2K_DEI_BTS_VERSION = 0x40,
249 OM2K_DEI_OML_IWD_VERSION = 0x41,
250 OM2K_DEI_RSL_IWD_VERSION = 0x42,
251 OM2K_DEI_OML_FUNC_MAP_1 = 0x43,
252 OM2K_DEI_OML_FUNC_MAP_2 = 0x44,
253 OM2K_DEI_RSL_FUNC_MAP_1 = 0x45,
254 OM2K_DEI_RSL_FUNC_MAP_2 = 0x46,
Harald Weltea0ce3492011-03-05 14:13:14 +0100255 OM2K_DEI_EXT_RANGE = 0x47,
Harald Weltef6d6b212011-03-05 20:13:52 +0100256 OM2K_DEI_REQ_IND = 0x48,
Philipp8136e4b2016-10-19 10:14:35 +0200257 OM2K_DEI_REPL_UNIT_MAP_EXT = 0x50,
Harald Welte75755c52011-03-05 20:38:35 +0100258 OM2K_DEI_ICM_BOUND_PARAMS = 0x74,
Harald Welte1164dce2011-03-05 19:21:26 +0100259 OM2K_DEI_LSC = 0x79,
260 OM2K_DEI_LSC_FILT_TIME = 0x7a,
261 OM2K_DEI_CALL_SUPV_TIME = 0x7b,
Harald Welte75755c52011-03-05 20:38:35 +0100262 OM2K_DEI_ICM_CHAN_RATE = 0x7e,
Harald Weltef6d6b212011-03-05 20:13:52 +0100263 OM2K_DEI_HW_INFO_SIG = 0x84,
Harald Welteba9adbb2011-03-06 19:01:16 +0100264 OM2K_DEI_TF_SYNC_SRC = 0x86,
Harald Welte1164dce2011-03-05 19:21:26 +0100265 OM2K_DEI_TTA = 0x87,
Harald Weltef6d6b212011-03-05 20:13:52 +0100266 OM2K_DEI_CAPA_SIG = 0x8a,
Harald Welte73541072011-02-12 13:44:14 +0100267 OM2K_DEI_NEGOT_REC1 = 0x90,
268 OM2K_DEI_NEGOT_REC2 = 0x91,
Harald Welte1164dce2011-03-05 19:21:26 +0100269 OM2K_DEI_ENCR_ALG = 0x92,
270 OM2K_DEI_INTERF_REJ_COMB = 0x94,
Harald Weltef9cf9612011-03-05 14:36:47 +0100271 OM2K_DEI_FS_OFFSET = 0x98,
Harald Weltef6d6b212011-03-05 20:13:52 +0100272 OM2K_DEI_EXT_COND_MAP_2_EXT = 0x9c,
Philipp8136e4b2016-10-19 10:14:35 +0200273 OM2K_DEI_TSS_MO_STATE = 0x9d,
Harald Welte9a311ec2011-02-12 12:33:06 +0100274};
275
Harald Weltee6e83832011-03-05 17:52:09 +0100276const struct tlv_definition om2k_att_tlvdef = {
277 .def = {
Harald Weltee898ecc2011-03-06 19:26:11 +0100278 [OM2K_DEI_ACCORDANCE_IND] = { TLV_TYPE_TV },
Harald Weltee6e83832011-03-05 17:52:09 +0100279 [OM2K_DEI_BCC] = { TLV_TYPE_TV },
Harald Welte1164dce2011-03-05 19:21:26 +0100280 [OM2K_DEI_BS_AG_BKS_RES] = { TLV_TYPE_TV },
Harald Weltee6e83832011-03-05 17:52:09 +0100281 [OM2K_DEI_BSIC] = { TLV_TYPE_TV },
Harald Welte1164dce2011-03-05 19:21:26 +0100282 [OM2K_DEI_BA_PA_MFRMS] = { TLV_TYPE_TV },
283 [OM2K_DEI_CBCH_INDICATOR] = { TLV_TYPE_TV },
Harald Weltef6d6b212011-03-05 20:13:52 +0100284 [OM2K_DEI_INT_FAULT_MAP_1A] = { TLV_TYPE_FIXED, 6 },
285 [OM2K_DEI_INT_FAULT_MAP_1B] = { TLV_TYPE_FIXED, 6 },
286 [OM2K_DEI_INT_FAULT_MAP_2A] = { TLV_TYPE_FIXED, 6 },
287 [OM2K_DEI_INT_FAULT_MAP_2A_EXT]={ TLV_TYPE_FIXED, 6 },
Harald Welte1164dce2011-03-05 19:21:26 +0100288 [OM2K_DEI_CCCH_OPTIONS] = { TLV_TYPE_TV },
Harald Weltee6e83832011-03-05 17:52:09 +0100289 [OM2K_DEI_CAL_TIME] = { TLV_TYPE_FIXED, 6 },
290 [OM2K_DEI_COMBINATION] = { TLV_TYPE_TV },
291 [OM2K_DEI_CON_CONN_LIST] = { TLV_TYPE_TLV },
Harald Welte1164dce2011-03-05 19:21:26 +0100292 [OM2K_DEI_DRX_DEV_MAX] = { TLV_TYPE_TV },
Harald Weltee6e83832011-03-05 17:52:09 +0100293 [OM2K_DEI_END_LIST_NR] = { TLV_TYPE_TV },
Harald Weltef6d6b212011-03-05 20:13:52 +0100294 [OM2K_DEI_EXT_COND_MAP_1] = { TLV_TYPE_FIXED, 2 },
295 [OM2K_DEI_EXT_COND_MAP_2] = { TLV_TYPE_FIXED, 2 },
Harald Weltee6e83832011-03-05 17:52:09 +0100296 [OM2K_DEI_FILLING_MARKER] = { TLV_TYPE_TV },
297 [OM2K_DEI_FN_OFFSET] = { TLV_TYPE_FIXED, 2 },
298 [OM2K_DEI_FREQ_LIST] = { TLV_TYPE_TLV },
299 [OM2K_DEI_FREQ_SPEC_RX] = { TLV_TYPE_FIXED, 2 },
300 [OM2K_DEI_FREQ_SPEC_TX] = { TLV_TYPE_FIXED, 2 },
301 [OM2K_DEI_HSN] = { TLV_TYPE_TV },
Harald Welte1164dce2011-03-05 19:21:26 +0100302 [OM2K_DEI_ICM_INDICATOR] = { TLV_TYPE_TV },
Harald Weltee6e83832011-03-05 17:52:09 +0100303 [OM2K_DEI_IS_CONN_LIST] = { TLV_TYPE_TLV },
304 [OM2K_DEI_LIST_NR] = { TLV_TYPE_TV },
Harald Weltef6d6b212011-03-05 20:13:52 +0100305 [OM2K_DEI_LOCAL_ACCESS] = { TLV_TYPE_TV },
Harald Weltee6e83832011-03-05 17:52:09 +0100306 [OM2K_DEI_MAIO] = { TLV_TYPE_TV },
Harald Weltef6d6b212011-03-05 20:13:52 +0100307 [OM2K_DEI_MO_STATE] = { TLV_TYPE_TV },
Harald Welte1164dce2011-03-05 19:21:26 +0100308 [OM2K_DEI_NY1] = { TLV_TYPE_TV },
Harald Weltee6e83832011-03-05 17:52:09 +0100309 [OM2K_DEI_OP_INFO] = { TLV_TYPE_TV },
310 [OM2K_DEI_POWER] = { TLV_TYPE_TV },
311 [OM2K_DEI_REASON_CODE] = { TLV_TYPE_TV },
312 [OM2K_DEI_RX_DIVERSITY] = { TLV_TYPE_TV },
313 [OM2K_DEI_RESULT_CODE] = { TLV_TYPE_TV },
Harald Welte1164dce2011-03-05 19:21:26 +0100314 [OM2K_DEI_T3105] = { TLV_TYPE_TV },
Harald Weltee6e83832011-03-05 17:52:09 +0100315 [OM2K_DEI_TF_MODE] = { TLV_TYPE_TV },
316 [OM2K_DEI_TS_NR] = { TLV_TYPE_TV },
Harald Welte1164dce2011-03-05 19:21:26 +0100317 [OM2K_DEI_TSC] = { TLV_TYPE_TV },
Harald Weltef6d6b212011-03-05 20:13:52 +0100318 [OM2K_DEI_BTS_VERSION] = { TLV_TYPE_FIXED, 12 },
319 [OM2K_DEI_OML_IWD_VERSION] = { TLV_TYPE_FIXED, 6 },
320 [OM2K_DEI_RSL_IWD_VERSION] = { TLV_TYPE_FIXED, 6 },
321 [OM2K_DEI_OML_FUNC_MAP_1] = { TLV_TYPE_TLV },
322 [OM2K_DEI_OML_FUNC_MAP_2] = { TLV_TYPE_TLV },
323 [OM2K_DEI_RSL_FUNC_MAP_1] = { TLV_TYPE_TLV },
324 [OM2K_DEI_RSL_FUNC_MAP_2] = { TLV_TYPE_TLV },
Harald Weltee6e83832011-03-05 17:52:09 +0100325 [OM2K_DEI_EXT_RANGE] = { TLV_TYPE_TV },
Harald Weltef6d6b212011-03-05 20:13:52 +0100326 [OM2K_DEI_REQ_IND] = { TLV_TYPE_TV },
327 [OM2K_DEI_REPL_UNIT_MAP] = { TLV_TYPE_FIXED, 6 },
Philipp8136e4b2016-10-19 10:14:35 +0200328 [OM2K_DEI_REPL_UNIT_MAP_EXT] = {TLV_TYPE_FIXED, 6},
Harald Welte75755c52011-03-05 20:38:35 +0100329 [OM2K_DEI_ICM_BOUND_PARAMS] = { TLV_TYPE_FIXED, 5 },
Harald Welte1164dce2011-03-05 19:21:26 +0100330 [OM2K_DEI_LSC] = { TLV_TYPE_TV },
331 [OM2K_DEI_LSC_FILT_TIME] = { TLV_TYPE_TV },
332 [OM2K_DEI_CALL_SUPV_TIME] = { TLV_TYPE_TV },
Harald Welte75755c52011-03-05 20:38:35 +0100333 [OM2K_DEI_ICM_CHAN_RATE] = { TLV_TYPE_TV },
Harald Weltef6d6b212011-03-05 20:13:52 +0100334 [OM2K_DEI_HW_INFO_SIG] = { TLV_TYPE_FIXED, 2 },
Harald Welteba9adbb2011-03-06 19:01:16 +0100335 [OM2K_DEI_TF_SYNC_SRC] = { TLV_TYPE_TV },
Harald Welte1164dce2011-03-05 19:21:26 +0100336 [OM2K_DEI_TTA] = { TLV_TYPE_TV },
Harald Weltef6d6b212011-03-05 20:13:52 +0100337 [OM2K_DEI_CAPA_SIG] = { TLV_TYPE_FIXED, 2 },
Harald Weltee6e83832011-03-05 17:52:09 +0100338 [OM2K_DEI_NEGOT_REC1] = { TLV_TYPE_TLV },
339 [OM2K_DEI_NEGOT_REC2] = { TLV_TYPE_TLV },
Harald Welte1164dce2011-03-05 19:21:26 +0100340 [OM2K_DEI_ENCR_ALG] = { TLV_TYPE_TV },
341 [OM2K_DEI_INTERF_REJ_COMB] = { TLV_TYPE_TV },
Harald Weltee6e83832011-03-05 17:52:09 +0100342 [OM2K_DEI_FS_OFFSET] = { TLV_TYPE_FIXED, 5 },
Harald Weltef6d6b212011-03-05 20:13:52 +0100343 [OM2K_DEI_EXT_COND_MAP_2_EXT] = { TLV_TYPE_FIXED, 4 },
Philipp8136e4b2016-10-19 10:14:35 +0200344 [OM2K_DEI_TSS_MO_STATE] = { TLV_TYPE_FIXED, 4 },
Harald Weltee6e83832011-03-05 17:52:09 +0100345 },
346};
347
Harald Welte9a311ec2011-02-12 12:33:06 +0100348static const struct value_string om2k_msgcode_vals[] = {
349 { 0x0000, "Abort SP Command" },
350 { 0x0002, "Abort SP Complete" },
351 { 0x0004, "Alarm Report ACK" },
352 { 0x0005, "Alarm Report NACK" },
353 { 0x0006, "Alarm Report" },
354 { 0x0008, "Alarm Status Request" },
355 { 0x000a, "Alarm Status Request Accept" },
356 { 0x000b, "Alarm Status Request Reject" },
357 { 0x000c, "Alarm Status Result ACK" },
358 { 0x000d, "Alarm Status Result NACK" },
359 { 0x000e, "Alarm Status Result" },
360 { 0x0010, "Calendar Time Response" },
361 { 0x0011, "Calendar Time Reject" },
362 { 0x0012, "Calendar Time Request" },
363 { 0x0014, "CON Configuration Request" },
364 { 0x0016, "CON Configuration Request Accept" },
365 { 0x0017, "CON Configuration Request Reject" },
366 { 0x0018, "CON Configuration Result ACK" },
367 { 0x0019, "CON Configuration Result NACK" },
368 { 0x001a, "CON Configuration Result" },
369 { 0x001c, "Connect Command" },
370 { 0x001e, "Connect Complete" },
Harald Welte3ede7232011-03-05 17:58:13 +0100371 { 0x001f, "Connect Reject" },
Harald Welte9a311ec2011-02-12 12:33:06 +0100372 { 0x0028, "Disable Request" },
373 { 0x002a, "Disable Request Accept" },
374 { 0x002b, "Disable Request Reject" },
375 { 0x002c, "Disable Result ACK" },
376 { 0x002d, "Disable Result NACK" },
377 { 0x002e, "Disable Result" },
378 { 0x0030, "Disconnect Command" },
379 { 0x0032, "Disconnect Complete" },
380 { 0x0033, "Disconnect Reject" },
381 { 0x0034, "Enable Request" },
382 { 0x0036, "Enable Request Accept" },
383 { 0x0037, "Enable Request Reject" },
384 { 0x0038, "Enable Result ACK" },
385 { 0x0039, "Enable Result NACK" },
386 { 0x003a, "Enable Result" },
387 { 0x003c, "Escape Downlink Normal" },
388 { 0x003d, "Escape Downlink NACK" },
389 { 0x003e, "Escape Uplink Normal" },
390 { 0x003f, "Escape Uplink NACK" },
391 { 0x0040, "Fault Report ACK" },
392 { 0x0041, "Fault Report NACK" },
393 { 0x0042, "Fault Report" },
394 { 0x0044, "File Package End Command" },
395 { 0x0046, "File Package End Result" },
396 { 0x0047, "File Package End Reject" },
397 { 0x0048, "File Relation Request" },
398 { 0x004a, "File Relation Response" },
399 { 0x004b, "File Relation Request Reject" },
400 { 0x004c, "File Segment Transfer" },
401 { 0x004e, "File Segment Transfer Complete" },
402 { 0x004f, "File Segment Transfer Reject" },
403 { 0x0050, "HW Information Request" },
404 { 0x0052, "HW Information Request Accept" },
405 { 0x0053, "HW Information Request Reject" },
406 { 0x0054, "HW Information Result ACK" },
407 { 0x0055, "HW Information Result NACK" },
408 { 0x0056, "HW Information Result" },
409 { 0x0060, "IS Configuration Request" },
410 { 0x0062, "IS Configuration Request Accept" },
411 { 0x0063, "IS Configuration Request Reject" },
412 { 0x0064, "IS Configuration Result ACK" },
413 { 0x0065, "IS Configuration Result NACK" },
414 { 0x0066, "IS Configuration Result" },
415 { 0x0068, "Load Data End" },
416 { 0x006a, "Load Data End Result" },
417 { 0x006b, "Load Data End Reject" },
418 { 0x006c, "Load Data Init" },
419 { 0x006e, "Load Data Init Accept" },
420 { 0x006f, "Load Data Init Reject" },
421 { 0x0070, "Loop Control Command" },
422 { 0x0072, "Loop Control Complete" },
423 { 0x0073, "Loop Control Reject" },
424 { 0x0074, "Operational Information" },
425 { 0x0076, "Operational Information Accept" },
426 { 0x0077, "Operational Information Reject" },
427 { 0x0078, "Reset Command" },
428 { 0x007a, "Reset Complete" },
429 { 0x007b, "Reset Reject" },
430 { 0x007c, "RX Configuration Request" },
431 { 0x007e, "RX Configuration Request Accept" },
432 { 0x007f, "RX Configuration Request Reject" },
433 { 0x0080, "RX Configuration Result ACK" },
434 { 0x0081, "RX Configuration Result NACK" },
435 { 0x0082, "RX Configuration Result" },
436 { 0x0084, "Start Request" },
437 { 0x0086, "Start Request Accept" },
438 { 0x0087, "Start Request Reject" },
439 { 0x0088, "Start Result ACK" },
440 { 0x0089, "Start Result NACK" },
441 { 0x008a, "Start Result" },
442 { 0x008c, "Status Request" },
443 { 0x008e, "Status Response" },
444 { 0x008f, "Status Reject" },
445 { 0x0094, "Test Request" },
446 { 0x0096, "Test Request Accept" },
447 { 0x0097, "Test Request Reject" },
448 { 0x0098, "Test Result ACK" },
449 { 0x0099, "Test Result NACK" },
450 { 0x009a, "Test Result" },
451 { 0x00a0, "TF Configuration Request" },
452 { 0x00a2, "TF Configuration Request Accept" },
453 { 0x00a3, "TF Configuration Request Reject" },
454 { 0x00a4, "TF Configuration Result ACK" },
455 { 0x00a5, "TF Configuration Result NACK" },
456 { 0x00a6, "TF Configuration Result" },
457 { 0x00a8, "TS Configuration Request" },
458 { 0x00aa, "TS Configuration Request Accept" },
459 { 0x00ab, "TS Configuration Request Reject" },
460 { 0x00ac, "TS Configuration Result ACK" },
461 { 0x00ad, "TS Configuration Result NACK" },
462 { 0x00ae, "TS Configuration Result" },
463 { 0x00b0, "TX Configuration Request" },
464 { 0x00b2, "TX Configuration Request Accept" },
465 { 0x00b3, "TX Configuration Request Reject" },
466 { 0x00b4, "TX Configuration Result ACK" },
467 { 0x00b5, "TX Configuration Result NACK" },
468 { 0x00b6, "TX Configuration Result" },
469 { 0x00bc, "DIP Alarm Report ACK" },
470 { 0x00bd, "DIP Alarm Report NACK" },
471 { 0x00be, "DIP Alarm Report" },
472 { 0x00c0, "DIP Alarm Status Request" },
473 { 0x00c2, "DIP Alarm Status Response" },
474 { 0x00c3, "DIP Alarm Status Reject" },
475 { 0x00c4, "DIP Quality Report I ACK" },
476 { 0x00c5, "DIP Quality Report I NACK" },
477 { 0x00c6, "DIP Quality Report I" },
478 { 0x00c8, "DIP Quality Report II ACK" },
479 { 0x00c9, "DIP Quality Report II NACK" },
480 { 0x00ca, "DIP Quality Report II" },
481 { 0x00dc, "DP Configuration Request" },
482 { 0x00de, "DP Configuration Request Accept" },
483 { 0x00df, "DP Configuration Request Reject" },
484 { 0x00e0, "DP Configuration Result ACK" },
485 { 0x00e1, "DP Configuration Result NACK" },
486 { 0x00e2, "DP Configuration Result" },
487 { 0x00e4, "Capabilities HW Info Report ACK" },
488 { 0x00e5, "Capabilities HW Info Report NACK" },
489 { 0x00e6, "Capabilities HW Info Report" },
490 { 0x00e8, "Capabilities Request" },
491 { 0x00ea, "Capabilities Request Accept" },
492 { 0x00eb, "Capabilities Request Reject" },
493 { 0x00ec, "Capabilities Result ACK" },
494 { 0x00ed, "Capabilities Result NACK" },
495 { 0x00ee, "Capabilities Result" },
496 { 0x00f0, "FM Configuration Request" },
497 { 0x00f2, "FM Configuration Request Accept" },
498 { 0x00f3, "FM Configuration Request Reject" },
499 { 0x00f4, "FM Configuration Result ACK" },
500 { 0x00f5, "FM Configuration Result NACK" },
501 { 0x00f6, "FM Configuration Result" },
502 { 0x00f8, "FM Report Request" },
503 { 0x00fa, "FM Report Response" },
504 { 0x00fb, "FM Report Reject" },
505 { 0x00fc, "FM Start Command" },
506 { 0x00fe, "FM Start Complete" },
507 { 0x00ff, "FM Start Reject" },
508 { 0x0100, "FM Stop Command" },
509 { 0x0102, "FM Stop Complete" },
510 { 0x0103, "FM Stop Reject" },
511 { 0x0104, "Negotiation Request ACK" },
512 { 0x0105, "Negotiation Request NACK" },
513 { 0x0106, "Negotiation Request" },
514 { 0x0108, "BTS Initiated Request ACK" },
515 { 0x0109, "BTS Initiated Request NACK" },
516 { 0x010a, "BTS Initiated Request" },
517 { 0x010c, "Radio Channels Release Command" },
518 { 0x010e, "Radio Channels Release Complete" },
519 { 0x010f, "Radio Channels Release Reject" },
520 { 0x0118, "Feature Control Command" },
521 { 0x011a, "Feature Control Complete" },
522 { 0x011b, "Feature Control Reject" },
523
524 { 0, NULL }
525};
526
527/* TS 12.21 Section 9.4: Attributes */
528static const struct value_string om2k_attr_vals[] = {
529 { 0x00, "Accordance indication" },
530 { 0x01, "Alarm Id" },
531 { 0x02, "Alarm Data" },
532 { 0x03, "Alarm Severity" },
533 { 0x04, "Alarm Status" },
534 { 0x05, "Alarm Status Type" },
535 { 0x06, "BCC" },
536 { 0x07, "BS_AG_BKS_RES" },
537 { 0x09, "BSIC" },
538 { 0x0a, "BA_PA_MFRMS" },
539 { 0x0b, "CBCH Indicator" },
540 { 0x0c, "CCCH Options" },
541 { 0x0d, "Calendar Time" },
542 { 0x0f, "Channel Combination" },
543 { 0x10, "CON Connection List" },
544 { 0x11, "Data End Indication" },
545 { 0x12, "DRX_DEV_MAX" },
546 { 0x13, "End List Number" },
547 { 0x14, "External Condition Map Class 1" },
548 { 0x15, "External Condition Map Class 2" },
549 { 0x16, "File Relation Indication" },
550 { 0x17, "File Revision" },
551 { 0x18, "File Segment Data" },
552 { 0x19, "File Segment Length" },
553 { 0x1a, "File Segment Sequence Number" },
554 { 0x1b, "File Size" },
555 { 0x1c, "Filling Marker" },
556 { 0x1d, "FN Offset" },
557 { 0x1e, "Frequency List" },
558 { 0x1f, "Frequency Specifier RX" },
559 { 0x20, "Frequency Specifier TX" },
560 { 0x21, "HSN" },
561 { 0x22, "ICM Indicator" },
562 { 0x23, "Internal Fault Map Class 1A" },
563 { 0x24, "Internal Fault Map Class 1B" },
564 { 0x25, "Internal Fault Map Class 2A" },
565 { 0x26, "Internal Fault Map Class 2A Extension" },
566 { 0x27, "IS Connection List" },
567 { 0x28, "List Number" },
568 { 0x29, "File Package State Indication" },
569 { 0x2a, "Local Access State" },
570 { 0x2b, "MAIO" },
571 { 0x2c, "MO State" },
572 { 0x2d, "Ny1" },
573 { 0x2e, "Operational Information" },
574 { 0x2f, "Power" },
575 { 0x30, "RU Position Data" },
576 { 0x31, "Protocol Error" },
577 { 0x32, "Reason Code" },
578 { 0x33, "Receiver Diversity" },
579 { 0x34, "Replacement Unit Map" },
580 { 0x35, "Result Code" },
581 { 0x36, "RU Revision Data" },
582 { 0x38, "T3105" },
583 { 0x39, "Test Loop Setting" },
584 { 0x3a, "TF Mode" },
585 { 0x3b, "TF Compensation Value" },
586 { 0x3c, "Time Slot Number" },
587 { 0x3d, "TSC" },
588 { 0x3e, "RU Logical Id" },
589 { 0x3f, "RU Serial Number Data" },
590 { 0x40, "BTS Version" },
591 { 0x41, "OML IWD Version" },
592 { 0x42, "RWL IWD Version" },
593 { 0x43, "OML Function Map 1" },
594 { 0x44, "OML Function Map 2" },
595 { 0x45, "RSL Function Map 1" },
596 { 0x46, "RSL Function Map 2" },
597 { 0x47, "Extended Range Indicator" },
598 { 0x48, "Request Indicators" },
599 { 0x49, "DIP Alarm Condition Map" },
600 { 0x4a, "ES Incoming" },
601 { 0x4b, "ES Outgoing" },
602 { 0x4e, "SES Incoming" },
603 { 0x4f, "SES Outgoing" },
604 { 0x50, "Replacement Unit Map Extension" },
605 { 0x52, "UAS Incoming" },
606 { 0x53, "UAS Outgoing" },
607 { 0x58, "DF Incoming" },
608 { 0x5a, "DF Outgoing" },
609 { 0x5c, "SF" },
610 { 0x60, "S Bits Setting" },
611 { 0x61, "CRC-4 Use Option" },
612 { 0x62, "T Parameter" },
613 { 0x63, "N Parameter" },
614 { 0x64, "N1 Parameter" },
615 { 0x65, "N3 Parameter" },
616 { 0x66, "N4 Parameter" },
617 { 0x67, "P Parameter" },
618 { 0x68, "Q Parameter" },
619 { 0x69, "BI_Q1" },
620 { 0x6a, "BI_Q2" },
621 { 0x74, "ICM Boundary Parameters" },
622 { 0x77, "AFT" },
623 { 0x78, "AFT RAI" },
624 { 0x79, "Link Supervision Control" },
625 { 0x7a, "Link Supervision Filtering Time" },
626 { 0x7b, "Call Supervision Time" },
627 { 0x7c, "Interval Length UAS Incoming" },
628 { 0x7d, "Interval Length UAS Outgoing" },
629 { 0x7e, "ICM Channel Rate" },
630 { 0x7f, "Attribute Identifier" },
631 { 0x80, "FM Frequency List" },
632 { 0x81, "FM Frequency Report" },
633 { 0x82, "FM Percentile" },
634 { 0x83, "FM Clear Indication" },
635 { 0x84, "HW Info Signature" },
636 { 0x85, "MO Record" },
637 { 0x86, "TF Synchronisation Source" },
638 { 0x87, "TTA" },
639 { 0x88, "End Segment Number" },
640 { 0x89, "Segment Number" },
641 { 0x8a, "Capabilities Signature" },
642 { 0x8c, "File Relation List" },
643 { 0x90, "Negotiation Record I" },
644 { 0x91, "Negotiation Record II" },
645 { 0x92, "Encryption Algorithm" },
646 { 0x94, "Interference Rejection Combining" },
647 { 0x95, "Dedication Information" },
648 { 0x97, "Feature Code" },
649 { 0x98, "FS Offset" },
650 { 0x99, "ESB Timeslot" },
651 { 0x9a, "Master TG Instance" },
652 { 0x9b, "Master TX Chain Delay" },
653 { 0x9c, "External Condition Class 2 Extension" },
654 { 0x9d, "TSs MO State" },
655 { 0, NULL }
656};
657
Harald Weltee1d5eca2011-02-12 14:42:59 +0100658const struct value_string om2k_mo_class_short_vals[] = {
Harald Welte9a311ec2011-02-12 12:33:06 +0100659 { 0x01, "TRXC" },
660 { 0x03, "TS" },
661 { 0x04, "TF" },
662 { 0x05, "IS" },
663 { 0x06, "CON" },
664 { 0x07, "DP" },
665 { 0x0a, "CF" },
666 { 0x0b, "TX" },
667 { 0x0c, "RX" },
668 { 0, NULL }
669};
670
Harald Welte591e1d72016-07-09 22:20:57 +0200671const struct value_string om2k_result_strings[] = {
672 { 0x02, "Wrong state or out of sequence" },
673 { 0x03, "File error" },
674 { 0x04, "Fault, unspecified" },
675 { 0x05, "Tuning fault" },
676 { 0x06, "Protocol error" },
677 { 0x07, "MO not connected" },
678 { 0x08, "Parameter error" },
679 { 0x09, "Optional function not supported" },
680 { 0x0a, "Local access state LOCALLY DISCONNECTED" },
681 { 0, NULL }
682};
683
684const struct value_string om2k_accordance_strings[] = {
685 { 0x00, "Data according to request" },
686 { 0x01, "Data not according to request" },
687 { 0x02, "Inconsistent MO data" },
688 { 0x03, "Capability constraint violation" },
689 { 0, NULL }
690};
691
692const struct value_string om2k_mostate_vals[] = {
693 { 0x00, "RESET" },
694 { 0x01, "STARTED" },
695 { 0x02, "ENABLED" },
696 { 0x03, "DISABLED" },
697 { 0, NULL }
698};
699
700/* entire decoded OM2K message (header + parsed TLV) */
701struct om2k_decoded_msg {
702 struct abis_om2k_hdr o2h;
703 uint16_t msg_type;
704 struct tlv_parsed tp;
705};
706
707/* resolve the OM2000 Managed Object by BTS + MO Address */
708static struct om2k_mo *
709get_om2k_mo(struct gsm_bts *bts, const struct abis_om2k_mo *abis_mo)
710{
711 struct om2k_mo *mo = NULL;
712 struct gsm_bts_trx *trx;
713
714 switch (abis_mo->class) {
715 case OM2K_MO_CLS_CF:
716 mo = &bts->rbs2000.cf.om2k_mo;
717 break;
718 case OM2K_MO_CLS_CON:
719 mo = &bts->rbs2000.con.om2k_mo;
720 break;
721 case OM2K_MO_CLS_IS:
722 mo = &bts->rbs2000.is.om2k_mo;
723 break;
724 case OM2K_MO_CLS_TF:
725 mo = &bts->rbs2000.tf.om2k_mo;
726 break;
727
728 case OM2K_MO_CLS_TRXC:
729 trx = gsm_bts_trx_num(bts, abis_mo->inst);
730 if (!trx)
731 return NULL;
732 mo = &trx->rbs2000.trxc.om2k_mo;
733 break;
734 case OM2K_MO_CLS_TX:
735 trx = gsm_bts_trx_num(bts, abis_mo->inst);
736 if (!trx)
737 return NULL;
738 mo = &trx->rbs2000.tx.om2k_mo;
739 break;
740 case OM2K_MO_CLS_RX:
741 trx = gsm_bts_trx_num(bts, abis_mo->inst);
742 if (!trx)
743 return NULL;
744 mo = &trx->rbs2000.rx.om2k_mo;
745 break;
746 case OM2K_MO_CLS_TS:
747 trx = gsm_bts_trx_num(bts, abis_mo->assoc_so);
748 if (!trx)
749 return NULL;
750 if (abis_mo->inst >= ARRAY_SIZE(trx->ts))
751 return NULL;
752 mo = &trx->ts[abis_mo->inst].rbs2000.om2k_mo;
753 break;
754 default:
755 return NULL;
756 };
757
758 return mo;
759}
760
Harald Welte9a311ec2011-02-12 12:33:06 +0100761static struct msgb *om2k_msgb_alloc(void)
762{
763 return msgb_alloc_headroom(OM_ALLOC_SIZE, OM_HEADROOM_SIZE,
764 "OM2000");
765}
766
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200767static int abis_om2k_tlv_parse(struct tlv_parsed *tp, const uint8_t *buf, int len)
Harald Weltee6e83832011-03-05 17:52:09 +0100768{
769 return tlv_parse(tp, &om2k_att_tlvdef, buf, len, 0, 0);
770}
771
Harald Weltee898ecc2011-03-06 19:26:11 +0100772static int abis_om2k_msg_tlv_parse(struct tlv_parsed *tp, struct abis_om2k_hdr *oh)
773{
774 return abis_om2k_tlv_parse(tp, oh->data, oh->om.length - 6);
775}
776
Harald Welte591e1d72016-07-09 22:20:57 +0200777/* decode/parse the message */
778static int om2k_decode_msg(struct om2k_decoded_msg *odm, struct msgb *msg)
779{
780 struct abis_om2k_hdr *o2h = msgb_l2(msg);
781 odm->msg_type = ntohs(o2h->msg_type);
782 odm->o2h = *o2h;
783 return abis_om2k_msg_tlv_parse(&odm->tp, o2h);
784}
785
Harald Welted88a3872011-02-14 15:26:13 +0100786static char *om2k_mo_name(const struct abis_om2k_mo *mo)
787{
788 static char mo_buf[64];
789
790 memset(mo_buf, 0, sizeof(mo_buf));
791 snprintf(mo_buf, sizeof(mo_buf), "%s/%02x/%02x/%02x",
792 get_value_string(om2k_mo_class_short_vals, mo->class),
793 mo->bts, mo->assoc_so, mo->inst);
794 return mo_buf;
795}
796
Harald Welteaf9b8102011-03-06 21:20:38 +0100797/* resolve the gsm_nm_state data structure for a given MO */
798static struct gsm_nm_state *
799mo2nm_state(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
800{
801 struct gsm_bts_trx *trx;
802 struct gsm_nm_state *nm_state = NULL;
803
804 switch (mo->class) {
805 case OM2K_MO_CLS_TRXC:
Harald Welte2d027752016-11-15 22:09:08 +0100806 trx = gsm_bts_trx_num(bts, mo->inst);
Harald Welteaf9b8102011-03-06 21:20:38 +0100807 if (!trx)
808 return NULL;
Harald Welted64c0bc2011-05-30 12:07:53 +0200809 nm_state = &trx->mo.nm_state;
Harald Welteaf9b8102011-03-06 21:20:38 +0100810 break;
811 case OM2K_MO_CLS_TS:
812 trx = gsm_bts_trx_num(bts, mo->assoc_so);
813 if (!trx)
814 return NULL;
815 if (mo->inst >= ARRAY_SIZE(trx->ts))
816 return NULL;
Harald Welted64c0bc2011-05-30 12:07:53 +0200817 nm_state = &trx->ts[mo->inst].mo.nm_state;
Harald Welteaf9b8102011-03-06 21:20:38 +0100818 break;
819 case OM2K_MO_CLS_TF:
Harald Welted64c0bc2011-05-30 12:07:53 +0200820 nm_state = &bts->rbs2000.tf.mo.nm_state;
Harald Welteaf9b8102011-03-06 21:20:38 +0100821 break;
822 case OM2K_MO_CLS_IS:
Harald Welted64c0bc2011-05-30 12:07:53 +0200823 nm_state = &bts->rbs2000.is.mo.nm_state;
Harald Welteaf9b8102011-03-06 21:20:38 +0100824 break;
825 case OM2K_MO_CLS_CON:
Harald Welted64c0bc2011-05-30 12:07:53 +0200826 nm_state = &bts->rbs2000.con.mo.nm_state;
Harald Welteaf9b8102011-03-06 21:20:38 +0100827 break;
828 case OM2K_MO_CLS_DP:
Harald Welted64c0bc2011-05-30 12:07:53 +0200829 nm_state = &bts->rbs2000.con.mo.nm_state;
Harald Welteaf9b8102011-03-06 21:20:38 +0100830 break;
831 case OM2K_MO_CLS_CF:
Harald Welted64c0bc2011-05-30 12:07:53 +0200832 nm_state = &bts->mo.nm_state;
Harald Welteaf9b8102011-03-06 21:20:38 +0100833 break;
834 case OM2K_MO_CLS_TX:
Harald Welte2d027752016-11-15 22:09:08 +0100835 trx = gsm_bts_trx_num(bts, mo->inst);
Harald Welteaf9b8102011-03-06 21:20:38 +0100836 if (!trx)
837 return NULL;
Harald Welte0722ffc2016-11-15 22:58:49 +0100838 /* FIXME */
Harald Welteaf9b8102011-03-06 21:20:38 +0100839 break;
840 case OM2K_MO_CLS_RX:
Harald Welte2d027752016-11-15 22:09:08 +0100841 trx = gsm_bts_trx_num(bts, mo->inst);
Harald Welteaf9b8102011-03-06 21:20:38 +0100842 if (!trx)
843 return NULL;
Harald Welte0722ffc2016-11-15 22:58:49 +0100844 /* FIXME */
Harald Welteaf9b8102011-03-06 21:20:38 +0100845 break;
846 }
847
848 return nm_state;
849}
850
851static void *mo2obj(struct gsm_bts *bts, struct abis_om2k_mo *mo)
852{
853 struct gsm_bts_trx *trx;
854
855 switch (mo->class) {
856 case OM2K_MO_CLS_TX:
857 case OM2K_MO_CLS_RX:
858 case OM2K_MO_CLS_TRXC:
Harald Welte2d027752016-11-15 22:09:08 +0100859 return gsm_bts_trx_num(bts, mo->inst);
Harald Welteaf9b8102011-03-06 21:20:38 +0100860 case OM2K_MO_CLS_TS:
861 trx = gsm_bts_trx_num(bts, mo->assoc_so);
862 if (!trx)
863 return NULL;
864 if (mo->inst >= ARRAY_SIZE(trx->ts))
865 return NULL;
866 return &trx->ts[mo->inst];
867 case OM2K_MO_CLS_TF:
868 case OM2K_MO_CLS_IS:
869 case OM2K_MO_CLS_CON:
870 case OM2K_MO_CLS_DP:
871 case OM2K_MO_CLS_CF:
872 return bts;
873 }
874
875 return NULL;
876}
877
878static void update_mo_state(struct gsm_bts *bts, struct abis_om2k_mo *mo,
879 uint8_t mo_state)
880{
881 struct gsm_nm_state *nm_state = mo2nm_state(bts, mo);
882 struct gsm_nm_state new_state;
883 struct nm_statechg_signal_data nsd;
884
885 if (!nm_state)
886 return;
887
888 new_state = *nm_state;
889 /* NOTICE: 12.21 Availability state values != OM2000 */
890 new_state.availability = mo_state;
891
892 memset(&nsd, 0, sizeof(nsd));
893
Harald Welte8b277ac2011-03-06 23:00:32 +0100894 nsd.bts = bts;
Harald Welteaf9b8102011-03-06 21:20:38 +0100895 nsd.obj = mo2obj(bts, mo);
896 nsd.old_state = nm_state;
897 nsd.new_state = &new_state;
898 nsd.om2k_mo = mo;
899
Pablo Neira Ayusobbc5b992011-05-06 12:12:31 +0200900 osmo_signal_dispatch(SS_NM, S_NM_STATECHG_ADM, &nsd);
Harald Welteaf9b8102011-03-06 21:20:38 +0100901
902 nm_state->availability = new_state.availability;
903}
904
905static void update_op_state(struct gsm_bts *bts, const struct abis_om2k_mo *mo,
906 uint8_t op_state)
907{
908 struct gsm_nm_state *nm_state = mo2nm_state(bts, mo);
909 struct gsm_nm_state new_state;
910
911 if (!nm_state)
912 return;
913
914 new_state = *nm_state;
915 switch (op_state) {
916 case 1:
917 new_state.operational = NM_OPSTATE_ENABLED;
918 break;
919 case 0:
920 new_state.operational = NM_OPSTATE_DISABLED;
921 break;
922 default:
923 new_state.operational = NM_OPSTATE_NULL;
924 break;
925 }
926
927 nm_state->operational = new_state.operational;
928}
929
Harald Weltebc867d92011-02-12 13:09:38 +0100930static int abis_om2k_sendmsg(struct gsm_bts *bts, struct msgb *msg)
931{
Harald Welted88a3872011-02-14 15:26:13 +0100932 struct abis_om2k_hdr *o2h;
Harald Welte15eae8d2011-09-26 23:43:23 +0200933 struct gsm_bts_trx *trx;
Harald Weltebc867d92011-02-12 13:09:38 +0100934
Harald Welted88a3872011-02-14 15:26:13 +0100935 msg->l2h = msg->data;
936 o2h = (struct abis_om2k_hdr *) msg->l2h;
937
Harald Welte1164dce2011-03-05 19:21:26 +0100938 /* Compute the length in the OML header */
939 o2h->om.length = 6 + msgb_l2len(msg)-sizeof(*o2h);
940
Harald Welted88a3872011-02-14 15:26:13 +0100941 switch (o2h->mo.class) {
942 case OM2K_MO_CLS_TRXC:
943 case OM2K_MO_CLS_TX:
944 case OM2K_MO_CLS_RX:
Harald Welted88a3872011-02-14 15:26:13 +0100945 /* Route through per-TRX OML Link to the appropriate TRX */
Harald Welte15eae8d2011-09-26 23:43:23 +0200946 trx = gsm_bts_trx_by_nr(bts, o2h->mo.inst);
947 if (!trx) {
Harald Welted88a3872011-02-14 15:26:13 +0100948 LOGP(DNM, LOGL_ERROR, "MO=%s Tx Dropping msg to "
949 "non-existing TRX\n", om2k_mo_name(&o2h->mo));
950 return -ENODEV;
951 }
Harald Welte0818f312012-09-07 19:09:46 +0200952 msg->dst = trx->oml_link;
Harald Welted88a3872011-02-14 15:26:13 +0100953 break;
Harald Welte8aeac192011-03-05 20:15:09 +0100954 case OM2K_MO_CLS_TS:
955 /* Route through per-TRX OML Link to the appropriate TRX */
Harald Welte15eae8d2011-09-26 23:43:23 +0200956 trx = gsm_bts_trx_by_nr(bts, o2h->mo.assoc_so);
957 if (!trx) {
Harald Welte8aeac192011-03-05 20:15:09 +0100958 LOGP(DNM, LOGL_ERROR, "MO=%s Tx Dropping msg to "
959 "non-existing TRX\n", om2k_mo_name(&o2h->mo));
960 return -ENODEV;
961 }
Harald Welte0818f312012-09-07 19:09:46 +0200962 msg->dst = trx->oml_link;
Harald Welte8aeac192011-03-05 20:15:09 +0100963 break;
Harald Welted88a3872011-02-14 15:26:13 +0100964 default:
965 /* Route through the IXU/DXU OML Link */
Harald Welte0818f312012-09-07 19:09:46 +0200966 msg->dst = bts->oml_link;
Harald Welted88a3872011-02-14 15:26:13 +0100967 break;
968 }
969
Harald Welte15eae8d2011-09-26 23:43:23 +0200970 return _abis_nm_sendmsg(msg);
Harald Weltebc867d92011-02-12 13:09:38 +0100971}
972
Harald Welte9a311ec2011-02-12 12:33:06 +0100973static void fill_om2k_hdr(struct abis_om2k_hdr *o2h, const struct abis_om2k_mo *mo,
Harald Welte1164dce2011-03-05 19:21:26 +0100974 uint16_t msg_type)
Harald Welte9a311ec2011-02-12 12:33:06 +0100975{
976 o2h->om.mdisc = ABIS_OM_MDISC_FOM;
977 o2h->om.placement = ABIS_OM_PLACEMENT_ONLY;
978 o2h->om.sequence = 0;
Harald Welte1164dce2011-03-05 19:21:26 +0100979 /* We fill o2h->om.length later during om2k_sendmsg() */
Harald Welte9a311ec2011-02-12 12:33:06 +0100980 o2h->msg_type = htons(msg_type);
981 memcpy(&o2h->mo, mo, sizeof(o2h->mo));
982}
983
Harald Welte9a311ec2011-02-12 12:33:06 +0100984static int abis_om2k_cal_time_resp(struct gsm_bts *bts)
985{
986 struct msgb *msg = om2k_msgb_alloc();
987 struct abis_om2k_hdr *o2k;
988 time_t tm_t;
989 struct tm *tm;
990
991 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
Harald Welte591e1d72016-07-09 22:20:57 +0200992 fill_om2k_hdr(o2k, &bts->rbs2000.cf.om2k_mo.addr,
993 OM2K_MSGT_CAL_TIME_RESP);
Harald Welte9a311ec2011-02-12 12:33:06 +0100994
995 tm_t = time(NULL);
996 tm = localtime(&tm_t);
997
998 msgb_put_u8(msg, OM2K_DEI_CAL_TIME);
999 msgb_put_u8(msg, tm->tm_year % 100);
1000 msgb_put_u8(msg, tm->tm_mon + 1);
1001 msgb_put_u8(msg, tm->tm_mday);
1002 msgb_put_u8(msg, tm->tm_hour);
1003 msgb_put_u8(msg, tm->tm_min);
1004 msgb_put_u8(msg, tm->tm_sec);
1005
Harald Weltebc867d92011-02-12 13:09:38 +01001006 return abis_om2k_sendmsg(bts, msg);
Harald Welte9a311ec2011-02-12 12:33:06 +01001007}
1008
Harald Welte6fec79d2011-02-12 14:57:17 +01001009static int abis_om2k_tx_simple(struct gsm_bts *bts, const struct abis_om2k_mo *mo,
Harald Welte9a311ec2011-02-12 12:33:06 +01001010 uint8_t msg_type)
1011{
1012 struct msgb *msg = om2k_msgb_alloc();
1013 struct abis_om2k_hdr *o2k;
1014
1015 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
Harald Welte1164dce2011-03-05 19:21:26 +01001016 fill_om2k_hdr(o2k, mo, msg_type);
Harald Welte9a311ec2011-02-12 12:33:06 +01001017
Harald Welte73541072011-02-12 13:44:14 +01001018 DEBUGP(DNM, "Tx MO=%s %s\n", om2k_mo_name(mo),
1019 get_value_string(om2k_msgcode_vals, msg_type));
1020
Harald Weltebc867d92011-02-12 13:09:38 +01001021 return abis_om2k_sendmsg(bts, msg);
Harald Welte9a311ec2011-02-12 12:33:06 +01001022}
1023
Harald Welte6fec79d2011-02-12 14:57:17 +01001024int abis_om2k_tx_reset_cmd(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
Harald Welte73541072011-02-12 13:44:14 +01001025{
1026 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_RESET_CMD);
1027}
1028
Harald Welte6fec79d2011-02-12 14:57:17 +01001029int abis_om2k_tx_start_req(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
Harald Welte73541072011-02-12 13:44:14 +01001030{
1031 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_START_REQ);
1032}
1033
Harald Welte6fec79d2011-02-12 14:57:17 +01001034int abis_om2k_tx_status_req(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
Harald Weltee1d5eca2011-02-12 14:42:59 +01001035{
1036 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_STATUS_REQ);
1037}
1038
Harald Welte6fec79d2011-02-12 14:57:17 +01001039int abis_om2k_tx_connect_cmd(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
1040{
1041 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_CONNECT_CMD);
1042}
1043
1044int abis_om2k_tx_disconnect_cmd(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
1045{
1046 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_DISCONNECT_CMD);
1047}
1048
Harald Welte8024d8f2011-02-12 15:07:30 +01001049int abis_om2k_tx_test_req(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
1050{
1051 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_TEST_REQ);
1052}
1053
Harald Welte0741ffe2011-02-12 18:48:53 +01001054int abis_om2k_tx_enable_req(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
1055{
1056 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_ENABLE_REQ);
1057}
1058
1059int abis_om2k_tx_disable_req(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
1060{
1061 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_DISABLE_REQ);
1062}
1063
Harald Welte6fec79d2011-02-12 14:57:17 +01001064int abis_om2k_tx_op_info(struct gsm_bts *bts, const struct abis_om2k_mo *mo,
1065 uint8_t operational)
Harald Welte9a311ec2011-02-12 12:33:06 +01001066{
1067 struct msgb *msg = om2k_msgb_alloc();
1068 struct abis_om2k_hdr *o2k;
1069
1070 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
Harald Welte1164dce2011-03-05 19:21:26 +01001071 fill_om2k_hdr(o2k, mo, OM2K_MSGT_OP_INFO);
Harald Welte9a311ec2011-02-12 12:33:06 +01001072
1073 msgb_tv_put(msg, OM2K_DEI_OP_INFO, operational);
1074
Harald Welte73541072011-02-12 13:44:14 +01001075 DEBUGP(DNM, "Tx MO=%s %s\n", om2k_mo_name(mo),
1076 get_value_string(om2k_msgcode_vals, OM2K_MSGT_OP_INFO));
1077
Harald Welteaf9b8102011-03-06 21:20:38 +01001078 /* we update the state here... and send the signal at ACK */
1079 update_op_state(bts, mo, operational);
1080
Harald Weltebc867d92011-02-12 13:09:38 +01001081 return abis_om2k_sendmsg(bts, msg);
Harald Welte9a311ec2011-02-12 12:33:06 +01001082}
1083
root45799782016-10-15 21:24:57 +02001084int abis_om2k_tx_cap_req(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
1085{
1086 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_CAPA_REQ);
1087}
1088
Harald Welted529db62011-03-06 21:49:21 +01001089static void om2k_fill_is_conn_grp(struct om2k_is_conn_grp *grp, uint16_t icp1,
1090 uint16_t icp2, uint8_t cont_idx)
1091{
1092 grp->icp1 = htons(icp1);
1093 grp->icp2 = htons(icp2);
1094 grp->cont_idx = cont_idx;
1095}
1096
1097int abis_om2k_tx_is_conf_req(struct gsm_bts *bts)
Harald Welte8bcb1a02011-02-12 20:23:40 +01001098{
1099 struct msgb *msg = om2k_msgb_alloc();
1100 struct abis_om2k_hdr *o2k;
Harald Welted529db62011-03-06 21:49:21 +01001101 struct is_conn_group *grp;
1102 unsigned int num_grps = 0, i = 0;
1103 struct om2k_is_conn_grp *cg;
1104
1105 /* count number of groups in linked list */
1106 llist_for_each_entry(grp, &bts->rbs2000.is.conn_groups, list)
1107 num_grps++;
1108
1109 if (!num_grps)
1110 return -EINVAL;
1111
1112 /* allocate buffer for oml group array */
1113 cg = talloc_zero_array(bts, struct om2k_is_conn_grp, num_grps);
1114
1115 /* fill array with data from linked list */
1116 llist_for_each_entry(grp, &bts->rbs2000.is.conn_groups, list)
1117 om2k_fill_is_conn_grp(&cg[i++], grp->icp1, grp->icp2, grp->ci);
Harald Welte8bcb1a02011-02-12 20:23:40 +01001118
1119 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
Harald Welte591e1d72016-07-09 22:20:57 +02001120 fill_om2k_hdr(o2k, &bts->rbs2000.is.om2k_mo.addr,
1121 OM2K_MSGT_IS_CONF_REQ);
Harald Welte8bcb1a02011-02-12 20:23:40 +01001122
1123 msgb_tv_put(msg, OM2K_DEI_LIST_NR, 1);
1124 msgb_tv_put(msg, OM2K_DEI_END_LIST_NR, 1);
1125
1126 msgb_tlv_put(msg, OM2K_DEI_IS_CONN_LIST,
Harald Welted529db62011-03-06 21:49:21 +01001127 num_grps * sizeof(*cg), (uint8_t *)cg);
1128
1129 talloc_free(cg);
Harald Welte8bcb1a02011-02-12 20:23:40 +01001130
Harald Welte591e1d72016-07-09 22:20:57 +02001131 DEBUGP(DNM, "Tx MO=%s %s\n",
1132 om2k_mo_name(&bts->rbs2000.is.om2k_mo.addr),
Harald Welte79c34ff2012-09-07 20:15:50 +02001133 get_value_string(om2k_msgcode_vals, OM2K_MSGT_IS_CONF_REQ));
1134
Harald Welte8bcb1a02011-02-12 20:23:40 +01001135 return abis_om2k_sendmsg(bts, msg);
1136}
1137
Harald Welteeae68292016-11-11 19:41:59 +01001138int abis_om2k_tx_con_conf_req(struct gsm_bts *bts)
Harald Weltefdb71942011-02-14 15:31:43 +01001139{
1140 struct msgb *msg = om2k_msgb_alloc();
1141 struct abis_om2k_hdr *o2k;
Harald Welteeae68292016-11-11 19:41:59 +01001142 struct con_group *grp;
1143 unsigned int num_grps = 0;
Harald Weltefdb71942011-02-14 15:31:43 +01001144
Harald Welteeae68292016-11-11 19:41:59 +01001145 /* count number of groups in linked list */
1146 llist_for_each_entry(grp, &bts->rbs2000.con.conn_groups, list)
1147 num_grps++;
1148
1149 if (!num_grps)
1150 return -EINVAL;
1151
1152 /* first build the value part of the OM2K_DEI_CON_CONN_LIST DEI */
1153 msgb_put_u8(msg, num_grps);
1154 llist_for_each_entry(grp, &bts->rbs2000.con.conn_groups, list) {
1155 struct con_path *cp;
1156 unsigned int num_paths = 0;
1157 llist_for_each_entry(cp, &grp->paths, list)
1158 num_paths++;
1159 msgb_put_u8(msg, num_paths);
1160 llist_for_each_entry(cp, &grp->paths, list) {
1161 struct om2k_con_path *om2k_cp;
1162 om2k_cp = (struct om2k_con_path *) msgb_put(msg, sizeof(*om2k_cp));
1163 om2k_cp->ccp = htons(cp->ccp);
1164 om2k_cp->ci = cp->ci;
1165 om2k_cp->tag = cp->tag;
1166 om2k_cp->tei = cp->tei;
1167 }
1168 }
1169 msgb_push_u8(msg, msgb_length(msg));
1170 msgb_push_u8(msg, OM2K_DEI_CON_CONN_LIST);
1171
1172 /* pre-pend the list number DEIs */
1173 msgb_tv_push(msg, OM2K_DEI_END_LIST_NR, 1);
1174 msgb_tv_push(msg, OM2K_DEI_LIST_NR, 1);
1175
1176 /* pre-pend the OM2K header */
1177 o2k = (struct abis_om2k_hdr *) msgb_push(msg, sizeof(*o2k));
Harald Welte591e1d72016-07-09 22:20:57 +02001178 fill_om2k_hdr(o2k, &bts->rbs2000.con.om2k_mo.addr,
1179 OM2K_MSGT_CON_CONF_REQ);
Harald Weltefdb71942011-02-14 15:31:43 +01001180
Harald Welte591e1d72016-07-09 22:20:57 +02001181 DEBUGP(DNM, "Tx MO=%s %s\n",
1182 om2k_mo_name(&bts->rbs2000.con.om2k_mo.addr),
Harald Welte79c34ff2012-09-07 20:15:50 +02001183 get_value_string(om2k_msgcode_vals, OM2K_MSGT_CON_CONF_REQ));
1184
Harald Weltefdb71942011-02-14 15:31:43 +01001185 return abis_om2k_sendmsg(bts, msg);
1186}
1187
Harald Weltea0ce3492011-03-05 14:13:14 +01001188static void om2k_trx_to_mo(struct abis_om2k_mo *mo,
1189 const struct gsm_bts_trx *trx,
1190 enum abis_om2k_mo_cls cls)
1191{
1192 mo->class = cls;
1193 mo->bts = 0;
1194 mo->inst = trx->nr;
Harald Welte53492c82011-03-05 16:21:01 +01001195 mo->assoc_so = 255;
Harald Weltea0ce3492011-03-05 14:13:14 +01001196}
1197
1198static void om2k_ts_to_mo(struct abis_om2k_mo *mo,
1199 const struct gsm_bts_trx_ts *ts)
1200{
1201 mo->class = OM2K_MO_CLS_TS;
1202 mo->bts = 0;
1203 mo->inst = ts->nr;
1204 mo->assoc_so = ts->trx->nr;
1205}
1206
1207/* Configure a Receiver MO */
1208int abis_om2k_tx_rx_conf_req(struct gsm_bts_trx *trx)
1209{
1210 struct msgb *msg = om2k_msgb_alloc();
1211 struct abis_om2k_hdr *o2k;
1212 struct abis_om2k_mo mo;
1213
1214 om2k_trx_to_mo(&mo, trx, OM2K_MO_CLS_RX);
1215
1216 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
Harald Welte1164dce2011-03-05 19:21:26 +01001217 fill_om2k_hdr(o2k, &mo, OM2K_MSGT_RX_CONF_REQ);
Harald Weltea0ce3492011-03-05 14:13:14 +01001218
1219 msgb_tv16_put(msg, OM2K_DEI_FREQ_SPEC_RX, trx->arfcn);
Harald Welte1edc2b42011-03-06 19:01:54 +01001220 msgb_tv_put(msg, OM2K_DEI_RX_DIVERSITY, 0x02); /* A */
Harald Weltea0ce3492011-03-05 14:13:14 +01001221
1222 return abis_om2k_sendmsg(trx->bts, msg);
1223}
1224
1225/* Configure a Transmitter MO */
1226int abis_om2k_tx_tx_conf_req(struct gsm_bts_trx *trx)
1227{
1228 struct msgb *msg = om2k_msgb_alloc();
1229 struct abis_om2k_hdr *o2k;
1230 struct abis_om2k_mo mo;
1231
1232 om2k_trx_to_mo(&mo, trx, OM2K_MO_CLS_TX);
1233
1234 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
Harald Welte1164dce2011-03-05 19:21:26 +01001235 fill_om2k_hdr(o2k, &mo, OM2K_MSGT_TX_CONF_REQ);
Harald Weltea0ce3492011-03-05 14:13:14 +01001236
1237 msgb_tv16_put(msg, OM2K_DEI_FREQ_SPEC_TX, trx->arfcn);
1238 msgb_tv_put(msg, OM2K_DEI_POWER, trx->nominal_power-trx->max_power_red);
1239 msgb_tv_put(msg, OM2K_DEI_FILLING_MARKER, 0); /* Filling enabled */
1240 msgb_tv_put(msg, OM2K_DEI_BCC, trx->bts->bsic & 0x7);
1241 /* Dedication Information is optional */
1242
1243 return abis_om2k_sendmsg(trx->bts, msg);
1244}
1245
Harald Weltef9cf9612011-03-05 14:36:47 +01001246enum abis_om2k_tf_mode {
1247 OM2K_TF_MODE_MASTER = 0x00,
1248 OM2K_TF_MODE_STANDALONE = 0x01,
1249 OM2K_TF_MODE_SLAVE = 0x02,
1250 OM2K_TF_MODE_UNDEFINED = 0xff,
1251};
1252
1253static const uint8_t fs_offset_undef[5] = { 0xff, 0xff, 0xff, 0xff, 0xff };
1254
1255int abis_om2k_tx_tf_conf_req(struct gsm_bts *bts)
1256{
1257 struct msgb *msg = om2k_msgb_alloc();
1258 struct abis_om2k_hdr *o2k;
1259
1260 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
Harald Welte591e1d72016-07-09 22:20:57 +02001261 fill_om2k_hdr(o2k, &bts->rbs2000.tf.om2k_mo.addr,
1262 OM2K_MSGT_TF_CONF_REQ);
Harald Weltef9cf9612011-03-05 14:36:47 +01001263
1264 msgb_tv_put(msg, OM2K_DEI_TF_MODE, OM2K_TF_MODE_STANDALONE);
Harald Welteba9adbb2011-03-06 19:01:16 +01001265 msgb_tv_put(msg, OM2K_DEI_TF_SYNC_SRC, 0x00);
Harald Weltef9cf9612011-03-05 14:36:47 +01001266 msgb_tv_fixed_put(msg, OM2K_DEI_FS_OFFSET,
1267 sizeof(fs_offset_undef), fs_offset_undef);
1268
Harald Welte591e1d72016-07-09 22:20:57 +02001269 DEBUGP(DNM, "Tx MO=%s %s\n",
1270 om2k_mo_name(&bts->rbs2000.tf.om2k_mo.addr),
Harald Welte79c34ff2012-09-07 20:15:50 +02001271 get_value_string(om2k_msgcode_vals, OM2K_MSGT_TF_CONF_REQ));
1272
Harald Weltef9cf9612011-03-05 14:36:47 +01001273 return abis_om2k_sendmsg(bts, msg);
1274}
1275
Harald Weltea0ce3492011-03-05 14:13:14 +01001276static uint8_t pchan2comb(enum gsm_phys_chan_config pchan)
1277{
1278 switch (pchan) {
1279 case GSM_PCHAN_CCCH:
1280 return 4;
1281 case GSM_PCHAN_CCCH_SDCCH4:
1282 return 5;
1283 case GSM_PCHAN_SDCCH8_SACCH8C:
1284 return 3;
1285 case GSM_PCHAN_TCH_F:
1286 case GSM_PCHAN_TCH_H:
1287 case GSM_PCHAN_PDCH:
Harald Welte80ccb952016-11-15 23:23:42 +01001288 case GSM_PCHAN_TCH_F_PDCH:
1289 case GSM_PCHAN_TCH_F_TCH_H_PDCH:
Harald Weltea0ce3492011-03-05 14:13:14 +01001290 return 8;
1291 default:
1292 return 0;
1293 }
1294}
1295
Neels Hofmeyr23c3aa32016-09-25 15:15:59 +02001296static uint8_t ts2comb(struct gsm_bts_trx_ts *ts)
1297{
1298 switch (ts->pchan) {
1299 case GSM_PCHAN_TCH_F_PDCH:
Neels Hofmeyr87ef68e2016-11-10 02:18:00 +01001300 LOGP(DNM, LOGL_ERROR, "%s pchan %s not intended for use"
1301 " with OM2000, use %s instead\n",
1302 gsm_ts_and_pchan_name(ts),
1303 gsm_pchan_name(GSM_PCHAN_TCH_F_PDCH),
1304 gsm_pchan_name(GSM_PCHAN_TCH_F_TCH_H_PDCH));
1305 /* If we allowed initialization of TCH/F_PDCH, it would fail
1306 * when we try to send the ip.access specific RSL PDCH Act
1307 * message for it. Rather fail completely right now: */
1308 return 0;
Neels Hofmeyr23c3aa32016-09-25 15:15:59 +02001309 case GSM_PCHAN_TCH_F_TCH_H_PDCH:
Neels Hofmeyrf926f452016-10-31 18:16:34 +01001310 return pchan2comb(GSM_PCHAN_TCH_F);
Neels Hofmeyr23c3aa32016-09-25 15:15:59 +02001311 default:
1312 return pchan2comb(ts->pchan);
1313 }
1314}
1315
Harald Welte5748c202011-03-05 17:30:07 +01001316static int put_freq_list(uint8_t *buf, uint16_t arfcn)
1317{
1318 buf[0] = 0x00; /* TX/RX address */
1319 buf[1] = (arfcn >> 8);
1320 buf[2] = (arfcn & 0xff);
1321
1322 return 3;
1323}
1324
Harald Weltea0ce3492011-03-05 14:13:14 +01001325/* Compute a frequency list in OM2000 fomrmat */
1326static int om2k_gen_freq_list(uint8_t *list, struct gsm_bts_trx_ts *ts)
1327{
1328 uint8_t *cur = list;
Harald Weltee6e83832011-03-05 17:52:09 +01001329 int len;
Harald Weltea0ce3492011-03-05 14:13:14 +01001330
1331 if (ts->hopping.enabled) {
1332 unsigned int i;
1333 for (i = 0; i < ts->hopping.arfcns.data_len*8; i++) {
Harald Welte5748c202011-03-05 17:30:07 +01001334 if (bitvec_get_bit_pos(&ts->hopping.arfcns, i))
1335 cur += put_freq_list(cur, i);
Harald Weltea0ce3492011-03-05 14:13:14 +01001336 }
Harald Welte5748c202011-03-05 17:30:07 +01001337 } else
1338 cur += put_freq_list(cur, ts->trx->arfcn);
1339
Harald Weltee6e83832011-03-05 17:52:09 +01001340 len = cur - list;
1341
1342 return len;
Harald Weltea0ce3492011-03-05 14:13:14 +01001343}
1344
Harald Welte75755c52011-03-05 20:38:35 +01001345const uint8_t icm_bound_params[] = { 0x02, 0x06, 0x0c, 0x16, 0x06 };
1346
Harald Weltea0ce3492011-03-05 14:13:14 +01001347int abis_om2k_tx_ts_conf_req(struct gsm_bts_trx_ts *ts)
1348{
1349 struct msgb *msg = om2k_msgb_alloc();
1350 struct abis_om2k_hdr *o2k;
1351 struct abis_om2k_mo mo;
1352 uint8_t freq_list[64*3]; /* BA max size: 64 ARFCN */
1353 int freq_list_len;
1354
1355 om2k_ts_to_mo(&mo, ts);
1356
Harald Welte5748c202011-03-05 17:30:07 +01001357 memset(freq_list, 0, sizeof(freq_list));
Harald Weltea0ce3492011-03-05 14:13:14 +01001358 freq_list_len = om2k_gen_freq_list(freq_list, ts);
1359 if (freq_list_len < 0)
1360 return freq_list_len;
1361
1362 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
Harald Welte1164dce2011-03-05 19:21:26 +01001363 fill_om2k_hdr(o2k, &mo, OM2K_MSGT_TS_CONF_REQ);
Harald Weltea0ce3492011-03-05 14:13:14 +01001364
Neels Hofmeyr23c3aa32016-09-25 15:15:59 +02001365 msgb_tv_put(msg, OM2K_DEI_COMBINATION, ts2comb(ts));
Harald Weltea0ce3492011-03-05 14:13:14 +01001366 msgb_tv_put(msg, OM2K_DEI_TS_NR, ts->nr);
1367 msgb_tlv_put(msg, OM2K_DEI_FREQ_LIST, freq_list_len, freq_list);
1368 msgb_tv_put(msg, OM2K_DEI_HSN, ts->hopping.hsn);
1369 msgb_tv_put(msg, OM2K_DEI_MAIO, ts->hopping.maio);
1370 msgb_tv_put(msg, OM2K_DEI_BSIC, ts->trx->bts->bsic);
Harald Welte1edc2b42011-03-06 19:01:54 +01001371 msgb_tv_put(msg, OM2K_DEI_RX_DIVERSITY, 0x02); /* A */
Harald Weltea0ce3492011-03-05 14:13:14 +01001372 msgb_tv16_put(msg, OM2K_DEI_FN_OFFSET, 0);
1373 msgb_tv_put(msg, OM2K_DEI_EXT_RANGE, 0); /* Off */
1374 /* Optional: Interference Rejection Combining */
Harald Welte1164dce2011-03-05 19:21:26 +01001375 msgb_tv_put(msg, OM2K_DEI_INTERF_REJ_COMB, 0x00);
1376 switch (ts->pchan) {
1377 case GSM_PCHAN_CCCH:
Harald Welte1164dce2011-03-05 19:21:26 +01001378 msgb_tv_put(msg, OM2K_DEI_BA_PA_MFRMS, 0x06);
1379 msgb_tv_put(msg, OM2K_DEI_BS_AG_BKS_RES, 0x01);
1380 msgb_tv_put(msg, OM2K_DEI_DRX_DEV_MAX, 0x05);
1381 /* Repeat Paging/IMM.ASS: True, Allow Paging Type 3: Yes, Page for 5 seconds (default) */
1382 msgb_tv_put(msg, OM2K_DEI_CCCH_OPTIONS, 0x01);
1383 break;
Harald Welte75755c52011-03-05 20:38:35 +01001384 case GSM_PCHAN_CCCH_SDCCH4:
Harald Welte67161f22012-06-03 13:01:47 +02001385 msgb_tv_put(msg, OM2K_DEI_T3105, ts->trx->bts->network->T3105 / 10);
Harald Welte75755c52011-03-05 20:38:35 +01001386 msgb_tv_put(msg, OM2K_DEI_NY1, 35);
1387 msgb_tv_put(msg, OM2K_DEI_BA_PA_MFRMS, 0x06);
1388 msgb_tv_put(msg, OM2K_DEI_CBCH_INDICATOR, 0);
Harald Welte94bc1e02014-01-19 17:19:10 +01001389 msgb_tv_put(msg, OM2K_DEI_TSC, gsm_ts_tsc(ts));
Harald Welte75755c52011-03-05 20:38:35 +01001390 msgb_tv_put(msg, OM2K_DEI_BS_AG_BKS_RES, 0x01);
1391 msgb_tv_put(msg, OM2K_DEI_ICM_INDICATOR, 0);
1392 msgb_tv_put(msg, OM2K_DEI_DRX_DEV_MAX, 0x05);
1393 /* Repeat Paging/IMM.ASS: True, Allow Paging Type 3: Yes, Page for 5 seconds (default) */
1394 msgb_tv_put(msg, OM2K_DEI_CCCH_OPTIONS, 0x01);
1395 msgb_tv_fixed_put(msg, OM2K_DEI_ICM_BOUND_PARAMS,
1396 sizeof(icm_bound_params), icm_bound_params);
1397 break;
Harald Welte1164dce2011-03-05 19:21:26 +01001398 case GSM_PCHAN_SDCCH8_SACCH8C:
Harald Welte67161f22012-06-03 13:01:47 +02001399 msgb_tv_put(msg, OM2K_DEI_T3105, ts->trx->bts->network->T3105 / 10);
Harald Welte1164dce2011-03-05 19:21:26 +01001400 msgb_tv_put(msg, OM2K_DEI_NY1, 35);
1401 msgb_tv_put(msg, OM2K_DEI_CBCH_INDICATOR, 0);
Harald Welte94bc1e02014-01-19 17:19:10 +01001402 msgb_tv_put(msg, OM2K_DEI_TSC, gsm_ts_tsc(ts));
Harald Welte1164dce2011-03-05 19:21:26 +01001403 /* Disable RF RESOURCE INDICATION on idle channels */
1404 msgb_tv_put(msg, OM2K_DEI_ICM_INDICATOR, 0);
Harald Welte75755c52011-03-05 20:38:35 +01001405 msgb_tv_fixed_put(msg, OM2K_DEI_ICM_BOUND_PARAMS,
1406 sizeof(icm_bound_params), icm_bound_params);
Harald Welte1164dce2011-03-05 19:21:26 +01001407 break;
1408 default:
Harald Welte67161f22012-06-03 13:01:47 +02001409 msgb_tv_put(msg, OM2K_DEI_T3105, ts->trx->bts->network->T3105 / 10);
Harald Welte1164dce2011-03-05 19:21:26 +01001410 msgb_tv_put(msg, OM2K_DEI_NY1, 35);
Harald Welte94bc1e02014-01-19 17:19:10 +01001411 msgb_tv_put(msg, OM2K_DEI_TSC, gsm_ts_tsc(ts));
Harald Welte1164dce2011-03-05 19:21:26 +01001412 /* Disable RF RESOURCE INDICATION on idle channels */
1413 msgb_tv_put(msg, OM2K_DEI_ICM_INDICATOR, 0);
Harald Welte75755c52011-03-05 20:38:35 +01001414 msgb_tv_fixed_put(msg, OM2K_DEI_ICM_BOUND_PARAMS,
1415 sizeof(icm_bound_params), icm_bound_params);
Harald Welte1164dce2011-03-05 19:21:26 +01001416 msgb_tv_put(msg, OM2K_DEI_TTA, 10); /* Timer for Time Alignment */
Harald Welte75755c52011-03-05 20:38:35 +01001417 if (ts->pchan == GSM_PCHAN_TCH_H)
1418 msgb_tv_put(msg, OM2K_DEI_ICM_CHAN_RATE, 1); /* TCH/H */
1419 else
1420 msgb_tv_put(msg, OM2K_DEI_ICM_CHAN_RATE, 0); /* TCH/F */
Harald Welte1164dce2011-03-05 19:21:26 +01001421 msgb_tv_put(msg, OM2K_DEI_LSC, 1); /* enabled */
Harald Welte1edc2b42011-03-06 19:01:54 +01001422 msgb_tv_put(msg, OM2K_DEI_LSC_FILT_TIME, 10); /* units of 100ms */
Harald Welte1164dce2011-03-05 19:21:26 +01001423 msgb_tv_put(msg, OM2K_DEI_CALL_SUPV_TIME, 8);
1424 msgb_tv_put(msg, OM2K_DEI_ENCR_ALG, 0x00);
Harald Welte96638d12016-11-15 23:23:56 +01001425 /* Not sure what those below mean */
1426 msgb_tv_put(msg, 0x9e, 0x00);
1427 msgb_tv_put(msg, 0x9f, 0x37);
1428 msgb_tv_put(msg, 0xa0, 0x01);
Harald Welte1164dce2011-03-05 19:21:26 +01001429 break;
1430 }
Harald Weltea0ce3492011-03-05 14:13:14 +01001431
Harald Welte591e1d72016-07-09 22:20:57 +02001432 DEBUGP(DNM, "Tx MO=%s %s\n",
1433 om2k_mo_name(&mo),
1434 get_value_string(om2k_msgcode_vals, OM2K_MSGT_TS_CONF_REQ));
1435
Harald Weltea0ce3492011-03-05 14:13:14 +01001436 return abis_om2k_sendmsg(ts->trx->bts, msg);
1437}
Harald Weltefdb71942011-02-14 15:31:43 +01001438
Harald Welte591e1d72016-07-09 22:20:57 +02001439
1440/***********************************************************************
1441 * OM2000 Managed Object (MO) FSM
1442 ***********************************************************************/
1443
1444#define S(x) (1 << (x))
1445
1446enum om2k_event_name {
1447 OM2K_MO_EVT_START,
1448 OM2K_MO_EVT_RX_CONN_COMPL,
1449 OM2K_MO_EVT_RX_RESET_COMPL,
1450 OM2K_MO_EVT_RX_START_REQ_ACCEPT,
1451 OM2K_MO_EVT_RX_START_RES,
1452 OM2K_MO_EVT_RX_CFG_REQ_ACCEPT,
1453 OM2K_MO_EVT_RX_CFG_RES,
1454 OM2K_MO_EVT_RX_ENA_REQ_ACCEPT,
1455 OM2K_MO_EVT_RX_ENA_RES,
1456 OM2K_MO_EVT_RX_OPINFO_ACC,
1457};
1458
1459static const struct value_string om2k_event_names[] = {
1460 { OM2K_MO_EVT_START, "START" },
1461 { OM2K_MO_EVT_RX_CONN_COMPL, "RX-CONN-COMPL" },
1462 { OM2K_MO_EVT_RX_RESET_COMPL, "RX-RESET-COMPL" },
1463 { OM2K_MO_EVT_RX_START_REQ_ACCEPT, "RX-RESET-REQ-ACCEPT" },
1464 { OM2K_MO_EVT_RX_START_RES, "RX-START-RESULT" },
1465 { OM2K_MO_EVT_RX_CFG_REQ_ACCEPT, "RX-CFG-REQ-ACCEPT" },
1466 { OM2K_MO_EVT_RX_CFG_RES, "RX-CFG-RESULT" },
1467 { OM2K_MO_EVT_RX_ENA_REQ_ACCEPT, "RX-ENABLE-REQ-ACCEPT" },
1468 { OM2K_MO_EVT_RX_ENA_RES, "RX-ENABLE-RESULT" },
1469 { OM2K_MO_EVT_RX_OPINFO_ACC, "RX-OPINFO-ACCEPT" },
1470 { 0, NULL }
1471};
1472
1473enum om2k_mo_fsm_state {
1474 OM2K_ST_INIT,
1475 OM2K_ST_WAIT_CONN_COMPL,
1476 OM2K_ST_WAIT_RES_COMPL,
1477 OM2K_ST_WAIT_START_ACCEPT,
1478 OM2K_ST_WAIT_START_RES,
1479 OM2K_ST_WAIT_CFG_ACCEPT,
1480 OM2K_ST_WAIT_CFG_RES,
1481 OM2K_ST_WAIT_ENABLE_ACCEPT,
1482 OM2K_ST_WAIT_ENABLE_RES,
1483 OM2K_ST_WAIT_OPINFO_ACCEPT,
1484 OM2K_ST_DONE,
1485 OM2K_ST_ERROR,
1486};
1487
1488struct om2k_mo_fsm_priv {
1489 struct gsm_bts_trx *trx;
1490 struct om2k_mo *mo;
1491 uint8_t ts_nr;
1492};
1493
1494static void om2k_mo_st_init(struct osmo_fsm_inst *fi, uint32_t event, void *data)
1495{
1496 struct om2k_mo_fsm_priv *omfp = fi->priv;
1497
1498 OSMO_ASSERT(event == OM2K_MO_EVT_START);
1499
1500 switch (omfp->mo->addr.class) {
1501 case OM2K_MO_CLS_CF:
1502 /* no Connect required, is always connected */
1503 osmo_fsm_inst_state_chg(fi, OM2K_ST_WAIT_START_ACCEPT,
1504 OM2K_TIMEOUT, 0);
1505 abis_om2k_tx_start_req(omfp->trx->bts, &omfp->mo->addr);
1506 break;
1507 case OM2K_MO_CLS_TRXC:
1508 /* no Connect required, start with Reset */
1509 osmo_fsm_inst_state_chg(fi, OM2K_ST_WAIT_RES_COMPL,
1510 OM2K_TIMEOUT, 0);
1511 abis_om2k_tx_reset_cmd(omfp->trx->bts, &omfp->mo->addr);
1512 break;
1513 default:
1514 /* start with Connect */
1515 osmo_fsm_inst_state_chg(fi, OM2K_ST_WAIT_CONN_COMPL,
1516 OM2K_TIMEOUT, 0);
1517 abis_om2k_tx_connect_cmd(omfp->trx->bts, &omfp->mo->addr);
1518 break;
1519 }
1520}
1521
1522static void om2k_mo_st_wait_conn_compl(struct osmo_fsm_inst *fi, uint32_t event, void *data)
1523{
1524 struct om2k_mo_fsm_priv *omfp = fi->priv;
1525
1526 switch (omfp->mo->addr.class) {
1527#if 0
1528 case OM2K_MO_CLS_TF:
1529 /* skip the reset, hope that helps */
1530 osmo_fsm_inst_state_chg(fi, OM2K_ST_WAIT_START_ACCEPT,
1531 OM2K_TIMEOUT, 0);
1532 abis_om2k_tx_start_req(omfp->trx->bts, &omfp->mo->addr);
1533 break;
1534#endif
1535 default:
1536 osmo_fsm_inst_state_chg(fi, OM2K_ST_WAIT_RES_COMPL,
1537 OM2K_TIMEOUT, 0);
1538 abis_om2k_tx_reset_cmd(omfp->trx->bts, &omfp->mo->addr);
1539 break;
1540 }
1541}
1542
1543static void om2k_mo_st_wait_res_compl(struct osmo_fsm_inst *fi, uint32_t event, void *data)
1544{
1545 struct om2k_mo_fsm_priv *omfp = fi->priv;
1546
1547 osmo_fsm_inst_state_chg(fi, OM2K_ST_WAIT_START_ACCEPT,
1548 OM2K_TIMEOUT, 0);
1549 abis_om2k_tx_start_req(omfp->trx->bts, &omfp->mo->addr);
1550}
1551
1552static void om2k_mo_st_wait_start_accept(struct osmo_fsm_inst *fi, uint32_t event, void *data)
1553{
1554 struct om2k_decoded_msg *omd = data;
1555
1556 switch (omd->msg_type) {
1557 case OM2K_MSGT_START_REQ_ACK:
1558 osmo_fsm_inst_state_chg(fi, OM2K_ST_WAIT_START_RES,
1559 OM2K_TIMEOUT, 0);
1560 break;
1561 case OM2K_MSGT_START_REQ_REJ:
1562 osmo_fsm_inst_state_chg(fi, OM2K_ST_ERROR, 0, 0);
1563 break;
1564 }
1565}
1566
1567static void om2k_mo_st_wait_start_res(struct osmo_fsm_inst *fi, uint32_t event, void *data)
1568{
1569 struct om2k_mo_fsm_priv *omfp = fi->priv;
1570 struct gsm_bts_trx_ts *ts;
1571
1572 switch (omfp->mo->addr.class) {
1573 case OM2K_MO_CLS_CF:
1574 case OM2K_MO_CLS_TRXC:
1575 /* Transition directly to Operational Info */
1576 osmo_fsm_inst_state_chg(fi, OM2K_ST_WAIT_OPINFO_ACCEPT,
1577 OM2K_TIMEOUT, 0);
1578 abis_om2k_tx_op_info(omfp->trx->bts, &omfp->mo->addr, 1);
Harald Welte424656e2016-10-15 16:30:35 +02001579 return;
Harald Welte591e1d72016-07-09 22:20:57 +02001580 case OM2K_MO_CLS_DP:
1581 /* Transition directoy to WAIT_ENABLE_ACCEPT */
1582 osmo_fsm_inst_state_chg(fi, OM2K_ST_WAIT_ENABLE_ACCEPT,
1583 OM2K_TIMEOUT, 0);
1584 abis_om2k_tx_enable_req(omfp->trx->bts, &omfp->mo->addr);
1585 return;
1586#if 0
1587 case OM2K_MO_CLS_TF:
1588 /* skip the config, hope that helps speeding things up */
1589 osmo_fsm_inst_state_chg(fi, OM2K_ST_WAIT_ENABLE_ACCEPT,
1590 OM2K_TIMEOUT, 0);
1591 abis_om2k_tx_enable_req(omfp->trx->bts, &omfp->mo->addr);
1592 return;
1593#endif
1594 }
1595
1596 osmo_fsm_inst_state_chg(fi, OM2K_ST_WAIT_CFG_ACCEPT,
1597 OM2K_TIMEOUT, 0);
1598 switch (omfp->mo->addr.class) {
1599 case OM2K_MO_CLS_TF:
1600 abis_om2k_tx_tf_conf_req(omfp->trx->bts);
1601 break;
1602 case OM2K_MO_CLS_IS:
1603 abis_om2k_tx_is_conf_req(omfp->trx->bts);
1604 break;
1605 case OM2K_MO_CLS_CON:
Harald Welteeae68292016-11-11 19:41:59 +01001606 abis_om2k_tx_con_conf_req(omfp->trx->bts);
Harald Welte591e1d72016-07-09 22:20:57 +02001607 break;
1608 case OM2K_MO_CLS_TX:
1609 abis_om2k_tx_tx_conf_req(omfp->trx);
1610 break;
1611 case OM2K_MO_CLS_RX:
1612 abis_om2k_tx_rx_conf_req(omfp->trx);
1613 break;
1614 case OM2K_MO_CLS_TS:
1615 ts = mo2obj(omfp->trx->bts, &omfp->mo->addr);
1616 abis_om2k_tx_ts_conf_req(ts);
1617 break;
1618 }
1619}
1620
1621static void om2k_mo_st_wait_cfg_accept(struct osmo_fsm_inst *fi, uint32_t event, void *data)
1622{
1623 struct om2k_mo_fsm_priv *omfp = fi->priv;
1624 uint32_t timeout = OM2K_TIMEOUT;
1625
1626 if (omfp->mo->addr.class == OM2K_MO_CLS_TF)
1627 timeout = 600;
1628
1629 osmo_fsm_inst_state_chg(fi, OM2K_ST_WAIT_CFG_RES, timeout, 0);
1630}
1631
1632static void om2k_mo_st_wait_cfg_res(struct osmo_fsm_inst *fi, uint32_t event, void *data)
1633{
1634 struct om2k_mo_fsm_priv *omfp = fi->priv;
1635 struct om2k_decoded_msg *omd = data;
1636 uint8_t accordance;
1637
1638 if (!TLVP_PRESENT(&omd->tp, OM2K_DEI_ACCORDANCE_IND)) {
1639 osmo_fsm_inst_state_chg(fi, OM2K_ST_ERROR, 0, 0);
1640 return;
1641 }
1642 accordance = *TLVP_VAL(&omd->tp, OM2K_DEI_ACCORDANCE_IND);
1643
1644 if (accordance != 0) {
1645 /* accordance not OK */
1646 osmo_fsm_inst_state_chg(fi, OM2K_ST_ERROR, 0, 0);
1647 return;
1648 }
1649
1650 osmo_fsm_inst_state_chg(fi, OM2K_ST_WAIT_ENABLE_ACCEPT,
1651 OM2K_TIMEOUT, 0);
1652 abis_om2k_tx_enable_req(omfp->trx->bts, &omfp->mo->addr);
1653}
1654
1655static void om2k_mo_st_wait_enable_accept(struct osmo_fsm_inst *fi, uint32_t event, void *data)
1656{
Harald Weltece492582016-11-15 22:59:24 +01001657 struct om2k_mo_fsm_priv *omfp = fi->priv;
Harald Welte591e1d72016-07-09 22:20:57 +02001658 struct om2k_decoded_msg *omd = data;
1659
1660 switch (omd->msg_type) {
1661 case OM2K_MSGT_ENABLE_REQ_REJ:
1662 osmo_fsm_inst_state_chg(fi, OM2K_ST_ERROR, 0, 0);
1663 break;
1664 case OM2K_MSGT_ENABLE_REQ_ACK:
Harald Weltece492582016-11-15 22:59:24 +01001665 if (omfp->mo->addr.class == OM2K_MO_CLS_IS &&
1666 omfp->trx->bts->rbs2000.use_superchannel)
1667 e1inp_ericsson_set_altc(omfp->trx->bts->oml_link->ts->line, 1);
Harald Welte591e1d72016-07-09 22:20:57 +02001668 osmo_fsm_inst_state_chg(fi, OM2K_ST_WAIT_ENABLE_RES,
1669 OM2K_TIMEOUT, 0);
1670 }
1671}
1672
1673static void om2k_mo_st_wait_enable_res(struct osmo_fsm_inst *fi, uint32_t event, void *data)
1674{
1675 struct om2k_mo_fsm_priv *omfp = fi->priv;
1676 //struct om2k_decoded_msg *omd = data;
1677 /* TODO: check if state is actually enabled now? */
1678
1679 osmo_fsm_inst_state_chg(fi, OM2K_ST_WAIT_OPINFO_ACCEPT,
1680 OM2K_TIMEOUT, 0);
1681 abis_om2k_tx_op_info(omfp->trx->bts, &omfp->mo->addr, 1);
1682}
1683
1684static void om2k_mo_st_wait_opinfo_accept(struct osmo_fsm_inst *fi, uint32_t event, void *data)
1685{
Harald Welte80ccb952016-11-15 23:23:42 +01001686 struct om2k_mo_fsm_priv *omfp = fi->priv;
1687
1688 /* if we have just received opinfo accept for the timeslot,
1689 * start dynamic TCH switching procedures */
1690 if (omfp->mo->addr.class == OM2K_MO_CLS_TS) {
Neels Hofmeyr2b9c5342016-12-02 01:58:08 +01001691 struct gsm_bts_trx_ts *ts;
Harald Welte80ccb952016-11-15 23:23:42 +01001692 ts = mo2obj(omfp->trx->bts, &omfp->mo->addr);
1693 dyn_ts_init(ts);
1694 }
Harald Welte591e1d72016-07-09 22:20:57 +02001695 osmo_fsm_inst_state_chg(fi, OM2K_ST_DONE, 0, 0);
1696}
1697
1698static void om2k_mo_s_done_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state)
1699{
Alexander Couzens3521af72016-11-02 02:41:41 +01001700 struct om2k_mo_fsm_priv *omfp = fi->priv;
1701 omfp->mo->fsm = NULL;
Harald Welte591e1d72016-07-09 22:20:57 +02001702 osmo_fsm_inst_term(fi, OSMO_FSM_TERM_REGULAR, NULL);
1703}
1704
Alexander Couzens3521af72016-11-02 02:41:41 +01001705static void om2k_mo_s_error_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state)
1706{
1707 struct om2k_mo_fsm_priv *omfp = fi->priv;
1708
1709 omfp->mo->fsm = NULL;
1710 osmo_fsm_inst_term(fi, OSMO_FSM_TERM_ERROR, NULL);
1711}
1712
Harald Welte591e1d72016-07-09 22:20:57 +02001713static const struct osmo_fsm_state om2k_is_states[] = {
1714 [OM2K_ST_INIT] = {
1715 .name = "INIT",
1716 .in_event_mask = S(OM2K_MO_EVT_START),
1717 .out_state_mask = S(OM2K_ST_DONE) |
1718 S(OM2K_ST_ERROR) |
1719 S(OM2K_ST_WAIT_CONN_COMPL) |
1720 S(OM2K_ST_WAIT_START_ACCEPT) |
1721 S(OM2K_ST_WAIT_RES_COMPL),
1722 .action = om2k_mo_st_init,
1723 },
1724 [OM2K_ST_WAIT_CONN_COMPL] = {
1725 .name = "WAIT-CONN-COMPL",
1726 .in_event_mask = S(OM2K_MO_EVT_RX_CONN_COMPL),
1727 .out_state_mask = S(OM2K_ST_DONE) |
1728 S(OM2K_ST_ERROR) |
1729 S(OM2K_ST_WAIT_START_ACCEPT) |
1730 S(OM2K_ST_WAIT_RES_COMPL),
1731 .action = om2k_mo_st_wait_conn_compl,
1732 },
1733 [OM2K_ST_WAIT_RES_COMPL] = {
1734 .name = "WAIT-RES-COMPL",
1735 .in_event_mask = S(OM2K_MO_EVT_RX_RESET_COMPL),
1736 .out_state_mask = S(OM2K_ST_DONE) |
1737 S(OM2K_ST_ERROR) |
1738 S(OM2K_ST_WAIT_START_ACCEPT),
1739 .action = om2k_mo_st_wait_res_compl,
1740 },
1741 [OM2K_ST_WAIT_START_ACCEPT] = {
1742 .name = "WAIT-START-ACCEPT",
1743 .in_event_mask = S(OM2K_MO_EVT_RX_START_REQ_ACCEPT),
1744 .out_state_mask = S(OM2K_ST_DONE) |
1745 S(OM2K_ST_ERROR) |
1746 S(OM2K_ST_WAIT_START_RES),
1747 .action =om2k_mo_st_wait_start_accept,
1748 },
1749 [OM2K_ST_WAIT_START_RES] = {
1750 .name = "WAIT-START-RES",
1751 .in_event_mask = S(OM2K_MO_EVT_RX_START_RES),
1752 .out_state_mask = S(OM2K_ST_DONE) |
1753 S(OM2K_ST_ERROR) |
1754 S(OM2K_ST_WAIT_CFG_ACCEPT) |
1755 S(OM2K_ST_WAIT_OPINFO_ACCEPT),
1756 .action = om2k_mo_st_wait_start_res,
1757 },
1758 [OM2K_ST_WAIT_CFG_ACCEPT] = {
1759 .name = "WAIT-CFG-ACCEPT",
1760 .in_event_mask = S(OM2K_MO_EVT_RX_CFG_REQ_ACCEPT),
1761 .out_state_mask = S(OM2K_ST_DONE) |
1762 S(OM2K_ST_ERROR) |
1763 S(OM2K_ST_WAIT_CFG_RES),
1764 .action = om2k_mo_st_wait_cfg_accept,
1765 },
1766 [OM2K_ST_WAIT_CFG_RES] = {
1767 .name = "WAIT-CFG-RES",
1768 .in_event_mask = S(OM2K_MO_EVT_RX_CFG_RES),
1769 .out_state_mask = S(OM2K_ST_DONE) |
1770 S(OM2K_ST_ERROR) |
1771 S(OM2K_ST_WAIT_ENABLE_ACCEPT),
1772 .action = om2k_mo_st_wait_cfg_res,
1773 },
1774 [OM2K_ST_WAIT_ENABLE_ACCEPT] = {
1775 .name = "WAIT-ENABLE-ACCEPT",
1776 .in_event_mask = S(OM2K_MO_EVT_RX_ENA_REQ_ACCEPT),
1777 .out_state_mask = S(OM2K_ST_DONE) |
1778 S(OM2K_ST_ERROR) |
1779 S(OM2K_ST_WAIT_ENABLE_RES),
1780 .action = om2k_mo_st_wait_enable_accept,
1781 },
1782 [OM2K_ST_WAIT_ENABLE_RES] = {
1783 .name = "WAIT-ENABLE-RES",
1784 .in_event_mask = S(OM2K_MO_EVT_RX_ENA_RES),
1785 .out_state_mask = S(OM2K_ST_DONE) |
1786 S(OM2K_ST_ERROR) |
1787 S(OM2K_ST_WAIT_OPINFO_ACCEPT),
1788 .action = om2k_mo_st_wait_enable_res,
1789 },
1790 [OM2K_ST_WAIT_OPINFO_ACCEPT] = {
1791 .name = "WAIT-OPINFO-ACCEPT",
1792 .in_event_mask = S(OM2K_MO_EVT_RX_OPINFO_ACC),
1793 .out_state_mask = S(OM2K_ST_DONE) |
1794 S(OM2K_ST_ERROR),
1795 .action = om2k_mo_st_wait_opinfo_accept,
1796 },
1797 [OM2K_ST_DONE] = {
1798 .name = "DONE",
1799 .in_event_mask = 0,
1800 .out_state_mask = 0,
1801 .onenter = om2k_mo_s_done_onenter,
1802 },
1803 [OM2K_ST_ERROR] = {
1804 .name = "ERROR",
1805 .in_event_mask = 0,
1806 .out_state_mask = 0,
Alexander Couzens3521af72016-11-02 02:41:41 +01001807 .onenter = om2k_mo_s_error_onenter,
Harald Welte591e1d72016-07-09 22:20:57 +02001808 },
1809
1810};
1811
1812static int om2k_mo_timer_cb(struct osmo_fsm_inst *fi)
1813{
1814 osmo_fsm_inst_state_chg(fi, OM2K_ST_ERROR, 0, 0);
1815 return 0;
1816}
1817
1818static struct osmo_fsm om2k_mo_fsm = {
1819 .name = "OM2000-MO",
1820 .states = om2k_is_states,
1821 .num_states = ARRAY_SIZE(om2k_is_states),
1822 .log_subsys = DNM,
1823 .event_names = om2k_event_names,
1824 .timer_cb = om2k_mo_timer_cb,
1825};
1826
1827struct osmo_fsm_inst *om2k_mo_fsm_start(struct osmo_fsm_inst *parent,
1828 uint32_t term_event,
1829 struct gsm_bts_trx *trx, struct om2k_mo *mo)
1830{
1831 struct osmo_fsm_inst *fi;
1832 struct om2k_mo_fsm_priv *omfp;
1833 char idbuf[64];
1834
1835 snprintf(idbuf, sizeof(idbuf), "%s-%s", parent->id,
1836 om2k_mo_name(&mo->addr));
1837
1838 fi = osmo_fsm_inst_alloc_child_id(&om2k_mo_fsm, parent,
1839 term_event, idbuf);
1840 if (!fi)
1841 return NULL;
1842
1843 mo->fsm = fi;
1844 omfp = talloc_zero(fi, struct om2k_mo_fsm_priv);
1845 omfp->mo = mo;
1846 omfp->trx = trx;
1847 fi->priv = omfp;
1848
1849 osmo_fsm_inst_dispatch(fi, OM2K_MO_EVT_START, NULL);
1850
1851 return fi;
1852}
1853
1854int om2k_mo_fsm_recvmsg(struct gsm_bts *bts, struct om2k_mo *mo,
1855 struct om2k_decoded_msg *odm)
1856{
1857 switch (odm->msg_type) {
1858 case OM2K_MSGT_CONNECT_COMPL:
1859 case OM2K_MSGT_CONNECT_REJ:
1860 osmo_fsm_inst_dispatch(mo->fsm,
1861 OM2K_MO_EVT_RX_CONN_COMPL, odm);
1862 break;
1863
1864 case OM2K_MSGT_RESET_COMPL:
1865 case OM2K_MSGT_RESET_REJ:
1866 osmo_fsm_inst_dispatch(mo->fsm,
1867 OM2K_MO_EVT_RX_RESET_COMPL, odm);
1868 break;
1869
1870 case OM2K_MSGT_START_REQ_ACK:
1871 case OM2K_MSGT_START_REQ_REJ:
1872 osmo_fsm_inst_dispatch(mo->fsm,
1873 OM2K_MO_EVT_RX_START_REQ_ACCEPT, odm);
1874 break;
1875
1876 case OM2K_MSGT_START_RES:
1877 osmo_fsm_inst_dispatch(mo->fsm,
1878 OM2K_MO_EVT_RX_START_RES, odm);
1879 break;
1880
1881 case OM2K_MSGT_CON_CONF_REQ_ACK:
1882 case OM2K_MSGT_IS_CONF_REQ_ACK:
1883 case OM2K_MSGT_RX_CONF_REQ_ACK:
1884 case OM2K_MSGT_TF_CONF_REQ_ACK:
1885 case OM2K_MSGT_TS_CONF_REQ_ACK:
1886 case OM2K_MSGT_TX_CONF_REQ_ACK:
1887 osmo_fsm_inst_dispatch(mo->fsm,
1888 OM2K_MO_EVT_RX_CFG_REQ_ACCEPT, odm);
1889 break;
1890
1891 case OM2K_MSGT_CON_CONF_RES:
1892 case OM2K_MSGT_IS_CONF_RES:
1893 case OM2K_MSGT_RX_CONF_RES:
1894 case OM2K_MSGT_TF_CONF_RES:
1895 case OM2K_MSGT_TS_CONF_RES:
1896 case OM2K_MSGT_TX_CONF_RES:
1897 osmo_fsm_inst_dispatch(mo->fsm,
1898 OM2K_MO_EVT_RX_CFG_RES, odm);
1899 break;
1900
1901 case OM2K_MSGT_ENABLE_REQ_ACK:
1902 case OM2K_MSGT_ENABLE_REQ_REJ:
1903 osmo_fsm_inst_dispatch(mo->fsm,
1904 OM2K_MO_EVT_RX_ENA_REQ_ACCEPT, odm);
1905 break;
1906 case OM2K_MSGT_ENABLE_RES:
1907 osmo_fsm_inst_dispatch(mo->fsm,
1908 OM2K_MO_EVT_RX_ENA_RES, odm);
1909 break;
1910
1911 case OM2K_MSGT_OP_INFO_ACK:
1912 case OM2K_MSGT_OP_INFO_REJ:
1913 osmo_fsm_inst_dispatch(mo->fsm,
1914 OM2K_MO_EVT_RX_OPINFO_ACC, odm);
1915 break;
1916 default:
1917 return -1;
1918 }
1919
1920 return 0;
1921}
1922
1923/***********************************************************************
1924 * OM2000 TRX Finite State Machine, initializes TRXC and all siblings
1925 ***********************************************************************/
1926
1927enum om2k_trx_event {
1928 OM2K_TRX_EVT_START,
1929 OM2K_TRX_EVT_TRXC_DONE,
1930 OM2K_TRX_EVT_TX_DONE,
1931 OM2K_TRX_EVT_RX_DONE,
1932 OM2K_TRX_EVT_TS_DONE,
1933 OM2K_TRX_EVT_STOP,
1934};
1935
1936static struct value_string om2k_trx_events[] = {
1937 { OM2K_TRX_EVT_START, "START" },
1938 { OM2K_TRX_EVT_TRXC_DONE, "TRXC-DONE" },
1939 { OM2K_TRX_EVT_TX_DONE, "TX-DONE" },
1940 { OM2K_TRX_EVT_RX_DONE, "RX-DONE" },
1941 { OM2K_TRX_EVT_TS_DONE, "TS-DONE" },
1942 { OM2K_TRX_EVT_STOP, "STOP" },
1943 { 0, NULL }
1944};
1945
1946enum om2k_trx_state {
1947 OM2K_TRX_S_INIT,
1948 OM2K_TRX_S_WAIT_TRXC,
1949 OM2K_TRX_S_WAIT_TX,
1950 OM2K_TRX_S_WAIT_RX,
1951 OM2K_TRX_S_WAIT_TS,
1952 OM2K_TRX_S_DONE,
1953 OM2K_TRX_S_ERROR
1954};
1955
1956struct om2k_trx_fsm_priv {
1957 struct gsm_bts_trx *trx;
1958 uint8_t next_ts_nr;
1959};
1960
1961static void om2k_trx_s_init(struct osmo_fsm_inst *fi, uint32_t event, void *data)
1962{
1963 struct om2k_trx_fsm_priv *otfp = fi->priv;
1964
1965 /* First initialize TRXC */
1966 osmo_fsm_inst_state_chg(fi, OM2K_TRX_S_WAIT_TRXC,
1967 TRX_FSM_TIMEOUT, 0);
1968 om2k_mo_fsm_start(fi, OM2K_TRX_EVT_TRXC_DONE, otfp->trx,
1969 &otfp->trx->rbs2000.trxc.om2k_mo);
1970}
1971
1972static void om2k_trx_s_wait_trxc(struct osmo_fsm_inst *fi, uint32_t event, void *data)
1973{
1974 struct om2k_trx_fsm_priv *otfp = fi->priv;
1975
1976 /* Initialize TX after TRXC */
1977 osmo_fsm_inst_state_chg(fi, OM2K_TRX_S_WAIT_TX,
1978 TRX_FSM_TIMEOUT, 0);
1979 om2k_mo_fsm_start(fi, OM2K_TRX_EVT_TX_DONE, otfp->trx,
1980 &otfp->trx->rbs2000.tx.om2k_mo);
1981}
1982
1983static void om2k_trx_s_wait_tx(struct osmo_fsm_inst *fi, uint32_t event, void *data)
1984{
1985 struct om2k_trx_fsm_priv *otfp = fi->priv;
1986
1987 /* Initialize RX after TX */
1988 osmo_fsm_inst_state_chg(fi, OM2K_TRX_S_WAIT_RX,
1989 TRX_FSM_TIMEOUT, 0);
1990 om2k_mo_fsm_start(fi, OM2K_TRX_EVT_RX_DONE, otfp->trx,
1991 &otfp->trx->rbs2000.rx.om2k_mo);
1992}
1993
1994static void om2k_trx_s_wait_rx(struct osmo_fsm_inst *fi, uint32_t event, void *data)
1995{
1996 struct om2k_trx_fsm_priv *otfp = fi->priv;
1997 struct gsm_bts_trx_ts *ts;
1998
1999 /* Initialize Timeslots after TX */
2000 osmo_fsm_inst_state_chg(fi, OM2K_TRX_S_WAIT_TS,
2001 TRX_FSM_TIMEOUT, 0);
2002 otfp->next_ts_nr = 0;
2003 ts = &otfp->trx->ts[otfp->next_ts_nr++];
2004 om2k_mo_fsm_start(fi, OM2K_TRX_EVT_TS_DONE, otfp->trx,
2005 &ts->rbs2000.om2k_mo);
2006}
2007
2008static void om2k_trx_s_wait_ts(struct osmo_fsm_inst *fi, uint32_t event, void *data)
2009{
2010 struct om2k_trx_fsm_priv *otfp = fi->priv;
2011 struct gsm_bts_trx_ts *ts;
2012
2013 if (otfp->next_ts_nr < 8) {
2014 /* iterate to the next timeslot */
2015 ts = &otfp->trx->ts[otfp->next_ts_nr++];
2016 om2k_mo_fsm_start(fi, OM2K_TRX_EVT_TS_DONE, otfp->trx,
2017 &ts->rbs2000.om2k_mo);
2018 } else {
2019 /* only after all 8 TS */
2020 osmo_fsm_inst_state_chg(fi, OM2K_TRX_S_DONE, 0, 0);
2021 }
2022}
2023
2024static void om2k_trx_s_done_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state)
2025{
2026 struct om2k_trx_fsm_priv *otfp = fi->priv;
2027 gsm_bts_trx_set_system_infos(otfp->trx);
2028 osmo_fsm_inst_term(fi, OSMO_FSM_TERM_REGULAR, NULL);
2029}
2030
2031static const struct osmo_fsm_state om2k_trx_states[] = {
2032 [OM2K_TRX_S_INIT] = {
2033 .in_event_mask = S(OM2K_TRX_EVT_START),
2034 .out_state_mask = S(OM2K_TRX_S_WAIT_TRXC),
2035 .name = "INIT",
2036 .action = om2k_trx_s_init,
2037 },
2038 [OM2K_TRX_S_WAIT_TRXC] = {
2039 .in_event_mask = S(OM2K_TRX_EVT_TRXC_DONE),
2040 .out_state_mask = S(OM2K_TRX_S_ERROR) |
2041 S(OM2K_TRX_S_WAIT_TX),
2042 .name = "WAIT-TRXC",
2043 .action = om2k_trx_s_wait_trxc,
2044 },
2045 [OM2K_TRX_S_WAIT_TX] = {
2046 .in_event_mask = S(OM2K_TRX_EVT_TX_DONE),
2047 .out_state_mask = S(OM2K_TRX_S_ERROR) |
2048 S(OM2K_TRX_S_WAIT_RX),
2049 .name = "WAIT-TX",
2050 .action = om2k_trx_s_wait_tx,
2051 },
2052 [OM2K_TRX_S_WAIT_RX] = {
2053 .in_event_mask = S(OM2K_TRX_EVT_RX_DONE),
2054 .out_state_mask = S(OM2K_TRX_S_ERROR) |
2055 S(OM2K_TRX_S_WAIT_TS),
2056 .name = "WAIT-RX",
2057 .action = om2k_trx_s_wait_rx,
2058 },
2059 [OM2K_TRX_S_WAIT_TS] = {
2060 .in_event_mask = S(OM2K_TRX_EVT_TS_DONE),
2061 .out_state_mask = S(OM2K_TRX_S_ERROR) |
2062 S(OM2K_TRX_S_DONE),
2063 .name = "WAIT-TS",
2064 .action = om2k_trx_s_wait_ts,
2065 },
2066 [OM2K_TRX_S_DONE] = {
2067 .name = "DONE",
2068 .onenter = om2k_trx_s_done_onenter,
2069 },
2070 [OM2K_TRX_S_ERROR] = {
2071 .name = "ERROR",
2072 },
2073};
2074
2075static int om2k_trx_timer_cb(struct osmo_fsm_inst *fi)
2076{
2077 osmo_fsm_inst_state_chg(fi, OM2K_TRX_S_ERROR, 0, 0);
2078 return 0;
2079}
2080
2081static struct osmo_fsm om2k_trx_fsm = {
2082 .name = "OM2000-TRX",
2083 .states = om2k_trx_states,
2084 .num_states = ARRAY_SIZE(om2k_trx_states),
2085 .log_subsys = DNM,
2086 .event_names = om2k_trx_events,
2087 .timer_cb = om2k_trx_timer_cb,
2088};
2089
2090struct osmo_fsm_inst *om2k_trx_fsm_start(struct osmo_fsm_inst *parent,
2091 struct gsm_bts_trx *trx,
2092 uint32_t term_event)
2093{
2094 struct osmo_fsm_inst *fi;
2095 struct om2k_trx_fsm_priv *otfp;
2096 char idbuf[32];
2097
2098 snprintf(idbuf, sizeof(idbuf), "%u/%u", trx->bts->nr, trx->nr);
2099
2100 fi = osmo_fsm_inst_alloc_child_id(&om2k_trx_fsm, parent, term_event,
2101 idbuf);
2102 if (!fi)
2103 return NULL;
2104
2105 otfp = talloc_zero(fi, struct om2k_trx_fsm_priv);
2106 otfp->trx = trx;
2107 fi->priv = otfp;
2108
2109 osmo_fsm_inst_dispatch(fi, OM2K_TRX_EVT_START, NULL);
2110
2111 return fi;
2112}
2113
2114
2115/***********************************************************************
2116 * OM2000 BTS Finite State Machine, initializes CF and all siblings
2117 ***********************************************************************/
2118
2119enum om2k_bts_event {
2120 OM2K_BTS_EVT_START,
2121 OM2K_BTS_EVT_CF_DONE,
2122 OM2K_BTS_EVT_IS_DONE,
Harald Welteeae68292016-11-11 19:41:59 +01002123 OM2K_BTS_EVT_CON_DONE,
Harald Welte591e1d72016-07-09 22:20:57 +02002124 OM2K_BTS_EVT_TF_DONE,
2125 OM2K_BTS_EVT_TRX_DONE,
2126 OM2K_BTS_EVT_STOP,
2127};
2128
2129static const struct value_string om2k_bts_events[] = {
2130 { OM2K_BTS_EVT_START, "START" },
2131 { OM2K_BTS_EVT_CF_DONE, "CF-DONE" },
2132 { OM2K_BTS_EVT_IS_DONE, "IS-DONE" },
Harald Welteeae68292016-11-11 19:41:59 +01002133 { OM2K_BTS_EVT_CON_DONE, "CON-DONE" },
Harald Welte591e1d72016-07-09 22:20:57 +02002134 { OM2K_BTS_EVT_TF_DONE, "TF-DONE" },
2135 { OM2K_BTS_EVT_TRX_DONE, "TRX-DONE" },
2136 { OM2K_BTS_EVT_STOP, "STOP" },
2137 { 0, NULL }
2138};
2139
2140enum om2k_bts_state {
2141 OM2K_BTS_S_INIT,
2142 OM2K_BTS_S_WAIT_CF,
2143 OM2K_BTS_S_WAIT_IS,
Harald Welteeae68292016-11-11 19:41:59 +01002144 OM2K_BTS_S_WAIT_CON,
Harald Welte591e1d72016-07-09 22:20:57 +02002145 OM2K_BTS_S_WAIT_TF,
2146 OM2K_BTS_S_WAIT_TRX,
2147 OM2K_BTS_S_DONE,
2148 OM2K_BTS_S_ERROR,
2149};
2150
2151struct om2k_bts_fsm_priv {
2152 struct gsm_bts *bts;
2153 uint8_t next_trx_nr;
2154};
2155
2156static void om2k_bts_s_init(struct osmo_fsm_inst *fi, uint32_t event, void *data)
2157{
2158 struct om2k_bts_fsm_priv *obfp = fi->priv;
2159 struct gsm_bts *bts = obfp->bts;
2160
2161 OSMO_ASSERT(event == OM2K_BTS_EVT_START);
2162 osmo_fsm_inst_state_chg(fi, OM2K_BTS_S_WAIT_CF,
2163 BTS_FSM_TIMEOUT, 0);
2164 om2k_mo_fsm_start(fi, OM2K_BTS_EVT_CF_DONE, bts->c0,
2165 &bts->rbs2000.cf.om2k_mo);
2166}
2167
2168static void om2k_bts_s_wait_cf(struct osmo_fsm_inst *fi, uint32_t event, void *data)
2169{
2170 struct om2k_bts_fsm_priv *obfp = fi->priv;
2171 struct gsm_bts *bts = obfp->bts;
2172
2173 OSMO_ASSERT(event == OM2K_BTS_EVT_CF_DONE);
Harald Weltec103c642017-03-13 09:39:08 +01002174 /* TF can take a long time to initialize, wait for 10min */
2175 osmo_fsm_inst_state_chg(fi, OM2K_BTS_S_WAIT_TF, 600, 0);
2176 om2k_mo_fsm_start(fi, OM2K_BTS_EVT_TF_DONE, bts->c0,
2177 &bts->rbs2000.tf.om2k_mo);
Harald Welte591e1d72016-07-09 22:20:57 +02002178}
2179
Harald Weltec103c642017-03-13 09:39:08 +01002180static void om2k_bts_s_wait_tf(struct osmo_fsm_inst *fi, uint32_t event, void *data)
Harald Welte591e1d72016-07-09 22:20:57 +02002181{
2182 struct om2k_bts_fsm_priv *obfp = fi->priv;
2183 struct gsm_bts *bts = obfp->bts;
2184
Harald Weltec103c642017-03-13 09:39:08 +01002185 OSMO_ASSERT(event == OM2K_BTS_EVT_TF_DONE);
2186
Harald Welteeae68292016-11-11 19:41:59 +01002187 osmo_fsm_inst_state_chg(fi, OM2K_BTS_S_WAIT_CON,
2188 BTS_FSM_TIMEOUT, 0);
2189 om2k_mo_fsm_start(fi, OM2K_BTS_EVT_CON_DONE, bts->c0,
2190 &bts->rbs2000.con.om2k_mo);
2191}
2192
2193static void om2k_bts_s_wait_con(struct osmo_fsm_inst *fi, uint32_t event, void *data)
2194{
2195 struct om2k_bts_fsm_priv *obfp = fi->priv;
2196 struct gsm_bts *bts = obfp->bts;
2197
2198 OSMO_ASSERT(event == OM2K_BTS_EVT_CON_DONE);
Harald Weltec103c642017-03-13 09:39:08 +01002199
2200 osmo_fsm_inst_state_chg(fi, OM2K_BTS_S_WAIT_IS,
2201 BTS_FSM_TIMEOUT, 0);
2202 om2k_mo_fsm_start(fi, OM2K_BTS_EVT_IS_DONE, bts->c0,
2203 &bts->rbs2000.is.om2k_mo);
Harald Welte591e1d72016-07-09 22:20:57 +02002204}
2205
Harald Weltec103c642017-03-13 09:39:08 +01002206static void om2k_bts_s_wait_is(struct osmo_fsm_inst *fi, uint32_t event, void *data)
Harald Welte591e1d72016-07-09 22:20:57 +02002207{
2208 struct om2k_bts_fsm_priv *obfp = fi->priv;
2209 struct gsm_bts_trx *trx;
2210
Harald Weltec103c642017-03-13 09:39:08 +01002211 OSMO_ASSERT(event == OM2K_BTS_EVT_IS_DONE);
Harald Welte591e1d72016-07-09 22:20:57 +02002212
2213 osmo_fsm_inst_state_chg(fi, OM2K_BTS_S_WAIT_TRX,
2214 BTS_FSM_TIMEOUT, 0);
2215 obfp->next_trx_nr = 0;
2216 trx = gsm_bts_trx_num(obfp->bts, obfp->next_trx_nr++);
2217 om2k_trx_fsm_start(fi, trx, OM2K_BTS_EVT_TRX_DONE);
2218}
2219
2220static void om2k_bts_s_wait_trx(struct osmo_fsm_inst *fi, uint32_t event, void *data)
2221{
2222 struct om2k_bts_fsm_priv *obfp = fi->priv;
2223
2224 OSMO_ASSERT(event == OM2K_BTS_EVT_TRX_DONE);
2225
2226 if (obfp->next_trx_nr < obfp->bts->num_trx) {
2227 struct gsm_bts_trx *trx;
2228 trx = gsm_bts_trx_num(obfp->bts, obfp->next_trx_nr++);
2229 om2k_trx_fsm_start(fi, trx, OM2K_BTS_EVT_TRX_DONE);
2230 } else {
2231 osmo_fsm_inst_state_chg(fi, OM2K_BTS_S_DONE, 0, 0);
2232 }
2233}
2234
2235static void om2k_bts_s_done_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state)
2236{
2237 osmo_fsm_inst_term(fi, OSMO_FSM_TERM_REGULAR, NULL);
2238}
2239
2240static const struct osmo_fsm_state om2k_bts_states[] = {
2241 [OM2K_BTS_S_INIT] = {
2242 .in_event_mask = S(OM2K_BTS_EVT_START),
2243 .out_state_mask = S(OM2K_BTS_S_WAIT_CF),
2244 .name = "INIT",
2245 .action = om2k_bts_s_init,
2246 },
2247 [OM2K_BTS_S_WAIT_CF] = {
2248 .in_event_mask = S(OM2K_BTS_EVT_CF_DONE),
2249 .out_state_mask = S(OM2K_BTS_S_ERROR) |
Harald Weltec103c642017-03-13 09:39:08 +01002250 S(OM2K_BTS_S_WAIT_TF),
Harald Welte591e1d72016-07-09 22:20:57 +02002251 .name = "WAIT-CF",
2252 .action = om2k_bts_s_wait_cf,
2253 },
Harald Welte591e1d72016-07-09 22:20:57 +02002254 [OM2K_BTS_S_WAIT_TF] = {
2255 .in_event_mask = S(OM2K_BTS_EVT_TF_DONE),
2256 .out_state_mask = S(OM2K_BTS_S_ERROR) |
Harald Weltec103c642017-03-13 09:39:08 +01002257 S(OM2K_BTS_S_WAIT_CON),
Harald Welte591e1d72016-07-09 22:20:57 +02002258 .name = "WAIT-TF",
2259 .action = om2k_bts_s_wait_tf,
2260 },
Harald Weltec103c642017-03-13 09:39:08 +01002261 [OM2K_BTS_S_WAIT_CON] = {
2262 .in_event_mask = S(OM2K_BTS_EVT_CON_DONE),
2263 .out_state_mask = S(OM2K_BTS_S_ERROR) |
2264 S(OM2K_BTS_S_WAIT_IS),
2265 .name = "WAIT-CON",
2266 .action = om2k_bts_s_wait_con,
2267 },
2268 [OM2K_BTS_S_WAIT_IS] = {
2269 .in_event_mask = S(OM2K_BTS_EVT_IS_DONE),
2270 .out_state_mask = S(OM2K_BTS_S_ERROR) |
2271 S(OM2K_BTS_S_WAIT_TRX),
2272 .name = "WAIT-IS",
2273 .action = om2k_bts_s_wait_is,
2274 },
Harald Welte591e1d72016-07-09 22:20:57 +02002275 [OM2K_BTS_S_WAIT_TRX] = {
2276 .in_event_mask = S(OM2K_BTS_EVT_TRX_DONE),
2277 .out_state_mask = S(OM2K_BTS_S_ERROR) |
2278 S(OM2K_BTS_S_DONE),
2279 .name = "WAIT-TRX",
2280 .action = om2k_bts_s_wait_trx,
2281 },
2282 [OM2K_BTS_S_DONE] = {
2283 .name = "DONE",
2284 .onenter = om2k_bts_s_done_onenter,
2285 },
2286 [OM2K_BTS_S_ERROR] = {
2287 .name = "ERROR",
2288 },
2289};
2290
2291static int om2k_bts_timer_cb(struct osmo_fsm_inst *fi)
2292{
2293 osmo_fsm_inst_state_chg(fi, OM2K_BTS_S_ERROR, 0, 0);
2294 return 0;
2295}
2296
2297static struct osmo_fsm om2k_bts_fsm = {
2298 .name = "OM2000-BTS",
2299 .states = om2k_bts_states,
2300 .num_states = ARRAY_SIZE(om2k_bts_states),
2301 .log_subsys = DNM,
2302 .event_names = om2k_bts_events,
2303 .timer_cb = om2k_bts_timer_cb,
2304};
2305
2306struct osmo_fsm_inst *
2307om2k_bts_fsm_start(struct gsm_bts *bts)
2308{
2309 struct osmo_fsm_inst *fi;
2310 struct om2k_bts_fsm_priv *obfp;
2311 char idbuf[16];
2312
2313 snprintf(idbuf, sizeof(idbuf), "%u", bts->nr);
2314
2315 fi = osmo_fsm_inst_alloc(&om2k_bts_fsm, bts, NULL,
2316 LOGL_DEBUG, idbuf);
2317 if (!fi)
2318 return NULL;
2319 fi->priv = obfp = talloc_zero(fi, struct om2k_bts_fsm_priv);
2320 obfp->bts = bts;
2321
2322 osmo_fsm_inst_dispatch(fi, OM2K_BTS_EVT_START, NULL);
2323
2324 return fi;
2325}
2326
2327
2328/***********************************************************************
2329 * OM2000 Negotiation
2330 ***********************************************************************/
2331
Harald Welte6fec79d2011-02-12 14:57:17 +01002332static int abis_om2k_tx_negot_req_ack(struct gsm_bts *bts, const struct abis_om2k_mo *mo,
Harald Welte73541072011-02-12 13:44:14 +01002333 uint8_t *data, unsigned int len)
2334{
2335 struct msgb *msg = om2k_msgb_alloc();
2336 struct abis_om2k_hdr *o2k;
2337
2338 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
Harald Welte1164dce2011-03-05 19:21:26 +01002339 fill_om2k_hdr(o2k, mo, OM2K_MSGT_NEGOT_REQ_ACK);
Harald Welte73541072011-02-12 13:44:14 +01002340
2341 msgb_tlv_put(msg, OM2K_DEI_NEGOT_REC2, len, data);
2342
2343 DEBUGP(DNM, "Tx MO=%s %s\n", om2k_mo_name(mo),
2344 get_value_string(om2k_msgcode_vals, OM2K_MSGT_NEGOT_REQ_ACK));
2345
2346 return abis_om2k_sendmsg(bts, msg);
2347}
Harald Welte9a311ec2011-02-12 12:33:06 +01002348
Harald Welte563d3162011-02-12 18:11:16 +01002349struct iwd_version {
2350 uint8_t gen_char[3+1];
2351 uint8_t rev_char[3+1];
2352};
2353
2354struct iwd_type {
2355 uint8_t num_vers;
2356 struct iwd_version v[8];
2357};
2358
Harald Welte9a311ec2011-02-12 12:33:06 +01002359static int om2k_rx_negot_req(struct msgb *msg)
2360{
Pablo Neira Ayuso7abecfc2011-08-17 22:43:54 +02002361 struct e1inp_sign_link *sign_link = (struct e1inp_sign_link *)msg->dst;
Harald Welte9a311ec2011-02-12 12:33:06 +01002362 struct abis_om2k_hdr *o2h = msgb_l2(msg);
Harald Welte563d3162011-02-12 18:11:16 +01002363 struct iwd_type iwd_types[16];
2364 uint8_t num_iwd_types = o2h->data[2];
2365 uint8_t *cur = o2h->data+3;
2366 unsigned int i, v;
Harald Welte9a311ec2011-02-12 12:33:06 +01002367
Harald Welte563d3162011-02-12 18:11:16 +01002368 uint8_t out_buf[1024];
2369 uint8_t *out_cur = out_buf+1;
2370 uint8_t out_num_types = 0;
2371
2372 memset(iwd_types, 0, sizeof(iwd_types));
2373
2374 /* Parse the RBS-supported IWD versions into iwd_types array */
2375 for (i = 0; i < num_iwd_types; i++) {
2376 uint8_t num_versions = *cur++;
2377 uint8_t iwd_type = *cur++;
2378
2379 iwd_types[iwd_type].num_vers = num_versions;
2380
2381 for (v = 0; v < num_versions; v++) {
2382 struct iwd_version *iwd_v = &iwd_types[iwd_type].v[v];
2383
2384 memcpy(iwd_v->gen_char, cur, 3);
Harald Welte56ee6b82011-02-12 18:13:37 +01002385 cur += 3;
2386 memcpy(iwd_v->rev_char, cur, 3);
2387 cur += 3;
2388
Harald Welte563d3162011-02-12 18:11:16 +01002389 DEBUGP(DNM, "\tIWD Type %u Gen %s Rev %s\n", iwd_type,
2390 iwd_v->gen_char, iwd_v->rev_char);
2391 }
2392 }
2393
2394 /* Select the last version for each IWD type */
2395 for (i = 0; i < ARRAY_SIZE(iwd_types); i++) {
2396 struct iwd_type *type = &iwd_types[i];
2397 struct iwd_version *last_v;
2398
2399 if (type->num_vers == 0)
2400 continue;
2401
2402 out_num_types++;
2403
2404 last_v = &type->v[type->num_vers-1];
2405
2406 *out_cur++ = i;
2407 memcpy(out_cur, last_v->gen_char, 3);
2408 out_cur += 3;
2409 memcpy(out_cur, last_v->rev_char, 3);
2410 out_cur += 3;
2411 }
2412
2413 out_buf[0] = out_num_types;
2414
Pablo Neira Ayuso7abecfc2011-08-17 22:43:54 +02002415 return abis_om2k_tx_negot_req_ack(sign_link->trx->bts, &o2h->mo, out_buf, out_cur - out_buf);
Harald Welte9a311ec2011-02-12 12:33:06 +01002416}
2417
Harald Welte9a311ec2011-02-12 12:33:06 +01002418
Harald Welte591e1d72016-07-09 22:20:57 +02002419/***********************************************************************
2420 * OM2000 Receive Message Handler
2421 ***********************************************************************/
Harald Weltee898ecc2011-03-06 19:26:11 +01002422
Harald Weltee6e83832011-03-05 17:52:09 +01002423static int om2k_rx_nack(struct msgb *msg)
2424{
2425 struct abis_om2k_hdr *o2h = msgb_l2(msg);
2426 uint16_t msg_type = ntohs(o2h->msg_type);
2427 struct tlv_parsed tp;
2428
2429 LOGP(DNM, LOGL_ERROR, "Rx MO=%s %s", om2k_mo_name(&o2h->mo),
2430 get_value_string(om2k_msgcode_vals, msg_type));
2431
Harald Weltee898ecc2011-03-06 19:26:11 +01002432 abis_om2k_msg_tlv_parse(&tp, o2h);
Harald Weltee6e83832011-03-05 17:52:09 +01002433 if (TLVP_PRESENT(&tp, OM2K_DEI_REASON_CODE))
2434 LOGPC(DNM, LOGL_ERROR, ", Reason 0x%02x",
2435 *TLVP_VAL(&tp, OM2K_DEI_REASON_CODE));
2436
2437 if (TLVP_PRESENT(&tp, OM2K_DEI_RESULT_CODE))
2438 LOGPC(DNM, LOGL_ERROR, ", Result %s",
2439 get_value_string(om2k_result_strings,
2440 *TLVP_VAL(&tp, OM2K_DEI_RESULT_CODE)));
2441 LOGPC(DNM, LOGL_ERROR, "\n");
2442
2443 return 0;
2444}
2445
Harald Welte591e1d72016-07-09 22:20:57 +02002446static int process_mo_state(struct gsm_bts *bts, struct om2k_decoded_msg *odm)
Harald Weltee898ecc2011-03-06 19:26:11 +01002447{
Harald Weltee898ecc2011-03-06 19:26:11 +01002448 uint8_t mo_state;
2449
Harald Welte591e1d72016-07-09 22:20:57 +02002450 if (!TLVP_PRESENT(&odm->tp, OM2K_DEI_MO_STATE))
Harald Weltee898ecc2011-03-06 19:26:11 +01002451 return -EIO;
Harald Welte591e1d72016-07-09 22:20:57 +02002452 mo_state = *TLVP_VAL(&odm->tp, OM2K_DEI_MO_STATE);
Harald Weltee898ecc2011-03-06 19:26:11 +01002453
2454 LOGP(DNM, LOGL_DEBUG, "Rx MO=%s %s, MO State: %s\n",
Harald Welte591e1d72016-07-09 22:20:57 +02002455 om2k_mo_name(&odm->o2h.mo),
2456 get_value_string(om2k_msgcode_vals, odm->msg_type),
Harald Weltee898ecc2011-03-06 19:26:11 +01002457 get_value_string(om2k_mostate_vals, mo_state));
2458
Philippb4ecc1d2016-10-20 13:55:21 +02002459 /* Throw error message in case we see an enable rsponse that does
2460 * not yield an enabled mo-state */
2461 if (odm->msg_type == OM2K_MSGT_ENABLE_RES
2462 && mo_state != OM2K_MO_S_ENABLED) {
2463 LOGP(DNM, LOGL_ERROR,
2464 "Rx MO=%s %s Failed to enable MO State!\n",
2465 om2k_mo_name(&odm->o2h.mo),
2466 get_value_string(om2k_msgcode_vals, odm->msg_type));
2467 }
2468
Harald Welte591e1d72016-07-09 22:20:57 +02002469 update_mo_state(bts, &odm->o2h.mo, mo_state);
Harald Welteaf9b8102011-03-06 21:20:38 +01002470
Harald Weltee898ecc2011-03-06 19:26:11 +01002471 return 0;
2472}
2473
Philipp8136e4b2016-10-19 10:14:35 +02002474/* Display fault report bits (helper function of display_fault_maps()) */
Philipp38cba5a2016-11-15 19:27:20 +01002475static bool display_fault_bits(const uint8_t *vect, uint16_t len,
Philipp8136e4b2016-10-19 10:14:35 +02002476 uint8_t dei, const struct abis_om2k_mo *mo)
2477{
Philipp38cba5a2016-11-15 19:27:20 +01002478 uint16_t i;
Philipp8136e4b2016-10-19 10:14:35 +02002479 int k;
2480 bool faults_present = false;
2481 int first = 1;
2482 char string[255];
2483
2484 /* Check if errors are present at all */
2485 for (i = 0; i < len; i++)
2486 if (vect[i])
2487 faults_present = true;
2488 if (!faults_present)
2489 return false;
2490
2491 sprintf(string, "Fault Report: %s (",
2492 get_value_string(om2k_attr_vals, dei));
2493
2494 for (i = 0; i < len; i++) {
2495 for (k = 0; k < 8; k++) {
2496 if ((vect[i] >> k) & 1) {
2497 if (!first)
2498 sprintf(string + strlen(string), ",");
2499 sprintf(string + strlen(string), "%d", k + i*8);
2500 first = 0;
2501 }
2502 }
2503 }
2504
2505 sprintf(string + strlen(string), ")\n");
2506 DEBUGP(DNM, "Rx MO=%s %s", om2k_mo_name(mo), string);
2507
2508 return true;
2509}
2510
2511/* Display fault report maps */
2512static void display_fault_maps(const uint8_t *src, unsigned int src_len,
2513 const struct abis_om2k_mo *mo)
2514{
2515 uint8_t tag;
2516 uint16_t tag_len;
2517 const uint8_t *val;
2518 int src_pos = 0;
2519 int rc;
2520 int tlv_count = 0;
2521 uint16_t msg_code;
2522 bool faults_present = false;
2523
2524 /* Chop off header */
2525 src+=4;
2526 src_len-=4;
2527
2528 /* Check message type */
2529 msg_code = (*src & 0xff) << 8;
2530 src++;
2531 src_len--;
2532 msg_code |= (*src & 0xff);
2533 src++;
2534 src_len--;
2535 if (msg_code != OM2K_MSGT_FAULT_REP) {
2536 LOGP(DNM, LOGL_ERROR, "Rx MO=%s Fault report: invalid message code!\n",
2537 om2k_mo_name(mo));
2538 return;
2539 }
2540
2541 /* Chop off mo-interface */
2542 src += 4;
2543 src_len -= 4;
2544
2545 /* Iterate over each TLV element */
2546 while (1) {
2547
2548 /* Bail if an the maximum number of TLV fields
2549 * have been parsed */
2550 if (tlv_count >= 11) {
2551 LOGP(DNM, LOGL_ERROR,
2552 "Rx MO=%s Fault Report: too many tlv elements!\n",
2553 om2k_mo_name(mo));
2554 return;
2555 }
2556
2557 /* Parse TLV field */
2558 rc = tlv_parse_one(&tag, &tag_len, &val, &om2k_att_tlvdef,
2559 src + src_pos, src_len - src_pos);
2560 if (rc > 0)
2561 src_pos += rc;
2562 else {
2563 LOGP(DNM, LOGL_ERROR,
2564 "Rx MO=%s Fault Report: invalid tlv element!\n",
2565 om2k_mo_name(mo));
2566 return;
2567 }
2568
2569 switch (tag) {
2570 case OM2K_DEI_INT_FAULT_MAP_1A:
2571 case OM2K_DEI_INT_FAULT_MAP_1B:
2572 case OM2K_DEI_INT_FAULT_MAP_2A:
2573 case OM2K_DEI_EXT_COND_MAP_1:
2574 case OM2K_DEI_EXT_COND_MAP_2:
2575 case OM2K_DEI_REPL_UNIT_MAP:
2576 case OM2K_DEI_INT_FAULT_MAP_2A_EXT:
2577 case OM2K_DEI_EXT_COND_MAP_2_EXT:
2578 case OM2K_DEI_REPL_UNIT_MAP_EXT:
2579 faults_present |= display_fault_bits(val, tag_len,
2580 tag, mo);
2581 break;
2582 }
2583
2584 /* Stop when no further TLV elements can be expected */
2585 if (src_len - src_pos < 2)
2586 break;
2587
2588 tlv_count++;
2589 }
2590
2591 if (!faults_present) {
2592 DEBUGP(DNM, "Rx MO=%s Fault Report: All faults ceased!\n",
2593 om2k_mo_name(mo));
2594 }
2595}
2596
Harald Welte9a311ec2011-02-12 12:33:06 +01002597int abis_om2k_rcvmsg(struct msgb *msg)
2598{
Pablo Neira Ayuso7abecfc2011-08-17 22:43:54 +02002599 struct e1inp_sign_link *sign_link = (struct e1inp_sign_link *)msg->dst;
2600 struct gsm_bts *bts = sign_link->trx->bts;
Harald Welte9a311ec2011-02-12 12:33:06 +01002601 struct abis_om2k_hdr *o2h = msgb_l2(msg);
2602 struct abis_om_hdr *oh = &o2h->om;
Harald Weltebc867d92011-02-12 13:09:38 +01002603 uint16_t msg_type = ntohs(o2h->msg_type);
Harald Welte591e1d72016-07-09 22:20:57 +02002604 struct om2k_decoded_msg odm;
2605 struct om2k_mo *mo;
Harald Welte9a311ec2011-02-12 12:33:06 +01002606 int rc = 0;
2607
2608 /* Various consistency checks */
2609 if (oh->placement != ABIS_OM_PLACEMENT_ONLY) {
2610 LOGP(DNM, LOGL_ERROR, "ABIS OML placement 0x%x not supported\n",
2611 oh->placement);
2612 if (oh->placement != ABIS_OM_PLACEMENT_FIRST)
2613 return -EINVAL;
2614 }
2615 if (oh->sequence != 0) {
2616 LOGP(DNM, LOGL_ERROR, "ABIS OML sequence 0x%x != 0x00\n",
2617 oh->sequence);
2618 return -EINVAL;
2619 }
2620
2621 msg->l3h = (unsigned char *)o2h + sizeof(*o2h);
2622
2623 if (oh->mdisc != ABIS_OM_MDISC_FOM) {
2624 LOGP(DNM, LOGL_ERROR, "unknown ABIS OM2000 message discriminator 0x%x\n",
2625 oh->mdisc);
2626 return -EINVAL;
2627 }
2628
Harald Welte73541072011-02-12 13:44:14 +01002629 DEBUGP(DNM, "Rx MO=%s %s (%s)\n", om2k_mo_name(&o2h->mo),
Harald Weltebc867d92011-02-12 13:09:38 +01002630 get_value_string(om2k_msgcode_vals, msg_type),
Pablo Neira Ayusoc0d17f22011-05-07 12:12:48 +02002631 osmo_hexdump(msg->l2h, msgb_l2len(msg)));
Harald Welte9a311ec2011-02-12 12:33:06 +01002632
Harald Welte591e1d72016-07-09 22:20:57 +02002633 om2k_decode_msg(&odm, msg);
2634
2635 process_mo_state(bts, &odm);
2636
Harald Weltebc867d92011-02-12 13:09:38 +01002637 switch (msg_type) {
Harald Welte9a311ec2011-02-12 12:33:06 +01002638 case OM2K_MSGT_CAL_TIME_REQ:
2639 rc = abis_om2k_cal_time_resp(bts);
2640 break;
2641 case OM2K_MSGT_FAULT_REP:
Philipp8136e4b2016-10-19 10:14:35 +02002642 display_fault_maps(msg->l2h, msgb_l2len(msg), &o2h->mo);
Harald Welte9a311ec2011-02-12 12:33:06 +01002643 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_FAULT_REP_ACK);
2644 break;
2645 case OM2K_MSGT_NEGOT_REQ:
2646 rc = om2k_rx_negot_req(msg);
2647 break;
2648 case OM2K_MSGT_START_RES:
Harald Welte591e1d72016-07-09 22:20:57 +02002649 /* common processing here */
2650 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_START_RES_ACK);
2651 /* below we dispatch into MO */
Harald Welte9a311ec2011-02-12 12:33:06 +01002652 break;
2653 case OM2K_MSGT_IS_CONF_RES:
2654 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_IS_CONF_RES_ACK);
2655 break;
Harald Weltefdb71942011-02-14 15:31:43 +01002656 case OM2K_MSGT_CON_CONF_RES:
2657 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_CON_CONF_RES_ACK);
2658 break;
Harald Weltea0ce3492011-03-05 14:13:14 +01002659 case OM2K_MSGT_TX_CONF_RES:
2660 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_TX_CONF_RES_ACK);
2661 break;
2662 case OM2K_MSGT_RX_CONF_RES:
2663 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_RX_CONF_RES_ACK);
2664 break;
2665 case OM2K_MSGT_TS_CONF_RES:
2666 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_TS_CONF_RES_ACK);
2667 break;
Harald Weltef9cf9612011-03-05 14:36:47 +01002668 case OM2K_MSGT_TF_CONF_RES:
2669 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_TF_CONF_RES_ACK);
Harald Welte9a311ec2011-02-12 12:33:06 +01002670 break;
Harald Welteb3d70fd2011-02-13 12:43:44 +01002671 case OM2K_MSGT_ENABLE_RES:
2672 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_ENABLE_RES_ACK);
2673 break;
Harald Weltefdb71942011-02-14 15:31:43 +01002674 case OM2K_MSGT_DISABLE_RES:
2675 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_DISABLE_RES_ACK);
2676 break;
2677 case OM2K_MSGT_TEST_RES:
2678 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_TEST_RES_ACK);
Harald Welte9a311ec2011-02-12 12:33:06 +01002679 break;
root45799782016-10-15 21:24:57 +02002680 case OM2K_MSGT_CAPA_RES:
2681 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_CAPA_RES_ACK);
2682 break;
Harald Welte591e1d72016-07-09 22:20:57 +02002683 /* ERrors */
Harald Weltee6e83832011-03-05 17:52:09 +01002684 case OM2K_MSGT_START_REQ_REJ:
Harald Welte3ede7232011-03-05 17:58:13 +01002685 case OM2K_MSGT_CONNECT_REJ:
Harald Welteaff63bc2011-03-05 19:42:16 +01002686 case OM2K_MSGT_OP_INFO_REJ:
Harald Welte3ede7232011-03-05 17:58:13 +01002687 case OM2K_MSGT_DISCONNECT_REJ:
Harald Welteaff63bc2011-03-05 19:42:16 +01002688 case OM2K_MSGT_TEST_REQ_REJ:
Harald Weltee6e83832011-03-05 17:52:09 +01002689 case OM2K_MSGT_CON_CONF_REQ_REJ:
2690 case OM2K_MSGT_IS_CONF_REQ_REJ:
2691 case OM2K_MSGT_TX_CONF_REQ_REJ:
2692 case OM2K_MSGT_RX_CONF_REQ_REJ:
2693 case OM2K_MSGT_TS_CONF_REQ_REJ:
2694 case OM2K_MSGT_TF_CONF_REQ_REJ:
2695 case OM2K_MSGT_ENABLE_REQ_REJ:
2696 case OM2K_MSGT_ALARM_STATUS_REQ_REJ:
2697 case OM2K_MSGT_DISABLE_REQ_REJ:
2698 rc = om2k_rx_nack(msg);
2699 break;
Harald Welte9a311ec2011-02-12 12:33:06 +01002700 }
2701
Harald Welte591e1d72016-07-09 22:20:57 +02002702 /* Resolve the MO for this message */
2703 mo = get_om2k_mo(bts, &o2h->mo);
2704 if (!mo) {
2705 LOGP(DNM, LOGL_ERROR, "Couldn't resolve MO for OM2K msg "
2706 "%s: %s\n", get_value_string(om2k_msgcode_vals, msg_type),
2707 msgb_hexdump(msg));
2708 return 0;
2709 }
Alexander Couzens3521af72016-11-02 02:41:41 +01002710 if (!mo->fsm) {
2711 LOGP(DNM, LOGL_ERROR, "MO object should not generate any message. fsm == NULL "
2712 "%s: %s\n", get_value_string(om2k_msgcode_vals, msg_type),
2713 msgb_hexdump(msg));
2714 return 0;
2715 }
Harald Welte591e1d72016-07-09 22:20:57 +02002716
2717 /* Dispatch message to that MO */
2718 om2k_mo_fsm_recvmsg(bts, mo, &odm);
2719
Harald Welte9a311ec2011-02-12 12:33:06 +01002720 msgb_free(msg);
2721 return rc;
2722}
Harald Welte591e1d72016-07-09 22:20:57 +02002723
2724static void om2k_mo_init(struct om2k_mo *mo, uint8_t class,
2725 uint8_t bts_nr, uint8_t assoc_so, uint8_t inst)
2726{
2727 mo->addr.class = class;
2728 mo->addr.bts = bts_nr;
2729 mo->addr.assoc_so = assoc_so;
2730 mo->addr.inst = inst;
2731}
2732
2733/* initialize the OM2K_MO members of gsm_bts_trx and its timeslots */
2734void abis_om2k_trx_init(struct gsm_bts_trx *trx)
2735{
2736 struct gsm_bts *bts = trx->bts;
2737 unsigned int i;
2738
2739 OSMO_ASSERT(bts->type == GSM_BTS_TYPE_RBS2000);
2740
2741 om2k_mo_init(&trx->rbs2000.trxc.om2k_mo, OM2K_MO_CLS_TRXC,
2742 bts->nr, 255, trx->nr);
2743 om2k_mo_init(&trx->rbs2000.tx.om2k_mo, OM2K_MO_CLS_TX,
2744 bts->nr, 255, trx->nr);
2745 om2k_mo_init(&trx->rbs2000.rx.om2k_mo, OM2K_MO_CLS_RX,
2746 bts->nr, 255, trx->nr);
2747
2748 for (i = 0; i < ARRAY_SIZE(trx->ts); i++) {
2749 om2k_mo_init(&trx->ts[i].rbs2000.om2k_mo, OM2K_MO_CLS_TS,
2750 bts->nr, trx->nr, i);
2751 }
2752}
2753
2754/* initialize the OM2K_MO members of gsm_bts */
2755void abis_om2k_bts_init(struct gsm_bts *bts)
2756{
2757 OSMO_ASSERT(bts->type == GSM_BTS_TYPE_RBS2000);
2758
2759 om2k_mo_init(&bts->rbs2000.cf.om2k_mo, OM2K_MO_CLS_CF,
2760 bts->nr, 0xFF, 0);
2761 om2k_mo_init(&bts->rbs2000.is.om2k_mo, OM2K_MO_CLS_IS,
2762 bts->nr, 0xFF, 0);
2763 om2k_mo_init(&bts->rbs2000.con.om2k_mo, OM2K_MO_CLS_CON,
2764 bts->nr, 0xFF, 0);
2765 om2k_mo_init(&bts->rbs2000.dp.om2k_mo, OM2K_MO_CLS_DP,
2766 bts->nr, 0xFF, 0);
2767 om2k_mo_init(&bts->rbs2000.tf.om2k_mo, OM2K_MO_CLS_TF,
2768 bts->nr, 0xFF, 0);
2769}
2770
2771static __attribute__((constructor)) void abis_om2k_init(void)
2772{
2773 osmo_fsm_register(&om2k_mo_fsm);
2774 osmo_fsm_register(&om2k_bts_fsm);
2775 osmo_fsm_register(&om2k_trx_fsm);
2776}