mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-25 07:48:10 +00:00
tests: update u2ftest to auto-confirm when needed
This commit is contained in:
parent
5472499326
commit
de011fa069
@ -7,12 +7,6 @@
|
|||||||
// Thin shim to allow abstracting away from hid_* calls to
|
// Thin shim to allow abstracting away from hid_* calls to
|
||||||
// a set or read/write pipes w/ a particular interface.
|
// a set or read/write pipes w/ a particular interface.
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <endian.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "u2f_util.h"
|
#include "u2f_util.h"
|
||||||
|
|
||||||
bool DEV_opened(struct U2Fob* device) {
|
bool DEV_opened(struct U2Fob* device) {
|
||||||
@ -24,10 +18,19 @@ void DEV_close(struct U2Fob* device) {
|
|||||||
hid_close(device->dev);
|
hid_close(device->dev);
|
||||||
device->dev = NULL;
|
device->dev = NULL;
|
||||||
}
|
}
|
||||||
|
if (device->dev_debug) {
|
||||||
|
hid_close(device->dev_debug);
|
||||||
|
device->dev_debug = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DEV_open_path(struct U2Fob* device) {
|
void DEV_open_path(struct U2Fob* device) {
|
||||||
device->dev = hid_open_path(device->path);
|
device->dev = hid_open_path(device->path);
|
||||||
|
if (atoi(device->path) != 21325) {
|
||||||
|
device->dev_debug = hid_open_path("21325");
|
||||||
|
} else {
|
||||||
|
device->dev_debug = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int DEV_write(struct U2Fob* device, const uint8_t* src, size_t n) {
|
int DEV_write(struct U2Fob* device, const uint8_t* src, size_t n) {
|
||||||
@ -42,5 +45,12 @@ int DEV_read_timeout(struct U2Fob* device, uint8_t* dst, size_t n,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int DEV_touch(struct U2Fob* device) {
|
int DEV_touch(struct U2Fob* device) {
|
||||||
return 0;
|
if (!device->dev_debug) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
sleep(1);
|
||||||
|
// send DebugLinkDecision{yes_no=True} to DebugLink interface
|
||||||
|
hid_write(device->dev_debug, (const uint8_t *)"\x00?##\x00" "d\x00\x00\x00\x02\x08\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 65);
|
||||||
|
sleep(1);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
@ -42,6 +43,7 @@ hid_device *hid_open_path(const char *path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
hid_device *d = malloc(sizeof(hid_device));
|
hid_device *d = malloc(sizeof(hid_device));
|
||||||
|
memset(d, 0, sizeof(hid_device));
|
||||||
d->fd = fd;
|
d->fd = fd;
|
||||||
|
|
||||||
d->other.sin_family = AF_INET;
|
d->other.sin_family = AF_INET;
|
||||||
@ -75,7 +77,7 @@ int hid_write(hid_device *device, const unsigned char *data, size_t length) {
|
|||||||
fprintf(stderr, "Failed to write socket\n");
|
fprintf(stderr, "Failed to write socket\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
usleep(1000);
|
usleep(1500);
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +87,7 @@ int hid_read_timeout(hid_device *device, unsigned char *data, size_t length, int
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < milliseconds; i++) {
|
for (int i = 0; i < milliseconds; i++) {
|
||||||
usleep(1000);
|
usleep(1500);
|
||||||
ssize_t n = recvfrom(device->fd, data, length, MSG_DONTWAIT, (struct sockaddr *)&(device->other), &(device->slen));
|
ssize_t n = recvfrom(device->fd, data, length, MSG_DONTWAIT, (struct sockaddr *)&(device->other), &(device->slen));
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
if (errno == EAGAIN && errno == EWOULDBLOCK) { // timeout tick
|
if (errno == EAGAIN && errno == EWOULDBLOCK) { // timeout tick
|
||||||
|
Loading…
Reference in New Issue
Block a user