Page 79 - From GMS to LTE
P. 79

Global System for Mobile Communications (GSM)  65


               CLA   INS   P1   P2   P3               Data

               Figure 1.51  Structure of a command APDU.


               Table 1.8  Examples for APDU commands.

               Command                           ID    P1          P2         Length

               Select (open file)                A4    00          00         02
               Read binary (read file)           B0    Offset high  Offset low  Length
               Update binary (write file)        D6    Offset high  Offset low  Length
               Verify CHV (check PIN)            20    00          ID         08
               Change CHV (change PIN)           24    00          ID         10
               Run GSM algorithm (RAND, SRES, Kc, …)  88  00       00         10



                               Data                   SW1 SW2

               Figure 1.52  Response APDU.

                If a file is to be read from the SIM card, the command APDU contains, among other
               information, the file ID and the number of bytes to read from the file. If the file is of
               cyclic or linear fixed type, the command also contains the record number. If access to
               the file is allowed, the SIM card then returns the requested information in one or more
               response APDUs.
                If the mobile device wants to write some data into a file on the SIM card, the command
               APDUs contain the file ID and the data to be written into the file. In the response APDU,
               the SIM card then returns a response as to whether the data were successfully written
               to the file.
                Figure 1.51 shows the format of a command APDU. The first field contains the class
               of instruction, which is always 0xA0 for GSM. The instruction (INS) field contains the
               ID of the command that has to be executed by the SIM card.
                Table 1.8 shows some commands and their IDs. The fields P1 and P2 are used for
               additional parameters for the command. P3 contains the length of the following data
               field, which contains the data that the mobile device would like to write on the SIM card.
                The format of a response APDU is shown in Figure 1.52. Apart from the data field, the
               response also contains two fields called SW1 and SW2. These are used by the SIM card
               to inform the mobile device whether the command was executed correctly.
                For example, to open a file for reading or writing, the mobile device sends a SELECT
               command to the SIM card. The SELECT APDU is structured as shown in Figure 1.53.
                As a response, the SIM card replies with a response APDU that contains a number of
               fields. Some of them are shown in Table 1.9.
                For a complete list of information returned for the example, see [35]. In the next step,
               the READ BINARY or WRITE BINARY APDU can be used to read or modify the file.
   74   75   76   77   78   79   80   81   82   83   84