blob: 8d89d048f922d80aede8e66cfddb5ee06676a91c [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>
Stefan Sperlingb24efa52018-08-28 14:03:41 +020026#include <sys/un.h>
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020027
Harald Weltef2737fc2011-08-16 14:30:10 +020028#include <osmocom/core/linuxlist.h>
29#include <osmocom/core/talloc.h>
30#include <osmocom/core/utils.h>
31#include <osmocom/gsm/gsm_utils.h>
32
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020033#include <osmocom/vty/command.h>
34#include <osmocom/vty/buffer.h>
35#include <osmocom/vty/vty.h>
36#include <osmocom/vty/logging.h>
Harald Weltef2737fc2011-08-16 14:30:10 +020037#include <osmocom/vty/misc.h>
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020038#include <osmocom/vty/telnet_interface.h>
39
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020040#include <osmocom/abis/e1_input.h>
Eric Wildef1f3272019-07-10 18:10:31 +020041#include <osmocom/abis/ipa.h>
Harald Weltef2737fc2011-08-16 14:30:10 +020042
43/* CONFIG */
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020044
Sylvain Munautb559a532019-05-09 11:14:26 +020045#define E1_DRIVER_NAMES "(misdn|misdn_lapd|dahdi|e1d|ipa|unixsocket)"
Harald Weltece307b42011-08-21 01:18:05 +020046#define E1_DRIVER_HELP "mISDN supported E1 Card (kernel LAPD)\n" \
47 "mISDN supported E1 Card (userspace LAPD)\n" \
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020048 "DAHDI supported E1/T1/J1 Card\n" \
Holger Hans Peter Freyther36bac9a2012-07-20 23:49:52 +020049 "IPA TCP/IP input\n" \
Alexander Couzensbeb10ef2016-11-01 22:05:13 +010050 "HSL TCP/IP input\n" \
51 "Unix socket input\n"
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020052
Harald Welte601a9c72011-08-16 14:17:49 +020053#define E1_LINE_HELP "Configure E1/T1/J1 Line\n" "Line Number\n"
54
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020055DEFUN(cfg_e1line_driver, cfg_e1_line_driver_cmd,
56 "e1_line <0-255> driver " E1_DRIVER_NAMES,
Harald Welte601a9c72011-08-16 14:17:49 +020057 E1_LINE_HELP "Set driver for this line\n"
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020058 E1_DRIVER_HELP)
59{
60 struct e1inp_line *line;
61 int e1_nr = atoi(argv[0]);
62
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +020063 line = e1inp_line_find(e1_nr);
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020064 if (line) {
65 vty_out(vty, "%% Line %d already exists%s", e1_nr, VTY_NEWLINE);
66 return CMD_WARNING;
67 }
68 line = e1inp_line_create(e1_nr, argv[1]);
69 if (!line) {
70 vty_out(vty, "%% Error creating line %d%s", e1_nr, VTY_NEWLINE);
71 return CMD_WARNING;
72 }
73
74 return CMD_SUCCESS;
75}
76
Harald Weltec2889512011-09-13 23:49:04 +010077DEFUN(cfg_e1line_port, cfg_e1_line_port_cmd,
Harald Welte356918f2011-09-26 22:54:51 +020078 "e1_line <0-255> port <0-255>",
79 E1_LINE_HELP "Set physical port/span/card number\n"
Harald Weltec2889512011-09-13 23:49:04 +010080 "E1/T1 Port/Span/Card number\n")
81{
82 struct e1inp_line *line;
83 int e1_nr = atoi(argv[0]);
84
85 line = e1inp_line_find(e1_nr);
86 if (!line) {
87 vty_out(vty, "%% Line %d doesn't exist%s", e1_nr, VTY_NEWLINE);
88 return CMD_WARNING;
89 }
90
91 line->port_nr = atoi(argv[1]);
92
93 return CMD_SUCCESS;
94}
95
Alexander Couzensbeb10ef2016-11-01 22:05:13 +010096DEFUN(cfg_e1line_socket, cfg_e1_line_socket_cmd,
97 "e1_line <0-255> socket .SOCKET",
98 E1_LINE_HELP "Set socket path for unixsocket\n"
99 "socket path\n")
100{
101 struct e1inp_line *line;
102 int e1_nr = atoi(argv[0]);
Stefan Sperlingb24efa52018-08-28 14:03:41 +0200103 struct sockaddr_un sun;
104
Stefan Sperling0d7d0b02018-09-20 17:34:31 +0200105 /* Don't exceed the maximum unix socket path length, including a NUL byte. See the unix(7) man page.*/
106 if (strlen(argv[1]) > sizeof(sun.sun_path) - 1) {
Stefan Sperlingb24efa52018-08-28 14:03:41 +0200107 vty_out(vty, "%% Socket path length exceeds %zd bytes: '%s'%s",
Stefan Sperling0d7d0b02018-09-20 17:34:31 +0200108 sizeof(sun.sun_path) - 1, argv[1], VTY_NEWLINE);
Stefan Sperlingb24efa52018-08-28 14:03:41 +0200109 return CMD_WARNING;
110 }
Alexander Couzensbeb10ef2016-11-01 22:05:13 +0100111
112 line = e1inp_line_find(e1_nr);
113 if (!line) {
114 vty_out(vty, "%% Line %d doesn't exist%s", e1_nr, VTY_NEWLINE);
115 return CMD_WARNING;
116 }
117
118 line->sock_path = talloc_strdup(line, argv[1]);
119
120 return CMD_SUCCESS;
121}
122
Jacob Erlbeck86dae842014-01-16 18:10:37 +0100123#define KEEPALIVE_HELP "Enable keep-alive probing\n"
124static int set_keepalive_params(struct vty *vty, int e1_nr,
125 int idle, int num_probes, int probe_interval)
126{
127 struct e1inp_line *line = e1inp_line_find(e1_nr);
128
129 if (!line) {
130 vty_out(vty, "%% Line %d doesn't exist%s", e1_nr, VTY_NEWLINE);
131 return CMD_WARNING;
132 }
133 if (!line->driver->has_keepalive && num_probes != 0) {
134 vty_out(vty, "%% Driver '%s' does not support keep alive%s",
135 line->driver->name, VTY_NEWLINE);
136 return CMD_WARNING;
137 }
138
139 line->keepalive_idle_timeout = idle;
140 line->keepalive_num_probes = num_probes;
141 line->keepalive_probe_interval = probe_interval;
142
143 return CMD_SUCCESS;
144}
145
146DEFUN(cfg_e1line_keepalive, cfg_e1_line_keepalive_cmd,
147 "e1_line <0-255> keepalive",
148 E1_LINE_HELP KEEPALIVE_HELP)
149{
150 return set_keepalive_params(vty, atoi(argv[0]),
151 E1INP_USE_DEFAULT, E1INP_USE_DEFAULT,
152 E1INP_USE_DEFAULT);
153}
154
155DEFUN(cfg_e1line_keepalive_params, cfg_e1_line_keepalive_params_cmd,
156 "e1_line <0-255> keepalive <1-300> <1-20> <1-300>",
157 E1_LINE_HELP KEEPALIVE_HELP
158 "Idle interval in seconds before probes are sent\n"
159 "Number of probes to sent\n"
160 "Delay between probe packets in seconds\n")
161{
162 return set_keepalive_params(vty, atoi(argv[0]),
163 atoi(argv[1]), atoi(argv[2]), atoi(argv[3]));
164}
165
166DEFUN(cfg_e1line_no_keepalive, cfg_e1_line_no_keepalive_cmd,
167 "no e1_line <0-255> keepalive",
168 NO_STR E1_LINE_HELP KEEPALIVE_HELP)
169{
170 return set_keepalive_params(vty, atoi(argv[0]), 0, 0, 0);
171}
172
Eric Wildef1f3272019-07-10 18:10:31 +0200173#define IPA_KEEPALIVE_HELP "Enable IPA PING/PONG keep-alive\n"
174static int set_ipa_keepalive_params(struct vty *vty, int e1_nr, int interval, int wait_for_resp)
175{
176 struct e1inp_line *line = e1inp_line_find(e1_nr);
177
178 if (!line) {
179 vty_out(vty, "%% Line %d doesn't exist%s", e1_nr, VTY_NEWLINE);
180 return CMD_WARNING;
181 }
182
183 if (strcmp(line->driver->name, "ipa") != 0) {
184 vty_out(vty, "%% Line %d doesn't use the ipa driver%s", e1_nr, VTY_NEWLINE);
185 return CMD_WARNING;
186 }
187
188 TALLOC_FREE(line->ipa_kap);
189 if (interval) {
190 line->ipa_kap = talloc_zero(line, struct ipa_keepalive_params);
191 line->ipa_kap->wait_for_resp = wait_for_resp;
192 line->ipa_kap->interval = interval;
193 }
194
195 return CMD_SUCCESS;
196}
197
198DEFUN(cfg_e1line_ipa_keepalive, cfg_e1_line_ipa_keepalive_cmd,
199 "e1_line <0-255> ipa-keepalive <1-300> <1-300>",
200 E1_LINE_HELP IPA_KEEPALIVE_HELP
201 "Idle interval in seconds before probes are sent\n"
202 "Time to wait for PONG response\n")
203{
204 return set_ipa_keepalive_params(vty, atoi(argv[0]), atoi(argv[1]), atoi(argv[2]));
205}
206
207DEFUN(cfg_e1line_no_ipa_keepalive, cfg_e1_line_no_ipa_keepalive_cmd,
208 "no e1_line <0-255> ipa-keepalive",
209 NO_STR E1_LINE_HELP IPA_KEEPALIVE_HELP)
210{
211 return set_ipa_keepalive_params(vty, atoi(argv[0]), 0, 0);
212}
213
Harald Welte601a9c72011-08-16 14:17:49 +0200214DEFUN(cfg_e1line_name, cfg_e1_line_name_cmd,
215 "e1_line <0-255> name .LINE",
216 E1_LINE_HELP "Set name for this line\n" "Human readable name\n")
217{
218 struct e1inp_line *line;
219 int e1_nr = atoi(argv[0]);
220
221 line = e1inp_line_find(e1_nr);
222 if (!line) {
223 vty_out(vty, "%% Line %d doesn't exist%s", e1_nr, VTY_NEWLINE);
224 return CMD_WARNING;
225 }
226 if (line->name) {
227 talloc_free((void *)line->name);
228 line->name = NULL;
229 }
230 line->name = talloc_strdup(line, argv[1]);
231
232 return CMD_SUCCESS;
233}
234
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200235DEFUN(cfg_e1inp, cfg_e1inp_cmd,
236 "e1_input",
237 "Configure E1/T1/J1 TDM input\n")
238{
Harald Weltecc2241b2011-07-19 16:06:06 +0200239 vty->node = L_E1INP_NODE;
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200240
241 return CMD_SUCCESS;
242}
243
Neels Hofmeyr0db1d432016-02-22 13:29:09 +0100244DEFUN(cfg_ipa_bind,
245 cfg_ipa_bind_cmd,
246 "ipa bind A.B.C.D",
247 "ipa driver config\n"
248 "Set ipa local bind address\n"
249 "Listen on this IP address (default 0.0.0.0)\n")
250{
251 e1inp_ipa_set_bind_addr(argv[0]);
252 return CMD_SUCCESS;
253}
254
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200255static int e1inp_config_write(struct vty *vty)
256{
257 struct e1inp_line *line;
258
259 if (llist_empty(&e1inp_line_list))
260 return CMD_SUCCESS;
261
262 vty_out(vty, "e1_input%s", VTY_NEWLINE);
263
264 llist_for_each_entry(line, &e1inp_line_list, list) {
265 vty_out(vty, " e1_line %u driver %s%s", line->num,
266 line->driver->name, VTY_NEWLINE);
Harald Weltec2889512011-09-13 23:49:04 +0100267 vty_out(vty, " e1_line %u port %u%s", line->num,
268 line->port_nr, VTY_NEWLINE);
Harald Welte601a9c72011-08-16 14:17:49 +0200269 if (line->name)
270 vty_out(vty, " e1_line %u name %s%s", line->num,
271 line->name, VTY_NEWLINE);
Jacob Erlbeck86dae842014-01-16 18:10:37 +0100272 if (!line->keepalive_num_probes)
273 vty_out(vty, " no e1_line %u keepalive%s", line->num,
274 VTY_NEWLINE);
275 else if (line->keepalive_idle_timeout == E1INP_USE_DEFAULT &&
276 line->keepalive_num_probes == E1INP_USE_DEFAULT &&
277 line->keepalive_probe_interval == E1INP_USE_DEFAULT)
278 vty_out(vty, " e1_line %u keepalive%s", line->num,
279 VTY_NEWLINE);
280 else
281 vty_out(vty, " e1_line %u keepalive %d %d %d%s",
282 line->num,
283 line->keepalive_idle_timeout,
284 line->keepalive_num_probes,
285 line->keepalive_probe_interval,
286 VTY_NEWLINE);
Eric Wildef1f3272019-07-10 18:10:31 +0200287 if (line->ipa_kap)
288 vty_out(vty, " e1_line %u ipa-keepalive %d %d%s", line->num,
289 line->ipa_kap->interval, line->ipa_kap->wait_for_resp,
290 VTY_NEWLINE);
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200291 }
Neels Hofmeyr0db1d432016-02-22 13:29:09 +0100292
293 const char *ipa_bind = e1inp_ipa_get_bind_addr();
294 if (ipa_bind && (strcmp(ipa_bind, "0.0.0.0") != 0))
295 vty_out(vty, " ipa bind %s%s",
296 ipa_bind, VTY_NEWLINE);
297
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200298 return CMD_SUCCESS;
299}
300
Harald Weltef2737fc2011-08-16 14:30:10 +0200301/* SHOW */
302
Harald Welte6e37c592011-08-11 12:43:31 +0200303static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv)
304{
305 vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE);
306}
307
308DEFUN(show_e1drv,
309 show_e1drv_cmd,
310 "show e1_driver",
311 SHOW_STR "Display information about available E1 drivers\n")
312{
313 struct e1inp_driver *drv;
314
315 llist_for_each_entry(drv, &e1inp_driver_list, list)
316 e1drv_dump_vty(vty, drv);
317
318 return CMD_SUCCESS;
319}
320
Harald Weltef2737fc2011-08-16 14:30:10 +0200321static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line,
322 int stats)
Harald Welte6e37c592011-08-11 12:43:31 +0200323{
324 vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s",
325 line->num, line->name ? line->name : "",
326 line->driver->name, VTY_NEWLINE);
Harald Weltefe05cf52011-09-26 23:18:41 +0200327 if (line->driver->vty_show)
328 line->driver->vty_show(vty, line);
Harald Weltef2737fc2011-08-16 14:30:10 +0200329 if (stats)
330 vty_out_rate_ctr_group(vty, " ", line->rate_ctr);
Harald Welte6e37c592011-08-11 12:43:31 +0200331}
332
333DEFUN(show_e1line,
334 show_e1line_cmd,
Harald Weltef2737fc2011-08-16 14:30:10 +0200335 "show e1_line [line_nr] [stats]",
Harald Welte6e37c592011-08-11 12:43:31 +0200336 SHOW_STR "Display information about a E1 line\n"
Holger Hans Peter Freyther9e8f1c02012-07-21 00:09:52 +0200337 "E1 Line Number\n" "Include statistics\n")
Harald Welte6e37c592011-08-11 12:43:31 +0200338{
339 struct e1inp_line *line;
Harald Weltef2737fc2011-08-16 14:30:10 +0200340 int stats = 0;
Harald Welte6e37c592011-08-11 12:43:31 +0200341
Harald Weltef2737fc2011-08-16 14:30:10 +0200342 if (argc >= 1 && strcmp(argv[0], "stats")) {
Harald Welte6e37c592011-08-11 12:43:31 +0200343 int num = atoi(argv[0]);
Harald Weltef2737fc2011-08-16 14:30:10 +0200344 if (argc >= 2)
345 stats = 1;
Harald Welte6e37c592011-08-11 12:43:31 +0200346 llist_for_each_entry(line, &e1inp_line_list, list) {
347 if (line->num == num) {
Harald Weltef2737fc2011-08-16 14:30:10 +0200348 e1line_dump_vty(vty, line, stats);
Harald Welte6e37c592011-08-11 12:43:31 +0200349 return CMD_SUCCESS;
350 }
351 }
352 return CMD_WARNING;
353 }
354
Harald Weltef2737fc2011-08-16 14:30:10 +0200355 if (argc >= 1 && !strcmp(argv[0], "stats"))
356 stats = 1;
357
Harald Welte6e37c592011-08-11 12:43:31 +0200358 llist_for_each_entry(line, &e1inp_line_list, list)
Harald Weltef2737fc2011-08-16 14:30:10 +0200359 e1line_dump_vty(vty, line, stats);
Harald Welte6e37c592011-08-11 12:43:31 +0200360
361 return CMD_SUCCESS;
362}
363
364static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts)
365{
366 if (ts->type == E1INP_TS_TYPE_NONE)
367 return;
368 vty_out(vty, "E1 Timeslot %2u of Line %u is Type %s%s",
369 ts->num, ts->line->num, e1inp_tstype_name(ts->type),
370 VTY_NEWLINE);
371}
372
373DEFUN(show_e1ts,
374 show_e1ts_cmd,
375 "show e1_timeslot [line_nr] [ts_nr]",
376 SHOW_STR "Display information about a E1 timeslot\n"
377 "E1 Line Number\n" "E1 Timeslot Number\n")
378{
379 struct e1inp_line *line = NULL;
380 struct e1inp_ts *ts;
381 int ts_nr;
382
Holger Hans Peter Freyther8cbd9f42013-07-04 20:00:33 +0200383 if (argc <= 0) {
Harald Welte6e37c592011-08-11 12:43:31 +0200384 llist_for_each_entry(line, &e1inp_line_list, list) {
Harald Weltec2889512011-09-13 23:49:04 +0100385 for (ts_nr = 0; ts_nr < line->num_ts; ts_nr++) {
Harald Welte6e37c592011-08-11 12:43:31 +0200386 ts = &line->ts[ts_nr];
387 e1ts_dump_vty(vty, ts);
388 }
389 }
390 return CMD_SUCCESS;
391 }
392 if (argc >= 1) {
393 int num = atoi(argv[0]);
394 struct e1inp_line *l;
395 llist_for_each_entry(l, &e1inp_line_list, list) {
396 if (l->num == num) {
397 line = l;
398 break;
399 }
400 }
401 if (!line) {
402 vty_out(vty, "E1 line %s is invalid%s",
403 argv[0], VTY_NEWLINE);
404 return CMD_WARNING;
405 }
406 }
407 if (argc >= 2) {
408 ts_nr = atoi(argv[1]);
Harald Weltec2889512011-09-13 23:49:04 +0100409 if (ts_nr >= line->num_ts) {
Harald Welte6e37c592011-08-11 12:43:31 +0200410 vty_out(vty, "E1 timeslot %s is invalid%s",
411 argv[1], VTY_NEWLINE);
412 return CMD_WARNING;
413 }
414 ts = &line->ts[ts_nr];
415 e1ts_dump_vty(vty, ts);
416 return CMD_SUCCESS;
417 } else {
Harald Weltec2889512011-09-13 23:49:04 +0100418 for (ts_nr = 0; ts_nr < line->num_ts; ts_nr++) {
Harald Welte6e37c592011-08-11 12:43:31 +0200419 ts = &line->ts[ts_nr];
420 e1ts_dump_vty(vty, ts);
421 }
422 return CMD_SUCCESS;
423 }
424 return CMD_SUCCESS;
425}
426
427
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200428struct cmd_node e1inp_node = {
Harald Weltecc2241b2011-07-19 16:06:06 +0200429 L_E1INP_NODE,
Jacob Erlbeck1c9dcc12013-11-11 14:13:13 +0100430 "%s(config-e1_input)# ",
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200431 1,
432};
433
434int e1inp_vty_init(void)
435{
436 install_element(CONFIG_NODE, &cfg_e1inp_cmd);
437 install_node(&e1inp_node, e1inp_config_write);
Jacob Erlbeck37f06952013-11-11 14:13:12 +0100438
Harald Weltecc2241b2011-07-19 16:06:06 +0200439 install_element(L_E1INP_NODE, &cfg_e1_line_driver_cmd);
Harald Weltec2889512011-09-13 23:49:04 +0100440 install_element(L_E1INP_NODE, &cfg_e1_line_port_cmd);
Alexander Couzensbeb10ef2016-11-01 22:05:13 +0100441 install_element(L_E1INP_NODE, &cfg_e1_line_socket_cmd);
Harald Welte601a9c72011-08-16 14:17:49 +0200442 install_element(L_E1INP_NODE, &cfg_e1_line_name_cmd);
Jacob Erlbeck86dae842014-01-16 18:10:37 +0100443 install_element(L_E1INP_NODE, &cfg_e1_line_keepalive_cmd);
444 install_element(L_E1INP_NODE, &cfg_e1_line_keepalive_params_cmd);
445 install_element(L_E1INP_NODE, &cfg_e1_line_no_keepalive_cmd);
Eric Wildef1f3272019-07-10 18:10:31 +0200446 install_element(L_E1INP_NODE, &cfg_e1_line_ipa_keepalive_cmd);
447 install_element(L_E1INP_NODE, &cfg_e1_line_no_ipa_keepalive_cmd);
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200448
Neels Hofmeyr0db1d432016-02-22 13:29:09 +0100449 install_element(L_E1INP_NODE, &cfg_ipa_bind_cmd);
450
Harald Welte6e37c592011-08-11 12:43:31 +0200451 install_element_ve(&show_e1drv_cmd);
452 install_element_ve(&show_e1line_cmd);
453 install_element_ve(&show_e1ts_cmd);
454
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200455 return 0;
456}