1 /* 2 * This file and its contents are supplied under the terms of the 3 * Common Development and Distribution License ("CDDL"), version 1.0. 4 * You may only use this file in accordance with the terms of version 5 * 1.0 of the CDDL. 6 * 7 * A full copy of the text of the CDDL should have accompanied this 8 * source. A copy of the CDDL is also available via the Internet at 9 * http://www.illumos.org/license/CDDL. 10 */ 11 12 /* 13 * Copyright 2019, Joyent, Inc. 14 */ 15 16 #ifndef _SYS_USB_UCCID_H 17 #define _SYS_USB_UCCID_H 18 19 /* 20 * Definitions for the userland CCID interface. 21 */ 22 23 #include <sys/types.h> 24 #include <sys/usb/clients/ccid/ccid.h> 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 /* 31 * The maximum size of a normal APDU. This is the upper bound of what a user can 32 * read or write to a given card. 33 */ 34 #define UCCID_APDU_SIZE_MAX 261 35 36 /* 37 * This is the maximum length of an ATR as per ISO/IEC 7816-3:2006. 38 */ 39 #define UCCID_ATR_MAX 33 40 41 42 #define UCCID_IOCTL (('u' << 24) | ('c' << 16) | ('d') << 8) 43 44 #define UCCID_VERSION_ONE 1 45 #define UCCID_CURRENT_VERSION UCCID_VERSION_ONE 46 47 /* 48 * Attempt to obtain exclusive access. If the UCN_TXN_DONT_BLOCK flag is 49 * specified, the ioctl will return immediately if exclusive access cannot be 50 * gained. Otherwise, it will block in an interruptible fashion. The argument is 51 * a uccid_cmd_txn_begin_t. 52 */ 53 #define UCCID_CMD_TXN_BEGIN (UCCID_IOCTL | 0x01) 54 #define UCCID_TXN_DONT_BLOCK 0x01 55 56 typedef struct uccid_cmd_txn_begin { 57 uint32_t uct_version; 58 uint32_t uct_flags; 59 } uccid_cmd_txn_begin_t; 60 61 /* 62 * Relinquish exclusive access. Takes a uccid_cmd_txn_end_t. The callers should 63 * specify one of UCCID_TXN_END_RESET or UCCID_TXN_END_RELEASE. These indicate 64 * what behavior should be taken when we release the transaction. It is 65 * considered an error if neither is specified. If the caller exits without 66 * calling this function, then the ICC will be reset. 67 */ 68 #define UCCID_CMD_TXN_END (UCCID_IOCTL | 0x02) 69 #define UCCID_TXN_END_RESET 0x01 70 #define UCCID_TXN_END_RELEASE 0x02 71 72 typedef struct uccid_cmd_txn_end { 73 uint32_t uct_version; 74 uint32_t uct_flags; 75 } uccid_cmd_txn_end_t; 76 77 /* 78 * Obtain the status of the slot. Returns a filled-in uccid_cmd_status_t. 79 */ 80 #define UCCID_CMD_STATUS (UCCID_IOCTL | 0x3) 81 82 /* 83 * Protocol definitions. This should match common/ccid/atr.h. 84 */ 85 typedef enum { 86 UCCID_PROT_T0 = 1 << 0, 87 UCCID_PROT_T1 = 1 << 1 88 } uccid_prot_t; 89 90 /* 91 * Bits for UCS Status 92 */ 93 #define UCCID_STATUS_F_CARD_PRESENT 0x01 94 #define UCCID_STATUS_F_CARD_ACTIVE 0x02 95 #define UCCID_STATUS_F_PRODUCT_VALID 0x04 96 #define UCCID_STATUS_F_SERIAL_VALID 0x08 97 #define UCCID_STATUS_F_PARAMS_VALID 0x10 98 99 typedef struct uccid_cmd_status { 100 uint32_t ucs_version; 101 uint32_t ucs_status; 102 int32_t ucs_instance; 103 uint32_t ucs_slot; 104 uint8_t ucs_atr[UCCID_ATR_MAX]; 105 uint8_t ucs_atrlen; 106 uint8_t ucs_pad[6]; 107 int8_t ucs_product[256]; 108 int8_t ucs_serial[256]; 109 ccid_class_descr_t ucs_class; 110 uccid_prot_t ucs_prot; 111 ccid_params_t ucs_params; 112 } uccid_cmd_status_t; 113 114 /* 115 * Modify the state of the ICC, if present. 116 */ 117 #define UCCID_CMD_ICC_MODIFY (UCCID_IOCTL | 0x04) 118 119 #define UCCID_ICC_POWER_ON 0x01 120 #define UCCID_ICC_POWER_OFF 0x02 121 #define UCCID_ICC_WARM_RESET 0x03 122 123 typedef struct uccid_cmd_icc_modify { 124 uint32_t uci_version; 125 uint32_t uci_action; 126 } uccid_cmd_icc_modify_t; 127 128 #ifdef __cplusplus 129 } 130 #endif 131 132 133 #endif /* _SYS_USB_UCCID_H */ 134