adb: reorganize adbd USB handling code.
Break adbd's USB initialization code into its own static library to allow it to be used by benchmark code that pretends to be adbd. Bug: http://b/31289465 Test: adb shell works on bullhead Change-Id: I0ac7d78a4f7aef59bd6d14fc5cf1ed870e1f3a9d
This commit is contained in:
parent
1e7cdf3c7d
commit
44c688ca19
3 changed files with 80 additions and 33 deletions
|
|
@ -99,13 +99,9 @@ LIBADB_TEST_windows_SRCS := \
|
||||||
|
|
||||||
include $(CLEAR_VARS)
|
include $(CLEAR_VARS)
|
||||||
LOCAL_CLANG := true
|
LOCAL_CLANG := true
|
||||||
LOCAL_MODULE := libadbd
|
LOCAL_MODULE := libadbd_usb
|
||||||
LOCAL_CFLAGS := $(LIBADB_CFLAGS) -DADB_HOST=0
|
LOCAL_CFLAGS := $(LIBADB_CFLAGS) -DADB_HOST=0
|
||||||
LOCAL_SRC_FILES := \
|
LOCAL_SRC_FILES := daemon/usb.cpp
|
||||||
$(LIBADB_SRC_FILES) \
|
|
||||||
adbd_auth.cpp \
|
|
||||||
jdwp_service.cpp \
|
|
||||||
usb_linux_client.cpp \
|
|
||||||
|
|
||||||
LOCAL_SANITIZE := $(adb_target_sanitize)
|
LOCAL_SANITIZE := $(adb_target_sanitize)
|
||||||
|
|
||||||
|
|
@ -115,6 +111,25 @@ LOCAL_STATIC_LIBRARIES := libcrypto_utils libcrypto libbase
|
||||||
|
|
||||||
include $(BUILD_STATIC_LIBRARY)
|
include $(BUILD_STATIC_LIBRARY)
|
||||||
|
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
LOCAL_CLANG := true
|
||||||
|
LOCAL_MODULE := libadbd
|
||||||
|
LOCAL_CFLAGS := $(LIBADB_CFLAGS) -DADB_HOST=0
|
||||||
|
LOCAL_SRC_FILES := \
|
||||||
|
$(LIBADB_SRC_FILES) \
|
||||||
|
adbd_auth.cpp \
|
||||||
|
jdwp_service.cpp \
|
||||||
|
|
||||||
|
LOCAL_SANITIZE := $(adb_target_sanitize)
|
||||||
|
|
||||||
|
# Even though we're building a static library (and thus there's no link step for
|
||||||
|
# this to take effect), this adds the includes to our path.
|
||||||
|
LOCAL_STATIC_LIBRARIES := libcrypto_utils libcrypto libbase
|
||||||
|
|
||||||
|
LOCAL_WHOLE_STATIC_LIBRARIES := libadbd_usb
|
||||||
|
|
||||||
|
include $(BUILD_STATIC_LIBRARY)
|
||||||
|
|
||||||
include $(CLEAR_VARS)
|
include $(CLEAR_VARS)
|
||||||
LOCAL_MODULE := libadb
|
LOCAL_MODULE := libadb
|
||||||
LOCAL_MODULE_HOST_OS := darwin linux windows
|
LOCAL_MODULE_HOST_OS := darwin linux windows
|
||||||
|
|
@ -346,3 +361,5 @@ LOCAL_STATIC_LIBRARIES := \
|
||||||
libdebuggerd_handler \
|
libdebuggerd_handler \
|
||||||
|
|
||||||
include $(BUILD_EXECUTABLE)
|
include $(BUILD_EXECUTABLE)
|
||||||
|
|
||||||
|
include $(call first-makefiles-under,$(LOCAL_PATH))
|
||||||
|
|
|
||||||
|
|
@ -40,13 +40,14 @@
|
||||||
#include <android-base/properties.h>
|
#include <android-base/properties.h>
|
||||||
|
|
||||||
#include "adb.h"
|
#include "adb.h"
|
||||||
|
#include "daemon/usb.h"
|
||||||
#include "transport.h"
|
#include "transport.h"
|
||||||
|
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
#define MAX_PACKET_SIZE_FS 64
|
#define MAX_PACKET_SIZE_FS 64
|
||||||
#define MAX_PACKET_SIZE_HS 512
|
#define MAX_PACKET_SIZE_HS 512
|
||||||
#define MAX_PACKET_SIZE_SS 1024
|
#define MAX_PACKET_SIZE_SS 1024
|
||||||
|
|
||||||
// Writes larger than 16k fail on some devices (seed with 3.10.49-g209ea2f in particular).
|
// Writes larger than 16k fail on some devices (seed with 3.10.49-g209ea2f in particular).
|
||||||
#define USB_FFS_MAX_WRITE 16384
|
#define USB_FFS_MAX_WRITE 16384
|
||||||
|
|
@ -55,31 +56,11 @@ using namespace std::chrono_literals;
|
||||||
// fragmentation. 16k chosen arbitrarily to match the write limit.
|
// fragmentation. 16k chosen arbitrarily to match the write limit.
|
||||||
#define USB_FFS_MAX_READ 16384
|
#define USB_FFS_MAX_READ 16384
|
||||||
|
|
||||||
#define cpu_to_le16(x) htole16(x)
|
#define cpu_to_le16(x) htole16(x)
|
||||||
#define cpu_to_le32(x) htole32(x)
|
#define cpu_to_le32(x) htole32(x)
|
||||||
|
|
||||||
static int dummy_fd = -1;
|
static int dummy_fd = -1;
|
||||||
|
|
||||||
struct usb_handle {
|
|
||||||
usb_handle() : kicked(false) {
|
|
||||||
}
|
|
||||||
|
|
||||||
std::condition_variable notify;
|
|
||||||
std::mutex lock;
|
|
||||||
std::atomic<bool> kicked;
|
|
||||||
bool open_new_connection = true;
|
|
||||||
|
|
||||||
int (*write)(usb_handle *h, const void *data, int len);
|
|
||||||
int (*read)(usb_handle *h, void *data, int len);
|
|
||||||
void (*kick)(usb_handle *h);
|
|
||||||
void (*close)(usb_handle *h);
|
|
||||||
|
|
||||||
// FunctionFS
|
|
||||||
int control = -1;
|
|
||||||
int bulk_out = -1; /* "out" from the host's perspective => source for adbd */
|
|
||||||
int bulk_in = -1; /* "in" from the host's perspective => sink for adbd */
|
|
||||||
};
|
|
||||||
|
|
||||||
struct func_desc {
|
struct func_desc {
|
||||||
struct usb_interface_descriptor intf;
|
struct usb_interface_descriptor intf;
|
||||||
struct usb_endpoint_descriptor_no_audio source;
|
struct usb_endpoint_descriptor_no_audio source;
|
||||||
|
|
@ -223,7 +204,6 @@ static struct usb_os_desc_header os_desc_header = {
|
||||||
.Reserved = cpu_to_le32(0),
|
.Reserved = cpu_to_le32(0),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#define STR_INTERFACE_ "ADB Interface"
|
#define STR_INTERFACE_ "ADB Interface"
|
||||||
|
|
||||||
static const struct {
|
static const struct {
|
||||||
|
|
@ -245,7 +225,7 @@ static const struct {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool init_functionfs(struct usb_handle* h) {
|
bool init_functionfs(struct usb_handle* h) {
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
struct desc_v1 v1_descriptor;
|
struct desc_v1 v1_descriptor;
|
||||||
struct desc_v2 v2_descriptor;
|
struct desc_v2 v2_descriptor;
|
||||||
50
adb/daemon/usb.h
Normal file
50
adb/daemon/usb.h
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2017 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
#include <condition_variable>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
// Writes larger than 16k fail on some devices (seed with 3.10.49-g209ea2f in particular).
|
||||||
|
#define USB_FFS_MAX_WRITE 16384
|
||||||
|
|
||||||
|
// The kernel allocates a contiguous buffer for reads, which can fail for large ones due to
|
||||||
|
// fragmentation. 16k chosen arbitrarily to match the write limit.
|
||||||
|
#define USB_FFS_MAX_READ 16384
|
||||||
|
|
||||||
|
struct usb_handle {
|
||||||
|
usb_handle() : kicked(false) {
|
||||||
|
}
|
||||||
|
|
||||||
|
std::condition_variable notify;
|
||||||
|
std::mutex lock;
|
||||||
|
std::atomic<bool> kicked;
|
||||||
|
bool open_new_connection = true;
|
||||||
|
|
||||||
|
int (*write)(usb_handle* h, const void* data, int len);
|
||||||
|
int (*read)(usb_handle* h, void* data, int len);
|
||||||
|
void (*kick)(usb_handle* h);
|
||||||
|
void (*close)(usb_handle* h);
|
||||||
|
|
||||||
|
// FunctionFS
|
||||||
|
int control = -1;
|
||||||
|
int bulk_out = -1; /* "out" from the host's perspective => source for adbd */
|
||||||
|
int bulk_in = -1; /* "in" from the host's perspective => sink for adbd */
|
||||||
|
};
|
||||||
|
|
||||||
|
bool init_functionfs(struct usb_handle* h);
|
||||||
Loading…
Add table
Reference in a new issue