7#include "device/usbd_pvt.h"
14static const char*
TAG =
"CCID";
16#define CCID_LOG(tag, fmt, ...) LOG_I(tag, fmt, ##__VA_ARGS__)
17#define CCID_LOG_E(tag, fmt, ...) LOG_E(tag, fmt, ##__VA_ARGS__)
18#define CCID_LOG_W(tag, fmt, ...) LOG_W(tag, fmt, ##__VA_ARGS__)
20#define CCID_RX_BUF_SIZE (CCID_MAX_MSG_SIZE + CCID_HEADER_SIZE)
21#define CCID_TX_BUF_SIZE (CCID_MAX_MSG_SIZE + CCID_HEADER_SIZE)
58 if (desc_itf->bInterfaceClass != TUSB_CLASS_SMART_CARD) {
62 ccid_state.itf_num = desc_itf->bInterfaceNumber;
65 uint16_t drv_len =
sizeof(tusb_desc_interface_t);
66 uint8_t
const* p_desc = (uint8_t
const*)desc_itf + drv_len;
68 while (drv_len < max_len) {
69 uint8_t desc_len = p_desc[0];
70 uint8_t desc_type = p_desc[1];
71 if (desc_type == 0x21) {
80 while (drv_len < max_len && ep_count < desc_itf->bNumEndpoints) {
81 uint8_t desc_len = p_desc[0];
82 uint8_t desc_type = p_desc[1];
84 if (desc_type == TUSB_DESC_ENDPOINT) {
85 tusb_desc_endpoint_t
const* ep_desc = (tusb_desc_endpoint_t
const*)p_desc;
86 uint8_t ep_addr = ep_desc->bEndpointAddress;
88 if (usbd_edpt_open(
rhport, ep_desc)) {
89 if (tu_edpt_dir(ep_addr) == TUSB_DIR_IN) {
111 if (stage != CONTROL_STAGE_SETUP)
return true;
113 if (request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS &&
114 request->bmRequestType_bit.recipient == TUSB_REQ_RCPT_INTERFACE &&
121 if (request->bRequest == 0x01) {
124 return tud_control_status(
rhport, request);
131 if (request->bRequest == 0x02) {
132 static const uint8_t clocks[] = {0xA0, 0x0F, 0x00, 0x00};
133 return tud_control_xfer(
rhport, request,
134 const_cast<uint8_t*
>(clocks),
142 if (request->bRequest == 0x03) {
143 static const uint8_t rates[] = {0xB0, 0x04, 0x00, 0x00};
144 return tud_control_xfer(
rhport, request,
145 const_cast<uint8_t*
>(rates),
155 if (result != XFER_RESULT_SUCCESS) {
178 if ((uint32_t)
ccid_state.rx_len >= total_len) {
187 }
else if (resp_len < 0) {
int ccid_process_message(const uint8_t *msg, size_t msg_len, uint8_t *resp, size_t resp_max)
Processes one incoming CCID message and writes corresponding response.
usbd_class_driver_t const * usbd_app_driver_get_cb(uint8_t *driver_count)
static struct @003011067126132137154336156300372031204254255025 ccid_state
static void ccid_driver_init(void)
static usbd_class_driver_t const ccid_driver
static uint16_t ccid_driver_open(uint8_t rhport, tusb_desc_interface_t const *desc_itf, uint16_t max_len)
static void ccid_driver_reset(uint8_t rhport)
static bool ccid_driver_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const *request)
static uint8_t ccid_rx_buf[(2048+10)]
#define CCID_LOG(tag, fmt,...)
void ccid_driver_link_anchor(void)
Initializes CCID transport and backing OpenPGP applet.
static bool ccid_driver_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
static uint8_t ccid_tx_buf[(2048+10)]
CDC Log: logging over TinyUSB CDC and UART.