diff options
author | Mallikarjuna GB <gbmalli@codeaurora.org> | 2015-12-10 18:36:48 +0530 |
---|---|---|
committer | Gerrit - the friendly Code Review server <code-review@localhost> | 2016-01-10 04:23:34 -0800 |
commit | 1707433a801bc48855fc66f9c9914bd99f94ad3c (patch) | |
tree | 4eac72c7eeb1f44bc21021ca1e82f25a00a7ce65 | |
parent | 687f51d0c92796e70458b152b3316388fb0a8a03 (diff) | |
download | android_system_bt-1707433a801bc48855fc66f9c9914bd99f94ad3c.tar.gz android_system_bt-1707433a801bc48855fc66f9c9914bd99f94ad3c.tar.bz2 android_system_bt-1707433a801bc48855fc66f9c9914bd99f94ad3c.zip |
btsnoop: Remove the ext snoop dependency on snoop socket
Snoop socket cannot be enabled by default to be CTS compliant.
External snoop dump uses same thread, external dump related
functionality is moved out of TCP socket enabling
condition check.
CRs-Fixed: 951828
Change-Id: Icf51b27531a42ce257704d2c00b6e6b394cad3af
-rwxr-xr-x[-rw-r--r--] | hci/src/btsnoop_net.c | 41 |
1 files changed, 18 insertions, 23 deletions
diff --git a/hci/src/btsnoop_net.c b/hci/src/btsnoop_net.c index 077a4d432..a7a8c8e7a 100644..100755 --- a/hci/src/btsnoop_net.c +++ b/hci/src/btsnoop_net.c @@ -77,10 +77,6 @@ static int local_socket_create(void) { } void btsnoop_net_open() { -#if (!defined(BT_NET_DEBUG) || (BT_NET_DEBUG != TRUE)) - return; // Disable using network sockets for security reasons -#endif - listen_thread_valid_ = (pthread_create(&listen_thread_, NULL, listen_fn_, NULL) == 0); if (!listen_thread_valid_) { LOG_ERROR("%s pthread_create failed: %s", __func__, strerror(errno)); @@ -90,12 +86,11 @@ void btsnoop_net_open() { } void btsnoop_net_close() { -#if (!defined(BT_NET_DEBUG) || (BT_NET_DEBUG != TRUE)) - return; // Disable using network sockets for security reasons -#endif - if (listen_thread_valid_) { +#if (defined(BT_NET_DEBUG) && (NET_DEBUG == TRUE)) + // Disable using network sockets for security reasons shutdown(listen_socket_, SHUT_RDWR); +#endif shutdown(listen_socket_local_, SHUT_RDWR); pthread_join(listen_thread_, NULL); safe_close_(&client_socket_btsnoop); @@ -105,10 +100,6 @@ void btsnoop_net_close() { void btsnoop_net_write(const void *data, size_t length) { ssize_t ret; -#if (!defined(BT_NET_DEBUG) || (BT_NET_DEBUG != TRUE)) - return; // Disable using network sockets for security reasons -#endif - pthread_mutex_lock(&client_socket_lock_); if (client_socket_btsnoop != -1) { do { @@ -127,14 +118,15 @@ void btsnoop_net_write(const void *data, size_t length) { } static void *listen_fn_(UNUSED_ATTR void *context) { - ssize_t ret; fd_set sock_fds; - int fd_max, retval; + int fd_max = -1, retval; prctl(PR_SET_NAME, (unsigned long)LISTEN_THREAD_NAME_, 0, 0, 0); FD_ZERO(&sock_fds); +#if (defined(BT_NET_DEBUG) && (NET_DEBUG == TRUE)) + // Disable using network sockets for security reasons listen_socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (listen_socket_ == -1) { LOG_ERROR("%s socket creation failed: %s", __func__, strerror(errno)); @@ -162,6 +154,7 @@ static void *listen_fn_(UNUSED_ATTR void *context) { LOG_ERROR("%s unable to listen: %s", __func__, strerror(errno)); goto cleanup; } +#endif if (local_socket_create() != -1) { if (listen_socket_local_ > fd_max) { @@ -170,6 +163,11 @@ static void *listen_fn_(UNUSED_ATTR void *context) { FD_SET(listen_socket_local_, &sock_fds); } + if (fd_max == -1) { + LOG_ERROR("%s No sockets to wait for conn..", __func__); + return NULL; + } + for (;;) { int client_socket = -1; @@ -180,12 +178,7 @@ static void *listen_fn_(UNUSED_ATTR void *context) { goto cleanup; } - if(retval == 2) { - LOG_INFO("%s sockets shutdown :", __func__); - break; - } - - if (FD_ISSET(listen_socket_, &sock_fds)) { + if ((listen_socket_ != -1) && FD_ISSET(listen_socket_, &sock_fds)) { client_socket = accept(listen_socket_, NULL, NULL); if (client_socket == -1) { if (errno == EINVAL || errno == EBADF) { @@ -195,7 +188,7 @@ static void *listen_fn_(UNUSED_ATTR void *context) { LOG_WARN("%s error accepting TCP socket: %s", __func__, strerror(errno)); continue; } - } else if (FD_ISSET(listen_socket_local_, &sock_fds)){ + } else if ((listen_socket_local_ != -1) && FD_ISSET(listen_socket_local_, &sock_fds)){ struct sockaddr_un cliaddr; int length; @@ -215,11 +208,13 @@ static void *listen_fn_(UNUSED_ATTR void *context) { pthread_mutex_lock(&client_socket_lock_); safe_close_(&client_socket_btsnoop); client_socket_btsnoop = client_socket; - ret = send(client_socket_btsnoop, "btsnoop\0\0\0\0\1\0\0\x3\xea", 16, 0); + send(client_socket_btsnoop, "btsnoop\0\0\0\0\1\0\0\x3\xea", 16, 0); pthread_mutex_unlock(&client_socket_lock_); FD_ZERO(&sock_fds); - FD_SET(listen_socket_, &sock_fds); + if(listen_socket_ != -1) { + FD_SET(listen_socket_, &sock_fds); + } if(listen_socket_local_ != -1) { FD_SET(listen_socket_local_, &sock_fds); } |