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