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