blob: 41202b06f0da3fc08f8bbcf9498f8e5dddc08f10 [file] [log] [blame]
Harald Welte3016d9f2011-02-05 13:54:41 +01001/* OpenBSC 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
20#include <stdlib.h>
21#include <unistd.h>
Harald Welte3016d9f2011-02-05 13:54:41 +010022
23#include <osmocom/vty/command.h>
24#include <osmocom/vty/buffer.h>
25#include <osmocom/vty/vty.h>
26#include <osmocom/vty/logging.h>
27#include <osmocom/vty/telnet_interface.h>
28
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010029#include <osmocom/core/linuxlist.h>
Harald Welte3016d9f2011-02-05 13:54:41 +010030#include <openbsc/gsm_data.h>
31#include <openbsc/e1_input.h>
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010032#include <osmocom/core/utils.h>
33#include <osmocom/gsm/gsm_utils.h>
34#include <osmocom/core/talloc.h>
Harald Welte3016d9f2011-02-05 13:54:41 +010035#include <openbsc/vty.h>
36#include <openbsc/debug.h>
37
Harald Weltec08e8be2011-03-04 13:53:51 +010038#include "../../bscconfig.h"
Harald Welte3016d9f2011-02-05 13:54:41 +010039
Harald Welte1dd68c32011-02-05 13:58:46 +010040#define E1_DRIVER_NAMES "(misdn|dahdi)"
41#define E1_DRIVER_HELP "mISDN supported E1 Card\n" \
42 "DAHDI supported E1/T1/J1 Card\n"
Harald Welte3016d9f2011-02-05 13:54:41 +010043
Harald Welte4da55922011-08-11 12:40:07 +020044#define E1_LINE_HELP "Configure E1/T1/J1 Line\n" "Line Number\n"
45
Harald Welte3016d9f2011-02-05 13:54:41 +010046DEFUN(cfg_e1line_driver, cfg_e1_line_driver_cmd,
47 "e1_line <0-255> driver " E1_DRIVER_NAMES,
Harald Welte4da55922011-08-11 12:40:07 +020048 E1_LINE_HELP "Set driver for this line\n"
Harald Welte3016d9f2011-02-05 13:54:41 +010049 E1_DRIVER_HELP)
50{
51 struct e1inp_line *line;
52 int e1_nr = atoi(argv[0]);
53
54 line = e1inp_line_get(e1_nr);
55 if (line) {
56 vty_out(vty, "%% Line %d already exists%s", e1_nr, VTY_NEWLINE);
57 return CMD_WARNING;
58 }
59 line = e1inp_line_create(e1_nr, argv[1]);
60 if (!line) {
61 vty_out(vty, "%% Error creating line %d%s", e1_nr, VTY_NEWLINE);
62 return CMD_WARNING;
63 }
64
65 return CMD_SUCCESS;
66}
67
Harald Welte4da55922011-08-11 12:40:07 +020068DEFUN(cfg_e1line_name, cfg_e1_line_name_cmd,
69 "e1_line <0-255> name .LINE",
70 E1_LINE_HELP "Set name for this line\n" "Human readable name\n")
71{
72 struct e1inp_line *line;
73 int e1_nr = atoi(argv[0]);
74
75 line = e1inp_line_get(e1_nr);
76 if (!line) {
77 vty_out(vty, "%% Line %d doesn't exist%s", e1_nr, VTY_NEWLINE);
78 return CMD_WARNING;
79 }
80 if (line->name) {
81 talloc_free((void *)line->name);
82 line->name = NULL;
83 }
84 line->name = talloc_strdup(line, argv[1]);
85
86 return CMD_SUCCESS;
87}
88
Harald Welte3016d9f2011-02-05 13:54:41 +010089DEFUN(cfg_e1inp, cfg_e1inp_cmd,
90 "e1_input",
91 "Configure E1/T1/J1 TDM input\n")
92{
93 vty->node = E1INP_NODE;
94
95 return CMD_SUCCESS;
96}
97
98static int e1inp_config_write(struct vty *vty)
99{
100 struct e1inp_line *line;
101
Pablo Neira Ayusod2a78782011-05-14 11:32:45 +0200102 if (llist_empty(&e1inp_line_list))
103 return CMD_SUCCESS;
104
Harald Welte07bb0da2011-02-05 15:57:42 +0100105 vty_out(vty, "e1_input%s", VTY_NEWLINE);
106
Harald Welte3016d9f2011-02-05 13:54:41 +0100107 llist_for_each_entry(line, &e1inp_line_list, list) {
108 vty_out(vty, " e1_line %u driver %s%s", line->num,
109 line->driver->name, VTY_NEWLINE);
Harald Welte4da55922011-08-11 12:40:07 +0200110 if (line->name)
111 vty_out(vty, " e1_line %u name %s%s", line->num,
112 line->name, VTY_NEWLINE);
Harald Welte3016d9f2011-02-05 13:54:41 +0100113 }
114 return CMD_SUCCESS;
115}
116
117struct cmd_node e1inp_node = {
118 E1INP_NODE,
119 "%s(e1_input)#",
120 1,
121};
122
123int e1inp_vty_init(void)
124{
125 install_element(CONFIG_NODE, &cfg_e1inp_cmd);
126 install_node(&e1inp_node, e1inp_config_write);
127 install_element(E1INP_NODE, &cfg_e1_line_driver_cmd);
Harald Welte4da55922011-08-11 12:40:07 +0200128 install_element(E1INP_NODE, &cfg_e1_line_name_cmd);
Harald Welte3016d9f2011-02-05 13:54:41 +0100129
130 return 0;
131}