1 /* "Application" code of the layer2/3 stack */
3 /* (C) 2010 by Andreas Eversberg <jolly@eversberg.eu>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include <osmocom/bb/common/osmocom_data.h>
29 #include <osmocom/bb/common/l1ctl.h>
30 #include <osmocom/bb/common/l23_app.h>
31 #include <osmocom/bb/common/logging.h>
32 #include <osmocom/bb/common/gps.h>
33 #include <osmocom/bb/misc/cell_log.h>
35 #include <osmocore/talloc.h>
36 #include <osmocore/utils.h>
38 extern struct log_target *stderr_target;
41 char *logname = "/var/log/osmocom.log";
44 int _scan_work(struct osmocom_ms *ms)
49 int _scan_exit(struct osmocom_ms *ms)
51 /* in case there is a lockup during exit */
52 signal(SIGINT, SIG_DFL);
53 signal(SIGHUP, SIG_DFL);
54 signal(SIGTERM, SIG_DFL);
55 signal(SIGPIPE, SIG_DFL);
62 int l23_app_init(struct osmocom_ms *ms)
68 // log_parse_category_mask(stderr_target, "DL1C:DRSL:DRR:DGPS:DSUM");
69 log_parse_category_mask(stderr_target, "DSUM");
70 log_set_log_level(stderr_target, LOGL_INFO);
72 l23_app_work = _scan_work;
73 l23_app_exit = _scan_exit;
79 l1ctl_tx_reset_req(ms, L1CTL_RES_T_FULL);
80 printf("Mobile initialized, please start phone now!\n");
84 static int l23_cfg_supported()
86 return L23_OPT_TAP | L23_OPT_DBG;
89 static int l23_getopt_options(struct option **options)
91 static struct option opts [] = {
92 {"logfile", 1, 0, 'l'},
94 {"no-rach", 1, 0, 'n'},
96 {"gpsd-host", 1, 0, 'g'},
97 {"gpsd-port", 1, 0, 'p'}
105 return ARRAY_SIZE(opts);
108 static int l23_cfg_print_help()
110 printf("\nApplication specific\n");
111 printf(" -l --logfile LOGFILE Logfile for the cell log.\n");
112 printf(" -r --rach RACH Nr. of RACH bursts to send.\n");
113 printf(" -n --no-rach Send no rach bursts.\n");
115 printf(" -g --gpsd-host HOST 127.0.0.1. gpsd host.\n");
116 printf(" -p --port PORT 2947. gpsd port\n");
118 printf(" -g --gps DEVICE /dev/ttyACM0. GPS device.\n");
119 printf(" -b --baud BAUDRAT The baud rate of the GPS device\n");
124 static int l23_cfg_handle(int c, const char *optarg)
128 logname = talloc_strdup(l23_ctx, optarg);
131 RACH_MAX = atoi(optarg);
138 snprintf(gps.gpsd_host, ARRAY_SIZE(gps.gpsd_host), "%s", optarg);
139 /* force string terminator */
140 gps.gpsd_host[ARRAY_SIZE(gps.gpsd_host) - 1] = '\0';
141 LOGP(DGPS, LOGL_INFO, "Using gpsd host %s\n", gps.gpsd_host);
144 snprintf(gps.gpsd_port, ARRAY_SIZE(gps.gpsd_port), "%s", optarg);
145 /* force string terminator */
146 gps.gpsd_port[ARRAY_SIZE(gps.gpsd_port) - 1] = '\0';
147 LOGP(DGPS, LOGL_INFO, "Using gpsd port %s\n", gps.gpsd_port);
151 snprintf(gps.device, ARRAY_SIZE(gps.device), "%s", optarg);
152 /* force string terminator */
153 gps.device[ARRAY_SIZE(gps.device) - 1] = '\0';
154 LOGP(DGPS, LOGL_INFO, "Using GPS device %s\n", gps.device);
157 gps.baud = atoi(optarg);
158 LOGP(DGPS, LOGL_INFO, "Setting GPS baudrate to %u\n", gps.baud);
165 static struct l23_app_info info = {
166 .copyright = "Copyright (C) 2010 Andreas Eversberg\n",
168 .getopt_string = "l:r:ng:p:",
170 .getopt_string = "l:r:ng:b:",
172 .cfg_supported = l23_cfg_supported,
173 .cfg_getopt_opt = l23_getopt_options,
174 .cfg_handle_opt = l23_cfg_handle,
175 .cfg_print_help = l23_cfg_print_help,
178 struct l23_app_info *l23_app_info()