OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview Implements a low-level gnubby driver based on chrome.usb. | 6 * @fileoverview Implements a low-level gnubby driver based on chrome.usb. |
7 */ | 7 */ |
8 'use strict'; | 8 'use strict'; |
9 | 9 |
10 /** | 10 /** |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 | 367 |
368 var lockArg = (u8.length > 0) ? u8[0] : 0; | 368 var lockArg = (u8.length > 0) ? u8[0] : 0; |
369 this.updateLock_(cid, cmd, lockArg); | 369 this.updateLock_(cid, cmd, lockArg); |
370 | 370 |
371 var wasEmpty = (this.txqueue.length == 0); | 371 var wasEmpty = (this.txqueue.length == 0); |
372 this.txqueue.push(frame.buffer); | 372 this.txqueue.push(frame.buffer); |
373 if (wasEmpty) this.writeOneRequest_(); | 373 if (wasEmpty) this.writeOneRequest_(); |
374 }; | 374 }; |
375 | 375 |
376 /** | 376 /** |
| 377 * @const |
| 378 */ |
| 379 UsbGnubbyDevice.WINUSB_VID_PIDS = [ |
| 380 {'vendorId': 4176, 'productId': 529} // Yubico WinUSB |
| 381 ]; |
| 382 |
| 383 /** |
377 * @param {function(Array)} cb Enumerate callback | 384 * @param {function(Array)} cb Enumerate callback |
378 */ | 385 */ |
379 UsbGnubbyDevice.enumerate = function(cb) { | 386 UsbGnubbyDevice.enumerate = function(cb) { |
380 var permittedDevs; | |
381 var numEnumerated = 0; | 387 var numEnumerated = 0; |
382 var allDevs = []; | 388 var allDevs = []; |
383 | 389 |
384 function enumerated(devs) { | 390 function enumerated(devs) { |
385 allDevs = allDevs.concat(devs); | 391 allDevs = allDevs.concat(devs); |
386 if (++numEnumerated == permittedDevs.length) { | 392 if (++numEnumerated == UsbGnubbyDevice.WINUSB_VID_PIDS.length) { |
387 cb(allDevs); | 393 cb(allDevs); |
388 } | 394 } |
389 } | 395 } |
390 | 396 |
391 GnubbyDevice.getPermittedUsbDevices(function(devs) { | 397 for (var i = 0; i < UsbGnubbyDevice.WINUSB_VID_PIDS.length; i++) { |
392 permittedDevs = devs; | 398 chrome.usb.getDevices(UsbGnubbyDevice.WINUSB_VID_PIDS[i], enumerated); |
393 for (var i = 0; i < devs.length; i++) { | 399 } |
394 chrome.usb.getDevices(devs[i], enumerated); | |
395 } | |
396 }); | |
397 }; | 400 }; |
398 | 401 |
399 /** | 402 /** |
400 * @typedef {?{ | 403 * @typedef {?{ |
401 * address: number, | 404 * address: number, |
402 * type: string, | 405 * type: string, |
403 * direction: string, | 406 * direction: string, |
404 * maximumPacketSize: number, | 407 * maximumPacketSize: number, |
405 * synchronization: (string|undefined), | 408 * synchronization: (string|undefined), |
406 * usage: (string|undefined), | 409 * usage: (string|undefined), |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 */ | 526 */ |
524 UsbGnubbyDevice.register = function(gnubbies) { | 527 UsbGnubbyDevice.register = function(gnubbies) { |
525 var USB_GNUBBY_IMPL = { | 528 var USB_GNUBBY_IMPL = { |
526 isSharedAccess: false, | 529 isSharedAccess: false, |
527 enumerate: UsbGnubbyDevice.enumerate, | 530 enumerate: UsbGnubbyDevice.enumerate, |
528 deviceToDeviceId: UsbGnubbyDevice.deviceToDeviceId, | 531 deviceToDeviceId: UsbGnubbyDevice.deviceToDeviceId, |
529 open: UsbGnubbyDevice.open | 532 open: UsbGnubbyDevice.open |
530 }; | 533 }; |
531 gnubbies.registerNamespace(UsbGnubbyDevice.NAMESPACE, USB_GNUBBY_IMPL); | 534 gnubbies.registerNamespace(UsbGnubbyDevice.NAMESPACE, USB_GNUBBY_IMPL); |
532 }; | 535 }; |
OLD | NEW |