CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
orangepi-xunlong

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: orangepi-xunlong/orangepi-build
Path: blob/next/external/cache/sources/hcitools/monitor/main.c
Views: 3959
1
/*
2
*
3
* BlueZ - Bluetooth protocol stack for Linux
4
*
5
* Copyright (C) 2011-2012 Intel Corporation
6
* Copyright (C) 2004-2010 Marcel Holtmann <[email protected]>
7
*
8
*
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 2 of the License, or
12
* (at your option) any later version.
13
*
14
* This program 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
17
* GNU General Public License for more details.
18
*
19
* You should have received a copy of the GNU General Public License
20
* along with this program; if not, write to the Free Software
21
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
*
23
*/
24
25
#ifdef HAVE_CONFIG_H
26
#include <config.h>
27
#endif
28
29
#include <stdio.h>
30
#include <ctype.h>
31
#include <stdlib.h>
32
#include <string.h>
33
#include <getopt.h>
34
35
#include "mainloop.h"
36
#include "packet.h"
37
#include "control.h"
38
39
static void signal_callback(int signum, void *user_data)
40
{
41
switch (signum) {
42
case SIGINT:
43
case SIGTERM:
44
mainloop_quit();
45
break;
46
}
47
}
48
49
static void usage(void)
50
{
51
printf("btmon - Bluetooth monitor\n"
52
"Usage:\n");
53
printf("\tbtmon [options]\n");
54
printf("options:\n"
55
"\t-r, --read <file> Read traces in btsnoop format\n"
56
"\t-w, --write <file> Save traces in btsnoop format\n"
57
"\t-s, --server <socket> Start monitor server socket\n"
58
"\t-i, --index <num> Show only specified controller\n"
59
"\t-t, --time Show time instead of time offset\n"
60
"\t-T, --date Show time and date information\n"
61
"\t-S, --sco Dump SCO traffic\n"
62
"\t-h, --help Show help options\n");
63
}
64
65
static const struct option main_options[] = {
66
{ "read", required_argument, NULL, 'r' },
67
{ "write", required_argument, NULL, 'w' },
68
{ "server", required_argument, NULL, 's' },
69
{ "index", required_argument, NULL, 'i' },
70
{ "time", no_argument, NULL, 't' },
71
{ "date", no_argument, NULL, 'T' },
72
{ "sco", no_argument, NULL, 'S' },
73
{ "version", no_argument, NULL, 'v' },
74
{ "help", no_argument, NULL, 'h' },
75
{ }
76
};
77
78
int main(int argc, char *argv[])
79
{
80
unsigned long filter_mask = 0;
81
const char *str, *reader_path = NULL, *writer_path = NULL;
82
sigset_t mask;
83
84
mainloop_init();
85
86
filter_mask |= PACKET_FILTER_SHOW_TIME_OFFSET;
87
88
for (;;) {
89
int opt;
90
91
opt = getopt_long(argc, argv, "r:w:s:i:tTSvh",
92
main_options, NULL);
93
if (opt < 0)
94
break;
95
96
switch (opt) {
97
case 'r':
98
reader_path = optarg;
99
break;
100
case 'w':
101
writer_path = optarg;
102
break;
103
case 's':
104
control_server(optarg);
105
break;
106
case 'i':
107
if (strlen(optarg) > 3 && !strncmp(optarg, "hci", 3))
108
str = optarg + 3;
109
else
110
str = optarg;
111
if (!isdigit(*str)) {
112
usage();
113
return EXIT_FAILURE;
114
}
115
packet_select_index(atoi(str));
116
break;
117
case 't':
118
filter_mask &= ~PACKET_FILTER_SHOW_TIME_OFFSET;
119
filter_mask |= PACKET_FILTER_SHOW_TIME;
120
break;
121
case 'T':
122
filter_mask &= ~PACKET_FILTER_SHOW_TIME_OFFSET;
123
filter_mask |= PACKET_FILTER_SHOW_TIME;
124
filter_mask |= PACKET_FILTER_SHOW_DATE;
125
break;
126
case 'S':
127
filter_mask |= PACKET_FILTER_SHOW_SCO_DATA;
128
break;
129
case 'v':
130
printf("%s\n", VERSION);
131
return EXIT_SUCCESS;
132
case 'h':
133
usage();
134
return EXIT_SUCCESS;
135
default:
136
return EXIT_FAILURE;
137
}
138
}
139
140
if (argc - optind > 0) {
141
fprintf(stderr, "Invalid command line parameters\n");
142
return EXIT_FAILURE;
143
}
144
145
sigemptyset(&mask);
146
sigaddset(&mask, SIGINT);
147
sigaddset(&mask, SIGTERM);
148
149
mainloop_set_signal(&mask, signal_callback, NULL, NULL);
150
151
printf("Bluetooth monitor ver %s\n", VERSION);
152
153
packet_set_filter(filter_mask);
154
155
if (reader_path) {
156
control_reader(reader_path);
157
return EXIT_SUCCESS;
158
}
159
160
if (writer_path)
161
control_writer(writer_path);
162
163
if (control_tracing() < 0)
164
return EXIT_FAILURE;
165
166
return mainloop_run();
167
}
168
169