mirror of
https://github.com/polhenarejos/pico-keys-sdk
synced 2026-06-18 20:35:57 +02:00
Add casts to fix warnings.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
12
src/apdu.c
12
src/apdu.c
@@ -123,12 +123,12 @@ uint16_t apdu_process(uint8_t itf, const uint8_t *buffer, uint16_t buffer_size)
|
|||||||
#ifndef ENABLE_EMULATION
|
#ifndef ENABLE_EMULATION
|
||||||
#ifdef USB_ITF_HID
|
#ifdef USB_ITF_HID
|
||||||
if (itf == ITF_HID_CTAP) {
|
if (itf == ITF_HID_CTAP) {
|
||||||
driver_exec_finished_cont_hid(itf, apdu.rlen + 2, rdata_gr - apdu.rdata);
|
driver_exec_finished_cont_hid(itf, apdu.rlen + 2, (uint16_t)(rdata_gr - apdu.rdata));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef USB_ITF_CCID
|
#ifdef USB_ITF_CCID
|
||||||
if (itf == ITF_SC_CCID || itf == ITF_SC_WCID) {
|
if (itf == ITF_SC_CCID || itf == ITF_SC_WCID) {
|
||||||
driver_exec_finished_cont_ccid(itf, apdu.rlen + 2, rdata_gr - apdu.rdata);
|
driver_exec_finished_cont_ccid(itf, apdu.rlen + 2, (uint16_t)(rdata_gr - apdu.rdata));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
@@ -152,12 +152,12 @@ uint16_t apdu_process(uint8_t itf, const uint8_t *buffer, uint16_t buffer_size)
|
|||||||
#ifndef ENABLE_EMULATION
|
#ifndef ENABLE_EMULATION
|
||||||
#ifdef USB_ITF_HID
|
#ifdef USB_ITF_HID
|
||||||
if (itf == ITF_HID_CTAP) {
|
if (itf == ITF_HID_CTAP) {
|
||||||
driver_exec_finished_cont_hid(itf, apdu.ne + 2, rdata_gr - apdu.ne - apdu.rdata);
|
driver_exec_finished_cont_hid(itf, (uint16_t)(apdu.ne + 2), (uint16_t)(rdata_gr - apdu.ne - apdu.rdata));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef USB_ITF_CCID
|
#ifdef USB_ITF_CCID
|
||||||
if (itf == ITF_SC_CCID || itf == ITF_SC_WCID) {
|
if (itf == ITF_SC_CCID || itf == ITF_SC_WCID) {
|
||||||
driver_exec_finished_cont_ccid(itf, apdu.ne + 2, rdata_gr - apdu.ne - apdu.rdata);
|
driver_exec_finished_cont_ccid(itf, (uint16_t)(apdu.ne + 2), (uint16_t)(rdata_gr - apdu.ne - apdu.rdata));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
@@ -183,7 +183,8 @@ uint16_t set_res_sw(uint8_t sw1, uint8_t sw2) {
|
|||||||
return make_uint16_t_be(sw1, sw2);
|
return make_uint16_t_be(sw1, sw2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void apdu_thread(void) {
|
void *apdu_thread(void *arg) {
|
||||||
|
(void)arg;
|
||||||
card_init_core1();
|
card_init_core1();
|
||||||
while (1) {
|
while (1) {
|
||||||
uint32_t m = 0;
|
uint32_t m = 0;
|
||||||
@@ -219,6 +220,7 @@ done: ;
|
|||||||
#ifdef ESP_PLATFORM
|
#ifdef ESP_PLATFORM
|
||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
#endif
|
#endif
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void apdu_finish() {
|
void apdu_finish() {
|
||||||
|
|||||||
@@ -73,6 +73,6 @@ extern int process_apdu();
|
|||||||
extern uint16_t apdu_process(uint8_t, const uint8_t *buffer, uint16_t buffer_size);
|
extern uint16_t apdu_process(uint8_t, const uint8_t *buffer, uint16_t buffer_size);
|
||||||
extern void apdu_finish();
|
extern void apdu_finish();
|
||||||
extern uint16_t apdu_next();
|
extern uint16_t apdu_next();
|
||||||
extern void apdu_thread();
|
extern void *apdu_thread(void *);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ int decrypt_with_aad(const uint8_t key[32], const uint8_t *in_buf, size_t in_len
|
|||||||
void double_hash_pin(const uint8_t *pin, uint16_t len, uint8_t output[32]) {
|
void double_hash_pin(const uint8_t *pin, uint16_t len, uint8_t output[32]) {
|
||||||
uint8_t o1[32];
|
uint8_t o1[32];
|
||||||
hash_multi(pin, len, o1);
|
hash_multi(pin, len, o1);
|
||||||
for (int i = 0; i < sizeof(o1); i++) {
|
for (size_t i = 0; i < sizeof(o1); i++) {
|
||||||
o1[i] ^= pin[i % len];
|
o1[i] ^= pin[i % len];
|
||||||
}
|
}
|
||||||
hash_multi(o1, sizeof(o1), output);
|
hash_multi(o1, sizeof(o1), output);
|
||||||
|
|||||||
16
src/debug.h
16
src/debug.h
@@ -20,16 +20,16 @@
|
|||||||
|
|
||||||
#if defined(DEBUG_APDU) && DEBUG_APDU == 1
|
#if defined(DEBUG_APDU) && DEBUG_APDU == 1
|
||||||
#define DEBUG_PAYLOAD(_p, _s) { \
|
#define DEBUG_PAYLOAD(_p, _s) { \
|
||||||
printf("Payload %s (%d bytes) [%s:%d]:\n", #_p, (int) (_s), __FILE__, __LINE__); \
|
printf("Payload %s (%zu bytes) [%s:%d]:\n", #_p, (size_t)(_s), __FILE__, __LINE__); \
|
||||||
for (int _i = 0; _i < _s; _i += 16) { \
|
for (size_t _i = 0; _i < (size_t)(_s); _i += 16) { \
|
||||||
printf("%" PRIxPTR "h : ", (uintptr_t) (_i + _p)); \
|
printf("%" PRIxPTR "h : ", (uintptr_t) (_i + _p)); \
|
||||||
for (int _j = 0; _j < 16; _j++) { \
|
for (size_t _j = 0; _j < 16; _j++) { \
|
||||||
if (_j < _s - _i) printf("%02X ", (_p)[_i + _j]); \
|
if (_j < (size_t)(_s) - _i) printf("%02X ", (_p)[_i + _j]); \
|
||||||
else printf(" "); \
|
else printf(" "); \
|
||||||
if (_j == 7) printf(" "); \
|
if (_j == 7) printf(" "); \
|
||||||
} printf(": "); \
|
} printf(": "); \
|
||||||
for (int _j = 0; _j < 16; _j++) { \
|
for (size_t _j = 0; _j < 16; _j++) { \
|
||||||
if (_j < _s - _i && (_p)[_i + _j] > 32 && (_p)[_i + _j] != 127 && (_p)[_i + _j] < 176) printf("%c", (_p)[_i + _j]); \
|
if (_j < (size_t)(_s) - _i && (_p)[_i + _j] > 32 && (_p)[_i + _j] != 127 && (_p)[_i + _j] < 176) printf("%c", (_p)[_i + _j]); \
|
||||||
else printf(" "); \
|
else printf(" "); \
|
||||||
if (_j == 7) printf(" "); \
|
if (_j == 7) printf(" "); \
|
||||||
} \
|
} \
|
||||||
@@ -37,9 +37,9 @@
|
|||||||
} printf("\n"); \
|
} printf("\n"); \
|
||||||
}
|
}
|
||||||
#define DEBUG_DATA(_p, _s) { \
|
#define DEBUG_DATA(_p, _s) { \
|
||||||
printf("Data %s (%d bytes) [%s:%d]:\n", #_p, (int) (_s), __FILE__, __LINE__); \
|
printf("Data %s (%zu bytes) [%s:%d]:\n", #_p, (size_t)(_s), __FILE__, __LINE__); \
|
||||||
char *_tmp = (char *) calloc(2 * (_s) + 1, sizeof(char)); \
|
char *_tmp = (char *) calloc(2 * (_s) + 1, sizeof(char)); \
|
||||||
for (int _i = 0; _i < (_s); _i++) { \
|
for (size_t _i = 0; _i < (size_t)(_s); _i++) { \
|
||||||
sprintf(&_tmp[2 * _i], "%02X", (_p)[_i]); \
|
sprintf(&_tmp[2 * _i], "%02X", (_p)[_i]); \
|
||||||
} \
|
} \
|
||||||
printf("%s\n", _tmp); \
|
printf("%s\n", _tmp); \
|
||||||
|
|||||||
@@ -237,7 +237,7 @@ int sm_verify() {
|
|||||||
uint16_t input_len = 0;
|
uint16_t input_len = 0;
|
||||||
int r = 0;
|
int r = 0;
|
||||||
bool add_header = (CLA(apdu) & 0xC) == 0xC;
|
bool add_header = (CLA(apdu) & 0xC) == 0xC;
|
||||||
int data_len = (int) (apdu.nc / sm_blocksize) * sm_blocksize;
|
size_t data_len = (size_t)(apdu.nc / sm_blocksize) * sm_blocksize;
|
||||||
if (data_len % sm_blocksize) {
|
if (data_len % sm_blocksize) {
|
||||||
data_len += sm_blocksize;
|
data_len += sm_blocksize;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -282,7 +282,7 @@ void scan_region(bool persistent)
|
|||||||
void wait_flash_finish();
|
void wait_flash_finish();
|
||||||
void scan_flash() {
|
void scan_flash() {
|
||||||
initialize_flash(false); //soft initialization
|
initialize_flash(false); //soft initialization
|
||||||
uint32_t r1 = *(uintptr_t *) flash_read(end_rom_pool), r2 = *(uintptr_t *) flash_read(end_rom_pool + sizeof(uintptr_t));
|
uint32_t r1 = (uint32_t)(*(uintptr_t *) flash_read(end_rom_pool)), r2 = (uint32_t)(*(uintptr_t *) flash_read(end_rom_pool + sizeof(uintptr_t)));
|
||||||
if ((r1 == 0xffffffff || r1 == 0xefefefef) && (r2 == 0xffffffff || r2 == 0xefefefef)) {
|
if ((r1 == 0xffffffff || r1 == 0xefefefef) && (r2 == 0xffffffff || r2 == 0xefefefef)) {
|
||||||
printf("First initialization (or corrupted!)\n");
|
printf("First initialization (or corrupted!)\n");
|
||||||
uint8_t empty[sizeof(uintptr_t) * 2 + sizeof(uint32_t)];
|
uint8_t empty[sizeof(uintptr_t) * 2 + sizeof(uint32_t)];
|
||||||
|
|||||||
@@ -71,6 +71,9 @@
|
|||||||
|
|
||||||
#define MAX_DYNAMIC_FILES 256
|
#define MAX_DYNAMIC_FILES 256
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
__pragma( pack(push, 1) )
|
||||||
|
#endif
|
||||||
typedef struct file {
|
typedef struct file {
|
||||||
const uint8_t *name;
|
const uint8_t *name;
|
||||||
uint8_t *data; //should include 2 bytes len at begining
|
uint8_t *data; //should include 2 bytes len at begining
|
||||||
@@ -82,7 +85,13 @@ typedef struct file {
|
|||||||
#ifdef ENABLE_EMULATION
|
#ifdef ENABLE_EMULATION
|
||||||
uint32_t _padding;
|
uint32_t _padding;
|
||||||
#endif
|
#endif
|
||||||
} __attribute__ ((packed)) file_t;
|
}
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
__pragma( pack(pop) )
|
||||||
|
#else
|
||||||
|
__attribute__ ((packed))
|
||||||
|
#endif
|
||||||
|
file_t;
|
||||||
|
|
||||||
extern bool file_has_data(file_t *);
|
extern bool file_has_data(file_t *);
|
||||||
|
|
||||||
|
|||||||
@@ -195,15 +195,15 @@ int flash_write_data_to_file(file_t *file, const uint8_t *data, uint16_t len) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t flash_free_space() {
|
uint32_t flash_free_space() {
|
||||||
return last_base - start_data_pool;
|
return (uint32_t)(last_base - start_data_pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t flash_used_space() {
|
uint32_t flash_used_space() {
|
||||||
return end_data_pool - last_base;
|
return (uint32_t)(end_data_pool - last_base);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t flash_total_space() {
|
uint32_t flash_total_space() {
|
||||||
return end_data_pool - start_data_pool;
|
return (uint32_t)(end_data_pool - start_data_pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t flash_num_files() {
|
uint32_t flash_num_files() {
|
||||||
|
|||||||
@@ -54,8 +54,8 @@
|
|||||||
#else
|
#else
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include "queue.h"
|
|
||||||
#endif
|
#endif
|
||||||
|
#include "queue.h"
|
||||||
#endif
|
#endif
|
||||||
#define FLASH_SECTOR_SIZE 4096
|
#define FLASH_SECTOR_SIZE 4096
|
||||||
#define XIP_BASE 0
|
#define XIP_BASE 0
|
||||||
@@ -322,7 +322,7 @@ uint8_t *flash_read(uintptr_t addr) {
|
|||||||
uintptr_t flash_read_uintptr(uintptr_t addr) {
|
uintptr_t flash_read_uintptr(uintptr_t addr) {
|
||||||
uint8_t *p = flash_read(addr);
|
uint8_t *p = flash_read(addr);
|
||||||
uintptr_t v = 0x0;
|
uintptr_t v = 0x0;
|
||||||
for (int i = 0; i < sizeof(uintptr_t); i++) {
|
for (size_t i = 0; i < sizeof(uintptr_t); i++) {
|
||||||
v |= (uintptr_t) p[i] << (8 * i);
|
v |= (uintptr_t) p[i] << (8 * i);
|
||||||
}
|
}
|
||||||
return v;
|
return v;
|
||||||
@@ -330,7 +330,7 @@ uintptr_t flash_read_uintptr(uintptr_t addr) {
|
|||||||
uint16_t flash_read_uint16(uintptr_t addr) {
|
uint16_t flash_read_uint16(uintptr_t addr) {
|
||||||
uint8_t *p = flash_read(addr);
|
uint8_t *p = flash_read(addr);
|
||||||
uint16_t v = 0x0;
|
uint16_t v = 0x0;
|
||||||
for (int i = 0; i < sizeof(uint16_t); i++) {
|
for (size_t i = 0; i < sizeof(uint16_t); i++) {
|
||||||
v |= p[i] << (8 * i);
|
v |= p[i] << (8 * i);
|
||||||
}
|
}
|
||||||
return v;
|
return v;
|
||||||
|
|||||||
@@ -171,6 +171,9 @@ int otp_enable_secure_boot(uint8_t bootkey, bool secure_lock) {
|
|||||||
}
|
}
|
||||||
#elif defined(ESP_PLATFORM)
|
#elif defined(ESP_PLATFORM)
|
||||||
// TODO: Implement secure boot for ESP32-S3
|
// TODO: Implement secure boot for ESP32-S3
|
||||||
|
#else
|
||||||
|
(void)bootkey;
|
||||||
|
(void)secure_lock;
|
||||||
#endif // PICO_RP2350
|
#endif // PICO_RP2350
|
||||||
goto err;
|
goto err;
|
||||||
err:
|
err:
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ int phy_serialize_data(const phy_data_t *phy, uint8_t *data, uint16_t *len) {
|
|||||||
}
|
}
|
||||||
if (phy->usb_product_present) {
|
if (phy->usb_product_present) {
|
||||||
*p++ = PHY_USB_PRODUCT;
|
*p++ = PHY_USB_PRODUCT;
|
||||||
*p++ = strlen(phy->usb_product) + 1;
|
*p++ = (uint8_t)strlen(phy->usb_product) + 1;
|
||||||
strcpy((char *)p, phy->usb_product);
|
strcpy((char *)p, phy->usb_product);
|
||||||
p += strlen(phy->usb_product);
|
p += strlen(phy->usb_product);
|
||||||
*p++ = '\0';
|
*p++ = '\0';
|
||||||
@@ -76,7 +76,7 @@ int phy_serialize_data(const phy_data_t *phy, uint8_t *data, uint16_t *len) {
|
|||||||
*p++ = phy->led_driver;
|
*p++ = phy->led_driver;
|
||||||
}
|
}
|
||||||
|
|
||||||
*len = p - data;
|
*len = (uint8_t)(p - data);
|
||||||
return PICOKEY_OK;
|
return PICOKEY_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -118,7 +118,6 @@ bool is_req_button_pending() {
|
|||||||
|
|
||||||
bool cancel_button = false;
|
bool cancel_button = false;
|
||||||
|
|
||||||
#ifdef ENABLE_EMULATION
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
struct timezone
|
struct timezone
|
||||||
@@ -148,7 +147,7 @@ int gettimeofday(struct timeval* tp, struct timezone* tzp)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#else
|
#if !defined(ENABLE_EMULATION)
|
||||||
#ifdef ESP_PLATFORM
|
#ifdef ESP_PLATFORM
|
||||||
bool picok_board_button_read() {
|
bool picok_board_button_read() {
|
||||||
int boot_state = gpio_get_level(BOOT_PIN);
|
int boot_state = gpio_get_level(BOOT_PIN);
|
||||||
@@ -307,7 +306,7 @@ int main(void) {
|
|||||||
#endif
|
#endif
|
||||||
pico_get_unique_board_id(&pico_serial);
|
pico_get_unique_board_id(&pico_serial);
|
||||||
memset(pico_serial_str, 0, sizeof(pico_serial_str));
|
memset(pico_serial_str, 0, sizeof(pico_serial_str));
|
||||||
for (int i = 0; i < sizeof(pico_serial); i++) {
|
for (size_t i = 0; i < sizeof(pico_serial); i++) {
|
||||||
snprintf(&pico_serial_str[2 * i], 3, "%02X", pico_serial.id[i]);
|
snprintf(&pico_serial_str[2 * i], 3, "%02X", pico_serial.id[i]);
|
||||||
}
|
}
|
||||||
mbedtls_sha256(pico_serial.id, sizeof(pico_serial.id), pico_serial_hash, false);
|
mbedtls_sha256(pico_serial.id, sizeof(pico_serial.id), pico_serial_hash, false);
|
||||||
|
|||||||
@@ -75,12 +75,12 @@ static inline uint16_t get_uint16_t_be(const uint8_t *b) {
|
|||||||
static inline uint16_t get_uint16_t_le(const uint8_t *b) {
|
static inline uint16_t get_uint16_t_le(const uint8_t *b) {
|
||||||
return make_uint16_t_le(b[0], b[1]);
|
return make_uint16_t_le(b[0], b[1]);
|
||||||
}
|
}
|
||||||
static inline uint32_t put_uint16_t_be(uint16_t n, uint8_t *b) {
|
static inline uint8_t put_uint16_t_be(uint16_t n, uint8_t *b) {
|
||||||
*b++ = (n >> 8) & 0xff;
|
*b++ = (n >> 8) & 0xff;
|
||||||
*b = n & 0xff;
|
*b = n & 0xff;
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
static inline uint32_t put_uint16_t_le(uint16_t n, uint8_t *b) {
|
static inline uint8_t put_uint16_t_le(uint16_t n, uint8_t *b) {
|
||||||
*b++ = n & 0xff;
|
*b++ = n & 0xff;
|
||||||
*b = (n >> 8) & 0xff;
|
*b = (n >> 8) & 0xff;
|
||||||
return 2;
|
return 2;
|
||||||
@@ -154,7 +154,6 @@ extern int flash_clear_file(file_t *file);
|
|||||||
extern int (*button_pressed_cb)(uint8_t);
|
extern int (*button_pressed_cb)(uint8_t);
|
||||||
|
|
||||||
extern bool is_req_button_pending();
|
extern bool is_req_button_pending();
|
||||||
extern uint32_t button_timeout;
|
|
||||||
|
|
||||||
#define SW_BYTES_REMAINING_00() set_res_sw(0x61, 0x00)
|
#define SW_BYTES_REMAINING_00() set_res_sw(0x61, 0x00)
|
||||||
#define SW_WARNING_STATE_UNCHANGED() set_res_sw(0x62, 0x00)
|
#define SW_WARNING_STATE_UNCHANGED() set_res_sw(0x62, 0x00)
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ int cmd_write() {
|
|||||||
|
|
||||||
if (P1(apdu) == 0x1) { // PHY
|
if (P1(apdu) == 0x1) { // PHY
|
||||||
#ifndef ENABLE_EMULATION
|
#ifndef ENABLE_EMULATION
|
||||||
int ret = phy_unserialize_data(apdu.data, apdu.nc, &phy_data);
|
int ret = phy_unserialize_data(apdu.data, (uint16_t)apdu.nc, &phy_data);
|
||||||
if (ret == PICOKEY_OK) {
|
if (ret == PICOKEY_OK) {
|
||||||
if (phy_save() != PICOKEY_OK) {
|
if (phy_save() != PICOKEY_OK) {
|
||||||
return SW_EXEC_ERROR();
|
return SW_EXEC_ERROR();
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
#include "hwrng.h"
|
#include "hwrng.h"
|
||||||
#include "bsp/board.h"
|
#include "bsp/board.h"
|
||||||
#include "pico/rand.h"
|
#include "pico/rand.h"
|
||||||
#elif (ESP_PLATFORM)
|
#elif defined(ESP_PLATFORM)
|
||||||
#include "bootloader_random.h"
|
#include "bootloader_random.h"
|
||||||
#include "esp_random.h"
|
#include "esp_random.h"
|
||||||
#include "esp_compat.h"
|
#include "esp_compat.h"
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ static portMUX_TYPE mutex = portMUX_INITIALIZER_UNLOCKED;
|
|||||||
#include "apdu.h"
|
#include "apdu.h"
|
||||||
#include "usb.h"
|
#include "usb.h"
|
||||||
|
|
||||||
static bool mounted = false;
|
|
||||||
extern void init_fido();
|
extern void init_fido();
|
||||||
bool is_nk = false;
|
bool is_nk = false;
|
||||||
uint8_t (*get_version_major)() = NULL;
|
uint8_t (*get_version_major)() = NULL;
|
||||||
@@ -48,14 +47,6 @@ typedef struct msg_packet {
|
|||||||
|
|
||||||
msg_packet_t msg_packet = { 0 };
|
msg_packet_t msg_packet = { 0 };
|
||||||
|
|
||||||
void tud_mount_cb() {
|
|
||||||
mounted = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool driver_mounted_hid() {
|
|
||||||
return mounted;
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint16_t *send_buffer_size = NULL;
|
static uint16_t *send_buffer_size = NULL;
|
||||||
static write_status_t *last_write_result = NULL;
|
static write_status_t *last_write_result = NULL;
|
||||||
|
|
||||||
@@ -158,7 +149,7 @@ static bool sent_key = false;
|
|||||||
static bool keyboard_encode = false;
|
static bool keyboard_encode = false;
|
||||||
|
|
||||||
void add_keyboard_buffer(const uint8_t *data, size_t data_len, bool encode) {
|
void add_keyboard_buffer(const uint8_t *data, size_t data_len, bool encode) {
|
||||||
keyboard_buffer_len = MIN(sizeof(keyboard_buffer), data_len);
|
keyboard_buffer_len = (uint8_t)MIN(sizeof(keyboard_buffer), data_len);
|
||||||
memcpy(keyboard_buffer, data, keyboard_buffer_len);
|
memcpy(keyboard_buffer, data, keyboard_buffer_len);
|
||||||
keyboard_encode = encode;
|
keyboard_encode = encode;
|
||||||
}
|
}
|
||||||
@@ -166,7 +157,7 @@ void add_keyboard_buffer(const uint8_t *data, size_t data_len, bool encode) {
|
|||||||
void append_keyboard_buffer(const uint8_t *data, size_t data_len) {
|
void append_keyboard_buffer(const uint8_t *data, size_t data_len) {
|
||||||
if (keyboard_buffer_len + data_len < sizeof(keyboard_buffer)) {
|
if (keyboard_buffer_len + data_len < sizeof(keyboard_buffer)) {
|
||||||
memcpy(keyboard_buffer + keyboard_buffer_len, data, MIN(sizeof(keyboard_buffer) - keyboard_buffer_len, data_len));
|
memcpy(keyboard_buffer + keyboard_buffer_len, data, MIN(sizeof(keyboard_buffer) - keyboard_buffer_len, data_len));
|
||||||
keyboard_buffer_len += MIN(sizeof(keyboard_buffer) - keyboard_buffer_len, data_len);
|
keyboard_buffer_len += (uint8_t)MIN(sizeof(keyboard_buffer) - keyboard_buffer_len, data_len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -328,7 +319,7 @@ int driver_process_usb_nopacket_hid() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extern const uint8_t fido_aid[], u2f_aid[], oath_aid[];
|
extern const uint8_t fido_aid[], u2f_aid[], oath_aid[];
|
||||||
extern void apdu_thread(void), cbor_thread(void);
|
extern void *cbor_thread(void *);
|
||||||
|
|
||||||
int driver_process_usb_packet_hid(uint16_t read) {
|
int driver_process_usb_packet_hid(uint16_t read) {
|
||||||
int apdu_sent = 0;
|
int apdu_sent = 0;
|
||||||
|
|||||||
@@ -90,8 +90,12 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef CFG_TUSB_MEM_ALIGN
|
#ifndef CFG_TUSB_MEM_ALIGN
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#define CFG_TUSB_MEM_ALIGN __declspec(align(4))
|
||||||
|
#else
|
||||||
#define CFG_TUSB_MEM_ALIGN __attribute__((aligned(4)))
|
#define CFG_TUSB_MEM_ALIGN __attribute__((aligned(4)))
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
// DEVICE CONFIGURATION
|
// DEVICE CONFIGURATION
|
||||||
|
|||||||
@@ -37,13 +37,15 @@
|
|||||||
// Device specific functions
|
// Device specific functions
|
||||||
static uint32_t *timeout_counter = NULL;
|
static uint32_t *timeout_counter = NULL;
|
||||||
static uint8_t card_locked_itf = 0; // no locked
|
static uint8_t card_locked_itf = 0; // no locked
|
||||||
static void (*card_locked_func)(void) = NULL;
|
static void *(*card_locked_func)(void *) = NULL;
|
||||||
#ifndef ENABLE_EMULATION
|
#ifndef ENABLE_EMULATION
|
||||||
static mutex_t mutex;
|
static mutex_t mutex;
|
||||||
extern void usb_desc_setup();
|
extern void usb_desc_setup();
|
||||||
#endif
|
#endif
|
||||||
#if !defined(PICO_PLATFORM) && !defined(ENABLE_EMULATION) && !defined(ESP_PLATFORM)
|
#if !defined(PICO_PLATFORM) && !defined(ENABLE_EMULATION) && !defined(ESP_PLATFORM)
|
||||||
#include <pthread.h>
|
#ifdef _MSC_VER
|
||||||
|
#include "pthread_win32.h"
|
||||||
|
#endif
|
||||||
pthread_t hcore0, hcore1;
|
pthread_t hcore0, hcore1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -175,7 +177,7 @@ void card_init_core1() {
|
|||||||
|
|
||||||
uint16_t finished_data_size = 0;
|
uint16_t finished_data_size = 0;
|
||||||
|
|
||||||
void card_start(uint8_t itf, void (*func)(void)) {
|
void card_start(uint8_t itf, void *(*func)(void *)) {
|
||||||
timeout_start();
|
timeout_start();
|
||||||
if (card_locked_itf != itf || card_locked_func != func) {
|
if (card_locked_itf != itf || card_locked_func != func) {
|
||||||
if (card_locked_itf != ITF_TOTAL || card_locked_func != NULL) {
|
if (card_locked_itf != ITF_TOTAL || card_locked_func != NULL) {
|
||||||
|
|||||||
@@ -47,7 +47,7 @@
|
|||||||
#define EV_BUTTON_TIMEOUT 16
|
#define EV_BUTTON_TIMEOUT 16
|
||||||
#define EV_BUTTON_PRESSED 32
|
#define EV_BUTTON_PRESSED 32
|
||||||
|
|
||||||
static const uint8_t ITF_INVALID = 0xFF;
|
enum { ITF_INVALID = 0xFF };
|
||||||
|
|
||||||
#ifdef USB_ITF_HID
|
#ifdef USB_ITF_HID
|
||||||
extern uint8_t ITF_HID_CTAP, ITF_HID_KB;
|
extern uint8_t ITF_HID_CTAP, ITF_HID_KB;
|
||||||
@@ -77,7 +77,7 @@ extern void usb_task();
|
|||||||
extern queue_t usb_to_card_q;
|
extern queue_t usb_to_card_q;
|
||||||
extern queue_t card_to_usb_q;
|
extern queue_t card_to_usb_q;
|
||||||
|
|
||||||
extern void card_start(uint8_t, void (*func)(void));
|
extern void card_start(uint8_t, void *(*func)(void *));
|
||||||
extern void card_exit();
|
extern void card_exit();
|
||||||
extern int card_status(uint8_t itf);
|
extern int card_status(uint8_t itf);
|
||||||
extern void usb_init();
|
extern void usb_init();
|
||||||
|
|||||||
@@ -167,13 +167,13 @@ void usb_desc_setup() {
|
|||||||
#ifdef USB_ITF_HID
|
#ifdef USB_ITF_HID
|
||||||
if (ITF_HID != ITF_INVALID) {
|
if (ITF_HID != ITF_INVALID) {
|
||||||
TUSB_DESC_TOTAL_LEN += TUD_HID_INOUT_DESC_LEN;
|
TUSB_DESC_TOTAL_LEN += TUD_HID_INOUT_DESC_LEN;
|
||||||
const uint8_t desc[] = { 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) };
|
const uint8_t desc[] = { TUD_HID_INOUT_DESCRIPTOR(ITF_HID, ITF_HID + 5, HID_ITF_PROTOCOL_NONE, sizeof(desc_hid_report), EPNUM_HID, (uint8_t)TUSB_DIR_IN_MASK | EPNUM_HID, CFG_TUD_HID_EP_BUFSIZE, 10) };
|
||||||
memcpy(p, desc, sizeof(desc));
|
memcpy(p, desc, sizeof(desc));
|
||||||
p += sizeof(desc);
|
p += sizeof(desc);
|
||||||
}
|
}
|
||||||
if (ITF_KEYBOARD != ITF_INVALID) {
|
if (ITF_KEYBOARD != ITF_INVALID) {
|
||||||
TUSB_DESC_TOTAL_LEN += TUD_HID_DESC_LEN;
|
TUSB_DESC_TOTAL_LEN += TUD_HID_DESC_LEN;
|
||||||
const uint8_t desc_kb[] = { TUD_HID_DESCRIPTOR(ITF_KEYBOARD, ITF_KEYBOARD + 5, HID_ITF_PROTOCOL_NONE, sizeof(desc_hid_report_kb), TUSB_DIR_IN_MASK | EPNUM_HID_KB, 16, 5) };
|
const uint8_t desc_kb[] = { TUD_HID_DESCRIPTOR(ITF_KEYBOARD, ITF_KEYBOARD + 5, HID_ITF_PROTOCOL_NONE, sizeof(desc_hid_report_kb), (uint8_t)TUSB_DIR_IN_MASK | EPNUM_HID_KB, 16, 5) };
|
||||||
memcpy(p, desc_kb, sizeof(desc_kb));
|
memcpy(p, desc_kb, sizeof(desc_kb));
|
||||||
p += sizeof(desc_kb);
|
p += sizeof(desc_kb);
|
||||||
}
|
}
|
||||||
@@ -373,8 +373,8 @@ uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
|
|||||||
uint8_t buff_avail = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1;
|
uint8_t buff_avail = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1;
|
||||||
if (index >= 4) {
|
if (index >= 4) {
|
||||||
const char *product = phy_data.usb_product_present ? phy_data.usb_product : string_desc_arr[2];
|
const char *product = phy_data.usb_product_present ? phy_data.usb_product : string_desc_arr[2];
|
||||||
uint8_t len = MIN(strlen(product), buff_avail);
|
uint8_t len = (uint8_t)MIN(strlen(product), buff_avail);
|
||||||
for (int ix = 0; ix < len; chr_count++, ix++) {
|
for (size_t ix = 0; ix < len; chr_count++, ix++) {
|
||||||
_desc_str[1 + chr_count] = product[ix];
|
_desc_str[1 + chr_count] = product[ix];
|
||||||
}
|
}
|
||||||
buff_avail -= len;
|
buff_avail -= len;
|
||||||
@@ -383,7 +383,7 @@ uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
|
|||||||
buff_avail--;
|
buff_avail--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int ix = 0; ix < MIN(strlen(str), buff_avail); chr_count++, ix++) {
|
for (size_t ix = 0; ix < MIN(strlen(str), buff_avail); chr_count++, ix++) {
|
||||||
_desc_str[1 + chr_count] = str[ix];
|
_desc_str[1 + chr_count] = str[ix];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user