blob: e184f49722938e05e0f05883fe7d0e943576e235 [file] [log] [blame]
Pau Espin Pedrol5ea18172018-02-20 16:48:15 +01001/*
Pau Espin Pedrole9ce77b2019-06-25 12:29:01 +02002 * Copyright (C) 2018-2019 sysmocom - s.f.m.c. GmbH
Pau Espin Pedrol5ea18172018-02-20 16:48:15 +01003 * All Rights Reserved
4 *
Pau Espin Pedrole9ce77b2019-06-25 12:29:01 +02005 * 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 Pedrol5ea18172018-02-20 16:48:15 +010012 * (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 Pedrole9ce77b2019-06-25 12:29:01 +020017 * GNU Affero General Public License for more details.
Pau Espin Pedrol5ea18172018-02-20 16:48:15 +010018 *
Pau Espin Pedrole9ce77b2019-06-25 12:29:01 +020019 * You should have received a copy of the GNU Affero General Public License
Pau Espin Pedrol5ea18172018-02-20 16:48:15 +010020 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Pau Espin Pedrole9ce77b2019-06-25 12:29:01 +020021 * See the COPYING file in the main directory for details.
Pau Espin Pedrol5ea18172018-02-20 16:48:15 +010022 */
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 Pedrol6a305fe2019-05-24 19:58:20 +020038#include "trx_rate_ctr.h"
Pau Espin Pedrol5ea18172018-02-20 16:48:15 +010039#include "trx_vty.h"
40#include "../config.h"
41
42static struct trx_ctx* g_trx_ctx;
43
Pau Espin Pedrola3ab8c22018-02-21 15:41:03 +010044static const struct value_string clock_ref_names[] = {
45 { REF_INTERNAL, "internal" },
46 { REF_EXTERNAL, "external" },
Pau Espin Pedrolaae403f2018-08-27 16:50:19 +020047 { REF_GPS, "gpsdo" },
Pau Espin Pedrola3ab8c22018-02-21 15:41:03 +010048 { 0, NULL }
49};
50
51static 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 Pedrol5ea18172018-02-20 16:48:15 +010060struct 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
72enum trx_vty_node {
73 TRX_NODE = _LAST_OSMOVTY_NODE + 1,
Pau Espin Pedrola3ab8c22018-02-21 15:41:03 +010074 CHAN_NODE,
Pau Espin Pedrol5ea18172018-02-20 16:48:15 +010075};
76
77static struct cmd_node trx_node = {
78 TRX_NODE,
79 "%s(config-trx)# ",
80 1,
81};
82
Pau Espin Pedrola3ab8c22018-02-21 15:41:03 +010083static struct cmd_node chan_node = {
84 CHAN_NODE,
85 "%s(config-trx-chan)# ",
86 1,
87};
88
Pau Espin Pedrol5ea18172018-02-20 16:48:15 +010089DEFUN(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
103DEFUN(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 Pedrola3ab8c22018-02-21 15:41:03 +0100115DEFUN(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
127DEFUN(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
139DEFUN(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
151DEFUN(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
163DEFUN(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
175DEFUN(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
196DEFUN(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
222DEFUN(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
236DEFUN(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 Tsoud2800452019-04-01 07:55:48 +0700244 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 Pedrola3ab8c22018-02-21 15:41:03 +0100250 return CMD_WARNING;
251 }
252
Tom Tsoud2800452019-04-01 07:55:48 +0700253 trx->cfg.multi_arfcn = true;
Pau Espin Pedrola3ab8c22018-02-21 15:41:03 +0100254 return CMD_SUCCESS;
255}
256
257DEFUN(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
269DEFUN(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
281DEFUN(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
298DEFUN(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 Yanitskiya8b35652018-10-22 02:52:18 +0200316DEFUN(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 Pedrola3ab8c22018-02-21 15:41:03 +0100331DEFUN(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 Wildac0487e2019-06-17 13:02:44 +0200343DEFUN(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 Pedrola3ab8c22018-02-21 15:41:03 +0100355DEFUN(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 Pedrol6a305fe2019-05-24 19:58:20 +0200367static 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
377static 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
403DEFUN(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
434DEFUN(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 Pedrola3ab8c22018-02-21 15:41:03 +0100468DEFUN(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 Tsoud2800452019-04-01 07:55:48 +0700479 } 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 Pedrola3ab8c22018-02-21 15:41:03 +0100483 }
Tom Tsoud2800452019-04-01 07:55:48 +0700484
Pau Espin Pedrola3ab8c22018-02-21 15:41:03 +0100485 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
501DEFUN(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
513DEFUN(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
525static int dummy_config_write(struct vty *v)
526{
527 return CMD_SUCCESS;
528}
529
Pau Espin Pedrol5ea18172018-02-20 16:48:15 +0100530static int config_write_trx(struct vty *vty)
531{
Pau Espin Pedrola3ab8c22018-02-21 15:41:03 +0100532 struct trx_chan *chan;
533 int i;
Pau Espin Pedrol5ea18172018-02-20 16:48:15 +0100534 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 Pedrola3ab8c22018-02-21 15:41:03 +0100539 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 Yanitskiya8b35652018-10-22 02:52:18 +0200562 vty_out(vty, " ext-rach %s%s", trx->cfg.ext_rach ? "enable" : "disable", VTY_NEWLINE);
Pau Espin Pedrola3ab8c22018-02-21 15:41:03 +0100563 if (trx->cfg.sched_rr != 0)
564 vty_out(vty, " rt-prio %u%s", trx->cfg.sched_rr, VTY_NEWLINE);
Eric Wildac0487e2019-06-17 13:02:44 +0200565 if (trx->cfg.stack_size != 0)
566 vty_out(vty, " stack-size %u%s", trx->cfg.stack_size, VTY_NEWLINE);
Pau Espin Pedrol6a305fe2019-05-24 19:58:20 +0200567 trx_rate_ctr_threshold_write_config(vty, " ");
Pau Espin Pedrola3ab8c22018-02-21 15:41:03 +0100568
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 Welte03b3c302018-07-31 15:48:18 +0200573 vty_out(vty, " rx-path %s%s", chan->rx_path, VTY_NEWLINE);
Pau Espin Pedrola3ab8c22018-02-21 15:41:03 +0100574 if (chan->tx_path)
Harald Welte03b3c302018-07-31 15:48:18 +0200575 vty_out(vty, " tx-path %s%s", chan->tx_path, VTY_NEWLINE);
Pau Espin Pedrola3ab8c22018-02-21 15:41:03 +0100576 }
Pau Espin Pedrol5ea18172018-02-20 16:48:15 +0100577
578 return CMD_SUCCESS;
579}
580
Pau Espin Pedrola3ab8c22018-02-21 15:41:03 +0100581static 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 Yanitskiya8b35652018-10-22 02:52:18 +0200603 vty_out(vty, " Extended RACH support: %s%s", trx->cfg.ext_rach ? "Enabled" : "Disabled", VTY_NEWLINE);
Pau Espin Pedrola3ab8c22018-02-21 15:41:03 +0100604 vty_out(vty, " Real Time Priority: %u (%s)%s", trx->cfg.sched_rr,
605 trx->cfg.sched_rr ? "Enabled" : "Disabled", VTY_NEWLINE);
Eric Wildac0487e2019-06-17 13:02:44 +0200606 vty_out(vty, " Stack size per Thread in BYTE (0 = OS default): %u%s", trx->cfg.stack_size, VTY_NEWLINE);
Pau Espin Pedrola3ab8c22018-02-21 15:41:03 +0100607 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 Pedrol5ea18172018-02-20 16:48:15 +0100618DEFUN(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 Pedrola3ab8c22018-02-21 15:41:03 +0100624 trx_dump_vty(vty, trx);
Pau Espin Pedrol5ea18172018-02-20 16:48:15 +0100625
626 return CMD_SUCCESS;
627}
628
629static int trx_vty_is_config_node(struct vty *vty, int node)
630{
631 switch (node) {
632 case TRX_NODE:
Pau Espin Pedrola3ab8c22018-02-21 15:41:03 +0100633 case CHAN_NODE:
Pau Espin Pedrol5ea18172018-02-20 16:48:15 +0100634 return 1;
635 default:
636 return 0;
637 }
638}
639
640static 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 Pedrola3ab8c22018-02-21 15:41:03 +0100648 case CHAN_NODE:
649 vty->node = TRX_NODE;
650 vty->index = NULL;
651 vty->index_sub = NULL;
652 break;
Pau Espin Pedrol5ea18172018-02-20 16:48:15 +0100653 default:
Vadim Yanitskiy01eea0a2018-05-09 15:19:48 +0700654 vty->node = CONFIG_NODE;
655 vty->index = NULL;
656 vty->index_sub = NULL;
Pau Espin Pedrol5ea18172018-02-20 16:48:15 +0100657 }
658
659 return vty->node;
660}
661
662static 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
671struct 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 Pedrola3ab8c22018-02-21 15:41:03 +0100679struct 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 Pedrol5ea18172018-02-20 16:48:15 +0100693int 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 Pedrola3ab8c22018-02-21 15:41:03 +0100702 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 Yanitskiya8b35652018-10-22 02:52:18 +0200715 install_element(TRX_NODE, &cfg_ext_rach_cmd);
Pau Espin Pedrola3ab8c22018-02-21 15:41:03 +0100716 install_element(TRX_NODE, &cfg_rt_prio_cmd);
717 install_element(TRX_NODE, &cfg_filler_cmd);
Pau Espin Pedrol6a305fe2019-05-24 19:58:20 +0200718 install_element(TRX_NODE, &cfg_ctr_error_threshold_cmd);
719 install_element(TRX_NODE, &cfg_no_ctr_error_threshold_cmd);
Eric Wildac0487e2019-06-17 13:02:44 +0200720 install_element(TRX_NODE, &cfg_stack_size_cmd);
Pau Espin Pedrola3ab8c22018-02-21 15:41:03 +0100721
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 Pedrol5ea18172018-02-20 16:48:15 +0100726
727 return 0;
728}