diff options
-rw-r--r-- | tools/idevicebtlogger.c | 56 |
1 files changed, 29 insertions, 27 deletions
diff --git a/tools/idevicebtlogger.c b/tools/idevicebtlogger.c index e2ace34..c16573e 100644 --- a/tools/idevicebtlogger.c +++ b/tools/idevicebtlogger.c | |||
@@ -87,16 +87,18 @@ const uint8_t pcap_file_header[] = { | |||
87 | 0x00, 0x00, 0x00, 201, | 87 | 0x00, 0x00, 0x00, 201, |
88 | }; | 88 | }; |
89 | 89 | ||
90 | static uint32_t big_endian_read_32(const uint8_t * buffer, int position) { | 90 | static uint32_t big_endian_read_32(const uint8_t * buffer, int position) |
91 | return ((uint32_t) buffer[position+3]) | (((uint32_t)buffer[position+2]) << 8) | (((uint32_t)buffer[position+1]) << 16) | (((uint32_t) buffer[position]) << 24); | 91 | { |
92 | return ((uint32_t) buffer[position+3]) | (((uint32_t)buffer[position+2]) << 8) | (((uint32_t)buffer[position+1]) << 16) | (((uint32_t) buffer[position]) << 24); | ||
92 | } | 93 | } |
93 | 94 | ||
94 | static void big_endian_store_32(uint8_t * buffer, uint16_t position, uint32_t value){ | 95 | static void big_endian_store_32(uint8_t * buffer, uint16_t position, uint32_t value) |
95 | uint16_t pos = position; | 96 | { |
96 | buffer[pos++] = (uint8_t)(value >> 24); | 97 | uint16_t pos = position; |
97 | buffer[pos++] = (uint8_t)(value >> 16); | 98 | buffer[pos++] = (uint8_t)(value >> 24); |
98 | buffer[pos++] = (uint8_t)(value >> 8); | 99 | buffer[pos++] = (uint8_t)(value >> 16); |
99 | buffer[pos++] = (uint8_t)(value); | 100 | buffer[pos++] = (uint8_t)(value >> 8); |
101 | buffer[pos++] = (uint8_t)(value); | ||
100 | } | 102 | } |
101 | 103 | ||
102 | /** | 104 | /** |
@@ -118,8 +120,8 @@ static void bt_packet_logger_callback_pcap(uint8_t * data, uint16_t len, void *u | |||
118 | } | 120 | } |
119 | 121 | ||
120 | // parse packet header (ignore len field) | 122 | // parse packet header (ignore len field) |
121 | uint32_t ts_secs = big_endian_read_32(data, 4); | 123 | uint32_t ts_secs = big_endian_read_32(data, 4); |
122 | uint32_t ts_us = big_endian_read_32(data, 8); | 124 | uint32_t ts_us = big_endian_read_32(data, 8); |
123 | uint8_t packet_type = data[12]; | 125 | uint8_t packet_type = data[12]; |
124 | data += 13; | 126 | data += 13; |
125 | len -= 13; | 127 | len -= 13; |
@@ -158,18 +160,18 @@ static void bt_packet_logger_callback_pcap(uint8_t * data, uint16_t len, void *u | |||
158 | } | 160 | } |
159 | 161 | ||
160 | // setup pcap record header, 4 byte direction flag, 1 byte HCI H4 packet type, data | 162 | // setup pcap record header, 4 byte direction flag, 1 byte HCI H4 packet type, data |
161 | uint8_t pcap_record_header[21]; | 163 | uint8_t pcap_record_header[21]; |
162 | big_endian_store_32(pcap_record_header, 0, ts_secs); // Timestamp seconds | 164 | big_endian_store_32(pcap_record_header, 0, ts_secs); // Timestamp seconds |
163 | big_endian_store_32(pcap_record_header, 4, ts_us); // Timestamp microseconds | 165 | big_endian_store_32(pcap_record_header, 4, ts_us); // Timestamp microseconds |
164 | big_endian_store_32(pcap_record_header, 8, 4 + 1 + len); // Captured Packet Length | 166 | big_endian_store_32(pcap_record_header, 8, 4 + 1 + len); // Captured Packet Length |
165 | big_endian_store_32(pcap_record_header, 12, 4 + 1 + len); // Original Packet Length | 167 | big_endian_store_32(pcap_record_header, 12, 4 + 1 + len); // Original Packet Length |
166 | big_endian_store_32(pcap_record_header, 16, direction_in); // Direction: Incoming = 1 | 168 | big_endian_store_32(pcap_record_header, 16, direction_in); // Direction: Incoming = 1 |
167 | pcap_record_header[20] = hci_h4_type; | 169 | pcap_record_header[20] = hci_h4_type; |
168 | 170 | ||
169 | // write header | 171 | // write header |
170 | (void) fwrite(pcap_record_header, 1, sizeof(pcap_record_header), packetlogger_file); | 172 | (void) fwrite(pcap_record_header, 1, sizeof(pcap_record_header), packetlogger_file); |
171 | 173 | ||
172 | // write packet | 174 | // write packet |
173 | (void) fwrite(data, 1, len, packetlogger_file); | 175 | (void) fwrite(data, 1, len, packetlogger_file); |
174 | 176 | ||
175 | // flush | 177 | // flush |
@@ -420,20 +422,20 @@ int main(int argc, char *argv[]) | |||
420 | } | 422 | } |
421 | 423 | ||
422 | 424 | ||
423 | if (packetlogger_file == NULL){ | 425 | if (packetlogger_file == NULL){ |
424 | fprintf(stderr, "Failed to open file %s, errno = %d\n", out_filename, errno); | 426 | fprintf(stderr, "Failed to open file %s, errno = %d\n", out_filename, errno); |
425 | return -2; | 427 | return -2; |
426 | } | 428 | } |
427 | 429 | ||
428 | switch (log_format){ | 430 | switch (log_format){ |
429 | case LOG_FORMAT_PCAP: | 431 | case LOG_FORMAT_PCAP: |
430 | // printf("Output Format: PCAP\n"); | 432 | // printf("Output Format: PCAP\n"); |
431 | // write PCAP file header | 433 | // write PCAP file header |
432 | (void) fwrite(&pcap_file_header, 1, sizeof(pcap_file_header), packetlogger_file); | 434 | (void) fwrite(&pcap_file_header, 1, sizeof(pcap_file_header), packetlogger_file); |
433 | break; | 435 | break; |
434 | case LOG_FORMAT_PACKETLOGGER: | 436 | case LOG_FORMAT_PACKETLOGGER: |
435 | printf("Output Format: PacketLogger\n"); | 437 | printf("Output Format: PacketLogger\n"); |
436 | break; | 438 | break; |
437 | default: | 439 | default: |
438 | assert(0); | 440 | assert(0); |
439 | return -2; | 441 | return -2; |