Answer The APDU (Application Protocol Data Unit) is the communication unit between a reader and a card. The structure of an APDU is defined by the ISO 7816 standards. There are two categories of APDUs: command APDUs and response APDUs. As the name implies, the former is sent by the reader to the card: it contains a mandatory 5-byte header and from 0 to up to 255 bytes of data. The latter is sent by the card to the reader: it contains a mandatory 2-byte status word and from 0 to up to 256 bytes of data. The APDU is an application level protocol as specified in the ISO 7816-4, which takes place between a smart card and a host application for the communication purpose. APDU consist of two structures, as defined below:
- Command APDU (C-APDU: this command is used by the host application to send command to the card.
- Header: it consist of 4 bytes:-
- Class of instruction (CLA)
- Instruction code (INS)
- Parameters: P1 and 2
- Optional body: varies in length.
- Lc = specifies the length of the optional body or the data field (Bytes).
- Le = specifies the length of the data or the number of bytes that the host is expecting in response to the command sent.
- Data field contains the data that are sent to the card for executing the instruction specified in the header.
- Response APDU (R-APDU): this command is used by the card in order to respond to the command send by the host application.
- Optional body: it consist of data field whose length is specified by the Le
- Trailer: it consist of two words SW1 and SW2 called as status word, which denotes the processing state in the card after the execution of the command APDU.
Structure of the APDU is given below: 1. Command APDU
|Mandatory Header||Optional body|
2. Response APDU
|Optional body||Mandatory Trailer|
- A command is always paired with response APDU
- The data field is optional in both command APDU and response APDU.
The second case further divides the command and response APDU in four categories.
- There is no transfer of data to or from the card
- C- APDU: contains header only.
- R- APDU: contains only the trailer status word.
- There is no transfer of data to the card but data are returned from the card
- C- APDU: contains Le only, which specifies the number of data bytes in the corresponding response APDU.
- There is transfer of data to the card but no data is returned from the card
- C- APDU: contains Lc and data field, Lc which specifies the length of the data field.
- R-APDU: contains the trailer status word SW1 and SW2.
- There is transfer of data to the card and data is returned from the card
- C- APDU: contains Lc and data field and Le.
- R-APDU: contains both the optional body and the trailer status word SW1 and SW2.