blob: 3bcd94ba67410e595ca37971ff76433c9fc02957 [file] [log] [blame]
Harald Welte51c82382011-02-12 14:44:16 +01001/* VTY interface for A-bis OM2000 */
2
3/* (C) 2010-2011 by Harald Welte <laforge@gnumonks.org>
4 *
5 * All Rights Reserved
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#include <stdlib.h>
23#include <unistd.h>
24#include <errno.h>
25#include <stdint.h>
26
27#include <arpa/inet.h>
28
29#include <openbsc/gsm_data.h>
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010030#include <osmocom/core/msgb.h>
31#include <osmocom/gsm/tlv.h>
32#include <osmocom/core/talloc.h>
Harald Welte51c82382011-02-12 14:44:16 +010033#include <openbsc/debug.h>
34#include <openbsc/signal.h>
35#include <openbsc/abis_om2000.h>
36#include <openbsc/vty.h>
37
38#include <osmocom/vty/vty.h>
39#include <osmocom/vty/command.h>
40#include <osmocom/vty/logging.h>
41#include <osmocom/vty/telnet_interface.h>
42
43extern struct gsm_network *bsc_gsmnet;
44
45static struct cmd_node om2k_node = {
46 OM2K_NODE,
Harald Welteb0ec9e32011-02-12 20:50:58 +010047 "%s(om2k)# ",
Harald Welte51c82382011-02-12 14:44:16 +010048 1,
49};
50
51struct oml_node_state {
52 struct gsm_bts *bts;
53 struct abis_om2k_mo mo;
54};
55
56static int dummy_config_write(struct vty *v)
57{
58 return CMD_SUCCESS;
59}
60
61/* FIXME: auto-generate those strings from the value_string lists */
62#define OM2K_OBJCLASS_VTY "(trxc|ts|tf|is|con|dp|cf|tx|rx)"
Harald Welte9c0958b2011-02-13 22:51:03 +010063#define OM2K_OBJCLASS_VTY_HELP "TRX Controller\n" \
64 "Timeslot\n" \
65 "Timing Function\n" \
66 "Interface Switch\n" \
67 "Abis Concentrator\n" \
68 "Digital Path\n" \
69 "Central Function\n" \
70 "Transmitter\n" \
71 "Receiver\n"
Harald Welte51c82382011-02-12 14:44:16 +010072
73DEFUN(om2k_class_inst, om2k_class_inst_cmd,
74 "bts <0-255> om2000 class " OM2K_OBJCLASS_VTY
75 " <0-255> <0-255> <0-255>",
76 "BTS related commands\n" "BTS Number\n"
77 "Manipulate the OM2000 managed objects\n"
78 "Object Class\n" OM2K_OBJCLASS_VTY_HELP
79 "BTS Number\n" "Associated SO Instance\n" "Instance Number\n")
80{
81 struct gsm_bts *bts;
82 struct oml_node_state *oms;
83 int bts_nr = atoi(argv[0]);
84
85 bts = gsm_bts_num(bsc_gsmnet, bts_nr);
86 if (!bts) {
87 vty_out(vty, "%% No such BTS (%d)%s", bts_nr, VTY_NEWLINE);
88 return CMD_WARNING;
89 }
90
91 if (bts->type != GSM_BTS_TYPE_RBS2000) {
92 vty_out(vty, "%% BTS %d not an Ericsson RBS%s",
93 bts_nr, VTY_NEWLINE);
94 return CMD_WARNING;
95 }
96
97 oms = talloc_zero(tall_bsc_ctx, struct oml_node_state);
98 if (!oms)
99 return CMD_WARNING;
100
101 oms->bts = bts;
102 oms->mo.class = get_string_value(om2k_mo_class_short_vals, argv[1]);
103 oms->mo.bts = atoi(argv[2]);
104 oms->mo.assoc_so = atoi(argv[3]);
105 oms->mo.inst = atoi(argv[4]);
106
107 vty->index = oms;
108 vty->node = OM2K_NODE;
109
110 return CMD_SUCCESS;
111
112}
113
114DEFUN(om2k_classnum_inst, om2k_classnum_inst_cmd,
115 "bts <0-255> om2000 class <0-255> <0-255> <0-255> <0-255>",
116 "BTS related commands\n" "BTS Number\n"
117 "Manipulate the OML managed objects\n"
118 "Object Class\n" "Object Class\n"
119 "BTS Number\n" "Associated SO Instance\n" "Instance Number\n")
120{
121 struct gsm_bts *bts;
122 struct oml_node_state *oms;
123 int bts_nr = atoi(argv[0]);
124
125 bts = gsm_bts_num(bsc_gsmnet, bts_nr);
126 if (!bts) {
127 vty_out(vty, "%% No such BTS (%d)%s", bts_nr, VTY_NEWLINE);
128 return CMD_WARNING;
129 }
130
131 oms = talloc_zero(tall_bsc_ctx, struct oml_node_state);
132 if (!oms)
133 return CMD_WARNING;
134
135 oms->bts = bts;
136 oms->mo.class = atoi(argv[1]);
137 oms->mo.bts = atoi(argv[2]);
138 oms->mo.assoc_so = atoi(argv[3]);
139 oms->mo.inst = atoi(argv[4]);
140
141 vty->index = oms;
142 vty->node = OM2K_NODE;
143
144 return CMD_SUCCESS;
145}
146
147DEFUN(om2k_reset, om2k_reset_cmd,
148 "reset-command",
149 "Reset the MO\n")
150{
151 struct oml_node_state *oms = vty->index;
152
153 abis_om2k_tx_reset_cmd(oms->bts, &oms->mo);
154 return CMD_SUCCESS;
155}
156
157DEFUN(om2k_start, om2k_start_cmd,
158 "start-request",
159 "Start the MO\n")
160{
161 struct oml_node_state *oms = vty->index;
162
163 abis_om2k_tx_start_req(oms->bts, &oms->mo);
164 return CMD_SUCCESS;
165}
166
167DEFUN(om2k_status, om2k_status_cmd,
168 "status-request",
169 "Get the MO Status\n")
170{
171 struct oml_node_state *oms = vty->index;
172
173 abis_om2k_tx_status_req(oms->bts, &oms->mo);
174 return CMD_SUCCESS;
175}
176
Harald Welte6fec79d2011-02-12 14:57:17 +0100177DEFUN(om2k_connect, om2k_connect_cmd,
178 "connect-command",
179 "Connect the MO\n")
180{
181 struct oml_node_state *oms = vty->index;
182
183 abis_om2k_tx_connect_cmd(oms->bts, &oms->mo);
184 return CMD_SUCCESS;
185}
186
187DEFUN(om2k_disconnect, om2k_disconnect_cmd,
188 "disconnect-command",
189 "Disconnect the MO\n")
190{
191 struct oml_node_state *oms = vty->index;
192
193 abis_om2k_tx_disconnect_cmd(oms->bts, &oms->mo);
194 return CMD_SUCCESS;
195}
196
Harald Welte0741ffe2011-02-12 18:48:53 +0100197DEFUN(om2k_enable, om2k_enable_cmd,
198 "enable-request",
199 "Enable the MO\n")
200{
201 struct oml_node_state *oms = vty->index;
202
203 abis_om2k_tx_enable_req(oms->bts, &oms->mo);
204 return CMD_SUCCESS;
205}
206
207DEFUN(om2k_disable, om2k_disable_cmd,
208 "disable-request",
209 "Disable the MO\n")
210{
211 struct oml_node_state *oms = vty->index;
212
213 abis_om2k_tx_disable_req(oms->bts, &oms->mo);
214 return CMD_SUCCESS;
215}
216
Harald Welte6fec79d2011-02-12 14:57:17 +0100217DEFUN(om2k_op_info, om2k_op_info_cmd,
218 "operational-info <0-1>",
Harald Weltecfaabbb2012-08-16 23:23:50 +0200219 "Set operational information\n"
220 "Set operational info to 0\n"
221 "Set operational info to 1\n")
Harald Welte6fec79d2011-02-12 14:57:17 +0100222{
223 struct oml_node_state *oms = vty->index;
224 int oper = atoi(argv[0]);
225
226 abis_om2k_tx_op_info(oms->bts, &oms->mo, oper);
227 return CMD_SUCCESS;
228}
229
Harald Welte8024d8f2011-02-12 15:07:30 +0100230DEFUN(om2k_test, om2k_test_cmd,
231 "test-request",
232 "Test the MO\n")
233{
234 struct oml_node_state *oms = vty->index;
235
236 abis_om2k_tx_test_req(oms->bts, &oms->mo);
237 return CMD_SUCCESS;
238}
239
Harald Weltea02085d2011-02-13 22:45:02 +0100240struct con_conn_group {
241 struct llist_head list;
242
243 uint8_t cg;
244 uint16_t ccp;
245 uint8_t tag;
246 uint8_t tei;
247};
248
249static void add_con_list(struct gsm_bts *bts, uint8_t cg, uint16_t ccp,
250 uint8_t tag, uint8_t tei)
251{
252 struct con_conn_group *ent = talloc_zero(bts, struct con_conn_group);
253
254 ent->cg = cg;
255 ent->ccp = ccp;
256 ent->tag = tag;
257 ent->tei = tei;
258
Harald Welteda871542011-02-14 16:32:44 +0100259 llist_add_tail(&ent->list, &bts->rbs2000.con.conn_groups);
Harald Weltea02085d2011-02-13 22:45:02 +0100260}
261
262static int del_con_list(struct gsm_bts *bts, uint8_t cg, uint16_t ccp,
263 uint8_t tag, uint8_t tei)
264{
265 struct con_conn_group *grp, *grp2;
266
267 llist_for_each_entry_safe(grp, grp2, &bts->rbs2000.con.conn_groups, list) {
268 if (grp->cg == cg && grp->ccp == ccp && grp->tag == tag
269 && grp->tei == tei) {
270 llist_del(&grp->list);
271 talloc_free(grp);
272 return 0;
273 }
274 }
275 return -ENOENT;
276}
277
278#define CON_LIST_HELP "CON connetiton list\n" \
279 "Add entry to CON list\n" \
280 "Delete entry from CON list\n" \
281 "Connection Group Number\n" \
282 "CON Connection Point\n" \
283
284DEFUN(om2k_con_list_dec, om2k_con_list_dec_cmd,
285 "con-connection-list (add|del) <1-255> <0-1023> deconcentrated",
286 CON_LIST_HELP "De-concentrated in/outlet\n")
287{
288 struct oml_node_state *oms = vty->index;
289 struct gsm_bts *bts = oms->bts;
290 uint8_t cg = atoi(argv[1]);
291 uint16_t ccp = atoi(argv[2]);
292
293 if (!strcmp(argv[0], "add"))
294 add_con_list(bts, cg, ccp, 0, 0xff);
295 else {
296 if (del_con_list(bts, cg, ccp, 0, 0xff) < 0) {
297 vty_out(vty, "%% No matching CON list entry%s",
298 VTY_NEWLINE);
299 return CMD_WARNING;
300 }
301 }
302
303 return CMD_SUCCESS;
304}
305
306DEFUN(om2k_con_list_tei, om2k_con_list_tei_cmd,
307 "con-connection-list (add|del) <1-255> <0-1023> tei <0-63>",
308 CON_LIST_HELP "Concentrated in/outlet with TEI\n" "TEI Number\n")
309{
310 struct oml_node_state *oms = vty->index;
311 struct gsm_bts *bts = oms->bts;
312 uint8_t cg = atoi(argv[1]);
313 uint16_t ccp = atoi(argv[2]);
314 uint8_t tei = atoi(argv[3]);
315
316 if (!strcmp(argv[0], "add"))
317 add_con_list(bts, cg, ccp, cg, tei);
318 else {
319 if (del_con_list(bts, cg, ccp, cg, tei) < 0) {
320 vty_out(vty, "%% No matching CON list entry%s",
321 VTY_NEWLINE);
322 return CMD_WARNING;
323 }
324 }
325
326 return CMD_SUCCESS;
327}
328
Harald Welte59eee422011-02-14 16:17:49 +0100329DEFUN(cfg_bts_is_conn_list, cfg_bts_is_conn_list_cmd,
Harald Weltea8e6a652011-02-13 22:13:28 +0100330 "is-connection-list (add|del) <0-2047> <0-2047> <0-255>",
331 "Interface Switch Connnection List\n"
332 "Add to IS list\n" "Delete from IS list\n"
333 "ICP1\n" "ICP2\n" "Contiguity Index\n")
Harald Welte8bcb1a02011-02-12 20:23:40 +0100334{
Harald Welte59eee422011-02-14 16:17:49 +0100335 struct gsm_bts *bts = vty->index;
Harald Weltea8e6a652011-02-13 22:13:28 +0100336 uint16_t icp1 = atoi(argv[1]);
337 uint16_t icp2 = atoi(argv[2]);
338 uint8_t ci = atoi(argv[3]);
339 struct is_conn_group *grp, *grp2;
Harald Welte8bcb1a02011-02-12 20:23:40 +0100340
Harald Weltea8e6a652011-02-13 22:13:28 +0100341 if (!strcmp(argv[0], "add")) {
342 grp = talloc_zero(bts, struct is_conn_group);
343 grp->icp1 = icp1;
344 grp->icp2 = icp2;
345 grp->ci = ci;
Harald Welteda871542011-02-14 16:32:44 +0100346 llist_add_tail(&grp->list, &bts->rbs2000.is.conn_groups);
Harald Weltea8e6a652011-02-13 22:13:28 +0100347 } else {
348 llist_for_each_entry_safe(grp, grp2, &bts->rbs2000.is.conn_groups, list) {
349 if (grp->icp1 == icp1 && grp->icp2 == icp2
350 && grp->ci == ci) {
351 llist_del(&grp->list);
352 talloc_free(grp);
353 return CMD_SUCCESS;
354 }
355 }
356 vty_out(vty, "%% No matching IS Conn Group found!%s",
357 VTY_NEWLINE);
358 return CMD_WARNING;
359 }
Harald Welte8bcb1a02011-02-12 20:23:40 +0100360
Harald Weltea8e6a652011-02-13 22:13:28 +0100361 return CMD_SUCCESS;
362}
363
364
Harald Weltea0ce3492011-03-05 14:13:14 +0100365DEFUN(om2k_conf_req, om2k_conf_req_cmd,
366 "configuration-request",
367 "Send the configuration request for current MO\n")
368{
369 struct oml_node_state *oms = vty->index;
370 struct gsm_bts *bts = oms->bts;
371 struct gsm_bts_trx *trx = NULL;
372 struct gsm_bts_trx_ts *ts = NULL;
373
374 switch (oms->mo.class) {
Harald Welte217c6b62011-03-06 19:46:15 +0100375 case OM2K_MO_CLS_IS:
Harald Welted529db62011-03-06 21:49:21 +0100376 abis_om2k_tx_is_conf_req(bts);
Harald Welte217c6b62011-03-06 19:46:15 +0100377 break;
Harald Weltea0ce3492011-03-05 14:13:14 +0100378 case OM2K_MO_CLS_TS:
379 trx = gsm_bts_trx_by_nr(bts, oms->mo.assoc_so);
380 if (!trx) {
381 vty_out(vty, "%% BTS %u has no TRX %u%s", bts->nr,
382 oms->mo.assoc_so, VTY_NEWLINE);
383 return CMD_WARNING;
384 }
385 if (oms->mo.inst >= ARRAY_SIZE(trx->ts)) {
386 vty_out(vty, "%% Timeslot %u out of range%s",
387 oms->mo.inst, VTY_NEWLINE);
388 return CMD_WARNING;
389 }
390 ts = &trx->ts[oms->mo.inst];
391 abis_om2k_tx_ts_conf_req(ts);
392 break;
393 case OM2K_MO_CLS_RX:
394 case OM2K_MO_CLS_TX:
395 case OM2K_MO_CLS_TRXC:
396 trx = gsm_bts_trx_by_nr(bts, oms->mo.inst);
397 if (!trx) {
398 vty_out(vty, "%% BTS %u has no TRX %u%s", bts->nr,
399 oms->mo.inst, VTY_NEWLINE);
400 return CMD_WARNING;
401 }
402 switch (oms->mo.class) {
403 case OM2K_MO_CLS_RX:
404 abis_om2k_tx_rx_conf_req(trx);
405 break;
406 case OM2K_MO_CLS_TX:
Harald Welte52af3ae2011-03-05 16:14:34 +0100407 abis_om2k_tx_tx_conf_req(trx);
Harald Weltea0ce3492011-03-05 14:13:14 +0100408 break;
409 default:
410 break;
411 }
412 break;
Harald Weltef9cf9612011-03-05 14:36:47 +0100413 case OM2K_MO_CLS_TF:
414 abis_om2k_tx_tf_conf_req(bts);
415 break;
Harald Weltea0ce3492011-03-05 14:13:14 +0100416 default:
417 vty_out(vty, "%% Don't know how to configure MO%s",
418 VTY_NEWLINE);
419 }
420
421 return CMD_SUCCESS;
422}
423
Harald Welte59eee422011-02-14 16:17:49 +0100424void abis_om2k_config_write_bts(struct vty *vty, struct gsm_bts *bts)
425{
426 struct is_conn_group *igrp;
427 struct con_conn_group *cgrp;
428
429 llist_for_each_entry(igrp, &bts->rbs2000.is.conn_groups, list)
430 vty_out(vty, " is-connection-list add %u %u %u%s",
431 igrp->icp1, igrp->icp2, igrp->ci, VTY_NEWLINE);
432
433 llist_for_each_entry(cgrp, &bts->rbs2000.con.conn_groups, list) {
434 vty_out(vty, " con-connection-list add %u %u ",
435 cgrp->cg, cgrp->ccp);
436 if (cgrp->tei == 0xff)
437 vty_out(vty, "deconcentrated%s", VTY_NEWLINE);
438 else
439 vty_out(vty, "tei %u%s", cgrp->tei, VTY_NEWLINE);
440 }
441}
442
Harald Welte51c82382011-02-12 14:44:16 +0100443int abis_om2k_vty_init(void)
444{
445 install_element(ENABLE_NODE, &om2k_class_inst_cmd);
446 install_element(ENABLE_NODE, &om2k_classnum_inst_cmd);
447 install_node(&om2k_node, dummy_config_write);
448
449 install_default(OM2K_NODE);
450 install_element(OM2K_NODE, &ournode_exit_cmd);
451 install_element(OM2K_NODE, &om2k_reset_cmd);
452 install_element(OM2K_NODE, &om2k_start_cmd);
453 install_element(OM2K_NODE, &om2k_status_cmd);
Harald Welte6fec79d2011-02-12 14:57:17 +0100454 install_element(OM2K_NODE, &om2k_connect_cmd);
455 install_element(OM2K_NODE, &om2k_disconnect_cmd);
Harald Welte0741ffe2011-02-12 18:48:53 +0100456 install_element(OM2K_NODE, &om2k_enable_cmd);
457 install_element(OM2K_NODE, &om2k_disable_cmd);
Harald Welte6fec79d2011-02-12 14:57:17 +0100458 install_element(OM2K_NODE, &om2k_op_info_cmd);
Harald Welte8024d8f2011-02-12 15:07:30 +0100459 install_element(OM2K_NODE, &om2k_test_cmd);
Harald Weltea0ce3492011-03-05 14:13:14 +0100460 install_element(OM2K_NODE, &om2k_conf_req_cmd);
Harald Weltea02085d2011-02-13 22:45:02 +0100461 install_element(OM2K_NODE, &om2k_con_list_dec_cmd);
462 install_element(OM2K_NODE, &om2k_con_list_tei_cmd);
Harald Welte51c82382011-02-12 14:44:16 +0100463
Harald Welte59eee422011-02-14 16:17:49 +0100464 install_element(BTS_NODE, &cfg_bts_is_conn_list_cmd);
465
Harald Welte51c82382011-02-12 14:44:16 +0100466 return 0;
467}