2012-02-20 23:11:26 +08:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* BlueZ - Bluetooth protocol stack for Linux
|
|
|
|
*
|
2012-02-27 10:39:56 +08:00
|
|
|
* Copyright (C) 2011-2012 Intel Corporation
|
2012-02-20 23:11:26 +08:00
|
|
|
* Copyright (C) 2004-2010 Marcel Holtmann <marcel@holtmann.org>
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-12-07 18:46:04 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2012-02-20 23:11:26 +08:00
|
|
|
#include <stdio.h>
|
2012-11-05 00:47:27 +08:00
|
|
|
#include <ctype.h>
|
2012-02-20 23:11:26 +08:00
|
|
|
#include <stdlib.h>
|
2012-11-05 00:47:27 +08:00
|
|
|
#include <string.h>
|
2012-03-02 08:56:59 +08:00
|
|
|
#include <getopt.h>
|
2012-02-20 23:11:26 +08:00
|
|
|
|
2012-02-27 16:55:34 +08:00
|
|
|
#include "mainloop.h"
|
|
|
|
#include "packet.h"
|
|
|
|
#include "control.h"
|
2012-03-02 08:56:59 +08:00
|
|
|
#include "btsnoop.h"
|
2012-02-20 23:11:26 +08:00
|
|
|
|
2012-02-28 02:35:31 +08:00
|
|
|
static void signal_callback(int signum, void *user_data)
|
|
|
|
{
|
|
|
|
switch (signum) {
|
|
|
|
case SIGINT:
|
|
|
|
case SIGTERM:
|
|
|
|
mainloop_quit();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-27 10:00:36 +08:00
|
|
|
static void usage(void)
|
|
|
|
{
|
|
|
|
printf("btmon - Bluetooth monitor\n"
|
|
|
|
"Usage:\n");
|
|
|
|
printf("\tbtmon [options]\n");
|
|
|
|
printf("options:\n"
|
2012-11-01 09:28:41 +08:00
|
|
|
"\t-r, --read <file> Read traces in btsnoop format\n"
|
2012-10-31 11:03:06 +08:00
|
|
|
"\t-w, --write <file> Save traces in btsnoop format\n"
|
|
|
|
"\t-s, --server <socket> Start monitor server socket\n"
|
2012-11-05 00:47:27 +08:00
|
|
|
"\t-i, --index <num> Show only specified controller\n"
|
2012-11-05 00:02:40 +08:00
|
|
|
"\t-t, --time Show time instead of time offset\n"
|
|
|
|
"\t-T, --date Show time and date information\n"
|
2013-04-17 23:03:42 +08:00
|
|
|
"\t-S, --sco Dump SCO traffic\n"
|
2012-10-31 11:03:06 +08:00
|
|
|
"\t-h, --help Show help options\n");
|
2012-04-27 10:00:36 +08:00
|
|
|
}
|
|
|
|
|
2012-03-02 08:56:59 +08:00
|
|
|
static const struct option main_options[] = {
|
2012-11-01 09:28:41 +08:00
|
|
|
{ "read", required_argument, NULL, 'r' },
|
2012-11-05 00:47:27 +08:00
|
|
|
{ "write", required_argument, NULL, 'w' },
|
|
|
|
{ "server", required_argument, NULL, 's' },
|
|
|
|
{ "index", required_argument, NULL, 'i' },
|
2012-11-05 00:02:40 +08:00
|
|
|
{ "time", no_argument, NULL, 't' },
|
|
|
|
{ "date", no_argument, NULL, 'T' },
|
2013-04-17 23:03:42 +08:00
|
|
|
{ "sco", no_argument, NULL, 'S' },
|
2012-10-31 11:03:06 +08:00
|
|
|
{ "version", no_argument, NULL, 'v' },
|
|
|
|
{ "help", no_argument, NULL, 'h' },
|
2012-03-02 08:56:59 +08:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2012-02-20 23:11:26 +08:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2012-02-27 16:55:34 +08:00
|
|
|
unsigned long filter_mask = 0;
|
2012-11-05 00:47:27 +08:00
|
|
|
const char *str, *reader_path = NULL;
|
2012-02-28 02:35:31 +08:00
|
|
|
sigset_t mask;
|
2012-02-21 01:17:34 +08:00
|
|
|
|
2012-02-27 16:55:34 +08:00
|
|
|
mainloop_init();
|
2012-02-20 23:11:26 +08:00
|
|
|
|
2012-11-05 00:02:40 +08:00
|
|
|
filter_mask |= PACKET_FILTER_SHOW_TIME_OFFSET;
|
|
|
|
|
2012-03-02 08:56:59 +08:00
|
|
|
for (;;) {
|
|
|
|
int opt;
|
|
|
|
|
2013-04-17 23:03:42 +08:00
|
|
|
opt = getopt_long(argc, argv, "r:w:s:i:tTSvh",
|
2012-11-05 00:02:40 +08:00
|
|
|
main_options, NULL);
|
2012-03-02 08:56:59 +08:00
|
|
|
if (opt < 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch (opt) {
|
2012-11-01 09:28:41 +08:00
|
|
|
case 'r':
|
|
|
|
reader_path = optarg;
|
|
|
|
break;
|
2012-10-31 11:03:06 +08:00
|
|
|
case 'w':
|
2013-08-21 06:58:53 +08:00
|
|
|
btsnoop_create(optarg, BTSNOOP_TYPE_EXTENDED_HCI);
|
2012-03-02 08:56:59 +08:00
|
|
|
break;
|
2012-10-31 09:57:16 +08:00
|
|
|
case 's':
|
|
|
|
control_server(optarg);
|
|
|
|
break;
|
2012-11-05 00:47:27 +08:00
|
|
|
case 'i':
|
|
|
|
if (strlen(optarg) > 3 && !strncmp(optarg, "hci", 3))
|
|
|
|
str = optarg + 3;
|
|
|
|
else
|
|
|
|
str = optarg;
|
|
|
|
if (!isdigit(*str)) {
|
|
|
|
usage();
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
packet_select_index(atoi(str));
|
|
|
|
break;
|
2012-11-05 00:02:40 +08:00
|
|
|
case 't':
|
|
|
|
filter_mask &= ~PACKET_FILTER_SHOW_TIME_OFFSET;
|
|
|
|
filter_mask |= PACKET_FILTER_SHOW_TIME;
|
|
|
|
break;
|
|
|
|
case 'T':
|
|
|
|
filter_mask &= ~PACKET_FILTER_SHOW_TIME_OFFSET;
|
|
|
|
filter_mask |= PACKET_FILTER_SHOW_TIME;
|
|
|
|
filter_mask |= PACKET_FILTER_SHOW_DATE;
|
|
|
|
break;
|
2013-04-17 23:03:42 +08:00
|
|
|
case 'S':
|
|
|
|
filter_mask |= PACKET_FILTER_SHOW_SCO_DATA;
|
|
|
|
break;
|
2012-04-27 10:00:37 +08:00
|
|
|
case 'v':
|
|
|
|
printf("%s\n", VERSION);
|
|
|
|
return EXIT_SUCCESS;
|
2012-04-27 10:00:36 +08:00
|
|
|
case 'h':
|
|
|
|
usage();
|
|
|
|
return EXIT_SUCCESS;
|
2012-03-02 08:56:59 +08:00
|
|
|
default:
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-28 02:35:31 +08:00
|
|
|
sigemptyset(&mask);
|
|
|
|
sigaddset(&mask, SIGINT);
|
|
|
|
sigaddset(&mask, SIGTERM);
|
|
|
|
|
|
|
|
mainloop_set_signal(&mask, signal_callback, NULL, NULL);
|
|
|
|
|
2012-11-05 00:02:40 +08:00
|
|
|
printf("Bluetooth monitor ver %s\n", VERSION);
|
2012-02-22 20:42:47 +08:00
|
|
|
|
2012-02-27 16:55:34 +08:00
|
|
|
packet_set_filter(filter_mask);
|
2012-02-20 23:11:26 +08:00
|
|
|
|
2012-11-01 09:28:41 +08:00
|
|
|
if (reader_path) {
|
|
|
|
control_reader(reader_path);
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2012-11-11 00:57:00 +08:00
|
|
|
if (control_tracing() < 0)
|
|
|
|
return EXIT_FAILURE;
|
2012-02-20 23:11:26 +08:00
|
|
|
|
2012-02-27 16:55:34 +08:00
|
|
|
return mainloop_run();
|
2012-02-20 23:11:26 +08:00
|
|
|
}
|