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

UPDATE BINARY command
The command initiates the update of bits already present in an EF with the bits given in the command data field. When the process is completed, each bit of each specified data unit will have the value specified in the command data field.

Table 44 UPDATE BINARYcommand-response pair
CLA INS P1-P2 As defined in 5.1.1 ‘D6′ or ‘D7′ See 7.2.2
Lc field Present for encoding Nc> 0
Data field String of data units to be updated (INS = ‘D6′), or offset data object and discretionary data object for encapsulating the string of updating data units (INS = ‘D7′)
Le field Absent for encoding Ne= 0
Data field Absent
SW1-SW2 See Tables 5 and 6 when relevant, e.g., ’63CX’ (see 7.2.2), ’6581′, ’6700′, ’6981′, ’6982′, ’6B00′ (offset outside the EF)

SEARCH BINARY command
The command initiates a search within an EF supporting data units. The response data field gives the offset of a data unit: the byte string at the returned offset within the EF shall have the same value as the search string in the command data field. The response data field is absent either because the Le field is absent, or because no match is found. If the search string is absent, then the response data field gives the offset of the first data unit in a logically erased state.

Table 45 SEARCH BINARYcommand-response pair
CLA INS P1-P2 As defined in 5.1.1 ‘A0′ or ‘A1′ See 7.2.2
Lc field Absent for encoding Nc= 0, present for encoding Nc> 0
Data field Absent or search string (INS = ‘A0′), or offset data object and discretionary data object for encapsulating the search string (INS = ‘A1′)
Le field Absent for encoding Ne= 0, present for encoding Ne> 0
Data field Absent or offset of the first data unit matching the command data field (INS = ‘A0′), or offset data object indicating the first data unit matching the search string (INS = ‘A1′)
SW1-SW2 See Tables 5 and 6 when relevant, e.g., ’6282′, ’6982′

ERASE BINARY command
The command sets [part of] the content of an EF to its logical erased state, sequentially, starting from a given offset.
–If INS = ’0E’, then, if present, the command data field encodes the offset of the first data unit not to be erased. This offset shall be higher than the one encoded in P1-P2. If the data field is absent, then the command erases up to the end of the file.
–If INS = ’0F’, then, if present, the command data field shall consist of zero, one or two offset data objects. If there is no offset, then the command erases all the data units in the file. If there is one offset, it indicates the first data unit to be erased; then the command erases up to the end of the file. Two offsets define a sequence of data units: the second offset indicates the first data unit not to be erased; it shall be higher than the first offset.

Table 45 — SEARCH BINARYcommand-response pair
CLA INS P1-P2 As defined in 5.1.1 ‘A0′ or ‘A1′ See 7.2.2
Lc field Absent for encoding Nc= 0, present for encoding Nc> 0
Data field Absent or search string (INS = ‘A0′), or offset data object and discretionary data object for encapsulating the search string (INS = ‘A1′)
Le field Absent for encoding Ne= 0, present for encoding Ne> 0
Data field Absent or offset of the first data unit matching the command data field (INS = ‘A0′), or offset data object indicating the first data unit matching the search string (INS = ‘A1′)
SW1-SW2 See Tables 5 and 6 when relevant, e.g., ’6282′, ’6982′

Record handling
Records

Within each EF supporting records, a record number and / or a record identifier shall reference each record. Reference to a record not contained in the EF is an error.
Referencing by record number — Each record number is unique and sequential.
–Within each EF supporting a linear structure, the record numbers shall be sequentially assigned when writing or appending, i.e., in the order of creation; the first record (number one) is the first created record.
–Within each EF supporting a cyclic structure, the record numbers shall be sequentially assigned in the opposite order, i.e., the first record (number one) is the most recently created record.

The following additional rule is defined for linear structures and for cyclic structures.
–Zero shall refer to the current record, i.e., that record referenced by the record pointer.

Referencing by record identifier — Each record identifier is provided by an application. Several records may have the same record identifier, in which case data contained in the records may be used for discriminating between them. If a record is a SIMPLE-TLV data object in a data field, then the record identifier is the first byte of the data object, i.e., the SIMPLE-TLV tag.

Referencing by record identifier shall induce the management of a record pointer. A reset of the card, a SELECT and any command using a valid short EF identifier for accessing an EF can affect the record pointer. Referencing by record number shall not affect the record pointer.

Each time a reference is made with a record identifier, the logical position of the target record shall be indicated: the first or last occurrence, the next or previous occurrence relative to the record pointer.
–Within each EF supporting a linear structure, the logical positions shall be sequentially assigned when writing or appending, i.e., in the order of creation. The first created record is in the first logical position.
–Within each EF supporting a cyclic structure, the logical positions shall be sequentially assigned in the opposite order, i.e., the most recently created record is in the first logical position.

The following additional rules are defined for linear structures and for cyclic structures.
–The first occurrence shall be the record with the specified identifier and in the first logical position; the last occurrence shall be the record with the specified identifier and in the last logical position.
–If there is a current record, then the next occurrence shall be the closest record with the specified identifier but in a greater logical position than the current record; the previous occurrence shall be the closest record with the specified identifier but in a smaller logical position than the current record.
–If there is no current record, then the next occurrence shall be equivalent to the first occurrence; the previous occurrence shall be equivalent to the last occurrence.
–Zero shall refer to the first, last, next or previous record in the numbering sequence, independently from the record identifier.