Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 1 | /* 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 Welte | d4f8f68 | 2011-08-19 13:28:48 +0200 | [diff] [blame] | 23 | #include <string.h> |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 24 | |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 25 | #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 Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 30 | #include <osmocom/vty/command.h> |
| 31 | #include <osmocom/vty/buffer.h> |
| 32 | #include <osmocom/vty/vty.h> |
| 33 | #include <osmocom/vty/logging.h> |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 34 | #include <osmocom/vty/misc.h> |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 35 | #include <osmocom/vty/telnet_interface.h> |
| 36 | |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 37 | #include <osmocom/abis/e1_input.h> |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 38 | |
| 39 | /* CONFIG */ |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 40 | |
Harald Welte | ce307b4 | 2011-08-21 01:18:05 +0200 | [diff] [blame] | 41 | #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 Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 44 | "DAHDI supported E1/T1/J1 Card\n" \ |
| 45 | "IPA TCP/IP input" \ |
| 46 | "HSL TCP/IP input" |
| 47 | |
Harald Welte | 601a9c7 | 2011-08-16 14:17:49 +0200 | [diff] [blame] | 48 | #define E1_LINE_HELP "Configure E1/T1/J1 Line\n" "Line Number\n" |
| 49 | |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 50 | DEFUN(cfg_e1line_driver, cfg_e1_line_driver_cmd, |
| 51 | "e1_line <0-255> driver " E1_DRIVER_NAMES, |
Harald Welte | 601a9c7 | 2011-08-16 14:17:49 +0200 | [diff] [blame] | 52 | E1_LINE_HELP "Set driver for this line\n" |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 53 | E1_DRIVER_HELP) |
| 54 | { |
| 55 | struct e1inp_line *line; |
| 56 | int e1_nr = atoi(argv[0]); |
| 57 | |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 58 | line = e1inp_line_find(e1_nr); |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 59 | 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 Welte | c288951 | 2011-09-13 23:49:04 +0100 | [diff] [blame] | 72 | DEFUN(cfg_e1line_port, cfg_e1_line_port_cmd, |
Harald Welte | 356918f | 2011-09-26 22:54:51 +0200 | [diff] [blame] | 73 | "e1_line <0-255> port <0-255>", |
| 74 | E1_LINE_HELP "Set physical port/span/card number\n" |
Harald Welte | c288951 | 2011-09-13 23:49:04 +0100 | [diff] [blame] | 75 | "E1/T1 Port/Span/Card number\n") |
| 76 | { |
| 77 | struct e1inp_line *line; |
| 78 | int e1_nr = atoi(argv[0]); |
| 79 | |
| 80 | line = e1inp_line_find(e1_nr); |
| 81 | if (!line) { |
| 82 | vty_out(vty, "%% Line %d doesn't exist%s", e1_nr, VTY_NEWLINE); |
| 83 | return CMD_WARNING; |
| 84 | } |
| 85 | |
| 86 | line->port_nr = atoi(argv[1]); |
| 87 | |
| 88 | return CMD_SUCCESS; |
| 89 | } |
| 90 | |
Harald Welte | 601a9c7 | 2011-08-16 14:17:49 +0200 | [diff] [blame] | 91 | DEFUN(cfg_e1line_name, cfg_e1_line_name_cmd, |
| 92 | "e1_line <0-255> name .LINE", |
| 93 | E1_LINE_HELP "Set name for this line\n" "Human readable name\n") |
| 94 | { |
| 95 | struct e1inp_line *line; |
| 96 | int e1_nr = atoi(argv[0]); |
| 97 | |
| 98 | line = e1inp_line_find(e1_nr); |
| 99 | if (!line) { |
| 100 | vty_out(vty, "%% Line %d doesn't exist%s", e1_nr, VTY_NEWLINE); |
| 101 | return CMD_WARNING; |
| 102 | } |
| 103 | if (line->name) { |
| 104 | talloc_free((void *)line->name); |
| 105 | line->name = NULL; |
| 106 | } |
| 107 | line->name = talloc_strdup(line, argv[1]); |
| 108 | |
| 109 | return CMD_SUCCESS; |
| 110 | } |
| 111 | |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 112 | DEFUN(cfg_e1inp, cfg_e1inp_cmd, |
| 113 | "e1_input", |
| 114 | "Configure E1/T1/J1 TDM input\n") |
| 115 | { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 116 | vty->node = L_E1INP_NODE; |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 117 | |
| 118 | return CMD_SUCCESS; |
| 119 | } |
| 120 | |
| 121 | static int e1inp_config_write(struct vty *vty) |
| 122 | { |
| 123 | struct e1inp_line *line; |
| 124 | |
| 125 | if (llist_empty(&e1inp_line_list)) |
| 126 | return CMD_SUCCESS; |
| 127 | |
| 128 | vty_out(vty, "e1_input%s", VTY_NEWLINE); |
| 129 | |
| 130 | llist_for_each_entry(line, &e1inp_line_list, list) { |
| 131 | vty_out(vty, " e1_line %u driver %s%s", line->num, |
| 132 | line->driver->name, VTY_NEWLINE); |
Harald Welte | c288951 | 2011-09-13 23:49:04 +0100 | [diff] [blame] | 133 | vty_out(vty, " e1_line %u port %u%s", line->num, |
| 134 | line->port_nr, VTY_NEWLINE); |
Harald Welte | 601a9c7 | 2011-08-16 14:17:49 +0200 | [diff] [blame] | 135 | if (line->name) |
| 136 | vty_out(vty, " e1_line %u name %s%s", line->num, |
| 137 | line->name, VTY_NEWLINE); |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 138 | } |
| 139 | return CMD_SUCCESS; |
| 140 | } |
| 141 | |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 142 | /* SHOW */ |
| 143 | |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 144 | static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv) |
| 145 | { |
| 146 | vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE); |
| 147 | } |
| 148 | |
| 149 | DEFUN(show_e1drv, |
| 150 | show_e1drv_cmd, |
| 151 | "show e1_driver", |
| 152 | SHOW_STR "Display information about available E1 drivers\n") |
| 153 | { |
| 154 | struct e1inp_driver *drv; |
| 155 | |
| 156 | llist_for_each_entry(drv, &e1inp_driver_list, list) |
| 157 | e1drv_dump_vty(vty, drv); |
| 158 | |
| 159 | return CMD_SUCCESS; |
| 160 | } |
| 161 | |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 162 | static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line, |
| 163 | int stats) |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 164 | { |
| 165 | vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s", |
| 166 | line->num, line->name ? line->name : "", |
| 167 | line->driver->name, VTY_NEWLINE); |
Harald Welte | fe05cf5 | 2011-09-26 23:18:41 +0200 | [diff] [blame] | 168 | if (line->driver->vty_show) |
| 169 | line->driver->vty_show(vty, line); |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 170 | if (stats) |
| 171 | vty_out_rate_ctr_group(vty, " ", line->rate_ctr); |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | DEFUN(show_e1line, |
| 175 | show_e1line_cmd, |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 176 | "show e1_line [line_nr] [stats]", |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 177 | SHOW_STR "Display information about a E1 line\n" |
| 178 | "E1 Line Number\n") |
| 179 | { |
| 180 | struct e1inp_line *line; |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 181 | int stats = 0; |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 182 | |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 183 | if (argc >= 1 && strcmp(argv[0], "stats")) { |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 184 | int num = atoi(argv[0]); |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 185 | if (argc >= 2) |
| 186 | stats = 1; |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 187 | llist_for_each_entry(line, &e1inp_line_list, list) { |
| 188 | if (line->num == num) { |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 189 | e1line_dump_vty(vty, line, stats); |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 190 | return CMD_SUCCESS; |
| 191 | } |
| 192 | } |
| 193 | return CMD_WARNING; |
| 194 | } |
| 195 | |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 196 | if (argc >= 1 && !strcmp(argv[0], "stats")) |
| 197 | stats = 1; |
| 198 | |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 199 | llist_for_each_entry(line, &e1inp_line_list, list) |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 200 | e1line_dump_vty(vty, line, stats); |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 201 | |
| 202 | return CMD_SUCCESS; |
| 203 | } |
| 204 | |
| 205 | static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts) |
| 206 | { |
| 207 | if (ts->type == E1INP_TS_TYPE_NONE) |
| 208 | return; |
| 209 | vty_out(vty, "E1 Timeslot %2u of Line %u is Type %s%s", |
| 210 | ts->num, ts->line->num, e1inp_tstype_name(ts->type), |
| 211 | VTY_NEWLINE); |
| 212 | } |
| 213 | |
| 214 | DEFUN(show_e1ts, |
| 215 | show_e1ts_cmd, |
| 216 | "show e1_timeslot [line_nr] [ts_nr]", |
| 217 | SHOW_STR "Display information about a E1 timeslot\n" |
| 218 | "E1 Line Number\n" "E1 Timeslot Number\n") |
| 219 | { |
| 220 | struct e1inp_line *line = NULL; |
| 221 | struct e1inp_ts *ts; |
| 222 | int ts_nr; |
| 223 | |
| 224 | if (argc == 0) { |
| 225 | llist_for_each_entry(line, &e1inp_line_list, list) { |
Harald Welte | c288951 | 2011-09-13 23:49:04 +0100 | [diff] [blame] | 226 | for (ts_nr = 0; ts_nr < line->num_ts; ts_nr++) { |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 227 | ts = &line->ts[ts_nr]; |
| 228 | e1ts_dump_vty(vty, ts); |
| 229 | } |
| 230 | } |
| 231 | return CMD_SUCCESS; |
| 232 | } |
| 233 | if (argc >= 1) { |
| 234 | int num = atoi(argv[0]); |
| 235 | struct e1inp_line *l; |
| 236 | llist_for_each_entry(l, &e1inp_line_list, list) { |
| 237 | if (l->num == num) { |
| 238 | line = l; |
| 239 | break; |
| 240 | } |
| 241 | } |
| 242 | if (!line) { |
| 243 | vty_out(vty, "E1 line %s is invalid%s", |
| 244 | argv[0], VTY_NEWLINE); |
| 245 | return CMD_WARNING; |
| 246 | } |
| 247 | } |
| 248 | if (argc >= 2) { |
| 249 | ts_nr = atoi(argv[1]); |
Harald Welte | c288951 | 2011-09-13 23:49:04 +0100 | [diff] [blame] | 250 | if (ts_nr >= line->num_ts) { |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 251 | vty_out(vty, "E1 timeslot %s is invalid%s", |
| 252 | argv[1], VTY_NEWLINE); |
| 253 | return CMD_WARNING; |
| 254 | } |
| 255 | ts = &line->ts[ts_nr]; |
| 256 | e1ts_dump_vty(vty, ts); |
| 257 | return CMD_SUCCESS; |
| 258 | } else { |
Harald Welte | c288951 | 2011-09-13 23:49:04 +0100 | [diff] [blame] | 259 | for (ts_nr = 0; ts_nr < line->num_ts; ts_nr++) { |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 260 | ts = &line->ts[ts_nr]; |
| 261 | e1ts_dump_vty(vty, ts); |
| 262 | } |
| 263 | return CMD_SUCCESS; |
| 264 | } |
| 265 | return CMD_SUCCESS; |
| 266 | } |
| 267 | |
| 268 | |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 269 | struct cmd_node e1inp_node = { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 270 | L_E1INP_NODE, |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 271 | "%s(e1_input)#", |
| 272 | 1, |
| 273 | }; |
| 274 | |
| 275 | int e1inp_vty_init(void) |
| 276 | { |
| 277 | install_element(CONFIG_NODE, &cfg_e1inp_cmd); |
| 278 | install_node(&e1inp_node, e1inp_config_write); |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 279 | install_element(L_E1INP_NODE, &cfg_e1_line_driver_cmd); |
Harald Welte | c288951 | 2011-09-13 23:49:04 +0100 | [diff] [blame] | 280 | install_element(L_E1INP_NODE, &cfg_e1_line_port_cmd); |
Harald Welte | 601a9c7 | 2011-08-16 14:17:49 +0200 | [diff] [blame] | 281 | install_element(L_E1INP_NODE, &cfg_e1_line_name_cmd); |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 282 | |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 283 | install_element_ve(&show_e1drv_cmd); |
| 284 | install_element_ve(&show_e1line_cmd); |
| 285 | install_element_ve(&show_e1ts_cmd); |
| 286 | |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 287 | return 0; |
| 288 | } |