1 // Licensed under the Apache License, Version 2.0 2 // <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license 3 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option. 4 // All files in the project carrying such notice may not be copied, modified, or distributed 5 // except according to those terms. 6 //! Smart Card class/port IOCTL codes. 7 use shared::minwindef::{BYTE, DWORD, ULONG, WORD}; 8 use um::winioctl::{FILE_ANY_ACCESS, FILE_DEVICE_SMARTCARD, METHOD_BUFFERED}; 9 pub type UWORD = WORD; 10 DEFINE_GUID!{GUID_DEVINTERFACE_SMARTCARD_READER, 11 0x50DD5230, 0xBA8A, 0x11D1, 0xBF, 0x5D, 0x00, 0x00, 0xF8, 0x05, 0xF5, 0x30} 12 pub const SCARD_ATR_LENGTHL: DWORD = 33; 13 pub const SCARD_PROTOCOL_UNDEFINED: DWORD = 0x00000000; 14 pub const SCARD_PROTOCOL_T0: DWORD = 0x00000001; 15 pub const SCARD_PROTOCOL_T1: DWORD = 0x00000002; 16 pub const SCARD_PROTOCOL_RAW: DWORD = 0x00010000; 17 pub const SCARD_PROTOCOL_Tx: DWORD = SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1; 18 pub const SCARD_PROTOCOL_DEFAULT: DWORD = 0x80000000; 19 pub const SCARD_PROTOCOL_OPTIMAL: DWORD = 0x00000000; 20 pub const SCARD_POWER_DOWN: DWORD = 0; 21 pub const SCARD_COLD_RESET: DWORD = 1; 22 pub const SCARD_WARM_RESET: DWORD = 2; 23 pub const IOCTL_SMARTCARD_POWER: DWORD = CTL_CODE!(FILE_DEVICE_SMARTCARD, 1, METHOD_BUFFERED, 24 FILE_ANY_ACCESS); 25 pub const IOCTL_SMARTCARD_GET_ATTRIBUTE: DWORD = CTL_CODE!(FILE_DEVICE_SMARTCARD, 2, 26 METHOD_BUFFERED, FILE_ANY_ACCESS); 27 pub const IOCTL_SMARTCARD_SET_ATTRIBUTE: DWORD = CTL_CODE!(FILE_DEVICE_SMARTCARD, 3, 28 METHOD_BUFFERED, FILE_ANY_ACCESS); 29 pub const IOCTL_SMARTCARD_CONFISCATE: DWORD = CTL_CODE!(FILE_DEVICE_SMARTCARD, 4, 30 METHOD_BUFFERED, FILE_ANY_ACCESS); 31 pub const IOCTL_SMARTCARD_TRANSMIT: DWORD = CTL_CODE!(FILE_DEVICE_SMARTCARD, 5, 32 METHOD_BUFFERED, FILE_ANY_ACCESS); 33 pub const IOCTL_SMARTCARD_EJECT: DWORD = CTL_CODE!(FILE_DEVICE_SMARTCARD, 6, METHOD_BUFFERED, 34 FILE_ANY_ACCESS); 35 pub const IOCTL_SMARTCARD_SWALLOW: DWORD = CTL_CODE!(FILE_DEVICE_SMARTCARD, 7, 36 METHOD_BUFFERED, FILE_ANY_ACCESS); 37 pub const IOCTL_SMARTCARD_IS_PRESENT: DWORD = CTL_CODE!(FILE_DEVICE_SMARTCARD, 10, 38 METHOD_BUFFERED, FILE_ANY_ACCESS); 39 pub const IOCTL_SMARTCARD_IS_ABSENT: DWORD = CTL_CODE!(FILE_DEVICE_SMARTCARD, 11, 40 METHOD_BUFFERED, FILE_ANY_ACCESS); 41 pub const IOCTL_SMARTCARD_SET_PROTOCOL: DWORD = CTL_CODE!(FILE_DEVICE_SMARTCARD, 12, 42 METHOD_BUFFERED, FILE_ANY_ACCESS); 43 pub const IOCTL_SMARTCARD_GET_STATE: DWORD = CTL_CODE!(FILE_DEVICE_SMARTCARD, 14, 44 METHOD_BUFFERED, FILE_ANY_ACCESS); 45 pub const IOCTL_SMARTCARD_GET_LAST_ERROR: DWORD = CTL_CODE!(FILE_DEVICE_SMARTCARD, 15, 46 METHOD_BUFFERED, FILE_ANY_ACCESS); 47 pub const IOCTL_SMARTCARD_GET_PERF_CNTR: DWORD = CTL_CODE!(FILE_DEVICE_SMARTCARD, 16, 48 METHOD_BUFFERED, FILE_ANY_ACCESS); 49 pub const MAXIMUM_ATTR_STRING_LENGTH: DWORD = 32; 50 pub const MAXIMUM_SMARTCARD_READERS: DWORD = 10; 51 pub const SCARD_CLASS_VENDOR_INFO: ULONG = 1; 52 pub const SCARD_CLASS_COMMUNICATIONS: ULONG = 2; 53 pub const SCARD_CLASS_PROTOCOL: ULONG = 3; 54 pub const SCARD_CLASS_POWER_MGMT: ULONG = 4; 55 pub const SCARD_CLASS_SECURITY: ULONG = 5; 56 pub const SCARD_CLASS_MECHANICAL: ULONG = 6; 57 pub const SCARD_CLASS_VENDOR_DEFINED: ULONG = 7; 58 pub const SCARD_CLASS_IFD_PROTOCOL: ULONG = 8; 59 pub const SCARD_CLASS_ICC_STATE: ULONG = 9; 60 pub const SCARD_CLASS_PERF: ULONG = 0x7ffe; 61 pub const SCARD_CLASS_SYSTEM: ULONG = 0x7fff; 62 pub const SCARD_ATTR_VENDOR_NAME: ULONG = SCARD_CLASS_VENDOR_INFO << 16 | 0x0100; 63 pub const SCARD_ATTR_VENDOR_IFD_TYPE: ULONG = SCARD_CLASS_VENDOR_INFO << 16 | 0x0101; 64 pub const SCARD_ATTR_VENDOR_IFD_VERSION: ULONG = SCARD_CLASS_VENDOR_INFO << 16 | 0x0102; 65 pub const SCARD_ATTR_VENDOR_IFD_SERIAL_NO: ULONG = SCARD_CLASS_VENDOR_INFO << 16 | 0x0103; 66 pub const SCARD_ATTR_CHANNEL_ID: ULONG = SCARD_CLASS_COMMUNICATIONS << 16 | 0x0110; 67 pub const SCARD_ATTR_PROTOCOL_TYPES: ULONG = SCARD_CLASS_PROTOCOL << 16 | 0x0120; 68 pub const SCARD_ATTR_DEFAULT_CLK: ULONG = SCARD_CLASS_PROTOCOL << 16 | 0x0121; 69 pub const SCARD_ATTR_MAX_CLK: ULONG = SCARD_CLASS_PROTOCOL << 16 | 0x0122; 70 pub const SCARD_ATTR_DEFAULT_DATA_RATE: ULONG = SCARD_CLASS_PROTOCOL << 16 | 0x0123; 71 pub const SCARD_ATTR_MAX_DATA_RATE: ULONG = SCARD_CLASS_PROTOCOL << 16 | 0x0124; 72 pub const SCARD_ATTR_MAX_IFSD: ULONG = SCARD_CLASS_PROTOCOL << 16 | 0x0125; 73 pub const SCARD_ATTR_POWER_MGMT_SUPPORT: ULONG = SCARD_CLASS_POWER_MGMT << 16 | 0x0131; 74 pub const SCARD_ATTR_USER_TO_CARD_AUTH_DEVICE: ULONG = SCARD_CLASS_SECURITY << 16 | 0x0140; 75 pub const SCARD_ATTR_USER_AUTH_INPUT_DEVICE: ULONG = SCARD_CLASS_SECURITY << 16 | 0x0142; 76 pub const SCARD_ATTR_CHARACTERISTICS: ULONG = SCARD_CLASS_MECHANICAL << 16 | 0x0150; 77 pub const SCARD_ATTR_CURRENT_PROTOCOL_TYPE: ULONG = SCARD_CLASS_IFD_PROTOCOL << 16 | 0x0201; 78 pub const SCARD_ATTR_CURRENT_CLK: ULONG = SCARD_CLASS_IFD_PROTOCOL << 16 | 0x0202; 79 pub const SCARD_ATTR_CURRENT_F: ULONG = SCARD_CLASS_IFD_PROTOCOL << 16 | 0x0203; 80 pub const SCARD_ATTR_CURRENT_D: ULONG = SCARD_CLASS_IFD_PROTOCOL << 16 | 0x0204; 81 pub const SCARD_ATTR_CURRENT_N: ULONG = SCARD_CLASS_IFD_PROTOCOL << 16 | 0x0205; 82 pub const SCARD_ATTR_CURRENT_W: ULONG = SCARD_CLASS_IFD_PROTOCOL << 16 | 0x0206; 83 pub const SCARD_ATTR_CURRENT_IFSC: ULONG = SCARD_CLASS_IFD_PROTOCOL << 16 | 0x0207; 84 pub const SCARD_ATTR_CURRENT_IFSD: ULONG = SCARD_CLASS_IFD_PROTOCOL << 16 | 0x0208; 85 pub const SCARD_ATTR_CURRENT_BWT: ULONG = SCARD_CLASS_IFD_PROTOCOL << 16 | 0x0209; 86 pub const SCARD_ATTR_CURRENT_CWT: ULONG = SCARD_CLASS_IFD_PROTOCOL << 16 | 0x020a; 87 pub const SCARD_ATTR_CURRENT_EBC_ENCODING: ULONG = SCARD_CLASS_IFD_PROTOCOL << 16 | 0x020b; 88 pub const SCARD_ATTR_EXTENDED_BWT: ULONG = SCARD_CLASS_IFD_PROTOCOL << 16 | 0x020c; 89 pub const SCARD_ATTR_ICC_PRESENCE: ULONG = SCARD_CLASS_ICC_STATE << 16 | 0x0300; 90 pub const SCARD_ATTR_ICC_INTERFACE_STATUS: ULONG = SCARD_CLASS_ICC_STATE << 16 | 0x0301; 91 pub const SCARD_ATTR_CURRENT_IO_STATE: ULONG = SCARD_CLASS_ICC_STATE << 16 | 0x0302; 92 pub const SCARD_ATTR_ATR_STRING: ULONG = SCARD_CLASS_ICC_STATE << 16 | 0x0303; 93 pub const SCARD_ATTR_ICC_TYPE_PER_ATR: ULONG = SCARD_CLASS_ICC_STATE << 16 | 0x0304; 94 pub const SCARD_ATTR_ESC_RESET: ULONG = SCARD_CLASS_VENDOR_DEFINED << 16 | 0xA000; 95 pub const SCARD_ATTR_ESC_CANCEL: ULONG = SCARD_CLASS_VENDOR_DEFINED << 16 | 0xA003; 96 pub const SCARD_ATTR_ESC_AUTHREQUEST: ULONG = SCARD_CLASS_VENDOR_DEFINED << 16 | 0xA005; 97 pub const SCARD_ATTR_MAXINPUT: ULONG = SCARD_CLASS_VENDOR_DEFINED << 16 | 0xA007; 98 pub const SCARD_ATTR_DEVICE_UNIT: ULONG = SCARD_CLASS_SYSTEM << 16 | 0x0001; 99 pub const SCARD_ATTR_DEVICE_IN_USE: ULONG = SCARD_CLASS_SYSTEM << 16 | 0x0002; 100 pub const SCARD_ATTR_DEVICE_FRIENDLY_NAME_A: ULONG = SCARD_CLASS_SYSTEM << 16 | 0x0003; 101 pub const SCARD_ATTR_DEVICE_SYSTEM_NAME_A: ULONG = SCARD_CLASS_SYSTEM << 16 | 0x0004; 102 pub const SCARD_ATTR_DEVICE_FRIENDLY_NAME_W: ULONG = SCARD_CLASS_SYSTEM << 16 | 0x0005; 103 pub const SCARD_ATTR_DEVICE_SYSTEM_NAME_W: ULONG = SCARD_CLASS_SYSTEM << 16 | 0x0006; 104 pub const SCARD_ATTR_SUPRESS_T1_IFS_REQUEST: ULONG = SCARD_CLASS_SYSTEM << 16 | 0x0007; 105 pub const SCARD_PERF_NUM_TRANSMISSIONS: ULONG = SCARD_CLASS_PERF << 16 | 0x0001; 106 pub const SCARD_PERF_BYTES_TRANSMITTED: ULONG = SCARD_CLASS_PERF << 16 | 0x0002; 107 pub const SCARD_PERF_TRANSMISSION_TIME: ULONG = SCARD_CLASS_PERF << 16 | 0x0003; 108 pub const SCARD_T0_HEADER_LENGTH: DWORD = 7; 109 pub const SCARD_T0_CMD_LENGTH: DWORD = 5; 110 pub const SCARD_T1_PROLOGUE_LENGTH: DWORD = 3; 111 pub const SCARD_T1_EPILOGUE_LENGTH: DWORD = 2; 112 pub const SCARD_T1_MAX_IFS: DWORD = 254; 113 pub const SCARD_UNKNOWN: ULONG = 0; 114 pub const SCARD_ABSENT: ULONG = 1; 115 pub const SCARD_PRESENT: ULONG = 2; 116 pub const SCARD_SWALLOWED: ULONG = 3; 117 pub const SCARD_POWERED: ULONG = 4; 118 pub const SCARD_NEGOTIABLE: ULONG = 5; 119 pub const SCARD_SPECIFIC: ULONG = 6; 120 STRUCT!{struct SCARD_IO_REQUEST { 121 dwProtocol: DWORD, 122 cbPciLength: DWORD, 123 }} 124 pub type PSCARD_IO_REQUEST = *mut SCARD_IO_REQUEST; 125 pub type LPSCARD_IO_REQUEST = *mut SCARD_IO_REQUEST; 126 pub type LPCSCARD_IO_REQUEST = *const SCARD_IO_REQUEST; 127 STRUCT!{struct SCARD_T0_COMMAND { 128 bCla: BYTE, 129 bIns: BYTE, 130 bP1: BYTE, 131 bP2: BYTE, 132 bP3: BYTE, 133 }} 134 pub type LPSCARD_T0_COMMAND = *mut SCARD_T0_COMMAND; 135 UNION!{union SCARD_T0_REQUEST_u { 136 [u8; 5], 137 CmdBytes CmdBytes_mut: SCARD_T0_COMMAND, 138 rgbHeader rgbHeader_mut: [BYTE; 5], 139 }} 140 STRUCT!{struct SCARD_T0_REQUEST { 141 ioRequest: SCARD_IO_REQUEST, 142 bSw1: BYTE, 143 bSw2: BYTE, 144 u: SCARD_T0_REQUEST_u, 145 }} 146 pub type PSCARD_T0_REQUEST = *mut SCARD_T0_REQUEST; 147 pub type LPSCARD_T0_REQUEST = *mut SCARD_T0_REQUEST; 148 STRUCT!{struct SCARD_T1_REQUEST { 149 ioRequest: SCARD_IO_REQUEST, 150 }} 151 pub type PSCARD_T1_REQUEST = *mut SCARD_T1_REQUEST; 152 pub type LPSCARD_T1_REQUEST = *mut SCARD_T1_REQUEST; 153 pub const SCARD_READER_SWALLOWS: ULONG = 0x00000001; 154 pub const SCARD_READER_EJECTS: ULONG = 0x00000002; 155 pub const SCARD_READER_CONFISCATES: ULONG = 0x00000004; 156 pub const SCARD_READER_TYPE_SERIAL: ULONG = 0x01; 157 pub const SCARD_READER_TYPE_PARALELL: ULONG = 0x02; 158 pub const SCARD_READER_TYPE_KEYBOARD: ULONG = 0x04; 159 pub const SCARD_READER_TYPE_SCSI: ULONG = 0x08; 160 pub const SCARD_READER_TYPE_IDE: ULONG = 0x10; 161 pub const SCARD_READER_TYPE_USB: ULONG = 0x20; 162 pub const SCARD_READER_TYPE_PCMCIA: ULONG = 0x40; 163 pub const SCARD_READER_TYPE_TPM: ULONG = 0x80; 164 pub const SCARD_READER_TYPE_NFC: ULONG = 0x100; 165 pub const SCARD_READER_TYPE_UICC: ULONG = 0x200; 166 pub const SCARD_READER_TYPE_VENDOR: ULONG = 0xF0; 167