summaryrefslogtreecommitdiff
path: root/host
diff options
context:
space:
mode:
authorHannes Ellinger <hannes.ellinger@eas.iis.fraunhofer.de>2015-10-16 13:30:42 +0200
committerHannes Ellinger <hannes.ellinger@eas.iis.fraunhofer.de>2015-10-16 13:37:43 +0200
commitda493ac018042a5c533def7ff40f9c73ac417fb2 (patch)
treebd97302f75eab08a684641c995f4d5cb87b8fa60 /host
parent1bf44f4bbb5b04518b729c6de9205e13937e0290 (diff)
store ubertooth status inside a struct instead of globals
Diffstat (limited to 'host')
-rw-r--r--host/libubertooth/src/ubertooth.c240
-rw-r--r--host/libubertooth/src/ubertooth.h42
-rw-r--r--host/ubertooth-tools/src/ubertooth-btle.c38
-rw-r--r--host/ubertooth-tools/src/ubertooth-debug.c8
-rw-r--r--host/ubertooth-tools/src/ubertooth-dfu.c4
-rw-r--r--host/ubertooth-tools/src/ubertooth-dump.c14
-rw-r--r--host/ubertooth-tools/src/ubertooth-ego.c18
-rw-r--r--host/ubertooth-tools/src/ubertooth-follow.c19
-rw-r--r--host/ubertooth-tools/src/ubertooth-rx.c14
-rw-r--r--host/ubertooth-tools/src/ubertooth-scan.c12
-rw-r--r--host/ubertooth-tools/src/ubertooth-specan.c12
-rw-r--r--host/ubertooth-tools/src/ubertooth-util.c74
12 files changed, 267 insertions, 228 deletions
diff --git a/host/libubertooth/src/ubertooth.c b/host/libubertooth/src/ubertooth.c
index 2eb45d4..c337d22 100644
--- a/host/libubertooth/src/ubertooth.c
+++ b/host/libubertooth/src/ubertooth.c
@@ -36,25 +36,12 @@
#define VERSION "unknown"
#endif
-/* this stuff should probably be in a struct managed by the calling program */
-static usb_pkt_rx usb_packets[NUM_BANKS];
-static char br_symbols[NUM_BANKS][BANK_LEN];
-static u8 *empty_usb_buf = NULL;
-static u8 *full_usb_buf = NULL;
-static u8 usb_really_full = 0;
-static struct libusb_transfer *rx_xfer = NULL;
-static uint32_t systime;
-static u8 stop_ubertooth = 0;
-static uint64_t abs_start_ns;
-static uint32_t start_clk100ns = 0;
-static uint64_t last_clk100ns = 0;
-static uint64_t clk100ns_upper = 0;
+uint32_t systime;
u8 debug = 0;
FILE *infile = NULL;
FILE *dumpfile = NULL;
int max_ac_errors = 2;
-btbb_piconet *follow_pn = NULL; // currently following this piconet
#ifdef ENABLE_PCAP
btbb_pcap_handle * h_pcap_bredr = NULL;
lell_pcap_handle * h_pcap_le = NULL;
@@ -67,7 +54,7 @@ void print_version() {
btbb_get_version(), btbb_get_release());
}
-struct libusb_device_handle *cleanup_devh = NULL;
+ubertooth_t* cleanup_devh = NULL;
static void cleanup(int sig __attribute__((unused)))
{
if (cleanup_devh) {
@@ -76,8 +63,8 @@ static void cleanup(int sig __attribute__((unused)))
exit(0);
}
-void register_cleanup_handler(struct libusb_device_handle *devh) {
- cleanup_devh = devh;
+void register_cleanup_handler(ubertooth_t* ut) {
+ cleanup_devh = ut;
/* Clean up on exit. */
signal(SIGINT, cleanup);
@@ -85,16 +72,19 @@ void register_cleanup_handler(struct libusb_device_handle *devh) {
signal(SIGTERM, cleanup);
}
+ubertooth_t* timeout_dev = NULL;
void stop_transfers(int sig __attribute__((unused))) {
- stop_ubertooth = 1;
+ if (timeout_dev)
+ timeout_dev->stop_ubertooth = 1;
}
-void set_timeout(int seconds) {
+void set_timeout(ubertooth_t* ut, int seconds) {
/* Upon SIGALRM, call stop_transfers() */
if (signal(SIGALRM, stop_transfers) == SIG_ERR) {
perror("Unable to catch SIGALRM");
exit(1);
}
+ timeout_dev = ut;
alarm(seconds);
}
@@ -194,10 +184,11 @@ static void cb_xfer(struct libusb_transfer *xfer)
{
int r;
uint8_t *tmp;
+ ubertooth_t* ut = (ubertooth_t*)xfer->user_data;
if (xfer->status != LIBUSB_TRANSFER_COMPLETED) {
if(xfer->status == LIBUSB_TRANSFER_TIMED_OUT) {
- r = libusb_submit_transfer(rx_xfer);
+ r = libusb_submit_transfer(ut->rx_xfer);
if (r < 0)
fprintf(stderr, "Failed to submit USB transfer (%d)\n", r);
return;
@@ -205,33 +196,33 @@ static void cb_xfer(struct libusb_transfer *xfer)
if(xfer->status != LIBUSB_TRANSFER_CANCELLED)
rx_xfer_status(xfer->status);
libusb_free_transfer(xfer);
- rx_xfer = NULL;
+ ut->rx_xfer = NULL;
return;
}
- if(usb_really_full) {
+ if(ut->usb_really_full) {
/* This should never happen, but we'd prefer to error and exit
* than to clobber existing data
*/
fprintf(stderr, "uh oh, full_usb_buf not emptied\n");
- stop_ubertooth = 1;
+ ut->stop_ubertooth = 1;
}
- if(stop_ubertooth)
+ if(ut->stop_ubertooth)
return;
- tmp = full_usb_buf;
- full_usb_buf = empty_usb_buf;
- empty_usb_buf = tmp;
- usb_really_full = 1;
- rx_xfer->buffer = empty_usb_buf;
+ tmp = ut->full_usb_buf;
+ ut->full_usb_buf = ut->empty_usb_buf;
+ ut->empty_usb_buf = tmp;
+ ut->usb_really_full = 1;
+ ut->rx_xfer->buffer = ut->empty_usb_buf;
- r = libusb_submit_transfer(rx_xfer);
+ r = libusb_submit_transfer(ut->rx_xfer);
if (r < 0)
fprintf(stderr, "Failed to submit USB transfer (%d)\n", r);
}
-int stream_rx_usb(struct libusb_device_handle* devh, int xfer_size,
+int stream_rx_usb(ubertooth_t* ut, int xfer_size,
rx_callback cb, void* cb_args)
{
int xfer_blocks, i, r;
@@ -251,23 +242,23 @@ int stream_rx_usb(struct libusb_device_handle* devh, int xfer_size,
xfer_blocks = xfer_size / PKT_LEN;
xfer_size = xfer_blocks * PKT_LEN;
- empty_usb_buf = &rx_buf1[0];
- full_usb_buf = &rx_buf2[0];
- usb_really_full = 0;
- rx_xfer = libusb_alloc_transfer(0);
- libusb_fill_bulk_transfer(rx_xfer, devh, DATA_IN, empty_usb_buf,
- xfer_size, cb_xfer, NULL, TIMEOUT);
+ ut->empty_usb_buf = &rx_buf1[0];
+ ut->full_usb_buf = &rx_buf2[0];
+ ut->usb_really_full = 0;
+ ut->rx_xfer = libusb_alloc_transfer(0);
+ libusb_fill_bulk_transfer(ut->rx_xfer, ut->devh, DATA_IN, ut->empty_usb_buf,
+ xfer_size, cb_xfer, ut, TIMEOUT);
- cmd_rx_syms(devh);
+ cmd_rx_syms(ut->devh);
- r = libusb_submit_transfer(rx_xfer);
+ r = libusb_submit_transfer(ut->rx_xfer);
if (r < 0) {
fprintf(stderr, "rx_xfer submission: %d\n", r);
return -1;
}
while (1) {
- while (!usb_really_full) {
+ while (!ut->usb_really_full) {
r = libusb_handle_events(NULL);
if (r < 0) {
if (r == LIBUSB_ERROR_INTERRUPTED)
@@ -278,17 +269,17 @@ int stream_rx_usb(struct libusb_device_handle* devh, int xfer_size,
/* process each received block */
for (i = 0; i < xfer_blocks; i++) {
- rx = (usb_pkt_rx *)(full_usb_buf + PKT_LEN * i);
+ rx = (usb_pkt_rx *)(ut->full_usb_buf + PKT_LEN * i);
if(rx->pkt_type != KEEP_ALIVE)
- (*cb)(cb_args, rx, bank);
+ (*cb)(ut, cb_args, rx, bank);
bank = (bank + 1) % NUM_BANKS;
- if(stop_ubertooth) {
- if(rx_xfer)
- libusb_cancel_transfer(rx_xfer);
+ if(ut->stop_ubertooth) {
+ if(ut->rx_xfer)
+ libusb_cancel_transfer(ut->rx_xfer);
return 1;
}
}
- usb_really_full = 0;
+ ut->usb_really_full = 0;
fflush(stderr);
}
}
@@ -300,6 +291,10 @@ int stream_rx_file(FILE* fp, rx_callback cb, void* cb_args)
uint8_t buf[BUFFER_SIZE];
size_t nitems;
+ ubertooth_t* ut = ubertooth_init();
+ if (ut == NULL)
+ return -1;
+
while(1) {
uint32_t systime_be;
nitems = fread(&systime_be, sizeof(systime_be), 1, fp);
@@ -310,7 +305,7 @@ int stream_rx_file(FILE* fp, rx_callback cb, void* cb_args)
nitems = fread(buf, sizeof(buf[0]), PKT_LEN, fp);
if (nitems != PKT_LEN)
return 0;
- (*cb)(cb_args, (usb_pkt_rx *)buf, bank);
+ (*cb)(ut, cb_args, (usb_pkt_rx *)buf, bank);
bank = (bank + 1) % NUM_BANKS;
}
}
@@ -402,32 +397,32 @@ static uint64_t now_ns( void )
#endif
}
-static void track_clk100ns( const usb_pkt_rx *rx )
+static void track_clk100ns( ubertooth_t* ut, const usb_pkt_rx* rx )
{
/* track clk100ns */
- if (!start_clk100ns) {
- last_clk100ns = start_clk100ns = rx->clk100ns;
- abs_start_ns = now_ns( );
+ if (!ut->start_clk100ns) {
+ ut->last_clk100ns = ut->start_clk100ns = rx->clk100ns;
+ ut->abs_start_ns = now_ns( );
}
/* detect clk100ns roll-over */
- if (rx->clk100ns < last_clk100ns) {
- clk100ns_upper += 1;
+ if (rx->clk100ns < ut->last_clk100ns) {
+ ut->clk100ns_upper += 1;
}
- last_clk100ns = rx->clk100ns;
+ ut->last_clk100ns = rx->clk100ns;
}
-static uint64_t now_ns_from_clk100ns( const usb_pkt_rx *rx )
+static uint64_t now_ns_from_clk100ns( ubertooth_t* ut, const usb_pkt_rx* rx )
{
- track_clk100ns( rx );
- return abs_start_ns +
- 100ull*(uint64_t)((rx->clk100ns-start_clk100ns)&0xffffffff) +
- ((100ull*clk100ns_upper)<<32);
+ track_clk100ns( ut, rx );
+ return ut->abs_start_ns +
+ 100ull*(uint64_t)((rx->clk100ns-ut->start_clk100ns)&0xffffffff) +
+ ((100ull*ut->clk100ns_upper)<<32);
}
/* Sniff for LAPs. If a piconet is provided, use the given LAP to
* search for UAP.
*/
-static void cb_br_rx(void* args, usb_pkt_rx *rx, int bank)
+static void cb_br_rx(ubertooth_t* ut, void* args, usb_pkt_rx* rx, int bank)
{
btbb_packet *pkt = NULL;
btbb_piconet *pn = (btbb_piconet *)args;
@@ -446,13 +441,13 @@ static void cb_br_rx(void* args, usb_pkt_rx *rx, int bank)
goto out;
/* Copy packet (for dump) */
- memcpy(&usb_packets[bank], rx, sizeof(usb_pkt_rx));
+ memcpy(&(ut->usb_packets[bank]), rx, sizeof(usb_pkt_rx));
- unpack_symbols(rx->data, br_symbols[bank]);
+ unpack_symbols(rx->data, ut->br_symbols[bank]);
/* Do analysis based on oldest packet */
- rx = &usb_packets[ (bank+1) % NUM_BANKS ];
- uint64_t nowns = now_ns_from_clk100ns( rx );
+ rx = &(ut->usb_packets[ (bank+1) % NUM_BANKS ]);
+ uint64_t nowns = now_ns_from_clk100ns( ut, rx );
determine_signal_and_noise( rx, &signal_level, &noise_level );
snr = signal_level - noise_level;
@@ -464,7 +459,7 @@ static void cb_br_rx(void* args, usb_pkt_rx *rx, int bank)
* cross a bank boundary. */
for (i = 0; i < 2; i++)
memcpy(syms + i * BANK_LEN,
- br_symbols[(i + 1 + bank) % NUM_BANKS],
+ ut->br_symbols[(i + 1 + bank) % NUM_BANKS],
BANK_LEN);
/* Look for packets with specified LAP, if given. Otherwise
@@ -486,7 +481,7 @@ static void cb_br_rx(void* args, usb_pkt_rx *rx, int bank)
/* Copy out remaining banks of symbols for full analysis. */
for (i = 1; i < NUM_BANKS; i++)
memcpy(syms + i * BANK_LEN,
- br_symbols[(i + 1 + bank) % NUM_BANKS],
+ ut->br_symbols[(i + 1 + bank) % NUM_BANKS],
BANK_LEN);
/* Once offset is known for a valid packet, copy in symbols
@@ -512,7 +507,7 @@ static void cb_br_rx(void* args, usb_pkt_rx *rx, int bank)
sizeof(systime_be), 1,
dumpfile)
!= 1) {;}
- if (fwrite(&usb_packets[(i + 1 + bank) % NUM_BANKS],
+ if (fwrite(&(ut->usb_packets[(i + 1 + bank) % NUM_BANKS]),
sizeof(usb_pkt_rx), 1, dumpfile)
!= 1) {;}
}
@@ -547,8 +542,8 @@ static void cb_br_rx(void* args, usb_pkt_rx *rx, int bank)
}
if(i < 0) {
- follow_pn = pn;
- stop_ubertooth = 1;
+ ut->follow_pn = pn;
+ ut->stop_ubertooth = 1;
}
out:
@@ -560,32 +555,32 @@ out:
* stream_rx_usb() means that UAP and clocks have been found, and that
* hopping should be started. A more flexible framework would be
* nice. */
-void rx_live(struct libusb_device_handle* devh, btbb_piconet* pn, int timeout)
+void rx_live(ubertooth_t* ut, btbb_piconet* pn, int timeout)
{
int r = btbb_init(max_ac_errors);
if (r < 0)
return;
if (timeout)
- set_timeout(timeout);
+ set_timeout(ut, timeout);
- if (follow_pn)
- cmd_set_clock(devh, 0);
+ if (ut->follow_pn)
+ cmd_set_clock(ut->devh, 0);
else {
- stream_rx_usb(devh, XFER_LEN, cb_br_rx, pn);
+ stream_rx_usb(ut, XFER_LEN, cb_br_rx, pn);
/* Allow pending transfers to finish */
sleep(1);
}
/* Used when follow_pn is preset OR set by stream_rx_usb above
* i.e. This cannot be rolled in to the above if...else
*/
- if (follow_pn) {
- stop_ubertooth = 0;
- usb_really_full = 0;
- cmd_stop(devh);
- cmd_set_bdaddr(devh, btbb_piconet_get_bdaddr(follow_pn));
- cmd_start_hopping(devh, btbb_piconet_get_clk_offset(follow_pn));
- stream_rx_usb(devh, XFER_LEN, cb_br_rx, follow_pn);
+ if (ut->follow_pn) {
+ ut->stop_ubertooth = 0;
+ ut->usb_really_full = 0;
+ cmd_stop(ut->devh);
+ cmd_set_bdaddr(ut->devh, btbb_piconet_get_bdaddr(ut->follow_pn));
+ cmd_start_hopping(ut->devh, btbb_piconet_get_clk_offset(ut->follow_pn));
+ stream_rx_usb(ut, XFER_LEN, cb_br_rx, ut->follow_pn);
}
}
@@ -601,7 +596,7 @@ void rx_file(FILE* fp, btbb_piconet* pn)
/*
* Sniff Bluetooth Low Energy packets.
*/
-void cb_btle(void* args, usb_pkt_rx *rx, int bank)
+void cb_btle(ubertooth_t* ut, void* args, usb_pkt_rx *rx, int bank)
{
lell_packet * pkt;
btle_options * opts = (btle_options *) args;
@@ -643,7 +638,7 @@ void cb_btle(void* args, usb_pkt_rx *rx, int bank)
return;
}
- uint64_t nowns = now_ns_from_clk100ns( rx );
+ uint64_t nowns = now_ns_from_clk100ns( ut, rx );
/* Sanity check */
if (rx->channel > (NUM_BREDR_CHANNELS-1))
@@ -720,7 +715,7 @@ void cb_btle(void* args, usb_pkt_rx *rx, int bank)
/*
* Sniff E-GO packets
*/
-void cb_ego(void* args __attribute__((unused)), usb_pkt_rx *rx, int bank)
+void cb_ego(ubertooth_t* ut, void* args __attribute__((unused)), usb_pkt_rx *rx, int bank)
{
int i;
static u32 prev_ts = 0;
@@ -750,30 +745,30 @@ void rx_btle_file(FILE* fp)
stream_rx_file(fp, cb_btle, NULL);
}
-static void cb_dump_bitstream(void* args, usb_pkt_rx *rx, int bank)
+static void cb_dump_bitstream(ubertooth_t* ut, void* args, usb_pkt_rx *rx, int bank)
{
int i;
char nl = '\n';
UNUSED(args);
- unpack_symbols(rx->data, br_symbols[bank]);
+ unpack_symbols(rx->data, ut->br_symbols[bank]);
// convert to ascii
for (i = 0; i < BANK_LEN; ++i)
- br_symbols[bank][i] += 0x30;
+ ut->br_symbols[bank][i] += 0x30;
fprintf(stderr, "rx block timestamp %u * 100 nanoseconds\n", rx->clk100ns);
if (dumpfile == NULL) {
- if (fwrite(br_symbols[bank], sizeof(u8), BANK_LEN, stdout) != 1) {;}
+ if (fwrite(ut->br_symbols[bank], sizeof(u8), BANK_LEN, stdout) != 1) {;}
fwrite(&nl, sizeof(u8), 1, stdout);
} else {
- if (fwrite(br_symbols[bank], sizeof(u8), BANK_LEN, dumpfile) != 1) {;}
+ if (fwrite(ut->br_symbols[bank], sizeof(u8), BANK_LEN, dumpfile) != 1) {;}
fwrite(&nl, sizeof(u8), 1, dumpfile);
}
}
-static void cb_dump_full(void* args, usb_pkt_rx *rx, int bank)
+static void cb_dump_full(ubertooth_t* ut, void* args, usb_pkt_rx *rx, int bank)
{
uint8_t *buf = (uint8_t*)rx;
@@ -793,16 +788,16 @@ static void cb_dump_full(void* args, usb_pkt_rx *rx, int bank)
}
/* dump received symbols to stdout */
-void rx_dump(struct libusb_device_handle* devh, int bitstream)
+void rx_dump(ubertooth_t* ut, int bitstream)
{
if (bitstream)
- stream_rx_usb(devh, XFER_LEN, cb_dump_bitstream, NULL);
+ stream_rx_usb(ut, XFER_LEN, cb_dump_bitstream, NULL);
else
- stream_rx_usb(devh, XFER_LEN, cb_dump_full, NULL);
+ stream_rx_usb(ut, XFER_LEN, cb_dump_full, NULL);
}
/* Spectrum analyser mode */
-int specan(struct libusb_device_handle* devh, int xfer_size, u16 low_freq,
+int specan(ubertooth_t* ut, int xfer_size, u16 low_freq,
u16 high_freq, u8 output_mode)
{
u8 buffer[BUFFER_SIZE];
@@ -817,10 +812,10 @@ int specan(struct libusb_device_handle* devh, int xfer_size, u16 low_freq,
xfer_blocks = xfer_size / PKT_LEN;
xfer_size = xfer_blocks * PKT_LEN;
- cmd_specan(devh, low_freq, high_freq);
+ cmd_specan(ut->devh, low_freq, high_freq);
while (1) {
- r = libusb_bulk_transfer(devh, DATA_IN, buffer, xfer_size,
+ r = libusb_bulk_transfer(ut->devh, DATA_IN, buffer, xfer_size,
&transferred, TIMEOUT);
if (r < 0) {
fprintf(stderr, "bulk read returned: %d , failed to read\n", r);
@@ -889,16 +884,16 @@ int specan(struct libusb_device_handle* devh, int xfer_size, u16 low_freq,
return 0;
}
-void ubertooth_stop(struct libusb_device_handle *devh)
+void ubertooth_stop(ubertooth_t* ut)
{
/* make sure xfers are not active */
- if(rx_xfer != NULL)
- libusb_cancel_transfer(rx_xfer);
- if (devh != NULL) {
- cmd_stop(devh);
- libusb_release_interface(devh, 0);
+ if(ut->rx_xfer != NULL)
+ libusb_cancel_transfer(ut->rx_xfer);
+ if (ut->devh != NULL) {
+ cmd_stop(ut->devh);
+ libusb_release_interface(ut->devh, 0);
}
- libusb_close(devh);
+ libusb_close(ut->devh);
libusb_exit(NULL);
#ifdef ENABLE_PCAP
@@ -921,10 +916,33 @@ void ubertooth_stop(struct libusb_device_handle *devh)
}
}
-struct libusb_device_handle* ubertooth_start(int ubertooth_device)
+ubertooth_t* ubertooth_init()
+{
+ ubertooth_t* ut = (ubertooth_t*)malloc(sizeof(ubertooth_t));
+ if(ut == NULL) {
+ fprintf(stderr, "Unable to allocate memory\n");
+ }
+
+ ut->devh = NULL;
+ ut->rx_xfer = NULL;
+ ut->empty_usb_buf = NULL;
+ ut->full_usb_buf = NULL;
+ ut->usb_really_full = 0;
+ ut->usb_retry = 1;
+ ut->stop_ubertooth = 0;
+ ut->abs_start_ns;
+ ut->start_clk100ns = 0;
+ ut->last_clk100ns = 0;
+ ut->clk100ns_upper = 0;
+ ut->follow_pn = NULL;
+
+ return ut;
+}
+
+ubertooth_t* ubertooth_start(int ubertooth_device)
{
int r;
- struct libusb_device_handle *devh = NULL;
+ ubertooth_t* ut = ubertooth_init();
r = libusb_init(NULL);
if (r < 0) {
@@ -932,19 +950,19 @@ struct libusb_device_handle* ubertooth_start(int ubertooth_device)
return NULL;
}
- devh = find_ubertooth_device(ubertooth_device);
- if (devh == NULL) {
+ ut->devh = find_ubertooth_device(ubertooth_device);
+ if (ut->devh == NULL) {
fprintf(stderr, "could not open Ubertooth device\n");
- ubertooth_stop(devh);
+ ubertooth_stop(ut);
return NULL;
}
- r = libusb_claim_interface(devh, 0);
+ r = libusb_claim_interface(ut->devh, 0);
if (r < 0) {
fprintf(stderr, "usb_claim_interface error %d\n", r);
- ubertooth_stop(devh);
+ ubertooth_stop(ut);
return NULL;
}
- return devh;
+ return ut;
}
diff --git a/host/libubertooth/src/ubertooth.h b/host/libubertooth/src/ubertooth.h
index 7c5cbeb..7bfc745 100644
--- a/host/libubertooth/src/ubertooth.h
+++ b/host/libubertooth/src/ubertooth.h
@@ -43,29 +43,49 @@ enum board_ids {
BOARD_ID_TC13BADGE = 2
};
-typedef void (*rx_callback)(void* args, usb_pkt_rx *rx, int bank);
+typedef struct {
+ usb_pkt_rx usb_packets[NUM_BANKS];
+ char br_symbols[NUM_BANKS][BANK_LEN];
+
+ struct libusb_device_handle* devh;
+ struct libusb_transfer* rx_xfer;
+ uint8_t* empty_usb_buf;
+ uint8_t* full_usb_buf;
+ uint8_t usb_really_full;
+ uint8_t usb_retry;
+
+ uint8_t stop_ubertooth;
+ uint64_t abs_start_ns;
+ uint32_t start_clk100ns;
+ uint64_t last_clk100ns;
+ uint64_t clk100ns_upper;
+ btbb_piconet* follow_pn;
+} ubertooth_t;
+
+typedef void (*rx_callback)(ubertooth_t* ut, void* args, usb_pkt_rx *rx, int bank);
typedef struct {
unsigned allowed_access_address_errors;
} btle_options;
void print_version();
-void register_cleanup_handler(struct libusb_device_handle *devh);
-struct libusb_device_handle* ubertooth_start(int ubertooth_device);
-void ubertooth_stop(struct libusb_device_handle *devh);
-int specan(struct libusb_device_handle* devh, int xfer_size, u16 low_freq,
+void register_cleanup_handler(ubertooth_t* ut);
+ubertooth_t* ubertooth_init();
+ubertooth_t* ubertooth_start(int ubertooth_device);
+void ubertooth_stop(ubertooth_t* ut);
+int specan(ubertooth_t* ut, int xfer_size, u16 low_freq,
u16 high_freq, u8 output_mode);
int cmd_ping(struct libusb_device_handle* devh);
-int stream_rx_usb(struct libusb_device_handle* devh, int xfer_size,
+int stream_rx_usb(ubertooth_t* ut, int xfer_size,
rx_callback cb, void* cb_args);
int stream_rx_file(FILE* fp, rx_callback cb, void* cb_args);
-void rx_live(struct libusb_device_handle* devh, btbb_piconet* pn, int timeout);
+void rx_live(ubertooth_t* ut, btbb_piconet* pn, int timeout);
void rx_file(FILE* fp, btbb_piconet* pn);
-void rx_dump(struct libusb_device_handle* devh, int full);
-void rx_btle(struct libusb_device_handle* devh);
+void rx_dump(ubertooth_t* ut, int full);
+void rx_btle(ubertooth_t* ut);
void rx_btle_file(FILE* fp);
-void cb_btle(void* args, usb_pkt_rx *rx, int bank);
-void cb_ego(void* args, usb_pkt_rx *rx, int bank);
+void cb_btle(ubertooth_t* ut, void* args, usb_pkt_rx *rx, int bank);
+void cb_ego(ubertooth_t* ut, void* args, usb_pkt_rx *rx, int bank);
#ifdef ENABLE_PCAP
extern btbb_pcap_handle * h_pcap_bredr;
diff --git a/host/ubertooth-tools/src/ubertooth-btle.c b/host/ubertooth-tools/src/ubertooth-btle.c
index ec19131..512b89b 100644
--- a/host/ubertooth-tools/src/ubertooth-btle.c
+++ b/host/ubertooth-tools/src/ubertooth-btle.c
@@ -33,7 +33,7 @@ extern pcap_t *pcap_dumpfile;
extern pcap_dumper_t *dumper;
#endif // ENABLE_PCAP
-struct libusb_device_handle *devh = NULL;
+ubertooth_t* ut = NULL;
int convert_mac_address(char *s, uint8_t *o) {
int i;
@@ -229,14 +229,14 @@ int main(int argc, char *argv[])
}
}
- devh = ubertooth_start(ubertooth_device);
- if (devh == NULL) {
+ ut = ubertooth_start(ubertooth_device);
+ if (ut == NULL) {
usage();
return 1;
}
/* Clean up on exit. */
- register_cleanup_handler(devh);
+ register_cleanup_handler(ut);
if (do_follow && do_promisc) {
printf("Error: must choose either -f or -p, one or the other pal\n");
@@ -246,12 +246,12 @@ int main(int argc, char *argv[])
if (do_follow || do_promisc) {
usb_pkt_rx pkt;
- int r = cmd_set_jam_mode(devh, jam_mode);
+ int r = cmd_set_jam_mode(ut->devh, jam_mode);
if (jam_mode != JAM_NONE && r != 0) {
printf("Jamming not supported\n");
return 1;
}
- cmd_set_modulation(devh, MOD_BT_LOW_ENERGY);
+ cmd_set_modulation(ut->devh, MOD_BT_LOW_ENERGY);
if (do_follow) {
u16 channel;
@@ -261,42 +261,42 @@ int main(int argc, char *argv[])
channel = 2426;
else
channel = 2480;
- cmd_set_channel(devh, channel);
- cmd_btle_sniffing(devh, 2);
+ cmd_set_channel(ut->devh, channel);
+ cmd_btle_sniffing(ut->devh, 2);
} else {
- cmd_btle_promisc(devh);
+ cmd_btle_promisc(ut->devh);
}
while (1) {
- int r = cmd_poll(devh, &pkt);
+ int r = cmd_poll(ut->devh, &pkt);
if (r < 0) {
printf("USB error\n");
break;
}
if (r == sizeof(usb_pkt_rx))
- cb_btle(&cb_opts, &pkt, 0);
+ cb_btle(ut, &cb_opts, &pkt, 0);
usleep(500);
}
- ubertooth_stop(devh);
+ ubertooth_stop(ut);
}
if (do_get_aa) {
- access_address = cmd_get_access_address(devh);
+ access_address = cmd_get_access_address(ut->devh);
printf("Access address: %08x\n", access_address);
return 0;
}
if (do_set_aa) {
- cmd_set_access_address(devh, access_address);
+ cmd_set_access_address(ut->devh, access_address);
printf("access address set to: %08x\n", access_address);
}
if (do_crc >= 0) {
int r;
if (do_crc == 2) {
- r = cmd_get_crc_verify(devh);
+ r = cmd_get_crc_verify(ut->devh);
} else {
- cmd_set_crc_verify(devh, do_crc);
+ cmd_set_crc_verify(ut->devh, do_crc);
r = do_crc;
}
printf("CRC: %sverify\n", r ? "" : "DO NOT ");
@@ -310,13 +310,13 @@ int main(int argc, char *argv[])
channel = 2426;
else
channel = 2480;
- cmd_set_channel(devh, channel);
+ cmd_set_channel(ut->devh, channel);
- cmd_btle_slave(devh, mac_address);
+ cmd_btle_slave(ut->devh, mac_address);
}
if (do_target) {
- r = cmd_btle_set_target(devh, mac_address);
+ r = cmd_btle_set_target(ut->devh, mac_address);
if (r == 0) {
int i;
printf("target set to: ");
diff --git a/host/ubertooth-tools/src/ubertooth-debug.c b/host/ubertooth-tools/src/ubertooth-debug.c
index 35c559c..17b8047 100644
--- a/host/ubertooth-tools/src/ubertooth-debug.c
+++ b/host/ubertooth-tools/src/ubertooth-debug.c
@@ -69,7 +69,7 @@ int main(int argc, char *argv[])
int opt;
int r = 0;
int verbose = 1;
- struct libusb_device_handle *devh = NULL;
+ ubertooth_t* ut = NULL;
int do_read_register;
char ubertooth_device = -1;
int *regList = NULL;
@@ -117,15 +117,15 @@ int main(int argc, char *argv[])
}
/* initialise device */
- devh = ubertooth_start(ubertooth_device);
- if (devh == NULL) {
+ ut = ubertooth_start(ubertooth_device);
+ if (ut == NULL) {
usage();
return 1;
}
if (do_read_register >= 0) {
for (i = 0; i < regListN; i++) {
- r = cmd_read_register(devh, regList[i]);
+ r = cmd_read_register(ut->devh, regList[i]);
if (r >= 0)
cc2400_decode(stdout, regList[i], r, verbose);
}
diff --git a/host/ubertooth-tools/src/ubertooth-dfu.c b/host/ubertooth-tools/src/ubertooth-dfu.c
index b1e1931..433c66c 100644
--- a/host/ubertooth-tools/src/ubertooth-dfu.c
+++ b/host/ubertooth-tools/src/ubertooth-dfu.c
@@ -406,6 +406,7 @@ int main(int argc, char **argv) {
uint8_t functions = 0;
int opt, ubertooth_device = -1;
int r;
+ ubertooth_t* ut = NULL;
while ((opt=getopt(argc,argv,"hd:u:s:rU:")) != EOF) {
switch(opt) {
@@ -468,7 +469,8 @@ int main(int argc, char **argv) {
int rv, count= 0;
devh = find_ubertooth_dfu_device();
if(devh == NULL) {
- devh = ubertooth_start(ubertooth_device);
+ ut = ubertooth_start(ubertooth_device);
+ devh = ut->devh;
cmd_flash(devh);
fprintf(stdout, "Switching to DFU mode...\n");
while(((devh = find_ubertooth_dfu_device()) == NULL) && (count++) < 5)
diff --git a/host/ubertooth-tools/src/ubertooth-dump.c b/host/ubertooth-tools/src/ubertooth-dump.c
index abc79d0..9e0af92 100644
--- a/host/ubertooth-tools/src/ubertooth-dump.c
+++ b/host/ubertooth-tools/src/ubertooth-dump.c
@@ -53,7 +53,7 @@ int main(int argc, char *argv[])
int bitstream = 0;
int modulation = MOD_BT_BASIC_RATE;
char ubertooth_device = -1;
- struct libusb_device_handle *devh = NULL;
+ ubertooth_t* ut = NULL;
while ((opt=getopt(argc,argv,"bhclU:d:")) != EOF) {
switch(opt) {
@@ -83,19 +83,19 @@ int main(int argc, char *argv[])
}
}
- devh = ubertooth_start(ubertooth_device);
+ ut = ubertooth_start(ubertooth_device);
- if (devh == NULL) {
+ if (ut == NULL) {
usage();
return 1;
}
/* Clean up on exit. */
- register_cleanup_handler(devh);
+ register_cleanup_handler(ut);
- cmd_set_modulation(devh, modulation);
- rx_dump(devh, bitstream);
+ cmd_set_modulation(ut->devh, modulation);
+ rx_dump(ut, bitstream);
- ubertooth_stop(devh);
+ ubertooth_stop(ut);
return 0;
}
diff --git a/host/ubertooth-tools/src/ubertooth-ego.c b/host/ubertooth-tools/src/ubertooth-ego.c
index 6a0e291..fa92862 100644
--- a/host/ubertooth-tools/src/ubertooth-ego.c
+++ b/host/ubertooth-tools/src/ubertooth-ego.c
@@ -27,7 +27,7 @@
#include <unistd.h>
#include <stdlib.h>
-struct libusb_device_handle *devh = NULL;
+ubertooth_t* ut = NULL;
static void usage(void)
{
@@ -77,22 +77,22 @@ int main(int argc, char *argv[])
}
}
- devh = ubertooth_start(ubertooth_device);
- if (devh == NULL) {
+ ut = ubertooth_start(ubertooth_device);
+ if (ut == NULL) {
usage();
return 1;
}
/* Clean up on exit. */
- register_cleanup_handler(devh);
+ register_cleanup_handler(ut);
if (do_mode >= 0) {
usb_pkt_rx pkt;
if (do_mode == 1) // FIXME magic number!
- cmd_set_channel(devh, do_channel);
+ cmd_set_channel(ut->devh, do_channel);
- r = cmd_ego(devh, do_mode);
+ r = cmd_ego(ut->devh, do_mode);
if (r < 0) {
if (do_mode == 0 || do_mode == 1)
printf("Error: E-GO not supported by this firmware\n");
@@ -102,16 +102,16 @@ int main(int argc, char *argv[])
}
while (1) {
- int r = cmd_poll(devh, &pkt);
+ int r = cmd_poll(ut->devh, &pkt);
if (r < 0) {
printf("USB error\n");
break;
}
if (r == sizeof(usb_pkt_rx))
- cb_ego(NULL, &pkt, 0);
+ cb_ego(ut, NULL, &pkt, 0);
usleep(500);
}
- ubertooth_stop(devh);
+ ubertooth_stop(ut);
}
return 0;
diff --git a/host/ubertooth-tools/src/ubertooth-follow.c b/host/ubertooth-tools/src/ubertooth-follow.c
index f0a1c94..a772f32 100644
--- a/host/ubertooth-tools/src/ubertooth-follow.c
+++ b/host/ubertooth-tools/src/ubertooth-follow.c
@@ -33,10 +33,9 @@
#include <getopt.h>
extern int max_ac_errors;
-extern btbb_piconet *follow_pn;
extern FILE *dumpfile;
-struct libusb_device_handle *devh = NULL;
+ubertooth_t* ut = NULL;
static void usage()
{
@@ -224,22 +223,22 @@ int main(int argc, char *argv[])
}
/* Clean up on exit. */
- register_cleanup_handler(devh);
+ register_cleanup_handler(ut);
- devh = ubertooth_start(ubertooth_device);
- if (devh == NULL) {
+ ut = ubertooth_start(ubertooth_device);
+ if (ut == NULL) {
usage();
return 1;
}
- cmd_set_bdaddr(devh, btbb_piconet_get_bdaddr(pn));
+ cmd_set_bdaddr(ut->devh, btbb_piconet_get_bdaddr(pn));
if(afh_enabled)
- cmd_set_afh_map(devh, afh_map);
+ cmd_set_afh_map(ut->devh, afh_map);
btbb_piconet_set_clk_offset(pn, clock+delay);
btbb_piconet_set_flag(pn, BTBB_FOLLOWING, 1);
btbb_piconet_set_flag(pn, BTBB_CLK27_VALID, 1);
- follow_pn = pn;
- rx_live(devh, pn, 0);
- ubertooth_stop(devh);
+ ut->follow_pn = pn;
+ rx_live(ut, pn, 0);
+ ubertooth_stop(ut);
return 0;
}
diff --git a/host/ubertooth-tools/src/ubertooth-rx.c b/host/ubertooth-tools/src/ubertooth-rx.c
index 7fc79b8..9210990 100644
--- a/host/ubertooth-tools/src/ubertooth-rx.c
+++ b/host/ubertooth-tools/src/ubertooth-rx.c
@@ -28,7 +28,7 @@ extern FILE *dumpfile;
extern FILE *infile;
extern int max_ac_errors;
-struct libusb_device_handle *devh = NULL;
+ubertooth_t* ut = NULL;
static void usage()
{
@@ -148,8 +148,8 @@ int main(int argc, char *argv[])
}
if (infile == NULL) {
- devh = ubertooth_start(ubertooth_device);
- if (devh == NULL) {
+ ut = ubertooth_start(ubertooth_device);
+ if (ut == NULL) {
usage();
return 1;
}
@@ -158,19 +158,19 @@ int main(int argc, char *argv[])
* ubertooth-utils -c9999. This is necessary after
* following a piconet. */
if (reset_scan) {
- cmd_set_channel(devh, 9999);
+ cmd_set_channel(ut->devh, 9999);
}
/* Clean up on exit. */
- register_cleanup_handler(devh);
+ register_cleanup_handler(ut);
- rx_live(devh, pn, timeout);
+ rx_live(ut, pn, timeout);
// Print AFH map from piconet if we have one
if (pn)
btbb_print_afh_map(pn);
- ubertooth_stop(devh);
+ ubertooth_stop(ut);
} else {
rx_file(infile, pn);
fclose(infile);
diff --git a/host/ubertooth-tools/src/ubertooth-scan.c b/host/ubertooth-tools/src/ubertooth-scan.c
index 9945897..122ffa3 100644
--- a/host/ubertooth-tools/src/ubertooth-scan.c
+++ b/host/ubertooth-tools/src/ubertooth-scan.c
@@ -188,7 +188,7 @@ int main(int argc, char *argv[])
char ubertooth_device = -1;
char *bt_dev = "hci0";
char addr[19] = { 0 };
- struct libusb_device_handle *devh = NULL;
+ ubertooth_t* ut = NULL;
btbb_piconet *pn;
bdaddr_t bdaddr;
@@ -235,13 +235,13 @@ int main(int argc, char *argv[])
return 1;
}
- devh = ubertooth_start(ubertooth_device);
- if (devh == NULL) {
+ ut = ubertooth_start(ubertooth_device);
+ if (ut == NULL) {
usage();
return 1;
}
/* Set sweep mode - otherwise AFH map is useless */
- cmd_set_channel(devh, 9999);
+ cmd_set_channel(ut->devh, 9999);
if (scan) {
/* Equivalent to "hcitool scan" */
@@ -266,8 +266,8 @@ int main(int argc, char *argv[])
/* Now find hidden piconets with Ubertooth */
printf("\nUbertooth scan\n");
btbb_init_survey();
- rx_live(devh, NULL, timeout);
- ubertooth_stop(devh);
+ rx_live(ut, NULL, timeout);
+ ubertooth_stop(ut);
while((pn=btbb_next_survey_result()) != NULL) {
lap = btbb_piconet_get_lap(pn);
diff --git a/host/ubertooth-tools/src/ubertooth-specan.c b/host/ubertooth-tools/src/ubertooth-specan.c
index 8998674..c233c0b 100644
--- a/host/ubertooth-tools/src/ubertooth-specan.c
+++ b/host/ubertooth-tools/src/ubertooth-specan.c
@@ -26,7 +26,7 @@
extern u8 debug;
extern FILE *dumpfile;
-struct libusb_device_handle *devh = NULL;
+ubertooth_t* ut = NULL;
static void usage(FILE *file)
{
@@ -95,23 +95,23 @@ int main(int argc, char *argv[])
}
}
- devh = ubertooth_start(ubertooth_device);
+ ut = ubertooth_start(ubertooth_device);
- if (devh == NULL) {
+ if (ut == NULL) {
usage(stderr);
return 1;
}
/* Clean up on exit. */
- register_cleanup_handler(devh);
+ register_cleanup_handler(ut);
while (1) {
- r = specan(devh, 512, lower, upper, output_mode);
+ r = specan(ut, 512, lower, upper, output_mode);
if(r<0)
break;
}
- ubertooth_stop(devh);
+ ubertooth_stop(ut);
fprintf(stderr, "Ubertooth stopped\n");
return r;
}
diff --git a/host/ubertooth-tools/src/ubertooth-util.c b/host/ubertooth-tools/src/ubertooth-util.c
index 3c1455c..21f5349 100644
--- a/host/ubertooth-tools/src/ubertooth-util.c
+++ b/host/ubertooth-tools/src/ubertooth-util.c
@@ -64,7 +64,7 @@ int main(int argc, char *argv[])
{
int opt;
int r = 0;
- struct libusb_device_handle *devh= NULL;
+ ubertooth_t* ut = NULL;
rangetest_result rr;
int do_stop, do_flash, do_isp, do_leds, do_part, do_reset;
int do_serial, do_tx, do_palevel, do_channel, do_led_specan;
@@ -188,71 +188,71 @@ int main(int argc, char *argv[])
}
/* initialise device */
- devh = ubertooth_start(ubertooth_device);
- if (devh == NULL) {
+ ut = ubertooth_start(ubertooth_device);
+ if (ut == NULL) {
usage();
return 1;
}
if(do_reset == 0) {
printf("Resetting ubertooth device number %d\n", (ubertooth_device >= 0) ? ubertooth_device : 0);
- r = cmd_reset(devh);
+ r = cmd_reset(ut->devh);
sleep(2);
- devh = ubertooth_start(ubertooth_device);
+ ut = ubertooth_start(ubertooth_device);
}
if(do_stop == 0) {
printf("Stopping ubertooth device number %d\n", (ubertooth_device >= 0) ? ubertooth_device : 0);
- r= cmd_stop(devh);
+ r = cmd_stop(ut->devh);
}
/* device configuration actions */
if(do_all_leds == 0 || do_all_leds == 1) {
- cmd_set_usrled(devh, do_all_leds);
- cmd_set_rxled(devh, do_all_leds);
- r= cmd_set_txled(devh, do_all_leds);
+ cmd_set_usrled(ut->devh, do_all_leds);
+ cmd_set_rxled(ut->devh, do_all_leds);
+ r= cmd_set_txled(ut->devh, do_all_leds);
r = (r >= 0) ? 0 : r;
}
if(do_channel > 0)
- r= cmd_set_channel(devh, do_channel);
+ r= cmd_set_channel(ut->devh, do_channel);
if(do_leds == 0 || do_leds == 1)
- r= cmd_set_usrled(devh, do_leds);
+ r= cmd_set_usrled(ut->devh, do_leds);
if(do_palevel > 0)
- r= cmd_set_palevel(devh, do_palevel);
+ r= cmd_set_palevel(ut->devh, do_palevel);
/* reporting actions */
if(do_all_leds == 2) {
- printf("USR LED status: %d\n", cmd_get_usrled(devh));
- printf("RX LED status : %d\n", cmd_get_rxled(devh));
- printf("TX LED status : %d\n", r= cmd_get_txled(devh));
+ printf("USR LED status: %d\n", cmd_get_usrled(ut->devh));
+ printf("RX LED status : %d\n", cmd_get_rxled(ut->devh));
+ printf("TX LED status : %d\n", r= cmd_get_txled(ut->devh));
r = (r >= 0) ? 0 : r;
}
if(do_board_id == 0) {
- r= cmd_get_board_id(devh);
+ r= cmd_get_board_id(ut->devh);
printf("Board ID Number: %d (%s)\n", r, board_names[r]);
}
if(do_channel == 0) {
- r= cmd_get_channel(devh);
+ r= cmd_get_channel(ut->devh);
printf("Current frequency: %d MHz (Bluetooth channel %d)\n", r, r - 2402);
}
if(do_firmware == 0) {
char version[255];
- cmd_get_rev_num(devh, version, (u8)sizeof(version));
+ cmd_get_rev_num(ut->devh, version, (u8)sizeof(version));
printf("Firmware revision: %s\n", version);
}
if(do_compile_info == 0) {
char compile_info[255];
- cmd_get_compile_info(devh, compile_info, (u8)sizeof(compile_info));
+ cmd_get_compile_info(ut->devh, compile_info, (u8)sizeof(compile_info));
puts(compile_info);
}
if(do_leds == 2)
- printf("USR LED status: %d\n", r= cmd_get_usrled(devh));
+ printf("USR LED status: %d\n", r= cmd_get_usrled(ut->devh));
if(do_palevel == 0)
- printf("PA Level: %d\n", r= cmd_get_palevel(devh));
+ printf("PA Level: %d\n", r= cmd_get_palevel(ut->devh));
if(do_part == 0) {
- printf("Part ID: %X\n", r = cmd_get_partnum(devh));
+ printf("Part ID: %X\n", r = cmd_get_partnum(ut->devh));
r = (r >= 0) ? 0 : r;
}
if(do_range_result == 0) {
- r = cmd_get_rangeresult(devh, &rr);
+ r = cmd_get_rangeresult(ut->devh, &rr);
if (r == 0) {
if (rr.valid==1) {
printf("request PA level : %d\n", rr.request_pa);
@@ -268,7 +268,7 @@ int main(int argc, char *argv[])
}
if(do_serial == 0) {
u8 serial[17];
- r= cmd_get_serial(devh, serial);
+ r= cmd_get_serial(ut->devh, serial);
if(r==0) {
print_serial(serial, NULL);
}
@@ -279,51 +279,51 @@ int main(int argc, char *argv[])
/* final actions */
if(do_flash == 0) {
printf("Entering flash programming (DFU) mode\n");
- return cmd_flash(devh);
+ return cmd_flash(ut->devh);
}
if(do_identify == 0) {
printf("Flashing LEDs on ubertooth device number %d\n", (ubertooth_device >= 0) ? ubertooth_device : 0);
while(42) {
do_identify= !do_identify;
- cmd_set_usrled(devh, do_identify);
- cmd_set_rxled(devh, do_identify);
- cmd_set_txled(devh, do_identify);
+ cmd_set_usrled(ut->devh, do_identify);
+ cmd_set_rxled(ut->devh, do_identify);
+ cmd_set_txled(ut->devh, do_identify);
sleep(1);
}
}
if(do_isp == 0) {
printf("Entering flash programming (ISP) mode\n");
- return cmd_set_isp(devh);
+ return cmd_set_isp(ut->devh);
}
if(do_led_specan >= 0) {
do_led_specan= do_led_specan ? do_led_specan : 225;
printf("Entering LED specan mode (RSSI %d)\n", do_led_specan);
- return cmd_led_specan(devh, do_led_specan);
+ return cmd_led_specan(ut->devh, do_led_specan);
}
if(do_range_test == 0) {
printf("Starting range test\n");
- return cmd_range_test(devh);
+ return cmd_range_test(ut->devh);
}
if(do_repeater == 0) {
printf("Starting repeater\n");
- return cmd_repeater(devh);
+ return cmd_repeater(ut->devh);
}
if(do_tx == 0) {
printf("Starting TX test\n");
- return cmd_tx_test(devh);
+ return cmd_tx_test(ut->devh);
}
if(do_set_squelch > 0) {
printf("Setting squelch to %d\n", squelch_level);
- cmd_set_squelch(devh, squelch_level);
+ cmd_set_squelch(ut->devh, squelch_level);
}
if(do_get_squelch > 0) {
- r = cmd_get_squelch(devh);
+ r = cmd_get_squelch(ut->devh);
printf("Squelch set to %d\n", (int8_t)r);
}
if(do_something) {
unsigned char buf[4] = { 0x55, 0x55, 0x55, 0x55 };
- cmd_do_something(devh, NULL, 0);
- cmd_do_something_reply(devh, buf, 4);
+ cmd_do_something(ut->devh, NULL, 0);
+ cmd_do_something_reply(ut->devh, buf, 4);
printf("%02x %02x %02x %02x\n", buf[0], buf[1], buf[2], buf[3]);
return 0;
}