Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FL-3772] Felica poller #3570

Merged
merged 56 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
c996d37
New types for felica poller
RebornedBrain Mar 6, 2024
1bc7dd2
New functions for felica data transmissions
RebornedBrain Mar 6, 2024
4cd06ba
Felica memory map extended with new fields
RebornedBrain Mar 6, 2024
da65c61
Init/deinit of mbedtls context added for felica encryption
RebornedBrain Mar 6, 2024
24b610f
Functions for session key and mac calculations added
RebornedBrain Mar 13, 2024
a87e5ee
Raw felica_poller implementation added
RebornedBrain Mar 13, 2024
5439e47
Removed MAC type parameter from check_mac function
RebornedBrain Mar 13, 2024
3a7b15b
Replaced all data fields needed for auth with context structure
RebornedBrain Mar 13, 2024
0d1feaa
Clean up felica_poller.c
RebornedBrain Mar 13, 2024
bfb1c36
Now RC block is filled with random numbers
RebornedBrain Mar 14, 2024
ea67ae8
New parameter for counting well-read blocks
RebornedBrain Mar 14, 2024
086edf3
Some cleanups
RebornedBrain Mar 14, 2024
7deafef
Felica file save and load logic added
RebornedBrain Mar 21, 2024
ee09661
Now we use card key from context for session key calculation
RebornedBrain Mar 21, 2024
d3c3ac8
Copying card key to card block from auth context when both authentica…
RebornedBrain Mar 21, 2024
69faee8
New felica poller event added
RebornedBrain Mar 21, 2024
d4c778d
Moved some data structions to public namespace
RebornedBrain Mar 21, 2024
69264bb
FelicaAuthenticationContext struct moved to felica.h
RebornedBrain Mar 21, 2024
1c7ae8e
Field type and name changed for better ones
RebornedBrain Mar 21, 2024
504f2eb
Helper functions for felica_auth added to the app
RebornedBrain Mar 21, 2024
e188a53
New scene for felica card key input added
RebornedBrain Mar 21, 2024
d830aab
Logic for felica key input added
RebornedBrain Mar 21, 2024
20f1c88
Auth context request processing added
RebornedBrain Mar 21, 2024
37a9fa1
Added block index definitions and replaced all index numbers with them
RebornedBrain Mar 21, 2024
6d193e9
More macro defines
RebornedBrain Mar 21, 2024
1ba4a6b
Replace nesting with do while block
RebornedBrain Mar 21, 2024
73693f5
New function for write operations mac calculation added
RebornedBrain Mar 21, 2024
ad8a0ac
Replace nesting with do while block
RebornedBrain Mar 21, 2024
2f246f4
Make functions static for now because they are used internally
RebornedBrain Mar 22, 2024
e4a65bf
Wrote some comments
RebornedBrain Mar 22, 2024
c367de1
Raw felica render implementation
RebornedBrain Mar 25, 2024
5dc07dc
New felica scenes
RebornedBrain Mar 29, 2024
3d38bfc
Adjusted felica dump rendering according design requirements
RebornedBrain Mar 29, 2024
559a1de
New felica scene added
RebornedBrain Apr 2, 2024
75b7016
Helper for switching scene during unlock added
RebornedBrain Apr 2, 2024
ad3392f
Added warning scene and transfer to it
RebornedBrain Apr 3, 2024
526badf
Moved unlock scene logic to separate files
RebornedBrain Apr 3, 2024
0ad7aec
Magic number changed
RebornedBrain Apr 3, 2024
6b01895
New felica render logic
RebornedBrain Apr 3, 2024
6fac089
Felica scenes adjusted according to design requirements
RebornedBrain Apr 3, 2024
82f49c6
Merge branch 'dev'
RebornedBrain Apr 4, 2024
da0f818
Felica poller cleanups
RebornedBrain Apr 5, 2024
517aec8
Merge branch 'dev'
RebornedBrain Apr 5, 2024
fec8dcf
Merge branch 'dev' into reborned/felica_poller
skotopes Apr 7, 2024
534e902
Some asserts added and some fixed
RebornedBrain Apr 8, 2024
c37245f
Merge branch 'dev' into reborned/felica_poller
skotopes Apr 9, 2024
a8f743c
Replcaed asserts to checks in public api
RebornedBrain Apr 9, 2024
96d5d33
Merge branch 'dev' into reborned/felica_poller
skotopes Apr 9, 2024
bed5a8e
Fixed pvs warnings in felica_poller
RebornedBrain Apr 9, 2024
a61de97
Merge branch 'reborned/felica_poller' of git@github.com:RebornedBrain…
RebornedBrain Apr 9, 2024
b61abb9
Merge branch 'dev' into reborned/felica_poller
skotopes Apr 9, 2024
759cc82
New event for felica_poller added for incomplete read actions
RebornedBrain Apr 9, 2024
4ec511a
Handling of new poller event added
RebornedBrain Apr 9, 2024
b65a76a
Update SConscript with felica files
RebornedBrain Apr 9, 2024
4145bcb
Update api_symbols.csv with felica functions
RebornedBrain Apr 9, 2024
7b26ab1
Sync API versions
skotopes Apr 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added block index definitions and replaced all index numbers with them
  • Loading branch information
