diff options
author | Hannes Ellinger <hannes.ellinger@posteo.de> | 2016-02-11 12:06:27 +0100 |
---|---|---|
committer | Hannes Ellinger <hannes.ellinger@posteo.de> | 2016-02-13 11:44:24 +0100 |
commit | 5172ec3565b2f9df1705065e7a047bc7f2037fad (patch) | |
tree | cd2adce093277543178e3ff6ba3f41e5daeeb33f /host/libubertooth | |
parent | 7e77810f7066bcbcf8ddd260df93207b0957d4bf (diff) |
fix dumpfile support
Diffstat (limited to 'host/libubertooth')
-rw-r--r-- | host/libubertooth/src/ubertooth.c | 19 | ||||
-rw-r--r-- | host/libubertooth/src/ubertooth.h | 2 | ||||
-rw-r--r-- | host/libubertooth/src/ubertooth_callback.c | 20 |
3 files changed, 32 insertions, 9 deletions
diff --git a/host/libubertooth/src/ubertooth.c b/host/libubertooth/src/ubertooth.c index 29b2dad..028a887 100644 --- a/host/libubertooth/src/ubertooth.c +++ b/host/libubertooth/src/ubertooth.c @@ -310,15 +310,11 @@ static int stream_rx_usb(ubertooth_t* ut, rx_callback cb, void* cb_args) } /* file should be in full USB packet format (ubertooth-dump -f) */ -static int stream_rx_file(FILE* fp, rx_callback cb, void* cb_args) +int stream_rx_file(ubertooth_t* ut, 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); @@ -447,12 +443,21 @@ void rx_file(FILE* fp, btbb_piconet* pn) int r = btbb_init(max_ac_errors); if (r < 0) return; - stream_rx_file(fp, cb_br_rx, pn); + + ubertooth_t* ut = ubertooth_init(); + if (ut == NULL) + return; + + stream_rx_file(ut, fp, cb_br_rx, pn); } void rx_btle_file(FILE* fp) { - stream_rx_file(fp, cb_btle, NULL); + ubertooth_t* ut = ubertooth_init(); + if (ut == NULL) + return; + + stream_rx_file(ut, fp, cb_btle, NULL); } static void cb_dump_bitstream(ubertooth_t* ut, void* args __attribute__((unused))) diff --git a/host/libubertooth/src/ubertooth.h b/host/libubertooth/src/ubertooth.h index c396bd9..cab4de6 100644 --- a/host/libubertooth/src/ubertooth.h +++ b/host/libubertooth/src/ubertooth.h @@ -89,6 +89,8 @@ int ubertooth_bulk_init(ubertooth_t* ut); void ubertooth_bulk_wait(ubertooth_t* ut); int ubertooth_bulk_receive(ubertooth_t* ut, rx_callback cb, void* cb_args); +int stream_rx_file(ubertooth_t* ut,FILE* fp, rx_callback cb, void* cb_args); + void rx_live(ubertooth_t* ut, btbb_piconet* pn, int timeout); void rx_file(FILE* fp, btbb_piconet* pn); void rx_dump(ubertooth_t* ut, int full); diff --git a/host/libubertooth/src/ubertooth_callback.c b/host/libubertooth/src/ubertooth_callback.c index 57ed44e..b38be28 100644 --- a/host/libubertooth/src/ubertooth_callback.c +++ b/host/libubertooth/src/ubertooth_callback.c @@ -547,6 +547,12 @@ void cb_rx(ubertooth_t* ut, void* args) btbb_packet_set_data(pkt, syms + offset, NUM_BANKS * BANK_LEN - offset, rx->channel, clkn); + /* When reading from file, caller will read + * systime before calling this routine, so do + * not overwrite. Otherwise, get current time. */ + if (infile == NULL) + systime = time(NULL); + printf("systime=%u ch=%2d LAP=%06x err=%u clkn=%u clk_offset=%u s=%d n=%d snr=%d\n", (uint32_t)time(NULL), btbb_packet_get_channel(pkt), @@ -561,7 +567,7 @@ void cb_rx(ubertooth_t* ut, void* args) /* calibrate Ubertooth clock such that the first bit of the AC * arrives CLK_TUNE_TIME after the rising edge of CLKN */ - if (!calibrated) { + if (infile == NULL && !calibrated) { if (clk_offset < CLK_TUNE_TIME) { printf("offset < CLK_TUNE_TIME\n"); printf("CLK100ns Trim: %d\n", 6250 + clk_offset - CLK_TUNE_TIME); @@ -575,6 +581,16 @@ void cb_rx(ubertooth_t* ut, void* args) goto out; } + /* If dumpfile is specified, write out all banks to the + * file. There could be duplicate data in the dump if more + * than one LAP is found within the span of NUM_BANKS. */ + if (dumpfile) { + uint32_t systime_be = htobe32(systime); + fwrite(&systime_be, sizeof(systime_be), 1, dumpfile); + fwrite(rx, sizeof(usb_pkt_rx), 1, dumpfile); + fflush(dumpfile); + } + /* Dump to PCAP/PCAPNG if specified */ #ifdef ENABLE_PCAP if (ut->h_pcap_bredr) { @@ -590,7 +606,7 @@ void cb_rx(ubertooth_t* ut, void* args) } int r = btbb_process_packet(pkt, pn); - if(r < 0) + if(infile == NULL && r < 0) cmd_start_hopping(ut->devh, btbb_piconet_get_clk_offset(pn), 0); out: |