-
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# initialize from the image | ||
|
||
FROM fedora:24 | ||
|
||
# update package repositories | ||
|
||
RUN dnf update -y | ||
|
||
# install tools | ||
|
||
RUN dnf install -y make wget | ||
RUN dnf install -y mingw32-gcc | ||
|
||
# install dependencies for Windows build | ||
|
||
RUN dnf install -y mingw32-hidapi-static | ||
|
||
# install dependencies from COPR | ||
|
||
RUN wget https://copr-be.cloud.fedoraproject.org/results/prusnak/private/fedora-24-x86_64/00365081-mingw-protobuf/mingw32-protobuf{,-static}-2.6.1-3.fc24.noarch.rpm | ||
RUN dnf install -y mingw32-protobuf{,-static}-2.6.1-3.fc24.noarch.rpm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
VOL_MOUNT = -v $(shell pwd):/src | ||
IMAGETAG = trezor-prod-test | ||
|
||
all: .wrap | ||
|
||
.wrap: .docker-image | ||
docker run -i -t $(VOL_MOUNT) $(IMAGETAG) /bin/sh -c 'cd /src ; make build' | ||
|
||
build: | ||
i686-w64-mingw32-gcc test-trezor.c -Wl,-Bstatic -lhidapi -Wl,-Bdynamic -lsetupapi -mwindows -o test-trezor-32bit.exe | ||
# /usr/i686-w64-mingw32/sys-root/mingw/lib/libhidapi.a | ||
|
||
.docker-image: | ||
$(info Preparing docker image ...) | ||
docker build -t $(IMAGETAG) . | ||
|
||
shell: .docker-image | ||
docker run -i -t $(VOL_MOUNT) $(IMAGETAG) /bin/bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#include <stdio.h> | ||
#include <stdint.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include <hidapi/hidapi.h> | ||
|
||
void test_ok() | ||
{ | ||
printf("TEST OK\n"); | ||
exit(0); | ||
} | ||
|
||
void test_failed() | ||
{ | ||
printf("TEST FAILED\n"); | ||
exit(1); | ||
} | ||
|
||
int main() | ||
{ | ||
int res; | ||
uint32_t pos; | ||
uint8_t buf[65]; | ||
uint8_t msg[1024]; | ||
|
||
hid_device *handle; | ||
|
||
handle = hid_open(0x534c, 0x0001, NULL); | ||
if (!handle) { | ||
printf("No TREZOR found!\n"); | ||
test_failed(); | ||
} | ||
|
||
printf("TREZOR found\n"); | ||
|
||
memset(buf, 0, sizeof(buf)); | ||
|
||
buf[0] = 0x00; | ||
buf[1] = '?'; buf[2] = '#'; buf[3] = '#'; | ||
buf[4] = 0x00; buf[5] = 0x00; | ||
buf[6] = 0x00; buf[7] = 0x00; buf[8] = 0x00; buf[9] = 0x00; | ||
|
||
// write Initialize | ||
printf("Writing message\n"); | ||
res = hid_write(handle, buf, 65); | ||
|
||
printf("Reading response\n"); | ||
memset(msg, 0, sizeof(msg)); | ||
pos = 0; | ||
// read answer | ||
for (;;) { | ||
memset(buf, 0, sizeof(buf)); | ||
res = hid_read_timeout(handle, buf, 64, 100); | ||
if (res < 0) { | ||
printf("Unable to read\n"); | ||
test_failed(); | ||
} | ||
if (res == 0) { | ||
printf("End of read\n"); | ||
break; | ||
} | ||
printf("Read %d bytes\n", res); | ||
memcpy(msg + pos, buf + 1, res - 1); | ||
pos += res - 1; | ||
} | ||
printf("Total read %d bytes\n", pos); | ||
|
||
char msg_valid = msg[0] == '#' && msg[1] == '#'; | ||
uint16_t msg_id = (msg[2] << 8) + msg[3]; | ||
uint32_t msg_len = (msg[4] << 24) + (msg[5]<< 16) + (msg[6] << 8) + msg[7]; | ||
|
||
if (msg_valid && msg_id == 17 && msg_len <= pos - 8) { | ||
test_ok(); | ||
} else { | ||
test_failed(); | ||
} | ||
|
||
return 0; | ||
} |