blob: 6105fec4e4388949531d8df54e9126e840ae2b8a [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 Welte73541072011-02-12 13:44:14 +010042#include <openbsc/abis_om2000.h>
Harald Welte9a311ec2011-02-12 12:33:06 +010043#include <openbsc/signal.h>
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +020044#include <osmocom/abis/e1_input.h>
Harald Welte9a311ec2011-02-12 12:33:06 +010045
Harald Welte591e1d72016-07-09 22:20:57 +020046/* FIXME: move to libosmocore */
47struct osmo_fsm_inst *osmo_fsm_inst_alloc_child_id(struct osmo_fsm *fsm,
48 struct osmo_fsm_inst *parent,
49 uint32_t parent_term_event,
50 const char *id)
51{
52 struct osmo_fsm_inst *fi;
53
54 fi = osmo_fsm_inst_alloc(fsm, parent, NULL, parent->log_level,
55 id ? id : parent->id);
56 if (!fi) {
57 /* indicate immediate termination to caller */
58 osmo_fsm_inst_dispatch(parent, parent_term_event, NULL);
59 return NULL;
60 }
61
62 LOGPFSM(fi, "is child of %s\n", osmo_fsm_inst_name(parent));
63
64 fi->proc.parent = parent;
65 fi->proc.parent_term_event = parent_term_event;
66 llist_add(&fi->proc.child, &parent->proc.children);
67
68 return fi;
69}
70
71
Harald Welte9a311ec2011-02-12 12:33:06 +010072#define OM_ALLOC_SIZE 1024
73#define OM_HEADROOM_SIZE 128
74
Harald Welte591e1d72016-07-09 22:20:57 +020075#define OM2K_TIMEOUT 10
76#define TRX_FSM_TIMEOUT 60
77#define BTS_FSM_TIMEOUT 60
78
Harald Welte9a311ec2011-02-12 12:33:06 +010079/* use following functions from abis_nm.c:
80 * om2k_msgb_alloc()
Harald Weltebc867d92011-02-12 13:09:38 +010081 * abis_om2k_sendmsg()
Harald Welte9a311ec2011-02-12 12:33:06 +010082 */
83
Harald Welte9a311ec2011-02-12 12:33:06 +010084struct abis_om2k_hdr {
85 struct abis_om_hdr om;
86 uint16_t msg_type;
87 struct abis_om2k_mo mo;
88 uint8_t data[0];
89} __attribute__ ((packed));
90
91enum abis_om2k_msgtype {
92 OM2K_MSGT_ABORT_SP_CMD = 0x0000,
93 OM2K_MSGT_ABORT_SP_COMPL = 0x0002,
94 OM2K_MSGT_ALARM_REP_ACK = 0x0004,
95 OM2K_MSGT_ALARM_REP_NACK = 0x0005,
96 OM2K_MSGT_ALARM_REP = 0x0006,
97 OM2K_MSGT_ALARM_STATUS_REQ = 0x0008,
98 OM2K_MSGT_ALARM_STATUS_REQ_ACK = 0x000a,
99 OM2K_MSGT_ALARM_STATUS_REQ_REJ = 0x000b,
100 OM2K_MSGT_ALARM_STATUS_RES_ACK = 0x000c,
101 OM2K_MSGT_ALARM_STATUS_RES_NACK = 0x000d,
102 OM2K_MSGT_ALARM_STATUS_RES = 0x000e,
103 OM2K_MSGT_CAL_TIME_RESP = 0x0010,
104 OM2K_MSGT_CAL_TIME_REJ = 0x0011,
105 OM2K_MSGT_CAL_TIME_REQ = 0x0012,
106
Harald Weltefdb71942011-02-14 15:31:43 +0100107 OM2K_MSGT_CON_CONF_REQ = 0x0014,
108 OM2K_MSGT_CON_CONF_REQ_ACK = 0x0016,
109 OM2K_MSGT_CON_CONF_REQ_REJ = 0x0017,
110 OM2K_MSGT_CON_CONF_RES_ACK = 0x0018,
111 OM2K_MSGT_CON_CONF_RES_NACK = 0x0019,
112 OM2K_MSGT_CON_CONF_RES = 0x001a,
113
Harald Welte9a311ec2011-02-12 12:33:06 +0100114 OM2K_MSGT_CONNECT_CMD = 0x001c,
115 OM2K_MSGT_CONNECT_COMPL = 0x001e,
116 OM2K_MSGT_CONNECT_REJ = 0x001f,
117
Harald Welte0741ffe2011-02-12 18:48:53 +0100118 OM2K_MSGT_DISABLE_REQ = 0x0028,
119 OM2K_MSGT_DISABLE_REQ_ACK = 0x002a,
120 OM2K_MSGT_DISABLE_REQ_REJ = 0x002b,
121 OM2K_MSGT_DISABLE_RES_ACK = 0x002c,
122 OM2K_MSGT_DISABLE_RES_NACK = 0x002d,
123 OM2K_MSGT_DISABLE_RES = 0x002e,
Harald Welte6fec79d2011-02-12 14:57:17 +0100124 OM2K_MSGT_DISCONNECT_CMD = 0x0030,
125 OM2K_MSGT_DISCONNECT_COMPL = 0x0032,
126 OM2K_MSGT_DISCONNECT_REJ = 0x0033,
Harald Welte0741ffe2011-02-12 18:48:53 +0100127 OM2K_MSGT_ENABLE_REQ = 0x0034,
128 OM2K_MSGT_ENABLE_REQ_ACK = 0x0036,
129 OM2K_MSGT_ENABLE_REQ_REJ = 0x0037,
130 OM2K_MSGT_ENABLE_RES_ACK = 0x0038,
131 OM2K_MSGT_ENABLE_RES_NACK = 0x0039,
132 OM2K_MSGT_ENABLE_RES = 0x003a,
Harald Welte6fec79d2011-02-12 14:57:17 +0100133
Harald Welte9a311ec2011-02-12 12:33:06 +0100134 OM2K_MSGT_FAULT_REP_ACK = 0x0040,
135 OM2K_MSGT_FAULT_REP_NACK = 0x0041,
136 OM2K_MSGT_FAULT_REP = 0x0042,
137
138 OM2K_MSGT_IS_CONF_REQ = 0x0060,
139 OM2K_MSGT_IS_CONF_REQ_ACK = 0x0062,
140 OM2K_MSGT_IS_CONF_REQ_REJ = 0x0063,
141 OM2K_MSGT_IS_CONF_RES_ACK = 0x0064,
142 OM2K_MSGT_IS_CONF_RES_NACK = 0x0065,
143 OM2K_MSGT_IS_CONF_RES = 0x0066,
144
145 OM2K_MSGT_OP_INFO = 0x0074,
146 OM2K_MSGT_OP_INFO_ACK = 0x0076,
147 OM2K_MSGT_OP_INFO_REJ = 0x0077,
148 OM2K_MSGT_RESET_CMD = 0x0078,
149 OM2K_MSGT_RESET_COMPL = 0x007a,
150 OM2K_MSGT_RESET_REJ = 0x007b,
Harald Weltea0ce3492011-03-05 14:13:14 +0100151 OM2K_MSGT_RX_CONF_REQ = 0x007c,
152 OM2K_MSGT_RX_CONF_REQ_ACK = 0x007e,
153 OM2K_MSGT_RX_CONF_REQ_REJ = 0x007f,
154 OM2K_MSGT_RX_CONF_RES_ACK = 0x0080,
155 OM2K_MSGT_RX_CONF_RES_NACK = 0x0081,
156 OM2K_MSGT_RX_CONF_RES = 0x0082,
Harald Welte9a311ec2011-02-12 12:33:06 +0100157 OM2K_MSGT_START_REQ = 0x0084,
158 OM2K_MSGT_START_REQ_ACK = 0x0086,
159 OM2K_MSGT_START_REQ_REJ = 0x0087,
160 OM2K_MSGT_START_RES_ACK = 0x0088,
161 OM2K_MSGT_START_RES_NACK = 0x0089,
162 OM2K_MSGT_START_RES = 0x008a,
Harald Weltee1d5eca2011-02-12 14:42:59 +0100163 OM2K_MSGT_STATUS_REQ = 0x008c,
164 OM2K_MSGT_STATUS_RESP = 0x008e,
165 OM2K_MSGT_STATUS_REJ = 0x008f,
Harald Welte9a311ec2011-02-12 12:33:06 +0100166
Harald Welte8024d8f2011-02-12 15:07:30 +0100167 OM2K_MSGT_TEST_REQ = 0x0094,
168 OM2K_MSGT_TEST_REQ_ACK = 0x0096,
169 OM2K_MSGT_TEST_REQ_REJ = 0x0097,
170 OM2K_MSGT_TEST_RES_ACK = 0x0098,
171 OM2K_MSGT_TEST_RES_NACK = 0x0099,
172 OM2K_MSGT_TEST_RES = 0x009a,
173
Harald Weltef9cf9612011-03-05 14:36:47 +0100174 OM2K_MSGT_TF_CONF_REQ = 0x00a0,
175 OM2K_MSGT_TF_CONF_REQ_ACK = 0x00a2,
176 OM2K_MSGT_TF_CONF_REQ_REJ = 0x00a3,
177 OM2K_MSGT_TF_CONF_RES_ACK = 0x00a4,
178 OM2K_MSGT_TF_CONF_RES_NACK = 0x00a5,
179 OM2K_MSGT_TF_CONF_RES = 0x00a6,
Harald Weltea0ce3492011-03-05 14:13:14 +0100180 OM2K_MSGT_TS_CONF_REQ = 0x00a8,
181 OM2K_MSGT_TS_CONF_REQ_ACK = 0x00aa,
182 OM2K_MSGT_TS_CONF_REQ_REJ = 0x00ab,
183 OM2K_MSGT_TS_CONF_RES_ACK = 0x00ac,
184 OM2K_MSGT_TS_CONF_RES_NACK = 0x00ad,
185 OM2K_MSGT_TS_CONF_RES = 0x00ae,
186 OM2K_MSGT_TX_CONF_REQ = 0x00b0,
187 OM2K_MSGT_TX_CONF_REQ_ACK = 0x00b2,
188 OM2K_MSGT_TX_CONF_REQ_REJ = 0x00b3,
189 OM2K_MSGT_TX_CONF_RES_ACK = 0x00b4,
190 OM2K_MSGT_TX_CONF_RES_NACK = 0x00b5,
191 OM2K_MSGT_TX_CONF_RES = 0x00b6,
192
root45799782016-10-15 21:24:57 +0200193 OM2K_MSGT_CAPA_REQ = 0x00e8,
194 OM2K_MSGT_CAPA_REQ_ACK = 0x00ea,
195 OM2K_MSGT_CAPA_REQ_REJ = 0x00eb,
196 OM2K_MSGT_CAPA_RES = 0x00ee,
197 OM2K_MSGT_CAPA_RES_ACK = 0x00ec,
198 OM2K_MSGT_CAPA_RES_NACK = 0x00ed,
199
Harald Welte9a311ec2011-02-12 12:33:06 +0100200 OM2K_MSGT_NEGOT_REQ_ACK = 0x0104,
201 OM2K_MSGT_NEGOT_REQ_NACK = 0x0105,
202 OM2K_MSGT_NEGOT_REQ = 0x0106,
203};
204
205enum abis_om2k_dei {
Harald Weltee898ecc2011-03-06 19:26:11 +0100206 OM2K_DEI_ACCORDANCE_IND = 0x00,
Harald Weltea0ce3492011-03-05 14:13:14 +0100207 OM2K_DEI_BCC = 0x06,
Harald Welte1164dce2011-03-05 19:21:26 +0100208 OM2K_DEI_BS_AG_BKS_RES = 0x07,
Harald Weltea0ce3492011-03-05 14:13:14 +0100209 OM2K_DEI_BSIC = 0x09,
Harald Welte1164dce2011-03-05 19:21:26 +0100210 OM2K_DEI_BA_PA_MFRMS = 0x0a,
211 OM2K_DEI_CBCH_INDICATOR = 0x0b,
212 OM2K_DEI_CCCH_OPTIONS = 0x0c,
Harald Welte9a311ec2011-02-12 12:33:06 +0100213 OM2K_DEI_CAL_TIME = 0x0d,
Harald Weltea0ce3492011-03-05 14:13:14 +0100214 OM2K_DEI_COMBINATION = 0x0f,
Harald Weltefdb71942011-02-14 15:31:43 +0100215 OM2K_DEI_CON_CONN_LIST = 0x10,
Harald Welte1164dce2011-03-05 19:21:26 +0100216 OM2K_DEI_DRX_DEV_MAX = 0x12,
Harald Welte8bcb1a02011-02-12 20:23:40 +0100217 OM2K_DEI_END_LIST_NR = 0x13,
Harald Weltef6d6b212011-03-05 20:13:52 +0100218 OM2K_DEI_EXT_COND_MAP_1 = 0x14,
219 OM2K_DEI_EXT_COND_MAP_2 = 0x15,
Harald Weltea0ce3492011-03-05 14:13:14 +0100220 OM2K_DEI_FILLING_MARKER = 0x1c,
221 OM2K_DEI_FN_OFFSET = 0x1d,
222 OM2K_DEI_FREQ_LIST = 0x1e,
223 OM2K_DEI_FREQ_SPEC_RX = 0x1f,
224 OM2K_DEI_FREQ_SPEC_TX = 0x20,
225 OM2K_DEI_HSN = 0x21,
Harald Welte1164dce2011-03-05 19:21:26 +0100226 OM2K_DEI_ICM_INDICATOR = 0x22,
Harald Weltef6d6b212011-03-05 20:13:52 +0100227 OM2K_DEI_INT_FAULT_MAP_1A = 0x23,
228 OM2K_DEI_INT_FAULT_MAP_1B = 0x24,
229 OM2K_DEI_INT_FAULT_MAP_2A = 0x25,
230 OM2K_DEI_INT_FAULT_MAP_2A_EXT = 0x26,
Harald Welte8bcb1a02011-02-12 20:23:40 +0100231 OM2K_DEI_IS_CONN_LIST = 0x27,
232 OM2K_DEI_LIST_NR = 0x28,
Harald Weltef6d6b212011-03-05 20:13:52 +0100233 OM2K_DEI_LOCAL_ACCESS = 0x2a,
Harald Weltea0ce3492011-03-05 14:13:14 +0100234 OM2K_DEI_MAIO = 0x2b,
Harald Weltef6d6b212011-03-05 20:13:52 +0100235 OM2K_DEI_MO_STATE = 0x2c,
Harald Welte1164dce2011-03-05 19:21:26 +0100236 OM2K_DEI_NY1 = 0x2d,
Harald Welte9a311ec2011-02-12 12:33:06 +0100237 OM2K_DEI_OP_INFO = 0x2e,
Harald Weltea0ce3492011-03-05 14:13:14 +0100238 OM2K_DEI_POWER = 0x2f,
Harald Weltee6e83832011-03-05 17:52:09 +0100239 OM2K_DEI_REASON_CODE = 0x32,
Harald Weltea0ce3492011-03-05 14:13:14 +0100240 OM2K_DEI_RX_DIVERSITY = 0x33,
Philipp8136e4b2016-10-19 10:14:35 +0200241 OM2K_DEI_REPL_UNIT_MAP = 0x34,
Harald Weltee6e83832011-03-05 17:52:09 +0100242 OM2K_DEI_RESULT_CODE = 0x35,
Harald Welte1164dce2011-03-05 19:21:26 +0100243 OM2K_DEI_T3105 = 0x38,
Harald Weltef9cf9612011-03-05 14:36:47 +0100244 OM2K_DEI_TF_MODE = 0x3a,
Harald Weltea0ce3492011-03-05 14:13:14 +0100245 OM2K_DEI_TS_NR = 0x3c,
Harald Welte1164dce2011-03-05 19:21:26 +0100246 OM2K_DEI_TSC = 0x3d,
Harald Weltef6d6b212011-03-05 20:13:52 +0100247 OM2K_DEI_BTS_VERSION = 0x40,
248 OM2K_DEI_OML_IWD_VERSION = 0x41,
249 OM2K_DEI_RSL_IWD_VERSION = 0x42,
250 OM2K_DEI_OML_FUNC_MAP_1 = 0x43,
251 OM2K_DEI_OML_FUNC_MAP_2 = 0x44,
252 OM2K_DEI_RSL_FUNC_MAP_1 = 0x45,
253 OM2K_DEI_RSL_FUNC_MAP_2 = 0x46,
Harald Weltea0ce3492011-03-05 14:13:14 +0100254 OM2K_DEI_EXT_RANGE = 0x47,
Harald Weltef6d6b212011-03-05 20:13:52 +0100255 OM2K_DEI_REQ_IND = 0x48,
Philipp8136e4b2016-10-19 10:14:35 +0200256 OM2K_DEI_REPL_UNIT_MAP_EXT = 0x50,
Harald Welte75755c52011-03-05 20:38:35 +0100257 OM2K_DEI_ICM_BOUND_PARAMS = 0x74,
Harald Welte1164dce2011-03-05 19:21:26 +0100258 OM2K_DEI_LSC = 0x79,
259 OM2K_DEI_LSC_FILT_TIME = 0x7a,
260 OM2K_DEI_CALL_SUPV_TIME = 0x7b,
Harald Welte75755c52011-03-05 20:38:35 +0100261 OM2K_DEI_ICM_CHAN_RATE = 0x7e,
Harald Weltef6d6b212011-03-05 20:13:52 +0100262 OM2K_DEI_HW_INFO_SIG = 0x84,
Harald Welteba9adbb2011-03-06 19:01:16 +0100263 OM2K_DEI_TF_SYNC_SRC = 0x86,
Harald Welte1164dce2011-03-05 19:21:26 +0100264 OM2K_DEI_TTA = 0x87,
Harald Weltef6d6b212011-03-05 20:13:52 +0100265 OM2K_DEI_CAPA_SIG = 0x8a,
Harald Welte73541072011-02-12 13:44:14 +0100266 OM2K_DEI_NEGOT_REC1 = 0x90,
267 OM2K_DEI_NEGOT_REC2 = 0x91,
Harald Welte1164dce2011-03-05 19:21:26 +0100268 OM2K_DEI_ENCR_ALG = 0x92,
269 OM2K_DEI_INTERF_REJ_COMB = 0x94,
Harald Weltef9cf9612011-03-05 14:36:47 +0100270 OM2K_DEI_FS_OFFSET = 0x98,
Harald Weltef6d6b212011-03-05 20:13:52 +0100271 OM2K_DEI_EXT_COND_MAP_2_EXT = 0x9c,
Philipp8136e4b2016-10-19 10:14:35 +0200272 OM2K_DEI_TSS_MO_STATE = 0x9d,
Harald Welte9a311ec2011-02-12 12:33:06 +0100273};
274
Harald Weltee6e83832011-03-05 17:52:09 +0100275const struct tlv_definition om2k_att_tlvdef = {
276 .def = {
Harald Weltee898ecc2011-03-06 19:26:11 +0100277 [OM2K_DEI_ACCORDANCE_IND] = { TLV_TYPE_TV },
Harald Weltee6e83832011-03-05 17:52:09 +0100278 [OM2K_DEI_BCC] = { TLV_TYPE_TV },
Harald Welte1164dce2011-03-05 19:21:26 +0100279 [OM2K_DEI_BS_AG_BKS_RES] = { TLV_TYPE_TV },
Harald Weltee6e83832011-03-05 17:52:09 +0100280 [OM2K_DEI_BSIC] = { TLV_TYPE_TV },
Harald Welte1164dce2011-03-05 19:21:26 +0100281 [OM2K_DEI_BA_PA_MFRMS] = { TLV_TYPE_TV },
282 [OM2K_DEI_CBCH_INDICATOR] = { TLV_TYPE_TV },
Harald Weltef6d6b212011-03-05 20:13:52 +0100283 [OM2K_DEI_INT_FAULT_MAP_1A] = { TLV_TYPE_FIXED, 6 },
284 [OM2K_DEI_INT_FAULT_MAP_1B] = { TLV_TYPE_FIXED, 6 },
285 [OM2K_DEI_INT_FAULT_MAP_2A] = { TLV_TYPE_FIXED, 6 },
286 [OM2K_DEI_INT_FAULT_MAP_2A_EXT]={ TLV_TYPE_FIXED, 6 },
Harald Welte1164dce2011-03-05 19:21:26 +0100287 [OM2K_DEI_CCCH_OPTIONS] = { TLV_TYPE_TV },
Harald Weltee6e83832011-03-05 17:52:09 +0100288 [OM2K_DEI_CAL_TIME] = { TLV_TYPE_FIXED, 6 },
289 [OM2K_DEI_COMBINATION] = { TLV_TYPE_TV },
290 [OM2K_DEI_CON_CONN_LIST] = { TLV_TYPE_TLV },
Harald Welte1164dce2011-03-05 19:21:26 +0100291 [OM2K_DEI_DRX_DEV_MAX] = { TLV_TYPE_TV },
Harald Weltee6e83832011-03-05 17:52:09 +0100292 [OM2K_DEI_END_LIST_NR] = { TLV_TYPE_TV },
Harald Weltef6d6b212011-03-05 20:13:52 +0100293 [OM2K_DEI_EXT_COND_MAP_1] = { TLV_TYPE_FIXED, 2 },
294 [OM2K_DEI_EXT_COND_MAP_2] = { TLV_TYPE_FIXED, 2 },
Harald Weltee6e83832011-03-05 17:52:09 +0100295 [OM2K_DEI_FILLING_MARKER] = { TLV_TYPE_TV },
296 [OM2K_DEI_FN_OFFSET] = { TLV_TYPE_FIXED, 2 },
297 [OM2K_DEI_FREQ_LIST] = { TLV_TYPE_TLV },
298 [OM2K_DEI_FREQ_SPEC_RX] = { TLV_TYPE_FIXED, 2 },
299 [OM2K_DEI_FREQ_SPEC_TX] = { TLV_TYPE_FIXED, 2 },
300 [OM2K_DEI_HSN] = { TLV_TYPE_TV },
Harald Welte1164dce2011-03-05 19:21:26 +0100301 [OM2K_DEI_ICM_INDICATOR] = { TLV_TYPE_TV },
Harald Weltee6e83832011-03-05 17:52:09 +0100302 [OM2K_DEI_IS_CONN_LIST] = { TLV_TYPE_TLV },
303 [OM2K_DEI_LIST_NR] = { TLV_TYPE_TV },
Harald Weltef6d6b212011-03-05 20:13:52 +0100304 [OM2K_DEI_LOCAL_ACCESS] = { TLV_TYPE_TV },
Harald Weltee6e83832011-03-05 17:52:09 +0100305 [OM2K_DEI_MAIO] = { TLV_TYPE_TV },
Harald Weltef6d6b212011-03-05 20:13:52 +0100306 [OM2K_DEI_MO_STATE] = { TLV_TYPE_TV },
Harald Welte1164dce2011-03-05 19:21:26 +0100307 [OM2K_DEI_NY1] = { TLV_TYPE_TV },
Harald Weltee6e83832011-03-05 17:52:09 +0100308 [OM2K_DEI_OP_INFO] = { TLV_TYPE_TV },
309 [OM2K_DEI_POWER] = { TLV_TYPE_TV },
310 [OM2K_DEI_REASON_CODE] = { TLV_TYPE_TV },
311 [OM2K_DEI_RX_DIVERSITY] = { TLV_TYPE_TV },
312 [OM2K_DEI_RESULT_CODE] = { TLV_TYPE_TV },
Harald Welte1164dce2011-03-05 19:21:26 +0100313 [OM2K_DEI_T3105] = { TLV_TYPE_TV },
Harald Weltee6e83832011-03-05 17:52:09 +0100314 [OM2K_DEI_TF_MODE] = { TLV_TYPE_TV },
315 [OM2K_DEI_TS_NR] = { TLV_TYPE_TV },
Harald Welte1164dce2011-03-05 19:21:26 +0100316 [OM2K_DEI_TSC] = { TLV_TYPE_TV },
Harald Weltef6d6b212011-03-05 20:13:52 +0100317 [OM2K_DEI_BTS_VERSION] = { TLV_TYPE_FIXED, 12 },
318 [OM2K_DEI_OML_IWD_VERSION] = { TLV_TYPE_FIXED, 6 },
319 [OM2K_DEI_RSL_IWD_VERSION] = { TLV_TYPE_FIXED, 6 },
320 [OM2K_DEI_OML_FUNC_MAP_1] = { TLV_TYPE_TLV },
321 [OM2K_DEI_OML_FUNC_MAP_2] = { TLV_TYPE_TLV },
322 [OM2K_DEI_RSL_FUNC_MAP_1] = { TLV_TYPE_TLV },
323 [OM2K_DEI_RSL_FUNC_MAP_2] = { TLV_TYPE_TLV },
Harald Weltee6e83832011-03-05 17:52:09 +0100324 [OM2K_DEI_EXT_RANGE] = { TLV_TYPE_TV },
Harald Weltef6d6b212011-03-05 20:13:52 +0100325 [OM2K_DEI_REQ_IND] = { TLV_TYPE_TV },
326 [OM2K_DEI_REPL_UNIT_MAP] = { TLV_TYPE_FIXED, 6 },
Philipp8136e4b2016-10-19 10:14:35 +0200327 [OM2K_DEI_REPL_UNIT_MAP_EXT] = {TLV_TYPE_FIXED, 6},
Harald Welte75755c52011-03-05 20:38:35 +0100328 [OM2K_DEI_ICM_BOUND_PARAMS] = { TLV_TYPE_FIXED, 5 },
Harald Welte1164dce2011-03-05 19:21:26 +0100329 [OM2K_DEI_LSC] = { TLV_TYPE_TV },
330 [OM2K_DEI_LSC_FILT_TIME] = { TLV_TYPE_TV },
331 [OM2K_DEI_CALL_SUPV_TIME] = { TLV_TYPE_TV },
Harald Welte75755c52011-03-05 20:38:35 +0100332 [OM2K_DEI_ICM_CHAN_RATE] = { TLV_TYPE_TV },
Harald Weltef6d6b212011-03-05 20:13:52 +0100333 [OM2K_DEI_HW_INFO_SIG] = { TLV_TYPE_FIXED, 2 },
Harald Welteba9adbb2011-03-06 19:01:16 +0100334 [OM2K_DEI_TF_SYNC_SRC] = { TLV_TYPE_TV },
Harald Welte1164dce2011-03-05 19:21:26 +0100335 [OM2K_DEI_TTA] = { TLV_TYPE_TV },
Harald Weltef6d6b212011-03-05 20:13:52 +0100336 [OM2K_DEI_CAPA_SIG] = { TLV_TYPE_FIXED, 2 },
Harald Weltee6e83832011-03-05 17:52:09 +0100337 [OM2K_DEI_NEGOT_REC1] = { TLV_TYPE_TLV },
338 [OM2K_DEI_NEGOT_REC2] = { TLV_TYPE_TLV },
Harald Welte1164dce2011-03-05 19:21:26 +0100339 [OM2K_DEI_ENCR_ALG] = { TLV_TYPE_TV },
340 [OM2K_DEI_INTERF_REJ_COMB] = { TLV_TYPE_TV },
Harald Weltee6e83832011-03-05 17:52:09 +0100341 [OM2K_DEI_FS_OFFSET] = { TLV_TYPE_FIXED, 5 },
Harald Weltef6d6b212011-03-05 20:13:52 +0100342 [OM2K_DEI_EXT_COND_MAP_2_EXT] = { TLV_TYPE_FIXED, 4 },
Philipp8136e4b2016-10-19 10:14:35 +0200343 [OM2K_DEI_TSS_MO_STATE] = { TLV_TYPE_FIXED, 4 },
Harald Weltee6e83832011-03-05 17:52:09 +0100344 },
345};
346
Harald Welte9a311ec2011-02-12 12:33:06 +0100347static const struct value_string om2k_msgcode_vals[] = {
348 { 0x0000, "Abort SP Command" },
349 { 0x0002, "Abort SP Complete" },
350 { 0x0004, "Alarm Report ACK" },
351 { 0x0005, "Alarm Report NACK" },
352 { 0x0006, "Alarm Report" },
353 { 0x0008, "Alarm Status Request" },
354 { 0x000a, "Alarm Status Request Accept" },
355 { 0x000b, "Alarm Status Request Reject" },
356 { 0x000c, "Alarm Status Result ACK" },
357 { 0x000d, "Alarm Status Result NACK" },
358 { 0x000e, "Alarm Status Result" },
359 { 0x0010, "Calendar Time Response" },
360 { 0x0011, "Calendar Time Reject" },
361 { 0x0012, "Calendar Time Request" },
362 { 0x0014, "CON Configuration Request" },
363 { 0x0016, "CON Configuration Request Accept" },
364 { 0x0017, "CON Configuration Request Reject" },
365 { 0x0018, "CON Configuration Result ACK" },
366 { 0x0019, "CON Configuration Result NACK" },
367 { 0x001a, "CON Configuration Result" },
368 { 0x001c, "Connect Command" },
369 { 0x001e, "Connect Complete" },
Harald Welte3ede7232011-03-05 17:58:13 +0100370 { 0x001f, "Connect Reject" },
Harald Welte9a311ec2011-02-12 12:33:06 +0100371 { 0x0028, "Disable Request" },
372 { 0x002a, "Disable Request Accept" },
373 { 0x002b, "Disable Request Reject" },
374 { 0x002c, "Disable Result ACK" },
375 { 0x002d, "Disable Result NACK" },
376 { 0x002e, "Disable Result" },
377 { 0x0030, "Disconnect Command" },
378 { 0x0032, "Disconnect Complete" },
379 { 0x0033, "Disconnect Reject" },
380 { 0x0034, "Enable Request" },
381 { 0x0036, "Enable Request Accept" },
382 { 0x0037, "Enable Request Reject" },
383 { 0x0038, "Enable Result ACK" },
384 { 0x0039, "Enable Result NACK" },
385 { 0x003a, "Enable Result" },
386 { 0x003c, "Escape Downlink Normal" },
387 { 0x003d, "Escape Downlink NACK" },
388 { 0x003e, "Escape Uplink Normal" },
389 { 0x003f, "Escape Uplink NACK" },
390 { 0x0040, "Fault Report ACK" },
391 { 0x0041, "Fault Report NACK" },
392 { 0x0042, "Fault Report" },
393 { 0x0044, "File Package End Command" },
394 { 0x0046, "File Package End Result" },
395 { 0x0047, "File Package End Reject" },
396 { 0x0048, "File Relation Request" },
397 { 0x004a, "File Relation Response" },
398 { 0x004b, "File Relation Request Reject" },
399 { 0x004c, "File Segment Transfer" },
400 { 0x004e, "File Segment Transfer Complete" },
401 { 0x004f, "File Segment Transfer Reject" },
402 { 0x0050, "HW Information Request" },
403 { 0x0052, "HW Information Request Accept" },
404 { 0x0053, "HW Information Request Reject" },
405 { 0x0054, "HW Information Result ACK" },
406 { 0x0055, "HW Information Result NACK" },
407 { 0x0056, "HW Information Result" },
408 { 0x0060, "IS Configuration Request" },
409 { 0x0062, "IS Configuration Request Accept" },
410 { 0x0063, "IS Configuration Request Reject" },
411 { 0x0064, "IS Configuration Result ACK" },
412 { 0x0065, "IS Configuration Result NACK" },
413 { 0x0066, "IS Configuration Result" },
414 { 0x0068, "Load Data End" },
415 { 0x006a, "Load Data End Result" },
416 { 0x006b, "Load Data End Reject" },
417 { 0x006c, "Load Data Init" },
418 { 0x006e, "Load Data Init Accept" },
419 { 0x006f, "Load Data Init Reject" },
420 { 0x0070, "Loop Control Command" },
421 { 0x0072, "Loop Control Complete" },
422 { 0x0073, "Loop Control Reject" },
423 { 0x0074, "Operational Information" },
424 { 0x0076, "Operational Information Accept" },
425 { 0x0077, "Operational Information Reject" },
426 { 0x0078, "Reset Command" },
427 { 0x007a, "Reset Complete" },
428 { 0x007b, "Reset Reject" },
429 { 0x007c, "RX Configuration Request" },
430 { 0x007e, "RX Configuration Request Accept" },
431 { 0x007f, "RX Configuration Request Reject" },
432 { 0x0080, "RX Configuration Result ACK" },
433 { 0x0081, "RX Configuration Result NACK" },
434 { 0x0082, "RX Configuration Result" },
435 { 0x0084, "Start Request" },
436 { 0x0086, "Start Request Accept" },
437 { 0x0087, "Start Request Reject" },
438 { 0x0088, "Start Result ACK" },
439 { 0x0089, "Start Result NACK" },
440 { 0x008a, "Start Result" },
441 { 0x008c, "Status Request" },
442 { 0x008e, "Status Response" },
443 { 0x008f, "Status Reject" },
444 { 0x0094, "Test Request" },
445 { 0x0096, "Test Request Accept" },
446 { 0x0097, "Test Request Reject" },
447 { 0x0098, "Test Result ACK" },
448 { 0x0099, "Test Result NACK" },
449 { 0x009a, "Test Result" },
450 { 0x00a0, "TF Configuration Request" },
451 { 0x00a2, "TF Configuration Request Accept" },
452 { 0x00a3, "TF Configuration Request Reject" },
453 { 0x00a4, "TF Configuration Result ACK" },
454 { 0x00a5, "TF Configuration Result NACK" },
455 { 0x00a6, "TF Configuration Result" },
456 { 0x00a8, "TS Configuration Request" },
457 { 0x00aa, "TS Configuration Request Accept" },
458 { 0x00ab, "TS Configuration Request Reject" },
459 { 0x00ac, "TS Configuration Result ACK" },
460 { 0x00ad, "TS Configuration Result NACK" },
461 { 0x00ae, "TS Configuration Result" },
462 { 0x00b0, "TX Configuration Request" },
463 { 0x00b2, "TX Configuration Request Accept" },
464 { 0x00b3, "TX Configuration Request Reject" },
465 { 0x00b4, "TX Configuration Result ACK" },
466 { 0x00b5, "TX Configuration Result NACK" },
467 { 0x00b6, "TX Configuration Result" },
468 { 0x00bc, "DIP Alarm Report ACK" },
469 { 0x00bd, "DIP Alarm Report NACK" },
470 { 0x00be, "DIP Alarm Report" },
471 { 0x00c0, "DIP Alarm Status Request" },
472 { 0x00c2, "DIP Alarm Status Response" },
473 { 0x00c3, "DIP Alarm Status Reject" },
474 { 0x00c4, "DIP Quality Report I ACK" },
475 { 0x00c5, "DIP Quality Report I NACK" },
476 { 0x00c6, "DIP Quality Report I" },
477 { 0x00c8, "DIP Quality Report II ACK" },
478 { 0x00c9, "DIP Quality Report II NACK" },
479 { 0x00ca, "DIP Quality Report II" },
480 { 0x00dc, "DP Configuration Request" },
481 { 0x00de, "DP Configuration Request Accept" },
482 { 0x00df, "DP Configuration Request Reject" },
483 { 0x00e0, "DP Configuration Result ACK" },
484 { 0x00e1, "DP Configuration Result NACK" },
485 { 0x00e2, "DP Configuration Result" },
486 { 0x00e4, "Capabilities HW Info Report ACK" },
487 { 0x00e5, "Capabilities HW Info Report NACK" },
488 { 0x00e6, "Capabilities HW Info Report" },
489 { 0x00e8, "Capabilities Request" },
490 { 0x00ea, "Capabilities Request Accept" },
491 { 0x00eb, "Capabilities Request Reject" },
492 { 0x00ec, "Capabilities Result ACK" },
493 { 0x00ed, "Capabilities Result NACK" },
494 { 0x00ee, "Capabilities Result" },
495 { 0x00f0, "FM Configuration Request" },
496 { 0x00f2, "FM Configuration Request Accept" },
497 { 0x00f3, "FM Configuration Request Reject" },
498 { 0x00f4, "FM Configuration Result ACK" },
499 { 0x00f5, "FM Configuration Result NACK" },
500 { 0x00f6, "FM Configuration Result" },
501 { 0x00f8, "FM Report Request" },
502 { 0x00fa, "FM Report Response" },
503 { 0x00fb, "FM Report Reject" },
504 { 0x00fc, "FM Start Command" },
505 { 0x00fe, "FM Start Complete" },
506 { 0x00ff, "FM Start Reject" },
507 { 0x0100, "FM Stop Command" },
508 { 0x0102, "FM Stop Complete" },
509 { 0x0103, "FM Stop Reject" },
510 { 0x0104, "Negotiation Request ACK" },
511 { 0x0105, "Negotiation Request NACK" },
512 { 0x0106, "Negotiation Request" },
513 { 0x0108, "BTS Initiated Request ACK" },
514 { 0x0109, "BTS Initiated Request NACK" },
515 { 0x010a, "BTS Initiated Request" },
516 { 0x010c, "Radio Channels Release Command" },
517 { 0x010e, "Radio Channels Release Complete" },
518 { 0x010f, "Radio Channels Release Reject" },
519 { 0x0118, "Feature Control Command" },
520 { 0x011a, "Feature Control Complete" },
521 { 0x011b, "Feature Control Reject" },
522
523 { 0, NULL }
524};
525
526/* TS 12.21 Section 9.4: Attributes */
527static const struct value_string om2k_attr_vals[] = {
528 { 0x00, "Accordance indication" },
529 { 0x01, "Alarm Id" },
530 { 0x02, "Alarm Data" },
531 { 0x03, "Alarm Severity" },
532 { 0x04, "Alarm Status" },
533 { 0x05, "Alarm Status Type" },
534 { 0x06, "BCC" },
535 { 0x07, "BS_AG_BKS_RES" },
536 { 0x09, "BSIC" },
537 { 0x0a, "BA_PA_MFRMS" },
538 { 0x0b, "CBCH Indicator" },
539 { 0x0c, "CCCH Options" },
540 { 0x0d, "Calendar Time" },
541 { 0x0f, "Channel Combination" },
542 { 0x10, "CON Connection List" },
543 { 0x11, "Data End Indication" },
544 { 0x12, "DRX_DEV_MAX" },
545 { 0x13, "End List Number" },
546 { 0x14, "External Condition Map Class 1" },
547 { 0x15, "External Condition Map Class 2" },
548 { 0x16, "File Relation Indication" },
549 { 0x17, "File Revision" },
550 { 0x18, "File Segment Data" },
551 { 0x19, "File Segment Length" },
552 { 0x1a, "File Segment Sequence Number" },
553 { 0x1b, "File Size" },
554 { 0x1c, "Filling Marker" },
555 { 0x1d, "FN Offset" },
556 { 0x1e, "Frequency List" },
557 { 0x1f, "Frequency Specifier RX" },
558 { 0x20, "Frequency Specifier TX" },
559 { 0x21, "HSN" },
560 { 0x22, "ICM Indicator" },
561 { 0x23, "Internal Fault Map Class 1A" },
562 { 0x24, "Internal Fault Map Class 1B" },
563 { 0x25, "Internal Fault Map Class 2A" },
564 { 0x26, "Internal Fault Map Class 2A Extension" },
565 { 0x27, "IS Connection List" },
566 { 0x28, "List Number" },
567 { 0x29, "File Package State Indication" },
568 { 0x2a, "Local Access State" },
569 { 0x2b, "MAIO" },
570 { 0x2c, "MO State" },
571 { 0x2d, "Ny1" },
572 { 0x2e, "Operational Information" },
573 { 0x2f, "Power" },
574 { 0x30, "RU Position Data" },
575 { 0x31, "Protocol Error" },
576 { 0x32, "Reason Code" },
577 { 0x33, "Receiver Diversity" },
578 { 0x34, "Replacement Unit Map" },
579 { 0x35, "Result Code" },
580 { 0x36, "RU Revision Data" },
581 { 0x38, "T3105" },
582 { 0x39, "Test Loop Setting" },
583 { 0x3a, "TF Mode" },
584 { 0x3b, "TF Compensation Value" },
585 { 0x3c, "Time Slot Number" },
586 { 0x3d, "TSC" },
587 { 0x3e, "RU Logical Id" },
588 { 0x3f, "RU Serial Number Data" },
589 { 0x40, "BTS Version" },
590 { 0x41, "OML IWD Version" },
591 { 0x42, "RWL IWD Version" },
592 { 0x43, "OML Function Map 1" },
593 { 0x44, "OML Function Map 2" },
594 { 0x45, "RSL Function Map 1" },
595 { 0x46, "RSL Function Map 2" },
596 { 0x47, "Extended Range Indicator" },
597 { 0x48, "Request Indicators" },
598 { 0x49, "DIP Alarm Condition Map" },
599 { 0x4a, "ES Incoming" },
600 { 0x4b, "ES Outgoing" },
601 { 0x4e, "SES Incoming" },
602 { 0x4f, "SES Outgoing" },
603 { 0x50, "Replacement Unit Map Extension" },
604 { 0x52, "UAS Incoming" },
605 { 0x53, "UAS Outgoing" },
606 { 0x58, "DF Incoming" },
607 { 0x5a, "DF Outgoing" },
608 { 0x5c, "SF" },
609 { 0x60, "S Bits Setting" },
610 { 0x61, "CRC-4 Use Option" },
611 { 0x62, "T Parameter" },
612 { 0x63, "N Parameter" },
613 { 0x64, "N1 Parameter" },
614 { 0x65, "N3 Parameter" },
615 { 0x66, "N4 Parameter" },
616 { 0x67, "P Parameter" },
617 { 0x68, "Q Parameter" },
618 { 0x69, "BI_Q1" },
619 { 0x6a, "BI_Q2" },
620 { 0x74, "ICM Boundary Parameters" },
621 { 0x77, "AFT" },
622 { 0x78, "AFT RAI" },
623 { 0x79, "Link Supervision Control" },
624 { 0x7a, "Link Supervision Filtering Time" },
625 { 0x7b, "Call Supervision Time" },
626 { 0x7c, "Interval Length UAS Incoming" },
627 { 0x7d, "Interval Length UAS Outgoing" },
628 { 0x7e, "ICM Channel Rate" },
629 { 0x7f, "Attribute Identifier" },
630 { 0x80, "FM Frequency List" },
631 { 0x81, "FM Frequency Report" },
632 { 0x82, "FM Percentile" },
633 { 0x83, "FM Clear Indication" },
634 { 0x84, "HW Info Signature" },
635 { 0x85, "MO Record" },
636 { 0x86, "TF Synchronisation Source" },
637 { 0x87, "TTA" },
638 { 0x88, "End Segment Number" },
639 { 0x89, "Segment Number" },
640 { 0x8a, "Capabilities Signature" },
641 { 0x8c, "File Relation List" },
642 { 0x90, "Negotiation Record I" },
643 { 0x91, "Negotiation Record II" },
644 { 0x92, "Encryption Algorithm" },
645 { 0x94, "Interference Rejection Combining" },
646 { 0x95, "Dedication Information" },
647 { 0x97, "Feature Code" },
648 { 0x98, "FS Offset" },
649 { 0x99, "ESB Timeslot" },
650 { 0x9a, "Master TG Instance" },
651 { 0x9b, "Master TX Chain Delay" },
652 { 0x9c, "External Condition Class 2 Extension" },
653 { 0x9d, "TSs MO State" },
654 { 0, NULL }
655};
656
Harald Weltee1d5eca2011-02-12 14:42:59 +0100657const struct value_string om2k_mo_class_short_vals[] = {
Harald Welte9a311ec2011-02-12 12:33:06 +0100658 { 0x01, "TRXC" },
659 { 0x03, "TS" },
660 { 0x04, "TF" },
661 { 0x05, "IS" },
662 { 0x06, "CON" },
663 { 0x07, "DP" },
664 { 0x0a, "CF" },
665 { 0x0b, "TX" },
666 { 0x0c, "RX" },
667 { 0, NULL }
668};
669
Harald Welte591e1d72016-07-09 22:20:57 +0200670const struct value_string om2k_result_strings[] = {
671 { 0x02, "Wrong state or out of sequence" },
672 { 0x03, "File error" },
673 { 0x04, "Fault, unspecified" },
674 { 0x05, "Tuning fault" },
675 { 0x06, "Protocol error" },
676 { 0x07, "MO not connected" },
677 { 0x08, "Parameter error" },
678 { 0x09, "Optional function not supported" },
679 { 0x0a, "Local access state LOCALLY DISCONNECTED" },
680 { 0, NULL }
681};
682
683const struct value_string om2k_accordance_strings[] = {
684 { 0x00, "Data according to request" },
685 { 0x01, "Data not according to request" },
686 { 0x02, "Inconsistent MO data" },
687 { 0x03, "Capability constraint violation" },
688 { 0, NULL }
689};
690
691const struct value_string om2k_mostate_vals[] = {
692 { 0x00, "RESET" },
693 { 0x01, "STARTED" },
694 { 0x02, "ENABLED" },
695 { 0x03, "DISABLED" },
696 { 0, NULL }
697};
698
699/* entire decoded OM2K message (header + parsed TLV) */
700struct om2k_decoded_msg {
701 struct abis_om2k_hdr o2h;
702 uint16_t msg_type;
703 struct tlv_parsed tp;
704};
705
706/* resolve the OM2000 Managed Object by BTS + MO Address */
707static struct om2k_mo *
708get_om2k_mo(struct gsm_bts *bts, const struct abis_om2k_mo *abis_mo)
709{
710 struct om2k_mo *mo = NULL;
711 struct gsm_bts_trx *trx;
712
713 switch (abis_mo->class) {
714 case OM2K_MO_CLS_CF:
715 mo = &bts->rbs2000.cf.om2k_mo;
716 break;
717 case OM2K_MO_CLS_CON:
718 mo = &bts->rbs2000.con.om2k_mo;
719 break;
720 case OM2K_MO_CLS_IS:
721 mo = &bts->rbs2000.is.om2k_mo;
722 break;
723 case OM2K_MO_CLS_TF:
724 mo = &bts->rbs2000.tf.om2k_mo;
725 break;
726
727 case OM2K_MO_CLS_TRXC:
728 trx = gsm_bts_trx_num(bts, abis_mo->inst);
729 if (!trx)
730 return NULL;
731 mo = &trx->rbs2000.trxc.om2k_mo;
732 break;
733 case OM2K_MO_CLS_TX:
734 trx = gsm_bts_trx_num(bts, abis_mo->inst);
735 if (!trx)
736 return NULL;
737 mo = &trx->rbs2000.tx.om2k_mo;
738 break;
739 case OM2K_MO_CLS_RX:
740 trx = gsm_bts_trx_num(bts, abis_mo->inst);
741 if (!trx)
742 return NULL;
743 mo = &trx->rbs2000.rx.om2k_mo;
744 break;
745 case OM2K_MO_CLS_TS:
746 trx = gsm_bts_trx_num(bts, abis_mo->assoc_so);
747 if (!trx)
748 return NULL;
749 if (abis_mo->inst >= ARRAY_SIZE(trx->ts))
750 return NULL;
751 mo = &trx->ts[abis_mo->inst].rbs2000.om2k_mo;
752 break;
753 default:
754 return NULL;
755 };
756
757 return mo;
758}
759
Harald Welte9a311ec2011-02-12 12:33:06 +0100760static struct msgb *om2k_msgb_alloc(void)
761{
762 return msgb_alloc_headroom(OM_ALLOC_SIZE, OM_HEADROOM_SIZE,
763 "OM2000");
764}
765
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200766static int abis_om2k_tlv_parse(struct tlv_parsed *tp, const uint8_t *buf, int len)
Harald Weltee6e83832011-03-05 17:52:09 +0100767{
768 return tlv_parse(tp, &om2k_att_tlvdef, buf, len, 0, 0);
769}
770
Harald Weltee898ecc2011-03-06 19:26:11 +0100771static int abis_om2k_msg_tlv_parse(struct tlv_parsed *tp, struct abis_om2k_hdr *oh)
772{
773 return abis_om2k_tlv_parse(tp, oh->data, oh->om.length - 6);
774}
775
Harald Welte591e1d72016-07-09 22:20:57 +0200776/* decode/parse the message */
777static int om2k_decode_msg(struct om2k_decoded_msg *odm, struct msgb *msg)
778{
779 struct abis_om2k_hdr *o2h = msgb_l2(msg);
780 odm->msg_type = ntohs(o2h->msg_type);
781 odm->o2h = *o2h;
782 return abis_om2k_msg_tlv_parse(&odm->tp, o2h);
783}
784
Harald Welted88a3872011-02-14 15:26:13 +0100785static char *om2k_mo_name(const struct abis_om2k_mo *mo)
786{
787 static char mo_buf[64];
788
789 memset(mo_buf, 0, sizeof(mo_buf));
790 snprintf(mo_buf, sizeof(mo_buf), "%s/%02x/%02x/%02x",
791 get_value_string(om2k_mo_class_short_vals, mo->class),
792 mo->bts, mo->assoc_so, mo->inst);
793 return mo_buf;
794}
795
Harald Welteaf9b8102011-03-06 21:20:38 +0100796/* resolve the gsm_nm_state data structure for a given MO */
797static struct gsm_nm_state *
798mo2nm_state(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
799{
800 struct gsm_bts_trx *trx;
801 struct gsm_nm_state *nm_state = NULL;
802
803 switch (mo->class) {
804 case OM2K_MO_CLS_TRXC:
805 trx = gsm_bts_trx_num(bts, mo->assoc_so);
806 if (!trx)
807 return NULL;
Harald Welted64c0bc2011-05-30 12:07:53 +0200808 nm_state = &trx->mo.nm_state;
Harald Welteaf9b8102011-03-06 21:20:38 +0100809 break;
810 case OM2K_MO_CLS_TS:
811 trx = gsm_bts_trx_num(bts, mo->assoc_so);
812 if (!trx)
813 return NULL;
814 if (mo->inst >= ARRAY_SIZE(trx->ts))
815 return NULL;
Harald Welted64c0bc2011-05-30 12:07:53 +0200816 nm_state = &trx->ts[mo->inst].mo.nm_state;
Harald Welteaf9b8102011-03-06 21:20:38 +0100817 break;
818 case OM2K_MO_CLS_TF:
Harald Welted64c0bc2011-05-30 12:07:53 +0200819 nm_state = &bts->rbs2000.tf.mo.nm_state;
Harald Welteaf9b8102011-03-06 21:20:38 +0100820 break;
821 case OM2K_MO_CLS_IS:
Harald Welted64c0bc2011-05-30 12:07:53 +0200822 nm_state = &bts->rbs2000.is.mo.nm_state;
Harald Welteaf9b8102011-03-06 21:20:38 +0100823 break;
824 case OM2K_MO_CLS_CON:
Harald Welted64c0bc2011-05-30 12:07:53 +0200825 nm_state = &bts->rbs2000.con.mo.nm_state;
Harald Welteaf9b8102011-03-06 21:20:38 +0100826 break;
827 case OM2K_MO_CLS_DP:
Harald Welted64c0bc2011-05-30 12:07:53 +0200828 nm_state = &bts->rbs2000.con.mo.nm_state;
Harald Welteaf9b8102011-03-06 21:20:38 +0100829 break;
830 case OM2K_MO_CLS_CF:
Harald Welted64c0bc2011-05-30 12:07:53 +0200831 nm_state = &bts->mo.nm_state;
Harald Welteaf9b8102011-03-06 21:20:38 +0100832 break;
833 case OM2K_MO_CLS_TX:
834 trx = gsm_bts_trx_num(bts, mo->assoc_so);
835 if (!trx)
836 return NULL;
837 break;
838 case OM2K_MO_CLS_RX:
839 trx = gsm_bts_trx_num(bts, mo->assoc_so);
840 if (!trx)
841 return NULL;
842 break;
843 }
844
845 return nm_state;
846}
847
848static void *mo2obj(struct gsm_bts *bts, struct abis_om2k_mo *mo)
849{
850 struct gsm_bts_trx *trx;
851
852 switch (mo->class) {
853 case OM2K_MO_CLS_TX:
854 case OM2K_MO_CLS_RX:
855 case OM2K_MO_CLS_TRXC:
856 return gsm_bts_trx_num(bts, mo->assoc_so);
857 case OM2K_MO_CLS_TS:
858 trx = gsm_bts_trx_num(bts, mo->assoc_so);
859 if (!trx)
860 return NULL;
861 if (mo->inst >= ARRAY_SIZE(trx->ts))
862 return NULL;
863 return &trx->ts[mo->inst];
864 case OM2K_MO_CLS_TF:
865 case OM2K_MO_CLS_IS:
866 case OM2K_MO_CLS_CON:
867 case OM2K_MO_CLS_DP:
868 case OM2K_MO_CLS_CF:
869 return bts;
870 }
871
872 return NULL;
873}
874
875static void update_mo_state(struct gsm_bts *bts, struct abis_om2k_mo *mo,
876 uint8_t mo_state)
877{
878 struct gsm_nm_state *nm_state = mo2nm_state(bts, mo);
879 struct gsm_nm_state new_state;
880 struct nm_statechg_signal_data nsd;
881
882 if (!nm_state)
883 return;
884
885 new_state = *nm_state;
886 /* NOTICE: 12.21 Availability state values != OM2000 */
887 new_state.availability = mo_state;
888
889 memset(&nsd, 0, sizeof(nsd));
890
Harald Welte8b277ac2011-03-06 23:00:32 +0100891 nsd.bts = bts;
Harald Welteaf9b8102011-03-06 21:20:38 +0100892 nsd.obj = mo2obj(bts, mo);
893 nsd.old_state = nm_state;
894 nsd.new_state = &new_state;
895 nsd.om2k_mo = mo;
896
Pablo Neira Ayusobbc5b992011-05-06 12:12:31 +0200897 osmo_signal_dispatch(SS_NM, S_NM_STATECHG_ADM, &nsd);
Harald Welteaf9b8102011-03-06 21:20:38 +0100898
899 nm_state->availability = new_state.availability;
900}
901
902static void update_op_state(struct gsm_bts *bts, const struct abis_om2k_mo *mo,
903 uint8_t op_state)
904{
905 struct gsm_nm_state *nm_state = mo2nm_state(bts, mo);
906 struct gsm_nm_state new_state;
907
908 if (!nm_state)
909 return;
910
911 new_state = *nm_state;
912 switch (op_state) {
913 case 1:
914 new_state.operational = NM_OPSTATE_ENABLED;
915 break;
916 case 0:
917 new_state.operational = NM_OPSTATE_DISABLED;
918 break;
919 default:
920 new_state.operational = NM_OPSTATE_NULL;
921 break;
922 }
923
924 nm_state->operational = new_state.operational;
925}
926
Harald Weltebc867d92011-02-12 13:09:38 +0100927static int abis_om2k_sendmsg(struct gsm_bts *bts, struct msgb *msg)
928{
Harald Welted88a3872011-02-14 15:26:13 +0100929 struct abis_om2k_hdr *o2h;
Harald Welte15eae8d2011-09-26 23:43:23 +0200930 struct gsm_bts_trx *trx;
Harald Weltebc867d92011-02-12 13:09:38 +0100931
Harald Welted88a3872011-02-14 15:26:13 +0100932 msg->l2h = msg->data;
933 o2h = (struct abis_om2k_hdr *) msg->l2h;
934
Harald Welte1164dce2011-03-05 19:21:26 +0100935 /* Compute the length in the OML header */
936 o2h->om.length = 6 + msgb_l2len(msg)-sizeof(*o2h);
937
Harald Welted88a3872011-02-14 15:26:13 +0100938 switch (o2h->mo.class) {
939 case OM2K_MO_CLS_TRXC:
940 case OM2K_MO_CLS_TX:
941 case OM2K_MO_CLS_RX:
Harald Welted88a3872011-02-14 15:26:13 +0100942 /* Route through per-TRX OML Link to the appropriate TRX */
Harald Welte15eae8d2011-09-26 23:43:23 +0200943 trx = gsm_bts_trx_by_nr(bts, o2h->mo.inst);
944 if (!trx) {
Harald Welted88a3872011-02-14 15:26:13 +0100945 LOGP(DNM, LOGL_ERROR, "MO=%s Tx Dropping msg to "
946 "non-existing TRX\n", om2k_mo_name(&o2h->mo));
947 return -ENODEV;
948 }
Harald Welte0818f312012-09-07 19:09:46 +0200949 msg->dst = trx->oml_link;
Harald Welted88a3872011-02-14 15:26:13 +0100950 break;
Harald Welte8aeac192011-03-05 20:15:09 +0100951 case OM2K_MO_CLS_TS:
952 /* Route through per-TRX OML Link to the appropriate TRX */
Harald Welte15eae8d2011-09-26 23:43:23 +0200953 trx = gsm_bts_trx_by_nr(bts, o2h->mo.assoc_so);
954 if (!trx) {
Harald Welte8aeac192011-03-05 20:15:09 +0100955 LOGP(DNM, LOGL_ERROR, "MO=%s Tx Dropping msg to "
956 "non-existing TRX\n", om2k_mo_name(&o2h->mo));
957 return -ENODEV;
958 }
Harald Welte0818f312012-09-07 19:09:46 +0200959 msg->dst = trx->oml_link;
Harald Welte8aeac192011-03-05 20:15:09 +0100960 break;
Harald Welted88a3872011-02-14 15:26:13 +0100961 default:
962 /* Route through the IXU/DXU OML Link */
Harald Welte0818f312012-09-07 19:09:46 +0200963 msg->dst = bts->oml_link;
Harald Welted88a3872011-02-14 15:26:13 +0100964 break;
965 }
966
Harald Welte15eae8d2011-09-26 23:43:23 +0200967 return _abis_nm_sendmsg(msg);
Harald Weltebc867d92011-02-12 13:09:38 +0100968}
969
Harald Welte9a311ec2011-02-12 12:33:06 +0100970static void fill_om2k_hdr(struct abis_om2k_hdr *o2h, const struct abis_om2k_mo *mo,
Harald Welte1164dce2011-03-05 19:21:26 +0100971 uint16_t msg_type)
Harald Welte9a311ec2011-02-12 12:33:06 +0100972{
973 o2h->om.mdisc = ABIS_OM_MDISC_FOM;
974 o2h->om.placement = ABIS_OM_PLACEMENT_ONLY;
975 o2h->om.sequence = 0;
Harald Welte1164dce2011-03-05 19:21:26 +0100976 /* We fill o2h->om.length later during om2k_sendmsg() */
Harald Welte9a311ec2011-02-12 12:33:06 +0100977 o2h->msg_type = htons(msg_type);
978 memcpy(&o2h->mo, mo, sizeof(o2h->mo));
979}
980
Harald Welte9a311ec2011-02-12 12:33:06 +0100981static int abis_om2k_cal_time_resp(struct gsm_bts *bts)
982{
983 struct msgb *msg = om2k_msgb_alloc();
984 struct abis_om2k_hdr *o2k;
985 time_t tm_t;
986 struct tm *tm;
987
988 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
Harald Welte591e1d72016-07-09 22:20:57 +0200989 fill_om2k_hdr(o2k, &bts->rbs2000.cf.om2k_mo.addr,
990 OM2K_MSGT_CAL_TIME_RESP);
Harald Welte9a311ec2011-02-12 12:33:06 +0100991
992 tm_t = time(NULL);
993 tm = localtime(&tm_t);
994
995 msgb_put_u8(msg, OM2K_DEI_CAL_TIME);
996 msgb_put_u8(msg, tm->tm_year % 100);
997 msgb_put_u8(msg, tm->tm_mon + 1);
998 msgb_put_u8(msg, tm->tm_mday);
999 msgb_put_u8(msg, tm->tm_hour);
1000 msgb_put_u8(msg, tm->tm_min);
1001 msgb_put_u8(msg, tm->tm_sec);
1002
Harald Weltebc867d92011-02-12 13:09:38 +01001003 return abis_om2k_sendmsg(bts, msg);
Harald Welte9a311ec2011-02-12 12:33:06 +01001004}
1005
Harald Welte6fec79d2011-02-12 14:57:17 +01001006static int abis_om2k_tx_simple(struct gsm_bts *bts, const struct abis_om2k_mo *mo,
Harald Welte9a311ec2011-02-12 12:33:06 +01001007 uint8_t msg_type)
1008{
1009 struct msgb *msg = om2k_msgb_alloc();
1010 struct abis_om2k_hdr *o2k;
1011
1012 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
Harald Welte1164dce2011-03-05 19:21:26 +01001013 fill_om2k_hdr(o2k, mo, msg_type);
Harald Welte9a311ec2011-02-12 12:33:06 +01001014
Harald Welte73541072011-02-12 13:44:14 +01001015 DEBUGP(DNM, "Tx MO=%s %s\n", om2k_mo_name(mo),
1016 get_value_string(om2k_msgcode_vals, msg_type));
1017
Harald Weltebc867d92011-02-12 13:09:38 +01001018 return abis_om2k_sendmsg(bts, msg);
Harald Welte9a311ec2011-02-12 12:33:06 +01001019}
1020
Harald Welte6fec79d2011-02-12 14:57:17 +01001021int abis_om2k_tx_reset_cmd(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
Harald Welte73541072011-02-12 13:44:14 +01001022{
1023 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_RESET_CMD);
1024}
1025
Harald Welte6fec79d2011-02-12 14:57:17 +01001026int abis_om2k_tx_start_req(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
Harald Welte73541072011-02-12 13:44:14 +01001027{
1028 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_START_REQ);
1029}
1030
Harald Welte6fec79d2011-02-12 14:57:17 +01001031int abis_om2k_tx_status_req(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
Harald Weltee1d5eca2011-02-12 14:42:59 +01001032{
1033 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_STATUS_REQ);
1034}
1035
Harald Welte6fec79d2011-02-12 14:57:17 +01001036int abis_om2k_tx_connect_cmd(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
1037{
1038 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_CONNECT_CMD);
1039}
1040
1041int abis_om2k_tx_disconnect_cmd(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
1042{
1043 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_DISCONNECT_CMD);
1044}
1045
Harald Welte8024d8f2011-02-12 15:07:30 +01001046int abis_om2k_tx_test_req(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
1047{
1048 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_TEST_REQ);
1049}
1050
Harald Welte0741ffe2011-02-12 18:48:53 +01001051int abis_om2k_tx_enable_req(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
1052{
1053 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_ENABLE_REQ);
1054}
1055
1056int abis_om2k_tx_disable_req(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
1057{
1058 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_DISABLE_REQ);
1059}
1060
Harald Welte6fec79d2011-02-12 14:57:17 +01001061int abis_om2k_tx_op_info(struct gsm_bts *bts, const struct abis_om2k_mo *mo,
1062 uint8_t operational)
Harald Welte9a311ec2011-02-12 12:33:06 +01001063{
1064 struct msgb *msg = om2k_msgb_alloc();
1065 struct abis_om2k_hdr *o2k;
1066
1067 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
Harald Welte1164dce2011-03-05 19:21:26 +01001068 fill_om2k_hdr(o2k, mo, OM2K_MSGT_OP_INFO);
Harald Welte9a311ec2011-02-12 12:33:06 +01001069
1070 msgb_tv_put(msg, OM2K_DEI_OP_INFO, operational);
1071
Harald Welte73541072011-02-12 13:44:14 +01001072 DEBUGP(DNM, "Tx MO=%s %s\n", om2k_mo_name(mo),
1073 get_value_string(om2k_msgcode_vals, OM2K_MSGT_OP_INFO));
1074
Harald Welteaf9b8102011-03-06 21:20:38 +01001075 /* we update the state here... and send the signal at ACK */
1076 update_op_state(bts, mo, operational);
1077
Harald Weltebc867d92011-02-12 13:09:38 +01001078 return abis_om2k_sendmsg(bts, msg);
Harald Welte9a311ec2011-02-12 12:33:06 +01001079}
1080
root45799782016-10-15 21:24:57 +02001081int abis_om2k_tx_cap_req(struct gsm_bts *bts, const struct abis_om2k_mo *mo)
1082{
1083 return abis_om2k_tx_simple(bts, mo, OM2K_MSGT_CAPA_REQ);
1084}
1085
Harald Welted529db62011-03-06 21:49:21 +01001086static void om2k_fill_is_conn_grp(struct om2k_is_conn_grp *grp, uint16_t icp1,
1087 uint16_t icp2, uint8_t cont_idx)
1088{
1089 grp->icp1 = htons(icp1);
1090 grp->icp2 = htons(icp2);
1091 grp->cont_idx = cont_idx;
1092}
1093
1094int abis_om2k_tx_is_conf_req(struct gsm_bts *bts)
Harald Welte8bcb1a02011-02-12 20:23:40 +01001095{
1096 struct msgb *msg = om2k_msgb_alloc();
1097 struct abis_om2k_hdr *o2k;
Harald Welted529db62011-03-06 21:49:21 +01001098 struct is_conn_group *grp;
1099 unsigned int num_grps = 0, i = 0;
1100 struct om2k_is_conn_grp *cg;
1101
1102 /* count number of groups in linked list */
1103 llist_for_each_entry(grp, &bts->rbs2000.is.conn_groups, list)
1104 num_grps++;
1105
1106 if (!num_grps)
1107 return -EINVAL;
1108
1109 /* allocate buffer for oml group array */
1110 cg = talloc_zero_array(bts, struct om2k_is_conn_grp, num_grps);
1111
1112 /* fill array with data from linked list */
1113 llist_for_each_entry(grp, &bts->rbs2000.is.conn_groups, list)
1114 om2k_fill_is_conn_grp(&cg[i++], grp->icp1, grp->icp2, grp->ci);
Harald Welte8bcb1a02011-02-12 20:23:40 +01001115
1116 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
Harald Welte591e1d72016-07-09 22:20:57 +02001117 fill_om2k_hdr(o2k, &bts->rbs2000.is.om2k_mo.addr,
1118 OM2K_MSGT_IS_CONF_REQ);
Harald Welte8bcb1a02011-02-12 20:23:40 +01001119
1120 msgb_tv_put(msg, OM2K_DEI_LIST_NR, 1);
1121 msgb_tv_put(msg, OM2K_DEI_END_LIST_NR, 1);
1122
1123 msgb_tlv_put(msg, OM2K_DEI_IS_CONN_LIST,
Harald Welted529db62011-03-06 21:49:21 +01001124 num_grps * sizeof(*cg), (uint8_t *)cg);
1125
1126 talloc_free(cg);
Harald Welte8bcb1a02011-02-12 20:23:40 +01001127
Harald Welte591e1d72016-07-09 22:20:57 +02001128 DEBUGP(DNM, "Tx MO=%s %s\n",
1129 om2k_mo_name(&bts->rbs2000.is.om2k_mo.addr),
Harald Welte79c34ff2012-09-07 20:15:50 +02001130 get_value_string(om2k_msgcode_vals, OM2K_MSGT_IS_CONF_REQ));
1131
Harald Welte8bcb1a02011-02-12 20:23:40 +01001132 return abis_om2k_sendmsg(bts, msg);
1133}
1134
Harald Welteeae68292016-11-11 19:41:59 +01001135int abis_om2k_tx_con_conf_req(struct gsm_bts *bts)
Harald Weltefdb71942011-02-14 15:31:43 +01001136{
1137 struct msgb *msg = om2k_msgb_alloc();
1138 struct abis_om2k_hdr *o2k;
Harald Welteeae68292016-11-11 19:41:59 +01001139 struct con_group *grp;
1140 unsigned int num_grps = 0;
Harald Weltefdb71942011-02-14 15:31:43 +01001141
Harald Welteeae68292016-11-11 19:41:59 +01001142 /* count number of groups in linked list */
1143 llist_for_each_entry(grp, &bts->rbs2000.con.conn_groups, list)
1144 num_grps++;
1145
1146 if (!num_grps)
1147 return -EINVAL;
1148
1149 /* first build the value part of the OM2K_DEI_CON_CONN_LIST DEI */
1150 msgb_put_u8(msg, num_grps);
1151 llist_for_each_entry(grp, &bts->rbs2000.con.conn_groups, list) {
1152 struct con_path *cp;
1153 unsigned int num_paths = 0;
1154 llist_for_each_entry(cp, &grp->paths, list)
1155 num_paths++;
1156 msgb_put_u8(msg, num_paths);
1157 llist_for_each_entry(cp, &grp->paths, list) {
1158 struct om2k_con_path *om2k_cp;
1159 om2k_cp = (struct om2k_con_path *) msgb_put(msg, sizeof(*om2k_cp));
1160 om2k_cp->ccp = htons(cp->ccp);
1161 om2k_cp->ci = cp->ci;
1162 om2k_cp->tag = cp->tag;
1163 om2k_cp->tei = cp->tei;
1164 }
1165 }
1166 msgb_push_u8(msg, msgb_length(msg));
1167 msgb_push_u8(msg, OM2K_DEI_CON_CONN_LIST);
1168
1169 /* pre-pend the list number DEIs */
1170 msgb_tv_push(msg, OM2K_DEI_END_LIST_NR, 1);
1171 msgb_tv_push(msg, OM2K_DEI_LIST_NR, 1);
1172
1173 /* pre-pend the OM2K header */
1174 o2k = (struct abis_om2k_hdr *) msgb_push(msg, sizeof(*o2k));
Harald Welte591e1d72016-07-09 22:20:57 +02001175 fill_om2k_hdr(o2k, &bts->rbs2000.con.om2k_mo.addr,
1176 OM2K_MSGT_CON_CONF_REQ);
Harald Weltefdb71942011-02-14 15:31:43 +01001177
Harald Welte591e1d72016-07-09 22:20:57 +02001178 DEBUGP(DNM, "Tx MO=%s %s\n",
1179 om2k_mo_name(&bts->rbs2000.con.om2k_mo.addr),
Harald Welte79c34ff2012-09-07 20:15:50 +02001180 get_value_string(om2k_msgcode_vals, OM2K_MSGT_CON_CONF_REQ));
1181
Harald Weltefdb71942011-02-14 15:31:43 +01001182 return abis_om2k_sendmsg(bts, msg);
1183}
1184
Harald Weltea0ce3492011-03-05 14:13:14 +01001185static void om2k_trx_to_mo(struct abis_om2k_mo *mo,
1186 const struct gsm_bts_trx *trx,
1187 enum abis_om2k_mo_cls cls)
1188{
1189 mo->class = cls;
1190 mo->bts = 0;
1191 mo->inst = trx->nr;
Harald Welte53492c82011-03-05 16:21:01 +01001192 mo->assoc_so = 255;
Harald Weltea0ce3492011-03-05 14:13:14 +01001193}
1194
1195static void om2k_ts_to_mo(struct abis_om2k_mo *mo,
1196 const struct gsm_bts_trx_ts *ts)
1197{
1198 mo->class = OM2K_MO_CLS_TS;
1199 mo->bts = 0;
1200 mo->inst = ts->nr;
1201 mo->assoc_so = ts->trx->nr;
1202}
1203
1204/* Configure a Receiver MO */
1205int abis_om2k_tx_rx_conf_req(struct gsm_bts_trx *trx)
1206{
1207 struct msgb *msg = om2k_msgb_alloc();
1208 struct abis_om2k_hdr *o2k;
1209 struct abis_om2k_mo mo;
1210
1211 om2k_trx_to_mo(&mo, trx, OM2K_MO_CLS_RX);
1212
1213 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
Harald Welte1164dce2011-03-05 19:21:26 +01001214 fill_om2k_hdr(o2k, &mo, OM2K_MSGT_RX_CONF_REQ);
Harald Weltea0ce3492011-03-05 14:13:14 +01001215
1216 msgb_tv16_put(msg, OM2K_DEI_FREQ_SPEC_RX, trx->arfcn);
Harald Welte1edc2b42011-03-06 19:01:54 +01001217 msgb_tv_put(msg, OM2K_DEI_RX_DIVERSITY, 0x02); /* A */
Harald Weltea0ce3492011-03-05 14:13:14 +01001218
1219 return abis_om2k_sendmsg(trx->bts, msg);
1220}
1221
1222/* Configure a Transmitter MO */
1223int abis_om2k_tx_tx_conf_req(struct gsm_bts_trx *trx)
1224{
1225 struct msgb *msg = om2k_msgb_alloc();
1226 struct abis_om2k_hdr *o2k;
1227 struct abis_om2k_mo mo;
1228
1229 om2k_trx_to_mo(&mo, trx, OM2K_MO_CLS_TX);
1230
1231 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
Harald Welte1164dce2011-03-05 19:21:26 +01001232 fill_om2k_hdr(o2k, &mo, OM2K_MSGT_TX_CONF_REQ);
Harald Weltea0ce3492011-03-05 14:13:14 +01001233
1234 msgb_tv16_put(msg, OM2K_DEI_FREQ_SPEC_TX, trx->arfcn);
1235 msgb_tv_put(msg, OM2K_DEI_POWER, trx->nominal_power-trx->max_power_red);
1236 msgb_tv_put(msg, OM2K_DEI_FILLING_MARKER, 0); /* Filling enabled */
1237 msgb_tv_put(msg, OM2K_DEI_BCC, trx->bts->bsic & 0x7);
1238 /* Dedication Information is optional */
1239
1240 return abis_om2k_sendmsg(trx->bts, msg);
1241}
1242
Harald Weltef9cf9612011-03-05 14:36:47 +01001243enum abis_om2k_tf_mode {
1244 OM2K_TF_MODE_MASTER = 0x00,
1245 OM2K_TF_MODE_STANDALONE = 0x01,
1246 OM2K_TF_MODE_SLAVE = 0x02,
1247 OM2K_TF_MODE_UNDEFINED = 0xff,
1248};
1249
1250static const uint8_t fs_offset_undef[5] = { 0xff, 0xff, 0xff, 0xff, 0xff };
1251
1252int abis_om2k_tx_tf_conf_req(struct gsm_bts *bts)
1253{
1254 struct msgb *msg = om2k_msgb_alloc();
1255 struct abis_om2k_hdr *o2k;
1256
1257 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
Harald Welte591e1d72016-07-09 22:20:57 +02001258 fill_om2k_hdr(o2k, &bts->rbs2000.tf.om2k_mo.addr,
1259 OM2K_MSGT_TF_CONF_REQ);
Harald Weltef9cf9612011-03-05 14:36:47 +01001260
1261 msgb_tv_put(msg, OM2K_DEI_TF_MODE, OM2K_TF_MODE_STANDALONE);
Harald Welteba9adbb2011-03-06 19:01:16 +01001262 msgb_tv_put(msg, OM2K_DEI_TF_SYNC_SRC, 0x00);
Harald Weltef9cf9612011-03-05 14:36:47 +01001263 msgb_tv_fixed_put(msg, OM2K_DEI_FS_OFFSET,
1264 sizeof(fs_offset_undef), fs_offset_undef);
1265
Harald Welte591e1d72016-07-09 22:20:57 +02001266 DEBUGP(DNM, "Tx MO=%s %s\n",
1267 om2k_mo_name(&bts->rbs2000.tf.om2k_mo.addr),
Harald Welte79c34ff2012-09-07 20:15:50 +02001268 get_value_string(om2k_msgcode_vals, OM2K_MSGT_TF_CONF_REQ));
1269
Harald Weltef9cf9612011-03-05 14:36:47 +01001270 return abis_om2k_sendmsg(bts, msg);
1271}
1272
Harald Weltea0ce3492011-03-05 14:13:14 +01001273static uint8_t pchan2comb(enum gsm_phys_chan_config pchan)
1274{
1275 switch (pchan) {
1276 case GSM_PCHAN_CCCH:
1277 return 4;
1278 case GSM_PCHAN_CCCH_SDCCH4:
1279 return 5;
1280 case GSM_PCHAN_SDCCH8_SACCH8C:
1281 return 3;
1282 case GSM_PCHAN_TCH_F:
1283 case GSM_PCHAN_TCH_H:
1284 case GSM_PCHAN_PDCH:
Harald Weltea0ce3492011-03-05 14:13:14 +01001285 return 8;
1286 default:
1287 return 0;
1288 }
1289}
1290
Neels Hofmeyr23c3aa32016-09-25 15:15:59 +02001291static uint8_t ts2comb(struct gsm_bts_trx_ts *ts)
1292{
1293 switch (ts->pchan) {
1294 case GSM_PCHAN_TCH_F_PDCH:
Neels Hofmeyr87ef68e2016-11-10 02:18:00 +01001295 LOGP(DNM, LOGL_ERROR, "%s pchan %s not intended for use"
1296 " with OM2000, use %s instead\n",
1297 gsm_ts_and_pchan_name(ts),
1298 gsm_pchan_name(GSM_PCHAN_TCH_F_PDCH),
1299 gsm_pchan_name(GSM_PCHAN_TCH_F_TCH_H_PDCH));
1300 /* If we allowed initialization of TCH/F_PDCH, it would fail
1301 * when we try to send the ip.access specific RSL PDCH Act
1302 * message for it. Rather fail completely right now: */
1303 return 0;
Neels Hofmeyr23c3aa32016-09-25 15:15:59 +02001304 case GSM_PCHAN_TCH_F_TCH_H_PDCH:
Neels Hofmeyrf926f452016-10-31 18:16:34 +01001305 return pchan2comb(GSM_PCHAN_TCH_F);
Neels Hofmeyr23c3aa32016-09-25 15:15:59 +02001306 default:
1307 return pchan2comb(ts->pchan);
1308 }
1309}
1310
Harald Welte5748c202011-03-05 17:30:07 +01001311static int put_freq_list(uint8_t *buf, uint16_t arfcn)
1312{
1313 buf[0] = 0x00; /* TX/RX address */
1314 buf[1] = (arfcn >> 8);
1315 buf[2] = (arfcn & 0xff);
1316
1317 return 3;
1318}
1319
Harald Weltea0ce3492011-03-05 14:13:14 +01001320/* Compute a frequency list in OM2000 fomrmat */
1321static int om2k_gen_freq_list(uint8_t *list, struct gsm_bts_trx_ts *ts)
1322{
1323 uint8_t *cur = list;
Harald Weltee6e83832011-03-05 17:52:09 +01001324 int len;
Harald Weltea0ce3492011-03-05 14:13:14 +01001325
1326 if (ts->hopping.enabled) {
1327 unsigned int i;
1328 for (i = 0; i < ts->hopping.arfcns.data_len*8; i++) {
Harald Welte5748c202011-03-05 17:30:07 +01001329 if (bitvec_get_bit_pos(&ts->hopping.arfcns, i))
1330 cur += put_freq_list(cur, i);
Harald Weltea0ce3492011-03-05 14:13:14 +01001331 }
Harald Welte5748c202011-03-05 17:30:07 +01001332 } else
1333 cur += put_freq_list(cur, ts->trx->arfcn);
1334
Harald Weltee6e83832011-03-05 17:52:09 +01001335 len = cur - list;
1336
1337 return len;
Harald Weltea0ce3492011-03-05 14:13:14 +01001338}
1339
Harald Welte75755c52011-03-05 20:38:35 +01001340const uint8_t icm_bound_params[] = { 0x02, 0x06, 0x0c, 0x16, 0x06 };
1341
Harald Weltea0ce3492011-03-05 14:13:14 +01001342int abis_om2k_tx_ts_conf_req(struct gsm_bts_trx_ts *ts)
1343{
1344 struct msgb *msg = om2k_msgb_alloc();
1345 struct abis_om2k_hdr *o2k;
1346 struct abis_om2k_mo mo;
1347 uint8_t freq_list[64*3]; /* BA max size: 64 ARFCN */
1348 int freq_list_len;
1349
1350 om2k_ts_to_mo(&mo, ts);
1351
Harald Welte5748c202011-03-05 17:30:07 +01001352 memset(freq_list, 0, sizeof(freq_list));
Harald Weltea0ce3492011-03-05 14:13:14 +01001353 freq_list_len = om2k_gen_freq_list(freq_list, ts);
1354 if (freq_list_len < 0)
1355 return freq_list_len;
1356
1357 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
Harald Welte1164dce2011-03-05 19:21:26 +01001358 fill_om2k_hdr(o2k, &mo, OM2K_MSGT_TS_CONF_REQ);
Harald Weltea0ce3492011-03-05 14:13:14 +01001359
Neels Hofmeyr23c3aa32016-09-25 15:15:59 +02001360 msgb_tv_put(msg, OM2K_DEI_COMBINATION, ts2comb(ts));
Harald Weltea0ce3492011-03-05 14:13:14 +01001361 msgb_tv_put(msg, OM2K_DEI_TS_NR, ts->nr);
1362 msgb_tlv_put(msg, OM2K_DEI_FREQ_LIST, freq_list_len, freq_list);
1363 msgb_tv_put(msg, OM2K_DEI_HSN, ts->hopping.hsn);
1364 msgb_tv_put(msg, OM2K_DEI_MAIO, ts->hopping.maio);
1365 msgb_tv_put(msg, OM2K_DEI_BSIC, ts->trx->bts->bsic);
Harald Welte1edc2b42011-03-06 19:01:54 +01001366 msgb_tv_put(msg, OM2K_DEI_RX_DIVERSITY, 0x02); /* A */
Harald Weltea0ce3492011-03-05 14:13:14 +01001367 msgb_tv16_put(msg, OM2K_DEI_FN_OFFSET, 0);
1368 msgb_tv_put(msg, OM2K_DEI_EXT_RANGE, 0); /* Off */
1369 /* Optional: Interference Rejection Combining */
Harald Welte1164dce2011-03-05 19:21:26 +01001370 msgb_tv_put(msg, OM2K_DEI_INTERF_REJ_COMB, 0x00);
1371 switch (ts->pchan) {
1372 case GSM_PCHAN_CCCH:
Harald Welte1164dce2011-03-05 19:21:26 +01001373 msgb_tv_put(msg, OM2K_DEI_BA_PA_MFRMS, 0x06);
1374 msgb_tv_put(msg, OM2K_DEI_BS_AG_BKS_RES, 0x01);
1375 msgb_tv_put(msg, OM2K_DEI_DRX_DEV_MAX, 0x05);
1376 /* Repeat Paging/IMM.ASS: True, Allow Paging Type 3: Yes, Page for 5 seconds (default) */
1377 msgb_tv_put(msg, OM2K_DEI_CCCH_OPTIONS, 0x01);
1378 break;
Harald Welte75755c52011-03-05 20:38:35 +01001379 case GSM_PCHAN_CCCH_SDCCH4:
Harald Welte67161f22012-06-03 13:01:47 +02001380 msgb_tv_put(msg, OM2K_DEI_T3105, ts->trx->bts->network->T3105 / 10);
Harald Welte75755c52011-03-05 20:38:35 +01001381 msgb_tv_put(msg, OM2K_DEI_NY1, 35);
1382 msgb_tv_put(msg, OM2K_DEI_BA_PA_MFRMS, 0x06);
1383 msgb_tv_put(msg, OM2K_DEI_CBCH_INDICATOR, 0);
Harald Welte94bc1e02014-01-19 17:19:10 +01001384 msgb_tv_put(msg, OM2K_DEI_TSC, gsm_ts_tsc(ts));
Harald Welte75755c52011-03-05 20:38:35 +01001385 msgb_tv_put(msg, OM2K_DEI_BS_AG_BKS_RES, 0x01);
1386 msgb_tv_put(msg, OM2K_DEI_ICM_INDICATOR, 0);
1387 msgb_tv_put(msg, OM2K_DEI_DRX_DEV_MAX, 0x05);
1388 /* Repeat Paging/IMM.ASS: True, Allow Paging Type 3: Yes, Page for 5 seconds (default) */
1389 msgb_tv_put(msg, OM2K_DEI_CCCH_OPTIONS, 0x01);
1390 msgb_tv_fixed_put(msg, OM2K_DEI_ICM_BOUND_PARAMS,
1391 sizeof(icm_bound_params), icm_bound_params);
1392 break;
Harald Welte1164dce2011-03-05 19:21:26 +01001393 case GSM_PCHAN_SDCCH8_SACCH8C:
Harald Welte67161f22012-06-03 13:01:47 +02001394 msgb_tv_put(msg, OM2K_DEI_T3105, ts->trx->bts->network->T3105 / 10);
Harald Welte1164dce2011-03-05 19:21:26 +01001395 msgb_tv_put(msg, OM2K_DEI_NY1, 35);
1396 msgb_tv_put(msg, OM2K_DEI_CBCH_INDICATOR, 0);
Harald Welte94bc1e02014-01-19 17:19:10 +01001397 msgb_tv_put(msg, OM2K_DEI_TSC, gsm_ts_tsc(ts));
Harald Welte1164dce2011-03-05 19:21:26 +01001398 /* Disable RF RESOURCE INDICATION on idle channels */
1399 msgb_tv_put(msg, OM2K_DEI_ICM_INDICATOR, 0);
Harald Welte75755c52011-03-05 20:38:35 +01001400 msgb_tv_fixed_put(msg, OM2K_DEI_ICM_BOUND_PARAMS,
1401 sizeof(icm_bound_params), icm_bound_params);
Harald Welte1164dce2011-03-05 19:21:26 +01001402 break;
1403 default:
Harald Welte67161f22012-06-03 13:01:47 +02001404 msgb_tv_put(msg, OM2K_DEI_T3105, ts->trx->bts->network->T3105 / 10);
Harald Welte1164dce2011-03-05 19:21:26 +01001405 msgb_tv_put(msg, OM2K_DEI_NY1, 35);
Harald Welte94bc1e02014-01-19 17:19:10 +01001406 msgb_tv_put(msg, OM2K_DEI_TSC, gsm_ts_tsc(ts));
Harald Welte1164dce2011-03-05 19:21:26 +01001407 /* Disable RF RESOURCE INDICATION on idle channels */
1408 msgb_tv_put(msg, OM2K_DEI_ICM_INDICATOR, 0);
Harald Welte75755c52011-03-05 20:38:35 +01001409 msgb_tv_fixed_put(msg, OM2K_DEI_ICM_BOUND_PARAMS,
1410 sizeof(icm_bound_params), icm_bound_params);
Harald Welte1164dce2011-03-05 19:21:26 +01001411 msgb_tv_put(msg, OM2K_DEI_TTA, 10); /* Timer for Time Alignment */
Harald Welte75755c52011-03-05 20:38:35 +01001412 if (ts->pchan == GSM_PCHAN_TCH_H)
1413 msgb_tv_put(msg, OM2K_DEI_ICM_CHAN_RATE, 1); /* TCH/H */
1414 else
1415 msgb_tv_put(msg, OM2K_DEI_ICM_CHAN_RATE, 0); /* TCH/F */
Harald Welte1164dce2011-03-05 19:21:26 +01001416 msgb_tv_put(msg, OM2K_DEI_LSC, 1); /* enabled */
Harald Welte1edc2b42011-03-06 19:01:54 +01001417 msgb_tv_put(msg, OM2K_DEI_LSC_FILT_TIME, 10); /* units of 100ms */
Harald Welte1164dce2011-03-05 19:21:26 +01001418 msgb_tv_put(msg, OM2K_DEI_CALL_SUPV_TIME, 8);
1419 msgb_tv_put(msg, OM2K_DEI_ENCR_ALG, 0x00);
Harald Welte96638d12016-11-15 23:23:56 +01001420 /* Not sure what those below mean */
1421 msgb_tv_put(msg, 0x9e, 0x00);
1422 msgb_tv_put(msg, 0x9f, 0x37);
1423 msgb_tv_put(msg, 0xa0, 0x01);
Harald Welte1164dce2011-03-05 19:21:26 +01001424 break;
1425 }
Harald Weltea0ce3492011-03-05 14:13:14 +01001426
Harald Welte591e1d72016-07-09 22:20:57 +02001427 DEBUGP(DNM, "Tx MO=%s %s\n",
1428 om2k_mo_name(&mo),
1429 get_value_string(om2k_msgcode_vals, OM2K_MSGT_TS_CONF_REQ));
1430
Harald Weltea0ce3492011-03-05 14:13:14 +01001431 return abis_om2k_sendmsg(ts->trx->bts, msg);
1432}
Harald Weltefdb71942011-02-14 15:31:43 +01001433
Harald Welte591e1d72016-07-09 22:20:57 +02001434
1435/***********************************************************************
1436 * OM2000 Managed Object (MO) FSM
1437 ***********************************************************************/
1438
1439#define S(x) (1 << (x))
1440
1441enum om2k_event_name {
1442 OM2K_MO_EVT_START,
1443 OM2K_MO_EVT_RX_CONN_COMPL,
1444 OM2K_MO_EVT_RX_RESET_COMPL,
1445 OM2K_MO_EVT_RX_START_REQ_ACCEPT,
1446 OM2K_MO_EVT_RX_START_RES,
1447 OM2K_MO_EVT_RX_CFG_REQ_ACCEPT,
1448 OM2K_MO_EVT_RX_CFG_RES,
1449 OM2K_MO_EVT_RX_ENA_REQ_ACCEPT,
1450 OM2K_MO_EVT_RX_ENA_RES,
1451 OM2K_MO_EVT_RX_OPINFO_ACC,
1452};
1453
1454static const struct value_string om2k_event_names[] = {
1455 { OM2K_MO_EVT_START, "START" },
1456 { OM2K_MO_EVT_RX_CONN_COMPL, "RX-CONN-COMPL" },
1457 { OM2K_MO_EVT_RX_RESET_COMPL, "RX-RESET-COMPL" },
1458 { OM2K_MO_EVT_RX_START_REQ_ACCEPT, "RX-RESET-REQ-ACCEPT" },
1459 { OM2K_MO_EVT_RX_START_RES, "RX-START-RESULT" },
1460 { OM2K_MO_EVT_RX_CFG_REQ_ACCEPT, "RX-CFG-REQ-ACCEPT" },
1461 { OM2K_MO_EVT_RX_CFG_RES, "RX-CFG-RESULT" },
1462 { OM2K_MO_EVT_RX_ENA_REQ_ACCEPT, "RX-ENABLE-REQ-ACCEPT" },
1463 { OM2K_MO_EVT_RX_ENA_RES, "RX-ENABLE-RESULT" },
1464 { OM2K_MO_EVT_RX_OPINFO_ACC, "RX-OPINFO-ACCEPT" },
1465 { 0, NULL }
1466};
1467
1468enum om2k_mo_fsm_state {
1469 OM2K_ST_INIT,
1470 OM2K_ST_WAIT_CONN_COMPL,
1471 OM2K_ST_WAIT_RES_COMPL,
1472 OM2K_ST_WAIT_START_ACCEPT,
1473 OM2K_ST_WAIT_START_RES,
1474 OM2K_ST_WAIT_CFG_ACCEPT,
1475 OM2K_ST_WAIT_CFG_RES,
1476 OM2K_ST_WAIT_ENABLE_ACCEPT,
1477 OM2K_ST_WAIT_ENABLE_RES,
1478 OM2K_ST_WAIT_OPINFO_ACCEPT,
1479 OM2K_ST_DONE,
1480 OM2K_ST_ERROR,
1481};
1482
1483struct om2k_mo_fsm_priv {
1484 struct gsm_bts_trx *trx;
1485 struct om2k_mo *mo;
1486 uint8_t ts_nr;
1487};
1488
1489static void om2k_mo_st_init(struct osmo_fsm_inst *fi, uint32_t event, void *data)
1490{
1491 struct om2k_mo_fsm_priv *omfp = fi->priv;
1492
1493 OSMO_ASSERT(event == OM2K_MO_EVT_START);
1494
1495 switch (omfp->mo->addr.class) {
1496 case OM2K_MO_CLS_CF:
1497 /* no Connect required, is always connected */
1498 osmo_fsm_inst_state_chg(fi, OM2K_ST_WAIT_START_ACCEPT,
1499 OM2K_TIMEOUT, 0);
1500 abis_om2k_tx_start_req(omfp->trx->bts, &omfp->mo->addr);
1501 break;
1502 case OM2K_MO_CLS_TRXC:
1503 /* no Connect required, start with Reset */
1504 osmo_fsm_inst_state_chg(fi, OM2K_ST_WAIT_RES_COMPL,
1505 OM2K_TIMEOUT, 0);
1506 abis_om2k_tx_reset_cmd(omfp->trx->bts, &omfp->mo->addr);
1507 break;
1508 default:
1509 /* start with Connect */
1510 osmo_fsm_inst_state_chg(fi, OM2K_ST_WAIT_CONN_COMPL,
1511 OM2K_TIMEOUT, 0);
1512 abis_om2k_tx_connect_cmd(omfp->trx->bts, &omfp->mo->addr);
1513 break;
1514 }
1515}
1516
1517static void om2k_mo_st_wait_conn_compl(struct osmo_fsm_inst *fi, uint32_t event, void *data)
1518{
1519 struct om2k_mo_fsm_priv *omfp = fi->priv;
1520
1521 switch (omfp->mo->addr.class) {
1522#if 0
1523 case OM2K_MO_CLS_TF:
1524 /* skip the reset, hope that helps */
1525 osmo_fsm_inst_state_chg(fi, OM2K_ST_WAIT_START_ACCEPT,
1526 OM2K_TIMEOUT, 0);
1527 abis_om2k_tx_start_req(omfp->trx->bts, &omfp->mo->addr);
1528 break;
1529#endif
1530 default:
1531 osmo_fsm_inst_state_chg(fi, OM2K_ST_WAIT_RES_COMPL,
1532 OM2K_TIMEOUT, 0);
1533 abis_om2k_tx_reset_cmd(omfp->trx->bts, &omfp->mo->addr);
1534 break;
1535 }
1536}
1537
1538static void om2k_mo_st_wait_res_compl(struct osmo_fsm_inst *fi, uint32_t event, void *data)
1539{
1540 struct om2k_mo_fsm_priv *omfp = fi->priv;
1541
1542 osmo_fsm_inst_state_chg(fi, OM2K_ST_WAIT_START_ACCEPT,
1543 OM2K_TIMEOUT, 0);
1544 abis_om2k_tx_start_req(omfp->trx->bts, &omfp->mo->addr);
1545}
1546
1547static void om2k_mo_st_wait_start_accept(struct osmo_fsm_inst *fi, uint32_t event, void *data)
1548{
1549 struct om2k_decoded_msg *omd = data;
1550
1551 switch (omd->msg_type) {
1552 case OM2K_MSGT_START_REQ_ACK:
1553 osmo_fsm_inst_state_chg(fi, OM2K_ST_WAIT_START_RES,
1554 OM2K_TIMEOUT, 0);
1555 break;
1556 case OM2K_MSGT_START_REQ_REJ:
1557 osmo_fsm_inst_state_chg(fi, OM2K_ST_ERROR, 0, 0);
1558 break;
1559 }
1560}
1561
1562static void om2k_mo_st_wait_start_res(struct osmo_fsm_inst *fi, uint32_t event, void *data)
1563{
1564 struct om2k_mo_fsm_priv *omfp = fi->priv;
1565 struct gsm_bts_trx_ts *ts;
1566
1567 switch (omfp->mo->addr.class) {
1568 case OM2K_MO_CLS_CF:
1569 case OM2K_MO_CLS_TRXC:
1570 /* Transition directly to Operational Info */
1571 osmo_fsm_inst_state_chg(fi, OM2K_ST_WAIT_OPINFO_ACCEPT,
1572 OM2K_TIMEOUT, 0);
1573 abis_om2k_tx_op_info(omfp->trx->bts, &omfp->mo->addr, 1);
Harald Welte424656e2016-10-15 16:30:35 +02001574 return;
Harald Welte591e1d72016-07-09 22:20:57 +02001575 case OM2K_MO_CLS_DP:
1576 /* Transition directoy to WAIT_ENABLE_ACCEPT */
1577 osmo_fsm_inst_state_chg(fi, OM2K_ST_WAIT_ENABLE_ACCEPT,
1578 OM2K_TIMEOUT, 0);
1579 abis_om2k_tx_enable_req(omfp->trx->bts, &omfp->mo->addr);
1580 return;
1581#if 0
1582 case OM2K_MO_CLS_TF:
1583 /* skip the config, hope that helps speeding things up */
1584 osmo_fsm_inst_state_chg(fi, OM2K_ST_WAIT_ENABLE_ACCEPT,
1585 OM2K_TIMEOUT, 0);
1586 abis_om2k_tx_enable_req(omfp->trx->bts, &omfp->mo->addr);
1587 return;
1588#endif
1589 }
1590
1591 osmo_fsm_inst_state_chg(fi, OM2K_ST_WAIT_CFG_ACCEPT,
1592 OM2K_TIMEOUT, 0);
1593 switch (omfp->mo->addr.class) {
1594 case OM2K_MO_CLS_TF:
1595 abis_om2k_tx_tf_conf_req(omfp->trx->bts);
1596 break;
1597 case OM2K_MO_CLS_IS:
1598 abis_om2k_tx_is_conf_req(omfp->trx->bts);
1599 break;
1600 case OM2K_MO_CLS_CON:
Harald Welteeae68292016-11-11 19:41:59 +01001601 abis_om2k_tx_con_conf_req(omfp->trx->bts);
Harald Welte591e1d72016-07-09 22:20:57 +02001602 break;
1603 case OM2K_MO_CLS_TX:
1604 abis_om2k_tx_tx_conf_req(omfp->trx);
1605 break;
1606 case OM2K_MO_CLS_RX:
1607 abis_om2k_tx_rx_conf_req(omfp->trx);
1608 break;
1609 case OM2K_MO_CLS_TS:
1610 ts = mo2obj(omfp->trx->bts, &omfp->mo->addr);
1611 abis_om2k_tx_ts_conf_req(ts);
1612 break;
1613 }
1614}
1615
1616static void om2k_mo_st_wait_cfg_accept(struct osmo_fsm_inst *fi, uint32_t event, void *data)
1617{
1618 struct om2k_mo_fsm_priv *omfp = fi->priv;
1619 uint32_t timeout = OM2K_TIMEOUT;
1620
1621 if (omfp->mo->addr.class == OM2K_MO_CLS_TF)
1622 timeout = 600;
1623
1624 osmo_fsm_inst_state_chg(fi, OM2K_ST_WAIT_CFG_RES, timeout, 0);
1625}
1626
1627static void om2k_mo_st_wait_cfg_res(struct osmo_fsm_inst *fi, uint32_t event, void *data)
1628{
1629 struct om2k_mo_fsm_priv *omfp = fi->priv;
1630 struct om2k_decoded_msg *omd = data;
1631 uint8_t accordance;
1632
1633 if (!TLVP_PRESENT(&omd->tp, OM2K_DEI_ACCORDANCE_IND)) {
1634 osmo_fsm_inst_state_chg(fi, OM2K_ST_ERROR, 0, 0);
1635 return;
1636 }
1637 accordance = *TLVP_VAL(&omd->tp, OM2K_DEI_ACCORDANCE_IND);
1638
1639 if (accordance != 0) {
1640 /* accordance not OK */
1641 osmo_fsm_inst_state_chg(fi, OM2K_ST_ERROR, 0, 0);
1642 return;
1643 }
1644
1645 osmo_fsm_inst_state_chg(fi, OM2K_ST_WAIT_ENABLE_ACCEPT,
1646 OM2K_TIMEOUT, 0);
1647 abis_om2k_tx_enable_req(omfp->trx->bts, &omfp->mo->addr);
1648}
1649
1650static void om2k_mo_st_wait_enable_accept(struct osmo_fsm_inst *fi, uint32_t event, void *data)
1651{
1652 struct om2k_decoded_msg *omd = data;
1653
1654 switch (omd->msg_type) {
1655 case OM2K_MSGT_ENABLE_REQ_REJ:
1656 osmo_fsm_inst_state_chg(fi, OM2K_ST_ERROR, 0, 0);
1657 break;
1658 case OM2K_MSGT_ENABLE_REQ_ACK:
1659 osmo_fsm_inst_state_chg(fi, OM2K_ST_WAIT_ENABLE_RES,
1660 OM2K_TIMEOUT, 0);
1661 }
1662}
1663
1664static void om2k_mo_st_wait_enable_res(struct osmo_fsm_inst *fi, uint32_t event, void *data)
1665{
1666 struct om2k_mo_fsm_priv *omfp = fi->priv;
1667 //struct om2k_decoded_msg *omd = data;
1668 /* TODO: check if state is actually enabled now? */
1669
1670 osmo_fsm_inst_state_chg(fi, OM2K_ST_WAIT_OPINFO_ACCEPT,
1671 OM2K_TIMEOUT, 0);
1672 abis_om2k_tx_op_info(omfp->trx->bts, &omfp->mo->addr, 1);
1673}
1674
1675static void om2k_mo_st_wait_opinfo_accept(struct osmo_fsm_inst *fi, uint32_t event, void *data)
1676{
1677 osmo_fsm_inst_state_chg(fi, OM2K_ST_DONE, 0, 0);
1678}
1679
1680static void om2k_mo_s_done_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state)
1681{
1682 osmo_fsm_inst_term(fi, OSMO_FSM_TERM_REGULAR, NULL);
1683}
1684
1685static const struct osmo_fsm_state om2k_is_states[] = {
1686 [OM2K_ST_INIT] = {
1687 .name = "INIT",
1688 .in_event_mask = S(OM2K_MO_EVT_START),
1689 .out_state_mask = S(OM2K_ST_DONE) |
1690 S(OM2K_ST_ERROR) |
1691 S(OM2K_ST_WAIT_CONN_COMPL) |
1692 S(OM2K_ST_WAIT_START_ACCEPT) |
1693 S(OM2K_ST_WAIT_RES_COMPL),
1694 .action = om2k_mo_st_init,
1695 },
1696 [OM2K_ST_WAIT_CONN_COMPL] = {
1697 .name = "WAIT-CONN-COMPL",
1698 .in_event_mask = S(OM2K_MO_EVT_RX_CONN_COMPL),
1699 .out_state_mask = S(OM2K_ST_DONE) |
1700 S(OM2K_ST_ERROR) |
1701 S(OM2K_ST_WAIT_START_ACCEPT) |
1702 S(OM2K_ST_WAIT_RES_COMPL),
1703 .action = om2k_mo_st_wait_conn_compl,
1704 },
1705 [OM2K_ST_WAIT_RES_COMPL] = {
1706 .name = "WAIT-RES-COMPL",
1707 .in_event_mask = S(OM2K_MO_EVT_RX_RESET_COMPL),
1708 .out_state_mask = S(OM2K_ST_DONE) |
1709 S(OM2K_ST_ERROR) |
1710 S(OM2K_ST_WAIT_START_ACCEPT),
1711 .action = om2k_mo_st_wait_res_compl,
1712 },
1713 [OM2K_ST_WAIT_START_ACCEPT] = {
1714 .name = "WAIT-START-ACCEPT",
1715 .in_event_mask = S(OM2K_MO_EVT_RX_START_REQ_ACCEPT),
1716 .out_state_mask = S(OM2K_ST_DONE) |
1717 S(OM2K_ST_ERROR) |
1718 S(OM2K_ST_WAIT_START_RES),
1719 .action =om2k_mo_st_wait_start_accept,
1720 },
1721 [OM2K_ST_WAIT_START_RES] = {
1722 .name = "WAIT-START-RES",
1723 .in_event_mask = S(OM2K_MO_EVT_RX_START_RES),
1724 .out_state_mask = S(OM2K_ST_DONE) |
1725 S(OM2K_ST_ERROR) |
1726 S(OM2K_ST_WAIT_CFG_ACCEPT) |
1727 S(OM2K_ST_WAIT_OPINFO_ACCEPT),
1728 .action = om2k_mo_st_wait_start_res,
1729 },
1730 [OM2K_ST_WAIT_CFG_ACCEPT] = {
1731 .name = "WAIT-CFG-ACCEPT",
1732 .in_event_mask = S(OM2K_MO_EVT_RX_CFG_REQ_ACCEPT),
1733 .out_state_mask = S(OM2K_ST_DONE) |
1734 S(OM2K_ST_ERROR) |
1735 S(OM2K_ST_WAIT_CFG_RES),
1736 .action = om2k_mo_st_wait_cfg_accept,
1737 },
1738 [OM2K_ST_WAIT_CFG_RES] = {
1739 .name = "WAIT-CFG-RES",
1740 .in_event_mask = S(OM2K_MO_EVT_RX_CFG_RES),
1741 .out_state_mask = S(OM2K_ST_DONE) |
1742 S(OM2K_ST_ERROR) |
1743 S(OM2K_ST_WAIT_ENABLE_ACCEPT),
1744 .action = om2k_mo_st_wait_cfg_res,
1745 },
1746 [OM2K_ST_WAIT_ENABLE_ACCEPT] = {
1747 .name = "WAIT-ENABLE-ACCEPT",
1748 .in_event_mask = S(OM2K_MO_EVT_RX_ENA_REQ_ACCEPT),
1749 .out_state_mask = S(OM2K_ST_DONE) |
1750 S(OM2K_ST_ERROR) |
1751 S(OM2K_ST_WAIT_ENABLE_RES),
1752 .action = om2k_mo_st_wait_enable_accept,
1753 },
1754 [OM2K_ST_WAIT_ENABLE_RES] = {
1755 .name = "WAIT-ENABLE-RES",
1756 .in_event_mask = S(OM2K_MO_EVT_RX_ENA_RES),
1757 .out_state_mask = S(OM2K_ST_DONE) |
1758 S(OM2K_ST_ERROR) |
1759 S(OM2K_ST_WAIT_OPINFO_ACCEPT),
1760 .action = om2k_mo_st_wait_enable_res,
1761 },
1762 [OM2K_ST_WAIT_OPINFO_ACCEPT] = {
1763 .name = "WAIT-OPINFO-ACCEPT",
1764 .in_event_mask = S(OM2K_MO_EVT_RX_OPINFO_ACC),
1765 .out_state_mask = S(OM2K_ST_DONE) |
1766 S(OM2K_ST_ERROR),
1767 .action = om2k_mo_st_wait_opinfo_accept,
1768 },
1769 [OM2K_ST_DONE] = {
1770 .name = "DONE",
1771 .in_event_mask = 0,
1772 .out_state_mask = 0,
1773 .onenter = om2k_mo_s_done_onenter,
1774 },
1775 [OM2K_ST_ERROR] = {
1776 .name = "ERROR",
1777 .in_event_mask = 0,
1778 .out_state_mask = 0,
1779 .onenter = om2k_mo_s_done_onenter,
1780 },
1781
1782};
1783
1784static int om2k_mo_timer_cb(struct osmo_fsm_inst *fi)
1785{
1786 osmo_fsm_inst_state_chg(fi, OM2K_ST_ERROR, 0, 0);
1787 return 0;
1788}
1789
1790static struct osmo_fsm om2k_mo_fsm = {
1791 .name = "OM2000-MO",
1792 .states = om2k_is_states,
1793 .num_states = ARRAY_SIZE(om2k_is_states),
1794 .log_subsys = DNM,
1795 .event_names = om2k_event_names,
1796 .timer_cb = om2k_mo_timer_cb,
1797};
1798
1799struct osmo_fsm_inst *om2k_mo_fsm_start(struct osmo_fsm_inst *parent,
1800 uint32_t term_event,
1801 struct gsm_bts_trx *trx, struct om2k_mo *mo)
1802{
1803 struct osmo_fsm_inst *fi;
1804 struct om2k_mo_fsm_priv *omfp;
1805 char idbuf[64];
1806
1807 snprintf(idbuf, sizeof(idbuf), "%s-%s", parent->id,
1808 om2k_mo_name(&mo->addr));
1809
1810 fi = osmo_fsm_inst_alloc_child_id(&om2k_mo_fsm, parent,
1811 term_event, idbuf);
1812 if (!fi)
1813 return NULL;
1814
1815 mo->fsm = fi;
1816 omfp = talloc_zero(fi, struct om2k_mo_fsm_priv);
1817 omfp->mo = mo;
1818 omfp->trx = trx;
1819 fi->priv = omfp;
1820
1821 osmo_fsm_inst_dispatch(fi, OM2K_MO_EVT_START, NULL);
1822
1823 return fi;
1824}
1825
1826int om2k_mo_fsm_recvmsg(struct gsm_bts *bts, struct om2k_mo *mo,
1827 struct om2k_decoded_msg *odm)
1828{
1829 switch (odm->msg_type) {
1830 case OM2K_MSGT_CONNECT_COMPL:
1831 case OM2K_MSGT_CONNECT_REJ:
1832 osmo_fsm_inst_dispatch(mo->fsm,
1833 OM2K_MO_EVT_RX_CONN_COMPL, odm);
1834 break;
1835
1836 case OM2K_MSGT_RESET_COMPL:
1837 case OM2K_MSGT_RESET_REJ:
1838 osmo_fsm_inst_dispatch(mo->fsm,
1839 OM2K_MO_EVT_RX_RESET_COMPL, odm);
1840 break;
1841
1842 case OM2K_MSGT_START_REQ_ACK:
1843 case OM2K_MSGT_START_REQ_REJ:
1844 osmo_fsm_inst_dispatch(mo->fsm,
1845 OM2K_MO_EVT_RX_START_REQ_ACCEPT, odm);
1846 break;
1847
1848 case OM2K_MSGT_START_RES:
1849 osmo_fsm_inst_dispatch(mo->fsm,
1850 OM2K_MO_EVT_RX_START_RES, odm);
1851 break;
1852
1853 case OM2K_MSGT_CON_CONF_REQ_ACK:
1854 case OM2K_MSGT_IS_CONF_REQ_ACK:
1855 case OM2K_MSGT_RX_CONF_REQ_ACK:
1856 case OM2K_MSGT_TF_CONF_REQ_ACK:
1857 case OM2K_MSGT_TS_CONF_REQ_ACK:
1858 case OM2K_MSGT_TX_CONF_REQ_ACK:
1859 osmo_fsm_inst_dispatch(mo->fsm,
1860 OM2K_MO_EVT_RX_CFG_REQ_ACCEPT, odm);
1861 break;
1862
1863 case OM2K_MSGT_CON_CONF_RES:
1864 case OM2K_MSGT_IS_CONF_RES:
1865 case OM2K_MSGT_RX_CONF_RES:
1866 case OM2K_MSGT_TF_CONF_RES:
1867 case OM2K_MSGT_TS_CONF_RES:
1868 case OM2K_MSGT_TX_CONF_RES:
1869 osmo_fsm_inst_dispatch(mo->fsm,
1870 OM2K_MO_EVT_RX_CFG_RES, odm);
1871 break;
1872
1873 case OM2K_MSGT_ENABLE_REQ_ACK:
1874 case OM2K_MSGT_ENABLE_REQ_REJ:
1875 osmo_fsm_inst_dispatch(mo->fsm,
1876 OM2K_MO_EVT_RX_ENA_REQ_ACCEPT, odm);
1877 break;
1878 case OM2K_MSGT_ENABLE_RES:
1879 osmo_fsm_inst_dispatch(mo->fsm,
1880 OM2K_MO_EVT_RX_ENA_RES, odm);
1881 break;
1882
1883 case OM2K_MSGT_OP_INFO_ACK:
1884 case OM2K_MSGT_OP_INFO_REJ:
1885 osmo_fsm_inst_dispatch(mo->fsm,
1886 OM2K_MO_EVT_RX_OPINFO_ACC, odm);
1887 break;
1888 default:
1889 return -1;
1890 }
1891
1892 return 0;
1893}
1894
1895/***********************************************************************
1896 * OM2000 TRX Finite State Machine, initializes TRXC and all siblings
1897 ***********************************************************************/
1898
1899enum om2k_trx_event {
1900 OM2K_TRX_EVT_START,
1901 OM2K_TRX_EVT_TRXC_DONE,
1902 OM2K_TRX_EVT_TX_DONE,
1903 OM2K_TRX_EVT_RX_DONE,
1904 OM2K_TRX_EVT_TS_DONE,
1905 OM2K_TRX_EVT_STOP,
1906};
1907
1908static struct value_string om2k_trx_events[] = {
1909 { OM2K_TRX_EVT_START, "START" },
1910 { OM2K_TRX_EVT_TRXC_DONE, "TRXC-DONE" },
1911 { OM2K_TRX_EVT_TX_DONE, "TX-DONE" },
1912 { OM2K_TRX_EVT_RX_DONE, "RX-DONE" },
1913 { OM2K_TRX_EVT_TS_DONE, "TS-DONE" },
1914 { OM2K_TRX_EVT_STOP, "STOP" },
1915 { 0, NULL }
1916};
1917
1918enum om2k_trx_state {
1919 OM2K_TRX_S_INIT,
1920 OM2K_TRX_S_WAIT_TRXC,
1921 OM2K_TRX_S_WAIT_TX,
1922 OM2K_TRX_S_WAIT_RX,
1923 OM2K_TRX_S_WAIT_TS,
1924 OM2K_TRX_S_DONE,
1925 OM2K_TRX_S_ERROR
1926};
1927
1928struct om2k_trx_fsm_priv {
1929 struct gsm_bts_trx *trx;
1930 uint8_t next_ts_nr;
1931};
1932
1933static void om2k_trx_s_init(struct osmo_fsm_inst *fi, uint32_t event, void *data)
1934{
1935 struct om2k_trx_fsm_priv *otfp = fi->priv;
1936
1937 /* First initialize TRXC */
1938 osmo_fsm_inst_state_chg(fi, OM2K_TRX_S_WAIT_TRXC,
1939 TRX_FSM_TIMEOUT, 0);
1940 om2k_mo_fsm_start(fi, OM2K_TRX_EVT_TRXC_DONE, otfp->trx,
1941 &otfp->trx->rbs2000.trxc.om2k_mo);
1942}
1943
1944static void om2k_trx_s_wait_trxc(struct osmo_fsm_inst *fi, uint32_t event, void *data)
1945{
1946 struct om2k_trx_fsm_priv *otfp = fi->priv;
1947
1948 /* Initialize TX after TRXC */
1949 osmo_fsm_inst_state_chg(fi, OM2K_TRX_S_WAIT_TX,
1950 TRX_FSM_TIMEOUT, 0);
1951 om2k_mo_fsm_start(fi, OM2K_TRX_EVT_TX_DONE, otfp->trx,
1952 &otfp->trx->rbs2000.tx.om2k_mo);
1953}
1954
1955static void om2k_trx_s_wait_tx(struct osmo_fsm_inst *fi, uint32_t event, void *data)
1956{
1957 struct om2k_trx_fsm_priv *otfp = fi->priv;
1958
1959 /* Initialize RX after TX */
1960 osmo_fsm_inst_state_chg(fi, OM2K_TRX_S_WAIT_RX,
1961 TRX_FSM_TIMEOUT, 0);
1962 om2k_mo_fsm_start(fi, OM2K_TRX_EVT_RX_DONE, otfp->trx,
1963 &otfp->trx->rbs2000.rx.om2k_mo);
1964}
1965
1966static void om2k_trx_s_wait_rx(struct osmo_fsm_inst *fi, uint32_t event, void *data)
1967{
1968 struct om2k_trx_fsm_priv *otfp = fi->priv;
1969 struct gsm_bts_trx_ts *ts;
1970
1971 /* Initialize Timeslots after TX */
1972 osmo_fsm_inst_state_chg(fi, OM2K_TRX_S_WAIT_TS,
1973 TRX_FSM_TIMEOUT, 0);
1974 otfp->next_ts_nr = 0;
1975 ts = &otfp->trx->ts[otfp->next_ts_nr++];
1976 om2k_mo_fsm_start(fi, OM2K_TRX_EVT_TS_DONE, otfp->trx,
1977 &ts->rbs2000.om2k_mo);
1978}
1979
1980static void om2k_trx_s_wait_ts(struct osmo_fsm_inst *fi, uint32_t event, void *data)
1981{
1982 struct om2k_trx_fsm_priv *otfp = fi->priv;
1983 struct gsm_bts_trx_ts *ts;
1984
1985 if (otfp->next_ts_nr < 8) {
1986 /* iterate to the next timeslot */
1987 ts = &otfp->trx->ts[otfp->next_ts_nr++];
1988 om2k_mo_fsm_start(fi, OM2K_TRX_EVT_TS_DONE, otfp->trx,
1989 &ts->rbs2000.om2k_mo);
1990 } else {
1991 /* only after all 8 TS */
1992 osmo_fsm_inst_state_chg(fi, OM2K_TRX_S_DONE, 0, 0);
1993 }
1994}
1995
1996static void om2k_trx_s_done_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state)
1997{
1998 struct om2k_trx_fsm_priv *otfp = fi->priv;
1999 gsm_bts_trx_set_system_infos(otfp->trx);
2000 osmo_fsm_inst_term(fi, OSMO_FSM_TERM_REGULAR, NULL);
2001}
2002
2003static const struct osmo_fsm_state om2k_trx_states[] = {
2004 [OM2K_TRX_S_INIT] = {
2005 .in_event_mask = S(OM2K_TRX_EVT_START),
2006 .out_state_mask = S(OM2K_TRX_S_WAIT_TRXC),
2007 .name = "INIT",
2008 .action = om2k_trx_s_init,
2009 },
2010 [OM2K_TRX_S_WAIT_TRXC] = {
2011 .in_event_mask = S(OM2K_TRX_EVT_TRXC_DONE),
2012 .out_state_mask = S(OM2K_TRX_S_ERROR) |
2013 S(OM2K_TRX_S_WAIT_TX),
2014 .name = "WAIT-TRXC",
2015 .action = om2k_trx_s_wait_trxc,
2016 },
2017 [OM2K_TRX_S_WAIT_TX] = {
2018 .in_event_mask = S(OM2K_TRX_EVT_TX_DONE),
2019 .out_state_mask = S(OM2K_TRX_S_ERROR) |
2020 S(OM2K_TRX_S_WAIT_RX),
2021 .name = "WAIT-TX",
2022 .action = om2k_trx_s_wait_tx,
2023 },
2024 [OM2K_TRX_S_WAIT_RX] = {
2025 .in_event_mask = S(OM2K_TRX_EVT_RX_DONE),
2026 .out_state_mask = S(OM2K_TRX_S_ERROR) |
2027 S(OM2K_TRX_S_WAIT_TS),
2028 .name = "WAIT-RX",
2029 .action = om2k_trx_s_wait_rx,
2030 },
2031 [OM2K_TRX_S_WAIT_TS] = {
2032 .in_event_mask = S(OM2K_TRX_EVT_TS_DONE),
2033 .out_state_mask = S(OM2K_TRX_S_ERROR) |
2034 S(OM2K_TRX_S_DONE),
2035 .name = "WAIT-TS",
2036 .action = om2k_trx_s_wait_ts,
2037 },
2038 [OM2K_TRX_S_DONE] = {
2039 .name = "DONE",
2040 .onenter = om2k_trx_s_done_onenter,
2041 },
2042 [OM2K_TRX_S_ERROR] = {
2043 .name = "ERROR",
2044 },
2045};
2046
2047static int om2k_trx_timer_cb(struct osmo_fsm_inst *fi)
2048{
2049 osmo_fsm_inst_state_chg(fi, OM2K_TRX_S_ERROR, 0, 0);
2050 return 0;
2051}
2052
2053static struct osmo_fsm om2k_trx_fsm = {
2054 .name = "OM2000-TRX",
2055 .states = om2k_trx_states,
2056 .num_states = ARRAY_SIZE(om2k_trx_states),
2057 .log_subsys = DNM,
2058 .event_names = om2k_trx_events,
2059 .timer_cb = om2k_trx_timer_cb,
2060};
2061
2062struct osmo_fsm_inst *om2k_trx_fsm_start(struct osmo_fsm_inst *parent,
2063 struct gsm_bts_trx *trx,
2064 uint32_t term_event)
2065{
2066 struct osmo_fsm_inst *fi;
2067 struct om2k_trx_fsm_priv *otfp;
2068 char idbuf[32];
2069
2070 snprintf(idbuf, sizeof(idbuf), "%u/%u", trx->bts->nr, trx->nr);
2071
2072 fi = osmo_fsm_inst_alloc_child_id(&om2k_trx_fsm, parent, term_event,
2073 idbuf);
2074 if (!fi)
2075 return NULL;
2076
2077 otfp = talloc_zero(fi, struct om2k_trx_fsm_priv);
2078 otfp->trx = trx;
2079 fi->priv = otfp;
2080
2081 osmo_fsm_inst_dispatch(fi, OM2K_TRX_EVT_START, NULL);
2082
2083 return fi;
2084}
2085
2086
2087/***********************************************************************
2088 * OM2000 BTS Finite State Machine, initializes CF and all siblings
2089 ***********************************************************************/
2090
2091enum om2k_bts_event {
2092 OM2K_BTS_EVT_START,
2093 OM2K_BTS_EVT_CF_DONE,
2094 OM2K_BTS_EVT_IS_DONE,
Harald Welteeae68292016-11-11 19:41:59 +01002095 OM2K_BTS_EVT_CON_DONE,
Harald Welte591e1d72016-07-09 22:20:57 +02002096 OM2K_BTS_EVT_TF_DONE,
2097 OM2K_BTS_EVT_TRX_DONE,
2098 OM2K_BTS_EVT_STOP,
2099};
2100
2101static const struct value_string om2k_bts_events[] = {
2102 { OM2K_BTS_EVT_START, "START" },
2103 { OM2K_BTS_EVT_CF_DONE, "CF-DONE" },
2104 { OM2K_BTS_EVT_IS_DONE, "IS-DONE" },
Harald Welteeae68292016-11-11 19:41:59 +01002105 { OM2K_BTS_EVT_CON_DONE, "CON-DONE" },
Harald Welte591e1d72016-07-09 22:20:57 +02002106 { OM2K_BTS_EVT_TF_DONE, "TF-DONE" },
2107 { OM2K_BTS_EVT_TRX_DONE, "TRX-DONE" },
2108 { OM2K_BTS_EVT_STOP, "STOP" },
2109 { 0, NULL }
2110};
2111
2112enum om2k_bts_state {
2113 OM2K_BTS_S_INIT,
2114 OM2K_BTS_S_WAIT_CF,
2115 OM2K_BTS_S_WAIT_IS,
Harald Welteeae68292016-11-11 19:41:59 +01002116 OM2K_BTS_S_WAIT_CON,
Harald Welte591e1d72016-07-09 22:20:57 +02002117 OM2K_BTS_S_WAIT_TF,
2118 OM2K_BTS_S_WAIT_TRX,
2119 OM2K_BTS_S_DONE,
2120 OM2K_BTS_S_ERROR,
2121};
2122
2123struct om2k_bts_fsm_priv {
2124 struct gsm_bts *bts;
2125 uint8_t next_trx_nr;
2126};
2127
2128static void om2k_bts_s_init(struct osmo_fsm_inst *fi, uint32_t event, void *data)
2129{
2130 struct om2k_bts_fsm_priv *obfp = fi->priv;
2131 struct gsm_bts *bts = obfp->bts;
2132
2133 OSMO_ASSERT(event == OM2K_BTS_EVT_START);
2134 osmo_fsm_inst_state_chg(fi, OM2K_BTS_S_WAIT_CF,
2135 BTS_FSM_TIMEOUT, 0);
2136 om2k_mo_fsm_start(fi, OM2K_BTS_EVT_CF_DONE, bts->c0,
2137 &bts->rbs2000.cf.om2k_mo);
2138}
2139
2140static void om2k_bts_s_wait_cf(struct osmo_fsm_inst *fi, uint32_t event, void *data)
2141{
2142 struct om2k_bts_fsm_priv *obfp = fi->priv;
2143 struct gsm_bts *bts = obfp->bts;
2144
2145 OSMO_ASSERT(event == OM2K_BTS_EVT_CF_DONE);
2146 osmo_fsm_inst_state_chg(fi, OM2K_BTS_S_WAIT_IS,
2147 BTS_FSM_TIMEOUT, 0);
2148 om2k_mo_fsm_start(fi, OM2K_BTS_EVT_IS_DONE, bts->c0,
2149 &bts->rbs2000.is.om2k_mo);
2150}
2151
2152static void om2k_bts_s_wait_is(struct osmo_fsm_inst *fi, uint32_t event, void *data)
2153{
2154 struct om2k_bts_fsm_priv *obfp = fi->priv;
2155 struct gsm_bts *bts = obfp->bts;
2156
2157 OSMO_ASSERT(event == OM2K_BTS_EVT_IS_DONE);
Harald Welteeae68292016-11-11 19:41:59 +01002158 osmo_fsm_inst_state_chg(fi, OM2K_BTS_S_WAIT_CON,
2159 BTS_FSM_TIMEOUT, 0);
2160 om2k_mo_fsm_start(fi, OM2K_BTS_EVT_CON_DONE, bts->c0,
2161 &bts->rbs2000.con.om2k_mo);
2162}
2163
2164static void om2k_bts_s_wait_con(struct osmo_fsm_inst *fi, uint32_t event, void *data)
2165{
2166 struct om2k_bts_fsm_priv *obfp = fi->priv;
2167 struct gsm_bts *bts = obfp->bts;
2168
2169 OSMO_ASSERT(event == OM2K_BTS_EVT_CON_DONE);
Harald Welte591e1d72016-07-09 22:20:57 +02002170 /* TF can take a long time to initialize, wait for 10min */
2171 osmo_fsm_inst_state_chg(fi, OM2K_BTS_S_WAIT_TF, 600, 0);
2172 om2k_mo_fsm_start(fi, OM2K_BTS_EVT_TF_DONE, bts->c0,
2173 &bts->rbs2000.tf.om2k_mo);
2174}
2175
2176static void om2k_bts_s_wait_tf(struct osmo_fsm_inst *fi, uint32_t event, void *data)
2177{
2178 struct om2k_bts_fsm_priv *obfp = fi->priv;
2179 struct gsm_bts_trx *trx;
2180
2181 OSMO_ASSERT(event == OM2K_BTS_EVT_TF_DONE);
2182
2183 osmo_fsm_inst_state_chg(fi, OM2K_BTS_S_WAIT_TRX,
2184 BTS_FSM_TIMEOUT, 0);
2185 obfp->next_trx_nr = 0;
2186 trx = gsm_bts_trx_num(obfp->bts, obfp->next_trx_nr++);
2187 om2k_trx_fsm_start(fi, trx, OM2K_BTS_EVT_TRX_DONE);
2188}
2189
2190static void om2k_bts_s_wait_trx(struct osmo_fsm_inst *fi, uint32_t event, void *data)
2191{
2192 struct om2k_bts_fsm_priv *obfp = fi->priv;
2193
2194 OSMO_ASSERT(event == OM2K_BTS_EVT_TRX_DONE);
2195
2196 if (obfp->next_trx_nr < obfp->bts->num_trx) {
2197 struct gsm_bts_trx *trx;
2198 trx = gsm_bts_trx_num(obfp->bts, obfp->next_trx_nr++);
2199 om2k_trx_fsm_start(fi, trx, OM2K_BTS_EVT_TRX_DONE);
2200 } else {
2201 osmo_fsm_inst_state_chg(fi, OM2K_BTS_S_DONE, 0, 0);
2202 }
2203}
2204
2205static void om2k_bts_s_done_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state)
2206{
2207 osmo_fsm_inst_term(fi, OSMO_FSM_TERM_REGULAR, NULL);
2208}
2209
2210static const struct osmo_fsm_state om2k_bts_states[] = {
2211 [OM2K_BTS_S_INIT] = {
2212 .in_event_mask = S(OM2K_BTS_EVT_START),
2213 .out_state_mask = S(OM2K_BTS_S_WAIT_CF),
2214 .name = "INIT",
2215 .action = om2k_bts_s_init,
2216 },
2217 [OM2K_BTS_S_WAIT_CF] = {
2218 .in_event_mask = S(OM2K_BTS_EVT_CF_DONE),
2219 .out_state_mask = S(OM2K_BTS_S_ERROR) |
2220 S(OM2K_BTS_S_WAIT_IS),
2221 .name = "WAIT-CF",
2222 .action = om2k_bts_s_wait_cf,
2223 },
2224 [OM2K_BTS_S_WAIT_IS] = {
2225 .in_event_mask = S(OM2K_BTS_EVT_IS_DONE),
2226 .out_state_mask = S(OM2K_BTS_S_ERROR) |
Harald Welteeae68292016-11-11 19:41:59 +01002227 S(OM2K_BTS_S_WAIT_CON),
Harald Welte591e1d72016-07-09 22:20:57 +02002228 .name = "WAIT-IS",
2229 .action = om2k_bts_s_wait_is,
2230 },
Harald Welteeae68292016-11-11 19:41:59 +01002231 [OM2K_BTS_S_WAIT_CON] = {
2232 .in_event_mask = S(OM2K_BTS_EVT_CON_DONE),
2233 .out_state_mask = S(OM2K_BTS_S_ERROR) |
2234 S(OM2K_BTS_S_WAIT_TF),
2235 .name = "WAIT-CON",
2236 .action = om2k_bts_s_wait_con,
2237 },
Harald Welte591e1d72016-07-09 22:20:57 +02002238 [OM2K_BTS_S_WAIT_TF] = {
2239 .in_event_mask = S(OM2K_BTS_EVT_TF_DONE),
2240 .out_state_mask = S(OM2K_BTS_S_ERROR) |
2241 S(OM2K_BTS_S_WAIT_TRX),
2242 .name = "WAIT-TF",
2243 .action = om2k_bts_s_wait_tf,
2244 },
2245 [OM2K_BTS_S_WAIT_TRX] = {
2246 .in_event_mask = S(OM2K_BTS_EVT_TRX_DONE),
2247 .out_state_mask = S(OM2K_BTS_S_ERROR) |
2248 S(OM2K_BTS_S_DONE),
2249 .name = "WAIT-TRX",
2250 .action = om2k_bts_s_wait_trx,
2251 },
2252 [OM2K_BTS_S_DONE] = {
2253 .name = "DONE",
2254 .onenter = om2k_bts_s_done_onenter,
2255 },
2256 [OM2K_BTS_S_ERROR] = {
2257 .name = "ERROR",
2258 },
2259};
2260
2261static int om2k_bts_timer_cb(struct osmo_fsm_inst *fi)
2262{
2263 osmo_fsm_inst_state_chg(fi, OM2K_BTS_S_ERROR, 0, 0);
2264 return 0;
2265}
2266
2267static struct osmo_fsm om2k_bts_fsm = {
2268 .name = "OM2000-BTS",
2269 .states = om2k_bts_states,
2270 .num_states = ARRAY_SIZE(om2k_bts_states),
2271 .log_subsys = DNM,
2272 .event_names = om2k_bts_events,
2273 .timer_cb = om2k_bts_timer_cb,
2274};
2275
2276struct osmo_fsm_inst *
2277om2k_bts_fsm_start(struct gsm_bts *bts)
2278{
2279 struct osmo_fsm_inst *fi;
2280 struct om2k_bts_fsm_priv *obfp;
2281 char idbuf[16];
2282
2283 snprintf(idbuf, sizeof(idbuf), "%u", bts->nr);
2284
2285 fi = osmo_fsm_inst_alloc(&om2k_bts_fsm, bts, NULL,
2286 LOGL_DEBUG, idbuf);
2287 if (!fi)
2288 return NULL;
2289 fi->priv = obfp = talloc_zero(fi, struct om2k_bts_fsm_priv);
2290 obfp->bts = bts;
2291
2292 osmo_fsm_inst_dispatch(fi, OM2K_BTS_EVT_START, NULL);
2293
2294 return fi;
2295}
2296
2297
2298/***********************************************************************
2299 * OM2000 Negotiation
2300 ***********************************************************************/
2301
Harald Welte6fec79d2011-02-12 14:57:17 +01002302static int abis_om2k_tx_negot_req_ack(struct gsm_bts *bts, const struct abis_om2k_mo *mo,
Harald Welte73541072011-02-12 13:44:14 +01002303 uint8_t *data, unsigned int len)
2304{
2305 struct msgb *msg = om2k_msgb_alloc();
2306 struct abis_om2k_hdr *o2k;
2307
2308 o2k = (struct abis_om2k_hdr *) msgb_put(msg, sizeof(*o2k));
Harald Welte1164dce2011-03-05 19:21:26 +01002309 fill_om2k_hdr(o2k, mo, OM2K_MSGT_NEGOT_REQ_ACK);
Harald Welte73541072011-02-12 13:44:14 +01002310
2311 msgb_tlv_put(msg, OM2K_DEI_NEGOT_REC2, len, data);
2312
2313 DEBUGP(DNM, "Tx MO=%s %s\n", om2k_mo_name(mo),
2314 get_value_string(om2k_msgcode_vals, OM2K_MSGT_NEGOT_REQ_ACK));
2315
2316 return abis_om2k_sendmsg(bts, msg);
2317}
Harald Welte9a311ec2011-02-12 12:33:06 +01002318
Harald Welte563d3162011-02-12 18:11:16 +01002319struct iwd_version {
2320 uint8_t gen_char[3+1];
2321 uint8_t rev_char[3+1];
2322};
2323
2324struct iwd_type {
2325 uint8_t num_vers;
2326 struct iwd_version v[8];
2327};
2328
Harald Welte9a311ec2011-02-12 12:33:06 +01002329static int om2k_rx_negot_req(struct msgb *msg)
2330{
Pablo Neira Ayuso7abecfc2011-08-17 22:43:54 +02002331 struct e1inp_sign_link *sign_link = (struct e1inp_sign_link *)msg->dst;
Harald Welte9a311ec2011-02-12 12:33:06 +01002332 struct abis_om2k_hdr *o2h = msgb_l2(msg);
Harald Welte563d3162011-02-12 18:11:16 +01002333 struct iwd_type iwd_types[16];
2334 uint8_t num_iwd_types = o2h->data[2];
2335 uint8_t *cur = o2h->data+3;
2336 unsigned int i, v;
Harald Welte9a311ec2011-02-12 12:33:06 +01002337
Harald Welte563d3162011-02-12 18:11:16 +01002338 uint8_t out_buf[1024];
2339 uint8_t *out_cur = out_buf+1;
2340 uint8_t out_num_types = 0;
2341
2342 memset(iwd_types, 0, sizeof(iwd_types));
2343
2344 /* Parse the RBS-supported IWD versions into iwd_types array */
2345 for (i = 0; i < num_iwd_types; i++) {
2346 uint8_t num_versions = *cur++;
2347 uint8_t iwd_type = *cur++;
2348
2349 iwd_types[iwd_type].num_vers = num_versions;
2350
2351 for (v = 0; v < num_versions; v++) {
2352 struct iwd_version *iwd_v = &iwd_types[iwd_type].v[v];
2353
2354 memcpy(iwd_v->gen_char, cur, 3);
Harald Welte56ee6b82011-02-12 18:13:37 +01002355 cur += 3;
2356 memcpy(iwd_v->rev_char, cur, 3);
2357 cur += 3;
2358
Harald Welte563d3162011-02-12 18:11:16 +01002359 DEBUGP(DNM, "\tIWD Type %u Gen %s Rev %s\n", iwd_type,
2360 iwd_v->gen_char, iwd_v->rev_char);
2361 }
2362 }
2363
2364 /* Select the last version for each IWD type */
2365 for (i = 0; i < ARRAY_SIZE(iwd_types); i++) {
2366 struct iwd_type *type = &iwd_types[i];
2367 struct iwd_version *last_v;
2368
2369 if (type->num_vers == 0)
2370 continue;
2371
2372 out_num_types++;
2373
2374 last_v = &type->v[type->num_vers-1];
2375
2376 *out_cur++ = i;
2377 memcpy(out_cur, last_v->gen_char, 3);
2378 out_cur += 3;
2379 memcpy(out_cur, last_v->rev_char, 3);
2380 out_cur += 3;
2381 }
2382
2383 out_buf[0] = out_num_types;
2384
Pablo Neira Ayuso7abecfc2011-08-17 22:43:54 +02002385 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 +01002386}
2387
Harald Welte9a311ec2011-02-12 12:33:06 +01002388
Harald Welte591e1d72016-07-09 22:20:57 +02002389/***********************************************************************
2390 * OM2000 Receive Message Handler
2391 ***********************************************************************/
Harald Weltee898ecc2011-03-06 19:26:11 +01002392
Harald Weltee6e83832011-03-05 17:52:09 +01002393static int om2k_rx_nack(struct msgb *msg)
2394{
2395 struct abis_om2k_hdr *o2h = msgb_l2(msg);
2396 uint16_t msg_type = ntohs(o2h->msg_type);
2397 struct tlv_parsed tp;
2398
2399 LOGP(DNM, LOGL_ERROR, "Rx MO=%s %s", om2k_mo_name(&o2h->mo),
2400 get_value_string(om2k_msgcode_vals, msg_type));
2401
Harald Weltee898ecc2011-03-06 19:26:11 +01002402 abis_om2k_msg_tlv_parse(&tp, o2h);
Harald Weltee6e83832011-03-05 17:52:09 +01002403 if (TLVP_PRESENT(&tp, OM2K_DEI_REASON_CODE))
2404 LOGPC(DNM, LOGL_ERROR, ", Reason 0x%02x",
2405 *TLVP_VAL(&tp, OM2K_DEI_REASON_CODE));
2406
2407 if (TLVP_PRESENT(&tp, OM2K_DEI_RESULT_CODE))
2408 LOGPC(DNM, LOGL_ERROR, ", Result %s",
2409 get_value_string(om2k_result_strings,
2410 *TLVP_VAL(&tp, OM2K_DEI_RESULT_CODE)));
2411 LOGPC(DNM, LOGL_ERROR, "\n");
2412
2413 return 0;
2414}
2415
Harald Welte591e1d72016-07-09 22:20:57 +02002416static int process_mo_state(struct gsm_bts *bts, struct om2k_decoded_msg *odm)
Harald Weltee898ecc2011-03-06 19:26:11 +01002417{
Harald Weltee898ecc2011-03-06 19:26:11 +01002418 uint8_t mo_state;
2419
Harald Welte591e1d72016-07-09 22:20:57 +02002420 if (!TLVP_PRESENT(&odm->tp, OM2K_DEI_MO_STATE))
Harald Weltee898ecc2011-03-06 19:26:11 +01002421 return -EIO;
Harald Welte591e1d72016-07-09 22:20:57 +02002422 mo_state = *TLVP_VAL(&odm->tp, OM2K_DEI_MO_STATE);
Harald Weltee898ecc2011-03-06 19:26:11 +01002423
2424 LOGP(DNM, LOGL_DEBUG, "Rx MO=%s %s, MO State: %s\n",
Harald Welte591e1d72016-07-09 22:20:57 +02002425 om2k_mo_name(&odm->o2h.mo),
2426 get_value_string(om2k_msgcode_vals, odm->msg_type),
Harald Weltee898ecc2011-03-06 19:26:11 +01002427 get_value_string(om2k_mostate_vals, mo_state));
2428
Philippb4ecc1d2016-10-20 13:55:21 +02002429 /* Throw error message in case we see an enable rsponse that does
2430 * not yield an enabled mo-state */
2431 if (odm->msg_type == OM2K_MSGT_ENABLE_RES
2432 && mo_state != OM2K_MO_S_ENABLED) {
2433 LOGP(DNM, LOGL_ERROR,
2434 "Rx MO=%s %s Failed to enable MO State!\n",
2435 om2k_mo_name(&odm->o2h.mo),
2436 get_value_string(om2k_msgcode_vals, odm->msg_type));
2437 }
2438
Harald Welte591e1d72016-07-09 22:20:57 +02002439 update_mo_state(bts, &odm->o2h.mo, mo_state);
Harald Welteaf9b8102011-03-06 21:20:38 +01002440
Harald Weltee898ecc2011-03-06 19:26:11 +01002441 return 0;
2442}
2443
Philipp8136e4b2016-10-19 10:14:35 +02002444/* Display fault report bits (helper function of display_fault_maps()) */
Philipp38cba5a2016-11-15 19:27:20 +01002445static bool display_fault_bits(const uint8_t *vect, uint16_t len,
Philipp8136e4b2016-10-19 10:14:35 +02002446 uint8_t dei, const struct abis_om2k_mo *mo)
2447{
Philipp38cba5a2016-11-15 19:27:20 +01002448 uint16_t i;
Philipp8136e4b2016-10-19 10:14:35 +02002449 int k;
2450 bool faults_present = false;
2451 int first = 1;
2452 char string[255];
2453
2454 /* Check if errors are present at all */
2455 for (i = 0; i < len; i++)
2456 if (vect[i])
2457 faults_present = true;
2458 if (!faults_present)
2459 return false;
2460
2461 sprintf(string, "Fault Report: %s (",
2462 get_value_string(om2k_attr_vals, dei));
2463
2464 for (i = 0; i < len; i++) {
2465 for (k = 0; k < 8; k++) {
2466 if ((vect[i] >> k) & 1) {
2467 if (!first)
2468 sprintf(string + strlen(string), ",");
2469 sprintf(string + strlen(string), "%d", k + i*8);
2470 first = 0;
2471 }
2472 }
2473 }
2474
2475 sprintf(string + strlen(string), ")\n");
2476 DEBUGP(DNM, "Rx MO=%s %s", om2k_mo_name(mo), string);
2477
2478 return true;
2479}
2480
2481/* Display fault report maps */
2482static void display_fault_maps(const uint8_t *src, unsigned int src_len,
2483 const struct abis_om2k_mo *mo)
2484{
2485 uint8_t tag;
2486 uint16_t tag_len;
2487 const uint8_t *val;
2488 int src_pos = 0;
2489 int rc;
2490 int tlv_count = 0;
2491 uint16_t msg_code;
2492 bool faults_present = false;
2493
2494 /* Chop off header */
2495 src+=4;
2496 src_len-=4;
2497
2498 /* Check message type */
2499 msg_code = (*src & 0xff) << 8;
2500 src++;
2501 src_len--;
2502 msg_code |= (*src & 0xff);
2503 src++;
2504 src_len--;
2505 if (msg_code != OM2K_MSGT_FAULT_REP) {
2506 LOGP(DNM, LOGL_ERROR, "Rx MO=%s Fault report: invalid message code!\n",
2507 om2k_mo_name(mo));
2508 return;
2509 }
2510
2511 /* Chop off mo-interface */
2512 src += 4;
2513 src_len -= 4;
2514
2515 /* Iterate over each TLV element */
2516 while (1) {
2517
2518 /* Bail if an the maximum number of TLV fields
2519 * have been parsed */
2520 if (tlv_count >= 11) {
2521 LOGP(DNM, LOGL_ERROR,
2522 "Rx MO=%s Fault Report: too many tlv elements!\n",
2523 om2k_mo_name(mo));
2524 return;
2525 }
2526
2527 /* Parse TLV field */
2528 rc = tlv_parse_one(&tag, &tag_len, &val, &om2k_att_tlvdef,
2529 src + src_pos, src_len - src_pos);
2530 if (rc > 0)
2531 src_pos += rc;
2532 else {
2533 LOGP(DNM, LOGL_ERROR,
2534 "Rx MO=%s Fault Report: invalid tlv element!\n",
2535 om2k_mo_name(mo));
2536 return;
2537 }
2538
2539 switch (tag) {
2540 case OM2K_DEI_INT_FAULT_MAP_1A:
2541 case OM2K_DEI_INT_FAULT_MAP_1B:
2542 case OM2K_DEI_INT_FAULT_MAP_2A:
2543 case OM2K_DEI_EXT_COND_MAP_1:
2544 case OM2K_DEI_EXT_COND_MAP_2:
2545 case OM2K_DEI_REPL_UNIT_MAP:
2546 case OM2K_DEI_INT_FAULT_MAP_2A_EXT:
2547 case OM2K_DEI_EXT_COND_MAP_2_EXT:
2548 case OM2K_DEI_REPL_UNIT_MAP_EXT:
2549 faults_present |= display_fault_bits(val, tag_len,
2550 tag, mo);
2551 break;
2552 }
2553
2554 /* Stop when no further TLV elements can be expected */
2555 if (src_len - src_pos < 2)
2556 break;
2557
2558 tlv_count++;
2559 }
2560
2561 if (!faults_present) {
2562 DEBUGP(DNM, "Rx MO=%s Fault Report: All faults ceased!\n",
2563 om2k_mo_name(mo));
2564 }
2565}
2566
Harald Welte9a311ec2011-02-12 12:33:06 +01002567int abis_om2k_rcvmsg(struct msgb *msg)
2568{
Pablo Neira Ayuso7abecfc2011-08-17 22:43:54 +02002569 struct e1inp_sign_link *sign_link = (struct e1inp_sign_link *)msg->dst;
2570 struct gsm_bts *bts = sign_link->trx->bts;
Harald Welte9a311ec2011-02-12 12:33:06 +01002571 struct abis_om2k_hdr *o2h = msgb_l2(msg);
2572 struct abis_om_hdr *oh = &o2h->om;
Harald Weltebc867d92011-02-12 13:09:38 +01002573 uint16_t msg_type = ntohs(o2h->msg_type);
Harald Welte591e1d72016-07-09 22:20:57 +02002574 struct om2k_decoded_msg odm;
2575 struct om2k_mo *mo;
Harald Welte9a311ec2011-02-12 12:33:06 +01002576 int rc = 0;
2577
2578 /* Various consistency checks */
2579 if (oh->placement != ABIS_OM_PLACEMENT_ONLY) {
2580 LOGP(DNM, LOGL_ERROR, "ABIS OML placement 0x%x not supported\n",
2581 oh->placement);
2582 if (oh->placement != ABIS_OM_PLACEMENT_FIRST)
2583 return -EINVAL;
2584 }
2585 if (oh->sequence != 0) {
2586 LOGP(DNM, LOGL_ERROR, "ABIS OML sequence 0x%x != 0x00\n",
2587 oh->sequence);
2588 return -EINVAL;
2589 }
2590
2591 msg->l3h = (unsigned char *)o2h + sizeof(*o2h);
2592
2593 if (oh->mdisc != ABIS_OM_MDISC_FOM) {
2594 LOGP(DNM, LOGL_ERROR, "unknown ABIS OM2000 message discriminator 0x%x\n",
2595 oh->mdisc);
2596 return -EINVAL;
2597 }
2598
Harald Welte73541072011-02-12 13:44:14 +01002599 DEBUGP(DNM, "Rx MO=%s %s (%s)\n", om2k_mo_name(&o2h->mo),
Harald Weltebc867d92011-02-12 13:09:38 +01002600 get_value_string(om2k_msgcode_vals, msg_type),
Pablo Neira Ayusoc0d17f22011-05-07 12:12:48 +02002601 osmo_hexdump(msg->l2h, msgb_l2len(msg)));
Harald Welte9a311ec2011-02-12 12:33:06 +01002602
Harald Welte591e1d72016-07-09 22:20:57 +02002603 om2k_decode_msg(&odm, msg);
2604
2605 process_mo_state(bts, &odm);
2606
Harald Weltebc867d92011-02-12 13:09:38 +01002607 switch (msg_type) {
Harald Welte9a311ec2011-02-12 12:33:06 +01002608 case OM2K_MSGT_CAL_TIME_REQ:
2609 rc = abis_om2k_cal_time_resp(bts);
2610 break;
2611 case OM2K_MSGT_FAULT_REP:
Philipp8136e4b2016-10-19 10:14:35 +02002612 display_fault_maps(msg->l2h, msgb_l2len(msg), &o2h->mo);
Harald Welte9a311ec2011-02-12 12:33:06 +01002613 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_FAULT_REP_ACK);
2614 break;
2615 case OM2K_MSGT_NEGOT_REQ:
2616 rc = om2k_rx_negot_req(msg);
2617 break;
2618 case OM2K_MSGT_START_RES:
Harald Welte591e1d72016-07-09 22:20:57 +02002619 /* common processing here */
2620 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_START_RES_ACK);
2621 /* below we dispatch into MO */
Harald Welte9a311ec2011-02-12 12:33:06 +01002622 break;
2623 case OM2K_MSGT_IS_CONF_RES:
2624 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_IS_CONF_RES_ACK);
2625 break;
Harald Weltefdb71942011-02-14 15:31:43 +01002626 case OM2K_MSGT_CON_CONF_RES:
2627 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_CON_CONF_RES_ACK);
2628 break;
Harald Weltea0ce3492011-03-05 14:13:14 +01002629 case OM2K_MSGT_TX_CONF_RES:
2630 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_TX_CONF_RES_ACK);
2631 break;
2632 case OM2K_MSGT_RX_CONF_RES:
2633 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_RX_CONF_RES_ACK);
2634 break;
2635 case OM2K_MSGT_TS_CONF_RES:
2636 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_TS_CONF_RES_ACK);
2637 break;
Harald Weltef9cf9612011-03-05 14:36:47 +01002638 case OM2K_MSGT_TF_CONF_RES:
2639 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_TF_CONF_RES_ACK);
Harald Welte9a311ec2011-02-12 12:33:06 +01002640 break;
Harald Welteb3d70fd2011-02-13 12:43:44 +01002641 case OM2K_MSGT_ENABLE_RES:
2642 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_ENABLE_RES_ACK);
2643 break;
Harald Weltefdb71942011-02-14 15:31:43 +01002644 case OM2K_MSGT_DISABLE_RES:
2645 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_DISABLE_RES_ACK);
2646 break;
2647 case OM2K_MSGT_TEST_RES:
2648 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_TEST_RES_ACK);
Harald Welte9a311ec2011-02-12 12:33:06 +01002649 break;
root45799782016-10-15 21:24:57 +02002650 case OM2K_MSGT_CAPA_RES:
2651 rc = abis_om2k_tx_simple(bts, &o2h->mo, OM2K_MSGT_CAPA_RES_ACK);
2652 break;
Harald Welte591e1d72016-07-09 22:20:57 +02002653 /* ERrors */
Harald Weltee6e83832011-03-05 17:52:09 +01002654 case OM2K_MSGT_START_REQ_REJ:
Harald Welte3ede7232011-03-05 17:58:13 +01002655 case OM2K_MSGT_CONNECT_REJ:
Harald Welteaff63bc2011-03-05 19:42:16 +01002656 case OM2K_MSGT_OP_INFO_REJ:
Harald Welte3ede7232011-03-05 17:58:13 +01002657 case OM2K_MSGT_DISCONNECT_REJ:
Harald Welteaff63bc2011-03-05 19:42:16 +01002658 case OM2K_MSGT_TEST_REQ_REJ:
Harald Weltee6e83832011-03-05 17:52:09 +01002659 case OM2K_MSGT_CON_CONF_REQ_REJ:
2660 case OM2K_MSGT_IS_CONF_REQ_REJ:
2661 case OM2K_MSGT_TX_CONF_REQ_REJ:
2662 case OM2K_MSGT_RX_CONF_REQ_REJ:
2663 case OM2K_MSGT_TS_CONF_REQ_REJ:
2664 case OM2K_MSGT_TF_CONF_REQ_REJ:
2665 case OM2K_MSGT_ENABLE_REQ_REJ:
2666 case OM2K_MSGT_ALARM_STATUS_REQ_REJ:
2667 case OM2K_MSGT_DISABLE_REQ_REJ:
2668 rc = om2k_rx_nack(msg);
2669 break;
Harald Welte9a311ec2011-02-12 12:33:06 +01002670 }
2671
Harald Welte591e1d72016-07-09 22:20:57 +02002672 /* Resolve the MO for this message */
2673 mo = get_om2k_mo(bts, &o2h->mo);
2674 if (!mo) {
2675 LOGP(DNM, LOGL_ERROR, "Couldn't resolve MO for OM2K msg "
2676 "%s: %s\n", get_value_string(om2k_msgcode_vals, msg_type),
2677 msgb_hexdump(msg));
2678 return 0;
2679 }
2680
2681 /* Dispatch message to that MO */
2682 om2k_mo_fsm_recvmsg(bts, mo, &odm);
2683
Harald Welte9a311ec2011-02-12 12:33:06 +01002684 msgb_free(msg);
2685 return rc;
2686}
Harald Welte591e1d72016-07-09 22:20:57 +02002687
2688static void om2k_mo_init(struct om2k_mo *mo, uint8_t class,
2689 uint8_t bts_nr, uint8_t assoc_so, uint8_t inst)
2690{
2691 mo->addr.class = class;
2692 mo->addr.bts = bts_nr;
2693 mo->addr.assoc_so = assoc_so;
2694 mo->addr.inst = inst;
2695}
2696
2697/* initialize the OM2K_MO members of gsm_bts_trx and its timeslots */
2698void abis_om2k_trx_init(struct gsm_bts_trx *trx)
2699{
2700 struct gsm_bts *bts = trx->bts;
2701 unsigned int i;
2702
2703 OSMO_ASSERT(bts->type == GSM_BTS_TYPE_RBS2000);
2704
2705 om2k_mo_init(&trx->rbs2000.trxc.om2k_mo, OM2K_MO_CLS_TRXC,
2706 bts->nr, 255, trx->nr);
2707 om2k_mo_init(&trx->rbs2000.tx.om2k_mo, OM2K_MO_CLS_TX,
2708 bts->nr, 255, trx->nr);
2709 om2k_mo_init(&trx->rbs2000.rx.om2k_mo, OM2K_MO_CLS_RX,
2710 bts->nr, 255, trx->nr);
2711
2712 for (i = 0; i < ARRAY_SIZE(trx->ts); i++) {
2713 om2k_mo_init(&trx->ts[i].rbs2000.om2k_mo, OM2K_MO_CLS_TS,
2714 bts->nr, trx->nr, i);
2715 }
2716}
2717
2718/* initialize the OM2K_MO members of gsm_bts */
2719void abis_om2k_bts_init(struct gsm_bts *bts)
2720{
2721 OSMO_ASSERT(bts->type == GSM_BTS_TYPE_RBS2000);
2722
2723 om2k_mo_init(&bts->rbs2000.cf.om2k_mo, OM2K_MO_CLS_CF,
2724 bts->nr, 0xFF, 0);
2725 om2k_mo_init(&bts->rbs2000.is.om2k_mo, OM2K_MO_CLS_IS,
2726 bts->nr, 0xFF, 0);
2727 om2k_mo_init(&bts->rbs2000.con.om2k_mo, OM2K_MO_CLS_CON,
2728 bts->nr, 0xFF, 0);
2729 om2k_mo_init(&bts->rbs2000.dp.om2k_mo, OM2K_MO_CLS_DP,
2730 bts->nr, 0xFF, 0);
2731 om2k_mo_init(&bts->rbs2000.tf.om2k_mo, OM2K_MO_CLS_TF,
2732 bts->nr, 0xFF, 0);
2733}
2734
2735static __attribute__((constructor)) void abis_om2k_init(void)
2736{
2737 osmo_fsm_register(&om2k_mo_fsm);
2738 osmo_fsm_register(&om2k_bts_fsm);
2739 osmo_fsm_register(&om2k_trx_fsm);
2740}