M5Unit-NFC 0.1.0 git rev:93745b5
Loading...
Searching...
No Matches
nfcf.hpp File Reference

NFC-F definitions. More...

#include "nfc/nfc.hpp"
#include <cstdint>
#include <string>
#include <array>

Go to the source code of this file.

Classes

struct  m5::nfc::f::block_t
 Block list element. More...
 
struct  m5::nfc::f::PICC
 PICC information for NFC-F. More...
 
struct  m5::nfc::f::REG
 Subtract Register Block Data. More...
 

Namespaces

namespace  m5
 Top level namespace of M5Stack.
 
namespace  f
 NFC-F definitions.
 
namespace  standard
 For FeliCa Standard.
 
namespace  lite
 For FeliCa Lite.
 
namespace  lite_s
 For FeliCa Lite-S.
 

Enumerations

enum class  m5::nfc::f::Type : uint8_t {
  Unknown , FeliCaStandard , FeliCaLite , FeliCaLiteS ,
  FeliCaPlug
}
 Type of the PICC. More...
 
enum class  m5::nfc::f::CommandCode : uint8_t {
  Polling , RequestService = 0x02 , RequestResponse = 0x04 , ReadWithoutEncryption = 0x06 ,
  WriteWithoutEncryption = 0x08 , RequestSystemCode = 0x0C
}
 NFC-F Command code.
 
enum class  m5::nfc::f::ResponseCode : uint8_t {
  Polling = 0x01 , RequestService = 0x03 , RequestResponse = 0x05 , ReadWithoutEncryption = 0x07 ,
  WriteWithoutEncryption = 0x09 , RequestSystemCode = 0x0D
}
 NFC-F Response code.
 
enum class  m5::nfc::f::RequestCode : uint8_t { None , SystemCode , CommunicationPerformance }
 Request code for Polling. More...
 
enum class  m5::nfc::f::TimeSlot : uint8_t {
  Slot1 , Slot2 , Slot4 = 0x03 , Slot8 = 0x07 ,
  Slot16 = 0x0F
}
 Timeslot value for Polling.
 
enum class  m5::nfc::f::standard::Mode : uint8_t { Mode0 , Mode1 , Mode2 , Mode3 }
 Mode for Standard. More...
 
enum class  m5::nfc::f::lite_s::Mode : uint8_t { Mode00 , Mode01 , Mode10 , Mode11 }
 Mode for LiteS. More...
 

Functions

m5::nfc::NFCForumTag m5::nfc::f::get_nfc_forum_tag_type (const Type t)
 Get NFC Forum Tag Type from PICC type.
 
constexpr uint8_t m5::nfc::f::timeslot_to_slot (const TimeSlot ts)
 TimeSlot to the number of the slot.
 
uint16_t m5::nfc::f::get_maximum_block (const Type t)
 Gets the maximum block.
 
uint16_t m5::nfc::f::get_number_of_user_blocks (const Type t)
 Gets the number of user blocks.
 
uint16_t m5::nfc::f::get_user_area_size (const Type t)
 Gets the user area bytes.
 
uint16_t m5::nfc::f::get_first_user_block (const Type t)
 Gets the first user area block number.
 
uint16_t m5::nfc::f::get_last_user_block (const Type t)
 Gets the last user area block number.
 
bool m5::nfc::f::is_user_block (const Type t, const uint16_t block)
 Is block user area?
 
uint8_t m5::nfc::f::get_maximum_read_blocks (const Type t)
 Maximum number of blocks that can be read simultaneously.
 
uint8_t m5::nfc::f::get_maximum_write_blocks (const Type t)
 Maximum number of blocks that can be write simultaneously.
 
bool m5::nfc::f::is_read_only_lite (const block_t block)
 Is read only block (Permissions are not considered)
 
bool m5::nfc::f::is_read_only_lite_s (const block_t block)
 Is read only block (Permissions are not considered)
 
bool m5::nfc::f::can_read_lite (const block_t block)
 Can the value of the specified block be read? (Permissions are not considered)
 
bool m5::nfc::f::can_read_lite_s (const block_t block)
 Can the value of the specified block be read? (Permissions are not considered)
 
bool m5::nfc::f::operator== (const PICC &a, const PICC &b)
 Equal? (Only IDm,PMm)
 
bool m5::nfc::f::operator!= (const PICC &a, const PICC &b)
 Not equal?
 
