Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 Thomas Tsou <tom@tsou.cc> |
| 3 | * |
| 4 | * This library is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU Lesser General Public |
| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 2.1 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Lesser General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Lesser General Public |
| 15 | * License along with this library; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | */ |
| 18 | |
| 19 | #ifdef HAVE_CONFIG_H |
| 20 | #include "config.h" |
| 21 | #endif |
| 22 | |
| 23 | #include "Transceiver.h" |
| 24 | #include "radioDevice.h" |
| 25 | |
| 26 | #include <time.h> |
| 27 | #include <signal.h> |
| 28 | #include <stdlib.h> |
| 29 | #include <unistd.h> |
Harald Welte | 81486e0 | 2017-06-29 15:35:22 +0200 | [diff] [blame] | 30 | #include <sched.h> |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 31 | |
| 32 | #include <GSMCommon.h> |
| 33 | #include <Logger.h> |
| 34 | #include <Configuration.h> |
| 35 | |
Philipp Maier | 7e07cf2 | 2017-03-15 18:09:35 +0100 | [diff] [blame] | 36 | extern "C" { |
| 37 | #include "convolve.h" |
| 38 | #include "convert.h" |
| 39 | } |
| 40 | |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 41 | /* Samples-per-symbol for downlink path |
| 42 | * 4 - Uses precision modulator (more computation, less distortion) |
| 43 | * 1 - Uses minimized modulator (less computation, more distortion) |
| 44 | * |
| 45 | * Other values are invalid. Receive path (uplink) is always |
Tom Tsou | 0fe41a5 | 2016-05-03 15:14:45 -0700 | [diff] [blame] | 46 | * downsampled to 1 sps. Default to 4 sps for all cases. |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 47 | */ |
Tom Tsou | 5cd70dc | 2016-03-06 01:28:40 -0800 | [diff] [blame] | 48 | #define DEFAULT_TX_SPS 4 |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 49 | |
Tom Tsou | 5cd70dc | 2016-03-06 01:28:40 -0800 | [diff] [blame] | 50 | /* |
| 51 | * Samples-per-symbol for uplink (receiver) path |
| 52 | * Do not modify this value. EDGE configures 4 sps automatically on |
| 53 | * B200/B210 devices only. Use of 4 sps on the receive path for other |
| 54 | * configurations is not supported. |
| 55 | */ |
| 56 | #define DEFAULT_RX_SPS 1 |
| 57 | |
Tom Tsou | de116e9 | 2017-03-30 17:00:42 -0700 | [diff] [blame] | 58 | /* Default configuration parameters */ |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 59 | #define DEFAULT_TRX_PORT 5700 |
| 60 | #define DEFAULT_TRX_IP "127.0.0.1" |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 61 | #define DEFAULT_CHANS 1 |
| 62 | |
| 63 | struct trx_config { |
| 64 | std::string log_level; |
Pau Espin Pedrol | 8c80095 | 2017-08-16 16:53:23 +0200 | [diff] [blame] | 65 | std::string local_addr; |
| 66 | std::string remote_addr; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 67 | std::string dev_args; |
| 68 | unsigned port; |
Tom Tsou | 5cd70dc | 2016-03-06 01:28:40 -0800 | [diff] [blame] | 69 | unsigned tx_sps; |
| 70 | unsigned rx_sps; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 71 | unsigned chans; |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 72 | unsigned rtsc; |
Alexander Chemeris | 37c52c7 | 2016-03-25 18:28:34 +0300 | [diff] [blame] | 73 | unsigned rach_delay; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 74 | bool extref; |
Tom Tsou | 2f3e60b | 2016-07-17 19:29:08 -0700 | [diff] [blame] | 75 | bool gpsref; |
Alexander Chemeris | f5fd578 | 2015-05-24 18:56:51 -0400 | [diff] [blame] | 76 | Transceiver::FillerType filler; |
Tom Tsou | 7676427 | 2016-06-24 14:25:39 -0700 | [diff] [blame] | 77 | bool mcbts; |
Thomas Tsou | 8e17df7 | 2014-03-06 14:16:11 -0500 | [diff] [blame] | 78 | double offset; |
Alexander Chemeris | e8905a0 | 2015-06-03 23:47:56 -0400 | [diff] [blame] | 79 | double rssi_offset; |
Alexander Chemeris | 50747dc | 2015-06-07 01:07:45 -0400 | [diff] [blame] | 80 | bool swap_channels; |
Tom Tsou | b0aefcb | 2016-03-06 03:44:34 -0800 | [diff] [blame] | 81 | bool edge; |
Harald Welte | 81486e0 | 2017-06-29 15:35:22 +0200 | [diff] [blame] | 82 | int sched_rr; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 83 | }; |
| 84 | |
Thomas Tsou | 4de70be | 2013-11-17 18:54:52 -0500 | [diff] [blame] | 85 | ConfigurationTable gConfig; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 86 | |
| 87 | volatile bool gshutdown = false; |
| 88 | |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 89 | /* Setup configuration values |
| 90 | * Don't query the existence of the Log.Level because it's a |
| 91 | * mandatory value. That is, if it doesn't exist, the configuration |
Thomas Tsou | 4de70be | 2013-11-17 18:54:52 -0500 | [diff] [blame] | 92 | * table will crash or will have already crashed. Everything else we |
| 93 | * can survive without and use default values if the database entries |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 94 | * are empty. |
| 95 | */ |
| 96 | bool trx_setup_config(struct trx_config *config) |
| 97 | { |
Tom Tsou | 7676427 | 2016-06-24 14:25:39 -0700 | [diff] [blame] | 98 | std::string refstr, fillstr, divstr, mcstr, edgestr; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 99 | |
Tom Tsou | 6031734 | 2017-03-30 19:36:41 -0700 | [diff] [blame] | 100 | if (config->mcbts && config->chans > 5) { |
Tom Tsou | 7676427 | 2016-06-24 14:25:39 -0700 | [diff] [blame] | 101 | std::cout << "Unsupported number of channels" << std::endl; |
| 102 | return false; |
| 103 | } |
| 104 | |
Tom Tsou | b0aefcb | 2016-03-06 03:44:34 -0800 | [diff] [blame] | 105 | edgestr = config->edge ? "Enabled" : "Disabled"; |
Tom Tsou | 7676427 | 2016-06-24 14:25:39 -0700 | [diff] [blame] | 106 | mcstr = config->mcbts ? "Enabled" : "Disabled"; |
| 107 | |
Tom Tsou | 2f3e60b | 2016-07-17 19:29:08 -0700 | [diff] [blame] | 108 | if (config->extref) |
| 109 | refstr = "External"; |
| 110 | else if (config->gpsref) |
| 111 | refstr = "GPS"; |
| 112 | else |
| 113 | refstr = "Internal"; |
| 114 | |
Alexander Chemeris | f5fd578 | 2015-05-24 18:56:51 -0400 | [diff] [blame] | 115 | switch (config->filler) { |
| 116 | case Transceiver::FILLER_DUMMY: |
| 117 | fillstr = "Dummy bursts"; |
| 118 | break; |
| 119 | case Transceiver::FILLER_ZERO: |
| 120 | fillstr = "Disabled"; |
| 121 | break; |
Tom Tsou | af717b2 | 2016-03-06 22:19:15 -0800 | [diff] [blame] | 122 | case Transceiver::FILLER_NORM_RAND: |
Alexander Chemeris | f5fd578 | 2015-05-24 18:56:51 -0400 | [diff] [blame] | 123 | fillstr = "Normal busrts with random payload"; |
| 124 | break; |
Tom Tsou | af717b2 | 2016-03-06 22:19:15 -0800 | [diff] [blame] | 125 | case Transceiver::FILLER_EDGE_RAND: |
| 126 | fillstr = "EDGE busrts with random payload"; |
| 127 | break; |
Alexander Chemeris | 5efe050 | 2016-03-23 17:06:32 +0300 | [diff] [blame] | 128 | case Transceiver::FILLER_ACCESS_RAND: |
| 129 | fillstr = "Access busrts with random payload"; |
| 130 | break; |
Alexander Chemeris | f5fd578 | 2015-05-24 18:56:51 -0400 | [diff] [blame] | 131 | } |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 132 | |
| 133 | std::ostringstream ost(""); |
| 134 | ost << "Config Settings" << std::endl; |
| 135 | ost << " Log Level............... " << config->log_level << std::endl; |
| 136 | ost << " Device args............. " << config->dev_args << std::endl; |
| 137 | ost << " TRX Base Port........... " << config->port << std::endl; |
Pau Espin Pedrol | 8c80095 | 2017-08-16 16:53:23 +0200 | [diff] [blame] | 138 | ost << " TRX Address............. " << config->local_addr << std::endl; |
| 139 | ost << " GSM Core Address........." << config->remote_addr << std::endl; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 140 | ost << " Channels................ " << config->chans << std::endl; |
Tom Tsou | 5cd70dc | 2016-03-06 01:28:40 -0800 | [diff] [blame] | 141 | ost << " Tx Samples-per-Symbol... " << config->tx_sps << std::endl; |
Alexander Chemeris | 1ab5e7f | 2016-04-20 08:44:55 +0300 | [diff] [blame] | 142 | ost << " Rx Samples-per-Symbol... " << config->rx_sps << std::endl; |
Tom Tsou | b0aefcb | 2016-03-06 03:44:34 -0800 | [diff] [blame] | 143 | ost << " EDGE support............ " << edgestr << std::endl; |
Tom Tsou | 2f3e60b | 2016-07-17 19:29:08 -0700 | [diff] [blame] | 144 | ost << " Reference............... " << refstr << std::endl; |
Thomas Tsou | 15d743e | 2014-01-25 02:34:03 -0500 | [diff] [blame] | 145 | ost << " C0 Filler Table......... " << fillstr << std::endl; |
Tom Tsou | 7676427 | 2016-06-24 14:25:39 -0700 | [diff] [blame] | 146 | ost << " Multi-Carrier........... " << mcstr << std::endl; |
Thomas Tsou | 8e17df7 | 2014-03-06 14:16:11 -0500 | [diff] [blame] | 147 | ost << " Tuning offset........... " << config->offset << std::endl; |
Alexander Chemeris | e8905a0 | 2015-06-03 23:47:56 -0400 | [diff] [blame] | 148 | ost << " RSSI to dBm offset...... " << config->rssi_offset << std::endl; |
Alexander Chemeris | 50747dc | 2015-06-07 01:07:45 -0400 | [diff] [blame] | 149 | ost << " Swap channels........... " << config->swap_channels << std::endl; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 150 | std::cout << ost << std::endl; |
| 151 | |
| 152 | return true; |
| 153 | } |
| 154 | |
| 155 | /* Create radio interface |
| 156 | * The interface consists of sample rate changes, frequency shifts, |
| 157 | * channel multiplexing, and other conversions. The transceiver core |
| 158 | * accepts input vectors sampled at multiples of the GSM symbol rate. |
| 159 | * The radio interface connects the main transceiver with the device |
| 160 | * object, which may be operating some other rate. |
| 161 | */ |
| 162 | RadioInterface *makeRadioInterface(struct trx_config *config, |
| 163 | RadioDevice *usrp, int type) |
| 164 | { |
| 165 | RadioInterface *radio = NULL; |
| 166 | |
| 167 | switch (type) { |
| 168 | case RadioDevice::NORMAL: |
Tom Tsou | 5cd70dc | 2016-03-06 01:28:40 -0800 | [diff] [blame] | 169 | radio = new RadioInterface(usrp, config->tx_sps, |
| 170 | config->rx_sps, config->chans); |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 171 | break; |
| 172 | case RadioDevice::RESAMP_64M: |
| 173 | case RadioDevice::RESAMP_100M: |
Tom Tsou | 5cd70dc | 2016-03-06 01:28:40 -0800 | [diff] [blame] | 174 | radio = new RadioInterfaceResamp(usrp, config->tx_sps, |
Tom Tsou | 8f0ccf6 | 2016-07-20 16:35:03 -0700 | [diff] [blame] | 175 | config->rx_sps); |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 176 | break; |
Tom Tsou | 7676427 | 2016-06-24 14:25:39 -0700 | [diff] [blame] | 177 | case RadioDevice::MULTI_ARFCN: |
| 178 | radio = new RadioInterfaceMulti(usrp, config->tx_sps, |
| 179 | config->rx_sps, config->chans); |
| 180 | break; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 181 | default: |
| 182 | LOG(ALERT) << "Unsupported radio interface configuration"; |
| 183 | return NULL; |
| 184 | } |
| 185 | |
| 186 | if (!radio->init(type)) { |
| 187 | LOG(ALERT) << "Failed to initialize radio interface"; |
| 188 | return NULL; |
| 189 | } |
| 190 | |
| 191 | return radio; |
| 192 | } |
| 193 | |
| 194 | /* Create transceiver core |
| 195 | * The multi-threaded modem core operates at multiples of the GSM rate of |
| 196 | * 270.8333 ksps and consists of GSM specific modulation, demodulation, |
| 197 | * and decoding schemes. Also included are the socket interfaces for |
| 198 | * connecting to the upper layer stack. |
| 199 | */ |
| 200 | Transceiver *makeTransceiver(struct trx_config *config, RadioInterface *radio) |
| 201 | { |
| 202 | Transceiver *trx; |
| 203 | VectorFIFO *fifo; |
| 204 | |
Pau Espin Pedrol | 8c80095 | 2017-08-16 16:53:23 +0200 | [diff] [blame] | 205 | trx = new Transceiver(config->port, config->local_addr.c_str(), |
| 206 | config->remote_addr.c_str(), config->tx_sps, |
| 207 | config->rx_sps, config->chans, GSM::Time(3,0), |
| 208 | radio, config->rssi_offset); |
Tom Tsou | 64464e6 | 2016-07-01 03:46:46 -0700 | [diff] [blame] | 209 | if (!trx->init(config->filler, config->rtsc, |
| 210 | config->rach_delay, config->edge)) { |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 211 | LOG(ALERT) << "Failed to initialize transceiver"; |
| 212 | delete trx; |
| 213 | return NULL; |
| 214 | } |
| 215 | |
| 216 | for (size_t i = 0; i < config->chans; i++) { |
| 217 | fifo = radio->receiveFIFO(i); |
| 218 | if (fifo && trx->receiveFIFO(fifo, i)) |
| 219 | continue; |
| 220 | |
| 221 | LOG(ALERT) << "Could not attach FIFO to channel " << i; |
| 222 | delete trx; |
| 223 | return NULL; |
| 224 | } |
| 225 | |
| 226 | return trx; |
| 227 | } |
| 228 | |
| 229 | static void sig_handler(int signo) |
| 230 | { |
| 231 | fprintf(stdout, "Received shutdown signal"); |
| 232 | gshutdown = true; |
| 233 | } |
| 234 | |
| 235 | static void setup_signal_handlers() |
| 236 | { |
| 237 | if (signal(SIGINT, sig_handler) == SIG_ERR) { |
| 238 | fprintf(stderr, "Failed to install SIGINT signal handler\n"); |
| 239 | exit(EXIT_FAILURE); |
| 240 | } |
| 241 | if (signal(SIGTERM, sig_handler) == SIG_ERR) { |
| 242 | fprintf(stderr, "Couldn't install SIGTERM signal handler\n"); |
| 243 | exit( EXIT_FAILURE); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | static void print_help() |
| 248 | { |
| 249 | fprintf(stdout, "Options:\n" |
| 250 | " -h This text\n" |
| 251 | " -a UHD device args\n" |
| 252 | " -l Logging level (%s)\n" |
| 253 | " -i IP address of GSM core\n" |
Pau Espin Pedrol | 8c80095 | 2017-08-16 16:53:23 +0200 | [diff] [blame] | 254 | " -j IP address of osmo-trx\n" |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 255 | " -p Base port number\n" |
Tom Tsou | b0aefcb | 2016-03-06 03:44:34 -0800 | [diff] [blame] | 256 | " -e Enable EDGE receiver\n" |
Tom Tsou | 7676427 | 2016-06-24 14:25:39 -0700 | [diff] [blame] | 257 | " -m Enable multi-ARFCN transceiver (default=disabled)\n" |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 258 | " -x Enable external 10 MHz reference\n" |
Tom Tsou | 2f3e60b | 2016-07-17 19:29:08 -0700 | [diff] [blame] | 259 | " -g Enable GPSDO reference\n" |
Tom Tsou | 2e4ed10 | 2016-06-27 15:39:16 -0700 | [diff] [blame] | 260 | " -s Tx samples-per-symbol (1 or 4)\n" |
| 261 | " -b Rx samples-per-symbol (1 or 4)\n" |
Thomas Tsou | 15d743e | 2014-01-25 02:34:03 -0500 | [diff] [blame] | 262 | " -c Number of ARFCN channels (default=1)\n" |
Thomas Tsou | 8e17df7 | 2014-03-06 14:16:11 -0500 | [diff] [blame] | 263 | " -f Enable C0 filler table\n" |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 264 | " -o Set baseband frequency offset (default=auto)\n" |
Alexander Chemeris | 37c52c7 | 2016-03-25 18:28:34 +0300 | [diff] [blame] | 265 | " -r Random Normal Burst test mode with TSC\n" |
| 266 | " -A Random Access Burst test mode with delay\n" |
Alexander Chemeris | 50747dc | 2015-06-07 01:07:45 -0400 | [diff] [blame] | 267 | " -R RSSI to dBm offset in dB (default=0)\n" |
Harald Welte | 81486e0 | 2017-06-29 15:35:22 +0200 | [diff] [blame] | 268 | " -S Swap channels (UmTRX only)\n" |
| 269 | " -t SCHED_RR real-time priority (1..32)\n", |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 270 | "EMERG, ALERT, CRT, ERR, WARNING, NOTICE, INFO, DEBUG"); |
| 271 | } |
| 272 | |
| 273 | static void handle_options(int argc, char **argv, struct trx_config *config) |
| 274 | { |
| 275 | int option; |
| 276 | |
Tom Tsou | de116e9 | 2017-03-30 17:00:42 -0700 | [diff] [blame] | 277 | config->log_level = "NOTICE"; |
Pau Espin Pedrol | 8c80095 | 2017-08-16 16:53:23 +0200 | [diff] [blame] | 278 | config->local_addr = DEFAULT_TRX_IP; |
| 279 | config->remote_addr = DEFAULT_TRX_IP; |
Tom Tsou | de116e9 | 2017-03-30 17:00:42 -0700 | [diff] [blame] | 280 | config->port = DEFAULT_TRX_PORT; |
Tom Tsou | 5cd70dc | 2016-03-06 01:28:40 -0800 | [diff] [blame] | 281 | config->tx_sps = DEFAULT_TX_SPS; |
| 282 | config->rx_sps = DEFAULT_RX_SPS; |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 283 | config->chans = DEFAULT_CHANS; |
| 284 | config->rtsc = 0; |
Alexander Chemeris | 37c52c7 | 2016-03-25 18:28:34 +0300 | [diff] [blame] | 285 | config->rach_delay = 0; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 286 | config->extref = false; |
Tom Tsou | 2f3e60b | 2016-07-17 19:29:08 -0700 | [diff] [blame] | 287 | config->gpsref = false; |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 288 | config->filler = Transceiver::FILLER_ZERO; |
Tom Tsou | 7676427 | 2016-06-24 14:25:39 -0700 | [diff] [blame] | 289 | config->mcbts = false; |
Thomas Tsou | 8e17df7 | 2014-03-06 14:16:11 -0500 | [diff] [blame] | 290 | config->offset = 0.0; |
Alexander Chemeris | e8905a0 | 2015-06-03 23:47:56 -0400 | [diff] [blame] | 291 | config->rssi_offset = 0.0; |
Alexander Chemeris | 50747dc | 2015-06-07 01:07:45 -0400 | [diff] [blame] | 292 | config->swap_channels = false; |
Tom Tsou | b0aefcb | 2016-03-06 03:44:34 -0800 | [diff] [blame] | 293 | config->edge = false; |
Harald Welte | 81486e0 | 2017-06-29 15:35:22 +0200 | [diff] [blame] | 294 | config->sched_rr = -1; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 295 | |
Pau Espin Pedrol | 8c80095 | 2017-08-16 16:53:23 +0200 | [diff] [blame] | 296 | while ((option = getopt(argc, argv, "ha:l:i:j:p:c:dmxgfo:s:b:r:A:R:Set:")) != -1) { |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 297 | switch (option) { |
| 298 | case 'h': |
| 299 | print_help(); |
| 300 | exit(0); |
| 301 | break; |
| 302 | case 'a': |
| 303 | config->dev_args = optarg; |
| 304 | break; |
| 305 | case 'l': |
| 306 | config->log_level = optarg; |
| 307 | break; |
| 308 | case 'i': |
Pau Espin Pedrol | 8c80095 | 2017-08-16 16:53:23 +0200 | [diff] [blame] | 309 | config->remote_addr = optarg; |
| 310 | break; |
| 311 | case 'j': |
| 312 | config->local_addr = optarg; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 313 | break; |
| 314 | case 'p': |
| 315 | config->port = atoi(optarg); |
| 316 | break; |
| 317 | case 'c': |
| 318 | config->chans = atoi(optarg); |
| 319 | break; |
Tom Tsou | 7676427 | 2016-06-24 14:25:39 -0700 | [diff] [blame] | 320 | case 'm': |
| 321 | config->mcbts = true; |
| 322 | break; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 323 | case 'x': |
| 324 | config->extref = true; |
| 325 | break; |
Tom Tsou | 2f3e60b | 2016-07-17 19:29:08 -0700 | [diff] [blame] | 326 | case 'g': |
| 327 | config->gpsref = true; |
| 328 | break; |
Thomas Tsou | 15d743e | 2014-01-25 02:34:03 -0500 | [diff] [blame] | 329 | case 'f': |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 330 | config->filler = Transceiver::FILLER_DUMMY; |
Thomas Tsou | 15d743e | 2014-01-25 02:34:03 -0500 | [diff] [blame] | 331 | break; |
Thomas Tsou | 8e17df7 | 2014-03-06 14:16:11 -0500 | [diff] [blame] | 332 | case 'o': |
| 333 | config->offset = atof(optarg); |
| 334 | break; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 335 | case 's': |
Tom Tsou | 5cd70dc | 2016-03-06 01:28:40 -0800 | [diff] [blame] | 336 | config->tx_sps = atoi(optarg); |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 337 | break; |
Tom Tsou | 2e4ed10 | 2016-06-27 15:39:16 -0700 | [diff] [blame] | 338 | case 'b': |
| 339 | config->rx_sps = atoi(optarg); |
| 340 | break; |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 341 | case 'r': |
| 342 | config->rtsc = atoi(optarg); |
Tom Tsou | af717b2 | 2016-03-06 22:19:15 -0800 | [diff] [blame] | 343 | config->filler = Transceiver::FILLER_NORM_RAND; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 344 | break; |
Alexander Chemeris | 5efe050 | 2016-03-23 17:06:32 +0300 | [diff] [blame] | 345 | case 'A': |
Alexander Chemeris | 37c52c7 | 2016-03-25 18:28:34 +0300 | [diff] [blame] | 346 | config->rach_delay = atoi(optarg); |
Alexander Chemeris | 5efe050 | 2016-03-23 17:06:32 +0300 | [diff] [blame] | 347 | config->filler = Transceiver::FILLER_ACCESS_RAND; |
| 348 | break; |
Alexander Chemeris | e8905a0 | 2015-06-03 23:47:56 -0400 | [diff] [blame] | 349 | case 'R': |
| 350 | config->rssi_offset = atof(optarg); |
| 351 | break; |
Alexander Chemeris | 50747dc | 2015-06-07 01:07:45 -0400 | [diff] [blame] | 352 | case 'S': |
| 353 | config->swap_channels = true; |
| 354 | break; |
Tom Tsou | b0aefcb | 2016-03-06 03:44:34 -0800 | [diff] [blame] | 355 | case 'e': |
| 356 | config->edge = true; |
Tom Tsou | b0aefcb | 2016-03-06 03:44:34 -0800 | [diff] [blame] | 357 | break; |
Harald Welte | 81486e0 | 2017-06-29 15:35:22 +0200 | [diff] [blame] | 358 | case 't': |
| 359 | config->sched_rr = atoi(optarg); |
| 360 | break; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 361 | default: |
| 362 | print_help(); |
| 363 | exit(0); |
| 364 | } |
| 365 | } |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 366 | |
Tom Tsou | 7676427 | 2016-06-24 14:25:39 -0700 | [diff] [blame] | 367 | /* Force 4 SPS for EDGE or multi-ARFCN configurations */ |
| 368 | if ((config->edge) || (config->mcbts)) { |
Tom Tsou | 2e4ed10 | 2016-06-27 15:39:16 -0700 | [diff] [blame] | 369 | config->tx_sps = 4; |
| 370 | config->rx_sps = 4; |
| 371 | } |
| 372 | |
Tom Tsou | 8f0ccf6 | 2016-07-20 16:35:03 -0700 | [diff] [blame] | 373 | if (config->gpsref && config->extref) { |
| 374 | printf("External and GPSDO references unavailable at the same time\n\n"); |
| 375 | goto bad_config; |
| 376 | } |
| 377 | |
Tom Tsou | af717b2 | 2016-03-06 22:19:15 -0800 | [diff] [blame] | 378 | if (config->edge && (config->filler == Transceiver::FILLER_NORM_RAND)) |
| 379 | config->filler = Transceiver::FILLER_EDGE_RAND; |
| 380 | |
Tom Tsou | 7676427 | 2016-06-24 14:25:39 -0700 | [diff] [blame] | 381 | if ((config->tx_sps != 1) && (config->tx_sps != 4) && |
| 382 | (config->rx_sps != 1) && (config->rx_sps != 4)) { |
Tom Tsou | 5cd70dc | 2016-03-06 01:28:40 -0800 | [diff] [blame] | 383 | printf("Unsupported samples-per-symbol %i\n\n", config->tx_sps); |
Tom Tsou | 8f0ccf6 | 2016-07-20 16:35:03 -0700 | [diff] [blame] | 384 | goto bad_config; |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | if (config->rtsc > 7) { |
| 388 | printf("Invalid training sequence %i\n\n", config->rtsc); |
Tom Tsou | 8f0ccf6 | 2016-07-20 16:35:03 -0700 | [diff] [blame] | 389 | goto bad_config; |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 390 | } |
Alexander Chemeris | 37c52c7 | 2016-03-25 18:28:34 +0300 | [diff] [blame] | 391 | |
| 392 | if (config->rach_delay > 68) { |
| 393 | printf("RACH delay is too big %i\n\n", config->rach_delay); |
Tom Tsou | 8f0ccf6 | 2016-07-20 16:35:03 -0700 | [diff] [blame] | 394 | goto bad_config; |
Alexander Chemeris | 37c52c7 | 2016-03-25 18:28:34 +0300 | [diff] [blame] | 395 | } |
Tom Tsou | 8f0ccf6 | 2016-07-20 16:35:03 -0700 | [diff] [blame] | 396 | |
| 397 | return; |
| 398 | |
| 399 | bad_config: |
| 400 | print_help(); |
| 401 | exit(0); |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 402 | } |
| 403 | |
Harald Welte | 81486e0 | 2017-06-29 15:35:22 +0200 | [diff] [blame] | 404 | static int set_sched_rr(int prio) |
| 405 | { |
| 406 | struct sched_param param; |
| 407 | int rc; |
| 408 | memset(¶m, 0, sizeof(param)); |
| 409 | param.sched_priority = prio; |
| 410 | printf("Setting SCHED_RR priority(%d)\n", param.sched_priority); |
| 411 | rc = sched_setscheduler(getpid(), SCHED_RR, ¶m); |
| 412 | if (rc != 0) { |
| 413 | std::cerr << "Config: Setting SCHED_RR failed" << std::endl; |
| 414 | return -1; |
| 415 | } |
| 416 | return 0; |
| 417 | } |
| 418 | |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 419 | int main(int argc, char *argv[]) |
| 420 | { |
Tom Tsou | 2f3e60b | 2016-07-17 19:29:08 -0700 | [diff] [blame] | 421 | int type, chans, ref; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 422 | RadioDevice *usrp; |
| 423 | RadioInterface *radio = NULL; |
| 424 | Transceiver *trx = NULL; |
Tom Tsou | 05c6feb | 2016-06-22 16:09:44 -0700 | [diff] [blame] | 425 | RadioDevice::InterfaceType iface = RadioDevice::NORMAL; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 426 | struct trx_config config; |
| 427 | |
Philipp Maier | e51a8f0 | 2017-03-16 12:09:34 +0100 | [diff] [blame] | 428 | #ifdef HAVE_SSE3 |
| 429 | printf("Info: SSE3 support compiled in"); |
Vadim Yanitskiy | 3bd763d | 2017-05-20 01:46:51 +0300 | [diff] [blame] | 430 | #ifdef HAVE___BUILTIN_CPU_SUPPORTS |
Philipp Maier | e51a8f0 | 2017-03-16 12:09:34 +0100 | [diff] [blame] | 431 | if (__builtin_cpu_supports("sse3")) |
| 432 | printf(" and supported by CPU\n"); |
| 433 | else |
| 434 | printf(", but not supported by CPU\n"); |
Vadim Yanitskiy | 3bd763d | 2017-05-20 01:46:51 +0300 | [diff] [blame] | 435 | #else |
| 436 | printf(", but runtime SIMD detection disabled\n"); |
| 437 | #endif |
Philipp Maier | e51a8f0 | 2017-03-16 12:09:34 +0100 | [diff] [blame] | 438 | #endif |
| 439 | |
| 440 | #ifdef HAVE_SSE4_1 |
| 441 | printf("Info: SSE4.1 support compiled in"); |
Vadim Yanitskiy | 3bd763d | 2017-05-20 01:46:51 +0300 | [diff] [blame] | 442 | #ifdef HAVE___BUILTIN_CPU_SUPPORTS |
Philipp Maier | e51a8f0 | 2017-03-16 12:09:34 +0100 | [diff] [blame] | 443 | if (__builtin_cpu_supports("sse4.1")) |
| 444 | printf(" and supported by CPU\n"); |
| 445 | else |
| 446 | printf(", but not supported by CPU\n"); |
Vadim Yanitskiy | 3bd763d | 2017-05-20 01:46:51 +0300 | [diff] [blame] | 447 | #else |
| 448 | printf(", but runtime SIMD detection disabled\n"); |
| 449 | #endif |
Philipp Maier | e51a8f0 | 2017-03-16 12:09:34 +0100 | [diff] [blame] | 450 | #endif |
| 451 | |
Philipp Maier | 7e07cf2 | 2017-03-15 18:09:35 +0100 | [diff] [blame] | 452 | convolve_init(); |
| 453 | convert_init(); |
| 454 | |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 455 | handle_options(argc, argv, &config); |
| 456 | |
Harald Welte | 81486e0 | 2017-06-29 15:35:22 +0200 | [diff] [blame] | 457 | if (config.sched_rr != -1) { |
| 458 | if (set_sched_rr(config.sched_rr) < 0) |
| 459 | return EXIT_FAILURE; |
| 460 | } |
| 461 | |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 462 | setup_signal_handlers(); |
| 463 | |
| 464 | /* Check database sanity */ |
| 465 | if (!trx_setup_config(&config)) { |
| 466 | std::cerr << "Config: Database failure - exiting" << std::endl; |
| 467 | return EXIT_FAILURE; |
| 468 | } |
| 469 | |
| 470 | gLogInit("transceiver", config.log_level.c_str(), LOG_LOCAL7); |
| 471 | |
| 472 | srandom(time(NULL)); |
| 473 | |
| 474 | /* Create the low level device object */ |
Tom Tsou | 7676427 | 2016-06-24 14:25:39 -0700 | [diff] [blame] | 475 | if (config.mcbts) |
| 476 | iface = RadioDevice::MULTI_ARFCN; |
| 477 | |
Tom Tsou | 2f3e60b | 2016-07-17 19:29:08 -0700 | [diff] [blame] | 478 | if (config.extref) |
| 479 | ref = RadioDevice::REF_EXTERNAL; |
| 480 | else if (config.gpsref) |
| 481 | ref = RadioDevice::REF_GPS; |
| 482 | else |
| 483 | ref = RadioDevice::REF_INTERNAL; |
| 484 | |
Tom Tsou | 05c6feb | 2016-06-22 16:09:44 -0700 | [diff] [blame] | 485 | usrp = RadioDevice::make(config.tx_sps, config.rx_sps, iface, |
| 486 | config.chans, config.offset); |
Tom Tsou | 2f3e60b | 2016-07-17 19:29:08 -0700 | [diff] [blame] | 487 | type = usrp->open(config.dev_args, ref, config.swap_channels); |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 488 | if (type < 0) { |
| 489 | LOG(ALERT) << "Failed to create radio device" << std::endl; |
| 490 | goto shutdown; |
| 491 | } |
| 492 | |
| 493 | /* Setup the appropriate device interface */ |
| 494 | radio = makeRadioInterface(&config, usrp, type); |
| 495 | if (!radio) |
| 496 | goto shutdown; |
| 497 | |
| 498 | /* Create the transceiver core */ |
| 499 | trx = makeTransceiver(&config, radio); |
| 500 | if (!trx) |
| 501 | goto shutdown; |
| 502 | |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 503 | chans = trx->numChans(); |
| 504 | std::cout << "-- Transceiver active with " |
| 505 | << chans << " channel(s)" << std::endl; |
| 506 | |
| 507 | while (!gshutdown) |
| 508 | sleep(1); |
| 509 | |
| 510 | shutdown: |
| 511 | std::cout << "Shutting down transceiver..." << std::endl; |
| 512 | |
| 513 | delete trx; |
| 514 | delete radio; |
| 515 | delete usrp; |
| 516 | |
| 517 | return 0; |
| 518 | } |