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

BER-TLV length fields
In short form, the length field consists of a single byte where bit 8 is set to 0 and bits 7 to 1 encode the number of bytes in the value field. One byte can thus encode any number from zero to 127. NOTE Any number from one to 127 is encoded in the same way in BER-TLV length field as in Lc and Le fields. The encoding differs for zero, 128 and more. See for example, the coding of data objects in the GET DATA command in 7.4.2.
In long form, the length field consists of two or more bytes. Bit 8 of the first byte is set to 1 and bits 7 to 1 are not all equal, thus encoding the number of subsequent bytes in the length field. Those subsequent bytes encode the number of bytes in the value field.
ISO/IEC 7816 does not use the “indefinite length” specified by the basic encoding rules of ASN.1.
ISO/IEC 7816 supports length fields of one, two, … up to five bytes (see Table 8). In ISO/IEC 7816, the values ’80′ and ’85′ to ‘FF’ are invalid for the first byte of length fields.
Table 8 — BER-TLV length fields in ISO/IEC 7816

Mifare DESFire EV1 4K Proximity Smart Cards,Mifare DESFire EV1 4K Card,ISO 14443 A Mifare DESFire EV1 4K Cards,

Data fields, value fields, data objects and data elements
Any command or response data field may be encoded in BER-TLV, e.g., in a command-response pair where CLA indicates secure messaging (see 6) or where bit 1 of INS is set to 1 (odd INS code, see 5.1.2).
–Any BER-TLV data object is denoted {T-L-V} with a tag field followed by a length field encoding a number. Depending on whether the number is zero or not, the value field is absent (empty data object) or present.
–Any constructed BER-TLV data object is denoted {T-L- {T1-L1-V1} … – {Tn-Ln-Vn}} with a tag field followed by a length field encoding a number. If the number is not zero, then the value field of the constructed data object, i.e., the template, consists of one or more BER-TLV data objects, each one consisting of a tag field, a length field encoding a number and if the number is not zero, a value field.
Some data fields, e.g., commands for handling data units (see 7.2), the value fields of SIMPLE-TLV data objects and the value fields of some primitive BER-TLV data objects consist of data elements according to the specifications of the command or according to the tag of the data object.
Some data fields, e.g., commands for handling records (see 7.3) and the value fields of some primitive BER-TLV data objects consist of SIMPLE-TLV data objects.
Some data fields, e.g., commands for handling data objects (see 7.4) and the value fields of constructed BER-TLV data objects, i.e., the templates, consist of BER-TLV data objects.

Identification of data elements
The identification of data elements relies on the following principles.
1) If the number of bits representing a data element is not a multiple of eight, then the mapping into a byte or a string of bytes should be specified in the context of the respective data element. Unless otherwise specified, the appropriate number of bits shall be set to 1 in the last byte starting from bit 1.
2) At the interface between the card and the interface device, a data element is generally presented in the value field of a BER-TLV data object.
3) For purposes of retrieval and referencing in interchange, a data element shall be associated with the tag of a BER-TLV data object and the data element may be encapsulated in this data object.
4) A data element may be referenced directly by its associated BER-TLV tag. It may be associated with another data element that sets the context to which it belongs.
5) One or more command-to-perform data objects may indirectly reference a data element.
6) When present, data objects of the universal class (first byte from ’01′ to ’3F’) have their general meaning.
7) All the data objects of the application class (first byte from ’40′ to ’7F’) are interindustry, unless otherwise specified. This part and other parts of ISO/IEC 7816 allocate tags of the application class. Every application class tag not defined in ISO/IEC 7816 is reserved for ISO/IEC JTC 1/SC 17. 8) This document specifies many interindustry data elements. In addition to defining further interindustry data elements, ISO/IEC 7816-6 maintains an exhaustive list of the interindustry data elements specified in ISO/IEC 7816 at the time of publication.
9) There may be multiple occurrences of the same interindustry data object within the card.
10) In command and response data fields, all the data objects of the context-specific class (first byte from ’80′ to ‘BF’) shall be nested within interindustry templates, except for file control information (see 5.3.3) and secure messaging (see 6).
11) Illustrated by annex A, the subsequent clauses specify tag allocation schemes for identifying interindustry data objects in data fields. When needed, those tag allocation schemes use the interindustry data objects shown in Table 9 for notifying an authority responsible for tag allocation.

Table 9 — Interindustry data objects for tag allocation authority

Tag Value
’06′ Object identifier (encoding specified in ISO/IEC 8825-1, see examples in annex A)
’41′ Country code (encoding specified in ISO 3166-1[1]) and optional national data
’42′ Issuer identification number (encoding and registration specified in ISO/IEC 7812-1[3]) and optional issuer data
’4F’ Application identifier (AID, encoding specified in 8.2.1.2)

 

Compatible tag allocation scheme
These tag allocation schemes use interindustry data objects and further data objects.
These further data objects shall be nested within interindustry templates referenced by tags ’70′ to ’77′ (except for tag ’73′ reserved for nesting proprietary data objects, see 5.2.4.3) where the meaning of the application class tags is not defined in ISO/IEC 7816 except for tags ’41′, ’42′ and ’4F’ for identifying tag allocation authorities as shown in Table 9.
The use of the context-specific class (first byte from ’80′ to ‘BF’) within interindustry templates with tags ’65′ (cardholder-related data), ’66′ (card data), ’67′ (authentication data) and ’6E’ (application-related data) is deprecated.
In order to identify a compatible tag allocation scheme and the authority responsible for the scheme, an interindustry template referenced by tag ’78′ may be used. If present, such a template shall contain one of the interindustry data objects shown in Table 9, for identifying a tag allocation authority.
–If tag ’78′ is present in the initial data string (see 8.1.2) or in EF.ATR (see 8.2.1.1), then the authority is valid for the entire card.
–If tag ’78′ is present in DF management data (see 5.3.3), then the authority is valid within that DF.

Coexistent tag allocation scheme
These tag allocation schemes may use tags with an interpretation not defined in ISO/IEC 7816. In order to identify a coexistent tag allocation scheme and the authority responsible for the scheme, an interindustry template referenced by tag ’79′ shall be used. If present, such a template shall contain one of the interindustry data objects shown in Table 9, for identifying a tag allocation authority.
–If an authority is valid for the entire card, then tag ’79′ shall be present in the initial data string (see 8.1.2) or in EF.ATR (see 8.2.1.1).
–If an authority is valid within a DF, then tag ’79′ shall be present in the DF management data (see 5.3.3).
In such a scheme, all the interindustry data objects shall be nested within interindustry templates referenced by tag ’7E’. Moreover, tags ’79′ and ’7E’ shall not be given another interpretation, as well as tags ’62′, ’64′, ’6F’ (FCP, FMD and FCI templates, see 5.3.3) and ’7D’ (SM template, see 6).

Independent tag allocation scheme
These tag allocation schemes may use tags with another interpretation than ISO/IEC 7816, but which does not comply with 5.2.4.2. Such tag allocation schemes do not allow interchange and do not comply with this document.
The use of interindustry discretionary data objects with tags ’53′ for presenting discretionary data elements and ’73′ for nesting proprietary data objects in discretionary templates allows the use of proprietary data elements and data objects while remaining compliant with this document.