### Bug Summary

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

### Annotated Source Code

Press '?' to see keyboard shortcuts

Show analyzer invocation
clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name androiddump.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -pic-is-pie -fno-delete-null-pointer-checks -mframe-pointer=all -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -ffloat16-excess-precision=fast -fbfloat16-excess-precision=fast -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/builds/wireshark/wireshark/build -fcoverage-compilation-dir=/builds/wireshark/wireshark/build -resource-dir /usr/lib/llvm-21/lib/clang/21 -isystem /usr/include/glib-2.0 -isystem /usr/lib/x86_64-linux-gnu/glib-2.0/include -D G_DISABLE_DEPRECATED -D G_DISABLE_SINGLE_INCLUDES -D WS_DEBUG -D WS_DEBUG_UTF_8 -I /builds/wireshark/wireshark/build -I /builds/wireshark/wireshark -I /builds/wireshark/wireshark/include -I /builds/wireshark/wireshark/wiretap -D _GLIBCXX_ASSERTIONS -internal-isystem /usr/lib/llvm-21/lib/clang/21/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fmacro-prefix-map=/builds/wireshark/wireshark/= -fmacro-prefix-map=/builds/wireshark/wireshark/build/= -fmacro-prefix-map=../= -Wno-format-nonliteral -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/2026-01-28-100410-3623-1 -x c /builds/wireshark/wireshark/extcap/androiddump.c

Keyboard shortcuts:

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

Close
Show only relevant lines Show control flow arrows

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