Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(852)

Side by Side Diff: device/u2f/u2f_hid_device.h

Issue 2721223002: Add support for U2fHidDevice interaction (Closed)
Patch Set: Use MockHidConnection to fail writes in unittest Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « device/u2f/u2f_device.cc ('k') | device/u2f/u2f_hid_device.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 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.
4
5 #ifndef DEVICE_U2F_U2F_HID_DEVICE_H_
6 #define DEVICE_U2F_U2F_HID_DEVICE_H_
7
8 #include <list>
9
10 #include "device/hid/hid_service.h"
11 #include "u2f_device.h"
12
13 namespace net {
14 class IOBuffer;
15 } // namespace net
16
17 namespace device {
18
19 class U2fMessage;
20 class HidConnection;
21 class HidDeviceInfo;
22
23 class U2fHidDevice : public U2fDevice {
24 public:
25 U2fHidDevice(scoped_refptr<HidDeviceInfo>);
26 ~U2fHidDevice();
27
28 // Send a U2f command to this device
29 void DeviceTransact(scoped_refptr<U2fApduCommand> command,
30 const DeviceCallback& callback) final;
31 // Send a wink command if supported
32 void TryWink(const WinkCallback& callback) final;
33 // Use a string identifier to compare to other devices
34 std::string GetId() final;
35 // Command line flag to enable tests on actual U2f HID hardware
36 static bool IsTestEnabled();
37
38 private:
39 FRIEND_TEST_ALL_PREFIXES(U2fHidDeviceTest, TestConnectionFailure);
40 FRIEND_TEST_ALL_PREFIXES(U2fHidDeviceTest, TestDeviceError);
41
42 // Internal state machine states
43 enum class State { INIT, CONNECTED, BUSY, IDLE, DEVICE_ERROR };
44
45 using U2fHidMessageCallback =
46 base::OnceCallback<void(bool, scoped_refptr<U2fMessage>)>;
47
48 // Open a connection to this device
49 void Connect(const HidService::ConnectCallback& callback);
50 void OnConnect(scoped_refptr<U2fApduCommand> command,
51 const DeviceCallback& callback,
52 scoped_refptr<HidConnection> connection);
53 // Ask device to allocate a unique channel id for this connection
54 void AllocateChannel(scoped_refptr<U2fApduCommand> command,
55 const DeviceCallback& callback);
56 void OnAllocateChannel(std::vector<uint8_t> nonce,
57 scoped_refptr<U2fApduCommand> command,
58 const DeviceCallback& callback,
59 bool success,
60 scoped_refptr<U2fMessage> message);
61 void Transition(scoped_refptr<U2fApduCommand> command,
62 const DeviceCallback& callback);
63 // Write all message packets to device, and read response if expected
64 void WriteMessage(scoped_refptr<U2fMessage> message,
65 bool response_expected,
66 U2fHidMessageCallback callback);
67 void PacketWritten(scoped_refptr<U2fMessage> message,
68 bool response_expected,
69 U2fHidMessageCallback callback,
70 bool success);
71 // Read all response message packets from device
72 void ReadMessage(U2fHidMessageCallback callback);
73 void MessageReceived(const DeviceCallback& callback,
74 bool success,
75 scoped_refptr<U2fMessage> message);
76 void OnRead(U2fHidMessageCallback callback,
77 bool success,
78 scoped_refptr<net::IOBuffer> buf,
79 size_t size);
80 void OnReadContinuation(scoped_refptr<U2fMessage> message,
81 U2fHidMessageCallback,
82 bool success,
83 scoped_refptr<net::IOBuffer> buf,
84 size_t size);
85 void OnWink(const WinkCallback& callback,
86 bool success,
87 scoped_refptr<U2fMessage> response);
88
89 State state_;
90 std::list<std::pair<scoped_refptr<U2fApduCommand>, DeviceCallback>>
91 pending_transactions_;
92 scoped_refptr<HidDeviceInfo> device_info_;
93 scoped_refptr<HidConnection> connection_;
94 base::WeakPtrFactory<U2fHidDevice> weak_factory_;
95
96 DISALLOW_COPY_AND_ASSIGN(U2fHidDevice);
97 };
98
99 } // namespace device
100
101 #endif // DEVICE_U2F_U2F_HID_DEVICE_H_
OLDNEW
« no previous file with comments | « device/u2f/u2f_device.cc ('k') | device/u2f/u2f_hid_device.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698