summaryrefslogtreecommitdiff
path: root/usr/src/uts/common/sys/usb/clients/ccid/uccid.h
blob: 032ac7327404ec60791cd868741257cae56ac137 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
 * This file and its contents are supplied under the terms of the
 * Common Development and Distribution License ("CDDL"), version 1.0.
 * You may only use this file in accordance with the terms of version
 * 1.0 of the CDDL.
 *
 * A full copy of the text of the CDDL should have accompanied this
 * source.  A copy of the CDDL is also available via the Internet at
 * http://www.illumos.org/license/CDDL.
 */

/*
 * Copyright 2019, Joyent, Inc.
 */

#ifndef _SYS_USB_UCCID_H
#define	_SYS_USB_UCCID_H

/*
 * Definitions for the userland CCID interface.
 */

#include <sys/types.h>
#include <sys/usb/clients/ccid/ccid.h>

#ifdef __cplusplus
extern "C" {
#endif

/*
 * The maximum size of a normal APDU. This is the upper bound of what a user can
 * read or write to a given card.
 */
#define	UCCID_APDU_SIZE_MAX	261

/*
 * This is the maximum length of an ATR as per ISO/IEC 7816-3:2006.
 */
#define	UCCID_ATR_MAX		33


#define	UCCID_IOCTL	(('u' << 24) | ('c' << 16) | ('d') << 8)

#define	UCCID_VERSION_ONE	1
#define	UCCID_CURRENT_VERSION	UCCID_VERSION_ONE

/*
 * Attempt to obtain exclusive access. If the UCN_TXN_DONT_BLOCK flag is
 * specified, the ioctl will return immediately if exclusive access cannot be
 * gained. Otherwise, it will block in an interruptible fashion. The argument is
 * a uccid_cmd_txn_begin_t.
 */
#define	UCCID_CMD_TXN_BEGIN	(UCCID_IOCTL | 0x01)
#define	UCCID_TXN_DONT_BLOCK	0x01

typedef struct uccid_cmd_txn_begin {
	uint32_t	uct_version;
	uint32_t	uct_flags;
} uccid_cmd_txn_begin_t;

/*
 * Relinquish exclusive access. Takes a uccid_cmd_txn_end_t. The callers should
 * specify one of UCCID_TXN_END_RESET or UCCID_TXN_END_RELEASE. These indicate
 * what behavior should be taken when we release the transaction. It is
 * considered an error if neither is specified. If the caller exits without
 * calling this function, then the ICC will be reset.
 */
#define	UCCID_CMD_TXN_END	(UCCID_IOCTL | 0x02)
#define	UCCID_TXN_END_RESET	0x01
#define	UCCID_TXN_END_RELEASE	0x02

typedef struct uccid_cmd_txn_end {
	uint32_t	uct_version;
	uint32_t	uct_flags;
} uccid_cmd_txn_end_t;

/*
 * Obtain the status of the slot. Returns a filled-in uccid_cmd_status_t.
 */
#define	UCCID_CMD_STATUS	(UCCID_IOCTL | 0x3)

/*
 * Protocol definitions. This should match common/ccid/atr.h.
 */
typedef enum {
	UCCID_PROT_NONE = 0,
	UCCID_PROT_T0	= 1 << 0,
	UCCID_PROT_T1	= 1 << 1
} uccid_prot_t;

/*
 * Bits for UCS Status
 */
#define	UCCID_STATUS_F_CARD_PRESENT	0x01
#define	UCCID_STATUS_F_CARD_ACTIVE	0x02
#define	UCCID_STATUS_F_PRODUCT_VALID	0x04
#define	UCCID_STATUS_F_SERIAL_VALID	0x08
#define	UCCID_STATUS_F_PARAMS_VALID	0x10

typedef struct uccid_cmd_status {
	uint32_t	ucs_version;
	uint32_t	ucs_status;
	int32_t		ucs_instance;
	uint32_t	ucs_slot;
	uint8_t		ucs_atr[UCCID_ATR_MAX];
	uint8_t		ucs_atrlen;
	uint8_t		ucs_pad[6];
	int8_t		ucs_product[256];
	int8_t		ucs_serial[256];
	ccid_class_descr_t	ucs_class;
	uccid_prot_t	ucs_prot;
	ccid_params_t	ucs_params;
} uccid_cmd_status_t;

/*
 * Modify the state of the ICC, if present.
 */
#define	UCCID_CMD_ICC_MODIFY	(UCCID_IOCTL | 0x04)

#define	UCCID_ICC_POWER_ON	0x01
#define	UCCID_ICC_POWER_OFF	0x02
#define	UCCID_ICC_WARM_RESET	0x03

typedef struct uccid_cmd_icc_modify {
	uint32_t uci_version;
	uint32_t uci_action;
} uccid_cmd_icc_modify_t;

#ifdef __cplusplus
}
#endif


#endif /* _SYS_USB_UCCID_H */