solo1/fido2/ctaphid.h

116 wiersze
3.3 KiB
C
Czysty Zwykły widok Historia

2018-09-13 21:58:34 +00:00
/*
2018-12-17 00:05:33 +00:00
* Copyright (C) 2018 SoloKeys, Inc. <https://solokeys.com/>
*
* This file is part of Solo.
*
* Solo is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Solo is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Solo. If not, see <https://www.gnu.org/licenses/>
*
* This code is available under licenses for commercial use.
* Please contact SoloKeys for more information.
*/
2018-04-29 01:40:13 +00:00
#ifndef _CTAPHID_H_H
#define _CTAPHID_H_H
2018-06-02 18:44:12 +00:00
#include "device.h"
#include "ctap_errors.h"
2018-04-29 01:40:13 +00:00
2018-05-02 02:22:52 +00:00
#define TYPE_INIT 0x80
#define TYPE_CONT 0x00
#define CTAPHID_PING (TYPE_INIT | 0x01)
#define CTAPHID_MSG (TYPE_INIT | 0x03)
#define CTAPHID_LOCK (TYPE_INIT | 0x04)
#define CTAPHID_INIT (TYPE_INIT | 0x06)
#define CTAPHID_WINK (TYPE_INIT | 0x08)
#define CTAPHID_CBOR (TYPE_INIT | 0x10)
#define CTAPHID_CANCEL (TYPE_INIT | 0x11)
#define CTAPHID_ERROR (TYPE_INIT | 0x3f)
2018-10-28 20:30:55 +00:00
#define CTAPHID_KEEPALIVE (TYPE_INIT | 0x3b)
2018-05-02 02:22:52 +00:00
// Custom commands between 0x40-0x7f
2018-12-05 00:14:11 +00:00
#define CTAPHID_BOOT (TYPE_INIT | 0x50)
#define CTAPHID_ENTERBOOT (TYPE_INIT | 0x51)
#define CTAPHID_ENTERSTBOOT (TYPE_INIT | 0x52)
2018-12-06 00:35:22 +00:00
#define CTAPHID_GETRNG (TYPE_INIT | 0x60)
2018-05-02 02:22:52 +00:00
#define ERR_INVALID_CMD 0x01
#define ERR_INVALID_PAR 0x02
#define ERR_INVALID_SEQ 0x04
#define ERR_MSG_TIMEOUT 0x05
#define ERR_CHANNEL_BUSY 0x06
2018-04-29 01:40:13 +00:00
2018-10-28 20:30:55 +00:00
#define CTAPHID_PROTOCOL_VERSION 2
#define CTAPHID_STATUS_IDLE 0
#define CTAPHID_STATUS_PROCESSING 1
#define CTAPHID_STATUS_UPNEEDED 2
2018-04-29 01:40:13 +00:00
#define CTAPHID_INIT_PAYLOAD_SIZE (HID_MESSAGE_SIZE-7)
#define CTAPHID_CONT_PAYLOAD_SIZE (HID_MESSAGE_SIZE-5)
#define CTAPHID_BROADCAST_CID 0xffffffff
#define CTAPHID_BUFFER_SIZE 7609
2018-04-29 01:40:13 +00:00
2018-05-01 03:27:26 +00:00
#define CAPABILITY_WINK 0x01
#define CAPABILITY_LOCK 0x02
#define CAPABILITY_CBOR 0x04
#define CAPABILITY_NMSG 0x08
#define CTAP_CAPABILITIES (CAPABILITY_WINK | CAPABILITY_CBOR)
2018-05-26 19:29:37 +00:00
2018-04-29 01:40:13 +00:00
typedef struct
{
uint32_t cid;
union{
struct{
uint8_t cmd;
uint8_t bcnth;
uint8_t bcntl;
uint8_t payload[CTAPHID_INIT_PAYLOAD_SIZE];
} init;
struct{
uint8_t seq;
uint8_t payload[CTAPHID_CONT_PAYLOAD_SIZE];
} cont;
} pkt;
} CTAPHID_PACKET;
2018-05-01 03:27:26 +00:00
typedef struct
{
uint8_t nonce[8];
uint32_t cid;
uint8_t protocol_version;
uint8_t version_major;
uint8_t version_minor;
uint8_t build_version;
uint8_t capabilities;
} __attribute__((packed)) CTAPHID_INIT_RESPONSE;
2018-04-29 01:40:13 +00:00
void ctaphid_init();
2018-10-28 20:30:55 +00:00
uint8_t ctaphid_handle_packet(uint8_t * pkt_raw);
2018-05-01 03:27:26 +00:00
2018-06-02 18:44:12 +00:00
void ctaphid_check_timeouts();
2018-04-29 01:40:13 +00:00
2018-10-28 20:30:55 +00:00
void ctaphid_update_status(int8_t status);
2018-05-02 02:22:52 +00:00
2018-04-29 01:40:13 +00:00
#define ctaphid_packet_len(pkt) ((uint16_t)((pkt)->pkt.init.bcnth << 8) | ((pkt)->pkt.init.bcntl))
#endif