blob: 0e4575f5bdead14fad66940e089fe726b2359d5a [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 *
Harald Welte323d39d2017-11-13 01:09:21 +09005 * SPDX-License-Identifier: AGPL-3.0+
6 *
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +02007 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21#include "internal.h"
22
23#include <stdlib.h>
24#include <unistd.h>
Harald Welted4f8f682011-08-19 13:28:48 +020025#include <string.h>
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020026
Harald Weltef2737fc2011-08-16 14:30:10 +020027#include <osmocom/core/linuxlist.h>
28#include <osmocom/core/talloc.h>
29#include <osmocom/core/utils.h>
30#include <osmocom/gsm/gsm_utils.h>
31
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020032#include <osmocom/vty/command.h>
33#include <osmocom/vty/buffer.h>
34#include <osmocom/vty/vty.h>
35#include <osmocom/vty/logging.h>
Harald Weltef2737fc2011-08-16 14:30:10 +020036#include <osmocom/vty/misc.h>
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020037#include <osmocom/vty/telnet_interface.h>
38
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020039#include <osmocom/abis/e1_input.h>
Harald Weltef2737fc2011-08-16 14:30:10 +020040
41/* CONFIG */
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020042
Alexander Couzensbeb10ef2016-11-01 22:05:13 +010043#define E1_DRIVER_NAMES "(misdn|misdn_lapd|dahdi|ipa|unixsocket)"
Harald Weltece307b42011-08-21 01:18:05 +020044#define E1_DRIVER_HELP "mISDN supported E1 Card (kernel LAPD)\n" \
45 "mISDN supported E1 Card (userspace LAPD)\n" \
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020046 "DAHDI supported E1/T1/J1 Card\n" \
Holger Hans Peter Freyther36bac9a2012-07-20 23:49:52 +020047 "IPA TCP/IP input\n" \
Alexander Couzensbeb10ef2016-11-01 22:05:13 +010048 "HSL TCP/IP input\n" \
49 "Unix socket input\n"
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020050
Harald Welte601a9c72011-08-16 14:17:49 +020051#define E1_LINE_HELP "Configure E1/T1/J1 Line\n" "Line Number\n"
52
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020053DEFUN(cfg_e1line_driver, cfg_e1_line_driver_cmd,
54 "e1_line <0-255> driver " E1_DRIVER_NAMES,
Harald Welte601a9c72011-08-16 14:17:49 +020055 E1_LINE_HELP "Set driver for this line\n"
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020056 E1_DRIVER_HELP)
57{
58 struct e1inp_line *line;
59 int e1_nr = atoi(argv[0]);
60
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +020061 line = e1inp_line_find(e1_nr);
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020062 if (line) {
63 vty_out(vty, "%% Line %d already exists%s", e1_nr, VTY_NEWLINE);
64 return CMD_WARNING;
65 }
66 line = e1inp_line_create(e1_nr, argv[1]);
67 if (!line) {
68 vty_out(vty, "%% Error creating line %d%s", e1_nr, VTY_NEWLINE);
69 return CMD_WARNING;
70 }
71
72 return CMD_SUCCESS;
73}
74
Harald Weltec2889512011-09-13 23:49:04 +010075DEFUN(cfg_e1line_port, cfg_e1_line_port_cmd,
Harald Welte356918f2011-09-26 22:54:51 +020076 "e1_line <0-255> port <0-255>",
77 E1_LINE_HELP "Set physical port/span/card number\n"
Harald Weltec2889512011-09-13 23:49:04 +010078 "E1/T1 Port/Span/Card number\n")
79{
80 struct e1inp_line *line;
81 int e1_nr = atoi(argv[0]);
82
83 line = e1inp_line_find(e1_nr);
84 if (!line) {
85 vty_out(vty, "%% Line %d doesn't exist%s", e1_nr, VTY_NEWLINE);
86 return CMD_WARNING;
87 }
88
89 line->port_nr = atoi(argv[1]);
90
91 return CMD_SUCCESS;
92}
93
Alexander Couzensbeb10ef2016-11-01 22:05:13 +010094DEFUN(cfg_e1line_socket, cfg_e1_line_socket_cmd,
95 "e1_line <0-255> socket .SOCKET",
96 E1_LINE_HELP "Set socket path for unixsocket\n"
97 "socket path\n")
98{
99 struct e1inp_line *line;
100 int e1_nr = atoi(argv[0]);
101
102 line = e1inp_line_find(e1_nr);
103 if (!line) {
104 vty_out(vty, "%% Line %d doesn't exist%s", e1_nr, VTY_NEWLINE);
105 return CMD_WARNING;
106 }
107
108 line->sock_path = talloc_strdup(line, argv[1]);
109
110 return CMD_SUCCESS;
111}
112
Jacob Erlbeck86dae842014-01-16 18:10:37 +0100113#define KEEPALIVE_HELP "Enable keep-alive probing\n"
114static int set_keepalive_params(struct vty *vty, int e1_nr,
115 int idle, int num_probes, int probe_interval)
116{
117 struct e1inp_line *line = e1inp_line_find(e1_nr);
118
119 if (!line) {
120 vty_out(vty, "%% Line %d doesn't exist%s", e1_nr, VTY_NEWLINE);
121 return CMD_WARNING;
122 }
123 if (!line->driver->has_keepalive && num_probes != 0) {
124 vty_out(vty, "%% Driver '%s' does not support keep alive%s",
125 line->driver->name, VTY_NEWLINE);
126 return CMD_WARNING;
127 }
128
129 line->keepalive_idle_timeout = idle;
130 line->keepalive_num_probes = num_probes;
131 line->keepalive_probe_interval = probe_interval;
132
133 return CMD_SUCCESS;
134}
135
136DEFUN(cfg_e1line_keepalive, cfg_e1_line_keepalive_cmd,
137 "e1_line <0-255> keepalive",
138 E1_LINE_HELP KEEPALIVE_HELP)
139{
140 return set_keepalive_params(vty, atoi(argv[0]),
141 E1INP_USE_DEFAULT, E1INP_USE_DEFAULT,
142 E1INP_USE_DEFAULT);
143}
144
145DEFUN(cfg_e1line_keepalive_params, cfg_e1_line_keepalive_params_cmd,
146 "e1_line <0-255> keepalive <1-300> <1-20> <1-300>",
147 E1_LINE_HELP KEEPALIVE_HELP
148 "Idle interval in seconds before probes are sent\n"
149 "Number of probes to sent\n"
150 "Delay between probe packets in seconds\n")
151{
152 return set_keepalive_params(vty, atoi(argv[0]),
153 atoi(argv[1]), atoi(argv[2]), atoi(argv[3]));
154}
155
156DEFUN(cfg_e1line_no_keepalive, cfg_e1_line_no_keepalive_cmd,
157 "no e1_line <0-255> keepalive",
158 NO_STR E1_LINE_HELP KEEPALIVE_HELP)
159{
160 return set_keepalive_params(vty, atoi(argv[0]), 0, 0, 0);
161}
162
Harald Welte601a9c72011-08-16 14:17:49 +0200163DEFUN(cfg_e1line_name, cfg_e1_line_name_cmd,
164 "e1_line <0-255> name .LINE",
165 E1_LINE_HELP "Set name for this line\n" "Human readable name\n")
166{
167 struct e1inp_line *line;
168 int e1_nr = atoi(argv[0]);
169
170 line = e1inp_line_find(e1_nr);
171 if (!line) {
172 vty_out(vty, "%% Line %d doesn't exist%s", e1_nr, VTY_NEWLINE);
173 return CMD_WARNING;
174 }
175 if (line->name) {
176 talloc_free((void *)line->name);
177 line->name = NULL;
178 }
179 line->name = talloc_strdup(line, argv[1]);
180
181 return CMD_SUCCESS;
182}
183
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200184DEFUN(cfg_e1inp, cfg_e1inp_cmd,
185 "e1_input",
186 "Configure E1/T1/J1 TDM input\n")
187{
Harald Weltecc2241b2011-07-19 16:06:06 +0200188 vty->node = L_E1INP_NODE;
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200189
190 return CMD_SUCCESS;
191}
192
Neels Hofmeyr0db1d432016-02-22 13:29:09 +0100193DEFUN(cfg_ipa_bind,
194 cfg_ipa_bind_cmd,
195 "ipa bind A.B.C.D",
196 "ipa driver config\n"
197 "Set ipa local bind address\n"
198 "Listen on this IP address (default 0.0.0.0)\n")
199{
200 e1inp_ipa_set_bind_addr(argv[0]);
201 return CMD_SUCCESS;
202}
203
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200204static int e1inp_config_write(struct vty *vty)
205{
206 struct e1inp_line *line;
207
208 if (llist_empty(&e1inp_line_list))
209 return CMD_SUCCESS;
210
211 vty_out(vty, "e1_input%s", VTY_NEWLINE);
212
213 llist_for_each_entry(line, &e1inp_line_list, list) {
214 vty_out(vty, " e1_line %u driver %s%s", line->num,
215 line->driver->name, VTY_NEWLINE);
Harald Weltec2889512011-09-13 23:49:04 +0100216 vty_out(vty, " e1_line %u port %u%s", line->num,
217 line->port_nr, VTY_NEWLINE);
Harald Welte601a9c72011-08-16 14:17:49 +0200218 if (line->name)
219 vty_out(vty, " e1_line %u name %s%s", line->num,
220 line->name, VTY_NEWLINE);
Jacob Erlbeck86dae842014-01-16 18:10:37 +0100221 if (!line->keepalive_num_probes)
222 vty_out(vty, " no e1_line %u keepalive%s", line->num,
223 VTY_NEWLINE);
224 else if (line->keepalive_idle_timeout == E1INP_USE_DEFAULT &&
225 line->keepalive_num_probes == E1INP_USE_DEFAULT &&
226 line->keepalive_probe_interval == E1INP_USE_DEFAULT)
227 vty_out(vty, " e1_line %u keepalive%s", line->num,
228 VTY_NEWLINE);
229 else
230 vty_out(vty, " e1_line %u keepalive %d %d %d%s",
231 line->num,
232 line->keepalive_idle_timeout,
233 line->keepalive_num_probes,
234 line->keepalive_probe_interval,
235 VTY_NEWLINE);
236
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200237 }
Neels Hofmeyr0db1d432016-02-22 13:29:09 +0100238
239 const char *ipa_bind = e1inp_ipa_get_bind_addr();
240 if (ipa_bind && (strcmp(ipa_bind, "0.0.0.0") != 0))
241 vty_out(vty, " ipa bind %s%s",
242 ipa_bind, VTY_NEWLINE);
243
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200244 return CMD_SUCCESS;
245}
246
Harald Weltef2737fc2011-08-16 14:30:10 +0200247/* SHOW */
248
Harald Welte6e37c592011-08-11 12:43:31 +0200249static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv)
250{
251 vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE);
252}
253
254DEFUN(show_e1drv,
255 show_e1drv_cmd,
256 "show e1_driver",
257 SHOW_STR "Display information about available E1 drivers\n")
258{
259 struct e1inp_driver *drv;
260
261 llist_for_each_entry(drv, &e1inp_driver_list, list)
262 e1drv_dump_vty(vty, drv);
263
264 return CMD_SUCCESS;
265}
266
Harald Weltef2737fc2011-08-16 14:30:10 +0200267static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line,
268 int stats)
Harald Welte6e37c592011-08-11 12:43:31 +0200269{
270 vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s",
271 line->num, line->name ? line->name : "",
272 line->driver->name, VTY_NEWLINE);
Harald Weltefe05cf52011-09-26 23:18:41 +0200273 if (line->driver->vty_show)
274 line->driver->vty_show(vty, line);
Harald Weltef2737fc2011-08-16 14:30:10 +0200275 if (stats)
276 vty_out_rate_ctr_group(vty, " ", line->rate_ctr);
Harald Welte6e37c592011-08-11 12:43:31 +0200277}
278
279DEFUN(show_e1line,
280 show_e1line_cmd,
Harald Weltef2737fc2011-08-16 14:30:10 +0200281 "show e1_line [line_nr] [stats]",
Harald Welte6e37c592011-08-11 12:43:31 +0200282 SHOW_STR "Display information about a E1 line\n"
Holger Hans Peter Freyther9e8f1c02012-07-21 00:09:52 +0200283 "E1 Line Number\n" "Include statistics\n")
Harald Welte6e37c592011-08-11 12:43:31 +0200284{
285 struct e1inp_line *line;
Harald Weltef2737fc2011-08-16 14:30:10 +0200286 int stats = 0;
Harald Welte6e37c592011-08-11 12:43:31 +0200287
Harald Weltef2737fc2011-08-16 14:30:10 +0200288 if (argc >= 1 && strcmp(argv[0], "stats")) {
Harald Welte6e37c592011-08-11 12:43:31 +0200289 int num = atoi(argv[0]);
Harald Weltef2737fc2011-08-16 14:30:10 +0200290 if (argc >= 2)
291 stats = 1;
Harald Welte6e37c592011-08-11 12:43:31 +0200292 llist_for_each_entry(line, &e1inp_line_list, list) {
293 if (line->num == num) {
Harald Weltef2737fc2011-08-16 14:30:10 +0200294 e1line_dump_vty(vty, line, stats);
Harald Welte6e37c592011-08-11 12:43:31 +0200295 return CMD_SUCCESS;
296 }
297 }
298 return CMD_WARNING;
299 }
300
Harald Weltef2737fc2011-08-16 14:30:10 +0200301 if (argc >= 1 && !strcmp(argv[0], "stats"))
302 stats = 1;
303
Harald Welte6e37c592011-08-11 12:43:31 +0200304 llist_for_each_entry(line, &e1inp_line_list, list)
Harald Weltef2737fc2011-08-16 14:30:10 +0200305 e1line_dump_vty(vty, line, stats);
Harald Welte6e37c592011-08-11 12:43:31 +0200306
307 return CMD_SUCCESS;
308}
309
310static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts)
311{
312 if (ts->type == E1INP_TS_TYPE_NONE)
313 return;
314 vty_out(vty, "E1 Timeslot %2u of Line %u is Type %s%s",
315 ts->num, ts->line->num, e1inp_tstype_name(ts->type),
316 VTY_NEWLINE);
317}
318
319DEFUN(show_e1ts,
320 show_e1ts_cmd,
321 "show e1_timeslot [line_nr] [ts_nr]",
322 SHOW_STR "Display information about a E1 timeslot\n"
323 "E1 Line Number\n" "E1 Timeslot Number\n")
324{
325 struct e1inp_line *line = NULL;
326 struct e1inp_ts *ts;
327 int ts_nr;
328
Holger Hans Peter Freyther8cbd9f42013-07-04 20:00:33 +0200329 if (argc <= 0) {
Harald Welte6e37c592011-08-11 12:43:31 +0200330 llist_for_each_entry(line, &e1inp_line_list, list) {
Harald Weltec2889512011-09-13 23:49:04 +0100331 for (ts_nr = 0; ts_nr < line->num_ts; ts_nr++) {
Harald Welte6e37c592011-08-11 12:43:31 +0200332 ts = &line->ts[ts_nr];
333 e1ts_dump_vty(vty, ts);
334 }
335 }
336 return CMD_SUCCESS;
337 }
338 if (argc >= 1) {
339 int num = atoi(argv[0]);
340 struct e1inp_line *l;
341 llist_for_each_entry(l, &e1inp_line_list, list) {
342 if (l->num == num) {
343 line = l;
344 break;
345 }
346 }
347 if (!line) {
348 vty_out(vty, "E1 line %s is invalid%s",
349 argv[0], VTY_NEWLINE);
350 return CMD_WARNING;
351 }
352 }
353 if (argc >= 2) {
354 ts_nr = atoi(argv[1]);
Harald Weltec2889512011-09-13 23:49:04 +0100355 if (ts_nr >= line->num_ts) {
Harald Welte6e37c592011-08-11 12:43:31 +0200356 vty_out(vty, "E1 timeslot %s is invalid%s",
357 argv[1], VTY_NEWLINE);
358 return CMD_WARNING;
359 }
360 ts = &line->ts[ts_nr];
361 e1ts_dump_vty(vty, ts);
362 return CMD_SUCCESS;
363 } else {
Harald Weltec2889512011-09-13 23:49:04 +0100364 for (ts_nr = 0; ts_nr < line->num_ts; ts_nr++) {
Harald Welte6e37c592011-08-11 12:43:31 +0200365 ts = &line->ts[ts_nr];
366 e1ts_dump_vty(vty, ts);
367 }
368 return CMD_SUCCESS;
369 }
370 return CMD_SUCCESS;
371}
372
373
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200374struct cmd_node e1inp_node = {
Harald Weltecc2241b2011-07-19 16:06:06 +0200375 L_E1INP_NODE,
Jacob Erlbeck1c9dcc12013-11-11 14:13:13 +0100376 "%s(config-e1_input)# ",
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200377 1,
378};
379
380int e1inp_vty_init(void)
381{
382 install_element(CONFIG_NODE, &cfg_e1inp_cmd);
383 install_node(&e1inp_node, e1inp_config_write);
Jacob Erlbeck37f06952013-11-11 14:13:12 +0100384
Harald Weltecc2241b2011-07-19 16:06:06 +0200385 install_element(L_E1INP_NODE, &cfg_e1_line_driver_cmd);
Harald Weltec2889512011-09-13 23:49:04 +0100386 install_element(L_E1INP_NODE, &cfg_e1_line_port_cmd);
Alexander Couzensbeb10ef2016-11-01 22:05:13 +0100387 install_element(L_E1INP_NODE, &cfg_e1_line_socket_cmd);
Harald Welte601a9c72011-08-16 14:17:49 +0200388 install_element(L_E1INP_NODE, &cfg_e1_line_name_cmd);
Jacob Erlbeck86dae842014-01-16 18:10:37 +0100389 install_element(L_E1INP_NODE, &cfg_e1_line_keepalive_cmd);
390 install_element(L_E1INP_NODE, &cfg_e1_line_keepalive_params_cmd);
391 install_element(L_E1INP_NODE, &cfg_e1_line_no_keepalive_cmd);
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200392
Neels Hofmeyr0db1d432016-02-22 13:29:09 +0100393 install_element(L_E1INP_NODE, &cfg_ipa_bind_cmd);
394
Harald Welte6e37c592011-08-11 12:43:31 +0200395 install_element_ve(&show_e1drv_cmd);
396 install_element_ve(&show_e1line_cmd);
397 install_element_ve(&show_e1ts_cmd);
398
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200399 return 0;
400}