Chinaunix首页 | 论坛 | 博客
  • 博客访问: 739936
  • 博文数量: 98
  • 博客积分: 4934
  • 博客等级: 上校
  • 技术积分: 1151
  • 用 户 组: 普通用户
  • 注册时间: 2009-06-12 19:55
文章分类

全部博文(98)

文章存档

2014年(1)

2013年(2)

2012年(4)

2011年(25)

2010年(33)

2009年(33)

分类: 嵌入式

2010-04-05 21:34:40

关于smartcard 通信协议

参考 ISO7816 智能卡标准.chm---7916 patr3

Structures and content

1,atr的整体构成:最多不超过32个字节

A reset operation results in the answer from the card consisting 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 character
Figure  : General configuration of the Answer to Reset
2,atr的第一个字节TS,也就是atr[0]的位说明:

The two possible values of TS (ten consecutive 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.

Start  ba  bb  bc  bd  be  bf  bg  bh  bi
          Z   ____     _______     ___________         ______
                  |   |   |   |   | Z   Z   Z |       |       |   |
               (Z)| A | Z   Z | A |     or    |       | Z  (Z)
          A       |___|       |___|_A___A___A_|___|___|

                    Figure  : Initial character TS
上面是对TS也就是atr的第一个字节atr[0]的说明:
当TS的逻辑电平时A时,atr[0]=3B,正向传输;
当TS的逻辑电平时Z时,atr[0]=3F,反向传输。
 
3,atr的第二个字节atr[1],也就是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 : Informations 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[1] & 0x0f0) {
       if (atr[1] & 0x80) {
        // TD1 is transmitted when b8=1
        td1_flag = 1;
        atr_len ++;
       }
       else {
        me->irdtV3Mgr->vdMgr->sc_info[index].protocol = IRDETO_V3_SC_T0;
       }
       if (atr[1] & 0x40) {
        atr_len ++;
       }
       if (atr[1] & 0x20) {
        atr_len ++;
       }
       if (atr[1] & 0x10) {
        atr_len ++;
       }
      }
      if (td1_flag) {//TD1---T>0, TCK
       if ((atr[atr_len - 1] & 0x0f) == 0) {
        me->irdtV3Mgr->vdMgr->sc_info[index].protocol = IRDETO_V3_SC_T0;
       }
       else if ((atr[atr_len - 1] & 0x0f) == 1) {
        me->irdtV3Mgr->vdMgr->sc_info[index].protocol = IRDETO_V3_SC_T1;
       }
       else if ((atr[atr_len - 1] & 0x0f) == 14) {
        me->irdtV3Mgr->vdMgr->sc_info[index].protocol = IRDETO_V3_SC_T14;
       }
       atr_len ++;
      }
      atr_len += (atr[1] & 0x0f);
转载:http://blog.csdn.net/turui/archive/2009/10/27/4732985.aspx
阅读(3192) | 评论(0) | 转发(2) |
0

上一篇:gdbserver用法简介

下一篇:ATR解析

给主人留下些什么吧!~~