Skip to content

Commit 99e406d

Browse files
noglitchldesroches
authored andcommitted
tty/serial_core: add ISO7816 infrastructure
Add the ISO7816 ioctl and associated accessors and data structure. Drivers can then use this common implementation to handle ISO7816. Signed-off-by: Nicolas Ferre <nicolas.ferre@microchip.com> [ludovic.desroches@microchip.com: squash and rebase, removal of gpios, checkpatch fixes] Signed-off-by: Ludovic Desroches <ludovic.desroches@microchip.com>
1 parent bebc608 commit 99e406d

11 files changed

Lines changed: 96 additions & 0 deletions

File tree

arch/alpha/include/uapi/asm/ioctls.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@
102102
#define TIOCGPTLCK _IOR('T', 0x39, int) /* Get Pty lock state */
103103
#define TIOCGEXCL _IOR('T', 0x40, int) /* Get exclusive mode state */
104104
#define TIOCGPTPEER _IO('T', 0x41) /* Safely open the slave */
105+
#define TIOCGISO7816 _IOR('T', 0x42, struct serial_iso7816)
106+
#define TIOCSISO7816 _IOWR('T', 0x43, struct serial_iso7816)
105107

106108
#define TIOCSERCONFIG 0x5453
107109
#define TIOCSERGWILD 0x5454

arch/mips/include/uapi/asm/ioctls.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@
9393
#define TIOCGPTLCK _IOR('T', 0x39, int) /* Get Pty lock state */
9494
#define TIOCGEXCL _IOR('T', 0x40, int) /* Get exclusive mode state */
9595
#define TIOCGPTPEER _IO('T', 0x41) /* Safely open the slave */
96+
#define TIOCGISO7816 _IOR('T', 0x42, struct serial_iso7816)
97+
#define TIOCSISO7816 _IOWR('T', 0x43, struct serial_iso7816)
9698

9799
/* I hope the range from 0x5480 on is free ... */
98100
#define TIOCSCTTY 0x5480 /* become controlling tty */

arch/parisc/include/uapi/asm/ioctls.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262
#define TIOCGPTLCK _IOR('T', 0x39, int) /* Get Pty lock state */
6363
#define TIOCGEXCL _IOR('T', 0x40, int) /* Get exclusive mode state */
6464
#define TIOCGPTPEER _IO('T', 0x41) /* Safely open the slave */
65+
#define TIOCGISO7816 _IOR('T', 0x42, struct serial_iso7816)
66+
#define TIOCSISO7816 _IOWR('T', 0x43, struct serial_iso7816)
6567

6668
#define FIONCLEX 0x5450 /* these numbers need to be adjusted. */
6769
#define FIOCLEX 0x5451

arch/powerpc/include/uapi/asm/ioctls.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@
102102
#define TIOCGPTLCK _IOR('T', 0x39, int) /* Get Pty lock state */
103103
#define TIOCGEXCL _IOR('T', 0x40, int) /* Get exclusive mode state */
104104
#define TIOCGPTPEER _IO('T', 0x41) /* Safely open the slave */
105+
#define TIOCGISO7816 _IOR('T', 0x42, struct serial_iso7816)
106+
#define TIOCSISO7816 _IOWR('T', 0x43, struct serial_iso7816)
105107

106108
#define TIOCSERCONFIG 0x5453
107109
#define TIOCSERGWILD 0x5454

arch/sh/include/uapi/asm/ioctls.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@
9595
#define TIOCGPTLCK _IOR('T', 0x39, int) /* Get Pty lock state */
9696
#define TIOCGEXCL _IOR('T', 0x40, int) /* Get exclusive mode state */
9797
#define TIOCGPTPEER _IO('T', 0x41) /* Safely open the slave */
98+
#define TIOCGISO7816 _IOR('T', 0x42, struct serial_iso7816)
99+
#define TIOCSISO7816 _IOWR('T', 0x43, struct serial_iso7816)
98100

99101
#define TIOCSERCONFIG _IO('T', 83) /* 0x5453 */
100102
#define TIOCSERGWILD _IOR('T', 84, int) /* 0x5454 */

arch/sparc/include/uapi/asm/ioctls.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#define TIOCGEXCL _IOR('T', 0x40, int) /* Get exclusive mode state */
2828
#define TIOCGRS485 _IOR('T', 0x41, struct serial_rs485)
2929
#define TIOCSRS485 _IOWR('T', 0x42, struct serial_rs485)
30+
#define TIOCGISO7816 _IOR('T', 0x43, struct serial_iso7816)
31+
#define TIOCSISO7816 _IOWR('T', 0x44, struct serial_iso7816)
3032

