### Bug Summary

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