Understanding Smart Card Timing

本文详细介绍了智能卡的各种时序概念和技术细节,包括激活、复位、字符帧传输及协议消息之间的时序要求等,为智能卡驱动开发者提供实用指南。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原文出处: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]       


内容概要:本文档介绍了Intel oneAPI工具集及其行业倡议,旨在提供跨架构编程解决方案,支持加速计算并打破专有锁定。oneAPI允许开发者选择最佳硬件加速技术,实现跨CPU、GPU、FPGA及其他加速器的性能优化。它兼容多种编程语言和模型(如C++、Python、SYCL、OpenMP等),并通过开放标准确保未来兼容性和代码重用。文档详细描述了oneAPI工具包的功能,包括渲染、高性能计算(HPC)、物联网(IoT)、AI分析等领域的应用。此外,还介绍了DPC++(数据并行C++)编程语言及其在不同硬件架构上的执行方式,以及Intel提供的各种优化库和分析工具,如Intel MKL、IPP、VTune Profiler等。最后,通过实际案例展示了oneAPI在医疗成像和超声产品中的成功应用。 适合人群:软件开发人员、硬件工程师、系统架构师、OEM/ODM厂商、ISV合作伙伴,特别是那些需要在多种硬件平台上进行高效编程和性能优化的专业人士。 使用场景及目标:①为跨架构编程提供统一的编程模型,简化多硬件平台的应用开发;②利用开放标准和工具集,提高代码可移植性和重用性;③通过优化编译器和技术库,提升应用程序的性能表现;④借助分析和调试工具,快速识别并解决性能瓶颈。 其他说明:Intel oneAPI工具集不仅支持现有编程语言和模型,还提供了强大的中间件和框架支持,适用于多样化的应用负载需求。开发者可以通过Intel DevCloud获取实际操作经验,同时利用DPC++兼容性工具将现有CUDA代码迁移到SYCL环境。此外,文档还提供了详细的性能优化指南和未来产品路线图,帮助用户更好地规划技术演进路径。
“班级网站设计源代码”项目是网页设计初学者及有一定基础的设计师的理想学习资源。它提供了完整的源代码,涵盖构建可运行班级网站所需的所有文件。网页设计包含前端开发、后端开发和用户体验设计等多个方面,而这个项目能帮助你深入理解这些技术的实际应用。 首先,HTML是网页的基础,它通过标签定义网页的结构,如标题、段落、图片和链接等。在这个项目中,你可以清晰地看到如何利用HTML搭建网页的框架。其次,CSS用于控制网页的样式和布局,赋予网页视觉美感。通过设置颜色、字体、布局以及响应式设计,CSS确保网站能在不同设备上良好显示。项目中的源代码展示了如何运用CSS实现多样化的样式效果。 JavaScript则是实现网页动态功能的关键,它能够处理用户交互、数据操作和动画效果。在这个班级网站中,JavaScript代码可能用于实现按钮点击事件、表单验证或页面动态更新等功能。此外,响应式设计是现代网页设计的重要组成部分。借助媒体查询和流式布局,该班级网站能够自动适应手机、平板和桌面电脑等不同设备的屏幕尺寸。 为了提高开发效率,现代网页设计常常会引入前端框架和库,如Bootstrap或Vue.js。这些工具提供了一套预设的样式和组件,简化了网页的构建过程。虽然具体是否使用了这些框架需要查看源代码,但了解它们的工作原理对于提升网页设计能力至关重要。 如果班级网站包含用户登录、留言等功能,那么后端技术(如PHP、Node.js或Python)和数据库(如MySQL或MongoDB)也会被涉及。这部分代码主要负责处理数据的提交、验证和存储,以及与服务器的通信。 用户体验(UX)和界面设计也是网页设计的重要方面。一个优秀的网站不仅要有美观的外观,还要具备良好的易用性。通过观察和分析这个班级网站的布局和交互设计,你可以学习如何提升用户体验,例如如何设计清晰的导航、易读的信息和直观的操作流程。 通过深入研究“
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值