For MAC
bool m5::nfc::f::make_session_key (uint8_t sk[16], const uint8_t ck[16], const uint8_t rc[16])
 Make session key.
 
bool m5::nfc::f::generate_mac (uint8_t mac[8], const uint8_t *plain, uint32_t plain_len, const uint8_t *block_data, uint32_t block_len, const uint8_t sk1[8], const uint8_t sk2[8], const uint8_t rc[16])
 Generate MAC.
 
bool m5::nfc::f::make_personalized_card_key_lite_s (uint8_t card_key[16], const uint8_t master_key[24], const uint8_t id_block[16])
 Generate personalized card key for FeliCa Lite-S.
 

Variables

constexpr uint8_t m5::nfc::f::FELICA_ID_LENGTH {8}
 
constexpr uint8_t m5::nfc::f::FELICA_MAX_BLOCKS {8}
 
constexpr uint16_t m5::nfc::f::FELICA_MAX_PACKET_LENGTH_REQUEST_SERVICE {1 + 8 + 1 + 2 * 255}
 
constexpr uint16_t m5::nfc::f::FELICA_MAX_PACKET_LENGTH_REQUEST_RESPONSE {1 + 8 + 1}
 
constexpr uint16_t m5::nfc::f::FELICA_MAX_PACKET_LENGTH_REQUEST_SYSTEM_CODE {1 + 8 + 1 + 2 * 255}
 
SystemCode
constexpr uint16_t m5::nfc::f::system_code_wildcard {0xFFFF}
 Wildcard.
 
constexpr uint16_t m5::nfc::f::system_code_ndef {0x12FC}
 NDEF.
 
constexpr uint16_t m5::nfc::f::system_code_felica_secure_id {0x957A}
 FeliCa secure ID.
 
constexpr uint16_t m5::nfc::f::system_code_shared {0xFE00}
 Shared area.
 
constexpr uint16_t m5::nfc::f::system_code_lite {0x88B4}
 Lite, Lite-S.
 
constexpr uint16_t m5::nfc::f::system_code_felica_plug {0xFEE1}
 FeliCa Plug.
 
Service attribute
constexpr uint16_t m5::nfc::f::service_random_read_write_auth {0x0008}
 Random,Read/write,Authentication required (S)
 
constexpr uint16_t m5::nfc::f::service_random_read_write {0x0009}
 Random,Read/write,No authentication required (S, L, LS)
 
constexpr uint16_t m5::nfc::f::service_random_read_auth {0x000A}
 Random,Read only,No authentication required (S)
 
constexpr uint16_t m5::nfc::f::service_random_read {0x000B}
 Random,Read only,No authentication required (S,LS)
 
constexpr uint16_t m5::nfc::f::service_cyclic_read_write_auth {0x000C}
 Cyclic,Read/write,Authentication required(S)
 
constexpr uint16_t m5::nfc::f::service_cyclic_read_write {0x000D}
 Cyclic,Read/write,No authentication required(S)
 
constexpr uint16_t m5::nfc::f::service_cyclic_read_auth {0x000E}
 Cyclic,Read only,Authentication required(S)
 
constexpr uint16_t m5::nfc::f::service_cyclic_read {0x000F}
 Cyclic,Read only,No authentication required(S)
 
constexpr uint16_t m5::nfc::f::service_parse_direct_auth {0x0100}
 Random,Read/write,Authentication required (S)
 
constexpr uint16_t m5::nfc::f::service_parse_direct {0x0101}
 Random,Read/write,Authentication required (S)
 
constexpr uint16_t m5::nfc::f::service_parse_cacheback_auth {0x0102}
 Random,Read/write,Authentication required (S)
 
constexpr uint16_t m5::nfc::f::service_parse_cacheback {0x0103}
 Random,Read/write,Authentication required (S)
 
constexpr uint16_t m5::nfc::f::service_parse_decrement_auth {0x0104}
 Random,Read/write,Authentication required (S)
 
constexpr uint16_t m5::nfc::f::service_parse_decrement {0x0105}
 Random,Read/write,Authentication required (S)
 
constexpr uint16_t m5::nfc::f::service_parse_increment_auth {0x0106}
 Random,Read/write,Authentication required (S)
 
constexpr uint16_t m5::nfc::f::service_parse_increment {0x0107}
 Random,Read/write,Authentication required (S)
 
Block
constexpr block_t m5::nfc::f::lite::S_PAD0 {0x00}
 
