blob: 8c3489313cb665a682a61d0386e66d1e1c348205 [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>
Pau Espin Pedrol77ce99a2018-02-05 13:05:06 +010031#include <vector>
32#include <string>
33#include <sstream>
34#include <iostream>
Thomas Tsou85b179d2013-11-15 21:14:33 -050035
36#include <GSMCommon.h>
37#include <Logger.h>
Thomas Tsou85b179d2013-11-15 21:14:33 -050038
Philipp Maier7e07cf22017-03-15 18:09:35 +010039extern "C" {
40#include "convolve.h"
41#include "convert.h"
42}
43
Thomas Tsou85b179d2013-11-15 21:14:33 -050044/* Samples-per-symbol for downlink path
45 * 4 - Uses precision modulator (more computation, less distortion)
46 * 1 - Uses minimized modulator (less computation, more distortion)
47 *
48 * Other values are invalid. Receive path (uplink) is always
Tom Tsou0fe41a52016-05-03 15:14:45 -070049 * downsampled to 1 sps. Default to 4 sps for all cases.
Thomas Tsou85b179d2013-11-15 21:14:33 -050050 */
Tom Tsou5cd70dc2016-03-06 01:28:40 -080051#define DEFAULT_TX_SPS 4
Thomas Tsou85b179d2013-11-15 21:14:33 -050052
Tom Tsou5cd70dc2016-03-06 01:28:40 -080053/*
54 * Samples-per-symbol for uplink (receiver) path
55 * Do not modify this value. EDGE configures 4 sps automatically on
56 * B200/B210 devices only. Use of 4 sps on the receive path for other
57 * configurations is not supported.
58 */
59#define DEFAULT_RX_SPS 1
60
Tom Tsoude116e92017-03-30 17:00:42 -070061/* Default configuration parameters */
Thomas Tsou85b179d2013-11-15 21:14:33 -050062#define DEFAULT_TRX_PORT 5700
63#define DEFAULT_TRX_IP "127.0.0.1"
Thomas Tsou85b179d2013-11-15 21:14:33 -050064#define DEFAULT_CHANS 1
65
66struct trx_config {
67 std::string log_level;
Pau Espin Pedrol8c800952017-08-16 16:53:23 +020068 std::string local_addr;
69 std::string remote_addr;
Thomas Tsou85b179d2013-11-15 21:14:33 -050070 std::string dev_args;
71 unsigned port;
Tom Tsou5cd70dc2016-03-06 01:28:40 -080072 unsigned tx_sps;
73 unsigned rx_sps;
Thomas Tsou85b179d2013-11-15 21:14:33 -050074 unsigned chans;
Tom Tsou64ad7122015-05-19 18:26:31 -070075 unsigned rtsc;
Alexander Chemeris37c52c72016-03-25 18:28:34 +030076 unsigned rach_delay;
Thomas Tsou85b179d2013-11-15 21:14:33 -050077 bool extref;
Tom Tsou2f3e60b2016-07-17 19:29:08 -070078 bool gpsref;
Alexander Chemerisf5fd5782015-05-24 18:56:51 -040079 Transceiver::FillerType filler;
Tom Tsou76764272016-06-24 14:25:39 -070080 bool mcbts;
Thomas Tsou8e17df72014-03-06 14:16:11 -050081 double offset;
Alexander Chemerise8905a02015-06-03 23:47:56 -040082 double rssi_offset;
Alexander Chemeris50747dc2015-06-07 01:07:45 -040083 bool swap_channels;
Tom Tsoub0aefcb2016-03-06 03:44:34 -080084 bool edge;
Harald Welte81486e02017-06-29 15:35:22 +020085 int sched_rr;
Pau Espin Pedrol77ce99a2018-02-05 13:05:06 +010086 std::vector<std::string> rx_paths;
87 std::vector<std::string> tx_paths;
Thomas Tsou85b179d2013-11-15 21:14:33 -050088};
89
Thomas Tsou85b179d2013-11-15 21:14:33 -050090volatile bool gshutdown = false;
91
Thomas Tsou85b179d2013-11-15 21:14:33 -050092/* Setup configuration values
93 * Don't query the existence of the Log.Level because it's a
94 * mandatory value. That is, if it doesn't exist, the configuration
Thomas Tsou4de70be2013-11-17 18:54:52 -050095 * table will crash or will have already crashed. Everything else we
96 * can survive without and use default values if the database entries
Thomas Tsou85b179d2013-11-15 21:14:33 -050097 * are empty.
98 */
99bool trx_setup_config(struct trx_config *config)
100{
Tom Tsou76764272016-06-24 14:25:39 -0700101 std::string refstr, fillstr, divstr, mcstr, edgestr;
Pau Espin Pedrol77ce99a2018-02-05 13:05:06 +0100102 std::vector<std::string>::const_iterator si;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500103
Tom Tsou60317342017-03-30 19:36:41 -0700104 if (config->mcbts && config->chans > 5) {
Tom Tsou76764272016-06-24 14:25:39 -0700105 std::cout << "Unsupported number of channels" << std::endl;
106 return false;
107 }
108
Tom Tsoub0aefcb2016-03-06 03:44:34 -0800109 edgestr = config->edge ? "Enabled" : "Disabled";
Tom Tsou76764272016-06-24 14:25:39 -0700110 mcstr = config->mcbts ? "Enabled" : "Disabled";
111
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700112 if (config->extref)
113 refstr = "External";
114 else if (config->gpsref)
115 refstr = "GPS";
116 else
117 refstr = "Internal";
118
Alexander Chemerisf5fd5782015-05-24 18:56:51 -0400119 switch (config->filler) {
120 case Transceiver::FILLER_DUMMY:
121 fillstr = "Dummy bursts";
122 break;
123 case Transceiver::FILLER_ZERO:
124 fillstr = "Disabled";
125 break;
Tom Tsouaf717b22016-03-06 22:19:15 -0800126 case Transceiver::FILLER_NORM_RAND:
Alexander Chemerisf5fd5782015-05-24 18:56:51 -0400127 fillstr = "Normal busrts with random payload";
128 break;
Tom Tsouaf717b22016-03-06 22:19:15 -0800129 case Transceiver::FILLER_EDGE_RAND:
130 fillstr = "EDGE busrts with random payload";
131 break;
Alexander Chemeris5efe0502016-03-23 17:06:32 +0300132 case Transceiver::FILLER_ACCESS_RAND:
133 fillstr = "Access busrts with random payload";
134 break;
Alexander Chemerisf5fd5782015-05-24 18:56:51 -0400135 }
Thomas Tsou85b179d2013-11-15 21:14:33 -0500136
137 std::ostringstream ost("");
138 ost << "Config Settings" << std::endl;
139 ost << " Log Level............... " << config->log_level << std::endl;
140 ost << " Device args............. " << config->dev_args << std::endl;
141 ost << " TRX Base Port........... " << config->port << std::endl;
Pau Espin Pedrol8c800952017-08-16 16:53:23 +0200142 ost << " TRX Address............. " << config->local_addr << std::endl;
143 ost << " GSM Core Address........." << config->remote_addr << std::endl;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500144 ost << " Channels................ " << config->chans << std::endl;
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800145 ost << " Tx Samples-per-Symbol... " << config->tx_sps << std::endl;
Alexander Chemeris1ab5e7f2016-04-20 08:44:55 +0300146 ost << " Rx Samples-per-Symbol... " << config->rx_sps << std::endl;
Tom Tsoub0aefcb2016-03-06 03:44:34 -0800147 ost << " EDGE support............ " << edgestr << std::endl;
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700148 ost << " Reference............... " << refstr << std::endl;
Thomas Tsou15d743e2014-01-25 02:34:03 -0500149 ost << " C0 Filler Table......... " << fillstr << std::endl;
Tom Tsou76764272016-06-24 14:25:39 -0700150 ost << " Multi-Carrier........... " << mcstr << std::endl;
Thomas Tsou8e17df72014-03-06 14:16:11 -0500151 ost << " Tuning offset........... " << config->offset << std::endl;
Alexander Chemerise8905a02015-06-03 23:47:56 -0400152 ost << " RSSI to dBm offset...... " << config->rssi_offset << std::endl;
Alexander Chemeris50747dc2015-06-07 01:07:45 -0400153 ost << " Swap channels........... " << config->swap_channels << std::endl;
Pau Espin Pedrol77ce99a2018-02-05 13:05:06 +0100154 ost << " Tx Antennas.............";
155 for (si = config->tx_paths.begin(); si != config->tx_paths.end(); ++si)
156 ost << " '" << ((*si != "") ? *si : "<default>") << "'";
157 ost << std::endl;
158 ost << " Rx Antennas.............";
159 for (si = config->rx_paths.begin(); si != config->rx_paths.end(); ++si)
160 ost << " '" << ((*si != "") ? *si : "<default>") << "'";
161 ost << std::endl;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500162
Pau Espin Pedrol77ce99a2018-02-05 13:05:06 +0100163 std::cout << ost << std::endl;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500164 return true;
165}
166
167/* Create radio interface
168 * The interface consists of sample rate changes, frequency shifts,
169 * channel multiplexing, and other conversions. The transceiver core
170 * accepts input vectors sampled at multiples of the GSM symbol rate.
171 * The radio interface connects the main transceiver with the device
172 * object, which may be operating some other rate.
173 */
174RadioInterface *makeRadioInterface(struct trx_config *config,
175 RadioDevice *usrp, int type)
176{
177 RadioInterface *radio = NULL;
178
179 switch (type) {
180 case RadioDevice::NORMAL:
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800181 radio = new RadioInterface(usrp, config->tx_sps,
182 config->rx_sps, config->chans);
Thomas Tsou85b179d2013-11-15 21:14:33 -0500183 break;
184 case RadioDevice::RESAMP_64M:
185 case RadioDevice::RESAMP_100M:
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800186 radio = new RadioInterfaceResamp(usrp, config->tx_sps,
Tom Tsou8f0ccf62016-07-20 16:35:03 -0700187 config->rx_sps);
Thomas Tsou85b179d2013-11-15 21:14:33 -0500188 break;
Tom Tsou76764272016-06-24 14:25:39 -0700189 case RadioDevice::MULTI_ARFCN:
190 radio = new RadioInterfaceMulti(usrp, config->tx_sps,
191 config->rx_sps, config->chans);
192 break;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500193 default:
194 LOG(ALERT) << "Unsupported radio interface configuration";
195 return NULL;
196 }
197
198 if (!radio->init(type)) {
199 LOG(ALERT) << "Failed to initialize radio interface";
200 return NULL;
201 }
202
203 return radio;
204}
205
206/* Create transceiver core
207 * The multi-threaded modem core operates at multiples of the GSM rate of
208 * 270.8333 ksps and consists of GSM specific modulation, demodulation,
209 * and decoding schemes. Also included are the socket interfaces for
210 * connecting to the upper layer stack.
211 */
212Transceiver *makeTransceiver(struct trx_config *config, RadioInterface *radio)
213{
214 Transceiver *trx;
215 VectorFIFO *fifo;
216
Pau Espin Pedrol8c800952017-08-16 16:53:23 +0200217 trx = new Transceiver(config->port, config->local_addr.c_str(),
218 config->remote_addr.c_str(), config->tx_sps,
219 config->rx_sps, config->chans, GSM::Time(3,0),
220 radio, config->rssi_offset);
Tom Tsou64464e62016-07-01 03:46:46 -0700221 if (!trx->init(config->filler, config->rtsc,
222 config->rach_delay, config->edge)) {
Thomas Tsou85b179d2013-11-15 21:14:33 -0500223 LOG(ALERT) << "Failed to initialize transceiver";
224 delete trx;
225 return NULL;
226 }
227
228 for (size_t i = 0; i < config->chans; i++) {
229 fifo = radio->receiveFIFO(i);
230 if (fifo && trx->receiveFIFO(fifo, i))
231 continue;
232
233 LOG(ALERT) << "Could not attach FIFO to channel " << i;
234 delete trx;
235 return NULL;
236 }
237
238 return trx;
239}
240
241static void sig_handler(int signo)
242{
243 fprintf(stdout, "Received shutdown signal");
244 gshutdown = true;
245}
246
247static void setup_signal_handlers()
248{
249 if (signal(SIGINT, sig_handler) == SIG_ERR) {
250 fprintf(stderr, "Failed to install SIGINT signal handler\n");
251 exit(EXIT_FAILURE);
252 }
253 if (signal(SIGTERM, sig_handler) == SIG_ERR) {
254 fprintf(stderr, "Couldn't install SIGTERM signal handler\n");
255 exit( EXIT_FAILURE);
256 }
257}
258
Pau Espin Pedrol77ce99a2018-02-05 13:05:06 +0100259
260static std::vector<std::string> comma_delimited_to_vector(char* opt) {
261 std::string str = std::string(opt);
262 std::vector<std::string> result;
263 std::stringstream ss(str);
264
265 while( ss.good() )
266 {
267 std::string substr;
268 getline(ss, substr, ',');
269 result.push_back(substr);
270 }
271 return result;
272}
273
Thomas Tsou85b179d2013-11-15 21:14:33 -0500274static void print_help()
275{
276 fprintf(stdout, "Options:\n"
277 " -h This text\n"
278 " -a UHD device args\n"
279 " -l Logging level (%s)\n"
280 " -i IP address of GSM core\n"
Pau Espin Pedrol8c800952017-08-16 16:53:23 +0200281 " -j IP address of osmo-trx\n"
Thomas Tsou85b179d2013-11-15 21:14:33 -0500282 " -p Base port number\n"
Tom Tsoub0aefcb2016-03-06 03:44:34 -0800283 " -e Enable EDGE receiver\n"
Tom Tsou76764272016-06-24 14:25:39 -0700284 " -m Enable multi-ARFCN transceiver (default=disabled)\n"
Thomas Tsou85b179d2013-11-15 21:14:33 -0500285 " -x Enable external 10 MHz reference\n"
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700286 " -g Enable GPSDO reference\n"
Tom Tsou2e4ed102016-06-27 15:39:16 -0700287 " -s Tx samples-per-symbol (1 or 4)\n"
288 " -b Rx samples-per-symbol (1 or 4)\n"
Thomas Tsou15d743e2014-01-25 02:34:03 -0500289 " -c Number of ARFCN channels (default=1)\n"
Thomas Tsou8e17df72014-03-06 14:16:11 -0500290 " -f Enable C0 filler table\n"
Tom Tsou64ad7122015-05-19 18:26:31 -0700291 " -o Set baseband frequency offset (default=auto)\n"
Alexander Chemeris37c52c72016-03-25 18:28:34 +0300292 " -r Random Normal Burst test mode with TSC\n"
293 " -A Random Access Burst test mode with delay\n"
Alexander Chemeris50747dc2015-06-07 01:07:45 -0400294 " -R RSSI to dBm offset in dB (default=0)\n"
Harald Welte81486e02017-06-29 15:35:22 +0200295 " -S Swap channels (UmTRX only)\n"
Pau Espin Pedrol77ce99a2018-02-05 13:05:06 +0100296 " -t SCHED_RR real-time priority (1..32)\n"
297 " -y comma-delimited list of Tx paths (num elements matches -c)\n"
298 " -z comma-delimited list of Rx paths (num elements matches -c)\n",
Thomas Tsou85b179d2013-11-15 21:14:33 -0500299 "EMERG, ALERT, CRT, ERR, WARNING, NOTICE, INFO, DEBUG");
300}
301
302static void handle_options(int argc, char **argv, struct trx_config *config)
303{
304 int option;
Pau Espin Pedrol77ce99a2018-02-05 13:05:06 +0100305 bool tx_path_set = false, rx_path_set = false;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500306
Tom Tsoude116e92017-03-30 17:00:42 -0700307 config->log_level = "NOTICE";
Pau Espin Pedrol8c800952017-08-16 16:53:23 +0200308 config->local_addr = DEFAULT_TRX_IP;
309 config->remote_addr = DEFAULT_TRX_IP;
Tom Tsoude116e92017-03-30 17:00:42 -0700310 config->port = DEFAULT_TRX_PORT;
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800311 config->tx_sps = DEFAULT_TX_SPS;
312 config->rx_sps = DEFAULT_RX_SPS;
Tom Tsou64ad7122015-05-19 18:26:31 -0700313 config->chans = DEFAULT_CHANS;
314 config->rtsc = 0;
Alexander Chemeris37c52c72016-03-25 18:28:34 +0300315 config->rach_delay = 0;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500316 config->extref = false;
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700317 config->gpsref = false;
Tom Tsou64ad7122015-05-19 18:26:31 -0700318 config->filler = Transceiver::FILLER_ZERO;
Tom Tsou76764272016-06-24 14:25:39 -0700319 config->mcbts = false;
Thomas Tsou8e17df72014-03-06 14:16:11 -0500320 config->offset = 0.0;
Alexander Chemerise8905a02015-06-03 23:47:56 -0400321 config->rssi_offset = 0.0;
Alexander Chemeris50747dc2015-06-07 01:07:45 -0400322 config->swap_channels = false;
Tom Tsoub0aefcb2016-03-06 03:44:34 -0800323 config->edge = false;
Harald Welte81486e02017-06-29 15:35:22 +0200324 config->sched_rr = -1;
Pau Espin Pedrol77ce99a2018-02-05 13:05:06 +0100325 config->tx_paths = std::vector<std::string>(DEFAULT_CHANS, "");
326 config->rx_paths = std::vector<std::string>(DEFAULT_CHANS, "");
Thomas Tsou85b179d2013-11-15 21:14:33 -0500327
Pau Espin Pedrol77ce99a2018-02-05 13:05:06 +0100328 while ((option = getopt(argc, argv, "ha:l:i:j:p:c:dmxgfo:s:b:r:A:R:Set:y:z:")) != -1) {
Thomas Tsou85b179d2013-11-15 21:14:33 -0500329 switch (option) {
330 case 'h':
331 print_help();
332 exit(0);
333 break;
334 case 'a':
335 config->dev_args = optarg;
336 break;
337 case 'l':
338 config->log_level = optarg;
339 break;
340 case 'i':
Pau Espin Pedrol8c800952017-08-16 16:53:23 +0200341 config->remote_addr = optarg;
342 break;
343 case 'j':
344 config->local_addr = optarg;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500345 break;
346 case 'p':
347 config->port = atoi(optarg);
348 break;
349 case 'c':
350 config->chans = atoi(optarg);
351 break;
Tom Tsou76764272016-06-24 14:25:39 -0700352 case 'm':
353 config->mcbts = true;
354 break;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500355 case 'x':
356 config->extref = true;
357 break;
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700358 case 'g':
359 config->gpsref = true;
360 break;
Thomas Tsou15d743e2014-01-25 02:34:03 -0500361 case 'f':
Tom Tsou64ad7122015-05-19 18:26:31 -0700362 config->filler = Transceiver::FILLER_DUMMY;
Thomas Tsou15d743e2014-01-25 02:34:03 -0500363 break;
Thomas Tsou8e17df72014-03-06 14:16:11 -0500364 case 'o':
365 config->offset = atof(optarg);
366 break;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500367 case 's':
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800368 config->tx_sps = atoi(optarg);
Tom Tsou64ad7122015-05-19 18:26:31 -0700369 break;
Tom Tsou2e4ed102016-06-27 15:39:16 -0700370 case 'b':
371 config->rx_sps = atoi(optarg);
372 break;
Tom Tsou64ad7122015-05-19 18:26:31 -0700373 case 'r':
374 config->rtsc = atoi(optarg);
Tom Tsouaf717b22016-03-06 22:19:15 -0800375 config->filler = Transceiver::FILLER_NORM_RAND;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500376 break;
Alexander Chemeris5efe0502016-03-23 17:06:32 +0300377 case 'A':
Alexander Chemeris37c52c72016-03-25 18:28:34 +0300378 config->rach_delay = atoi(optarg);
Alexander Chemeris5efe0502016-03-23 17:06:32 +0300379 config->filler = Transceiver::FILLER_ACCESS_RAND;
380 break;
Alexander Chemerise8905a02015-06-03 23:47:56 -0400381 case 'R':
382 config->rssi_offset = atof(optarg);
383 break;
Alexander Chemeris50747dc2015-06-07 01:07:45 -0400384 case 'S':
385 config->swap_channels = true;
386 break;
Tom Tsoub0aefcb2016-03-06 03:44:34 -0800387 case 'e':
388 config->edge = true;
Tom Tsoub0aefcb2016-03-06 03:44:34 -0800389 break;
Harald Welte81486e02017-06-29 15:35:22 +0200390 case 't':
391 config->sched_rr = atoi(optarg);
392 break;
Pau Espin Pedrol77ce99a2018-02-05 13:05:06 +0100393 case 'y':
394 config->tx_paths = comma_delimited_to_vector(optarg);
395 tx_path_set = true;
396 break;
397 case 'z':
398 config->rx_paths = comma_delimited_to_vector(optarg);
399 rx_path_set = true;
400 break;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500401 default:
402 print_help();
403 exit(0);
404 }
405 }
Tom Tsou64ad7122015-05-19 18:26:31 -0700406
Tom Tsou76764272016-06-24 14:25:39 -0700407 /* Force 4 SPS for EDGE or multi-ARFCN configurations */
408 if ((config->edge) || (config->mcbts)) {
Tom Tsou2e4ed102016-06-27 15:39:16 -0700409 config->tx_sps = 4;
410 config->rx_sps = 4;
411 }
412
Tom Tsou8f0ccf62016-07-20 16:35:03 -0700413 if (config->gpsref && config->extref) {
414 printf("External and GPSDO references unavailable at the same time\n\n");
415 goto bad_config;
416 }
417
Tom Tsouaf717b22016-03-06 22:19:15 -0800418 if (config->edge && (config->filler == Transceiver::FILLER_NORM_RAND))
419 config->filler = Transceiver::FILLER_EDGE_RAND;
420
Tom Tsou76764272016-06-24 14:25:39 -0700421 if ((config->tx_sps != 1) && (config->tx_sps != 4) &&
422 (config->rx_sps != 1) && (config->rx_sps != 4)) {
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800423 printf("Unsupported samples-per-symbol %i\n\n", config->tx_sps);
Tom Tsou8f0ccf62016-07-20 16:35:03 -0700424 goto bad_config;
Tom Tsou64ad7122015-05-19 18:26:31 -0700425 }
426
427 if (config->rtsc > 7) {
428 printf("Invalid training sequence %i\n\n", config->rtsc);
Tom Tsou8f0ccf62016-07-20 16:35:03 -0700429 goto bad_config;
Tom Tsou64ad7122015-05-19 18:26:31 -0700430 }
Alexander Chemeris37c52c72016-03-25 18:28:34 +0300431
432 if (config->rach_delay > 68) {
433 printf("RACH delay is too big %i\n\n", config->rach_delay);
Tom Tsou8f0ccf62016-07-20 16:35:03 -0700434 goto bad_config;
Alexander Chemeris37c52c72016-03-25 18:28:34 +0300435 }
Tom Tsou8f0ccf62016-07-20 16:35:03 -0700436
Pau Espin Pedrol77ce99a2018-02-05 13:05:06 +0100437 if (!tx_path_set) {
438 config->tx_paths = std::vector<std::string>(config->chans, "");
439 } else if (config->tx_paths.size() != config->chans) {
440 printf("Num of channels and num of Tx Antennas doesn't match\n\n");
441 goto bad_config;
442 }
443 if (!rx_path_set) {
444 config->rx_paths = std::vector<std::string>(config->chans, "");
445 } else if (config->rx_paths.size() != config->chans) {
446 printf("Num of channels and num of Rx Antennas doesn't match\n\n");
447 goto bad_config;
448 }
449
Tom Tsou8f0ccf62016-07-20 16:35:03 -0700450 return;
451
452bad_config:
453 print_help();
454 exit(0);
Thomas Tsou85b179d2013-11-15 21:14:33 -0500455}
456
Harald Welte81486e02017-06-29 15:35:22 +0200457static int set_sched_rr(int prio)
458{
459 struct sched_param param;
460 int rc;
461 memset(&param, 0, sizeof(param));
462 param.sched_priority = prio;
463 printf("Setting SCHED_RR priority(%d)\n", param.sched_priority);
464 rc = sched_setscheduler(getpid(), SCHED_RR, &param);
465 if (rc != 0) {
466 std::cerr << "Config: Setting SCHED_RR failed" << std::endl;
467 return -1;
468 }
469 return 0;
470}
471
Thomas Tsou85b179d2013-11-15 21:14:33 -0500472int main(int argc, char *argv[])
473{
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700474 int type, chans, ref;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500475 RadioDevice *usrp;
476 RadioInterface *radio = NULL;
477 Transceiver *trx = NULL;
Tom Tsou05c6feb2016-06-22 16:09:44 -0700478 RadioDevice::InterfaceType iface = RadioDevice::NORMAL;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500479 struct trx_config config;
480
Philipp Maiere51a8f02017-03-16 12:09:34 +0100481#ifdef HAVE_SSE3
482 printf("Info: SSE3 support compiled in");
Vadim Yanitskiy3bd763d2017-05-20 01:46:51 +0300483#ifdef HAVE___BUILTIN_CPU_SUPPORTS
Philipp Maiere51a8f02017-03-16 12:09:34 +0100484 if (__builtin_cpu_supports("sse3"))
485 printf(" and supported by CPU\n");
486 else
487 printf(", but not supported by CPU\n");
Vadim Yanitskiy3bd763d2017-05-20 01:46:51 +0300488#else
489 printf(", but runtime SIMD detection disabled\n");
490#endif
Philipp Maiere51a8f02017-03-16 12:09:34 +0100491#endif
492
493#ifdef HAVE_SSE4_1
494 printf("Info: SSE4.1 support compiled in");
Vadim Yanitskiy3bd763d2017-05-20 01:46:51 +0300495#ifdef HAVE___BUILTIN_CPU_SUPPORTS
Philipp Maiere51a8f02017-03-16 12:09:34 +0100496 if (__builtin_cpu_supports("sse4.1"))
497 printf(" and supported by CPU\n");
498 else
499 printf(", but not supported by CPU\n");
Vadim Yanitskiy3bd763d2017-05-20 01:46:51 +0300500#else
501 printf(", but runtime SIMD detection disabled\n");
502#endif
Philipp Maiere51a8f02017-03-16 12:09:34 +0100503#endif
504
Philipp Maier7e07cf22017-03-15 18:09:35 +0100505 convolve_init();
506 convert_init();
507
Thomas Tsou85b179d2013-11-15 21:14:33 -0500508 handle_options(argc, argv, &config);
509
Harald Welte81486e02017-06-29 15:35:22 +0200510 if (config.sched_rr != -1) {
511 if (set_sched_rr(config.sched_rr) < 0)
512 return EXIT_FAILURE;
513 }
514
Thomas Tsou85b179d2013-11-15 21:14:33 -0500515 setup_signal_handlers();
516
517 /* Check database sanity */
518 if (!trx_setup_config(&config)) {
519 std::cerr << "Config: Database failure - exiting" << std::endl;
520 return EXIT_FAILURE;
521 }
522
523 gLogInit("transceiver", config.log_level.c_str(), LOG_LOCAL7);
524
525 srandom(time(NULL));
526
527 /* Create the low level device object */
Tom Tsou76764272016-06-24 14:25:39 -0700528 if (config.mcbts)
529 iface = RadioDevice::MULTI_ARFCN;
530
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700531 if (config.extref)
532 ref = RadioDevice::REF_EXTERNAL;
533 else if (config.gpsref)
534 ref = RadioDevice::REF_GPS;
535 else
536 ref = RadioDevice::REF_INTERNAL;
537
Tom Tsou05c6feb2016-06-22 16:09:44 -0700538 usrp = RadioDevice::make(config.tx_sps, config.rx_sps, iface,
Pau Espin Pedrol77ce99a2018-02-05 13:05:06 +0100539 config.chans, config.offset, config.tx_paths, config.rx_paths);
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700540 type = usrp->open(config.dev_args, ref, config.swap_channels);
Thomas Tsou85b179d2013-11-15 21:14:33 -0500541 if (type < 0) {
542 LOG(ALERT) << "Failed to create radio device" << std::endl;
543 goto shutdown;
544 }
545
546 /* Setup the appropriate device interface */
547 radio = makeRadioInterface(&config, usrp, type);
548 if (!radio)
549 goto shutdown;
550
551 /* Create the transceiver core */
552 trx = makeTransceiver(&config, radio);
553 if (!trx)
554 goto shutdown;
555
Thomas Tsou85b179d2013-11-15 21:14:33 -0500556 chans = trx->numChans();
557 std::cout << "-- Transceiver active with "
558 << chans << " channel(s)" << std::endl;
559
560 while (!gshutdown)
561 sleep(1);
562
563shutdown:
564 std::cout << "Shutting down transceiver..." << std::endl;
565
566 delete trx;
567 delete radio;
568 delete usrp;
569
570 return 0;
571}