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).
This commit is contained in:
Xavier Ducrohet 2009-05-20 17:33:53 -07:00
parent 463de48fb0
commit a09fbd164d
7 changed files with 103 additions and 21 deletions

View File

@ -53,6 +53,7 @@ LOCAL_SRC_FILES := \
$(USB_SRCS) \
shlist.c \
utils.c \
usb_vendors.c \
ifneq ($(USE_SYSDEPS_WIN32),)

View File

@ -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;
}

View File

@ -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);

View File

@ -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,23 +129,23 @@ 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)) {
return 1;
}
}
/* class:vendor (0xff) subclass:android (0x42) proto:adb (0x01) */
if(usb_class == 0xff) {
if((usb_subclass == 0x42) && (usb_protocol == 0x01)) {
return 1;
return 0;
}
}
return 0;
}
#endif

View File

@ -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)

40
adb/usb_vendors.c Normal file
View File

@ -0,0 +1,40 @@
/*
* Copyright (C) 2009 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 "usb_vendors.h"
#include "sysdeps.h"
#include <stdio.h>
#include "adb.h"
int* vendorIds = NULL;
unsigned vendorIdCount = 0;
void usb_vendors_init(void) {
/* for now, only put the built-in VENDOR_ID_* */
vendorIdCount = 2;
vendorIds = (int*)malloc(vendorIdCount * sizeof(int));
vendorIds[0] = VENDOR_ID_GOOGLE;
vendorIds[1] = VENDOR_ID_HTC;
}
void usb_vendors_cleanup(void) {
if (vendorIds != NULL) {
free(vendorIds);
vendorIds = NULL;
vendorIdCount = 0;
}
}

26
adb/usb_vendors.h Normal file
View File

@ -0,0 +1,26 @@
/*
* Copyright (C) 2009 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.
*/
#ifndef __USB_VENDORS_H
#define __USB_VENDORS_H
extern int* vendorIds;
extern unsigned vendorIdCount;
void usb_vendors_init(void);
void usb_vendors_cleanup(void);
#endif