Understanding Smart Card Timing

原文出处:http://leijiye.blog.163.com/blog/static/5699763720103135131428/


Understanding Smart Card Timing

Lei Jiye

Version 1.0, 2010-3-25

1.  Preface

There are various timing in all smart card sessions, including: card activation, card deactivation, cold/warm reset, answer to reset (ATR) reception, and data transfers. As a smart card driver developer, it is very important to understand smart card timing in those sessions. Understanding smart card timing is a guide to understand smart card communication, it is very useful for developing smart card driver.

 

In this document, various concepts and timing are described based on contact smart card, memory card and contactless smart card are out of scope of this document. This document can be treated as an interpretation of ISO/CEI 7816-3.

 

Figure 1-1 Contact smart card

2.  Abbreviation

Abbreviation

Description

Vcc

Voltage, contact C1

RST

Reset, contact C2

CLK

Clock, contact C3

AUX1

Auxiliary 1, Supplementary contact C4

GND

Ground, contact C5

Vpp

Programming voltage, contact C6

I/O

Input/output for serial communication, contact C7

AUX2

Auxiliary2, Supplementary contact C8

 

 

SCI

Smart Card Interface, it can be considered as smart card reader.

ATR

Answer to Reset

ETU

Elementary time unit is the time of transferring one bit on the I/O line

ICC

Integrated Circuit Card, i.e. smart card

ASC

Asynchronous Serial Controller

 

 

CGT

Character Guard Time, also abbreviated as guardtime

WWT

Work Waiting Time

CWT

Character Waiting Time

CWI

Character Waiting time Integer

BGT

Block Guard Time

BWT

Block Waiting Time

 

 

 

 

 

 

 

 

3.  Basic concepts for smart card timing

3.1.      ETU

ETU (elementary time unit) is the time of transferring one bit on the I/O line.

1 ETU = (F / D) * (1 / f)

l  F is the clock rate conversion factor.

l  D is the baud rate adjustment factor.

l  The minimum value of the frequency f shall be 1 MHz. The maximum value is given by table 7 as a function of FI. The default maximum value is 5 MHz.

 

For computing the ETU, the pair of factors F and D shall take one of the following three pairs of values:

l  Fi and Di, the values indicated by the card in TA(1) according to tables 3-1 and 3-2. If TA(1) is absent, then Fi and Di are set at default values.

l  Fd and Dd, the default values 372 and 1.

l  Fn and Dn, the values negotiated by a successful PPS exchange in ranges Fd to Fi and Dd to Di.

Table 3-1 – Fi, indicated values of the clock rate conversion factor

FI

0000

0001

0010

0011

0100

0101

0110

0111

Fi

372

372

558

744

1116

1488

1860

RFU

f(max)MHz

4

5

6

8

12

16

20

-

 

FI

1000

1001

1010

1011

1100

1101

1110

1111

Fi

RFU

512

768

1024

1536

2048

RFU

RFU

f(max)MHz

-

5

7.5

10

15

20

-

-

 

Table 3-2 – Di, indicated values of the baud rate adjustment factor

DI

0000

0001

0010

0011

0100

0101

0110

0111

Di

RFU

1

2

4

8

16

32

RFU

 

DI

1000

1001

1010

1011

1100

1101

1110

1111

Di

12

20

RFU

RFU

RFU

RFU

RFU

RFU

 

3.2.      Clock and baudrate

Smart card processors usually do not have internal clock generators. An externally supplied clock is therefore necessary, and it is applied to the CLK contact. This clock also provides the reference for data transmission rates.

 

In smart card driver, the clock can be configured to choose the clock source (source clock value) and the division factor to derive the input clock for smart card.

 

In this document, baudrate is equal to bit rate, since only one bit is transmitted for each state change. Baudrate or bit rate is the data transmission rate on the I/O line.

Baudrate = (Clock / F) * D.

l  During reset, F = 372, D = 1. In case Fclk = 3.5712 MHz, Baudrate = 3571200 / 372 = 9600 b/s.

l  During command and response, baudrate is fixed by F and D in the ATR. For example, the Smart Cards NAGRAVISION indicates T=1, F=512 and D=16 in their ATR. So, with these cards, the SC interface is configured for a baudrate of 3571200 / 512 * 16 = 111600 b/s.

 

4.  Activation and deactivation

After card insertion, to avoid damage and undefined state, the card must be precisely activated. And also it should be precisely deactivated when the card is removed. The sequences of activation and deactivation are reflected in ISO/CEI 7816-3.

Figure 4-1 Activation and deactivation

 

5.  Cold reset and warm reset

 

With VCC and CLK provided, the smart card starts working, then it can be reset via the RST line. This requires a low level to be first applied to this line, with the actual reset being initiated by the subsequent rising edge.

There are two ways a card is reset:

