[SIM/USIM] Command APDU structure

2014. 10. 6. 10:55Mobile/SIM

Contents of command APDU

CodeLengthDescriptionGrouping
CLA1Class of instructionHeader
INS1Instruction code
P11Instruction parameter 1
P21Instruction parameter 2
Lc0 or 1Number of bytes in the command data fieldBody
DataLcCommand data string
Le0 or 1Maximum number of data bytes expected in response of the command

일반적으로 Command APDU는 위 표와 같이 구성된다. 특히 Header 부분은 mandatory이며, Body는 optional이다.
위 항목으로 나올 수 있는 APDU는 총 4가지가 된다.


Class of APDUs
CaseStructure
1  CLA  INS  P1  P2 
2  CLA  INS  P1  P2  Le
3  CLA  INS  P1  P2  Lc  Data
4  CLA  INS  P1  P2  Lc  Data  Le 


이런 Command APDU에 좀더 구체적인 의미를 부여하기 위해서는 아래와 같이 APDU의 각 Content를 정의한다.

Coding of Instruction Byte of the Commands for a telecom application
COMMANDCLAINS
Command APDUs

SELECT FILE0XA4
STATUS8XF2
READ BINARY0XB0
UPDATE BINARY0XD6
READ RECORD0XB2
UPDATE RECORD0XDC
SEARCH RECORD0XA2
INCREASE8X32
RETRIEVE DATA8XCB
SET DATA8XDB
VERIFY0X20
CHANGE PIN0X24
DISABLE PIN0X26
ENABLE PIN0X28
UNBLOCK PIN0X2C
DEACTIVATE FILE0X04
ACTIVATE FILE0X44
AUTHENTICATE0X88, 89
GET CHALLENGE0X84
TERMINAL CAPABILITY8XAA
TERMINAL PROFILE8010
ENVELOPE80C2
FETCH8012
TERMINAL RESPONSE8014
MANAGE CHANNEL0X70
MANAGE SECURE CHANNEL0X73
TRANSACT DATA0X75
Transmission oriented APDUs

GET RESPONSE0XC0


여기서 CLA를 보면 대부분 0X, 혹은 8X로 되어 있는 것을 볼 수 있다.
이에 대한 사항은 ETSI 102.221의 Table 10.3을 확인해 볼 필요가 있다.

Coding of class byte for standard logical channels
b8b7b6b5b4b3b2b1ValueMeaning
0000----'0X'The coding is according to the first interindustry values of CLA byte defined in ISO/IEC 7843-4
1010----'AX'Coded as for '0X' unless stated otherwise
1000----'8X'Structured as for '0X', coding and meaning is defined in the present document.
----XX---Secure Messaging indication.
------XX-Logical channel number from 0 to 3.

즉, 위의 b4 ~ b1의 값에 따라 'X'값이 결정이 된다. 
그런데 일반적으로는 Logical channel number로 많이 사용이 되기 때문에 CLA = 0x00, INS = 0x0A라면 logical channel 0을 이용한 SELECT FILE이라고 인식하면 된다.
CLA = 0x01, INS = 0x0A는 logical channel 1을 이용한 SELECT FILE.
CLA = 0x02, INS = 0x0A는 logical channel 2을 이용한 SELECT FILE.
CLA = 0x03, INS = 0x0A는 logical channel 3을 이용한 SELECT FILE.




출처 : http://jasmine125.tistory.com/581