ISO/IEC 7816-4
Identification cards — Integrated circuit cards — Part 4: Organization, security and commands for interchange
Cartes d’identification — Cartes à circuit intégré — Partie 4: Organisation, sécurité et commandes pour les échanges

Organization for interchange

For organizing interchange, this clause specifies the following basic features. 1) Command-response pairs 2) Data objects 3) Structures for applications and data 4) Security architecture

Command-response pairs

Table 1 shows a command-response pair, namely a command APDU followed by a response APDU in the opposite direction (see ISO/IEC 7816-3). There shall be no interleaving of command-response pairs across the interface, i.e., the response APDU shall be received before initiating another command-response pair.

Table 1 — Command-response pair

Field Description Number of bytes
Command header Class byte denoted CLA 1
Instruction byte denoted INS 1
  Parameter bytes denoted P1-P2 2
Lc field Absent for encoding Nc = 0, present for encoding Nc > 0 0, 1 or 3
Command data field Absent if Nc = 0, present as a string of Nc bytes if Nc > 0 Nc
Le field Absent for encoding Ne = 0, present for encoding Ne > 0 0, 1, 2 or 3
Response data field Absent if Nr = 0, present as a string of Nr bytes if Nr > 0 Nr (at most Ne)
Response trailer Status bytes denoted SW1-SW2 2

In any command-response pair comprising both Lc and Le fields (see ISO/IEC 7816-3), short and extended length fields shall not be combined: either both of them are short, or both of them are extended.

If the card explicitly states its capability of handling “extended Lc and Le fields” (see Table 88, third software function table) in the historical bytes (see 8.1.1) or in EF.ATR (see 8.2.1.1), then the card handles short and extended length fields. Otherwise (default value), the card handles only short length fields.

Nc denotes the number of bytes in the command data field. The Lc field encodes Nc.

 If the Lc field is absent, then Nc is zero.

 A short Lc field consists of one byte not set to ’00′.

• From ’01′ to ‘FF’, the byte encodes Nc from one to 255.

 An extended Lc field consists of three bytes: one byte set to ’00′ followed by two bytes not set to ’0000′.

• From ’0001′ to ‘FFFF’, the two bytes encode Nc from one to 65 535.

Ne denotes the maximum number of bytes expected in the response data field. The Le field encodes Ne.

 If the Le field is absent, then Ne is zero.

 A short Le field consists of one byte with any value.

  • From ’01′ to ‘FF’, the byte encodes Ne from one to 255.
  • If the byte is set to ’00′, then Ne is 256.

 An extended Le field consists of either three bytes (one byte set to ’00′ followed by two bytes with any value) if the Lc field is absent, or two bytes (with any value) if an extended Lc field is present.

  • From ’0001′ to ‘FFFF’, the two bytes encode Ne from one to 65 535.
  • If the two bytes are set to ’0000′, then Ne is 65 536.

Nr denotes the number of bytes in the response data field. Nr shall be less than or equal to Ne. Therefore in any command-response pair, the absence of Le field is the standard way for receiving no response data field. If the Le field contains only bytes set to ’00′, then Ne is maximum, i.e., within the limit of 256 for a short Le field, or 65 536 for an extended Le field, all the available bytes should be returned.

If the process is aborted, then the card may become unresponsive. However if a response APDU occurs, then the response data field shall be absent and SW1-SW2 shall indicate an error.

P1-P2 indicates controls and options for processing the command. A parameter byte set to ’00′ generally provides no further qualification. There is no other general convention for encoding the parameter bytes.

General conventions are specified hereafter for encoding the class byte denoted CLA (see 5.1.1), the instruction byte denoted INS (see 5.1.2) and the status bytes denoted SW1-SW2 (see 5.1.3). In those bytes, the RFU bits shall be set to 0 unless otherwise specified.