uTank-木头
每一个你不满意的现在,都有一个你没有努力的曾经。

一、ATR是什么

ATR也叫复位应答,是一个字节序列,这些字节是由卡作为对复位命令的响应发送给读卡器的。在I/O电路上,每个成功的复位操作都会导致I/O上的一个由初始字符TS开始,后跟最多32个字符的复位应答。ATR的作用是告诉读卡器,我是一张什么样的卡片,以便读卡器知道接下来该以什么样的方式和卡片通信。

二、ATR的数据元

ISO/IEC 7816-3标准中对ATR的数据串和数据元做了规定和描述。ATR的数据元和它们的意义:

数据元

说明

TS

起始字符

T0

格式字符

TA1,TB1,TC1,TD1,...

接口字符

T1,T2,... ,TK

历史字符

TCK

校验字符

 

三、ATR的基本数据结构

复位应答ATR的基本数据结构和数据元如下:

 

(一)起始字符TS

起始字符规定了用于在ATR中的所有数据和后继通信过程的约定。此外,TS字节含有特殊的位模式可由终端用以识别分频值。终端测量TS中前两个下降沿之间的时间并除以3,其结果就是一个etu的持续时间。然而,由于ATR的分频值固定在372,终端通常并不评估同步模式。

TS是ATR的强制部分,总是必须送出的。此字节只允许有两种编码:3B为正向约定,3F为反向约定

使用反向逻辑约定时, I/O的低电平状态等效于逻辑1,且该数据字节的最高位在起始位之后首先发送

使用正向逻辑约定时, I/O的高电平状态等效于逻辑1,且该数据字节的最低位在起始位之后首先发送

正向约定的波形如下,一般终端读取到的字符为3B:

反向约定的波形,一般终端读取到的字符为03:

 

(二)格式字符T0

格式字符T0含有一组位表明将要传送哪个接口字符,它同时也指出后继历史字符的个数。像TS一样,每个ATR中都必须有这个字节。

高半字节( b5-b8) 表示后续字符TA1到TD1是否存在。(b5对应TA1,b8对应TD1);

低半字节( b1-b4) 表明可选历史字符的数目( 0到15);

终端应接受包含任何T0值的ATR。一般情况下,基本ATR中,当仅选择T=0时, IC卡应回送T0=6x,表示字符TB1和TC1存在;当仅选择T=1时, IC卡应回送T0=Ex,表示字符TB1到TD1存在。

 

(三)接口字符

接口字符规定所用协议的所用传输参数,它们包含TAi、TBi、TCi、TDi各字节。然而,这些字节在ATR中是可选的,它们也可以被略去。由于对协议的所用参数的缺省值都做了规定,对于一般的通信处理可以不需要ATR中的接口字符。

接口字符可以分为全局接口字符和专用接口字符。全局接口字符规定基本传输协议参数,诸如分频值,它们用于所有后继的协议;专用接口字符则是用于指明特定的传输协议中的参数。“工作等待时间(work waiting time)”就是T=0协议中这类参数的典型例子。

全程接口字符基本上用于所有协议,出于历史原因(因为在ISO标准中,最初仅包含有T=0协议),这些字符中的几个仅和T=0协议有关。如果没有实现T=0协议,可以忽略它们,这这种情况下将使用缺省值。

TDi字节仅用于对任何跟随接口字符的链接保护,TDi字节的高4位组合有一个指示后继接口字符的存在的位模式。它类似于格式字符T0的编码,TDi字节的低4位则标识现行使用的传输协议。如果没有TDi字节的存在,则TAi+1、TBi+1、TCi+1和TDi+1都不传送。

其他接口字符(TAi、TBi、TCi)它们都不用于链接,而是规定了可用的传输协议,按照ISO/IEC 7816-3标准,它们的含义如下:

1.         全局接口字符TA1:(重要)

TA1高半字节 FI 用于确定 F 的值, F 为时钟速率转换因子。用于修改复位应答之后终端所提供的时钟频率。低半字节 DI 用于确定 D 的值, D 为位速率调节因子。用于调整复位应答之后所使用的位持续时间。etu =(F/D) * (1/f)

如果ATR中存在TA1,且TA2的b5='0',则:

  • 如果TA1的值在'11'到'13'之间,终端必须接收ATR,且必须立即采用指明的F和D值(F=372,D=1,2,4);
  • 如果TA1的值不在'11'到'13'之间,终端必须拒绝ATR,除非它支持并立即采用指明的条件;(ICS会有选择,TA1支持的值)

如果ATR中存在TA1,且TA2没有返回(协商模式),终端必须接收ATR且继续在后续信息交换过程中使用缺省值D=1和F=372,除非它支持使用协商参数的特殊方法。

如果ATR中没有返回TA1,则后续信息交换中使用缺省值D=1和F=372。

FI和DI编码如下:

FI

0000

0001

0010

0011

0100

0101

0110

0111

F

372

372

558

744

1116

1488

1860

