blob: b211e818f671fec0f78e61952d7fefe43855f827 [file] [log] [blame]
Harald Welte3016d9f2011-02-05 13:54:41 +01001/* OpenBSC E1 vty interface */
2/* (C) 2011 by Harald Welte <laforge@gnumonks.org>
3 * All Rights Reserved
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 */
19
20#include <stdlib.h>
21#include <unistd.h>
Harald Welte3016d9f2011-02-05 13:54:41 +010022
23#include <osmocom/vty/command.h>
24#include <osmocom/vty/buffer.h>
25#include <osmocom/vty/vty.h>
26#include <osmocom/vty/logging.h>
27#include <osmocom/vty/telnet_interface.h>
28
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010029#include <osmocom/core/linuxlist.h>
Harald Welte3016d9f2011-02-05 13:54:41 +010030#include <openbsc/gsm_data.h>
31#include <openbsc/e1_input.h>
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010032#include <osmocom/core/utils.h>
33#include <osmocom/gsm/gsm_utils.h>
34#include <osmocom/core/talloc.h>
Harald Welte3016d9f2011-02-05 13:54:41 +010035#include <openbsc/vty.h>
36#include <openbsc/debug.h>
37
Harald Weltec08e8be2011-03-04 13:53:51 +010038#include "../../bscconfig.h"
Harald Welte3016d9f2011-02-05 13:54:41 +010039
Harald Welte1dd68c32011-02-05 13:58:46 +010040#define E1_DRIVER_NAMES "(misdn|dahdi)"
41#define E1_DRIVER_HELP "mISDN supported E1 Card\n" \
42 "DAHDI supported E1/T1/J1 Card\n"
Harald Welte3016d9f2011-02-05 13:54:41 +010043
44DEFUN(cfg_e1line_driver, cfg_e1_line_driver_cmd,
45 "e1_line <0-255> driver " E1_DRIVER_NAMES,
46 "Configure E1/T1/J1 Line\n" "Line Number\n" "Set driver for this line\n"
47 E1_DRIVER_HELP)
48{
49 struct e1inp_line *line;
50 int e1_nr = atoi(argv[0]);
51
52 line = e1inp_line_get(e1_nr);
53 if (line) {
54 vty_out(vty, "%% Line %d already exists%s", e1_nr, VTY_NEWLINE);
55 return CMD_WARNING;
56 }
57 line = e1inp_line_create(e1_nr, argv[1]);
58 if (!line) {
59 vty_out(vty, "%% Error creating line %d%s", e1_nr, VTY_NEWLINE);
60 return CMD_WARNING;
61 }
62
63 return CMD_SUCCESS;
64}
65
66DEFUN(cfg_e1inp, cfg_e1inp_cmd,
67 "e1_input",
68 "Configure E1/T1/J1 TDM input\n")
69{
70 vty->node = E1INP_NODE;
71
72 return CMD_SUCCESS;
73}
74
75static int e1inp_config_write(struct vty *vty)
76{
77 struct e1inp_line *line;
78
Pablo Neira Ayusod2a78782011-05-14 11:32:45 +020079 if (llist_empty(&e1inp_line_list))
80 return CMD_SUCCESS;
81
Harald Welte07bb0da2011-02-05 15:57:42 +010082 vty_out(vty, "e1_input%s", VTY_NEWLINE);
83
Harald Welte3016d9f2011-02-05 13:54:41 +010084 llist_for_each_entry(line, &e1inp_line_list, list) {
85 vty_out(vty, " e1_line %u driver %s%s", line->num,
86 line->driver->name, VTY_NEWLINE);
87 }
88 return CMD_SUCCESS;
89}
90
91struct cmd_node e1inp_node = {
92 E1INP_NODE,
93 "%s(e1_input)#",
94 1,
95};
96
97int e1inp_vty_init(void)
98{
99 install_element(CONFIG_NODE, &cfg_e1inp_cmd);
100 install_node(&e1inp_node, e1inp_config_write);
101 install_element(E1INP_NODE, &cfg_e1_line_driver_cmd);
102
103 return 0;
104}