Xavier Ducrohet | 2ef5fc2 | 2009-05-20 17:33:53 -0700 | [diff] [blame] | 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 | |
Xavier Ducrohet | 2ef5fc2 | 2009-05-20 17:33:53 -0700 | [diff] [blame] | 19 | #include <stdio.h> |
Xavier Ducrohet | 30a4033 | 2009-05-21 17:47:43 -0700 | [diff] [blame] | 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" |
Xavier Ducrohet | 2ef5fc2 | 2009-05-20 17:33:53 -0700 | [diff] [blame] | 31 | #include "adb.h" |
| 32 | |
Xavier Ducrohet | 30a4033 | 2009-05-21 17:47:43 -0700 | [diff] [blame] | 33 | #define ANDROID_PATH ".android" |
| 34 | #define ANDROID_ADB_INI "adb_usb.ini" |
| 35 | |
| 36 | #define TRACE_TAG TRACE_USB |
| 37 | |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame^] | 38 | /* Keep the list below sorted alphabetically by #define name */ |
Robert CH Chou | e9d3563 | 2009-09-21 09:51:35 +0800 | [diff] [blame] | 39 | // Acer's USB Vendor ID |
| 40 | #define VENDOR_ID_ACER 0x0502 |
Sam Lin | 79fb149 | 2013-03-12 20:14:56 +0800 | [diff] [blame] | 41 | // AnyDATA's USB Vendor ID |
| 42 | #define VENDOR_ID_ANYDATA 0x16D5 |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame^] | 43 | // Archos's USB Vendor ID |
| 44 | #define VENDOR_ID_ARCHOS 0x0E79 |
| 45 | // Asus's USB Vendor ID |
| 46 | #define VENDOR_ID_ASUS 0x0b05 |
sunxiaoqi | 2726fa9 | 2013-03-15 16:17:37 +0800 | [diff] [blame] | 47 | // BYD's USB Vendor ID |
kongfanqing | fbcd114 | 2013-05-15 14:17:41 +0800 | [diff] [blame] | 48 | #define VENDOR_ID_BYD 0x1D91 |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame^] | 49 | // Compal's USB Vendor ID |
| 50 | #define VENDOR_ID_COMPAL 0x1219 |
| 51 | // Dell's USB Vendor ID |
| 52 | #define VENDOR_ID_DELL 0x413c |
ecsgms | 26a84e7 | 2013-07-24 16:13:49 +0800 | [diff] [blame] | 53 | // ECS's USB Vendor ID |
| 54 | #define VENDOR_ID_ECS 0x03fc |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame^] | 55 | // Foxconn's USB Vendor ID |
| 56 | #define VENDOR_ID_FOXCONN 0x0489 |
| 57 | // Fujitsu's USB Vendor ID |
| 58 | #define VENDOR_ID_FUJITSU 0x04C5 |
| 59 | // Funai's USB Vendor ID |
| 60 | #define VENDOR_ID_FUNAI 0x0F1C |
| 61 | // Garmin-Asus's USB Vendor ID |
| 62 | #define VENDOR_ID_GARMIN_ASUS 0x091E |
| 63 | // Gigabyte's USB Vendor ID |
| 64 | #define VENDOR_ID_GIGABYTE 0x0414 |
| 65 | // Google's USB Vendor ID |
| 66 | #define VENDOR_ID_GOOGLE 0x18d1 |
| 67 | // Haier's USB Vendor ID |
| 68 | #define VENDOR_ID_HAIER 0x201E |
| 69 | // Harris's USB Vendor ID |
| 70 | #define VENDOR_ID_HARRIS 0x19A5 |
| 71 | // Hisense's USB Vendor ID |
| 72 | #define VENDOR_ID_HISENSE 0x109b |
| 73 | // HTC's USB Vendor ID |
| 74 | #define VENDOR_ID_HTC 0x0bb4 |
| 75 | // Huawei's USB Vendor ID |
| 76 | #define VENDOR_ID_HUAWEI 0x12D1 |
| 77 | // INQ Mobile's USB Vendor ID |
| 78 | #define VENDOR_ID_INQ_MOBILE 0x2314 |
| 79 | // Intel's USB Vendor ID |
| 80 | #define VENDOR_ID_INTEL 0x8087 |
| 81 | // IRiver's USB Vendor ID |
| 82 | #define VENDOR_ID_IRIVER 0x2420 |
| 83 | // K-Touch's USB Vendor ID |
| 84 | #define VENDOR_ID_K_TOUCH 0x24E3 |
| 85 | // KT Tech's USB Vendor ID |
| 86 | #define VENDOR_ID_KT_TECH 0x2116 |
| 87 | // Kobo's USB Vendor ID |
| 88 | #define VENDOR_ID_KOBO 0x2237 |
| 89 | // Kyocera's USB Vendor ID |
| 90 | #define VENDOR_ID_KYOCERA 0x0482 |
| 91 | // Lab126's USB Vendor ID |
| 92 | #define VENDOR_ID_LAB126 0x1949 |
| 93 | // Lenovo's USB Vendor ID |
| 94 | #define VENDOR_ID_LENOVO 0x17EF |
| 95 | // LenovoMobile's USB Vendor ID |
| 96 | #define VENDOR_ID_LENOVOMOBILE 0x2006 |
| 97 | // LG's USB Vendor ID |
| 98 | #define VENDOR_ID_LGE 0x1004 |
| 99 | // Lumigon's USB Vendor ID |
| 100 | #define VENDOR_ID_LUMIGON 0x25E3 |
| 101 | // Motorola's USB Vendor ID |
| 102 | #define VENDOR_ID_MOTOROLA 0x22b8 |
astonehuang | 3748b64 | 2013-08-01 15:23:17 +0800 | [diff] [blame] | 103 | // MSI's USB Vendor ID |
astonehuang | 4843745 | 2013-08-28 10:53:17 +0800 | [diff] [blame] | 104 | #define VENDOR_ID_MSI 0x0DB0 |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame^] | 105 | // MTK's USB Vendor ID |
| 106 | #define VENDOR_ID_MTK 0x0e8d |
| 107 | // NEC's USB Vendor ID |
| 108 | #define VENDOR_ID_NEC 0x0409 |
| 109 | // B&N Nook's USB Vendor ID |
| 110 | #define VENDOR_ID_NOOK 0x2080 |
| 111 | // Nvidia's USB Vendor ID |
| 112 | #define VENDOR_ID_NVIDIA 0x0955 |
| 113 | // OPPO's USB Vendor ID |
| 114 | #define VENDOR_ID_OPPO 0x22D9 |
| 115 | // On-The-Go-Video's USB Vendor ID |
| 116 | #define VENDOR_ID_OTGV 0x2257 |
| 117 | // OUYA's USB Vendor ID |
| 118 | #define VENDOR_ID_OUYA 0x2836 |
| 119 | // Pantech's USB Vendor ID |
| 120 | #define VENDOR_ID_PANTECH 0x10A9 |
| 121 | // Pegatron's USB Vendor ID |
| 122 | #define VENDOR_ID_PEGATRON 0x1D4D |
| 123 | // Philips's USB Vendor ID |
| 124 | #define VENDOR_ID_PHILIPS 0x0471 |
| 125 | // Panasonic Mobile Communication's USB Vendor ID |
| 126 | #define VENDOR_ID_PMC 0x04DA |
| 127 | // Positivo's USB Vendor ID |
| 128 | #define VENDOR_ID_POSITIVO 0x1662 |
| 129 | // Qisda's USB Vendor ID |
| 130 | #define VENDOR_ID_QISDA 0x1D45 |
| 131 | // Qualcomm's USB Vendor ID |
| 132 | #define VENDOR_ID_QUALCOMM 0x05c6 |
| 133 | // Quanta's USB Vendor ID |
| 134 | #define VENDOR_ID_QUANTA 0x0408 |
| 135 | // Samsung's USB Vendor ID |
| 136 | #define VENDOR_ID_SAMSUNG 0x04e8 |
| 137 | // Sharp's USB Vendor ID |
| 138 | #define VENDOR_ID_SHARP 0x04dd |
| 139 | // SK Telesys's USB Vendor ID |
| 140 | #define VENDOR_ID_SK_TELESYS 0x1F53 |
| 141 | // Sony's USB Vendor ID |
| 142 | #define VENDOR_ID_SONY 0x054C |
| 143 | // Sony Ericsson's USB Vendor ID |
| 144 | #define VENDOR_ID_SONY_ERICSSON 0x0FCE |
| 145 | // T & A Mobile Phones' USB Vendor ID |
| 146 | #define VENDOR_ID_T_AND_A 0x1BBB |
| 147 | // Teleepoch's USB Vendor ID |
| 148 | #define VENDOR_ID_TELEEPOCH 0x2340 |
| 149 | // Texas Instruments's USB Vendor ID |
| 150 | #define VENDOR_ID_TI 0x0451 |
| 151 | // Toshiba's USB Vendor ID |
| 152 | #define VENDOR_ID_TOSHIBA 0x0930 |
| 153 | // Vizio's USB Vendor ID |
| 154 | #define VENDOR_ID_VIZIO 0xE040 |
Wing Tseng | dd1e455 | 2013-08-13 11:50:47 +0800 | [diff] [blame] | 155 | // Wacom's USB Vendor ID |
| 156 | #define VENDOR_ID_WACOM 0x0531 |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame^] | 157 | // Xiaomi's USB Vendor ID |
| 158 | #define VENDOR_ID_XIAOMI 0x2717 |
| 159 | // Yulong Coolpad's USB Vendor ID |
| 160 | #define VENDOR_ID_YULONG_COOLPAD 0x1EBF |
| 161 | // ZTE's USB Vendor ID |
| 162 | #define VENDOR_ID_ZTE 0x19D2 |
| 163 | /* Keep the list above sorted alphabetically by #define name */ |
| 164 | |
Xavier Ducrohet | 30a4033 | 2009-05-21 17:47:43 -0700 | [diff] [blame] | 165 | |
| 166 | /** built-in vendor list */ |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame^] | 167 | /* Keep the list below sorted alphabetically */ |
Xavier Ducrohet | 30a4033 | 2009-05-21 17:47:43 -0700 | [diff] [blame] | 168 | int builtInVendorIds[] = { |
Robert CH Chou | e9d3563 | 2009-09-21 09:51:35 +0800 | [diff] [blame] | 169 | VENDOR_ID_ACER, |
Sam Lin | 79fb149 | 2013-03-12 20:14:56 +0800 | [diff] [blame] | 170 | VENDOR_ID_ANYDATA, |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame^] | 171 | VENDOR_ID_ARCHOS, |
| 172 | VENDOR_ID_ASUS, |
sunxiaoqi | 2726fa9 | 2013-03-15 16:17:37 +0800 | [diff] [blame] | 173 | VENDOR_ID_BYD, |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame^] | 174 | VENDOR_ID_COMPAL, |
| 175 | VENDOR_ID_DELL, |
ecsgms | 26a84e7 | 2013-07-24 16:13:49 +0800 | [diff] [blame] | 176 | VENDOR_ID_ECS, |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame^] | 177 | VENDOR_ID_FOXCONN, |
| 178 | VENDOR_ID_FUJITSU, |
| 179 | VENDOR_ID_FUNAI, |
| 180 | VENDOR_ID_GARMIN_ASUS, |
| 181 | VENDOR_ID_GIGABYTE, |
| 182 | VENDOR_ID_GOOGLE, |
| 183 | VENDOR_ID_HAIER, |
| 184 | VENDOR_ID_HARRIS, |
| 185 | VENDOR_ID_HISENSE, |
| 186 | VENDOR_ID_HTC, |
| 187 | VENDOR_ID_HUAWEI, |
| 188 | VENDOR_ID_INQ_MOBILE, |
| 189 | VENDOR_ID_INTEL, |
| 190 | VENDOR_ID_IRIVER, |
| 191 | VENDOR_ID_KOBO, |
| 192 | VENDOR_ID_K_TOUCH, |
| 193 | VENDOR_ID_KT_TECH, |
| 194 | VENDOR_ID_KYOCERA, |
| 195 | VENDOR_ID_LAB126, |
| 196 | VENDOR_ID_LENOVO, |
| 197 | VENDOR_ID_LENOVOMOBILE, |
| 198 | VENDOR_ID_LGE, |
| 199 | VENDOR_ID_LUMIGON, |
| 200 | VENDOR_ID_MOTOROLA, |
astonehuang | 3748b64 | 2013-08-01 15:23:17 +0800 | [diff] [blame] | 201 | VENDOR_ID_MSI, |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame^] | 202 | VENDOR_ID_MTK, |
| 203 | VENDOR_ID_NEC, |
| 204 | VENDOR_ID_NOOK, |
| 205 | VENDOR_ID_NVIDIA, |
| 206 | VENDOR_ID_OPPO, |
| 207 | VENDOR_ID_OTGV, |
| 208 | VENDOR_ID_OUYA, |
| 209 | VENDOR_ID_PANTECH, |
| 210 | VENDOR_ID_PEGATRON, |
| 211 | VENDOR_ID_PHILIPS, |
| 212 | VENDOR_ID_PMC, |
| 213 | VENDOR_ID_POSITIVO, |
| 214 | VENDOR_ID_QISDA, |
| 215 | VENDOR_ID_QUALCOMM, |
| 216 | VENDOR_ID_QUANTA, |
| 217 | VENDOR_ID_SAMSUNG, |
| 218 | VENDOR_ID_SHARP, |
| 219 | VENDOR_ID_SK_TELESYS, |
| 220 | VENDOR_ID_SONY, |
| 221 | VENDOR_ID_SONY_ERICSSON, |
| 222 | VENDOR_ID_T_AND_A, |
| 223 | VENDOR_ID_TELEEPOCH, |
| 224 | VENDOR_ID_TI, |
| 225 | VENDOR_ID_TOSHIBA, |
| 226 | VENDOR_ID_VIZIO, |
Wing Tseng | dd1e455 | 2013-08-13 11:50:47 +0800 | [diff] [blame] | 227 | VENDOR_ID_WACOM, |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame^] | 228 | VENDOR_ID_XIAOMI, |
| 229 | VENDOR_ID_YULONG_COOLPAD, |
| 230 | VENDOR_ID_ZTE, |
Xavier Ducrohet | 30a4033 | 2009-05-21 17:47:43 -0700 | [diff] [blame] | 231 | }; |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame^] | 232 | /* Keep the list above sorted alphabetically */ |
Xavier Ducrohet | 30a4033 | 2009-05-21 17:47:43 -0700 | [diff] [blame] | 233 | |
| 234 | #define BUILT_IN_VENDOR_COUNT (sizeof(builtInVendorIds)/sizeof(builtInVendorIds[0])) |
| 235 | |
| 236 | /* max number of supported vendor ids (built-in + 3rd party). increase as needed */ |
| 237 | #define VENDOR_COUNT_MAX 128 |
| 238 | |
| 239 | int vendorIds[VENDOR_COUNT_MAX]; |
Xavier Ducrohet | 2ef5fc2 | 2009-05-20 17:33:53 -0700 | [diff] [blame] | 240 | unsigned vendorIdCount = 0; |
| 241 | |
Xavier Ducrohet | 30a4033 | 2009-05-21 17:47:43 -0700 | [diff] [blame] | 242 | int get_adb_usb_ini(char* buff, size_t len); |
| 243 | |
| 244 | void usb_vendors_init(void) |
| 245 | { |
| 246 | if (VENDOR_COUNT_MAX < BUILT_IN_VENDOR_COUNT) { |
| 247 | fprintf(stderr, "VENDOR_COUNT_MAX not big enough for built-in vendor list.\n"); |
| 248 | exit(2); |
| 249 | } |
| 250 | |
| 251 | /* add the built-in vendors at the beginning of the array */ |
| 252 | memcpy(vendorIds, builtInVendorIds, sizeof(builtInVendorIds)); |
| 253 | |
| 254 | /* default array size is the number of built-in vendors */ |
| 255 | vendorIdCount = BUILT_IN_VENDOR_COUNT; |
| 256 | |
| 257 | if (VENDOR_COUNT_MAX == BUILT_IN_VENDOR_COUNT) |
| 258 | return; |
| 259 | |
| 260 | char temp[PATH_MAX]; |
| 261 | if (get_adb_usb_ini(temp, sizeof(temp)) == 0) { |
| 262 | FILE * f = fopen(temp, "rt"); |
| 263 | |
| 264 | if (f != NULL) { |
| 265 | /* The vendor id file is pretty basic. 1 vendor id per line. |
| 266 | Lines starting with # are comments */ |
| 267 | while (fgets(temp, sizeof(temp), f) != NULL) { |
| 268 | if (temp[0] == '#') |
| 269 | continue; |
| 270 | |
| 271 | long value = strtol(temp, NULL, 0); |
| 272 | if (errno == EINVAL || errno == ERANGE || value > INT_MAX || value < 0) { |
| 273 | fprintf(stderr, "Invalid content in %s. Quitting.\n", ANDROID_ADB_INI); |
| 274 | exit(2); |
| 275 | } |
| 276 | |
| 277 | vendorIds[vendorIdCount++] = (int)value; |
| 278 | |
| 279 | /* make sure we don't go beyond the array */ |
| 280 | if (vendorIdCount == VENDOR_COUNT_MAX) { |
| 281 | break; |
| 282 | } |
| 283 | } |
Chris Dearman | 71bbfa4 | 2012-11-15 13:05:48 -0800 | [diff] [blame] | 284 | fclose(f); |
Xavier Ducrohet | 30a4033 | 2009-05-21 17:47:43 -0700 | [diff] [blame] | 285 | } |
| 286 | } |
Xavier Ducrohet | 2ef5fc2 | 2009-05-20 17:33:53 -0700 | [diff] [blame] | 287 | } |
| 288 | |
Xavier Ducrohet | 30a4033 | 2009-05-21 17:47:43 -0700 | [diff] [blame] | 289 | /* Utils methods */ |
| 290 | |
| 291 | /* builds the path to the adb vendor id file. returns 0 if success */ |
| 292 | int build_path(char* buff, size_t len, const char* format, const char* home) |
| 293 | { |
Michael Richardson | e545f0a | 2010-06-02 19:21:39 -0400 | [diff] [blame] | 294 | if (snprintf(buff, len, format, home, ANDROID_PATH, ANDROID_ADB_INI) >= (signed)len) { |
Xavier Ducrohet | 30a4033 | 2009-05-21 17:47:43 -0700 | [diff] [blame] | 295 | return 1; |
Xavier Ducrohet | 2ef5fc2 | 2009-05-20 17:33:53 -0700 | [diff] [blame] | 296 | } |
Xavier Ducrohet | 30a4033 | 2009-05-21 17:47:43 -0700 | [diff] [blame] | 297 | |
| 298 | return 0; |
| 299 | } |
| 300 | |
| 301 | /* fills buff with the path to the adb vendor id file. returns 0 if success */ |
| 302 | int get_adb_usb_ini(char* buff, size_t len) |
| 303 | { |
| 304 | #ifdef _WIN32 |
| 305 | const char* home = getenv("ANDROID_SDK_HOME"); |
| 306 | if (home != NULL) { |
| 307 | return build_path(buff, len, "%s\\%s\\%s", home); |
| 308 | } else { |
| 309 | char path[MAX_PATH]; |
| 310 | SHGetFolderPath( NULL, CSIDL_PROFILE, NULL, 0, path); |
| 311 | return build_path(buff, len, "%s\\%s\\%s", path); |
| 312 | } |
| 313 | #else |
| 314 | const char* home = getenv("HOME"); |
| 315 | if (home == NULL) |
| 316 | home = "/tmp"; |
| 317 | |
| 318 | return build_path(buff, len, "%s/%s/%s", home); |
| 319 | #endif |
Xavier Ducrohet | 2ef5fc2 | 2009-05-20 17:33:53 -0700 | [diff] [blame] | 320 | } |