Skip to content

Commit

Permalink
WIP Update zxlib
Browse files Browse the repository at this point in the history
STAX and FLEX menu feature not merged into zxlib yet
  • Loading branch information
Robert Lukoťka committed Dec 30, 2024
1 parent a90c920 commit 9cc3f06
Show file tree
Hide file tree
Showing 83 changed files with 2,122 additions and 2,391 deletions.
73 changes: 34 additions & 39 deletions deps/ledger-zxlib/app/common/app_main.c
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
/*******************************************************************************
* (c) 2018 - 2023 Zondax AG
* (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.
********************************************************************************/
* (c) 2018 - 2024 Zondax AG
* (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 "app_main.h"

#include <string.h>
#include <os_io_seproxyhal.h>
#include <os.h>
#include <os_io_seproxyhal.h>
#include <string.h>
#include <ux.h>

#include "view.h"
#include "actions.h"
#include "tx.h"
#include "app_mode.h"
#include "coin.h"
#include "zxmacros.h"
#include "tx.h"
#include "view.h"
#include "zxcanary.h"
#include "app_mode.h"
#include "zxmacros.h"
#ifdef HAVE_SWAP
#include "swap.h"
#endif // HAVE_SWAP
#endif // HAVE_SWAP

unsigned char G_io_seproxyhal_spi_buffer[IO_SEPROXYHAL_BUFFER_SIZE_B];

unsigned char io_event(__Z_UNUSED unsigned char channel) {
switch (G_io_seproxyhal_spi_buffer[0]) {

case SEPROXYHAL_TAG_BUTTON_PUSH_EVENT: // for Nano
#ifdef HAVE_BAGL
UX_BUTTON_PUSH_EVENT(G_io_seproxyhal_spi_buffer);
Expand All @@ -51,7 +50,7 @@ unsigned char io_event(__Z_UNUSED unsigned char channel) {
THROW(EXCEPTION_IO_RESET);
}

__attribute__((fallthrough));
__attribute__((fallthrough));
case SEPROXYHAL_TAG_DISPLAY_PROCESSED_EVENT:
#ifdef HAVE_BAGL
UX_DISPLAYED_EVENT({});
Expand All @@ -78,7 +77,7 @@ unsigned char io_event(__Z_UNUSED unsigned char channel) {
if (!io_seproxyhal_spi_is_status_sent()) {
io_seproxyhal_general_status();
}
return 1; // DO NOT reset the current APDU transport
return 1; // DO NOT reset the current APDU transport
}

unsigned short io_exchange_al(unsigned char channel, unsigned short tx_len) {
Expand All @@ -94,7 +93,7 @@ unsigned short io_exchange_al(unsigned char channel, unsigned short tx_len) {
if (channel & IO_RESET_AFTER_REPLIED) {
reset();
}
return 0; // nothing received from the master so far (it's a tx
return 0; // nothing received from the master so far (it's a tx
// transaction)
} else {
return io_seproxyhal_spi_recv(G_io_apdu_buffer, sizeof(G_io_apdu_buffer), 0);
Expand Down Expand Up @@ -138,7 +137,7 @@ void app_init() {
#ifdef HAVE_BLE
// grab the current plane mode setting
G_io_app.plane_mode = os_setting_get(OS_SETTING_PLANEMODE, NULL, 0);
#endif // HAVE_BLE
#endif // HAVE_BLE

USB_power(0);
USB_power(1);
Expand All @@ -150,19 +149,18 @@ void app_init() {
view_idle_show(0, NULL);
}
#else
#ifdef SUPPORT_SR25519
#ifdef SUPPORT_SR25519
zeroize_sr25519_signdata();
#endif
#endif
view_idle_show(0, NULL);
#endif // HAVE_SWAP
#endif // POSTPONE_MAIN_SCREEN_INIT
#endif // HAVE_SWAP
#endif // POSTPONE_MAIN_SCREEN_INIT

#ifdef HAVE_BLE
// Enable Bluetooth
BLE_power(0, NULL);
BLE_power(1, NULL);
#endif // HAVE_BLE

#endif // HAVE_BLE
}

void app_main() {
Expand All @@ -185,17 +183,15 @@ void app_main() {
flags = 0;
CHECK_APP_CANARY()

if (rx == 0)
THROW(APDU_CODE_EMPTY_BUFFER);
if (rx == 0) THROW(APDU_CODE_EMPTY_BUFFER);

handle_generic_apdu(&flags, &tx, rx);
CHECK_APP_CANARY()

handleApdu(&flags, &tx, rx);
CHECK_APP_CANARY()
}
CATCH(EXCEPTION_IO_RESET)
{
CATCH(EXCEPTION_IO_RESET) {
// reset IO and UX before continuing
app_init();
continue;
Expand All @@ -216,8 +212,7 @@ void app_main() {
tx += 2;
}
FINALLY;
{
}
{}
}
END_TRY;
}
Expand Down
61 changes: 31 additions & 30 deletions deps/ledger-zxlib/app/common/app_main.h
Original file line number Diff line number Diff line change
@@ -1,45 +1,46 @@
/*******************************************************************************
* (c) 2016 Ledger
* (c) 2018 Zondax GmbH
*
* 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.
********************************************************************************/
* (c) 2016 Ledger
* (c) 2018 - 2024 Zondax AG
*
* 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 <stdbool.h>

#include "apdu_codes.h"

#define OFFSET_CLA 0
#define OFFSET_INS 1 //< Instruction offset
#define OFFSET_P1 2 //< P1
#define OFFSET_P2 3 //< P2
#define OFFSET_DATA_LEN 4 //< Data Length
#define OFFSET_DATA 5 //< Data offset
#define OFFSET_CLA 0
#define OFFSET_INS 1 //< Instruction offset
#define OFFSET_P1 2 //< P1
#define OFFSET_P2 3 //< P2
#define OFFSET_DATA_LEN 4 //< Data Length
#define OFFSET_DATA 5 //< Data offset

#define APDU_MIN_LENGTH 5
#define APDU_MIN_LENGTH 5

#define P1_INIT 0 //< P1
#define P1_ADD 1 //< P1
#define P1_LAST 2 //< P1
#define P1_INIT 0 //< P1
#define P1_ADD 1 //< P1
#define P1_LAST 2 //< P1

#define OFFSET_PAYLOAD_TYPE OFFSET_P1
#define OFFSET_PAYLOAD_TYPE OFFSET_P1

#define INS_GET_VERSION 0x00
#define INS_GET_ADDR 0x01
#define INS_SIGN 0x02
#define INS_GET_VERSION 0x00
#define INS_GET_ADDR 0x01
#define INS_SIGN 0x02

#if defined(APP_TESTING)
#define INS_TEST 0xFF
#define INS_TEST 0xFF
#endif

void app_init();
Expand Down
63 changes: 37 additions & 26 deletions deps/ledger-zxlib/app/ui/view.c
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
/*******************************************************************************
* (c) 2018 - 2022 Zondax AG
* (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.
********************************************************************************/
* (c) 2018 - 2022 Zondax AG
* (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_internal.h"
#include "actions.h"
#include "view_internal.h"
#include "zxmacros.h"

view_t viewdata;
Expand All @@ -43,26 +43,37 @@ void view_init(void) {
#endif
}

void view_idle_show(uint8_t item_idx, const char *statusString) {
view_idle_show_impl(item_idx, statusString);
}
void view_idle_show(uint8_t item_idx, const char *statusString) { view_idle_show_impl(item_idx, statusString); }

void view_message_show(const char *title, const char *message) {
view_message_impl(title, message);
}
void view_message_show(const char *title, const char *message) { view_message_impl(title, message); }

void view_review_init(viewfunc_getItem_t viewfuncGetItem,
viewfunc_getNumItems_t viewfuncGetNumItems,
void view_review_init(viewfunc_getItem_t viewfuncGetItem, viewfunc_getNumItems_t viewfuncGetNumItems,
viewfunc_accept_t viewfuncAccept) {
viewdata.viewfuncGetItem = viewfuncGetItem;
viewdata.viewfuncGetNumItems = viewfuncGetNumItems;
viewdata.viewfuncAccept = viewfuncAccept;

#if defined(TARGET_NANOS) || defined(TARGET_NANOS2) || defined(TARGET_NANOX)
viewdata.with_confirmation = false;
#endif

}

void view_initialize_init(viewfunc_initialize_t viewFuncInit) {
viewdata.viewfuncInitialize = viewFuncInit;
void view_review_init_progressive(
viewfunc_getItem_t viewfuncGetItem,
viewfunc_getNumItems_t viewfuncGetNumItems,
viewfunc_accept_t viewfuncAccept) {

view_review_init(viewfuncGetItem, viewfuncGetNumItems, viewfuncAccept);

#if defined(TARGET_NANOS) || defined(TARGET_NANOS2) || defined(TARGET_NANOX)
viewdata.with_confirmation = true;
#endif

}

void view_initialize_init(viewfunc_initialize_t viewFuncInit) { viewdata.viewfuncInitialize = viewFuncInit; }

void view_review_show(review_type_e reviewKind) {
// Set > 0 to reply apdu message
view_review_show_impl((unsigned int)reviewKind, NULL, NULL);
Expand Down
10 changes: 10 additions & 0 deletions deps/ledger-zxlib/app/ui/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ typedef void (*viewfunc_accept_t)();

typedef zxerr_t (*viewfunc_initialize_t)();

// Callback type for continuation confirmation
typedef void (*viewfunc_confirm_continue_t)(char *outKey, uint16_t outKeyLen, char *outVal, uint16_t outValLen);

typedef enum {
REVIEW_UI = 0,
REVIEW_ADDRESS,
Expand Down Expand Up @@ -111,9 +114,16 @@ void view_error_show();

void view_custom_error_show(const char *upper, const char *lower);

void view_blindsign_error_show();

void view_review_init(viewfunc_getItem_t viewfuncGetItem, viewfunc_getNumItems_t viewfuncGetNumItems,
viewfunc_accept_t viewfuncAccept);

void view_review_init_progressive(
viewfunc_getItem_t viewfuncGetItem,
viewfunc_getNumItems_t viewfuncGetNumItems,
viewfunc_accept_t viewfuncAccept);

void view_inspect_init(viewfunc_getInnerItem_t view_funcGetInnerItem, viewfunc_getNumItems_t view_funcGetInnerNumItems,
viewfunc_canInspectItem_t view_funcCanInspectItem);

Expand Down
Loading

0 comments on commit 9cc3f06

Please sign in to comment.