Fix emulation build.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos
2024-08-23 14:24:17 +02:00
parent 65fea84df1
commit 90842bb8f7
6 changed files with 154 additions and 167 deletions

View File

@@ -164,16 +164,6 @@ int emul_init(char *host, uint16_t port) {
return 0;
}
uint8_t *driver_prepare_response_emul(uint8_t itf) {
apdu.rdata = usb_get_tx(itf);
#ifdef USB_ITF_HID
if (itf == ITF_HID) {
apdu.rdata += 7;
}
#endif
return apdu.rdata;
}
socket_t get_sock_itf(uint8_t itf) {
#ifdef USB_ITF_CCID
if (itf == ITF_CCID) {
@@ -188,11 +178,6 @@ socket_t get_sock_itf(uint8_t itf) {
return INVALID_SOCKET;
}
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 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);
socket_t sock = get_sock_itf(itf);
@@ -210,28 +195,10 @@ uint16_t driver_write_emul(uint8_t itf, const uint8_t *buffer, uint16_t buffer_s
msleep(10);
}
} while (ret <= 0);
#ifdef USB_ITF_HID
if (itf == ITF_HID) {
last_write_result[itf] = WRITE_PENDING;
complete_report = buffer;
complete_len = buffer_size;
}
#endif
emul_tx_size = buffer_size;
return buffer_size;
}
uint32_t emul_write_offset(uint8_t itf, uint16_t size, uint16_t offset) {
if (size > 0) {
//DEBUG_PAYLOAD(usb_get_tx(itf)+offset, size);
return usb_write_offset(itf, size, offset);
}
return 0;
}
uint32_t emul_write(uint8_t itf, uint16_t size) {
return emul_write_offset(itf, size, 0);
}
void driver_exec_finished_cont_emul(uint8_t itf, uint16_t size_next, uint16_t offset) {
#ifdef USB_ITF_HID
if (itf == ITF_HID) {
@@ -240,62 +207,14 @@ void driver_exec_finished_cont_emul(uint8_t itf, uint16_t size_next, uint16_t of
#endif
#ifdef USB_ITF_CCID
if (itf == ITF_CCID) {
emul_write_offset(itf, size_next, offset);
driver_exec_finished_cont_ccid(itf, size_next, offset);
}
#endif
}
int driver_process_usb_packet_emul(uint8_t itf, uint16_t len) {
if (len > 0) {
#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) {
driver_write_emul(itf, ccid_atr ? ccid_atr + 1 : NULL, ccid_atr ? ccid_atr[0] : 0);
}
}
else {
uint16_t sent = 0;
DEBUG_PAYLOAD(data, len);
if ((sent = apdu_process(itf, data, len)) > 0) {
process_apdu();
apdu_finish();
}
if (sent > 0) {
uint16_t ret = apdu_next();
DEBUG_PAYLOAD(apdu.rdata, ret);
emul_write(itf, ret);
}
}
}
#endif
#ifdef USB_ITF_HID
if (itf == ITF_HID) {
if (driver_process_usb_packet_hid(len) > 0) {
if (thread_type == 1) {
process_apdu();
apdu_finish();
finished_data_size = apdu_next();
}
else if (thread_type == 2) {
apdu.sw = cbor_parse(cmd, cbor_data, cbor_len);
if (apdu.sw == 0) {
DEBUG_DATA(res_APDU + 1, res_APDU_size);
}
finished_data_size = res_APDU_size + 1;
}
driver_exec_finished_hid(finished_data_size);
}
}
#endif
}
usb_clear_rx(itf);
return 0;
}
uint8_t emul_rx[USB_BUFFER_SIZE];
uint16_t emul_rx_size = 0, emul_tx_size = 0;
uint16_t emul_read(uint8_t itf) {
/* First we look for a client */
#ifdef USB_ITF_HID
@@ -359,8 +278,9 @@ uint16_t emul_read(uint8_t itf) {
len = ntohs(len);
if (len > 0) {
while (true) {
valread = recv(sock, (char *)usb_get_rx(itf), len, 0);
valread = recv(sock, (char *)emul_rx, len, 0);
if (valread > 0) {
emul_rx_size = valread;
return (uint16_t)valread;
}
msleep(10);