Skip to content

Commit

Permalink
Merge pull request #5 from LedgerHQ/y333/fix_legacy_support
Browse files Browse the repository at this point in the history
Handle GET_OPERATION_MODE apdu
  • Loading branch information
yogh333 authored Jun 12, 2024
2 parents b36ec9c + df1d5d6 commit 40fded7
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions apdu/apdu_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#define INS_SIGN_MESSAGE 0x4E
#define INS_GET_FIRMWARE_VERSION 0xC4
#define INS_GET_COIN_VER 0x16
#define INS_GET_OPERATION_MODE 0x24

#define SW_INCORRECT_LENGTH 0x6700
#define SW_SECURITY_STATUS_NOT_SATISFIED 0x6982
Expand Down Expand Up @@ -61,3 +62,4 @@ unsigned short handler_get_trusted_input(buffer_t *buffer, uint8_t p1,
uint8_t p2);
unsigned short handler_get_firmware_version(void);
unsigned short handler_get_coin_version(void);
unsigned short handler_get_operation_mode(void);
5 changes: 5 additions & 0 deletions apdu/dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ int apdu_dispatcher(const command_t *cmd) {

return handler_get_coin_version();

case INS_GET_OPERATION_MODE:
PRINTF("Get operation mode\n");

return handler_get_operation_mode();

default:
PRINTF("Instruction not supported\n");
return io_send_sw(SW_INS_NOT_SUPPORTED);
Expand Down
38 changes: 38 additions & 0 deletions handler/get_operation_mode.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*******************************************************************************
* Ledger App - Bitcoin Wallet
* (c) 2016-2019 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 "io.h"

#include "apdu_constants.h"
#include "context.h"

#define MODE_WALLET 0x01

/*
* Function: handler_get_firmware_versi
* ---------------------------------------
* Retrieves the firmware version information.
*
* Returns:
* - -1 if the operation is unsuccessful.
*/
WEAK unsigned short handler_get_operation_mode() {

G_io_apdu_buffer[0] = MODE_WALLET;
context.outLength = 0x01;

return io_send_response_pointer(G_io_apdu_buffer, context.outLength, SW_OK);
}

0 comments on commit 40fded7

Please sign in to comment.