### Bug Summary

File: | builds/wireshark/wireshark/extcap/androiddump.c
Warning: | line 1963, 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-04-26-100332-3641-1 -x c /builds/wireshark/wireshark/extcap/androiddump.c

Keyboard shortcuts:

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

Close
Show only relevant lines Show control flow arrows

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