mirror of
https://github.com/polhenarejos/pico-keys-sdk
synced 2026-05-10 17:28:27 +02:00
Harmonizing coding style.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
@@ -50,33 +50,33 @@
|
||||
#define USB_BUF_SIZE (MAX_CMD_APDU_DATA_SIZE+20+9)
|
||||
#endif
|
||||
|
||||
#define CCID_SET_PARAMS 0x61 /* non-ICCD command */
|
||||
#define CCID_POWER_ON 0x62
|
||||
#define CCID_POWER_OFF 0x63
|
||||
#define CCID_SLOT_STATUS 0x65 /* non-ICCD command */
|
||||
#define CCID_SECURE 0x69 /* non-ICCD command */
|
||||
#define CCID_GET_PARAMS 0x6C /* non-ICCD command */
|
||||
#define CCID_RESET_PARAMS 0x6D /* non-ICCD command */
|
||||
#define CCID_XFR_BLOCK 0x6F
|
||||
#define CCID_DATA_BLOCK_RET 0x80
|
||||
#define CCID_SLOT_STATUS_RET 0x81 /* non-ICCD result */
|
||||
#define CCID_PARAMS_RET 0x82 /* non-ICCD result */
|
||||
#define CCID_SET_PARAMS 0x61 /* non-ICCD command */
|
||||
#define CCID_POWER_ON 0x62
|
||||
#define CCID_POWER_OFF 0x63
|
||||
#define CCID_SLOT_STATUS 0x65 /* non-ICCD command */
|
||||
#define CCID_SECURE 0x69 /* non-ICCD command */
|
||||
#define CCID_GET_PARAMS 0x6C /* non-ICCD command */
|
||||
#define CCID_RESET_PARAMS 0x6D /* non-ICCD command */
|
||||
#define CCID_XFR_BLOCK 0x6F
|
||||
#define CCID_DATA_BLOCK_RET 0x80
|
||||
#define CCID_SLOT_STATUS_RET 0x81 /* non-ICCD result */
|
||||
#define CCID_PARAMS_RET 0x82 /* non-ICCD result */
|
||||
|
||||
#define CCID_MSG_SEQ_OFFSET 6
|
||||
#define CCID_MSG_STATUS_OFFSET 7
|
||||
#define CCID_MSG_ERROR_OFFSET 8
|
||||
#define CCID_MSG_CHAIN_OFFSET 9
|
||||
#define CCID_MSG_DATA_OFFSET 10 /* == CCID_MSG_HEADER_SIZE */
|
||||
#define CCID_MAX_MSG_DATA_SIZE USB_BUF_SIZE
|
||||
#define CCID_MSG_SEQ_OFFSET 6
|
||||
#define CCID_MSG_STATUS_OFFSET 7
|
||||
#define CCID_MSG_ERROR_OFFSET 8
|
||||
#define CCID_MSG_CHAIN_OFFSET 9
|
||||
#define CCID_MSG_DATA_OFFSET 10 /* == CCID_MSG_HEADER_SIZE */
|
||||
#define CCID_MAX_MSG_DATA_SIZE USB_BUF_SIZE
|
||||
|
||||
#define CCID_STATUS_RUN 0x00
|
||||
#define CCID_STATUS_PRESENT 0x01
|
||||
#define CCID_STATUS_NOTPRESENT 0x02
|
||||
#define CCID_CMD_STATUS_OK 0x00
|
||||
#define CCID_CMD_STATUS_ERROR 0x40
|
||||
#define CCID_CMD_STATUS_TIMEEXT 0x80
|
||||
#define CCID_STATUS_RUN 0x00
|
||||
#define CCID_STATUS_PRESENT 0x01
|
||||
#define CCID_STATUS_NOTPRESENT 0x02
|
||||
#define CCID_CMD_STATUS_OK 0x00
|
||||
#define CCID_CMD_STATUS_ERROR 0x40
|
||||
#define CCID_CMD_STATUS_TIMEEXT 0x80
|
||||
|
||||
#define CCID_ERROR_XFR_OVERRUN 0xFC
|
||||
#define CCID_ERROR_XFR_OVERRUN 0xFC
|
||||
|
||||
/*
|
||||
* Since command-byte is at offset 0,
|
||||
@@ -97,67 +97,78 @@ struct ccid_header {
|
||||
uint8_t abRFU0;
|
||||
uint16_t abRFU1;
|
||||
uint8_t apdu; //Actually it is an array
|
||||
} __attribute__ ((__packed__));
|
||||
} __attribute__((__packed__));
|
||||
|
||||
uint8_t ccid_status = 1;
|
||||
static uint8_t itf_num;
|
||||
|
||||
void ccid_write_offset(uint16_t size, uint16_t offset) {
|
||||
if (*usb_get_tx(ITF_CCID)+offset != 0x81)
|
||||
DEBUG_PAYLOAD(usb_get_tx(ITF_CCID)+offset,size+10);
|
||||
void ccid_write_offset(uint16_t size, uint16_t offset)
|
||||
{
|
||||
if (*usb_get_tx(ITF_CCID)+offset != 0x81) {
|
||||
DEBUG_PAYLOAD(usb_get_tx(ITF_CCID)+offset, size+10);
|
||||
}
|
||||
usb_write_offset(ITF_CCID, size+10, offset);
|
||||
}
|
||||
|
||||
void ccid_write(uint16_t size) {
|
||||
void ccid_write(uint16_t size)
|
||||
{
|
||||
ccid_write_offset(size, 0);
|
||||
}
|
||||
|
||||
struct ccid_header *ccid_response;
|
||||
struct ccid_header *ccid_header;
|
||||
|
||||
int driver_init_ccid() {
|
||||
ccid_header = (struct ccid_header *)usb_get_rx(ITF_CCID);
|
||||
int driver_init_ccid()
|
||||
{
|
||||
ccid_header = (struct ccid_header *) usb_get_rx(ITF_CCID);
|
||||
// apdu.header = &ccid_header->apdu;
|
||||
|
||||
ccid_response = (struct ccid_header *)usb_get_tx(ITF_CCID);
|
||||
ccid_response = (struct ccid_header *) usb_get_tx(ITF_CCID);
|
||||
|
||||
usb_set_timeout_counter(ITF_CCID, 1500);
|
||||
|
||||
return CCID_OK;
|
||||
}
|
||||
|
||||
void tud_vendor_rx_cb(uint8_t itf) {
|
||||
void tud_vendor_rx_cb(uint8_t itf)
|
||||
{
|
||||
(void) itf;
|
||||
|
||||
uint32_t len = tud_vendor_available();
|
||||
usb_rx(ITF_CCID, NULL, len);
|
||||
}
|
||||
|
||||
void tud_vendor_tx_cb(uint8_t itf, uint32_t sent_bytes) {
|
||||
printf("written %ld\n",sent_bytes);
|
||||
void tud_vendor_tx_cb(uint8_t itf, uint32_t sent_bytes)
|
||||
{
|
||||
printf("written %ld\n", sent_bytes);
|
||||
usb_write_flush(ITF_CCID);
|
||||
}
|
||||
|
||||
int driver_write_ccid(const uint8_t *buffer, size_t buffer_size) {
|
||||
int driver_write_ccid(const uint8_t *buffer, size_t buffer_size)
|
||||
{
|
||||
return tud_vendor_write(buffer, buffer_size);
|
||||
}
|
||||
|
||||
size_t driver_read_ccid(uint8_t *buffer, size_t buffer_size) {
|
||||
size_t driver_read_ccid(uint8_t *buffer, size_t buffer_size)
|
||||
{
|
||||
return tud_vendor_read(buffer, buffer_size);
|
||||
}
|
||||
|
||||
int driver_process_usb_nopacket_ccid() {
|
||||
int driver_process_usb_nopacket_ccid()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int driver_process_usb_packet_ccid(uint16_t rx_read) {
|
||||
int driver_process_usb_packet_ccid(uint16_t rx_read)
|
||||
{
|
||||
if (rx_read >= 10) {
|
||||
driver_init_ccid();
|
||||
//printf("%d %d %x\r\n",tccid->dwLength,rx_read-10,tccid->bMessageType);
|
||||
if (ccid_header->dwLength <= rx_read-10) {
|
||||
size_t apdu_sent = 0;
|
||||
if (ccid_header->bMessageType != 0x65)
|
||||
DEBUG_PAYLOAD(usb_get_rx(ITF_CCID),usb_read_available(ITF_CCID));
|
||||
if (ccid_header->bMessageType != 0x65) {
|
||||
DEBUG_PAYLOAD(usb_get_rx(ITF_CCID), usb_read_available(ITF_CCID));
|
||||
}
|
||||
if (ccid_header->bMessageType == 0x65) {
|
||||
ccid_response->bMessageType = CCID_SLOT_STATUS_RET;
|
||||
ccid_response->dwLength = 0;
|
||||
@@ -166,8 +177,7 @@ int driver_process_usb_packet_ccid(uint16_t rx_read) {
|
||||
ccid_response->abRFU0 = ccid_status;
|
||||
ccid_response->abRFU1 = 0;
|
||||
ccid_write(0);
|
||||
}
|
||||
else if (ccid_header->bMessageType == 0x62) {
|
||||
} else if (ccid_header->bMessageType == 0x62) {
|
||||
size_t size_atr = (ccid_atr ? ccid_atr[0] : 0);
|
||||
ccid_response->bMessageType = 0x80;
|
||||
ccid_response->dwLength = size_atr;
|
||||
@@ -180,10 +190,10 @@ int driver_process_usb_packet_ccid(uint16_t rx_read) {
|
||||
card_start(apdu_thread);
|
||||
ccid_status = 0;
|
||||
ccid_write(size_atr);
|
||||
}
|
||||
else if (ccid_header->bMessageType == 0x63) {
|
||||
if (ccid_status == 0)
|
||||
} else if (ccid_header->bMessageType == 0x63) {
|
||||
if (ccid_status == 0) {
|
||||
card_exit(0);
|
||||
}
|
||||
ccid_status = 1;
|
||||
ccid_response->bMessageType = CCID_SLOT_STATUS_RET;
|
||||
ccid_response->dwLength = 0;
|
||||
@@ -192,8 +202,7 @@ int driver_process_usb_packet_ccid(uint16_t rx_read) {
|
||||
ccid_response->abRFU0 = ccid_status;
|
||||
ccid_response->abRFU1 = 0;
|
||||
ccid_write(0);
|
||||
}
|
||||
else if (ccid_header->bMessageType == 0x6F) {
|
||||
} else if (ccid_header->bMessageType == 0x6F) {
|
||||
apdu_sent = apdu_process(ITF_CCID, &ccid_header->apdu, ccid_header->dwLength);
|
||||
}
|
||||
usb_clear_rx(ITF_CCID);
|
||||
@@ -201,23 +210,25 @@ int driver_process_usb_packet_ccid(uint16_t rx_read) {
|
||||
}
|
||||
}
|
||||
/*
|
||||
if (usb_read_available() && c->epo->ready) {
|
||||
if (usb_read_available() && c->epo->ready) {
|
||||
if ()
|
||||
uint32_t count = usb_read(endp1_rx_buf, sizeof(endp1_rx_buf));
|
||||
//if (endp1_rx_buf[0] != 0x65)
|
||||
DEBUG_PAYLOAD(endp1_rx_buf, count);
|
||||
//DEBUG_PAYLOAD(endp1_rx_buf, count);
|
||||
ccid_rx_ready(count);
|
||||
}
|
||||
*/
|
||||
}
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool driver_mounted_ccid() {
|
||||
bool driver_mounted_ccid()
|
||||
{
|
||||
return tud_vendor_mounted();
|
||||
}
|
||||
|
||||
void driver_exec_timeout_ccid() {
|
||||
void driver_exec_timeout_ccid()
|
||||
{
|
||||
ccid_response->bMessageType = CCID_DATA_BLOCK_RET;
|
||||
ccid_response->dwLength = 0;
|
||||
ccid_response->bSlot = 0;
|
||||
@@ -227,7 +238,8 @@ void driver_exec_timeout_ccid() {
|
||||
ccid_write(0);
|
||||
}
|
||||
|
||||
void driver_exec_finished_ccid(size_t size_next) {
|
||||
void driver_exec_finished_ccid(size_t size_next)
|
||||
{
|
||||
ccid_response->bMessageType = CCID_DATA_BLOCK_RET;
|
||||
ccid_response->dwLength = size_next;
|
||||
ccid_response->bSlot = 0;
|
||||
@@ -237,9 +249,10 @@ void driver_exec_finished_ccid(size_t size_next) {
|
||||
ccid_write(size_next);
|
||||
}
|
||||
|
||||
void driver_exec_finished_cont_ccid(size_t size_next, size_t offset) {
|
||||
void driver_exec_finished_cont_ccid(size_t size_next, size_t offset)
|
||||
{
|
||||
|
||||
ccid_response = (struct ccid_header *)(usb_get_tx(ITF_CCID)+offset-10);
|
||||
ccid_response = (struct ccid_header *) (usb_get_tx(ITF_CCID)+offset-10);
|
||||
ccid_response->bMessageType = CCID_DATA_BLOCK_RET;
|
||||
ccid_response->dwLength = size_next;
|
||||
ccid_response->bSlot = 0;
|
||||
@@ -249,40 +262,47 @@ void driver_exec_finished_cont_ccid(size_t size_next, size_t offset) {
|
||||
ccid_write_offset(size_next, offset-10);
|
||||
}
|
||||
|
||||
uint8_t *driver_prepare_response_ccid() {
|
||||
ccid_response = (struct ccid_header *)usb_get_tx(ITF_CCID);
|
||||
uint8_t *driver_prepare_response_ccid()
|
||||
{
|
||||
ccid_response = (struct ccid_header *) usb_get_tx(ITF_CCID);
|
||||
apdu.rdata = &ccid_response->apdu;
|
||||
return &ccid_response->apdu;
|
||||
}
|
||||
#define USB_CONFIG_ATT_ONE TU_BIT(7)
|
||||
|
||||
#define MAX_USB_POWER 1
|
||||
#define MAX_USB_POWER 1
|
||||
|
||||
static void ccid_init_cb(void) {
|
||||
static void ccid_init_cb(void)
|
||||
{
|
||||
TU_LOG1("-------- CCID INIT\r\n");
|
||||
vendord_init();
|
||||
|
||||
//ccid_notify_slot_change(c);
|
||||
}
|
||||
|
||||
static void ccid_reset_cb(uint8_t rhport) {
|
||||
static void ccid_reset_cb(uint8_t rhport)
|
||||
{
|
||||
TU_LOG1("-------- CCID RESET\r\n");
|
||||
itf_num = 0;
|
||||
vendord_reset(rhport);
|
||||
}
|
||||
|
||||
static uint16_t ccid_open(uint8_t rhport, tusb_desc_interface_t const *itf_desc, uint16_t max_len) {
|
||||
uint8_t *itf_vendor = (uint8_t *)malloc(sizeof(uint8_t)*max_len);
|
||||
static uint16_t ccid_open(uint8_t rhport, tusb_desc_interface_t const *itf_desc, uint16_t max_len)
|
||||
{
|
||||
uint8_t *itf_vendor = (uint8_t *) malloc(sizeof(uint8_t)*max_len);
|
||||
//TU_LOG1("-------- CCID OPEN\r\n");
|
||||
TU_VERIFY(itf_desc->bInterfaceClass == TUSB_CLASS_SMART_CARD && itf_desc->bInterfaceSubClass == 0 && itf_desc->bInterfaceProtocol == 0, 0);
|
||||
TU_VERIFY(
|
||||
itf_desc->bInterfaceClass == TUSB_CLASS_SMART_CARD && itf_desc->bInterfaceSubClass == 0 && itf_desc->bInterfaceProtocol == 0,
|
||||
0);
|
||||
|
||||
//vendord_open expects a CLASS_VENDOR interface class
|
||||
memcpy(itf_vendor, itf_desc, sizeof(uint8_t)*max_len);
|
||||
((tusb_desc_interface_t *)itf_vendor)->bInterfaceClass = TUSB_CLASS_VENDOR_SPECIFIC;
|
||||
vendord_open(rhport, (tusb_desc_interface_t *)itf_vendor, max_len);
|
||||
((tusb_desc_interface_t *) itf_vendor)->bInterfaceClass = TUSB_CLASS_VENDOR_SPECIFIC;
|
||||
vendord_open(rhport, (tusb_desc_interface_t *) itf_vendor, max_len);
|
||||
free(itf_vendor);
|
||||
|
||||
uint16_t const drv_len = sizeof(tusb_desc_interface_t) + sizeof(struct ccid_class_descriptor) + 2*sizeof(tusb_desc_endpoint_t);
|
||||
uint16_t const drv_len = sizeof(tusb_desc_interface_t) + sizeof(struct ccid_class_descriptor) +
|
||||
2*sizeof(tusb_desc_endpoint_t);
|
||||
TU_VERIFY(max_len >= drv_len, 0);
|
||||
|
||||
itf_num = itf_desc->bInterfaceNumber;
|
||||
@@ -290,44 +310,56 @@ static uint16_t ccid_open(uint8_t rhport, tusb_desc_interface_t const *itf_desc,
|
||||
}
|
||||
|
||||
// Support for parameterized reset via vendor interface control request
|
||||
static bool ccid_control_xfer_cb(uint8_t __unused rhport, uint8_t stage, tusb_control_request_t const * request) {
|
||||
static bool ccid_control_xfer_cb(uint8_t __unused rhport,
|
||||
uint8_t stage,
|
||||
tusb_control_request_t const *request)
|
||||
{
|
||||
// nothing to do with DATA & ACK stage
|
||||
TU_LOG2("-------- CCID CTRL XFER\r\n");
|
||||
if (stage != CONTROL_STAGE_SETUP) return true;
|
||||
if (stage != CONTROL_STAGE_SETUP) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (request->wIndex == itf_num)
|
||||
{
|
||||
TU_LOG2("-------- bmRequestType %x, bRequest %x, wValue %x, wLength %x\r\n",request->bmRequestType,request->bRequest, request->wValue, request->wLength);
|
||||
if (request->wIndex == itf_num) {
|
||||
TU_LOG2("-------- bmRequestType %x, bRequest %x, wValue %x, wLength %x\r\n",
|
||||
request->bmRequestType,
|
||||
request->bRequest,
|
||||
request->wValue,
|
||||
request->wLength);
|
||||
/*
|
||||
#if PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL
|
||||
#if PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL
|
||||
if (request->bRequest == RESET_REQUEST_BOOTSEL) {
|
||||
#ifdef PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED
|
||||
#ifdef PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED
|
||||
uint gpio_mask = 1u << PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED;
|
||||
#else
|
||||
#else
|
||||
uint gpio_mask = 0u;
|
||||
#endif
|
||||
#if !PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED
|
||||
#endif
|
||||
#if !PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED
|
||||
if (request->wValue & 0x100) {
|
||||
gpio_mask = 1u << (request->wValue >> 9u);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
reset_usb_boot(gpio_mask, (request->wValue & 0x7f) | PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK);
|
||||
// does not return, otherwise we'd return true
|
||||
}
|
||||
#endif
|
||||
#if PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT
|
||||
#endif
|
||||
#if PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT
|
||||
if (request->bRequest == RESET_REQUEST_FLASH) {
|
||||
watchdog_reboot(0, 0, PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
#endif
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool ccid_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes) {
|
||||
static bool ccid_xfer_cb(uint8_t rhport,
|
||||
uint8_t ep_addr,
|
||||
xfer_result_t result,
|
||||
uint32_t xferred_bytes)
|
||||
{
|
||||
//printf("------ CALLED XFER_CB\r\n");
|
||||
return vendord_xfer_cb(rhport, ep_addr, result, xferred_bytes);
|
||||
//return true;
|
||||
@@ -346,7 +378,8 @@ static const usbd_class_driver_t ccid_driver = {
|
||||
};
|
||||
|
||||
// Implement callback to add our custom driver
|
||||
usbd_class_driver_t const *usbd_app_driver_get_cb(uint8_t *driver_count) {
|
||||
usbd_class_driver_t const *usbd_app_driver_get_cb(uint8_t *driver_count)
|
||||
{
|
||||
*driver_count = 1;
|
||||
return &ccid_driver;
|
||||
}
|
||||
|
||||
@@ -26,16 +26,16 @@ extern const uint8_t historical_bytes[];
|
||||
#define USB_LL_BUF_SIZE 64
|
||||
|
||||
enum ccid_state {
|
||||
CCID_STATE_NOCARD, /* No card available */
|
||||
CCID_STATE_START, /* Initial */
|
||||
CCID_STATE_WAIT, /* Waiting APDU */
|
||||
CCID_STATE_NOCARD, /* No card available */
|
||||
CCID_STATE_START, /* Initial */
|
||||
CCID_STATE_WAIT, /* Waiting APDU */
|
||||
|
||||
CCID_STATE_EXECUTE, /* Executing command */
|
||||
CCID_STATE_ACK_REQUIRED_0, /* Ack required (executing)*/
|
||||
CCID_STATE_ACK_REQUIRED_1, /* Waiting user's ACK (execution finished) */
|
||||
CCID_STATE_EXECUTE, /* Executing command */
|
||||
CCID_STATE_ACK_REQUIRED_0, /* Ack required (executing)*/
|
||||
CCID_STATE_ACK_REQUIRED_1, /* Waiting user's ACK (execution finished) */
|
||||
|
||||
CCID_STATE_EXITED, /* CCID Thread Terminated */
|
||||
CCID_STATE_EXEC_REQUESTED, /* Exec requested */
|
||||
CCID_STATE_EXITED, /* CCID Thread Terminated */
|
||||
CCID_STATE_EXEC_REQUESTED, /* Exec requested */
|
||||
};
|
||||
|
||||
extern const uint8_t *ccid_atr;
|
||||
|
||||
@@ -133,29 +133,29 @@ struct usb_endpoint_descriptor_long {
|
||||
|
||||
|
||||
struct ccid_class_descriptor {
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint16_t bcdCCID;
|
||||
uint8_t bMaxSlotIndex;
|
||||
uint8_t bVoltageSupport;
|
||||
uint32_t dwProtocols;
|
||||
uint32_t dwDefaultClock;
|
||||
uint32_t dwMaximumClock;
|
||||
uint8_t bNumClockSupport;
|
||||
uint32_t dwDataRate;
|
||||
uint32_t dwMaxDataRate;
|
||||
uint8_t bNumDataRatesSupported;
|
||||
uint32_t dwMaxIFSD;
|
||||
uint32_t dwSynchProtocols;
|
||||
uint32_t dwMechanical;
|
||||
uint32_t dwFeatures;
|
||||
uint32_t dwMaxCCIDMessageLength;
|
||||
uint8_t bClassGetResponse;
|
||||
uint8_t bclassEnvelope;
|
||||
uint16_t wLcdLayout;
|
||||
uint8_t bPINSupport;
|
||||
uint8_t bMaxCCIDBusySlots;
|
||||
} __attribute__ ((__packed__));
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint16_t bcdCCID;
|
||||
uint8_t bMaxSlotIndex;
|
||||
uint8_t bVoltageSupport;
|
||||
uint32_t dwProtocols;
|
||||
uint32_t dwDefaultClock;
|
||||
uint32_t dwMaximumClock;
|
||||
uint8_t bNumClockSupport;
|
||||
uint32_t dwDataRate;
|
||||
uint32_t dwMaxDataRate;
|
||||
uint8_t bNumDataRatesSupported;
|
||||
uint32_t dwMaxIFSD;
|
||||
uint32_t dwSynchProtocols;
|
||||
uint32_t dwMechanical;
|
||||
uint32_t dwFeatures;
|
||||
uint32_t dwMaxCCIDMessageLength;
|
||||
uint8_t bClassGetResponse;
|
||||
uint8_t bclassEnvelope;
|
||||
uint16_t wLcdLayout;
|
||||
uint8_t bPINSupport;
|
||||
uint8_t bMaxCCIDBusySlots;
|
||||
} __attribute__((__packed__));
|
||||
|
||||
static const struct ccid_class_descriptor ccid_desc = {
|
||||
.bLength = sizeof(struct ccid_class_descriptor),
|
||||
@@ -164,8 +164,8 @@ static const struct ccid_class_descriptor ccid_desc = {
|
||||
.bMaxSlotIndex = 0,
|
||||
.bVoltageSupport = 0x01, // 5.0V
|
||||
.dwProtocols = (
|
||||
0x01| // T=0
|
||||
0x02), // T=1
|
||||
0x01| // T=0
|
||||
0x02), // T=1
|
||||
.dwDefaultClock = (0xDFC),
|
||||
.dwMaximumClock = (0xDFC),
|
||||
.bNumClockSupport = 0,
|
||||
@@ -219,90 +219,90 @@ struct usb_device_configuration {
|
||||
|
||||
// EP0 IN and OUT
|
||||
static const struct usb_endpoint_descriptor ep0_out = {
|
||||
.bLength = sizeof(struct usb_endpoint_descriptor),
|
||||
.bDescriptorType = USB_DT_ENDPOINT,
|
||||
.bEndpointAddress = EP0_OUT_ADDR, // EP number 0, OUT from host (rx to device)
|
||||
.bmAttributes = USB_TRANSFER_TYPE_CONTROL,
|
||||
.wMaxPacketSize = 64,
|
||||
.bInterval = 0
|
||||
.bLength = sizeof(struct usb_endpoint_descriptor),
|
||||
.bDescriptorType = USB_DT_ENDPOINT,
|
||||
.bEndpointAddress = EP0_OUT_ADDR, // EP number 0, OUT from host (rx to device)
|
||||
.bmAttributes = USB_TRANSFER_TYPE_CONTROL,
|
||||
.wMaxPacketSize = 64,
|
||||
.bInterval = 0
|
||||
};
|
||||
|
||||
static const struct usb_endpoint_descriptor ep0_in = {
|
||||
.bLength = sizeof(struct usb_endpoint_descriptor),
|
||||
.bDescriptorType = USB_DT_ENDPOINT,
|
||||
.bEndpointAddress = EP0_IN_ADDR, // EP number 0, OUT from host (rx to device)
|
||||
.bmAttributes = USB_TRANSFER_TYPE_CONTROL,
|
||||
.wMaxPacketSize = 64,
|
||||
.bInterval = 0
|
||||
.bLength = sizeof(struct usb_endpoint_descriptor),
|
||||
.bDescriptorType = USB_DT_ENDPOINT,
|
||||
.bEndpointAddress = EP0_IN_ADDR, // EP number 0, OUT from host (rx to device)
|
||||
.bmAttributes = USB_TRANSFER_TYPE_CONTROL,
|
||||
.wMaxPacketSize = 64,
|
||||
.bInterval = 0
|
||||
};
|
||||
|
||||
// Descriptors
|
||||
static const struct usb_device_descriptor device_descriptor = {
|
||||
.bLength = sizeof(struct usb_device_descriptor),
|
||||
.bDescriptorType = USB_DT_DEVICE,
|
||||
.bcdUSB = 0x0200, // USB 1.1 device
|
||||
.bDeviceClass = 0, // Specified in interface descriptor
|
||||
.bDeviceSubClass = 0, // No subclass
|
||||
.bDeviceProtocol = 0, // No protocol
|
||||
.bMaxPacketSize0 = 64, // Max packet size for ep0
|
||||
.idVendor = 0x20a0, // Your vendor id
|
||||
.idProduct = 0x4230, // Your product ID
|
||||
.bcdDevice = 0x0101, // No device revision number
|
||||
.iManufacturer = 1, // Manufacturer string index
|
||||
.iProduct = 2, // Product string index
|
||||
.iSerialNumber = 3, // No serial number
|
||||
.bNumConfigurations = 1 // One configuration
|
||||
.bLength = sizeof(struct usb_device_descriptor),
|
||||
.bDescriptorType = USB_DT_DEVICE,
|
||||
.bcdUSB = 0x0200, // USB 1.1 device
|
||||
.bDeviceClass = 0, // Specified in interface descriptor
|
||||
.bDeviceSubClass = 0, // No subclass
|
||||
.bDeviceProtocol = 0, // No protocol
|
||||
.bMaxPacketSize0 = 64, // Max packet size for ep0
|
||||
.idVendor = 0x20a0, // Your vendor id
|
||||
.idProduct = 0x4230, // Your product ID
|
||||
.bcdDevice = 0x0101, // No device revision number
|
||||
.iManufacturer = 1, // Manufacturer string index
|
||||
.iProduct = 2, // Product string index
|
||||
.iSerialNumber = 3, // No serial number
|
||||
.bNumConfigurations = 1 // One configuration
|
||||
};
|
||||
|
||||
static const struct usb_interface_descriptor interface_descriptor = {
|
||||
.bLength = sizeof(struct usb_interface_descriptor),
|
||||
.bDescriptorType = USB_DT_INTERFACE,
|
||||
.bInterfaceNumber = 0,
|
||||
.bAlternateSetting = 0,
|
||||
.bNumEndpoints = 2, // Interface has 2 endpoints
|
||||
.bInterfaceClass = 0x0b, // Vendor specific endpoint
|
||||
.bInterfaceSubClass = 0,
|
||||
.bInterfaceProtocol = 0,
|
||||
.iInterface = 5
|
||||
.bLength = sizeof(struct usb_interface_descriptor),
|
||||
.bDescriptorType = USB_DT_INTERFACE,
|
||||
.bInterfaceNumber = 0,
|
||||
.bAlternateSetting = 0,
|
||||
.bNumEndpoints = 2, // Interface has 2 endpoints
|
||||
.bInterfaceClass = 0x0b, // Vendor specific endpoint
|
||||
.bInterfaceSubClass = 0,
|
||||
.bInterfaceProtocol = 0,
|
||||
.iInterface = 5
|
||||
};
|
||||
|
||||
static const struct usb_endpoint_descriptor ep1_out = {
|
||||
.bLength = sizeof(struct usb_endpoint_descriptor),
|
||||
.bDescriptorType = USB_DT_ENDPOINT,
|
||||
.bEndpointAddress = EP1_OUT_ADDR, // EP number 1, OUT from host (rx to device)
|
||||
.bmAttributes = USB_TRANSFER_TYPE_BULK,
|
||||
.wMaxPacketSize = 64,
|
||||
.bInterval = 0
|
||||
.bLength = sizeof(struct usb_endpoint_descriptor),
|
||||
.bDescriptorType = USB_DT_ENDPOINT,
|
||||
.bEndpointAddress = EP1_OUT_ADDR, // EP number 1, OUT from host (rx to device)
|
||||
.bmAttributes = USB_TRANSFER_TYPE_BULK,
|
||||
.wMaxPacketSize = 64,
|
||||
.bInterval = 0
|
||||
};
|
||||
|
||||
static const struct usb_endpoint_descriptor ep2_in = {
|
||||
.bLength = sizeof(struct usb_endpoint_descriptor),
|
||||
.bDescriptorType = USB_DT_ENDPOINT,
|
||||
.bEndpointAddress = EP2_IN_ADDR, // EP number 2, IN from host (tx from device)
|
||||
.bmAttributes = USB_TRANSFER_TYPE_BULK,
|
||||
.wMaxPacketSize = 64,
|
||||
.bInterval = 0
|
||||
.bLength = sizeof(struct usb_endpoint_descriptor),
|
||||
.bDescriptorType = USB_DT_ENDPOINT,
|
||||
.bEndpointAddress = EP2_IN_ADDR, // EP number 2, IN from host (tx from device)
|
||||
.bmAttributes = USB_TRANSFER_TYPE_BULK,
|
||||
.wMaxPacketSize = 64,
|
||||
.bInterval = 0
|
||||
};
|
||||
|
||||
static const struct usb_configuration_descriptor config_descriptor = {
|
||||
.bLength = sizeof(struct usb_configuration_descriptor),
|
||||
.bDescriptorType = USB_DT_CONFIG,
|
||||
.wTotalLength = (sizeof(config_descriptor) +
|
||||
sizeof(interface_descriptor) +
|
||||
sizeof(ccid_desc) +
|
||||
sizeof(ep1_out) +
|
||||
sizeof(ep2_in)),
|
||||
.bNumInterfaces = 1,
|
||||
.bConfigurationValue = 1, // Configuration 1
|
||||
.iConfiguration = 4, // No string
|
||||
.bmAttributes = 0xa0, // attributes: self powered, no remote wakeup
|
||||
.bMaxPower = 0x32 // 100ma
|
||||
.bLength = sizeof(struct usb_configuration_descriptor),
|
||||
.bDescriptorType = USB_DT_CONFIG,
|
||||
.wTotalLength = (sizeof(config_descriptor) +
|
||||
sizeof(interface_descriptor) +
|
||||
sizeof(ccid_desc) +
|
||||
sizeof(ep1_out) +
|
||||
sizeof(ep2_in)),
|
||||
.bNumInterfaces = 1,
|
||||
.bConfigurationValue = 1, // Configuration 1
|
||||
.iConfiguration = 4, // No string
|
||||
.bmAttributes = 0xa0, // attributes: self powered, no remote wakeup
|
||||
.bMaxPower = 0x32 // 100ma
|
||||
};
|
||||
|
||||
static const unsigned char lang_descriptor[] = {
|
||||
4, // bLength
|
||||
0x03, // bDescriptorType == String Descriptor
|
||||
0x09, 0x04 // language id = us english
|
||||
4, // bLength
|
||||
0x03, // bDescriptorType == String Descriptor
|
||||
0x09, 0x04 // language id = us english
|
||||
};
|
||||
|
||||
|
||||
@@ -322,4 +322,3 @@ extern bool usb_write_available();
|
||||
extern uint32_t usb_write_flush();
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user