Loading...
Searching...
No Matches
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
22#ifndef FIDO2_CTAP_TRANSPORT_HID_CTAP_HID_H
23#define FIDO2_CTAP_TRANSPORT_HID_CTAP_HID_H
24
25#include <stdint.h>
26
27#include "usb/usbus/hid.h"
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
38#define CTAP_HID_INIT_PAYLOAD_SIZE (CONFIG_USBUS_HID_INTERRUPT_EP_SIZE - 7)
39#define CTAP_HID_CONT_PAYLOAD_SIZE (CONFIG_USBUS_HID_INTERRUPT_EP_SIZE - 5)
45#define CTAP_HID_PROTOCOL_VERSION 0x02
46
52#define CTAP_HID_INIT_PACKET 0x80
53#define CTAP_HID_CONT_PACKET 0x00
59#define CTAP_HID_INIT_NONCE_SIZE 8
60
64#ifdef CONFIG_FIDO2_CTAP_TRANSPORT_HID_TRANSACTION_TIMEOUT
65#define CTAP_HID_TRANSACTION_TIMEOUT_MS (CONFIG_FIDO2_CTAP_TRANSPORT_HID_TRANSACTION_TIMEOUT)
66#else
67#define CTAP_HID_TRANSACTION_TIMEOUT_MS (500)
68#endif
69
75#define CTAP_HID_BUFFER_SIZE 7609
76
82#define CTAP_HID_COMMAND_PING (0x01 | CTAP_HID_INIT_PACKET)
83#define CTAP_HID_COMMAND_MSG (0x03 | CTAP_HID_INIT_PACKET)
84#define CTAP_HID_COMMAND_LOCK (0x04 | CTAP_HID_INIT_PACKET)
85#define CTAP_HID_COMMAND_INIT (0x06 | CTAP_HID_INIT_PACKET)
86#define CTAP_HID_COMMAND_WINK (0x08 | CTAP_HID_INIT_PACKET)
87#define CTAP_HID_COMMAND_CBOR (0x10 | CTAP_HID_INIT_PACKET)
88#define CTAP_HID_COMMAND_CANCEL (0x11 | CTAP_HID_INIT_PACKET)
89#define CTAP_HID_COMMAND_KEEPALIVE (0x3b | CTAP_HID_INIT_PACKET)
90#define CTAP_HID_COMMAND_ERROR (0x3f | CTAP_HID_INIT_PACKET)
98#define CTAP_HID_CAPABILITY_WINK 0x01
99#define CTAP_HID_CAPABILITY_CBOR 0x04
100#define CTAP_HID_CAPABILITY_NMSG 0x08
108#define CTAP_HID_OK 0x00
109#define CTAP_HID_ERR_INVALID_CMD 0x01
110#define CTAP_HID_ERR_INVALID_PAR 0x02
111#define CTAP_HID_ERR_INVALID_LEN 0x03
112#define CTAP_HID_ERR_INVALID_SEQ 0x04
113#define CTAP_HID_ERR_MSG_TIMEOUT 0x05
114#define CTAP_HID_ERR_CHANNEL_BUSY 0x06
115#define CTAP_HID_ERR_LOCK_REQUIRED 0x0a
116#define CTAP_HID_ERR_INVALID_CHANNEL 0x0b
117#define CTAP_HID_ERR_OTHER 0x7f
125#define CTAP_HID_STATUS_PROCESSING 0x01
126#define CTAP_HID_STATUS_UPNEEDED 0x02
133#define CTAP_HID_CIDS_MAX 0x08
134
138#define CTAP_HID_WINK_DELAY 400
139
144#define CTAP_HID_BROADCAST_CID 0xffffffff
145
151#define CTAP_HID_BUFFER_STATUS_BUFFERING 0x00
152#define CTAP_HID_BUFFER_STATUS_DONE 0x01
153#define CTAP_HID_BUFFER_STATUS_ERROR 0x02
160typedef struct {
161 uint8_t cmd;
162 uint8_t bcnth;
163 uint8_t bcntl;
164 uint8_t payload[CTAP_HID_INIT_PAYLOAD_SIZE];
166
171typedef struct {
172 uint8_t seq;
173 uint8_t payload[CTAP_HID_CONT_PAYLOAD_SIZE];
175
180typedef struct {
181 uint32_t cid;
182 union {
185 };
187
193typedef struct __attribute__((packed)){
195 uint32_t cid;
200 uint8_t capabilities;
202
208typedef struct {
209 bool taken;
210 uint32_t cid;
211 uint64_t last_used;
213
220
227
242
250
251#ifdef __cplusplus
252}
253#endif
254#endif /* FIDO2_CTAP_TRANSPORT_HID_CTAP_HID_H */
#define CTAP_HID_CONT_PAYLOAD_SIZE
endpoint size - cont packet metadata
Definition ctap_hid.h:39
#define CTAP_HID_INIT_PAYLOAD_SIZE
endpoint size - init packet metadata
Definition ctap_hid.h:38
#define CTAP_HID_INIT_NONCE_SIZE
CTAP_HID size of nonce for init request.
Definition ctap_hid.h:59
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:156
CTAP_HID channel identifier struct.
Definition ctap_hid.h:208
uint64_t last_used
timestamp of last usage
Definition ctap_hid.h:211
bool taken
is cid taken?
Definition ctap_hid.h:209
uint32_t cid
channel identifier
Definition ctap_hid.h:210
CTAP_HID continuation packet struct.
Definition ctap_hid.h:171
uint8_t seq
packet sequence number
Definition ctap_hid.h:172
CTAP_HID initialization packet struct.
Definition ctap_hid.h:160
uint8_t cmd
CTAP_HID command.
Definition ctap_hid.h:161
uint8_t bcntl
lower byte
Definition ctap_hid.h:163
uint8_t bcnth
higher byte
Definition ctap_hid.h:162
CTAP_HID initialization response struct.
Definition ctap_hid.h:193
uint8_t protocol_version
CTAP_HID protocol version.
Definition ctap_hid.h:196
uint8_t version_minor
minor device version
Definition ctap_hid.h:198
uint8_t version_major
major device version
Definition ctap_hid.h:197
uint32_t cid
channel identifier
Definition ctap_hid.h:195
uint8_t build_version
build device version
Definition ctap_hid.h:199
uint8_t capabilities
capabilities flags
Definition ctap_hid.h:200
CTAP_HID packet struct.
Definition ctap_hid.h:180
ctap_hid_cont_pkt_t cont
continuation packet
Definition ctap_hid.h:184
ctap_hid_init_pkt_t init
initialization packet
Definition ctap_hid.h:183
uint32_t cid
channel identifier
Definition ctap_hid.h:181
Interface and definitions for USB HID type interfaces in USBUS.