blob: aa70805b8671dfacb69a9419ba62982c45a9fc66 [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
41#define E1_DRIVER_NAMES "(misdn|dahdi|ipa|hsl)"
42#define E1_DRIVER_HELP "mISDN supported E1 Card\n" \
43 "DAHDI supported E1/T1/J1 Card\n" \
44 "IPA TCP/IP input" \
45 "HSL TCP/IP input"
46
Harald Welte601a9c72011-08-16 14:17:49 +020047#define E1_LINE_HELP "Configure E1/T1/J1 Line\n" "Line Number\n"
48
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020049DEFUN(cfg_e1line_driver, cfg_e1_line_driver_cmd,
50 "e1_line <0-255> driver " E1_DRIVER_NAMES,
Harald Welte601a9c72011-08-16 14:17:49 +020051 E1_LINE_HELP "Set driver for this line\n"
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020052 E1_DRIVER_HELP)
53{
54 struct e1inp_line *line;
55 int e1_nr = atoi(argv[0]);
56
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +020057 line = e1inp_line_find(e1_nr);
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020058 if (line) {
59 vty_out(vty, "%% Line %d already exists%s", e1_nr, VTY_NEWLINE);
60 return CMD_WARNING;
61 }
62 line = e1inp_line_create(e1_nr, argv[1]);
63 if (!line) {
64 vty_out(vty, "%% Error creating line %d%s", e1_nr, VTY_NEWLINE);
65 return CMD_WARNING;
66 }
67
68 return CMD_SUCCESS;
69}
70
Harald Welte601a9c72011-08-16 14:17:49 +020071DEFUN(cfg_e1line_name, cfg_e1_line_name_cmd,
72 "e1_line <0-255> name .LINE",
73 E1_LINE_HELP "Set name for this line\n" "Human readable name\n")
74{
75 struct e1inp_line *line;
76 int e1_nr = atoi(argv[0]);
77
78 line = e1inp_line_find(e1_nr);
79 if (!line) {
80 vty_out(vty, "%% Line %d doesn't exist%s", e1_nr, VTY_NEWLINE);
81 return CMD_WARNING;
82 }
83 if (line->name) {
84 talloc_free((void *)line->name);
85 line->name = NULL;
86 }
87 line->name = talloc_strdup(line, argv[1]);
88
89 return CMD_SUCCESS;
90}
91
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020092DEFUN(cfg_e1inp, cfg_e1inp_cmd,
93 "e1_input",
94 "Configure E1/T1/J1 TDM input\n")
95{
Harald Weltecc2241b2011-07-19 16:06:06 +020096 vty->node = L_E1INP_NODE;
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020097
98 return CMD_SUCCESS;
99}
100
101static int e1inp_config_write(struct vty *vty)
102{
103 struct e1inp_line *line;
104
105 if (llist_empty(&e1inp_line_list))
106 return CMD_SUCCESS;
107
108 vty_out(vty, "e1_input%s", VTY_NEWLINE);
109
110 llist_for_each_entry(line, &e1inp_line_list, list) {
111 vty_out(vty, " e1_line %u driver %s%s", line->num,
112 line->driver->name, VTY_NEWLINE);
Harald Welte601a9c72011-08-16 14:17:49 +0200113 if (line->name)
114 vty_out(vty, " e1_line %u name %s%s", line->num,
115 line->name, VTY_NEWLINE);
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200116 }
117 return CMD_SUCCESS;
118}
119
Harald Weltef2737fc2011-08-16 14:30:10 +0200120/* SHOW */
121
Harald Welte6e37c592011-08-11 12:43:31 +0200122static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv)
123{
124 vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE);
125}
126
127DEFUN(show_e1drv,
128 show_e1drv_cmd,
129 "show e1_driver",
130 SHOW_STR "Display information about available E1 drivers\n")
131{
132 struct e1inp_driver *drv;
133
134 llist_for_each_entry(drv, &e1inp_driver_list, list)
135 e1drv_dump_vty(vty, drv);
136
137 return CMD_SUCCESS;
138}
139
Harald Weltef2737fc2011-08-16 14:30:10 +0200140static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line,
141 int stats)
Harald Welte6e37c592011-08-11 12:43:31 +0200142{
143 vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s",
144 line->num, line->name ? line->name : "",
145 line->driver->name, VTY_NEWLINE);
Harald Weltef2737fc2011-08-16 14:30:10 +0200146 if (stats)
147 vty_out_rate_ctr_group(vty, " ", line->rate_ctr);
Harald Welte6e37c592011-08-11 12:43:31 +0200148}
149
150DEFUN(show_e1line,
151 show_e1line_cmd,
Harald Weltef2737fc2011-08-16 14:30:10 +0200152 "show e1_line [line_nr] [stats]",
Harald Welte6e37c592011-08-11 12:43:31 +0200153 SHOW_STR "Display information about a E1 line\n"
154 "E1 Line Number\n")
155{
156 struct e1inp_line *line;
Harald Weltef2737fc2011-08-16 14:30:10 +0200157 int stats = 0;
Harald Welte6e37c592011-08-11 12:43:31 +0200158
Harald Weltef2737fc2011-08-16 14:30:10 +0200159 if (argc >= 1 && strcmp(argv[0], "stats")) {
Harald Welte6e37c592011-08-11 12:43:31 +0200160 int num = atoi(argv[0]);
Harald Weltef2737fc2011-08-16 14:30:10 +0200161 if (argc >= 2)
162 stats = 1;
Harald Welte6e37c592011-08-11 12:43:31 +0200163 llist_for_each_entry(line, &e1inp_line_list, list) {
164 if (line->num == num) {
Harald Weltef2737fc2011-08-16 14:30:10 +0200165 e1line_dump_vty(vty, line, stats);
Harald Welte6e37c592011-08-11 12:43:31 +0200166 return CMD_SUCCESS;
167 }
168 }
169 return CMD_WARNING;
170 }
171
Harald Weltef2737fc2011-08-16 14:30:10 +0200172 if (argc >= 1 && !strcmp(argv[0], "stats"))
173 stats = 1;
174
Harald Welte6e37c592011-08-11 12:43:31 +0200175 llist_for_each_entry(line, &e1inp_line_list, list)
Harald Weltef2737fc2011-08-16 14:30:10 +0200176 e1line_dump_vty(vty, line, stats);
Harald Welte6e37c592011-08-11 12:43:31 +0200177
178 return CMD_SUCCESS;
179}
180
181static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts)
182{
183 if (ts->type == E1INP_TS_TYPE_NONE)
184 return;
185 vty_out(vty, "E1 Timeslot %2u of Line %u is Type %s%s",
186 ts->num, ts->line->num, e1inp_tstype_name(ts->type),
187 VTY_NEWLINE);
188}
189
190DEFUN(show_e1ts,
191 show_e1ts_cmd,
192 "show e1_timeslot [line_nr] [ts_nr]",
193 SHOW_STR "Display information about a E1 timeslot\n"
194 "E1 Line Number\n" "E1 Timeslot Number\n")
195{
196 struct e1inp_line *line = NULL;
197 struct e1inp_ts *ts;
198 int ts_nr;
199
200 if (argc == 0) {
201 llist_for_each_entry(line, &e1inp_line_list, list) {
202 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
203 ts = &line->ts[ts_nr];
204 e1ts_dump_vty(vty, ts);
205 }
206 }
207 return CMD_SUCCESS;
208 }
209 if (argc >= 1) {
210 int num = atoi(argv[0]);
211 struct e1inp_line *l;
212 llist_for_each_entry(l, &e1inp_line_list, list) {
213 if (l->num == num) {
214 line = l;
215 break;
216 }
217 }
218 if (!line) {
219 vty_out(vty, "E1 line %s is invalid%s",
220 argv[0], VTY_NEWLINE);
221 return CMD_WARNING;
222 }
223 }
224 if (argc >= 2) {
225 ts_nr = atoi(argv[1]);
226 if (ts_nr >= NUM_E1_TS) {
227 vty_out(vty, "E1 timeslot %s is invalid%s",
228 argv[1], VTY_NEWLINE);
229 return CMD_WARNING;
230 }
231 ts = &line->ts[ts_nr];
232 e1ts_dump_vty(vty, ts);
233 return CMD_SUCCESS;
234 } else {
235 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
236 ts = &line->ts[ts_nr];
237 e1ts_dump_vty(vty, ts);
238 }
239 return CMD_SUCCESS;
240 }
241 return CMD_SUCCESS;
242}
243
244
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200245struct cmd_node e1inp_node = {
Harald Weltecc2241b2011-07-19 16:06:06 +0200246 L_E1INP_NODE,
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200247 "%s(e1_input)#",
248 1,
249};
250
251int e1inp_vty_init(void)
252{
253 install_element(CONFIG_NODE, &cfg_e1inp_cmd);
254 install_node(&e1inp_node, e1inp_config_write);
Harald Weltecc2241b2011-07-19 16:06:06 +0200255 install_element(L_E1INP_NODE, &cfg_e1_line_driver_cmd);
Harald Welte601a9c72011-08-16 14:17:49 +0200256 install_element(L_E1INP_NODE, &cfg_e1_line_name_cmd);
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200257
Harald Welte6e37c592011-08-11 12:43:31 +0200258 install_element_ve(&show_e1drv_cmd);
259 install_element_ve(&show_e1line_cmd);
260 install_element_ve(&show_e1ts_cmd);
261
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200262 return 0;
263}