-
-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* New types for felica poller * New functions for felica data transmissions * Felica memory map extended with new fields * Init/deinit of mbedtls context added for felica encryption * Functions for session key and mac calculations added * Raw felica_poller implementation added * Removed MAC type parameter from check_mac function * Replaced all data fields needed for auth with context structure * Clean up felica_poller.c * Now RC block is filled with random numbers * New parameter for counting well-read blocks * Some cleanups * Felica file save and load logic added * Now we use card key from context for session key calculation * Copying card key to card block from auth context when both authentications succeeded, otherwise decrement blocks count by 1 * New felica poller event added * Moved some data structions to public namespace * FelicaAuthenticationContext struct moved to felica.h * Field type and name changed for better ones * Helper functions for felica_auth added to the app * New scene for felica card key input added * Logic for felica key input added * Auth context request processing added * Added block index definitions and replaced all index numbers with them * More macro defines * Replace nesting with do while block * New function for write operations mac calculation added * Replace nesting with do while block * Make functions static for now because they are used internally * Wrote some comments * Raw felica render implementation * New felica scenes * Adjusted felica dump rendering according design requirements * New felica scene added * Helper for switching scene during unlock added * Added warning scene and transfer to it * Moved unlock scene logic to separate files * Magic number changed * New felica render logic * Felica scenes adjusted according to design requirements * Felica poller cleanups * Some asserts added and some fixed * Replcaed asserts to checks in public api * Fixed pvs warnings in felica_poller * New event for felica_poller added for incomplete read actions * Handling of new poller event added * Update SConscript with felica files * Update api_symbols.csv with felica functions * Sync API versions Co-authored-by: あく <[email protected]>
- Loading branch information
1 parent
db14ca9
commit fb9728d
Showing
22 changed files
with
1,185 additions
and
84 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include "felica_auth.h" | ||
|
||
FelicaAuthenticationContext* felica_auth_alloc() { | ||
FelicaAuthenticationContext* instance = malloc(sizeof(FelicaAuthenticationContext)); | ||
memset(instance->card_key.data, 0, FELICA_DATA_BLOCK_SIZE); | ||
instance->skip_auth = true; | ||
return instance; | ||
} | ||
|
||
void felica_auth_free(FelicaAuthenticationContext* instance) { | ||
furi_assert(instance); | ||
free(instance); | ||
} | ||
|
||
void felica_auth_reset(FelicaAuthenticationContext* instance) { | ||
furi_assert(instance); | ||
memset(instance->card_key.data, 0, FELICA_DATA_BLOCK_SIZE); | ||
instance->skip_auth = true; | ||
instance->auth_status.external = 0; | ||
instance->auth_status.internal = 0; | ||
} |
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,17 @@ | ||
#pragma once | ||
|
||
#include <lib/nfc/protocols/felica/felica.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
FelicaAuthenticationContext* felica_auth_alloc(); | ||
|
||
void felica_auth_free(FelicaAuthenticationContext* instance); | ||
|
||
void felica_auth_reset(FelicaAuthenticationContext* instance); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
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
98 changes: 93 additions & 5 deletions
98
applications/main/nfc/helpers/protocol_support/felica/felica_render.c
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 |
---|---|---|
@@ -1,19 +1,107 @@ | ||
#include "felica_render.h" | ||
|
||
void nfc_render_felica_info( | ||
void nfc_render_felica_blocks_count( | ||
const FelicaData* data, | ||
FuriString* str, | ||
bool render_auth_notification) { | ||
furi_string_cat_printf(str, "\nBlocks Read: %u/%u", data->blocks_read, data->blocks_total); | ||
if(render_auth_notification && data->blocks_read != data->blocks_total) { | ||
furi_string_cat_printf(str, "\nAuth-protected blocks!"); | ||
} | ||
} | ||
|
||
void nfc_render_felica_idm( | ||
const FelicaData* data, | ||
NfcProtocolFormatType format_type, | ||
FuriString* str) { | ||
furi_string_cat_printf(str, "IDm:"); | ||
furi_string_cat_printf(str, (format_type == NfcProtocolFormatTypeFull) ? "IDm:\n" : "IDm:"); | ||
|
||
for(size_t i = 0; i < FELICA_IDM_SIZE; i++) { | ||
furi_string_cat_printf(str, " %02X", data->idm.data[i]); | ||
furi_string_cat_printf( | ||
str, | ||
(format_type == NfcProtocolFormatTypeFull) ? "%02X " : " %02X", | ||
data->idm.data[i]); | ||
} | ||
} | ||
|
||
void nfc_render_felica_info( | ||
const FelicaData* data, | ||
NfcProtocolFormatType format_type, | ||
FuriString* str) { | ||
if(format_type == NfcProtocolFormatTypeFull) { | ||
furi_string_cat_printf(str, "Tech: JIS X 6319-4,\nISO 18092 [NFC-F]\n"); | ||
} | ||
|
||
nfc_render_felica_idm(data, format_type, str); | ||
|
||
if(format_type == NfcProtocolFormatTypeFull) { | ||
furi_string_cat_printf(str, "\nPMm:"); | ||
furi_string_cat_printf(str, "\nPMm:\n"); | ||
for(size_t i = 0; i < FELICA_PMM_SIZE; ++i) { | ||
furi_string_cat_printf(str, " %02X", data->pmm.data[i]); | ||
furi_string_cat_printf(str, "%02X ", data->pmm.data[i]); | ||
} | ||
} | ||
nfc_render_felica_blocks_count(data, str, true); | ||
} | ||
|
||
static void nfc_render_felica_block_name( | ||
const char* name, | ||
FuriString* str, | ||
uint8_t prefix_separator_cnt, | ||
uint8_t suffix_separator_cnt) { | ||
for(uint8_t i = 0; i < prefix_separator_cnt; i++) { | ||
furi_string_cat_printf(str, ":"); | ||
} | ||
furi_string_cat_printf(str, "[ %s ]", name); | ||
for(uint8_t i = 0; i < suffix_separator_cnt; i++) { | ||
furi_string_cat_printf(str, ":"); | ||
} | ||
} | ||
|
||
static void nfc_render_felica_block_data(const FelicaBlock* block, FuriString* str) { | ||
furi_string_cat_printf(str, "\nSF1=%02X; SF2=%02X\n", block->SF1, block->SF2); | ||
for(size_t j = 0; j < FELICA_DATA_BLOCK_SIZE; j++) { | ||
if((j != 0) && (j % 8 == 0)) furi_string_cat_printf(str, "\n"); | ||
furi_string_cat_printf(str, "%02X ", block->data[j]); | ||
} | ||
furi_string_cat_printf(str, "\n"); | ||
} | ||
|
||
static void nfc_render_felica_block( | ||
const FelicaBlock* block, | ||
FuriString* str, | ||
const char* name, | ||
uint8_t prefix_separator_cnt, | ||
uint8_t suffix_separator_cnt) { | ||
nfc_render_felica_block_name(name, str, prefix_separator_cnt, suffix_separator_cnt); | ||
nfc_render_felica_block_data(block, str); | ||
} | ||
|
||
void nfc_render_felica_dump(const FelicaData* data, FuriString* str) { | ||
FuriString* name = furi_string_alloc(); | ||
for(size_t i = 0; i < 14; i++) { | ||
furi_string_printf(name, "S_PAD%d", i); | ||
uint8_t suf_cnt = 18; | ||
if(i == 1) { | ||
suf_cnt = 19; | ||
} else if((i == 10) || (i == 12) || (i == 13)) { | ||
suf_cnt = 16; | ||
} | ||
nfc_render_felica_block( | ||
&data->data.fs.spad[i], str, furi_string_get_cstr(name), 20, suf_cnt); | ||
} | ||
furi_string_free(name); | ||
nfc_render_felica_block(&data->data.fs.reg, str, "REG", 23, 23); | ||
nfc_render_felica_block(&data->data.fs.rc, str, "RC", 25, 25); | ||
nfc_render_felica_block(&data->data.fs.mac, str, "MAC", 23, 23); | ||
nfc_render_felica_block(&data->data.fs.id, str, "ID", 25, 25); | ||
nfc_render_felica_block(&data->data.fs.d_id, str, "D_ID", 22, 24); | ||
nfc_render_felica_block(&data->data.fs.ser_c, str, "SER_C", 20, 21); | ||
nfc_render_felica_block(&data->data.fs.sys_c, str, "SYS_C", 20, 21); | ||
nfc_render_felica_block(&data->data.fs.ckv, str, "CKV", 23, 23); | ||
nfc_render_felica_block(&data->data.fs.ck, str, "CK", 25, 25); | ||
nfc_render_felica_block(&data->data.fs.mc, str, "MC", 25, 24); | ||
nfc_render_felica_block(&data->data.fs.wcnt, str, "WCNT", 22, 20); | ||
nfc_render_felica_block(&data->data.fs.mac_a, str, "MAC_A", 20, 20); | ||
nfc_render_felica_block(&data->data.fs.state, str, "STATE", 20, 21); | ||
nfc_render_felica_block(&data->data.fs.crc_check, str, "CRC_CHCK", 15, 17); | ||
} |
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
Oops, something went wrong.