forked from Zondax/ledger-zxlib
-
Notifications
You must be signed in to change notification settings - Fork 0
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
33 changed files
with
1,120 additions
and
34 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
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
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,162 @@ | ||
/******************************************************************************* | ||
* (c) 2018, 2019 Zondax GmbH | ||
* (c) 2016 Ledger | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
********************************************************************************/ | ||
|
||
#include "view.h" | ||
#include "coin.h" | ||
#include "view_internal.h" | ||
#include "crypto.h" | ||
|
||
#include "actions.h" | ||
#include "apdu_codes.h" | ||
#include "glyphs.h" | ||
#include "bagl.h" | ||
#include "zxmacros.h" | ||
#include "view_templates.h" | ||
#include "tx.h" | ||
|
||
#include <string.h> | ||
#include <stdio.h> | ||
|
||
view_t viewdata; | ||
|
||
void h_address_accept(unsigned int _) { | ||
UNUSED(_); | ||
view_idle_show(0); | ||
UX_WAIT(); | ||
app_reply_address(); | ||
} | ||
|
||
void h_error_accept(unsigned int _) { | ||
UNUSED(_); | ||
view_idle_show(0); | ||
UX_WAIT(); | ||
app_reply_address(); | ||
} | ||
|
||
void h_sign_accept(unsigned int _) { | ||
UNUSED(_); | ||
|
||
const uint8_t replyLen = app_sign(); | ||
|
||
view_idle_show(0); | ||
UX_WAIT(); | ||
|
||
if (replyLen > 0) { | ||
set_code(G_io_apdu_buffer, replyLen, APDU_CODE_OK); | ||
io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, replyLen + 2); | ||
} else { | ||
set_code(G_io_apdu_buffer, 0, APDU_CODE_SIGN_VERIFY_ERROR); | ||
io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, 2); | ||
} | ||
} | ||
|
||
void h_sign_reject(unsigned int _) { | ||
UNUSED(_); | ||
view_idle_show(0); | ||
UX_WAIT(); | ||
|
||
set_code(G_io_apdu_buffer, 0, APDU_CODE_COMMAND_NOT_ALLOWED); | ||
io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, 2); | ||
} | ||
|
||
void h_review_init() { | ||
viewdata.idx = 0; | ||
viewdata.pageIdx = 0; | ||
viewdata.pageCount = 1; | ||
} | ||
|
||
void h_review_increase() { | ||
viewdata.pageIdx++; | ||
if (viewdata.pageIdx >= viewdata.pageCount) { | ||
viewdata.idx++; | ||
viewdata.pageIdx = 0; | ||
} | ||
} | ||
|
||
void h_review_decrease() { | ||
viewdata.pageIdx--; | ||
if (viewdata.pageIdx < 0) { | ||
viewdata.idx--; | ||
viewdata.pageIdx = 0; | ||
} | ||
} | ||
|
||
view_error_t h_review_update_data() { | ||
tx_error_t err = tx_no_error; | ||
|
||
do { | ||
err = tx_getItem(viewdata.idx, | ||
viewdata.key, MAX_CHARS_PER_KEY_LINE, | ||
viewdata.value, MAX_CHARS_PER_VALUE1_LINE, | ||
viewdata.pageIdx, &viewdata.pageCount); | ||
|
||
if (err == tx_no_data) { | ||
return view_no_data; | ||
} | ||
|
||
if (viewdata.pageCount == 0) { | ||
h_review_increase(); | ||
} | ||
} while (viewdata.pageCount == 0); | ||
|
||
if (err != tx_no_error) { | ||
return view_error_detected; | ||
} | ||
|
||
splitValueField(); | ||
return view_no_error; | ||
} | ||
|
||
view_error_t h_addr_update_item(uint8_t idx) { | ||
MEMZERO(viewdata.addr, MAX_CHARS_ADDR); | ||
switch (idx) { | ||
case 0: | ||
snprintf(viewdata.addr, MAX_CHARS_ADDR, "%s", (char *) (G_io_apdu_buffer + VIEW_ADDRESS_BUFFER_OFFSET)); | ||
break; | ||
case 1: | ||
bip32_to_str(viewdata.addr, MAX_CHARS_ADDR, hdPath, HDPATH_LEN_DEFAULT); | ||
break; | ||
} | ||
return view_no_error; | ||
} | ||
|
||
void io_seproxyhal_display(const bagl_element_t *element) { | ||
io_seproxyhal_display_default((bagl_element_t *) element); | ||
} | ||
|
||
void view_init(void) { | ||
UX_INIT(); | ||
} | ||
|
||
void view_idle_show(unsigned int ignored) { | ||
view_idle_show_impl(); | ||
} | ||
|
||
void view_address_show() { | ||
view_address_show_impl(); | ||
} | ||
|
||
void view_error_show() { | ||
snprintf(viewdata.key, MAX_CHARS_PER_KEY_LINE, "ERROR"); | ||
snprintf(viewdata.value, MAX_CHARS_PER_VALUE1_LINE, "SHOWING DATA"); | ||
splitValueField(); | ||
view_error_show_impl(); | ||
} | ||
|
||
void view_sign_show() { | ||
view_sign_show_impl(); | ||
} |
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,42 @@ | ||
/******************************************************************************* | ||
* (c) 2018-2020 Zondax GmbH | ||
* (c) 2016 Ledger | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
********************************************************************************/ | ||
#pragma once | ||
|
||
#include <stdint.h> | ||
|
||
#if defined(LEDGER_SPECIFIC) | ||
#include "bolos_target.h" | ||
#if defined(BOLOS_SDK) | ||
#include "os.h" | ||
#include "cx.h" | ||
#endif | ||
#endif | ||
|
||
/// view_init (initializes UI) | ||
void view_init(); | ||
|
||
/// view_idle_show (idle view - main menu + status) | ||
void view_idle_show(unsigned int ignored); | ||
|
||
/// view_error (error view) | ||
void view_error_show(); | ||
|
||
// shows address in the screen | ||
void view_address_show(); | ||
|
||
// Shows review screen + later sign menu | ||
void view_sign_show(); |
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,108 @@ | ||
/******************************************************************************* | ||
* (c) 2019 Zondax GmbH | ||
* (c) 2016 Ledger | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
********************************************************************************/ | ||
#pragma once | ||
|
||
#include <stdint.h> | ||
#include "coin.h" | ||
|
||
#define CUR_FLOW G_ux.flow_stack[G_ux.stack_count-1] | ||
|
||
#if defined(TARGET_NANOX) | ||
#define MAX_CHARS_PER_KEY_LINE 64 | ||
#define MAX_CHARS_PER_VALUE1_LINE 4096 | ||
#define MAX_CHARS_HEXMESSAGE 160 | ||
#else | ||
#define MAX_CHARS_PER_KEY_LINE (32+1) | ||
#define MAX_CHARS_PER_VALUE_LINE (18) | ||
#define MAX_CHARS_PER_VALUE1_LINE (2*MAX_CHARS_PER_VALUE_LINE+1) | ||
#define MAX_CHARS_PER_VALUE2_LINE (MAX_CHARS_PER_VALUE_LINE+1) | ||
#define MAX_CHARS_HEXMESSAGE 40 | ||
#endif | ||
#define MAX_CHARS_ADDR (MAX_CHARS_PER_KEY_LINE + MAX_CHARS_PER_VALUE1_LINE) | ||
|
||
// This typically will point to G_io_apdu_buffer that is prefilled with the address | ||
|
||
typedef struct { | ||
union { | ||
struct { | ||
char key[MAX_CHARS_PER_KEY_LINE]; | ||
char value[MAX_CHARS_PER_VALUE1_LINE]; | ||
#if defined(TARGET_NANOS) | ||
char value2[MAX_CHARS_PER_VALUE2_LINE]; | ||
#endif | ||
}; | ||
struct { | ||
char addr[MAX_CHARS_ADDR]; | ||
}; | ||
}; | ||
int8_t idx; | ||
int8_t pageIdx; | ||
uint8_t pageCount; | ||
} view_t; | ||
|
||
extern view_t viewdata; | ||
|
||
typedef enum { | ||
view_no_error = 0, | ||
view_no_data = 1, | ||
view_error_detected = 2 | ||
} view_error_t; | ||
|
||
#define print_title(...) snprintf(viewdata.title, sizeof(viewdata.title), __VA_ARGS__) | ||
#define print_key(...) snprintf(viewdata.key, sizeof(viewdata.key), __VA_ARGS__); | ||
#define print_value(...) snprintf(viewdata.value, sizeof(viewdata.value), __VA_ARGS__); | ||
|
||
#if defined(TARGET_NANOS) | ||
#define print_value2(...) snprintf(viewdata.value2, sizeof(viewdata.value2), __VA_ARGS__); | ||
#endif | ||
|
||
void splitValueField(); | ||
|
||
/////////////////////////////////////////////// | ||
/////////////////////////////////////////////// | ||
/////////////////////////////////////////////// | ||
/////////////////////////////////////////////// | ||
/////////////////////////////////////////////// | ||
/////////////////////////////////////////////// | ||
/////////////////////////////////////////////// | ||
/////////////////////////////////////////////// | ||
|
||
void view_idle_show_impl(); | ||
|
||
void view_address_show_impl(); | ||
|
||
void view_error_show_impl(); | ||
|
||
void view_sign_show_impl(); | ||
|
||
void h_address_accept(unsigned int _); | ||
|
||
void h_error_accept(unsigned int _); | ||
|
||
void h_sign_accept(unsigned int _); | ||
|
||
void h_sign_reject(unsigned int _); | ||
|
||
void h_review_init(); | ||
|
||
void h_review_increase(); | ||
|
||
void h_review_decrease(); | ||
|
||
view_error_t h_review_update_data(); | ||
|
||
view_error_t h_addr_update_item(uint8_t idx); |
Oops, something went wrong.