mirror of
https://github.com/polhenarejos/pico-keys-sdk
synced 2026-06-08 14:23:34 +02:00
Adding KEEP_ALIVE response.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
@@ -61,6 +61,8 @@ enum {
|
|||||||
};
|
};
|
||||||
extern void led_set_blink(uint32_t mode);
|
extern void led_set_blink(uint32_t mode);
|
||||||
|
|
||||||
|
extern bool is_req_button_pending();
|
||||||
|
|
||||||
#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)
|
||||||
#define SW_WARNING_CORRUPTED() set_res_sw (0x62, 0x81)
|
#define SW_WARNING_CORRUPTED() set_res_sw (0x62, 0x81)
|
||||||
|
|||||||
@@ -67,11 +67,17 @@ void led_set_blink(uint32_t mode) {
|
|||||||
|
|
||||||
void execute_tasks();
|
void execute_tasks();
|
||||||
|
|
||||||
|
static bool req_button_pending = false;
|
||||||
|
|
||||||
|
bool is_req_button_pending() {
|
||||||
|
return req_button_pending;
|
||||||
|
}
|
||||||
|
|
||||||
bool wait_button() {
|
bool wait_button() {
|
||||||
uint32_t start_button = board_millis();
|
uint32_t start_button = board_millis();
|
||||||
bool timeout = false;
|
bool timeout = false;
|
||||||
led_set_blink((1000 << 16) | 100);
|
led_set_blink((1000 << 16) | 100);
|
||||||
|
req_button_pending = true;
|
||||||
while (board_button_read() == false) {
|
while (board_button_read() == false) {
|
||||||
execute_tasks();
|
execute_tasks();
|
||||||
//sleep_ms(10);
|
//sleep_ms(10);
|
||||||
@@ -91,6 +97,7 @@ bool wait_button() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
led_set_blink(BLINK_PROCESSING);
|
led_set_blink(BLINK_PROCESSING);
|
||||||
|
req_button_pending = false;
|
||||||
return timeout;
|
return timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -124,6 +124,8 @@ int driver_init() {
|
|||||||
ccid_response = (struct ccid_header *)usb_get_tx();
|
ccid_response = (struct ccid_header *)usb_get_tx();
|
||||||
apdu.rdata = &ccid_response->apdu;
|
apdu.rdata = &ccid_response->apdu;
|
||||||
|
|
||||||
|
usb_set_timeout_counter(1500);
|
||||||
|
|
||||||
return CCID_OK;
|
return CCID_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ int driver_init() {
|
|||||||
ctap_resp = (CTAPHID_FRAME *)usb_get_tx();
|
ctap_resp = (CTAPHID_FRAME *)usb_get_tx();
|
||||||
apdu.rdata = ctap_resp->init.data;
|
apdu.rdata = ctap_resp->init.data;
|
||||||
|
|
||||||
|
usb_set_timeout_counter(200);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
void driver_task() {
|
void driver_task() {
|
||||||
@@ -272,7 +274,15 @@ int driver_process_usb_packet(uint16_t read) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void driver_exec_timeout() {
|
void driver_exec_timeout() {
|
||||||
|
ctap_resp = (CTAPHID_FRAME *)usb_get_tx();
|
||||||
|
memset(ctap_resp, 0, sizeof(CTAPHID_FRAME));
|
||||||
|
ctap_resp->cid = ctap_req->cid;
|
||||||
|
ctap_resp->init.cmd = CTAPHID_KEEPALIVE;
|
||||||
|
ctap_resp->init.bcntl = 1;
|
||||||
|
uint8_t bck = ctap_resp->init.data[0];
|
||||||
|
ctap_resp->init.data[0] = is_req_button_pending() ? 2 : 1;
|
||||||
|
hid_write(64);
|
||||||
|
ctap_resp->init.data[0] = bck;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *driver_prepare_response() {
|
uint8_t *driver_prepare_response() {
|
||||||
|
|||||||
@@ -38,6 +38,11 @@
|
|||||||
static uint8_t rx_buffer[4096], tx_buffer[4096];
|
static uint8_t rx_buffer[4096], tx_buffer[4096];
|
||||||
static uint16_t w_offset = 0, r_offset = 0;
|
static uint16_t w_offset = 0, r_offset = 0;
|
||||||
static uint16_t w_len = 0, tx_r_offset = 0;
|
static uint16_t w_len = 0, tx_r_offset = 0;
|
||||||
|
static uint32_t timeout_counter = 0;
|
||||||
|
|
||||||
|
void usb_set_timeout_counter(uint32_t v) {
|
||||||
|
timeout_counter = v;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t usb_write_offset(uint16_t len, uint16_t offset) {
|
uint32_t usb_write_offset(uint16_t len, uint16_t offset) {
|
||||||
uint8_t pkt_max = 64;
|
uint8_t pkt_max = 64;
|
||||||
@@ -147,7 +152,6 @@ static void card_init_core1(void) {
|
|||||||
|
|
||||||
size_t finished_data_size = 0;
|
size_t finished_data_size = 0;
|
||||||
|
|
||||||
void apdu_thread();
|
|
||||||
void card_start(void (*func)(void)) {
|
void card_start(void (*func)(void)) {
|
||||||
multicore_reset_core1();
|
multicore_reset_core1();
|
||||||
card_init_core1();
|
card_init_core1();
|
||||||
@@ -175,6 +179,7 @@ void usb_task() {
|
|||||||
if (m == EV_EXEC_FINISHED) {
|
if (m == EV_EXEC_FINISHED) {
|
||||||
driver_exec_finished(finished_data_size);
|
driver_exec_finished(finished_data_size);
|
||||||
led_set_blink(BLINK_MOUNTED);
|
led_set_blink(BLINK_MOUNTED);
|
||||||
|
timeout_stop();
|
||||||
}
|
}
|
||||||
else if (m == EV_PRESS_BUTTON) {
|
else if (m == EV_PRESS_BUTTON) {
|
||||||
uint32_t flag = wait_button() ? EV_BUTTON_TIMEOUT : EV_BUTTON_PRESSED;
|
uint32_t flag = wait_button() ? EV_BUTTON_TIMEOUT : EV_BUTTON_PRESSED;
|
||||||
@@ -232,7 +237,7 @@ void usb_task() {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (timeout > 0) {
|
if (timeout > 0) {
|
||||||
if (timeout + 1500 < board_millis()) {
|
if (timeout + timeout_counter < board_millis()) {
|
||||||
driver_exec_timeout();
|
driver_exec_timeout();
|
||||||
timeout = board_millis();
|
timeout = board_millis();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,4 +57,6 @@ extern uint8_t *usb_get_tx();
|
|||||||
extern uint32_t usb_write_offset(uint16_t len, uint16_t offset);
|
extern uint32_t usb_write_offset(uint16_t len, uint16_t offset);
|
||||||
extern void usb_clear_rx();
|
extern void usb_clear_rx();
|
||||||
extern size_t finished_data_size;
|
extern size_t finished_data_size;
|
||||||
|
extern void usb_set_timeout_counter(uint32_t v);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user