Skip to content

Commit

Permalink
Use standard app
Browse files Browse the repository at this point in the history
  • Loading branch information
fbeutin-ledger committed Jun 13, 2024
1 parent c5682e9 commit 9742172
Show file tree
Hide file tree
Showing 22 changed files with 99 additions and 263 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ ENABLE_BLUETOOTH = 1
# These advanced settings allow to disable some feature that are by
# default enabled in the SDK `Makefile.standard_app`.

# Todo at a later date
DISABLE_STANDARD_APP_FILES = 1
# DISABLE_STANDARD_APP_FILES = 1

#DISABLE_DEFAULT_IO_SEPROXY_BUFFER_SIZE = 1 # To allow custom size declaration
#DISABLE_STANDARD_APP_DEFINES = 1 # Will set all the following disablers
Expand Down
2 changes: 1 addition & 1 deletion src/apdu_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ static uint16_t check_instruction(uint8_t instruction, uint8_t subcommand) {
}

// Return 0 if we can proceed with this APDU, return a status code if we can not
uint16_t apdu_parser(uint8_t *apdu, size_t apdu_length, command_t *command) {
uint16_t check_apdu_validity(uint8_t *apdu, size_t apdu_length, command_t *command) {
if (apdu_length < OFFSET_CDATA) {
PRINTF("Error: malformed APDU, length is too short %d\n", apdu_length);
return MALFORMED_APDU;
Expand Down
2 changes: 1 addition & 1 deletion src/apdu_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

#include "commands.h"

uint16_t apdu_parser(uint8_t *apdu, size_t apdu_length, command_t *command);
uint16_t check_apdu_validity(uint8_t *apdu, size_t apdu_length, command_t *command);
2 changes: 1 addition & 1 deletion src/buffer.c → src/buf.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "buffer.h"
#include "buf.h"
#include "os.h"

// Parse a buffer at a given offset to read a buf_t, the offset is incremented accordingly
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/check_addresses_and_amounts.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "swap_errors.h"
#include "globals.h"
#include "currency_lib_calls.h"
#include "io.h"
#include "io_helpers.h"
#include "parse_check_address_message.h"
#include "parse_coin_config.h"
#include "printable_amount.h"
Expand Down
2 changes: 1 addition & 1 deletion src/check_partner.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "check_partner.h"
#include "globals.h"
#include "swap_errors.h"
#include "io.h"
#include "io_helpers.h"

// This function receive signature of
// Input should be in the form of DER serialized signature
Expand Down
2 changes: 1 addition & 1 deletion src/check_tx_signature.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "check_tx_signature.h"
#include "globals.h"
#include "swap_errors.h"
#include "io.h"
#include "io_helpers.h"
#include "der.h"

// One int (r or s) in DER is (1 byte prefix + 1 byte r/s length + r/s + 1 optional ending byte)
Expand Down
2 changes: 1 addition & 1 deletion src/commands.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "buffer.h"
#include "buf.h"

// CLA to use when communicating with Exchange
#define CLA 0xE0
Expand Down
14 changes: 10 additions & 4 deletions src/get_version_handler.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
#include "get_version_handler.h"
#include "swap_errors.h"
#include "buffer.h"
#include "io.h"

int get_version_handler(void) {
unsigned char output_buffer[5];
unsigned char output_buffer[3];
output_buffer[0] = MAJOR_VERSION;
output_buffer[1] = MINOR_VERSION;
output_buffer[2] = PATCH_VERSION;
output_buffer[3] = 0x90;
output_buffer[4] = 0x00;
if (send_apdu(output_buffer, 5) < 0) {

buffer_t output;
output.ptr = output_buffer;
output.size = 3;
output.offset = 0;

if (io_send_response_buffers(&output, 1, SUCCESS) < 0) {
return -1;
}
return 0;
Expand Down
191 changes: 0 additions & 191 deletions src/io.c

This file was deleted.

34 changes: 0 additions & 34 deletions src/io.h

This file was deleted.

44 changes: 44 additions & 0 deletions src/io_helpers.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*****************************************************************************
* Ledger App Exchange.
* (c) 2024 Ledger SAS.
*
* 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 <stdint.h>
#include <string.h>

#include "os.h"
#include "ux.h"
#include "globals.h"
#include "io.h"
#include "io_helpers.h"
#include "swap_errors.h"

int reply_error(swap_error_e error) {
return io_send_response_buffers(NULL, 0, error);
}

int instant_reply_error(swap_error_e error) {
G_io_apdu_buffer[0] = (error >> 8) & 0xFF;
G_io_apdu_buffer[1] = error & 0xFF;
return io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, 2);
}

int reply_success(void) {
return reply_error(SUCCESS);
}

int instant_reply_success(void) {
return instant_reply_error(SUCCESS);
}
13 changes: 13 additions & 0 deletions src/io_helpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <stdint.h>

#include "ux.h"
#include "os_io_seproxyhal.h"
#include "swap_errors.h"

int reply_error(swap_error_e error);
int instant_reply_error(swap_error_e error);

int reply_success(void);
int instant_reply_success(void);
Loading

0 comments on commit 9742172

Please sign in to comment.