181 182static const struct usb_device_id u3g_devs[] = { 183#define U3G_DEV(v,p,i) { USB_VPI(USB_VENDOR_##v, USB_PRODUCT_##v##_##p, i) } 184 U3G_DEV(ACERP, H10, 0), 185 U3G_DEV(AIRPLUS, MCD650, 0), 186 U3G_DEV(AIRPRIME, PC5220, 0), 187 U3G_DEV(ALINK, 3G, 0), 188 U3G_DEV(ALINK, 3GU, 0), 189 U3G_DEV(ALINK, DWM652U5, 0), 190 U3G_DEV(AMOI, H01, 0), 191 U3G_DEV(AMOI, H01A, 0), 192 U3G_DEV(AMOI, H02, 0), 193 U3G_DEV(ANYDATA, ADU_500A, 0), 194 U3G_DEV(ANYDATA, ADU_620UW, 0), 195 U3G_DEV(ANYDATA, ADU_E100X, 0), 196 U3G_DEV(AXESSTEL, DATAMODEM, 0), 197 U3G_DEV(CMOTECH, CDMA_MODEM1, 0), 198 U3G_DEV(CMOTECH, CGU628, U3GINIT_CMOTECH), 199 U3G_DEV(DELL, U5500, 0), 200 U3G_DEV(DELL, U5505, 0), 201 U3G_DEV(DELL, U5510, 0), 202 U3G_DEV(DELL, U5520, 0), 203 U3G_DEV(DELL, U5520_2, 0), 204 U3G_DEV(DELL, U5520_3, 0), 205 U3G_DEV(DELL, U5700, 0), 206 U3G_DEV(DELL, U5700_2, 0), 207 U3G_DEV(DELL, U5700_3, 0), 208 U3G_DEV(DELL, U5700_4, 0), 209 U3G_DEV(DELL, U5720, 0), 210 U3G_DEV(DELL, U5720_2, 0), 211 U3G_DEV(DELL, U5730, 0), 212 U3G_DEV(DELL, U5730_2, 0), 213 U3G_DEV(DELL, U5730_3, 0), 214 U3G_DEV(DELL, U740, 0), 215 U3G_DEV(DLINK3, DWM652, 0), 216 U3G_DEV(HP, EV2200, 0), 217 U3G_DEV(HP, HS2300, 0), 218 U3G_DEV(HUAWEI, E1401, U3GINIT_HUAWEI), 219 U3G_DEV(HUAWEI, E1402, U3GINIT_HUAWEI), 220 U3G_DEV(HUAWEI, E1403, U3GINIT_HUAWEI), 221 U3G_DEV(HUAWEI, E1404, U3GINIT_HUAWEI), 222 U3G_DEV(HUAWEI, E1405, U3GINIT_HUAWEI), 223 U3G_DEV(HUAWEI, E1406, U3GINIT_HUAWEI), 224 U3G_DEV(HUAWEI, E1407, U3GINIT_HUAWEI), 225 U3G_DEV(HUAWEI, E1408, U3GINIT_HUAWEI), 226 U3G_DEV(HUAWEI, E1409, U3GINIT_HUAWEI), 227 U3G_DEV(HUAWEI, E140A, U3GINIT_HUAWEI), 228 U3G_DEV(HUAWEI, E140B, U3GINIT_HUAWEI), 229 U3G_DEV(HUAWEI, E140D, U3GINIT_HUAWEI), 230 U3G_DEV(HUAWEI, E140E, U3GINIT_HUAWEI), 231 U3G_DEV(HUAWEI, E140F, U3GINIT_HUAWEI), 232 U3G_DEV(HUAWEI, E1410, U3GINIT_HUAWEI), 233 U3G_DEV(HUAWEI, E1411, U3GINIT_HUAWEI), 234 U3G_DEV(HUAWEI, E1412, U3GINIT_HUAWEI), 235 U3G_DEV(HUAWEI, E1413, U3GINIT_HUAWEI), 236 U3G_DEV(HUAWEI, E1414, U3GINIT_HUAWEI), 237 U3G_DEV(HUAWEI, E1415, U3GINIT_HUAWEI), 238 U3G_DEV(HUAWEI, E1416, U3GINIT_HUAWEI), 239 U3G_DEV(HUAWEI, E1417, U3GINIT_HUAWEI), 240 U3G_DEV(HUAWEI, E1418, U3GINIT_HUAWEI), 241 U3G_DEV(HUAWEI, E1419, U3GINIT_HUAWEI), 242 U3G_DEV(HUAWEI, E141A, U3GINIT_HUAWEI), 243 U3G_DEV(HUAWEI, E141B, U3GINIT_HUAWEI), 244 U3G_DEV(HUAWEI, E141C, U3GINIT_HUAWEI), 245 U3G_DEV(HUAWEI, E141D, U3GINIT_HUAWEI), 246 U3G_DEV(HUAWEI, E141E, U3GINIT_HUAWEI), 247 U3G_DEV(HUAWEI, E141F, U3GINIT_HUAWEI), 248 U3G_DEV(HUAWEI, E1420, U3GINIT_HUAWEI), 249 U3G_DEV(HUAWEI, E1421, U3GINIT_HUAWEI), 250 U3G_DEV(HUAWEI, E1422, U3GINIT_HUAWEI), 251 U3G_DEV(HUAWEI, E1423, U3GINIT_HUAWEI), 252 U3G_DEV(HUAWEI, E1424, U3GINIT_HUAWEI), 253 U3G_DEV(HUAWEI, E1425, U3GINIT_HUAWEI), 254 U3G_DEV(HUAWEI, E1426, U3GINIT_HUAWEI), 255 U3G_DEV(HUAWEI, E1427, U3GINIT_HUAWEI), 256 U3G_DEV(HUAWEI, E1428, U3GINIT_HUAWEI), 257 U3G_DEV(HUAWEI, E1429, U3GINIT_HUAWEI), 258 U3G_DEV(HUAWEI, E142A, U3GINIT_HUAWEI), 259 U3G_DEV(HUAWEI, E142B, U3GINIT_HUAWEI), 260 U3G_DEV(HUAWEI, E142C, U3GINIT_HUAWEI), 261 U3G_DEV(HUAWEI, E142D, U3GINIT_HUAWEI), 262 U3G_DEV(HUAWEI, E142E, U3GINIT_HUAWEI), 263 U3G_DEV(HUAWEI, E142F, U3GINIT_HUAWEI), 264 U3G_DEV(HUAWEI, E1430, U3GINIT_HUAWEI), 265 U3G_DEV(HUAWEI, E1431, U3GINIT_HUAWEI), 266 U3G_DEV(HUAWEI, E1432, U3GINIT_HUAWEI), 267 U3G_DEV(HUAWEI, E1433, U3GINIT_HUAWEI), 268 U3G_DEV(HUAWEI, E1434, U3GINIT_HUAWEI), 269 U3G_DEV(HUAWEI, E1435, U3GINIT_HUAWEI), 270 U3G_DEV(HUAWEI, E1436, U3GINIT_HUAWEI), 271 U3G_DEV(HUAWEI, E1437, U3GINIT_HUAWEI), 272 U3G_DEV(HUAWEI, E1438, U3GINIT_HUAWEI), 273 U3G_DEV(HUAWEI, E1439, U3GINIT_HUAWEI), 274 U3G_DEV(HUAWEI, E143A, U3GINIT_HUAWEI), 275 U3G_DEV(HUAWEI, E143B, U3GINIT_HUAWEI), 276 U3G_DEV(HUAWEI, E143C, U3GINIT_HUAWEI), 277 U3G_DEV(HUAWEI, E143D, U3GINIT_HUAWEI), 278 U3G_DEV(HUAWEI, E143E, U3GINIT_HUAWEI), 279 U3G_DEV(HUAWEI, E143F, U3GINIT_HUAWEI), 280 U3G_DEV(HUAWEI, E14AC, U3GINIT_HUAWEI), 281 U3G_DEV(HUAWEI, E180V, U3GINIT_HUAWEI), 282 U3G_DEV(HUAWEI, E220, U3GINIT_HUAWEI), 283 U3G_DEV(HUAWEI, E220BIS, U3GINIT_HUAWEI), 284 U3G_DEV(HUAWEI, MOBILE, U3GINIT_HUAWEI), 285 U3G_DEV(HUAWEI, E1752, U3GINIT_HUAWEISCSI), 286 U3G_DEV(KYOCERA2, CDMA_MSM_K, 0), 287 U3G_DEV(KYOCERA2, KPC680, 0), 288 U3G_DEV(LONGCHEER, WM66, U3GINIT_HUAWEI), 289 U3G_DEV(MERLIN, V620, 0), 290 U3G_DEV(NOVATEL, E725, 0), 291 U3G_DEV(NOVATEL, ES620, 0), 292 U3G_DEV(NOVATEL, ES620_2, 0), 293 U3G_DEV(NOVATEL, EU730, 0), 294 U3G_DEV(NOVATEL, EU740, 0), 295 U3G_DEV(NOVATEL, EU870D, 0), 296 U3G_DEV(NOVATEL, MC760, 0), 297 U3G_DEV(NOVATEL, MC950D, 0), 298 U3G_DEV(NOVATEL, U720, 0), 299 U3G_DEV(NOVATEL, U727, 0), 300 U3G_DEV(NOVATEL, U727_2, 0), 301 U3G_DEV(NOVATEL, U740, 0), 302 U3G_DEV(NOVATEL, U740_2, 0), 303 U3G_DEV(NOVATEL, U760, U3GINIT_SCSIEJECT), 304 U3G_DEV(NOVATEL, U870, 0), 305 U3G_DEV(NOVATEL, V620, 0), 306 U3G_DEV(NOVATEL, V640, 0), 307 U3G_DEV(NOVATEL, V720, 0), 308 U3G_DEV(NOVATEL, V740, 0), 309 U3G_DEV(NOVATEL, X950D, 0), 310 U3G_DEV(NOVATEL, XU870, 0), 311 U3G_DEV(OPTION, E6500, 0), 312 U3G_DEV(OPTION, E6501, 0), 313 U3G_DEV(OPTION, E6601, 0), 314 U3G_DEV(OPTION, E6721, 0), 315 U3G_DEV(OPTION, E6741, 0), 316 U3G_DEV(OPTION, E6761, 0), 317 U3G_DEV(OPTION, E6800, 0), 318 U3G_DEV(OPTION, E7021, 0), 319 U3G_DEV(OPTION, E7041, 0), 320 U3G_DEV(OPTION, E7061, 0), 321 U3G_DEV(OPTION, E7100, 0), 322 U3G_DEV(OPTION, GE40X, 0), 323 U3G_DEV(OPTION, GT3G, 0), 324 U3G_DEV(OPTION, GT3GPLUS, 0), 325 U3G_DEV(OPTION, GT3GQUAD, 0), 326 U3G_DEV(OPTION, GT3G_1, 0), 327 U3G_DEV(OPTION, GT3G_2, 0), 328 U3G_DEV(OPTION, GT3G_3, 0), 329 U3G_DEV(OPTION, GT3G_4, 0), 330 U3G_DEV(OPTION, GT3G_5, 0), 331 U3G_DEV(OPTION, GT3G_6, 0), 332 U3G_DEV(OPTION, GTHSDPA, 0), 333 U3G_DEV(OPTION, GTM380, 0), 334 U3G_DEV(OPTION, GTMAX36, 0), 335 U3G_DEV(OPTION, GTMAX380HSUPAE, 0), 336 U3G_DEV(OPTION, GTMAXHSUPA, 0), 337 U3G_DEV(OPTION, GTMAXHSUPAE, 0), 338 U3G_DEV(OPTION, VODAFONEMC3G, 0), 339 U3G_DEV(QISDA, H20_1, 0), 340 U3G_DEV(QISDA, H20_2, 0), 341 U3G_DEV(QISDA, H21_1, 0), 342 U3G_DEV(QISDA, H21_2, 0), 343 U3G_DEV(QUALCOMM2, AC8700, 0), 344 U3G_DEV(QUALCOMM2, MF330, 0), 345 U3G_DEV(QUALCOMMINC, AC2726, 0), 346 U3G_DEV(QUALCOMMINC, AC8700, 0), 347 U3G_DEV(QUALCOMMINC, AC8710, 0), 348 U3G_DEV(QUALCOMMINC, CDMA_MSM, U3GINIT_SCSIEJECT), 349 U3G_DEV(QUALCOMMINC, E0002, 0), 350 U3G_DEV(QUALCOMMINC, E0003, 0), 351 U3G_DEV(QUALCOMMINC, E0004, 0), 352 U3G_DEV(QUALCOMMINC, E0005, 0), 353 U3G_DEV(QUALCOMMINC, E0006, 0), 354 U3G_DEV(QUALCOMMINC, E0007, 0), 355 U3G_DEV(QUALCOMMINC, E0008, 0), 356 U3G_DEV(QUALCOMMINC, E0009, 0), 357 U3G_DEV(QUALCOMMINC, E000A, 0), 358 U3G_DEV(QUALCOMMINC, E000B, 0), 359 U3G_DEV(QUALCOMMINC, E000C, 0), 360 U3G_DEV(QUALCOMMINC, E000D, 0), 361 U3G_DEV(QUALCOMMINC, E000E, 0), 362 U3G_DEV(QUALCOMMINC, E000F, 0), 363 U3G_DEV(QUALCOMMINC, E0010, 0), 364 U3G_DEV(QUALCOMMINC, E0011, 0), 365 U3G_DEV(QUALCOMMINC, E0012, 0), 366 U3G_DEV(QUALCOMMINC, E0013, 0), 367 U3G_DEV(QUALCOMMINC, E0014, 0), 368 U3G_DEV(QUALCOMMINC, E0017, 0), 369 U3G_DEV(QUALCOMMINC, E0018, 0), 370 U3G_DEV(QUALCOMMINC, E0019, 0), 371 U3G_DEV(QUALCOMMINC, E0020, 0), 372 U3G_DEV(QUALCOMMINC, E0021, 0), 373 U3G_DEV(QUALCOMMINC, E0022, 0), 374 U3G_DEV(QUALCOMMINC, E0023, 0), 375 U3G_DEV(QUALCOMMINC, E0024, 0), 376 U3G_DEV(QUALCOMMINC, E0025, 0), 377 U3G_DEV(QUALCOMMINC, E0026, 0), 378 U3G_DEV(QUALCOMMINC, E0027, 0), 379 U3G_DEV(QUALCOMMINC, E0028, 0), 380 U3G_DEV(QUALCOMMINC, E0029, 0), 381 U3G_DEV(QUALCOMMINC, E0030, 0), 382 U3G_DEV(QUALCOMMINC, E0032, 0), 383 U3G_DEV(QUALCOMMINC, E0033, 0), 384 U3G_DEV(QUALCOMMINC, E0037, 0), 385 U3G_DEV(QUALCOMMINC, E0039, 0), 386 U3G_DEV(QUALCOMMINC, E0042, 0), 387 U3G_DEV(QUALCOMMINC, E0043, 0), 388 U3G_DEV(QUALCOMMINC, E0048, 0), 389 U3G_DEV(QUALCOMMINC, E0049, 0), 390 U3G_DEV(QUALCOMMINC, E0051, 0), 391 U3G_DEV(QUALCOMMINC, E0052, 0), 392 U3G_DEV(QUALCOMMINC, E0054, 0), 393 U3G_DEV(QUALCOMMINC, E0055, 0), 394 U3G_DEV(QUALCOMMINC, E0057, 0), 395 U3G_DEV(QUALCOMMINC, E0058, 0), 396 U3G_DEV(QUALCOMMINC, E0059, 0), 397 U3G_DEV(QUALCOMMINC, E0060, 0), 398 U3G_DEV(QUALCOMMINC, E0061, 0), 399 U3G_DEV(QUALCOMMINC, E0062, 0), 400 U3G_DEV(QUALCOMMINC, E0063, 0), 401 U3G_DEV(QUALCOMMINC, E0064, 0), 402 U3G_DEV(QUALCOMMINC, E0066, 0), 403 U3G_DEV(QUALCOMMINC, E0069, 0), 404 U3G_DEV(QUALCOMMINC, E0070, 0), 405 U3G_DEV(QUALCOMMINC, E0073, 0), 406 U3G_DEV(QUALCOMMINC, E0076, 0), 407 U3G_DEV(QUALCOMMINC, E0078, 0), 408 U3G_DEV(QUALCOMMINC, E0082, 0), 409 U3G_DEV(QUALCOMMINC, E0086, 0), 410 U3G_DEV(QUALCOMMINC, E2002, 0), 411 U3G_DEV(QUALCOMMINC, E2003, 0), 412 U3G_DEV(QUALCOMMINC, MF626, 0), 413 U3G_DEV(QUALCOMMINC, MF628, 0), 414 U3G_DEV(QUALCOMMINC, MF633R, 0), 415 U3G_DEV(QUANTA, GKE, 0), 416 U3G_DEV(QUANTA, GLE, 0), 417 U3G_DEV(QUANTA, GLX, 0), 418 U3G_DEV(QUANTA, Q101, 0), 419 U3G_DEV(QUANTA, Q111, 0), 420 U3G_DEV(SIERRA, AC402, 0), 421 U3G_DEV(SIERRA, AC595U, 0), 422 U3G_DEV(SIERRA, AC597E, 0), 423 U3G_DEV(SIERRA, AC875E, 0), 424 U3G_DEV(SIERRA, AC875U, 0), 425 U3G_DEV(SIERRA, AC875U_2, 0), 426 U3G_DEV(SIERRA, AC880, 0), 427 U3G_DEV(SIERRA, AC880E, 0), 428 U3G_DEV(SIERRA, AC880U, 0), 429 U3G_DEV(SIERRA, AC881, 0), 430 U3G_DEV(SIERRA, AC881E, 0), 431 U3G_DEV(SIERRA, AC881U, 0), 432 U3G_DEV(SIERRA, AC885E, 0), 433 U3G_DEV(SIERRA, AC885E_2, 0), 434 U3G_DEV(SIERRA, AC885U, 0), 435 U3G_DEV(SIERRA, AIRCARD580, 0), 436 U3G_DEV(SIERRA, AIRCARD595, 0), 437 U3G_DEV(SIERRA, AIRCARD875, 0), 438 U3G_DEV(SIERRA, C22, 0), 439 U3G_DEV(SIERRA, C597, 0), 440 U3G_DEV(SIERRA, C888, 0), 441 U3G_DEV(SIERRA, E0029, 0), 442 U3G_DEV(SIERRA, E6892, 0), 443 U3G_DEV(SIERRA, E6893, 0), 444 U3G_DEV(SIERRA, EM5625, 0), 445 U3G_DEV(SIERRA, EM5725, 0), 446 U3G_DEV(SIERRA, MC5720, 0), 447 U3G_DEV(SIERRA, MC5720_2, 0), 448 U3G_DEV(SIERRA, MC5725, 0), 449 U3G_DEV(SIERRA, MC5727, 0), 450 U3G_DEV(SIERRA, MC5727_2, 0), 451 U3G_DEV(SIERRA, MC5728, 0), 452 U3G_DEV(SIERRA, MC8755, 0), 453 U3G_DEV(SIERRA, MC8755_2, 0), 454 U3G_DEV(SIERRA, MC8755_3, 0), 455 U3G_DEV(SIERRA, MC8755_4, 0), 456 U3G_DEV(SIERRA, MC8765, 0), 457 U3G_DEV(SIERRA, MC8765_2, 0), 458 U3G_DEV(SIERRA, MC8765_3, 0), 459 U3G_DEV(SIERRA, MC8775, 0), 460 U3G_DEV(SIERRA, MC8775_2, 0), 461 U3G_DEV(SIERRA, MC8780, 0), 462 U3G_DEV(SIERRA, MC8780_2, 0), 463 U3G_DEV(SIERRA, MC8780_3, 0), 464 U3G_DEV(SIERRA, MC8781, 0), 465 U3G_DEV(SIERRA, MC8781_2, 0), 466 U3G_DEV(SIERRA, MC8781_3, 0), 467 U3G_DEV(SIERRA, MC8785, 0), 468 U3G_DEV(SIERRA, MC8785_2, 0), 469 U3G_DEV(SIERRA, MC8790, 0), 470 U3G_DEV(SIERRA, MC8791, 0), 471 U3G_DEV(SIERRA, MC8792, 0), 472 U3G_DEV(SIERRA, MINI5725, 0), 473 U3G_DEV(SIERRA, T11, 0), 474 U3G_DEV(SIERRA, T598, 0), 475 U3G_DEV(SILABS, SAEL, U3GINIT_SAEL_M460), 476 U3G_DEV(STELERA, C105, 0), 477 U3G_DEV(STELERA, E1003, 0), 478 U3G_DEV(STELERA, E1004, 0), 479 U3G_DEV(STELERA, E1005, 0), 480 U3G_DEV(STELERA, E1006, 0), 481 U3G_DEV(STELERA, E1007, 0), 482 U3G_DEV(STELERA, E1008, 0), 483 U3G_DEV(STELERA, E1009, 0), 484 U3G_DEV(STELERA, E100A, 0), 485 U3G_DEV(STELERA, E100B, 0), 486 U3G_DEV(STELERA, E100C, 0), 487 U3G_DEV(STELERA, E100D, 0), 488 U3G_DEV(STELERA, E100E, 0), 489 U3G_DEV(STELERA, E100F, 0), 490 U3G_DEV(STELERA, E1010, 0), 491 U3G_DEV(STELERA, E1011, 0), 492 U3G_DEV(STELERA, E1012, 0), 493 U3G_DEV(TCTMOBILE, X060S, 0), 494 U3G_DEV(TELIT, UC864E, 0), 495 U3G_DEV(TELIT, UC864G, 0), 496 U3G_DEV(TLAYTECH, TEU800, 0), 497 U3G_DEV(TOSHIBA, G450, 0), 498 U3G_DEV(TOSHIBA, HSDPA, 0), 499 U3G_DEV(YISO, C893, 0), 500 /* Autoinstallers */ 501 U3G_DEV(NOVATEL, ZEROCD, U3GINIT_SCSIEJECT), 502 U3G_DEV(OPTION, GTICON322, U3GINIT_REZERO), 503 U3G_DEV(QUALCOMMINC, ZTE_STOR, U3GINIT_ZTESTOR), 504 U3G_DEV(QUALCOMMINC, ZTE_STOR2, U3GINIT_SCSIEJECT), 505 U3G_DEV(QUANTA, Q101_STOR, U3GINIT_SCSIEJECT), 506 U3G_DEV(SIERRA, TRUINSTALL, U3GINIT_SIERRA), 507#undef U3G_DEV 508}; 509 510static int 511u3g_sierra_init(struct usb_device *udev) 512{ 513 struct usb_device_request req; 514 515 req.bmRequestType = UT_VENDOR; 516 req.bRequest = UR_SET_INTERFACE; 517 USETW(req.wValue, UF_DEVICE_REMOTE_WAKEUP); 518 USETW(req.wIndex, UHF_PORT_CONNECTION); 519 USETW(req.wLength, 0); 520 521 if (usbd_do_request_flags(udev, NULL, &req, 522 NULL, 0, NULL, USB_MS_HZ)) { 523 /* ignore any errors */ 524 } 525 return (0); 526} 527 528static int 529u3g_huawei_init(struct usb_device *udev) 530{ 531 struct usb_device_request req; 532 533 req.bmRequestType = UT_WRITE_DEVICE; 534 req.bRequest = UR_SET_FEATURE; 535 USETW(req.wValue, UF_DEVICE_REMOTE_WAKEUP); 536 USETW(req.wIndex, UHF_PORT_SUSPEND); 537 USETW(req.wLength, 0); 538 539 if (usbd_do_request_flags(udev, NULL, &req, 540 NULL, 0, NULL, USB_MS_HZ)) { 541 /* ignore any errors */ 542 } 543 return (0); 544} 545 546static void 547u3g_sael_m460_init(struct usb_device *udev) 548{ 549 static const uint8_t setup[][24] = { 550 { 0x41, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 551 { 0x41, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 }, 552 { 0x41, 0x13, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 553 0x01, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 554 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 555 { 0xc1, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x40, 0x02 }, 556 { 0xc1, 0x08, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00 }, 557 { 0x41, 0x07, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 }, 558 { 0xc1, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }, 559 { 0x41, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00 }, 560 { 0x41, 0x07, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 }, 561 { 0x41, 0x03, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00 }, 562 { 0x41, 0x19, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 563 0x00, 0x00, 0x00, 0x00, 0x11, 0x13 }, 564 { 0x41, 0x13, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 565 0x09, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 566 0x0a, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00 }, 567 { 0x41, 0x12, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00 }, 568 { 0x41, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00 }, 569 { 0x41, 0x07, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 }, 570 { 0x41, 0x03, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00 }, 571 { 0x41, 0x19, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 572 0x00, 0x00, 0x00, 0x00, 0x11, 0x13 }, 573 { 0x41, 0x13, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 574 0x09, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 575 0x0a, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00 }, 576 { 0x41, 0x07, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 }, 577 }; 578 579 struct usb_device_request req; 580 usb_error_t err; 581 uint16_t len; 582 uint8_t buf[0x300]; 583 uint8_t n; 584 585 DPRINTFN(1, "\n"); 586 587 if (usbd_req_set_alt_interface_no(udev, NULL, 0, 0)) { 588 DPRINTFN(0, "Alt setting 0 failed\n"); 589 return; 590 } 591 592 for (n = 0; n != (sizeof(setup)/sizeof(setup[0])); n++) { 593 594 memcpy(&req, setup[n], sizeof(req)); 595 596 len = UGETW(req.wLength); 597 if (req.bmRequestType & UE_DIR_IN) { 598 if (len > sizeof(buf)) { 599 DPRINTFN(0, "too small buffer\n"); 600 continue; 601 } 602 err = usbd_do_request(udev, NULL, &req, buf); 603 } else { 604 if (len > (sizeof(setup[0]) - 8)) { 605 DPRINTFN(0, "too small buffer\n"); 606 continue; 607 } 608 err = usbd_do_request(udev, NULL, &req, 609 __DECONST(uint8_t *, &setup[n][8])); 610 } 611 if (err) { 612 DPRINTFN(1, "request %u failed\n", 613 (unsigned int)n); 614 /* 615 * Some of the requests will fail. Stop doing 616 * requests when we are getting timeouts so 617 * that we don't block the explore/attach 618 * thread forever. 619 */ 620 if (err == USB_ERR_TIMEOUT) 621 break; 622 } 623 } 624} 625 626/* 627 * The following function handles 3G modem devices (E220, Mobile, 628 * etc.) with auto-install flash disks for Windows/MacOSX on the first 629 * interface. After some command or some delay they change appearance 630 * to a modem. 631 */ 632static void 633u3g_test_autoinst(void *arg, struct usb_device *udev, 634 struct usb_attach_arg *uaa) 635{ 636 struct usb_interface *iface; 637 struct usb_interface_descriptor *id; 638 int error; 639 640 if (uaa->dev_state != UAA_DEV_READY) 641 return; 642 643 iface = usbd_get_iface(udev, 0); 644 if (iface == NULL) 645 return; 646 id = iface->idesc; 647 if (id == NULL || id->bInterfaceClass != UICLASS_MASS) 648 return; 649 if (usbd_lookup_id_by_uaa(u3g_devs, sizeof(u3g_devs), uaa)) 650 return; /* no device match */ 651 652 switch (USB_GET_DRIVER_INFO(uaa)) { 653 case U3GINIT_HUAWEI: 654 error = u3g_huawei_init(udev); 655 break; 656 case U3GINIT_HUAWEISCSI: 657 error = usb_msc_eject(udev, 0, MSC_EJECT_HUAWEI); 658 break; 659 case U3GINIT_SCSIEJECT: 660 error = usb_msc_eject(udev, 0, MSC_EJECT_STOPUNIT); 661 break; 662 case U3GINIT_REZERO: 663 error = usb_msc_eject(udev, 0, MSC_EJECT_REZERO); 664 break; 665 case U3GINIT_ZTESTOR: 666 error = usb_msc_eject(udev, 0, MSC_EJECT_ZTESTOR); 667 break; 668 case U3GINIT_CMOTECH: 669 error = usb_msc_eject(udev, 0, MSC_EJECT_CMOTECH); 670 break; 671 case U3GINIT_SIERRA: 672 error = u3g_sierra_init(udev); 673 break; 674 case U3GINIT_WAIT: 675 /* Just pretend we ejected, the card will timeout */ 676 error = 0; 677 break; 678 default: 679 /* no 3G eject quirks */ 680 error = EOPNOTSUPP; 681 break; 682 } 683 if (error == 0) { 684 /* success, mark the udev as disappearing */ 685 uaa->dev_state = UAA_DEV_EJECTING; 686 } 687} 688 689static int 690u3g_driver_loaded(struct module *mod, int what, void *arg) 691{ 692 switch (what) { 693 case MOD_LOAD: 694 /* register our autoinstall handler */ 695 u3g_etag = EVENTHANDLER_REGISTER(usb_dev_configured, 696 u3g_test_autoinst, NULL, EVENTHANDLER_PRI_ANY); 697 break; 698 case MOD_UNLOAD: 699 EVENTHANDLER_DEREGISTER(usb_dev_configured, u3g_etag); 700 break; 701 default: 702 return (EOPNOTSUPP); 703 } 704 return (0); 705} 706 707static int 708u3g_probe(device_t self) 709{ 710 struct usb_attach_arg *uaa = device_get_ivars(self); 711 712 if (uaa->usb_mode != USB_MODE_HOST) { 713 return (ENXIO); 714 } 715 if (uaa->info.bConfigIndex != U3G_CONFIG_INDEX) { 716 return (ENXIO); 717 } 718 if (uaa->info.bInterfaceClass != UICLASS_VENDOR) { 719 return (ENXIO); 720 } 721 return (usbd_lookup_id_by_uaa(u3g_devs, sizeof(u3g_devs), uaa)); 722} 723 724static int 725u3g_attach(device_t dev) 726{ 727 struct usb_config u3g_config_tmp[U3G_N_TRANSFER]; 728 struct usb_attach_arg *uaa = device_get_ivars(dev); 729 struct u3g_softc *sc = device_get_softc(dev); 730 struct usb_interface *iface; 731 struct usb_interface_descriptor *id; 732 uint32_t iface_valid; 733 int error, type, nports; 734 int ep, n; 735 uint8_t i; 736 737 DPRINTF("sc=%p\n", sc); 738 739 type = USB_GET_DRIVER_INFO(uaa); 740 if (type == U3GINIT_SAEL_M460) 741 u3g_sael_m460_init(uaa->device); 742 743 /* copy in USB config */ 744 for (n = 0; n != U3G_N_TRANSFER; n++) 745 u3g_config_tmp[n] = u3g_config[n]; 746 747 device_set_usb_desc(dev); 748 mtx_init(&sc->sc_mtx, "u3g", NULL, MTX_DEF); 749 750 sc->sc_udev = uaa->device; 751 752 /* Claim all interfaces on the device */ 753 iface_valid = 0; 754 for (i = uaa->info.bIfaceIndex; i < USB_IFACE_MAX; i++) { 755 iface = usbd_get_iface(uaa->device, i); 756 if (iface == NULL) 757 break; 758 id = usbd_get_interface_descriptor(iface); 759 if (id == NULL || id->bInterfaceClass != UICLASS_VENDOR) 760 continue; 761 usbd_set_parent_iface(uaa->device, i, uaa->info.bIfaceIndex); 762 iface_valid |= (1<<i); 763 } 764 765 i = 0; /* interface index */ 766 ep = 0; /* endpoint index */ 767 nports = 0; /* number of ports */ 768 while (i < USB_IFACE_MAX) { 769 if ((iface_valid & (1<<i)) == 0) { 770 i++; 771 continue; 772 } 773 774 /* update BULK endpoint index */ 775 for (n = 0; n < U3G_N_TRANSFER; n++) 776 u3g_config_tmp[n].ep_index = ep; 777 778 /* try to allocate a set of BULK endpoints */ 779 error = usbd_transfer_setup(uaa->device, &i, 780 sc->sc_xfer[nports], u3g_config_tmp, U3G_N_TRANSFER, 781 &sc->sc_ucom[nports], &sc->sc_mtx); 782 if (error) { 783 /* next interface */ 784 i++; 785 ep = 0; 786 continue; 787 } 788 789 /* set stall by default */ 790 mtx_lock(&sc->sc_mtx); 791 usbd_xfer_set_stall(sc->sc_xfer[nports][U3G_BULK_WR]); 792 usbd_xfer_set_stall(sc->sc_xfer[nports][U3G_BULK_RD]); 793 mtx_unlock(&sc->sc_mtx); 794 795 nports++; /* found one port */ 796 ep++; 797 if (nports == U3G_MAXPORTS) 798 break; 799 } 800 if (nports == 0) { 801 device_printf(dev, "no ports found\n"); 802 goto detach; 803 } 804 sc->sc_numports = nports; 805 806 error = ucom_attach(&sc->sc_super_ucom, sc->sc_ucom, 807 sc->sc_numports, sc, &u3g_callback, &sc->sc_mtx); 808 if (error) { 809 DPRINTF("ucom_attach failed\n"); 810 goto detach; 811 } 812 device_printf(dev, "Found %u port%s.\n", sc->sc_numports, 813 sc->sc_numports > 1 ? "s":""); 814 return (0); 815 816detach: 817 u3g_detach(dev); 818 return (ENXIO); 819} 820 821static int 822u3g_detach(device_t dev) 823{ 824 struct u3g_softc *sc = device_get_softc(dev); 825 uint8_t m; 826 827 DPRINTF("sc=%p\n", sc); 828 829 /* NOTE: It is not dangerous to detach more ports than attached! */ 830 ucom_detach(&sc->sc_super_ucom, sc->sc_ucom, U3G_MAXPORTS); 831 832 for (m = 0; m != U3G_MAXPORTS; m++) 833 usbd_transfer_unsetup(sc->sc_xfer[m], U3G_N_TRANSFER); 834 mtx_destroy(&sc->sc_mtx); 835 836 return (0); 837} 838 839static void 840u3g_start_read(struct ucom_softc *ucom) 841{ 842 struct u3g_softc *sc = ucom->sc_parent; 843 844 /* start read endpoint */ 845 usbd_transfer_start(sc->sc_xfer[ucom->sc_local_unit][U3G_BULK_RD]); 846 return; 847} 848 849static void 850u3g_stop_read(struct ucom_softc *ucom) 851{ 852 struct u3g_softc *sc = ucom->sc_parent; 853 854 /* stop read endpoint */ 855 usbd_transfer_stop(sc->sc_xfer[ucom->sc_local_unit][U3G_BULK_RD]); 856 return; 857} 858 859static void 860u3g_start_write(struct ucom_softc *ucom) 861{ 862 struct u3g_softc *sc = ucom->sc_parent; 863 864 usbd_transfer_start(sc->sc_xfer[ucom->sc_local_unit][U3G_BULK_WR]); 865 return; 866} 867 868static void 869u3g_stop_write(struct ucom_softc *ucom) 870{ 871 struct u3g_softc *sc = ucom->sc_parent; 872 873 usbd_transfer_stop(sc->sc_xfer[ucom->sc_local_unit][U3G_BULK_WR]); 874 return; 875} 876 877static void 878u3g_write_callback(struct usb_xfer *xfer, usb_error_t error) 879{ 880 struct ucom_softc *ucom = usbd_xfer_softc(xfer); 881 struct usb_page_cache *pc; 882 uint32_t actlen; 883 884 switch (USB_GET_STATE(xfer)) { 885 case USB_ST_TRANSFERRED: 886 case USB_ST_SETUP: 887tr_setup: 888 pc = usbd_xfer_get_frame(xfer, 0); 889 if (ucom_get_data(ucom, pc, 0, U3G_BSIZE, &actlen)) { 890 usbd_xfer_set_frame_len(xfer, 0, actlen); 891 usbd_transfer_submit(xfer); 892 } 893 break; 894 895 default: /* Error */ 896 if (error != USB_ERR_CANCELLED) { 897 /* do a builtin clear-stall */ 898 usbd_xfer_set_stall(xfer); 899 goto tr_setup; 900 } 901 break; 902 } 903 return; 904} 905 906static void 907u3g_read_callback(struct usb_xfer *xfer, usb_error_t error) 908{ 909 struct ucom_softc *ucom = usbd_xfer_softc(xfer); 910 struct usb_page_cache *pc; 911 int actlen; 912 913 usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL); 914 915 switch (USB_GET_STATE(xfer)) { 916 case USB_ST_TRANSFERRED: 917 pc = usbd_xfer_get_frame(xfer, 0); 918 ucom_put_data(ucom, pc, 0, actlen); 919 920 case USB_ST_SETUP: 921tr_setup: 922 usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer)); 923 usbd_transfer_submit(xfer); 924 break; 925 926 default: /* Error */ 927 if (error != USB_ERR_CANCELLED) { 928 /* do a builtin clear-stall */ 929 usbd_xfer_set_stall(xfer); 930 goto tr_setup; 931 } 932 break; 933 } 934 return; 935}
| 182 183static const struct usb_device_id u3g_devs[] = { 184#define U3G_DEV(v,p,i) { USB_VPI(USB_VENDOR_##v, USB_PRODUCT_##v##_##p, i) } 185 U3G_DEV(ACERP, H10, 0), 186 U3G_DEV(AIRPLUS, MCD650, 0), 187 U3G_DEV(AIRPRIME, PC5220, 0), 188 U3G_DEV(ALINK, 3G, 0), 189 U3G_DEV(ALINK, 3GU, 0), 190 U3G_DEV(ALINK, DWM652U5, 0), 191 U3G_DEV(AMOI, H01, 0), 192 U3G_DEV(AMOI, H01A, 0), 193 U3G_DEV(AMOI, H02, 0), 194 U3G_DEV(ANYDATA, ADU_500A, 0), 195 U3G_DEV(ANYDATA, ADU_620UW, 0), 196 U3G_DEV(ANYDATA, ADU_E100X, 0), 197 U3G_DEV(AXESSTEL, DATAMODEM, 0), 198 U3G_DEV(CMOTECH, CDMA_MODEM1, 0), 199 U3G_DEV(CMOTECH, CGU628, U3GINIT_CMOTECH), 200 U3G_DEV(DELL, U5500, 0), 201 U3G_DEV(DELL, U5505, 0), 202 U3G_DEV(DELL, U5510, 0), 203 U3G_DEV(DELL, U5520, 0), 204 U3G_DEV(DELL, U5520_2, 0), 205 U3G_DEV(DELL, U5520_3, 0), 206 U3G_DEV(DELL, U5700, 0), 207 U3G_DEV(DELL, U5700_2, 0), 208 U3G_DEV(DELL, U5700_3, 0), 209 U3G_DEV(DELL, U5700_4, 0), 210 U3G_DEV(DELL, U5720, 0), 211 U3G_DEV(DELL, U5720_2, 0), 212 U3G_DEV(DELL, U5730, 0), 213 U3G_DEV(DELL, U5730_2, 0), 214 U3G_DEV(DELL, U5730_3, 0), 215 U3G_DEV(DELL, U740, 0), 216 U3G_DEV(DLINK3, DWM652, 0), 217 U3G_DEV(HP, EV2200, 0), 218 U3G_DEV(HP, HS2300, 0), 219 U3G_DEV(HUAWEI, E1401, U3GINIT_HUAWEI), 220 U3G_DEV(HUAWEI, E1402, U3GINIT_HUAWEI), 221 U3G_DEV(HUAWEI, E1403, U3GINIT_HUAWEI), 222 U3G_DEV(HUAWEI, E1404, U3GINIT_HUAWEI), 223 U3G_DEV(HUAWEI, E1405, U3GINIT_HUAWEI), 224 U3G_DEV(HUAWEI, E1406, U3GINIT_HUAWEI), 225 U3G_DEV(HUAWEI, E1407, U3GINIT_HUAWEI), 226 U3G_DEV(HUAWEI, E1408, U3GINIT_HUAWEI), 227 U3G_DEV(HUAWEI, E1409, U3GINIT_HUAWEI), 228 U3G_DEV(HUAWEI, E140A, U3GINIT_HUAWEI), 229 U3G_DEV(HUAWEI, E140B, U3GINIT_HUAWEI), 230 U3G_DEV(HUAWEI, E140D, U3GINIT_HUAWEI), 231 U3G_DEV(HUAWEI, E140E, U3GINIT_HUAWEI), 232 U3G_DEV(HUAWEI, E140F, U3GINIT_HUAWEI), 233 U3G_DEV(HUAWEI, E1410, U3GINIT_HUAWEI), 234 U3G_DEV(HUAWEI, E1411, U3GINIT_HUAWEI), 235 U3G_DEV(HUAWEI, E1412, U3GINIT_HUAWEI), 236 U3G_DEV(HUAWEI, E1413, U3GINIT_HUAWEI), 237 U3G_DEV(HUAWEI, E1414, U3GINIT_HUAWEI), 238 U3G_DEV(HUAWEI, E1415, U3GINIT_HUAWEI), 239 U3G_DEV(HUAWEI, E1416, U3GINIT_HUAWEI), 240 U3G_DEV(HUAWEI, E1417, U3GINIT_HUAWEI), 241 U3G_DEV(HUAWEI, E1418, U3GINIT_HUAWEI), 242 U3G_DEV(HUAWEI, E1419, U3GINIT_HUAWEI), 243 U3G_DEV(HUAWEI, E141A, U3GINIT_HUAWEI), 244 U3G_DEV(HUAWEI, E141B, U3GINIT_HUAWEI), 245 U3G_DEV(HUAWEI, E141C, U3GINIT_HUAWEI), 246 U3G_DEV(HUAWEI, E141D, U3GINIT_HUAWEI), 247 U3G_DEV(HUAWEI, E141E, U3GINIT_HUAWEI), 248 U3G_DEV(HUAWEI, E141F, U3GINIT_HUAWEI), 249 U3G_DEV(HUAWEI, E1420, U3GINIT_HUAWEI), 250 U3G_DEV(HUAWEI, E1421, U3GINIT_HUAWEI), 251 U3G_DEV(HUAWEI, E1422, U3GINIT_HUAWEI), 252 U3G_DEV(HUAWEI, E1423, U3GINIT_HUAWEI), 253 U3G_DEV(HUAWEI, E1424, U3GINIT_HUAWEI), 254 U3G_DEV(HUAWEI, E1425, U3GINIT_HUAWEI), 255 U3G_DEV(HUAWEI, E1426, U3GINIT_HUAWEI), 256 U3G_DEV(HUAWEI, E1427, U3GINIT_HUAWEI), 257 U3G_DEV(HUAWEI, E1428, U3GINIT_HUAWEI), 258 U3G_DEV(HUAWEI, E1429, U3GINIT_HUAWEI), 259 U3G_DEV(HUAWEI, E142A, U3GINIT_HUAWEI), 260 U3G_DEV(HUAWEI, E142B, U3GINIT_HUAWEI), 261 U3G_DEV(HUAWEI, E142C, U3GINIT_HUAWEI), 262 U3G_DEV(HUAWEI, E142D, U3GINIT_HUAWEI), 263 U3G_DEV(HUAWEI, E142E, U3GINIT_HUAWEI), 264 U3G_DEV(HUAWEI, E142F, U3GINIT_HUAWEI), 265 U3G_DEV(HUAWEI, E1430, U3GINIT_HUAWEI), 266 U3G_DEV(HUAWEI, E1431, U3GINIT_HUAWEI), 267 U3G_DEV(HUAWEI, E1432, U3GINIT_HUAWEI), 268 U3G_DEV(HUAWEI, E1433, U3GINIT_HUAWEI), 269 U3G_DEV(HUAWEI, E1434, U3GINIT_HUAWEI), 270 U3G_DEV(HUAWEI, E1435, U3GINIT_HUAWEI), 271 U3G_DEV(HUAWEI, E1436, U3GINIT_HUAWEI), 272 U3G_DEV(HUAWEI, E1437, U3GINIT_HUAWEI), 273 U3G_DEV(HUAWEI, E1438, U3GINIT_HUAWEI), 274 U3G_DEV(HUAWEI, E1439, U3GINIT_HUAWEI), 275 U3G_DEV(HUAWEI, E143A, U3GINIT_HUAWEI), 276 U3G_DEV(HUAWEI, E143B, U3GINIT_HUAWEI), 277 U3G_DEV(HUAWEI, E143C, U3GINIT_HUAWEI), 278 U3G_DEV(HUAWEI, E143D, U3GINIT_HUAWEI), 279 U3G_DEV(HUAWEI, E143E, U3GINIT_HUAWEI), 280 U3G_DEV(HUAWEI, E143F, U3GINIT_HUAWEI), 281 U3G_DEV(HUAWEI, E14AC, U3GINIT_HUAWEI), 282 U3G_DEV(HUAWEI, E180V, U3GINIT_HUAWEI), 283 U3G_DEV(HUAWEI, E220, U3GINIT_HUAWEI), 284 U3G_DEV(HUAWEI, E220BIS, U3GINIT_HUAWEI), 285 U3G_DEV(HUAWEI, MOBILE, U3GINIT_HUAWEI), 286 U3G_DEV(HUAWEI, E1752, U3GINIT_HUAWEISCSI), 287 U3G_DEV(KYOCERA2, CDMA_MSM_K, 0), 288 U3G_DEV(KYOCERA2, KPC680, 0), 289 U3G_DEV(LONGCHEER, WM66, U3GINIT_HUAWEI), 290 U3G_DEV(MERLIN, V620, 0), 291 U3G_DEV(NOVATEL, E725, 0), 292 U3G_DEV(NOVATEL, ES620, 0), 293 U3G_DEV(NOVATEL, ES620_2, 0), 294 U3G_DEV(NOVATEL, EU730, 0), 295 U3G_DEV(NOVATEL, EU740, 0), 296 U3G_DEV(NOVATEL, EU870D, 0), 297 U3G_DEV(NOVATEL, MC760, 0), 298 U3G_DEV(NOVATEL, MC950D, 0), 299 U3G_DEV(NOVATEL, U720, 0), 300 U3G_DEV(NOVATEL, U727, 0), 301 U3G_DEV(NOVATEL, U727_2, 0), 302 U3G_DEV(NOVATEL, U740, 0), 303 U3G_DEV(NOVATEL, U740_2, 0), 304 U3G_DEV(NOVATEL, U760, U3GINIT_SCSIEJECT), 305 U3G_DEV(NOVATEL, U870, 0), 306 U3G_DEV(NOVATEL, V620, 0), 307 U3G_DEV(NOVATEL, V640, 0), 308 U3G_DEV(NOVATEL, V720, 0), 309 U3G_DEV(NOVATEL, V740, 0), 310 U3G_DEV(NOVATEL, X950D, 0), 311 U3G_DEV(NOVATEL, XU870, 0), 312 U3G_DEV(OPTION, E6500, 0), 313 U3G_DEV(OPTION, E6501, 0), 314 U3G_DEV(OPTION, E6601, 0), 315 U3G_DEV(OPTION, E6721, 0), 316 U3G_DEV(OPTION, E6741, 0), 317 U3G_DEV(OPTION, E6761, 0), 318 U3G_DEV(OPTION, E6800, 0), 319 U3G_DEV(OPTION, E7021, 0), 320 U3G_DEV(OPTION, E7041, 0), 321 U3G_DEV(OPTION, E7061, 0), 322 U3G_DEV(OPTION, E7100, 0), 323 U3G_DEV(OPTION, GE40X, 0), 324 U3G_DEV(OPTION, GT3G, 0), 325 U3G_DEV(OPTION, GT3GPLUS, 0), 326 U3G_DEV(OPTION, GT3GQUAD, 0), 327 U3G_DEV(OPTION, GT3G_1, 0), 328 U3G_DEV(OPTION, GT3G_2, 0), 329 U3G_DEV(OPTION, GT3G_3, 0), 330 U3G_DEV(OPTION, GT3G_4, 0), 331 U3G_DEV(OPTION, GT3G_5, 0), 332 U3G_DEV(OPTION, GT3G_6, 0), 333 U3G_DEV(OPTION, GTHSDPA, 0), 334 U3G_DEV(OPTION, GTM380, 0), 335 U3G_DEV(OPTION, GTMAX36, 0), 336 U3G_DEV(OPTION, GTMAX380HSUPAE, 0), 337 U3G_DEV(OPTION, GTMAXHSUPA, 0), 338 U3G_DEV(OPTION, GTMAXHSUPAE, 0), 339 U3G_DEV(OPTION, VODAFONEMC3G, 0), 340 U3G_DEV(QISDA, H20_1, 0), 341 U3G_DEV(QISDA, H20_2, 0), 342 U3G_DEV(QISDA, H21_1, 0), 343 U3G_DEV(QISDA, H21_2, 0), 344 U3G_DEV(QUALCOMM2, AC8700, 0), 345 U3G_DEV(QUALCOMM2, MF330, 0), 346 U3G_DEV(QUALCOMMINC, AC2726, 0), 347 U3G_DEV(QUALCOMMINC, AC8700, 0), 348 U3G_DEV(QUALCOMMINC, AC8710, 0), 349 U3G_DEV(QUALCOMMINC, CDMA_MSM, U3GINIT_SCSIEJECT), 350 U3G_DEV(QUALCOMMINC, E0002, 0), 351 U3G_DEV(QUALCOMMINC, E0003, 0), 352 U3G_DEV(QUALCOMMINC, E0004, 0), 353 U3G_DEV(QUALCOMMINC, E0005, 0), 354 U3G_DEV(QUALCOMMINC, E0006, 0), 355 U3G_DEV(QUALCOMMINC, E0007, 0), 356 U3G_DEV(QUALCOMMINC, E0008, 0), 357 U3G_DEV(QUALCOMMINC, E0009, 0), 358 U3G_DEV(QUALCOMMINC, E000A, 0), 359 U3G_DEV(QUALCOMMINC, E000B, 0), 360 U3G_DEV(QUALCOMMINC, E000C, 0), 361 U3G_DEV(QUALCOMMINC, E000D, 0), 362 U3G_DEV(QUALCOMMINC, E000E, 0), 363 U3G_DEV(QUALCOMMINC, E000F, 0), 364 U3G_DEV(QUALCOMMINC, E0010, 0), 365 U3G_DEV(QUALCOMMINC, E0011, 0), 366 U3G_DEV(QUALCOMMINC, E0012, 0), 367 U3G_DEV(QUALCOMMINC, E0013, 0), 368 U3G_DEV(QUALCOMMINC, E0014, 0), 369 U3G_DEV(QUALCOMMINC, E0017, 0), 370 U3G_DEV(QUALCOMMINC, E0018, 0), 371 U3G_DEV(QUALCOMMINC, E0019, 0), 372 U3G_DEV(QUALCOMMINC, E0020, 0), 373 U3G_DEV(QUALCOMMINC, E0021, 0), 374 U3G_DEV(QUALCOMMINC, E0022, 0), 375 U3G_DEV(QUALCOMMINC, E0023, 0), 376 U3G_DEV(QUALCOMMINC, E0024, 0), 377 U3G_DEV(QUALCOMMINC, E0025, 0), 378 U3G_DEV(QUALCOMMINC, E0026, 0), 379 U3G_DEV(QUALCOMMINC, E0027, 0), 380 U3G_DEV(QUALCOMMINC, E0028, 0), 381 U3G_DEV(QUALCOMMINC, E0029, 0), 382 U3G_DEV(QUALCOMMINC, E0030, 0), 383 U3G_DEV(QUALCOMMINC, E0032, 0), 384 U3G_DEV(QUALCOMMINC, E0033, 0), 385 U3G_DEV(QUALCOMMINC, E0037, 0), 386 U3G_DEV(QUALCOMMINC, E0039, 0), 387 U3G_DEV(QUALCOMMINC, E0042, 0), 388 U3G_DEV(QUALCOMMINC, E0043, 0), 389 U3G_DEV(QUALCOMMINC, E0048, 0), 390 U3G_DEV(QUALCOMMINC, E0049, 0), 391 U3G_DEV(QUALCOMMINC, E0051, 0), 392 U3G_DEV(QUALCOMMINC, E0052, 0), 393 U3G_DEV(QUALCOMMINC, E0054, 0), 394 U3G_DEV(QUALCOMMINC, E0055, 0), 395 U3G_DEV(QUALCOMMINC, E0057, 0), 396 U3G_DEV(QUALCOMMINC, E0058, 0), 397 U3G_DEV(QUALCOMMINC, E0059, 0), 398 U3G_DEV(QUALCOMMINC, E0060, 0), 399 U3G_DEV(QUALCOMMINC, E0061, 0), 400 U3G_DEV(QUALCOMMINC, E0062, 0), 401 U3G_DEV(QUALCOMMINC, E0063, 0), 402 U3G_DEV(QUALCOMMINC, E0064, 0), 403 U3G_DEV(QUALCOMMINC, E0066, 0), 404 U3G_DEV(QUALCOMMINC, E0069, 0), 405 U3G_DEV(QUALCOMMINC, E0070, 0), 406 U3G_DEV(QUALCOMMINC, E0073, 0), 407 U3G_DEV(QUALCOMMINC, E0076, 0), 408 U3G_DEV(QUALCOMMINC, E0078, 0), 409 U3G_DEV(QUALCOMMINC, E0082, 0), 410 U3G_DEV(QUALCOMMINC, E0086, 0), 411 U3G_DEV(QUALCOMMINC, E2002, 0), 412 U3G_DEV(QUALCOMMINC, E2003, 0), 413 U3G_DEV(QUALCOMMINC, MF626, 0), 414 U3G_DEV(QUALCOMMINC, MF628, 0), 415 U3G_DEV(QUALCOMMINC, MF633R, 0), 416 U3G_DEV(QUANTA, GKE, 0), 417 U3G_DEV(QUANTA, GLE, 0), 418 U3G_DEV(QUANTA, GLX, 0), 419 U3G_DEV(QUANTA, Q101, 0), 420 U3G_DEV(QUANTA, Q111, 0), 421 U3G_DEV(SIERRA, AC402, 0), 422 U3G_DEV(SIERRA, AC595U, 0), 423 U3G_DEV(SIERRA, AC597E, 0), 424 U3G_DEV(SIERRA, AC875E, 0), 425 U3G_DEV(SIERRA, AC875U, 0), 426 U3G_DEV(SIERRA, AC875U_2, 0), 427 U3G_DEV(SIERRA, AC880, 0), 428 U3G_DEV(SIERRA, AC880E, 0), 429 U3G_DEV(SIERRA, AC880U, 0), 430 U3G_DEV(SIERRA, AC881, 0), 431 U3G_DEV(SIERRA, AC881E, 0), 432 U3G_DEV(SIERRA, AC881U, 0), 433 U3G_DEV(SIERRA, AC885E, 0), 434 U3G_DEV(SIERRA, AC885E_2, 0), 435 U3G_DEV(SIERRA, AC885U, 0), 436 U3G_DEV(SIERRA, AIRCARD580, 0), 437 U3G_DEV(SIERRA, AIRCARD595, 0), 438 U3G_DEV(SIERRA, AIRCARD875, 0), 439 U3G_DEV(SIERRA, C22, 0), 440 U3G_DEV(SIERRA, C597, 0), 441 U3G_DEV(SIERRA, C888, 0), 442 U3G_DEV(SIERRA, E0029, 0), 443 U3G_DEV(SIERRA, E6892, 0), 444 U3G_DEV(SIERRA, E6893, 0), 445 U3G_DEV(SIERRA, EM5625, 0), 446 U3G_DEV(SIERRA, EM5725, 0), 447 U3G_DEV(SIERRA, MC5720, 0), 448 U3G_DEV(SIERRA, MC5720_2, 0), 449 U3G_DEV(SIERRA, MC5725, 0), 450 U3G_DEV(SIERRA, MC5727, 0), 451 U3G_DEV(SIERRA, MC5727_2, 0), 452 U3G_DEV(SIERRA, MC5728, 0), 453 U3G_DEV(SIERRA, MC8755, 0), 454 U3G_DEV(SIERRA, MC8755_2, 0), 455 U3G_DEV(SIERRA, MC8755_3, 0), 456 U3G_DEV(SIERRA, MC8755_4, 0), 457 U3G_DEV(SIERRA, MC8765, 0), 458 U3G_DEV(SIERRA, MC8765_2, 0), 459 U3G_DEV(SIERRA, MC8765_3, 0), 460 U3G_DEV(SIERRA, MC8775, 0), 461 U3G_DEV(SIERRA, MC8775_2, 0), 462 U3G_DEV(SIERRA, MC8780, 0), 463 U3G_DEV(SIERRA, MC8780_2, 0), 464 U3G_DEV(SIERRA, MC8780_3, 0), 465 U3G_DEV(SIERRA, MC8781, 0), 466 U3G_DEV(SIERRA, MC8781_2, 0), 467 U3G_DEV(SIERRA, MC8781_3, 0), 468 U3G_DEV(SIERRA, MC8785, 0), 469 U3G_DEV(SIERRA, MC8785_2, 0), 470 U3G_DEV(SIERRA, MC8790, 0), 471 U3G_DEV(SIERRA, MC8791, 0), 472 U3G_DEV(SIERRA, MC8792, 0), 473 U3G_DEV(SIERRA, MINI5725, 0), 474 U3G_DEV(SIERRA, T11, 0), 475 U3G_DEV(SIERRA, T598, 0), 476 U3G_DEV(SILABS, SAEL, U3GINIT_SAEL_M460), 477 U3G_DEV(STELERA, C105, 0), 478 U3G_DEV(STELERA, E1003, 0), 479 U3G_DEV(STELERA, E1004, 0), 480 U3G_DEV(STELERA, E1005, 0), 481 U3G_DEV(STELERA, E1006, 0), 482 U3G_DEV(STELERA, E1007, 0), 483 U3G_DEV(STELERA, E1008, 0), 484 U3G_DEV(STELERA, E1009, 0), 485 U3G_DEV(STELERA, E100A, 0), 486 U3G_DEV(STELERA, E100B, 0), 487 U3G_DEV(STELERA, E100C, 0), 488 U3G_DEV(STELERA, E100D, 0), 489 U3G_DEV(STELERA, E100E, 0), 490 U3G_DEV(STELERA, E100F, 0), 491 U3G_DEV(STELERA, E1010, 0), 492 U3G_DEV(STELERA, E1011, 0), 493 U3G_DEV(STELERA, E1012, 0), 494 U3G_DEV(TCTMOBILE, X060S, 0), 495 U3G_DEV(TELIT, UC864E, 0), 496 U3G_DEV(TELIT, UC864G, 0), 497 U3G_DEV(TLAYTECH, TEU800, 0), 498 U3G_DEV(TOSHIBA, G450, 0), 499 U3G_DEV(TOSHIBA, HSDPA, 0), 500 U3G_DEV(YISO, C893, 0), 501 /* Autoinstallers */ 502 U3G_DEV(NOVATEL, ZEROCD, U3GINIT_SCSIEJECT), 503 U3G_DEV(OPTION, GTICON322, U3GINIT_REZERO), 504 U3G_DEV(QUALCOMMINC, ZTE_STOR, U3GINIT_ZTESTOR), 505 U3G_DEV(QUALCOMMINC, ZTE_STOR2, U3GINIT_SCSIEJECT), 506 U3G_DEV(QUANTA, Q101_STOR, U3GINIT_SCSIEJECT), 507 U3G_DEV(SIERRA, TRUINSTALL, U3GINIT_SIERRA), 508#undef U3G_DEV 509}; 510 511static int 512u3g_sierra_init(struct usb_device *udev) 513{ 514 struct usb_device_request req; 515 516 req.bmRequestType = UT_VENDOR; 517 req.bRequest = UR_SET_INTERFACE; 518 USETW(req.wValue, UF_DEVICE_REMOTE_WAKEUP); 519 USETW(req.wIndex, UHF_PORT_CONNECTION); 520 USETW(req.wLength, 0); 521 522 if (usbd_do_request_flags(udev, NULL, &req, 523 NULL, 0, NULL, USB_MS_HZ)) { 524 /* ignore any errors */ 525 } 526 return (0); 527} 528 529static int 530u3g_huawei_init(struct usb_device *udev) 531{ 532 struct usb_device_request req; 533 534 req.bmRequestType = UT_WRITE_DEVICE; 535 req.bRequest = UR_SET_FEATURE; 536 USETW(req.wValue, UF_DEVICE_REMOTE_WAKEUP); 537 USETW(req.wIndex, UHF_PORT_SUSPEND); 538 USETW(req.wLength, 0); 539 540 if (usbd_do_request_flags(udev, NULL, &req, 541 NULL, 0, NULL, USB_MS_HZ)) { 542 /* ignore any errors */ 543 } 544 return (0); 545} 546 547static void 548u3g_sael_m460_init(struct usb_device *udev) 549{ 550 static const uint8_t setup[][24] = { 551 { 0x41, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 552 { 0x41, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 }, 553 { 0x41, 0x13, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 554 0x01, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 555 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 556 { 0xc1, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x40, 0x02 }, 557 { 0xc1, 0x08, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00 }, 558 { 0x41, 0x07, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 }, 559 { 0xc1, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }, 560 { 0x41, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00 }, 561 { 0x41, 0x07, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 }, 562 { 0x41, 0x03, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00 }, 563 { 0x41, 0x19, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 564 0x00, 0x00, 0x00, 0x00, 0x11, 0x13 }, 565 { 0x41, 0x13, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 566 0x09, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 567 0x0a, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00 }, 568 { 0x41, 0x12, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00 }, 569 { 0x41, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00 }, 570 { 0x41, 0x07, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 }, 571 { 0x41, 0x03, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00 }, 572 { 0x41, 0x19, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 573 0x00, 0x00, 0x00, 0x00, 0x11, 0x13 }, 574 { 0x41, 0x13, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 575 0x09, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 576 0x0a, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00 }, 577 { 0x41, 0x07, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 }, 578 }; 579 580 struct usb_device_request req; 581 usb_error_t err; 582 uint16_t len; 583 uint8_t buf[0x300]; 584 uint8_t n; 585 586 DPRINTFN(1, "\n"); 587 588 if (usbd_req_set_alt_interface_no(udev, NULL, 0, 0)) { 589 DPRINTFN(0, "Alt setting 0 failed\n"); 590 return; 591 } 592 593 for (n = 0; n != (sizeof(setup)/sizeof(setup[0])); n++) { 594 595 memcpy(&req, setup[n], sizeof(req)); 596 597 len = UGETW(req.wLength); 598 if (req.bmRequestType & UE_DIR_IN) { 599 if (len > sizeof(buf)) { 600 DPRINTFN(0, "too small buffer\n"); 601 continue; 602 } 603 err = usbd_do_request(udev, NULL, &req, buf); 604 } else { 605 if (len > (sizeof(setup[0]) - 8)) { 606 DPRINTFN(0, "too small buffer\n"); 607 continue; 608 } 609 err = usbd_do_request(udev, NULL, &req, 610 __DECONST(uint8_t *, &setup[n][8])); 611 } 612 if (err) { 613 DPRINTFN(1, "request %u failed\n", 614 (unsigned int)n); 615 /* 616 * Some of the requests will fail. Stop doing 617 * requests when we are getting timeouts so 618 * that we don't block the explore/attach 619 * thread forever. 620 */ 621 if (err == USB_ERR_TIMEOUT) 622 break; 623 } 624 } 625} 626 627/* 628 * The following function handles 3G modem devices (E220, Mobile, 629 * etc.) with auto-install flash disks for Windows/MacOSX on the first 630 * interface. After some command or some delay they change appearance 631 * to a modem. 632 */ 633static void 634u3g_test_autoinst(void *arg, struct usb_device *udev, 635 struct usb_attach_arg *uaa) 636{ 637 struct usb_interface *iface; 638 struct usb_interface_descriptor *id; 639 int error; 640 641 if (uaa->dev_state != UAA_DEV_READY) 642 return; 643 644 iface = usbd_get_iface(udev, 0); 645 if (iface == NULL) 646 return; 647 id = iface->idesc; 648 if (id == NULL || id->bInterfaceClass != UICLASS_MASS) 649 return; 650 if (usbd_lookup_id_by_uaa(u3g_devs, sizeof(u3g_devs), uaa)) 651 return; /* no device match */ 652 653 switch (USB_GET_DRIVER_INFO(uaa)) { 654 case U3GINIT_HUAWEI: 655 error = u3g_huawei_init(udev); 656 break; 657 case U3GINIT_HUAWEISCSI: 658 error = usb_msc_eject(udev, 0, MSC_EJECT_HUAWEI); 659 break; 660 case U3GINIT_SCSIEJECT: 661 error = usb_msc_eject(udev, 0, MSC_EJECT_STOPUNIT); 662 break; 663 case U3GINIT_REZERO: 664 error = usb_msc_eject(udev, 0, MSC_EJECT_REZERO); 665 break; 666 case U3GINIT_ZTESTOR: 667 error = usb_msc_eject(udev, 0, MSC_EJECT_ZTESTOR); 668 break; 669 case U3GINIT_CMOTECH: 670 error = usb_msc_eject(udev, 0, MSC_EJECT_CMOTECH); 671 break; 672 case U3GINIT_SIERRA: 673 error = u3g_sierra_init(udev); 674 break; 675 case U3GINIT_WAIT: 676 /* Just pretend we ejected, the card will timeout */ 677 error = 0; 678 break; 679 default: 680 /* no 3G eject quirks */ 681 error = EOPNOTSUPP; 682 break; 683 } 684 if (error == 0) { 685 /* success, mark the udev as disappearing */ 686 uaa->dev_state = UAA_DEV_EJECTING; 687 } 688} 689 690static int 691u3g_driver_loaded(struct module *mod, int what, void *arg) 692{ 693 switch (what) { 694 case MOD_LOAD: 695 /* register our autoinstall handler */ 696 u3g_etag = EVENTHANDLER_REGISTER(usb_dev_configured, 697 u3g_test_autoinst, NULL, EVENTHANDLER_PRI_ANY); 698 break; 699 case MOD_UNLOAD: 700 EVENTHANDLER_DEREGISTER(usb_dev_configured, u3g_etag); 701 break; 702 default: 703 return (EOPNOTSUPP); 704 } 705 return (0); 706} 707 708static int 709u3g_probe(device_t self) 710{ 711 struct usb_attach_arg *uaa = device_get_ivars(self); 712 713 if (uaa->usb_mode != USB_MODE_HOST) { 714 return (ENXIO); 715 } 716 if (uaa->info.bConfigIndex != U3G_CONFIG_INDEX) { 717 return (ENXIO); 718 } 719 if (uaa->info.bInterfaceClass != UICLASS_VENDOR) { 720 return (ENXIO); 721 } 722 return (usbd_lookup_id_by_uaa(u3g_devs, sizeof(u3g_devs), uaa)); 723} 724 725static int 726u3g_attach(device_t dev) 727{ 728 struct usb_config u3g_config_tmp[U3G_N_TRANSFER]; 729 struct usb_attach_arg *uaa = device_get_ivars(dev); 730 struct u3g_softc *sc = device_get_softc(dev); 731 struct usb_interface *iface; 732 struct usb_interface_descriptor *id; 733 uint32_t iface_valid; 734 int error, type, nports; 735 int ep, n; 736 uint8_t i; 737 738 DPRINTF("sc=%p\n", sc); 739 740 type = USB_GET_DRIVER_INFO(uaa); 741 if (type == U3GINIT_SAEL_M460) 742 u3g_sael_m460_init(uaa->device); 743 744 /* copy in USB config */ 745 for (n = 0; n != U3G_N_TRANSFER; n++) 746 u3g_config_tmp[n] = u3g_config[n]; 747 748 device_set_usb_desc(dev); 749 mtx_init(&sc->sc_mtx, "u3g", NULL, MTX_DEF); 750 751 sc->sc_udev = uaa->device; 752 753 /* Claim all interfaces on the device */ 754 iface_valid = 0; 755 for (i = uaa->info.bIfaceIndex; i < USB_IFACE_MAX; i++) { 756 iface = usbd_get_iface(uaa->device, i); 757 if (iface == NULL) 758 break; 759 id = usbd_get_interface_descriptor(iface); 760 if (id == NULL || id->bInterfaceClass != UICLASS_VENDOR) 761 continue; 762 usbd_set_parent_iface(uaa->device, i, uaa->info.bIfaceIndex); 763 iface_valid |= (1<<i); 764 } 765 766 i = 0; /* interface index */ 767 ep = 0; /* endpoint index */ 768 nports = 0; /* number of ports */ 769 while (i < USB_IFACE_MAX) { 770 if ((iface_valid & (1<<i)) == 0) { 771 i++; 772 continue; 773 } 774 775 /* update BULK endpoint index */ 776 for (n = 0; n < U3G_N_TRANSFER; n++) 777 u3g_config_tmp[n].ep_index = ep; 778 779 /* try to allocate a set of BULK endpoints */ 780 error = usbd_transfer_setup(uaa->device, &i, 781 sc->sc_xfer[nports], u3g_config_tmp, U3G_N_TRANSFER, 782 &sc->sc_ucom[nports], &sc->sc_mtx); 783 if (error) { 784 /* next interface */ 785 i++; 786 ep = 0; 787 continue; 788 } 789 790 /* set stall by default */ 791 mtx_lock(&sc->sc_mtx); 792 usbd_xfer_set_stall(sc->sc_xfer[nports][U3G_BULK_WR]); 793 usbd_xfer_set_stall(sc->sc_xfer[nports][U3G_BULK_RD]); 794 mtx_unlock(&sc->sc_mtx); 795 796 nports++; /* found one port */ 797 ep++; 798 if (nports == U3G_MAXPORTS) 799 break; 800 } 801 if (nports == 0) { 802 device_printf(dev, "no ports found\n"); 803 goto detach; 804 } 805 sc->sc_numports = nports; 806 807 error = ucom_attach(&sc->sc_super_ucom, sc->sc_ucom, 808 sc->sc_numports, sc, &u3g_callback, &sc->sc_mtx); 809 if (error) { 810 DPRINTF("ucom_attach failed\n"); 811 goto detach; 812 } 813 device_printf(dev, "Found %u port%s.\n", sc->sc_numports, 814 sc->sc_numports > 1 ? "s":""); 815 return (0); 816 817detach: 818 u3g_detach(dev); 819 return (ENXIO); 820} 821 822static int 823u3g_detach(device_t dev) 824{ 825 struct u3g_softc *sc = device_get_softc(dev); 826 uint8_t m; 827 828 DPRINTF("sc=%p\n", sc); 829 830 /* NOTE: It is not dangerous to detach more ports than attached! */ 831 ucom_detach(&sc->sc_super_ucom, sc->sc_ucom, U3G_MAXPORTS); 832 833 for (m = 0; m != U3G_MAXPORTS; m++) 834 usbd_transfer_unsetup(sc->sc_xfer[m], U3G_N_TRANSFER); 835 mtx_destroy(&sc->sc_mtx); 836 837 return (0); 838} 839 840static void 841u3g_start_read(struct ucom_softc *ucom) 842{ 843 struct u3g_softc *sc = ucom->sc_parent; 844 845 /* start read endpoint */ 846 usbd_transfer_start(sc->sc_xfer[ucom->sc_local_unit][U3G_BULK_RD]); 847 return; 848} 849 850static void 851u3g_stop_read(struct ucom_softc *ucom) 852{ 853 struct u3g_softc *sc = ucom->sc_parent; 854 855 /* stop read endpoint */ 856 usbd_transfer_stop(sc->sc_xfer[ucom->sc_local_unit][U3G_BULK_RD]); 857 return; 858} 859 860static void 861u3g_start_write(struct ucom_softc *ucom) 862{ 863 struct u3g_softc *sc = ucom->sc_parent; 864 865 usbd_transfer_start(sc->sc_xfer[ucom->sc_local_unit][U3G_BULK_WR]); 866 return; 867} 868 869static void 870u3g_stop_write(struct ucom_softc *ucom) 871{ 872 struct u3g_softc *sc = ucom->sc_parent; 873 874 usbd_transfer_stop(sc->sc_xfer[ucom->sc_local_unit][U3G_BULK_WR]); 875 return; 876} 877 878static void 879u3g_write_callback(struct usb_xfer *xfer, usb_error_t error) 880{ 881 struct ucom_softc *ucom = usbd_xfer_softc(xfer); 882 struct usb_page_cache *pc; 883 uint32_t actlen; 884 885 switch (USB_GET_STATE(xfer)) { 886 case USB_ST_TRANSFERRED: 887 case USB_ST_SETUP: 888tr_setup: 889 pc = usbd_xfer_get_frame(xfer, 0); 890 if (ucom_get_data(ucom, pc, 0, U3G_BSIZE, &actlen)) { 891 usbd_xfer_set_frame_len(xfer, 0, actlen); 892 usbd_transfer_submit(xfer); 893 } 894 break; 895 896 default: /* Error */ 897 if (error != USB_ERR_CANCELLED) { 898 /* do a builtin clear-stall */ 899 usbd_xfer_set_stall(xfer); 900 goto tr_setup; 901 } 902 break; 903 } 904 return; 905} 906 907static void 908u3g_read_callback(struct usb_xfer *xfer, usb_error_t error) 909{ 910 struct ucom_softc *ucom = usbd_xfer_softc(xfer); 911 struct usb_page_cache *pc; 912 int actlen; 913 914 usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL); 915 916 switch (USB_GET_STATE(xfer)) { 917 case USB_ST_TRANSFERRED: 918 pc = usbd_xfer_get_frame(xfer, 0); 919 ucom_put_data(ucom, pc, 0, actlen); 920 921 case USB_ST_SETUP: 922tr_setup: 923 usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer)); 924 usbd_transfer_submit(xfer); 925 break; 926 927 default: /* Error */ 928 if (error != USB_ERR_CANCELLED) { 929 /* do a builtin clear-stall */ 930 usbd_xfer_set_stall(xfer); 931 goto tr_setup; 932 } 933 break; 934 } 935 return; 936}
|