blob: 705f02ba82fd21589a5a54f9ef62674bef16cb42 [file] [log] [blame]
Xavier Ducrohet2ef5fc22009-05-20 17:33:53 -07001/*
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
Xavier Ducrohet2ef5fc22009-05-20 17:33:53 -070019#include <stdio.h>
Xavier Ducrohet30a40332009-05-21 17:47:43 -070020
21#ifdef _WIN32
22# define WIN32_LEAN_AND_MEAN
23# include "windows.h"
24# include "shlobj.h"
25#else
26# include <unistd.h>
27# include <sys/stat.h>
28#endif
29
30#include "sysdeps.h"
Xavier Ducrohet2ef5fc22009-05-20 17:33:53 -070031#include "adb.h"
32
Xavier Ducrohet30a40332009-05-21 17:47:43 -070033#define ANDROID_PATH ".android"
34#define ANDROID_ADB_INI "adb_usb.ini"
35
36#define TRACE_TAG TRACE_USB
37
Colin Crossd8a76372014-01-05 18:19:51 -080038/* Keep the list below sorted alphabetically by #define name */
Robert CH Choue9d35632009-09-21 09:51:35 +080039// Acer's USB Vendor ID
40#define VENDOR_ID_ACER 0x0502
DanielMoc087e9b2013-08-28 18:39:01 +080041// Allwinner's USB Vendor ID
42#define VENDOR_ID_ALLWINNER 0x1F3A
DanielMo196fef62013-08-26 18:36:11 +080043// Amlogic's USB Vendor ID
44#define VENDOR_ID_AMLOGIC 0x1b8e
Sam Lin79fb1492013-03-12 20:14:56 +080045// AnyDATA's USB Vendor ID
46#define VENDOR_ID_ANYDATA 0x16D5
Colin Crossd8a76372014-01-05 18:19:51 -080047// Archos's USB Vendor ID
48#define VENDOR_ID_ARCHOS 0x0E79
49// Asus's USB Vendor ID
50#define VENDOR_ID_ASUS 0x0b05
sunxiaoqi2726fa92013-03-15 16:17:37 +080051// BYD's USB Vendor ID
kongfanqingfbcd1142013-05-15 14:17:41 +080052#define VENDOR_ID_BYD 0x1D91
Colin Crossd8a76372014-01-05 18:19:51 -080053// Compal's USB Vendor ID
herman_lin5efccfe2014-05-05 03:43:20 +080054#define VENDOR_ID_COMPAL 0x04B7
55// Compalcomm's USB Vendor ID
56#define VENDOR_ID_COMPALCOMM 0x1219
Colin Crossd8a76372014-01-05 18:19:51 -080057// Dell's USB Vendor ID
58#define VENDOR_ID_DELL 0x413c
ecsgms26a84e72013-07-24 16:13:49 +080059// ECS's USB Vendor ID
60#define VENDOR_ID_ECS 0x03fc
DanielMo1c22c5f2013-10-08 16:14:18 +080061// EMERGING_TECH's USB Vendor ID
62#define VENDOR_ID_EMERGING_TECH 0x297F
Jon Sawyerb3212642014-01-11 22:59:18 -080063// Emerson's USB Vendor ID
64#define VENDOR_ID_EMERSON 0x2207
Colin Crossd8a76372014-01-05 18:19:51 -080065// Foxconn's USB Vendor ID
66#define VENDOR_ID_FOXCONN 0x0489
67// Fujitsu's USB Vendor ID
68#define VENDOR_ID_FUJITSU 0x04C5
69// Funai's USB Vendor ID
70#define VENDOR_ID_FUNAI 0x0F1C
71// Garmin-Asus's USB Vendor ID
72#define VENDOR_ID_GARMIN_ASUS 0x091E
73// Gigabyte's USB Vendor ID
74#define VENDOR_ID_GIGABYTE 0x0414
Volker Moesker2b1f7ee2013-10-07 14:42:28 +020075// Gigaset's USB Vendor ID
76#define VENDOR_ID_GIGASET 0x1E85
xuefeng caie1febab2014-06-16 16:09:57 +080077// GIONEE's USB Vendor ID
78#define VENDOR_ID_GIONEE 0x271D
Colin Crossd8a76372014-01-05 18:19:51 -080079// Google's USB Vendor ID
80#define VENDOR_ID_GOOGLE 0x18d1
81// Haier's USB Vendor ID
82#define VENDOR_ID_HAIER 0x201E
83// Harris's USB Vendor ID
84#define VENDOR_ID_HARRIS 0x19A5
85// Hisense's USB Vendor ID
86#define VENDOR_ID_HISENSE 0x109b
Jon Sawyer78586e92014-01-08 08:14:26 -080087// HP's USB Vendor ID
88#define VENDOR_ID_HP 0x03f0
Colin Crossd8a76372014-01-05 18:19:51 -080089// HTC's USB Vendor ID
90#define VENDOR_ID_HTC 0x0bb4
91// Huawei's USB Vendor ID
92#define VENDOR_ID_HUAWEI 0x12D1
93// INQ Mobile's USB Vendor ID
94#define VENDOR_ID_INQ_MOBILE 0x2314
95// Intel's USB Vendor ID
96#define VENDOR_ID_INTEL 0x8087
DanielMo631c8ec2014-03-26 15:33:23 +080097// Intermec's USB Vendor ID
98#define VENDOR_ID_INTERMEC 0x067e
Colin Crossd8a76372014-01-05 18:19:51 -080099// IRiver's USB Vendor ID
100#define VENDOR_ID_IRIVER 0x2420
101// K-Touch's USB Vendor ID
102#define VENDOR_ID_K_TOUCH 0x24E3
103// KT Tech's USB Vendor ID
104#define VENDOR_ID_KT_TECH 0x2116
105// Kobo's USB Vendor ID
106#define VENDOR_ID_KOBO 0x2237
107// Kyocera's USB Vendor ID
108#define VENDOR_ID_KYOCERA 0x0482
109// Lab126's USB Vendor ID
110#define VENDOR_ID_LAB126 0x1949
111// Lenovo's USB Vendor ID
112#define VENDOR_ID_LENOVO 0x17EF
113// LenovoMobile's USB Vendor ID
114#define VENDOR_ID_LENOVOMOBILE 0x2006
115// LG's USB Vendor ID
116#define VENDOR_ID_LGE 0x1004
117// Lumigon's USB Vendor ID
118#define VENDOR_ID_LUMIGON 0x25E3
119// Motorola's USB Vendor ID
120#define VENDOR_ID_MOTOROLA 0x22b8
astonehuang3748b642013-08-01 15:23:17 +0800121// MSI's USB Vendor ID
astonehuang48437452013-08-28 10:53:17 +0800122#define VENDOR_ID_MSI 0x0DB0
Colin Crossd8a76372014-01-05 18:19:51 -0800123// MTK's USB Vendor ID
124#define VENDOR_ID_MTK 0x0e8d
125// NEC's USB Vendor ID
126#define VENDOR_ID_NEC 0x0409
127// B&N Nook's USB Vendor ID
128#define VENDOR_ID_NOOK 0x2080
129// Nvidia's USB Vendor ID
130#define VENDOR_ID_NVIDIA 0x0955
131// OPPO's USB Vendor ID
132#define VENDOR_ID_OPPO 0x22D9
133// On-The-Go-Video's USB Vendor ID
134#define VENDOR_ID_OTGV 0x2257
135// OUYA's USB Vendor ID
136#define VENDOR_ID_OUYA 0x2836
137// Pantech's USB Vendor ID
138#define VENDOR_ID_PANTECH 0x10A9
139// Pegatron's USB Vendor ID
140#define VENDOR_ID_PEGATRON 0x1D4D
141// Philips's USB Vendor ID
142#define VENDOR_ID_PHILIPS 0x0471
143// Panasonic Mobile Communication's USB Vendor ID
144#define VENDOR_ID_PMC 0x04DA
145// Positivo's USB Vendor ID
146#define VENDOR_ID_POSITIVO 0x1662
DanielMo57e36aa2014-04-16 12:13:18 +0800147// Prestigio's USB Vendor ID
148#define VENDOR_ID_PRESTIGIO 0x29e4
Colin Crossd8a76372014-01-05 18:19:51 -0800149// Qisda's USB Vendor ID
150#define VENDOR_ID_QISDA 0x1D45
151// Qualcomm's USB Vendor ID
152#define VENDOR_ID_QUALCOMM 0x05c6
153// Quanta's USB Vendor ID
154#define VENDOR_ID_QUANTA 0x0408
DanielMo9b2ca202013-08-27 11:19:32 +0800155// Rockchip's USB Vendor ID
156#define VENDOR_ID_ROCKCHIP 0x2207
Colin Crossd8a76372014-01-05 18:19:51 -0800157// Samsung's USB Vendor ID
158#define VENDOR_ID_SAMSUNG 0x04e8
159// Sharp's USB Vendor ID
160#define VENDOR_ID_SHARP 0x04dd
161// SK Telesys's USB Vendor ID
162#define VENDOR_ID_SK_TELESYS 0x1F53
163// Sony's USB Vendor ID
164#define VENDOR_ID_SONY 0x054C
165// Sony Ericsson's USB Vendor ID
166#define VENDOR_ID_SONY_ERICSSON 0x0FCE
167// T & A Mobile Phones' USB Vendor ID
168#define VENDOR_ID_T_AND_A 0x1BBB
DanielMoa36c61d2013-12-17 16:25:42 +0800169// TechFaith's USB Vendor ID
170#define VENDOR_ID_TECHFAITH 0x1d09
Colin Crossd8a76372014-01-05 18:19:51 -0800171// Teleepoch's USB Vendor ID
172#define VENDOR_ID_TELEEPOCH 0x2340
173// Texas Instruments's USB Vendor ID
174#define VENDOR_ID_TI 0x0451
175// Toshiba's USB Vendor ID
176#define VENDOR_ID_TOSHIBA 0x0930
Wing Tsengdcbbd862014-05-26 13:09:28 +0800177// Unowhy's USB Vendor ID
178#define VENDOR_ID_UNOWHY 0x2A49
Colin Crossd8a76372014-01-05 18:19:51 -0800179// Vizio's USB Vendor ID
180#define VENDOR_ID_VIZIO 0xE040
Wing Tsengdd1e4552013-08-13 11:50:47 +0800181// Wacom's USB Vendor ID
182#define VENDOR_ID_WACOM 0x0531
Colin Crossd8a76372014-01-05 18:19:51 -0800183// Xiaomi's USB Vendor ID
184#define VENDOR_ID_XIAOMI 0x2717
DanielMo6b1981b2013-09-04 09:35:48 +0800185// YotaDevices's USB Vendor ID
186#define VENDOR_ID_YOTADEVICES 0x2916
Colin Crossd8a76372014-01-05 18:19:51 -0800187// Yulong Coolpad's USB Vendor ID
188#define VENDOR_ID_YULONG_COOLPAD 0x1EBF
189// ZTE's USB Vendor ID
190#define VENDOR_ID_ZTE 0x19D2
191/* Keep the list above sorted alphabetically by #define name */
192
Xavier Ducrohet30a40332009-05-21 17:47:43 -0700193/** built-in vendor list */
Colin Crossd8a76372014-01-05 18:19:51 -0800194/* Keep the list below sorted alphabetically */
Xavier Ducrohet30a40332009-05-21 17:47:43 -0700195int builtInVendorIds[] = {
Robert CH Choue9d35632009-09-21 09:51:35 +0800196 VENDOR_ID_ACER,
DanielMoc087e9b2013-08-28 18:39:01 +0800197 VENDOR_ID_ALLWINNER,
DanielMo196fef62013-08-26 18:36:11 +0800198 VENDOR_ID_AMLOGIC,
Sam Lin79fb1492013-03-12 20:14:56 +0800199 VENDOR_ID_ANYDATA,
Colin Crossd8a76372014-01-05 18:19:51 -0800200 VENDOR_ID_ARCHOS,
201 VENDOR_ID_ASUS,
sunxiaoqi2726fa92013-03-15 16:17:37 +0800202 VENDOR_ID_BYD,
Colin Crossd8a76372014-01-05 18:19:51 -0800203 VENDOR_ID_COMPAL,
herman_lin5efccfe2014-05-05 03:43:20 +0800204 VENDOR_ID_COMPALCOMM,
Colin Crossd8a76372014-01-05 18:19:51 -0800205 VENDOR_ID_DELL,
ecsgms26a84e72013-07-24 16:13:49 +0800206 VENDOR_ID_ECS,
DanielMo1c22c5f2013-10-08 16:14:18 +0800207 VENDOR_ID_EMERGING_TECH,
Jon Sawyerb3212642014-01-11 22:59:18 -0800208 VENDOR_ID_EMERSON,
Colin Crossd8a76372014-01-05 18:19:51 -0800209 VENDOR_ID_FOXCONN,
210 VENDOR_ID_FUJITSU,
211 VENDOR_ID_FUNAI,
212 VENDOR_ID_GARMIN_ASUS,
213 VENDOR_ID_GIGABYTE,
Volker Moesker2b1f7ee2013-10-07 14:42:28 +0200214 VENDOR_ID_GIGASET,
xuefeng caie1febab2014-06-16 16:09:57 +0800215 VENDOR_ID_GIONEE,
Colin Crossd8a76372014-01-05 18:19:51 -0800216 VENDOR_ID_GOOGLE,
217 VENDOR_ID_HAIER,
218 VENDOR_ID_HARRIS,
219 VENDOR_ID_HISENSE,
Jon Sawyer78586e92014-01-08 08:14:26 -0800220 VENDOR_ID_HP,
Colin Crossd8a76372014-01-05 18:19:51 -0800221 VENDOR_ID_HTC,
222 VENDOR_ID_HUAWEI,
223 VENDOR_ID_INQ_MOBILE,
224 VENDOR_ID_INTEL,
DanielMo631c8ec2014-03-26 15:33:23 +0800225 VENDOR_ID_INTERMEC,
Colin Crossd8a76372014-01-05 18:19:51 -0800226 VENDOR_ID_IRIVER,
227 VENDOR_ID_KOBO,
228 VENDOR_ID_K_TOUCH,
229 VENDOR_ID_KT_TECH,
230 VENDOR_ID_KYOCERA,
231 VENDOR_ID_LAB126,
232 VENDOR_ID_LENOVO,
233 VENDOR_ID_LENOVOMOBILE,
234 VENDOR_ID_LGE,
235 VENDOR_ID_LUMIGON,
236 VENDOR_ID_MOTOROLA,
astonehuang3748b642013-08-01 15:23:17 +0800237 VENDOR_ID_MSI,
Colin Crossd8a76372014-01-05 18:19:51 -0800238 VENDOR_ID_MTK,
239 VENDOR_ID_NEC,
240 VENDOR_ID_NOOK,
241 VENDOR_ID_NVIDIA,
242 VENDOR_ID_OPPO,
243 VENDOR_ID_OTGV,
244 VENDOR_ID_OUYA,
245 VENDOR_ID_PANTECH,
246 VENDOR_ID_PEGATRON,
247 VENDOR_ID_PHILIPS,
248 VENDOR_ID_PMC,
249 VENDOR_ID_POSITIVO,
DanielMo57e36aa2014-04-16 12:13:18 +0800250 VENDOR_ID_PRESTIGIO,
Colin Crossd8a76372014-01-05 18:19:51 -0800251 VENDOR_ID_QISDA,
252 VENDOR_ID_QUALCOMM,
253 VENDOR_ID_QUANTA,
DanielMo9b2ca202013-08-27 11:19:32 +0800254 VENDOR_ID_ROCKCHIP,
Colin Crossd8a76372014-01-05 18:19:51 -0800255 VENDOR_ID_SAMSUNG,
256 VENDOR_ID_SHARP,
257 VENDOR_ID_SK_TELESYS,
258 VENDOR_ID_SONY,
259 VENDOR_ID_SONY_ERICSSON,
260 VENDOR_ID_T_AND_A,
DanielMoa36c61d2013-12-17 16:25:42 +0800261 VENDOR_ID_TECHFAITH,
Colin Crossd8a76372014-01-05 18:19:51 -0800262 VENDOR_ID_TELEEPOCH,
263 VENDOR_ID_TI,
264 VENDOR_ID_TOSHIBA,
Wing Tsengdcbbd862014-05-26 13:09:28 +0800265 VENDOR_ID_UNOWHY,
Colin Crossd8a76372014-01-05 18:19:51 -0800266 VENDOR_ID_VIZIO,
Wing Tsengdd1e4552013-08-13 11:50:47 +0800267 VENDOR_ID_WACOM,
Colin Crossd8a76372014-01-05 18:19:51 -0800268 VENDOR_ID_XIAOMI,
DanielMo6b1981b2013-09-04 09:35:48 +0800269 VENDOR_ID_YOTADEVICES,
Colin Crossd8a76372014-01-05 18:19:51 -0800270 VENDOR_ID_YULONG_COOLPAD,
271 VENDOR_ID_ZTE,
Xavier Ducrohet30a40332009-05-21 17:47:43 -0700272};
Colin Crossd8a76372014-01-05 18:19:51 -0800273/* Keep the list above sorted alphabetically */
Xavier Ducrohet30a40332009-05-21 17:47:43 -0700274
275#define BUILT_IN_VENDOR_COUNT (sizeof(builtInVendorIds)/sizeof(builtInVendorIds[0]))
276
277/* max number of supported vendor ids (built-in + 3rd party). increase as needed */
278#define VENDOR_COUNT_MAX 128
279
280int vendorIds[VENDOR_COUNT_MAX];
Xavier Ducrohet2ef5fc22009-05-20 17:33:53 -0700281unsigned vendorIdCount = 0;
282
Xavier Ducrohet30a40332009-05-21 17:47:43 -0700283int get_adb_usb_ini(char* buff, size_t len);
284
285void usb_vendors_init(void)
286{
287 if (VENDOR_COUNT_MAX < BUILT_IN_VENDOR_COUNT) {
288 fprintf(stderr, "VENDOR_COUNT_MAX not big enough for built-in vendor list.\n");
289 exit(2);
290 }
291
292 /* add the built-in vendors at the beginning of the array */
293 memcpy(vendorIds, builtInVendorIds, sizeof(builtInVendorIds));
294
295 /* default array size is the number of built-in vendors */
296 vendorIdCount = BUILT_IN_VENDOR_COUNT;
297
298 if (VENDOR_COUNT_MAX == BUILT_IN_VENDOR_COUNT)
299 return;
300
301 char temp[PATH_MAX];
302 if (get_adb_usb_ini(temp, sizeof(temp)) == 0) {
303 FILE * f = fopen(temp, "rt");
304
305 if (f != NULL) {
306 /* The vendor id file is pretty basic. 1 vendor id per line.
307 Lines starting with # are comments */
308 while (fgets(temp, sizeof(temp), f) != NULL) {
309 if (temp[0] == '#')
310 continue;
311
312 long value = strtol(temp, NULL, 0);
313 if (errno == EINVAL || errno == ERANGE || value > INT_MAX || value < 0) {
314 fprintf(stderr, "Invalid content in %s. Quitting.\n", ANDROID_ADB_INI);
315 exit(2);
316 }
317
318 vendorIds[vendorIdCount++] = (int)value;
319
320 /* make sure we don't go beyond the array */
321 if (vendorIdCount == VENDOR_COUNT_MAX) {
322 break;
323 }
324 }
Chris Dearman71bbfa42012-11-15 13:05:48 -0800325 fclose(f);
Xavier Ducrohet30a40332009-05-21 17:47:43 -0700326 }
327 }
Xavier Ducrohet2ef5fc22009-05-20 17:33:53 -0700328}
329
Xavier Ducrohet30a40332009-05-21 17:47:43 -0700330/* Utils methods */
331
332/* builds the path to the adb vendor id file. returns 0 if success */
333int build_path(char* buff, size_t len, const char* format, const char* home)
334{
Michael Richardsone545f0a2010-06-02 19:21:39 -0400335 if (snprintf(buff, len, format, home, ANDROID_PATH, ANDROID_ADB_INI) >= (signed)len) {
Xavier Ducrohet30a40332009-05-21 17:47:43 -0700336 return 1;
Xavier Ducrohet2ef5fc22009-05-20 17:33:53 -0700337 }
Xavier Ducrohet30a40332009-05-21 17:47:43 -0700338
339 return 0;
340}
341
342/* fills buff with the path to the adb vendor id file. returns 0 if success */
343int get_adb_usb_ini(char* buff, size_t len)
344{
345#ifdef _WIN32
346 const char* home = getenv("ANDROID_SDK_HOME");
347 if (home != NULL) {
348 return build_path(buff, len, "%s\\%s\\%s", home);
349 } else {
350 char path[MAX_PATH];
351 SHGetFolderPath( NULL, CSIDL_PROFILE, NULL, 0, path);
352 return build_path(buff, len, "%s\\%s\\%s", path);
353 }
354#else
355 const char* home = getenv("HOME");
356 if (home == NULL)
357 home = "/tmp";
358
359 return build_path(buff, len, "%s/%s/%s", home);
360#endif
Xavier Ducrohet2ef5fc22009-05-20 17:33:53 -0700361}