blob: 212a4acdd71a9b5be17a101c3542f6674b0997e2 [file] [log] [blame]
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +02001/* 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#include "internal.h"
20
21#include <stdlib.h>
22#include <unistd.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
30#include <osmocom/core/linuxlist.h>
31#include <osmocom/abis/e1_input.h>
32#include <osmocom/core/utils.h>
33#include <osmocom/gsm/gsm_utils.h>
34#include <talloc.h>
35
36#define E1_DRIVER_NAMES "(misdn|dahdi|ipa|hsl)"
37#define E1_DRIVER_HELP "mISDN supported E1 Card\n" \
38 "DAHDI supported E1/T1/J1 Card\n" \
39 "IPA TCP/IP input" \
40 "HSL TCP/IP input"
41
42DEFUN(cfg_e1line_driver, cfg_e1_line_driver_cmd,
43 "e1_line <0-255> driver " E1_DRIVER_NAMES,
44 "Configure E1/T1/J1 Line\n" "Line Number\n" "Set driver for this line\n"
45 E1_DRIVER_HELP)
46{
47 struct e1inp_line *line;
48 int e1_nr = atoi(argv[0]);
49
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +020050 line = e1inp_line_find(e1_nr);
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020051 if (line) {
52 vty_out(vty, "%% Line %d already exists%s", e1_nr, VTY_NEWLINE);
53 return CMD_WARNING;
54 }
55 line = e1inp_line_create(e1_nr, argv[1]);
56 if (!line) {
57 vty_out(vty, "%% Error creating line %d%s", e1_nr, VTY_NEWLINE);
58 return CMD_WARNING;
59 }
60
61 return CMD_SUCCESS;
62}
63
64DEFUN(cfg_e1inp, cfg_e1inp_cmd,
65 "e1_input",
66 "Configure E1/T1/J1 TDM input\n")
67{
68 vty->node = E1INP_NODE;
69
70 return CMD_SUCCESS;
71}
72
73static int e1inp_config_write(struct vty *vty)
74{
75 struct e1inp_line *line;
76
77 if (llist_empty(&e1inp_line_list))
78 return CMD_SUCCESS;
79
80 vty_out(vty, "e1_input%s", VTY_NEWLINE);
81
82 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}