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

Commands for interchange
This clause specifies commands for interchange, presented hereafter in six groups.
1) Selection
2) Data unit handling
3) Record handling
4) Data object handling
5) Basic security handling
6) Transmission handling
It shall not be mandatory for all cards complying with this document to support all those commands or all the options of a supported command. When interchange is required, a set of application-independent card services and related commands and options shall be used as specified in 8.

Selection
After the answer to reset, the MF or an application DF is implicitly selected through the basic logical channel (see 5.1.1.2), unless otherwise specified in the historical bytes (see 8.1.1) or in the initial data string (see 8.1.2).

SELECT command
When completed, the command opens the logical channel (see 5.1.1.2) numbered in CLA (see 5.1.1), if not yet opened, and sets a current structure within that logical channel. Subsequent commands may implicitly refer to the current structure through that logical channel.
–The selected DF (the MF or an application DF) becomes current in the logical channel. The previously selected DF, if any, is no longer referred to through that logical channel and becomes the former current DF. After such a selection, an implicit current EF may be referred to through that logical channel.
–The selection of an EF sets a pair of current files: the EF and its parent DF.

Unless otherwise specified, the following rules apply to each open logical channel within a hierarchy of DFs.
–If the current EF is changed, or when there is no current EF, then the security status, if any, specific to the former current EF is lost.
–If the current DF is a descendant of, or identical to the former current DF, then the security status specific to the former current DF is maintained.
–If the current DF is neither a descendant of, nor identical to the former current DF, then the security status specific to the former current DF is lost. The security status common to all common ancestors of the previous and new current DF is maintained.

Table 38 — SELECT command-response pair
CLA INS P1 P2 As defined in 5.1.1 ‘A4′ See Table 39 See Table 40
Lcfield Absent for encoding Nc= 0, present for encoding Nc> 0
Data field Absent or file identifier or path or DF name (according to P1)
Lefield Absent for encoding Ne= 0, present for encoding Ne> 0
Data field Absent or file control information (according to P2)
SW1-SW2 See Tables 5 and 6 when relevant, e.g., ’6283′, ’6284′, ’6A80′, ’6A81′, ’6A82′, ’6A86′, ’6A87′

If P1 is set to ’00′, then the card knows whether the file to select is the MF, a DF or an EF, either because of a specific encoding of the file identifier, or because of the command processing context.
–If P2 is set to ’00′ and the command data field provides a file identifier, then that file identifier shall be unique in the following three environments: the immediate children of the current DF, the parent DF and the immediate children of the parent DF.
–If P2 is set to ’00′ and the command data field absent or set to ’3F00′, then the MF shall be selected.
If P1 is set to ’04′, then the command data field is a DF name, which may be an application identifier (see 8.2.1.2), possibly right truncated. If supported, successive such commands with the same data field shall select DFs whose names match with the data field, i.e., start with the command data field. If the card accepts the SELECT command without data field, then all or a subset of the DFs can be successively selected.
If the Le field contains only bytes set to ’00′, then all the bytes corresponding to the selection option should be returned within the limit of 256 for a short Le field, or 65 536 for an extended Le field. If the Le field is absent, i.e., for returning no file control information, then the response data field shall also be absent.

Table 39 P1
b8 b7 b6 b5 b4 b3 b2 b1 Meaning Command data field
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 x x 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 Selection by file identifier Select MF, DF or EF File identifier or absent Select child DF DF identifier Select EF under the current DF EF identifier Select parent DF of the current DF Absent
0 0 0 0 0 0 0 0 0 1 x x 0 1 0 0 Selection by DF name Select by DF name e.g., [truncated] application identifier
0 0 0 0 0 0 0 0 0 0 0 0 1 0 x x 1 0 0 0 1 0 0 1 Selection by path Select from the MF Path without the MF identifier Select from the current DF Path without the current DF identifier
Any other value is reserved for future use by ISO/IEC JTC 1/SC 17.

When present in the historical bytes (see 8.1.1) or in EF.ATR (see 8.2.1.1), the first software function table (see Table 86) indicates selection methods supported by the card.

 

Table 40 — P2
b8 b7 b6 b5 b4 b3 b2 b1 Meaning
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ———- x x 0 0 0 1 1 0 1 1 File occurrence —First or only occurrence —Last occurrence —Next occurrence —Previous occurrence
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 x x 0 0 0 1 1 0 1 1 ———- File control information (see 5.3.3 and Table 11) —Return FCI template, optional use of FCI tag and length —Return FCP template, mandatory use of FCP tag and length —Return FMD template, mandatory use of FMD tag and length —No response data if Lefield absent, or proprietary if Lefield present
 Any other value is reserved for future use by ISO/IEC JTC 1/SC 17.