### Bug Summary

File: | builds/wireshark/wireshark/extcap/androiddump.c
Warning: | line 1784, 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-07-20-100411-3661-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) {
1 | Assuming 'bt_forward_socket' is not equal to 0 | →
2 | ← | Taking true branch | →
1716 | if ((sock = socket(AF_INET2, SOCK_STREAMSOCK_STREAM, IPPROTO_TCPIPPROTO_TCP)) == INVALID_SOCKET(-1)) {
3 | ← | Taking false branch | →
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)
4 | ← | Taking true branch | →
5 | ← | Loop condition is false. Exiting loop | →
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) {
6 | ← | Assuming the condition is false | →
7 | ← | Taking false branch | →
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)) {
8 | ← | Taking false branch | →
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)) {
9 | ← | Taking false branch | →
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)) {
10 | ← | Assuming the condition is false | →
11 | ← | Taking false branch | →
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);
12 | ← | Taking true branch | →
13 | ← | Loop condition is false. Exiting loop | →
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) {
14 | ← | Loop condition is true. Entering loop body | →
1782 | errno(*__errno_location ()) = 0;
1783 | length = recv(sock, buffer + used_buffer_length, (int)(PACKET_LENGTH65535 - used_buffer_length), 0);
15 | ← | Assuming that 'recv' is successful; 'errno' becomes undefined after the call | →
1784 | CONTINUE_ON_TIMEOUT(length)if ((*__errno_location ()) == 11) continue;
16 | ← | An undefined value may be read from 'errno'
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" 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 | used_buffer_length >= (int) (24 + GINT32_FROM_BE(*captured_length)(((gint32) (((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)))))))) {
1984 | int32_t direction;
1985 |
1986 | 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))))));
1987 | ts -= BTSNOOP_TIMESTAMP_BASE;
1988 |
1989 | 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;
1990 | 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)))));
1991 |
1992 | endless_loop = extcap_dumper_dump(extcap_dumper, fifo,
1993 | payload - sizeof(own_pcap_bluetooth_h4_header),
1994 | GINT32_FROM_BE(*captured_length)(((gint32) (((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)))))) + sizeof(own_pcap_bluetooth_h4_header),
1995 | GINT32_FROM_BE(*reported_length)(((gint32) (((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)))))) + sizeof(own_pcap_bluetooth_h4_header),
1996 | (uint32_t)(ts / 1000000),
1997 | ((uint32_t)(ts % 1000000)) * 1000);
1998 |
1999 | used_buffer_length -= 24 + GINT32_FROM_BE(*captured_length)(((gint32) (((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))))));
2000 | if (used_buffer_length < 0) {
2001 | ws_warning("Internal Negative used buffer length.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2001, __func__, "Internal Negative used buffer length."); } } while (0);
2002 | closesocket(sock)close(sock);
2003 | return EXIT_CODE_GENERIC;
2004 | }
2005 |
2006 | if (used_buffer_length > 0)
2007 | memmove(packet + sizeof(own_pcap_bluetooth_h4_header), payload + GINT32_FROM_BE(*captured_length)(((gint32) (((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)))))), used_buffer_length);
2008 | }
2009 | }
2010 |
2011 | closesocket(sock)close(sock);
2012 | return EXIT_CODE_SUCCESS;
2013 | }
2014 |
2015 | /*----------------------------------------------------------------------------*/
2016 | /* Android Logcat Text*/
2017 | /*----------------------------------------------------------------------------*/
2018 |
2019 |
2020 | static int capture_android_logcat_text(char *interface, char *fifo,
2021 | const char *adb_server_ip, unsigned short *adb_server_tcp_port,
2022 | int logcat_ignore_log_buffer, const char *logcat_custom_parameter) {
2023 | struct extcap_dumper extcap_dumper;
2024 | static char packet[PACKET_LENGTH65535];
2025 | ssize_t length;
2026 | size_t used_buffer_length = 0;
2027 | socket_handle_tint sock;
2028 | const char *protocol_name;
2029 | size_t exported_pdu_headers_size = 0;
2030 | struct exported_pdu_header exported_pdu_header_protocol_normal;
2031 | struct exported_pdu_header *exported_pdu_header_protocol;
2032 | struct exported_pdu_header exported_pdu_header_end = {0, 0};
2033 | static const char *wireshark_protocol_logcat_text = "logcat_text_threadtime";
2034 | const char *adb_logcat_template = "shell:export ANDROID_LOG_TAGS=\"\" ; exec logcat -v threadtime%s%s %s";
2035 | char *serial_number = NULL((void*)0);
2036 | int result;
2037 | char *pos;
2038 | const char *logcat_buffer;
2039 | const char *logcat_log_buffer;
2040 |
2041 | extcap_dumper = extcap_dumper_open(fifo, EXTCAP_ENCAP_WIRESHARK_UPPER_PDU155);
2042 |
2043 | exported_pdu_header_protocol_normal.tag = GUINT16_TO_BE(EXP_PDU_TAG_DISSECTOR_NAME)((((guint16) ( (guint16) ((guint16) (12) >> 8) | (guint16 ) ((guint16) (12) << 8)))));
2044 | 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)))));
2045 |
2046 | serial_number = get_serial_from_interface(interface);
2047 | sock = adb_connect_transport(adb_server_ip, adb_server_tcp_port, serial_number);
2048 | if (sock == INVALID_SOCKET(-1))
2049 | return EXIT_CODE_INVALID_SOCKET_8;
2050 |
2051 | 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"))
2052 | logcat_buffer = " -b main";
2053 | 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"))
2054 | logcat_buffer = " -b system";
2055 | 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"))
2056 | logcat_buffer = " -b radio";
2057 | 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"))
2058 | logcat_buffer = " -b events";
2059 | else if (is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_TEXT_CRASH"android-logcat-text-crash"))
2060 | logcat_buffer = " -b crash";
2061 | else {
2062 | ws_warning("Unknown interface: <%s>", interface)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2062, __func__, "Unknown interface: <%s>", interface) ; } } while (0);
2063 | closesocket(sock)close(sock);
2064 | return EXIT_CODE_GENERIC;
2065 | }
2066 |
2067 | if (logcat_ignore_log_buffer)
2068 | logcat_log_buffer = " -T 1";
2069 | else
2070 | logcat_log_buffer = "";
2071 |
2072 | if (!logcat_custom_parameter)
2073 | logcat_custom_parameter = "";
2074 |
2075 | result = snprintf((char *) packet, PACKET_LENGTH65535, adb_logcat_template, logcat_buffer, logcat_log_buffer, logcat_custom_parameter);
2076 | if (result <= 0 || result > PACKET_LENGTH65535) {
2077 | ws_warning("Error while completing adb packet")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2077, __func__, "Error while completing adb packet"); } } while (0);
2078 | closesocket(sock)close(sock);
2079 | return EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_17;
2080 | }
2081 |
2082 | result = adb_send(sock, packet);
2083 | if (result) {
2084 | ws_warning("Error while sending command <%s>", packet)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2084, __func__, "Error while sending command <%s>", packet ); } } while (0);
2085 | closesocket(sock)close(sock);
2086 | return EXIT_CODE_ERROR_WHILE_SENDING_ADB_PACKET_3;
2087 | }
2088 |
2089 | protocol_name = wireshark_protocol_logcat_text;
2090 | exported_pdu_header_protocol = &exported_pdu_header_protocol_normal;
2091 |
2092 | memcpy(packet, exported_pdu_header_protocol, sizeof(struct exported_pdu_header));
2093 | exported_pdu_headers_size += sizeof(struct exported_pdu_header);
2094 |
2095 | 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);
2096 | 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))))));
2097 |
2098 | packet[exported_pdu_headers_size - 1] = 0;
2099 | packet[exported_pdu_headers_size - 2] = 0;
2100 |
2101 | memcpy(packet + exported_pdu_headers_size, &exported_pdu_header_end, sizeof(struct exported_pdu_header));
2102 | 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))))));
2103 |
2104 | used_buffer_length = 0;
2105 | while (endless_loop) {
2106 | errno(*__errno_location ()) = 0;
2107 | length = recv(sock, packet + exported_pdu_headers_size + used_buffer_length, (int)(PACKET_LENGTH65535 - exported_pdu_headers_size - used_buffer_length), 0);
2108 | CONTINUE_ON_TIMEOUT(length)if ((*__errno_location ()) == 11) continue;
2109 | else if (errno(*__errno_location ()) != 0) {
2110 | ws_warning("ERROR capture: %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2110, __func__, "ERROR capture: %s", strerror((*__errno_location ()))); } } while (0);
2111 | closesocket(sock)close(sock);
2112 | return EXIT_CODE_GENERIC;
2113 | }
2114 |
2115 | if (length <= 0) {
2116 | ws_warning("Broken socket connection. Try reconnect.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2116, __func__, "Broken socket connection. Try reconnect.") ; } } while (0);
2117 | closesocket(sock)close(sock);
2118 | return EXIT_CODE_GENERIC;
2119 | }
2120 |
2121 | used_buffer_length += length;
2122 |
2123 | while (used_buffer_length > 0 && (pos = (char *) memchr(packet + exported_pdu_headers_size, '\n', used_buffer_length))) {
2124 | int ms;
2125 | struct tm* date;
2126 | time_t seconds;
2127 | time_t secs = 0;
2128 | int nsecs = 0;
2129 | time_t t;
2130 |
2131 | length = (ssize_t)(pos - packet) + 1;
2132 |
2133 | t = time(NULL((void*)0));
2134 | date = localtime(&t);
2135 | if (!date)
2136 | continue;
2137 | if (6 == sscanf(packet + exported_pdu_headers_size, "%d-%d %d:%d:%d.%d", &date->tm_mon, &date->tm_mday, &date->tm_hour,
2138 | &date->tm_min, &date->tm_sec, &ms)) {
2139 | date->tm_mon -= 1;
2140 | date->tm_isdst = -1;
2141 | seconds = mktime(date);
2142 | secs = (time_t) seconds;
2143 | nsecs = (int) (ms * 1e6);
2144 | }
2145 |
2146 | endless_loop = extcap_dumper_dump(extcap_dumper, fifo, packet,
2147 | length,
2148 | length,
2149 | secs, nsecs);
2150 |
2151 | memmove(packet + exported_pdu_headers_size, packet + length, used_buffer_length + exported_pdu_headers_size - length);
2152 | used_buffer_length -= length - exported_pdu_headers_size;
2153 | }
2154 | }
2155 |
2156 | closesocket(sock)close(sock);
2157 | return EXIT_CODE_SUCCESS;
2158 | }
2159 |
2160 | /*----------------------------------------------------------------------------*/
2161 | /* Android Logger / Logcat */
2162 | /*----------------------------------------------------------------------------*/
2163 |
2164 | static int capture_android_logcat(char *interface, char *fifo,
2165 | const char *adb_server_ip, unsigned short *adb_server_tcp_port) {
2166 | struct extcap_dumper extcap_dumper;
2167 | static char packet[PACKET_LENGTH65535];
2168 | ssize_t length;
2169 | size_t used_buffer_length = 0;
2170 | socket_handle_tint sock;
2171 | const char *protocol_name;
2172 | size_t exported_pdu_headers_size = 0;
2173 | struct exported_pdu_header exported_pdu_header_protocol_events;
2174 | struct exported_pdu_header exported_pdu_header_protocol_normal;
2175 | struct exported_pdu_header *exported_pdu_header_protocol;
2176 | struct exported_pdu_header exported_pdu_header_end = {0, 0};
2177 | static const char *wireshark_protocol_logcat = "logcat";
2178 | static const char *wireshark_protocol_logcat_events = "logcat_events";
2179 | const char *adb_command;
2180 | uint16_t *payload_length;
2181 | uint16_t *try_header_size;
2182 | uint32_t *timestamp_secs;
2183 | uint32_t *timestamp_nsecs;
2184 | uint16_t header_size;
2185 | int result;
2186 | char *serial_number = NULL((void*)0);
2187 |
2188 | extcap_dumper = extcap_dumper_open(fifo, EXTCAP_ENCAP_WIRESHARK_UPPER_PDU155);
2189 |
2190 | exported_pdu_header_protocol_events.tag = GUINT16_TO_BE(EXP_PDU_TAG_DISSECTOR_NAME)((((guint16) ( (guint16) ((guint16) (12) >> 8) | (guint16 ) ((guint16) (12) << 8)))));
2191 | 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)))));
2192 |
2193 | exported_pdu_header_protocol_normal.tag = GUINT16_TO_BE(EXP_PDU_TAG_DISSECTOR_NAME)((((guint16) ( (guint16) ((guint16) (12) >> 8) | (guint16 ) ((guint16) (12) << 8)))));
2194 | 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)))));
2195 |
2196 | serial_number = get_serial_from_interface(interface);
2197 | sock = adb_connect_transport(adb_server_ip, adb_server_tcp_port, serial_number);
2198 | if (sock == INVALID_SOCKET(-1))
2199 | return EXIT_CODE_INVALID_SOCKET_9;
2200 |
2201 | adb_command = interface_to_logbuf(interface);
2202 | if (!adb_command) {
2203 | ws_warning("Unknown interface: <%s>", interface)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2203, __func__, "Unknown interface: <%s>", interface) ; } } while (0);
2204 | closesocket(sock)close(sock);
2205 | return EXIT_CODE_GENERIC;
2206 | }
2207 |
2208 | result = adb_send(sock, adb_command);
2209 | if (result) {
2210 | ws_warning("Error while sending command <%s>", adb_command)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2210, __func__, "Error while sending command <%s>", adb_command ); } } while (0);
2211 | closesocket(sock)close(sock);
2212 | return EXIT_CODE_ERROR_WHILE_SENDING_ADB_PACKET_4;
2213 | }
2214 |
2215 | if (is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_EVENTS"android-logcat-events"))
2216 | {
2217 | protocol_name = wireshark_protocol_logcat_events;
2218 | exported_pdu_header_protocol = &exported_pdu_header_protocol_events;
2219 | } else {
2220 | protocol_name = wireshark_protocol_logcat;
2221 | exported_pdu_header_protocol = &exported_pdu_header_protocol_normal;
2222 | }
2223 |
2224 | memcpy(packet, exported_pdu_header_protocol, sizeof(struct exported_pdu_header));
2225 | exported_pdu_headers_size += sizeof(struct exported_pdu_header);
2226 |
2227 | 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);
2228 | 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))))));
2229 |
2230 | packet[exported_pdu_headers_size - 1] = 0;
2231 | packet[exported_pdu_headers_size - 2] = 0;
2232 |
2233 | memcpy(packet + exported_pdu_headers_size, &exported_pdu_header_end, sizeof(struct exported_pdu_header));
2234 | 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))))));
2235 |
2236 | 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; };
2237 | 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; };
2238 | 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; };
2239 | 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; };
2240 |
2241 | while (endless_loop) {
2242 | errno(*__errno_location ()) = 0;
2243 | length = recv(sock, packet + exported_pdu_headers_size + used_buffer_length, (int)(PACKET_LENGTH65535 - exported_pdu_headers_size - used_buffer_length), 0);
2244 | CONTINUE_ON_TIMEOUT(length)if ((*__errno_location ()) == 11) continue;
2245 | else if (errno(*__errno_location ()) != 0) {
2246 | ws_warning("ERROR capture: %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2246, __func__, "ERROR capture: %s", strerror((*__errno_location ()))); } } while (0);
2247 | closesocket(sock)close(sock);
2248 | return EXIT_CODE_GENERIC;
2249 | }
2250 |
2251 | if (length <= 0) {
2252 | while (endless_loop) {
2253 | ws_warning("Broken socket connection. Try reconnect.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2253, __func__, "Broken socket connection. Try reconnect.") ; } } while (0);
2254 | used_buffer_length = 0;
2255 | closesocket(sock)close(sock);
2256 |
2257 | sock = adb_connect_transport(adb_server_ip, adb_server_tcp_port, serial_number);
2258 | if (sock == INVALID_SOCKET(-1))
2259 | return EXIT_CODE_INVALID_SOCKET_10;
2260 |
2261 | result = adb_send(sock, adb_command);
2262 | if (result) {
2263 | ws_warning("WARNING: Error while sending command <%s>", adb_command)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2263, __func__, "WARNING: Error while sending command <%s>" , adb_command); } } while (0);
2264 | continue;
2265 | }
2266 |
2267 | break;
2268 | }
2269 | }
2270 |
2271 | used_buffer_length += length + exported_pdu_headers_size;
2272 |
2273 | if (*try_header_size != 24)
2274 | header_size = 20;
2275 | else
2276 | header_size = *try_header_size;
2277 |
2278 | length = (*payload_length) + header_size + (ssize_t)exported_pdu_headers_size;
2279 |
2280 | while (used_buffer_length >= exported_pdu_headers_size + header_size && (size_t)length <= used_buffer_length) {
2281 | endless_loop = extcap_dumper_dump(extcap_dumper, fifo, packet,
2282 | length,
2283 | length,
2284 | *timestamp_secs, *timestamp_nsecs);
2285 |
2286 | memmove(packet + exported_pdu_headers_size, packet + length, used_buffer_length - length);
2287 | used_buffer_length -= length;
2288 | used_buffer_length += exported_pdu_headers_size;
2289 |
2290 |
2291 | length = (*payload_length) + header_size + (ssize_t)exported_pdu_headers_size;
2292 |
2293 | if (*try_header_size != 24)
2294 | header_size = 20;
2295 | else
2296 | header_size = *try_header_size;
2297 | }
2298 | used_buffer_length -= exported_pdu_headers_size;
2299 | }
2300 |
2301 | closesocket(sock)close(sock);
2302 |
2303 | return EXIT_CODE_SUCCESS;
2304 | }
2305 |
2306 |
2307 | /*----------------------------------------------------------------------------*/
2308 | /* Android Wifi Tcpdump */
2309 | /* The Tcpdump sends data in pcap format. So for using the extcap_dumper we */
2310 | /* need to unpack the pcap and then send the packet data to the dumper. */
2311 | /*----------------------------------------------------------------------------*/
2312 | static int capture_android_tcpdump(char *interface, char *fifo,
2313 | char *capture_filter, const char *adb_server_ip,
2314 | unsigned short *adb_server_tcp_port) {
2315 | static const char *const adb_shell_tcpdump_format = "exec:tcpdump -U -n -s 0 -u -i %s -w - %s 2>/dev/null";
2316 | static const char *const regex_interface = INTERFACE_ANDROID_TCPDUMP"android-tcpdump" "-(?<iface>.*?)-(?<serial>.*)";
2317 | struct extcap_dumper extcap_dumper;
2318 | static char data[PACKET_LENGTH65535];
2319 | ssize_t length;
2320 | ssize_t used_buffer_length = 0;
2321 | ssize_t frame_length=0;
2322 | socket_handle_tint sock;
2323 | int result;
2324 | char *iface = NULL((void*)0);
2325 | char *serial_number = NULL((void*)0);
2326 | bool_Bool nanosecond_timestamps;
2327 | bool_Bool swap_byte_order;
2328 | pcap_hdr_t *global_header;
2329 | pcaprec_hdr_t p_header;
2330 | GRegex *regex = NULL((void*)0);
2331 | GError *err = NULL((void*)0);
2332 | GMatchInfo *match = NULL((void*)0);
2333 | char *tcpdump_cmd = NULL((void*)0);
2334 | char *quoted_filter = NULL((void*)0);
2335 |
2336 | regex = g_regex_new(regex_interface, G_REGEX_RAW, (GRegexMatchFlags)0, &err);
2337 | if (!regex) {
2338 | ws_warning("Failed to compile regex for tcpdump interface")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2338, __func__, "Failed to compile regex for tcpdump interface" ); } } while (0);
2339 | return EXIT_CODE_GENERIC;
2340 | }
2341 |
2342 | g_regex_match(regex, interface, (GRegexMatchFlags)0, &match);
2343 | if (!g_match_info_matches(match)) {
2344 | ws_warning("Failed to determine iface name and serial number")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2344, __func__, "Failed to determine iface name and serial number" ); } } while (0);
2345 | g_regex_unref(regex);
2346 | return EXIT_CODE_GENERIC;
2347 | }
2348 |
2349 | iface = g_match_info_fetch_named(match, "iface");
2350 | serial_number = g_match_info_fetch_named(match, "serial");
2351 | g_match_info_free(match);
2352 | g_regex_unref(regex);
2353 |
2354 | /* First check for the device if it is connected or not */
2355 | sock = adb_connect_transport(adb_server_ip, adb_server_tcp_port, serial_number);
2356 | 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);
2357 | if (sock == INVALID_SOCKET(-1)) {
2358 | g_free(iface)(__builtin_object_size ((iface), 0) != ((size_t) - 1)) ? g_free_sized (iface, __builtin_object_size ((iface), 0)) : (g_free) (iface );
2359 | return EXIT_CODE_INVALID_SOCKET_11;
2360 | }
2361 |
2362 | quoted_filter = g_shell_quote(capture_filter ? capture_filter : "");
2363 | tcpdump_cmd = ws_strdup_printf(adb_shell_tcpdump_format, iface, quoted_filter)wmem_strdup_printf(((void*)0), adb_shell_tcpdump_format, iface , quoted_filter);
2364 | g_free(iface)(__builtin_object_size ((iface), 0) != ((size_t) - 1)) ? g_free_sized (iface, __builtin_object_size ((iface), 0)) : (g_free) (iface );
2365 | 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);
2366 | result = adb_send(sock, tcpdump_cmd);
2367 | 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);
2368 | if (result) {
2369 | ws_warning("Error while setting adb transport")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2369, __func__, "Error while setting adb transport"); } } while (0);
2370 | closesocket(sock)close(sock);
2371 | return EXIT_CODE_GENERIC;
2372 | }
2373 |
2374 | while (used_buffer_length < PCAP_GLOBAL_HEADER_LENGTH24) {
2375 | errno(*__errno_location ()) = 0;
2376 | length = recv(sock, data + used_buffer_length, (int)(PCAP_GLOBAL_HEADER_LENGTH24 - used_buffer_length), 0);
2377 | CONTINUE_ON_TIMEOUT(length)if ((*__errno_location ()) == 11) continue;
2378 | else if (errno(*__errno_location ()) != 0) {
2379 | ws_warning("ERROR capture: %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2379, __func__, "ERROR capture: %s", strerror((*__errno_location ()))); } } while (0);
2380 | closesocket(sock)close(sock);
2381 | return EXIT_CODE_GENERIC;
2382 | }
2383 |
2384 | if (length <= 0) {
2385 | ws_warning("Broken socket connection.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2385, __func__, "Broken socket connection."); } } while (0);
2386 | closesocket(sock)close(sock);
2387 | return EXIT_CODE_GENERIC;
2388 | }
2389 |
2390 | used_buffer_length += length;
2391 | }
2392 |
2393 | global_header = (pcap_hdr_t*) data;
2394 | switch (global_header->magic_number) {
2395 | case 0xa1b2c3d4:
2396 | swap_byte_order = false0;
2397 | nanosecond_timestamps = false0;
2398 | break;
2399 | case 0xd4c3b2a1:
2400 | swap_byte_order = true1;
2401 | nanosecond_timestamps = false0;
2402 | break;
2403 | case 0xa1b23c4d:
2404 | swap_byte_order = false0;
2405 | nanosecond_timestamps = true1;
2406 | break;
2407 | case 0x4d3cb2a1:
2408 | swap_byte_order = true1;
2409 | nanosecond_timestamps = true1;
2410 | break;
2411 | default:
2412 | ws_warning("Received incorrect magic")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2412, __func__, "Received incorrect magic"); } } while (0);
2413 | closesocket(sock)close(sock);
2414 | return EXIT_CODE_GENERIC;
2415 | }
2416 | 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);
2417 | #ifndef ANDROIDDUMP_USE_LIBPCAP
2418 | encap = wtap_pcap_encap_to_wtap_encap(encap);
2419 | #endif
2420 | extcap_dumper = extcap_dumper_open(fifo, encap);
2421 |
2422 | used_buffer_length = 0;
2423 | while (endless_loop) {
2424 | ssize_t offset = 0;
2425 |
2426 | errno(*__errno_location ()) = 0;
2427 | length = recv(sock, data + used_buffer_length, (int)(PACKET_LENGTH65535 - used_buffer_length), 0);
2428 | CONTINUE_ON_TIMEOUT(length)if ((*__errno_location ()) == 11) continue;
2429 | else if (errno(*__errno_location ()) != 0) {
2430 | ws_warning("ERROR capture: %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2430, __func__, "ERROR capture: %s", strerror((*__errno_location ()))); } } while (0);
2431 | closesocket(sock)close(sock);
2432 | return EXIT_CODE_GENERIC;
2433 | }
2434 |
2435 | if (length <= 0) {
2436 | ws_warning("Broken socket connection.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2436, __func__, "Broken socket connection."); } } while (0);
2437 | closesocket(sock)close(sock);
2438 | return EXIT_CODE_GENERIC;
2439 | }
2440 |
2441 | used_buffer_length += length;
2442 |
2443 | while ((used_buffer_length - offset) > PCAP_RECORD_HEADER_LENGTH16) {
2444 | p_header = *((pcaprec_hdr_t*) (data + offset));
2445 | if (swap_byte_order) {
2446 | 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))));
2447 | 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))));
2448 | 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))));
2449 | 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))));
2450 | }
2451 | if (!nanosecond_timestamps) {
2452 | p_header.ts_usec = p_header.ts_usec * 1000;
2453 | }
2454 |
2455 | frame_length = p_header.incl_len + PCAP_RECORD_HEADER_LENGTH16;
2456 | if ((used_buffer_length - offset) < frame_length) {
2457 | break; /* wait for complete packet */
2458 | }
2459 |
2460 | /* It was observed that some times tcpdump reports the length of packet as '0' and that leads to the
2461 | * ( Warn Error "Less data was read than was expected" while reading )
2462 | * So to avoid this error we are checking for length of packet before passing it to dumper.
2463 | */
2464 | if (p_header.incl_len > 0) {
2465 | endless_loop = extcap_dumper_dump(extcap_dumper, fifo, data + offset + PCAP_RECORD_HEADER_LENGTH16,
2466 | p_header.incl_len, p_header.orig_len, p_header.ts_sec, p_header.ts_usec);
2467 | }
2468 |
2469 | offset += frame_length;
2470 | }
2471 |
2472 | if (offset < used_buffer_length) {
2473 | memmove(data, data + offset, used_buffer_length - offset);
2474 | }
2475 | used_buffer_length -= offset;
2476 | }
2477 |
2478 | closesocket(sock)close(sock);
2479 | return EXIT_CODE_SUCCESS;
2480 | }
2481 |
2482 | int main(int argc, char *argv[]) {
2483 | char *err_msg;
2484 | int ret = EXIT_CODE_GENERIC;
2485 | int option_idx = 0;
2486 | int result;
2487 | const char *adb_server_ip = NULL((void*)0);
2488 | unsigned short *adb_server_tcp_port = NULL((void*)0);
2489 | unsigned int logcat_text = 0;
2490 | unsigned int logcat_ignore_log_buffer = 0;
2491 | const char *logcat_custom_parameter = NULL((void*)0);
2492 | const char *default_adb_server_ip = "127.0.0.1";
2493 | unsigned short default_adb_server_tcp_port = 5037;
2494 | unsigned short local_adb_server_tcp_port;
2495 | unsigned short local_bt_server_tcp_port;
2496 | unsigned short local_bt_local_tcp_port;
2497 | unsigned short *bt_server_tcp_port = NULL((void*)0);
2498 | unsigned int bt_forward_socket = 0;
2499 | const char *bt_local_ip = NULL((void*)0);
2500 | unsigned short *bt_local_tcp_port = NULL((void*)0);
2501 | unsigned short default_bt_server_tcp_port = 4330;
2502 | const char *default_bt_local_ip = "127.0.0.1";
2503 | unsigned short default_bt_local_tcp_port = 4330;
2504 | extcap_parameters * extcap_conf = NULL((void*)0);
2505 | char *help_url;
2506 | char *help_header = NULL((void*)0);
2507 |
2508 | /* Set the program name. */
2509 | g_set_prgname("androiddump");
2510 |
2511 | cmdarg_err_init(extcap_log_cmdarg_err, extcap_log_cmdarg_err);
2512 |
2513 | /* Initialize log handler early so we can have proper logging during startup. */
2514 | extcap_log_init();
2515 |
2516 | /*
2517 | * Get credential information for later use.
2518 | */
2519 | init_process_policies();
2520 |
2521 | /*
2522 | * Attempt to get the pathname of the directory containing the
2523 | * executable file.
2524 | */
2525 | err_msg = configuration_init(argv[0], "wireshark");
2526 | if (err_msg != NULL((void*)0)) {
2527 | 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" , 2528, __func__, "Can't get pathname of directory containing the extcap program: %s." , err_msg); } } while (0)
2528 | err_msg)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2528, __func__, "Can't get pathname of directory containing the extcap program: %s." , err_msg); } } while (0);
2529 | 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);
2530 | }
2531 |
2532 | #ifndef ANDROIDDUMP_USE_LIBPCAP
2533 | init_report_failure_message("androiddump");
2534 | #endif
2535 |
2536 | extcap_conf = g_new0(extcap_parameters, 1)((extcap_parameters *) g_malloc0_n ((1), sizeof (extcap_parameters )));
2537 |
2538 | help_url = data_file_url("androiddump.html", application_configuration_environment_prefix());
2539 | extcap_base_set_util_info(extcap_conf, argv[0], ANDROIDDUMP_VERSION_MAJOR"1", ANDROIDDUMP_VERSION_MINOR"1",
2540 | ANDROIDDUMP_VERSION_RELEASE"0", help_url);
2541 | 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);
2542 |
2543 | 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])
2544 | " %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])
2545 | " %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])
2546 | " %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])
2547 | " %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])
2548 | "\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])
2549 | "\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])
2550 | "\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])
2551 | "\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])
2552 | "\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])
2553 | "\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])
2554 | "\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])
2555 | "\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])
2556 | "\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])
2557 | "\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])
2558 | "\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])
2559 | "\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])
2560 | "\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])
2561 | "\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])
2562 | "\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])
2563 | "\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])
2564 | "\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])
2565 | "\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""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])
2567 | "\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])
2568 |
2569 | 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]);
2570 | extcap_help_add_header(extcap_conf, help_header);
2571 | 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);
2572 |
2573 | extcap_help_add_option(extcap_conf, "--help", "print this help");
2574 | extcap_help_add_option(extcap_conf, "--adb-server-ip <IP>", "the IP address of the ADB server");
2575 | extcap_help_add_option(extcap_conf, "--adb-server-tcp-port <port>", "the TCP port of the ADB server");
2576 | extcap_help_add_option(extcap_conf, "--logcat-text", "use logcat text format");
2577 | extcap_help_add_option(extcap_conf, "--logcat-ignore-log-buffer", "ignore log buffer");
2578 | extcap_help_add_option(extcap_conf, "--logcat-custom-options <text>", "use custom logcat parameters");
2579 | extcap_help_add_option(extcap_conf, "--bt-server-tcp-port <port>", "bluetooth server TCP port");
2580 | extcap_help_add_option(extcap_conf, "--bt-forward-socket <path>", "bluetooth forward socket");
2581 | extcap_help_add_option(extcap_conf, "--bt-local-ip <IP>", "the bluetooth local IP");
2582 | extcap_help_add_option(extcap_conf, "--bt-local-tcp-port <port>", "the bluetooth local TCP port");
2583 |
2584 | ws_opterr = 0;
2585 | ws_optind = 0;
2586 |
2587 | if (argc == 1) {
2588 | extcap_help_print(extcap_conf);
2589 | ret = EXIT_CODE_SUCCESS;
2590 | goto end;
2591 | }
2592 |
2593 | while ((result = ws_getopt_long(argc, argv, "", longopts, &option_idx)) != -1) {
2594 | switch (result) {
2595 |
2596 | case OPT_VERSION:
2597 | extcap_version_print(extcap_conf);
2598 | ret = EXIT_CODE_SUCCESS;
2599 | goto end;
2600 | case OPT_HELP:
2601 | extcap_help_print(extcap_conf);
2602 | ret = EXIT_CODE_SUCCESS;
2603 | goto end;
2604 | case OPT_CONFIG_ADB_SERVER_IP:
2605 | adb_server_ip = ws_optarg;
2606 | break;
2607 | case OPT_CONFIG_ADB_SERVER_TCP_PORT:
2608 | adb_server_tcp_port = &local_adb_server_tcp_port;
2609 | if (!ws_optarg){
2610 | 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" , 2610, __func__, "Impossible exception. Parameter required argument, but there is no it right now." ); } } while (0);
2611 | goto end;
2612 | }
2613 | if (!ws_strtou16(ws_optarg, NULL((void*)0), adb_server_tcp_port)) {
2614 | ws_warning("Invalid adb server TCP port: %s", ws_optarg)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2614, __func__, "Invalid adb server TCP port: %s", ws_optarg ); } } while (0);
2615 | goto end;
2616 | }
2617 | break;
2618 | case OPT_CONFIG_LOGCAT_TEXT:
2619 | if (ws_optarg && !*ws_optarg)
2620 | logcat_text = true1;
2621 | else
2622 | logcat_text = (g_ascii_strncasecmp(ws_optarg, "true", 4) == 0);
2623 | break;
2624 | case OPT_CONFIG_LOGCAT_IGNORE_LOG_BUFFER:
2625 | if (ws_optarg == NULL((void*)0) || (ws_optarg && !*ws_optarg))
2626 | logcat_ignore_log_buffer = true1;
2627 | else
2628 | logcat_ignore_log_buffer = (g_ascii_strncasecmp(ws_optarg, "true", 4) == 0);
2629 | break;
2630 | case OPT_CONFIG_LOGCAT_CUSTOM_OPTIONS:
2631 | if (ws_optarg == NULL((void*)0) || (ws_optarg && *ws_optarg == '\0')) {
2632 | logcat_custom_parameter = NULL((void*)0);
2633 | break;
2634 | }
2635 |
2636 | if (g_regex_match_simple("(^|\\s)-[bBcDfgLnpPrv]", ws_optarg, G_REGEX_RAW, (GRegexMatchFlags)0)) {
2637 | ws_error("Found prohibited option in logcat-custom-options")ws_log_fatal_full("androiddump", LOG_LEVEL_ERROR, "extcap/androiddump.c" , 2637, __func__, "Found prohibited option in logcat-custom-options" );
2638 | return EXIT_CODE_GENERIC;
2639 | }
2640 |
2641 | logcat_custom_parameter = ws_optarg;
2642 |
2643 | break;
2644 | case OPT_CONFIG_BT_SERVER_TCP_PORT:
2645 | bt_server_tcp_port = &local_bt_server_tcp_port;
2646 | if (!ws_optarg){
2647 | 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" , 2647, __func__, "Impossible exception. Parameter required argument, but there is no it right now." ); } } while (0);
2648 | goto end;
2649 | }
2650 | if (!ws_strtou16(ws_optarg, NULL((void*)0), bt_server_tcp_port)) {
2651 | ws_warning("Invalid bluetooth server TCP port: %s", ws_optarg)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2651, __func__, "Invalid bluetooth server TCP port: %s", ws_optarg ); } } while (0);
2652 | goto end;
2653 | }
2654 | break;
2655 | case OPT_CONFIG_BT_FORWARD_SOCKET:
2656 | bt_forward_socket = (g_ascii_strncasecmp(ws_optarg, "true", 4) == 0);
2657 | break;
2658 | case OPT_CONFIG_BT_LOCAL_IP:
2659 | bt_local_ip = ws_optarg;
2660 | break;
2661 | case OPT_CONFIG_BT_LOCAL_TCP_PORT:
2662 | bt_local_tcp_port = &local_bt_local_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_local_tcp_port)) {
2668 | ws_warning("Invalid bluetooth local tcp port: %s", ws_optarg)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2668, __func__, "Invalid bluetooth local tcp port: %s", ws_optarg ); } } while (0);
2669 | goto end;
2670 | }
2671 | break;
2672 | default:
2673 | if (!extcap_base_parse_options(extcap_conf, result - EXTCAP_OPT_LIST_INTERFACES, ws_optarg))
2674 | {
2675 | 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" , 2675, __func__, "Invalid argument <%s>. Try --help.\n" , argv[ws_optind - 1]); } } while (0);
2676 | goto end;
2677 | }
2678 | }
2679 | }
2680 |
2681 | if (!adb_server_ip)
2682 | adb_server_ip = default_adb_server_ip;
2683 |
2684 | if (!adb_server_tcp_port)
2685 | adb_server_tcp_port = &default_adb_server_tcp_port;
2686 |
2687 | if (!bt_server_tcp_port)
2688 | bt_server_tcp_port = &default_bt_server_tcp_port;
2689 |
2690 | if (!bt_local_ip)
2691 | bt_local_ip = default_bt_local_ip;
2692 |
2693 | if (!bt_local_tcp_port)
2694 | bt_local_tcp_port = &default_bt_local_tcp_port;
2695 |
2696 | err_msg = ws_init_sockets();
2697 | if (err_msg != NULL((void*)0)) {
2698 | ws_warning("ERROR: %s", err_msg)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2698, __func__, "ERROR: %s", err_msg); } } while (0);
2699 | 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);
2700 | ws_warning("%s", please_report_bug())do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2700, __func__, "%s", please_report_bug()); } } while (0);
2701 | goto end;
2702 | }
2703 |
2704 | extcap_cmdline_debug(argv, argc);
2705 |
2706 | if (extcap_conf->do_list_interfaces)
2707 | register_interfaces(extcap_conf, adb_server_ip, adb_server_tcp_port);
2708 |
2709 | /* NOTE:
2710 | * extcap implementation calls androiddump --extcap-dlts for each interface.
2711 | * The only way to know whether an interface exists or not is to go through the
2712 | * whole process of listing all interfaces (i.e. calling register_interfaces
2713 | * function). Since being a system resource heavy operation and repeated for
2714 | * each interface instead register a fake interface to be returned for dlt
2715 | * listing only purpose
2716 | */
2717 | if (extcap_conf->do_list_dlts) {
2718 | new_fake_interface_for_list_dlts(extcap_conf, extcap_conf->interface);
2719 | }
2720 |
2721 | if (extcap_base_handle_interface(extcap_conf)) {
2722 | ret = EXIT_CODE_SUCCESS;
2723 | goto end;
2724 | }
2725 |
2726 | if (extcap_conf->show_config) {
2727 | ret = list_config(extcap_conf->interface);
2728 | goto end;
2729 | }
2730 |
2731 | if (extcap_conf->capture) {
2732 | if (extcap_conf->interface && is_logcat_interface(extcap_conf->interface))
2733 | if (logcat_text)
2734 | ret = capture_android_logcat_text(extcap_conf->interface,
2735 | extcap_conf->fifo, adb_server_ip, adb_server_tcp_port,
2736 | logcat_ignore_log_buffer, logcat_custom_parameter);
2737 | else
2738 | ret = capture_android_logcat(extcap_conf->interface,
2739 | extcap_conf->fifo, adb_server_ip, adb_server_tcp_port);
2740 | else if (extcap_conf->interface && is_logcat_text_interface(extcap_conf->interface))
2741 | ret = capture_android_logcat_text(extcap_conf->interface,
2742 | extcap_conf->fifo, adb_server_ip, adb_server_tcp_port,
2743 | logcat_ignore_log_buffer, logcat_custom_parameter);
2744 | else if (extcap_conf->interface && is_specified_interface(extcap_conf->interface, INTERFACE_ANDROID_BLUETOOTH_HCIDUMP"android-bluetooth-hcidump"))
2745 | ret = capture_android_bluetooth_hcidump(extcap_conf->interface, extcap_conf->fifo, adb_server_ip, adb_server_tcp_port);
2746 | else if (extcap_conf->interface && is_specified_interface(extcap_conf->interface, INTERFACE_ANDROID_BLUETOOTH_EXTERNAL_PARSER"android-bluetooth-external-parser"))
2747 | ret = capture_android_bluetooth_external_parser(extcap_conf->interface, extcap_conf->fifo, adb_server_ip, adb_server_tcp_port,
2748 | bt_server_tcp_port, bt_forward_socket, bt_local_ip, bt_local_tcp_port);
2749 | else if (extcap_conf->interface && (is_specified_interface(extcap_conf->interface, INTERFACE_ANDROID_BLUETOOTH_BTSNOOP_NET"android-bluetooth-btsnoop-net")))
2750 | ret = capture_android_bluetooth_btsnoop_net(extcap_conf->interface, extcap_conf->fifo, adb_server_ip, adb_server_tcp_port);
2751 | else if (extcap_conf->interface && (is_specified_interface(extcap_conf->interface,INTERFACE_ANDROID_TCPDUMP"android-tcpdump")))
2752 | ret = capture_android_tcpdump(extcap_conf->interface, extcap_conf->fifo, extcap_conf->capture_filter, adb_server_ip, adb_server_tcp_port);
2753 |
2754 | goto end;
2755 | }
2756 |
2757 | /* no action was given, assume success */
2758 | ret = EXIT_CODE_SUCCESS;
2759 |
2760 | end:
2761 | /* clean up stuff */
2762 | extcap_base_cleanup(&extcap_conf);
2763 | #ifndef ANDROIDDUMP_USE_LIBPCAP
2764 | wtap_cleanup();
2765 | #endif
2766 |
2767 | return ret;
2768 | }
2769 |
2770 | /*
2771 | * Editor modelines - https://www.wireshark.org/tools/modelines.html
2772 | *
2773 | * Local variables:
2774 | * c-basic-offset: 4
2775 | * tab-width: 8
2776 | * indent-tabs-mode: nil
2777 | * End:
2778 | *
2779 | * vi: set shiftwidth=4 tabstop=8 expandtab:
2780 | * :indentSize=4:tabSize=8:noTabs=true:
2781 | */