Friday, June 29, 2012

APDU


APDU message command-response pair

There are two categories of APDUs: command APDUs and response APDUs. A command APDU is sent by the reader to the card – it contains a mandatory 4-byte header (CLA, INS, P1, P2) and from 0 to 255 bytes of data. A response APDU is sent by the card to the reader – it contains a mandatory 2-byte status word and from 0 to 256 bytes of data.
Command APDU
Field nameLength (bytes)Description
CLA1Instruction class - indicates the type of command, e.g. interindustry or proprietary
INS1Instruction code - indicates the specific command, e.g. "write data"
P1-P22Instruction parameters for the command, e.g. offset into file at which to write the data
Lc0, 1 or 3Encodes the number (Nc) of bytes of command data to follow
Command dataNcNc bytes of data
Le0, 1, 2 or 3Encodes the maximum number (Ne) of response bytes expected
Response APDU
Response dataNr (at most Ne)Response data
SW1-SW2
(Response trailer)
2Command processing status, e.g. 90 00 (hexadecimal) indicates success

Abbreviations and Notation

For the purposes of this part of the ISO/IEC 7816, the following abbreviations apply :
APDUApplication protocol data unit
ATRAnswer to reset
BERBasic encoding rules of ASN.1 (see annex D)
CLAClass byte
DIRDirectory
DFDedicated file
EFElementary file
FCIFile control information
FCPFile control parameter
FMDFile management data
INSInstruction byte
MFInstruction byte
P1-P2Parameter bytes
PTSProtocol type selection
RFUReserved for future use
SMSecure messaging
SW1-SW2Status bytes
TLVTag length value
TPDUTransmission protocol data unit

For the purposes of this part of ISO/IEC 7816, the following notation applies :
< TR>
'0'-'9' and 'A'-'F'The sixteen hexadecimal digits
(B1)Value of byte B1
B1||B2Concatenation of bytes B1 (the most significant byte) and B2 (the least significant byte)
#Number

No comments: