Bug Summary

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

Annotated Source Code

Press '?' to see keyboard shortcuts

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