blob: 6055038f39395fdb7e3cd57d675052ee0029ece2 [file] [log] [blame]
Harald Weltee76bea02011-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 Weltee76bea02011-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 Ayusodd5fff42011-03-22 16:47:59 +010029#include <osmocom/core/linuxlist.h>
Harald Weltee76bea02011-02-05 13:54:41 +010030#include <openbsc/gsm_data.h>
31#include <openbsc/e1_input.h>
Pablo Neira Ayusodd5fff42011-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 Weltee76bea02011-02-05 13:54:41 +010035#include <openbsc/vty.h>
36#include <openbsc/debug.h>
37
Harald Welted9dea592011-03-04 13:53:51 +010038#include "../../bscconfig.h"
Harald Weltee76bea02011-02-05 13:54:41 +010039
Harald Welte890fe4a2011-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 Weltee76bea02011-02-05 13:54:41 +010043
Harald Welte7b612652011-08-11 12:40:07 +020044#define E1_LINE_HELP "Configure E1/T1/J1 Line\n" "Line Number\n"
45
Harald Weltee76bea02011-02-05 13:54:41 +010046DEFUN(cfg_e1line_driver, cfg_e1_line_driver_cmd,
47 "e1_line <0-255> driver " E1_DRIVER_NAMES,
Harald Welte7b612652011-08-11 12:40:07 +020048 E1_LINE_HELP "Set driver for this line\n"
Harald Weltee76bea02011-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 Welte7b612652011-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 Weltee76bea02011-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 Ayusoeaca15c2011-05-14 11:32:45 +0200102 if (llist_empty(&e1inp_line_list))
103 return CMD_SUCCESS;
104
Harald Weltecc5e9f82011-02-05 15:57:42 +0100105 vty_out(vty, "e1_input%s", VTY_NEWLINE);
106
Harald Weltee76bea02011-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 Welte7b612652011-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 Weltee76bea02011-02-05 13:54:41 +0100113 }
114 return CMD_SUCCESS;
115}
116
Harald Welte008be6a2011-08-11 12:43:31 +0200117static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv)
118{
119 vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE);
120}
121
122DEFUN(show_e1drv,
123 show_e1drv_cmd,
124 "show e1_driver",
125 SHOW_STR "Display information about available E1 drivers\n")
126{
127 struct e1inp_driver *drv;
128
129 llist_for_each_entry(drv, &e1inp_driver_list, list)
130 e1drv_dump_vty(vty, drv);
131
132 return CMD_SUCCESS;
133}
134
135static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line)
136{
137 vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s",
138 line->num, line->name ? line->name : "",
139 line->driver->name, VTY_NEWLINE);
140}
141
142DEFUN(show_e1line,
143 show_e1line_cmd,
144 "show e1_line [line_nr]",
145 SHOW_STR "Display information about a E1 line\n"
146 "E1 Line Number\n")
147{
148 struct e1inp_line *line;
149
150 if (argc >= 1) {
151 int num = atoi(argv[0]);
152 llist_for_each_entry(line, &e1inp_line_list, list) {
153 if (line->num == num) {
154 e1line_dump_vty(vty, line);
155 return CMD_SUCCESS;
156 }
157 }
158 return CMD_WARNING;
159 }
160
161 llist_for_each_entry(line, &e1inp_line_list, list)
162 e1line_dump_vty(vty, line);
163
164 return CMD_SUCCESS;
165}
166
167static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts)
168{
169 if (ts->type == E1INP_TS_TYPE_NONE)
170 return;
171 vty_out(vty, "E1 Timeslot %2u of Line %u is Type %s%s",
172 ts->num, ts->line->num, e1inp_tstype_name(ts->type),
173 VTY_NEWLINE);
174}
175
176DEFUN(show_e1ts,
177 show_e1ts_cmd,
178 "show e1_timeslot [line_nr] [ts_nr]",
179 SHOW_STR "Display information about a E1 timeslot\n"
180 "E1 Line Number\n" "E1 Timeslot Number\n")
181{
182 struct e1inp_line *line = NULL;
183 struct e1inp_ts *ts;
184 int ts_nr;
185
186 if (argc == 0) {
187 llist_for_each_entry(line, &e1inp_line_list, list) {
188 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
189 ts = &line->ts[ts_nr];
190 e1ts_dump_vty(vty, ts);
191 }
192 }
193 return CMD_SUCCESS;
194 }
195 if (argc >= 1) {
196 int num = atoi(argv[0]);
197 struct e1inp_line *l;
198 llist_for_each_entry(l, &e1inp_line_list, list) {
199 if (l->num == num) {
200 line = l;
201 break;
202 }
203 }
204 if (!line) {
205 vty_out(vty, "E1 line %s is invalid%s",
206 argv[0], VTY_NEWLINE);
207 return CMD_WARNING;
208 }
209 }
210 if (argc >= 2) {
211 ts_nr = atoi(argv[1]);
212 if (ts_nr >= NUM_E1_TS) {
213 vty_out(vty, "E1 timeslot %s is invalid%s",
214 argv[1], VTY_NEWLINE);
215 return CMD_WARNING;
216 }
217 ts = &line->ts[ts_nr];
218 e1ts_dump_vty(vty, ts);
219 return CMD_SUCCESS;
220 } else {
221 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
222 ts = &line->ts[ts_nr];
223 e1ts_dump_vty(vty, ts);
224 }
225 return CMD_SUCCESS;
226 }
227 return CMD_SUCCESS;
228}
229
230
Harald Weltee76bea02011-02-05 13:54:41 +0100231struct cmd_node e1inp_node = {
232 E1INP_NODE,
233 "%s(e1_input)#",
234 1,
235};
236
237int e1inp_vty_init(void)
238{
239 install_element(CONFIG_NODE, &cfg_e1inp_cmd);
240 install_node(&e1inp_node, e1inp_config_write);
241 install_element(E1INP_NODE, &cfg_e1_line_driver_cmd);
Harald Welte7b612652011-08-11 12:40:07 +0200242 install_element(E1INP_NODE, &cfg_e1_line_name_cmd);
Harald Weltee76bea02011-02-05 13:54:41 +0100243
Harald Welte008be6a2011-08-11 12:43:31 +0200244 install_element_ve(&show_e1drv_cmd);
245 install_element_ve(&show_e1line_cmd);
246 install_element_ve(&show_e1ts_cmd);
247
Harald Weltee76bea02011-02-05 13:54:41 +0100248 return 0;
249}