Adding KEEP_ALIVE response.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
parent
8b97791d8f
commit
5a4aff7008
6 changed files with 33 additions and 5 deletions
|
|
@ -61,6 +61,8 @@ enum {
|
|||
};
|
||||
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_WARNING_STATE_UNCHANGED() set_res_sw (0x62, 0x00)
|
||||
#define SW_WARNING_CORRUPTED() set_res_sw (0x62, 0x81)
|
||||
|
|
|
|||
|
|
@ -67,11 +67,17 @@ void led_set_blink(uint32_t mode) {
|
|||
|
||||
void execute_tasks();
|
||||
|
||||
static bool req_button_pending = false;
|
||||
|
||||
bool is_req_button_pending() {
|
||||
return req_button_pending;
|
||||
}
|
||||
|
||||
bool wait_button() {
|
||||
uint32_t start_button = board_millis();
|
||||
bool timeout = false;
|
||||
led_set_blink((1000 << 16) | 100);
|
||||
|
||||
req_button_pending = true;
|
||||
while (board_button_read() == false) {
|
||||
execute_tasks();
|
||||
//sleep_ms(10);
|
||||
|
|
@ -91,6 +97,7 @@ bool wait_button() {
|
|||
}
|
||||
}
|
||||
led_set_blink(BLINK_PROCESSING);
|
||||
req_button_pending = false;
|
||||
return timeout;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -124,6 +124,8 @@ int driver_init() {
|
|||
ccid_response = (struct ccid_header *)usb_get_tx();
|
||||
apdu.rdata = &ccid_response->apdu;
|
||||
|
||||
usb_set_timeout_counter(1500);
|
||||
|
||||
return CCID_OK;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,6 +53,8 @@ int driver_init() {
|
|||
ctap_resp = (CTAPHID_FRAME *)usb_get_tx();
|
||||
apdu.rdata = ctap_resp->init.data;
|
||||
|
||||
usb_set_timeout_counter(200);
|
||||
|
||||
return 0;
|
||||
}
|
||||
void driver_task() {
|
||||
|
|
@ -272,7 +274,15 @@ int driver_process_usb_packet(uint16_t read) {
|
|||
}
|
||||
|
||||
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() {
|
||||
|
|
|
|||
|
|
@ -38,6 +38,11 @@
|
|||
static uint8_t rx_buffer[4096], tx_buffer[4096];
|
||||
static uint16_t w_offset = 0, 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) {
|
||||
uint8_t pkt_max = 64;
|
||||
|
|
@ -147,7 +152,6 @@ static void card_init_core1(void) {
|
|||
|
||||
size_t finished_data_size = 0;
|
||||
|
||||
void apdu_thread();
|
||||
void card_start(void (*func)(void)) {
|
||||
multicore_reset_core1();
|
||||
card_init_core1();
|
||||
|
|
@ -175,8 +179,9 @@ void usb_task() {
|
|||
if (m == EV_EXEC_FINISHED) {
|
||||
driver_exec_finished(finished_data_size);
|
||||
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;
|
||||
queue_try_add(&usb_to_card_q, &flag);
|
||||
}
|
||||
|
|
@ -232,7 +237,7 @@ void usb_task() {
|
|||
}
|
||||
else {
|
||||
if (timeout > 0) {
|
||||
if (timeout + 1500 < board_millis()) {
|
||||
if (timeout + timeout_counter < board_millis()) {
|
||||
driver_exec_timeout();
|
||||
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 void usb_clear_rx();
|
||||
extern size_t finished_data_size;
|
||||
extern void usb_set_timeout_counter(uint32_t v);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue