Commit | Line | Data |
---|---|---|
ad8c0eaa NF |
1 | ISO7816 SERIAL COMMUNICATIONS |
2 | ||
3 | 1. INTRODUCTION | |
4 | ||
5 | ISO/IEC7816 is a series of standards specifying integrated circuit cards (ICC) | |
6 | also known as smart cards. | |
7 | ||
8 | 2. HARDWARE-RELATED CONSIDERATIONS | |
9 | ||
10 | Some CPUs/UARTs (e.g., Microchip AT91) contain a built-in mode capable of | |
11 | handling communication with a smart card. | |
12 | ||
13 | For these microcontrollers, the Linux driver should be made capable of | |
14 | working in both modes, and proper ioctls (see later) should be made | |
15 | available at user-level to allow switching from one mode to the other, and | |
16 | vice versa. | |
17 | ||
18 | 3. DATA STRUCTURES ALREADY AVAILABLE IN THE KERNEL | |
19 | ||
20 | The Linux kernel provides the serial_iso7816 structure (see [1]) to handle | |
21 | ISO7816 communications. This data structure is used to set and configure | |
22 | ISO7816 parameters in ioctls. | |
23 | ||
24 | Any driver for devices capable of working both as RS232 and ISO7816 should | |
25 | implement the iso7816_config callback in the uart_port structure. The | |
26 | serial_core calls iso7816_config to do the device specific part in response | |
27 | to TIOCGISO7816 and TIOCSISO7816 ioctls (see below). The iso7816_config | |
28 | callback receives a pointer to struct serial_iso7816. | |
29 | ||
30 | 4. USAGE FROM USER-LEVEL | |
31 | ||
32 | From user-level, ISO7816 configuration can be get/set using the previous | |
33 | ioctls. For instance, to set ISO7816 you can use the following code: | |
34 | ||
35 | #include <linux/serial.h> | |
36 | ||
37 | /* Include definition for ISO7816 ioctls: TIOCSISO7816 and TIOCGISO7816 */ | |
38 | #include <sys/ioctl.h> | |
39 | ||
40 | /* Open your specific device (e.g., /dev/mydevice): */ | |
41 | int fd = open ("/dev/mydevice", O_RDWR); | |
42 | if (fd < 0) { | |
43 | /* Error handling. See errno. */ | |
44 | } | |
45 | ||
46 | struct serial_iso7816 iso7816conf; | |
47 | ||
48 | /* Reserved fields as to be zeroed */ | |
49 | memset(&iso7816conf, 0, sizeof(iso7816conf)); | |
50 | ||
51 | /* Enable ISO7816 mode: */ | |
52 | iso7816conf.flags |= SER_ISO7816_ENABLED; | |
53 | ||
54 | /* Select the protocol: */ | |
55 | /* T=0 */ | |
56 | iso7816conf.flags |= SER_ISO7816_T(0); | |
57 | /* or T=1 */ | |
58 | iso7816conf.flags |= SER_ISO7816_T(1); | |
59 | ||
60 | /* Set the guard time: */ | |
61 | iso7816conf.tg = 2; | |
62 | ||
63 | /* Set the clock frequency*/ | |
64 | iso7816conf.clk = 3571200; | |
65 | ||
66 | /* Set transmission factors: */ | |
67 | iso7816conf.sc_fi = 372; | |
68 | iso7816conf.sc_di = 1; | |
69 | ||
70 | if (ioctl(fd_usart, TIOCSISO7816, &iso7816conf) < 0) { | |
71 | /* Error handling. See errno. */ | |
72 | } | |
73 | ||
74 | /* Use read() and write() syscalls here... */ | |
75 | ||
76 | /* Close the device when finished: */ | |
77 | if (close (fd) < 0) { | |
78 | /* Error handling. See errno. */ | |
79 | } | |
80 | ||
81 | 5. REFERENCES | |
82 | ||
83 | [1] include/uapi/linux/serial.h |