3133
/* Note that all the ioctls that are not available in Linux have a
3234
* double underscore on the front to: a) avoid some programs to

arch/xtensa/include/uapi/asm/ioctls.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@
107107
#define TIOCGPTLCK _IOR('T', 0x39, int) /* Get Pty lock state */
108108
#define TIOCGEXCL _IOR('T', 0x40, int) /* Get exclusive mode state */
109109
#define TIOCGPTPEER _IO('T', 0x41) /* Safely open the slave */
110+
#define TIOCGISO7816 _IOR('T', 0x42, struct serial_iso7816)
111+
#define TIOCSISO7816 _IOWR('T', 0x43, struct serial_iso7816)
110112

111113
#define TIOCSERCONFIG _IO('T', 83)
112114
#define TIOCSERGWILD _IOR('T', 84, int)

drivers/tty/serial/serial_core.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,58 @@ static int uart_set_rs485_config(struct uart_port *port,
13101310
return 0;
13111311
}
13121312

1313+
static int uart_get_iso7816_config(struct uart_port *port,
1314+
struct serial_iso7816 __user *iso7816)
1315+
{
1316+
unsigned long flags;
1317+
struct serial_iso7816 aux;
1318+
1319+
if (!port->iso7816_config)
1320+
return -ENOIOCTLCMD;
1321+
1322+
spin_lock_irqsave(&port->lock, flags);
1323+
aux = port->iso7816;
1324+
spin_unlock_irqrestore(&port->lock, flags);
1325+
1326+
if (copy_to_user(iso7816, &aux, sizeof(aux)))
1327+
return -EFAULT;
1328+
1329+
return 0;
1330+
}
1331+
1332+
static int uart_set_iso7816_config(struct uart_port *port,
1333+
struct serial_iso7816 __user *iso7816_user)
1334+
{
1335+
struct serial_iso7816 iso7816;
1336+
int i, ret;
1337+
unsigned long flags;
1338+
1339+
if (!port->iso7816_config)
1340+
return -ENOIOCTLCMD;
1341+
1342+
if (copy_from_user(&iso7816, iso7816_user, sizeof(*iso7816_user)))
1343+
return -EFAULT;
1344+
1345+
/*
1346+
* There are 5 words reserved for future use. Check that userspace
1347+
* doesn't put stuff in there to prevent breakages in the future.
1348+
*/
1349+
for (i = 0; i < 5; i++)
1350+
if (iso7816.reserved[i])
1351+
return -EINVAL;
1352+
1353+
spin_lock_irqsave(&port->lock, flags);
1354+
ret = port->iso7816_config(port, &iso7816);
1355+
spin_unlock_irqrestore(&port->lock, flags);
1356+
if (ret)
1357+
return ret;
1358+
1359+
if (copy_to_user(iso7816_user, &port->iso7816, sizeof(port->iso7816)))
1360+
return -EFAULT;
1361+
1362+
return 0;
1363+
}
1364+
13131365
/*
13141366
* Called via sys_ioctl. We can use spin_lock_irq() here.
13151367
*/
@@ -1394,6 +1446,14 @@ uart_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
13941446
case TIOCSRS485:
13951447
ret = uart_set_rs485_config(uport, uarg);
13961448
break;
1449+
1450+
case TIOCSISO7816:
1451+
ret = uart_set_iso7816_config(state->uart_port, uarg);
1452+
break;
1453+
1454+
case TIOCGISO7816:
1455+
ret = uart_get_iso7816_config(state->uart_port, uarg);
1456+
break;
13971457
default:
13981458
if (uport->ops->ioctl)
13991459
ret = uport->ops->ioctl(uport, cmd, arg);

include/linux/serial_core.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ struct uart_port {
137137
void (*handle_break)(struct uart_port *);
138138
int (*rs485_config)(struct uart_port *,
139139
struct serial_rs485 *rs485);
140+
int (*iso7816_config)(struct uart_port *,
141+
struct serial_iso7816 *iso7816);
140142
unsigned int irq; /* irq number */
141143
unsigned long irqflags; /* irq flags */
142144
unsigned int uartclk; /* base uart clock */
@@ -252,6 +254,7 @@ struct uart_port {
252254
struct attribute_group *attr_group; /* port specific attributes */
253255
const struct attribute_group **tty_groups; /* all attributes (serial core use only) */
254256
struct serial_rs485 rs485;
257+
struct serial_iso7816 iso7816;
255258
void *private_data; /* generic platform data pointer */
256259
};
257260

include/uapi/asm-generic/ioctls.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@
7979
#define TIOCGPTLCK _IOR('T', 0x39, int) /* Get Pty lock state */
8080
#define TIOCGEXCL _IOR('T', 0x40, int) /* Get exclusive mode state */
8181
#define TIOCGPTPEER _IO('T', 0x41) /* Safely open the slave */
82+
#define TIOCGISO7816 _IOR('T', 0x42, struct serial_iso7816)
83+
#define TIOCSISO7816 _IOWR('T', 0x43, struct serial_iso7816)
8284

8385
#define FIONCLEX 0x5450
8486
#define FIOCLEX 0x5451

0 commit comments

Comments
 (0)