blob: 3f72fb74ba90fe5c2566ac6a66b2e028bac6724f [file] [log] [blame]
Thomas Tsou85b179d2013-11-15 21:14:33 -05001/*
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 Welte81486e02017-06-29 15:35:22 +020030#include <sched.h>
Thomas Tsou85b179d2013-11-15 21:14:33 -050031
32#include <GSMCommon.h>
33#include <Logger.h>
34#include <Configuration.h>
35
Philipp Maier7e07cf22017-03-15 18:09:35 +010036extern "C" {
37#include "convolve.h"
38#include "convert.h"
39}
40
Thomas Tsou85b179d2013-11-15 21:14:33 -050041/* 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 Tsou0fe41a52016-05-03 15:14:45 -070046 * downsampled to 1 sps. Default to 4 sps for all cases.
Thomas Tsou85b179d2013-11-15 21:14:33 -050047 */
Tom Tsou5cd70dc2016-03-06 01:28:40 -080048#define DEFAULT_TX_SPS 4
Thomas Tsou85b179d2013-11-15 21:14:33 -050049
Tom Tsou5cd70dc2016-03-06 01:28:40 -080050/*
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 Tsoude116e92017-03-30 17:00:42 -070058/* Default configuration parameters */
Thomas Tsou85b179d2013-11-15 21:14:33 -050059#define DEFAULT_TRX_PORT 5700
60#define DEFAULT_TRX_IP "127.0.0.1"
Thomas Tsou85b179d2013-11-15 21:14:33 -050061#define DEFAULT_CHANS 1
62
63struct trx_config {
64 std::string log_level;
Pau Espin Pedrol8c800952017-08-16 16:53:23 +020065 std::string local_addr;
66 std::string remote_addr;
Thomas Tsou85b179d2013-11-15 21:14:33 -050067 std::string dev_args;
68 unsigned port;
Tom Tsou5cd70dc2016-03-06 01:28:40 -080069 unsigned tx_sps;
70 unsigned rx_sps;
Thomas Tsou85b179d2013-11-15 21:14:33 -050071 unsigned chans;
Tom Tsou64ad7122015-05-19 18:26:31 -070072 unsigned rtsc;
Alexander Chemeris37c52c72016-03-25 18:28:34 +030073 unsigned rach_delay;
Thomas Tsou85b179d2013-11-15 21:14:33 -050074 bool extref;
Tom Tsou2f3e60b2016-07-17 19:29:08 -070075 bool gpsref;
Alexander Chemerisf5fd5782015-05-24 18:56:51 -040076 Transceiver::FillerType filler;
Tom Tsou76764272016-06-24 14:25:39 -070077 bool mcbts;
Thomas Tsou8e17df72014-03-06 14:16:11 -050078 double offset;
Alexander Chemerise8905a02015-06-03 23:47:56 -040079 double rssi_offset;
Alexander Chemeris50747dc2015-06-07 01:07:45 -040080 bool swap_channels;
Tom Tsoub0aefcb2016-03-06 03:44:34 -080081 bool edge;
Harald Welte81486e02017-06-29 15:35:22 +020082 int sched_rr;
Thomas Tsou85b179d2013-11-15 21:14:33 -050083};
84
Thomas Tsou4de70be2013-11-17 18:54:52 -050085ConfigurationTable gConfig;
Thomas Tsou85b179d2013-11-15 21:14:33 -050086
87volatile bool gshutdown = false;
88
Thomas Tsou85b179d2013-11-15 21:14:33 -050089/* 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 Tsou4de70be2013-11-17 18:54:52 -050092 * table will crash or will have already crashed. Everything else we
93 * can survive without and use default values if the database entries
Thomas Tsou85b179d2013-11-15 21:14:33 -050094 * are empty.
95 */
96bool trx_setup_config(struct trx_config *config)
97{
Tom Tsou76764272016-06-24 14:25:39 -070098 std::string refstr, fillstr, divstr, mcstr, edgestr;
Thomas Tsou85b179d2013-11-15 21:14:33 -050099
Tom Tsou60317342017-03-30 19:36:41 -0700100 if (config->mcbts && config->chans > 5) {
Tom Tsou76764272016-06-24 14:25:39 -0700101 std::cout << "Unsupported number of channels" << std::endl;
102 return false;
103 }
104
Tom Tsoub0aefcb2016-03-06 03:44:34 -0800105 edgestr = config->edge ? "Enabled" : "Disabled";
Tom Tsou76764272016-06-24 14:25:39 -0700106 mcstr = config->mcbts ? "Enabled" : "Disabled";
107
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700108 if (config->extref)
109 refstr = "External";
110 else if (config->gpsref)
111 refstr = "GPS";
112 else
113 refstr = "Internal";
114
Alexander Chemerisf5fd5782015-05-24 18:56:51 -0400115 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 Tsouaf717b22016-03-06 22:19:15 -0800122 case Transceiver::FILLER_NORM_RAND:
Alexander Chemerisf5fd5782015-05-24 18:56:51 -0400123 fillstr = "Normal busrts with random payload";
124 break;
Tom Tsouaf717b22016-03-06 22:19:15 -0800125 case Transceiver::FILLER_EDGE_RAND:
126 fillstr = "EDGE busrts with random payload";
127 break;
Alexander Chemeris5efe0502016-03-23 17:06:32 +0300128 case Transceiver::FILLER_ACCESS_RAND:
129 fillstr = "Access busrts with random payload";
130 break;
Alexander Chemerisf5fd5782015-05-24 18:56:51 -0400131 }
Thomas Tsou85b179d2013-11-15 21:14:33 -0500132
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 Pedrol8c800952017-08-16 16:53:23 +0200138 ost << " TRX Address............. " << config->local_addr << std::endl;
139 ost << " GSM Core Address........." << config->remote_addr << std::endl;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500140 ost << " Channels................ " << config->chans << std::endl;
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800141 ost << " Tx Samples-per-Symbol... " << config->tx_sps << std::endl;
Alexander Chemeris1ab5e7f2016-04-20 08:44:55 +0300142 ost << " Rx Samples-per-Symbol... " << config->rx_sps << std::endl;
Tom Tsoub0aefcb2016-03-06 03:44:34 -0800143 ost << " EDGE support............ " << edgestr << std::endl;
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700144 ost << " Reference............... " << refstr << std::endl;
Thomas Tsou15d743e2014-01-25 02:34:03 -0500145 ost << " C0 Filler Table......... " << fillstr << std::endl;
Tom Tsou76764272016-06-24 14:25:39 -0700146 ost << " Multi-Carrier........... " << mcstr << std::endl;
Thomas Tsou8e17df72014-03-06 14:16:11 -0500147 ost << " Tuning offset........... " << config->offset << std::endl;
Alexander Chemerise8905a02015-06-03 23:47:56 -0400148 ost << " RSSI to dBm offset...... " << config->rssi_offset << std::endl;
Alexander Chemeris50747dc2015-06-07 01:07:45 -0400149 ost << " Swap channels........... " << config->swap_channels << std::endl;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500150 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 */
162RadioInterface *makeRadioInterface(struct trx_config *config,
163 RadioDevice *usrp, int type)
164{
165 RadioInterface *radio = NULL;
166
167 switch (type) {
168 case RadioDevice::NORMAL:
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800169 radio = new RadioInterface(usrp, config->tx_sps,
170 config->rx_sps, config->chans);
Thomas Tsou85b179d2013-11-15 21:14:33 -0500171 break;
172 case RadioDevice::RESAMP_64M:
173 case RadioDevice::RESAMP_100M:
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800174 radio = new RadioInterfaceResamp(usrp, config->tx_sps,
Tom Tsou8f0ccf62016-07-20 16:35:03 -0700175 config->rx_sps);
Thomas Tsou85b179d2013-11-15 21:14:33 -0500176 break;
Tom Tsou76764272016-06-24 14:25:39 -0700177 case RadioDevice::MULTI_ARFCN:
178 radio = new RadioInterfaceMulti(usrp, config->tx_sps,
179 config->rx_sps, config->chans);
180 break;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500181 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 */
200Transceiver *makeTransceiver(struct trx_config *config, RadioInterface *radio)
201{
202 Transceiver *trx;
203 VectorFIFO *fifo;
204
Pau Espin Pedrol8c800952017-08-16 16:53:23 +0200205 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 Tsou64464e62016-07-01 03:46:46 -0700209 if (!trx->init(config->filler, config->rtsc,
210 config->rach_delay, config->edge)) {
Thomas Tsou85b179d2013-11-15 21:14:33 -0500211 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
229static void sig_handler(int signo)
230{
231 fprintf(stdout, "Received shutdown signal");
232 gshutdown = true;
233}
234
235static 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
247static 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 Pedrol8c800952017-08-16 16:53:23 +0200254 " -j IP address of osmo-trx\n"
Thomas Tsou85b179d2013-11-15 21:14:33 -0500255 " -p Base port number\n"
Tom Tsoub0aefcb2016-03-06 03:44:34 -0800256 " -e Enable EDGE receiver\n"
Tom Tsou76764272016-06-24 14:25:39 -0700257 " -m Enable multi-ARFCN transceiver (default=disabled)\n"
Thomas Tsou85b179d2013-11-15 21:14:33 -0500258 " -x Enable external 10 MHz reference\n"
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700259 " -g Enable GPSDO reference\n"
Tom Tsou2e4ed102016-06-27 15:39:16 -0700260 " -s Tx samples-per-symbol (1 or 4)\n"
261 " -b Rx samples-per-symbol (1 or 4)\n"
Thomas Tsou15d743e2014-01-25 02:34:03 -0500262 " -c Number of ARFCN channels (default=1)\n"
Thomas Tsou8e17df72014-03-06 14:16:11 -0500263 " -f Enable C0 filler table\n"
Tom Tsou64ad7122015-05-19 18:26:31 -0700264 " -o Set baseband frequency offset (default=auto)\n"
Alexander Chemeris37c52c72016-03-25 18:28:34 +0300265 " -r Random Normal Burst test mode with TSC\n"
266 " -A Random Access Burst test mode with delay\n"
Alexander Chemeris50747dc2015-06-07 01:07:45 -0400267 " -R RSSI to dBm offset in dB (default=0)\n"
Harald Welte81486e02017-06-29 15:35:22 +0200268 " -S Swap channels (UmTRX only)\n"
269 " -t SCHED_RR real-time priority (1..32)\n",
Thomas Tsou85b179d2013-11-15 21:14:33 -0500270 "EMERG, ALERT, CRT, ERR, WARNING, NOTICE, INFO, DEBUG");
271}
272
273static void handle_options(int argc, char **argv, struct trx_config *config)
274{
275 int option;
276
Tom Tsoude116e92017-03-30 17:00:42 -0700277 config->log_level = "NOTICE";
Pau Espin Pedrol8c800952017-08-16 16:53:23 +0200278 config->local_addr = DEFAULT_TRX_IP;
279 config->remote_addr = DEFAULT_TRX_IP;
Tom Tsoude116e92017-03-30 17:00:42 -0700280 config->port = DEFAULT_TRX_PORT;
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800281 config->tx_sps = DEFAULT_TX_SPS;
282 config->rx_sps = DEFAULT_RX_SPS;
Tom Tsou64ad7122015-05-19 18:26:31 -0700283 config->chans = DEFAULT_CHANS;
284 config->rtsc = 0;
Alexander Chemeris37c52c72016-03-25 18:28:34 +0300285 config->rach_delay = 0;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500286 config->extref = false;
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700287 config->gpsref = false;
Tom Tsou64ad7122015-05-19 18:26:31 -0700288 config->filler = Transceiver::FILLER_ZERO;
Tom Tsou76764272016-06-24 14:25:39 -0700289 config->mcbts = false;
Thomas Tsou8e17df72014-03-06 14:16:11 -0500290 config->offset = 0.0;
Alexander Chemerise8905a02015-06-03 23:47:56 -0400291 config->rssi_offset = 0.0;
Alexander Chemeris50747dc2015-06-07 01:07:45 -0400292 config->swap_channels = false;
Tom Tsoub0aefcb2016-03-06 03:44:34 -0800293 config->edge = false;
Harald Welte81486e02017-06-29 15:35:22 +0200294 config->sched_rr = -1;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500295
Pau Espin Pedrol8c800952017-08-16 16:53:23 +0200296 while ((option = getopt(argc, argv, "ha:l:i:j:p:c:dmxgfo:s:b:r:A:R:Set:")) != -1) {
Thomas Tsou85b179d2013-11-15 21:14:33 -0500297 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 Pedrol8c800952017-08-16 16:53:23 +0200309 config->remote_addr = optarg;
310 break;
311 case 'j':
312 config->local_addr = optarg;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500313 break;
314 case 'p':
315 config->port = atoi(optarg);
316 break;
317 case 'c':
318 config->chans = atoi(optarg);
319 break;
Tom Tsou76764272016-06-24 14:25:39 -0700320 case 'm':
321 config->mcbts = true;
322 break;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500323 case 'x':
324 config->extref = true;
325 break;
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700326 case 'g':
327 config->gpsref = true;
328 break;
Thomas Tsou15d743e2014-01-25 02:34:03 -0500329 case 'f':
Tom Tsou64ad7122015-05-19 18:26:31 -0700330 config->filler = Transceiver::FILLER_DUMMY;
Thomas Tsou15d743e2014-01-25 02:34:03 -0500331 break;
Thomas Tsou8e17df72014-03-06 14:16:11 -0500332 case 'o':
333 config->offset = atof(optarg);
334 break;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500335 case 's':
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800336 config->tx_sps = atoi(optarg);
Tom Tsou64ad7122015-05-19 18:26:31 -0700337 break;
Tom Tsou2e4ed102016-06-27 15:39:16 -0700338 case 'b':
339 config->rx_sps = atoi(optarg);
340 break;
Tom Tsou64ad7122015-05-19 18:26:31 -0700341 case 'r':
342 config->rtsc = atoi(optarg);
Tom Tsouaf717b22016-03-06 22:19:15 -0800343 config->filler = Transceiver::FILLER_NORM_RAND;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500344 break;
Alexander Chemeris5efe0502016-03-23 17:06:32 +0300345 case 'A':
Alexander Chemeris37c52c72016-03-25 18:28:34 +0300346 config->rach_delay = atoi(optarg);
Alexander Chemeris5efe0502016-03-23 17:06:32 +0300347 config->filler = Transceiver::FILLER_ACCESS_RAND;
348 break;
Alexander Chemerise8905a02015-06-03 23:47:56 -0400349 case 'R':
350 config->rssi_offset = atof(optarg);
351 break;
Alexander Chemeris50747dc2015-06-07 01:07:45 -0400352 case 'S':
353 config->swap_channels = true;
354 break;
Tom Tsoub0aefcb2016-03-06 03:44:34 -0800355 case 'e':
356 config->edge = true;
Tom Tsoub0aefcb2016-03-06 03:44:34 -0800357 break;
Harald Welte81486e02017-06-29 15:35:22 +0200358 case 't':
359 config->sched_rr = atoi(optarg);
360 break;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500361 default:
362 print_help();
363 exit(0);
364 }
365 }
Tom Tsou64ad7122015-05-19 18:26:31 -0700366
Tom Tsou76764272016-06-24 14:25:39 -0700367 /* Force 4 SPS for EDGE or multi-ARFCN configurations */
368 if ((config->edge) || (config->mcbts)) {
Tom Tsou2e4ed102016-06-27 15:39:16 -0700369 config->tx_sps = 4;
370 config->rx_sps = 4;
371 }
372
Tom Tsou8f0ccf62016-07-20 16:35:03 -0700373 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 Tsouaf717b22016-03-06 22:19:15 -0800378 if (config->edge && (config->filler == Transceiver::FILLER_NORM_RAND))
379 config->filler = Transceiver::FILLER_EDGE_RAND;
380
Tom Tsou76764272016-06-24 14:25:39 -0700381 if ((config->tx_sps != 1) && (config->tx_sps != 4) &&
382 (config->rx_sps != 1) && (config->rx_sps != 4)) {
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800383 printf("Unsupported samples-per-symbol %i\n\n", config->tx_sps);
Tom Tsou8f0ccf62016-07-20 16:35:03 -0700384 goto bad_config;
Tom Tsou64ad7122015-05-19 18:26:31 -0700385 }
386
387 if (config->rtsc > 7) {
388 printf("Invalid training sequence %i\n\n", config->rtsc);
Tom Tsou8f0ccf62016-07-20 16:35:03 -0700389 goto bad_config;
Tom Tsou64ad7122015-05-19 18:26:31 -0700390 }
Alexander Chemeris37c52c72016-03-25 18:28:34 +0300391
392 if (config->rach_delay > 68) {
393 printf("RACH delay is too big %i\n\n", config->rach_delay);
Tom Tsou8f0ccf62016-07-20 16:35:03 -0700394 goto bad_config;
Alexander Chemeris37c52c72016-03-25 18:28:34 +0300395 }
Tom Tsou8f0ccf62016-07-20 16:35:03 -0700396
397 return;
398
399bad_config:
400 print_help();
401 exit(0);
Thomas Tsou85b179d2013-11-15 21:14:33 -0500402}
403
Harald Welte81486e02017-06-29 15:35:22 +0200404static int set_sched_rr(int prio)
405{
406 struct sched_param param;
407 int rc;
408 memset(&param, 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, &param);
412 if (rc != 0) {
413 std::cerr << "Config: Setting SCHED_RR failed" << std::endl;
414 return -1;
415 }
416 return 0;
417}
418
Thomas Tsou85b179d2013-11-15 21:14:33 -0500419int main(int argc, char *argv[])
420{
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700421 int type, chans, ref;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500422 RadioDevice *usrp;
423 RadioInterface *radio = NULL;
424 Transceiver *trx = NULL;
Tom Tsou05c6feb2016-06-22 16:09:44 -0700425 RadioDevice::InterfaceType iface = RadioDevice::NORMAL;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500426 struct trx_config config;
427
Philipp Maiere51a8f02017-03-16 12:09:34 +0100428#ifdef HAVE_SSE3
429 printf("Info: SSE3 support compiled in");
Vadim Yanitskiy3bd763d2017-05-20 01:46:51 +0300430#ifdef HAVE___BUILTIN_CPU_SUPPORTS
Philipp Maiere51a8f02017-03-16 12:09:34 +0100431 if (__builtin_cpu_supports("sse3"))
432 printf(" and supported by CPU\n");
433 else
434 printf(", but not supported by CPU\n");
Vadim Yanitskiy3bd763d2017-05-20 01:46:51 +0300435#else
436 printf(", but runtime SIMD detection disabled\n");
437#endif
Philipp Maiere51a8f02017-03-16 12:09:34 +0100438#endif
439
440#ifdef HAVE_SSE4_1
441 printf("Info: SSE4.1 support compiled in");
Vadim Yanitskiy3bd763d2017-05-20 01:46:51 +0300442#ifdef HAVE___BUILTIN_CPU_SUPPORTS
Philipp Maiere51a8f02017-03-16 12:09:34 +0100443 if (__builtin_cpu_supports("sse4.1"))
444 printf(" and supported by CPU\n");
445 else
446 printf(", but not supported by CPU\n");
Vadim Yanitskiy3bd763d2017-05-20 01:46:51 +0300447#else
448 printf(", but runtime SIMD detection disabled\n");
449#endif
Philipp Maiere51a8f02017-03-16 12:09:34 +0100450#endif
451
Philipp Maier7e07cf22017-03-15 18:09:35 +0100452 convolve_init();
453 convert_init();
454
Thomas Tsou85b179d2013-11-15 21:14:33 -0500455 handle_options(argc, argv, &config);
456
Harald Welte81486e02017-06-29 15:35:22 +0200457 if (config.sched_rr != -1) {
458 if (set_sched_rr(config.sched_rr) < 0)
459 return EXIT_FAILURE;
460 }
461
Thomas Tsou85b179d2013-11-15 21:14:33 -0500462 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 Tsou76764272016-06-24 14:25:39 -0700475 if (config.mcbts)
476 iface = RadioDevice::MULTI_ARFCN;
477
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700478 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 Tsou05c6feb2016-06-22 16:09:44 -0700485 usrp = RadioDevice::make(config.tx_sps, config.rx_sps, iface,
486 config.chans, config.offset);
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700487 type = usrp->open(config.dev_args, ref, config.swap_channels);
Thomas Tsou85b179d2013-11-15 21:14:33 -0500488 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 Tsou85b179d2013-11-15 21:14:33 -0500503 chans = trx->numChans();
504 std::cout << "-- Transceiver active with "
505 << chans << " channel(s)" << std::endl;
506
507 while (!gshutdown)
508 sleep(1);
509
510shutdown:
511 std::cout << "Shutting down transceiver..." << std::endl;
512
513 delete trx;
514 delete radio;
515 delete usrp;
516
517 return 0;
518}