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