Skip to content

Commit

Permalink
Disable all penumbre api for nanos
Browse files Browse the repository at this point in the history
  • Loading branch information
neithanmo committed Nov 22, 2024
1 parent a9e804a commit ec1eed1
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions app/src/apdu_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ __Z_INLINE void handle_getversion(__Z_UNUSED volatile uint32_t *flags, volatile
void handleTest(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) { THROW(APDU_CODE_OK); }
#endif

#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) || defined(TARGET_FLEX)
void handleApdu(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) {
zemu_log("handleApdu\n");
volatile uint16_t sw = 0;
Expand Down Expand Up @@ -289,3 +290,56 @@ void handleApdu(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) {
}
END_TRY;
}
#elif defined(TARGET_NANOS)
void handleApdu(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) {
zemu_log("handleApdu\n");
volatile uint16_t sw = 0;

BEGIN_TRY {
TRY {
if (G_io_apdu_buffer[OFFSET_CLA] != CLA) {
zemu_log("CLA not supported\n");
THROW(APDU_CODE_CLA_NOT_SUPPORTED);
}

if (rx < APDU_MIN_LENGTH) {
THROW(APDU_CODE_WRONG_LENGTH);
}

switch (G_io_apdu_buffer[OFFSET_INS]) {
case INS_GET_VERSION: {
handle_getversion(flags, tx);
break;
}
#if defined(APP_TESTING)
case INS_TEST: {
handleTest(flags, tx, rx);
THROW(APDU_CODE_OK);
break;
}
#endif
default:
zemu_log("ins_not_supported**\n");
THROW(APDU_CODE_INS_NOT_SUPPORTED);
}

Check notice

Code scanning / CodeQL

No trivial switch statements Note

This switch statement should either handle more cases, or be rewritten as an if statement.
}
CATCH(EXCEPTION_IO_RESET) { THROW(EXCEPTION_IO_RESET); }
CATCH_OTHER(e) {
switch (e & 0xF000) {
case 0x6000:
case APDU_CODE_OK:
sw = e;
break;
default:
sw = 0x6800 | (e & 0x7FF);
break;
}
G_io_apdu_buffer[*tx] = sw >> 8;
G_io_apdu_buffer[*tx + 1] = sw & 0xFF;
*tx += 2;
}
FINALLY {}
}
END_TRY;
}
#endif

0 comments on commit ec1eed1

Please sign in to comment.