Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/next/external/cache/sources/hcitools/monitor/main.c
Views: 3959
/*1*2* BlueZ - Bluetooth protocol stack for Linux3*4* Copyright (C) 2011-2012 Intel Corporation5* Copyright (C) 2004-2010 Marcel Holtmann <[email protected]>6*7*8* This program is free software; you can redistribute it and/or modify9* it under the terms of the GNU General Public License as published by10* the Free Software Foundation; either version 2 of the License, or11* (at your option) any later version.12*13* This program is distributed in the hope that it will be useful,14* but WITHOUT ANY WARRANTY; without even the implied warranty of15* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the16* GNU General Public License for more details.17*18* You should have received a copy of the GNU General Public License19* along with this program; if not, write to the Free Software20* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA21*22*/2324#ifdef HAVE_CONFIG_H25#include <config.h>26#endif2728#include <stdio.h>29#include <ctype.h>30#include <stdlib.h>31#include <string.h>32#include <getopt.h>3334#include "mainloop.h"35#include "packet.h"36#include "control.h"3738static void signal_callback(int signum, void *user_data)39{40switch (signum) {41case SIGINT:42case SIGTERM:43mainloop_quit();44break;45}46}4748static void usage(void)49{50printf("btmon - Bluetooth monitor\n"51"Usage:\n");52printf("\tbtmon [options]\n");53printf("options:\n"54"\t-r, --read <file> Read traces in btsnoop format\n"55"\t-w, --write <file> Save traces in btsnoop format\n"56"\t-s, --server <socket> Start monitor server socket\n"57"\t-i, --index <num> Show only specified controller\n"58"\t-t, --time Show time instead of time offset\n"59"\t-T, --date Show time and date information\n"60"\t-S, --sco Dump SCO traffic\n"61"\t-h, --help Show help options\n");62}6364static const struct option main_options[] = {65{ "read", required_argument, NULL, 'r' },66{ "write", required_argument, NULL, 'w' },67{ "server", required_argument, NULL, 's' },68{ "index", required_argument, NULL, 'i' },69{ "time", no_argument, NULL, 't' },70{ "date", no_argument, NULL, 'T' },71{ "sco", no_argument, NULL, 'S' },72{ "version", no_argument, NULL, 'v' },73{ "help", no_argument, NULL, 'h' },74{ }75};7677int main(int argc, char *argv[])78{79unsigned long filter_mask = 0;80const char *str, *reader_path = NULL, *writer_path = NULL;81sigset_t mask;8283mainloop_init();8485filter_mask |= PACKET_FILTER_SHOW_TIME_OFFSET;8687for (;;) {88int opt;8990opt = getopt_long(argc, argv, "r:w:s:i:tTSvh",91main_options, NULL);92if (opt < 0)93break;9495switch (opt) {96case 'r':97reader_path = optarg;98break;99case 'w':100writer_path = optarg;101break;102case 's':103control_server(optarg);104break;105case 'i':106if (strlen(optarg) > 3 && !strncmp(optarg, "hci", 3))107str = optarg + 3;108else109str = optarg;110if (!isdigit(*str)) {111usage();112return EXIT_FAILURE;113}114packet_select_index(atoi(str));115break;116case 't':117filter_mask &= ~PACKET_FILTER_SHOW_TIME_OFFSET;118filter_mask |= PACKET_FILTER_SHOW_TIME;119break;120case 'T':121filter_mask &= ~PACKET_FILTER_SHOW_TIME_OFFSET;122filter_mask |= PACKET_FILTER_SHOW_TIME;123filter_mask |= PACKET_FILTER_SHOW_DATE;124break;125case 'S':126filter_mask |= PACKET_FILTER_SHOW_SCO_DATA;127break;128case 'v':129printf("%s\n", VERSION);130return EXIT_SUCCESS;131case 'h':132usage();133return EXIT_SUCCESS;134default:135return EXIT_FAILURE;136}137}138139if (argc - optind > 0) {140fprintf(stderr, "Invalid command line parameters\n");141return EXIT_FAILURE;142}143144sigemptyset(&mask);145sigaddset(&mask, SIGINT);146sigaddset(&mask, SIGTERM);147148mainloop_set_signal(&mask, signal_callback, NULL, NULL);149150printf("Bluetooth monitor ver %s\n", VERSION);151152packet_set_filter(filter_mask);153154if (reader_path) {155control_reader(reader_path);156return EXIT_SUCCESS;157}158159if (writer_path)160control_writer(writer_path);161162if (control_tracing() < 0)163return EXIT_FAILURE;164165return mainloop_run();166}167168169