Documentation/driver-api/serial/serial-iso7816.rst GitHub 원문 ↗

Linux 6.18.37 · Driver API

ISO7816 Serial Communications

Smart-card UART mode, serial_iso7816 callback·ioctl과 userspace parameter 설정을 다루는 전문 번역입니다.

Source pathDocumentation/driver-api/serial/serial-iso7816.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약과 해설

serial-iso7816.rst:1-90

Dual-mode UART driver는 `iso7816_config` callback으로 smart-card mode를 적용합니다. Userspace는 `struct serial_iso7816`에 protocol, guard time, clock, transmission factor를 채우고 ISO 7816 ioctl로 설정합니다.

문서 구성
원문 줄내용
1-21ISO 7816 표준과 dual-mode hardware
22-34Kernel structure와 callback
35-86Userspace configuration 예제
87-90UAPI header reference

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 =============================
2 ISO7816 Serial Communications
3 =============================
4
5 1. Introduction
6 ===============
7
8 ISO/IEC7816 is a series of standards specifying integrated circuit cards (ICC)
9 also known as smart cards.
10
11 2. Hardware-related considerations
12 ==================================
13
14 Some CPUs/UARTs (e.g., Microchip AT91) contain a built-in mode capable of
15 handling communication with a smart card.
16
17 For these microcontrollers, the Linux driver should be made capable of
18 working in both modes, and proper ioctls (see later) should be made
19 available at user-level to allow switching from one mode to the other, and
20 vice versa.
21
22 3. Data Structures Already Available in the Kernel
23 ==================================================
24
25 The Linux kernel provides the serial_iso7816 structure (see [1]) to handle
26 ISO7816 communications. This data structure is used to set and configure
27 ISO7816 parameters in ioctls.
28
29 Any driver for devices capable of working both as RS232 and ISO7816 should
30 implement the iso7816_config callback in the uart_port structure. The
31 serial_core calls iso7816_config to do the device specific part in response
32 to TIOCGISO7816 and TIOCSISO7816 ioctls (see below). The iso7816_config
33 callback receives a pointer to struct serial_iso7816.
34
35 4. Usage from user-level
36 ========================
37
38 From user-level, ISO7816 configuration can be get/set using the previous
39 ioctls. For instance, to set ISO7816 you can use the following code::
40
41 #include <linux/serial.h>
42
43 /* Include definition for ISO7816 ioctls: TIOCSISO7816 and TIOCGISO7816 */
44 #include <sys/ioctl.h>
45
46 /* Open your specific device (e.g., /dev/mydevice): */
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(iso7816conf));
56
57 /* Enable ISO7816 mode: */
58 iso7816conf.flags |= SER_ISO7816_ENABLED;
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, &iso7816conf) < 0) {
77 /* Error handling. See errno. */
78 }
79
80 /* Use read() and write() syscalls here... */
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
91

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

ISO7816 serial communication

1-4

이 문서는 ISO/IEC 7816 smart-card serial communication의 kernel·userspace configuration interface를 설명합니다.

문서 식별 정보
항목
문서ISO7816 Serial Communications
대상Integrated circuit card / smart card UART mode

=============================
ISO7816 Serial Communications
=============================

ISO/IEC 7816 표준

5-10

ISO/IEC 7816은 smart card라고도 부르는 integrated circuit card(ICC)를 규정하는 일련의 표준입니다.

ISO 7816 용어
용어의미
ICCIntegrated circuit card
Smart cardICC의 일반 명칭
ISO/IEC 7816ICC interface와 communication 표준군

1. Introduction
===============

  ISO/IEC7816 is a series of standards specifying integrated circuit cards (ICC)
  also known as smart cards.

Dual-mode UART 고려사항

11-21

Microchip AT91 같은 일부 CPU/UART에는 smart card와 통신할 수 있는 built-in mode가 있습니다.

이런 microcontroller의 Linux driver는 일반 serial mode와 ISO 7816 mode 모두에서 동작해야 합니다. Userspace가 두 mode 사이를 양방향으로 전환할 수 있도록 적절한 ioctl도 제공해야 합니다.

Dual-mode UART
Userspace ioctlLinux UART driverNormal serial mode
Userspace ioctlLinux UART driverISO 7816 modeSmart card

하나의 hardware driver가 normal serial과 smart-card mode를 ioctl로 전환합니다.

2. Hardware-related considerations
==================================

  Some CPUs/UARTs (e.g., Microchip AT91) contain a built-in mode capable of
  handling communication with a smart card.

  For these microcontrollers, the Linux driver should be made capable of
  working in both modes, and proper ioctls (see later) should be made
  available at user-level to allow switching from one mode to the other, and
  vice versa.

serial_iso7816과 callback

