blob: bcc025191aa904fc4001d896c6b68aecf12e9d5e [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
Harald Weltece307b42011-08-21 01:18:05 +020041#define E1_DRIVER_NAMES "(misdn|misdn_lapd|dahdi|ipa|hsl)"
42#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" \
45 "IPA TCP/IP input" \
46 "HSL TCP/IP input"
47
Harald Welte601a9c72011-08-16 14:17:49 +020048#define E1_LINE_HELP "Configure E1/T1/J1 Line\n" "Line Number\n"
49
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020050DEFUN(cfg_e1line_driver, cfg_e1_line_driver_cmd,
51 "e1_line <0-255> driver " E1_DRIVER_NAMES,
Harald Welte601a9c72011-08-16 14:17:49 +020052 E1_LINE_HELP "Set driver for this line\n"
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020053 E1_DRIVER_HELP)
54{
55 struct e1inp_line *line;
56 int e1_nr = atoi(argv[0]);
57
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +020058 line = e1inp_line_find(e1_nr);
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020059 if (line) {
60 vty_out(vty, "%% Line %d already exists%s", e1_nr, VTY_NEWLINE);
61 return CMD_WARNING;
62 }
63 line = e1inp_line_create(e1_nr, argv[1]);
64 if (!line) {
65 vty_out(vty, "%% Error creating line %d%s", e1_nr, VTY_NEWLINE);
66 return CMD_WARNING;
67 }
68
69 return CMD_SUCCESS;
70}
71
Harald Welte601a9c72011-08-16 14:17:49 +020072DEFUN(cfg_e1line_name, cfg_e1_line_name_cmd,
73 "e1_line <0-255> name .LINE",
74 E1_LINE_HELP "Set name for this line\n" "Human readable name\n")
75{
76 struct e1inp_line *line;
77 int e1_nr = atoi(argv[0]);
78
79 line = e1inp_line_find(e1_nr);
80 if (!line) {
81 vty_out(vty, "%% Line %d doesn't exist%s", e1_nr, VTY_NEWLINE);
82 return CMD_WARNING;
83 }
84 if (line->name) {
85 talloc_free((void *)line->name);
86 line->name = NULL;
87 }
88 line->name = talloc_strdup(line, argv[1]);
89
90 return CMD_SUCCESS;
91}
92
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020093DEFUN(cfg_e1inp, cfg_e1inp_cmd,
94 "e1_input",
95 "Configure E1/T1/J1 TDM input\n")
96{
Harald Weltecc2241b2011-07-19 16:06:06 +020097 vty->node = L_E1INP_NODE;
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020098
99 return CMD_SUCCESS;
100}
101
102static int e1inp_config_write(struct vty *vty)
103{
104 struct e1inp_line *line;
105
106 if (llist_empty(&e1inp_line_list))
107 return CMD_SUCCESS;
108
109 vty_out(vty, "e1_input%s", VTY_NEWLINE);
110
111 llist_for_each_entry(line, &e1inp_line_list, list) {
112 vty_out(vty, " e1_line %u driver %s%s", line->num,
113 line->driver->name, VTY_NEWLINE);
Harald Welte601a9c72011-08-16 14:17:49 +0200114 if (line->name)
115 vty_out(vty, " e1_line %u name %s%s", line->num,
116 line->name, VTY_NEWLINE);
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200117 }
118 return CMD_SUCCESS;
119}
120
Harald Weltef2737fc2011-08-16 14:30:10 +0200121/* SHOW */
122
Harald Welte6e37c592011-08-11 12:43:31 +0200123static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv)
124{
125 vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE);
126}
127
128DEFUN(show_e1drv,
129 show_e1drv_cmd,
130 "show e1_driver",
131 SHOW_STR "Display information about available E1 drivers\n")
132{
133 struct e1inp_driver *drv;
134
135 llist_for_each_entry(drv, &e1inp_driver_list, list)
136 e1drv_dump_vty(vty, drv);
137
138 return CMD_SUCCESS;
139}
140
Harald Weltef2737fc2011-08-16 14:30:10 +0200141static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line,
142 int stats)
Harald Welte6e37c592011-08-11 12:43:31 +0200143{
144 vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s",
145 line->num, line->name ? line->name : "",
146 line->driver->name, VTY_NEWLINE);
Harald Weltef2737fc2011-08-16 14:30:10 +0200147 if (stats)
148 vty_out_rate_ctr_group(vty, " ", line->rate_ctr);
Harald Welte6e37c592011-08-11 12:43:31 +0200149}
150
151DEFUN(show_e1line,
152 show_e1line_cmd,
Harald Weltef2737fc2011-08-16 14:30:10 +0200153 "show e1_line [line_nr] [stats]",
Harald Welte6e37c592011-08-11 12:43:31 +0200154 SHOW_STR "Display information about a E1 line\n"
155 "E1 Line Number\n")
156{
157 struct e1inp_line *line;
Harald Weltef2737fc2011-08-16 14:30:10 +0200158 int stats = 0;
Harald Welte6e37c592011-08-11 12:43:31 +0200159
Harald Weltef2737fc2011-08-16 14:30:10 +0200160 if (argc >= 1 && strcmp(argv[0], "stats")) {
Harald Welte6e37c592011-08-11 12:43:31 +0200161 int num = atoi(argv[0]);
Harald Weltef2737fc2011-08-16 14:30:10 +0200162 if (argc >= 2)
163 stats = 1;
Harald Welte6e37c592011-08-11 12:43:31 +0200164 llist_for_each_entry(line, &e1inp_line_list, list) {
165 if (line->num == num) {
Harald Weltef2737fc2011-08-16 14:30:10 +0200166 e1line_dump_vty(vty, line, stats);
Harald Welte6e37c592011-08-11 12:43:31 +0200167 return CMD_SUCCESS;
168 }
169 }
170 return CMD_WARNING;
171 }
172
Harald Weltef2737fc2011-08-16 14:30:10 +0200173 if (argc >= 1 && !strcmp(argv[0], "stats"))
174 stats = 1;
175
Harald Welte6e37c592011-08-11 12:43:31 +0200176 llist_for_each_entry(line, &e1inp_line_list, list)
Harald Weltef2737fc2011-08-16 14:30:10 +0200177 e1line_dump_vty(vty, line, stats);
Harald Welte6e37c592011-08-11 12:43:31 +0200178
179 return CMD_SUCCESS;
180}
181
182static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts)
183{
184 if (ts->type == E1INP_TS_TYPE_NONE)
185 return;
186 vty_out(vty, "E1 Timeslot %2u of Line %u is Type %s%s",
187 ts->num, ts->line->num, e1inp_tstype_name(ts->type),
188 VTY_NEWLINE);
189}
190
191DEFUN(show_e1ts,
192 show_e1ts_cmd,
193 "show e1_timeslot [line_nr] [ts_nr]",
194 SHOW_STR "Display information about a E1 timeslot\n"
195 "E1 Line Number\n" "E1 Timeslot Number\n")
196{
197 struct e1inp_line *line = NULL;
198 struct e1inp_ts *ts;
199 int ts_nr;
200
201 if (argc == 0) {
202 llist_for_each_entry(line, &e1inp_line_list, list) {
203 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
204 ts = &line->ts[ts_nr];
205 e1ts_dump_vty(vty, ts);
206 }
207 }
208 return CMD_SUCCESS;
209 }
210 if (argc >= 1) {
211 int num = atoi(argv[0]);
212 struct e1inp_line *l;
213 llist_for_each_entry(l, &e1inp_line_list, list) {
214 if (l->num == num) {
215 line = l;
216 break;
217 }
218 }
219 if (!line) {
220 vty_out(vty, "E1 line %s is invalid%s",
221 argv[0], VTY_NEWLINE);
222 return CMD_WARNING;
223 }
224 }
225 if (argc >= 2) {
226 ts_nr = atoi(argv[1]);
227 if (ts_nr >= NUM_E1_TS) {
228 vty_out(vty, "E1 timeslot %s is invalid%s",
229 argv[1], VTY_NEWLINE);
230 return CMD_WARNING;
231 }
232 ts = &line->ts[ts_nr];
233 e1ts_dump_vty(vty, ts);
234 return CMD_SUCCESS;
235 } else {
236 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
237 ts = &line->ts[ts_nr];
238 e1ts_dump_vty(vty, ts);
239 }
240 return CMD_SUCCESS;
241 }
242 return CMD_SUCCESS;
243}
244
245
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200246struct cmd_node e1inp_node = {
Harald Weltecc2241b2011-07-19 16:06:06 +0200247 L_E1INP_NODE,
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200248 "%s(e1_input)#",
249 1,
250};
251
252int e1inp_vty_init(void)
253{
254 install_element(CONFIG_NODE, &cfg_e1inp_cmd);
255 install_node(&e1inp_node, e1inp_config_write);
Harald Weltecc2241b2011-07-19 16:06:06 +0200256 install_element(L_E1INP_NODE, &cfg_e1_line_driver_cmd);
Harald Welte601a9c72011-08-16 14:17:49 +0200257 install_element(L_E1INP_NODE, &cfg_e1_line_name_cmd);
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200258
Harald Welte6e37c592011-08-11 12:43:31 +0200259 install_element_ve(&show_e1drv_cmd);
260 install_element_ve(&show_e1line_cmd);
261 install_element_ve(&show_e1ts_cmd);
262
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200263 return 0;
264}