Pau Espin Pedrol | 5ea1817 | 2018-02-20 16:48:15 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012-2017 sysmocom - s.f.m.c. GmbH |
| 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 General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 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 General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | * |
| 18 | */ |
| 19 | |
| 20 | #include <string.h> |
| 21 | #include <stdint.h> |
| 22 | #include <inttypes.h> |
| 23 | #include <netinet/in.h> |
| 24 | #include <arpa/inet.h> |
| 25 | |
| 26 | #include <osmocom/core/talloc.h> |
| 27 | #include <osmocom/core/utils.h> |
| 28 | #include <osmocom/core/rate_ctr.h> |
| 29 | |
| 30 | #include <osmocom/vty/command.h> |
| 31 | #include <osmocom/vty/vty.h> |
| 32 | #include <osmocom/vty/misc.h> |
| 33 | |
| 34 | #include "trx_vty.h" |
| 35 | #include "../config.h" |
| 36 | |
| 37 | static struct trx_ctx* g_trx_ctx; |
| 38 | |
Pau Espin Pedrol | a3ab8c2 | 2018-02-21 15:41:03 +0100 | [diff] [blame] | 39 | static const struct value_string clock_ref_names[] = { |
| 40 | { REF_INTERNAL, "internal" }, |
| 41 | { REF_EXTERNAL, "external" }, |
Pau Espin Pedrol | aae403f | 2018-08-27 16:50:19 +0200 | [diff] [blame] | 42 | { REF_GPS, "gpsdo" }, |
Pau Espin Pedrol | a3ab8c2 | 2018-02-21 15:41:03 +0100 | [diff] [blame] | 43 | { 0, NULL } |
| 44 | }; |
| 45 | |
| 46 | static const struct value_string filler_names[] = { |
| 47 | { FILLER_DUMMY, "Dummy bursts" }, |
| 48 | { FILLER_ZERO, "Disabled" }, |
| 49 | { FILLER_NORM_RAND, "Normal bursts with random payload" }, |
| 50 | { FILLER_EDGE_RAND, "EDGE bursts with random payload" }, |
| 51 | { FILLER_ACCESS_RAND, "Access bursts with random payload" }, |
| 52 | { 0, NULL } |
| 53 | }; |
| 54 | |
Pau Espin Pedrol | 5ea1817 | 2018-02-20 16:48:15 +0100 | [diff] [blame] | 55 | struct trx_ctx *trx_from_vty(struct vty *v) |
| 56 | { |
| 57 | /* It can't hurt to force callers to continue to pass the vty instance |
| 58 | * to this function, in case we'd like to retrieve the global |
| 59 | * trx instance from the vty at some point in the future. But |
| 60 | * until then, just return the global pointer, which should have been |
| 61 | * initialized by trx_vty_init(). |
| 62 | */ |
| 63 | OSMO_ASSERT(g_trx_ctx); |
| 64 | return g_trx_ctx; |
| 65 | } |
| 66 | |
| 67 | enum trx_vty_node { |
| 68 | TRX_NODE = _LAST_OSMOVTY_NODE + 1, |
Pau Espin Pedrol | a3ab8c2 | 2018-02-21 15:41:03 +0100 | [diff] [blame] | 69 | CHAN_NODE, |
Pau Espin Pedrol | 5ea1817 | 2018-02-20 16:48:15 +0100 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | static struct cmd_node trx_node = { |
| 73 | TRX_NODE, |
| 74 | "%s(config-trx)# ", |
| 75 | 1, |
| 76 | }; |
| 77 | |
Pau Espin Pedrol | a3ab8c2 | 2018-02-21 15:41:03 +0100 | [diff] [blame] | 78 | static struct cmd_node chan_node = { |
| 79 | CHAN_NODE, |
| 80 | "%s(config-trx-chan)# ", |
| 81 | 1, |
| 82 | }; |
| 83 | |
Pau Espin Pedrol | 5ea1817 | 2018-02-20 16:48:15 +0100 | [diff] [blame] | 84 | DEFUN(cfg_trx, cfg_trx_cmd, |
| 85 | "trx", |
| 86 | "Configure the TRX\n") |
| 87 | { |
| 88 | struct trx_ctx *trx = trx_from_vty(vty); |
| 89 | |
| 90 | if (!trx) |
| 91 | return CMD_WARNING; |
| 92 | |
| 93 | vty->node = TRX_NODE; |
| 94 | |
| 95 | return CMD_SUCCESS; |
| 96 | } |
| 97 | |
| 98 | DEFUN(cfg_bind_ip, cfg_bind_ip_cmd, |
| 99 | "bind-ip A.B.C.D", |
| 100 | "Set the IP address for the local bind\n" |
| 101 | "IPv4 Address\n") |
| 102 | { |
| 103 | struct trx_ctx *trx = trx_from_vty(vty); |
| 104 | |
| 105 | osmo_talloc_replace_string(trx, &trx->cfg.bind_addr, argv[0]); |
| 106 | |
| 107 | return CMD_SUCCESS; |
| 108 | } |
| 109 | |
Pau Espin Pedrol | a3ab8c2 | 2018-02-21 15:41:03 +0100 | [diff] [blame] | 110 | DEFUN(cfg_remote_ip, cfg_remote_ip_cmd, |
| 111 | "remote-ip A.B.C.D", |
| 112 | "Set the IP address for the remote BTS\n" |
| 113 | "IPv4 Address\n") |
| 114 | { |
| 115 | struct trx_ctx *trx = trx_from_vty(vty); |
| 116 | |
| 117 | osmo_talloc_replace_string(trx, &trx->cfg.remote_addr, argv[0]); |
| 118 | |
| 119 | return CMD_SUCCESS; |
| 120 | } |
| 121 | |
| 122 | DEFUN(cfg_base_port, cfg_base_port_cmd, |
| 123 | "base-port <1-65535>", |
| 124 | "Set the TRX Base Port\n" |
| 125 | "TRX Base Port\n") |
| 126 | { |
| 127 | struct trx_ctx *trx = trx_from_vty(vty); |
| 128 | |
| 129 | trx->cfg.base_port = atoi(argv[0]); |
| 130 | |
| 131 | return CMD_SUCCESS; |
| 132 | } |
| 133 | |
| 134 | DEFUN(cfg_dev_args, cfg_dev_args_cmd, |
| 135 | "dev-args DESC", |
| 136 | "Set the device-specific arguments to pass to the device\n" |
| 137 | "Device-specific arguments\n") |
| 138 | { |
| 139 | struct trx_ctx *trx = trx_from_vty(vty); |
| 140 | |
| 141 | osmo_talloc_replace_string(trx, &trx->cfg.dev_args, argv[0]); |
| 142 | |
| 143 | return CMD_SUCCESS; |
| 144 | } |
| 145 | |
| 146 | DEFUN(cfg_tx_sps, cfg_tx_sps_cmd, |
| 147 | "tx-sps (1|4)", |
| 148 | "Set the Tx Samples-per-Symbol\n" |
| 149 | "Tx Samples-per-Symbol\n") |
| 150 | { |
| 151 | struct trx_ctx *trx = trx_from_vty(vty); |
| 152 | |
| 153 | trx->cfg.tx_sps = atoi(argv[0]); |
| 154 | |
| 155 | return CMD_SUCCESS; |
| 156 | } |
| 157 | |
| 158 | DEFUN(cfg_rx_sps, cfg_rx_sps_cmd, |
| 159 | "rx-sps (1|4)", |
| 160 | "Set the Rx Samples-per-Symbol\n" |
| 161 | "Rx Samples-per-Symbol\n") |
| 162 | { |
| 163 | struct trx_ctx *trx = trx_from_vty(vty); |
| 164 | |
| 165 | trx->cfg.rx_sps = atoi(argv[0]); |
| 166 | |
| 167 | return CMD_SUCCESS; |
| 168 | } |
| 169 | |
| 170 | DEFUN(cfg_test_rtsc, cfg_test_rtsc_cmd, |
| 171 | "test rtsc <0-7>", |
| 172 | "Set the Random Normal Burst test mode with TSC\n" |
| 173 | "TSC\n") |
| 174 | { |
| 175 | struct trx_ctx *trx = trx_from_vty(vty); |
| 176 | |
| 177 | if (trx->cfg.rach_delay_set) { |
| 178 | vty_out(vty, "rach-delay and rtsc options are mutual-exclusive%s", |
| 179 | VTY_NEWLINE); |
| 180 | return CMD_WARNING; |
| 181 | } |
| 182 | |
| 183 | trx->cfg.rtsc_set = true; |
| 184 | trx->cfg.rtsc = atoi(argv[0]); |
| 185 | if (!trx->cfg.egprs) /* Don't override egprs which sets different filler */ |
| 186 | trx->cfg.filler = FILLER_NORM_RAND; |
| 187 | |
| 188 | return CMD_SUCCESS; |
| 189 | } |
| 190 | |
| 191 | DEFUN(cfg_test_rach_delay, cfg_test_rach_delay_cmd, |
| 192 | "test rach-delay <0-68>", |
| 193 | "Set the Random Access Burst test mode with delay\n" |
| 194 | "RACH delay\n") |
| 195 | { |
| 196 | struct trx_ctx *trx = trx_from_vty(vty); |
| 197 | |
| 198 | if (trx->cfg.rtsc_set) { |
| 199 | vty_out(vty, "rach-delay and rtsc options are mutual-exclusive%s", |
| 200 | VTY_NEWLINE); |
| 201 | return CMD_WARNING; |
| 202 | } |
| 203 | |
| 204 | if (trx->cfg.egprs) { |
| 205 | vty_out(vty, "rach-delay and egprs options are mutual-exclusive%s", |
| 206 | VTY_NEWLINE); |
| 207 | return CMD_WARNING; |
| 208 | } |
| 209 | |
| 210 | trx->cfg.rach_delay_set = true; |
| 211 | trx->cfg.rach_delay = atoi(argv[0]); |
| 212 | trx->cfg.filler = FILLER_ACCESS_RAND; |
| 213 | |
| 214 | return CMD_SUCCESS; |
| 215 | } |
| 216 | |
| 217 | DEFUN(cfg_clock_ref, cfg_clock_ref_cmd, |
| 218 | "clock-ref (internal|external|gpsdo)", |
| 219 | "Set the Reference Clock\n" |
| 220 | "Enable internal referece (default)\n" |
| 221 | "Enable external 10 MHz reference\n" |
| 222 | "Enable GPSDO reference\n") |
| 223 | { |
| 224 | struct trx_ctx *trx = trx_from_vty(vty); |
| 225 | |
| 226 | trx->cfg.clock_ref = get_string_value(clock_ref_names, argv[0]); |
| 227 | |
| 228 | return CMD_SUCCESS; |
| 229 | } |
| 230 | |
| 231 | DEFUN(cfg_multi_arfcn, cfg_multi_arfcn_cmd, |
| 232 | "multi-arfcn (disable|enable)", |
| 233 | "Enable multi-ARFCN transceiver (default=disable)\n") |
| 234 | { |
| 235 | struct trx_ctx *trx = trx_from_vty(vty); |
| 236 | |
| 237 | if (strcmp("disable", argv[0]) == 0) { |
| 238 | trx->cfg.multi_arfcn = false; |
| 239 | } else if (strcmp("enable", argv[0]) == 0) { |
| 240 | trx->cfg.multi_arfcn = true; |
| 241 | } else { |
| 242 | return CMD_WARNING; |
| 243 | } |
| 244 | |
| 245 | return CMD_SUCCESS; |
| 246 | } |
| 247 | |
| 248 | DEFUN(cfg_offset, cfg_offset_cmd, |
| 249 | "offset FLOAT", |
| 250 | "Set the baseband frequency offset (default=0, auto)\n" |
| 251 | "Baseband Frequency Offset\n") |
| 252 | { |
| 253 | struct trx_ctx *trx = trx_from_vty(vty); |
| 254 | |
| 255 | trx->cfg.offset = atof(argv[0]); |
| 256 | |
| 257 | return CMD_SUCCESS; |
| 258 | } |
| 259 | |
| 260 | DEFUN(cfg_rssi_offset, cfg_rssi_offset_cmd, |
| 261 | "rssi-offset FLOAT", |
| 262 | "Set the RSSI to dBm offset in dB (default=0)\n" |
| 263 | "RSSI to dBm offset in dB\n") |
| 264 | { |
| 265 | struct trx_ctx *trx = trx_from_vty(vty); |
| 266 | |
| 267 | trx->cfg.rssi_offset = atof(argv[0]); |
| 268 | |
| 269 | return CMD_SUCCESS; |
| 270 | } |
| 271 | |
| 272 | DEFUN(cfg_swap_channels, cfg_swap_channels_cmd, |
| 273 | "swap-channels (disable|enable)", |
| 274 | "Swap channels (default=disable)\n") |
| 275 | { |
| 276 | struct trx_ctx *trx = trx_from_vty(vty); |
| 277 | |
| 278 | if (strcmp("disable", argv[0]) == 0) { |
| 279 | trx->cfg.swap_channels = false; |
| 280 | } else if (strcmp("enable", argv[0]) == 0) { |
| 281 | trx->cfg.swap_channels = true; |
| 282 | } else { |
| 283 | return CMD_WARNING; |
| 284 | } |
| 285 | |
| 286 | return CMD_SUCCESS; |
| 287 | } |
| 288 | |
| 289 | DEFUN(cfg_egprs, cfg_egprs_cmd, |
| 290 | "egprs (disable|enable)", |
| 291 | "Enable EDGE receiver (default=disable)\n") |
| 292 | { |
| 293 | struct trx_ctx *trx = trx_from_vty(vty); |
| 294 | |
| 295 | if (strcmp("disable", argv[0]) == 0) { |
| 296 | trx->cfg.egprs = false; |
| 297 | } else if (strcmp("enable", argv[0]) == 0) { |
| 298 | trx->cfg.egprs = true; |
| 299 | trx->cfg.filler = FILLER_EDGE_RAND; |
| 300 | } else { |
| 301 | return CMD_WARNING; |
| 302 | } |
| 303 | |
| 304 | return CMD_SUCCESS; |
| 305 | } |
| 306 | |
Vadim Yanitskiy | a8b3565 | 2018-10-22 02:52:18 +0200 | [diff] [blame^] | 307 | DEFUN(cfg_ext_rach, cfg_ext_rach_cmd, |
| 308 | "ext-rach (disable|enable)", |
| 309 | "Enable extended (11-bit) RACH (default=disable)\n") |
| 310 | { |
| 311 | struct trx_ctx *trx = trx_from_vty(vty); |
| 312 | |
| 313 | if (strcmp("disable", argv[0]) == 0) |
| 314 | trx->cfg.ext_rach = false; |
| 315 | |
| 316 | if (strcmp("enable", argv[0]) == 0) |
| 317 | trx->cfg.ext_rach = true; |
| 318 | |
| 319 | return CMD_SUCCESS; |
| 320 | } |
| 321 | |
Pau Espin Pedrol | a3ab8c2 | 2018-02-21 15:41:03 +0100 | [diff] [blame] | 322 | DEFUN(cfg_rt_prio, cfg_rt_prio_cmd, |
| 323 | "rt-prio <1-32>", |
| 324 | "Set the SCHED_RR real-time priority\n" |
| 325 | "Real time priority\n") |
| 326 | { |
| 327 | struct trx_ctx *trx = trx_from_vty(vty); |
| 328 | |
| 329 | trx->cfg.sched_rr = atoi(argv[0]); |
| 330 | |
| 331 | return CMD_SUCCESS; |
| 332 | } |
| 333 | |
| 334 | DEFUN(cfg_filler, cfg_filler_cmd, |
| 335 | "filler dummy", |
| 336 | "Enable C0 filler table\n" |
| 337 | "Dummy method\n") |
| 338 | { |
| 339 | struct trx_ctx *trx = trx_from_vty(vty); |
| 340 | |
| 341 | trx->cfg.filler = FILLER_DUMMY; |
| 342 | |
| 343 | return CMD_SUCCESS; |
| 344 | } |
| 345 | |
| 346 | DEFUN(cfg_chan, cfg_chan_cmd, |
| 347 | "chan <0-100>", |
| 348 | "Select a channel to configure\n" |
| 349 | "Channel index\n") |
| 350 | { |
| 351 | struct trx_ctx *trx = trx_from_vty(vty); |
| 352 | int idx = atoi(argv[0]); |
| 353 | |
| 354 | if (idx >= TRX_CHAN_MAX) { |
| 355 | vty_out(vty, "Chan list full.%s", VTY_NEWLINE); |
| 356 | return CMD_WARNING; |
| 357 | } |
| 358 | if (trx->cfg.num_chans < idx) { /* Unexisting or creating non-consecutive */ |
| 359 | vty_out(vty, "Non-existent or non-consecutive chan %d.%s", |
| 360 | idx, VTY_NEWLINE); |
| 361 | return CMD_WARNING; |
| 362 | } else if (trx->cfg.num_chans == idx) { /* creating it */ |
| 363 | trx->cfg.num_chans++; |
| 364 | trx->cfg.chans[idx].trx = trx; |
| 365 | trx->cfg.chans[idx].idx = idx; |
| 366 | } |
| 367 | |
| 368 | vty->node = CHAN_NODE; |
| 369 | vty->index = &trx->cfg.chans[idx]; |
| 370 | |
| 371 | return CMD_SUCCESS; |
| 372 | } |
| 373 | |
| 374 | DEFUN(cfg_chan_rx_path, cfg_chan_rx_path_cmd, |
| 375 | "rx-path NAME", |
| 376 | "Set the Rx Path\n" |
| 377 | "Rx Path name\n") |
| 378 | { |
| 379 | struct trx_chan *chan = vty->index; |
| 380 | |
| 381 | osmo_talloc_replace_string(chan->trx, &chan->rx_path, argv[0]); |
| 382 | |
| 383 | return CMD_SUCCESS; |
| 384 | } |
| 385 | |
| 386 | DEFUN(cfg_chan_tx_path, cfg_chan_tx_path_cmd, |
| 387 | "tx-path NAME", |
| 388 | "Set the Tx Path\n" |
| 389 | "Tx Path name\n") |
| 390 | { |
| 391 | struct trx_chan *chan = vty->index; |
| 392 | |
| 393 | osmo_talloc_replace_string(chan->trx, &chan->tx_path, argv[0]); |
| 394 | |
| 395 | return CMD_SUCCESS; |
| 396 | } |
| 397 | |
| 398 | static int dummy_config_write(struct vty *v) |
| 399 | { |
| 400 | return CMD_SUCCESS; |
| 401 | } |
| 402 | |
Pau Espin Pedrol | 5ea1817 | 2018-02-20 16:48:15 +0100 | [diff] [blame] | 403 | static int config_write_trx(struct vty *vty) |
| 404 | { |
Pau Espin Pedrol | a3ab8c2 | 2018-02-21 15:41:03 +0100 | [diff] [blame] | 405 | struct trx_chan *chan; |
| 406 | int i; |
Pau Espin Pedrol | 5ea1817 | 2018-02-20 16:48:15 +0100 | [diff] [blame] | 407 | struct trx_ctx *trx = trx_from_vty(vty); |
| 408 | |
| 409 | vty_out(vty, "trx%s", VTY_NEWLINE); |
| 410 | if (trx->cfg.bind_addr) |
| 411 | vty_out(vty, " bind-ip %s%s", trx->cfg.bind_addr, VTY_NEWLINE); |
Pau Espin Pedrol | a3ab8c2 | 2018-02-21 15:41:03 +0100 | [diff] [blame] | 412 | if (trx->cfg.remote_addr) |
| 413 | vty_out(vty, " remote-ip %s%s", trx->cfg.remote_addr, VTY_NEWLINE); |
| 414 | if (trx->cfg.base_port != DEFAULT_TRX_PORT) |
| 415 | vty_out(vty, " base-port %u%s", trx->cfg.base_port, VTY_NEWLINE); |
| 416 | if (trx->cfg.dev_args) |
| 417 | vty_out(vty, " dev-args %s%s", trx->cfg.dev_args, VTY_NEWLINE); |
| 418 | if (trx->cfg.tx_sps != DEFAULT_TX_SPS) |
| 419 | vty_out(vty, " tx-sps %u%s", trx->cfg.tx_sps, VTY_NEWLINE); |
| 420 | if (trx->cfg.rx_sps != DEFAULT_RX_SPS) |
| 421 | vty_out(vty, " rx-sps %u%s", trx->cfg.rx_sps, VTY_NEWLINE); |
| 422 | if (trx->cfg.rtsc_set) |
| 423 | vty_out(vty, " test rtsc %u%s", trx->cfg.rtsc, VTY_NEWLINE); |
| 424 | if (trx->cfg.rach_delay_set) |
| 425 | vty_out(vty, " test rach-delay %u%s", trx->cfg.rach_delay, VTY_NEWLINE); |
| 426 | if (trx->cfg.clock_ref != REF_INTERNAL) |
| 427 | vty_out(vty, " clock-ref %s%s", get_value_string(clock_ref_names, trx->cfg.clock_ref), VTY_NEWLINE); |
| 428 | vty_out(vty, " multi-arfcn %s%s", trx->cfg.multi_arfcn ? "enable" : "disable", VTY_NEWLINE); |
| 429 | if (trx->cfg.offset != 0) |
| 430 | vty_out(vty, " offset %f%s", trx->cfg.offset, VTY_NEWLINE); |
| 431 | if (trx->cfg.rssi_offset != 0) |
| 432 | vty_out(vty, " rssi-offset %f%s", trx->cfg.rssi_offset, VTY_NEWLINE); |
| 433 | vty_out(vty, " swap-channels %s%s", trx->cfg.swap_channels ? "enable" : "disable", VTY_NEWLINE); |
| 434 | vty_out(vty, " egprs %s%s", trx->cfg.egprs ? "enable" : "disable", VTY_NEWLINE); |
Vadim Yanitskiy | a8b3565 | 2018-10-22 02:52:18 +0200 | [diff] [blame^] | 435 | vty_out(vty, " ext-rach %s%s", trx->cfg.ext_rach ? "enable" : "disable", VTY_NEWLINE); |
Pau Espin Pedrol | a3ab8c2 | 2018-02-21 15:41:03 +0100 | [diff] [blame] | 436 | if (trx->cfg.sched_rr != 0) |
| 437 | vty_out(vty, " rt-prio %u%s", trx->cfg.sched_rr, VTY_NEWLINE); |
| 438 | |
| 439 | for (i = 0; i < trx->cfg.num_chans; i++) { |
| 440 | chan = &trx->cfg.chans[i]; |
| 441 | vty_out(vty, " chan %u%s", chan->idx, VTY_NEWLINE); |
| 442 | if (chan->rx_path) |
Harald Welte | 03b3c30 | 2018-07-31 15:48:18 +0200 | [diff] [blame] | 443 | vty_out(vty, " rx-path %s%s", chan->rx_path, VTY_NEWLINE); |
Pau Espin Pedrol | a3ab8c2 | 2018-02-21 15:41:03 +0100 | [diff] [blame] | 444 | if (chan->tx_path) |
Harald Welte | 03b3c30 | 2018-07-31 15:48:18 +0200 | [diff] [blame] | 445 | vty_out(vty, " tx-path %s%s", chan->tx_path, VTY_NEWLINE); |
Pau Espin Pedrol | a3ab8c2 | 2018-02-21 15:41:03 +0100 | [diff] [blame] | 446 | } |
Pau Espin Pedrol | 5ea1817 | 2018-02-20 16:48:15 +0100 | [diff] [blame] | 447 | |
| 448 | return CMD_SUCCESS; |
| 449 | } |
| 450 | |
Pau Espin Pedrol | a3ab8c2 | 2018-02-21 15:41:03 +0100 | [diff] [blame] | 451 | static void trx_dump_vty(struct vty *vty, struct trx_ctx *trx) |
| 452 | { |
| 453 | struct trx_chan *chan; |
| 454 | int i; |
| 455 | vty_out(vty, "TRX Config:%s", VTY_NEWLINE); |
| 456 | vty_out(vty, " Local IP: %s%s", trx->cfg.bind_addr, VTY_NEWLINE); |
| 457 | vty_out(vty, " Remote IP: %s%s", trx->cfg.remote_addr, VTY_NEWLINE); |
| 458 | vty_out(vty, " TRX Base Port: %u%s", trx->cfg.base_port, VTY_NEWLINE); |
| 459 | vty_out(vty, " Device args: %s%s", trx->cfg.dev_args, VTY_NEWLINE); |
| 460 | vty_out(vty, " Tx Samples-per-Symbol: %u%s", trx->cfg.tx_sps, VTY_NEWLINE); |
| 461 | vty_out(vty, " Rx Samples-per-Symbol: %u%s", trx->cfg.rx_sps, VTY_NEWLINE); |
| 462 | vty_out(vty, " Test Mode: TSC: %u (%s)%s", trx->cfg.rtsc, |
| 463 | trx->cfg.rtsc_set ? "Enabled" : "Disabled", VTY_NEWLINE); |
| 464 | vty_out(vty, " Test Mode: RACH Delay: %u (%s)%s", trx->cfg.rach_delay, |
| 465 | trx->cfg.rach_delay_set ? "Enabled" : "Disabled", VTY_NEWLINE); |
| 466 | vty_out(vty, " C0 Filler Table: %s%s", get_value_string(filler_names, trx->cfg.filler), VTY_NEWLINE); |
| 467 | vty_out(vty, " Clock Reference: %s%s", get_value_string(clock_ref_names, trx->cfg.clock_ref), VTY_NEWLINE); |
| 468 | vty_out(vty, " Multi-Carrier: %s%s", trx->cfg.multi_arfcn ? "Enabled" : "Disabled", VTY_NEWLINE); |
| 469 | vty_out(vty, " Tuning offset: %f%s", trx->cfg.offset, VTY_NEWLINE); |
| 470 | vty_out(vty, " RSSI to dBm offset: %f%s", trx->cfg.rssi_offset, VTY_NEWLINE); |
| 471 | vty_out(vty, " Swap channels: %s%s", trx->cfg.swap_channels ? "Enabled" : "Disabled", VTY_NEWLINE); |
| 472 | vty_out(vty, " EDGE support: %s%s", trx->cfg.egprs ? "Enabled" : "Disabled", VTY_NEWLINE); |
Vadim Yanitskiy | a8b3565 | 2018-10-22 02:52:18 +0200 | [diff] [blame^] | 473 | vty_out(vty, " Extended RACH support: %s%s", trx->cfg.ext_rach ? "Enabled" : "Disabled", VTY_NEWLINE); |
Pau Espin Pedrol | a3ab8c2 | 2018-02-21 15:41:03 +0100 | [diff] [blame] | 474 | vty_out(vty, " Real Time Priority: %u (%s)%s", trx->cfg.sched_rr, |
| 475 | trx->cfg.sched_rr ? "Enabled" : "Disabled", VTY_NEWLINE); |
| 476 | vty_out(vty, " Channels: %u%s", trx->cfg.num_chans, VTY_NEWLINE); |
| 477 | for (i = 0; i < trx->cfg.num_chans; i++) { |
| 478 | chan = &trx->cfg.chans[i]; |
| 479 | vty_out(vty, " Channel %u:%s", chan->idx, VTY_NEWLINE); |
| 480 | if (chan->rx_path) |
| 481 | vty_out(vty, " Rx Path: %s%s", chan->rx_path, VTY_NEWLINE); |
| 482 | if (chan->tx_path) |
| 483 | vty_out(vty, " Tx Path: %s%s", chan->tx_path, VTY_NEWLINE); |
| 484 | } |
| 485 | } |
| 486 | |
Pau Espin Pedrol | 5ea1817 | 2018-02-20 16:48:15 +0100 | [diff] [blame] | 487 | DEFUN(show_trx, show_trx_cmd, |
| 488 | "show trx", |
| 489 | SHOW_STR "Display information on the TRX\n") |
| 490 | { |
| 491 | struct trx_ctx *trx = trx_from_vty(vty); |
| 492 | |
Pau Espin Pedrol | a3ab8c2 | 2018-02-21 15:41:03 +0100 | [diff] [blame] | 493 | trx_dump_vty(vty, trx); |
Pau Espin Pedrol | 5ea1817 | 2018-02-20 16:48:15 +0100 | [diff] [blame] | 494 | |
| 495 | return CMD_SUCCESS; |
| 496 | } |
| 497 | |
| 498 | static int trx_vty_is_config_node(struct vty *vty, int node) |
| 499 | { |
| 500 | switch (node) { |
| 501 | case TRX_NODE: |
Pau Espin Pedrol | a3ab8c2 | 2018-02-21 15:41:03 +0100 | [diff] [blame] | 502 | case CHAN_NODE: |
Pau Espin Pedrol | 5ea1817 | 2018-02-20 16:48:15 +0100 | [diff] [blame] | 503 | return 1; |
| 504 | default: |
| 505 | return 0; |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | static int trx_vty_go_parent(struct vty *vty) |
| 510 | { |
| 511 | switch (vty->node) { |
| 512 | case TRX_NODE: |
| 513 | vty->node = CONFIG_NODE; |
| 514 | vty->index = NULL; |
| 515 | vty->index_sub = NULL; |
| 516 | break; |
Pau Espin Pedrol | a3ab8c2 | 2018-02-21 15:41:03 +0100 | [diff] [blame] | 517 | case CHAN_NODE: |
| 518 | vty->node = TRX_NODE; |
| 519 | vty->index = NULL; |
| 520 | vty->index_sub = NULL; |
| 521 | break; |
Pau Espin Pedrol | 5ea1817 | 2018-02-20 16:48:15 +0100 | [diff] [blame] | 522 | default: |
Vadim Yanitskiy | 01eea0a | 2018-05-09 15:19:48 +0700 | [diff] [blame] | 523 | vty->node = CONFIG_NODE; |
| 524 | vty->index = NULL; |
| 525 | vty->index_sub = NULL; |
Pau Espin Pedrol | 5ea1817 | 2018-02-20 16:48:15 +0100 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | return vty->node; |
| 529 | } |
| 530 | |
| 531 | static const char trx_copyright[] = |
| 532 | "Copyright (C) 2007-2014 Free Software Foundation, Inc.\r\n" |
| 533 | "Copyright (C) 2013 Thomas Tsou <tom@tsou.cc>\r\n" |
| 534 | "Copyright (C) 2015 Ettus Research LLC\r\n" |
| 535 | "Copyright (C) 2017-2018 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>\r\n" |
| 536 | "License AGPLv3+: GNU AGPL version 3 or later <http://gnu.org/licenses/agpl-3.0.html>\r\n" |
| 537 | "This is free software: you are free to change and redistribute it.\r\n" |
| 538 | "There is NO WARRANTY, to the extent permitted by law.\r\n"; |
| 539 | |
| 540 | struct vty_app_info g_vty_info = { |
| 541 | .name = "OsmoTRX", |
| 542 | .version = PACKAGE_VERSION, |
| 543 | .copyright = trx_copyright, |
| 544 | .go_parent_cb = trx_vty_go_parent, |
| 545 | .is_config_node = trx_vty_is_config_node, |
| 546 | }; |
| 547 | |
Pau Espin Pedrol | a3ab8c2 | 2018-02-21 15:41:03 +0100 | [diff] [blame] | 548 | struct trx_ctx *vty_trx_ctx_alloc(void *talloc_ctx) |
| 549 | { |
| 550 | struct trx_ctx * trx = talloc_zero(talloc_ctx, struct trx_ctx); |
| 551 | |
| 552 | trx->cfg.bind_addr = talloc_strdup(trx, DEFAULT_TRX_IP); |
| 553 | trx->cfg.remote_addr = talloc_strdup(trx, DEFAULT_TRX_IP); |
| 554 | trx->cfg.base_port = DEFAULT_TRX_PORT; |
| 555 | trx->cfg.tx_sps = DEFAULT_TX_SPS; |
| 556 | trx->cfg.rx_sps = DEFAULT_RX_SPS; |
| 557 | trx->cfg.filler = FILLER_ZERO; |
| 558 | |
| 559 | return trx; |
| 560 | } |
| 561 | |
Pau Espin Pedrol | 5ea1817 | 2018-02-20 16:48:15 +0100 | [diff] [blame] | 562 | int trx_vty_init(struct trx_ctx* trx) |
| 563 | { |
| 564 | g_trx_ctx = trx; |
| 565 | install_element_ve(&show_trx_cmd); |
| 566 | |
| 567 | install_element(CONFIG_NODE, &cfg_trx_cmd); |
| 568 | |
| 569 | install_node(&trx_node, config_write_trx); |
| 570 | install_element(TRX_NODE, &cfg_bind_ip_cmd); |
Pau Espin Pedrol | a3ab8c2 | 2018-02-21 15:41:03 +0100 | [diff] [blame] | 571 | install_element(TRX_NODE, &cfg_remote_ip_cmd); |
| 572 | install_element(TRX_NODE, &cfg_base_port_cmd); |
| 573 | install_element(TRX_NODE, &cfg_dev_args_cmd); |
| 574 | install_element(TRX_NODE, &cfg_tx_sps_cmd); |
| 575 | install_element(TRX_NODE, &cfg_rx_sps_cmd); |
| 576 | install_element(TRX_NODE, &cfg_test_rtsc_cmd); |
| 577 | install_element(TRX_NODE, &cfg_test_rach_delay_cmd); |
| 578 | install_element(TRX_NODE, &cfg_clock_ref_cmd); |
| 579 | install_element(TRX_NODE, &cfg_multi_arfcn_cmd); |
| 580 | install_element(TRX_NODE, &cfg_offset_cmd); |
| 581 | install_element(TRX_NODE, &cfg_rssi_offset_cmd); |
| 582 | install_element(TRX_NODE, &cfg_swap_channels_cmd); |
| 583 | install_element(TRX_NODE, &cfg_egprs_cmd); |
Vadim Yanitskiy | a8b3565 | 2018-10-22 02:52:18 +0200 | [diff] [blame^] | 584 | install_element(TRX_NODE, &cfg_ext_rach_cmd); |
Pau Espin Pedrol | a3ab8c2 | 2018-02-21 15:41:03 +0100 | [diff] [blame] | 585 | install_element(TRX_NODE, &cfg_rt_prio_cmd); |
| 586 | install_element(TRX_NODE, &cfg_filler_cmd); |
| 587 | |
| 588 | install_element(TRX_NODE, &cfg_chan_cmd); |
| 589 | install_node(&chan_node, dummy_config_write); |
| 590 | install_element(CHAN_NODE, &cfg_chan_rx_path_cmd); |
| 591 | install_element(CHAN_NODE, &cfg_chan_tx_path_cmd); |
Pau Espin Pedrol | 5ea1817 | 2018-02-20 16:48:15 +0100 | [diff] [blame] | 592 | |
| 593 | return 0; |
| 594 | } |