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
3 // found in the LICENSE file.
6 * @fileoverview Interface for representing a low-level gnubby device.
11 * Low level gnubby 'driver'. One per physical USB device.
14 function GnubbyDevice() {}
16 // Commands of the USB interface.
17 /** Echo data through local processor only */
18 GnubbyDevice
.CMD_PING
= 0x81;
19 /** Perform reset action and read ATR string */
20 GnubbyDevice
.CMD_ATR
= 0x82;
22 GnubbyDevice
.CMD_APDU
= 0x83;
23 /** Send lock channel command */
24 GnubbyDevice
.CMD_LOCK
= 0x84;
25 /** Obtain system information record */
26 GnubbyDevice
.CMD_SYSINFO
= 0x85;
27 /** Obtain an unused channel ID */
28 GnubbyDevice
.CMD_INIT
= 0x86;
29 /** Control prompt flashing */
30 GnubbyDevice
.CMD_PROMPT
= 0x87;
31 /** Send device identification wink */
32 GnubbyDevice
.CMD_WINK
= 0x88;
34 GnubbyDevice
.CMD_USB_TEST
= 0xb9;
35 /** Device Firmware Upgrade */
36 GnubbyDevice
.CMD_DFU
= 0xba;
37 /** Protocol resync command */
38 GnubbyDevice
.CMD_SYNC
= 0xbc;
40 GnubbyDevice
.CMD_ERROR
= 0xbf;
42 // Low-level error codes.
45 /** Invalid command */
46 GnubbyDevice
.INVALID_CMD
= 1;
47 /** Invalid parameter */
48 GnubbyDevice
.INVALID_PAR
= 2;
49 /** Invalid message length */
50 GnubbyDevice
.INVALID_LEN
= 3;
51 /** Invalid message sequencing */
52 GnubbyDevice
.INVALID_SEQ
= 4;
53 /** Message has timed out */
54 GnubbyDevice
.TIMEOUT
= 5;
55 /** CHannel is busy */
56 GnubbyDevice
.BUSY
= 6;
58 GnubbyDevice
.ACCESS_DENIED
= 7;
60 GnubbyDevice
.GONE
= 8;
61 /** Verification error */
62 GnubbyDevice
.VERIFY_ERROR
= 9;
63 /** Command requires channel lock */
64 GnubbyDevice
.LOCK_REQUIRED
= 10;
66 GnubbyDevice
.SYNC_FAIL
= 11;
67 /** Other unspecified error */
68 GnubbyDevice
.OTHER
= 127;
70 // Remote helper errors.
71 /** Not a remote helper */
72 GnubbyDevice
.NOTREMOTE
= 263;
73 /** Could not reach remote endpoint */
74 GnubbyDevice
.COULDNOTDIAL
= 264;
76 // chrome.usb-related errors.
78 GnubbyDevice
.NODEVICE
= 512;
79 /** Permission denied */
80 GnubbyDevice
.NOPERMISSION
= 666;
82 /** Destroys this low-level device instance. */
83 GnubbyDevice
.prototype.destroy = function() {};
86 * Register a client for this gnubby.
87 * @param {*} who The client.
89 GnubbyDevice
.prototype.registerClient = function(who
) {};
92 * De-register a client.
93 * @param {*} who The client.
94 * @return {number} The number of remaining listeners for this device, or -1
95 * if this had no clients to start with.
97 GnubbyDevice
.prototype.deregisterClient = function(who
) {};
100 * @param {*} who The client.
101 * @return {boolean} Whether this device has who as a client.
103 GnubbyDevice
.prototype.hasClient = function(who
) {};
106 * Queue command to be sent.
107 * If queue was empty, initiate the write.
108 * @param {number} cid The client's channel ID.
109 * @param {number} cmd The command to send.
110 * @param {ArrayBuffer|Uint8Array} data Command data
112 GnubbyDevice
.prototype.queueCommand = function(cid
, cmd
, data
) {};