RebornedBrain committed Mar 21, 2024
commit 37a9fa13a19b6dbb0204187ec730f3af1c4567ab
15 changes: 15 additions & 0 deletions lib/nfc/protocols/felica/felica.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@ extern "C" {
#define FELICA_PMM_SIZE (8U)
#define FELICA_DATA_BLOCK_SIZE (16U)

#define FELICA_BLOCK_INDEX_REG (0x0EU)
#define FELICA_BLOCK_INDEX_RC (0x80U)
#define FELICA_BLOCK_INDEX_MAC (0x81U)
#define FELICA_BLOCK_INDEX_ID (0x82U)
#define FELICA_BLOCK_INDEX_D_ID (0x83U)
#define FELICA_BLOCK_INDEX_SER_C (0x84U)
#define FELICA_BLOCK_INDEX_SYS_C (0x85U)
#define FELICA_BLOCK_INDEX_CKV (0x86U)
#define FELICA_BLOCK_INDEX_CK (0x87U)
#define FELICA_BLOCK_INDEX_MC (0x88U)
#define FELICA_BLOCK_INDEX_WCNT (0x90U)
#define FELICA_BLOCK_INDEX_MAC_A (0x91U)
#define FELICA_BLOCK_INDEX_STATE (0x92U)
#define FELICA_BLOCK_INDEX_CRC_CHECK (0xA0U)

#define FELICA_GUARD_TIME_US (20000U)
#define FELICA_FDT_POLL_FC (10000U)
#define FELICA_POLL_POLL_MIN_US (1280U)
Expand Down
28 changes: 14 additions & 14 deletions lib/nfc/protocols/felica/felica_poller.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,17 @@ NfcCommand felica_poller_state_handler_auth_internal(FelicaPoller* instance) {

instance->state = FelicaPollerStateReadBlocks;

uint8_t blocks[3] = {0x80};
uint8_t blocks[3] = {FELICA_BLOCK_INDEX_RC};
FelicaPollerWriteCommandResponse* response;
FelicaError error = felica_poller_write_blocks(
instance, 1, blocks, instance->data->data.fs.rc.data, &response);
///TODO: Think of reworking this part into do{}while in order to reduce nesting
if(error == FelicaErrorNone && response->SF1 == 0 && response->SF2 == 0) {
///TODO: replace all block numbers to defines
///and place them in felica.h
blocks[0] = 0x82;
blocks[1] = 0x90;
blocks[2] = 0x91;
blocks[0] = FELICA_BLOCK_INDEX_ID;
blocks[1] = FELICA_BLOCK_INDEX_WCNT;
blocks[2] = FELICA_BLOCK_INDEX_MAC_A;
FelicaPollerReadCommandResponse* new_resp;
error = felica_poller_read_blocks(instance, sizeof(blocks), blocks, &new_resp);
if(error == FelicaErrorNone && new_resp->SF1 == 0 && new_resp->SF2 == 0) {
Expand Down Expand Up @@ -155,7 +155,7 @@ NfcCommand felica_poller_state_handler_auth_external(FelicaPoller* instance) {
///called felica_calculate_mac_write() where all the logic written below
///will be placed. In such case felica_calculate_mac can be possibly made static
memcpy(WCNT_data, instance->data->data.fs.wcnt.data, 3);
WCNT_data[3] = 0x92;
WCNT_data[3] = FELICA_BLOCK_INDEX_STATE;
felica_prepare_first_block(FelicaMACTypeWrite, WCNT_data, 3, first_block);

instance->data->data.fs.state.data[0] = 1;
Expand All @@ -178,13 +178,13 @@ NfcCommand felica_poller_state_handler_auth_external(FelicaPoller* instance) {
memcpy(tx_data, instance->data->data.fs.state.data, 16);
memcpy(tx_data + 16, instance->data->data.fs.mac_a.data, 16);

WCNT_data[0] = 0x92;
WCNT_data[1] = 0x91;
WCNT_data[0] = FELICA_BLOCK_INDEX_STATE;
WCNT_data[1] = FELICA_BLOCK_INDEX_MAC_A;
FelicaPollerWriteCommandResponse* response;
FelicaError error = felica_poller_write_blocks(instance, 2, WCNT_data, tx_data, &response);

if(error == FelicaErrorNone && response->SF1 == 0 && response->SF2 == 0) {
WCNT_data[0] = 0x92;
WCNT_data[0] = FELICA_BLOCK_INDEX_STATE;
FelicaPollerReadCommandResponse* resp;
error = felica_poller_read_blocks(instance, 1, WCNT_data, &resp);
if(error == FelicaErrorNone && resp->SF1 == 0 && resp->SF2 == 0) {
Expand All @@ -206,12 +206,12 @@ NfcCommand felica_poller_state_handler_read_blocks(FelicaPoller* instance) {
block_list[0] = instance->block_index;

instance->block_index++;
if(instance->block_index == 0x0F) {
instance->block_index = 0x80;
} else if(instance->block_index == 0x89) {
instance->block_index = 0x90;
} else if(instance->block_index == 0x93) {
instance->block_index = 0xA0;
if(instance->block_index == FELICA_BLOCK_INDEX_REG + 1) {
instance->block_index = FELICA_BLOCK_INDEX_RC;
} else if(instance->block_index == FELICA_BLOCK_INDEX_MC + 1) {
instance->block_index = FELICA_BLOCK_INDEX_WCNT;
} else if(instance->block_index == FELICA_BLOCK_INDEX_STATE + 1) {
instance->block_index = FELICA_BLOCK_INDEX_CRC_CHECK;
}

FelicaPollerReadCommandResponse* response;
Expand Down