22-34

Linux kernel은 ISO 7816 parameter를 ioctl에서 설정·구성하는 `serial_iso7816` structure를 제공합니다.

RS-232와 ISO 7816 두 mode를 모두 지원하는 driver는 `uart_port`의 `iso7816_config` callback을 구현해야 합니다. Serial core는 `TIOCGISO7816`·`TIOCSISO7816` ioctl에 응답해 device-specific 설정을 수행할 때 callback을 호출하며 `struct serial_iso7816` pointer를 전달합니다.

ISO 7816 configuration callback
`TIOCGISO7816` / `TIOCSISO7816`Serial core`uart_port.iso7816_config`Device-specific UART mode
`struct serial_iso7816 *``iso7816_config`

Userspace 구조체가 serial core를 거쳐 driver의 device-specific callback으로 전달됩니다.

3. Data Structures Already Available in the Kernel
==================================================

  The Linux kernel provides the serial_iso7816 structure (see [1]) to handle
  ISO7816 communications. This data structure is used to set and configure
  ISO7816 parameters in ioctls.

  Any driver for devices capable of working both as RS232 and ISO7816 should
  implement the iso7816_config callback in the uart_port structure. The
  serial_core calls iso7816_config to do the device specific part in response
  to TIOCGISO7816 and TIOCSISO7816 ioctls (see below). The iso7816_config
  callback receives a pointer to struct serial_iso7816.

Userspace ISO 7816 설정 예제

35-86

Userspace는 앞의 ioctl로 ISO 7816 configuration을 읽거나 설정합니다. 예제는 `linux/serial.h`와 `sys/ioctl.h`를 include하고 target device를 read/write mode로 엽니다.

`struct serial_iso7816`의 reserved field가 0이 되도록 초기화한 뒤 `SER_ISO7816_ENABLED`로 mode를 켭니다. `SER_ISO7816_T(0)` 또는 `SER_ISO7816_T(1)`로 protocol을 선택하고 guard time `tg`, clock `clk`, transmission factor `sc_fi`·`sc_di`를 설정합니다.

완성한 structure를 `TIOCSISO7816` ioctl로 적용한 뒤 `read()`·`write()`로 통신하고 device를 닫습니다. 원문 예제의 file descriptor 이름은 open 결과의 `fd`와 ioctl의 `fd_usart`가 다르므로 실제 code에서는 같은 descriptor로 맞춰야 합니다.

`serial_iso7816` 예제 설정
Field/flag예제 값·역할
`SER_ISO7816_ENABLED`ISO 7816 mode enable
`SER_ISO7816_T(0/1)`T=0 또는 T=1 protocol
`tg`Guard time, 예제 2
`clk`Clock frequency, 예제 3571200
`sc_fi`, `sc_di`Transmission factor, 예제 372와 1
`TIOCSISO7816`Configuration 적용

4. Usage from user-level
========================

  From user-level, ISO7816 configuration can be get/set using the previous
  ioctls. For instance, to set ISO7816 you can use the following code::

        #include <linux/serial.h>

        /* Include definition for ISO7816 ioctls: TIOCSISO7816 and TIOCGISO7816 */
        #include <sys/ioctl.h>

        /* Open your specific device (e.g., /dev/mydevice): */
        int fd = open ("/dev/mydevice", O_RDWR);
        if (fd < 0) {
                /* Error handling. See errno. */
        }

        struct serial_iso7816 iso7816conf;

        /* Reserved fields as to be zeroed */
        memset(&iso7816conf, 0, sizeof(iso7816conf));

        /* Enable ISO7816 mode: */
        iso7816conf.flags |= SER_ISO7816_ENABLED;

        /* Select the protocol: */
        /* T=0 */
        iso7816conf.flags |= SER_ISO7816_T(0);
        /* or T=1 */
        iso7816conf.flags |= SER_ISO7816_T(1);

        /* Set the guard time: */
        iso7816conf.tg = 2;

        /* Set the clock frequency*/
        iso7816conf.clk = 3571200;

        /* Set transmission factors: */
        iso7816conf.sc_fi = 372;
        iso7816conf.sc_di = 1;

        if (ioctl(fd_usart, TIOCSISO7816, &iso7816conf) < 0) {
                /* Error handling. See errno. */
        }

        /* Use read() and write() syscalls here... */

        /* Close the device when finished: */
        if (close (fd) < 0) {
                /* Error handling. See errno. */
        }

ISO 7816 structure reference

87-90

ISO 7816 serial structure와 ioctl 정의의 reference source는 `include/uapi/linux/serial.h`입니다.

Reference
번호Source path
[1]`include/uapi/linux/serial.h`

5. References
=============

 [1]    include/uapi/linux/serial.h