10#ifndef M5_UNIT_UNIFIED_NFC_NFC_APDU_APDU_HPP
11#define M5_UNIT_UNIFIED_NFC_NFC_APDU_APDU_HPP
58enum class INS : uint8_t {
71 UPDATE_RECORRD = 0xDC,
79 INTERNAL_AUTHENTICATE = 0x88,
80 EXTERNAL_AUTHENTICATE = 0x82,
89 ERASE_ALL_RECORDS = 0x06,
93 DF_CREATE_APPLICATION = 0xCA,
94 DF_DELETE_APPLICATION = 0xDA,
95 DF_SELECT_APPLICATION = 0x5A,
96 DF_GET_APPLICATION_IDS = 0x6A,
97 DF_CREATE_STD_DATA_FILE = 0xCD,
98 DF_GET_FREE_MEMORY = 0x6E,
99 DF_GET_FILE_IDS = 0x6F,
100 DF_GET_ISO_FILE_IDS = 0x61,
101 DF_GET_KEY_SETTINGS = 0x45,
102 DF_SET_CONFIGURATION = 0x5C,
103 DF_CHANGE_FILE_SETTINGS = 0x5F,
104 DF_AUTHENTICATE = 0x0A,
105 DF_AUTHENTICATE_ISO = 0x1A,
106 DF_AUTHENTICATE_AES = 0xAA,
107 DF_AUTHENTICATE_EV2 = 0x71,
108 DF_FORMAT_PICC = 0xFC,
110 DF_WRITE_DATA = 0x3D,
111 DF_GET_FILE_SETTINGS = 0xF5,
112 DF_DELETE_TRANSACTION_MAC_FILE = 0xDF,
113 DF_CREATE_TRANSACTION_MAC_FILE = 0xCE,
157inline bool need_select_file_le(
const uint8_t param2)
159 return (param2 & 0x0C) != 0x0C;
172 inline bool is_constructed()
const
174 return (
tag & 0x20) != 0;
176 inline bool is_primitive()
const
178 return !is_constructed();
183std::vector<TLV> parse_tlv(
const uint8_t* ptr,
const uint32_t len);
185void dump_tlv(
const std::vector<TLV>& tlvs,
const uint8_t depth = 0);
198std::vector<uint8_t> make_apdu_command(
const uint8_t cla,
const uint8_t ins,
const uint8_t param1 = 0x00,
199 const uint8_t param2 = 0x00,
const uint8_t* data =
nullptr,
200 const uint16_t data_len = 0,
const uint16_t rx_len = 0);
203inline std::vector<uint8_t>
make_apdu_case1(
const uint8_t cla,
const uint8_t ins,
const uint8_t p1,
const uint8_t p2)
209inline std::vector<uint8_t>
make_apdu_case2(
const uint8_t cla,
const uint8_t ins,
const uint8_t p1,
const uint8_t p2,
216inline std::vector<uint8_t>
make_apdu_case3(
const uint8_t cla,
const uint8_t ins,
const uint8_t p1,
const uint8_t p2,
217 const uint8_t* data,
const uint16_t data_len)
223inline std::vector<uint8_t>
make_apdu_case4(
const uint8_t cla,
const uint8_t ins,
const uint8_t p1,
const uint8_t p2,
224 const uint8_t* data,
const uint16_t data_len,
const uint16_t le)
std::vector< uint8_t > make_apdu_command(const uint8_t cla, const uint8_t ins, const uint8_t param1, const uint8_t param2, const uint8_t *data, const uint16_t data_len, const uint16_t rx_len)
Make APDU command.
Definition apdu.cpp:22
SelectBy
Select control for SELECT_FILE.
Definition apdu.hpp:122
@ EfUnderCurrentDf
Select EF under current DF (FID in data)
@ FileId
Select MF/DF/EF by file ID.
@ DfName
Select by DF name (AID)
@ ChildDf
Select child DF (FID in data)
@ PathFromMf
Select by path from MF.
@ PathFromCurrentDf
Select by path from current DF.
@ ParentDf
Select parent DF.
constexpr uint16_t RESPONSE_OK
Command successfully executed (OK)
Definition apdu.hpp:27
constexpr uint16_t SUCCESSFULLY_2
Command successfully executed; xx bytes of data are available and can be requested using GET RESPON.
Definition apdu.hpp:31
std::vector< uint8_t > make_apdu_case1(const uint8_t cla, const uint8_t ins, const uint8_t p1, const uint8_t p2)
Make APDU case1 command [CLA | INS | P1 | P2].
Definition apdu.hpp:203
SelectResponse
Response for SELECT_FILE.
Definition apdu.hpp:148
constexpr uint8_t WRONG_LENGTH_LE
Wrong length Le.
Definition apdu.hpp:34
std::vector< uint8_t > make_apdu_case2(const uint8_t cla, const uint8_t ins, const uint8_t p1, const uint8_t p2, const uint16_t le)
Make APDU case2 command [CLA | INS | P1 | P2 | Le].
Definition apdu.hpp:209
INS
APDU instruction code.
Definition apdu.hpp:58
constexpr uint8_t RESPONSE_BYTES_STILL_AVAILABLE
Response bytes still available.
Definition apdu.hpp:33
constexpr uint16_t SUCCESSFULLY_1
Command successfully executed; xx bytes of data are available and can be requested using GET RESPON.
Definition apdu.hpp:29
SelectOccurrence
Select occurrence for SELECT_FILE.
Definition apdu.hpp:137
@ Next
Select the next match.
@ FirstOrOnly
Select the first (or only) match.
@ Last
Select the last match.
@ Previous
Select the previous match.
constexpr uint16_t master_file_id
Master file ID.
Definition apdu.hpp:155
bool is_response_OK(const uint16_t sw12)
Is response successfully?
Definition apdu.hpp:38
std::vector< uint8_t > make_apdu_case4(const uint8_t cla, const uint8_t ins, const uint8_t p1, const uint8_t p2, const uint8_t *data, const uint16_t data_len, const uint16_t le)
Make APDU case4 command [CLA | INS | P1 | P2 | Lc | C-Data | Le].
Definition apdu.hpp:223
std::vector< uint8_t > make_apdu_case3(const uint8_t cla, const uint8_t ins, const uint8_t p1, const uint8_t p2, const uint8_t *data, const uint16_t data_len)
Make APDU case3 command [CLA | INS | P1 | P2 | Lc | C-Data].
Definition apdu.hpp:216
Top level namespace of M5stack.
File Control Parameters.
Definition file_system.hpp:26
TLV element.
Definition apdu.hpp:166
uint32_t len
L (length)
Definition apdu.hpp:168
uint8_t tag_len
Tag length.
Definition apdu.hpp:170
uint32_t tag
T (Tag)
Definition apdu.hpp:167