constexpr block_t m5::nfc::f::lite::S_PAD1 {0x01}
 
constexpr block_t m5::nfc::f::lite::S_PAD2 {0x02}
 
constexpr block_t m5::nfc::f::lite::S_PAD3 {0x03}
 
constexpr block_t m5::nfc::f::lite::S_PAD4 {0x04}
 
constexpr block_t m5::nfc::f::lite::S_PAD5 {0x05}
 
constexpr block_t m5::nfc::f::lite::S_PAD6 {0x06}
 
constexpr block_t m5::nfc::f::lite::S_PAD7 {0x07}
 
constexpr block_t m5::nfc::f::lite::S_PAD8 {0x08}
 
constexpr block_t m5::nfc::f::lite::S_PAD9 {0x09}
 
constexpr block_t m5::nfc::f::lite::S_PAD10 {0x0A}
 
constexpr block_t m5::nfc::f::lite::S_PAD11 {0x0B}
 
constexpr block_t m5::nfc::f::lite::S_PAD12 {0X0C}
 
constexpr block_t m5::nfc::f::lite::S_PAD13 {0x0D}
 
constexpr block_t m5::nfc::f::lite::REG {0x0E}
 
constexpr block_t m5::nfc::f::lite::RC {0x80}
 
constexpr block_t m5::nfc::f::lite::MAC {0x81}
 
constexpr block_t m5::nfc::f::lite::ID {0x082}
 
constexpr block_t m5::nfc::f::lite::D_ID {0x83}
 
constexpr block_t m5::nfc::f::lite::SER_C {0x84}
 
constexpr block_t m5::nfc::f::lite::SYS_C {0x85}
 
constexpr block_t m5::nfc::f::lite::CKV {0x86}
 
constexpr block_t m5::nfc::f::lite::CK {0x87}
 
constexpr block_t m5::nfc::f::lite::MC {0x88}
 
Block
constexpr block_t m5::nfc::f::lite_s::S_PAD0 {0x00}
 
constexpr block_t m5::nfc::f::lite_s::S_PAD1 {0x01}
 
constexpr block_t m5::nfc::f::lite_s::S_PAD2 {0x02}
 
constexpr block_t m5::nfc::f::lite_s::S_PAD3 {0x03}
 
constexpr block_t m5::nfc::f::lite_s::S_PAD4 {0x04}
 
constexpr block_t m5::nfc::f::lite_s::S_PAD5 {0x05}
 
constexpr block_t m5::nfc::f::lite_s::S_PAD6 {0x06}
 
constexpr block_t m5::nfc::f::lite_s::S_PAD7 {0x07}
 
constexpr block_t m5::nfc::f::lite_s::S_PAD8 {0x08}
 
constexpr block_t m5::nfc::f::lite_s::S_PAD9 {0x09}
 
constexpr block_t m5::nfc::f::lite_s::S_PAD10 {0x0A}
 
constexpr block_t m5::nfc::f::lite_s::S_PAD11 {0x0B}
 
constexpr block_t m5::nfc::f::lite_s::S_PAD12 {0X0C}
 
constexpr block_t m5::nfc::f::lite_s::S_PAD13 {0x0D}
 
constexpr block_t m5::nfc::f::lite_s::REG {0x0E}
 
constexpr block_t m5::nfc::f::lite_s::RC {0x80}
 
constexpr block_t m5::nfc::f::lite_s::MAC {0x81}
 
constexpr block_t m5::nfc::f::lite_s::ID {0x082}
 
constexpr block_t m5::nfc::f::lite_s::D_ID {0x83}
 
constexpr block_t m5::nfc::f::lite_s::SER_C {0x84}
 
constexpr block_t m5::nfc::f::lite_s::SYS_C {0x85}
 
constexpr block_t m5::nfc::f::lite_s::CKV {0x86}
 
constexpr block_t m5::nfc::f::lite_s::CK {0x87}
 
constexpr block_t m5::nfc::f::lite_s::MC {0x88}
 
constexpr block_t m5::nfc::f::lite_s::WCNT {0x90}
 
constexpr block_t m5::nfc::f::lite_s::MAC_A {0x91}
 
constexpr block_t m5::nfc::f::lite_s::STATE {0x92}
 
constexpr block_t m5::nfc::f::lite_s::CRC_CHECK {0xA0}
 