RFU

FI

1000

1001

1010

1011

1100

1101

1110

1111

F

RFU

512

768

1024

1536

2048

RFU

RFU

 

DI

0000

0001

0010

0011

0100

0101

0110

0111

D

RFU

1

2

4

8

16

32

RFU

DI

1000

1001

1010

1011

1100

1101

1110

1111

D

12

20

RFU

RFU

RFU

RFU

RFU

RFU

2.         全局接口字符TB1:(没有意义了)

TB1传送PI1和II的值,PI1 在 b1 到 b5 位中定义,用于确定 IC 卡所需的编程电压 P 值;II 在 b6 和 b7 位中定义,用于确定 IC 卡所需的最大编程电流 I 值。一般情况下ATR中必须包含TB1=00,表示IC卡不使用VPP。

3.         全局接口字符TC1(重要)

TC1传送N值,N用于表示增加到最小持续时间的额外保护时间,此处的最小持续时间表示从终端发送到IC卡的、作为后续信息交换的两个连续字符的起始位下降沿之间的时间。N在TC1的b1-b8位为二进制编码,其值作为额外保护时间表示增加的etu数目,其值可在0到255之间任选。N=255具有特殊含义,表示在使用T=0协议时,两个连续字符的起始位下降沿之间的最小延迟时间可减少到12个etu,而在使用T=1协议时可减小到11个etu。

如果TC1值在00到FE之间,增加到字符间最小持续时间的额外保护时间为0到254个etu。对于后续传输,额外保护时间必须在12到266个etu之间。如果TC1=FF,则后续传输的字符间最小持续时间在使用T=0协议时为12个etu,使用T=1协议时为11个etu。

TC1只适用于终端向IC卡发送的两个连续字符间的时序,而不适用于IC卡向终端发送字符的情况,也不适用于在相反方向发送字符的情况。

4.         全局接口字符TB2:(没有意义了)

TB2传送PI2, PI2用于确定IC卡所需的编程电压P的值,当PI2出现时,它将取代TB1中回送的PI1的值。通常在ATR中不再使用。

5.         T=0传输协议专用的接口字符:

1)         专用接口字符TC2(重要)

TC2专用于T=0协议, 传输工作等待时间整数(WI),WI用来确定由IC卡发送的任意一个字符起始位下降沿与IC卡或终端发送的前一个字符起始位下降沿之间的最大时间间隔。工作等待时间为:960×D×WI etu。

若TC2字符不出现在ATR中,则使用工作等待时间的缺省值WI=10。

6.         T=1传输协议专用的接口字符:

1)         专用接口字符TA3(重要)

TA3(如果TD2中指明T=1)回送IC卡的信息域大小整数(IFSI),IFSI决定了IFSC,并指明了卡片可接收的块信息域的最大长度(INF)。 TA3以字节形式表示IFSC的长度,其取值范围从01到FE。 00和FF预留(RFU)。

2)         专用接口字符TB3(重要)

TB3(如果TD2中指明T=1)表明了用来计算字符等待时间CWT字组等待时间BWT的CWI和BWI值, TB3由两部分组成。低半字节(b1-b4)用于表明CWI值,而高半字节(b5-b8)用于表明BWI值。

BWI的值在0到4之间,CWI的值在0到5之间

3)         专用接口字符TC3(重要)

TC3(如果TD2中指明T=1)指明了所用的块错误校验码的类型,所用代码类型用b1位表示, b2到b8位未使用。

终端必须能够接收包括TC3='00'的ATR,拒绝TC3为其它任何值得ATR。

4)         全局接口字符TA2

TA2的存在与否表示IC卡是以“特定模式/专用模式”还是以“协商模式”工作。TA2的低半字节表明的协议类型正是ATR中第一次表明的协议类型。

TA2存在时是“特定模式/专用模式”;

TA2不存在时是“协商模式”;

“协商模式”:终端可以发送“协议和参数选择”指令PPS,选择要和IC卡进行通信的协议和相关参数。

(四)历史字符

很长一段时间,没有任何标准对历史字符做出规定,结果是随操作系统生产者而不同,它们包含了变化广泛的数据。

(五)校验字符TCK

TCK具有一个检验复位应答期间所发送数据完整性的值。TCK的值应使从T0到包括TCK在内的所有字节进行异或运算的结果为零。

如果在ATR中仅指出了T=0协议,TCK校验和可以不在ATR的尾部出现。在这种情况下,完全没有发送它,因为用奇偶校验已经知道了差错字节而在T=0协议中重复发送出错字节又是强制性的。相反,在T=1协议中,TCK字节必须出现,校验和的计算从字节T0开始,结束于最后的接口字符,如果有则是最后的历史字符。

 


 

【EMV文档】接收到的ATR不在EMV规定范围,终端需要的操作

Required terminal behaviour in the event that a terminal receives characters outside the range allowed by EMV.

/************************* TS *************************/

