mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-11 09:40:24 +00:00
add simple hci logger compatible to BlueZ's hcidump
This commit is contained in:
parent
0258271367
commit
7966267251
@ -20,6 +20,7 @@ LDFLAGS = \
|
||||
SRCS = \
|
||||
bt_control_iphone.c \
|
||||
hci.c \
|
||||
hci_dump.c \
|
||||
hci_transport_h4.c \
|
||||
l2cap.c \
|
||||
main.c \
|
||||
@ -28,6 +29,7 @@ HEADERS = \
|
||||
bt_control.h \
|
||||
bt_control_iphone.h \
|
||||
hci.h \
|
||||
hci_dump.h \
|
||||
hci_transport.h \
|
||||
hci_transport_h4.h \
|
||||
l2cap.h \
|
||||
|
@ -11,6 +11,7 @@
|
||||
9C46FC390FA906F700ABEF05 /* hci.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C46FC340FA906F700ABEF05 /* hci.c */; };
|
||||
9C46FC3A0FA906F700ABEF05 /* hci_transport_h4.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C46FC360FA906F700ABEF05 /* hci_transport_h4.c */; };
|
||||
9C7ECB840FCC85650085DAC5 /* bt_control_iphone.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C7ECB820FCC85650085DAC5 /* bt_control_iphone.c */; };
|
||||
9C7ECBB50FCC95DD0085DAC5 /* hci_dump.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C7ECBB40FCC95DD0085DAC5 /* hci_dump.c */; };
|
||||
9C88500E0FBF6702004980E4 /* l2cap.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C88500C0FBF6702004980E4 /* l2cap.c */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
@ -37,6 +38,8 @@
|
||||
9C7ECB810FCC85650085DAC5 /* bt_control.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; name = bt_control.h; path = src/bt_control.h; sourceTree = "<group>"; };
|
||||
9C7ECB820FCC85650085DAC5 /* bt_control_iphone.c */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.c; name = bt_control_iphone.c; path = src/bt_control_iphone.c; sourceTree = "<group>"; };
|
||||
9C7ECB830FCC85650085DAC5 /* bt_control_iphone.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; name = bt_control_iphone.h; path = src/bt_control_iphone.h; sourceTree = "<group>"; };
|
||||
9C7ECBB30FCC95DD0085DAC5 /* hci_dump.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = hci_dump.h; path = src/hci_dump.h; sourceTree = "<group>"; };
|
||||
9C7ECBB40FCC95DD0085DAC5 /* hci_dump.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = hci_dump.c; path = src/hci_dump.c; sourceTree = "<group>"; };
|
||||
9C88500C0FBF6702004980E4 /* l2cap.c */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.c; name = l2cap.c; path = src/l2cap.c; sourceTree = "<group>"; };
|
||||
9C88500D0FBF6702004980E4 /* l2cap.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; name = l2cap.h; path = src/l2cap.h; sourceTree = "<group>"; };
|
||||
9CA3C0900FB8B3C4005F48DE /* TODO.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = TODO.txt; sourceTree = "<group>"; };
|
||||
@ -78,6 +81,8 @@
|
||||
9C88500C0FBF6702004980E4 /* l2cap.c */,
|
||||
9C88500D0FBF6702004980E4 /* l2cap.h */,
|
||||
9C46FBAE0FA8F31800ABEF05 /* main.c */,
|
||||
9C7ECBB30FCC95DD0085DAC5 /* hci_dump.h */,
|
||||
9C7ECBB40FCC95DD0085DAC5 /* hci_dump.c */,
|
||||
);
|
||||
name = Source;
|
||||
sourceTree = "<group>";
|
||||
@ -146,6 +151,7 @@
|
||||
9C46FC3A0FA906F700ABEF05 /* hci_transport_h4.c in Sources */,
|
||||
9C88500E0FBF6702004980E4 /* l2cap.c in Sources */,
|
||||
9C7ECB840FCC85650085DAC5 /* bt_control_iphone.c in Sources */,
|
||||
9C7ECBB50FCC95DD0085DAC5 /* hci_dump.c in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
38
src/hci_dump.c
Normal file
38
src/hci_dump.c
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* hci_dump.c
|
||||
*
|
||||
* Dump HCI trace in BlueZ's hcidump format
|
||||
*
|
||||
* Created by Matthias Ringwald on 5/26/09.
|
||||
*/
|
||||
|
||||
#include "hci_dump.h"
|
||||
#include "hci.h"
|
||||
#include "hci_transport_h4.h"
|
||||
|
||||
#include <fcntl.h> // open
|
||||
#include <arpa/inet.h> // hton..
|
||||
#include <strings.h> // bzero
|
||||
#include <unistd.h> // write
|
||||
#include <stdio.h>
|
||||
|
||||
static int dump_file;
|
||||
|
||||
void hci_dump_open(char *filename){
|
||||
dump_file = open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
|
||||
}
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
void hci_dump_close(){
|
||||
close(dump_file);
|
||||
}
|
||||
|
22
src/hci_dump.h
Normal file
22
src/hci_dump.h
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* hci_dump.h
|
||||
*
|
||||
* Dump HCI trace in BlueZ's hcidump format
|
||||
*
|
||||
* Created by Matthias Ringwald on 5/26/09.
|
||||
*/
|
||||
|
||||
#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;
|
||||
|
||||
void hci_dump_open(char *filename);
|
||||
void hci_dump_packet(uint8_t packet_type, uint8_t in, uint8_t *packet, uint16_t len);
|
||||
void hci_dump_close();
|
@ -12,6 +12,9 @@
|
||||
|
||||
#include "hci.h"
|
||||
#include "hci_transport_h4.h"
|
||||
#include "hci_dump.h"
|
||||
|
||||
#define HCI_DUMP
|
||||
|
||||
typedef enum {
|
||||
H4_W4_PACKET_TYPE,
|
||||
@ -36,7 +39,6 @@ static int read_pos;
|
||||
static uint8_t hci_packet[400]; // bigger than largest packet
|
||||
|
||||
|
||||
|
||||
// prototypes
|
||||
static int h4_open(void *transport_config){
|
||||
hci_uart_config = (hci_uart_config_t*) transport_config;
|
||||
@ -102,11 +104,18 @@ static int h4_open(void *transport_config){
|
||||
bytes_to_read = 1;
|
||||
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;
|
||||
}
|
||||
|
||||
@ -116,6 +125,11 @@ 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) {
|
||||
int bytes_written = write(fd, data, size);
|
||||
@ -134,6 +148,11 @@ 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) {
|
||||
int bytes_written = write(fd, data, size);
|
||||
@ -192,6 +211,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;
|
||||
@ -204,6 +226,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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user