blob: 89055019608b491e05c1f0da359b82fb38441ddc [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>
22#include <sys/types.h>
23
24#include <osmocom/vty/command.h>
25#include <osmocom/vty/buffer.h>
26#include <osmocom/vty/vty.h>
27#include <osmocom/vty/logging.h>
28#include <osmocom/vty/telnet_interface.h>
29
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010030#include <osmocom/core/linuxlist.h>
Harald Welte3016d9f2011-02-05 13:54:41 +010031#include <openbsc/gsm_data.h>
32#include <openbsc/e1_input.h>
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010033#include <osmocom/core/utils.h>
34#include <osmocom/gsm/gsm_utils.h>
35#include <osmocom/core/talloc.h>
Harald Welte3016d9f2011-02-05 13:54:41 +010036#include <openbsc/vty.h>
37#include <openbsc/debug.h>
38
Harald Weltec08e8be2011-03-04 13:53:51 +010039#include "../../bscconfig.h"
Harald Welte3016d9f2011-02-05 13:54:41 +010040
Harald Welte1dd68c32011-02-05 13:58:46 +010041#define E1_DRIVER_NAMES "(misdn|dahdi)"
42#define E1_DRIVER_HELP "mISDN supported E1 Card\n" \
43 "DAHDI supported E1/T1/J1 Card\n"
Harald Welte3016d9f2011-02-05 13:54:41 +010044
45DEFUN(cfg_e1line_driver, cfg_e1_line_driver_cmd,
46 "e1_line <0-255> driver " E1_DRIVER_NAMES,
47 "Configure E1/T1/J1 Line\n" "Line Number\n" "Set driver for this line\n"
48 E1_DRIVER_HELP)
49{
50 struct e1inp_line *line;
51 int e1_nr = atoi(argv[0]);
52
53 line = e1inp_line_get(e1_nr);
54 if (line) {
55 vty_out(vty, "%% Line %d already exists%s", e1_nr, VTY_NEWLINE);
56 return CMD_WARNING;
57 }
58 line = e1inp_line_create(e1_nr, argv[1]);
59 if (!line) {
60 vty_out(vty, "%% Error creating line %d%s", e1_nr, VTY_NEWLINE);
61 return CMD_WARNING;
62 }
63
64 return CMD_SUCCESS;
65}
66
67DEFUN(cfg_e1inp, cfg_e1inp_cmd,
68 "e1_input",
69 "Configure E1/T1/J1 TDM input\n")
70{
71 vty->node = E1INP_NODE;
72
73 return CMD_SUCCESS;
74}
75
76static int e1inp_config_write(struct vty *vty)
77{
78 struct e1inp_line *line;
79
Harald Welte07bb0da2011-02-05 15:57:42 +010080 vty_out(vty, "e1_input%s", VTY_NEWLINE);
81
Harald Welte3016d9f2011-02-05 13:54:41 +010082 llist_for_each_entry(line, &e1inp_line_list, list) {
83 vty_out(vty, " e1_line %u driver %s%s", line->num,
84 line->driver->name, VTY_NEWLINE);
85 }
86 return CMD_SUCCESS;
87}
88
89struct cmd_node e1inp_node = {
90 E1INP_NODE,
91 "%s(e1_input)#",
92 1,
93};
94
95int e1inp_vty_init(void)
96{
97 install_element(CONFIG_NODE, &cfg_e1inp_cmd);
98 install_node(&e1inp_node, e1inp_config_write);
99 install_element(E1INP_NODE, &cfg_e1_line_driver_cmd);
100
101 return 0;
102}