The terminal shall be capable of supporting both inverse and direct convention and shall accept an ATR containing TS having a value of either '3B' or '3F'. An ICC returning an ATR containing TS having any other value shall be rejected.

/************************* T0 *************************/

The terminal shall accept an ATR containing T0 of any value provided that the value returned correctly indicates and is consistent with the interface characters TA1 to TD1 and historical bytes actually returned.

/************************* TA1 *************************/

If TA1 is present in the ATR (indicated by b5 of T0 set to 1) and TA2 is returned with b5 = 0 (specific mode, parameters defined by the interface bytes), the terminal shall:

1. Accept the ATR if the value of TA1 is in the range '11' to '13', and immediately implement the values of F and D indicated (F=372 and D = 1, 2, or 4).

2. Reject the ATR if the value of TA1 is not in the range '11' to '13', unless it is able to support and immediately implement the conditions indicated.

If TA1 is present in the ATR (indicated by b5 of T0 set to 1) and TA2 is not returned (negotiable mode), the terminal shall accept the ATR and shall continue using the default values of D = 1 and F = 372 during all subsequent exchanges, unless it supports a proprietary technique for negotiating the parameters to be used.

If TA1 is absent from the ATR, the default values of D = 1 and F = 372 shall be used during all subsequent exchanges.

/************************* TB1 *************************/

In response to a cold reset, the terminal shall accept only an ATR containing TB1 = '00'.

In response to a warm reset the terminal shall accept an ATR containing TB1 of any value (provided that b6 of T0 is set to 1) or not containing TB1 (provided that b6 of T0 is set to 0) and shall continue the card session as though TB1 = '00' had been returned.

VPP shall never be generated.

/************************* TC1 *************************/

If the value of TC1 is in the range '00' to 'FE', between 0 and 254 etus of extra guardtime shall be added to the minimum character to character duration, which for subsequent transmissions shall be between 12 and 266 etus.

If the value of TC1 = 'FF', then the minimum character to character duration for subsequent transmissions shall be 12 etus if T=0 is to be used, or 11 etus if T=1 is to be used.

The terminal shall accept an ATR not containing TC1 (provided that b7 of T0 is set to 0), and shall continue the card session as though TC1 = '00' had been returned.

/************************* TD1 *************************/

The terminal shall accept an ATR containing TD1 with the m.s. nibble having any value (provided that the value returned correctly indicates and is consistent with the interface characters TA2 to TD2 actually returned), and the l.s. nibble having a value of '0' or '1'. The terminal shall reject an ATR containing other values of TD1.

/************************* TA2 *************************/

The terminal shall accept an ATR containing TA2 provided that all the following conditions are met:

1. The protocol indicated in the l.s. nibble is also the first indicated protocol in the ATR.

2. b5 = 0

3. The terminal is able to support the exact conditions indicated in the applicable interface characters and immediately uses those conditions.

Otherwise, the terminal shall reject an ATR containing TA2.

/************************* TB2 *************************/

The terminal shall reject an ATR containing TB2.

/************************* TC2 *************************/

The terminal shall:

1. reject an ATR containing TC2 = '00'

2. accept an ATR containing TC2 = '0A'

3. reject an ATR containing TC2 having any other value unless it is able to support it.

/************************* TD2 *************************/

The terminal shall accept an ATR containing TD2 with the m.s. nibble having any value (provided that the value returned correctly indicates and is consistent with the interface characters TA3 to TD3 actually returned), and the l.s. nibble having a value of '1' (or 'E' if the l.s. nibble of TD1 is '0'). The terminal shall reject an ATR containing other values of TD2.

/************************* TA3 *************************/

The terminal shall accept an ATR not containing TA3 (provided that b5 of TD2 is set to 0), and shall continue the card session using a value of '20' for TA3.

The terminal shall reject an ATR containing TA3 having a value in the range '00' to '0F' or a value of 'FF'.

/************************* TB3 *************************/

TB3 (if T=1 is indicated in TD2) indicates the values of the CWI and the BWI used to compute the CWT and BWT respectively. The l.s. nibble (b1–b4) is used to indicate the value of CWI, whilst the m.s. nibble (b5–b8) is used to indicate the value of BWI.

The terminal shall reject an ATR not containing TB3, or containing a TB3 indicating BWI greater than 4 and/or CWI greater than 5, or having a value such that 2^CWI ≤ (N + 1). It shall accept an ATR containing a TB3 having any other value.

Note: N is the extra guardtime indicated in TC1. When using T=1, if TC1='FF', the value of N shall be taken as –1. Since the maximum value for CWI allowed by these specifications is 5, note that when T=1 is used, TC1 shall have a value in the range '00' to '1E' or a value of 'FF' in order to avoid a conflict between TC1 and TB3.

/************************* TC3 *************************/

The terminal shall accept an ATR containing TC3 = '00'. It shall reject an ATR containing TC3 having any other value.

 

posted on 2016-06-05 11:12  uTank  阅读(12394)  评论(0编辑  收藏  举报