mirror of
https://github.com/polhenarejos/pico-keys-sdk
synced 2026-05-26 08:05:10 +02:00
@@ -426,36 +426,44 @@ function(picokeys_apply_strict_flags)
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(PICOKEYS_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 (MSVC)
|
||||
set(PICOKEYS_STRICT_FLAGS
|
||||
-Wall
|
||||
-Zc:strictStrings
|
||||
-WX
|
||||
)
|
||||
else ()
|
||||
set(PICOKEYS_STRICT_FLAGS
|
||||
-pipe
|
||||
-funsigned-char
|
||||
-fstrict-aliasing
|
||||
-fdiagnostics-color=auto
|
||||
-Wextra
|
||||
-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
|
||||
-Wmissing-prototypes
|
||||
-Wstrict-prototypes
|
||||
-Wold-style-definition
|
||||
-Wbad-function-cast
|
||||
-Wnested-externs
|
||||
-Wmissing-declarations
|
||||
-Werror
|
||||
)
|
||||
endif()
|
||||
|
||||
foreach(src IN LISTS PKAS_SOURCES)
|
||||
if(PKAS_FILTER_REGEX)
|
||||
|
||||
@@ -64,6 +64,19 @@ int settimeofday(const struct timeval* tp, const struct timezone* tzp)
|
||||
}
|
||||
#endif
|
||||
|
||||
struct tm *gmtime_utc(const time_t *timep, struct tm *result) {
|
||||
#ifdef _WIN32
|
||||
struct tm *tmp = gmtime(timep);
|
||||
if (tmp == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
*result = *tmp;
|
||||
return result;
|
||||
#else
|
||||
return gmtime_r(timep, result);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef ENABLE_EMULATION
|
||||
bool set_rtc = true;
|
||||
#else
|
||||
@@ -79,7 +92,7 @@ void set_rtc_time(time_t t) {
|
||||
struct timespec tv = {.tv_sec = t, .tv_nsec = 0};
|
||||
aon_timer_set_time(&tv);
|
||||
#else
|
||||
struct timeval tv = {.tv_sec = t, .tv_usec = 0};
|
||||
struct timeval tv = {.tv_sec = (long)t, .tv_usec = 0};
|
||||
settimeofday(&tv, NULL);
|
||||
#endif
|
||||
set_rtc = true;
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "compat/board.h"
|
||||
#endif
|
||||
|
||||
extern struct tm *gmtime_utc(const time_t *timep, struct tm *result);
|
||||
extern bool has_set_rtc(void);
|
||||
extern time_t get_rtc_time(void);
|
||||
extern void set_rtc_time(time_t tv_sec);
|
||||
|
||||
23
src/rescue.c
23
src/rescue.c
@@ -338,23 +338,18 @@ static int cmd_read(void) {
|
||||
}
|
||||
res_APDU_size = 0;
|
||||
time_t tv_sec = get_rtc_time();
|
||||
#ifdef PICO_PLATFORM
|
||||
struct timespec tv = {.tv_sec = tv_sec, .tv_nsec = 0};
|
||||
#else
|
||||
struct timeval tv = {.tv_sec = tv_sec, .tv_usec = 0};
|
||||
#endif
|
||||
if (p2 == 0x1) {
|
||||
struct tm *tm = localtime(&tv.tv_sec);
|
||||
res_APDU_size += put_uint16_be(tm->tm_year + 1900, res_APDU);
|
||||
res_APDU[res_APDU_size++] = tm->tm_mon;
|
||||
res_APDU[res_APDU_size++] = tm->tm_mday;
|
||||
res_APDU[res_APDU_size++] = tm->tm_wday;
|
||||
res_APDU[res_APDU_size++] = tm->tm_hour;
|
||||
res_APDU[res_APDU_size++] = tm->tm_min;
|
||||
res_APDU[res_APDU_size++] = tm->tm_sec;
|
||||
struct tm *tm = localtime(&tv_sec);
|
||||
res_APDU_size += put_uint16_be((uint16_t)(tm->tm_year + 1900), res_APDU);
|
||||
res_APDU[res_APDU_size++] = (uint8_t)tm->tm_mon;
|
||||
res_APDU[res_APDU_size++] = (uint8_t)tm->tm_mday;
|
||||
res_APDU[res_APDU_size++] = (uint8_t)tm->tm_wday;
|
||||
res_APDU[res_APDU_size++] = (uint8_t)tm->tm_hour;
|
||||
res_APDU[res_APDU_size++] = (uint8_t)tm->tm_min;
|
||||
res_APDU[res_APDU_size++] = (uint8_t)tm->tm_sec;
|
||||
}
|
||||
else if (p2 == 0x2) {
|
||||
res_APDU_size += put_uint32_be((uint32_t)tv.tv_sec, res_APDU);
|
||||
res_APDU_size += put_uint32_be((uint32_t)tv_sec, res_APDU);
|
||||
}
|
||||
}
|
||||
return SW_OK();
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
static void hwrng_start(void) {
|
||||
#if defined(ENABLE_EMULATION)
|
||||
srand(time(0));
|
||||
srand((unsigned int)time(NULL));
|
||||
#elif defined(ESP_PLATFORM)
|
||||
bootloader_random_enable();
|
||||
#endif
|
||||
@@ -188,8 +188,7 @@ uint32_t hwrng_get(void) {
|
||||
|
||||
while (true) {
|
||||
hwrng_lock();
|
||||
bool empty = rb->empty;
|
||||
if (!empty) {
|
||||
if (!rb->empty) {
|
||||
v = hwrng_buf_del(rb);
|
||||
hwrng_unlock();
|
||||
break;
|
||||
@@ -210,9 +209,8 @@ void hwrng_wait_full(void) {
|
||||
#endif
|
||||
while (true) {
|
||||
hwrng_lock();
|
||||
bool full = rb->full;
|
||||
hwrng_unlock();
|
||||
if (full) {
|
||||
if (rb->full) {
|
||||
break;
|
||||
}
|
||||
#if defined(PICO_PLATFORM) || defined(ESP_PLATFORM)
|
||||
|
||||
@@ -80,7 +80,7 @@ const uint8_t *random_bytes_get(size_t len) {
|
||||
*/
|
||||
int random_fill_iterator(void *arg, unsigned char *out, size_t out_len) {
|
||||
random_fill_iterator_ctx_t *ctx = (random_fill_iterator_ctx_t *) arg;
|
||||
uint32_t index = ctx ? ctx->index : 0;
|
||||
uint8_t index = ctx ? ctx->index : 0;
|
||||
uint8_t n;
|
||||
int ret = 0;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct {
|
||||
uint32_t index;
|
||||
uint8_t index;
|
||||
volatile bool cancel;
|
||||
} random_fill_iterator_ctx_t;
|
||||
|
||||
|
||||
@@ -345,7 +345,7 @@ void driver_exec_finished_cont_ccid(uint8_t itf, uint16_t size_next, uint16_t of
|
||||
}
|
||||
|
||||
void ccid_task(void) {
|
||||
for (int itf = 0; itf < ITF_SC_TOTAL; itf++) {
|
||||
for (uint8_t itf = 0; itf < ITF_SC_TOTAL; itf++) {
|
||||
int status = card_status(sc_itf_to_usb_itf(itf));
|
||||
if (status == PICOKEYS_OK) {
|
||||
driver_exec_finished_ccid(itf, finished_data_size);
|
||||
|
||||
@@ -336,7 +336,7 @@ uint16_t emul_read(uint8_t itf) {
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
emul_rx_size += valread;
|
||||
emul_rx_size += (uint16_t)valread;
|
||||
}
|
||||
return (uint16_t)emul_rx_size;
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ typedef int socket_t;
|
||||
static struct tcp_pcb *listener_pcb = NULL;
|
||||
#else
|
||||
extern socket_t tls_listener_sock;
|
||||
static socket_t listener_sock = -1;
|
||||
static socket_t listener_sock = INVALID_SOCKET;
|
||||
static pthread_t rest_thread;
|
||||
#endif
|
||||
static rest_conn_t conns[REST_MAX_CONNS];
|
||||
@@ -162,7 +162,7 @@ static void send_json_error(rest_conn_t *conn, int status_code, const char *erro
|
||||
rest_close_conn(conn);
|
||||
return;
|
||||
}
|
||||
send_json(conn, status_code, rest_status_text_from_code(status_code), json);
|
||||
send_json(conn, status_code, rest_status_text_from_code((uint16_t)status_code), json);
|
||||
}
|
||||
|
||||
void rest_task(void) {
|
||||
@@ -395,7 +395,7 @@ static void send_response(rest_conn_t *conn, int status_code, const char *status
|
||||
}
|
||||
#ifdef ENABLE_EMULATION
|
||||
while (sent_total < (size_t)header_len) {
|
||||
int n = send((socket_t)conn->sock, headers_buf + sent_total, (size_t)header_len - sent_total, 0);
|
||||
int n = send((socket_t)conn->sock, headers_buf + sent_total, (int)((size_t)header_len - sent_total), 0);
|
||||
if (n <= 0) {
|
||||
rest_close_conn(conn);
|
||||
return;
|
||||
@@ -404,7 +404,7 @@ static void send_response(rest_conn_t *conn, int status_code, const char *status
|
||||
}
|
||||
sent_total = 0;
|
||||
while (sent_total < body_len) {
|
||||
int n = send((socket_t)conn->sock, body + sent_total, body_len - sent_total, 0);
|
||||
int n = send((socket_t)conn->sock, body + sent_total, (int)(body_len - sent_total), 0);
|
||||
if (n <= 0) {
|
||||
rest_close_conn(conn);
|
||||
return;
|
||||
@@ -610,7 +610,7 @@ static int parse_request(rest_conn_t *conn, rest_request_t *request) {
|
||||
}
|
||||
|
||||
headers_size = conn->request_headers_size;
|
||||
content_length = conn->request_content_length;
|
||||
content_length = (unsigned long)conn->request_content_length;
|
||||
header_end = conn->request + headers_size - 4;
|
||||
|
||||
line_end = strstr(conn->request, "\r\n");
|
||||
|
||||
@@ -163,6 +163,7 @@ typedef int socklen_t;
|
||||
#else
|
||||
#include <strings.h>
|
||||
typedef int socket_t;
|
||||
#define INVALID_SOCKET (-1)
|
||||
#include <arpa/inet.h>
|
||||
#include <errno.h>
|
||||
#include <netinet/in.h>
|
||||
@@ -171,7 +172,7 @@ typedef int socket_t;
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
socket_t tls_listener_sock = -1;
|
||||
socket_t tls_listener_sock = INVALID_SOCKET;
|
||||
|
||||
int emulation_rest_tls_port(void) {
|
||||
const char *port_env = getenv("PICO_REST_TLS_PORT");
|
||||
|
||||
Reference in New Issue
Block a user