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