blob: fe14799480270675a15a58862364e2e8ea9f8e4e [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
Harald Welte6e37c592011-08-11 12:43:31 +0200115static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv)
116{
117 vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE);
118}
119
120DEFUN(show_e1drv,
121 show_e1drv_cmd,
122 "show e1_driver",
123 SHOW_STR "Display information about available E1 drivers\n")
124{
125 struct e1inp_driver *drv;
126
127 llist_for_each_entry(drv, &e1inp_driver_list, list)
128 e1drv_dump_vty(vty, drv);
129
130 return CMD_SUCCESS;
131}
132
133static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line)
134{
135 vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s",
136 line->num, line->name ? line->name : "",
137 line->driver->name, VTY_NEWLINE);
138}
139
140DEFUN(show_e1line,
141 show_e1line_cmd,
142 "show e1_line [line_nr]",
143 SHOW_STR "Display information about a E1 line\n"
144 "E1 Line Number\n")
145{
146 struct e1inp_line *line;
147
148 if (argc >= 1) {
149 int num = atoi(argv[0]);
150 llist_for_each_entry(line, &e1inp_line_list, list) {
151 if (line->num == num) {
152 e1line_dump_vty(vty, line);
153 return CMD_SUCCESS;
154 }
155 }
156 return CMD_WARNING;
157 }
158
159 llist_for_each_entry(line, &e1inp_line_list, list)
160 e1line_dump_vty(vty, line);
161
162 return CMD_SUCCESS;
163}
164
165static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts)
166{
167 if (ts->type == E1INP_TS_TYPE_NONE)
168 return;
169 vty_out(vty, "E1 Timeslot %2u of Line %u is Type %s%s",
170 ts->num, ts->line->num, e1inp_tstype_name(ts->type),
171 VTY_NEWLINE);
172}
173
174DEFUN(show_e1ts,
175 show_e1ts_cmd,
176 "show e1_timeslot [line_nr] [ts_nr]",
177 SHOW_STR "Display information about a E1 timeslot\n"
178 "E1 Line Number\n" "E1 Timeslot Number\n")
179{
180 struct e1inp_line *line = NULL;
181 struct e1inp_ts *ts;
182 int ts_nr;
183
184 if (argc == 0) {
185 llist_for_each_entry(line, &e1inp_line_list, list) {
186 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
187 ts = &line->ts[ts_nr];
188 e1ts_dump_vty(vty, ts);
189 }
190 }
191 return CMD_SUCCESS;
192 }
193 if (argc >= 1) {
194 int num = atoi(argv[0]);
195 struct e1inp_line *l;
196 llist_for_each_entry(l, &e1inp_line_list, list) {
197 if (l->num == num) {
198 line = l;
199 break;
200 }
201 }
202 if (!line) {
203 vty_out(vty, "E1 line %s is invalid%s",
204 argv[0], VTY_NEWLINE);
205 return CMD_WARNING;
206 }
207 }
208 if (argc >= 2) {
209 ts_nr = atoi(argv[1]);
210 if (ts_nr >= NUM_E1_TS) {
211 vty_out(vty, "E1 timeslot %s is invalid%s",
212 argv[1], VTY_NEWLINE);
213 return CMD_WARNING;
214 }
215 ts = &line->ts[ts_nr];
216 e1ts_dump_vty(vty, ts);
217 return CMD_SUCCESS;
218 } else {
219 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
220 ts = &line->ts[ts_nr];
221 e1ts_dump_vty(vty, ts);
222 }
223 return CMD_SUCCESS;
224 }
225 return CMD_SUCCESS;
226}
227
228
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200229struct cmd_node e1inp_node = {
Harald Weltecc2241b2011-07-19 16:06:06 +0200230 L_E1INP_NODE,
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200231 "%s(e1_input)#",
232 1,
233};
234
235int e1inp_vty_init(void)
236{
237 install_element(CONFIG_NODE, &cfg_e1inp_cmd);
238 install_node(&e1inp_node, e1inp_config_write);
Harald Weltecc2241b2011-07-19 16:06:06 +0200239 install_element(L_E1INP_NODE, &cfg_e1_line_driver_cmd);
Harald Welte601a9c72011-08-16 14:17:49 +0200240 install_element(L_E1INP_NODE, &cfg_e1_line_name_cmd);
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200241
Harald Welte6e37c592011-08-11 12:43:31 +0200242 install_element_ve(&show_e1drv_cmd);
243 install_element_ve(&show_e1line_cmd);
244 install_element_ve(&show_e1ts_cmd);
245
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200246 return 0;
247}