usb_vendors.c revision fd18127eb7f1b900beb72be35bbe9163bf95995a
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 <stdio.h> 20 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" 31#include "adb.h" 32 33#define ANDROID_PATH ".android" 34#define ANDROID_ADB_INI "adb_usb.ini" 35 36#define TRACE_TAG TRACE_USB 37 38/* Keep the list below sorted alphabetically by #define name */ 39// Acer's USB Vendor ID 40#define VENDOR_ID_ACER 0x0502 41// Allwinner's USB Vendor ID 42#define VENDOR_ID_ALLWINNER 0x1F3A 43// Amlogic's USB Vendor ID 44#define VENDOR_ID_AMLOGIC 0x1b8e 45// AnyDATA's USB Vendor ID 46#define VENDOR_ID_ANYDATA 0x16D5 47// Archos's USB Vendor ID 48#define VENDOR_ID_ARCHOS 0x0E79 49// Asus's USB Vendor ID 50#define VENDOR_ID_ASUS 0x0b05 51// BYD's USB Vendor ID 52#define VENDOR_ID_BYD 0x1D91 53// Compal's USB Vendor ID 54#define VENDOR_ID_COMPAL 0x04B7 55// Compalcomm's USB Vendor ID 56#define VENDOR_ID_COMPALCOMM 0x1219 57// Dell's USB Vendor ID 58#define VENDOR_ID_DELL 0x413c 59// ECS's USB Vendor ID 60#define VENDOR_ID_ECS 0x03fc 61// EMERGING_TECH's USB Vendor ID 62#define VENDOR_ID_EMERGING_TECH 0x297F 63// Emerson's USB Vendor ID 64#define VENDOR_ID_EMERSON 0x2207 65// 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 75// Gigaset's USB Vendor ID 76#define VENDOR_ID_GIGASET 0x1E85 77// Google's USB Vendor ID 78#define VENDOR_ID_GOOGLE 0x18d1 79// Haier's USB Vendor ID 80#define VENDOR_ID_HAIER 0x201E 81// Harris's USB Vendor ID 82#define VENDOR_ID_HARRIS 0x19A5 83// Hisense's USB Vendor ID 84#define VENDOR_ID_HISENSE 0x109b 85// HP's USB Vendor ID 86#define VENDOR_ID_HP 0x03f0 87// HTC's USB Vendor ID 88#define VENDOR_ID_HTC 0x0bb4 89// Huawei's USB Vendor ID 90#define VENDOR_ID_HUAWEI 0x12D1 91// INQ Mobile's USB Vendor ID 92#define VENDOR_ID_INQ_MOBILE 0x2314 93// Intel's USB Vendor ID 94#define VENDOR_ID_INTEL 0x8087 95// Intermec's USB Vendor ID 96#define VENDOR_ID_INTERMEC 0x067e 97// IRiver's USB Vendor ID 98#define VENDOR_ID_IRIVER 0x2420 99// K-Touch's USB Vendor ID 100#define VENDOR_ID_K_TOUCH 0x24E3 101// KT Tech's USB Vendor ID 102#define VENDOR_ID_KT_TECH 0x2116 103// Kobo's USB Vendor ID 104#define VENDOR_ID_KOBO 0x2237 105// Kyocera's USB Vendor ID 106#define VENDOR_ID_KYOCERA 0x0482 107// Lab126's USB Vendor ID 108#define VENDOR_ID_LAB126 0x1949 109// Lenovo's USB Vendor ID 110#define VENDOR_ID_LENOVO 0x17EF 111// LenovoMobile's USB Vendor ID 112#define VENDOR_ID_LENOVOMOBILE 0x2006 113// LG's USB Vendor ID 114#define VENDOR_ID_LGE 0x1004 115// Lumigon's USB Vendor ID 116#define VENDOR_ID_LUMIGON 0x25E3 117// Motorola's USB Vendor ID 118#define VENDOR_ID_MOTOROLA 0x22b8 119// MSI's USB Vendor ID 120#define VENDOR_ID_MSI 0x0DB0 121// MTK's USB Vendor ID 122#define VENDOR_ID_MTK 0x0e8d 123// NEC's USB Vendor ID 124#define VENDOR_ID_NEC 0x0409 125// B&N Nook's USB Vendor ID 126#define VENDOR_ID_NOOK 0x2080 127// Nvidia's USB Vendor ID 128#define VENDOR_ID_NVIDIA 0x0955 129// OPPO's USB Vendor ID 130#define VENDOR_ID_OPPO 0x22D9 131// On-The-Go-Video's USB Vendor ID 132#define VENDOR_ID_OTGV 0x2257 133// OUYA's USB Vendor ID 134#define VENDOR_ID_OUYA 0x2836 135// Pantech's USB Vendor ID 136#define VENDOR_ID_PANTECH 0x10A9 137// Pegatron's USB Vendor ID 138#define VENDOR_ID_PEGATRON 0x1D4D 139// Philips's USB Vendor ID 140#define VENDOR_ID_PHILIPS 0x0471 141// Panasonic Mobile Communication's USB Vendor ID 142#define VENDOR_ID_PMC 0x04DA 143// Positivo's USB Vendor ID 144#define VENDOR_ID_POSITIVO 0x1662 145// Prestigio's USB Vendor ID 146#define VENDOR_ID_PRESTIGIO 0x29e4 147// Qisda's USB Vendor ID 148#define VENDOR_ID_QISDA 0x1D45 149// Qualcomm's USB Vendor ID 150#define VENDOR_ID_QUALCOMM 0x05c6 151// Quanta's USB Vendor ID 152#define VENDOR_ID_QUANTA 0x0408 153// Rockchip's USB Vendor ID 154#define VENDOR_ID_ROCKCHIP 0x2207 155// Samsung's USB Vendor ID 156#define VENDOR_ID_SAMSUNG 0x04e8 157// Sharp's USB Vendor ID 158#define VENDOR_ID_SHARP 0x04dd 159// SK Telesys's USB Vendor ID 160#define VENDOR_ID_SK_TELESYS 0x1F53 161// Sony's USB Vendor ID 162#define VENDOR_ID_SONY 0x054C 163// Sony Ericsson's USB Vendor ID 164#define VENDOR_ID_SONY_ERICSSON 0x0FCE 165// T & A Mobile Phones' USB Vendor ID 166#define VENDOR_ID_T_AND_A 0x1BBB 167// TechFaith's USB Vendor ID 168#define VENDOR_ID_TECHFAITH 0x1d09 169// Teleepoch's USB Vendor ID 170#define VENDOR_ID_TELEEPOCH 0x2340 171// Texas Instruments's USB Vendor ID 172#define VENDOR_ID_TI 0x0451 173// Toshiba's USB Vendor ID 174#define VENDOR_ID_TOSHIBA 0x0930 175// Vizio's USB Vendor ID 176#define VENDOR_ID_VIZIO 0xE040 177// Wacom's USB Vendor ID 178#define VENDOR_ID_WACOM 0x0531 179// Xiaomi's USB Vendor ID 180#define VENDOR_ID_XIAOMI 0x2717 181// YotaDevices's USB Vendor ID 182#define VENDOR_ID_YOTADEVICES 0x2916 183// Yulong Coolpad's USB Vendor ID 184#define VENDOR_ID_YULONG_COOLPAD 0x1EBF 185// ZTE's USB Vendor ID 186#define VENDOR_ID_ZTE 0x19D2 187/* Keep the list above sorted alphabetically by #define name */ 188 189/** built-in vendor list */ 190/* Keep the list below sorted alphabetically */ 191int builtInVendorIds[] = { 192 VENDOR_ID_ACER, 193 VENDOR_ID_ALLWINNER, 194 VENDOR_ID_AMLOGIC, 195 VENDOR_ID_ANYDATA, 196 VENDOR_ID_ARCHOS, 197 VENDOR_ID_ASUS, 198 VENDOR_ID_BYD, 199 VENDOR_ID_COMPAL, 200 VENDOR_ID_COMPALCOMM, 201 VENDOR_ID_DELL, 202 VENDOR_ID_ECS, 203 VENDOR_ID_EMERGING_TECH, 204 VENDOR_ID_EMERSON, 205 VENDOR_ID_FOXCONN, 206 VENDOR_ID_FUJITSU, 207 VENDOR_ID_FUNAI, 208 VENDOR_ID_GARMIN_ASUS, 209 VENDOR_ID_GIGABYTE, 210 VENDOR_ID_GIGASET, 211 VENDOR_ID_GOOGLE, 212 VENDOR_ID_HAIER, 213 VENDOR_ID_HARRIS, 214 VENDOR_ID_HISENSE, 215 VENDOR_ID_HP, 216 VENDOR_ID_HTC, 217 VENDOR_ID_HUAWEI, 218 VENDOR_ID_INQ_MOBILE, 219 VENDOR_ID_INTEL, 220 VENDOR_ID_INTERMEC, 221 VENDOR_ID_IRIVER, 222 VENDOR_ID_KOBO, 223 VENDOR_ID_K_TOUCH, 224 VENDOR_ID_KT_TECH, 225 VENDOR_ID_KYOCERA, 226 VENDOR_ID_LAB126, 227 VENDOR_ID_LENOVO, 228 VENDOR_ID_LENOVOMOBILE, 229 VENDOR_ID_LGE, 230 VENDOR_ID_LUMIGON, 231 VENDOR_ID_MOTOROLA, 232 VENDOR_ID_MSI, 233 VENDOR_ID_MTK, 234 VENDOR_ID_NEC, 235 VENDOR_ID_NOOK, 236 VENDOR_ID_NVIDIA, 237 VENDOR_ID_OPPO, 238 VENDOR_ID_OTGV, 239 VENDOR_ID_OUYA, 240 VENDOR_ID_PANTECH, 241 VENDOR_ID_PEGATRON, 242 VENDOR_ID_PHILIPS, 243 VENDOR_ID_PMC, 244 VENDOR_ID_POSITIVO, 245 VENDOR_ID_PRESTIGIO, 246 VENDOR_ID_QISDA, 247 VENDOR_ID_QUALCOMM, 248 VENDOR_ID_QUANTA, 249 VENDOR_ID_ROCKCHIP, 250 VENDOR_ID_SAMSUNG, 251 VENDOR_ID_SHARP, 252 VENDOR_ID_SK_TELESYS, 253 VENDOR_ID_SONY, 254 VENDOR_ID_SONY_ERICSSON, 255 VENDOR_ID_T_AND_A, 256 VENDOR_ID_TECHFAITH, 257 VENDOR_ID_TELEEPOCH, 258 VENDOR_ID_TI, 259 VENDOR_ID_TOSHIBA, 260 VENDOR_ID_VIZIO, 261 VENDOR_ID_WACOM, 262 VENDOR_ID_XIAOMI, 263 VENDOR_ID_YOTADEVICES, 264 VENDOR_ID_YULONG_COOLPAD, 265 VENDOR_ID_ZTE, 266}; 267/* Keep the list above sorted alphabetically */ 268 269#define BUILT_IN_VENDOR_COUNT (sizeof(builtInVendorIds)/sizeof(builtInVendorIds[0])) 270 271/* max number of supported vendor ids (built-in + 3rd party). increase as needed */ 272#define VENDOR_COUNT_MAX 128 273 274int vendorIds[VENDOR_COUNT_MAX]; 275unsigned vendorIdCount = 0; 276 277int get_adb_usb_ini(char* buff, size_t len); 278 279void usb_vendors_init(void) 280{ 281 if (VENDOR_COUNT_MAX < BUILT_IN_VENDOR_COUNT) { 282 fprintf(stderr, "VENDOR_COUNT_MAX not big enough for built-in vendor list.\n"); 283 exit(2); 284 } 285 286 /* add the built-in vendors at the beginning of the array */ 287 memcpy(vendorIds, builtInVendorIds, sizeof(builtInVendorIds)); 288 289 /* default array size is the number of built-in vendors */ 290 vendorIdCount = BUILT_IN_VENDOR_COUNT; 291 292 if (VENDOR_COUNT_MAX == BUILT_IN_VENDOR_COUNT) 293 return; 294 295 char temp[PATH_MAX]; 296 if (get_adb_usb_ini(temp, sizeof(temp)) == 0) { 297 FILE * f = fopen(temp, "rt"); 298 299 if (f != NULL) { 300 /* The vendor id file is pretty basic. 1 vendor id per line. 301 Lines starting with # are comments */ 302 while (fgets(temp, sizeof(temp), f) != NULL) { 303 if (temp[0] == '#') 304 continue; 305 306 long value = strtol(temp, NULL, 0); 307 if (errno == EINVAL || errno == ERANGE || value > INT_MAX || value < 0) { 308 fprintf(stderr, "Invalid content in %s. Quitting.\n", ANDROID_ADB_INI); 309 exit(2); 310 } 311 312 vendorIds[vendorIdCount++] = (int)value; 313 314 /* make sure we don't go beyond the array */ 315 if (vendorIdCount == VENDOR_COUNT_MAX) { 316 break; 317 } 318 } 319 fclose(f); 320 } 321 } 322} 323 324/* Utils methods */ 325 326/* builds the path to the adb vendor id file. returns 0 if success */ 327int build_path(char* buff, size_t len, const char* format, const char* home) 328{ 329 if (snprintf(buff, len, format, home, ANDROID_PATH, ANDROID_ADB_INI) >= (signed)len) { 330 return 1; 331 } 332 333 return 0; 334} 335 336/* fills buff with the path to the adb vendor id file. returns 0 if success */ 337int get_adb_usb_ini(char* buff, size_t len) 338{ 339#ifdef _WIN32 340 const char* home = getenv("ANDROID_SDK_HOME"); 341 if (home != NULL) { 342 return build_path(buff, len, "%s\\%s\\%s", home); 343 } else { 344 char path[MAX_PATH]; 345 SHGetFolderPath( NULL, CSIDL_PROFILE, NULL, 0, path); 346 return build_path(buff, len, "%s\\%s\\%s", path); 347 } 348#else 349 const char* home = getenv("HOME"); 350 if (home == NULL) 351 home = "/tmp"; 352 353 return build_path(buff, len, "%s/%s/%s", home); 354#endif 355} 356