summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/idevicebtlogger.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/tools/idevicebtlogger.c b/tools/idevicebtlogger.c
index 48be01a..8728ef0 100644
--- a/tools/idevicebtlogger.c
+++ b/tools/idevicebtlogger.c
@@ -45,6 +45,10 @@
45#include <libimobiledevice/bt_packet_logger.h> 45#include <libimobiledevice/bt_packet_logger.h>
46#include <pcap.h> 46#include <pcap.h>
47 47
48#define DLT_BLUETOOTH_HCI_H4_WITH_PHDR 201
49#define LIBPCAP_BT_PHDR_SENT 0x00000000
50#define LIBPCAP_BT_PHDR_RECV htonl(0x00000001)
51
48static int quit_flag = 0; 52static int quit_flag = 0;
49static int exit_on_disconnect = 0; 53static int exit_on_disconnect = 0;
50 54
@@ -67,9 +71,10 @@ static void bt_packet_logger_callback(uint8_t * data, uint16_t len, void *user_d
67 bt_packet_logger_header_t * header = (bt_packet_logger_header_t *)data; 71 bt_packet_logger_header_t * header = (bt_packet_logger_header_t *)data;
68 uint16_t offset = sizeof(bt_packet_logger_header_t); 72 uint16_t offset = sizeof(bt_packet_logger_header_t);
69 73
74 // size + sizeof(uint32_t) to account for the direction pseudo header
70 struct pcap_pkthdr pcap_header; 75 struct pcap_pkthdr pcap_header;
71 pcap_header.caplen = ntohl(header->length); 76 pcap_header.caplen = ntohl(header->length) + sizeof(uint32_t);
72 pcap_header.len = len - sizeof(bt_packet_logger_header_t); 77 pcap_header.len = len - sizeof(bt_packet_logger_header_t) + sizeof(uint32_t);
73 pcap_header.ts.tv_sec = ntohl(header->ts_secs); 78 pcap_header.ts.tv_sec = ntohl(header->ts_secs);
74 pcap_header.ts.tv_usec = ntohl(header->ts_usecs); 79 pcap_header.ts.tv_usec = ntohl(header->ts_usecs);
75 80
@@ -81,31 +86,43 @@ static void bt_packet_logger_callback(uint8_t * data, uint16_t len, void *user_d
81 86
82 uint8_t packet_type = data[offset]; 87 uint8_t packet_type = data[offset];
83 uint8_t hci_h4_type = 0xff; 88 uint8_t hci_h4_type = 0xff;
89 uint32_t direction;
84 90
85 switch(packet_type) { 91 switch(packet_type) {
86 case HCI_EVENT: 92 case HCI_EVENT:
87 hci_h4_type = 0x04; 93 hci_h4_type = 0x04;
94 direction = LIBPCAP_BT_PHDR_RECV;
88 break; 95 break;
89 96
90 case HCI_COMMAND: 97 case HCI_COMMAND:
91 hci_h4_type = 0x01; 98 hci_h4_type = 0x01;
99 direction = LIBPCAP_BT_PHDR_SENT;
92 break; 100 break;
93 101
94 case SENT_ACL_DATA: 102 case SENT_ACL_DATA:
95 hci_h4_type = 0x02; 103 hci_h4_type = 0x02;
104 direction = LIBPCAP_BT_PHDR_SENT;
96 break; 105 break;
97 106
98 case RECV_ACL_DATA: 107 case RECV_ACL_DATA:
99 hci_h4_type = 0x02; 108 hci_h4_type = 0x02;
109 direction = LIBPCAP_BT_PHDR_RECV;
100 break; 110 break;
101 111
102 default: 112 default:
103 // unknown packet logger type, just pass it on 113 // unknown packet logger type, just pass it on
104 hci_h4_type = packet_type; 114 hci_h4_type = packet_type;
115 direction = LIBPCAP_BT_PHDR_RECV;
105 break; 116 break;
106 } 117 }
107 if(hci_h4_type != 0xff) { 118 if(hci_h4_type != 0xff) {
108 data[offset] = hci_h4_type; 119 data[offset] = hci_h4_type;
120 // we know we are sizeof(bt_packet_logger_header_t) into the buffer passed in to
121 // this function. We need to add the uint32_t pseudo header to the front of the packet
122 // so adjust the offset back by sizeof(uint32_t) and write it to the buffer. This avoids
123 // having to memcpy things around.
124 offset -= sizeof(uint32_t);
125 *(uint32_t*)&data[offset] = direction;
109 pcap_dump((unsigned char*)dump, &pcap_header, &data[offset]); 126 pcap_dump((unsigned char*)dump, &pcap_header, &data[offset]);
110 pcap_dump_flush(dump); 127 pcap_dump_flush(dump);
111 } 128 }
@@ -328,7 +345,7 @@ int main(int argc, char *argv[])
328 } 345 }
329 } 346 }
330 347
331 dump = pcap_dump_open(pcap_open_dead(187, BT_MAX_PACKET_SIZE), out_filename); 348 dump = pcap_dump_open(pcap_open_dead(DLT_BLUETOOTH_HCI_H4_WITH_PHDR, BT_MAX_PACKET_SIZE), out_filename);
332 idevice_event_subscribe(device_event_cb, NULL); 349 idevice_event_subscribe(device_event_cb, NULL);
333 350
334 while (!quit_flag) { 351 while (!quit_flag) {