ctap_hid.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 Freie Universität Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
9 #pragma once
10 
24 #include <stdint.h>
25 
26 #include "usb/usbus/hid.h"
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
37 #define CTAP_HID_INIT_PAYLOAD_SIZE (CONFIG_USBUS_HID_INTERRUPT_EP_SIZE - 7)
38 #define CTAP_HID_CONT_PAYLOAD_SIZE (CONFIG_USBUS_HID_INTERRUPT_EP_SIZE - 5)
44 #define CTAP_HID_PROTOCOL_VERSION 0x02
45 
51 #define CTAP_HID_INIT_PACKET 0x80
52 #define CTAP_HID_CONT_PACKET 0x00
58 #define CTAP_HID_INIT_NONCE_SIZE 8
59 
63 #ifdef CONFIG_FIDO2_CTAP_TRANSPORT_HID_TRANSACTION_TIMEOUT
64 #define CTAP_HID_TRANSACTION_TIMEOUT_MS (CONFIG_FIDO2_CTAP_TRANSPORT_HID_TRANSACTION_TIMEOUT)
65 #else
66 #define CTAP_HID_TRANSACTION_TIMEOUT_MS (500)
67 #endif
68 
74 #define CTAP_HID_BUFFER_SIZE 7609
75 
81 #define CTAP_HID_COMMAND_PING (0x01 | CTAP_HID_INIT_PACKET)
82 #define CTAP_HID_COMMAND_MSG (0x03 | CTAP_HID_INIT_PACKET)
83 #define CTAP_HID_COMMAND_LOCK (0x04 | CTAP_HID_INIT_PACKET)
84 #define CTAP_HID_COMMAND_INIT (0x06 | CTAP_HID_INIT_PACKET)
85 #define CTAP_HID_COMMAND_WINK (0x08 | CTAP_HID_INIT_PACKET)
86 #define CTAP_HID_COMMAND_CBOR (0x10 | CTAP_HID_INIT_PACKET)
87 #define CTAP_HID_COMMAND_CANCEL (0x11 | CTAP_HID_INIT_PACKET)
88 #define CTAP_HID_COMMAND_KEEPALIVE (0x3b | CTAP_HID_INIT_PACKET)
89 #define CTAP_HID_COMMAND_ERROR (0x3f | CTAP_HID_INIT_PACKET)
97 #define CTAP_HID_CAPABILITY_WINK 0x01
98 #define CTAP_HID_CAPABILITY_CBOR 0x04
99 #define CTAP_HID_CAPABILITY_NMSG 0x08
107 #define CTAP_HID_OK 0x00
108 #define CTAP_HID_ERR_INVALID_CMD 0x01
109 #define CTAP_HID_ERR_INVALID_PAR 0x02
110 #define CTAP_HID_ERR_INVALID_LEN 0x03
111 #define CTAP_HID_ERR_INVALID_SEQ 0x04
112 #define CTAP_HID_ERR_MSG_TIMEOUT 0x05
113 #define CTAP_HID_ERR_CHANNEL_BUSY 0x06
114 #define CTAP_HID_ERR_LOCK_REQUIRED 0x0a
115 #define CTAP_HID_ERR_INVALID_CHANNEL 0x0b
116 #define CTAP_HID_ERR_OTHER 0x7f
124 #define CTAP_HID_STATUS_PROCESSING 0x01
125 #define CTAP_HID_STATUS_UPNEEDED 0x02
132 #define CTAP_HID_CIDS_MAX 0x08
133 
137 #define CTAP_HID_WINK_DELAY 400
138 
143 #define CTAP_HID_BROADCAST_CID 0xffffffff
144 
150 #define CTAP_HID_BUFFER_STATUS_BUFFERING 0x00
151 #define CTAP_HID_BUFFER_STATUS_DONE 0x01
152 #define CTAP_HID_BUFFER_STATUS_ERROR 0x02
159 typedef struct {
160  uint8_t cmd;
161  uint8_t bcnth;
162  uint8_t bcntl;
163  uint8_t payload[CTAP_HID_INIT_PAYLOAD_SIZE];
165 
170 typedef struct {
171  uint8_t seq;
172  uint8_t payload[CTAP_HID_CONT_PAYLOAD_SIZE];
174 
179 typedef struct {
180  uint32_t cid;
181  union {
184  };
186 
192 typedef struct __attribute__((packed)){
193  uint8_t nonce[CTAP_HID_INIT_NONCE_SIZE];
194  uint32_t cid;
196  uint8_t version_major;
197  uint8_t version_minor;
198  uint8_t build_version;
199  uint8_t capabilities;
201 
207 typedef struct {
208  bool taken;
209  uint32_t cid;
210  uint32_t last_used;
212 
219 
226 
241 
249 
250 #ifdef __cplusplus
251 }
252 #endif
#define CTAP_HID_CONT_PAYLOAD_SIZE
endpoint size - cont packet metadata
Definition: ctap_hid.h:38
#define CTAP_HID_INIT_PAYLOAD_SIZE
endpoint size - init packet metadata
Definition: ctap_hid.h:37
#define CTAP_HID_INIT_NONCE_SIZE
CTAP_HID size of nonce for init request.
Definition: ctap_hid.h:58
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:153
CTAP_HID channel identifier struct.
Definition: ctap_hid.h:207
uint32_t last_used
timestamp of last usage
Definition: ctap_hid.h:210
bool taken
is cid taken?
Definition: ctap_hid.h:208
uint32_t cid
channel identifier
Definition: ctap_hid.h:209
CTAP_HID continuation packet struct.
Definition: ctap_hid.h:170
uint8_t seq
packet sequence number
Definition: ctap_hid.h:171
CTAP_HID initialization packet struct.
Definition: ctap_hid.h:159
uint8_t cmd
CTAP_HID command.
Definition: ctap_hid.h:160
uint8_t bcntl
lower byte
Definition: ctap_hid.h:162
uint8_t bcnth
higher byte
Definition: ctap_hid.h:161
CTAP_HID initialization response struct.
Definition: ctap_hid.h:192
uint8_t protocol_version
CTAP_HID protocol version.
Definition: ctap_hid.h:195
uint8_t version_minor
minor device version
Definition: ctap_hid.h:197
uint8_t version_major
major device version
Definition: ctap_hid.h:196
uint32_t cid
channel identifier
Definition: ctap_hid.h:194
uint8_t build_version
build device version
Definition: ctap_hid.h:198
uint8_t capabilities
capabilities flags
Definition: ctap_hid.h:199
CTAP_HID packet struct.
Definition: ctap_hid.h:179
ctap_hid_cont_pkt_t cont
continuation packet
Definition: ctap_hid.h:183
ctap_hid_init_pkt_t init
initialization packet
Definition: ctap_hid.h:182
uint32_t cid
channel identifier
Definition: ctap_hid.h:180
Interface and definitions for USB HID type interfaces in USBUS.