The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 3 | * Copyright (C) 2014 Google, Inc. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | * |
| 17 | ******************************************************************************/ |
| 18 | |
Marie Janssen | 985d4b6 | 2015-07-07 16:47:20 -0700 | [diff] [blame] | 19 | #define LOG_TAG "bt_snoop" |
| 20 | |
Etan Cohen | 3e59b5b | 2015-03-31 17:15:53 -0700 | [diff] [blame] | 21 | #include <arpa/inet.h> |
Sharvil Nanavati | a7d7eb7 | 2014-06-14 23:45:16 -0700 | [diff] [blame] | 22 | #include <assert.h> |
Matadeen Mishra | aab3e11 | 2014-11-14 19:46:19 +0530 | [diff] [blame] | 23 | #include <cutils/properties.h> |
Sharvil Nanavati | a7d7eb7 | 2014-06-14 23:45:16 -0700 | [diff] [blame] | 24 | #include <errno.h> |
| 25 | #include <fcntl.h> |
Pavlin Radoslavov | 12265e3 | 2016-02-13 08:47:19 -0800 | [diff] [blame] | 26 | #include <inttypes.h> |
Scott James Remnant | 933926c | 2015-04-02 15:22:14 -0700 | [diff] [blame] | 27 | #include <limits.h> |
| 28 | #include <netinet/in.h> |
Sharvil Nanavati | a7d7eb7 | 2014-06-14 23:45:16 -0700 | [diff] [blame] | 29 | #include <stdbool.h> |
| 30 | #include <stdio.h> |
| 31 | #include <stdlib.h> |
Etan Cohen | 3e59b5b | 2015-03-31 17:15:53 -0700 | [diff] [blame] | 32 | #include <string.h> |
Matadeen Mishra | aab3e11 | 2014-11-14 19:46:19 +0530 | [diff] [blame] | 33 | #include <time.h> |
Sharvil Nanavati | a7d7eb7 | 2014-06-14 23:45:16 -0700 | [diff] [blame] | 34 | #include <sys/stat.h> |
| 35 | #include <sys/time.h> |
Matadeen Mishra | aab3e11 | 2014-11-14 19:46:19 +0530 | [diff] [blame] | 36 | #include <sys/poll.h> |
Sharvil Nanavati | a7d7eb7 | 2014-06-14 23:45:16 -0700 | [diff] [blame] | 37 | #include <unistd.h> |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 38 | |
Marie Janssen | db55458 | 2015-06-26 14:53:46 -0700 | [diff] [blame] | 39 | #include "bt_types.h" |
Andre Eisenbach | 89f5e41 | 2014-12-05 09:40:20 -0800 | [diff] [blame] | 40 | #include "hci/include/btsnoop.h" |
| 41 | #include "hci/include/btsnoop_mem.h" |
Zach Johnson | fbbd42b | 2014-08-15 17:00:17 -0700 | [diff] [blame] | 42 | #include "hci_layer.h" |
Sharvil Nanavati | 4480276 | 2014-12-23 23:08:58 -0800 | [diff] [blame] | 43 | #include "osi/include/log.h" |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 44 | #include "stack_config.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 45 | |
Sharvil Nanavati | 611f3ab | 2014-03-22 14:27:07 -0700 | [diff] [blame] | 46 | typedef enum { |
| 47 | kCommandPacket = 1, |
| 48 | kAclPacket = 2, |
| 49 | kScoPacket = 3, |
| 50 | kEventPacket = 4 |
Sharvil Nanavati | a7d7eb7 | 2014-06-14 23:45:16 -0700 | [diff] [blame] | 51 | } packet_type_t; |
Sharvil Nanavati | 611f3ab | 2014-03-22 14:27:07 -0700 | [diff] [blame] | 52 | |
Sharvil Nanavati | a7d7eb7 | 2014-06-14 23:45:16 -0700 | [diff] [blame] | 53 | // Epoch in microseconds since 01/01/0000. |
| 54 | static const uint64_t BTSNOOP_EPOCH_DELTA = 0x00dcddb30f2f8000ULL; |
| 55 | |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 56 | static const stack_config_t *stack_config; |
Matadeen Mishra | aab3e11 | 2014-11-14 19:46:19 +0530 | [diff] [blame] | 57 | extern int client_socket_btsnoop; |
| 58 | static long int gmt_offset; |
| 59 | #define USEC_PER_SEC 1000000L |
| 60 | #define MAX_SNOOP_BUF_SIZE 1200 |
| 61 | |
| 62 | // External BT snoop |
| 63 | bool hci_ext_dump_enabled = false; |
| 64 | |
| 65 | /* snoop config from the config file, required for userdebug |
| 66 | build where snoop is enabled by default. |
| 67 | power/perf measurements need the snoop to be disabled. |
| 68 | */ |
| 69 | bool btsnoop_conf_from_file = false; |
Sharvil Nanavati | a7d7eb7 | 2014-06-14 23:45:16 -0700 | [diff] [blame] | 70 | |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 71 | static int logfile_fd = INVALID_FD; |
| 72 | static bool module_started; |
| 73 | static bool is_logging; |
| 74 | static bool logging_enabled_via_api; |
| 75 | |
| 76 | // TODO(zachoverflow): merge btsnoop and btsnoop_net together |
Sharvil Nanavati | a7d7eb7 | 2014-06-14 23:45:16 -0700 | [diff] [blame] | 77 | void btsnoop_net_open(); |
| 78 | void btsnoop_net_close(); |
Sharvil Nanavati | 611f3ab | 2014-03-22 14:27:07 -0700 | [diff] [blame] | 79 | void btsnoop_net_write(const void *data, size_t length); |
Kim Schulz | f1d68e9 | 2013-09-23 12:48:47 +0200 | [diff] [blame] | 80 | |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 81 | static void btsnoop_write_packet(packet_type_t type, const uint8_t *packet, bool is_received); |
| 82 | static void update_logging(); |
| 83 | |
| 84 | // Module lifecycle functions |
| 85 | |
| 86 | static future_t *start_up(void) { |
Matadeen Mishra | aab3e11 | 2014-11-14 19:46:19 +0530 | [diff] [blame] | 87 | time_t t = time(NULL); |
| 88 | struct tm tm_cur; |
| 89 | |
| 90 | localtime_r (&t, &tm_cur); |
| 91 | LOG_INFO(LOG_TAG, "%s Time GMT offset %ld\n", __func__, tm_cur.tm_gmtoff); |
| 92 | gmt_offset = tm_cur.tm_gmtoff; |
| 93 | |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 94 | module_started = true; |
Matadeen Mishra | aab3e11 | 2014-11-14 19:46:19 +0530 | [diff] [blame] | 95 | stack_config->get_btsnoop_ext_options(&hci_ext_dump_enabled, &btsnoop_conf_from_file); |
Gurpreet Ghai | 842fd8c | 2017-02-05 20:11:03 +0530 | [diff] [blame] | 96 | #ifdef BLUEDROID_DEBUG |
Matadeen Mishra | aab3e11 | 2014-11-14 19:46:19 +0530 | [diff] [blame] | 97 | if (btsnoop_conf_from_file == false) { |
| 98 | hci_ext_dump_enabled = true; |
| 99 | } |
Gurpreet Ghai | 842fd8c | 2017-02-05 20:11:03 +0530 | [diff] [blame] | 100 | #endif |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 101 | update_logging(); |
| 102 | |
| 103 | return NULL; |
| 104 | } |
| 105 | |
| 106 | static future_t *shut_down(void) { |
| 107 | module_started = false; |
Matadeen Mishra | aab3e11 | 2014-11-14 19:46:19 +0530 | [diff] [blame] | 108 | if (hci_ext_dump_enabled == true) { |
Gurpreet Ghai | b7998a4 | 2016-10-10 11:41:05 +0530 | [diff] [blame] | 109 | STOP_SNOOP_LOGGING(); |
Matadeen Mishra | aab3e11 | 2014-11-14 19:46:19 +0530 | [diff] [blame] | 110 | } |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 111 | update_logging(); |
| 112 | |
| 113 | return NULL; |
| 114 | } |
| 115 | |
Ian Coolidge | 1f81b64 | 2015-04-21 16:25:08 -0700 | [diff] [blame] | 116 | EXPORT_SYMBOL const module_t btsnoop_module = { |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 117 | .name = BTSNOOP_MODULE, |
| 118 | .init = NULL, |
| 119 | .start_up = start_up, |
| 120 | .shut_down = shut_down, |
| 121 | .clean_up = NULL, |
| 122 | .dependencies = { |
| 123 | STACK_CONFIG_MODULE, |
| 124 | NULL |
| 125 | } |
| 126 | }; |
| 127 | |
| 128 | // Interface functions |
| 129 | |
| 130 | static void set_api_wants_to_log(bool value) { |
| 131 | logging_enabled_via_api = value; |
| 132 | update_logging(); |
| 133 | } |
| 134 | |
| 135 | static void capture(const BT_HDR *buffer, bool is_received) { |
| 136 | const uint8_t *p = buffer->data + buffer->offset; |
| 137 | |
Andre Eisenbach | 89f5e41 | 2014-12-05 09:40:20 -0800 | [diff] [blame] | 138 | btsnoop_mem_capture(buffer); |
| 139 | |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 140 | if (logfile_fd == INVALID_FD) |
| 141 | return; |
| 142 | |
| 143 | switch (buffer->event & MSG_EVT_MASK) { |
| 144 | case MSG_HC_TO_STACK_HCI_EVT: |
| 145 | btsnoop_write_packet(kEventPacket, p, false); |
| 146 | break; |
| 147 | case MSG_HC_TO_STACK_HCI_ACL: |
| 148 | case MSG_STACK_TO_HC_HCI_ACL: |
| 149 | btsnoop_write_packet(kAclPacket, p, is_received); |
| 150 | break; |
| 151 | case MSG_HC_TO_STACK_HCI_SCO: |
| 152 | case MSG_STACK_TO_HC_HCI_SCO: |
| 153 | btsnoop_write_packet(kScoPacket, p, is_received); |
| 154 | break; |
| 155 | case MSG_STACK_TO_HC_HCI_CMD: |
| 156 | btsnoop_write_packet(kCommandPacket, p, true); |
| 157 | break; |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | static const btsnoop_t interface = { |
| 162 | set_api_wants_to_log, |
| 163 | capture |
| 164 | }; |
| 165 | |
| 166 | const btsnoop_t *btsnoop_get_interface() { |
| 167 | stack_config = stack_config_get_interface(); |
| 168 | return &interface; |
| 169 | } |
| 170 | |
| 171 | // Internal functions |
| 172 | |
Tucker Sylvestro | 1192df9 | 2015-07-06 19:29:06 -0400 | [diff] [blame] | 173 | static uint64_t btsnoop_timestamp(void) { |
| 174 | struct timeval tv; |
| 175 | gettimeofday(&tv, NULL); |
Matadeen Mishra | aab3e11 | 2014-11-14 19:46:19 +0530 | [diff] [blame] | 176 | tv.tv_sec += gmt_offset; |
Tucker Sylvestro | 1192df9 | 2015-07-06 19:29:06 -0400 | [diff] [blame] | 177 | |
| 178 | // Timestamp is in microseconds. |
zhenchao | 13e7a89 | 2016-12-01 17:43:43 +0800 | [diff] [blame] | 179 | uint64_t timestamp = ((uint64_t)tv.tv_sec) * 1000 * 1000LL; |
Tucker Sylvestro | 1192df9 | 2015-07-06 19:29:06 -0400 | [diff] [blame] | 180 | timestamp += tv.tv_usec; |
| 181 | timestamp += BTSNOOP_EPOCH_DELTA; |
| 182 | return timestamp; |
| 183 | } |
| 184 | |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 185 | static void update_logging() { |
Gurpreet Ghai | 842fd8c | 2017-02-05 20:11:03 +0530 | [diff] [blame] | 186 | bool btsnoop_log_output = stack_config->get_btsnoop_turned_on(); |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 187 | bool should_log = module_started && |
Gurpreet Ghai | 842fd8c | 2017-02-05 20:11:03 +0530 | [diff] [blame] | 188 | (logging_enabled_via_api || btsnoop_log_output || hci_ext_dump_enabled); |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 189 | |
| 190 | if (should_log == is_logging) |
| 191 | return; |
| 192 | |
| 193 | is_logging = should_log; |
| 194 | if (should_log) { |
| 195 | btsnoop_net_open(); |
Gurpreet Ghai | 842fd8c | 2017-02-05 20:11:03 +0530 | [diff] [blame] | 196 | #ifdef BLUEDROID_DEBUG |
| 197 | if(!btsnoop_log_output) |
| 198 | #endif |
| 199 | { |
| 200 | if (logging_enabled_via_api || hci_ext_dump_enabled == true) { |
| 201 | START_SNOOP_LOGGING(); |
| 202 | } |
Matadeen Mishra | aab3e11 | 2014-11-14 19:46:19 +0530 | [diff] [blame] | 203 | } |
Gurpreet Ghai | 842fd8c | 2017-02-05 20:11:03 +0530 | [diff] [blame] | 204 | |
Zach Johnson | 04bb236 | 2015-03-04 14:06:13 -0800 | [diff] [blame] | 205 | const char *log_path = stack_config->get_btsnoop_log_path(); |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 206 | |
Zach Johnson | 04bb236 | 2015-03-04 14:06:13 -0800 | [diff] [blame] | 207 | // Save the old log if configured to do so |
| 208 | if (stack_config->get_btsnoop_should_save_last()) { |
| 209 | char last_log_path[PATH_MAX]; |
Pavlin Radoslavov | 12265e3 | 2016-02-13 08:47:19 -0800 | [diff] [blame] | 210 | snprintf(last_log_path, PATH_MAX, "%s.%" PRIu64, log_path, |
| 211 | btsnoop_timestamp()); |
Zach Johnson | 04bb236 | 2015-03-04 14:06:13 -0800 | [diff] [blame] | 212 | if (!rename(log_path, last_log_path) && errno != ENOENT) |
Marie Janssen | db55458 | 2015-06-26 14:53:46 -0700 | [diff] [blame] | 213 | LOG_ERROR(LOG_TAG, "%s unable to rename '%s' to '%s': %s", __func__, log_path, last_log_path, strerror(errno)); |
Zach Johnson | 04bb236 | 2015-03-04 14:06:13 -0800 | [diff] [blame] | 214 | } |
| 215 | |
Ajay Panicker | a512475 | 2016-09-14 11:46:23 -0700 | [diff] [blame] | 216 | mode_t prevmask = umask(0); |
Zach Johnson | 04bb236 | 2015-03-04 14:06:13 -0800 | [diff] [blame] | 217 | logfile_fd = open(log_path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 218 | if (logfile_fd == INVALID_FD) { |
Marie Janssen | db55458 | 2015-06-26 14:53:46 -0700 | [diff] [blame] | 219 | LOG_ERROR(LOG_TAG, "%s unable to open '%s': %s", __func__, log_path, strerror(errno)); |
Zach Johnson | 04bb236 | 2015-03-04 14:06:13 -0800 | [diff] [blame] | 220 | is_logging = false; |
Ajay Panicker | a512475 | 2016-09-14 11:46:23 -0700 | [diff] [blame] | 221 | umask(prevmask); |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 222 | return; |
| 223 | } |
Ajay Panicker | a512475 | 2016-09-14 11:46:23 -0700 | [diff] [blame] | 224 | umask(prevmask); |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 225 | |
| 226 | write(logfile_fd, "btsnoop\0\0\0\0\1\0\0\x3\xea", 16); |
| 227 | } else { |
| 228 | if (logfile_fd != INVALID_FD) |
| 229 | close(logfile_fd); |
| 230 | |
| 231 | logfile_fd = INVALID_FD; |
| 232 | btsnoop_net_close(); |
| 233 | } |
| 234 | } |
| 235 | |
Sharvil Nanavati | 611f3ab | 2014-03-22 14:27:07 -0700 | [diff] [blame] | 236 | static void btsnoop_write(const void *data, size_t length) { |
Matadeen Mishra | aab3e11 | 2014-11-14 19:46:19 +0530 | [diff] [blame] | 237 | if (client_socket_btsnoop != -1) { |
| 238 | btsnoop_net_write(data, length); |
| 239 | /* skip writing to file if external client is connected*/ |
| 240 | return; |
| 241 | } |
| 242 | |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 243 | if (logfile_fd != INVALID_FD) |
| 244 | write(logfile_fd, data, length); |
Sharvil Nanavati | 611f3ab | 2014-03-22 14:27:07 -0700 | [diff] [blame] | 245 | } |
Kim Schulz | f1d68e9 | 2013-09-23 12:48:47 +0200 | [diff] [blame] | 246 | |
Matadeen Mishra | aab3e11 | 2014-11-14 19:46:19 +0530 | [diff] [blame] | 247 | #ifdef DEBUG_SNOOP |
| 248 | static uint64_t time_now_us() { |
| 249 | struct timespec ts_now; |
| 250 | clock_gettime(CLOCK_BOOTTIME, &ts_now); |
| 251 | return ((uint64_t)ts_now.tv_sec * USEC_PER_SEC) + ((uint64_t)ts_now.tv_nsec / 1000); |
| 252 | } |
| 253 | #endif |
| 254 | |
Sharvil Nanavati | a7d7eb7 | 2014-06-14 23:45:16 -0700 | [diff] [blame] | 255 | static void btsnoop_write_packet(packet_type_t type, const uint8_t *packet, bool is_received) { |
Chris Manton | 227f6b0 | 2014-07-18 13:41:32 -0700 | [diff] [blame] | 256 | int length_he = 0; |
Sharvil Nanavati | a7d7eb7 | 2014-06-14 23:45:16 -0700 | [diff] [blame] | 257 | int length; |
| 258 | int flags; |
| 259 | int drops = 0; |
Matadeen Mishra | aab3e11 | 2014-11-14 19:46:19 +0530 | [diff] [blame] | 260 | struct pollfd pfd; |
| 261 | #ifdef DEBUG_SNOOP |
| 262 | uint64_t ts_begin; |
| 263 | uint64_t ts_end, ts_diff; |
| 264 | #endif |
| 265 | uint8_t snoop_buf[MAX_SNOOP_BUF_SIZE] = {0}; |
| 266 | uint32_t offset = 0; |
| 267 | |
Sharvil Nanavati | a7d7eb7 | 2014-06-14 23:45:16 -0700 | [diff] [blame] | 268 | switch (type) { |
| 269 | case kCommandPacket: |
| 270 | length_he = packet[2] + 4; |
| 271 | flags = 2; |
| 272 | break; |
| 273 | case kAclPacket: |
| 274 | length_he = (packet[3] << 8) + packet[2] + 5; |
| 275 | flags = is_received; |
| 276 | break; |
| 277 | case kScoPacket: |
| 278 | length_he = packet[2] + 4; |
| 279 | flags = is_received; |
| 280 | break; |
| 281 | case kEventPacket: |
| 282 | length_he = packet[1] + 3; |
| 283 | flags = 3; |
| 284 | break; |
| 285 | } |
Sharvil Nanavati | 611f3ab | 2014-03-22 14:27:07 -0700 | [diff] [blame] | 286 | |
Sharvil Nanavati | a7d7eb7 | 2014-06-14 23:45:16 -0700 | [diff] [blame] | 287 | uint64_t timestamp = btsnoop_timestamp(); |
| 288 | uint32_t time_hi = timestamp >> 32; |
| 289 | uint32_t time_lo = timestamp & 0xFFFFFFFF; |
Kim Schulz | f1d68e9 | 2013-09-23 12:48:47 +0200 | [diff] [blame] | 290 | |
Sharvil Nanavati | a7d7eb7 | 2014-06-14 23:45:16 -0700 | [diff] [blame] | 291 | length = htonl(length_he); |
| 292 | flags = htonl(flags); |
| 293 | drops = htonl(drops); |
| 294 | time_hi = htonl(time_hi); |
| 295 | time_lo = htonl(time_lo); |
Kim Schulz | f1d68e9 | 2013-09-23 12:48:47 +0200 | [diff] [blame] | 296 | |
Matadeen Mishra | aab3e11 | 2014-11-14 19:46:19 +0530 | [diff] [blame] | 297 | /* store the length in both original and included fields */ |
| 298 | memcpy(snoop_buf + offset, &length, 4); |
| 299 | offset += 4; |
| 300 | memcpy(snoop_buf + offset, &length, 4); |
| 301 | offset += 4; |
| 302 | |
| 303 | /* flags: */ |
| 304 | memcpy(snoop_buf + offset, &flags, 4); |
| 305 | offset += 4; |
| 306 | |
| 307 | /* drops: none */ |
| 308 | memcpy(snoop_buf + offset, &drops, 4); |
| 309 | offset += 4; |
| 310 | |
| 311 | /* time */ |
| 312 | memcpy(snoop_buf + offset, &time_hi, 4); |
| 313 | offset += 4; |
| 314 | memcpy(snoop_buf + offset, &time_lo, 4); |
| 315 | offset = offset + 4; |
| 316 | |
| 317 | snoop_buf[offset] = type; |
| 318 | offset += 1; |
| 319 | if (offset + length_he + 1 > MAX_SNOOP_BUF_SIZE) { |
| 320 | LOG_ERROR(LOG_TAG, "Bad packet length, downgrading the length to %d from %d", |
| 321 | MAX_SNOOP_BUF_SIZE - offset - 1, length_he); |
| 322 | length_he = MAX_SNOOP_BUF_SIZE - offset - 1; |
| 323 | } |
| 324 | memcpy(snoop_buf + offset, packet, length_he - 1); |
| 325 | |
| 326 | if (client_socket_btsnoop != -1) { |
| 327 | pfd.fd = client_socket_btsnoop; |
| 328 | pfd.events = POLLOUT; |
| 329 | #ifdef DEBUG_SNOOP |
| 330 | ts_begin = time_now_us(); |
| 331 | #endif |
| 332 | |
| 333 | if (poll(&pfd, 1, 10) == 0) { |
| 334 | LOG_ERROR(LOG_TAG, "btsnoop poll : Taking more than 10 ms : skip dump"); |
| 335 | #ifdef DEBUG_SNOOP |
| 336 | ts_end = time_now_us(); |
| 337 | ts_diff = ts_end - ts_begin; |
| 338 | if (ts_diff > 10000) { |
| 339 | LOG_ERROR(LOG_TAG, "btsnoop poll T/O : took more time %08lld us", ts_diff); |
| 340 | } |
| 341 | #endif |
| 342 | return; |
| 343 | } |
| 344 | |
| 345 | #ifdef DEBUG_SNOOP |
| 346 | ts_end = time_now_us(); |
| 347 | ts_diff = ts_end - ts_begin; |
| 348 | if (ts_diff > 10000) { |
| 349 | LOG_ERROR(LOG_TAG, "btsnoop poll : took more time %08lld us", ts_diff); |
| 350 | } |
| 351 | #endif |
| 352 | } |
| 353 | #ifdef DEBUG_SNOOP |
| 354 | ts_begin = time_now_us(); |
| 355 | #endif |
| 356 | |
| 357 | btsnoop_write(snoop_buf, offset + length_he - 1); |
| 358 | |
| 359 | #ifdef DEBUG_SNOOP |
| 360 | ts_end = time_now_us(); |
| 361 | ts_diff = ts_end - ts_begin; |
| 362 | if (ts_diff > 10000) { |
| 363 | LOG_ERROR(LOG_TAG, "btsnoop write : Write took more time %08lld us", ts_diff); |
| 364 | } |
| 365 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 366 | } |