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 |
DanielMo | c087e9b | 2013-08-28 18:39:01 +0800 | [diff] [blame] | 41 | // Allwinner's USB Vendor ID |
| 42 | #define VENDOR_ID_ALLWINNER 0x1F3A |
DanielMo | 196fef6 | 2013-08-26 18:36:11 +0800 | [diff] [blame] | 43 | // Amlogic's USB Vendor ID |
| 44 | #define VENDOR_ID_AMLOGIC 0x1b8e |
Sam Lin | 79fb149 | 2013-03-12 20:14:56 +0800 | [diff] [blame] | 45 | // AnyDATA's USB Vendor ID |
| 46 | #define VENDOR_ID_ANYDATA 0x16D5 |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame] | 47 | // Archos's USB Vendor ID |
| 48 | #define VENDOR_ID_ARCHOS 0x0E79 |
| 49 | // Asus's USB Vendor ID |
| 50 | #define VENDOR_ID_ASUS 0x0b05 |
sunxiaoqi | 2726fa9 | 2013-03-15 16:17:37 +0800 | [diff] [blame] | 51 | // BYD's USB Vendor ID |
kongfanqing | fbcd114 | 2013-05-15 14:17:41 +0800 | [diff] [blame] | 52 | #define VENDOR_ID_BYD 0x1D91 |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame] | 53 | // Compal's USB Vendor ID |
herman_lin | 5efccfe | 2014-05-05 03:43:20 +0800 | [diff] [blame] | 54 | #define VENDOR_ID_COMPAL 0x04B7 |
| 55 | // Compalcomm's USB Vendor ID |
| 56 | #define VENDOR_ID_COMPALCOMM 0x1219 |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame] | 57 | // Dell's USB Vendor ID |
| 58 | #define VENDOR_ID_DELL 0x413c |
ecsgms | 26a84e7 | 2013-07-24 16:13:49 +0800 | [diff] [blame] | 59 | // ECS's USB Vendor ID |
| 60 | #define VENDOR_ID_ECS 0x03fc |
DanielMo | 1c22c5f | 2013-10-08 16:14:18 +0800 | [diff] [blame] | 61 | // EMERGING_TECH's USB Vendor ID |
| 62 | #define VENDOR_ID_EMERGING_TECH 0x297F |
Jon Sawyer | b321264 | 2014-01-11 22:59:18 -0800 | [diff] [blame] | 63 | // Emerson's USB Vendor ID |
| 64 | #define VENDOR_ID_EMERSON 0x2207 |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame] | 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 |
Volker Moesker | 2b1f7ee | 2013-10-07 14:42:28 +0200 | [diff] [blame] | 75 | // Gigaset's USB Vendor ID |
| 76 | #define VENDOR_ID_GIGASET 0x1E85 |
xuefeng cai | e1febab | 2014-06-16 16:09:57 +0800 | [diff] [blame] | 77 | // GIONEE's USB Vendor ID |
| 78 | #define VENDOR_ID_GIONEE 0x271D |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame] | 79 | // 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 |
DanielMo | 3f4b725 | 2014-06-19 16:02:14 +0800 | [diff] [blame] | 87 | // Honeywell's USB Vendor ID |
| 88 | #define VENDOR_ID_HONEYWELL 0x0c2e |
Jon Sawyer | 78586e9 | 2014-01-08 08:14:26 -0800 | [diff] [blame] | 89 | // HP's USB Vendor ID |
| 90 | #define VENDOR_ID_HP 0x03f0 |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame] | 91 | // HTC's USB Vendor ID |
| 92 | #define VENDOR_ID_HTC 0x0bb4 |
| 93 | // Huawei's USB Vendor ID |
| 94 | #define VENDOR_ID_HUAWEI 0x12D1 |
| 95 | // INQ Mobile's USB Vendor ID |
| 96 | #define VENDOR_ID_INQ_MOBILE 0x2314 |
| 97 | // Intel's USB Vendor ID |
| 98 | #define VENDOR_ID_INTEL 0x8087 |
DanielMo | 631c8ec | 2014-03-26 15:33:23 +0800 | [diff] [blame] | 99 | // Intermec's USB Vendor ID |
| 100 | #define VENDOR_ID_INTERMEC 0x067e |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame] | 101 | // IRiver's USB Vendor ID |
| 102 | #define VENDOR_ID_IRIVER 0x2420 |
| 103 | // K-Touch's USB Vendor ID |
| 104 | #define VENDOR_ID_K_TOUCH 0x24E3 |
| 105 | // KT Tech's USB Vendor ID |
| 106 | #define VENDOR_ID_KT_TECH 0x2116 |
| 107 | // Kobo's USB Vendor ID |
| 108 | #define VENDOR_ID_KOBO 0x2237 |
| 109 | // Kyocera's USB Vendor ID |
| 110 | #define VENDOR_ID_KYOCERA 0x0482 |
| 111 | // Lab126's USB Vendor ID |
| 112 | #define VENDOR_ID_LAB126 0x1949 |
| 113 | // Lenovo's USB Vendor ID |
| 114 | #define VENDOR_ID_LENOVO 0x17EF |
| 115 | // LenovoMobile's USB Vendor ID |
| 116 | #define VENDOR_ID_LENOVOMOBILE 0x2006 |
| 117 | // LG's USB Vendor ID |
| 118 | #define VENDOR_ID_LGE 0x1004 |
| 119 | // Lumigon's USB Vendor ID |
| 120 | #define VENDOR_ID_LUMIGON 0x25E3 |
| 121 | // Motorola's USB Vendor ID |
| 122 | #define VENDOR_ID_MOTOROLA 0x22b8 |
astonehuang | 3748b64 | 2013-08-01 15:23:17 +0800 | [diff] [blame] | 123 | // MSI's USB Vendor ID |
astonehuang | 4843745 | 2013-08-28 10:53:17 +0800 | [diff] [blame] | 124 | #define VENDOR_ID_MSI 0x0DB0 |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame] | 125 | // MTK's USB Vendor ID |
| 126 | #define VENDOR_ID_MTK 0x0e8d |
| 127 | // NEC's USB Vendor ID |
| 128 | #define VENDOR_ID_NEC 0x0409 |
| 129 | // B&N Nook's USB Vendor ID |
| 130 | #define VENDOR_ID_NOOK 0x2080 |
| 131 | // Nvidia's USB Vendor ID |
| 132 | #define VENDOR_ID_NVIDIA 0x0955 |
| 133 | // OPPO's USB Vendor ID |
| 134 | #define VENDOR_ID_OPPO 0x22D9 |
| 135 | // On-The-Go-Video's USB Vendor ID |
| 136 | #define VENDOR_ID_OTGV 0x2257 |
| 137 | // OUYA's USB Vendor ID |
| 138 | #define VENDOR_ID_OUYA 0x2836 |
| 139 | // Pantech's USB Vendor ID |
| 140 | #define VENDOR_ID_PANTECH 0x10A9 |
| 141 | // Pegatron's USB Vendor ID |
| 142 | #define VENDOR_ID_PEGATRON 0x1D4D |
| 143 | // Philips's USB Vendor ID |
| 144 | #define VENDOR_ID_PHILIPS 0x0471 |
| 145 | // Panasonic Mobile Communication's USB Vendor ID |
| 146 | #define VENDOR_ID_PMC 0x04DA |
| 147 | // Positivo's USB Vendor ID |
| 148 | #define VENDOR_ID_POSITIVO 0x1662 |
DanielMo | 57e36aa | 2014-04-16 12:13:18 +0800 | [diff] [blame] | 149 | // Prestigio's USB Vendor ID |
| 150 | #define VENDOR_ID_PRESTIGIO 0x29e4 |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame] | 151 | // Qisda's USB Vendor ID |
| 152 | #define VENDOR_ID_QISDA 0x1D45 |
| 153 | // Qualcomm's USB Vendor ID |
| 154 | #define VENDOR_ID_QUALCOMM 0x05c6 |
| 155 | // Quanta's USB Vendor ID |
| 156 | #define VENDOR_ID_QUANTA 0x0408 |
DanielMo | 9b2ca20 | 2013-08-27 11:19:32 +0800 | [diff] [blame] | 157 | // Rockchip's USB Vendor ID |
| 158 | #define VENDOR_ID_ROCKCHIP 0x2207 |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame] | 159 | // Samsung's USB Vendor ID |
| 160 | #define VENDOR_ID_SAMSUNG 0x04e8 |
| 161 | // Sharp's USB Vendor ID |
| 162 | #define VENDOR_ID_SHARP 0x04dd |
| 163 | // SK Telesys's USB Vendor ID |
| 164 | #define VENDOR_ID_SK_TELESYS 0x1F53 |
Bao Haojun | a24a692 | 2014-03-31 16:12:40 +0800 | [diff] [blame] | 165 | // Smartisan's USB Vendor ID |
| 166 | #define VENDOR_ID_SMARTISAN 0x29a9 |
DanielMo | f6850d4 | 2014-07-25 11:15:24 +0800 | [diff] [blame^] | 167 | // Sonim Tech's USB Vendor ID |
| 168 | #define VENDOR_ID_SONIM_TECH 0x1d9c |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame] | 169 | // Sony's USB Vendor ID |
| 170 | #define VENDOR_ID_SONY 0x054C |
| 171 | // Sony Ericsson's USB Vendor ID |
| 172 | #define VENDOR_ID_SONY_ERICSSON 0x0FCE |
| 173 | // T & A Mobile Phones' USB Vendor ID |
| 174 | #define VENDOR_ID_T_AND_A 0x1BBB |
DanielMo | a36c61d | 2013-12-17 16:25:42 +0800 | [diff] [blame] | 175 | // TechFaith's USB Vendor ID |
| 176 | #define VENDOR_ID_TECHFAITH 0x1d09 |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame] | 177 | // Teleepoch's USB Vendor ID |
| 178 | #define VENDOR_ID_TELEEPOCH 0x2340 |
| 179 | // Texas Instruments's USB Vendor ID |
| 180 | #define VENDOR_ID_TI 0x0451 |
| 181 | // Toshiba's USB Vendor ID |
| 182 | #define VENDOR_ID_TOSHIBA 0x0930 |
Wing Tseng | dcbbd86 | 2014-05-26 13:09:28 +0800 | [diff] [blame] | 183 | // Unowhy's USB Vendor ID |
| 184 | #define VENDOR_ID_UNOWHY 0x2A49 |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame] | 185 | // Vizio's USB Vendor ID |
| 186 | #define VENDOR_ID_VIZIO 0xE040 |
Wing Tseng | dd1e455 | 2013-08-13 11:50:47 +0800 | [diff] [blame] | 187 | // Wacom's USB Vendor ID |
| 188 | #define VENDOR_ID_WACOM 0x0531 |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame] | 189 | // Xiaomi's USB Vendor ID |
| 190 | #define VENDOR_ID_XIAOMI 0x2717 |
DanielMo | 6b1981b | 2013-09-04 09:35:48 +0800 | [diff] [blame] | 191 | // YotaDevices's USB Vendor ID |
| 192 | #define VENDOR_ID_YOTADEVICES 0x2916 |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame] | 193 | // Yulong Coolpad's USB Vendor ID |
| 194 | #define VENDOR_ID_YULONG_COOLPAD 0x1EBF |
| 195 | // ZTE's USB Vendor ID |
| 196 | #define VENDOR_ID_ZTE 0x19D2 |
| 197 | /* Keep the list above sorted alphabetically by #define name */ |
| 198 | |
Xavier Ducrohet | 30a4033 | 2009-05-21 17:47:43 -0700 | [diff] [blame] | 199 | /** built-in vendor list */ |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame] | 200 | /* Keep the list below sorted alphabetically */ |
Xavier Ducrohet | 30a4033 | 2009-05-21 17:47:43 -0700 | [diff] [blame] | 201 | int builtInVendorIds[] = { |
Robert CH Chou | e9d3563 | 2009-09-21 09:51:35 +0800 | [diff] [blame] | 202 | VENDOR_ID_ACER, |
DanielMo | c087e9b | 2013-08-28 18:39:01 +0800 | [diff] [blame] | 203 | VENDOR_ID_ALLWINNER, |
DanielMo | 196fef6 | 2013-08-26 18:36:11 +0800 | [diff] [blame] | 204 | VENDOR_ID_AMLOGIC, |
Sam Lin | 79fb149 | 2013-03-12 20:14:56 +0800 | [diff] [blame] | 205 | VENDOR_ID_ANYDATA, |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame] | 206 | VENDOR_ID_ARCHOS, |
| 207 | VENDOR_ID_ASUS, |
sunxiaoqi | 2726fa9 | 2013-03-15 16:17:37 +0800 | [diff] [blame] | 208 | VENDOR_ID_BYD, |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame] | 209 | VENDOR_ID_COMPAL, |
herman_lin | 5efccfe | 2014-05-05 03:43:20 +0800 | [diff] [blame] | 210 | VENDOR_ID_COMPALCOMM, |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame] | 211 | VENDOR_ID_DELL, |
ecsgms | 26a84e7 | 2013-07-24 16:13:49 +0800 | [diff] [blame] | 212 | VENDOR_ID_ECS, |
DanielMo | 1c22c5f | 2013-10-08 16:14:18 +0800 | [diff] [blame] | 213 | VENDOR_ID_EMERGING_TECH, |
Jon Sawyer | b321264 | 2014-01-11 22:59:18 -0800 | [diff] [blame] | 214 | VENDOR_ID_EMERSON, |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame] | 215 | VENDOR_ID_FOXCONN, |
| 216 | VENDOR_ID_FUJITSU, |
| 217 | VENDOR_ID_FUNAI, |
| 218 | VENDOR_ID_GARMIN_ASUS, |
| 219 | VENDOR_ID_GIGABYTE, |
Volker Moesker | 2b1f7ee | 2013-10-07 14:42:28 +0200 | [diff] [blame] | 220 | VENDOR_ID_GIGASET, |
xuefeng cai | e1febab | 2014-06-16 16:09:57 +0800 | [diff] [blame] | 221 | VENDOR_ID_GIONEE, |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame] | 222 | VENDOR_ID_GOOGLE, |
| 223 | VENDOR_ID_HAIER, |
| 224 | VENDOR_ID_HARRIS, |
| 225 | VENDOR_ID_HISENSE, |
DanielMo | 3f4b725 | 2014-06-19 16:02:14 +0800 | [diff] [blame] | 226 | VENDOR_ID_HONEYWELL, |
Jon Sawyer | 78586e9 | 2014-01-08 08:14:26 -0800 | [diff] [blame] | 227 | VENDOR_ID_HP, |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame] | 228 | VENDOR_ID_HTC, |
| 229 | VENDOR_ID_HUAWEI, |
| 230 | VENDOR_ID_INQ_MOBILE, |
| 231 | VENDOR_ID_INTEL, |
DanielMo | 631c8ec | 2014-03-26 15:33:23 +0800 | [diff] [blame] | 232 | VENDOR_ID_INTERMEC, |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame] | 233 | VENDOR_ID_IRIVER, |
| 234 | VENDOR_ID_KOBO, |
| 235 | VENDOR_ID_K_TOUCH, |
| 236 | VENDOR_ID_KT_TECH, |
| 237 | VENDOR_ID_KYOCERA, |
| 238 | VENDOR_ID_LAB126, |
| 239 | VENDOR_ID_LENOVO, |
| 240 | VENDOR_ID_LENOVOMOBILE, |
| 241 | VENDOR_ID_LGE, |
| 242 | VENDOR_ID_LUMIGON, |
| 243 | VENDOR_ID_MOTOROLA, |
astonehuang | 3748b64 | 2013-08-01 15:23:17 +0800 | [diff] [blame] | 244 | VENDOR_ID_MSI, |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame] | 245 | VENDOR_ID_MTK, |
| 246 | VENDOR_ID_NEC, |
| 247 | VENDOR_ID_NOOK, |
| 248 | VENDOR_ID_NVIDIA, |
| 249 | VENDOR_ID_OPPO, |
| 250 | VENDOR_ID_OTGV, |
| 251 | VENDOR_ID_OUYA, |
| 252 | VENDOR_ID_PANTECH, |
| 253 | VENDOR_ID_PEGATRON, |
| 254 | VENDOR_ID_PHILIPS, |
| 255 | VENDOR_ID_PMC, |
| 256 | VENDOR_ID_POSITIVO, |
DanielMo | 57e36aa | 2014-04-16 12:13:18 +0800 | [diff] [blame] | 257 | VENDOR_ID_PRESTIGIO, |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame] | 258 | VENDOR_ID_QISDA, |
| 259 | VENDOR_ID_QUALCOMM, |
| 260 | VENDOR_ID_QUANTA, |
DanielMo | 9b2ca20 | 2013-08-27 11:19:32 +0800 | [diff] [blame] | 261 | VENDOR_ID_ROCKCHIP, |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame] | 262 | VENDOR_ID_SAMSUNG, |
| 263 | VENDOR_ID_SHARP, |
| 264 | VENDOR_ID_SK_TELESYS, |
Bao Haojun | a24a692 | 2014-03-31 16:12:40 +0800 | [diff] [blame] | 265 | VENDOR_ID_SMARTISAN, |
DanielMo | f6850d4 | 2014-07-25 11:15:24 +0800 | [diff] [blame^] | 266 | VENDOR_ID_SONIM_TECH, |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame] | 267 | VENDOR_ID_SONY, |
| 268 | VENDOR_ID_SONY_ERICSSON, |
| 269 | VENDOR_ID_T_AND_A, |
DanielMo | a36c61d | 2013-12-17 16:25:42 +0800 | [diff] [blame] | 270 | VENDOR_ID_TECHFAITH, |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame] | 271 | VENDOR_ID_TELEEPOCH, |
| 272 | VENDOR_ID_TI, |
| 273 | VENDOR_ID_TOSHIBA, |
Wing Tseng | dcbbd86 | 2014-05-26 13:09:28 +0800 | [diff] [blame] | 274 | VENDOR_ID_UNOWHY, |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame] | 275 | VENDOR_ID_VIZIO, |
Wing Tseng | dd1e455 | 2013-08-13 11:50:47 +0800 | [diff] [blame] | 276 | VENDOR_ID_WACOM, |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame] | 277 | VENDOR_ID_XIAOMI, |
DanielMo | 6b1981b | 2013-09-04 09:35:48 +0800 | [diff] [blame] | 278 | VENDOR_ID_YOTADEVICES, |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame] | 279 | VENDOR_ID_YULONG_COOLPAD, |
| 280 | VENDOR_ID_ZTE, |
Xavier Ducrohet | 30a4033 | 2009-05-21 17:47:43 -0700 | [diff] [blame] | 281 | }; |
Colin Cross | d8a7637 | 2014-01-05 18:19:51 -0800 | [diff] [blame] | 282 | /* Keep the list above sorted alphabetically */ |
Xavier Ducrohet | 30a4033 | 2009-05-21 17:47:43 -0700 | [diff] [blame] | 283 | |
| 284 | #define BUILT_IN_VENDOR_COUNT (sizeof(builtInVendorIds)/sizeof(builtInVendorIds[0])) |
| 285 | |
| 286 | /* max number of supported vendor ids (built-in + 3rd party). increase as needed */ |
| 287 | #define VENDOR_COUNT_MAX 128 |
| 288 | |
| 289 | int vendorIds[VENDOR_COUNT_MAX]; |
Xavier Ducrohet | 2ef5fc2 | 2009-05-20 17:33:53 -0700 | [diff] [blame] | 290 | unsigned vendorIdCount = 0; |
| 291 | |
Xavier Ducrohet | 30a4033 | 2009-05-21 17:47:43 -0700 | [diff] [blame] | 292 | int get_adb_usb_ini(char* buff, size_t len); |
| 293 | |
| 294 | void usb_vendors_init(void) |
| 295 | { |
| 296 | if (VENDOR_COUNT_MAX < BUILT_IN_VENDOR_COUNT) { |
| 297 | fprintf(stderr, "VENDOR_COUNT_MAX not big enough for built-in vendor list.\n"); |
| 298 | exit(2); |
| 299 | } |
| 300 | |
| 301 | /* add the built-in vendors at the beginning of the array */ |
| 302 | memcpy(vendorIds, builtInVendorIds, sizeof(builtInVendorIds)); |
| 303 | |
| 304 | /* default array size is the number of built-in vendors */ |
| 305 | vendorIdCount = BUILT_IN_VENDOR_COUNT; |
| 306 | |
| 307 | if (VENDOR_COUNT_MAX == BUILT_IN_VENDOR_COUNT) |
| 308 | return; |
| 309 | |
| 310 | char temp[PATH_MAX]; |
| 311 | if (get_adb_usb_ini(temp, sizeof(temp)) == 0) { |
| 312 | FILE * f = fopen(temp, "rt"); |
| 313 | |
| 314 | if (f != NULL) { |
| 315 | /* The vendor id file is pretty basic. 1 vendor id per line. |
| 316 | Lines starting with # are comments */ |
| 317 | while (fgets(temp, sizeof(temp), f) != NULL) { |
| 318 | if (temp[0] == '#') |
| 319 | continue; |
| 320 | |
| 321 | long value = strtol(temp, NULL, 0); |
| 322 | if (errno == EINVAL || errno == ERANGE || value > INT_MAX || value < 0) { |
| 323 | fprintf(stderr, "Invalid content in %s. Quitting.\n", ANDROID_ADB_INI); |
| 324 | exit(2); |
| 325 | } |
| 326 | |
| 327 | vendorIds[vendorIdCount++] = (int)value; |
| 328 | |
| 329 | /* make sure we don't go beyond the array */ |
| 330 | if (vendorIdCount == VENDOR_COUNT_MAX) { |
| 331 | break; |
| 332 | } |
| 333 | } |
Chris Dearman | 71bbfa4 | 2012-11-15 13:05:48 -0800 | [diff] [blame] | 334 | fclose(f); |
Xavier Ducrohet | 30a4033 | 2009-05-21 17:47:43 -0700 | [diff] [blame] | 335 | } |
| 336 | } |
Xavier Ducrohet | 2ef5fc2 | 2009-05-20 17:33:53 -0700 | [diff] [blame] | 337 | } |
| 338 | |
Xavier Ducrohet | 30a4033 | 2009-05-21 17:47:43 -0700 | [diff] [blame] | 339 | /* Utils methods */ |
| 340 | |
| 341 | /* builds the path to the adb vendor id file. returns 0 if success */ |
| 342 | int build_path(char* buff, size_t len, const char* format, const char* home) |
| 343 | { |
Michael Richardson | e545f0a | 2010-06-02 19:21:39 -0400 | [diff] [blame] | 344 | 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] | 345 | return 1; |
Xavier Ducrohet | 2ef5fc2 | 2009-05-20 17:33:53 -0700 | [diff] [blame] | 346 | } |
Xavier Ducrohet | 30a4033 | 2009-05-21 17:47:43 -0700 | [diff] [blame] | 347 | |
| 348 | return 0; |
| 349 | } |
| 350 | |
| 351 | /* fills buff with the path to the adb vendor id file. returns 0 if success */ |
| 352 | int get_adb_usb_ini(char* buff, size_t len) |
| 353 | { |
| 354 | #ifdef _WIN32 |
| 355 | const char* home = getenv("ANDROID_SDK_HOME"); |
| 356 | if (home != NULL) { |
| 357 | return build_path(buff, len, "%s\\%s\\%s", home); |
| 358 | } else { |
| 359 | char path[MAX_PATH]; |
| 360 | SHGetFolderPath( NULL, CSIDL_PROFILE, NULL, 0, path); |
| 361 | return build_path(buff, len, "%s\\%s\\%s", path); |
| 362 | } |
| 363 | #else |
| 364 | const char* home = getenv("HOME"); |
| 365 | if (home == NULL) |
| 366 | home = "/tmp"; |
| 367 | |
| 368 | return build_path(buff, len, "%s/%s/%s", home); |
| 369 | #endif |
Xavier Ducrohet | 2ef5fc2 | 2009-05-20 17:33:53 -0700 | [diff] [blame] | 370 | } |