blob: 3a9316f3fcd960066d48dfd1f7013c4db26eb563 [file] [log] [blame]
Xavier Ducroheta09fbd12009-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 Ducroheta09fbd12009-05-20 17:33:53 -070019#include <stdio.h>
Xavier Ducroheta481d092009-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 Ducroheta09fbd12009-05-20 17:33:53 -070031#include "adb.h"
32
Xavier Ducroheta481d092009-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 Cross293717c2014-01-05 18:19:51 -080038/* Keep the list below sorted alphabetically by #define name */
Robert CH Chou7953b892009-09-21 09:51:35 +080039// Acer's USB Vendor ID
40#define VENDOR_ID_ACER 0x0502
DanielMo63f0f512013-08-28 18:39:01 +080041// Allwinner's USB Vendor ID
42#define VENDOR_ID_ALLWINNER 0x1F3A
DanielMod5dab6d2013-08-26 18:36:11 +080043// Amlogic's USB Vendor ID
44#define VENDOR_ID_AMLOGIC 0x1b8e
Sam Lindf6d7662013-03-12 20:14:56 +080045// AnyDATA's USB Vendor ID
46#define VENDOR_ID_ANYDATA 0x16D5
Colin Cross293717c2014-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
sunxiaoqi92eb5832013-03-15 16:17:37 +080051// BYD's USB Vendor ID
kongfanqingcabb75e2013-05-15 14:17:41 +080052#define VENDOR_ID_BYD 0x1D91
Colin Cross293717c2014-01-05 18:19:51 -080053// Compal's USB Vendor ID
54#define VENDOR_ID_COMPAL 0x1219
55// Dell's USB Vendor ID
56#define VENDOR_ID_DELL 0x413c
ecsgmscae8b9d2013-07-24 16:13:49 +080057// ECS's USB Vendor ID
58#define VENDOR_ID_ECS 0x03fc
DanielMofdd189c2013-10-08 16:14:18 +080059// EMERGING_TECH's USB Vendor ID
60#define VENDOR_ID_EMERGING_TECH 0x297F
Colin Cross293717c2014-01-05 18:19:51 -080061// Foxconn's USB Vendor ID
62#define VENDOR_ID_FOXCONN 0x0489
63// Fujitsu's USB Vendor ID
64#define VENDOR_ID_FUJITSU 0x04C5
65// Funai's USB Vendor ID
66#define VENDOR_ID_FUNAI 0x0F1C
67// Garmin-Asus's USB Vendor ID
68#define VENDOR_ID_GARMIN_ASUS 0x091E
69// Gigabyte's USB Vendor ID
70#define VENDOR_ID_GIGABYTE 0x0414
Volker Moesker319d8c12013-10-07 14:42:28 +020071// Gigaset's USB Vendor ID
72#define VENDOR_ID_GIGASET 0x1E85
Colin Cross293717c2014-01-05 18:19:51 -080073// Google's USB Vendor ID
74#define VENDOR_ID_GOOGLE 0x18d1
75// Haier's USB Vendor ID
76#define VENDOR_ID_HAIER 0x201E
77// Harris's USB Vendor ID
78#define VENDOR_ID_HARRIS 0x19A5
79// Hisense's USB Vendor ID
80#define VENDOR_ID_HISENSE 0x109b
81// HTC's USB Vendor ID
82#define VENDOR_ID_HTC 0x0bb4
83// Huawei's USB Vendor ID
84#define VENDOR_ID_HUAWEI 0x12D1
85// INQ Mobile's USB Vendor ID
86#define VENDOR_ID_INQ_MOBILE 0x2314
87// Intel's USB Vendor ID
88#define VENDOR_ID_INTEL 0x8087
89// IRiver's USB Vendor ID
90#define VENDOR_ID_IRIVER 0x2420
91// K-Touch's USB Vendor ID
92#define VENDOR_ID_K_TOUCH 0x24E3
93// KT Tech's USB Vendor ID
94#define VENDOR_ID_KT_TECH 0x2116
95// Kobo's USB Vendor ID
96#define VENDOR_ID_KOBO 0x2237
97// Kyocera's USB Vendor ID
98#define VENDOR_ID_KYOCERA 0x0482
99// Lab126's USB Vendor ID
100#define VENDOR_ID_LAB126 0x1949
101// Lenovo's USB Vendor ID
102#define VENDOR_ID_LENOVO 0x17EF
103// LenovoMobile's USB Vendor ID
104#define VENDOR_ID_LENOVOMOBILE 0x2006
105// LG's USB Vendor ID
106#define VENDOR_ID_LGE 0x1004
107// Lumigon's USB Vendor ID
108#define VENDOR_ID_LUMIGON 0x25E3
109// Motorola's USB Vendor ID
110#define VENDOR_ID_MOTOROLA 0x22b8
astonehuang307d96a2013-08-01 15:23:17 +0800111// MSI's USB Vendor ID
astonehuang48c5d7b2013-08-28 10:53:17 +0800112#define VENDOR_ID_MSI 0x0DB0
Colin Cross293717c2014-01-05 18:19:51 -0800113// MTK's USB Vendor ID
114#define VENDOR_ID_MTK 0x0e8d
115// NEC's USB Vendor ID
116#define VENDOR_ID_NEC 0x0409
117// B&N Nook's USB Vendor ID
118#define VENDOR_ID_NOOK 0x2080
119// Nvidia's USB Vendor ID
120#define VENDOR_ID_NVIDIA 0x0955
121// OPPO's USB Vendor ID
122#define VENDOR_ID_OPPO 0x22D9
123// On-The-Go-Video's USB Vendor ID
124#define VENDOR_ID_OTGV 0x2257
125// OUYA's USB Vendor ID
126#define VENDOR_ID_OUYA 0x2836
127// Pantech's USB Vendor ID
128#define VENDOR_ID_PANTECH 0x10A9
129// Pegatron's USB Vendor ID
130#define VENDOR_ID_PEGATRON 0x1D4D
131// Philips's USB Vendor ID
132#define VENDOR_ID_PHILIPS 0x0471
133// Panasonic Mobile Communication's USB Vendor ID
134#define VENDOR_ID_PMC 0x04DA
135// Positivo's USB Vendor ID
136#define VENDOR_ID_POSITIVO 0x1662
137// Qisda's USB Vendor ID
138#define VENDOR_ID_QISDA 0x1D45
139// Qualcomm's USB Vendor ID
140#define VENDOR_ID_QUALCOMM 0x05c6
141// Quanta's USB Vendor ID
142#define VENDOR_ID_QUANTA 0x0408
DanielMod0057c02013-08-27 11:19:32 +0800143// Rockchip's USB Vendor ID
144#define VENDOR_ID_ROCKCHIP 0x2207
Colin Cross293717c2014-01-05 18:19:51 -0800145// Samsung's USB Vendor ID
146#define VENDOR_ID_SAMSUNG 0x04e8
147// Sharp's USB Vendor ID
148#define VENDOR_ID_SHARP 0x04dd
149// SK Telesys's USB Vendor ID
150#define VENDOR_ID_SK_TELESYS 0x1F53
151// Sony's USB Vendor ID
152#define VENDOR_ID_SONY 0x054C
153// Sony Ericsson's USB Vendor ID
154#define VENDOR_ID_SONY_ERICSSON 0x0FCE
155// T & A Mobile Phones' USB Vendor ID
156#define VENDOR_ID_T_AND_A 0x1BBB
DanielMo402c2b92013-12-17 16:25:42 +0800157// TechFaith's USB Vendor ID
158#define VENDOR_ID_TECHFAITH 0x1d09
Colin Cross293717c2014-01-05 18:19:51 -0800159// Teleepoch's USB Vendor ID
160#define VENDOR_ID_TELEEPOCH 0x2340
161// Texas Instruments's USB Vendor ID
162#define VENDOR_ID_TI 0x0451
163// Toshiba's USB Vendor ID
164#define VENDOR_ID_TOSHIBA 0x0930
165// Vizio's USB Vendor ID
166#define VENDOR_ID_VIZIO 0xE040
Wing Tseng64a60292013-08-13 11:50:47 +0800167// Wacom's USB Vendor ID
168#define VENDOR_ID_WACOM 0x0531
Colin Cross293717c2014-01-05 18:19:51 -0800169// Xiaomi's USB Vendor ID
170#define VENDOR_ID_XIAOMI 0x2717
171// Yulong Coolpad's USB Vendor ID
172#define VENDOR_ID_YULONG_COOLPAD 0x1EBF
173// ZTE's USB Vendor ID
174#define VENDOR_ID_ZTE 0x19D2
175/* Keep the list above sorted alphabetically by #define name */
176
Xavier Ducroheta481d092009-05-21 17:47:43 -0700177/** built-in vendor list */
Colin Cross293717c2014-01-05 18:19:51 -0800178/* Keep the list below sorted alphabetically */
Xavier Ducroheta481d092009-05-21 17:47:43 -0700179int builtInVendorIds[] = {
Robert CH Chou7953b892009-09-21 09:51:35 +0800180 VENDOR_ID_ACER,
DanielMo63f0f512013-08-28 18:39:01 +0800181 VENDOR_ID_ALLWINNER,
DanielMod5dab6d2013-08-26 18:36:11 +0800182 VENDOR_ID_AMLOGIC,
Sam Lindf6d7662013-03-12 20:14:56 +0800183 VENDOR_ID_ANYDATA,
Colin Cross293717c2014-01-05 18:19:51 -0800184 VENDOR_ID_ARCHOS,
185 VENDOR_ID_ASUS,
sunxiaoqi92eb5832013-03-15 16:17:37 +0800186 VENDOR_ID_BYD,
Colin Cross293717c2014-01-05 18:19:51 -0800187 VENDOR_ID_COMPAL,
188 VENDOR_ID_DELL,
ecsgmscae8b9d2013-07-24 16:13:49 +0800189 VENDOR_ID_ECS,
DanielMofdd189c2013-10-08 16:14:18 +0800190 VENDOR_ID_EMERGING_TECH,
Colin Cross293717c2014-01-05 18:19:51 -0800191 VENDOR_ID_FOXCONN,
192 VENDOR_ID_FUJITSU,
193 VENDOR_ID_FUNAI,
194 VENDOR_ID_GARMIN_ASUS,
195 VENDOR_ID_GIGABYTE,
Volker Moesker319d8c12013-10-07 14:42:28 +0200196 VENDOR_ID_GIGASET,
Colin Cross293717c2014-01-05 18:19:51 -0800197 VENDOR_ID_GOOGLE,
198 VENDOR_ID_HAIER,
199 VENDOR_ID_HARRIS,
200 VENDOR_ID_HISENSE,
201 VENDOR_ID_HTC,
202 VENDOR_ID_HUAWEI,
203 VENDOR_ID_INQ_MOBILE,
204 VENDOR_ID_INTEL,
205 VENDOR_ID_IRIVER,
206 VENDOR_ID_KOBO,
207 VENDOR_ID_K_TOUCH,
208 VENDOR_ID_KT_TECH,
209 VENDOR_ID_KYOCERA,
210 VENDOR_ID_LAB126,
211 VENDOR_ID_LENOVO,
212 VENDOR_ID_LENOVOMOBILE,
213 VENDOR_ID_LGE,
214 VENDOR_ID_LUMIGON,
215 VENDOR_ID_MOTOROLA,
astonehuang307d96a2013-08-01 15:23:17 +0800216 VENDOR_ID_MSI,
Colin Cross293717c2014-01-05 18:19:51 -0800217 VENDOR_ID_MTK,
218 VENDOR_ID_NEC,
219 VENDOR_ID_NOOK,
220 VENDOR_ID_NVIDIA,
221 VENDOR_ID_OPPO,
222 VENDOR_ID_OTGV,
223 VENDOR_ID_OUYA,
224 VENDOR_ID_PANTECH,
225 VENDOR_ID_PEGATRON,
226 VENDOR_ID_PHILIPS,
227 VENDOR_ID_PMC,
228 VENDOR_ID_POSITIVO,
229 VENDOR_ID_QISDA,
230 VENDOR_ID_QUALCOMM,
231 VENDOR_ID_QUANTA,
DanielMod0057c02013-08-27 11:19:32 +0800232 VENDOR_ID_ROCKCHIP,
Colin Cross293717c2014-01-05 18:19:51 -0800233 VENDOR_ID_SAMSUNG,
234 VENDOR_ID_SHARP,
235 VENDOR_ID_SK_TELESYS,
236 VENDOR_ID_SONY,
237 VENDOR_ID_SONY_ERICSSON,
238 VENDOR_ID_T_AND_A,
DanielMo402c2b92013-12-17 16:25:42 +0800239 VENDOR_ID_TECHFAITH,
Colin Cross293717c2014-01-05 18:19:51 -0800240 VENDOR_ID_TELEEPOCH,
241 VENDOR_ID_TI,
242 VENDOR_ID_TOSHIBA,
243 VENDOR_ID_VIZIO,
Wing Tseng64a60292013-08-13 11:50:47 +0800244 VENDOR_ID_WACOM,
Colin Cross293717c2014-01-05 18:19:51 -0800245 VENDOR_ID_XIAOMI,
246 VENDOR_ID_YULONG_COOLPAD,
247 VENDOR_ID_ZTE,
Xavier Ducroheta481d092009-05-21 17:47:43 -0700248};
Colin Cross293717c2014-01-05 18:19:51 -0800249/* Keep the list above sorted alphabetically */
Xavier Ducroheta481d092009-05-21 17:47:43 -0700250
251#define BUILT_IN_VENDOR_COUNT (sizeof(builtInVendorIds)/sizeof(builtInVendorIds[0]))
252
253/* max number of supported vendor ids (built-in + 3rd party). increase as needed */
254#define VENDOR_COUNT_MAX 128
255
256int vendorIds[VENDOR_COUNT_MAX];
Xavier Ducroheta09fbd12009-05-20 17:33:53 -0700257unsigned vendorIdCount = 0;
258
Xavier Ducroheta481d092009-05-21 17:47:43 -0700259int get_adb_usb_ini(char* buff, size_t len);
260
261void usb_vendors_init(void)
262{
263 if (VENDOR_COUNT_MAX < BUILT_IN_VENDOR_COUNT) {
264 fprintf(stderr, "VENDOR_COUNT_MAX not big enough for built-in vendor list.\n");
265 exit(2);
266 }
267
268 /* add the built-in vendors at the beginning of the array */
269 memcpy(vendorIds, builtInVendorIds, sizeof(builtInVendorIds));
270
271 /* default array size is the number of built-in vendors */
272 vendorIdCount = BUILT_IN_VENDOR_COUNT;
273
274 if (VENDOR_COUNT_MAX == BUILT_IN_VENDOR_COUNT)
275 return;
276
277 char temp[PATH_MAX];
278 if (get_adb_usb_ini(temp, sizeof(temp)) == 0) {
279 FILE * f = fopen(temp, "rt");
280
281 if (f != NULL) {
282 /* The vendor id file is pretty basic. 1 vendor id per line.
283 Lines starting with # are comments */
284 while (fgets(temp, sizeof(temp), f) != NULL) {
285 if (temp[0] == '#')
286 continue;
287
288 long value = strtol(temp, NULL, 0);
289 if (errno == EINVAL || errno == ERANGE || value > INT_MAX || value < 0) {
290 fprintf(stderr, "Invalid content in %s. Quitting.\n", ANDROID_ADB_INI);
291 exit(2);
292 }
293
294 vendorIds[vendorIdCount++] = (int)value;
295
296 /* make sure we don't go beyond the array */
297 if (vendorIdCount == VENDOR_COUNT_MAX) {
298 break;
299 }
300 }
Chris Dearman60529e32012-11-15 13:05:48 -0800301 fclose(f);
Xavier Ducroheta481d092009-05-21 17:47:43 -0700302 }
303 }
Xavier Ducroheta09fbd12009-05-20 17:33:53 -0700304}
305
Xavier Ducroheta481d092009-05-21 17:47:43 -0700306/* Utils methods */
307
308/* builds the path to the adb vendor id file. returns 0 if success */
309int build_path(char* buff, size_t len, const char* format, const char* home)
310{
Michael Richardsoneb558b92010-06-02 19:21:39 -0400311 if (snprintf(buff, len, format, home, ANDROID_PATH, ANDROID_ADB_INI) >= (signed)len) {
Xavier Ducroheta481d092009-05-21 17:47:43 -0700312 return 1;
Xavier Ducroheta09fbd12009-05-20 17:33:53 -0700313 }
Xavier Ducroheta481d092009-05-21 17:47:43 -0700314
315 return 0;
316}
317
318/* fills buff with the path to the adb vendor id file. returns 0 if success */
319int get_adb_usb_ini(char* buff, size_t len)
320{
321#ifdef _WIN32
322 const char* home = getenv("ANDROID_SDK_HOME");
323 if (home != NULL) {
324 return build_path(buff, len, "%s\\%s\\%s", home);
325 } else {
326 char path[MAX_PATH];
327 SHGetFolderPath( NULL, CSIDL_PROFILE, NULL, 0, path);
328 return build_path(buff, len, "%s\\%s\\%s", path);
329 }
330#else
331 const char* home = getenv("HOME");
332 if (home == NULL)
333 home = "/tmp";
334
335 return build_path(buff, len, "%s/%s/%s", home);
336#endif
Xavier Ducroheta09fbd12009-05-20 17:33:53 -0700337}