blob: 9d6958693d726ad0c352b3377fb82a1199c9b1ab [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>
Harald Welted4f8f682011-08-19 13:28:48 +020023#include <string.h>
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020024
Harald Weltef2737fc2011-08-16 14:30:10 +020025#include <osmocom/core/linuxlist.h>
26#include <osmocom/core/talloc.h>
27#include <osmocom/core/utils.h>
28#include <osmocom/gsm/gsm_utils.h>
29
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020030#include <osmocom/vty/command.h>
31#include <osmocom/vty/buffer.h>
32#include <osmocom/vty/vty.h>
33#include <osmocom/vty/logging.h>
Harald Weltef2737fc2011-08-16 14:30:10 +020034#include <osmocom/vty/misc.h>
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020035#include <osmocom/vty/telnet_interface.h>
36
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020037#include <osmocom/abis/e1_input.h>
Harald Weltef2737fc2011-08-16 14:30:10 +020038
39/* CONFIG */
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020040
Alexander Couzensbeb10ef2016-11-01 22:05:13 +010041#define E1_DRIVER_NAMES "(misdn|misdn_lapd|dahdi|ipa|unixsocket)"
Harald Weltece307b42011-08-21 01:18:05 +020042#define E1_DRIVER_HELP "mISDN supported E1 Card (kernel LAPD)\n" \
43 "mISDN supported E1 Card (userspace LAPD)\n" \
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020044 "DAHDI supported E1/T1/J1 Card\n" \
Holger Hans Peter Freyther36bac9a2012-07-20 23:49:52 +020045 "IPA TCP/IP input\n" \
Alexander Couzensbeb10ef2016-11-01 22:05:13 +010046 "HSL TCP/IP input\n" \
47 "Unix socket input\n"
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020048
Harald Welte601a9c72011-08-16 14:17:49 +020049#define E1_LINE_HELP "Configure E1/T1/J1 Line\n" "Line Number\n"
50
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020051DEFUN(cfg_e1line_driver, cfg_e1_line_driver_cmd,
52 "e1_line <0-255> driver " E1_DRIVER_NAMES,
Harald Welte601a9c72011-08-16 14:17:49 +020053 E1_LINE_HELP "Set driver for this line\n"
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020054 E1_DRIVER_HELP)
55{
56 struct e1inp_line *line;
57 int e1_nr = atoi(argv[0]);
58
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +020059 line = e1inp_line_find(e1_nr);
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020060 if (line) {
61 vty_out(vty, "%% Line %d already exists%s", e1_nr, VTY_NEWLINE);
62 return CMD_WARNING;
63 }
64 line = e1inp_line_create(e1_nr, argv[1]);
65 if (!line) {
66 vty_out(vty, "%% Error creating line %d%s", e1_nr, VTY_NEWLINE);
67 return CMD_WARNING;
68 }
69
70 return CMD_SUCCESS;
71}
72
Harald Weltec2889512011-09-13 23:49:04 +010073DEFUN(cfg_e1line_port, cfg_e1_line_port_cmd,
Harald Welte356918f2011-09-26 22:54:51 +020074 "e1_line <0-255> port <0-255>",
75 E1_LINE_HELP "Set physical port/span/card number\n"
Harald Weltec2889512011-09-13 23:49:04 +010076 "E1/T1 Port/Span/Card number\n")
77{
78 struct e1inp_line *line;
79 int e1_nr = atoi(argv[0]);
80
81 line = e1inp_line_find(e1_nr);
82 if (!line) {
83 vty_out(vty, "%% Line %d doesn't exist%s", e1_nr, VTY_NEWLINE);
84 return CMD_WARNING;
85 }
86
87 line->port_nr = atoi(argv[1]);
88
89 return CMD_SUCCESS;
90}
91
Alexander Couzensbeb10ef2016-11-01 22:05:13 +010092DEFUN(cfg_e1line_socket, cfg_e1_line_socket_cmd,
93 "e1_line <0-255> socket .SOCKET",
94 E1_LINE_HELP "Set socket path for unixsocket\n"
95 "socket path\n")
96{
97 struct e1inp_line *line;
98 int e1_nr = atoi(argv[0]);
99
100 line = e1inp_line_find(e1_nr);
101 if (!line) {
102 vty_out(vty, "%% Line %d doesn't exist%s", e1_nr, VTY_NEWLINE);
103 return CMD_WARNING;
104 }
105
106 line->sock_path = talloc_strdup(line, argv[1]);
107
108 return CMD_SUCCESS;
109}
110
Jacob Erlbeck86dae842014-01-16 18:10:37 +0100111#define KEEPALIVE_HELP "Enable keep-alive probing\n"
112static int set_keepalive_params(struct vty *vty, int e1_nr,
113 int idle, int num_probes, int probe_interval)
114{
115 struct e1inp_line *line = e1inp_line_find(e1_nr);
116
117 if (!line) {
118 vty_out(vty, "%% Line %d doesn't exist%s", e1_nr, VTY_NEWLINE);
119 return CMD_WARNING;
120 }
121 if (!line->driver->has_keepalive && num_probes != 0) {
122 vty_out(vty, "%% Driver '%s' does not support keep alive%s",
123 line->driver->name, VTY_NEWLINE);
124 return CMD_WARNING;
125 }
126
127 line->keepalive_idle_timeout = idle;
128 line->keepalive_num_probes = num_probes;
129 line->keepalive_probe_interval = probe_interval;
130
131 return CMD_SUCCESS;
132}
133
134DEFUN(cfg_e1line_keepalive, cfg_e1_line_keepalive_cmd,
135 "e1_line <0-255> keepalive",
136 E1_LINE_HELP KEEPALIVE_HELP)
137{
138 return set_keepalive_params(vty, atoi(argv[0]),
139 E1INP_USE_DEFAULT, E1INP_USE_DEFAULT,
140 E1INP_USE_DEFAULT);
141}
142
143DEFUN(cfg_e1line_keepalive_params, cfg_e1_line_keepalive_params_cmd,
144 "e1_line <0-255> keepalive <1-300> <1-20> <1-300>",
145 E1_LINE_HELP KEEPALIVE_HELP
146 "Idle interval in seconds before probes are sent\n"
147 "Number of probes to sent\n"
148 "Delay between probe packets in seconds\n")
149{
150 return set_keepalive_params(vty, atoi(argv[0]),
151 atoi(argv[1]), atoi(argv[2]), atoi(argv[3]));
152}
153
154DEFUN(cfg_e1line_no_keepalive, cfg_e1_line_no_keepalive_cmd,
155 "no e1_line <0-255> keepalive",
156 NO_STR E1_LINE_HELP KEEPALIVE_HELP)
157{
158 return set_keepalive_params(vty, atoi(argv[0]), 0, 0, 0);
159}
160
Harald Welte601a9c72011-08-16 14:17:49 +0200161DEFUN(cfg_e1line_name, cfg_e1_line_name_cmd,
162 "e1_line <0-255> name .LINE",
163 E1_LINE_HELP "Set name for this line\n" "Human readable name\n")
164{
165 struct e1inp_line *line;
166 int e1_nr = atoi(argv[0]);
167
168 line = e1inp_line_find(e1_nr);
169 if (!line) {
170 vty_out(vty, "%% Line %d doesn't exist%s", e1_nr, VTY_NEWLINE);
171 return CMD_WARNING;
172 }
173 if (line->name) {
174 talloc_free((void *)line->name);
175 line->name = NULL;
176 }
177 line->name = talloc_strdup(line, argv[1]);
178
179 return CMD_SUCCESS;
180}
181
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200182DEFUN(cfg_e1inp, cfg_e1inp_cmd,
183 "e1_input",
184 "Configure E1/T1/J1 TDM input\n")
185{
Harald Weltecc2241b2011-07-19 16:06:06 +0200186 vty->node = L_E1INP_NODE;
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200187
188 return CMD_SUCCESS;
189}
190
Neels Hofmeyr0db1d432016-02-22 13:29:09 +0100191DEFUN(cfg_ipa_bind,
192 cfg_ipa_bind_cmd,
193 "ipa bind A.B.C.D",
194 "ipa driver config\n"
195 "Set ipa local bind address\n"
196 "Listen on this IP address (default 0.0.0.0)\n")
197{
198 e1inp_ipa_set_bind_addr(argv[0]);
199 return CMD_SUCCESS;
200}
201
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200202static int e1inp_config_write(struct vty *vty)
203{
204 struct e1inp_line *line;
205
206 if (llist_empty(&e1inp_line_list))
207 return CMD_SUCCESS;
208
209 vty_out(vty, "e1_input%s", VTY_NEWLINE);
210
211 llist_for_each_entry(line, &e1inp_line_list, list) {
212 vty_out(vty, " e1_line %u driver %s%s", line->num,
213 line->driver->name, VTY_NEWLINE);
Harald Weltec2889512011-09-13 23:49:04 +0100214 vty_out(vty, " e1_line %u port %u%s", line->num,
215 line->port_nr, VTY_NEWLINE);
Harald Welte601a9c72011-08-16 14:17:49 +0200216 if (line->name)
217 vty_out(vty, " e1_line %u name %s%s", line->num,
218 line->name, VTY_NEWLINE);
Jacob Erlbeck86dae842014-01-16 18:10:37 +0100219 if (!line->keepalive_num_probes)
220 vty_out(vty, " no e1_line %u keepalive%s", line->num,
221 VTY_NEWLINE);
222 else if (line->keepalive_idle_timeout == E1INP_USE_DEFAULT &&
223 line->keepalive_num_probes == E1INP_USE_DEFAULT &&
224 line->keepalive_probe_interval == E1INP_USE_DEFAULT)
225 vty_out(vty, " e1_line %u keepalive%s", line->num,
226 VTY_NEWLINE);
227 else
228 vty_out(vty, " e1_line %u keepalive %d %d %d%s",
229 line->num,
230 line->keepalive_idle_timeout,
231 line->keepalive_num_probes,
232 line->keepalive_probe_interval,
233 VTY_NEWLINE);
234
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200235 }
Neels Hofmeyr0db1d432016-02-22 13:29:09 +0100236
237 const char *ipa_bind = e1inp_ipa_get_bind_addr();
238 if (ipa_bind && (strcmp(ipa_bind, "0.0.0.0") != 0))
239 vty_out(vty, " ipa bind %s%s",
240 ipa_bind, VTY_NEWLINE);
241
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200242 return CMD_SUCCESS;
243}
244
Harald Weltef2737fc2011-08-16 14:30:10 +0200245/* SHOW */
246
Harald Welte6e37c592011-08-11 12:43:31 +0200247static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv)
248{
249 vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE);
250}
251
252DEFUN(show_e1drv,
253 show_e1drv_cmd,
254 "show e1_driver",
255 SHOW_STR "Display information about available E1 drivers\n")
256{
257 struct e1inp_driver *drv;
258
259 llist_for_each_entry(drv, &e1inp_driver_list, list)
260 e1drv_dump_vty(vty, drv);
261
262 return CMD_SUCCESS;
263}
264
Harald Weltef2737fc2011-08-16 14:30:10 +0200265static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line,
266 int stats)
Harald Welte6e37c592011-08-11 12:43:31 +0200267{
268 vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s",
269 line->num, line->name ? line->name : "",
270 line->driver->name, VTY_NEWLINE);
Harald Weltefe05cf52011-09-26 23:18:41 +0200271 if (line->driver->vty_show)
272 line->driver->vty_show(vty, line);
Harald Weltef2737fc2011-08-16 14:30:10 +0200273 if (stats)
274 vty_out_rate_ctr_group(vty, " ", line->rate_ctr);
Harald Welte6e37c592011-08-11 12:43:31 +0200275}
276
277DEFUN(show_e1line,
278 show_e1line_cmd,
Harald Weltef2737fc2011-08-16 14:30:10 +0200279 "show e1_line [line_nr] [stats]",
Harald Welte6e37c592011-08-11 12:43:31 +0200280 SHOW_STR "Display information about a E1 line\n"
Holger Hans Peter Freyther9e8f1c02012-07-21 00:09:52 +0200281 "E1 Line Number\n" "Include statistics\n")
Harald Welte6e37c592011-08-11 12:43:31 +0200282{
283 struct e1inp_line *line;
Harald Weltef2737fc2011-08-16 14:30:10 +0200284 int stats = 0;
Harald Welte6e37c592011-08-11 12:43:31 +0200285
Harald Weltef2737fc2011-08-16 14:30:10 +0200286 if (argc >= 1 && strcmp(argv[0], "stats")) {
Harald Welte6e37c592011-08-11 12:43:31 +0200287 int num = atoi(argv[0]);
Harald Weltef2737fc2011-08-16 14:30:10 +0200288 if (argc >= 2)
289 stats = 1;
Harald Welte6e37c592011-08-11 12:43:31 +0200290 llist_for_each_entry(line, &e1inp_line_list, list) {
291 if (line->num == num) {
Harald Weltef2737fc2011-08-16 14:30:10 +0200292 e1line_dump_vty(vty, line, stats);
Harald Welte6e37c592011-08-11 12:43:31 +0200293 return CMD_SUCCESS;
294 }
295 }
296 return CMD_WARNING;
297 }
298
Harald Weltef2737fc2011-08-16 14:30:10 +0200299 if (argc >= 1 && !strcmp(argv[0], "stats"))
300 stats = 1;
301
Harald Welte6e37c592011-08-11 12:43:31 +0200302 llist_for_each_entry(line, &e1inp_line_list, list)
Harald Weltef2737fc2011-08-16 14:30:10 +0200303 e1line_dump_vty(vty, line, stats);
Harald Welte6e37c592011-08-11 12:43:31 +0200304
305 return CMD_SUCCESS;
306}
307
308static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts)
309{
310 if (ts->type == E1INP_TS_TYPE_NONE)
311 return;
312 vty_out(vty, "E1 Timeslot %2u of Line %u is Type %s%s",
313 ts->num, ts->line->num, e1inp_tstype_name(ts->type),
314 VTY_NEWLINE);
315}
316
317DEFUN(show_e1ts,
318 show_e1ts_cmd,
319 "show e1_timeslot [line_nr] [ts_nr]",
320 SHOW_STR "Display information about a E1 timeslot\n"
321 "E1 Line Number\n" "E1 Timeslot Number\n")
322{
323 struct e1inp_line *line = NULL;
324 struct e1inp_ts *ts;
325 int ts_nr;
326
Holger Hans Peter Freyther8cbd9f42013-07-04 20:00:33 +0200327 if (argc <= 0) {
Harald Welte6e37c592011-08-11 12:43:31 +0200328 llist_for_each_entry(line, &e1inp_line_list, list) {
Harald Weltec2889512011-09-13 23:49:04 +0100329 for (ts_nr = 0; ts_nr < line->num_ts; ts_nr++) {
Harald Welte6e37c592011-08-11 12:43:31 +0200330 ts = &line->ts[ts_nr];
331 e1ts_dump_vty(vty, ts);
332 }
333 }
334 return CMD_SUCCESS;
335 }
336 if (argc >= 1) {
337 int num = atoi(argv[0]);
338 struct e1inp_line *l;
339 llist_for_each_entry(l, &e1inp_line_list, list) {
340 if (l->num == num) {
341 line = l;
342 break;
343 }
344 }
345 if (!line) {
346 vty_out(vty, "E1 line %s is invalid%s",
347 argv[0], VTY_NEWLINE);
348 return CMD_WARNING;
349 }
350 }
351 if (argc >= 2) {
352 ts_nr = atoi(argv[1]);
Harald Weltec2889512011-09-13 23:49:04 +0100353 if (ts_nr >= line->num_ts) {
Harald Welte6e37c592011-08-11 12:43:31 +0200354 vty_out(vty, "E1 timeslot %s is invalid%s",
355 argv[1], VTY_NEWLINE);
356 return CMD_WARNING;
357 }
358 ts = &line->ts[ts_nr];
359 e1ts_dump_vty(vty, ts);
360 return CMD_SUCCESS;
361 } else {
Harald Weltec2889512011-09-13 23:49:04 +0100362 for (ts_nr = 0; ts_nr < line->num_ts; ts_nr++) {
Harald Welte6e37c592011-08-11 12:43:31 +0200363 ts = &line->ts[ts_nr];
364 e1ts_dump_vty(vty, ts);
365 }
366 return CMD_SUCCESS;
367 }
368 return CMD_SUCCESS;
369}
370
371
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200372struct cmd_node e1inp_node = {
Harald Weltecc2241b2011-07-19 16:06:06 +0200373 L_E1INP_NODE,
Jacob Erlbeck1c9dcc12013-11-11 14:13:13 +0100374 "%s(config-e1_input)# ",
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200375 1,
376};
377
378int e1inp_vty_init(void)
379{
380 install_element(CONFIG_NODE, &cfg_e1inp_cmd);
381 install_node(&e1inp_node, e1inp_config_write);
Jacob Erlbeck37f06952013-11-11 14:13:12 +0100382
383 vty_install_default(L_E1INP_NODE);
Harald Weltecc2241b2011-07-19 16:06:06 +0200384 install_element(L_E1INP_NODE, &cfg_e1_line_driver_cmd);
Harald Weltec2889512011-09-13 23:49:04 +0100385 install_element(L_E1INP_NODE, &cfg_e1_line_port_cmd);
Alexander Couzensbeb10ef2016-11-01 22:05:13 +0100386 install_element(L_E1INP_NODE, &cfg_e1_line_socket_cmd);
Harald Welte601a9c72011-08-16 14:17:49 +0200387 install_element(L_E1INP_NODE, &cfg_e1_line_name_cmd);
Jacob Erlbeck86dae842014-01-16 18:10:37 +0100388 install_element(L_E1INP_NODE, &cfg_e1_line_keepalive_cmd);
389 install_element(L_E1INP_NODE, &cfg_e1_line_keepalive_params_cmd);
390 install_element(L_E1INP_NODE, &cfg_e1_line_no_keepalive_cmd);
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200391
Neels Hofmeyr0db1d432016-02-22 13:29:09 +0100392 install_element(L_E1INP_NODE, &cfg_ipa_bind_cmd);
393
Harald Welte6e37c592011-08-11 12:43:31 +0200394 install_element_ve(&show_e1drv_cmd);
395 install_element_ve(&show_e1line_cmd);
396 install_element_ve(&show_e1ts_cmd);
397
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200398 return 0;
399}