mirror of
https://github.com/polhenarejos/pico-keys-sdk
synced 2026-05-10 17:28:27 +02:00
Switching to new style.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
@@ -33,8 +33,7 @@
|
||||
|
||||
int sock = 0;
|
||||
|
||||
int msleep(long msec)
|
||||
{
|
||||
int msleep(long msec) {
|
||||
struct timespec ts;
|
||||
int res;
|
||||
|
||||
@@ -53,8 +52,7 @@ int msleep(long msec)
|
||||
return res;
|
||||
}
|
||||
|
||||
int emul_init(char *host, uint16_t port)
|
||||
{
|
||||
int emul_init(char *host, uint16_t port) {
|
||||
struct sockaddr_in serv_addr;
|
||||
fprintf(stderr, "\n Starting emulation envionrment\n");
|
||||
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
|
||||
@@ -81,14 +79,12 @@ int emul_init(char *host, uint16_t port)
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t *driver_prepare_response_emul()
|
||||
{
|
||||
uint8_t *driver_prepare_response_emul() {
|
||||
apdu.rdata = usb_get_tx(ITF_EMUL);
|
||||
return apdu.rdata;
|
||||
}
|
||||
|
||||
int driver_write_emul(const uint8_t *buffer, size_t buffer_size)
|
||||
{
|
||||
int driver_write_emul(const uint8_t *buffer, size_t buffer_size) {
|
||||
uint16_t size = htons(buffer_size);
|
||||
//DEBUG_PAYLOAD(buffer,buffer_size);
|
||||
int ret = 0;
|
||||
@@ -107,8 +103,7 @@ int driver_write_emul(const uint8_t *buffer, size_t buffer_size)
|
||||
return buffer_size;
|
||||
}
|
||||
|
||||
uint32_t emul_write_offset(uint16_t size, uint16_t offset)
|
||||
{
|
||||
uint32_t emul_write_offset(uint16_t size, uint16_t offset) {
|
||||
if (size > 0) {
|
||||
//DEBUG_PAYLOAD(usb_get_tx(ITF_EMUL)+offset, size);
|
||||
return usb_write_offset(ITF_EMUL, size, offset);
|
||||
@@ -116,29 +111,27 @@ uint32_t emul_write_offset(uint16_t size, uint16_t offset)
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t emul_write(uint16_t size)
|
||||
{
|
||||
uint32_t emul_write(uint16_t size) {
|
||||
return emul_write_offset(size, 0);
|
||||
}
|
||||
|
||||
void driver_exec_finished_cont_emul(size_t size_next, size_t offset)
|
||||
{
|
||||
void driver_exec_finished_cont_emul(size_t size_next, size_t offset) {
|
||||
emul_write_offset(size_next, offset);
|
||||
}
|
||||
|
||||
int driver_process_usb_packet_emul(uint16_t len)
|
||||
{
|
||||
int driver_process_usb_packet_emul(uint16_t len) {
|
||||
if (len > 0) {
|
||||
uint8_t *data = usb_get_rx(ITF_EMUL), *rdata = usb_get_tx(ITF_EMUL);
|
||||
if (len == 1) {
|
||||
uint8_t c = data[0];
|
||||
if (c == 4) {
|
||||
if (ccid_atr) {
|
||||
memcpy(rdata, ccid_atr+1, ccid_atr[0]);
|
||||
memcpy(rdata, ccid_atr + 1, ccid_atr[0]);
|
||||
}
|
||||
emul_write(ccid_atr ? ccid_atr[0] : 0);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
DEBUG_PAYLOAD(data, len);
|
||||
if (apdu_process(ITF_EMUL, data, len) > 0) {
|
||||
process_apdu();
|
||||
@@ -153,8 +146,7 @@ int driver_process_usb_packet_emul(uint16_t len)
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint16_t emul_read()
|
||||
{
|
||||
uint16_t emul_read() {
|
||||
uint16_t len = 0;
|
||||
fd_set input;
|
||||
FD_ZERO(&input);
|
||||
@@ -166,7 +158,8 @@ uint16_t emul_read()
|
||||
if (n == -1) {
|
||||
printf("read wrong\n");
|
||||
//something wrong
|
||||
} else if (n == 0) {
|
||||
}
|
||||
else if (n == 0) {
|
||||
printf("read timeout\n");
|
||||
}
|
||||
if (FD_ISSET(sock, &input)) {
|
||||
|
||||
Reference in New Issue
Block a user