xref: /btstack/src/hci_dump.c (revision 7966267251b9debd0b0cb126c2187747faa073f9)
1 /*
2  *  hci_dump.c
3  *
4  *  Dump HCI trace in BlueZ's hcidump format
5  *
6  *  Created by Matthias Ringwald on 5/26/09.
7  */
8 
9 #include "hci_dump.h"
10 #include "hci.h"
11 #include "hci_transport_h4.h"
12 
13 #include <fcntl.h>        // open
14 #include <arpa/inet.h>    // hton..
15 #include <strings.h>      // bzero
16 #include <unistd.h>       // write
17 #include <stdio.h>
18 
19 static int dump_file;
20 
21 void hci_dump_open(char *filename){
22     dump_file =  open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
23 }
24 
25 void hci_dump_packet(uint8_t packet_type, uint8_t in, uint8_t *packet, uint16_t len) {
26     static hcidump_hdr header;
27     bzero( &header, sizeof(hcidump_hdr));
28     bt_store_16( (uint8_t *) &header, 0, 1 + len);
29     header.in  = in;
30     header.packet_type = packet_type;
31     write (dump_file, &header, sizeof(hcidump_hdr) );
32     write (dump_file, packet, len );
33 }
34 
35 void hci_dump_close(){
36     close(dump_file);
37 }
38 
39