### Bug Summary

File: | builds/wireshark/wireshark/extcap/androiddump.c
Warning: | line 2125, column 9 An undefined value may be read from 'errno'

### Annotated Source Code

Press '?' to see keyboard shortcuts

Show analyzer invocation
clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name androiddump.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -pic-is-pie -fno-delete-null-pointer-checks -mframe-pointer=all -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -ffloat16-excess-precision=fast -fbfloat16-excess-precision=fast -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/builds/wireshark/wireshark/build -fcoverage-compilation-dir=/builds/wireshark/wireshark/build -resource-dir /usr/lib/llvm-22/lib/clang/22 -isystem /usr/include/glib-2.0 -isystem /usr/lib/x86_64-linux-gnu/glib-2.0/include -D CARES_NO_DEPRECATED -D G_DISABLE_DEPRECATED -D G_DISABLE_SINGLE_INCLUDES -D WS_DEBUG -D WS_DEBUG_UTF_8 -I /builds/wireshark/wireshark/build -I /builds/wireshark/wireshark -I /builds/wireshark/wireshark/include -I /builds/wireshark/wireshark/wiretap -D _GLIBCXX_ASSERTIONS -internal-isystem /usr/lib/llvm-22/lib/clang/22/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fmacro-prefix-map=/builds/wireshark/wireshark/= -fmacro-prefix-map=/builds/wireshark/wireshark/build/= -fmacro-prefix-map=../= -Wno-format-nonliteral -std=gnu17 -ferror-limit 19 -fvisibility=hidden -fwrapv -fwrapv-pointer -fstrict-flex-arrays=3 -stack-protector 2 -fstack-clash-protection -fcf-protection=full -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fexceptions -fcolor-diagnostics -analyzer-output=html -faddrsig -fdwarf2-cfi-asm -o /builds/wireshark/wireshark/sbout/2026-08-09-100310-3660-1 -x c /builds/wireshark/wireshark/extcap/androiddump.c

Keyboard shortcuts:

- Use 'j/k' keys for keyboard navigation
- Use 'Shift+S' to show/hide relevant lines
- Use '?' to toggle this window

Close
Show only relevant lines Show control flow arrows

