ctap_hid.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2021 Freie Universität Berlin
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
21 #include <stdint.h>
22 
23 #include "usb/usbus/hid.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
34 #define CTAP_HID_INIT_PAYLOAD_SIZE (CONFIG_USBUS_HID_INTERRUPT_EP_SIZE - 7)
35 #define CTAP_HID_CONT_PAYLOAD_SIZE (CONFIG_USBUS_HID_INTERRUPT_EP_SIZE - 5)
41 #define CTAP_HID_PROTOCOL_VERSION 0x02
42 
48 #define CTAP_HID_INIT_PACKET 0x80
49 #define CTAP_HID_CONT_PACKET 0x00
55 #define CTAP_HID_INIT_NONCE_SIZE 8
56 
60 #ifdef CONFIG_FIDO2_CTAP_TRANSPORT_HID_TRANSACTION_TIMEOUT
61 #define CTAP_HID_TRANSACTION_TIMEOUT_MS (CONFIG_FIDO2_CTAP_TRANSPORT_HID_TRANSACTION_TIMEOUT)
62 #else
63 #define CTAP_HID_TRANSACTION_TIMEOUT_MS (500)
64 #endif
65 
71 #define CTAP_HID_BUFFER_SIZE 7609
72 
78 #define CTAP_HID_COMMAND_PING (0x01 | CTAP_HID_INIT_PACKET)
79 #define CTAP_HID_COMMAND_MSG (0x03 | CTAP_HID_INIT_PACKET)
80 #define CTAP_HID_COMMAND_LOCK (0x04 | CTAP_HID_INIT_PACKET)
81 #define CTAP_HID_COMMAND_INIT (0x06 | CTAP_HID_INIT_PACKET)
82 #define CTAP_HID_COMMAND_WINK (0x08 | CTAP_HID_INIT_PACKET)
83 #define CTAP_HID_COMMAND_CBOR (0x10 | CTAP_HID_INIT_PACKET)
84 #define CTAP_HID_COMMAND_CANCEL (0x11 | CTAP_HID_INIT_PACKET)
85 #define CTAP_HID_COMMAND_KEEPALIVE (0x3b | CTAP_HID_INIT_PACKET)
86 #define CTAP_HID_COMMAND_ERROR (0x3f | CTAP_HID_INIT_PACKET)
94 #define CTAP_HID_CAPABILITY_WINK 0x01
95 #define CTAP_HID_CAPABILITY_CBOR 0x04
96 #define CTAP_HID_CAPABILITY_NMSG 0x08
104 #define CTAP_HID_OK 0x00
105 #define CTAP_HID_ERR_INVALID_CMD 0x01
106 #define CTAP_HID_ERR_INVALID_PAR 0x02
107 #define CTAP_HID_ERR_INVALID_LEN 0x03
108 #define CTAP_HID_ERR_INVALID_SEQ 0x04
109 #define CTAP_HID_ERR_MSG_TIMEOUT 0x05
110 #define CTAP_HID_ERR_CHANNEL_BUSY 0x06
111 #define CTAP_HID_ERR_LOCK_REQUIRED 0x0a
112 #define CTAP_HID_ERR_INVALID_CHANNEL 0x0b
113 #define CTAP_HID_ERR_OTHER 0x7f
121 #define CTAP_HID_STATUS_PROCESSING 0x01
122 #define CTAP_HID_STATUS_UPNEEDED 0x02
129 #define CTAP_HID_CIDS_MAX 0x08
130 
134 #define CTAP_HID_WINK_DELAY 400
135 
140 #define CTAP_HID_BROADCAST_CID 0xffffffff
141 
147 #define CTAP_HID_BUFFER_STATUS_BUFFERING 0x00
148 #define CTAP_HID_BUFFER_STATUS_DONE 0x01
149 #define CTAP_HID_BUFFER_STATUS_ERROR 0x02
156 typedef struct {
157  uint8_t cmd;
158  uint8_t bcnth;
159  uint8_t bcntl;
160  uint8_t payload[CTAP_HID_INIT_PAYLOAD_SIZE];
162 
167 typedef struct {
168  uint8_t seq;
169  uint8_t payload[CTAP_HID_CONT_PAYLOAD_SIZE];
171 
176 typedef struct {
177  uint32_t cid;
178  union {
181  };
183 
189 typedef struct __attribute__((packed)){
190  uint8_t nonce[CTAP_HID_INIT_NONCE_SIZE];
191  uint32_t cid;
193  uint8_t version_major;
194  uint8_t version_minor;
195  uint8_t build_version;
196  uint8_t capabilities;
198 
204 typedef struct {
205  bool taken;
206  uint32_t cid;
207  uint32_t last_used;
209 
216 
223 
238 
246 
247 #ifdef __cplusplus
248 }
249 #endif
#define CTAP_HID_CONT_PAYLOAD_SIZE
endpoint size - cont packet metadata
Definition: ctap_hid.h:35
#define CTAP_HID_INIT_PAYLOAD_SIZE
endpoint size - init packet metadata
Definition: ctap_hid.h:34
#define CTAP_HID_INIT_NONCE_SIZE
CTAP_HID size of nonce for init request.
Definition: ctap_hid.h:55
void fido2_ctap_transport_hid_init(event_queue_t *queue)
Initialize CTAPHID.
bool fido2_ctap_transport_hid_should_cancel(void)
Check if CTAPHID layer has received CANCEL command.
void fido2_ctap_transport_hid_check_timeouts(void)
Check logical channels for timeouts.
void fido2_ctap_transport_hid_handle_packet(void *pkt_raw)
Handle CTAP_HID packet.
event queue structure
Definition: event.h:150
CTAP_HID channel identifier struct.
Definition: ctap_hid.h:204
uint32_t last_used
timestamp of last usage
Definition: ctap_hid.h:207
bool taken
is cid taken?
Definition: ctap_hid.h:205
uint32_t cid
channel identifier
Definition: ctap_hid.h:206
CTAP_HID continuation packet struct.
Definition: ctap_hid.h:167
uint8_t seq
packet sequence number
Definition: ctap_hid.h:168
CTAP_HID initialization packet struct.
Definition: ctap_hid.h:156
uint8_t cmd
CTAP_HID command.
Definition: ctap_hid.h:157
uint8_t bcntl
lower byte
Definition: ctap_hid.h:159
uint8_t bcnth
higher byte
Definition: ctap_hid.h:158
CTAP_HID initialization response struct.
Definition: ctap_hid.h:189
uint8_t protocol_version
CTAP_HID protocol version.
Definition: ctap_hid.h:192
uint8_t version_minor
minor device version
Definition: ctap_hid.h:194
uint8_t version_major
major device version
Definition: ctap_hid.h:193
uint32_t cid
channel identifier
Definition: ctap_hid.h:191
uint8_t build_version
build device version
Definition: ctap_hid.h:195
uint8_t capabilities
capabilities flags
Definition: ctap_hid.h:196
CTAP_HID packet struct.
Definition: ctap_hid.h:176
ctap_hid_cont_pkt_t cont
continuation packet
Definition: ctap_hid.h:180
ctap_hid_init_pkt_t init
initialization packet
Definition: ctap_hid.h:179
uint32_t cid
channel identifier
Definition: ctap_hid.h:177
Interface and definitions for USB HID type interfaces in USBUS.