3 * BlueZ - Bluetooth protocol stack for Linux
5 * Copyright (C) 2011-2014 Intel Corporation
6 * Copyright (C) 2002-2010 Marcel Holtmann <marcel@holtmann.org>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
35 #include "src/shared/mainloop.h"
44 static void signal_callback(int signum, void *user_data)
54 static void usage(void)
56 printf("btmon - Bluetooth monitor\n"
58 printf("\tbtmon [options]\n");
60 "\t-r, --read <file> Read traces in btsnoop format\n"
61 "\t-w, --write <file> Save traces in btsnoop format\n"
62 "\t-a, --analyze <file> Analyze traces in btsnoop format\n"
63 "\t-s, --server <socket> Start monitor server socket\n"
64 "\t-p, --priority <level> Show only priority or lower\n"
65 "\t-i, --index <num> Show only specified controller\n"
66 "\t-t, --time Show time instead of time offset\n"
67 "\t-T, --date Show time and date information\n"
68 "\t-S, --sco Dump SCO traffic\n"
69 "\t-E, --ellisys [ip] Send Ellisys HCI Injection\n"
70 #ifdef __TIZEN_PATCH__
71 "\t-C, --count <num> Save traces by <num> rotation\n"
72 "\t-W, --size <num> Save traces at most <num> size\n"
74 "\t-h, --help Show help options\n");
77 static const struct option main_options[] = {
78 { "read", required_argument, NULL, 'r' },
79 { "write", required_argument, NULL, 'w' },
80 { "analyze", required_argument, NULL, 'a' },
81 { "server", required_argument, NULL, 's' },
82 { "priority",required_argument, NULL, 'p' },
83 { "index", required_argument, NULL, 'i' },
84 { "time", no_argument, NULL, 't' },
85 { "date", no_argument, NULL, 'T' },
86 { "sco", no_argument, NULL, 'S' },
87 { "ellisys", required_argument, NULL, 'E' },
88 #ifdef __TIZEN_PATCH__
89 { "count", required_argument, NULL, 'C' },
90 { "size", required_argument, NULL, 'W' },
92 { "todo", no_argument, NULL, '#' },
93 { "version", no_argument, NULL, 'v' },
94 { "help", no_argument, NULL, 'h' },
98 int main(int argc, char *argv[])
100 unsigned long filter_mask = 0;
101 const char *reader_path = NULL;
102 const char *writer_path = NULL;
103 const char *analyze_path = NULL;
104 const char *ellisys_server = NULL;
105 unsigned short ellisys_port = 0;
106 #ifdef __TIZEN_PATCH__
107 int16_t rotate_count = -1;
108 ssize_t file_size = -1;
116 filter_mask |= PACKET_FILTER_SHOW_TIME_OFFSET;
121 #ifdef __TIZEN_PATCH__
122 opt = getopt_long(argc, argv, "r:w:a:s:p:i:tTSE:C:W:vh",
125 opt = getopt_long(argc, argv, "r:w:a:s:p:i:tTSE:vh",
133 reader_path = optarg;
136 writer_path = optarg;
139 analyze_path = optarg;
142 control_server(optarg);
145 packet_set_priority(optarg);
148 if (strlen(optarg) > 3 && !strncmp(optarg, "hci", 3))
152 if (!isdigit(*str)) {
156 packet_select_index(atoi(str));
159 filter_mask &= ~PACKET_FILTER_SHOW_TIME_OFFSET;
160 filter_mask |= PACKET_FILTER_SHOW_TIME;
163 filter_mask &= ~PACKET_FILTER_SHOW_TIME_OFFSET;
164 filter_mask |= PACKET_FILTER_SHOW_TIME;
165 filter_mask |= PACKET_FILTER_SHOW_DATE;
168 filter_mask |= PACKET_FILTER_SHOW_SCO_DATA;
171 ellisys_server = optarg;
172 ellisys_port = 24352;
174 #ifdef __TIZEN_PATCH__
176 rotate_count = atoi(optarg);
179 file_size = atoll(optarg);
187 printf("%s\n", VERSION);
197 if (argc - optind > 0) {
198 fprintf(stderr, "Invalid command line parameters\n");
202 if (reader_path && analyze_path) {
203 fprintf(stderr, "Display and analyze can't be combined\n");
208 sigaddset(&mask, SIGINT);
209 sigaddset(&mask, SIGTERM);
211 mainloop_set_signal(&mask, signal_callback, NULL, NULL);
213 printf("Bluetooth monitor ver %s\n", VERSION);
217 packet_set_filter(filter_mask);
220 analyze_trace(analyze_path);
226 ellisys_enable(ellisys_server, ellisys_port);
228 control_reader(reader_path);
232 #ifdef __TIZEN_PATCH__
233 if (writer_path && !control_writer(writer_path,
234 rotate_count, file_size)) {
235 printf("Failed to open '%s'\n", writer_path);
239 if (writer_path && !control_writer(writer_path)) {
240 printf("Failed to open '%s'\n", writer_path);
246 ellisys_enable(ellisys_server, ellisys_port);
248 if (control_tracing() < 0)
251 exit_status = mainloop_run();