Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a09fbd16 authored by Xavier Ducrohet's avatar Xavier Ducrohet
Browse files

Preparation work for adb to support USB vendor Ids provided by SDK add-ons.

Added usb_vendors.* which handles creating (and deleting) a list of vendor ids.
This list is meant to be used everywhere the built-in lists (usb_osx), or the
built-in vendor IDs (transport_usb)  were used.

For now the list is only built with the built-in VENDOR_ID_*. Next step
is to read a small file created from all the SDK add-on.

Other misc changes: made is_adb_interface present only if ADB_HOST is true
to prevent accessing a list that doesn't exist (usb_vendors is only
compiled for the host version of adb).
parent 463de48f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ LOCAL_SRC_FILES := \
	$(USB_SRCS) \
	shlist.c \
	utils.c \
	usb_vendors.c \


ifneq ($(USE_SYSDEPS_WIN32),)
+6 −0
Original line number Diff line number Diff line
@@ -29,6 +29,8 @@

#if !ADB_HOST
#include <private/android_filesystem_config.h>
#else
#include "usb_vendors.h"
#endif


@@ -833,6 +835,7 @@ int adb_main(int is_daemon)

#if ADB_HOST
    HOST = 1;
    usb_vendors_init();
    usb_init();
    local_init();

@@ -916,6 +919,9 @@ int adb_main(int is_daemon)
    fdevent_loop();

    usb_cleanup();
#if ADB_HOST
    usb_vendors_cleanup();
#endif

    return 0;
}
+2 −0
Original line number Diff line number Diff line
@@ -375,7 +375,9 @@ int usb_close(usb_handle *h);
void usb_kick(usb_handle *h);

/* used for USB device detection */
#if ADB_HOST
int is_adb_interface(int vid, int pid, int usb_class, int usb_subclass, int usb_protocol);
#endif

unsigned host_to_le32(unsigned n);
int adb_commandline(int argc, char **argv);
+17 −13
Original line number Diff line number Diff line
@@ -23,6 +23,10 @@
#define  TRACE_TAG  TRACE_TRANSPORT
#include "adb.h"

#if ADB_HOST
#include "usb_vendors.h"
#endif

/* XXX better define? */
#ifdef __ppc__
#define H4(x)	(((x) & 0xFF000000) >> 24) | (((x) & 0x00FF0000) >> 8) | (((x) & 0x0000FF00) << 8) | (((x) & 0x000000FF) << 24)
@@ -125,17 +129,12 @@ void init_usb_transport(atransport *t, usb_handle *h)
#endif
}

#if ADB_HOST
int is_adb_interface(int vid, int pid, int usb_class, int usb_subclass, int usb_protocol)
{
    if (vid == VENDOR_ID_GOOGLE) {
            /* might support adb */
    } else if (vid == VENDOR_ID_HTC) {
            /* might support adb */
    } else {
            /* not supported */
        return 0;
    }

    unsigned i;
    for (i = 0; i < vendorIdCount; i++) {
        if (vid == vendorIds[i]) {
            /* class:vendor (0xff) subclass:android (0x42) proto:adb (0x01) */
            if(usb_class == 0xff) {
                if((usb_subclass == 0x42) && (usb_protocol == 0x01)) {
@@ -145,3 +144,8 @@ int is_adb_interface(int vid, int pid, int usb_class, int usb_subclass, int usb_

            return 0;
        }
    }

    return 0;
}
#endif
+12 −9
Original line number Diff line number Diff line
@@ -28,20 +28,15 @@

#define TRACE_TAG   TRACE_USB
#include "adb.h"
#include "usb_vendors.h"

#define  DBG   D

#define ADB_SUBCLASS           0x42
#define ADB_PROTOCOL           0x1

int vendorIds[] = {
    VENDOR_ID_GOOGLE,
    VENDOR_ID_HTC,
};
#define NUM_VENDORS             (sizeof(vendorIds)/sizeof(vendorIds[0]))

static IONotificationPortRef    notificationPort = 0;
static io_iterator_t            notificationIterators[NUM_VENDORS];
static io_iterator_t*           notificationIterators;

struct usb_handle
{
@@ -81,7 +76,7 @@ InitUSB()
    memset(notificationIterators, 0, sizeof(notificationIterators));

    //* loop through all supported vendors
    for (i = 0; i < NUM_VENDORS; i++) {
    for (i = 0; i < vendorIdCount; i++) {
        //* Create our matching dictionary to find the Android device's
        //* adb interface
        //* IOServiceAddMatchingNotification consumes the reference, so we do
@@ -374,7 +369,7 @@ void* RunLoopThread(void* unused)
    CFRunLoopRun();
    currentRunLoop = 0;

    for (i = 0; i < NUM_VENDORS; i++) {
    for (i = 0; i < vendorIdCount; i++) {
        IOObjectRelease(notificationIterators[i]);
    }
    IONotificationPortDestroy(notificationPort);
@@ -391,6 +386,9 @@ void usb_init()
    {
        adb_thread_t    tid;

        notificationIterators = (io_iterator_t*)malloc(
            vendorIdCount * sizeof(io_iterator_t));

        adb_mutex_init(&start_lock, NULL);
        adb_cond_init(&start_cond, NULL);

@@ -415,6 +413,11 @@ void usb_cleanup()
    close_usb_devices();
    if (currentRunLoop)
        CFRunLoopStop(currentRunLoop);

    if (notificationIterators != NULL) {
        free(notificationIterators);
        notificationIterators = NULL;
    }
}

int usb_write(usb_handle *handle, const void *buf, int len)
Loading