blob: 1b6ea1f1b354643ec1d8b34888a4ae906d00ef96 [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>
Harald Welte71d87b22011-07-18 14:49:56 +020034#include <osmocom/core/talloc.h>
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020035
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
Harald Welte601a9c72011-08-16 14:17:49 +020042#define E1_LINE_HELP "Configure E1/T1/J1 Line\n" "Line Number\n"
43
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020044DEFUN(cfg_e1line_driver, cfg_e1_line_driver_cmd,
45 "e1_line <0-255> driver " E1_DRIVER_NAMES,
Harald Welte601a9c72011-08-16 14:17:49 +020046 E1_LINE_HELP "Set driver for this line\n"
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020047 E1_DRIVER_HELP)
48{
49 struct e1inp_line *line;
50 int e1_nr = atoi(argv[0]);
51
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +020052 line = e1inp_line_find(e1_nr);
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020053 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
Harald Welte601a9c72011-08-16 14:17:49 +020066DEFUN(cfg_e1line_name, cfg_e1_line_name_cmd,
67 "e1_line <0-255> name .LINE",
68 E1_LINE_HELP "Set name for this line\n" "Human readable name\n")
69{
70 struct e1inp_line *line;
71 int e1_nr = atoi(argv[0]);
72
73 line = e1inp_line_find(e1_nr);
74 if (!line) {
75 vty_out(vty, "%% Line %d doesn't exist%s", e1_nr, VTY_NEWLINE);
76 return CMD_WARNING;
77 }
78 if (line->name) {
79 talloc_free((void *)line->name);
80 line->name = NULL;
81 }
82 line->name = talloc_strdup(line, argv[1]);
83
84 return CMD_SUCCESS;
85}
86
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020087DEFUN(cfg_e1inp, cfg_e1inp_cmd,
88 "e1_input",
89 "Configure E1/T1/J1 TDM input\n")
90{
Harald Weltecc2241b2011-07-19 16:06:06 +020091 vty->node = L_E1INP_NODE;
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020092
93 return CMD_SUCCESS;
94}
95
96static int e1inp_config_write(struct vty *vty)
97{
98 struct e1inp_line *line;
99
100 if (llist_empty(&e1inp_line_list))
101 return CMD_SUCCESS;
102
103 vty_out(vty, "e1_input%s", VTY_NEWLINE);
104
105 llist_for_each_entry(line, &e1inp_line_list, list) {
106 vty_out(vty, " e1_line %u driver %s%s", line->num,
107 line->driver->name, VTY_NEWLINE);
Harald Welte601a9c72011-08-16 14:17:49 +0200108 if (line->name)
109 vty_out(vty, " e1_line %u name %s%s", line->num,
110 line->name, VTY_NEWLINE);
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200111 }
112 return CMD_SUCCESS;
113}
114
115struct cmd_node e1inp_node = {
Harald Weltecc2241b2011-07-19 16:06:06 +0200116 L_E1INP_NODE,
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200117 "%s(e1_input)#",
118 1,
119};
120
121int e1inp_vty_init(void)
122{
123 install_element(CONFIG_NODE, &cfg_e1inp_cmd);
124 install_node(&e1inp_node, e1inp_config_write);
Harald Weltecc2241b2011-07-19 16:06:06 +0200125 install_element(L_E1INP_NODE, &cfg_e1_line_driver_cmd);
Harald Welte601a9c72011-08-16 14:17:49 +0200126 install_element(L_E1INP_NODE, &cfg_e1_line_name_cmd);
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200127
128 return 0;
129}