l  Cold Reset: When the supply voltage is turned off and on again. Ejecting the card out and inserting again will have the same effect.

l  Warm Reset: When a Signal is sent through RST pin to reset the ICC without power &clock off.

 

Figure 5-1 Cold Reset

 

Figure 5-2 Warm Reset

 

 

 

6.  Character frame

A character consists of ten consecutive moments; each moment is either at state Z (high) or at state A (low).

l  m1: the “start moment”, shall be at state A;

l  m2 to m9: convey a byte of 8 bits;

l  m10: conveys the “parity bit”.

Figure 6-1 Character frame

 

(In the above character frame, 0.2 ETU is the sampling time.)

 

In smart card driver, usually some settings for character frame must be set in Asynchronous Serial Controller (ASC) registers. These settings include:

(1)    ASC mode: ASC mode can be 7-bit data + parity, 8-bit data, 8-bit data + parity, 8-bit data + wake up bit, or 9-bit data.

(2)    Parity mode: Even parity or odd parity.

(3)    Stop bits: 0.5, 1, 1.5 or 2 stop bits. The time allocated to the stop bits is designated as the ‘guard time’.

 

7.  Time between characters

7.1.      Character Guardtime (CGT)

7.1.1. Guardtime concept

The guardtime (Character Guardtime, CGT) is the delay between the end of the previous character and the start of the next character. So, the delay between two consecutives characters (between start leading edges) is at least 12 ETU, including a character duration (10+/-0.2) ETU plus a guardtime (minimum guardtime).

 

While in guardtime, the card and the interface device shall remain both in reception mode (in error-free operation), so the I/O is maintained at state Z. The guardtime consists of a minimum guardtime and an extra guardtime.

l  The minimum guardtime is 2 ETU.

l  The extra guardtime is defined by TC1 (N) in the ATR.

i.e., guardtime = minimum guardtime + extra guardtime = 2 ETU + (Q * N / f).

 

In the ATR, TC1 codes the parameter N over the eight bits (b8 to b1). N is the extra guardtime used to send characters from the interface device to the card. No extra guardtime is used to send characters from the card to the interface device (only minimum guardtime is required).

In the formula, Q shall take either one of the two values:

l  F / D, i.e., the values used for computing the ETU, if T = 15 is absent in the ATR.

l  Fi / Di, if T = 15 is present in the ATR.

Note: if TA(1) is present and T=15 is absent, then Q = F / D = f * ETU, (1 ETU = (F/D)*(1/f))

guardtime = 2 ETU + (Q * N / f) = 2 ETU + N * ETU = (2 + N) ETU.

 

The range of N is 0 to 255.

(1)      The default value is N = 0.

(2)      In the range 0 to 254, N indicates that, before ready to receive the next character, the card requires the delay of (12 ETU + (Q * N / f)) from the leading edge of the previous character (sent either by the card or by the interface device).

(3)      N = 255 indicates that, during the transmission protocol, the minimum delay between the leading edges of two consecutive characters is the same in both directions of transmission. The value of this minimum delay is

l  12 ETU for T = 0,

l  11 ETU for T = 1.

 

7.1.2. Guardtime in smart card driver

In smart card driver, extra guardtime is programmed in GUARDTIME register. For example, in a 32-bit GUARDTIME register, only bit[7~0] is used for setting the extra guardtime.

guardtime = (GUARDTIME + 2) mode 256

l  For a guardtime of 2 ETU, GUARDTIME register value is 0.

l  Extra guardtime of 1-254 ETU can be programmed.

l  If a value of 255 is written into GUARDTIME register, this means the total guardtime is 1 ETU, and characters are transmitted every 11 ETU. Note that this setting is only applicable in T = 1 mode.

 

 

7.2.      Work waiting time (WWT)

7.2.1. Work waiting time concept

The interval between the start leading edge of any character sent by the card and the start leading edge of the previous character (sent either by the card or by the interface device) shall not exceed 960 * WI * (Fi / f). This maximum delay is named the work waiting time (WWT). (ISO/CEI 7816-3, 8.2)

 

Figure 7-1 Work waiting time

In an answer to reset, the interface character TC2 codes the integer value WI over eight bits b8 to b1. When no TC2 appears in the answer to reset, the default value of WI is 10.

 

For example, Using default values and the assumed card clock frequency of 3571200, we have: WWT = 960 * 10 * (372 / 3571200) = 1 second.

If interface byte TA(1) is present, F = Fi, then, D * ETU = F / f = Fi / f,

WWT = 960 * WI * (Fi / f) = 960 * WI * D * ETU

 

7.2.2. Work waiting time in smart card driver

Work waiting time is usually controlled by a timer. A timeout interrupt will be raised if there is no character received from the card within WWT. (There is no register used to control the WWT.) The timer is enabled in the ISR of ASC, after the previous Rx/Tx interrupt and before receiving the next character from smart card.

 