RequestService
constexpr uint16_t m5::nfc::f::NODE_SYSTEM_KEY {0xFFFF}
 Retrieving the System Key Version.
 
constexpr uint16_t m5::nfc::f::KEY_VERSION_NONE {0xFFFF}
 No key version exists.
 
constexpr uint16_t m5::nfc::f::KEY_VERIOSN_NONE {KEY_VERSION_NONE}
 

Format bits

using m5::nfc::f::Format = uint8_t
 Support ISO/IEC18092.
 
constexpr Format m5::nfc::f::format_nfcip1 {0x0001}
 Support ISO/IEC18092.
 
constexpr Format m5::nfc::f::format_lite {0x0002}
 Lite or Lite-S.
 
constexpr Format m5::nfc::f::format_private {0x0004}
 Has private area.
 
constexpr Format m5::nfc::f::format_ndef {0x0008}
 Support NDEF.
 
constexpr Format m5::nfc::f::format_shared {0x0010}
 Has shared area.
 
constexpr Format m5::nfc::f::format_secure {0x0020}
 FeliCa Secure ID.
 
constexpr Format m5::nfc::f::format_felica_plug {0x0040}
 FeliCa Plug.
 

Timeout

constexpr uint32_t m5::nfc::f::TIMEOUT_POLLING {5}
 Is the new value writable?
 
constexpr uint32_t m5::nfc::f::TIMEOUT_POLLING_PICC {2}
 Is the new value writable?
 
bool m5::nfc::f::can_write_reg (const REG &o, const REG &n)
 Is the new value writable?
 

Detailed Description

NFC-F definitions.

Enumeration Type Documentation

◆ Mode [1/2]

enum class m5::nfc::f::lite_s::Mode : uint8_t
strong

Mode for LiteS.

Enumerator
Mode00 

External authentication incomplete, polling response possible.

Mode01 

External authentication incomplete, polling response not possible.

Mode10 

External authentication complete, polling response possible.

Mode11 

External authentication complete, polling response not possible.

◆ Mode [2/2]

enum class m5::nfc::f::standard::Mode : uint8_t
strong

Mode for Standard.

Enumerator
Mode0 

Power was supplied to the PICC.

Mode1 

Certification for PICC has been completed (Auth1)

Mode2 

After mutual authentication is complete (Auth2)

Mode3 

After registering area services or executing system partitioning.

◆ RequestCode

enum class m5::nfc::f::RequestCode : uint8_t
strong

Request code for Polling.

Enumerator
None 

No request.

SystemCode 

Request system code.

CommunicationPerformance 

Request communication performance.

◆ Type

enum class m5::nfc::f::Type : uint8_t
strong

Type of the PICC.

Enumerator
Unknown 

Unknown type.

FeliCaStandard 

Standard.

FeliCaLite 

Lite.

FeliCaLiteS 

Lite-S.

FeliCaPlug 

Plug.

Function Documentation

◆ can_read_lite()

bool m5::nfc::f::can_read_lite ( const block_t block)

Can the value of the specified block be read? (Permissions are not considered)

Parameters
blockBlock list element
Returns
True if the FeliCa Lite block can be read

◆ can_read_lite_s()

bool m5::nfc::f::can_read_lite_s ( const block_t block)

Can the value of the specified block be read? (Permissions are not considered)

Parameters
blockBlock list element
Returns
True if the FeliCa Lite-S block can be read

◆ can_write_reg()

bool m5::nfc::f::can_write_reg ( const REG & o,
const REG & n )
inline

Is the new value writable?

Parameters
oOld REG value
nNew REG value
Returns
true if writable

◆ generate_mac()

bool m5::nfc::f::generate_mac ( uint8_t mac[8],
const uint8_t * plain,
uint32_t plain_len,
const uint8_t * block_data,
uint32_t block_len,
const uint8_t sk1[8],
const uint8_t sk2[8],
const uint8_t rc[16] )

Generate MAC.

Parameters
[out]macMAC
plainPlain blocks (If nullptr, do not use)
plain_lenLength of plain (If zero, do not use)
block_dataBlock data
block_lenLength of block_data
sk1Session key 1
sk2Session key 2
rcRandom challenge
Returns
True if successful

◆ get_first_user_block()

uint16_t m5::nfc::f::get_first_user_block ( const Type t)

Gets the first user area block number.

Parameters
tPICC type
Returns
First user block number

◆ get_last_user_block()