1 | /* androiddump.c
2 | * androiddump is extcap tool used to capture Android specific stuff
3 | *
4 | * Copyright 2015, Michal Labedzki for Tieto Corporation
5 | *
6 | * Wireshark - Network traffic analyzer
7 | * By Gerald Combs <gerald@wireshark.org>
8 | * Copyright 1998 Gerald Combs
9 | *
10 | * SPDX-License-Identifier: GPL-2.0-or-later
11 | */
12 | #include "config.h"
13 | #define WS_LOG_DOMAIN"androiddump" "androiddump"
14 |
15 | #include "extcap-base.h"
16 |
17 | #include <stdio.h>
18 | #include <stdint.h>
19 | #include <string.h>
20 | #include <errno(*__errno_location ()).h>
21 | #include <time.h>
22 | #include <fcntl.h>
23 | #include <wsutil/strtoi.h>
24 | #include <wsutil/filesystem.h>
25 | #include <wsutil/privileges.h>
26 | #include <wsutil/please_report_bug.h>
27 | #include <wsutil/wslog.h>
28 | #include <wsutil/cmdarg_err.h>
29 | #include <wsutil/inet_addr.h>
30 | #include <wsutil/exported_pdu_tlvs.h>
31 | #include <wsutil/report_message.h>
32 | #include <app/application_flavor.h>
33 |
34 | #ifdef HAVE_NETINET_IN_H1
35 | # include <netinet/in.h>
36 | #endif
37 |
38 | #ifdef HAVE_UNISTD_H1
39 | #include <unistd.h>
40 | #endif
41 |
42 | #ifdef HAVE_SYS_SOCKET_H1
43 | #include <sys/socket.h>
44 | #endif
45 |
46 | #ifdef HAVE_ARPA_INET_H1
47 | #include <arpa/inet.h>
48 | #endif
49 |
50 | #ifdef HAVE_SYS_TIME_H1
51 | #include <sys/time.h>
52 | #endif
53 |
54 | /* Configuration options */
55 | /* #define ANDROIDDUMP_USE_LIBPCAP */
56 |
57 | #define PCAP_GLOBAL_HEADER_LENGTH24 24
58 | #define PCAP_RECORD_HEADER_LENGTH16 16
59 |
60 | #ifdef ANDROIDDUMP_USE_LIBPCAP
61 | #include <pcap/pcap.h>
62 | #include <pcap/bpf.h>
63 | #include <pcap/bluetooth.h>
64 |
65 | #ifndef DLT_BLUETOOTH_H4_WITH_PHDR
66 | #define DLT_BLUETOOTH_H4_WITH_PHDR 201
67 | #endif
68 |
69 | #ifndef DLT_WIRESHARK_UPPER_PDU
70 | #define DLT_WIRESHARK_UPPER_PDU 252
71 | #endif
72 |
73 | #ifndef PCAP_TSTAMP_PRECISION_MICRO
74 | #define PCAP_TSTAMP_PRECISION_MICRO 0
75 | #endif
76 |
77 | #ifndef PCAP_TSTAMP_PRECISION_NANO
78 | #define PCAP_TSTAMP_PRECISION_NANO 1
79 | #endif
80 | #else
81 | #include "wiretap/wtap.h"
82 | #include "wiretap/pcap-encap.h"
83 | #include "ui/failure_message.h"
84 | #endif
85 |
86 | #include <cli_main.h>
87 |
88 | #ifdef ANDROIDDUMP_USE_LIBPCAP
89 | #define EXTCAP_ENCAP_BLUETOOTH_H4_WITH_PHDR99 DLT_BLUETOOTH_H4_WITH_PHDR
90 | #define EXTCAP_ENCAP_WIRESHARK_UPPER_PDU155 DLT_WIRESHARK_UPPER_PDU
91 | #define EXTCAP_ENCAP_ETHERNET1 DLT_EN10MB
92 | #define EXTCAP_ENCAP_LINUX_SLL25 DLT_LINUX_SLL
93 | #define EXTCAP_ENCAP_IEEE802_11_RADIO23 DLT_IEEE802_11_RADIO
94 | #define EXTCAP_ENCAP_NETLINK158 DLT_NETLINK
95 | #else
96 | #define EXTCAP_ENCAP_BLUETOOTH_H4_WITH_PHDR99 WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR99
97 | #define EXTCAP_ENCAP_WIRESHARK_UPPER_PDU155 WTAP_ENCAP_WIRESHARK_UPPER_PDU155
98 | #define EXTCAP_ENCAP_ETHERNET1 WTAP_ENCAP_ETHERNET1
99 | #define EXTCAP_ENCAP_LINUX_SLL25 WTAP_ENCAP_SLL25
100 | #define EXTCAP_ENCAP_IEEE802_11_RADIO23 WTAP_ENCAP_IEEE_802_11_RADIOTAP23
101 | #define EXTCAP_ENCAP_NETLINK158 WTAP_ENCAP_NETLINK158
102 | #endif
103 |
104 | #define INTERFACE_ANDROID_LOGCAT_MAIN"android-logcat-main" "android-logcat-main"
105 | #define INTERFACE_ANDROID_LOGCAT_SYSTEM"android-logcat-system" "android-logcat-system"
106 | #define INTERFACE_ANDROID_LOGCAT_RADIO"android-logcat-radio" "android-logcat-radio"
107 | #define INTERFACE_ANDROID_LOGCAT_EVENTS"android-logcat-events" "android-logcat-events"
108 | #define INTERFACE_ANDROID_LOGCAT_TEXT_MAIN"android-logcat-text-main" "android-logcat-text-main"
109 | #define INTERFACE_ANDROID_LOGCAT_TEXT_SYSTEM"android-logcat-text-system" "android-logcat-text-system"
110 | #define INTERFACE_ANDROID_LOGCAT_TEXT_RADIO"android-logcat-text-radio" "android-logcat-text-radio"
111 | #define INTERFACE_ANDROID_LOGCAT_TEXT_EVENTS"android-logcat-text-events" "android-logcat-text-events"
112 | #define INTERFACE_ANDROID_LOGCAT_TEXT_CRASH"android-logcat-text-crash" "android-logcat-text-crash"
113 | #define INTERFACE_ANDROID_BLUETOOTH_HCIDUMP"android-bluetooth-hcidump" "android-bluetooth-hcidump"
114 | #define INTERFACE_ANDROID_BLUETOOTH_EXTERNAL_PARSER"android-bluetooth-external-parser" "android-bluetooth-external-parser"
115 | #define INTERFACE_ANDROID_BLUETOOTH_BTSNOOP_NET"android-bluetooth-btsnoop-net" "android-bluetooth-btsnoop-net"
116 | #define INTERFACE_ANDROID_TCPDUMP"android-tcpdump" "android-tcpdump"
117 | #define INTERFACE_ANDROID_TCPDUMP_FORMAT"android-tcpdump" "-%s" INTERFACE_ANDROID_TCPDUMP"android-tcpdump" "-%s"
118 | #define INTERFACE_ANDROID_TCPDUMP_SERIAL_FORMAT"android-tcpdump" "-%s" "-%s" INTERFACE_ANDROID_TCPDUMP_FORMAT"android-tcpdump" "-%s" "-%s"
119 |
120 | #define ANDROIDDUMP_VERSION_MAJOR"1" "1"
121 | #define ANDROIDDUMP_VERSION_MINOR"1" "1"
122 | #define ANDROIDDUMP_VERSION_RELEASE"0" "0"
123 |
124 | #define SERIAL_NUMBER_LENGTH_MAX512 512
125 | #define MODEL_NAME_LENGTH_MAX64 64
126 |
127 | #define PACKET_LENGTH65535 65535
128 |
129 | #define SOCKET_RW_TIMEOUT_MS2000 2000
130 | #define SOCKET_CONNECT_TIMEOUT_TRIES10 10
131 | #define SOCKET_CONNECT_DELAY_US1000 1000 /* (1000us = 1ms) * SOCKET_CONNECT_TIMEOUT_TRIES (10) = 10ms worst-case */
132 |
133 | #define ADB_HEX4_FORMAT"%04zx" "%04zx"
134 | #define ADB_HEX4_LEN4 4
135 |
136 | #define BTSNOOP_HDR_LEN16 16
137 |
138 | enum exit_code {
139 | EXIT_CODE_SUCCESS = 0,
140 | EXIT_CODE_CANNOT_GET_INTERFACES_LIST = 1,
141 | EXIT_CODE_UNKNOWN_ENCAPSULATION_WIRETAP,
142 | EXIT_CODE_UNKNOWN_ENCAPSULATION_LIBPCAP,
143 | EXIT_CODE_CANNOT_SAVE_WIRETAP_DUMP,
144 | EXIT_CODE_CANNOT_SAVE_LIBPCAP_DUMP,
145 | EXIT_CODE_NO_INTERFACE_SPECIFIED,
146 | EXIT_CODE_INVALID_INTERFACE,
147 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_1,
148 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_2,
149 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_3,
150 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_4,
151 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_5,
152 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_6,
153 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_7,
154 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_8,
155 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_9,
156 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_10,
157 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_11,
158 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_12,
159 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_13,
160 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_14,
161 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_15,
162 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_16,
163 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_17,
164 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_18,
165 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_19,
166 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_20,
167 | EXIT_CODE_ERROR_WHILE_SENDING_ADB_PACKET_1,
168 | EXIT_CODE_ERROR_WHILE_SENDING_ADB_PACKET_2,
169 | EXIT_CODE_ERROR_WHILE_SENDING_ADB_PACKET_3,
170 | EXIT_CODE_ERROR_WHILE_SENDING_ADB_PACKET_4,
171 | EXIT_CODE_ERROR_WHILE_RECEIVING_ADB_PACKET_STATUS,
172 | EXIT_CODE_ERROR_WHILE_RECEIVING_ADB_PACKET_DATA,
173 | EXIT_CODE_INVALID_SOCKET_INTERFACES_LIST,
174 | EXIT_CODE_INVALID_SOCKET_1,
175 | EXIT_CODE_INVALID_SOCKET_2,
176 | EXIT_CODE_INVALID_SOCKET_3,
177 | EXIT_CODE_INVALID_SOCKET_4,
178 | EXIT_CODE_INVALID_SOCKET_5,
179 | EXIT_CODE_INVALID_SOCKET_6,
180 | EXIT_CODE_INVALID_SOCKET_7,
181 | EXIT_CODE_INVALID_SOCKET_8,
182 | EXIT_CODE_INVALID_SOCKET_9,
183 | EXIT_CODE_INVALID_SOCKET_10,
184 | EXIT_CODE_INVALID_SOCKET_11,
185 | EXIT_CODE_GENERIC = -1
186 | };
187 |
188 | enum {
189 | EXTCAP_BASE_OPTIONS_ENUMEXTCAP_OPT_LIST_INTERFACES, EXTCAP_OPT_VERSION, EXTCAP_OPT_LIST_DLTS , EXTCAP_OPT_INTERFACE, EXTCAP_OPT_CONFIG, EXTCAP_OPT_CONFIG_OPTION_NAME , EXTCAP_OPT_CONFIG_OPTION_VALUE, EXTCAP_OPT_CLEANUP_POSTKILL , EXTCAP_OPT_CAPTURE, EXTCAP_OPT_CAPTURE_FILTER, EXTCAP_OPT_FIFO , EXTCAP_OPT_LOG_LEVEL, EXTCAP_OPT_LOG_FILE,
190 | OPT_HELP,
191 | OPT_VERSION,
192 | OPT_CONFIG_ADB_SERVER_IP,
193 | OPT_CONFIG_ADB_SERVER_TCP_PORT,
194 | OPT_CONFIG_LOGCAT_TEXT,
195 | OPT_CONFIG_LOGCAT_IGNORE_LOG_BUFFER,
196 | OPT_CONFIG_LOGCAT_CUSTOM_OPTIONS,
197 | OPT_CONFIG_BT_SERVER_TCP_PORT,
198 | OPT_CONFIG_BT_FORWARD_SOCKET,
199 | OPT_CONFIG_BT_LOCAL_IP,
200 | OPT_CONFIG_BT_LOCAL_TCP_PORT
201 | };
202 |
203 | static const struct ws_option longopts[] = {
204 | EXTCAP_BASE_OPTIONS{ "extcap-interfaces", 0, ((void*)0), EXTCAP_OPT_LIST_INTERFACES }, { "extcap-version", 2, ((void*)0), EXTCAP_OPT_VERSION}, { "extcap-dlts" , 0, ((void*)0), EXTCAP_OPT_LIST_DLTS}, { "extcap-interface", 1, ((void*)0), EXTCAP_OPT_INTERFACE}, { "extcap-config", 0, ( (void*)0), EXTCAP_OPT_CONFIG}, { "extcap-config-option-name", 1, ((void*)0), EXTCAP_OPT_CONFIG_OPTION_NAME}, { "extcap-config-option-value" , 1, ((void*)0), EXTCAP_OPT_CONFIG_OPTION_VALUE }, { "extcap-cleanup-postkill" , 0, ((void*)0), EXTCAP_OPT_CLEANUP_POSTKILL }, { "capture", 0 , ((void*)0), EXTCAP_OPT_CAPTURE}, { "extcap-capture-filter", 1, ((void*)0), EXTCAP_OPT_CAPTURE_FILTER}, { "fifo", 1, ((void *)0), EXTCAP_OPT_FIFO}, { "log-level", 1, ((void*)0), EXTCAP_OPT_LOG_LEVEL }, { "log-file", 1, ((void*)0), EXTCAP_OPT_LOG_FILE},
205 | { "help", ws_no_argument0, NULL((void*)0), OPT_HELP},
206 | { "version", ws_no_argument0, NULL((void*)0), OPT_VERSION},
207 | { "adb-server-ip", ws_required_argument1, NULL((void*)0), OPT_CONFIG_ADB_SERVER_IP},
208 | { "adb-server-tcp-port", ws_required_argument1, NULL((void*)0), OPT_CONFIG_ADB_SERVER_TCP_PORT},
209 | { "logcat-text", ws_optional_argument2, NULL((void*)0), OPT_CONFIG_LOGCAT_TEXT},
210 | { "logcat-ignore-log-buffer", ws_optional_argument2, NULL((void*)0), OPT_CONFIG_LOGCAT_IGNORE_LOG_BUFFER},
211 | { "logcat-custom-options", ws_required_argument1, NULL((void*)0), OPT_CONFIG_LOGCAT_CUSTOM_OPTIONS},
212 | { "bt-server-tcp-port", ws_required_argument1, NULL((void*)0), OPT_CONFIG_BT_SERVER_TCP_PORT},
213 | { "bt-forward-socket", ws_required_argument1, NULL((void*)0), OPT_CONFIG_BT_FORWARD_SOCKET},
214 | { "bt-local-ip", ws_required_argument1, NULL((void*)0), OPT_CONFIG_BT_LOCAL_IP},
215 | { "bt-local-tcp-port", ws_required_argument1, NULL((void*)0), OPT_CONFIG_BT_LOCAL_TCP_PORT},
216 | { 0, 0, 0, 0 }
217 | };
218 |
219 | struct interface_t {
220 | const char *display_name;
221 | const char *interface_name;
222 | struct interface_t *next;
223 | };
224 |
225 | struct exported_pdu_header {
226 | uint16_t tag;
227 | uint16_t length;
228 | /* unsigned char value[0]; */
229 | };
230 |
231 |
232 | typedef struct _own_pcap_bluetooth_h4_header {
233 | uint32_t direction;
234 | } own_pcap_bluetooth_h4_header;
235 |
236 | typedef struct pcap_hdr_s {
237 | uint32_t magic_number; /* magic number */
238 | uint16_t version_major; /* major version number */
239 | uint16_t version_minor; /* minor version number */
240 | int32_t thiszone; /* GMT to local correction */
241 | uint32_t sigfigs; /* accuracy of timestamps */
242 | uint32_t snaplen; /* max length of captured packets, in octets */
243 | uint32_t network; /* data link type */
244 | } pcap_hdr_t;
245 |
246 |
247 | typedef struct pcaprec_hdr_s {
248 | uint32_t ts_sec; /* timestamp seconds */
249 | uint32_t ts_usec; /* timestamp microseconds */
250 | uint32_t incl_len; /* number of octets of packet saved in file */
251 | uint32_t orig_len; /* actual length of packet */
252 | } pcaprec_hdr_t;
253 |
254 | /* This fix compilator warning like "warning: cast from 'char *' to 'uint32_t *' (aka 'unsigned int *') increases required alignment from 1 to 4 " */
255 | typedef union {
256 | char *value_char;
257 | uint8_t *value_u8;
258 | uint16_t *value_u16;
259 | uint32_t *value_u32;
260 | uint64_t *value_u64;
261 | int8_t *value_i8;
262 | int16_t *value_i16;
263 | int32_t *value_i32;
264 | int64_t *value_i64;
265 | own_pcap_bluetooth_h4_header *value_own_pcap_bluetooth_h4_header;
266 | } data_aligned_t;
267 |
268 | #define SET_DATA(dest, type, src){ data_aligned_t data_aligned; data_aligned.value_char = src; dest = data_aligned.type; } \
269 | { \
270 | data_aligned_t data_aligned; \
271 | \
272 | data_aligned.value_char = src; \
273 | dest = data_aligned.type; \
274 | }
275 |
276 | struct extcap_dumper {
277 | int encap;
278 | union {
279 | #ifdef ANDROIDDUMP_USE_LIBPCAP
280 | pcap_dumper_t *pcap;
281 | #else
282 | wtap_dumper *wtap;
283 | #endif
284 | } dumper;
285 | };
286 |
287 | /* Globals */
288 | static int endless_loop = 1;
289 |
290 | /* Functions */
291 | static inline int is_specified_interface(const char *interface, const char *interface_prefix) {
292 | return !strncmp(interface, interface_prefix, strlen(interface_prefix));
293 | }
294 |
295 | static bool_Bool is_logcat_interface(const char *interface) {
296 | return is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_MAIN"android-logcat-main") ||
297 | is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_SYSTEM"android-logcat-system") ||
298 | is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_RADIO"android-logcat-radio") ||
299 | is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_EVENTS"android-logcat-events");
300 | }
301 |
302 | static bool_Bool is_logcat_text_interface(const char *interface) {
303 | return is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_TEXT_MAIN"android-logcat-text-main") ||
304 | is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_TEXT_SYSTEM"android-logcat-text-system") ||
305 | is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_TEXT_RADIO"android-logcat-text-radio") ||
306 | is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_TEXT_EVENTS"android-logcat-text-events") ||
307 | is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_TEXT_CRASH"android-logcat-text-crash");
308 | }
309 |
310 | static char* get_serial_from_interface(char *interface)
311 | {
312 | static const char* const iface_prefix[] = {
313 | INTERFACE_ANDROID_LOGCAT_MAIN"android-logcat-main",
314 | INTERFACE_ANDROID_LOGCAT_SYSTEM"android-logcat-system",
315 | INTERFACE_ANDROID_LOGCAT_RADIO"android-logcat-radio",
316 | INTERFACE_ANDROID_LOGCAT_EVENTS"android-logcat-events",
317 | INTERFACE_ANDROID_LOGCAT_TEXT_MAIN"android-logcat-text-main",
318 | INTERFACE_ANDROID_LOGCAT_TEXT_SYSTEM"android-logcat-text-system",
319 | INTERFACE_ANDROID_LOGCAT_TEXT_RADIO"android-logcat-text-radio",
320 | INTERFACE_ANDROID_LOGCAT_TEXT_EVENTS"android-logcat-text-events",
321 | INTERFACE_ANDROID_LOGCAT_TEXT_CRASH"android-logcat-text-crash",
322 | INTERFACE_ANDROID_BLUETOOTH_HCIDUMP"android-bluetooth-hcidump",
323 | INTERFACE_ANDROID_BLUETOOTH_EXTERNAL_PARSER"android-bluetooth-external-parser",
324 | INTERFACE_ANDROID_BLUETOOTH_BTSNOOP_NET"android-bluetooth-btsnoop-net",
325 | NULL((void*)0)
326 | };
327 | int i;
328 | const char* curr = NULL((void*)0);
329 | for (i = 0; (curr = iface_prefix[i]); i++) {
330 | if (is_specified_interface(interface, curr) &&
331 | strlen(interface) > strlen(curr) + 1) {
332 | return interface + strlen(curr) + 1;
333 | }
334 | }
335 | return NULL((void*)0);
336 | }
337 |
338 | static const char* interface_to_logbuf(char* interface)
339 | {
340 | const char *const adb_log_main = "log:main";
341 | const char *const adb_log_system = "log:system";
342 | const char *const adb_log_radio = "log:radio";
343 | const char *const adb_log_events = "log:events";
344 | const char *logbuf = NULL((void*)0);
345 |
346 | if (is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_MAIN"android-logcat-main"))
347 | logbuf = adb_log_main;
348 | else if (is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_SYSTEM"android-logcat-system"))
349 | logbuf = adb_log_system;
350 | else if (is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_RADIO"android-logcat-radio"))
351 | logbuf = adb_log_radio;
352 | else if (is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_EVENTS"android-logcat-events"))
353 | logbuf = adb_log_events;
354 | return logbuf;
355 | }
356 |
357 | /* "Error codes set by Windows Sockets are not made available through the errno
358 | * variable."
359 | * https://learn.microsoft.com/en-us/windows/win32/winsock/error-codes-errno-h-errno-and-wsagetlasterror-2
360 | */
361 | #ifdef _WIN32
362 | #define CONTINUE_ON_TIMEOUT(length)if ((*__errno_location ()) == 11) continue; \
363 | if (length == SOCKET_ERROR(-1)) { \
364 | int last_err = WSAGetLastError(); \
365 | if (last_err == WSAETIMEDOUT || last_err == WSAEWOULDBLOCK) \
366 | continue; \
367 | }
368 | #elif EWOULDBLOCK11 != EAGAIN11
369 | #define CONTINUE_ON_TIMEOUT(length)if ((*__errno_location ()) == 11) continue; \
370 | if (errno(*__errno_location ()) == EAGAIN11 || errno(*__errno_location ()) == EWOULDBLOCK11) \
371 | continue;
372 | #else
373 | #define CONTINUE_ON_TIMEOUT(length)if ((*__errno_location ()) == 11) continue; \
374 | if (errno(*__errno_location ()) == EAGAIN11) \
375 | continue;
376 | #endif /* _WIN32 */
377 |
378 | static void useSndTimeout(socket_handle_tint sock) {
379 | int res;
380 | #ifdef _WIN32
381 | const DWORD socket_timeout = SOCKET_RW_TIMEOUT_MS2000;
382 |
383 | res = setsockopt(sock, SOL_SOCKET1, SO_SNDTIMEO21, (const char *) &socket_timeout, (socklen_t)sizeof(socket_timeout));
384 | #else
385 | const struct timeval socket_timeout = {
386 | .tv_sec = SOCKET_RW_TIMEOUT_MS2000 / 1000,
387 | .tv_usec = (SOCKET_RW_TIMEOUT_MS2000 % 1000) * 1000
388 | };
389 |
390 | res = setsockopt(sock, SOL_SOCKET1, SO_SNDTIMEO21, &socket_timeout, (socklen_t)sizeof(socket_timeout));
391 | #endif
392 | if (res != 0)
393 | ws_debug("Can't set socket timeout, using default")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 393, __func__, "Can't set socket timeout, using default"); } } while (0);
394 | }
395 |
396 | static void useNonBlockingConnectTimeout(socket_handle_tint sock) {
397 | #ifdef _WIN32
398 | int res_snd;
399 | int res_rcv;
400 | const DWORD socket_timeout = SOCKET_RW_TIMEOUT_MS2000;
401 | unsigned long non_blocking = 1;
402 |
403 | /* set timeout when non-blocking to 2s on Windows */
404 | res_snd = setsockopt(sock, SOL_SOCKET1, SO_SNDTIMEO21, (const char*)&socket_timeout, sizeof(socket_timeout));
405 | res_rcv = setsockopt(sock, SOL_SOCKET1, SO_RCVTIMEO20, (const char*)&socket_timeout, sizeof(socket_timeout));
406 | /* set socket to non-blocking */
407 | ioctlsocket(sock, FIONBIO, &non_blocking);
408 | if (res_snd != 0)
409 | ws_debug("Can't set socket timeout, using default")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 409, __func__, "Can't set socket timeout, using default"); } } while (0);
410 | if (res_rcv != 0)
411 | ws_debug("Can't set socket timeout, using default")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 411, __func__, "Can't set socket timeout, using default"); } } while (0);
412 | #else
413 | int flags = fcntl(sock, F_GETFL3);
414 | if (-1 == fcntl(sock, F_SETFL4, flags | O_NONBLOCK04000)) {
415 | ws_info("Failure setting socket to non-blocking: %s", g_strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_INFO, ((void *)0), -1, ((void*)0), "Failure setting socket to non-blocking: %s" , g_strerror((*__errno_location ()))); } } while (0);
416 | }
417 | #endif
418 | }
419 |
420 | static void useNormalConnectTimeout(socket_handle_tint sock) {
421 | int res_snd;
422 | int res_rcv;
423 | #ifdef _WIN32
424 | const DWORD socket_timeout = SOCKET_RW_TIMEOUT_MS2000;
425 | unsigned long non_blocking = 0;
426 |
427 | res_snd = setsockopt(sock, SOL_SOCKET1, SO_SNDTIMEO21, (const char *) &socket_timeout, sizeof(socket_timeout));
428 | res_rcv = setsockopt(sock, SOL_SOCKET1, SO_RCVTIMEO20, (const char *) &socket_timeout, sizeof(socket_timeout));
429 | ioctlsocket(sock, FIONBIO, &non_blocking);
430 | #else
431 | int flags = fcntl(sock, F_GETFL3);
432 | if (-1 == fcntl(sock, F_SETFL4, flags & ~O_NONBLOCK04000)) {
433 | ws_info("Failure setting socket to blocking: %s", g_strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_INFO, ((void *)0), -1, ((void*)0), "Failure setting socket to blocking: %s" , g_strerror((*__errno_location ()))); } } while (0);
434 | }
435 | const struct timeval socket_timeout = {
436 | .tv_sec = SOCKET_RW_TIMEOUT_MS2000 / 1000,
437 | .tv_usec = (SOCKET_RW_TIMEOUT_MS2000 % 1000) * 1000
438 | };
439 |
440 | res_snd = setsockopt(sock, SOL_SOCKET1, SO_SNDTIMEO21, &socket_timeout, sizeof(socket_timeout));
441 | res_rcv = setsockopt(sock, SOL_SOCKET1, SO_RCVTIMEO20, &socket_timeout, sizeof(socket_timeout));
442 | #endif
443 | if (res_snd != 0)
444 | ws_debug("Can't set socket timeout, using default")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 444, __func__, "Can't set socket timeout, using default"); } } while (0);
445 | if (res_rcv != 0)
446 | ws_debug("Can't set socket timeout, using default")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 446, __func__, "Can't set socket timeout, using default"); } } while (0);
447 | }
448 |
449 | static struct extcap_dumper extcap_dumper_open(char *fifo, int encap) {
450 | struct extcap_dumper extcap_dumper;
451 |
452 | #ifdef ANDROIDDUMP_USE_LIBPCAP
453 | pcap_t *pcap;
454 |
455 | pcap = pcap_open_dead_with_tstamp_precision(encap, PACKET_LENGTH65535, PCAP_TSTAMP_PRECISION_NANO);
456 | extcap_dumper.dumper.pcap = pcap_dump_open(pcap, fifo);
457 | if (!extcap_dumper.dumper.pcap) {
458 | ws_warning("Can't open %s for saving packets: %s", fifo, pcap_geterr(pcap))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 458, __func__, "Can't open %s for saving packets: %s", fifo , pcap_geterr(pcap)); } } while (0);
459 | pcap_close(pcap);
460 | exit(EXIT_CODE_CANNOT_SAVE_LIBPCAP_DUMP);
461 | }
462 | extcap_dumper.encap = encap;
463 | if (pcap_dump_flush(extcap_dumper.dumper.pcap) == -1) {
464 | ws_warning("Write to %s failed: %s", fifo, g_strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 464, __func__, "Write to %s failed: %s", fifo, g_strerror(( *__errno_location ()))); } } while (0);
465 | }
466 | #else
467 | wtap_dump_params params = WTAP_DUMP_PARAMS_INIT{.snaplen=0};
468 | int file_type_subtype;
469 | int err = 0;
470 | char *err_info = NULL((void*)0);
471 | const struct file_extension_info* file_extensions;
472 | unsigned num_extensions;
473 |
474 | application_file_extensions(&file_extensions, &num_extensions);
475 | wtap_init(false0, application_configuration_environment_prefix(), file_extensions, num_extensions);
476 |
477 | params.encap = encap;
478 | params.snaplen = PACKET_LENGTH65535;
479 | file_type_subtype = wtap_pcap_nsec_file_type_subtype();
480 | extcap_dumper.dumper.wtap = wtap_dump_open(fifo, file_type_subtype, WS_FILE_UNCOMPRESSED, &params, &err, &err_info);
481 | if (!extcap_dumper.dumper.wtap) {
482 | report_cfile_dump_open_failure(fifo, err, err_info, file_type_subtype);
483 | exit(EXIT_CODE_CANNOT_SAVE_WIRETAP_DUMP);
484 | }
485 | extcap_dumper.encap = encap;
486 | if (!wtap_dump_flush(extcap_dumper.dumper.wtap, &err)) {
487 | report_cfile_dump_open_failure(fifo, err, NULL((void*)0), file_type_subtype);
488 | exit(EXIT_CODE_CANNOT_SAVE_WIRETAP_DUMP);
489 | }
490 | #endif
491 |
492 | return extcap_dumper;
493 | }
494 |
495 | static bool_Bool extcap_dumper_dump(struct extcap_dumper extcap_dumper,
496 | char *fifo, char *buffer,
497 | ssize_t captured_length, ssize_t reported_length,
498 | time_t seconds, int nanoseconds) {
499 | #ifdef ANDROIDDUMP_USE_LIBPCAP
500 | struct pcap_pkthdr pcap_header;
501 |
502 | pcap_header.caplen = (bpf_u_int32) captured_length;
503 | pcap_header.len = (bpf_u_int32) reported_length;
504 | pcap_header.ts.tv_sec = seconds;
505 | pcap_header.ts.tv_usec = nanoseconds / 1000;
506 |
507 | pcap_dump((u_char *) extcap_dumper.dumper.pcap, &pcap_header, (uint8_t*)buffer);
508 | if (pcap_dump_flush(extcap_dumper.dumper.pcap) == -1) {
509 | ws_warning("Write to %s failed: %s", fifo, g_strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 509, __func__, "Write to %s failed: %s", fifo, g_strerror(( *__errno_location ()))); } } while (0);
510 | }
511 | #else
512 | int err = 0;
513 | char *err_info;
514 | wtap_rec rec;
515 |
516 | wtap_rec_init(&rec, captured_length);
517 | wtap_setup_packet_rec(&rec, extcap_dumper.encap);
518 |
519 | rec.presence_flags = WTAP_HAS_TS0x00000001;
520 | rec.ts.secs = seconds;
521 | rec.ts.nsecs = (int) nanoseconds;
522 |
523 | /* NOTE: Try to handle pseudoheaders manually */
524 | if (extcap_dumper.encap == EXTCAP_ENCAP_BLUETOOTH_H4_WITH_PHDR99) {
525 | uint32_t *direction;
526 |
527 | SET_DATA(direction, value_u32, buffer){ data_aligned_t data_aligned; data_aligned.value_char = buffer ; direction = data_aligned.value_u32; }
528 |
529 | rec.rec_header.packet_header.pseudo_header.bthci.sent = GINT32_FROM_BE(*direction)(((gint32) (((guint32) ( (((guint32) (*direction) & (guint32 ) 0x000000ffU) << 24) | (((guint32) (*direction) & ( guint32) 0x0000ff00U) << 8) | (((guint32) (*direction) & (guint32) 0x00ff0000U) >> 8) | (((guint32) (*direction ) & (guint32) 0xff000000U) >> 24)))))) ? 0 : 1;
530 |
531 | buffer += sizeof(own_pcap_bluetooth_h4_header);
532 | captured_length -= sizeof(own_pcap_bluetooth_h4_header);
533 | }
534 |
535 | rec.rec_header.packet_header.caplen = (uint32_t) captured_length;
536 | rec.rec_header.packet_header.len = (uint32_t) reported_length;
537 |
538 | ws_buffer_append(&rec.data, (const uint8_t*)buffer, captured_length);
539 |
540 | if (!wtap_dump(extcap_dumper.dumper.wtap, &rec, &err, &err_info)) {
541 | report_cfile_write_failure(NULL((void*)0), fifo, err, err_info, 0,
542 | wtap_dump_file_type_subtype(extcap_dumper.dumper.wtap));
543 | wtap_rec_cleanup(&rec);
544 | return false0;
545 | }
546 |
547 | if (!wtap_dump_flush(extcap_dumper.dumper.wtap, &err)) {
548 | report_cfile_write_failure(NULL((void*)0), fifo, err, NULL((void*)0), 0,
549 | wtap_dump_file_type_subtype(extcap_dumper.dumper.wtap));
550 | wtap_rec_cleanup(&rec);
551 | return false0;
552 | }
553 |
554 | wtap_rec_cleanup(&rec);
555 | #endif
556 |
557 | return true1;
558 | }
559 |
560 |
561 | static socket_handle_tint adb_connect(const char *server_ip, unsigned short *server_tcp_port) {
562 | socket_handle_tint sock;
563 | socklen_t length;
564 | struct sockaddr_in server;
565 | struct sockaddr_in client;
566 | int status;
567 | #ifndef _WIN32
568 | int result;
569 | #endif
570 | int tries = 0;
571 |
572 | memset(&server, 0x0, sizeof(server));
573 |
574 | server.sin_family = AF_INET2;
575 | server.sin_port = GINT16_TO_BE(*server_tcp_port)((gint16) (((guint16) ( (guint16) ((guint16) (*server_tcp_port ) >> 8) | (guint16) ((guint16) (*server_tcp_port) << 8)))));
576 | ws_inet_pton4(server_ip, (ws_in4_addr *)&(server.sin_addr.s_addr));
577 |
578 | if ((sock = socket(AF_INET2, SOCK_STREAMSOCK_STREAM, IPPROTO_TCPIPPROTO_TCP)) == INVALID_SOCKET(-1)) {
579 | ws_warning("Cannot open system TCP socket: %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 579, __func__, "Cannot open system TCP socket: %s", strerror ((*__errno_location ()))); } } while (0);
580 | return INVALID_SOCKET(-1);
581 | }
582 |
583 | useNonBlockingConnectTimeout(sock);
584 | status = connect(sock, (struct sockaddr *) &server, (socklen_t)sizeof(server));
585 | #ifdef _WIN32
586 | if ((status == SOCKET_ERROR(-1)) && (WSAGetLastError() == WSAEWOULDBLOCK)) {
587 | #else
588 | if ((status == SOCKET_ERROR(-1)) && (errno(*__errno_location ()) == EINPROGRESS115)) {
589 | #endif
590 | while (tries < SOCKET_CONNECT_TIMEOUT_TRIES10) {
591 | tries += 1;
592 | struct timeval timeout = {
593 | .tv_sec = 0,
594 | .tv_usec = SOCKET_CONNECT_DELAY_US1000,
595 | };
596 | fd_set fdset;
597 | FD_ZERO(&fdset)do { unsigned int __i; fd_set *__arr = (&fdset); for (__i = 0; __i < sizeof (fd_set) / sizeof (__fd_mask); ++__i) ( (__arr)->__fds_bits)[__i] = 0; } while (0);
598 | FD_SET(sock, &fdset)((void) (((&fdset)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * ( int) sizeof (__fd_mask)))))));
599 | #ifdef _WIN32
600 | if ((select(0, NULL((void*)0), &fdset, NULL((void*)0), &timeout) != 0) && (FD_ISSET(sock, &fdset)((((&fdset)->__fds_bits)[((sock) / (8 * (int) sizeof ( __fd_mask)))] & ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))) != 0))) {
601 | status = 0;
602 | break;
603 | #else
604 | if ((select(sock+1, NULL((void*)0), &fdset, NULL((void*)0), &timeout) != 0) && (FD_ISSET(sock, &fdset)((((&fdset)->__fds_bits)[((sock) / (8 * (int) sizeof ( __fd_mask)))] & ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))) != 0))) {
605 | length = sizeof(result);
606 | getsockopt(sock, SOL_SOCKET1, SO_ERROR4, &result, &length);
607 | if (result == 0) {
608 | status = 0;
609 | } else {
610 | ws_debug("Error connecting to ADB: <%s>", strerror(result))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 610, __func__, "Error connecting to ADB: <%s>", strerror (result)); } } while (0);
611 | }
612 | break;
613 | #endif
614 | } else {
615 | ws_debug("Try %i: Timeout connecting to ADB", tries)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 615, __func__, "Try %i: Timeout connecting to ADB", tries); } } while (0);
616 | }
617 | }
618 | }
619 | useNormalConnectTimeout(sock);
620 |
621 | if (status == SOCKET_ERROR(-1)) {
622 | #if 0
623 | /* NOTE: This does not work well - make significant delay while initializing Wireshark.
624 | Do fork() then call "adb" also does not make sense, because there is need to
625 | do something like sleep(1) to ensure adb is started... system() cannot be used
626 | on Windows, because open console window. This helper does not work as expected,
627 | so disable it and user must ensure that adb is started (adb start-server,
628 | but also all other command start-server automatically)
629 | */
630 | #ifdef _WIN32
631 | if (_execlp("adb", "adb", "start-server", NULL((void*)0))) {
632 | #else
633 | if (execlp("adb", "adb", "start-server", NULL((void*)0))) {
634 | #endif
635 | errmsg("WARNING: Cannot execute system command to start adb: %s", strerror(errno(*__errno_location ())));
636 | closesocket(sock)close(sock);
637 | return INVALID_SOCKET(-1);
638 | };
639 |
640 | if (connect(sock, (struct sockaddr *) &server, (socklen_t)sizeof(server)) == SOCKET_ERROR(-1)) {
641 | ws_warning("Cannot connect to ADB: <%s> Please check that adb daemon is running.", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 641, __func__, "Cannot connect to ADB: <%s> Please check that adb daemon is running." , strerror((*__errno_location ()))); } } while (0);
642 | closesocket(sock)close(sock);
643 | return INVALID_SOCKET(-1);
644 | }
645 | #else
646 | ws_debug("Cannot connect to ADB: Please check that adb daemon is running.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 646, __func__, "Cannot connect to ADB: Please check that adb daemon is running." ); } } while (0);
647 | closesocket(sock)close(sock);
648 | return INVALID_SOCKET(-1);
649 | #endif
650 | }
651 |
652 | length = sizeof(client);
653 | if (getsockname(sock, (struct sockaddr *) &client, &length)) {
654 | ws_warning("getsockname: %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 654, __func__, "getsockname: %s", strerror((*__errno_location ()))); } } while (0);
655 | closesocket(sock)close(sock);
656 | return INVALID_SOCKET(-1);
657 | }
658 |
659 | if (length != sizeof(client)) {
660 | ws_warning("incorrect length")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 660, __func__, "incorrect length"); } } while (0);
661 | closesocket(sock)close(sock);
662 | return INVALID_SOCKET(-1);
663 | }
664 |
665 | ws_debug("Client port %u", GUINT16_FROM_BE(client.sin_port))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 665, __func__, "Client port %u", (((((guint16) ( (guint16) ( (guint16) (client.sin_port) >> 8) | (guint16) ((guint16 ) (client.sin_port) << 8))))))); } } while (0);
666 |
667 | return sock;
668 | }
669 |
670 |
671 | static char *adb_send_and_receive(socket_handle_tint sock, const char *adb_service,
672 | char *buffer, size_t buffer_length, size_t *data_length) {
673 | size_t used_buffer_length;
674 | size_t bytes_to_read;
675 | uint32_t length;
676 | ssize_t result;
677 | char status[4];
678 | char tmp_buffer;
679 | size_t adb_service_length;
680 |
681 | adb_service_length = strlen(adb_service);
682 | if (adb_service_length > INT_MAX2147483647) {
683 | ws_warning("Service name too long when sending <%s> to ADB daemon", adb_service)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 683, __func__, "Service name too long when sending <%s> to ADB daemon" , adb_service); } } while (0);
684 | if (data_length)
685 | *data_length = 0;
686 | return NULL((void*)0);
687 | }
688 |
689 | /* 8 bytes of hex length + terminating NUL */
690 | if (buffer_length < 9) {
691 | ws_warning("Buffer for response too short while sending <%s> to ADB daemon", adb_service)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 691, __func__, "Buffer for response too short while sending <%s> to ADB daemon" , adb_service); } } while (0);
692 | if (data_length)
693 | *data_length = 0;
694 | return NULL((void*)0);
695 | }
696 |
697 | snprintf(buffer, buffer_length, ADB_HEX4_FORMAT"%04zx", adb_service_length);
698 | result = send(sock, buffer, ADB_HEX4_LEN4, 0);
699 | if (result < ADB_HEX4_LEN4) {
700 | ws_warning("Error while sending <%s> length to ADB daemon", adb_service)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 700, __func__, "Error while sending <%s> length to ADB daemon" , adb_service); } } while (0);
701 | return NULL((void*)0);
702 | }
703 |
704 | result = send(sock, adb_service, (int) adb_service_length, 0);
705 | if (result != (ssize_t) adb_service_length) {
706 | ws_warning("Error while sending <%s> to ADB daemon", adb_service)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 706, __func__, "Error while sending <%s> to ADB daemon" , adb_service); } } while (0);
707 | if (data_length)
708 | *data_length = 0;
709 | return NULL((void*)0);
710 | }
711 |
712 | used_buffer_length = 0;
713 | while (used_buffer_length < 8) {
714 | bytes_to_read = buffer_length - used_buffer_length;
715 | if (bytes_to_read > INT_MAX2147483647)
716 | bytes_to_read = INT_MAX2147483647;
717 | result = recv(sock, buffer + used_buffer_length, (int)bytes_to_read, 0);
718 |
719 | if (result <= 0) {
720 | ws_warning("Broken socket connection while fetching reply status for <%s>", adb_service)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 720, __func__, "Broken socket connection while fetching reply status for <%s>" , adb_service); } } while (0);
721 | if (data_length)
722 | *data_length = 0;
723 | return NULL((void*)0);
724 | }
725 |
726 | used_buffer_length += result;
727 | }
728 |
729 | memcpy(status, buffer, 4);
730 | tmp_buffer = buffer[8];
731 | buffer[8] = '\0';
732 | if (!ws_hexstrtou32(buffer + 4, NULL((void*)0), &length)) {
733 | ws_warning("Invalid reply length <%s> while reading reply for <%s>", buffer + 4, adb_service)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 733, __func__, "Invalid reply length <%s> while reading reply for <%s>" , buffer + 4, adb_service); } } while (0);
734 | if (data_length)
735 | *data_length = 0;
736 | return NULL((void*)0);
737 | }
738 | buffer[8] = tmp_buffer;
739 |
740 | if (buffer_length < length + 8) {
741 | ws_warning("Buffer for response too short while sending <%s> to ADB daemon", adb_service)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 741, __func__, "Buffer for response too short while sending <%s> to ADB daemon" , adb_service); } } while (0);
742 | if (data_length)
743 | *data_length = 0;
744 | return NULL((void*)0);
745 | }
746 |
747 | while (used_buffer_length < length + 8) {
748 | bytes_to_read = buffer_length - used_buffer_length;
749 | if (bytes_to_read > INT_MAX2147483647)
750 | bytes_to_read = INT_MAX2147483647;
751 | result = recv(sock, buffer + used_buffer_length, (int)bytes_to_read, 0);
752 |
753 | if (result <= 0) {
754 | ws_warning("Broken socket connection while reading reply for <%s>", adb_service)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 754, __func__, "Broken socket connection while reading reply for <%s>" , adb_service); } } while (0);
755 | if (data_length)
756 | *data_length = 0;
757 | return NULL((void*)0);
758 | }
759 |
760 | used_buffer_length += result;
761 | }
762 |
763 | if (data_length)
764 | *data_length = used_buffer_length - 8;
765 |
766 | if (memcmp(status, "OKAY", 4)) {
767 | ws_warning("Error while receiving by ADB for <%s>", adb_service)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 767, __func__, "Error while receiving by ADB for <%s>" , adb_service); } } while (0);
768 | if (data_length)
769 | *data_length = 0;
770 | return NULL((void*)0);
771 | }
772 |
773 | return buffer + 8;
774 | }
775 |
776 |
777 | static char *adb_send_and_read(socket_handle_tint sock, const char *adb_service, char *buffer,
778 | int buffer_length, ssize_t *data_length) {
779 | ssize_t used_buffer_length;
780 | ssize_t result;
781 | char status[4];
782 | size_t adb_service_length;
783 |
784 | adb_service_length = strlen(adb_service);
785 | snprintf(buffer, buffer_length, ADB_HEX4_FORMAT"%04zx", adb_service_length);
786 |
787 | result = send(sock, buffer, ADB_HEX4_LEN4, 0);
788 | if (result < ADB_HEX4_LEN4) {
789 | ws_warning("Error while sending <%s> to ADB daemon", adb_service)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 789, __func__, "Error while sending <%s> to ADB daemon" , adb_service); } } while (0);
790 | return NULL((void*)0);
791 | }
792 |
793 | result = send(sock, adb_service, (int) adb_service_length, 0);
794 | if (result != (ssize_t) adb_service_length) {
795 | ws_warning("Error while sending <%s> to ADB", adb_service)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 795, __func__, "Error while sending <%s> to ADB", adb_service ); } } while (0);
796 | if (data_length)
797 | *data_length = 0;
798 | return NULL((void*)0);
799 | }
800 |
801 | used_buffer_length = 0;
802 | while (used_buffer_length < 4) {
803 | result = recv(sock, buffer + used_buffer_length, (int)(buffer_length - used_buffer_length), 0);
804 |
805 | if (result <= 0) {
806 | ws_warning("Broken socket connection while fetching reply status for <%s>", adb_service)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 806, __func__, "Broken socket connection while fetching reply status for <%s>" , adb_service); } } while (0);
807 |
808 | return NULL((void*)0);
809 | }
810 |
811 | used_buffer_length += result;
812 | }
813 |
814 | memcpy(status, buffer, 4);
815 |
816 | while (result > 0) {
817 | result= recv(sock, buffer + used_buffer_length, (int)(buffer_length - used_buffer_length), 0);
818 |
819 | if (result < 0) {
820 | ws_warning("Broken socket connection while reading reply for <%s>", adb_service)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 820, __func__, "Broken socket connection while reading reply for <%s>" , adb_service); } } while (0);
821 |
822 | return NULL((void*)0);
823 | } else if (result == 0) {
824 | break;
825 | }
826 |
827 | used_buffer_length += result;
828 | }
829 |
830 | if (data_length)
831 | *data_length = used_buffer_length - 4;
832 |
833 | if (memcmp(status, "OKAY", 4)) {
834 | ws_warning("Error while receiving by ADB for <%s>", adb_service)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 834, __func__, "Error while receiving by ADB for <%s>" , adb_service); } } while (0);
835 | if (data_length)
836 | *data_length = 0;
837 | return NULL((void*)0);
838 | }
839 |
840 | return buffer + 4;
841 | }
842 |
843 |
844 | static int adb_send(socket_handle_tint sock, const char *adb_service) {
845 | char buffer[5];
846 | int used_buffer_length;
847 | ssize_t result;
848 | size_t adb_service_length;
849 |
850 | adb_service_length = strlen(adb_service);
851 | result = snprintf(buffer, sizeof(buffer), ADB_HEX4_FORMAT"%04zx", adb_service_length);
852 | if ((size_t)result >= sizeof(buffer)) {
853 | /* Truncation (or failure somehow) */
854 | ws_warning("Service name too long when sending <%s> to ADB daemon", adb_service)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 854, __func__, "Service name too long when sending <%s> to ADB daemon" , adb_service); } } while (0);
855 | return EXIT_CODE_ERROR_WHILE_SENDING_ADB_PACKET_1;
856 | }
857 |
858 | result = send(sock, buffer, ADB_HEX4_LEN4, 0);
859 | if (result < ADB_HEX4_LEN4) {
860 | ws_warning("Error while sending <%s> to ADB daemon", adb_service)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 860, __func__, "Error while sending <%s> to ADB daemon" , adb_service); } } while (0);
861 | return EXIT_CODE_ERROR_WHILE_SENDING_ADB_PACKET_1;
862 | }
863 |
864 | result = send(sock, adb_service, (int) adb_service_length, 0);
865 | if (result != (ssize_t) adb_service_length) {
866 | ws_warning("Error while sending <%s> to ADB", adb_service)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 866, __func__, "Error while sending <%s> to ADB", adb_service ); } } while (0);
867 | return EXIT_CODE_ERROR_WHILE_SENDING_ADB_PACKET_1;
868 | }
869 |
870 | used_buffer_length = 0;
871 | while (used_buffer_length < 4) {
872 | result = recv(sock, buffer + used_buffer_length, 4 - used_buffer_length, 0);
873 |
874 | if (result <= 0) {
875 | ws_warning("Broken socket connection while fetching reply status for <%s>", adb_service)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 875, __func__, "Broken socket connection while fetching reply status for <%s>" , adb_service); } } while (0);
876 |
877 | return EXIT_CODE_ERROR_WHILE_RECEIVING_ADB_PACKET_STATUS;
878 | }
879 |
880 | used_buffer_length += (int)result;
881 | }
882 |
883 | if (memcmp(buffer, "OKAY", 4)) {
884 | ws_debug("Error while receiving by ADB for <%s>", adb_service)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 884, __func__, "Error while receiving by ADB for <%s>" , adb_service); } } while (0);
885 |
886 | return EXIT_CODE_ERROR_WHILE_RECEIVING_ADB_PACKET_DATA;
887 | }
888 |
889 | return EXIT_CODE_SUCCESS;
890 | }
891 |
892 |
893 | static socket_handle_tint
894 | adb_connect_transport(const char *server_ip, unsigned short *server_tcp_port,
895 | const char* serial_number)
896 | {
897 | static const char *const adb_transport_serial_templace = "host:transport:%s";
898 | static const char *const adb_transport_any = "host:transport-any";
899 | char transport_buf[80];
900 | const char* transport = transport_buf;
901 | socket_handle_tint sock;
902 | ssize_t result;
903 |
904 | sock = adb_connect(server_ip, server_tcp_port);
905 | if (sock == INVALID_SOCKET(-1)) {
906 | ws_warning("Error while connecting to adb server")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 906, __func__, "Error while connecting to adb server"); } } while (0);
907 | return sock;
908 | }
909 |
910 | if (!serial_number) {
911 | transport = adb_transport_any;
912 | } else {
913 | result = snprintf(transport_buf, sizeof(transport_buf), adb_transport_serial_templace, serial_number);
914 | if (result <= 0 || result > (int)sizeof(transport_buf)) {
915 | ws_warning("Error while completing adb packet for transport")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 915, __func__, "Error while completing adb packet for transport" ); } } while (0);
916 | closesocket(sock)close(sock);
917 | return INVALID_SOCKET(-1);
918 | }
919 | }
920 |
921 | result = adb_send(sock, transport);
922 | if (result) {
923 | ws_warning("Error while setting adb transport for <%s>", transport_buf)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 923, __func__, "Error while setting adb transport for <%s>" , transport_buf); } } while (0);
924 | closesocket(sock)close(sock);
925 | return INVALID_SOCKET(-1);
926 | }
927 | return sock;
928 | }
929 |
930 |
931 | static void new_interface(extcap_parameters * extcap_conf, const char *interface_id,
932 | const char *model_name, const char *serial_number, const char *display_name)
933 | {
934 | char *interface = ws_strdup_printf("%s-%s", interface_id, serial_number)wmem_strdup_printf(((void*)0), "%s-%s", interface_id, serial_number );
935 | char *ifdisplay = ws_strdup_printf("%s %s %s", display_name, model_name, serial_number)wmem_strdup_printf(((void*)0), "%s %s %s", display_name, model_name , serial_number);
936 |
937 | if (is_specified_interface(interface, INTERFACE_ANDROID_BLUETOOTH_HCIDUMP"android-bluetooth-hcidump") ||
938 | is_specified_interface(interface, INTERFACE_ANDROID_BLUETOOTH_EXTERNAL_PARSER"android-bluetooth-external-parser") ||
939 | is_specified_interface(interface, INTERFACE_ANDROID_BLUETOOTH_BTSNOOP_NET"android-bluetooth-btsnoop-net")) {
940 |
941 | extcap_base_register_interface_ext(extcap_conf, interface, ifdisplay, 99, "BluetoothH4", "Bluetooth HCI UART transport layer plus pseudo-header" );
942 | } else if (is_logcat_interface(interface) || is_logcat_text_interface(interface)) {
943 | extcap_base_register_interface(extcap_conf, interface, ifdisplay, 252, "Upper PDU" );
944 | } else if (is_specified_interface(interface, INTERFACE_ANDROID_TCPDUMP"android-tcpdump")) {
945 | extcap_base_register_interface(extcap_conf, interface, ifdisplay, 1, "Ethernet");
946 | }
947 | g_free(interface)(__builtin_object_size ((interface), 0) != ((size_t) - 1)) ? g_free_sized (interface, __builtin_object_size ((interface), 0)) : (g_free ) (interface);
948 | g_free(ifdisplay)(__builtin_object_size ((ifdisplay), 0) != ((size_t) - 1)) ? g_free_sized (ifdisplay, __builtin_object_size ((ifdisplay), 0)) : (g_free ) (ifdisplay);
949 | }
950 |
951 |
952 | static void new_fake_interface_for_list_dlts(extcap_parameters * extcap_conf,
953 | const char *ifname)
954 | {
955 | if (is_specified_interface(ifname, INTERFACE_ANDROID_BLUETOOTH_HCIDUMP"android-bluetooth-hcidump") ||
956 | is_specified_interface(ifname, INTERFACE_ANDROID_BLUETOOTH_EXTERNAL_PARSER"android-bluetooth-external-parser") ||
957 | is_specified_interface(ifname, INTERFACE_ANDROID_BLUETOOTH_BTSNOOP_NET"android-bluetooth-btsnoop-net")) {
958 | extcap_base_register_interface_ext(extcap_conf, ifname, ifname, 99, "BluetoothH4", "Bluetooth HCI UART transport layer plus pseudo-header" );
959 | } else if (is_logcat_interface(ifname) || is_logcat_text_interface(ifname)) {
960 | extcap_base_register_interface(extcap_conf, ifname, ifname, 252, "Upper PDU" );
961 | } else if (is_specified_interface(ifname, INTERFACE_ANDROID_TCPDUMP"android-tcpdump")) {
962 | extcap_base_register_interface(extcap_conf, ifname, ifname, 1, "Ethernet");
963 | }
964 | }
965 |
966 |
967 | static int add_tcpdump_interfaces(extcap_parameters * extcap_conf, const char *adb_server_ip, unsigned short *adb_server_tcp_port, const char *serial_number)
968 | {
969 | static const char *const adb_tcpdump_list = "shell:tcpdump -D";
970 | static const char *const regex_ifaces = "\\d+\\.(?<iface>\\S+)(\\s+?(?:(?:\\(.*\\))*)(\\s*?\\[(?<flags>.*?)\\])?)?";
971 | static char recv_buffer[PACKET_LENGTH65535];
972 | char *response;
973 | ssize_t data_length;
974 | socket_handle_tint sock;
975 | GRegex* regex = NULL((void*)0);
976 | GError *err = NULL((void*)0);
977 | GMatchInfo *match = NULL((void*)0);
978 | char* tok;
979 | char iface_name[80];
980 | bool_Bool flags_supported;
981 |
982 | sock = adb_connect_transport(adb_server_ip, adb_server_tcp_port, serial_number);
983 | if (sock == INVALID_SOCKET(-1)) {
984 | ws_warning("Failed to connect to adb server")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 984, __func__, "Failed to connect to adb server"); } } while (0);
985 | return EXIT_CODE_GENERIC;
986 | }
987 |
988 | response = adb_send_and_read(sock, adb_tcpdump_list, recv_buffer, sizeof(recv_buffer), &data_length);
989 | closesocket(sock)close(sock);
990 |
991 | if (!response) {
992 | ws_warning("Failed to get list of available tcpdump interfaces")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 992, __func__, "Failed to get list of available tcpdump interfaces" ); } } while (0);
993 | return EXIT_CODE_GENERIC;
994 | }
995 | response[data_length] = '\0';
996 |
997 | regex = g_regex_new(regex_ifaces, G_REGEX_RAW, (GRegexMatchFlags)0, &err);
998 | if (!regex) {
999 | ws_warning("Failed to compile regex for tcpdump interface matching")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 999, __func__, "Failed to compile regex for tcpdump interface matching" ); } } while (0);
1000 | return EXIT_CODE_GENERIC;
1001 | }
1002 |
1003 | flags_supported = (strstr(response, "[") != 0) && (strstr(response, "]") != 0);
1004 |
1005 | tok = strtok(response, "\n");
1006 | while (tok != NULL((void*)0)) {
1007 | g_regex_match(regex, tok, (GRegexMatchFlags)0, &match);
1008 | if (g_match_info_matches(match)) {
1009 | char *iface = g_match_info_fetch_named(match, "iface");
1010 | char *flags = g_match_info_fetch_named(match, "flags");
1011 |
1012 | if (!flags_supported || (flags && strstr(flags, "Up"))) {
1013 | snprintf(iface_name, sizeof(iface_name), INTERFACE_ANDROID_TCPDUMP_FORMAT"android-tcpdump" "-%s", iface);
1014 | new_interface(extcap_conf, iface_name, iface, serial_number, "Android tcpdump");
1015 | }
1016 | g_free(flags)(__builtin_object_size ((flags), 0) != ((size_t) - 1)) ? g_free_sized (flags, __builtin_object_size ((flags), 0)) : (g_free) (flags );
1017 | g_free(iface)(__builtin_object_size ((iface), 0) != ((size_t) - 1)) ? g_free_sized (iface, __builtin_object_size ((iface), 0)) : (g_free) (iface );
1018 | }
1019 | g_match_info_free(match);
1020 | tok = strtok(NULL((void*)0), "\n");
1021 | }
1022 | g_regex_unref(regex);
1023 | return 0;
1024 | }
1025 |
1026 |
1027 | static int register_interfaces(extcap_parameters * extcap_conf, const char *adb_server_ip, unsigned short *adb_server_tcp_port) {
1028 | static char packet[PACKET_LENGTH65535];
1029 | static char helpful_packet[PACKET_LENGTH65535];
1030 | char check_port_buf[80];
1031 | char *response;
1032 | char *device_list;
1033 | ssize_t data_length;
1034 | size_t device_length;
1035 | socket_handle_tint sock;
1036 | const char *adb_check_port_templace = "shell:cat /proc/%s/net/tcp";
1037 | const char *adb_devices = "host:devices-l";
1038 | const char *adb_api_level = "shell:getprop ro.build.version.sdk";
1039 | const char *adb_hcidump_version = "shell:hcidump --version";
1040 | const char *adb_ps_droid_bluetooth = "shell:ps droid.bluetooth";
1041 | const char *adb_ps_bluetooth_app = "shell:ps com.android.bluetooth";
1042 | const char *adb_ps_with_grep = "shell:ps | grep com.android.bluetooth";
1043 | const char *adb_ps_all_with_grep = "shell:ps -A | grep com.*android.bluetooth";
1044 | char serial_number[SERIAL_NUMBER_LENGTH_MAX512];
1045 | char model_name[MODEL_NAME_LENGTH_MAX64];
1046 | int result;
1047 | char *pos;
1048 | char *i_pos;
1049 | char *model_pos;
1050 | char *device_pos;
1051 | char *prev_pos;
1052 | int api_level;
1053 | int disable_interface;
1054 |
1055 | /* NOTE: It seems that "adb devices" and "adb shell" closed connection
1056 | so cannot send next command after them, there is need to reconnect */
1057 |
1058 | sock = adb_connect(adb_server_ip, adb_server_tcp_port);
1059 | if (sock == INVALID_SOCKET(-1))
1060 | return EXIT_CODE_INVALID_SOCKET_INTERFACES_LIST;
1061 |
1062 | device_list = adb_send_and_receive(sock, adb_devices, packet, sizeof(packet), &device_length);
1063 | closesocket(sock)close(sock);
1064 |
1065 | if (!device_list) {
1066 | ws_warning("Cannot get list of interfaces from devices")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1066, __func__, "Cannot get list of interfaces from devices" ); } } while (0);
1067 |
1068 | return EXIT_CODE_CANNOT_GET_INTERFACES_LIST;
1069 | }
1070 |
1071 | device_list[device_length] = '\0';
1072 | pos = (char *) device_list;
1073 |
1074 | while (pos < (char *) (device_list + device_length)) {
1075 | prev_pos = pos;
1076 | pos = strchr(pos, ' ');
1077 | i_pos = pos;
1078 | result = (int) (pos - prev_pos);
1079 | pos = strchr(pos, '\n') + 1;
1080 | if (result >= (int) sizeof(serial_number)) {
1081 | ws_warning("Serial number too long, ignore device")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1081, __func__, "Serial number too long, ignore device"); } } while (0);
1082 | continue;
1083 | }
1084 | memcpy(serial_number, prev_pos, result);
1085 | serial_number[result] = '\0';
1086 |
1087 | model_name[0] = '\0';
1088 | model_pos = g_strstr_len(i_pos, pos - i_pos, "model:");
1089 | if (model_pos) {
1090 | device_pos = g_strstr_len(i_pos, pos - i_pos, "device:");
1091 | if (device_pos && device_pos - model_pos - 6 - 1 < MODEL_NAME_LENGTH_MAX64) {
1092 | memcpy(model_name, model_pos + 6, device_pos - model_pos - 6 - 1);
1093 | model_name[device_pos - model_pos - 6 - 1] = '\0';
1094 | }
1095 | }
1096 |
1097 | if (model_name[0] == '\0')
1098 | strcpy(model_name, "unknown");
1099 |
1100 | ws_debug("Processing device: \"%s\" <%s>" , serial_number, model_name)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1100, __func__, "Processing device: \"%s\" <%s>" , serial_number , model_name); } } while (0);
1101 |
1102 | /* Function will only add tcpdump interfaces if tcpdump is present on the device */
1103 | result = add_tcpdump_interfaces(extcap_conf, adb_server_ip, adb_server_tcp_port, serial_number );
1104 | if (result) {
1105 | ws_warning("Error while adding tcpdump interfaces")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1105, __func__, "Error while adding tcpdump interfaces"); } } while (0);
1106 | }
1107 |
1108 | sock = adb_connect_transport(adb_server_ip, adb_server_tcp_port, serial_number);
1109 | if (sock == INVALID_SOCKET(-1)) continue;
1110 |
1111 | response = adb_send_and_read(sock, adb_api_level, helpful_packet, sizeof(helpful_packet), &data_length);
1112 | closesocket(sock)close(sock);
1113 |
1114 | if (!response) {
1115 | ws_warning("Error on socket: <%s>", helpful_packet)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1115, __func__, "Error on socket: <%s>", helpful_packet ); } } while (0);
1116 | continue;
1117 | }
1118 |
1119 | response[data_length] = '\0';
1120 | api_level = (int) g_ascii_strtoll(response, NULL((void*)0), 10);
1121 | ws_debug("Android API Level for %s is %i", serial_number, api_level)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1121, __func__, "Android API Level for %s is %i", serial_number , api_level); } } while (0);
1122 |
1123 | if (api_level < 21) {
1124 | new_interface(extcap_conf, INTERFACE_ANDROID_LOGCAT_MAIN"android-logcat-main", model_name, serial_number, "Android Logcat Main");
1125 | new_interface(extcap_conf, INTERFACE_ANDROID_LOGCAT_SYSTEM"android-logcat-system", model_name, serial_number, "Android Logcat System");
1126 | new_interface(extcap_conf, INTERFACE_ANDROID_LOGCAT_RADIO"android-logcat-radio", model_name, serial_number, "Android Logcat Radio");
1127 | new_interface(extcap_conf, INTERFACE_ANDROID_LOGCAT_EVENTS"android-logcat-events", model_name, serial_number, "Android Logcat Events");
1128 |
1129 | new_interface(extcap_conf, INTERFACE_ANDROID_LOGCAT_TEXT_MAIN"android-logcat-text-main", model_name, serial_number, "Android Logcat Main");
1130 | new_interface(extcap_conf, INTERFACE_ANDROID_LOGCAT_TEXT_SYSTEM"android-logcat-text-system", model_name, serial_number, "Android Logcat System");
1131 | new_interface(extcap_conf, INTERFACE_ANDROID_LOGCAT_TEXT_RADIO"android-logcat-text-radio", model_name, serial_number, "Android Logcat Radio");
1132 | new_interface(extcap_conf, INTERFACE_ANDROID_LOGCAT_TEXT_EVENTS"android-logcat-text-events", model_name, serial_number, "Android Logcat Events");
1133 | } else {
1134 | new_interface(extcap_conf, INTERFACE_ANDROID_LOGCAT_TEXT_MAIN"android-logcat-text-main", model_name, serial_number, "Android Logcat Main");
1135 | new_interface(extcap_conf, INTERFACE_ANDROID_LOGCAT_TEXT_SYSTEM"android-logcat-text-system", model_name, serial_number, "Android Logcat System");
1136 | new_interface(extcap_conf, INTERFACE_ANDROID_LOGCAT_TEXT_RADIO"android-logcat-text-radio", model_name, serial_number, "Android Logcat Radio");
1137 | new_interface(extcap_conf, INTERFACE_ANDROID_LOGCAT_TEXT_EVENTS"android-logcat-text-events", model_name, serial_number, "Android Logcat Events");
1138 | new_interface(extcap_conf, INTERFACE_ANDROID_LOGCAT_TEXT_CRASH"android-logcat-text-crash", model_name, serial_number, "Android Logcat Crash");
1139 | }
1140 |
1141 | if (api_level >= 5 && api_level < 17) {
1142 | disable_interface = 0;
1143 |
1144 | sock = adb_connect_transport(adb_server_ip, adb_server_tcp_port, serial_number);
1145 | if (sock == INVALID_SOCKET(-1)) continue;
1146 |
1147 | response = adb_send_and_read(sock, adb_hcidump_version, helpful_packet, sizeof(helpful_packet), &data_length);
1148 | closesocket(sock)close(sock);
1149 |
1150 | if (!response || data_length < 1) {
1151 | ws_warning("Error while getting hcidump version by <%s> (%p len=%"PRIdMAX")",do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1152, __func__, "Error while getting hcidump version by <%s> (%p len=%" "l" "d"")", adb_hcidump_version, (void*)response, (intmax_t)data_length ); } } while (0)
1152 | adb_hcidump_version, (void*)response, (intmax_t)data_length)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1152, __func__, "Error while getting hcidump version by <%s> (%p len=%" "l" "d"")", adb_hcidump_version, (void*)response, (intmax_t)data_length ); } } while (0);
1153 | ws_debug("Android hcidump version for %s is unknown", serial_number)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1153, __func__, "Android hcidump version for %s is unknown" , serial_number); } } while (0);
1154 | disable_interface = 1;
1155 | } else {
1156 | response[data_length] = '\0';
1157 |
1158 | if (g_ascii_strtoull(response, NULL((void*)0), 10) == 0) {
1159 | ws_debug("Android hcidump version for %s is unknown", serial_number)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1159, __func__, "Android hcidump version for %s is unknown" , serial_number); } } while (0);
1160 | disable_interface = 1;
1161 | } else {
1162 | ws_debug("Android hcidump version for %s is %s", serial_number, response)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1162, __func__, "Android hcidump version for %s is %s", serial_number , response); } } while (0);
1163 | }
1164 | }
1165 |
1166 | if (!disable_interface) {
1167 | new_interface(extcap_conf, INTERFACE_ANDROID_BLUETOOTH_HCIDUMP"android-bluetooth-hcidump", model_name, serial_number, "Android Bluetooth Hcidump");
1168 | }
1169 | }
1170 |
1171 | if (api_level >= 17 && api_level < 21) {
1172 | disable_interface = 0;
1173 | sock = adb_connect_transport(adb_server_ip, adb_server_tcp_port, serial_number);
1174 | if (sock == INVALID_SOCKET(-1)) continue;
1175 |
1176 | response = adb_send_and_read(sock, adb_ps_droid_bluetooth, helpful_packet, sizeof(helpful_packet), &data_length);
1177 | closesocket(sock)close(sock);
1178 | if (!response || data_length < 1) {
1179 | ws_warning("Error while getting Bluetooth application process id by <%s> "do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1180, __func__, "Error while getting Bluetooth application process id by <%s> " "(%p len=%""l" "d"")", adb_ps_droid_bluetooth, (void*)response , (intmax_t)data_length); } } while (0)
1180 | "(%p len=%"PRIdMAX")", adb_ps_droid_bluetooth, (void*)response, (intmax_t)data_length)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1180, __func__, "Error while getting Bluetooth application process id by <%s> " "(%p len=%""l" "d"")", adb_ps_droid_bluetooth, (void*)response , (intmax_t)data_length); } } while (0);
1181 | ws_debug( "Android Bluetooth application PID for %s is unknown", serial_number)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1181, __func__, "Android Bluetooth application PID for %s is unknown" , serial_number); } } while (0);
1182 | disable_interface = 1;
1183 | } else {
1184 | char *data_str;
1185 | char pid[16];
1186 |
1187 | memset(pid, 0, sizeof(pid));
1188 | response[data_length] = '\0';
1189 |
1190 | data_str = strchr(response, '\n');
1191 | if (data_str && sscanf(data_str, "%*s %15s", pid) == 1) {
1192 | ws_debug("Android Bluetooth application PID for %s is %s", serial_number, pid)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1192, __func__, "Android Bluetooth application PID for %s is %s" , serial_number, pid); } } while (0);
1193 |
1194 | result = snprintf(check_port_buf, sizeof(check_port_buf), adb_check_port_templace, pid);
1195 | if (result <= 0 || result > (int)sizeof(check_port_buf)) {
1196 | ws_warning("Error while completing adb packet")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1196, __func__, "Error while completing adb packet"); } } while (0);
1197 | return EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_6;
1198 | }
1199 |
1200 | sock = adb_connect_transport(adb_server_ip, adb_server_tcp_port, serial_number);
1201 | if (sock == INVALID_SOCKET(-1)) continue;
1202 |
1203 | response = adb_send_and_read(sock, check_port_buf, helpful_packet, sizeof(helpful_packet), &data_length);
1204 | closesocket(sock)close(sock);
1205 |
1206 | if (!response) {
1207 | disable_interface = 1;
1208 | } else {
1209 | response[data_length] = '\0';
1210 |
1211 | data_str = strchr(response, '\n');
1212 | if (data_str && sscanf(data_str, "%*s %15s", pid) == 1 && strlen(pid) > 10 && strcmp(pid + 9, "10EA") == 0) {
1213 | ws_debug("Bluedroid External Parser Port for %s is %s", serial_number, pid + 9)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1213, __func__, "Bluedroid External Parser Port for %s is %s" , serial_number, pid + 9); } } while (0);
1214 | } else {
1215 | disable_interface = 1;
1216 | ws_debug("Bluedroid External Parser Port for %s is unknown", serial_number)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1216, __func__, "Bluedroid External Parser Port for %s is unknown" , serial_number); } } while (0);
1217 | }
1218 | }
1219 | } else {
1220 | disable_interface = 1;
1221 | ws_debug("Android Bluetooth application PID for %s is unknown", serial_number)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1221, __func__, "Android Bluetooth application PID for %s is unknown" , serial_number); } } while (0);
1222 | }
1223 | }
1224 |
1225 | if (!disable_interface) {
1226 | new_interface(extcap_conf, INTERFACE_ANDROID_BLUETOOTH_EXTERNAL_PARSER"android-bluetooth-external-parser", model_name, serial_number, "Android Bluetooth External Parser");
1227 | }
1228 | }
1229 |
1230 | if (api_level >= 21) {
1231 | const char* ps_cmd;
1232 | disable_interface = 0;
1233 |
1234 | if (api_level >= 26) {
1235 | ps_cmd = adb_ps_all_with_grep;
1236 | } else if (api_level >= 24) {
1237 | ps_cmd = adb_ps_with_grep;
1238 | } else if (api_level >= 23) {
1239 | ps_cmd = adb_ps_bluetooth_app;
1240 | } else {
1241 | ps_cmd = adb_ps_droid_bluetooth;
1242 | }
1243 | sock = adb_connect_transport(adb_server_ip, adb_server_tcp_port, serial_number);
1244 | if (sock == INVALID_SOCKET(-1)) continue;
1245 |
1246 | response = adb_send_and_read(sock, ps_cmd, helpful_packet, sizeof(helpful_packet), &data_length);
1247 | closesocket(sock)close(sock);
1248 |
1249 | if (!response || data_length < 1) {
1250 | ws_warning("Error while getting Bluetooth application process id by <%s> "do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1251, __func__, "Error while getting Bluetooth application process id by <%s> " "(%p len=%""l" "d"")", ps_cmd, (void*)response, (intmax_t)data_length ); } } while (0)
1251 | "(%p len=%"PRIdMAX")", ps_cmd, (void*)response, (intmax_t)data_length)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1251, __func__, "Error while getting Bluetooth application process id by <%s> " "(%p len=%""l" "d"")", ps_cmd, (void*)response, (intmax_t)data_length ); } } while (0);
1252 | ws_debug("Android Bluetooth application PID for %s is unknown", serial_number)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1252, __func__, "Android Bluetooth application PID for %s is unknown" , serial_number); } } while (0);
1253 | disable_interface = 1;
1254 | } else {
1255 | char *data_str;
1256 | char pid[16];
1257 |
1258 | memset(pid, 0, sizeof(pid));
1259 | response[data_length] = '\0';
1260 |
1261 | if (api_level >= 24)
1262 | data_str = response;
1263 | else
1264 | data_str = strchr(response, '\n');
1265 |
1266 | if (data_str && sscanf(data_str, "%*s %15s", pid) == 1) {
1267 | ws_debug("Android Bluetooth application PID for %s is %s", serial_number, pid)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1267, __func__, "Android Bluetooth application PID for %s is %s" , serial_number, pid); } } while (0);
1268 |
1269 | result = snprintf(check_port_buf, sizeof(check_port_buf), adb_check_port_templace, pid);
1270 | if (result <= 0 || result > (int)sizeof(check_port_buf)) {
1271 | ws_warning("Error while completing adb packet")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1271, __func__, "Error while completing adb packet"); } } while (0);
1272 | return EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_9;
1273 | }
1274 |
1275 | sock = adb_connect_transport(adb_server_ip, adb_server_tcp_port, serial_number);
1276 | if (sock == INVALID_SOCKET(-1)) continue;
1277 |
1278 | response = adb_send_and_read(sock, check_port_buf, helpful_packet, sizeof(helpful_packet), &data_length);
1279 | closesocket(sock)close(sock);
1280 |
1281 | if (!response) {
1282 | disable_interface = 1;
1283 | } else {
1284 | response[data_length] = '\0';
1285 | data_str = strtok(response, "\n");
1286 | while (data_str != NULL((void*)0)) {
1287 | if (sscanf(data_str, "%*s %15s", pid) == 1 && strlen(pid) > 10 && strcmp(pid + 9, "22A8") == 0) {
1288 | ws_debug("Btsnoop Net Port for %s is %s", serial_number, pid + 9)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1288, __func__, "Btsnoop Net Port for %s is %s", serial_number , pid + 9); } } while (0);
1289 | break;
1290 | }
1291 | data_str = strtok(NULL((void*)0), "\n");
1292 | }
1293 | if (data_str == NULL((void*)0)) {
1294 | disable_interface = 1;
1295 | ws_debug("Btsnoop Net Port for %s is unknown", serial_number)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1295, __func__, "Btsnoop Net Port for %s is unknown", serial_number ); } } while (0);
1296 | }
1297 | }
1298 | } else {
1299 | disable_interface = 1;
1300 | ws_debug("Android Bluetooth application PID for %s is unknown", serial_number)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1300, __func__, "Android Bluetooth application PID for %s is unknown" , serial_number); } } while (0);
1301 | }
1302 | }
1303 |
1304 | if (!disable_interface) {
1305 | new_interface(extcap_conf, INTERFACE_ANDROID_BLUETOOTH_BTSNOOP_NET"android-bluetooth-btsnoop-net", model_name, serial_number, "Android Bluetooth Btsnoop Net");
1306 | }
1307 | }
1308 | }
1309 |
1310 | return EXIT_CODE_SUCCESS;
1311 | }
1312 |
1313 | static int list_config(char *interface) {
1314 | int ret = EXIT_CODE_INVALID_INTERFACE;
1315 | unsigned inc = 0;
1316 |
1317 | if (!interface) {
1318 | ws_warning("No interface specified.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1318, __func__, "No interface specified."); } } while (0);
1319 | return EXIT_CODE_NO_INTERFACE_SPECIFIED;
1320 | }
1321 |
1322 | if (is_specified_interface(interface, INTERFACE_ANDROID_BLUETOOTH_EXTERNAL_PARSER"android-bluetooth-external-parser")) {
1323 | printf("arg {number=%u}{call=--adb-server-ip}{display=ADB Server IP Address}{type=string}{default=127.0.0.1}\n", inc++);
1324 | printf("arg {number=%u}{call=--adb-server-tcp-port}{display=ADB Server TCP Port}{type=integer}{range=0,65535}{default=5037}\n", inc++);
1325 | printf("arg {number=%u}{call=--bt-server-tcp-port}{display=Bluetooth Server TCP Port}{type=integer}{range=0,65535}{default=4330}\n", inc++);
1326 | printf("arg {number=%u}{call=--bt-forward-socket}{display=Forward Bluetooth Socket}{type=boolean}{default=false}\n", inc++);
1327 | printf("arg {number=%u}{call=--bt-local-ip}{display=Bluetooth Local IP Address}{type=string}{default=127.0.0.1}\n", inc++);
1328 | printf("arg {number=%u}{call=--bt-local-tcp-port}{display=Bluetooth Local TCP Port}{type=integer}{range=0,65535}{default=4330}{tooltip=Used to do \"adb forward tcp:LOCAL_TCP_PORT tcp:SERVER_TCP_PORT\"}\n", inc++);
1329 | ret = EXIT_CODE_SUCCESS;
1330 | } else if (is_specified_interface(interface, INTERFACE_ANDROID_BLUETOOTH_HCIDUMP"android-bluetooth-hcidump") ||
1331 | is_specified_interface(interface, INTERFACE_ANDROID_BLUETOOTH_BTSNOOP_NET"android-bluetooth-btsnoop-net") ||
1332 | is_specified_interface(interface, INTERFACE_ANDROID_TCPDUMP"android-tcpdump")) {
1333 | printf("arg {number=%u}{call=--adb-server-ip}{display=ADB Server IP Address}{type=string}{default=127.0.0.1}\n", inc++);
1334 | printf("arg {number=%u}{call=--adb-server-tcp-port}{display=ADB Server TCP Port}{type=integer}{range=0,65535}{default=5037}\n", inc++);
1335 | ret = EXIT_CODE_SUCCESS;
1336 | } else if (is_logcat_interface(interface)) {
1337 | printf("arg {number=%u}{call=--adb-server-ip}{display=ADB Server IP Address}{type=string}{default=127.0.0.1}\n", inc++);
1338 | printf("arg {number=%u}{call=--adb-server-tcp-port}{display=ADB Server TCP Port}{type=integer}{range=0,65535}{default=5037}\n", inc++);
1339 | printf("arg {number=%u}{call=--logcat-text}{display=Use text logcat}{type=boolean}{default=false}\n", inc++);
1340 | printf("arg {number=%u}{call=--logcat-ignore-log-buffer}{display=Ignore log buffer}{type=boolean}{default=false}\n", inc++);
1341 | printf("arg {number=%u}{call=--logcat-custom-options}{display=Custom logcat parameters}{type=string}\n", inc++);
1342 | ret = EXIT_CODE_SUCCESS;
1343 | } else if (is_logcat_text_interface(interface)) {
1344 | printf("arg {number=%u}{call=--adb-server-ip}{display=ADB Server IP Address}{type=string}{default=127.0.0.1}\n", inc++);
1345 | printf("arg {number=%u}{call=--adb-server-tcp-port}{display=ADB Server TCP Port}{type=integer}{range=0,65535}{default=5037}\n", inc++);
1346 | printf("arg {number=%u}{call=--logcat-ignore-log-buffer}{display=Ignore log buffer}{type=boolean}{default=false}\n", inc++);
1347 | printf("arg {number=%u}{call=--logcat-custom-options}{display=Custom logcat parameters}{type=string}\n", inc++);
1348 | ret = EXIT_CODE_SUCCESS;
1349 | }
1350 |
1351 | if (ret != EXIT_CODE_SUCCESS)
1352 | ws_warning("Invalid interface: <%s>", interface)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1352, __func__, "Invalid interface: <%s>", interface) ; } } while (0);
1353 | else
1354 | extcap_config_debug(&inc);
1355 |
1356 | return ret;
1357 | }
1358 |
1359 | /*----------------------------------------------------------------------------*/
1360 | /* Android Bluetooth Hcidump */
1361 | /*----------------------------------------------------------------------------*/
1362 |
1363 | static int capture_android_bluetooth_hcidump(char *interface, char *fifo,
1364 | const char *adb_server_ip, unsigned short *adb_server_tcp_port) {
1365 | struct extcap_dumper extcap_dumper;
1366 | static char data[PACKET_LENGTH65535];
1367 | static char packet[PACKET_LENGTH65535];
1368 | ssize_t length;
1369 | ssize_t used_buffer_length = 0;
1370 | socket_handle_tint sock = INVALID_SOCKET(-1);
1371 | const char *adb_shell_hcidump = "shell:hcidump -R -t";
1372 | const char *adb_shell_su_hcidump = "shell:su -c hcidump -R -t";
1373 | int result;
1374 | char *serial_number;
1375 | time_t ts = 0;
1376 | unsigned int captured_length;
1377 | int64_t hex;
1378 | char *hex_data;
1379 | char *new_hex_data;
1380 | own_pcap_bluetooth_h4_header *h4_header;
1381 | int64_t raw_length = 0;
1382 | int64_t frame_length;
1383 | int ms = 0;
1384 | struct tm date;
1385 | char direction_character;
1386 |
1387 | SET_DATA(h4_header, value_own_pcap_bluetooth_h4_header, packet){ data_aligned_t data_aligned; data_aligned.value_char = packet ; h4_header = data_aligned.value_own_pcap_bluetooth_h4_header ; };
1388 |
1389 | extcap_dumper = extcap_dumper_open(fifo, EXTCAP_ENCAP_BLUETOOTH_H4_WITH_PHDR99);
1390 |
1391 | serial_number = get_serial_from_interface(interface);
1392 | sock = adb_connect_transport(adb_server_ip, adb_server_tcp_port, serial_number);
1393 | if (sock == INVALID_SOCKET(-1))
1394 | return EXIT_CODE_INVALID_SOCKET_3;
1395 |
1396 | result = adb_send(sock, adb_shell_hcidump);
1397 | if (result) {
1398 | ws_warning("Error while starting capture by sending command: %s", adb_shell_hcidump)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1398, __func__, "Error while starting capture by sending command: %s" , adb_shell_hcidump); } } while (0);
1399 | closesocket(sock)close(sock);
1400 | return EXIT_CODE_GENERIC;
1401 | }
1402 |
1403 | while (endless_loop) {
1404 | char *i_position;
1405 |
1406 | errno(*__errno_location ()) = 0;
1407 | length = recv(sock, data + used_buffer_length, (int)(PACKET_LENGTH65535 - used_buffer_length), 0);
1408 | CONTINUE_ON_TIMEOUT(length)if ((*__errno_location ()) == 11) continue;
1409 | else if (errno(*__errno_location ()) != 0) {
1410 | ws_warning("ERROR capture: %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1410, __func__, "ERROR capture: %s", strerror((*__errno_location ()))); } } while (0);
1411 | closesocket(sock)close(sock);
1412 | return EXIT_CODE_GENERIC;
1413 | }
1414 |
1415 | if (length <= 0) {
1416 | ws_warning("Broken socket connection.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1416, __func__, "Broken socket connection."); } } while (0);
1417 | closesocket(sock)close(sock);
1418 | return EXIT_CODE_GENERIC;
1419 | }
1420 |
1421 | used_buffer_length += length;
1422 | i_position = (char *) memchr(data, '\n', used_buffer_length);
1423 | if (i_position && i_position < data + used_buffer_length) {
1424 | char *state_line_position = i_position + 1;
1425 |
1426 | if (!strncmp(data, "/system/bin/sh: hcidump: not found", 34)) {
1427 | ws_warning("Command not found for <%s>", adb_shell_hcidump)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1427, __func__, "Command not found for <%s>", adb_shell_hcidump ); } } while (0);
1428 | closesocket(sock)close(sock);
1429 | return EXIT_CODE_GENERIC;
1430 | }
1431 |
1432 | i_position = (char *) memchr(i_position + 1, '\n', used_buffer_length);
1433 | if (i_position) {
1434 | i_position += 1;
1435 | if (!strncmp(state_line_position, "Can't access device: Permission denied", 38)) {
1436 | ws_warning("No permission for command <%s>", adb_shell_hcidump)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1436, __func__, "No permission for command <%s>", adb_shell_hcidump ); } } while (0);
1437 | used_buffer_length = 0;
1438 | closesocket(sock)close(sock);
1439 | sock = INVALID_SOCKET(-1);
1440 | break;
1441 | }
1442 | memmove(data, i_position, used_buffer_length - (i_position - data));
1443 | used_buffer_length = used_buffer_length - (ssize_t)(i_position - data);
1444 | break;
1445 | }
1446 | }
1447 | }
1448 |
1449 | if (sock == INVALID_SOCKET(-1)) {
1450 | sock = adb_connect_transport(adb_server_ip, adb_server_tcp_port, serial_number);
1451 | if (sock == INVALID_SOCKET(-1))
1452 | return EXIT_CODE_INVALID_SOCKET_4;
1453 |
1454 | result = adb_send(sock, adb_shell_su_hcidump);
1455 | if (result) {
1456 | ws_warning("Error while starting capture by sending command: <%s>", adb_shell_su_hcidump)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1456, __func__, "Error while starting capture by sending command: <%s>" , adb_shell_su_hcidump); } } while (0);
1457 | closesocket(sock)close(sock);
1458 | return EXIT_CODE_GENERIC;
1459 | }
1460 |
1461 | used_buffer_length = 0;
1462 | while (endless_loop) {
1463 | char *i_position;
1464 |
1465 | errno(*__errno_location ()) = 0;
1466 | length = recv(sock, data + used_buffer_length, (int)(PACKET_LENGTH65535 - used_buffer_length), 0);
1467 | CONTINUE_ON_TIMEOUT(length)if ((*__errno_location ()) == 11) continue;
1468 | else if (errno(*__errno_location ()) != 0) {
1469 | ws_warning("ERROR capture: %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1469, __func__, "ERROR capture: %s", strerror((*__errno_location ()))); } } while (0);
1470 | closesocket(sock)close(sock);
1471 | return EXIT_CODE_GENERIC;
1472 | }
1473 |
1474 | if (length <= 0) {
1475 | ws_warning("Broken socket connection.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1475, __func__, "Broken socket connection."); } } while (0);
1476 | closesocket(sock)close(sock);
1477 | return EXIT_CODE_GENERIC;
1478 | }
1479 |
1480 | used_buffer_length += length;
1481 | i_position = (char *) memchr(data, '\n', used_buffer_length);
1482 | if (i_position && i_position < data + used_buffer_length) {
1483 | if (!strncmp(data, "/system/bin/sh: su: not found", 29)) {
1484 | ws_warning("Command 'su' not found for <%s>", adb_shell_su_hcidump)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1484, __func__, "Command 'su' not found for <%s>", adb_shell_su_hcidump ); } } while (0);
1485 | closesocket(sock)close(sock);
1486 | return EXIT_CODE_GENERIC;
1487 | }
1488 |
1489 | i_position = (char *) memchr(i_position + 1, '\n', used_buffer_length);
1490 | if (i_position) {
1491 | i_position += 1;
1492 | memmove(data, i_position, used_buffer_length - (i_position - data));
1493 | used_buffer_length = used_buffer_length - (ssize_t)(i_position - data);
1494 | break;
1495 | }
1496 | }
1497 | }
1498 | }
1499 |
1500 | while (endless_loop) {
1501 | errno(*__errno_location ()) = 0;
1502 | length = recv(sock, data + used_buffer_length, (int)(PACKET_LENGTH65535 - used_buffer_length), 0);
1503 | CONTINUE_ON_TIMEOUT(length)if ((*__errno_location ()) == 11) continue;
1504 | else if (errno(*__errno_location ()) != 0) {
1505 | ws_warning("ERROR capture: %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1505, __func__, "ERROR capture: %s", strerror((*__errno_location ()))); } } while (0);
1506 | closesocket(sock)close(sock);
1507 | return EXIT_CODE_GENERIC;
1508 | }
1509 |
1510 | if (length <= 0) {
1511 | ws_warning("Broken socket connection.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1511, __func__, "Broken socket connection."); } } while (0);
1512 | closesocket(sock)close(sock);
1513 | return EXIT_CODE_GENERIC;
1514 | }
1515 |
1516 | while (endless_loop) {
1517 | if (used_buffer_length + length >= 1) {
1518 | hex_data = data + 29;
1519 | hex = g_ascii_strtoll(hex_data, &new_hex_data, 16);
1520 |
1521 | if ((hex == 0x01 && used_buffer_length + length >= 4) ||
1522 | (hex == 0x02 && used_buffer_length + length >= 5) ||
1523 | (hex == 0x04 && used_buffer_length + length >= 3)) {
1524 |
1525 | if (hex == 0x01) {
1526 | hex_data = new_hex_data;
1527 | hex = g_ascii_strtoll(hex_data, &new_hex_data, 16);
1528 | if (hex < 0 || hex >= 256 || hex_data == new_hex_data) {
1529 | ws_warning("data format %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1529, __func__, "data format %s", strerror((*__errno_location ()))); } } while (0);
1530 | closesocket(sock)close(sock);
1531 | return EXIT_CODE_GENERIC;
1532 | }
1533 |
1534 | hex_data = new_hex_data;
1535 | hex = g_ascii_strtoll(hex_data, &new_hex_data, 16);
1536 | if (hex < 0 || hex >= 256 || hex_data == new_hex_data) {
1537 | ws_warning("data format %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1537, __func__, "data format %s", strerror((*__errno_location ()))); } } while (0);
1538 | closesocket(sock)close(sock);
1539 | return EXIT_CODE_GENERIC;
1540 | }
1541 |
1542 | hex_data = new_hex_data;
1543 | hex = g_ascii_strtoll(hex_data, &new_hex_data, 16);
1544 |
1545 | raw_length = hex + 4;
1546 | } else if (hex == 0x04) {
1547 | hex_data = new_hex_data;
1548 | hex = g_ascii_strtoll(hex_data, &new_hex_data, 16);
1549 | if (hex < 0 || hex >= 256 || hex_data == new_hex_data) {
1550 | ws_warning("data format %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1550, __func__, "data format %s", strerror((*__errno_location ()))); } } while (0);
1551 | closesocket(sock)close(sock);
1552 | return EXIT_CODE_GENERIC;
1553 | }
1554 |
1555 | hex_data = new_hex_data;
1556 | hex = g_ascii_strtoll(hex_data, &new_hex_data, 16);
1557 |
1558 | raw_length = hex + 3;
1559 | } else if (hex == 0x02) {
1560 | hex_data = new_hex_data;
1561 | hex = g_ascii_strtoll(hex_data, &new_hex_data, 16);
1562 | if (hex < 0 || hex >= 256 || hex_data == new_hex_data) {
1563 | ws_warning("data format %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1563, __func__, "data format %s", strerror((*__errno_location ()))); } } while (0);
1564 | closesocket(sock)close(sock);
1565 | return EXIT_CODE_GENERIC;
1566 | }
1567 |
1568 | hex_data = new_hex_data;
1569 | hex = g_ascii_strtoll(hex_data, &new_hex_data, 16);
1570 | if (hex < 0 || hex >= 256 || hex_data == new_hex_data) {
1571 | ws_warning("data format %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1571, __func__, "data format %s", strerror((*__errno_location ()))); } } while (0);
1572 | closesocket(sock)close(sock);
1573 | return EXIT_CODE_GENERIC;
1574 | }
1575 |
1576 | hex_data = new_hex_data;
1577 | hex = g_ascii_strtoll(hex_data, &new_hex_data, 16);
1578 | raw_length = hex + 5;
1579 |
1580 | hex_data = new_hex_data;
1581 | hex = g_ascii_strtoll(hex_data, &new_hex_data, 16);
1582 | raw_length += hex << 8;
1583 | }
1584 |
1585 | } else {
1586 | ws_warning("bad raw stream")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1586, __func__, "bad raw stream"); } } while (0);
1587 | closesocket(sock)close(sock);
1588 | return EXIT_CODE_GENERIC;
1589 | }
1590 | } else {
1591 | used_buffer_length += length;
1592 | break;
1593 | }
1594 |
1595 | frame_length = raw_length * 3 + (raw_length / 20) * 4 + ((raw_length % 20) ? 2 : -2) + 29;
1596 |
1597 | if ((used_buffer_length + length) < frame_length) {
1598 | used_buffer_length += length;
1599 | break;
1600 | }
1601 |
1602 | if (8 == sscanf(data, "%04d-%02d-%02d %02d:%02d:%02d.%06d %c",
1603 | &date.tm_year, &date.tm_mon, &date.tm_mday, &date.tm_hour,
1604 | &date.tm_min, &date.tm_sec, &ms, &direction_character)) {
1605 |
1606 | ws_debug("time %04d-%02d-%02d %02d:%02d:%02d.%06d %c",do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1608, __func__, "time %04d-%02d-%02d %02d:%02d:%02d.%06d %c" , date.tm_year, date.tm_mon, date.tm_mday, date.tm_hour, date .tm_min, date.tm_sec, ms, direction_character); } } while (0)
1607 | date.tm_year, date.tm_mon, date.tm_mday, date.tm_hour,do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1608, __func__, "time %04d-%02d-%02d %02d:%02d:%02d.%06d %c" , date.tm_year, date.tm_mon, date.tm_mday, date.tm_hour, date .tm_min, date.tm_sec, ms, direction_character); } } while (0)
1608 | date.tm_min, date.tm_sec, ms, direction_character)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1608, __func__, "time %04d-%02d-%02d %02d:%02d:%02d.%06d %c" , date.tm_year, date.tm_mon, date.tm_mday, date.tm_hour, date .tm_min, date.tm_sec, ms, direction_character); } } while (0);
1609 | date.tm_mon -= 1;
1610 | date.tm_year -= 1900;
1611 | date.tm_isdst = -1;
1612 | ts = mktime(&date);
1613 |
1614 | new_hex_data = data + 29;
1615 | }
1616 |
1617 | captured_length = 0;
1618 |
1619 | while ((long)(new_hex_data - data + sizeof(own_pcap_bluetooth_h4_header)) < frame_length) {
1620 | hex_data = new_hex_data;
1621 | hex = g_ascii_strtoll(hex_data, &new_hex_data, 16);
1622 |
1623 | packet[sizeof(own_pcap_bluetooth_h4_header) + captured_length] = (char) hex;
1624 | captured_length += 1;
1625 | }
1626 |
1627 | h4_header->direction = GINT32_TO_BE(direction_character == '>')((gint32) (((guint32) ( (((guint32) (direction_character == '>' ) & (guint32) 0x000000ffU) << 24) | (((guint32) (direction_character == '>') & (guint32) 0x0000ff00U) << 8) | (((guint32 ) (direction_character == '>') & (guint32) 0x00ff0000U ) >> 8) | (((guint32) (direction_character == '>') & (guint32) 0xff000000U) >> 24)))));
1628 |
1629 | endless_loop = extcap_dumper_dump(extcap_dumper, fifo, packet,
1630 | captured_length + sizeof(own_pcap_bluetooth_h4_header),
1631 | captured_length + sizeof(own_pcap_bluetooth_h4_header),
1632 | ts,
1633 | ms * 1000);
1634 |
1635 | memmove(data, data + frame_length, (size_t)(used_buffer_length + length - frame_length));
1636 | used_buffer_length = (ssize_t)(used_buffer_length + length - frame_length);
1637 | length = 0;
1638 | }
1639 | }
1640 |
1641 | closesocket(sock)close(sock);
1642 | return EXIT_CODE_SUCCESS;
1643 | }
1644 |
1645 | /*----------------------------------------------------------------------------*/
1646 | /* Android Bluetooth External Parser */
1647 | /*----------------------------------------------------------------------------*/
1648 |
1649 | #define BLUEDROID_H4_PACKET_TYPE0 0
1650 | #define BLUEDROID_TIMESTAMP_SIZE8 8
1651 | #define BLUEDROID_H4_SIZE1 1
1652 |
1653 | static const uint64_t BLUEDROID_TIMESTAMP_BASE = UINT64_C(0x00dcddb30f2f8000)0x00dcddb30f2f8000UL;
1654 |
1655 | #define BLUEDROID_H4_PACKET_TYPE_HCI_CMD0x01 0x01
1656 | #define BLUEDROID_H4_PACKET_TYPE_ACL0x02 0x02
1657 | #define BLUEDROID_H4_PACKET_TYPE_SCO0x03 0x03
1658 | #define BLUEDROID_H4_PACKET_TYPE_HCI_EVT0x04 0x04
1659 |
1660 | #define BLUEDROID_DIRECTION_SENT0 0
1661 | #define BLUEDROID_DIRECTION_RECV1 1
1662 |
1663 | static int adb_forward(char *serial_number, const char *adb_server_ip, unsigned short *adb_server_tcp_port,
1664 | unsigned short local_tcp_port, unsigned short server_tcp_port) {
1665 | socket_handle_tint sock;
1666 | int result;
1667 | static char helpful_packet[PACKET_LENGTH65535];
1668 | static const char *adb_forward_template = "%s%s:forward:tcp:%05u;tcp:%05u";
1669 |
1670 | sock = adb_connect(adb_server_ip, adb_server_tcp_port);
1671 | if (sock == INVALID_SOCKET(-1))
1672 | return EXIT_CODE_INVALID_SOCKET_5;
1673 |
1674 | result = snprintf(helpful_packet, PACKET_LENGTH65535, adb_forward_template, (serial_number) ? "host-serial:" : "host", (serial_number) ? serial_number: "", local_tcp_port, server_tcp_port);
1675 | if (result <= 0 || result > PACKET_LENGTH65535) {
1676 | ws_warning("Error while completing adb packet")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1676, __func__, "Error while completing adb packet"); } } while (0);
1677 | closesocket(sock)close(sock);
1678 | return EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_12;
1679 | }
1680 |
1681 | result = adb_send(sock, helpful_packet);
1682 | closesocket(sock)close(sock);
1683 |
1684 | return result;
1685 | }
1686 |
1687 | static int capture_android_bluetooth_external_parser(char *interface,
1688 | char *fifo, const char *adb_server_ip, unsigned short *adb_server_tcp_port,
1689 | unsigned short *bt_server_tcp_port, unsigned int bt_forward_socket, const char *bt_local_ip,
1690 | unsigned short *bt_local_tcp_port) {
1691 | struct extcap_dumper extcap_dumper;
1692 | static char buffer[PACKET_LENGTH65535];
1693 | uint64_t *timestamp;
1694 | char *packet = buffer + BLUEDROID_TIMESTAMP_SIZE8 - sizeof(own_pcap_bluetooth_h4_header); /* skip timestamp (8 bytes) and reuse its space for header */
1695 | own_pcap_bluetooth_h4_header *h4_header;
1696 | uint8_t *payload = (uint8_t*)(packet + sizeof(own_pcap_bluetooth_h4_header));
1697 | const char *adb_tcp_bluedroid_external_parser_template = "tcp:%05u";
1698 | socklen_t slen;
1699 | ssize_t length;
1700 | ssize_t used_buffer_length = 0;
1701 | uint64_t ts;
1702 | socket_handle_tint sock;
1703 | struct sockaddr_in server;
1704 | int captured_length;
1705 | char *serial_number;
1706 | static unsigned int id = 1;
1707 | struct sockaddr_in client;
1708 |
1709 | SET_DATA(timestamp, value_u64, buffer){ data_aligned_t data_aligned; data_aligned.value_char = buffer ; timestamp = data_aligned.value_u64; };
1710 | SET_DATA(h4_header, value_own_pcap_bluetooth_h4_header, packet){ data_aligned_t data_aligned; data_aligned.value_char = packet ; h4_header = data_aligned.value_own_pcap_bluetooth_h4_header ; };
1711 |
1712 | extcap_dumper = extcap_dumper_open(fifo, EXTCAP_ENCAP_BLUETOOTH_H4_WITH_PHDR99);
1713 | serial_number = get_serial_from_interface(interface);
1714 |
1715 | if (bt_forward_socket) {
1716 | if ((sock = socket(AF_INET2, SOCK_STREAMSOCK_STREAM, IPPROTO_TCPIPPROTO_TCP)) == INVALID_SOCKET(-1)) {
1717 | ws_warning("Cannot open system TCP socket: %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1717, __func__, "Cannot open system TCP socket: %s", strerror ((*__errno_location ()))); } } while (0);
1718 | return EXIT_CODE_GENERIC;
1719 | }
1720 |
1721 | ws_debug("Using config: Server TCP Port=%u, Local IP=%s, Local TCP Port=%u",do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1722, __func__, "Using config: Server TCP Port=%u, Local IP=%s, Local TCP Port=%u" , *bt_server_tcp_port, bt_local_ip, *bt_local_tcp_port); } } while (0)
1722 | *bt_server_tcp_port, bt_local_ip, *bt_local_tcp_port)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1722, __func__, "Using config: Server TCP Port=%u, Local IP=%s, Local TCP Port=%u" , *bt_server_tcp_port, bt_local_ip, *bt_local_tcp_port); } } while (0);
1723 |
1724 | if (*bt_local_tcp_port != 0) {
1725 | int result;
1726 |
1727 | result = adb_forward(serial_number, adb_server_ip, adb_server_tcp_port, *bt_local_tcp_port, *bt_server_tcp_port);
1728 | ws_debug("DO: adb forward tcp:%u (local) tcp:%u (remote) result=%i",do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1729, __func__, "DO: adb forward tcp:%u (local) tcp:%u (remote) result=%i" , *bt_local_tcp_port, *bt_server_tcp_port, result); } } while (0)
1729 | *bt_local_tcp_port, *bt_server_tcp_port, result)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1729, __func__, "DO: adb forward tcp:%u (local) tcp:%u (remote) result=%i" , *bt_local_tcp_port, *bt_server_tcp_port, result); } } while (0);
1730 | }
1731 |
1732 | memset(&server, 0 , sizeof(server));
1733 | server.sin_family = AF_INET2;
1734 | server.sin_port = GINT16_TO_BE(*bt_local_tcp_port)((gint16) (((guint16) ( (guint16) ((guint16) (*bt_local_tcp_port ) >> 8) | (guint16) ((guint16) (*bt_local_tcp_port) << 8)))));
1735 | ws_inet_pton4(bt_local_ip, (ws_in4_addr *)&(server.sin_addr.s_addr));
1736 |
1737 | useSndTimeout(sock);
1738 |
1739 | if (connect(sock, (struct sockaddr *) &server, sizeof(server)) == SOCKET_ERROR(-1)) {
1740 | ws_warning("<%s> Please check that adb daemon is running.", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1740, __func__, "<%s> Please check that adb daemon is running." , strerror((*__errno_location ()))); } } while (0);
1741 | closesocket(sock)close(sock);
1742 | return EXIT_CODE_GENERIC;
1743 | }
1744 |
1745 | slen = (socklen_t)sizeof(client);
1746 | if (getsockname(sock, (struct sockaddr *) &client, &slen)) {
1747 | ws_warning("getsockname: %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1747, __func__, "getsockname: %s", strerror((*__errno_location ()))); } } while (0);
1748 | closesocket(sock)close(sock);
1749 | return EXIT_CODE_GENERIC;
1750 | }
1751 |
1752 | if (slen != sizeof(client)) {
1753 | ws_warning("incorrect length")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1753, __func__, "incorrect length"); } } while (0);
1754 | closesocket(sock)close(sock);
1755 | return EXIT_CODE_GENERIC;
1756 | }
1757 |
1758 | ws_debug("Client port %u", GUINT16_FROM_BE(client.sin_port))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1758, __func__, "Client port %u", (((((guint16) ( (guint16) ((guint16) (client.sin_port) >> 8) | (guint16) ((guint16 ) (client.sin_port) << 8))))))); } } while (0);
1759 | } else {
1760 | int result;
1761 |
1762 | sock = adb_connect_transport(adb_server_ip, adb_server_tcp_port, serial_number);
1763 | if (sock == INVALID_SOCKET(-1))
1764 | return EXIT_CODE_INVALID_SOCKET_6;
1765 |
1766 | result = snprintf((char *) buffer, PACKET_LENGTH65535, adb_tcp_bluedroid_external_parser_template, *bt_server_tcp_port);
1767 | if (result <= 0 || result > PACKET_LENGTH65535) {
1768 | ws_warning("Error while completing adb packet")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1768, __func__, "Error while completing adb packet"); } } while (0);
1769 | closesocket(sock)close(sock);
1770 | return EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_14;
1771 | }
1772 |
1773 | result = adb_send(sock, buffer);
1774 | if (result) {
1775 | ws_warning("Error while forwarding adb port")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1775, __func__, "Error while forwarding adb port"); } } while (0);
1776 | closesocket(sock)close(sock);
1777 | return EXIT_CODE_GENERIC;
1778 | }
1779 | }
1780 |
1781 | while (endless_loop) {
1782 | errno(*__errno_location ()) = 0;
1783 | length = recv(sock, buffer + used_buffer_length, (int)(PACKET_LENGTH65535 - used_buffer_length), 0);
1784 | CONTINUE_ON_TIMEOUT(length)if ((*__errno_location ()) == 11) continue;
1785 | else if (errno(*__errno_location ()) != 0) {
1786 | ws_warning("ERROR capture: %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1786, __func__, "ERROR capture: %s", strerror((*__errno_location ()))); } } while (0);
1787 | closesocket(sock)close(sock);
1788 | return EXIT_CODE_GENERIC;
1789 | }
1790 |
1791 | if (length <= 0) {
1792 | if (bt_forward_socket) {
1793 | /* NOTE: Workaround... It seems that Bluedroid is slower and we can connect to socket that are not really ready... */
1794 | ws_warning("Broken socket connection. Try reconnect.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1794, __func__, "Broken socket connection. Try reconnect.") ; } } while (0);
1795 | closesocket(sock)close(sock);
1796 |
1797 | if ((sock = socket(AF_INET2, SOCK_STREAMSOCK_STREAM, IPPROTO_TCPIPPROTO_TCP)) == INVALID_SOCKET(-1)) {
1798 | ws_warning("%s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1798, __func__, "%s", strerror((*__errno_location ()))); } } while (0);
1799 | return EXIT_CODE_GENERIC;
1800 | }
1801 |
1802 | server.sin_family = AF_INET2;
1803 | server.sin_port = GINT16_TO_BE(*bt_local_tcp_port)((gint16) (((guint16) ( (guint16) ((guint16) (*bt_local_tcp_port ) >> 8) | (guint16) ((guint16) (*bt_local_tcp_port) << 8)))));
1804 | ws_inet_pton4(bt_local_ip, (ws_in4_addr *)&(server.sin_addr.s_addr));
1805 |
1806 | useSndTimeout(sock);
1807 |
1808 | if (connect(sock, (struct sockaddr *) &server, sizeof(server)) == SOCKET_ERROR(-1)) {
1809 | ws_warning("ERROR reconnect: <%s> Please check that adb daemon is running.", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1809, __func__, "ERROR reconnect: <%s> Please check that adb daemon is running." , strerror((*__errno_location ()))); } } while (0);
1810 | closesocket(sock)close(sock);
1811 | return EXIT_CODE_GENERIC;
1812 | }
1813 | } else {
1814 | ws_warning("Broken socket connection.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1814, __func__, "Broken socket connection."); } } while (0);
1815 | closesocket(sock)close(sock);
1816 | return EXIT_CODE_GENERIC;
1817 | }
1818 |
1819 | continue;
1820 | }
1821 |
1822 | used_buffer_length += length;
1823 |
1824 | ws_debug("Received: length=%"PRIdMAX, (intmax_t)length)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1824, __func__, "Received: length=%""l" "d", (intmax_t)length ); } } while (0);
1825 |
1826 | while (((payload[BLUEDROID_H4_PACKET_TYPE0] == BLUEDROID_H4_PACKET_TYPE_HCI_CMD0x01 || payload[BLUEDROID_H4_PACKET_TYPE0] == BLUEDROID_H4_PACKET_TYPE_SCO0x03) &&
1827 | used_buffer_length >= BLUEDROID_TIMESTAMP_SIZE8 + BLUEDROID_H4_SIZE1 + 2 + 1 &&
1828 | BLUEDROID_TIMESTAMP_SIZE8 + BLUEDROID_H4_SIZE1 + 2 + payload[BLUEDROID_H4_SIZE1 + 2] + 1 <= used_buffer_length) ||
1829 | (payload[BLUEDROID_H4_PACKET_TYPE0] == BLUEDROID_H4_PACKET_TYPE_ACL0x02 &&
1830 | used_buffer_length >= BLUEDROID_TIMESTAMP_SIZE8 + BLUEDROID_H4_SIZE1 + 2 + 2 &&
1831 | BLUEDROID_TIMESTAMP_SIZE8 + BLUEDROID_H4_SIZE1 + 2 + payload[BLUEDROID_H4_SIZE1 + 2] + (payload[BLUEDROID_H4_SIZE1 + 2 + 1] << 8) + 2 <= used_buffer_length) ||
1832 | (payload[BLUEDROID_H4_PACKET_TYPE0] == BLUEDROID_H4_PACKET_TYPE_SCO0x03 &&
1833 | used_buffer_length >= BLUEDROID_TIMESTAMP_SIZE8 + BLUEDROID_H4_SIZE1 + 2 + 1 &&
1834 | BLUEDROID_TIMESTAMP_SIZE8 + BLUEDROID_H4_SIZE1 + 2 + payload[BLUEDROID_H4_SIZE1 + 2] + 1 <= used_buffer_length) ||
1835 | (payload[BLUEDROID_H4_PACKET_TYPE0] == BLUEDROID_H4_PACKET_TYPE_HCI_EVT0x04 &&
1836 | used_buffer_length >= BLUEDROID_TIMESTAMP_SIZE8 + BLUEDROID_H4_SIZE1 + 1 + 1 &&
1837 | BLUEDROID_TIMESTAMP_SIZE8 + BLUEDROID_H4_SIZE1 + 1 + payload[BLUEDROID_H4_SIZE1 + 1] + 1 <= used_buffer_length)) {
1838 |
1839 | ts = GINT64_FROM_BE(*timestamp)(((gint64) (((guint64) ( (((guint64) (*timestamp) & (guint64 ) (0x00000000000000ffUL)) << 56) | (((guint64) (*timestamp ) & (guint64) (0x000000000000ff00UL)) << 40) | (((guint64 ) (*timestamp) & (guint64) (0x0000000000ff0000UL)) << 24) | (((guint64) (*timestamp) & (guint64) (0x00000000ff000000UL )) << 8) | (((guint64) (*timestamp) & (guint64) (0x000000ff00000000UL )) >> 8) | (((guint64) (*timestamp) & (guint64) (0x0000ff0000000000UL )) >> 24) | (((guint64) (*timestamp) & (guint64) (0x00ff000000000000UL )) >> 40) | (((guint64) (*timestamp) & (guint64) (0xff00000000000000UL )) >> 56))))));
1840 |
1841 | switch (payload[BLUEDROID_H4_PACKET_TYPE0]) {
1842 | case BLUEDROID_H4_PACKET_TYPE_HCI_CMD0x01:
1843 | h4_header->direction = GINT32_TO_BE(BLUEDROID_DIRECTION_SENT)((gint32) (((guint32) ( (((guint32) (0) & (guint32) 0x000000ffU ) << 24) | (((guint32) (0) & (guint32) 0x0000ff00U) << 8) | (((guint32) (0) & (guint32) 0x00ff0000U) >> 8) | (((guint32) (0) & (guint32) 0xff000000U) >> 24 )))));
1844 |
1845 | captured_length = (unsigned int)sizeof(own_pcap_bluetooth_h4_header) + payload[3] + 4;
1846 |
1847 | length = sizeof(own_pcap_bluetooth_h4_header) + BLUEDROID_H4_SIZE1 + 2 + 1 + payload[3];
1848 |
1849 | break;
1850 | case BLUEDROID_H4_PACKET_TYPE_ACL0x02:
1851 | h4_header->direction = (payload[2] & 0x80) ? GINT32_TO_BE(BLUEDROID_DIRECTION_RECV)((gint32) (((guint32) ( (((guint32) (1) & (guint32) 0x000000ffU ) << 24) | (((guint32) (1) & (guint32) 0x0000ff00U) << 8) | (((guint32) (1) & (guint32) 0x00ff0000U) >> 8) | (((guint32) (1) & (guint32) 0xff000000U) >> 24 ))))) : GINT32_TO_BE(BLUEDROID_DIRECTION_SENT)((gint32) (((guint32) ( (((guint32) (0) & (guint32) 0x000000ffU ) << 24) | (((guint32) (0) & (guint32) 0x0000ff00U) << 8) | (((guint32) (0) & (guint32) 0x00ff0000U) >> 8) | (((guint32) (0) & (guint32) 0xff000000U) >> 24 )))));
1852 |
1853 | captured_length = (unsigned int)sizeof(own_pcap_bluetooth_h4_header) + payload[3] + (payload[3 + 1] << 8) + 5;
1854 |
1855 | length = sizeof(own_pcap_bluetooth_h4_header) + BLUEDROID_H4_SIZE1 + 2 + 2 + payload[3] + (ssize_t)(payload[3 + 1] << 8);
1856 |
1857 | break;
1858 | case BLUEDROID_H4_PACKET_TYPE_SCO0x03:
1859 | h4_header->direction = (payload[2] & 0x80) ? GINT32_TO_BE(BLUEDROID_DIRECTION_RECV)((gint32) (((guint32) ( (((guint32) (1) & (guint32) 0x000000ffU ) << 24) | (((guint32) (1) & (guint32) 0x0000ff00U) << 8) | (((guint32) (1) & (guint32) 0x00ff0000U) >> 8) | (((guint32) (1) & (guint32) 0xff000000U) >> 24 ))))) : GINT32_TO_BE(BLUEDROID_DIRECTION_SENT)((gint32) (((guint32) ( (((guint32) (0) & (guint32) 0x000000ffU ) << 24) | (((guint32) (0) & (guint32) 0x0000ff00U) << 8) | (((guint32) (0) & (guint32) 0x00ff0000U) >> 8) | (((guint32) (0) & (guint32) 0xff000000U) >> 24 )))));
1860 |
1861 | captured_length = (unsigned int)sizeof(own_pcap_bluetooth_h4_header) + payload[3] + 4;
1862 |
1863 | length = sizeof(own_pcap_bluetooth_h4_header) + BLUEDROID_H4_SIZE1 + 2 + 1 + payload[3];
1864 |
1865 | break;
1866 | case BLUEDROID_H4_PACKET_TYPE_HCI_EVT0x04:
1867 | h4_header->direction = GINT32_TO_BE(BLUEDROID_DIRECTION_RECV)((gint32) (((guint32) ( (((guint32) (1) & (guint32) 0x000000ffU ) << 24) | (((guint32) (1) & (guint32) 0x0000ff00U) << 8) | (((guint32) (1) & (guint32) 0x00ff0000U) >> 8) | (((guint32) (1) & (guint32) 0xff000000U) >> 24 )))));
1868 |
1869 | captured_length = (unsigned int)sizeof(own_pcap_bluetooth_h4_header) + payload[2] + 3;
1870 |
1871 | length = sizeof(own_pcap_bluetooth_h4_header) + BLUEDROID_H4_SIZE1 + 1 + 1 + payload[2];
1872 |
1873 | break;
1874 | default:
1875 | ws_warning("Invalid stream")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1875, __func__, "Invalid stream"); } } while (0);
1876 | closesocket(sock)close(sock);
1877 | return EXIT_CODE_GENERIC;
1878 | }
1879 |
1880 | ws_debug("\t Packet %u: used_buffer_length=%"PRIdMAX" length=%"PRIdMAX" captured_length=%i type=0x%02x", id, (intmax_t)used_buffer_length, (intmax_t)length, captured_length, payload[BLUEDROID_H4_PACKET_TYPE])do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1880, __func__, "\t Packet %u: used_buffer_length=%""l" "d" " length=%""l" "d"" captured_length=%i type=0x%02x", id, (intmax_t )used_buffer_length, (intmax_t)length, captured_length, payload [0]); } } while (0);
1881 | if (payload[BLUEDROID_H4_PACKET_TYPE0] == BLUEDROID_H4_PACKET_TYPE_HCI_EVT0x04)
1882 | ws_debug("\t Packet: %02x %02x %02x", (unsigned int) payload[0], (unsigned int) payload[1], (unsigned int)payload[2])do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1882, __func__, "\t Packet: %02x %02x %02x", (unsigned int) payload[0], (unsigned int) payload[1], (unsigned int)payload [2]); } } while (0);
1883 | id +=1;
1884 |
1885 | ts -= BLUEDROID_TIMESTAMP_BASE;
1886 |
1887 | endless_loop = extcap_dumper_dump(extcap_dumper, fifo, packet,
1888 | captured_length,
1889 | captured_length,
1890 | (uint32_t)(ts / 1000000),
1891 | ((uint32_t)(ts % 1000000)) * 1000);
1892 |
1893 | used_buffer_length -= length - sizeof(own_pcap_bluetooth_h4_header) + BLUEDROID_TIMESTAMP_SIZE8;
1894 | if (used_buffer_length < 0) {
1895 | ws_warning("Internal Negative used buffer length.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1895, __func__, "Internal Negative used buffer length."); } } while (0);
1896 | closesocket(sock)close(sock);
1897 | return EXIT_CODE_GENERIC;
1898 | }
1899 | memmove(buffer, packet + length, used_buffer_length);
1900 | }
1901 | }
1902 |
1903 | closesocket(sock)close(sock);
1904 | return EXIT_CODE_SUCCESS;
1905 | }
1906 |
1907 | /*----------------------------------------------------------------------------*/
1908 | /* Android Btsnoop Net */
1909 | /*----------------------------------------------------------------------------*/
1910 |
1911 | static int capture_android_bluetooth_btsnoop_net(char *interface, char *fifo,
1912 | const char *adb_server_ip, unsigned short *adb_server_tcp_port) {
1913 | struct extcap_dumper extcap_dumper;
1914 | static char packet[PACKET_LENGTH65535];
1915 | ssize_t length;
1916 | ssize_t used_buffer_length = 0;
1917 | socket_handle_tint sock;
1918 | const char *adb_tcp_btsnoop_net = "tcp:8872";
1919 | int result;
1920 | char *serial_number;
1921 | uint64_t ts;
1922 | static const uint64_t BTSNOOP_TIMESTAMP_BASE = UINT64_C(0x00dcddb30f2f8000)0x00dcddb30f2f8000UL;
1923 | uint32_t *reported_length;
1924 | uint32_t *captured_length;
1925 | uint32_t *flags;
1926 | /* uint32_t *cumulative_dropped_packets; */
1927 | uint64_t *timestamp;
1928 | char *payload = packet + sizeof(own_pcap_bluetooth_h4_header) + 24;
1929 | own_pcap_bluetooth_h4_header *h4_header;
1930 |
1931 | SET_DATA(reported_length, value_u32, packet + sizeof(own_pcap_bluetooth_h4_header) + 0){ data_aligned_t data_aligned; data_aligned.value_char = packet + sizeof(own_pcap_bluetooth_h4_header) + 0; reported_length = data_aligned.value_u32; };
1932 | SET_DATA(captured_length, value_u32, packet + sizeof(own_pcap_bluetooth_h4_header) + 4){ data_aligned_t data_aligned; data_aligned.value_char = packet + sizeof(own_pcap_bluetooth_h4_header) + 4; captured_length = data_aligned.value_u32; };
1933 | SET_DATA(flags, value_u32, packet + sizeof(own_pcap_bluetooth_h4_header) + 8){ data_aligned_t data_aligned; data_aligned.value_char = packet + sizeof(own_pcap_bluetooth_h4_header) + 8; flags = data_aligned .value_u32; };
1934 | /* SET_DATA(cumulative_dropped_packets, value_u32, packet + sizeof(own_pcap_bluetooth_h4_header) + 12); */
1935 | SET_DATA(timestamp, value_u64, packet + sizeof(own_pcap_bluetooth_h4_header) + 16){ data_aligned_t data_aligned; data_aligned.value_char = packet + sizeof(own_pcap_bluetooth_h4_header) + 16; timestamp = data_aligned .value_u64; };
1936 | SET_DATA(h4_header, value_own_pcap_bluetooth_h4_header, payload - sizeof(own_pcap_bluetooth_h4_header)){ data_aligned_t data_aligned; data_aligned.value_char = payload - sizeof(own_pcap_bluetooth_h4_header); h4_header = data_aligned .value_own_pcap_bluetooth_h4_header; };
1937 |
1938 | extcap_dumper = extcap_dumper_open(fifo, EXTCAP_ENCAP_BLUETOOTH_H4_WITH_PHDR99);
1939 | serial_number = get_serial_from_interface(interface);
1940 | sock = adb_connect_transport(adb_server_ip, adb_server_tcp_port, serial_number);
1941 | if (sock == INVALID_SOCKET(-1))
1942 | return EXIT_CODE_INVALID_SOCKET_7;
1943 |
1944 | result = adb_send(sock, adb_tcp_btsnoop_net);
1945 | if (result) {
1946 | ws_warning("Error while sending command <%s>", adb_tcp_btsnoop_net)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1946, __func__, "Error while sending command <%s>", adb_tcp_btsnoop_net ); } } while (0);
1947 | closesocket(sock)close(sock);
1948 | return EXIT_CODE_ERROR_WHILE_SENDING_ADB_PACKET_2;
1949 | }
1950 |
1951 | /* Read "btsnoop" file header - 16 bytes */
1952 | while (used_buffer_length < BTSNOOP_HDR_LEN16) {
1953 | length = recv(sock, packet + used_buffer_length, (int)(BTSNOOP_HDR_LEN16 - used_buffer_length), 0);
1954 | if (length <= 0) {
1955 | ws_warning("Broken socket connection.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1955, __func__, "Broken socket connection."); } } while (0);
1956 | closesocket(sock)close(sock);
1957 | return EXIT_CODE_GENERIC;
1958 | }
1959 | used_buffer_length += length;
1960 | }
1961 | used_buffer_length = 0;
1962 |
1963 | while (endless_loop) {
1964 | errno(*__errno_location ()) = 0;
1965 | length = recv(sock, packet + used_buffer_length + sizeof(own_pcap_bluetooth_h4_header),
1966 | (int)(PACKET_LENGTH65535 - sizeof(own_pcap_bluetooth_h4_header) - used_buffer_length), 0);
1967 | CONTINUE_ON_TIMEOUT(length)if ((*__errno_location ()) == 11) continue;
1968 | else if (errno(*__errno_location ()) != 0) {
1969 | ws_warning("ERROR capture: %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1969, __func__, "ERROR capture: %s", strerror((*__errno_location ()))); } } while (0);
1970 | closesocket(sock)close(sock);
1971 | return EXIT_CODE_GENERIC;
1972 | }
1973 |
1974 | if (length <= 0) {
1975 | ws_warning("Broken socket connection.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1975, __func__, "Broken socket connection."); } } while (0);
1976 | closesocket(sock)close(sock);
1977 | return EXIT_CODE_GENERIC;
1978 | }
1979 |
1980 | used_buffer_length += length;
1981 |
1982 | while (used_buffer_length >= 24) {
1983 | /* We have the next record header. */
1984 | uint32_t record_reported_length = GUINT32_FROM_BE(*reported_length)(((((guint32) ( (((guint32) (*reported_length) & (guint32 ) 0x000000ffU) << 24) | (((guint32) (*reported_length) & (guint32) 0x0000ff00U) << 8) | (((guint32) (*reported_length ) & (guint32) 0x00ff0000U) >> 8) | (((guint32) (*reported_length ) & (guint32) 0xff000000U) >> 24))))));
1985 | uint32_t record_captured_length = GUINT32_FROM_BE(*captured_length)(((((guint32) ( (((guint32) (*captured_length) & (guint32 ) 0x000000ffU) << 24) | (((guint32) (*captured_length) & (guint32) 0x0000ff00U) << 8) | (((guint32) (*captured_length ) & (guint32) 0x00ff0000U) >> 8) | (((guint32) (*captured_length ) & (guint32) 0xff000000U) >> 24))))));
1986 | int32_t direction;
1987 |
1988 | /* Check that the captured length fits in our allocated packet buf,
1989 | * and that the reported length is at least as long as the captured
1990 | * length and won't overflow. */
1991 | if (record_captured_length > PACKET_LENGTH65535 - sizeof(own_pcap_bluetooth_h4_header) - 24 ||
1992 | record_reported_length < record_captured_length ||
1993 | record_reported_length > UINT32_MAX(4294967295U) - sizeof(own_pcap_bluetooth_h4_header)) {
1994 | ws_warning("Invalid btsnoop packet length.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1994, __func__, "Invalid btsnoop packet length."); } } while (0);
1995 | closesocket(sock)close(sock);
1996 | return EXIT_CODE_GENERIC;
1997 | }
1998 |
1999 | /* Check if we have the entire record. */
2000 | if ((size_t)used_buffer_length < 24 + record_captured_length)
2001 | break;
2002 |
2003 | ts = GINT64_FROM_BE(*timestamp)(((gint64) (((guint64) ( (((guint64) (*timestamp) & (guint64 ) (0x00000000000000ffUL)) << 56) | (((guint64) (*timestamp ) & (guint64) (0x000000000000ff00UL)) << 40) | (((guint64 ) (*timestamp) & (guint64) (0x0000000000ff0000UL)) << 24) | (((guint64) (*timestamp) & (guint64) (0x00000000ff000000UL )) << 8) | (((guint64) (*timestamp) & (guint64) (0x000000ff00000000UL )) >> 8) | (((guint64) (*timestamp) & (guint64) (0x0000ff0000000000UL )) >> 24) | (((guint64) (*timestamp) & (guint64) (0x00ff000000000000UL )) >> 40) | (((guint64) (*timestamp) & (guint64) (0xff00000000000000UL )) >> 56))))));
2004 | ts -= BTSNOOP_TIMESTAMP_BASE;
2005 |
2006 | direction = GINT32_FROM_BE(*flags)(((gint32) (((guint32) ( (((guint32) (*flags) & (guint32) 0x000000ffU) << 24) | (((guint32) (*flags) & (guint32 ) 0x0000ff00U) << 8) | (((guint32) (*flags) & (guint32 ) 0x00ff0000U) >> 8) | (((guint32) (*flags) & (guint32 ) 0xff000000U) >> 24)))))) & 0x01;
2007 | h4_header->direction = GINT32_TO_BE(direction)((gint32) (((guint32) ( (((guint32) (direction) & (guint32 ) 0x000000ffU) << 24) | (((guint32) (direction) & ( guint32) 0x0000ff00U) << 8) | (((guint32) (direction) & (guint32) 0x00ff0000U) >> 8) | (((guint32) (direction) & (guint32) 0xff000000U) >> 24)))));
2008 |
2009 | endless_loop = extcap_dumper_dump(extcap_dumper, fifo,
2010 | payload - sizeof(own_pcap_bluetooth_h4_header),
2011 | (ssize_t)(record_captured_length + sizeof(own_pcap_bluetooth_h4_header)),
2012 | (ssize_t)(record_reported_length + sizeof(own_pcap_bluetooth_h4_header)),
2013 | (uint32_t)(ts / 1000000),
2014 | ((uint32_t)(ts % 1000000)) * 1000);
2015 |
2016 | used_buffer_length -= 24 + record_captured_length;
2017 | if (used_buffer_length < 0) {
2018 | ws_warning("Internal Negative used buffer length.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2018, __func__, "Internal Negative used buffer length."); } } while (0);
2019 | closesocket(sock)close(sock);
2020 | return EXIT_CODE_GENERIC;
2021 | }
2022 |
2023 | if (used_buffer_length > 0)
2024 | memmove(packet + sizeof(own_pcap_bluetooth_h4_header), payload + record_captured_length, used_buffer_length);
2025 | }
2026 | }
2027 |
2028 | closesocket(sock)close(sock);
2029 | return EXIT_CODE_SUCCESS;
2030 | }
2031 |
2032 | /*----------------------------------------------------------------------------*/
2033 | /* Android Logcat Text*/
2034 | /*----------------------------------------------------------------------------*/
2035 |
2036 |
2037 | static int capture_android_logcat_text(char *interface, char *fifo,
2038 | const char *adb_server_ip, unsigned short *adb_server_tcp_port,
2039 | int logcat_ignore_log_buffer, const char *logcat_custom_parameter) {
2040 | struct extcap_dumper extcap_dumper;
2041 | static char packet[PACKET_LENGTH65535];
2042 | ssize_t length;
2043 | size_t used_buffer_length = 0;
2044 | socket_handle_tint sock;
2045 | const char *protocol_name;
2046 | size_t exported_pdu_headers_size = 0;
2047 | struct exported_pdu_header exported_pdu_header_protocol_normal;
2048 | struct exported_pdu_header *exported_pdu_header_protocol;
2049 | struct exported_pdu_header exported_pdu_header_end = {0, 0};
2050 | static const char *wireshark_protocol_logcat_text = "logcat_text_threadtime";
2051 | const char *adb_logcat_template = "shell:export ANDROID_LOG_TAGS=\"\" ; exec logcat -v threadtime%s%s %s";
2052 | char *serial_number = NULL((void*)0);
2053 | int result;
2054 | char *pos;
2055 | const char *logcat_buffer;
2056 | const char *logcat_log_buffer;
2057 |
2058 | extcap_dumper = extcap_dumper_open(fifo, EXTCAP_ENCAP_WIRESHARK_UPPER_PDU155);
2059 |
2060 | exported_pdu_header_protocol_normal.tag = GUINT16_TO_BE(EXP_PDU_TAG_DISSECTOR_NAME)((((guint16) ( (guint16) ((guint16) (12) >> 8) | (guint16 ) ((guint16) (12) << 8)))));
2061 | exported_pdu_header_protocol_normal.length = GUINT16_TO_BE(strlen(wireshark_protocol_logcat_text) + 2)((((guint16) ( (guint16) ((guint16) (strlen(wireshark_protocol_logcat_text ) + 2) >> 8) | (guint16) ((guint16) (strlen(wireshark_protocol_logcat_text ) + 2) << 8)))));
2062 |
2063 | serial_number = get_serial_from_interface(interface);
2064 | sock = adb_connect_transport(adb_server_ip, adb_server_tcp_port, serial_number);
2065 | if (sock == INVALID_SOCKET(-1))
2066 | return EXIT_CODE_INVALID_SOCKET_8;
2067 |
2068 | if (is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_MAIN"android-logcat-main") || is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_TEXT_MAIN"android-logcat-text-main"))
2069 | logcat_buffer = " -b main";
2070 | else if (is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_SYSTEM"android-logcat-system") || is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_TEXT_SYSTEM"android-logcat-text-system"))
2071 | logcat_buffer = " -b system";
2072 | else if (is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_RADIO"android-logcat-radio") || is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_TEXT_RADIO"android-logcat-text-radio"))
2073 | logcat_buffer = " -b radio";
2074 | else if (is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_EVENTS"android-logcat-events") || is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_TEXT_EVENTS"android-logcat-text-events"))
2075 | logcat_buffer = " -b events";
2076 | else if (is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_TEXT_CRASH"android-logcat-text-crash"))
2077 | logcat_buffer = " -b crash";
2078 | else {
2079 | ws_warning("Unknown interface: <%s>", interface)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2079, __func__, "Unknown interface: <%s>", interface) ; } } while (0);
2080 | closesocket(sock)close(sock);
2081 | return EXIT_CODE_GENERIC;
2082 | }
2083 |
2084 | if (logcat_ignore_log_buffer
29.1 | 'logcat_ignore_log_buffer' is 0
)
30 | ← | Taking false branch | →
2085 | logcat_log_buffer = " -T 1";
2086 | else
2087 | logcat_log_buffer = "";
2088 |
2089 | if (!logcat_custom_parameter
30.1 | 'logcat_custom_parameter' is null
)
31 | ← | Taking true branch | →
2090 | logcat_custom_parameter = "";
2091 |
2092 | result = snprintf((char *) packet, PACKET_LENGTH65535, adb_logcat_template, logcat_buffer, logcat_log_buffer, logcat_custom_parameter);
2093 | if (result <= 0 || result > PACKET_LENGTH65535) {
32 | ← | Assuming 'result' is > 0 | →
33 | ← | Assuming 'result' is <= PACKET_LENGTH | →
34 | ← | Taking false branch | →
2094 | ws_warning("Error while completing adb packet")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2094, __func__, "Error while completing adb packet"); } } while (0);
2095 | closesocket(sock)close(sock);
2096 | return EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_17;
2097 | }
2098 |
2099 | result = adb_send(sock, packet);
2100 | if (result) {
35 | ← | Assuming 'result' is 0 | →
36 | ← | Taking false branch | →
2101 | ws_warning("Error while sending command <%s>", packet)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2101, __func__, "Error while sending command <%s>", packet ); } } while (0);
2102 | closesocket(sock)close(sock);
2103 | return EXIT_CODE_ERROR_WHILE_SENDING_ADB_PACKET_3;
2104 | }
2105 |
2106 | protocol_name = wireshark_protocol_logcat_text;
2107 | exported_pdu_header_protocol = &exported_pdu_header_protocol_normal;
2108 |
2109 | memcpy(packet, exported_pdu_header_protocol, sizeof(struct exported_pdu_header));
2110 | exported_pdu_headers_size += sizeof(struct exported_pdu_header);
2111 |
2112 | memcpy(packet + exported_pdu_headers_size, protocol_name, GUINT16_FROM_BE(exported_pdu_header_protocol->length)(((((guint16) ( (guint16) ((guint16) (exported_pdu_header_protocol ->length) >> 8) | (guint16) ((guint16) (exported_pdu_header_protocol ->length) << 8)))))) - 2);
2113 | exported_pdu_headers_size += GUINT16_FROM_BE(exported_pdu_header_protocol->length)(((((guint16) ( (guint16) ((guint16) (exported_pdu_header_protocol ->length) >> 8) | (guint16) ((guint16) (exported_pdu_header_protocol ->length) << 8))))));
2114 |
2115 | packet[exported_pdu_headers_size - 1] = 0;
2116 | packet[exported_pdu_headers_size - 2] = 0;
2117 |
2118 | memcpy(packet + exported_pdu_headers_size, &exported_pdu_header_end, sizeof(struct exported_pdu_header));
2119 | exported_pdu_headers_size += sizeof(struct exported_pdu_header) + GUINT16_FROM_BE(exported_pdu_header_end.length)(((((guint16) ( (guint16) ((guint16) (exported_pdu_header_end .length) >> 8) | (guint16) ((guint16) (exported_pdu_header_end .length) << 8))))));
2120 |
2121 | used_buffer_length = 0;
2122 | while (endless_loop) {
37 | ← | Loop condition is true. Entering loop body | →
2123 | errno(*__errno_location ()) = 0;
2124 | length = recv(sock, packet + exported_pdu_headers_size + used_buffer_length, (int)(PACKET_LENGTH65535 - exported_pdu_headers_size - used_buffer_length), 0);
38 | ← | Assuming that 'recv' is successful; 'errno' becomes undefined after the call | →
2125 | CONTINUE_ON_TIMEOUT(length)if ((*__errno_location ()) == 11) continue;
39 | ← | An undefined value may be read from 'errno'
2126 | else if (errno(*__errno_location ()) != 0) {
2127 | ws_warning("ERROR capture: %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2127, __func__, "ERROR capture: %s", strerror((*__errno_location ()))); } } while (0);
2128 | closesocket(sock)close(sock);
2129 | return EXIT_CODE_GENERIC;
2130 | }
2131 |
2132 | if (length <= 0) {
2133 | ws_warning("Broken socket connection. Try reconnect.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2133, __func__, "Broken socket connection. Try reconnect.") ; } } while (0);
2134 | closesocket(sock)close(sock);
2135 | return EXIT_CODE_GENERIC;
2136 | }
2137 |
2138 | used_buffer_length += length;
2139 |
2140 | while (used_buffer_length > 0 && (pos = (char *) memchr(packet + exported_pdu_headers_size, '\n', used_buffer_length))) {
2141 | int ms;
2142 | struct tm* date;
2143 | time_t seconds;
2144 | time_t secs = 0;
2145 | int nsecs = 0;
2146 | time_t t;
2147 |
2148 | length = (ssize_t)(pos - packet) + 1;
2149 |
2150 | t = time(NULL((void*)0));
2151 | date = localtime(&t);
2152 | if (!date)
2153 | continue;
2154 | if (6 == sscanf(packet + exported_pdu_headers_size, "%d-%d %d:%d:%d.%d", &date->tm_mon, &date->tm_mday, &date->tm_hour,
2155 | &date->tm_min, &date->tm_sec, &ms)) {
2156 | date->tm_mon -= 1;
2157 | date->tm_isdst = -1;
2158 | seconds = mktime(date);
2159 | secs = (time_t) seconds;
2160 | nsecs = (int) (ms * 1e6);
2161 | }
2162 |
2163 | endless_loop = extcap_dumper_dump(extcap_dumper, fifo, packet,
2164 | length,
2165 | length,
2166 | secs, nsecs);
2167 |
2168 | memmove(packet + exported_pdu_headers_size, packet + length, used_buffer_length + exported_pdu_headers_size - length);
2169 | used_buffer_length -= length - exported_pdu_headers_size;
2170 | }
2171 | }
2172 |
2173 | closesocket(sock)close(sock);
2174 | return EXIT_CODE_SUCCESS;
2175 | }
2176 |
2177 | /*----------------------------------------------------------------------------*/
2178 | /* Android Logger / Logcat */
2179 | /*----------------------------------------------------------------------------*/
2180 |
2181 | static int capture_android_logcat(char *interface, char *fifo,
2182 | const char *adb_server_ip, unsigned short *adb_server_tcp_port) {
2183 | struct extcap_dumper extcap_dumper;
2184 | static char packet[PACKET_LENGTH65535];
2185 | ssize_t length;
2186 | size_t used_buffer_length = 0;
2187 | socket_handle_tint sock;
2188 | const char *protocol_name;
2189 | size_t exported_pdu_headers_size = 0;
2190 | struct exported_pdu_header exported_pdu_header_protocol_events;
2191 | struct exported_pdu_header exported_pdu_header_protocol_normal;
2192 | struct exported_pdu_header *exported_pdu_header_protocol;
2193 | struct exported_pdu_header exported_pdu_header_end = {0, 0};
2194 | static const char *wireshark_protocol_logcat = "logcat";
2195 | static const char *wireshark_protocol_logcat_events = "logcat_events";
2196 | const char *adb_command;
2197 | uint16_t *payload_length;
2198 | uint16_t *try_header_size;
2199 | uint32_t *timestamp_secs;
2200 | uint32_t *timestamp_nsecs;
2201 | uint16_t header_size;
2202 | int result;
2203 | char *serial_number = NULL((void*)0);
2204 |
2205 | extcap_dumper = extcap_dumper_open(fifo, EXTCAP_ENCAP_WIRESHARK_UPPER_PDU155);
2206 |
2207 | exported_pdu_header_protocol_events.tag = GUINT16_TO_BE(EXP_PDU_TAG_DISSECTOR_NAME)((((guint16) ( (guint16) ((guint16) (12) >> 8) | (guint16 ) ((guint16) (12) << 8)))));
2208 | exported_pdu_header_protocol_events.length = GUINT16_TO_BE(strlen(wireshark_protocol_logcat_events) + 2)((((guint16) ( (guint16) ((guint16) (strlen(wireshark_protocol_logcat_events ) + 2) >> 8) | (guint16) ((guint16) (strlen(wireshark_protocol_logcat_events ) + 2) << 8)))));
2209 |
2210 | exported_pdu_header_protocol_normal.tag = GUINT16_TO_BE(EXP_PDU_TAG_DISSECTOR_NAME)((((guint16) ( (guint16) ((guint16) (12) >> 8) | (guint16 ) ((guint16) (12) << 8)))));
2211 | exported_pdu_header_protocol_normal.length = GUINT16_TO_BE(strlen(wireshark_protocol_logcat) + 2)((((guint16) ( (guint16) ((guint16) (strlen(wireshark_protocol_logcat ) + 2) >> 8) | (guint16) ((guint16) (strlen(wireshark_protocol_logcat ) + 2) << 8)))));
2212 |
2213 | serial_number = get_serial_from_interface(interface);
2214 | sock = adb_connect_transport(adb_server_ip, adb_server_tcp_port, serial_number);
2215 | if (sock == INVALID_SOCKET(-1))
2216 | return EXIT_CODE_INVALID_SOCKET_9;
2217 |
2218 | adb_command = interface_to_logbuf(interface);
2219 | if (!adb_command) {
2220 | ws_warning("Unknown interface: <%s>", interface)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2220, __func__, "Unknown interface: <%s>", interface) ; } } while (0);
2221 | closesocket(sock)close(sock);
2222 | return EXIT_CODE_GENERIC;
2223 | }
2224 |
2225 | result = adb_send(sock, adb_command);
2226 | if (result) {
2227 | ws_warning("Error while sending command <%s>", adb_command)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2227, __func__, "Error while sending command <%s>", adb_command ); } } while (0);
2228 | closesocket(sock)close(sock);
2229 | return EXIT_CODE_ERROR_WHILE_SENDING_ADB_PACKET_4;
2230 | }
2231 |
2232 | if (is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_EVENTS"android-logcat-events"))
2233 | {
2234 | protocol_name = wireshark_protocol_logcat_events;
2235 | exported_pdu_header_protocol = &exported_pdu_header_protocol_events;
2236 | } else {
2237 | protocol_name = wireshark_protocol_logcat;
2238 | exported_pdu_header_protocol = &exported_pdu_header_protocol_normal;
2239 | }
2240 |
2241 | memcpy(packet, exported_pdu_header_protocol, sizeof(struct exported_pdu_header));
2242 | exported_pdu_headers_size += sizeof(struct exported_pdu_header);
2243 |
2244 | memcpy(packet + exported_pdu_headers_size, protocol_name, GUINT16_FROM_BE(exported_pdu_header_protocol->length)(((((guint16) ( (guint16) ((guint16) (exported_pdu_header_protocol ->length) >> 8) | (guint16) ((guint16) (exported_pdu_header_protocol ->length) << 8)))))) - 2);
2245 | exported_pdu_headers_size += GUINT16_FROM_BE(exported_pdu_header_protocol->length)(((((guint16) ( (guint16) ((guint16) (exported_pdu_header_protocol ->length) >> 8) | (guint16) ((guint16) (exported_pdu_header_protocol ->length) << 8))))));
2246 |
2247 | packet[exported_pdu_headers_size - 1] = 0;
2248 | packet[exported_pdu_headers_size - 2] = 0;
2249 |
2250 | memcpy(packet + exported_pdu_headers_size, &exported_pdu_header_end, sizeof(struct exported_pdu_header));
2251 | exported_pdu_headers_size += sizeof(struct exported_pdu_header) + GUINT16_FROM_BE(exported_pdu_header_end.length)(((((guint16) ( (guint16) ((guint16) (exported_pdu_header_end .length) >> 8) | (guint16) ((guint16) (exported_pdu_header_end .length) << 8))))));
2252 |
2253 | SET_DATA(payload_length, value_u16, packet + exported_pdu_headers_size + 0){ data_aligned_t data_aligned; data_aligned.value_char = packet + exported_pdu_headers_size + 0; payload_length = data_aligned .value_u16; };
2254 | SET_DATA(try_header_size, value_u16, packet + exported_pdu_headers_size + 2){ data_aligned_t data_aligned; data_aligned.value_char = packet + exported_pdu_headers_size + 2; try_header_size = data_aligned .value_u16; };
2255 | SET_DATA(timestamp_secs, value_u32, packet + exported_pdu_headers_size + 12){ data_aligned_t data_aligned; data_aligned.value_char = packet + exported_pdu_headers_size + 12; timestamp_secs = data_aligned .value_u32; };
2256 | SET_DATA(timestamp_nsecs, value_u32, packet + exported_pdu_headers_size + 16){ data_aligned_t data_aligned; data_aligned.value_char = packet + exported_pdu_headers_size + 16; timestamp_nsecs = data_aligned .value_u32; };
2257 |
2258 | while (endless_loop) {
2259 | errno(*__errno_location ()) = 0;
2260 | length = recv(sock, packet + exported_pdu_headers_size + used_buffer_length, (int)(PACKET_LENGTH65535 - exported_pdu_headers_size - used_buffer_length), 0);
2261 | CONTINUE_ON_TIMEOUT(length)if ((*__errno_location ()) == 11) continue;
2262 | else if (errno(*__errno_location ()) != 0) {
2263 | ws_warning("ERROR capture: %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2263, __func__, "ERROR capture: %s", strerror((*__errno_location ()))); } } while (0);
2264 | closesocket(sock)close(sock);
2265 | return EXIT_CODE_GENERIC;
2266 | }
2267 |
2268 | if (length <= 0) {
2269 | while (endless_loop) {
2270 | ws_warning("Broken socket connection. Try reconnect.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2270, __func__, "Broken socket connection. Try reconnect.") ; } } while (0);
2271 | used_buffer_length = 0;
2272 | closesocket(sock)close(sock);
2273 |
2274 | sock = adb_connect_transport(adb_server_ip, adb_server_tcp_port, serial_number);
2275 | if (sock == INVALID_SOCKET(-1))
2276 | return EXIT_CODE_INVALID_SOCKET_10;
2277 |
2278 | result = adb_send(sock, adb_command);
2279 | if (result) {
2280 | ws_warning("WARNING: Error while sending command <%s>", adb_command)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2280, __func__, "WARNING: Error while sending command <%s>" , adb_command); } } while (0);
2281 | continue;
2282 | }
2283 |
2284 | break;
2285 | }
2286 | }
2287 |
2288 | used_buffer_length += length + exported_pdu_headers_size;
2289 |
2290 | if (*try_header_size != 24)
2291 | header_size = 20;
2292 | else
2293 | header_size = *try_header_size;
2294 |
2295 | length = (*payload_length) + header_size + (ssize_t)exported_pdu_headers_size;
2296 |
2297 | while (used_buffer_length >= exported_pdu_headers_size + header_size && (size_t)length <= used_buffer_length) {
2298 | endless_loop = extcap_dumper_dump(extcap_dumper, fifo, packet,
2299 | length,
2300 | length,
2301 | *timestamp_secs, *timestamp_nsecs);
2302 |
2303 | memmove(packet + exported_pdu_headers_size, packet + length, used_buffer_length - length);
2304 | used_buffer_length -= length;
2305 | used_buffer_length += exported_pdu_headers_size;
2306 |
2307 |
2308 | length = (*payload_length) + header_size + (ssize_t)exported_pdu_headers_size;
2309 |
2310 | if (*try_header_size != 24)
2311 | header_size = 20;
2312 | else
2313 | header_size = *try_header_size;
2314 | }
2315 | used_buffer_length -= exported_pdu_headers_size;
2316 | }
2317 |
2318 | closesocket(sock)close(sock);
2319 |
2320 | return EXIT_CODE_SUCCESS;
2321 | }
2322 |
2323 |
2324 | /*----------------------------------------------------------------------------*/
2325 | /* Android Wifi Tcpdump */
2326 | /* The Tcpdump sends data in pcap format. So for using the extcap_dumper we */
2327 | /* need to unpack the pcap and then send the packet data to the dumper. */
2328 | /*----------------------------------------------------------------------------*/
2329 | static int capture_android_tcpdump(char *interface, char *fifo,
2330 | char *capture_filter, const char *adb_server_ip,
2331 | unsigned short *adb_server_tcp_port) {
2332 | static const char *const adb_shell_tcpdump_format = "exec:tcpdump -U -n -s 0 -u -i %s -w - %s 2>/dev/null";
2333 | static const char *const regex_interface = INTERFACE_ANDROID_TCPDUMP"android-tcpdump" "-(?<iface>.*?)-(?<serial>.*)";
2334 | struct extcap_dumper extcap_dumper;
2335 | static char data[PACKET_LENGTH65535];
2336 | ssize_t length;
2337 | ssize_t used_buffer_length = 0;
2338 | ssize_t frame_length=0;
2339 | socket_handle_tint sock;
2340 | int result;
2341 | char *iface = NULL((void*)0);
2342 | char *serial_number = NULL((void*)0);
2343 | bool_Bool nanosecond_timestamps;
2344 | bool_Bool swap_byte_order;
2345 | pcap_hdr_t *global_header;
2346 | pcaprec_hdr_t p_header;
2347 | GRegex *regex = NULL((void*)0);
2348 | GError *err = NULL((void*)0);
2349 | GMatchInfo *match = NULL((void*)0);
2350 | char *tcpdump_cmd = NULL((void*)0);
2351 | char *quoted_filter = NULL((void*)0);
2352 |
2353 | regex = g_regex_new(regex_interface, G_REGEX_RAW, (GRegexMatchFlags)0, &err);
2354 | if (!regex) {
2355 | ws_warning("Failed to compile regex for tcpdump interface")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2355, __func__, "Failed to compile regex for tcpdump interface" ); } } while (0);
2356 | return EXIT_CODE_GENERIC;
2357 | }
2358 |
2359 | g_regex_match(regex, interface, (GRegexMatchFlags)0, &match);
2360 | if (!g_match_info_matches(match)) {
2361 | ws_warning("Failed to determine iface name and serial number")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2361, __func__, "Failed to determine iface name and serial number" ); } } while (0);
2362 | g_regex_unref(regex);
2363 | return EXIT_CODE_GENERIC;
2364 | }
2365 |
2366 | iface = g_match_info_fetch_named(match, "iface");
2367 | serial_number = g_match_info_fetch_named(match, "serial");
2368 | g_match_info_free(match);
2369 | g_regex_unref(regex);
2370 |
2371 | /* First check for the device if it is connected or not */
2372 | sock = adb_connect_transport(adb_server_ip, adb_server_tcp_port, serial_number);
2373 | g_free(serial_number)(__builtin_object_size ((serial_number), 0) != ((size_t) - 1) ) ? g_free_sized (serial_number, __builtin_object_size ((serial_number ), 0)) : (g_free) (serial_number);
2374 | if (sock == INVALID_SOCKET(-1)) {
2375 | g_free(iface)(__builtin_object_size ((iface), 0) != ((size_t) - 1)) ? g_free_sized (iface, __builtin_object_size ((iface), 0)) : (g_free) (iface );
2376 | return EXIT_CODE_INVALID_SOCKET_11;
2377 | }
2378 |
2379 | quoted_filter = g_shell_quote(capture_filter ? capture_filter : "");
2380 | tcpdump_cmd = ws_strdup_printf(adb_shell_tcpdump_format, iface, quoted_filter)wmem_strdup_printf(((void*)0), adb_shell_tcpdump_format, iface , quoted_filter);
2381 | g_free(iface)(__builtin_object_size ((iface), 0) != ((size_t) - 1)) ? g_free_sized (iface, __builtin_object_size ((iface), 0)) : (g_free) (iface );
2382 | g_free(quoted_filter)(__builtin_object_size ((quoted_filter), 0) != ((size_t) - 1) ) ? g_free_sized (quoted_filter, __builtin_object_size ((quoted_filter ), 0)) : (g_free) (quoted_filter);
2383 | result = adb_send(sock, tcpdump_cmd);
2384 | g_free(tcpdump_cmd)(__builtin_object_size ((tcpdump_cmd), 0) != ((size_t) - 1)) ? g_free_sized (tcpdump_cmd, __builtin_object_size ((tcpdump_cmd ), 0)) : (g_free) (tcpdump_cmd);
2385 | if (result) {
2386 | ws_warning("Error while setting adb transport")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2386, __func__, "Error while setting adb transport"); } } while (0);
2387 | closesocket(sock)close(sock);
2388 | return EXIT_CODE_GENERIC;
2389 | }
2390 |
2391 | while (used_buffer_length < PCAP_GLOBAL_HEADER_LENGTH24) {
2392 | errno(*__errno_location ()) = 0;
2393 | length = recv(sock, data + used_buffer_length, (int)(PCAP_GLOBAL_HEADER_LENGTH24 - used_buffer_length), 0);
2394 | CONTINUE_ON_TIMEOUT(length)if ((*__errno_location ()) == 11) continue;
2395 | else if (errno(*__errno_location ()) != 0) {
2396 | ws_warning("ERROR capture: %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2396, __func__, "ERROR capture: %s", strerror((*__errno_location ()))); } } while (0);
2397 | closesocket(sock)close(sock);
2398 | return EXIT_CODE_GENERIC;
2399 | }
2400 |
2401 | if (length <= 0) {
2402 | ws_warning("Broken socket connection.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2402, __func__, "Broken socket connection."); } } while (0);
2403 | closesocket(sock)close(sock);
2404 | return EXIT_CODE_GENERIC;
2405 | }
2406 |
2407 | used_buffer_length += length;
2408 | }
2409 |
2410 | global_header = (pcap_hdr_t*) data;
2411 | switch (global_header->magic_number) {
2412 | case 0xa1b2c3d4:
2413 | swap_byte_order = false0;
2414 | nanosecond_timestamps = false0;
2415 | break;
2416 | case 0xd4c3b2a1:
2417 | swap_byte_order = true1;
2418 | nanosecond_timestamps = false0;
2419 | break;
2420 | case 0xa1b23c4d:
2421 | swap_byte_order = false0;
2422 | nanosecond_timestamps = true1;
2423 | break;
2424 | case 0x4d3cb2a1:
2425 | swap_byte_order = true1;
2426 | nanosecond_timestamps = true1;
2427 | break;
2428 | default:
2429 | ws_warning("Received incorrect magic")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2429, __func__, "Received incorrect magic"); } } while (0);
2430 | closesocket(sock)close(sock);
2431 | return EXIT_CODE_GENERIC;
2432 | }
2433 | int encap = (int)(swap_byte_order ? GUINT32_SWAP_LE_BE(global_header->network)(((guint32) ( (((guint32) (global_header->network) & ( guint32) 0x000000ffU) << 24) | (((guint32) (global_header ->network) & (guint32) 0x0000ff00U) << 8) | (((guint32 ) (global_header->network) & (guint32) 0x00ff0000U) >> 8) | (((guint32) (global_header->network) & (guint32) 0xff000000U) >> 24)))) : global_header->network);
2434 | #ifndef ANDROIDDUMP_USE_LIBPCAP
2435 | encap = wtap_pcap_encap_to_wtap_encap(encap);
2436 | #endif
2437 | extcap_dumper = extcap_dumper_open(fifo, encap);
2438 |
2439 | used_buffer_length = 0;
2440 | while (endless_loop) {
2441 | ssize_t offset = 0;
2442 |
2443 | errno(*__errno_location ()) = 0;
2444 | length = recv(sock, data + used_buffer_length, (int)(PACKET_LENGTH65535 - used_buffer_length), 0);
2445 | CONTINUE_ON_TIMEOUT(length)if ((*__errno_location ()) == 11) continue;
2446 | else if (errno(*__errno_location ()) != 0) {
2447 | ws_warning("ERROR capture: %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2447, __func__, "ERROR capture: %s", strerror((*__errno_location ()))); } } while (0);
2448 | closesocket(sock)close(sock);
2449 | return EXIT_CODE_GENERIC;
2450 | }
2451 |
2452 | if (length <= 0) {
2453 | ws_warning("Broken socket connection.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2453, __func__, "Broken socket connection."); } } while (0);
2454 | closesocket(sock)close(sock);
2455 | return EXIT_CODE_GENERIC;
2456 | }
2457 |
2458 | used_buffer_length += length;
2459 |
2460 | while ((used_buffer_length - offset) > PCAP_RECORD_HEADER_LENGTH16) {
2461 | p_header = *((pcaprec_hdr_t*) (data + offset));
2462 | if (swap_byte_order) {
2463 | p_header.ts_sec = GUINT32_SWAP_LE_BE(p_header.ts_sec)(((guint32) ( (((guint32) (p_header.ts_sec) & (guint32) 0x000000ffU ) << 24) | (((guint32) (p_header.ts_sec) & (guint32 ) 0x0000ff00U) << 8) | (((guint32) (p_header.ts_sec) & (guint32) 0x00ff0000U) >> 8) | (((guint32) (p_header.ts_sec ) & (guint32) 0xff000000U) >> 24))));
2464 | p_header.ts_usec = GUINT32_SWAP_LE_BE(p_header.ts_usec)(((guint32) ( (((guint32) (p_header.ts_usec) & (guint32) 0x000000ffU ) << 24) | (((guint32) (p_header.ts_usec) & (guint32 ) 0x0000ff00U) << 8) | (((guint32) (p_header.ts_usec) & (guint32) 0x00ff0000U) >> 8) | (((guint32) (p_header.ts_usec ) & (guint32) 0xff000000U) >> 24))));
2465 | p_header.incl_len = GUINT32_SWAP_LE_BE(p_header.incl_len)(((guint32) ( (((guint32) (p_header.incl_len) & (guint32) 0x000000ffU) << 24) | (((guint32) (p_header.incl_len) & (guint32) 0x0000ff00U) << 8) | (((guint32) (p_header.incl_len ) & (guint32) 0x00ff0000U) >> 8) | (((guint32) (p_header .incl_len) & (guint32) 0xff000000U) >> 24))));
2466 | p_header.orig_len = GUINT32_SWAP_LE_BE(p_header.orig_len)(((guint32) ( (((guint32) (p_header.orig_len) & (guint32) 0x000000ffU) << 24) | (((guint32) (p_header.orig_len) & (guint32) 0x0000ff00U) << 8) | (((guint32) (p_header.orig_len ) & (guint32) 0x00ff0000U) >> 8) | (((guint32) (p_header .orig_len) & (guint32) 0xff000000U) >> 24))));
2467 | }
2468 | if (!nanosecond_timestamps) {
2469 | p_header.ts_usec = p_header.ts_usec * 1000;
2470 | }
2471 |
2472 | frame_length = p_header.incl_len + PCAP_RECORD_HEADER_LENGTH16;
2473 | if ((used_buffer_length - offset) < frame_length) {
2474 | break; /* wait for complete packet */
2475 | }
2476 |
2477 | /* It was observed that some times tcpdump reports the length of packet as '0' and that leads to the
2478 | * ( Warn Error "Less data was read than was expected" while reading )
2479 | * So to avoid this error we are checking for length of packet before passing it to dumper.
2480 | */
2481 | if (p_header.incl_len > 0) {
2482 | endless_loop = extcap_dumper_dump(extcap_dumper, fifo, data + offset + PCAP_RECORD_HEADER_LENGTH16,
2483 | p_header.incl_len, p_header.orig_len, p_header.ts_sec, p_header.ts_usec);
2484 | }
2485 |
2486 | offset += frame_length;
2487 | }
2488 |
2489 | if (offset < used_buffer_length) {
2490 | memmove(data, data + offset, used_buffer_length - offset);
2491 | }
2492 | used_buffer_length -= offset;
2493 | }
2494 |
2495 | closesocket(sock)close(sock);
2496 | return EXIT_CODE_SUCCESS;
2497 | }
2498 |
2499 | int main(int argc, char *argv[]) {
2500 | char *err_msg;
2501 | int ret = EXIT_CODE_GENERIC;
2502 | int option_idx = 0;
2503 | int result;
2504 | const char *adb_server_ip = NULL((void*)0);
2505 | unsigned short *adb_server_tcp_port = NULL((void*)0);
2506 | unsigned int logcat_text = 0;
2507 | unsigned int logcat_ignore_log_buffer = 0;
2508 | const char *logcat_custom_parameter = NULL((void*)0);
2509 | const char *default_adb_server_ip = "127.0.0.1";
2510 | unsigned short default_adb_server_tcp_port = 5037;
2511 | unsigned short local_adb_server_tcp_port;
2512 | unsigned short local_bt_server_tcp_port;
2513 | unsigned short local_bt_local_tcp_port;
2514 | unsigned short *bt_server_tcp_port = NULL((void*)0);
2515 | unsigned int bt_forward_socket = 0;
2516 | const char *bt_local_ip = NULL((void*)0);
2517 | unsigned short *bt_local_tcp_port = NULL((void*)0);
2518 | unsigned short default_bt_server_tcp_port = 4330;
2519 | const char *default_bt_local_ip = "127.0.0.1";
2520 | unsigned short default_bt_local_tcp_port = 4330;
2521 | extcap_parameters * extcap_conf = NULL((void*)0);
2522 | char *help_url;
2523 | char *help_header = NULL((void*)0);
2524 |
2525 | /* Set the program name. */
2526 | g_set_prgname("androiddump");
2527 |
2528 | cmdarg_err_init(extcap_log_cmdarg_err, extcap_log_cmdarg_err);
2529 |
2530 | /* Initialize log handler early so we can have proper logging during startup. */
2531 | extcap_log_init();
2532 |
2533 | /*
2534 | * Get credential information for later use.
2535 | */
2536 | init_process_policies();
2537 |
2538 | /*
2539 | * Attempt to get the pathname of the directory containing the
2540 | * executable file.
2541 | */
2542 | err_msg = configuration_init(argv[0], "wireshark");
2543 | if (err_msg != NULL((void*)0)) {
1 | Assuming 'err_msg' is equal to NULL | →
2 | ← | Taking false branch | →
2544 | ws_warning("Can't get pathname of directory containing the extcap program: %s.",do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2545, __func__, "Can't get pathname of directory containing the extcap program: %s." , err_msg); } } while (0)
2545 | err_msg)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2545, __func__, "Can't get pathname of directory containing the extcap program: %s." , err_msg); } } while (0);
2546 | g_free(err_msg)(__builtin_object_size ((err_msg), 0) != ((size_t) - 1)) ? g_free_sized (err_msg, __builtin_object_size ((err_msg), 0)) : (g_free) ( err_msg);
2547 | }
2548 |
2549 | #ifndef ANDROIDDUMP_USE_LIBPCAP
2550 | init_report_failure_message("androiddump");
2551 | #endif
2552 |
2553 | extcap_conf = g_new0(extcap_parameters, 1)((extcap_parameters *) g_malloc0_n ((1), sizeof (extcap_parameters )));
2554 |
2555 | help_url = data_file_url("androiddump.html", application_configuration_environment_prefix());
2556 | extcap_base_set_util_info(extcap_conf, argv[0], ANDROIDDUMP_VERSION_MAJOR"1", ANDROIDDUMP_VERSION_MINOR"1",
2557 | ANDROIDDUMP_VERSION_RELEASE"0", help_url);
2558 | g_free(help_url)(__builtin_object_size ((help_url), 0) != ((size_t) - 1)) ? g_free_sized (help_url, __builtin_object_size ((help_url), 0)) : (g_free) (help_url);
3 | ← | Assuming the condition is false | →
4 | ← | '?' condition is false | →
2559 |
2560 | help_header = ws_strdup_printf(wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2561 | " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2562 | " %s --extcap-interface=INTERFACE --extcap-dlts\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2563 | " %s --extcap-interface=INTERFACE --extcap-config\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2564 | " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2565 | "\nINTERFACE has the form TYPE-DEVICEID:\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2566 | "\t""For example: "INTERFACE_ANDROID_BLUETOOTH_BTSNOOP_NET"-W3D7N15C29005648""\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2567 | "\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2568 | "\tTYPE is one of:\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2569 | "\t"INTERFACE_ANDROID_LOGCAT_MAIN"\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2570 | "\t"INTERFACE_ANDROID_LOGCAT_SYSTEM"\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2571 | "\t"INTERFACE_ANDROID_LOGCAT_RADIO"\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2572 | "\t"INTERFACE_ANDROID_LOGCAT_EVENTS"\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2573 | "\t"INTERFACE_ANDROID_LOGCAT_TEXT_MAIN"\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2574 | "\t"INTERFACE_ANDROID_LOGCAT_TEXT_SYSTEM"\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2575 | "\t"INTERFACE_ANDROID_LOGCAT_TEXT_RADIO"\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2576 | "\t"INTERFACE_ANDROID_LOGCAT_TEXT_EVENTS"\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2577 | "\t"INTERFACE_ANDROID_LOGCAT_TEXT_CRASH"\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2578 | "\t"INTERFACE_ANDROID_BLUETOOTH_HCIDUMP"\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2579 | "\t"INTERFACE_ANDROID_BLUETOOTH_EXTERNAL_PARSER"\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2580 | "\t"INTERFACE_ANDROID_BLUETOOTH_BTSNOOP_NET"\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2581 | "\t"INTERFACE_ANDROID_TCPDUMP"\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2582 | "\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2583 | "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2584 | "\t""For example: W3D7N15C29005648""\n",wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2585 |
2586 | argv[0], argv[0], argv[0], argv[0])wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0]);
2587 | extcap_help_add_header(extcap_conf, help_header);
2588 | g_free(help_header)(__builtin_object_size ((help_header), 0) != ((size_t) - 1)) ? g_free_sized (help_header, __builtin_object_size ((help_header ), 0)) : (g_free) (help_header);
5 | ← | Assuming the condition is false | →
6 | ← | '?' condition is false | →
2589 |
2590 | extcap_help_add_option(extcap_conf, "--help", "print this help");
2591 | extcap_help_add_option(extcap_conf, "--adb-server-ip <IP>", "the IP address of the ADB server");
2592 | extcap_help_add_option(extcap_conf, "--adb-server-tcp-port <port>", "the TCP port of the ADB server");
2593 | extcap_help_add_option(extcap_conf, "--logcat-text", "use logcat text format");
2594 | extcap_help_add_option(extcap_conf, "--logcat-ignore-log-buffer", "ignore log buffer");
2595 | extcap_help_add_option(extcap_conf, "--logcat-custom-options <text>", "use custom logcat parameters");
2596 | extcap_help_add_option(extcap_conf, "--bt-server-tcp-port <port>", "bluetooth server TCP port");
2597 | extcap_help_add_option(extcap_conf, "--bt-forward-socket <path>", "bluetooth forward socket");
2598 | extcap_help_add_option(extcap_conf, "--bt-local-ip <IP>", "the bluetooth local IP");
2599 | extcap_help_add_option(extcap_conf, "--bt-local-tcp-port <port>", "the bluetooth local TCP port");
2600 |
2601 | ws_opterr = 0;
2602 | ws_optind = 0;
2603 |
2604 | if (argc == 1) {
7 | ← | Assuming 'argc' is not equal to 1 | →
8 | ← | Taking false branch | →
2605 | extcap_help_print(extcap_conf);
2606 | ret = EXIT_CODE_SUCCESS;
2607 | goto end;
2608 | }
2609 |
2610 | while ((result = ws_getopt_long(argc, argv, "", longopts, &option_idx)) != -1) {
9 | ← | Assuming the condition is false | →
10 | ← | Loop condition is false. Execution continues on line 2698 | →
2611 | switch (result) {
2612 |
2613 | case OPT_VERSION:
2614 | extcap_version_print(extcap_conf);
2615 | ret = EXIT_CODE_SUCCESS;
2616 | goto end;
2617 | case OPT_HELP:
2618 | extcap_help_print(extcap_conf);
2619 | ret = EXIT_CODE_SUCCESS;
2620 | goto end;
2621 | case OPT_CONFIG_ADB_SERVER_IP:
2622 | adb_server_ip = ws_optarg;
2623 | break;
2624 | case OPT_CONFIG_ADB_SERVER_TCP_PORT:
2625 | adb_server_tcp_port = &local_adb_server_tcp_port;
2626 | if (!ws_optarg){
2627 | ws_warning("Impossible exception. Parameter required argument, but there is no it right now.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2627, __func__, "Impossible exception. Parameter required argument, but there is no it right now." ); } } while (0);
2628 | goto end;
2629 | }
2630 | if (!ws_strtou16(ws_optarg, NULL((void*)0), adb_server_tcp_port)) {
2631 | ws_warning("Invalid adb server TCP port: %s", ws_optarg)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2631, __func__, "Invalid adb server TCP port: %s", ws_optarg ); } } while (0);
2632 | goto end;
2633 | }
2634 | break;
2635 | case OPT_CONFIG_LOGCAT_TEXT:
2636 | if (ws_optarg && !*ws_optarg)
2637 | logcat_text = true1;
2638 | else
2639 | logcat_text = (g_ascii_strncasecmp(ws_optarg, "true", 4) == 0);
2640 | break;
2641 | case OPT_CONFIG_LOGCAT_IGNORE_LOG_BUFFER:
2642 | if (ws_optarg == NULL((void*)0) || (ws_optarg && !*ws_optarg))
2643 | logcat_ignore_log_buffer = true1;
2644 | else
2645 | logcat_ignore_log_buffer = (g_ascii_strncasecmp(ws_optarg, "true", 4) == 0);
2646 | break;
2647 | case OPT_CONFIG_LOGCAT_CUSTOM_OPTIONS:
2648 | if (ws_optarg == NULL((void*)0) || (ws_optarg && *ws_optarg == '\0')) {
2649 | logcat_custom_parameter = NULL((void*)0);
2650 | break;
2651 | }
2652 |
2653 | if (g_regex_match_simple("(^|\\s)-[bBcDfgLnpPrv]", ws_optarg, G_REGEX_RAW, (GRegexMatchFlags)0)) {
2654 | ws_error("Found prohibited option in logcat-custom-options")ws_log_fatal_full("androiddump", LOG_LEVEL_ERROR, "extcap/androiddump.c" , 2654, __func__, "Found prohibited option in logcat-custom-options" );
2655 | return EXIT_CODE_GENERIC;
2656 | }
2657 |
2658 | logcat_custom_parameter = ws_optarg;
2659 |
2660 | break;
2661 | case OPT_CONFIG_BT_SERVER_TCP_PORT:
2662 | bt_server_tcp_port = &local_bt_server_tcp_port;
2663 | if (!ws_optarg){
2664 | ws_warning("Impossible exception. Parameter required argument, but there is no it right now.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2664, __func__, "Impossible exception. Parameter required argument, but there is no it right now." ); } } while (0);
2665 | goto end;
2666 | }
2667 | if (!ws_strtou16(ws_optarg, NULL((void*)0), bt_server_tcp_port)) {
2668 | ws_warning("Invalid bluetooth server TCP port: %s", ws_optarg)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2668, __func__, "Invalid bluetooth server TCP port: %s", ws_optarg ); } } while (0);
2669 | goto end;
2670 | }
2671 | break;
2672 | case OPT_CONFIG_BT_FORWARD_SOCKET:
2673 | bt_forward_socket = (g_ascii_strncasecmp(ws_optarg, "true", 4) == 0);
2674 | break;
2675 | case OPT_CONFIG_BT_LOCAL_IP:
2676 | bt_local_ip = ws_optarg;
2677 | break;
2678 | case OPT_CONFIG_BT_LOCAL_TCP_PORT:
2679 | bt_local_tcp_port = &local_bt_local_tcp_port;
2680 | if (!ws_optarg){
2681 | ws_warning("Impossible exception. Parameter required argument, but there is no it right now.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2681, __func__, "Impossible exception. Parameter required argument, but there is no it right now." ); } } while (0);
2682 | goto end;
2683 | }
2684 | if (!ws_strtou16(ws_optarg, NULL((void*)0), bt_local_tcp_port)) {
2685 | ws_warning("Invalid bluetooth local tcp port: %s", ws_optarg)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2685, __func__, "Invalid bluetooth local tcp port: %s", ws_optarg ); } } while (0);
2686 | goto end;
2687 | }
2688 | break;
2689 | default:
2690 | if (!extcap_base_parse_options(extcap_conf, result - EXTCAP_OPT_LIST_INTERFACES, ws_optarg))
2691 | {
2692 | ws_warning("Invalid argument <%s>. Try --help.\n", argv[ws_optind - 1])do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2692, __func__, "Invalid argument <%s>. Try --help.\n" , argv[ws_optind - 1]); } } while (0);
2693 | goto end;
2694 | }
2695 | }
2696 | }
2697 |
2698 | if (!adb_server_ip
10.1 | 'adb_server_ip' is null
)
11 | ← | Taking true branch | →
2699 | adb_server_ip = default_adb_server_ip;
2700 |
2701 | if (!adb_server_tcp_port
11.1 | 'adb_server_tcp_port' is null
)
12 | ← | Taking true branch | →
2702 | adb_server_tcp_port = &default_adb_server_tcp_port;
2703 |
2704 | if (!bt_server_tcp_port
12.1 | 'bt_server_tcp_port' is null
)
13 | ← | Taking true branch | →
2705 | bt_server_tcp_port = &default_bt_server_tcp_port;
2706 |
2707 | if (!bt_local_ip
13.1 | 'bt_local_ip' is null
)
14 | ← | Taking true branch | →
2708 | bt_local_ip = default_bt_local_ip;
2709 |
2710 | if (!bt_local_tcp_port
14.1 | 'bt_local_tcp_port' is null
)
15 | ← | Taking true branch | →
2711 | bt_local_tcp_port = &default_bt_local_tcp_port;
2712 |
2713 | err_msg = ws_init_sockets();
2714 | if (err_msg != NULL((void*)0)) {
16 | ← | Assuming 'err_msg' is equal to NULL | →
17 | ← | Taking false branch | →
2715 | ws_warning("ERROR: %s", err_msg)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2715, __func__, "ERROR: %s", err_msg); } } while (0);
2716 | g_free(err_msg)(__builtin_object_size ((err_msg), 0) != ((size_t) - 1)) ? g_free_sized (err_msg, __builtin_object_size ((err_msg), 0)) : (g_free) ( err_msg);
2717 | ws_warning("%s", please_report_bug())do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2717, __func__, "%s", please_report_bug()); } } while (0);
2718 | goto end;
2719 | }
2720 |
2721 | extcap_cmdline_debug(argv, argc);
2722 |
2723 | if (extcap_conf->do_list_interfaces)
18 | ← | Assuming field 'do_list_interfaces' is 0 | →
19 | ← | Taking false branch | →
2724 | register_interfaces(extcap_conf, adb_server_ip, adb_server_tcp_port);
2725 |
2726 | /* NOTE:
2727 | * extcap implementation calls androiddump --extcap-dlts for each interface.
2728 | * The only way to know whether an interface exists or not is to go through the
2729 | * whole process of listing all interfaces (i.e. calling register_interfaces
2730 | * function). Since being a system resource heavy operation and repeated for
2731 | * each interface instead register a fake interface to be returned for dlt
2732 | * listing only purpose
2733 | */
2734 | if (extcap_conf->do_list_dlts) {
20 | ← | Assuming field 'do_list_dlts' is 0 | →
21 | ← | Taking false branch | →
2735 | new_fake_interface_for_list_dlts(extcap_conf, extcap_conf->interface);
2736 | }
2737 |
2738 | if (extcap_base_handle_interface(extcap_conf)) {
22 | ← | Assuming the condition is false | →
23 | ← | Taking false branch | →
2739 | ret = EXIT_CODE_SUCCESS;
2740 | goto end;
2741 | }
2742 |
2743 | if (extcap_conf->show_config) {
24 | ← | Assuming field 'show_config' is 0 | →
25 | ← | Taking false branch | →
2744 | ret = list_config(extcap_conf->interface);
2745 | goto end;
2746 | }
2747 |
2748 | if (extcap_conf->capture) {
26 | ← | Assuming field 'capture' is not equal to 0 | →
2749 | if (extcap_conf->interface && is_logcat_interface(extcap_conf->interface))
27 | ← | Assuming field 'interface' is non-null | →
2750 | if (logcat_text)
2751 | ret = capture_android_logcat_text(extcap_conf->interface,
2752 | extcap_conf->fifo, adb_server_ip, adb_server_tcp_port,
2753 | logcat_ignore_log_buffer, logcat_custom_parameter);
2754 | else
2755 | ret = capture_android_logcat(extcap_conf->interface,
2756 | extcap_conf->fifo, adb_server_ip, adb_server_tcp_port);
2757 | else if (extcap_conf->interface
27.1 | Field 'interface' is non-null
&& is_logcat_text_interface(extcap_conf->interface))
28 | ← | Taking true branch | →
2758 | ret = capture_android_logcat_text(extcap_conf->interface,
29 | ← | Calling 'capture_android_logcat_text' | →
2759 | extcap_conf->fifo, adb_server_ip, adb_server_tcp_port,
2760 | logcat_ignore_log_buffer, logcat_custom_parameter);
2761 | else if (extcap_conf->interface && is_specified_interface(extcap_conf->interface, INTERFACE_ANDROID_BLUETOOTH_HCIDUMP"android-bluetooth-hcidump"))
2762 | ret = capture_android_bluetooth_hcidump(extcap_conf->interface, extcap_conf->fifo, adb_server_ip, adb_server_tcp_port);
2763 | else if (extcap_conf->interface && is_specified_interface(extcap_conf->interface, INTERFACE_ANDROID_BLUETOOTH_EXTERNAL_PARSER"android-bluetooth-external-parser"))
2764 | ret = capture_android_bluetooth_external_parser(extcap_conf->interface, extcap_conf->fifo, adb_server_ip, adb_server_tcp_port,
2765 | bt_server_tcp_port, bt_forward_socket, bt_local_ip, bt_local_tcp_port);
2766 | else if (extcap_conf->interface && (is_specified_interface(extcap_conf->interface, INTERFACE_ANDROID_BLUETOOTH_BTSNOOP_NET"android-bluetooth-btsnoop-net")))
2767 | ret = capture_android_bluetooth_btsnoop_net(extcap_conf->interface, extcap_conf->fifo, adb_server_ip, adb_server_tcp_port);
2768 | else if (extcap_conf->interface && (is_specified_interface(extcap_conf->interface,INTERFACE_ANDROID_TCPDUMP"android-tcpdump")))
2769 | ret = capture_android_tcpdump(extcap_conf->interface, extcap_conf->fifo, extcap_conf->capture_filter, adb_server_ip, adb_server_tcp_port);
2770 |
2771 | goto end;
2772 | }
2773 |
2774 | /* no action was given, assume success */
2775 | ret = EXIT_CODE_SUCCESS;
2776 |
2777 | end:
2778 | /* clean up stuff */
2779 | extcap_base_cleanup(&extcap_conf);
2780 | #ifndef ANDROIDDUMP_USE_LIBPCAP
2781 | wtap_cleanup();
2782 | #endif
2783 |
2784 | return ret;
2785 | }
2786 |
2787 | /*
2788 | * Editor modelines - https://www.wireshark.org/tools/modelines.html
2789 | *
2790 | * Local variables:
2791 | * c-basic-offset: 4
2792 | * tab-width: 8
2793 | * indent-tabs-mode: nil
2794 | * End:
2795 | *
2796 | * vi: set shiftwidth=4 tabstop=8 expandtab:
2797 | * :indentSize=4:tabSize=8:noTabs=true:
2798 | */