The timer should be disabled in several cases:

l  error occurred,

l  the expected character has been received,

l  ASC changes from receiving to transmitting.

 

 

7.3.      Character waiting time (CWT)

Character waiting time (CWT) is a concept in T=1 protocol. It is defined as the maximum delay between the leading edge of two consecutive characters in the block.

Figure 7-2 Character waiting time

CWT is calculated from CWI (Character Waiting time Integer) by the following formula

CWT = (11 + 2CWI) ETU

The bits b4 to b1 of the first TB(i) give CWI from 0 to 15. The default value of CWI is 13.

 

8.  Time between blocks in T = 1 protocol

8.1.      Block Guard Time

The block guard time is defined as the minimum interval between the leading edge of the final byte and the leading edge of the first byte in the opposite direction. The purpose of the block guard time is to provide the sender with a minimum time interval in which to switch over from transmitting to receiving.

 

The block guard time has a standard fixed value of 22 etu. In a smart card running at 3.5712

MHz with a divider value of 372, this yields an interval of approximately 2.3 ms.

 

BGT = 22 etu

 

8.2.      Block Waiting Time

The block waiting time is the maximum allowed interval between the leading edge of the last byte of a block sent to the card and the leading edge of the first byte returned by the card.

If this waiting period expires without a response being received from the card, the terminal may assume that the card is faulty and initiate an appropriate response. This could for example be a card reset, followed by a new attempt to establish communication.

Figure 8-1 Block waiting time

 

The value of the BWT is given by the formula:

BWT = 2BWI * 960 * 372/f s + 11 ETU

The bits b8 to b5 of the first TB(i) in ATR give BWI from 0 to 9.  The values 10 to 15 are reserved for future use. The default value of BWI is 4.

 

If no BWI value is given in the ATR, the default value of 4 is used. With 3.5712 MHz and a divider value of 372, this gives 1.6 s as the value for the block waiting time:

BWT = 24 × 960 × 372 / 3,571,200 Hz s + 11 etu = 24 × 0.1 s + 11 etu ≈ 1.6 s

 

9.  Time between protocol messages

The entire procedure for data transmission to and from the smart card is represented in Figure 9-1.

 

After a card has been inserted in a terminal, its contacts are first mechanically connected to those of the terminal. The five active contacts are then electrically enabled in the correct sequence. Following this, the card automatically executes a power-on reset and then sends an Answer to Reset (ATR) to the terminal (see section 4 “activation and deactivation”). The terminal evaluates the ATR, which contains various parameters relating to the card and data transmissions, and then sends the first command. The card processes the command and generates a response, which it sends back to the terminal. This back-and-forth interplay of commands and responses continues until the card is deactivated.

 

Figure 9-1 Smart card data transmission

During the data transmission procedure, there are some important timing constraints:

l  t0: It’s the time between the rising edge of RST signal and ATR, i.e. tc in the reset diagram, 400 clock <= t0 <= 40 000 clock.

l  t1and t3: For t1 and t3, the minimum value is character guardtime (CGT), and there is no maximum value. After receiving ATR or the response to the last command, the next command can be sent at any time after CGT elapses.

However, for t1, a long enough waiting time is recommended, which allows the smart card to finish its initialization after ATR. A typical example is initialization for smart card with NAND Flash. If the smart card has to initialize NAND Flash driver and file system, it takes a long time (about 2 seconds) to do this initialization. If the first command comes soon after activation and reset, the smart card is not prepared for receiving and processing this command because of its long time initialization, and then the first command will not be responded in time, and the smart card will be considered as mute.

l  t2: It’s the time between command and response, CGT <= T2 <= WWT. A timer is needed for timing t2. If the response doesn’t come in WWT, a time-out interrupt will be raised.

 

 

10.        Conclusion

In this document, smart card timing is described from low-level (reset, character transmission, block transmission) to high level (protocol messages), for more details, please refer to “smart card handbook” and ISO/CEI 7816-3.

All the description is based on my experience on Irdeto T = 0 card, Watchdata SIM card. Special timing constraints in T = 1 or T = 14 protocol are not explored much more in this document. Especially for T = 14 protocol, please refer to the specification provided by the smart card manufacture.

 

 

11.        References

[1]      Smart Handbook, Third Edition. Wolfgang Rankl and Wolfgang Effing, Giesecke & Devrient GmbH, Munich, Germany. Translated by Kenneth Cox, Kenneth Cox Technical Translations, Wassenaar, The Netherlands. John Wiley & Sons, Ltd.

[2]      ISO/CEI 7816-3: 1997, Information technology – Identification cards – Integrated circuit(s) cards with contacts – Part 3: Electronic signals and transmission protocols.

[3]       


1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看REAdMe.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看REAdMe.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看READme.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值