mirror of
https://github.com/polhenarejos/pico-keys-sdk
synced 2026-05-28 17:11:23 +02:00
WCID interface is always enabled.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
@@ -110,9 +110,6 @@ void init_otp_files() {
|
|||||||
random_gen(NULL, mkek, sizeof(mkek));
|
random_gen(NULL, mkek, sizeof(mkek));
|
||||||
otp_write_data(OTP_KEY_1, mkek, sizeof(mkek));
|
otp_write_data(OTP_KEY_1, mkek, sizeof(mkek));
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
DEBUG_DATA(otp_buffer(OTP_KEY_1), 32);
|
|
||||||
}
|
|
||||||
otp_key_1 = otp_buffer(OTP_KEY_1);
|
otp_key_1 = otp_buffer(OTP_KEY_1);
|
||||||
|
|
||||||
otp_lock_page(page);
|
otp_lock_page(page);
|
||||||
@@ -167,7 +164,6 @@ void init_otp_files() {
|
|||||||
if (esp_efuse_key_block_unused(OTP_KEY_1)) {
|
if (esp_efuse_key_block_unused(OTP_KEY_1)) {
|
||||||
uint8_t mkek[32] = {0};
|
uint8_t mkek[32] = {0};
|
||||||
random_gen(NULL, mkek, sizeof(mkek));
|
random_gen(NULL, mkek, sizeof(mkek));
|
||||||
DEBUG_DATA(mkek, 32);
|
|
||||||
esp_err_t ret = esp_efuse_write_key(OTP_KEY_1, ESP_EFUSE_KEY_PURPOSE_USER, mkek, sizeof(mkek));
|
esp_err_t ret = esp_efuse_write_key(OTP_KEY_1, ESP_EFUSE_KEY_PURPOSE_USER, mkek, sizeof(mkek));
|
||||||
if (ret != ESP_OK) {
|
if (ret != ESP_OK) {
|
||||||
printf("Error writing OTP key 1 [%d]\n", ret);
|
printf("Error writing OTP key 1 [%d]\n", ret);
|
||||||
@@ -185,9 +181,6 @@ void init_otp_files() {
|
|||||||
if (ret != ESP_OK) {
|
if (ret != ESP_OK) {
|
||||||
printf("Error reading OTP key 1 [%d]\n", ret);
|
printf("Error reading OTP key 1 [%d]\n", ret);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
DEBUG_DATA(_otp_key_1, 32);
|
|
||||||
}
|
|
||||||
otp_key_1 = _otp_key_1;
|
otp_key_1 = _otp_key_1;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -87,7 +87,6 @@ int phy_init() {
|
|||||||
memset(&phy_data, 0, sizeof(phy_data_t));
|
memset(&phy_data, 0, sizeof(phy_data_t));
|
||||||
if (file_has_data(ef_phy)) {
|
if (file_has_data(ef_phy)) {
|
||||||
const uint8_t *data = file_get_data(ef_phy);
|
const uint8_t *data = file_get_data(ef_phy);
|
||||||
DEBUG_DATA(data, file_get_size(ef_phy));
|
|
||||||
int ret = phy_unserialize_data(data, file_get_size(ef_phy), &phy_data);
|
int ret = phy_unserialize_data(data, file_get_size(ef_phy), &phy_data);
|
||||||
if (ret != PICOKEY_OK) {
|
if (ret != PICOKEY_OK) {
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
@@ -317,9 +317,8 @@ int main(void) {
|
|||||||
gpio_pulldown_dis(BOOT_PIN);
|
gpio_pulldown_dis(BOOT_PIN);
|
||||||
|
|
||||||
tusb_cfg.string_descriptor[3] = pico_serial_str;
|
tusb_cfg.string_descriptor[3] = pico_serial_str;
|
||||||
if (phy_data.opts & PHY_OPT_WCID) {
|
|
||||||
tusb_cfg.configuration_descriptor = desc_config;
|
tusb_cfg.configuration_descriptor = desc_config;
|
||||||
}
|
|
||||||
tinyusb_driver_install(&tusb_cfg);
|
tinyusb_driver_install(&tusb_cfg);
|
||||||
#else
|
#else
|
||||||
tusb_init();
|
tusb_init();
|
||||||
|
|||||||
@@ -80,22 +80,15 @@ uint8_t const *tud_descriptor_device_cb(void) {
|
|||||||
#define TUSB_SMARTCARD_WCID_DESC_LEN (TUD_INTERFACE_DESC_LEN + TUSB_SMARTCARD_LEN + 2 * TUD_ENDPOINT_DESC_LEN)
|
#define TUSB_SMARTCARD_WCID_DESC_LEN (TUD_INTERFACE_DESC_LEN + TUSB_SMARTCARD_LEN + 2 * TUD_ENDPOINT_DESC_LEN)
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
TUSB_DESC_TOTAL_LEN_NOWCID = TUD_CONFIG_DESC_LEN
|
TUSB_DESC_TOTAL_LEN = TUD_CONFIG_DESC_LEN
|
||||||
#ifdef USB_ITF_HID
|
#ifdef USB_ITF_HID
|
||||||
+ TUD_HID_INOUT_DESC_LEN + TUD_HID_DESC_LEN
|
+ TUD_HID_INOUT_DESC_LEN
|
||||||
|
+ TUD_HID_DESC_LEN
|
||||||
#endif
|
#endif
|
||||||
#ifdef USB_ITF_CCID
|
#ifdef USB_ITF_CCID
|
||||||
+ TUSB_SMARTCARD_CCID_DESC_LEN
|
+ TUSB_SMARTCARD_CCID_DESC_LEN
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
enum {
|
|
||||||
TUSB_DESC_TOTAL_LEN = TUSB_DESC_TOTAL_LEN_NOWCID
|
|
||||||
#ifdef USB_ITF_CCID
|
|
||||||
#ifdef USB_ITF_WCID
|
|
||||||
+ TUSB_SMARTCARD_WCID_DESC_LEN
|
+ TUSB_SMARTCARD_WCID_DESC_LEN
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef USB_ITF_HID
|
#ifdef USB_ITF_HID
|
||||||
@@ -109,13 +102,11 @@ uint8_t const desc_hid_report_kb[] = {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USB_ITF_CCID
|
#ifdef USB_ITF_CCID
|
||||||
#ifdef USB_ITF_WCID
|
|
||||||
#define TUD_SMARTCARD_DESCRIPTOR_WEB(_itf, _strix, _epout, _epin, _epsize) \
|
#define TUD_SMARTCARD_DESCRIPTOR_WEB(_itf, _strix, _epout, _epin, _epsize) \
|
||||||
9, TUSB_DESC_INTERFACE, _itf, 0, 2, 0xFF, 0, 0, _strix, \
|
9, TUSB_DESC_INTERFACE, _itf, 0, 2, 0xFF, 0, 0, _strix, \
|
||||||
54, 0x21, U16_TO_U8S_LE(0x0110), 0, 0x1, U32_TO_U8S_LE(0x01|0x2), U32_TO_U8S_LE(0xDFC), U32_TO_U8S_LE(0xDFC), 0, U32_TO_U8S_LE(0x2580), U32_TO_U8S_LE(0x2580), 0, U32_TO_U8S_LE(0xFE), U32_TO_U8S_LE(0), U32_TO_U8S_LE(0), U32_TO_U8S_LE(0x40840), U32_TO_U8S_LE(65544+10), 0xFF, 0xFF, U16_TO_U8S_LE(0x0), 0, 0x1, \
|
54, 0x21, U16_TO_U8S_LE(0x0110), 0, 0x1, U32_TO_U8S_LE(0x01|0x2), U32_TO_U8S_LE(0xDFC), U32_TO_U8S_LE(0xDFC), 0, U32_TO_U8S_LE(0x2580), U32_TO_U8S_LE(0x2580), 0, U32_TO_U8S_LE(0xFE), U32_TO_U8S_LE(0), U32_TO_U8S_LE(0), U32_TO_U8S_LE(0x40840), U32_TO_U8S_LE(65544+10), 0xFF, 0xFF, U16_TO_U8S_LE(0x0), 0, 0x1, \
|
||||||
7, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0, \
|
7, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0, \
|
||||||
7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0
|
7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0
|
||||||
#endif
|
|
||||||
#define TUD_SMARTCARD_DESCRIPTOR(_itf, _strix, _epout, _epin, _epint, _epsize) \
|
#define TUD_SMARTCARD_DESCRIPTOR(_itf, _strix, _epout, _epin, _epint, _epsize) \
|
||||||
9, TUSB_DESC_INTERFACE, _itf, 0, 3, TUSB_CLASS_SMART_CARD, 0, 0, _strix, \
|
9, TUSB_DESC_INTERFACE, _itf, 0, 3, TUSB_CLASS_SMART_CARD, 0, 0, _strix, \
|
||||||
54, 0x21, U16_TO_U8S_LE(0x0110), 0, 0x1, U32_TO_U8S_LE(0x01|0x2), U32_TO_U8S_LE(0xDFC), U32_TO_U8S_LE(0xDFC), 0, U32_TO_U8S_LE(0x2580), U32_TO_U8S_LE(0x2580), 0, U32_TO_U8S_LE(0xFE), U32_TO_U8S_LE(0), U32_TO_U8S_LE(0), U32_TO_U8S_LE(0x40840), U32_TO_U8S_LE(65544+10), 0xFF, 0xFF, U16_TO_U8S_LE(0x0), 0, 0x1, \
|
54, 0x21, U16_TO_U8S_LE(0x0110), 0, 0x1, U32_TO_U8S_LE(0x01|0x2), U32_TO_U8S_LE(0xDFC), U32_TO_U8S_LE(0xDFC), 0, U32_TO_U8S_LE(0x2580), U32_TO_U8S_LE(0x2580), 0, U32_TO_U8S_LE(0xFE), U32_TO_U8S_LE(0), U32_TO_U8S_LE(0), U32_TO_U8S_LE(0x40840), U32_TO_U8S_LE(65544+10), 0xFF, 0xFF, U16_TO_U8S_LE(0x0), 0, 0x1, \
|
||||||
@@ -124,21 +115,6 @@ uint8_t const desc_hid_report_kb[] = {
|
|||||||
7, TUSB_DESC_ENDPOINT, _epint, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_epsize), 0
|
7, TUSB_DESC_ENDPOINT, _epint, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_epsize), 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const uint8_t desc_config_nowcid[] = {
|
|
||||||
#ifdef USB_ITF_CCID
|
|
||||||
TUD_CONFIG_DESCRIPTOR(1, ITF_TOTAL-1, 4, TUSB_DESC_TOTAL_LEN_NOWCID, USB_CONFIG_ATT_ONE | TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, MAX_USB_POWER),
|
|
||||||
#else
|
|
||||||
TUD_CONFIG_DESCRIPTOR(1, ITF_TOTAL, 4, TUSB_DESC_TOTAL_LEN_NOWCID, USB_CONFIG_ATT_ONE | TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, MAX_USB_POWER),
|
|
||||||
#endif
|
|
||||||
#ifdef USB_ITF_HID
|
|
||||||
TUD_HID_INOUT_DESCRIPTOR(ITF_HID, ITF_HID + 5, HID_ITF_PROTOCOL_NONE, sizeof(desc_hid_report), EPNUM_HID, TUSB_DIR_IN_MASK | EPNUM_HID, CFG_TUD_HID_EP_BUFSIZE, 10),
|
|
||||||
TUD_HID_DESCRIPTOR(ITF_KEYBOARD, ITF_KEYBOARD + 5, HID_ITF_PROTOCOL_NONE, sizeof(desc_hid_report_kb), TUSB_DIR_IN_MASK | (EPNUM_HID + 1), 16, 5),
|
|
||||||
#endif
|
|
||||||
#ifdef USB_ITF_CCID
|
|
||||||
TUD_SMARTCARD_DESCRIPTOR(ITF_CCID, ITF_CCID+5, 1, TUSB_DIR_IN_MASK | 1, TUSB_DIR_IN_MASK | 2, 64),
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
const uint8_t desc_config[] = {
|
const uint8_t desc_config[] = {
|
||||||
TUD_CONFIG_DESCRIPTOR(1, ITF_TOTAL, 4, TUSB_DESC_TOTAL_LEN, USB_CONFIG_ATT_ONE | TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, MAX_USB_POWER),
|
TUD_CONFIG_DESCRIPTOR(1, ITF_TOTAL, 4, TUSB_DESC_TOTAL_LEN, USB_CONFIG_ATT_ONE | TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, MAX_USB_POWER),
|
||||||
#ifdef USB_ITF_HID
|
#ifdef USB_ITF_HID
|
||||||
@@ -147,16 +123,13 @@ const uint8_t desc_config[] = {
|
|||||||
#endif
|
#endif
|
||||||
#ifdef USB_ITF_CCID
|
#ifdef USB_ITF_CCID
|
||||||
TUD_SMARTCARD_DESCRIPTOR(ITF_CCID, ITF_CCID+5, 1, TUSB_DIR_IN_MASK | 1, TUSB_DIR_IN_MASK | 2, 64),
|
TUD_SMARTCARD_DESCRIPTOR(ITF_CCID, ITF_CCID+5, 1, TUSB_DIR_IN_MASK | 1, TUSB_DIR_IN_MASK | 2, 64),
|
||||||
#ifdef USB_ITF_WCID
|
|
||||||
TUD_SMARTCARD_DESCRIPTOR_WEB(ITF_WCID, ITF_WCID+5, 3, TUSB_DIR_IN_MASK | 3, 64),
|
TUD_SMARTCARD_DESCRIPTOR_WEB(ITF_WCID, ITF_WCID+5, 3, TUSB_DIR_IN_MASK | 3, 64),
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef USB_ITF_HID
|
#ifdef USB_ITF_HID
|
||||||
uint8_t const *tud_hid_descriptor_report_cb(uint8_t itf) {
|
uint8_t const *tud_hid_descriptor_report_cb(uint8_t itf) {
|
||||||
printf("report_cb %d\n", itf);
|
printf("report_cb %d\n", itf);
|
||||||
DEBUG_DATA(desc_hid_report, sizeof(desc_hid_report));
|
|
||||||
if (itf == ITF_HID_CTAP) {
|
if (itf == ITF_HID_CTAP) {
|
||||||
return desc_hid_report;
|
return desc_hid_report;
|
||||||
}
|
}
|
||||||
@@ -169,14 +142,10 @@ uint8_t const *tud_hid_descriptor_report_cb(uint8_t itf) {
|
|||||||
#ifndef ESP_PLATFORM
|
#ifndef ESP_PLATFORM
|
||||||
uint8_t const *tud_descriptor_configuration_cb(uint8_t index) {
|
uint8_t const *tud_descriptor_configuration_cb(uint8_t index) {
|
||||||
(void) index; // for multiple configurations
|
(void) index; // for multiple configurations
|
||||||
if (phy_data.opts & PHY_OPT_WCID) {
|
|
||||||
return desc_config;
|
return desc_config;
|
||||||
}
|
|
||||||
return desc_config_nowcid;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USB_ITF_WCID
|
|
||||||
#define BOS_TOTAL_LEN (TUD_BOS_DESC_LEN + TUD_BOS_WEBUSB_DESC_LEN + TUD_BOS_MICROSOFT_OS_DESC_LEN)
|
#define BOS_TOTAL_LEN (TUD_BOS_DESC_LEN + TUD_BOS_WEBUSB_DESC_LEN + TUD_BOS_MICROSOFT_OS_DESC_LEN)
|
||||||
#define MS_OS_20_DESC_LEN 0xB2
|
#define MS_OS_20_DESC_LEN 0xB2
|
||||||
|
|
||||||
@@ -276,12 +245,9 @@ uint8_t const desc_bos[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
uint8_t const *tud_descriptor_bos_cb(void) {
|
uint8_t const *tud_descriptor_bos_cb(void) {
|
||||||
if (phy_data.opts & PHY_OPT_WCID) {
|
|
||||||
return desc_bos;
|
return desc_bos;
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// String Descriptors
|
// String Descriptors
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
@@ -299,10 +265,8 @@ char const *string_desc_arr [] = {
|
|||||||
#endif
|
#endif
|
||||||
#ifdef USB_ITF_CCID
|
#ifdef USB_ITF_CCID
|
||||||
, "Pico Key CCID Interface"
|
, "Pico Key CCID Interface"
|
||||||
#ifdef USB_ITF_WCID
|
|
||||||
, "Pico Key WebCCID Interface"
|
, "Pico Key WebCCID Interface"
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef ESP_PLATFORM
|
#ifdef ESP_PLATFORM
|
||||||
|
|||||||
Reference in New Issue
Block a user