summaryrefslogtreecommitdiff
path: root/chromium/chrome/browser/resources/cryptotoken/gnubbydevice.js
blob: 77c3eb58f051e549977828e9ef2251e8eb51a8a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/**
 * @fileoverview Interface for representing a low-level gnubby device.
 */
'use strict';

/**
 * Low level gnubby 'driver'. One per physical USB device.
 * @interface
 */
function GnubbyDevice() {}

// Commands of the USB interface.
/** Echo data through local processor only */
GnubbyDevice.CMD_PING = 0x81;
/** Perform reset action and read ATR string */
GnubbyDevice.CMD_ATR = 0x82;
/** Send raw APDU */
GnubbyDevice.CMD_APDU = 0x83;
/** Send lock channel command */
GnubbyDevice.CMD_LOCK = 0x84;
/** Obtain system information record */
GnubbyDevice.CMD_SYSINFO = 0x85;
/** Obtain an unused channel ID */
GnubbyDevice.CMD_INIT = 0x86;
/** Control prompt flashing */
GnubbyDevice.CMD_PROMPT = 0x87;
/** Send device identification wink */
GnubbyDevice.CMD_WINK = 0x88;
/** USB test */
GnubbyDevice.CMD_USB_TEST = 0xb9;
/** Device Firmware Upgrade */
GnubbyDevice.CMD_DFU = 0xba;
/** Protocol resync command */
GnubbyDevice.CMD_SYNC = 0xbc;
/** Error response */
GnubbyDevice.CMD_ERROR = 0xbf;

// Low-level error codes.
/** No error */
GnubbyDevice.OK = 0;
/** Invalid command */
GnubbyDevice.INVALID_CMD = 1;
/** Invalid parameter */
GnubbyDevice.INVALID_PAR = 2;
/** Invalid message length */
GnubbyDevice.INVALID_LEN = 3;
/** Invalid message sequencing */
GnubbyDevice.INVALID_SEQ = 4;
/** Message has timed out */
GnubbyDevice.TIMEOUT = 5;
/** CHannel is busy */
GnubbyDevice.BUSY = 6;
/** Access denied */
GnubbyDevice.ACCESS_DENIED = 7;
/** Device is gone */
GnubbyDevice.GONE = 8;
/** Verification error */
GnubbyDevice.VERIFY_ERROR = 9;
/** Command requires channel lock */
GnubbyDevice.LOCK_REQUIRED = 10;
/** Sync error */
GnubbyDevice.SYNC_FAIL = 11;
/** Other unspecified error */
GnubbyDevice.OTHER = 127;

// Remote helper errors.
/** Not a remote helper */
GnubbyDevice.NOTREMOTE = 263;
/** Could not reach remote endpoint */
GnubbyDevice.COULDNOTDIAL = 264;

// chrome.usb-related errors.
/** No device */
GnubbyDevice.NODEVICE = 512;
/** Permission denied */
GnubbyDevice.NOPERMISSION = 666;

/** Destroys this low-level device instance. */
GnubbyDevice.prototype.destroy = function() {};

/**
 * Register a client for this gnubby.
 * @param {*} who The client.
 */
GnubbyDevice.prototype.registerClient = function(who) {};

/**
 * De-register a client.
 * @param {*} who The client.
 * @return {number} The number of remaining listeners for this device, or -1
 *     if this had no clients to start with.
 */
GnubbyDevice.prototype.deregisterClient = function(who) {};

/**
 * @param {*} who The client.
 * @return {boolean} Whether this device has who as a client.
 */
GnubbyDevice.prototype.hasClient = function(who) {};

/**
 * Queue command to be sent.
 * If queue was empty, initiate the write.
 * @param {number} cid The client's channel ID.
 * @param {number} cmd The command to send.
 * @param {ArrayBuffer|Uint8Array} data Command data
 */
GnubbyDevice.prototype.queueCommand = function(cid, cmd, data) {};

/**
 * @typedef {{
 *   vendorId: number,
 *   productId: number
 * }}
 */
var UsbDeviceSpec;