From 2992c13168ffd5c7ba64c094e594db1ebb030b39 Mon Sep 17 00:00:00 2001 From: "matthias.ringwald" Date: Sun, 5 Dec 2010 22:22:46 +0000 Subject: [PATCH] allow to specify max nr of packets in hci_dump log --- TODO.txt | 9 +++++---- src/daemon.c | 1 + src/hci_dump.c | 20 ++++++++++++++++++-- src/hci_dump.h | 1 + 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/TODO.txt b/TODO.txt index 7f4233d2a..36f67cecd 100644 --- a/TODO.txt +++ b/TODO.txt @@ -3,17 +3,18 @@ 2009-11-08: Release 0.1 2010-06-20: Release 0.2 - SDP + iOS 4 support 2010-11-2x: Release 0.2 - revsion 973 for WeBe++ -- fix regression bug in 0.2-899 that prevented disabling of Apple Bluetooth stack, less crashes +- Fix for regression bug in 0.2-899 that prevented automatic disabling of Apple Bluetooth stack, less crashes - Startup: send kill signal to BlueTool and BTServer, if necessary -- Connection establishment: don't close baseband during authentication, +- Connection setup: don't close baseband during authentication - Remote Device DB: automatic link key handling in BTdaemon, provide cached remote names during inquiry - SDP: use 1000 bytes MTU, fix partial responses, fix an incompatibility with Windows native statck - Cocoa run_loop: added timeouts, include in libBTstack.dylib build +2010-xxxx: Release 0.2 - revions xxx +- limit size of /tmp/hci_dump.pklg to 1000 packets (max 1 MB) + NEXT: - figure out how to receive iPhone System Power IONotifications (in BTdaemon) to detect, when phone gets locked -- limit size of /tmp/hci_dump.pklg - - e.g. rm hci_dump.old.pklg, mv hci_dump.pkg->hci_dump.old.pklg - have a look at External Accessory interface by Apple - it's quite similar - move RFCOMM code into BTdaemon - HCI CMD packet is limited to 1024 bytes payload. SDP records could be larger than that. Options: diff --git a/src/daemon.c b/src/daemon.c index 0e0f7e7ee..2cdb4b078 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -366,6 +366,7 @@ int main (int argc, char * const * argv){ // use logger: format HCI_DUMP_PACKETLOGGER, HCI_DUMP_BLUEZ or HCI_DUMP_STDOUT hci_dump_open("/tmp/hci_dump.pklg", HCI_DUMP_PACKETLOGGER); + hci_dump_set_max_packets(1000); // hci_dump_open(NULL, HCI_DUMP_STDOUT); // init HCI diff --git a/src/hci_dump.c b/src/hci_dump.c index 21fa406ee..577ec8320 100644 --- a/src/hci_dump.c +++ b/src/hci_dump.c @@ -80,6 +80,8 @@ static int dump_format; static hcidump_hdr header_bluez; static pktlog_hdr header_packetlogger; static char time_string[40]; +static int max_nr_packets = -1; +static int nr_packets = 0; #endif void hci_dump_open(char *filename, hci_dump_format_t format){ @@ -88,16 +90,30 @@ void hci_dump_open(char *filename, hci_dump_format_t format){ if (dump_format == HCI_DUMP_STDOUT) { dump_file = fileno(stdout); } else { - dump_file = open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + dump_file = open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); } #endif } +void hci_dump_set_max_packets(int packets){ + max_nr_packets = packets; +} + void hci_dump_packet(uint8_t packet_type, uint8_t in, uint8_t *packet, uint16_t len) { #ifndef EMBEDDED if (dump_file < 0) return; // not activated yet - + + // don't grow bigger than max_nr_packets + if (dump_format != HCI_DUMP_STDOUT && max_nr_packets > 0){ + if (nr_packets >= max_nr_packets){ + lseek(dump_file, 0, SEEK_SET); + ftruncate(dump_file, 0); + nr_packets = 0; + } + nr_packets++; + } + // get time struct timeval curr_time; struct tm* ptm; diff --git a/src/hci_dump.h b/src/hci_dump.h index 254933d18..7b964ed9a 100644 --- a/src/hci_dump.h +++ b/src/hci_dump.h @@ -46,5 +46,6 @@ typedef enum { } hci_dump_format_t; void hci_dump_open(char *filename, hci_dump_format_t format); +void hci_dump_set_max_packets(int packets); // -1 for unlimited void hci_dump_packet(uint8_t packet_type, uint8_t in, uint8_t *packet, uint16_t len); void hci_dump_close();