icezhou 发表于 2016-7-1 18:01:22

智能卡协议ISO7816

对于智能卡来说,主要是ATR与PPS的获取,其他的信息,就要参照具体卡的制造商来
通信了。
Structures and content
1,atr的整体构成:最多不超过32个字节
A reset operation results in the answer from the card c**isting of the initial character TS followed by at most 32 characters in the following order:- T0 ................... Format character (Mandatory)         - TAi, TBi, TCi, TDi ... Interface characters(Optional)         - T1, T2, ... ,TK ...... Historical characters (Optional)         - TCK .................. Check character    (Conditional)Reset | |    _________________________________________         _______   _________ |   |   |   |   |   |   |   |   |   |   |   |         |   |   |   |   | '-->| TS| T0|TA1|TB1|TC1|TD1|TA2|TB2|TC2|TD2| ......... | T1| ... | TK|TCK|   |___|___|___|___|___|___|___|___|___|___|_         _|___|_   _|__ |___|   TS: Initial character   TO: Format character   TAi : Interface character [ codes FI,DI ]   TBi : Interface character [ codes II,PI1 ]   TCi : Interface character [ codes N ]   TDi : Interface character [ codes Yi+1, T ]   T1, ... , TK : Historical characters (max,15)   TCK : Check characterFigure: General configuration of the Answer to Reset2,atr的第一个字节TS,也就是atr的位说明:The two possible values of TS (ten c**ecutive bits from start to bi and corresponding hexadecimal value) are
- Inverse convention : (Z)ZZAAAAAZ where logic level ONE is A, ba is b8 (msb is first), equal to $3F when decoded by inverse convention.
- Direct convention : (Z)ZZAZZZAAZ where logic level ONE is Z, ba is b1 (lsb first), equal to $3B when decoded by direct convention.
Startbabbbcbdbebfbgbhbi          Z   ____   _______   ___________         ______                  |   |   |   |   | Z   Z   Z |       |       |   |               (Z)| A | Z   Z | A |   or    |       | Z(Z)          A       |___|       |___|_A___A___A_|___|___|                  Figure: Initial character TS上面是对TS也就是atr的第一个字节atr的说明:当TS的逻辑电平时A时,atr=3B,正向传输;当TS的逻辑电平时Z时,atr=3F,反向传输。 3,atr的第二个字节atr,也就是T0的位说明:主要是其中的b1-b4组成的K,来说明历史字节数。这4个为最大可以表示15,这个K表明在这个字节后面还跟有K个历史字节,除开这K个历史字节后才是真正的atr数据。Format character T0 ------------------- The T0 character contains two parts: - The most significant half byte (b5, b6, b7, b8) is named Y1 and indicates with a logic level ONE the presence of subsequent characters TA1, TB1, TC1, TD1 respectively.
- The least significant half byte (b4 to b1) is named K and indicates the number (0 to 15) of historical characters.
,----,----,----,----,----,----,----,----,         | b8 | b7 | b6 | b5 | b4 | b3 | b2 | b1 |         '----'----'----'----'----'----'----'----'         :<------- Y1 ------>:<-------- K ------>:         Y1 : indicator for the presence of the interface characters                TA1 is transmitted when b5=1                TB1 is transmitted when b6=1                TC1 is transmitted when b7=1                TD1 is transmitted when b8=1         K : number of hitorical characters         Figure : Informati** provided by T0 4,协议类型说明字节:TAi, TBi, TCi (i=1, 2, 3, ... ) indicate the protocol parameters 此段代码就是根据上面的协议来解析atr数据的,可以仔细参考nRet = eis_smartcard_reset(index, atr);      atr_len += 2; //CLA/INS      if (atr & 0x0f0) {         if (atr & 0x80) {          // TD1 is transmitted when b8=1          td1_flag = 1;          atr_len ++;         }         else {          me->irdtV3Mgr->vdMgr->sc_info.protocol = IRDETO_V3_SC_T0;         }         if (atr & 0x40) {          atr_len ++;         }         if (atr & 0x20) {          atr_len ++;         }         if (atr & 0x10) {          atr_len ++;         }      }      if (td1_flag) {//TD1---T>0, TCK         if ((atr & 0x0f) == 0) {          me->irdtV3Mgr->vdMgr->sc_info.protocol = IRDETO_V3_SC_T0;         }         else if ((atr & 0x0f) == 1) {          me->irdtV3Mgr->vdMgr->sc_info.protocol = IRDETO_V3_SC_T1;         }         else if ((atr & 0x0f) == 14) {          me->irdtV3Mgr->vdMgr->sc_info.protocol = IRDETO_V3_SC_T14;         }         atr_len ++;      }      atr_len += (atr & 0x0f);
页: [1]
查看完整版本: 智能卡协议ISO7816