uint16_t m5::nfc::f::get_last_user_block ( const Type t)

Gets the last user area block number.

Parameters
tPICC type
Returns
Last user block number

◆ get_maximum_block()

uint16_t m5::nfc::f::get_maximum_block ( const Type t)

Gets the maximum block.

Parameters
tPICC type
Returns
Maximum block number

◆ get_maximum_read_blocks()

uint8_t m5::nfc::f::get_maximum_read_blocks ( const Type t)

Maximum number of blocks that can be read simultaneously.

Parameters
tPICC type
Returns
Maximum readable block count

◆ get_maximum_write_blocks()

uint8_t m5::nfc::f::get_maximum_write_blocks ( const Type t)

Maximum number of blocks that can be write simultaneously.

Parameters
tPICC type
Returns
Maximum writable block count

◆ get_nfc_forum_tag_type()

m5::nfc::NFCForumTag m5::nfc::f::get_nfc_forum_tag_type ( const Type t)
inline

Get NFC Forum Tag Type from PICC type.

Parameters
tPICC type
Returns
NFC Forum Tag Type

◆ get_number_of_user_blocks()

uint16_t m5::nfc::f::get_number_of_user_blocks ( const Type t)

Gets the number of user blocks.

Parameters
tPICC type
Returns
Number of user blocks

◆ get_user_area_size()

uint16_t m5::nfc::f::get_user_area_size ( const Type t)
inline

Gets the user area bytes.

Parameters
tPICC type
Returns
User area size in bytes

◆ is_read_only_lite()

bool m5::nfc::f::is_read_only_lite ( const block_t block)

Is read only block (Permissions are not considered)

Parameters
blockBlock list element
Returns
True if the FeliCa Lite block is read-only

◆ is_read_only_lite_s()

bool m5::nfc::f::is_read_only_lite_s ( const block_t block)

Is read only block (Permissions are not considered)

Parameters
blockBlock list element
Returns
True if the FeliCa Lite-S block is read-only

◆ is_user_block()

bool m5::nfc::f::is_user_block ( const Type t,
const uint16_t block )
inline

Is block user area?

Parameters
tPICC type
blockBlock number
Returns
True if the block is in the user area

◆ make_personalized_card_key_lite_s()

bool m5::nfc::f::make_personalized_card_key_lite_s ( uint8_t card_key[16],
const uint8_t master_key[24],
const uint8_t id_block[16] )

Generate personalized card key for FeliCa Lite-S.

Parameters
[out]card_keyPersonalized card key (16 bytes)
master_keyPersonalized master key (24 bytes)
id_blockID block value (16 bytes)
Returns
True if successful

◆ make_session_key()

bool m5::nfc::f::make_session_key ( uint8_t sk[16],
const uint8_t ck[16],
const uint8_t rc[16] )

Make session key.

Parameters
[out]skSession key (sk1 8byte + sk2 8byte)
ckCard key
rcRandom challenge
Returns
True if successful

◆ operator!=()

bool m5::nfc::f::operator!= ( const PICC & a,
const PICC & b )
inline

Not equal?

Parameters
aLeft PICC
bRight PICC
Returns
True if IDm or PMm differs

◆ operator==()

bool m5::nfc::f::operator== ( const PICC & a,
const PICC & b )

Equal? (Only IDm,PMm)

Parameters
aLeft PICC
bRight PICC
Returns
True if IDm and PMm are equal

◆ timeslot_to_slot()

uint8_t m5::nfc::f::timeslot_to_slot ( const TimeSlot ts)
inlineconstexpr

TimeSlot to the number of the slot.

Parameters
tsTimeSlot value
Returns
Number of polling slots, or 0 if illegal

Variable Documentation

◆ KEY_VERIOSN_NONE

uint16_t m5::nfc::f::KEY_VERIOSN_NONE {KEY_VERSION_NONE}
constexpr
Deprecated
typo alias; use KEY_VERSION_NONE

◆ TIMEOUT_POLLING

uint32_t m5::nfc::f::TIMEOUT_POLLING {5}
constexpr

Is the new value writable?

Parameters
oOld REG value
nNew REG value
Returns
true if writable

◆ TIMEOUT_POLLING_PICC

uint32_t m5::nfc::f::TIMEOUT_POLLING_PICC {2}
constexpr

Is the new value writable?

Parameters
oOld REG value
nNew REG value
Returns
true if writable