M5Unit-NFC 0.0.3 git rev:59f5362
Loading...
Searching...
No Matches
apdu.hpp File Reference

Application Protocol Data Unit (ISO/IEC 7816-4) More...

#include <cstdint>
#include <string>
#include <vector>

Go to the source code of this file.

Classes

struct  m5::nfc::apdu::TLV
 TLV element. More...
 

Namespaces

namespace  m5
 Top level namespace of M5stack.
 
namespace  apdu
 For APDU.
 

Enumerations

enum class  m5::nfc::apdu::INS : uint8_t {
  SELECT_FILE = 0xA4 , CREATE_FILE = 0xE0 , READ_BINARY = 0xB0 , WRITE_BINARY = 0xD0 ,
  UPDATE_BINARY = 0xD6 , ERASE_BINARY = 0x0E , READ_RECORD = 0xB2 , WRITE_RECORD = 0xD2 ,
  APPEND_RECORD = 0xE2 , UPDATE_RECORRD = 0xDC , GET_RESPONSE = 0xC0 , GET_DATA = 0xCA ,
  PUT_DATA = 0xDA , VERIFY = 0x20 , INTERNAL_AUTHENTICATE = 0x88 , EXTERNAL_AUTHENTICATE = 0x82 ,
  GET_CHALLEMGE = 0x84 , LOCK_DF = 0x50 , UNLOCK_DF = 0x52 , UNLOCK_KEY = 0x54 ,
  CHANGE_KEY = 0x32 , ERASE_ALL_RECORDS = 0x06 , GET_VERSION = 0x60 , DF_CREATE_APPLICATION = 0xCA ,
  DF_DELETE_APPLICATION = 0xDA , DF_SELECT_APPLICATION = 0x5A , DF_GET_APPLICATION_IDS = 0x6A , DF_CREATE_STD_DATA_FILE = 0xCD ,
  DF_GET_FREE_MEMORY = 0x6E , DF_GET_FILE_IDS = 0x6F , DF_GET_ISO_FILE_IDS = 0x61 , DF_GET_KEY_SETTINGS = 0x45 ,
  DF_SET_CONFIGURATION = 0x5C , DF_CHANGE_FILE_SETTINGS = 0x5F , DF_AUTHENTICATE = 0x0A , DF_AUTHENTICATE_ISO = 0x1A ,
  DF_AUTHENTICATE_AES = 0xAA , DF_AUTHENTICATE_EV2 = 0x71 , DF_FORMAT_PICC = 0xFC , DF_READ_DATA = 0xBD ,
  DF_WRITE_DATA = 0x3D , DF_GET_FILE_SETTINGS = 0xF5 , DF_DELETE_TRANSACTION_MAC_FILE = 0xDF , DF_CREATE_TRANSACTION_MAC_FILE = 0xCE
}
 APDU instruction code.
 
enum class  m5::nfc::apdu::SelectBy : uint8_t {
  FileId = 0x00 , ChildDf = 0x01 , EfUnderCurrentDf = 0x02 , ParentDf = 0x03 ,
  DfName = 0x04 , PathFromMf = 0x08 , PathFromCurrentDf = 0x09
}
 Select control for SELECT_FILE. More...
 
enum class  m5::nfc::apdu::SelectOccurrence : uint8_t { FirstOrOnly = 0x00 , Last = 0x01 , Next = 0x02 , Previous = 0x03 }
 Select occurrence for SELECT_FILE. More...
 
enum class  m5::nfc::apdu::SelectResponse : uint8_t { FCI = 0x00 , FCP = 0x04 , FMD = 0x08 , None = 0x0C }
 Response for SELECT_FILE. More...
 

Functions

bool m5::nfc::apdu::is_response_OK (const uint16_t sw12)
 Is response successfully?
 
bool m5::nfc::apdu::is_response_OK (const uint8_t sw[2])
 Is response successfully?
 
bool m5::nfc::apdu::is_response_OK (const uint8_t sw1, const uint8_t sw2)
 Is response successfully?
 
bool m5::nfc::apdu::need_select_file_le (const uint8_t param2)
 
std::vector< TLVm5::nfc::apdu::parse_tlv (const uint8_t *ptr, const uint32_t len)
 Parse TLV.
 
void m5::nfc::apdu::dump_tlv (const std::vector< TLV > &tlvs, const uint8_t depth=0)
 Dump TLV.
 
std::vector< uint8_t > m5::nfc::apdu::make_apdu_command (const uint8_t cla, const uint8_t ins, const uint8_t param1=0x00, const uint8_t param2=0x00, const uint8_t *data=nullptr, const uint16_t data_len=0, const uint16_t rx_len=0)
 Make APDU command.
 
std::vector< uint8_t > m5::nfc::apdu::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].
 
std::vector< uint8_t > m5::nfc::apdu::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].
 
std::vector< uint8_t > m5::nfc::apdu::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].
 
std::vector< uint8_t > m5::nfc::apdu::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].
 

Variables

constexpr uint16_t m5::nfc::apdu::master_file_id {0x3F00}
 Master file ID.
 
APDU responses
constexpr uint16_t m5::nfc::apdu::RESPONSE_OK {0x9000}
 Command successfully executed (OK)
 
constexpr uint16_t m5::nfc::apdu::SUCCESSFULLY_1 {0x6100}
 Command successfully executed; xx bytes of data are available and can be requested using GET RESPON.
 
constexpr uint16_t m5::nfc::apdu::SUCCESSFULLY_2 {0x9F00}
 Command successfully executed; xx bytes of data are available and can be requested using GET RESPON.
 
constexpr uint8_t m5::nfc::apdu::RESPONSE_BYTES_STILL_AVAILABLE {0x61}
 Response bytes still available.
 
constexpr uint8_t m5::nfc::apdu::WRONG_LENGTH_LE {0x6C}
 Wrong length Le.
 

Detailed Description

Application Protocol Data Unit (ISO/IEC 7816-4)

Enumeration Type Documentation

◆ SelectBy

enum class m5::nfc::apdu::SelectBy : uint8_t
strong

Select control for SELECT_FILE.

Note
OR with SelectOccurrence
Enumerator
FileId 

Select MF/DF/EF by file ID.

ChildDf 

Select child DF (FID in data)

EfUnderCurrentDf 

Select EF under current DF (FID in data)

ParentDf 

Select parent DF.

DfName 

Select by DF name (AID)

PathFromMf 

Select by path from MF.

PathFromCurrentDf 

Select by path from current DF.

◆ SelectOccurrence

enum class m5::nfc::apdu::SelectOccurrence : uint8_t
strong

Select occurrence for SELECT_FILE.

Note
OR with SelectBy
Enumerator
FirstOrOnly 

Select the first (or only) match.

Last 

Select the last match.

Next 

Select the next match.

Previous 

Select the previous match.

◆ SelectResponse

enum class m5::nfc::apdu::SelectResponse : uint8_t
strong

Response for SELECT_FILE.

Enumerator
FCI 

FCI template.

FCP 

FCP template.

FMD 

FMD template.

None 

/ No response

Function Documentation

◆ make_apdu_command()

std::vector< uint8_t > m5::nfc::apdu::make_apdu_command ( const uint8_t cla,
const uint8_t ins,
const uint8_t param1 = 0x00,
const uint8_t param2 = 0x00,
const uint8_t * data = nullptr,
const uint16_t data_len = 0,
const uint16_t rx_len = 0 )

Make APDU command.

Parameters
claCLA
insINS
param1PARAM1
param2PARAM2
dataPayload data
data_lenPayload data length
rx_lenExpected bytes to receive
Returns
Constructed command data