1 ============================= 2 ISO7816 Serial Communications 3 ============================= 4 5 1. Introduction 6 =============== 7 8 ISO/IEC7816 is a series of standards specify 9 also known as smart cards. 10 11 2. Hardware-related considerations 12 ================================== 13 14 Some CPUs/UARTs (e.g., Microchip AT91) conta 15 handling communication with a smart card. 16 17 For these microcontrollers, the Linux driver 18 working in both modes, and proper ioctls (se 19 available at user-level to allow switching f 20 vice versa. 21 22 3. Data Structures Already Available in the Ke 23 ============================================== 24 25 The Linux kernel provides the serial_iso7816 26 ISO7816 communications. This data structure 27 ISO7816 parameters in ioctls. 28 29 Any driver for devices capable of working bo 30 implement the iso7816_config callback in the 31 serial_core calls iso7816_config to do the d 32 to TIOCGISO7816 and TIOCSISO7816 ioctls (see 33 callback receives a pointer to struct serial 34 35 4. Usage from user-level 36 ======================== 37 38 From user-level, ISO7816 configuration can b 39 ioctls. For instance, to set ISO7816 you can 40 41 #include <linux/serial.h> 42 43 /* Include definition for ISO7816 ioct 44 #include <sys/ioctl.h> 45 46 /* Open your specific device (e.g., /d 47 int fd = open ("/dev/mydevice", O_RDWR 48 if (fd < 0) { 49 /* Error handling. See errno. 50 } 51 52 struct serial_iso7816 iso7816conf; 53 54 /* Reserved fields as to be zeroed */ 55 memset(&iso7816conf, 0, sizeof(iso7816 56 57 /* Enable ISO7816 mode: */ 58 iso7816conf.flags |= SER_ISO7816_ENABL 59 60 /* Select the protocol: */ 61 /* T=0 */ 62 iso7816conf.flags |= SER_ISO7816_T(0); 63 /* or T=1 */ 64 iso7816conf.flags |= SER_ISO7816_T(1); 65 66 /* Set the guard time: */ 67 iso7816conf.tg = 2; 68 69 /* Set the clock frequency*/ 70 iso7816conf.clk = 3571200; 71 72 /* Set transmission factors: */ 73 iso7816conf.sc_fi = 372; 74 iso7816conf.sc_di = 1; 75 76 if (ioctl(fd_usart, TIOCSISO7816, &iso 77 /* Error handling. See errno. 78 } 79 80 /* Use read() and write() syscalls her 81 82 /* Close the device when finished: */ 83 if (close (fd) < 0) { 84 /* Error handling. See errno. 85 } 86 87 5. References 88 ============= 89 90 [1] include/uapi/linux/serial.h
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.