APDU command format for Sim

Source: Internet
Author: User

The sim interacts with me through APDU.

APDU includes the command APDU and the corresponding APDU. The command APDU is in the format of "linoleic + INS + p1 + p2 + P3 + Data" and the response APDU is in the format of "Data + SW1 + sw2, when the me reads data from the sim, stplayer uses read and writes data to the upper layer in write mode. I have already written every command format and APDU format. I will not introduce it more here. I will mainly explain why it is written and how to judge the return value.

 

Corresponding parameter/data in MF or DF: 1-2: rfu, 3-4: available unallocated space in MF/DF, 5-6 File identification, 7: file type, 8-12: rfu, 13: length of optional fields, 14-34: Specific GSM data

GSM-specific data 14: file type, 15: number of direct DF in the current directory, 16: Number of direct EF in the current directory, 17: (CHV + Puk + ADM, 18: rfu, 19: chv1 status (bit 1 is a few verify chv1 tries to keep), 20: unblock chv1 status (bit 1 is a few unblock chv1 tries to keep), 21: chv2 status, 22: unblock
Chv2 status, 23: Fru, 24-34: management field, followed by rfu

Response Data/parameter in EF: 1-2: rfu, 3-4: file size, 5-6: file recognition, 7: file type, 8: rfu, 9-11: GSM access permission, 12: File status, 13: length of optional fields, 14: file type, 15: record length, rfu after 16

EF file category: 00: transparent EF (File Header + byte sequence), 01: Linear fixed ef (File Header + vertical record) 03: cyclic ef (File Header + vertical record, the last record has a pointer link. Update operations can only be performed in the previous mode)

File Type: 00: rfu 01: MF, 02: DF, 04: ef

Status word: correctly executed 90 00: Command ends normally 9f XX: Corresponding data with a length of xx

Reference Management 94 00: no EF selected 94 02: Out of range 94 04: File ID not found, or feature string not found 94 08: file inconsistent with command

Security management 98 02: CHV has not been initialized 98 04: it does not meet the access conditions or the CHV verification fails. At least one remaining attempt or unblock CHV verification fails, at least one remaining attempt or authentication failure (three consecutive CHV or ten unblocks) 98 08: conflict with the CHV status 98 10: conflict with the invalid file status 98 40: CHV Verification Failed, no remaining attempts or unblock CHV Verification Failed, no remaining attempts, CHV locks or unblock CHV locks 98 50: cannot be executed increase, has reached the maximum value

Application error 67 XX: Incorrect Parameter P3 (generally XX is 00), 6B XX: Incorrect Parameter P1 or P2, 6d XX: The command provides incorrect command code, 6e XX: indicates the wrong command type in the command. 6f XX indicates that no technical problem is diagnosed.

Select: You can only select the current file, son, father, and brother. After EF is selected in stplayer, the next operation fails and returns to the upper level. You must select EF again.

Status and get response: the difference is that the status command is not applicable to EF, where the Len required by P3 is the select Response Parameter sw2

Read_binary and update_binary: for transparent EF, offset high and offset low, the high and low offsets are indicated. The Len of read is the last bit in get response, that is, the length of the byte sequence, the update Len is the length of the byte sequence to be updated, that is, the length of the subsequent data.

Read_record and update_record: for linear fixed EF and cyclic EF, when cyclic EF is used, update can only use the previous method. The mode is described here. 02: Next record, 03: previous record, 04: absolute mode/current mode, where Len is the last bit of status or get response data, the range of record numbers is 1 to the maximum for linear fixed ef (3 and 4 bits for response data (file size) divided by this Len ), but for cyclic, although the next one of the last one is the first one, when you specify the record number of the last one + 1 and then use the current mode, it will happen.
94 02 error.

Seek: for linear fixed EF and cyclic EF, there are four modes: x0 (from the beginning to the end), x1 (from the end to the end), X2 (from the next to the next ), x3 (from the top), where X is 1, the record number is returned. If the operation fails, the record pointer remains unchanged. The query length is 1 to the record length.

Increase: for cyclic EF, each record is added with the data of this command, which specifies three bytes. I have searched all cysclic, the efacm and eflnd files are found. Since it specifies three bytes, I think it is set for efacm.

Verify_chv/change_chv/disable_chv/enable_chv/unblock_chv.

Invalidate/rehabilitate: There is a requirement before this command: The simulator gets the safe withdrawal condition. When I write it according to the steps in section 1117, efloci is selected before it, however, I couldn't try it in this file. Later I changed the file to efadn. I think efloci has no safe withdrawal conditions, but efadn does. Note that the command is executed and chv2 is verified. After the execution is successful, the GET_RESPONSE Response Data byte 12-bit 1 is 0, that is, the invalid file. At this time, only the select and rehabilitate commands can be executed. Here, rehabilitate is the command for restoring to valid.

Run_algorithm: This function requires a 16-byte random data next to dfgsm to return the key through get response.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.