mirror of
https://github.com/polhenarejos/pico-keys-sdk
synced 2026-05-28 17:11:23 +02:00
@@ -77,6 +77,7 @@ static portMUX_TYPE mutex = portMUX_INITIALIZER_UNLOCKED;
|
||||
#define CCID_THREAD_TERMINATED 0xffff
|
||||
#define CCID_ACK_TIMEOUT 0x6600
|
||||
|
||||
PACK(
|
||||
typedef struct {
|
||||
uint8_t bMessageType;
|
||||
uint32_t dwLength;
|
||||
@@ -85,7 +86,7 @@ typedef struct {
|
||||
uint8_t abRFU0;
|
||||
uint16_t abRFU1;
|
||||
uint8_t apdu; //Actually it is an array
|
||||
} __attribute__((__packed__)) ccid_header_t;
|
||||
}) ccid_header_t;
|
||||
|
||||
uint8_t ccid_status = 1;
|
||||
static uint8_t itf_num;
|
||||
|
||||
@@ -18,16 +18,9 @@
|
||||
#ifndef _CTAP_HID_H_
|
||||
#define _CTAP_HID_H_
|
||||
|
||||
#ifdef _MSC_VER // Windows
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef unsigned long int uint64_t;
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -47,6 +40,7 @@ extern "C" {
|
||||
#define TYPE_INIT 0x80 // Initial frame identifier
|
||||
#define TYPE_CONT 0x00 // Continuation frame identifier
|
||||
|
||||
PACK(
|
||||
typedef struct {
|
||||
uint32_t cid; // Channel identifier
|
||||
union {
|
||||
@@ -62,7 +56,7 @@ typedef struct {
|
||||
uint8_t data[HID_RPT_SIZE - 5]; // Data payload
|
||||
} cont;
|
||||
};
|
||||
} __attribute__((__packed__)) CTAPHID_FRAME;
|
||||
}) CTAPHID_FRAME;
|
||||
|
||||
extern CTAPHID_FRAME *ctap_req, *ctap_resp;
|
||||
|
||||
@@ -120,10 +114,12 @@ extern CTAPHID_FRAME *ctap_req, *ctap_resp;
|
||||
#define CAPFLAG_WINK 0x01 // Device supports WINK command
|
||||
#define CAPFLAG_CBOR 0x04 // Device supports CBOR command
|
||||
|
||||
PACK(
|
||||
typedef struct {
|
||||
uint8_t nonce[INIT_NONCE_SIZE]; // Client application nonce
|
||||
} __attribute__((__packed__)) CTAPHID_INIT_REQ;
|
||||
}) CTAPHID_INIT_REQ;
|
||||
|
||||
PACK(
|
||||
typedef struct {
|
||||
uint8_t nonce[INIT_NONCE_SIZE]; // Client application nonce
|
||||
uint32_t cid; // Channel identifier
|
||||
@@ -132,7 +128,7 @@ typedef struct {
|
||||
uint8_t versionMinor; // Minor version number
|
||||
uint8_t versionBuild; // Build version number
|
||||
uint8_t capFlags; // Capabilities flags
|
||||
} __attribute__((__packed__)) CTAPHID_INIT_RESP;
|
||||
}) CTAPHID_INIT_RESP;
|
||||
|
||||
// CTAPHID_SYNC command defines
|
||||
|
||||
|
||||
@@ -37,11 +37,12 @@ uint8_t (*get_version_minor)() = NULL;
|
||||
|
||||
static usb_buffer_t hid_rx[ITF_HID_TOTAL] = {0}, hid_tx[ITF_HID_TOTAL] = {0};
|
||||
|
||||
PACK(
|
||||
typedef struct msg_packet {
|
||||
uint16_t len;
|
||||
uint16_t current_len;
|
||||
uint8_t data[CTAP_MAX_PACKET_SIZE];
|
||||
} __attribute__((__packed__)) msg_packet_t;
|
||||
}) msg_packet_t;
|
||||
|
||||
msg_packet_t msg_packet = { 0 };
|
||||
|
||||
@@ -247,11 +248,11 @@ void tud_hid_report_complete_cb(uint8_t instance, uint8_t const *report, uint16_
|
||||
#ifdef ESP_PLATFORM
|
||||
taskENTER_CRITICAL(&mutex);
|
||||
#endif
|
||||
CTAPHID_FRAME *ctap_req = (CTAPHID_FRAME *) report;
|
||||
CTAPHID_FRAME *req = (CTAPHID_FRAME *) report;
|
||||
if (last_write_result[instance] == WRITE_PENDING) {
|
||||
last_write_result[instance] = WRITE_SUCCESS;
|
||||
if (FRAME_TYPE(ctap_req) == TYPE_INIT) {
|
||||
if (ctap_req->init.cmd != CTAPHID_KEEPALIVE) {
|
||||
if (FRAME_TYPE(req) == TYPE_INIT) {
|
||||
if (req->init.cmd != CTAPHID_KEEPALIVE) {
|
||||
send_buffer_size[instance] -= MIN(64 - 7, send_buffer_size[instance]);
|
||||
}
|
||||
}
|
||||
@@ -260,11 +261,11 @@ void tud_hid_report_complete_cb(uint8_t instance, uint8_t const *report, uint16_
|
||||
}
|
||||
}
|
||||
if (last_write_result[instance] == WRITE_SUCCESS) {
|
||||
if (FRAME_TYPE(ctap_req) != TYPE_INIT || ctap_req->init.cmd != CTAPHID_KEEPALIVE) {
|
||||
if (FRAME_TYPE(req) != TYPE_INIT || req->init.cmd != CTAPHID_KEEPALIVE) {
|
||||
if (send_buffer_size[instance] > 0) {
|
||||
ctap_resp = (CTAPHID_FRAME *) ((uint8_t *) ctap_resp + 64 - 5);
|
||||
uint8_t seq = FRAME_TYPE(ctap_req) == TYPE_INIT ? 0 : FRAME_SEQ(ctap_req) + 1;
|
||||
ctap_resp->cid = ctap_req->cid;
|
||||
uint8_t seq = FRAME_TYPE(req) == TYPE_INIT ? 0 : FRAME_SEQ(req) + 1;
|
||||
ctap_resp->cid = req->cid;
|
||||
ctap_resp->cont.seq = seq;
|
||||
|
||||
hid_tx[ITF_HID_CTAP].r_ptr += 64 - 5;
|
||||
@@ -352,7 +353,7 @@ int driver_process_usb_nopacket_hid() {
|
||||
}
|
||||
|
||||
extern const uint8_t fido_aid[], u2f_aid[];
|
||||
extern void apdu_thread(), cbor_thread();
|
||||
extern void apdu_thread(void), cbor_thread(void);
|
||||
|
||||
int driver_process_usb_packet_hid(uint16_t read) {
|
||||
int apdu_sent = 0;
|
||||
@@ -552,7 +553,7 @@ int driver_process_usb_packet_hid(uint16_t read) {
|
||||
msg_packet.len = msg_packet.current_len = 0;
|
||||
last_packet_time = 0;
|
||||
if (apdu_sent < 0) {
|
||||
return ctap_error(-apdu_sent);
|
||||
return ctap_error((uint8_t)(-apdu_sent));
|
||||
}
|
||||
send_keepalive();
|
||||
}
|
||||
|
||||
@@ -87,7 +87,9 @@ bool is_busy() {
|
||||
}
|
||||
|
||||
void usb_send_event(uint32_t flag) {
|
||||
#if !defined(ENABLE_EMULATION)
|
||||
queue_add_blocking(&usb_to_card_q, &flag);
|
||||
#endif
|
||||
if (flag == EV_CMD_AVAILABLE) {
|
||||
timeout_start();
|
||||
}
|
||||
@@ -183,16 +185,8 @@ int card_status(uint8_t itf) {
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
(void) itf;
|
||||
#endif
|
||||
return CCID_ERR_FILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
uint8_t *usb_prepare_response(uint8_t itf) {
|
||||
#ifndef ENABLE_EMULATION
|
||||
#ifdef USB_ITF_CCID
|
||||
#endif
|
||||
return NULL;
|
||||
#else
|
||||
return driver_prepare_response_emul(itf);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -26,8 +26,7 @@
|
||||
#include "pico/util/queue.h"
|
||||
#endif
|
||||
|
||||
|
||||
#include "esp_compat.h"
|
||||
#include "compat.h"
|
||||
|
||||
/* USB thread */
|
||||
#define EV_CARD_CHANGE 1
|
||||
@@ -108,12 +107,18 @@ extern void driver_exec_finished_ccid(uint8_t itf, uint16_t size_next);
|
||||
extern void driver_exec_finished_cont_ccid(uint8_t itf, uint16_t size_next, uint16_t offset);
|
||||
#endif
|
||||
|
||||
#define USB_BUFFER_SIZE 2048 // Size of USB buffer
|
||||
#ifdef ENABLE_EMULATION
|
||||
extern void driver_exec_finished_emul(uint8_t itf, uint16_t size_next);
|
||||
extern void driver_exec_finished_cont_emul(uint8_t itf, uint16_t size_next, uint16_t offset);
|
||||
#endif
|
||||
|
||||
#define USB_BUFFER_SIZE 2048 // Size of USB buffer"
|
||||
PACK(
|
||||
typedef struct {
|
||||
uint8_t buffer[USB_BUFFER_SIZE];
|
||||
uint16_t r_ptr, w_ptr;
|
||||
} __attribute__((__packed__)) usb_buffer_t;
|
||||
uint16_t r_ptr;
|
||||
uint16_t w_ptr;
|
||||
}) usb_buffer_t;
|
||||
|
||||
typedef enum {
|
||||
WRITE_UNKNOWN = 0,
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#ifndef USB_DESCRIPTORS_H_
|
||||
#define USB_DESCRIPTORS_H_
|
||||
|
||||
PACK(
|
||||
struct ccid_class_descriptor {
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
@@ -41,6 +42,6 @@ struct ccid_class_descriptor {
|
||||
uint16_t wLcdLayout;
|
||||
uint8_t bPINSupport;
|
||||
uint8_t bMaxCCIDBusySlots;
|
||||
} __attribute__((__packed__));
|
||||
});
|
||||
|
||||
#endif /* USB_DESCRIPTORS_H_ */
|
||||
|
||||
Reference in New Issue
Block a user