Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FatFileSystem TB6612FNG2 mbed
BTstack/hci_dump.c@0:de03cbbcd0ff, 2015-11-30 (annotated)
- Committer:
- mbed_Cookbook_SE
- Date:
- Mon Nov 30 09:32:15 2015 +0000
- Revision:
- 0:de03cbbcd0ff
??
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 1 | /* |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 2 | * Copyright (C) 2009-2012 by Matthias Ringwald |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 3 | * |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 4 | * Redistribution and use in source and binary forms, with or without |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 5 | * modification, are permitted provided that the following conditions |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 6 | * are met: |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 7 | * |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 8 | * 1. Redistributions of source code must retain the above copyright |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 9 | * notice, this list of conditions and the following disclaimer. |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 11 | * notice, this list of conditions and the following disclaimer in the |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 12 | * documentation and/or other materials provided with the distribution. |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 13 | * 3. Neither the name of the copyright holders nor the names of |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 14 | * contributors may be used to endorse or promote products derived |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 15 | * from this software without specific prior written permission. |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 16 | * 4. Any redistribution, use, or modification is done solely for |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 17 | * personal benefit and not for any commercial purpose or for |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 18 | * monetary gain. |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 19 | * |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 20 | * THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD AND CONTRIBUTORS |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 24 | * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 30 | * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 31 | * SUCH DAMAGE. |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 32 | * |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 33 | * Please inquire about commercial licensing options at btstack@ringwald.ch |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 34 | * |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 35 | */ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 36 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 37 | /* |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 38 | * hci_dump.c |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 39 | * |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 40 | * Dump HCI trace in various formats: |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 41 | * |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 42 | * - BlueZ's hcidump format |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 43 | * - Apple's PacketLogger |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 44 | * - stdout hexdump |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 45 | * |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 46 | * Created by Matthias Ringwald on 5/26/09. |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 47 | */ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 48 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 49 | #include "config.h" |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 50 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 51 | #include "hci_dump.h" |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 52 | #include "hci.h" |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 53 | #include "hci_transport.h" |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 54 | #include <btstack/hci_cmds.h> |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 55 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 56 | #ifndef EMBEDDED |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 57 | #include <fcntl.h> // open |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 58 | #include <arpa/inet.h> // hton.. |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 59 | #include <unistd.h> // write |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 60 | #include <stdio.h> |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 61 | #include <time.h> |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 62 | #include <sys/time.h> // for timestamps |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 63 | #include <sys/stat.h> // for mode flags |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 64 | #include <stdarg.h> // for va_list |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 65 | #endif |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 66 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 67 | // BLUEZ hcidump |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 68 | typedef struct { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 69 | uint16_t len; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 70 | uint8_t in; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 71 | uint8_t pad; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 72 | uint32_t ts_sec; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 73 | uint32_t ts_usec; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 74 | uint8_t packet_type; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 75 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 76 | #ifdef __GNUC__ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 77 | __attribute__ ((packed)) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 78 | #endif |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 79 | hcidump_hdr; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 80 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 81 | // APPLE PacketLogger |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 82 | typedef struct { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 83 | uint32_t len; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 84 | uint32_t ts_sec; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 85 | uint32_t ts_usec; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 86 | uint8_t type; // 0xfc for note |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 87 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 88 | #ifdef __GNUC__ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 89 | __attribute__ ((packed)) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 90 | #endif |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 91 | pktlog_hdr; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 92 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 93 | #ifndef EMBEDDED |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 94 | static int dump_file = -1; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 95 | static int dump_format; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 96 | static hcidump_hdr header_bluez; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 97 | static pktlog_hdr header_packetlogger; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 98 | static char time_string[40]; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 99 | static int max_nr_packets = -1; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 100 | static int nr_packets = 0; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 101 | static char log_message_buffer[256]; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 102 | #endif |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 103 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 104 | void hci_dump_open(char *filename, hci_dump_format_t format){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 105 | #ifndef EMBEDDED |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 106 | dump_format = format; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 107 | if (dump_format == HCI_DUMP_STDOUT) { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 108 | dump_file = fileno(stdout); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 109 | } else { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 110 | dump_file = open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 111 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 112 | #endif |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 113 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 114 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 115 | #ifndef EMBEDDED |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 116 | void hci_dump_set_max_packets(int packets){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 117 | max_nr_packets = packets; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 118 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 119 | #endif |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 120 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 121 | void hci_dump_packet(uint8_t packet_type, uint8_t in, uint8_t *packet, uint16_t len) { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 122 | #ifndef EMBEDDED |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 123 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 124 | if (dump_file < 0) return; // not activated yet |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 125 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 126 | // don't grow bigger than max_nr_packets |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 127 | if (dump_format != HCI_DUMP_STDOUT && max_nr_packets > 0){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 128 | if (nr_packets >= max_nr_packets){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 129 | lseek(dump_file, 0, SEEK_SET); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 130 | ftruncate(dump_file, 0); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 131 | nr_packets = 0; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 132 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 133 | nr_packets++; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 134 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 135 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 136 | // get time |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 137 | struct timeval curr_time; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 138 | struct tm* ptm; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 139 | gettimeofday(&curr_time, NULL); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 140 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 141 | switch (dump_format){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 142 | case HCI_DUMP_STDOUT: { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 143 | /* Obtain the time of day, and convert it to a tm struct. */ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 144 | ptm = localtime (&curr_time.tv_sec); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 145 | /* Format the date and time, down to a single second. */ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 146 | strftime (time_string, sizeof (time_string), "[%Y-%m-%d %H:%M:%S", ptm); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 147 | /* Compute milliseconds from microseconds. */ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 148 | uint16_t milliseconds = curr_time.tv_usec / 1000; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 149 | /* Print the formatted time, in seconds, followed by a decimal point |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 150 | and the milliseconds. */ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 151 | printf ("%s.%03u] ", time_string, milliseconds); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 152 | switch (packet_type){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 153 | case HCI_COMMAND_DATA_PACKET: |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 154 | printf("CMD => "); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 155 | break; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 156 | case HCI_EVENT_PACKET: |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 157 | printf("EVT <= "); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 158 | break; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 159 | case HCI_ACL_DATA_PACKET: |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 160 | if (in) { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 161 | printf("ACL <= "); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 162 | } else { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 163 | printf("ACL => "); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 164 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 165 | break; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 166 | case LOG_MESSAGE_PACKET: |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 167 | // assume buffer is big enough |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 168 | packet[len] = 0; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 169 | printf("LOG -- %s\n", (char*) packet); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 170 | return; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 171 | default: |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 172 | return; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 173 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 174 | hexdump(packet, len); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 175 | break; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 176 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 177 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 178 | case HCI_DUMP_BLUEZ: |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 179 | bt_store_16( (uint8_t *) &header_bluez.len, 0, 1 + len); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 180 | header_bluez.in = in; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 181 | header_bluez.pad = 0; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 182 | bt_store_32( (uint8_t *) &header_bluez.ts_sec, 0, curr_time.tv_sec); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 183 | bt_store_32( (uint8_t *) &header_bluez.ts_usec, 0, curr_time.tv_usec); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 184 | header_bluez.packet_type = packet_type; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 185 | write (dump_file, &header_bluez, sizeof(hcidump_hdr) ); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 186 | write (dump_file, packet, len ); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 187 | break; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 188 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 189 | case HCI_DUMP_PACKETLOGGER: |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 190 | header_packetlogger.len = htonl( sizeof(pktlog_hdr) - 4 + len); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 191 | header_packetlogger.ts_sec = htonl(curr_time.tv_sec); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 192 | header_packetlogger.ts_usec = htonl(curr_time.tv_usec); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 193 | switch (packet_type){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 194 | case HCI_COMMAND_DATA_PACKET: |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 195 | header_packetlogger.type = 0x00; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 196 | break; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 197 | case HCI_ACL_DATA_PACKET: |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 198 | if (in) { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 199 | header_packetlogger.type = 0x03; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 200 | } else { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 201 | header_packetlogger.type = 0x02; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 202 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 203 | break; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 204 | case HCI_EVENT_PACKET: |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 205 | header_packetlogger.type = 0x01; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 206 | break; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 207 | case LOG_MESSAGE_PACKET: |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 208 | header_packetlogger.type = 0xfc; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 209 | break; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 210 | default: |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 211 | return; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 212 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 213 | write (dump_file, &header_packetlogger, sizeof(pktlog_hdr) ); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 214 | write (dump_file, packet, len ); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 215 | break; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 216 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 217 | default: |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 218 | break; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 219 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 220 | #endif |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 221 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 222 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 223 | void hci_dump_log(const char * format, ...){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 224 | #ifndef EMBEDDED |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 225 | va_list argptr; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 226 | va_start(argptr, format); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 227 | int len = vsnprintf(log_message_buffer, sizeof(log_message_buffer), format, argptr); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 228 | hci_dump_packet(LOG_MESSAGE_PACKET, 0, (uint8_t*) log_message_buffer, len); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 229 | va_end(argptr); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 230 | #endif |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 231 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 232 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 233 | void hci_dump_close(){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 234 | #ifndef EMBEDDED |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 235 | close(dump_file); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 236 | dump_file = -1; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 237 | #endif |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 238 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 239 |