-
Notifications
You must be signed in to change notification settings - Fork 11
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
300 changed files
with
381 additions
and
1,591 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,92 @@ | ||
/***************************************************************************** | ||
* Ledger App Boilerplate. | ||
* (c) 2020 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> // uint*_t | ||
#include <string.h> // memset, explicit_bzero | ||
#include <stdbool.h> | ||
|
||
#include "os.h" | ||
#include "ux.h" | ||
|
||
#include "types.h" | ||
#include "globals.h" | ||
#include "io.h" | ||
#include "sw.h" | ||
#include "ui/menu.h" | ||
#include "parser.h" | ||
#include "apdu/dispatcher.h" | ||
|
||
global_ctx_t G_context; | ||
|
||
const internalStorage_t N_storage_real; | ||
|
||
void nv_init() { | ||
if (!N_storage.initialized) { | ||
internalStorage_t storage; | ||
storage.initialized = true; | ||
storage.blind_signing_enabled = false; | ||
storage.expert_mode = false; | ||
nvm_write((void *) &N_storage, (void *) &storage, sizeof(internalStorage_t)); | ||
} | ||
} | ||
|
||
/** | ||
* Handle APDU command received and send back APDU response using handlers. | ||
*/ | ||
void app_main() { | ||
// Length of APDU command received in G_io_apdu_buffer | ||
int input_len = 0; | ||
// Structured APDU command | ||
command_t cmd; | ||
|
||
io_init(); | ||
|
||
ui_menu_main(); | ||
|
||
// Reset context | ||
explicit_bzero(&G_context, sizeof(G_context)); | ||
|
||
nv_init(); | ||
|
||
for (;;) { | ||
// Receive command bytes in G_io_apdu_buffer | ||
if ((input_len = io_recv_command()) < 0) { | ||
return; | ||
} | ||
|
||
// Parse APDU command from G_io_apdu_buffer | ||
if (!apdu_parser(&cmd, G_io_apdu_buffer, input_len)) { | ||
PRINTF("=> /!\\ BAD LENGTH: %.*H\n", input_len, G_io_apdu_buffer); | ||
io_send_sw(SW_WRONG_DATA_LENGTH); | ||
continue; | ||
} | ||
|
||
PRINTF("=> CLA=%02X | INS=%02X | P1=%02X | P2=%02X | Lc=%02X | CData=%.*H\n", | ||
cmd.cla, | ||
cmd.ins, | ||
cmd.p1, | ||
cmd.p2, | ||
cmd.lc, | ||
cmd.lc, | ||
cmd.data); | ||
|
||
// Dispatch structured APDU command to handler | ||
if (apdu_dispatcher(&cmd) < 0) { | ||
return; | ||
} | ||
} | ||
} |
Oops, something went wrong.