mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-21 21:41:13 +00:00
cleaned up hci_dump integration, added support for Apple's PacketLogger, also store local timestamp
This commit is contained in:
parent
7966267251
commit
8b658ebcf8
11
src/hci.c
11
src/hci.c
@ -60,8 +60,15 @@ static hci_stack_t hci_stack;
|
||||
|
||||
|
||||
void bt_store_16(uint8_t *buffer, uint16_t pos, uint16_t value){
|
||||
buffer[pos] = value & 0xff;
|
||||
buffer[pos+1] = value >> 8;
|
||||
buffer[pos++] = value;
|
||||
buffer[pos++] = value >> 8;
|
||||
}
|
||||
|
||||
void bt_store_32(uint8_t *buffer, uint16_t pos, uint32_t value){
|
||||
buffer[pos++] = value;
|
||||
buffer[pos++] = value >> 8;
|
||||
buffer[pos++] = value >> 16;
|
||||
buffer[pos++] = value >> 24;
|
||||
}
|
||||
|
||||
void bt_flip_addr(bd_addr_t dest, bd_addr_t src){
|
||||
|
@ -173,6 +173,7 @@ int hci_send_acl_packet(uint8_t *packet, int size);
|
||||
|
||||
// helper
|
||||
extern void bt_store_16(uint8_t *buffer, uint16_t pos, uint16_t value);
|
||||
extern void bt_store_32(uint8_t *buffer, uint16_t pos, uint32_t value);
|
||||
|
||||
extern hci_cmd_t hci_inquiry;
|
||||
extern hci_cmd_t hci_link_key_request_negative_reply;
|
||||
|
@ -15,21 +15,78 @@
|
||||
#include <strings.h> // bzero
|
||||
#include <unistd.h> // write
|
||||
#include <stdio.h>
|
||||
#include <sys/time.h> // for timestamps
|
||||
|
||||
static int dump_file;
|
||||
// BLUEZ hcidump
|
||||
typedef struct {
|
||||
uint16_t len;
|
||||
uint8_t in;
|
||||
uint8_t pad;
|
||||
uint32_t ts_sec;
|
||||
uint32_t ts_usec;
|
||||
uint8_t packet_type;
|
||||
} __attribute__ ((packed)) hcidump_hdr;
|
||||
|
||||
void hci_dump_open(char *filename){
|
||||
// APPLE PacketLogger
|
||||
typedef struct {
|
||||
uint32_t len;
|
||||
uint32_t ts_sec;
|
||||
uint32_t ts_usec;
|
||||
uint8_t type;
|
||||
} __attribute__ ((packed)) pktlog_hdr;
|
||||
|
||||
static int dump_file = -1;
|
||||
static int dump_format;
|
||||
static hcidump_hdr header_bluez;
|
||||
static pktlog_hdr header_packetlogger;
|
||||
|
||||
void hci_dump_open(char *filename, hci_dump_format_t format){
|
||||
dump_file = open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
|
||||
dump_format = format;
|
||||
}
|
||||
|
||||
void hci_dump_packet(uint8_t packet_type, uint8_t in, uint8_t *packet, uint16_t len) {
|
||||
static hcidump_hdr header;
|
||||
bzero( &header, sizeof(hcidump_hdr));
|
||||
bt_store_16( (uint8_t *) &header, 0, 1 + len);
|
||||
header.in = in;
|
||||
header.packet_type = packet_type;
|
||||
write (dump_file, &header, sizeof(hcidump_hdr) );
|
||||
write (dump_file, packet, len );
|
||||
if (dump_file < 0) return; // not activated yet
|
||||
|
||||
// get time
|
||||
struct timeval curr_time;
|
||||
gettimeofday(&curr_time, NULL);
|
||||
|
||||
switch (dump_format){
|
||||
case HCI_DUMP_BLUEZ:
|
||||
bt_store_16( (uint8_t *) &header_bluez.len, 0, 1 + len);
|
||||
header_bluez.in = in;
|
||||
header_bluez.pad = 0;
|
||||
bt_store_32( (uint8_t *) &header_bluez.ts_sec, 0, curr_time.tv_sec);
|
||||
bt_store_32( (uint8_t *) &header_bluez.ts_usec, 0, curr_time.tv_usec);
|
||||
header_bluez.packet_type = packet_type;
|
||||
write (dump_file, &header_bluez, sizeof(hcidump_hdr) );
|
||||
write (dump_file, packet, len );
|
||||
break;
|
||||
case HCI_DUMP_PACKETLOGGER:
|
||||
header_packetlogger.len = htonl( sizeof(pktlog_hdr) - 4 + len);
|
||||
header_packetlogger.ts_sec = htonl(curr_time.tv_sec);
|
||||
header_packetlogger.ts_usec = htonl(curr_time.tv_usec);
|
||||
switch (packet_type){
|
||||
case HCI_COMMAND_DATA_PACKET:
|
||||
header_packetlogger.type = 0x00;
|
||||
break;
|
||||
case HCI_ACL_DATA_PACKET:
|
||||
if (in) {
|
||||
header_packetlogger.type = 0x03;
|
||||
} else {
|
||||
header_packetlogger.type = 0x02;
|
||||
}
|
||||
break;
|
||||
case HCI_EVENT_PACKET:
|
||||
header_packetlogger.type = 0x01;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
write (dump_file, &header_packetlogger, sizeof(pktlog_hdr) );
|
||||
write (dump_file, packet, len );
|
||||
}
|
||||
}
|
||||
|
||||
void hci_dump_close(){
|
||||
|
@ -8,15 +8,11 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
uint16_t len;
|
||||
uint8_t in;
|
||||
uint8_t pad;
|
||||
uint32_t ts_sec;
|
||||
uint32_t ts_usec;
|
||||
uint8_t packet_type;
|
||||
} __attribute__ ((packed)) hcidump_hdr;
|
||||
typedef enum {
|
||||
HCI_DUMP_BLUEZ = 0,
|
||||
HCI_DUMP_PACKETLOGGER
|
||||
} hci_dump_format_t;
|
||||
|
||||
void hci_dump_open(char *filename);
|
||||
void hci_dump_open(char *filename, hci_dump_format_t format);
|
||||
void hci_dump_packet(uint8_t packet_type, uint8_t in, uint8_t *packet, uint16_t len);
|
||||
void hci_dump_close();
|
||||
|
@ -14,8 +14,6 @@
|
||||
#include "hci_transport_h4.h"
|
||||
#include "hci_dump.h"
|
||||
|
||||
#define HCI_DUMP
|
||||
|
||||
typedef enum {
|
||||
H4_W4_PACKET_TYPE,
|
||||
H4_W4_EVENT_HEADER,
|
||||
@ -105,17 +103,11 @@ static int h4_open(void *transport_config){
|
||||
h4_state = H4_W4_PACKET_TYPE;
|
||||
read_pos = 0;
|
||||
|
||||
#ifdef HCI_DUMP
|
||||
hci_dump_open("/tmp/hci_dump.cap");
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int h4_close(){
|
||||
#ifdef HCI_DUMP
|
||||
hci_dump_close();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -126,9 +118,7 @@ static int h4_send_cmd_packet(uint8_t *packet, int size){
|
||||
char *data = (char*) packet;
|
||||
char packet_type = HCI_COMMAND_DATA_PACKET;
|
||||
|
||||
#ifdef HCI_DUMP
|
||||
hci_dump_packet( (uint8_t) packet_type, 0, packet, size);
|
||||
#endif
|
||||
|
||||
write(fd, &packet_type, 1);
|
||||
while (size > 0) {
|
||||
@ -149,9 +139,7 @@ static int h4_send_acl_packet(uint8_t *packet, int size){
|
||||
char *data = (char*) packet;
|
||||
char packet_type = HCI_ACL_DATA_PACKET;
|
||||
|
||||
#ifdef HCI_DUMP
|
||||
hci_dump_packet( (uint8_t) packet_type, 0, packet, size);
|
||||
#endif
|
||||
|
||||
write(fd, &packet_type, 1);
|
||||
while (size > 0) {
|
||||
@ -211,9 +199,9 @@ static int h4_handle_data() {
|
||||
case H4_W4_EVENT_PAYLOAD:
|
||||
printf("EVT: ");
|
||||
hexdump(hci_packet, read_pos);
|
||||
#ifdef HCI_DUMP
|
||||
|
||||
hci_dump_packet( HCI_EVENT_PACKET, 1, hci_packet, read_pos);
|
||||
#endif
|
||||
|
||||
event_packet_handler(hci_packet, read_pos);
|
||||
h4_state = H4_W4_PACKET_TYPE;
|
||||
read_pos = 0;
|
||||
@ -226,9 +214,9 @@ static int h4_handle_data() {
|
||||
case H4_W4_ACL_PAYLOAD:
|
||||
printf("<ACL ");
|
||||
hexdump(hci_packet, read_pos);
|
||||
#ifdef HCI_DUMP
|
||||
|
||||
hci_dump_packet( HCI_ACL_DATA_PACKET, 1, hci_packet, read_pos);
|
||||
#endif
|
||||
|
||||
acl_packet_handler(hci_packet, read_pos);
|
||||
h4_state = H4_W4_PACKET_TYPE;
|
||||
read_pos = 0;
|
||||
|
@ -10,10 +10,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "bt_control_iphone.h"
|
||||
|
||||
#include "hci.h"
|
||||
#include "hci_transport_h4.h"
|
||||
#include "hci_dump.h"
|
||||
|
||||
#include "l2cap.h"
|
||||
|
||||
@ -96,7 +95,7 @@ int main (int argc, const char * argv[]) {
|
||||
|
||||
bt_control_t * control = NULL;
|
||||
|
||||
#if 0
|
||||
#if 1
|
||||
//
|
||||
if (argc <= 1){
|
||||
printf("HCI Daemon tester. Specify device name for Ericsson ROK 101 007\n");
|
||||
@ -119,6 +118,9 @@ int main (int argc, const char * argv[]) {
|
||||
control = &bt_control_iphone;
|
||||
#endif
|
||||
|
||||
// use logger: format HCI_DUMP_PACKETLOGGER or HCI_DUMP_BLUEZ
|
||||
hci_dump_open("/tmp/hci_dump.pklg", HCI_DUMP_PACKETLOGGER);
|
||||
|
||||
// H4 UART
|
||||
transport = &hci_transport_h4;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user