From 7c76a71f33b15f2efdfbd736a26b8c6193502035 Mon Sep 17 00:00:00 2001 From: Pol Henarejos Date: Mon, 19 Aug 2024 13:18:03 +0200 Subject: [PATCH] Fix emulation build. Signed-off-by: Pol Henarejos --- src/usb/emulation/emulation.c | 11 ++++++----- src/usb/hid/ctap_hid.h | 7 +++++++ src/usb/usb.c | 2 ++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/usb/emulation/emulation.c b/src/usb/emulation/emulation.c index bb370c2..90c0cbb 100644 --- a/src/usb/emulation/emulation.c +++ b/src/usb/emulation/emulation.c @@ -45,6 +45,7 @@ typedef int socklen_t; #include "apdu.h" #include "usb.h" #include "ccid/ccid.h" +#include "hid/ctap_hid.h" socket_t ccid_sock = 0; socket_t hid_server_sock = 0; @@ -190,7 +191,7 @@ socket_t get_sock_itf(uint8_t itf) { extern void tud_hid_report_complete_cb(uint8_t instance, uint8_t const *report, uint16_t len); const uint8_t *complete_report = NULL; uint16_t complete_len = 0; -extern bool last_write_result; +extern uint8_t last_write_result[ITF_TOTAL]; extern uint16_t send_buffer_size[ITF_TOTAL]; uint16_t driver_write_emul(uint8_t itf, const uint8_t *buffer, uint16_t buffer_size) { uint16_t size = htons(buffer_size); @@ -211,7 +212,7 @@ uint16_t driver_write_emul(uint8_t itf, const uint8_t *buffer, uint16_t buffer_s } while (ret <= 0); #ifdef USB_ITF_HID if (itf == ITF_HID) { - last_write_result = true; + last_write_result[itf] = WRITE_PENDING; complete_report = buffer; complete_len = buffer_size; } @@ -234,7 +235,7 @@ uint32_t emul_write(uint8_t itf, uint16_t size) { void driver_exec_finished_cont_emul(uint8_t itf, uint16_t size_next, uint16_t offset) { #ifdef USB_ITF_HID if (itf == ITF_HID) { - driver_exec_finished_cont_hid(size_next, offset); + driver_exec_finished_cont_hid(itf, size_next, offset); } #endif #ifdef USB_ITF_CCID @@ -246,9 +247,9 @@ void driver_exec_finished_cont_emul(uint8_t itf, uint16_t size_next, uint16_t of int driver_process_usb_packet_emul(uint8_t itf, uint16_t len) { if (len > 0) { - uint8_t *data = usb_get_rx(itf); #ifdef USB_ITF_CCID if (itf == ITF_CCID) { + uint8_t *data = usb_get_rx(itf); if (len == 1) { uint8_t c = data[0]; if (c == 4) { @@ -324,7 +325,7 @@ uint16_t emul_read(uint8_t itf) { printf("hid_client connected!\n"); } if (send_buffer_size > 0) { - last_write_result = true; + last_write_result[itf] = WRITE_PENDING; tud_hid_report_complete_cb(ITF_HID, complete_report, complete_len); } } diff --git a/src/usb/hid/ctap_hid.h b/src/usb/hid/ctap_hid.h index cd56b8b..9828ef5 100644 --- a/src/usb/hid/ctap_hid.h +++ b/src/usb/hid/ctap_hid.h @@ -162,6 +162,13 @@ extern void append_keyboard_buffer(const uint8_t *data, size_t data_len); extern bool is_nitrokey; +typedef enum { + WRITE_UNKNOWN = 0, + WRITE_PENDING, + WRITE_FAILED, + WRITE_SUCCESS, +} write_status_t; + #ifdef __cplusplus } #endif diff --git a/src/usb/usb.c b/src/usb/usb.c index ee5dfaa..7ddb03c 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -40,7 +40,9 @@ static uint16_t w_offset[ITF_TOTAL] = { 0 }, r_offset[ITF_TOTAL] = { 0 }; static uint16_t w_len[ITF_TOTAL] = { 0 }, tx_r_offset[ITF_TOTAL] = { 0 }; static uint32_t timeout_counter[ITF_TOTAL] = { 0 }; uint8_t card_locked_itf = ITF_TOTAL; // no locked +#ifndef ENABLE_EMULATION static uint8_t proc_locked = 0; +#endif void (*cbor_thread_func)() = NULL;