Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 Thomas Tsou <tom@tsou.cc> |
| 3 | * |
Pau Espin Pedrol | 21d03d3 | 2019-07-22 12:05:52 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: LGPL-2.1+ |
| 5 | * |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2.1 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | */ |
| 20 | |
| 21 | #ifdef HAVE_CONFIG_H |
| 22 | #include "config.h" |
| 23 | #endif |
| 24 | |
| 25 | #include "Transceiver.h" |
| 26 | #include "radioDevice.h" |
Oliver Smith | 8d9a05c | 2018-12-12 16:03:38 +0100 | [diff] [blame] | 27 | #include "Utils.h" |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 28 | |
| 29 | #include <time.h> |
| 30 | #include <signal.h> |
| 31 | #include <stdlib.h> |
| 32 | #include <unistd.h> |
Oliver Smith | a439fed | 2018-10-23 13:12:17 +0200 | [diff] [blame] | 33 | #include <getopt.h> |
Harald Welte | 81486e0 | 2017-06-29 15:35:22 +0200 | [diff] [blame] | 34 | #include <sched.h> |
Pau Espin Pedrol | 77ce99a | 2018-02-05 13:05:06 +0100 | [diff] [blame] | 35 | #include <vector> |
| 36 | #include <string> |
| 37 | #include <sstream> |
| 38 | #include <iostream> |
Pau Espin Pedrol | 21032b7 | 2019-03-29 19:20:06 +0100 | [diff] [blame] | 39 | #include <sys/signalfd.h> |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 40 | |
| 41 | #include <GSMCommon.h> |
| 42 | #include <Logger.h> |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 43 | |
Philipp Maier | 7e07cf2 | 2017-03-15 18:09:35 +0100 | [diff] [blame] | 44 | extern "C" { |
Pau Espin Pedrol | 3a3b220 | 2018-02-21 20:15:47 +0100 | [diff] [blame] | 45 | #include <osmocom/core/talloc.h> |
Pau Espin Pedrol | ab22f4c | 2018-02-21 20:15:18 +0100 | [diff] [blame] | 46 | #include <osmocom/core/application.h> |
Pau Espin Pedrol | 3a3b220 | 2018-02-21 20:15:47 +0100 | [diff] [blame] | 47 | #include <osmocom/core/msgb.h> |
Pau Espin Pedrol | 5ea1817 | 2018-02-20 16:48:15 +0100 | [diff] [blame] | 48 | #include <osmocom/core/stats.h> |
| 49 | #include <osmocom/vty/logging.h> |
| 50 | #include <osmocom/vty/ports.h> |
| 51 | #include <osmocom/vty/misc.h> |
| 52 | #include <osmocom/vty/telnet_interface.h> |
| 53 | #include <osmocom/ctrl/control_vty.h> |
| 54 | #include <osmocom/ctrl/ports.h> |
| 55 | #include <osmocom/ctrl/control_if.h> |
| 56 | #include <osmocom/vty/stats.h> |
Pau Espin Pedrol | 16e7e20 | 2018-06-15 15:19:21 +0200 | [diff] [blame] | 57 | #include <osmocom/vty/command.h> |
| 58 | |
Philipp Maier | 7e07cf2 | 2017-03-15 18:09:35 +0100 | [diff] [blame] | 59 | #include "convolve.h" |
| 60 | #include "convert.h" |
Pau Espin Pedrol | 5ea1817 | 2018-02-20 16:48:15 +0100 | [diff] [blame] | 61 | #include "trx_vty.h" |
| 62 | #include "debug.h" |
Pau Espin Pedrol | db936b9 | 2018-09-03 16:50:49 +0200 | [diff] [blame] | 63 | #include "osmo_signal.h" |
Pau Espin Pedrol | 4456b6f | 2019-05-24 16:54:19 +0200 | [diff] [blame] | 64 | #include "trx_rate_ctr.h" |
Philipp Maier | 7e07cf2 | 2017-03-15 18:09:35 +0100 | [diff] [blame] | 65 | } |
| 66 | |
Pau Espin Pedrol | 5ea1817 | 2018-02-20 16:48:15 +0100 | [diff] [blame] | 67 | #define DEFAULT_CONFIG_FILE "osmo-trx.cfg" |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 68 | |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 69 | #define charp2str(a) ((a) ? std::string(a) : std::string("")) |
| 70 | |
| 71 | static char* config_file = (char*)DEFAULT_CONFIG_FILE; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 72 | |
Pau Espin Pedrol | 21032b7 | 2019-03-29 19:20:06 +0100 | [diff] [blame] | 73 | struct osmo_fd signal_ofd; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 74 | volatile bool gshutdown = false; |
| 75 | |
Pau Espin Pedrol | 3a3b220 | 2018-02-21 20:15:47 +0100 | [diff] [blame] | 76 | static void *tall_trx_ctx; |
Pau Espin Pedrol | 5ea1817 | 2018-02-20 16:48:15 +0100 | [diff] [blame] | 77 | static struct trx_ctx *g_trx_ctx; |
| 78 | static struct ctrl_handle *g_ctrlh; |
Pau Espin Pedrol | 3a3b220 | 2018-02-21 20:15:47 +0100 | [diff] [blame] | 79 | |
Pau Espin Pedrol | 0bbd892 | 2018-02-21 11:59:26 +0100 | [diff] [blame] | 80 | static RadioDevice *usrp; |
| 81 | static RadioInterface *radio; |
| 82 | static Transceiver *transceiver; |
| 83 | |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 84 | /* Create radio interface |
| 85 | * The interface consists of sample rate changes, frequency shifts, |
| 86 | * channel multiplexing, and other conversions. The transceiver core |
| 87 | * accepts input vectors sampled at multiples of the GSM symbol rate. |
| 88 | * The radio interface connects the main transceiver with the device |
| 89 | * object, which may be operating some other rate. |
| 90 | */ |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 91 | RadioInterface *makeRadioInterface(struct trx_ctx *trx, |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 92 | RadioDevice *usrp, int type) |
| 93 | { |
| 94 | RadioInterface *radio = NULL; |
| 95 | |
| 96 | switch (type) { |
| 97 | case RadioDevice::NORMAL: |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 98 | radio = new RadioInterface(usrp, trx->cfg.tx_sps, |
| 99 | trx->cfg.rx_sps, trx->cfg.num_chans); |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 100 | break; |
| 101 | case RadioDevice::RESAMP_64M: |
| 102 | case RadioDevice::RESAMP_100M: |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 103 | radio = new RadioInterfaceResamp(usrp, trx->cfg.tx_sps, |
| 104 | trx->cfg.rx_sps); |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 105 | break; |
Tom Tsou | 7676427 | 2016-06-24 14:25:39 -0700 | [diff] [blame] | 106 | case RadioDevice::MULTI_ARFCN: |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 107 | radio = new RadioInterfaceMulti(usrp, trx->cfg.tx_sps, |
| 108 | trx->cfg.rx_sps, trx->cfg.num_chans); |
Tom Tsou | 7676427 | 2016-06-24 14:25:39 -0700 | [diff] [blame] | 109 | break; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 110 | default: |
| 111 | LOG(ALERT) << "Unsupported radio interface configuration"; |
| 112 | return NULL; |
| 113 | } |
| 114 | |
| 115 | if (!radio->init(type)) { |
| 116 | LOG(ALERT) << "Failed to initialize radio interface"; |
| 117 | return NULL; |
| 118 | } |
| 119 | |
| 120 | return radio; |
| 121 | } |
| 122 | |
Pau Espin Pedrol | db936b9 | 2018-09-03 16:50:49 +0200 | [diff] [blame] | 123 | /* Callback function to be called every time we receive a signal from TRANSC */ |
| 124 | static int transc_sig_cb(unsigned int subsys, unsigned int signal, |
| 125 | void *handler_data, void *signal_data) |
| 126 | { |
| 127 | switch (signal) { |
Pau Espin Pedrol | b426e4a | 2019-06-04 12:39:28 +0200 | [diff] [blame] | 128 | case S_MAIN_STOP_REQUIRED: |
Pau Espin Pedrol | db936b9 | 2018-09-03 16:50:49 +0200 | [diff] [blame] | 129 | gshutdown = true; |
| 130 | break; |
| 131 | default: |
| 132 | break; |
| 133 | } |
| 134 | return 0; |
| 135 | } |
| 136 | |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 137 | /* Create transceiver core |
| 138 | * The multi-threaded modem core operates at multiples of the GSM rate of |
| 139 | * 270.8333 ksps and consists of GSM specific modulation, demodulation, |
| 140 | * and decoding schemes. Also included are the socket interfaces for |
| 141 | * connecting to the upper layer stack. |
| 142 | */ |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 143 | int makeTransceiver(struct trx_ctx *trx, RadioInterface *radio) |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 144 | { |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 145 | VectorFIFO *fifo; |
| 146 | |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 147 | transceiver = new Transceiver(trx->cfg.base_port, trx->cfg.bind_addr, |
| 148 | trx->cfg.remote_addr, trx->cfg.tx_sps, |
| 149 | trx->cfg.rx_sps, trx->cfg.num_chans, GSM::Time(3,0), |
Eric Wild | ac0487e | 2019-06-17 13:02:44 +0200 | [diff] [blame] | 150 | radio, trx->cfg.rssi_offset, trx->cfg.stack_size); |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 151 | if (!transceiver->init(trx->cfg.filler, trx->cfg.rtsc, |
Vadim Yanitskiy | a8b3565 | 2018-10-22 02:52:18 +0200 | [diff] [blame] | 152 | trx->cfg.rach_delay, trx->cfg.egprs, trx->cfg.ext_rach)) { |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 153 | LOG(ALERT) << "Failed to initialize transceiver"; |
Pau Espin Pedrol | 0bbd892 | 2018-02-21 11:59:26 +0100 | [diff] [blame] | 154 | return -1; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 155 | } |
| 156 | |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 157 | for (size_t i = 0; i < trx->cfg.num_chans; i++) { |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 158 | fifo = radio->receiveFIFO(i); |
Pau Espin Pedrol | 0bbd892 | 2018-02-21 11:59:26 +0100 | [diff] [blame] | 159 | if (fifo && transceiver->receiveFIFO(fifo, i)) |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 160 | continue; |
| 161 | |
| 162 | LOG(ALERT) << "Could not attach FIFO to channel " << i; |
Pau Espin Pedrol | 0bbd892 | 2018-02-21 11:59:26 +0100 | [diff] [blame] | 163 | return -1; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 164 | } |
Pau Espin Pedrol | 0bbd892 | 2018-02-21 11:59:26 +0100 | [diff] [blame] | 165 | return 0; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | static void sig_handler(int signo) |
| 169 | { |
Pau Espin Pedrol | d01c7b9 | 2019-03-29 18:36:30 +0100 | [diff] [blame] | 170 | |
| 171 | if (gshutdown) |
| 172 | /* We are in the middle of shutdown process, avoid any kind of extra |
| 173 | action like printing */ |
| 174 | return; |
| 175 | |
Pau Espin Pedrol | 3eed8eb | 2019-08-14 16:26:45 +0200 | [diff] [blame] | 176 | fprintf(stderr, "signal %d received\n", signo); |
Pau Espin Pedrol | ab22f4c | 2018-02-21 20:15:18 +0100 | [diff] [blame] | 177 | switch (signo) { |
| 178 | case SIGINT: |
| 179 | case SIGTERM: |
Pau Espin Pedrol | 3eed8eb | 2019-08-14 16:26:45 +0200 | [diff] [blame] | 180 | fprintf(stderr, "shutting down\n"); |
Pau Espin Pedrol | ab22f4c | 2018-02-21 20:15:18 +0100 | [diff] [blame] | 181 | gshutdown = true; |
| 182 | break; |
Pau Espin Pedrol | 3a3b220 | 2018-02-21 20:15:47 +0100 | [diff] [blame] | 183 | case SIGABRT: |
| 184 | case SIGUSR1: |
| 185 | talloc_report(tall_trx_ctx, stderr); |
| 186 | talloc_report_full(tall_trx_ctx, stderr); |
| 187 | break; |
| 188 | case SIGUSR2: |
| 189 | talloc_report_full(tall_trx_ctx, stderr); |
| 190 | break; |
Pau Espin Pedrol | 21032b7 | 2019-03-29 19:20:06 +0100 | [diff] [blame] | 191 | case SIGHUP: |
| 192 | log_targets_reopen(); |
Pau Espin Pedrol | ab22f4c | 2018-02-21 20:15:18 +0100 | [diff] [blame] | 193 | default: |
| 194 | break; |
| 195 | } |
Pau Espin Pedrol | 21032b7 | 2019-03-29 19:20:06 +0100 | [diff] [blame] | 196 | |
| 197 | } |
| 198 | |
| 199 | static int signalfd_callback(struct osmo_fd *ofd, unsigned int what) |
| 200 | { |
| 201 | struct signalfd_siginfo fdsi; |
| 202 | ssize_t s; |
| 203 | |
| 204 | s = read(ofd->fd, &fdsi, sizeof(struct signalfd_siginfo)); |
| 205 | if (s < 0) { |
| 206 | LOG(FATAL) << "Failed to read from signalfd ("<< ofd->fd << "): " << errno; |
| 207 | gshutdown = true; |
| 208 | return 0; |
| 209 | } |
| 210 | sig_handler(fdsi.ssi_signo); |
| 211 | return 0; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | static void setup_signal_handlers() |
| 215 | { |
Pau Espin Pedrol | 21032b7 | 2019-03-29 19:20:06 +0100 | [diff] [blame] | 216 | sigset_t set; |
| 217 | int sfd; |
| 218 | |
Pau Espin Pedrol | ab22f4c | 2018-02-21 20:15:18 +0100 | [diff] [blame] | 219 | signal(SIGABRT, &sig_handler); |
Pau Espin Pedrol | ab22f4c | 2018-02-21 20:15:18 +0100 | [diff] [blame] | 220 | osmo_init_ignore_signals(); |
Pau Espin Pedrol | 21032b7 | 2019-03-29 19:20:06 +0100 | [diff] [blame] | 221 | |
| 222 | /* Other threads created by this thread (main) will inherit a copy of the |
| 223 | signal mask. */ |
| 224 | sigemptyset(&set); |
| 225 | sigaddset(&set, SIGINT); |
| 226 | sigaddset(&set, SIGTERM); |
| 227 | sigaddset(&set, SIGUSR1); |
| 228 | sigaddset(&set, SIGUSR2); |
| 229 | sigaddset(&set, SIGHUP); |
| 230 | if (pthread_sigmask(SIG_BLOCK, &set, NULL)) { |
| 231 | fprintf(stderr, "pthread_sigmask() failed.\n"); |
| 232 | exit(EXIT_FAILURE); |
| 233 | } |
| 234 | |
| 235 | if ((sfd = signalfd(-1, &set, 0)) == -1) { |
| 236 | fprintf(stderr, "signalfd() failed (%d).\n", errno); |
| 237 | exit(EXIT_FAILURE); |
| 238 | } |
| 239 | |
Harald Welte | 71df425 | 2019-04-16 17:17:40 +0200 | [diff] [blame] | 240 | osmo_fd_setup(&signal_ofd, sfd, BSC_FD_READ, signalfd_callback, NULL, 0); |
Pau Espin Pedrol | 5e6f3e0 | 2019-04-02 11:45:04 +0200 | [diff] [blame] | 241 | if (osmo_fd_register(&signal_ofd) < 0) { |
| 242 | fprintf(stderr, "osmo_fd_register() failed.\n"); |
| 243 | exit(EXIT_FAILURE); |
| 244 | } |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | static void print_help() |
| 248 | { |
| 249 | fprintf(stdout, "Options:\n" |
Oliver Smith | a439fed | 2018-10-23 13:12:17 +0200 | [diff] [blame] | 250 | " -h, --help This text\n" |
| 251 | " -C, --config Filename The config file to use\n" |
| 252 | " -V, --version Print the version of OsmoTRX\n" |
Pau Espin Pedrol | 3da1f83 | 2018-02-20 20:01:10 +0100 | [diff] [blame] | 253 | ); |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 254 | } |
| 255 | |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 256 | static void print_deprecated(char opt) |
| 257 | { |
| 258 | LOG(WARNING) << "Cmd line option '" << opt << "' is deprecated and will be soon removed." |
| 259 | << " Please use VTY cfg option instead." |
Ruben Undheim | 252564b | 2018-07-20 22:03:39 +0200 | [diff] [blame] | 260 | << " All cmd line options are already being overridden by VTY options if set."; |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | static void handle_options(int argc, char **argv, struct trx_ctx* trx) |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 264 | { |
| 265 | int option; |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 266 | unsigned int i; |
| 267 | std::vector<std::string> rx_paths, tx_paths; |
| 268 | bool rx_paths_set = false, tx_paths_set = false; |
Oliver Smith | a439fed | 2018-10-23 13:12:17 +0200 | [diff] [blame] | 269 | static struct option long_options[] = { |
| 270 | {"help", 0, 0, 'h'}, |
| 271 | {"config", 1, 0, 'C'}, |
| 272 | {"version", 0, 0, 'V'}, |
| 273 | {NULL, 0, 0, 0} |
| 274 | }; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 275 | |
Oliver Smith | a439fed | 2018-10-23 13:12:17 +0200 | [diff] [blame] | 276 | while ((option = getopt_long(argc, argv, "ha:l:i:j:p:c:dmxgfo:s:b:r:A:R:Set:y:z:C:V", long_options, |
| 277 | NULL)) != -1) { |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 278 | switch (option) { |
| 279 | case 'h': |
| 280 | print_help(); |
| 281 | exit(0); |
| 282 | break; |
| 283 | case 'a': |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 284 | print_deprecated(option); |
| 285 | osmo_talloc_replace_string(trx, &trx->cfg.dev_args, optarg); |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 286 | break; |
Pau Espin Pedrol | 8dffadb | 2018-03-06 18:38:22 +0100 | [diff] [blame] | 287 | case 'l': |
| 288 | print_deprecated(option); |
| 289 | log_set_log_level(osmo_stderr_target, atoi(optarg)); |
| 290 | break; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 291 | case 'i': |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 292 | print_deprecated(option); |
| 293 | osmo_talloc_replace_string(trx, &trx->cfg.remote_addr, optarg); |
Pau Espin Pedrol | 8c80095 | 2017-08-16 16:53:23 +0200 | [diff] [blame] | 294 | break; |
| 295 | case 'j': |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 296 | print_deprecated(option); |
| 297 | osmo_talloc_replace_string(trx, &trx->cfg.bind_addr, optarg); |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 298 | break; |
| 299 | case 'p': |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 300 | print_deprecated(option); |
| 301 | trx->cfg.base_port = atoi(optarg); |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 302 | break; |
| 303 | case 'c': |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 304 | print_deprecated(option); |
| 305 | trx->cfg.num_chans = atoi(optarg); |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 306 | break; |
Tom Tsou | 7676427 | 2016-06-24 14:25:39 -0700 | [diff] [blame] | 307 | case 'm': |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 308 | print_deprecated(option); |
| 309 | trx->cfg.multi_arfcn = true; |
Tom Tsou | 7676427 | 2016-06-24 14:25:39 -0700 | [diff] [blame] | 310 | break; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 311 | case 'x': |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 312 | print_deprecated(option); |
| 313 | trx->cfg.clock_ref = REF_EXTERNAL; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 314 | break; |
Tom Tsou | 2f3e60b | 2016-07-17 19:29:08 -0700 | [diff] [blame] | 315 | case 'g': |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 316 | print_deprecated(option); |
| 317 | trx->cfg.clock_ref = REF_GPS; |
Tom Tsou | 2f3e60b | 2016-07-17 19:29:08 -0700 | [diff] [blame] | 318 | break; |
Thomas Tsou | 15d743e | 2014-01-25 02:34:03 -0500 | [diff] [blame] | 319 | case 'f': |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 320 | print_deprecated(option); |
| 321 | trx->cfg.filler = FILLER_DUMMY; |
Thomas Tsou | 15d743e | 2014-01-25 02:34:03 -0500 | [diff] [blame] | 322 | break; |
Thomas Tsou | 8e17df7 | 2014-03-06 14:16:11 -0500 | [diff] [blame] | 323 | case 'o': |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 324 | print_deprecated(option); |
| 325 | trx->cfg.offset = atof(optarg); |
Thomas Tsou | 8e17df7 | 2014-03-06 14:16:11 -0500 | [diff] [blame] | 326 | break; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 327 | case 's': |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 328 | print_deprecated(option); |
| 329 | trx->cfg.tx_sps = atoi(optarg); |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 330 | break; |
Tom Tsou | 2e4ed10 | 2016-06-27 15:39:16 -0700 | [diff] [blame] | 331 | case 'b': |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 332 | print_deprecated(option); |
| 333 | trx->cfg.rx_sps = atoi(optarg); |
Tom Tsou | 2e4ed10 | 2016-06-27 15:39:16 -0700 | [diff] [blame] | 334 | break; |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 335 | case 'r': |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 336 | print_deprecated(option); |
| 337 | trx->cfg.rtsc_set = true; |
| 338 | trx->cfg.rtsc = atoi(optarg); |
| 339 | if (!trx->cfg.egprs) /* Don't override egprs which sets different filler */ |
| 340 | trx->cfg.filler = FILLER_NORM_RAND; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 341 | break; |
Alexander Chemeris | 5efe050 | 2016-03-23 17:06:32 +0300 | [diff] [blame] | 342 | case 'A': |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 343 | print_deprecated(option); |
| 344 | trx->cfg.rach_delay_set = true; |
| 345 | trx->cfg.rach_delay = atoi(optarg); |
| 346 | trx->cfg.filler = FILLER_ACCESS_RAND; |
Alexander Chemeris | 5efe050 | 2016-03-23 17:06:32 +0300 | [diff] [blame] | 347 | break; |
Alexander Chemeris | e8905a0 | 2015-06-03 23:47:56 -0400 | [diff] [blame] | 348 | case 'R': |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 349 | print_deprecated(option); |
| 350 | trx->cfg.rssi_offset = atof(optarg); |
Alexander Chemeris | e8905a0 | 2015-06-03 23:47:56 -0400 | [diff] [blame] | 351 | break; |
Alexander Chemeris | 50747dc | 2015-06-07 01:07:45 -0400 | [diff] [blame] | 352 | case 'S': |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 353 | print_deprecated(option); |
| 354 | trx->cfg.swap_channels = true; |
Alexander Chemeris | 50747dc | 2015-06-07 01:07:45 -0400 | [diff] [blame] | 355 | break; |
Tom Tsou | b0aefcb | 2016-03-06 03:44:34 -0800 | [diff] [blame] | 356 | case 'e': |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 357 | print_deprecated(option); |
| 358 | trx->cfg.egprs = true; |
Tom Tsou | b0aefcb | 2016-03-06 03:44:34 -0800 | [diff] [blame] | 359 | break; |
Harald Welte | 81486e0 | 2017-06-29 15:35:22 +0200 | [diff] [blame] | 360 | case 't': |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 361 | print_deprecated(option); |
| 362 | trx->cfg.sched_rr = atoi(optarg); |
Harald Welte | 81486e0 | 2017-06-29 15:35:22 +0200 | [diff] [blame] | 363 | break; |
Pau Espin Pedrol | 77ce99a | 2018-02-05 13:05:06 +0100 | [diff] [blame] | 364 | case 'y': |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 365 | print_deprecated(option); |
| 366 | tx_paths = comma_delimited_to_vector(optarg); |
| 367 | tx_paths_set = true; |
Pau Espin Pedrol | 77ce99a | 2018-02-05 13:05:06 +0100 | [diff] [blame] | 368 | break; |
| 369 | case 'z': |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 370 | print_deprecated(option); |
| 371 | rx_paths = comma_delimited_to_vector(optarg); |
| 372 | rx_paths_set = true; |
Pau Espin Pedrol | 77ce99a | 2018-02-05 13:05:06 +0100 | [diff] [blame] | 373 | break; |
Pau Espin Pedrol | 5ea1817 | 2018-02-20 16:48:15 +0100 | [diff] [blame] | 374 | case 'C': |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 375 | config_file = optarg; |
Pau Espin Pedrol | 5ea1817 | 2018-02-20 16:48:15 +0100 | [diff] [blame] | 376 | break; |
Pau Espin Pedrol | 16e7e20 | 2018-06-15 15:19:21 +0200 | [diff] [blame] | 377 | case 'V': |
| 378 | print_version(1); |
| 379 | exit(0); |
| 380 | break; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 381 | default: |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 382 | goto bad_config; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 383 | } |
| 384 | } |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 385 | |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 386 | /* Cmd line option specific validation & setup */ |
Tom Tsou | 2e4ed10 | 2016-06-27 15:39:16 -0700 | [diff] [blame] | 387 | |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 388 | if (trx->cfg.num_chans > TRX_CHAN_MAX) { |
| 389 | LOG(ERROR) << "Too many channels requested, maximum is " << TRX_CHAN_MAX; |
Tom Tsou | 8f0ccf6 | 2016-07-20 16:35:03 -0700 | [diff] [blame] | 390 | goto bad_config; |
| 391 | } |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 392 | if ((tx_paths_set && tx_paths.size() != trx->cfg.num_chans) || |
| 393 | (rx_paths_set && rx_paths.size() != trx->cfg.num_chans)) { |
| 394 | LOG(ERROR) << "Num of channels and num of Rx/Tx Antennas doesn't match"; |
Tom Tsou | 8f0ccf6 | 2016-07-20 16:35:03 -0700 | [diff] [blame] | 395 | goto bad_config; |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 396 | } |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 397 | for (i = 0; i < trx->cfg.num_chans; i++) { |
| 398 | trx->cfg.chans[i].trx = trx; |
| 399 | trx->cfg.chans[i].idx = i; |
| 400 | if (tx_paths_set) |
| 401 | osmo_talloc_replace_string(trx, &trx->cfg.chans[i].tx_path, tx_paths[i].c_str()); |
| 402 | if (rx_paths_set) |
| 403 | osmo_talloc_replace_string(trx, &trx->cfg.chans[i].rx_path, rx_paths[i].c_str()); |
Pau Espin Pedrol | 77ce99a | 2018-02-05 13:05:06 +0100 | [diff] [blame] | 404 | } |
| 405 | |
Tom Tsou | 8f0ccf6 | 2016-07-20 16:35:03 -0700 | [diff] [blame] | 406 | return; |
| 407 | |
| 408 | bad_config: |
| 409 | print_help(); |
| 410 | exit(0); |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 411 | } |
| 412 | |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 413 | int trx_validate_config(struct trx_ctx *trx) |
| 414 | { |
Tom Tsou | d280045 | 2019-04-01 07:55:48 +0700 | [diff] [blame] | 415 | if (trx->cfg.multi_arfcn && trx->cfg.num_chans > TRX_MCHAN_MAX) { |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 416 | LOG(ERROR) << "Unsupported number of channels"; |
| 417 | return -1; |
| 418 | } |
| 419 | |
| 420 | /* Force 4 SPS for EDGE or multi-ARFCN configurations */ |
| 421 | if ((trx->cfg.egprs || trx->cfg.multi_arfcn) && |
Harald Welte | 8fb0c3d | 2018-10-21 12:15:30 +0200 | [diff] [blame] | 422 | (trx->cfg.tx_sps!=4 || trx->cfg.rx_sps!=4)) { |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 423 | LOG(ERROR) << "EDGE and Multi-Carrier options require 4 tx and rx sps. Check you config."; |
| 424 | return -1; |
| 425 | } |
| 426 | |
| 427 | return 0; |
| 428 | } |
| 429 | |
| 430 | static int set_sched_rr(unsigned int prio) |
Harald Welte | 81486e0 | 2017-06-29 15:35:22 +0200 | [diff] [blame] | 431 | { |
| 432 | struct sched_param param; |
| 433 | int rc; |
| 434 | memset(¶m, 0, sizeof(param)); |
| 435 | param.sched_priority = prio; |
Pau Espin Pedrol | 2d085e2 | 2018-12-03 18:21:13 +0100 | [diff] [blame] | 436 | LOG(INFO) << "Setting SCHED_RR priority " << param.sched_priority; |
Harald Welte | 81486e0 | 2017-06-29 15:35:22 +0200 | [diff] [blame] | 437 | rc = sched_setscheduler(getpid(), SCHED_RR, ¶m); |
| 438 | if (rc != 0) { |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 439 | LOG(ERROR) << "Config: Setting SCHED_RR failed"; |
Harald Welte | 81486e0 | 2017-06-29 15:35:22 +0200 | [diff] [blame] | 440 | return -1; |
| 441 | } |
| 442 | return 0; |
| 443 | } |
| 444 | |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 445 | static void print_config(struct trx_ctx *trx) |
| 446 | { |
| 447 | unsigned int i; |
| 448 | std::ostringstream ost(""); |
| 449 | |
| 450 | ost << "Config Settings" << std::endl; |
Pau Espin Pedrol | 8dffadb | 2018-03-06 18:38:22 +0100 | [diff] [blame] | 451 | ost << " Log Level............... " << (unsigned int) osmo_stderr_target->loglevel << std::endl; |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 452 | ost << " Device args............. " << charp2str(trx->cfg.dev_args) << std::endl; |
| 453 | ost << " TRX Base Port........... " << trx->cfg.base_port << std::endl; |
| 454 | ost << " TRX Address............. " << charp2str(trx->cfg.bind_addr) << std::endl; |
Harald Welte | fad2e09 | 2018-04-28 21:25:09 +0200 | [diff] [blame] | 455 | ost << " GSM BTS Address......... " << charp2str(trx->cfg.remote_addr) << std::endl; |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 456 | ost << " Channels................ " << trx->cfg.num_chans << std::endl; |
| 457 | ost << " Tx Samples-per-Symbol... " << trx->cfg.tx_sps << std::endl; |
| 458 | ost << " Rx Samples-per-Symbol... " << trx->cfg.rx_sps << std::endl; |
| 459 | ost << " EDGE support............ " << trx->cfg.egprs << std::endl; |
Vadim Yanitskiy | a8b3565 | 2018-10-22 02:52:18 +0200 | [diff] [blame] | 460 | ost << " Extended RACH support... " << trx->cfg.ext_rach << std::endl; |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 461 | ost << " Reference............... " << trx->cfg.clock_ref << std::endl; |
| 462 | ost << " C0 Filler Table......... " << trx->cfg.filler << std::endl; |
| 463 | ost << " Multi-Carrier........... " << trx->cfg.multi_arfcn << std::endl; |
| 464 | ost << " Tuning offset........... " << trx->cfg.offset << std::endl; |
| 465 | ost << " RSSI to dBm offset...... " << trx->cfg.rssi_offset << std::endl; |
| 466 | ost << " Swap channels........... " << trx->cfg.swap_channels << std::endl; |
| 467 | ost << " Tx Antennas............."; |
| 468 | for (i = 0; i < trx->cfg.num_chans; i++) { |
| 469 | std::string p = charp2str(trx->cfg.chans[i].tx_path); |
| 470 | ost << " '" << ((p != "") ? p : "<default>") << "'"; |
| 471 | } |
| 472 | ost << std::endl; |
| 473 | ost << " Rx Antennas............."; |
| 474 | for (i = 0; i < trx->cfg.num_chans; i++) { |
| 475 | std::string p = charp2str(trx->cfg.chans[i].rx_path); |
| 476 | ost << " '" << ((p != "") ? p : "<default>") << "'"; |
| 477 | } |
| 478 | ost << std::endl; |
| 479 | |
Pau Espin Pedrol | 2d085e2 | 2018-12-03 18:21:13 +0100 | [diff] [blame] | 480 | LOG(INFO) << ost << std::endl; |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 481 | } |
| 482 | |
Pau Espin Pedrol | 0bbd892 | 2018-02-21 11:59:26 +0100 | [diff] [blame] | 483 | static void trx_stop() |
| 484 | { |
Pau Espin Pedrol | 2d085e2 | 2018-12-03 18:21:13 +0100 | [diff] [blame] | 485 | LOG(NOTICE) << "Shutting down transceiver..." << std::endl; |
Pau Espin Pedrol | 0bbd892 | 2018-02-21 11:59:26 +0100 | [diff] [blame] | 486 | |
| 487 | delete transceiver; |
| 488 | delete radio; |
| 489 | delete usrp; |
| 490 | } |
| 491 | |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 492 | static int trx_start(struct trx_ctx *trx) |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 493 | { |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 494 | int type, chans; |
| 495 | unsigned int i; |
| 496 | std::vector<std::string> rx_paths, tx_paths; |
Tom Tsou | 05c6feb | 2016-06-22 16:09:44 -0700 | [diff] [blame] | 497 | RadioDevice::InterfaceType iface = RadioDevice::NORMAL; |
Pau Espin Pedrol | 0bbd892 | 2018-02-21 11:59:26 +0100 | [diff] [blame] | 498 | |
| 499 | /* Create the low level device object */ |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 500 | if (trx->cfg.multi_arfcn) |
Pau Espin Pedrol | 0bbd892 | 2018-02-21 11:59:26 +0100 | [diff] [blame] | 501 | iface = RadioDevice::MULTI_ARFCN; |
| 502 | |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 503 | /* Generate vector of rx/tx_path: */ |
| 504 | for (i = 0; i < trx->cfg.num_chans; i++) { |
| 505 | rx_paths.push_back(charp2str(trx->cfg.chans[i].rx_path)); |
| 506 | tx_paths.push_back(charp2str(trx->cfg.chans[i].tx_path)); |
| 507 | } |
Pau Espin Pedrol | 0bbd892 | 2018-02-21 11:59:26 +0100 | [diff] [blame] | 508 | |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 509 | usrp = RadioDevice::make(trx->cfg.tx_sps, trx->cfg.rx_sps, iface, |
| 510 | trx->cfg.num_chans, trx->cfg.offset, |
| 511 | tx_paths, rx_paths); |
| 512 | type = usrp->open(charp2str(trx->cfg.dev_args), trx->cfg.clock_ref, trx->cfg.swap_channels); |
Pau Espin Pedrol | 0bbd892 | 2018-02-21 11:59:26 +0100 | [diff] [blame] | 513 | if (type < 0) { |
| 514 | LOG(ALERT) << "Failed to create radio device" << std::endl; |
| 515 | goto shutdown; |
| 516 | } |
| 517 | |
| 518 | /* Setup the appropriate device interface */ |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 519 | radio = makeRadioInterface(trx, usrp, type); |
Pau Espin Pedrol | 0bbd892 | 2018-02-21 11:59:26 +0100 | [diff] [blame] | 520 | if (!radio) |
| 521 | goto shutdown; |
| 522 | |
| 523 | /* Create the transceiver core */ |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 524 | if (makeTransceiver(trx, radio) < 0) |
Pau Espin Pedrol | 0bbd892 | 2018-02-21 11:59:26 +0100 | [diff] [blame] | 525 | goto shutdown; |
| 526 | |
| 527 | chans = transceiver->numChans(); |
Pau Espin Pedrol | 2d085e2 | 2018-12-03 18:21:13 +0100 | [diff] [blame] | 528 | LOG(NOTICE) << "-- Transceiver active with " |
Pau Espin Pedrol | 0bbd892 | 2018-02-21 11:59:26 +0100 | [diff] [blame] | 529 | << chans << " channel(s)" << std::endl; |
| 530 | |
| 531 | return 0; |
| 532 | |
| 533 | shutdown: |
| 534 | trx_stop(); |
| 535 | return -1; |
| 536 | } |
| 537 | |
| 538 | int main(int argc, char *argv[]) |
| 539 | { |
Pau Espin Pedrol | 5ea1817 | 2018-02-20 16:48:15 +0100 | [diff] [blame] | 540 | int rc; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 541 | |
Pau Espin Pedrol | 3a3b220 | 2018-02-21 20:15:47 +0100 | [diff] [blame] | 542 | tall_trx_ctx = talloc_named_const(NULL, 0, "OsmoTRX"); |
| 543 | msgb_talloc_ctx_init(tall_trx_ctx, 0); |
Pau Espin Pedrol | 5ea1817 | 2018-02-20 16:48:15 +0100 | [diff] [blame] | 544 | g_vty_info.tall_ctx = tall_trx_ctx; |
| 545 | |
Pau Espin Pedrol | ab22f4c | 2018-02-21 20:15:18 +0100 | [diff] [blame] | 546 | setup_signal_handlers(); |
| 547 | |
Pau Espin Pedrol | a3ab8c2 | 2018-02-21 15:41:03 +0100 | [diff] [blame] | 548 | g_trx_ctx = vty_trx_ctx_alloc(tall_trx_ctx); |
Pau Espin Pedrol | 5ea1817 | 2018-02-20 16:48:15 +0100 | [diff] [blame] | 549 | |
Philipp Maier | e51a8f0 | 2017-03-16 12:09:34 +0100 | [diff] [blame] | 550 | #ifdef HAVE_SSE3 |
| 551 | printf("Info: SSE3 support compiled in"); |
Vadim Yanitskiy | 3bd763d | 2017-05-20 01:46:51 +0300 | [diff] [blame] | 552 | #ifdef HAVE___BUILTIN_CPU_SUPPORTS |
Philipp Maier | e51a8f0 | 2017-03-16 12:09:34 +0100 | [diff] [blame] | 553 | if (__builtin_cpu_supports("sse3")) |
| 554 | printf(" and supported by CPU\n"); |
| 555 | else |
| 556 | printf(", but not supported by CPU\n"); |
Vadim Yanitskiy | 3bd763d | 2017-05-20 01:46:51 +0300 | [diff] [blame] | 557 | #else |
| 558 | printf(", but runtime SIMD detection disabled\n"); |
| 559 | #endif |
Philipp Maier | e51a8f0 | 2017-03-16 12:09:34 +0100 | [diff] [blame] | 560 | #endif |
| 561 | |
| 562 | #ifdef HAVE_SSE4_1 |
| 563 | printf("Info: SSE4.1 support compiled in"); |
Vadim Yanitskiy | 3bd763d | 2017-05-20 01:46:51 +0300 | [diff] [blame] | 564 | #ifdef HAVE___BUILTIN_CPU_SUPPORTS |
Philipp Maier | e51a8f0 | 2017-03-16 12:09:34 +0100 | [diff] [blame] | 565 | if (__builtin_cpu_supports("sse4.1")) |
| 566 | printf(" and supported by CPU\n"); |
| 567 | else |
| 568 | printf(", but not supported by CPU\n"); |
Vadim Yanitskiy | 3bd763d | 2017-05-20 01:46:51 +0300 | [diff] [blame] | 569 | #else |
| 570 | printf(", but runtime SIMD detection disabled\n"); |
| 571 | #endif |
Philipp Maier | e51a8f0 | 2017-03-16 12:09:34 +0100 | [diff] [blame] | 572 | #endif |
| 573 | |
Pau Espin Pedrol | c9202ab | 2019-07-01 20:13:32 +0200 | [diff] [blame] | 574 | if (!log_mutex_init()) { |
| 575 | fprintf(stderr, "Failed to initialize log mutex!\n"); |
| 576 | exit(2); |
| 577 | } |
Philipp Maier | 7e07cf2 | 2017-03-15 18:09:35 +0100 | [diff] [blame] | 578 | convolve_init(); |
| 579 | convert_init(); |
| 580 | |
Pau Espin Pedrol | e1977fc | 2018-04-16 14:50:11 +0200 | [diff] [blame] | 581 | osmo_init_logging2(tall_trx_ctx, &log_info); |
Pau Espin Pedrol | 5ea1817 | 2018-02-20 16:48:15 +0100 | [diff] [blame] | 582 | osmo_stats_init(tall_trx_ctx); |
| 583 | vty_init(&g_vty_info); |
| 584 | ctrl_vty_init(tall_trx_ctx); |
| 585 | trx_vty_init(g_trx_ctx); |
| 586 | |
| 587 | logging_vty_add_cmds(); |
| 588 | osmo_talloc_vty_add_cmds(); |
| 589 | osmo_stats_vty_add_cmds(); |
| 590 | |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 591 | handle_options(argc, argv, g_trx_ctx); |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 592 | |
Pau Espin Pedrol | 5ea1817 | 2018-02-20 16:48:15 +0100 | [diff] [blame] | 593 | rate_ctr_init(tall_trx_ctx); |
| 594 | |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 595 | rc = vty_read_config_file(config_file, NULL); |
Pau Espin Pedrol | 5ea1817 | 2018-02-20 16:48:15 +0100 | [diff] [blame] | 596 | if (rc < 0) { |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 597 | fprintf(stderr, "Failed to open config file: '%s'\n", config_file); |
Pau Espin Pedrol | 5ea1817 | 2018-02-20 16:48:15 +0100 | [diff] [blame] | 598 | exit(2); |
| 599 | } |
| 600 | |
| 601 | rc = telnet_init_dynif(tall_trx_ctx, NULL, vty_get_bind_addr(), OSMO_VTY_PORT_TRX); |
| 602 | if (rc < 0) |
| 603 | exit(1); |
| 604 | |
Pau Espin Pedrol | 88f86a1 | 2019-07-22 12:30:14 +0200 | [diff] [blame] | 605 | g_ctrlh = ctrl_interface_setup_dynip(NULL, ctrl_vty_get_bind_addr(), OSMO_CTRL_PORT_TRX, NULL); |
Pau Espin Pedrol | 5ea1817 | 2018-02-20 16:48:15 +0100 | [diff] [blame] | 606 | if (!g_ctrlh) { |
Pau Espin Pedrol | 2d085e2 | 2018-12-03 18:21:13 +0100 | [diff] [blame] | 607 | LOG(ERROR) << "Failed to create CTRL interface.\n"; |
Pau Espin Pedrol | 5ea1817 | 2018-02-20 16:48:15 +0100 | [diff] [blame] | 608 | exit(1); |
| 609 | } |
| 610 | |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 611 | /* Backward compatibility: Hack to have 1 channel allocated by default. |
| 612 | * Can be Dropped once we * get rid of "-c" cmdline param */ |
| 613 | if (g_trx_ctx->cfg.num_chans == 0) { |
| 614 | g_trx_ctx->cfg.num_chans = 1; |
| 615 | g_trx_ctx->cfg.chans[0].trx = g_trx_ctx; |
| 616 | g_trx_ctx->cfg.chans[0].idx = 0; |
| 617 | LOG(ERROR) << "No explicit channel config found. Make sure you" \ |
| 618 | " configure channels in VTY config. Using 1 channel as default," \ |
| 619 | " but expect your config to break in the future."; |
Harald Welte | 81486e0 | 2017-06-29 15:35:22 +0200 | [diff] [blame] | 620 | } |
| 621 | |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 622 | print_config(g_trx_ctx); |
| 623 | |
| 624 | if (trx_validate_config(g_trx_ctx) < 0) { |
| 625 | LOG(ERROR) << "Config failure - exiting"; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 626 | return EXIT_FAILURE; |
| 627 | } |
| 628 | |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 629 | if (g_trx_ctx->cfg.sched_rr) { |
| 630 | if (set_sched_rr(g_trx_ctx->cfg.sched_rr) < 0) |
| 631 | return EXIT_FAILURE; |
| 632 | } |
| 633 | |
Pau Espin Pedrol | b426e4a | 2019-06-04 12:39:28 +0200 | [diff] [blame] | 634 | osmo_signal_register_handler(SS_MAIN, transc_sig_cb, NULL); |
Pau Espin Pedrol | 4456b6f | 2019-05-24 16:54:19 +0200 | [diff] [blame] | 635 | trx_rate_ctr_init(tall_trx_ctx, g_trx_ctx); |
| 636 | |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 637 | srandom(time(NULL)); |
| 638 | |
Pau Espin Pedrol | 408f250 | 2018-02-21 18:47:35 +0100 | [diff] [blame] | 639 | if(trx_start(g_trx_ctx) < 0) |
Pau Espin Pedrol | 0bbd892 | 2018-02-21 11:59:26 +0100 | [diff] [blame] | 640 | return EXIT_FAILURE; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 641 | |
| 642 | while (!gshutdown) |
Pau Espin Pedrol | 5ea1817 | 2018-02-20 16:48:15 +0100 | [diff] [blame] | 643 | osmo_select_main(0); |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 644 | |
Pau Espin Pedrol | 0bbd892 | 2018-02-21 11:59:26 +0100 | [diff] [blame] | 645 | trx_stop(); |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 646 | |
Pau Espin Pedrol | 21032b7 | 2019-03-29 19:20:06 +0100 | [diff] [blame] | 647 | osmo_fd_unregister(&signal_ofd); |
| 648 | osmo_fd_close(&signal_ofd); |
Pau Espin Pedrol | b426e4a | 2019-06-04 12:39:28 +0200 | [diff] [blame] | 649 | osmo_signal_unregister_handler(SS_MAIN, transc_sig_cb, NULL); |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 650 | return 0; |
| 651 | } |