Smart Card Data Transmission
The possibility of two-way communications is a prerequisite for all interactions between a smart card and a terminal. However, only a single line is available. Digital data are exchanged between the card and the terminal via this electrical connection. Since only one line exists, the card and the terminal must take turns transmitting data, with the other party acting as the recipient. This alternate transmitting and receiving of data is called a half-duplex procedure. A full-duplex procedure, in which both parties can transmit and receive simultaneously, is presently not implemented for smart cards.However, since most smart card processors have two I/O ports, and two of the eight contacts are reserved for future applications (such as a second I/O connection or USB interface), full-duplex operation would certainly be technically possible. This will doubtless be implemented in hardware and operating systems in the medium term. Communication with the card is always initiated by the terminal. The card always responds to commands from the terminal, which means that the card never sends data without an external stimulus. This yields a pure master–slave relationship, with the terminal as master and the card as slave. The proactive command procedure,1 which is used by telecommunications smart cards and allows the smart card to send commands to the terminal, is also based on the standard master–slave arrangement. 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.2 Following this, the card automatically executes a power-on reset and then sends an Answer to Reset (ATR) to the terminal. The terminal evaluates theATR, 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. Between the ATR and the first command sent to the card, the terminal can also send a Protocol Parameter Selection (PPS) command. The terminal can use this command, which like the ATR is independent of the transmission protocol, to set various transmission parameters for the card’s transmission protocol.

The entire procedure for data transmission to and from the smart card can be represented using the OSI layer model. This differentiates electrical events on the I/O line, logical processes in the actual transmission protocol and the behavior of applications that use these processes. The behavior and interactions within and between these layers are specified in several international standards. These relationships are illustrated in Figure 6.3. In this chapter, the asynchronous transmission protocols are described with respect to relevant standards in terms of their functions. All allowed parameters and settings within the context of the protocol are described. In practice, it often happens that smart cards do not support all options of the transmission protocol, due to the limitations of available memory. From a functional perspective, the various options can be regarded as simply a range of possibilities from which an optimum set can be selected for a particular application or smart card. The important consideration is that the selected parameters should not be too exotic, in order to allow the card to communicate with as many different types of terminals as possible. In terminals, the situation with regard to data transmission protocols is somewhat different. There the full functionality of the relevant standard is normally implemented, since sufficient memory is available.

THE PHYSICAL TRANSMISSION LAYER
The general parameters of the physical transmission layer are specified in the international smart card standard ISO/IEC 7816-3. This is the fundamental standard for all aspects of communications at the physical level. The entire data exchange with the smart card takes place digitally, which means that it employs only the logic values 0 and 1. The voltage levels used are the conventional values for digital technology, namely +5 V, +3 V and +1.8 V, with 0 V as a reference. The choice of whether a physical high or lowlevel represents a logic 1 is freely definable, with the actual selection being indicated by the card in the first byte of the ATR. Here the ‘direct convention’ means that a logic 1 is represented by the+1.8-V,+3-V or+5-V level, while the ‘inverse convention’means that the +1.8-V, +3-V or +5-V level represents a logic 0. In either case, the level of the I/O line is always high in the quiescent state, which is when no data are being transmitted. Communications between a smart card and the outside world take place serially. Data handled by the processor in the form of bytes must therefore be converted into a serial bit stream. To this end, each byte is separated into its eight individual bits, which are then sent over the line one after the other. The bit order depends on the convention used.With the direct convention, the first data bit after the start bit is the least significant bit in the byte. With the inverse convention, the most significant bit is sent directly following the start bit. Data transmission between the card and the terminal is asynchronous, which means that each byte sent must be provided with supplementary synchronization bits. A start bit is added to the beginning of each transmitted byte to mark the start of the transmission sequence for the recipient. At the end of each byte, the sender also adds a parity bit for error detection and one or two stop bits. The time allocated to the stop bits is designated as the ‘guard time’ in the T=0 protocol. In principle, the guard time is a sort of stop bit. The receiver and the transmitter can both use this time to prepare for the next byte transmission. The parity of each byte must always be even. The parity bit thus has the logic value 1 if the number of ones in the byte is odd, or 0 if the number of ones in the byte is even. Since smart card microcontrollers do not have timers that are independent of the applied clock signal, it is not possible to specify an absolute time interval for an individual data bit. The bit interval is therefore specified in terms of the applied clock. For this purpose, a ‘divider’ is defined to indicate the number of clock pulses per bit interval. The duration of one bit is called an ‘elementary time unit’ (etu). It is thus meaningless to specify the data transmission rate of a smart card as a fixed value (such as 9600 bit/s), since the rate is proportional to the rate of the applied clock. However, there are essentially only two divider values in use worldwide: 372 and 512. For some time now, even smaller divider values are being used increasingly often to increase the transmission rate. Reducing the divider value makes it increasingly difficult for the card’s operating system to receive and transmit data, since the processor has progressively less time to perform these tasks. For instance, if data are received using a divider value of 64, the processor has only 64 clock intervals to recognize each bit and transfer it to the I/O buffer. To calculate the transmission rates that can be achieved with the standard divider values, we only need to consider the clock rate and the divider value, as shown in the following examples:
3.5712 MHz ÷ 372 = 9600bit/s
4.9152 MHz ÷ 512 = 9600bit/s

