system/corennnnn
修訂 | 8a88939d6473e513cb3c38e74a53c0c5dbdfdded (tree) |
---|---|
時間 | 2009-05-22 03:55:52 |
作者 | Xavier Ducrohet <xav@andr...> |
Commiter | The Android Open Source Project |
am a09fbd16: Preparation work for adb to support USB vendor Ids provided by SDK add-ons.
Merge commit 'a09fbd164d2e088bc5433d310e25640ae048d47d'
* commit 'a09fbd164d2e088bc5433d310e25640ae048d47d':
@@ -53,6 +53,7 @@ LOCAL_SRC_FILES := \ | ||
53 | 53 | $(USB_SRCS) \ |
54 | 54 | shlist.c \ |
55 | 55 | utils.c \ |
56 | + usb_vendors.c \ | |
56 | 57 | |
57 | 58 | |
58 | 59 | ifneq ($(USE_SYSDEPS_WIN32),) |
@@ -29,6 +29,8 @@ | ||
29 | 29 | |
30 | 30 | #if !ADB_HOST |
31 | 31 | #include <private/android_filesystem_config.h> |
32 | +#else | |
33 | +#include "usb_vendors.h" | |
32 | 34 | #endif |
33 | 35 | |
34 | 36 |
@@ -833,6 +835,7 @@ int adb_main(int is_daemon) | ||
833 | 835 | |
834 | 836 | #if ADB_HOST |
835 | 837 | HOST = 1; |
838 | + usb_vendors_init(); | |
836 | 839 | usb_init(); |
837 | 840 | local_init(); |
838 | 841 |
@@ -916,6 +919,9 @@ int adb_main(int is_daemon) | ||
916 | 919 | fdevent_loop(); |
917 | 920 | |
918 | 921 | usb_cleanup(); |
922 | +#if ADB_HOST | |
923 | + usb_vendors_cleanup(); | |
924 | +#endif | |
919 | 925 | |
920 | 926 | return 0; |
921 | 927 | } |
@@ -375,7 +375,9 @@ int usb_close(usb_handle *h); | ||
375 | 375 | void usb_kick(usb_handle *h); |
376 | 376 | |
377 | 377 | /* used for USB device detection */ |
378 | +#if ADB_HOST | |
378 | 379 | int is_adb_interface(int vid, int pid, int usb_class, int usb_subclass, int usb_protocol); |
380 | +#endif | |
379 | 381 | |
380 | 382 | unsigned host_to_le32(unsigned n); |
381 | 383 | int adb_commandline(int argc, char **argv); |
@@ -23,6 +23,10 @@ | ||
23 | 23 | #define TRACE_TAG TRACE_TRANSPORT |
24 | 24 | #include "adb.h" |
25 | 25 | |
26 | +#if ADB_HOST | |
27 | +#include "usb_vendors.h" | |
28 | +#endif | |
29 | + | |
26 | 30 | /* XXX better define? */ |
27 | 31 | #ifdef __ppc__ |
28 | 32 | #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) | ||
125 | 129 | #endif |
126 | 130 | } |
127 | 131 | |
132 | +#if ADB_HOST | |
128 | 133 | int is_adb_interface(int vid, int pid, int usb_class, int usb_subclass, int usb_protocol) |
129 | 134 | { |
130 | - if (vid == VENDOR_ID_GOOGLE) { | |
131 | - /* might support adb */ | |
132 | - } else if (vid == VENDOR_ID_HTC) { | |
133 | - /* might support adb */ | |
134 | - } else { | |
135 | - /* not supported */ | |
136 | - return 0; | |
137 | - } | |
138 | - | |
139 | - /* class:vendor (0xff) subclass:android (0x42) proto:adb (0x01) */ | |
140 | - if(usb_class == 0xff) { | |
141 | - if((usb_subclass == 0x42) && (usb_protocol == 0x01)) { | |
142 | - return 1; | |
135 | + unsigned i; | |
136 | + for (i = 0; i < vendorIdCount; i++) { | |
137 | + if (vid == vendorIds[i]) { | |
138 | + /* class:vendor (0xff) subclass:android (0x42) proto:adb (0x01) */ | |
139 | + if(usb_class == 0xff) { | |
140 | + if((usb_subclass == 0x42) && (usb_protocol == 0x01)) { | |
141 | + return 1; | |
142 | + } | |
143 | + } | |
144 | + | |
145 | + return 0; | |
143 | 146 | } |
144 | 147 | } |
145 | 148 | |
146 | 149 | return 0; |
147 | 150 | } |
151 | +#endif |
@@ -28,20 +28,15 @@ | ||
28 | 28 | |
29 | 29 | #define TRACE_TAG TRACE_USB |
30 | 30 | #include "adb.h" |
31 | +#include "usb_vendors.h" | |
31 | 32 | |
32 | 33 | #define DBG D |
33 | 34 | |
34 | 35 | #define ADB_SUBCLASS 0x42 |
35 | 36 | #define ADB_PROTOCOL 0x1 |
36 | 37 | |
37 | -int vendorIds[] = { | |
38 | - VENDOR_ID_GOOGLE, | |
39 | - VENDOR_ID_HTC, | |
40 | -}; | |
41 | -#define NUM_VENDORS (sizeof(vendorIds)/sizeof(vendorIds[0])) | |
42 | - | |
43 | 38 | static IONotificationPortRef notificationPort = 0; |
44 | -static io_iterator_t notificationIterators[NUM_VENDORS]; | |
39 | +static io_iterator_t* notificationIterators; | |
45 | 40 | |
46 | 41 | struct usb_handle |
47 | 42 | { |
@@ -81,7 +76,7 @@ InitUSB() | ||
81 | 76 | memset(notificationIterators, 0, sizeof(notificationIterators)); |
82 | 77 | |
83 | 78 | //* loop through all supported vendors |
84 | - for (i = 0; i < NUM_VENDORS; i++) { | |
79 | + for (i = 0; i < vendorIdCount; i++) { | |
85 | 80 | //* Create our matching dictionary to find the Android device's |
86 | 81 | //* adb interface |
87 | 82 | //* IOServiceAddMatchingNotification consumes the reference, so we do |
@@ -374,7 +369,7 @@ void* RunLoopThread(void* unused) | ||
374 | 369 | CFRunLoopRun(); |
375 | 370 | currentRunLoop = 0; |
376 | 371 | |
377 | - for (i = 0; i < NUM_VENDORS; i++) { | |
372 | + for (i = 0; i < vendorIdCount; i++) { | |
378 | 373 | IOObjectRelease(notificationIterators[i]); |
379 | 374 | } |
380 | 375 | IONotificationPortDestroy(notificationPort); |
@@ -391,6 +386,9 @@ void usb_init() | ||
391 | 386 | { |
392 | 387 | adb_thread_t tid; |
393 | 388 | |
389 | + notificationIterators = (io_iterator_t*)malloc( | |
390 | + vendorIdCount * sizeof(io_iterator_t)); | |
391 | + | |
394 | 392 | adb_mutex_init(&start_lock, NULL); |
395 | 393 | adb_cond_init(&start_cond, NULL); |
396 | 394 |
@@ -415,6 +413,11 @@ void usb_cleanup() | ||
415 | 413 | close_usb_devices(); |
416 | 414 | if (currentRunLoop) |
417 | 415 | CFRunLoopStop(currentRunLoop); |
416 | + | |
417 | + if (notificationIterators != NULL) { | |
418 | + free(notificationIterators); | |
419 | + notificationIterators = NULL; | |
420 | + } | |
418 | 421 | } |
419 | 422 | |
420 | 423 | int usb_write(usb_handle *handle, const void *buf, int len) |
@@ -0,0 +1,40 @@ | ||
1 | +/* | |
2 | + * Copyright (C) 2009 The Android Open Source Project | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + */ | |
16 | + | |
17 | +#include "usb_vendors.h" | |
18 | + | |
19 | +#include "sysdeps.h" | |
20 | +#include <stdio.h> | |
21 | +#include "adb.h" | |
22 | + | |
23 | +int* vendorIds = NULL; | |
24 | +unsigned vendorIdCount = 0; | |
25 | + | |
26 | +void usb_vendors_init(void) { | |
27 | + /* for now, only put the built-in VENDOR_ID_* */ | |
28 | + vendorIdCount = 2; | |
29 | + vendorIds = (int*)malloc(vendorIdCount * sizeof(int)); | |
30 | + vendorIds[0] = VENDOR_ID_GOOGLE; | |
31 | + vendorIds[1] = VENDOR_ID_HTC; | |
32 | +} | |
33 | + | |
34 | +void usb_vendors_cleanup(void) { | |
35 | + if (vendorIds != NULL) { | |
36 | + free(vendorIds); | |
37 | + vendorIds = NULL; | |
38 | + vendorIdCount = 0; | |
39 | + } | |
40 | +} |
@@ -0,0 +1,26 @@ | ||
1 | +/* | |
2 | + * Copyright (C) 2009 The Android Open Source Project | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + */ | |
16 | + | |
17 | +#ifndef __USB_VENDORS_H | |
18 | +#define __USB_VENDORS_H | |
19 | + | |
20 | +extern int* vendorIds; | |
21 | +extern unsigned vendorIdCount; | |
22 | + | |
23 | +void usb_vendors_init(void); | |
24 | +void usb_vendors_cleanup(void); | |
25 | + | |
26 | +#endif | |
\ No newline at end of file |