mirror of
https://github.com/polhenarejos/pico-keys-sdk
synced 2026-05-28 17:11:23 +02:00
Apply strict build.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
@@ -467,6 +467,64 @@ function(add_impl_library target)
|
|||||||
target_compile_definitions(${target} INTERFACE LIB_${TARGET_UPPER}=1)
|
target_compile_definitions(${target} INTERFACE LIB_${TARGET_UPPER}=1)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
# Apply strict warning flags to a caller-provided source list.
|
||||||
|
# Usage:
|
||||||
|
# pico_keys_apply_strict_flags(SOURCES ${SOURCES} FILTER_REGEX "/src/fido/")
|
||||||
|
function(pico_keys_apply_strict_flags)
|
||||||
|
set(options)
|
||||||
|
set(oneValueArgs FILTER_REGEX)
|
||||||
|
set(multiValueArgs SOURCES)
|
||||||
|
cmake_parse_arguments(PKAS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||||
|
|
||||||
|
if(NOT PKAS_SOURCES)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(PICO_KEYS_STRICT_FLAGS
|
||||||
|
-Wextra
|
||||||
|
-pipe
|
||||||
|
-funsigned-char
|
||||||
|
-fstrict-aliasing
|
||||||
|
-Wchar-subscripts
|
||||||
|
-Wundef
|
||||||
|
-Wshadow
|
||||||
|
-Wcast-align
|
||||||
|
-Wwrite-strings
|
||||||
|
-Wunused
|
||||||
|
-Wuninitialized
|
||||||
|
-Wpointer-arith
|
||||||
|
-Wredundant-decls
|
||||||
|
-Winline
|
||||||
|
-Wformat
|
||||||
|
-Wformat-security
|
||||||
|
-Wswitch-enum
|
||||||
|
-Winit-self
|
||||||
|
-Wmissing-include-dirs
|
||||||
|
-Wempty-body
|
||||||
|
-fdiagnostics-color=auto
|
||||||
|
-Wmissing-prototypes
|
||||||
|
-Wstrict-prototypes
|
||||||
|
-Wold-style-definition
|
||||||
|
-Wbad-function-cast
|
||||||
|
-Wnested-externs
|
||||||
|
-Wmissing-declarations
|
||||||
|
-Werror
|
||||||
|
)
|
||||||
|
|
||||||
|
if(NOT ENABLE_EMULATION)
|
||||||
|
list(APPEND PICO_KEYS_STRICT_FLAGS -D_FORTIFY_SOURCE=2)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
foreach(src IN LISTS PKAS_SOURCES)
|
||||||
|
if(PKAS_FILTER_REGEX)
|
||||||
|
if(NOT src MATCHES "${PKAS_FILTER_REGEX}")
|
||||||
|
continue()
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
set_property(SOURCE "${src}" APPEND PROPERTY COMPILE_OPTIONS ${PICO_KEYS_STRICT_FLAGS})
|
||||||
|
endforeach()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
if(USB_ITF_HID)
|
if(USB_ITF_HID)
|
||||||
list(APPEND PICO_KEYS_SOURCES
|
list(APPEND PICO_KEYS_SOURCES
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/usb/hid/hid.c
|
${CMAKE_CURRENT_LIST_DIR}/src/usb/hid/hid.c
|
||||||
|
|||||||
12
src/apdu.c
12
src/apdu.c
@@ -33,13 +33,15 @@ bool is_chaining = false;
|
|||||||
uint8_t chain_buf[2038];
|
uint8_t chain_buf[2038];
|
||||||
uint8_t *chain_ptr = NULL;
|
uint8_t *chain_ptr = NULL;
|
||||||
|
|
||||||
int process_apdu() {
|
int process_apdu(void) {
|
||||||
led_set_mode(MODE_PROCESSING);
|
led_set_mode(MODE_PROCESSING);
|
||||||
if (CLA(apdu) & 0x10) {
|
if (CLA(apdu) & 0x10) {
|
||||||
|
size_t chain_used = 0;
|
||||||
if (!is_chaining) {
|
if (!is_chaining) {
|
||||||
chain_ptr = chain_buf;
|
chain_ptr = chain_buf;
|
||||||
}
|
}
|
||||||
if (chain_ptr - chain_buf + apdu.nc >= sizeof(chain_buf)) {
|
chain_used = (size_t)(chain_ptr - chain_buf);
|
||||||
|
if (chain_used + apdu.nc >= sizeof(chain_buf)) {
|
||||||
return SW_CLA_NOT_SUPPORTED();
|
return SW_CLA_NOT_SUPPORTED();
|
||||||
}
|
}
|
||||||
memcpy(chain_ptr, apdu.data, apdu.nc);
|
memcpy(chain_ptr, apdu.data, apdu.nc);
|
||||||
@@ -222,7 +224,7 @@ done: ;
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void apdu_finish() {
|
void apdu_finish(void) {
|
||||||
put_uint16_t_be(apdu.sw, apdu.rdata + apdu.rlen);
|
put_uint16_t_be(apdu.sw, apdu.rdata + apdu.rlen);
|
||||||
// timeout_stop();
|
// timeout_stop();
|
||||||
#ifndef ENABLE_EMULATION
|
#ifndef ENABLE_EMULATION
|
||||||
@@ -233,7 +235,7 @@ void apdu_finish() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t apdu_next() {
|
uint16_t apdu_next(void) {
|
||||||
if (apdu.sw != 0) {
|
if (apdu.sw != 0) {
|
||||||
if (apdu.rlen <= apdu.ne) {
|
if (apdu.rlen <= apdu.ne) {
|
||||||
return apdu.rlen + 2;
|
return apdu.rlen + 2;
|
||||||
@@ -255,7 +257,7 @@ uint16_t apdu_next() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int bulk_cmd(int (*cmd)()) {
|
int bulk_cmd(int (*cmd)(void)) {
|
||||||
uint8_t *p = apdu.data;
|
uint8_t *p = apdu.data;
|
||||||
uint8_t *rapdu = apdu.rdata;
|
uint8_t *rapdu = apdu.rdata;
|
||||||
uint16_t rapdu_size = 0;
|
uint16_t rapdu_size = 0;
|
||||||
|
|||||||
14
src/apdu.h
14
src/apdu.h
@@ -29,9 +29,9 @@
|
|||||||
|
|
||||||
typedef struct app {
|
typedef struct app {
|
||||||
const uint8_t *aid;
|
const uint8_t *aid;
|
||||||
int (*process_apdu)();
|
int (*process_apdu)(void);
|
||||||
int (*select_aid)(struct app *, uint8_t);
|
int (*select_aid)(struct app *, uint8_t);
|
||||||
int (*unload)();
|
int (*unload)(void);
|
||||||
} app_t;
|
} app_t;
|
||||||
|
|
||||||
extern bool app_exists(const uint8_t *aid, size_t aid_len);
|
extern bool app_exists(const uint8_t *aid, size_t aid_len);
|
||||||
@@ -40,7 +40,7 @@ extern int select_app(const uint8_t *aid, size_t aid_len);
|
|||||||
|
|
||||||
typedef struct cmd {
|
typedef struct cmd {
|
||||||
uint8_t ins;
|
uint8_t ins;
|
||||||
int (*cmd_handler)();
|
int (*cmd_handler)(void);
|
||||||
} cmd_t;
|
} cmd_t;
|
||||||
|
|
||||||
extern uint8_t num_apps;
|
extern uint8_t num_apps;
|
||||||
@@ -69,11 +69,11 @@ PACK(struct apdu {
|
|||||||
extern struct apdu apdu;
|
extern struct apdu apdu;
|
||||||
|
|
||||||
extern uint16_t set_res_sw(uint8_t sw1, uint8_t sw2);
|
extern uint16_t set_res_sw(uint8_t sw1, uint8_t sw2);
|
||||||
extern int process_apdu();
|
extern int process_apdu(void);
|
||||||
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(void);
|
||||||
extern uint16_t apdu_next();
|
extern uint16_t apdu_next(void);
|
||||||
extern void *apdu_thread(void *);
|
extern void *apdu_thread(void *);
|
||||||
extern int bulk_cmd(int (*cmd)());
|
extern int bulk_cmd(int (*cmd)(void));
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ extern int gettimeofday(struct timeval *tp, struct timezone *tzp);
|
|||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static inline uint32_t board_millis() {
|
static inline uint32_t board_millis(void) {
|
||||||
struct timeval start;
|
struct timeval start;
|
||||||
gettimeofday(&start, NULL);
|
gettimeofday(&start, NULL);
|
||||||
return start.tv_sec * 1000 + start.tv_usec / 1000;
|
return start.tv_sec * 1000 + start.tv_usec / 1000;
|
||||||
|
|||||||
28
src/eac.c
28
src/eac.c
@@ -37,16 +37,16 @@ static uint8_t sm_iv[16];
|
|||||||
uint16_t sm_session_pin_len = 0;
|
uint16_t sm_session_pin_len = 0;
|
||||||
uint8_t sm_session_pin[16];
|
uint8_t sm_session_pin[16];
|
||||||
|
|
||||||
bool is_secured_apdu() {
|
bool is_secured_apdu(void) {
|
||||||
return CLA(apdu) & 0xC;
|
return CLA(apdu) & 0xC;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sm_derive_key(const uint8_t *input,
|
static void sm_derive_key(const uint8_t *input,
|
||||||
size_t input_len,
|
size_t input_len,
|
||||||
uint8_t counter,
|
uint8_t counter,
|
||||||
const uint8_t *nonce,
|
const uint8_t *nonce,
|
||||||
size_t nonce_len,
|
size_t nonce_len,
|
||||||
uint8_t *out) {
|
uint8_t *out) {
|
||||||
uint8_t *b = (uint8_t *) calloc(1, input_len + nonce_len + 4);
|
uint8_t *b = (uint8_t *) calloc(1, input_len + nonce_len + 4);
|
||||||
if (input) {
|
if (input) {
|
||||||
memcpy(b, input, input_len);
|
memcpy(b, input, input_len);
|
||||||
@@ -82,11 +82,11 @@ void sm_set_protocol(MSE_protocol proto) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MSE_protocol sm_get_protocol() {
|
MSE_protocol sm_get_protocol(void) {
|
||||||
return sm_protocol;
|
return sm_protocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *sm_get_nonce() {
|
uint8_t *sm_get_nonce(void) {
|
||||||
return sm_nonce;
|
return sm_nonce;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,7 +99,7 @@ int sm_sign(uint8_t *in, size_t in_len, uint8_t *out) {
|
|||||||
out);
|
out);
|
||||||
}
|
}
|
||||||
|
|
||||||
int sm_unwrap() {
|
int sm_unwrap(void) {
|
||||||
uint8_t sm_indicator = (CLA(apdu) >> 2) & 0x3;
|
uint8_t sm_indicator = (CLA(apdu) >> 2) & 0x3;
|
||||||
if (sm_indicator == 0) {
|
if (sm_indicator == 0) {
|
||||||
return PICOKEY_OK;
|
return PICOKEY_OK;
|
||||||
@@ -144,7 +144,7 @@ int sm_unwrap() {
|
|||||||
return PICOKEY_OK;
|
return PICOKEY_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sm_wrap() {
|
int sm_wrap(void) {
|
||||||
uint8_t sm_indicator = (CLA(apdu) >> 2) & 0x3;
|
uint8_t sm_indicator = (CLA(apdu) >> 2) & 0x3;
|
||||||
if (sm_indicator == 0) {
|
if (sm_indicator == 0) {
|
||||||
return PICOKEY_OK;
|
return PICOKEY_OK;
|
||||||
@@ -210,7 +210,7 @@ int sm_wrap() {
|
|||||||
return PICOKEY_OK;
|
return PICOKEY_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t sm_get_le() {
|
uint16_t sm_get_le(void) {
|
||||||
uint16_t tag = 0x0;
|
uint16_t tag = 0x0;
|
||||||
uint8_t *tag_data = NULL, *p = NULL;
|
uint8_t *tag_data = NULL, *p = NULL;
|
||||||
uint16_t tag_len = 0;
|
uint16_t tag_len = 0;
|
||||||
@@ -228,7 +228,7 @@ uint16_t sm_get_le() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sm_update_iv() {
|
void sm_update_iv(void) {
|
||||||
uint8_t tmp_iv[16], sc_counter[16];
|
uint8_t tmp_iv[16], sc_counter[16];
|
||||||
memset(tmp_iv, 0, sizeof(tmp_iv)); //IV is always 0 for encryption of IV based on counter
|
memset(tmp_iv, 0, sizeof(tmp_iv)); //IV is always 0 for encryption of IV based on counter
|
||||||
mbedtls_mpi_write_binary(&sm_mSSC, sc_counter, sizeof(sc_counter));
|
mbedtls_mpi_write_binary(&sm_mSSC, sc_counter, sizeof(sc_counter));
|
||||||
@@ -236,7 +236,7 @@ void sm_update_iv() {
|
|||||||
memcpy(sm_iv, sc_counter, sizeof(sc_counter));
|
memcpy(sm_iv, sc_counter, sizeof(sc_counter));
|
||||||
}
|
}
|
||||||
|
|
||||||
int sm_verify() {
|
int sm_verify(void) {
|
||||||
uint8_t input[USB_BUFFER_SIZE];
|
uint8_t input[USB_BUFFER_SIZE];
|
||||||
memset(input, 0, sizeof(input));
|
memset(input, 0, sizeof(input));
|
||||||
uint16_t input_len = 0;
|
uint16_t input_len = 0;
|
||||||
|
|||||||
16
src/eac.h
16
src/eac.h
@@ -28,16 +28,16 @@ typedef enum MSE_protocol {
|
|||||||
|
|
||||||
extern void sm_derive_all_keys(const uint8_t *input, size_t input_len);
|
extern void sm_derive_all_keys(const uint8_t *input, size_t input_len);
|
||||||
extern void sm_set_protocol(MSE_protocol proto);
|
extern void sm_set_protocol(MSE_protocol proto);
|
||||||
extern MSE_protocol sm_get_protocol();
|
extern MSE_protocol sm_get_protocol(void);
|
||||||
extern uint8_t *sm_get_nonce();
|
extern uint8_t *sm_get_nonce(void);
|
||||||
extern int sm_sign(uint8_t *in, size_t in_len, uint8_t *out);
|
extern int sm_sign(uint8_t *in, size_t in_len, uint8_t *out);
|
||||||
int sm_verify();
|
int sm_verify(void);
|
||||||
void sm_update_iv();
|
void sm_update_iv(void);
|
||||||
uint16_t sm_get_le();
|
uint16_t sm_get_le(void);
|
||||||
extern int sm_unwrap();
|
extern int sm_unwrap(void);
|
||||||
uint16_t sm_remove_padding(const uint8_t *data, uint16_t data_len);
|
uint16_t sm_remove_padding(const uint8_t *data, uint16_t data_len);
|
||||||
extern int sm_wrap();
|
extern int sm_wrap(void);
|
||||||
extern bool is_secured_apdu();
|
extern bool is_secured_apdu(void);
|
||||||
extern uint8_t sm_session_pin[16];
|
extern uint8_t sm_session_pin[16];
|
||||||
extern uint16_t sm_session_pin_len;
|
extern uint16_t sm_session_pin_len;
|
||||||
|
|
||||||
|
|||||||
@@ -26,15 +26,6 @@ extern const uintptr_t end_data_pool;
|
|||||||
extern const uintptr_t start_data_pool;
|
extern const uintptr_t start_data_pool;
|
||||||
extern const uintptr_t end_rom_pool;
|
extern const uintptr_t end_rom_pool;
|
||||||
extern const uintptr_t start_rom_pool;
|
extern const uintptr_t start_rom_pool;
|
||||||
extern int flash_write_data_to_file(file_t *file, const uint8_t *data, uint16_t len);
|
|
||||||
extern int flash_program_block(uintptr_t addr, const uint8_t *data, size_t len);
|
|
||||||
extern uintptr_t flash_read_uintptr(uintptr_t addr);
|
|
||||||
extern uint16_t flash_read_uint16(uintptr_t addr);
|
|
||||||
extern uint8_t flash_read_uint8(uintptr_t addr);
|
|
||||||
extern uint8_t *flash_read(uintptr_t addr);
|
|
||||||
extern int flash_clear_file(file_t *ef);
|
|
||||||
extern void low_flash_available(void);
|
|
||||||
|
|
||||||
#ifndef ENABLE_EMULATION
|
#ifndef ENABLE_EMULATION
|
||||||
file_t sef_phy = {.fid = EF_PHY, .parent = 5, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH | FILE_PERSISTENT, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = {0xff}};
|
file_t sef_phy = {.fid = EF_PHY, .parent = 5, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH | FILE_PERSISTENT, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = {0xff}};
|
||||||
file_t *ef_phy = &sef_phy;
|
file_t *ef_phy = &sef_phy;
|
||||||
@@ -55,7 +46,8 @@ void process_fci(const file_t *pe, int fmd) {
|
|||||||
res_APDU[res_APDU_size++] = 2;
|
res_APDU[res_APDU_size++] = 2;
|
||||||
if (pe->data) {
|
if (pe->data) {
|
||||||
if ((pe->type & FILE_DATA_FUNC) == FILE_DATA_FUNC) {
|
if ((pe->type & FILE_DATA_FUNC) == FILE_DATA_FUNC) {
|
||||||
uint16_t len = (uint16_t)((int (*)(const file_t *, int))(pe->data))(pe, 0);
|
int (*data_fn)(const file_t *, int) = (int (*)(const file_t *, int))(uintptr_t)pe->data;
|
||||||
|
uint16_t len = (uint16_t)data_fn(pe, 0);
|
||||||
res_APDU_size += put_uint16_t_be(len, res_APDU + res_APDU_size);
|
res_APDU_size += put_uint16_t_be(len, res_APDU + res_APDU_size);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -115,7 +107,7 @@ file_t dynamic_file[MAX_DYNAMIC_FILES];
|
|||||||
|
|
||||||
bool card_terminated = false;
|
bool card_terminated = false;
|
||||||
|
|
||||||
bool is_parent(const file_t *child, const file_t *parent) {
|
static bool is_parent(const file_t *child, const file_t *parent) {
|
||||||
if (child == parent) {
|
if (child == parent) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -166,7 +158,7 @@ file_t *search_file(const uint16_t fid) {
|
|||||||
return search_dynamic_file(fid);
|
return search_dynamic_file(fid);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t make_path_buf(const file_t *pe, uint8_t *buf, uint8_t buflen, const file_t *top) {
|
static uint8_t make_path_buf(const file_t *pe, uint8_t *buf, uint8_t buflen, const file_t *top) {
|
||||||
if (!buflen) {
|
if (!buflen) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -177,7 +169,7 @@ uint8_t make_path_buf(const file_t *pe, uint8_t *buf, uint8_t buflen, const file
|
|||||||
return make_path_buf(&file_entries[pe->parent], buf + 2, buflen - 2, top) + 2;
|
return make_path_buf(&file_entries[pe->parent], buf + 2, buflen - 2, top) + 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t make_path(const file_t *pe, const file_t *top, uint8_t *path) {
|
static uint8_t make_path(const file_t *pe, const file_t *top, uint8_t *path) {
|
||||||
uint8_t buf[MAX_DEPTH * 2], *p = path;
|
uint8_t buf[MAX_DEPTH * 2], *p = path;
|
||||||
put_uint16_t_be(pe->fid, buf);
|
put_uint16_t_be(pe->fid, buf);
|
||||||
uint8_t depth = make_path_buf(&file_entries[pe->parent], buf + 2, sizeof(buf) - 2, top) + 2;
|
uint8_t depth = make_path_buf(&file_entries[pe->parent], buf + 2, sizeof(buf) - 2, top) + 2;
|
||||||
@@ -243,7 +235,7 @@ void initialize_flash(bool hard) {
|
|||||||
|
|
||||||
extern uintptr_t last_base;
|
extern uintptr_t last_base;
|
||||||
extern uint32_t num_files;
|
extern uint32_t num_files;
|
||||||
void scan_region(bool persistent)
|
static void scan_region(bool persistent)
|
||||||
{
|
{
|
||||||
uintptr_t endp = end_data_pool, startp = start_data_pool;
|
uintptr_t endp = end_data_pool, startp = start_data_pool;
|
||||||
if (persistent) {
|
if (persistent) {
|
||||||
@@ -279,9 +271,10 @@ void scan_region(bool persistent)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void scan_flash() {
|
void scan_flash(void) {
|
||||||
initialize_flash(false); //soft initialization
|
initialize_flash(false); //soft initialization
|
||||||
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)));
|
uint32_t r1 = (uint32_t)flash_read_uintptr(end_rom_pool);
|
||||||
|
uint32_t r2 = (uint32_t)flash_read_uintptr(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)];
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ extern file_t *search_by_name(uint8_t *name, uint16_t namelen);
|
|||||||
extern file_t *search_by_path(const uint8_t *pe_path, uint8_t pathlen, const file_t *parent);
|
extern file_t *search_by_path(const uint8_t *pe_path, uint8_t pathlen, const file_t *parent);
|
||||||
extern bool authenticate_action(const file_t *ef, uint8_t op);
|
extern bool authenticate_action(const file_t *ef, uint8_t op);
|
||||||
extern void process_fci(const file_t *pe, int fmd);
|
extern void process_fci(const file_t *pe, int fmd);
|
||||||
extern void scan_flash();
|
extern void scan_flash(void);
|
||||||
extern void initialize_flash(bool);
|
extern void initialize_flash(bool);
|
||||||
|
|
||||||
extern file_t file_entries[];
|
extern file_t file_entries[];
|
||||||
@@ -142,11 +142,26 @@ extern int meta_delete(uint16_t fid);
|
|||||||
extern int meta_add(uint16_t fid, const uint8_t *data, uint16_t len);
|
extern int meta_add(uint16_t fid, const uint8_t *data, uint16_t len);
|
||||||
extern int delete_file(file_t *ef);
|
extern int delete_file(file_t *ef);
|
||||||
|
|
||||||
extern uint32_t flash_free_space();
|
extern uint32_t flash_free_space(void);
|
||||||
extern uint32_t flash_used_space();
|
extern uint32_t flash_used_space(void);
|
||||||
extern uint32_t flash_total_space();
|
extern uint32_t flash_total_space(void);
|
||||||
extern uint32_t flash_num_files();
|
extern uint32_t flash_num_files(void);
|
||||||
extern uint32_t flash_size();
|
extern uint32_t flash_size(void);
|
||||||
|
|
||||||
|
extern void flash_set_bounds(uintptr_t start, uintptr_t end);
|
||||||
|
extern int flash_write_data_to_file(file_t *file, const uint8_t *data, uint16_t len);
|
||||||
|
extern int flash_program_block(uintptr_t addr, const uint8_t *data, size_t len);
|
||||||
|
extern int flash_program_halfword(uintptr_t addr, uint16_t data);
|
||||||
|
extern int flash_program_word(uintptr_t addr, uint32_t data);
|
||||||
|
extern int flash_program_uintptr(uintptr_t addr, uintptr_t data);
|
||||||
|
extern uintptr_t flash_read_uintptr(uintptr_t addr);
|
||||||
|
extern uint16_t flash_read_uint16(uintptr_t addr);
|
||||||
|
extern uint8_t flash_read_uint8(uintptr_t addr);
|
||||||
|
extern uint8_t *flash_read(uintptr_t addr);
|
||||||
|
extern int flash_erase_page(uintptr_t addr, size_t page_size);
|
||||||
|
extern bool flash_check_blank(const uint8_t *p_start, size_t size);
|
||||||
|
extern void do_flash(void);
|
||||||
|
extern void low_flash_init(void);
|
||||||
|
|
||||||
#ifndef ENABLE_EMULATION
|
#ifndef ENABLE_EMULATION
|
||||||
extern file_t *ef_phy;
|
extern file_t *ef_phy;
|
||||||
|
|||||||
@@ -54,15 +54,6 @@ uint32_t FLASH_SIZE_BYTES = (2 * 1024 * 1024);
|
|||||||
//To avoid possible future allocations, data region starts at the end of flash and goes upwards to the center region
|
//To avoid possible future allocations, data region starts at the end of flash and goes upwards to the center region
|
||||||
uintptr_t end_flash, end_rom_pool, start_rom_pool, end_data_pool, start_data_pool;
|
uintptr_t end_flash, end_rom_pool, start_rom_pool, end_data_pool, start_data_pool;
|
||||||
|
|
||||||
extern int flash_program_block(uintptr_t addr, const uint8_t *data, size_t len);
|
|
||||||
extern int flash_program_halfword(uintptr_t addr, uint16_t data);
|
|
||||||
extern int flash_program_uintptr(uintptr_t, uintptr_t);
|
|
||||||
extern uintptr_t flash_read_uintptr(uintptr_t addr);
|
|
||||||
extern uint16_t flash_read_uint16(uintptr_t addr);
|
|
||||||
extern uint8_t *flash_read(uintptr_t addr);
|
|
||||||
|
|
||||||
extern void low_flash_available(void);
|
|
||||||
|
|
||||||
uintptr_t last_base;
|
uintptr_t last_base;
|
||||||
uint32_t num_files = 0;
|
uint32_t num_files = 0;
|
||||||
|
|
||||||
@@ -76,7 +67,7 @@ void flash_set_bounds(uintptr_t start, uintptr_t end) {
|
|||||||
last_base = end_data_pool;
|
last_base = end_data_pool;
|
||||||
}
|
}
|
||||||
|
|
||||||
uintptr_t allocate_free_addr(uint16_t size, bool persistent) {
|
static uintptr_t allocate_free_addr(uint16_t size, bool persistent) {
|
||||||
if (size > FLASH_SECTOR_SIZE) {
|
if (size > FLASH_SECTOR_SIZE) {
|
||||||
return 0x0; //ERROR
|
return 0x0; //ERROR
|
||||||
}
|
}
|
||||||
@@ -144,7 +135,7 @@ int flash_clear_file(file_t *file) {
|
|||||||
return PICOKEY_OK;
|
return PICOKEY_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int flash_write_data_to_file_offset(file_t *file, const uint8_t *data, uint16_t len, uint16_t offset) {
|
static int flash_write_data_to_file_offset(file_t *file, const uint8_t *data, uint16_t len, uint16_t offset) {
|
||||||
if (!file) {
|
if (!file) {
|
||||||
return PICOKEY_ERR_NULL_PARAM;
|
return PICOKEY_ERR_NULL_PARAM;
|
||||||
}
|
}
|
||||||
@@ -198,22 +189,22 @@ int flash_write_data_to_file(file_t *file, const uint8_t *data, uint16_t len) {
|
|||||||
return flash_write_data_to_file_offset(file, data, len, 0);
|
return flash_write_data_to_file_offset(file, data, len, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t flash_free_space() {
|
uint32_t flash_free_space(void) {
|
||||||
return (uint32_t)(last_base - start_data_pool);
|
return (uint32_t)(last_base - start_data_pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t flash_used_space() {
|
uint32_t flash_used_space(void) {
|
||||||
return (uint32_t)(end_data_pool - last_base);
|
return (uint32_t)(end_data_pool - last_base);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t flash_total_space() {
|
uint32_t flash_total_space(void) {
|
||||||
return (uint32_t)(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(void) {
|
||||||
return num_files;
|
return num_files;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t flash_size() {
|
uint32_t flash_size(void) {
|
||||||
return FLASH_SIZE_BYTES;
|
return FLASH_SIZE_BYTES;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,8 +76,6 @@ extern uint32_t FLASH_SIZE_BYTES;
|
|||||||
|
|
||||||
#define TOTAL_FLASH_PAGES 6
|
#define TOTAL_FLASH_PAGES 6
|
||||||
|
|
||||||
extern void flash_set_bounds(uintptr_t start, uintptr_t end);
|
|
||||||
|
|
||||||
extern const uintptr_t start_data_pool;
|
extern const uintptr_t start_data_pool;
|
||||||
extern const uintptr_t end_rom_pool;
|
extern const uintptr_t end_rom_pool;
|
||||||
|
|
||||||
@@ -105,7 +103,7 @@ bool flash_available = false;
|
|||||||
|
|
||||||
|
|
||||||
//this function has to be called from the core 0
|
//this function has to be called from the core 0
|
||||||
void do_flash() {
|
void do_flash(void) {
|
||||||
if (mutex_try_enter(&mtx_flash, NULL) == true) {
|
if (mutex_try_enter(&mtx_flash, NULL) == true) {
|
||||||
if (locked_out == true && flash_available == true && ready_pages > 0) {
|
if (locked_out == true && flash_available == true && ready_pages > 0) {
|
||||||
//printf(" DO_FLASH AVAILABLE\n");
|
//printf(" DO_FLASH AVAILABLE\n");
|
||||||
@@ -181,10 +179,10 @@ void do_flash() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef PICO_RP2040
|
#ifdef PICO_RP2040
|
||||||
void phymarker_write();
|
void phymarker_write(void);
|
||||||
#endif
|
#endif
|
||||||
//this function has to be called from the core 0
|
//this function has to be called from the core 0
|
||||||
void low_flash_init() {
|
void low_flash_init(void) {
|
||||||
#ifdef PICO_RP2040
|
#ifdef PICO_RP2040
|
||||||
phymarker_write();
|
phymarker_write();
|
||||||
#endif
|
#endif
|
||||||
@@ -206,21 +204,21 @@ void low_flash_init() {
|
|||||||
|
|
||||||
FLASH_SIZE_BYTES = (1 << rxbuf[3]);
|
FLASH_SIZE_BYTES = (1 << rxbuf[3]);
|
||||||
#ifdef PICO_RP2350
|
#ifdef PICO_RP2350
|
||||||
__attribute__((aligned(4))) uint8_t workarea[4 * 1024];
|
__attribute__((aligned(4))) uint32_t workarea[1024];
|
||||||
int rc = rom_load_partition_table(workarea, sizeof(workarea), false);
|
int rc = rom_load_partition_table((uint8_t *)workarea, sizeof(workarea), false);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
reset_usb_boot(0, 0);
|
reset_usb_boot(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t boot_partition = 1;
|
uint8_t boot_partition = 1;
|
||||||
rc = rom_get_partition_table_info((uint32_t*)workarea, 0x8, PT_INFO_PARTITION_LOCATION_AND_FLAGS | PT_INFO_SINGLE_PARTITION | (boot_partition << 24));
|
rc = rom_get_partition_table_info(workarea, 0x8, PT_INFO_PARTITION_LOCATION_AND_FLAGS | PT_INFO_SINGLE_PARTITION | (boot_partition << 24));
|
||||||
|
|
||||||
if (rc != 3) {
|
if (rc != 3) {
|
||||||
data_start_addr = (FLASH_SIZE_BYTES >> 1);
|
data_start_addr = (FLASH_SIZE_BYTES >> 1);
|
||||||
data_end_addr = FLASH_SIZE_BYTES;
|
data_end_addr = FLASH_SIZE_BYTES;
|
||||||
} else {
|
} else {
|
||||||
uint16_t first_sector_number = (((uint32_t*)workarea)[1] & PICOBIN_PARTITION_LOCATION_FIRST_SECTOR_BITS) >> PICOBIN_PARTITION_LOCATION_FIRST_SECTOR_LSB;
|
uint16_t first_sector_number = (workarea[1] & PICOBIN_PARTITION_LOCATION_FIRST_SECTOR_BITS) >> PICOBIN_PARTITION_LOCATION_FIRST_SECTOR_LSB;
|
||||||
uint16_t last_sector_number = (((uint32_t*)workarea)[1] & PICOBIN_PARTITION_LOCATION_LAST_SECTOR_BITS) >> PICOBIN_PARTITION_LOCATION_LAST_SECTOR_LSB;
|
uint16_t last_sector_number = (workarea[1] & PICOBIN_PARTITION_LOCATION_LAST_SECTOR_BITS) >> PICOBIN_PARTITION_LOCATION_LAST_SECTOR_LSB;
|
||||||
data_start_addr = first_sector_number * FLASH_SECTOR_SIZE;
|
data_start_addr = first_sector_number * FLASH_SECTOR_SIZE;
|
||||||
data_end_addr = (last_sector_number + 1) * FLASH_SECTOR_SIZE;
|
data_end_addr = (last_sector_number + 1) * FLASH_SECTOR_SIZE;
|
||||||
if (data_end_addr > FLASH_SIZE_BYTES) {
|
if (data_end_addr > FLASH_SIZE_BYTES) {
|
||||||
@@ -259,7 +257,7 @@ void low_flash_available(void) {
|
|||||||
mutex_exit(&mtx_flash);
|
mutex_exit(&mtx_flash);
|
||||||
}
|
}
|
||||||
|
|
||||||
page_flash_t *find_free_page(uintptr_t addr) {
|
static page_flash_t *find_free_page(uintptr_t addr) {
|
||||||
uintptr_t addr_alg = addr & -FLASH_SECTOR_SIZE;
|
uintptr_t addr_alg = addr & -FLASH_SECTOR_SIZE;
|
||||||
page_flash_t *p = NULL;
|
page_flash_t *p = NULL;
|
||||||
for (int r = 0; r < TOTAL_FLASH_PAGES; r++) {
|
for (int r = 0; r < TOTAL_FLASH_PAGES; r++) {
|
||||||
@@ -406,7 +404,7 @@ uintptr_t __phymarker_start = (uintptr_t)0x10100000;
|
|||||||
|
|
||||||
const uint64_t PHYSICAL_MARKER_MAGIC = 0x5049434F4B455953ULL; // "PICOKEYS"
|
const uint64_t PHYSICAL_MARKER_MAGIC = 0x5049434F4B455953ULL; // "PICOKEYS"
|
||||||
|
|
||||||
void phymarker_write() {
|
void phymarker_write(void) {
|
||||||
const uint64_t magic = *(uint64_t *)__phymarker_start;
|
const uint64_t magic = *(uint64_t *)__phymarker_start;
|
||||||
if (magic == PHYSICAL_MARKER_MAGIC) {
|
if (magic == PHYSICAL_MARKER_MAGIC) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -260,6 +260,7 @@ typedef esp_err_t otp_ret_t;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool otp_is_secure_boot_enabled(uint8_t *bootkey) {
|
bool otp_is_secure_boot_enabled(uint8_t *bootkey) {
|
||||||
|
(void)bootkey;
|
||||||
#ifdef PICO_RP2350
|
#ifdef PICO_RP2350
|
||||||
const uint8_t *crit1 = otp_buffer(OTP_DATA_CRIT1_ROW);
|
const uint8_t *crit1 = otp_buffer(OTP_DATA_CRIT1_ROW);
|
||||||
if ((crit1[0] & (1 << OTP_DATA_CRIT1_SECURE_BOOT_ENABLE_LSB)) == 0) {
|
if ((crit1[0] & (1 << OTP_DATA_CRIT1_SECURE_BOOT_ENABLE_LSB)) == 0) {
|
||||||
@@ -511,7 +512,7 @@ static otp_ret_t otp_migrate_key(uint16_t new_row, uint16_t old_row, uint16_t le
|
|||||||
return BOOTROM_ERROR_INVALID_STATE;
|
return BOOTROM_ERROR_INVALID_STATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void otp_migrate_chaff() {
|
static void otp_migrate_chaff(void) {
|
||||||
otp_migrate_key(OTP_MKEK_ROW, OTP_OLD_MKEK_ROW, 32);
|
otp_migrate_key(OTP_MKEK_ROW, OTP_OLD_MKEK_ROW, 32);
|
||||||
otp_migrate_key(OTP_DEVK_ROW, OTP_OLD_DEVK_ROW, 32);
|
otp_migrate_key(OTP_DEVK_ROW, OTP_OLD_DEVK_ROW, 32);
|
||||||
otp_lock_page(OTP_MKEK_ROW >> 6);
|
otp_lock_page(OTP_MKEK_ROW >> 6);
|
||||||
@@ -564,7 +565,7 @@ void init_otp_files(void) {
|
|||||||
}
|
}
|
||||||
OTP_READ(OTP_KEY_2, otp_key_2);
|
OTP_READ(OTP_KEY_2, otp_key_2);
|
||||||
|
|
||||||
for (int i = 0; i < sizeof(write_otp)/sizeof(uint16_t); i++) {
|
for (size_t i = 0; i < sizeof(write_otp) / sizeof(write_otp[0]); i++) {
|
||||||
if (write_otp[i] != 0xFFFF) {
|
if (write_otp[i] != 0xFFFF) {
|
||||||
#if defined(PICO_RP2350)
|
#if defined(PICO_RP2350)
|
||||||
otp_lock_page(write_otp[i] >> 6);
|
otp_lock_page(write_otp[i] >> 6);
|
||||||
|
|||||||
@@ -165,12 +165,12 @@ int phy_unserialize_data(const uint8_t *data, uint16_t len, phy_data_t *phy) {
|
|||||||
return PICOKEY_OK;
|
return PICOKEY_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int phy_init() {
|
int phy_init(void) {
|
||||||
memset(&phy_data, 0, sizeof(phy_data_t));
|
memset(&phy_data, 0, sizeof(phy_data_t));
|
||||||
return phy_load();
|
return phy_load();
|
||||||
}
|
}
|
||||||
|
|
||||||
int phy_save() {
|
int phy_save(void) {
|
||||||
uint8_t tmp[PHY_MAX_SIZE] = {0};
|
uint8_t tmp[PHY_MAX_SIZE] = {0};
|
||||||
uint16_t tmp_len = 0;
|
uint16_t tmp_len = 0;
|
||||||
int ret = phy_serialize_data(&phy_data, tmp, &tmp_len);
|
int ret = phy_serialize_data(&phy_data, tmp, &tmp_len);
|
||||||
@@ -182,7 +182,7 @@ int phy_save() {
|
|||||||
return PICOKEY_OK;
|
return PICOKEY_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int phy_load() {
|
int phy_load(void) {
|
||||||
if (file_has_data(ef_phy)) {
|
if (file_has_data(ef_phy)) {
|
||||||
return phy_unserialize_data(file_get_data(ef_phy), file_get_size(ef_phy), &phy_data);
|
return phy_unserialize_data(file_get_data(ef_phy), file_get_size(ef_phy), &phy_data);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,9 +104,9 @@ typedef struct phy_data {
|
|||||||
#ifndef ENABLE_EMULATION
|
#ifndef ENABLE_EMULATION
|
||||||
extern int phy_serialize_data(const phy_data_t *phy, uint8_t *data, uint16_t *len);
|
extern int phy_serialize_data(const phy_data_t *phy, uint8_t *data, uint16_t *len);
|
||||||
extern int phy_unserialize_data(const uint8_t *data, uint16_t len, phy_data_t *phy);
|
extern int phy_unserialize_data(const uint8_t *data, uint16_t len, phy_data_t *phy);
|
||||||
extern int phy_init();
|
extern int phy_init(void);
|
||||||
extern int phy_save();
|
extern int phy_save(void);
|
||||||
extern int phy_load();
|
extern int phy_load(void);
|
||||||
extern phy_data_t phy_data;
|
extern phy_data_t phy_data;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -35,11 +35,11 @@ void led_set_mode(uint32_t mode) {
|
|||||||
led_mode = mode;
|
led_mode = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t led_get_mode() {
|
uint32_t led_get_mode(void) {
|
||||||
return led_mode;
|
return led_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void led_blinking_task() {
|
void led_blinking_task(void) {
|
||||||
#if defined(PICO_PLATFORM) || defined(ESP_PLATFORM)
|
#if defined(PICO_PLATFORM) || defined(ESP_PLATFORM)
|
||||||
static uint32_t start_ms = 0;
|
static uint32_t start_ms = 0;
|
||||||
static uint32_t stop_ms = 0;
|
static uint32_t stop_ms = 0;
|
||||||
@@ -81,7 +81,7 @@ void led_blinking_task() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void led_off_all() {
|
void led_off_all(void) {
|
||||||
#if defined(PICO_PLATFORM) || defined(ESP_PLATFORM)
|
#if defined(PICO_PLATFORM) || defined(ESP_PLATFORM)
|
||||||
led_driver->set_color(LED_COLOR_OFF, 0, 0);
|
led_driver->set_color(LED_COLOR_OFF, 0, 0);
|
||||||
#endif
|
#endif
|
||||||
@@ -93,11 +93,11 @@ extern led_driver_t led_driver_ws2812;
|
|||||||
extern led_driver_t led_driver_neopixel;
|
extern led_driver_t led_driver_neopixel;
|
||||||
extern led_driver_t led_driver_pimoroni;
|
extern led_driver_t led_driver_pimoroni;
|
||||||
|
|
||||||
void led_driver_init_dummy() {
|
static void led_driver_init_dummy(void) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
void led_driver_color_dummy(uint8_t color, uint32_t led_brightness, float progress) {
|
static void led_driver_color_dummy(uint8_t color, uint32_t led_brightness, float progress) {
|
||||||
(void)color;
|
(void)color;
|
||||||
(void)led_brightness;
|
(void)led_brightness;
|
||||||
(void)progress;
|
(void)progress;
|
||||||
@@ -109,7 +109,7 @@ led_driver_t led_driver_dummy = {
|
|||||||
.set_color = led_driver_color_dummy,
|
.set_color = led_driver_color_dummy,
|
||||||
};
|
};
|
||||||
|
|
||||||
void led_init() {
|
void led_init(void) {
|
||||||
led_driver = &led_driver_dummy;
|
led_driver = &led_driver_dummy;
|
||||||
#if defined(PICO_PLATFORM) || defined(ESP_PLATFORM)
|
#if defined(PICO_PLATFORM) || defined(ESP_PLATFORM)
|
||||||
// Guess default driver
|
// Guess default driver
|
||||||
|
|||||||
@@ -62,13 +62,13 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
extern void led_set_mode(uint32_t mode);
|
extern void led_set_mode(uint32_t mode);
|
||||||
extern uint32_t led_get_mode();
|
extern uint32_t led_get_mode(void);
|
||||||
extern void led_blinking_task();
|
extern void led_blinking_task(void);
|
||||||
extern void led_off_all();
|
extern void led_off_all(void);
|
||||||
extern void led_init();
|
extern void led_init(void);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
void (*init)();
|
void (*init)(void);
|
||||||
void (*set_color)(uint8_t color, uint32_t led_brightness, float progress);
|
void (*set_color)(uint8_t color, uint32_t led_brightness, float progress);
|
||||||
} led_driver_t;
|
} led_driver_t;
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
#include "pico/cyw43_arch.h"
|
#include "pico/cyw43_arch.h"
|
||||||
|
|
||||||
void led_driver_init_cyw43() {
|
void led_driver_init_cyw43(void) {
|
||||||
cyw43_arch_init();
|
cyw43_arch_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ tNeopixel pixel[] = {
|
|||||||
#define NEOPIXEL_PIN GPIO_NUM_27
|
#define NEOPIXEL_PIN GPIO_NUM_27
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void led_driver_init_neopixel() {
|
void led_driver_init_neopixel(void) {
|
||||||
uint8_t gpio = NEOPIXEL_PIN;
|
uint8_t gpio = NEOPIXEL_PIN;
|
||||||
if (phy_data.led_gpio_present) {
|
if (phy_data.led_gpio_present) {
|
||||||
gpio = phy_data.led_gpio;
|
gpio = phy_data.led_gpio;
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ static uint8_t gpio = 0;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(PICO_PLATFORM) || defined(ESP_PLATFORM)
|
#if defined(PICO_PLATFORM) || defined(ESP_PLATFORM)
|
||||||
void led_driver_init_pico() {
|
static void led_driver_init_pico(void) {
|
||||||
if (phy_data.led_gpio_present) {
|
if (phy_data.led_gpio_present) {
|
||||||
gpio = phy_data.led_gpio;
|
gpio = phy_data.led_gpio;
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,8 @@ void led_driver_init_pico() {
|
|||||||
gpio_set_dir(gpio, GPIO_OUT);
|
gpio_set_dir(gpio, GPIO_OUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void led_driver_color_pico(uint8_t color, uint32_t led_brightness, float progress) {
|
static void led_driver_color_pico(uint8_t color, uint32_t led_brightness, float progress) {
|
||||||
|
(void)color;
|
||||||
(void)led_brightness;
|
(void)led_brightness;
|
||||||
gpio_put(gpio, progress >= 0.5);
|
gpio_put(gpio, progress >= 0.5);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ uint8_t pixel[][3] = {
|
|||||||
{0, 0, 0} // 7: white
|
{0, 0, 0} // 7: white
|
||||||
};
|
};
|
||||||
|
|
||||||
void led_driver_init_pimoroni() {
|
static void led_driver_init_pimoroni(void) {
|
||||||
if (phy_data.led_gpio_present) {
|
if (phy_data.led_gpio_present) {
|
||||||
gpio = phy_data.led_gpio;
|
gpio = phy_data.led_gpio;
|
||||||
}
|
}
|
||||||
@@ -47,7 +47,8 @@ void led_driver_init_pimoroni() {
|
|||||||
gpio_set_dir(gpio+1, GPIO_OUT);
|
gpio_set_dir(gpio+1, GPIO_OUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void led_driver_color_pimoroni(uint8_t color, uint32_t led_brightness, float progress) {
|
static void led_driver_color_pimoroni(uint8_t color, uint32_t led_brightness, float progress) {
|
||||||
|
(void)led_brightness;
|
||||||
if (progress < 0.5) {
|
if (progress < 0.5) {
|
||||||
color = LED_COLOR_OFF;
|
color = LED_COLOR_OFF;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ static inline void ws2812_program_init(PIO pio, uint sm, uint offset, uint pin,
|
|||||||
pio_sm_set_enabled(pio, sm, true);
|
pio_sm_set_enabled(pio, sm, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void led_driver_init_ws2812() {
|
static void led_driver_init_ws2812(void) {
|
||||||
PIO pio = pio0;
|
PIO pio = pio0;
|
||||||
int sm = 0;
|
int sm = 0;
|
||||||
uint offset = pio_add_program(pio, &ws2812_program);
|
uint offset = pio_add_program(pio, &ws2812_program);
|
||||||
@@ -115,7 +115,7 @@ static inline void ws2812_put_pixel(uint32_t u32_pixel) {
|
|||||||
pio_sm_put_blocking(pio0, 0, u32_pixel << 8u);
|
pio_sm_put_blocking(pio0, 0, u32_pixel << 8u);
|
||||||
}
|
}
|
||||||
|
|
||||||
void led_driver_color_ws2812(uint8_t color, uint32_t led_brightness, float progress) {
|
static void led_driver_color_ws2812(uint8_t color, uint32_t led_brightness, float progress) {
|
||||||
if (!(phy_data.opts & PHY_OPT_DIMM)) {
|
if (!(phy_data.opts & PHY_OPT_DIMM)) {
|
||||||
progress = progress >= 0.5 ? 1 : 0;
|
progress = progress >= 0.5 ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|||||||
30
src/main.c
30
src/main.c
@@ -41,12 +41,11 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "random.h"
|
#include "random.h"
|
||||||
|
#include "hwrng.h"
|
||||||
#include "apdu.h"
|
#include "apdu.h"
|
||||||
#include "usb.h"
|
#include "usb.h"
|
||||||
#include "mbedtls/sha256.h"
|
#include "mbedtls/sha256.h"
|
||||||
|
|
||||||
extern void do_flash();
|
|
||||||
extern void low_flash_init();
|
|
||||||
extern void init_otp_files(void);
|
extern void init_otp_files(void);
|
||||||
|
|
||||||
app_t apps[16];
|
app_t apps[16];
|
||||||
@@ -105,7 +104,7 @@ int select_app(const uint8_t *aid, size_t aid_len) {
|
|||||||
|
|
||||||
int (*button_pressed_cb)(uint8_t) = NULL;
|
int (*button_pressed_cb)(uint8_t) = NULL;
|
||||||
|
|
||||||
void execute_tasks();
|
static void execute_tasks(void);
|
||||||
|
|
||||||
static bool req_button_pending = false;
|
static bool req_button_pending = false;
|
||||||
|
|
||||||
@@ -146,12 +145,12 @@ int gettimeofday(struct timeval* tp, struct timezone* tzp)
|
|||||||
#endif
|
#endif
|
||||||
#if !defined(ENABLE_EMULATION)
|
#if !defined(ENABLE_EMULATION)
|
||||||
#ifdef ESP_PLATFORM
|
#ifdef ESP_PLATFORM
|
||||||
bool picok_board_button_read() {
|
static bool picok_board_button_read(void) {
|
||||||
int boot_state = gpio_get_level(BOOT_PIN);
|
int boot_state = gpio_get_level(BOOT_PIN);
|
||||||
return boot_state == 0;
|
return boot_state == 0;
|
||||||
}
|
}
|
||||||
#elif defined(PICO_PLATFORM)
|
#elif defined(PICO_PLATFORM)
|
||||||
bool __no_inline_not_in_flash_func(picok_get_bootsel_button)() {
|
static bool __no_inline_not_in_flash_func(picok_get_bootsel_button)(void) {
|
||||||
const uint CS_PIN_INDEX = 1;
|
const uint CS_PIN_INDEX = 1;
|
||||||
|
|
||||||
// Must disable interrupts, as interrupt handlers may be in flash, and we
|
// Must disable interrupts, as interrupt handlers may be in flash, and we
|
||||||
@@ -168,7 +167,7 @@ bool __no_inline_not_in_flash_func(picok_get_bootsel_button)() {
|
|||||||
|
|
||||||
// The HI GPIO registers in SIO can observe and control the 6 QSPI pins.
|
// The HI GPIO registers in SIO can observe and control the 6 QSPI pins.
|
||||||
// Note the button pulls the pin *low* when pressed.
|
// Note the button pulls the pin *low* when pressed.
|
||||||
#if PICO_RP2040
|
#ifdef PICO_RP2040
|
||||||
#define CS_BIT (1u << 1)
|
#define CS_BIT (1u << 1)
|
||||||
#else
|
#else
|
||||||
#define CS_BIT SIO_GPIO_HI_IN_QSPI_CSN_BITS
|
#define CS_BIT SIO_GPIO_HI_IN_QSPI_CSN_BITS
|
||||||
@@ -185,11 +184,11 @@ bool __no_inline_not_in_flash_func(picok_get_bootsel_button)() {
|
|||||||
|
|
||||||
return button_state;
|
return button_state;
|
||||||
}
|
}
|
||||||
bool picok_board_button_read(void) {
|
static bool picok_board_button_read(void) {
|
||||||
return picok_get_bootsel_button();
|
return picok_get_bootsel_button();
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
bool picok_board_button_read(void) {
|
static bool picok_board_button_read(void) {
|
||||||
return true; // always unpressed
|
return true; // always unpressed
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -236,7 +235,7 @@ bool wait_button(void) {
|
|||||||
return timeout || cancel_button;
|
return timeout || cancel_button;
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((weak)) int picokey_init() {
|
__attribute__((weak)) int picokey_init(void) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,7 +272,7 @@ time_t get_rtc_time(void) {
|
|||||||
|
|
||||||
struct apdu apdu;
|
struct apdu apdu;
|
||||||
|
|
||||||
void init_rtc() {
|
static void init_rtc(void) {
|
||||||
#ifdef PICO_PLATFORM
|
#ifdef PICO_PLATFORM
|
||||||
struct timespec tv = {0};
|
struct timespec tv = {0};
|
||||||
tv.tv_sec = 1577836800; // 2020-01-01
|
tv.tv_sec = 1577836800; // 2020-01-01
|
||||||
@@ -281,9 +280,7 @@ void init_rtc() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void hwrng_task();
|
static void execute_tasks(void)
|
||||||
extern void usb_task();
|
|
||||||
void execute_tasks()
|
|
||||||
{
|
{
|
||||||
#if !defined(ENABLE_EMULATION) && !defined(ESP_PLATFORM)
|
#if !defined(ENABLE_EMULATION) && !defined(ESP_PLATFORM)
|
||||||
tud_task(); // tinyusb device task
|
tud_task(); // tinyusb device task
|
||||||
@@ -292,7 +289,8 @@ void execute_tasks()
|
|||||||
led_blinking_task();
|
led_blinking_task();
|
||||||
}
|
}
|
||||||
|
|
||||||
void core0_loop() {
|
static void core0_loop(void *arg) {
|
||||||
|
(void)arg;
|
||||||
while (1) {
|
while (1) {
|
||||||
execute_tasks();
|
execute_tasks();
|
||||||
hwrng_task();
|
hwrng_task();
|
||||||
@@ -331,7 +329,7 @@ pico_unique_board_id_t pico_serial;
|
|||||||
extern tinyusb_config_t tusb_cfg;
|
extern tinyusb_config_t tusb_cfg;
|
||||||
extern const uint8_t desc_config[];
|
extern const uint8_t desc_config[];
|
||||||
TaskHandle_t hcore0 = NULL, hcore1 = NULL;
|
TaskHandle_t hcore0 = NULL, hcore1 = NULL;
|
||||||
int app_main() {
|
int app_main(void) {
|
||||||
#else
|
#else
|
||||||
#ifndef PICO_PLATFORM
|
#ifndef PICO_PLATFORM
|
||||||
#define pico_get_unique_board_id(a) memset(a, 0, sizeof(*(a)))
|
#define pico_get_unique_board_id(a) memset(a, 0, sizeof(*(a)))
|
||||||
@@ -405,7 +403,7 @@ int main(void) {
|
|||||||
#ifdef ESP_PLATFORM
|
#ifdef ESP_PLATFORM
|
||||||
xTaskCreatePinnedToCore(core0_loop, "core0", 4096*ITF_TOTAL*2, NULL, CONFIG_TINYUSB_TASK_PRIORITY - 1, &hcore0, ESP32_CORE0);
|
xTaskCreatePinnedToCore(core0_loop, "core0", 4096*ITF_TOTAL*2, NULL, CONFIG_TINYUSB_TASK_PRIORITY - 1, &hcore0, ESP32_CORE0);
|
||||||
#else
|
#else
|
||||||
core0_loop();
|
core0_loop(NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -71,6 +71,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern bool wait_button(void);
|
extern bool wait_button(void);
|
||||||
|
extern int picokey_init(void);
|
||||||
|
|
||||||
extern void low_flash_init_core1(void);
|
extern void low_flash_init_core1(void);
|
||||||
|
|
||||||
|
|||||||
22
src/rescue.c
22
src/rescue.c
@@ -29,8 +29,8 @@ extern char __flash_binary_start;
|
|||||||
extern char __flash_binary_end;
|
extern char __flash_binary_end;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int rescue_process_apdu();
|
static int rescue_process_apdu(void);
|
||||||
int rescue_unload();
|
static int rescue_unload(void);
|
||||||
|
|
||||||
const uint8_t rescue_aid[] = {
|
const uint8_t rescue_aid[] = {
|
||||||
8,
|
8,
|
||||||
@@ -55,7 +55,7 @@ extern uint8_t PICO_PRODUCT;
|
|||||||
extern uint8_t PICO_VERSION_MAJOR;
|
extern uint8_t PICO_VERSION_MAJOR;
|
||||||
extern uint8_t PICO_VERSION_MINOR;
|
extern uint8_t PICO_VERSION_MINOR;
|
||||||
|
|
||||||
int rescue_select(app_t *a, uint8_t force) {
|
static int rescue_select(app_t *a, uint8_t force) {
|
||||||
a->process_apdu = rescue_process_apdu;
|
a->process_apdu = rescue_process_apdu;
|
||||||
a->unload = rescue_unload;
|
a->unload = rescue_unload;
|
||||||
res_APDU_size = 0;
|
res_APDU_size = 0;
|
||||||
@@ -76,7 +76,7 @@ INITIALIZER ( rescue_ctor ) {
|
|||||||
register_app(rescue_select, rescue_aid);
|
register_app(rescue_select, rescue_aid);
|
||||||
}
|
}
|
||||||
|
|
||||||
int rescue_unload() {
|
static int rescue_unload(void) {
|
||||||
return PICOKEY_OK;
|
return PICOKEY_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ static int load_internal_keydev(mbedtls_ecp_keypair *ecp, mbedtls_ecp_group_id e
|
|||||||
return PICOKEY_OK;
|
return PICOKEY_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cmd_keydev_sign() {
|
static int cmd_keydev_sign(void) {
|
||||||
uint8_t p1 = P1(apdu);
|
uint8_t p1 = P1(apdu);
|
||||||
if (p1 == 0x01) {
|
if (p1 == 0x01) {
|
||||||
if (apdu.nc != 32) {
|
if (apdu.nc != 32) {
|
||||||
@@ -210,7 +210,7 @@ int cmd_keydev_sign() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Blocking CORE1
|
// Blocking CORE1
|
||||||
void led_3_blinks() {
|
static void led_3_blinks(void) {
|
||||||
#ifndef ENABLE_EMULATION
|
#ifndef ENABLE_EMULATION
|
||||||
uint32_t mode = led_get_mode();
|
uint32_t mode = led_get_mode();
|
||||||
led_set_mode(MODE_PROCESSING);
|
led_set_mode(MODE_PROCESSING);
|
||||||
@@ -219,7 +219,7 @@ void led_3_blinks() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int cmd_write() {
|
static int cmd_write(void) {
|
||||||
if (apdu.nc < 2) {
|
if (apdu.nc < 2) {
|
||||||
return SW_WRONG_LENGTH();
|
return SW_WRONG_LENGTH();
|
||||||
}
|
}
|
||||||
@@ -268,7 +268,7 @@ int cmd_write() {
|
|||||||
return SW_OK();
|
return SW_OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
int cmd_read() {
|
static int cmd_read(void) {
|
||||||
if (apdu.nc != 0) {
|
if (apdu.nc != 0) {
|
||||||
return SW_WRONG_LENGTH();
|
return SW_WRONG_LENGTH();
|
||||||
}
|
}
|
||||||
@@ -340,7 +340,7 @@ int cmd_read() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(PICO_RP2350) || defined(ESP_PLATFORM)
|
#if defined(PICO_RP2350) || defined(ESP_PLATFORM)
|
||||||
int cmd_secure() {
|
static int cmd_secure(void) {
|
||||||
if (apdu.nc != 0) {
|
if (apdu.nc != 0) {
|
||||||
return SW_WRONG_LENGTH();
|
return SW_WRONG_LENGTH();
|
||||||
}
|
}
|
||||||
@@ -358,7 +358,7 @@ int cmd_secure() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef PICO_PLATFORM
|
#ifdef PICO_PLATFORM
|
||||||
int cmd_reboot_bootsel() {
|
static int cmd_reboot_bootsel(void) {
|
||||||
if (apdu.nc != 0) {
|
if (apdu.nc != 0) {
|
||||||
return SW_WRONG_LENGTH();
|
return SW_WRONG_LENGTH();
|
||||||
}
|
}
|
||||||
@@ -398,7 +398,7 @@ static const cmd_t cmds[] = {
|
|||||||
{ 0x00, 0x0 }
|
{ 0x00, 0x0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
int rescue_process_apdu() {
|
static int rescue_process_apdu(void) {
|
||||||
if (CLA(apdu) != 0x80) {
|
if (CLA(apdu) != 0x80) {
|
||||||
return SW_CLA_NOT_SUPPORTED();
|
return SW_CLA_NOT_SUPPORTED();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,10 +18,10 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include "hwrng.h"
|
||||||
|
|
||||||
#if defined(PICO_PLATFORM)
|
#if defined(PICO_PLATFORM)
|
||||||
#include "pico/stdlib.h"
|
#include "pico/stdlib.h"
|
||||||
#include "hwrng.h"
|
|
||||||
#include "bsp/board.h"
|
#include "bsp/board.h"
|
||||||
#include "pico/rand.h"
|
#include "pico/rand.h"
|
||||||
#elif defined(ESP_PLATFORM)
|
#elif defined(ESP_PLATFORM)
|
||||||
@@ -35,7 +35,7 @@
|
|||||||
#include "board.h"
|
#include "board.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void hwrng_start() {
|
static void hwrng_start(void) {
|
||||||
#if defined(ENABLE_EMULATION)
|
#if defined(ENABLE_EMULATION)
|
||||||
srand(time(0));
|
srand(time(0));
|
||||||
#elif defined(ESP_PLATFORM)
|
#elif defined(ESP_PLATFORM)
|
||||||
@@ -46,13 +46,13 @@ void hwrng_start() {
|
|||||||
static uint64_t random_word = 0xcbf29ce484222325;
|
static uint64_t random_word = 0xcbf29ce484222325;
|
||||||
static uint8_t hwrng_mix_round = 0;
|
static uint8_t hwrng_mix_round = 0;
|
||||||
|
|
||||||
static void hwrng_mix_init() {
|
static void hwrng_mix_init(void) {
|
||||||
random_word = 0xcbf29ce484222325;
|
random_word = 0xcbf29ce484222325;
|
||||||
hwrng_mix_round = 0;
|
hwrng_mix_round = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Here, we assume a little endian architecture. */
|
/* Here, we assume a little endian architecture. */
|
||||||
static int hwrng_mix_process() {
|
static int hwrng_mix_process(void) {
|
||||||
if (hwrng_mix_round == 0) {
|
if (hwrng_mix_round == 0) {
|
||||||
hwrng_mix_init();
|
hwrng_mix_init();
|
||||||
}
|
}
|
||||||
@@ -119,7 +119,7 @@ static uint32_t hwrng_buf_del(struct hwrng_buf *rb) {
|
|||||||
|
|
||||||
static struct hwrng_buf ring_buffer;
|
static struct hwrng_buf ring_buffer;
|
||||||
|
|
||||||
void *hwrng_task() {
|
void *hwrng_task(void) {
|
||||||
struct hwrng_buf *rb = &ring_buffer;
|
struct hwrng_buf *rb = &ring_buffer;
|
||||||
|
|
||||||
int n;
|
int n;
|
||||||
@@ -154,7 +154,7 @@ void hwrng_flush(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t hwrng_get() {
|
uint32_t hwrng_get(void) {
|
||||||
struct hwrng_buf *rb = &ring_buffer;
|
struct hwrng_buf *rb = &ring_buffer;
|
||||||
uint32_t v;
|
uint32_t v;
|
||||||
|
|
||||||
@@ -166,7 +166,7 @@ uint32_t hwrng_get() {
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hwrng_wait_full() {
|
void hwrng_wait_full(void) {
|
||||||
struct hwrng_buf *rb = &ring_buffer;
|
struct hwrng_buf *rb = &ring_buffer;
|
||||||
#ifdef ESP_PLATFORM
|
#ifdef ESP_PLATFORM
|
||||||
uint8_t core = xTaskGetCurrentTaskHandle() == hcore1 ? 1 : 0;
|
uint8_t core = xTaskGetCurrentTaskHandle() == hcore1 ? 1 : 0;
|
||||||
|
|||||||
@@ -20,8 +20,9 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
void hwrng_init(uint32_t *buf, uint8_t size);
|
void hwrng_init(uint32_t *buf, uint8_t size);
|
||||||
uint32_t hwrng_get();
|
uint32_t hwrng_get(void);
|
||||||
void hwrng_flush(void);
|
void hwrng_flush(void);
|
||||||
void hwrng_wait_full();
|
void hwrng_wait_full(void);
|
||||||
|
void *hwrng_task(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "hwrng.h"
|
#include "hwrng.h"
|
||||||
|
#include "random.h"
|
||||||
|
|
||||||
#define RANDOM_BYTES_LENGTH 32
|
#define RANDOM_BYTES_LENGTH 32
|
||||||
static uint32_t random_word[RANDOM_BYTES_LENGTH / sizeof(uint32_t)];
|
static uint32_t random_word[RANDOM_BYTES_LENGTH / sizeof(uint32_t)];
|
||||||
|
|||||||
@@ -97,21 +97,22 @@ static uint8_t itf_num;
|
|||||||
static usb_buffer_t *ccid_rx = NULL, *ccid_tx = NULL;
|
static usb_buffer_t *ccid_rx = NULL, *ccid_tx = NULL;
|
||||||
|
|
||||||
int driver_process_usb_packet_ccid(uint8_t itf, uint16_t rx_read);
|
int driver_process_usb_packet_ccid(uint8_t itf, uint16_t rx_read);
|
||||||
|
void ccid_init(void);
|
||||||
|
void ccid_task(void);
|
||||||
|
#ifdef ENABLE_EMULATION
|
||||||
|
void tud_vendor_rx_cb(uint8_t itf, const uint8_t *buffer, uint16_t bufsize);
|
||||||
|
#endif
|
||||||
|
|
||||||
void ccid_write_offset(uint8_t itf, uint16_t size, uint16_t offset) {
|
static void ccid_write_offset(uint8_t itf, uint16_t size, uint16_t offset) {
|
||||||
ccid_tx[itf].w_ptr += size + offset;
|
ccid_tx[itf].w_ptr += size + offset;
|
||||||
ccid_tx[itf].r_ptr += offset;
|
ccid_tx[itf].r_ptr += offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ccid_write(uint8_t itf, uint16_t size) {
|
|
||||||
ccid_write_offset(itf, size, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
ccid_header_t **ccid_response = NULL;
|
ccid_header_t **ccid_response = NULL;
|
||||||
ccid_header_t **ccid_resp_fast = NULL;
|
ccid_header_t **ccid_resp_fast = NULL;
|
||||||
ccid_header_t **ccid_header = NULL;
|
ccid_header_t **ccid_header = NULL;
|
||||||
|
|
||||||
uint8_t sc_itf_to_usb_itf(uint8_t itf) {
|
static uint8_t sc_itf_to_usb_itf(uint8_t itf) {
|
||||||
if (itf == ITF_SC_CCID) {
|
if (itf == ITF_SC_CCID) {
|
||||||
return ITF_CCID;
|
return ITF_CCID;
|
||||||
}
|
}
|
||||||
@@ -121,7 +122,7 @@ uint8_t sc_itf_to_usb_itf(uint8_t itf) {
|
|||||||
return itf;
|
return itf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ccid_init_buffers() {
|
static void ccid_init_buffers(void) {
|
||||||
if (ITF_SC_TOTAL == 0) {
|
if (ITF_SC_TOTAL == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -142,7 +143,7 @@ void ccid_init_buffers() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int driver_init_ccid(uint8_t itf) {
|
static int driver_init_ccid(uint8_t itf) {
|
||||||
ccid_header[itf] = (ccid_header_t *) (ccid_rx[itf].buffer + ccid_rx[itf].r_ptr);
|
ccid_header[itf] = (ccid_header_t *) (ccid_rx[itf].buffer + ccid_rx[itf].r_ptr);
|
||||||
ccid_resp_fast[itf] = (ccid_header_t *) (ccid_tx[itf].buffer + sizeof(ccid_tx[itf].buffer) - 64);
|
ccid_resp_fast[itf] = (ccid_header_t *) (ccid_tx[itf].buffer + sizeof(ccid_tx[itf].buffer) - 64);
|
||||||
// apdu.header = &ccid_header->apdu;
|
// apdu.header = &ccid_header->apdu;
|
||||||
@@ -157,6 +158,8 @@ int driver_init_ccid(uint8_t itf) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void tud_vendor_rx_cb(uint8_t itf, const uint8_t *buffer, uint16_t bufsize) {
|
void tud_vendor_rx_cb(uint8_t itf, const uint8_t *buffer, uint16_t bufsize) {
|
||||||
|
(void)buffer;
|
||||||
|
(void)bufsize;
|
||||||
uint32_t len = tud_vendor_n_available(itf);
|
uint32_t len = tud_vendor_n_available(itf);
|
||||||
do {
|
do {
|
||||||
uint16_t tlen = 0;
|
uint16_t tlen = 0;
|
||||||
@@ -173,7 +176,7 @@ void tud_vendor_rx_cb(uint8_t itf, const uint8_t *buffer, uint16_t bufsize) {
|
|||||||
} while (len > 0);
|
} while (len > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int driver_write_ccid(uint8_t itf, const uint8_t *tx_buffer, uint16_t buffer_size) {
|
static int driver_write_ccid(uint8_t itf, const uint8_t *tx_buffer, uint16_t buffer_size) {
|
||||||
if (*tx_buffer != 0x81) {
|
if (*tx_buffer != 0x81) {
|
||||||
DEBUG_PAYLOAD(tx_buffer, buffer_size);
|
DEBUG_PAYLOAD(tx_buffer, buffer_size);
|
||||||
}
|
}
|
||||||
@@ -193,7 +196,7 @@ int driver_write_ccid(uint8_t itf, const uint8_t *tx_buffer, uint16_t buffer_siz
|
|||||||
return (int)written;
|
return (int)written;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ccid_write_fast(uint8_t itf, const uint8_t *buffer, uint16_t buffer_size) {
|
static int ccid_write_fast(uint8_t itf, const uint8_t *buffer, uint16_t buffer_size) {
|
||||||
return driver_write_ccid(itf, buffer, buffer_size);
|
return driver_write_ccid(itf, buffer, buffer_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -316,7 +319,7 @@ int driver_process_usb_packet_ccid(uint8_t itf, uint16_t rx_read) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void driver_exec_timeout_ccid(uint8_t itf) {
|
static void driver_exec_timeout_ccid(uint8_t itf) {
|
||||||
ccid_resp_fast[itf]->bMessageType = CCID_DATA_BLOCK_RET;
|
ccid_resp_fast[itf]->bMessageType = CCID_DATA_BLOCK_RET;
|
||||||
ccid_resp_fast[itf]->dwLength = 0;
|
ccid_resp_fast[itf]->dwLength = 0;
|
||||||
ccid_resp_fast[itf]->bSlot = 0;
|
ccid_resp_fast[itf]->bSlot = 0;
|
||||||
@@ -341,7 +344,7 @@ void driver_exec_finished_cont_ccid(uint8_t itf, uint16_t size_next, uint16_t of
|
|||||||
ccid_write_offset(itf, size_next+10, offset);
|
ccid_write_offset(itf, size_next+10, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ccid_task() {
|
void ccid_task(void) {
|
||||||
for (int itf = 0; itf < ITF_SC_TOTAL; itf++) {
|
for (int itf = 0; itf < ITF_SC_TOTAL; itf++) {
|
||||||
int status = card_status(sc_itf_to_usb_itf(itf));
|
int status = card_status(sc_itf_to_usb_itf(itf));
|
||||||
if (status == PICOKEY_OK) {
|
if (status == PICOKEY_OK) {
|
||||||
@@ -358,7 +361,7 @@ void ccid_task() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ccid_init() {
|
void ccid_init(void) {
|
||||||
ccid_init_buffers();
|
ccid_init_buffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ extern int cbor_parse(uint8_t cmd, const uint8_t *data, size_t len);
|
|||||||
pthread_t hcore0, hcore1;
|
pthread_t hcore0, hcore1;
|
||||||
|
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
int msleep(long msec) {
|
static int msleep(long msec) {
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ int msleep(long msec) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int emul_init(char *host, uint16_t port) {
|
int emul_init(const char *host, uint16_t port) {
|
||||||
struct sockaddr_in serv_addr;
|
struct sockaddr_in serv_addr;
|
||||||
fprintf(stderr, "\n Starting emulation envionrment\n");
|
fprintf(stderr, "\n Starting emulation envionrment\n");
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
@@ -167,7 +167,7 @@ int emul_init(char *host, uint16_t port) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
socket_t get_sock_itf(uint8_t itf) {
|
static socket_t get_sock_itf(uint8_t itf) {
|
||||||
#ifdef USB_ITF_CCID
|
#ifdef USB_ITF_CCID
|
||||||
if (itf == ITF_CCID) {
|
if (itf == ITF_CCID) {
|
||||||
return ccid_sock;
|
return ccid_sock;
|
||||||
@@ -333,7 +333,7 @@ uint16_t emul_read(uint8_t itf) {
|
|||||||
return emul_rx_size;
|
return emul_rx_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void emul_task() {
|
void emul_task(void) {
|
||||||
#ifdef USB_ITF_CCID
|
#ifdef USB_ITF_CCID
|
||||||
emul_read(ITF_CCID);
|
emul_read(ITF_CCID);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -25,11 +25,12 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#define USB_BUFFER_SIZE 4096
|
#define USB_BUFFER_SIZE 4096
|
||||||
extern int emul_init(char *host, uint16_t port);
|
extern int emul_init(const char *host, uint16_t port);
|
||||||
extern uint8_t emul_rx[USB_BUFFER_SIZE];
|
extern uint8_t emul_rx[USB_BUFFER_SIZE];
|
||||||
extern uint16_t emul_rx_size, emul_tx_size;
|
extern uint16_t emul_rx_size, emul_tx_size;
|
||||||
extern uint16_t driver_write_emul(uint8_t itf, const uint8_t *buffer, uint16_t buffer_size);
|
extern uint16_t driver_write_emul(uint8_t itf, const uint8_t *buffer, uint16_t buffer_size);
|
||||||
extern uint16_t emul_read(uint8_t itf);
|
extern uint16_t emul_read(uint8_t itf);
|
||||||
|
extern void emul_task(void);
|
||||||
|
|
||||||
#ifdef USB_ITF_HID
|
#ifdef USB_ITF_HID
|
||||||
typedef uint8_t hid_report_type_t;
|
typedef uint8_t hid_report_type_t;
|
||||||
|
|||||||
@@ -158,6 +158,9 @@ typedef struct {
|
|||||||
|
|
||||||
extern void add_keyboard_buffer(const uint8_t *, size_t, bool);
|
extern void add_keyboard_buffer(const uint8_t *, size_t, bool);
|
||||||
extern void append_keyboard_buffer(const uint8_t *data, size_t data_len);
|
extern void append_keyboard_buffer(const uint8_t *data, size_t data_len);
|
||||||
|
extern int driver_init_hid(void);
|
||||||
|
extern int ctap_error(uint8_t error);
|
||||||
|
extern uint16_t *get_send_buffer_size(uint8_t itf);
|
||||||
|
|
||||||
extern bool is_nk;
|
extern bool is_nk;
|
||||||
|
|
||||||
|
|||||||
@@ -31,10 +31,10 @@ static portMUX_TYPE mutex = portMUX_INITIALIZER_UNLOCKED;
|
|||||||
#include "apdu.h"
|
#include "apdu.h"
|
||||||
#include "usb.h"
|
#include "usb.h"
|
||||||
|
|
||||||
extern void init_fido();
|
extern void init_fido(void);
|
||||||
bool is_nk = false;
|
bool is_nk = false;
|
||||||
uint8_t (*get_version_major)() = NULL;
|
uint8_t (*get_version_major)(void) = NULL;
|
||||||
uint8_t (*get_version_minor)() = NULL;
|
uint8_t (*get_version_minor)(void) = NULL;
|
||||||
|
|
||||||
static usb_buffer_t *hid_rx = NULL, *hid_tx = NULL;
|
static usb_buffer_t *hid_rx = NULL, *hid_tx = NULL;
|
||||||
|
|
||||||
@@ -51,12 +51,18 @@ static uint16_t *send_buffer_size = NULL;
|
|||||||
static write_status_t *last_write_result = NULL;
|
static write_status_t *last_write_result = NULL;
|
||||||
|
|
||||||
CTAPHID_FRAME *ctap_req = NULL, *ctap_resp = NULL;
|
CTAPHID_FRAME *ctap_req = NULL, *ctap_resp = NULL;
|
||||||
void send_keepalive();
|
static void send_keepalive(void);
|
||||||
int driver_process_usb_packet_hid(uint16_t read);
|
int driver_process_usb_packet_hid(uint16_t read);
|
||||||
int driver_write_hid(uint8_t itf, const uint8_t *buffer, uint16_t buffer_size);
|
int driver_write_hid(uint8_t itf, const uint8_t *buffer, uint16_t buffer_size);
|
||||||
int driver_process_usb_nopacket_hid();
|
static int driver_process_usb_nopacket_hid(void);
|
||||||
|
void hid_init(void);
|
||||||
|
void hid_task(void);
|
||||||
|
#ifdef ENABLE_EMULATION
|
||||||
|
uint16_t tud_hid_get_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t *buffer, uint16_t reqlen);
|
||||||
|
void tud_hid_set_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t const *buffer, uint16_t bufsize);
|
||||||
|
#endif
|
||||||
|
|
||||||
void hid_init() {
|
void hid_init(void) {
|
||||||
if (ITF_HID_TOTAL == 0) {
|
if (ITF_HID_TOTAL == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -74,7 +80,7 @@ void hid_init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int driver_init_hid() {
|
int driver_init_hid(void) {
|
||||||
#ifndef ENABLE_EMULATION
|
#ifndef ENABLE_EMULATION
|
||||||
static bool _init = false;
|
static bool _init = false;
|
||||||
if (_init == false) {
|
if (_init == false) {
|
||||||
@@ -98,10 +104,6 @@ int driver_init_hid() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t *get_send_buffer_size(uint8_t itf) {
|
|
||||||
return &send_buffer_size[itf];
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// USB HID
|
// USB HID
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
@@ -127,7 +129,7 @@ uint16_t tud_hid_get_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t
|
|||||||
return reqlen;
|
return reqlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t hid_write_offset(uint16_t size, uint16_t offset) {
|
static uint32_t hid_write_offset(uint16_t size, uint16_t offset) {
|
||||||
if (hid_tx[ITF_HID_CTAP].buffer[offset] != 0x81) {
|
if (hid_tx[ITF_HID_CTAP].buffer[offset] != 0x81) {
|
||||||
DEBUG_PAYLOAD(&hid_tx[ITF_HID_CTAP].buffer[offset], size);
|
DEBUG_PAYLOAD(&hid_tx[ITF_HID_CTAP].buffer[offset], size);
|
||||||
}
|
}
|
||||||
@@ -136,7 +138,7 @@ uint32_t hid_write_offset(uint16_t size, uint16_t offset) {
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t hid_write(uint16_t size) {
|
static uint32_t hid_write(uint16_t size) {
|
||||||
return hid_write_offset(size, 0);
|
return hid_write_offset(size, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -309,7 +311,7 @@ uint8_t thread_type = 0; //1 is APDU, 2 is CBOR
|
|||||||
extern bool cancel_button;
|
extern bool cancel_button;
|
||||||
extern int cbor_process(uint8_t last_cmd, const uint8_t *data, size_t len);
|
extern int cbor_process(uint8_t last_cmd, const uint8_t *data, size_t len);
|
||||||
|
|
||||||
int driver_process_usb_nopacket_hid() {
|
int driver_process_usb_nopacket_hid(void) {
|
||||||
if (last_packet_time > 0 && last_packet_time + 500 < board_millis()) {
|
if (last_packet_time > 0 && last_packet_time + 500 < board_millis()) {
|
||||||
ctap_error(CTAP1_ERR_MSG_TIMEOUT);
|
ctap_error(CTAP1_ERR_MSG_TIMEOUT);
|
||||||
last_packet_time = 0;
|
last_packet_time = 0;
|
||||||
@@ -321,6 +323,10 @@ 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 *cbor_thread(void *);
|
extern void *cbor_thread(void *);
|
||||||
|
|
||||||
|
uint16_t *get_send_buffer_size(uint8_t itf) {
|
||||||
|
return &send_buffer_size[itf];
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
||||||
if (read >= 5) {
|
if (read >= 5) {
|
||||||
@@ -549,7 +555,7 @@ int driver_process_usb_packet_hid(uint16_t read) {
|
|||||||
return apdu_sent;
|
return apdu_sent;
|
||||||
}
|
}
|
||||||
|
|
||||||
void send_keepalive() {
|
static void send_keepalive(void) {
|
||||||
if (thread_type == 1) {
|
if (thread_type == 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -593,7 +599,7 @@ void driver_exec_finished_cont_hid(uint8_t itf, uint16_t size_next, uint16_t off
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void hid_task() {
|
void hid_task(void) {
|
||||||
#ifdef ENABLE_EMULATION
|
#ifdef ENABLE_EMULATION
|
||||||
uint16_t rx_len = emul_read(ITF_HID);
|
uint16_t rx_len = emul_read(ITF_HID);
|
||||||
if (rx_len) {
|
if (rx_len) {
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ 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();
|
|
||||||
#endif
|
#endif
|
||||||
#if !defined(PICO_PLATFORM) && !defined(ENABLE_EMULATION) && !defined(ESP_PLATFORM)
|
#if !defined(PICO_PLATFORM) && !defined(ENABLE_EMULATION) && !defined(ESP_PLATFORM)
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
@@ -53,14 +52,14 @@ pthread_t hcore0, hcore1;
|
|||||||
uint8_t ITF_HID_CTAP = ITF_INVALID, ITF_HID_KB = ITF_INVALID;
|
uint8_t ITF_HID_CTAP = ITF_INVALID, ITF_HID_KB = ITF_INVALID;
|
||||||
uint8_t ITF_HID = ITF_INVALID, ITF_KEYBOARD = ITF_INVALID;
|
uint8_t ITF_HID = ITF_INVALID, ITF_KEYBOARD = ITF_INVALID;
|
||||||
uint8_t ITF_HID_TOTAL = 0;
|
uint8_t ITF_HID_TOTAL = 0;
|
||||||
extern void hid_init();
|
extern void hid_init(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USB_ITF_CCID
|
#ifdef USB_ITF_CCID
|
||||||
uint8_t ITF_SC_CCID = ITF_INVALID, ITF_SC_WCID = ITF_INVALID;
|
uint8_t ITF_SC_CCID = ITF_INVALID, ITF_SC_WCID = ITF_INVALID;
|
||||||
uint8_t ITF_CCID = ITF_INVALID, ITF_WCID = ITF_INVALID;
|
uint8_t ITF_CCID = ITF_INVALID, ITF_WCID = ITF_INVALID;
|
||||||
uint8_t ITF_SC_TOTAL = 0;
|
uint8_t ITF_SC_TOTAL = 0;
|
||||||
extern void ccid_init();
|
extern void ccid_init(void);
|
||||||
#endif
|
#endif
|
||||||
uint8_t ITF_TOTAL = 0;
|
uint8_t ITF_TOTAL = 0;
|
||||||
|
|
||||||
@@ -75,7 +74,7 @@ queue_t card_to_usb_q = {0};
|
|||||||
extern tusb_desc_device_t desc_device;
|
extern tusb_desc_device_t desc_device;
|
||||||
extern char *string_desc_itf[4], *string_desc_arr[];
|
extern char *string_desc_itf[4], *string_desc_arr[];
|
||||||
#endif
|
#endif
|
||||||
void usb_init()
|
void usb_init(void)
|
||||||
{
|
{
|
||||||
#ifndef ENABLE_EMULATION
|
#ifndef ENABLE_EMULATION
|
||||||
if (phy_data.vidpid_present) {
|
if (phy_data.vidpid_present) {
|
||||||
@@ -158,15 +157,15 @@ void usb_init()
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t timeout = 0;
|
uint32_t timeout = 0;
|
||||||
void timeout_stop() {
|
void timeout_stop(void) {
|
||||||
timeout = 0;
|
timeout = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void timeout_start() {
|
void timeout_start(void) {
|
||||||
timeout = board_millis();
|
timeout = board_millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_busy() {
|
bool is_busy(void) {
|
||||||
return timeout > 0;
|
return timeout > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,8 +186,7 @@ void usb_send_event(uint32_t flag) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void low_flash_init();
|
void card_init_core1(void) {
|
||||||
void card_init_core1() {
|
|
||||||
low_flash_init_core1();
|
low_flash_init_core1();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,7 +208,7 @@ void card_start(uint8_t itf, void *(*func)(void *)) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void card_exit() {
|
void card_exit(void) {
|
||||||
if (card_locked_itf != ITF_TOTAL || card_locked_func != NULL) {
|
if (card_locked_itf != ITF_TOTAL || card_locked_func != NULL) {
|
||||||
usb_send_event(EV_EXIT);
|
usb_send_event(EV_EXIT);
|
||||||
uint32_t m;
|
uint32_t m;
|
||||||
@@ -238,10 +236,10 @@ void card_exit() {
|
|||||||
card_locked_itf = ITF_TOTAL;
|
card_locked_itf = ITF_TOTAL;
|
||||||
card_locked_func = NULL;
|
card_locked_func = NULL;
|
||||||
}
|
}
|
||||||
extern void hid_task();
|
extern void hid_task(void);
|
||||||
extern void ccid_task();
|
extern void ccid_task(void);
|
||||||
extern void emul_task();
|
extern void emul_task(void);
|
||||||
void usb_task() {
|
void usb_task(void) {
|
||||||
#ifdef USB_ITF_HID
|
#ifdef USB_ITF_HID
|
||||||
hid_task();
|
hid_task();
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -73,23 +73,24 @@ enum {
|
|||||||
#define TUSB_SMARTCARD_CCID_EPS 3
|
#define TUSB_SMARTCARD_CCID_EPS 3
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern void usb_task();
|
extern void usb_task(void);
|
||||||
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(void);
|
||||||
extern int card_status(uint8_t itf);
|
extern int card_status(uint8_t itf);
|
||||||
extern void usb_init();
|
extern void usb_init(void);
|
||||||
|
|
||||||
extern uint16_t finished_data_size;
|
extern uint16_t finished_data_size;
|
||||||
extern void usb_set_timeout_counter(uint8_t itf, uint32_t v);
|
extern void usb_set_timeout_counter(uint8_t itf, uint32_t v);
|
||||||
extern void card_init_core1();
|
extern void card_init_core1(void);
|
||||||
|
|
||||||
extern void usb_send_event(uint32_t flag);
|
extern void usb_send_event(uint32_t flag);
|
||||||
extern void timeout_stop();
|
extern void timeout_stop(void);
|
||||||
extern void timeout_start();
|
extern void timeout_start(void);
|
||||||
extern bool is_busy();
|
extern bool is_busy(void);
|
||||||
|
extern void usb_desc_setup(void);
|
||||||
|
|
||||||
#ifdef USB_ITF_HID
|
#ifdef USB_ITF_HID
|
||||||
extern void driver_exec_finished_hid(uint16_t size_next);
|
extern void driver_exec_finished_hid(uint16_t size_next);
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ uint8_t const *tud_hid_descriptor_report_cb(uint8_t itf) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void usb_desc_setup() {
|
void usb_desc_setup(void) {
|
||||||
desc_config[4] = ITF_TOTAL;
|
desc_config[4] = ITF_TOTAL;
|
||||||
TUSB_DESC_TOTAL_LEN = TUD_CONFIG_DESC_LEN;
|
TUSB_DESC_TOTAL_LEN = TUD_CONFIG_DESC_LEN;
|
||||||
uint8_t *p = desc_config + TUD_CONFIG_DESC_LEN;
|
uint8_t *p = desc_config + TUD_CONFIG_DESC_LEN;
|
||||||
|
|||||||
Reference in New Issue
Block a user