5#include <mbedtls/include/mbedtls/des.h>
12#define FELICA_IDM_SIZE (8U)
13#define FELICA_PMM_SIZE (8U)
14#define FELICA_DATA_BLOCK_SIZE (16U)
16#define FELICA_CMD_READ_WITHOUT_ENCRYPTION (0x06U)
17#define FELICA_CMD_WRITE_WITHOUT_ENCRYPTION (0x08U)
19#define FELICA_SERVICE_RW_ACCESS (0x0009U)
20#define FELICA_SERVICE_RO_ACCESS (0x000BU)
22#define FELICA_BLOCKS_TOTAL_COUNT (28U)
23#define FELICA_BLOCK_INDEX_REG (0x0EU)
24#define FELICA_BLOCK_INDEX_RC (0x80U)
25#define FELICA_BLOCK_INDEX_MAC (0x81U)
26#define FELICA_BLOCK_INDEX_ID (0x82U)
27#define FELICA_BLOCK_INDEX_D_ID (0x83U)
28#define FELICA_BLOCK_INDEX_SER_C (0x84U)
29#define FELICA_BLOCK_INDEX_SYS_C (0x85U)
30#define FELICA_BLOCK_INDEX_CKV (0x86U)
31#define FELICA_BLOCK_INDEX_CK (0x87U)
32#define FELICA_BLOCK_INDEX_MC (0x88U)
33#define FELICA_BLOCK_INDEX_WCNT (0x90U)
34#define FELICA_BLOCK_INDEX_MAC_A (0x91U)
35#define FELICA_BLOCK_INDEX_STATE (0x92U)
36#define FELICA_BLOCK_INDEX_CRC_CHECK (0xA0U)
38#define FELICA_STANDARD_MAX_BLOCK_COUNT (0xFFU)
40#define FELICA_GUARD_TIME_US (20000U)
41#define FELICA_FDT_POLL_FC (10000U)
42#define FELICA_POLL_POLL_MIN_US (1280U)
44#define FELICA_FDT_LISTEN_FC (0)
46#define FELICA_SYSTEM_CODE_CODE (0xFFFFU)
47#define FELICA_TIME_SLOT_1 (0x00U)
48#define FELICA_TIME_SLOT_2 (0x01U)
49#define FELICA_TIME_SLOT_4 (0x03U)
50#define FELICA_TIME_SLOT_8 (0x07U)
51#define FELICA_TIME_SLOT_16 (0x0FU)
53#define FELICA_CMD_LIST_SERVICE_CODE 0x0A
54#define FELICA_CMD_LIST_SERVICE_CODE_RESP 0x0B
56#define FELICA_SERVICE_ATTRIBUTE_UNAUTH_READ (0b000001)
57#define FELICA_SERVICE_ATTRIBUTE_READ_ONLY (0b000010)
58#define FELICA_SERVICE_ATTRIBUTE_RANDOM_ACCESS (0b001000)
59#define FELICA_SERVICE_ATTRIBUTE_CYCLIC (0b001100)
60#define FELICA_SERVICE_ATTRIBUTE_PURSE (0b010000)
61#define FELICA_SERVICE_ATTRIBUTE_PURSE_SUBFIELD (0b000110)
66 FelicaErrorNotPresent,
67 FelicaErrorColResFailed,
68 FelicaErrorBufferOverflow,
69 FelicaErrorCommunication,
74 FelicaErrorFeatureUnsupported,
84 uint8_t data[FELICA_DATA_BLOCK_SIZE];
89 uint8_t data[FELICA_DATA_BLOCK_SIZE];
113 uint8_t data[FELICA_DATA_BLOCK_SIZE];
127 uint8_t data[FELICA_IDM_SIZE];
132 uint8_t data[FELICA_PMM_SIZE];
140 uint8_t data[FELICA_DATA_BLOCK_SIZE];
181 uint16_t service_code;
189 uint8_t blocks_total;
196 FelicaWorkflowType workflow_type;
203 uint16_t service_code;
209 uint8_t response_code;
224 uint8_t service_code : 4;
225 uint8_t access_mode : 3;
227 uint8_t block_number;
232 uint8_t response_code;
275const uint8_t* felica_get_uid(
const FelicaData* data,
size_t* uid_len);
277bool felica_set_uid(
FelicaData* data,
const uint8_t* uid,
size_t uid_len);
281void felica_calculate_session_key(
282 mbedtls_des3_context* ctx,
287bool felica_check_mac(
288 mbedtls_des3_context* ctx,
289 const uint8_t* session_key,
291 const uint8_t* blocks,
292 const uint8_t block_count,
295void felica_calculate_mac_read(
296 mbedtls_des3_context* ctx,
297 const uint8_t* session_key,
299 const uint8_t* blocks,
300 const uint8_t block_count,
304void felica_calculate_mac_write(
305 mbedtls_des3_context* ctx,
306 const uint8_t* session_key,
314void felica_get_workflow_type(
FelicaData* data);
NfcDeviceNameType
Verbosity level of the displayed NFC device name.
Definition nfc_device_base.h:14
Abstract interface definitions for the NFC device system.
This file provides a simple (non-type safe) array for elements with (optional) in-place construction ...
Definition system/js_app/modules/js_gui/icon.c:36
Struct which controls the process of authentication and can be passed as a parameter to the applicati...
Definition felica.h:102
FelicaAuthenticationStatus auth_status
Authentication status.
Definition felica.h:106
bool skip_auth
By default it is true, so auth is skipped.
Definition felica.h:103
FelicaCardKey card_key
User must fill this field with known card key in order to pass auth.
Definition felica.h:105
Structure used to hold authentication related fields.
Definition felica.h:119
mbedtls_des3_context des_context
Context for mbedtls des functions.
Definition felica.h:120
FelicaAuthenticationContext context
Public auth context provided to upper levels.
Definition felica.h:122
FelicaSessionKey session_key
Calculated session key.
Definition felica.h:121
In Felica there two types of auth.
Definition felica.h:95
Felica block with status flags indicating last operation with it.
Definition felica.h:137
uint8_t SF1
Status flag 1, equals to 0 when success.
Definition felica.h:138
uint8_t SF2
Status flag 2, equals to 0 when success.
Definition felica.h:139
Separate type for card key block.
Definition felica.h:88
Structure used to store Felica data and additional values about reading.
Definition felica.h:186
Felica filesystem structure.
Definition felica.h:144
Felica ID block.
Definition felica.h:126
Felica PMm block.
Definition felica.h:131
Stucture for holding Felica session key which is calculated from rc and ck.
Definition felica.h:112
Generic NFC device interface.
Definition nfc_device_base_i.h:142
Definition simple_array.c:5
Union which represents filesystem in junction with plain data dump.
Definition felica.h:163