A data transmission rate of exactly 9600 bit/s can thus be obtained with both commonly used clock frequencies (3.5712 MHz and 4.9152 MHz).3 The desire for a transmission rate of 9600 bit/s is the reason for the awkward divider values. In the early days of smart card technology, inexpensive quartz crystals were available for only very few frequencies. Standard crystals for use in television sets were used, and the divider values for the cards were set to obtain a data transmission rate of 9600 bit/s, which was a common value at the time. A clock rate of 4.77 MHz was used in early PCs for the same reason, since this was compatible with US television sets, and in principle a PC could thus be connected to a television set. If we assume that 5 MHz is the highest practical value for the clock rate and 32 is the minimum divider value, we obtain the current upper limit for the data transmission rate, at least as long as transmission is performed using software executed by the processor:
5 MHz ÷ 32 = 156,250 bit/s

Of course, it is possible to reduce the divider value even further in order to increase the transmission rate. However, this significantly increases the amount of program code in the card, and so it is not normally done, due to the limited amount of available memory. Many newsmart card microcontrollers have a built-in hardware unit (a universal asynchronous receiver/transmitter, or UART) that handles data transmission via the serial interface. This sharply reduces the amount of software overhead in the card for handling data transmission, making it possible to use much higher data transmission rates. Such an interface unit can easily achieve the standard transmission rate of 111.6 kbit/s.The bit interval can be calculated from the clock rate and the divider value. With a 3.5712 MHz clock frequency and a divider value of 372, we obtain a bit interval of 104 μs, which by definition corresponds to one etu (elementary time unit) for this divider value.We can construct the diagram shown in Figure 6.6 for various transmission rates. The timing of serial data transmissions does not have to be strictly controlled. For technical reasons, a certain amount of tolerance is allowed. Since many smart card microcontrollers do not have interface hardware, it is sometimes necessary to exploit the allowed tolerance to accommodate software implementations of the interface function. The timing variation between the falling edge of the start bit and the final transition of the nth bit may not exceed ±0.2 etu. As far as the transmitter is concerned, this means that while the variation in the timing of individual bits may be up to ±0.2 etu, the variation over several bits is also not allowed to exceed this value. The sum of the timing variations over a group of bits must therefore not exceed the allowed tolerance.

Particularly when data are transmitted via a physical conductor, it is relatively common for signal dropouts and overshoots to occur. Consequently, the incoming signal is sampled multiple times rather than just once. Triple sampling followed by a 2-of-3 majority vote is a commonly used method. Small distortions in signal levels can thus be compensated at relatively little effort. Increasing the number of samples to five or seven would make little sense, given the generally good quality of the smart card data transmissions and the amount of extra effort thiswould entail. The three samples should be distributed as evenly as possible over the received bit interval, in order to best compensate for brief dropouts. This is done by sampling at the middle of the bit interval and at both ends of the ‘test zone’, as defined by the applicable timing tolerances for byte transmission. The optimum sampling points can be defined by determining the boundaries of the test zone and the midpoint of the bit interval. However, these are not specified in any standard.5 Sampling within the ‘transition zone’ is not allowed, since the signal level is invalid within this zone.