blob: cce4eb388ecd68d231f27f3124b5f828191dc716 [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>
30#include <osmocore/msgb.h>
31#include <osmocore/tlv.h>
32#include <osmocore/talloc.h>
33#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>",
219 "Set operational information\n")
220{
221 struct oml_node_state *oms = vty->index;
222 int oper = atoi(argv[0]);
223
224 abis_om2k_tx_op_info(oms->bts, &oms->mo, oper);
225 return CMD_SUCCESS;
226}
227
Harald Welte8024d8f2011-02-12 15:07:30 +0100228DEFUN(om2k_test, om2k_test_cmd,
229 "test-request",
230 "Test the MO\n")
231{
232 struct oml_node_state *oms = vty->index;
233
234 abis_om2k_tx_test_req(oms->bts, &oms->mo);
235 return CMD_SUCCESS;
236}
237
Harald Weltea02085d2011-02-13 22:45:02 +0100238struct con_conn_group {
239 struct llist_head list;
240
241 uint8_t cg;
242 uint16_t ccp;
243 uint8_t tag;
244 uint8_t tei;
245};
246
247static void add_con_list(struct gsm_bts *bts, uint8_t cg, uint16_t ccp,
248 uint8_t tag, uint8_t tei)
249{
250 struct con_conn_group *ent = talloc_zero(bts, struct con_conn_group);
251
252 ent->cg = cg;
253 ent->ccp = ccp;
254 ent->tag = tag;
255 ent->tei = tei;
256
Harald Welteda871542011-02-14 16:32:44 +0100257 llist_add_tail(&ent->list, &bts->rbs2000.con.conn_groups);
Harald Weltea02085d2011-02-13 22:45:02 +0100258}
259
260static int del_con_list(struct gsm_bts *bts, uint8_t cg, uint16_t ccp,
261 uint8_t tag, uint8_t tei)
262{
263 struct con_conn_group *grp, *grp2;
264
265 llist_for_each_entry_safe(grp, grp2, &bts->rbs2000.con.conn_groups, list) {
266 if (grp->cg == cg && grp->ccp == ccp && grp->tag == tag
267 && grp->tei == tei) {
268 llist_del(&grp->list);
269 talloc_free(grp);
270 return 0;
271 }
272 }
273 return -ENOENT;
274}
275
276#define CON_LIST_HELP "CON connetiton list\n" \
277 "Add entry to CON list\n" \
278 "Delete entry from CON list\n" \
279 "Connection Group Number\n" \
280 "CON Connection Point\n" \
281
282DEFUN(om2k_con_list_dec, om2k_con_list_dec_cmd,
283 "con-connection-list (add|del) <1-255> <0-1023> deconcentrated",
284 CON_LIST_HELP "De-concentrated in/outlet\n")
285{
286 struct oml_node_state *oms = vty->index;
287 struct gsm_bts *bts = oms->bts;
288 uint8_t cg = atoi(argv[1]);
289 uint16_t ccp = atoi(argv[2]);
290
291 if (!strcmp(argv[0], "add"))
292 add_con_list(bts, cg, ccp, 0, 0xff);
293 else {
294 if (del_con_list(bts, cg, ccp, 0, 0xff) < 0) {
295 vty_out(vty, "%% No matching CON list entry%s",
296 VTY_NEWLINE);
297 return CMD_WARNING;
298 }
299 }
300
301 return CMD_SUCCESS;
302}
303
304DEFUN(om2k_con_list_tei, om2k_con_list_tei_cmd,
305 "con-connection-list (add|del) <1-255> <0-1023> tei <0-63>",
306 CON_LIST_HELP "Concentrated in/outlet with TEI\n" "TEI Number\n")
307{
308 struct oml_node_state *oms = vty->index;
309 struct gsm_bts *bts = oms->bts;
310 uint8_t cg = atoi(argv[1]);
311 uint16_t ccp = atoi(argv[2]);
312 uint8_t tei = atoi(argv[3]);
313
314 if (!strcmp(argv[0], "add"))
315 add_con_list(bts, cg, ccp, cg, tei);
316 else {
317 if (del_con_list(bts, cg, ccp, cg, tei) < 0) {
318 vty_out(vty, "%% No matching CON list entry%s",
319 VTY_NEWLINE);
320 return CMD_WARNING;
321 }
322 }
323
324 return CMD_SUCCESS;
325}
326
Harald Welte59eee422011-02-14 16:17:49 +0100327DEFUN(cfg_bts_is_conn_list, cfg_bts_is_conn_list_cmd,
Harald Weltea8e6a652011-02-13 22:13:28 +0100328 "is-connection-list (add|del) <0-2047> <0-2047> <0-255>",
329 "Interface Switch Connnection List\n"
330 "Add to IS list\n" "Delete from IS list\n"
331 "ICP1\n" "ICP2\n" "Contiguity Index\n")
Harald Welte8bcb1a02011-02-12 20:23:40 +0100332{
Harald Welte59eee422011-02-14 16:17:49 +0100333 struct gsm_bts *bts = vty->index;
Harald Weltea8e6a652011-02-13 22:13:28 +0100334 uint16_t icp1 = atoi(argv[1]);
335 uint16_t icp2 = atoi(argv[2]);
336 uint8_t ci = atoi(argv[3]);
337 struct is_conn_group *grp, *grp2;
Harald Welte8bcb1a02011-02-12 20:23:40 +0100338
Harald Weltea8e6a652011-02-13 22:13:28 +0100339 if (!strcmp(argv[0], "add")) {
340 grp = talloc_zero(bts, struct is_conn_group);
341 grp->icp1 = icp1;
342 grp->icp2 = icp2;
343 grp->ci = ci;
Harald Welteda871542011-02-14 16:32:44 +0100344 llist_add_tail(&grp->list, &bts->rbs2000.is.conn_groups);
Harald Weltea8e6a652011-02-13 22:13:28 +0100345 } else {
346 llist_for_each_entry_safe(grp, grp2, &bts->rbs2000.is.conn_groups, list) {
347 if (grp->icp1 == icp1 && grp->icp2 == icp2
348 && grp->ci == ci) {
349 llist_del(&grp->list);
350 talloc_free(grp);
351 return CMD_SUCCESS;
352 }
353 }
354 vty_out(vty, "%% No matching IS Conn Group found!%s",
355 VTY_NEWLINE);
356 return CMD_WARNING;
357 }
Harald Welte8bcb1a02011-02-12 20:23:40 +0100358
Harald Weltea8e6a652011-02-13 22:13:28 +0100359 return CMD_SUCCESS;
360}
361
362
Harald Weltea0ce3492011-03-05 14:13:14 +0100363DEFUN(om2k_conf_req, om2k_conf_req_cmd,
364 "configuration-request",
365 "Send the configuration request for current MO\n")
366{
367 struct oml_node_state *oms = vty->index;
368 struct gsm_bts *bts = oms->bts;
369 struct gsm_bts_trx *trx = NULL;
370 struct gsm_bts_trx_ts *ts = NULL;
371
372 switch (oms->mo.class) {
Harald Welte217c6b62011-03-06 19:46:15 +0100373 case OM2K_MO_CLS_IS:
Harald Welted529db62011-03-06 21:49:21 +0100374 abis_om2k_tx_is_conf_req(bts);
Harald Welte217c6b62011-03-06 19:46:15 +0100375 break;
Harald Weltea0ce3492011-03-05 14:13:14 +0100376 case OM2K_MO_CLS_TS:
377 trx = gsm_bts_trx_by_nr(bts, oms->mo.assoc_so);
378 if (!trx) {
379 vty_out(vty, "%% BTS %u has no TRX %u%s", bts->nr,
380 oms->mo.assoc_so, VTY_NEWLINE);
381 return CMD_WARNING;
382 }
383 if (oms->mo.inst >= ARRAY_SIZE(trx->ts)) {
384 vty_out(vty, "%% Timeslot %u out of range%s",
385 oms->mo.inst, VTY_NEWLINE);
386 return CMD_WARNING;
387 }
388 ts = &trx->ts[oms->mo.inst];
389 abis_om2k_tx_ts_conf_req(ts);
390 break;
391 case OM2K_MO_CLS_RX:
392 case OM2K_MO_CLS_TX:
393 case OM2K_MO_CLS_TRXC:
394 trx = gsm_bts_trx_by_nr(bts, oms->mo.inst);
395 if (!trx) {
396 vty_out(vty, "%% BTS %u has no TRX %u%s", bts->nr,
397 oms->mo.inst, VTY_NEWLINE);
398 return CMD_WARNING;
399 }
400 switch (oms->mo.class) {
401 case OM2K_MO_CLS_RX:
402 abis_om2k_tx_rx_conf_req(trx);
403 break;
404 case OM2K_MO_CLS_TX:
Harald Welte52af3ae2011-03-05 16:14:34 +0100405 abis_om2k_tx_tx_conf_req(trx);
Harald Weltea0ce3492011-03-05 14:13:14 +0100406 break;
407 default:
408 break;
409 }
410 break;
Harald Weltef9cf9612011-03-05 14:36:47 +0100411 case OM2K_MO_CLS_TF:
412 abis_om2k_tx_tf_conf_req(bts);
413 break;
Harald Weltea0ce3492011-03-05 14:13:14 +0100414 default:
415 vty_out(vty, "%% Don't know how to configure MO%s",
416 VTY_NEWLINE);
417 }
418
419 return CMD_SUCCESS;
420}
421
Harald Welte59eee422011-02-14 16:17:49 +0100422void abis_om2k_config_write_bts(struct vty *vty, struct gsm_bts *bts)
423{
424 struct is_conn_group *igrp;
425 struct con_conn_group *cgrp;
426
427 llist_for_each_entry(igrp, &bts->rbs2000.is.conn_groups, list)
428 vty_out(vty, " is-connection-list add %u %u %u%s",
429 igrp->icp1, igrp->icp2, igrp->ci, VTY_NEWLINE);
430
431 llist_for_each_entry(cgrp, &bts->rbs2000.con.conn_groups, list) {
432 vty_out(vty, " con-connection-list add %u %u ",
433 cgrp->cg, cgrp->ccp);
434 if (cgrp->tei == 0xff)
435 vty_out(vty, "deconcentrated%s", VTY_NEWLINE);
436 else
437 vty_out(vty, "tei %u%s", cgrp->tei, VTY_NEWLINE);
438 }
439}
440
Harald Welte51c82382011-02-12 14:44:16 +0100441int abis_om2k_vty_init(void)
442{
443 install_element(ENABLE_NODE, &om2k_class_inst_cmd);
444 install_element(ENABLE_NODE, &om2k_classnum_inst_cmd);
445 install_node(&om2k_node, dummy_config_write);
446
447 install_default(OM2K_NODE);
448 install_element(OM2K_NODE, &ournode_exit_cmd);
449 install_element(OM2K_NODE, &om2k_reset_cmd);
450 install_element(OM2K_NODE, &om2k_start_cmd);
451 install_element(OM2K_NODE, &om2k_status_cmd);
Harald Welte6fec79d2011-02-12 14:57:17 +0100452 install_element(OM2K_NODE, &om2k_connect_cmd);
453 install_element(OM2K_NODE, &om2k_disconnect_cmd);
Harald Welte0741ffe2011-02-12 18:48:53 +0100454 install_element(OM2K_NODE, &om2k_enable_cmd);
455 install_element(OM2K_NODE, &om2k_disable_cmd);
Harald Welte6fec79d2011-02-12 14:57:17 +0100456 install_element(OM2K_NODE, &om2k_op_info_cmd);
Harald Welte8024d8f2011-02-12 15:07:30 +0100457 install_element(OM2K_NODE, &om2k_test_cmd);
Harald Weltea0ce3492011-03-05 14:13:14 +0100458 install_element(OM2K_NODE, &om2k_conf_req_cmd);
Harald Weltea02085d2011-02-13 22:45:02 +0100459 install_element(OM2K_NODE, &om2k_con_list_dec_cmd);
460 install_element(OM2K_NODE, &om2k_con_list_tei_cmd);
Harald Welte51c82382011-02-12 14:44:16 +0100461
Harald Welte59eee422011-02-14 16:17:49 +0100462 install_element(BTS_NODE, &cfg_bts_is_conn_list_cmd);
463
Harald Welte51c82382011-02-12 14:44:16 +0100464 return 0;
465}