Skip to content

Commit

Permalink
UI changes for compatibility with decoupling changes to Signer
Browse files Browse the repository at this point in the history
- Renamed UI communication module to avoid name clashing with HAL
- Changed platform define in Makefile
  • Loading branch information
amendelzon committed May 21, 2024
1 parent 2083aa5 commit a10ea6a
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 18 deletions.
1 change: 1 addition & 0 deletions ledger/src/ui/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ CFLAGS += -fdata-sections -ffunction-sections -funsigned-char -fshort-enums
CFLAGS += -mno-unaligned-access
CFLAGS += -Wno-unused-parameter -Wno-duplicate-decl-specifier
CFLAGS += -Werror
CFLAGS += -DHSM_PLATFORM_LEDGER
ifeq ($(DEBUG_BUILD),1)
CFLAGS += -DDEBUG_BUILD=${DEBUG_BUILD}
endif
Expand Down
4 changes: 2 additions & 2 deletions ledger/src/ui/src/bootloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "ui_instructions.h"
#include "defs.h"
#include "ui_err.h"
#include "communication.h"
#include "ui_comm.h"
#include "unlock.h"

// Attestation context shorthand
Expand Down Expand Up @@ -206,7 +206,7 @@ void bootloader_main(bootloader_mode_t mode) {
break;
}
CATCH_OTHER(e) {
tx = comm_process_exception(e, tx, &reset_state);
tx = ui_process_exception(e, tx, &reset_state);
}
FINALLY {
}
Expand Down
36 changes: 36 additions & 0 deletions ledger/src/ui/src/common_requirements.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2021 RSK Labs Ltd
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/

#ifndef __COMMON_REQUIREMENTS_H
#define __COMMON_REQUIREMENTS_H

#include <string.h>

#include "os.h"

#define communication_get_msg_buffer() (G_io_apdu_buffer)
#define communication_get_msg_buffer_size() (sizeof(G_io_apdu_buffer))
#define platform_memmove(...) os_memmove(__VA_ARGS__)

#endif // __COMMON_REQUIREMENTS_H
1 change: 0 additions & 1 deletion ledger/src/ui/src/signer_authorization_status.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
* IN THE SOFTWARE.
*/

#include "os.h"
#include "signer_authorization_status.h"
#include "runtime.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
* IN THE SOFTWARE.
*/

#include "os.h"
#include "runtime.h"
#include "apdu.h"
#include "communication.h"
#include "ui_comm.h"
#include "modes.h"

/**
Expand Down Expand Up @@ -88,13 +88,13 @@ unsigned int get_retries() {
* @arg[in] comm_reset_cb callback to reset the state
* @returns the resulting APDU buffer size
*/
unsigned int comm_process_exception(unsigned short ex,
unsigned int ui_process_exception(unsigned short ex,
unsigned int tx,
comm_reset_cb_t comm_reset_cb) {
unsigned short sw = 0;

// Reset the state in case of an error
if (ex != APDU_OK || tx + 2 > sizeof(G_io_apdu_buffer)) {
if (ex != APDU_OK || tx + 2 > APDU_TOTAL_SIZE) {
comm_reset_cb();
}

Expand All @@ -110,7 +110,7 @@ unsigned int comm_process_exception(unsigned short ex,

// Unexpected exception => report
// (check for a potential overflow first)
if (tx + 2 > sizeof(G_io_apdu_buffer)) {
if (tx + 2 > APDU_TOTAL_SIZE) {
tx = 0;
sw = 0x6983;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
* IN THE SOFTWARE.
*/

#ifndef __COMMUNICATION_H
#define __COMMUNICATION_H
#ifndef __UI_COMM_H
#define __UI_COMM_H

#include <stdbool.h>

Expand Down Expand Up @@ -79,8 +79,8 @@ unsigned int get_retries();
* @arg[in] comm_reset_cb callback to reset the state
* @returns the resulting APDU buffer size
*/
unsigned int comm_process_exception(unsigned short ex,
unsigned int ui_process_exception(unsigned short ex,
unsigned int tx,
comm_reset_cb_t comm_reset_cb);

#endif // __COMMUNICATION_H
#endif // __UI_COMM_H
5 changes: 3 additions & 2 deletions ledger/src/ui/src/ui_heartbeat.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@

#include <string.h>

#include "runtime.h"
#include "ui_heartbeat.h"
#include "apdu.h"
#include "ui_instructions.h"
#include "ints.h"
#include "ui_err.h"
#include "communication.h"
#include "ui_comm.h"
#include "memutil.h"
#include "compiletime.h"
#include "signer_authorization_status.h"
Expand Down Expand Up @@ -253,7 +254,7 @@ void ui_heartbeat_main(ui_heartbeat_t *ui_heartbeat_ctx) {
}
CATCH_OTHER(e) {
current_context = ui_heartbeat_ctx;
tx = comm_process_exception(e, tx, &reset_state);
tx = ui_process_exception(e, tx, &reset_state);
}
FINALLY {
}
Expand Down
4 changes: 2 additions & 2 deletions ledger/src/ui/test/bootloader/test_bootloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "modes.h"
#include "ui_err.h"
#include "bootloader_mock.h"
#include "communication.h"
#include "ui_comm.h"

// Mock variables needed for bootloader module
bolos_ux_context_t G_bolos_ux_context;
Expand Down Expand Up @@ -176,7 +176,7 @@ unsigned short io_exchange(unsigned char channel, unsigned short tx_len) {
return 0;
}

unsigned int comm_process_exception(unsigned short ex,
unsigned int ui_process_exception(unsigned short ex,
unsigned int tx,
comm_reset_cb_t comm_reset_cb) {
return 0;
Expand Down
2 changes: 1 addition & 1 deletion ledger/src/ui/test/communication/test_communication.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "assert_utils.h"
#include "defs.h"
#include "mock.h"
#include "communication.h"
#include "ui_comm.h"

static unsigned int G_retries;

Expand Down
2 changes: 1 addition & 1 deletion ledger/src/ui/test/ui_heartbeat/test_ui_heartbeat.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "bolos_ux.h"
#include "ui_heartbeat.h"
#include "signer_authorization.h"
#include "communication.h"
#include "ui_comm.h"
#include "apdu_utils.h"
#include "assert_utils.h"
#include "ui_err.h"
Expand Down

0 comments on commit a10ea6a

Please sign in to comment.