### Bug Summary

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