From e5d55967a0308dba7efd6ff5b83ac11db0351ba2 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Fri, 8 Aug 2014 19:09:54 +0200 Subject: [PATCH] implement GetAddress.show_display --- .gitmodules | 3 ++ Makefile.include | 1 + firmware/Makefile | 4 ++- firmware/fsm.c | 9 ++++++ firmware/layout2.c | 53 +++++++++++++++++++++++++++++++++++ firmware/layout2.h | 1 + firmware/protob/messages.pb.c | 3 +- firmware/protob/messages.pb.h | 7 +++-- firmware/protob/types.pb.h | 3 +- trezor-common | 2 +- trezor-qrenc | 1 + 11 files changed, 81 insertions(+), 6 deletions(-) create mode 160000 trezor-qrenc diff --git a/.gitmodules b/.gitmodules index e02923314..97aef8fa1 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "trezor-common"] path = trezor-common url = https://github.com/trezor/trezor-common.git +[submodule "trezor-qrenc"] + path = trezor-qrenc + url = https://github.com/trezor/trezor-qrenc.git diff --git a/Makefile.include b/Makefile.include index 59b8e7de5..965c5388b 100644 --- a/Makefile.include +++ b/Makefile.include @@ -44,6 +44,7 @@ CFLAGS += $(OPTFLAGS) \ -I$(TOP_DIR) \ -I$(TOP_DIR)/gen \ -I$(TOP_DIR)/trezor-crypto \ + -I$(TOP_DIR)/trezor-qrenc ifdef APPVER CFLAGS += -DAPPVER=$(APPVER) diff --git a/firmware/Makefile b/firmware/Makefile index f5f5d6b21..eff59afc2 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -35,6 +35,8 @@ OBJS += ../trezor-crypto/aeskey.o OBJS += ../trezor-crypto/aestab.o OBJS += ../trezor-crypto/aes_modes.o +OBJS += ../trezor-qrenc/qr_encode.o + OBJS += protob/pb_decode.o OBJS += protob/pb_encode.o OBJS += protob/messages.pb.o @@ -43,9 +45,9 @@ OBJS += protob/types.pb.o include ../Makefile.include -# CFLAGS += -fstack-protector -fstack-protector-all CFLAGS += -Wno-sequence-point CFLAGS += -Iprotob -DPB_FIELD_16BIT=1 +CFLAGS += -DQR_MAX_VERSION=0 CFLAGS += -DDEBUG_LINK=0 CFLAGS += -DDEBUG_LOG=0 CFLAGS += -DSCM_REVISION='"$(shell git rev-parse HEAD | sed 's:\(..\):\\x\1:g')"' diff --git a/firmware/fsm.c b/firmware/fsm.c index 383a2f512..8c1ecb670 100644 --- a/firmware/fsm.c +++ b/firmware/fsm.c @@ -478,6 +478,15 @@ void fsm_msgGetAddress(GetAddress *msg) ecdsa_get_address(node->public_key, coin->address_type, resp->address); + if (msg->has_show_display && msg->show_display) { + layoutAddress(resp->address); + if (!protectButton(ButtonRequestType_ButtonRequest_Address, true)) { + fsm_sendFailure(FailureType_Failure_ActionCancelled, "Show address cancelled"); + layoutHome(); + return; + } + } + msg_write(MessageType_MessageType_Address, resp); layoutHome(); } diff --git a/firmware/layout2.c b/firmware/layout2.c index f5b48215a..1e2ad5bb3 100644 --- a/firmware/layout2.c +++ b/firmware/layout2.c @@ -26,6 +26,7 @@ #include "bitmaps.h" #include "string.h" #include "util.h" +#include "qr_encode.h" void *layoutLast = layoutHome; @@ -251,3 +252,55 @@ void layoutCipherKeyValue(bool encrypt, const char *key) encrypt ? "Encrypt?" : "Decrypt?", str[0], str[1], str[2], str[3], NULL, NULL); } + +void layoutAddress(const char *address) +{ + oledSwipeLeft(); + layoutLast = layoutAddress; + + static unsigned char bitdata[QR_MAX_BITDATA]; + int a, i, j; + int side = qr_encode(QR_LEVEL_M, 0, address, 0, bitdata); + + if (side > 0 && side <= 29) { + oledInvert(0, 0, (side + 2) * 2, (side + 2) * 2); + for (i = 0; i < side; i++) { + for (j = 0; j< side; j++) { + a = i * side + j; + if (bitdata[a / 8] & (1 << (7 - a % 8))) { + oledClearPixel(2 + i * 2, 2 + j * 2); + oledClearPixel(3 + i * 2, 2 + j * 2); + oledClearPixel(2 + i * 2, 3 + j * 2); + oledClearPixel(3 + i * 2, 3 + j * 2); + } + } + } + } + + int len = strlen(address); + char str[4][10]; + memset(str, 0, sizeof(str)); + + strlcpy(str[0], (char *)address, 10); + if (len > 9) { + strlcpy(str[1], (char *)address + 9, 10); + } + if (len > 18) { + strlcpy(str[2], (char *)address + 18, 10); + } + if (len > 27) { + strlcpy(str[3], (char *)address + 27, 10); + } + + oledDrawString(68, 0 * 9, str[0]); + oledDrawString(68, 1 * 9, str[1]); + oledDrawString(68, 2 * 9, str[2]); + oledDrawString(68, 3 * 9, str[3]); + + static const char *btnYes = "Continue"; + oledDrawString(OLED_WIDTH - fontCharWidth('}') - 1, OLED_HEIGHT - 8, "}"); + oledDrawString(OLED_WIDTH - fontStringWidth(btnYes) - fontCharWidth('}') - 3, OLED_HEIGHT - 8, btnYes); + oledInvert(OLED_WIDTH - fontStringWidth(btnYes) - fontCharWidth('}') - 4, OLED_HEIGHT - 9, OLED_WIDTH - 1, OLED_HEIGHT - 1); + + oledRefresh(); +} diff --git a/firmware/layout2.h b/firmware/layout2.h index ffa2f93f2..9a836d3b7 100644 --- a/firmware/layout2.h +++ b/firmware/layout2.h @@ -33,5 +33,6 @@ void layoutFeeOverThreshold(const CoinType *coin, uint64_t fee, uint32_t kb); void layoutSignMessage(const uint8_t *msg, uint32_t len); void layoutVerifyMessage(const uint8_t *msg, uint32_t len); void layoutCipherKeyValue(bool encrypt, const char *key); +void layoutAddress(const char *address); #endif diff --git a/firmware/protob/messages.pb.c b/firmware/protob/messages.pb.c index 6c0097fd0..629844fa5 100644 --- a/firmware/protob/messages.pb.c +++ b/firmware/protob/messages.pb.c @@ -126,9 +126,10 @@ const pb_field_t PublicKey_fields[3] = { PB_LAST_FIELD }; -const pb_field_t GetAddress_fields[3] = { +const pb_field_t GetAddress_fields[4] = { PB_FIELD2( 1, UINT32 , REPEATED, STATIC , FIRST, GetAddress, address_n, address_n, 0), PB_FIELD2( 2, STRING , OPTIONAL, STATIC , OTHER, GetAddress, coin_name, address_n, &GetAddress_coin_name_default), + PB_FIELD2( 3, BOOL , OPTIONAL, STATIC , OTHER, GetAddress, show_display, coin_name, 0), PB_LAST_FIELD }; diff --git a/firmware/protob/messages.pb.h b/firmware/protob/messages.pb.h index 234ea073b..3937da58d 100644 --- a/firmware/protob/messages.pb.h +++ b/firmware/protob/messages.pb.h @@ -298,6 +298,8 @@ typedef struct _GetAddress { uint32_t address_n[8]; bool has_coin_name; char coin_name[17]; + bool has_show_display; + bool show_display; } GetAddress; typedef struct _GetEntropy { @@ -551,6 +553,7 @@ extern const char SimpleSignTx_coin_name_default[17]; #define FirmwareUpload_payload_tag 1 #define GetAddress_address_n_tag 1 #define GetAddress_coin_name_tag 2 +#define GetAddress_show_display_tag 3 #define GetEntropy_size_tag 1 #define GetPublicKey_address_n_tag 1 #define LoadDevice_mnemonic_tag 1 @@ -625,7 +628,7 @@ extern const pb_field_t GetEntropy_fields[2]; extern const pb_field_t Entropy_fields[2]; extern const pb_field_t GetPublicKey_fields[2]; extern const pb_field_t PublicKey_fields[3]; -extern const pb_field_t GetAddress_fields[3]; +extern const pb_field_t GetAddress_fields[4]; extern const pb_field_t Address_fields[2]; extern const pb_field_t WipeDevice_fields[1]; extern const pb_field_t LoadDevice_fields[8]; @@ -675,7 +678,7 @@ extern const pb_field_t DebugLinkLog_fields[4]; #define Entropy_size 1027 #define GetPublicKey_size 48 #define PublicKey_size (121 + HDNodeType_size) -#define GetAddress_size 67 +#define GetAddress_size 69 #define Address_size 37 #define WipeDevice_size 0 #define LoadDevice_size (320 + HDNodeType_size) diff --git a/firmware/protob/types.pb.h b/firmware/protob/types.pb.h index ac4756a44..8f532605c 100644 --- a/firmware/protob/types.pb.h +++ b/firmware/protob/types.pb.h @@ -50,7 +50,8 @@ typedef enum _ButtonRequestType { ButtonRequestType_ButtonRequest_WipeDevice = 6, ButtonRequestType_ButtonRequest_ProtectCall = 7, ButtonRequestType_ButtonRequest_SignTx = 8, - ButtonRequestType_ButtonRequest_FirmwareCheck = 9 + ButtonRequestType_ButtonRequest_FirmwareCheck = 9, + ButtonRequestType_ButtonRequest_Address = 10 } ButtonRequestType; typedef enum _PinMatrixRequestType { diff --git a/trezor-common b/trezor-common index ce8e99465..5bbe684c1 160000 --- a/trezor-common +++ b/trezor-common @@ -1 +1 @@ -Subproject commit ce8e99465ea1fbcbdc5e7b477cfdab73244a444d +Subproject commit 5bbe684c1068bd9cb6d24b12da5e216feb74351d diff --git a/trezor-qrenc b/trezor-qrenc new file mode 160000 index 000000000..dfcfd702b --- /dev/null +++ b/trezor-qrenc @@ -0,0 +1 @@ +Subproject commit dfcfd702be6d0c1bc3f035001fba20f5336f308b