blob: a8ccabb3c29d35ad3adc0202462dcd8e8b1585fb [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>
23
Harald Weltef2737fc2011-08-16 14:30:10 +020024#include <osmocom/core/linuxlist.h>
25#include <osmocom/core/talloc.h>
26#include <osmocom/core/utils.h>
27#include <osmocom/gsm/gsm_utils.h>
28
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020029#include <osmocom/vty/command.h>
30#include <osmocom/vty/buffer.h>
31#include <osmocom/vty/vty.h>
32#include <osmocom/vty/logging.h>
Harald Weltef2737fc2011-08-16 14:30:10 +020033#include <osmocom/vty/misc.h>
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020034#include <osmocom/vty/telnet_interface.h>
35
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020036#include <osmocom/abis/e1_input.h>
Harald Weltef2737fc2011-08-16 14:30:10 +020037
38/* CONFIG */
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020039
40#define E1_DRIVER_NAMES "(misdn|dahdi|ipa|hsl)"
41#define E1_DRIVER_HELP "mISDN supported E1 Card\n" \
42 "DAHDI supported E1/T1/J1 Card\n" \
43 "IPA TCP/IP input" \
44 "HSL TCP/IP input"
45
Harald Welte601a9c72011-08-16 14:17:49 +020046#define E1_LINE_HELP "Configure E1/T1/J1 Line\n" "Line Number\n"
47
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020048DEFUN(cfg_e1line_driver, cfg_e1_line_driver_cmd,
49 "e1_line <0-255> driver " E1_DRIVER_NAMES,
Harald Welte601a9c72011-08-16 14:17:49 +020050 E1_LINE_HELP "Set driver for this line\n"
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020051 E1_DRIVER_HELP)
52{
53 struct e1inp_line *line;
54 int e1_nr = atoi(argv[0]);
55
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +020056 line = e1inp_line_find(e1_nr);
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020057 if (line) {
58 vty_out(vty, "%% Line %d already exists%s", e1_nr, VTY_NEWLINE);
59 return CMD_WARNING;
60 }
61 line = e1inp_line_create(e1_nr, argv[1]);
62 if (!line) {
63 vty_out(vty, "%% Error creating line %d%s", e1_nr, VTY_NEWLINE);
64 return CMD_WARNING;
65 }
66
67 return CMD_SUCCESS;
68}
69
Harald Welte601a9c72011-08-16 14:17:49 +020070DEFUN(cfg_e1line_name, cfg_e1_line_name_cmd,
71 "e1_line <0-255> name .LINE",
72 E1_LINE_HELP "Set name for this line\n" "Human readable name\n")
73{
74 struct e1inp_line *line;
75 int e1_nr = atoi(argv[0]);
76
77 line = e1inp_line_find(e1_nr);
78 if (!line) {
79 vty_out(vty, "%% Line %d doesn't exist%s", e1_nr, VTY_NEWLINE);
80 return CMD_WARNING;
81 }
82 if (line->name) {
83 talloc_free((void *)line->name);
84 line->name = NULL;
85 }
86 line->name = talloc_strdup(line, argv[1]);
87
88 return CMD_SUCCESS;
89}
90
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020091DEFUN(cfg_e1inp, cfg_e1inp_cmd,
92 "e1_input",
93 "Configure E1/T1/J1 TDM input\n")
94{
Harald Weltecc2241b2011-07-19 16:06:06 +020095 vty->node = L_E1INP_NODE;
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020096
97 return CMD_SUCCESS;
98}
99
100static int e1inp_config_write(struct vty *vty)
101{
102 struct e1inp_line *line;
103
104 if (llist_empty(&e1inp_line_list))
105 return CMD_SUCCESS;
106
107 vty_out(vty, "e1_input%s", VTY_NEWLINE);
108
109 llist_for_each_entry(line, &e1inp_line_list, list) {
110 vty_out(vty, " e1_line %u driver %s%s", line->num,
111 line->driver->name, VTY_NEWLINE);
Harald Welte601a9c72011-08-16 14:17:49 +0200112 if (line->name)
113 vty_out(vty, " e1_line %u name %s%s", line->num,
114 line->name, VTY_NEWLINE);
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200115 }
116 return CMD_SUCCESS;
117}
118
Harald Weltef2737fc2011-08-16 14:30:10 +0200119/* SHOW */
120
Harald Welte6e37c592011-08-11 12:43:31 +0200121static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv)
122{
123 vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE);
124}
125
126DEFUN(show_e1drv,
127 show_e1drv_cmd,
128 "show e1_driver",
129 SHOW_STR "Display information about available E1 drivers\n")
130{
131 struct e1inp_driver *drv;
132
133 llist_for_each_entry(drv, &e1inp_driver_list, list)
134 e1drv_dump_vty(vty, drv);
135
136 return CMD_SUCCESS;
137}
138
Harald Weltef2737fc2011-08-16 14:30:10 +0200139static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line,
140 int stats)
Harald Welte6e37c592011-08-11 12:43:31 +0200141{
142 vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s",
143 line->num, line->name ? line->name : "",
144 line->driver->name, VTY_NEWLINE);
Harald Weltef2737fc2011-08-16 14:30:10 +0200145 if (stats)
146 vty_out_rate_ctr_group(vty, " ", line->rate_ctr);
Harald Welte6e37c592011-08-11 12:43:31 +0200147}
148
149DEFUN(show_e1line,
150 show_e1line_cmd,
Harald Weltef2737fc2011-08-16 14:30:10 +0200151 "show e1_line [line_nr] [stats]",
Harald Welte6e37c592011-08-11 12:43:31 +0200152 SHOW_STR "Display information about a E1 line\n"
153 "E1 Line Number\n")
154{
155 struct e1inp_line *line;
Harald Weltef2737fc2011-08-16 14:30:10 +0200156 int stats = 0;
Harald Welte6e37c592011-08-11 12:43:31 +0200157
Harald Weltef2737fc2011-08-16 14:30:10 +0200158 if (argc >= 1 && strcmp(argv[0], "stats")) {
Harald Welte6e37c592011-08-11 12:43:31 +0200159 int num = atoi(argv[0]);
Harald Weltef2737fc2011-08-16 14:30:10 +0200160 if (argc >= 2)
161 stats = 1;
Harald Welte6e37c592011-08-11 12:43:31 +0200162 llist_for_each_entry(line, &e1inp_line_list, list) {
163 if (line->num == num) {
Harald Weltef2737fc2011-08-16 14:30:10 +0200164 e1line_dump_vty(vty, line, stats);
Harald Welte6e37c592011-08-11 12:43:31 +0200165 return CMD_SUCCESS;
166 }
167 }
168 return CMD_WARNING;
169 }
170
Harald Weltef2737fc2011-08-16 14:30:10 +0200171 if (argc >= 1 && !strcmp(argv[0], "stats"))
172 stats = 1;
173
Harald Welte6e37c592011-08-11 12:43:31 +0200174 llist_for_each_entry(line, &e1inp_line_list, list)
Harald Weltef2737fc2011-08-16 14:30:10 +0200175 e1line_dump_vty(vty, line, stats);
Harald Welte6e37c592011-08-11 12:43:31 +0200176
177 return CMD_SUCCESS;
178}
179
180static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts)
181{
182 if (ts->type == E1INP_TS_TYPE_NONE)
183 return;
184 vty_out(vty, "E1 Timeslot %2u of Line %u is Type %s%s",
185 ts->num, ts->line->num, e1inp_tstype_name(ts->type),
186 VTY_NEWLINE);
187}
188
189DEFUN(show_e1ts,
190 show_e1ts_cmd,
191 "show e1_timeslot [line_nr] [ts_nr]",
192 SHOW_STR "Display information about a E1 timeslot\n"
193 "E1 Line Number\n" "E1 Timeslot Number\n")
194{
195 struct e1inp_line *line = NULL;
196 struct e1inp_ts *ts;
197 int ts_nr;
198
199 if (argc == 0) {
200 llist_for_each_entry(line, &e1inp_line_list, list) {
201 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
202 ts = &line->ts[ts_nr];
203 e1ts_dump_vty(vty, ts);
204 }
205 }
206 return CMD_SUCCESS;
207 }
208 if (argc >= 1) {
209 int num = atoi(argv[0]);
210 struct e1inp_line *l;
211 llist_for_each_entry(l, &e1inp_line_list, list) {
212 if (l->num == num) {
213 line = l;
214 break;
215 }
216 }
217 if (!line) {
218 vty_out(vty, "E1 line %s is invalid%s",
219 argv[0], VTY_NEWLINE);
220 return CMD_WARNING;
221 }
222 }
223 if (argc >= 2) {
224 ts_nr = atoi(argv[1]);
225 if (ts_nr >= NUM_E1_TS) {
226 vty_out(vty, "E1 timeslot %s is invalid%s",
227 argv[1], VTY_NEWLINE);
228 return CMD_WARNING;
229 }
230 ts = &line->ts[ts_nr];
231 e1ts_dump_vty(vty, ts);
232 return CMD_SUCCESS;
233 } else {
234 for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) {
235 ts = &line->ts[ts_nr];
236 e1ts_dump_vty(vty, ts);
237 }
238 return CMD_SUCCESS;
239 }
240 return CMD_SUCCESS;
241}
242
243
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200244struct cmd_node e1inp_node = {
Harald Weltecc2241b2011-07-19 16:06:06 +0200245 L_E1INP_NODE,
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200246 "%s(e1_input)#",
247 1,
248};
249
250int e1inp_vty_init(void)
251{
252 install_element(CONFIG_NODE, &cfg_e1inp_cmd);
253 install_node(&e1inp_node, e1inp_config_write);
Harald Weltecc2241b2011-07-19 16:06:06 +0200254 install_element(L_E1INP_NODE, &cfg_e1_line_driver_cmd);
Harald Welte601a9c72011-08-16 14:17:49 +0200255 install_element(L_E1INP_NODE, &cfg_e1_line_name_cmd);
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200256
Harald Welte6e37c592011-08-11 12:43:31 +0200257 install_element_ve(&show_e1drv_cmd);
258 install_element_ve(&show_e1line_cmd);
259 install_element_ve(&show_e1ts_cmd);
260
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200261 return 0;
262}