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 <osmocom/core/talloc.h>
36 #include <osmocom/core/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'},
104 return ARRAY_SIZE(opts);
107 static int l23_cfg_print_help()
109 printf("\nApplication specific\n");
110 printf(" -l --logfile LOGFILE Logfile for the cell log.\n");
111 printf(" -r --rach RACH Nr. of RACH bursts to send.\n");
112 printf(" -n --no-rach Send no rach bursts.\n");
113 printf(" -g --gpsd-host HOST 127.0.0.1. gpsd host.\n");
114 printf(" -p --port PORT 2947. gpsd port\n");
115 printf(" -f --gps DEVICE /dev/ttyACM0. GPS serial device.\n");
116 printf(" -b --baud BAUDRAT The baud rate of the GPS device\n");
121 static int l23_cfg_handle(int c, const char *optarg)
125 logname = talloc_strdup(l23_ctx, optarg);
128 RACH_MAX = atoi(optarg);
135 snprintf(g.gpsd_host, ARRAY_SIZE(g.gpsd_host), "%s", optarg);
136 /* force string terminator */
137 g.gpsd_host[ARRAY_SIZE(g.gpsd_host) - 1] = '\0';
138 if (g.gps_type != GPS_TYPE_UNDEF)
140 g.gps_type = GPS_TYPE_GPSD;
141 LOGP(DGPS, LOGL_INFO, "Using gpsd host %s\n", g.gpsd_host);
143 printf("Gpsd support not compiled.\n");
149 snprintf(g.gpsd_port, ARRAY_SIZE(g.gpsd_port), "%s", optarg);
150 /* force string terminator */
151 g.gpsd_port[ARRAY_SIZE(g.gpsd_port) - 1] = '\0';
152 g.gps_type = GPS_TYPE_GPSD;
153 LOGP(DGPS, LOGL_INFO, "Using gpsd port %s\n", g.gpsd_port);
155 printf("Gpsd support not compiled.\n");
160 snprintf(g.device, ARRAY_SIZE(g.device), "%s", optarg);
161 /* force string terminator */
162 g.device[ARRAY_SIZE(g.device) - 1] = '\0';
163 if (g.gps_type != GPS_TYPE_UNDEF)
165 g.gps_type = GPS_TYPE_SERIAL;
166 LOGP(DGPS, LOGL_INFO, "Using GPS serial device %s\n", g.device);
169 g.baud = atoi(optarg);
170 g.gps_type = GPS_TYPE_SERIAL;
171 LOGP(DGPS, LOGL_INFO, "Setting GPS baudrate to %u\n", g.baud);
177 printf("\nYou can't specify both gpsd and serial gps!!\n\n");
181 static struct l23_app_info info = {
182 .copyright = "Copyright (C) 2010 Andreas Eversberg\n",
183 .getopt_string = "g:p:l:r:nf:b:",
184 .cfg_supported = l23_cfg_supported,
185 .cfg_getopt_opt = l23_getopt_options,
186 .cfg_handle_opt = l23_cfg_handle,
187 .cfg_print_help = l23_cfg_print_help,
190 struct l23_app_info *l23_app_info()