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

WRITE RECORD command
The command initiates one of the following operations within an EF:
–the write-once of a record given in the command data field (the command shall be aborted if the record is not in the logical erased state);
–the logical-OR of the data bytes of a record already present in the card with the data bytes of the record given in the command data field;
–the logical-AND of the data bytes of a record already present in the card with the data bytes of the record given in the command data field.

By default, i.e., when the data coding byte (see Table 87) is absent in the historical bytes (see 8.1.1), in EF.ATR (see 8.2.1.1) and in the control parameters (see tag ’82′ in Table 12) of every file within the path from the MF to a given EF, the logical-OR shall apply for that EF. When using current record addressing, the command shall set the record pointer on the successfully written record. If applied to an EF supporting a cyclic structure with records of fixed size, the “previous” option (bits 3, 2 and 1 of P2 set to 011) behaves as APPEND RECORD. If the records are SIMPLE-TLV data objects (see 5.2.1), then Table 53 illustrates the command data field.

Table 51 WRITE RECORDcommand-response pair
CLA INS P1 P2 As defined in 5.1.1 ‘D2′ Record number (’00′ references the current record) See Table 52
Lcfield Present for encoding Nc> 0
Data field Record to be written
Lefield Absent for encoding Ne= 0
Data field Absent
SW1-SW2 See Tables 5 and 6 when relevant, e.g., ’63CX’ (see 7.3.2), ’6581′, ’6700′, ’6981′, ’6982′, ’6986′, ’6A81′, ’6A82′, ’6A83, ’6A84′, ’6A85′

 

Table 52 P2
b8 b7 b6 b5 b4 b3 b2 b1 Meaning
x x x x x Short EF identifier according to Table 47
————————- 0 x x 0 0 0 0 0 1 0 1 0 0 1 1 P1 set to ’00′ —First record —Last record —Next record —Previous record
—– 1 0 0 Record number in P1
Any other value is reserved for future use by ISO/IEC JTC 1/SC 17.

 

Table 53 Command data field (one complete record)
Tn (one byte) Ln (one or three bytes) All the bytes of Vn

UPDATE RECORD command
The command initiates the update of a specific record with the bits given in the command data field. When using current record addressing, the command shall set the record pointer on the updated record.
–If applied to an EF supporting a linear or cyclic structure with records of fixed size, then the command shall be aborted if the record size is different from the size of the existing record.
–If applied to an EF supporting a linear structure with records of variable size, then the command may be carried out when the record size is different from the size of the existing record.
–If applied to an EF supporting a cyclic structure with records of fixed size, the “previous” option (bits 3, 2 and 1 of P2 set to 011) behaves as APPEND RECORD.
 

Table 54 UPDATE RECORDcommand-response pair
CLA INS P1 P2 As defined in 5.1.1 ‘DC’ or ‘DD’ Record number (’00′ references the current record) See Table 52 (INS = ‘DC’) or 55 (INS = ‘DD’)
Lcfield Present for encoding Nc> 0
Data field Updating data (INS = ‘DC’), or offset data object and discretionary data object for encapsulating the updating data (INS = ‘DD’)
Lefield Absent for encoding Ne= 0
Data field Absent
SW1-SW2 See Tables 5 and 6 when relevant, e.g., ’63CX’ (see 7.3.2), ’6581′, ’6700′, ’6981′, ’6982′, ’6986′, ’6A81′, ’6A82′, ’6A83, ’6A84′, ’6A85′

If INS = ‘DC’ and if the records are SIMPLE-TLV data objects (see 5.2.1), then Table 53 illustrates the command data field.

If INS = ‘DD’, then the command partially updates the record referenced by P1. The command data field shall contain an offset data object (tag ’54′) for indicating the first byte to be updated in the record and a discretionary data object (tag ’53′ or ’73′) for encapsulating the updating data.

Table 55 P2 with INS = ‘DD’
b8 b7 b6 b5 b4 b3 b2 b1 Meaning
x x x x x Short EF identifier according to Table 47
————————- 1 x x 1 0 0 1 0 1 1 1 0 1 1 1 Record number in P1 —Replace —Logical AND —Logical OR —Logical XOR
Any other value is reserved for future use by ISO/IEC JTC 1/SC 17.