Back to home page

OSCL-LXR

 
 

    


0001 =============================
0002 ISO7816 Serial Communications
0003 =============================
0004 
0005 1. Introduction
0006 ===============
0007 
0008   ISO/IEC7816 is a series of standards specifying integrated circuit cards (ICC)
0009   also known as smart cards.
0010 
0011 2. Hardware-related considerations
0012 ==================================
0013 
0014   Some CPUs/UARTs (e.g., Microchip AT91) contain a built-in mode capable of
0015   handling communication with a smart card.
0016 
0017   For these microcontrollers, the Linux driver should be made capable of
0018   working in both modes, and proper ioctls (see later) should be made
0019   available at user-level to allow switching from one mode to the other, and
0020   vice versa.
0021 
0022 3. Data Structures Already Available in the Kernel
0023 ==================================================
0024 
0025   The Linux kernel provides the serial_iso7816 structure (see [1]) to handle
0026   ISO7816 communications. This data structure is used to set and configure
0027   ISO7816 parameters in ioctls.
0028 
0029   Any driver for devices capable of working both as RS232 and ISO7816 should
0030   implement the iso7816_config callback in the uart_port structure. The
0031   serial_core calls iso7816_config to do the device specific part in response
0032   to TIOCGISO7816 and TIOCSISO7816 ioctls (see below). The iso7816_config
0033   callback receives a pointer to struct serial_iso7816.
0034 
0035 4. Usage from user-level
0036 ========================
0037 
0038   From user-level, ISO7816 configuration can be get/set using the previous
0039   ioctls. For instance, to set ISO7816 you can use the following code::
0040 
0041         #include <linux/serial.h>
0042 
0043         /* Include definition for ISO7816 ioctls: TIOCSISO7816 and TIOCGISO7816 */
0044         #include <sys/ioctl.h>
0045 
0046         /* Open your specific device (e.g., /dev/mydevice): */
0047         int fd = open ("/dev/mydevice", O_RDWR);
0048         if (fd < 0) {
0049                 /* Error handling. See errno. */
0050         }
0051 
0052         struct serial_iso7816 iso7816conf;
0053 
0054         /* Reserved fields as to be zeroed */
0055         memset(&iso7816conf, 0, sizeof(iso7816conf));
0056 
0057         /* Enable ISO7816 mode: */
0058         iso7816conf.flags |= SER_ISO7816_ENABLED;
0059 
0060         /* Select the protocol: */
0061         /* T=0 */
0062         iso7816conf.flags |= SER_ISO7816_T(0);
0063         /* or T=1 */
0064         iso7816conf.flags |= SER_ISO7816_T(1);
0065 
0066         /* Set the guard time: */
0067         iso7816conf.tg = 2;
0068 
0069         /* Set the clock frequency*/
0070         iso7816conf.clk = 3571200;
0071 
0072         /* Set transmission factors: */
0073         iso7816conf.sc_fi = 372;
0074         iso7816conf.sc_di = 1;
0075 
0076         if (ioctl(fd_usart, TIOCSISO7816, &iso7816conf) < 0) {
0077                 /* Error handling. See errno. */
0078         }
0079 
0080         /* Use read() and write() syscalls here... */
0081 
0082         /* Close the device when finished: */
0083         if (close (fd) < 0) {
0084                 /* Error handling. See errno. */
0085         }
0086 
0087 5. References
0088 =============
0089 
0090  [1]    include/uapi/linux/serial.h